@lifi/sdk 3.7.2 → 3.7.4

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 +13 -1
  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 +11 -0
  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 +15 -0
  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
@@ -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,5 @@
1
1
  import type { LiFiStep } from '@lifi/types'
2
+ import { AtomicReadyWalletRejectedUpgradeError } from 'viem'
2
3
  import { SDKError } from '../../errors/SDKError.js'
3
4
  import { BaseError } from '../../errors/baseError.js'
4
5
  import { ErrorMessage, LiFiErrorCode } from '../../errors/constants.js'
@@ -84,3 +85,17 @@ const handleSpecificErrors = async (
84
85
 
85
86
  return new UnknownError(e.message || ErrorMessage.UnknownError, e)
86
87
  }
88
+
89
+ export const isAtomicReadyWalletRejectedUpgradeError = (e: any) => {
90
+ if (e.cause?.code === AtomicReadyWalletRejectedUpgradeError.code) {
91
+ return true
92
+ }
93
+
94
+ const details = e.cause?.details?.toLowerCase()
95
+ const isTransactionError = e.name === 'TransactionExecutionError'
96
+ const hasRejectedUpgrade =
97
+ details?.includes('rejected') && details?.includes('upgrade')
98
+ const has7702ErrorCode = details?.includes('7702')
99
+
100
+ return isTransactionError && (hasRejectedUpgrade || has7702ErrorCode)
101
+ }
@@ -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.2'
2
+ export const version = '3.7.4'