@lifi/sdk 3.5.1-beta.0 → 3.6.0-beta.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 (224) hide show
  1. package/package.json +6 -3
  2. package/src/_cjs/constants.js +4 -2
  3. package/src/_cjs/constants.js.map +1 -1
  4. package/src/_cjs/core/EVM/EVM.js +0 -4
  5. package/src/_cjs/core/EVM/EVM.js.map +1 -1
  6. package/src/_cjs/core/EVM/EVMStepExecutor.js +156 -81
  7. package/src/_cjs/core/EVM/EVMStepExecutor.js.map +1 -1
  8. package/src/_cjs/core/EVM/abi.js +36 -43
  9. package/src/_cjs/core/EVM/abi.js.map +1 -1
  10. package/src/_cjs/core/EVM/checkAllowance.js +36 -30
  11. package/src/_cjs/core/EVM/checkAllowance.js.map +1 -1
  12. package/src/_cjs/core/EVM/getAllowance.js.map +1 -1
  13. package/src/_cjs/core/EVM/getEVMBalance.js.map +1 -1
  14. package/src/_cjs/core/EVM/getNativePermit.js +90 -0
  15. package/src/_cjs/core/EVM/getNativePermit.js.map +1 -0
  16. package/src/_cjs/core/EVM/parseEVMErrors.js +5 -2
  17. package/src/_cjs/core/EVM/parseEVMErrors.js.map +1 -1
  18. package/src/_cjs/core/EVM/permit2/allowanceTransfer.js +100 -0
  19. package/src/_cjs/core/EVM/permit2/allowanceTransfer.js.map +1 -0
  20. package/src/_cjs/core/EVM/permit2/constants.js +12 -0
  21. package/src/_cjs/core/EVM/permit2/constants.js.map +1 -0
  22. package/src/_cjs/core/EVM/permit2/domain.js +12 -0
  23. package/src/_cjs/core/EVM/permit2/domain.js.map +1 -0
  24. package/src/_cjs/core/EVM/permit2/signatureTransfer.js +121 -0
  25. package/src/_cjs/core/EVM/permit2/signatureTransfer.js.map +1 -0
  26. package/src/_cjs/core/EVM/setAllowance.js +3 -4
  27. package/src/_cjs/core/EVM/setAllowance.js.map +1 -1
  28. package/src/_cjs/core/EVM/signPermitMessage.js +169 -0
  29. package/src/_cjs/core/EVM/signPermitMessage.js.map +1 -0
  30. package/src/_cjs/core/EVM/typeguards.js +8 -0
  31. package/src/_cjs/core/EVM/typeguards.js.map +1 -0
  32. package/src/_cjs/core/EVM/types.js.map +1 -1
  33. package/src/_cjs/core/EVM/utils.js +2 -1
  34. package/src/_cjs/core/EVM/utils.js.map +1 -1
  35. package/src/_cjs/core/EVM/waitForBatchTransactionReceipt.js +32 -0
  36. package/src/_cjs/core/EVM/waitForBatchTransactionReceipt.js.map +1 -0
  37. package/src/_cjs/core/EVM/waitForRelayedTransactionReceipt.js +38 -0
  38. package/src/_cjs/core/EVM/waitForRelayedTransactionReceipt.js.map +1 -0
  39. package/src/_cjs/core/checkBalance.js +3 -3
  40. package/src/_cjs/core/checkBalance.js.map +1 -1
  41. package/src/_cjs/core/waitForTransactionStatus.js +4 -2
  42. package/src/_cjs/core/waitForTransactionStatus.js.map +1 -1
  43. package/src/_cjs/createConfig.js +2 -2
  44. package/src/_cjs/createConfig.js.map +1 -1
  45. package/src/_cjs/errors/constants.js +1 -0
  46. package/src/_cjs/errors/constants.js.map +1 -1
  47. package/src/_cjs/index.js +9 -6
  48. package/src/_cjs/index.js.map +1 -1
  49. package/src/_cjs/services/api.js +127 -53
  50. package/src/_cjs/services/api.js.map +1 -1
  51. package/src/_cjs/utils/checkPackageUpdates.js +20 -0
  52. package/src/_cjs/utils/checkPackageUpdates.js.map +1 -0
  53. package/src/_cjs/utils/convertQuoteToRoute.js +33 -0
  54. package/src/_cjs/utils/convertQuoteToRoute.js.map +1 -0
  55. package/src/_cjs/utils/fetchTxErrorDetails.js +13 -0
  56. package/src/_cjs/utils/fetchTxErrorDetails.js.map +1 -0
  57. package/src/_cjs/utils/invariant.js +17 -0
  58. package/src/_cjs/utils/invariant.js.map +1 -0
  59. package/src/_cjs/utils/waitForResult.js +16 -3
  60. package/src/_cjs/utils/waitForResult.js.map +1 -1
  61. package/src/_cjs/version.js +1 -1
  62. package/src/_esm/constants.js +3 -1
  63. package/src/_esm/constants.js.map +1 -1
  64. package/src/_esm/core/EVM/EVM.js +0 -4
  65. package/src/_esm/core/EVM/EVM.js.map +1 -1
  66. package/src/_esm/core/EVM/EVMStepExecutor.js +186 -92
  67. package/src/_esm/core/EVM/EVMStepExecutor.js.map +1 -1
  68. package/src/_esm/core/EVM/abi.js +37 -42
  69. package/src/_esm/core/EVM/abi.js.map +1 -1
  70. package/src/_esm/core/EVM/checkAllowance.js +41 -32
  71. package/src/_esm/core/EVM/checkAllowance.js.map +1 -1
  72. package/src/_esm/core/EVM/getAllowance.js.map +1 -1
  73. package/src/_esm/core/EVM/getEVMBalance.js.map +1 -1
  74. package/src/_esm/core/EVM/getNativePermit.js +95 -0
  75. package/src/_esm/core/EVM/getNativePermit.js.map +1 -0
  76. package/src/_esm/core/EVM/parseEVMErrors.js +9 -1
  77. package/src/_esm/core/EVM/parseEVMErrors.js.map +1 -1
  78. package/src/_esm/core/EVM/permit2/allowanceTransfer.js +93 -0
  79. package/src/_esm/core/EVM/permit2/allowanceTransfer.js.map +1 -0
  80. package/src/_esm/core/EVM/permit2/constants.js +9 -0
  81. package/src/_esm/core/EVM/permit2/constants.js.map +1 -0
  82. package/src/_esm/core/EVM/permit2/domain.js +9 -0
  83. package/src/_esm/core/EVM/permit2/domain.js.map +1 -0
  84. package/src/_esm/core/EVM/permit2/signatureTransfer.js +117 -0
  85. package/src/_esm/core/EVM/permit2/signatureTransfer.js.map +1 -0
  86. package/src/_esm/core/EVM/setAllowance.js +3 -4
  87. package/src/_esm/core/EVM/setAllowance.js.map +1 -1
  88. package/src/_esm/core/EVM/signPermitMessage.js +163 -0
  89. package/src/_esm/core/EVM/signPermitMessage.js.map +1 -0
  90. package/src/_esm/core/EVM/typeguards.js +5 -0
  91. package/src/_esm/core/EVM/typeguards.js.map +1 -0
  92. package/src/_esm/core/EVM/types.js.map +1 -1
  93. package/src/_esm/core/EVM/utils.js +2 -1
  94. package/src/_esm/core/EVM/utils.js.map +1 -1
  95. package/src/_esm/core/EVM/waitForBatchTransactionReceipt.js +28 -0
  96. package/src/_esm/core/EVM/waitForBatchTransactionReceipt.js.map +1 -0
  97. package/src/_esm/core/EVM/waitForRelayedTransactionReceipt.js +34 -0
  98. package/src/_esm/core/EVM/waitForRelayedTransactionReceipt.js.map +1 -0
  99. package/src/_esm/core/checkBalance.js +3 -3
  100. package/src/_esm/core/checkBalance.js.map +1 -1
  101. package/src/_esm/core/waitForTransactionStatus.js +4 -2
  102. package/src/_esm/core/waitForTransactionStatus.js.map +1 -1
  103. package/src/_esm/createConfig.js +1 -1
  104. package/src/_esm/createConfig.js.map +1 -1
  105. package/src/_esm/errors/constants.js +1 -0
  106. package/src/_esm/errors/constants.js.map +1 -1
  107. package/src/_esm/index.js +4 -2
  108. package/src/_esm/index.js.map +1 -1
  109. package/src/_esm/services/api.js +165 -72
  110. package/src/_esm/services/api.js.map +1 -1
  111. package/src/_esm/utils/checkPackageUpdates.js +17 -0
  112. package/src/_esm/utils/checkPackageUpdates.js.map +1 -0
  113. package/src/_esm/utils/convertQuoteToRoute.js +37 -0
  114. package/src/_esm/utils/convertQuoteToRoute.js.map +1 -0
  115. package/src/_esm/utils/fetchTxErrorDetails.js +9 -0
  116. package/src/_esm/utils/fetchTxErrorDetails.js.map +1 -0
  117. package/src/_esm/utils/invariant.js +43 -0
  118. package/src/_esm/utils/invariant.js.map +1 -0
  119. package/src/_esm/utils/waitForResult.js +19 -3
  120. package/src/_esm/utils/waitForResult.js.map +1 -1
  121. package/src/_esm/version.js +1 -1
  122. package/src/_types/constants.d.ts +3 -1
  123. package/src/_types/constants.d.ts.map +1 -1
  124. package/src/_types/core/EVM/EVM.d.ts.map +1 -1
  125. package/src/_types/core/EVM/EVMStepExecutor.d.ts +7 -4
  126. package/src/_types/core/EVM/EVMStepExecutor.d.ts.map +1 -1
  127. package/src/_types/core/EVM/abi.d.ts +202 -5
  128. package/src/_types/core/EVM/abi.d.ts.map +1 -1
  129. package/src/_types/core/EVM/checkAllowance.d.ts +12 -2
  130. package/src/_types/core/EVM/checkAllowance.d.ts.map +1 -1
  131. package/src/_types/core/EVM/getAllowance.d.ts +5 -4
  132. package/src/_types/core/EVM/getAllowance.d.ts.map +1 -1
  133. package/src/_types/core/EVM/getEVMBalance.d.ts +2 -1
  134. package/src/_types/core/EVM/getEVMBalance.d.ts.map +1 -1
  135. package/src/_types/core/EVM/getNativePermit.d.ts +18 -0
  136. package/src/_types/core/EVM/getNativePermit.d.ts.map +1 -0
  137. package/src/_types/core/EVM/permit2/allowanceTransfer.d.ts +41 -0
  138. package/src/_types/core/EVM/permit2/allowanceTransfer.d.ts.map +1 -0
  139. package/src/_types/core/EVM/permit2/constants.d.ts +8 -0
  140. package/src/_types/core/EVM/permit2/constants.d.ts.map +1 -0
  141. package/src/_types/core/EVM/permit2/domain.d.ts +8 -0
  142. package/src/_types/core/EVM/permit2/domain.d.ts.map +1 -0
  143. package/src/_types/core/EVM/permit2/signatureTransfer.d.ts +42 -0
  144. package/src/_types/core/EVM/permit2/signatureTransfer.d.ts.map +1 -0
  145. package/src/_types/core/EVM/setAllowance.d.ts +2 -2
  146. package/src/_types/core/EVM/setAllowance.d.ts.map +1 -1
  147. package/src/_types/core/EVM/signPermitMessage.d.ts +25 -0
  148. package/src/_types/core/EVM/signPermitMessage.d.ts.map +1 -0
  149. package/src/_types/core/EVM/typeguards.d.ts +4 -0
  150. package/src/_types/core/EVM/typeguards.d.ts.map +1 -0
  151. package/src/_types/core/EVM/types.d.ts +8 -18
  152. package/src/_types/core/EVM/types.d.ts.map +1 -1
  153. package/src/_types/core/EVM/utils.d.ts +2 -2
  154. package/src/_types/core/EVM/utils.d.ts.map +1 -1
  155. package/src/_types/core/EVM/waitForBatchTransactionReceipt.d.ts +4 -0
  156. package/src/_types/core/EVM/waitForBatchTransactionReceipt.d.ts.map +1 -0
  157. package/src/_types/core/EVM/waitForRelayedTransactionReceipt.d.ts +4 -0
  158. package/src/_types/core/EVM/waitForRelayedTransactionReceipt.d.ts.map +1 -0
  159. package/src/_types/core/checkBalance.d.ts.map +1 -1
  160. package/src/_types/core/waitForTransactionStatus.d.ts.map +1 -1
  161. package/src/_types/createConfig.d.ts.map +1 -1
  162. package/src/_types/errors/constants.d.ts +2 -1
  163. package/src/_types/errors/constants.d.ts.map +1 -1
  164. package/src/_types/index.d.ts +5 -3
  165. package/src/_types/index.d.ts.map +1 -1
  166. package/src/_types/services/api.d.ts +93 -26
  167. package/src/_types/services/api.d.ts.map +1 -1
  168. package/src/_types/utils/checkPackageUpdates.d.ts +2 -0
  169. package/src/_types/utils/checkPackageUpdates.d.ts.map +1 -0
  170. package/src/_types/utils/convertQuoteToRoute.d.ts +11 -0
  171. package/src/_types/utils/convertQuoteToRoute.d.ts.map +1 -0
  172. package/src/_types/utils/fetchTxErrorDetails.d.ts +2 -0
  173. package/src/_types/utils/fetchTxErrorDetails.d.ts.map +1 -0
  174. package/src/_types/utils/invariant.d.ts +22 -0
  175. package/src/_types/utils/invariant.d.ts.map +1 -0
  176. package/src/_types/utils/waitForResult.d.ts +4 -1
  177. package/src/_types/utils/waitForResult.d.ts.map +1 -1
  178. package/src/_types/version.d.ts +1 -1
  179. package/src/constants.ts +6 -1
  180. package/src/core/EVM/EVM.ts +0 -4
  181. package/src/core/EVM/EVMStepExecutor.ts +242 -146
  182. package/src/core/EVM/abi.ts +40 -43
  183. package/src/core/EVM/checkAllowance.ts +96 -92
  184. package/src/core/EVM/getAllowance.ts +8 -8
  185. package/src/core/EVM/getEVMBalance.ts +2 -2
  186. package/src/core/EVM/getNativePermit.ts +114 -0
  187. package/src/core/EVM/parseEVMErrors.ts +9 -1
  188. package/src/core/EVM/permit2/allowanceTransfer.ts +168 -0
  189. package/src/core/EVM/permit2/constants.ts +11 -0
  190. package/src/core/EVM/permit2/domain.ts +20 -0
  191. package/src/core/EVM/permit2/signatureTransfer.ts +214 -0
  192. package/src/core/EVM/setAllowance.ts +14 -15
  193. package/src/core/EVM/signPermitMessage.ts +280 -0
  194. package/src/core/EVM/typeguards.ts +7 -0
  195. package/src/core/EVM/types.ts +11 -26
  196. package/src/core/EVM/utils.ts +4 -3
  197. package/src/core/EVM/waitForBatchTransactionReceipt.ts +61 -0
  198. package/src/core/EVM/waitForRelayedTransactionReceipt.ts +50 -0
  199. package/src/core/checkBalance.ts +6 -3
  200. package/src/core/waitForTransactionStatus.ts +6 -2
  201. package/src/createConfig.ts +1 -1
  202. package/src/errors/constants.ts +1 -0
  203. package/src/index.ts +4 -8
  204. package/src/services/api.ts +279 -105
  205. package/src/utils/checkPackageUpdates.ts +22 -0
  206. package/src/utils/convertQuoteToRoute.ts +45 -0
  207. package/src/utils/fetchTxErrorDetails.ts +10 -0
  208. package/src/utils/invariant.ts +51 -0
  209. package/src/utils/waitForResult.ts +22 -3
  210. package/src/version.ts +1 -1
  211. package/src/_cjs/core/EVM/multisig.js +0 -29
  212. package/src/_cjs/core/EVM/multisig.js.map +0 -1
  213. package/src/_cjs/helpers.js +0 -55
  214. package/src/_cjs/helpers.js.map +0 -1
  215. package/src/_esm/core/EVM/multisig.js +0 -25
  216. package/src/_esm/core/EVM/multisig.js.map +0 -1
  217. package/src/_esm/helpers.js +0 -58
  218. package/src/_esm/helpers.js.map +0 -1
  219. package/src/_types/core/EVM/multisig.d.ts +0 -6
  220. package/src/_types/core/EVM/multisig.d.ts.map +0 -1
  221. package/src/_types/helpers.d.ts +0 -13
  222. package/src/_types/helpers.d.ts.map +0 -1
  223. package/src/core/EVM/multisig.ts +0 -54
  224. package/src/helpers.ts +0 -75
