@lifi/sdk 2.2.1 → 3.0.0-alpha.1
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 +23 -42
- package/dist/cjs/services/ChainsService.d.ts +1 -1
- package/dist/cjs/services/ConfigService.d.ts +1 -1
- package/dist/cjs/services/ConfigService.js +5 -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 -30
- 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 +23 -42
- package/dist/services/ChainsService.d.ts +1 -1
- package/dist/services/ConfigService.d.ts +1 -1
- package/dist/services/ConfigService.js +6 -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 -30
- 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 +28 -27
- 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
package/dist/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
|
package/dist/LiFi.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getTokenAllowance, getTokenAllowanceMulticall, revokeTokenApproval, setTokenAllowance, } from './allowance';
|
|
2
2
|
import * as balance from './balance';
|
|
3
|
-
import {
|
|
3
|
+
import { getPublicClient } from './connectors';
|
|
4
4
|
import { RouteExecutionManager } from './execution/RouteExecutionManager';
|
|
5
5
|
import { checkPackageUpdates } from './helpers';
|
|
6
6
|
import ApiService from './services/ApiService';
|
|
@@ -13,40 +13,40 @@ export class LiFi extends RouteExecutionManager {
|
|
|
13
13
|
super(configUpdate);
|
|
14
14
|
/**
|
|
15
15
|
* Get the current configuration of the SDK
|
|
16
|
-
* @
|
|
16
|
+
* @returns - The config object
|
|
17
17
|
*/
|
|
18
18
|
this.getConfig = () => {
|
|
19
19
|
return this.configService.getConfig();
|
|
20
20
|
};
|
|
21
21
|
/**
|
|
22
22
|
* Get the SDK configuration after all setup calls are finished
|
|
23
|
-
* @
|
|
23
|
+
* @returns - The config object
|
|
24
24
|
*/
|
|
25
25
|
this.getConfigAsync = () => {
|
|
26
26
|
return this.configService.getConfigAsync();
|
|
27
27
|
};
|
|
28
28
|
/**
|
|
29
29
|
* Get an instance of a provider for a specific chain
|
|
30
|
-
* @param
|
|
31
|
-
* @
|
|
32
|
-
* @return {FallbackProvider} The provider for the given chain
|
|
30
|
+
* @param chainId - Id of the chain the provider is for
|
|
31
|
+
* @returns The public client for the given chain
|
|
33
32
|
*/
|
|
34
|
-
this.
|
|
35
|
-
return
|
|
33
|
+
this.getPublicClient = (chainId) => {
|
|
34
|
+
return getPublicClient(chainId);
|
|
36
35
|
};
|
|
37
36
|
/**
|
|
38
37
|
* Set a new confuration for the SDK
|
|
39
|
-
* @param
|
|
40
|
-
* @
|
|
38
|
+
* @param configUpdate - An object containing the configuration fields that should be updated.
|
|
39
|
+
* @returns The renewed config object
|
|
41
40
|
*/
|
|
42
41
|
this.setConfig = (configUpdate) => {
|
|
43
42
|
return this.configService.updateConfig(configUpdate);
|
|
44
43
|
};
|
|
45
44
|
/**
|
|
46
45
|
* Get a set of current possibilities based on a request that specifies which chains, exchanges and bridges are preferred or unwanted.
|
|
47
|
-
* @param
|
|
48
|
-
* @
|
|
49
|
-
* @
|
|
46
|
+
* @param request - Object defining preferences regarding chain, exchanges and bridges
|
|
47
|
+
* @param options
|
|
48
|
+
* @returns Object listing current possibilities for any-to-any cross-chain-swaps based on the provided preferences.
|
|
49
|
+
* @throws {LiFiError} Throws a LiFiError if request fails.
|
|
50
50
|
* @deprecated We don't want to support this endpoint anymore in the future. /chains, /tools, /connections, and /tokens should be used instead
|
|
51
51
|
*/
|
|
52
52
|
this.getPossibilities = async (request, options) => {
|
|
@@ -54,40 +54,47 @@ export class LiFi extends RouteExecutionManager {
|
|
|
54
54
|
};
|
|
55
55
|
/**
|
|
56
56
|
* Fetch information about a Token
|
|
57
|
-
* @param
|
|
58
|
-
* @param
|
|
59
|
-
* @
|
|
57
|
+
* @param chain - Id or key of the chain that contains the token
|
|
58
|
+
* @param token - Address or symbol of the token on the requested chain
|
|
59
|
+
* @param options
|
|
60
|
+
* @throws {LiFiError} - Throws a LiFiError if request fails
|
|
60
61
|
*/
|
|
61
62
|
this.getToken = async (chain, token, options) => {
|
|
62
63
|
return ApiService.getToken(chain, token, options);
|
|
63
64
|
};
|
|
64
65
|
/**
|
|
65
66
|
* Get a quote for a token transfer
|
|
66
|
-
* @param
|
|
67
|
-
* @
|
|
67
|
+
* @param request - The configuration of the requested quote
|
|
68
|
+
* @param options
|
|
69
|
+
* @throws {LiFiError} - Throws a LiFiError if request fails
|
|
68
70
|
*/
|
|
69
71
|
this.getQuote = async (request, options) => {
|
|
70
72
|
return ApiService.getQuote(request, options);
|
|
71
73
|
};
|
|
72
74
|
/**
|
|
73
75
|
* Get a quote for a destination contract call
|
|
74
|
-
* @param
|
|
75
|
-
* @
|
|
76
|
+
* @param request - The configuration of the requested destination call
|
|
77
|
+
* @param options
|
|
78
|
+
* @throws {LiFiError} - Throws a LiFiError if request fails
|
|
79
|
+
* @returns - Returns step.
|
|
76
80
|
*/
|
|
77
81
|
this.getContractCallQuote = async (request, options) => {
|
|
78
82
|
return ApiService.getContractCallQuote(request, options);
|
|
79
83
|
};
|
|
80
84
|
/**
|
|
81
85
|
* Check the status of a transfer. For cross chain transfers, the "bridge" parameter is required.
|
|
82
|
-
* @param
|
|
83
|
-
* @
|
|
86
|
+
* @param request - Configuration of the requested status
|
|
87
|
+
* @param options - Rrquest options.
|
|
88
|
+
* @throws {LiFiError} - Throws a LiFiError if request fails
|
|
89
|
+
* @returns Returns status response.
|
|
84
90
|
*/
|
|
85
91
|
this.getStatus = async (request, options) => {
|
|
86
92
|
return ApiService.getStatus(request, options);
|
|
87
93
|
};
|
|
88
94
|
/**
|
|
89
95
|
* Get the available tools to bridge and swap tokens.
|
|
90
|
-
* @param
|
|
96
|
+
* @param request - The configuration of the requested tools
|
|
97
|
+
* @param options
|
|
91
98
|
* @returns The tools that are available on the requested chains
|
|
92
99
|
*/
|
|
93
100
|
this.getTools = async (request, options) => {
|
|
@@ -95,7 +102,8 @@ export class LiFi extends RouteExecutionManager {
|
|
|
95
102
|
};
|
|
96
103
|
/**
|
|
97
104
|
* Get all known tokens.
|
|
98
|
-
* @param
|
|
105
|
+
* @param request - The configuration of the requested tokens
|
|
106
|
+
* @param options
|
|
99
107
|
* @returns The tokens that are available on the requested chains
|
|
100
108
|
*/
|
|
101
109
|
this.getTokens = async (request, options) => {
|
|
@@ -103,43 +111,46 @@ export class LiFi extends RouteExecutionManager {
|
|
|
103
111
|
};
|
|
104
112
|
/**
|
|
105
113
|
* Get all available chains
|
|
106
|
-
* @
|
|
107
|
-
* @throws {
|
|
114
|
+
* @returns A list of all available chains
|
|
115
|
+
* @throws {LiFiError} Throws a LiFiError if request fails.
|
|
108
116
|
*/
|
|
109
117
|
this.getChains = async () => {
|
|
110
118
|
return this.chainsService.getChains();
|
|
111
119
|
};
|
|
112
120
|
/**
|
|
113
121
|
* Get a set of routes for a request that describes a transfer of tokens.
|
|
114
|
-
* @param
|
|
115
|
-
* @
|
|
116
|
-
* @
|
|
122
|
+
* @param request - A description of the transfer.
|
|
123
|
+
* @param options
|
|
124
|
+
* @returns The resulting routes that can be used to realize the described transfer of tokens.
|
|
125
|
+
* @throws {LiFiError} Throws a LiFiError if request fails.
|
|
117
126
|
*/
|
|
118
127
|
this.getRoutes = async (request, options) => {
|
|
119
128
|
return ApiService.getRoutes(request, options);
|
|
120
129
|
};
|
|
121
130
|
/**
|
|
122
131
|
* Get the transaction data for a single step of a route
|
|
123
|
-
* @param
|
|
124
|
-
* @
|
|
125
|
-
* @
|
|
132
|
+
* @param step - The step object.
|
|
133
|
+
* @param options
|
|
134
|
+
* @returns The step populated with the transaction data.
|
|
135
|
+
* @throws {LiFiError} Throws a LiFiError if request fails.
|
|
126
136
|
*/
|
|
127
137
|
this.getStepTransaction = async (step, options) => {
|
|
128
138
|
return ApiService.getStepTransaction(step, options);
|
|
129
139
|
};
|
|
130
140
|
/**
|
|
131
141
|
* Get gas recommendation for a certain chain
|
|
132
|
-
* @param
|
|
133
|
-
* @
|
|
142
|
+
* @param request - Configuration of the requested recommendation.
|
|
143
|
+
* @param options
|
|
144
|
+
* @throws {LiFiError} Throws a LiFiError if request fails.
|
|
134
145
|
*/
|
|
135
146
|
this.getGasRecommendation = async (request, options) => {
|
|
136
147
|
return ApiService.getGasRecommendation(request, options);
|
|
137
148
|
};
|
|
138
149
|
/**
|
|
139
150
|
* Returns the balances of a specific token a wallet holds across all aggregated chains.
|
|
140
|
-
* @param
|
|
141
|
-
* @param
|
|
142
|
-
* @
|
|
151
|
+
* @param walletAddress - A wallet address.
|
|
152
|
+
* @param token - A Token object.
|
|
153
|
+
* @returns An object containing the token and the amounts on different chains.
|
|
143
154
|
* @throws {ValidationError} Throws a ValidationError if parameters are invalid.
|
|
144
155
|
*/
|
|
145
156
|
this.getTokenBalance = async (walletAddress, token) => {
|
|
@@ -153,9 +164,9 @@ export class LiFi extends RouteExecutionManager {
|
|
|
153
164
|
};
|
|
154
165
|
/**
|
|
155
166
|
* Returns the balances for a list tokens a wallet holds across all aggregated chains.
|
|
156
|
-
* @param
|
|
157
|
-
* @param
|
|
158
|
-
* @
|
|
167
|
+
* @param walletAddress - A wallet address.
|
|
168
|
+
* @param tokens - A list of Token objects.
|
|
169
|
+
* @returns A list of objects containing the tokens and the amounts on different chains.
|
|
159
170
|
* @throws {ValidationError} Throws a ValidationError if parameters are invalid.
|
|
160
171
|
*/
|
|
161
172
|
this.getTokenBalances = async (walletAddress, tokens) => {
|
|
@@ -170,12 +181,12 @@ export class LiFi extends RouteExecutionManager {
|
|
|
170
181
|
};
|
|
171
182
|
/**
|
|
172
183
|
* This method queries the balances of tokens for a specific list of chains for a given wallet.
|
|
173
|
-
* @param
|
|
174
|
-
* @param
|
|
175
|
-
* @
|
|
184
|
+
* @param walletAddress - A walletaddress.
|
|
185
|
+
* @param tokensByChain - A list of Token objects organized by chain ids.
|
|
186
|
+
* @returns A list of objects containing the tokens and the amounts on different chains organized by the chosen chains.
|
|
176
187
|
* @throws {ValidationError} Throws a ValidationError if parameters are invalid.
|
|
177
188
|
*/
|
|
178
|
-
this.
|
|
189
|
+
this.getTokenBalancesByChain = async (walletAddress, tokensByChain) => {
|
|
179
190
|
if (!walletAddress) {
|
|
180
191
|
throw new ValidationError('Missing walletAddress.');
|
|
181
192
|
}
|
|
@@ -184,35 +195,35 @@ export class LiFi extends RouteExecutionManager {
|
|
|
184
195
|
if (invalidTokens.length) {
|
|
185
196
|
throw new ValidationError(`Invalid token passed: address "${invalidTokens[0].address}" on chainId "${invalidTokens[0].chainId}"`);
|
|
186
197
|
}
|
|
187
|
-
return balance.
|
|
198
|
+
return balance.getTokenBalancesByChain(walletAddress, tokensByChain);
|
|
188
199
|
};
|
|
189
200
|
/**
|
|
190
|
-
* Get the current
|
|
191
|
-
* @param signer - The signer owning the token
|
|
201
|
+
* Get the current allowance for a certain token.
|
|
192
202
|
* @param token - The token that should be checked
|
|
193
|
-
* @param
|
|
203
|
+
* @param ownerAddress - The owner of the token
|
|
204
|
+
* @param spenderAddress - The spender address that has to be approved
|
|
194
205
|
*/
|
|
195
|
-
this.
|
|
196
|
-
return
|
|
206
|
+
this.getTokenAllowance = async (token, ownerAddress, spenderAddress) => {
|
|
207
|
+
return getTokenAllowance(token, ownerAddress, spenderAddress);
|
|
197
208
|
};
|
|
198
209
|
/**
|
|
199
|
-
* Get the current
|
|
200
|
-
* @param
|
|
201
|
-
* @param
|
|
210
|
+
* Get the current allowance for a list of token / spender address pairs.
|
|
211
|
+
* @param ownerAddress - The owner of the tokens
|
|
212
|
+
* @param tokens - A list of token and spender address pairs
|
|
202
213
|
*/
|
|
203
|
-
this.
|
|
204
|
-
return
|
|
214
|
+
this.getTokenAllowanceMulticall = async (ownerAddress, tokens) => {
|
|
215
|
+
return getTokenAllowanceMulticall(ownerAddress, tokens);
|
|
205
216
|
};
|
|
206
217
|
/**
|
|
207
218
|
* Set approval for a certain token and amount.
|
|
208
|
-
* @param
|
|
219
|
+
* @param request - The approval request
|
|
209
220
|
*/
|
|
210
|
-
this.
|
|
211
|
-
return
|
|
221
|
+
this.setTokenApproval = (request) => {
|
|
222
|
+
return setTokenAllowance(request);
|
|
212
223
|
};
|
|
213
224
|
/**
|
|
214
225
|
* Revoke approval for a certain token.
|
|
215
|
-
* @param
|
|
226
|
+
* @param request - The revoke request
|
|
216
227
|
*/
|
|
217
228
|
this.revokeTokenApproval = (request) => {
|
|
218
229
|
return revokeTokenApproval(request);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ChainId, Token } from '@lifi/types';
|
|
2
|
+
import type { TokenAllowance, TokenSpender, TokenSpenderAllowance } from './types';
|
|
3
|
+
export declare const getAllowance: (chainId: ChainId, tokenAddress: string, ownerAddress: string, spenderAddress: string) => Promise<bigint>;
|
|
4
|
+
export declare const getAllowanceMulticall: (chainId: ChainId, tokens: TokenSpender[], ownerAddress: string) => Promise<TokenSpenderAllowance[]>;
|
|
5
|
+
export declare const getTokenAllowance: (token: Token, ownerAddress: string, spenderAddress: string) => Promise<bigint | undefined>;
|
|
6
|
+
export declare const getTokenAllowanceMulticall: (ownerAddress: string, tokens: TokenSpender[]) => Promise<TokenAllowance[]>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { getContract } from 'viem';
|
|
2
|
+
import { getMulticallAddress, getPublicClient } from '../connectors';
|
|
3
|
+
import { MulticallBatchSize } from '../constants';
|
|
4
|
+
import { allowanceAbi } from '../types';
|
|
5
|
+
import { isNativeTokenAddress } from '../utils/utils';
|
|
6
|
+
export const getAllowance = async (chainId, tokenAddress, ownerAddress, spenderAddress) => {
|
|
7
|
+
const client = await getPublicClient(chainId);
|
|
8
|
+
const contract = getContract({
|
|
9
|
+
address: tokenAddress,
|
|
10
|
+
abi: allowanceAbi,
|
|
11
|
+
publicClient: client,
|
|
12
|
+
});
|
|
13
|
+
try {
|
|
14
|
+
const approved = (await contract.read.allowance([
|
|
15
|
+
ownerAddress,
|
|
16
|
+
spenderAddress,
|
|
17
|
+
]));
|
|
18
|
+
return approved;
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
return 0n;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
export const getAllowanceMulticall = async (chainId, tokens, ownerAddress) => {
|
|
25
|
+
if (!tokens.length) {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
const multicallAddress = await getMulticallAddress(chainId);
|
|
29
|
+
if (!multicallAddress) {
|
|
30
|
+
throw new Error(`No multicall address configured for chainId ${chainId}.`);
|
|
31
|
+
}
|
|
32
|
+
const client = await getPublicClient(chainId);
|
|
33
|
+
const contracts = tokens.map((token) => ({
|
|
34
|
+
address: token.token.address,
|
|
35
|
+
abi: allowanceAbi,
|
|
36
|
+
functionName: 'allowance',
|
|
37
|
+
args: [ownerAddress, token.spenderAddress],
|
|
38
|
+
}));
|
|
39
|
+
const results = await client.multicall({
|
|
40
|
+
contracts,
|
|
41
|
+
multicallAddress: multicallAddress,
|
|
42
|
+
batchSize: MulticallBatchSize,
|
|
43
|
+
});
|
|
44
|
+
if (!results.length) {
|
|
45
|
+
throw new Error(`Couldn't load allowance from chainId ${chainId} using multicall.`);
|
|
46
|
+
}
|
|
47
|
+
return tokens.map(({ token, spenderAddress }, i) => ({
|
|
48
|
+
token,
|
|
49
|
+
spenderAddress,
|
|
50
|
+
allowance: results[i].result,
|
|
51
|
+
}));
|
|
52
|
+
};
|
|
53
|
+
export const getTokenAllowance = async (token, ownerAddress, spenderAddress) => {
|
|
54
|
+
// native token don't need approval
|
|
55
|
+
if (isNativeTokenAddress(token.address)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const approved = await getAllowance(token.chainId, token.address, ownerAddress, spenderAddress);
|
|
59
|
+
return approved;
|
|
60
|
+
};
|
|
61
|
+
export const getTokenAllowanceMulticall = async (ownerAddress, tokens) => {
|
|
62
|
+
// filter out native tokens
|
|
63
|
+
const filteredTokens = tokens.filter(({ token }) => !isNativeTokenAddress(token.address));
|
|
64
|
+
// group by chain
|
|
65
|
+
const tokenDataByChain = {};
|
|
66
|
+
filteredTokens.forEach((data) => {
|
|
67
|
+
if (!tokenDataByChain[data.token.chainId]) {
|
|
68
|
+
tokenDataByChain[data.token.chainId] = [];
|
|
69
|
+
}
|
|
70
|
+
tokenDataByChain[data.token.chainId].push(data);
|
|
71
|
+
});
|
|
72
|
+
const chainKeys = Object.keys(tokenDataByChain).map(Number.parseInt);
|
|
73
|
+
const allowances = (await Promise.all(chainKeys.map(async (chainId) => {
|
|
74
|
+
// get allowances for current chain and token list
|
|
75
|
+
return getAllowanceMulticall(chainId, tokenDataByChain[chainId], ownerAddress);
|
|
76
|
+
}))).flat();
|
|
77
|
+
return allowances;
|
|
78
|
+
};
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
1
|
+
export * from './getAllowance';
|
|
2
|
+
export * from './setAllowance';
|
|
3
|
+
export * from './types';
|
package/dist/allowance/index.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
1
|
+
export * from './getAllowance';
|
|
2
|
+
export * from './setAllowance';
|
|
3
|
+
export * from './types';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Hash, WalletClient } from 'viem';
|
|
2
|
+
import type { ApproveTokenRequest, RevokeApprovalRequest } from './types';
|
|
3
|
+
export declare const setAllowance: (walletClient: WalletClient, tokenAddress: string, contractAddress: string, amount: bigint, returnPopulatedTransaction?: boolean) => Promise<Hash>;
|
|
4
|
+
export declare const setTokenAllowance: ({ walletClient, token, spenderAddress, amount, infiniteApproval, }: ApproveTokenRequest) => Promise<Hash | undefined>;
|
|
5
|
+
export declare const revokeTokenApproval: ({ walletClient, token, spenderAddress, }: RevokeApprovalRequest) => Promise<Hash | undefined>;
|