@lifi/sdk 2.2.3 → 3.0.0-alpha.2
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 +69 -62
- package/dist/LiFi.js +71 -60
- package/dist/allowance/getAllowance.d.ts +6 -0
- package/dist/allowance/getAllowance.js +78 -0
- package/dist/allowance/index.d.ts +3 -2
- package/dist/allowance/index.js +3 -2
- package/dist/allowance/setAllowance.d.ts +5 -0
- package/dist/allowance/setAllowance.js +50 -0
- package/dist/allowance/types.d.ts +27 -0
- package/dist/allowance/types.js +1 -0
- package/dist/balance/getBalance.d.ts +2 -0
- package/dist/balance/getBalance.js +93 -0
- package/dist/balance/getTokenBalance.d.ts +2 -2
- package/dist/balance/getTokenBalance.js +4 -4
- package/dist/balance/index.d.ts +1 -12
- package/dist/balance/index.js +1 -9
- package/dist/cjs/LiFi.d.ts +69 -62
- package/dist/cjs/LiFi.js +69 -58
- package/dist/cjs/allowance/getAllowance.d.ts +6 -0
- package/dist/cjs/allowance/getAllowance.js +85 -0
- package/dist/cjs/allowance/index.d.ts +3 -2
- package/dist/cjs/allowance/index.js +3 -2
- package/dist/cjs/allowance/setAllowance.d.ts +5 -0
- package/dist/cjs/allowance/setAllowance.js +56 -0
- package/dist/cjs/allowance/types.d.ts +27 -0
- package/dist/cjs/allowance/types.js +2 -0
- package/dist/cjs/balance/getBalance.d.ts +2 -0
- package/dist/cjs/balance/getBalance.js +97 -0
- package/dist/cjs/balance/getTokenBalance.d.ts +2 -2
- package/dist/cjs/balance/getTokenBalance.js +6 -9
- package/dist/cjs/balance/index.d.ts +1 -12
- package/dist/cjs/balance/index.js +1 -9
- package/dist/cjs/connectors.d.ts +7 -5
- package/dist/cjs/connectors.js +45 -37
- package/dist/cjs/constants.d.ts +6 -0
- package/dist/cjs/constants.js +9 -0
- package/dist/cjs/execution/RouteExecutionManager.d.ts +24 -30
- package/dist/cjs/execution/RouteExecutionManager.js +27 -45
- package/dist/cjs/execution/StatusManager.d.ts +22 -23
- package/dist/cjs/execution/StatusManager.js +21 -22
- package/dist/cjs/execution/StepExecutionManager.d.ts +3 -3
- package/dist/cjs/execution/StepExecutionManager.js +118 -125
- package/dist/cjs/execution/StepExecutor.d.ts +4 -4
- package/dist/cjs/execution/StepExecutor.js +6 -6
- package/dist/cjs/execution/checkAllowance.d.ts +4 -0
- package/dist/cjs/execution/checkAllowance.js +77 -0
- package/dist/cjs/execution/checkBalance.d.ts +2 -0
- package/dist/cjs/execution/checkBalance.js +42 -0
- package/dist/cjs/execution/multisig.d.ts +4 -3
- package/dist/cjs/execution/multisig.js +9 -11
- package/dist/cjs/execution/prepareRestart.d.ts +3 -0
- package/dist/cjs/execution/prepareRestart.js +65 -0
- package/dist/cjs/execution/stepComparison.d.ts +3 -3
- package/dist/cjs/execution/stepComparison.js +2 -2
- package/dist/cjs/execution/switchChain.d.ts +13 -8
- package/dist/cjs/execution/switchChain.js +16 -11
- package/dist/cjs/execution/utils.d.ts +9 -3
- package/dist/cjs/execution/utils.js +19 -66
- package/dist/cjs/execution/waitForReceivingTransaction.d.ts +3 -0
- package/dist/cjs/execution/waitForReceivingTransaction.js +58 -0
- package/dist/cjs/helpers.d.ts +7 -17
- package/dist/cjs/helpers.js +6 -38
- package/dist/cjs/request.js +1 -1
- package/dist/cjs/services/ApiService.d.ts +2 -2
- package/dist/cjs/services/ApiService.js +4 -2
- package/dist/cjs/services/ChainsService.d.ts +1 -1
- package/dist/cjs/services/ConfigService.d.ts +1 -1
- package/dist/cjs/services/ConfigService.js +1 -2
- package/dist/cjs/typeguards.d.ts +1 -1
- package/dist/cjs/types/abi.d.ts +5 -0
- package/dist/cjs/types/abi.js +45 -0
- package/dist/cjs/types/index.d.ts +2 -2
- package/dist/cjs/types/index.js +3 -3
- package/dist/cjs/types/internal.types.d.ts +24 -31
- package/dist/cjs/utils/errors.d.ts +15 -14
- package/dist/cjs/utils/errors.js +38 -37
- package/dist/cjs/utils/getMaxPriorityFeePerGas.d.ts +2 -0
- package/dist/cjs/utils/getMaxPriorityFeePerGas.js +22 -0
- package/dist/cjs/utils/index.d.ts +5 -0
- package/dist/cjs/utils/index.js +21 -0
- package/dist/cjs/utils/median.d.ts +1 -0
- package/dist/cjs/utils/median.js +15 -0
- package/dist/cjs/utils/parseError.d.ts +4 -4
- package/dist/cjs/utils/parseError.js +41 -38
- package/dist/cjs/utils/utils.d.ts +1 -16
- package/dist/cjs/utils/utils.js +9 -78
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/connectors.d.ts +7 -5
- package/dist/connectors.js +19 -35
- package/dist/constants.d.ts +6 -0
- package/dist/constants.js +6 -0
- package/dist/execution/RouteExecutionManager.d.ts +24 -30
- package/dist/execution/RouteExecutionManager.js +27 -45
- package/dist/execution/StatusManager.d.ts +22 -23
- package/dist/execution/StatusManager.js +22 -23
- package/dist/execution/StepExecutionManager.d.ts +3 -3
- package/dist/execution/StepExecutionManager.js +116 -123
- package/dist/execution/StepExecutor.d.ts +4 -4
- package/dist/execution/StepExecutor.js +6 -6
- package/dist/execution/checkAllowance.d.ts +4 -0
- package/dist/execution/checkAllowance.js +73 -0
- package/dist/execution/checkBalance.d.ts +2 -0
- package/dist/execution/checkBalance.js +38 -0
- package/dist/execution/multisig.d.ts +4 -3
- package/dist/execution/multisig.js +10 -12
- package/dist/execution/prepareRestart.d.ts +3 -0
- package/dist/execution/prepareRestart.js +61 -0
- package/dist/execution/stepComparison.d.ts +3 -3
- package/dist/execution/stepComparison.js +3 -3
- package/dist/execution/switchChain.d.ts +13 -8
- package/dist/execution/switchChain.js +17 -12
- package/dist/execution/utils.d.ts +9 -3
- package/dist/execution/utils.js +18 -61
- package/dist/execution/waitForReceivingTransaction.d.ts +3 -0
- package/dist/execution/waitForReceivingTransaction.js +51 -0
- package/dist/helpers.d.ts +7 -17
- package/dist/helpers.js +5 -34
- package/dist/request.js +2 -2
- package/dist/services/ApiService.d.ts +2 -2
- package/dist/services/ApiService.js +4 -2
- package/dist/services/ChainsService.d.ts +1 -1
- package/dist/services/ConfigService.d.ts +1 -1
- package/dist/services/ConfigService.js +2 -3
- package/dist/typeguards.d.ts +1 -1
- package/dist/types/abi.d.ts +5 -0
- package/dist/types/abi.js +42 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.js +2 -2
- package/dist/types/internal.types.d.ts +24 -31
- package/dist/utils/errors.d.ts +15 -14
- package/dist/utils/errors.js +36 -35
- package/dist/utils/getMaxPriorityFeePerGas.d.ts +2 -0
- package/dist/utils/getMaxPriorityFeePerGas.js +18 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/median.d.ts +1 -0
- package/dist/utils/median.js +11 -0
- package/dist/utils/parseError.d.ts +4 -4
- package/dist/utils/parseError.js +42 -39
- package/dist/utils/utils.d.ts +1 -16
- package/dist/utils/utils.js +7 -69
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +43 -40
- package/dist/allowance/checkAllowance.d.ts +0 -4
- package/dist/allowance/checkAllowance.js +0 -96
- package/dist/allowance/tokenApproval.d.ts +0 -22
- package/dist/allowance/tokenApproval.js +0 -59
- package/dist/allowance/utils.d.ts +0 -15
- package/dist/allowance/utils.js +0 -77
- package/dist/balance/checkBalance.d.ts +0 -3
- package/dist/balance/checkBalance.js +0 -38
- package/dist/balance/utils.d.ts +0 -6
- package/dist/balance/utils.js +0 -143
- package/dist/cjs/allowance/checkAllowance.d.ts +0 -4
- package/dist/cjs/allowance/checkAllowance.js +0 -103
- package/dist/cjs/allowance/tokenApproval.d.ts +0 -22
- package/dist/cjs/allowance/tokenApproval.js +0 -69
- package/dist/cjs/allowance/utils.d.ts +0 -15
- package/dist/cjs/allowance/utils.js +0 -87
- package/dist/cjs/balance/checkBalance.d.ts +0 -3
- package/dist/cjs/balance/checkBalance.js +0 -45
- package/dist/cjs/balance/utils.d.ts +0 -6
- package/dist/cjs/balance/utils.js +0 -150
- package/dist/cjs/types/ERC20.d.ts +0 -22
- package/dist/cjs/types/ERC20.js +0 -53
- package/dist/cjs/utils/getProvider.d.ts +0 -3
- package/dist/cjs/utils/getProvider.js +0 -11
- package/dist/cjs/utils/multicall.d.ts +0 -10
- package/dist/cjs/utils/multicall.js +0 -68
- package/dist/cjs/utils/multicallAbi.json +0 -313
- package/dist/cjs/utils/preRestart.d.ts +0 -3
- package/dist/cjs/utils/preRestart.js +0 -56
- package/dist/types/ERC20.d.ts +0 -22
- package/dist/types/ERC20.js +0 -50
- package/dist/utils/getProvider.d.ts +0 -3
- package/dist/utils/getProvider.js +0 -7
- package/dist/utils/multicall.d.ts +0 -10
- package/dist/utils/multicall.js +0 -61
- package/dist/utils/multicallAbi.json +0 -313
- package/dist/utils/preRestart.d.ts +0 -3
- package/dist/utils/preRestart.js +0 -52
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { encodeFunctionData, maxUint256, publicActions } from 'viem';
|
|
2
|
+
import { approveAbi } from '../types';
|
|
3
|
+
import { getMaxPriorityFeePerGas } from '../utils';
|
|
4
|
+
import { isNativeTokenAddress } from '../utils/utils';
|
|
5
|
+
import { getAllowance } from './getAllowance';
|
|
6
|
+
export const setAllowance = async (walletClient, tokenAddress, contractAddress, amount, returnPopulatedTransaction) => {
|
|
7
|
+
const data = encodeFunctionData({
|
|
8
|
+
abi: approveAbi,
|
|
9
|
+
functionName: 'approve',
|
|
10
|
+
args: [contractAddress, amount],
|
|
11
|
+
});
|
|
12
|
+
if (returnPopulatedTransaction) {
|
|
13
|
+
return data;
|
|
14
|
+
}
|
|
15
|
+
const client = walletClient.extend(publicActions);
|
|
16
|
+
let maxPriorityFeePerGas;
|
|
17
|
+
if (walletClient.account?.type === 'local') {
|
|
18
|
+
maxPriorityFeePerGas = await getMaxPriorityFeePerGas(client);
|
|
19
|
+
}
|
|
20
|
+
return client.sendTransaction({
|
|
21
|
+
to: tokenAddress,
|
|
22
|
+
account: walletClient.account,
|
|
23
|
+
data,
|
|
24
|
+
maxPriorityFeePerGas,
|
|
25
|
+
chain: null,
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
export const setTokenAllowance = async ({ walletClient, token, spenderAddress, amount, infiniteApproval = false, }) => {
|
|
29
|
+
// native token don't need approval
|
|
30
|
+
if (isNativeTokenAddress(token.address)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const approvedAmount = await getAllowance(token.chainId, token.address, walletClient.account.address, spenderAddress);
|
|
34
|
+
if (amount > approvedAmount) {
|
|
35
|
+
const approvalAmount = infiniteApproval ? maxUint256 : amount;
|
|
36
|
+
const approveTx = await setAllowance(walletClient, token.address, spenderAddress, approvalAmount);
|
|
37
|
+
return approveTx;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
export const revokeTokenApproval = async ({ walletClient, token, spenderAddress, }) => {
|
|
41
|
+
// native token don't need approval
|
|
42
|
+
if (isNativeTokenAddress(token.address)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const approvedAmount = await getAllowance(token.chainId, token.address, walletClient.account.address, spenderAddress);
|
|
46
|
+
if (approvedAmount > 0) {
|
|
47
|
+
const approveTx = await setAllowance(walletClient, token.address, spenderAddress, 0n);
|
|
48
|
+
return approveTx;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Token } from '@lifi/types';
|
|
2
|
+
import type { WalletClient } from 'viem';
|
|
3
|
+
export type TokenSpender = {
|
|
4
|
+
token: Token;
|
|
5
|
+
spenderAddress: string;
|
|
6
|
+
};
|
|
7
|
+
export type TokenAllowance = {
|
|
8
|
+
token: Token;
|
|
9
|
+
allowance?: bigint;
|
|
10
|
+
};
|
|
11
|
+
export type TokenSpenderAllowance = {
|
|
12
|
+
token: Token;
|
|
13
|
+
spenderAddress: string;
|
|
14
|
+
allowance?: bigint;
|
|
15
|
+
};
|
|
16
|
+
export interface ApproveTokenRequest {
|
|
17
|
+
walletClient: WalletClient;
|
|
18
|
+
token: Token;
|
|
19
|
+
spenderAddress: string;
|
|
20
|
+
amount: bigint;
|
|
21
|
+
infiniteApproval?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface RevokeApprovalRequest {
|
|
24
|
+
walletClient: WalletClient;
|
|
25
|
+
token: Token;
|
|
26
|
+
spenderAddress: string;
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { getMulticallAddress, getPublicClient } from '../connectors';
|
|
2
|
+
import { MulticallBatchSize } from '../constants';
|
|
3
|
+
import { balanceOfAbi, getEthBalanceAbi } from '../types';
|
|
4
|
+
import { isZeroAddress } from '../utils/utils';
|
|
5
|
+
export const getBalance = async (walletAddress, tokens) => {
|
|
6
|
+
if (tokens.length === 0) {
|
|
7
|
+
return [];
|
|
8
|
+
}
|
|
9
|
+
const { chainId } = tokens[0];
|
|
10
|
+
tokens.forEach((token) => {
|
|
11
|
+
if (token.chainId !== chainId) {
|
|
12
|
+
console.warn(`Requested tokens have to be on the same chain.`);
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
const multicallAddress = await getMulticallAddress(chainId);
|
|
17
|
+
if (multicallAddress && tokens.length > 1) {
|
|
18
|
+
return getBalanceMulticall(chainId, tokens, walletAddress, multicallAddress);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
return getBalanceDefault(chainId, tokens, walletAddress);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const getBalanceMulticall = async (chainId, tokens, walletAddress, multicallAddress) => {
|
|
25
|
+
const client = await getPublicClient(chainId);
|
|
26
|
+
const contracts = tokens.map((token) => {
|
|
27
|
+
if (isZeroAddress(token.address)) {
|
|
28
|
+
return {
|
|
29
|
+
address: multicallAddress,
|
|
30
|
+
abi: getEthBalanceAbi,
|
|
31
|
+
functionName: 'getEthBalance',
|
|
32
|
+
args: [walletAddress],
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
address: token.address,
|
|
37
|
+
abi: balanceOfAbi,
|
|
38
|
+
functionName: 'balanceOf',
|
|
39
|
+
args: [walletAddress],
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
const blockNumber = await client.getBlockNumber();
|
|
43
|
+
const results = await client.multicall({
|
|
44
|
+
contracts,
|
|
45
|
+
multicallAddress: multicallAddress,
|
|
46
|
+
blockNumber,
|
|
47
|
+
batchSize: MulticallBatchSize,
|
|
48
|
+
});
|
|
49
|
+
if (!results.length) {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
return tokens.map((token, i) => {
|
|
53
|
+
return {
|
|
54
|
+
...token,
|
|
55
|
+
amount: results[i].result,
|
|
56
|
+
blockNumber,
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
const getBalanceDefault = async (chainId, tokens, walletAddress) => {
|
|
61
|
+
const client = await getPublicClient(chainId);
|
|
62
|
+
const blockNumber = await client.getBlockNumber();
|
|
63
|
+
const queue = tokens.map((token) => {
|
|
64
|
+
if (isZeroAddress(token.address)) {
|
|
65
|
+
return client.getBalance({
|
|
66
|
+
address: walletAddress,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return client.readContract({
|
|
70
|
+
address: token.address,
|
|
71
|
+
abi: balanceOfAbi,
|
|
72
|
+
functionName: 'balanceOf',
|
|
73
|
+
args: [walletAddress],
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
const results = await Promise.allSettled(queue);
|
|
77
|
+
const tokenAmounts = tokens.map((token, index) => {
|
|
78
|
+
const result = results[index];
|
|
79
|
+
if (result.status === 'rejected') {
|
|
80
|
+
console.warn(result.reason);
|
|
81
|
+
return {
|
|
82
|
+
...token,
|
|
83
|
+
blockNumber,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
...token,
|
|
88
|
+
amount: result.value,
|
|
89
|
+
blockNumber,
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
return tokenAmounts;
|
|
93
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Token, TokenAmount } from '@lifi/types';
|
|
1
|
+
import type { Token, TokenAmount } from '@lifi/types';
|
|
2
2
|
export declare const getTokenBalance: (walletAddress: string, token: Token) => Promise<TokenAmount | null>;
|
|
3
3
|
export declare const getTokenBalances: (walletAddress: string, tokens: Token[]) => Promise<TokenAmount[]>;
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const getTokenBalancesByChain: (walletAddress: string, tokensByChain: {
|
|
5
5
|
[chainId: number]: Token[];
|
|
6
6
|
}) => Promise<{
|
|
7
7
|
[chainId: number]: TokenAmount[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { getBalance } from './getBalance';
|
|
2
2
|
export const getTokenBalance = async (walletAddress, token) => {
|
|
3
3
|
const tokenAmounts = await getTokenBalances(walletAddress, [token]);
|
|
4
4
|
return tokenAmounts.length ? tokenAmounts[0] : null;
|
|
@@ -12,14 +12,14 @@ export const getTokenBalances = async (walletAddress, tokens) => {
|
|
|
12
12
|
}
|
|
13
13
|
tokensByChain[token.chainId].push(token);
|
|
14
14
|
});
|
|
15
|
-
const tokenAmountsByChain = await
|
|
15
|
+
const tokenAmountsByChain = await getTokenBalancesByChain(walletAddress, tokensByChain);
|
|
16
16
|
return Object.values(tokenAmountsByChain).flat();
|
|
17
17
|
};
|
|
18
|
-
export const
|
|
18
|
+
export const getTokenBalancesByChain = async (walletAddress, tokensByChain) => {
|
|
19
19
|
const tokenAmountsByChain = {};
|
|
20
20
|
const promises = Object.keys(tokensByChain).map(async (chainIdStr) => {
|
|
21
21
|
const chainId = parseInt(chainIdStr);
|
|
22
|
-
const tokenAmounts = await
|
|
22
|
+
const tokenAmounts = await getBalance(walletAddress, tokensByChain[chainId]);
|
|
23
23
|
tokenAmountsByChain[chainId] = tokenAmounts;
|
|
24
24
|
});
|
|
25
25
|
await Promise.allSettled(promises);
|
package/dist/balance/index.d.ts
CHANGED
|
@@ -1,13 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './getBalance';
|
|
2
2
|
export * from './getTokenBalance';
|
|
3
|
-
declare const _default: {
|
|
4
|
-
checkBalance: (signer: import("ethers").Signer, step: import("@lifi/types").LifiStep, depth?: number) => Promise<void>;
|
|
5
|
-
getTokenBalance: (walletAddress: string, token: import("@lifi/types").Token) => Promise<import("@lifi/types").TokenAmount | null>;
|
|
6
|
-
getTokenBalances: (walletAddress: string, tokens: import("@lifi/types").Token[]) => Promise<import("@lifi/types").TokenAmount[]>;
|
|
7
|
-
getTokenBalancesForChains: (walletAddress: string, tokensByChain: {
|
|
8
|
-
[chainId: number]: import("@lifi/types").Token[];
|
|
9
|
-
}) => Promise<{
|
|
10
|
-
[chainId: number]: import("@lifi/types").TokenAmount[];
|
|
11
|
-
}>;
|
|
12
|
-
};
|
|
13
|
-
export default _default;
|
package/dist/balance/index.js
CHANGED
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './getBalance';
|
|
2
2
|
export * from './getTokenBalance';
|
|
3
|
-
import { checkBalance } from './checkBalance';
|
|
4
|
-
import { getTokenBalance, getTokenBalances, getTokenBalancesForChains, } from './getTokenBalance';
|
|
5
|
-
export default {
|
|
6
|
-
checkBalance,
|
|
7
|
-
getTokenBalance,
|
|
8
|
-
getTokenBalances,
|
|
9
|
-
getTokenBalancesForChains,
|
|
10
|
-
};
|
package/dist/cjs/LiFi.d.ts
CHANGED
|
@@ -1,160 +1,167 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { ApproveTokenRequest, RevokeApprovalRequest } from './allowance';
|
|
1
|
+
import type { 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';
|
|
2
|
+
import type { Hash, PublicClient } from 'viem';
|
|
3
|
+
import type { ApproveTokenRequest, RevokeApprovalRequest, TokenAllowance, TokenSpender } from './allowance';
|
|
5
4
|
import { RouteExecutionManager } from './execution/RouteExecutionManager';
|
|
6
|
-
import { Config, ConfigUpdate
|
|
5
|
+
import type { Config, ConfigUpdate } from './types';
|
|
7
6
|
export declare class LiFi extends RouteExecutionManager {
|
|
8
7
|
private chainsService;
|
|
9
8
|
constructor(configUpdate: ConfigUpdate);
|
|
10
9
|
/**
|
|
11
10
|
* Get the current configuration of the SDK
|
|
12
|
-
* @
|
|
11
|
+
* @returns - The config object
|
|
13
12
|
*/
|
|
14
13
|
getConfig: () => Config;
|
|
15
14
|
/**
|
|
16
15
|
* Get the SDK configuration after all setup calls are finished
|
|
17
|
-
* @
|
|
16
|
+
* @returns - The config object
|
|
18
17
|
*/
|
|
19
18
|
getConfigAsync: () => Promise<Config>;
|
|
20
19
|
/**
|
|
21
20
|
* Get an instance of a provider for a specific chain
|
|
22
|
-
* @param
|
|
23
|
-
* @
|
|
24
|
-
* @return {FallbackProvider} The provider for the given chain
|
|
21
|
+
* @param chainId - Id of the chain the provider is for
|
|
22
|
+
* @returns The public client for the given chain
|
|
25
23
|
*/
|
|
26
|
-
|
|
24
|
+
getPublicClient: (chainId: number) => Promise<PublicClient>;
|
|
27
25
|
/**
|
|
28
26
|
* Set a new confuration for the SDK
|
|
29
|
-
* @param
|
|
30
|
-
* @
|
|
27
|
+
* @param configUpdate - An object containing the configuration fields that should be updated.
|
|
28
|
+
* @returns The renewed config object
|
|
31
29
|
*/
|
|
32
30
|
setConfig: (configUpdate: Partial<ConfigUpdate>) => Config;
|
|
33
31
|
/**
|
|
34
32
|
* Get a set of current possibilities based on a request that specifies which chains, exchanges and bridges are preferred or unwanted.
|
|
35
|
-
* @param
|
|
36
|
-
* @
|
|
37
|
-
* @
|
|
33
|
+
* @param request - Object defining preferences regarding chain, exchanges and bridges
|
|
34
|
+
* @param options
|
|
35
|
+
* @returns Object listing current possibilities for any-to-any cross-chain-swaps based on the provided preferences.
|
|
36
|
+
* @throws {LiFiError} Throws a LiFiError if request fails.
|
|
38
37
|
* @deprecated We don't want to support this endpoint anymore in the future. /chains, /tools, /connections, and /tokens should be used instead
|
|
39
38
|
*/
|
|
40
39
|
getPossibilities: (request?: PossibilitiesRequest, options?: RequestOptions) => Promise<PossibilitiesResponse>;
|
|
41
40
|
/**
|
|
42
41
|
* Fetch information about a Token
|
|
43
|
-
* @param
|
|
44
|
-
* @param
|
|
45
|
-
* @
|
|
42
|
+
* @param chain - Id or key of the chain that contains the token
|
|
43
|
+
* @param token - Address or symbol of the token on the requested chain
|
|
44
|
+
* @param options
|
|
45
|
+
* @throws {LiFiError} - Throws a LiFiError if request fails
|
|
46
46
|
*/
|
|
47
47
|
getToken: (chain: ChainKey | ChainId, token: string, options?: RequestOptions) => Promise<Token>;
|
|
48
48
|
/**
|
|
49
49
|
* Get a quote for a token transfer
|
|
50
|
-
* @param
|
|
51
|
-
* @
|
|
50
|
+
* @param request - The configuration of the requested quote
|
|
51
|
+
* @param options
|
|
52
|
+
* @throws {LiFiError} - Throws a LiFiError if request fails
|
|
52
53
|
*/
|
|
53
54
|
getQuote: (request: QuoteRequest, options?: RequestOptions) => Promise<LifiStep>;
|
|
54
55
|
/**
|
|
55
56
|
* Get a quote for a destination contract call
|
|
56
|
-
* @param
|
|
57
|
-
* @
|
|
57
|
+
* @param request - The configuration of the requested destination call
|
|
58
|
+
* @param options
|
|
59
|
+
* @throws {LiFiError} - Throws a LiFiError if request fails
|
|
60
|
+
* @returns - Returns step.
|
|
58
61
|
*/
|
|
59
62
|
getContractCallQuote: (request: ContractCallQuoteRequest, options?: RequestOptions) => Promise<LifiStep>;
|
|
60
63
|
/**
|
|
61
64
|
* Check the status of a transfer. For cross chain transfers, the "bridge" parameter is required.
|
|
62
|
-
* @param
|
|
63
|
-
* @
|
|
65
|
+
* @param request - Configuration of the requested status
|
|
66
|
+
* @param options - Rrquest options.
|
|
67
|
+
* @throws {LiFiError} - Throws a LiFiError if request fails
|
|
68
|
+
* @returns Returns status response.
|
|
64
69
|
*/
|
|
65
70
|
getStatus: (request: GetStatusRequest, options?: RequestOptions) => Promise<StatusResponse>;
|
|
66
71
|
/**
|
|
67
72
|
* Get the available tools to bridge and swap tokens.
|
|
68
|
-
* @param
|
|
73
|
+
* @param request - The configuration of the requested tools
|
|
74
|
+
* @param options
|
|
69
75
|
* @returns The tools that are available on the requested chains
|
|
70
76
|
*/
|
|
71
77
|
getTools: (request?: ToolsRequest, options?: RequestOptions) => Promise<ToolsResponse>;
|
|
72
78
|
/**
|
|
73
79
|
* Get all known tokens.
|
|
74
|
-
* @param
|
|
80
|
+
* @param request - The configuration of the requested tokens
|
|
81
|
+
* @param options
|
|
75
82
|
* @returns The tokens that are available on the requested chains
|
|
76
83
|
*/
|
|
77
84
|
getTokens: (request?: TokensRequest, options?: RequestOptions) => Promise<TokensResponse>;
|
|
78
85
|
/**
|
|
79
86
|
* Get all available chains
|
|
80
|
-
* @
|
|
81
|
-
* @throws {
|
|
87
|
+
* @returns A list of all available chains
|
|
88
|
+
* @throws {LiFiError} Throws a LiFiError if request fails.
|
|
82
89
|
*/
|
|
83
90
|
getChains: () => Promise<ExtendedChain[]>;
|
|
84
91
|
/**
|
|
85
92
|
* Get a set of routes for a request that describes a transfer of tokens.
|
|
86
|
-
* @param
|
|
87
|
-
* @
|
|
88
|
-
* @
|
|
93
|
+
* @param request - A description of the transfer.
|
|
94
|
+
* @param options
|
|
95
|
+
* @returns The resulting routes that can be used to realize the described transfer of tokens.
|
|
96
|
+
* @throws {LiFiError} Throws a LiFiError if request fails.
|
|
89
97
|
*/
|
|
90
98
|
getRoutes: (request: RoutesRequest, options?: RequestOptions) => Promise<RoutesResponse>;
|
|
91
99
|
/**
|
|
92
100
|
* Get the transaction data for a single step of a route
|
|
93
|
-
* @param
|
|
94
|
-
* @
|
|
95
|
-
* @
|
|
101
|
+
* @param step - The step object.
|
|
102
|
+
* @param options
|
|
103
|
+
* @returns The step populated with the transaction data.
|
|
104
|
+
* @throws {LiFiError} Throws a LiFiError if request fails.
|
|
96
105
|
*/
|
|
97
106
|
getStepTransaction: (step: LifiStep, options?: RequestOptions) => Promise<LifiStep>;
|
|
98
107
|
/**
|
|
99
108
|
* Get gas recommendation for a certain chain
|
|
100
|
-
* @param
|
|
101
|
-
* @
|
|
109
|
+
* @param request - Configuration of the requested recommendation.
|
|
110
|
+
* @param options
|
|
111
|
+
* @throws {LiFiError} Throws a LiFiError if request fails.
|
|
102
112
|
*/
|
|
103
113
|
getGasRecommendation: (request: GasRecommendationRequest, options?: RequestOptions) => Promise<GasRecommendationResponse>;
|
|
104
114
|
/**
|
|
105
115
|
* Returns the balances of a specific token a wallet holds across all aggregated chains.
|
|
106
|
-
* @param
|
|
107
|
-
* @param
|
|
108
|
-
* @
|
|
116
|
+
* @param walletAddress - A wallet address.
|
|
117
|
+
* @param token - A Token object.
|
|
118
|
+
* @returns An object containing the token and the amounts on different chains.
|
|
109
119
|
* @throws {ValidationError} Throws a ValidationError if parameters are invalid.
|
|
110
120
|
*/
|
|
111
121
|
getTokenBalance: (walletAddress: string, token: Token) => Promise<TokenAmount | null>;
|
|
112
122
|
/**
|
|
113
123
|
* Returns the balances for a list tokens a wallet holds across all aggregated chains.
|
|
114
|
-
* @param
|
|
115
|
-
* @param
|
|
116
|
-
* @
|
|
124
|
+
* @param walletAddress - A wallet address.
|
|
125
|
+
* @param tokens - A list of Token objects.
|
|
126
|
+
* @returns A list of objects containing the tokens and the amounts on different chains.
|
|
117
127
|
* @throws {ValidationError} Throws a ValidationError if parameters are invalid.
|
|
118
128
|
*/
|
|
119
129
|
getTokenBalances: (walletAddress: string, tokens: Token[]) => Promise<TokenAmount[]>;
|
|
120
130
|
/**
|
|
121
131
|
* This method queries the balances of tokens for a specific list of chains for a given wallet.
|
|
122
|
-
* @param
|
|
123
|
-
* @param
|
|
124
|
-
* @
|
|
132
|
+
* @param walletAddress - A walletaddress.
|
|
133
|
+
* @param tokensByChain - A list of Token objects organized by chain ids.
|
|
134
|
+
* @returns A list of objects containing the tokens and the amounts on different chains organized by the chosen chains.
|
|
125
135
|
* @throws {ValidationError} Throws a ValidationError if parameters are invalid.
|
|
126
136
|
*/
|
|
127
|
-
|
|
137
|
+
getTokenBalancesByChain: (walletAddress: string, tokensByChain: {
|
|
128
138
|
[chainId: number]: Token[];
|
|
129
139
|
}) => Promise<{
|
|
130
140
|
[chainId: number]: TokenAmount[];
|
|
131
141
|
}>;
|
|
132
142
|
/**
|
|
133
|
-
* Get the current
|
|
134
|
-
* @param signer - The signer owning the token
|
|
143
|
+
* Get the current allowance for a certain token.
|
|
135
144
|
* @param token - The token that should be checked
|
|
136
|
-
* @param
|
|
145
|
+
* @param ownerAddress - The owner of the token
|
|
146
|
+
* @param spenderAddress - The spender address that has to be approved
|
|
137
147
|
*/
|
|
138
|
-
|
|
148
|
+
getTokenAllowance: (token: Token, ownerAddress: string, spenderAddress: string) => Promise<bigint | undefined>;
|
|
139
149
|
/**
|
|
140
|
-
* Get the current
|
|
141
|
-
* @param
|
|
142
|
-
* @param
|
|
150
|
+
* Get the current allowance for a list of token / spender address pairs.
|
|
151
|
+
* @param ownerAddress - The owner of the tokens
|
|
152
|
+
* @param tokens - A list of token and spender address pairs
|
|
143
153
|
*/
|
|
144
|
-
|
|
145
|
-
token: Token;
|
|
146
|
-
approval: string | undefined;
|
|
147
|
-
}[]>;
|
|
154
|
+
getTokenAllowanceMulticall: (ownerAddress: string, tokens: TokenSpender[]) => Promise<TokenAllowance[]>;
|
|
148
155
|
/**
|
|
149
156
|
* Set approval for a certain token and amount.
|
|
150
|
-
* @param
|
|
157
|
+
* @param request - The approval request
|
|
151
158
|
*/
|
|
152
|
-
|
|
159
|
+
setTokenApproval: (request: ApproveTokenRequest) => Promise<Hash | void>;
|
|
153
160
|
/**
|
|
154
161
|
* Revoke approval for a certain token.
|
|
155
|
-
* @param
|
|
162
|
+
* @param request - The revoke request
|
|
156
163
|
*/
|
|
157
|
-
revokeTokenApproval: (request: RevokeApprovalRequest) => Promise<void>;
|
|
164
|
+
revokeTokenApproval: (request: RevokeApprovalRequest) => Promise<Hash | void>;
|
|
158
165
|
/**
|
|
159
166
|
* Get all the available connections for swap/bridging tokens
|
|
160
167
|
* @param connectionRequest ConnectionsRequest
|