@lifi/sdk 2.2.2 → 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.
Files changed (183) hide show
  1. package/dist/LiFi.d.ts +69 -62
  2. package/dist/LiFi.js +71 -60
  3. package/dist/allowance/getAllowance.d.ts +6 -0
  4. package/dist/allowance/getAllowance.js +78 -0
  5. package/dist/allowance/index.d.ts +3 -2
  6. package/dist/allowance/index.js +3 -2
  7. package/dist/allowance/setAllowance.d.ts +5 -0
  8. package/dist/allowance/setAllowance.js +50 -0
  9. package/dist/allowance/types.d.ts +27 -0
  10. package/dist/allowance/types.js +1 -0
  11. package/dist/balance/getBalance.d.ts +2 -0
  12. package/dist/balance/getBalance.js +93 -0
  13. package/dist/balance/getTokenBalance.d.ts +2 -2
  14. package/dist/balance/getTokenBalance.js +4 -4
  15. package/dist/balance/index.d.ts +1 -12
  16. package/dist/balance/index.js +1 -9
  17. package/dist/cjs/LiFi.d.ts +69 -62
  18. package/dist/cjs/LiFi.js +69 -58
  19. package/dist/cjs/allowance/getAllowance.d.ts +6 -0
  20. package/dist/cjs/allowance/getAllowance.js +85 -0
  21. package/dist/cjs/allowance/index.d.ts +3 -2
  22. package/dist/cjs/allowance/index.js +3 -2
  23. package/dist/cjs/allowance/setAllowance.d.ts +5 -0
  24. package/dist/cjs/allowance/setAllowance.js +56 -0
  25. package/dist/cjs/allowance/types.d.ts +27 -0
  26. package/dist/cjs/allowance/types.js +2 -0
  27. package/dist/cjs/balance/getBalance.d.ts +2 -0
  28. package/dist/cjs/balance/getBalance.js +97 -0
  29. package/dist/cjs/balance/getTokenBalance.d.ts +2 -2
  30. package/dist/cjs/balance/getTokenBalance.js +6 -9
  31. package/dist/cjs/balance/index.d.ts +1 -12
  32. package/dist/cjs/balance/index.js +1 -9
  33. package/dist/cjs/connectors.d.ts +7 -5
  34. package/dist/cjs/connectors.js +45 -37
  35. package/dist/cjs/constants.d.ts +6 -0
  36. package/dist/cjs/constants.js +9 -0
  37. package/dist/cjs/execution/RouteExecutionManager.d.ts +24 -30
  38. package/dist/cjs/execution/RouteExecutionManager.js +27 -45
  39. package/dist/cjs/execution/StatusManager.d.ts +22 -23
  40. package/dist/cjs/execution/StatusManager.js +21 -22
  41. package/dist/cjs/execution/StepExecutionManager.d.ts +3 -3
  42. package/dist/cjs/execution/StepExecutionManager.js +118 -125
  43. package/dist/cjs/execution/StepExecutor.d.ts +4 -4
  44. package/dist/cjs/execution/StepExecutor.js +6 -6
  45. package/dist/cjs/execution/checkAllowance.d.ts +4 -0
  46. package/dist/cjs/execution/checkAllowance.js +77 -0
  47. package/dist/cjs/execution/checkBalance.d.ts +2 -0
  48. package/dist/cjs/execution/checkBalance.js +42 -0
  49. package/dist/cjs/execution/multisig.d.ts +4 -3
  50. package/dist/cjs/execution/multisig.js +9 -11
  51. package/dist/cjs/execution/prepareRestart.d.ts +3 -0
  52. package/dist/cjs/execution/prepareRestart.js +65 -0
  53. package/dist/cjs/execution/stepComparison.d.ts +3 -3
  54. package/dist/cjs/execution/stepComparison.js +2 -2
  55. package/dist/cjs/execution/switchChain.d.ts +13 -8
  56. package/dist/cjs/execution/switchChain.js +16 -11
  57. package/dist/cjs/execution/utils.d.ts +9 -3
  58. package/dist/cjs/execution/utils.js +19 -66
  59. package/dist/cjs/execution/waitForReceivingTransaction.d.ts +3 -0
  60. package/dist/cjs/execution/waitForReceivingTransaction.js +58 -0
  61. package/dist/cjs/helpers.d.ts +7 -17
  62. package/dist/cjs/helpers.js +6 -38
  63. package/dist/cjs/request.js +1 -1
  64. package/dist/cjs/services/ApiService.d.ts +2 -2
  65. package/dist/cjs/services/ApiService.js +2 -0
  66. package/dist/cjs/services/ChainsService.d.ts +1 -1
  67. package/dist/cjs/services/ConfigService.d.ts +1 -1
  68. package/dist/cjs/services/ConfigService.js +1 -2
  69. package/dist/cjs/typeguards.d.ts +1 -1
  70. package/dist/cjs/types/abi.d.ts +5 -0
  71. package/dist/cjs/types/abi.js +45 -0
  72. package/dist/cjs/types/index.d.ts +2 -2
  73. package/dist/cjs/types/index.js +3 -3
  74. package/dist/cjs/types/internal.types.d.ts +24 -30
  75. package/dist/cjs/utils/errors.d.ts +15 -14
  76. package/dist/cjs/utils/errors.js +38 -37
  77. package/dist/cjs/utils/getMaxPriorityFeePerGas.d.ts +2 -0
  78. package/dist/cjs/utils/getMaxPriorityFeePerGas.js +22 -0
  79. package/dist/cjs/utils/index.d.ts +5 -0
  80. package/dist/cjs/utils/index.js +21 -0
  81. package/dist/cjs/utils/median.d.ts +1 -0
  82. package/dist/cjs/utils/median.js +15 -0
  83. package/dist/cjs/utils/parseError.d.ts +4 -4
  84. package/dist/cjs/utils/parseError.js +41 -38
  85. package/dist/cjs/utils/utils.d.ts +1 -16
  86. package/dist/cjs/utils/utils.js +9 -78
  87. package/dist/cjs/version.d.ts +1 -1
  88. package/dist/cjs/version.js +1 -1
  89. package/dist/connectors.d.ts +7 -5
  90. package/dist/connectors.js +19 -35
  91. package/dist/constants.d.ts +6 -0
  92. package/dist/constants.js +6 -0
  93. package/dist/execution/RouteExecutionManager.d.ts +24 -30
  94. package/dist/execution/RouteExecutionManager.js +27 -45
  95. package/dist/execution/StatusManager.d.ts +22 -23
  96. package/dist/execution/StatusManager.js +22 -23
  97. package/dist/execution/StepExecutionManager.d.ts +3 -3
  98. package/dist/execution/StepExecutionManager.js +116 -123
  99. package/dist/execution/StepExecutor.d.ts +4 -4
  100. package/dist/execution/StepExecutor.js +6 -6
  101. package/dist/execution/checkAllowance.d.ts +4 -0
  102. package/dist/execution/checkAllowance.js +73 -0
  103. package/dist/execution/checkBalance.d.ts +2 -0
  104. package/dist/execution/checkBalance.js +38 -0
  105. package/dist/execution/multisig.d.ts +4 -3
  106. package/dist/execution/multisig.js +10 -12
  107. package/dist/execution/prepareRestart.d.ts +3 -0
  108. package/dist/execution/prepareRestart.js +61 -0
  109. package/dist/execution/stepComparison.d.ts +3 -3
  110. package/dist/execution/stepComparison.js +3 -3
  111. package/dist/execution/switchChain.d.ts +13 -8
  112. package/dist/execution/switchChain.js +17 -12
  113. package/dist/execution/utils.d.ts +9 -3
  114. package/dist/execution/utils.js +18 -61
  115. package/dist/execution/waitForReceivingTransaction.d.ts +3 -0
  116. package/dist/execution/waitForReceivingTransaction.js +51 -0
  117. package/dist/helpers.d.ts +7 -17
  118. package/dist/helpers.js +5 -34
  119. package/dist/request.js +2 -2
  120. package/dist/services/ApiService.d.ts +2 -2
  121. package/dist/services/ApiService.js +2 -0
  122. package/dist/services/ChainsService.d.ts +1 -1
  123. package/dist/services/ConfigService.d.ts +1 -1
  124. package/dist/services/ConfigService.js +2 -3
  125. package/dist/typeguards.d.ts +1 -1
  126. package/dist/types/abi.d.ts +5 -0
  127. package/dist/types/abi.js +42 -0
  128. package/dist/types/index.d.ts +2 -2
  129. package/dist/types/index.js +2 -2
  130. package/dist/types/internal.types.d.ts +24 -30
  131. package/dist/utils/errors.d.ts +15 -14
  132. package/dist/utils/errors.js +36 -35
  133. package/dist/utils/getMaxPriorityFeePerGas.d.ts +2 -0
  134. package/dist/utils/getMaxPriorityFeePerGas.js +18 -0
  135. package/dist/utils/index.d.ts +5 -0
  136. package/dist/utils/index.js +5 -0
  137. package/dist/utils/median.d.ts +1 -0
  138. package/dist/utils/median.js +11 -0
  139. package/dist/utils/parseError.d.ts +4 -4
  140. package/dist/utils/parseError.js +42 -39
  141. package/dist/utils/utils.d.ts +1 -16
  142. package/dist/utils/utils.js +7 -69
  143. package/dist/version.d.ts +1 -1
  144. package/dist/version.js +1 -1
  145. package/package.json +28 -27
  146. package/dist/allowance/checkAllowance.d.ts +0 -4
  147. package/dist/allowance/checkAllowance.js +0 -96
  148. package/dist/allowance/tokenApproval.d.ts +0 -22
  149. package/dist/allowance/tokenApproval.js +0 -59
  150. package/dist/allowance/utils.d.ts +0 -15
  151. package/dist/allowance/utils.js +0 -77
  152. package/dist/balance/checkBalance.d.ts +0 -3
  153. package/dist/balance/checkBalance.js +0 -38
  154. package/dist/balance/utils.d.ts +0 -6
  155. package/dist/balance/utils.js +0 -143
  156. package/dist/cjs/allowance/checkAllowance.d.ts +0 -4
  157. package/dist/cjs/allowance/checkAllowance.js +0 -103
  158. package/dist/cjs/allowance/tokenApproval.d.ts +0 -22
  159. package/dist/cjs/allowance/tokenApproval.js +0 -69
  160. package/dist/cjs/allowance/utils.d.ts +0 -15
  161. package/dist/cjs/allowance/utils.js +0 -87
  162. package/dist/cjs/balance/checkBalance.d.ts +0 -3
  163. package/dist/cjs/balance/checkBalance.js +0 -45
  164. package/dist/cjs/balance/utils.d.ts +0 -6
  165. package/dist/cjs/balance/utils.js +0 -150
  166. package/dist/cjs/types/ERC20.d.ts +0 -22
  167. package/dist/cjs/types/ERC20.js +0 -53
  168. package/dist/cjs/utils/getProvider.d.ts +0 -3
  169. package/dist/cjs/utils/getProvider.js +0 -11
  170. package/dist/cjs/utils/multicall.d.ts +0 -10
  171. package/dist/cjs/utils/multicall.js +0 -68
  172. package/dist/cjs/utils/multicallAbi.json +0 -313
  173. package/dist/cjs/utils/preRestart.d.ts +0 -3
  174. package/dist/cjs/utils/preRestart.js +0 -56
  175. package/dist/types/ERC20.d.ts +0 -22
  176. package/dist/types/ERC20.js +0 -50
  177. package/dist/utils/getProvider.d.ts +0 -3
  178. package/dist/utils/getProvider.js +0 -7
  179. package/dist/utils/multicall.d.ts +0 -10
  180. package/dist/utils/multicall.js +0 -61
  181. package/dist/utils/multicallAbi.json +0 -313
  182. package/dist/utils/preRestart.d.ts +0 -3
  183. package/dist/utils/preRestart.js +0 -52
