@cetusprotocol/aggregator-sdk 0.0.0-experimental-20241018200510 → 0.0.0-experimental-20241021144153

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts 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 DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
76
77
  type BuildRouterSwapParams = {
77
78
  routers: Router[];
78
79
  byAmountIn: boolean;
@@ -109,7 +110,7 @@ declare class AggregatorClient {
109
110
  client: SuiClient;
110
111
  env: Env;
111
112
  private allCoins;
112
- constructor(endpoint: string, signer: string, client: SuiClient, env: Env);
113
+ constructor(endpoint?: string, signer?: string, client?: SuiClient, env?: Env);
113
114
  getAllCoins(): Promise<CoinAsset[]>;
114
115
  findRouters(params: FindRouterParams): Promise<RouterData | null>;
115
116
  expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
@@ -118,7 +119,7 @@ declare class AggregatorClient {
118
119
  routerSwap(params: BuildRouterSwapParams): Promise<TransactionObjectArgument>;
119
120
  fastRouterSwap(params: BuildFastRouterSwapParams): Promise<void>;
120
121
  publishedAt(): string;
121
- publishedV2At(): string;
122
+ publishedAtV2(): string;
122
123
  deepbookv3DeepFeeType(): string;
123
124
  transferOrDestoryCoin(txb: Transaction, coin: TransactionObjectArgument, coinType: string): void;
124
125
  checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, amountLimit: BN): TransactionObjectArgument;
@@ -262,4 +263,4 @@ declare enum Env {
262
263
  Testnet = 1
263
264
  }
264
265
 
265
- export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, 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 };
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 };
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 DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
76
77
  type BuildRouterSwapParams = {
77
78
  routers: Router[];
78
79
  byAmountIn: boolean;
@@ -109,7 +110,7 @@ declare class AggregatorClient {
109
110
  client: SuiClient;
110
111
  env: Env;
111
112
  private allCoins;
112
- constructor(endpoint: string, signer: string, client: SuiClient, env: Env);
113
+ constructor(endpoint?: string, signer?: string, client?: SuiClient, env?: Env);
113
114
  getAllCoins(): Promise<CoinAsset[]>;
114
115
  findRouters(params: FindRouterParams): Promise<RouterData | null>;
115
116
  expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
@@ -118,7 +119,7 @@ declare class AggregatorClient {
118
119
  routerSwap(params: BuildRouterSwapParams): Promise<TransactionObjectArgument>;
119
120
  fastRouterSwap(params: BuildFastRouterSwapParams): Promise<void>;
120
121
  publishedAt(): string;
121
- publishedV2At(): string;
122
+ publishedAtV2(): string;
122
123
  deepbookv3DeepFeeType(): string;
123
124
  transferOrDestoryCoin(txb: Transaction, coin: TransactionObjectArgument, coinType: string): void;
124
125
  checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, amountLimit: BN): TransactionObjectArgument;
@@ -262,4 +263,4 @@ declare enum Env {
262
263
  Testnet = 1
263
264
  }
264
265
 
265
- export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, 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 };
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 };
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ var client = require('@mysten/sui/client');
3
4
  var utils = require('@mysten/sui/utils');
4
5
  var transactions = require('@mysten/sui/transactions');
5
6
 