@@ -0,0 +1,61 @@
1
+ import type {
2
+ Client,
3
+ Hash,
4
+ WalletCallReceipt as _WalletCallReceipt,
5
+ } from 'viem'
6
+ import { getCallsStatus } from 'viem/experimental'
7
+ import { getAction } from 'viem/utils'
8
+ import { LiFiErrorCode } from '../../errors/constants.js'
9
+ import { TransactionError } from '../../errors/errors.js'
10
+ import { waitForResult } from '../../utils/waitForResult.js'
11
+
12
+ export type WalletCallReceipt = _WalletCallReceipt<
13
+ bigint,
14
+ 'success' | 'reverted'
15
+ >
16
+
17
+ export const waitForBatchTransactionReceipt = async (
18
+ client: Client,
19
+ batchHash: Hash
20
+ ): Promise<WalletCallReceipt> => {
21
+ return waitForResult(
22
+ async () => {
23
+ const callsDetails = await getAction(
24
+ client,
25
+ getCallsStatus,
26
+ 'getCallsStatus'
27
+ )({
28
+ id: batchHash,
29
+ })
30
+
31
+ if (callsDetails.status === 'PENDING') {
32
+ return undefined
33
+ }
34
+
35
+ if (callsDetails.status === 'CONFIRMED') {
36
+ if (
37
+ !callsDetails.receipts?.length ||
38
+ !callsDetails.receipts.every((receipt) => receipt.transactionHash) ||
39
+ callsDetails.receipts.some((receipt) => receipt.status === 'reverted')
40
+ ) {
41
+ throw new TransactionError(
42
+ LiFiErrorCode.TransactionFailed,
43
+ 'Transaction was reverted.'
44
+ )
45
+ }
46
+ const transactionReceipt = callsDetails.receipts.at(-1)!
47
+ return transactionReceipt
48
+ }
49
+
50
+ throw new TransactionError(
51
+ LiFiErrorCode.TransactionNotFound,
52
+ 'Transaction not found.'
53
+ )
54
+ },
55
+ 5000,
56
+ 3,
57
+ (_, error) => {
58
+ return !(error instanceof TransactionError)
59
+ }
60
+ )
61
+ }
@@ -0,0 +1,50 @@
1
+ import type { ExtendedTransactionInfo } from '@lifi/types'
2
+ import type { Hash, WalletCallReceipt as _WalletCallReceipt } from 'viem'
3
+ import { LiFiErrorCode } from '../../errors/constants.js'
4
+ import { TransactionError } from '../../errors/errors.js'
5
+ import { getRelayedTransactionStatus } from '../../services/api.js'
6
+ import { waitForResult } from '../../utils/waitForResult.js'
7
+
8
+ export type WalletCallReceipt = _WalletCallReceipt<
9
+ bigint,
10
+ 'success' | 'reverted'
11
+ >
12
+
13
+ export const waitForRelayedTransactionReceipt = async (
14
+ taskId: Hash
15
+ ): Promise<WalletCallReceipt> => {
16
+ return waitForResult(async () => {
17
+ const result = await getRelayedTransactionStatus({
18
+ taskId,
19
+ }).catch((e) => {
20
+ if (process.env.NODE_ENV === 'development') {
21
+ console.debug('Fetching status from relayer failed.', e)
22
+ }
23
+ return undefined
24
+ })
25
+
26
+ switch (result?.data.status) {
27
+ case 'PENDING':
28
+ return undefined
29
+ case 'DONE': {
30
+ const sending: ExtendedTransactionInfo | undefined = result?.data
31
+ .transactionStatus?.sending as ExtendedTransactionInfo
32
+ return {
33
+ status: 'success',
34
+ gasUsed: sending?.gasUsed,
35
+ transactionHash: result?.data.metadata.txHash,
36
+ } as unknown as WalletCallReceipt
37
+ }
38
+ case 'FAILED':
39
+ throw new TransactionError(
40
+ LiFiErrorCode.TransactionFailed,
41
+ 'Transaction was reverted.'
42
+ )
43
+ default:
44
+ throw new TransactionError(
45
+ LiFiErrorCode.TransactionNotFound,
46
+ 'Transaction not found.'
47
+ )
48
+ }
49
+ }, 5000)
50
+ }
@@ -28,13 +28,16 @@ export const checkBalance = async (
28
28
  } else {
29
29
  const neeeded = formatUnits(neededBalance, token.decimals)
30
30
  const current = formatUnits(currentBalance, token.decimals)
31
- let _errorMessage = `Your ${token.symbol} balance is too low, you try to transfer ${neeeded} ${token.symbol}, but your wallet only holds ${current} ${token.symbol}. No funds have been sent.`
31
+ let errorMessage = `Your ${token.symbol} balance is too low, you try to transfer ${neeeded} ${token.symbol}, but your wallet only holds ${current} ${token.symbol}. No funds have been sent.`
32
32
 
33
33
  if (currentBalance !== 0n) {
34
- _errorMessage += `If the problem consists, please delete this transfer and start a new one with a maximum of ${current} ${token.symbol}.`
34
+ errorMessage += `If the problem consists, please delete this transfer and start a new one with a maximum of ${current} ${token.symbol}.`
35
35
  }
36
36
 
37
- throw new BalanceError('The balance is too low.')
37
+ throw new BalanceError(
38
+ 'The balance is too low.',
39
+ new Error(errorMessage)
40
+ )
38
41
  }
