@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.
- package/package.json +6 -3
- 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 +38 -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/_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 +34 -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/_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/constants.ts +6 -1
- package/src/core/EVM/EVM.ts +0 -4
- package/src/core/EVM/EVMStepExecutor.ts +242 -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 +50 -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,22 @@
|
|
|
1
|
+
import { name, version } from '../version.js'
|
|
2
|
+
|
|
3
|
+
export const checkPackageUpdates = async (
|
|
4
|
+
packageName?: string,
|
|
5
|
+
packageVersion?: string
|
|
6
|
+
) => {
|
|
7
|
+
try {
|
|
8
|
+
const pkgName = packageName ?? name
|
|
9
|
+
const response = await fetch(`https://registry.npmjs.org/${pkgName}/latest`)
|
|
10
|
+
const reponseBody = await response.json()
|
|
11
|
+
const latestVersion = reponseBody.version
|
|
12
|
+
const currentVersion = packageVersion ?? version
|
|
13
|
+
|
|
14
|
+
if (latestVersion > currentVersion) {
|
|
15
|
+
console.warn(
|
|
16
|
+
`${pkgName}: new package version is available. Please update as soon as possible to enjoy the newest features. Current version: ${currentVersion}. Latest version: ${latestVersion}.`
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
} catch (_error) {
|
|
20
|
+
// Cannot verify version, might be network error etc. We don't bother showing anything in that case
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { LiFiStep, Route } from '@lifi/types'
|
|
2
|
+
import { SDKError } from '../errors/SDKError.js'
|
|
3
|
+
import { ValidationError } from '../errors/errors.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Converts a quote to Route
|
|
7
|
+
* @param quote - Step returned from the quote endpoint.
|
|
8
|
+
* @param txHash
|
|
9
|
+
* @param chainId
|
|
10
|
+
* @returns - The route to be executed.
|
|
11
|
+
* @throws {BaseError} Throws a ValidationError if the step has missing values.
|
|
12
|
+
*/
|
|
13
|
+
export const convertQuoteToRoute = (quote: LiFiStep): Route => {
|
|
14
|
+
if (!quote.estimate.fromAmountUSD) {
|
|
15
|
+
throw new SDKError(
|
|
16
|
+
new ValidationError("Missing 'fromAmountUSD' in step estimate.")
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (!quote.estimate.toAmountUSD) {
|
|
21
|
+
throw new SDKError(
|
|
22
|
+
new ValidationError("Missing 'toAmountUSD' in step estimate.")
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const route: Route = {
|
|
27
|
+
id: quote.id,
|
|
28
|
+
fromChainId: quote.action.fromToken.chainId,
|
|
29
|
+
fromToken: quote.action.fromToken,
|
|
30
|
+
fromAmount: quote.action.fromAmount,
|
|
31
|
+
fromAmountUSD: quote.estimate.fromAmountUSD,
|
|
32
|
+
fromAddress: quote.action.fromAddress,
|
|
33
|
+
toChainId: quote.action.toToken.chainId,
|
|
34
|
+
toToken: quote.action.toToken,
|
|
35
|
+
toAmount: quote.estimate.toAmount,
|
|
36
|
+
toAmountMin: quote.estimate.toAmountMin,
|
|
37
|
+
toAmountUSD: quote.estimate.toAmountUSD,
|
|
38
|
+
toAddress: quote.action.toAddress || quote.action.fromAddress,
|
|
39
|
+
gasCostUSD: quote.estimate.gasCosts?.[0].amountUSD,
|
|
40
|
+
steps: [quote],
|
|
41
|
+
insurance: { state: 'NOT_INSURABLE', feeAmountUsd: '0' },
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return route
|
|
45
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const fetchTxErrorDetails = async (txHash: string, chainId: number) => {
|
|
2
|
+
try {
|
|
3
|
+
const response = await fetch(
|
|
4
|
+
`https://api.tenderly.co/api/v1/public-contract/${chainId}/tx/${txHash}`
|
|
5
|
+
)
|
|
6
|
+
const reponseBody = await response.json()
|
|
7
|
+
|
|
8
|
+
return reponseBody
|
|
9
|
+
} catch (_) {}
|
|
10
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// https://github.com/alexreardon/tiny-invariant
|
|
2
|
+
|
|
3
|
+
const isProduction: boolean = process.env.NODE_ENV === 'production'
|
|
4
|
+
const prefix: string = 'Invariant failed'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `invariant` is used to [assert](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions) that the `condition` is [truthy](https://github.com/getify/You-Dont-Know-JS/blob/bdbe570600d4e1107d0b131787903ca1c9ec8140/up%20%26%20going/ch2.md#truthy--falsy).
|
|
8
|
+
*
|
|
9
|
+
* 💥 `invariant` will `throw` an `Error` if the `condition` is [falsey](https://github.com/getify/You-Dont-Know-JS/blob/bdbe570600d4e1107d0b131787903ca1c9ec8140/up%20%26%20going/ch2.md#truthy--falsy)
|
|
10
|
+
*
|
|
11
|
+
* 🤏 `message`s are not displayed in production environments to help keep bundles small
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* const value: Person | null = { name: 'Alex' };
|
|
17
|
+
* invariant(value, 'Expected value to be a person');
|
|
18
|
+
* // type of `value`` has been narrowed to `Person`
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function invariant(
|
|
22
|
+
condition: any,
|
|
23
|
+
// Not providing an inline default argument for message as the result is smaller
|
|
24
|
+
/**
|
|
25
|
+
* Can provide a string, or a function that returns a string for cases where
|
|
26
|
+
* the message takes a fair amount of effort to compute
|
|
27
|
+
*/
|
|
28
|
+
message?: string | (() => string)
|
|
29
|
+
): asserts condition {
|
|
30
|
+
if (condition) {
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
// Condition not passed
|
|
34
|
+
|
|
35
|
+
// In production we strip the message but still throw
|
|
36
|
+
if (isProduction) {
|
|
37
|
+
throw new Error(prefix)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// When not in production we allow the message to pass through
|
|
41
|
+
// *This block will be removed in production builds*
|
|
42
|
+
|
|
43
|
+
const provided: string | undefined =
|
|
44
|
+
typeof message === 'function' ? message() : message
|
|
45
|
+
|
|
46
|
+
// Options:
|
|
47
|
+
// 1. message provided: `${prefix}: ${provided}`
|
|
48
|
+
// 2. message not provided: prefix
|
|
49
|
+
const value: string = provided ? `${prefix}: ${provided}` : prefix
|
|
50
|
+
throw new Error(value)
|
|
51
|
+
}
|
|
@@ -4,18 +4,37 @@ import { sleep } from './sleep.js'
|
|
|
4
4
|
* Repeatedly calls a given asynchronous function until it resolves with a value
|
|
5
5
|
* @param fn The function that should be repeated
|
|
6
6
|
* @param interval The timeout in milliseconds between retries, defaults to 5000
|
|
7
|
+
* @param maxRetries Maximum number of retries before throwing an error, defaults to 3
|
|
8
|
+
* @param shouldRetry Optional predicate to determine if an error should trigger a retry
|
|
7
9
|
* @returns The result of the fn function
|
|
10
|
+
* @throws Error if maximum retries is reached, if function keeps returning undefined, or if shouldRetry returns false
|
|
8
11
|
*/
|
|
9
12
|
export const waitForResult = async <T>(
|
|
10
13
|
fn: () => Promise<T | undefined>,
|
|
11
|
-
interval = 5000
|
|
14
|
+
interval = 5000,
|
|
15
|
+
maxRetries = 3,
|
|
16
|
+
shouldRetry: (count: number, error: unknown) => boolean = () => true
|
|
12
17
|
): Promise<T> => {
|
|
13
18
|
let result: T | undefined
|
|
19
|
+
let attempts = 0
|
|
20
|
+
|
|
14
21
|
while (!result) {
|
|
15
|
-
|
|
16
|
-
|
|
22
|
+
try {
|
|
23
|
+
result = await fn()
|
|
24
|
+
if (!result) {
|
|
25
|
+
await sleep(interval)
|
|
26
|
+
}
|
|
27
|
+
} catch (error) {
|
|
28
|
+
if (!shouldRetry(attempts, error)) {
|
|
29
|
+
throw error
|
|
30
|
+
}
|
|
31
|
+
attempts++
|
|
32
|
+
if (attempts === maxRetries) {
|
|
33
|
+
throw error
|
|
34
|
+
}
|
|
17
35
|
await sleep(interval)
|
|
18
36
|
}
|
|
19
37
|
}
|
|
38
|
+
|
|
20
39
|
return result
|
|
21
40
|
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/sdk'
|
|
2
|
-
export const version = '3.
|
|
2
|
+
export const version = '3.6.0-beta.0'
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateMultisigRouteProcess = void 0;
|
|
4
|
-
const constants_js_1 = require("../../errors/constants.js");
|
|
5
|
-
const errors_js_1 = require("../../errors/errors.js");
|
|
6
|
-
const updateMultisigRouteProcess = async (internalTxHash, step, processType, fromChain, statusManager, multisig) => {
|
|
7
|
-
if (!multisig?.getMultisigTransactionDetails) {
|
|
8
|
-
throw new Error('getMultisigTransactionDetails is missing in multisig config.');
|
|
9
|
-
}
|
|
10
|
-
const updateIntermediateMultisigStatus = () => {
|
|
11
|
-
statusManager.updateProcess(step, processType, 'PENDING');
|
|
12
|
-
};
|
|
13
|
-
const multisigStatusResponse = await multisig?.getMultisigTransactionDetails(internalTxHash, fromChain.id, updateIntermediateMultisigStatus);
|
|
14
|
-
if (multisigStatusResponse.status === 'DONE') {
|
|
15
|
-
statusManager.updateProcess(step, processType, 'PENDING', {
|
|
16
|
-
txHash: multisigStatusResponse.txHash,
|
|
17
|
-
multisigTxHash: undefined,
|
|
18
|
-
txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${multisigStatusResponse.txHash}`,
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
if (multisigStatusResponse.status === 'FAILED') {
|
|
22
|
-
throw new errors_js_1.TransactionError(constants_js_1.LiFiErrorCode.TransactionFailed, 'Multisig transaction failed.');
|
|
23
|
-
}
|
|
24
|
-
if (multisigStatusResponse.status === 'CANCELLED') {
|
|
25
|
-
throw new errors_js_1.TransactionError(constants_js_1.LiFiErrorCode.SignatureRejected, 'Transaction was rejected by user.');
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
exports.updateMultisigRouteProcess = updateMultisigRouteProcess;
|
|
29
|
-
//# sourceMappingURL=multisig.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"multisig.js","sourceRoot":"","sources":["../../../core/EVM/multisig.ts"],"names":[],"mappings":";;;AAEA,4DAAyD;AACzD,sDAAyD;AAIlD,MAAM,0BAA0B,GAAG,KAAK,EAC7C,cAAoB,EACpB,IAAc,EACd,WAAwB,EACxB,SAAwB,EACxB,aAA4B,EAC5B,QAAyB,EACzB,EAAE;IACF,IAAI,CAAC,QAAQ,EAAE,6BAA6B,EAAE,CAAC;QAC7C,MAAM,IAAI,KAAK,CACb,8DAA8D,CAC/D,CAAA;IACH,CAAC;IAED,MAAM,gCAAgC,GAAG,GAAG,EAAE;QAC5C,aAAa,CAAC,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE,SAAS,CAAC,CAAA;IAC3D,CAAC,CAAA;IAED,MAAM,sBAAsB,GAC1B,MAAM,QAAQ,EAAE,6BAA6B,CAC3C,cAAc,EACd,SAAS,CAAC,EAAE,EACZ,gCAAgC,CACjC,CAAA;IAEH,IAAI,sBAAsB,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;QAC7C,aAAa,CAAC,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE;YACxD,MAAM,EAAE,sBAAsB,CAAC,MAAM;YACrC,cAAc,EAAE,SAAS;YACzB,MAAM,EAAE,GAAG,SAAS,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,MAAM,sBAAsB,CAAC,MAAM,EAAE;SACxF,CAAC,CAAA;IACJ,CAAC;IAED,IAAI,sBAAsB,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/C,MAAM,IAAI,4BAAgB,CACxB,4BAAa,CAAC,iBAAiB,EAC/B,8BAA8B,CAC/B,CAAA;IACH,CAAC;IAED,IAAI,sBAAsB,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;QAClD,MAAM,IAAI,4BAAgB,CACxB,4BAAa,CAAC,iBAAiB,EAC/B,mCAAmC,CACpC,CAAA;IACH,CAAC;AACH,CAAC,CAAA;AA9CY,QAAA,0BAA0B,8BA8CtC"}
|
package/src/_cjs/helpers.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchTxErrorDetails = exports.convertQuoteToRoute = exports.checkPackageUpdates = void 0;
|
|
4
|
-
const SDKError_js_1 = require("./errors/SDKError.js");
|
|
5
|
-
const errors_js_1 = require("./errors/errors.js");
|
|
6
|
-
const version_js_1 = require("./version.js");
|
|
7
|
-
const checkPackageUpdates = async (packageName, packageVersion) => {
|
|
8
|
-
try {
|
|
9
|
-
const pkgName = packageName ?? version_js_1.name;
|
|
10
|
-
const response = await fetch(`https://registry.npmjs.org/${pkgName}/latest`);
|
|
11
|
-
const reponseBody = await response.json();
|
|
12
|
-
const latestVersion = reponseBody.version;
|
|
13
|
-
const currentVersion = packageVersion ?? version_js_1.version;
|
|
14
|
-
if (latestVersion > currentVersion) {
|
|
15
|
-
console.warn(`${pkgName}: new package version is available. Please update as soon as possible to enjoy the newest features. Current version: ${currentVersion}. Latest version: ${latestVersion}.`);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
catch (_error) {
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
exports.checkPackageUpdates = checkPackageUpdates;
|
|
22
|
-
const convertQuoteToRoute = (step) => {
|
|
23
|
-
if (!step.estimate.fromAmountUSD) {
|
|
24
|
-
throw new SDKError_js_1.SDKError(new errors_js_1.ValidationError("Missing 'fromAmountUSD' in step estimate."));
|
|
25
|
-
}
|
|
26
|
-
if (!step.estimate.toAmountUSD) {
|
|
27
|
-
throw new SDKError_js_1.SDKError(new errors_js_1.ValidationError("Missing 'toAmountUSD' in step estimate."));
|
|
28
|
-
}
|
|
29
|
-
const route = {
|
|
30
|
-
fromToken: step.action.fromToken,
|
|
31
|
-
toToken: step.action.toToken,
|
|
32
|
-
fromAmount: step.action.fromAmount,
|
|
33
|
-
toAmount: step.estimate.toAmount,
|
|
34
|
-
id: step.id,
|
|
35
|
-
fromChainId: step.action.fromToken.chainId,
|
|
36
|
-
toChainId: step.action.toToken.chainId,
|
|
37
|
-
fromAmountUSD: step.estimate.fromAmountUSD,
|
|
38
|
-
toAmountUSD: step.estimate.toAmountUSD,
|
|
39
|
-
steps: [step],
|
|
40
|
-
toAmountMin: step.estimate.toAmountMin,
|
|
41
|
-
insurance: { state: 'NOT_INSURABLE', feeAmountUsd: '0' },
|
|
42
|
-
};
|
|
43
|
-
return route;
|
|
44
|
-
};
|
|
45
|
-
exports.convertQuoteToRoute = convertQuoteToRoute;
|
|
46
|
-
const fetchTxErrorDetails = async (txHash, chainId) => {
|
|
47
|
-
try {
|
|
48
|
-
const response = await fetch(`https://api.tenderly.co/api/v1/public-contract/${chainId}/tx/${txHash}`);
|
|
49
|
-
const reponseBody = await response.json();
|
|
50
|
-
return reponseBody;
|
|
51
|
-
}
|
|
52
|
-
catch (_) { }
|
|
53
|
-
};
|
|
54
|
-
exports.fetchTxErrorDetails = fetchTxErrorDetails;
|
|
55
|
-
//# sourceMappingURL=helpers.js.map
|
package/src/_cjs/helpers.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../helpers.ts"],"names":[],"mappings":";;;AACA,sDAA+C;AAC/C,kDAAoD;AACpD,6CAA4C;AAErC,MAAM,mBAAmB,GAAG,KAAK,EACtC,WAAoB,EACpB,cAAuB,EACvB,EAAE;IACF,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,WAAW,IAAI,iBAAI,CAAA;QACnC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,8BAA8B,OAAO,SAAS,CAAC,CAAA;QAC5E,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;QACzC,MAAM,aAAa,GAAG,WAAW,CAAC,OAAO,CAAA;QACzC,MAAM,cAAc,GAAG,cAAc,IAAI,oBAAO,CAAA;QAEhD,IAAI,aAAa,GAAG,cAAc,EAAE,CAAC;YACnC,OAAO,CAAC,IAAI,CACV,GAAG,OAAO,wHAAwH,cAAc,qBAAqB,aAAa,GAAG,CACtL,CAAA;QACH,CAAC;IACH,CAAC;IAAC,OAAO,MAAM,EAAE,CAAC;IAElB,CAAC;AACH,CAAC,CAAA;AAnBY,QAAA,mBAAmB,uBAmB/B;AAUM,MAAM,mBAAmB,GAAG,CAAC,IAAc,EAAS,EAAE;IAC3D,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC;QACjC,MAAM,IAAI,sBAAQ,CAChB,IAAI,2BAAe,CAAC,2CAA2C,CAAC,CACjE,CAAA;IACH,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC;QAC/B,MAAM,IAAI,sBAAQ,CAChB,IAAI,2BAAe,CAAC,yCAAyC,CAAC,CAC/D,CAAA;IACH,CAAC;IAED,MAAM,KAAK,GAAU;QACnB,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS;QAChC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;QAC5B,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU;QAClC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ;QAChC,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO;QAC1C,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO;QACtC,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,aAAa;QAC1C,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,WAAW;QACtC,KAAK,EAAE,CAAC,IAAI,CAAC;QACb,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,WAAW;QACtC,SAAS,EAAE,EAAE,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,GAAG,EAAE;KACzD,CAAA;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AA7BY,QAAA,mBAAmB,uBA6B/B;AAEM,MAAM,mBAAmB,GAAG,KAAK,EAAE,MAAc,EAAE,OAAe,EAAE,EAAE;IAC3E,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAC1B,kDAAkD,OAAO,OAAO,MAAM,EAAE,CACzE,CAAA;QACD,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;QAEzC,OAAO,WAAW,CAAA;IACpB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC,CAAA,CAAC;AAChB,CAAC,CAAA;AATY,QAAA,mBAAmB,uBAS/B"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { LiFiErrorCode } from '../../errors/constants.js';
|
|
2
|
-
import { TransactionError } from '../../errors/errors.js';
|
|
3
|
-
export const updateMultisigRouteProcess = async (internalTxHash, step, processType, fromChain, statusManager, multisig) => {
|
|
4
|
-
if (!multisig?.getMultisigTransactionDetails) {
|
|
5
|
-
throw new Error('getMultisigTransactionDetails is missing in multisig config.');
|
|
6
|
-
}
|
|
7
|
-
const updateIntermediateMultisigStatus = () => {
|
|
8
|
-
statusManager.updateProcess(step, processType, 'PENDING');
|
|
9
|
-
};
|
|
10
|
-
const multisigStatusResponse = await multisig?.getMultisigTransactionDetails(internalTxHash, fromChain.id, updateIntermediateMultisigStatus);
|
|
11
|
-
if (multisigStatusResponse.status === 'DONE') {
|
|
12
|
-
statusManager.updateProcess(step, processType, 'PENDING', {
|
|
13
|
-
txHash: multisigStatusResponse.txHash,
|
|
14
|
-
multisigTxHash: undefined,
|
|
15
|
-
txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${multisigStatusResponse.txHash}`,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
if (multisigStatusResponse.status === 'FAILED') {
|
|
19
|
-
throw new TransactionError(LiFiErrorCode.TransactionFailed, 'Multisig transaction failed.');
|
|
20
|
-
}
|
|
21
|
-
if (multisigStatusResponse.status === 'CANCELLED') {
|
|
22
|
-
throw new TransactionError(LiFiErrorCode.SignatureRejected, 'Transaction was rejected by user.');
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=multisig.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"multisig.js","sourceRoot":"","sources":["../../../core/EVM/multisig.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAIzD,MAAM,CAAC,MAAM,0BAA0B,GAAG,KAAK,EAC7C,cAAoB,EACpB,IAAc,EACd,WAAwB,EACxB,SAAwB,EACxB,aAA4B,EAC5B,QAAyB,EACzB,EAAE;IACF,IAAI,CAAC,QAAQ,EAAE,6BAA6B,EAAE,CAAC;QAC7C,MAAM,IAAI,KAAK,CACb,8DAA8D,CAC/D,CAAA;IACH,CAAC;IAED,MAAM,gCAAgC,GAAG,GAAG,EAAE;QAC5C,aAAa,CAAC,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE,SAAS,CAAC,CAAA;IAC3D,CAAC,CAAA;IAED,MAAM,sBAAsB,GAC1B,MAAM,QAAQ,EAAE,6BAA6B,CAC3C,cAAc,EACd,SAAS,CAAC,EAAE,EACZ,gCAAgC,CACjC,CAAA;IAEH,IAAI,sBAAsB,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;QAC7C,aAAa,CAAC,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE;YACxD,MAAM,EAAE,sBAAsB,CAAC,MAAM;YACrC,cAAc,EAAE,SAAS;YACzB,MAAM,EAAE,GAAG,SAAS,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,MAAM,sBAAsB,CAAC,MAAM,EAAE;SACxF,CAAC,CAAA;IACJ,CAAC;IAED,IAAI,sBAAsB,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/C,MAAM,IAAI,gBAAgB,CACxB,aAAa,CAAC,iBAAiB,EAC/B,8BAA8B,CAC/B,CAAA;IACH,CAAC;IAED,IAAI,sBAAsB,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;QAClD,MAAM,IAAI,gBAAgB,CACxB,aAAa,CAAC,iBAAiB,EAC/B,mCAAmC,CACpC,CAAA;IACH,CAAC;AACH,CAAC,CAAA"}
|
package/src/_esm/helpers.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { SDKError } from './errors/SDKError.js';
|
|
2
|
-
import { ValidationError } from './errors/errors.js';
|
|
3
|
-
import { name, version } from './version.js';
|
|
4
|
-
export const checkPackageUpdates = async (packageName, packageVersion) => {
|
|
5
|
-
try {
|
|
6
|
-
const pkgName = packageName ?? name;
|
|
7
|
-
const response = await fetch(`https://registry.npmjs.org/${pkgName}/latest`);
|
|
8
|
-
const reponseBody = await response.json();
|
|
9
|
-
const latestVersion = reponseBody.version;
|
|
10
|
-
const currentVersion = packageVersion ?? version;
|
|
11
|
-
if (latestVersion > currentVersion) {
|
|
12
|
-
console.warn(`${pkgName}: new package version is available. Please update as soon as possible to enjoy the newest features. Current version: ${currentVersion}. Latest version: ${latestVersion}.`);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
catch (_error) {
|
|
16
|
-
// Cannot verify version, might be network error etc. We don't bother showing anything in that case
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Converts a quote to Route
|
|
21
|
-
* @param step - Step returned from the quote endpoint.
|
|
22
|
-
* @param txHash
|
|
23
|
-
* @param chainId
|
|
24
|
-
* @returns - The route to be executed.
|
|
25
|
-
* @throws {BaseError} Throws a ValidationError if the step has missing values.
|
|
26
|
-
*/
|
|
27
|
-
export const convertQuoteToRoute = (step) => {
|
|
28
|
-
if (!step.estimate.fromAmountUSD) {
|
|
29
|
-
throw new SDKError(new ValidationError("Missing 'fromAmountUSD' in step estimate."));
|
|
30
|
-
}
|
|
31
|
-
if (!step.estimate.toAmountUSD) {
|
|
32
|
-
throw new SDKError(new ValidationError("Missing 'toAmountUSD' in step estimate."));
|
|
33
|
-
}
|
|
34
|
-
const route = {
|
|
35
|
-
fromToken: step.action.fromToken,
|
|
36
|
-
toToken: step.action.toToken,
|
|
37
|
-
fromAmount: step.action.fromAmount,
|
|
38
|
-
toAmount: step.estimate.toAmount,
|
|
39
|
-
id: step.id,
|
|
40
|
-
fromChainId: step.action.fromToken.chainId,
|
|
41
|
-
toChainId: step.action.toToken.chainId,
|
|
42
|
-
fromAmountUSD: step.estimate.fromAmountUSD,
|
|
43
|
-
toAmountUSD: step.estimate.toAmountUSD,
|
|
44
|
-
steps: [step],
|
|
45
|
-
toAmountMin: step.estimate.toAmountMin,
|
|
46
|
-
insurance: { state: 'NOT_INSURABLE', feeAmountUsd: '0' },
|
|
47
|
-
};
|
|
48
|
-
return route;
|
|
49
|
-
};
|
|
50
|
-
export const fetchTxErrorDetails = async (txHash, chainId) => {
|
|
51
|
-
try {
|
|
52
|
-
const response = await fetch(`https://api.tenderly.co/api/v1/public-contract/${chainId}/tx/${txHash}`);
|
|
53
|
-
const reponseBody = await response.json();
|
|
54
|
-
return reponseBody;
|
|
55
|
-
}
|
|
56
|
-
catch (_) { }
|
|
57
|
-
};
|
|
58
|
-
//# sourceMappingURL=helpers.js.map
|
package/src/_esm/helpers.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE5C,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EACtC,WAAoB,EACpB,cAAuB,EACvB,EAAE;IACF,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,WAAW,IAAI,IAAI,CAAA;QACnC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,8BAA8B,OAAO,SAAS,CAAC,CAAA;QAC5E,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;QACzC,MAAM,aAAa,GAAG,WAAW,CAAC,OAAO,CAAA;QACzC,MAAM,cAAc,GAAG,cAAc,IAAI,OAAO,CAAA;QAEhD,IAAI,aAAa,GAAG,cAAc,EAAE,CAAC;YACnC,OAAO,CAAC,IAAI,CACV,GAAG,OAAO,wHAAwH,cAAc,qBAAqB,aAAa,GAAG,CACtL,CAAA;QACH,CAAC;IACH,CAAC;IAAC,OAAO,MAAM,EAAE,CAAC;QAChB,mGAAmG;IACrG,CAAC;AACH,CAAC,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,IAAc,EAAS,EAAE;IAC3D,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC;QACjC,MAAM,IAAI,QAAQ,CAChB,IAAI,eAAe,CAAC,2CAA2C,CAAC,CACjE,CAAA;IACH,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC;QAC/B,MAAM,IAAI,QAAQ,CAChB,IAAI,eAAe,CAAC,yCAAyC,CAAC,CAC/D,CAAA;IACH,CAAC;IAED,MAAM,KAAK,GAAU;QACnB,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS;QAChC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;QAC5B,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU;QAClC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ;QAChC,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO;QAC1C,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO;QACtC,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,aAAa;QAC1C,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,WAAW;QACtC,KAAK,EAAE,CAAC,IAAI,CAAC;QACb,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,WAAW;QACtC,SAAS,EAAE,EAAE,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,GAAG,EAAE;KACzD,CAAA;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EAAE,MAAc,EAAE,OAAe,EAAE,EAAE;IAC3E,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAC1B,kDAAkD,OAAO,OAAO,MAAM,EAAE,CACzE,CAAA;QACD,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;QAEzC,OAAO,WAAW,CAAA;IACpB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC,CAAA,CAAC;AAChB,CAAC,CAAA"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { ExtendedChain, LiFiStep, ProcessType } from '@lifi/types';
|
|
2
|
-
import type { Hash } from 'viem';
|
|
3
|
-
import type { StatusManager } from '../StatusManager.js';
|
|
4
|
-
import type { MultisigConfig } from './types.js';
|
|
5
|
-
export declare const updateMultisigRouteProcess: (internalTxHash: Hash, step: LiFiStep, processType: ProcessType, fromChain: ExtendedChain, statusManager: StatusManager, multisig?: MultisigConfig) => Promise<void>;
|
|
6
|
-
//# sourceMappingURL=multisig.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"multisig.d.ts","sourceRoot":"","sources":["../../../core/EVM/multisig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACvE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAGhC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,KAAK,EAAE,cAAc,EAAqB,MAAM,YAAY,CAAA;AAEnE,eAAO,MAAM,0BAA0B,mBACrB,IAAI,QACd,QAAQ,eACD,WAAW,aACb,aAAa,iBACT,aAAa,aACjB,cAAc,kBAwC1B,CAAA"}
|
package/src/_types/helpers.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { LiFiStep, Route } from '@lifi/types';
|
|
2
|
-
export declare const checkPackageUpdates: (packageName?: string, packageVersion?: string) => Promise<void>;
|
|
3
|
-
/**
|
|
4
|
-
* Converts a quote to Route
|
|
5
|
-
* @param step - Step returned from the quote endpoint.
|
|
6
|
-
* @param txHash
|
|
7
|
-
* @param chainId
|
|
8
|
-
* @returns - The route to be executed.
|
|
9
|
-
* @throws {BaseError} Throws a ValidationError if the step has missing values.
|
|
10
|
-
*/
|
|
11
|
-
export declare const convertQuoteToRoute: (step: LiFiStep) => Route;
|
|
12
|
-
export declare const fetchTxErrorDetails: (txHash: string, chainId: number) => Promise<any>;
|
|
13
|
-
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAKlD,eAAO,MAAM,mBAAmB,iBAChB,MAAM,mBACH,MAAM,kBAiBxB,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,SAAU,QAAQ,KAAG,KA6BpD,CAAA;AAED,eAAO,MAAM,mBAAmB,WAAkB,MAAM,WAAW,MAAM,iBASxE,CAAA"}
|
package/src/core/EVM/multisig.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { ExtendedChain, LiFiStep, ProcessType } from '@lifi/types'
|
|
2
|
-
import type { Hash } from 'viem'
|
|
3
|
-
import { LiFiErrorCode } from '../../errors/constants.js'
|
|
4
|
-
import { TransactionError } from '../../errors/errors.js'
|
|
5
|
-
import type { StatusManager } from '../StatusManager.js'
|
|
6
|
-
import type { MultisigConfig, MultisigTxDetails } from './types.js'
|
|
7
|
-
|
|
8
|
-
export const updateMultisigRouteProcess = async (
|
|
9
|
-
internalTxHash: Hash,
|
|
10
|
-
step: LiFiStep,
|
|
11
|
-
processType: ProcessType,
|
|
12
|
-
fromChain: ExtendedChain,
|
|
13
|
-
statusManager: StatusManager,
|
|
14
|
-
multisig?: MultisigConfig
|
|
15
|
-
) => {
|
|
16
|
-
if (!multisig?.getMultisigTransactionDetails) {
|
|
17
|
-
throw new Error(
|
|
18
|
-
'getMultisigTransactionDetails is missing in multisig config.'
|
|
19
|
-
)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const updateIntermediateMultisigStatus = () => {
|
|
23
|
-
statusManager.updateProcess(step, processType, 'PENDING')
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const multisigStatusResponse: MultisigTxDetails =
|
|
27
|
-
await multisig?.getMultisigTransactionDetails(
|
|
28
|
-
internalTxHash,
|
|
29
|
-
fromChain.id,
|
|
30
|
-
updateIntermediateMultisigStatus
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
if (multisigStatusResponse.status === 'DONE') {
|
|
34
|
-
statusManager.updateProcess(step, processType, 'PENDING', {
|
|
35
|
-
txHash: multisigStatusResponse.txHash,
|
|
36
|
-
multisigTxHash: undefined,
|
|
37
|
-
txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${multisigStatusResponse.txHash}`,
|
|
38
|
-
})
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (multisigStatusResponse.status === 'FAILED') {
|
|
42
|
-
throw new TransactionError(
|
|
43
|
-
LiFiErrorCode.TransactionFailed,
|
|
44
|
-
'Multisig transaction failed.'
|
|
45
|
-
)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (multisigStatusResponse.status === 'CANCELLED') {
|
|
49
|
-
throw new TransactionError(
|
|
50
|
-
LiFiErrorCode.SignatureRejected,
|
|
51
|
-
'Transaction was rejected by user.'
|
|
52
|
-
)
|
|
53
|
-
}
|
|
54
|
-
}
|
package/src/helpers.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import type { LiFiStep, Route } from '@lifi/types'
|
|
2
|
-
import { SDKError } from './errors/SDKError.js'
|
|
3
|
-
import { ValidationError } from './errors/errors.js'
|
|
4
|
-
import { name, version } from './version.js'
|
|
5
|
-
|
|
6
|
-
export const checkPackageUpdates = async (
|
|
7
|
-
packageName?: string,
|
|
8
|
-
packageVersion?: string
|
|
9
|
-
) => {
|
|
10
|
-
try {
|
|
11
|
-
const pkgName = packageName ?? name
|
|
12
|
-
const response = await fetch(`https://registry.npmjs.org/${pkgName}/latest`)
|
|
13
|
-
const reponseBody = await response.json()
|
|
14
|
-
const latestVersion = reponseBody.version
|
|
15
|
-
const currentVersion = packageVersion ?? version
|
|
16
|
-
|
|
17
|
-
if (latestVersion > currentVersion) {
|
|
18
|
-
console.warn(
|
|
19
|
-
`${pkgName}: new package version is available. Please update as soon as possible to enjoy the newest features. Current version: ${currentVersion}. Latest version: ${latestVersion}.`
|
|
20
|
-
)
|
|
21
|
-
}
|
|
22
|
-
} catch (_error) {
|
|
23
|
-
// Cannot verify version, might be network error etc. We don't bother showing anything in that case
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Converts a quote to Route
|
|
29
|
-
* @param step - Step returned from the quote endpoint.
|
|
30
|
-
* @param txHash
|
|
31
|
-
* @param chainId
|
|
32
|
-
* @returns - The route to be executed.
|
|
33
|
-
* @throws {BaseError} Throws a ValidationError if the step has missing values.
|
|
34
|
-
*/
|
|
35
|
-
export const convertQuoteToRoute = (step: LiFiStep): Route => {
|
|
36
|
-
if (!step.estimate.fromAmountUSD) {
|
|
37
|
-
throw new SDKError(
|
|
38
|
-
new ValidationError("Missing 'fromAmountUSD' in step estimate.")
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (!step.estimate.toAmountUSD) {
|
|
43
|
-
throw new SDKError(
|
|
44
|
-
new ValidationError("Missing 'toAmountUSD' in step estimate.")
|
|
45
|
-
)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const route: Route = {
|
|
49
|
-
fromToken: step.action.fromToken,
|
|
50
|
-
toToken: step.action.toToken,
|
|
51
|
-
fromAmount: step.action.fromAmount,
|
|
52
|
-
toAmount: step.estimate.toAmount,
|
|
53
|
-
id: step.id,
|
|
54
|
-
fromChainId: step.action.fromToken.chainId,
|
|
55
|
-
toChainId: step.action.toToken.chainId,
|
|
56
|
-
fromAmountUSD: step.estimate.fromAmountUSD,
|
|
57
|
-
toAmountUSD: step.estimate.toAmountUSD,
|
|
58
|
-
steps: [step],
|
|
59
|
-
toAmountMin: step.estimate.toAmountMin,
|
|
60
|
-
insurance: { state: 'NOT_INSURABLE', feeAmountUsd: '0' },
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return route
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export const fetchTxErrorDetails = async (txHash: string, chainId: number) => {
|
|
67
|
-
try {
|
|
68
|
-
const response = await fetch(
|
|
69
|
-
`https://api.tenderly.co/api/v1/public-contract/${chainId}/tx/${txHash}`
|
|
70
|
-
)
|
|
71
|
-
const reponseBody = await response.json()
|
|
72
|
-
|
|
73
|
-
return reponseBody
|
|
74
|
-
} catch (_) {}
|
|
75
|
-
}
|