@cetusprotocol/aggregator-sdk 0.0.0-experimental-20241113171032 → 0.0.0-experimental-20241121205059

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 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
- import { SuiClient, getFullnodeUrl } from '@mysten/sui/client';
2
- import { normalizeSuiObjectId, SUI_FRAMEWORK_ADDRESS } from '@mysten/sui/utils';
3
- import { Transaction } from '@mysten/sui/transactions';
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
- !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
52
+ __defProp(target, "default", { value: mod2, enumerable: true }) ,
51
53
  mod2
52
54
  ));
53
55
  var __async = (__this, __arguments, generator) => {
@@ -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
  }
@@ -5768,9 +5770,9 @@ function swapInPools(client, params, sender, env) {
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 = env === 0 /* Mainnet */ ? "0x15c0555d7601d98ca2659a8387d377a81b1e285ee0808484e101f96d05806187" : "0x2918cf39850de6d5d94d8196dc878c8c722cd79db659318e00bff57fbb4e2ede";
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];
@@ -6035,6 +6037,43 @@ var DeepbookV3 = class {
6035
6037
  }
6036
6038
  };
6037
6039
 
6040
+ // src/transaction/scallop.ts
6041
+ var Scallop = class {
6042
+ constructor(env) {
6043
+ if (env !== 0 /* Mainnet */) {
6044
+ throw new Error("Scallop only supported on mainnet");
6045
+ }
6046
+ this.version = env === 0 /* Mainnet */ ? "0x07871c4b3c847a0f674510d4978d5cf6f960452795e8ff6f189fd2088a3f6ac7" : "0x0";
6047
+ this.market = env === 0 /* Mainnet */ ? "0xa757975255146dc9686aa823b7838b507f315d704f428cbadad2f4ea061939d9" : "0x0";
6048
+ }
6049
+ swap(client, txb, path, inputCoin) {
6050
+ return __async(this, null, function* () {
6051
+ const { direction, from, target } = path;
6052
+ const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", from, target];
6053
+ if (path.extendedDetails == null) {
6054
+ throw new Error("Extended details not supported");
6055
+ } else {
6056
+ if (path.extendedDetails.scallopScoinTreasury == null) {
6057
+ throw new Error("Scallop coin treasury not supported");
6058
+ }
6059
+ }
6060
+ const args = [
6061
+ txb.object(this.version),
6062
+ txb.object(this.market),
6063
+ txb.object(path.extendedDetails.scallopScoinTreasury),
6064
+ inputCoin,
6065
+ txb.object(CLOCK_ADDRESS)
6066
+ ];
6067
+ const res = txb.moveCall({
6068
+ target: `${client.publishedAtV2()}::scallop::${func}`,
6069
+ typeArguments: [coinAType, coinBType],
6070
+ arguments: args
6071
+ });
6072
+ return res;
6073
+ });
6074
+ }
6075
+ };
6076
+
6038
6077
  // src/client.ts
6039
6078
  var CETUS = "CETUS";
6040
6079
  var DEEPBOOKV2 = "DEEPBOOK";
@@ -6049,11 +6088,12 @@ var VOLO = "VOLO";
6049
6088
  var AFSUI = "AFSUI";
6050
6089
  var BLUEMOVE = "BLUEMOVE";
6051
6090
  var DEEPBOOKV3 = "DEEPBOOKV3";
6091
+ var SCALLOP = "SCALLOP";
6052
6092
  var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
