@cetusprotocol/aggregator-sdk 0.3.31 → 0.4.0
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.d.mts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +219 -24
- package/dist/index.mjs +218 -24
- package/dist/src/api.d.ts +4 -0
- package/dist/src/client.d.ts +3 -0
- package/dist/src/errors.d.ts +2 -1
- package/dist/src/transaction/obric.d.ts +8 -0
- package/dist/tests/router/obric.test.d.ts +2 -0
- package/dist/tests/router/scallop.test.d.ts +2 -0
- package/package.json +1 -1
- package/src/api.ts +12 -5
- package/src/client.ts +156 -2
- package/src/errors.ts +4 -1
- package/src/transaction/obric.ts +90 -0
- package/src/utils/msafe.ts +27 -17
- package/tests/router/obric.test.ts +197 -0
- package/tests/router/scallop.test.ts +127 -0
package/dist/index.d.mts
CHANGED
|
@@ -81,6 +81,7 @@ declare const ALPHAFI = "ALPHAFI";
|
|
|
81
81
|
declare const SPRINGSUI = "SPRINGSUI";
|
|
82
82
|
declare const STEAMM = "STEAMM";
|
|
83
83
|
declare const METASTABLE = "METASTABLE";
|
|
84
|
+
declare const OBRIC = "OBRIC";
|
|
84
85
|
declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
85
86
|
type BuildRouterSwapParams = {
|
|
86
87
|
routers: Router[];
|
|
@@ -139,10 +140,12 @@ declare class AggregatorClient {
|
|
|
139
140
|
constructor(endpoint?: string, signer?: string, client?: SuiClient, env?: Env);
|
|
140
141
|
getCoins(coinType: string, refresh?: boolean): Promise<CoinAsset[]>;
|
|
141
142
|
findRouters(params: FindRouterParams): Promise<RouterData | null>;
|
|
143
|
+
executeFlexibleInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, pythPriceIDs: Map<string, string>, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
|
|
142
144
|
expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, pythPriceIDs: Map<string, string>, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
|
|
143
145
|
expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
|
|
144
146
|
swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResult | null>;
|
|
145
147
|
routerSwap(params: BuildRouterSwapParams | BuildRouterSwapParamsV2): Promise<TransactionObjectArgument>;
|
|
148
|
+
fixableRouterSwap(params: BuildRouterSwapParamsV2): Promise<TransactionObjectArgument>;
|
|
146
149
|
fastRouterSwap(params: BuildFastRouterSwapParams | BuildFastRouterSwapParamsV2): Promise<void>;
|
|
147
150
|
publishedAtV2(): string;
|
|
148
151
|
publishedAtV2Extend(): string;
|
|
@@ -251,6 +254,10 @@ type ExtendedDetails = {
|
|
|
251
254
|
metastableCreateCapModule?: string;
|
|
252
255
|
metastableCreateCapAllTypeParams?: boolean;
|
|
253
256
|
metastableRegistryId?: string;
|
|
257
|
+
obricCoinAPriceSeed?: string;
|
|
258
|
+
obricCoinBPriceSeed?: string;
|
|
259
|
+
obricCoinAPriceId?: string;
|
|
260
|
+
obricCoinBPriceId?: string;
|
|
254
261
|
};
|
|
255
262
|
type Path = {
|
|
256
263
|
id: string;
|
|
@@ -314,4 +321,4 @@ declare enum Env {
|
|
|
314
321
|
Testnet = 1
|
|
315
322
|
}
|
|
316
323
|
|
|
317
|
-
export { AFSUI, AFTERMATH, AGGREGATOR_V2, AGGREGATOR_V2_EXTEND, ALPHAFI, AggregatorClient, type AggregatorResponse, BLUEFIN, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildFastRouterSwapParamsV2, type BuildRouterSwapParams, type BuildRouterSwapParamsV2, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, type DeepbookV3Config, type DeepbookV3ConfigResponse, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, HAEDALPMM, KRIYA, KRIYAV3, METASTABLE, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, SCALLOP, SPRINGSUI, STEAMM, SUILEND, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, findPythPriceIDs, fixSuiObjectId, getAggregatorV2ExtendPublishedAt, getAggregatorV2PublishedAt, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
|
|
324
|
+
export { AFSUI, AFTERMATH, AGGREGATOR_V2, AGGREGATOR_V2_EXTEND, ALPHAFI, AggregatorClient, type AggregatorResponse, BLUEFIN, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildFastRouterSwapParamsV2, type BuildRouterSwapParams, type BuildRouterSwapParamsV2, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, type DeepbookV3Config, type DeepbookV3ConfigResponse, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, HAEDALPMM, KRIYA, KRIYAV3, METASTABLE, OBRIC, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, SCALLOP, SPRINGSUI, STEAMM, SUILEND, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, findPythPriceIDs, fixSuiObjectId, getAggregatorV2ExtendPublishedAt, getAggregatorV2PublishedAt, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
|
package/dist/index.d.ts
CHANGED
|
@@ -81,6 +81,7 @@ declare const ALPHAFI = "ALPHAFI";
|
|
|
81
81
|
declare const SPRINGSUI = "SPRINGSUI";
|
|
82
82
|
declare const STEAMM = "STEAMM";
|
|
83
83
|
declare const METASTABLE = "METASTABLE";
|
|
84
|
+
declare const OBRIC = "OBRIC";
|
|
84
85
|
declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
85
86
|
type BuildRouterSwapParams = {
|
|
86
87
|
routers: Router[];
|
|
@@ -139,10 +140,12 @@ declare class AggregatorClient {
|
|
|
139
140
|
constructor(endpoint?: string, signer?: string, client?: SuiClient, env?: Env);
|
|
140
141
|
getCoins(coinType: string, refresh?: boolean): Promise<CoinAsset[]>;
|
|
141
142
|
findRouters(params: FindRouterParams): Promise<RouterData | null>;
|
|
143
|
+
executeFlexibleInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, pythPriceIDs: Map<string, string>, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
|
|
142
144
|
expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, pythPriceIDs: Map<string, string>, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
|
|
143
145
|
expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
|
|
144
146
|
swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResult | null>;
|
|
145
147
|
routerSwap(params: BuildRouterSwapParams | BuildRouterSwapParamsV2): Promise<TransactionObjectArgument>;
|
|
148
|
+
fixableRouterSwap(params: BuildRouterSwapParamsV2): Promise<TransactionObjectArgument>;
|
|
146
149
|
fastRouterSwap(params: BuildFastRouterSwapParams | BuildFastRouterSwapParamsV2): Promise<void>;
|
|
147
150
|
publishedAtV2(): string;
|
|
148
151
|
publishedAtV2Extend(): string;
|
|
@@ -251,6 +254,10 @@ type ExtendedDetails = {
|
|
|
251
254
|
metastableCreateCapModule?: string;
|
|
252
255
|
metastableCreateCapAllTypeParams?: boolean;
|
|
253
256
|
metastableRegistryId?: string;
|
|
257
|
+
obricCoinAPriceSeed?: string;
|
|
258
|
+
obricCoinBPriceSeed?: string;
|
|
259
|
+
obricCoinAPriceId?: string;
|
|
260
|
+
obricCoinBPriceId?: string;
|
|
254
261
|
};
|
|
255
262
|
type Path = {
|
|
256
263
|
id: string;
|
|
@@ -314,4 +321,4 @@ declare enum Env {
|
|
|
314
321
|
Testnet = 1
|
|
315
322
|
}
|
|
316
323
|
|
|
317
|
-
export { AFSUI, AFTERMATH, AGGREGATOR_V2, AGGREGATOR_V2_EXTEND, ALPHAFI, AggregatorClient, type AggregatorResponse, BLUEFIN, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildFastRouterSwapParamsV2, type BuildRouterSwapParams, type BuildRouterSwapParamsV2, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, type DeepbookV3Config, type DeepbookV3ConfigResponse, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, HAEDALPMM, KRIYA, KRIYAV3, METASTABLE, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, SCALLOP, SPRINGSUI, STEAMM, SUILEND, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, findPythPriceIDs, fixSuiObjectId, getAggregatorV2ExtendPublishedAt, getAggregatorV2PublishedAt, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
|
|
324
|
+
export { AFSUI, AFTERMATH, AGGREGATOR_V2, AGGREGATOR_V2_EXTEND, ALPHAFI, AggregatorClient, type AggregatorResponse, BLUEFIN, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildFastRouterSwapParamsV2, type BuildRouterSwapParams, type BuildRouterSwapParamsV2, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, type DeepbookV3Config, type DeepbookV3ConfigResponse, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, HAEDALPMM, KRIYA, KRIYAV3, METASTABLE, OBRIC, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, SCALLOP, SPRINGSUI, STEAMM, SUILEND, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, findPythPriceIDs, fixSuiObjectId, getAggregatorV2ExtendPublishedAt, getAggregatorV2PublishedAt, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
|
package/dist/index.js
CHANGED
|
@@ -5633,6 +5633,8 @@ function getAggregatorServerErrorMessage(code) {
|
|
|
5633
5633
|
return "Insufficient Liquidity";
|
|
5634
5634
|
case 10004 /* HoneyPot */:
|
|
5635
5635
|
return "Target token is detected as a HoneyPot scam";
|
|
5636
|
+
case 10005 /* RateLimitExceeded */:
|
|
5637
|
+
return "Too many requests. Please try again later";
|
|
5636
5638
|
default:
|
|
5637
5639
|
return "Unknown error";
|
|
5638
5640
|
}
|
|
@@ -6420,6 +6422,67 @@ var Metastable = class {
|
|
|
6420
6422
|
}
|
|
6421
6423
|
};
|
|
6422
6424
|
|
|
6425
|
+
// src/transaction/obric.ts
|
|
6426
|
+
var Obric = class {
|
|
6427
|
+
constructor(env, pythPriceIDs) {
|
|
6428
|
+
if (env === 1 /* Testnet */) {
|
|
6429
|
+
throw new Error("Obric is not supported on testnet");
|
|
6430
|
+
}
|
|
6431
|
+
this.pythPriceIDs = pythPriceIDs;
|
|
6432
|
+
this.pythStateObjectId = "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8";
|
|
6433
|
+
}
|
|
6434
|
+
swap(client, txb, path, inputCoin, packages) {
|
|
6435
|
+
return __async(this, null, function* () {
|
|
6436
|
+
const { direction, from, target } = path;
|
|
6437
|
+
const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", target, from];
|
|
6438
|
+
let coinAPriceSeed;
|
|
6439
|
+
let coinBPriceSeed;
|
|
6440
|
+
let coinAPriceInfoObjectId;
|
|
6441
|
+
let coinBPriceInfoObjectId;
|
|
6442
|
+
if (path.extendedDetails == null) {
|
|
6443
|
+
throw new Error("Extended details not supported in obric");
|
|
6444
|
+
} else {
|
|
6445
|
+
if (path.extendedDetails.obricCoinAPriceSeed && path.extendedDetails.obricCoinBPriceSeed) {
|
|
6446
|
+
coinAPriceSeed = path.extendedDetails.obricCoinAPriceSeed;
|
|
6447
|
+
coinAPriceInfoObjectId = this.pythPriceIDs.get(coinAPriceSeed);
|
|
6448
|
+
coinBPriceSeed = path.extendedDetails.obricCoinBPriceSeed;
|
|
6449
|
+
coinBPriceInfoObjectId = this.pythPriceIDs.get(coinBPriceSeed);
|
|
6450
|
+
} else {
|
|
6451
|
+
if (!path.extendedDetails.obricCoinAPriceId || !path.extendedDetails.obricCoinBPriceId) {
|
|
6452
|
+
throw new Error("Base price id or quote price id not supported");
|
|
6453
|
+
} else {
|
|
6454
|
+
coinAPriceInfoObjectId = path.extendedDetails.obricCoinAPriceId;
|
|
6455
|
+
coinBPriceInfoObjectId = path.extendedDetails.obricCoinBPriceId;
|
|
6456
|
+
}
|
|
6457
|
+
}
|
|
6458
|
+
}
|
|
6459
|
+
if (!coinAPriceInfoObjectId || !coinBPriceInfoObjectId) {
|
|
6460
|
+
throw new Error(
|
|
6461
|
+
"Base price info object id or quote price info object id not found"
|
|
6462
|
+
);
|
|
6463
|
+
}
|
|
6464
|
+
const args = [
|
|
6465
|
+
txb.object(path.id),
|
|
6466
|
+
inputCoin,
|
|
6467
|
+
txb.object(this.pythStateObjectId),
|
|
6468
|
+
txb.object(coinAPriceInfoObjectId),
|
|
6469
|
+
txb.object(coinBPriceInfoObjectId),
|
|
6470
|
+
txb.object(CLOCK_ADDRESS)
|
|
6471
|
+
];
|
|
6472
|
+
const publishedAt = getAggregatorV2ExtendPublishedAt(
|
|
6473
|
+
client.publishedAtV2Extend(),
|
|
6474
|
+
packages
|
|
6475
|
+
);
|
|
6476
|
+
const res = txb.moveCall({
|
|
6477
|
+
target: `${publishedAt}::obric::${func}`,
|
|
6478
|
+
typeArguments: [coinAType, coinBType],
|
|
6479
|
+
arguments: args
|
|
6480
|
+
});
|
|
6481
|
+
return res;
|
|
6482
|
+
});
|
|
6483
|
+
}
|
|
6484
|
+
};
|
|
6485
|
+
|
|
6423
6486
|
// src/client.ts
|
|
6424
6487
|
var CETUS = "CETUS";
|
|
6425
6488
|
var DEEPBOOKV2 = "DEEPBOOK";
|
|
@@ -6442,6 +6505,7 @@ var ALPHAFI = "ALPHAFI";
|
|
|
6442
6505
|
var SPRINGSUI = "SPRINGSUI";
|
|
6443
6506
|
var STEAMM = "STEAMM";
|
|
6444
6507
|
var METASTABLE = "METASTABLE";
|
|
6508
|
+
var OBRIC = "OBRIC";
|
|
6445
6509
|
var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
6446
6510
|
function isBuilderRouterSwapParams(params) {
|
|
6447
6511
|
return Array.isArray(params.routers);
|
|
@@ -6511,6 +6575,62 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
6511
6575
|
return getRouterResult(this.endpoint, params);
|
|
6512
6576
|
});
|
|
6513
6577
|
}
|
|
6578
|
+
executeFlexibleInputSwap(txb, inputCoin, routers, amountOutLimit, pythPriceIDs, partner, deepbookv3DeepFee, packages) {
|
|
6579
|
+
return __async(this, null, function* () {
|
|
6580
|
+
if (routers.length === 0) {
|
|
6581
|
+
throw new Error("No router found");
|
|
6582
|
+
}
|
|
6583
|
+
const outputCoinType = routers[0].path[routers[0].path.length - 1].target;
|
|
6584
|
+
const outputCoins = [];
|
|
6585
|
+
for (let i = 0; i < routers.length - 1; i++) {
|
|
6586
|
+
if (routers[i].path.length === 0) {
|
|
6587
|
+
throw new Error("Empty path");
|
|
6588
|
+
}
|
|
6589
|
+
const splitCoin = txb.splitCoins(inputCoin, [routers[i].amountIn.toString()]);
|
|
6590
|
+
let nextCoin = splitCoin[0];
|
|
6591
|
+
for (const path of routers[i].path) {
|
|
6592
|
+
const dex = this.newDex(path.provider, pythPriceIDs, partner);
|
|
6593
|
+
nextCoin = yield dex.swap(
|
|
6594
|
+
this,
|
|
6595
|
+
txb,
|
|
6596
|
+
path,
|
|
6597
|
+
nextCoin,
|
|
6598
|
+
packages,
|
|
6599
|
+
deepbookv3DeepFee
|
|
6600
|
+
);
|
|
6601
|
+
}
|
|
6602
|
+
outputCoins.push(nextCoin);
|
|
6603
|
+
}
|
|
6604
|
+
if (routers[routers.length - 1].path.length === 0) {
|
|
6605
|
+
throw new Error("Empty path");
|
|
6606
|
+
}
|
|
6607
|
+
let lastCoin = inputCoin;
|
|
6608
|
+
for (const path of routers[routers.length - 1].path) {
|
|
6609
|
+
const dex = this.newDex(path.provider, pythPriceIDs, partner);
|
|
6610
|
+
lastCoin = yield dex.swap(
|
|
6611
|
+
this,
|
|
6612
|
+
txb,
|
|
6613
|
+
path,
|
|
6614
|
+
lastCoin,
|
|
6615
|
+
packages,
|
|
6616
|
+
deepbookv3DeepFee
|
|
6617
|
+
);
|
|
6618
|
+
}
|
|
6619
|
+
outputCoins.push(lastCoin);
|
|
6620
|
+
const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(
|
|
6621
|
+
this.publishedAtV2(),
|
|
6622
|
+
packages
|
|
6623
|
+
);
|
|
6624
|
+
const mergedTargetCoin = this.checkCoinThresholdAndMergeCoin(
|
|
6625
|
+
txb,
|
|
6626
|
+
outputCoins,
|
|
6627
|
+
outputCoinType,
|
|
6628
|
+
amountOutLimit,
|
|
6629
|
+
aggregatorV2PublishedAt
|
|
6630
|
+
);
|
|
6631
|
+
return mergedTargetCoin;
|
|
6632
|
+
});
|
|
6633
|
+
}
|
|
6514
6634
|
expectInputSwap(txb, inputCoin, routers, amountOutLimit, pythPriceIDs, partner, deepbookv3DeepFee, packages) {
|
|
6515
6635
|
return __async(this, null, function* () {
|
|
6516
6636
|
if (routers.length === 0) {
|
|
@@ -6689,6 +6809,53 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
6689
6809
|
return targetCoin;
|
|
6690
6810
|
});
|
|
6691
6811
|
}
|
|
6812
|
+
fixableRouterSwap(params) {
|
|
6813
|
+
return __async(this, null, function* () {
|
|
6814
|
+
const { routers, inputCoin, slippage, txb, partner, deepbookv3DeepFee } = params;
|
|
6815
|
+
const routerData = Array.isArray(routers) ? routers : routers.routes;
|
|
6816
|
+
const byAmountIn = params.routers.byAmountIn;
|
|
6817
|
+
const amountIn = routerData.reduce(
|
|
6818
|
+
(acc, router) => acc.add(router.amountIn),
|
|
6819
|
+
new import_bn5.default(0)
|
|
6820
|
+
);
|
|
6821
|
+
const amountOut = routerData.reduce(
|
|
6822
|
+
(acc, router) => acc.add(router.amountOut),
|
|
6823
|
+
new import_bn5.default(0)
|
|
6824
|
+
);
|
|
6825
|
+
const amountLimit = CalculateAmountLimitBN(
|
|
6826
|
+
byAmountIn ? amountOut : amountIn,
|
|
6827
|
+
byAmountIn,
|
|
6828
|
+
slippage
|
|
6829
|
+
);
|
|
6830
|
+
const packages = isBuilderRouterSwapParams(params) ? void 0 : params.routers.packages;
|
|
6831
|
+
getAggregatorV2PublishedAt(
|
|
6832
|
+
this.publishedAtV2(),
|
|
6833
|
+
packages
|
|
6834
|
+
);
|
|
6835
|
+
const priceIDs = findPythPriceIDs(routerData);
|
|
6836
|
+
const priceInfoObjectIds = priceIDs.length > 0 ? yield this.updatePythPriceIDs(priceIDs, txb) : /* @__PURE__ */ new Map();
|
|
6837
|
+
if (byAmountIn) {
|
|
6838
|
+
const targetCoin2 = yield this.executeFlexibleInputSwap(
|
|
6839
|
+
txb,
|
|
6840
|
+
inputCoin,
|
|
6841
|
+
routerData,
|
|
6842
|
+
amountLimit,
|
|
6843
|
+
priceInfoObjectIds,
|
|
6844
|
+
partner,
|
|
6845
|
+
deepbookv3DeepFee,
|
|
6846
|
+
packages
|
|
6847
|
+
);
|
|
6848
|
+
return targetCoin2;
|
|
6849
|
+
}
|
|
6850
|
+
const targetCoin = yield this.expectOutputSwap(
|
|
6851
|
+
txb,
|
|
6852
|
+
inputCoin,
|
|
6853
|
+
routerData,
|
|
6854
|
+
partner
|
|
6855
|
+
);
|
|
6856
|
+
return targetCoin;
|
|
6857
|
+
});
|
|
6858
|
+
}
|
|
6692
6859
|
// auto build input coin
|
|
6693
6860
|
// auto merge, transfer or destory target coin.
|
|
6694
6861
|
fastRouterSwap(params) {
|
|
@@ -6792,7 +6959,7 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
6792
6959
|
// Include deepbookv3, scallop, bluefin
|
|
6793
6960
|
publishedAtV2Extend() {
|
|
6794
6961
|
if (this.env === 0 /* Mainnet */) {
|
|
6795
|
-
return "
|
|
6962
|
+
return "0x200e762fa2c49f3dc150813038fbf22fd4f894ac6f23ebe1085c62f2ef97f1ca";
|
|
6796
6963
|
} else {
|
|
6797
6964
|
return "0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78";
|
|
6798
6965
|
}
|
|
@@ -6873,6 +7040,8 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
6873
7040
|
return new Steamm(this.env);
|
|
6874
7041
|
case METASTABLE:
|
|
6875
7042
|
return new Metastable(this.env, pythPriceIDs);
|
|
7043
|
+
case OBRIC:
|
|
7044
|
+
return new Obric(this.env, pythPriceIDs);
|
|
6876
7045
|
default:
|
|
6877
7046
|
throw new Error(`Unsupported dex ${provider}`);
|
|
6878
7047
|
}
|
|
@@ -6980,7 +7149,7 @@ _AggregatorClient.CONFIG = {
|
|
|
6980
7149
|
pythStateId: "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8"
|
|
6981
7150
|
}
|
|
6982
7151
|
};
|
|
6983
|
-
var
|
|
7152
|
+
var AggregatorClient22 = _AggregatorClient;
|
|
6984
7153
|
function findPythPriceIDs(routes) {
|
|
6985
7154
|
const priceIDs = /* @__PURE__ */ new Set();
|
|
6986
7155
|
for (const route of routes) {
|
|
@@ -6999,6 +7168,14 @@ function findPythPriceIDs(routes) {
|
|
|
6999
7168
|
priceIDs.add(path.extendedDetails.metastableETHPriceSeed);
|
|
7000
7169
|
}
|
|
7001
7170
|
}
|
|
7171
|
+
if (path.provider === OBRIC) {
|
|
7172
|
+
if (path.extendedDetails && path.extendedDetails.obricCoinAPriceSeed) {
|
|
7173
|
+
priceIDs.add(path.extendedDetails.obricCoinAPriceSeed);
|
|
7174
|
+
}
|
|
7175
|
+
if (path.extendedDetails && path.extendedDetails.obricCoinBPriceSeed) {
|
|
7176
|
+
priceIDs.add(path.extendedDetails.obricCoinBPriceSeed);
|
|
7177
|
+
}
|
|
7178
|
+
}
|
|
7002
7179
|
}
|
|
7003
7180
|
}
|
|
7004
7181
|
return Array.from(priceIDs);
|
|
@@ -7027,13 +7204,13 @@ function parseRouterResponse(data, byAmountIn) {
|
|
|
7027
7204
|
routes: data.routes.map((route) => {
|
|
7028
7205
|
return {
|
|
7029
7206
|
path: route.path.map((path) => {
|
|
7030
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
7207
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
|
|
7031
7208
|
let version;
|
|
7032
7209
|
if (path.provider === AFTERMATH) {
|
|
7033
7210
|
version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
|
|
7034
7211
|
}
|
|
7035
7212
|
let extendedDetails;
|
|
7036
|
-
if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3 || path.provider === SCALLOP || path.provider === HAEDALPMM || path.provider === STEAMM || path.provider === METASTABLE) {
|
|
7213
|
+
if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3 || path.provider === SCALLOP || path.provider === HAEDALPMM || path.provider === STEAMM || path.provider === METASTABLE || path.provider === OBRIC) {
|
|
7037
7214
|
extendedDetails = {
|
|
7038
7215
|
aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
|
|
7039
7216
|
turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
|
|
@@ -7055,7 +7232,11 @@ function parseRouterResponse(data, byAmountIn) {
|
|
|
7055
7232
|
metastableCreateCapPkgId: (_r = path.extended_details) == null ? void 0 : _r.metastable_create_cap_pkg_id,
|
|
7056
7233
|
metastableCreateCapModule: (_s = path.extended_details) == null ? void 0 : _s.metastable_create_cap_module,
|
|
7057
7234
|
metastableCreateCapAllTypeParams: (_t = path.extended_details) == null ? void 0 : _t.metastable_create_cap_all_type_params,
|
|
7058
|
-
metastableRegistryId: (_u = path.extended_details) == null ? void 0 : _u.metastable_registry_id
|
|
7235
|
+
metastableRegistryId: (_u = path.extended_details) == null ? void 0 : _u.metastable_registry_id,
|
|
7236
|
+
obricCoinAPriceSeed: (_v = path.extended_details) == null ? void 0 : _v.obric_coin_a_price_seed,
|
|
7237
|
+
obricCoinBPriceSeed: (_w = path.extended_details) == null ? void 0 : _w.obric_coin_b_price_seed,
|
|
7238
|
+
obricCoinAPriceId: (_x = path.extended_details) == null ? void 0 : _x.obric_coin_a_price_id,
|
|
7239
|
+
obricCoinBPriceId: (_y = path.extended_details) == null ? void 0 : _y.obric_coin_b_price_id
|
|
7059
7240
|
};
|
|
7060
7241
|
}
|
|
7061
7242
|
return {
|
|
@@ -7102,23 +7283,34 @@ function getAggregatorV2ExtendPublishedAt(aggregatorV2ExtendPublishedAt, package
|
|
|
7102
7283
|
// src/utils/msafe.ts
|
|
7103
7284
|
var import_bn6 = __toESM(require_bn());
|
|
7104
7285
|
var dealWithFastRouterSwapParamsForMsafe = (data) => {
|
|
7105
|
-
|
|
7106
|
-
|
|
7107
|
-
|
|
7108
|
-
|
|
7109
|
-
|
|
7110
|
-
|
|
7111
|
-
|
|
7286
|
+
var _a, _b, _c;
|
|
7287
|
+
const result = __spreadProps(__spreadValues({}, data), {
|
|
7288
|
+
amountIn: (_a = data == null ? void 0 : data.amountIn) == null ? void 0 : _a.toString(),
|
|
7289
|
+
amountOut: (_b = data == null ? void 0 : data.amountIn) == null ? void 0 : _b.toString(),
|
|
7290
|
+
routes: (_c = data == null ? void 0 : data.routes) == null ? void 0 : _c.map((item) => {
|
|
7291
|
+
var _a2, _b2, _c2;
|
|
7292
|
+
return __spreadProps(__spreadValues({}, item), {
|
|
7293
|
+
amountIn: (_a2 = item == null ? void 0 : item.amountIn) == null ? void 0 : _a2.toString(),
|
|
7294
|
+
amountOut: (_b2 = item == null ? void 0 : item.amountOut) == null ? void 0 : _b2.toString(),
|
|
7295
|
+
initialPrice: (_c2 = item == null ? void 0 : item.initialPrice) == null ? void 0 : _c2.toString()
|
|
7296
|
+
});
|
|
7297
|
+
})
|
|
7112
7298
|
});
|
|
7113
7299
|
return result;
|
|
7114
7300
|
};
|
|
7115
7301
|
var restituteMsafeFastRouterSwapParams = (data) => {
|
|
7116
|
-
|
|
7117
|
-
|
|
7118
|
-
|
|
7119
|
-
|
|
7120
|
-
|
|
7121
|
-
|
|
7302
|
+
var _a;
|
|
7303
|
+
const result = __spreadProps(__spreadValues({}, data), {
|
|
7304
|
+
amountIn: new import_bn6.default(data == null ? void 0 : data.amountIn),
|
|
7305
|
+
amountOut: new import_bn6.default(data == null ? void 0 : data.amountIn),
|
|
7306
|
+
routes: (_a = data == null ? void 0 : data.routes) == null ? void 0 : _a.map((item) => {
|
|
7307
|
+
var _a2;
|
|
7308
|
+
return __spreadProps(__spreadValues({}, item), {
|
|
7309
|
+
amountIn: new import_bn6.default(item == null ? void 0 : item.amountIn),
|
|
7310
|
+
amountOut: new import_bn6.default(item == null ? void 0 : item.amountOut),
|
|
7311
|
+
initialPrice: new decimal_default((_a2 = item == null ? void 0 : item.initialPrice) == null ? void 0 : _a2.toString())
|
|
7312
|
+
});
|
|
7313
|
+
})
|
|
7122
7314
|
});
|
|
7123
7315
|
return result;
|
|
7124
7316
|
};
|
|
@@ -7132,7 +7324,7 @@ function processEndpoint(endpoint) {
|
|
|
7132
7324
|
}
|
|
7133
7325
|
|
|
7134
7326
|
// src/api.ts
|
|
7135
|
-
var SDK_VERSION =
|
|
7327
|
+
var SDK_VERSION = 1000400;
|
|
7136
7328
|
function getRouterResult(endpoint, params) {
|
|
7137
7329
|
return __async(this, null, function* () {
|
|
7138
7330
|
let response;
|
|
@@ -7145,6 +7337,10 @@ function getRouterResult(endpoint, params) {
|
|
|
7145
7337
|
return null;
|
|
7146
7338
|
}
|
|
7147
7339
|
if (!response.ok) {
|
|
7340
|
+
let errorCode = 10001 /* NumberTooLarge */;
|
|
7341
|
+
if (response.status === 429) {
|
|
7342
|
+
errorCode = 10005 /* RateLimitExceeded */;
|
|
7343
|
+
}
|
|
7148
7344
|
return {
|
|
7149
7345
|
amountIn: ZERO,
|
|
7150
7346
|
amountOut: ZERO,
|
|
@@ -7152,10 +7348,8 @@ function getRouterResult(endpoint, params) {
|
|
|
7152
7348
|
byAmountIn: params.byAmountIn,
|
|
7153
7349
|
insufficientLiquidity: false,
|
|
7154
7350
|
error: {
|
|
7155
|
-
code:
|
|
7156
|
-
msg: getAggregatorServerErrorMessage(
|
|
7157
|
-
10001 /* NumberTooLarge */
|
|
7158
|
-
)
|
|
7351
|
+
code: errorCode,
|
|
7352
|
+
msg: getAggregatorServerErrorMessage(errorCode)
|
|
7159
7353
|
}
|
|
7160
7354
|
};
|
|
7161
7355
|
}
|
|
@@ -7325,7 +7519,7 @@ exports.AFTERMATH = AFTERMATH;
|
|
|
7325
7519
|
exports.AGGREGATOR_V2 = AGGREGATOR_V2;
|
|
7326
7520
|
exports.AGGREGATOR_V2_EXTEND = AGGREGATOR_V2_EXTEND;
|
|
7327
7521
|
exports.ALPHAFI = ALPHAFI;
|
|
7328
|
-
exports.AggregatorClient =
|
|
7522
|
+
exports.AggregatorClient = AggregatorClient22;
|
|
7329
7523
|
exports.BLUEFIN = BLUEFIN;
|
|
7330
7524
|
exports.BLUEMOVE = BLUEMOVE;
|
|
7331
7525
|
exports.CETUS = CETUS;
|
|
@@ -7341,6 +7535,7 @@ exports.HAEDALPMM = HAEDALPMM;
|
|
|
7341
7535
|
exports.KRIYA = KRIYA;
|
|
7342
7536
|
exports.KRIYAV3 = KRIYAV3;
|
|
7343
7537
|
exports.METASTABLE = METASTABLE;
|
|
7538
|
+
exports.OBRIC = OBRIC;
|
|
7344
7539
|
exports.ONE = ONE;
|
|
7345
7540
|
exports.SCALLOP = SCALLOP;
|
|
7346
7541
|
exports.SPRINGSUI = SPRINGSUI;
|