@cetusprotocol/aggregator-sdk 0.3.32 → 0.4.1
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/README.md +19 -8
- package/dist/index.d.mts +21 -3
- package/dist/index.d.ts +21 -3
- package/dist/index.js +211 -33
- package/dist/index.mjs +211 -34
- package/dist/src/api.d.ts +5 -1
- package/dist/src/client.d.ts +15 -1
- package/dist/src/transaction/obric.d.ts +8 -0
- package/dist/tests/router/alphafi.test.d.ts +2 -0
- package/dist/tests/router/obric.test.d.ts +2 -0
- package/package.json +1 -1
- package/src/api.ts +12 -3
- package/src/client.ts +184 -31
- package/src/transaction/obric.ts +90 -0
- package/tests/router/alphafi.test.ts +132 -0
- package/tests/router/metastable.test.ts +7 -1
- package/tests/router/obric.test.ts +203 -0
- package/tests/router/scallop.test.ts +7 -1
- package/tests/router/steamm.test.ts +7 -1
- package/tests/router.test.ts +7 -1
package/README.md
CHANGED
|
@@ -41,9 +41,22 @@ npm install @cetusprotocol/aggregator-sdk
|
|
|
41
41
|
|
|
42
42
|
## 1. Init client with rpc and package config
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
1. Fast init:
|
|
45
|
+
```typescript
|
|
46
|
+
const client = new AggregatorClient()
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
2. Full init:
|
|
50
|
+
```typescript
|
|
51
|
+
const client = new AggregatorClient({
|
|
52
|
+
// endpoint, // If you do not have a exclusive aggregator api domain,just use cetus default aggregator endpoints.
|
|
53
|
+
signer: wallet,
|
|
54
|
+
client: suiClient,
|
|
55
|
+
env: Env.Mainnet,
|
|
56
|
+
pythUrls: ["YOUR_PYTH_URL", "ANOTHER_PYTH_URL"],
|
|
57
|
+
})
|
|
58
|
+
```
|
|
59
|
+
**Notes**: Some providers, such as HaedalHMM and Metastable, rely on Pyth oracle prices when build transactions. Currently, we have a default configuration that connects to Pyth's publicly available node. However, if you frequently build transactions, we recommend setting up a private Pyth node interface as an additional backup. This will ensure uninterrupted access to HaedalHMM and Metastable, even if the public node experiences occasional downtime.
|
|
47
60
|
|
|
48
61
|
## 2. Get best router swap result from aggregator service
|
|
49
62
|
|
|
@@ -53,7 +66,7 @@ const from = "0x2::sui::SUI"
|
|
|
53
66
|
const target =
|
|
54
67
|
"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS"
|
|
55
68
|
|
|
56
|
-
const
|
|
69
|
+
const routers = await client.findRouters({
|
|
57
70
|
from,
|
|
58
71
|
target,
|
|
59
72
|
amount,
|
|
@@ -68,8 +81,7 @@ const routerTx = new Transaction()
|
|
|
68
81
|
|
|
69
82
|
if (routerRes != null) {
|
|
70
83
|
await client.fastRouterSwap({
|
|
71
|
-
routers
|
|
72
|
-
byAmountIn,
|
|
84
|
+
routers,
|
|
73
85
|
txb: routerTx,
|
|
74
86
|
slippage: 0.01,
|
|
75
87
|
isMergeTragetCoin: true,
|
|
@@ -94,8 +106,7 @@ const byAmountIn = true;
|
|
|
94
106
|
|
|
95
107
|
if (routerRes != null) {
|
|
96
108
|
const targetCoin = await client.routerSwap({
|
|
97
|
-
routers
|
|
98
|
-
byAmountIn,
|
|
109
|
+
routers,
|
|
99
110
|
txb: routerTx,
|
|
100
111
|
inputCoin,
|
|
101
112
|
slippage: 0.01,
|
package/dist/index.d.mts
CHANGED
|
@@ -4,6 +4,7 @@ import { TransactionObjectArgument, Transaction } from '@mysten/sui/transactions
|
|
|
4
4
|
import { Signer } from '@mysten/sui/cryptography';
|
|
5
5
|
import BN from 'bn.js';
|
|
6
6
|
import Decimal from 'decimal.js';
|
|
7
|
+
import { SuiPriceServiceConnection } from '@pythnetwork/pyth-sui-js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Represents a SUI address, which is a string.
|
|
@@ -81,6 +82,7 @@ declare const ALPHAFI = "ALPHAFI";
|
|
|
81
82
|
declare const SPRINGSUI = "SPRINGSUI";
|
|
82
83
|
declare const STEAMM = "STEAMM";
|
|
83
84
|
declare const METASTABLE = "METASTABLE";
|
|
85
|
+
declare const OBRIC = "OBRIC";
|
|
84
86
|
declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
85
87
|
type BuildRouterSwapParams = {
|
|
86
88
|
routers: Router[];
|
|
@@ -127,22 +129,34 @@ interface SwapInPoolsResult {
|
|
|
127
129
|
isExceed: boolean;
|
|
128
130
|
routeData?: RouterData;
|
|
129
131
|
}
|
|
132
|
+
type AggregatorClientParams = {
|
|
133
|
+
endpoint?: string;
|
|
134
|
+
signer?: string;
|
|
135
|
+
client?: SuiClient;
|
|
136
|
+
env?: Env;
|
|
137
|
+
pythUrls?: string[];
|
|
138
|
+
apiKey?: string;
|
|
139
|
+
};
|
|
130
140
|
declare class AggregatorClient {
|
|
131
141
|
endpoint: string;
|
|
132
142
|
signer: string;
|
|
133
143
|
client: SuiClient;
|
|
134
144
|
env: Env;
|
|
145
|
+
apiKey: string;
|
|
135
146
|
private allCoins;
|
|
136
147
|
private pythConnections;
|
|
137
148
|
private pythClient;
|
|
138
149
|
private static readonly CONFIG;
|
|
139
|
-
constructor(
|
|
150
|
+
constructor(params: AggregatorClientParams);
|
|
151
|
+
newPythClients(pythUrls: string[]): SuiPriceServiceConnection[];
|
|
140
152
|
getCoins(coinType: string, refresh?: boolean): Promise<CoinAsset[]>;
|
|
141
153
|
findRouters(params: FindRouterParams): Promise<RouterData | null>;
|
|
154
|
+
executeFlexibleInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, pythPriceIDs: Map<string, string>, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
|
|
142
155
|
expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, pythPriceIDs: Map<string, string>, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
|
|
143
156
|
expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
|
|
144
157
|
swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResult | null>;
|
|
145
158
|
routerSwap(params: BuildRouterSwapParams | BuildRouterSwapParamsV2): Promise<TransactionObjectArgument>;
|
|
159
|
+
fixableRouterSwap(params: BuildRouterSwapParamsV2): Promise<TransactionObjectArgument>;
|
|
146
160
|
fastRouterSwap(params: BuildFastRouterSwapParams | BuildFastRouterSwapParamsV2): Promise<void>;
|
|
147
161
|
publishedAtV2(): string;
|
|
148
162
|
publishedAtV2Extend(): string;
|
|
@@ -251,6 +265,10 @@ type ExtendedDetails = {
|
|
|
251
265
|
metastableCreateCapModule?: string;
|
|
252
266
|
metastableCreateCapAllTypeParams?: boolean;
|
|
253
267
|
metastableRegistryId?: string;
|
|
268
|
+
obricCoinAPriceSeed?: string;
|
|
269
|
+
obricCoinBPriceSeed?: string;
|
|
270
|
+
obricCoinAPriceId?: string;
|
|
271
|
+
obricCoinBPriceId?: string;
|
|
254
272
|
};
|
|
255
273
|
type Path = {
|
|
256
274
|
id: string;
|
|
@@ -289,7 +307,7 @@ type AggregatorResponse = {
|
|
|
289
307
|
msg: string;
|
|
290
308
|
data: RouterData;
|
|
291
309
|
};
|
|
292
|
-
declare function getRouterResult(endpoint: string, params: FindRouterParams): Promise<RouterData | null>;
|
|
310
|
+
declare function getRouterResult(endpoint: string, apiKey: string, params: FindRouterParams): Promise<RouterData | null>;
|
|
293
311
|
type DeepbookV3Config = {
|
|
294
312
|
id: string;
|
|
295
313
|
is_alternative_payment: boolean;
|
|
@@ -314,4 +332,4 @@ declare enum Env {
|
|
|
314
332
|
Testnet = 1
|
|
315
333
|
}
|
|
316
334
|
|
|
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 };
|
|
335
|
+
export { AFSUI, AFTERMATH, AGGREGATOR_V2, AGGREGATOR_V2_EXTEND, ALPHAFI, AggregatorClient, type AggregatorClientParams, 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
|
@@ -4,6 +4,7 @@ import { TransactionObjectArgument, Transaction } from '@mysten/sui/transactions
|
|
|
4
4
|
import { Signer } from '@mysten/sui/cryptography';
|
|
5
5
|
import BN from 'bn.js';
|
|
6
6
|
import Decimal from 'decimal.js';
|
|
7
|
+
import { SuiPriceServiceConnection } from '@pythnetwork/pyth-sui-js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Represents a SUI address, which is a string.
|
|
@@ -81,6 +82,7 @@ declare const ALPHAFI = "ALPHAFI";
|
|
|
81
82
|
declare const SPRINGSUI = "SPRINGSUI";
|
|
82
83
|
declare const STEAMM = "STEAMM";
|
|
83
84
|
declare const METASTABLE = "METASTABLE";
|
|
85
|
+
declare const OBRIC = "OBRIC";
|
|
84
86
|
declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
85
87
|
type BuildRouterSwapParams = {
|
|
86
88
|
routers: Router[];
|
|
@@ -127,22 +129,34 @@ interface SwapInPoolsResult {
|
|
|
127
129
|
isExceed: boolean;
|
|
128
130
|
routeData?: RouterData;
|
|
129
131
|
}
|
|
132
|
+
type AggregatorClientParams = {
|
|
133
|
+
endpoint?: string;
|
|
134
|
+
signer?: string;
|
|
135
|
+
client?: SuiClient;
|
|
136
|
+
env?: Env;
|
|
137
|
+
pythUrls?: string[];
|
|
138
|
+
apiKey?: string;
|
|
139
|
+
};
|
|
130
140
|
declare class AggregatorClient {
|
|
131
141
|
endpoint: string;
|
|
132
142
|
signer: string;
|
|
133
143
|
client: SuiClient;
|
|
134
144
|
env: Env;
|
|
145
|
+
apiKey: string;
|
|
135
146
|
private allCoins;
|
|
136
147
|
private pythConnections;
|
|
137
148
|
private pythClient;
|
|
138
149
|
private static readonly CONFIG;
|
|
139
|
-
constructor(
|
|
150
|
+
constructor(params: AggregatorClientParams);
|
|
151
|
+
newPythClients(pythUrls: string[]): SuiPriceServiceConnection[];
|
|
140
152
|
getCoins(coinType: string, refresh?: boolean): Promise<CoinAsset[]>;
|
|
141
153
|
findRouters(params: FindRouterParams): Promise<RouterData | null>;
|
|
154
|
+
executeFlexibleInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, pythPriceIDs: Map<string, string>, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
|
|
142
155
|
expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, pythPriceIDs: Map<string, string>, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
|
|
143
156
|
expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
|
|
144
157
|
swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResult | null>;
|
|
145
158
|
routerSwap(params: BuildRouterSwapParams | BuildRouterSwapParamsV2): Promise<TransactionObjectArgument>;
|
|
159
|
+
fixableRouterSwap(params: BuildRouterSwapParamsV2): Promise<TransactionObjectArgument>;
|
|
146
160
|
fastRouterSwap(params: BuildFastRouterSwapParams | BuildFastRouterSwapParamsV2): Promise<void>;
|
|
147
161
|
publishedAtV2(): string;
|
|
148
162
|
publishedAtV2Extend(): string;
|
|
@@ -251,6 +265,10 @@ type ExtendedDetails = {
|
|
|
251
265
|
metastableCreateCapModule?: string;
|
|
252
266
|
metastableCreateCapAllTypeParams?: boolean;
|
|
253
267
|
metastableRegistryId?: string;
|
|
268
|
+
obricCoinAPriceSeed?: string;
|
|
269
|
+
obricCoinBPriceSeed?: string;
|
|
270
|
+
obricCoinAPriceId?: string;
|
|
271
|
+
obricCoinBPriceId?: string;
|
|
254
272
|
};
|
|
255
273
|
type Path = {
|
|
256
274
|
id: string;
|
|
@@ -289,7 +307,7 @@ type AggregatorResponse = {
|
|
|
289
307
|
msg: string;
|
|
290
308
|
data: RouterData;
|
|
291
309
|
};
|
|
292
|
-
declare function getRouterResult(endpoint: string, params: FindRouterParams): Promise<RouterData | null>;
|
|
310
|
+
declare function getRouterResult(endpoint: string, apiKey: string, params: FindRouterParams): Promise<RouterData | null>;
|
|
293
311
|
type DeepbookV3Config = {
|
|
294
312
|
id: string;
|
|
295
313
|
is_alternative_payment: boolean;
|
|
@@ -314,4 +332,4 @@ declare enum Env {
|
|
|
314
332
|
Testnet = 1
|
|
315
333
|
}
|
|
316
334
|
|
|
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 };
|
|
335
|
+
export { AFSUI, AFTERMATH, AGGREGATOR_V2, AGGREGATOR_V2_EXTEND, ALPHAFI, AggregatorClient, type AggregatorClientParams, 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
|
@@ -6422,6 +6422,67 @@ var Metastable = class {
|
|
|
6422
6422
|
}
|
|
6423
6423
|
};
|
|
6424
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
|
+
|
|
6425
6486
|
// src/client.ts
|
|
6426
6487
|
var CETUS = "CETUS";
|
|
6427
6488
|
var DEEPBOOKV2 = "DEEPBOOK";
|
|
@@ -6444,6 +6505,7 @@ var ALPHAFI = "ALPHAFI";
|
|
|
6444
6505
|
var SPRINGSUI = "SPRINGSUI";
|
|
6445
6506
|
var STEAMM = "STEAMM";
|
|
6446
6507
|
var METASTABLE = "METASTABLE";
|
|
6508
|
+
var OBRIC = "OBRIC";
|
|
6447
6509
|
var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
6448
6510
|
function isBuilderRouterSwapParams(params) {
|
|
6449
6511
|
return Array.isArray(params.routers);
|
|
@@ -6452,19 +6514,28 @@ function isBuilderFastRouterSwapParams(params) {
|
|
|
6452
6514
|
return Array.isArray(params.routers);
|
|
6453
6515
|
}
|
|
6454
6516
|
var _AggregatorClient = class _AggregatorClient {
|
|
6455
|
-
constructor(
|
|
6456
|
-
|
|
6457
|
-
this.
|
|
6458
|
-
this.
|
|
6459
|
-
this.
|
|
6517
|
+
constructor(params) {
|
|
6518
|
+
var _a;
|
|
6519
|
+
this.endpoint = params.endpoint ? processEndpoint(params.endpoint) : DEFAULT_ENDPOINT;
|
|
6520
|
+
this.client = params.client || new client.SuiClient({ url: client.getFullnodeUrl("mainnet") });
|
|
6521
|
+
this.signer = params.signer || "";
|
|
6522
|
+
this.env = params.env || 0 /* Mainnet */;
|
|
6460
6523
|
this.allCoins = /* @__PURE__ */ new Map();
|
|
6461
6524
|
const config2 = _AggregatorClient.CONFIG[this.env];
|
|
6462
|
-
this.pythConnections =
|
|
6525
|
+
this.pythConnections = this.newPythClients((_a = params.pythUrls) != null ? _a : []);
|
|
6463
6526
|
this.pythClient = new pythSuiJs.SuiPythClient(
|
|
6464
6527
|
this.client,
|
|
6465
6528
|
config2.pythStateId,
|
|
6466
6529
|
config2.wormholeStateId
|
|
6467
6530
|
);
|
|
6531
|
+
this.apiKey = params.apiKey || "";
|
|
6532
|
+
}
|
|
6533
|
+
newPythClients(pythUrls) {
|
|
6534
|
+
if (!pythUrls.includes("https://hermes.pyth.network")) {
|
|
6535
|
+
pythUrls.push("https://hermes.pyth.network");
|
|
6536
|
+
}
|
|
6537
|
+
const connections = pythUrls.map((url) => new pythSuiJs.SuiPriceServiceConnection(url, { timeout: 3e3 }));
|
|
6538
|
+
return connections;
|
|
6468
6539
|
}
|
|
6469
6540
|
getCoins(coinType, refresh = true) {
|
|
6470
6541
|
return __async(this, null, function* () {
|
|
@@ -6510,7 +6581,63 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
6510
6581
|
}
|
|
6511
6582
|
findRouters(params) {
|
|
6512
6583
|
return __async(this, null, function* () {
|
|
6513
|
-
return getRouterResult(this.endpoint, params);
|
|
6584
|
+
return getRouterResult(this.endpoint, this.apiKey, params);
|
|
6585
|
+
});
|
|
6586
|
+
}
|
|
6587
|
+
executeFlexibleInputSwap(txb, inputCoin, routers, amountOutLimit, pythPriceIDs, partner, deepbookv3DeepFee, packages) {
|
|
6588
|
+
return __async(this, null, function* () {
|
|
6589
|
+
if (routers.length === 0) {
|
|
6590
|
+
throw new Error("No router found");
|
|
6591
|
+
}
|
|
6592
|
+
const outputCoinType = routers[0].path[routers[0].path.length - 1].target;
|
|
6593
|
+
const outputCoins = [];
|
|
6594
|
+
for (let i = 0; i < routers.length - 1; i++) {
|
|
6595
|
+
if (routers[i].path.length === 0) {
|
|
6596
|
+
throw new Error("Empty path");
|
|
6597
|
+
}
|
|
6598
|
+
const splitCoin = txb.splitCoins(inputCoin, [routers[i].amountIn.toString()]);
|
|
6599
|
+
let nextCoin = splitCoin[0];
|
|
6600
|
+
for (const path of routers[i].path) {
|
|
6601
|
+
const dex = this.newDex(path.provider, pythPriceIDs, partner);
|
|
6602
|
+
nextCoin = yield dex.swap(
|
|
6603
|
+
this,
|
|
6604
|
+
txb,
|
|
6605
|
+
path,
|
|
6606
|
+
nextCoin,
|
|
6607
|
+
packages,
|
|
6608
|
+
deepbookv3DeepFee
|
|
6609
|
+
);
|
|
6610
|
+
}
|
|
6611
|
+
outputCoins.push(nextCoin);
|
|
6612
|
+
}
|
|
6613
|
+
if (routers[routers.length - 1].path.length === 0) {
|
|
6614
|
+
throw new Error("Empty path");
|
|
6615
|
+
}
|
|
6616
|
+
let lastCoin = inputCoin;
|
|
6617
|
+
for (const path of routers[routers.length - 1].path) {
|
|
6618
|
+
const dex = this.newDex(path.provider, pythPriceIDs, partner);
|
|
6619
|
+
lastCoin = yield dex.swap(
|
|
6620
|
+
this,
|
|
6621
|
+
txb,
|
|
6622
|
+
path,
|
|
6623
|
+
lastCoin,
|
|
6624
|
+
packages,
|
|
6625
|
+
deepbookv3DeepFee
|
|
6626
|
+
);
|
|
6627
|
+
}
|
|
6628
|
+
outputCoins.push(lastCoin);
|
|
6629
|
+
const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(
|
|
6630
|
+
this.publishedAtV2(),
|
|
6631
|
+
packages
|
|
6632
|
+
);
|
|
6633
|
+
const mergedTargetCoin = this.checkCoinThresholdAndMergeCoin(
|
|
6634
|
+
txb,
|
|
6635
|
+
outputCoins,
|
|
6636
|
+
outputCoinType,
|
|
6637
|
+
amountOutLimit,
|
|
6638
|
+
aggregatorV2PublishedAt
|
|
6639
|
+
);
|
|
6640
|
+
return mergedTargetCoin;
|
|
6514
6641
|
});
|
|
6515
6642
|
}
|
|
6516
6643
|
expectInputSwap(txb, inputCoin, routers, amountOutLimit, pythPriceIDs, partner, deepbookv3DeepFee, packages) {
|
|
@@ -6691,6 +6818,53 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
6691
6818
|
return targetCoin;
|
|
6692
6819
|
});
|
|
6693
6820
|
}
|
|
6821
|
+
fixableRouterSwap(params) {
|
|
6822
|
+
return __async(this, null, function* () {
|
|
6823
|
+
const { routers, inputCoin, slippage, txb, partner, deepbookv3DeepFee } = params;
|
|
6824
|
+
const routerData = Array.isArray(routers) ? routers : routers.routes;
|
|
6825
|
+
const byAmountIn = params.routers.byAmountIn;
|
|
6826
|
+
const amountIn = routerData.reduce(
|
|
6827
|
+
(acc, router) => acc.add(router.amountIn),
|
|
6828
|
+
new import_bn5.default(0)
|
|
6829
|
+
);
|
|
6830
|
+
const amountOut = routerData.reduce(
|
|
6831
|
+
(acc, router) => acc.add(router.amountOut),
|
|
6832
|
+
new import_bn5.default(0)
|
|
6833
|
+
);
|
|
6834
|
+
const amountLimit = CalculateAmountLimitBN(
|
|
6835
|
+
byAmountIn ? amountOut : amountIn,
|
|
6836
|
+
byAmountIn,
|
|
6837
|
+
slippage
|
|
6838
|
+
);
|
|
6839
|
+
const packages = isBuilderRouterSwapParams(params) ? void 0 : params.routers.packages;
|
|
6840
|
+
getAggregatorV2PublishedAt(
|
|
6841
|
+
this.publishedAtV2(),
|
|
6842
|
+
packages
|
|
6843
|
+
);
|
|
6844
|
+
const priceIDs = findPythPriceIDs(routerData);
|
|
6845
|
+
const priceInfoObjectIds = priceIDs.length > 0 ? yield this.updatePythPriceIDs(priceIDs, txb) : /* @__PURE__ */ new Map();
|
|
6846
|
+
if (byAmountIn) {
|
|
6847
|
+
const targetCoin2 = yield this.executeFlexibleInputSwap(
|
|
6848
|
+
txb,
|
|
6849
|
+
inputCoin,
|
|
6850
|
+
routerData,
|
|
6851
|
+
amountLimit,
|
|
6852
|
+
priceInfoObjectIds,
|
|
6853
|
+
partner,
|
|
6854
|
+
deepbookv3DeepFee,
|
|
6855
|
+
packages
|
|
6856
|
+
);
|
|
6857
|
+
return targetCoin2;
|
|
6858
|
+
}
|
|
6859
|
+
const targetCoin = yield this.expectOutputSwap(
|
|
6860
|
+
txb,
|
|
6861
|
+
inputCoin,
|
|
6862
|
+
routerData,
|
|
6863
|
+
partner
|
|
6864
|
+
);
|
|
6865
|
+
return targetCoin;
|
|
6866
|
+
});
|
|
6867
|
+
}
|
|
6694
6868
|
// auto build input coin
|
|
6695
6869
|
// auto merge, transfer or destory target coin.
|
|
6696
6870
|
fastRouterSwap(params) {
|
|
@@ -6794,7 +6968,7 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
6794
6968
|
// Include deepbookv3, scallop, bluefin
|
|
6795
6969
|
publishedAtV2Extend() {
|
|
6796
6970
|
if (this.env === 0 /* Mainnet */) {
|
|
6797
|
-
return "
|
|
6971
|
+
return "0x200e762fa2c49f3dc150813038fbf22fd4f894ac6f23ebe1085c62f2ef97f1ca";
|
|
6798
6972
|
} else {
|
|
6799
6973
|
return "0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78";
|
|
6800
6974
|
}
|
|
@@ -6875,6 +7049,8 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
6875
7049
|
return new Steamm(this.env);
|
|
6876
7050
|
case METASTABLE:
|
|
6877
7051
|
return new Metastable(this.env, pythPriceIDs);
|
|
7052
|
+
case OBRIC:
|
|
7053
|
+
return new Obric(this.env, pythPriceIDs);
|
|
6878
7054
|
default:
|
|
6879
7055
|
throw new Error(`Unsupported dex ${provider}`);
|
|
6880
7056
|
}
|
|
@@ -6937,7 +7113,7 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
6937
7113
|
}
|
|
6938
7114
|
if (priceUpdateData == null) {
|
|
6939
7115
|
throw new Error(
|
|
6940
|
-
`
|
|
7116
|
+
`All Pyth price nodes are unavailable. Cannot fetch price data. Please switch to or add new available Pyth nodes. Detailed error: ${lastError == null ? void 0 : lastError.message}`
|
|
6941
7117
|
);
|
|
6942
7118
|
}
|
|
6943
7119
|
let priceInfoObjectIds = [];
|
|
@@ -6948,7 +7124,7 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
6948
7124
|
priceIDs
|
|
6949
7125
|
);
|
|
6950
7126
|
} catch (e) {
|
|
6951
|
-
throw new Error(`
|
|
7127
|
+
throw new Error(`All Pyth price nodes are unavailable. Cannot fetch price data. Please switch to or add new available Pyth nodes in the pythUrls parameter when initializing AggregatorClient, for example: new AggregatorClient({ pythUrls: ["https://your-pyth-node-url"] }). Detailed error: ${e}`);
|
|
6952
7128
|
}
|
|
6953
7129
|
let priceInfoObjectIdsMap = /* @__PURE__ */ new Map();
|
|
6954
7130
|
for (let i = 0; i < priceIDs.length; i++) {
|
|
@@ -6960,29 +7136,15 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
6960
7136
|
};
|
|
6961
7137
|
_AggregatorClient.CONFIG = {
|
|
6962
7138
|
[1 /* Testnet */]: {
|
|
6963
|
-
connections: [
|
|
6964
|
-
new pythSuiJs.SuiPriceServiceConnection("https://hermes-beta.pyth.network")
|
|
6965
|
-
],
|
|
6966
7139
|
wormholeStateId: "0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790",
|
|
6967
7140
|
pythStateId: "0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c"
|
|
6968
7141
|
},
|
|
6969
7142
|
[0 /* Mainnet */]: {
|
|
6970
|
-
connections: [
|
|
6971
|
-
new pythSuiJs.SuiPriceServiceConnection(
|
|
6972
|
-
"https://cetus-pythnet-a648.mainnet.pythnet.rpcpool.com/219cf7a8-6d75-432d-a648-d487a6dd5dc3/hermes",
|
|
6973
|
-
{
|
|
6974
|
-
timeout: 3e3
|
|
6975
|
-
}
|
|
6976
|
-
),
|
|
6977
|
-
new pythSuiJs.SuiPriceServiceConnection("https://hermes.pyth.network", {
|
|
6978
|
-
timeout: 3e3
|
|
6979
|
-
})
|
|
6980
|
-
],
|
|
6981
7143
|
wormholeStateId: "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c",
|
|
6982
7144
|
pythStateId: "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8"
|
|
6983
7145
|
}
|
|
6984
7146
|
};
|
|
6985
|
-
var
|
|
7147
|
+
var AggregatorClient22 = _AggregatorClient;
|
|
6986
7148
|
function findPythPriceIDs(routes) {
|
|
6987
7149
|
const priceIDs = /* @__PURE__ */ new Set();
|
|
6988
7150
|
for (const route of routes) {
|
|
@@ -7001,6 +7163,14 @@ function findPythPriceIDs(routes) {
|
|
|
7001
7163
|
priceIDs.add(path.extendedDetails.metastableETHPriceSeed);
|
|
7002
7164
|
}
|
|
7003
7165
|
}
|
|
7166
|
+
if (path.provider === OBRIC) {
|
|
7167
|
+
if (path.extendedDetails && path.extendedDetails.obricCoinAPriceSeed) {
|
|
7168
|
+
priceIDs.add(path.extendedDetails.obricCoinAPriceSeed);
|
|
7169
|
+
}
|
|
7170
|
+
if (path.extendedDetails && path.extendedDetails.obricCoinBPriceSeed) {
|
|
7171
|
+
priceIDs.add(path.extendedDetails.obricCoinBPriceSeed);
|
|
7172
|
+
}
|
|
7173
|
+
}
|
|
7004
7174
|
}
|
|
7005
7175
|
}
|
|
7006
7176
|
return Array.from(priceIDs);
|
|
@@ -7029,13 +7199,13 @@ function parseRouterResponse(data, byAmountIn) {
|
|
|
7029
7199
|
routes: data.routes.map((route) => {
|
|
7030
7200
|
return {
|
|
7031
7201
|
path: route.path.map((path) => {
|
|
7032
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
7202
|
+
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;
|
|
7033
7203
|
let version;
|
|
7034
7204
|
if (path.provider === AFTERMATH) {
|
|
7035
7205
|
version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
|
|
7036
7206
|
}
|
|
7037
7207
|
let extendedDetails;
|
|
7038
|
-
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) {
|
|
7208
|
+
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) {
|
|
7039
7209
|
extendedDetails = {
|
|
7040
7210
|
aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
|
|
7041
7211
|
turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
|
|
@@ -7057,7 +7227,11 @@ function parseRouterResponse(data, byAmountIn) {
|
|
|
7057
7227
|
metastableCreateCapPkgId: (_r = path.extended_details) == null ? void 0 : _r.metastable_create_cap_pkg_id,
|
|
7058
7228
|
metastableCreateCapModule: (_s = path.extended_details) == null ? void 0 : _s.metastable_create_cap_module,
|
|
7059
7229
|
metastableCreateCapAllTypeParams: (_t = path.extended_details) == null ? void 0 : _t.metastable_create_cap_all_type_params,
|
|
7060
|
-
metastableRegistryId: (_u = path.extended_details) == null ? void 0 : _u.metastable_registry_id
|
|
7230
|
+
metastableRegistryId: (_u = path.extended_details) == null ? void 0 : _u.metastable_registry_id,
|
|
7231
|
+
obricCoinAPriceSeed: (_v = path.extended_details) == null ? void 0 : _v.obric_coin_a_price_seed,
|
|
7232
|
+
obricCoinBPriceSeed: (_w = path.extended_details) == null ? void 0 : _w.obric_coin_b_price_seed,
|
|
7233
|
+
obricCoinAPriceId: (_x = path.extended_details) == null ? void 0 : _x.obric_coin_a_price_id,
|
|
7234
|
+
obricCoinBPriceId: (_y = path.extended_details) == null ? void 0 : _y.obric_coin_b_price_id
|
|
7061
7235
|
};
|
|
7062
7236
|
}
|
|
7063
7237
|
return {
|
|
@@ -7145,14 +7319,14 @@ function processEndpoint(endpoint) {
|
|
|
7145
7319
|
}
|
|
7146
7320
|
|
|
7147
7321
|
// src/api.ts
|
|
7148
|
-
var SDK_VERSION =
|
|
7149
|
-
function getRouterResult(endpoint, params) {
|
|
7322
|
+
var SDK_VERSION = 1000401;
|
|
7323
|
+
function getRouterResult(endpoint, apiKey, params) {
|
|
7150
7324
|
return __async(this, null, function* () {
|
|
7151
7325
|
let response;
|
|
7152
7326
|
if (params.liquidityChanges && params.liquidityChanges.length > 0) {
|
|
7153
7327
|
response = yield postRouterWithLiquidityChanges(endpoint, params);
|
|
7154
7328
|
} else {
|
|
7155
|
-
response = yield getRouter(endpoint, params);
|
|
7329
|
+
response = yield getRouter(endpoint, apiKey, params);
|
|
7156
7330
|
}
|
|
7157
7331
|
if (!response) {
|
|
7158
7332
|
return null;
|
|
@@ -7210,7 +7384,7 @@ function getRouterResult(endpoint, params) {
|
|
|
7210
7384
|
};
|
|
7211
7385
|
});
|
|
7212
7386
|
}
|
|
7213
|
-
function getRouter(endpoint, params) {
|
|
7387
|
+
function getRouter(endpoint, apiKey, params) {
|
|
7214
7388
|
return __async(this, null, function* () {
|
|
7215
7389
|
try {
|
|
7216
7390
|
const {
|
|
@@ -7244,6 +7418,9 @@ function getRouter(endpoint, params) {
|
|
|
7244
7418
|
url += `&providers=${providers.join(",")}`;
|
|
7245
7419
|
}
|
|
7246
7420
|
}
|
|
7421
|
+
if (apiKey.length > 0) {
|
|
7422
|
+
url += `&apiKey=${apiKey}`;
|
|
7423
|
+
}
|
|
7247
7424
|
url += `&v=${SDK_VERSION}`;
|
|
7248
7425
|
const response = yield fetch(url);
|
|
7249
7426
|
return response;
|
|
@@ -7340,7 +7517,7 @@ exports.AFTERMATH = AFTERMATH;
|
|
|
7340
7517
|
exports.AGGREGATOR_V2 = AGGREGATOR_V2;
|
|
7341
7518
|
exports.AGGREGATOR_V2_EXTEND = AGGREGATOR_V2_EXTEND;
|
|
7342
7519
|
exports.ALPHAFI = ALPHAFI;
|
|
7343
|
-
exports.AggregatorClient =
|
|
7520
|
+
exports.AggregatorClient = AggregatorClient22;
|
|
7344
7521
|
exports.BLUEFIN = BLUEFIN;
|
|
7345
7522
|
exports.BLUEMOVE = BLUEMOVE;
|
|
7346
7523
|
exports.CETUS = CETUS;
|
|
@@ -7356,6 +7533,7 @@ exports.HAEDALPMM = HAEDALPMM;
|
|
|
7356
7533
|
exports.KRIYA = KRIYA;
|
|
7357
7534
|
exports.KRIYAV3 = KRIYAV3;
|
|
7358
7535
|
exports.METASTABLE = METASTABLE;
|
|
7536
|
+
exports.OBRIC = OBRIC;
|
|
7359
7537
|
exports.ONE = ONE;
|
|
7360
7538
|
exports.SCALLOP = SCALLOP;
|
|
7361
7539
|
exports.SPRINGSUI = SPRINGSUI;
|