-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/paltalabs/defindex into fea…
…t/implementChangeFeeReciever
- Loading branch information
Showing
24 changed files
with
633 additions
and
8,222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { useSorobanReact } from "@soroban-react/core"; | ||
|
||
import { HStack, Text } from "@chakra-ui/react"; | ||
import { contractInvoke } from "@soroban-react/contracts"; | ||
import { Address, Keypair, nativeToScVal, scValToNative, xdr } from "@stellar/stellar-sdk"; | ||
import { useEffect, useState } from "react"; | ||
import { Button } from "./ui/button"; | ||
|
||
export const TestTokens = () => { | ||
const sorobanContext = useSorobanReact(); | ||
const { address, activeChain, server } = sorobanContext; | ||
const networkPassphrase = activeChain?.networkPassphrase ?? ''; | ||
const [isSubmitting, setSubmitting] = useState(false); | ||
const [balance, setBalance] = useState<string>("0"); | ||
|
||
const testnetUSDC = "CAAFIHB4I7WQMJMKC22CZVQNNX7EONWSOMT6SUXK6I3G3F6J4XFRWNDI"; | ||
const admin_account = Keypair.fromSecret( | ||
process.env.NEXT_PUBLIC_TEST_TOKENS_ADMIN as string, | ||
); | ||
|
||
const fetchBalance = async () => { | ||
if (!address) return; | ||
contractInvoke({ | ||
contractAddress: testnetUSDC, | ||
method: 'balance', | ||
args: [new Address(address).toScVal()], | ||
sorobanContext, | ||
signAndSend: false, | ||
}).then((result) => { | ||
let balance = scValToNative(result as xdr.ScVal); | ||
balance = BigInt(BigInt(balance) / BigInt(1e7)).toString(); | ||
setBalance(balance); | ||
|
||
}).catch ((error) => { | ||
console.log('🚀 « error:', error); | ||
}) | ||
} | ||
|
||
useEffect(() => { | ||
fetchBalance(); | ||
}, [address]) | ||
|
||
const handleMint = async () => { | ||
console.log("Minting"); | ||
setSubmitting(true); | ||
|
||
const amount = 1000000000000 | ||
|
||
let adminSource; | ||
|
||
try { | ||
adminSource = await server?.getAccount(admin_account.publicKey()); | ||
} catch (error) { | ||
alert('Your wallet or the token admin wallet might not be funded'); | ||
setSubmitting(false); | ||
return; | ||
} | ||
|
||
if (!address) { | ||
return; | ||
} | ||
if (!adminSource) { | ||
return; | ||
} | ||
|
||
try { | ||
let result = await contractInvoke({ | ||
contractAddress: testnetUSDC, | ||
method: 'mint', | ||
args: [new Address(address).toScVal(), nativeToScVal(amount, {type: 'i128'})], | ||
sorobanContext, | ||
signAndSend: true, | ||
secretKey: admin_account.secret(), | ||
}); | ||
if (result) { | ||
fetchBalance(); | ||
} | ||
} catch (error) { | ||
console.log('🚀 « error:', error); | ||
} | ||
|
||
setSubmitting(false); | ||
} | ||
|
||
return ( | ||
<HStack> | ||
<Text>Current Balance: {balance} USDC</Text> | ||
<Button | ||
rounded={18} | ||
onClick={handleMint} | ||
loadingText="Minting..." | ||
loading={isSubmitting} | ||
> | ||
Mint test USDC | ||
</Button> | ||
</HStack> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# TypeScript SDK | ||
|
||
The TypeScript SDK provides a simple way to interact with DeFindex vaults in your web applications. You can easily integrate vault functionality with just **a few lines of code**. The SDK handles all the complexities of Soroban contract interactions while providing a type-safe interface. | ||
|
||
## Getting Started | ||
|
||
1. **Install the SDK** | ||
```bash | ||
npm install defindex-sdk | ||
# or | ||
yarn add defindex-sdk | ||
``` | ||
|
||
2. **Import and Initialize** | ||
```typescript | ||
import { Vault, SorobanNetwork } from 'defindex-sdk'; | ||
|
||
const vault = new Vault({ | ||
network: SorobanNetwork.TESTNET, | ||
contractId: 'YOUR_VAULT_CONTRACT_ID' | ||
}); | ||
``` | ||
|
||
3. **Use Vault Functions** | ||
```typescript | ||
// Check balance | ||
const balance = await vault.balance(accountAddress, sorobanContext); | ||
|
||
// Make a deposit | ||
const txHash = await vault.deposit( | ||
accountAddress, | ||
100, | ||
true, | ||
sorobanContext, | ||
secretKey // Optional secret key for signing, if you are using a connected wallet it's not needed | ||
); | ||
|
||
// Withdraw funds | ||
const withdrawTxHash = await vault.withdraw( | ||
accountAddress, | ||
50, | ||
true, | ||
sorobanContext, | ||
secretKey // Optional secret key for signing, if you are using a connected wallet it's not needed | ||
); | ||
``` |
Oops, something went wrong.