39
42
  }
40
43
  }
@@ -49,7 +49,9 @@ export async function waitForTransactionStatus(
49
49
  }
50
50
  })
51
51
  .catch((e) => {
52
- console.debug('Fetching status from backend failed.', e)
52
+ if (process.env.NODE_ENV === 'development') {
53
+ console.debug('Fetching status from backend failed.', e)
54
+ }
53
55
  return undefined
54
56
  })
55
57
  }
@@ -64,7 +66,9 @@ export async function waitForTransactionStatus(
64
66
  const resolvedStatus = await status
65
67
 
66
68
  if (!('receiving' in resolvedStatus)) {
67
- throw new ServerError("Status doesn't contain receiving information.")
69
+ throw new ServerError(
70
+ "Status doesn't contain destination chain information."
71
+ )
68
72
  }
69
73
 
70
74
  return resolvedStatus
@@ -1,8 +1,8 @@
1
1
  import { ChainType } from '@lifi/types'
2
2
  import { config } from './config.js'
3
- import { checkPackageUpdates } from './helpers.js'
4
3
  import { getChains } from './services/api.js'
5
4
  import type { SDKConfig } from './types/internal.js'
5
+ import { checkPackageUpdates } from './utils/checkPackageUpdates.js'
6
6
  import { name, version } from './version.js'
7
7
 
8
8
  function createBaseConfig(options: SDKConfig) {
@@ -35,6 +35,7 @@ export enum LiFiErrorCode {
35
35
  TransactionExpired = 1018,
36
36
  TransactionSimulationFailed = 1019,
37
37
  TransactionConflict = 1020,
38
+ TransactionNotFound = 1021,
38
39
  }
39
40
 
40
41
  export enum ErrorMessage {
package/src/index.ts CHANGED
@@ -15,9 +15,6 @@ export { isEVM } from './core/EVM/types.js'
15
15
  export type {
16
16
  EVMProvider,
17
17
  EVMProviderOptions,
18
- MultisigConfig,
19
- MultisigTransaction,
20
- MultisigTxDetails,
21
18
  } from './core/EVM/types.js'
22
19
  export { StatusManager } from './core/StatusManager.js'
23
20
  export {
@@ -65,17 +62,16 @@ export { UTXO } from './core/UTXO/UTXO.js'
65
62
  export { isUTXO } from './core/UTXO/types.js'
66
63
  export type { UTXOProvider, UTXOProviderOptions } from './core/UTXO/types.js'
67
64
  export { createConfig } from './createConfig.js'
68
- export {
69
- checkPackageUpdates,
70
- convertQuoteToRoute,
71
- fetchTxErrorDetails,
72
- } from './helpers.js'
65
+ export { checkPackageUpdates } from './utils/checkPackageUpdates.js'
66
+ export { convertQuoteToRoute } from './utils/convertQuoteToRoute.js'
67
+ export { fetchTxErrorDetails } from './utils/fetchTxErrorDetails.js'
73
68
  export {
74
69
  getChains,
75
70
  getConnections,
76
71
  getContractCallsQuote,
77
72
  getGasRecommendation,
78
73
  getQuote,
74
+ getRelayerQuote,
79
75
  getRoutes,
80
76
  getStatus,
81
77
  getStepTransaction,
@@ -26,44 +26,56 @@ import {
26
26
  isContractCallsRequestWithFromAmount,
27
27
  isContractCallsRequestWithToAmount,
28
28
  } from '@lifi/types'
29
+ import type { Address, Hash, Hex } from 'viem'
29
30
  import { config } from '../config.js'
31
+ import type { PermitData } from '../core/EVM/permit2/domain.js'
32
+ import type {
33
+ PermitTransferFrom,
34
+ Witness,
35
+ } from '../core/EVM/permit2/signatureTransfer.js'
30
36
  import { SDKError } from '../errors/SDKError.js'
31
37
  import { ValidationError } from '../errors/errors.js'
32
38
  import { request } from '../request.js'
33
39
  import { isRoutesRequest, isStep } from '../typeguards.js'
34
40
  import { withDedupe } from '../utils/withDedupe.js'
35
- /**
36
- * Fetch information about a Token
37
- * @param chain - Id or key of the chain that contains the token
38
- * @param token - Address or symbol of the token on the requested chain
39
- * @param options - Request options
40
- * @throws {LiFiError} - Throws a LiFiError if request fails
41
- * @returns Token information
42
- */
43
- export const getToken = async (
44
- chain: ChainKey | ChainId,
45
- token: string,
46
- options?: RequestOptions
47
- ): Promise<Token> => {
48
- if (!chain) {
49
- throw new SDKError(
50
- new ValidationError('Required parameter "chain" is missing.')
51
- )
52
- }
53
- if (!token) {
54
- throw new SDKError(
55
- new ValidationError('Required parameter "token" is missing.')
56
- )
41
+
42
+ interface TaskStatus {
43
+ data: {
44
+ status: 'DONE' | 'PENDING' | 'FAILED'
45
+ message?: string
46
+ metadata: { chainId: number; txHash?: Hash }
47
+ transactionStatus?: StatusResponse
57
48
  }
58
- return await request<Token>(
59
- `${config.get().apiUrl}/token?${new URLSearchParams({
60
- chain,
61
- token,
62
- } as Record<string, string>)}`,
63
- {
64
- signal: options?.signal,
49
+ }
50
+
51
+ interface RelayStatusRequest {
52
+ taskId: Hash
53
+ }
54
+
55
+ interface RelayRequest {
56
+ tokenOwner: Address
57
+ chainId: number
58
+ permit: PermitTransferFrom
59
+ witness: Witness
60
+ signedPermitData: Hex
61
+ callData: string
62
+ }
63
+
64
+ interface RelayResponse {
65
+ data: { taskId: Hash }
66
+ }
67
+
68
+ interface RelayerQuoteResponse {
69
+ data: {
70
+ quote: {
71
+ step: LiFiStep
72
+ permit: PermitTransferFrom
73
+ witness: Witness
74
+ permitData: PermitData
75
+ tokenOwner: Address
76
+ chainId: number
65
77
  }
66
- )
78
+ }
67
79
  }
68
80
 
69
81
  /**
@@ -124,6 +136,38 @@ export const getQuote = async (
124
136
  )
125
137
  }
126
138
 
139
+ /**
140
+ * Get a set of routes for a request that describes a transfer of tokens.
141
+ * @param params - A description of the transfer.
142
+ * @param options - Request options
143
+ * @returns The resulting routes that can be used to realize the described transfer of tokens.
144
+ * @throws {LiFiError} Throws a LiFiError if request fails.
145
+ */
146
+ export const getRoutes = async (
147
+ params: RoutesRequest,
148
+ options?: RequestOptions
149
+ ): Promise<RoutesResponse> => {
150
+ if (!isRoutesRequest(params)) {
151
+ throw new SDKError(new ValidationError('Invalid routes request.'))
152
+ }
153
+ const _config = config.get()
154
+ // apply defaults
155
+ params.options = {
156
+ integrator: _config.integrator,
157
+ ..._config.routeOptions,
158
+ ...params.options,
159
+ }
160
+
161
+ return await request<RoutesResponse>(`${_config.apiUrl}/advanced/routes`, {
162
+ method: 'POST',
163
+ headers: {
164
+ 'Content-Type': 'application/json',
165
+ },
166
+ body: JSON.stringify(params),
167
+ signal: options?.signal,
168
+ })
169
+ }
170
+
127
171
  /**
128
172
  * Get a quote for a destination contract call
129
173
  * @param params - The configuration of the requested destination call
@@ -187,6 +231,35 @@ export const getContractCallsQuote = async (
187
231
  })
188
232
  }
189
233
 
234
+ /**
235
+ * Get the transaction data for a single step of a route
236
+ * @param step - The step object.
237
+ * @param options - Request options
238
+ * @returns The step populated with the transaction data.
239
+ * @throws {LiFiError} Throws a LiFiError if request fails.
240
+ */
241
+ export const getStepTransaction = async (
242
+ step: LiFiStep,
243
+ options?: RequestOptions
244
+ ): Promise<LiFiStep> => {
245
+ if (!isStep(step)) {
246
+ // While the validation fails for some users we should not enforce it
247
+ console.warn('SDK Validation: Invalid Step', step)
248
+ }
249
+
250
+ return await request<LiFiStep>(
251
+ `${config.get().apiUrl}/advanced/stepTransaction`,
252
+ {
253
+ method: 'POST',
254
+ headers: {
255
+ 'Content-Type': 'application/json',
256
+ },
257
+ body: JSON.stringify(step),
258
+ signal: options?.signal,
259
+ }
260
+ )
261
+ }
262
+
190
263
  /**
191
264
  * Check the status of a transfer. For cross chain transfers, the "bridge" parameter is required.
192
265
  * @param params - Configuration of the requested status
@@ -215,125 +288,165 @@ export const getStatus = async (
215
288
  }
216
289
 
217
290
  /**
218
- * Get all available chains
219
- * @param params - The configuration of the requested chains
291
+ * Get a relayer quote for a token transfer
292
+ * @param params - The configuration of the requested quote
220
293
  * @param options - Request options
221
- * @returns A list of all available chains
222
- * @throws {LiFiError} Throws a LiFiError if request fails.
294
+ * @throws {LiFiError} - Throws a LiFiError if request fails
295
+ * @returns Relayer quote for a token transfer
223
296
  */
224
- export const getChains = async (
225
- params?: ChainsRequest,
297
+ export const getRelayerQuote = async (
298
+ params: QuoteRequest,
226
299
  options?: RequestOptions
227
- ): Promise<ExtendedChain[]> => {
228
- if (params) {
229
- for (const key of Object.keys(params)) {
230
- if (!params[key as keyof ChainsRequest]) {
231
- delete params[key as keyof ChainsRequest]
232
- }
300
+ ): Promise<RelayerQuoteResponse> => {
301
+ const requiredParameters: Array<keyof QuoteRequest> = [
302
+ 'fromChain',
303
+ 'fromToken',
304
+ 'fromAddress',
305
+ 'fromAmount',
306
+ 'toChain',
307
+ 'toToken',
308
+ ]
309
+ for (const requiredParameter of requiredParameters) {
310
+ if (!params[requiredParameter]) {
311
+ throw new SDKError(
312
+ new ValidationError(
313
+ `Required parameter "${requiredParameter}" is missing.`
314
+ )
315
+ )
233
316
  }
234
317
  }
235
- const urlSearchParams = new URLSearchParams(
236
- params as Record<string, string>
237
- ).toString()
238
- const response = await withDedupe(
239
- () =>
240
- request<ChainsResponse>(
241
- `${config.get().apiUrl}/chains?${urlSearchParams}`,
242
- {
243
- signal: options?.signal,
244
- }
245
- ),
246
- { id: `${getChains.name}.${urlSearchParams}` }
318
+ const _config = config.get()
319
+ // apply defaults
320
+ params.integrator ??= _config.integrator
321
+ params.order ??= _config.routeOptions?.order
322
+ params.slippage ??= _config.routeOptions?.slippage
323
+ params.referrer ??= _config.routeOptions?.referrer
324
+ params.fee ??= _config.routeOptions?.fee
325
+ params.allowBridges ??= _config.routeOptions?.bridges?.allow
326
+ params.denyBridges ??= _config.routeOptions?.bridges?.deny
327
+ params.preferBridges ??= _config.routeOptions?.bridges?.prefer
328
+ params.allowExchanges ??= _config.routeOptions?.exchanges?.allow
329
+ params.denyExchanges ??= _config.routeOptions?.exchanges?.deny
330
+ params.preferExchanges ??= _config.routeOptions?.exchanges?.prefer
331
+
332
+ for (const key of Object.keys(params)) {
333
+ if (!params[key as keyof QuoteRequest]) {
334
+ delete params[key as keyof QuoteRequest]
335
+ }
336
+ }
337
+
338
+ return await request<RelayerQuoteResponse>(
339
+ `${config.get().apiUrl}/relayer/quote?${new URLSearchParams(
340
+ params as unknown as Record<string, string>
341
+ )}`,
342
+ {
343
+ signal: options?.signal,
344
+ }
247
345
  )
248
- return response.chains
249
346
  }
250
347
 
251
348
  /**
252
- * Get a set of routes for a request that describes a transfer of tokens.
253
- * @param params - A description of the transfer.
349
+ * Relay a transaction through the relayer service
350
+ * @param params - The configuration for the relay request
254
351
  * @param options - Request options
255
- * @returns The resulting routes that can be used to realize the described transfer of tokens.
256
- * @throws {LiFiError} Throws a LiFiError if request fails.
352
+ * @throws {LiFiError} - Throws a LiFiError if request fails
353
+ * @returns Task ID for the relayed transaction
257
354
  */
258
- export const getRoutes = async (
259
- params: RoutesRequest,
355
+ export const relayTransaction = async (
356
+ params: RelayRequest,
260
357
  options?: RequestOptions
261
- ): Promise<RoutesResponse> => {
262
- if (!isRoutesRequest(params)) {
263
- throw new SDKError(new ValidationError('Invalid routes request.'))
264
- }
265
- const _config = config.get()
266
- // apply defaults
267
- params.options = {
268
- integrator: _config.integrator,
269
- ..._config.routeOptions,
270
- ...params.options,
358
+ ): Promise<RelayResponse> => {
359
+ const requiredParameters: Array<keyof RelayRequest> = [
360
+ 'tokenOwner',
361
+ 'chainId',
362
+ 'permit',
363
+ 'witness',
364
+ 'signedPermitData',
365
+ 'callData',
366
+ ]
367
+
368
+ for (const requiredParameter of requiredParameters) {
369
+ if (!params[requiredParameter]) {
370
+ throw new SDKError(
371
+ new ValidationError(
372
+ `Required parameter "${requiredParameter}" is missing.`
373
+ )
374
+ )
375
+ }
271
376
  }
272
377
 
273
- return await request<RoutesResponse>(`${_config.apiUrl}/advanced/routes`, {
378
+ return await request<RelayResponse>(`${config.get().apiUrl}/relayer/relay`, {
274
379
  method: 'POST',
275
380
  headers: {
276
381
  'Content-Type': 'application/json',
277
382
  },
278
- body: JSON.stringify(params),
383
+ body: JSON.stringify(params, (_, value) => {
384
+ if (typeof value === 'bigint') {
385
+ return value.toString()
386
+ }
387
+ return value
388
+ }),
279
389
  signal: options?.signal,
280
390
  })
281
391
  }
282
392
 
283
393
  /**
284
- * Get the transaction data for a single step of a route
285
- * @param step - The step object.
394
+ * Get the status of a relayed transaction
395
+ * @param params - Parameters for the relay status request
286
396
  * @param options - Request options
287
- * @returns The step populated with the transaction data.
288
- * @throws {LiFiError} Throws a LiFiError if request fails.
397
+ * @throws {LiFiError} - Throws a LiFiError if request fails
398
+ * @returns Status of the relayed transaction
289
399
  */
290
- export const getStepTransaction = async (
291
- step: LiFiStep,
400
+ export const getRelayedTransactionStatus = async (
401
+ params: RelayStatusRequest,
292
402
  options?: RequestOptions
293
- ): Promise<LiFiStep> => {
294
- if (!isStep(step)) {
295
- // While the validation fails for some users we should not enforce it
296
- console.warn('SDK Validation: Invalid Step', step)
403
+ ): Promise<TaskStatus> => {
404
+ if (!params.taskId) {
405
+ throw new SDKError(
406
+ new ValidationError('Required parameter "taskId" is missing.')
407
+ )
297
408
  }
298
409
 
299
- return await request<LiFiStep>(
300
- `${config.get().apiUrl}/advanced/stepTransaction`,
410
+ return await request<TaskStatus>(
411
+ `${config.get().apiUrl}/relayer/status/${params.taskId}`,
301
412
  {
302
- method: 'POST',
303
- headers: {
304
- 'Content-Type': 'application/json',
305
- },
306
- body: JSON.stringify(step),
307
413
  signal: options?.signal,
308
414
  }
309
415
  )
310
416
  }
311
417
 
312
418
  /**
313
- * Get the available tools to bridge and swap tokens.
314
- * @param params - The configuration of the requested tools
419
+ * Get all available chains
420
+ * @param params - The configuration of the requested chains
315
421
  * @param options - Request options
316
- * @returns The tools that are available on the requested chains
422
+ * @returns A list of all available chains
423
+ * @throws {LiFiError} Throws a LiFiError if request fails.
317
424
  */
318
- export const getTools = async (
319
- params?: ToolsRequest,
425
+ export const getChains = async (
426
+ params?: ChainsRequest,
320
427
  options?: RequestOptions
321
- ): Promise<ToolsResponse> => {
428
+ ): Promise<ExtendedChain[]> => {
322
429
  if (params) {
323
430
  for (const key of Object.keys(params)) {
324
- if (!params[key as keyof ToolsRequest]) {
325
- delete params[key as keyof ToolsRequest]
431
+ if (!params[key as keyof ChainsRequest]) {
432
+ delete params[key as keyof ChainsRequest]
326
433
  }
327
434
  }
328
435
  }
329
- return await request<ToolsResponse>(
330
- `${config.get().apiUrl}/tools?${new URLSearchParams(
331
- params as Record<string, string>
332
- )}`,
333
- {
334
- signal: options?.signal,
335
- }
436
+ const urlSearchParams = new URLSearchParams(
437
+ params as Record<string, string>
438
+ ).toString()
439
+ const response = await withDedupe(
440
+ () =>
441
+ request<ChainsResponse>(
442
+ `${config.get().apiUrl}/chains?${urlSearchParams}`,
443
+ {
444
+ signal: options?.signal,
445
+ }
446
+ ),
447
+ { id: `${getChains.name}.${urlSearchParams}` }
336
448
  )
449
+ return response.chains
337
450
  }
338
451
 
339
452
  /**
@@ -369,6 +482,67 @@ export const getTokens = async (
369
482
  return response
370
483
  }
371
484
 
485
+ /**
486
+ * Fetch information about a Token
487
+ * @param chain - Id or key of the chain that contains the token
488
+ * @param token - Address or symbol of the token on the requested chain
489
+ * @param options - Request options
490
+ * @throws {LiFiError} - Throws a LiFiError if request fails
491
+ * @returns Token information
492
+ */
493
+ export const getToken = async (
494
+ chain: ChainKey | ChainId,
495
+ token: string,
496
+ options?: RequestOptions
497
+ ): Promise<Token> => {
498
+ if (!chain) {
499
+ throw new SDKError(
500
+ new ValidationError('Required parameter "chain" is missing.')
501
+ )
502
+ }
503
+ if (!token) {
504
+ throw new SDKError(
505
+ new ValidationError('Required parameter "token" is missing.')
506
+ )
507
+ }
508
+ return await request<Token>(
509
+ `${config.get().apiUrl}/token?${new URLSearchParams({
510
+ chain,
511
+ token,
512
+ } as Record<string, string>)}`,
513
+ {
514
+ signal: options?.signal,
515
+ }
516
+ )
517
+ }
518
+
519
+ /**
520
+ * Get the available tools to bridge and swap tokens.
521
+ * @param params - The configuration of the requested tools
522
+ * @param options - Request options
523
+ * @returns The tools that are available on the requested chains
524
+ */
525
+ export const getTools = async (
526
+ params?: ToolsRequest,
527
+ options?: RequestOptions
528
+ ): Promise<ToolsResponse> => {
529
+ if (params) {
530
+ for (const key of Object.keys(params)) {
531
+ if (!params[key as keyof ToolsRequest]) {
532
+ delete params[key as keyof ToolsRequest]
533
+ }
534
+ }
535
+ }
536
+ return await request<ToolsResponse>(
537
+ `${config.get().apiUrl}/tools?${new URLSearchParams(
538
+ params as Record<string, string>
539
+ )}`,
540
+ {
541
+ signal: options?.signal,
542
+ }
543
+ )
544
+ }
545
+
372
546
  /**
373
547
  * Get gas recommendation for a certain chain
374
548
  * @param params - Configuration of the requested gas recommendation.