Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 19 additions & 102 deletions examples/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"author": "Tinyman Core Team",
"license": "ISC",
"dependencies": {
"algosdk": "^1.22.0",
"@tinymanorg/tinyman-js-sdk": "^2.0.1"
"algosdk": "^2.1.0",
"@tinymanorg/tinyman-js-sdk": "^3.1.0"
},
"devDependencies": {
"@types/node": "^18.8.5",
Expand Down
2 changes: 1 addition & 1 deletion examples/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function main() {
// await bootstrapPool({ account, asset_1, asset_2 });

// Add some initial liquidity to the pool
await addInitialLiquidity({account, asset_1, asset_2});
// await addInitialLiquidity({account, asset_1, asset_2});
Comment thread
tatata96 marked this conversation as resolved.
Outdated

// Add subsequent liquidity to the pool using the flexible mode
await addFlexibleLiquidity({account, asset_1, asset_2});
Expand Down
4 changes: 2 additions & 2 deletions examples/src/operation/bootstrap/bootstrapPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function bootstrapPool({
console.log(`✅ Pool address: ${poolAddress}`);
console.log(`✅ Pool token ID: ${bootstrapExecutionResponse.poolTokenID}`);
console.log(
"✅ See pool account on AlgoExplorer: " +
`https://testnet.algoexplorer.io/address/${poolAddress}`
"✅ See pool account on PeraExplorer: " +
`https://testnet-api.algonode.cloud/v2/accounts/${poolAddress}`
Comment thread
tatata96 marked this conversation as resolved.
Outdated
);
}
37 changes: 15 additions & 22 deletions examples/src/operation/swap/fixedInputSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,24 @@ export async function fixedInputSwap({
* Swap.getQuote method, which will return the best quote (highest rate)
* after checking both v1 and v2
*/
const fixedInputSwapQuote = Swap.v2.getQuote(
SwapType.FixedInput,

const fixedInputSwapQuote = await Swap.v2.getQuote({
type: SwapType.FixedInput,
pool,
{id: pool.asset1ID, amount: 1_000_000},
{assetIn: 6, assetOut: 6}
);
const assetIn = {
id: fixedInputSwapQuote.assetInID,
amount: fixedInputSwapQuote.assetInAmount
};
const assetOut = {
id: fixedInputSwapQuote.assetOutID,
amount: fixedInputSwapQuote.assetOutAmount
};
amount: 1_000_000,
assetIn: {id: pool.asset1ID, decimals: 6},
assetOut: {id: pool.asset2ID, decimals: 6},
isSwapRouterEnabled: true,
network: "testnet"
});

const fixedInputSwapTxns = await Swap.v2.generateTxns({
client: algodClient,
swapType: SwapType.FixedInput,
pool,
network: "testnet",
quote: fixedInputSwapQuote,
swapType: SwapType.FixedInput,
slippage: 0.05,
initiatorAddr,
assetIn,
assetOut,
slippage: 0.05
});

const signedTxns = await Swap.v2.signTxns({
Expand All @@ -61,12 +56,10 @@ export async function fixedInputSwap({
});

const swapExecutionResponse = await Swap.v2.execute({
network: "testnet" as SupportedNetwork,
quote: fixedInputSwapQuote,
client: algodClient,
signedTxns,
pool,
txGroup: fixedInputSwapTxns,
assetIn
txGroup: fixedInputSwapTxns
});

console.log("✅ Fixed Input Swap executed successfully!");
Expand Down
33 changes: 12 additions & 21 deletions examples/src/operation/swap/fixedOutputSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,42 +30,33 @@ export async function fixedOutputSwap({
* Swap.getQuote method, which will return the best quote (highest rate)
* after checking both v1 and v2
*/
const fixedOutputSwapQuote = Swap.v2.getQuote(
SwapType.FixedOutput,
const fixedOutputSwapQuote = await Swap.v2.getQuote({

@Anlerkan Anlerkan Feb 20, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These examples use the swap router by default. Can you please add an example that does not use the swap router for both fixedInputSwap and fixedOutputSwap.

type: SwapType.FixedOutput,
pool,
{id: pool.asset2ID, amount: 1_000_000},
{assetIn: 6, assetOut: 6}
);

const assetIn = {
id: fixedOutputSwapQuote.assetInID,
amount: fixedOutputSwapQuote.assetInAmount
};
const assetOut = {
id: fixedOutputSwapQuote.assetOutID,
amount: fixedOutputSwapQuote.assetOutAmount
};
amount: 1_000_000,
assetIn: {id: pool.asset1ID, decimals: 6},
assetOut: {id: pool.asset2ID, decimals: 6},
isSwapRouterEnabled: true,
network: "testnet"
});

const fixedOutputSwapTxns = await Swap.v2.generateTxns({
client: algodClient,
network: "testnet",
quote: fixedOutputSwapQuote,
swapType: SwapType.FixedOutput,
pool,
slippage: 0.05,
initiatorAddr,
assetIn,
assetOut,
slippage: 0.05
});
const signedTxns = await Swap.v2.signTxns({
txGroup: fixedOutputSwapTxns,
initiatorSigner: signerWithSecretKey(account)
});
const swapExecutionResponse = await Swap.v2.execute({
network: "testnet" as SupportedNetwork,
quote: fixedOutputSwapQuote!,
client: algodClient,
signedTxns,
txGroup: fixedOutputSwapTxns,
pool,
assetIn
});

console.log("✅ Fixed Output Swap executed successfully!");
Expand Down
5 changes: 3 additions & 2 deletions examples/src/util/account.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Account, generateAccount } from "algosdk";
import { writeFileSync, readFileSync } from "fs";
import { getAccountInformation } from "@tinymanorg/tinyman-js-sdk";

import { algodClient } from "./client";
import { assertAccountHasBalance } from "./other";

Expand All @@ -15,8 +16,8 @@ export async function getAccount(): Promise<Account> {
if (!account) {
account = generateAccount();

console.log("✅ Account generated: " + account.addr);
console.log("✅ Account data saved to: " + ACCOUNT_FILENAME);
console.log(`✅ Account generated: ${ account.addr}`);
console.log(`✅ Account data saved to: ${ ACCOUNT_FILENAME}`);

writeFileSync(ACCOUNT_FILENAME, JSON.stringify(account));
}
Expand Down
2 changes: 1 addition & 1 deletion examples/src/util/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ console.log(
);
export const algodClient = new algosdk.Algodv2(
"",
"https://node.testnet.algoexplorerapi.io/",
"https://testnet-api.algonode.cloud",
""
);
1 change: 1 addition & 0 deletions examples/src/util/other.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { algodClient } from "./client";
*/
export async function assertAccountHasBalance(address: string) {
const accountInfo = await algodClient.accountInformation(address).do();

if (!accountInfo["amount"]) {
throw new Error(
`Go to https://bank.testnet.algorand.network/?account=${address} and fund your account.`
Expand Down