@bolt-liquidity-hq/sui-client 0.1.0-beta.17 → 0.1.0-beta.19

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
@@ -156,6 +156,24 @@ var TestnetAssets = {
156
156
  decimals: 6,
157
157
  logo: "https://raw.githubusercontent.com/cosmos/chain-registry/refs/heads/master/_non-cosmos/ethereum/images/usdt.svg",
158
158
  coingeckoId: "tether"
159
+ },
160
+ "::test_deep::TEST_DEEP": {
161
+ symbol: "TEST_DEEP",
162
+ name: "TEST_DEEP",
163
+ chainId: "103",
164
+ denom: "0xb3aa3abfda8979c403edcb2fdc5cd433d3ccc0e6332844bdfdfddc870bf116b0::test_deep::TEST_DEEP",
165
+ decimals: 6,
166
+ logo: "https://app.lotusfinance.io/images/coins/deepbook-icon.svg",
167
+ coingeckoId: "deep"
168
+ },
169
+ "::test_wal::TEST_WAL": {
170
+ symbol: "TEST_WAL",
171
+ name: "TEST_WAL",
172
+ chainId: "103",
173
+ denom: "0xb3aa3abfda8979c403edcb2fdc5cd433d3ccc0e6332844bdfdfddc870bf116b0::test_wal::TEST_WAL",
174
+ decimals: 9,
175
+ logo: "https://app.lotusfinance.io/images/coins/wal-icon.svg",
176
+ coingeckoId: "walrus-2"
159
177
  }
160
178
  };
161
179
 
