From a0378ec82b67e9b8b252ea0459b7d3fde1a15b18 Mon Sep 17 00:00:00 2001 From: Nathan Richards Date: Thu, 30 May 2024 15:21:16 +0200 Subject: [PATCH] docs: update the readme and a few simple comments in polynomial deposit example --- examples/node/README.md | 136 +++++--------------- examples/node/examples/polynomialDeposit.ts | 4 +- 2 files changed, 31 insertions(+), 109 deletions(-) diff --git a/examples/node/README.md b/examples/node/README.md index 4b1dd586..867a0269 100644 --- a/examples/node/README.md +++ b/examples/node/README.md @@ -1,118 +1,40 @@ -# LI.FI SDK - Node Demo +# LI.FI SDK - Node Demo Examples -The demo of [our SDK](https://github.com/lifinance/sdk) executes a simple cross chain transfer of 1 USDT from Polygon to xDai using the best bridge it can find. +This project presents a number of demos for [our SDK](https://github.com/lifinance/sdk) examples that you can run from the command line. -It needs access to an actual wallet and makes real transactions on chain. +They use our SDK (along with viem) to execute common work flows in node.js -1. First you need to specify your `MNEMONIC` in your environment, e.g. +These scripts need to be provided access to an actual wallet and will make real transactions on chains. -```bash -export MNEMONIC="..." -``` +To run these examples you will need a private key for your wallet and enough funds for the tokens and chains that they use -2. Execute the script. +Take look at the scrips in the `./examples` folder -Either the TypeScript version: +## Setting up the scripts to use your wallet -```bash -ts-node types.ts -``` +- First you will need to obtain the private key for your wallet +- Then duplicate the `.env-template` file renaming it to `.env` +- Add your private key to your `.env` file - replacing the text in quote marks with your private key -Or the Javascript version: +NOTE: it's important to keep your private key safe and secure. Don't share it with anyone and make sure you never commit it to git repo. -```bash -node index.js -``` +## Executing the scripts -3. Sit back, relax and watch the show. - -First a route is searched and the script prints out what it found. The property `toAmount` will tell you how much USDT will end up on xDAI. -Then the SDK will execute all necessary steps to do the transfer (approval, send Transaction, wait the bridge, claim, ... ). It prints out status updates for each of these steps - -Sample output: - -```bash -{ - route: { - id: '0xcae9da9a53573ee1b5f81f6fe7ebfcb49945a082455fa2be3662b44434cd156b', - fromChainId: 137, - fromAmountUSD: '1.00', - fromAmount: '1000000', - fromToken: { - id: '0xc2132d05d31c914a87c6611c10748aeb04b58e8f', - symbol: 'USDT', - decimals: 6, - chainId: 137, - name: '(PoS) Tether USD', - chainKey: 'pol', - key: 'USDT', - priceUSD: '1', - logoURI: 'https://static.debank.com/image/matic_token/logo_url/0xc2132d05d31c914a87c6611c10748aeb04b58e8f/66eadee7b7bb16b75e02b570ab8d5c01.png' - }, - toChainId: 100, - toAmountUSD: '0.85', - toAmount: '851698', - toAmountMin: '851698', - toToken: { - id: '0x4ecaba5870353805a9f068101a40e0f32ed605c6', - symbol: 'USDT', - decimals: 6, - chainId: 100, - name: 'Tether USD on xDai', - chainKey: 'dai', - key: 'USDT', - priceUSD: '1', - logoURI: 'https://static.debank.com/image/xdai_token/logo_url/0x4ecaba5870353805a9f068101a40e0f32ed605c6/66eadee7b7bb16b75e02b570ab8d5c01.png' - }, - gasCostUSD: '0.01', - steps: [ [Object] ] - } -} - -{ status: 'NOT_STARTED', process: [] } -{ - status: 'PENDING', - process: [ - { - id: 'allowanceProcess', - startedAt: 1638960397132, - message: 'Set Allowance for USDT', - status: 'PENDING' - } - ] -} -... -{ - status: 'DONE', - process: [ - { - id: 'allowanceProcess', - startedAt: 1638960397132, - message: 'Already Approved', - status: 'DONE', - doneAt: 1638960397438 - }, - { - id: 'crossProcess', - startedAt: 1638960397438, - message: 'Transfer started: ', - status: 'DONE', - txHash: '0xfc8f43109ccdd7ea6446b770e99b0e3e449ebb13b0d07aae3553bb10994ac24d', - txLink: 'https://polygonscan.com/tx/0xfc8f43109ccdd7ea6446b770e99b0e3e449ebb13b0d07aae3553bb10994ac24d', - doneAt: 1638960430378 - }, - { - id: 'claimProcess', - startedAt: 1638960430378, - message: 'Swapped:', - status: 'DONE', - txHash: '0x55b2472502a6e7768eea47add832d06f5c7083ff2a808e5648985197bd84ed04', - txLink: 'https://blockscout.com/xdai/mainnet/tx/0x55b2472502a6e7768eea47add832d06f5c7083ff2a808e5648985197bd84ed04', - doneAt: 1638960852668 - } - ], - fromAmount: '1000000', - toAmount: '851698' -} -DONE +First install the dependencies + +``` +yarn install ``` + +Each of the scripts are referenced in scripts section of the package.json file. +To run each example you can use the following commands + +- `yarn example:swap` will run `examples/swap.ts` +- `yarn example:bridge` will run `examples/bridge.ts` +- `yarn example:multihop` will run `examples/multihop` +- `yarn example:klima` will run `examples/klimaRetireExactCarbon.ts` +- `yarn example:polynomial` will run `examples/polynomialDeposit.ts` + + + + diff --git a/examples/node/examples/polynomialDeposit.ts b/examples/node/examples/polynomialDeposit.ts index f5290c18..1dddff90 100644 --- a/examples/node/examples/polynomialDeposit.ts +++ b/examples/node/examples/polynomialDeposit.ts @@ -68,8 +68,8 @@ const run = async () => { // config for polynomial deposit run const config = { - fromChain: ChainId.ETH, - fromToken: findDefaultToken(CoinKey.ETH, ChainId.ETH).address, + fromChain: ChainId.ETH, // Etheruem + fromToken: findDefaultToken(CoinKey.ETH, ChainId.ETH).address, // ETH on Etheruem amount: parseEther('0.00001').toString(), polynomialContractAddress: '0x2D46292cbB3C601c6e2c74C32df3A4FCe99b59C7', // Polynomial Ethereum Contract on Optimism polynomialContractToken: '0xE405de8F52ba7559f9df3C368500B6E6ae6Cee49', // sETH on Optimism