@lifi/sdk 1.0.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 +354 -0
- package/LICENSE +1 -0
- package/README.md +16 -0
- package/dist/Lifi.d.ts +186 -0
- package/dist/Lifi.js +461 -0
- package/dist/allowance/index.d.ts +22 -0
- package/dist/allowance/index.js +160 -0
- package/dist/allowance/utils.d.ts +14 -0
- package/dist/allowance/utils.js +137 -0
- package/dist/balances/index.d.ts +11 -0
- package/dist/balances/index.js +104 -0
- package/dist/balances/utils.d.ts +5 -0
- package/dist/balances/utils.js +255 -0
- package/dist/connectors.d.ts +6 -0
- package/dist/connectors.js +150 -0
- package/dist/execution/StatusManager.d.ts +63 -0
- package/dist/execution/StatusManager.js +150 -0
- package/dist/execution/StepExecutor.d.ts +15 -0
- package/dist/execution/StepExecutor.js +139 -0
- package/dist/execution/allowance.execute.d.ts +4 -0
- package/dist/execution/allowance.execute.js +156 -0
- package/dist/execution/balanceCheck.execute.d.ts +3 -0
- package/dist/execution/balanceCheck.execute.js +86 -0
- package/dist/execution/bridges/bridge.execute.d.ts +7 -0
- package/dist/execution/bridges/bridge.execute.js +218 -0
- package/dist/execution/exchanges/swap.execute.d.ts +7 -0
- package/dist/execution/exchanges/swap.execute.js +222 -0
- package/dist/execution/index.d.ts +1 -0
- package/dist/execution/index.js +17 -0
- package/dist/execution/switchChain.d.ts +16 -0
- package/dist/execution/switchChain.js +102 -0
- package/dist/execution/utils.d.ts +5 -0
- package/dist/execution/utils.js +175 -0
- package/dist/helpers.d.ts +18 -0
- package/dist/helpers.js +85 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +27 -0
- package/dist/services/ApiService.d.ts +14 -0
- package/dist/services/ApiService.js +350 -0
- package/dist/services/ChainsService.d.ts +11 -0
- package/dist/services/ChainsService.js +108 -0
- package/dist/services/ConfigService.d.ts +23 -0
- package/dist/services/ConfigService.js +133 -0
- package/dist/typeguards.d.ts +4 -0
- package/dist/typeguards.js +55 -0
- package/dist/types/ERC20.d.ts +22 -0
- package/dist/types/ERC20.js +53 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.js +22 -0
- package/dist/types/internal.types.d.ts +75 -0
- package/dist/types/internal.types.js +2 -0
- package/dist/utils/errors.d.ts +73 -0
- package/dist/utils/errors.js +147 -0
- package/dist/utils/getProvider.d.ts +3 -0
- package/dist/utils/getProvider.js +11 -0
- package/dist/utils/multicall.d.ts +10 -0
- package/dist/utils/multicall.js +111 -0
- package/dist/utils/multicallAbi.json +313 -0
- package/dist/utils/parseError.d.ts +37 -0
- package/dist/utils/parseError.js +184 -0
- package/dist/utils/utils.d.ts +26 -0
- package/dist/utils/utils.js +188 -0
- package/package.json +90 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isToken = exports.isStep = exports.isRoutesRequest = void 0;
|
|
4
|
+
var isRoutesRequest = function (routesRequest) {
|
|
5
|
+
var fromChainId = routesRequest.fromChainId, fromAmount = routesRequest.fromAmount, fromTokenAddress = routesRequest.fromTokenAddress, toChainId = routesRequest.toChainId, toTokenAddress = routesRequest.toTokenAddress, options = routesRequest.options;
|
|
6
|
+
return (typeof fromChainId === 'number' &&
|
|
7
|
+
typeof fromAmount === 'string' &&
|
|
8
|
+
fromAmount !== '' &&
|
|
9
|
+
typeof fromTokenAddress === 'string' &&
|
|
10
|
+
fromTokenAddress !== '' &&
|
|
11
|
+
typeof toChainId === 'number' &&
|
|
12
|
+
typeof toTokenAddress === 'string' &&
|
|
13
|
+
toTokenAddress !== '' &&
|
|
14
|
+
(!options || isRoutesOptions(options)));
|
|
15
|
+
};
|
|
16
|
+
exports.isRoutesRequest = isRoutesRequest;
|
|
17
|
+
var isRoutesOptions = function (routeOptions) {
|
|
18
|
+
return !(routeOptions === null || routeOptions === void 0 ? void 0 : routeOptions.slippage) || typeof routeOptions.slippage === 'number';
|
|
19
|
+
};
|
|
20
|
+
var isStep = function (step) {
|
|
21
|
+
var id = step.id, type = step.type, tool = step.tool, action = step.action, estimate = step.estimate;
|
|
22
|
+
return (typeof id === 'string' &&
|
|
23
|
+
['swap', 'cross', 'lifi'].includes(type) &&
|
|
24
|
+
typeof tool === 'string' &&
|
|
25
|
+
isAction(action) &&
|
|
26
|
+
isEstimate(estimate));
|
|
27
|
+
};
|
|
28
|
+
exports.isStep = isStep;
|
|
29
|
+
var isAction = function (action) {
|
|
30
|
+
var fromChainId = action.fromChainId, fromAmount = action.fromAmount, fromToken = action.fromToken, toChainId = action.toChainId, toToken = action.toToken, slippage = action.slippage;
|
|
31
|
+
return (typeof fromChainId === 'number' &&
|
|
32
|
+
typeof fromAmount === 'string' &&
|
|
33
|
+
fromAmount !== '' &&
|
|
34
|
+
(0, exports.isToken)(fromToken) &&
|
|
35
|
+
typeof toChainId === 'number' &&
|
|
36
|
+
(0, exports.isToken)(toToken) &&
|
|
37
|
+
typeof slippage === 'number');
|
|
38
|
+
};
|
|
39
|
+
var isEstimate = function (estimate) {
|
|
40
|
+
var fromAmount = estimate.fromAmount, toAmount = estimate.toAmount, toAmountMin = estimate.toAmountMin, approvalAddress = estimate.approvalAddress;
|
|
41
|
+
return (typeof fromAmount === 'string' &&
|
|
42
|
+
fromAmount !== '' &&
|
|
43
|
+
typeof toAmount === 'string' &&
|
|
44
|
+
toAmount !== '' &&
|
|
45
|
+
typeof toAmountMin === 'string' &&
|
|
46
|
+
toAmountMin !== '' &&
|
|
47
|
+
typeof approvalAddress === 'string');
|
|
48
|
+
};
|
|
49
|
+
var isToken = function (token) {
|
|
50
|
+
var address = token.address, decimals = token.decimals, chainId = token.chainId;
|
|
51
|
+
return (typeof address === 'string' &&
|
|
52
|
+
typeof decimals === 'number' &&
|
|
53
|
+
typeof chainId === 'number');
|
|
54
|
+
};
|
|
55
|
+
exports.isToken = isToken;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BaseContract, BigNumber, BigNumberish, CallOverrides, ContractTransaction, Overrides } from 'ethers';
|
|
2
|
+
export declare const ERC20_ABI: {
|
|
3
|
+
name: string;
|
|
4
|
+
inputs: {
|
|
5
|
+
internalType: string;
|
|
6
|
+
name: string;
|
|
7
|
+
type: string;
|
|
8
|
+
}[];
|
|
9
|
+
outputs: {
|
|
10
|
+
internalType: string;
|
|
11
|
+
name: string;
|
|
12
|
+
type: string;
|
|
13
|
+
}[];
|
|
14
|
+
stateMutability: string;
|
|
15
|
+
type: string;
|
|
16
|
+
}[];
|
|
17
|
+
export interface ERC20Contract extends BaseContract {
|
|
18
|
+
allowance(owner: string, spender: string, overrides?: CallOverrides): Promise<BigNumber>;
|
|
19
|
+
approve(spender: string, amount: BigNumberish, overrides?: Overrides & {
|
|
20
|
+
from?: string | Promise<string>;
|
|
21
|
+
}): Promise<ContractTransaction>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ERC20_ABI = void 0;
|
|
4
|
+
exports.ERC20_ABI = [
|
|
5
|
+
{
|
|
6
|
+
name: 'approve',
|
|
7
|
+
inputs: [
|
|
8
|
+
{
|
|
9
|
+
internalType: 'address',
|
|
10
|
+
name: 'spender',
|
|
11
|
+
type: 'address',
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
internalType: 'uint256',
|
|
15
|
+
name: 'amount',
|
|
16
|
+
type: 'uint256',
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
outputs: [
|
|
20
|
+
{
|
|
21
|
+
internalType: 'bool',
|
|
22
|
+
name: '',
|
|
23
|
+
type: 'bool',
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
stateMutability: 'nonpayable',
|
|
27
|
+
type: 'function',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'allowance',
|
|
31
|
+
inputs: [
|
|
32
|
+
{
|
|
33
|
+
internalType: 'address',
|
|
34
|
+
name: 'owner',
|
|
35
|
+
type: 'address',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
internalType: 'address',
|
|
39
|
+
name: 'spender',
|
|
40
|
+
type: 'address',
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
outputs: [
|
|
44
|
+
{
|
|
45
|
+
internalType: 'uint256',
|
|
46
|
+
name: '',
|
|
47
|
+
type: 'uint256',
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
stateMutability: 'view',
|
|
51
|
+
type: 'function',
|
|
52
|
+
},
|
|
53
|
+
];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.LifiError = void 0;
|
|
18
|
+
__exportStar(require("@lifi/types"), exports);
|
|
19
|
+
var errors_1 = require("../utils/errors");
|
|
20
|
+
Object.defineProperty(exports, "LifiError", { enumerable: true, get: function () { return errors_1.LifiError; } });
|
|
21
|
+
__exportStar(require("./ERC20"), exports);
|
|
22
|
+
__exportStar(require("./internal.types"), exports);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { CrossStep, LifiStep, Route, RouteOptions, Step, SwapStep, Token } from '@lifi/types';
|
|
2
|
+
import BigNumber from 'bignumber.js';
|
|
3
|
+
import { Signer } from 'ethers';
|
|
4
|
+
import { ChainId } from '.';
|
|
5
|
+
import { StatusManager } from '../execution/StatusManager';
|
|
6
|
+
import { StepExecutor } from '../execution/StepExecutor';
|
|
7
|
+
export interface TokenWithAmounts extends Token {
|
|
8
|
+
amount?: BigNumber;
|
|
9
|
+
amountRendered?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare type ParsedReceipt = {
|
|
12
|
+
fromAmount?: string;
|
|
13
|
+
toAmount: string;
|
|
14
|
+
gasUsed: string;
|
|
15
|
+
gasPrice: string;
|
|
16
|
+
gasFee: string;
|
|
17
|
+
toTokenAddress?: string;
|
|
18
|
+
};
|
|
19
|
+
interface ExecutionParams {
|
|
20
|
+
signer: Signer;
|
|
21
|
+
step: Step;
|
|
22
|
+
statusManager: StatusManager;
|
|
23
|
+
settings: InternalExecutionSettings;
|
|
24
|
+
}
|
|
25
|
+
export interface ExecuteSwapParams extends ExecutionParams {
|
|
26
|
+
step: SwapStep;
|
|
27
|
+
}
|
|
28
|
+
export interface ExecuteCrossParams extends ExecutionParams {
|
|
29
|
+
step: CrossStep | LifiStep;
|
|
30
|
+
}
|
|
31
|
+
export declare type CallbackFunction = (updatedRoute: Route) => void;
|
|
32
|
+
export declare type Config = {
|
|
33
|
+
apiUrl: string;
|
|
34
|
+
rpcs: Record<ChainId, string[]>;
|
|
35
|
+
multicallAddresses: Record<ChainId, string | undefined>;
|
|
36
|
+
defaultExecutionSettings: InternalExecutionSettings;
|
|
37
|
+
defaultRouteOptions: RouteOptions;
|
|
38
|
+
};
|
|
39
|
+
export declare type ConfigUpdate = {
|
|
40
|
+
apiUrl?: string;
|
|
41
|
+
rpcs?: Record<number, string[]>;
|
|
42
|
+
multicallAddresses?: Record<number, string | undefined>;
|
|
43
|
+
defaultExecutionSettings?: ExecutionSettings;
|
|
44
|
+
defaultRouteOptions?: RouteOptions;
|
|
45
|
+
};
|
|
46
|
+
export declare type SwitchChainHook = (requiredChainId: number) => Promise<Signer | undefined>;
|
|
47
|
+
export interface ExecutionData {
|
|
48
|
+
route: Route;
|
|
49
|
+
executors: StepExecutor[];
|
|
50
|
+
settings: InternalExecutionSettings;
|
|
51
|
+
}
|
|
52
|
+
export interface ExecutionSettings {
|
|
53
|
+
updateCallback?: CallbackFunction;
|
|
54
|
+
switchChainHook?: SwitchChainHook;
|
|
55
|
+
infiniteApproval?: boolean;
|
|
56
|
+
}
|
|
57
|
+
export interface InternalExecutionSettings extends ExecutionSettings {
|
|
58
|
+
updateCallback: CallbackFunction;
|
|
59
|
+
switchChainHook: SwitchChainHook;
|
|
60
|
+
infiniteApproval: boolean;
|
|
61
|
+
}
|
|
62
|
+
export declare type EnforcedObjectProperties<T> = T & {
|
|
63
|
+
[P in keyof T]-?: T[P];
|
|
64
|
+
};
|
|
65
|
+
export interface ActiveRouteDictionary {
|
|
66
|
+
[k: string]: ExecutionData;
|
|
67
|
+
}
|
|
68
|
+
export declare type RevokeTokenData = {
|
|
69
|
+
token: Token;
|
|
70
|
+
approvalAddress: string;
|
|
71
|
+
};
|
|
72
|
+
export interface HaltingSettings {
|
|
73
|
+
allowUpdates?: boolean;
|
|
74
|
+
}
|
|
75
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
declare enum ErrorType {
|
|
2
|
+
RPCError = "RPCError",
|
|
3
|
+
ProviderError = "ProviderError",
|
|
4
|
+
ServerError = "ServerError",
|
|
5
|
+
TransactionError = "TransactionError",
|
|
6
|
+
ValidationError = "ValidationError",
|
|
7
|
+
NotFoundError = "NotFoundError",
|
|
8
|
+
UnknownError = "UnknownError",
|
|
9
|
+
SlippageError = "SlippageError"
|
|
10
|
+
}
|
|
11
|
+
export declare enum LifiErrorCode {
|
|
12
|
+
InternalError = 1000,
|
|
13
|
+
ValidationError = 1001,
|
|
14
|
+
TransactionUnderpriced = 1002,
|
|
15
|
+
TransactionFailed = 1003,
|
|
16
|
+
TransactionUnprepared = 1008,
|
|
17
|
+
Timeout = 1004,
|
|
18
|
+
ProviderUnavailable = 1005,
|
|
19
|
+
NotFound = 1006,
|
|
20
|
+
ChainSwitchError = 1007,
|
|
21
|
+
SlippageError = 1008
|
|
22
|
+
}
|
|
23
|
+
export declare enum MetaMaskRPCErrorCode {
|
|
24
|
+
invalidInput = -32000,
|
|
25
|
+
resourceNotFound = -32001,
|
|
26
|
+
resourceUnavailable = -32002,
|
|
27
|
+
transactionRejected = -32003,
|
|
28
|
+
methodNotSupported = -32004,
|
|
29
|
+
limitExceeded = -32005,
|
|
30
|
+
parse = -32700,
|
|
31
|
+
invalidRequest = -32600,
|
|
32
|
+
methodNotFound = -32601,
|
|
33
|
+
invalidParams = -32602,
|
|
34
|
+
internal = -32603
|
|
35
|
+
}
|
|
36
|
+
export declare enum MetaMaskProviderErrorCode {
|
|
37
|
+
userRejectedRequest = 4001,
|
|
38
|
+
unauthorized = 4100,
|
|
39
|
+
unsupportedMethod = 4200,
|
|
40
|
+
disconnected = 4900,
|
|
41
|
+
chainDisconnected = 4901
|
|
42
|
+
}
|
|
43
|
+
export declare type ErrorCode = LifiErrorCode | MetaMaskRPCErrorCode | MetaMaskProviderErrorCode;
|
|
44
|
+
export declare class LifiError extends Error {
|
|
45
|
+
code: ErrorCode;
|
|
46
|
+
htmlMessage?: string;
|
|
47
|
+
constructor(type: ErrorType, code: number, message: string, htmlMessage?: string, stack?: string);
|
|
48
|
+
}
|
|
49
|
+
export declare class RPCError extends LifiError {
|
|
50
|
+
constructor(code: ErrorCode, message: string, htmlMessage?: string, stack?: string);
|
|
51
|
+
}
|
|
52
|
+
export declare class ProviderError extends LifiError {
|
|
53
|
+
constructor(code: ErrorCode, message: string, htmlMessage?: string, stack?: string);
|
|
54
|
+
}
|
|
55
|
+
export declare class ServerError extends LifiError {
|
|
56
|
+
constructor(message: string, htmlMessage?: string, stack?: string);
|
|
57
|
+
}
|
|
58
|
+
export declare class ValidationError extends LifiError {
|
|
59
|
+
constructor(message: string, htmlMessage?: string, stack?: string);
|
|
60
|
+
}
|
|
61
|
+
export declare class TransactionError extends LifiError {
|
|
62
|
+
constructor(code: ErrorCode, message: string, htmlMessage?: string, stack?: string);
|
|
63
|
+
}
|
|
64
|
+
export declare class SlippageError extends LifiError {
|
|
65
|
+
constructor(message: string, htmlMessage?: string, stack?: string);
|
|
66
|
+
}
|
|
67
|
+
export declare class NotFoundError extends LifiError {
|
|
68
|
+
constructor(message: string, htmlMessage?: string, stack?: string);
|
|
69
|
+
}
|
|
70
|
+
export declare class UnknownError extends LifiError {
|
|
71
|
+
constructor(code: ErrorCode, message: string, htmlMessage?: string, stack?: string);
|
|
72
|
+
}
|
|
73
|
+
export {};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.UnknownError = exports.NotFoundError = exports.SlippageError = exports.TransactionError = exports.ValidationError = exports.ServerError = exports.ProviderError = exports.RPCError = exports.LifiError = exports.MetaMaskProviderErrorCode = exports.MetaMaskRPCErrorCode = exports.LifiErrorCode = void 0;
|
|
19
|
+
var ErrorType;
|
|
20
|
+
(function (ErrorType) {
|
|
21
|
+
ErrorType["RPCError"] = "RPCError";
|
|
22
|
+
ErrorType["ProviderError"] = "ProviderError";
|
|
23
|
+
ErrorType["ServerError"] = "ServerError";
|
|
24
|
+
ErrorType["TransactionError"] = "TransactionError";
|
|
25
|
+
ErrorType["ValidationError"] = "ValidationError";
|
|
26
|
+
ErrorType["NotFoundError"] = "NotFoundError";
|
|
27
|
+
ErrorType["UnknownError"] = "UnknownError";
|
|
28
|
+
ErrorType["SlippageError"] = "SlippageError";
|
|
29
|
+
})(ErrorType || (ErrorType = {}));
|
|
30
|
+
var LifiErrorCode;
|
|
31
|
+
(function (LifiErrorCode) {
|
|
32
|
+
LifiErrorCode[LifiErrorCode["InternalError"] = 1000] = "InternalError";
|
|
33
|
+
LifiErrorCode[LifiErrorCode["ValidationError"] = 1001] = "ValidationError";
|
|
34
|
+
LifiErrorCode[LifiErrorCode["TransactionUnderpriced"] = 1002] = "TransactionUnderpriced";
|
|
35
|
+
LifiErrorCode[LifiErrorCode["TransactionFailed"] = 1003] = "TransactionFailed";
|
|
36
|
+
LifiErrorCode[LifiErrorCode["TransactionUnprepared"] = 1008] = "TransactionUnprepared";
|
|
37
|
+
LifiErrorCode[LifiErrorCode["Timeout"] = 1004] = "Timeout";
|
|
38
|
+
LifiErrorCode[LifiErrorCode["ProviderUnavailable"] = 1005] = "ProviderUnavailable";
|
|
39
|
+
LifiErrorCode[LifiErrorCode["NotFound"] = 1006] = "NotFound";
|
|
40
|
+
LifiErrorCode[LifiErrorCode["ChainSwitchError"] = 1007] = "ChainSwitchError";
|
|
41
|
+
LifiErrorCode[LifiErrorCode["SlippageError"] = 1008] = "SlippageError";
|
|
42
|
+
})(LifiErrorCode = exports.LifiErrorCode || (exports.LifiErrorCode = {}));
|
|
43
|
+
var MetaMaskRPCErrorCode;
|
|
44
|
+
(function (MetaMaskRPCErrorCode) {
|
|
45
|
+
MetaMaskRPCErrorCode[MetaMaskRPCErrorCode["invalidInput"] = -32000] = "invalidInput";
|
|
46
|
+
MetaMaskRPCErrorCode[MetaMaskRPCErrorCode["resourceNotFound"] = -32001] = "resourceNotFound";
|
|
47
|
+
MetaMaskRPCErrorCode[MetaMaskRPCErrorCode["resourceUnavailable"] = -32002] = "resourceUnavailable";
|
|
48
|
+
MetaMaskRPCErrorCode[MetaMaskRPCErrorCode["transactionRejected"] = -32003] = "transactionRejected";
|
|
49
|
+
MetaMaskRPCErrorCode[MetaMaskRPCErrorCode["methodNotSupported"] = -32004] = "methodNotSupported";
|
|
50
|
+
MetaMaskRPCErrorCode[MetaMaskRPCErrorCode["limitExceeded"] = -32005] = "limitExceeded";
|
|
51
|
+
MetaMaskRPCErrorCode[MetaMaskRPCErrorCode["parse"] = -32700] = "parse";
|
|
52
|
+
MetaMaskRPCErrorCode[MetaMaskRPCErrorCode["invalidRequest"] = -32600] = "invalidRequest";
|
|
53
|
+
MetaMaskRPCErrorCode[MetaMaskRPCErrorCode["methodNotFound"] = -32601] = "methodNotFound";
|
|
54
|
+
MetaMaskRPCErrorCode[MetaMaskRPCErrorCode["invalidParams"] = -32602] = "invalidParams";
|
|
55
|
+
MetaMaskRPCErrorCode[MetaMaskRPCErrorCode["internal"] = -32603] = "internal";
|
|
56
|
+
})(MetaMaskRPCErrorCode = exports.MetaMaskRPCErrorCode || (exports.MetaMaskRPCErrorCode = {}));
|
|
57
|
+
var MetaMaskProviderErrorCode;
|
|
58
|
+
(function (MetaMaskProviderErrorCode) {
|
|
59
|
+
MetaMaskProviderErrorCode[MetaMaskProviderErrorCode["userRejectedRequest"] = 4001] = "userRejectedRequest";
|
|
60
|
+
MetaMaskProviderErrorCode[MetaMaskProviderErrorCode["unauthorized"] = 4100] = "unauthorized";
|
|
61
|
+
MetaMaskProviderErrorCode[MetaMaskProviderErrorCode["unsupportedMethod"] = 4200] = "unsupportedMethod";
|
|
62
|
+
MetaMaskProviderErrorCode[MetaMaskProviderErrorCode["disconnected"] = 4900] = "disconnected";
|
|
63
|
+
MetaMaskProviderErrorCode[MetaMaskProviderErrorCode["chainDisconnected"] = 4901] = "chainDisconnected";
|
|
64
|
+
})(MetaMaskProviderErrorCode = exports.MetaMaskProviderErrorCode || (exports.MetaMaskProviderErrorCode = {}));
|
|
65
|
+
var LifiError = /** @class */ (function (_super) {
|
|
66
|
+
__extends(LifiError, _super);
|
|
67
|
+
function LifiError(type, code, message, htmlMessage, stack) {
|
|
68
|
+
var _this = _super.call(this, message) || this;
|
|
69
|
+
// Set the prototype explicitly: https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
|
|
70
|
+
Object.setPrototypeOf(_this, LifiError.prototype);
|
|
71
|
+
_this.code = code;
|
|
72
|
+
// the name property is used by toString(). It is a string and we can't use our custom ErrorTypes, that's why we have to cast
|
|
73
|
+
_this.name = type.toString();
|
|
74
|
+
_this.htmlMessage = htmlMessage;
|
|
75
|
+
// passing a stack allows us to preserve the stack from errors that we caught and just want to transform in one of our custom errors
|
|
76
|
+
if (stack) {
|
|
77
|
+
_this.stack = stack;
|
|
78
|
+
}
|
|
79
|
+
return _this;
|
|
80
|
+
}
|
|
81
|
+
return LifiError;
|
|
82
|
+
}(Error));
|
|
83
|
+
exports.LifiError = LifiError;
|
|
84
|
+
var RPCError = /** @class */ (function (_super) {
|
|
85
|
+
__extends(RPCError, _super);
|
|
86
|
+
function RPCError(code, message, htmlMessage, stack) {
|
|
87
|
+
return _super.call(this, ErrorType.RPCError, code, message, htmlMessage, stack) || this;
|
|
88
|
+
}
|
|
89
|
+
return RPCError;
|
|
90
|
+
}(LifiError));
|
|
91
|
+
exports.RPCError = RPCError;
|
|
92
|
+
var ProviderError = /** @class */ (function (_super) {
|
|
93
|
+
__extends(ProviderError, _super);
|
|
94
|
+
function ProviderError(code, message, htmlMessage, stack) {
|
|
95
|
+
return _super.call(this, ErrorType.ProviderError, code, message, htmlMessage, stack) || this;
|
|
96
|
+
}
|
|
97
|
+
return ProviderError;
|
|
98
|
+
}(LifiError));
|
|
99
|
+
exports.ProviderError = ProviderError;
|
|
100
|
+
var ServerError = /** @class */ (function (_super) {
|
|
101
|
+
__extends(ServerError, _super);
|
|
102
|
+
function ServerError(message, htmlMessage, stack) {
|
|
103
|
+
return _super.call(this, ErrorType.ServerError, LifiErrorCode.InternalError, message, htmlMessage, stack) || this;
|
|
104
|
+
}
|
|
105
|
+
return ServerError;
|
|
106
|
+
}(LifiError));
|
|
107
|
+
exports.ServerError = ServerError;
|
|
108
|
+
var ValidationError = /** @class */ (function (_super) {
|
|
109
|
+
__extends(ValidationError, _super);
|
|
110
|
+
function ValidationError(message, htmlMessage, stack) {
|
|
111
|
+
return _super.call(this, ErrorType.ValidationError, LifiErrorCode.ValidationError, message, htmlMessage, stack) || this;
|
|
112
|
+
}
|
|
113
|
+
return ValidationError;
|
|
114
|
+
}(LifiError));
|
|
115
|
+
exports.ValidationError = ValidationError;
|
|
116
|
+
var TransactionError = /** @class */ (function (_super) {
|
|
117
|
+
__extends(TransactionError, _super);
|
|
118
|
+
function TransactionError(code, message, htmlMessage, stack) {
|
|
119
|
+
return _super.call(this, ErrorType.TransactionError, code, message, htmlMessage, stack) || this;
|
|
120
|
+
}
|
|
121
|
+
return TransactionError;
|
|
122
|
+
}(LifiError));
|
|
123
|
+
exports.TransactionError = TransactionError;
|
|
124
|
+
var SlippageError = /** @class */ (function (_super) {
|
|
125
|
+
__extends(SlippageError, _super);
|
|
126
|
+
function SlippageError(message, htmlMessage, stack) {
|
|
127
|
+
return _super.call(this, ErrorType.SlippageError, LifiErrorCode.SlippageError, message, htmlMessage, stack) || this;
|
|
128
|
+
}
|
|
129
|
+
return SlippageError;
|
|
130
|
+
}(LifiError));
|
|
131
|
+
exports.SlippageError = SlippageError;
|
|
132
|
+
var NotFoundError = /** @class */ (function (_super) {
|
|
133
|
+
__extends(NotFoundError, _super);
|
|
134
|
+
function NotFoundError(message, htmlMessage, stack) {
|
|
135
|
+
return _super.call(this, ErrorType.NotFoundError, LifiErrorCode.NotFound, message, htmlMessage, stack) || this;
|
|
136
|
+
}
|
|
137
|
+
return NotFoundError;
|
|
138
|
+
}(LifiError));
|
|
139
|
+
exports.NotFoundError = NotFoundError;
|
|
140
|
+
var UnknownError = /** @class */ (function (_super) {
|
|
141
|
+
__extends(UnknownError, _super);
|
|
142
|
+
function UnknownError(code, message, htmlMessage, stack) {
|
|
143
|
+
return _super.call(this, ErrorType.UnknownError, code, message, htmlMessage, stack) || this;
|
|
144
|
+
}
|
|
145
|
+
return UnknownError;
|
|
146
|
+
}(LifiError));
|
|
147
|
+
exports.UnknownError = UnknownError;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getProvider = void 0;
|
|
4
|
+
var errors_1 = require("./errors");
|
|
5
|
+
var getProvider = function (signer) {
|
|
6
|
+
if (!signer.provider) {
|
|
7
|
+
throw new errors_1.ProviderError(errors_1.LifiErrorCode.ProviderUnavailable, 'No provider available in signer.');
|
|
8
|
+
}
|
|
9
|
+
return signer.provider;
|
|
10
|
+
};
|
|
11
|
+
exports.getProvider = getProvider;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Fragment, JsonFragment } from '@ethersproject/abi';
|
|
2
|
+
export declare type MultiCallData = {
|
|
3
|
+
address: string;
|
|
4
|
+
name: string;
|
|
5
|
+
params?: any[];
|
|
6
|
+
};
|
|
7
|
+
export declare const fetchDataUsingMulticall: (calls: Array<MultiCallData>, abi: ReadonlyArray<Fragment | JsonFragment | string>, chainId: number, multicallAddress: string, requireSuccess?: boolean) => Promise<{
|
|
8
|
+
data: unknown;
|
|
9
|
+
blockNumber: number;
|
|
10
|
+
}[]>;
|
|
@@ -0,0 +1,111 @@
|
|
|
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 __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.fetchDataUsingMulticall = void 0;
|
|
43
|
+
var abi_1 = require("@ethersproject/abi");
|
|
44
|
+
var contracts_1 = require("@ethersproject/contracts");
|
|
45
|
+
var connectors_1 = require("../connectors");
|
|
46
|
+
var utils_1 = require("./utils");
|
|
47
|
+
var multicallAbi_json_1 = __importDefault(require("./multicallAbi.json"));
|
|
48
|
+
var MAX_MULTICALL_SIZE = 100;
|
|
49
|
+
var fetchDataUsingMulticall = function (calls, abi, chainId, multicallAddress, requireSuccess) {
|
|
50
|
+
if (requireSuccess === void 0) { requireSuccess = false; }
|
|
51
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
52
|
+
var provider, multicallContract, abiInterface, chunkedList, chunkedResults;
|
|
53
|
+
return __generator(this, function (_a) {
|
|
54
|
+
switch (_a.label) {
|
|
55
|
+
case 0: return [4 /*yield*/, (0, connectors_1.getRpcProvider)(chainId)];
|
|
56
|
+
case 1:
|
|
57
|
+
provider = _a.sent();
|
|
58
|
+
multicallContract = new contracts_1.Contract(multicallAddress, multicallAbi_json_1.default, provider);
|
|
59
|
+
abiInterface = new abi_1.Interface(abi);
|
|
60
|
+
chunkedList = (0, utils_1.splitListIntoChunks)(calls, MAX_MULTICALL_SIZE);
|
|
61
|
+
return [4 /*yield*/, Promise.all(chunkedList.map(function (chunkedCalls) { return __awaiter(void 0, void 0, void 0, function () {
|
|
62
|
+
var callData, _a, blockNumber_1, returnData, e_1;
|
|
63
|
+
return __generator(this, function (_b) {
|
|
64
|
+
switch (_b.label) {
|
|
65
|
+
case 0:
|
|
66
|
+
callData = chunkedCalls.map(function (call) { return [
|
|
67
|
+
call.address.toLowerCase(),
|
|
68
|
+
abiInterface.encodeFunctionData(call.name, call.params),
|
|
69
|
+
]; });
|
|
70
|
+
_b.label = 1;
|
|
71
|
+
case 1:
|
|
72
|
+
_b.trys.push([1, 3, , 4]);
|
|
73
|
+
return [4 /*yield*/, multicallContract.tryBlockAndAggregate(requireSuccess, callData)
|
|
74
|
+
// 4. decode bytes array to useful data array...
|
|
75
|
+
];
|
|
76
|
+
case 2:
|
|
77
|
+
_a = _b.sent(), blockNumber_1 = _a.blockNumber, returnData = _a.returnData;
|
|
78
|
+
// 4. decode bytes array to useful data array...
|
|
79
|
+
return [2 /*return*/, returnData
|
|
80
|
+
.map(function (_a, i) {
|
|
81
|
+
var success = _a.success, returnData = _a.returnData;
|
|
82
|
+
if (success) {
|
|
83
|
+
return abiInterface.decodeFunctionResult(chunkedCalls[i].name, returnData);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
console.error("Multicall unsuccessful for address \"".concat(chunkedCalls[i].address, "\", function \"").concat(chunkedCalls[i].name, "\", chainId \"").concat(chainId, "\""));
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
.map(function (data) {
|
|
91
|
+
return {
|
|
92
|
+
data: data[0],
|
|
93
|
+
blockNumber: blockNumber_1.toNumber(),
|
|
94
|
+
};
|
|
95
|
+
})];
|
|
96
|
+
case 3:
|
|
97
|
+
e_1 = _b.sent();
|
|
98
|
+
console.error("Multicall failed on chainId \"".concat(chainId, "\""), chunkedList, e_1);
|
|
99
|
+
return [2 /*return*/, []];
|
|
100
|
+
case 4: return [2 /*return*/];
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}); }))];
|
|
104
|
+
case 2:
|
|
105
|
+
chunkedResults = _a.sent();
|
|
106
|
+
return [2 /*return*/, chunkedResults.flat()];
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
exports.fetchDataUsingMulticall = fetchDataUsingMulticall;
|