Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
28 changes: 25 additions & 3 deletions examples/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import {PoolStatus, poolUtils} from "@tinymanorg/tinyman-js-sdk";

import {addFlexibleLiquidity} from "./operation/add-liquidity/addFlexibleLiquidity";
import {addInitialLiquidity} from "./operation/add-liquidity/addInitialLiquidity";
import {addSingleAssetLiquidity} from "./operation/add-liquidity/addSingleAssetLiquidity";
import {bootstrapPool} from "./operation/bootstrap/bootstrapPool";
import {removeLiquidity} from "./operation/remove-liquidity/removeLiquidity";
import {removeLiquidityWithSingleAssetOut} from "./operation/remove-liquidity/removeLiquidityWithSingleAssetOut";
import {fixedInputSwap} from "./operation/swap/fixedInputSwap";
import {fixedOutputSwap} from "./operation/swap/fixedOutputSwap";
import {fixedInputSwap, fixedInputSwapWithoutSwapRouter} from "./operation/swap/fixedInputSwap";
import {fixedOutputSwap, fixedOutputSwapWithoutSwapRouter} from "./operation/swap/fixedOutputSwap";
import {getAccount} from "./util/account";
import {getAssetParams} from "./util/asset";
import {algodClient} from "./util/client";

/**
* Will run all the operations in the order they are defined
Expand All @@ -19,11 +22,24 @@ async function main() {
const account = await getAccount();
const {asset_1, asset_2} = await getAssetParams();

// Comment the next line if you already bootstrapped the pool
// Create the pool with the owned assets
// await bootstrapPool({ account, asset_1, asset_2 });

// Add some initial liquidity to the pool
await addInitialLiquidity({account, asset_1, asset_2});
const [_v1PoolInfo, v2PoolInfo] = await poolUtils.getPoolsForPair({
client: algodClient,
asset1ID: Number(asset_1.id),
asset2ID: Number(asset_2.id),
network: "testnet"
});

if (v2PoolInfo.status === PoolStatus.NOT_CREATED) {
// Create the pool with the owned assets
await bootstrapPool({account, asset_1, asset_2});
// Add some initial liquidity to the pool
await addInitialLiquidity({account, asset_1, asset_2});
}

// Add subsequent liquidity to the pool using the flexible mode
await addFlexibleLiquidity({account, asset_1, asset_2});
Expand All @@ -40,9 +56,15 @@ async function main() {
// Swap assets with fixed input
await fixedInputSwap({account, asset_1, asset_2});

// Swap assets with fixed input without using the swap router
await fixedInputSwapWithoutSwapRouter({account, asset_1, asset_2});

// Swap assets with fixed output
await fixedOutputSwap({account, asset_1, asset_2});

// Swap assets with fixed output without using the swap router
await fixedOutputSwapWithoutSwapRouter({account, asset_1, asset_2});

console.log("✅ All operations completed successfully");
}

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}`
);
}
Loading