package/dist/LiFi.d.ts CHANGED
@@ -1,160 +1,167 @@
1
- import { FallbackProvider } from '@ethersproject/providers';
2
- import { ChainId, ChainKey, ConnectionsRequest, ConnectionsResponse, ContractCallQuoteRequest, ExtendedChain, GasRecommendationRequest, GasRecommendationResponse, GetStatusRequest, LifiStep, PossibilitiesRequest, PossibilitiesResponse, QuoteRequest, RequestOptions, RoutesRequest, RoutesResponse, StatusResponse, Token, TokenAmount, TokensRequest, TokensResponse, ToolsRequest, ToolsResponse } from '@lifi/types';
3
- import { Signer } from 'ethers';
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, RevokeTokenData } from './types';
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
- * @return {Config} - The config object
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
- * @return {Promise<Config>} - The config object
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 {number} chainId - Id of the chain the provider is for
23
- * @param {boolean} archive - Whether to use an archive provider that is based on a default rpc or not. defaults to false
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
- getRpcProvider: (chainId: number, archive?: boolean) => Promise<FallbackProvider>;
24
+ getPublicClient: (chainId: number) => Promise<PublicClient>;
27
25
  /**
28
26
  * Set a new confuration for the SDK
29
- * @param {ConfigUpdate} configUpdate - An object containing the configuration fields that should be updated.
30
- * @return {Config} The renewed config object
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 {PossibilitiesRequest} request - Object defining preferences regarding chain, exchanges and bridges
36
- * @return {Promise<PossibilitiesResponse>} Object listing current possibilities for any-to-any cross-chain-swaps based on the provided preferences.
37
- * @throws {LifiError} Throws a LifiError if request fails.
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 {ChainKey | ChainId} chain - Id or key of the chain that contains the token
44
- * @param {string} token - Address or symbol of the token on the requested chain
45
- * @throws {LifiError} - Throws a LifiError if request fails
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 {QuoteRequest} request - The configuration of the requested quote
51
- * @throws {LifiError} - Throws a LifiError if request fails
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 {ContractCallQuoteRequest} request - The configuration of the requested destination call
57
- * @throws {LifiError} - Throws a LifiError if request fails
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 {GetStatusRequest} request - Configuration of the requested status
63
- * @throws {LifiError} - Throws a LifiError if request fails
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 {ToolsRequest?} request - The configuration of the requested tools
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 {TokensRequest?} request - The configuration of the requested tokens
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
- * @return {Promise<Chain[]>} A list of all available chains
81
- * @throws {LifiError} Throws a LifiError if request fails.
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 {RoutesRequest} request - A description of the transfer.
87
- * @return {Promise<RoutesResponse>} The resulting routes that can be used to realize the described transfer of tokens.
88
- * @throws {LifiError} Throws a LifiError if request fails.
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 {LifiStep} step - The step object.
94
- * @return {Promise<LifiStep>} The step populated with the transaction data.
95
- * @throws {LifiError} Throws a LifiError if request fails.
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 {GasRecommendationRequest} request - Configuration of the requested recommendation.
101
- * @throws {LifiError} Throws a LifiError if request fails.
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 {string} walletAddress - A wallet address.
107
- * @param {Token} token - A Token object.
108
- * @return {Promise<TokenAmount | null>} An object containing the token and the amounts on different chains.
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 {string} walletAddress - A wallet address.
115
- * @param {Token[]} tokens - A list of Token objects.
116
- * @return {Promise<TokenAmount[]>} A list of objects containing the tokens and the amounts on different chains.
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 {string} walletAddress - A walletaddress.
123
- * @param {{ [chainId: number]: Token[] }} tokensByChain - A list of Token objects organized by chain ids.
124
- * @return {Promise<{ [chainId: number]: TokenAmount[] }>} A list of objects containing the tokens and the amounts on different chains organized by the chosen chains.
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
- getTokenBalancesForChains: (walletAddress: string, tokensByChain: {
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 approval for a certain token.
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 approvalAddress - The address that has be approved
145
+ * @param ownerAddress - The owner of the token
146
+ * @param spenderAddress - The spender address that has to be approved
137
147
  */
