@cetusprotocol/aggregator-sdk 0.3.29 → 0.3.30

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
@@ -80,6 +80,7 @@ declare const HAEDALPMM = "HAEDALPMM";
80
80
  declare const ALPHAFI = "ALPHAFI";
81
81
  declare const SPRINGSUI = "SPRINGSUI";
82
82
  declare const STEAMM = "STEAMM";
83
+ declare const METASTABLE = "METASTABLE";
83
84
  declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
84
85
  type BuildRouterSwapParams = {
85
86
  routers: Router[];
@@ -243,6 +244,13 @@ type ExtendedDetails = {
243
244
  steammBCoinAType?: string;
244
245
  steammBCoinBType?: string;
245
246
  steammLPToken?: string;
247
+ metastablePriceSeed?: string;
248
+ metastableETHPriceSeed?: string;
249
+ metastableWhitelistedAppId?: string;
250
+ metastableCreateCapPkgId?: string;
251
+ metastableCreateCapModule?: string;
252
+ metastableCreateCapAllTypeParams?: boolean;
253
+ metastableRegistryId?: string;
246
254
  };
247
255
  type Path = {
248
256
  id: string;
@@ -306,4 +314,4 @@ declare enum Env {
306
314
  Testnet = 1
307
315
  }
308
316
 
309
- export { AFSUI, AFTERMATH, AGGREGATOR_V2, AGGREGATOR_V2_EXTEND, ALPHAFI, AggregatorClient, type AggregatorResponse, BLUEFIN, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildFastRouterSwapParamsV2, type BuildRouterSwapParams, type BuildRouterSwapParamsV2, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, type DeepbookV3Config, type DeepbookV3ConfigResponse, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, HAEDALPMM, KRIYA, KRIYAV3, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, SCALLOP, SPRINGSUI, STEAMM, SUILEND, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, findPythPriceIDs, fixSuiObjectId, getAggregatorV2ExtendPublishedAt, getAggregatorV2PublishedAt, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
317
+ export { AFSUI, AFTERMATH, AGGREGATOR_V2, AGGREGATOR_V2_EXTEND, ALPHAFI, AggregatorClient, type AggregatorResponse, BLUEFIN, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildFastRouterSwapParamsV2, type BuildRouterSwapParams, type BuildRouterSwapParamsV2, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, type DeepbookV3Config, type DeepbookV3ConfigResponse, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, HAEDALPMM, KRIYA, KRIYAV3, METASTABLE, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, SCALLOP, SPRINGSUI, STEAMM, SUILEND, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, findPythPriceIDs, fixSuiObjectId, getAggregatorV2ExtendPublishedAt, getAggregatorV2PublishedAt, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
package/dist/index.d.ts CHANGED
@@ -80,6 +80,7 @@ declare const HAEDALPMM = "HAEDALPMM";
80
80
  declare const ALPHAFI = "ALPHAFI";
81
81
  declare const SPRINGSUI = "SPRINGSUI";
82
82
  declare const STEAMM = "STEAMM";
83
+ declare const METASTABLE = "METASTABLE";
83
84
  declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
84
85
  type BuildRouterSwapParams = {
85
86
  routers: Router[];
@@ -243,6 +244,13 @@ type ExtendedDetails = {
243
244
  steammBCoinAType?: string;
244
245
  steammBCoinBType?: string;
245
246
  steammLPToken?: string;
247
+ metastablePriceSeed?: string;
248
+ metastableETHPriceSeed?: string;
249
+ metastableWhitelistedAppId?: string;
250
+ metastableCreateCapPkgId?: string;
251
+ metastableCreateCapModule?: string;
252
+ metastableCreateCapAllTypeParams?: boolean;
253
+ metastableRegistryId?: string;
246
254
  };
247
255
  type Path = {
248
256
  id: string;
@@ -306,4 +314,4 @@ declare enum Env {
306
314
  Testnet = 1
307
315
  }
308
316
 
309
- export { AFSUI, AFTERMATH, AGGREGATOR_V2, AGGREGATOR_V2_EXTEND, ALPHAFI, AggregatorClient, type AggregatorResponse, BLUEFIN, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildFastRouterSwapParamsV2, type BuildRouterSwapParams, type BuildRouterSwapParamsV2, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, type DeepbookV3Config, type DeepbookV3ConfigResponse, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, HAEDALPMM, KRIYA, KRIYAV3, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, SCALLOP, SPRINGSUI, STEAMM, SUILEND, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, findPythPriceIDs, fixSuiObjectId, getAggregatorV2ExtendPublishedAt, getAggregatorV2PublishedAt, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
317
+ export { AFSUI, AFTERMATH, AGGREGATOR_V2, AGGREGATOR_V2_EXTEND, ALPHAFI, AggregatorClient, type AggregatorResponse, BLUEFIN, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildFastRouterSwapParamsV2, type BuildRouterSwapParams, type BuildRouterSwapParamsV2, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, type DeepbookV3Config, type DeepbookV3ConfigResponse, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, HAEDALPMM, KRIYA, KRIYAV3, METASTABLE, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, SCALLOP, SPRINGSUI, STEAMM, SUILEND, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, findPythPriceIDs, fixSuiObjectId, getAggregatorV2ExtendPublishedAt, getAggregatorV2PublishedAt, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
package/dist/index.js CHANGED
@@ -6309,6 +6309,117 @@ var Steamm = class {
6309
6309
  }
6310
6310
  };
6311
6311
 
6312
+ // src/transaction/metastable.ts
6313
+ var SUPER_SUI_TYPE = "0x790f258062909e3a0ffc78b3c53ac2f62d7084c3bab95644bdeb05add7250001::super_sui::SUPER_SUI";
6314
+ var MUSD_TYPE = "0xe44df51c0b21a27ab915fa1fe2ca610cd3eaa6d9666fe5e62b988bf7f0bd8722::musd::MUSD";
6315
+ var METH_TYPE = "0xccd628c2334c5ed33e6c47d6c21bb664f8b6307b2ac32c2462a61f69a31ebcee::meth::METH";
6316
+ var Metastable = class {
6317
+ constructor(env, pythPriceIDs) {
6318
+ if (env !== 0 /* Mainnet */) {
6319
+ throw new Error("Metastable only supported on mainnet");
6320
+ }
6321
+ this.versionID = "0x4696559327b35ff2ab26904e7426a1646312e9c836d5c6cff6709a5ccc30915c";
6322
+ this.pythPriceIDs = pythPriceIDs;
6323
+ }
6324
+ swap(client, txb, path, inputCoin, packages) {
6325
+ return __async(this, null, function* () {
6326
+ const { direction, from, target } = path;
6327
+ const [func, createCapFunc, coinType, metaCoinType] = direction ? ["swap_a2b", "create_deposit_cap", from, target] : ["swap_b2a", "create_withdraw_cap", target, from];
6328
+ let createExchangePkgId = "";
6329
+ let createDepositModule = "pyth";
6330
+ let metaSingletonId = "";
6331
+ if (path.extendedDetails == null) {
6332
+ throw new Error("Extended details not supported metastable");
6333
+ } else {
6334
+ if (!path.extendedDetails.metastableCreateCapPkgId || !path.extendedDetails.metastableCreateCapModule || !path.extendedDetails.metastableRegistryId || !path.extendedDetails.metastableWhitelistedAppId) {
6335
+ throw new Error("CreateCapPkgId or CreateCapModule or RegistryId or WhitelistedAppId or CreateCapAllTypeParams not supported");
6336
+ }
6337
+ createExchangePkgId = path.extendedDetails.metastableCreateCapPkgId;
6338
+ createDepositModule = path.extendedDetails.metastableCreateCapModule;
6339
+ metaSingletonId = path.extendedDetails.metastableWhitelistedAppId;
6340
+ }
6341
+ const createDepositCapTypeArgs = [
6342
+ metaCoinType
6343
+ ];
6344
+ if (path.extendedDetails.metastableCreateCapAllTypeParams) {
6345
+ createDepositCapTypeArgs.push(coinType);
6346
+ }
6347
+ const depositArgs = [
6348
+ txb.object(metaSingletonId),
6349
+ txb.object(path.id)
6350
+ ];
6351
+ switch (metaCoinType) {
6352
+ case SUPER_SUI_TYPE: {
6353
+ if (!path.extendedDetails.metastableRegistryId) {
6354
+ throw new Error("Not found registry id for super sui");
6355
+ }
6356
+ depositArgs.push(txb.object(path.extendedDetails.metastableRegistryId));
6357
+ break;
6358
+ }
6359
+ case MUSD_TYPE: {
6360
+ if (path.extendedDetails.metastablePriceSeed != null) {
6361
+ const priceId = this.pythPriceIDs.get(path.extendedDetails.metastablePriceSeed);
6362
+ if (priceId == null) {
6363
+ throw new Error("Invalid Pyth price feed: " + path.extendedDetails.metastablePriceSeed);
6364
+ }
6365
+ depositArgs.push(txb.object(priceId));
6366
+ }
6367
+ if (path.extendedDetails.metastableETHPriceSeed != null) {
6368
+ const priceId = this.pythPriceIDs.get(path.extendedDetails.metastableETHPriceSeed);
6369
+ if (priceId == null) {
6370
+ throw new Error("Invalid Pyth price feed: " + path.extendedDetails.metastableETHPriceSeed);
6371
+ }
6372
+ depositArgs.push(txb.object(priceId));
6373
+ }
6374
+ depositArgs.push(txb.object(CLOCK_ADDRESS));
6375
+ break;
6376
+ }
6377
+ case METH_TYPE: {
6378
+ if (path.extendedDetails.metastablePriceSeed != null) {
6379
+ const priceId = this.pythPriceIDs.get(path.extendedDetails.metastablePriceSeed);
6380
+ if (priceId == null) {
6381
+ throw new Error("Invalid Pyth price feed: " + path.extendedDetails.metastablePriceSeed);
6382
+ }
6383
+ depositArgs.push(txb.object(priceId));
6384
+ }
6385
+ if (path.extendedDetails.metastableETHPriceSeed != null) {
6386
+ const priceId = this.pythPriceIDs.get(path.extendedDetails.metastableETHPriceSeed);
6387
+ if (priceId == null) {
6388
+ throw new Error("Invalid Pyth price feed: " + path.extendedDetails.metastableETHPriceSeed);
6389
+ }
6390
+ depositArgs.push(txb.object(priceId));
6391
+ }
6392
+ depositArgs.push(txb.object(CLOCK_ADDRESS));
6393
+ break;
6394
+ }
6395
+ default:
6396
+ throw new Error("Invalid Metacoin: " + metaCoinType);
6397
+ }
6398
+ const depositResult = txb.moveCall({
6399
+ target: `${createExchangePkgId}::${createDepositModule}::${createCapFunc}`,
6400
+ typeArguments: createDepositCapTypeArgs,
6401
+ arguments: depositArgs
6402
+ });
6403
+ const swapArgs = [
6404
+ txb.object(path.id),
6405
+ txb.object(this.versionID),
6406
+ depositResult,
6407
+ inputCoin
6408
+ ];
6409
+ const publishedAt = getAggregatorV2ExtendPublishedAt(client.publishedAtV2Extend(), packages);
6410
+ const res = txb.moveCall({
6411
+ target: `${publishedAt}::metastable::${func}`,
6412
+ typeArguments: [
6413
+ coinType,
6414
+ metaCoinType
6415
+ ],
6416
+ arguments: swapArgs
6417
+ });
6418
+ return res;
6419
+ });
6420
+ }
6421
+ };
6422
+
6312
6423
  // src/client.ts
6313
6424
  var CETUS = "CETUS";
6314
6425
  var DEEPBOOKV2 = "DEEPBOOK";
@@ -6330,6 +6441,7 @@ var HAEDALPMM = "HAEDALPMM";
6330
6441
  var ALPHAFI = "ALPHAFI";
6331
6442
  var SPRINGSUI = "SPRINGSUI";
6332
6443
  var STEAMM = "STEAMM";
6444
+ var METASTABLE = "METASTABLE";
6333
6445
  var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
6334
6446
  function isBuilderRouterSwapParams(params) {
6335
6447
  return Array.isArray(params.routers);
@@ -6759,6 +6871,8 @@ var _AggregatorClient = class _AggregatorClient {
6759
6871
  return new Alphafi(this.env);
6760
6872
  case STEAMM:
6761
6873
  return new Steamm(this.env);
6874
+ case METASTABLE:
6875
+ return new Metastable(this.env, pythPriceIDs);
6762
6876
  default:
6763
6877
  throw new Error(`Unsupported dex ${provider}`);
6764
6878
  }
@@ -6853,7 +6967,7 @@ _AggregatorClient.CONFIG = {
6853
6967
  [0 /* Mainnet */]: {
6854
6968
  connections: [
6855
6969
  new pythSuiJs.SuiPriceServiceConnection(
6856
- "https://cetus.liquify.com/api=X9LTVPQD7Y3R5N2A/hermes",
6970
+ "https://cetus-pythnet-a648.mainnet.pythnet.rpcpool.com/219cf7a8-6d75-432d-a648-d487a6dd5dc3/hermes",
6857
6971
  {
6858
6972
  timeout: 3e3
6859
6973
  }
@@ -6866,7 +6980,7 @@ _AggregatorClient.CONFIG = {
6866
6980
  pythStateId: "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8"
6867
6981
  }
6868
6982
  };
6869
- var AggregatorClient20 = _AggregatorClient;
6983
+ var AggregatorClient21 = _AggregatorClient;
6870
6984
  function findPythPriceIDs(routes) {
6871
6985
  const priceIDs = /* @__PURE__ */ new Set();
6872
6986
  for (const route of routes) {
@@ -6877,6 +6991,14 @@ function findPythPriceIDs(routes) {
6877
6991
  priceIDs.add(path.extendedDetails.haedalPmmQuotePriceSeed);
6878
6992
  }
6879
6993
  }
6994
+ if (path.provider === METASTABLE) {
6995
+ if (path.extendedDetails && path.extendedDetails.metastablePriceSeed) {
6996
+ priceIDs.add(path.extendedDetails.metastablePriceSeed);
6997
+ }
6998
+ if (path.extendedDetails && path.extendedDetails.metastableETHPriceSeed) {
6999
+ priceIDs.add(path.extendedDetails.metastableETHPriceSeed);
7000
+ }
7001
+ }
6880
7002
  }
6881
7003
  }
6882
7004
  return Array.from(priceIDs);
@@ -6905,13 +7027,13 @@ function parseRouterResponse(data, byAmountIn) {
6905
7027
  routes: data.routes.map((route) => {
6906
7028
  return {
6907
7029
  path: route.path.map((path) => {
6908
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
7030
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
6909
7031
  let version;
6910
7032
  if (path.provider === AFTERMATH) {
6911
7033
  version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
6912
7034
  }
6913
7035
  let extendedDetails;
6914
- if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3 || path.provider === SCALLOP || path.provider === HAEDALPMM || path.provider === STEAMM) {
7036
+ if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3 || path.provider === SCALLOP || path.provider === HAEDALPMM || path.provider === STEAMM || path.provider === METASTABLE) {
6915
7037
  extendedDetails = {
6916
7038
  aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
6917
7039
  turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
@@ -6926,7 +7048,14 @@ function parseRouterResponse(data, byAmountIn) {
6926
7048
  steammLendingMarketType: (_k = path.extended_details) == null ? void 0 : _k.steamm_lending_market_type,
6927
7049
  steammBCoinAType: (_l = path.extended_details) == null ? void 0 : _l.steamm_btoken_a_type,
6928
7050
  steammBCoinBType: (_m = path.extended_details) == null ? void 0 : _m.steamm_btoken_b_type,
6929
- steammLPToken: (_n = path.extended_details) == null ? void 0 : _n.steamm_lp_token_type
7051
+ steammLPToken: (_n = path.extended_details) == null ? void 0 : _n.steamm_lp_token_type,
7052
+ metastablePriceSeed: (_o = path.extended_details) == null ? void 0 : _o.metastable_price_seed,
7053
+ metastableETHPriceSeed: (_p = path.extended_details) == null ? void 0 : _p.metastable_eth_price_seed,
7054
+ metastableWhitelistedAppId: (_q = path.extended_details) == null ? void 0 : _q.metastable_whitelisted_app_id,
7055
+ metastableCreateCapPkgId: (_r = path.extended_details) == null ? void 0 : _r.metastable_create_cap_pkg_id,
7056
+ metastableCreateCapModule: (_s = path.extended_details) == null ? void 0 : _s.metastable_create_cap_module,
7057
+ metastableCreateCapAllTypeParams: (_t = path.extended_details) == null ? void 0 : _t.metastable_create_cap_all_type_params,
7058
+ metastableRegistryId: (_u = path.extended_details) == null ? void 0 : _u.metastable_registry_id
6930
7059
  };
6931
7060
  }
6932
7061
  return {
@@ -7014,7 +7143,7 @@ function processEndpoint(endpoint) {
7014
7143
  }
7015
7144
 
7016
7145
  // src/api.ts
7017
- var SDK_VERSION = 1000329;
7146
+ var SDK_VERSION = 1000330;
7018
7147
  function getRouterResult(endpoint, params) {
7019
7148
  return __async(this, null, function* () {
7020
7149
  let response;
@@ -7059,7 +7188,6 @@ function getRouterResult(endpoint, params) {
7059
7188
  };
7060
7189
  }
7061
7190
  if (data.data != null) {
7062
- console.log("data.data", JSON.stringify(data.data, null, 2));
7063
7191
  const res = parseRouterResponse(data.data, params.byAmountIn);
7064
7192
  return res;
7065
7193
  }
@@ -7208,7 +7336,7 @@ exports.AFTERMATH = AFTERMATH;
7208
7336
  exports.AGGREGATOR_V2 = AGGREGATOR_V2;
7209
7337
  exports.AGGREGATOR_V2_EXTEND = AGGREGATOR_V2_EXTEND;
7210
7338
  exports.ALPHAFI = ALPHAFI;
7211
- exports.AggregatorClient = AggregatorClient20;
7339
+ exports.AggregatorClient = AggregatorClient21;
7212
7340
  exports.BLUEFIN = BLUEFIN;
7213
7341
  exports.BLUEMOVE = BLUEMOVE;
7214
7342
  exports.CETUS = CETUS;
@@ -7223,6 +7351,7 @@ exports.HAEDAL = HAEDAL;
7223
7351
  exports.HAEDALPMM = HAEDALPMM;
7224
7352
  exports.KRIYA = KRIYA;
7225
7353
  exports.KRIYAV3 = KRIYAV3;
7354
+ exports.METASTABLE = METASTABLE;
7226
7355
  exports.ONE = ONE;
7227
7356
  exports.SCALLOP = SCALLOP;
7228
7357
  exports.SPRINGSUI = SPRINGSUI;
package/dist/index.mjs CHANGED
@@ -6307,6 +6307,117 @@ var Steamm = class {
6307
6307
  }
6308
6308
  };
6309
6309
 
6310
+ // src/transaction/metastable.ts
6311
+ var SUPER_SUI_TYPE = "0x790f258062909e3a0ffc78b3c53ac2f62d7084c3bab95644bdeb05add7250001::super_sui::SUPER_SUI";
6312
+ var MUSD_TYPE = "0xe44df51c0b21a27ab915fa1fe2ca610cd3eaa6d9666fe5e62b988bf7f0bd8722::musd::MUSD";
6313
+ var METH_TYPE = "0xccd628c2334c5ed33e6c47d6c21bb664f8b6307b2ac32c2462a61f69a31ebcee::meth::METH";
6314
+ var Metastable = class {
6315
+ constructor(env, pythPriceIDs) {
6316
+ if (env !== 0 /* Mainnet */) {
6317
+ throw new Error("Metastable only supported on mainnet");
6318
+ }
6319
+ this.versionID = "0x4696559327b35ff2ab26904e7426a1646312e9c836d5c6cff6709a5ccc30915c";
6320
+ this.pythPriceIDs = pythPriceIDs;
6321
+ }
6322
+ swap(client, txb, path, inputCoin, packages) {
6323
+ return __async(this, null, function* () {
6324
+ const { direction, from, target } = path;
6325
+ const [func, createCapFunc, coinType, metaCoinType] = direction ? ["swap_a2b", "create_deposit_cap", from, target] : ["swap_b2a", "create_withdraw_cap", target, from];
6326
+ let createExchangePkgId = "";
6327
+ let createDepositModule = "pyth";
6328
+ let metaSingletonId = "";
6329
+ if (path.extendedDetails == null) {
6330
+ throw new Error("Extended details not supported metastable");
6331
+ } else {
6332
+ if (!path.extendedDetails.metastableCreateCapPkgId || !path.extendedDetails.metastableCreateCapModule || !path.extendedDetails.metastableRegistryId || !path.extendedDetails.metastableWhitelistedAppId) {
6333
+ throw new Error("CreateCapPkgId or CreateCapModule or RegistryId or WhitelistedAppId or CreateCapAllTypeParams not supported");
6334
+ }
6335
+ createExchangePkgId = path.extendedDetails.metastableCreateCapPkgId;
6336
+ createDepositModule = path.extendedDetails.metastableCreateCapModule;
6337
+ metaSingletonId = path.extendedDetails.metastableWhitelistedAppId;
6338
+ }
6339
+ const createDepositCapTypeArgs = [
6340
+ metaCoinType
6341
+ ];
6342
+ if (path.extendedDetails.metastableCreateCapAllTypeParams) {
6343
+ createDepositCapTypeArgs.push(coinType);
6344
+ }
6345
+ const depositArgs = [
6346
+ txb.object(metaSingletonId),
6347
+ txb.object(path.id)
6348
+ ];
6349
+ switch (metaCoinType) {
6350
+ case SUPER_SUI_TYPE: {
6351
+ if (!path.extendedDetails.metastableRegistryId) {
6352
+ throw new Error("Not found registry id for super sui");
6353
+ }
6354
+ depositArgs.push(txb.object(path.extendedDetails.metastableRegistryId));
6355
+ break;
6356
+ }
6357
+ case MUSD_TYPE: {
6358
+ if (path.extendedDetails.metastablePriceSeed != null) {
6359
+ const priceId = this.pythPriceIDs.get(path.extendedDetails.metastablePriceSeed);
6360
+ if (priceId == null) {
6361
+ throw new Error("Invalid Pyth price feed: " + path.extendedDetails.metastablePriceSeed);
6362
+ }
6363
+ depositArgs.push(txb.object(priceId));
6364
+ }
6365
+ if (path.extendedDetails.metastableETHPriceSeed != null) {
6366
+ const priceId = this.pythPriceIDs.get(path.extendedDetails.metastableETHPriceSeed);
6367
+ if (priceId == null) {
6368
+ throw new Error("Invalid Pyth price feed: " + path.extendedDetails.metastableETHPriceSeed);
6369
+ }
6370
+ depositArgs.push(txb.object(priceId));
6371
+ }
6372
+ depositArgs.push(txb.object(CLOCK_ADDRESS));
6373
+ break;
6374
+ }
6375
+ case METH_TYPE: {
6376
+ if (path.extendedDetails.metastablePriceSeed != null) {
6377
+ const priceId = this.pythPriceIDs.get(path.extendedDetails.metastablePriceSeed);
6378
+ if (priceId == null) {
6379
+ throw new Error("Invalid Pyth price feed: " + path.extendedDetails.metastablePriceSeed);
6380
+ }
6381
+ depositArgs.push(txb.object(priceId));
6382
+ }
6383
+ if (path.extendedDetails.metastableETHPriceSeed != null) {
6384
+ const priceId = this.pythPriceIDs.get(path.extendedDetails.metastableETHPriceSeed);
6385
+ if (priceId == null) {
6386
+ throw new Error("Invalid Pyth price feed: " + path.extendedDetails.metastableETHPriceSeed);
6387
+ }
6388
+ depositArgs.push(txb.object(priceId));
6389
+ }
6390
+ depositArgs.push(txb.object(CLOCK_ADDRESS));
6391
+ break;
6392
+ }
6393
+ default:
6394
+ throw new Error("Invalid Metacoin: " + metaCoinType);
6395
+ }
6396
+ const depositResult = txb.moveCall({
6397
+ target: `${createExchangePkgId}::${createDepositModule}::${createCapFunc}`,
6398
+ typeArguments: createDepositCapTypeArgs,
6399
+ arguments: depositArgs
6400
+ });
6401
+ const swapArgs = [
6402
+ txb.object(path.id),
6403
+ txb.object(this.versionID),
6404
+ depositResult,
6405
+ inputCoin
6406
+ ];
6407
+ const publishedAt = getAggregatorV2ExtendPublishedAt(client.publishedAtV2Extend(), packages);
6408
+ const res = txb.moveCall({
6409
+ target: `${publishedAt}::metastable::${func}`,
6410
+ typeArguments: [
6411
+ coinType,
6412
+ metaCoinType
6413
+ ],
6414
+ arguments: swapArgs
6415
+ });
6416
+ return res;
6417
+ });
6418
+ }
6419
+ };
6420
+
6310
6421
  // src/client.ts
6311
6422
  var CETUS = "CETUS";
6312
6423
  var DEEPBOOKV2 = "DEEPBOOK";
@@ -6328,6 +6439,7 @@ var HAEDALPMM = "HAEDALPMM";
6328
6439
  var ALPHAFI = "ALPHAFI";
6329
6440
  var SPRINGSUI = "SPRINGSUI";
6330
6441
  var STEAMM = "STEAMM";
6442
+ var METASTABLE = "METASTABLE";
6331
6443
  var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
6332
6444
  function isBuilderRouterSwapParams(params) {
6333
6445
  return Array.isArray(params.routers);
@@ -6757,6 +6869,8 @@ var _AggregatorClient = class _AggregatorClient {
6757
6869
  return new Alphafi(this.env);
6758
6870
  case STEAMM:
6759
6871
  return new Steamm(this.env);
6872
+ case METASTABLE:
6873
+ return new Metastable(this.env, pythPriceIDs);
6760
6874
  default:
6761
6875
  throw new Error(`Unsupported dex ${provider}`);
6762
6876
  }
@@ -6851,7 +6965,7 @@ _AggregatorClient.CONFIG = {
6851
6965
  [0 /* Mainnet */]: {
6852
6966
  connections: [
6853
6967
  new SuiPriceServiceConnection(
6854
- "https://cetus.liquify.com/api=X9LTVPQD7Y3R5N2A/hermes",
6968
+ "https://cetus-pythnet-a648.mainnet.pythnet.rpcpool.com/219cf7a8-6d75-432d-a648-d487a6dd5dc3/hermes",
6855
6969
  {
6856
6970
  timeout: 3e3
6857
6971
  }
@@ -6864,7 +6978,7 @@ _AggregatorClient.CONFIG = {
6864
6978
  pythStateId: "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8"
6865
6979
  }
6866
6980
  };
6867
- var AggregatorClient20 = _AggregatorClient;
6981
+ var AggregatorClient21 = _AggregatorClient;
6868
6982
  function findPythPriceIDs(routes) {
6869
6983
  const priceIDs = /* @__PURE__ */ new Set();
6870
6984
  for (const route of routes) {
@@ -6875,6 +6989,14 @@ function findPythPriceIDs(routes) {
6875
6989
  priceIDs.add(path.extendedDetails.haedalPmmQuotePriceSeed);
6876
6990
  }
6877
6991
  }
6992
+ if (path.provider === METASTABLE) {
6993
+ if (path.extendedDetails && path.extendedDetails.metastablePriceSeed) {
6994
+ priceIDs.add(path.extendedDetails.metastablePriceSeed);
6995
+ }
6996
+ if (path.extendedDetails && path.extendedDetails.metastableETHPriceSeed) {
6997
+ priceIDs.add(path.extendedDetails.metastableETHPriceSeed);
6998
+ }
6999
+ }
6878
7000
  }
6879
7001
  }
6880
7002
  return Array.from(priceIDs);
@@ -6903,13 +7025,13 @@ function parseRouterResponse(data, byAmountIn) {
6903
7025
  routes: data.routes.map((route) => {
6904
7026
  return {
6905
7027
  path: route.path.map((path) => {
6906
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
7028
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
6907
7029
  let version;
6908
7030
  if (path.provider === AFTERMATH) {
6909
7031
  version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
6910
7032
  }
6911
7033
  let extendedDetails;
6912
- if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3 || path.provider === SCALLOP || path.provider === HAEDALPMM || path.provider === STEAMM) {
7034
+ if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3 || path.provider === SCALLOP || path.provider === HAEDALPMM || path.provider === STEAMM || path.provider === METASTABLE) {
6913
7035
  extendedDetails = {
6914
7036
  aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
6915
7037
  turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
@@ -6924,7 +7046,14 @@ function parseRouterResponse(data, byAmountIn) {
6924
7046
  steammLendingMarketType: (_k = path.extended_details) == null ? void 0 : _k.steamm_lending_market_type,
6925
7047
  steammBCoinAType: (_l = path.extended_details) == null ? void 0 : _l.steamm_btoken_a_type,
6926
7048
  steammBCoinBType: (_m = path.extended_details) == null ? void 0 : _m.steamm_btoken_b_type,
6927
- steammLPToken: (_n = path.extended_details) == null ? void 0 : _n.steamm_lp_token_type
7049
+ steammLPToken: (_n = path.extended_details) == null ? void 0 : _n.steamm_lp_token_type,
7050
+ metastablePriceSeed: (_o = path.extended_details) == null ? void 0 : _o.metastable_price_seed,
7051
+ metastableETHPriceSeed: (_p = path.extended_details) == null ? void 0 : _p.metastable_eth_price_seed,
7052
+ metastableWhitelistedAppId: (_q = path.extended_details) == null ? void 0 : _q.metastable_whitelisted_app_id,
7053
+ metastableCreateCapPkgId: (_r = path.extended_details) == null ? void 0 : _r.metastable_create_cap_pkg_id,
7054
+ metastableCreateCapModule: (_s = path.extended_details) == null ? void 0 : _s.metastable_create_cap_module,
7055
+ metastableCreateCapAllTypeParams: (_t = path.extended_details) == null ? void 0 : _t.metastable_create_cap_all_type_params,
7056
+ metastableRegistryId: (_u = path.extended_details) == null ? void 0 : _u.metastable_registry_id
6928
7057
  };
6929
7058
  }
6930
7059
  return {
@@ -7012,7 +7141,7 @@ function processEndpoint(endpoint) {
7012
7141
  }
7013
7142
 
7014
7143
  // src/api.ts
7015
- var SDK_VERSION = 1000329;
7144
+ var SDK_VERSION = 1000330;
7016
7145
  function getRouterResult(endpoint, params) {
7017
7146
  return __async(this, null, function* () {
7018
7147
  let response;
@@ -7057,7 +7186,6 @@ function getRouterResult(endpoint, params) {
7057
7186
  };
7058
7187
  }
7059
7188
  if (data.data != null) {
7060
- console.log("data.data", JSON.stringify(data.data, null, 2));
7061
7189
  const res = parseRouterResponse(data.data, params.byAmountIn);
7062
7190
  return res;
7063
7191
  }
@@ -7201,4 +7329,4 @@ decimal.js/decimal.mjs:
7201
7329
  *)
7202
7330
  */
7203
7331
 
7204
- export { AFSUI, AFTERMATH, AGGREGATOR_V2, AGGREGATOR_V2_EXTEND, ALPHAFI, AggregatorClient20 as AggregatorClient, BLUEFIN, BLUEMOVE, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, Env, FLOWXV2, FLOWXV3, HAEDAL, HAEDALPMM, KRIYA, KRIYAV3, ONE, SCALLOP, SPRINGSUI, STEAMM, SUILEND, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, findPythPriceIDs, fixSuiObjectId, getAggregatorV2ExtendPublishedAt, getAggregatorV2PublishedAt, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
7332
+ export { AFSUI, AFTERMATH, AGGREGATOR_V2, AGGREGATOR_V2_EXTEND, ALPHAFI, AggregatorClient21 as AggregatorClient, BLUEFIN, BLUEMOVE, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, Env, FLOWXV2, FLOWXV3, HAEDAL, HAEDALPMM, KRIYA, KRIYAV3, METASTABLE, ONE, SCALLOP, SPRINGSUI, STEAMM, SUILEND, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, findPythPriceIDs, fixSuiObjectId, getAggregatorV2ExtendPublishedAt, getAggregatorV2PublishedAt, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
package/dist/src/api.d.ts CHANGED
@@ -34,6 +34,13 @@ export type ExtendedDetails = {
34
34
  steammBCoinAType?: string;
35
35
  steammBCoinBType?: string;
36
36
  steammLPToken?: string;
37
+ metastablePriceSeed?: string;
38
+ metastableETHPriceSeed?: string;
39
+ metastableWhitelistedAppId?: string;
40
+ metastableCreateCapPkgId?: string;
41
+ metastableCreateCapModule?: string;
42
+ metastableCreateCapAllTypeParams?: boolean;
43
+ metastableRegistryId?: string;
37
44
  };
38
45
  export type Path = {
39
46
  id: string;
@@ -24,6 +24,7 @@ export declare const HAEDALPMM = "HAEDALPMM";
24
24
  export declare const ALPHAFI = "ALPHAFI";
25
25
  export declare const SPRINGSUI = "SPRINGSUI";
26
26
  export declare const STEAMM = "STEAMM";
27
+ export declare const METASTABLE = "METASTABLE";
27
28
  export declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
28
29
  export type BuildRouterSwapParams = {
29
30
  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 Metastable implements Dex {
4
+ private pythPriceIDs;
5
+ private versionID;
6
+ constructor(env: Env, pythPriceIDs: Map<string, string>);
7
+ swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
8
+ }
@@ -0,0 +1,2 @@
1
+ import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
2
+ export declare function buildTestAccount(): Ed25519Keypair;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cetusprotocol/aggregator-sdk",
3
- "version": "0.3.29",
3
+ "version": "0.3.30",
4
4
  "sideEffects": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/api.ts CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  } from "./errors"
9
9
  import { parseRouterResponse } from "./client"
10
10
 
11
- const SDK_VERSION = 1000329
11
+ const SDK_VERSION = 1000330
12
12
 
13
13
  export interface FindRouterParams {
14
14
  from: string
@@ -53,6 +53,13 @@ export type ExtendedDetails = {
53
53
  steammBCoinAType?: string
54
54
  steammBCoinBType?: string
55
55
  steammLPToken?: string
56
+ metastablePriceSeed?: string
57
+ metastableETHPriceSeed?: string
58
+ metastableWhitelistedAppId?: string
59
+ metastableCreateCapPkgId?: string
60
+ metastableCreateCapModule?: string
61
+ metastableCreateCapAllTypeParams?: boolean
62
+ metastableRegistryId?: string
56
63
  }
57
64
 
58
65
  export type Path = {
@@ -146,7 +153,6 @@ export async function getRouterResult(
146
153
  }
147
154
  }
148
155
  if (data.data != null) {
149
- console.log("data.data", JSON.stringify(data.data, null, 2))
150
156
  const res = parseRouterResponse(data.data, params.byAmountIn)
151
157
  return res
152
158
  }
package/src/client.ts CHANGED
@@ -48,6 +48,7 @@ import {
48
48
  SuiPythClient,
49
49
  } from "@pythnetwork/pyth-sui-js"
50
50
  import { Steamm } from "./transaction/steamm"
51
+ import { Metastable } from "./transaction/metastable"
51
52
 
52
53
  export const CETUS = "CETUS"
53
54
  export const DEEPBOOKV2 = "DEEPBOOK"
@@ -69,6 +70,7 @@ export const HAEDALPMM = "HAEDALPMM"
69
70
  export const ALPHAFI = "ALPHAFI"
70
71
  export const SPRINGSUI = "SPRINGSUI"
71
72
  export const STEAMM = "STEAMM"
73
+ export const METASTABLE = "METASTABLE"
72
74
  export const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2"
73
75
 
74
76
  export type BuildRouterSwapParams = {
@@ -167,7 +169,7 @@ export class AggregatorClient {
167
169
  [Env.Mainnet]: {
168
170
  connections: [
169
171
  new SuiPriceServiceConnection(
170
- "https://cetus.liquify.com/api=X9LTVPQD7Y3R5N2A/hermes",
172
+ "https://cetus-pythnet-a648.mainnet.pythnet.rpcpool.com/219cf7a8-6d75-432d-a648-d487a6dd5dc3/hermes",
171
173
  {
172
174
  timeout: 3000,
173
175
  }
@@ -707,6 +709,8 @@ export class AggregatorClient {
707
709
  return new Alphafi(this.env)
708
710
  case STEAMM:
709
711
  return new Steamm(this.env)
712
+ case METASTABLE:
713
+ return new Metastable(this.env, pythPriceIDs)
710
714
  default:
711
715
  throw new Error(`Unsupported dex ${provider}`)
712
716
  }
@@ -809,6 +813,14 @@ export function findPythPriceIDs(routes: Router[]): string[] {
809
813
  priceIDs.add(path.extendedDetails.haedalPmmQuotePriceSeed)
810
814
  }
811
815
  }
816
+ if (path.provider === METASTABLE) {
817
+ if (path.extendedDetails && path.extendedDetails.metastablePriceSeed) {
818
+ priceIDs.add(path.extendedDetails.metastablePriceSeed)
819
+ }
820
+ if (path.extendedDetails && path.extendedDetails.metastableETHPriceSeed) {
821
+ priceIDs.add(path.extendedDetails.metastableETHPriceSeed)
822
+ }
823
+ }
812
824
  }
813
825
  }
814
826
  return Array.from(priceIDs)
@@ -857,7 +869,8 @@ export function parseRouterResponse(
857
869
  path.provider === DEEPBOOKV3 ||
858
870
  path.provider === SCALLOP ||
859
871
  path.provider === HAEDALPMM ||
860
- path.provider === STEAMM
872
+ path.provider === STEAMM ||
873
+ path.provider === METASTABLE
861
874
  ) {
862
875
  extendedDetails = {
863
876
  aftermathLpSupplyType:
@@ -877,7 +890,14 @@ export function parseRouterResponse(
877
890
  steammLendingMarketType: path.extended_details?.steamm_lending_market_type,
878
891
  steammBCoinAType: path.extended_details?.steamm_btoken_a_type,
879
892
  steammBCoinBType: path.extended_details?.steamm_btoken_b_type,
880
- steammLPToken: path.extended_details?.steamm_lp_token_type,
893
+ steammLPToken: path.extended_details?.steamm_lp_token_type,
894
+ metastablePriceSeed: path.extended_details?.metastable_price_seed,
895
+ metastableETHPriceSeed: path.extended_details?.metastable_eth_price_seed,
896
+ metastableWhitelistedAppId: path.extended_details?.metastable_whitelisted_app_id,
897
+ metastableCreateCapPkgId: path.extended_details?.metastable_create_cap_pkg_id,
898
+ metastableCreateCapModule: path.extended_details?.metastable_create_cap_module,
899
+ metastableCreateCapAllTypeParams: path.extended_details?.metastable_create_cap_all_type_params,
900
+ metastableRegistryId: path.extended_details?.metastable_registry_id,
881
901
  }
882
902
  }
883
903
 
@@ -0,0 +1,141 @@
1
+ import {
2
+ Transaction,
3
+ TransactionObjectArgument,
4
+ } from "@mysten/sui/transactions"
5
+ import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, getAggregatorV2ExtendPublishedAt, Path } from ".."
6
+
7
+ const SUPER_SUI_TYPE = "0x790f258062909e3a0ffc78b3c53ac2f62d7084c3bab95644bdeb05add7250001::super_sui::SUPER_SUI"
8
+ const MUSD_TYPE = "0xe44df51c0b21a27ab915fa1fe2ca610cd3eaa6d9666fe5e62b988bf7f0bd8722::musd::MUSD"
9
+ const METH_TYPE = "0xccd628c2334c5ed33e6c47d6c21bb664f8b6307b2ac32c2462a61f69a31ebcee::meth::METH"
10
+
11
+ export class Metastable implements Dex {
12
+ private pythPriceIDs: Map<string, string>
13
+ private versionID: string
14
+
15
+ constructor(env: Env, pythPriceIDs: Map<string, string>) {
16
+ if (env !== Env.Mainnet) {
17
+ throw new Error("Metastable only supported on mainnet")
18
+ }
19
+ this.versionID = "0x4696559327b35ff2ab26904e7426a1646312e9c836d5c6cff6709a5ccc30915c"
20
+ this.pythPriceIDs = pythPriceIDs
21
+ }
22
+
23
+ async swap(
24
+ client: AggregatorClient,
25
+ txb: Transaction,
26
+ path: Path,
27
+ inputCoin: TransactionObjectArgument,
28
+ packages?: Map<string, string>
29
+ ): Promise<TransactionObjectArgument> {
30
+ const { direction, from, target } = path
31
+
32
+ const [func, createCapFunc, coinType, metaCoinType] = direction
33
+ ? ["swap_a2b", "create_deposit_cap", from, target]
34
+ : ["swap_b2a", "create_withdraw_cap", target, from]
35
+
36
+ let createExchangePkgId = "";
37
+ let createDepositModule = "pyth";
38
+ let metaSingletonId = "";
39
+ if (path.extendedDetails == null) {
40
+ throw new Error("Extended details not supported metastable")
41
+ } else {
42
+ if (
43
+ !path.extendedDetails.metastableCreateCapPkgId ||
44
+ !path.extendedDetails.metastableCreateCapModule ||
45
+ !path.extendedDetails.metastableRegistryId ||
46
+ !path.extendedDetails.metastableWhitelistedAppId
47
+ ) {
48
+ throw new Error("CreateCapPkgId or CreateCapModule or RegistryId or WhitelistedAppId or CreateCapAllTypeParams not supported")
49
+ }
50
+ createExchangePkgId = path.extendedDetails.metastableCreateCapPkgId
51
+ createDepositModule = path.extendedDetails.metastableCreateCapModule
52
+ metaSingletonId = path.extendedDetails.metastableWhitelistedAppId
53
+ }
54
+
55
+ const createDepositCapTypeArgs = [
56
+ metaCoinType
57
+ ]
58
+ if (path.extendedDetails.metastableCreateCapAllTypeParams) {
59
+ createDepositCapTypeArgs.push(coinType);
60
+ }
61
+
62
+ const depositArgs = [
63
+ txb.object(metaSingletonId),
64
+ txb.object(path.id),
65
+ ]
66
+
67
+ switch (metaCoinType) {
68
+ case SUPER_SUI_TYPE: {
69
+ if (!path.extendedDetails.metastableRegistryId) {
70
+ throw new Error("Not found registry id for super sui")
71
+ }
72
+ depositArgs.push(txb.object(path.extendedDetails.metastableRegistryId));
73
+ break;
74
+ }
75
+ case MUSD_TYPE: {
76
+ if (path.extendedDetails.metastablePriceSeed != null) {
77
+ const priceId = this.pythPriceIDs.get(path.extendedDetails.metastablePriceSeed)
78
+ if (priceId == null) {
79
+ throw new Error("Invalid Pyth price feed: " + path.extendedDetails.metastablePriceSeed)
80
+ }
81
+ depositArgs.push(txb.object(priceId));
82
+ }
83
+ if (path.extendedDetails.metastableETHPriceSeed != null) {
84
+ const priceId = this.pythPriceIDs.get(path.extendedDetails.metastableETHPriceSeed)
85
+ if (priceId == null) {
86
+ throw new Error("Invalid Pyth price feed: " + path.extendedDetails.metastableETHPriceSeed)
87
+ }
88
+ depositArgs.push(txb.object(priceId));
89
+ }
90
+ depositArgs.push(txb.object(CLOCK_ADDRESS));
91
+ break;
92
+ }
93
+ case METH_TYPE: {
94
+ if (path.extendedDetails.metastablePriceSeed != null) {
95
+ const priceId = this.pythPriceIDs.get(path.extendedDetails.metastablePriceSeed)
96
+ if (priceId == null) {
97
+ throw new Error("Invalid Pyth price feed: " + path.extendedDetails.metastablePriceSeed)
98
+ }
99
+ depositArgs.push(txb.object(priceId));
100
+ }
101
+ if (path.extendedDetails.metastableETHPriceSeed != null) {
102
+ const priceId = this.pythPriceIDs.get(path.extendedDetails.metastableETHPriceSeed)
103
+ if (priceId == null) {
104
+ throw new Error("Invalid Pyth price feed: " + path.extendedDetails.metastableETHPriceSeed)
105
+ }
106
+ depositArgs.push(txb.object(priceId));
107
+ }
108
+ depositArgs.push(txb.object(CLOCK_ADDRESS));
109
+ break;
110
+ }
111
+
112
+ default:
113
+ throw new Error("Invalid Metacoin: " + metaCoinType);
114
+ }
115
+
116
+ const depositResult = txb.moveCall({
117
+ target: `${createExchangePkgId}::${createDepositModule}::${createCapFunc}`,
118
+ typeArguments: createDepositCapTypeArgs,
119
+ arguments: depositArgs,
120
+ }) as TransactionObjectArgument
121
+
122
+ const swapArgs = [
123
+ txb.object(path.id),
124
+ txb.object(this.versionID),
125
+ depositResult,
126
+ inputCoin,
127
+ ]
128
+
129
+ const publishedAt = getAggregatorV2ExtendPublishedAt(client.publishedAtV2Extend(), packages)
130
+ const res = txb.moveCall({
131
+ target: `${publishedAt}::metastable::${func}`,
132
+ typeArguments: [
133
+ coinType,
134
+ metaCoinType,
135
+ ],
136
+ arguments: swapArgs,
137
+ }) as TransactionObjectArgument
138
+
139
+ return res
140
+ }
141
+ }
@@ -0,0 +1,377 @@
1
+ import { describe, test } from "@jest/globals"
2
+ import dotenv from "dotenv"
3
+ import { AggregatorClient } from "~/client"
4
+ import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"
5
+ import { printTransaction } from "~/utils/transaction"
6
+ import BN from "bn.js"
7
+ import { fromB64 } from "@mysten/sui/utils"
8
+ import { SuiClient } from "@mysten/sui/client"
9
+ import { Env } from "~/index"
10
+ import { Transaction } from "@mysten/sui/transactions"
11
+
12
+ dotenv.config()
13
+
14
+ export function buildTestAccount(): Ed25519Keypair {
15
+ const mnemonics = process.env.SUI_WALLET_MNEMONICS || ""
16
+ const testAccountObject = Ed25519Keypair.deriveKeypair(mnemonics)
17
+ return testAccountObject
18
+ }
19
+
20
+ describe("Test metastable provider", () => {
21
+ let client: AggregatorClient
22
+ let keypair: Ed25519Keypair
23
+
24
+ const T_SUPER_SUI = "0x790f258062909e3a0ffc78b3c53ac2f62d7084c3bab95644bdeb05add7250001::super_sui::SUPER_SUI"
25
+ const T_SUI = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"
26
+ const AF_SUI = "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI"
27
+
28
+ const WH_USDC = "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN"
29
+ const T_USDC = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"
30
+ const M_USDC = "0xe44df51c0b21a27ab915fa1fe2ca610cd3eaa6d9666fe5e62b988bf7f0bd8722::musd::MUSD"
31
+
32
+ const METH = "0xccd628c2334c5ed33e6c47d6c21bb664f8b6307b2ac32c2462a61f69a31ebcee::meth::METH"
33
+ const ETH = "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH"
34
+ const WEHT = "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN"
35
+
36
+ beforeAll(() => {
37
+ const fullNodeURL = process.env.SUI_RPC!
38
+ const aggregatorURL = process.env.CETUS_AGGREGATOR!
39
+ const secret = process.env.SUI_WALLET_SECRET!
40
+
41
+ if (secret) {
42
+ keypair = Ed25519Keypair.fromSecretKey(fromB64(secret).slice(1, 33))
43
+ } else {
44
+ keypair = buildTestAccount()
45
+ }
46
+
47
+ // const wallet = keypair.getPublicKey().toSuiAddress()
48
+ // const wallet =
49
+ // "0x5cade8f29891e04c5f6e5ad3a020583fda51c8267f1b0c0fa5a85158d486ac3b" // has 1 meth
50
+
51
+ const wallet = "0x80cda5d0baa1e33ad073f590f8e6dc00a8d3657663ce06ce08c18ecbb0e47031" // has 80 eth
52
+
53
+ console.log("wallet: ", wallet)
54
+
55
+ const endpoint = aggregatorURL
56
+
57
+ const suiClient = new SuiClient({
58
+ url: fullNodeURL,
59
+ })
60
+ client = new AggregatorClient(endpoint, wallet, suiClient, Env.Mainnet)
61
+ })
62
+
63
+ test("Find Routers --> SUI -> SUPER_SUI", async () => {
64
+ // const amounts = ["1000", "1000000", "100000000", "5000000000", "10000000000000"]
65
+ const amounts = ["999000000", "5000000000"]
66
+
67
+ for (const amount of amounts) {
68
+ const res = await client.findRouters({
69
+ from: T_SUI,
70
+ target: T_SUPER_SUI,
71
+ amount: new BN(amount),
72
+ byAmountIn: true,
73
+ depth: 3,
74
+ splitCount: 1,
75
+ providers: ["METASTABLE"],
76
+ })
77
+
78
+ if (res != null) {
79
+ console.log(JSON.stringify(res, null, 2))
80
+ }
81
+ console.log("amount in", res?.amountIn.toString())
82
+ console.log("amount out", res?.amountOut.toString())
83
+
84
+ const txb = new Transaction()
85
+
86
+ if (res != null) {
87
+ console.log(JSON.stringify(res, null, 2))
88
+ await client.fastRouterSwap({
89
+ routers: res,
90
+ txb,
91
+ slippage: 0.01,
92
+ refreshAllCoins: true,
93
+ payDeepFeeAmount: 0,
94
+ })
95
+
96
+ txb.setSender(client.signer)
97
+ const buildTxb = await txb.build({ client: client.client })
98
+ // const buildTxb = await txb.getData()
99
+
100
+ console.log("buildTxb", buildTxb)
101
+ // printTransaction(txb)
102
+
103
+ let result = await client.devInspectTransactionBlock(txb)
104
+ console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
105
+ for (const event of result.events) {
106
+ console.log("event", JSON.stringify(event, null, 2))
107
+ }
108
+ }
109
+ }
110
+ })
111
+
112
+ test("Find Routers --> SUPER_SUI --> SUI", async () => {
113
+ // const amounts = ["1000", "1000000", "100000000", "5000000000", "10000000000000"]
114
+ const amounts = ["1000", "1000000", "900000000"]
115
+
116
+ for (const amount of amounts) {
117
+ const res = await client.findRouters({
118
+ from: T_SUPER_SUI,
119
+ target: T_SUI,
120
+ amount: new BN(amount),
121
+ byAmountIn: true,
122
+ depth: 3,
123
+ splitCount: 1,
124
+ providers: ["METASTABLE"],
125
+ })
126
+
127
+ if (res != null) {
128
+ console.log(JSON.stringify(res, null, 2))
129
+ }
130
+ console.log("amount in", res?.amountIn.toString())
131
+ console.log("amount out", res?.amountOut.toString())
132
+
133
+ const txb = new Transaction()
134
+
135
+ if (res != null) {
136
+ console.log(JSON.stringify(res, null, 2))
137
+ await client.fastRouterSwap({
138
+ routers: res,
139
+ txb,
140
+ slippage: 0.01,
141
+ refreshAllCoins: true,
142
+ payDeepFeeAmount: 0,
143
+ })
144
+
145
+ txb.setSender(client.signer)
146
+ const buildTxb = await txb.build({ client: client.client })
147
+ // const buildTxb = await txb.getData()
148
+
149
+ // printTransaction(txb)
150
+
151
+ let result = await client.devInspectTransactionBlock(txb)
152
+ console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
153
+ for (const event of result.events) {
154
+ console.log("event", JSON.stringify(event, null, 2))
155
+ }
156
+ }
157
+ }
158
+ })
159
+
160
+ test("Find Routers --> USDC -> MUSDC", async () => {
161
+ const amounts = ["1000000", "30000000"]
162
+
163
+ for (const amount of amounts) {
164
+ const res = await client.findRouters({
165
+ from: T_USDC,
166
+ target: M_USDC,
167
+ amount: new BN(amount),
168
+ byAmountIn: true,
169
+ depth: 3,
170
+ splitCount: 1,
171
+ providers: ["METASTABLE"],
172
+ })
173
+
174
+ if (res != null) {
175
+ console.log(JSON.stringify(res, null, 2))
176
+ }
177
+ console.log("amount in", res?.amountIn.toString())
178
+ console.log("amount out", res?.amountOut.toString())
179
+
180
+ const txb = new Transaction()
181
+
182
+ if (res != null) {
183
+ console.log(JSON.stringify(res, null, 2))
184
+ await client.fastRouterSwap({
185
+ routers: res,
186
+ txb,
187
+ slippage: 0.01,
188
+ refreshAllCoins: true,
189
+ payDeepFeeAmount: 0,
190
+ })
191
+ txb.setSender(client.signer)
192
+
193
+ let result = await client.devInspectTransactionBlock(txb)
194
+ console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
195
+ for (const event of result.events) {
196
+ console.log("event", JSON.stringify(event, null, 2))
197
+ }
198
+ }
199
+ }
200
+ })
201
+
202
+ test("Find Routers --> MUSDC -> USDC", async () => {
203
+ // const amounts = ["1000", "1000000", "100000000", "5000000000", "10000000000000"]
204
+ const amounts = ["1000000", "1000000000"]
205
+
206
+ for (const amount of amounts) {
207
+ const res = await client.findRouters({
208
+ from: M_USDC,
209
+ target: T_USDC,
210
+ amount: new BN(amount),
211
+ byAmountIn: true,
212
+ depth: 3,
213
+ splitCount: 1,
214
+ providers: ["METASTABLE"],
215
+ })
216
+
217
+ if (res != null) {
218
+ console.log(JSON.stringify(res, null, 2))
219
+ }
220
+ console.log("amount in", res?.amountIn.toString())
221
+ console.log("amount out", res?.amountOut.toString())
222
+
223
+ const txb = new Transaction()
224
+
225
+ if (res != null) {
226
+ console.log(JSON.stringify(res, null, 2))
227
+ await client.fastRouterSwap({
228
+ routers: res,
229
+ txb,
230
+ slippage: 0.01,
231
+ refreshAllCoins: true,
232
+ payDeepFeeAmount: 0,
233
+ })
234
+ txb.setSender(client.signer)
235
+
236
+ let result = await client.devInspectTransactionBlock(txb)
237
+ console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
238
+ for (const event of result.events) {
239
+ console.log("event", JSON.stringify(event, null, 2))
240
+ }
241
+ }
242
+
243
+ }
244
+ })
245
+
246
+ test("Find Routers --> METH -> ETH", async () => {
247
+ const amounts = ["5000000", "100000000"]
248
+
249
+ for (const amount of amounts) {
250
+ const res = await client.findRouters({
251
+ from: METH,
252
+ target: ETH,
253
+ amount: new BN(amount),
254
+ byAmountIn: true,
255
+ depth: 3,
256
+ splitCount: 1,
257
+ providers: ["METASTABLE"],
258
+ })
259
+
260
+ if (res != null) {
261
+ console.log(JSON.stringify(res, null, 2))
262
+ }
263
+ console.log("amount in", res?.amountIn.toString())
264
+ console.log("amount out", res?.amountOut.toString())
265
+
266
+ const txb = new Transaction()
267
+
268
+ if (res != null) {
269
+ console.log(JSON.stringify(res, null, 2))
270
+ await client.fastRouterSwap({
271
+ routers: res,
272
+ txb,
273
+ slippage: 0.01,
274
+ refreshAllCoins: true,
275
+ payDeepFeeAmount: 0,
276
+ })
277
+ txb.setSender(client.signer)
278
+
279
+ let result = await client.devInspectTransactionBlock(txb)
280
+ console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
281
+ for (const event of result.events) {
282
+ console.log("event", JSON.stringify(event, null, 2))
283
+ }
284
+ }
285
+ }
286
+ })
287
+
288
+ test("Find Routers --> ETH -> METH", async () => {
289
+ const amounts = ["10000000", "5000000000"]
290
+
291
+ for (const amount of amounts) {
292
+ const res = await client.findRouters({
293
+ from: ETH,
294
+ target: METH,
295
+ amount: new BN(amount),
296
+ byAmountIn: true,
297
+ depth: 3,
298
+ splitCount: 1,
299
+ providers: ["METASTABLE"],
300
+ })
301
+
302
+ if (res != null) {
303
+ console.log(JSON.stringify(res, null, 2))
304
+ }
305
+ console.log("amount in", res?.amountIn.toString())
306
+ console.log("amount out", res?.amountOut.toString())
307
+
308
+ const txb = new Transaction()
309
+ if (res != null) {
310
+ console.log(JSON.stringify(res, null, 2))
311
+ await client.fastRouterSwap({
312
+ routers: res,
313
+ txb,
314
+ slippage: 0.01,
315
+ refreshAllCoins: true,
316
+ payDeepFeeAmount: 0,
317
+ })
318
+ txb.setSender(client.signer)
319
+
320
+ let result = await client.devInspectTransactionBlock(txb)
321
+ console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
322
+ for (const event of result.events) {
323
+ console.log("event", JSON.stringify(event, null, 2))
324
+ }
325
+ }
326
+ }
327
+ })
328
+
329
+ test("Build Router TX", async () => {
330
+ const amount = "10000000"
331
+
332
+ const res = await client.findRouters({
333
+ from: T_USDC,
334
+ target: M_USDC,
335
+ amount: new BN(amount),
336
+ byAmountIn: true,
337
+ depth: 3,
338
+ providers: ["METASTABLE"],
339
+ })
340
+
341
+ console.log("amount in", res?.amountIn.toString())
342
+ console.log("amount out", res?.amountOut.toString())
343
+
344
+ const txb = new Transaction()
345
+
346
+ if (res != null) {
347
+ console.log(JSON.stringify(res, null, 2))
348
+ await client.fastRouterSwap({
349
+ routers: res,
350
+ txb,
351
+ slippage: 0.01,
352
+ refreshAllCoins: true,
353
+ payDeepFeeAmount: 0,
354
+ })
355
+
356
+ txb.setSender(client.signer)
357
+ const buildTxb = await txb.build({ client: client.client })
358
+ // const buildTxb = await txb.getData()
359
+
360
+ console.log("buildTxb", buildTxb)
361
+ // printTransaction(txb)
362
+
363
+ let result = await client.devInspectTransactionBlock(txb)
364
+ console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
365
+ for (const event of result.events) {
366
+ console.log("event", JSON.stringify(event, null, 2))
367
+ }
368
+
369
+ // if (result.effects.status.status === "success") {
370
+ // const result = await client.signAndExecuteTransaction(txb, keypair)
371
+ // console.log("result", result)
372
+ // } else {
373
+ // console.log("result", result)
374
+ // }
375
+ }
376
+ }, 600000)
377
+ })