@cetusprotocol/aggregator-sdk 0.3.5 → 0.3.7
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 +127 -0
- package/dist/{index.mjs → index.cjs} +88 -35
- package/dist/{index.d.mts → index.d.cts} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +42 -81
- package/dist/src/client.d.ts +1 -1
- package/dist/src/transaction/swap.d.ts +2 -2
- package/dist/tests/test_data.test.d.ts +4 -2
- package/package.json +2 -1
- package/src/client.ts +33 -17
- package/src/transaction/cetus.ts +2 -2
- package/src/transaction/scallop.ts +1 -0
- package/src/transaction/swap.ts +10 -10
- package/tests/router.test.ts +30 -49
- package/tests/test_data.test.ts +4 -2
package/README.md
CHANGED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
<!-- PROJECT LOGO -->
|
|
2
|
+
<br />
|
|
3
|
+
<div align="center">
|
|
4
|
+
<a >
|
|
5
|
+
<img src="https://archive.cetus.zone/assets/image/logo.png" alt="Logo" width="100" height="100">
|
|
6
|
+
</a>
|
|
7
|
+
|
|
8
|
+
<h3 align="center">Cetus Plus Swap Aggregator</h3>
|
|
9
|
+
|
|
10
|
+
<p align="center">
|
|
11
|
+
Integrating Cetus-Aggregator-SDK: A Comprehensive Guide, Please see details in document.
|
|
12
|
+
<br />
|
|
13
|
+
<a href="https://cetus-1.gitbook.io/cetus-developer-docs/developer/cetus-plus-aggregator"><strong>Explore the document »</strong>
|
|
14
|
+
</a>
|
|
15
|
+
</p>
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
# Welcome to Cetus Plus Swap Aggregator
|
|
19
|
+
|
|
20
|
+
Cetus plus swap aggregator is a high-speed and easy-to-integrate solution designed to optimize your trading experience on the Sui blockchain. This aggregator integrates multiple mainstream decentralized exchanges (DEX) on the Sui chain, including various types of trading platforms, providing users with the best trading prices and the lowest slippage.
|
|
21
|
+
|
|
22
|
+
Core Advantages:
|
|
23
|
+
|
|
24
|
+
High-Speed Transactions: Thanks to advanced algorithms and efficient architecture, our aggregator can execute transactions at lightning speed, ensuring users get the best opportunities in a rapidly changing market.
|
|
25
|
+
|
|
26
|
+
Easy Integration: The aggregator is designed to be simple and easy to integrate. Whether you are an individual developer or a large project team, you can quickly connect and deploy.
|
|
27
|
+
|
|
28
|
+
Multi-Platform Support: Currently, we have integrated multiple mainstream DEXs on the Sui chain, including cetus, deepbook, kriya, flowx, aftermath, afsui, haedal, volo, turbos etc, allowing users to enjoy a diversified trading experience on a single platform.
|
|
29
|
+
|
|
30
|
+
By using our aggregator, you can trade more efficiently and securely on the Sui blockchain, fully leveraging the various opportunities brought by decentralized finance (DeFi).
|
|
31
|
+
|
|
32
|
+
# Install
|
|
33
|
+
|
|
34
|
+
The SDK is published to npm registry. To use the SDK in your project, you can
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
npm install @cetusprotocol/aggregator-sdk
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
# Usage
|
|
41
|
+
|
|
42
|
+
## 1. Init client with rpc and package config
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
const client = new AggregatorClient()
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 2. Get best router swap result from aggregator service
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
const amount = new BN(1000000)
|
|
52
|
+
const from = "0x2::sui::SUI"
|
|
53
|
+
const target =
|
|
54
|
+
"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS"
|
|
55
|
+
|
|
56
|
+
const routerRes = await client.findRouters({
|
|
57
|
+
from,
|
|
58
|
+
target,
|
|
59
|
+
amount,
|
|
60
|
+
byAmountIn: true, // true means fix input amount, false means fix output amount
|
|
61
|
+
})
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## 3. Confirm and do fast swap
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
const routerTx = new Transaction()
|
|
68
|
+
|
|
69
|
+
if (routerRes != null) {
|
|
70
|
+
await client.fastRouterSwap({
|
|
71
|
+
routers: routerRes.routes,
|
|
72
|
+
byAmountIn,
|
|
73
|
+
txb: routerTx,
|
|
74
|
+
slippage: 0.01,
|
|
75
|
+
isMergeTragetCoin: true,
|
|
76
|
+
refreshAllCoins: true,
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
let result = await client.devInspectTransactionBlock(routerTx, keypair)
|
|
80
|
+
|
|
81
|
+
if (result.effects.status.status === "success") {
|
|
82
|
+
console.log("Sim exec transaction success")
|
|
83
|
+
const result = await client.signAndExecuteTransaction(routerTx, keypair)
|
|
84
|
+
}
|
|
85
|
+
console.log("result", result)
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## 4. Build PTB and return target coin
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
const routerTx = new Transaction()
|
|
93
|
+
const byAmountIn = true;
|
|
94
|
+
|
|
95
|
+
if (routerRes != null) {
|
|
96
|
+
const targetCoin = await client.routerSwap({
|
|
97
|
+
routers: routerRes.routes,
|
|
98
|
+
byAmountIn,
|
|
99
|
+
txb: routerTx,
|
|
100
|
+
inputCoin,
|
|
101
|
+
slippage: 0.01,
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
// you can use this target coin object argument to build your ptb.
|
|
105
|
+
const client.transferOrDestoryCoin(
|
|
106
|
+
txb,
|
|
107
|
+
targetCoinRes.targetCoin,
|
|
108
|
+
targetCoinType
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
let result = await client.devInspectTransactionBlock(routerTx, keypair)
|
|
112
|
+
|
|
113
|
+
if (result.effects.status.status === "success") {
|
|
114
|
+
console.log("Sim exec transaction success")
|
|
115
|
+
const result = await client.signAndExecuteTransaction(routerTx, keypair)
|
|
116
|
+
}
|
|
117
|
+
console.log("result", result)
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
# More About Cetus
|
|
122
|
+
|
|
123
|
+
Use the following links to learn more about Cetus:
|
|
124
|
+
|
|
125
|
+
Learn more about working with Cetus in the [Cetus Documentation](https://cetus-1.gitbook.io/cetus-docs).
|
|
126
|
+
|
|
127
|
+
Join the Cetus community on [Cetus Discord](https://discord.com/channels/1009749448022315008/1009751382783447072).
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var client = require('@mysten/sui/client');
|
|
4
|
+
var utils = require('@mysten/sui/utils');
|
|
5
|
+
var transactions = require('@mysten/sui/transactions');
|
|
4
6
|
|
|
5
7
|
var __create = Object.create;
|
|
6
8
|
var __defProp = Object.defineProperty;
|
|
@@ -47,7 +49,7 @@ var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__
|
|
|
47
49
|
// file that has been converted to a CommonJS file using a Babel-
|
|
48
50
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
49
51
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
50
|
-
|
|
52
|
+
__defProp(target, "default", { value: mod2, enumerable: true }) ,
|
|
51
53
|
mod2
|
|
52
54
|
));
|
|
53
55
|
var __async = (__this, __arguments, generator) => {
|
|
@@ -5263,8 +5265,8 @@ var Turbos = class {
|
|
|
5263
5265
|
// src/transaction/cetus.ts
|
|
5264
5266
|
var Cetus = class {
|
|
5265
5267
|
constructor(env, partner) {
|
|
5266
|
-
this.globalConfig = env === 0 /* Mainnet */ ? "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f" : "
|
|
5267
|
-
this.partner = partner != null ? partner : env === 0 /* Mainnet */ ? "0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b" : "
|
|
5268
|
+
this.globalConfig = env === 0 /* Mainnet */ ? "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f" : "0x9774e359588ead122af1c7e7f64e14ade261cfeecdb5d0eb4a5b3b4c8ab8bd3e";
|
|
5269
|
+
this.partner = partner != null ? partner : env === 0 /* Mainnet */ ? "0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b" : "0x1f5fa5c820f40d43fc47815ad06d95e40a1942ff72a732a92e8ef4aa8cde70a5";
|
|
5268
5270
|
}
|
|
5269
5271
|
flash_swap(client, txb, path, by_amount_in) {
|
|
5270
5272
|
const { direction, from, target } = path;
|
|
@@ -5388,7 +5390,7 @@ function extractStructTagFromType(type) {
|
|
|
5388
5390
|
const isSuiCoin = _type === GAS_TYPE_ARG || _type === GAS_TYPE_ARG_LONG;
|
|
5389
5391
|
const structTag = {
|
|
5390
5392
|
full_address: _type,
|
|
5391
|
-
address: isSuiCoin ? "0x2" : normalizeSuiObjectId(parts[0]),
|
|
5393
|
+
address: isSuiCoin ? "0x2" : utils.normalizeSuiObjectId(parts[0]),
|
|
5392
5394
|
module: parts[1],
|
|
5393
5395
|
name: parts[2],
|
|
5394
5396
|
type_arguments: [],
|
|
@@ -5413,7 +5415,7 @@ function normalizeCoinType(coinType) {
|
|
|
5413
5415
|
}
|
|
5414
5416
|
function fixSuiObjectId(value) {
|
|
5415
5417
|
if (value.toLowerCase().startsWith("0x")) {
|
|
5416
|
-
return normalizeSuiObjectId(value);
|
|
5418
|
+
return utils.normalizeSuiObjectId(value);
|
|
5417
5419
|
}
|
|
5418
5420
|
return value;
|
|
5419
5421
|
}
|
|
@@ -5762,20 +5764,19 @@ function sqrtPriceX64ToPrice(sqrtPriceStr, decimalsA, decimalsB) {
|
|
|
5762
5764
|
}
|
|
5763
5765
|
|
|
5764
5766
|
// src/transaction/swap.ts
|
|
5765
|
-
function swapInPools(client, params, sender) {
|
|
5767
|
+
function swapInPools(client, params, sender, env) {
|
|
5766
5768
|
return __async(this, null, function* () {
|
|
5767
5769
|
var _a, _b, _c, _d, _e;
|
|
5768
5770
|
const { from, target, amount, byAmountIn, pools } = params;
|
|
5769
5771
|
const fromCoin = completionCoin(from);
|
|
5770
5772
|
const targetCoin = completionCoin(target);
|
|
5771
|
-
const tx = new Transaction();
|
|
5773
|
+
const tx = new transactions.Transaction();
|
|
5772
5774
|
const direction = compareCoins(fromCoin, targetCoin);
|
|
5773
|
-
const integratePublishedAt = "
|
|
5775
|
+
const integratePublishedAt = env === 0 /* Mainnet */ ? "0x3a5aa90ffa33d09100d7b6941ea1c0ffe6ab66e77062ddd26320c1b073aabb10" : "0x19dd42e05fa6c9988a60d30686ee3feb776672b5547e328d6dab16563da65293";
|
|
5774
5776
|
const coinA = direction ? fromCoin : targetCoin;
|
|
5775
5777
|
const coinB = direction ? targetCoin : fromCoin;
|
|
5776
5778
|
const typeArguments = [coinA, coinB];
|
|
5777
|
-
console.log("typeArguments", typeArguments);
|
|
5778
|
-
console.log("pools", pools);
|
|
5779
|
+
console.log("typeArguments", typeArguments, integratePublishedAt);
|
|
5779
5780
|
for (let i = 0; i < pools.length; i++) {
|
|
5780
5781
|
const args = [
|
|
5781
5782
|
tx.object(pools[i]),
|
|
@@ -5795,6 +5796,7 @@ function swapInPools(client, params, sender) {
|
|
|
5795
5796
|
"InvalidWallet" /* InvalidWallet */
|
|
5796
5797
|
);
|
|
5797
5798
|
}
|
|
5799
|
+
printTransaction(tx);
|
|
5798
5800
|
const simulateRes = yield client.devInspectTransactionBlock({
|
|
5799
5801
|
transactionBlock: tx,
|
|
5800
5802
|
sender
|
|
@@ -5836,7 +5838,6 @@ function swapInPools(client, params, sender) {
|
|
|
5836
5838
|
}
|
|
5837
5839
|
}
|
|
5838
5840
|
const event = valueData[tempIndex].parsedJson.data;
|
|
5839
|
-
console.log("event", JSON.stringify(event, null, 2));
|
|
5840
5841
|
const currentSqrtPrice = event.step_results[0].current_sqrt_price;
|
|
5841
5842
|
const [decimalA, decimalB] = yield Promise.all([
|
|
5842
5843
|
client.getCoinMetadata({ coinType: coinA }).then((metadata) => metadata == null ? void 0 : metadata.decimals),
|
|
@@ -6090,39 +6091,47 @@ var DEEPBOOKV3 = "DEEPBOOKV3";
|
|
|
6090
6091
|
var SCALLOP = "SCALLOP";
|
|
6091
6092
|
var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
6092
6093
|
var AggregatorClient8 = class {
|
|
6093
|
-
constructor(endpoint, signer, client, env) {
|
|
6094
|
+
constructor(endpoint, signer, client$1, env) {
|
|
6094
6095
|
this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
|
|
6095
|
-
this.client = client || new SuiClient({ url: getFullnodeUrl("mainnet") });
|
|
6096
|
+
this.client = client$1 || new client.SuiClient({ url: client.getFullnodeUrl("mainnet") });
|
|
6096
6097
|
this.signer = signer || "";
|
|
6097
6098
|
this.env = env || 0 /* Mainnet */;
|
|
6098
|
-
this.allCoins =
|
|
6099
|
+
this.allCoins = /* @__PURE__ */ new Map();
|
|
6099
6100
|
}
|
|
6100
|
-
|
|
6101
|
+
getCoins(coinType, refresh = true) {
|
|
6101
6102
|
return __async(this, null, function* () {
|
|
6102
6103
|
if (this.signer === "") {
|
|
6103
6104
|
throw new Error("Signer is required, but not provided.");
|
|
6104
6105
|
}
|
|
6105
6106
|
let cursor = null;
|
|
6106
6107
|
let limit = 50;
|
|
6108
|
+
if (!refresh) {
|
|
6109
|
+
const gotFromCoins = this.allCoins.get(coinType);
|
|
6110
|
+
if (gotFromCoins) {
|
|
6111
|
+
return gotFromCoins;
|
|
6112
|
+
}
|
|
6113
|
+
}
|
|
6107
6114
|
const allCoins = [];
|
|
6108
6115
|
while (true) {
|
|
6109
|
-
const
|
|
6116
|
+
const gotCoins = yield this.client.getCoins({
|
|
6110
6117
|
owner: this.signer,
|
|
6118
|
+
coinType,
|
|
6111
6119
|
cursor,
|
|
6112
6120
|
limit
|
|
6113
6121
|
});
|
|
6114
|
-
for (const coin of
|
|
6122
|
+
for (const coin of gotCoins.data) {
|
|
6115
6123
|
allCoins.push({
|
|
6116
6124
|
coinAddress: extractStructTagFromType(coin.coinType).source_address,
|
|
6117
6125
|
coinObjectId: coin.coinObjectId,
|
|
6118
6126
|
balance: BigInt(coin.balance)
|
|
6119
6127
|
});
|
|
6120
6128
|
}
|
|
6121
|
-
if (
|
|
6129
|
+
if (gotCoins.data.length < limit) {
|
|
6122
6130
|
break;
|
|
6123
6131
|
}
|
|
6124
|
-
cursor =
|
|
6132
|
+
cursor = gotCoins.data[limit - 1].coinObjectId;
|
|
6125
6133
|
}
|
|
6134
|
+
this.allCoins.set(coinType, allCoins);
|
|
6126
6135
|
return allCoins;
|
|
6127
6136
|
});
|
|
6128
6137
|
}
|
|
@@ -6202,7 +6211,7 @@ var AggregatorClient8 = class {
|
|
|
6202
6211
|
if (targetCoins.length > 1) {
|
|
6203
6212
|
const vec = txb.makeMoveVec({ elements: targetCoins.slice(1) });
|
|
6204
6213
|
txb.moveCall({
|
|
6205
|
-
target: `${SUI_FRAMEWORK_ADDRESS}::pay::join_vec`,
|
|
6214
|
+
target: `${utils.SUI_FRAMEWORK_ADDRESS}::pay::join_vec`,
|
|
6206
6215
|
typeArguments: [routers[0].path[routers[0].path.length - 1].target],
|
|
6207
6216
|
arguments: [targetCoins[0], vec]
|
|
6208
6217
|
});
|
|
@@ -6214,7 +6223,7 @@ var AggregatorClient8 = class {
|
|
|
6214
6223
|
return __async(this, null, function* () {
|
|
6215
6224
|
let result;
|
|
6216
6225
|
try {
|
|
6217
|
-
result = yield swapInPools(this.client, params, this.signer);
|
|
6226
|
+
result = yield swapInPools(this.client, params, this.signer, this.env);
|
|
6218
6227
|
} catch (e) {
|
|
6219
6228
|
console.error("swapInPools error:", e);
|
|
6220
6229
|
return null;
|
|
@@ -6276,10 +6285,8 @@ var AggregatorClient8 = class {
|
|
|
6276
6285
|
refreshAllCoins,
|
|
6277
6286
|
payDeepFeeAmount
|
|
6278
6287
|
} = params;
|
|
6279
|
-
if (refreshAllCoins || this.allCoins.length === 0) {
|
|
6280
|
-
this.allCoins = yield this.getAllCoins();
|
|
6281
|
-
}
|
|
6282
6288
|
const fromCoinType = routers[0].path[0].from;
|
|
6289
|
+
let fromCoins = yield this.getCoins(fromCoinType, refreshAllCoins);
|
|
6283
6290
|
const targetCoinType = routers[0].path[routers[0].path.length - 1].target;
|
|
6284
6291
|
const amountIn = routers.reduce(
|
|
6285
6292
|
(acc, router) => acc.add(router.amountIn),
|
|
@@ -6297,15 +6304,16 @@ var AggregatorClient8 = class {
|
|
|
6297
6304
|
const amount = byAmountIn ? amountIn : amountLimit;
|
|
6298
6305
|
const buildFromCoinRes = buildInputCoin(
|
|
6299
6306
|
txb,
|
|
6300
|
-
|
|
6307
|
+
fromCoins,
|
|
6301
6308
|
BigInt(amount.toString()),
|
|
6302
6309
|
fromCoinType
|
|
6303
6310
|
);
|
|
6304
6311
|
let deepCoin;
|
|
6305
6312
|
if (payDeepFeeAmount && payDeepFeeAmount > 0) {
|
|
6313
|
+
let deepCoins = yield this.getCoins(this.deepbookv3DeepFeeType());
|
|
6306
6314
|
deepCoin = buildInputCoin(
|
|
6307
6315
|
txb,
|
|
6308
|
-
|
|
6316
|
+
deepCoins,
|
|
6309
6317
|
BigInt(payDeepFeeAmount),
|
|
6310
6318
|
this.deepbookv3DeepFeeType()
|
|
6311
6319
|
).targetCoin;
|
|
@@ -6320,9 +6328,10 @@ var AggregatorClient8 = class {
|
|
|
6320
6328
|
deepbookv3DeepFee: deepCoin
|
|
6321
6329
|
});
|
|
6322
6330
|
if (isMergeTragetCoin) {
|
|
6331
|
+
let targetCoins = yield this.getCoins(targetCoinType, refreshAllCoins);
|
|
6323
6332
|
const targetCoinRes = buildInputCoin(
|
|
6324
6333
|
txb,
|
|
6325
|
-
|
|
6334
|
+
targetCoins,
|
|
6326
6335
|
BigInt(0),
|
|
6327
6336
|
targetCoinType
|
|
6328
6337
|
);
|
|
@@ -6342,9 +6351,9 @@ var AggregatorClient8 = class {
|
|
|
6342
6351
|
// Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
|
|
6343
6352
|
publishedAt() {
|
|
6344
6353
|
if (this.env === 0 /* Mainnet */) {
|
|
6345
|
-
return "
|
|
6354
|
+
return "0x11451575c775a3e633437b827ecbc1eb51a5964b0302210b28f5b89880be21a2";
|
|
6346
6355
|
} else {
|
|
6347
|
-
return "
|
|
6356
|
+
return "0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934";
|
|
6348
6357
|
}
|
|
6349
6358
|
}
|
|
6350
6359
|
// Include deepbookv3, scallop
|
|
@@ -6352,7 +6361,7 @@ var AggregatorClient8 = class {
|
|
|
6352
6361
|
if (this.env === 0 /* Mainnet */) {
|
|
6353
6362
|
return "0x6d70ffa7aa3f924c3f0b573d27d29895a0ee666aaff821073f75cb14af7fd01a";
|
|
6354
6363
|
} else {
|
|
6355
|
-
return "
|
|
6364
|
+
return "0xfd8a73ef0a4b928da9c27fc287dc37c1ca64df71da8e8eac7ca9ece55eb5f448";
|
|
6356
6365
|
}
|
|
6357
6366
|
}
|
|
6358
6367
|
deepbookv3DeepFeeType() {
|
|
@@ -6374,7 +6383,7 @@ var AggregatorClient8 = class {
|
|
|
6374
6383
|
if (coins.length > 1) {
|
|
6375
6384
|
let vec = txb.makeMoveVec({ elements: coins.slice(1) });
|
|
6376
6385
|
txb.moveCall({
|
|
6377
|
-
target: `${SUI_FRAMEWORK_ADDRESS}::pay::join_vec`,
|
|
6386
|
+
target: `${utils.SUI_FRAMEWORK_ADDRESS}::pay::join_vec`,
|
|
6378
6387
|
typeArguments: [coinType],
|
|
6379
6388
|
arguments: [coins[0], vec]
|
|
6380
6389
|
});
|
|
@@ -6724,4 +6733,48 @@ decimal.js/decimal.mjs:
|
|
|
6724
6733
|
*)
|
|
6725
6734
|
*/
|
|
6726
6735
|
|
|
6727
|
-
|
|
6736
|
+
exports.AFSUI = AFSUI;
|
|
6737
|
+
exports.AFTERMATH = AFTERMATH;
|
|
6738
|
+
exports.AggregatorClient = AggregatorClient8;
|
|
6739
|
+
exports.BLUEMOVE = BLUEMOVE;
|
|
6740
|
+
exports.CETUS = CETUS;
|
|
6741
|
+
exports.CLOCK_ADDRESS = CLOCK_ADDRESS;
|
|
6742
|
+
exports.DEEPBOOKV2 = DEEPBOOKV2;
|
|
6743
|
+
exports.DEEPBOOKV3 = DEEPBOOKV3;
|
|
6744
|
+
exports.DEFAULT_ENDPOINT = DEFAULT_ENDPOINT;
|
|
6745
|
+
exports.Env = Env;
|
|
6746
|
+
exports.FLOWXV2 = FLOWXV2;
|
|
6747
|
+
exports.FLOWXV3 = FLOWXV3;
|
|
6748
|
+
exports.HAEDAL = HAEDAL;
|
|
6749
|
+
exports.KRIYA = KRIYA;
|
|
6750
|
+
exports.KRIYAV3 = KRIYAV3;
|
|
6751
|
+
exports.ONE = ONE;
|
|
6752
|
+
exports.SCALLOP = SCALLOP;
|
|
6753
|
+
exports.TEN_POW_NINE = TEN_POW_NINE;
|
|
6754
|
+
exports.TURBOS = TURBOS;
|
|
6755
|
+
exports.TWO = TWO;
|
|
6756
|
+
exports.U128 = U128;
|
|
6757
|
+
exports.U64_MAX = U64_MAX;
|
|
6758
|
+
exports.U64_MAX_BN = U64_MAX_BN;
|
|
6759
|
+
exports.VOLO = VOLO;
|
|
6760
|
+
exports.ZERO = ZERO;
|
|
6761
|
+
exports.buildInputCoin = buildInputCoin;
|
|
6762
|
+
exports.checkInvalidSuiAddress = checkInvalidSuiAddress;
|
|
6763
|
+
exports.compareCoins = compareCoins;
|
|
6764
|
+
exports.completionCoin = completionCoin;
|
|
6765
|
+
exports.composeType = composeType;
|
|
6766
|
+
exports.createTarget = createTarget;
|
|
6767
|
+
exports.dealWithFastRouterSwapParamsForMsafe = dealWithFastRouterSwapParamsForMsafe;
|
|
6768
|
+
exports.extractAddressFromType = extractAddressFromType;
|
|
6769
|
+
exports.extractStructTagFromType = extractStructTagFromType;
|
|
6770
|
+
exports.fixSuiObjectId = fixSuiObjectId;
|
|
6771
|
+
exports.getDeepbookV3Config = getDeepbookV3Config;
|
|
6772
|
+
exports.getRouterResult = getRouterResult;
|
|
6773
|
+
exports.isSortedSymbols = isSortedSymbols;
|
|
6774
|
+
exports.mintZeroCoin = mintZeroCoin;
|
|
6775
|
+
exports.normalizeCoinType = normalizeCoinType;
|
|
6776
|
+
exports.parseRouterResponse = parseRouterResponse;
|
|
6777
|
+
exports.patchFixSuiObjectId = patchFixSuiObjectId;
|
|
6778
|
+
exports.printTransaction = printTransaction;
|
|
6779
|
+
exports.processEndpoint = processEndpoint;
|
|
6780
|
+
exports.restituteMsafeFastRouterSwapParams = restituteMsafeFastRouterSwapParams;
|
|
@@ -112,7 +112,7 @@ declare class AggregatorClient {
|
|
|
112
112
|
env: Env;
|
|
113
113
|
private allCoins;
|
|
114
114
|
constructor(endpoint?: string, signer?: string, client?: SuiClient, env?: Env);
|
|
115
|
-
|
|
115
|
+
getCoins(coinType: string, refresh?: boolean): Promise<CoinAsset[]>;
|
|
116
116
|
findRouters(params: FindRouterParams): Promise<RouterData | null>;
|
|
117
117
|
expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
118
118
|
expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string): Promise<TransactionObjectArgument>;
|
package/dist/index.d.ts
CHANGED
|
@@ -112,7 +112,7 @@ declare class AggregatorClient {
|
|
|
112
112
|
env: Env;
|
|
113
113
|
private allCoins;
|
|
114
114
|
constructor(endpoint?: string, signer?: string, client?: SuiClient, env?: Env);
|
|
115
|
-
|
|
115
|
+
getCoins(coinType: string, refresh?: boolean): Promise<CoinAsset[]>;
|
|
116
116
|
findRouters(params: FindRouterParams): Promise<RouterData | null>;
|
|
117
117
|
expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
118
118
|
expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string): Promise<TransactionObjectArgument>;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var utils = require('@mysten/sui/utils');
|
|
5
|
-
var transactions = require('@mysten/sui/transactions');
|
|
1
|
+
import { SuiClient, getFullnodeUrl } from '@mysten/sui/client';
|
|
2
|
+
import { normalizeSuiObjectId, SUI_FRAMEWORK_ADDRESS } from '@mysten/sui/utils';
|
|
3
|
+
import { Transaction } from '@mysten/sui/transactions';
|
|
6
4
|
|
|
7
5
|
var __create = Object.create;
|
|
8
6
|
var __defProp = Object.defineProperty;
|
|
@@ -49,7 +47,7 @@ var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__
|
|
|
49
47
|
// file that has been converted to a CommonJS file using a Babel-
|
|
50
48
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
51
49
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
52
|
-
|
|
50
|
+
__defProp(target, "default", { value: mod2, enumerable: true }) ,
|
|
53
51
|
mod2
|
|
54
52
|
));
|
|
55
53
|
var __async = (__this, __arguments, generator) => {
|
|
@@ -5265,8 +5263,8 @@ var Turbos = class {
|
|
|
5265
5263
|
// src/transaction/cetus.ts
|
|
5266
5264
|
var Cetus = class {
|
|
5267
5265
|
constructor(env, partner) {
|
|
5268
|
-
this.globalConfig = env === 0 /* Mainnet */ ? "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f" : "
|
|
5269
|
-
this.partner = partner != null ? partner : env === 0 /* Mainnet */ ? "0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b" : "
|
|
5266
|
+
this.globalConfig = env === 0 /* Mainnet */ ? "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f" : "0x9774e359588ead122af1c7e7f64e14ade261cfeecdb5d0eb4a5b3b4c8ab8bd3e";
|
|
5267
|
+
this.partner = partner != null ? partner : env === 0 /* Mainnet */ ? "0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b" : "0x1f5fa5c820f40d43fc47815ad06d95e40a1942ff72a732a92e8ef4aa8cde70a5";
|
|
5270
5268
|
}
|
|
5271
5269
|
flash_swap(client, txb, path, by_amount_in) {
|
|
5272
5270
|
const { direction, from, target } = path;
|
|
@@ -5390,7 +5388,7 @@ function extractStructTagFromType(type) {
|
|
|
5390
5388
|
const isSuiCoin = _type === GAS_TYPE_ARG || _type === GAS_TYPE_ARG_LONG;
|
|
5391
5389
|
const structTag = {
|
|
5392
5390
|
full_address: _type,
|
|
5393
|
-
address: isSuiCoin ? "0x2" :
|
|
5391
|
+
address: isSuiCoin ? "0x2" : normalizeSuiObjectId(parts[0]),
|
|
5394
5392
|
module: parts[1],
|
|
5395
5393
|
name: parts[2],
|
|
5396
5394
|
type_arguments: [],
|
|
@@ -5415,7 +5413,7 @@ function normalizeCoinType(coinType) {
|
|
|
5415
5413
|
}
|
|
5416
5414
|
function fixSuiObjectId(value) {
|
|
5417
5415
|
if (value.toLowerCase().startsWith("0x")) {
|
|
5418
|
-
return
|
|
5416
|
+
return normalizeSuiObjectId(value);
|
|
5419
5417
|
}
|
|
5420
5418
|
return value;
|
|
5421
5419
|
}
|
|
@@ -5764,20 +5762,19 @@ function sqrtPriceX64ToPrice(sqrtPriceStr, decimalsA, decimalsB) {
|
|
|
5764
5762
|
}
|
|
5765
5763
|
|
|
5766
5764
|
// src/transaction/swap.ts
|
|
5767
|
-
function swapInPools(client, params, sender) {
|
|
5765
|
+
function swapInPools(client, params, sender, env) {
|
|
5768
5766
|
return __async(this, null, function* () {
|
|
5769
5767
|
var _a, _b, _c, _d, _e;
|
|
5770
5768
|
const { from, target, amount, byAmountIn, pools } = params;
|
|
5771
5769
|
const fromCoin = completionCoin(from);
|
|
5772
5770
|
const targetCoin = completionCoin(target);
|
|
5773
|
-
const tx = new
|
|
5771
|
+
const tx = new Transaction();
|
|
5774
5772
|
const direction = compareCoins(fromCoin, targetCoin);
|
|
5775
|
-
const integratePublishedAt = "
|
|
5773
|
+
const integratePublishedAt = env === 0 /* Mainnet */ ? "0x3a5aa90ffa33d09100d7b6941ea1c0ffe6ab66e77062ddd26320c1b073aabb10" : "0x19dd42e05fa6c9988a60d30686ee3feb776672b5547e328d6dab16563da65293";
|
|
5776
5774
|
const coinA = direction ? fromCoin : targetCoin;
|
|
5777
5775
|
const coinB = direction ? targetCoin : fromCoin;
|
|
5778
5776
|
const typeArguments = [coinA, coinB];
|
|
5779
|
-
console.log("typeArguments", typeArguments);
|
|
5780
|
-
console.log("pools", pools);
|
|
5777
|
+
console.log("typeArguments", typeArguments, integratePublishedAt);
|
|
5781
5778
|
for (let i = 0; i < pools.length; i++) {
|
|
5782
5779
|
const args = [
|
|
5783
5780
|
tx.object(pools[i]),
|
|
@@ -5797,6 +5794,7 @@ function swapInPools(client, params, sender) {
|
|
|
5797
5794
|
"InvalidWallet" /* InvalidWallet */
|
|
5798
5795
|
);
|
|
5799
5796
|
}
|
|
5797
|
+
printTransaction(tx);
|
|
5800
5798
|
const simulateRes = yield client.devInspectTransactionBlock({
|
|
5801
5799
|
transactionBlock: tx,
|
|
5802
5800
|
sender
|
|
@@ -5838,7 +5836,6 @@ function swapInPools(client, params, sender) {
|
|
|
5838
5836
|
}
|
|
5839
5837
|
}
|
|
5840
5838
|
const event = valueData[tempIndex].parsedJson.data;
|
|
5841
|
-
console.log("event", JSON.stringify(event, null, 2));
|
|
5842
5839
|
const currentSqrtPrice = event.step_results[0].current_sqrt_price;
|
|
5843
5840
|
const [decimalA, decimalB] = yield Promise.all([
|
|
5844
5841
|
client.getCoinMetadata({ coinType: coinA }).then((metadata) => metadata == null ? void 0 : metadata.decimals),
|
|
@@ -6092,39 +6089,47 @@ var DEEPBOOKV3 = "DEEPBOOKV3";
|
|
|
6092
6089
|
var SCALLOP = "SCALLOP";
|
|
6093
6090
|
var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
6094
6091
|
var AggregatorClient8 = class {
|
|
6095
|
-
constructor(endpoint, signer, client
|
|
6092
|
+
constructor(endpoint, signer, client, env) {
|
|
6096
6093
|
this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
|
|
6097
|
-
this.client = client
|
|
6094
|
+
this.client = client || new SuiClient({ url: getFullnodeUrl("mainnet") });
|
|
6098
6095
|
this.signer = signer || "";
|
|
6099
6096
|
this.env = env || 0 /* Mainnet */;
|
|
6100
|
-
this.allCoins =
|
|
6097
|
+
this.allCoins = /* @__PURE__ */ new Map();
|
|
6101
6098
|
}
|
|
6102
|
-
|
|
6099
|
+
getCoins(coinType, refresh = true) {
|
|
6103
6100
|
return __async(this, null, function* () {
|
|
6104
6101
|
if (this.signer === "") {
|
|
6105
6102
|
throw new Error("Signer is required, but not provided.");
|
|
6106
6103
|
}
|
|
6107
6104
|
let cursor = null;
|
|
6108
6105
|
let limit = 50;
|
|
6106
|
+
if (!refresh) {
|
|
6107
|
+
const gotFromCoins = this.allCoins.get(coinType);
|
|
6108
|
+
if (gotFromCoins) {
|
|
6109
|
+
return gotFromCoins;
|
|
6110
|
+
}
|
|
6111
|
+
}
|
|
6109
6112
|
const allCoins = [];
|
|
6110
6113
|
while (true) {
|
|
6111
|
-
const
|
|
6114
|
+
const gotCoins = yield this.client.getCoins({
|
|
6112
6115
|
owner: this.signer,
|
|
6116
|
+
coinType,
|
|
6113
6117
|
cursor,
|
|
6114
6118
|
limit
|
|
6115
6119
|
});
|
|
6116
|
-
for (const coin of
|
|
6120
|
+
for (const coin of gotCoins.data) {
|
|
6117
6121
|
allCoins.push({
|
|
6118
6122
|
coinAddress: extractStructTagFromType(coin.coinType).source_address,
|
|
6119
6123
|
coinObjectId: coin.coinObjectId,
|
|
6120
6124
|
balance: BigInt(coin.balance)
|
|
6121
6125
|
});
|
|
6122
6126
|
}
|
|
6123
|
-
if (
|
|
6127
|
+
if (gotCoins.data.length < limit) {
|
|
6124
6128
|
break;
|
|
6125
6129
|
}
|
|
6126
|
-
cursor =
|
|
6130
|
+
cursor = gotCoins.data[limit - 1].coinObjectId;
|
|
6127
6131
|
}
|
|
6132
|
+
this.allCoins.set(coinType, allCoins);
|
|
6128
6133
|
return allCoins;
|
|
6129
6134
|
});
|
|
6130
6135
|
}
|
|
@@ -6204,7 +6209,7 @@ var AggregatorClient8 = class {
|
|
|
6204
6209
|
if (targetCoins.length > 1) {
|
|
6205
6210
|
const vec = txb.makeMoveVec({ elements: targetCoins.slice(1) });
|
|
6206
6211
|
txb.moveCall({
|
|
6207
|
-
target: `${
|
|
6212
|
+
target: `${SUI_FRAMEWORK_ADDRESS}::pay::join_vec`,
|
|
6208
6213
|
typeArguments: [routers[0].path[routers[0].path.length - 1].target],
|
|
6209
6214
|
arguments: [targetCoins[0], vec]
|
|
6210
6215
|
});
|
|
@@ -6216,7 +6221,7 @@ var AggregatorClient8 = class {
|
|
|
6216
6221
|
return __async(this, null, function* () {
|
|
6217
6222
|
let result;
|
|
6218
6223
|
try {
|
|
6219
|
-
result = yield swapInPools(this.client, params, this.signer);
|
|
6224
|
+
result = yield swapInPools(this.client, params, this.signer, this.env);
|
|
6220
6225
|
} catch (e) {
|
|
6221
6226
|
console.error("swapInPools error:", e);
|
|
6222
6227
|
return null;
|
|
@@ -6278,10 +6283,8 @@ var AggregatorClient8 = class {
|
|
|
6278
6283
|
refreshAllCoins,
|
|
6279
6284
|
payDeepFeeAmount
|
|
6280
6285
|
} = params;
|
|
6281
|
-
if (refreshAllCoins || this.allCoins.length === 0) {
|
|
6282
|
-
this.allCoins = yield this.getAllCoins();
|
|
6283
|
-
}
|
|
6284
6286
|
const fromCoinType = routers[0].path[0].from;
|
|
6287
|
+
let fromCoins = yield this.getCoins(fromCoinType, refreshAllCoins);
|
|
6285
6288
|
const targetCoinType = routers[0].path[routers[0].path.length - 1].target;
|
|
6286
6289
|
const amountIn = routers.reduce(
|
|
6287
6290
|
(acc, router) => acc.add(router.amountIn),
|
|
@@ -6299,15 +6302,16 @@ var AggregatorClient8 = class {
|
|
|
6299
6302
|
const amount = byAmountIn ? amountIn : amountLimit;
|
|
6300
6303
|
const buildFromCoinRes = buildInputCoin(
|
|
6301
6304
|
txb,
|
|
6302
|
-
|
|
6305
|
+
fromCoins,
|
|
6303
6306
|
BigInt(amount.toString()),
|
|
6304
6307
|
fromCoinType
|
|
6305
6308
|
);
|
|
6306
6309
|
let deepCoin;
|
|
6307
6310
|
if (payDeepFeeAmount && payDeepFeeAmount > 0) {
|
|
6311
|
+
let deepCoins = yield this.getCoins(this.deepbookv3DeepFeeType());
|
|
6308
6312
|
deepCoin = buildInputCoin(
|
|
6309
6313
|
txb,
|
|
6310
|
-
|
|
6314
|
+
deepCoins,
|
|
6311
6315
|
BigInt(payDeepFeeAmount),
|
|
6312
6316
|
this.deepbookv3DeepFeeType()
|
|
6313
6317
|
).targetCoin;
|
|
@@ -6322,9 +6326,10 @@ var AggregatorClient8 = class {
|
|
|
6322
6326
|
deepbookv3DeepFee: deepCoin
|
|
6323
6327
|
});
|
|
6324
6328
|
if (isMergeTragetCoin) {
|
|
6329
|
+
let targetCoins = yield this.getCoins(targetCoinType, refreshAllCoins);
|
|
6325
6330
|
const targetCoinRes = buildInputCoin(
|
|
6326
6331
|
txb,
|
|
6327
|
-
|
|
6332
|
+
targetCoins,
|
|
6328
6333
|
BigInt(0),
|
|
6329
6334
|
targetCoinType
|
|
6330
6335
|
);
|
|
@@ -6344,9 +6349,9 @@ var AggregatorClient8 = class {
|
|
|
6344
6349
|
// Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
|
|
6345
6350
|
publishedAt() {
|
|
6346
6351
|
if (this.env === 0 /* Mainnet */) {
|
|
6347
|
-
return "
|
|
6352
|
+
return "0x11451575c775a3e633437b827ecbc1eb51a5964b0302210b28f5b89880be21a2";
|
|
6348
6353
|
} else {
|
|
6349
|
-
return "
|
|
6354
|
+
return "0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934";
|
|
6350
6355
|
}
|
|
6351
6356
|
}
|
|
6352
6357
|
// Include deepbookv3, scallop
|
|
@@ -6354,7 +6359,7 @@ var AggregatorClient8 = class {
|
|
|
6354
6359
|
if (this.env === 0 /* Mainnet */) {
|
|
6355
6360
|
return "0x6d70ffa7aa3f924c3f0b573d27d29895a0ee666aaff821073f75cb14af7fd01a";
|
|
6356
6361
|
} else {
|
|
6357
|
-
return "
|
|
6362
|
+
return "0xfd8a73ef0a4b928da9c27fc287dc37c1ca64df71da8e8eac7ca9ece55eb5f448";
|
|
6358
6363
|
}
|
|
6359
6364
|
}
|
|
6360
6365
|
deepbookv3DeepFeeType() {
|
|
@@ -6376,7 +6381,7 @@ var AggregatorClient8 = class {
|
|
|
6376
6381
|
if (coins.length > 1) {
|
|
6377
6382
|
let vec = txb.makeMoveVec({ elements: coins.slice(1) });
|
|
6378
6383
|
txb.moveCall({
|
|
6379
|
-
target: `${
|
|
6384
|
+
target: `${SUI_FRAMEWORK_ADDRESS}::pay::join_vec`,
|
|
6380
6385
|
typeArguments: [coinType],
|
|
6381
6386
|
arguments: [coins[0], vec]
|
|
6382
6387
|
});
|
|
@@ -6726,48 +6731,4 @@ decimal.js/decimal.mjs:
|
|
|
6726
6731
|
*)
|
|
6727
6732
|
*/
|
|
6728
6733
|
|
|
6729
|
-
|
|
6730
|
-
exports.AFTERMATH = AFTERMATH;
|
|
6731
|
-
exports.AggregatorClient = AggregatorClient8;
|
|
6732
|
-
exports.BLUEMOVE = BLUEMOVE;
|
|
6733
|
-
exports.CETUS = CETUS;
|
|
6734
|
-
exports.CLOCK_ADDRESS = CLOCK_ADDRESS;
|
|
6735
|
-
exports.DEEPBOOKV2 = DEEPBOOKV2;
|
|
6736
|
-
exports.DEEPBOOKV3 = DEEPBOOKV3;
|
|
6737
|
-
exports.DEFAULT_ENDPOINT = DEFAULT_ENDPOINT;
|
|
6738
|
-
exports.Env = Env;
|
|
6739
|
-
exports.FLOWXV2 = FLOWXV2;
|
|
6740
|
-
exports.FLOWXV3 = FLOWXV3;
|
|
6741
|
-
exports.HAEDAL = HAEDAL;
|
|
6742
|
-
exports.KRIYA = KRIYA;
|
|
6743
|
-
exports.KRIYAV3 = KRIYAV3;
|
|
6744
|
-
exports.ONE = ONE;
|
|
6745
|
-
exports.SCALLOP = SCALLOP;
|
|
6746
|
-
exports.TEN_POW_NINE = TEN_POW_NINE;
|
|
6747
|
-
exports.TURBOS = TURBOS;
|
|
6748
|
-
exports.TWO = TWO;
|
|
6749
|
-
exports.U128 = U128;
|
|
6750
|
-
exports.U64_MAX = U64_MAX;
|
|
6751
|
-
exports.U64_MAX_BN = U64_MAX_BN;
|
|
6752
|
-
exports.VOLO = VOLO;
|
|
6753
|
-
exports.ZERO = ZERO;
|
|
6754
|
-
exports.buildInputCoin = buildInputCoin;
|
|
6755
|
-
exports.checkInvalidSuiAddress = checkInvalidSuiAddress;
|
|
6756
|
-
exports.compareCoins = compareCoins;
|
|
6757
|
-
exports.completionCoin = completionCoin;
|
|
6758
|
-
exports.composeType = composeType;
|
|
6759
|
-
exports.createTarget = createTarget;
|
|
6760
|
-
exports.dealWithFastRouterSwapParamsForMsafe = dealWithFastRouterSwapParamsForMsafe;
|
|
6761
|
-
exports.extractAddressFromType = extractAddressFromType;
|
|
6762
|
-
exports.extractStructTagFromType = extractStructTagFromType;
|
|
6763
|
-
exports.fixSuiObjectId = fixSuiObjectId;
|
|
6764
|
-
exports.getDeepbookV3Config = getDeepbookV3Config;
|
|
6765
|
-
exports.getRouterResult = getRouterResult;
|
|
6766
|
-
exports.isSortedSymbols = isSortedSymbols;
|
|
6767
|
-
exports.mintZeroCoin = mintZeroCoin;
|
|
6768
|
-
exports.normalizeCoinType = normalizeCoinType;
|
|
6769
|
-
exports.parseRouterResponse = parseRouterResponse;
|
|
6770
|
-
exports.patchFixSuiObjectId = patchFixSuiObjectId;
|
|
6771
|
-
exports.printTransaction = printTransaction;
|
|
6772
|
-
exports.processEndpoint = processEndpoint;
|
|
6773
|
-
exports.restituteMsafeFastRouterSwapParams = restituteMsafeFastRouterSwapParams;
|
|
6734
|
+
export { AFSUI, AFTERMATH, AggregatorClient8 as AggregatorClient, BLUEMOVE, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, Env, FLOWXV2, FLOWXV3, HAEDAL, KRIYA, KRIYAV3, ONE, SCALLOP, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
|
package/dist/src/client.d.ts
CHANGED
|
@@ -56,7 +56,7 @@ export declare class AggregatorClient {
|
|
|
56
56
|
env: Env;
|
|
57
57
|
private allCoins;
|
|
58
58
|
constructor(endpoint?: string, signer?: string, client?: SuiClient, env?: Env);
|
|
59
|
-
|
|
59
|
+
getCoins(coinType: string, refresh?: boolean): Promise<CoinAsset[]>;
|
|
60
60
|
findRouters(params: FindRouterParams): Promise<RouterData | null>;
|
|
61
61
|
expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
62
62
|
expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string): Promise<TransactionObjectArgument>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { SwapInPoolsParams } from "~/client";
|
|
2
|
-
import { SwapInPoolsResult } from "..";
|
|
2
|
+
import { Env, SwapInPoolsResult } from "..";
|
|
3
3
|
import { SuiClient } from "@mysten/sui/client";
|
|
4
|
-
export declare function swapInPools(client: SuiClient, params: SwapInPoolsParams, sender: string): Promise<SwapInPoolsResult>;
|
|
4
|
+
export declare function swapInPools(client: SuiClient, params: SwapInPoolsParams, sender: string, env: Env): Promise<SwapInPoolsResult>;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
export declare const T_USDC = "";
|
|
1
|
+
export declare const T_USDC = "0x26b3bc67befc214058ca78ea9a2690298d731a2d4309485ec3d40198063c4abc::usdc::USDC";
|
|
2
|
+
export declare const T_USDT = "0x26b3bc67befc214058ca78ea9a2690298d731a2d4309485ec3d40198063c4abc::usdt::USDT";
|
|
2
3
|
export declare const T_DEEP = "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP";
|
|
3
4
|
export declare const T_DBUSDC = "0xf7152c05930480cd740d7311b5b8b45c6f488e3a53a11c3f74a6fac36a52e0d7::DBUSDC::DBUSDC";
|
|
4
5
|
export declare const T_DBUSDT = "0xf7152c05930480cd740d7311b5b8b45c6f488e3a53a11c3f74a6fac36a52e0d7::DBUSDT::DBUSDT";
|
|
5
|
-
export declare const M_USDC = "
|
|
6
|
+
export declare const M_USDC = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
|
|
7
|
+
export declare const M_wUSDC = "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN";
|
|
6
8
|
export declare const M_CETUS = "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS";
|
|
7
9
|
export declare const M_NAVI = "0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX";
|
|
8
10
|
export declare const M_SUI = "0x2::sui::SUI";
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -95,42 +95,53 @@ export class AggregatorClient {
|
|
|
95
95
|
public signer: string
|
|
96
96
|
public client: SuiClient
|
|
97
97
|
public env: Env
|
|
98
|
-
private allCoins: CoinAsset[]
|
|
98
|
+
private allCoins: Map<string, CoinAsset[]>
|
|
99
99
|
|
|
100
100
|
constructor(endpoint?: string, signer?: string, client?: SuiClient, env?: Env) {
|
|
101
101
|
this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT
|
|
102
102
|
this.client = client || new SuiClient({url: getFullnodeUrl('mainnet')})
|
|
103
103
|
this.signer = signer || ""
|
|
104
104
|
this.env = env || Env.Mainnet
|
|
105
|
-
this.allCoins = []
|
|
105
|
+
this.allCoins = new Map<string, CoinAsset[]>()
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
async
|
|
108
|
+
async getCoins(coinType: string, refresh: boolean = true): Promise<CoinAsset[]> {
|
|
109
109
|
if (this.signer === "") {
|
|
110
110
|
throw new Error("Signer is required, but not provided.")
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
let cursor = null
|
|
114
114
|
let limit = 50
|
|
115
|
+
|
|
116
|
+
if (!refresh) {
|
|
117
|
+
const gotFromCoins = this.allCoins.get(coinType)
|
|
118
|
+
if (gotFromCoins) {
|
|
119
|
+
return gotFromCoins
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
115
123
|
const allCoins: CoinAsset[] = []
|
|
116
124
|
while (true) {
|
|
117
|
-
const
|
|
125
|
+
const gotCoins = await this.client.getCoins({
|
|
118
126
|
owner: this.signer,
|
|
127
|
+
coinType,
|
|
119
128
|
cursor,
|
|
120
129
|
limit,
|
|
121
130
|
})
|
|
122
|
-
for (const coin of
|
|
131
|
+
for (const coin of gotCoins.data) {
|
|
123
132
|
allCoins.push({
|
|
124
133
|
coinAddress: extractStructTagFromType(coin.coinType).source_address,
|
|
125
134
|
coinObjectId: coin.coinObjectId,
|
|
126
135
|
balance: BigInt(coin.balance),
|
|
127
136
|
})
|
|
128
137
|
}
|
|
129
|
-
if (
|
|
138
|
+
if (gotCoins.data.length < limit) {
|
|
130
139
|
break
|
|
131
140
|
}
|
|
132
|
-
cursor =
|
|
141
|
+
cursor = gotCoins.data[limit - 1].coinObjectId
|
|
133
142
|
}
|
|
143
|
+
|
|
144
|
+
this.allCoins.set(coinType, allCoins)
|
|
134
145
|
return allCoins
|
|
135
146
|
}
|
|
136
147
|
|
|
@@ -235,7 +246,7 @@ export class AggregatorClient {
|
|
|
235
246
|
): Promise<SwapInPoolsResult | null> {
|
|
236
247
|
let result
|
|
237
248
|
try {
|
|
238
|
-
result = await swapInPools(this.client, params, this.signer)
|
|
249
|
+
result = await swapInPools(this.client, params, this.signer, this.env)
|
|
239
250
|
} catch (e) {
|
|
240
251
|
console.error("swapInPools error:", e)
|
|
241
252
|
return null
|
|
@@ -300,10 +311,12 @@ export class AggregatorClient {
|
|
|
300
311
|
refreshAllCoins,
|
|
301
312
|
payDeepFeeAmount,
|
|
302
313
|
} = params
|
|
303
|
-
|
|
304
|
-
this.allCoins = await this.getAllCoins()
|
|
305
|
-
}
|
|
314
|
+
|
|
306
315
|
const fromCoinType = routers[0].path[0].from
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
let fromCoins = await this.getCoins(fromCoinType, refreshAllCoins)
|
|
319
|
+
|
|
307
320
|
const targetCoinType = routers[0].path[routers[0].path.length - 1].target
|
|
308
321
|
const amountIn = routers.reduce(
|
|
309
322
|
(acc, router) => acc.add(router.amountIn),
|
|
@@ -321,16 +334,17 @@ export class AggregatorClient {
|
|
|
321
334
|
const amount = byAmountIn ? amountIn : amountLimit
|
|
322
335
|
const buildFromCoinRes = buildInputCoin(
|
|
323
336
|
txb,
|
|
324
|
-
|
|
337
|
+
fromCoins,
|
|
325
338
|
BigInt(amount.toString()),
|
|
326
339
|
fromCoinType
|
|
327
340
|
)
|
|
328
341
|
|
|
329
342
|
let deepCoin
|
|
330
343
|
if (payDeepFeeAmount && payDeepFeeAmount > 0) {
|
|
344
|
+
let deepCoins = await this.getCoins(this.deepbookv3DeepFeeType())
|
|
331
345
|
deepCoin = buildInputCoin(
|
|
332
346
|
txb,
|
|
333
|
-
|
|
347
|
+
deepCoins,
|
|
334
348
|
BigInt(payDeepFeeAmount),
|
|
335
349
|
this.deepbookv3DeepFeeType()
|
|
336
350
|
).targetCoin
|
|
@@ -347,9 +361,10 @@ export class AggregatorClient {
|
|
|
347
361
|
})
|
|
348
362
|
|
|
349
363
|
if (isMergeTragetCoin) {
|
|
364
|
+
let targetCoins = await this.getCoins(targetCoinType, refreshAllCoins)
|
|
350
365
|
const targetCoinRes = buildInputCoin(
|
|
351
366
|
txb,
|
|
352
|
-
|
|
367
|
+
targetCoins,
|
|
353
368
|
BigInt(0),
|
|
354
369
|
targetCoinType
|
|
355
370
|
)
|
|
@@ -369,9 +384,10 @@ export class AggregatorClient {
|
|
|
369
384
|
// Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
|
|
370
385
|
publishedAt(): string {
|
|
371
386
|
if (this.env === Env.Mainnet) {
|
|
372
|
-
return "
|
|
387
|
+
return "0x11451575c775a3e633437b827ecbc1eb51a5964b0302210b28f5b89880be21a2" // version 5
|
|
373
388
|
} else {
|
|
374
|
-
return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637"
|
|
389
|
+
// return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637" // version 2
|
|
390
|
+
return "0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934"
|
|
375
391
|
}
|
|
376
392
|
}
|
|
377
393
|
|
|
@@ -381,7 +397,7 @@ export class AggregatorClient {
|
|
|
381
397
|
// return "0x43811be4677f5a5de7bf2dac740c10abddfaa524aee6b18e910eeadda8a2f6ae" // version 1, deepbookv3
|
|
382
398
|
return "0x6d70ffa7aa3f924c3f0b573d27d29895a0ee666aaff821073f75cb14af7fd01a" // version 3, deepbookv3 & scallop
|
|
383
399
|
} else {
|
|
384
|
-
return "
|
|
400
|
+
return "0xfd8a73ef0a4b928da9c27fc287dc37c1ca64df71da8e8eac7ca9ece55eb5f448"
|
|
385
401
|
}
|
|
386
402
|
}
|
|
387
403
|
|
package/src/transaction/cetus.ts
CHANGED
|
@@ -19,13 +19,13 @@ export class Cetus implements Dex {
|
|
|
19
19
|
this.globalConfig =
|
|
20
20
|
env === Env.Mainnet
|
|
21
21
|
? "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f"
|
|
22
|
-
: "
|
|
22
|
+
: "0x9774e359588ead122af1c7e7f64e14ade261cfeecdb5d0eb4a5b3b4c8ab8bd3e"
|
|
23
23
|
|
|
24
24
|
this.partner =
|
|
25
25
|
partner ??
|
|
26
26
|
(env === Env.Mainnet
|
|
27
27
|
? "0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b"
|
|
28
|
-
: "
|
|
28
|
+
: "0x1f5fa5c820f40d43fc47815ad06d95e40a1942ff72a732a92e8ef4aa8cde70a5")
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
flash_swap(
|
|
@@ -31,6 +31,7 @@ export class Scallop implements Dex {
|
|
|
31
31
|
): Promise<TransactionObjectArgument> {
|
|
32
32
|
const { direction, from, target } = path
|
|
33
33
|
|
|
34
|
+
// in scallop swap, the first coin type is always the common coin, the second coin type is always the special
|
|
34
35
|
const [func, coinAType, coinBType] = direction
|
|
35
36
|
? ["swap_a2b", from, target]
|
|
36
37
|
: ["swap_b2a", from, target]
|
package/src/transaction/swap.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { Transaction } from "@mysten/sui/transactions"
|
|
2
2
|
import { SwapInPoolsParams } from "~/client"
|
|
3
3
|
import { compareCoins, completionCoin } from "~/utils/coin"
|
|
4
|
-
import { SwapInPoolsResult, U64_MAX_BN, ZERO } from ".."
|
|
4
|
+
import { Env, SwapInPoolsResult, U64_MAX_BN, ZERO } from ".."
|
|
5
5
|
import { ConfigErrorCode, TransactionErrorCode } from "~/errors"
|
|
6
|
-
import { checkInvalidSuiAddress } from "~/utils/transaction"
|
|
6
|
+
import { checkInvalidSuiAddress, printTransaction } 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"
|
|
11
10
|
|
|
12
11
|
export async function swapInPools(
|
|
13
12
|
client: SuiClient,
|
|
14
13
|
params: SwapInPoolsParams,
|
|
15
|
-
sender: string
|
|
14
|
+
sender: string,
|
|
15
|
+
env: Env
|
|
16
16
|
): Promise<SwapInPoolsResult> {
|
|
17
17
|
const { from, target, amount, byAmountIn, pools } = params
|
|
18
18
|
const fromCoin = completionCoin(from)
|
|
@@ -20,15 +20,14 @@ export async function swapInPools(
|
|
|
20
20
|
|
|
21
21
|
const tx = new Transaction()
|
|
22
22
|
const direction = compareCoins(fromCoin, targetCoin)
|
|
23
|
-
const integratePublishedAt =
|
|
24
|
-
"
|
|
23
|
+
const integratePublishedAt = env === Env.Mainnet ?
|
|
24
|
+
"0x3a5aa90ffa33d09100d7b6941ea1c0ffe6ab66e77062ddd26320c1b073aabb10" :
|
|
25
|
+
"0x19dd42e05fa6c9988a60d30686ee3feb776672b5547e328d6dab16563da65293"
|
|
25
26
|
const coinA = direction ? fromCoin : targetCoin
|
|
26
27
|
const coinB = direction ? targetCoin : fromCoin
|
|
27
28
|
|
|
28
29
|
const typeArguments = [coinA, coinB]
|
|
29
|
-
console.log("typeArguments", typeArguments)
|
|
30
|
-
|
|
31
|
-
console.log("pools", pools)
|
|
30
|
+
console.log("typeArguments", typeArguments, integratePublishedAt)
|
|
32
31
|
|
|
33
32
|
for (let i = 0; i < pools.length; i++) {
|
|
34
33
|
const args = [
|
|
@@ -51,6 +50,8 @@ export async function swapInPools(
|
|
|
51
50
|
)
|
|
52
51
|
}
|
|
53
52
|
|
|
53
|
+
printTransaction(tx)
|
|
54
|
+
|
|
54
55
|
const simulateRes = await client.devInspectTransactionBlock({
|
|
55
56
|
transactionBlock: tx,
|
|
56
57
|
sender,
|
|
@@ -97,7 +98,6 @@ export async function swapInPools(
|
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
const event = valueData[tempIndex].parsedJson.data
|
|
100
|
-
console.log("event", JSON.stringify(event, null, 2))
|
|
101
101
|
|
|
102
102
|
const currentSqrtPrice = event.step_results[0].current_sqrt_price
|
|
103
103
|
|
package/tests/router.test.ts
CHANGED
|
@@ -1,21 +1,7 @@
|
|
|
1
1
|
import { describe, test } from "@jest/globals"
|
|
2
2
|
import dotenv from "dotenv"
|
|
3
3
|
import { AggregatorClient } from "~/client"
|
|
4
|
-
import
|
|
5
|
-
M_CETUS,
|
|
6
|
-
M_ETH,
|
|
7
|
-
M_HASUI,
|
|
8
|
-
M_MICHI,
|
|
9
|
-
M_NAVI,
|
|
10
|
-
M_SHaSUI,
|
|
11
|
-
M_SSUI,
|
|
12
|
-
M_SSWP,
|
|
13
|
-
M_SUI,
|
|
14
|
-
M_USDC,
|
|
15
|
-
T_DBUSDC,
|
|
16
|
-
T_DBUSDT,
|
|
17
|
-
T_DEEP,
|
|
18
|
-
} from "./test_data.test"
|
|
4
|
+
import * as testData from "./test_data.test"
|
|
19
5
|
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"
|
|
20
6
|
import { printTransaction } from "~/utils/transaction"
|
|
21
7
|
import BN from "bn.js"
|
|
@@ -47,48 +33,40 @@ describe("router module", () => {
|
|
|
47
33
|
keypair = buildTestAccount()
|
|
48
34
|
}
|
|
49
35
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// console.log("wallet", wallet, "\n", wallet.toString())
|
|
53
|
-
|
|
54
|
-
// const wallet =
|
|
55
|
-
// "0x2a6174f94a2c1d648de290297be27867527a6aaa263a4e0a567c9cd7656d3651"
|
|
56
|
-
const wallet =
|
|
57
|
-
"0xca171941521153181ff729d53489eaae7e99c3f4692884afd7cca61154e4cec4"
|
|
58
|
-
// const wallet =
|
|
59
|
-
// "0xaabf2fedcb36146db164bec930b74a47969c4df98216e049342a3c49b6d11580"
|
|
60
|
-
// const wallet = "0x410456cfc689666936b6bf80fbec958b69499b9f7183ecba07de577c17248a44"
|
|
61
|
-
// const wallet = "0xca171941521153181ff729d53489eaae7e99c3f4692884afd7cca61154e4cec4"
|
|
36
|
+
const wallet = keypair.getPublicKey().toSuiAddress()
|
|
62
37
|
console.log("wallet: ", wallet)
|
|
63
38
|
|
|
64
|
-
const endpoint =
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// "https://api-sui.devcetus.com/router_v2/find_routes"
|
|
39
|
+
// // const endpoint =
|
|
40
|
+
// // "https://api-sui-cloudfront.cetus.zone/router_v2/find_routes"
|
|
41
|
+
const endpoint = aggregatorURL
|
|
68
42
|
|
|
69
43
|
const suiClient = new SuiClient({
|
|
70
|
-
url:
|
|
44
|
+
url: fullNodeURL,
|
|
71
45
|
})
|
|
46
|
+
// const suiClient = new SuiClient({
|
|
47
|
+
// url: "https://fullnode.testnet.sui.io:443",
|
|
48
|
+
// })
|
|
49
|
+
|
|
72
50
|
client = new AggregatorClient(endpoint, wallet, suiClient, Env.Mainnet)
|
|
73
51
|
})
|
|
74
52
|
|
|
75
|
-
test("Get
|
|
76
|
-
return client.
|
|
53
|
+
test("Get coins", () => {
|
|
54
|
+
return client.getCoins(testData.M_wUSDC).then((coins) => {
|
|
77
55
|
console.log(coins)
|
|
78
56
|
})
|
|
79
57
|
})
|
|
80
58
|
|
|
81
59
|
test("Downgrade swap in route", async () => {
|
|
82
|
-
const amount =
|
|
60
|
+
const amount = 1000000
|
|
83
61
|
const byAmountIn = true
|
|
84
62
|
|
|
85
63
|
const res: any = await client.swapInPools({
|
|
86
|
-
from:
|
|
87
|
-
target:
|
|
64
|
+
from: testData.M_USDC,
|
|
65
|
+
target: testData.M_SUI,
|
|
88
66
|
amount: new BN(amount),
|
|
89
67
|
byAmountIn,
|
|
90
68
|
pools: [
|
|
91
|
-
'
|
|
69
|
+
'0xb8d7d9e66a60c239e7a60110efcf8de6c705580ed924d0dde141f4a0e2c90105'
|
|
92
70
|
],
|
|
93
71
|
})
|
|
94
72
|
|
|
@@ -106,6 +84,8 @@ describe("router module", () => {
|
|
|
106
84
|
refreshAllCoins: true,
|
|
107
85
|
})
|
|
108
86
|
|
|
87
|
+
printTransaction(txb)
|
|
88
|
+
|
|
109
89
|
let result = await client.devInspectTransactionBlock(txb)
|
|
110
90
|
console.log("🚀 ~ file: router.test.ts:114 ~ test ~ result:", result)
|
|
111
91
|
}
|
|
@@ -114,8 +94,8 @@ describe("router module", () => {
|
|
|
114
94
|
test("Find router", async () => {
|
|
115
95
|
const amount = "4239267610000000000"
|
|
116
96
|
const res = await client.findRouters({
|
|
117
|
-
from: M_SUI,
|
|
118
|
-
target: M_USDC,
|
|
97
|
+
from: testData.M_SUI,
|
|
98
|
+
target: testData.M_USDC,
|
|
119
99
|
amount: new BN(amount),
|
|
120
100
|
byAmountIn: true,
|
|
121
101
|
depth: 3,
|
|
@@ -132,9 +112,9 @@ describe("router module", () => {
|
|
|
132
112
|
|
|
133
113
|
test("Build router tx", async () => {
|
|
134
114
|
const byAmountIn = true
|
|
135
|
-
const amount = "
|
|
136
|
-
const target =
|
|
137
|
-
const from =
|
|
115
|
+
const amount = "320000"
|
|
116
|
+
const target = "0x2::sui::SUI"
|
|
117
|
+
const from = "0x26b3bc67befc214058ca78ea9a2690298d731a2d4309485ec3d40198063c4abc::eth::ETH"
|
|
138
118
|
|
|
139
119
|
const res = await client.findRouters({
|
|
140
120
|
from,
|
|
@@ -172,6 +152,7 @@ describe("router module", () => {
|
|
|
172
152
|
txb,
|
|
173
153
|
slippage: 0.01,
|
|
174
154
|
isMergeTragetCoin: false,
|
|
155
|
+
partner: "0x1f5fa5c820f40d43fc47815ad06d95e40a1942ff72a732a92e8ef4aa8cde70a5",
|
|
175
156
|
refreshAllCoins: true,
|
|
176
157
|
payDeepFeeAmount: 0,
|
|
177
158
|
})
|
|
@@ -195,8 +176,8 @@ describe("router module", () => {
|
|
|
195
176
|
const byAmountIn = false
|
|
196
177
|
const amount = "10000000000"
|
|
197
178
|
|
|
198
|
-
const from = M_USDC
|
|
199
|
-
const target = M_SSWP
|
|
179
|
+
const from = testData.M_USDC
|
|
180
|
+
const target = testData.M_SSWP
|
|
200
181
|
|
|
201
182
|
const res = await client.findRouters({
|
|
202
183
|
from,
|
|
@@ -238,8 +219,8 @@ describe("router module", () => {
|
|
|
238
219
|
|
|
239
220
|
test("Test Multi Input", async () => {
|
|
240
221
|
const amounts = [1000000000, 2000000000, 10000000000000]
|
|
241
|
-
const froms = [M_USDC, M_SUI, M_CETUS, M_NAVI]
|
|
242
|
-
const tos = [M_SUI, M_USDC, M_USDC, M_SUI]
|
|
222
|
+
const froms = [testData.M_USDC, testData.M_SUI, testData.M_CETUS, testData.M_NAVI]
|
|
223
|
+
const tos = [testData.M_SUI, testData.M_USDC, testData.M_USDC, testData.M_SUI]
|
|
243
224
|
|
|
244
225
|
for (let i = 0; i < froms.length; i++) {
|
|
245
226
|
const from = froms[i]
|
|
@@ -295,13 +276,13 @@ describe("router module", () => {
|
|
|
295
276
|
// const from = M_USDC
|
|
296
277
|
// const target = M_SUI
|
|
297
278
|
|
|
298
|
-
const from = M_SUI
|
|
279
|
+
const from = testData.M_SUI
|
|
299
280
|
// const target =
|
|
300
281
|
// "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
301
282
|
// const target =
|
|
302
283
|
// "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI"
|
|
303
284
|
|
|
304
|
-
const target = M_HASUI
|
|
285
|
+
const target = testData.M_HASUI
|
|
305
286
|
|
|
306
287
|
const res = await client.findRouters({
|
|
307
288
|
from,
|
package/tests/test_data.test.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
// Testnet
|
|
2
|
-
export const T_USDC = ""
|
|
2
|
+
export const T_USDC = "0x26b3bc67befc214058ca78ea9a2690298d731a2d4309485ec3d40198063c4abc::usdc::USDC"
|
|
3
|
+
export const T_USDT = "0x26b3bc67befc214058ca78ea9a2690298d731a2d4309485ec3d40198063c4abc::usdt::USDT"
|
|
3
4
|
export const T_DEEP = "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP"
|
|
4
5
|
export const T_DBUSDC = "0xf7152c05930480cd740d7311b5b8b45c6f488e3a53a11c3f74a6fac36a52e0d7::DBUSDC::DBUSDC"
|
|
5
6
|
export const T_DBUSDT = "0xf7152c05930480cd740d7311b5b8b45c6f488e3a53a11c3f74a6fac36a52e0d7::DBUSDT::DBUSDT"
|
|
6
7
|
|
|
7
8
|
// Mainnet
|
|
8
|
-
export const M_USDC =
|
|
9
|
+
export const M_USDC = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"
|
|
10
|
+
export const M_wUSDC =
|
|
9
11
|
"0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN"
|
|
10
12
|
export const M_CETUS =
|
|
11
13
|
"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS"
|