@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.cjs +300 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +212 -12
- package/dist/index.d.ts +212 -12
- package/dist/index.mjs +300 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -12935,7 +12935,8 @@ var SwapService = class {
|
|
|
12935
12935
|
intentParams: params,
|
|
12936
12936
|
spokeProvider,
|
|
12937
12937
|
fee = this.config.partnerFee,
|
|
12938
|
-
raw
|
|
12938
|
+
raw,
|
|
12939
|
+
skipSimulation = false
|
|
12939
12940
|
}) {
|
|
12940
12941
|
invariant6__default.default(
|
|
12941
12942
|
this.configService.isValidOriginalAssetAddress(params.srcChain, params.inputToken),
|
|
@@ -13004,7 +13005,8 @@ var SwapService = class {
|
|
|
13004
13005
|
},
|
|
13005
13006
|
spokeProvider,
|
|
13006
13007
|
this.hubProvider,
|
|
13007
|
-
raw
|
|
13008
|
+
raw,
|
|
13009
|
+
skipSimulation
|
|
13008
13010
|
);
|
|
13009
13011
|
return {
|
|
13010
13012
|
ok: true,
|
|
@@ -13024,6 +13026,179 @@ var SwapService = class {
|
|
|
13024
13026
|
};
|
|
13025
13027
|
}
|
|
13026
13028
|
}
|
|
13029
|
+
/**
|
|
13030
|
+
* Creates a limit order intent (no deadline, must be cancelled manually by user).
|
|
13031
|
+
* Similar to swap but enforces deadline=0n (no deadline).
|
|
13032
|
+
* Limit orders remain active until manually cancelled by the user.
|
|
13033
|
+
*
|
|
13034
|
+
* @param {Prettify<LimitOrderParams<S> & OptionalTimeout>} params - Object containing:
|
|
13035
|
+
* - intentParams: The parameters for creating the limit order (deadline is automatically set to 0n, deadline field should be omitted).
|
|
13036
|
+
* - spokeProvider: The spoke provider instance.
|
|
13037
|
+
* - fee: (Optional) Partner fee configuration.
|
|
13038
|
+
* - timeout: (Optional) Timeout in milliseconds for the transaction (default: 60 seconds).
|
|
13039
|
+
* - skipSimulation: (Optional) Whether to skip transaction simulation (default: false).
|
|
13040
|
+
* @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.
|
|
13041
|
+
*
|
|
13042
|
+
* @example
|
|
13043
|
+
* const payload = {
|
|
13044
|
+
* "inputToken": "0x2170Ed0880ac9A755fd29B2688956BD959F933F8", // BSC ETH token address
|
|
13045
|
+
* "outputToken": "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f", // ARB WBTC token address
|
|
13046
|
+
* "inputAmount": 1000000000000000n, // The amount of input tokens
|
|
13047
|
+
* "minOutputAmount": 900000000000000n, // min amount you are expecting to receive
|
|
13048
|
+
* // deadline is omitted - will be automatically set to 0n
|
|
13049
|
+
* "allowPartialFill": false, // Whether the intent can be partially filled
|
|
13050
|
+
* "srcChain": "0x38.bsc", // Chain ID where input tokens originate
|
|
13051
|
+
* "dstChain": "0xa4b1.arbitrum", // Chain ID where output tokens should be delivered
|
|
13052
|
+
* "srcAddress": "0x..", // Source address (original address on spoke chain)
|
|
13053
|
+
* "dstAddress": "0x...", // Destination address (original address on spoke chain)
|
|
13054
|
+
* "solver": "0x..", // Optional specific solver address (address(0) = any solver)
|
|
13055
|
+
* "data": "0x..", // Additional arbitrary data
|
|
13056
|
+
* } satisfies CreateLimitOrderParams;
|
|
13057
|
+
*
|
|
13058
|
+
* const createLimitOrderResult = await swapService.createLimitOrder({
|
|
13059
|
+
* intentParams: payload,
|
|
13060
|
+
* spokeProvider,
|
|
13061
|
+
* fee, // optional
|
|
13062
|
+
* timeout, // optional
|
|
13063
|
+
* });
|
|
13064
|
+
*
|
|
13065
|
+
* if (createLimitOrderResult.ok) {
|
|
13066
|
+
* const [solverExecutionResponse, intent, intentDeliveryInfo] = createLimitOrderResult.value;
|
|
13067
|
+
* console.log('Intent execution response:', solverExecutionResponse);
|
|
13068
|
+
* console.log('Intent:', intent);
|
|
13069
|
+
* console.log('Intent delivery info:', intentDeliveryInfo);
|
|
13070
|
+
* // Limit order is now active and will remain until cancelled manually
|
|
13071
|
+
* } else {
|
|
13072
|
+
* // handle error
|
|
13073
|
+
* }
|
|
13074
|
+
*/
|
|
13075
|
+
async createLimitOrder({
|
|
13076
|
+
intentParams: params,
|
|
13077
|
+
spokeProvider,
|
|
13078
|
+
fee = this.config.partnerFee,
|
|
13079
|
+
timeout = DEFAULT_RELAY_TX_TIMEOUT,
|
|
13080
|
+
skipSimulation = false
|
|
13081
|
+
}) {
|
|
13082
|
+
const limitOrderParams = {
|
|
13083
|
+
...params,
|
|
13084
|
+
deadline: 0n
|
|
13085
|
+
};
|
|
13086
|
+
return this.createAndSubmitIntent({
|
|
13087
|
+
intentParams: limitOrderParams,
|
|
13088
|
+
spokeProvider,
|
|
13089
|
+
fee,
|
|
13090
|
+
timeout,
|
|
13091
|
+
skipSimulation
|
|
13092
|
+
});
|
|
13093
|
+
}
|
|
13094
|
+
/**
|
|
13095
|
+
* Creates a limit order intent (no deadline, must be cancelled manually by user).
|
|
13096
|
+
* Similar to createIntent but enforces deadline=0n (no deadline) and uses LimitOrderParams.
|
|
13097
|
+
* Limit orders remain active until manually cancelled by the user.
|
|
13098
|
+
* NOTE: This method does not submit the intent to the Solver API
|
|
13099
|
+
*
|
|
13100
|
+
* @param {Prettify<LimitOrderParams<S> & OptionalRaw<R>>} params - Object containing:
|
|
13101
|
+
* - intentParams: The parameters for creating the limit order (deadline is automatically set to 0n, deadline field should be omitted).
|
|
13102
|
+
* - spokeProvider: The spoke provider instance.
|
|
13103
|
+
* - fee: (Optional) Partner fee configuration.
|
|
13104
|
+
* - raw: (Optional) Whether to return the raw transaction data instead of executing it
|
|
13105
|
+
* - skipSimulation: (Optional) Whether to skip transaction simulation (default: false).
|
|
13106
|
+
* @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
|
|
13107
|
+
*
|
|
13108
|
+
* @example
|
|
13109
|
+
* const payload = {
|
|
13110
|
+
* "inputToken": "0x2170Ed0880ac9A755fd29B2688956BD959F933F8", // BSC ETH token address
|
|
13111
|
+
* "outputToken": "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f", // ARB WBTC token address
|
|
13112
|
+
* "inputAmount": 1000000000000000n, // The amount of input tokens
|
|
13113
|
+
* "minOutputAmount": 900000000000000n, // min amount you are expecting to receive
|
|
13114
|
+
* // deadline is omitted - will be automatically set to 0n
|
|
13115
|
+
* "allowPartialFill": false, // Whether the intent can be partially filled
|
|
13116
|
+
* "srcChain": "0x38.bsc", // Chain ID where input tokens originate
|
|
13117
|
+
* "dstChain": "0xa4b1.arbitrum", // Chain ID where output tokens should be delivered
|
|
13118
|
+
* "srcAddress": "0x..", // Source address (original address on spoke chain)
|
|
13119
|
+
* "dstAddress": "0x...", // Destination address (original address on spoke chain)
|
|
13120
|
+
* "solver": "0x..", // Optional specific solver address (address(0) = any solver)
|
|
13121
|
+
* "data": "0x..", // Additional arbitrary data
|
|
13122
|
+
* } satisfies CreateLimitOrderParams;
|
|
13123
|
+
*
|
|
13124
|
+
* const createLimitOrderIntentResult = await swapService.createLimitOrderIntent({
|
|
13125
|
+
* intentParams: payload,
|
|
13126
|
+
* spokeProvider,
|
|
13127
|
+
* fee, // optional
|
|
13128
|
+
* raw, // optional
|
|
13129
|
+
* });
|
|
13130
|
+
*
|
|
13131
|
+
* if (createLimitOrderIntentResult.ok) {
|
|
13132
|
+
* const [txResult, intent, intentData] = createLimitOrderIntentResult.value;
|
|
13133
|
+
* console.log('Transaction result:', txResult);
|
|
13134
|
+
* console.log('Intent:', intent);
|
|
13135
|
+
* console.log('Intent data:', intentData);
|
|
13136
|
+
* } else {
|
|
13137
|
+
* // handle error
|
|
13138
|
+
* }
|
|
13139
|
+
*/
|
|
13140
|
+
async createLimitOrderIntent({
|
|
13141
|
+
intentParams: params,
|
|
13142
|
+
spokeProvider,
|
|
13143
|
+
fee = this.config.partnerFee,
|
|
13144
|
+
raw,
|
|
13145
|
+
skipSimulation = false
|
|
13146
|
+
}) {
|
|
13147
|
+
const limitOrderParams = {
|
|
13148
|
+
...params,
|
|
13149
|
+
deadline: 0n
|
|
13150
|
+
};
|
|
13151
|
+
return this.createIntent({
|
|
13152
|
+
intentParams: limitOrderParams,
|
|
13153
|
+
spokeProvider,
|
|
13154
|
+
fee,
|
|
13155
|
+
raw,
|
|
13156
|
+
skipSimulation
|
|
13157
|
+
});
|
|
13158
|
+
}
|
|
13159
|
+
/**
|
|
13160
|
+
* Syntactic sugar for cancelAndSubmitIntent: cancels a limit order intent and submits it to the Relayer API.
|
|
13161
|
+
* Similar to swap function that wraps createAndSubmitIntent.
|
|
13162
|
+
*
|
|
13163
|
+
* @param params - Object containing:
|
|
13164
|
+
* @param params.intent - The limit order intent to cancel.
|
|
13165
|
+
* @param params.spokeProvider - The spoke provider instance.
|
|
13166
|
+
* @param params.timeout - (Optional) Timeout in milliseconds for the transaction (default: 60 seconds).
|
|
13167
|
+
* @returns
|
|
13168
|
+
* A promise resolving to a Result containing a tuple of cancel transaction hash and destination transaction hash,
|
|
13169
|
+
* or an IntentError if the operation fails.
|
|
13170
|
+
*
|
|
13171
|
+
* @example
|
|
13172
|
+
* // Get intent first (or use intent from createLimitOrder response)
|
|
13173
|
+
* const intent: Intent = await swapService.getIntent(txHash);
|
|
13174
|
+
*
|
|
13175
|
+
* // Cancel the limit order
|
|
13176
|
+
* const result = await swapService.cancelLimitOrder({
|
|
13177
|
+
* intent,
|
|
13178
|
+
* spokeProvider,
|
|
13179
|
+
* timeout, // optional
|
|
13180
|
+
* });
|
|
13181
|
+
*
|
|
13182
|
+
* if (result.ok) {
|
|
13183
|
+
* const [cancelTxHash, dstTxHash] = result.value;
|
|
13184
|
+
* console.log('Cancel transaction hash:', cancelTxHash);
|
|
13185
|
+
* console.log('Destination transaction hash:', dstTxHash);
|
|
13186
|
+
* } else {
|
|
13187
|
+
* // handle error
|
|
13188
|
+
* console.error('[cancelLimitOrder] error:', result.error);
|
|
13189
|
+
* }
|
|
13190
|
+
*/
|
|
13191
|
+
async cancelLimitOrder({
|
|
13192
|
+
intent,
|
|
13193
|
+
spokeProvider,
|
|
13194
|
+
timeout = DEFAULT_RELAY_TX_TIMEOUT
|
|
13195
|
+
}) {
|
|
13196
|
+
return this.cancelAndSubmitIntent({
|
|
13197
|
+
intent,
|
|
13198
|
+
spokeProvider,
|
|
13199
|
+
timeout
|
|
13200
|
+
});
|
|
13201
|
+
}
|
|
13027
13202
|
/**
|
|
13028
13203
|
* Cancels an intent
|
|
13029
13204
|
* @param {Intent} intent - The intent to cancel
|
|
@@ -13065,7 +13240,97 @@ var SwapService = class {
|
|
|
13065
13240
|
} catch (error) {
|
|
13066
13241
|
return {
|
|
13067
13242
|
ok: false,
|
|
13068
|
-
error
|
|
13243
|
+
error: {
|
|
13244
|
+
code: "CANCEL_FAILED",
|
|
13245
|
+
data: {
|
|
13246
|
+
payload: intent,
|
|
13247
|
+
error
|
|
13248
|
+
}
|
|
13249
|
+
}
|
|
13250
|
+
};
|
|
13251
|
+
}
|
|
13252
|
+
}
|
|
13253
|
+
/**
|
|
13254
|
+
* Cancels an intent on the spoke chain, submits the cancel intent to the relayer API,
|
|
13255
|
+
* and waits until the intent cancel is executed (on the destination/hub chain).
|
|
13256
|
+
* Follows a similar workflow to createAndSubmitIntent, but for cancelling.
|
|
13257
|
+
*
|
|
13258
|
+
* @param params - The parameters for canceling and submitting the intent.
|
|
13259
|
+
* @param params.intent - The intent to be canceled.
|
|
13260
|
+
* @param params.spokeProvider - The provider for the spoke chain.
|
|
13261
|
+
* @param params.timeout - Optional timeout in milliseconds (default: 60 seconds).
|
|
13262
|
+
* @returns
|
|
13263
|
+
* A Result containing the SolverExecutionResponse (cancel tx), intent, and relay info,
|
|
13264
|
+
* or an IntentError on failure.
|
|
13265
|
+
*/
|
|
13266
|
+
async cancelAndSubmitIntent({
|
|
13267
|
+
intent,
|
|
13268
|
+
spokeProvider,
|
|
13269
|
+
timeout = DEFAULT_RELAY_TX_TIMEOUT
|
|
13270
|
+
}) {
|
|
13271
|
+
try {
|
|
13272
|
+
const cancelResult = await this.cancelIntent(intent, spokeProvider, false);
|
|
13273
|
+
if (!cancelResult.ok) {
|
|
13274
|
+
return cancelResult;
|
|
13275
|
+
}
|
|
13276
|
+
const cancelTxHash = cancelResult.value;
|
|
13277
|
+
const verifyTxHashResult = await SpokeService.verifyTxHash(cancelTxHash, spokeProvider);
|
|
13278
|
+
if (!verifyTxHashResult.ok) {
|
|
13279
|
+
return {
|
|
13280
|
+
ok: false,
|
|
13281
|
+
error: {
|
|
13282
|
+
code: "CANCEL_FAILED",
|
|
13283
|
+
data: {
|
|
13284
|
+
payload: intent,
|
|
13285
|
+
error: verifyTxHashResult.error
|
|
13286
|
+
}
|
|
13287
|
+
}
|
|
13288
|
+
};
|
|
13289
|
+
}
|
|
13290
|
+
let dstIntentTxHash;
|
|
13291
|
+
if (spokeProvider.chainConfig.chain.id !== this.hubProvider.chainConfig.chain.id) {
|
|
13292
|
+
const intentRelayChainId = intent.srcChain.toString();
|
|
13293
|
+
const submitPayload = {
|
|
13294
|
+
action: "submit",
|
|
13295
|
+
params: {
|
|
13296
|
+
chain_id: intentRelayChainId,
|
|
13297
|
+
tx_hash: cancelTxHash
|
|
13298
|
+
}
|
|
13299
|
+
};
|
|
13300
|
+
const submitResult = await this.submitIntent(submitPayload);
|
|
13301
|
+
if (!submitResult.ok) {
|
|
13302
|
+
return submitResult;
|
|
13303
|
+
}
|
|
13304
|
+
const packet = await waitUntilIntentExecuted({
|
|
13305
|
+
intentRelayChainId,
|
|
13306
|
+
spokeTxHash: cancelTxHash,
|
|
13307
|
+
timeout,
|
|
13308
|
+
apiUrl: this.config.relayerApiEndpoint
|
|
13309
|
+
});
|
|
13310
|
+
if (!packet.ok) {
|
|
13311
|
+
return {
|
|
13312
|
+
ok: false,
|
|
13313
|
+
error: packet.error
|
|
13314
|
+
};
|
|
13315
|
+
}
|
|
13316
|
+
dstIntentTxHash = packet.value.dst_tx_hash;
|
|
13317
|
+
} else {
|
|
13318
|
+
dstIntentTxHash = cancelTxHash;
|
|
13319
|
+
}
|
|
13320
|
+
return {
|
|
13321
|
+
ok: true,
|
|
13322
|
+
value: [cancelTxHash, dstIntentTxHash]
|
|
13323
|
+
};
|
|
13324
|
+
} catch (error) {
|
|
13325
|
+
return {
|
|
13326
|
+
ok: false,
|
|
13327
|
+
error: {
|
|
13328
|
+
code: "CANCEL_FAILED",
|
|
13329
|
+
data: {
|
|
13330
|
+
payload: intent,
|
|
13331
|
+
error
|
|
13332
|
+
}
|
|
13333
|
+
}
|
|
13069
13334
|
};
|
|
13070
13335
|
}
|
|
13071
13336
|
}
|
|
@@ -15706,6 +15971,29 @@ var BackendApiService = class {
|
|
|
15706
15971
|
const endpoint = `/solver/orderbook?${queryString}`;
|
|
15707
15972
|
return this.makeRequest(endpoint, { method: "GET" });
|
|
15708
15973
|
}
|
|
15974
|
+
/**
|
|
15975
|
+
* Get all intents created by a specific user address with optional filters.
|
|
15976
|
+
*
|
|
15977
|
+
* @param params - Options to filter the user intents.
|
|
15978
|
+
* @param params.userAddress - The user's wallet address on the hub chain (required).
|
|
15979
|
+
* @param params.startDate - Optional. Start timestamp in milliseconds (number, required if filtering by date).
|
|
15980
|
+
* @param params.endDate - Optional. End timestamp in milliseconds (number, required if filtering by date).
|
|
15981
|
+
* @param params.limit - Optional. Max number of results (string).
|
|
15982
|
+
* @param params.offset - Optional. Pagination offset (string).
|
|
15983
|
+
*
|
|
15984
|
+
* @returns {Promise<UserIntentsResponse>} Promise resolving to an array of intent responses for the user.
|
|
15985
|
+
*/
|
|
15986
|
+
async getUserIntents(params) {
|
|
15987
|
+
const { userAddress, startDate, endDate, limit, offset } = params;
|
|
15988
|
+
const queryParams = new URLSearchParams();
|
|
15989
|
+
if (startDate) queryParams.append("startDate", new Date(startDate).toISOString());
|
|
15990
|
+
if (endDate) queryParams.append("endDate", new Date(endDate).toISOString());
|
|
15991
|
+
if (limit) queryParams.append("limit", limit);
|
|
15992
|
+
if (offset) queryParams.append("offset", offset);
|
|
15993
|
+
const queryString = queryParams.toString();
|
|
15994
|
+
const endpoint = queryString.length > 0 ? `/intent/user/${userAddress}?${queryString}` : `/intent/user/${userAddress}`;
|
|
15995
|
+
return this.makeRequest(endpoint, { method: "GET" });
|
|
15996
|
+
}
|
|
15709
15997
|
// Money Market endpoints
|
|
15710
15998
|
/**
|
|
15711
15999
|
* Get money market position for a specific user
|
|
@@ -17182,7 +17470,13 @@ var StakingService = class {
|
|
|
17182
17470
|
spokeProvider,
|
|
17183
17471
|
this.hubProvider
|
|
17184
17472
|
);
|
|
17185
|
-
const
|
|
17473
|
+
const xSoda = this.hubProvider.chainConfig.addresses.xSoda;
|
|
17474
|
+
const underlyingSodaAmount = await StakingLogic.convertXSodaSharesToSoda(
|
|
17475
|
+
xSoda,
|
|
17476
|
+
params.amount,
|
|
17477
|
+
this.hubProvider.publicClient
|
|
17478
|
+
);
|
|
17479
|
+
const data = this.buildUnstakeData(hubWallet, params, xSoda, underlyingSodaAmount);
|
|
17186
17480
|
let txResult;
|
|
17187
17481
|
if (isHub) {
|
|
17188
17482
|
txResult = await SpokeService.deposit(
|
|
@@ -17225,13 +17519,12 @@ var StakingService = class {
|
|
|
17225
17519
|
* @param params - The unstake parameters
|
|
17226
17520
|
* @returns The encoded contract call data
|
|
17227
17521
|
*/
|
|
17228
|
-
buildUnstakeData(hubWallet, params) {
|
|
17522
|
+
buildUnstakeData(hubWallet, params, xSoda, underlyingSodaAmount) {
|
|
17229
17523
|
const hubConfig = getHubChainConfig();
|
|
17230
17524
|
const stakedSoda = hubConfig.addresses.stakedSoda;
|
|
17231
|
-
const xSoda = hubConfig.addresses.xSoda;
|
|
17232
17525
|
const calls = [];
|
|
17233
17526
|
calls.push(StakingLogic.encodeXSodaRedeem(xSoda, params.amount, hubWallet, hubWallet));
|
|
17234
|
-
calls.push(StakingLogic.encodeUnstake(stakedSoda, hubWallet,
|
|
17527
|
+
calls.push(StakingLogic.encodeUnstake(stakedSoda, hubWallet, underlyingSodaAmount));
|
|
17235
17528
|
return encodeContractCalls(calls);
|
|
17236
17529
|
}
|
|
17237
17530
|
/**
|