138
- getTokenApproval: (signer: Signer, token: Token, approvalAddress: string) => Promise<string | undefined>;
148
+ getTokenAllowance: (token: Token, ownerAddress: string, spenderAddress: string) => Promise<bigint | undefined>;
139
149
  /**
140
- * Get the current approval for a list of token / approval address pairs.
141
- * @param signer - The signer owning the tokens
142
- * @param tokenData - A list of token and approval address pairs
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
- bulkGetTokenApproval: (signer: Signer, tokenData: RevokeTokenData[]) => Promise<{
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 { ApproveTokenRequest } request - The approval request
157
+ * @param request - The approval request
151
158
  */
152
- approveToken: (request: ApproveTokenRequest) => Promise<void>;
159
+ setTokenApproval: (request: ApproveTokenRequest) => Promise<Hash | void>;
153
160
  /**
154
161
  * Revoke approval for a certain token.
155
- * @param { RevokeApprovalRequest } request - The revoke request
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 { approveToken, bulkGetTokenApproval, getTokenApproval, revokeTokenApproval, } from './allowance';
1
+ import { getTokenAllowance, getTokenAllowanceMulticall, revokeTokenApproval, setTokenAllowance, } from './allowance';
2
2
  import * as balance from './balance';
3
- import { getRpcProvider } from './connectors';
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
- * @return {Config} - The config object
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
- * @return {Promise<Config>} - The config object
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 {number} chainId - Id of the chain the provider is for
31
- * @param {boolean} archive - Whether to use an archive provider that is based on a default rpc or not. defaults to false
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.getRpcProvider = (chainId, archive = false) => {
35
- return getRpcProvider(chainId, archive);
33
+ this.getPublicClient = (chainId) => {
34
+ return getPublicClient(chainId);
36
35
  };
37
36
  /**
38
37
  * Set a new confuration for the SDK
39
- * @param {ConfigUpdate} configUpdate - An object containing the configuration fields that should be updated.
40
- * @return {Config} The renewed config object
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 {PossibilitiesRequest} request - Object defining preferences regarding chain, exchanges and bridges
48
- * @return {Promise<PossibilitiesResponse>} 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.
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 {ChainKey | ChainId} chain - Id or key of the chain that contains the token
58
- * @param {string} token - Address or symbol of the token on the requested chain
59
- * @throws {LifiError} - Throws a LifiError if request fails
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 {QuoteRequest} request - The configuration of the requested quote
67
- * @throws {LifiError} - Throws a LifiError if request fails
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 {ContractCallQuoteRequest} request - The configuration of the requested destination call
75
- * @throws {LifiError} - Throws a LifiError if request fails
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 {GetStatusRequest} request - Configuration of the requested status
83
- * @throws {LifiError} - Throws a LifiError if request fails
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 {ToolsRequest?} request - The configuration of the requested tools
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 {TokensRequest?} request - The configuration of the requested tokens
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
- * @return {Promise<Chain[]>} A list of all available chains
107
- * @throws {LifiError} Throws a LifiError if request fails.
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 {RoutesRequest} request - A description of the transfer.
115
- * @return {Promise<RoutesResponse>} The resulting routes that can be used to realize the described transfer of tokens.
116
- * @throws {LifiError} Throws a LifiError if request fails.
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 {LifiStep} step - The step object.
124
- * @return {Promise<LifiStep>} The step populated with the transaction data.
125
- * @throws {LifiError} Throws a LifiError if request fails.
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 {GasRecommendationRequest} request - Configuration of the requested recommendation.
133
- * @throws {LifiError} Throws a LifiError if request fails.
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 {string} walletAddress - A wallet address.
141
- * @param {Token} token - A Token object.
142
- * @return {Promise<TokenAmount | null>} An object containing the token and the amounts on different chains.
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 {string} walletAddress - A wallet address.
157
- * @param {Token[]} tokens - A list of Token objects.
158
- * @return {Promise<TokenAmount[]>} A list of objects containing the tokens and the amounts on different chains.
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 {string} walletAddress - A walletaddress.
174
- * @param {{ [chainId: number]: Token[] }} tokensByChain - A list of Token objects organized by chain ids.
175
- * @return {Promise<{ [chainId: number]: TokenAmount[] }>} A list of objects containing the tokens and the amounts on different chains organized by the chosen chains.
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.getTokenBalancesForChains = async (walletAddress, tokensByChain) => {
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.getTokenBalancesForChains(walletAddress, tokensByChain);
198
+ return balance.getTokenBalancesByChain(walletAddress, tokensByChain);
188
199
  };
189
200
  /**
190
- * Get the current approval for a certain token.
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 approvalAddress - The address that has be approved
203
+ * @param ownerAddress - The owner of the token
204
+ * @param spenderAddress - The spender address that has to be approved
194
205
  */
