@bolt-liquidity-hq/sui-client 0.1.0-beta.18 → 0.1.0-beta.20

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.cjs CHANGED
@@ -45,7 +45,7 @@ __export(index_exports, {
45
45
  MarketsResponseStruct: () => MarketsResponseStruct,
46
46
  OracleConfigStruct: () => OracleConfigStruct,
47
47
  PaginationStruct: () => PaginationStruct,
48
- PoolFeesInfoStruct: () => PoolFeesInfoStruct,
48
+ PoolConfigStruct: () => PoolConfigStruct,
49
49
  PoolInfoStruct: () => PoolInfoStruct,
50
50
  PriceDataStruct: () => PriceDataStruct,
51
51
  PriceResponseStruct: () => PriceResponseStruct,
@@ -61,7 +61,7 @@ module.exports = __toCommonJS(index_exports);
61
61
  // src/lib/client.ts
62
62
  var import_core15 = require("@bolt-liquidity-hq/core");
63
63
  var import_client = require("@mysten/sui/client");
64
- var import_utils10 = require("@mysten/sui/utils");
64
+ var import_utils11 = require("@mysten/sui/utils");
65
65
  var import_axios = __toESM(require("axios"), 1);
66
66
 
67
67
  // src/config/common.ts
@@ -76,11 +76,11 @@ var MainnetChainConfig = {
76
76
  rpcEndpoint: "https://fullnode.mainnet.sui.io:443"
77
77
  };
78
78
  var MainnetContracts = {
79
- oracle: "0x...",
80
- router: "0x..."
79
+ oracle: "0xfa3975b98f3d0e3df18ed88ae6e69db31836b3f4212df02fae144b1e5a89ca8e",
80
+ router: " "
81
81
  };
82
- var MainnetPackageId = "0x...";
83
- var MainnetPoolGlobalConfigId = "0x...";
82
+ var MainnetPackageId = "0xc8724de692400a2a08585f6f7c8617acfb783abe2c66ae6a4680a21b36a504c5";
83
+ var MainnetPoolGlobalConfigId = "0x7bcd5035a991f42fa84c5a42216b5638cb3f1a8c4f065063093b0a3d5f165d63";
84
84
  var MainnetNativeTokenDenom = SUI_TOKEN_DENOM;
85
85
  var MainnetAssets = {
86
86
  [SUI_TOKEN_DENOM]: {
@@ -100,9 +100,38 @@ var MainnetAssets = {
100
100
  decimals: 6,
101
101
  logo: "https://raw.githubusercontent.com/cosmos/chain-registry/refs/heads/master/_non-cosmos/ethereum/images/usdc.png",
102
102
  coingeckoId: "usd-coin"
103
+ },
104
+ "0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL": {
105
+ symbol: "WAL",
106
+ name: "Walrus",
107
+ chainId: "101",
108
+ denom: "0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL",
109
+ decimals: 9,
110
+ logo: "https://app.lotusfinance.io/images/coins/wal-icon.svg",
111
+ coingeckoId: "walrus-2"
112
+ },
113
+ "0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT": {
114
+ symbol: "suiUSDT",
115
+ name: "Tether by Sui Bridge",
116
+ chainId: "101",
117
+ denom: "0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT",
118
+ decimals: 6,
119
+ logo: "https://raw.githubusercontent.com/cosmos/chain-registry/refs/heads/master/_non-cosmos/ethereum/images/usdt.svg",
120
+ coingeckoId: "tether"
103
121
  }
104
122
  };
105
- var MainnetPools = [];
123
+ var MainnetPools = [
124
+ {
125
+ poolAddress: "0x21167b2e981e2c0a693afcfe882a3a827d663118e19afcb92e45bfe43fe56278",
126
+ baseDenom: "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",
127
+ quoteDenoms: ["0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"]
128
+ },
129
+ {
130
+ poolAddress: "0x34fcaa553f1185e1c3a05de37b6a4d10c39535d19f9c8581eeae826434602b58",
131
+ baseDenom: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
132
+ quoteDenoms: ["0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"]
133
+ }
134
+ ];
106
135
 
107
136
  // src/config/testnet.ts
108
137
  var import_utils3 = require("@mysten/sui/utils");
@@ -119,7 +148,6 @@ var TestnetContracts = {
119
148
  var TestnetPackageId = "";
120
149
  var TestnetPoolGlobalConfigId = "";
121
150
  var TestnetNativeTokenDenom = SUI_TOKEN_DENOM;
122
- var TestnetHelperAssets = ["::test_btc::TEST_BTC", "::test_usdt::TEST_USDT"];
123
151
  var TestnetAssets = {
124
152
  [SUI_TOKEN_DENOM]: {
125
153
  symbol: "SUI",
@@ -156,6 +184,24 @@ var TestnetAssets = {
156
184
  decimals: 6,
157
185
  logo: "https://raw.githubusercontent.com/cosmos/chain-registry/refs/heads/master/_non-cosmos/ethereum/images/usdt.svg",
158
186
  coingeckoId: "tether"
187
+ },
188
+ "::test_deep::TEST_DEEP": {
189
+ symbol: "TEST_DEEP",
190
+ name: "TEST_DEEP",
191
+ chainId: "103",
192
+ denom: "::test_deep::TEST_DEEP",
193
+ decimals: 6,
194
+ logo: "https://app.lotusfinance.io/images/coins/deepbook-icon.svg",
195
+ coingeckoId: "deep"
196
+ },
197
+ "::test_wal::TEST_WAL": {
198
+ symbol: "TEST_WAL",
199
+ name: "TEST_WAL",
200
+ chainId: "103",
201
+ denom: "::test_wal::TEST_WAL",
202
+ decimals: 9,
203
+ logo: "https://app.lotusfinance.io/images/coins/wal-icon.svg",
204
+ coingeckoId: "walrus-2"
159
205
  }
160
206
  };
161
207
 
@@ -763,6 +809,7 @@ var getSignerAddress = (signer) => {
763
809
  // src/lib/oracle/parsers.ts
764
810
  var import_core5 = require("@bolt-liquidity-hq/core");
765
811
  var import_bignumber2 = require("bignumber.js");
812
+ var import_utils6 = require("@mysten/sui/utils");
766
813
  var parseOracleConfigStructOutput = (output) => {
767
814
  return {
768
815
  // TODO: try to query admin somewhere else? to fill empty value
@@ -774,24 +821,22 @@ var parseOracleConfigStructOutput = (output) => {
774
821
  }
775
822
  };
776
823
  };
777
- var parseAssetPairStructOutput = (output) => {
824
+ var parseAssetPairStructOutput = (output, assetsConfig) => {
778
825
  return {
779
826
  base: {
780
- name: output.base_name,
781
- // TODO: map a different value for name/symbols
782
- symbol: output.base_name,
827
+ name: assetsConfig?.[output.base_name]?.name ?? output.base_name.match(/([^:]+)$/)?.[1] ?? output.base_name,
828
+ symbol: (0, import_utils6.normalizeStructTag)(output.base_name),
783
829
  precision: output.base_precision
784
830
  },
785
831
  quote: {
786
- name: output.quote_name,
787
- // TODO: map a different value for name/symbols
788
- symbol: output.quote_name,
832
+ name: assetsConfig?.[output.quote_name]?.name ?? output.quote_name.match(/([^:]+)$/)?.[1] ?? output.quote_name,
833
+ symbol: (0, import_utils6.normalizeStructTag)(output.quote_name),
789
834
  precision: output.quote_precision
790
835
  }
791
836
  };
792
837
  };
793
- var parseAssetPairsResponseStructOutput = (output) => {
794
- return output.map((item) => parseAssetPairStructOutput(item.info));
838
+ var parseAssetPairsResponseStructOutput = (output, assetsConfig) => {
839
+ return output.map((item) => parseAssetPairStructOutput(item.info, assetsConfig));
795
840
  };
796
841
  var parsePriceDataStructOutput = (output, baseDenom, quoteDenom, isInverted) => {
797
842
  return {
@@ -908,12 +953,15 @@ var BaseLiquidityResponseStruct = import_bcs6.bcs.struct("BaseLiquidityResponse"
908
953
  ...PaginationStruct
909
954
  });
910
955
  var SwapSimulationResultStruct = import_bcs6.bcs.struct("SwapSimulationResult", {
911
- amount_out: import_bcs6.bcs.u128(),
956
+ base_out: import_bcs6.bcs.u64(),
957
+ quote_out: import_bcs6.bcs.u64(),
958
+ swap_fee_pct: import_bcs6.bcs.u64(),
912
959
  dynamic_fee_pct: import_bcs6.bcs.u64(),
913
960
  ideal_quote_amt: import_bcs6.bcs.u128(),
914
961
  swap_fee: import_bcs6.bcs.u64(),
915
962
  lp_fee: import_bcs6.bcs.u64(),
916
- protocol_fee: import_bcs6.bcs.u64()
963
+ protocol_fee: import_bcs6.bcs.u64(),
964
+ price_used: import_bcs6.bcs.u128()
917
965
  });
918
966
 
919
967
  // src/types/pool.ts
@@ -924,12 +972,13 @@ var PoolInfoStruct = import_bcs8.bcs.struct("PoolInfo", {
924
972
  admin: BcsAddressType,
925
973
  is_paused: import_bcs8.bcs.bool()
926
974
  });
927
- var PoolFeesInfoStruct = import_bcs8.bcs.struct("PoolFeesInfo", {
975
+ var PoolConfigStruct = import_bcs8.bcs.struct("PoolConfig", {
928
976
  swap_fee_pct: import_bcs8.bcs.u64(),
929
977
  lp_withdrawal_fee_pct: import_bcs8.bcs.u64(),
930
978
  lp_fee_pct: import_bcs8.bcs.u64(),
931
979
  max_dynamic_fee: import_bcs8.bcs.u64(),
932
- limit_ratio: import_bcs8.bcs.u64()
980
+ limit_ratio: import_bcs8.bcs.u64(),
981
+ min_base_out: import_bcs8.bcs.u64()
933
982
  });
934
983
  var ProtocolFeesInfoStruct = import_bcs8.bcs.struct("ProtocolFeesInfo", {
935
984
  swap_fee_pct: import_bcs8.bcs.u64(),
@@ -945,22 +994,22 @@ var getAssetPairs = async (client) => {
945
994
  [client.contracts.oracle]
946
995
  );
947
996
  const output = parseDevInspectResult(response, AssetPairsResponseStruct);
948
- return parseAssetPairsResponseStructOutput(output);
997
+ return parseAssetPairsResponseStructOutput(output, client.assetsConfig);
949
998
  };
950
999
 
951
1000
  // src/lib/oracle/get-assets.ts
952
- var import_utils6 = require("@mysten/sui/utils");
1001
+ var import_utils7 = require("@mysten/sui/utils");
953
1002
  var getAssets = async (client) => {
954
1003
  const assetPairs = await client.getAllOracleAssetPairs();
955
1004
  const uniqueOracleAssets = {};
956
1005
  for (const item of assetPairs) {
957
- uniqueOracleAssets[(0, import_utils6.normalizeStructTag)(item.base.symbol)] = {
1006
+ uniqueOracleAssets[(0, import_utils7.normalizeStructTag)(item.base.symbol)] = {
958
1007
  ...item.base,
959
- symbol: (0, import_utils6.normalizeStructTag)(item.base.symbol)
1008
+ symbol: (0, import_utils7.normalizeStructTag)(item.base.symbol)
960
1009
  };
961
- uniqueOracleAssets[(0, import_utils6.normalizeStructTag)(item.quote.symbol)] = {
1010
+ uniqueOracleAssets[(0, import_utils7.normalizeStructTag)(item.quote.symbol)] = {
962
1011
  ...item.quote,
963
- symbol: (0, import_utils6.normalizeStructTag)(item.quote.symbol)
1012
+ symbol: (0, import_utils7.normalizeStructTag)(item.quote.symbol)
964
1013
  };
965
1014
  }
966
1015
  return Object.values(uniqueOracleAssets).map(
@@ -969,7 +1018,7 @@ var getAssets = async (client) => {
969
1018
  symbol: item.name,
970
1019
  name: item.name,
971
1020
  chainId: client.chainConfig.id,
972
- denom: (0, import_utils6.normalizeStructTag)(item.symbol),
1021
+ denom: (0, import_utils7.normalizeStructTag)(item.symbol),
973
1022
  decimals: item.precision,
974
1023
  logo: void 0,
975
1024
  coingeckoId: void 0
@@ -1004,7 +1053,7 @@ var getPrice = async (client, baseDenom, quoteDenom) => {
1004
1053
 
1005
1054
  // src/lib/oracle/get-prices.ts
1006
1055
  var import_core6 = require("@bolt-liquidity-hq/core");
1007
- var import_utils7 = require("@mysten/sui/utils");
1056
+ var import_utils8 = require("@mysten/sui/utils");
1008
1057
  var getPrices = async (client) => {
1009
1058
  const oracleObject = await client.suiClient.getObject({
1010
1059
  id: client.contracts.oracle,
@@ -1039,8 +1088,8 @@ var getPrices = async (client) => {
1039
1088
  const pairKey = dynamicFields.data[index]?.name?.value;
1040
1089
  if (fields && pairKey) {
1041
1090
  prices.push({
1042
- baseDenom: (0, import_utils7.normalizeStructTag)(pairKey.base.name),
1043
- quoteDenom: (0, import_utils7.normalizeStructTag)(pairKey.quote.name),
1091
+ baseDenom: (0, import_utils8.normalizeStructTag)(pairKey.base.name),
1092
+ quoteDenom: (0, import_utils8.normalizeStructTag)(pairKey.quote.name),
1044
1093
  price: fields.price,
1045
1094
  expiryTime: fields.expiry
1046
1095
  });
@@ -1107,7 +1156,7 @@ var import_bignumber3 = require("bignumber.js");
1107
1156
  var parseSwapSimulationResultStructOutput = (output, poolAddress, assetOut) => {
1108
1157
  return {
1109
1158
  poolAddress,
1110
- amountOut: output.amount_out,
1159
+ amountOut: output.base_out,
1111
1160
  assetOut,
1112
1161
  protocolFee: output.protocol_fee,
1113
1162
  lpFee: output.lp_fee,
@@ -1117,14 +1166,14 @@ var parseSwapSimulationResultStructOutput = (output, poolAddress, assetOut) => {
1117
1166
  };
1118
1167
 
1119
1168
  // src/lib/router/router-client/RouterClient.ts
1120
- var import_utils8 = require("@mysten/sui/utils");
1169
+ var import_utils9 = require("@mysten/sui/utils");
1121
1170
  var RouterClient = class {
1122
1171
  constructor(pools) {
1123
1172
  this.pools = pools;
1124
1173
  }
1125
1174
  getPool(denomIn, denomOut) {
1126
- const normalizedDenomIn = (0, import_utils8.normalizeStructTag)(denomIn);
1127
- const normalizedDenomOut = (0, import_utils8.normalizeStructTag)(denomOut);
1175
+ const normalizedDenomIn = (0, import_utils9.normalizeStructTag)(denomIn);
1176
+ const normalizedDenomOut = (0, import_utils9.normalizeStructTag)(denomOut);
1128
1177
  const directPairPool = this.pools.find(
1129
1178
  (item) => item.baseDenom === normalizedDenomOut && item.quoteDenoms.includes(normalizedDenomIn)
1130
1179
  );
@@ -1153,7 +1202,7 @@ var RouterClient = class {
1153
1202
  // src/lib/router/simulate-swap.ts
1154
1203
  var import_core13 = require("@bolt-liquidity-hq/core");
1155
1204
  var import_bcs10 = require("@mysten/bcs");
1156
- var import_utils9 = require("@mysten/sui/utils");
1205
+ var import_utils10 = require("@mysten/sui/utils");
1157
1206
  var simulateSwap = async (client, { assetIn, amountIn, assetOut }) => {
1158
1207
  const pool = await client.routerClient.getPool(assetIn, assetOut);
1159
1208
  if (!pool) {
@@ -1163,7 +1212,7 @@ var simulateSwap = async (client, { assetIn, amountIn, assetOut }) => {
1163
1212
  const response = await queryDevInspect(
1164
1213
  client.suiClient,
1165
1214
  [client.packageId, POOL_MODULE, FUNCTION_NAME],
1166
- [pool.poolAddress, client.contracts.oracle, import_utils9.SUI_CLOCK_OBJECT_ID, import_bcs10.bcs.u64().serialize(amountIn)],
1215
+ [pool.poolAddress, client.contracts.oracle, import_utils10.SUI_CLOCK_OBJECT_ID, import_bcs10.bcs.u64().serialize(amountIn)],
1167
1216
  [pool.isInverse ? assetIn : assetOut, pool.isInverse ? assetOut : assetIn]
1168
1217
  );
1169
1218
  const output = parseDevInspectResult(response, SwapSimulationResultStruct);
@@ -1195,39 +1244,35 @@ var import_core14 = require("@bolt-liquidity-hq/core");
1195
1244
 
1196
1245
  // src/lib/settlement/parsers.ts
1197
1246
  var import_bignumber4 = require("bignumber.js");
1198
- var parseSettlementConfigStructOutput = (routerClient, poolFeesInfo, priceOracleContract) => {
1247
+ var parsePoolConfigStructOutput = (routerClient, poolConfig, priceOracleContract) => {
1199
1248
  return {
1200
1249
  priceOracleContract,
1201
1250
  protocolFeeRecipient: "0x",
1202
- protocolFee: (0, import_bignumber4.BigNumber)(poolFeesInfo.swap_fee_pct).div(BASIS_POINTS).toFixed(),
1203
- lpFee: (0, import_bignumber4.BigNumber)(poolFeesInfo.lp_fee_pct).div(BASIS_POINTS).toFixed(),
1251
+ // TODO: get real fee recipient
1252
+ protocolFee: (0, import_bignumber4.BigNumber)(poolConfig.swap_fee_pct).div(BASIS_POINTS).toFixed(),
1253
+ lpFee: (0, import_bignumber4.BigNumber)(poolConfig.lp_fee_pct).div(BASIS_POINTS).toFixed(),
1204
1254
  allowanceMode: "allow",
1205
1255
  // Should come from pool config
1206
1256
  lps: routerClient.getPools().map((item) => item.poolAddress),
1207
- minBaseOut: "0"
1208
- // Should come from pool config
1257
+ minBaseOut: (0, import_bignumber4.BigNumber)(poolConfig.min_base_out).toFixed()
1209
1258
  };
1210
1259
  };
1211
1260
 
1212
1261
  // src/lib/settlement/get-pool-info.ts
1213
1262
  var getPoolInfo = async (client, contractAddress) => {
1214
- const GET_POOL_FEES_INFO_FUNCTION = "get_pool_fees_info";
1263
+ const GET_POOL_CONFIG_FUNCTION = "get_pool_config";
1215
1264
  const pool = client.routerClient.pools.find((item) => item.poolAddress === contractAddress);
1216
1265
  if (!pool) {
1217
1266
  throw new import_core14.NotFoundError(`Pool with the address ${contractAddress}`);
1218
1267
  }
1219
- const poolFeesInfo = await queryDevInspect(
1268
+ const poolConfig = await queryDevInspect(
1220
1269
  client.suiClient,
1221
- [client.packageId, POOL_MODULE, GET_POOL_FEES_INFO_FUNCTION],
1270
+ [client.packageId, POOL_MODULE, GET_POOL_CONFIG_FUNCTION],
1222
1271
  [contractAddress],
1223
1272
  [pool.baseDenom]
1224
1273
  );
1225
- const poolFeesInfoOutput = parseDevInspectResult(poolFeesInfo, PoolFeesInfoStruct);
1226
- return parseSettlementConfigStructOutput(
1227
- client.routerClient,
1228
- poolFeesInfoOutput,
1229
- client.contracts.oracle
1230
- );
1274
+ const output = parseDevInspectResult(poolConfig, PoolConfigStruct);
1275
+ return parsePoolConfigStructOutput(client.routerClient, output, client.contracts.oracle);
1231
1276
  };
1232
1277
 
1233
1278
  // src/lib/settlement/get-pool-info-by-denom.ts
@@ -1597,13 +1642,13 @@ var BoltSuiClient = class extends import_core15.BaseClient {
1597
1642
  this.poolGlobalConfigId = global_config_id;
1598
1643
  }
1599
1644
  for (const item of Object.values(assets)) {
1600
- for (const suffix of TestnetHelperAssets) {
1601
- if (item.includes(suffix) && this.assetsConfig[suffix]) {
1645
+ for (const existingConfig of Object.values(this.assetsConfig)) {
1646
+ if (item.endsWith(existingConfig.denom)) {
1602
1647
  this.assetsConfig[item] = {
1603
- ...this.assetsConfig[suffix],
1648
+ ...existingConfig,
1604
1649
  denom: item
1605
1650
  };
1606
- delete this.assetsConfig[suffix];
1651
+ delete this.assetsConfig[existingConfig.denom];
1607
1652
  break;
1608
1653
  }
1609
1654
  }
@@ -1612,8 +1657,8 @@ var BoltSuiClient = class extends import_core15.BaseClient {
1612
1657
  for (const item of pools) {
1613
1658
  this.routerClient.pools.push({
1614
1659
  poolAddress: item.pool_object_id,
1615
- baseDenom: (0, import_utils10.normalizeStructTag)(item.base),
1616
- quoteDenoms: Object.values(assets).map((auxAsset) => (0, import_utils10.normalizeStructTag)(auxAsset)).filter((auxAsset) => auxAsset !== (0, import_utils10.normalizeStructTag)(item.base))
1660
+ baseDenom: (0, import_utils11.normalizeStructTag)(item.base),
1661
+ quoteDenoms: Object.values(assets).map((auxAsset) => (0, import_utils11.normalizeStructTag)(auxAsset)).filter((auxAsset) => auxAsset !== (0, import_utils11.normalizeStructTag)(item.base))
1617
1662
  });
1618
1663
  }
1619
1664
  }