@lifi/sdk 3.1.5 → 3.2.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/package.json +29 -29
  2. package/src/_cjs/core/EVM/EVM.js +2 -2
  3. package/src/_cjs/core/EVM/EVM.js.map +1 -1
  4. package/src/_cjs/core/EVM/EVMStepExecutor.js +29 -29
  5. package/src/_cjs/core/EVM/EVMStepExecutor.js.map +1 -1
  6. package/src/_cjs/core/EVM/checkAllowance.js +8 -8
  7. package/src/_cjs/core/EVM/checkAllowance.js.map +1 -1
  8. package/src/_cjs/core/EVM/getAllowance.js +2 -1
  9. package/src/_cjs/core/EVM/getAllowance.js.map +1 -1
  10. package/src/_cjs/core/EVM/getENSAddress.js +1 -1
  11. package/src/_cjs/core/EVM/getENSAddress.js.map +1 -1
  12. package/src/_cjs/core/EVM/getEVMBalance.js +6 -5
  13. package/src/_cjs/core/EVM/getEVMBalance.js.map +1 -1
  14. package/src/_cjs/core/EVM/publicClient.js +1 -1
  15. package/src/_cjs/core/EVM/publicClient.js.map +1 -1
  16. package/src/_cjs/core/EVM/setAllowance.js +5 -5
  17. package/src/_cjs/core/EVM/setAllowance.js.map +1 -1
  18. package/src/_cjs/core/EVM/switchChain.js +10 -6
  19. package/src/_cjs/core/EVM/switchChain.js.map +1 -1
  20. package/src/_cjs/core/EVM/utils.js +2 -1
  21. package/src/_cjs/core/EVM/utils.js.map +1 -1
  22. package/src/_cjs/core/EVM/waitForTransactionReceipt.js +4 -4
  23. package/src/_cjs/core/EVM/waitForTransactionReceipt.js.map +1 -1
  24. package/src/_cjs/version.js +1 -1
  25. package/src/_cjs/version.js.map +1 -1
  26. package/src/_esm/core/EVM/EVM.js +2 -2
  27. package/src/_esm/core/EVM/EVM.js.map +1 -1
  28. package/src/_esm/core/EVM/EVMStepExecutor.js +29 -29
  29. package/src/_esm/core/EVM/EVMStepExecutor.js.map +1 -1
  30. package/src/_esm/core/EVM/checkAllowance.js +8 -8
  31. package/src/_esm/core/EVM/checkAllowance.js.map +1 -1
  32. package/src/_esm/core/EVM/getAllowance.js +2 -1
  33. package/src/_esm/core/EVM/getAllowance.js.map +1 -1
  34. package/src/_esm/core/EVM/getENSAddress.js +2 -2
  35. package/src/_esm/core/EVM/getENSAddress.js.map +1 -1
  36. package/src/_esm/core/EVM/getEVMBalance.js +6 -5
  37. package/src/_esm/core/EVM/getEVMBalance.js.map +1 -1
  38. package/src/_esm/core/EVM/publicClient.js +2 -2
  39. package/src/_esm/core/EVM/publicClient.js.map +1 -1
  40. package/src/_esm/core/EVM/setAllowance.js +6 -6
  41. package/src/_esm/core/EVM/setAllowance.js.map +1 -1
  42. package/src/_esm/core/EVM/switchChain.js +14 -10
  43. package/src/_esm/core/EVM/switchChain.js.map +1 -1
  44. package/src/_esm/core/EVM/utils.js +2 -1
  45. package/src/_esm/core/EVM/utils.js.map +1 -1
  46. package/src/_esm/core/EVM/waitForTransactionReceipt.js +4 -4
  47. package/src/_esm/core/EVM/waitForTransactionReceipt.js.map +1 -1
  48. package/src/_esm/version.js +1 -1
  49. package/src/_esm/version.js.map +1 -1
  50. package/src/_types/core/EVM/EVMStepExecutor.d.ts +4 -4
  51. package/src/_types/core/EVM/EVMStepExecutor.d.ts.map +1 -1
  52. package/src/_types/core/EVM/checkAllowance.d.ts +2 -2
  53. package/src/_types/core/EVM/checkAllowance.d.ts.map +1 -1
  54. package/src/_types/core/EVM/getAllowance.d.ts.map +1 -1
  55. package/src/_types/core/EVM/getEVMBalance.d.ts.map +1 -1
  56. package/src/_types/core/EVM/publicClient.d.ts +2 -2
  57. package/src/_types/core/EVM/publicClient.d.ts.map +1 -1
  58. package/src/_types/core/EVM/setAllowance.d.ts +2 -2
  59. package/src/_types/core/EVM/setAllowance.d.ts.map +1 -1
  60. package/src/_types/core/EVM/switchChain.d.ts +6 -6
  61. package/src/_types/core/EVM/switchChain.d.ts.map +1 -1
  62. package/src/_types/core/EVM/types.d.ts +5 -5
  63. package/src/_types/core/EVM/types.d.ts.map +1 -1
  64. package/src/_types/core/EVM/utils.d.ts +2 -2
  65. package/src/_types/core/EVM/utils.d.ts.map +1 -1
  66. package/src/_types/core/EVM/waitForTransactionReceipt.d.ts +3 -3
  67. package/src/_types/core/EVM/waitForTransactionReceipt.d.ts.map +1 -1
  68. package/src/_types/core/types.d.ts +2 -2
  69. package/src/_types/core/types.d.ts.map +1 -1
  70. package/src/_types/version.d.ts +1 -1
  71. package/src/_types/version.d.ts.map +1 -1
  72. package/src/core/EVM/EVM.ts +2 -2
  73. package/src/core/EVM/EVMStepExecutor.ts +33 -46
  74. package/src/core/EVM/checkAllowance.ts +9 -9
  75. package/src/core/EVM/getAllowance.ts +2 -1
  76. package/src/core/EVM/getENSAddress.ts +2 -2
  77. package/src/core/EVM/getEVMBalance.ts +11 -5
  78. package/src/core/EVM/publicClient.ts +5 -7
  79. package/src/core/EVM/setAllowance.ts +8 -13
  80. package/src/core/EVM/switchChain.ts +16 -12
  81. package/src/core/EVM/types.ts +5 -5
  82. package/src/core/EVM/utils.ts +4 -3
  83. package/src/core/EVM/waitForTransactionReceipt.ts +7 -10
  84. package/src/core/types.ts +2 -4
  85. package/src/version.ts +1 -1
