Skip to content

Commit

Permalink
chore: get the node process running using tsx
Browse files Browse the repository at this point in the history
- I think next comes understanding how to replace the newer get signer method
understanding how the execute route function has change and what is required
there
  • Loading branch information
Nathan Richards committed May 14, 2024
1 parent e03ff83 commit 7bd2613
Show file tree
Hide file tree
Showing 4 changed files with 1,068 additions and 929 deletions.
6 changes: 3 additions & 3 deletions examples/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.1",
"type": "module",
"description": "Sample project to showcase the usage of @lifi/sdk",
"main": "index.js",
"main": "swap.ts",
"author": "Max Klenk <max@li.finance>",
"license": "MIT",
"dependencies": {
Expand All @@ -14,11 +14,11 @@
"dotenv": "^16.3.1"
},
"scripts": {
"run-ts": "ts-node swap.ts"
"start": "tsx ."
},
"devDependencies": {
"@types/node": "^20.5.9",
"ts-node": "^10.9.1",
"tsx": "^4.10.2",
"typescript": "^5.2.2"
}
}
14 changes: 9 additions & 5 deletions examples/node/swap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { findDefaultToken } from '@lifi/data-types'
import * as lifiDataTypes from '@lifi/data-types'
import type { Execution, ExecutionSettings, Route, SDKOptions } from '@lifi/sdk'
import { ChainId, CoinKey } from '@lifi/sdk'
import 'dotenv/config'
Expand All @@ -7,16 +7,20 @@ import { getLifi, getSigner, promptConfirm } from './helpers'

console.log('>> Starting Demo')

const dataTypes = (lifiDataTypes as any).default

const mnemonic = process.env.MNEMONIC || ''

async function demo() {
// get Route
const routeRequest = {
fromChainId: ChainId.AVA, // Avalanche
fromAmount: '100000', // 1 USDT
fromTokenAddress: findDefaultToken(CoinKey.USDC, ChainId.AVA).address,
fromTokenAddress: dataTypes.findDefaultToken(CoinKey.USDC, ChainId.AVA)
.address,
toChainId: ChainId.AVA, // Avalanche
toTokenAddress: findDefaultToken(CoinKey.USDT, ChainId.AVA).address,
toTokenAddress: dataTypes.findDefaultToken(CoinKey.USDT, ChainId.AVA)
.address,
options: {
slippage: 0.03, // = 3%
allowSwitchChain: false, // execute all transaction on starting chain
Expand All @@ -41,8 +45,6 @@ async function demo() {

console.log('>> Initialize LiFi')

const wallet = await getSigner(ChainId.AVA)

const lifi = getLifi(optionalConfigs)

console.log('>> Initialized, Requesting route')
Expand All @@ -58,6 +60,8 @@ async function demo() {
console.log('>> Start Execution')

// These are optonal settings for execution ------------------------------------
const wallet = await getSigner(ChainId.AVA)

const settings: ExecutionSettings = {
updateRouteHook: (updatedRoute) => {
let lastExecution: Execution | undefined = undefined
Expand Down
2 changes: 1 addition & 1 deletion examples/node/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "node"
"moduleResolution": "node",
},
"ts-node": {
"esm": true,
Expand Down
Loading

0 comments on commit 7bd2613

Please sign in to comment.