@lifi/sdk 2.0.0-beta.7 → 2.0.0-beta.9
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/dist/LiFi.d.ts +4 -4
- package/dist/LiFi.js +1 -1
- package/dist/allowance/checkAllowance.js +16 -2
- package/dist/allowance/utils.d.ts +2 -1
- package/dist/allowance/utils.js +7 -2
- package/dist/cjs/LiFi.d.ts +4 -4
- package/dist/cjs/LiFi.js +1 -1
- package/dist/cjs/allowance/checkAllowance.js +16 -2
- package/dist/cjs/allowance/utils.d.ts +2 -1
- package/dist/cjs/allowance/utils.js +7 -2
- package/dist/cjs/execution/StepExecutionManager.js +8 -0
- package/dist/cjs/helpers.d.ts +3 -3
- package/dist/cjs/helpers.js +2 -7
- package/dist/cjs/services/ApiService.d.ts +3 -3
- package/dist/cjs/types/internal.types.d.ts +43 -0
- package/dist/cjs/utils/errors.d.ts +20 -1
- package/dist/cjs/utils/errors.js +23 -1
- package/dist/cjs/utils/parseError.js +22 -11
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/execution/StepExecutionManager.js +8 -0
- package/dist/helpers.d.ts +3 -3
- package/dist/helpers.js +2 -7
- package/dist/services/ApiService.d.ts +3 -3
- package/dist/types/internal.types.d.ts +43 -0
- package/dist/utils/errors.d.ts +20 -1
- package/dist/utils/errors.js +22 -0
- package/dist/utils/parseError.js +23 -12
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +8 -8
package/dist/LiFi.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FallbackProvider } from '@ethersproject/providers';
|
|
2
|
-
import { ChainId, ChainKey, ConnectionsRequest, ConnectionsResponse, ContractCallQuoteRequest, ExtendedChain, GasRecommendationRequest, GasRecommendationResponse, GetStatusRequest, LifiStep, PossibilitiesRequest, PossibilitiesResponse, QuoteRequest, RequestOptions, RoutesRequest, RoutesResponse, StatusResponse,
|
|
2
|
+
import { ChainId, ChainKey, ConnectionsRequest, ConnectionsResponse, ContractCallQuoteRequest, ExtendedChain, GasRecommendationRequest, GasRecommendationResponse, GetStatusRequest, LifiStep, PossibilitiesRequest, PossibilitiesResponse, QuoteRequest, RequestOptions, RoutesRequest, RoutesResponse, StatusResponse, Token, TokenAmount, TokensRequest, TokensResponse, ToolsRequest, ToolsResponse } from '@lifi/types';
|
|
3
3
|
import { Signer } from 'ethers';
|
|
4
4
|
import { ApproveTokenRequest, RevokeApprovalRequest } from './allowance';
|
|
5
5
|
import { RouteExecutionManager } from './execution/RouteExecutionManager';
|
|
@@ -49,13 +49,13 @@ export declare class LiFi extends RouteExecutionManager {
|
|
|
49
49
|
* @param {QuoteRequest} request - The configuration of the requested quote
|
|
50
50
|
* @throws {LifiError} - Throws a LifiError if request fails
|
|
51
51
|
*/
|
|
52
|
-
getQuote: (request: QuoteRequest, options?: RequestOptions) => Promise<
|
|
52
|
+
getQuote: (request: QuoteRequest, options?: RequestOptions) => Promise<LifiStep>;
|
|
53
53
|
/**
|
|
54
54
|
* Get a quote for a destination contract call
|
|
55
55
|
* @param {ContractCallQuoteRequest} request - The configuration of the requested destination call
|
|
56
56
|
* @throws {LifiError} - Throws a LifiError if request fails
|
|
57
57
|
*/
|
|
58
|
-
getContractCallQuote: (request: ContractCallQuoteRequest, options?: RequestOptions) => Promise<
|
|
58
|
+
getContractCallQuote: (request: ContractCallQuoteRequest, options?: RequestOptions) => Promise<LifiStep>;
|
|
59
59
|
/**
|
|
60
60
|
* Check the status of a transfer. For cross chain transfers, the "bridge" parameter is required.
|
|
61
61
|
* @param {GetStatusRequest} request - Configuration of the requested status
|
|
@@ -89,7 +89,7 @@ export declare class LiFi extends RouteExecutionManager {
|
|
|
89
89
|
getRoutes: (request: RoutesRequest, options?: RequestOptions) => Promise<RoutesResponse>;
|
|
90
90
|
/**
|
|
91
91
|
* Get the transaction data for a single step of a route
|
|
92
|
-
* @param {
|
|
92
|
+
* @param {LifiStep} step - The step object.
|
|
93
93
|
* @return {Promise<Step>} The step populated with the transaction data.
|
|
94
94
|
* @throws {LifiError} Throws a LifiError if request fails.
|
|
95
95
|
*/
|
package/dist/LiFi.js
CHANGED
|
@@ -119,7 +119,7 @@ export class LiFi extends RouteExecutionManager {
|
|
|
119
119
|
};
|
|
120
120
|
/**
|
|
121
121
|
* Get the transaction data for a single step of a route
|
|
122
|
-
* @param {
|
|
122
|
+
* @param {LifiStep} step - The step object.
|
|
123
123
|
* @return {Promise<Step>} The step populated with the transaction data.
|
|
124
124
|
* @throws {LifiError} Throws a LifiError if request fails.
|
|
125
125
|
*/
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
1
|
import BigNumber from 'bignumber.js';
|
|
3
2
|
import { constants } from 'ethers';
|
|
4
3
|
import { getApproved, setApproval } from '../allowance/utils';
|
|
@@ -17,7 +16,22 @@ export const checkAllowance = async (signer, step, statusManager, settings, chai
|
|
|
17
16
|
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
|
|
18
17
|
}
|
|
19
18
|
else {
|
|
20
|
-
const
|
|
19
|
+
const approvalRequest = {
|
|
20
|
+
from: step.action.fromToken.address,
|
|
21
|
+
to: step.estimate.approvalAddress,
|
|
22
|
+
};
|
|
23
|
+
if (settings.updateTransactionRequest) {
|
|
24
|
+
const config = await settings.updateTransactionRequest(approvalRequest);
|
|
25
|
+
approvalRequest.gasLimit = config.gasLimit;
|
|
26
|
+
approvalRequest.gasPrice = config.gasPrice;
|
|
27
|
+
}
|
|
28
|
+
if (!approvalRequest.from) {
|
|
29
|
+
throw new Error('Missing Signer address');
|
|
30
|
+
}
|
|
31
|
+
if (!approvalRequest.to) {
|
|
32
|
+
throw new Error('Missing ERC20 contract address');
|
|
33
|
+
}
|
|
34
|
+
const approved = await getApproved(signer, approvalRequest.from, approvalRequest.to, approvalRequest);
|
|
21
35
|
if (new BigNumber(step.action.fromAmount).gt(approved)) {
|
|
22
36
|
if (!allowUserInteraction) {
|
|
23
37
|
return;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { TransactionRequest } from '@ethersproject/abstract-provider';
|
|
1
2
|
import { ChainId, Token } from '@lifi/types';
|
|
2
3
|
import BigNumber from 'bignumber.js';
|
|
3
4
|
import { ContractTransaction, Signer } from 'ethers';
|
|
4
5
|
import { RevokeTokenData } from '../types';
|
|
5
|
-
export declare const getApproved: (signer: Signer, tokenAddress: string, contractAddress: string) => Promise<BigNumber>;
|
|
6
|
+
export declare const getApproved: (signer: Signer, tokenAddress: string, contractAddress: string, transactionRequest?: TransactionRequest) => Promise<BigNumber>;
|
|
6
7
|
export declare const setApproval: (signer: Signer, tokenAddress: string, contractAddress: string, amount: string) => Promise<ContractTransaction>;
|
|
7
8
|
export declare const getAllowanceViaMulticall: (signer: Signer, chainId: ChainId, tokenData: RevokeTokenData[]) => Promise<{
|
|
8
9
|
token: Token;
|
package/dist/allowance/utils.js
CHANGED
|
@@ -4,11 +4,16 @@ import ChainsService from '../services/ChainsService';
|
|
|
4
4
|
import { ERC20_ABI } from '../types';
|
|
5
5
|
import { ServerError } from '../utils/errors';
|
|
6
6
|
import { fetchDataUsingMulticall } from '../utils/multicall';
|
|
7
|
-
export const getApproved = async (signer, tokenAddress, contractAddress) => {
|
|
7
|
+
export const getApproved = async (signer, tokenAddress, contractAddress, transactionRequest) => {
|
|
8
8
|
const signerAddress = await signer.getAddress();
|
|
9
9
|
const erc20 = new Contract(tokenAddress, ERC20_ABI, signer);
|
|
10
10
|
try {
|
|
11
|
-
const approved = await erc20.allowance(signerAddress, contractAddress
|
|
11
|
+
const approved = await erc20.allowance(signerAddress, contractAddress, {
|
|
12
|
+
gasLimit: transactionRequest?.gasLimit,
|
|
13
|
+
gasPrice: transactionRequest?.gasPrice,
|
|
14
|
+
maxFeePerGas: transactionRequest?.maxFeePerGas,
|
|
15
|
+
maxPriorityFeePerGas: transactionRequest?.maxPriorityFeePerGas,
|
|
16
|
+
});
|
|
12
17
|
return new BigNumber(approved.toString());
|
|
13
18
|
}
|
|
14
19
|
catch (e) {
|
package/dist/cjs/LiFi.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FallbackProvider } from '@ethersproject/providers';
|
|
2
|
-
import { ChainId, ChainKey, ConnectionsRequest, ConnectionsResponse, ContractCallQuoteRequest, ExtendedChain, GasRecommendationRequest, GasRecommendationResponse, GetStatusRequest, LifiStep, PossibilitiesRequest, PossibilitiesResponse, QuoteRequest, RequestOptions, RoutesRequest, RoutesResponse, StatusResponse,
|
|
2
|
+
import { ChainId, ChainKey, ConnectionsRequest, ConnectionsResponse, ContractCallQuoteRequest, ExtendedChain, GasRecommendationRequest, GasRecommendationResponse, GetStatusRequest, LifiStep, PossibilitiesRequest, PossibilitiesResponse, QuoteRequest, RequestOptions, RoutesRequest, RoutesResponse, StatusResponse, Token, TokenAmount, TokensRequest, TokensResponse, ToolsRequest, ToolsResponse } from '@lifi/types';
|
|
3
3
|
import { Signer } from 'ethers';
|
|
4
4
|
import { ApproveTokenRequest, RevokeApprovalRequest } from './allowance';
|
|
5
5
|
import { RouteExecutionManager } from './execution/RouteExecutionManager';
|
|
@@ -49,13 +49,13 @@ export declare class LiFi extends RouteExecutionManager {
|
|
|
49
49
|
* @param {QuoteRequest} request - The configuration of the requested quote
|
|
50
50
|
* @throws {LifiError} - Throws a LifiError if request fails
|
|
51
51
|
*/
|
|
52
|
-
getQuote: (request: QuoteRequest, options?: RequestOptions) => Promise<
|
|
52
|
+
getQuote: (request: QuoteRequest, options?: RequestOptions) => Promise<LifiStep>;
|
|
53
53
|
/**
|
|
54
54
|
* Get a quote for a destination contract call
|
|
55
55
|
* @param {ContractCallQuoteRequest} request - The configuration of the requested destination call
|
|
56
56
|
* @throws {LifiError} - Throws a LifiError if request fails
|
|
57
57
|
*/
|
|
58
|
-
getContractCallQuote: (request: ContractCallQuoteRequest, options?: RequestOptions) => Promise<
|
|
58
|
+
getContractCallQuote: (request: ContractCallQuoteRequest, options?: RequestOptions) => Promise<LifiStep>;
|
|
59
59
|
/**
|
|
60
60
|
* Check the status of a transfer. For cross chain transfers, the "bridge" parameter is required.
|
|
61
61
|
* @param {GetStatusRequest} request - Configuration of the requested status
|
|
@@ -89,7 +89,7 @@ export declare class LiFi extends RouteExecutionManager {
|
|
|
89
89
|
getRoutes: (request: RoutesRequest, options?: RequestOptions) => Promise<RoutesResponse>;
|
|
90
90
|
/**
|
|
91
91
|
* Get the transaction data for a single step of a route
|
|
92
|
-
* @param {
|
|
92
|
+
* @param {LifiStep} step - The step object.
|
|
93
93
|
* @return {Promise<Step>} The step populated with the transaction data.
|
|
94
94
|
* @throws {LifiError} Throws a LifiError if request fails.
|
|
95
95
|
*/
|
package/dist/cjs/LiFi.js
CHANGED
|
@@ -148,7 +148,7 @@ class LiFi extends RouteExecutionManager_1.RouteExecutionManager {
|
|
|
148
148
|
};
|
|
149
149
|
/**
|
|
150
150
|
* Get the transaction data for a single step of a route
|
|
151
|
-
* @param {
|
|
151
|
+
* @param {LifiStep} step - The step object.
|
|
152
152
|
* @return {Promise<Step>} The step populated with the transaction data.
|
|
153
153
|
* @throws {LifiError} Throws a LifiError if request fails.
|
|
154
154
|
*/
|
|
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.checkAllowance = void 0;
|
|
7
|
-
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
8
7
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
9
8
|
const ethers_1 = require("ethers");
|
|
10
9
|
const utils_1 = require("../allowance/utils");
|
|
@@ -23,7 +22,22 @@ const checkAllowance = async (signer, step, statusManager, settings, chain, allo
|
|
|
23
22
|
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
|
|
24
23
|
}
|
|
25
24
|
else {
|
|
26
|
-
const
|
|
25
|
+
const approvalRequest = {
|
|
26
|
+
from: step.action.fromToken.address,
|
|
27
|
+
to: step.estimate.approvalAddress,
|
|
28
|
+
};
|
|
29
|
+
if (settings.updateTransactionRequest) {
|
|
30
|
+
const config = await settings.updateTransactionRequest(approvalRequest);
|
|
31
|
+
approvalRequest.gasLimit = config.gasLimit;
|
|
32
|
+
approvalRequest.gasPrice = config.gasPrice;
|
|
33
|
+
}
|
|
34
|
+
if (!approvalRequest.from) {
|
|
35
|
+
throw new Error('Missing Signer address');
|
|
36
|
+
}
|
|
37
|
+
if (!approvalRequest.to) {
|
|
38
|
+
throw new Error('Missing ERC20 contract address');
|
|
39
|
+
}
|
|
40
|
+
const approved = await (0, utils_1.getApproved)(signer, approvalRequest.from, approvalRequest.to, approvalRequest);
|
|
27
41
|
if (new bignumber_js_1.default(step.action.fromAmount).gt(approved)) {
|
|
28
42
|
if (!allowUserInteraction) {
|
|
29
43
|
return;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { TransactionRequest } from '@ethersproject/abstract-provider';
|
|
1
2
|
import { ChainId, Token } from '@lifi/types';
|
|
2
3
|
import BigNumber from 'bignumber.js';
|
|
3
4
|
import { ContractTransaction, Signer } from 'ethers';
|
|
4
5
|
import { RevokeTokenData } from '../types';
|
|
5
|
-
export declare const getApproved: (signer: Signer, tokenAddress: string, contractAddress: string) => Promise<BigNumber>;
|
|
6
|
+
export declare const getApproved: (signer: Signer, tokenAddress: string, contractAddress: string, transactionRequest?: TransactionRequest) => Promise<BigNumber>;
|
|
6
7
|
export declare const setApproval: (signer: Signer, tokenAddress: string, contractAddress: string, amount: string) => Promise<ContractTransaction>;
|
|
7
8
|
export declare const getAllowanceViaMulticall: (signer: Signer, chainId: ChainId, tokenData: RevokeTokenData[]) => Promise<{
|
|
8
9
|
token: Token;
|
|
@@ -10,11 +10,16 @@ const ChainsService_1 = __importDefault(require("../services/ChainsService"));
|
|
|
10
10
|
const types_1 = require("../types");
|
|
11
11
|
const errors_1 = require("../utils/errors");
|
|
12
12
|
const multicall_1 = require("../utils/multicall");
|
|
13
|
-
const getApproved = async (signer, tokenAddress, contractAddress) => {
|
|
13
|
+
const getApproved = async (signer, tokenAddress, contractAddress, transactionRequest) => {
|
|
14
14
|
const signerAddress = await signer.getAddress();
|
|
15
15
|
const erc20 = new ethers_1.Contract(tokenAddress, types_1.ERC20_ABI, signer);
|
|
16
16
|
try {
|
|
17
|
-
const approved = await erc20.allowance(signerAddress, contractAddress
|
|
17
|
+
const approved = await erc20.allowance(signerAddress, contractAddress, {
|
|
18
|
+
gasLimit: transactionRequest?.gasLimit,
|
|
19
|
+
gasPrice: transactionRequest?.gasPrice,
|
|
20
|
+
maxFeePerGas: transactionRequest?.maxFeePerGas,
|
|
21
|
+
maxPriorityFeePerGas: transactionRequest?.maxPriorityFeePerGas,
|
|
22
|
+
});
|
|
18
23
|
return new bignumber_js_1.default(approved.toString());
|
|
19
24
|
}
|
|
20
25
|
catch (e) {
|
|
@@ -81,6 +81,14 @@ class StepExecutionManager {
|
|
|
81
81
|
if (!this.allowUserInteraction) {
|
|
82
82
|
return step.execution;
|
|
83
83
|
}
|
|
84
|
+
if (settings.updateTransactionRequest) {
|
|
85
|
+
const customConfig = await settings.updateTransactionRequest(transactionRequest);
|
|
86
|
+
transactionRequest.gasLimit = customConfig.gasLimit;
|
|
87
|
+
transactionRequest.gasPrice = customConfig.gasPrice;
|
|
88
|
+
transactionRequest.maxPriorityFeePerGas =
|
|
89
|
+
customConfig.maxPriorityFeePerGas;
|
|
90
|
+
transactionRequest.maxFeePerGas = customConfig.maxFeePerGas;
|
|
91
|
+
}
|
|
84
92
|
// Submit the transaction
|
|
85
93
|
transaction = await signer.sendTransaction(transactionRequest);
|
|
86
94
|
// STEP 4: Wait for the transaction
|
package/dist/cjs/helpers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LifiStep, Route, Token } from '@lifi/types';
|
|
2
2
|
/**
|
|
3
3
|
* Predefined hook that decrypts calldata using EIP-1193 compliant wallet functions.
|
|
4
4
|
* @param {string} walletAddress - The wallet address of the user that should decrypt the calldata.
|
|
@@ -19,8 +19,8 @@ export declare const isSameToken: (tokenA: Token, tokenB: Token) => boolean;
|
|
|
19
19
|
export declare const checkPackageUpdates: (packageName?: string, packageVersion?: string, disableCheck?: boolean) => Promise<void>;
|
|
20
20
|
/**
|
|
21
21
|
* Converts a quote to Route
|
|
22
|
-
* @param {
|
|
22
|
+
* @param {LifiStep} step - Step returned from the quote endpoint.
|
|
23
23
|
* @return {Route} - The route to be executed.
|
|
24
24
|
* @throws {ValidationError} Throws a ValidationError if the step has missing values.
|
|
25
25
|
*/
|
|
26
|
-
export declare const convertQuoteToRoute: (step:
|
|
26
|
+
export declare const convertQuoteToRoute: (step: LifiStep) => Route;
|
package/dist/cjs/helpers.js
CHANGED
|
@@ -81,7 +81,7 @@ const checkPackageUpdates = async (packageName, packageVersion, disableCheck) =>
|
|
|
81
81
|
exports.checkPackageUpdates = checkPackageUpdates;
|
|
82
82
|
/**
|
|
83
83
|
* Converts a quote to Route
|
|
84
|
-
* @param {
|
|
84
|
+
* @param {LifiStep} step - Step returned from the quote endpoint.
|
|
85
85
|
* @return {Route} - The route to be executed.
|
|
86
86
|
* @throws {ValidationError} Throws a ValidationError if the step has missing values.
|
|
87
87
|
*/
|
|
@@ -92,11 +92,6 @@ const convertQuoteToRoute = (step) => {
|
|
|
92
92
|
if (!step.estimate.toAmountUSD) {
|
|
93
93
|
throw new errors_1.ValidationError("Missing 'toAmountUSD' in step estimate.");
|
|
94
94
|
}
|
|
95
|
-
const lifiStep = {
|
|
96
|
-
...step,
|
|
97
|
-
type: 'lifi',
|
|
98
|
-
includedSteps: [],
|
|
99
|
-
};
|
|
100
95
|
const route = {
|
|
101
96
|
fromToken: step.action.fromToken,
|
|
102
97
|
toToken: step.action.toToken,
|
|
@@ -107,7 +102,7 @@ const convertQuoteToRoute = (step) => {
|
|
|
107
102
|
toChainId: step.action.toToken.chainId,
|
|
108
103
|
fromAmountUSD: step.estimate.fromAmountUSD,
|
|
109
104
|
toAmountUSD: step.estimate.toAmountUSD,
|
|
110
|
-
steps: [
|
|
105
|
+
steps: [step],
|
|
111
106
|
toAmountMin: step.estimate.toAmountMin,
|
|
112
107
|
insurance: { state: 'NOT_INSURABLE', feeAmountUsd: '0' },
|
|
113
108
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ConnectionsRequest, ConnectionsResponse, ContractCallQuoteRequest, GasRecommendationRequest, GasRecommendationResponse, GetStatusRequest, LifiStep, QuoteRequest, RequestOptions, TokensRequest, TokensResponse } from '@lifi/types';
|
|
2
|
-
import { ChainId, ChainKey, ExtendedChain, PossibilitiesRequest, PossibilitiesResponse, RoutesRequest, RoutesResponse, StatusResponse,
|
|
2
|
+
import { ChainId, ChainKey, ExtendedChain, PossibilitiesRequest, PossibilitiesResponse, RoutesRequest, RoutesResponse, StatusResponse, Token, ToolsRequest, ToolsResponse } from '../types';
|
|
3
3
|
declare const _default: {
|
|
4
4
|
getChains: (options?: RequestOptions | undefined) => Promise<ExtendedChain[]>;
|
|
5
|
-
getContractCallQuote: (requestConfig: ContractCallQuoteRequest, options?: RequestOptions | undefined) => Promise<
|
|
5
|
+
getContractCallQuote: (requestConfig: ContractCallQuoteRequest, options?: RequestOptions | undefined) => Promise<LifiStep>;
|
|
6
6
|
getGasRecommendation: ({ chainId, fromChain, fromToken }: GasRecommendationRequest, options?: RequestOptions | undefined) => Promise<GasRecommendationResponse>;
|
|
7
7
|
getPossibilities: (requestConfig?: PossibilitiesRequest | undefined, options?: RequestOptions | undefined) => Promise<PossibilitiesResponse>;
|
|
8
|
-
getQuote: (requestConfig: QuoteRequest, options?: RequestOptions | undefined) => Promise<
|
|
8
|
+
getQuote: (requestConfig: QuoteRequest, options?: RequestOptions | undefined) => Promise<LifiStep>;
|
|
9
9
|
getRoutes: (requestConfig: RoutesRequest, options?: RequestOptions | undefined) => Promise<RoutesResponse>;
|
|
10
10
|
getStatus: (requestConfig: GetStatusRequest, options?: RequestOptions | undefined) => Promise<StatusResponse>;
|
|
11
11
|
getStepTransaction: (step: LifiStep, options?: RequestOptions | undefined) => Promise<LifiStep>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TransactionRequest } from '@ethersproject/abstract-provider';
|
|
1
2
|
import { LifiStep, Route, RouteOptions, Token } from '@lifi/types';
|
|
2
3
|
import BigNumber from 'bignumber.js';
|
|
3
4
|
import { Signer } from 'ethers';
|
|
@@ -23,6 +24,7 @@ export interface ExecutionParams {
|
|
|
23
24
|
settings: InternalExecutionSettings;
|
|
24
25
|
}
|
|
25
26
|
export type CallbackFunction = (updatedRoute: Route) => void;
|
|
27
|
+
export type TxRequestCallbackFunction = (updatedTxRequest: TransactionRequest) => Promise<TransactionRequest>;
|
|
26
28
|
export type Config = {
|
|
27
29
|
apiUrl: string;
|
|
28
30
|
rpcs: Record<ChainId, string[]>;
|
|
@@ -73,6 +75,7 @@ export interface InternalExecutionSettings {
|
|
|
73
75
|
acceptExchangeRateUpdateHook: AcceptExchangeRateUpdateHook;
|
|
74
76
|
infiniteApproval: boolean;
|
|
75
77
|
executeInBackground: boolean;
|
|
78
|
+
updateTransactionRequest?: TxRequestCallbackFunction;
|
|
76
79
|
}
|
|
77
80
|
export type EnforcedObjectProperties<T> = T & {
|
|
78
81
|
[P in keyof T]-?: T[P];
|
|
@@ -88,3 +91,43 @@ export interface InteractionSettings {
|
|
|
88
91
|
allowUpdates?: boolean;
|
|
89
92
|
stopExecution?: boolean;
|
|
90
93
|
}
|
|
94
|
+
export interface TenderlyResponse {
|
|
95
|
+
hash: string;
|
|
96
|
+
block_hash: string;
|
|
97
|
+
block_number: number;
|
|
98
|
+
from: string;
|
|
99
|
+
gas: number;
|
|
100
|
+
gas_price: number;
|
|
101
|
+
gas_fee_cap: number;
|
|
102
|
+
gas_tip_cap: number;
|
|
103
|
+
cumulative_gas_used: number;
|
|
104
|
+
gas_used: number;
|
|
105
|
+
effective_gas_price: number;
|
|
106
|
+
input: string;
|
|
107
|
+
nonce: number;
|
|
108
|
+
to: string;
|
|
109
|
+
index: number;
|
|
110
|
+
value: string;
|
|
111
|
+
access_list: any;
|
|
112
|
+
status: boolean;
|
|
113
|
+
addresses: string[];
|
|
114
|
+
contract_ids: string[];
|
|
115
|
+
network_id: string;
|
|
116
|
+
timestamp: string;
|
|
117
|
+
function_selector: string;
|
|
118
|
+
l1_block_number: number;
|
|
119
|
+
l1_timestamp: number;
|
|
120
|
+
deposit_tx: boolean;
|
|
121
|
+
system_tx: boolean;
|
|
122
|
+
mint: number;
|
|
123
|
+
sig: Signature;
|
|
124
|
+
error_message: string;
|
|
125
|
+
method: string;
|
|
126
|
+
decoded_input: any;
|
|
127
|
+
call_trace: any;
|
|
128
|
+
}
|
|
129
|
+
export interface Signature {
|
|
130
|
+
v: string;
|
|
131
|
+
r: string;
|
|
132
|
+
s: string;
|
|
133
|
+
}
|
|
@@ -22,7 +22,26 @@ export declare enum LifiErrorCode {
|
|
|
22
22
|
TransactionCanceled = 1010,
|
|
23
23
|
SlippageError = 1011,
|
|
24
24
|
TransactionRejected = 1012,
|
|
25
|
-
BalanceError = 1013
|
|
25
|
+
BalanceError = 1013,
|
|
26
|
+
AllowanceRequired = 1014
|
|
27
|
+
}
|
|
28
|
+
export declare enum EthersErrorType {
|
|
29
|
+
CallExecption = "CALL_EXCEPTION",
|
|
30
|
+
ActionRejected = "ACTION_REJECTED"
|
|
31
|
+
}
|
|
32
|
+
export declare enum EthersErrorMessage {
|
|
33
|
+
ERC20Allowance = "ERC20: transfer amount exceeds allowance",
|
|
34
|
+
LowGas = "intrinsic gas too low",
|
|
35
|
+
OutOfGas = "out of gas",
|
|
36
|
+
Underpriced = "underpriced",
|
|
37
|
+
LowReplacementFee = "replacement fee too low"
|
|
38
|
+
}
|
|
39
|
+
export declare enum ErrorMessage {
|
|
40
|
+
UnknownError = "Unknown error occurred.",
|
|
41
|
+
SlippageError = "The slippage is larger than the defined threshold. Please request a new route to get a fresh quote.",
|
|
42
|
+
GasLimitLow = "Gas limit is too low.",
|
|
43
|
+
TransactionUnderpriced = "Transaction is underpriced.",
|
|
44
|
+
Default = "Something went wrong."
|
|
26
45
|
}
|
|
27
46
|
export declare enum MetaMaskRPCErrorCode {
|
|
28
47
|
invalidInput = -32000,
|
package/dist/cjs/utils/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HTTPError = exports.UnknownError = exports.NotFoundError = exports.BalanceError = exports.SlippageError = exports.TransactionError = exports.ValidationError = exports.ServerError = exports.ProviderError = exports.RPCError = exports.LifiError = exports.MetaMaskProviderErrorCode = exports.MetaMaskRPCErrorCode = exports.LifiErrorCode = void 0;
|
|
3
|
+
exports.HTTPError = exports.UnknownError = exports.NotFoundError = exports.BalanceError = exports.SlippageError = exports.TransactionError = exports.ValidationError = exports.ServerError = exports.ProviderError = exports.RPCError = exports.LifiError = exports.MetaMaskProviderErrorCode = exports.MetaMaskRPCErrorCode = exports.ErrorMessage = exports.EthersErrorMessage = exports.EthersErrorType = exports.LifiErrorCode = void 0;
|
|
4
4
|
var ErrorType;
|
|
5
5
|
(function (ErrorType) {
|
|
6
6
|
ErrorType["RPCError"] = "RPCError";
|
|
@@ -28,7 +28,29 @@ var LifiErrorCode;
|
|
|
28
28
|
LifiErrorCode[LifiErrorCode["SlippageError"] = 1011] = "SlippageError";
|
|
29
29
|
LifiErrorCode[LifiErrorCode["TransactionRejected"] = 1012] = "TransactionRejected";
|
|
30
30
|
LifiErrorCode[LifiErrorCode["BalanceError"] = 1013] = "BalanceError";
|
|
31
|
+
LifiErrorCode[LifiErrorCode["AllowanceRequired"] = 1014] = "AllowanceRequired";
|
|
31
32
|
})(LifiErrorCode = exports.LifiErrorCode || (exports.LifiErrorCode = {}));
|
|
33
|
+
var EthersErrorType;
|
|
34
|
+
(function (EthersErrorType) {
|
|
35
|
+
EthersErrorType["CallExecption"] = "CALL_EXCEPTION";
|
|
36
|
+
EthersErrorType["ActionRejected"] = "ACTION_REJECTED";
|
|
37
|
+
})(EthersErrorType = exports.EthersErrorType || (exports.EthersErrorType = {}));
|
|
38
|
+
var EthersErrorMessage;
|
|
39
|
+
(function (EthersErrorMessage) {
|
|
40
|
+
EthersErrorMessage["ERC20Allowance"] = "ERC20: transfer amount exceeds allowance";
|
|
41
|
+
EthersErrorMessage["LowGas"] = "intrinsic gas too low";
|
|
42
|
+
EthersErrorMessage["OutOfGas"] = "out of gas";
|
|
43
|
+
EthersErrorMessage["Underpriced"] = "underpriced";
|
|
44
|
+
EthersErrorMessage["LowReplacementFee"] = "replacement fee too low";
|
|
45
|
+
})(EthersErrorMessage = exports.EthersErrorMessage || (exports.EthersErrorMessage = {}));
|
|
46
|
+
var ErrorMessage;
|
|
47
|
+
(function (ErrorMessage) {
|
|
48
|
+
ErrorMessage["UnknownError"] = "Unknown error occurred.";
|
|
49
|
+
ErrorMessage["SlippageError"] = "The slippage is larger than the defined threshold. Please request a new route to get a fresh quote.";
|
|
50
|
+
ErrorMessage["GasLimitLow"] = "Gas limit is too low.";
|
|
51
|
+
ErrorMessage["TransactionUnderpriced"] = "Transaction is underpriced.";
|
|
52
|
+
ErrorMessage["Default"] = "Something went wrong.";
|
|
53
|
+
})(ErrorMessage = exports.ErrorMessage || (exports.ErrorMessage = {}));
|
|
32
54
|
var MetaMaskRPCErrorCode;
|
|
33
55
|
(function (MetaMaskRPCErrorCode) {
|
|
34
56
|
MetaMaskRPCErrorCode[MetaMaskRPCErrorCode["invalidInput"] = -32000] = "invalidInput";
|
|
@@ -79,13 +79,13 @@ const parseError = async (e, step, process) => {
|
|
|
79
79
|
// rpc errors
|
|
80
80
|
// underpriced errors are sent as internal errors, so we need to parse the message manually
|
|
81
81
|
if (e.code === eth_rpc_errors_1.errorCodes.rpc.internal &&
|
|
82
|
-
(e.message?.includes(
|
|
83
|
-
e.message?.includes(
|
|
84
|
-
return new errors_1.RPCError(errors_1.LifiErrorCode.TransactionUnderpriced,
|
|
82
|
+
(e.message?.includes(errors_1.EthersErrorMessage.Underpriced) ||
|
|
83
|
+
e.message?.includes(errors_1.EthersErrorMessage.LowReplacementFee))) {
|
|
84
|
+
return new errors_1.RPCError(errors_1.LifiErrorCode.TransactionUnderpriced, errors_1.ErrorMessage.TransactionUnderpriced, await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
|
|
85
85
|
}
|
|
86
|
-
if (e.message?.includes(
|
|
87
|
-
e.message?.includes(
|
|
88
|
-
return new errors_1.TransactionError(errors_1.LifiErrorCode.GasLimitError,
|
|
86
|
+
if (e.message?.includes(errors_1.EthersErrorMessage.LowGas) ||
|
|
87
|
+
e.message?.includes(errors_1.EthersErrorMessage.OutOfGas)) {
|
|
88
|
+
return new errors_1.TransactionError(errors_1.LifiErrorCode.GasLimitError, errors_1.ErrorMessage.GasLimitLow, await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
|
|
89
89
|
}
|
|
90
90
|
return new errors_1.RPCError(e.code, (0, eth_rpc_errors_1.getMessageFromCode)(e.code), await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
|
|
91
91
|
}
|
|
@@ -96,9 +96,12 @@ const parseError = async (e, step, process) => {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
switch (e.code) {
|
|
99
|
-
case
|
|
99
|
+
case errors_1.EthersErrorType.CallExecption:
|
|
100
|
+
if (e.reason?.includes?.includes(errors_1.EthersErrorMessage.ERC20Allowance)) {
|
|
101
|
+
return new errors_1.TransactionError(errors_1.LifiErrorCode.AllowanceRequired, e.reason, await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
|
|
102
|
+
}
|
|
100
103
|
return new errors_1.ProviderError(errors_1.LifiErrorCode.TransactionFailed, e.reason, await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
|
|
101
|
-
case
|
|
104
|
+
case errors_1.EthersErrorType.ActionRejected:
|
|
102
105
|
case errors_1.MetaMaskProviderErrorCode.userRejectedRequest:
|
|
103
106
|
return new errors_1.TransactionError(errors_1.LifiErrorCode.TransactionRejected, e.message, await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
|
|
104
107
|
case errors_1.LifiErrorCode.TransactionUnprepared:
|
|
@@ -106,7 +109,7 @@ const parseError = async (e, step, process) => {
|
|
|
106
109
|
case errors_1.LifiErrorCode.ValidationError:
|
|
107
110
|
return new errors_1.TransactionError(errors_1.LifiErrorCode.ValidationError, e.message, e.htmlMessage);
|
|
108
111
|
default:
|
|
109
|
-
return new errors_1.UnknownError(errors_1.LifiErrorCode.InternalError, e.message ||
|
|
112
|
+
return new errors_1.UnknownError(errors_1.LifiErrorCode.InternalError, e.message || errors_1.ErrorMessage.UnknownError, undefined, e.stack);
|
|
110
113
|
}
|
|
111
114
|
};
|
|
112
115
|
exports.parseError = parseError;
|
|
@@ -125,11 +128,19 @@ const parseBackendError = async (e) => {
|
|
|
125
128
|
return new errors_1.NotFoundError(data?.message || e.response?.statusText, undefined, e.stack);
|
|
126
129
|
}
|
|
127
130
|
if (e.response?.status === 409) {
|
|
128
|
-
return new errors_1.SlippageError(data?.message || e.response?.statusText,
|
|
131
|
+
return new errors_1.SlippageError(data?.message || e.response?.statusText, errors_1.ErrorMessage.SlippageError, e.stack);
|
|
129
132
|
}
|
|
130
133
|
if (e.response?.status === 500) {
|
|
131
134
|
return new errors_1.ServerError(data?.message || e.response?.statusText, undefined, e.stack);
|
|
132
135
|
}
|
|
133
|
-
return new errors_1.ServerError(
|
|
136
|
+
return new errors_1.ServerError(errors_1.ErrorMessage.Default, undefined, e.stack);
|
|
134
137
|
};
|
|
135
138
|
exports.parseBackendError = parseBackendError;
|
|
139
|
+
// const fetchTxErrorDetails = async (txHash: string, chainId: number) => {
|
|
140
|
+
// const response = await request<TenderlyResponse>(
|
|
141
|
+
// `https://api.tenderly.co/api/v1/public-contract/${chainId}/tx/${txHash}`,
|
|
142
|
+
// undefined,
|
|
143
|
+
// 0
|
|
144
|
+
// )
|
|
145
|
+
// return response
|
|
146
|
+
// }
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/sdk";
|
|
2
|
-
export declare const version = "2.0.0-beta.
|
|
2
|
+
export declare const version = "2.0.0-beta.9";
|
package/dist/cjs/version.js
CHANGED
|
@@ -75,6 +75,14 @@ export class StepExecutionManager {
|
|
|
75
75
|
if (!this.allowUserInteraction) {
|
|
76
76
|
return step.execution;
|
|
77
77
|
}
|
|
78
|
+
if (settings.updateTransactionRequest) {
|
|
79
|
+
const customConfig = await settings.updateTransactionRequest(transactionRequest);
|
|
80
|
+
transactionRequest.gasLimit = customConfig.gasLimit;
|
|
81
|
+
transactionRequest.gasPrice = customConfig.gasPrice;
|
|
82
|
+
transactionRequest.maxPriorityFeePerGas =
|
|
83
|
+
customConfig.maxPriorityFeePerGas;
|
|
84
|
+
transactionRequest.maxFeePerGas = customConfig.maxFeePerGas;
|
|
85
|
+
}
|
|
78
86
|
// Submit the transaction
|
|
79
87
|
transaction = await signer.sendTransaction(transactionRequest);
|
|
80
88
|
// STEP 4: Wait for the transaction
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LifiStep, Route, Token } from '@lifi/types';
|
|
2
2
|
/**
|
|
3
3
|
* Predefined hook that decrypts calldata using EIP-1193 compliant wallet functions.
|
|
4
4
|
* @param {string} walletAddress - The wallet address of the user that should decrypt the calldata.
|
|
@@ -19,8 +19,8 @@ export declare const isSameToken: (tokenA: Token, tokenB: Token) => boolean;
|
|
|
19
19
|
export declare const checkPackageUpdates: (packageName?: string, packageVersion?: string, disableCheck?: boolean) => Promise<void>;
|
|
20
20
|
/**
|
|
21
21
|
* Converts a quote to Route
|
|
22
|
-
* @param {
|
|
22
|
+
* @param {LifiStep} step - Step returned from the quote endpoint.
|
|
23
23
|
* @return {Route} - The route to be executed.
|
|
24
24
|
* @throws {ValidationError} Throws a ValidationError if the step has missing values.
|
|
25
25
|
*/
|
|
26
|
-
export declare const convertQuoteToRoute: (step:
|
|
26
|
+
export declare const convertQuoteToRoute: (step: LifiStep) => Route;
|
package/dist/helpers.js
CHANGED
|
@@ -73,7 +73,7 @@ export const checkPackageUpdates = async (packageName, packageVersion, disableCh
|
|
|
73
73
|
};
|
|
74
74
|
/**
|
|
75
75
|
* Converts a quote to Route
|
|
76
|
-
* @param {
|
|
76
|
+
* @param {LifiStep} step - Step returned from the quote endpoint.
|
|
77
77
|
* @return {Route} - The route to be executed.
|
|
78
78
|
* @throws {ValidationError} Throws a ValidationError if the step has missing values.
|
|
79
79
|
*/
|
|
@@ -84,11 +84,6 @@ export const convertQuoteToRoute = (step) => {
|
|
|
84
84
|
if (!step.estimate.toAmountUSD) {
|
|
85
85
|
throw new ValidationError("Missing 'toAmountUSD' in step estimate.");
|
|
86
86
|
}
|
|
87
|
-
const lifiStep = {
|
|
88
|
-
...step,
|
|
89
|
-
type: 'lifi',
|
|
90
|
-
includedSteps: [],
|
|
91
|
-
};
|
|
92
87
|
const route = {
|
|
93
88
|
fromToken: step.action.fromToken,
|
|
94
89
|
toToken: step.action.toToken,
|
|
@@ -99,7 +94,7 @@ export const convertQuoteToRoute = (step) => {
|
|
|
99
94
|
toChainId: step.action.toToken.chainId,
|
|
100
95
|
fromAmountUSD: step.estimate.fromAmountUSD,
|
|
101
96
|
toAmountUSD: step.estimate.toAmountUSD,
|
|
102
|
-
steps: [
|
|
97
|
+
steps: [step],
|
|
103
98
|
toAmountMin: step.estimate.toAmountMin,
|
|
104
99
|
insurance: { state: 'NOT_INSURABLE', feeAmountUsd: '0' },
|
|
105
100
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ConnectionsRequest, ConnectionsResponse, ContractCallQuoteRequest, GasRecommendationRequest, GasRecommendationResponse, GetStatusRequest, LifiStep, QuoteRequest, RequestOptions, TokensRequest, TokensResponse } from '@lifi/types';
|
|
2
|
-
import { ChainId, ChainKey, ExtendedChain, PossibilitiesRequest, PossibilitiesResponse, RoutesRequest, RoutesResponse, StatusResponse,
|
|
2
|
+
import { ChainId, ChainKey, ExtendedChain, PossibilitiesRequest, PossibilitiesResponse, RoutesRequest, RoutesResponse, StatusResponse, Token, ToolsRequest, ToolsResponse } from '../types';
|
|
3
3
|
declare const _default: {
|
|
4
4
|
getChains: (options?: RequestOptions | undefined) => Promise<ExtendedChain[]>;
|
|
5
|
-
getContractCallQuote: (requestConfig: ContractCallQuoteRequest, options?: RequestOptions | undefined) => Promise<
|
|
5
|
+
getContractCallQuote: (requestConfig: ContractCallQuoteRequest, options?: RequestOptions | undefined) => Promise<LifiStep>;
|
|
6
6
|
getGasRecommendation: ({ chainId, fromChain, fromToken }: GasRecommendationRequest, options?: RequestOptions | undefined) => Promise<GasRecommendationResponse>;
|
|
7
7
|
getPossibilities: (requestConfig?: PossibilitiesRequest | undefined, options?: RequestOptions | undefined) => Promise<PossibilitiesResponse>;
|
|
8
|
-
getQuote: (requestConfig: QuoteRequest, options?: RequestOptions | undefined) => Promise<
|
|
8
|
+
getQuote: (requestConfig: QuoteRequest, options?: RequestOptions | undefined) => Promise<LifiStep>;
|
|
9
9
|
getRoutes: (requestConfig: RoutesRequest, options?: RequestOptions | undefined) => Promise<RoutesResponse>;
|
|
10
10
|
getStatus: (requestConfig: GetStatusRequest, options?: RequestOptions | undefined) => Promise<StatusResponse>;
|
|
11
11
|
getStepTransaction: (step: LifiStep, options?: RequestOptions | undefined) => Promise<LifiStep>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TransactionRequest } from '@ethersproject/abstract-provider';
|
|
1
2
|
import { LifiStep, Route, RouteOptions, Token } from '@lifi/types';
|
|
2
3
|
import BigNumber from 'bignumber.js';
|
|
3
4
|
import { Signer } from 'ethers';
|
|
@@ -23,6 +24,7 @@ export interface ExecutionParams {
|
|
|
23
24
|
settings: InternalExecutionSettings;
|
|
24
25
|
}
|
|
25
26
|
export type CallbackFunction = (updatedRoute: Route) => void;
|
|
27
|
+
export type TxRequestCallbackFunction = (updatedTxRequest: TransactionRequest) => Promise<TransactionRequest>;
|
|
26
28
|
export type Config = {
|
|
27
29
|
apiUrl: string;
|
|
28
30
|
rpcs: Record<ChainId, string[]>;
|
|
@@ -73,6 +75,7 @@ export interface InternalExecutionSettings {
|
|
|
73
75
|
acceptExchangeRateUpdateHook: AcceptExchangeRateUpdateHook;
|
|
74
76
|
infiniteApproval: boolean;
|
|
75
77
|
executeInBackground: boolean;
|
|
78
|
+
updateTransactionRequest?: TxRequestCallbackFunction;
|
|
76
79
|
}
|
|
77
80
|
export type EnforcedObjectProperties<T> = T & {
|
|
78
81
|
[P in keyof T]-?: T[P];
|
|
@@ -88,3 +91,43 @@ export interface InteractionSettings {
|
|
|
88
91
|
allowUpdates?: boolean;
|
|
89
92
|
stopExecution?: boolean;
|
|
90
93
|
}
|
|
94
|
+
export interface TenderlyResponse {
|
|
95
|
+
hash: string;
|
|
96
|
+
block_hash: string;
|
|
97
|
+
block_number: number;
|
|
98
|
+
from: string;
|
|
99
|
+
gas: number;
|
|
100
|
+
gas_price: number;
|
|
101
|
+
gas_fee_cap: number;
|
|
102
|
+
gas_tip_cap: number;
|
|
103
|
+
cumulative_gas_used: number;
|
|
104
|
+
gas_used: number;
|
|
105
|
+
effective_gas_price: number;
|
|
106
|
+
input: string;
|
|
107
|
+
nonce: number;
|
|
108
|
+
to: string;
|
|
109
|
+
index: number;
|
|
110
|
+
value: string;
|
|
111
|
+
access_list: any;
|
|
112
|
+
status: boolean;
|
|
113
|
+
addresses: string[];
|
|
114
|
+
contract_ids: string[];
|
|
115
|
+
network_id: string;
|
|
116
|
+
timestamp: string;
|
|
117
|
+
function_selector: string;
|
|
118
|
+
l1_block_number: number;
|
|
119
|
+
l1_timestamp: number;
|
|
120
|
+
deposit_tx: boolean;
|
|
121
|
+
system_tx: boolean;
|
|
122
|
+
mint: number;
|
|
123
|
+
sig: Signature;
|
|
124
|
+
error_message: string;
|
|
125
|
+
method: string;
|
|
126
|
+
decoded_input: any;
|
|
127
|
+
call_trace: any;
|
|
128
|
+
}
|
|
129
|
+
export interface Signature {
|
|
130
|
+
v: string;
|
|
131
|
+
r: string;
|
|
132
|
+
s: string;
|
|
133
|
+
}
|
package/dist/utils/errors.d.ts
CHANGED
|
@@ -22,7 +22,26 @@ export declare enum LifiErrorCode {
|
|
|
22
22
|
TransactionCanceled = 1010,
|
|
23
23
|
SlippageError = 1011,
|
|
24
24
|
TransactionRejected = 1012,
|
|
25
|
-
BalanceError = 1013
|
|
25
|
+
BalanceError = 1013,
|
|
26
|
+
AllowanceRequired = 1014
|
|
27
|
+
}
|
|
28
|
+
export declare enum EthersErrorType {
|
|
29
|
+
CallExecption = "CALL_EXCEPTION",
|
|
30
|
+
ActionRejected = "ACTION_REJECTED"
|
|
31
|
+
}
|
|
32
|
+
export declare enum EthersErrorMessage {
|
|
33
|
+
ERC20Allowance = "ERC20: transfer amount exceeds allowance",
|
|
34
|
+
LowGas = "intrinsic gas too low",
|
|
35
|
+
OutOfGas = "out of gas",
|
|
36
|
+
Underpriced = "underpriced",
|
|
37
|
+
LowReplacementFee = "replacement fee too low"
|
|
38
|
+
}
|
|
39
|
+
export declare enum ErrorMessage {
|
|
40
|
+
UnknownError = "Unknown error occurred.",
|
|
41
|
+
SlippageError = "The slippage is larger than the defined threshold. Please request a new route to get a fresh quote.",
|
|
42
|
+
GasLimitLow = "Gas limit is too low.",
|
|
43
|
+
TransactionUnderpriced = "Transaction is underpriced.",
|
|
44
|
+
Default = "Something went wrong."
|
|
26
45
|
}
|
|
27
46
|
export declare enum MetaMaskRPCErrorCode {
|
|
28
47
|
invalidInput = -32000,
|
package/dist/utils/errors.js
CHANGED
|
@@ -25,7 +25,29 @@ export var LifiErrorCode;
|
|
|
25
25
|
LifiErrorCode[LifiErrorCode["SlippageError"] = 1011] = "SlippageError";
|
|
26
26
|
LifiErrorCode[LifiErrorCode["TransactionRejected"] = 1012] = "TransactionRejected";
|
|
27
27
|
LifiErrorCode[LifiErrorCode["BalanceError"] = 1013] = "BalanceError";
|
|
28
|
+
LifiErrorCode[LifiErrorCode["AllowanceRequired"] = 1014] = "AllowanceRequired";
|
|
28
29
|
})(LifiErrorCode || (LifiErrorCode = {}));
|
|
30
|
+
export var EthersErrorType;
|
|
31
|
+
(function (EthersErrorType) {
|
|
32
|
+
EthersErrorType["CallExecption"] = "CALL_EXCEPTION";
|
|
33
|
+
EthersErrorType["ActionRejected"] = "ACTION_REJECTED";
|
|
34
|
+
})(EthersErrorType || (EthersErrorType = {}));
|
|
35
|
+
export var EthersErrorMessage;
|
|
36
|
+
(function (EthersErrorMessage) {
|
|
37
|
+
EthersErrorMessage["ERC20Allowance"] = "ERC20: transfer amount exceeds allowance";
|
|
38
|
+
EthersErrorMessage["LowGas"] = "intrinsic gas too low";
|
|
39
|
+
EthersErrorMessage["OutOfGas"] = "out of gas";
|
|
40
|
+
EthersErrorMessage["Underpriced"] = "underpriced";
|
|
41
|
+
EthersErrorMessage["LowReplacementFee"] = "replacement fee too low";
|
|
42
|
+
})(EthersErrorMessage || (EthersErrorMessage = {}));
|
|
43
|
+
export var ErrorMessage;
|
|
44
|
+
(function (ErrorMessage) {
|
|
45
|
+
ErrorMessage["UnknownError"] = "Unknown error occurred.";
|
|
46
|
+
ErrorMessage["SlippageError"] = "The slippage is larger than the defined threshold. Please request a new route to get a fresh quote.";
|
|
47
|
+
ErrorMessage["GasLimitLow"] = "Gas limit is too low.";
|
|
48
|
+
ErrorMessage["TransactionUnderpriced"] = "Transaction is underpriced.";
|
|
49
|
+
ErrorMessage["Default"] = "Something went wrong.";
|
|
50
|
+
})(ErrorMessage || (ErrorMessage = {}));
|
|
29
51
|
export var MetaMaskRPCErrorCode;
|
|
30
52
|
(function (MetaMaskRPCErrorCode) {
|
|
31
53
|
MetaMaskRPCErrorCode[MetaMaskRPCErrorCode["invalidInput"] = -32000] = "invalidInput";
|
package/dist/utils/parseError.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { errorCodes as MetaMaskErrorCodes, getMessageFromCode, } from 'eth-rpc-errors';
|
|
2
2
|
import ChainsService from '../services/ChainsService';
|
|
3
|
-
import { LifiError, LifiErrorCode, MetaMaskProviderErrorCode, NotFoundError, ProviderError, RPCError, ServerError, SlippageError, TransactionError, UnknownError, ValidationError, } from './errors';
|
|
3
|
+
import { ErrorMessage, EthersErrorType, EthersErrorMessage, LifiError, LifiErrorCode, MetaMaskProviderErrorCode, NotFoundError, ProviderError, RPCError, ServerError, SlippageError, TransactionError, UnknownError, ValidationError, } from './errors';
|
|
4
4
|
import { formatTokenAmountOnly } from './utils';
|
|
5
5
|
/**
|
|
6
6
|
* Available MetaMask error codes:
|
|
@@ -71,13 +71,13 @@ export const parseError = async (e, step, process) => {
|
|
|
71
71
|
// rpc errors
|
|
72
72
|
// underpriced errors are sent as internal errors, so we need to parse the message manually
|
|
73
73
|
if (e.code === MetaMaskErrorCodes.rpc.internal &&
|
|
74
|
-
(e.message?.includes(
|
|
75
|
-
e.message?.includes(
|
|
76
|
-
return new RPCError(LifiErrorCode.TransactionUnderpriced,
|
|
74
|
+
(e.message?.includes(EthersErrorMessage.Underpriced) ||
|
|
75
|
+
e.message?.includes(EthersErrorMessage.LowReplacementFee))) {
|
|
76
|
+
return new RPCError(LifiErrorCode.TransactionUnderpriced, ErrorMessage.TransactionUnderpriced, await getTransactionNotSentMessage(step, process), e.stack);
|
|
77
77
|
}
|
|
78
|
-
if (e.message?.includes(
|
|
79
|
-
e.message?.includes(
|
|
80
|
-
return new TransactionError(LifiErrorCode.GasLimitError,
|
|
78
|
+
if (e.message?.includes(EthersErrorMessage.LowGas) ||
|
|
79
|
+
e.message?.includes(EthersErrorMessage.OutOfGas)) {
|
|
80
|
+
return new TransactionError(LifiErrorCode.GasLimitError, ErrorMessage.GasLimitLow, await getTransactionNotSentMessage(step, process), e.stack);
|
|
81
81
|
}
|
|
82
82
|
return new RPCError(e.code, getMessageFromCode(e.code), await getTransactionNotSentMessage(step, process), e.stack);
|
|
83
83
|
}
|
|
@@ -88,9 +88,12 @@ export const parseError = async (e, step, process) => {
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
switch (e.code) {
|
|
91
|
-
case
|
|
91
|
+
case EthersErrorType.CallExecption:
|
|
92
|
+
if (e.reason?.includes?.includes(EthersErrorMessage.ERC20Allowance)) {
|
|
93
|
+
return new TransactionError(LifiErrorCode.AllowanceRequired, e.reason, await getTransactionNotSentMessage(step, process), e.stack);
|
|
94
|
+
}
|
|
92
95
|
return new ProviderError(LifiErrorCode.TransactionFailed, e.reason, await getTransactionNotSentMessage(step, process), e.stack);
|
|
93
|
-
case
|
|
96
|
+
case EthersErrorType.ActionRejected:
|
|
94
97
|
case MetaMaskProviderErrorCode.userRejectedRequest:
|
|
95
98
|
return new TransactionError(LifiErrorCode.TransactionRejected, e.message, await getTransactionNotSentMessage(step, process), e.stack);
|
|
96
99
|
case LifiErrorCode.TransactionUnprepared:
|
|
@@ -98,7 +101,7 @@ export const parseError = async (e, step, process) => {
|
|
|
98
101
|
case LifiErrorCode.ValidationError:
|
|
99
102
|
return new TransactionError(LifiErrorCode.ValidationError, e.message, e.htmlMessage);
|
|
100
103
|
default:
|
|
101
|
-
return new UnknownError(LifiErrorCode.InternalError, e.message ||
|
|
104
|
+
return new UnknownError(LifiErrorCode.InternalError, e.message || ErrorMessage.UnknownError, undefined, e.stack);
|
|
102
105
|
}
|
|
103
106
|
};
|
|
104
107
|
export const parseBackendError = async (e) => {
|
|
@@ -116,10 +119,18 @@ export const parseBackendError = async (e) => {
|
|
|
116
119
|
return new NotFoundError(data?.message || e.response?.statusText, undefined, e.stack);
|
|
117
120
|
}
|
|
118
121
|
if (e.response?.status === 409) {
|
|
119
|
-
return new SlippageError(data?.message || e.response?.statusText,
|
|
122
|
+
return new SlippageError(data?.message || e.response?.statusText, ErrorMessage.SlippageError, e.stack);
|
|
120
123
|
}
|
|
121
124
|
if (e.response?.status === 500) {
|
|
122
125
|
return new ServerError(data?.message || e.response?.statusText, undefined, e.stack);
|
|
123
126
|
}
|
|
124
|
-
return new ServerError(
|
|
127
|
+
return new ServerError(ErrorMessage.Default, undefined, e.stack);
|
|
125
128
|
};
|
|
129
|
+
// const fetchTxErrorDetails = async (txHash: string, chainId: number) => {
|
|
130
|
+
// const response = await request<TenderlyResponse>(
|
|
131
|
+
// `https://api.tenderly.co/api/v1/public-contract/${chainId}/tx/${txHash}`,
|
|
132
|
+
// undefined,
|
|
133
|
+
// 0
|
|
134
|
+
// )
|
|
135
|
+
// return response
|
|
136
|
+
// }
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/sdk";
|
|
2
|
-
export declare const version = "2.0.0-beta.
|
|
2
|
+
export declare const version = "2.0.0-beta.9";
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/sdk';
|
|
2
|
-
export const version = '2.0.0-beta.
|
|
2
|
+
export const version = '2.0.0-beta.9';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/sdk",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.9",
|
|
4
4
|
"description": "LI.FI Any-to-Any Cross-Chain-Swap SDK",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -76,17 +76,17 @@
|
|
|
76
76
|
"dependencies": {
|
|
77
77
|
"@ethersproject/abi": "^5.7.0",
|
|
78
78
|
"@ethersproject/contracts": "^5.7.0",
|
|
79
|
-
"@lifi/types": "^3.2.
|
|
79
|
+
"@lifi/types": "^3.2.7",
|
|
80
80
|
"bignumber.js": "^9.1.1",
|
|
81
81
|
"eth-rpc-errors": "^4.0.3",
|
|
82
82
|
"ethers": "^5.7.2"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
|
-
"@commitlint/cli": "^17.
|
|
86
|
-
"@commitlint/config-conventional": "^17.
|
|
87
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
88
|
-
"@typescript-eslint/parser": "^5.
|
|
89
|
-
"@vitest/coverage-c8": "^0.30.
|
|
85
|
+
"@commitlint/cli": "^17.6.1",
|
|
86
|
+
"@commitlint/config-conventional": "^17.6.1",
|
|
87
|
+
"@typescript-eslint/eslint-plugin": "^5.59.0",
|
|
88
|
+
"@typescript-eslint/parser": "^5.59.0",
|
|
89
|
+
"@vitest/coverage-c8": "^0.30.1",
|
|
90
90
|
"cross-fetch": "^3.1.5",
|
|
91
91
|
"eslint": "^8.38.0",
|
|
92
92
|
"eslint-config-prettier": "^8.8.0",
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
"standard-version": "^9.5.0",
|
|
101
101
|
"ts-loader": "^9.4.2",
|
|
102
102
|
"typescript": "^5.0.4",
|
|
103
|
-
"vitest": "^0.30.
|
|
103
|
+
"vitest": "^0.30.1"
|
|
104
104
|
},
|
|
105
105
|
"directories": {
|
|
106
106
|
"test": "test"
|