@lifi/sdk 3.0.0-alpha.4 → 3.0.0-alpha.7

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 (115) hide show
  1. package/dist/LiFi.d.ts +28 -21
  2. package/dist/LiFi.js +20 -13
  3. package/dist/allowance/setAllowance.d.ts +2 -1
  4. package/dist/allowance/setAllowance.js +23 -7
  5. package/dist/cjs/LiFi.d.ts +28 -21
  6. package/dist/cjs/LiFi.js +20 -13
  7. package/dist/cjs/allowance/setAllowance.d.ts +2 -1
  8. package/dist/cjs/allowance/setAllowance.js +23 -7
  9. package/dist/cjs/connectors.d.ts +1 -1
  10. package/dist/cjs/execution/BaseStepExecutor.d.ts +12 -0
  11. package/dist/cjs/execution/BaseStepExecutor.js +27 -0
  12. package/dist/cjs/execution/EVMStepExecutor.d.ts +13 -0
  13. package/dist/cjs/execution/EVMStepExecutor.js +292 -0
  14. package/dist/cjs/execution/RouteExecutionManager.d.ts +6 -7
  15. package/dist/cjs/execution/RouteExecutionManager.js +19 -19
  16. package/dist/cjs/execution/StatusManager.d.ts +8 -7
  17. package/dist/cjs/execution/StatusManager.js +1 -1
  18. package/dist/cjs/execution/StepExecutionManager.d.ts +3 -3
  19. package/dist/cjs/execution/StepExecutionManager.js +34 -29
  20. package/dist/cjs/execution/checkAllowance.d.ts +3 -2
  21. package/dist/cjs/execution/checkAllowance.js +1 -1
  22. package/dist/cjs/execution/checkBalance.d.ts +2 -2
  23. package/dist/cjs/execution/index.d.ts +1 -0
  24. package/dist/cjs/execution/index.js +1 -0
  25. package/dist/cjs/execution/multisig.d.ts +2 -2
  26. package/dist/cjs/execution/prepareRestart.d.ts +2 -3
  27. package/dist/cjs/execution/prepareRestart.js +2 -2
  28. package/dist/cjs/execution/stepComparison.d.ts +4 -3
  29. package/dist/cjs/execution/stepComparison.js +1 -1
  30. package/dist/cjs/execution/switchChain.d.ts +4 -3
  31. package/dist/cjs/execution/switchChain.js +1 -0
  32. package/dist/cjs/{types/internal.types.d.ts → execution/types.d.ts} +36 -96
  33. package/dist/cjs/execution/utils.d.ts +2 -2
  34. package/dist/cjs/execution/waitForReceivingTransaction.d.ts +3 -3
  35. package/dist/cjs/helpers.d.ts +2 -2
  36. package/dist/cjs/index.d.ts +3 -1
  37. package/dist/cjs/index.js +6 -3
  38. package/dist/cjs/providers/BaseProvider.d.ts +7 -0
  39. package/dist/cjs/providers/BaseProvider.js +6 -0
  40. package/dist/cjs/providers/EVMProvider.d.ts +16 -0
  41. package/dist/cjs/providers/EVMProvider.js +28 -0
  42. package/dist/cjs/providers/SolanaProvider.d.ts +15 -0
  43. package/dist/cjs/providers/SolanaProvider.js +32 -0
  44. package/dist/cjs/providers/types.d.ts +0 -0
  45. package/dist/cjs/providers/types.js +1 -0
  46. package/dist/cjs/request.js +11 -5
  47. package/dist/cjs/services/ApiService.d.ts +4 -5
  48. package/dist/cjs/services/ApiService.js +2 -2
  49. package/dist/cjs/services/ConfigService.d.ts +6 -5
  50. package/dist/cjs/services/ConfigService.js +3 -3
  51. package/dist/cjs/typeguards.d.ts +2 -2
  52. package/dist/cjs/types/index.d.ts +1 -3
  53. package/dist/cjs/types/index.js +1 -5
  54. package/dist/cjs/types/internal.d.ts +60 -0
  55. package/dist/cjs/types/internal.js +2 -0
  56. package/dist/cjs/utils/parseError.d.ts +4 -4
  57. package/dist/cjs/version.d.ts +1 -1
  58. package/dist/cjs/version.js +1 -1
  59. package/dist/connectors.d.ts +1 -1
  60. package/dist/execution/BaseStepExecutor.d.ts +12 -0
  61. package/dist/execution/BaseStepExecutor.js +23 -0
  62. package/dist/execution/EVMStepExecutor.d.ts +13 -0
  63. package/dist/execution/EVMStepExecutor.js +285 -0
  64. package/dist/execution/RouteExecutionManager.d.ts +6 -7
  65. package/dist/execution/RouteExecutionManager.js +19 -19
  66. package/dist/execution/StatusManager.d.ts +8 -7
  67. package/dist/execution/StatusManager.js +1 -1
  68. package/dist/execution/StepExecutionManager.d.ts +3 -3
  69. package/dist/execution/StepExecutionManager.js +34 -29
  70. package/dist/execution/checkAllowance.d.ts +3 -2
  71. package/dist/execution/checkAllowance.js +1 -1
  72. package/dist/execution/checkBalance.d.ts +2 -2
  73. package/dist/execution/index.d.ts +1 -0
  74. package/dist/execution/index.js +1 -0
  75. package/dist/execution/multisig.d.ts +2 -2
  76. package/dist/execution/prepareRestart.d.ts +2 -3
  77. package/dist/execution/prepareRestart.js +2 -2
  78. package/dist/execution/stepComparison.d.ts +4 -3
  79. package/dist/execution/stepComparison.js +1 -1
  80. package/dist/execution/switchChain.d.ts +4 -3
  81. package/dist/execution/switchChain.js +1 -0
  82. package/dist/{types/internal.types.d.ts → execution/types.d.ts} +36 -96
  83. package/dist/execution/utils.d.ts +2 -2
  84. package/dist/execution/waitForReceivingTransaction.d.ts +3 -3
  85. package/dist/helpers.d.ts +2 -2
  86. package/dist/index.d.ts +3 -1
  87. package/dist/index.js +3 -1
  88. package/dist/providers/BaseProvider.d.ts +7 -0
  89. package/dist/providers/BaseProvider.js +2 -0
  90. package/dist/providers/EVMProvider.d.ts +16 -0
  91. package/dist/providers/EVMProvider.js +24 -0
  92. package/dist/providers/SolanaProvider.d.ts +15 -0
  93. package/dist/providers/SolanaProvider.js +28 -0
  94. package/dist/providers/types.d.ts +0 -0
  95. package/dist/providers/types.js +1 -0
  96. package/dist/request.js +11 -5
  97. package/dist/services/ApiService.d.ts +4 -5
  98. package/dist/services/ApiService.js +2 -2
  99. package/dist/services/ConfigService.d.ts +6 -5
  100. package/dist/services/ConfigService.js +3 -3
  101. package/dist/typeguards.d.ts +2 -2
  102. package/dist/types/index.d.ts +1 -3
  103. package/dist/types/index.js +1 -3
  104. package/dist/types/internal.d.ts +60 -0
  105. package/dist/types/internal.js +1 -0
  106. package/dist/utils/parseError.d.ts +4 -4
  107. package/dist/version.d.ts +1 -1
  108. package/dist/version.js +1 -1
  109. package/package.json +61 -62
  110. package/dist/cjs/execution/StepExecutor.d.ts +0 -15
  111. package/dist/cjs/execution/StepExecutor.js +0 -62
  112. package/dist/execution/StepExecutor.d.ts +0 -15
  113. package/dist/execution/StepExecutor.js +0 -58
  114. /package/dist/cjs/{types/internal.types.js → execution/types.js} +0 -0
  115. /package/dist/{types/internal.types.js → execution/types.js} +0 -0