@@ -3,13 +3,8 @@ import type {
3
3
  FullStatusData,
4
4
  Process,
5
5
  } from '@lifi/types'
6
- import type {
7
- Hash,
8
- PublicClient,
9
- SendTransactionParameters,
10
- WalletClient,
11
- } from 'viem'
12
- import { publicActions } from 'viem'
6
+ import type { Client, Hash, SendTransactionParameters } from 'viem'
7
+ import { getAddresses, sendTransaction } from 'viem/actions'
13
8
  import { config } from '../../config.js'
14
9
  import { LiFiErrorCode } from '../../errors/constants.js'
15
10
  import { TransactionError, ValidationError } from '../../errors/errors.js'
@@ -37,40 +32,40 @@ import { getMaxPriorityFeePerGas } from './utils.js'
37
32
  import { waitForTransactionReceipt } from './waitForTransactionReceipt.js'
38
33
 
39
34
  export interface EVMStepExecutorOptions extends StepExecutorOptions {
40
- walletClient: WalletClient
35
+ client: Client
41
36
  multisig?: MultisigConfig
42
37
  }
43
38
 
44
39
  export class EVMStepExecutor extends BaseStepExecutor {
45
- private walletClient: WalletClient
40
+ private client: Client
46
41
  private multisig?: MultisigConfig
47
42
 
48
43
  constructor(options: EVMStepExecutorOptions) {
49
44
  super(options)
50
- this.walletClient = options.walletClient
45
+ this.client = options.client
51
46
  this.multisig = options.multisig
52
47
  }
53
48
 
54
49
  // Ensure that we are using the right chain and wallet when executing transactions.
55
- checkWalletClient = async (
50
+ checkClient = async (
56
51
  step: LiFiStepExtended,
57
52
  process?: Process
58
- ): Promise<WalletClient | undefined> => {
59
- const updatedWalletClient = await switchChain(
60
- this.walletClient,
53
+ ): Promise<Client | undefined> => {
54
+ const updatedClient = await switchChain(
55
+ this.client,
61
56
  this.statusManager,
62
57
  step,
63
58
  this.allowUserInteraction,
64
59
  this.executionOptions?.switchChainHook
65
60
  )
66
- if (updatedWalletClient) {
67
- this.walletClient = updatedWalletClient
61
+ if (updatedClient) {
62
+ this.client = updatedClient
68
63
  }
69
64
 
70
65
  // Prevent execution of the quote by wallet different from the one which requested the quote
71
- let accountAddress = this.walletClient.account?.address
66
+ let accountAddress = this.client.account?.address
72
67
  if (!accountAddress) {
73
- const accountAddresses = await this.walletClient.getAddresses()
68
+ const accountAddresses = await getAddresses(this.client)
74
69
  accountAddress = accountAddresses?.[0]
75
70
  }
76
71
  if (accountAddress !== step.action.fromAddress) {
@@ -100,7 +95,7 @@ export class EVMStepExecutor extends BaseStepExecutor {
100
95
  process
101
96
  )
102
97
  }
103
- return updatedWalletClient
98
+ return updatedClient
104
99
  }
105
100
 
106
101
  executeStep = async (step: LiFiStepExtended): Promise<LiFiStepExtended> => {
@@ -116,13 +111,13 @@ export class EVMStepExecutor extends BaseStepExecutor {
116
111
  // All changes are already done from the source chain
117
112
  // Return the step
118
113
  if (recievingChainProcess?.substatus !== 'WAIT_DESTINATION_TRANSACTION') {
119
- const updatedWalletClient = await this.checkWalletClient(step)
120
- if (!updatedWalletClient) {
114
+ const updatedClient = await this.checkClient(step)
115
+ if (!updatedClient) {
121
116
  return step
122
117
  }
123
118
  }
124
119
 
125
- const isMultisigWalletClient = !!this.multisig?.isMultisigWalletClient
120
+ const isMultisigClient = !!this.multisig?.isMultisigClient
126
121
  const multisigBatchTransactions: MultisigTransaction[] = []
127
122
 
128
123
  const shouldBatchTransactions =
@@ -144,13 +139,13 @@ export class EVMStepExecutor extends BaseStepExecutor {
144
139
  const checkForAllowance =
145
140
  !existingProcess?.txHash &&
146
141
  !isZeroAddress(step.action.fromToken.address) &&
147
- (shouldBatchTransactions || !isMultisigWalletClient)
142
+ (shouldBatchTransactions || !isMultisigClient)
148
143
 
149
144
  if (checkForAllowance) {
150
145
  const data = await checkAllowance(
146
+ this.client,
151
147
  fromChain,
152
148
  step,
153
- this.walletClient,
154
149
  this.statusManager,
155
150
  this.executionOptions,
156
151
  this.allowUserInteraction,
@@ -180,7 +175,7 @@ export class EVMStepExecutor extends BaseStepExecutor {
180
175
  )
181
176
 
182
177
  try {
183
- if (isMultisigWalletClient && multisigProcess) {
178
+ if (isMultisigClient && multisigProcess) {
184
179
  const multisigTxHash = multisigProcess.multisigTxHash as Hash
185
180
  if (!multisigTxHash) {
186
181
  throw new ValidationError(
@@ -200,11 +195,8 @@ export class EVMStepExecutor extends BaseStepExecutor {
200
195
  let txHash: Hash
201
196
  if (process.txHash) {
202
197
  // Make sure that the chain is still correct
203
- const updatedWalletClient = await this.checkWalletClient(
204
- step,
205
- process
206
- )
207
- if (!updatedWalletClient) {
198
+ const updatedClient = await this.checkClient(step, process)
199
+ if (!updatedClient) {
208
200
  return step
209
201
  }
210
202
 
@@ -218,7 +210,7 @@ export class EVMStepExecutor extends BaseStepExecutor {
218
210
  )
219
211
 
220
212
  // Check balance
221
- await checkBalance(this.walletClient.account!.address, step)
213
+ await checkBalance(this.client.account!.address, step)
222
214
 
223
215
  // Create new transaction
224
216
  if (!step.transactionRequest) {
@@ -246,11 +238,8 @@ export class EVMStepExecutor extends BaseStepExecutor {
246
238
 
247
239
  // STEP 3: Send the transaction
248
240
  // Make sure that the chain is still correct
249
- const updatedWalletClient = await this.checkWalletClient(
250
- step,
251
- process
252
- )
253
- if (!updatedWalletClient) {
241
+ const updatedClient = await this.checkClient(step, process)
242
+ if (!updatedClient) {
254
243
  return step
255
244
  }
256
245
 
@@ -281,10 +270,8 @@ export class EVMStepExecutor extends BaseStepExecutor {
281
270
  // ? BigInt(step.transactionRequest.maxFeePerGas as string)
282
271
  // : undefined,
283
272
  maxPriorityFeePerGas:
284
- this.walletClient.account?.type === 'local'
285
- ? await getMaxPriorityFeePerGas(
286
- this.walletClient.extend(publicActions) as PublicClient
287
- )
273
+ this.client.account?.type === 'local'
274
+ ? await getMaxPriorityFeePerGas(this.client)
288
275
  : step.transactionRequest.maxPriorityFeePerGas
289
276
  ? BigInt(step.transactionRequest.maxPriorityFeePerGas)
290
277
  : undefined,
@@ -322,9 +309,9 @@ export class EVMStepExecutor extends BaseStepExecutor {
322
309
  )
323
310
  }
324
311
  } else {
325
- txHash = await this.walletClient.sendTransaction({
312
+ txHash = await sendTransaction(this.client, {
326
313
  to: transactionRequest.to,
327
- account: this.walletClient.account!,
314
+ account: this.client.account!,
328
315
  data: transactionRequest.data,
329
316
  value: transactionRequest.value,
330
317
  gas: transactionRequest.gas,
@@ -336,7 +323,7 @@ export class EVMStepExecutor extends BaseStepExecutor {
336
323
  }
337
324
 
338
325
  // STEP 4: Wait for the transaction
339
- if (isMultisigWalletClient) {
326
+ if (isMultisigClient) {
340
327
  process = this.statusManager.updateProcess(
341
328
  step,
342
329
  process.type,
@@ -359,7 +346,7 @@ export class EVMStepExecutor extends BaseStepExecutor {
359
346
  }
360
347
 
361
348
  const transactionReceipt = await waitForTransactionReceipt({
362
- walletClient: this.walletClient,
349
+ client: this.client,
363
350
  chainId: fromChain.id,
364
351
  txHash,
365
352
  onReplaced: (response) => {
@@ -372,7 +359,7 @@ export class EVMStepExecutor extends BaseStepExecutor {
372
359
 
373
360
  // if it's multisig wallet client and the process is in ACTION_REQUIRED
374
361
  // then signatures are still needed
375
- if (isMultisigWalletClient && process.status === 'ACTION_REQUIRED') {
362
+ if (isMultisigClient && process.status === 'ACTION_REQUIRED') {
376
363
  await updateMultisigRouteProcess(
377
364
  transactionReceipt?.transactionHash || txHash,
378
365
  step,
@@ -386,7 +373,7 @@ export class EVMStepExecutor extends BaseStepExecutor {
386
373
  // Update pending process if the transaction hash from the receipt is different.
387
374
  // This might happen if the transaction was replaced.
388
375
  if (
389
- !isMultisigWalletClient &&
376
+ !isMultisigClient &&
390
377
  transactionReceipt?.transactionHash &&
391
378
  transactionReceipt.transactionHash !== txHash
392
379
  ) {
@@ -1,5 +1,5 @@
1
1
  import type { Chain, LiFiStep, Process, ProcessType } from '@lifi/types'
2
- import type { Address, Hash, WalletClient } from 'viem'
2
+ import type { Address, Client, Hash } from 'viem'
3
3
  import type { StatusManager } from '../StatusManager.js'
4
4
  import type { ExecutionOptions } from '../types.js'
5
5
  import { getAllowance } from './getAllowance.js'
@@ -8,9 +8,9 @@ import { setAllowance } from './setAllowance.js'
8
8
  import { waitForTransactionReceipt } from './waitForTransactionReceipt.js'
9
9
 
10
10
  export const checkAllowance = async (
11
+ client: Client,
11
12
  chain: Chain,
12
13
  step: LiFiStep,
13
- walletClient: WalletClient,
14
14
  statusManager: StatusManager,
15
15
  settings?: ExecutionOptions,
16
16
  allowUserInteraction = false,
@@ -26,7 +26,7 @@ export const checkAllowance = async (
26
26
  try {
27
27
  if (allowanceProcess.txHash && allowanceProcess.status !== 'DONE') {
28
28
  await waitForApprovalTransaction(
29
- walletClient,
29
+ client,
30
30
  allowanceProcess.txHash! as Address,
31
31
  allowanceProcess.type,
32
32
  step,
@@ -43,7 +43,7 @@ export const checkAllowance = async (
43
43
  const approved = await getAllowance(
44
44
  chain.id,
45
45
  step.action.fromToken.address,
46
- walletClient.account!.address,
46
+ client.account!.address,
47
47
  step.estimate.approvalAddress
48
48
  )
49
49
 
@@ -56,7 +56,7 @@ export const checkAllowance = async (
56
56
 
57
57
  if (shouldBatchTransactions) {
58
58
  const approveTxHash = await setAllowance(
59
- walletClient,
59
+ client,
60
60
  step.action.fromToken.address,
61
61
  step.estimate.approvalAddress,
62
62
  fromAmount,
@@ -74,13 +74,13 @@ export const checkAllowance = async (
74
74
  }
75
75
 
76
76
  const approveTxHash = await setAllowance(
77
- walletClient,
77
+ client,
78
78
  step.action.fromToken.address,
79
79
  step.estimate.approvalAddress,
80
80
  fromAmount
81
81
  )
82
82
  await waitForApprovalTransaction(
83
- walletClient,
83
+ client,
84
84
  approveTxHash,
85
85
  allowanceProcess.type,
86
86
  step,
@@ -114,7 +114,7 @@ export const checkAllowance = async (
114
114
  }
115
115
 
116
116
  const waitForApprovalTransaction = async (
117
- walletClient: WalletClient,
117
+ client: Client,
118
118
  txHash: Hash,
119
119
  processType: ProcessType,
120
120
  step: LiFiStep,
@@ -127,7 +127,7 @@ const waitForApprovalTransaction = async (
127
127
  })
128
128
 
129
129
  const transactionReceipt = await waitForTransactionReceipt({
130
- walletClient,
130
+ client: client,
131
131
  chainId: chain.id,
132
132
  txHash: txHash,
133
133
  onReplaced(response) {
@@ -1,6 +1,7 @@
1
1
  import type { BaseToken, ChainId } from '@lifi/types'
2
2
  import type { Address } from 'viem'
3
3
  import { getContract } from 'viem'
4
+ import { multicall } from 'viem/actions'
4
5
  import { isNativeTokenAddress } from '../../utils/utils.js'
5
6
  import { allowanceAbi } from './abi.js'
6
7
  import { getPublicClient } from './publicClient.js'
@@ -57,7 +58,7 @@ export const getAllowanceMulticall = async (
57
58
  args: [ownerAddress, token.spenderAddress],
58
59
  }))
59
60
 
60
- const results = await client.multicall({
61
+ const results = await multicall(client, {
61
62
  contracts,
62
63
  multicallAddress: multicallAddress as Address,
63
64
  })
@@ -1,5 +1,5 @@
1
1
  import { ChainId } from '@lifi/types'
2
- import { normalize } from 'viem/ens'
2
+ import { getEnsAddress, normalize } from 'viem/ens'
3
3
  import { getPublicClient } from './publicClient.js'
4
4
 
5
5
  export const getENSAddress = async (
@@ -7,7 +7,7 @@ export const getENSAddress = async (
7
7
  ): Promise<string | undefined> => {
8
8
  try {
9
9
  const client = await getPublicClient(ChainId.ETH)
10
- const address = await client.getEnsAddress({
10
+ const address = await getEnsAddress(client, {
11
11
  name: normalize(name),
12
12
  })
13
13
  return address as string | undefined
@@ -1,5 +1,11 @@
1
1
  import type { ChainId, Token, TokenAmount } from '@lifi/types'
2
2
  import type { Address } from 'viem'
3
+ import {
4
+ getBalance,
5
+ getBlockNumber,
6
+ multicall,
7
+ readContract,
8
+ } from 'viem/actions'
3
9
  import { isZeroAddress } from '../../utils/utils.js'
4
10
  import { balanceOfAbi, getEthBalanceAbi } from './abi.js'
5
11
  import { getPublicClient } from './publicClient.js'
@@ -57,8 +63,8 @@ const getEVMBalanceMulticall = async (
57
63
  args: [walletAddress],
58
64
  }
59
65
  })
60
- const blockNumber = await client.getBlockNumber()
61
- const results = await client.multicall({
66
+ const blockNumber = await getBlockNumber(client)
67
+ const results = await multicall(client, {
62
68
  contracts,
63
69
  multicallAddress: multicallAddress as Address,
64
70
  blockNumber,
@@ -83,14 +89,14 @@ const getEVMBalanceDefault = async (
83
89
  walletAddress: string
84
90
  ): Promise<TokenAmount[]> => {
85
91
  const client = await getPublicClient(chainId)
86
- const blockNumber = await client.getBlockNumber()
92
+ const blockNumber = await getBlockNumber(client)
87
93
  const queue: Promise<bigint>[] = tokens.map((token) => {
88
94
  if (isZeroAddress(token.address)) {
89
- return client.getBalance({
95
+ return getBalance(client, {
90
96
  address: walletAddress as Address,
91
97
  })
92
98
  }
93
- return client.readContract({
99
+ return readContract(client, {
94
100
  address: token.address as Address,
95
101
  abi: balanceOfAbi,
96
102
  functionName: 'balanceOf',
@@ -1,21 +1,19 @@
1
1
  import { ChainId } from '@lifi/types'
2
- import type { PublicClient } from 'viem'
3
- import { createPublicClient, fallback, http, webSocket } from 'viem'
2
+ import type { Client } from 'viem'
3
+ import { createClient, fallback, http, webSocket } from 'viem'
4
4
  import { mainnet, type Chain } from 'viem/chains'
5
5
  import { config } from '../../config.js'
6
6
  import { getRpcUrls } from '../rpc.js'
7
7
 
8
8
  // cached providers
9
- const publicClients: Record<number, PublicClient> = {}
9
+ const publicClients: Record<number, Client> = {}
10
10
 
11
11
  /**
12
12
  * Get an instance of a provider for a specific chain
13
13
  * @param chainId - Id of the chain the provider is for
14
14
  * @returns The public client for the given chain
15
15
  */
16
- export const getPublicClient = async (
17
- chainId: number
18
- ): Promise<PublicClient> => {
16
+ export const getPublicClient = async (chainId: number): Promise<Client> => {
19
17
  if (!publicClients[chainId]) {
20
18
  const urls = await getRpcUrls(chainId)
21
19
  const fallbackTransports = urls.map((url) =>
@@ -44,7 +42,7 @@ export const getPublicClient = async (
44
42
  ...chain.contracts,
45
43
  }
46
44
  }
47
- publicClients[chainId] = createPublicClient({
45
+ publicClients[chainId] = createClient({
48
46
  chain: chain,
49
47
  transport: fallback(fallbackTransports),
50
48
  batch: {
@@ -1,10 +1,6 @@
1
- import type {
2
- Hash,
3
- PublicClient,
4
- SendTransactionParameters,
5
- WalletClient,
6
- } from 'viem'
7
- import { encodeFunctionData, publicActions } from 'viem'
1
+ import type { Client, Hash, SendTransactionParameters } from 'viem'
2
+ import { encodeFunctionData } from 'viem'
3
+ import { sendTransaction } from 'viem/actions'
8
4
  import { isNativeTokenAddress } from '../../utils/utils.js'
9
5
  import type { ExecutionOptions, TransactionParameters } from '../types.js'
10
6
  import { approveAbi } from './abi.js'
@@ -13,7 +9,7 @@ import type { ApproveTokenRequest, RevokeApprovalRequest } from './types.js'
13
9
  import { getMaxPriorityFeePerGas } from './utils.js'
14
10
 
15
11
  export const setAllowance = async (
16
- walletClient: WalletClient,
12
+ client: Client,
17
13
  tokenAddress: string,
18
14
  contractAddress: string,
19
15
  amount: bigint,
@@ -29,14 +25,13 @@ export const setAllowance = async (
29
25
  if (returnPopulatedTransaction) {
30
26
  return data
31
27
  }
32
- const client = walletClient.extend(publicActions)
33
28
 
34
29
  let transactionRequest: TransactionParameters = {
35
30
  to: tokenAddress,
36
31
  data,
37
32
  maxPriorityFeePerGas:
38
- walletClient.account?.type === 'local'
39
- ? await getMaxPriorityFeePerGas(client as PublicClient)
33
+ client.account?.type === 'local'
34
+ ? await getMaxPriorityFeePerGas(client)
40
35
  : undefined,
41
36
  }
42
37
 
@@ -53,9 +48,9 @@ export const setAllowance = async (
53
48
  }
54
49
  }
55
50
 
56
- return client.sendTransaction({
51
+ return sendTransaction(client, {
57
52
  to: transactionRequest.to,
58
- account: walletClient.account!,
53
+ account: client.account!,
59
54
  data: transactionRequest.data,
60
55
  gas: transactionRequest.gas,
61
56
  gasPrice: transactionRequest.gasPrice,
@@ -1,4 +1,5 @@
1
- import type { WalletClient } from 'viem'
1
+ import type { Client } from 'viem'
2
+ import { getChainId } from 'viem/actions'
2
3
  import { LiFiErrorCode } from '../../errors/constants.js'
3
4
  import { ProviderError } from '../../errors/errors.js'
4
5
  import type { StatusManager } from '../StatusManager.js'
@@ -10,28 +11,28 @@ import type { LiFiStepExtended, SwitchChainHook } from '../types.js'
10
11
  * If no and if user interaction is allowed it triggers the switchChainHook. If no user interaction is allowed it aborts.
11
12
  *
12
13
  * Account Type: local -
13
- * We need to create and return a new WalletClient from the switchChainHook in order to continue execution on a new chain.
14
+ * We need to create and return a new connector client from the switchChainHook in order to continue execution on a new chain.
14
15
  *
15
16
  * Account Type: json-rpc -
16
- * We can switch chain and return existing WalletClient from the switchChainHook in order to continue execution on a new chain.
17
- * @param walletClient
17
+ * We can switch chain and return existing connector client from the switchChainHook in order to continue execution on a new chain.
18
+ * @param client
18
19
  * @param statusManager
19
20
  * @param step
20
21
  * @param switchChainHook
21
22
  * @param allowUserInteraction
22
- * @returns New WalletClient
23
+ * @returns New connector client
23
24
  */
24
25
  export const switchChain = async (
25
- walletClient: WalletClient,
26
+ client: Client,
26
27
  statusManager: StatusManager,
27
28
  step: LiFiStepExtended,
28
29
  allowUserInteraction: boolean,
29
30
  switchChainHook?: SwitchChainHook
30
- ): Promise<WalletClient | undefined> => {
31
+ ): Promise<Client | undefined> => {
31
32
  // if we are already on the correct chain we can proceed directly
32
- const currentChainId = await walletClient.getChainId()
33
+ const currentChainId = await getChainId(client)
33
34
  if (currentChainId === step.action.fromChainId) {
34
- return walletClient
35
+ return client
35
36
  }
36
37
 
37
38
  // -> set status message
@@ -49,8 +50,11 @@ export const switchChain = async (
49
50
  }
50
51
 
51
52
  try {
52
- const updatedWalletClient = await switchChainHook?.(step.action.fromChainId)
53
- const updatedChainId = await updatedWalletClient?.getChainId()
53
+ const updatedClient = await switchChainHook?.(step.action.fromChainId)
54
+ let updatedChainId
55
+ if (updatedClient) {
56
+ updatedChainId = await getChainId(updatedClient)
57
+ }
54
58
  if (updatedChainId !== step.action.fromChainId) {
55
59
  throw new ProviderError(
56
60
  LiFiErrorCode.ChainSwitchError,
@@ -64,7 +68,7 @@ export const switchChain = async (
64
68
  'DONE'
65
69
  )
66
70
  statusManager.updateExecution(step, 'PENDING')
67
- return updatedWalletClient
71
+ return updatedClient
68
72
  } catch (error: any) {
69
73
  statusManager.updateProcess(step, switchProcess.type, 'FAILED', {
70
74
  error: {
@@ -1,10 +1,10 @@
1
1
  import { ChainType, type BaseToken } from '@lifi/types'
2
- import type { Hash, WalletClient } from 'viem'
2
+ import type { Client, Hash } from 'viem'
3
3
  import type { SwitchChainHook } from '../types.js'
4
4
  import { type SDKProvider } from '../types.js'
5
5
 
6
6
  export interface EVMProviderOptions {
7
- getWalletClient?: () => Promise<WalletClient>
7
+ getWalletClient?: () => Promise<Client>
8
8
  switchChain?: SwitchChainHook
9
9
  multisig?: MultisigConfig
10
10
  }
@@ -35,7 +35,7 @@ export type TokenSpenderAllowance = {
35
35
  }
36
36
 
37
37
  export interface ApproveTokenRequest {
38
- walletClient: WalletClient
38
+ walletClient: Client
39
39
  token: BaseToken
40
40
  spenderAddress: string
41
41
  amount: bigint
@@ -46,7 +46,7 @@ export interface ApproveTokenRequest {
46
46
  }
47
47
 
48
48
  export interface RevokeApprovalRequest {
49
- walletClient: WalletClient
49
+ walletClient: Client
50
50
  token: BaseToken
51
51
  spenderAddress: string
52
52
  }
@@ -63,7 +63,7 @@ export interface MultisigTransaction {
63
63
  }
64
64
 
65
65
  export interface MultisigConfig {
66
- isMultisigWalletClient: boolean
66
+ isMultisigClient: boolean
67
67
  getMultisigTransactionDetails: (
68
68
  txHash: Hash,
69
69
  fromChainId: number,
@@ -1,12 +1,13 @@
1
1
  import { type ChainId } from '@lifi/types'
2
- import type { PublicClient, Transaction } from 'viem'
2
+ import type { Client, Transaction } from 'viem'
3
+ import { getBlock } from 'viem/actions'
3
4
  import { config } from '../../config.js'
4
5
  import { median } from '../../utils/median.js'
5
6
 
6
7
  export const getMaxPriorityFeePerGas = async (
7
- client: PublicClient
8
+ client: Client
8
9
  ): Promise<bigint | undefined> => {
9
- const block = await client.getBlock({
10
+ const block = await getBlock(client, {
10
11
  includeTransactions: true,
11
12
  })
12
13
 
@@ -1,33 +1,32 @@
1
1
  import type { ChainId } from '@lifi/types'
2
2
  import type {
3
3
  Chain,
4
+ Client,
4
5
  Hash,
5
- PublicClient,
6
6
  ReplacementReason,
7
7
  ReplacementReturnType,
8
8
  TransactionReceipt,
9
- WalletClient,
10
9
  } from 'viem'
11
- import { publicActions } from 'viem'
10
+ import { waitForTransactionReceipt as waitForTransactionReceiptInternal } from 'viem/actions'
12
11
  import { LiFiErrorCode, TransactionError } from '../../utils/index.js'
13
12
  import { getPublicClient } from './publicClient.js'
14
13
  import { retryCount, retryDelay } from './utils.js'
15
14
 
16
15
  interface WaitForTransactionReceiptProps {
17
- walletClient: WalletClient
16
+ client: Client
18
17
  chainId: ChainId
19
18
  txHash: Hash
20
19
  onReplaced?: (response: ReplacementReturnType<Chain | undefined>) => void
21
20
  }
22
21
 
23
22
  export async function waitForTransactionReceipt({
24
- walletClient,
23
+ client,
25
24
  chainId,
26
25
  txHash,
27
26
  onReplaced,
28
27
  }: WaitForTransactionReceiptProps): Promise<TransactionReceipt | undefined> {
29
28
  let { transactionReceipt, replacementReason } = await waitForReceipt(
30
- walletClient.extend(publicActions),
29
+ client,
31
30
  txHash,
32
31
  onReplaced
33
32
  )
@@ -56,7 +55,7 @@ export async function waitForTransactionReceipt({
56
55
  }
57
56
 
58
57
  async function waitForReceipt(
59
- client: PublicClient | WalletClient,
58
+ client: Client,
60
59
  txHash: Hash,
61
60
  onReplaced?: (response: ReplacementReturnType<Chain | undefined>) => void
62
61
  ): Promise<{
@@ -67,9 +66,7 @@ async function waitForReceipt(
67
66
  let transactionReceipt: TransactionReceipt | undefined
68
67
 
69
68
  try {
70
- transactionReceipt = await (
71
- client as PublicClient
72
- ).waitForTransactionReceipt({
69
+ transactionReceipt = await waitForTransactionReceiptInternal(client, {
73
70
  hash: txHash,
74
71
  onReplaced: (response) => {
75
72
  replacementReason = response.reason
package/src/core/types.ts CHANGED
@@ -7,7 +7,7 @@ import type {
7
7
  Token,
8
8
  TokenAmount,
9
9
  } from '@lifi/types'
10
- import type { WalletClient } from 'viem'
10
+ import type { Client } from 'viem'
11
11
 
12
12
  export interface SDKProvider {
13
13
  readonly type: ChainType
@@ -82,9 +82,7 @@ export type TransactionRequestUpdateHook = (
82
82
  updatedTxRequest: TransactionRequestParameters
83
83
  ) => Promise<TransactionParameters>
84
84
 
85
- export type SwitchChainHook = (
86
- chainId: number
87
- ) => Promise<WalletClient | undefined>
85
+ export type SwitchChainHook = (chainId: number) => Promise<Client | undefined>
88
86
 
89
87
  export interface AcceptSlippageUpdateHookParams {
90
88
  toToken: Token
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/sdk'
2
- export const version = '3.1.5'
2
+ export const version = '3.2.0-alpha.0'