@lifi/sdk 3.7.1 → 3.7.3

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 (86) hide show
  1. package/package.json +6 -6
  2. package/src/_cjs/core/EVM/EVMStepExecutor.js +3 -3
  3. package/src/_cjs/core/EVM/EVMStepExecutor.js.map +1 -1
  4. package/src/_cjs/core/EVM/checkAllowance.js +8 -2
  5. package/src/_cjs/core/EVM/checkAllowance.js.map +1 -1
  6. package/src/_cjs/core/EVM/checkPermitSupport.js +8 -9
  7. package/src/_cjs/core/EVM/checkPermitSupport.js.map +1 -1
  8. package/src/_cjs/core/EVM/getActionWithFallback.js +23 -0
  9. package/src/_cjs/core/EVM/getActionWithFallback.js.map +1 -0
  10. package/src/_cjs/core/EVM/getAllowance.js +10 -9
  11. package/src/_cjs/core/EVM/getAllowance.js.map +1 -1
  12. package/src/_cjs/core/EVM/getEVMBalance.js +11 -8
  13. package/src/_cjs/core/EVM/getEVMBalance.js.map +1 -1
  14. package/src/_cjs/core/EVM/parseEVMErrors.js +16 -4
  15. package/src/_cjs/core/EVM/parseEVMErrors.js.map +1 -1
  16. package/src/_cjs/core/EVM/permits/getNativePermit.js +4 -3
  17. package/src/_cjs/core/EVM/permits/getNativePermit.js.map +1 -1
  18. package/src/_cjs/core/EVM/permits/getPermitTransferFromValues.js +2 -1
  19. package/src/_cjs/core/EVM/permits/getPermitTransferFromValues.js.map +1 -1
  20. package/src/_cjs/core/EVM/setAllowance.js +2 -2
  21. package/src/_cjs/core/EVM/setAllowance.js.map +1 -1
  22. package/src/_cjs/core/EVM/utils.js +2 -1
  23. package/src/_cjs/core/EVM/utils.js.map +1 -1
  24. package/src/_cjs/core/UTXO/getUTXOPublicClient.js +6 -13
  25. package/src/_cjs/core/UTXO/getUTXOPublicClient.js.map +1 -1
  26. package/src/_cjs/core/execution.js +3 -1
  27. package/src/_cjs/core/execution.js.map +1 -1
  28. package/src/_cjs/version.js +1 -1
  29. package/src/_esm/core/EVM/EVMStepExecutor.js +4 -4
  30. package/src/_esm/core/EVM/EVMStepExecutor.js.map +1 -1
  31. package/src/_esm/core/EVM/checkAllowance.js +8 -2
  32. package/src/_esm/core/EVM/checkAllowance.js.map +1 -1
  33. package/src/_esm/core/EVM/checkPermitSupport.js +8 -10
  34. package/src/_esm/core/EVM/checkPermitSupport.js.map +1 -1
  35. package/src/_esm/core/EVM/getActionWithFallback.js +34 -0
  36. package/src/_esm/core/EVM/getActionWithFallback.js.map +1 -0
  37. package/src/_esm/core/EVM/getAllowance.js +10 -9
  38. package/src/_esm/core/EVM/getAllowance.js.map +1 -1
  39. package/src/_esm/core/EVM/getEVMBalance.js +11 -8
  40. package/src/_esm/core/EVM/getEVMBalance.js.map +1 -1
  41. package/src/_esm/core/EVM/parseEVMErrors.js +14 -3
  42. package/src/_esm/core/EVM/parseEVMErrors.js.map +1 -1
  43. package/src/_esm/core/EVM/permits/getNativePermit.js +4 -3
  44. package/src/_esm/core/EVM/permits/getNativePermit.js.map +1 -1
  45. package/src/_esm/core/EVM/permits/getPermitTransferFromValues.js +2 -1
  46. package/src/_esm/core/EVM/permits/getPermitTransferFromValues.js.map +1 -1
  47. package/src/_esm/core/EVM/setAllowance.js +2 -2
  48. package/src/_esm/core/EVM/setAllowance.js.map +1 -1
  49. package/src/_esm/core/EVM/utils.js +2 -1
  50. package/src/_esm/core/EVM/utils.js.map +1 -1
  51. package/src/_esm/core/UTXO/getUTXOPublicClient.js +7 -14
  52. package/src/_esm/core/UTXO/getUTXOPublicClient.js.map +1 -1
  53. package/src/_esm/core/execution.js +3 -1
  54. package/src/_esm/core/execution.js.map +1 -1
  55. package/src/_esm/version.js +1 -1
  56. package/src/_types/core/EVM/EVMStepExecutor.d.ts.map +1 -1
  57. package/src/_types/core/EVM/checkAllowance.d.ts.map +1 -1
  58. package/src/_types/core/EVM/checkPermitSupport.d.ts.map +1 -1
  59. package/src/_types/core/EVM/getActionWithFallback.d.ts +18 -0
  60. package/src/_types/core/EVM/getActionWithFallback.d.ts.map +1 -0
  61. package/src/_types/core/EVM/getAllowance.d.ts +3 -3
  62. package/src/_types/core/EVM/getAllowance.d.ts.map +1 -1
  63. package/src/_types/core/EVM/parseEVMErrors.d.ts +1 -0
  64. package/src/_types/core/EVM/parseEVMErrors.d.ts.map +1 -1
  65. package/src/_types/core/EVM/permits/getNativePermit.d.ts +7 -1
  66. package/src/_types/core/EVM/permits/getNativePermit.d.ts.map +1 -1
  67. package/src/_types/core/EVM/permits/getPermitTransferFromValues.d.ts.map +1 -1
  68. package/src/_types/core/EVM/utils.d.ts.map +1 -1
  69. package/src/_types/core/UTXO/getUTXOPublicClient.d.ts +21 -0
  70. package/src/_types/core/UTXO/getUTXOPublicClient.d.ts.map +1 -1
  71. package/src/_types/core/execution.d.ts.map +1 -1
  72. package/src/_types/version.d.ts +1 -1
  73. package/src/core/EVM/EVMStepExecutor.ts +17 -9
  74. package/src/core/EVM/checkAllowance.ts +11 -6
  75. package/src/core/EVM/checkPermitSupport.ts +12 -21
  76. package/src/core/EVM/getActionWithFallback.ts +58 -0
  77. package/src/core/EVM/getAllowance.ts +21 -13
  78. package/src/core/EVM/getEVMBalance.ts +13 -8
  79. package/src/core/EVM/parseEVMErrors.ts +22 -3
  80. package/src/core/EVM/permits/getNativePermit.ts +13 -6
  81. package/src/core/EVM/permits/getPermitTransferFromValues.ts +12 -6
  82. package/src/core/EVM/setAllowance.ts +2 -2
  83. package/src/core/EVM/utils.ts +2 -1
  84. package/src/core/UTXO/getUTXOPublicClient.ts +6 -14
  85. package/src/core/execution.ts +6 -1
  86. package/src/version.ts +1 -1
