@cetusprotocol/aggregator-sdk 0.0.0-experimental-20241012180800 → 0.0.0-experimental-20241018181235
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 +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +20 -26
- package/dist/index.mjs +20 -26
- package/dist/src/client.d.ts +1 -0
- package/dist/tests/test_data.test.d.ts +1 -0
- package/package.json +1 -1
- package/src/client.ts +16 -18
- package/src/transaction/deepbook_v3.ts +3 -8
- package/src/transaction/swap.ts +6 -0
- package/src/utils/coin.ts +1 -1
- package/tests/router.test.ts +20 -32
- package/tests/test_data.test.ts +1 -0
package/dist/index.d.mts
CHANGED
|
@@ -118,6 +118,7 @@ declare class AggregatorClient {
|
|
|
118
118
|
routerSwap(params: BuildRouterSwapParams): Promise<TransactionObjectArgument>;
|
|
119
119
|
fastRouterSwap(params: BuildFastRouterSwapParams): Promise<void>;
|
|
120
120
|
publishedAt(): string;
|
|
121
|
+
publishedV2At(): string;
|
|
121
122
|
deepbookv3DeepFeeType(): string;
|
|
122
123
|
transferOrDestoryCoin(txb: Transaction, coin: TransactionObjectArgument, coinType: string): void;
|
|
123
124
|
checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, amountLimit: BN): TransactionObjectArgument;
|
package/dist/index.d.ts
CHANGED
|
@@ -118,6 +118,7 @@ declare class AggregatorClient {
|
|
|
118
118
|
routerSwap(params: BuildRouterSwapParams): Promise<TransactionObjectArgument>;
|
|
119
119
|
fastRouterSwap(params: BuildFastRouterSwapParams): Promise<void>;
|
|
120
120
|
publishedAt(): string;
|
|
121
|
+
publishedV2At(): string;
|
|
121
122
|
deepbookv3DeepFeeType(): string;
|
|
122
123
|
transferOrDestoryCoin(txb: Transaction, coin: TransactionObjectArgument, coinType: string): void;
|
|
123
124
|
checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, amountLimit: BN): TransactionObjectArgument;
|
package/dist/index.js
CHANGED
|
@@ -5677,7 +5677,7 @@ function buildInputCoin(txb, allCoins, amount, coinType) {
|
|
|
5677
5677
|
if (totalCoinBalance < amount) {
|
|
5678
5678
|
throw new AggregateError(
|
|
5679
5679
|
"Insufficient balance when build merge coin, coinType: " + coinType,
|
|
5680
|
-
"InsufficientBalance" /* InsufficientBalance */
|
|
5680
|
+
"InsufficientBalance" /* InsufficientBalance */ + coinType
|
|
5681
5681
|
);
|
|
5682
5682
|
}
|
|
5683
5683
|
if (CoinUtils.isSuiCoin(coinType)) {
|
|
@@ -5775,6 +5775,8 @@ function swapInPools(client, params, sender) {
|
|
|
5775
5775
|
const coinA = direction ? fromCoin : targetCoin;
|
|
5776
5776
|
const coinB = direction ? targetCoin : fromCoin;
|
|
5777
5777
|
const typeArguments = [coinA, coinB];
|
|
5778
|
+
console.log("typeArguments", typeArguments);
|
|
5779
|
+
console.log("pools", pools);
|
|
5778
5780
|
for (let i = 0; i < pools.length; i++) {
|
|
5779
5781
|
const args = [
|
|
5780
5782
|
tx.object(pools[i]),
|
|
@@ -5799,6 +5801,7 @@ function swapInPools(client, params, sender) {
|
|
|
5799
5801
|
sender
|
|
5800
5802
|
});
|
|
5801
5803
|
if (simulateRes.error != null) {
|
|
5804
|
+
console.log("simulateRes.error", simulateRes.error);
|
|
5802
5805
|
throw new AggregateError(
|
|
5803
5806
|
"Aggregator package not set",
|
|
5804
5807
|
"SimulateError" /* SimulateError */
|
|
@@ -6005,22 +6008,16 @@ var Bluemove = class {
|
|
|
6005
6008
|
// src/transaction/deepbook_v3.ts
|
|
6006
6009
|
var DeepbookV3 = class {
|
|
6007
6010
|
constructor(env) {
|
|
6008
|
-
this.deepbookV3Config = env === 0 /* Mainnet */ ? "
|
|
6011
|
+
this.deepbookV3Config = env === 0 /* Mainnet */ ? "0xfdedcb665bc9a18f2fb355a80a4744be58acf043d5f65d9b4c98ac64e87da7d6" : "0xe19b5d072346cae83a037d4e3c8492068a74410a74e5830b3a68012db38296aa";
|
|
6009
6012
|
this.deepCoinType = env === 0 /* Mainnet */ ? "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP" : "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP";
|
|
6010
6013
|
}
|
|
6011
6014
|
swap(client, txb, path, inputCoin, deepbookv3DeepFee) {
|
|
6012
6015
|
return __async(this, null, function* () {
|
|
6013
|
-
var _a, _b, _c;
|
|
6014
6016
|
const { direction, from, target } = path;
|
|
6015
6017
|
const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", target, from];
|
|
6016
6018
|
let deepFee;
|
|
6017
6019
|
if (deepbookv3DeepFee) {
|
|
6018
|
-
|
|
6019
|
-
const splitAmounts = [(_c = path.extendedDetails) == null ? void 0 : _c.deepbookv3DeepFee];
|
|
6020
|
-
deepFee = txb.splitCoins(deepbookv3DeepFee, splitAmounts)[0];
|
|
6021
|
-
} else {
|
|
6022
|
-
deepFee = mintZeroCoin(txb, this.deepCoinType);
|
|
6023
|
-
}
|
|
6020
|
+
deepFee = deepbookv3DeepFee;
|
|
6024
6021
|
} else {
|
|
6025
6022
|
deepFee = mintZeroCoin(txb, this.deepCoinType);
|
|
6026
6023
|
}
|
|
@@ -6032,7 +6029,7 @@ var DeepbookV3 = class {
|
|
|
6032
6029
|
txb.object(CLOCK_ADDRESS)
|
|
6033
6030
|
];
|
|
6034
6031
|
const res = txb.moveCall({
|
|
6035
|
-
target: `${client.
|
|
6032
|
+
target: `${client.publishedV2At()}::deepbookv3::${func}`,
|
|
6036
6033
|
typeArguments: [coinAType, coinBType],
|
|
6037
6034
|
arguments: args
|
|
6038
6035
|
});
|
|
@@ -6116,9 +6113,6 @@ var AggregatorClient7 = class {
|
|
|
6116
6113
|
outputCoins.push(nextCoin);
|
|
6117
6114
|
}
|
|
6118
6115
|
this.transferOrDestoryCoin(txb, inputCoin, inputCoinType);
|
|
6119
|
-
if (deepbookv3DeepFee) {
|
|
6120
|
-
this.transferOrDestoryCoin(txb, deepbookv3DeepFee, this.deepbookv3DeepFeeType());
|
|
6121
|
-
}
|
|
6122
6116
|
const mergedTargetCointhis = this.checkCoinThresholdAndMergeCoin(
|
|
6123
6117
|
txb,
|
|
6124
6118
|
outputCoins,
|
|
@@ -6267,21 +6261,14 @@ var AggregatorClient7 = class {
|
|
|
6267
6261
|
BigInt(amount.toString()),
|
|
6268
6262
|
fromCoinType
|
|
6269
6263
|
);
|
|
6270
|
-
let
|
|
6264
|
+
let deepCoin;
|
|
6271
6265
|
if (payDeepFeeAmount && payDeepFeeAmount > 0) {
|
|
6272
|
-
|
|
6266
|
+
deepCoin = buildInputCoin(
|
|
6273
6267
|
txb,
|
|
6274
6268
|
this.allCoins,
|
|
6275
6269
|
BigInt(payDeepFeeAmount),
|
|
6276
6270
|
this.deepbookv3DeepFeeType()
|
|
6277
|
-
);
|
|
6278
|
-
} else {
|
|
6279
|
-
buildDeepFeeCoinRes = buildInputCoin(
|
|
6280
|
-
txb,
|
|
6281
|
-
this.allCoins,
|
|
6282
|
-
BigInt(0),
|
|
6283
|
-
this.deepbookv3DeepFeeType()
|
|
6284
|
-
);
|
|
6271
|
+
).targetCoin;
|
|
6285
6272
|
}
|
|
6286
6273
|
const targetCoin = yield this.routerSwap({
|
|
6287
6274
|
routers,
|
|
@@ -6290,7 +6277,7 @@ var AggregatorClient7 = class {
|
|
|
6290
6277
|
byAmountIn,
|
|
6291
6278
|
txb,
|
|
6292
6279
|
partner,
|
|
6293
|
-
deepbookv3DeepFee:
|
|
6280
|
+
deepbookv3DeepFee: deepCoin
|
|
6294
6281
|
});
|
|
6295
6282
|
if (isMergeTragetCoin) {
|
|
6296
6283
|
const targetCoinRes = buildInputCoin(
|
|
@@ -6314,9 +6301,16 @@ var AggregatorClient7 = class {
|
|
|
6314
6301
|
}
|
|
6315
6302
|
publishedAt() {
|
|
6316
6303
|
if (this.env === 0 /* Mainnet */) {
|
|
6317
|
-
return "
|
|
6304
|
+
return "0x868a192f542e819de99f8f289d7d6b47126e5da3103108fbc01d16cfd6be569a";
|
|
6305
|
+
} else {
|
|
6306
|
+
return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637";
|
|
6307
|
+
}
|
|
6308
|
+
}
|
|
6309
|
+
publishedV2At() {
|
|
6310
|
+
if (this.env === 0 /* Mainnet */) {
|
|
6311
|
+
return "0x43ddba51e679811ea575c86bf0e0877015eef4d14320cc36c33847d06cf2bffe";
|
|
6318
6312
|
} else {
|
|
6319
|
-
return "
|
|
6313
|
+
return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637";
|
|
6320
6314
|
}
|
|
6321
6315
|
}
|
|
6322
6316
|
deepbookv3DeepFeeType() {
|
package/dist/index.mjs
CHANGED
|
@@ -5675,7 +5675,7 @@ function buildInputCoin(txb, allCoins, amount, coinType) {
|
|
|
5675
5675
|
if (totalCoinBalance < amount) {
|
|
5676
5676
|
throw new AggregateError(
|
|
5677
5677
|
"Insufficient balance when build merge coin, coinType: " + coinType,
|
|
5678
|
-
"InsufficientBalance" /* InsufficientBalance */
|
|
5678
|
+
"InsufficientBalance" /* InsufficientBalance */ + coinType
|
|
5679
5679
|
);
|
|
5680
5680
|
}
|
|
5681
5681
|
if (CoinUtils.isSuiCoin(coinType)) {
|
|
@@ -5773,6 +5773,8 @@ function swapInPools(client, params, sender) {
|
|
|
5773
5773
|
const coinA = direction ? fromCoin : targetCoin;
|
|
5774
5774
|
const coinB = direction ? targetCoin : fromCoin;
|
|
5775
5775
|
const typeArguments = [coinA, coinB];
|
|
5776
|
+
console.log("typeArguments", typeArguments);
|
|
5777
|
+
console.log("pools", pools);
|
|
5776
5778
|
for (let i = 0; i < pools.length; i++) {
|
|
5777
5779
|
const args = [
|
|
5778
5780
|
tx.object(pools[i]),
|
|
@@ -5797,6 +5799,7 @@ function swapInPools(client, params, sender) {
|
|
|
5797
5799
|
sender
|
|
5798
5800
|
});
|
|
5799
5801
|
if (simulateRes.error != null) {
|
|
5802
|
+
console.log("simulateRes.error", simulateRes.error);
|
|
5800
5803
|
throw new AggregateError(
|
|
5801
5804
|
"Aggregator package not set",
|
|
5802
5805
|
"SimulateError" /* SimulateError */
|
|
@@ -6003,22 +6006,16 @@ var Bluemove = class {
|
|
|
6003
6006
|
// src/transaction/deepbook_v3.ts
|
|
6004
6007
|
var DeepbookV3 = class {
|
|
6005
6008
|
constructor(env) {
|
|
6006
|
-
this.deepbookV3Config = env === 0 /* Mainnet */ ? "
|
|
6009
|
+
this.deepbookV3Config = env === 0 /* Mainnet */ ? "0xfdedcb665bc9a18f2fb355a80a4744be58acf043d5f65d9b4c98ac64e87da7d6" : "0xe19b5d072346cae83a037d4e3c8492068a74410a74e5830b3a68012db38296aa";
|
|
6007
6010
|
this.deepCoinType = env === 0 /* Mainnet */ ? "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP" : "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP";
|
|
6008
6011
|
}
|
|
6009
6012
|
swap(client, txb, path, inputCoin, deepbookv3DeepFee) {
|
|
6010
6013
|
return __async(this, null, function* () {
|
|
6011
|
-
var _a, _b, _c;
|
|
6012
6014
|
const { direction, from, target } = path;
|
|
6013
6015
|
const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", target, from];
|
|
6014
6016
|
let deepFee;
|
|
6015
6017
|
if (deepbookv3DeepFee) {
|
|
6016
|
-
|
|
6017
|
-
const splitAmounts = [(_c = path.extendedDetails) == null ? void 0 : _c.deepbookv3DeepFee];
|
|
6018
|
-
deepFee = txb.splitCoins(deepbookv3DeepFee, splitAmounts)[0];
|
|
6019
|
-
} else {
|
|
6020
|
-
deepFee = mintZeroCoin(txb, this.deepCoinType);
|
|
6021
|
-
}
|
|
6018
|
+
deepFee = deepbookv3DeepFee;
|
|
6022
6019
|
} else {
|
|
6023
6020
|
deepFee = mintZeroCoin(txb, this.deepCoinType);
|
|
6024
6021
|
}
|
|
@@ -6030,7 +6027,7 @@ var DeepbookV3 = class {
|
|
|
6030
6027
|
txb.object(CLOCK_ADDRESS)
|
|
6031
6028
|
];
|
|
6032
6029
|
const res = txb.moveCall({
|
|
6033
|
-
target: `${client.
|
|
6030
|
+
target: `${client.publishedV2At()}::deepbookv3::${func}`,
|
|
6034
6031
|
typeArguments: [coinAType, coinBType],
|
|
6035
6032
|
arguments: args
|
|
6036
6033
|
});
|
|
@@ -6114,9 +6111,6 @@ var AggregatorClient7 = class {
|
|
|
6114
6111
|
outputCoins.push(nextCoin);
|
|
6115
6112
|
}
|
|
6116
6113
|
this.transferOrDestoryCoin(txb, inputCoin, inputCoinType);
|
|
6117
|
-
if (deepbookv3DeepFee) {
|
|
6118
|
-
this.transferOrDestoryCoin(txb, deepbookv3DeepFee, this.deepbookv3DeepFeeType());
|
|
6119
|
-
}
|
|
6120
6114
|
const mergedTargetCointhis = this.checkCoinThresholdAndMergeCoin(
|
|
6121
6115
|
txb,
|
|
6122
6116
|
outputCoins,
|
|
@@ -6265,21 +6259,14 @@ var AggregatorClient7 = class {
|
|
|
6265
6259
|
BigInt(amount.toString()),
|
|
6266
6260
|
fromCoinType
|
|
6267
6261
|
);
|
|
6268
|
-
let
|
|
6262
|
+
let deepCoin;
|
|
6269
6263
|
if (payDeepFeeAmount && payDeepFeeAmount > 0) {
|
|
6270
|
-
|
|
6264
|
+
deepCoin = buildInputCoin(
|
|
6271
6265
|
txb,
|
|
6272
6266
|
this.allCoins,
|
|
6273
6267
|
BigInt(payDeepFeeAmount),
|
|
6274
6268
|
this.deepbookv3DeepFeeType()
|
|
6275
|
-
);
|
|
6276
|
-
} else {
|
|
6277
|
-
buildDeepFeeCoinRes = buildInputCoin(
|
|
6278
|
-
txb,
|
|
6279
|
-
this.allCoins,
|
|
6280
|
-
BigInt(0),
|
|
6281
|
-
this.deepbookv3DeepFeeType()
|
|
6282
|
-
);
|
|
6269
|
+
).targetCoin;
|
|
6283
6270
|
}
|
|
6284
6271
|
const targetCoin = yield this.routerSwap({
|
|
6285
6272
|
routers,
|
|
@@ -6288,7 +6275,7 @@ var AggregatorClient7 = class {
|
|
|
6288
6275
|
byAmountIn,
|
|
6289
6276
|
txb,
|
|
6290
6277
|
partner,
|
|
6291
|
-
deepbookv3DeepFee:
|
|
6278
|
+
deepbookv3DeepFee: deepCoin
|
|
6292
6279
|
});
|
|
6293
6280
|
if (isMergeTragetCoin) {
|
|
6294
6281
|
const targetCoinRes = buildInputCoin(
|
|
@@ -6312,9 +6299,16 @@ var AggregatorClient7 = class {
|
|
|
6312
6299
|
}
|
|
6313
6300
|
publishedAt() {
|
|
6314
6301
|
if (this.env === 0 /* Mainnet */) {
|
|
6315
|
-
return "
|
|
6302
|
+
return "0x868a192f542e819de99f8f289d7d6b47126e5da3103108fbc01d16cfd6be569a";
|
|
6303
|
+
} else {
|
|
6304
|
+
return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637";
|
|
6305
|
+
}
|
|
6306
|
+
}
|
|
6307
|
+
publishedV2At() {
|
|
6308
|
+
if (this.env === 0 /* Mainnet */) {
|
|
6309
|
+
return "0x43ddba51e679811ea575c86bf0e0877015eef4d14320cc36c33847d06cf2bffe";
|
|
6316
6310
|
} else {
|
|
6317
|
-
return "
|
|
6311
|
+
return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637";
|
|
6318
6312
|
}
|
|
6319
6313
|
}
|
|
6320
6314
|
deepbookv3DeepFeeType() {
|
package/dist/src/client.d.ts
CHANGED
|
@@ -62,6 +62,7 @@ export declare class AggregatorClient {
|
|
|
62
62
|
routerSwap(params: BuildRouterSwapParams): Promise<TransactionObjectArgument>;
|
|
63
63
|
fastRouterSwap(params: BuildFastRouterSwapParams): Promise<void>;
|
|
64
64
|
publishedAt(): string;
|
|
65
|
+
publishedV2At(): string;
|
|
65
66
|
deepbookv3DeepFeeType(): string;
|
|
66
67
|
transferOrDestoryCoin(txb: Transaction, coin: TransactionObjectArgument, coinType: string): void;
|
|
67
68
|
checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, amountLimit: BN): TransactionObjectArgument;
|
|
@@ -10,3 +10,4 @@ export declare const M_VSUI = "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2
|
|
|
10
10
|
export declare const M_VAPOR = "0xa1f2c11169f32165ad4efb4468ec5bdfc880cd66b22094024b32ab7b76d14d30::vapor::VAPOR";
|
|
11
11
|
export declare const M_HASUI = "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI";
|
|
12
12
|
export declare const M_SSWP = "0x361dd589b98e8fcda9a7ee53b85efabef3569d00416640d2faa516e3801d7ffc::TOKEN::TOKEN";
|
|
13
|
+
export declare const M_MICHI = "0x50d796fde5709a97883e29e00bf511d66f2656de958ea0c2ce4c1147cdd20a23::MICHI::MICHI";
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -36,7 +36,7 @@ import { Afsui } from "./transaction/afsui"
|
|
|
36
36
|
import { Volo } from "./transaction/volo"
|
|
37
37
|
import { Bluemove } from "./transaction/bluemove"
|
|
38
38
|
import { CoinAsset } from "./types/sui"
|
|
39
|
-
import { buildInputCoin } from "./utils/coin"
|
|
39
|
+
import { buildInputCoin, mintZeroCoin } from "./utils/coin"
|
|
40
40
|
import { DeepbookV3 } from "./transaction/deepbook_v3"
|
|
41
41
|
|
|
42
42
|
export const CETUS = "CETUS"
|
|
@@ -62,7 +62,7 @@ export type BuildRouterSwapParams = {
|
|
|
62
62
|
partner?: string
|
|
63
63
|
// This parameter is used to pass the Deep token object. When using the DeepBook V3 provider,
|
|
64
64
|
// users must pay fees with Deep tokens in non-whitelisted pools.
|
|
65
|
-
deepbookv3DeepFee?: TransactionObjectArgument
|
|
65
|
+
deepbookv3DeepFee?: TransactionObjectArgument
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
export type BuildFastRouterSwapParams = {
|
|
@@ -162,9 +162,6 @@ export class AggregatorClient {
|
|
|
162
162
|
outputCoins.push(nextCoin)
|
|
163
163
|
}
|
|
164
164
|
this.transferOrDestoryCoin(txb, inputCoin, inputCoinType)
|
|
165
|
-
if (deepbookv3DeepFee) {
|
|
166
|
-
this.transferOrDestoryCoin(txb, deepbookv3DeepFee, this.deepbookv3DeepFeeType())
|
|
167
|
-
}
|
|
168
165
|
const mergedTargetCointhis = this.checkCoinThresholdAndMergeCoin(
|
|
169
166
|
txb,
|
|
170
167
|
outputCoins,
|
|
@@ -324,21 +321,14 @@ export class AggregatorClient {
|
|
|
324
321
|
fromCoinType
|
|
325
322
|
)
|
|
326
323
|
|
|
327
|
-
let
|
|
324
|
+
let deepCoin
|
|
328
325
|
if (payDeepFeeAmount && payDeepFeeAmount > 0) {
|
|
329
|
-
|
|
326
|
+
deepCoin = buildInputCoin(
|
|
330
327
|
txb,
|
|
331
328
|
this.allCoins,
|
|
332
329
|
BigInt(payDeepFeeAmount),
|
|
333
330
|
this.deepbookv3DeepFeeType()
|
|
334
|
-
)
|
|
335
|
-
} else {
|
|
336
|
-
buildDeepFeeCoinRes = buildInputCoin(
|
|
337
|
-
txb,
|
|
338
|
-
this.allCoins,
|
|
339
|
-
BigInt(0),
|
|
340
|
-
this.deepbookv3DeepFeeType()
|
|
341
|
-
)
|
|
331
|
+
).targetCoin
|
|
342
332
|
}
|
|
343
333
|
|
|
344
334
|
const targetCoin = await this.routerSwap({
|
|
@@ -348,7 +338,7 @@ export class AggregatorClient {
|
|
|
348
338
|
byAmountIn,
|
|
349
339
|
txb,
|
|
350
340
|
partner,
|
|
351
|
-
deepbookv3DeepFee:
|
|
341
|
+
deepbookv3DeepFee: deepCoin,
|
|
352
342
|
})
|
|
353
343
|
|
|
354
344
|
if (isMergeTragetCoin) {
|
|
@@ -373,9 +363,17 @@ export class AggregatorClient {
|
|
|
373
363
|
|
|
374
364
|
publishedAt(): string {
|
|
375
365
|
if (this.env === Env.Mainnet) {
|
|
376
|
-
return "
|
|
366
|
+
return "0x868a192f542e819de99f8f289d7d6b47126e5da3103108fbc01d16cfd6be569a"
|
|
367
|
+
} else {
|
|
368
|
+
return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637"
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
publishedV2At(): string {
|
|
373
|
+
if (this.env === Env.Mainnet) {
|
|
374
|
+
return "0x43ddba51e679811ea575c86bf0e0877015eef4d14320cc36c33847d06cf2bffe"
|
|
377
375
|
} else {
|
|
378
|
-
return "
|
|
376
|
+
return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637"
|
|
379
377
|
}
|
|
380
378
|
}
|
|
381
379
|
|
|
@@ -19,7 +19,7 @@ export class DeepbookV3 implements Dex {
|
|
|
19
19
|
constructor(env: Env) {
|
|
20
20
|
this.deepbookV3Config =
|
|
21
21
|
env === Env.Mainnet
|
|
22
|
-
? "
|
|
22
|
+
? "0xfdedcb665bc9a18f2fb355a80a4744be58acf043d5f65d9b4c98ac64e87da7d6"
|
|
23
23
|
: "0xe19b5d072346cae83a037d4e3c8492068a74410a74e5830b3a68012db38296aa"
|
|
24
24
|
this.deepCoinType =
|
|
25
25
|
env === Env.Mainnet
|
|
@@ -41,12 +41,7 @@ export class DeepbookV3 implements Dex {
|
|
|
41
41
|
|
|
42
42
|
let deepFee
|
|
43
43
|
if (deepbookv3DeepFee) {
|
|
44
|
-
|
|
45
|
-
const splitAmounts = [path.extendedDetails?.deepbookv3DeepFee]
|
|
46
|
-
deepFee = txb.splitCoins(deepbookv3DeepFee, splitAmounts)[0] as TransactionObjectArgument
|
|
47
|
-
} else {
|
|
48
|
-
deepFee = mintZeroCoin(txb, this.deepCoinType)
|
|
49
|
-
}
|
|
44
|
+
deepFee = deepbookv3DeepFee
|
|
50
45
|
} else {
|
|
51
46
|
deepFee = mintZeroCoin(txb, this.deepCoinType)
|
|
52
47
|
}
|
|
@@ -59,7 +54,7 @@ export class DeepbookV3 implements Dex {
|
|
|
59
54
|
txb.object(CLOCK_ADDRESS),
|
|
60
55
|
]
|
|
61
56
|
const res = txb.moveCall({
|
|
62
|
-
target: `${client.
|
|
57
|
+
target: `${client.publishedV2At()}::deepbookv3::${func}`,
|
|
63
58
|
typeArguments: [coinAType, coinBType],
|
|
64
59
|
arguments: args,
|
|
65
60
|
}) as TransactionArgument
|
package/src/transaction/swap.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { checkInvalidSuiAddress } from "~/utils/transaction"
|
|
|
7
7
|
import { SuiClient } from "@mysten/sui/client"
|
|
8
8
|
import { BN } from "bn.js"
|
|
9
9
|
import { sqrtPriceX64ToPrice } from "~/math"
|
|
10
|
+
import { error } from "console"
|
|
10
11
|
|
|
11
12
|
export async function swapInPools(
|
|
12
13
|
client: SuiClient,
|
|
@@ -25,6 +26,10 @@ export async function swapInPools(
|
|
|
25
26
|
const coinB = direction ? targetCoin : fromCoin
|
|
26
27
|
|
|
27
28
|
const typeArguments = [coinA, coinB]
|
|
29
|
+
console.log("typeArguments", typeArguments)
|
|
30
|
+
|
|
31
|
+
console.log("pools", pools)
|
|
32
|
+
|
|
28
33
|
for (let i = 0; i < pools.length; i++) {
|
|
29
34
|
const args = [
|
|
30
35
|
tx.object(pools[i]),
|
|
@@ -51,6 +56,7 @@ export async function swapInPools(
|
|
|
51
56
|
sender,
|
|
52
57
|
})
|
|
53
58
|
if (simulateRes.error != null) {
|
|
59
|
+
console.log("simulateRes.error", simulateRes.error)
|
|
54
60
|
throw new AggregateError(
|
|
55
61
|
"Aggregator package not set",
|
|
56
62
|
ConfigErrorCode.SimulateError
|
package/src/utils/coin.ts
CHANGED
|
@@ -77,7 +77,7 @@ export function buildInputCoin(
|
|
|
77
77
|
if (totalCoinBalance < amount) {
|
|
78
78
|
throw new AggregateError(
|
|
79
79
|
"Insufficient balance when build merge coin, coinType: " + coinType,
|
|
80
|
-
TransactionErrorCode.InsufficientBalance
|
|
80
|
+
TransactionErrorCode.InsufficientBalance + coinType
|
|
81
81
|
)
|
|
82
82
|
}
|
|
83
83
|
|
package/tests/router.test.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { AggregatorClient } from "~/client"
|
|
|
4
4
|
import {
|
|
5
5
|
M_CETUS,
|
|
6
6
|
M_HASUI,
|
|
7
|
+
M_MICHI,
|
|
7
8
|
M_NAVI,
|
|
8
9
|
M_SSWP,
|
|
9
10
|
M_SUI,
|
|
@@ -47,38 +48,23 @@ describe("router module", () => {
|
|
|
47
48
|
|
|
48
49
|
// console.log("wallet", wallet, "\n", wallet.toString())
|
|
49
50
|
|
|
50
|
-
const wallet =
|
|
51
|
-
"0xf7b8d77dd06a6bb51c37ad3ce69e0a44c6f1064f52ac54606ef47763c8a71be6"
|
|
52
51
|
// const wallet =
|
|
53
|
-
|
|
52
|
+
// "0x2a6174f94a2c1d648de290297be27867527a6aaa263a4e0a567c9cd7656d3651"
|
|
53
|
+
const wallet =
|
|
54
|
+
"0xfba94aa36e93ccc7d84a6a57040fc51983223f1b522a8d0be3c3bf2c98977ebb"
|
|
54
55
|
// const wallet =
|
|
55
56
|
// "0xaabf2fedcb36146db164bec930b74a47969c4df98216e049342a3c49b6d11580"
|
|
56
57
|
// const wallet = "0x410456cfc689666936b6bf80fbec958b69499b9f7183ecba07de577c17248a44"
|
|
57
58
|
// const wallet = "0xca171941521153181ff729d53489eaae7e99c3f4692884afd7cca61154e4cec4"
|
|
58
59
|
console.log("wallet: ", wallet)
|
|
59
60
|
|
|
60
|
-
const aggregatorPackage = {
|
|
61
|
-
packageName: "aggregator",
|
|
62
|
-
packageId:
|
|
63
|
-
"0x640d44dbdc0ede165c7cc417d7f57f1b09648083109de7132c6b3fb15861f5ee",
|
|
64
|
-
publishedAt:
|
|
65
|
-
"0x640d44dbdc0ede165c7cc417d7f57f1b09648083109de7132c6b3fb15861f5ee",
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const integratePackage = {
|
|
69
|
-
packageName: "integrate",
|
|
70
|
-
packageId:
|
|
71
|
-
"0x996c4d9480708fb8b92aa7acf819fb0497b5ec8e65ba06601cae2fb6db3312c3",
|
|
72
|
-
publishedAt:
|
|
73
|
-
"0x8faab90228e4c4df91c41626bbaefa19fc25c514405ac64de54578dec9e6f5ee",
|
|
74
|
-
}
|
|
75
|
-
// const endpoint =
|
|
76
|
-
// "https://api-sui-cloudfront.cetus.zone/router_v2/find_routes"
|
|
77
61
|
const endpoint =
|
|
78
|
-
"https://api-sui.
|
|
62
|
+
"https://api-sui-cloudfront.cetus.zone/router_v2/find_routes"
|
|
63
|
+
// const endpoint =
|
|
64
|
+
// "https://api-sui.devcetus.com/router_v2/find_routes"
|
|
79
65
|
|
|
80
66
|
const suiClient = new SuiClient({
|
|
81
|
-
url: "https://
|
|
67
|
+
url: "https://cetus-mainnet-rpc.blockvision.org:443/2R8NDfQ1v3UAqVAY8PwWQdB4FIb",
|
|
82
68
|
})
|
|
83
69
|
client = new AggregatorClient(endpoint, wallet, suiClient, Env.Testnet)
|
|
84
70
|
})
|
|
@@ -90,19 +76,21 @@ describe("router module", () => {
|
|
|
90
76
|
})
|
|
91
77
|
|
|
92
78
|
test("Downgrade swap in route", async () => {
|
|
93
|
-
const amount =
|
|
94
|
-
const byAmountIn =
|
|
79
|
+
const amount = 100000000
|
|
80
|
+
const byAmountIn = true
|
|
95
81
|
|
|
96
82
|
const res: any = await client.swapInPools({
|
|
97
|
-
from:
|
|
98
|
-
target:
|
|
83
|
+
from: "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",
|
|
84
|
+
target: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
|
|
99
85
|
amount: new BN(amount),
|
|
100
86
|
byAmountIn,
|
|
101
87
|
pools: [
|
|
102
|
-
|
|
88
|
+
'0x51e883ba7c0b566a26cbc8a94cd33eb0abd418a77cc1e60ad22fd9b1f29cd2ab', '0x03d7739b33fe221a830ff101042fa81fd19188feca04a335f7dea4e37c0fca81', '0xb8d7d9e66a60c239e7a60110efcf8de6c705580ed924d0dde141f4a0e2c90105'
|
|
103
89
|
],
|
|
104
90
|
})
|
|
105
91
|
|
|
92
|
+
console.log("res", res)
|
|
93
|
+
|
|
106
94
|
if (res != null) {
|
|
107
95
|
console.log(JSON.stringify(res, null, 2))
|
|
108
96
|
const txb = new Transaction()
|
|
@@ -118,7 +106,7 @@ describe("router module", () => {
|
|
|
118
106
|
let result = await client.devInspectTransactionBlock(txb)
|
|
119
107
|
console.log("🚀 ~ file: router.test.ts:114 ~ test ~ result:", result)
|
|
120
108
|
}
|
|
121
|
-
},
|
|
109
|
+
}, 60000)
|
|
122
110
|
|
|
123
111
|
test("Find router", async () => {
|
|
124
112
|
const amount = "4239267610000000000"
|
|
@@ -141,9 +129,9 @@ describe("router module", () => {
|
|
|
141
129
|
|
|
142
130
|
test("Build router tx", async () => {
|
|
143
131
|
const byAmountIn = true
|
|
144
|
-
const amount = "
|
|
145
|
-
const
|
|
146
|
-
const
|
|
132
|
+
const amount = "32"
|
|
133
|
+
const target = M_SUI
|
|
134
|
+
const from = M_MICHI
|
|
147
135
|
|
|
148
136
|
const res = await client.findRouters({
|
|
149
137
|
from,
|
|
@@ -153,7 +141,7 @@ describe("router module", () => {
|
|
|
153
141
|
depth: 3,
|
|
154
142
|
providers: [
|
|
155
143
|
"CETUS",
|
|
156
|
-
"DEEPBOOKV3",
|
|
144
|
+
// "DEEPBOOKV3",
|
|
157
145
|
// "DEEPBOOK",
|
|
158
146
|
// "AFTERMATH",
|
|
159
147
|
// "FLOWX",
|
package/tests/test_data.test.ts
CHANGED
|
@@ -20,3 +20,4 @@ export const M_HASUI =
|
|
|
20
20
|
"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
21
21
|
export const M_SSWP =
|
|
22
22
|
"0x361dd589b98e8fcda9a7ee53b85efabef3569d00416640d2faa516e3801d7ffc::TOKEN::TOKEN"
|
|
23
|
+
export const M_MICHI = "0x50d796fde5709a97883e29e00bf511d66f2656de958ea0c2ce4c1147cdd20a23::MICHI::MICHI"
|