195
- this.getTokenApproval = async (signer, token, approvalAddress) => {
196
- return getTokenApproval(signer, token, approvalAddress);
206
+ this.getTokenAllowance = async (token, ownerAddress, spenderAddress) => {
207
+ return getTokenAllowance(token, ownerAddress, spenderAddress);
197
208
  };
198
209
  /**
199
- * Get the current approval for a list of token / approval address pairs.
200
- * @param signer - The signer owning the tokens
201
- * @param tokenData - A list of token and approval address pairs
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.bulkGetTokenApproval = async (signer, tokenData) => {
204
- return bulkGetTokenApproval(signer, tokenData);
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 { ApproveTokenRequest } request - The approval request
219
+ * @param request - The approval request
209
220
  */
210
- this.approveToken = (request) => {
211
- return approveToken(request);
221
+ this.setTokenApproval = (request) => {
222
+ return setTokenAllowance(request);
212
223
  };
213
224
  /**
214
225
  * Revoke approval for a certain token.
215
- * @param { RevokeApprovalRequest } request - The revoke request
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 './checkAllowance';
2
- export * from './tokenApproval';
1
+ export * from './getAllowance';
2
+ export * from './setAllowance';
3
+ export * from './types';
@@ -1,2 +1,3 @@
1
- export * from './checkAllowance';
2
- export * from './tokenApproval';
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>;