@shogun-sdk/swap 0.0.2-test.3 → 0.0.2-test.31
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/core.cjs +984 -157
- package/dist/core.d.cts +4 -136
- package/dist/core.d.ts +4 -136
- package/dist/core.js +983 -129
- package/dist/index-CXY6BUx9.d.ts +394 -0
- package/dist/index-CtZ-hgYk.d.cts +394 -0
- package/dist/index.cjs +973 -527
- package/dist/index.d.cts +4 -9
- package/dist/index.d.ts +4 -9
- package/dist/index.js +972 -496
- package/dist/react.cjs +1517 -484
- package/dist/react.d.cts +283 -89
- package/dist/react.d.ts +283 -89
- package/dist/react.js +1510 -467
- package/dist/{wallet-MmUIz8GE.d.cts → wallet-B9bKceyN.d.cts} +3 -3
- package/dist/{wallet-MmUIz8GE.d.ts → wallet-B9bKceyN.d.ts} +3 -3
- package/dist/wallet-adapter.cjs +25659 -27
- package/dist/wallet-adapter.d.cts +1 -2
- package/dist/wallet-adapter.d.ts +1 -2
- package/dist/wallet-adapter.js +25679 -16
- package/package.json +44 -14
- package/dist/execute-FaLLPp1i.d.cts +0 -147
- package/dist/execute-HX1fQ7wG.d.ts +0 -147
package/dist/core.cjs
CHANGED
|
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
7
|
var __export = (target, all) => {
|
|
7
8
|
for (var name in all)
|
|
8
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -16,40 +17,29 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
17
|
return to;
|
|
17
18
|
};
|
|
18
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
19
21
|
|
|
20
22
|
// src/core/index.ts
|
|
21
23
|
var core_exports = {};
|
|
22
24
|
__export(core_exports, {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
SOLANA_CHAIN_ID: () => SOLANA_CHAIN_ID,
|
|
25
|
+
ChainId: () => ChainId,
|
|
26
|
+
OrderExecutionType: () => OrderExecutionType,
|
|
26
27
|
SupportedChains: () => SupportedChains,
|
|
28
|
+
SwapSDK: () => SwapSDK,
|
|
27
29
|
buildQuoteParams: () => buildQuoteParams,
|
|
28
|
-
|
|
29
|
-
getBalances: () => getBalances,
|
|
30
|
-
getQuote: () => getQuote,
|
|
31
|
-
getTokenList: () => getTokenList,
|
|
32
|
-
isEvmChain: () => import_intents_sdk10.isEvmChain,
|
|
33
|
-
isNativeAddress: () => isNativeAddress,
|
|
34
|
-
isViemWalletClient: () => isViemWalletClient,
|
|
35
|
-
serializeBigIntsToStrings: () => serializeBigIntsToStrings
|
|
30
|
+
isEvmChain: () => isEvmChain
|
|
36
31
|
});
|
|
37
32
|
module.exports = __toCommonJS(core_exports);
|
|
38
33
|
|
|
39
|
-
// src/core/token-list.ts
|
|
40
|
-
var import_intents_sdk = require("@shogun-sdk/intents-sdk");
|
|
41
|
-
async function getTokenList(params) {
|
|
42
|
-
return (0, import_intents_sdk.getTokenList)(params);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
34
|
// src/core/getQuote.ts
|
|
46
|
-
var import_intents_sdk4 = require("@shogun-sdk/intents-sdk");
|
|
47
|
-
var import_viem = require("viem");
|
|
48
|
-
|
|
49
|
-
// src/core/executeOrder/normalizeNative.ts
|
|
50
35
|
var import_intents_sdk3 = require("@shogun-sdk/intents-sdk");
|
|
36
|
+
var import_viem2 = require("viem");
|
|
37
|
+
|
|
38
|
+
// src/core/execute/normalizeNative.ts
|
|
39
|
+
var import_intents_sdk2 = require("@shogun-sdk/intents-sdk");
|
|
51
40
|
|
|
52
41
|
// src/utils/address.ts
|
|
42
|
+
var import_viem = require("viem");
|
|
53
43
|
var NATIVE_TOKEN = {
|
|
54
44
|
ETH: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
|
55
45
|
SOL: "So11111111111111111111111111111111111111111",
|
|
@@ -60,13 +50,32 @@ var isNativeAddress = (tokenAddress) => {
|
|
|
60
50
|
const normalizedTokenAddress = tokenAddress.toLowerCase();
|
|
61
51
|
return !!tokenAddress && NATIVE_ADDRESSES.includes(normalizedTokenAddress);
|
|
62
52
|
};
|
|
53
|
+
function normalizeEvmTokenAddress(address) {
|
|
54
|
+
const lower = address.toLowerCase();
|
|
55
|
+
return lower === NATIVE_TOKEN.ETH.toLowerCase() ? import_viem.zeroAddress : address;
|
|
56
|
+
}
|
|
63
57
|
|
|
64
58
|
// src/utils/chain.ts
|
|
65
|
-
var
|
|
66
|
-
var SOLANA_CHAIN_ID =
|
|
67
|
-
var
|
|
59
|
+
var import_intents_sdk = require("@shogun-sdk/intents-sdk");
|
|
60
|
+
var SOLANA_CHAIN_ID = import_intents_sdk.ChainID.Solana;
|
|
61
|
+
var CURRENT_SUPPORTED = [
|
|
62
|
+
import_intents_sdk.ChainID.Solana,
|
|
63
|
+
import_intents_sdk.ChainID.BSC,
|
|
64
|
+
import_intents_sdk.ChainID.Base,
|
|
65
|
+
import_intents_sdk.ChainID.MONAD
|
|
66
|
+
];
|
|
67
|
+
var ChainId = Object.entries(import_intents_sdk.ChainID).reduce(
|
|
68
|
+
(acc, [key, value]) => {
|
|
69
|
+
if (typeof value === "number" && CURRENT_SUPPORTED.includes(value)) {
|
|
70
|
+
acc[key] = value;
|
|
71
|
+
}
|
|
72
|
+
return acc;
|
|
73
|
+
},
|
|
74
|
+
{}
|
|
75
|
+
);
|
|
76
|
+
var SupportedChainsInternal = [
|
|
68
77
|
{
|
|
69
|
-
id:
|
|
78
|
+
id: import_intents_sdk.ChainID.Arbitrum,
|
|
70
79
|
name: "Arbitrum",
|
|
71
80
|
isEVM: true,
|
|
72
81
|
wrapped: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
@@ -75,7 +84,7 @@ var SupportedChains = [
|
|
|
75
84
|
tokenAddress: NATIVE_TOKEN.ETH
|
|
76
85
|
},
|
|
77
86
|
{
|
|
78
|
-
id:
|
|
87
|
+
id: import_intents_sdk.ChainID.Optimism,
|
|
79
88
|
name: "Optimism",
|
|
80
89
|
isEVM: true,
|
|
81
90
|
wrapped: "0x4200000000000000000000000000000000000006",
|
|
@@ -84,7 +93,7 @@ var SupportedChains = [
|
|
|
84
93
|
tokenAddress: NATIVE_TOKEN.ETH
|
|
85
94
|
},
|
|
86
95
|
{
|
|
87
|
-
id:
|
|
96
|
+
id: import_intents_sdk.ChainID.Base,
|
|
88
97
|
name: "Base",
|
|
89
98
|
isEVM: true,
|
|
90
99
|
wrapped: "0x4200000000000000000000000000000000000006",
|
|
@@ -93,7 +102,7 @@ var SupportedChains = [
|
|
|
93
102
|
tokenAddress: NATIVE_TOKEN.ETH
|
|
94
103
|
},
|
|
95
104
|
{
|
|
96
|
-
id:
|
|
105
|
+
id: import_intents_sdk.ChainID.Hyperliquid,
|
|
97
106
|
name: "Hyperliquid",
|
|
98
107
|
isEVM: true,
|
|
99
108
|
wrapped: "0x5555555555555555555555555555555555555555",
|
|
@@ -102,7 +111,7 @@ var SupportedChains = [
|
|
|
102
111
|
tokenAddress: NATIVE_TOKEN.ETH
|
|
103
112
|
},
|
|
104
113
|
{
|
|
105
|
-
id:
|
|
114
|
+
id: import_intents_sdk.ChainID.BSC,
|
|
106
115
|
name: "BSC",
|
|
107
116
|
isEVM: true,
|
|
108
117
|
wrapped: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
|
|
@@ -118,8 +127,21 @@ var SupportedChains = [
|
|
|
118
127
|
symbol: "SOL",
|
|
119
128
|
decimals: 9,
|
|
120
129
|
tokenAddress: NATIVE_TOKEN.SOL
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
id: import_intents_sdk.ChainID.MONAD,
|
|
133
|
+
name: "Monad",
|
|
134
|
+
isEVM: true,
|
|
135
|
+
wrapped: "0x3bd359C1119dA7Da1D913D1C4D2B7c461115433A",
|
|
136
|
+
symbol: "MON",
|
|
137
|
+
decimals: 18,
|
|
138
|
+
tokenAddress: NATIVE_TOKEN.ETH
|
|
121
139
|
}
|
|
122
140
|
];
|
|
141
|
+
var SupportedChains = SupportedChainsInternal.filter(
|
|
142
|
+
(c) => CURRENT_SUPPORTED.includes(c.id)
|
|
143
|
+
);
|
|
144
|
+
var isEvmChain = import_intents_sdk.isEvmChain;
|
|
123
145
|
|
|
124
146
|
// src/utils/viem.ts
|
|
125
147
|
function isViemWalletClient(wallet) {
|
|
@@ -147,9 +169,9 @@ function serializeBigIntsToStrings(obj) {
|
|
|
147
169
|
return obj;
|
|
148
170
|
}
|
|
149
171
|
|
|
150
|
-
// src/core/
|
|
172
|
+
// src/core/execute/normalizeNative.ts
|
|
151
173
|
function normalizeNative(chainId, address) {
|
|
152
|
-
if ((0,
|
|
174
|
+
if ((0, import_intents_sdk2.isEvmChain)(chainId) && isNativeAddress(address)) {
|
|
153
175
|
const chain = SupportedChains.find((c) => c.id === chainId);
|
|
154
176
|
if (!chain?.wrapped)
|
|
155
177
|
throw new Error(`Wrapped token not found for chainId ${chainId}`);
|
|
@@ -160,39 +182,43 @@ function normalizeNative(chainId, address) {
|
|
|
160
182
|
|
|
161
183
|
// src/core/getQuote.ts
|
|
162
184
|
async function getQuote(params) {
|
|
185
|
+
const amount = BigInt(params.amount);
|
|
163
186
|
if (!params.tokenIn?.address || !params.tokenOut?.address) {
|
|
164
187
|
throw new Error("Both tokenIn and tokenOut must include an address.");
|
|
165
188
|
}
|
|
166
189
|
if (!params.sourceChainId || !params.destChainId) {
|
|
167
190
|
throw new Error("Both sourceChainId and destChainId are required.");
|
|
168
191
|
}
|
|
169
|
-
if (
|
|
192
|
+
if (amount <= 0n) {
|
|
170
193
|
throw new Error("Amount must be greater than 0.");
|
|
171
194
|
}
|
|
172
195
|
const normalizedTokenIn = normalizeNative(params.sourceChainId, params.tokenIn.address);
|
|
173
|
-
const data = await
|
|
196
|
+
const data = await import_intents_sdk3.QuoteProvider.getQuote({
|
|
174
197
|
sourceChainId: params.sourceChainId,
|
|
175
198
|
destChainId: params.destChainId,
|
|
176
199
|
tokenIn: normalizedTokenIn,
|
|
177
200
|
tokenOut: params.tokenOut.address,
|
|
178
|
-
amount
|
|
201
|
+
amount
|
|
179
202
|
});
|
|
180
|
-
const
|
|
181
|
-
const slippageDecimal = inputSlippage / 100;
|
|
182
|
-
const slippage = Math.min(Math.max(slippageDecimal, 0), 0.5);
|
|
203
|
+
const slippagePercent = Math.min(Math.max(params.slippage ?? 0.5, 0), 50);
|
|
183
204
|
let warning;
|
|
184
|
-
if (
|
|
185
|
-
warning = `\u26A0\uFE0F High slippage tolerance (${
|
|
205
|
+
if (slippagePercent > 10) {
|
|
206
|
+
warning = `\u26A0\uFE0F High slippage tolerance (${slippagePercent.toFixed(2)}%) \u2014 price may vary significantly.`;
|
|
186
207
|
}
|
|
187
|
-
const estimatedAmountOut = BigInt(data.
|
|
188
|
-
const slippageBps = BigInt(Math.round(
|
|
208
|
+
const estimatedAmountOut = BigInt(data.estimatedAmountOut);
|
|
209
|
+
const slippageBps = BigInt(Math.round(slippagePercent * 100));
|
|
189
210
|
const estimatedAmountOutAfterSlippage = estimatedAmountOut * (10000n - slippageBps) / 10000n;
|
|
211
|
+
const pricePerTokenOutInUsd = data.estimatedAmountOutUsd / Number(data.estimatedAmountOut);
|
|
212
|
+
const amountOutUsdAfterSlippage = Number(estimatedAmountOutAfterSlippage) * pricePerTokenOutInUsd;
|
|
213
|
+
const minStablecoinsAmountValue = BigInt(data.estimatedAmountInAsMinStablecoinAmount);
|
|
214
|
+
const minStablecoinsAmountAfterSlippage = minStablecoinsAmountValue * (10000n - slippageBps) / 10000n;
|
|
190
215
|
const pricePerInputToken = estimatedAmountOut * 10n ** BigInt(params.tokenIn.decimals ?? 18) / BigInt(params.amount);
|
|
191
216
|
return {
|
|
192
|
-
amountOut:
|
|
193
|
-
amountOutUsd:
|
|
217
|
+
amountOut: estimatedAmountOutAfterSlippage,
|
|
218
|
+
amountOutUsd: amountOutUsdAfterSlippage,
|
|
194
219
|
amountInUsd: data.amountInUsd,
|
|
195
|
-
|
|
220
|
+
// Input USD stays the same
|
|
221
|
+
minStablecoinsAmount: minStablecoinsAmountAfterSlippage,
|
|
196
222
|
tokenIn: {
|
|
197
223
|
address: params.tokenIn.address,
|
|
198
224
|
decimals: params.tokenIn.decimals ?? 18,
|
|
@@ -203,12 +229,13 @@ async function getQuote(params) {
|
|
|
203
229
|
decimals: params.tokenOut.decimals ?? 18,
|
|
204
230
|
chainId: params.destChainId
|
|
205
231
|
},
|
|
206
|
-
amountIn: params.amount,
|
|
232
|
+
amountIn: BigInt(params.amount),
|
|
207
233
|
pricePerInputToken,
|
|
208
|
-
slippage,
|
|
234
|
+
slippage: slippagePercent,
|
|
209
235
|
internal: {
|
|
210
236
|
...data,
|
|
211
|
-
estimatedAmountOutReduced: estimatedAmountOutAfterSlippage
|
|
237
|
+
estimatedAmountOutReduced: estimatedAmountOutAfterSlippage,
|
|
238
|
+
estimatedAmountOutUsdReduced: amountOutUsdAfterSlippage
|
|
212
239
|
},
|
|
213
240
|
warning
|
|
214
241
|
};
|
|
@@ -226,13 +253,13 @@ function buildQuoteParams({
|
|
|
226
253
|
tokenOut,
|
|
227
254
|
sourceChainId,
|
|
228
255
|
destChainId,
|
|
229
|
-
amount: (0,
|
|
256
|
+
amount: (0, import_viem2.parseUnits)(amount.toString(), tokenIn.decimals ?? 18).toString(),
|
|
230
257
|
slippage
|
|
231
258
|
};
|
|
232
259
|
}
|
|
233
260
|
|
|
234
261
|
// src/core/getBalances.ts
|
|
235
|
-
var
|
|
262
|
+
var import_intents_sdk4 = require("@shogun-sdk/intents-sdk");
|
|
236
263
|
async function getBalances(params, options) {
|
|
237
264
|
const { addresses, cursorEvm, cursorSvm } = params;
|
|
238
265
|
const { signal } = options ?? {};
|
|
@@ -245,7 +272,7 @@ async function getBalances(params, options) {
|
|
|
245
272
|
cursorSvm
|
|
246
273
|
});
|
|
247
274
|
const start = performance.now();
|
|
248
|
-
const response = await fetch(`${
|
|
275
|
+
const response = await fetch(`${import_intents_sdk4.TOKEN_SEARCH_API_BASE_URL}/tokens/balances`, {
|
|
249
276
|
method: "POST",
|
|
250
277
|
headers: {
|
|
251
278
|
accept: "application/json",
|
|
@@ -273,21 +300,67 @@ async function getBalances(params, options) {
|
|
|
273
300
|
const evmItems = data.evm?.items ?? [];
|
|
274
301
|
const svmItems = data.svm?.items ?? [];
|
|
275
302
|
const combined = [...evmItems, ...svmItems];
|
|
303
|
+
const filtered = combined.filter(
|
|
304
|
+
(b) => CURRENT_SUPPORTED.includes(b.chainId)
|
|
305
|
+
);
|
|
276
306
|
return {
|
|
277
|
-
results:
|
|
307
|
+
results: filtered,
|
|
278
308
|
nextCursorEvm: data.evm?.cursor ?? null,
|
|
279
309
|
nextCursorSvm: data.svm?.cursor ?? null
|
|
280
310
|
};
|
|
281
311
|
}
|
|
282
312
|
|
|
283
|
-
// src/core/
|
|
284
|
-
var
|
|
285
|
-
|
|
313
|
+
// src/core/token-list.ts
|
|
314
|
+
var import_intents_sdk5 = require("@shogun-sdk/intents-sdk");
|
|
315
|
+
async function getTokenList(params) {
|
|
316
|
+
const url = new URL(`${import_intents_sdk5.TOKEN_SEARCH_API_BASE_URL}/tokens/search`);
|
|
317
|
+
if (params.q) url.searchParams.append("q", params.q);
|
|
318
|
+
if (params.networkId) url.searchParams.append("networkId", String(params.networkId));
|
|
319
|
+
if (params.page) url.searchParams.append("page", String(params.page));
|
|
320
|
+
if (params.limit) url.searchParams.append("limit", String(params.limit));
|
|
321
|
+
const res = await fetch(url.toString(), {
|
|
322
|
+
signal: params.signal
|
|
323
|
+
});
|
|
324
|
+
if (!res.ok) {
|
|
325
|
+
throw new Error(`Failed to fetch tokens: ${res.status} ${res.statusText}`);
|
|
326
|
+
}
|
|
327
|
+
const data = await res.json();
|
|
328
|
+
const filteredResults = data.results.filter(
|
|
329
|
+
(token) => CURRENT_SUPPORTED.includes(token.chainId)
|
|
330
|
+
);
|
|
331
|
+
return {
|
|
332
|
+
...data,
|
|
333
|
+
results: filteredResults,
|
|
334
|
+
count: filteredResults.length
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// src/core/token.ts
|
|
339
|
+
var import_intents_sdk6 = require("@shogun-sdk/intents-sdk");
|
|
340
|
+
async function getTokensData(addresses) {
|
|
341
|
+
if (!addresses?.length) return [];
|
|
342
|
+
const response = await fetch(`${import_intents_sdk6.TOKEN_SEARCH_API_BASE_URL}/tokens/tokens`, {
|
|
343
|
+
method: "POST",
|
|
344
|
+
headers: {
|
|
345
|
+
"Content-Type": "application/json",
|
|
346
|
+
accept: "*/*"
|
|
347
|
+
},
|
|
348
|
+
body: JSON.stringify({ addresses })
|
|
349
|
+
});
|
|
350
|
+
if (!response.ok) {
|
|
351
|
+
throw new Error(`Failed to fetch token data: ${response.statusText}`);
|
|
352
|
+
}
|
|
353
|
+
const data = await response.json();
|
|
354
|
+
const filtered = data.filter((t) => CURRENT_SUPPORTED.includes(Number(t.chainId)));
|
|
355
|
+
return filtered;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// src/core/execute/execute.ts
|
|
359
|
+
var import_intents_sdk12 = require("@shogun-sdk/intents-sdk");
|
|
360
|
+
var import_viem7 = require("viem");
|
|
286
361
|
|
|
287
362
|
// src/wallet-adapter/evm-wallet-adapter/adapter.ts
|
|
288
|
-
var
|
|
289
|
-
var import_utils2 = require("ethers/lib/utils.js");
|
|
290
|
-
var import_viem2 = require("viem");
|
|
363
|
+
var import_viem3 = require("viem");
|
|
291
364
|
function isEVMTransaction(tx) {
|
|
292
365
|
return typeof tx.from === "string";
|
|
293
366
|
}
|
|
@@ -305,15 +378,26 @@ var adaptViemWallet = (wallet) => {
|
|
|
305
378
|
if (!isEVMTransaction(transaction)) {
|
|
306
379
|
throw new Error("Expected EVMTransaction but got SolanaTransaction");
|
|
307
380
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
381
|
+
if (wallet.transport.type === "http") {
|
|
382
|
+
const request = await wallet.prepareTransactionRequest({
|
|
383
|
+
to: transaction.to,
|
|
384
|
+
data: transaction.data,
|
|
385
|
+
value: transaction.value,
|
|
386
|
+
chain: wallet.chain
|
|
387
|
+
});
|
|
388
|
+
const serializedTransaction = await wallet.signTransaction(request);
|
|
389
|
+
const tx = await wallet.sendRawTransaction({ serializedTransaction });
|
|
390
|
+
return tx;
|
|
391
|
+
} else {
|
|
392
|
+
const hash = await wallet.sendTransaction({
|
|
393
|
+
to: transaction.to,
|
|
394
|
+
data: transaction.data,
|
|
395
|
+
value: transaction.value,
|
|
396
|
+
chain: wallet.chain,
|
|
397
|
+
account: wallet.account
|
|
398
|
+
});
|
|
399
|
+
return hash;
|
|
400
|
+
}
|
|
317
401
|
};
|
|
318
402
|
const switchChain = async (chainId) => {
|
|
319
403
|
try {
|
|
@@ -336,55 +420,96 @@ var adaptViemWallet = (wallet) => {
|
|
|
336
420
|
if (!addr) throw new Error("No address found");
|
|
337
421
|
return addr;
|
|
338
422
|
};
|
|
423
|
+
const readContract = async ({
|
|
424
|
+
address: address2,
|
|
425
|
+
abi,
|
|
426
|
+
functionName,
|
|
427
|
+
args = []
|
|
428
|
+
}) => {
|
|
429
|
+
const publicClient = wallet.extend(import_viem3.publicActions);
|
|
430
|
+
return await publicClient.readContract({
|
|
431
|
+
address: address2,
|
|
432
|
+
abi,
|
|
433
|
+
functionName,
|
|
434
|
+
args
|
|
435
|
+
});
|
|
436
|
+
};
|
|
339
437
|
return {
|
|
340
438
|
vmType: "EVM" /* EVM */,
|
|
341
|
-
transport: (0,
|
|
439
|
+
transport: (0, import_viem3.custom)(wallet.transport),
|
|
342
440
|
getChainId: async () => wallet.getChainId(),
|
|
343
441
|
address,
|
|
344
442
|
sendTransaction,
|
|
345
443
|
signTypedData,
|
|
346
|
-
switchChain
|
|
444
|
+
switchChain,
|
|
445
|
+
readContract
|
|
347
446
|
};
|
|
348
447
|
};
|
|
349
448
|
|
|
350
|
-
// src/core/
|
|
351
|
-
var
|
|
352
|
-
var
|
|
449
|
+
// src/core/execute/handleEvmExecution.ts
|
|
450
|
+
var import_intents_sdk10 = require("@shogun-sdk/intents-sdk");
|
|
451
|
+
var import_viem6 = require("viem");
|
|
353
452
|
|
|
354
|
-
// src/core/
|
|
453
|
+
// src/core/execute/stageMessages.ts
|
|
355
454
|
var DEFAULT_STAGE_MESSAGES = {
|
|
356
455
|
processing: "Preparing transaction for execution",
|
|
357
456
|
approving: "Approving token allowance",
|
|
358
457
|
approved: "Token approved successfully",
|
|
359
|
-
signing: "Signing
|
|
360
|
-
submitting: "Submitting
|
|
361
|
-
|
|
362
|
-
|
|
458
|
+
signing: "Signing transaction for submission",
|
|
459
|
+
submitting: "Submitting transaction",
|
|
460
|
+
initiated: "Transaction initiated.",
|
|
461
|
+
success: "Transaction Executed successfully",
|
|
462
|
+
success_limit: "Limit order has been submitted successfully.",
|
|
463
|
+
shogun_processing: "Shogun is processing your transaction",
|
|
464
|
+
error: "Transaction failed during submission"
|
|
363
465
|
};
|
|
364
466
|
|
|
365
|
-
// src/core/
|
|
366
|
-
var
|
|
467
|
+
// src/core/execute/buildOrder.ts
|
|
468
|
+
var import_intents_sdk7 = require("@shogun-sdk/intents-sdk");
|
|
469
|
+
var import_viem4 = require("viem");
|
|
470
|
+
|
|
471
|
+
// src/utils/order.ts
|
|
472
|
+
var OrderExecutionType = /* @__PURE__ */ ((OrderExecutionType2) => {
|
|
473
|
+
OrderExecutionType2["LIMIT"] = "limit";
|
|
474
|
+
OrderExecutionType2["MARKET"] = "market";
|
|
475
|
+
return OrderExecutionType2;
|
|
476
|
+
})(OrderExecutionType || {});
|
|
477
|
+
|
|
478
|
+
// src/core/execute/buildOrder.ts
|
|
367
479
|
async function buildOrder({
|
|
368
480
|
quote,
|
|
369
481
|
accountAddress,
|
|
370
482
|
destination,
|
|
371
483
|
deadline,
|
|
372
|
-
isSingleChain
|
|
484
|
+
isSingleChain,
|
|
485
|
+
orderType,
|
|
486
|
+
options
|
|
373
487
|
}) {
|
|
374
488
|
const { tokenIn, tokenOut } = quote;
|
|
489
|
+
let amountOutMin = BigInt(quote.internal.estimatedAmountOutReduced);
|
|
490
|
+
if (orderType === "limit" /* LIMIT */ && options && "executionPrice" in options) {
|
|
491
|
+
const executionPrice = Number(options.executionPrice);
|
|
492
|
+
if (Number.isFinite(executionPrice) && executionPrice > 0) {
|
|
493
|
+
const decimalsIn = tokenIn.decimals ?? 18;
|
|
494
|
+
const decimalsOut = tokenOut.decimals ?? 18;
|
|
495
|
+
const formattedAmountIn = Number((0, import_viem4.formatUnits)(BigInt(quote.amountIn.toString()), decimalsIn));
|
|
496
|
+
const rawAmountOut = formattedAmountIn * executionPrice;
|
|
497
|
+
amountOutMin = (0, import_viem4.parseUnits)(rawAmountOut.toString(), decimalsOut);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
375
500
|
if (isSingleChain) {
|
|
376
|
-
return await
|
|
501
|
+
return await import_intents_sdk7.SingleChainOrder.create({
|
|
377
502
|
user: accountAddress,
|
|
378
503
|
chainId: tokenIn.chainId,
|
|
379
504
|
tokenIn: tokenIn.address,
|
|
380
505
|
tokenOut: tokenOut.address,
|
|
381
506
|
amountIn: quote.amountIn,
|
|
382
|
-
amountOutMin
|
|
507
|
+
amountOutMin,
|
|
383
508
|
deadline,
|
|
384
509
|
destinationAddress: destination
|
|
385
510
|
});
|
|
386
511
|
}
|
|
387
|
-
return await
|
|
512
|
+
return await import_intents_sdk7.CrossChainOrder.create({
|
|
388
513
|
user: accountAddress,
|
|
389
514
|
sourceChainId: tokenIn.chainId,
|
|
390
515
|
sourceTokenAddress: tokenIn.address,
|
|
@@ -393,12 +518,161 @@ async function buildOrder({
|
|
|
393
518
|
destinationTokenAddress: tokenOut.address,
|
|
394
519
|
destinationAddress: destination,
|
|
395
520
|
deadline,
|
|
396
|
-
destinationTokenMinAmount:
|
|
521
|
+
destinationTokenMinAmount: amountOutMin,
|
|
397
522
|
minStablecoinAmount: quote.minStablecoinsAmount
|
|
398
523
|
});
|
|
399
524
|
}
|
|
400
525
|
|
|
401
|
-
// src/
|
|
526
|
+
// src/utils/pollOrderStatus.ts
|
|
527
|
+
var import_intents_sdk8 = require("@shogun-sdk/intents-sdk");
|
|
528
|
+
async function pollOrderStatus(address, orderId, options = {}) {
|
|
529
|
+
const { intervalMs = 2e3, timeoutMs = 3e5 } = options;
|
|
530
|
+
const startTime = Date.now();
|
|
531
|
+
const isDebug = process.env.NODE_ENV !== "production";
|
|
532
|
+
const isEvmAddress = /^0x[a-fA-F0-9]{40}$/.test(address);
|
|
533
|
+
const isSuiAddress = /^0x[a-fA-F0-9]{64}$/.test(address);
|
|
534
|
+
const isSolanaAddress = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(address);
|
|
535
|
+
let queryParam;
|
|
536
|
+
if (isEvmAddress) queryParam = `evmWallets=${address}`;
|
|
537
|
+
else if (isSuiAddress) queryParam = `suiWallets=${address}`;
|
|
538
|
+
else if (isSolanaAddress) queryParam = `solanaWallets=${address}`;
|
|
539
|
+
else throw new Error(`Unrecognized wallet address format: ${address}`);
|
|
540
|
+
const queryUrl = `${import_intents_sdk8.AUCTIONEER_URL}/user_intent?${queryParam}`;
|
|
541
|
+
return new Promise((resolve, reject) => {
|
|
542
|
+
const pollInterval = setInterval(async () => {
|
|
543
|
+
try {
|
|
544
|
+
if (Date.now() - startTime > timeoutMs) {
|
|
545
|
+
clearInterval(pollInterval);
|
|
546
|
+
return resolve("Timeout");
|
|
547
|
+
}
|
|
548
|
+
const res = await fetch(queryUrl, {
|
|
549
|
+
method: "GET",
|
|
550
|
+
headers: { "Content-Type": "application/json" }
|
|
551
|
+
});
|
|
552
|
+
if (!res.ok) {
|
|
553
|
+
clearInterval(pollInterval);
|
|
554
|
+
return reject(
|
|
555
|
+
new Error(`Failed to fetch orders: ${res.status} ${res.statusText}`)
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
const json = await res.json();
|
|
559
|
+
const data = json?.data ?? {};
|
|
560
|
+
const allOrders = [
|
|
561
|
+
...data.crossChainDcaOrders ?? [],
|
|
562
|
+
...data.crossChainLimitOrders ?? [],
|
|
563
|
+
...data.singleChainDcaOrders ?? [],
|
|
564
|
+
...data.singleChainLimitOrders ?? []
|
|
565
|
+
];
|
|
566
|
+
const targetOrder = allOrders.find((o) => o.orderId === orderId);
|
|
567
|
+
if (!targetOrder) {
|
|
568
|
+
if (isDebug)
|
|
569
|
+
console.debug(`[pollOrderStatus] [${orderId}] Not found yet`);
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
const { orderStatus } = targetOrder;
|
|
573
|
+
if (isDebug) {
|
|
574
|
+
const elapsed = ((Date.now() - startTime) / 1e3).toFixed(1);
|
|
575
|
+
console.debug(`targetOrder`, targetOrder);
|
|
576
|
+
console.debug(
|
|
577
|
+
`[pollOrderStatus] [${orderId}] status=${orderStatus} (elapsed ${elapsed}s)`
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
if (["Fulfilled", "Cancelled", "Outdated"].includes(orderStatus)) {
|
|
581
|
+
clearInterval(pollInterval);
|
|
582
|
+
return resolve(orderStatus);
|
|
583
|
+
}
|
|
584
|
+
} catch (error) {
|
|
585
|
+
clearInterval(pollInterval);
|
|
586
|
+
return reject(error);
|
|
587
|
+
}
|
|
588
|
+
}, intervalMs);
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// src/core/execute/handleOrderPollingResult.ts
|
|
593
|
+
async function handleOrderPollingResult({
|
|
594
|
+
status,
|
|
595
|
+
orderId,
|
|
596
|
+
chainId,
|
|
597
|
+
update,
|
|
598
|
+
messageFor
|
|
599
|
+
}) {
|
|
600
|
+
switch (status) {
|
|
601
|
+
case "Fulfilled":
|
|
602
|
+
update("success", messageFor("success"));
|
|
603
|
+
return {
|
|
604
|
+
status: true,
|
|
605
|
+
orderId,
|
|
606
|
+
chainId,
|
|
607
|
+
finalStatus: status,
|
|
608
|
+
stage: "success"
|
|
609
|
+
};
|
|
610
|
+
case "Cancelled":
|
|
611
|
+
update("error", "Order was cancelled before fulfillment");
|
|
612
|
+
break;
|
|
613
|
+
case "Timeout":
|
|
614
|
+
update("error", "Order polling timed out");
|
|
615
|
+
break;
|
|
616
|
+
case "NotFound":
|
|
617
|
+
default:
|
|
618
|
+
update("error", "Order not found");
|
|
619
|
+
break;
|
|
620
|
+
}
|
|
621
|
+
return {
|
|
622
|
+
status: false,
|
|
623
|
+
orderId,
|
|
624
|
+
chainId,
|
|
625
|
+
finalStatus: status,
|
|
626
|
+
stage: "error"
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// src/core/execute/ensurePermit2Allowance.ts
|
|
631
|
+
var import_viem5 = require("viem");
|
|
632
|
+
var import_intents_sdk9 = require("@shogun-sdk/intents-sdk");
|
|
633
|
+
async function ensurePermit2Allowance({
|
|
634
|
+
chainId,
|
|
635
|
+
tokenIn,
|
|
636
|
+
wallet,
|
|
637
|
+
accountAddress,
|
|
638
|
+
requiredAmount,
|
|
639
|
+
increaseByDelta = false
|
|
640
|
+
}) {
|
|
641
|
+
const spender = import_intents_sdk9.PERMIT2_ADDRESS[chainId];
|
|
642
|
+
let currentAllowance = 0n;
|
|
643
|
+
try {
|
|
644
|
+
if (!wallet.readContract) {
|
|
645
|
+
throw new Error("Wallet does not implement readContract()");
|
|
646
|
+
}
|
|
647
|
+
currentAllowance = await wallet.readContract({
|
|
648
|
+
address: tokenIn,
|
|
649
|
+
abi: import_viem5.erc20Abi,
|
|
650
|
+
functionName: "allowance",
|
|
651
|
+
args: [accountAddress, spender]
|
|
652
|
+
});
|
|
653
|
+
} catch (error) {
|
|
654
|
+
console.warn(`[Permit2] Failed to read allowance for ${tokenIn}`, error);
|
|
655
|
+
}
|
|
656
|
+
const approvalAmount = increaseByDelta ? currentAllowance + requiredAmount : import_viem5.maxUint256;
|
|
657
|
+
console.debug(
|
|
658
|
+
`[Permit2] Approving ${approvalAmount} for ${tokenIn} (current: ${currentAllowance}, required: ${requiredAmount})`
|
|
659
|
+
);
|
|
660
|
+
await wallet.sendTransaction({
|
|
661
|
+
to: tokenIn,
|
|
662
|
+
from: accountAddress,
|
|
663
|
+
data: (0, import_viem5.encodeFunctionData)({
|
|
664
|
+
abi: import_viem5.erc20Abi,
|
|
665
|
+
functionName: "approve",
|
|
666
|
+
args: [spender, approvalAmount]
|
|
667
|
+
}),
|
|
668
|
+
value: 0n
|
|
669
|
+
});
|
|
670
|
+
console.info(
|
|
671
|
+
`[Permit2] Approval transaction sent for ${tokenIn} on chain ${chainId}`
|
|
672
|
+
);
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// src/core/execute/handleEvmExecution.ts
|
|
402
676
|
async function handleEvmExecution({
|
|
403
677
|
recipientAddress,
|
|
404
678
|
quote,
|
|
@@ -406,18 +680,22 @@ async function handleEvmExecution({
|
|
|
406
680
|
accountAddress,
|
|
407
681
|
wallet,
|
|
408
682
|
isSingleChain,
|
|
409
|
-
|
|
410
|
-
|
|
683
|
+
update,
|
|
684
|
+
orderType,
|
|
685
|
+
options
|
|
411
686
|
}) {
|
|
412
|
-
const messageFor = (stage) => DEFAULT_STAGE_MESSAGES[stage];
|
|
687
|
+
const messageFor = (stage) => DEFAULT_STAGE_MESSAGES[stage] ?? "";
|
|
688
|
+
const deadline = options?.deadline ?? Math.floor(Date.now() / 1e3) + 20 * 60;
|
|
413
689
|
await wallet.switchChain(chainId);
|
|
414
690
|
const tokenIn = normalizeNative(chainId, quote.tokenIn.address);
|
|
691
|
+
quote.tokenOut.address = normalizeEvmTokenAddress(quote.tokenOut.address);
|
|
415
692
|
const shouldWrapNative = isNativeAddress(quote.tokenIn.address);
|
|
416
693
|
update("processing", shouldWrapNative ? `${messageFor("processing")} (wrapping native token)` : messageFor("processing"));
|
|
417
694
|
if (shouldWrapNative) {
|
|
695
|
+
quote.tokenIn.address === tokenIn;
|
|
418
696
|
await wallet.sendTransaction({
|
|
419
697
|
to: tokenIn,
|
|
420
|
-
data: (0,
|
|
698
|
+
data: (0, import_viem6.encodeFunctionData)({
|
|
421
699
|
abi: [{ type: "function", name: "deposit", stateMutability: "payable", inputs: [], outputs: [] }],
|
|
422
700
|
functionName: "deposit",
|
|
423
701
|
args: []
|
|
@@ -426,43 +704,70 @@ async function handleEvmExecution({
|
|
|
426
704
|
from: accountAddress
|
|
427
705
|
});
|
|
428
706
|
}
|
|
429
|
-
update("
|
|
430
|
-
await
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
}),
|
|
437
|
-
value: 0n,
|
|
438
|
-
from: accountAddress
|
|
707
|
+
update("processing", messageFor("approving"));
|
|
708
|
+
await ensurePermit2Allowance({
|
|
709
|
+
chainId,
|
|
710
|
+
tokenIn,
|
|
711
|
+
wallet,
|
|
712
|
+
accountAddress,
|
|
713
|
+
requiredAmount: BigInt(quote.amountIn)
|
|
439
714
|
});
|
|
440
|
-
update("
|
|
715
|
+
update("processing", messageFor("approved"));
|
|
441
716
|
const destination = recipientAddress ?? accountAddress;
|
|
442
717
|
const order = await buildOrder({
|
|
443
718
|
quote,
|
|
444
719
|
accountAddress,
|
|
445
720
|
destination,
|
|
446
721
|
deadline,
|
|
447
|
-
isSingleChain
|
|
722
|
+
isSingleChain,
|
|
723
|
+
orderType,
|
|
724
|
+
options
|
|
448
725
|
});
|
|
449
|
-
|
|
450
|
-
|
|
726
|
+
console.debug(`order`, order);
|
|
727
|
+
update("processing", messageFor("signing"));
|
|
728
|
+
const { orderTypedData, nonce } = isSingleChain ? await (0, import_intents_sdk10.getEVMSingleChainOrderTypedData)(order) : await (0, import_intents_sdk10.getEVMCrossChainOrderTypedData)(order);
|
|
729
|
+
const typedData = serializeBigIntsToStrings(orderTypedData);
|
|
451
730
|
if (!wallet.signTypedData) {
|
|
452
731
|
throw new Error("Wallet does not support EIP-712 signing");
|
|
453
732
|
}
|
|
454
|
-
const signature = await wallet.signTypedData(
|
|
455
|
-
|
|
733
|
+
const signature = await wallet.signTypedData({
|
|
734
|
+
domain: typedData.domain,
|
|
735
|
+
types: typedData.types,
|
|
736
|
+
primaryType: typedData.primaryType,
|
|
737
|
+
value: typedData.message,
|
|
738
|
+
message: typedData.message
|
|
739
|
+
});
|
|
740
|
+
update("processing", messageFor("submitting"));
|
|
456
741
|
const res = await order.sendToAuctioneer({ signature, nonce: nonce.toString() });
|
|
457
742
|
if (!res.success) {
|
|
458
743
|
throw new Error("Auctioneer submission failed");
|
|
459
744
|
}
|
|
460
|
-
update("
|
|
461
|
-
|
|
745
|
+
update("initiated", messageFor("initiated"));
|
|
746
|
+
const { intentId: orderId } = res.data;
|
|
747
|
+
update("initiated", messageFor("shogun_processing"));
|
|
748
|
+
if (orderType === "limit" /* LIMIT */) {
|
|
749
|
+
update("success", messageFor("success_limit"));
|
|
750
|
+
return {
|
|
751
|
+
status: true,
|
|
752
|
+
orderId,
|
|
753
|
+
chainId,
|
|
754
|
+
finalStatus: "OrderPlaced",
|
|
755
|
+
stage: "success"
|
|
756
|
+
};
|
|
757
|
+
} else {
|
|
758
|
+
const status = await pollOrderStatus(accountAddress, orderId);
|
|
759
|
+
return await handleOrderPollingResult({
|
|
760
|
+
status,
|
|
761
|
+
orderId,
|
|
762
|
+
chainId,
|
|
763
|
+
update,
|
|
764
|
+
messageFor
|
|
765
|
+
});
|
|
766
|
+
}
|
|
462
767
|
}
|
|
463
768
|
|
|
464
|
-
// src/core/
|
|
465
|
-
var
|
|
769
|
+
// src/core/execute/handleSolanaExecution.ts
|
|
770
|
+
var import_intents_sdk11 = require("@shogun-sdk/intents-sdk");
|
|
466
771
|
var import_web3 = require("@solana/web3.js");
|
|
467
772
|
async function handleSolanaExecution({
|
|
468
773
|
recipientAddress,
|
|
@@ -471,12 +776,14 @@ async function handleSolanaExecution({
|
|
|
471
776
|
isSingleChain,
|
|
472
777
|
update,
|
|
473
778
|
accountAddress,
|
|
474
|
-
|
|
779
|
+
orderType,
|
|
780
|
+
options
|
|
475
781
|
}) {
|
|
476
782
|
if (!wallet.rpcUrl) {
|
|
477
783
|
throw new Error("Solana wallet is missing rpcUrl");
|
|
478
784
|
}
|
|
479
|
-
const
|
|
785
|
+
const deadline = options?.deadline ?? Math.floor(Date.now() / 1e3) + 20 * 60;
|
|
786
|
+
const messageFor = (stage) => DEFAULT_STAGE_MESSAGES[stage] ?? "";
|
|
480
787
|
update("processing", messageFor("processing"));
|
|
481
788
|
const destination = recipientAddress ?? accountAddress;
|
|
482
789
|
const order = await buildOrder({
|
|
@@ -484,7 +791,9 @@ async function handleSolanaExecution({
|
|
|
484
791
|
accountAddress,
|
|
485
792
|
destination,
|
|
486
793
|
deadline,
|
|
487
|
-
isSingleChain
|
|
794
|
+
isSingleChain,
|
|
795
|
+
orderType,
|
|
796
|
+
options
|
|
488
797
|
});
|
|
489
798
|
const txData = await getSolanaOrderInstructions({
|
|
490
799
|
order,
|
|
@@ -492,10 +801,9 @@ async function handleSolanaExecution({
|
|
|
492
801
|
rpcUrl: wallet.rpcUrl
|
|
493
802
|
});
|
|
494
803
|
const transaction = import_web3.VersionedTransaction.deserialize(Uint8Array.from(txData.txBytes));
|
|
495
|
-
update("
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
update("submitting", messageFor("submitting"));
|
|
804
|
+
update("processing", messageFor("signing"));
|
|
805
|
+
await wallet.sendTransaction(transaction);
|
|
806
|
+
update("processing", messageFor("submitting"));
|
|
499
807
|
const response = await submitToAuctioneer({
|
|
500
808
|
order,
|
|
501
809
|
isSingleChain,
|
|
@@ -504,13 +812,28 @@ async function handleSolanaExecution({
|
|
|
504
812
|
if (!response.success) {
|
|
505
813
|
throw new Error("Auctioneer submission failed");
|
|
506
814
|
}
|
|
507
|
-
update("
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
815
|
+
update("initiated", messageFor("initiated"));
|
|
816
|
+
const { intentId: orderId } = response.data;
|
|
817
|
+
update("initiated", messageFor("shogun_processing"));
|
|
818
|
+
if (orderType === "limit" /* LIMIT */) {
|
|
819
|
+
update("success", messageFor("success_limit"));
|
|
820
|
+
return {
|
|
821
|
+
status: true,
|
|
822
|
+
orderId,
|
|
823
|
+
chainId: SOLANA_CHAIN_ID,
|
|
824
|
+
finalStatus: "OrderPlaced",
|
|
825
|
+
stage: "success"
|
|
826
|
+
};
|
|
827
|
+
} else {
|
|
828
|
+
const status = await pollOrderStatus(accountAddress, orderId);
|
|
829
|
+
return await handleOrderPollingResult({
|
|
830
|
+
status,
|
|
831
|
+
orderId,
|
|
832
|
+
chainId: SOLANA_CHAIN_ID,
|
|
833
|
+
update,
|
|
834
|
+
messageFor
|
|
835
|
+
});
|
|
836
|
+
}
|
|
514
837
|
}
|
|
515
838
|
async function getSolanaOrderInstructions({
|
|
516
839
|
order,
|
|
@@ -518,11 +841,11 @@ async function getSolanaOrderInstructions({
|
|
|
518
841
|
rpcUrl
|
|
519
842
|
}) {
|
|
520
843
|
if (isSingleChain) {
|
|
521
|
-
return await (0,
|
|
844
|
+
return await (0, import_intents_sdk11.getSolanaSingleChainOrderInstructions)(order, {
|
|
522
845
|
rpcUrl
|
|
523
846
|
});
|
|
524
847
|
}
|
|
525
|
-
return await (0,
|
|
848
|
+
return await (0, import_intents_sdk11.getSolanaCrossChainOrderInstructions)(order, {
|
|
526
849
|
rpcUrl
|
|
527
850
|
});
|
|
528
851
|
}
|
|
@@ -543,52 +866,93 @@ async function submitToAuctioneer({
|
|
|
543
866
|
});
|
|
544
867
|
}
|
|
545
868
|
|
|
546
|
-
// src/core/
|
|
869
|
+
// src/core/execute/execute.ts
|
|
547
870
|
async function executeOrder({
|
|
548
871
|
quote,
|
|
549
872
|
accountAddress,
|
|
550
873
|
recipientAddress,
|
|
551
874
|
wallet,
|
|
552
875
|
onStatus,
|
|
876
|
+
orderType = "market" /* MARKET */,
|
|
553
877
|
options = {}
|
|
554
878
|
}) {
|
|
555
|
-
const
|
|
879
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
880
|
+
const log = (...args) => {
|
|
881
|
+
if (isDev) console.debug("[OneShot::executeOrder]", ...args);
|
|
882
|
+
};
|
|
556
883
|
const messageFor = (stage) => DEFAULT_STAGE_MESSAGES[stage];
|
|
557
|
-
const update = (stage, message) =>
|
|
884
|
+
const update = (stage, message) => {
|
|
885
|
+
log("Stage:", stage, "| Message:", message ?? messageFor(stage));
|
|
886
|
+
onStatus?.(stage, message ?? messageFor(stage));
|
|
887
|
+
};
|
|
558
888
|
try {
|
|
889
|
+
log("Starting execution:", {
|
|
890
|
+
accountAddress,
|
|
891
|
+
recipientAddress,
|
|
892
|
+
tokenIn: quote?.tokenIn,
|
|
893
|
+
tokenOut: quote?.tokenOut
|
|
894
|
+
});
|
|
559
895
|
const adapter = normalizeWallet(wallet);
|
|
560
896
|
if (!adapter) throw new Error("No wallet provided");
|
|
561
897
|
const { tokenIn, tokenOut } = quote;
|
|
898
|
+
const srcChain = Number(tokenIn.chainId);
|
|
899
|
+
const destChain = Number(tokenOut.chainId);
|
|
900
|
+
if (!CURRENT_SUPPORTED.includes(srcChain) || !CURRENT_SUPPORTED.includes(destChain)) {
|
|
901
|
+
const unsupportedChains = [
|
|
902
|
+
!CURRENT_SUPPORTED.includes(srcChain) ? srcChain : null,
|
|
903
|
+
!CURRENT_SUPPORTED.includes(destChain) ? destChain : null
|
|
904
|
+
].filter(Boolean).join(", ");
|
|
905
|
+
const errorMsg = `Unsupported chain(s): ${unsupportedChains}`;
|
|
906
|
+
update("error", errorMsg);
|
|
907
|
+
log("Error:", errorMsg);
|
|
908
|
+
throw new Error(errorMsg);
|
|
909
|
+
}
|
|
562
910
|
const isSingleChain = tokenIn.chainId === tokenOut.chainId;
|
|
563
911
|
const chainId = Number(tokenIn.chainId);
|
|
564
|
-
update("processing"
|
|
565
|
-
if ((0,
|
|
566
|
-
|
|
912
|
+
update("processing");
|
|
913
|
+
if ((0, import_intents_sdk12.isEvmChain)(chainId)) {
|
|
914
|
+
log("Detected EVM chain:", chainId);
|
|
915
|
+
const result = await handleEvmExecution({
|
|
567
916
|
recipientAddress,
|
|
568
917
|
quote,
|
|
569
918
|
chainId,
|
|
570
919
|
accountAddress,
|
|
571
920
|
wallet: adapter,
|
|
572
921
|
isSingleChain,
|
|
573
|
-
|
|
574
|
-
|
|
922
|
+
update,
|
|
923
|
+
orderType,
|
|
924
|
+
options
|
|
575
925
|
});
|
|
926
|
+
log("EVM execution result:", result);
|
|
927
|
+
return result;
|
|
576
928
|
}
|
|
577
|
-
if (chainId ===
|
|
578
|
-
|
|
929
|
+
if (chainId === import_intents_sdk12.ChainID.Solana) {
|
|
930
|
+
log("Detected Solana chain");
|
|
931
|
+
const result = await handleSolanaExecution({
|
|
579
932
|
recipientAddress,
|
|
580
933
|
quote,
|
|
581
934
|
accountAddress,
|
|
582
935
|
wallet: adapter,
|
|
583
936
|
isSingleChain,
|
|
584
|
-
|
|
585
|
-
|
|
937
|
+
update,
|
|
938
|
+
orderType,
|
|
939
|
+
options
|
|
586
940
|
});
|
|
941
|
+
log("Solana execution result:", result);
|
|
942
|
+
return result;
|
|
587
943
|
}
|
|
588
|
-
|
|
589
|
-
|
|
944
|
+
const unsupported = `Unsupported chain: ${chainId}`;
|
|
945
|
+
update("error", unsupported);
|
|
946
|
+
log("Error:", unsupported);
|
|
947
|
+
return { status: false, message: unsupported, stage: "error" };
|
|
590
948
|
} catch (error) {
|
|
591
|
-
|
|
949
|
+
let message = "An unknown error occurred";
|
|
950
|
+
if (error && typeof error === "object") {
|
|
951
|
+
const err = error;
|
|
952
|
+
message = err.details ?? err.message ?? message;
|
|
953
|
+
} else if (typeof error === "string") {
|
|
954
|
+
message = error;
|
|
955
|
+
}
|
|
592
956
|
update("error", message);
|
|
593
957
|
return { status: false, message, stage: "error" };
|
|
594
958
|
}
|
|
@@ -599,21 +963,484 @@ function normalizeWallet(wallet) {
|
|
|
599
963
|
return wallet;
|
|
600
964
|
}
|
|
601
965
|
|
|
602
|
-
// src/core/
|
|
603
|
-
var
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
966
|
+
// src/core/orders/getOrders.ts
|
|
967
|
+
var import_intents_sdk13 = require("@shogun-sdk/intents-sdk");
|
|
968
|
+
async function getOrders({
|
|
969
|
+
evmAddress,
|
|
970
|
+
solAddress
|
|
971
|
+
}) {
|
|
972
|
+
if (!evmAddress && !solAddress) {
|
|
973
|
+
throw new Error("At least one wallet address (EVM, Solana) must be provided.");
|
|
974
|
+
}
|
|
975
|
+
const orders = await (0, import_intents_sdk13.fetchUserOrders)(evmAddress, solAddress);
|
|
976
|
+
return orders;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
// src/core/orders/cancelOrder.ts
|
|
980
|
+
var import_intents_sdk14 = require("@shogun-sdk/intents-sdk");
|
|
981
|
+
var import_web32 = require("@solana/web3.js");
|
|
982
|
+
var import_viem8 = require("viem");
|
|
983
|
+
async function cancelIntentsOrder({
|
|
984
|
+
order,
|
|
985
|
+
wallet,
|
|
986
|
+
sol_rpc
|
|
987
|
+
}) {
|
|
988
|
+
const isCrossChain = "srcChainId" in order && "destChainId" in order && order.srcChainId !== order.destChainId;
|
|
989
|
+
const srcChain = "srcChainId" in order ? order.srcChainId : order.chainId;
|
|
990
|
+
const isSolanaOrder = srcChain === import_intents_sdk14.ChainID.Solana;
|
|
991
|
+
if (isSolanaOrder) {
|
|
992
|
+
if (!isCrossChain) {
|
|
993
|
+
const { versionedMessageBytes: versionedMessageBytes2 } = await (0, import_intents_sdk14.cancelSingleChainOrderInstructionsAsBytes)(
|
|
994
|
+
order.orderId,
|
|
995
|
+
order.user,
|
|
996
|
+
{ rpcUrl: sol_rpc }
|
|
997
|
+
);
|
|
998
|
+
const message2 = import_web32.VersionedMessage.deserialize(
|
|
999
|
+
versionedMessageBytes2
|
|
1000
|
+
);
|
|
1001
|
+
const tx2 = new import_web32.VersionedTransaction(message2);
|
|
1002
|
+
return await wallet.sendTransaction(tx2);
|
|
1003
|
+
}
|
|
1004
|
+
const { versionedMessageBytes } = await (0, import_intents_sdk14.cancelCrossChainOrderInstructionsAsBytes)(
|
|
1005
|
+
order.orderId,
|
|
1006
|
+
order.user,
|
|
1007
|
+
{ rpcUrl: sol_rpc }
|
|
1008
|
+
);
|
|
1009
|
+
const message = import_web32.VersionedMessage.deserialize(
|
|
1010
|
+
versionedMessageBytes
|
|
1011
|
+
);
|
|
1012
|
+
const tx = new import_web32.VersionedTransaction(message);
|
|
1013
|
+
return await wallet.sendTransaction(tx);
|
|
1014
|
+
}
|
|
1015
|
+
const chainId = srcChain;
|
|
1016
|
+
const { readContract } = wallet;
|
|
1017
|
+
if (!readContract) {
|
|
1018
|
+
throw new Error("Wallet does not support readContract");
|
|
1019
|
+
}
|
|
1020
|
+
const nonce = BigInt(order.nonce ?? "0");
|
|
1021
|
+
const nonceWordPos = nonce >> 8n;
|
|
1022
|
+
const nonceBitPos = nonce - nonceWordPos * 256n;
|
|
1023
|
+
if (isCrossChain) {
|
|
1024
|
+
const [orderData = [false, false], currentNonceBitmap = 0n] = await Promise.all([
|
|
1025
|
+
readContract({
|
|
1026
|
+
address: import_intents_sdk14.CROSS_CHAIN_GUARD_ADDRESSES[chainId],
|
|
1027
|
+
abi: [
|
|
1028
|
+
{
|
|
1029
|
+
inputs: [{ name: "orderId", type: "bytes32" }],
|
|
1030
|
+
name: "orderData",
|
|
1031
|
+
outputs: [
|
|
1032
|
+
{ name: "initialized", type: "bool" },
|
|
1033
|
+
{ name: "deactivated", type: "bool" }
|
|
1034
|
+
],
|
|
1035
|
+
stateMutability: "view",
|
|
1036
|
+
type: "function"
|
|
1037
|
+
}
|
|
1038
|
+
],
|
|
1039
|
+
functionName: "orderData",
|
|
1040
|
+
args: [order.orderId]
|
|
1041
|
+
}),
|
|
1042
|
+
readContract({
|
|
1043
|
+
address: import_intents_sdk14.PERMIT2_ADDRESS[chainId],
|
|
1044
|
+
abi: [
|
|
1045
|
+
{
|
|
1046
|
+
inputs: [
|
|
1047
|
+
{ name: "owner", type: "address" },
|
|
1048
|
+
{ name: "wordPos", type: "uint256" }
|
|
1049
|
+
],
|
|
1050
|
+
name: "nonceBitmap",
|
|
1051
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
1052
|
+
stateMutability: "view",
|
|
1053
|
+
type: "function"
|
|
1054
|
+
}
|
|
1055
|
+
],
|
|
1056
|
+
functionName: "nonceBitmap",
|
|
1057
|
+
args: [order.user, nonceWordPos]
|
|
1058
|
+
})
|
|
1059
|
+
]);
|
|
1060
|
+
const [initialized, deactivated] = orderData;
|
|
1061
|
+
if (initialized) {
|
|
1062
|
+
if (deactivated) {
|
|
1063
|
+
throw new Error("Order is already deactivated");
|
|
1064
|
+
}
|
|
1065
|
+
return await wallet.sendTransaction({
|
|
1066
|
+
to: import_intents_sdk14.CROSS_CHAIN_GUARD_ADDRESSES[order.srcChainId],
|
|
1067
|
+
data: (0, import_viem8.encodeFunctionData)({
|
|
1068
|
+
abi: [
|
|
1069
|
+
{
|
|
1070
|
+
inputs: [
|
|
1071
|
+
{
|
|
1072
|
+
components: [
|
|
1073
|
+
{ name: "user", type: "address" },
|
|
1074
|
+
{ name: "tokenIn", type: "address" },
|
|
1075
|
+
{ name: "srcChainId", type: "uint256" },
|
|
1076
|
+
{ name: "deadline", type: "uint256" },
|
|
1077
|
+
{ name: "amountIn", type: "uint256" },
|
|
1078
|
+
{ name: "minStablecoinsAmount", type: "uint256" },
|
|
1079
|
+
{ name: "executionDetailsHash", type: "bytes32" },
|
|
1080
|
+
{ name: "nonce", type: "uint256" }
|
|
1081
|
+
],
|
|
1082
|
+
name: "orderInfo",
|
|
1083
|
+
type: "tuple"
|
|
1084
|
+
}
|
|
1085
|
+
],
|
|
1086
|
+
name: "cancelOrder",
|
|
1087
|
+
outputs: [],
|
|
1088
|
+
stateMutability: "nonpayable",
|
|
1089
|
+
type: "function"
|
|
1090
|
+
}
|
|
1091
|
+
],
|
|
1092
|
+
functionName: "cancelOrder",
|
|
1093
|
+
args: [
|
|
1094
|
+
{
|
|
1095
|
+
user: order.user,
|
|
1096
|
+
tokenIn: order.tokenIn,
|
|
1097
|
+
srcChainId: BigInt(order.srcChainId),
|
|
1098
|
+
deadline: BigInt(order.deadline),
|
|
1099
|
+
amountIn: BigInt(order.amountIn),
|
|
1100
|
+
minStablecoinsAmount: BigInt(order.minStablecoinsAmount),
|
|
1101
|
+
executionDetailsHash: order.executionDetailsHash,
|
|
1102
|
+
nonce
|
|
1103
|
+
}
|
|
1104
|
+
]
|
|
1105
|
+
}),
|
|
1106
|
+
value: BigInt(0),
|
|
1107
|
+
from: order.user
|
|
1108
|
+
});
|
|
1109
|
+
} else {
|
|
1110
|
+
if ((currentNonceBitmap & 1n << nonceBitPos) !== 0n) {
|
|
1111
|
+
throw new Error("Nonce is already invalidated");
|
|
1112
|
+
}
|
|
1113
|
+
const mask2 = 1n << nonceBitPos;
|
|
1114
|
+
return await wallet.sendTransaction({
|
|
1115
|
+
to: import_intents_sdk14.PERMIT2_ADDRESS[order.srcChainId],
|
|
1116
|
+
data: (0, import_viem8.encodeFunctionData)({
|
|
1117
|
+
abi: [
|
|
1118
|
+
{
|
|
1119
|
+
inputs: [
|
|
1120
|
+
{ name: "wordPos", type: "uint256" },
|
|
1121
|
+
{ name: "mask", type: "uint256" }
|
|
1122
|
+
],
|
|
1123
|
+
name: "invalidateUnorderedNonces",
|
|
1124
|
+
outputs: [],
|
|
1125
|
+
stateMutability: "nonpayable",
|
|
1126
|
+
type: "function"
|
|
1127
|
+
}
|
|
1128
|
+
],
|
|
1129
|
+
functionName: "invalidateUnorderedNonces",
|
|
1130
|
+
args: [nonceWordPos, mask2]
|
|
1131
|
+
}),
|
|
1132
|
+
value: BigInt(0),
|
|
1133
|
+
from: order.user
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
const [wasManuallyInitialized, currentBitmap = 0n] = await Promise.all([
|
|
1138
|
+
readContract({
|
|
1139
|
+
address: import_intents_sdk14.SINGLE_CHAIN_GUARD_ADDRESSES[chainId],
|
|
1140
|
+
abi: [
|
|
1141
|
+
{
|
|
1142
|
+
inputs: [{ name: "orderHash", type: "bytes32" }],
|
|
1143
|
+
name: "orderManuallyInitialized",
|
|
1144
|
+
outputs: [{ name: "", type: "bool" }],
|
|
1145
|
+
stateMutability: "view",
|
|
1146
|
+
type: "function"
|
|
1147
|
+
}
|
|
1148
|
+
],
|
|
1149
|
+
functionName: "orderManuallyInitialized",
|
|
1150
|
+
args: [order.orderId]
|
|
1151
|
+
}),
|
|
1152
|
+
readContract({
|
|
1153
|
+
address: import_intents_sdk14.PERMIT2_ADDRESS[chainId],
|
|
1154
|
+
abi: [
|
|
1155
|
+
{
|
|
1156
|
+
inputs: [
|
|
1157
|
+
{ name: "owner", type: "address" },
|
|
1158
|
+
{ name: "wordPos", type: "uint256" }
|
|
1159
|
+
],
|
|
1160
|
+
name: "nonceBitmap",
|
|
1161
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
1162
|
+
stateMutability: "view",
|
|
1163
|
+
type: "function"
|
|
1164
|
+
}
|
|
1165
|
+
],
|
|
1166
|
+
functionName: "nonceBitmap",
|
|
1167
|
+
args: [order.user, nonceWordPos]
|
|
1168
|
+
})
|
|
1169
|
+
]);
|
|
1170
|
+
if (wasManuallyInitialized) {
|
|
1171
|
+
return await wallet.sendTransaction({
|
|
1172
|
+
to: import_intents_sdk14.SINGLE_CHAIN_GUARD_ADDRESSES[chainId],
|
|
1173
|
+
data: (0, import_viem8.encodeFunctionData)({
|
|
1174
|
+
abi: [
|
|
1175
|
+
{
|
|
1176
|
+
inputs: [
|
|
1177
|
+
{
|
|
1178
|
+
name: "order",
|
|
1179
|
+
type: "tuple",
|
|
1180
|
+
components: [
|
|
1181
|
+
{ name: "amountIn", type: "uint256" },
|
|
1182
|
+
{ name: "tokenIn", type: "address" },
|
|
1183
|
+
{ name: "deadline", type: "uint256" },
|
|
1184
|
+
{ name: "nonce", type: "uint256" },
|
|
1185
|
+
{ name: "encodedExternalCallData", type: "bytes" },
|
|
1186
|
+
{
|
|
1187
|
+
name: "extraTransfers",
|
|
1188
|
+
type: "tuple[]",
|
|
1189
|
+
components: [
|
|
1190
|
+
{ name: "amount", type: "uint256" },
|
|
1191
|
+
{ name: "receiver", type: "address" },
|
|
1192
|
+
{ name: "token", type: "address" }
|
|
1193
|
+
]
|
|
1194
|
+
},
|
|
1195
|
+
{
|
|
1196
|
+
name: "requestedOutput",
|
|
1197
|
+
type: "tuple",
|
|
1198
|
+
components: [
|
|
1199
|
+
{ name: "amount", type: "uint256" },
|
|
1200
|
+
{ name: "receiver", type: "address" },
|
|
1201
|
+
{ name: "token", type: "address" }
|
|
1202
|
+
]
|
|
1203
|
+
},
|
|
1204
|
+
{ name: "user", type: "address" }
|
|
1205
|
+
]
|
|
1206
|
+
}
|
|
1207
|
+
],
|
|
1208
|
+
name: "cancelManuallyCreatedOrder",
|
|
1209
|
+
outputs: [],
|
|
1210
|
+
stateMutability: "nonpayable",
|
|
1211
|
+
type: "function"
|
|
1212
|
+
}
|
|
1213
|
+
],
|
|
1214
|
+
functionName: "cancelManuallyCreatedOrder",
|
|
1215
|
+
args: [
|
|
1216
|
+
{
|
|
1217
|
+
amountIn: BigInt(order.amountIn),
|
|
1218
|
+
tokenIn: order.tokenIn,
|
|
1219
|
+
deadline: BigInt(order.deadline),
|
|
1220
|
+
nonce,
|
|
1221
|
+
encodedExternalCallData: "0x",
|
|
1222
|
+
extraTransfers: (order.extraTransfers || []).map((t) => ({
|
|
1223
|
+
amount: BigInt(t.amount),
|
|
1224
|
+
receiver: t.receiver,
|
|
1225
|
+
token: t.token
|
|
1226
|
+
})),
|
|
1227
|
+
requestedOutput: {
|
|
1228
|
+
amount: BigInt(order.amountOutMin),
|
|
1229
|
+
receiver: order.destinationAddress,
|
|
1230
|
+
token: order.tokenOut
|
|
1231
|
+
},
|
|
1232
|
+
user: order.user
|
|
1233
|
+
}
|
|
1234
|
+
]
|
|
1235
|
+
}),
|
|
1236
|
+
value: 0n,
|
|
1237
|
+
from: order.user
|
|
1238
|
+
});
|
|
1239
|
+
}
|
|
1240
|
+
const mask = 1n << nonceBitPos;
|
|
1241
|
+
if ((currentBitmap & mask) !== 0n) {
|
|
1242
|
+
throw new Error("Nonce is already invalidated");
|
|
1243
|
+
}
|
|
1244
|
+
return await wallet.sendTransaction({
|
|
1245
|
+
to: import_intents_sdk14.PERMIT2_ADDRESS[chainId],
|
|
1246
|
+
data: (0, import_viem8.encodeFunctionData)({
|
|
1247
|
+
abi: [
|
|
1248
|
+
{
|
|
1249
|
+
inputs: [
|
|
1250
|
+
{ name: "wordPos", type: "uint256" },
|
|
1251
|
+
{ name: "mask", type: "uint256" }
|
|
1252
|
+
],
|
|
1253
|
+
name: "invalidateUnorderedNonces",
|
|
1254
|
+
outputs: [],
|
|
1255
|
+
stateMutability: "nonpayable",
|
|
1256
|
+
type: "function"
|
|
1257
|
+
}
|
|
1258
|
+
],
|
|
1259
|
+
functionName: "invalidateUnorderedNonces",
|
|
1260
|
+
args: [nonceWordPos, mask]
|
|
1261
|
+
}),
|
|
1262
|
+
value: 0n,
|
|
1263
|
+
from: order.user
|
|
1264
|
+
});
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
// src/core/client.ts
|
|
1268
|
+
var SwapSDK = class {
|
|
1269
|
+
constructor(config) {
|
|
1270
|
+
__publicField(this, "apiKey");
|
|
1271
|
+
/**
|
|
1272
|
+
* Fetches metadata for one or more tokens from the Shogun Token Search API.
|
|
1273
|
+
*
|
|
1274
|
+
* ---
|
|
1275
|
+
* ### Overview
|
|
1276
|
+
* `getTokensData` retrieves normalized token information — such as symbol, name,
|
|
1277
|
+
* decimals, logo URI, and verified status — for a given list of token addresses.
|
|
1278
|
+
*
|
|
1279
|
+
* It supports both **EVM** and **SVM (Solana)** tokens, returning metadata from
|
|
1280
|
+
* Shogun’s unified token registry.
|
|
1281
|
+
*
|
|
1282
|
+
* ---
|
|
1283
|
+
* @example
|
|
1284
|
+
* ```ts
|
|
1285
|
+
* const tokens = await getTokensData([
|
|
1286
|
+
* "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
|
|
1287
|
+
* "So11111111111111111111111111111111111111112", // SOL
|
|
1288
|
+
* ]);
|
|
1289
|
+
*
|
|
1290
|
+
* console.log(tokens);
|
|
1291
|
+
* [
|
|
1292
|
+
* { symbol: "USDC", name: "USD Coin", chainId: 1, decimals: 6, ... },
|
|
1293
|
+
* { symbol: "SOL", name: "Solana", chainId: 101, decimals: 9, ... }
|
|
1294
|
+
* ]
|
|
1295
|
+
* ```
|
|
1296
|
+
*
|
|
1297
|
+
* @param addresses - An array of token addresses (EVM or SVM) to fetch metadata for.
|
|
1298
|
+
* @returns A promise resolving to an array of {@link TokenInfo} objects.
|
|
1299
|
+
*
|
|
1300
|
+
* @throws Will throw an error if the network request fails or the API responds with a non-OK status.
|
|
1301
|
+
*/
|
|
1302
|
+
__publicField(this, "getTokensData", getTokensData.bind(this));
|
|
1303
|
+
if (!config.apiKey) {
|
|
1304
|
+
throw new Error("SwapSDK: Missing API key");
|
|
1305
|
+
}
|
|
1306
|
+
this.apiKey = config.apiKey;
|
|
1307
|
+
if (this.apiKey) void this.apiKey;
|
|
1308
|
+
}
|
|
1309
|
+
/**
|
|
1310
|
+
* Retrieves a swap quote for the given input and output tokens.
|
|
1311
|
+
*
|
|
1312
|
+
* @param params - Quote parameters including source/destination tokens and amount.
|
|
1313
|
+
* @returns A normalized `SwapQuoteResponse` containing output amount, route, and metadata.
|
|
1314
|
+
*/
|
|
1315
|
+
async getQuote(params) {
|
|
1316
|
+
return getQuote(params);
|
|
1317
|
+
}
|
|
1318
|
+
/**
|
|
1319
|
+
* Fetches token balances for the specified user wallet(s).
|
|
1320
|
+
*
|
|
1321
|
+
* Supports both EVM and SVM (Solana) wallet addresses.
|
|
1322
|
+
*
|
|
1323
|
+
* @param params - Wallet address and optional chain filters.
|
|
1324
|
+
* @param options - Optional abort signal for cancellation.
|
|
1325
|
+
* @returns A unified balance response with per-chain token details.
|
|
1326
|
+
*/
|
|
1327
|
+
async getBalances(params, options) {
|
|
1328
|
+
return getBalances(params, options);
|
|
1329
|
+
}
|
|
1330
|
+
/**
|
|
1331
|
+
* Retrieves a list of verified tokens based on search query or chain filter.
|
|
1332
|
+
*
|
|
1333
|
+
* @param params - Search parameters (query, chain ID, pagination options).
|
|
1334
|
+
* @returns Paginated `TokenSearchResponse` containing token metadata.
|
|
1335
|
+
*/
|
|
1336
|
+
async getTokenList(params) {
|
|
1337
|
+
return getTokenList(params);
|
|
1338
|
+
}
|
|
1339
|
+
/**
|
|
1340
|
+
* Executes a prepared swap quote using the provided wallet and configuration.
|
|
1341
|
+
*
|
|
1342
|
+
* Handles:
|
|
1343
|
+
* - Token approval (if required)
|
|
1344
|
+
* - Transaction signing and broadcasting
|
|
1345
|
+
* - Confirmation polling and stage-based status updates
|
|
1346
|
+
*
|
|
1347
|
+
* Supports both:
|
|
1348
|
+
* - Market orders (with optional deadline)
|
|
1349
|
+
* - Limit orders (requires executionPrice and deadline)
|
|
1350
|
+
*
|
|
1351
|
+
* @param quote - The swap quote to execute, containing route and metadata.
|
|
1352
|
+
* @param accountAddress - The user's wallet address executing the swap.
|
|
1353
|
+
* @param recipientAddress - Optional recipient address for the output tokens (defaults to sender).
|
|
1354
|
+
* @param wallet - Adapted wallet instance (EVM/Solana) or a standard Viem `WalletClient`.
|
|
1355
|
+
* @param onStatus - Optional callback for receiving execution stage updates and messages.
|
|
1356
|
+
* @param orderType - Defines whether this is a market or limit order.
|
|
1357
|
+
* @param options - Execution parameters (different per order type).
|
|
1358
|
+
*
|
|
1359
|
+
* @returns A finalized execution result containing transaction hash, status, and any returned data.
|
|
1360
|
+
*
|
|
1361
|
+
* @example
|
|
1362
|
+
* ```ts
|
|
1363
|
+
* * Market order
|
|
1364
|
+
* const result = await sdk.executeTransaction({
|
|
1365
|
+
* quote,
|
|
1366
|
+
* accountAddress: "0x123...",
|
|
1367
|
+
* wallet,
|
|
1368
|
+
* orderType: OrderExecutionType.MARKET,
|
|
1369
|
+
* options: { deadline: 1800 },
|
|
1370
|
+
* onStatus: (stage, msg) => console.log(stage, msg),
|
|
1371
|
+
* });
|
|
1372
|
+
*
|
|
1373
|
+
* * Limit order
|
|
1374
|
+
* const result = await sdk.executeTransaction({
|
|
1375
|
+
* quote,
|
|
1376
|
+
* accountAddress: "0x123...",
|
|
1377
|
+
* wallet,
|
|
1378
|
+
* orderType: OrderExecutionType.LIMIT,
|
|
1379
|
+
* options: { executionPrice: "0.0021", deadline: 3600 },
|
|
1380
|
+
* });
|
|
1381
|
+
* ```
|
|
1382
|
+
*/
|
|
1383
|
+
async executeTransaction({
|
|
1384
|
+
quote,
|
|
1385
|
+
accountAddress,
|
|
1386
|
+
recipientAddress,
|
|
1387
|
+
wallet,
|
|
1388
|
+
onStatus,
|
|
1389
|
+
orderType,
|
|
1390
|
+
options
|
|
1391
|
+
}) {
|
|
1392
|
+
return executeOrder({
|
|
1393
|
+
quote,
|
|
1394
|
+
wallet,
|
|
1395
|
+
accountAddress,
|
|
1396
|
+
recipientAddress,
|
|
1397
|
+
onStatus,
|
|
1398
|
+
orderType,
|
|
1399
|
+
options
|
|
1400
|
+
});
|
|
1401
|
+
}
|
|
1402
|
+
/**
|
|
1403
|
+
* Fetches all user orders (Market, Limit, Cross-chain) for connected wallets.
|
|
1404
|
+
*
|
|
1405
|
+
* ---
|
|
1406
|
+
* ### Overview
|
|
1407
|
+
* Retrieves both **single-chain** and **cross-chain** orders from the Shogun Intents API.
|
|
1408
|
+
* Works across EVM, Solana
|
|
1409
|
+
*
|
|
1410
|
+
* ---
|
|
1411
|
+
* @example
|
|
1412
|
+
* ```ts
|
|
1413
|
+
* const orders = await sdk.getOrders({
|
|
1414
|
+
* evmAddress: "0x123...",
|
|
1415
|
+
* solAddress: "9d12hF...abc",
|
|
1416
|
+
* });
|
|
1417
|
+
*
|
|
1418
|
+
* console.log(orders.singleChainLimitOrders);
|
|
1419
|
+
* ```
|
|
1420
|
+
*
|
|
1421
|
+
* @param params - Wallet addresses to fetch orders for (EVM, Solana).
|
|
1422
|
+
* @returns A structured {@link ApiUserOrders} object containing all user orders.
|
|
1423
|
+
*/
|
|
1424
|
+
async getOrders(params) {
|
|
1425
|
+
return getOrders(params);
|
|
1426
|
+
}
|
|
1427
|
+
/**
|
|
1428
|
+
* Cancels an order (single-chain or cross-chain) on EVM or Solana.
|
|
1429
|
+
*
|
|
1430
|
+
* Internally routes to the correct guard contract or Solana program to
|
|
1431
|
+
* deactivate the order or invalidate its nonce.
|
|
1432
|
+
*
|
|
1433
|
+
* @param params.order - Order payload returned from the Intents API.
|
|
1434
|
+
* @param params.wallet - Adapted wallet used to submit the cancellation transaction.
|
|
1435
|
+
* @param params.solRpc - Solana RPC URL used for SVM cancellations.
|
|
1436
|
+
*
|
|
1437
|
+
* @returns A transaction signature or hash from the underlying wallet.
|
|
1438
|
+
*/
|
|
1439
|
+
async cancelOrder(params) {
|
|
1440
|
+
return cancelIntentsOrder({
|
|
1441
|
+
order: params.order,
|
|
1442
|
+
wallet: params.wallet,
|
|
1443
|
+
sol_rpc: params.solRpc
|
|
1444
|
+
});
|
|
1445
|
+
}
|
|
1446
|
+
};
|