package/dist/LiFi.d.ts CHANGED
@@ -1,21 +1,21 @@
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';
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
2
  import type { Hash, PublicClient } from 'viem';
3
3
  import type { ApproveTokenRequest, RevokeApprovalRequest, TokenAllowance, TokenSpender } from './allowance';
4
4
  import { RouteExecutionManager } from './execution/RouteExecutionManager';
5
- import type { Config, ConfigUpdate } from './types';
5
+ import type { SDKConfig, SDKOptions } from './types';
6
6
  export declare class LiFi extends RouteExecutionManager {
7
7
  private chainsService;
8
- constructor(configUpdate: ConfigUpdate);
8
+ constructor(options: SDKOptions);
9
9
  /**
10
10
  * Get the current configuration of the SDK
11
11
  * @returns - The config object
12
12
  */
13
- getConfig: () => Config;
13
+ getConfig: () => SDKConfig;
14
14
  /**
15
15
  * Get the SDK configuration after all setup calls are finished
16
16
  * @returns - The config object
17
17
  */
18
- getConfigAsync: () => Promise<Config>;
18
+ getConfigAsync: () => Promise<SDKConfig>;
19
19
  /**
20
20
  * Get an instance of a provider for a specific chain
21
21
  * @param chainId - Id of the chain the provider is for
@@ -27,11 +27,11 @@ export declare class LiFi extends RouteExecutionManager {
27
27
  * @param configUpdate - An object containing the configuration fields that should be updated.
28
28
  * @returns The renewed config object
29
29
  */
30
- setConfig: (configUpdate: Partial<ConfigUpdate>) => Config;
30
+ setConfig: (configUpdate: Partial<SDKOptions>) => SDKConfig;
31
31
  /**
32
32
  * Get a set of current possibilities based on a request that specifies which chains, exchanges and bridges are preferred or unwanted.
33
33
  * @param request - Object defining preferences regarding chain, exchanges and bridges
34
- * @param options
34
+ * @param options - Request options
35
35
  * @returns Object listing current possibilities for any-to-any cross-chain-swaps based on the provided preferences.
36
36
  * @throws {LiFiError} Throws a LiFiError if request fails.
37
37
  * @deprecated We don't want to support this endpoint anymore in the future. /chains, /tools, /connections, and /tokens should be used instead
@@ -41,25 +41,27 @@ export declare class LiFi extends RouteExecutionManager {
41
41
  * Fetch information about a Token
42
42
  * @param chain - Id or key of the chain that contains the token
43
43
  * @param token - Address or symbol of the token on the requested chain
44
- * @param options
44
+ * @param options - Request options
45
45
  * @throws {LiFiError} - Throws a LiFiError if request fails
46
+ * @returns Token information
46
47
  */
47
48
  getToken: (chain: ChainKey | ChainId, token: string, options?: RequestOptions) => Promise<Token>;
48
49
  /**
49
50
  * Get a quote for a token transfer
50
51
  * @param request - The configuration of the requested quote
51
- * @param options
52
+ * @param options - Request options
52
53
  * @throws {LiFiError} - Throws a LiFiError if request fails
54
+ * @returns Quote for a token transfer
53
55
  */
54
- getQuote: (request: QuoteRequest, options?: RequestOptions) => Promise<LifiStep>;
56
+ getQuote: (request: QuoteRequest, options?: RequestOptions) => Promise<LiFiStep>;
55
57
  /**
56
58
  * Get a quote for a destination contract call
57
59
  * @param request - The configuration of the requested destination call
58
- * @param options
60
+ * @param options - Request options
59
61
  * @throws {LiFiError} - Throws a LiFiError if request fails
60
62
  * @returns - Returns step.
61
63
  */
62
- getContractCallQuote: (request: ContractCallQuoteRequest, options?: RequestOptions) => Promise<LifiStep>;
64
+ getContractCallQuote: (request: ContractCallQuoteRequest, options?: RequestOptions) => Promise<LiFiStep>;
63
65
  /**
64
66
  * Check the status of a transfer. For cross chain transfers, the "bridge" parameter is required.
65
67
  * @param request - Configuration of the requested status
@@ -71,14 +73,14 @@ export declare class LiFi extends RouteExecutionManager {
71
73
  /**
72
74
  * Get the available tools to bridge and swap tokens.
73
75
  * @param request - The configuration of the requested tools
74
- * @param options
76
+ * @param options - Request options
75
77
  * @returns The tools that are available on the requested chains
76
78
  */
77
79
  getTools: (request?: ToolsRequest, options?: RequestOptions) => Promise<ToolsResponse>;
78
80
  /**
79
81
  * Get all known tokens.
80
82
  * @param request - The configuration of the requested tokens
81
- * @param options
83
+ * @param options - Request options
82
84
  * @returns The tokens that are available on the requested chains
83
85
  */
84
86
  getTokens: (request?: TokensRequest, options?: RequestOptions) => Promise<TokensResponse>;
@@ -91,7 +93,7 @@ export declare class LiFi extends RouteExecutionManager {
91
93
  /**
92
94
  * Get a set of routes for a request that describes a transfer of tokens.
93
95
  * @param request - A description of the transfer.
94
- * @param options
96
+ * @param options - Request options
95
97
  * @returns The resulting routes that can be used to realize the described transfer of tokens.
96
98
  * @throws {LiFiError} Throws a LiFiError if request fails.
97
99
  */
@@ -99,16 +101,17 @@ export declare class LiFi extends RouteExecutionManager {
99
101
  /**
100
102
  * Get the transaction data for a single step of a route
101
103
  * @param step - The step object.
102
- * @param options
104
+ * @param options - Request options
103
105
  * @returns The step populated with the transaction data.
104
106
  * @throws {LiFiError} Throws a LiFiError if request fails.
105
107
  */
106
- getStepTransaction: (step: LifiStep, options?: RequestOptions) => Promise<LifiStep>;
108
+ getStepTransaction: (step: LiFiStep, options?: RequestOptions) => Promise<LiFiStep>;
107
109
  /**
108
110
  * Get gas recommendation for a certain chain
109
111
  * @param request - Configuration of the requested recommendation.
110
- * @param options
112
+ * @param options - Request options
111
113
  * @throws {LiFiError} Throws a LiFiError if request fails.
114
+ * @returns Gas recommendation response.
112
115
  */
113
116
  getGasRecommendation: (request: GasRecommendationRequest, options?: RequestOptions) => Promise<GasRecommendationResponse>;
114
117
  /**
@@ -144,24 +147,28 @@ export declare class LiFi extends RouteExecutionManager {
144
147
  * @param token - The token that should be checked
145
148
  * @param ownerAddress - The owner of the token
146
149
  * @param spenderAddress - The spender address that has to be approved
150
+ * @returns Returns allowance
147
151
  */
148
152
  getTokenAllowance: (token: Token, ownerAddress: string, spenderAddress: string) => Promise<bigint | undefined>;
149
153
  /**
150
- * Get the current allowance for a list of token / spender address pairs.
154
+ * Get the current allowance for a list of token/spender address pairs.
151
155
  * @param ownerAddress - The owner of the tokens
152
156
  * @param tokens - A list of token and spender address pairs
157
+ * @returns Returns array of tokens and their allowance
153
158
  */
154
159
  getTokenAllowanceMulticall: (ownerAddress: string, tokens: TokenSpender[]) => Promise<TokenAllowance[]>;
155
160
  /**
156
161
  * Set approval for a certain token and amount.
157
162
  * @param request - The approval request
163
+ * @returns Returns Hash or nothing
158
164
  */
159
- setTokenApproval: (request: ApproveTokenRequest) => Promise<Hash | void>;
165
+ setTokenApproval: (request: ApproveTokenRequest) => Promise<Hash | undefined>;
160
166
  /**
161
167
  * Revoke approval for a certain token.
162
168
  * @param request - The revoke request
169
+ * @returns Returns Hash or nothing
163
170
  */
164
- revokeTokenApproval: (request: RevokeApprovalRequest) => Promise<Hash | void>;
171
+ revokeTokenApproval: (request: RevokeApprovalRequest) => Promise<Hash | undefined>;
165
172
  /**
166
173
  * Get all the available connections for swap/bridging tokens
167
174
  * @param connectionRequest ConnectionsRequest
package/dist/LiFi.js CHANGED
@@ -9,8 +9,8 @@ import { isToken } from './typeguards';
9
9
  import { ValidationError } from './utils/errors';
10
10
  import { name, version } from './version';
11
11
  export class LiFi extends RouteExecutionManager {
12
- constructor(configUpdate) {
13
- super(configUpdate);
12
+ constructor(options) {
13
+ super(options);
14
14
  /**
15
15
  * Get the current configuration of the SDK
16
16
  * @returns - The config object
@@ -44,7 +44,7 @@ export class LiFi extends RouteExecutionManager {
44
44
  /**
45
45
  * Get a set of current possibilities based on a request that specifies which chains, exchanges and bridges are preferred or unwanted.
46
46
  * @param request - Object defining preferences regarding chain, exchanges and bridges
47
- * @param options
47
+ * @param options - Request options
48
48
  * @returns Object listing current possibilities for any-to-any cross-chain-swaps based on the provided preferences.
49
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
@@ -56,8 +56,9 @@ export class LiFi extends RouteExecutionManager {
56
56
  * Fetch information about a Token
57
57
  * @param chain - Id or key of the chain that contains the token
58
58
  * @param token - Address or symbol of the token on the requested chain
59
- * @param options
59
+ * @param options - Request options
60
60
  * @throws {LiFiError} - Throws a LiFiError if request fails
61
+ * @returns Token information
61
62
  */
62
63
  this.getToken = async (chain, token, options) => {
63
64
  return ApiService.getToken(chain, token, options);
@@ -65,8 +66,9 @@ export class LiFi extends RouteExecutionManager {
65
66
  /**
66
67
  * Get a quote for a token transfer
67
68
  * @param request - The configuration of the requested quote
68
- * @param options
69
+ * @param options - Request options
69
70
  * @throws {LiFiError} - Throws a LiFiError if request fails
71
+ * @returns Quote for a token transfer
70
72
  */
71
73
  this.getQuote = async (request, options) => {
72
74
  return ApiService.getQuote(request, options);
@@ -74,7 +76,7 @@ export class LiFi extends RouteExecutionManager {
74
76
  /**
75
77
  * Get a quote for a destination contract call
76
78
  * @param request - The configuration of the requested destination call
77
- * @param options
79
+ * @param options - Request options
78
80
  * @throws {LiFiError} - Throws a LiFiError if request fails
79
81
  * @returns - Returns step.
80
82
  */
@@ -94,7 +96,7 @@ export class LiFi extends RouteExecutionManager {
94
96
  /**
95
97
  * Get the available tools to bridge and swap tokens.
96
98
  * @param request - The configuration of the requested tools
97
- * @param options
99
+ * @param options - Request options
98
100
  * @returns The tools that are available on the requested chains
99
101
  */
100
102
  this.getTools = async (request, options) => {
@@ -103,7 +105,7 @@ export class LiFi extends RouteExecutionManager {
103
105
  /**
104
106
  * Get all known tokens.
105
107
  * @param request - The configuration of the requested tokens
106
- * @param options
108
+ * @param options - Request options
107
109
  * @returns The tokens that are available on the requested chains
108
110
  */
109
111
  this.getTokens = async (request, options) => {
@@ -120,7 +122,7 @@ export class LiFi extends RouteExecutionManager {
120
122
  /**
121
123
  * Get a set of routes for a request that describes a transfer of tokens.
122
124
  * @param request - A description of the transfer.
123
- * @param options
125
+ * @param options - Request options
124
126
  * @returns The resulting routes that can be used to realize the described transfer of tokens.
125
127
  * @throws {LiFiError} Throws a LiFiError if request fails.
126
128
  */
@@ -130,7 +132,7 @@ export class LiFi extends RouteExecutionManager {
130
132
  /**
131
133
  * Get the transaction data for a single step of a route
132
134
  * @param step - The step object.
133
- * @param options
135
+ * @param options - Request options
134
136
  * @returns The step populated with the transaction data.
135
137
  * @throws {LiFiError} Throws a LiFiError if request fails.
136
138
  */
@@ -140,8 +142,9 @@ export class LiFi extends RouteExecutionManager {
140
142
  /**
141
143
  * Get gas recommendation for a certain chain
142
144
  * @param request - Configuration of the requested recommendation.
143
- * @param options
145
+ * @param options - Request options
144
146
  * @throws {LiFiError} Throws a LiFiError if request fails.
147
+ * @returns Gas recommendation response.
145
148
  */
146
149
  this.getGasRecommendation = async (request, options) => {
147
150
  return ApiService.getGasRecommendation(request, options);
@@ -202,14 +205,16 @@ export class LiFi extends RouteExecutionManager {
202
205
  * @param token - The token that should be checked
203
206
  * @param ownerAddress - The owner of the token
204
207
  * @param spenderAddress - The spender address that has to be approved
208
+ * @returns Returns allowance
205
209
  */
206
210
  this.getTokenAllowance = async (token, ownerAddress, spenderAddress) => {
207
211
  return getTokenAllowance(token, ownerAddress, spenderAddress);
208
212
  };
209
213
  /**
210
- * Get the current allowance for a list of token / spender address pairs.
214
+ * Get the current allowance for a list of token/spender address pairs.
211
215
  * @param ownerAddress - The owner of the tokens
212
216
  * @param tokens - A list of token and spender address pairs
217
+ * @returns Returns array of tokens and their allowance
213
218
  */
214
219
  this.getTokenAllowanceMulticall = async (ownerAddress, tokens) => {
215
220
  return getTokenAllowanceMulticall(ownerAddress, tokens);
@@ -217,6 +222,7 @@ export class LiFi extends RouteExecutionManager {
217
222
  /**
218
223
  * Set approval for a certain token and amount.
219
224
  * @param request - The approval request
225
+ * @returns Returns Hash or nothing
220
226
  */
221
227
  this.setTokenApproval = (request) => {
222
228
  return setTokenAllowance(request);
@@ -224,6 +230,7 @@ export class LiFi extends RouteExecutionManager {
224
230
  /**
225
231
  * Revoke approval for a certain token.
226
232
  * @param request - The revoke request
233
+ * @returns Returns Hash or nothing
227
234
  */
228
235
  this.revokeTokenApproval = (request) => {
229
236
  return revokeTokenApproval(request);
@@ -241,6 +248,6 @@ export class LiFi extends RouteExecutionManager {
241
248
  this.chainsService.getChains().then((chains) => {
242
249
  this.configService.updateChains(chains);
243
250
  });
244
- checkPackageUpdates(name, version, configUpdate.disableVersionCheck);
251
+ checkPackageUpdates(name, version, options.disableVersionCheck);
245
252
  }
246
253
  }
@@ -1,5 +1,6 @@
1
1
  import type { Hash, WalletClient } from 'viem';
2
+ import type { InternalExecutionSettings } from '../execution/types';
2
3
  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 setAllowance: (walletClient: WalletClient, tokenAddress: string, contractAddress: string, amount: bigint, settings?: InternalExecutionSettings, returnPopulatedTransaction?: boolean) => Promise<Hash>;
4
5
  export declare const setTokenAllowance: ({ walletClient, token, spenderAddress, amount, infiniteApproval, }: ApproveTokenRequest) => Promise<Hash | undefined>;
5
6
  export declare const revokeTokenApproval: ({ walletClient, token, spenderAddress, }: RevokeApprovalRequest) => Promise<Hash | undefined>;
@@ -3,7 +3,7 @@ import { approveAbi } from '../types';
3
3
  import { getMaxPriorityFeePerGas } from '../utils';
4
4
  import { isNativeTokenAddress } from '../utils/utils';
5
5
  import { getAllowance } from './getAllowance';
6
- export const setAllowance = async (walletClient, tokenAddress, contractAddress, amount, returnPopulatedTransaction) => {
6
+ export const setAllowance = async (walletClient, tokenAddress, contractAddress, amount, settings, returnPopulatedTransaction) => {
7
7
  const data = encodeFunctionData({
8
8
  abi: approveAbi,
9
9
  functionName: 'approve',
@@ -13,15 +13,31 @@ export const setAllowance = async (walletClient, tokenAddress, contractAddress,
13
13
  return data;
14
14
  }
15
15
  const client = walletClient.extend(publicActions);
16
- let maxPriorityFeePerGas;
17
- if (walletClient.account?.type === 'local') {
18
- maxPriorityFeePerGas = await getMaxPriorityFeePerGas(client);
16
+ let transactionRequest = {
17
+ to: tokenAddress,
18
+ data,
19
+ maxPriorityFeePerGas: walletClient.account?.type === 'local'
20
+ ? await getMaxPriorityFeePerGas(client)
21
+ : undefined,
22
+ };
23
+ if (settings?.updateTransactionRequestHook) {
24
+ const customizedTransactionRequest = await settings.updateTransactionRequestHook({
25
+ requestType: 'approve',
26
+ ...transactionRequest,
27
+ });
28
+ transactionRequest = {
29
+ ...transactionRequest,
30
+ ...customizedTransactionRequest,
31
+ };
19
32
  }
20
33
  return client.sendTransaction({
21
- to: tokenAddress,
34
+ to: transactionRequest.to,
22
35
  account: walletClient.account,
23
- data,
24
- maxPriorityFeePerGas,
36
+ data: transactionRequest.data,
37
+ gas: transactionRequest.gas,
38
+ gasPrice: transactionRequest.gasPrice,
39
+ maxFeePerGas: transactionRequest.maxFeePerGas,
40
+ maxPriorityFeePerGas: transactionRequest.maxPriorityFeePerGas,
25
41
  chain: null,
26
42
  });
27
43
  };
@@ -1,21 +1,21 @@
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';
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
2
  import type { Hash, PublicClient } from 'viem';
3
3
  import type { ApproveTokenRequest, RevokeApprovalRequest, TokenAllowance, TokenSpender } from './allowance';
4
4
  import { RouteExecutionManager } from './execution/RouteExecutionManager';
5
- import type { Config, ConfigUpdate } from './types';
5
+ import type { SDKConfig, SDKOptions } from './types';
6
6
  export declare class LiFi extends RouteExecutionManager {
7
7
  private chainsService;
8
- constructor(configUpdate: ConfigUpdate);
8
+ constructor(options: SDKOptions);
9
9
  /**
10
10
  * Get the current configuration of the SDK
11
11
  * @returns - The config object
12
12
  */
13
- getConfig: () => Config;
13
+ getConfig: () => SDKConfig;
14
14
  /**
15
15
  * Get the SDK configuration after all setup calls are finished
16
16
  * @returns - The config object
17
17
  */
18
- getConfigAsync: () => Promise<Config>;
18
+ getConfigAsync: () => Promise<SDKConfig>;
19
19
  /**
20
20
  * Get an instance of a provider for a specific chain
21
21
  * @param chainId - Id of the chain the provider is for
@@ -27,11 +27,11 @@ export declare class LiFi extends RouteExecutionManager {
27
27
  * @param configUpdate - An object containing the configuration fields that should be updated.
28
28
  * @returns The renewed config object
29
29
  */
30
- setConfig: (configUpdate: Partial<ConfigUpdate>) => Config;
30
+ setConfig: (configUpdate: Partial<SDKOptions>) => SDKConfig;
31
31
  /**
32
32
  * Get a set of current possibilities based on a request that specifies which chains, exchanges and bridges are preferred or unwanted.
33
33
  * @param request - Object defining preferences regarding chain, exchanges and bridges
34
- * @param options
34
+ * @param options - Request options
35
35
  * @returns Object listing current possibilities for any-to-any cross-chain-swaps based on the provided preferences.
36
36
  * @throws {LiFiError} Throws a LiFiError if request fails.
37
37
  * @deprecated We don't want to support this endpoint anymore in the future. /chains, /tools, /connections, and /tokens should be used instead
@@ -41,25 +41,27 @@ export declare class LiFi extends RouteExecutionManager {
41
41
  * Fetch information about a Token
42
42
  * @param chain - Id or key of the chain that contains the token
43
43
  * @param token - Address or symbol of the token on the requested chain
44
- * @param options
44
+ * @param options - Request options
45
45
  * @throws {LiFiError} - Throws a LiFiError if request fails
46
+ * @returns Token information
46
47
  */
47
48
  getToken: (chain: ChainKey | ChainId, token: string, options?: RequestOptions) => Promise<Token>;
48
49
  /**
49
50
  * Get a quote for a token transfer
50
51
  * @param request - The configuration of the requested quote
51
- * @param options
52
+ * @param options - Request options
52
53
  * @throws {LiFiError} - Throws a LiFiError if request fails
54
+ * @returns Quote for a token transfer
53
55
  */
54
- getQuote: (request: QuoteRequest, options?: RequestOptions) => Promise<LifiStep>;
56
+ getQuote: (request: QuoteRequest, options?: RequestOptions) => Promise<LiFiStep>;
55
57
  /**
56
58
  * Get a quote for a destination contract call
57
59
  * @param request - The configuration of the requested destination call
58
- * @param options
60
+ * @param options - Request options
59
61
  * @throws {LiFiError} - Throws a LiFiError if request fails
60
62
  * @returns - Returns step.
61
63
  */
62
- getContractCallQuote: (request: ContractCallQuoteRequest, options?: RequestOptions) => Promise<LifiStep>;
64
+ getContractCallQuote: (request: ContractCallQuoteRequest, options?: RequestOptions) => Promise<LiFiStep>;
63
65
  /**
64
66
  * Check the status of a transfer. For cross chain transfers, the "bridge" parameter is required.
65
67
  * @param request - Configuration of the requested status
@@ -71,14 +73,14 @@ export declare class LiFi extends RouteExecutionManager {
71
73
  /**
72
74
  * Get the available tools to bridge and swap tokens.
73
75
  * @param request - The configuration of the requested tools
74
- * @param options
76
+ * @param options - Request options
75
77
  * @returns The tools that are available on the requested chains
76
78
  */
77
79
  getTools: (request?: ToolsRequest, options?: RequestOptions) => Promise<ToolsResponse>;
78
80
  /**
79
81
  * Get all known tokens.
80
82
  * @param request - The configuration of the requested tokens
81
- * @param options
83
+ * @param options - Request options
82
84
  * @returns The tokens that are available on the requested chains
83
85
  */
84
86
  getTokens: (request?: TokensRequest, options?: RequestOptions) => Promise<TokensResponse>;
@@ -91,7 +93,7 @@ export declare class LiFi extends RouteExecutionManager {
91
93
  /**
92
94
  * Get a set of routes for a request that describes a transfer of tokens.
93
95
  * @param request - A description of the transfer.
94
- * @param options
96
+ * @param options - Request options
95
97
  * @returns The resulting routes that can be used to realize the described transfer of tokens.
96
98
  * @throws {LiFiError} Throws a LiFiError if request fails.
97
99
  */
@@ -99,16 +101,17 @@ export declare class LiFi extends RouteExecutionManager {
99
101
  /**
100
102
  * Get the transaction data for a single step of a route
101
103
  * @param step - The step object.
102
- * @param options
104
+ * @param options - Request options
103
105
  * @returns The step populated with the transaction data.
104
106
  * @throws {LiFiError} Throws a LiFiError if request fails.
105
107
  */
106
- getStepTransaction: (step: LifiStep, options?: RequestOptions) => Promise<LifiStep>;
108
+ getStepTransaction: (step: LiFiStep, options?: RequestOptions) => Promise<LiFiStep>;
107
109
  /**
108
110
  * Get gas recommendation for a certain chain
109
111
  * @param request - Configuration of the requested recommendation.
110
- * @param options
112
+ * @param options - Request options
111
113
  * @throws {LiFiError} Throws a LiFiError if request fails.
114
+ * @returns Gas recommendation response.
112
115
  */
113
116
  getGasRecommendation: (request: GasRecommendationRequest, options?: RequestOptions) => Promise<GasRecommendationResponse>;
114
117
  /**
@@ -144,24 +147,28 @@ export declare class LiFi extends RouteExecutionManager {
144
147
  * @param token - The token that should be checked
145
148
  * @param ownerAddress - The owner of the token
146
149
  * @param spenderAddress - The spender address that has to be approved
150
+ * @returns Returns allowance
147
151
  */
148
152
  getTokenAllowance: (token: Token, ownerAddress: string, spenderAddress: string) => Promise<bigint | undefined>;
149
153
  /**
150
- * Get the current allowance for a list of token / spender address pairs.
154
+ * Get the current allowance for a list of token/spender address pairs.
151
155
  * @param ownerAddress - The owner of the tokens
152
156
  * @param tokens - A list of token and spender address pairs
157
+ * @returns Returns array of tokens and their allowance
153
158
  */
154
159
  getTokenAllowanceMulticall: (ownerAddress: string, tokens: TokenSpender[]) => Promise<TokenAllowance[]>;
155
160
  /**
156
161
  * Set approval for a certain token and amount.
157
162
  * @param request - The approval request
163
+ * @returns Returns Hash or nothing
158
164
  */
159
- setTokenApproval: (request: ApproveTokenRequest) => Promise<Hash | void>;
165
+ setTokenApproval: (request: ApproveTokenRequest) => Promise<Hash | undefined>;
160
166
  /**
161
167
  * Revoke approval for a certain token.
162
168
  * @param request - The revoke request
169
+ * @returns Returns Hash or nothing
163
170
  */
164
- revokeTokenApproval: (request: RevokeApprovalRequest) => Promise<Hash | void>;
171
+ revokeTokenApproval: (request: RevokeApprovalRequest) => Promise<Hash | undefined>;
165
172
  /**
166
173
  * Get all the available connections for swap/bridging tokens
167
174
  * @param connectionRequest ConnectionsRequest
package/dist/cjs/LiFi.js CHANGED
@@ -38,8 +38,8 @@ const typeguards_1 = require("./typeguards");
38
38
  const errors_1 = require("./utils/errors");
39
39
  const version_1 = require("./version");
40
40
  class LiFi extends RouteExecutionManager_1.RouteExecutionManager {
41
- constructor(configUpdate) {
42
- super(configUpdate);
41
+ constructor(options) {
42
+ super(options);
43
43
  /**
44
44
  * Get the current configuration of the SDK
45
45
  * @returns - The config object
@@ -73,7 +73,7 @@ class LiFi extends RouteExecutionManager_1.RouteExecutionManager {
73
73
  /**
74
74
  * Get a set of current possibilities based on a request that specifies which chains, exchanges and bridges are preferred or unwanted.
75
75
  * @param request - Object defining preferences regarding chain, exchanges and bridges
76
- * @param options
76
+ * @param options - Request options
77
77
  * @returns Object listing current possibilities for any-to-any cross-chain-swaps based on the provided preferences.
78
78
  * @throws {LiFiError} Throws a LiFiError if request fails.
79
79
  * @deprecated We don't want to support this endpoint anymore in the future. /chains, /tools, /connections, and /tokens should be used instead
@@ -85,8 +85,9 @@ class LiFi extends RouteExecutionManager_1.RouteExecutionManager {
85
85
  * Fetch information about a Token
86
86
  * @param chain - Id or key of the chain that contains the token
87
87
  * @param token - Address or symbol of the token on the requested chain
88
- * @param options
88
+ * @param options - Request options
89
89
  * @throws {LiFiError} - Throws a LiFiError if request fails
90
+ * @returns Token information
90
91
  */
91
92
  this.getToken = async (chain, token, options) => {
92
93
  return ApiService_1.default.getToken(chain, token, options);
@@ -94,8 +95,9 @@ class LiFi extends RouteExecutionManager_1.RouteExecutionManager {
94
95
  /**
95
96
  * Get a quote for a token transfer
96
97
  * @param request - The configuration of the requested quote
97
- * @param options
98
+ * @param options - Request options
98
99
  * @throws {LiFiError} - Throws a LiFiError if request fails
100
+ * @returns Quote for a token transfer
99
101
  */
100
102
  this.getQuote = async (request, options) => {
101
103
  return ApiService_1.default.getQuote(request, options);
@@ -103,7 +105,7 @@ class LiFi extends RouteExecutionManager_1.RouteExecutionManager {
103
105
  /**
104
106
  * Get a quote for a destination contract call
105
107
  * @param request - The configuration of the requested destination call
106
- * @param options
108
+ * @param options - Request options
107
109
  * @throws {LiFiError} - Throws a LiFiError if request fails
108
110
  * @returns - Returns step.
109
111
  */
@@ -123,7 +125,7 @@ class LiFi extends RouteExecutionManager_1.RouteExecutionManager {
123
125
  /**
124
126
  * Get the available tools to bridge and swap tokens.
125
127
  * @param request - The configuration of the requested tools
126
- * @param options
128
+ * @param options - Request options
127
129
  * @returns The tools that are available on the requested chains
128
130
  */
129
131
  this.getTools = async (request, options) => {
@@ -132,7 +134,7 @@ class LiFi extends RouteExecutionManager_1.RouteExecutionManager {
132
134
  /**
133
135
  * Get all known tokens.
134
136
  * @param request - The configuration of the requested tokens
135
- * @param options
137
+ * @param options - Request options
136
138
  * @returns The tokens that are available on the requested chains
137
139
  */
138
140
  this.getTokens = async (request, options) => {
@@ -149,7 +151,7 @@ class LiFi extends RouteExecutionManager_1.RouteExecutionManager {
149
151
  /**
150
152
  * Get a set of routes for a request that describes a transfer of tokens.
151
153
  * @param request - A description of the transfer.
152
- * @param options
154
+ * @param options - Request options
153
155
  * @returns The resulting routes that can be used to realize the described transfer of tokens.
154
156
  * @throws {LiFiError} Throws a LiFiError if request fails.
155
157
  */
@@ -159,7 +161,7 @@ class LiFi extends RouteExecutionManager_1.RouteExecutionManager {
159
161
  /**
160
162
  * Get the transaction data for a single step of a route
161
163
  * @param step - The step object.
162
- * @param options
164
+ * @param options - Request options
163
165
  * @returns The step populated with the transaction data.
164
166
  * @throws {LiFiError} Throws a LiFiError if request fails.
165
167
  */
@@ -169,8 +171,9 @@ class LiFi extends RouteExecutionManager_1.RouteExecutionManager {
169
171
  /**
170
172
  * Get gas recommendation for a certain chain
171
173
  * @param request - Configuration of the requested recommendation.
172
- * @param options
174
+ * @param options - Request options
173
175
  * @throws {LiFiError} Throws a LiFiError if request fails.
176
+ * @returns Gas recommendation response.
174
177
  */
175
178
  this.getGasRecommendation = async (request, options) => {
176
179
  return ApiService_1.default.getGasRecommendation(request, options);
@@ -231,14 +234,16 @@ class LiFi extends RouteExecutionManager_1.RouteExecutionManager {
231
234
  * @param token - The token that should be checked
232
235
  * @param ownerAddress - The owner of the token
233
236
  * @param spenderAddress - The spender address that has to be approved
237
+ * @returns Returns allowance
234
238
  */
235
239
  this.getTokenAllowance = async (token, ownerAddress, spenderAddress) => {
236
240
  return (0, allowance_1.getTokenAllowance)(token, ownerAddress, spenderAddress);
237
241
  };
238
242
  /**
239
- * Get the current allowance for a list of token / spender address pairs.
243
+ * Get the current allowance for a list of token/spender address pairs.
240
244
  * @param ownerAddress - The owner of the tokens
241
245
  * @param tokens - A list of token and spender address pairs
246
+ * @returns Returns array of tokens and their allowance
242
247
  */
243
248
  this.getTokenAllowanceMulticall = async (ownerAddress, tokens) => {
244
249
  return (0, allowance_1.getTokenAllowanceMulticall)(ownerAddress, tokens);
@@ -246,6 +251,7 @@ class LiFi extends RouteExecutionManager_1.RouteExecutionManager {
246
251
  /**
247
252
  * Set approval for a certain token and amount.
248
253
  * @param request - The approval request
254
+ * @returns Returns Hash or nothing
249
255
  */
250
256
  this.setTokenApproval = (request) => {
251
257
  return (0, allowance_1.setTokenAllowance)(request);
@@ -253,6 +259,7 @@ class LiFi extends RouteExecutionManager_1.RouteExecutionManager {
253
259
  /**
254
260
  * Revoke approval for a certain token.
255
261
  * @param request - The revoke request
262
+ * @returns Returns Hash or nothing
256
263
  */
257
264
  this.revokeTokenApproval = (request) => {
258
265
  return (0, allowance_1.revokeTokenApproval)(request);
@@ -270,7 +277,7 @@ class LiFi extends RouteExecutionManager_1.RouteExecutionManager {
270
277
  this.chainsService.getChains().then((chains) => {
271
278
  this.configService.updateChains(chains);
272
279
  });
273
- (0, helpers_1.checkPackageUpdates)(version_1.name, version_1.version, configUpdate.disableVersionCheck);
280
+ (0, helpers_1.checkPackageUpdates)(version_1.name, version_1.version, options.disableVersionCheck);
274
281
  }
275
282
  }
276
283
  exports.LiFi = LiFi;
@@ -1,5 +1,6 @@
1
1
  import type { Hash, WalletClient } from 'viem';
2
+ import type { InternalExecutionSettings } from '../execution/types';
2
3
  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 setAllowance: (walletClient: WalletClient, tokenAddress: string, contractAddress: string, amount: bigint, settings?: InternalExecutionSettings, returnPopulatedTransaction?: boolean) => Promise<Hash>;
4
5
  export declare const setTokenAllowance: ({ walletClient, token, spenderAddress, amount, infiniteApproval, }: ApproveTokenRequest) => Promise<Hash | undefined>;
5
6
  export declare const revokeTokenApproval: ({ walletClient, token, spenderAddress, }: RevokeApprovalRequest) => Promise<Hash | undefined>;