-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: update the readme and a few simple comments in polynomial depos…
…it example
- Loading branch information
Showing
2 changed files
with
31 additions
and
109 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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` | ||
|
||
|
||
|
||
|
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