@@ -763,6 +781,7 @@ var getSignerAddress = (signer) => {
763
781
  // src/lib/oracle/parsers.ts
764
782
  var import_core5 = require("@bolt-liquidity-hq/core");
765
783
  var import_bignumber2 = require("bignumber.js");
784
+ var import_utils6 = require("@mysten/sui/utils");
766
785
  var parseOracleConfigStructOutput = (output) => {
767
786
  return {
768
787
  // TODO: try to query admin somewhere else? to fill empty value
@@ -774,24 +793,22 @@ var parseOracleConfigStructOutput = (output) => {
774
793
  }
775
794
  };
776
795
  };
777
- var parseAssetPairStructOutput = (output) => {
796
+ var parseAssetPairStructOutput = (output, assetsConfig) => {
778
797
  return {
779
798
  base: {
780
- name: output.base_name,
781
- // TODO: map a different value for name/symbols
782
- symbol: output.base_name,
799
+ name: assetsConfig?.[output.base_name]?.name ?? output.base_name.match(/([^:]+)$/)?.[1] ?? output.base_name,
800
+ symbol: (0, import_utils6.normalizeStructTag)(output.base_name),
783
801
  precision: output.base_precision
784
802
  },
785
803
  quote: {
786
- name: output.quote_name,
787
- // TODO: map a different value for name/symbols
788
- symbol: output.quote_name,
804
+ name: assetsConfig?.[output.quote_name]?.name ?? output.quote_name.match(/([^:]+)$/)?.[1] ?? output.quote_name,
805
+ symbol: (0, import_utils6.normalizeStructTag)(output.quote_name),
789
806
  precision: output.quote_precision
790
807
  }
791
808
  };
792
809
  };
793
- var parseAssetPairsResponseStructOutput = (output) => {
794
- return output.map((item) => parseAssetPairStructOutput(item.info));
810
+ var parseAssetPairsResponseStructOutput = (output, assetsConfig) => {
811
+ return output.map((item) => parseAssetPairStructOutput(item.info, assetsConfig));
795
812
  };
796
813
  var parsePriceDataStructOutput = (output, baseDenom, quoteDenom, isInverted) => {
797
814
  return {
@@ -908,12 +925,15 @@ var BaseLiquidityResponseStruct = import_bcs6.bcs.struct("BaseLiquidityResponse"
908
925
  ...PaginationStruct
909
926
  });
910
927
  var SwapSimulationResultStruct = import_bcs6.bcs.struct("SwapSimulationResult", {
911
- amount_out: import_bcs6.bcs.u128(),
928
+ base_out: import_bcs6.bcs.u64(),
929
+ quote_out: import_bcs6.bcs.u64(),
930
+ swap_fee_pct: import_bcs6.bcs.u64(),
912
931
  dynamic_fee_pct: import_bcs6.bcs.u64(),
913
932
  ideal_quote_amt: import_bcs6.bcs.u128(),
914
933
  swap_fee: import_bcs6.bcs.u64(),
915
934
  lp_fee: import_bcs6.bcs.u64(),
916
- protocol_fee: import_bcs6.bcs.u64()
935
+ protocol_fee: import_bcs6.bcs.u64(),
936
+ price_used: import_bcs6.bcs.u128()
917
937
  });
918
938
 
919
939
  // src/types/pool.ts
@@ -924,12 +944,13 @@ var PoolInfoStruct = import_bcs8.bcs.struct("PoolInfo", {
924
944
  admin: BcsAddressType,
925
945
  is_paused: import_bcs8.bcs.bool()
926
946
  });
927
- var PoolFeesInfoStruct = import_bcs8.bcs.struct("PoolFeesInfo", {
947
+ var PoolConfigStruct = import_bcs8.bcs.struct("PoolConfig", {
928
948
  swap_fee_pct: import_bcs8.bcs.u64(),
929
949
  lp_withdrawal_fee_pct: import_bcs8.bcs.u64(),
930
950
  lp_fee_pct: import_bcs8.bcs.u64(),
931
951
  max_dynamic_fee: import_bcs8.bcs.u64(),
932
- limit_ratio: import_bcs8.bcs.u64()
952
+ limit_ratio: import_bcs8.bcs.u64(),
953
+ min_base_out: import_bcs8.bcs.u64()
933
954
  });
934
955
  var ProtocolFeesInfoStruct = import_bcs8.bcs.struct("ProtocolFeesInfo", {
935
956
  swap_fee_pct: import_bcs8.bcs.u64(),
@@ -945,22 +966,22 @@ var getAssetPairs = async (client) => {
945
966
  [client.contracts.oracle]
946
967
  );
947
968
  const output = parseDevInspectResult(response, AssetPairsResponseStruct);
948
- return parseAssetPairsResponseStructOutput(output);
969
+ return parseAssetPairsResponseStructOutput(output, client.assetsConfig);
949
970
  };
950
971
 
951
972
  // src/lib/oracle/get-assets.ts
952
- var import_utils6 = require("@mysten/sui/utils");
973
+ var import_utils7 = require("@mysten/sui/utils");
953
974
  var getAssets = async (client) => {
954
975
  const assetPairs = await client.getAllOracleAssetPairs();
955
976
  const uniqueOracleAssets = {};
956
977
  for (const item of assetPairs) {
957
- uniqueOracleAssets[(0, import_utils6.normalizeStructTag)(item.base.symbol)] = {
978
+ uniqueOracleAssets[(0, import_utils7.normalizeStructTag)(item.base.symbol)] = {
958
979
  ...item.base,
959
- symbol: (0, import_utils6.normalizeStructTag)(item.base.symbol)
980
+ symbol: (0, import_utils7.normalizeStructTag)(item.base.symbol)
960
981
  };
961
- uniqueOracleAssets[(0, import_utils6.normalizeStructTag)(item.quote.symbol)] = {
982
+ uniqueOracleAssets[(0, import_utils7.normalizeStructTag)(item.quote.symbol)] = {
962
983
  ...item.quote,
963
- symbol: (0, import_utils6.normalizeStructTag)(item.quote.symbol)
984
+ symbol: (0, import_utils7.normalizeStructTag)(item.quote.symbol)
964
985
  };
965
986
  }
966
987
  return Object.values(uniqueOracleAssets).map(
@@ -969,7 +990,7 @@ var getAssets = async (client) => {
969
990
  symbol: item.name,
970
991
  name: item.name,
971
992
  chainId: client.chainConfig.id,
972
- denom: (0, import_utils6.normalizeStructTag)(item.symbol),
993
+ denom: (0, import_utils7.normalizeStructTag)(item.symbol),
973
994
  decimals: item.precision,
974
995
  logo: void 0,
975
996
  coingeckoId: void 0
@@ -1004,7 +1025,7 @@ var getPrice = async (client, baseDenom, quoteDenom) => {
1004
1025
 
1005
1026
  // src/lib/oracle/get-prices.ts
1006
1027
  var import_core6 = require("@bolt-liquidity-hq/core");
1007
- var import_utils7 = require("@mysten/sui/utils");
1028
+ var import_utils8 = require("@mysten/sui/utils");
1008
1029
  var getPrices = async (client) => {
1009
1030
  const oracleObject = await client.suiClient.getObject({
1010
1031
  id: client.contracts.oracle,
@@ -1039,8 +1060,8 @@ var getPrices = async (client) => {
1039
1060
  const pairKey = dynamicFields.data[index]?.name?.value;
1040
1061
  if (fields && pairKey) {
1041
1062
  prices.push({
1042
- baseDenom: (0, import_utils7.normalizeStructTag)(pairKey.base.name),
1043
- quoteDenom: (0, import_utils7.normalizeStructTag)(pairKey.quote.name),
1063
+ baseDenom: (0, import_utils8.normalizeStructTag)(pairKey.base.name),
1064
+ quoteDenom: (0, import_utils8.normalizeStructTag)(pairKey.quote.name),
1044
1065
  price: fields.price,
1045
1066
  expiryTime: fields.expiry
1046
1067
  });
@@ -1107,7 +1128,7 @@ var import_bignumber3 = require("bignumber.js");
1107
1128
  var parseSwapSimulationResultStructOutput = (output, poolAddress, assetOut) => {
1108
1129
  return {
1109
1130
  poolAddress,
1110
- amountOut: output.amount_out,
1131
+ amountOut: output.base_out,
1111
1132
  assetOut,
1112
1133
  protocolFee: output.protocol_fee,
1113
1134
  lpFee: output.lp_fee,
@@ -1117,14 +1138,14 @@ var parseSwapSimulationResultStructOutput = (output, poolAddress, assetOut) => {
1117
1138
  };
1118
1139
 
1119
1140
  // src/lib/router/router-client/RouterClient.ts
1120
- var import_utils8 = require("@mysten/sui/utils");
1141
+ var import_utils9 = require("@mysten/sui/utils");
1121
1142
  var RouterClient = class {
1122
1143
  constructor(pools) {
1123
1144
  this.pools = pools;
1124
1145
  }
1125
1146
  getPool(denomIn, denomOut) {
1126
- const normalizedDenomIn = (0, import_utils8.normalizeStructTag)(denomIn);
1127
- const normalizedDenomOut = (0, import_utils8.normalizeStructTag)(denomOut);
1147
+ const normalizedDenomIn = (0, import_utils9.normalizeStructTag)(denomIn);
1148
+ const normalizedDenomOut = (0, import_utils9.normalizeStructTag)(denomOut);
1128
1149
  const directPairPool = this.pools.find(
1129
1150
  (item) => item.baseDenom === normalizedDenomOut && item.quoteDenoms.includes(normalizedDenomIn)
1130
1151
  );
@@ -1153,7 +1174,7 @@ var RouterClient = class {
1153
1174
  // src/lib/router/simulate-swap.ts
1154
1175
  var import_core13 = require("@bolt-liquidity-hq/core");
1155
1176
  var import_bcs10 = require("@mysten/bcs");
1156
- var import_utils9 = require("@mysten/sui/utils");
1177
+ var import_utils10 = require("@mysten/sui/utils");
1157
1178
  var simulateSwap = async (client, { assetIn, amountIn, assetOut }) => {
1158
1179
  const pool = await client.routerClient.getPool(assetIn, assetOut);
1159
1180
  if (!pool) {
@@ -1163,7 +1184,7 @@ var simulateSwap = async (client, { assetIn, amountIn, assetOut }) => {
1163
1184
  const response = await queryDevInspect(
1164
1185
  client.suiClient,
1165
1186
  [client.packageId, POOL_MODULE, FUNCTION_NAME],
1166
- [pool.poolAddress, client.contracts.oracle, import_utils9.SUI_CLOCK_OBJECT_ID, import_bcs10.bcs.u64().serialize(amountIn)],
1187
+ [pool.poolAddress, client.contracts.oracle, import_utils10.SUI_CLOCK_OBJECT_ID, import_bcs10.bcs.u64().serialize(amountIn)],
1167
1188
  [pool.isInverse ? assetIn : assetOut, pool.isInverse ? assetOut : assetIn]
1168
1189
  );
1169
1190
  const output = parseDevInspectResult(response, SwapSimulationResultStruct);
@@ -1195,39 +1216,35 @@ var import_core14 = require("@bolt-liquidity-hq/core");
1195
1216
 
1196
1217
  // src/lib/settlement/parsers.ts
1197
1218
  var import_bignumber4 = require("bignumber.js");
1198
- var parseSettlementConfigStructOutput = (routerClient, poolFeesInfo, priceOracleContract) => {
1219
+ var parsePoolConfigStructOutput = (routerClient, poolConfig, priceOracleContract) => {
1199
1220
  return {
1200
1221
  priceOracleContract,
1201
1222
  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(),
1223
+ // TODO: get real fee recipient
1224
+ protocolFee: (0, import_bignumber4.BigNumber)(poolConfig.swap_fee_pct).div(BASIS_POINTS).toFixed(),
1225
+ lpFee: (0, import_bignumber4.BigNumber)(poolConfig.lp_fee_pct).div(BASIS_POINTS).toFixed(),
1204
1226
  allowanceMode: "allow",
1205
1227
  // Should come from pool config
1206
1228
  lps: routerClient.getPools().map((item) => item.poolAddress),
1207
- minBaseOut: "0"
1208
- // Should come from pool config
1229
+ minBaseOut: (0, import_bignumber4.BigNumber)(poolConfig.min_base_out).toFixed()
1209
1230
  };
1210
1231
  };
1211
1232
 
1212
1233
  // src/lib/settlement/get-pool-info.ts
1213
1234
  var getPoolInfo = async (client, contractAddress) => {
1214
- const GET_POOL_FEES_INFO_FUNCTION = "get_pool_fees_info";
1235
+ const GET_POOL_CONFIG_FUNCTION = "get_pool_config";
1215
1236
  const pool = client.routerClient.pools.find((item) => item.poolAddress === contractAddress);
1216
1237
  if (!pool) {
1217
1238
  throw new import_core14.NotFoundError(`Pool with the address ${contractAddress}`);
1218
1239
  }
1219
- const poolFeesInfo = await queryDevInspect(
1240
+ const poolConfig = await queryDevInspect(
1220
1241
  client.suiClient,
1221
- [client.packageId, POOL_MODULE, GET_POOL_FEES_INFO_FUNCTION],
1242
+ [client.packageId, POOL_MODULE, GET_POOL_CONFIG_FUNCTION],
1222
1243
  [contractAddress],
1223
1244
  [pool.baseDenom]
1224
1245
  );
1225
- const poolFeesInfoOutput = parseDevInspectResult(poolFeesInfo, PoolFeesInfoStruct);
1226
- return parseSettlementConfigStructOutput(
1227
- client.routerClient,
1228
- poolFeesInfoOutput,
1229
- client.contracts.oracle
1230
- );
1246
+ const output = parseDevInspectResult(poolConfig, PoolConfigStruct);
1247
+ return parsePoolConfigStructOutput(client.routerClient, output, client.contracts.oracle);
1231
1248
  };
1232
1249
 
1233
1250
  // src/lib/settlement/get-pool-info-by-denom.ts
@@ -1612,8 +1629,8 @@ var BoltSuiClient = class extends import_core15.BaseClient {
1612
1629
  for (const item of pools) {
1613
1630
  this.routerClient.pools.push({
1614
1631
  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))
1632
+ baseDenom: (0, import_utils11.normalizeStructTag)(item.base),
1633
+ quoteDenoms: Object.values(assets).map((auxAsset) => (0, import_utils11.normalizeStructTag)(auxAsset)).filter((auxAsset) => auxAsset !== (0, import_utils11.normalizeStructTag)(item.base))
1617
1634
  });
1618
1635
  }
1619
1636
  }