Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: the sdk node example #189

Merged
merged 33 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4fa2c29
chore: get the node process running using tsx
May 14, 2024
2f89955
chore: update deps and add EVM SDK configuration
May 15, 2024
c35bff1
chore: more changes to get the sdk working in the swap example
May 15, 2024
cd07497
chore: get the swap.js example working
May 16, 2024
c36795f
chore: add bridge example
May 16, 2024
1113ea0
chore: start of trying to get multihop to work
May 17, 2024
44c10ca
chore: work on the multihop example
May 22, 2024
bdc142e
chore: updates to some scripts: changing chain to undefined
May 22, 2024
82fa62a
chore: start updates to klima and polynomial examples
May 22, 2024
8bbc19a
chore: update examples
May 22, 2024
a4276c9
chore: using localised contract examples to try and get klima contrac…
May 23, 2024
82e0b7b
chore: make polynomial and klima examples executable
May 24, 2024
aa77856
refactor: clean up the scripts and make sdk set up reusable function
May 24, 2024
e3edefd
chore: minor changes
May 24, 2024
1a6746d
chore: modifications to scripts
May 24, 2024
d64bcf2
chore: inline all examples so sequence of execution is easier to follow
May 27, 2024
b3bb2cc
fix: klima and multihop examples
May 28, 2024
a034734
fix: types
May 28, 2024
22e4dbf
refactor: start on cleaning up of examples
May 28, 2024
9c16876
chore: remove uneeded values from multihop
May 28, 2024
c8e2040
refactor: move values of config
May 29, 2024
8130ca2
chore: try using the arb chain in polynomial
DNR500 May 29, 2024
a74ac41
chore: get scripts to report as done
DNR500 May 30, 2024
27cc82f
chore: use find default token function in scripts
DNR500 May 30, 2024
a0378ec
docs: update the readme and a few simple comments in polynomial depos…
DNR500 May 30, 2024
a47510c
docs: simple corrections and updates
DNR500 May 30, 2024
076f823
chore: change polynomial config to some that might run with arbitrum …
DNR500 May 31, 2024
2f07790
chore: tidy up the example scripts
DNR500 Jun 5, 2024
b924760
docs: correction to the README.md
DNR500 Jun 5, 2024
f58d475
chore: remove uneeded comma from JSON file
DNR500 Jun 5, 2024
8a587c4
chore: fix README.md typos
chybisov Jun 6, 2024
5627e97
Merge branch 'main' into get-node-example-working
DNR500 Jun 7, 2024
628bdd7
fix: allow bs58 cjs package to be imported so it causes no problems f…
DNR500 Jun 10, 2024
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
7 changes: 7 additions & 0 deletions examples/node/.env-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# You should be able to obtain your private key from the account details section
# from your wallet
#
# NOTE: the private key is a Hex type and should being with 0x - some wallets may
# not include this at the beginning of your key when you try to obtain it

PRIVATE_KEY="your-private-key-here"
138 changes: 31 additions & 107 deletions examples/node/README.md
Original file line number Diff line number Diff line change
@@ -1,118 +1,42 @@
# 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) 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](https://viem.sh/), 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 these scripts use.

2. Execute the script.
Take a look at the scripts in the `./examples` folder.

Either the TypeScript version:
## Setting up the scripts to use your wallet

```bash
ts-node index.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 a git repository.

```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 is referenced in the 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.ts`
- `yarn example:klima` will run `examples/klimaRetireExactCarbon.ts`
- `yarn example:polynomial` will run `examples/polynomialDeposit.ts`

Be sure to take a look inside the scripts to find out what they do.




105 changes: 0 additions & 105 deletions examples/node/contractCalls/klimaRetireExactCarbon.ts

This file was deleted.

87 changes: 0 additions & 87 deletions examples/node/contractCalls/multihop.ts

This file was deleted.

Loading
Loading