@lifi/sdk 1.6.3 → 1.7.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/CHANGELOG.md +9 -0
- package/dist/Lifi.d.ts +1 -1
- package/dist/Lifi.js +5 -5
- package/dist/{cjs/execution/allowance.execute.d.ts → allowance/checkAllowance.d.ts} +1 -1
- package/dist/{execution/allowance.execute.js → allowance/checkAllowance.js} +1 -0
- package/dist/allowance/index.d.ts +2 -22
- package/dist/allowance/index.js +2 -68
- package/dist/allowance/tokenApproval.d.ts +22 -0
- package/dist/allowance/tokenApproval.js +68 -0
- package/dist/balance/checkBalance.d.ts +3 -0
- package/dist/{execution/balanceCheck.execute.js → balance/checkBalance.js} +12 -6
- package/dist/balance/getTokenBalance.d.ts +8 -0
- package/dist/{balances/index.js → balance/getTokenBalance.js} +3 -8
- package/dist/balance/index.d.ts +2 -0
- package/dist/balance/index.js +2 -0
- package/dist/{balances → balance}/utils.d.ts +0 -0
- package/dist/{balances → balance}/utils.js +1 -1
- package/dist/cjs/Lifi.d.ts +1 -1
- package/dist/cjs/Lifi.js +28 -5
- package/dist/{execution/allowance.execute.d.ts → cjs/allowance/checkAllowance.d.ts} +1 -1
- package/dist/cjs/{execution/allowance.execute.js → allowance/checkAllowance.js} +1 -0
- package/dist/cjs/allowance/index.d.ts +2 -22
- package/dist/cjs/allowance/index.js +15 -75
- package/dist/cjs/allowance/tokenApproval.d.ts +22 -0
- package/dist/cjs/allowance/tokenApproval.js +78 -0
- package/dist/cjs/balance/checkBalance.d.ts +3 -0
- package/dist/cjs/{execution/balanceCheck.execute.js → balance/checkBalance.js} +13 -7
- package/dist/cjs/balance/getTokenBalance.d.ts +8 -0
- package/dist/cjs/{balances/index.js → balance/getTokenBalance.js} +6 -7
- package/dist/cjs/balance/index.d.ts +2 -0
- package/dist/cjs/balance/index.js +18 -0
- package/dist/cjs/{balances → balance}/utils.d.ts +0 -0
- package/dist/cjs/{balances → balance}/utils.js +1 -1
- package/dist/cjs/execution/{exchanges/swap.execute.d.ts → ExecutionManager.d.ts} +3 -3
- package/dist/cjs/execution/{bridges/bridge.execute.js → ExecutionManager.js} +52 -37
- package/dist/cjs/execution/StatusManager.d.ts +6 -3
- package/dist/cjs/execution/StatusManager.js +1 -3
- package/dist/cjs/execution/StepExecutor.d.ts +3 -5
- package/dist/cjs/execution/StepExecutor.js +7 -32
- package/dist/cjs/execution/stepComparison.d.ts +4 -4
- package/dist/cjs/execution/stepComparison.js +11 -7
- package/dist/cjs/execution/switchChain.js +1 -1
- package/dist/cjs/execution/utils.d.ts +1 -1
- package/dist/cjs/execution/utils.js +11 -10
- package/dist/cjs/services/ConfigService.js +1 -0
- package/dist/cjs/types/internal.types.d.ts +18 -24
- package/dist/cjs/utils/errors.d.ts +7 -3
- package/dist/cjs/utils/errors.js +9 -2
- package/dist/cjs/utils/multicall.d.ts +1 -1
- package/dist/cjs/utils/parseError.d.ts +0 -1
- package/dist/cjs/utils/parseError.js +1 -7
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/execution/{exchanges/swap.execute.d.ts → ExecutionManager.d.ts} +3 -3
- package/dist/execution/{bridges/bridge.execute.js → ExecutionManager.js} +49 -34
- package/dist/execution/StatusManager.d.ts +6 -3
- package/dist/execution/StatusManager.js +1 -3
- package/dist/execution/StepExecutor.d.ts +3 -5
- package/dist/execution/StepExecutor.js +7 -32
- package/dist/execution/stepComparison.d.ts +4 -4
- package/dist/execution/stepComparison.js +12 -8
- package/dist/execution/switchChain.js +1 -1
- package/dist/execution/utils.d.ts +1 -1
- package/dist/execution/utils.js +9 -8
- package/dist/services/ConfigService.js +1 -0
- package/dist/types/internal.types.d.ts +18 -24
- package/dist/utils/errors.d.ts +7 -3
- package/dist/utils/errors.js +7 -1
- package/dist/utils/multicall.d.ts +1 -1
- package/dist/utils/parseError.d.ts +0 -1
- package/dist/utils/parseError.js +0 -5
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +13 -15
- package/dist/balances/index.d.ts +0 -11
- package/dist/cjs/balances/index.d.ts +0 -11
- package/dist/cjs/execution/balanceCheck.execute.d.ts +0 -3
- package/dist/cjs/execution/bridges/bridge.execute.d.ts +0 -7
- package/dist/cjs/execution/exchanges/swap.execute.js +0 -152
- package/dist/execution/balanceCheck.execute.d.ts +0 -3
- package/dist/execution/bridges/bridge.execute.d.ts +0 -7
- package/dist/execution/exchanges/swap.execute.js +0 -145
|
@@ -8,12 +8,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { LifiErrorCode, TransactionError } from '../utils/errors';
|
|
11
|
-
import {
|
|
12
|
-
import { updatedStepMeetsSlippageConditions } from './utils';
|
|
11
|
+
import { checkStepSlippageThreshold } from './utils';
|
|
13
12
|
/**
|
|
14
|
-
* This method checks whether the new and updated Step meets the required
|
|
13
|
+
* This method checks whether the new and updated Step meets the required exchange rate conditions.
|
|
15
14
|
* If yes it returns the updated Step.
|
|
16
|
-
* If no and if user interaction is allowed it triggers the
|
|
15
|
+
* If no and if user interaction is allowed it triggers the acceptExchangeRateUpdateHook. If no user interaction is allowed it aborts.
|
|
17
16
|
*
|
|
18
17
|
* @param statusManager
|
|
19
18
|
* @param oldStep
|
|
@@ -21,13 +20,16 @@ import { updatedStepMeetsSlippageConditions } from './utils';
|
|
|
21
20
|
* @param acceptSlippageUpdateHook
|
|
22
21
|
* @param allowUserInteraction
|
|
23
22
|
*/
|
|
24
|
-
export const stepComparison = (statusManager, oldStep, newStep,
|
|
25
|
-
|
|
23
|
+
export const stepComparison = (statusManager, oldStep, newStep, settings, allowUserInteraction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
var _a;
|
|
25
|
+
// Check if changed exchange rate is in the range of slippage threshold
|
|
26
|
+
if (checkStepSlippageThreshold(oldStep, newStep)) {
|
|
26
27
|
return statusManager.updateStepInRoute(newStep);
|
|
27
28
|
}
|
|
29
|
+
const acceptExchangeRateUpdateHook = (_a = settings.acceptExchangeRateUpdateHook) !== null && _a !== void 0 ? _a : settings.acceptSlippageUpdateHook;
|
|
28
30
|
let allowStepUpdate;
|
|
29
31
|
if (allowUserInteraction) {
|
|
30
|
-
allowStepUpdate = yield
|
|
32
|
+
allowStepUpdate = yield acceptExchangeRateUpdateHook({
|
|
31
33
|
oldToAmount: oldStep.estimate.toAmount,
|
|
32
34
|
newToAmount: newStep.estimate.toAmount,
|
|
33
35
|
toToken: newStep.action.toToken,
|
|
@@ -36,7 +38,9 @@ export const stepComparison = (statusManager, oldStep, newStep, acceptSlippageUp
|
|
|
36
38
|
});
|
|
37
39
|
}
|
|
38
40
|
if (!allowStepUpdate) {
|
|
39
|
-
|
|
41
|
+
// The user declined the new exchange rate, so we are not going to proceed
|
|
42
|
+
throw new TransactionError(LifiErrorCode.TransactionCanceled, 'Exchange rate has changed!', `Transaction was not sent, your funds are still in your wallet.
|
|
43
|
+
The exchange rate has changed and the previous estimation can not be fulfilled due to value loss.`);
|
|
40
44
|
}
|
|
41
45
|
return statusManager.updateStepInRoute(newStep);
|
|
42
46
|
});
|
|
@@ -42,7 +42,7 @@ export const switchChain = (signer, statusManager, step, switchChainHook, allowU
|
|
|
42
42
|
return updatedSigner;
|
|
43
43
|
}
|
|
44
44
|
catch (error) {
|
|
45
|
-
|
|
45
|
+
statusManager.updateProcess(step, switchProcess.type, 'FAILED', {
|
|
46
46
|
error: {
|
|
47
47
|
message: error.message,
|
|
48
48
|
code: LifiErrorCode.ChainSwitchError,
|
|
@@ -3,4 +3,4 @@ import { StatusManager } from '..';
|
|
|
3
3
|
export declare function waitForReceivingTransaction(txHash: string, statusManager: StatusManager, processType: ProcessType, step: Step): Promise<StatusResponse>;
|
|
4
4
|
export declare function getProcessMessage(type: ProcessType, status: Status): string | undefined;
|
|
5
5
|
export declare function getSubstatusMessage(status: StatusMessage, substatus?: Substatus): string | undefined;
|
|
6
|
-
export declare function
|
|
6
|
+
export declare function checkStepSlippageThreshold(oldStep: Step, newStep: Step): boolean;
|
package/dist/execution/utils.js
CHANGED
|
@@ -69,20 +69,20 @@ const processMessages = {
|
|
|
69
69
|
DONE: 'Chain switched successfully.',
|
|
70
70
|
},
|
|
71
71
|
SWAP: {
|
|
72
|
-
STARTED: 'Preparing swap.',
|
|
72
|
+
STARTED: 'Preparing swap transaction.',
|
|
73
73
|
ACTION_REQUIRED: 'Please sign the transaction.',
|
|
74
|
-
PENDING: '
|
|
74
|
+
PENDING: 'Waiting for swap transaction.',
|
|
75
75
|
DONE: 'Swap completed.',
|
|
76
76
|
},
|
|
77
77
|
CROSS_CHAIN: {
|
|
78
|
-
STARTED: 'Preparing transaction.',
|
|
78
|
+
STARTED: 'Preparing bridge transaction.',
|
|
79
79
|
ACTION_REQUIRED: 'Please sign the transaction.',
|
|
80
|
-
PENDING: 'Waiting for transaction.',
|
|
81
|
-
DONE: '
|
|
80
|
+
PENDING: 'Waiting for bridge transaction.',
|
|
81
|
+
DONE: 'Bridge transaction confirmed.',
|
|
82
82
|
},
|
|
83
83
|
RECEIVING_CHAIN: {
|
|
84
|
-
PENDING: 'Waiting for
|
|
85
|
-
DONE: '
|
|
84
|
+
PENDING: 'Waiting for destination chain.',
|
|
85
|
+
DONE: 'Bridge completed.',
|
|
86
86
|
},
|
|
87
87
|
TRANSACTION: {},
|
|
88
88
|
};
|
|
@@ -115,7 +115,8 @@ export function getSubstatusMessage(status, substatus) {
|
|
|
115
115
|
const message = substatusMessages[status][substatus];
|
|
116
116
|
return message;
|
|
117
117
|
}
|
|
118
|
-
|
|
118
|
+
// Used to check if changed exchange rate is in the range of slippage threshold
|
|
119
|
+
export function checkStepSlippageThreshold(oldStep, newStep) {
|
|
119
120
|
const setSlippage = new BigNumber(oldStep.action.slippage);
|
|
120
121
|
const oldEstimatedToAmount = new BigNumber(oldStep.estimate.toAmountMin);
|
|
121
122
|
const newEstimatedToAmount = new BigNumber(newStep.estimate.toAmountMin);
|
|
@@ -13,6 +13,7 @@ const DefaultExecutionSettings = {
|
|
|
13
13
|
updateCallback: () => { },
|
|
14
14
|
switchChainHook: () => Promise.resolve(undefined),
|
|
15
15
|
acceptSlippageUpdateHook: () => Promise.resolve(undefined),
|
|
16
|
+
acceptExchangeRateUpdateHook: () => Promise.resolve(undefined),
|
|
16
17
|
infiniteApproval: false,
|
|
17
18
|
executeInBackground: false,
|
|
18
19
|
};
|
|
@@ -8,7 +8,7 @@ export interface TokenWithAmounts extends Token {
|
|
|
8
8
|
amount?: BigNumber;
|
|
9
9
|
amountRendered?: string;
|
|
10
10
|
}
|
|
11
|
-
export
|
|
11
|
+
export type ParsedReceipt = {
|
|
12
12
|
fromAmount?: string;
|
|
13
13
|
toAmount: string;
|
|
14
14
|
gasUsed: string;
|
|
@@ -16,20 +16,14 @@ export declare type ParsedReceipt = {
|
|
|
16
16
|
gasFee: string;
|
|
17
17
|
toTokenAddress?: string;
|
|
18
18
|
};
|
|
19
|
-
interface ExecutionParams {
|
|
19
|
+
export interface ExecutionParams {
|
|
20
20
|
signer: Signer;
|
|
21
21
|
step: Step;
|
|
22
22
|
statusManager: StatusManager;
|
|
23
23
|
settings: InternalExecutionSettings;
|
|
24
24
|
}
|
|
25
|
-
export
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
export interface ExecuteCrossParams extends ExecutionParams {
|
|
29
|
-
step: Step;
|
|
30
|
-
}
|
|
31
|
-
export declare type CallbackFunction = (updatedRoute: Route) => void;
|
|
32
|
-
export declare type Config = {
|
|
25
|
+
export type CallbackFunction = (updatedRoute: Route) => void;
|
|
26
|
+
export type Config = {
|
|
33
27
|
apiUrl: string;
|
|
34
28
|
rpcs: Record<ChainId, string[]>;
|
|
35
29
|
multicallAddresses: Record<ChainId, string | undefined>;
|
|
@@ -37,7 +31,7 @@ export declare type Config = {
|
|
|
37
31
|
defaultRouteOptions: RouteOptions;
|
|
38
32
|
disableVersionCheck?: boolean;
|
|
39
33
|
};
|
|
40
|
-
export
|
|
34
|
+
export type ConfigUpdate = {
|
|
41
35
|
apiUrl?: string;
|
|
42
36
|
rpcs?: Record<number, string[]>;
|
|
43
37
|
multicallAddresses?: Record<number, string | undefined>;
|
|
@@ -45,7 +39,7 @@ export declare type ConfigUpdate = {
|
|
|
45
39
|
defaultRouteOptions?: RouteOptions;
|
|
46
40
|
disableVersionCheck?: boolean;
|
|
47
41
|
};
|
|
48
|
-
export
|
|
42
|
+
export type SwitchChainHook = (requiredChainId: number) => Promise<Signer | undefined>;
|
|
49
43
|
export interface AcceptSlippageUpdateHookParams {
|
|
50
44
|
toToken: Token;
|
|
51
45
|
oldToAmount: string;
|
|
@@ -53,33 +47,34 @@ export interface AcceptSlippageUpdateHookParams {
|
|
|
53
47
|
oldSlippage: number;
|
|
54
48
|
newSlippage: number;
|
|
55
49
|
}
|
|
56
|
-
export
|
|
50
|
+
export type AcceptSlippageUpdateHook = (params: AcceptSlippageUpdateHookParams) => Promise<boolean | undefined>;
|
|
51
|
+
export interface ExchangeRateUpdateParams {
|
|
52
|
+
toToken: Token;
|
|
53
|
+
oldToAmount: string;
|
|
54
|
+
newToAmount: string;
|
|
55
|
+
}
|
|
56
|
+
export type AcceptExchangeRateUpdateHook = (params: ExchangeRateUpdateParams) => Promise<boolean | undefined>;
|
|
57
57
|
export interface ExecutionData {
|
|
58
58
|
route: Route;
|
|
59
59
|
executors: StepExecutor[];
|
|
60
60
|
settings: InternalExecutionSettings;
|
|
61
61
|
}
|
|
62
|
-
export
|
|
63
|
-
|
|
64
|
-
switchChainHook?: SwitchChainHook;
|
|
65
|
-
acceptSlippageUpdateHook?: AcceptSlippageUpdateHook;
|
|
66
|
-
infiniteApproval?: boolean;
|
|
67
|
-
executeInBackground?: boolean;
|
|
68
|
-
}
|
|
69
|
-
export interface InternalExecutionSettings extends ExecutionSettings {
|
|
62
|
+
export type ExecutionSettings = Partial<InternalExecutionSettings>;
|
|
63
|
+
export interface InternalExecutionSettings {
|
|
70
64
|
updateCallback: CallbackFunction;
|
|
71
65
|
switchChainHook: SwitchChainHook;
|
|
72
66
|
acceptSlippageUpdateHook: AcceptSlippageUpdateHook;
|
|
67
|
+
acceptExchangeRateUpdateHook: AcceptExchangeRateUpdateHook;
|
|
73
68
|
infiniteApproval: boolean;
|
|
74
69
|
executeInBackground: boolean;
|
|
75
70
|
}
|
|
76
|
-
export
|
|
71
|
+
export type EnforcedObjectProperties<T> = T & {
|
|
77
72
|
[P in keyof T]-?: T[P];
|
|
78
73
|
};
|
|
79
74
|
export interface ActiveRouteDictionary {
|
|
80
75
|
[k: string]: ExecutionData;
|
|
81
76
|
}
|
|
82
|
-
export
|
|
77
|
+
export type RevokeTokenData = {
|
|
83
78
|
token: Token;
|
|
84
79
|
approvalAddress: string;
|
|
85
80
|
};
|
|
@@ -88,4 +83,3 @@ export interface InteractionSettings {
|
|
|
88
83
|
allowUpdates?: boolean;
|
|
89
84
|
stopExecution?: boolean;
|
|
90
85
|
}
|
|
91
|
-
export {};
|
package/dist/utils/errors.d.ts
CHANGED
|
@@ -19,9 +19,10 @@ export declare enum LifiErrorCode {
|
|
|
19
19
|
ChainSwitchError = 1007,
|
|
20
20
|
TransactionUnprepared = 1008,
|
|
21
21
|
GasLimitError = 1009,
|
|
22
|
-
|
|
22
|
+
TransactionCanceled = 1010,
|
|
23
23
|
SlippageError = 1011,
|
|
24
|
-
TransactionRejected = 1012
|
|
24
|
+
TransactionRejected = 1012,
|
|
25
|
+
BalanceError = 1013
|
|
25
26
|
}
|
|
26
27
|
export declare enum MetaMaskRPCErrorCode {
|
|
27
28
|
invalidInput = -32000,
|
|
@@ -43,7 +44,7 @@ export declare enum MetaMaskProviderErrorCode {
|
|
|
43
44
|
disconnected = 4900,
|
|
44
45
|
chainDisconnected = 4901
|
|
45
46
|
}
|
|
46
|
-
export
|
|
47
|
+
export type ErrorCode = LifiErrorCode | MetaMaskRPCErrorCode | MetaMaskProviderErrorCode;
|
|
47
48
|
export declare class LifiError extends Error {
|
|
48
49
|
code: ErrorCode;
|
|
49
50
|
htmlMessage?: string;
|
|
@@ -67,6 +68,9 @@ export declare class TransactionError extends LifiError {
|
|
|
67
68
|
export declare class SlippageError extends LifiError {
|
|
68
69
|
constructor(message: string, htmlMessage?: string, stack?: string);
|
|
69
70
|
}
|
|
71
|
+
export declare class BalanceError extends LifiError {
|
|
72
|
+
constructor(message: string, htmlMessage?: string, stack?: string);
|
|
73
|
+
}
|
|
70
74
|
export declare class NotFoundError extends LifiError {
|
|
71
75
|
constructor(message: string, htmlMessage?: string, stack?: string);
|
|
72
76
|
}
|
package/dist/utils/errors.js
CHANGED
|
@@ -21,9 +21,10 @@ export var LifiErrorCode;
|
|
|
21
21
|
LifiErrorCode[LifiErrorCode["ChainSwitchError"] = 1007] = "ChainSwitchError";
|
|
22
22
|
LifiErrorCode[LifiErrorCode["TransactionUnprepared"] = 1008] = "TransactionUnprepared";
|
|
23
23
|
LifiErrorCode[LifiErrorCode["GasLimitError"] = 1009] = "GasLimitError";
|
|
24
|
-
LifiErrorCode[LifiErrorCode["
|
|
24
|
+
LifiErrorCode[LifiErrorCode["TransactionCanceled"] = 1010] = "TransactionCanceled";
|
|
25
25
|
LifiErrorCode[LifiErrorCode["SlippageError"] = 1011] = "SlippageError";
|
|
26
26
|
LifiErrorCode[LifiErrorCode["TransactionRejected"] = 1012] = "TransactionRejected";
|
|
27
|
+
LifiErrorCode[LifiErrorCode["BalanceError"] = 1013] = "BalanceError";
|
|
27
28
|
})(LifiErrorCode || (LifiErrorCode = {}));
|
|
28
29
|
export var MetaMaskRPCErrorCode;
|
|
29
30
|
(function (MetaMaskRPCErrorCode) {
|
|
@@ -92,6 +93,11 @@ export class SlippageError extends LifiError {
|
|
|
92
93
|
super(ErrorType.SlippageError, LifiErrorCode.SlippageError, message, htmlMessage, stack);
|
|
93
94
|
}
|
|
94
95
|
}
|
|
96
|
+
export class BalanceError extends LifiError {
|
|
97
|
+
constructor(message, htmlMessage, stack) {
|
|
98
|
+
super(ErrorType.ValidationError, LifiErrorCode.BalanceError, message, htmlMessage, stack);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
95
101
|
export class NotFoundError extends LifiError {
|
|
96
102
|
constructor(message, htmlMessage, stack) {
|
|
97
103
|
super(ErrorType.NotFoundError, LifiErrorCode.NotFound, message, htmlMessage, stack);
|
|
@@ -35,4 +35,3 @@ export declare const getTransactionNotSentMessage: (step?: Step, process?: Proce
|
|
|
35
35
|
export declare const getTransactionFailedMessage: (step: Step, txLink?: string) => string;
|
|
36
36
|
export declare const parseError: (e: any, step?: Step, process?: Process) => Promise<LifiError>;
|
|
37
37
|
export declare const parseBackendError: (e: any) => LifiError;
|
|
38
|
-
export declare const getSlippageNotMetMessage: (step: Step) => string;
|
package/dist/utils/parseError.js
CHANGED
|
@@ -125,8 +125,3 @@ export const parseBackendError = (e) => {
|
|
|
125
125
|
}
|
|
126
126
|
return new ServerError('Something went wrong.', undefined, e.stack);
|
|
127
127
|
};
|
|
128
|
-
export const getSlippageNotMetMessage = (step) => {
|
|
129
|
-
const { slippage } = step.action;
|
|
130
|
-
return `Transaction was not sent, your funds are still in your wallet.
|
|
131
|
-
The updated quote for the current transaction does not meet your set slippage of ${slippage * 100}%.`;
|
|
132
|
-
};
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/sdk";
|
|
2
|
-
export declare const version = "1.
|
|
2
|
+
export declare const version = "1.7.0";
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/sdk';
|
|
2
|
-
export const version = '1.
|
|
2
|
+
export const version = '1.7.0';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
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,36 +76,34 @@
|
|
|
76
76
|
"dependencies": {
|
|
77
77
|
"@ethersproject/abi": "^5.7.0",
|
|
78
78
|
"@ethersproject/contracts": "^5.7.0",
|
|
79
|
-
"@lifi/types": "^1.
|
|
79
|
+
"@lifi/types": "^1.18.0",
|
|
80
80
|
"axios": "^1.1.3",
|
|
81
81
|
"bignumber.js": "^9.1.0",
|
|
82
82
|
"eth-rpc-errors": "^4.0.3",
|
|
83
83
|
"ethers": "^5.7.2"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
|
-
"@commitlint/cli": "^17.
|
|
87
|
-
"@commitlint/config-conventional": "^17.
|
|
88
|
-
"@types/chai": "^4.3.
|
|
86
|
+
"@commitlint/cli": "^17.3.0",
|
|
87
|
+
"@commitlint/config-conventional": "^17.3.0",
|
|
88
|
+
"@types/chai": "^4.3.4",
|
|
89
89
|
"@types/hdkey": "^2.0.0",
|
|
90
|
-
"@types/jest": "^29.2.
|
|
90
|
+
"@types/jest": "^29.2.3",
|
|
91
91
|
"@types/websocket": "^1.0.4",
|
|
92
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
93
|
-
"@typescript-eslint/parser": "^5.
|
|
94
|
-
"eslint": "^8.
|
|
92
|
+
"@typescript-eslint/eslint-plugin": "^5.44.0",
|
|
93
|
+
"@typescript-eslint/parser": "^5.44.0",
|
|
94
|
+
"eslint": "^8.28.0",
|
|
95
95
|
"eslint-config-prettier": "^8.3.0",
|
|
96
96
|
"eslint-plugin-prettier": "^4.2.1",
|
|
97
|
-
"husky": "^8.0.
|
|
98
|
-
"jest": "^29.
|
|
97
|
+
"husky": "^8.0.2",
|
|
98
|
+
"jest": "^29.3.1",
|
|
99
99
|
"lint-staged": "^13.0.3",
|
|
100
100
|
"npm-run-all": "^4.1.5",
|
|
101
101
|
"pinst": "^3.0.0",
|
|
102
|
-
"prettier": "^2.
|
|
102
|
+
"prettier": "^2.8.0",
|
|
103
103
|
"standard-version": "^9.5.0",
|
|
104
104
|
"ts-jest": "^29.0.3",
|
|
105
105
|
"ts-loader": "^9.4.1",
|
|
106
|
-
"typescript": "^4.
|
|
107
|
-
"webpack": "^5.73.0",
|
|
108
|
-
"webpack-cli": "^4.10.0"
|
|
106
|
+
"typescript": "^4.9.3"
|
|
109
107
|
},
|
|
110
108
|
"directories": {
|
|
111
109
|
"test": "test"
|
package/dist/balances/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Token, TokenAmount } from '@lifi/types';
|
|
2
|
-
declare const _default: {
|
|
3
|
-
getTokenBalance: (walletAddress: string, token: Token) => Promise<TokenAmount | null>;
|
|
4
|
-
getTokenBalances: (walletAddress: string, tokens: Token[]) => Promise<TokenAmount[]>;
|
|
5
|
-
getTokenBalancesForChains: (walletAddress: string, tokensByChain: {
|
|
6
|
-
[chainId: number]: Token[];
|
|
7
|
-
}) => Promise<{
|
|
8
|
-
[chainId: number]: TokenAmount[];
|
|
9
|
-
}>;
|
|
10
|
-
};
|
|
11
|
-
export default _default;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Token, TokenAmount } from '@lifi/types';
|
|
2
|
-
declare const _default: {
|
|
3
|
-
getTokenBalance: (walletAddress: string, token: Token) => Promise<TokenAmount | null>;
|
|
4
|
-
getTokenBalances: (walletAddress: string, tokens: Token[]) => Promise<TokenAmount[]>;
|
|
5
|
-
getTokenBalancesForChains: (walletAddress: string, tokensByChain: {
|
|
6
|
-
[chainId: number]: Token[];
|
|
7
|
-
}) => Promise<{
|
|
8
|
-
[chainId: number]: TokenAmount[];
|
|
9
|
-
}>;
|
|
10
|
-
};
|
|
11
|
-
export default _default;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Execution } from '@lifi/types';
|
|
2
|
-
import { ExecuteCrossParams } from '../../types';
|
|
3
|
-
export declare class BridgeExecutionManager {
|
|
4
|
-
allowUserInteraction: boolean;
|
|
5
|
-
allowInteraction: (value: boolean) => void;
|
|
6
|
-
execute: ({ signer, step, statusManager, settings, }: ExecuteCrossParams) => Promise<Execution>;
|
|
7
|
-
}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.SwapExecutionManager = void 0;
|
|
16
|
-
const ApiService_1 = __importDefault(require("../../services/ApiService"));
|
|
17
|
-
const ChainsService_1 = __importDefault(require("../../services/ChainsService"));
|
|
18
|
-
const errors_1 = require("../../utils/errors");
|
|
19
|
-
const getProvider_1 = require("../../utils/getProvider");
|
|
20
|
-
const parseError_1 = require("../../utils/parseError");
|
|
21
|
-
const utils_1 = require("../../utils/utils");
|
|
22
|
-
const allowance_execute_1 = require("../allowance.execute");
|
|
23
|
-
const balanceCheck_execute_1 = require("../balanceCheck.execute");
|
|
24
|
-
const stepComparison_1 = require("../stepComparison");
|
|
25
|
-
const switchChain_1 = require("../switchChain");
|
|
26
|
-
const utils_2 = require("../utils");
|
|
27
|
-
class SwapExecutionManager {
|
|
28
|
-
constructor() {
|
|
29
|
-
this.allowUserInteraction = true;
|
|
30
|
-
this.allowInteraction = (value) => {
|
|
31
|
-
this.allowUserInteraction = value;
|
|
32
|
-
};
|
|
33
|
-
this.execute = ({ signer, step, statusManager, settings, }) => __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
var _a, _b, _c, _d;
|
|
35
|
-
step.execution = statusManager.initExecutionObject(step);
|
|
36
|
-
const chainsService = ChainsService_1.default.getInstance();
|
|
37
|
-
const fromChain = yield chainsService.getChainById(step.action.fromChainId);
|
|
38
|
-
// STEP 1: Check allowance
|
|
39
|
-
if (!(0, utils_1.isZeroAddress)(step.action.fromToken.address)) {
|
|
40
|
-
yield (0, allowance_execute_1.checkAllowance)(signer, step, statusManager, settings, fromChain, this.allowUserInteraction);
|
|
41
|
-
}
|
|
42
|
-
// STEP 2: Get transaction
|
|
43
|
-
let swapProcess = statusManager.findOrCreateProcess(step, 'SWAP');
|
|
44
|
-
let transaction;
|
|
45
|
-
try {
|
|
46
|
-
if (swapProcess.txHash) {
|
|
47
|
-
// Make sure that the chain is still correct
|
|
48
|
-
const updatedSigner = yield (0, switchChain_1.switchChain)(signer, statusManager, step, settings.switchChainHook, this.allowUserInteraction);
|
|
49
|
-
if (!updatedSigner) {
|
|
50
|
-
// Chain switch was not successful, stop execution here
|
|
51
|
-
return step.execution;
|
|
52
|
-
}
|
|
53
|
-
signer = updatedSigner;
|
|
54
|
-
// Load exiting transaction
|
|
55
|
-
transaction = yield (0, getProvider_1.getProvider)(signer).getTransaction(swapProcess.txHash);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
swapProcess = statusManager.updateProcess(step, swapProcess.type, 'STARTED');
|
|
59
|
-
// Check balance
|
|
60
|
-
yield (0, balanceCheck_execute_1.balanceCheck)(signer, step);
|
|
61
|
-
// Create new transaction
|
|
62
|
-
if (!step.transactionRequest) {
|
|
63
|
-
const personalizedStep = yield (0, utils_1.personalizeStep)(signer, step);
|
|
64
|
-
const updatedStep = yield ApiService_1.default.getStepTransaction(personalizedStep);
|
|
65
|
-
step = Object.assign(Object.assign({}, (yield (0, stepComparison_1.stepComparison)(statusManager, personalizedStep, updatedStep, settings.acceptSlippageUpdateHook, this.allowUserInteraction))), { execution: step.execution });
|
|
66
|
-
}
|
|
67
|
-
const { transactionRequest } = step;
|
|
68
|
-
if (!transactionRequest) {
|
|
69
|
-
throw new errors_1.TransactionError(errors_1.LifiErrorCode.TransactionUnprepared, 'Unable to prepare transaction.');
|
|
70
|
-
}
|
|
71
|
-
// STEP 3: Send the transaction
|
|
72
|
-
// Make sure that the chain is still correct
|
|
73
|
-
const updatedSigner = yield (0, switchChain_1.switchChain)(signer, statusManager, step, settings.switchChainHook, this.allowUserInteraction);
|
|
74
|
-
if (!updatedSigner) {
|
|
75
|
-
// Chain switch was not successful, stop execution here
|
|
76
|
-
return step.execution;
|
|
77
|
-
}
|
|
78
|
-
signer = updatedSigner;
|
|
79
|
-
swapProcess = statusManager.updateProcess(step, swapProcess.type, 'ACTION_REQUIRED');
|
|
80
|
-
if (!this.allowUserInteraction) {
|
|
81
|
-
return step.execution;
|
|
82
|
-
}
|
|
83
|
-
// Submit the transaction
|
|
84
|
-
transaction = yield signer.sendTransaction(transactionRequest);
|
|
85
|
-
}
|
|
86
|
-
// STEP 4: Wait for the transaction
|
|
87
|
-
swapProcess = statusManager.updateProcess(step, swapProcess.type, 'PENDING', {
|
|
88
|
-
txLink: fromChain.metamask.blockExplorerUrls[0] + 'tx/' + transaction.hash,
|
|
89
|
-
txHash: transaction.hash,
|
|
90
|
-
});
|
|
91
|
-
yield transaction.wait();
|
|
92
|
-
}
|
|
93
|
-
catch (e) {
|
|
94
|
-
if (e.code === 'TRANSACTION_REPLACED' && e.replacement) {
|
|
95
|
-
swapProcess = statusManager.updateProcess(step, swapProcess.type, 'PENDING', {
|
|
96
|
-
txHash: e.replacement.hash,
|
|
97
|
-
txLink: fromChain.metamask.blockExplorerUrls[0] +
|
|
98
|
-
'tx/' +
|
|
99
|
-
e.replacement.hash,
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
const error = yield (0, parseError_1.parseError)(e);
|
|
104
|
-
swapProcess = statusManager.updateProcess(step, swapProcess.type, 'FAILED', {
|
|
105
|
-
error: {
|
|
106
|
-
message: error.message,
|
|
107
|
-
htmlMessage: error.htmlMessage,
|
|
108
|
-
code: error.code,
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
statusManager.updateExecution(step, 'FAILED');
|
|
112
|
-
throw error;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
// STEP 5: Wait for the receiving chain
|
|
116
|
-
let statusResponse;
|
|
117
|
-
try {
|
|
118
|
-
if (!swapProcess.txHash) {
|
|
119
|
-
throw new Error('Transaction hash is undefined.');
|
|
120
|
-
}
|
|
121
|
-
statusResponse = yield (0, utils_2.waitForReceivingTransaction)(swapProcess.txHash, statusManager, swapProcess.type, step);
|
|
122
|
-
}
|
|
123
|
-
catch (e) {
|
|
124
|
-
swapProcess = statusManager.updateProcess(step, swapProcess.type, 'FAILED', {
|
|
125
|
-
error: {
|
|
126
|
-
code: errors_1.LifiErrorCode.TransactionFailed,
|
|
127
|
-
message: 'Failed while waiting for receiving chain.',
|
|
128
|
-
htmlMessage: (0, parseError_1.getTransactionFailedMessage)(step, swapProcess.txLink),
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
statusManager.updateExecution(step, 'FAILED');
|
|
132
|
-
throw e;
|
|
133
|
-
}
|
|
134
|
-
swapProcess = statusManager.updateProcess(step, swapProcess.type, 'DONE', {
|
|
135
|
-
txHash: (_a = statusResponse.receiving) === null || _a === void 0 ? void 0 : _a.txHash,
|
|
136
|
-
txLink: fromChain.metamask.blockExplorerUrls[0] +
|
|
137
|
-
'tx/' +
|
|
138
|
-
((_b = statusResponse.receiving) === null || _b === void 0 ? void 0 : _b.txHash),
|
|
139
|
-
});
|
|
140
|
-
statusManager.updateExecution(step, 'DONE', {
|
|
141
|
-
fromAmount: statusResponse.sending.amount,
|
|
142
|
-
toAmount: (_c = statusResponse.receiving) === null || _c === void 0 ? void 0 : _c.amount,
|
|
143
|
-
toToken: (_d = statusResponse.receiving) === null || _d === void 0 ? void 0 : _d.token,
|
|
144
|
-
gasUsed: statusResponse.sending.gasUsed,
|
|
145
|
-
gasPrice: statusResponse.sending.gasPrice,
|
|
146
|
-
});
|
|
147
|
-
// DONE
|
|
148
|
-
return step.execution;
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
exports.SwapExecutionManager = SwapExecutionManager;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Execution } from '@lifi/types';
|
|
2
|
-
import { ExecuteCrossParams } from '../../types';
|
|
3
|
-
export declare class BridgeExecutionManager {
|
|
4
|
-
allowUserInteraction: boolean;
|
|
5
|
-
allowInteraction: (value: boolean) => void;
|
|
6
|
-
execute: ({ signer, step, statusManager, settings, }: ExecuteCrossParams) => Promise<Execution>;
|
|
7
|
-
}
|