6053
- var AggregatorClient7 = class {
6054
- constructor(endpoint, signer, client, env) {
6093
+ var AggregatorClient8 = class {
6094
+ constructor(endpoint, signer, client$1, env) {
6055
6095
  this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
6056
- this.client = client || new SuiClient({ url: getFullnodeUrl("mainnet") });
6096
+ this.client = client$1 || new client.SuiClient({ url: client.getFullnodeUrl("mainnet") });
6057
6097
  this.signer = signer || "";
6058
6098
  this.env = env || 0 /* Mainnet */;
6059
6099
  this.allCoins = /* @__PURE__ */ new Map();
@@ -6171,7 +6211,7 @@ var AggregatorClient7 = class {
6171
6211
  if (targetCoins.length > 1) {
6172
6212
  const vec = txb.makeMoveVec({ elements: targetCoins.slice(1) });
6173
6213
  txb.moveCall({
6174
- target: `${SUI_FRAMEWORK_ADDRESS}::pay::join_vec`,
6214
+ target: `${utils.SUI_FRAMEWORK_ADDRESS}::pay::join_vec`,
6175
6215
  typeArguments: [routers[0].path[routers[0].path.length - 1].target],
6176
6216
  arguments: [targetCoins[0], vec]
6177
6217
  });
@@ -6311,17 +6351,17 @@ var AggregatorClient7 = class {
6311
6351
  // Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
6312
6352
  publishedAt() {
6313
6353
  if (this.env === 0 /* Mainnet */) {
6314
- return "0xec2108d2092dd6f1f6fe45def639500e323596e0bab9fabc206461aadf357e6a";
6354
+ return "0x11451575c775a3e633437b827ecbc1eb51a5964b0302210b28f5b89880be21a2";
6315
6355
  } else {
6316
6356
  return "0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934";
6317
6357
  }
6318
6358
  }
6319
- // Include deepbookv3
6359
+ // Include deepbookv3, scallop
6320
6360
  publishedAtV2() {
6321
6361
  if (this.env === 0 /* Mainnet */) {
6322
- return "0x43811be4677f5a5de7bf2dac740c10abddfaa524aee6b18e910eeadda8a2f6ae";
6362
+ return "0x6d70ffa7aa3f924c3f0b573d27d29895a0ee666aaff821073f75cb14af7fd01a";
6323
6363
  } else {
6324
- return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637";
6364
+ return "0xfd8a73ef0a4b928da9c27fc287dc37c1ca64df71da8e8eac7ca9ece55eb5f448";
6325
6365
  }
6326
6366
  }
6327
6367
  deepbookv3DeepFeeType() {
@@ -6343,7 +6383,7 @@ var AggregatorClient7 = class {
6343
6383
  if (coins.length > 1) {
6344
6384
  let vec = txb.makeMoveVec({ elements: coins.slice(1) });
6345
6385
  txb.moveCall({
6346
- target: `${SUI_FRAMEWORK_ADDRESS}::pay::join_vec`,
6386
+ target: `${utils.SUI_FRAMEWORK_ADDRESS}::pay::join_vec`,
6347
6387
  typeArguments: [coinType],
6348
6388
  arguments: [coins[0], vec]
6349
6389
  });
@@ -6384,6 +6424,8 @@ var AggregatorClient7 = class {
6384
6424
  return new Volo(this.env);
6385
6425
  case BLUEMOVE:
6386
6426
  return new Bluemove(this.env);
6427
+ case SCALLOP:
6428
+ return new Scallop(this.env);
6387
6429
  default:
6388
6430
  throw new Error(`Unsupported dex ${provider}`);
6389
6431
  }
@@ -6447,18 +6489,19 @@ function parseRouterResponse(data) {
6447
6489
  routes: data.routes.map((route) => {
6448
6490
  return {
6449
6491
  path: route.path.map((path) => {
6450
- var _a, _b, _c, _d;
6492
+ var _a, _b, _c, _d, _e;
6451
6493
  let version;
6452
6494
  if (path.provider === AFTERMATH) {
6453
6495
  version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
6454
6496
  }
6455
6497
  let extendedDetails;
6456
- if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3) {
6498
+ if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3 || path.provider === SCALLOP) {
6457
6499
  extendedDetails = {
6458
6500
  aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
6459
6501
  turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
6460
6502
  afterSqrtPrice: (_c = path.extended_details) == null ? void 0 : _c.after_sqrt_price,
6461
- deepbookv3DeepFee: (_d = path.extended_details) == null ? void 0 : _d.deepbookv3_deep_fee
6503
+ deepbookv3DeepFee: (_d = path.extended_details) == null ? void 0 : _d.deepbookv3_deep_fee,
6504
+ scallopScoinTreasury: (_e = path.extended_details) == null ? void 0 : _e.scallop_scoin_treasury
6462
6505
  };
6463
6506
  }
6464
6507
  return {
@@ -6600,7 +6643,7 @@ function getRouter(endpoint, params) {
6600
6643
  url += `&providers=${providers.join(",")}`;
6601
6644
  }
6602
6645
  }
6603
- url += "&v=1000302";
6646
+ url += "&v=1000304";
6604
6647
  const response = yield fetch(url);
6605
6648
  return response;
6606
6649
  } catch (error) {
@@ -6690,4 +6733,48 @@ decimal.js/decimal.mjs:
6690
6733
  *)
6691
6734
  */
6692
6735
 
6693
- export { AFSUI, AFTERMATH, AggregatorClient7 as AggregatorClient, BLUEMOVE, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, Env, FLOWXV2, FLOWXV3, HAEDAL, KRIYA, KRIYAV3, ONE, 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 };
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;
@@ -73,6 +73,7 @@ declare const VOLO = "VOLO";
73
73
  declare const AFSUI = "AFSUI";
74
74
  declare const BLUEMOVE = "BLUEMOVE";
75
75
  declare const DEEPBOOKV3 = "DEEPBOOKV3";
76
+ declare const SCALLOP = "SCALLOP";
76
77
  declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
77
78
  type BuildRouterSwapParams = {
78
79
  routers: Router[];
@@ -202,6 +203,7 @@ type ExtendedDetails = {
202
203
  turbosFeeType?: string;
203
204
  afterSqrtPrice?: string;
204
205
  deepbookv3DeepFee?: number;
206
+ scallopScoinTreasury?: string;
205
207
  };
206
208
  type Path = {
207
209
  id: string;
@@ -263,4 +265,4 @@ declare enum Env {
263
265
  Testnet = 1
264
266
  }
265
267
 
266
- export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, type DeepbookV3Config, type DeepbookV3ConfigResponse, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, KRIYA, KRIYAV3, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, 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, fixSuiObjectId, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
268
+ export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, type DeepbookV3Config, type DeepbookV3ConfigResponse, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, KRIYA, KRIYAV3, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, SCALLOP, 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, fixSuiObjectId, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
package/dist/index.d.ts CHANGED
@@ -73,6 +73,7 @@ declare const VOLO = "VOLO";
73
73
  declare const AFSUI = "AFSUI";
74
74
  declare const BLUEMOVE = "BLUEMOVE";
75
75
  declare const DEEPBOOKV3 = "DEEPBOOKV3";
76
+ declare const SCALLOP = "SCALLOP";
76
77
  declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
77
78
  type BuildRouterSwapParams = {
78
79
  routers: Router[];
@@ -202,6 +203,7 @@ type ExtendedDetails = {
202
203
  turbosFeeType?: string;
203
204
  afterSqrtPrice?: string;
204
205
  deepbookv3DeepFee?: number;
206
+ scallopScoinTreasury?: string;
205
207
  };
206
208
  type Path = {
207
209
  id: string;
@@ -263,4 +265,4 @@ declare enum Env {
263
265
  Testnet = 1
264
266
  }
265
267
 
266
- export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, type DeepbookV3Config, type DeepbookV3ConfigResponse, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, KRIYA, KRIYAV3, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, 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, fixSuiObjectId, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
268
+ export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, type DeepbookV3Config, type DeepbookV3ConfigResponse, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, KRIYA, KRIYAV3, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, SCALLOP, 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, fixSuiObjectId, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
package/dist/index.js CHANGED
@@ -1,8 +1,6 @@
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');
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
- !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
50
+ __defProp(target, "default", { value: mod2, enumerable: true }) ,
53
51
  mod2
54
52
  ));
55
53
  var __async = (__this, __arguments, generator) => {
@@ -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" : utils.normalizeSuiObjectId(parts[0]),
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 utils.normalizeSuiObjectId(value);
5416
+ return normalizeSuiObjectId(value);
5419
5417
  }
5420
5418
  return value;
5421
5419
  }
@@ -5770,9 +5768,9 @@ function swapInPools(client, params, sender, env) {
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 transactions.Transaction();
5771
+ const tx = new Transaction();
5774
5772
  const direction = compareCoins(fromCoin, targetCoin);
5775
- const integratePublishedAt = env === 0 /* Mainnet */ ? "0x15c0555d7601d98ca2659a8387d377a81b1e285ee0808484e101f96d05806187" : "0x2918cf39850de6d5d94d8196dc878c8c722cd79db659318e00bff57fbb4e2ede";
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];
@@ -6037,6 +6035,43 @@ var DeepbookV3 = class {
6037
6035
  }
6038
6036
  };
6039
6037
 
6038
+ // src/transaction/scallop.ts
6039
+ var Scallop = class {
6040
+ constructor(env) {
6041
+ if (env !== 0 /* Mainnet */) {
6042
+ throw new Error("Scallop only supported on mainnet");
6043
+ }
6044
+ this.version = env === 0 /* Mainnet */ ? "0x07871c4b3c847a0f674510d4978d5cf6f960452795e8ff6f189fd2088a3f6ac7" : "0x0";
6045
+ this.market = env === 0 /* Mainnet */ ? "0xa757975255146dc9686aa823b7838b507f315d704f428cbadad2f4ea061939d9" : "0x0";
6046
+ }
6047
+ swap(client, txb, path, inputCoin) {
6048
+ return __async(this, null, function* () {
6049
+ const { direction, from, target } = path;
6050
+ const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", from, target];
6051
+ if (path.extendedDetails == null) {
6052
+ throw new Error("Extended details not supported");
6053
+ } else {
6054
+ if (path.extendedDetails.scallopScoinTreasury == null) {
6055
+ throw new Error("Scallop coin treasury not supported");
6056
+ }
6057
+ }
6058
+ const args = [
6059
+ txb.object(this.version),
6060
+ txb.object(this.market),
6061
+ txb.object(path.extendedDetails.scallopScoinTreasury),
6062
+ inputCoin,
6063
+ txb.object(CLOCK_ADDRESS)
6064
+ ];
6065
+ const res = txb.moveCall({
6066
+ target: `${client.publishedAtV2()}::scallop::${func}`,
6067
+ typeArguments: [coinAType, coinBType],
6068
+ arguments: args
6069
+ });
6070
+ return res;
6071
+ });
6072
+ }
6073
+ };
6074
+
6040
6075
  // src/client.ts
6041
6076
  var CETUS = "CETUS";
6042
6077
  var DEEPBOOKV2 = "DEEPBOOK";
@@ -6051,11 +6086,12 @@ var VOLO = "VOLO";
6051
6086
  var AFSUI = "AFSUI";
6052
6087
  var BLUEMOVE = "BLUEMOVE";
6053
6088
  var DEEPBOOKV3 = "DEEPBOOKV3";
6089
+ var SCALLOP = "SCALLOP";
6054
6090
  var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
6055
- var AggregatorClient7 = class {
6056
- constructor(endpoint, signer, client$1, env) {
6091
+ var AggregatorClient8 = class {
6092
+ constructor(endpoint, signer, client, env) {
6057
6093
  this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
6058
- this.client = client$1 || new client.SuiClient({ url: client.getFullnodeUrl("mainnet") });
6094
+ this.client = client || new SuiClient({ url: getFullnodeUrl("mainnet") });
6059
6095
  this.signer = signer || "";
6060
6096
  this.env = env || 0 /* Mainnet */;
6061
6097
  this.allCoins = /* @__PURE__ */ new Map();
@@ -6173,7 +6209,7 @@ var AggregatorClient7 = class {
6173
6209
  if (targetCoins.length > 1) {
6174
6210
  const vec = txb.makeMoveVec({ elements: targetCoins.slice(1) });
6175
6211
  txb.moveCall({
6176
- target: `${utils.SUI_FRAMEWORK_ADDRESS}::pay::join_vec`,
6212
+ target: `${SUI_FRAMEWORK_ADDRESS}::pay::join_vec`,
6177
6213
  typeArguments: [routers[0].path[routers[0].path.length - 1].target],
6178
6214
  arguments: [targetCoins[0], vec]
6179
6215
  });
@@ -6313,17 +6349,17 @@ var AggregatorClient7 = class {
6313
6349
  // Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
6314
6350
  publishedAt() {
6315
6351
  if (this.env === 0 /* Mainnet */) {
6316
- return "0xec2108d2092dd6f1f6fe45def639500e323596e0bab9fabc206461aadf357e6a";
6352
+ return "0x11451575c775a3e633437b827ecbc1eb51a5964b0302210b28f5b89880be21a2";
6317
6353
  } else {
6318
6354
  return "0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934";
6319
6355
  }
6320
6356
  }
6321
- // Include deepbookv3
6357
+ // Include deepbookv3, scallop
6322
6358
  publishedAtV2() {
6323
6359
  if (this.env === 0 /* Mainnet */) {
6324
- return "0x43811be4677f5a5de7bf2dac740c10abddfaa524aee6b18e910eeadda8a2f6ae";
6360
+ return "0x6d70ffa7aa3f924c3f0b573d27d29895a0ee666aaff821073f75cb14af7fd01a";
6325
6361
  } else {
6326
- return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637";
6362
+ return "0xfd8a73ef0a4b928da9c27fc287dc37c1ca64df71da8e8eac7ca9ece55eb5f448";
6327
6363
  }
6328
6364
  }
6329
6365
  deepbookv3DeepFeeType() {
@@ -6345,7 +6381,7 @@ var AggregatorClient7 = class {
6345
6381
  if (coins.length > 1) {
6346
6382
  let vec = txb.makeMoveVec({ elements: coins.slice(1) });
6347
6383
  txb.moveCall({
6348
- target: `${utils.SUI_FRAMEWORK_ADDRESS}::pay::join_vec`,
6384
+ target: `${SUI_FRAMEWORK_ADDRESS}::pay::join_vec`,
6349
6385
  typeArguments: [coinType],
6350
6386
  arguments: [coins[0], vec]
6351
6387
  });
@@ -6386,6 +6422,8 @@ var AggregatorClient7 = class {
6386
6422
  return new Volo(this.env);
6387
6423
  case BLUEMOVE:
6388
6424
  return new Bluemove(this.env);
6425
+ case SCALLOP:
6426
+ return new Scallop(this.env);
6389
6427
  default:
6390
6428
  throw new Error(`Unsupported dex ${provider}`);
6391
6429
  }
@@ -6449,18 +6487,19 @@ function parseRouterResponse(data) {
6449
6487
  routes: data.routes.map((route) => {
6450
6488
  return {
6451
6489
  path: route.path.map((path) => {
6452
- var _a, _b, _c, _d;
6490
+ var _a, _b, _c, _d, _e;
6453
6491
  let version;
6454
6492
  if (path.provider === AFTERMATH) {
6455
6493
  version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
6456
6494
  }
6457
6495
  let extendedDetails;
6458
- if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3) {
6496
+ if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3 || path.provider === SCALLOP) {
6459
6497
  extendedDetails = {
6460
6498
  aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
6461
6499
  turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
6462
6500
  afterSqrtPrice: (_c = path.extended_details) == null ? void 0 : _c.after_sqrt_price,
6463
- deepbookv3DeepFee: (_d = path.extended_details) == null ? void 0 : _d.deepbookv3_deep_fee
6501
+ deepbookv3DeepFee: (_d = path.extended_details) == null ? void 0 : _d.deepbookv3_deep_fee,
6502
+ scallopScoinTreasury: (_e = path.extended_details) == null ? void 0 : _e.scallop_scoin_treasury
6464
6503
  };
6465
6504
  }
6466
6505
  return {
@@ -6602,7 +6641,7 @@ function getRouter(endpoint, params) {
6602
6641
  url += `&providers=${providers.join(",")}`;
6603
6642
  }
6604
6643
  }
6605
- url += "&v=1000302";
6644
+ url += "&v=1000304";
6606
6645
  const response = yield fetch(url);
6607
6646
  return response;
6608
6647
  } catch (error) {
@@ -6692,47 +6731,4 @@ decimal.js/decimal.mjs:
6692
6731
  *)
6693
6732
  */
6694
6733
 
6695
- exports.AFSUI = AFSUI;
6696
- exports.AFTERMATH = AFTERMATH;
6697
- exports.AggregatorClient = AggregatorClient7;
6698
- exports.BLUEMOVE = BLUEMOVE;
6699
- exports.CETUS = CETUS;
6700
- exports.CLOCK_ADDRESS = CLOCK_ADDRESS;
6701
- exports.DEEPBOOKV2 = DEEPBOOKV2;
6702
- exports.DEEPBOOKV3 = DEEPBOOKV3;
6703
- exports.DEFAULT_ENDPOINT = DEFAULT_ENDPOINT;
6704
- exports.Env = Env;
6705
- exports.FLOWXV2 = FLOWXV2;
6706
- exports.FLOWXV3 = FLOWXV3;
6707
- exports.HAEDAL = HAEDAL;
6708
- exports.KRIYA = KRIYA;
6709
- exports.KRIYAV3 = KRIYAV3;
6710
- exports.ONE = ONE;
6711
- exports.TEN_POW_NINE = TEN_POW_NINE;
6712
- exports.TURBOS = TURBOS;
6713
- exports.TWO = TWO;
6714
- exports.U128 = U128;
6715
- exports.U64_MAX = U64_MAX;
6716
- exports.U64_MAX_BN = U64_MAX_BN;
6717
- exports.VOLO = VOLO;
6718
- exports.ZERO = ZERO;
6719
- exports.buildInputCoin = buildInputCoin;
6720
- exports.checkInvalidSuiAddress = checkInvalidSuiAddress;
6721
- exports.compareCoins = compareCoins;
6722
- exports.completionCoin = completionCoin;
6723
- exports.composeType = composeType;
6724
- exports.createTarget = createTarget;
6725
- exports.dealWithFastRouterSwapParamsForMsafe = dealWithFastRouterSwapParamsForMsafe;
6726
- exports.extractAddressFromType = extractAddressFromType;
6727
- exports.extractStructTagFromType = extractStructTagFromType;
6728
- exports.fixSuiObjectId = fixSuiObjectId;
6729
- exports.getDeepbookV3Config = getDeepbookV3Config;
6730
- exports.getRouterResult = getRouterResult;
6731
- exports.isSortedSymbols = isSortedSymbols;
6732
- exports.mintZeroCoin = mintZeroCoin;
6733
- exports.normalizeCoinType = normalizeCoinType;
6734
- exports.parseRouterResponse = parseRouterResponse;
6735
- exports.patchFixSuiObjectId = patchFixSuiObjectId;
6736
- exports.printTransaction = printTransaction;
6737
- exports.processEndpoint = processEndpoint;
6738
- 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/api.d.ts CHANGED
@@ -24,6 +24,7 @@ export type ExtendedDetails = {
24
24
  turbosFeeType?: string;
25
25
  afterSqrtPrice?: string;
26
26
  deepbookv3DeepFee?: number;
27
+ scallopScoinTreasury?: string;
27
28
  };
28
29
  export type Path = {
29
30
  id: string;
@@ -17,6 +17,7 @@ export declare const VOLO = "VOLO";
17
17
  export declare const AFSUI = "AFSUI";
18
18
  export declare const BLUEMOVE = "BLUEMOVE";
19
19
  export declare const DEEPBOOKV3 = "DEEPBOOKV3";
20
+ export declare const SCALLOP = "SCALLOP";
20
21
  export declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
21
22
  export type BuildRouterSwapParams = {
22
23
  routers: Router[];
@@ -0,0 +1,8 @@
1
+ import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
2
+ import { AggregatorClient, Dex, Env, Path } from "..";
3
+ export declare class Scallop implements Dex {
4
+ private version;
5
+ private market;
6
+ constructor(env: Env);
7
+ swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
8
+ }
@@ -13,3 +13,6 @@ export declare const M_VAPOR = "0xa1f2c11169f32165ad4efb4468ec5bdfc880cd66b22094
13
13
  export declare const M_HASUI = "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI";
14
14
  export declare const M_SSWP = "0x361dd589b98e8fcda9a7ee53b85efabef3569d00416640d2faa516e3801d7ffc::TOKEN::TOKEN";
15
15
  export declare const M_MICHI = "0x50d796fde5709a97883e29e00bf511d66f2656de958ea0c2ce4c1147cdd20a23::MICHI::MICHI";
16
+ export declare const M_SSUI = "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI";
17
+ export declare const M_SHaSUI = "0x9a2376943f7d22f88087c259c5889925f332ca4347e669dc37d54c2bf651af3c::scallop_ha_sui::SCALLOP_HA_SUI";
18
+ export declare const M_ETH = "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH";
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@cetusprotocol/aggregator-sdk",
3
- "version": "0.0.0-experimental-20241113171032",
3
+ "version": "0.0.0-experimental-20241121205059",
4
4
  "sideEffects": false,
5
5
  "main": "dist/index.js",
6
+ "type": "module",
6
7
  "types": "dist/index.d.ts",
7
8
  "module": "dist/index.js",
8
9
  "scripts": {
package/src/api.ts CHANGED
@@ -34,6 +34,7 @@ export type ExtendedDetails = {
34
34
  turbosFeeType?: string
35
35
  afterSqrtPrice?: string
36
36
  deepbookv3DeepFee?: number
37
+ scallopScoinTreasury?: string
37
38
  }
38
39
 
39
40
  export type Path = {
@@ -167,7 +168,7 @@ async function getRouter(endpoint: string, params: FindRouterParams) {
167
168
  }
168
169
 
169
170
  // set newest sdk version
170
- url += "&v=1000302"
171
+ url += "&v=1000304"
171
172
 
172
173
  const response = await fetch(url)
173
174
  return response
package/src/client.ts CHANGED
@@ -36,7 +36,7 @@ import { Bluemove } from "./transaction/bluemove"
36
36
  import { CoinAsset } from "./types/sui"
37
37
  import { buildInputCoin } from "./utils/coin"
38
38
  import { DeepbookV3 } from "./transaction/deepbook_v3"
39
-
39
+ import { Scallop } from "./transaction/scallop"
40
40
  export const CETUS = "CETUS"
41
41
  export const DEEPBOOKV2 = "DEEPBOOK"
42
42
  export const KRIYA = "KRIYA"
@@ -50,6 +50,7 @@ export const VOLO = "VOLO"
50
50
  export const AFSUI = "AFSUI"
51
51
  export const BLUEMOVE = "BLUEMOVE"
52
52
  export const DEEPBOOKV3 = "DEEPBOOKV3"
53
+ export const SCALLOP = "SCALLOP"
53
54
 
54
55
  export const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2"
55
56
 
@@ -383,19 +384,20 @@ export class AggregatorClient {
383
384
  // Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
384
385
  publishedAt(): string {
385
386
  if (this.env === Env.Mainnet) {
386
- return "0xec2108d2092dd6f1f6fe45def639500e323596e0bab9fabc206461aadf357e6a" // version 4
387
+ return "0x11451575c775a3e633437b827ecbc1eb51a5964b0302210b28f5b89880be21a2" // version 5
387
388
  } else {
388
389
  // return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637" // version 2
389
390
  return "0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934"
390
391
  }
391
392
  }
392
393
 
393
- // Include deepbookv3
394
+ // Include deepbookv3, scallop
394
395
  publishedAtV2(): string {
395
396
  if (this.env === Env.Mainnet) {
396
- return "0x43811be4677f5a5de7bf2dac740c10abddfaa524aee6b18e910eeadda8a2f6ae" // version 1
397
+ // return "0x43811be4677f5a5de7bf2dac740c10abddfaa524aee6b18e910eeadda8a2f6ae" // version 1, deepbookv3
398
+ return "0x6d70ffa7aa3f924c3f0b573d27d29895a0ee666aaff821073f75cb14af7fd01a" // version 3, deepbookv3 & scallop
397
399
  } else {
398
- return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637"
400
+ return "0xfd8a73ef0a4b928da9c27fc287dc37c1ca64df71da8e8eac7ca9ece55eb5f448"
399
401
  }
400
402
  }
401
403
 
@@ -472,6 +474,8 @@ export class AggregatorClient {
472
474
  return new Volo(this.env)
473
475
  case BLUEMOVE:
474
476
  return new Bluemove(this.env)
477
+ case SCALLOP:
478
+ return new Scallop(this.env)
475
479
  default:
476
480
  throw new Error(`Unsupported dex ${provider}`)
477
481
  }
@@ -545,7 +549,8 @@ export function parseRouterResponse(data: any): RouterData {
545
549
  path.provider === TURBOS ||
546
550
  path.provider === AFTERMATH ||
547
551
  path.provider === CETUS ||
548
- path.provider === DEEPBOOKV3
552
+ path.provider === DEEPBOOKV3 ||
553
+ path.provider === SCALLOP
549
554
  ) {
550
555
  extendedDetails = {
551
556
  aftermathLpSupplyType:
@@ -553,6 +558,7 @@ export function parseRouterResponse(data: any): RouterData {
553
558
  turbosFeeType: path.extended_details?.turbos_fee_type,
554
559
  afterSqrtPrice: path.extended_details?.after_sqrt_price,
555
560
  deepbookv3DeepFee: path.extended_details?.deepbookv3_deep_fee,
561
+ scallopScoinTreasury: path.extended_details?.scallop_scoin_treasury,
556
562
  }
557
563
  }
558
564
 
@@ -1,8 +1,6 @@
1
1
  import {
2
2
  Transaction,
3
- TransactionArgument,
4
3
  TransactionObjectArgument,
5
- TransactionResult,
6
4
  } from "@mysten/sui/transactions"
7
5
  import { AggregatorClient, Dex, Env, Path } from ".."
8
6
 
@@ -0,0 +1,63 @@
1
+ import {
2
+ Transaction,
3
+ TransactionObjectArgument,
4
+ } from "@mysten/sui/transactions"
5
+ import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, Path } from ".."
6
+
7
+ export class Scallop implements Dex {
8
+ private version: string
9
+ private market: string
10
+
11
+ constructor(env: Env) {
12
+ if (env !== Env.Mainnet) {
13
+ throw new Error("Scallop only supported on mainnet")
14
+ }
15
+
16
+ this.version = env === Env.Mainnet
17
+ ? "0x07871c4b3c847a0f674510d4978d5cf6f960452795e8ff6f189fd2088a3f6ac7"
18
+ : "0x0"
19
+
20
+ this.market =
21
+ env === Env.Mainnet
22
+ ? "0xa757975255146dc9686aa823b7838b507f315d704f428cbadad2f4ea061939d9"
23
+ : "0x0"
24
+ }
25
+
26
+ async swap(
27
+ client: AggregatorClient,
28
+ txb: Transaction,
29
+ path: Path,
30
+ inputCoin: TransactionObjectArgument
31
+ ): Promise<TransactionObjectArgument> {
32
+ const { direction, from, target } = path
33
+
34
+ // in scallop swap, the first coin type is always the common coin, the second coin type is always the special
35
+ const [func, coinAType, coinBType] = direction
36
+ ? ["swap_a2b", from, target]
37
+ : ["swap_b2a", from, target]
38
+
39
+ if (path.extendedDetails == null) {
40
+ throw new Error("Extended details not supported")
41
+ } else {
42
+ if (path.extendedDetails.scallopScoinTreasury == null) {
43
+ throw new Error("Scallop coin treasury not supported")
44
+ }
45
+ }
46
+
47
+ const args = [
48
+ txb.object(this.version),
49
+ txb.object(this.market),
50
+ txb.object(path.extendedDetails.scallopScoinTreasury),
51
+ inputCoin,
52
+ txb.object(CLOCK_ADDRESS),
53
+ ]
54
+
55
+ const res = txb.moveCall({
56
+ target: `${client.publishedAtV2()}::scallop::${func}`,
57
+ typeArguments: [coinAType, coinBType],
58
+ arguments: args,
59
+ }) as TransactionObjectArgument
60
+
61
+ return res
62
+ }
63
+ }
@@ -21,8 +21,8 @@ export async function swapInPools(
21
21
  const tx = new Transaction()
22
22
  const direction = compareCoins(fromCoin, targetCoin)
23
23
  const integratePublishedAt = env === Env.Mainnet ?
24
- "0x15c0555d7601d98ca2659a8387d377a81b1e285ee0808484e101f96d05806187" :
25
- "0x2918cf39850de6d5d94d8196dc878c8c722cd79db659318e00bff57fbb4e2ede"
24
+ "0x3a5aa90ffa33d09100d7b6941ea1c0ffe6ab66e77062ddd26320c1b073aabb10" :
25
+ "0x19dd42e05fa6c9988a60d30686ee3feb776672b5547e328d6dab16563da65293"
26
26
  const coinA = direction ? fromCoin : targetCoin
27
27
  const coinB = direction ? targetCoin : fromCoin
28
28
 
@@ -123,6 +123,7 @@ describe("router module", () => {
123
123
  byAmountIn,
124
124
  depth: 3,
125
125
  providers: [
126
+ "SCALLOP",
126
127
  "CETUS",
127
128
  // "DEEPBOOKV3",
128
129
  // "DEEPBOOK",
@@ -23,3 +23,6 @@ export const M_HASUI =
23
23
  export const M_SSWP =
24
24
  "0x361dd589b98e8fcda9a7ee53b85efabef3569d00416640d2faa516e3801d7ffc::TOKEN::TOKEN"
25
25
  export const M_MICHI = "0x50d796fde5709a97883e29e00bf511d66f2656de958ea0c2ce4c1147cdd20a23::MICHI::MICHI"
26
+ export const M_SSUI = "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI"
27
+ export const M_SHaSUI = "0x9a2376943f7d22f88087c259c5889925f332ca4347e669dc37d54c2bf651af3c::scallop_ha_sui::SCALLOP_HA_SUI"
28
+ export const M_ETH = "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH"