Skip to content

Commit

Permalink
fix: klima and multihop examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Richards committed May 28, 2024
1 parent 6ce75b8 commit b0f3a4a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 35 deletions.
22 changes: 10 additions & 12 deletions examples/node/examples/klimaRetireExactCarbon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ 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 type { WalletClientWithPublicActions } from './types'
import { AddressZero } from './constants'

const { findDefaultToken } = (lifiDataTypes as any).default
Expand All @@ -45,7 +45,7 @@ const run = async () => {
account,
chain: optimism as Chain,
transport: http(),
}).extend(publicActions) as WalletClientWithPublicActions
}).extend(publicActions)

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

Expand Down Expand Up @@ -133,6 +133,7 @@ const run = async () => {
toChain: ChainId.POL,
toToken: USDCe_POL.address,
toAmount: usdcAmount,
allowBridges: ['hop', 'across', 'amarok'],
contractCalls: [
{
fromAmount: usdcAmount,
Expand Down Expand Up @@ -194,24 +195,21 @@ const run = async () => {

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)
: 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
30 changes: 7 additions & 23 deletions examples/node/examples/multihop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const run = async () => {
toChain,
toToken,
fromAddress: account.address, // will actually be a relayer
// allowBridges: ['hop', 'across', 'amarok'],
allowBridges: ['hop', 'across', 'amarok'],
// denyBridges: ['stargate'],
maxPriceImpact: 0.4,
}
Expand Down Expand Up @@ -163,35 +163,19 @@ const run = async () => {

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

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

console.log(
'viem maxFeePerGas, maxPriorityFeePerGas',
maxFeePerGas,
maxPriorityFeePerGas
)

console.log(
'out gasPrice',
transactionRequest.gasPrice
? BigInt(transactionRequest.gasPrice as string)
: undefined
)

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)
: 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)

Expand Down

0 comments on commit b0f3a4a

Please sign in to comment.