@sodax/sdk 1.0.1-beta → 1.0.2-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -12907,7 +12907,8 @@ var SwapService = class {
12907
12907
  intentParams: params,
12908
12908
  spokeProvider,
12909
12909
  fee = this.config.partnerFee,
12910
- raw
12910
+ raw,
12911
+ skipSimulation = false
12911
12912
  }) {
12912
12913
  invariant6(
12913
12914
  this.configService.isValidOriginalAssetAddress(params.srcChain, params.inputToken),
@@ -12976,7 +12977,8 @@ var SwapService = class {
12976
12977
  },
12977
12978
  spokeProvider,
12978
12979
  this.hubProvider,
12979
- raw
12980
+ raw,
12981
+ skipSimulation
12980
12982
  );
12981
12983
  return {
12982
12984
  ok: true,
@@ -12996,6 +12998,179 @@ var SwapService = class {
12996
12998
  };
12997
12999
  }
12998
13000
  }
13001
+ /**
13002
+ * Creates a limit order intent (no deadline, must be cancelled manually by user).
13003
+ * Similar to swap but enforces deadline=0n (no deadline).
13004
+ * Limit orders remain active until manually cancelled by the user.
13005
+ *
13006
+ * @param {Prettify<LimitOrderParams<S> & OptionalTimeout>} params - Object containing:
13007
+ * - intentParams: The parameters for creating the limit order (deadline is automatically set to 0n, deadline field should be omitted).
13008
+ * - spokeProvider: The spoke provider instance.
13009
+ * - fee: (Optional) Partner fee configuration.
13010
+ * - timeout: (Optional) Timeout in milliseconds for the transaction (default: 60 seconds).
13011
+ * - skipSimulation: (Optional) Whether to skip transaction simulation (default: false).
13012
+ * @returns {Promise<Result<[SolverExecutionResponse, Intent, IntentDeliveryInfo], IntentError<IntentErrorCode>>>} A promise resolving to a Result containing a tuple of SolverExecutionResponse, Intent, and intent delivery info, or an IntentError if the operation fails.
13013
+ *
13014
+ * @example
13015
+ * const payload = {
13016
+ * "inputToken": "0x2170Ed0880ac9A755fd29B2688956BD959F933F8", // BSC ETH token address
13017
+ * "outputToken": "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f", // ARB WBTC token address
13018
+ * "inputAmount": 1000000000000000n, // The amount of input tokens
13019
+ * "minOutputAmount": 900000000000000n, // min amount you are expecting to receive
13020
+ * // deadline is omitted - will be automatically set to 0n
13021
+ * "allowPartialFill": false, // Whether the intent can be partially filled
13022
+ * "srcChain": "0x38.bsc", // Chain ID where input tokens originate
13023
+ * "dstChain": "0xa4b1.arbitrum", // Chain ID where output tokens should be delivered
13024
+ * "srcAddress": "0x..", // Source address (original address on spoke chain)
13025
+ * "dstAddress": "0x...", // Destination address (original address on spoke chain)
13026
+ * "solver": "0x..", // Optional specific solver address (address(0) = any solver)
13027
+ * "data": "0x..", // Additional arbitrary data
13028
+ * } satisfies CreateLimitOrderParams;
13029
+ *
13030
+ * const createLimitOrderResult = await swapService.createLimitOrder({
13031
+ * intentParams: payload,
13032
+ * spokeProvider,
13033
+ * fee, // optional
13034
+ * timeout, // optional
13035
+ * });
13036
+ *
13037
+ * if (createLimitOrderResult.ok) {
13038
+ * const [solverExecutionResponse, intent, intentDeliveryInfo] = createLimitOrderResult.value;
13039
+ * console.log('Intent execution response:', solverExecutionResponse);
13040
+ * console.log('Intent:', intent);
13041
+ * console.log('Intent delivery info:', intentDeliveryInfo);
13042
+ * // Limit order is now active and will remain until cancelled manually
13043
+ * } else {
13044
+ * // handle error
13045
+ * }
13046
+ */
13047
+ async createLimitOrder({
13048
+ intentParams: params,
13049
+ spokeProvider,
13050
+ fee = this.config.partnerFee,
13051
+ timeout = DEFAULT_RELAY_TX_TIMEOUT,
13052
+ skipSimulation = false
13053
+ }) {
13054
+ const limitOrderParams = {
13055
+ ...params,
13056
+ deadline: 0n
13057
+ };
13058
+ return this.createAndSubmitIntent({
13059
+ intentParams: limitOrderParams,
13060
+ spokeProvider,
13061
+ fee,
13062
+ timeout,
13063
+ skipSimulation
13064
+ });
13065
+ }
13066
+ /**
13067
+ * Creates a limit order intent (no deadline, must be cancelled manually by user).
13068
+ * Similar to createIntent but enforces deadline=0n (no deadline) and uses LimitOrderParams.
13069
+ * Limit orders remain active until manually cancelled by the user.
13070
+ * NOTE: This method does not submit the intent to the Solver API
13071
+ *
13072
+ * @param {Prettify<LimitOrderParams<S> & OptionalRaw<R>>} params - Object containing:
13073
+ * - intentParams: The parameters for creating the limit order (deadline is automatically set to 0n, deadline field should be omitted).
13074
+ * - spokeProvider: The spoke provider instance.
13075
+ * - fee: (Optional) Partner fee configuration.
13076
+ * - raw: (Optional) Whether to return the raw transaction data instead of executing it
13077
+ * - skipSimulation: (Optional) Whether to skip transaction simulation (default: false).
13078
+ * @returns {Promise<Result<[TxReturnType<S, R>, Intent & FeeAmount, Hex], IntentError<'CREATION_FAILED'>>>} The encoded contract call or raw transaction data, Intent and intent data as hex
13079
+ *
13080
+ * @example
13081
+ * const payload = {
13082
+ * "inputToken": "0x2170Ed0880ac9A755fd29B2688956BD959F933F8", // BSC ETH token address
13083
+ * "outputToken": "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f", // ARB WBTC token address
13084
+ * "inputAmount": 1000000000000000n, // The amount of input tokens
13085
+ * "minOutputAmount": 900000000000000n, // min amount you are expecting to receive
13086
+ * // deadline is omitted - will be automatically set to 0n
13087
+ * "allowPartialFill": false, // Whether the intent can be partially filled
13088
+ * "srcChain": "0x38.bsc", // Chain ID where input tokens originate
13089
+ * "dstChain": "0xa4b1.arbitrum", // Chain ID where output tokens should be delivered
13090
+ * "srcAddress": "0x..", // Source address (original address on spoke chain)
13091
+ * "dstAddress": "0x...", // Destination address (original address on spoke chain)
13092
+ * "solver": "0x..", // Optional specific solver address (address(0) = any solver)
13093
+ * "data": "0x..", // Additional arbitrary data
13094
+ * } satisfies CreateLimitOrderParams;
13095
+ *
13096
+ * const createLimitOrderIntentResult = await swapService.createLimitOrderIntent({
13097
+ * intentParams: payload,
13098
+ * spokeProvider,
13099
+ * fee, // optional
13100
+ * raw, // optional
13101
+ * });
13102
+ *
13103
+ * if (createLimitOrderIntentResult.ok) {
13104
+ * const [txResult, intent, intentData] = createLimitOrderIntentResult.value;
13105
+ * console.log('Transaction result:', txResult);
13106
+ * console.log('Intent:', intent);
13107
+ * console.log('Intent data:', intentData);
13108
+ * } else {
13109
+ * // handle error
13110
+ * }
13111
+ */
13112
+ async createLimitOrderIntent({
13113
+ intentParams: params,
13114
+ spokeProvider,
13115
+ fee = this.config.partnerFee,
13116
+ raw,
13117
+ skipSimulation = false
13118
+ }) {
13119
+ const limitOrderParams = {
13120
+ ...params,
13121
+ deadline: 0n
13122
+ };
13123
+ return this.createIntent({
13124
+ intentParams: limitOrderParams,
13125
+ spokeProvider,
13126
+ fee,
13127
+ raw,
13128
+ skipSimulation
13129
+ });
13130
+ }
13131
+ /**
13132
+ * Syntactic sugar for cancelAndSubmitIntent: cancels a limit order intent and submits it to the Relayer API.
13133
+ * Similar to swap function that wraps createAndSubmitIntent.
13134
+ *
13135
+ * @param params - Object containing:
13136
+ * @param params.intent - The limit order intent to cancel.
13137
+ * @param params.spokeProvider - The spoke provider instance.
13138
+ * @param params.timeout - (Optional) Timeout in milliseconds for the transaction (default: 60 seconds).
13139
+ * @returns
13140
+ * A promise resolving to a Result containing a tuple of cancel transaction hash and destination transaction hash,
13141
+ * or an IntentError if the operation fails.
13142
+ *
13143
+ * @example
13144
+ * // Get intent first (or use intent from createLimitOrder response)
13145
+ * const intent: Intent = await swapService.getIntent(txHash);
13146
+ *
13147
+ * // Cancel the limit order
13148
+ * const result = await swapService.cancelLimitOrder({
13149
+ * intent,
13150
+ * spokeProvider,
13151
+ * timeout, // optional
13152
+ * });
13153
+ *
13154
+ * if (result.ok) {
13155
+ * const [cancelTxHash, dstTxHash] = result.value;
13156
+ * console.log('Cancel transaction hash:', cancelTxHash);
13157
+ * console.log('Destination transaction hash:', dstTxHash);
13158
+ * } else {
13159
+ * // handle error
13160
+ * console.error('[cancelLimitOrder] error:', result.error);
13161
+ * }
13162
+ */
13163
+ async cancelLimitOrder({
13164
+ intent,
13165
+ spokeProvider,
13166
+ timeout = DEFAULT_RELAY_TX_TIMEOUT
13167
+ }) {
13168
+ return this.cancelAndSubmitIntent({
13169
+ intent,
13170
+ spokeProvider,
13171
+ timeout
13172
+ });
13173
+ }
12999
13174
  /**
13000
13175
  * Cancels an intent
13001
13176
  * @param {Intent} intent - The intent to cancel
@@ -13037,7 +13212,97 @@ var SwapService = class {
13037
13212
  } catch (error) {
13038
13213
  return {
13039
13214
  ok: false,
13040
- error
13215
+ error: {
13216
+ code: "CANCEL_FAILED",
13217
+ data: {
13218
+ payload: intent,
13219
+ error
13220
+ }
13221
+ }
13222
+ };
13223
+ }
13224
+ }
13225
+ /**
13226
+ * Cancels an intent on the spoke chain, submits the cancel intent to the relayer API,
13227
+ * and waits until the intent cancel is executed (on the destination/hub chain).
13228
+ * Follows a similar workflow to createAndSubmitIntent, but for cancelling.
13229
+ *
13230
+ * @param params - The parameters for canceling and submitting the intent.
13231
+ * @param params.intent - The intent to be canceled.
13232
+ * @param params.spokeProvider - The provider for the spoke chain.
13233
+ * @param params.timeout - Optional timeout in milliseconds (default: 60 seconds).
13234
+ * @returns
13235
+ * A Result containing the SolverExecutionResponse (cancel tx), intent, and relay info,
13236
+ * or an IntentError on failure.
13237
+ */
13238
+ async cancelAndSubmitIntent({
13239
+ intent,
13240
+ spokeProvider,
13241
+ timeout = DEFAULT_RELAY_TX_TIMEOUT
13242
+ }) {
13243
+ try {
13244
+ const cancelResult = await this.cancelIntent(intent, spokeProvider, false);
13245
+ if (!cancelResult.ok) {
13246
+ return cancelResult;
13247
+ }
13248
+ const cancelTxHash = cancelResult.value;
13249
+ const verifyTxHashResult = await SpokeService.verifyTxHash(cancelTxHash, spokeProvider);
13250
+ if (!verifyTxHashResult.ok) {
13251
+ return {
13252
+ ok: false,
13253
+ error: {
13254
+ code: "CANCEL_FAILED",
13255
+ data: {
13256
+ payload: intent,
13257
+ error: verifyTxHashResult.error
13258
+ }
13259
+ }
13260
+ };
13261
+ }
13262
+ let dstIntentTxHash;
13263
+ if (spokeProvider.chainConfig.chain.id !== this.hubProvider.chainConfig.chain.id) {
13264
+ const intentRelayChainId = intent.srcChain.toString();
13265
+ const submitPayload = {
13266
+ action: "submit",
13267
+ params: {
13268
+ chain_id: intentRelayChainId,
13269
+ tx_hash: cancelTxHash
13270
+ }
13271
+ };
13272
+ const submitResult = await this.submitIntent(submitPayload);
13273
+ if (!submitResult.ok) {
13274
+ return submitResult;
13275
+ }
13276
+ const packet = await waitUntilIntentExecuted({
13277
+ intentRelayChainId,
13278
+ spokeTxHash: cancelTxHash,
13279
+ timeout,
13280
+ apiUrl: this.config.relayerApiEndpoint
13281
+ });
13282
+ if (!packet.ok) {
13283
+ return {
13284
+ ok: false,
13285
+ error: packet.error
13286
+ };
13287
+ }
13288
+ dstIntentTxHash = packet.value.dst_tx_hash;
13289
+ } else {
13290
+ dstIntentTxHash = cancelTxHash;
13291
+ }
13292
+ return {
13293
+ ok: true,
13294
+ value: [cancelTxHash, dstIntentTxHash]
13295
+ };
13296
+ } catch (error) {
13297
+ return {
13298
+ ok: false,
13299
+ error: {
13300
+ code: "CANCEL_FAILED",
13301
+ data: {
13302
+ payload: intent,
13303
+ error
13304
+ }
13305
+ }
13041
13306
  };
13042
13307
  }
13043
13308
  }