@@ -6009,7 +6010,6 @@ var Bluemove = class {
6009
6010
  var DeepbookV3 = class {
6010
6011
  constructor(env) {
6011
6012
  this.deepbookV3Config = env === 0 /* Mainnet */ ? "0xa0c3e61f2f57045942f498cdc38c6347bd2e09e04a85ac33b866b84de5b5b141" : "0xe19b5d072346cae83a037d4e3c8492068a74410a74e5830b3a68012db38296aa";
6012
- this.deepCoinType = env === 0 /* Mainnet */ ? "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP" : "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP";
6013
6013
  }
6014
6014
  swap(client, txb, path, inputCoin, deepbookv3DeepFee) {
6015
6015
  return __async(this, null, function* () {
@@ -6019,7 +6019,7 @@ var DeepbookV3 = class {
6019
6019
  if (deepbookv3DeepFee) {
6020
6020
  deepFee = deepbookv3DeepFee;
6021
6021
  } else {
6022
- deepFee = mintZeroCoin(txb, this.deepCoinType);
6022
+ deepFee = mintZeroCoin(txb, client.deepbookv3DeepFeeType());
6023
6023
  }
6024
6024
  const args = [
6025
6025
  txb.object(this.deepbookV3Config),
@@ -6029,7 +6029,7 @@ var DeepbookV3 = class {
6029
6029
  txb.object(CLOCK_ADDRESS)
6030
6030
  ];
6031
6031
  const res = txb.moveCall({
6032
- target: `${client.publishedV2At()}::deepbookv3::${func}`,
6032
+ target: `${client.publishedAtV2()}::deepbookv3::${func}`,
6033
6033
  typeArguments: [coinAType, coinBType],
6034
6034
  arguments: args
6035
6035
  });
@@ -6052,16 +6052,20 @@ var VOLO = "VOLO";
6052
6052
  var AFSUI = "AFSUI";
6053
6053
  var BLUEMOVE = "BLUEMOVE";
6054
6054
  var DEEPBOOKV3 = "DEEPBOOKV3";
6055
+ var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
6055
6056
  var AggregatorClient7 = class {
6056
- constructor(endpoint, signer, client, env) {
6057
- this.endpoint = processEndpoint(endpoint);
6058
- this.client = client;
6059
- this.signer = signer;
6060
- this.env = env;
6057
+ constructor(endpoint, signer, client$1, env) {
6058
+ this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
6059
+ this.client = client$1 || new client.SuiClient({ url: client.getFullnodeUrl("mainnet") });
6060
+ this.signer = signer || "";
6061
+ this.env = env || 0 /* Mainnet */;
6061
6062
  this.allCoins = [];
6062
6063
  }
6063
6064
  getAllCoins() {
6064
6065
  return __async(this, null, function* () {
6066
+ if (this.signer === "") {
6067
+ throw new Error("Signer is required, but not provided.");
6068
+ }
6065
6069
  let cursor = null;
6066
6070
  let limit = 50;
6067
6071
  const allCoins = [];
@@ -6299,14 +6303,16 @@ var AggregatorClient7 = class {
6299
6303
  }
6300
6304
  });
6301
6305
  }
6306
+ // Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
6302
6307
  publishedAt() {
6303
6308
  if (this.env === 0 /* Mainnet */) {
6304
- return "0x868a192f542e819de99f8f289d7d6b47126e5da3103108fbc01d16cfd6be569a";
6309
+ return "0xf98ed029af555e4a103febf26243dc33ac09a7ea1b2da7e414c728b25b729086";
6305
6310
  } else {
6306
6311
  return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637";
6307
6312
  }
6308
6313
  }
6309
- publishedV2At() {
6314
+ // Include deepbookv3
6315
+ publishedAtV2() {
6310
6316
  if (this.env === 0 /* Mainnet */) {
6311
6317
  return "0x43ddba51e679811ea575c86bf0e0877015eef4d14320cc36c33847d06cf2bffe";
6312
6318
  } else {
@@ -6687,6 +6693,7 @@ exports.CETUS = CETUS;
6687
6693
  exports.CLOCK_ADDRESS = CLOCK_ADDRESS;
6688
6694
  exports.DEEPBOOKV2 = DEEPBOOKV2;
6689
6695
  exports.DEEPBOOKV3 = DEEPBOOKV3;
6696
+ exports.DEFAULT_ENDPOINT = DEFAULT_ENDPOINT;
6690
6697
  exports.Env = Env;
6691
6698
  exports.FLOWXV2 = FLOWXV2;
6692
6699
  exports.FLOWXV3 = FLOWXV3;
package/dist/index.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { SuiClient, getFullnodeUrl } from '@mysten/sui/client';
1
2
  import { normalizeSuiObjectId, SUI_FRAMEWORK_ADDRESS } from '@mysten/sui/utils';
2
3
  import { Transaction } from '@mysten/sui/transactions';
3
4
 
@@ -6007,7 +6008,6 @@ var Bluemove = class {
6007
6008
  var DeepbookV3 = class {
6008
6009
  constructor(env) {
6009
6010
  this.deepbookV3Config = env === 0 /* Mainnet */ ? "0xa0c3e61f2f57045942f498cdc38c6347bd2e09e04a85ac33b866b84de5b5b141" : "0xe19b5d072346cae83a037d4e3c8492068a74410a74e5830b3a68012db38296aa";
6010
- this.deepCoinType = env === 0 /* Mainnet */ ? "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP" : "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP";
6011
6011
  }
6012
6012
  swap(client, txb, path, inputCoin, deepbookv3DeepFee) {
6013
6013
  return __async(this, null, function* () {
@@ -6017,7 +6017,7 @@ var DeepbookV3 = class {
6017
6017
  if (deepbookv3DeepFee) {
6018
6018
  deepFee = deepbookv3DeepFee;
6019
6019
  } else {
6020
- deepFee = mintZeroCoin(txb, this.deepCoinType);
6020
+ deepFee = mintZeroCoin(txb, client.deepbookv3DeepFeeType());
6021
6021
  }
6022
6022
  const args = [
6023
6023
  txb.object(this.deepbookV3Config),
@@ -6027,7 +6027,7 @@ var DeepbookV3 = class {
6027
6027
  txb.object(CLOCK_ADDRESS)
6028
6028
  ];
6029
6029
  const res = txb.moveCall({
6030
- target: `${client.publishedV2At()}::deepbookv3::${func}`,
6030
+ target: `${client.publishedAtV2()}::deepbookv3::${func}`,
6031
6031
  typeArguments: [coinAType, coinBType],
6032
6032
  arguments: args
6033
6033
  });
@@ -6050,16 +6050,20 @@ var VOLO = "VOLO";
6050
6050
  var AFSUI = "AFSUI";
6051
6051
  var BLUEMOVE = "BLUEMOVE";
6052
6052
  var DEEPBOOKV3 = "DEEPBOOKV3";
6053
+ var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
6053
6054
  var AggregatorClient7 = class {
6054
6055
  constructor(endpoint, signer, client, env) {
6055
- this.endpoint = processEndpoint(endpoint);
6056
- this.client = client;
6057
- this.signer = signer;
6058
- this.env = env;
6056
+ this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
6057
+ this.client = client || new SuiClient({ url: getFullnodeUrl("mainnet") });
6058
+ this.signer = signer || "";
6059
+ this.env = env || 0 /* Mainnet */;
6059
6060
  this.allCoins = [];
6060
6061
  }
6061
6062
  getAllCoins() {
6062
6063
  return __async(this, null, function* () {
6064
+ if (this.signer === "") {
6065
+ throw new Error("Signer is required, but not provided.");
6066
+ }
6063
6067
  let cursor = null;
6064
6068
  let limit = 50;
6065
6069
  const allCoins = [];
@@ -6297,14 +6301,16 @@ var AggregatorClient7 = class {
6297
6301
  }
6298
6302
  });
6299
6303
  }
6304
+ // Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
6300
6305
  publishedAt() {
6301
6306
  if (this.env === 0 /* Mainnet */) {
6302
- return "0x868a192f542e819de99f8f289d7d6b47126e5da3103108fbc01d16cfd6be569a";
6307
+ return "0xf98ed029af555e4a103febf26243dc33ac09a7ea1b2da7e414c728b25b729086";
6303
6308
  } else {
6304
6309
  return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637";
6305
6310
  }
6306
6311
  }
6307
- publishedV2At() {
6312
+ // Include deepbookv3
6313
+ publishedAtV2() {
6308
6314
  if (this.env === 0 /* Mainnet */) {
6309
6315
  return "0x43ddba51e679811ea575c86bf0e0877015eef4d14320cc36c33847d06cf2bffe";
6310
6316
  } else {
@@ -6677,4 +6683,4 @@ decimal.js/decimal.mjs:
6677
6683
  *)
6678
6684
  */
6679
6685
 
6680
- export { AFSUI, AFTERMATH, AggregatorClient7 as AggregatorClient, BLUEMOVE, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, 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 };
6686
+ 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 };
@@ -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 DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
20
21
  export type BuildRouterSwapParams = {
21
22
  routers: Router[];
22
23
  byAmountIn: boolean;
@@ -53,7 +54,7 @@ export declare class AggregatorClient {
53
54
  client: SuiClient;
54
55
  env: Env;
55
56
  private allCoins;
56
- constructor(endpoint: string, signer: string, client: SuiClient, env: Env);
57
+ constructor(endpoint?: string, signer?: string, client?: SuiClient, env?: Env);
57
58
  getAllCoins(): Promise<CoinAsset[]>;
58
59
  findRouters(params: FindRouterParams): Promise<RouterData | null>;
59
60
  expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
@@ -62,7 +63,7 @@ export declare class AggregatorClient {
62
63
  routerSwap(params: BuildRouterSwapParams): Promise<TransactionObjectArgument>;
63
64
  fastRouterSwap(params: BuildFastRouterSwapParams): Promise<void>;
64
65
  publishedAt(): string;
65
- publishedV2At(): string;
66
+ publishedAtV2(): string;
66
67
  deepbookv3DeepFeeType(): string;
67
68
  transferOrDestoryCoin(txb: Transaction, coin: TransactionObjectArgument, coinType: string): void;
68
69
  checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, amountLimit: BN): TransactionObjectArgument;
@@ -7,7 +7,6 @@ export type CetusFlashSwapResult = {
7
7
  };
8
8
  export declare class DeepbookV3 implements Dex {
9
9
  private deepbookV3Config;
10
- private deepCoinType;
11
10
  constructor(env: Env);
12
11
  swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
13
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cetusprotocol/aggregator-sdk",
3
- "version": "0.0.0-experimental-20241018200510",
3
+ "version": "0.0.0-experimental-20241021144153",
4
4
  "sideEffects": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/client.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import Decimal from "decimal.js"
2
- import { SuiClient } from "@mysten/sui/client"
2
+ import { getFullnodeUrl, SuiClient } from "@mysten/sui/client"
3
3
  import {
4
4
  Transaction,
5
5
  TransactionObjectArgument,
@@ -16,10 +16,8 @@ import {
16
16
  Router,
17
17
  RouterData,
18
18
  getDeepbookV3Config,
19
- DeepbookV3ConfigResponse,
20
19
  processEndpoint,
21
20
  DeepbookV3Config,
22
- ZERO,
23
21
  } from "."
24
22
  import { Aftermath } from "./transaction/aftermath"
25
23
  import { DeepbookV2 } from "./transaction/deepbook_v2"
@@ -36,7 +34,7 @@ import { Afsui } from "./transaction/afsui"
36
34
  import { Volo } from "./transaction/volo"
37
35
  import { Bluemove } from "./transaction/bluemove"
38
36
  import { CoinAsset } from "./types/sui"
39
- import { buildInputCoin, mintZeroCoin } from "./utils/coin"
37
+ import { buildInputCoin } from "./utils/coin"
40
38
  import { DeepbookV3 } from "./transaction/deepbook_v3"
41
39
 
42
40
  export const CETUS = "CETUS"
@@ -53,6 +51,8 @@ export const AFSUI = "AFSUI"
53
51
  export const BLUEMOVE = "BLUEMOVE"
54
52
  export const DEEPBOOKV3 = "DEEPBOOKV3"
55
53
 
54
+ export const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2"
55
+
56
56
  export type BuildRouterSwapParams = {
57
57
  routers: Router[]
58
58
  byAmountIn: boolean
@@ -96,15 +96,19 @@ export class AggregatorClient {
96
96
  public env: Env
97
97
  private allCoins: CoinAsset[]
98
98
 
99
- constructor(endpoint: string, signer: string, client: SuiClient, env: Env) {
100
- this.endpoint = processEndpoint(endpoint)
101
- this.client = client
102
- this.signer = signer
103
- this.env = env
99
+ constructor(endpoint?: string, signer?: string, client?: SuiClient, env?: Env) {
100
+ this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT
101
+ this.client = client || new SuiClient({url: getFullnodeUrl('mainnet')})
102
+ this.signer = signer || ""
103
+ this.env = env || Env.Mainnet
104
104
  this.allCoins = []
105
105
  }
106
106
 
107
107
  async getAllCoins(): Promise<CoinAsset[]> {
108
+ if (this.signer === "") {
109
+ throw new Error("Signer is required, but not provided.")
110
+ }
111
+
108
112
  let cursor = null
109
113
  let limit = 50
110
114
  const allCoins: CoinAsset[] = []
@@ -361,17 +365,19 @@ export class AggregatorClient {
361
365
  }
362
366
  }
363
367
 
368
+ // Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
364
369
  publishedAt(): string {
365
370
  if (this.env === Env.Mainnet) {
366
- return "0x868a192f542e819de99f8f289d7d6b47126e5da3103108fbc01d16cfd6be569a"
371
+ return "0xf98ed029af555e4a103febf26243dc33ac09a7ea1b2da7e414c728b25b729086" // version 3
367
372
  } else {
368
373
  return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637"
369
374
  }
370
375
  }
371
376
 
372
- publishedV2At(): string {
377
+ // Include deepbookv3
378
+ publishedAtV2(): string {
373
379
  if (this.env === Env.Mainnet) {
374
- return "0x43ddba51e679811ea575c86bf0e0877015eef4d14320cc36c33847d06cf2bffe"
380
+ return "0x43ddba51e679811ea575c86bf0e0877015eef4d14320cc36c33847d06cf2bffe" // version 1
375
381
  } else {
376
382
  return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637"
377
383
  }
@@ -14,17 +14,12 @@ export type CetusFlashSwapResult = {
14
14
 
15
15
  export class DeepbookV3 implements Dex {
16
16
  private deepbookV3Config: string
17
- private deepCoinType: string
18
17
 
19
18
  constructor(env: Env) {
20
19
  this.deepbookV3Config =
21
20
  env === Env.Mainnet
22
21
  ? "0xa0c3e61f2f57045942f498cdc38c6347bd2e09e04a85ac33b866b84de5b5b141"
23
22
  : "0xe19b5d072346cae83a037d4e3c8492068a74410a74e5830b3a68012db38296aa"
24
- this.deepCoinType =
25
- env === Env.Mainnet
26
- ? "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP"
27
- : "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP"
28
23
  }
29
24
 
30
25
  async swap(
@@ -43,7 +38,7 @@ export class DeepbookV3 implements Dex {
43
38
  if (deepbookv3DeepFee) {
44
39
  deepFee = deepbookv3DeepFee
45
40
  } else {
46
- deepFee = mintZeroCoin(txb, this.deepCoinType)
41
+ deepFee = mintZeroCoin(txb, client.deepbookv3DeepFeeType())
47
42
  }
48
43
 
49
44
  const args = [
@@ -54,7 +49,7 @@ export class DeepbookV3 implements Dex {
54
49
  txb.object(CLOCK_ADDRESS),
55
50
  ]
56
51
  const res = txb.moveCall({
57
- target: `${client.publishedV2At()}::deepbookv3::${func}`,
52
+ target: `${client.publishedAtV2()}::deepbookv3::${func}`,
58
53
  typeArguments: [coinAType, coinBType],
59
54
  arguments: args,
60
55
  }) as TransactionArgument
@@ -3,7 +3,6 @@ import {
3
3
  TransactionObjectArgument,
4
4
  } from "@mysten/sui/transactions"
5
5
  import { AggregatorClient, Dex, Env, Path } from ".."
6
- import { SUI_SYSTEM_ADDRESS } from "@mysten/sui/utils"
7
6
 
8
7
  export class Volo implements Dex {
9
8
  private nativePool: string
package/src/utils/api.ts CHANGED
@@ -1,4 +1,4 @@
1
- export function processEndpoint(endpoint: string) {
1
+ export function processEndpoint(endpoint: string): string {
2
2
  if (endpoint.endsWith("/find_routes")) {
3
3
  return endpoint.replace("/find_routes", "")
4
4
  }