Skip to content

Commit

Permalink
fix: types
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Richards committed May 28, 2024
1 parent b3bb2cc commit a034734
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 55 deletions.
16 changes: 10 additions & 6 deletions examples/node/examples/bridge.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as lifiDataTypes from '@lifi/data-types'
import type { RouteExtended, Execution } from '@lifi/sdk'
import {
executeRoute,
getRoutes,
Expand Down Expand Up @@ -82,12 +83,15 @@ async function run() {

// here we are using the update route hook to report the execution steps to the terminal
const executionOptions = {
updateRouteHook: (updatedRoute) => {
const lastExecution = updatedRoute.steps.reduce((accum, step) => {
if (step.execution) {
return step.execution
}
}, undefined)
updateRouteHook: (updatedRoute: RouteExtended) => {
const lastExecution = updatedRoute.steps.reduce(
(accum, step) => {
if (step.execution) {
return step.execution
}
},
undefined as undefined | Execution
)
console.info(lastExecution)
},
}
Expand Down
16 changes: 9 additions & 7 deletions examples/node/examples/klimaRetireExactCarbon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
} from 'viem'
import { mainnet, arbitrum, optimism, polygon } from 'viem/chains'
import { privateKeyToAccount } from 'viem/accounts'
import { publicActionsL2 } from 'viem/op-stack'
import 'dotenv/config'
import { promptConfirm } from '../helpers/promptConfirm'
import { AddressZero } from './constants'
Expand Down Expand Up @@ -91,7 +90,7 @@ const run = async () => {
transport: http(),
})

const sourceAmountDefaultRetirement = await publicClient.readContract({
const sourceAmountDefaultRetirement = (await publicClient.readContract({
address: KLIMA_ETHEREUM_CONTRACT_POL,
abi,
functionName: 'getSourceAmountDefaultRetirement',
Expand All @@ -100,7 +99,7 @@ const run = async () => {
Base_Carbon_Tonne_POL, // address poolToken,
retireAmount, // uint256 retireAmount,
],
})
})) as bigint

const usdcAmount = parseUnits(
sourceAmountDefaultRetirement.toString(),
Expand All @@ -125,7 +124,6 @@ const run = async () => {
],
})

