@shogun-sdk/intents-sdk 1.2.6-test.14 → 1.2.6-test.16
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 +277 -99
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +109 -22
- package/dist/index.d.ts +109 -22
- package/dist/index.js +277 -99
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
- package/src/auth/siwe.ts +10 -11
- package/src/constants.ts +32 -8
- 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 -39
- package/src/core/orders/cross-chain.ts +3 -0
- package/src/core/orders/single-chain.ts +21 -8
- package/src/core/sdk.ts +12 -6
- package/src/core/solana/intent-helpers.ts +6 -4
- package/src/core/sui/intent-helpers.ts +4 -1
- package/src/index.ts +4 -0
- 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/dist/index.js
CHANGED
|
@@ -129,7 +129,10 @@ function isNativeEvmToken(tokenAddress) {
|
|
|
129
129
|
const normalizedAddress = tokenAddress.toLowerCase();
|
|
130
130
|
return NATIVE_EVM_ETH_ADDRESSES.some((addr) => addr.toLowerCase() === normalizedAddress);
|
|
131
131
|
}
|
|
132
|
-
|
|
132
|
+
function normalizeNativeEvmTokenForSigning(tokenAddress) {
|
|
133
|
+
return isNativeEvmToken(tokenAddress) ? EVM_ZERO_ADDRESS : tokenAddress;
|
|
134
|
+
}
|
|
135
|
+
var 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;
|
|
133
136
|
var init_constants = __esm({
|
|
134
137
|
"src/constants.ts"() {
|
|
135
138
|
"use strict";
|
|
@@ -189,7 +192,9 @@ var init_constants = __esm({
|
|
|
189
192
|
[42161 /* Arbitrum */]: "0x0000000000000000000000000000000000000000",
|
|
190
193
|
[10 /* Optimism */]: "0x1b754840f058b78e412156d2674b5954728cb86e",
|
|
191
194
|
[8453 /* Base */]: "0x2df3ab1bb8b9d48769718003de2d8ca8e9d3c465",
|
|
192
|
-
|
|
195
|
+
// HyperEVM SingleChainGuardDca per the on-chain deployment + auctioneer config.
|
|
196
|
+
// (0x618ee9… is the SingleChainGuardLimit, which previously sat here by mistake.)
|
|
197
|
+
[999 /* Hyperliquid */]: "0xdcbb658910b5192a43b79fd8244bdf27940d3b6b",
|
|
193
198
|
[56 /* BSC */]: "0x11ef880e2e8d17c114b9eb87369ce3d1311c62e1",
|
|
194
199
|
[143 /* MONAD */]: "0x418302C3bef14D405A9B30381a9cb9d4d82EB2d4"
|
|
195
200
|
};
|
|
@@ -212,6 +217,7 @@ var init_constants = __esm({
|
|
|
212
217
|
CROSS_CHAIN_GUARD_ADDRESSES = useProdConfig ? PROD_CROSS_CHAIN_GUARD_ADDRESSES : TEST_CROSS_CHAIN_GUARD_ADDRESSES;
|
|
213
218
|
SINGLE_CHAIN_GUARD_ADDRESSES = useProdConfig ? PROD_SINGLE_CHAIN_GUARD_ADDRESSES : TEST_SINGLE_CHAIN_GUARD_ADDRESSES;
|
|
214
219
|
DCA_SINGLE_CHAIN_GUARD_ADDRESSES = useProdConfig ? PROD_DCA_SINGLE_CHAIN_GUARD_ADDRESSES : TEST_DCA_SINGLE_CHAIN_GUARD_ADDRESSES;
|
|
220
|
+
DCA_CROSS_CHAIN_GUARD_ADDRESSES = PROD_DCA_CROSS_CHAIN_GUARD_ADDRESSES;
|
|
215
221
|
NATIVE_SOLANA_TOKEN_ADDRESS = "So11111111111111111111111111111111111111111";
|
|
216
222
|
WRAPPED_SOL_MINT_ADDRESS = "So11111111111111111111111111111111111111112";
|
|
217
223
|
SOLANA_USDC_MINT = {
|
|
@@ -225,7 +231,8 @@ var init_constants = __esm({
|
|
|
225
231
|
SUI_PACKAGE_ID = useProdConfig ? PROD_SUI_PACKAGE_ID : TEST_SUI_PACKAGE_ID;
|
|
226
232
|
SUI_GUARD_COLLATERAL_TYPE = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
|
|
227
233
|
SUI_GUARD_STABLECOIN_TYPE = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
|
|
228
|
-
|
|
234
|
+
auctioneerUrlOverride = typeof process !== "undefined" ? process.env?.INTENTS_AUCTIONEER_URL : void 0;
|
|
235
|
+
AUCTIONEER_URL = auctioneerUrlOverride || (useProdConfig ? "https://auctioneer-825534211396.us-central1.run.app" : "http://127.0.0.1:8080");
|
|
229
236
|
MAX_UINT_32 = 2n ** 32n - 1n;
|
|
230
237
|
MAX_UINT_64 = 2n ** 64n - 1n;
|
|
231
238
|
MAX_UINT_128 = 2n ** 128n - 1n;
|
|
@@ -243,8 +250,9 @@ var init_constants = __esm({
|
|
|
243
250
|
[143 /* MONAD */]: "0x3bd359C1119dA7Da1D913D1C4D2B7c461115433A"
|
|
244
251
|
};
|
|
245
252
|
NATIVE_SUI_TOKEN_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";
|
|
253
|
+
EVM_ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
254
|
+
EVM_ZERO_SIGNATURE = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
246
255
|
TOKEN_SEARCH_API_BASE_URL = "https://shogun-token-search-api-825534211396.europe-west4.run.app";
|
|
247
|
-
DEV_ACCESS_KEY = typeof window !== "undefined" ? localStorage.getItem("x-dev-access") : null;
|
|
248
256
|
}
|
|
249
257
|
});
|
|
250
258
|
|
|
@@ -379,9 +387,6 @@ var BaseValidator = class {
|
|
|
379
387
|
this.validateTokenAddress(order.tokenOut);
|
|
380
388
|
this.validateAmount(order.amountIn);
|
|
381
389
|
this.validateAmount(order.amountOutMin ?? 1n);
|
|
382
|
-
if (order.stopLossMaxOut) {
|
|
383
|
-
this.validateAmount(order.stopLossMaxOut);
|
|
384
|
-
}
|
|
385
390
|
if (order.takeProfitMinOut) {
|
|
386
391
|
this.validateAmount(order.takeProfitMinOut);
|
|
387
392
|
}
|
|
@@ -3556,6 +3561,29 @@ var DCA_SINGLE_CHAIN_PERMIT2_TYPES = {
|
|
|
3556
3561
|
{ name: "witness", type: "SingleChainDcaOrder" }
|
|
3557
3562
|
]
|
|
3558
3563
|
};
|
|
3564
|
+
var CROSS_CHAIN_DCA_PERMIT2_TYPES = {
|
|
3565
|
+
TokenPermissions: TOKEN_PERMISSIONS_TYPE,
|
|
3566
|
+
DcaOrderInfo: [
|
|
3567
|
+
{ name: "user", type: "address" },
|
|
3568
|
+
{ name: "tokenIn", type: "address" },
|
|
3569
|
+
{ name: "srcChainId", type: "uint32" },
|
|
3570
|
+
{ name: "startTime", type: "uint32" },
|
|
3571
|
+
{ name: "deadline", type: "uint32" },
|
|
3572
|
+
{ name: "totalIntervals", type: "uint24" },
|
|
3573
|
+
{ name: "intervalDuration", type: "uint32" },
|
|
3574
|
+
{ name: "amountInPerInterval", type: "uint128" },
|
|
3575
|
+
{ name: "minStablecoinsAmountPerInterval", type: "uint128" },
|
|
3576
|
+
{ name: "executionDetailsHash", type: "bytes32" },
|
|
3577
|
+
{ name: "nonce", type: "uint256" }
|
|
3578
|
+
],
|
|
3579
|
+
PermitWitnessTransferFrom: [
|
|
3580
|
+
{ name: "permitted", type: "TokenPermissions" },
|
|
3581
|
+
{ name: "spender", type: "address" },
|
|
3582
|
+
{ name: "nonce", type: "uint256" },
|
|
3583
|
+
{ name: "deadline", type: "uint256" },
|
|
3584
|
+
{ name: "witness", type: "DcaOrderInfo" }
|
|
3585
|
+
]
|
|
3586
|
+
};
|
|
3559
3587
|
|
|
3560
3588
|
// src/core/evm/intent-provider.ts
|
|
3561
3589
|
var EVMIntentProvider = class {
|
|
@@ -3622,12 +3650,12 @@ var EVMIntentProvider = class {
|
|
|
3622
3650
|
static getSingleChainLimitPermissionMessage(order, nonce) {
|
|
3623
3651
|
const spender = SINGLE_CHAIN_GUARD_ADDRESSES[order.chainId];
|
|
3624
3652
|
const requestedOutput = {
|
|
3625
|
-
token: order.tokenOut,
|
|
3653
|
+
token: normalizeNativeEvmTokenForSigning(order.tokenOut),
|
|
3626
3654
|
receiver: order.destinationAddress,
|
|
3627
3655
|
amount: order.amountOutMin
|
|
3628
3656
|
};
|
|
3629
3657
|
const extraTransfers = order.extraTransfers?.map((transfer) => ({
|
|
3630
|
-
token: transfer.token,
|
|
3658
|
+
token: normalizeNativeEvmTokenForSigning(transfer.token),
|
|
3631
3659
|
receiver: transfer.receiver,
|
|
3632
3660
|
amount: transfer.amount
|
|
3633
3661
|
})) || [];
|
|
@@ -3675,12 +3703,12 @@ var EVMIntentProvider = class {
|
|
|
3675
3703
|
static getDcaSingleChainPermissionMessage(order, nonce) {
|
|
3676
3704
|
const spender = DCA_SINGLE_CHAIN_GUARD_ADDRESSES[order.chainId];
|
|
3677
3705
|
const requestedOutput = {
|
|
3678
|
-
token: order.tokenOut,
|
|
3706
|
+
token: normalizeNativeEvmTokenForSigning(order.tokenOut),
|
|
3679
3707
|
receiver: order.destinationAddress,
|
|
3680
3708
|
amount: BigInt(order.amountOutMin)
|
|
3681
3709
|
};
|
|
3682
3710
|
const extraTransfers = order.extraTransfers?.map((transfer) => ({
|
|
3683
|
-
token: transfer.token,
|
|
3711
|
+
token: normalizeNativeEvmTokenForSigning(transfer.token),
|
|
3684
3712
|
receiver: transfer.receiver,
|
|
3685
3713
|
amount: transfer.amount
|
|
3686
3714
|
})) || [];
|
|
@@ -6028,10 +6056,93 @@ var RelayQuoteProvider = class {
|
|
|
6028
6056
|
}
|
|
6029
6057
|
};
|
|
6030
6058
|
|
|
6031
|
-
// src/utils/quote/
|
|
6032
|
-
|
|
6059
|
+
// src/utils/quote/pricing/decimals.ts
|
|
6060
|
+
function convertDecimals(amount, fromDecimals, toDecimals) {
|
|
6061
|
+
const diff = toDecimals - fromDecimals;
|
|
6062
|
+
if (diff >= 0) {
|
|
6063
|
+
return amount * 10n ** BigInt(diff);
|
|
6064
|
+
}
|
|
6065
|
+
return amount / 10n ** BigInt(-diff);
|
|
6066
|
+
}
|
|
6067
|
+
|
|
6068
|
+
// src/utils/quote/pricing/estimate-amount-out.ts
|
|
6069
|
+
var IntentNotViableError = class extends Error {
|
|
6070
|
+
constructor(message) {
|
|
6071
|
+
super(message);
|
|
6072
|
+
this.name = "IntentNotViableError";
|
|
6073
|
+
}
|
|
6074
|
+
};
|
|
6075
|
+
function estimateAmountOut(swapOutput, commissionBps, expenses, commissionDenominator = 10000n) {
|
|
6076
|
+
const commissionFee = swapOutput * commissionBps / commissionDenominator;
|
|
6077
|
+
const total = expenses.gasInTokenOut + expenses.protocolFeeInTokenOut + expenses.extraTransfersInTokenOut + commissionFee;
|
|
6078
|
+
if (total >= swapOutput) {
|
|
6079
|
+
throw new IntentNotViableError(`Total expenses (${total}) meet or exceed swap output (${swapOutput})`);
|
|
6080
|
+
}
|
|
6081
|
+
return swapOutput - total;
|
|
6082
|
+
}
|
|
6083
|
+
|
|
6084
|
+
// src/utils/quote/pricing/expenses.ts
|
|
6085
|
+
init_constants();
|
|
6086
|
+
|
|
6087
|
+
// src/utils/quote/address.ts
|
|
6088
|
+
function compareAddresses2(firstAddress, secondAddress) {
|
|
6033
6089
|
return !!firstAddress && !!secondAddress && firstAddress.toLowerCase() === secondAddress.toLowerCase();
|
|
6090
|
+
}
|
|
6091
|
+
|
|
6092
|
+
// src/utils/quote/pricing/gas.ts
|
|
6093
|
+
init_chains();
|
|
6094
|
+
import { getGasPrice } from "viem/actions";
|
|
6095
|
+
|
|
6096
|
+
// src/utils/quote/pricing/constants.ts
|
|
6097
|
+
var DEFAULT_COMMISSION_BPS = 50n;
|
|
6098
|
+
var SINGLE_CHAIN_COMMISSION_DENOMINATOR = 10000n;
|
|
6099
|
+
var CROSS_CHAIN_COMMISSION_DENOMINATOR = 100000n;
|
|
6100
|
+
var EVM_SINGLE_CHAIN_GAS_LIMIT = 3000000n;
|
|
6101
|
+
var EVM_CROSS_CHAIN_GAS_LIMIT = 2000000n;
|
|
6102
|
+
var NON_EVM_FIXED_NATIVE_GAS_COST = {
|
|
6103
|
+
[101 /* Sui */]: 20000000n,
|
|
6104
|
+
[7565164 /* Solana */]: 200000n
|
|
6034
6105
|
};
|
|
6106
|
+
|
|
6107
|
+
// src/utils/quote/pricing/gas.ts
|
|
6108
|
+
async function getNativeGasCost(params) {
|
|
6109
|
+
const { chainId, gasLimit, rpcProviderUrl } = params;
|
|
6110
|
+
if (isEvmChain(chainId)) {
|
|
6111
|
+
const client = ChainProvider.getClient(chainId, rpcProviderUrl);
|
|
6112
|
+
const gasPrice = await getGasPrice(client);
|
|
6113
|
+
return gasLimit * gasPrice;
|
|
6114
|
+
}
|
|
6115
|
+
const fixed = NON_EVM_FIXED_NATIVE_GAS_COST[chainId];
|
|
6116
|
+
if (fixed === void 0) {
|
|
6117
|
+
throw new Error(`No fixed native gas cost configured for chain ${chainId}`);
|
|
6118
|
+
}
|
|
6119
|
+
return fixed;
|
|
6120
|
+
}
|
|
6121
|
+
|
|
6122
|
+
// src/utils/quote/pricing/expenses.ts
|
|
6123
|
+
function nativeTokenAddressForChain(chainId) {
|
|
6124
|
+
if (chainId === 7565164 /* Solana */) return NATIVE_SOLANA_TOKEN_ADDRESS;
|
|
6125
|
+
if (chainId === 101 /* Sui */) return NATIVE_SUI_TOKEN_ADDRESS;
|
|
6126
|
+
return NATIVE_EVM_ETH_ADDRESSES[0];
|
|
6127
|
+
}
|
|
6128
|
+
function isNativeToken(chainId, address9) {
|
|
6129
|
+
if (chainId === 7565164 /* Solana */) return compareAddresses2(address9, NATIVE_SOLANA_TOKEN_ADDRESS);
|
|
6130
|
+
if (chainId === 101 /* Sui */) return compareAddresses2(address9, NATIVE_SUI_TOKEN_ADDRESS);
|
|
6131
|
+
return isNativeEvmToken(address9);
|
|
6132
|
+
}
|
|
6133
|
+
async function estimateExpensesInTokenOut(params) {
|
|
6134
|
+
const { chainId, tokenOut, gasLimit, getQuote, rpcProviderUrl } = params;
|
|
6135
|
+
const nativeGasCost = await getNativeGasCost({ chainId, gasLimit, rpcProviderUrl });
|
|
6136
|
+
const gasInTokenOut = isNativeToken(chainId, tokenOut) ? nativeGasCost : (await getQuote({
|
|
6137
|
+
chainId,
|
|
6138
|
+
amount: nativeGasCost,
|
|
6139
|
+
tokenIn: nativeTokenAddressForChain(chainId),
|
|
6140
|
+
tokenOut
|
|
6141
|
+
})).amountOut;
|
|
6142
|
+
return { gasInTokenOut, protocolFeeInTokenOut: 0n, extraTransfersInTokenOut: 0n };
|
|
6143
|
+
}
|
|
6144
|
+
|
|
6145
|
+
// src/utils/quote/aggregator.ts
|
|
6035
6146
|
var QuoteProvider = class _QuoteProvider {
|
|
6036
6147
|
static async getQuote(params) {
|
|
6037
6148
|
try {
|
|
@@ -6048,6 +6159,7 @@ var QuoteProvider = class _QuoteProvider {
|
|
|
6048
6159
|
}
|
|
6049
6160
|
};
|
|
6050
6161
|
} catch (e) {
|
|
6162
|
+
if (e instanceof IntentNotViableError) throw e;
|
|
6051
6163
|
console.error("Error getting quote from routers:", e);
|
|
6052
6164
|
throw new Error("Failed to get quote from routers");
|
|
6053
6165
|
}
|
|
@@ -6077,9 +6189,19 @@ var QuoteProvider = class _QuoteProvider {
|
|
|
6077
6189
|
tokenIn: params.tokenIn,
|
|
6078
6190
|
tokenOut: sourceStable.address
|
|
6079
6191
|
};
|
|
6080
|
-
const sourceQuote = await
|
|
6081
|
-
|
|
6082
|
-
|
|
6192
|
+
const [sourceQuote, expenses] = await Promise.all([
|
|
6193
|
+
this.getSingleChainQuote(sourceSingleChainQuoteParams),
|
|
6194
|
+
estimateExpensesInTokenOut({
|
|
6195
|
+
chainId: params.destChainId,
|
|
6196
|
+
tokenOut: params.tokenOut,
|
|
6197
|
+
gasLimit: EVM_CROSS_CHAIN_GAS_LIMIT,
|
|
6198
|
+
getQuote: (p) => this.getSingleChainQuote(p)
|
|
6199
|
+
})
|
|
6200
|
+
]);
|
|
6201
|
+
const normalizedBridgeAmount = convertDecimals(
|
|
6202
|
+
sourceQuote.amountOut,
|
|
6203
|
+
sourceStable.decimals,
|
|
6204
|
+
destStable.decimals
|
|
6083
6205
|
);
|
|
6084
6206
|
const destSingleChainQuoteParams = {
|
|
6085
6207
|
chainId: params.destChainId,
|
|
@@ -6091,12 +6213,19 @@ var QuoteProvider = class _QuoteProvider {
|
|
|
6091
6213
|
const estimatedAmountInAsMinStablecoinAmount = BigInt(
|
|
6092
6214
|
Math.floor(sourceQuote.amountInUsd * 10 ** sourceStable.decimals)
|
|
6093
6215
|
);
|
|
6216
|
+
const swapOutput = destQuote.amountOutMin ?? destQuote.amountOut;
|
|
6217
|
+
const estimatedAmountOutReduced = estimateAmountOut(
|
|
6218
|
+
swapOutput,
|
|
6219
|
+
DEFAULT_COMMISSION_BPS,
|
|
6220
|
+
expenses,
|
|
6221
|
+
CROSS_CHAIN_COMMISSION_DENOMINATOR
|
|
6222
|
+
);
|
|
6094
6223
|
return {
|
|
6095
6224
|
estimatedAmountOut: destQuote.amountOut,
|
|
6096
6225
|
estimatedAmountOutUsd: destQuote.amountOutUsd,
|
|
6097
6226
|
amountInUsd: sourceQuote.amountInUsd,
|
|
6098
6227
|
estimatedAmountInAsMinStablecoinAmount,
|
|
6099
|
-
estimatedAmountOutReduced
|
|
6228
|
+
estimatedAmountOutReduced,
|
|
6100
6229
|
estimatedAmountOutUsdReduced: destQuote.amountOutUsd
|
|
6101
6230
|
};
|
|
6102
6231
|
}
|
|
@@ -6555,7 +6684,10 @@ var CrossChainOrder = class _CrossChainOrder {
|
|
|
6555
6684
|
tokenOut: this.destinationTokenAddress,
|
|
6556
6685
|
destinationAddress: this.destinationAddress,
|
|
6557
6686
|
amountOutMin: this.destinationTokenMinAmount,
|
|
6558
|
-
extraTransfers: this.extraTransfers
|
|
6687
|
+
extraTransfers: this.extraTransfers,
|
|
6688
|
+
stopLossType: this.stopLossType,
|
|
6689
|
+
stopLossTriggerPrice: this.stopLossTriggerPrice,
|
|
6690
|
+
takeProfitMinOut: this.takeProfitMinOut
|
|
6559
6691
|
};
|
|
6560
6692
|
}
|
|
6561
6693
|
executionDetailsHashToBytes() {
|
|
@@ -6736,13 +6868,22 @@ var SingleChainOrder = class _SingleChainOrder {
|
|
|
6736
6868
|
});
|
|
6737
6869
|
switch (scenario) {
|
|
6738
6870
|
case "QUOTE_REQUIRED": {
|
|
6739
|
-
const quote = await
|
|
6740
|
-
|
|
6741
|
-
|
|
6742
|
-
|
|
6743
|
-
|
|
6744
|
-
|
|
6745
|
-
|
|
6871
|
+
const [quote, expenses] = await Promise.all([
|
|
6872
|
+
QuoteProvider.getSingleChainQuote({
|
|
6873
|
+
tokenIn: input.tokenIn,
|
|
6874
|
+
amount: input.amountIn,
|
|
6875
|
+
chainId: input.chainId,
|
|
6876
|
+
tokenOut: input.tokenOut
|
|
6877
|
+
}),
|
|
6878
|
+
estimateExpensesInTokenOut({
|
|
6879
|
+
chainId: input.chainId,
|
|
6880
|
+
tokenOut: input.tokenOut,
|
|
6881
|
+
gasLimit: EVM_SINGLE_CHAIN_GAS_LIMIT,
|
|
6882
|
+
getQuote: (p) => QuoteProvider.getSingleChainQuote(p)
|
|
6883
|
+
})
|
|
6884
|
+
]);
|
|
6885
|
+
const swapOutput = quote.amountOutMin ?? quote.amountOut;
|
|
6886
|
+
return estimateAmountOut(swapOutput, DEFAULT_COMMISSION_BPS, expenses, SINGLE_CHAIN_COMMISSION_DENOMINATOR);
|
|
6746
6887
|
}
|
|
6747
6888
|
case "USE_PROVIDED_AMOUNT":
|
|
6748
6889
|
return amountOutMin;
|
|
@@ -6802,10 +6943,7 @@ var BaseSDK = class _BaseSDK {
|
|
|
6802
6943
|
static async makeRequest(url, body) {
|
|
6803
6944
|
const response = await fetch(url, {
|
|
6804
6945
|
method: "POST",
|
|
6805
|
-
headers: {
|
|
6806
|
-
"Content-Type": "application/json",
|
|
6807
|
-
...DEV_ACCESS_KEY ? { "x-dev-access": DEV_ACCESS_KEY } : {}
|
|
6808
|
-
},
|
|
6946
|
+
headers: { "Content-Type": "application/json" },
|
|
6809
6947
|
body
|
|
6810
6948
|
});
|
|
6811
6949
|
console.debug(`url`, url, `body`, body);
|
|
@@ -6874,6 +7012,13 @@ var BaseSDK = class _BaseSDK {
|
|
|
6874
7012
|
static async validateDcaSingleChainOrder(intentRequest) {
|
|
6875
7013
|
return _BaseSDK.validateOrder(intentRequest, "/validate_intent/single_chain/dca_order");
|
|
6876
7014
|
}
|
|
7015
|
+
static async validateDcaCrossChainOrder(intentRequest) {
|
|
7016
|
+
return _BaseSDK.validateOrder(intentRequest, "/validate_intent/cross_chain/dca_order");
|
|
7017
|
+
}
|
|
7018
|
+
static async sendDcaCrossChainOrder(intentRequest) {
|
|
7019
|
+
const body = JSON.stringify(intentRequest, Parsers.bigIntReplacer);
|
|
7020
|
+
return _BaseSDK.makeRequest(`${AUCTIONEER_URL}/user_intent/cross_chain/dca_order`, body);
|
|
7021
|
+
}
|
|
6877
7022
|
};
|
|
6878
7023
|
|
|
6879
7024
|
// src/core/solana/dca/create-order.ts
|
|
@@ -7100,11 +7245,7 @@ import "viem";
|
|
|
7100
7245
|
init_constants();
|
|
7101
7246
|
async function fetchSiweMessage(params) {
|
|
7102
7247
|
const url = `${AUCTIONEER_URL}/siwe?wallet=${params.wallet}&chainId=${params.chainId}`;
|
|
7103
|
-
const response = await fetch(url
|
|
7104
|
-
headers: {
|
|
7105
|
-
...DEV_ACCESS_KEY ? { "x-dev-access": DEV_ACCESS_KEY } : {}
|
|
7106
|
-
}
|
|
7107
|
-
});
|
|
7248
|
+
const response = await fetch(url);
|
|
7108
7249
|
if (!response.ok) {
|
|
7109
7250
|
throw new Error(`Failed to fetch SIWE message: ${response.status} ${response.statusText}`);
|
|
7110
7251
|
}
|
|
@@ -7113,12 +7254,14 @@ async function fetchSiweMessage(params) {
|
|
|
7113
7254
|
}
|
|
7114
7255
|
async function fetchJWTToken(params, token) {
|
|
7115
7256
|
const url = `${AUCTIONEER_URL}/siwe`;
|
|
7257
|
+
const headers = { "Content-Type": "application/json" };
|
|
7258
|
+
if (token) {
|
|
7259
|
+
headers.Authorization = `Bearer ${token}`;
|
|
7260
|
+
}
|
|
7116
7261
|
const response = await fetch(url, {
|
|
7117
7262
|
method: "POST",
|
|
7118
7263
|
body: JSON.stringify(params),
|
|
7119
|
-
headers
|
|
7120
|
-
Authorization: `Bearer ${token}`
|
|
7121
|
-
}
|
|
7264
|
+
headers
|
|
7122
7265
|
});
|
|
7123
7266
|
if (!response.ok) {
|
|
7124
7267
|
throw new Error(`Failed to fetch JWT token: ${response.status} ${response.statusText}`);
|
|
@@ -7918,34 +8061,6 @@ var SuiSDK = class extends BaseSDK {
|
|
|
7918
8061
|
}
|
|
7919
8062
|
};
|
|
7920
8063
|
|
|
7921
|
-
// src/core/orders/api/fetch.ts
|
|
7922
|
-
init_constants();
|
|
7923
|
-
async function fetchUserOrders(evmAddress, solAddress, suiAddress) {
|
|
7924
|
-
const params = new URLSearchParams();
|
|
7925
|
-
if (evmAddress) params.append("evmWallets", evmAddress);
|
|
7926
|
-
if (solAddress) params.append("solanaWallets", solAddress);
|
|
7927
|
-
if (suiAddress) params.append("suiWallets", suiAddress);
|
|
7928
|
-
if ([evmAddress, solAddress, suiAddress].every((a) => !a)) {
|
|
7929
|
-
throw new Error("At least one wallet address is required");
|
|
7930
|
-
}
|
|
7931
|
-
const url = `${AUCTIONEER_URL}/user_intent?${params.toString()}`;
|
|
7932
|
-
const response = await fetch(url, {
|
|
7933
|
-
method: "GET",
|
|
7934
|
-
headers: {
|
|
7935
|
-
"Content-Type": "application/json",
|
|
7936
|
-
...DEV_ACCESS_KEY ? { "x-dev-access": DEV_ACCESS_KEY } : {}
|
|
7937
|
-
}
|
|
7938
|
-
});
|
|
7939
|
-
if (!response.ok) {
|
|
7940
|
-
throw new Error(`Failed to fetch user orders: ${response.status} ${response.statusText}`);
|
|
7941
|
-
}
|
|
7942
|
-
const data = await response.json();
|
|
7943
|
-
if (!data.success) {
|
|
7944
|
-
throw new Error(`Failed to fetch user orders: ${data.error}`);
|
|
7945
|
-
}
|
|
7946
|
-
return data.data;
|
|
7947
|
-
}
|
|
7948
|
-
|
|
7949
8064
|
// src/core/orders/api/index.ts
|
|
7950
8065
|
init_constants();
|
|
7951
8066
|
var AuctioneerAPI = class {
|
|
@@ -7973,6 +8088,14 @@ var AuctioneerAPI = class {
|
|
|
7973
8088
|
}
|
|
7974
8089
|
};
|
|
7975
8090
|
|
|
8091
|
+
// src/core/orders/api/fetch.ts
|
|
8092
|
+
async function fetchUserOrders(aggregatedToken) {
|
|
8093
|
+
if (!aggregatedToken) {
|
|
8094
|
+
throw new Error("A SIWE-issued JWT is required to fetch user orders");
|
|
8095
|
+
}
|
|
8096
|
+
return new AuctioneerAPI(aggregatedToken).getUserOrders();
|
|
8097
|
+
}
|
|
8098
|
+
|
|
7976
8099
|
// src/index.ts
|
|
7977
8100
|
init_errors();
|
|
7978
8101
|
|
|
@@ -8403,27 +8526,7 @@ init_single_chain_limit_order();
|
|
|
8403
8526
|
|
|
8404
8527
|
// src/utils/generate-execution-details-hash.ts
|
|
8405
8528
|
import { createHash } from "crypto";
|
|
8406
|
-
function generateExecutionDetailsHash({
|
|
8407
|
-
destChainId,
|
|
8408
|
-
destinationAddress,
|
|
8409
|
-
tokenOut,
|
|
8410
|
-
amountOutMin,
|
|
8411
|
-
stopLossMaxOut,
|
|
8412
|
-
takeProfitMinOut,
|
|
8413
|
-
extraTransfers
|
|
8414
|
-
}) {
|
|
8415
|
-
const executionDetails = JSON.stringify(
|
|
8416
|
-
{
|
|
8417
|
-
destChainId,
|
|
8418
|
-
destinationAddress,
|
|
8419
|
-
tokenOut,
|
|
8420
|
-
amountOutMin,
|
|
8421
|
-
stopLossMaxOut,
|
|
8422
|
-
takeProfitMinOut,
|
|
8423
|
-
extraTransfers
|
|
8424
|
-
},
|
|
8425
|
-
Parsers.bigIntReplacer
|
|
8426
|
-
);
|
|
8529
|
+
function generateExecutionDetailsHash(executionDetails) {
|
|
8427
8530
|
return "0x" + createHash("sha256").update(executionDetails).digest("hex");
|
|
8428
8531
|
}
|
|
8429
8532
|
|
|
@@ -8441,7 +8544,9 @@ function createSuiSingleChainLimitOrderIntentRequest(params) {
|
|
|
8441
8544
|
destinationAddress: params.destinationAddress,
|
|
8442
8545
|
extraTransfers: params.extraTransfers,
|
|
8443
8546
|
deadline: params.deadline,
|
|
8444
|
-
takeProfitMinOut: params.takeProfitMinOut
|
|
8547
|
+
takeProfitMinOut: params.takeProfitMinOut,
|
|
8548
|
+
stopLossType: params.stopLossType,
|
|
8549
|
+
stopLossTriggerPrice: params.stopLossTriggerPrice
|
|
8445
8550
|
};
|
|
8446
8551
|
return {
|
|
8447
8552
|
genericData: order,
|
|
@@ -8491,7 +8596,7 @@ function createSuiCrossChainOrderIntentRequest(params) {
|
|
|
8491
8596
|
extraTransfers: params.extraTransfers
|
|
8492
8597
|
};
|
|
8493
8598
|
const executionDetailsString = JSON.stringify(executionDetails, Parsers.bigIntReplacer);
|
|
8494
|
-
const executionDetailsHash = generateExecutionDetailsHash(
|
|
8599
|
+
const executionDetailsHash = generateExecutionDetailsHash(executionDetailsString);
|
|
8495
8600
|
const genericData = {
|
|
8496
8601
|
user: params.user,
|
|
8497
8602
|
srcChainId: params.srcChainId,
|
|
@@ -8720,6 +8825,7 @@ async function getTokenList(params) {
|
|
|
8720
8825
|
}
|
|
8721
8826
|
|
|
8722
8827
|
// src/core/evm/intent-helpers.ts
|
|
8828
|
+
init_constants();
|
|
8723
8829
|
function createEvmSingleChainLimitOrderIntentRequest(params) {
|
|
8724
8830
|
const order = {
|
|
8725
8831
|
user: params.user,
|
|
@@ -8740,7 +8846,7 @@ function createEvmSingleChainLimitOrderIntentRequest(params) {
|
|
|
8740
8846
|
chainSpecificData: {
|
|
8741
8847
|
EVM: {
|
|
8742
8848
|
nonce: params.nonce || String(Math.floor(Math.random() * 1e7)),
|
|
8743
|
-
signature: params.signature ||
|
|
8849
|
+
signature: params.signature || EVM_ZERO_SIGNATURE
|
|
8744
8850
|
}
|
|
8745
8851
|
}
|
|
8746
8852
|
};
|
|
@@ -8765,7 +8871,7 @@ function createEvmSingleChainDcaOrderIntentRequest(params) {
|
|
|
8765
8871
|
chainSpecificData: {
|
|
8766
8872
|
EVM: {
|
|
8767
8873
|
nonce: params.nonce || String(Math.floor(Math.random() * 1e7)),
|
|
8768
|
-
signature: params.signature ||
|
|
8874
|
+
signature: params.signature || EVM_ZERO_SIGNATURE
|
|
8769
8875
|
}
|
|
8770
8876
|
}
|
|
8771
8877
|
};
|
|
@@ -8782,7 +8888,7 @@ function createEvmCrossChainOrderIntentRequest(params) {
|
|
|
8782
8888
|
stopLossTriggerPrice: params.stopLossTriggerPrice
|
|
8783
8889
|
};
|
|
8784
8890
|
const executionDetailsString = JSON.stringify(executionDetails, Parsers.bigIntReplacer);
|
|
8785
|
-
const executionDetailsHash = generateExecutionDetailsHash(
|
|
8891
|
+
const executionDetailsHash = generateExecutionDetailsHash(executionDetailsString);
|
|
8786
8892
|
const genericData = {
|
|
8787
8893
|
user: params.user,
|
|
8788
8894
|
srcChainId: params.sourceChainId,
|
|
@@ -8791,10 +8897,7 @@ function createEvmCrossChainOrderIntentRequest(params) {
|
|
|
8791
8897
|
minStablecoinsAmount: params.minStablecoinAmount || 1n,
|
|
8792
8898
|
deadline: params.deadline,
|
|
8793
8899
|
executionDetailsHash,
|
|
8794
|
-
extraTransfers: params.extraTransfers
|
|
8795
|
-
takeProfitMinOut: params.takeProfitMinOut,
|
|
8796
|
-
stopLossType: params.stopLossType,
|
|
8797
|
-
stopLossTriggerPrice: params.stopLossTriggerPrice
|
|
8900
|
+
extraTransfers: params.extraTransfers
|
|
8798
8901
|
};
|
|
8799
8902
|
return {
|
|
8800
8903
|
genericData,
|
|
@@ -8802,7 +8905,7 @@ function createEvmCrossChainOrderIntentRequest(params) {
|
|
|
8802
8905
|
chainSpecificData: {
|
|
8803
8906
|
EVM: {
|
|
8804
8907
|
nonce: params.nonce || String(Math.floor(Math.random() * 1e7)),
|
|
8805
|
-
signature: params.signature ||
|
|
8908
|
+
signature: params.signature || EVM_ZERO_SIGNATURE
|
|
8806
8909
|
}
|
|
8807
8910
|
}
|
|
8808
8911
|
};
|
|
@@ -8819,6 +8922,75 @@ async function generateEvmCrossChainOrderTypedData(order) {
|
|
|
8819
8922
|
function generateEvmRandomNonce() {
|
|
8820
8923
|
return String(Math.floor(Math.random() * 1e7));
|
|
8821
8924
|
}
|
|
8925
|
+
function buildCrossChainDcaExecutionDetails(params) {
|
|
8926
|
+
const executionDetails = {
|
|
8927
|
+
destChainId: params.destinationChainId,
|
|
8928
|
+
tokenOut: params.destinationTokenAddress,
|
|
8929
|
+
amountOutMin: params.destinationTokenMinAmount?.toString() || "1",
|
|
8930
|
+
destinationAddress: params.destinationAddress,
|
|
8931
|
+
extraTransfers: params.extraTransfers
|
|
8932
|
+
};
|
|
8933
|
+
const executionDetailsString = JSON.stringify(executionDetails, Parsers.bigIntReplacer);
|
|
8934
|
+
return { executionDetailsString, executionDetailsHash: generateExecutionDetailsHash(executionDetailsString) };
|
|
8935
|
+
}
|
|
8936
|
+
function createEvmCrossChainDcaOrderIntentRequest(params) {
|
|
8937
|
+
const { executionDetailsString, executionDetailsHash } = buildCrossChainDcaExecutionDetails(params);
|
|
8938
|
+
return {
|
|
8939
|
+
genericData: {
|
|
8940
|
+
user: params.user,
|
|
8941
|
+
srcChainId: params.sourceChainId,
|
|
8942
|
+
tokenIn: params.sourceTokenAddress,
|
|
8943
|
+
minStablecoinsAmount: params.minStablecoinAmount || 1n,
|
|
8944
|
+
deadline: params.deadline,
|
|
8945
|
+
executionDetailsHash,
|
|
8946
|
+
startTime: params.startTime,
|
|
8947
|
+
amountInPerInterval: params.amountInPerInterval,
|
|
8948
|
+
totalIntervals: params.totalIntervals,
|
|
8949
|
+
intervalDuration: params.intervalDuration
|
|
8950
|
+
},
|
|
8951
|
+
executionDetails: executionDetailsString,
|
|
8952
|
+
chainSpecificData: {
|
|
8953
|
+
EVM: {
|
|
8954
|
+
nonce: params.nonce || generateEvmRandomNonce(),
|
|
8955
|
+
signature: params.signature || EVM_ZERO_SIGNATURE
|
|
8956
|
+
}
|
|
8957
|
+
}
|
|
8958
|
+
};
|
|
8959
|
+
}
|
|
8960
|
+
function getEVMCrossChainDcaOrderTypedData(params, providedNonce) {
|
|
8961
|
+
const { executionDetailsHash } = buildCrossChainDcaExecutionDetails(params);
|
|
8962
|
+
const nonce = providedNonce ?? EVMIntentProvider.getRandomNonce();
|
|
8963
|
+
const totalAmountIn = params.amountInPerInterval * BigInt(params.totalIntervals);
|
|
8964
|
+
const spender = DCA_CROSS_CHAIN_GUARD_ADDRESSES[params.sourceChainId];
|
|
8965
|
+
const message = {
|
|
8966
|
+
permitted: { token: params.sourceTokenAddress, amount: totalAmountIn },
|
|
8967
|
+
spender,
|
|
8968
|
+
nonce,
|
|
8969
|
+
deadline: BigInt(params.deadline),
|
|
8970
|
+
witness: {
|
|
8971
|
+
user: params.user,
|
|
8972
|
+
tokenIn: params.sourceTokenAddress,
|
|
8973
|
+
srcChainId: params.sourceChainId,
|
|
8974
|
+
startTime: params.startTime,
|
|
8975
|
+
deadline: params.deadline,
|
|
8976
|
+
totalIntervals: params.totalIntervals,
|
|
8977
|
+
intervalDuration: params.intervalDuration,
|
|
8978
|
+
amountInPerInterval: params.amountInPerInterval,
|
|
8979
|
+
minStablecoinsAmountPerInterval: params.minStablecoinAmount || 1n,
|
|
8980
|
+
executionDetailsHash,
|
|
8981
|
+
nonce
|
|
8982
|
+
}
|
|
8983
|
+
};
|
|
8984
|
+
return {
|
|
8985
|
+
orderTypedData: {
|
|
8986
|
+
domain: PERMIT2_DOMAIN(params.sourceChainId),
|
|
8987
|
+
types: CROSS_CHAIN_DCA_PERMIT2_TYPES,
|
|
8988
|
+
primaryType: "PermitWitnessTransferFrom",
|
|
8989
|
+
message
|
|
8990
|
+
},
|
|
8991
|
+
nonce
|
|
8992
|
+
};
|
|
8993
|
+
}
|
|
8822
8994
|
|
|
8823
8995
|
// src/core/solana/intent-helpers.ts
|
|
8824
8996
|
function createSolanaSingleChainLimitOrderIntentRequest(params) {
|
|
@@ -8880,11 +9052,12 @@ function createSolanaCrossChainOrderIntentRequest(params) {
|
|
|
8880
9052
|
amountOutMin: params.destinationTokenMinAmount?.toString() || "1",
|
|
8881
9053
|
destinationAddress: params.destinationAddress,
|
|
8882
9054
|
extraTransfers: params.extraTransfers,
|
|
8883
|
-
|
|
9055
|
+
stopLossType: params.stopLossType,
|
|
9056
|
+
stopLossTriggerPrice: params.stopLossTriggerPrice,
|
|
8884
9057
|
takeProfitMinOut: params.takeProfitMinOut?.toString()
|
|
8885
9058
|
};
|
|
8886
9059
|
const executionDetailsString = JSON.stringify(executionDetails, Parsers.bigIntReplacer);
|
|
8887
|
-
const executionDetailsHash = generateExecutionDetailsHash(
|
|
9060
|
+
const executionDetailsHash = generateExecutionDetailsHash(executionDetailsString);
|
|
8888
9061
|
const genericData = {
|
|
8889
9062
|
user: params.user,
|
|
8890
9063
|
srcChainId: params.sourceChainId,
|
|
@@ -8958,10 +9131,12 @@ export {
|
|
|
8958
9131
|
ChainID,
|
|
8959
9132
|
ChainType,
|
|
8960
9133
|
CrossChainOrder,
|
|
9134
|
+
DCA_CROSS_CHAIN_GUARD_ADDRESSES,
|
|
8961
9135
|
DCA_SINGLE_CHAIN_GUARD_ADDRESSES,
|
|
8962
|
-
DEV_ACCESS_KEY,
|
|
8963
9136
|
DcaSingleChainOrder,
|
|
8964
9137
|
EVMSDK,
|
|
9138
|
+
EVM_ZERO_ADDRESS,
|
|
9139
|
+
EVM_ZERO_SIGNATURE,
|
|
8965
9140
|
IntentsOrderType,
|
|
8966
9141
|
MAX_UINT_128,
|
|
8967
9142
|
MAX_UINT_256,
|
|
@@ -9000,6 +9175,7 @@ export {
|
|
|
9000
9175
|
cancelDcaSingleChainOrderInstructions,
|
|
9001
9176
|
cancelSingleChainOrderInstructionsAsBytes,
|
|
9002
9177
|
chainIdToChainTypeMap,
|
|
9178
|
+
createEvmCrossChainDcaOrderIntentRequest,
|
|
9003
9179
|
createEvmCrossChainOrderIntentRequest,
|
|
9004
9180
|
createEvmSingleChainDcaOrderIntentRequest,
|
|
9005
9181
|
createEvmSingleChainLimitOrderIntentRequest,
|
|
@@ -9029,6 +9205,7 @@ export {
|
|
|
9029
9205
|
getCancelSingleChainOrderRawData,
|
|
9030
9206
|
getCoinFromResponse,
|
|
9031
9207
|
getDcaSecretHash,
|
|
9208
|
+
getEVMCrossChainDcaOrderTypedData,
|
|
9032
9209
|
getEVMCrossChainOrderTypedData,
|
|
9033
9210
|
getEVMSingleChainOrderTypedData,
|
|
9034
9211
|
getInvalidateNoncesRawData,
|
|
@@ -9049,6 +9226,7 @@ export {
|
|
|
9049
9226
|
isNativeEvmToken,
|
|
9050
9227
|
isSuccessApiResponse,
|
|
9051
9228
|
isSupportedChain,
|
|
9229
|
+
normalizeNativeEvmTokenForSigning,
|
|
9052
9230
|
prepareDcaSecretData,
|
|
9053
9231
|
prepareSecretData,
|
|
9054
9232
|
signSingleChainDcaOrder,
|