@sodax/sdk 0.0.1-rc.2 → 0.0.1-rc.4
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/README.md +2 -0
- package/dist/constants.d.ts +17 -32
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +67 -67
- package/dist/constants.js.map +1 -1
- package/dist/constants.test.js +3 -2
- package/dist/constants.test.js.map +1 -1
- package/dist/entities/Providers.d.ts +3 -10
- package/dist/entities/Providers.d.ts.map +1 -1
- package/dist/entities/Providers.js +2 -2
- package/dist/entities/Providers.js.map +1 -1
- package/dist/entities/Sodax.test.js +120 -104
- package/dist/entities/Sodax.test.js.map +1 -1
- package/dist/entities/cosmos/CWSpokeProvider.d.ts +2 -1
- package/dist/entities/cosmos/CWSpokeProvider.d.ts.map +1 -1
- package/dist/entities/cosmos/CWSpokeProvider.js.map +1 -1
- package/dist/entities/cosmos/CosmosWalletProvider.d.ts +2 -2
- package/dist/entities/cosmos/CosmosWalletProvider.d.ts.map +1 -1
- package/dist/entities/cosmos/CosmosWalletProvider.js +4 -4
- package/dist/entities/cosmos/CosmosWalletProvider.js.map +1 -1
- package/dist/entities/cosmos/InjectiveWalletProvider.d.ts +2 -2
- package/dist/entities/cosmos/InjectiveWalletProvider.d.ts.map +1 -1
- package/dist/entities/cosmos/InjectiveWalletProvider.js +4 -4
- package/dist/entities/cosmos/InjectiveWalletProvider.js.map +1 -1
- package/dist/entities/icon/IconSpokeProvider.d.ts +5 -3
- package/dist/entities/icon/IconSpokeProvider.d.ts.map +1 -1
- package/dist/entities/icon/IconSpokeProvider.js +4 -1
- package/dist/entities/icon/IconSpokeProvider.js.map +1 -1
- package/dist/entities/icon/index.d.ts +0 -1
- package/dist/entities/icon/index.d.ts.map +1 -1
- package/dist/entities/icon/index.js +0 -1
- package/dist/entities/icon/index.js.map +1 -1
- package/dist/entities/index.d.ts +0 -1
- package/dist/entities/index.d.ts.map +1 -1
- package/dist/entities/index.js +0 -1
- package/dist/entities/index.js.map +1 -1
- package/dist/entities/solana/SolanaWalletProvider.d.ts +3 -3
- package/dist/entities/solana/SolanaWalletProvider.d.ts.map +1 -1
- package/dist/entities/solana/SolanaWalletProvider.js +3 -3
- package/dist/entities/solana/SolanaWalletProvider.js.map +1 -1
- package/dist/entities/solana/utils/utils.js +2 -1
- package/dist/entities/solana/utils/utils.js.map +1 -1
- package/dist/entities/stellar/StellarSpokeProvider.d.ts +4 -11
- package/dist/entities/stellar/StellarSpokeProvider.d.ts.map +1 -1
- package/dist/entities/stellar/StellarSpokeProvider.js +27 -31
- package/dist/entities/stellar/StellarSpokeProvider.js.map +1 -1
- package/dist/entities/sui/SuiSpokeProvider.d.ts +6 -5
- package/dist/entities/sui/SuiSpokeProvider.d.ts.map +1 -1
- package/dist/entities/sui/SuiSpokeProvider.js +9 -7
- package/dist/entities/sui/SuiSpokeProvider.js.map +1 -1
- package/dist/guards.js +8 -8
- package/dist/guards.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/services/hub/EvmAssetManagerService.d.ts +2 -1
- package/dist/services/hub/EvmAssetManagerService.d.ts.map +1 -1
- package/dist/services/hub/EvmAssetManagerService.js.map +1 -1
- package/dist/services/hub/EvmVaultTokenService.d.ts.map +1 -1
- package/dist/services/hub/EvmVaultTokenService.js +4 -2
- package/dist/services/hub/EvmVaultTokenService.js.map +1 -1
- package/dist/services/hub/EvmWalletAbstraction.d.ts +2 -1
- package/dist/services/hub/EvmWalletAbstraction.d.ts.map +1 -1
- package/dist/services/hub/EvmWalletAbstraction.js.map +1 -1
- package/dist/services/intentRelay/IntentRelayApiService.d.ts +2 -1
- package/dist/services/intentRelay/IntentRelayApiService.d.ts.map +1 -1
- package/dist/services/intentRelay/IntentRelayApiService.js.map +1 -1
- package/dist/services/moneyMarket/MoneyMarketService.d.ts +267 -63
- package/dist/services/moneyMarket/MoneyMarketService.d.ts.map +1 -1
- package/dist/services/moneyMarket/MoneyMarketService.js +283 -73
- package/dist/services/moneyMarket/MoneyMarketService.js.map +1 -1
- package/dist/services/moneyMarket/MoneyMarketService.test.js +36 -19
- package/dist/services/moneyMarket/MoneyMarketService.test.js.map +1 -1
- package/dist/services/shared/Erc20Service.d.ts +6 -5
- package/dist/services/shared/Erc20Service.d.ts.map +1 -1
- package/dist/services/shared/Erc20Service.js +7 -6
- package/dist/services/shared/Erc20Service.js.map +1 -1
- package/dist/services/solver/SolverApiService.test.js +2 -1
- package/dist/services/solver/SolverApiService.test.js.map +1 -1
- package/dist/services/solver/SolverService.d.ts +138 -37
- package/dist/services/solver/SolverService.d.ts.map +1 -1
- package/dist/services/solver/SolverService.js +146 -41
- package/dist/services/solver/SolverService.js.map +1 -1
- package/dist/services/solver/SolverService.test.js +89 -143
- package/dist/services/solver/SolverService.test.js.map +1 -1
- package/dist/services/spoke/CWSpokeService.d.ts +1 -1
- package/dist/services/spoke/CWSpokeService.d.ts.map +1 -1
- package/dist/services/spoke/CWSpokeService.js +2 -2
- package/dist/services/spoke/CWSpokeService.js.map +1 -1
- package/dist/services/spoke/EvmSpokeService.d.ts +3 -2
- package/dist/services/spoke/EvmSpokeService.d.ts.map +1 -1
- package/dist/services/spoke/EvmSpokeService.js +4 -2
- package/dist/services/spoke/EvmSpokeService.js.map +1 -1
- package/dist/services/spoke/IconSpokeService.d.ts +4 -3
- package/dist/services/spoke/IconSpokeService.d.ts.map +1 -1
- package/dist/services/spoke/IconSpokeService.js +28 -15
- package/dist/services/spoke/IconSpokeService.js.map +1 -1
- package/dist/services/spoke/SolanaSpokeService.d.ts +3 -2
- package/dist/services/spoke/SolanaSpokeService.d.ts.map +1 -1
- package/dist/services/spoke/SolanaSpokeService.js.map +1 -1
- package/dist/services/spoke/SpokeService.d.ts +2 -1
- package/dist/services/spoke/SpokeService.d.ts.map +1 -1
- package/dist/services/spoke/SpokeService.js.map +1 -1
- package/dist/services/spoke/StellarSpokeService.d.ts +1 -1
- package/dist/services/spoke/StellarSpokeService.d.ts.map +1 -1
- package/dist/services/spoke/SuiSpokeService.d.ts +1 -1
- package/dist/services/spoke/SuiSpokeService.d.ts.map +1 -1
- package/dist/tests/services/hub/EvmAssetManagerService.test.js +45 -30
- package/dist/tests/services/hub/EvmAssetManagerService.test.js.map +1 -1
- package/dist/tests/services/spoke/EvmSpokeService.test.js +7 -6
- package/dist/tests/services/spoke/EvmSpokeService.test.js.map +1 -1
- package/dist/types.d.ts +28 -71
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/evm-utils.d.ts +2 -2
- package/dist/utils/evm-utils.d.ts.map +1 -1
- package/dist/utils/shared-utils.d.ts +2 -1
- package/dist/utils/shared-utils.d.ts.map +1 -1
- package/dist/utils/shared-utils.js +3 -0
- package/dist/utils/shared-utils.js.map +1 -1
- package/package.json +3 -3
- package/dist/entities/icon/IconWalletProvider.d.ts +0 -12
- package/dist/entities/icon/IconWalletProvider.d.ts.map +0 -1
- package/dist/entities/icon/IconWalletProvider.js +0 -34
- package/dist/entities/icon/IconWalletProvider.js.map +0 -1
- package/dist/entities/sui/SuiWalletProvider.d.ts +0 -15
- package/dist/entities/sui/SuiWalletProvider.d.ts.map +0 -1
- package/dist/entities/sui/SuiWalletProvider.js +0 -43
- package/dist/entities/sui/SuiWalletProvider.js.map +0 -1
- package/dist/interfaces.d.ts +0 -8
- package/dist/interfaces.d.ts.map +0 -1
- package/dist/interfaces.js +0 -2
- package/dist/interfaces.js.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type EvmHubProvider, type IntentRelayRequest, type PacketData, type RelayErrorCode, type SpokeProvider, type WaitUntilIntentExecutedPayload } from '../../index.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { FeeAmount, HttpUrl, IntentErrorResponse, IntentExecutionRequest, IntentExecutionResponse, IntentQuoteRequest, IntentQuoteResponse, IntentRelayChainId, IntentStatusRequest, IntentStatusResponse, PartnerFee, Result, SolverConfigParams, TxReturnType } from '../../types.js';
|
|
3
|
+
import { type SpokeChainId, type Address, type Hex, type EvmRawTransactionReceipt, type Hash } from '@sodax/types';
|
|
3
4
|
export type CreateIntentParams = {
|
|
4
5
|
inputToken: string;
|
|
5
6
|
outputToken: string;
|
|
@@ -75,25 +76,33 @@ export declare class SolverService {
|
|
|
75
76
|
* @returns {Promise<Result<IntentQuoteResponse, IntentErrorResponse>>} The intent quote response
|
|
76
77
|
*
|
|
77
78
|
* @example
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* "
|
|
81
|
-
* "
|
|
82
|
-
* "
|
|
83
|
-
* "token_dst_blockchain_id":"42161",
|
|
79
|
+
* const payload = {
|
|
80
|
+
* "token_src":"0x2170Ed0880ac9A755fd29B2688956BD959F933F8", // BSC ETH token address
|
|
81
|
+
* "token_dst":"0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f", // ARB WBTC token address
|
|
82
|
+
* "token_src_blockchain_id":"0x38.bsc",
|
|
83
|
+
* "token_dst_blockchain_id":"0xa4b1.arbitrum",
|
|
84
84
|
* "amount":1000000000000000n,
|
|
85
85
|
* "quote_type": "exact_input"
|
|
86
86
|
* } satisfies IntentQuoteRequest
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
87
|
+
*
|
|
88
|
+
* const response = await solverService.getQuote(payload);
|
|
89
|
+
*
|
|
90
|
+
* if (response.ok) {
|
|
91
|
+
* const quotedAmount = response.value.quoted_amount;
|
|
92
|
+
* console.log('Quoted amount:', quotedAmount);
|
|
93
|
+
* } else {
|
|
94
|
+
* console.error('Quote failed:', response.error);
|
|
95
|
+
* }
|
|
91
96
|
*/
|
|
92
97
|
getQuote(payload: IntentQuoteRequest): Promise<Result<IntentQuoteResponse, IntentErrorResponse>>;
|
|
93
98
|
/**
|
|
94
99
|
* Get the fee for a given input amount
|
|
95
100
|
* @param {bigint} inputAmount - The amount of input tokens
|
|
96
101
|
* @returns {Promise<bigint>} The fee amount (denominated in input tokens)
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* const fee: bigint = await solverService.getFee(1000000000000000n);
|
|
105
|
+
* console.log('Fee:', fee);
|
|
97
106
|
*/
|
|
98
107
|
getFee(inputAmount: bigint): Promise<bigint>;
|
|
99
108
|
/**
|
|
@@ -102,38 +111,39 @@ export declare class SolverService {
|
|
|
102
111
|
* @returns {Promise<Result<IntentStatusResponse, IntentErrorResponse>>} The intent status response
|
|
103
112
|
*
|
|
104
113
|
* @example
|
|
105
|
-
*
|
|
106
|
-
* {
|
|
114
|
+
* const intentStatusRequest = {
|
|
107
115
|
* "intentHash": "a0dd7652-b360-4123-ab2d-78cfbcd20c6b"
|
|
108
|
-
* }
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
116
|
+
* } satisfies IntentStatusRequest
|
|
117
|
+
*
|
|
118
|
+
* const response = await solverService.getStatus(intentStatusRequest);
|
|
119
|
+
*
|
|
120
|
+
* if (response.ok) {
|
|
121
|
+
* const { status, intent_hash } = response.value;
|
|
122
|
+
* console.log('Status:', status);
|
|
123
|
+
* console.log('Intent hash:', intent_hash);
|
|
124
|
+
* } else {
|
|
125
|
+
* // handle error
|
|
113
126
|
* }
|
|
114
127
|
*/
|
|
115
128
|
getStatus(intentStatusRequest: IntentStatusRequest): Promise<Result<IntentStatusResponse, IntentErrorResponse>>;
|
|
116
129
|
/**
|
|
117
|
-
* Post execution of intent order to Solver API
|
|
130
|
+
* Post execution of intent order transaction executed on hub chain to Solver API
|
|
118
131
|
* @param {IntentExecutionRequest} intentExecutionRequest - The intent execution request
|
|
119
132
|
* @returns {Promise<Result<IntentExecutionResponse, IntentErrorResponse>>} The intent execution response
|
|
120
133
|
*
|
|
121
134
|
* @example
|
|
122
|
-
*
|
|
123
|
-
* {
|
|
135
|
+
* const intentExecutionRequest = {
|
|
124
136
|
* "intent_tx_hash": "0xba3dce19347264db32ced212ff1a2036f20d9d2c7493d06af15027970be061af",
|
|
125
|
-
*
|
|
126
|
-
*
|
|
137
|
+
* } satisfies IntentExecutionRequest
|
|
138
|
+
*
|
|
139
|
+
* const response = await solverService.postExecution(intentExecutionRequest);
|
|
127
140
|
*
|
|
128
|
-
*
|
|
129
|
-
* {
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* "task_id":"a0dd7652-b360-4123-ab2d-78cfbcd20c6b"
|
|
135
|
-
* }
|
|
136
|
-
* }
|
|
141
|
+
* if (response.ok) {
|
|
142
|
+
* const { answer, intent_hash } = response.value;
|
|
143
|
+
* console.log('Answer:', answer);
|
|
144
|
+
* console.log('Intent hash:', intent_hash);
|
|
145
|
+
* } else {
|
|
146
|
+
* // handle error
|
|
137
147
|
* }
|
|
138
148
|
*/
|
|
139
149
|
postExecution(intentExecutionRequest: IntentExecutionRequest): Promise<Result<IntentExecutionResponse, IntentErrorResponse>>;
|
|
@@ -141,8 +151,35 @@ export declare class SolverService {
|
|
|
141
151
|
* Creates an intent and submits it to the Solver API and Relayer API
|
|
142
152
|
* @param {CreateIntentParams} payload - The intent to create
|
|
143
153
|
* @param {ISpokeProvider} spokeProvider - The spoke provider
|
|
144
|
-
* @param {number} timeout - The timeout in milliseconds for the transaction. Default is
|
|
145
|
-
* @returns {Promise<Result<IntentExecutionResponse,
|
|
154
|
+
* @param {number} timeout - The timeout in milliseconds for the transaction. Default is 60 seconds.
|
|
155
|
+
* @returns {Promise<Result<[IntentExecutionResponse, Intent, PacketData], IntentSubmitError<IntentSubmitErrorCode>>>} The intent execution response, intent, and packet data
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* const payload = {
|
|
159
|
+
* "inputToken": "0x2170Ed0880ac9A755fd29B2688956BD959F933F8", // BSC ETH token address
|
|
160
|
+
* "outputToken": "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f", // ARB WBTC token address
|
|
161
|
+
* "inputAmount": 1000000000000000n, // The amount of input tokens
|
|
162
|
+
* "minOutputAmount": 900000000000000n, // min amount you are expecting to receive
|
|
163
|
+
* "deadline": 0n, // Optional timestamp after which intent expires (0 = no deadline)
|
|
164
|
+
* "allowPartialFill": false, // Whether the intent can be partially filled
|
|
165
|
+
* "srcChain": "0x38.bsc", // Chain ID where input tokens originate
|
|
166
|
+
* "dstChain": "0xa4b1.arbitrum", // Chain ID where output tokens should be delivered
|
|
167
|
+
* "srcAddress": "0x..", // Source address in bytes (original address on spoke chain)
|
|
168
|
+
* "dstAddress": "0x...", // Destination address in bytes (original address on spoke chain)
|
|
169
|
+
* "solver": "0x..", // Optional specific solver address (address(0) = any solver)
|
|
170
|
+
* "data": "0x..", // Additional arbitrary data
|
|
171
|
+
* } satisfies CreateIntentParams;
|
|
172
|
+
*
|
|
173
|
+
* const createAndSubmitIntentResult = await solverService.createAndSubmitIntent(payload, spokeProvider);
|
|
174
|
+
*
|
|
175
|
+
* if (createAndSubmitIntentResult.ok) {
|
|
176
|
+
* const [intentExecutionResponse, intent, packetData] = createAndSubmitIntentResult.value;
|
|
177
|
+
* console.log('Intent execution response:', intentExecutionResponse);
|
|
178
|
+
* console.log('Intent:', intent);
|
|
179
|
+
* console.log('Packet data:', packetData);
|
|
180
|
+
* } else {
|
|
181
|
+
* // handle error
|
|
182
|
+
* }
|
|
146
183
|
*/
|
|
147
184
|
createAndSubmitIntent<S extends SpokeProvider>(payload: CreateIntentParams, spokeProvider: S, fee?: PartnerFee, timeout?: number): Promise<Result<[IntentExecutionResponse, Intent, PacketData], IntentSubmitError<IntentSubmitErrorCode>>>;
|
|
148
185
|
/**
|
|
@@ -150,14 +187,55 @@ export declare class SolverService {
|
|
|
150
187
|
* @param {CreateIntentParams} params - The intent to create
|
|
151
188
|
* @param {SpokeProvider} spokeProvider - The spoke provider
|
|
152
189
|
* @return {Promise<Result<boolean>>} - valid = true, invalid = false
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* const payload = {
|
|
193
|
+
* "inputToken": "0x2170Ed0880ac9A755fd29B2688956BD959F933F8", // BSC ETH token address
|
|
194
|
+
* "outputToken": "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f", // ARB WBTC token address
|
|
195
|
+
* "inputAmount": 1000000000000000n, // The amount of input tokens
|
|
196
|
+
* "minOutputAmount": 900000000000000n, // min amount you are expecting to receive
|
|
197
|
+
* "deadline": 0n, // Optional timestamp after which intent expires (0 = no deadline)
|
|
198
|
+
* "allowPartialFill": false, // Whether the intent can be partially filled
|
|
199
|
+
* "srcChain": "0x38.bsc", // Chain ID where input tokens originate
|
|
200
|
+
* "dstChain": "0xa4b1.arbitrum", // Chain ID where output tokens should be delivered
|
|
201
|
+
* "srcAddress": "0x..", // Source address in bytes (original address on spoke chain)
|
|
202
|
+
* "dstAddress": "0x...", // Destination address in bytes (original address on spoke chain)
|
|
203
|
+
* "solver": "0x..", // Optional specific solver address (address(0) = any solver)
|
|
204
|
+
* "data": "0x..", // Additional arbitrary data
|
|
205
|
+
* } satisfies CreateIntentParams;
|
|
206
|
+
*
|
|
207
|
+
* const isAllowanceValid = await solverService.isAllowanceValid(payload, spokeProvider);
|
|
208
|
+
*
|
|
209
|
+
* if (!allowanceValid.ok) {
|
|
210
|
+
* // Handle error
|
|
211
|
+
* }
|
|
212
|
+
*
|
|
213
|
+
* if (!allowanceValid.value) {
|
|
214
|
+
* // Need to approve
|
|
215
|
+
* }
|
|
153
216
|
*/
|
|
154
217
|
isAllowanceValid<S extends SpokeProvider>(params: CreateIntentParams, spokeProvider: S): Promise<Result<boolean>>;
|
|
155
218
|
/**
|
|
156
|
-
* Approve
|
|
219
|
+
* Approve amount spending (currently required for EVM only)
|
|
157
220
|
* @param token - ERC20 token address
|
|
158
221
|
* @param amount - Amount to approve
|
|
159
|
-
* @param
|
|
222
|
+
* @param spender - Spender address
|
|
160
223
|
* @param spokeProvider - Spoke provider
|
|
224
|
+
* @returns {Promise<Result<EvmRawTransactionReceipt>>} - Returns the transaction receipt
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* const approveResult = await approve(
|
|
228
|
+
* '0x...', // ERC20 token address
|
|
229
|
+
* 1000n, // Amount to approve (in token decimals)
|
|
230
|
+
* '0x...', // Spender address (usually the asset manager contract: spokeProvider.chainConfig.addresses.assetManager)
|
|
231
|
+
* spokeProvider
|
|
232
|
+
* );
|
|
233
|
+
*
|
|
234
|
+
* if (!approveResult.ok) {
|
|
235
|
+
* // Handle error
|
|
236
|
+
* }
|
|
237
|
+
*
|
|
238
|
+
* const txReceipt = approveResult.value;
|
|
161
239
|
*/
|
|
162
240
|
approve<S extends SpokeProvider>(token: Address, amount: bigint, address: Address, spokeProvider: S): Promise<Result<EvmRawTransactionReceipt>>;
|
|
163
241
|
/**
|
|
@@ -167,7 +245,30 @@ export declare class SolverService {
|
|
|
167
245
|
* @param {SpokeProvider} spokeProvider - The spoke provider
|
|
168
246
|
* @param {boolean} raw - Whether to return the raw transaction
|
|
169
247
|
* @param {PartnerFee} fee - The fee to apply to the intent
|
|
170
|
-
* @returns {Promise<[TxReturnType<
|
|
248
|
+
* @returns {Promise<Result<[TxReturnType<S, R>, Intent & FeeAmount], IntentSubmitError<'CREATION_FAILED'>>>} The encoded contract call
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* const payload = {
|
|
252
|
+
* "inputToken": "0x2170Ed0880ac9A755fd29B2688956BD959F933F8", // BSC ETH token address
|
|
253
|
+
* "outputToken": "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f", // ARB WBTC token address
|
|
254
|
+
* "inputAmount": 1000000000000000n, // The amount of input tokens
|
|
255
|
+
* "minOutputAmount": 900000000000000n, // min amount you are expecting to receive
|
|
256
|
+
* "deadline": 0n, // Optional timestamp after which intent expires (0 = no deadline)
|
|
257
|
+
* "allowPartialFill": false, // Whether the intent can be partially filled
|
|
258
|
+
* "srcChain": "0x38.bsc", // Chain ID where input tokens originate
|
|
259
|
+
* "dstChain": "0xa4b1.arbitrum", // Chain ID where output tokens should be delivered
|
|
260
|
+
* "srcAddress": "0x..", // Source address in bytes (original address on spoke chain)
|
|
261
|
+
* "dstAddress": "0x...", // Destination address in bytes (original address on spoke chain)
|
|
262
|
+
* "solver": "0x..", // Optional specific solver address (address(0) = any solver)
|
|
263
|
+
* "data": "0x..", // Additional arbitrary data
|
|
264
|
+
* } satisfies CreateIntentParams;
|
|
265
|
+
*
|
|
266
|
+
* const createIntentResult = await solverService.createIntent(payload, spokeProvider);
|
|
267
|
+
*
|
|
268
|
+
* if (createIntentResult.ok) {
|
|
269
|
+
* const [txResult, intent] = createIntentResult.value;
|
|
270
|
+
* console.log('Intent:', intent);
|
|
271
|
+
*
|
|
171
272
|
*/
|
|
172
273
|
createIntent<S extends SpokeProvider, R extends boolean = false>(params: CreateIntentParams, spokeProvider: S, fee?: PartnerFee, raw?: R): Promise<Result<[TxReturnType<S, R>, Intent & FeeAmount], IntentSubmitError<'CREATION_FAILED'>>>;
|
|
173
274
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolverService.d.ts","sourceRoot":"","sources":["../../../src/services/solver/SolverService.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,cAAc,EAEnB,KAAK,kBAAkB,EACvB,KAAK,UAAU,EACf,KAAK,cAAc,
|
|
1
|
+
{"version":3,"file":"SolverService.d.ts","sourceRoot":"","sources":["../../../src/services/solver/SolverService.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,cAAc,EAEnB,KAAK,kBAAkB,EACvB,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,aAAa,EAElB,KAAK,8BAA8B,EAWpC,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAEV,SAAS,EAET,OAAO,EACP,mBAAmB,EACnB,sBAAsB,EACtB,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,E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AC,GACf,OAAO,CAAC,MAAM,CAAC,wBAAwB,CAAC,CAAC;IAkB5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACU,YAAY,CAAC,CAAC,SAAS,aAAa,EAAE,CAAC,SAAS,OAAO,GAAG,KAAK,EAC1E,MAAM,EAAE,kBAAkB,EAC1B,aAAa,EAAE,CAAC,EAChB,GAAG,CAAC,EAAE,UAAU,EAChB,GAAG,CAAC,EAAE,CAAC,GACN,OAAO,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,EAAE,iBAAiB,CAAC,iBAAiB,CAAC,CAAC,CAAC;IA6DlG;;;;;;OAMG;IACU,YAAY,CAAC,CAAC,SAAS,aAAa,EAAE,CAAC,SAAS,OAAO,GAAG,KAAK,EAC1E,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,CAAC,EAChB,GAAG,CAAC,EAAE,CAAC,GACN,OAAO,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAmB9B;;;;OAIG;IACI,SAAS,CAAC,MAAM,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC;IAI/C;;;;OAIG;IACI,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG;CAG1C"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import invariant from 'tiny-invariant';
|
|
2
|
-
import { DEFAULT_RELAYER_API_ENDPOINT, DEFAULT_RELAY_TX_TIMEOUT, Erc20Service, EvmSpokeProvider,
|
|
2
|
+
import { DEFAULT_RELAYER_API_ENDPOINT, DEFAULT_RELAY_TX_TIMEOUT, Erc20Service, EvmSpokeProvider, SpokeService, calculateFeeAmount, encodeContractCalls, getIntentRelayChainId, getSolverConfig, isConfiguredSolverConfig, isValidIntentRelayChainId, isValidOriginalAssetAddress, isValidSpokeChainId, submitTransaction, waitUntilIntentExecuted, } from '../../index.js';
|
|
3
3
|
import { EvmWalletAbstraction } from '../hub/EvmWalletAbstraction.js';
|
|
4
4
|
import { EvmSolverService } from './EvmSolverService.js';
|
|
5
5
|
import { SolverApiService } from './SolverApiService.js';
|
|
6
|
+
import { SONIC_MAINNET_CHAIN_ID, } from '@sodax/types';
|
|
6
7
|
// Data types for arbitrary data
|
|
7
8
|
export var IntentDataType;
|
|
8
9
|
(function (IntentDataType) {
|
|
@@ -42,19 +43,23 @@ export class SolverService {
|
|
|
42
43
|
* @returns {Promise<Result<IntentQuoteResponse, IntentErrorResponse>>} The intent quote response
|
|
43
44
|
*
|
|
44
45
|
* @example
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* "
|
|
48
|
-
* "
|
|
49
|
-
* "
|
|
50
|
-
* "token_dst_blockchain_id":"42161",
|
|
46
|
+
* const payload = {
|
|
47
|
+
* "token_src":"0x2170Ed0880ac9A755fd29B2688956BD959F933F8", // BSC ETH token address
|
|
48
|
+
* "token_dst":"0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f", // ARB WBTC token address
|
|
49
|
+
* "token_src_blockchain_id":"0x38.bsc",
|
|
50
|
+
* "token_dst_blockchain_id":"0xa4b1.arbitrum",
|
|
51
51
|
* "amount":1000000000000000n,
|
|
52
52
|
* "quote_type": "exact_input"
|
|
53
53
|
* } satisfies IntentQuoteRequest
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
54
|
+
*
|
|
55
|
+
* const response = await solverService.getQuote(payload);
|
|
56
|
+
*
|
|
57
|
+
* if (response.ok) {
|
|
58
|
+
* const quotedAmount = response.value.quoted_amount;
|
|
59
|
+
* console.log('Quoted amount:', quotedAmount);
|
|
60
|
+
* } else {
|
|
61
|
+
* console.error('Quote failed:', response.error);
|
|
62
|
+
* }
|
|
58
63
|
*/
|
|
59
64
|
async getQuote(payload) {
|
|
60
65
|
return SolverApiService.getQuote(payload, this.config);
|
|
@@ -63,6 +68,10 @@ export class SolverService {
|
|
|
63
68
|
* Get the fee for a given input amount
|
|
64
69
|
* @param {bigint} inputAmount - The amount of input tokens
|
|
65
70
|
* @returns {Promise<bigint>} The fee amount (denominated in input tokens)
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* const fee: bigint = await solverService.getFee(1000000000000000n);
|
|
74
|
+
* console.log('Fee:', fee);
|
|
66
75
|
*/
|
|
67
76
|
async getFee(inputAmount) {
|
|
68
77
|
if (!this.config.partnerFee) {
|
|
@@ -76,40 +85,41 @@ export class SolverService {
|
|
|
76
85
|
* @returns {Promise<Result<IntentStatusResponse, IntentErrorResponse>>} The intent status response
|
|
77
86
|
*
|
|
78
87
|
* @example
|
|
79
|
-
*
|
|
80
|
-
* {
|
|
88
|
+
* const intentStatusRequest = {
|
|
81
89
|
* "intentHash": "a0dd7652-b360-4123-ab2d-78cfbcd20c6b"
|
|
82
|
-
* }
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
90
|
+
* } satisfies IntentStatusRequest
|
|
91
|
+
*
|
|
92
|
+
* const response = await solverService.getStatus(intentStatusRequest);
|
|
93
|
+
*
|
|
94
|
+
* if (response.ok) {
|
|
95
|
+
* const { status, intent_hash } = response.value;
|
|
96
|
+
* console.log('Status:', status);
|
|
97
|
+
* console.log('Intent hash:', intent_hash);
|
|
98
|
+
* } else {
|
|
99
|
+
* // handle error
|
|
87
100
|
* }
|
|
88
101
|
*/
|
|
89
102
|
async getStatus(intentStatusRequest) {
|
|
90
103
|
return SolverApiService.getStatus(intentStatusRequest, this.config);
|
|
91
104
|
}
|
|
92
105
|
/**
|
|
93
|
-
* Post execution of intent order to Solver API
|
|
106
|
+
* Post execution of intent order transaction executed on hub chain to Solver API
|
|
94
107
|
* @param {IntentExecutionRequest} intentExecutionRequest - The intent execution request
|
|
95
108
|
* @returns {Promise<Result<IntentExecutionResponse, IntentErrorResponse>>} The intent execution response
|
|
96
109
|
*
|
|
97
110
|
* @example
|
|
98
|
-
*
|
|
99
|
-
* {
|
|
111
|
+
* const intentExecutionRequest = {
|
|
100
112
|
* "intent_tx_hash": "0xba3dce19347264db32ced212ff1a2036f20d9d2c7493d06af15027970be061af",
|
|
101
|
-
*
|
|
102
|
-
*
|
|
113
|
+
* } satisfies IntentExecutionRequest
|
|
114
|
+
*
|
|
115
|
+
* const response = await solverService.postExecution(intentExecutionRequest);
|
|
103
116
|
*
|
|
104
|
-
*
|
|
105
|
-
* {
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
* "task_id":"a0dd7652-b360-4123-ab2d-78cfbcd20c6b"
|
|
111
|
-
* }
|
|
112
|
-
* }
|
|
117
|
+
* if (response.ok) {
|
|
118
|
+
* const { answer, intent_hash } = response.value;
|
|
119
|
+
* console.log('Answer:', answer);
|
|
120
|
+
* console.log('Intent hash:', intent_hash);
|
|
121
|
+
* } else {
|
|
122
|
+
* // handle error
|
|
113
123
|
* }
|
|
114
124
|
*/
|
|
115
125
|
async postExecution(intentExecutionRequest) {
|
|
@@ -119,8 +129,35 @@ export class SolverService {
|
|
|
119
129
|
* Creates an intent and submits it to the Solver API and Relayer API
|
|
120
130
|
* @param {CreateIntentParams} payload - The intent to create
|
|
121
131
|
* @param {ISpokeProvider} spokeProvider - The spoke provider
|
|
122
|
-
* @param {number} timeout - The timeout in milliseconds for the transaction. Default is
|
|
123
|
-
* @returns {Promise<Result<IntentExecutionResponse,
|
|
132
|
+
* @param {number} timeout - The timeout in milliseconds for the transaction. Default is 60 seconds.
|
|
133
|
+
* @returns {Promise<Result<[IntentExecutionResponse, Intent, PacketData], IntentSubmitError<IntentSubmitErrorCode>>>} The intent execution response, intent, and packet data
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* const payload = {
|
|
137
|
+
* "inputToken": "0x2170Ed0880ac9A755fd29B2688956BD959F933F8", // BSC ETH token address
|
|
138
|
+
* "outputToken": "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f", // ARB WBTC token address
|
|
139
|
+
* "inputAmount": 1000000000000000n, // The amount of input tokens
|
|
140
|
+
* "minOutputAmount": 900000000000000n, // min amount you are expecting to receive
|
|
141
|
+
* "deadline": 0n, // Optional timestamp after which intent expires (0 = no deadline)
|
|
142
|
+
* "allowPartialFill": false, // Whether the intent can be partially filled
|
|
143
|
+
* "srcChain": "0x38.bsc", // Chain ID where input tokens originate
|
|
144
|
+
* "dstChain": "0xa4b1.arbitrum", // Chain ID where output tokens should be delivered
|
|
145
|
+
* "srcAddress": "0x..", // Source address in bytes (original address on spoke chain)
|
|
146
|
+
* "dstAddress": "0x...", // Destination address in bytes (original address on spoke chain)
|
|
147
|
+
* "solver": "0x..", // Optional specific solver address (address(0) = any solver)
|
|
148
|
+
* "data": "0x..", // Additional arbitrary data
|
|
149
|
+
* } satisfies CreateIntentParams;
|
|
150
|
+
*
|
|
151
|
+
* const createAndSubmitIntentResult = await solverService.createAndSubmitIntent(payload, spokeProvider);
|
|
152
|
+
*
|
|
153
|
+
* if (createAndSubmitIntentResult.ok) {
|
|
154
|
+
* const [intentExecutionResponse, intent, packetData] = createAndSubmitIntentResult.value;
|
|
155
|
+
* console.log('Intent execution response:', intentExecutionResponse);
|
|
156
|
+
* console.log('Intent:', intent);
|
|
157
|
+
* console.log('Packet data:', packetData);
|
|
158
|
+
* } else {
|
|
159
|
+
* // handle error
|
|
160
|
+
* }
|
|
124
161
|
*/
|
|
125
162
|
async createAndSubmitIntent(payload, spokeProvider, fee, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
|
|
126
163
|
try {
|
|
@@ -200,11 +237,38 @@ export class SolverService {
|
|
|
200
237
|
* @param {CreateIntentParams} params - The intent to create
|
|
201
238
|
* @param {SpokeProvider} spokeProvider - The spoke provider
|
|
202
239
|
* @return {Promise<Result<boolean>>} - valid = true, invalid = false
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* const payload = {
|
|
243
|
+
* "inputToken": "0x2170Ed0880ac9A755fd29B2688956BD959F933F8", // BSC ETH token address
|
|
244
|
+
* "outputToken": "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f", // ARB WBTC token address
|
|
245
|
+
* "inputAmount": 1000000000000000n, // The amount of input tokens
|
|
246
|
+
* "minOutputAmount": 900000000000000n, // min amount you are expecting to receive
|
|
247
|
+
* "deadline": 0n, // Optional timestamp after which intent expires (0 = no deadline)
|
|
248
|
+
* "allowPartialFill": false, // Whether the intent can be partially filled
|
|
249
|
+
* "srcChain": "0x38.bsc", // Chain ID where input tokens originate
|
|
250
|
+
* "dstChain": "0xa4b1.arbitrum", // Chain ID where output tokens should be delivered
|
|
251
|
+
* "srcAddress": "0x..", // Source address in bytes (original address on spoke chain)
|
|
252
|
+
* "dstAddress": "0x...", // Destination address in bytes (original address on spoke chain)
|
|
253
|
+
* "solver": "0x..", // Optional specific solver address (address(0) = any solver)
|
|
254
|
+
* "data": "0x..", // Additional arbitrary data
|
|
255
|
+
* } satisfies CreateIntentParams;
|
|
256
|
+
*
|
|
257
|
+
* const isAllowanceValid = await solverService.isAllowanceValid(payload, spokeProvider);
|
|
258
|
+
*
|
|
259
|
+
* if (!allowanceValid.ok) {
|
|
260
|
+
* // Handle error
|
|
261
|
+
* }
|
|
262
|
+
*
|
|
263
|
+
* if (!allowanceValid.value) {
|
|
264
|
+
* // Need to approve
|
|
265
|
+
* }
|
|
203
266
|
*/
|
|
204
267
|
async isAllowanceValid(params, spokeProvider) {
|
|
205
268
|
try {
|
|
206
269
|
if (spokeProvider instanceof EvmSpokeProvider) {
|
|
207
|
-
|
|
270
|
+
const walletAddress = (await spokeProvider.walletProvider.getWalletAddress());
|
|
271
|
+
return Erc20Service.isAllowanceValid(params.inputToken, params.inputAmount, walletAddress, spokeProvider.chainConfig.addresses.assetManager, spokeProvider);
|
|
208
272
|
}
|
|
209
273
|
return {
|
|
210
274
|
ok: true,
|
|
@@ -219,11 +283,26 @@ export class SolverService {
|
|
|
219
283
|
}
|
|
220
284
|
}
|
|
221
285
|
/**
|
|
222
|
-
* Approve
|
|
286
|
+
* Approve amount spending (currently required for EVM only)
|
|
223
287
|
* @param token - ERC20 token address
|
|
224
288
|
* @param amount - Amount to approve
|
|
225
|
-
* @param
|
|
289
|
+
* @param spender - Spender address
|
|
226
290
|
* @param spokeProvider - Spoke provider
|
|
291
|
+
* @returns {Promise<Result<EvmRawTransactionReceipt>>} - Returns the transaction receipt
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* const approveResult = await approve(
|
|
295
|
+
* '0x...', // ERC20 token address
|
|
296
|
+
* 1000n, // Amount to approve (in token decimals)
|
|
297
|
+
* '0x...', // Spender address (usually the asset manager contract: spokeProvider.chainConfig.addresses.assetManager)
|
|
298
|
+
* spokeProvider
|
|
299
|
+
* );
|
|
300
|
+
*
|
|
301
|
+
* if (!approveResult.ok) {
|
|
302
|
+
* // Handle error
|
|
303
|
+
* }
|
|
304
|
+
*
|
|
305
|
+
* const txReceipt = approveResult.value;
|
|
227
306
|
*/
|
|
228
307
|
async approve(token, amount, address, spokeProvider) {
|
|
229
308
|
try {
|
|
@@ -249,7 +328,30 @@ export class SolverService {
|
|
|
249
328
|
* @param {SpokeProvider} spokeProvider - The spoke provider
|
|
250
329
|
* @param {boolean} raw - Whether to return the raw transaction
|
|
251
330
|
* @param {PartnerFee} fee - The fee to apply to the intent
|
|
252
|
-
* @returns {Promise<[TxReturnType<
|
|
331
|
+
* @returns {Promise<Result<[TxReturnType<S, R>, Intent & FeeAmount], IntentSubmitError<'CREATION_FAILED'>>>} The encoded contract call
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
* const payload = {
|
|
335
|
+
* "inputToken": "0x2170Ed0880ac9A755fd29B2688956BD959F933F8", // BSC ETH token address
|
|
336
|
+
* "outputToken": "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f", // ARB WBTC token address
|
|
337
|
+
* "inputAmount": 1000000000000000n, // The amount of input tokens
|
|
338
|
+
* "minOutputAmount": 900000000000000n, // min amount you are expecting to receive
|
|
339
|
+
* "deadline": 0n, // Optional timestamp after which intent expires (0 = no deadline)
|
|
340
|
+
* "allowPartialFill": false, // Whether the intent can be partially filled
|
|
341
|
+
* "srcChain": "0x38.bsc", // Chain ID where input tokens originate
|
|
342
|
+
* "dstChain": "0xa4b1.arbitrum", // Chain ID where output tokens should be delivered
|
|
343
|
+
* "srcAddress": "0x..", // Source address in bytes (original address on spoke chain)
|
|
344
|
+
* "dstAddress": "0x...", // Destination address in bytes (original address on spoke chain)
|
|
345
|
+
* "solver": "0x..", // Optional specific solver address (address(0) = any solver)
|
|
346
|
+
* "data": "0x..", // Additional arbitrary data
|
|
347
|
+
* } satisfies CreateIntentParams;
|
|
348
|
+
*
|
|
349
|
+
* const createIntentResult = await solverService.createIntent(payload, spokeProvider);
|
|
350
|
+
*
|
|
351
|
+
* if (createIntentResult.ok) {
|
|
352
|
+
* const [txResult, intent] = createIntentResult.value;
|
|
353
|
+
* console.log('Intent:', intent);
|
|
354
|
+
*
|
|
253
355
|
*/
|
|
254
356
|
async createIntent(params, spokeProvider, fee, raw) {
|
|
255
357
|
invariant(isValidOriginalAssetAddress(params.srcChain, params.inputToken), `Unsupported spoke chain token (params.srcChain): ${params.srcChain}, params.inputToken): ${params.inputToken}`);
|
|
@@ -257,12 +359,14 @@ export class SolverService {
|
|
|
257
359
|
invariant(isValidSpokeChainId(params.srcChain), `Invalid spoke chain (params.srcChain): ${params.srcChain}`);
|
|
258
360
|
invariant(isValidSpokeChainId(params.dstChain), `Invalid spoke chain (params.dstChain): ${params.dstChain}`);
|
|
259
361
|
try {
|
|
362
|
+
const walletAddressBytes = await spokeProvider.walletProvider.getWalletAddressBytes();
|
|
260
363
|
// derive users hub wallet address
|
|
261
|
-
const creatorHubWalletAddress = await EvmWalletAbstraction.getUserHubWalletAddress(params.srcChain,
|
|
364
|
+
const creatorHubWalletAddress = await EvmWalletAbstraction.getUserHubWalletAddress(params.srcChain, walletAddressBytes, this.hubProvider);
|
|
262
365
|
// construct the intent data
|
|
263
366
|
const [data, intent, feeAmount] = EvmSolverService.constructCreateIntentData(params, creatorHubWalletAddress, this.config, fee);
|
|
367
|
+
const walletAddress = (await spokeProvider.walletProvider.getWalletAddress());
|
|
264
368
|
const txResult = await SpokeService.deposit({
|
|
265
|
-
from:
|
|
369
|
+
from: walletAddress,
|
|
266
370
|
to: creatorHubWalletAddress,
|
|
267
371
|
token: params.inputToken,
|
|
268
372
|
amount: params.inputAmount + feeAmount,
|
|
@@ -296,8 +400,9 @@ export class SolverService {
|
|
|
296
400
|
async cancelIntent(intent, spokeProvider, raw) {
|
|
297
401
|
invariant(isValidIntentRelayChainId(intent.srcChain), `Invalid intent.srcChain: ${intent.srcChain}`);
|
|
298
402
|
invariant(isValidIntentRelayChainId(intent.dstChain), `Invalid intent.dstChain: ${intent.dstChain}`);
|
|
403
|
+
const walletAddressBytes = await spokeProvider.walletProvider.getWalletAddressBytes();
|
|
299
404
|
// derive users hub wallet address
|
|
300
|
-
const creatorHubWalletAddress = await EvmWalletAbstraction.getUserHubWalletAddress(spokeProvider.chainConfig.chain.id,
|
|
405
|
+
const creatorHubWalletAddress = await EvmWalletAbstraction.getUserHubWalletAddress(spokeProvider.chainConfig.chain.id, walletAddressBytes, this.hubProvider);
|
|
301
406
|
const calls = [];
|
|
302
407
|
const intentsContract = this.config.intentsContract;
|
|
303
408
|
calls.push(EvmSolverService.encodeCancelIntent(intent, intentsContract));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolverService.js","sourceRoot":"","sources":["../../../src/services/solver/SolverService.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAC;AACvC,OAAO,EACL,4BAA4B,EAC5B,wBAAwB,EACxB,YAAY,EAEZ,gBAAgB,
|
|
1
|
+
{"version":3,"file":"SolverService.js","sourceRoot":"","sources":["../../../src/services/solver/SolverService.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,C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