@@ -15678,6 +15943,29 @@ var BackendApiService = class {
15678
15943
  const endpoint = `/solver/orderbook?${queryString}`;
15679
15944
  return this.makeRequest(endpoint, { method: "GET" });
15680
15945
  }
15946
+ /**
15947
+ * Get all intents created by a specific user address with optional filters.
15948
+ *
15949
+ * @param params - Options to filter the user intents.
15950
+ * @param params.userAddress - The user's wallet address on the hub chain (required).
15951
+ * @param params.startDate - Optional. Start timestamp in milliseconds (number, required if filtering by date).
15952
+ * @param params.endDate - Optional. End timestamp in milliseconds (number, required if filtering by date).
15953
+ * @param params.limit - Optional. Max number of results (string).
15954
+ * @param params.offset - Optional. Pagination offset (string).
15955
+ *
15956
+ * @returns {Promise<UserIntentsResponse>} Promise resolving to an array of intent responses for the user.
15957
+ */
15958
+ async getUserIntents(params) {
15959
+ const { userAddress, startDate, endDate, limit, offset } = params;
15960
+ const queryParams = new URLSearchParams();
15961
+ if (startDate) queryParams.append("startDate", new Date(startDate).toISOString());
15962
+ if (endDate) queryParams.append("endDate", new Date(endDate).toISOString());
15963
+ if (limit) queryParams.append("limit", limit);
15964
+ if (offset) queryParams.append("offset", offset);
15965
+ const queryString = queryParams.toString();
15966
+ const endpoint = queryString.length > 0 ? `/intent/user/${userAddress}?${queryString}` : `/intent/user/${userAddress}`;
15967
+ return this.makeRequest(endpoint, { method: "GET" });
15968
+ }
15681
15969
  // Money Market endpoints