// quote
const contractCallsQuoteRequest: ContractCallsQuoteRequest = {
fromChain,
fromToken,
Expand Down Expand Up @@ -168,7 +166,10 @@ const run = async () => {
)

// set approval if needed
if (approval < BigInt(contactCallsQuoteResponse.action.fromAmount)) {
if (
approval &&
approval < BigInt(contactCallsQuoteResponse.action.fromAmount)
) {
const txHash = await setTokenAllowance({
walletClient: client,
spenderAddress: contactCallsQuoteResponse.estimate.approvalAddress,
Expand All @@ -191,17 +192,18 @@ const run = async () => {
}
}

const transactionRequest = contactCallsQuoteResponse.transactionRequest
const transactionRequest =
contactCallsQuoteResponse.transactionRequest || {}

console.info('>> Execute transaction', transactionRequest)

const hash = await client.sendTransaction({
to: transactionRequest.to as Address,
account: client.account!,
data: transactionRequest.data as Hash,
value: transactionRequest.value
? BigInt(transactionRequest.value)
: undefined,
data: transactionRequest.data as Hash,
gas: transactionRequest.gasLimit
? BigInt(transactionRequest.gasLimit as string)
: undefined,
Expand Down
10 changes: 7 additions & 3 deletions examples/node/examples/multihop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ const run = async () => {
)

// set approval if needed
if (approval < BigInt(contactCallsQuoteResponse.action.fromAmount)) {
if (
approval &&
approval < BigInt(contactCallsQuoteResponse.action.fromAmount)
) {
const txHash = await setTokenAllowance({
walletClient: client,
spenderAddress: contactCallsQuoteResponse.estimate.approvalAddress,
Expand All @@ -159,7 +162,8 @@ const run = async () => {
}
}

const transactionRequest = contactCallsQuoteResponse.transactionRequest
const transactionRequest =
contactCallsQuoteResponse.transactionRequest || {}

console.info('>> Execute transaction', transactionRequest)

Expand All @@ -177,7 +181,7 @@ const run = async () => {
? BigInt(transactionRequest.gasPrice as string)
: undefined,
chain: null,
} as any)
})

console.info('>> Transaction sent', hash)

Expand Down
28 changes: 14 additions & 14 deletions examples/node/examples/polynomialDeposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { privateKeyToAccount } from 'viem/accounts'
import { mainnet, arbitrum, optimism, polygon } from 'viem/chains'
import 'dotenv/config'
import { promptConfirm } from '../helpers/promptConfirm'
import type { WalletClientWithPublicActions } from './types'
import { AddressZero } from './constants'

const run = async () => {
Expand All @@ -39,7 +38,7 @@ const run = async () => {
account,
chain: mainnet,
transport: http(),
}).extend(publicActions) as WalletClientWithPublicActions
}).extend(publicActions)

const switchChains = [mainnet, arbitrum, optimism, polygon]

Expand Down Expand Up @@ -124,7 +123,10 @@ const run = async () => {
)

// set approval if needed
if (approval < BigInt(contactCallsQuoteResponse.action.fromAmount)) {
if (
approval &&
approval < BigInt(contactCallsQuoteResponse.action.fromAmount)
) {
const txHash = await setTokenAllowance({
walletClient: client,
spenderAddress: contactCallsQuoteResponse.estimate.approvalAddress,
Expand All @@ -147,28 +149,26 @@ const run = async () => {
}
}

const transactionRequest = contactCallsQuoteResponse.transactionRequest
const transactionRequest =
contactCallsQuoteResponse.transactionRequest || {}

console.info('>> Execute transaction', transactionRequest)

const { maxFeePerGas, maxPriorityFeePerGas } =
await client.estimateFeesPerGas()

const hash = await client.sendTransaction({
to: transactionRequest.to as Address,
account: client.account!,
value: transactionRequest.value ? transactionRequest.value : undefined,
value: transactionRequest.value
? BigInt(transactionRequest.value as string)
: undefined,
data: transactionRequest.data as Hash,
gas: transactionRequest.gasLimit
? BigInt(transactionRequest.gasLimit as string)
: undefined,
// gasPrice: transactionRequest.gasPrice
// ? BigInt(transactionRequest.gasPrice as string)
// : undefined,
maxFeePerGas,
maxPriorityFeePerGas,
gasPrice: transactionRequest.gasPrice
? BigInt(transactionRequest.gasPrice as string)
: undefined,
chain: null,
} as any)
})

console.info('>> Transaction sent', hash)

Expand Down
16 changes: 10 additions & 6 deletions examples/node/examples/swap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as lifiDataTypes from '@lifi/data-types'
import type { RouteExtended, Execution } from '@lifi/sdk'
import {
createConfig,
EVM,
Expand Down Expand Up @@ -73,12 +74,15 @@ async function run() {

// here we are using the update route hook to report the execution steps to the terminal
const executionOptions = {
updateRouteHook: (updatedRoute) => {
const lastExecution = updatedRoute.steps.reduce((accum, step) => {
if (step.execution) {
return step.execution
}
}, undefined)
updateRouteHook: (updatedRoute: RouteExtended) => {
const lastExecution = updatedRoute.steps.reduce(
(accum, step) => {
if (step.execution) {
return step.execution
}
},
undefined as undefined | Execution
)
console.info(lastExecution)
},
}
Expand Down
5 changes: 0 additions & 5 deletions examples/node/examples/types.ts

This file was deleted.

4 changes: 2 additions & 2 deletions examples/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
"dependencies": {
"@lifi/data-types": "^4.2.1",
"@lifi/rpc-wrapper": "^0.0.27",
"@lifi/sdk": "^3.0.0-alpha.62",
"@lifi/sdk": "^3.0.0-alpha.63",
"@types/dotenv": "^8.2.0",
"@wagmi/connectors": "^4.3.9",
"@wagmi/core": "^2.9.7",
"dotenv": "^16.4.5",
"viem": "^2.10.0"
"viem": "^2.12.1"
},
"scripts": {
"example:swap": "tsx examples/swap.ts",
Expand Down
1 change: 1 addition & 0 deletions examples/node/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"strict": true,
"module": "ESNext",
"moduleResolution": "node",
},
Expand Down
31 changes: 19 additions & 12 deletions examples/node/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -700,20 +700,20 @@ __metadata:
languageName: node
linkType: hard

"@lifi/sdk@npm:^3.0.0-alpha.62":
version: 3.0.0-alpha.62
resolution: "@lifi/sdk@npm:3.0.0-alpha.62"
"@lifi/sdk@npm:^3.0.0-alpha.63":
version: 3.0.0-alpha.63
resolution: "@lifi/sdk@npm:3.0.0-alpha.63"
dependencies:
"@lifi/types": "npm:^13.3.0"
"@lifi/types": "npm:^13.7.1"
"@solana/wallet-adapter-base": "npm:^0.9.23"
"@solana/web3.js": "npm:^1.91.8"
eth-rpc-errors: "npm:^4.0.3"
viem: "npm:^2.11.0"
viem: "npm:^2.12.1"
peerDependencies:
"@solana/wallet-adapter-base": ^0.9.0
"@solana/web3.js": ^1.91.0
viem: ^2.10.0
checksum: 10/d260664a1c9384cf83dc0f2959853782828eb30c0c8b7d5907cc6cbcfd4bfdb8a9aad818393356e5734f5149913515c649135a4e497f452a860d64a2ba4bee04
checksum: 10/c1cb9cab1ba8bb8fec1bd24ed0fa20a15d97516a1ebb283a38e9f06ef53022ef58afff65141f1c27368104d19239e8f58a585a02cb5a24b373ae1581e78f8e8b
languageName: node
linkType: hard

Expand All @@ -724,6 +724,13 @@ __metadata:
languageName: node
linkType: hard

"@lifi/types@npm:^13.7.1":
version: 13.7.1
resolution: "@lifi/types@npm:13.7.1"
checksum: 10/37d4dbb642342a0eb791f7657c19f46623cdf59396cbf7898602e25d5394735c8e8e2d71648d914a7b97e94ee552324f6826ab550407c319dabe653d3deec815
languageName: node
linkType: hard

"@lit-labs/ssr-dom-shim@npm:^1.0.0, @lit-labs/ssr-dom-shim@npm:^1.1.0":
version: 1.2.0
resolution: "@lit-labs/ssr-dom-shim@npm:1.2.0"
Expand Down Expand Up @@ -4136,15 +4143,15 @@ __metadata:
dependencies:
"@lifi/data-types": "npm:^4.2.1"
"@lifi/rpc-wrapper": "npm:^0.0.27"
"@lifi/sdk": "npm:^3.0.0-alpha.62"
"@lifi/sdk": "npm:^3.0.0-alpha.63"
"@types/dotenv": "npm:^8.2.0"
"@types/node": "npm:^20.12.12"
"@wagmi/connectors": "npm:^4.3.9"
"@wagmi/core": "npm:^2.9.7"
dotenv: "npm:^16.4.5"
tsx: "npm:^4.10.2"
typescript: "npm:^5.4.5"
viem: "npm:^2.10.0"
viem: "npm:^2.12.1"
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -5945,9 +5952,9 @@ __metadata:
languageName: node
linkType: hard

"viem@npm:^2.10.0, viem@npm:^2.11.0":
version: 2.11.1
resolution: "viem@npm:2.11.1"
"viem@npm:^2.12.1":
version: 2.13.1
resolution: "viem@npm:2.13.1"
dependencies:
"@adraffy/ens-normalize": "npm:1.10.0"
"@noble/curves": "npm:1.2.0"
Expand All @@ -5962,7 +5969,7 @@ __metadata:
peerDependenciesMeta:
typescript:
optional: true
checksum: 10/1dc5d1455d006e5788e865e6e8a702e7dcf8cd2ca5cdfecc2dccf5886a579044fc8e0915f6a53e6a5db82e52f8660d6cf1d18dfcf75486fde6cea379d02cbb8b
checksum: 10/bfddca57e09d30810eaaa8ea01b281b8b1bcdb6da698404bc0f2b1d0a01a57051d70e911da0f480d9cdd8ec22c04ea88de0f09e29de5b4f1459e93c16d712952
languageName: node
linkType: hard

Expand Down

0 comments on commit a034734

Please sign in to comment.