@cetusprotocol/aggregator-sdk 0.4.4 → 0.6.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/README.md +24 -8
- package/dist/index.d.mts +13 -5
- package/dist/index.d.ts +13 -5
- package/dist/index.js +334 -216
- package/dist/index.mjs +333 -216
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,10 +43,12 @@ npm install @cetusprotocol/aggregator-sdk
|
|
|
43
43
|
|
|
44
44
|
1. Fast init:
|
|
45
45
|
```typescript
|
|
46
|
-
const client = new AggregatorClient()
|
|
46
|
+
const client = new AggregatorClient({})
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
2. Full init:
|
|
50
|
+
> Note: overlayFeeRate and overlayFeeReceiver are used for additional fee logic beyond protocol fees, allowing project parties to collect extra fees.
|
|
51
|
+
|
|
50
52
|
```typescript
|
|
51
53
|
const client = new AggregatorClient({
|
|
52
54
|
// endpoint, // If you do not have a exclusive aggregator api domain,just use cetus default aggregator endpoints.
|
|
@@ -54,6 +56,9 @@ npm install @cetusprotocol/aggregator-sdk
|
|
|
54
56
|
client: suiClient,
|
|
55
57
|
env: Env.Mainnet,
|
|
56
58
|
pythUrls: ["YOUR_PYTH_URL", "ANOTHER_PYTH_URL"],
|
|
59
|
+
partner: "YOUR_PARTNER_ID", // Partner ID for fee sharing. Set once during initialization instead of per swap.
|
|
60
|
+
overlayFeeRate: 0.01, // Overlay fee rate (0.01 represents 1%). The denominator is 1000000, so 0.01% = 100
|
|
61
|
+
overlayFeeReceiver: "0x..", // Address to receive the overlay fees
|
|
57
62
|
})
|
|
58
63
|
```
|
|
59
64
|
**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.
|
|
@@ -75,7 +80,6 @@ const routers = await client.findRouters({
|
|
|
75
80
|
```
|
|
76
81
|
|
|
77
82
|
## 3. Confirm and do fast swap
|
|
78
|
-
|
|
79
83
|
```typescript
|
|
80
84
|
const routerTx = new Transaction()
|
|
81
85
|
|
|
@@ -85,16 +89,22 @@ if (routerRes != null) {
|
|
|
85
89
|
txb: routerTx,
|
|
86
90
|
slippage: 0.01,
|
|
87
91
|
isMergeTragetCoin: true,
|
|
88
|
-
refreshAllCoins: true
|
|
92
|
+
refreshAllCoins: true
|
|
89
93
|
})
|
|
90
94
|
|
|
91
95
|
let result = await client.devInspectTransactionBlock(routerTx, keypair)
|
|
92
96
|
|
|
93
97
|
if (result.effects.status.status === "success") {
|
|
94
|
-
console.log("
|
|
98
|
+
console.log("[Cetus] Transaction simulation successful")
|
|
95
99
|
const result = await client.signAndExecuteTransaction(routerTx, keypair)
|
|
100
|
+
console.log("[Cetus] Transaction executed successfully:", {
|
|
101
|
+
digest: result.digest,
|
|
102
|
+
status: result.effects?.status,
|
|
103
|
+
gasUsed: result.effects?.gasUsed
|
|
104
|
+
})
|
|
105
|
+
} else {
|
|
106
|
+
console.error("[Cetus] Transaction simulation failed:", result.effects?.status)
|
|
96
107
|
}
|
|
97
|
-
console.log("result", result)
|
|
98
108
|
}
|
|
99
109
|
```
|
|
100
110
|
|
|
@@ -113,7 +123,7 @@ if (routerRes != null) {
|
|
|
113
123
|
})
|
|
114
124
|
|
|
115
125
|
// you can use this target coin object argument to build your ptb.
|
|
116
|
-
|
|
126
|
+
client.transferOrDestroyCoin(
|
|
117
127
|
txb,
|
|
118
128
|
targetCoin,
|
|
119
129
|
targetCoinType
|
|
@@ -122,10 +132,16 @@ if (routerRes != null) {
|
|
|
122
132
|
let result = await client.devInspectTransactionBlock(routerTx, keypair)
|
|
123
133
|
|
|
124
134
|
if (result.effects.status.status === "success") {
|
|
125
|
-
console.log("
|
|
135
|
+
console.log("[Cetus] Transaction simulation successful")
|
|
126
136
|
const result = await client.signAndExecuteTransaction(routerTx, keypair)
|
|
137
|
+
console.log("[Cetus] Transaction executed successfully:", {
|
|
138
|
+
digest: result.digest,
|
|
139
|
+
status: result.effects?.status,
|
|
140
|
+
gasUsed: result.effects?.gasUsed
|
|
141
|
+
})
|
|
142
|
+
} else {
|
|
143
|
+
console.error("[Cetus] Transaction simulation failed:", result.effects?.status)
|
|
127
144
|
}
|
|
128
|
-
console.log("result", result)
|
|
129
145
|
}
|
|
130
146
|
```
|
|
131
147
|
|
package/dist/index.d.mts
CHANGED
|
@@ -83,6 +83,7 @@ declare const SPRINGSUI = "SPRINGSUI";
|
|
|
83
83
|
declare const STEAMM = "STEAMM";
|
|
84
84
|
declare const METASTABLE = "METASTABLE";
|
|
85
85
|
declare const OBRIC = "OBRIC";
|
|
86
|
+
declare const HAWAL = "HAWAL";
|
|
86
87
|
declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
87
88
|
type BuildRouterSwapParams = {
|
|
88
89
|
routers: Router[];
|
|
@@ -136,6 +137,9 @@ type AggregatorClientParams = {
|
|
|
136
137
|
env?: Env;
|
|
137
138
|
pythUrls?: string[];
|
|
138
139
|
apiKey?: string;
|
|
140
|
+
partner?: string;
|
|
141
|
+
overlayFeeRate?: number;
|
|
142
|
+
overlayFeeReceiver?: string;
|
|
139
143
|
};
|
|
140
144
|
declare class AggregatorClient {
|
|
141
145
|
endpoint: string;
|
|
@@ -146,13 +150,16 @@ declare class AggregatorClient {
|
|
|
146
150
|
private allCoins;
|
|
147
151
|
private pythConnections;
|
|
148
152
|
private pythClient;
|
|
153
|
+
private overlayFeeRate;
|
|
154
|
+
private overlayFeeReceiver;
|
|
155
|
+
private partner?;
|
|
149
156
|
private static readonly CONFIG;
|
|
150
157
|
constructor(params: AggregatorClientParams);
|
|
151
158
|
newPythClients(pythUrls: string[]): SuiPriceServiceConnection[];
|
|
152
159
|
getCoins(coinType: string, refresh?: boolean): Promise<CoinAsset[]>;
|
|
153
160
|
findRouters(params: FindRouterParams): Promise<RouterData | null>;
|
|
154
|
-
executeFlexibleInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[],
|
|
155
|
-
expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[],
|
|
161
|
+
executeFlexibleInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], expectedAmountOut: string, amountLimit: string, pythPriceIDs: Map<string, string>, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
|
|
162
|
+
expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], expectedAmountOut: string, amountLimit: string, pythPriceIDs: Map<string, string>, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
|
|
156
163
|
expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
|
|
157
164
|
swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResult | null>;
|
|
158
165
|
routerSwap(params: BuildRouterSwapParams | BuildRouterSwapParamsV2): Promise<TransactionObjectArgument>;
|
|
@@ -162,7 +169,7 @@ declare class AggregatorClient {
|
|
|
162
169
|
publishedAtV2Extend(): string;
|
|
163
170
|
deepbookv3DeepFeeType(): string;
|
|
164
171
|
transferOrDestoryCoin(txb: Transaction, coin: TransactionObjectArgument, coinType: string, aggregatorV2PublishedAt: string): void;
|
|
165
|
-
checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string,
|
|
172
|
+
checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, expectedAmountOut: string, threshold: string, aggregatorV2ExtendPublishedAt: string): TransactionObjectArgument;
|
|
166
173
|
newDex(provider: string, pythPriceIDs: Map<string, string>, partner?: string): Dex;
|
|
167
174
|
signAndExecuteTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiTransactionBlockResponse>;
|
|
168
175
|
devInspectTransactionBlock(txb: Transaction): Promise<_mysten_sui_client.DevInspectResults>;
|
|
@@ -301,13 +308,14 @@ type RouterData = {
|
|
|
301
308
|
packages?: Map<string, string>;
|
|
302
309
|
totalDeepFee?: number;
|
|
303
310
|
error?: RouterError;
|
|
311
|
+
overlayFee?: number;
|
|
304
312
|
};
|
|
305
313
|
type AggregatorResponse = {
|
|
306
314
|
code: number;
|
|
307
315
|
msg: string;
|
|
308
316
|
data: RouterData;
|
|
309
317
|
};
|
|
310
|
-
declare function getRouterResult(endpoint: string, apiKey: string, params: FindRouterParams): Promise<RouterData | null>;
|
|
318
|
+
declare function getRouterResult(endpoint: string, apiKey: string, params: FindRouterParams, overlayFee: number, overlayFeeReceiver: string): Promise<RouterData | null>;
|
|
311
319
|
type DeepbookV3Config = {
|
|
312
320
|
id: string;
|
|
313
321
|
is_alternative_payment: boolean;
|
|
@@ -332,4 +340,4 @@ declare enum Env {
|
|
|
332
340
|
Testnet = 1
|
|
333
341
|
}
|
|
334
342
|
|
|
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 };
|
|
343
|
+
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, HAWAL, 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
|
@@ -83,6 +83,7 @@ declare const SPRINGSUI = "SPRINGSUI";
|
|
|
83
83
|
declare const STEAMM = "STEAMM";
|
|
84
84
|
declare const METASTABLE = "METASTABLE";
|
|
85
85
|
declare const OBRIC = "OBRIC";
|
|
86
|
+
declare const HAWAL = "HAWAL";
|
|
86
87
|
declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
87
88
|
type BuildRouterSwapParams = {
|
|
88
89
|
routers: Router[];
|
|
@@ -136,6 +137,9 @@ type AggregatorClientParams = {
|
|
|
136
137
|
env?: Env;
|
|
137
138
|
pythUrls?: string[];
|
|
138
139
|
apiKey?: string;
|
|
140
|
+
partner?: string;
|
|
141
|
+
overlayFeeRate?: number;
|
|
142
|
+
overlayFeeReceiver?: string;
|
|
139
143
|
};
|
|
140
144
|
declare class AggregatorClient {
|
|
141
145
|
endpoint: string;
|
|
@@ -146,13 +150,16 @@ declare class AggregatorClient {
|
|
|
146
150
|
private allCoins;
|
|
147
151
|
private pythConnections;
|
|
148
152
|
private pythClient;
|
|
153
|
+
private overlayFeeRate;
|
|
154
|
+
private overlayFeeReceiver;
|
|
155
|
+
private partner?;
|
|
149
156
|
private static readonly CONFIG;
|
|
150
157
|
constructor(params: AggregatorClientParams);
|
|
151
158
|
newPythClients(pythUrls: string[]): SuiPriceServiceConnection[];
|
|
152
159
|
getCoins(coinType: string, refresh?: boolean): Promise<CoinAsset[]>;
|
|
153
160
|
findRouters(params: FindRouterParams): Promise<RouterData | null>;
|
|
154
|
-
executeFlexibleInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[],
|
|
155
|
-
expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[],
|
|
161
|
+
executeFlexibleInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], expectedAmountOut: string, amountLimit: string, pythPriceIDs: Map<string, string>, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
|
|
162
|
+
expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], expectedAmountOut: string, amountLimit: string, pythPriceIDs: Map<string, string>, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
|
|
156
163
|
expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
|
|
157
164
|
swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResult | null>;
|
|
158
165
|
routerSwap(params: BuildRouterSwapParams | BuildRouterSwapParamsV2): Promise<TransactionObjectArgument>;
|
|
@@ -162,7 +169,7 @@ declare class AggregatorClient {
|
|
|
162
169
|
publishedAtV2Extend(): string;
|
|
163
170
|
deepbookv3DeepFeeType(): string;
|
|
164
171
|
transferOrDestoryCoin(txb: Transaction, coin: TransactionObjectArgument, coinType: string, aggregatorV2PublishedAt: string): void;
|
|
165
|
-
checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string,
|
|
172
|
+
checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, expectedAmountOut: string, threshold: string, aggregatorV2ExtendPublishedAt: string): TransactionObjectArgument;
|
|
166
173
|
newDex(provider: string, pythPriceIDs: Map<string, string>, partner?: string): Dex;
|
|
167
174
|
signAndExecuteTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiTransactionBlockResponse>;
|
|
168
175
|
devInspectTransactionBlock(txb: Transaction): Promise<_mysten_sui_client.DevInspectResults>;
|
|
@@ -301,13 +308,14 @@ type RouterData = {
|
|
|
301
308
|
packages?: Map<string, string>;
|
|
302
309
|
totalDeepFee?: number;
|
|
303
310
|
error?: RouterError;
|
|
311
|
+
overlayFee?: number;
|
|
304
312
|
};
|
|
305
313
|
type AggregatorResponse = {
|
|
306
314
|
code: number;
|
|
307
315
|
msg: string;
|
|
308
316
|
data: RouterData;
|
|
309
317
|
};
|
|
310
|
-
declare function getRouterResult(endpoint: string, apiKey: string, params: FindRouterParams): Promise<RouterData | null>;
|
|
318
|
+
declare function getRouterResult(endpoint: string, apiKey: string, params: FindRouterParams, overlayFee: number, overlayFeeReceiver: string): Promise<RouterData | null>;
|
|
311
319
|
type DeepbookV3Config = {
|
|
312
320
|
id: string;
|
|
313
321
|
is_alternative_payment: boolean;
|
|
@@ -332,4 +340,4 @@ declare enum Env {
|
|
|
332
340
|
Testnet = 1
|
|
333
341
|
}
|
|
334
342
|
|
|
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 };
|
|
343
|
+
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, HAWAL, 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 };
|