@lifi/sdk 3.5.2 → 3.6.0-beta.1
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.
- package/package.json +1 -1
- package/src/_cjs/constants.js +4 -2
- package/src/_cjs/constants.js.map +1 -1
- package/src/_cjs/core/EVM/EVM.js +0 -4
- package/src/_cjs/core/EVM/EVM.js.map +1 -1
- package/src/_cjs/core/EVM/EVMStepExecutor.js +156 -81
- package/src/_cjs/core/EVM/EVMStepExecutor.js.map +1 -1
- package/src/_cjs/core/EVM/abi.js +36 -43
- package/src/_cjs/core/EVM/abi.js.map +1 -1
- package/src/_cjs/core/EVM/checkAllowance.js +36 -30
- package/src/_cjs/core/EVM/checkAllowance.js.map +1 -1
- package/src/_cjs/core/EVM/getAllowance.js.map +1 -1
- package/src/_cjs/core/EVM/getEVMBalance.js.map +1 -1
- package/src/_cjs/core/EVM/getNativePermit.js +90 -0
- package/src/_cjs/core/EVM/getNativePermit.js.map +1 -0
- package/src/_cjs/core/EVM/parseEVMErrors.js +5 -2
- package/src/_cjs/core/EVM/parseEVMErrors.js.map +1 -1
- package/src/_cjs/core/EVM/permit2/allowanceTransfer.js +100 -0
- package/src/_cjs/core/EVM/permit2/allowanceTransfer.js.map +1 -0
- package/src/_cjs/core/EVM/permit2/constants.js +12 -0
- package/src/_cjs/core/EVM/permit2/constants.js.map +1 -0
- package/src/_cjs/core/EVM/permit2/domain.js +12 -0
- package/src/_cjs/core/EVM/permit2/domain.js.map +1 -0
- package/src/_cjs/core/EVM/permit2/signatureTransfer.js +121 -0
- package/src/_cjs/core/EVM/permit2/signatureTransfer.js.map +1 -0
- package/src/_cjs/core/EVM/setAllowance.js +3 -4
- package/src/_cjs/core/EVM/setAllowance.js.map +1 -1
- package/src/_cjs/core/EVM/signPermitMessage.js +169 -0
- package/src/_cjs/core/EVM/signPermitMessage.js.map +1 -0
- package/src/_cjs/core/EVM/typeguards.js +8 -0
- package/src/_cjs/core/EVM/typeguards.js.map +1 -0
- package/src/_cjs/core/EVM/types.js.map +1 -1
- package/src/_cjs/core/EVM/utils.js +2 -1
- package/src/_cjs/core/EVM/utils.js.map +1 -1
- package/src/_cjs/core/EVM/waitForBatchTransactionReceipt.js +32 -0
- package/src/_cjs/core/EVM/waitForBatchTransactionReceipt.js.map +1 -0
- package/src/_cjs/core/EVM/waitForRelayedTransactionReceipt.js +40 -0
- package/src/_cjs/core/EVM/waitForRelayedTransactionReceipt.js.map +1 -0
- package/src/_cjs/core/checkBalance.js +3 -3
- package/src/_cjs/core/checkBalance.js.map +1 -1
- package/src/_cjs/core/waitForTransactionStatus.js +4 -2
- package/src/_cjs/core/waitForTransactionStatus.js.map +1 -1
- package/src/_cjs/createConfig.js +2 -2
- package/src/_cjs/createConfig.js.map +1 -1
- package/src/_cjs/errors/constants.js +1 -0
- package/src/_cjs/errors/constants.js.map +1 -1
- package/src/_cjs/index.js +9 -6
- package/src/_cjs/index.js.map +1 -1
- package/src/_cjs/services/api.js +127 -53
- package/src/_cjs/services/api.js.map +1 -1
- package/src/_cjs/utils/checkPackageUpdates.js +20 -0
- package/src/_cjs/utils/checkPackageUpdates.js.map +1 -0
- package/src/_cjs/utils/convertQuoteToRoute.js +33 -0
- package/src/_cjs/utils/convertQuoteToRoute.js.map +1 -0
- package/src/_cjs/utils/fetchTxErrorDetails.js +13 -0
- package/src/_cjs/utils/fetchTxErrorDetails.js.map +1 -0
- package/src/_cjs/utils/invariant.js +17 -0
- package/src/_cjs/utils/invariant.js.map +1 -0
- package/src/_cjs/utils/waitForResult.js +16 -3
- package/src/_cjs/utils/waitForResult.js.map +1 -1
- package/src/_cjs/version.js +1 -1
- package/src/_cjs/version.js.map +1 -1
- package/src/_esm/constants.js +3 -1
- package/src/_esm/constants.js.map +1 -1
- package/src/_esm/core/EVM/EVM.js +0 -4
- package/src/_esm/core/EVM/EVM.js.map +1 -1
- package/src/_esm/core/EVM/EVMStepExecutor.js +186 -92
- package/src/_esm/core/EVM/EVMStepExecutor.js.map +1 -1
- package/src/_esm/core/EVM/abi.js +37 -42
- package/src/_esm/core/EVM/abi.js.map +1 -1
- package/src/_esm/core/EVM/checkAllowance.js +41 -32
- package/src/_esm/core/EVM/checkAllowance.js.map +1 -1
- package/src/_esm/core/EVM/getAllowance.js.map +1 -1
- package/src/_esm/core/EVM/getEVMBalance.js.map +1 -1
- package/src/_esm/core/EVM/getNativePermit.js +95 -0
- package/src/_esm/core/EVM/getNativePermit.js.map +1 -0
- package/src/_esm/core/EVM/parseEVMErrors.js +9 -1
- package/src/_esm/core/EVM/parseEVMErrors.js.map +1 -1
- package/src/_esm/core/EVM/permit2/allowanceTransfer.js +93 -0
- package/src/_esm/core/EVM/permit2/allowanceTransfer.js.map +1 -0
- package/src/_esm/core/EVM/permit2/constants.js +9 -0
- package/src/_esm/core/EVM/permit2/constants.js.map +1 -0
- package/src/_esm/core/EVM/permit2/domain.js +9 -0
- package/src/_esm/core/EVM/permit2/domain.js.map +1 -0
- package/src/_esm/core/EVM/permit2/signatureTransfer.js +117 -0
- package/src/_esm/core/EVM/permit2/signatureTransfer.js.map +1 -0
- package/src/_esm/core/EVM/setAllowance.js +3 -4
- package/src/_esm/core/EVM/setAllowance.js.map +1 -1
- package/src/_esm/core/EVM/signPermitMessage.js +163 -0
- package/src/_esm/core/EVM/signPermitMessage.js.map +1 -0
- package/src/_esm/core/EVM/typeguards.js +5 -0
- package/src/_esm/core/EVM/typeguards.js.map +1 -0
- package/src/_esm/core/EVM/types.js.map +1 -1
- package/src/_esm/core/EVM/utils.js +2 -1
- package/src/_esm/core/EVM/utils.js.map +1 -1
- package/src/_esm/core/EVM/waitForBatchTransactionReceipt.js +28 -0
- package/src/_esm/core/EVM/waitForBatchTransactionReceipt.js.map +1 -0
- package/src/_esm/core/EVM/waitForRelayedTransactionReceipt.js +36 -0
- package/src/_esm/core/EVM/waitForRelayedTransactionReceipt.js.map +1 -0
- package/src/_esm/core/checkBalance.js +3 -3
- package/src/_esm/core/checkBalance.js.map +1 -1
- package/src/_esm/core/waitForTransactionStatus.js +4 -2
- package/src/_esm/core/waitForTransactionStatus.js.map +1 -1
- package/src/_esm/createConfig.js +1 -1
- package/src/_esm/createConfig.js.map +1 -1
- package/src/_esm/errors/constants.js +1 -0
- package/src/_esm/errors/constants.js.map +1 -1
- package/src/_esm/index.js +4 -2
- package/src/_esm/index.js.map +1 -1
- package/src/_esm/services/api.js +165 -72
- package/src/_esm/services/api.js.map +1 -1
- package/src/_esm/utils/checkPackageUpdates.js +17 -0
- package/src/_esm/utils/checkPackageUpdates.js.map +1 -0
- package/src/_esm/utils/convertQuoteToRoute.js +37 -0
- package/src/_esm/utils/convertQuoteToRoute.js.map +1 -0
- package/src/_esm/utils/fetchTxErrorDetails.js +9 -0
- package/src/_esm/utils/fetchTxErrorDetails.js.map +1 -0
- package/src/_esm/utils/invariant.js +43 -0
- package/src/_esm/utils/invariant.js.map +1 -0
- package/src/_esm/utils/waitForResult.js +19 -3
- package/src/_esm/utils/waitForResult.js.map +1 -1
- package/src/_esm/version.js +1 -1
- package/src/_esm/version.js.map +1 -1
- package/src/_types/constants.d.ts +3 -1
- package/src/_types/constants.d.ts.map +1 -1
- package/src/_types/core/EVM/EVM.d.ts.map +1 -1
- package/src/_types/core/EVM/EVMStepExecutor.d.ts +7 -4
- package/src/_types/core/EVM/EVMStepExecutor.d.ts.map +1 -1
- package/src/_types/core/EVM/abi.d.ts +202 -5
- package/src/_types/core/EVM/abi.d.ts.map +1 -1
- package/src/_types/core/EVM/checkAllowance.d.ts +12 -2
- package/src/_types/core/EVM/checkAllowance.d.ts.map +1 -1
- package/src/_types/core/EVM/getAllowance.d.ts +5 -4
- package/src/_types/core/EVM/getAllowance.d.ts.map +1 -1
- package/src/_types/core/EVM/getEVMBalance.d.ts +2 -1
- package/src/_types/core/EVM/getEVMBalance.d.ts.map +1 -1
- package/src/_types/core/EVM/getNativePermit.d.ts +18 -0
- package/src/_types/core/EVM/getNativePermit.d.ts.map +1 -0
- package/src/_types/core/EVM/permit2/allowanceTransfer.d.ts +41 -0
- package/src/_types/core/EVM/permit2/allowanceTransfer.d.ts.map +1 -0
- package/src/_types/core/EVM/permit2/constants.d.ts +8 -0
- package/src/_types/core/EVM/permit2/constants.d.ts.map +1 -0
- package/src/_types/core/EVM/permit2/domain.d.ts +8 -0
- package/src/_types/core/EVM/permit2/domain.d.ts.map +1 -0
- package/src/_types/core/EVM/permit2/signatureTransfer.d.ts +42 -0
- package/src/_types/core/EVM/permit2/signatureTransfer.d.ts.map +1 -0
- package/src/_types/core/EVM/setAllowance.d.ts +2 -2
- package/src/_types/core/EVM/setAllowance.d.ts.map +1 -1
- package/src/_types/core/EVM/signPermitMessage.d.ts +25 -0
- package/src/_types/core/EVM/signPermitMessage.d.ts.map +1 -0
- package/src/_types/core/EVM/typeguards.d.ts +4 -0
- package/src/_types/core/EVM/typeguards.d.ts.map +1 -0
- package/src/_types/core/EVM/types.d.ts +8 -18
- package/src/_types/core/EVM/types.d.ts.map +1 -1
- package/src/_types/core/EVM/utils.d.ts +2 -2
- package/src/_types/core/EVM/utils.d.ts.map +1 -1
- package/src/_types/core/EVM/waitForBatchTransactionReceipt.d.ts +4 -0
- package/src/_types/core/EVM/waitForBatchTransactionReceipt.d.ts.map +1 -0
- package/src/_types/core/EVM/waitForRelayedTransactionReceipt.d.ts +4 -0
- package/src/_types/core/EVM/waitForRelayedTransactionReceipt.d.ts.map +1 -0
- package/src/_types/core/checkBalance.d.ts.map +1 -1
- package/src/_types/core/waitForTransactionStatus.d.ts.map +1 -1
- package/src/_types/createConfig.d.ts.map +1 -1
- package/src/_types/errors/constants.d.ts +2 -1
- package/src/_types/errors/constants.d.ts.map +1 -1
- package/src/_types/index.d.ts +5 -3
- package/src/_types/index.d.ts.map +1 -1
- package/src/_types/services/api.d.ts +93 -26
- package/src/_types/services/api.d.ts.map +1 -1
- package/src/_types/utils/checkPackageUpdates.d.ts +2 -0
- package/src/_types/utils/checkPackageUpdates.d.ts.map +1 -0
- package/src/_types/utils/convertQuoteToRoute.d.ts +11 -0
- package/src/_types/utils/convertQuoteToRoute.d.ts.map +1 -0
- package/src/_types/utils/fetchTxErrorDetails.d.ts +2 -0
- package/src/_types/utils/fetchTxErrorDetails.d.ts.map +1 -0
- package/src/_types/utils/invariant.d.ts +22 -0
- package/src/_types/utils/invariant.d.ts.map +1 -0
- package/src/_types/utils/waitForResult.d.ts +4 -1
- package/src/_types/utils/waitForResult.d.ts.map +1 -1
- package/src/_types/version.d.ts +1 -1
- package/src/_types/version.d.ts.map +1 -1
- package/src/constants.ts +6 -1
- package/src/core/EVM/EVM.ts +0 -4
- package/src/core/EVM/EVMStepExecutor.ts +239 -146
- package/src/core/EVM/abi.ts +40 -43
- package/src/core/EVM/checkAllowance.ts +96 -92
- package/src/core/EVM/getAllowance.ts +8 -8
- package/src/core/EVM/getEVMBalance.ts +2 -2
- package/src/core/EVM/getNativePermit.ts +114 -0
- package/src/core/EVM/parseEVMErrors.ts +9 -1
- package/src/core/EVM/permit2/allowanceTransfer.ts +168 -0
- package/src/core/EVM/permit2/constants.ts +11 -0
- package/src/core/EVM/permit2/domain.ts +20 -0
- package/src/core/EVM/permit2/signatureTransfer.ts +214 -0
- package/src/core/EVM/setAllowance.ts +14 -15
- package/src/core/EVM/signPermitMessage.ts +280 -0
- package/src/core/EVM/typeguards.ts +7 -0
- package/src/core/EVM/types.ts +11 -26
- package/src/core/EVM/utils.ts +4 -3
- package/src/core/EVM/waitForBatchTransactionReceipt.ts +61 -0
- package/src/core/EVM/waitForRelayedTransactionReceipt.ts +57 -0
- package/src/core/checkBalance.ts +6 -3
- package/src/core/waitForTransactionStatus.ts +6 -2
- package/src/createConfig.ts +1 -1
- package/src/errors/constants.ts +1 -0
- package/src/index.ts +4 -8
- package/src/services/api.ts +279 -105
- package/src/utils/checkPackageUpdates.ts +22 -0
- package/src/utils/convertQuoteToRoute.ts +45 -0
- package/src/utils/fetchTxErrorDetails.ts +10 -0
- package/src/utils/invariant.ts +51 -0
- package/src/utils/waitForResult.ts +22 -3
- package/src/version.ts +1 -1
- package/src/_cjs/core/EVM/multisig.js +0 -29
- package/src/_cjs/core/EVM/multisig.js.map +0 -1
- package/src/_cjs/helpers.js +0 -55
- package/src/_cjs/helpers.js.map +0 -1
- package/src/_esm/core/EVM/multisig.js +0 -25
- package/src/_esm/core/EVM/multisig.js.map +0 -1
- package/src/_esm/helpers.js +0 -58
- package/src/_esm/helpers.js.map +0 -1
- package/src/_types/core/EVM/multisig.d.ts +0 -6
- package/src/_types/core/EVM/multisig.d.ts.map +0 -1
- package/src/_types/helpers.d.ts +0 -13
- package/src/_types/helpers.d.ts.map +0 -1
- package/src/core/EVM/multisig.ts +0 -54
- 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,57 @@
|
|
|
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(
|
|
17
|
+
async () => {
|
|
18
|
+
const result = await getRelayedTransactionStatus({
|
|
19
|
+
taskId,
|
|
20
|
+
}).catch((e) => {
|
|
21
|
+
if (process.env.NODE_ENV === 'development') {
|
|
22
|
+
console.debug('Fetching status from relayer failed.', e)
|
|
23
|
+
}
|
|
24
|
+
return undefined
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
switch (result?.data.status) {
|
|
28
|
+
case 'PENDING':
|
|
29
|
+
return undefined
|
|
30
|
+
case 'DONE': {
|
|
31
|
+
const sending: ExtendedTransactionInfo | undefined = result?.data
|
|
32
|
+
.transactionStatus?.sending as ExtendedTransactionInfo
|
|
33
|
+
return {
|
|
34
|
+
status: 'success',
|
|
35
|
+
gasUsed: sending?.gasUsed,
|
|
36
|
+
transactionHash: result?.data.metadata.txHash,
|
|
37
|
+
} as unknown as WalletCallReceipt
|
|
38
|
+
}
|
|
39
|
+
case 'FAILED':
|
|
40
|
+
throw new TransactionError(
|
|
41
|
+
LiFiErrorCode.TransactionFailed,
|
|
42
|
+
'Transaction was reverted.'
|
|
43
|
+
)
|
|
44
|
+
default:
|
|
45
|
+
throw new TransactionError(
|
|
46
|
+
LiFiErrorCode.TransactionNotFound,
|
|
47
|
+
'Transaction not found.'
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
5000,
|
|
52
|
+
3,
|
|
53
|
+
(_, error) => {
|
|
54
|
+
return !(error instanceof TransactionError)
|
|
55
|
+
}
|
|
56
|
+
)
|
|
57
|
+
}
|
package/src/core/checkBalance.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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(
|
|
69
|
+
throw new ServerError(
|
|
70
|
+
"Status doesn't contain destination chain information."
|
|
71
|
+
)
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
return resolvedStatus
|
package/src/createConfig.ts
CHANGED
|
@@ -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) {
|
package/src/errors/constants.ts
CHANGED
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
|
-
|
|
70
|
-
|
|
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,
|
package/src/services/api.ts
CHANGED
|
@@ -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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
|
219
|
-
* @param params - The configuration of the requested
|
|
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
|
-
* @
|
|
222
|
-
* @
|
|
294
|
+
* @throws {LiFiError} - Throws a LiFiError if request fails
|
|
295
|
+
* @returns Relayer quote for a token transfer
|
|
223
296
|
*/
|
|
224
|
-
export const
|
|
225
|
-
params
|
|
297
|
+
export const getRelayerQuote = async (
|
|
298
|
+
params: QuoteRequest,
|
|
226
299
|
options?: RequestOptions
|
|
227
|
-
): Promise<
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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
|
-
*
|
|
253
|
-
* @param params -
|
|
349
|
+
* Relay a transaction through the relayer service
|
|
350
|
+
* @param params - The configuration for the relay request
|
|
254
351
|
* @param options - Request options
|
|
255
|
-
* @
|
|
256
|
-
* @
|
|
352
|
+
* @throws {LiFiError} - Throws a LiFiError if request fails
|
|
353
|
+
* @returns Task ID for the relayed transaction
|
|
257
354
|
*/
|
|
258
|
-
export const
|
|
259
|
-
params:
|
|
355
|
+
export const relayTransaction = async (
|
|
356
|
+
params: RelayRequest,
|
|
260
357
|
options?: RequestOptions
|
|
261
|
-
): Promise<
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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<
|
|
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
|
|
285
|
-
* @param
|
|
394
|
+
* Get the status of a relayed transaction
|
|
395
|
+
* @param params - Parameters for the relay status request
|
|
286
396
|
* @param options - Request options
|
|
287
|
-
* @
|
|
288
|
-
* @
|
|
397
|
+
* @throws {LiFiError} - Throws a LiFiError if request fails
|
|
398
|
+
* @returns Status of the relayed transaction
|
|
289
399
|
*/
|
|
290
|
-
export const
|
|
291
|
-
|
|
400
|
+
export const getRelayedTransactionStatus = async (
|
|
401
|
+
params: RelayStatusRequest,
|
|
292
402
|
options?: RequestOptions
|
|
293
|
-
): Promise<
|
|
294
|
-
if (!
|
|
295
|
-
|
|
296
|
-
|
|
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<
|
|
300
|
-
`${config.get().apiUrl}/
|
|
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
|
|
314
|
-
* @param params - The configuration of the requested
|
|
419
|
+
* Get all available chains
|
|
420
|
+
* @param params - The configuration of the requested chains
|
|
315
421
|
* @param options - Request options
|
|
316
|
-
* @returns
|
|
422
|
+
* @returns A list of all available chains
|
|
423
|
+
* @throws {LiFiError} Throws a LiFiError if request fails.
|
|
317
424
|
*/
|
|
318
|
-
export const
|
|
319
|
-
params?:
|
|
425
|
+
export const getChains = async (
|
|
426
|
+
params?: ChainsRequest,
|
|
320
427
|
options?: RequestOptions
|
|
321
|
-
): Promise<
|
|
428
|
+
): Promise<ExtendedChain[]> => {
|
|
322
429
|
if (params) {
|
|
323
430
|
for (const key of Object.keys(params)) {
|
|
324
|
-
if (!params[key as keyof
|
|
325
|
-
delete params[key as keyof
|
|
431
|
+
if (!params[key as keyof ChainsRequest]) {
|
|
432
|
+
delete params[key as keyof ChainsRequest]
|
|
326
433
|
}
|
|
327
434
|
}
|
|
328
435
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
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.
|