@@ -1,8 +1,9 @@
1
1
  import type { BaseToken, ChainId } from '@lifi/types'
2
- import type { Address } from 'viem'
2
+ import type { Address, Client } from 'viem'
3
3
  import { multicall, readContract } from 'viem/actions'
4
4
  import { isNativeTokenAddress } from '../../utils/isZeroAddress.js'
5
5
  import { allowanceAbi } from './abi.js'
6
+ import { getActionWithFallback } from './getActionWithFallback.js'
6
7
  import { getPublicClient } from './publicClient.js'
7
8
  import type {
8
9
  TokenAllowance,
@@ -12,19 +13,23 @@ import type {
12
13
  import { getMulticallAddress } from './utils.js'
13
14
 
14
15
  export const getAllowance = async (
15
- chainId: ChainId,
16
+ client: Client,
16
17
  tokenAddress: Address,
17
18
  ownerAddress: Address,
18
19
  spenderAddress: Address
19
20
  ): Promise<bigint> => {
20
- const client = await getPublicClient(chainId)
21
21
  try {
22
- const approved = (await readContract(client, {
23
- address: tokenAddress as Address,
24
- abi: allowanceAbi,
25
- functionName: 'allowance',
26
- args: [ownerAddress, spenderAddress],
27
- })) as bigint
22
+ const approved = await getActionWithFallback(
23
+ client,
24
+ readContract,
25
+ 'readContract',
26
+ {
27
+ address: tokenAddress as Address,
28
+ abi: allowanceAbi,
29
+ functionName: 'allowance' as const,
30
+ args: [ownerAddress, spenderAddress] as const,
31
+ }
32
+ )
28
33
  return approved
29
34
  } catch (_e) {
30
35
  return 0n
@@ -32,6 +37,7 @@ export const getAllowance = async (
32
37
  }
33
38
 
34
39
  export const getAllowanceMulticall = async (
40
+ client: Client,
35
41
  chainId: ChainId,
36
42
  tokens: TokenSpender[],
37
43
  ownerAddress: Address
@@ -44,8 +50,6 @@ export const getAllowanceMulticall = async (
44
50
  throw new Error(`No multicall address configured for chainId ${chainId}.`)
45
51
  }
46
52
 
47
- const client = await getPublicClient(chainId)
48
-
49
53
  const contracts = tokens.map((token) => ({
50
54
  address: token.token.address as Address,
51
55
  abi: allowanceAbi,
@@ -53,7 +57,7 @@ export const getAllowanceMulticall = async (
53
57
  args: [ownerAddress, token.spenderAddress],
54
58
  }))
55
59
 
56
- const results = await multicall(client, {
60
+ const results = await getActionWithFallback(client, multicall, 'multicall', {
57
61
  contracts,
58
62
  multicallAddress: multicallAddress as Address,
59
63
  })
@@ -88,8 +92,10 @@ export const getTokenAllowance = async (
88
92
  return
89
93
  }
90
94
 
95
+ const client = await getPublicClient(token.chainId)
96
+
91
97
  const approved = await getAllowance(
92
- token.chainId,
98
+ client,
93
99
  token.address as Address,
94
100
  ownerAddress,
95
101
  spenderAddress
@@ -126,8 +132,10 @@ export const getTokenAllowanceMulticall = async (
126
132
  const allowances = (
127
133
  await Promise.all(
128
134
  chainKeys.map(async (chainId) => {
135
+ const client = await getPublicClient(chainId)
129
136
  // get allowances for current chain and token list
130
137
  return getAllowanceMulticall(
138
+ client,
131
139
  chainId,
132
140
  tokenDataByChain[chainId],
133
141
  ownerAddress
@@ -62,12 +62,14 @@ const getEVMBalanceMulticall = async (
62
62
  args: [walletAddress],
63
63
  }
64
64
  })
65
- const blockNumber = await getBlockNumber(client)
66
- const results = await multicall(client, {
67
- contracts,
68
- multicallAddress: multicallAddress as Address,
69
- blockNumber,
70
- })
65
+
66
+ const [blockNumber, results] = await Promise.all([
67
+ getBlockNumber(client),
68
+ multicall(client, {
69
+ contracts,
70
+ multicallAddress: multicallAddress as Address,
71
+ }),
72
+ ])
71
73
 
72
74
  if (!results.length) {
73
75
  return []
@@ -88,7 +90,7 @@ const getEVMBalanceDefault = async (
88
90
  walletAddress: Address
89
91
  ): Promise<TokenAmount[]> => {
90
92
  const client = await getPublicClient(chainId)
91
- const blockNumber = await getBlockNumber(client)
93
+
92
94
  const queue: Promise<bigint>[] = tokens.map((token) => {
93
95
  if (isZeroAddress(token.address)) {
94
96
  return getBalance(client, {
@@ -103,7 +105,10 @@ const getEVMBalanceDefault = async (
103
105
  }) as Promise<bigint>
104
106
  })
105
107
 
106
- const results = await Promise.allSettled(queue)
108
+ const [blockNumber, results] = await Promise.all([
109
+ getBlockNumber(client),
110
+ Promise.allSettled(queue),
111
+ ])
107
112
 
108
113
  const tokenAmounts: TokenAmount[] = tokens.map((token, index) => {
109
114
  const result = results[index]
@@ -1,4 +1,9 @@
1
1
  import type { LiFiStep } from '@lifi/types'
2
+ import {
3
+ AtomicReadyWalletRejectedUpgradeError,
4
+ TransactionExecutionError,
5
+ UserRejectedRequestError,
6
+ } from 'viem'
2
7
  import { SDKError } from '../../errors/SDKError.js'
3
8
  import { BaseError } from '../../errors/baseError.js'
4
9
  import { ErrorMessage, LiFiErrorCode } from '../../errors/constants.js'
@@ -28,8 +33,8 @@ const handleSpecificErrors = async (
28
33
  process?: Process
29
34
  ) => {
30
35
  if (
31
- e.name === 'UserRejectedRequestError' ||
32
- e.cause?.name === 'UserRejectedRequestError'
36
+ e.name === UserRejectedRequestError.name ||
37
+ e.cause?.name === UserRejectedRequestError.name
33
38
  ) {
34
39
  return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)
35
40
  }
@@ -41,7 +46,7 @@ const handleSpecificErrors = async (
41
46
  if (
42
47
  e.cause?.code === -32000 ||
43
48
  // Safe doesn't return proper code, but the error details includes 'rejected'
44
- (e.name === 'TransactionExecutionError' &&
49
+ (e.name === TransactionExecutionError.name &&
45
50
  e.cause?.details?.includes('rejected'))
46
51
  ) {
47
52
  return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)
@@ -84,3 +89,17 @@ const handleSpecificErrors = async (
84
89
 
85
90
  return new UnknownError(e.message || ErrorMessage.UnknownError, e)
86
91
  }
92
+
93
+ export const isAtomicReadyWalletRejectedUpgradeError = (e: any) => {
94
+ if (e.cause?.code === AtomicReadyWalletRejectedUpgradeError.code) {
95
+ return true
96
+ }
97
+
98
+ const details = e.cause?.details?.toLowerCase()
99
+ const isTransactionError = e.name === TransactionExecutionError.name
100
+ const hasRejectedUpgrade =
101
+ details?.includes('rejected') && details?.includes('upgrade')
102
+ const has7702ErrorCode = details?.includes('7702')
103
+
104
+ return isTransactionError && (hasRejectedUpgrade || has7702ErrorCode)
105
+ }
@@ -10,6 +10,7 @@ import type { Address, Client, Hex } from 'viem'
10
10
  import type { TypedDataDomain } from 'viem'
11
11
  import { multicall, readContract } from 'viem/actions'
12
12
  import { eip2612Abi, eip2612Types } from '../abi.js'
13
+ import { getActionWithFallback } from '../getActionWithFallback.js'
13
14
  import { getMulticallAddress } from '../utils.js'
14
15
  import type { NativePermitData } from './types.js'
15
16
 
@@ -35,6 +36,13 @@ const EIP712_DOMAIN_TYPEHASH =
35
36
  const EIP712_DOMAIN_TYPEHASH_WITH_SALT =
36
37
  '0x36c25de3e541d5d970f66e4210d728721220fff5c077cc6cd008b3a0c62adab7' as Hex
37
38
 
39
+ export type GetNativePermitParams = {
40
+ chainId: number
41
+ tokenAddress: Address
42
+ spenderAddress: Address
43
+ amount: bigint
44
+ }
45
+
38
46
  function makeDomainSeparator({
39
47
  name,
40
48
  version,
@@ -144,10 +152,7 @@ function validateDomainSeparator({
144
152
  */
145
153
  export const getNativePermit = async (
146
154
  client: Client,
147
- chainId: number,
148
- tokenAddress: Address,
149
- spenderAddress: Address,
150
- amount: bigint
155
+ { chainId, tokenAddress, spenderAddress, amount }: GetNativePermitParams
151
156
  ): Promise<NativePermitData | undefined> => {
152
157
  try {
153
158
  const multicallAddress = await getMulticallAddress(chainId)
@@ -179,7 +184,7 @@ export const getNativePermit = async (
179
184
  if (multicallAddress) {
180
185
  try {
181
186
  const [nameResult, domainSeparatorResult, noncesResult, versionResult] =
182
- await multicall(client, {
187
+ await getActionWithFallback(client, multicall, 'multicall', {
183
188
  contracts: contractCalls,
184
189
  multicallAddress,
185
190
  })
@@ -229,7 +234,9 @@ export const getNativePermit = async (
229
234
 
230
235
  const [nameResult, domainSeparatorResult, noncesResult, versionResult] =
231
236
  (await Promise.allSettled(
232
- contractCalls.map((call) => readContract(client, call))
237
+ contractCalls.map((call) =>
238
+ getActionWithFallback(client, readContract, 'readContract', call)
239
+ )
233
240
  )) as [
234
241
  PromiseSettledResult<string>,
235
242
  PromiseSettledResult<Hex>,
@@ -2,6 +2,7 @@ import type { ExtendedChain } from '@lifi/types'
2
2
  import type { Address, Client } from 'viem'
3
3
  import { readContract } from 'viem/actions'
4
4
  import { permit2ProxyAbi } from '../abi.js'
5
+ import { getActionWithFallback } from '../getActionWithFallback.js'
5
6
  import type { PermitTransferFrom } from './signatureTransfer.js'
6
7
 
7
8
  export const getPermitTransferFromValues = async (
@@ -10,12 +11,17 @@ export const getPermitTransferFromValues = async (
10
11
  tokenAddress: Address,
11
12
  amount: bigint
12
13
  ): Promise<PermitTransferFrom> => {
13
- const nonce = await readContract(client, {
14
- address: chain.permit2Proxy as Address,
15
- abi: permit2ProxyAbi,
16
- functionName: 'nextNonce',
17
- args: [client.account!.address],
18
- })
14
+ const nonce = await getActionWithFallback(
15
+ client,
16
+ readContract,
17
+ 'readContract',
18
+ {
19
+ address: chain.permit2Proxy as Address,
20
+ abi: permit2ProxyAbi,
21
+ functionName: 'nextNonce' as const,
22
+ args: [client.account!.address] as const,
23
+ }
24
+ )
19
25
 
20
26
  return {
21
27
  permitted: {
@@ -84,7 +84,7 @@ export const setTokenAllowance = async ({
84
84
  return
85
85
  }
86
86
  const approvedAmount = await getAllowance(
87
- token.chainId,
87
+ walletClient,
88
88
  token.address as Address,
89
89
  walletClient.account!.address,
90
90
  spenderAddress as Address
@@ -120,7 +120,7 @@ export const revokeTokenApproval = async ({
120
120
  return
121
121
  }
122
122
  const approvedAmount = await getAllowance(
123
- token.chainId,
123
+ walletClient,
124
124
  token.address as Address,
125
125
  walletClient.account!.address,
126
126
  spenderAddress as Address
@@ -3,6 +3,7 @@ import type { Address, Chain, Client, Transaction } from 'viem'
3
3
  import { getBlock } from 'viem/actions'
4
4
  import { config } from '../../config.js'
5
5
  import { median } from '../../utils/median.js'
6
+ import { getActionWithFallback } from './getActionWithFallback.js'
6
7
 
7
8
  type ChainBlockExplorer = {
8
9
  name: string
@@ -58,7 +59,7 @@ export function isExtendedChain(chain: any): chain is ExtendedChain {
58
59
  export const getMaxPriorityFeePerGas = async (
59
60
  client: Client
60
61
  ): Promise<bigint | undefined> => {
61
- const block = await getBlock(client, {
62
+ const block = await getActionWithFallback(client, getBlock, 'getBlock', {
62
63
  includeTransactions: true,
63
64
  })
64
65
 
@@ -4,7 +4,6 @@ import {
4
4
  fallback,
5
5
  publicActions,
6
6
  rpcSchema,
7
- utxo,
8
7
  walletActions,
9
8
  } from '@bigmi/core'
10
9
  import type {
@@ -17,6 +16,9 @@ import type {
17
16
  UTXOSchema,
18
17
  WalletActions,
19
18
  } from '@bigmi/core'
19
+ import { blockchair } from '@bigmi/core'
20
+ import { blockcypher } from '@bigmi/core'
21
+ import { mempool } from '@bigmi/core'
20
22
  import { config } from '../../config.js'
21
23
  import { getRpcUrls } from '../rpc.js'
22
24
 
@@ -61,19 +63,9 @@ export const getUTXOPublicClient = async (chainId: number) => {
61
63
  chain,
62
64
  rpcSchema: rpcSchema<UTXOSchema>(),
63
65
  transport: fallback([
64
- utxo('https://api.blockchair.com', {
65
- key: 'blockchair',
66
- includeChainToURL: true,
67
- }),
68
- utxo('https://api.blockcypher.com/v1/btc/main', {
69
- key: 'blockcypher',
70
- }),
71
- utxo('https://mempool.space/api', {
72
- key: 'mempool',
73
- }),
74
- utxo('https://rpc.ankr.com/http/btc_blockbook/api/v2', {
75
- key: 'ankr',
76
- }),
66
+ blockchair(),
67
+ blockcypher(),
68
+ mempool(),
77
69
  ...fallbackTransports,
78
70
  ]),
79
71
  pollingInterval: 10_000,
@@ -1,5 +1,7 @@
1
1
  import type { Route } from '@lifi/types'
2
2
  import { config } from '../config.js'
3
+ import { LiFiErrorCode } from '../errors/constants.js'
4
+ import { ProviderError } from '../errors/errors.js'
3
5
  import { executionState } from './executionState.js'
4
6
  import { prepareRestart } from './prepareRestart.js'
5
7
  import type { ExecutionOptions, RouteExtended } from './types.js'
@@ -106,7 +108,10 @@ const executeSteps = async (route: RouteExtended): Promise<RouteExtended> => {
106
108
  .providers.find((provider) => provider.isAddress(fromAddress))
107
109
 
108
110
  if (!provider) {
109
- throw new Error('SDK Execution Provider not found.')
111
+ throw new ProviderError(
112
+ LiFiErrorCode.ProviderUnavailable,
113
+ 'SDK Execution Provider not found.'
114
+ )
110
115
  }
111
116
 
112
117
  const stepExecutor = await provider.getStepExecutor({
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/sdk'
2
- export const version = '3.7.1'
2
+ export const version = '3.7.3'