@shogun-sdk/intents-sdk 1.2.6-test.15 → 1.2.6-test.17
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 +535 -484
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +121 -43
- package/dist/index.d.ts +121 -43
- package/dist/index.js +369 -318
- package/dist/index.js.map +1 -1
- package/package.json +10 -7
- package/src/auth/siwe.ts +9 -7
- package/src/constants.ts +32 -17
- package/src/core/evm/intent-helpers.ts +131 -8
- package/src/core/evm/intent-provider.ts +5 -4
- package/src/core/evm/permit2.ts +36 -0
- package/src/core/orders/api/fetch.ts +12 -36
- package/src/core/orders/api/index.ts +2 -3
- package/src/core/orders/cross-chain.ts +3 -0
- package/src/core/orders/single-chain.ts +21 -8
- package/src/core/sdk.ts +11 -2
- package/src/core/solana/dca/create-order.ts +6 -19
- package/src/core/solana/intent-helpers.ts +12 -20
- package/src/core/solana/order-instructions.ts +12 -37
- package/src/core/sui/intent-helpers.ts +4 -1
- package/src/index.ts +4 -7
- package/src/types/api.ts +14 -3
- package/src/types/intent.ts +36 -2
- package/src/utils/base-validator.ts +0 -4
- package/src/utils/generate-execution-details-hash.ts +9 -32
- package/src/utils/quote/address.ts +4 -0
- package/src/utils/quote/aggregator.ts +29 -9
- package/src/utils/quote/pricing/constants.ts +33 -0
- package/src/utils/quote/pricing/decimals.ts +11 -0
- package/src/utils/quote/pricing/estimate-amount-out.ts +36 -0
- package/src/utils/quote/pricing/expenses.ts +62 -0
- package/src/utils/quote/pricing/gas.ts +28 -0
- package/src/core/solana/transaction-options.ts +0 -83
- package/src/utils/auctioneer-headers.ts +0 -32
package/dist/index.cjs
CHANGED
|
@@ -144,7 +144,10 @@ function isNativeEvmToken(tokenAddress) {
|
|
|
144
144
|
const normalizedAddress = tokenAddress.toLowerCase();
|
|
145
145
|
return NATIVE_EVM_ETH_ADDRESSES.some((addr) => addr.toLowerCase() === normalizedAddress);
|
|
146
146
|
}
|
|
147
|
-
|
|
147
|
+
function normalizeNativeEvmTokenForSigning(tokenAddress) {
|
|
148
|
+
return isNativeEvmToken(tokenAddress) ? EVM_ZERO_ADDRESS : tokenAddress;
|
|
149
|
+
}
|
|
150
|
+
var import_kit, useProdConfig, IntentsOrderType, PERMIT2_ADDRESS, PROD_CROSS_CHAIN_GUARD_ADDRESSES, TEST_CROSS_CHAIN_GUARD_ADDRESSES, PROD_SINGLE_CHAIN_GUARD_ADDRESSES, TEST_SINGLE_CHAIN_GUARD_ADDRESSES, PROD_DCA_SINGLE_CHAIN_GUARD_ADDRESSES, PROD_DCA_CROSS_CHAIN_GUARD_ADDRESSES, TEST_DCA_SINGLE_CHAIN_GUARD_ADDRESSES, CROSS_CHAIN_GUARD_ADDRESSES, SINGLE_CHAIN_GUARD_ADDRESSES, DCA_SINGLE_CHAIN_GUARD_ADDRESSES, DCA_CROSS_CHAIN_GUARD_ADDRESSES, NATIVE_SOLANA_TOKEN_ADDRESS, WRAPPED_SOL_MINT_ADDRESS, SOLANA_USDC_MINT, SOLANA_MINT_TOKEN, PROD_SUI_PACKAGE_ID, TEST_SUI_PACKAGE_ID, SUI_PACKAGE_ID, SUI_GUARD_COLLATERAL_TYPE, SUI_GUARD_STABLECOIN_TYPE, auctioneerUrlOverride, AUCTIONEER_URL, MAX_UINT_32, MAX_UINT_64, MAX_UINT_128, MAX_UINT_256, NATIVE_EVM_ETH_ADDRESSES, WRAPPED_ETH_ADDRESSES, NATIVE_SUI_TOKEN_ADDRESS, EVM_ZERO_ADDRESS, EVM_ZERO_SIGNATURE, TOKEN_SEARCH_API_BASE_URL;
|
|
148
151
|
var init_constants = __esm({
|
|
149
152
|
"src/constants.ts"() {
|
|
150
153
|
"use strict";
|
|
@@ -205,7 +208,9 @@ var init_constants = __esm({
|
|
|
205
208
|
[42161 /* Arbitrum */]: "0x0000000000000000000000000000000000000000",
|
|
206
209
|
[10 /* Optimism */]: "0x1b754840f058b78e412156d2674b5954728cb86e",
|
|
207
210
|
[8453 /* Base */]: "0x2df3ab1bb8b9d48769718003de2d8ca8e9d3c465",
|
|
208
|
-
|
|
211
|
+
// HyperEVM SingleChainGuardDca per the on-chain deployment + auctioneer config.
|
|
212
|
+
// (0x618ee9… is the SingleChainGuardLimit, which previously sat here by mistake.)
|
|
213
|
+
[999 /* Hyperliquid */]: "0xdcbb658910b5192a43b79fd8244bdf27940d3b6b",
|
|
209
214
|
[56 /* BSC */]: "0x11ef880e2e8d17c114b9eb87369ce3d1311c62e1",
|
|
210
215
|
[143 /* MONAD */]: "0x418302C3bef14D405A9B30381a9cb9d4d82EB2d4"
|
|
211
216
|
};
|
|
@@ -228,21 +233,9 @@ var init_constants = __esm({
|
|
|
228
233
|
CROSS_CHAIN_GUARD_ADDRESSES = useProdConfig ? PROD_CROSS_CHAIN_GUARD_ADDRESSES : TEST_CROSS_CHAIN_GUARD_ADDRESSES;
|
|
229
234
|
SINGLE_CHAIN_GUARD_ADDRESSES = useProdConfig ? PROD_SINGLE_CHAIN_GUARD_ADDRESSES : TEST_SINGLE_CHAIN_GUARD_ADDRESSES;
|
|
230
235
|
DCA_SINGLE_CHAIN_GUARD_ADDRESSES = useProdConfig ? PROD_DCA_SINGLE_CHAIN_GUARD_ADDRESSES : TEST_DCA_SINGLE_CHAIN_GUARD_ADDRESSES;
|
|
236
|
+
DCA_CROSS_CHAIN_GUARD_ADDRESSES = PROD_DCA_CROSS_CHAIN_GUARD_ADDRESSES;
|
|
231
237
|
NATIVE_SOLANA_TOKEN_ADDRESS = "So11111111111111111111111111111111111111111";
|
|
232
238
|
WRAPPED_SOL_MINT_ADDRESS = "So11111111111111111111111111111111111111112";
|
|
233
|
-
SOLANA_TIP_ACCOUNTS = [
|
|
234
|
-
"4ACfpUFoaSD9bfPdeu6DBt89gB6ENTeHBXCAi87NhDEE",
|
|
235
|
-
"D2L6yPZ2FmmmTKPgzaMKdhu6EWZcTpLy1Vhx8uvZe7NZ",
|
|
236
|
-
"9bnz4RShgq1hAnLnZbP8kbgBg1kEmcJBYQq3gQbmnSta",
|
|
237
|
-
"5VY91ws6B2hMmBFRsXkoAAdsPHBJwRfBht4DXox3xkwn",
|
|
238
|
-
"2nyhqdwKcJZR2vcqCyrYsaPVdAnFoJjiksCXJ7hfEYgD",
|
|
239
|
-
"2q5pghRs6arqVjRvT5gfgWfWcHWmw1ZuCzphgd5KfWGJ",
|
|
240
|
-
"wyvPkWjVZz1M8fHQnMMCDTQDbkManefNNhweYk5WkcF",
|
|
241
|
-
"3KCKozbAaF75qEU33jtzozcJ29yJuaLJTy2jFdzUY8bT",
|
|
242
|
-
"4vieeGHPYPG2MmyPRcYjdiDmmhN3ww7hsFNap8pVN3Ey",
|
|
243
|
-
"4TQLFNWK8AovT1gFvda5jfw2oJeRMKEmw7aH6MGBJ3or"
|
|
244
|
-
];
|
|
245
|
-
SOLANA_MIN_TIP_LAMPORTS = 200000n;
|
|
246
239
|
SOLANA_USDC_MINT = {
|
|
247
240
|
name: "USDC",
|
|
248
241
|
mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
|
@@ -254,7 +247,8 @@ var init_constants = __esm({
|
|
|
254
247
|
SUI_PACKAGE_ID = useProdConfig ? PROD_SUI_PACKAGE_ID : TEST_SUI_PACKAGE_ID;
|
|
255
248
|
SUI_GUARD_COLLATERAL_TYPE = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
|
|
256
249
|
SUI_GUARD_STABLECOIN_TYPE = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
|
|
257
|
-
|
|
250
|
+
auctioneerUrlOverride = typeof process !== "undefined" ? process.env?.INTENTS_AUCTIONEER_URL : void 0;
|
|
251
|
+
AUCTIONEER_URL = auctioneerUrlOverride || (useProdConfig ? "https://auctioneer-825534211396.us-central1.run.app" : "http://127.0.0.1:8080");
|
|
258
252
|
MAX_UINT_32 = 2n ** 32n - 1n;
|
|
259
253
|
MAX_UINT_64 = 2n ** 64n - 1n;
|
|
260
254
|
MAX_UINT_128 = 2n ** 128n - 1n;
|
|
@@ -272,6 +266,8 @@ var init_constants = __esm({
|
|
|
272
266
|
[143 /* MONAD */]: "0x3bd359C1119dA7Da1D913D1C4D2B7c461115433A"
|
|
273
267
|
};
|
|
274
268
|
NATIVE_SUI_TOKEN_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";
|
|
269
|
+
EVM_ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
270
|
+
EVM_ZERO_SIGNATURE = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
275
271
|
TOKEN_SEARCH_API_BASE_URL = "https://shogun-token-search-api-825534211396.europe-west4.run.app";
|
|
276
272
|
}
|
|
277
273
|
});
|
|
@@ -387,11 +383,12 @@ __export(index_exports, {
|
|
|
387
383
|
ChainID: () => ChainID,
|
|
388
384
|
ChainType: () => ChainType,
|
|
389
385
|
CrossChainOrder: () => CrossChainOrder,
|
|
386
|
+
DCA_CROSS_CHAIN_GUARD_ADDRESSES: () => DCA_CROSS_CHAIN_GUARD_ADDRESSES,
|
|
390
387
|
DCA_SINGLE_CHAIN_GUARD_ADDRESSES: () => DCA_SINGLE_CHAIN_GUARD_ADDRESSES,
|
|
391
|
-
DEV_ACCESS_HEADER: () => DEV_ACCESS_HEADER,
|
|
392
|
-
DEV_ACCESS_STORAGE_KEY: () => DEV_ACCESS_STORAGE_KEY,
|
|
393
388
|
DcaSingleChainOrder: () => DcaSingleChainOrder,
|
|
394
389
|
EVMSDK: () => EVMSDK,
|
|
390
|
+
EVM_ZERO_ADDRESS: () => EVM_ZERO_ADDRESS,
|
|
391
|
+
EVM_ZERO_SIGNATURE: () => EVM_ZERO_SIGNATURE,
|
|
395
392
|
IntentsOrderType: () => IntentsOrderType,
|
|
396
393
|
MAX_UINT_128: () => MAX_UINT_128,
|
|
397
394
|
MAX_UINT_256: () => MAX_UINT_256,
|
|
@@ -409,8 +406,6 @@ __export(index_exports, {
|
|
|
409
406
|
QuoteProvider: () => QuoteProvider,
|
|
410
407
|
SINGLE_CHAIN_GUARD_ADDRESSES: () => SINGLE_CHAIN_GUARD_ADDRESSES,
|
|
411
408
|
SOLANA_MINT_TOKEN: () => SOLANA_MINT_TOKEN,
|
|
412
|
-
SOLANA_MIN_TIP_LAMPORTS: () => SOLANA_MIN_TIP_LAMPORTS,
|
|
413
|
-
SOLANA_TIP_ACCOUNTS: () => SOLANA_TIP_ACCOUNTS,
|
|
414
409
|
SOLANA_USDC_MINT: () => SOLANA_USDC_MINT,
|
|
415
410
|
SUI_GUARD_COLLATERAL_TYPE: () => SUI_GUARD_COLLATERAL_TYPE,
|
|
416
411
|
SUI_GUARD_STABLECOIN_TYPE: () => SUI_GUARD_STABLECOIN_TYPE,
|
|
@@ -432,6 +427,7 @@ __export(index_exports, {
|
|
|
432
427
|
cancelDcaSingleChainOrderInstructions: () => cancelDcaSingleChainOrderInstructions,
|
|
433
428
|
cancelSingleChainOrderInstructionsAsBytes: () => cancelSingleChainOrderInstructionsAsBytes,
|
|
434
429
|
chainIdToChainTypeMap: () => chainIdToChainTypeMap,
|
|
430
|
+
createEvmCrossChainDcaOrderIntentRequest: () => createEvmCrossChainDcaOrderIntentRequest,
|
|
435
431
|
createEvmCrossChainOrderIntentRequest: () => createEvmCrossChainOrderIntentRequest,
|
|
436
432
|
createEvmSingleChainDcaOrderIntentRequest: () => createEvmSingleChainDcaOrderIntentRequest,
|
|
437
433
|
createEvmSingleChainLimitOrderIntentRequest: () => createEvmSingleChainLimitOrderIntentRequest,
|
|
@@ -461,7 +457,7 @@ __export(index_exports, {
|
|
|
461
457
|
getCancelSingleChainOrderRawData: () => getCancelSingleChainOrderRawData,
|
|
462
458
|
getCoinFromResponse: () => getCoinFromResponse,
|
|
463
459
|
getDcaSecretHash: () => getDcaSecretHash,
|
|
464
|
-
|
|
460
|
+
getEVMCrossChainDcaOrderTypedData: () => getEVMCrossChainDcaOrderTypedData,
|
|
465
461
|
getEVMCrossChainOrderTypedData: () => getEVMCrossChainOrderTypedData,
|
|
466
462
|
getEVMSingleChainOrderTypedData: () => getEVMSingleChainOrderTypedData,
|
|
467
463
|
getInvalidateNoncesRawData: () => getInvalidateNoncesRawData,
|
|
@@ -482,11 +478,11 @@ __export(index_exports, {
|
|
|
482
478
|
isNativeEvmToken: () => isNativeEvmToken,
|
|
483
479
|
isSuccessApiResponse: () => isSuccessApiResponse,
|
|
484
480
|
isSupportedChain: () => isSupportedChain,
|
|
481
|
+
normalizeNativeEvmTokenForSigning: () => normalizeNativeEvmTokenForSigning,
|
|
485
482
|
prepareDcaSecretData: () => prepareDcaSecretData,
|
|
486
483
|
prepareSecretData: () => prepareSecretData,
|
|
487
484
|
signSingleChainDcaOrder: () => signSingleChainDcaOrder,
|
|
488
|
-
signSingleChainLimitOrder: () => signSingleChainLimitOrder
|
|
489
|
-
withAuctioneerHeaders: () => withAuctioneerHeaders
|
|
485
|
+
signSingleChainLimitOrder: () => signSingleChainLimitOrder
|
|
490
486
|
});
|
|
491
487
|
module.exports = __toCommonJS(index_exports);
|
|
492
488
|
|
|
@@ -519,9 +515,6 @@ var BaseValidator = class {
|
|
|
519
515
|
this.validateTokenAddress(order.tokenOut);
|
|
520
516
|
this.validateAmount(order.amountIn);
|
|
521
517
|
this.validateAmount(order.amountOutMin ?? 1n);
|
|
522
|
-
if (order.stopLossMaxOut) {
|
|
523
|
-
this.validateAmount(order.stopLossMaxOut);
|
|
524
|
-
}
|
|
525
518
|
if (order.takeProfitMinOut) {
|
|
526
519
|
this.validateAmount(order.takeProfitMinOut);
|
|
527
520
|
}
|
|
@@ -571,9 +564,9 @@ var BaseValidator = class {
|
|
|
571
564
|
/**
|
|
572
565
|
* Helper methods that throw specific validation errors
|
|
573
566
|
*/
|
|
574
|
-
validateAddress(
|
|
575
|
-
if (!this.isValidAddress(
|
|
576
|
-
throw new ValidationError(`Invalid ${this.getChainName()} address: ${
|
|
567
|
+
validateAddress(address9) {
|
|
568
|
+
if (!this.isValidAddress(address9)) {
|
|
569
|
+
throw new ValidationError(`Invalid ${this.getChainName()} address: ${address9}`);
|
|
577
570
|
}
|
|
578
571
|
}
|
|
579
572
|
validateTokenAddress(tokenAddress) {
|
|
@@ -3298,9 +3291,9 @@ var ChainProvider = class _ChainProvider {
|
|
|
3298
3291
|
}
|
|
3299
3292
|
});
|
|
3300
3293
|
}
|
|
3301
|
-
getSingleChainAuctioneerContract(
|
|
3294
|
+
getSingleChainAuctioneerContract(address9) {
|
|
3302
3295
|
return (0, import_viem3.getContract)({
|
|
3303
|
-
address:
|
|
3296
|
+
address: address9,
|
|
3304
3297
|
abi: SINGLE_CHAIN_GUARD_LIMIT_ABI,
|
|
3305
3298
|
client: {
|
|
3306
3299
|
wallet: this.walletClient,
|
|
@@ -3339,8 +3332,8 @@ var ChainProvider = class _ChainProvider {
|
|
|
3339
3332
|
|
|
3340
3333
|
// src/core/evm/validator.ts
|
|
3341
3334
|
var EvmValidator = class extends BaseValidator {
|
|
3342
|
-
isValidAddress(
|
|
3343
|
-
return (0, import_viem4.isAddress)(
|
|
3335
|
+
isValidAddress(address9) {
|
|
3336
|
+
return (0, import_viem4.isAddress)(address9);
|
|
3344
3337
|
}
|
|
3345
3338
|
isValidTokenAddress(tokenAddress) {
|
|
3346
3339
|
return (0, import_viem4.isAddress)(tokenAddress);
|
|
@@ -3437,8 +3430,8 @@ var SolanaValidator = class extends BaseValidator {
|
|
|
3437
3430
|
validateSingleChainOrderFeasability() {
|
|
3438
3431
|
return Promise.resolve();
|
|
3439
3432
|
}
|
|
3440
|
-
isValidAddress(
|
|
3441
|
-
return (0, import_kit2.isAddress)(
|
|
3433
|
+
isValidAddress(address9) {
|
|
3434
|
+
return (0, import_kit2.isAddress)(address9);
|
|
3442
3435
|
}
|
|
3443
3436
|
isValidTokenAddress(tokenAddress) {
|
|
3444
3437
|
return (0, import_kit2.isAddress)(tokenAddress);
|
|
@@ -3462,12 +3455,12 @@ var import_utils = require("@mysten/sui/utils");
|
|
|
3462
3455
|
init_constants();
|
|
3463
3456
|
var SUI_TOKEN_ADDRESS_REGEX = /^0x[a-fA-F0-9]{64}::\w+::\w+$/;
|
|
3464
3457
|
var SuiValidator = class extends BaseValidator {
|
|
3465
|
-
isValidAddress(
|
|
3466
|
-
return (0, import_utils.isValidSuiAddress)((0, import_utils.normalizeSuiAddress)(
|
|
3458
|
+
isValidAddress(address9) {
|
|
3459
|
+
return (0, import_utils.isValidSuiAddress)((0, import_utils.normalizeSuiAddress)(address9));
|
|
3467
3460
|
}
|
|
3468
3461
|
isValidTokenAddress(tokenAddress) {
|
|
3469
|
-
const [
|
|
3470
|
-
const isValidAddress =
|
|
3462
|
+
const [address9] = tokenAddress.split("::");
|
|
3463
|
+
const isValidAddress = address9 !== void 0 ? this.isValidAddress(address9) : false;
|
|
3471
3464
|
return isValidAddress && SUI_TOKEN_ADDRESS_REGEX.test(tokenAddress);
|
|
3472
3465
|
}
|
|
3473
3466
|
isValidAmount(amount) {
|
|
@@ -3574,35 +3567,6 @@ var DcaSingleChainOrderValidator = class {
|
|
|
3574
3567
|
init_constants();
|
|
3575
3568
|
init_errors();
|
|
3576
3569
|
|
|
3577
|
-
// src/utils/auctioneer-headers.ts
|
|
3578
|
-
var DEV_ACCESS_STORAGE_KEY = "x-dev-access";
|
|
3579
|
-
var DEV_ACCESS_HEADER = "x-dev-access";
|
|
3580
|
-
function getDevAccessHeaderValue() {
|
|
3581
|
-
try {
|
|
3582
|
-
if (typeof globalThis === "undefined") {
|
|
3583
|
-
return void 0;
|
|
3584
|
-
}
|
|
3585
|
-
const storage = globalThis.localStorage;
|
|
3586
|
-
if (!storage?.getItem) {
|
|
3587
|
-
return void 0;
|
|
3588
|
-
}
|
|
3589
|
-
const value = storage.getItem(DEV_ACCESS_STORAGE_KEY)?.trim();
|
|
3590
|
-
return value ? value : void 0;
|
|
3591
|
-
} catch {
|
|
3592
|
-
return void 0;
|
|
3593
|
-
}
|
|
3594
|
-
}
|
|
3595
|
-
function withAuctioneerHeaders(headers = {}) {
|
|
3596
|
-
const value = getDevAccessHeaderValue();
|
|
3597
|
-
if (!value) {
|
|
3598
|
-
return headers;
|
|
3599
|
-
}
|
|
3600
|
-
return {
|
|
3601
|
-
...headers,
|
|
3602
|
-
[DEV_ACCESS_HEADER]: value
|
|
3603
|
-
};
|
|
3604
|
-
}
|
|
3605
|
-
|
|
3606
3570
|
// src/utils/parsers.ts
|
|
3607
3571
|
var import_viem5 = require("viem");
|
|
3608
3572
|
var Parsers;
|
|
@@ -3720,6 +3684,29 @@ var DCA_SINGLE_CHAIN_PERMIT2_TYPES = {
|
|
|
3720
3684
|
{ name: "witness", type: "SingleChainDcaOrder" }
|
|
3721
3685
|
]
|
|
3722
3686
|
};
|
|
3687
|
+
var CROSS_CHAIN_DCA_PERMIT2_TYPES = {
|
|
3688
|
+
TokenPermissions: TOKEN_PERMISSIONS_TYPE,
|
|
3689
|
+
DcaOrderInfo: [
|
|
3690
|
+
{ name: "user", type: "address" },
|
|
3691
|
+
{ name: "tokenIn", type: "address" },
|
|
3692
|
+
{ name: "srcChainId", type: "uint32" },
|
|
3693
|
+
{ name: "startTime", type: "uint32" },
|
|
3694
|
+
{ name: "deadline", type: "uint32" },
|
|
3695
|
+
{ name: "totalIntervals", type: "uint24" },
|
|
3696
|
+
{ name: "intervalDuration", type: "uint32" },
|
|
3697
|
+
{ name: "amountInPerInterval", type: "uint128" },
|
|
3698
|
+
{ name: "minStablecoinsAmountPerInterval", type: "uint128" },
|
|
3699
|
+
{ name: "executionDetailsHash", type: "bytes32" },
|
|
3700
|
+
{ name: "nonce", type: "uint256" }
|
|
3701
|
+
],
|
|
3702
|
+
PermitWitnessTransferFrom: [
|
|
3703
|
+
{ name: "permitted", type: "TokenPermissions" },
|
|
3704
|
+
{ name: "spender", type: "address" },
|
|
3705
|
+
{ name: "nonce", type: "uint256" },
|
|
3706
|
+
{ name: "deadline", type: "uint256" },
|
|
3707
|
+
{ name: "witness", type: "DcaOrderInfo" }
|
|
3708
|
+
]
|
|
3709
|
+
};
|
|
3723
3710
|
|
|
3724
3711
|
// src/core/evm/intent-provider.ts
|
|
3725
3712
|
var EVMIntentProvider = class {
|
|
@@ -3786,12 +3773,12 @@ var EVMIntentProvider = class {
|
|
|
3786
3773
|
static getSingleChainLimitPermissionMessage(order, nonce) {
|
|
3787
3774
|
const spender = SINGLE_CHAIN_GUARD_ADDRESSES[order.chainId];
|
|
3788
3775
|
const requestedOutput = {
|
|
3789
|
-
token: order.tokenOut,
|
|
3776
|
+
token: normalizeNativeEvmTokenForSigning(order.tokenOut),
|
|
3790
3777
|
receiver: order.destinationAddress,
|
|
3791
3778
|
amount: order.amountOutMin
|
|
3792
3779
|
};
|
|
3793
3780
|
const extraTransfers = order.extraTransfers?.map((transfer) => ({
|
|
3794
|
-
token: transfer.token,
|
|
3781
|
+
token: normalizeNativeEvmTokenForSigning(transfer.token),
|
|
3795
3782
|
receiver: transfer.receiver,
|
|
3796
3783
|
amount: transfer.amount
|
|
3797
3784
|
})) || [];
|
|
@@ -3839,12 +3826,12 @@ var EVMIntentProvider = class {
|
|
|
3839
3826
|
static getDcaSingleChainPermissionMessage(order, nonce) {
|
|
3840
3827
|
const spender = DCA_SINGLE_CHAIN_GUARD_ADDRESSES[order.chainId];
|
|
3841
3828
|
const requestedOutput = {
|
|
3842
|
-
token: order.tokenOut,
|
|
3829
|
+
token: normalizeNativeEvmTokenForSigning(order.tokenOut),
|
|
3843
3830
|
receiver: order.destinationAddress,
|
|
3844
3831
|
amount: BigInt(order.amountOutMin)
|
|
3845
3832
|
};
|
|
3846
3833
|
const extraTransfers = order.extraTransfers?.map((transfer) => ({
|
|
3847
|
-
token: transfer.token,
|
|
3834
|
+
token: normalizeNativeEvmTokenForSigning(transfer.token),
|
|
3848
3835
|
receiver: transfer.receiver,
|
|
3849
3836
|
amount: transfer.amount
|
|
3850
3837
|
})) || [];
|
|
@@ -3913,7 +3900,7 @@ async function getEVMDcaSingleChainOrderTypedData(order) {
|
|
|
3913
3900
|
// src/core/solana/order-instructions.ts
|
|
3914
3901
|
var import_system = require("@solana-program/system");
|
|
3915
3902
|
var import_token = require("@solana-program/token");
|
|
3916
|
-
var
|
|
3903
|
+
var import_kit4 = require("@solana/kit");
|
|
3917
3904
|
init_constants();
|
|
3918
3905
|
|
|
3919
3906
|
// src/core/solana/client.ts
|
|
@@ -3962,8 +3949,8 @@ function getOrderDecoder() {
|
|
|
3962
3949
|
function decodeOrder(encodedAccount) {
|
|
3963
3950
|
return (0, import_accounts2.decodeAccount)(encodedAccount, getOrderDecoder());
|
|
3964
3951
|
}
|
|
3965
|
-
async function fetchMaybeOrder(rpc,
|
|
3966
|
-
const maybeAccount = await (0, import_accounts2.fetchEncodedAccount)(rpc,
|
|
3952
|
+
async function fetchMaybeOrder(rpc, address9, config) {
|
|
3953
|
+
const maybeAccount = await (0, import_accounts2.fetchEncodedAccount)(rpc, address9, config);
|
|
3967
3954
|
return decodeOrder(maybeAccount);
|
|
3968
3955
|
}
|
|
3969
3956
|
|
|
@@ -4152,8 +4139,8 @@ function getDcaOrderDecoder() {
|
|
|
4152
4139
|
function decodeDcaOrder(encodedAccount) {
|
|
4153
4140
|
return (0, import_accounts3.decodeAccount)(encodedAccount, getDcaOrderDecoder());
|
|
4154
4141
|
}
|
|
4155
|
-
async function fetchMaybeDcaOrder(rpc,
|
|
4156
|
-
const maybeAccount = await (0, import_accounts3.fetchEncodedAccount)(rpc,
|
|
4142
|
+
async function fetchMaybeDcaOrder(rpc, address9, config) {
|
|
4143
|
+
const maybeAccount = await (0, import_accounts3.fetchEncodedAccount)(rpc, address9, config);
|
|
4157
4144
|
return decodeDcaOrder(maybeAccount);
|
|
4158
4145
|
}
|
|
4159
4146
|
|
|
@@ -4178,8 +4165,8 @@ function getLimitOrderDecoder() {
|
|
|
4178
4165
|
function decodeLimitOrder(encodedAccount) {
|
|
4179
4166
|
return (0, import_accounts4.decodeAccount)(encodedAccount, getLimitOrderDecoder());
|
|
4180
4167
|
}
|
|
4181
|
-
async function fetchMaybeLimitOrder(rpc,
|
|
4182
|
-
const maybeAccount = await (0, import_accounts4.fetchEncodedAccount)(rpc,
|
|
4168
|
+
async function fetchMaybeLimitOrder(rpc, address9, config) {
|
|
4169
|
+
const maybeAccount = await (0, import_accounts4.fetchEncodedAccount)(rpc, address9, config);
|
|
4183
4170
|
return decodeLimitOrder(maybeAccount);
|
|
4184
4171
|
}
|
|
4185
4172
|
|
|
@@ -4503,80 +4490,23 @@ function formatTokenPubkey(token) {
|
|
|
4503
4490
|
return token;
|
|
4504
4491
|
}
|
|
4505
4492
|
|
|
4506
|
-
// src/core/solana/transaction-options.ts
|
|
4507
|
-
var import_kit4 = require("@solana/kit");
|
|
4508
|
-
init_constants();
|
|
4509
|
-
function resolveSolanaFeePayer(userSigner, feePayer) {
|
|
4510
|
-
if (!feePayer || feePayer === userSigner.address) {
|
|
4511
|
-
return userSigner;
|
|
4512
|
-
}
|
|
4513
|
-
const feePayerAddress = (0, import_kit4.address)(feePayer);
|
|
4514
|
-
return (0, import_kit4.createNoopSigner)(feePayerAddress);
|
|
4515
|
-
}
|
|
4516
|
-
function resolveSolanaTip(options) {
|
|
4517
|
-
const lamports = normalizeTipLamports(options);
|
|
4518
|
-
if (!lamports) {
|
|
4519
|
-
return void 0;
|
|
4520
|
-
}
|
|
4521
|
-
const selectedTipAccount = options?.tipAccount ?? pickRandomTipAccount(options?.tipAccounts ?? SOLANA_TIP_ACCOUNTS);
|
|
4522
|
-
return {
|
|
4523
|
-
lamports,
|
|
4524
|
-
account: (0, import_kit4.address)(selectedTipAccount)
|
|
4525
|
-
};
|
|
4526
|
-
}
|
|
4527
|
-
function normalizeTipLamports(options) {
|
|
4528
|
-
if (!options) {
|
|
4529
|
-
return void 0;
|
|
4530
|
-
}
|
|
4531
|
-
if (options.tipLamports !== void 0) {
|
|
4532
|
-
if (options.tipLamports <= 0n) {
|
|
4533
|
-
return void 0;
|
|
4534
|
-
}
|
|
4535
|
-
return options.tipLamports < SOLANA_MIN_TIP_LAMPORTS ? SOLANA_MIN_TIP_LAMPORTS : options.tipLamports;
|
|
4536
|
-
}
|
|
4537
|
-
if (options.tipAmountSol === void 0 || options.tipAmountSol === null || options.tipAmountSol === "") {
|
|
4538
|
-
return void 0;
|
|
4539
|
-
}
|
|
4540
|
-
const tipInSol = Number(options.tipAmountSol);
|
|
4541
|
-
if (!Number.isFinite(tipInSol)) {
|
|
4542
|
-
throw new Error("Invalid Solana tip amount");
|
|
4543
|
-
}
|
|
4544
|
-
if (tipInSol <= 0) {
|
|
4545
|
-
return void 0;
|
|
4546
|
-
}
|
|
4547
|
-
const tipLamports = BigInt(Math.round(tipInSol * 1e9));
|
|
4548
|
-
return tipLamports < SOLANA_MIN_TIP_LAMPORTS ? SOLANA_MIN_TIP_LAMPORTS : tipLamports;
|
|
4549
|
-
}
|
|
4550
|
-
function pickRandomTipAccount(accounts) {
|
|
4551
|
-
if (!accounts.length) {
|
|
4552
|
-
throw new Error("No Solana tip accounts configured");
|
|
4553
|
-
}
|
|
4554
|
-
const index = Math.floor(Math.random() * accounts.length);
|
|
4555
|
-
const selected = accounts[index];
|
|
4556
|
-
if (!selected) {
|
|
4557
|
-
throw new Error("No Solana tip account selected");
|
|
4558
|
-
}
|
|
4559
|
-
return selected;
|
|
4560
|
-
}
|
|
4561
|
-
|
|
4562
4493
|
// src/core/solana/order-instructions.ts
|
|
4563
4494
|
async function getSolanaSingleChainOrderInstructions(order, options) {
|
|
4564
|
-
const rpc = options?.rpcUrl ? (0,
|
|
4565
|
-
const orderSigner = await (0,
|
|
4566
|
-
const
|
|
4567
|
-
|
|
4568
|
-
let tokenInMint = (0, import_kit5.address)(order.tokenIn);
|
|
4495
|
+
const rpc = options?.rpcUrl ? (0, import_kit4.createSolanaRpc)(options.rpcUrl) : getDefaultSolanaRPC();
|
|
4496
|
+
const orderSigner = await (0, import_kit4.generateKeyPairSigner)();
|
|
4497
|
+
const signer = (0, import_kit4.createNoopSigner)(order.user);
|
|
4498
|
+
let tokenInMint = (0, import_kit4.address)(order.tokenIn);
|
|
4569
4499
|
const { secretHash, secretNumber } = genSecretHashAndNumber(order);
|
|
4570
|
-
const orderUserAddress = (0,
|
|
4500
|
+
const orderUserAddress = (0, import_kit4.address)(order.user);
|
|
4571
4501
|
const spendingNative = tokenInMint === NATIVE_SOLANA_TOKEN_ADDRESS;
|
|
4572
4502
|
if (spendingNative) {
|
|
4573
4503
|
tokenInMint = WRAPPED_SOL_MINT_ADDRESS;
|
|
4574
4504
|
}
|
|
4575
4505
|
const tokenMintProgram = await (0, import_token.fetchMint)(rpc, tokenInMint);
|
|
4576
|
-
const guardAddress = (0,
|
|
4577
|
-
const addressEncoder = (0,
|
|
4506
|
+
const guardAddress = (0, import_kit4.address)(SINGLE_CHAIN_GUARD_ADDRESSES[7565164 /* Solana */]);
|
|
4507
|
+
const addressEncoder = (0, import_kit4.getAddressEncoder)();
|
|
4578
4508
|
const instructions = [];
|
|
4579
|
-
const [tokenInProgramAccount] = await (0,
|
|
4509
|
+
const [tokenInProgramAccount] = await (0, import_kit4.getProgramDerivedAddress)({
|
|
4580
4510
|
programAddress: import_token.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
4581
4511
|
seeds: [
|
|
4582
4512
|
addressEncoder.encode(orderUserAddress),
|
|
@@ -4584,10 +4514,10 @@ async function getSolanaSingleChainOrderInstructions(order, options) {
|
|
|
4584
4514
|
addressEncoder.encode(tokenInMint)
|
|
4585
4515
|
]
|
|
4586
4516
|
});
|
|
4587
|
-
const userTokenInAccount = await (0,
|
|
4517
|
+
const userTokenInAccount = await (0, import_kit4.fetchEncodedAccount)(rpc, tokenInProgramAccount);
|
|
4588
4518
|
if (!userTokenInAccount.exists) {
|
|
4589
4519
|
const createAccountIx = await (0, import_token.getCreateAssociatedTokenInstructionAsync)({
|
|
4590
|
-
payer:
|
|
4520
|
+
payer: signer,
|
|
4591
4521
|
ata: tokenInProgramAccount,
|
|
4592
4522
|
owner: orderUserAddress,
|
|
4593
4523
|
mint: tokenMintProgram.address,
|
|
@@ -4599,7 +4529,7 @@ async function getSolanaSingleChainOrderInstructions(order, options) {
|
|
|
4599
4529
|
const transferIx = (0, import_system.getTransferSolInstruction)({
|
|
4600
4530
|
amount: order.amountIn,
|
|
4601
4531
|
destination: userTokenInAccount.address,
|
|
4602
|
-
source:
|
|
4532
|
+
source: signer
|
|
4603
4533
|
});
|
|
4604
4534
|
instructions.push(transferIx);
|
|
4605
4535
|
const syncNativeIx = (0, import_token.getSyncNativeInstruction)({
|
|
@@ -4608,7 +4538,7 @@ async function getSolanaSingleChainOrderInstructions(order, options) {
|
|
|
4608
4538
|
instructions.push(syncNativeIx);
|
|
4609
4539
|
}
|
|
4610
4540
|
const createSingleChainLimitOrderIx = await getCreateLimitOrderInstructionAsync({
|
|
4611
|
-
user:
|
|
4541
|
+
user: signer,
|
|
4612
4542
|
order: orderSigner,
|
|
4613
4543
|
guard: guardAddress,
|
|
4614
4544
|
tokenInMint,
|
|
@@ -4622,26 +4552,16 @@ async function getSolanaSingleChainOrderInstructions(order, options) {
|
|
|
4622
4552
|
// TODO
|
|
4623
4553
|
});
|
|
4624
4554
|
instructions.push(createSingleChainLimitOrderIx);
|
|
4625
|
-
const tip = resolveSolanaTip(options);
|
|
4626
|
-
if (tip) {
|
|
4627
|
-
instructions.push(
|
|
4628
|
-
(0, import_system.getTransferSolInstruction)({
|
|
4629
|
-
source: feePayerSigner,
|
|
4630
|
-
destination: tip.account,
|
|
4631
|
-
amount: tip.lamports
|
|
4632
|
-
})
|
|
4633
|
-
);
|
|
4634
|
-
}
|
|
4635
4555
|
const { value: latestBlockhash } = await rpc.getLatestBlockhash({ commitment: "confirmed" }).send();
|
|
4636
|
-
const txMessage = (0,
|
|
4637
|
-
(0,
|
|
4638
|
-
(tx) => (0,
|
|
4639
|
-
(tx) => (0,
|
|
4640
|
-
(tx) => (0,
|
|
4641
|
-
(tx) => (0,
|
|
4556
|
+
const txMessage = (0, import_kit4.pipe)(
|
|
4557
|
+
(0, import_kit4.createTransactionMessage)({ version: 0 }),
|
|
4558
|
+
(tx) => (0, import_kit4.setTransactionMessageFeePayerSigner)(signer, tx),
|
|
4559
|
+
(tx) => (0, import_kit4.setTransactionMessageLifetimeUsingBlockhash)(latestBlockhash, tx),
|
|
4560
|
+
(tx) => (0, import_kit4.appendTransactionMessageInstructions)(instructions, tx),
|
|
4561
|
+
(tx) => (0, import_kit4.addSignersToTransactionMessage)([orderSigner], tx)
|
|
4642
4562
|
);
|
|
4643
|
-
const partiallySignedTransaction = await (0,
|
|
4644
|
-
const txBytes = (0,
|
|
4563
|
+
const partiallySignedTransaction = await (0, import_kit4.partiallySignTransactionMessageWithSigners)(txMessage);
|
|
4564
|
+
const txBytes = (0, import_kit4.getTransactionCodec)().encode(partiallySignedTransaction);
|
|
4645
4565
|
return {
|
|
4646
4566
|
orderAddress: orderSigner.address,
|
|
4647
4567
|
txBytes,
|
|
@@ -4649,20 +4569,19 @@ async function getSolanaSingleChainOrderInstructions(order, options) {
|
|
|
4649
4569
|
};
|
|
4650
4570
|
}
|
|
4651
4571
|
async function getSolanaCrossChainOrderInstructions(order, options) {
|
|
4652
|
-
const rpc = options?.rpcUrl ? (0,
|
|
4653
|
-
const orderSigner = await (0,
|
|
4654
|
-
const
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
const orderUserAddress = (0, import_kit5.address)(order.user);
|
|
4572
|
+
const rpc = options?.rpcUrl ? (0, import_kit4.createSolanaRpc)(options.rpcUrl) : getDefaultSolanaRPC();
|
|
4573
|
+
const orderSigner = await (0, import_kit4.generateKeyPairSigner)();
|
|
4574
|
+
const signer = (0, import_kit4.createNoopSigner)(order.user);
|
|
4575
|
+
let tokenInMint = (0, import_kit4.address)(order.sourceTokenAddress);
|
|
4576
|
+
const orderUserAddress = (0, import_kit4.address)(order.user);
|
|
4658
4577
|
const spendingNative = tokenInMint === NATIVE_SOLANA_TOKEN_ADDRESS;
|
|
4659
4578
|
if (spendingNative) {
|
|
4660
4579
|
tokenInMint = WRAPPED_SOL_MINT_ADDRESS;
|
|
4661
4580
|
}
|
|
4662
4581
|
const tokenMintProgram = await (0, import_token.fetchMint)(rpc, tokenInMint);
|
|
4663
|
-
const guardAddress = (0,
|
|
4664
|
-
const addressEncoder = (0,
|
|
4665
|
-
const [tokenInProgramAccount] = await (0,
|
|
4582
|
+
const guardAddress = (0, import_kit4.address)(CROSS_CHAIN_GUARD_ADDRESSES[7565164 /* Solana */]);
|
|
4583
|
+
const addressEncoder = (0, import_kit4.getAddressEncoder)();
|
|
4584
|
+
const [tokenInProgramAccount] = await (0, import_kit4.getProgramDerivedAddress)({
|
|
4666
4585
|
programAddress: import_token.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
4667
4586
|
seeds: [
|
|
4668
4587
|
addressEncoder.encode(orderUserAddress),
|
|
@@ -4670,7 +4589,7 @@ async function getSolanaCrossChainOrderInstructions(order, options) {
|
|
|
4670
4589
|
addressEncoder.encode(tokenInMint)
|
|
4671
4590
|
]
|
|
4672
4591
|
});
|
|
4673
|
-
const [guardProgramAccount] = await (0,
|
|
4592
|
+
const [guardProgramAccount] = await (0, import_kit4.getProgramDerivedAddress)({
|
|
4674
4593
|
programAddress: import_token.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
4675
4594
|
seeds: [
|
|
4676
4595
|
// Owner
|
|
@@ -4682,12 +4601,12 @@ async function getSolanaCrossChainOrderInstructions(order, options) {
|
|
|
4682
4601
|
]
|
|
4683
4602
|
});
|
|
4684
4603
|
const instructions = [];
|
|
4685
|
-
const userTokenInAccount = await (0,
|
|
4604
|
+
const userTokenInAccount = await (0, import_kit4.fetchEncodedAccount)(rpc, tokenInProgramAccount);
|
|
4686
4605
|
if (spendingNative) {
|
|
4687
4606
|
order.sourceTokenAddress = WRAPPED_SOL_MINT_ADDRESS;
|
|
4688
4607
|
if (!userTokenInAccount.exists) {
|
|
4689
4608
|
const createAccountIx = await (0, import_token.getCreateAssociatedTokenInstructionAsync)({
|
|
4690
|
-
payer:
|
|
4609
|
+
payer: signer,
|
|
4691
4610
|
ata: tokenInProgramAccount,
|
|
4692
4611
|
owner: orderUserAddress,
|
|
4693
4612
|
mint: tokenMintProgram.address,
|
|
@@ -4696,7 +4615,7 @@ async function getSolanaCrossChainOrderInstructions(order, options) {
|
|
|
4696
4615
|
instructions.push(createAccountIx);
|
|
4697
4616
|
}
|
|
4698
4617
|
const transferIx = (0, import_system.getTransferSolInstruction)({
|
|
4699
|
-
source:
|
|
4618
|
+
source: signer,
|
|
4700
4619
|
destination: userTokenInAccount.address,
|
|
4701
4620
|
amount: order.sourceTokenAmount
|
|
4702
4621
|
});
|
|
@@ -4708,9 +4627,9 @@ async function getSolanaCrossChainOrderInstructions(order, options) {
|
|
|
4708
4627
|
}
|
|
4709
4628
|
const executionHashUint8Array = order.executionDetailsHashToBytes();
|
|
4710
4629
|
const createOrderIx = getCreateOrderInstruction({
|
|
4711
|
-
user:
|
|
4630
|
+
user: signer,
|
|
4712
4631
|
order: orderSigner,
|
|
4713
|
-
guard: (0,
|
|
4632
|
+
guard: (0, import_kit4.address)(CROSS_CHAIN_GUARD_ADDRESSES[7565164 /* Solana */]),
|
|
4714
4633
|
systemProgram: import_system.SYSTEM_PROGRAM_ADDRESS,
|
|
4715
4634
|
associatedTokenProgram: import_token.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
4716
4635
|
tokenInMint,
|
|
@@ -4723,26 +4642,16 @@ async function getSolanaCrossChainOrderInstructions(order, options) {
|
|
|
4723
4642
|
minStablecoinsAmount: order.minStablecoinAmount
|
|
4724
4643
|
});
|
|
4725
4644
|
instructions.push(createOrderIx);
|
|
4726
|
-
const tip = resolveSolanaTip(options);
|
|
4727
|
-
if (tip) {
|
|
4728
|
-
instructions.push(
|
|
4729
|
-
(0, import_system.getTransferSolInstruction)({
|
|
4730
|
-
source: feePayerSigner,
|
|
4731
|
-
destination: tip.account,
|
|
4732
|
-
amount: tip.lamports
|
|
4733
|
-
})
|
|
4734
|
-
);
|
|
4735
|
-
}
|
|
4736
4645
|
const { value: latestBlockhash } = await rpc.getLatestBlockhash({ commitment: "confirmed" }).send();
|
|
4737
|
-
const txMessage = (0,
|
|
4738
|
-
(0,
|
|
4739
|
-
(tx) => (0,
|
|
4740
|
-
(tx) => (0,
|
|
4741
|
-
(tx) => (0,
|
|
4742
|
-
(tx) => (0,
|
|
4646
|
+
const txMessage = (0, import_kit4.pipe)(
|
|
4647
|
+
(0, import_kit4.createTransactionMessage)({ version: 0 }),
|
|
4648
|
+
(tx) => (0, import_kit4.setTransactionMessageFeePayerSigner)(signer, tx),
|
|
4649
|
+
(tx) => (0, import_kit4.setTransactionMessageLifetimeUsingBlockhash)(latestBlockhash, tx),
|
|
4650
|
+
(tx) => (0, import_kit4.appendTransactionMessageInstructions)(instructions, tx),
|
|
4651
|
+
(tx) => (0, import_kit4.addSignersToTransactionMessage)([orderSigner], tx)
|
|
4743
4652
|
);
|
|
4744
|
-
const partiallySignedTransaction = await (0,
|
|
4745
|
-
const txBytes = (0,
|
|
4653
|
+
const partiallySignedTransaction = await (0, import_kit4.partiallySignTransactionMessageWithSigners)(txMessage);
|
|
4654
|
+
const txBytes = (0, import_kit4.getTransactionCodec)().encode(partiallySignedTransaction);
|
|
4746
4655
|
return {
|
|
4747
4656
|
orderAddress: orderSigner.address,
|
|
4748
4657
|
txBytes: Uint8Array.from(txBytes)
|
|
@@ -5336,113 +5245,113 @@ var RaydiumQuoteProvider = class {
|
|
|
5336
5245
|
};
|
|
5337
5246
|
|
|
5338
5247
|
// src/utils/quote/pumpfun/index.ts
|
|
5339
|
-
var
|
|
5248
|
+
var import_kit7 = require("@solana/kit");
|
|
5340
5249
|
|
|
5341
5250
|
// src/utils/quote/pumpfun/utils.ts
|
|
5342
|
-
var
|
|
5251
|
+
var import_kit6 = require("@solana/kit");
|
|
5343
5252
|
|
|
5344
5253
|
// src/utils/quote/pumpfun/models.ts
|
|
5345
|
-
var
|
|
5254
|
+
var import_kit5 = require("@solana/kit");
|
|
5346
5255
|
function getPumpPoolDataDecoder() {
|
|
5347
|
-
return (0,
|
|
5348
|
-
["poolBump", (0,
|
|
5349
|
-
["index", (0,
|
|
5350
|
-
["creator", (0,
|
|
5351
|
-
["baseMint", (0,
|
|
5352
|
-
["quoteMint", (0,
|
|
5353
|
-
["lpMint", (0,
|
|
5354
|
-
["poolBaseTokenAccount", (0,
|
|
5355
|
-
["poolQuoteTokenAccount", (0,
|
|
5356
|
-
["lpSupply", (0,
|
|
5357
|
-
["coinCreator", (0,
|
|
5256
|
+
return (0, import_kit5.getStructDecoder)([
|
|
5257
|
+
["poolBump", (0, import_kit5.getU8Decoder)()],
|
|
5258
|
+
["index", (0, import_kit5.getU16Decoder)()],
|
|
5259
|
+
["creator", (0, import_kit5.getAddressDecoder)()],
|
|
5260
|
+
["baseMint", (0, import_kit5.getAddressDecoder)()],
|
|
5261
|
+
["quoteMint", (0, import_kit5.getAddressDecoder)()],
|
|
5262
|
+
["lpMint", (0, import_kit5.getAddressDecoder)()],
|
|
5263
|
+
["poolBaseTokenAccount", (0, import_kit5.getAddressDecoder)()],
|
|
5264
|
+
["poolQuoteTokenAccount", (0, import_kit5.getAddressDecoder)()],
|
|
5265
|
+
["lpSupply", (0, import_kit5.getU64Decoder)()],
|
|
5266
|
+
["coinCreator", (0, import_kit5.getAddressDecoder)()]
|
|
5358
5267
|
]);
|
|
5359
5268
|
}
|
|
5360
5269
|
function getBondingCurveDecoder() {
|
|
5361
|
-
return (0,
|
|
5362
|
-
["virtualTokenReserves", (0,
|
|
5363
|
-
["virtualSolReserves", (0,
|
|
5364
|
-
["realTokenReserves", (0,
|
|
5365
|
-
["realSolReserves", (0,
|
|
5366
|
-
["tokenTotalSupply", (0,
|
|
5367
|
-
["complete", (0,
|
|
5368
|
-
["creator", (0,
|
|
5270
|
+
return (0, import_kit5.getStructDecoder)([
|
|
5271
|
+
["virtualTokenReserves", (0, import_kit5.getU64Decoder)()],
|
|
5272
|
+
["virtualSolReserves", (0, import_kit5.getU64Decoder)()],
|
|
5273
|
+
["realTokenReserves", (0, import_kit5.getU64Decoder)()],
|
|
5274
|
+
["realSolReserves", (0, import_kit5.getU64Decoder)()],
|
|
5275
|
+
["tokenTotalSupply", (0, import_kit5.getU64Decoder)()],
|
|
5276
|
+
["complete", (0, import_kit5.getBooleanDecoder)()],
|
|
5277
|
+
["creator", (0, import_kit5.getAddressDecoder)()]
|
|
5369
5278
|
]);
|
|
5370
5279
|
}
|
|
5371
5280
|
function getGlobalAccountDecoder() {
|
|
5372
|
-
return (0,
|
|
5373
|
-
["initialized", (0,
|
|
5374
|
-
["authority", (0,
|
|
5375
|
-
["feeRecipient", (0,
|
|
5376
|
-
["initialVirtualTokenReserves", (0,
|
|
5377
|
-
["initialVirtualSolReserves", (0,
|
|
5378
|
-
["initialRealTokenReserves", (0,
|
|
5379
|
-
["tokenTotalSupply", (0,
|
|
5380
|
-
["feeBasisPoints", (0,
|
|
5381
|
-
["withdrawAuthority", (0,
|
|
5382
|
-
["enableMigrate", (0,
|
|
5383
|
-
["poolMigrationFee", (0,
|
|
5384
|
-
["creatorFeeBasisPoints", (0,
|
|
5385
|
-
["feeRecipients", (0,
|
|
5281
|
+
return (0, import_kit5.getStructDecoder)([
|
|
5282
|
+
["initialized", (0, import_kit5.getBooleanDecoder)()],
|
|
5283
|
+
["authority", (0, import_kit5.getAddressDecoder)()],
|
|
5284
|
+
["feeRecipient", (0, import_kit5.getAddressDecoder)()],
|
|
5285
|
+
["initialVirtualTokenReserves", (0, import_kit5.getU64Decoder)()],
|
|
5286
|
+
["initialVirtualSolReserves", (0, import_kit5.getU64Decoder)()],
|
|
5287
|
+
["initialRealTokenReserves", (0, import_kit5.getU64Decoder)()],
|
|
5288
|
+
["tokenTotalSupply", (0, import_kit5.getU64Decoder)()],
|
|
5289
|
+
["feeBasisPoints", (0, import_kit5.getU64Decoder)()],
|
|
5290
|
+
["withdrawAuthority", (0, import_kit5.getAddressDecoder)()],
|
|
5291
|
+
["enableMigrate", (0, import_kit5.getBooleanDecoder)()],
|
|
5292
|
+
["poolMigrationFee", (0, import_kit5.getU64Decoder)()],
|
|
5293
|
+
["creatorFeeBasisPoints", (0, import_kit5.getU64Decoder)()],
|
|
5294
|
+
["feeRecipients", (0, import_kit5.getArrayDecoder)((0, import_kit5.getAddressDecoder)(), { size: 7 })],
|
|
5386
5295
|
// Fixed array of 7 Pubkeys
|
|
5387
|
-
["setCreatorAuthority", (0,
|
|
5388
|
-
["adminSetCreatorAuthority", (0,
|
|
5296
|
+
["setCreatorAuthority", (0, import_kit5.getAddressDecoder)()],
|
|
5297
|
+
["adminSetCreatorAuthority", (0, import_kit5.getAddressDecoder)()]
|
|
5389
5298
|
]);
|
|
5390
5299
|
}
|
|
5391
5300
|
function getGlobalConfigDecoder() {
|
|
5392
|
-
return (0,
|
|
5393
|
-
["admin", (0,
|
|
5394
|
-
["lpFeeBasisPoints", (0,
|
|
5395
|
-
["protocolFeeBasisPoints", (0,
|
|
5396
|
-
["disableFlags", (0,
|
|
5397
|
-
["protocolFeeRecipients", (0,
|
|
5301
|
+
return (0, import_kit5.getStructDecoder)([
|
|
5302
|
+
["admin", (0, import_kit5.getAddressDecoder)()],
|
|
5303
|
+
["lpFeeBasisPoints", (0, import_kit5.getU64Decoder)()],
|
|
5304
|
+
["protocolFeeBasisPoints", (0, import_kit5.getU64Decoder)()],
|
|
5305
|
+
["disableFlags", (0, import_kit5.getU8Decoder)()],
|
|
5306
|
+
["protocolFeeRecipients", (0, import_kit5.getArrayDecoder)((0, import_kit5.getAddressDecoder)(), { size: 8 })],
|
|
5398
5307
|
// Fixed array of 8 Pubkeys
|
|
5399
|
-
["coinCreatorFeeBasisPoints", (0,
|
|
5400
|
-
["adminSetCoinCreatorAuthority", (0,
|
|
5308
|
+
["coinCreatorFeeBasisPoints", (0, import_kit5.getU64Decoder)()],
|
|
5309
|
+
["adminSetCoinCreatorAuthority", (0, import_kit5.getAddressDecoder)()]
|
|
5401
5310
|
]);
|
|
5402
5311
|
}
|
|
5403
5312
|
|
|
5404
5313
|
// src/utils/quote/pumpfun/utils.ts
|
|
5405
5314
|
var import_token2 = require("@solana-program/token");
|
|
5406
|
-
var PUMP_FUN_PROGRAM_ADDRESS = (0,
|
|
5407
|
-
var PUMP_FUN_AMM_PROGRAM_ADDRESS = (0,
|
|
5408
|
-
var WRAPPED_NATIVE_TOKEN_PUBKEY = (0,
|
|
5409
|
-
var GLOBAL_CONFIG_AMM = (0,
|
|
5315
|
+
var PUMP_FUN_PROGRAM_ADDRESS = (0, import_kit6.address)("6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P");
|
|
5316
|
+
var PUMP_FUN_AMM_PROGRAM_ADDRESS = (0, import_kit6.address)("pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA");
|
|
5317
|
+
var WRAPPED_NATIVE_TOKEN_PUBKEY = (0, import_kit6.address)("So11111111111111111111111111111111111111112");
|
|
5318
|
+
var GLOBAL_CONFIG_AMM = (0, import_kit6.address)("ADyA8hdefvWN2dbGGWFotbzWxrAvLW83WG6QCVXvJKqw");
|
|
5410
5319
|
var ANCHOR_DISCRIMINATOR_SIZE = 8;
|
|
5411
5320
|
var globalAccountCache = null;
|
|
5412
5321
|
var globalConfigCache = null;
|
|
5413
5322
|
var migratedPoolCache = /* @__PURE__ */ new Map();
|
|
5414
5323
|
var poolTokensInfoCache = /* @__PURE__ */ new Map();
|
|
5415
5324
|
async function findBondingCurvePda(tokenMint) {
|
|
5416
|
-
const [pda] = await (0,
|
|
5325
|
+
const [pda] = await (0, import_kit6.getProgramDerivedAddress)({
|
|
5417
5326
|
programAddress: PUMP_FUN_PROGRAM_ADDRESS,
|
|
5418
|
-
seeds: [new TextEncoder().encode("bonding-curve"), (0,
|
|
5327
|
+
seeds: [new TextEncoder().encode("bonding-curve"), (0, import_kit6.getAddressEncoder)().encode(tokenMint)]
|
|
5419
5328
|
});
|
|
5420
5329
|
return pda;
|
|
5421
5330
|
}
|
|
5422
5331
|
async function findGlobalAccountPda() {
|
|
5423
|
-
const [pda] = await (0,
|
|
5332
|
+
const [pda] = await (0, import_kit6.getProgramDerivedAddress)({
|
|
5424
5333
|
programAddress: PUMP_FUN_PROGRAM_ADDRESS,
|
|
5425
5334
|
seeds: [new TextEncoder().encode("global")]
|
|
5426
5335
|
});
|
|
5427
5336
|
return pda;
|
|
5428
5337
|
}
|
|
5429
5338
|
async function findPoolAuthorityPdaAmm(mint) {
|
|
5430
|
-
const [pda] = await (0,
|
|
5339
|
+
const [pda] = await (0, import_kit6.getProgramDerivedAddress)({
|
|
5431
5340
|
programAddress: PUMP_FUN_PROGRAM_ADDRESS,
|
|
5432
|
-
seeds: [new TextEncoder().encode("pool-authority"), (0,
|
|
5341
|
+
seeds: [new TextEncoder().encode("pool-authority"), (0, import_kit6.getAddressEncoder)().encode(mint)]
|
|
5433
5342
|
});
|
|
5434
5343
|
return pda;
|
|
5435
5344
|
}
|
|
5436
5345
|
async function findPoolPdaAmm(poolAuthority, baseMint, quoteMint) {
|
|
5437
|
-
const [pda] = await (0,
|
|
5346
|
+
const [pda] = await (0, import_kit6.getProgramDerivedAddress)({
|
|
5438
5347
|
programAddress: PUMP_FUN_AMM_PROGRAM_ADDRESS,
|
|
5439
5348
|
seeds: [
|
|
5440
5349
|
new TextEncoder().encode("pool"),
|
|
5441
5350
|
new Uint8Array([0, 0]),
|
|
5442
5351
|
// Pool type bytes
|
|
5443
|
-
(0,
|
|
5444
|
-
(0,
|
|
5445
|
-
(0,
|
|
5352
|
+
(0, import_kit6.getAddressEncoder)().encode(poolAuthority),
|
|
5353
|
+
(0, import_kit6.getAddressEncoder)().encode(baseMint),
|
|
5354
|
+
(0, import_kit6.getAddressEncoder)().encode(quoteMint)
|
|
5446
5355
|
]
|
|
5447
5356
|
});
|
|
5448
5357
|
return pda;
|
|
@@ -5451,7 +5360,7 @@ async function getPumpFunBondingCurve(tokenMint) {
|
|
|
5451
5360
|
const rpc = getDefaultSolanaRPC();
|
|
5452
5361
|
try {
|
|
5453
5362
|
const pda = await findBondingCurvePda(tokenMint);
|
|
5454
|
-
const encodedAccount = await (0,
|
|
5363
|
+
const encodedAccount = await (0, import_kit6.fetchEncodedAccount)(rpc, pda);
|
|
5455
5364
|
if (!encodedAccount.exists) {
|
|
5456
5365
|
throw new Error(`Bonding curve account not found for token mint: ${tokenMint}`);
|
|
5457
5366
|
}
|
|
@@ -5475,7 +5384,7 @@ async function getPumpFunGlobalAccount() {
|
|
|
5475
5384
|
}
|
|
5476
5385
|
const rpc = getDefaultSolanaRPC();
|
|
5477
5386
|
const pda = await findGlobalAccountPda();
|
|
5478
|
-
const encodedAccount = await (0,
|
|
5387
|
+
const encodedAccount = await (0, import_kit6.fetchEncodedAccount)(rpc, pda);
|
|
5479
5388
|
if (!encodedAccount.exists) {
|
|
5480
5389
|
throw new Error(`GlobalAccount not found: ${pda}`);
|
|
5481
5390
|
}
|
|
@@ -5502,7 +5411,7 @@ async function getPumpFunGlobalConfig() {
|
|
|
5502
5411
|
return globalConfigCache.data;
|
|
5503
5412
|
}
|
|
5504
5413
|
const rpc = getDefaultSolanaRPC();
|
|
5505
|
-
const encodedAccount = await (0,
|
|
5414
|
+
const encodedAccount = await (0, import_kit6.fetchEncodedAccount)(rpc, GLOBAL_CONFIG_AMM);
|
|
5506
5415
|
if (!encodedAccount.exists) {
|
|
5507
5416
|
throw new Error(`GlobalConfig account not found: ${GLOBAL_CONFIG_AMM}`);
|
|
5508
5417
|
}
|
|
@@ -5532,7 +5441,7 @@ async function getPumpFunMigratedPool(baseMint) {
|
|
|
5532
5441
|
try {
|
|
5533
5442
|
const poolAuthorityPda = await findPoolAuthorityPdaAmm(baseMint);
|
|
5534
5443
|
const poolPda = await findPoolPdaAmm(poolAuthorityPda, baseMint, WRAPPED_NATIVE_TOKEN_PUBKEY);
|
|
5535
|
-
const encodedAccount = await (0,
|
|
5444
|
+
const encodedAccount = await (0, import_kit6.fetchEncodedAccount)(rpc, poolPda);
|
|
5536
5445
|
if (!encodedAccount.exists) {
|
|
5537
5446
|
throw new Error(`Migrated pool not found for token mint: ${baseMint}`);
|
|
5538
5447
|
}
|
|
@@ -5561,7 +5470,7 @@ async function getPoolTokensInfo(poolBaseTokenAccount, poolQuoteTokenAccount) {
|
|
|
5561
5470
|
return cached.data;
|
|
5562
5471
|
}
|
|
5563
5472
|
const rpc = getDefaultSolanaRPC();
|
|
5564
|
-
const accountsInfo = await (0,
|
|
5473
|
+
const accountsInfo = await (0, import_kit6.fetchEncodedAccounts)(rpc, [poolBaseTokenAccount, poolQuoteTokenAccount]);
|
|
5565
5474
|
const baseAccountInfo = accountsInfo[0];
|
|
5566
5475
|
if (!baseAccountInfo || !baseAccountInfo.exists) {
|
|
5567
5476
|
throw new Error(`Base token account not found: ${poolBaseTokenAccount}`);
|
|
@@ -5576,22 +5485,22 @@ async function getPoolTokensInfo(poolBaseTokenAccount, poolQuoteTokenAccount) {
|
|
|
5576
5485
|
mint: baseDecoded.mint,
|
|
5577
5486
|
owner: baseDecoded.owner,
|
|
5578
5487
|
amount: baseDecoded.amount,
|
|
5579
|
-
delegate: (0,
|
|
5488
|
+
delegate: (0, import_kit6.unwrapOption)(baseDecoded.delegate),
|
|
5580
5489
|
state: baseDecoded.state,
|
|
5581
|
-
isNative: (0,
|
|
5490
|
+
isNative: (0, import_kit6.unwrapOption)(baseDecoded.isNative),
|
|
5582
5491
|
delegatedAmount: baseDecoded.delegatedAmount,
|
|
5583
|
-
closeAuthority: (0,
|
|
5492
|
+
closeAuthority: (0, import_kit6.unwrapOption)(baseDecoded.closeAuthority)
|
|
5584
5493
|
};
|
|
5585
5494
|
const quoteDecoded = tokenDecoder.decode(quoteAccountInfo.data);
|
|
5586
5495
|
const quoteTokenAccount = {
|
|
5587
5496
|
mint: quoteDecoded.mint,
|
|
5588
5497
|
owner: quoteDecoded.owner,
|
|
5589
5498
|
amount: quoteDecoded.amount,
|
|
5590
|
-
delegate: (0,
|
|
5499
|
+
delegate: (0, import_kit6.unwrapOption)(quoteDecoded.delegate),
|
|
5591
5500
|
state: quoteDecoded.state,
|
|
5592
|
-
isNative: (0,
|
|
5501
|
+
isNative: (0, import_kit6.unwrapOption)(quoteDecoded.isNative),
|
|
5593
5502
|
delegatedAmount: quoteDecoded.delegatedAmount,
|
|
5594
|
-
closeAuthority: (0,
|
|
5503
|
+
closeAuthority: (0, import_kit6.unwrapOption)(quoteDecoded.closeAuthority)
|
|
5595
5504
|
};
|
|
5596
5505
|
poolTokensInfoCache.set(cacheKey, {
|
|
5597
5506
|
data: [baseTokenAccount, quoteTokenAccount],
|
|
@@ -5812,8 +5721,8 @@ function estimatePumpFunAmm(baseToken, quoteToken, globalConfig, amount, tradeTy
|
|
|
5812
5721
|
// src/utils/quote/pumpfun/index.ts
|
|
5813
5722
|
var PumpFunQuoteProvider = class {
|
|
5814
5723
|
async getQuote(raydiumParams) {
|
|
5815
|
-
const inputMint = (0,
|
|
5816
|
-
const outputMint = (0,
|
|
5724
|
+
const inputMint = (0, import_kit7.address)(raydiumParams.inputMint);
|
|
5725
|
+
const outputMint = (0, import_kit7.address)(raydiumParams.outputMint);
|
|
5817
5726
|
const [inputBondingCurve, outputBondingCurve] = await this.getTokensBondingCurve(inputMint, outputMint);
|
|
5818
5727
|
const { bondingCurve, isInputPrebonded } = this.ensureSinglePrebondedToken(inputBondingCurve, outputBondingCurve);
|
|
5819
5728
|
let isInputSol = inputMint === NATIVE_SOLANA_TOKEN_ADDRESS || inputMint === WRAPPED_SOL_MINT_ADDRESS;
|
|
@@ -6074,10 +5983,93 @@ var RelayQuoteProvider = class {
|
|
|
6074
5983
|
}
|
|
6075
5984
|
};
|
|
6076
5985
|
|
|
6077
|
-
// src/utils/quote/
|
|
6078
|
-
|
|
5986
|
+
// src/utils/quote/pricing/decimals.ts
|
|
5987
|
+
function convertDecimals(amount, fromDecimals, toDecimals) {
|
|
5988
|
+
const diff = toDecimals - fromDecimals;
|
|
5989
|
+
if (diff >= 0) {
|
|
5990
|
+
return amount * 10n ** BigInt(diff);
|
|
5991
|
+
}
|
|
5992
|
+
return amount / 10n ** BigInt(-diff);
|
|
5993
|
+
}
|
|
5994
|
+
|
|
5995
|
+
// src/utils/quote/pricing/estimate-amount-out.ts
|
|
5996
|
+
var IntentNotViableError = class extends Error {
|
|
5997
|
+
constructor(message) {
|
|
5998
|
+
super(message);
|
|
5999
|
+
this.name = "IntentNotViableError";
|
|
6000
|
+
}
|
|
6001
|
+
};
|
|
6002
|
+
function estimateAmountOut(swapOutput, commissionBps, expenses, commissionDenominator = 10000n) {
|
|
6003
|
+
const commissionFee = swapOutput * commissionBps / commissionDenominator;
|
|
6004
|
+
const total = expenses.gasInTokenOut + expenses.protocolFeeInTokenOut + expenses.extraTransfersInTokenOut + commissionFee;
|
|
6005
|
+
if (total >= swapOutput) {
|
|
6006
|
+
throw new IntentNotViableError(`Total expenses (${total}) meet or exceed swap output (${swapOutput})`);
|
|
6007
|
+
}
|
|
6008
|
+
return swapOutput - total;
|
|
6009
|
+
}
|
|
6010
|
+
|
|
6011
|
+
// src/utils/quote/pricing/expenses.ts
|
|
6012
|
+
init_constants();
|
|
6013
|
+
|
|
6014
|
+
// src/utils/quote/address.ts
|
|
6015
|
+
function compareAddresses2(firstAddress, secondAddress) {
|
|
6079
6016
|
return !!firstAddress && !!secondAddress && firstAddress.toLowerCase() === secondAddress.toLowerCase();
|
|
6017
|
+
}
|
|
6018
|
+
|
|
6019
|
+
// src/utils/quote/pricing/gas.ts
|
|
6020
|
+
var import_actions = require("viem/actions");
|
|
6021
|
+
init_chains();
|
|
6022
|
+
|
|
6023
|
+
// src/utils/quote/pricing/constants.ts
|
|
6024
|
+
var DEFAULT_COMMISSION_BPS = 50n;
|
|
6025
|
+
var SINGLE_CHAIN_COMMISSION_DENOMINATOR = 10000n;
|
|
6026
|
+
var CROSS_CHAIN_COMMISSION_DENOMINATOR = 100000n;
|
|
6027
|
+
var EVM_SINGLE_CHAIN_GAS_LIMIT = 3000000n;
|
|
6028
|
+
var EVM_CROSS_CHAIN_GAS_LIMIT = 2000000n;
|
|
6029
|
+
var NON_EVM_FIXED_NATIVE_GAS_COST = {
|
|
6030
|
+
[101 /* Sui */]: 20000000n,
|
|
6031
|
+
[7565164 /* Solana */]: 200000n
|
|
6080
6032
|
};
|
|
6033
|
+
|
|
6034
|
+
// src/utils/quote/pricing/gas.ts
|
|
6035
|
+
async function getNativeGasCost(params) {
|
|
6036
|
+
const { chainId, gasLimit, rpcProviderUrl } = params;
|
|
6037
|
+
if (isEvmChain(chainId)) {
|
|
6038
|
+
const client = ChainProvider.getClient(chainId, rpcProviderUrl);
|
|
6039
|
+
const gasPrice = await (0, import_actions.getGasPrice)(client);
|
|
6040
|
+
return gasLimit * gasPrice;
|
|
6041
|
+
}
|
|
6042
|
+
const fixed = NON_EVM_FIXED_NATIVE_GAS_COST[chainId];
|
|
6043
|
+
if (fixed === void 0) {
|
|
6044
|
+
throw new Error(`No fixed native gas cost configured for chain ${chainId}`);
|
|
6045
|
+
}
|
|
6046
|
+
return fixed;
|
|
6047
|
+
}
|
|
6048
|
+
|
|
6049
|
+
// src/utils/quote/pricing/expenses.ts
|
|
6050
|
+
function nativeTokenAddressForChain(chainId) {
|
|
6051
|
+
if (chainId === 7565164 /* Solana */) return NATIVE_SOLANA_TOKEN_ADDRESS;
|
|
6052
|
+
if (chainId === 101 /* Sui */) return NATIVE_SUI_TOKEN_ADDRESS;
|
|
6053
|
+
return NATIVE_EVM_ETH_ADDRESSES[0];
|
|
6054
|
+
}
|
|
6055
|
+
function isNativeToken(chainId, address9) {
|
|
6056
|
+
if (chainId === 7565164 /* Solana */) return compareAddresses2(address9, NATIVE_SOLANA_TOKEN_ADDRESS);
|
|
6057
|
+
if (chainId === 101 /* Sui */) return compareAddresses2(address9, NATIVE_SUI_TOKEN_ADDRESS);
|
|
6058
|
+
return isNativeEvmToken(address9);
|
|
6059
|
+
}
|
|
6060
|
+
async function estimateExpensesInTokenOut(params) {
|
|
6061
|
+
const { chainId, tokenOut, gasLimit, getQuote, rpcProviderUrl } = params;
|
|
6062
|
+
const nativeGasCost = await getNativeGasCost({ chainId, gasLimit, rpcProviderUrl });
|
|
6063
|
+
const gasInTokenOut = isNativeToken(chainId, tokenOut) ? nativeGasCost : (await getQuote({
|
|
6064
|
+
chainId,
|
|
6065
|
+
amount: nativeGasCost,
|
|
6066
|
+
tokenIn: nativeTokenAddressForChain(chainId),
|
|
6067
|
+
tokenOut
|
|
6068
|
+
})).amountOut;
|
|
6069
|
+
return { gasInTokenOut, protocolFeeInTokenOut: 0n, extraTransfersInTokenOut: 0n };
|
|
6070
|
+
}
|
|
6071
|
+
|
|
6072
|
+
// src/utils/quote/aggregator.ts
|
|
6081
6073
|
var QuoteProvider = class _QuoteProvider {
|
|
6082
6074
|
static async getQuote(params) {
|
|
6083
6075
|
try {
|
|
@@ -6094,6 +6086,7 @@ var QuoteProvider = class _QuoteProvider {
|
|
|
6094
6086
|
}
|
|
6095
6087
|
};
|
|
6096
6088
|
} catch (e) {
|
|
6089
|
+
if (e instanceof IntentNotViableError) throw e;
|
|
6097
6090
|
console.error("Error getting quote from routers:", e);
|
|
6098
6091
|
throw new Error("Failed to get quote from routers");
|
|
6099
6092
|
}
|
|
@@ -6123,9 +6116,19 @@ var QuoteProvider = class _QuoteProvider {
|
|
|
6123
6116
|
tokenIn: params.tokenIn,
|
|
6124
6117
|
tokenOut: sourceStable.address
|
|
6125
6118
|
};
|
|
6126
|
-
const sourceQuote = await
|
|
6127
|
-
|
|
6128
|
-
|
|
6119
|
+
const [sourceQuote, expenses] = await Promise.all([
|
|
6120
|
+
this.getSingleChainQuote(sourceSingleChainQuoteParams),
|
|
6121
|
+
estimateExpensesInTokenOut({
|
|
6122
|
+
chainId: params.destChainId,
|
|
6123
|
+
tokenOut: params.tokenOut,
|
|
6124
|
+
gasLimit: EVM_CROSS_CHAIN_GAS_LIMIT,
|
|
6125
|
+
getQuote: (p) => this.getSingleChainQuote(p)
|
|
6126
|
+
})
|
|
6127
|
+
]);
|
|
6128
|
+
const normalizedBridgeAmount = convertDecimals(
|
|
6129
|
+
sourceQuote.amountOut,
|
|
6130
|
+
sourceStable.decimals,
|
|
6131
|
+
destStable.decimals
|
|
6129
6132
|
);
|
|
6130
6133
|
const destSingleChainQuoteParams = {
|
|
6131
6134
|
chainId: params.destChainId,
|
|
@@ -6137,12 +6140,19 @@ var QuoteProvider = class _QuoteProvider {
|
|
|
6137
6140
|
const estimatedAmountInAsMinStablecoinAmount = BigInt(
|
|
6138
6141
|
Math.floor(sourceQuote.amountInUsd * 10 ** sourceStable.decimals)
|
|
6139
6142
|
);
|
|
6143
|
+
const swapOutput = destQuote.amountOutMin ?? destQuote.amountOut;
|
|
6144
|
+
const estimatedAmountOutReduced = estimateAmountOut(
|
|
6145
|
+
swapOutput,
|
|
6146
|
+
DEFAULT_COMMISSION_BPS,
|
|
6147
|
+
expenses,
|
|
6148
|
+
CROSS_CHAIN_COMMISSION_DENOMINATOR
|
|
6149
|
+
);
|
|
6140
6150
|
return {
|
|
6141
6151
|
estimatedAmountOut: destQuote.amountOut,
|
|
6142
6152
|
estimatedAmountOutUsd: destQuote.amountOutUsd,
|
|
6143
6153
|
amountInUsd: sourceQuote.amountInUsd,
|
|
6144
6154
|
estimatedAmountInAsMinStablecoinAmount,
|
|
6145
|
-
estimatedAmountOutReduced
|
|
6155
|
+
estimatedAmountOutReduced,
|
|
6146
6156
|
estimatedAmountOutUsdReduced: destQuote.amountOutUsd
|
|
6147
6157
|
};
|
|
6148
6158
|
}
|
|
@@ -6601,7 +6611,10 @@ var CrossChainOrder = class _CrossChainOrder {
|
|
|
6601
6611
|
tokenOut: this.destinationTokenAddress,
|
|
6602
6612
|
destinationAddress: this.destinationAddress,
|
|
6603
6613
|
amountOutMin: this.destinationTokenMinAmount,
|
|
6604
|
-
extraTransfers: this.extraTransfers
|
|
6614
|
+
extraTransfers: this.extraTransfers,
|
|
6615
|
+
stopLossType: this.stopLossType,
|
|
6616
|
+
stopLossTriggerPrice: this.stopLossTriggerPrice,
|
|
6617
|
+
takeProfitMinOut: this.takeProfitMinOut
|
|
6605
6618
|
};
|
|
6606
6619
|
}
|
|
6607
6620
|
executionDetailsHashToBytes() {
|
|
@@ -6782,13 +6795,22 @@ var SingleChainOrder = class _SingleChainOrder {
|
|
|
6782
6795
|
});
|
|
6783
6796
|
switch (scenario) {
|
|
6784
6797
|
case "QUOTE_REQUIRED": {
|
|
6785
|
-
const quote = await
|
|
6786
|
-
|
|
6787
|
-
|
|
6788
|
-
|
|
6789
|
-
|
|
6790
|
-
|
|
6791
|
-
|
|
6798
|
+
const [quote, expenses] = await Promise.all([
|
|
6799
|
+
QuoteProvider.getSingleChainQuote({
|
|
6800
|
+
tokenIn: input.tokenIn,
|
|
6801
|
+
amount: input.amountIn,
|
|
6802
|
+
chainId: input.chainId,
|
|
6803
|
+
tokenOut: input.tokenOut
|
|
6804
|
+
}),
|
|
6805
|
+
estimateExpensesInTokenOut({
|
|
6806
|
+
chainId: input.chainId,
|
|
6807
|
+
tokenOut: input.tokenOut,
|
|
6808
|
+
gasLimit: EVM_SINGLE_CHAIN_GAS_LIMIT,
|
|
6809
|
+
getQuote: (p) => QuoteProvider.getSingleChainQuote(p)
|
|
6810
|
+
})
|
|
6811
|
+
]);
|
|
6812
|
+
const swapOutput = quote.amountOutMin ?? quote.amountOut;
|
|
6813
|
+
return estimateAmountOut(swapOutput, DEFAULT_COMMISSION_BPS, expenses, SINGLE_CHAIN_COMMISSION_DENOMINATOR);
|
|
6792
6814
|
}
|
|
6793
6815
|
case "USE_PROVIDED_AMOUNT":
|
|
6794
6816
|
return amountOutMin;
|
|
@@ -6848,7 +6870,7 @@ var BaseSDK = class _BaseSDK {
|
|
|
6848
6870
|
static async makeRequest(url, body) {
|
|
6849
6871
|
const response = await fetch(url, {
|
|
6850
6872
|
method: "POST",
|
|
6851
|
-
headers:
|
|
6873
|
+
headers: { "Content-Type": "application/json" },
|
|
6852
6874
|
body
|
|
6853
6875
|
});
|
|
6854
6876
|
console.debug(`url`, url, `body`, body);
|
|
@@ -6917,30 +6939,36 @@ var BaseSDK = class _BaseSDK {
|
|
|
6917
6939
|
static async validateDcaSingleChainOrder(intentRequest) {
|
|
6918
6940
|
return _BaseSDK.validateOrder(intentRequest, "/validate_intent/single_chain/dca_order");
|
|
6919
6941
|
}
|
|
6942
|
+
static async validateDcaCrossChainOrder(intentRequest) {
|
|
6943
|
+
return _BaseSDK.validateOrder(intentRequest, "/validate_intent/cross_chain/dca_order");
|
|
6944
|
+
}
|
|
6945
|
+
static async sendDcaCrossChainOrder(intentRequest) {
|
|
6946
|
+
const body = JSON.stringify(intentRequest, Parsers.bigIntReplacer);
|
|
6947
|
+
return _BaseSDK.makeRequest(`${AUCTIONEER_URL}/user_intent/cross_chain/dca_order`, body);
|
|
6948
|
+
}
|
|
6920
6949
|
};
|
|
6921
6950
|
|
|
6922
6951
|
// src/core/solana/dca/create-order.ts
|
|
6923
|
-
var
|
|
6952
|
+
var import_kit8 = require("@solana/kit");
|
|
6924
6953
|
init_constants();
|
|
6925
6954
|
var import_token3 = require("@solana-program/token");
|
|
6926
6955
|
var import_system2 = require("@solana-program/system");
|
|
6927
6956
|
async function getSolanaDcaSingleChainOrderInstructions(order, options) {
|
|
6928
|
-
const rpc = options?.rpcUrl ? (0,
|
|
6929
|
-
const orderSigner = await (0,
|
|
6930
|
-
const
|
|
6931
|
-
|
|
6932
|
-
let tokenInMint = (0, import_kit9.address)(order.tokenIn);
|
|
6957
|
+
const rpc = options?.rpcUrl ? (0, import_kit8.createSolanaRpc)(options.rpcUrl) : getDefaultSolanaRPC();
|
|
6958
|
+
const orderSigner = await (0, import_kit8.generateKeyPairSigner)();
|
|
6959
|
+
const signer = (0, import_kit8.createNoopSigner)(order.user);
|
|
6960
|
+
let tokenInMint = (0, import_kit8.address)(order.tokenIn);
|
|
6933
6961
|
const { secretHash, secretNumber } = genSecretHashAndNumber(order);
|
|
6934
|
-
const orderUserAddress = (0,
|
|
6962
|
+
const orderUserAddress = (0, import_kit8.address)(order.user);
|
|
6935
6963
|
const spendingNative = tokenInMint === NATIVE_SOLANA_TOKEN_ADDRESS;
|
|
6936
6964
|
if (spendingNative) {
|
|
6937
6965
|
tokenInMint = WRAPPED_SOL_MINT_ADDRESS;
|
|
6938
6966
|
}
|
|
6939
6967
|
const tokenMintProgram = await (0, import_token3.fetchMint)(rpc, tokenInMint);
|
|
6940
|
-
const guardAddress = (0,
|
|
6941
|
-
const addressEncoder = (0,
|
|
6968
|
+
const guardAddress = (0, import_kit8.address)(SINGLE_CHAIN_GUARD_ADDRESSES[7565164 /* Solana */]);
|
|
6969
|
+
const addressEncoder = (0, import_kit8.getAddressEncoder)();
|
|
6942
6970
|
const instructions = [];
|
|
6943
|
-
const [tokenInProgramAccount] = await (0,
|
|
6971
|
+
const [tokenInProgramAccount] = await (0, import_kit8.getProgramDerivedAddress)({
|
|
6944
6972
|
programAddress: import_token3.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
6945
6973
|
seeds: [
|
|
6946
6974
|
addressEncoder.encode(orderUserAddress),
|
|
@@ -6948,10 +6976,10 @@ async function getSolanaDcaSingleChainOrderInstructions(order, options) {
|
|
|
6948
6976
|
addressEncoder.encode(tokenInMint)
|
|
6949
6977
|
]
|
|
6950
6978
|
});
|
|
6951
|
-
const userTokenInAccount = await (0,
|
|
6979
|
+
const userTokenInAccount = await (0, import_kit8.fetchEncodedAccount)(rpc, tokenInProgramAccount);
|
|
6952
6980
|
if (!userTokenInAccount.exists) {
|
|
6953
6981
|
const createAccountIx = await (0, import_token3.getCreateAssociatedTokenInstructionAsync)({
|
|
6954
|
-
payer:
|
|
6982
|
+
payer: signer,
|
|
6955
6983
|
ata: tokenInProgramAccount,
|
|
6956
6984
|
owner: orderUserAddress,
|
|
6957
6985
|
mint: tokenMintProgram.address,
|
|
@@ -6964,7 +6992,7 @@ async function getSolanaDcaSingleChainOrderInstructions(order, options) {
|
|
|
6964
6992
|
const transferIx = (0, import_system2.getTransferSolInstruction)({
|
|
6965
6993
|
amount: totalAmountIn,
|
|
6966
6994
|
destination: userTokenInAccount.address,
|
|
6967
|
-
source:
|
|
6995
|
+
source: signer
|
|
6968
6996
|
});
|
|
6969
6997
|
instructions.push(transferIx);
|
|
6970
6998
|
const syncNativeIx = (0, import_token3.getSyncNativeInstruction)({
|
|
@@ -6973,7 +7001,7 @@ async function getSolanaDcaSingleChainOrderInstructions(order, options) {
|
|
|
6973
7001
|
instructions.push(syncNativeIx);
|
|
6974
7002
|
}
|
|
6975
7003
|
const createDcaOrderIx = await getCreateDcaOrderInstructionAsync({
|
|
6976
|
-
user:
|
|
7004
|
+
user: signer,
|
|
6977
7005
|
order: orderSigner,
|
|
6978
7006
|
guard: guardAddress,
|
|
6979
7007
|
tokenInMint,
|
|
@@ -6989,26 +7017,16 @@ async function getSolanaDcaSingleChainOrderInstructions(order, options) {
|
|
|
6989
7017
|
// TODO: Implement extra transfers
|
|
6990
7018
|
});
|
|
6991
7019
|
instructions.push(createDcaOrderIx);
|
|
6992
|
-
const tip = resolveSolanaTip(options);
|
|
6993
|
-
if (tip) {
|
|
6994
|
-
instructions.push(
|
|
6995
|
-
(0, import_system2.getTransferSolInstruction)({
|
|
6996
|
-
source: feePayerSigner,
|
|
6997
|
-
destination: tip.account,
|
|
6998
|
-
amount: tip.lamports
|
|
6999
|
-
})
|
|
7000
|
-
);
|
|
7001
|
-
}
|
|
7002
7020
|
const { value: latestBlockhash } = await rpc.getLatestBlockhash({ commitment: "confirmed" }).send();
|
|
7003
|
-
const txMessage = (0,
|
|
7004
|
-
(0,
|
|
7005
|
-
(tx) => (0,
|
|
7006
|
-
(tx) => (0,
|
|
7007
|
-
(tx) => (0,
|
|
7008
|
-
(tx) => (0,
|
|
7021
|
+
const txMessage = (0, import_kit8.pipe)(
|
|
7022
|
+
(0, import_kit8.createTransactionMessage)({ version: 0 }),
|
|
7023
|
+
(tx) => (0, import_kit8.setTransactionMessageFeePayerSigner)(signer, tx),
|
|
7024
|
+
(tx) => (0, import_kit8.setTransactionMessageLifetimeUsingBlockhash)(latestBlockhash, tx),
|
|
7025
|
+
(tx) => (0, import_kit8.appendTransactionMessageInstructions)(instructions, tx),
|
|
7026
|
+
(tx) => (0, import_kit8.addSignersToTransactionMessage)([orderSigner], tx)
|
|
7009
7027
|
);
|
|
7010
|
-
const partiallySignedTransaction = await (0,
|
|
7011
|
-
const txBytes = (0,
|
|
7028
|
+
const partiallySignedTransaction = await (0, import_kit8.partiallySignTransactionMessageWithSigners)(txMessage);
|
|
7029
|
+
const txBytes = (0, import_kit8.getTransactionCodec)().encode(partiallySignedTransaction);
|
|
7012
7030
|
return {
|
|
7013
7031
|
orderAddress: orderSigner.address,
|
|
7014
7032
|
txBytes,
|
|
@@ -7133,9 +7151,7 @@ init_constants();
|
|
|
7133
7151
|
init_constants();
|
|
7134
7152
|
async function fetchSiweMessage(params) {
|
|
7135
7153
|
const url = `${AUCTIONEER_URL}/siwe?wallet=${params.wallet}&chainId=${params.chainId}`;
|
|
7136
|
-
const response = await fetch(url
|
|
7137
|
-
headers: withAuctioneerHeaders()
|
|
7138
|
-
});
|
|
7154
|
+
const response = await fetch(url);
|
|
7139
7155
|
if (!response.ok) {
|
|
7140
7156
|
throw new Error(`Failed to fetch SIWE message: ${response.status} ${response.statusText}`);
|
|
7141
7157
|
}
|
|
@@ -7144,12 +7160,14 @@ async function fetchSiweMessage(params) {
|
|
|
7144
7160
|
}
|
|
7145
7161
|
async function fetchJWTToken(params, token) {
|
|
7146
7162
|
const url = `${AUCTIONEER_URL}/siwe`;
|
|
7163
|
+
const headers = { "Content-Type": "application/json" };
|
|
7164
|
+
if (token) {
|
|
7165
|
+
headers.Authorization = `Bearer ${token}`;
|
|
7166
|
+
}
|
|
7147
7167
|
const response = await fetch(url, {
|
|
7148
7168
|
method: "POST",
|
|
7149
7169
|
body: JSON.stringify(params),
|
|
7150
|
-
headers
|
|
7151
|
-
Authorization: `Bearer ${token}`
|
|
7152
|
-
})
|
|
7170
|
+
headers
|
|
7153
7171
|
});
|
|
7154
7172
|
if (!response.ok) {
|
|
7155
7173
|
throw new Error(`Failed to fetch JWT token: ${response.status} ${response.statusText}`);
|
|
@@ -7315,15 +7333,15 @@ var EVMSDK = class extends BaseSDK {
|
|
|
7315
7333
|
};
|
|
7316
7334
|
|
|
7317
7335
|
// src/core/solana/sdk.ts
|
|
7318
|
-
var
|
|
7336
|
+
var import_kit11 = require("@solana/kit");
|
|
7319
7337
|
|
|
7320
7338
|
// src/core/solana/cancel-order.ts
|
|
7321
|
-
var
|
|
7339
|
+
var import_kit9 = require("@solana/kit");
|
|
7322
7340
|
var import_token4 = require("@solana-program/token");
|
|
7323
7341
|
init_constants();
|
|
7324
7342
|
async function cancelSingleChainOrderInstructions(orderAddress, options) {
|
|
7325
|
-
const rpc = options?.rpcUrl ? (0,
|
|
7326
|
-
const orderId = (0,
|
|
7343
|
+
const rpc = options?.rpcUrl ? (0, import_kit9.createSolanaRpc)(options.rpcUrl) : getDefaultSolanaRPC();
|
|
7344
|
+
const orderId = (0, import_kit9.address)(orderAddress);
|
|
7327
7345
|
const chainOrder = await fetchMaybeLimitOrder(rpc, orderId);
|
|
7328
7346
|
if (!chainOrder.exists) {
|
|
7329
7347
|
throw new Error(`Order with address ${orderAddress} not found`);
|
|
@@ -7332,8 +7350,8 @@ async function cancelSingleChainOrderInstructions(orderAddress, options) {
|
|
|
7332
7350
|
const orderUserAddress = chainOrder.data.user;
|
|
7333
7351
|
const tokenInMint = chainOrder.data.tokenInMint;
|
|
7334
7352
|
const tokenMintProgram = await (0, import_token4.fetchMint)(rpc, tokenInMint);
|
|
7335
|
-
const addressEncoder = (0,
|
|
7336
|
-
const [tokenInProgramAccount] = await (0,
|
|
7353
|
+
const addressEncoder = (0, import_kit9.getAddressEncoder)();
|
|
7354
|
+
const [tokenInProgramAccount] = await (0, import_kit9.getProgramDerivedAddress)({
|
|
7337
7355
|
programAddress: import_token4.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
7338
7356
|
seeds: [
|
|
7339
7357
|
addressEncoder.encode(orderUserAddress),
|
|
@@ -7342,7 +7360,7 @@ async function cancelSingleChainOrderInstructions(orderAddress, options) {
|
|
|
7342
7360
|
]
|
|
7343
7361
|
});
|
|
7344
7362
|
const guardAddress = SINGLE_CHAIN_GUARD_ADDRESSES[7565164 /* Solana */];
|
|
7345
|
-
const [guardProgramAccount] = await (0,
|
|
7363
|
+
const [guardProgramAccount] = await (0, import_kit9.getProgramDerivedAddress)({
|
|
7346
7364
|
programAddress: import_token4.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
7347
7365
|
seeds: [
|
|
7348
7366
|
// Owner
|
|
@@ -7353,12 +7371,12 @@ async function cancelSingleChainOrderInstructions(orderAddress, options) {
|
|
|
7353
7371
|
addressEncoder.encode(tokenInMint)
|
|
7354
7372
|
]
|
|
7355
7373
|
});
|
|
7356
|
-
const userTokenInAccount = await (0,
|
|
7374
|
+
const userTokenInAccount = await (0, import_kit9.fetchEncodedAccount)(rpc, tokenInProgramAccount);
|
|
7357
7375
|
if (!userTokenInAccount.exists) {
|
|
7358
7376
|
const createTokenIx = await (0, import_token4.getCreateAssociatedTokenInstructionAsync)({
|
|
7359
7377
|
mint: tokenInMint,
|
|
7360
7378
|
owner: orderUserAddress,
|
|
7361
|
-
payer: (0,
|
|
7379
|
+
payer: (0, import_kit9.createNoopSigner)(orderUserAddress),
|
|
7362
7380
|
tokenProgram: tokenMintProgram.programAddress
|
|
7363
7381
|
});
|
|
7364
7382
|
instructions.push(createTokenIx);
|
|
@@ -7370,43 +7388,43 @@ async function cancelSingleChainOrderInstructions(orderAddress, options) {
|
|
|
7370
7388
|
userTokenInAccount: userTokenInAccount.address,
|
|
7371
7389
|
guardTokenInAccount: guardProgramAccount,
|
|
7372
7390
|
tokenInProgram: tokenMintProgram.programAddress,
|
|
7373
|
-
signer: (0,
|
|
7391
|
+
signer: (0, import_kit9.createNoopSigner)(orderUserAddress),
|
|
7374
7392
|
user: orderUserAddress
|
|
7375
7393
|
});
|
|
7376
7394
|
instructions.push(cancelLimitOrderIx);
|
|
7377
7395
|
return instructions;
|
|
7378
7396
|
}
|
|
7379
7397
|
async function cancelCrossChainOrderInstructionsAsBytes(orderAddress, signerAddress, options) {
|
|
7380
|
-
const rpc = options?.rpcUrl ? (0,
|
|
7398
|
+
const rpc = options?.rpcUrl ? (0, import_kit9.createSolanaRpc)(options.rpcUrl) : getDefaultSolanaRPC();
|
|
7381
7399
|
const instructions = await cancelCrossChainOrderInstructions(orderAddress, options);
|
|
7382
7400
|
const { value: latestBlockhash } = await rpc.getLatestBlockhash({ commitment: "confirmed" }).send();
|
|
7383
|
-
const txMessage = (0,
|
|
7384
|
-
(0,
|
|
7385
|
-
(tx) => (0,
|
|
7386
|
-
(tx) => (0,
|
|
7387
|
-
(tx) => (0,
|
|
7401
|
+
const txMessage = (0, import_kit9.pipe)(
|
|
7402
|
+
(0, import_kit9.createTransactionMessage)({ version: 0 }),
|
|
7403
|
+
(tx) => (0, import_kit9.setTransactionMessageFeePayerSigner)((0, import_kit9.createNoopSigner)((0, import_kit9.address)(signerAddress)), tx),
|
|
7404
|
+
(tx) => (0, import_kit9.setTransactionMessageLifetimeUsingBlockhash)(latestBlockhash, tx),
|
|
7405
|
+
(tx) => (0, import_kit9.appendTransactionMessageInstructions)(instructions, tx)
|
|
7388
7406
|
);
|
|
7389
|
-
const compiledTxMessage = (0,
|
|
7390
|
-
const txBytes = (0,
|
|
7407
|
+
const compiledTxMessage = (0, import_kit9.compileTransactionMessage)(txMessage);
|
|
7408
|
+
const txBytes = (0, import_kit9.getCompiledTransactionMessageEncoder)().encode(compiledTxMessage);
|
|
7391
7409
|
return { versionedMessageBytes: txBytes };
|
|
7392
7410
|
}
|
|
7393
7411
|
async function cancelSingleChainOrderInstructionsAsBytes(orderAddress, signerAddress, options) {
|
|
7394
|
-
const rpc = options?.rpcUrl ? (0,
|
|
7412
|
+
const rpc = options?.rpcUrl ? (0, import_kit9.createSolanaRpc)(options.rpcUrl) : getDefaultSolanaRPC();
|
|
7395
7413
|
const instructions = await cancelSingleChainOrderInstructions(orderAddress, options);
|
|
7396
7414
|
const { value: latestBlockhash } = await rpc.getLatestBlockhash({ commitment: "confirmed" }).send();
|
|
7397
|
-
const txMessage = (0,
|
|
7398
|
-
(0,
|
|
7399
|
-
(tx) => (0,
|
|
7400
|
-
(tx) => (0,
|
|
7401
|
-
(tx) => (0,
|
|
7415
|
+
const txMessage = (0, import_kit9.pipe)(
|
|
7416
|
+
(0, import_kit9.createTransactionMessage)({ version: 0 }),
|
|
7417
|
+
(tx) => (0, import_kit9.setTransactionMessageFeePayerSigner)((0, import_kit9.createNoopSigner)((0, import_kit9.address)(signerAddress)), tx),
|
|
7418
|
+
(tx) => (0, import_kit9.setTransactionMessageLifetimeUsingBlockhash)(latestBlockhash, tx),
|
|
7419
|
+
(tx) => (0, import_kit9.appendTransactionMessageInstructions)(instructions, tx)
|
|
7402
7420
|
);
|
|
7403
|
-
const compiledTxMessage = (0,
|
|
7404
|
-
const txBytes = (0,
|
|
7421
|
+
const compiledTxMessage = (0, import_kit9.compileTransactionMessage)(txMessage);
|
|
7422
|
+
const txBytes = (0, import_kit9.getCompiledTransactionMessageEncoder)().encode(compiledTxMessage);
|
|
7405
7423
|
return { versionedMessageBytes: txBytes };
|
|
7406
7424
|
}
|
|
7407
7425
|
async function cancelCrossChainOrderInstructions(orderAddress, options) {
|
|
7408
|
-
const rpc = options?.rpcUrl ? (0,
|
|
7409
|
-
const orderId = (0,
|
|
7426
|
+
const rpc = options?.rpcUrl ? (0, import_kit9.createSolanaRpc)(options.rpcUrl) : getDefaultSolanaRPC();
|
|
7427
|
+
const orderId = (0, import_kit9.address)(orderAddress);
|
|
7410
7428
|
const chainOrder = await fetchMaybeOrder(rpc, orderId);
|
|
7411
7429
|
if (!chainOrder.exists) {
|
|
7412
7430
|
throw new Error(`Order with address ${orderAddress} not found`);
|
|
@@ -7414,11 +7432,11 @@ async function cancelCrossChainOrderInstructions(orderAddress, options) {
|
|
|
7414
7432
|
const instructions = [];
|
|
7415
7433
|
const orderUserAddress = chainOrder.data.user;
|
|
7416
7434
|
const guardAddress = CROSS_CHAIN_GUARD_ADDRESSES[7565164 /* Solana */];
|
|
7417
|
-
const addressEncoder = (0,
|
|
7435
|
+
const addressEncoder = (0, import_kit9.getAddressEncoder)();
|
|
7418
7436
|
const isRecoveringTokenIn = chainOrder.data.lockedStablecoins === 0n;
|
|
7419
|
-
const recoverTokenMint = isRecoveringTokenIn ? chainOrder.data.tokenInMint : (0,
|
|
7437
|
+
const recoverTokenMint = isRecoveringTokenIn ? chainOrder.data.tokenInMint : (0, import_kit9.address)(SOLANA_MINT_TOKEN.mint);
|
|
7420
7438
|
const recoverTokenMintProgram = await (0, import_token4.fetchMint)(rpc, recoverTokenMint);
|
|
7421
|
-
const [userRecoveredTokenAccount] = await (0,
|
|
7439
|
+
const [userRecoveredTokenAccount] = await (0, import_kit9.getProgramDerivedAddress)({
|
|
7422
7440
|
programAddress: import_token4.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
7423
7441
|
seeds: [
|
|
7424
7442
|
addressEncoder.encode(orderUserAddress),
|
|
@@ -7426,7 +7444,7 @@ async function cancelCrossChainOrderInstructions(orderAddress, options) {
|
|
|
7426
7444
|
addressEncoder.encode(recoverTokenMint)
|
|
7427
7445
|
]
|
|
7428
7446
|
});
|
|
7429
|
-
const [guardRecoveredTokenAccount] = await (0,
|
|
7447
|
+
const [guardRecoveredTokenAccount] = await (0, import_kit9.getProgramDerivedAddress)({
|
|
7430
7448
|
programAddress: import_token4.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
7431
7449
|
seeds: [
|
|
7432
7450
|
addressEncoder.encode(guardAddress),
|
|
@@ -7434,10 +7452,10 @@ async function cancelCrossChainOrderInstructions(orderAddress, options) {
|
|
|
7434
7452
|
addressEncoder.encode(recoverTokenMint)
|
|
7435
7453
|
]
|
|
7436
7454
|
});
|
|
7437
|
-
const userRecoveredTokenAccountInfo = await (0,
|
|
7455
|
+
const userRecoveredTokenAccountInfo = await (0, import_kit9.fetchEncodedAccount)(rpc, userRecoveredTokenAccount);
|
|
7438
7456
|
if (!userRecoveredTokenAccountInfo.exists) {
|
|
7439
7457
|
const createRecoveredTokenAccountIx = await (0, import_token4.getCreateAssociatedTokenInstructionAsync)({
|
|
7440
|
-
payer: (0,
|
|
7458
|
+
payer: (0, import_kit9.createNoopSigner)(orderUserAddress),
|
|
7441
7459
|
ata: userRecoveredTokenAccount,
|
|
7442
7460
|
owner: orderUserAddress,
|
|
7443
7461
|
mint: recoverTokenMint,
|
|
@@ -7448,9 +7466,9 @@ async function cancelCrossChainOrderInstructions(orderAddress, options) {
|
|
|
7448
7466
|
let userCollateralTokenAccount;
|
|
7449
7467
|
const willClaimCollateral = chainOrder.data.lockedCollateral > 0n;
|
|
7450
7468
|
if (willClaimCollateral) {
|
|
7451
|
-
const collateralTokenMint2 = (0,
|
|
7469
|
+
const collateralTokenMint2 = (0, import_kit9.address)(SOLANA_MINT_TOKEN.mint);
|
|
7452
7470
|
const collateralTokenMintProgram2 = await (0, import_token4.fetchMint)(rpc, collateralTokenMint2);
|
|
7453
|
-
const [userCollateralAccount] = await (0,
|
|
7471
|
+
const [userCollateralAccount] = await (0, import_kit9.getProgramDerivedAddress)({
|
|
7454
7472
|
programAddress: import_token4.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
7455
7473
|
seeds: [
|
|
7456
7474
|
addressEncoder.encode(orderUserAddress),
|
|
@@ -7459,10 +7477,10 @@ async function cancelCrossChainOrderInstructions(orderAddress, options) {
|
|
|
7459
7477
|
]
|
|
7460
7478
|
});
|
|
7461
7479
|
userCollateralTokenAccount = userCollateralAccount;
|
|
7462
|
-
const userCollateralTokenAccountInfo = await (0,
|
|
7480
|
+
const userCollateralTokenAccountInfo = await (0, import_kit9.fetchEncodedAccount)(rpc, userCollateralTokenAccount);
|
|
7463
7481
|
if (!userCollateralTokenAccountInfo.exists) {
|
|
7464
7482
|
const createCollateralTokenAccountIx = await (0, import_token4.getCreateAssociatedTokenInstructionAsync)({
|
|
7465
|
-
payer: (0,
|
|
7483
|
+
payer: (0, import_kit9.createNoopSigner)(orderUserAddress),
|
|
7466
7484
|
ata: userCollateralTokenAccount,
|
|
7467
7485
|
owner: orderUserAddress,
|
|
7468
7486
|
mint: collateralTokenMint2,
|
|
@@ -7471,9 +7489,9 @@ async function cancelCrossChainOrderInstructions(orderAddress, options) {
|
|
|
7471
7489
|
instructions.push(createCollateralTokenAccountIx);
|
|
7472
7490
|
}
|
|
7473
7491
|
}
|
|
7474
|
-
const collateralTokenMint = (0,
|
|
7492
|
+
const collateralTokenMint = (0, import_kit9.address)(SOLANA_MINT_TOKEN.mint);
|
|
7475
7493
|
const collateralTokenMintProgram = await (0, import_token4.fetchMint)(rpc, collateralTokenMint);
|
|
7476
|
-
const [guardCollateralTokenAccount] = await (0,
|
|
7494
|
+
const [guardCollateralTokenAccount] = await (0, import_kit9.getProgramDerivedAddress)({
|
|
7477
7495
|
programAddress: import_token4.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
7478
7496
|
seeds: [
|
|
7479
7497
|
addressEncoder.encode(guardAddress),
|
|
@@ -7493,7 +7511,7 @@ async function cancelCrossChainOrderInstructions(orderAddress, options) {
|
|
|
7493
7511
|
userCollateralTokenAccount,
|
|
7494
7512
|
guardCollateralTokenAccount,
|
|
7495
7513
|
collateralTokenProgram: collateralTokenMintProgram.programAddress,
|
|
7496
|
-
signer: (0,
|
|
7514
|
+
signer: (0, import_kit9.createNoopSigner)(orderUserAddress)
|
|
7497
7515
|
});
|
|
7498
7516
|
instructions.push(cancelOrderIx);
|
|
7499
7517
|
return instructions;
|
|
@@ -7503,12 +7521,12 @@ async function cancelCrossChainOrderInstructions(orderAddress, options) {
|
|
|
7503
7521
|
var import_viem11 = require("viem");
|
|
7504
7522
|
|
|
7505
7523
|
// src/core/solana/dca/cancel-order.ts
|
|
7506
|
-
var
|
|
7524
|
+
var import_kit10 = require("@solana/kit");
|
|
7507
7525
|
var import_token5 = require("@solana-program/token");
|
|
7508
7526
|
init_constants();
|
|
7509
7527
|
async function cancelDcaSingleChainOrderInstructions(orderAddress, options) {
|
|
7510
|
-
const rpc = options?.rpcUrl ? (0,
|
|
7511
|
-
const orderId = (0,
|
|
7528
|
+
const rpc = options?.rpcUrl ? (0, import_kit10.createSolanaRpc)(options.rpcUrl) : getDefaultSolanaRPC();
|
|
7529
|
+
const orderId = (0, import_kit10.address)(orderAddress);
|
|
7512
7530
|
const chainOrder = await fetchMaybeDcaOrder(rpc, orderId);
|
|
7513
7531
|
if (!chainOrder.exists) {
|
|
7514
7532
|
throw new Error(`Order with address ${orderAddress} not found`);
|
|
@@ -7517,8 +7535,8 @@ async function cancelDcaSingleChainOrderInstructions(orderAddress, options) {
|
|
|
7517
7535
|
const orderUserAddress = chainOrder.data.user;
|
|
7518
7536
|
const tokenInMint = chainOrder.data.tokenInMint;
|
|
7519
7537
|
const tokenMintProgram = await (0, import_token5.fetchMint)(rpc, tokenInMint);
|
|
7520
|
-
const addressEncoder = (0,
|
|
7521
|
-
const [tokenInProgramAccount] = await (0,
|
|
7538
|
+
const addressEncoder = (0, import_kit10.getAddressEncoder)();
|
|
7539
|
+
const [tokenInProgramAccount] = await (0, import_kit10.getProgramDerivedAddress)({
|
|
7522
7540
|
programAddress: import_token5.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
7523
7541
|
seeds: [
|
|
7524
7542
|
addressEncoder.encode(orderUserAddress),
|
|
@@ -7527,7 +7545,7 @@ async function cancelDcaSingleChainOrderInstructions(orderAddress, options) {
|
|
|
7527
7545
|
]
|
|
7528
7546
|
});
|
|
7529
7547
|
const guardAddress = SINGLE_CHAIN_GUARD_ADDRESSES[7565164 /* Solana */];
|
|
7530
|
-
const [guardProgramAccount] = await (0,
|
|
7548
|
+
const [guardProgramAccount] = await (0, import_kit10.getProgramDerivedAddress)({
|
|
7531
7549
|
programAddress: import_token5.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
7532
7550
|
seeds: [
|
|
7533
7551
|
// Owner
|
|
@@ -7538,19 +7556,19 @@ async function cancelDcaSingleChainOrderInstructions(orderAddress, options) {
|
|
|
7538
7556
|
addressEncoder.encode(tokenInMint)
|
|
7539
7557
|
]
|
|
7540
7558
|
});
|
|
7541
|
-
const userTokenInAccount = await (0,
|
|
7559
|
+
const userTokenInAccount = await (0, import_kit10.fetchEncodedAccount)(rpc, tokenInProgramAccount);
|
|
7542
7560
|
if (!userTokenInAccount.exists) {
|
|
7543
7561
|
const createTokenIx = await (0, import_token5.getCreateAssociatedTokenInstructionAsync)({
|
|
7544
7562
|
mint: tokenInMint,
|
|
7545
7563
|
owner: orderUserAddress,
|
|
7546
|
-
payer: (0,
|
|
7564
|
+
payer: (0, import_kit10.createNoopSigner)(orderUserAddress),
|
|
7547
7565
|
tokenProgram: tokenMintProgram.programAddress
|
|
7548
7566
|
});
|
|
7549
7567
|
instructions.push(createTokenIx);
|
|
7550
7568
|
}
|
|
7551
7569
|
const cancelLimitOrderIx = getCancelDcaOrderInstruction({
|
|
7552
7570
|
user: orderUserAddress,
|
|
7553
|
-
signer: (0,
|
|
7571
|
+
signer: (0, import_kit10.createNoopSigner)(orderUserAddress),
|
|
7554
7572
|
order: orderId,
|
|
7555
7573
|
guard: guardAddress,
|
|
7556
7574
|
tokenInMint: chainOrder.data.tokenInMint,
|
|
@@ -7594,17 +7612,17 @@ var SolanaSDK = class extends BaseSDK {
|
|
|
7594
7612
|
const instructions = await cancelCrossChainOrderInstructions(orderId, { rpcUrl: this.config.rpcProviderUrl });
|
|
7595
7613
|
const signer = await this.getUserSigner();
|
|
7596
7614
|
const signerKeyPair = await this.getUserCryptoKeypair();
|
|
7597
|
-
const noopSigner = (0,
|
|
7615
|
+
const noopSigner = (0, import_kit11.createNoopSigner)(signer.address);
|
|
7598
7616
|
const { value: latestBlockhash } = await this.client.rpc.getLatestBlockhash({ commitment: this.config.commitment }).send();
|
|
7599
|
-
const transactionMessage = (0,
|
|
7600
|
-
(0,
|
|
7601
|
-
(tx) => (0,
|
|
7602
|
-
(tx) => (0,
|
|
7603
|
-
(tx) => (0,
|
|
7617
|
+
const transactionMessage = (0, import_kit11.pipe)(
|
|
7618
|
+
(0, import_kit11.createTransactionMessage)({ version: 0 }),
|
|
7619
|
+
(tx) => (0, import_kit11.setTransactionMessageFeePayerSigner)(noopSigner, tx),
|
|
7620
|
+
(tx) => (0, import_kit11.setTransactionMessageLifetimeUsingBlockhash)(latestBlockhash, tx),
|
|
7621
|
+
(tx) => (0, import_kit11.appendTransactionMessageInstructions)(instructions, tx)
|
|
7604
7622
|
);
|
|
7605
|
-
const myTx = (0,
|
|
7606
|
-
const signature = await (0,
|
|
7607
|
-
(0,
|
|
7623
|
+
const myTx = (0, import_kit11.compileTransaction)(transactionMessage);
|
|
7624
|
+
const signature = await (0, import_kit11.signTransaction)([signerKeyPair], myTx);
|
|
7625
|
+
(0, import_kit11.assertIsSendableTransaction)(signature);
|
|
7608
7626
|
await this.client.sendAndConfirmTransaction(signature, {
|
|
7609
7627
|
commitment: this.config.commitment
|
|
7610
7628
|
});
|
|
@@ -7614,17 +7632,17 @@ var SolanaSDK = class extends BaseSDK {
|
|
|
7614
7632
|
const instructions = await cancelSingleChainOrderInstructions(orderId, { rpcUrl: this.config.rpcProviderUrl });
|
|
7615
7633
|
const signer = await this.getUserSigner();
|
|
7616
7634
|
const signerKeyPair = await this.getUserCryptoKeypair();
|
|
7617
|
-
const noopSigner = (0,
|
|
7635
|
+
const noopSigner = (0, import_kit11.createNoopSigner)(signer.address);
|
|
7618
7636
|
const { value: latestBlockhash } = await this.client.rpc.getLatestBlockhash({ commitment: this.config.commitment }).send();
|
|
7619
|
-
const transactionMessage = (0,
|
|
7620
|
-
(0,
|
|
7621
|
-
(tx) => (0,
|
|
7622
|
-
(tx) => (0,
|
|
7623
|
-
(tx) => (0,
|
|
7637
|
+
const transactionMessage = (0, import_kit11.pipe)(
|
|
7638
|
+
(0, import_kit11.createTransactionMessage)({ version: 0 }),
|
|
7639
|
+
(tx) => (0, import_kit11.setTransactionMessageFeePayerSigner)(noopSigner, tx),
|
|
7640
|
+
(tx) => (0, import_kit11.setTransactionMessageLifetimeUsingBlockhash)(latestBlockhash, tx),
|
|
7641
|
+
(tx) => (0, import_kit11.appendTransactionMessageInstructions)(instructions, tx)
|
|
7624
7642
|
);
|
|
7625
|
-
const myTx = (0,
|
|
7626
|
-
const signature = await (0,
|
|
7627
|
-
(0,
|
|
7643
|
+
const myTx = (0, import_kit11.compileTransaction)(transactionMessage);
|
|
7644
|
+
const signature = await (0, import_kit11.signTransaction)([signerKeyPair], myTx);
|
|
7645
|
+
(0, import_kit11.assertIsSendableTransaction)(signature);
|
|
7628
7646
|
await this.client.sendAndConfirmTransaction(signature, {
|
|
7629
7647
|
commitment: this.config.commitment
|
|
7630
7648
|
});
|
|
@@ -7639,9 +7657,9 @@ var SolanaSDK = class extends BaseSDK {
|
|
|
7639
7657
|
* @private
|
|
7640
7658
|
*/
|
|
7641
7659
|
async getUserCryptoKeypair() {
|
|
7642
|
-
const encoder = (0,
|
|
7660
|
+
const encoder = (0, import_kit11.getBase58Encoder)();
|
|
7643
7661
|
const bytesWithPrefix = encoder.encode(this.config.privateKey);
|
|
7644
|
-
return (0,
|
|
7662
|
+
return (0, import_kit11.createKeyPairFromBytes)(bytesWithPrefix);
|
|
7645
7663
|
}
|
|
7646
7664
|
/**
|
|
7647
7665
|
* Creates a KeyPairSigner from the user's crypto keypair
|
|
@@ -7653,7 +7671,7 @@ var SolanaSDK = class extends BaseSDK {
|
|
|
7653
7671
|
*/
|
|
7654
7672
|
async getUserSigner() {
|
|
7655
7673
|
const signer = await this.getUserCryptoKeypair();
|
|
7656
|
-
return (0,
|
|
7674
|
+
return (0, import_kit11.createSignerFromKeyPair)(signer);
|
|
7657
7675
|
}
|
|
7658
7676
|
async authenticate(token) {
|
|
7659
7677
|
const wallet = await this.getUserAddress();
|
|
@@ -7662,10 +7680,10 @@ var SolanaSDK = class extends BaseSDK {
|
|
|
7662
7680
|
wallet
|
|
7663
7681
|
});
|
|
7664
7682
|
const message = response.data;
|
|
7665
|
-
const signableMessage = (0,
|
|
7683
|
+
const signableMessage = (0, import_kit11.createSignableMessage)(message);
|
|
7666
7684
|
const signer = await this.getUserSigner();
|
|
7667
7685
|
const signatureArray = await signer.signMessages([signableMessage]);
|
|
7668
|
-
const signatureBytes = signatureArray.map((signature) => signature[(0,
|
|
7686
|
+
const signatureBytes = signatureArray.map((signature) => signature[(0, import_kit11.address)(wallet)])[0];
|
|
7669
7687
|
if (!signatureBytes) {
|
|
7670
7688
|
throw new Error("No signature bytes found");
|
|
7671
7689
|
}
|
|
@@ -7696,10 +7714,10 @@ var SolanaSDK = class extends BaseSDK {
|
|
|
7696
7714
|
async prepareCrossChainOrder(order) {
|
|
7697
7715
|
const signerKeyPair = await this.getUserCryptoKeypair();
|
|
7698
7716
|
const { orderAddress, txBytes } = await getSolanaCrossChainOrderInstructions(order);
|
|
7699
|
-
const transactionCodec = (0,
|
|
7717
|
+
const transactionCodec = (0, import_kit11.getTransactionCodec)();
|
|
7700
7718
|
const tx = transactionCodec.decode(txBytes);
|
|
7701
|
-
const signedTx = await (0,
|
|
7702
|
-
const encodedTransaction = (0,
|
|
7719
|
+
const signedTx = await (0, import_kit11.signTransaction)([signerKeyPair], tx);
|
|
7720
|
+
const encodedTransaction = (0, import_kit11.getBase64EncodedWireTransaction)(signedTx);
|
|
7703
7721
|
await this.client.rpc.sendTransaction(encodedTransaction, { preflightCommitment: this.config.commitment, encoding: "base64" }).send();
|
|
7704
7722
|
return {
|
|
7705
7723
|
order,
|
|
@@ -7711,10 +7729,10 @@ var SolanaSDK = class extends BaseSDK {
|
|
|
7711
7729
|
async prepareSingleChainOrder(order) {
|
|
7712
7730
|
const signerKeyPair = await this.getUserCryptoKeypair();
|
|
7713
7731
|
const { orderAddress, txBytes, secretNumber } = await getSolanaSingleChainOrderInstructions(order);
|
|
7714
|
-
const transactionCodec = (0,
|
|
7732
|
+
const transactionCodec = (0, import_kit11.getTransactionCodec)();
|
|
7715
7733
|
const tx = transactionCodec.decode(txBytes);
|
|
7716
|
-
const signedTx = await (0,
|
|
7717
|
-
const encodedTransaction = (0,
|
|
7734
|
+
const signedTx = await (0, import_kit11.partiallySignTransaction)([signerKeyPair], tx);
|
|
7735
|
+
const encodedTransaction = (0, import_kit11.getBase64EncodedWireTransaction)(signedTx);
|
|
7718
7736
|
await this.client.rpc.sendTransaction(encodedTransaction, { preflightCommitment: this.config.commitment, encoding: "base64" }).send();
|
|
7719
7737
|
return {
|
|
7720
7738
|
order,
|
|
@@ -7728,17 +7746,17 @@ var SolanaSDK = class extends BaseSDK {
|
|
|
7728
7746
|
const instructions = await cancelDcaSingleChainOrderInstructions(orderId, { rpcUrl: this.config.rpcProviderUrl });
|
|
7729
7747
|
const signer = await this.getUserSigner();
|
|
7730
7748
|
const signerKeyPair = await this.getUserCryptoKeypair();
|
|
7731
|
-
const noopSigner = (0,
|
|
7749
|
+
const noopSigner = (0, import_kit11.createNoopSigner)(signer.address);
|
|
7732
7750
|
const { value: latestBlockhash } = await this.client.rpc.getLatestBlockhash({ commitment: this.config.commitment }).send();
|
|
7733
|
-
const transactionMessage = (0,
|
|
7734
|
-
(0,
|
|
7735
|
-
(tx) => (0,
|
|
7736
|
-
(tx) => (0,
|
|
7737
|
-
(tx) => (0,
|
|
7751
|
+
const transactionMessage = (0, import_kit11.pipe)(
|
|
7752
|
+
(0, import_kit11.createTransactionMessage)({ version: 0 }),
|
|
7753
|
+
(tx) => (0, import_kit11.setTransactionMessageFeePayerSigner)(noopSigner, tx),
|
|
7754
|
+
(tx) => (0, import_kit11.setTransactionMessageLifetimeUsingBlockhash)(latestBlockhash, tx),
|
|
7755
|
+
(tx) => (0, import_kit11.appendTransactionMessageInstructions)(instructions, tx)
|
|
7738
7756
|
);
|
|
7739
|
-
const myTx = (0,
|
|
7740
|
-
const signature = await (0,
|
|
7741
|
-
(0,
|
|
7757
|
+
const myTx = (0, import_kit11.compileTransaction)(transactionMessage);
|
|
7758
|
+
const signature = await (0, import_kit11.signTransaction)([signerKeyPair], myTx);
|
|
7759
|
+
(0, import_kit11.assertIsSendableTransaction)(signature);
|
|
7742
7760
|
await this.client.sendAndConfirmTransaction(signature, {
|
|
7743
7761
|
commitment: this.config.commitment
|
|
7744
7762
|
});
|
|
@@ -7747,10 +7765,10 @@ var SolanaSDK = class extends BaseSDK {
|
|
|
7747
7765
|
async prepareDcaSingleChainOrder(order) {
|
|
7748
7766
|
const signerKeyPair = await this.getUserCryptoKeypair();
|
|
7749
7767
|
const { orderAddress, txBytes, secretNumber } = await getSolanaDcaSingleChainOrderInstructions(order);
|
|
7750
|
-
const transactionCodec = (0,
|
|
7768
|
+
const transactionCodec = (0, import_kit11.getTransactionCodec)();
|
|
7751
7769
|
const tx = transactionCodec.decode(txBytes);
|
|
7752
|
-
const signedTx = await (0,
|
|
7753
|
-
const encodedTransaction = (0,
|
|
7770
|
+
const signedTx = await (0, import_kit11.partiallySignTransaction)([signerKeyPair], tx);
|
|
7771
|
+
const encodedTransaction = (0, import_kit11.getBase64EncodedWireTransaction)(signedTx);
|
|
7754
7772
|
await this.client.rpc.sendTransaction(encodedTransaction, { preflightCommitment: this.config.commitment, encoding: "base64" }).send();
|
|
7755
7773
|
return {
|
|
7756
7774
|
order,
|
|
@@ -7902,31 +7920,6 @@ var SuiSDK = class extends BaseSDK {
|
|
|
7902
7920
|
}
|
|
7903
7921
|
};
|
|
7904
7922
|
|
|
7905
|
-
// src/core/orders/api/fetch.ts
|
|
7906
|
-
init_constants();
|
|
7907
|
-
async function fetchUserOrders(evmAddress, solAddress, suiAddress) {
|
|
7908
|
-
const params = new URLSearchParams();
|
|
7909
|
-
if (evmAddress) params.append("evmWallets", evmAddress);
|
|
7910
|
-
if (solAddress) params.append("solanaWallets", solAddress);
|
|
7911
|
-
if (suiAddress) params.append("suiWallets", suiAddress);
|
|
7912
|
-
if ([evmAddress, solAddress, suiAddress].every((a) => !a)) {
|
|
7913
|
-
throw new Error("At least one wallet address is required");
|
|
7914
|
-
}
|
|
7915
|
-
const url = `${AUCTIONEER_URL}/user_intent?${params.toString()}`;
|
|
7916
|
-
const response = await fetch(url, {
|
|
7917
|
-
method: "GET",
|
|
7918
|
-
headers: withAuctioneerHeaders({ "Content-Type": "application/json" })
|
|
7919
|
-
});
|
|
7920
|
-
if (!response.ok) {
|
|
7921
|
-
throw new Error(`Failed to fetch user orders: ${response.status} ${response.statusText}`);
|
|
7922
|
-
}
|
|
7923
|
-
const data = await response.json();
|
|
7924
|
-
if (!data.success) {
|
|
7925
|
-
throw new Error(`Failed to fetch user orders: ${data.error}`);
|
|
7926
|
-
}
|
|
7927
|
-
return data.data;
|
|
7928
|
-
}
|
|
7929
|
-
|
|
7930
7923
|
// src/core/orders/api/index.ts
|
|
7931
7924
|
init_constants();
|
|
7932
7925
|
var AuctioneerAPI = class {
|
|
@@ -7941,10 +7934,10 @@ var AuctioneerAPI = class {
|
|
|
7941
7934
|
const url = `${AUCTIONEER_URL}/user_intent`;
|
|
7942
7935
|
const response = await fetch(url, {
|
|
7943
7936
|
method: "GET",
|
|
7944
|
-
headers:
|
|
7937
|
+
headers: {
|
|
7945
7938
|
"Content-Type": "application/json",
|
|
7946
7939
|
Authorization: `Bearer ${this.aggregatedToken}`
|
|
7947
|
-
}
|
|
7940
|
+
}
|
|
7948
7941
|
});
|
|
7949
7942
|
const data = await response.json();
|
|
7950
7943
|
if (!data.success) {
|
|
@@ -7954,6 +7947,14 @@ var AuctioneerAPI = class {
|
|
|
7954
7947
|
}
|
|
7955
7948
|
};
|
|
7956
7949
|
|
|
7950
|
+
// src/core/orders/api/fetch.ts
|
|
7951
|
+
async function fetchUserOrders(aggregatedToken) {
|
|
7952
|
+
if (!aggregatedToken) {
|
|
7953
|
+
throw new Error("A SIWE-issued JWT is required to fetch user orders");
|
|
7954
|
+
}
|
|
7955
|
+
return new AuctioneerAPI(aggregatedToken).getUserOrders();
|
|
7956
|
+
}
|
|
7957
|
+
|
|
7957
7958
|
// src/index.ts
|
|
7958
7959
|
init_errors();
|
|
7959
7960
|
|
|
@@ -8172,7 +8173,7 @@ function getInvalidateNoncesRawData(nonce) {
|
|
|
8172
8173
|
}
|
|
8173
8174
|
|
|
8174
8175
|
// src/core/solana/inspect.ts
|
|
8175
|
-
var
|
|
8176
|
+
var import_kit12 = require("@solana/kit");
|
|
8176
8177
|
|
|
8177
8178
|
// src/utils/logger.ts
|
|
8178
8179
|
init_errors();
|
|
@@ -8267,8 +8268,8 @@ var logger = Logger.getInstance();
|
|
|
8267
8268
|
|
|
8268
8269
|
// src/core/solana/inspect.ts
|
|
8269
8270
|
async function getSolanaOrdersWithLockedFunds(userAddress, config) {
|
|
8270
|
-
const rpc = config?.rpcUrl ? (0,
|
|
8271
|
-
const programAccountAddress = (0,
|
|
8271
|
+
const rpc = config?.rpcUrl ? (0, import_kit12.createSolanaRpc)(config.rpcUrl) : getDefaultSolanaRPC();
|
|
8272
|
+
const programAccountAddress = (0, import_kit12.address)("DQZQGiVa1PBXesdbCRzmJpZ7AyntLXfAwP5Qty1hgFqQ");
|
|
8272
8273
|
const programAccountsConfig = {
|
|
8273
8274
|
encoding: "base64",
|
|
8274
8275
|
filters: [
|
|
@@ -8384,27 +8385,7 @@ init_single_chain_limit_order();
|
|
|
8384
8385
|
|
|
8385
8386
|
// src/utils/generate-execution-details-hash.ts
|
|
8386
8387
|
var import_crypto = require("crypto");
|
|
8387
|
-
function generateExecutionDetailsHash({
|
|
8388
|
-
destChainId,
|
|
8389
|
-
destinationAddress,
|
|
8390
|
-
tokenOut,
|
|
8391
|
-
amountOutMin,
|
|
8392
|
-
stopLossMaxOut,
|
|
8393
|
-
takeProfitMinOut,
|
|
8394
|
-
extraTransfers
|
|
8395
|
-
}) {
|
|
8396
|
-
const executionDetails = JSON.stringify(
|
|
8397
|
-
{
|
|
8398
|
-
destChainId,
|
|
8399
|
-
destinationAddress,
|
|
8400
|
-
tokenOut,
|
|
8401
|
-
amountOutMin,
|
|
8402
|
-
stopLossMaxOut,
|
|
8403
|
-
takeProfitMinOut,
|
|
8404
|
-
extraTransfers
|
|
8405
|
-
},
|
|
8406
|
-
Parsers.bigIntReplacer
|
|
8407
|
-
);
|
|
8388
|
+
function generateExecutionDetailsHash(executionDetails) {
|
|
8408
8389
|
return "0x" + (0, import_crypto.createHash)("sha256").update(executionDetails).digest("hex");
|
|
8409
8390
|
}
|
|
8410
8391
|
|
|
@@ -8422,7 +8403,9 @@ function createSuiSingleChainLimitOrderIntentRequest(params) {
|
|
|
8422
8403
|
destinationAddress: params.destinationAddress,
|
|
8423
8404
|
extraTransfers: params.extraTransfers,
|
|
8424
8405
|
deadline: params.deadline,
|
|
8425
|
-
takeProfitMinOut: params.takeProfitMinOut
|
|
8406
|
+
takeProfitMinOut: params.takeProfitMinOut,
|
|
8407
|
+
stopLossType: params.stopLossType,
|
|
8408
|
+
stopLossTriggerPrice: params.stopLossTriggerPrice
|
|
8426
8409
|
};
|
|
8427
8410
|
return {
|
|
8428
8411
|
genericData: order,
|
|
@@ -8472,7 +8455,7 @@ function createSuiCrossChainOrderIntentRequest(params) {
|
|
|
8472
8455
|
extraTransfers: params.extraTransfers
|
|
8473
8456
|
};
|
|
8474
8457
|
const executionDetailsString = JSON.stringify(executionDetails, Parsers.bigIntReplacer);
|
|
8475
|
-
const executionDetailsHash = generateExecutionDetailsHash(
|
|
8458
|
+
const executionDetailsHash = generateExecutionDetailsHash(executionDetailsString);
|
|
8476
8459
|
const genericData = {
|
|
8477
8460
|
user: params.user,
|
|
8478
8461
|
srcChainId: params.srcChainId,
|
|
@@ -8701,6 +8684,7 @@ async function getTokenList(params) {
|
|
|
8701
8684
|
}
|
|
8702
8685
|
|
|
8703
8686
|
// src/core/evm/intent-helpers.ts
|
|
8687
|
+
init_constants();
|
|
8704
8688
|
function createEvmSingleChainLimitOrderIntentRequest(params) {
|
|
8705
8689
|
const order = {
|
|
8706
8690
|
user: params.user,
|
|
@@ -8721,7 +8705,7 @@ function createEvmSingleChainLimitOrderIntentRequest(params) {
|
|
|
8721
8705
|
chainSpecificData: {
|
|
8722
8706
|
EVM: {
|
|
8723
8707
|
nonce: params.nonce || String(Math.floor(Math.random() * 1e7)),
|
|
8724
|
-
signature: params.signature ||
|
|
8708
|
+
signature: params.signature || EVM_ZERO_SIGNATURE
|
|
8725
8709
|
}
|
|
8726
8710
|
}
|
|
8727
8711
|
};
|
|
@@ -8746,7 +8730,7 @@ function createEvmSingleChainDcaOrderIntentRequest(params) {
|
|
|
8746
8730
|
chainSpecificData: {
|
|
8747
8731
|
EVM: {
|
|
8748
8732
|
nonce: params.nonce || String(Math.floor(Math.random() * 1e7)),
|
|
8749
|
-
signature: params.signature ||
|
|
8733
|
+
signature: params.signature || EVM_ZERO_SIGNATURE
|
|
8750
8734
|
}
|
|
8751
8735
|
}
|
|
8752
8736
|
};
|
|
@@ -8763,7 +8747,7 @@ function createEvmCrossChainOrderIntentRequest(params) {
|
|
|
8763
8747
|
stopLossTriggerPrice: params.stopLossTriggerPrice
|
|
8764
8748
|
};
|
|
8765
8749
|
const executionDetailsString = JSON.stringify(executionDetails, Parsers.bigIntReplacer);
|
|
8766
|
-
const executionDetailsHash = generateExecutionDetailsHash(
|
|
8750
|
+
const executionDetailsHash = generateExecutionDetailsHash(executionDetailsString);
|
|
8767
8751
|
const genericData = {
|
|
8768
8752
|
user: params.user,
|
|
8769
8753
|
srcChainId: params.sourceChainId,
|
|
@@ -8772,10 +8756,7 @@ function createEvmCrossChainOrderIntentRequest(params) {
|
|
|
8772
8756
|
minStablecoinsAmount: params.minStablecoinAmount || 1n,
|
|
8773
8757
|
deadline: params.deadline,
|
|
8774
8758
|
executionDetailsHash,
|
|
8775
|
-
extraTransfers: params.extraTransfers
|
|
8776
|
-
takeProfitMinOut: params.takeProfitMinOut,
|
|
8777
|
-
stopLossType: params.stopLossType,
|
|
8778
|
-
stopLossTriggerPrice: params.stopLossTriggerPrice
|
|
8759
|
+
extraTransfers: params.extraTransfers
|
|
8779
8760
|
};
|
|
8780
8761
|
return {
|
|
8781
8762
|
genericData,
|
|
@@ -8783,7 +8764,7 @@ function createEvmCrossChainOrderIntentRequest(params) {
|
|
|
8783
8764
|
chainSpecificData: {
|
|
8784
8765
|
EVM: {
|
|
8785
8766
|
nonce: params.nonce || String(Math.floor(Math.random() * 1e7)),
|
|
8786
|
-
signature: params.signature ||
|
|
8767
|
+
signature: params.signature || EVM_ZERO_SIGNATURE
|
|
8787
8768
|
}
|
|
8788
8769
|
}
|
|
8789
8770
|
};
|
|
@@ -8800,6 +8781,75 @@ async function generateEvmCrossChainOrderTypedData(order) {
|
|
|
8800
8781
|
function generateEvmRandomNonce() {
|
|
8801
8782
|
return String(Math.floor(Math.random() * 1e7));
|
|
8802
8783
|
}
|
|
8784
|
+
function buildCrossChainDcaExecutionDetails(params) {
|
|
8785
|
+
const executionDetails = {
|
|
8786
|
+
destChainId: params.destinationChainId,
|
|
8787
|
+
tokenOut: params.destinationTokenAddress,
|
|
8788
|
+
amountOutMin: params.destinationTokenMinAmount?.toString() || "1",
|
|
8789
|
+
destinationAddress: params.destinationAddress,
|
|
8790
|
+
extraTransfers: params.extraTransfers
|
|
8791
|
+
};
|
|
8792
|
+
const executionDetailsString = JSON.stringify(executionDetails, Parsers.bigIntReplacer);
|
|
8793
|
+
return { executionDetailsString, executionDetailsHash: generateExecutionDetailsHash(executionDetailsString) };
|
|
8794
|
+
}
|
|
8795
|
+
function createEvmCrossChainDcaOrderIntentRequest(params) {
|
|
8796
|
+
const { executionDetailsString, executionDetailsHash } = buildCrossChainDcaExecutionDetails(params);
|
|
8797
|
+
return {
|
|
8798
|
+
genericData: {
|
|
8799
|
+
user: params.user,
|
|
8800
|
+
srcChainId: params.sourceChainId,
|
|
8801
|
+
tokenIn: params.sourceTokenAddress,
|
|
8802
|
+
minStablecoinsAmount: params.minStablecoinAmount || 1n,
|
|
8803
|
+
deadline: params.deadline,
|
|
8804
|
+
executionDetailsHash,
|
|
8805
|
+
startTime: params.startTime,
|
|
8806
|
+
amountInPerInterval: params.amountInPerInterval,
|
|
8807
|
+
totalIntervals: params.totalIntervals,
|
|
8808
|
+
intervalDuration: params.intervalDuration
|
|
8809
|
+
},
|
|
8810
|
+
executionDetails: executionDetailsString,
|
|
8811
|
+
chainSpecificData: {
|
|
8812
|
+
EVM: {
|
|
8813
|
+
nonce: params.nonce || generateEvmRandomNonce(),
|
|
8814
|
+
signature: params.signature || EVM_ZERO_SIGNATURE
|
|
8815
|
+
}
|
|
8816
|
+
}
|
|
8817
|
+
};
|
|
8818
|
+
}
|
|
8819
|
+
function getEVMCrossChainDcaOrderTypedData(params, providedNonce) {
|
|
8820
|
+
const { executionDetailsHash } = buildCrossChainDcaExecutionDetails(params);
|
|
8821
|
+
const nonce = providedNonce ?? EVMIntentProvider.getRandomNonce();
|
|
8822
|
+
const totalAmountIn = params.amountInPerInterval * BigInt(params.totalIntervals);
|
|
8823
|
+
const spender = DCA_CROSS_CHAIN_GUARD_ADDRESSES[params.sourceChainId];
|
|
8824
|
+
const message = {
|
|
8825
|
+
permitted: { token: params.sourceTokenAddress, amount: totalAmountIn },
|
|
8826
|
+
spender,
|
|
8827
|
+
nonce,
|
|
8828
|
+
deadline: BigInt(params.deadline),
|
|
8829
|
+
witness: {
|
|
8830
|
+
user: params.user,
|
|
8831
|
+
tokenIn: params.sourceTokenAddress,
|
|
8832
|
+
srcChainId: params.sourceChainId,
|
|
8833
|
+
startTime: params.startTime,
|
|
8834
|
+
deadline: params.deadline,
|
|
8835
|
+
totalIntervals: params.totalIntervals,
|
|
8836
|
+
intervalDuration: params.intervalDuration,
|
|
8837
|
+
amountInPerInterval: params.amountInPerInterval,
|
|
8838
|
+
minStablecoinsAmountPerInterval: params.minStablecoinAmount || 1n,
|
|
8839
|
+
executionDetailsHash,
|
|
8840
|
+
nonce
|
|
8841
|
+
}
|
|
8842
|
+
};
|
|
8843
|
+
return {
|
|
8844
|
+
orderTypedData: {
|
|
8845
|
+
domain: PERMIT2_DOMAIN(params.sourceChainId),
|
|
8846
|
+
types: CROSS_CHAIN_DCA_PERMIT2_TYPES,
|
|
8847
|
+
primaryType: "PermitWitnessTransferFrom",
|
|
8848
|
+
message
|
|
8849
|
+
},
|
|
8850
|
+
nonce
|
|
8851
|
+
};
|
|
8852
|
+
}
|
|
8803
8853
|
|
|
8804
8854
|
// src/core/solana/intent-helpers.ts
|
|
8805
8855
|
function createSolanaSingleChainLimitOrderIntentRequest(params) {
|
|
@@ -8861,11 +8911,12 @@ function createSolanaCrossChainOrderIntentRequest(params) {
|
|
|
8861
8911
|
amountOutMin: params.destinationTokenMinAmount?.toString() || "1",
|
|
8862
8912
|
destinationAddress: params.destinationAddress,
|
|
8863
8913
|
extraTransfers: params.extraTransfers,
|
|
8864
|
-
|
|
8914
|
+
stopLossType: params.stopLossType,
|
|
8915
|
+
stopLossTriggerPrice: params.stopLossTriggerPrice,
|
|
8865
8916
|
takeProfitMinOut: params.takeProfitMinOut?.toString()
|
|
8866
8917
|
};
|
|
8867
8918
|
const executionDetailsString = JSON.stringify(executionDetails, Parsers.bigIntReplacer);
|
|
8868
|
-
const executionDetailsHash = generateExecutionDetailsHash(
|
|
8919
|
+
const executionDetailsHash = generateExecutionDetailsHash(executionDetailsString);
|
|
8869
8920
|
const genericData = {
|
|
8870
8921
|
user: params.user,
|
|
8871
8922
|
srcChainId: params.sourceChainId,
|
|
@@ -8886,14 +8937,14 @@ function createSolanaCrossChainOrderIntentRequest(params) {
|
|
|
8886
8937
|
}
|
|
8887
8938
|
};
|
|
8888
8939
|
}
|
|
8889
|
-
async function generateSolanaSingleChainLimitOrderInstructions(order
|
|
8890
|
-
return getSolanaSingleChainOrderInstructions(order
|
|
8940
|
+
async function generateSolanaSingleChainLimitOrderInstructions(order) {
|
|
8941
|
+
return getSolanaSingleChainOrderInstructions(order);
|
|
8891
8942
|
}
|
|
8892
|
-
async function generateSolanaSingleChainDcaOrderInstructions(order
|
|
8893
|
-
return getSolanaDcaSingleChainOrderInstructions(order
|
|
8943
|
+
async function generateSolanaSingleChainDcaOrderInstructions(order) {
|
|
8944
|
+
return getSolanaDcaSingleChainOrderInstructions(order);
|
|
8894
8945
|
}
|
|
8895
|
-
async function generateSolanaCrossChainOrderInstructions(order
|
|
8896
|
-
return getSolanaCrossChainOrderInstructions(order
|
|
8946
|
+
async function generateSolanaCrossChainOrderInstructions(order) {
|
|
8947
|
+
return getSolanaCrossChainOrderInstructions(order);
|
|
8897
8948
|
}
|
|
8898
8949
|
function generateSolanaLimitOrderSecretData(tokenOut, receiver, secretNumber, extraTransfers) {
|
|
8899
8950
|
const secret = secretNumber || generateSolanaRandomSecretNumber();
|