15682
15970
  /**
15683
15971
  * Get money market position for a specific user
@@ -17154,7 +17442,13 @@ var StakingService = class {
17154
17442
  spokeProvider,
17155
17443
  this.hubProvider
17156
17444
  );
17157
- const data = this.buildUnstakeData(hubWallet, params);
17445
+ const xSoda = this.hubProvider.chainConfig.addresses.xSoda;
17446
+ const underlyingSodaAmount = await StakingLogic.convertXSodaSharesToSoda(
17447
+ xSoda,
17448
+ params.amount,
17449
+ this.hubProvider.publicClient
17450
+ );
17451
+ const data = this.buildUnstakeData(hubWallet, params, xSoda, underlyingSodaAmount);
17158
17452
  let txResult;
17159
17453
  if (isHub) {
17160
17454
  txResult = await SpokeService.deposit(
@@ -17197,13 +17491,12 @@ var StakingService = class {
17197
17491
  * @param params - The unstake parameters
17198
17492
  * @returns The encoded contract call data
17199
17493
  */
17200
- buildUnstakeData(hubWallet, params) {
17494
+ buildUnstakeData(hubWallet, params, xSoda, underlyingSodaAmount) {
17201
17495
  const hubConfig = getHubChainConfig();
17202
17496
  const stakedSoda = hubConfig.addresses.stakedSoda;
17203
- const xSoda = hubConfig.addresses.xSoda;
17204
17497
  const calls = [];
17205
17498
  calls.push(StakingLogic.encodeXSodaRedeem(xSoda, params.amount, hubWallet, hubWallet));
17206
- calls.push(StakingLogic.encodeUnstake(stakedSoda, hubWallet, params.amount));
17499
+ calls.push(StakingLogic.encodeUnstake(stakedSoda, hubWallet, underlyingSodaAmount));
17207
17500
  return encodeContractCalls(calls);
17208
17501
  }
17209
17502
  /**