@bolt-liquidity-hq/sui-client 0.1.0-beta.12 → 0.1.0-beta.13

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
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
9
  var __export = (target, all) => {
@@ -16,37 +18,51 @@ var __copyProps = (to, from, except, desc) => {
16
18
  }
17
19
  return to;
18
20
  };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
19
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
30
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
31
 
22
32
  // src/index.ts
23
33
  var index_exports = {};
24
34
  __export(index_exports, {
35
+ AssetPairResponseStruct: () => AssetPairResponseStruct,
25
36
  AssetPairStruct: () => AssetPairStruct,
26
- AssetPairsResponsePaginatedStruct: () => AssetPairsResponsePaginatedStruct,
27
37
  AssetPairsResponseStruct: () => AssetPairsResponseStruct,
28
38
  BaseLiquidityInfoStruct: () => BaseLiquidityInfoStruct,
29
39
  BaseLiquidityResponseStruct: () => BaseLiquidityResponseStruct,
30
40
  BcsAddressType: () => BcsAddressType,
31
41
  BoltSuiClient: () => BoltSuiClient,
32
- GetFeesResponseStruct: () => GetFeesResponseStruct,
33
- GetPoolInfoResponseStruct: () => GetPoolInfoResponseStruct,
34
42
  MarketResponseStruct: () => MarketResponseStruct,
35
43
  MarketStruct: () => MarketStruct,
36
44
  MarketsResponsePaginatedStruct: () => MarketsResponsePaginatedStruct,
37
45
  MarketsResponseStruct: () => MarketsResponseStruct,
38
46
  OracleConfigStruct: () => OracleConfigStruct,
39
47
  PaginationStruct: () => PaginationStruct,
48
+ PoolFeesInfoStruct: () => PoolFeesInfoStruct,
49
+ PoolInfoStruct: () => PoolInfoStruct,
40
50
  PriceDataStruct: () => PriceDataStruct,
41
51
  PriceResponseStruct: () => PriceResponseStruct,
42
52
  PricesResponsePaginatedStruct: () => PricesResponsePaginatedStruct,
43
- RouterConfigStruct: () => RouterConfigStruct
53
+ ProtocolFeesInfoStruct: () => ProtocolFeesInfoStruct,
54
+ RawPairStruct: () => RawPairStruct,
55
+ RawPriceStruct: () => RawPriceStruct,
56
+ RouterConfigStruct: () => RouterConfigStruct,
57
+ TypeNameStruct: () => TypeNameStruct
44
58
  });
45
59
  module.exports = __toCommonJS(index_exports);
46
60
 
47
61
  // src/lib/client.ts
48
- var import_core8 = require("@bolt-liquidity-hq/core");
62
+ var import_core12 = require("@bolt-liquidity-hq/core");
49
63
  var import_client = require("@mysten/sui/client");
64
+ var import_utils9 = require("@mysten/sui/utils");
65
+ var import_axios = __toESM(require("axios"), 1);
50
66
 
51
67
  // src/config/mainnet.ts
52
68
  var import_utils = require("@mysten/sui/utils");
@@ -82,21 +98,24 @@ var MainnetAssets = {
82
98
  coingeckoId: "usd-coin"
83
99
  }
84
100
  };
101
+ var MainnetPools = [];
85
102
 
86
103
  // src/config/testnet.ts
87
104
  var import_utils2 = require("@mysten/sui/utils");
105
+ var TestnetConfigUrl = "https://phi-labs-ltd.github.io/sui-outpost/testnet.json";
88
106
  var TestnetChainConfig = {
89
107
  name: "Sui Testnet",
90
108
  id: "103",
91
109
  rpcEndpoint: "https://fullnode.testnet.sui.io:443"
92
110
  };
93
111
  var TestnetContracts = {
94
- oracle: "0xecece01cfb23b5439e04b18fe656eaf2746b9087cf68f1d48797c8f71a3dd93b",
95
- router: "0x3881fdcb4a7fbcda8edc230e6f92eb57b24c0be6b44af0b5e1d0b45564f3ed00"
112
+ oracle: " ",
113
+ router: " "
96
114
  };
97
- var TestnetPackageId = "0x22384b1841229e2be878bb7e88833c03e23ff5dc39accd050fb932120602f85e";
98
- var TestnetPoolGlobalConfigId = "0xa9491e59fa63e666cbfdea2e880b2d8ba0085eeb244220cefa3fb817559cd79c";
115
+ var TestnetPackageId = "";
116
+ var TestnetPoolGlobalConfigId = "";
99
117
  var TestnetNativeTokenDenom = import_utils2.SUI_TYPE_ARG;
118
+ var TestnetHelperAssets = ["::test_btc::TEST_BTC", "::test_usdt::TEST_USDT"];
100
119
  var TestnetAssets = {
101
120
  [import_utils2.SUI_TYPE_ARG]: {
102
121
  symbol: "SUI",
@@ -115,20 +134,32 @@ var TestnetAssets = {
115
134
  decimals: 6,
116
135
  logo: "https://raw.githubusercontent.com/cosmos/chain-registry/master/noble/images/USDCoin.png",
117
136
  coingeckoId: "usd-coin"
137
+ },
138
+ "::test_btc::TEST_BTC": {
139
+ symbol: "TEST_BTC",
140
+ name: "Test BTC",
141
+ chainId: "103",
142
+ denom: "::test_btc::TEST_BTC",
143
+ decimals: 8,
144
+ logo: "https://github.com/cosmos/chain-registry/blob/master/_non-cosmos/bitcoin/images/btc.png",
145
+ coingeckoId: "bitcoin"
146
+ },
147
+ "::test_usdt::TEST_USDT": {
148
+ symbol: "TEST_USDT",
149
+ name: "Test USDT",
150
+ chainId: "103",
151
+ denom: "::test_usdt::TEST_USDT",
152
+ decimals: 6,
153
+ logo: "https://github.com/cosmos/chain-registry/blob/master/_non-cosmos/ethereum/images/usdt.png",
154
+ coingeckoId: "tether"
118
155
  }
119
156
  };
120
157
 
121
- // src/lib/oracle/get-asset-pairs.ts
122
- var import_bcs9 = require("@mysten/bcs");
123
-
124
- // src/lib/constants/defaults.ts
125
- var DEFAULT_PAGINATION_LIMIT = 50;
126
-
127
158
  // src/lib/constants/sui-objects.ts
128
159
  var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000000";
129
160
  var PRICE_ORACLE_MODULE = "price_oracle";
130
161
  var ROUTER_MODULE = "router";
131
- var POOL_MODULE = "settlement";
162
+ var POOL_MODULE = "pool";
132
163
 
133
164
  // src/lib/helpers/bcs-parse.ts
134
165
  var import_core = require("@bolt-liquidity-hq/core");
@@ -162,9 +193,6 @@ var parseDevInspectResult = (result, bcsType, resultIndex = 0, returnValueIndex
162
193
  });
163
194
  }
164
195
  };
165
- var parseMultipleResults = (info, schema) => {
166
- return schema.map((bcsType, index) => parseDevInspectResult(info, bcsType, 0, index));
167
- };
168
196
 
169
197
  // src/lib/helpers/coin-manager.ts
170
198
  var import_core2 = require("@bolt-liquidity-hq/core");
@@ -598,11 +626,40 @@ var queryDevInspect = async (suiClient, target, args, typeArguments, senderAddre
598
626
  }
599
627
  };
600
628
 
601
- // src/lib/helpers/txs.ts
629
+ // src/lib/helpers/transactions.ts
602
630
  var import_core4 = require("@bolt-liquidity-hq/core");
631
+ var import_bcs2 = require("@mysten/bcs");
603
632
  var import_transactions2 = require("@mysten/sui/transactions");
604
633
  var import_utils4 = require("@mysten/sui/utils");
605
634
  var import_bignumber = require("bignumber.js");
635
+ var buildSwapTxArgs = async (client, swapParams, signer) => {
636
+ const { assetIn, amountIn, assetOut, minimumAmountOut, receiver } = swapParams;
637
+ const pool = client.routerClient.getPool(assetIn, assetOut);
638
+ if (!pool) {
639
+ throw new import_core4.NotFoundError(`Pool for the pair ${assetIn}/${assetOut}`);
640
+ }
641
+ const isSell = (0, import_utils4.normalizeStructTag)(assetIn) === pool.baseDenom;
642
+ const FUNCTION_NAME = isSell ? "swap_sell" : "swap_buy";
643
+ const finalSigner = client.getSigner(signer);
644
+ const tx = new import_transactions2.Transaction();
645
+ const coinManager = new CoinManager(client.suiClient, finalSigner.toSuiAddress());
646
+ const coinInput = await coinManager.prepareCoinInput(tx, assetIn, amountIn);
647
+ return {
648
+ signer: finalSigner,
649
+ target: [client.packageId, ROUTER_MODULE, FUNCTION_NAME],
650
+ args: [
651
+ pool.poolAddress,
652
+ client.contracts.oracle,
653
+ import_utils4.SUI_CLOCK_OBJECT_ID,
654
+ coinInput,
655
+ import_bcs2.bcs.u64().serialize(amountIn),
656
+ import_bcs2.bcs.option(import_bcs2.bcs.string()).serialize(minimumAmountOut),
657
+ import_bcs2.bcs.option(import_bcs2.bcs.string()).serialize(receiver)
658
+ ],
659
+ typeArguments: [isSell ? assetIn : assetOut, isSell ? assetOut : assetIn],
660
+ tx
661
+ };
662
+ };
606
663
  var signAndExecuteTx = async (suiClient, signer, target, args, typeArguments, transaction, options) => {
607
664
  const tx = transaction ?? new import_transactions2.Transaction();
608
665
  const targetString = Array.isArray(target) ? `${target[0]}::${target[1]}::${target[2]}` : target;
@@ -633,7 +690,7 @@ var signAndExecuteTx = async (suiClient, signer, target, args, typeArguments, tr
633
690
  });
634
691
  }
635
692
  };
636
- var estimateTxGasPrice = async (suiClient, target, args, typeArguments, transaction, gasAdjustment = import_core4.DEFAULT_GAS_ADJUSTMENT) => {
693
+ var estimateTxGasPrice = async (suiClient, senderAddress, target, args, typeArguments, transaction, gasAdjustment = import_core4.DEFAULT_GAS_ADJUSTMENT) => {
637
694
  const tx = transaction ?? new import_transactions2.Transaction();
638
695
  const targetString = Array.isArray(target) ? `${target[0]}::${target[1]}::${target[2]}` : target;
639
696
  const txArgs = args?.map(
@@ -644,6 +701,7 @@ var estimateTxGasPrice = async (suiClient, target, args, typeArguments, transact
644
701
  arguments: txArgs,
645
702
  typeArguments
646
703
  });
704
+ tx.setSender(senderAddress);
647
705
  try {
648
706
  const transactionBytes = await tx.build({ client: suiClient });
649
707
  const dryRunResult = await suiClient.dryRunTransactionBlock({
@@ -678,7 +736,8 @@ var import_core5 = require("@bolt-liquidity-hq/core");
678
736
  var import_bignumber2 = require("bignumber.js");
679
737
  var parseOracleConfigStructOutput = (output) => {
680
738
  return {
681
- admin: output.admin,
739
+ // TODO: try to query admin somewhere else? to fill empty value
740
+ admin: "",
682
741
  priceThresholdRatio: output.price_threshold_ratio,
683
742
  priceExpireTime: {
684
743
  secs: Number(output.default_price_expiry_seconds),
@@ -689,47 +748,46 @@ var parseOracleConfigStructOutput = (output) => {
689
748
  var parseAssetPairStructOutput = (output) => {
690
749
  return {
691
750
  base: {
692
- name: output.base_symbol,
693
- symbol: output.base_symbol,
751
+ name: output.base_name,
752
+ // TODO: map a different value for name/symbols
753
+ symbol: output.base_name,
694
754
  precision: output.base_precision
695
755
  },
696
756
  quote: {
697
- name: output.quote_symbol,
698
- symbol: output.quote_symbol,
757
+ name: output.quote_name,
758
+ // TODO: map a different value for name/symbols
759
+ symbol: output.quote_name,
699
760
  precision: output.quote_precision
700
761
  }
701
762
  };
702
763
  };
703
- var parsePriceDataStructOutput = (output) => {
764
+ var parseAssetPairsResponseStructOutput = (output) => {
765
+ return output.map((item) => parseAssetPairStructOutput(item.info));
766
+ };
767
+ var parsePriceDataStructOutput = (output, baseDenom, quoteDenom) => {
704
768
  return {
705
- baseDenom: output.base_symbol,
706
- quoteDenom: output.quote_symbol,
707
- price: output.price,
708
- expiryTime: (0, import_bignumber2.BigNumber)(output.expiry_time_ms).times(1e6).toFixed(),
769
+ baseDenom,
770
+ quoteDenom,
771
+ price: output.price.price,
772
+ expiryTime: (0, import_bignumber2.BigNumber)(output.price.expiry).times(1e6).toFixed(),
709
773
  isInverse: false
710
774
  };
711
775
  };
712
- var parsePriceResponseStructOutput = (output) => {
776
+ var parsePriceResponseStructOutput = (output, baseDenom, quoteDenom) => {
713
777
  if (!output.pair_data) {
714
778
  throw new import_core5.InvalidObjectError("Can't find pair data price");
715
779
  }
716
- return parsePriceDataStructOutput(output.pair_data);
717
- };
718
- var parseAssetPairsResponsePaginatedStructOutput = (output) => {
719
- return output.asset_pairs.map((item) => parseAssetPairStructOutput(item));
720
- };
721
- var parsePricesResponsePaginatedStructOutput = (output) => {
722
- return output.prices.map((item) => parsePriceDataStructOutput(item));
780
+ return parsePriceDataStructOutput(output.pair_data, baseDenom, quoteDenom);
723
781
  };
724
782
 
725
783
  // src/types/bcs.ts
726
- var import_bcs2 = require("@mysten/bcs");
784
+ var import_bcs3 = require("@mysten/bcs");
727
785
  var PaginationStruct = {
728
- total_count: import_bcs2.bcs.u64(),
729
- has_next_page: import_bcs2.bcs.bool(),
730
- next_cursor: import_bcs2.bcs.option(import_bcs2.bcs.string())
786
+ total_count: import_bcs3.bcs.u64(),
787
+ has_next_page: import_bcs3.bcs.bool(),
788
+ next_cursor: import_bcs3.bcs.option(import_bcs3.bcs.string())
731
789
  };
732
- var BcsAddressType = new import_bcs2.BcsType({
790
+ var BcsAddressType = new import_bcs3.BcsType({
733
791
  name: "address",
734
792
  read(reader) {
735
793
  const bytes = new Uint8Array(32);
@@ -749,112 +807,114 @@ var BcsAddressType = new import_bcs2.BcsType({
749
807
  });
750
808
 
751
809
  // src/types/oracle.ts
752
- var import_bcs3 = require("@mysten/bcs");
753
- var OracleConfigStruct = import_bcs3.bcs.struct("Config", {
754
- admin: BcsAddressType,
755
- price_threshold_ratio: import_bcs3.bcs.u64(),
756
- default_price_expiry_seconds: import_bcs3.bcs.u64()
810
+ var import_bcs4 = require("@mysten/bcs");
811
+ var OracleConfigStruct = import_bcs4.bcs.struct("Config", {
812
+ price_threshold_ratio: import_bcs4.bcs.u64(),
813
+ default_price_expiry_seconds: import_bcs4.bcs.u64()
757
814
  });
758
- var AssetPairStruct = import_bcs3.bcs.struct("AssetPair", {
759
- base_symbol: import_bcs3.bcs.string(),
760
- quote_symbol: import_bcs3.bcs.string(),
761
- base_precision: import_bcs3.bcs.u8(),
762
- quote_precision: import_bcs3.bcs.u8()
815
+ var AssetPairStruct = import_bcs4.bcs.struct("AssetPair", {
816
+ base_name: import_bcs4.bcs.string(),
817
+ quote_name: import_bcs4.bcs.string(),
818
+ base_precision: import_bcs4.bcs.u8(),
819
+ quote_precision: import_bcs4.bcs.u8()
763
820
  });
764
- var AssetPairsResponseStruct = import_bcs3.bcs.struct("AssetPairsResponse", {
765
- asset_pairs: import_bcs3.bcs.vector(AssetPairStruct)
821
+ var TypeNameStruct = import_bcs4.bcs.struct("TypeName", {
822
+ name: import_bcs4.bcs.string()
766
823
  });
767
- var AssetPairsResponsePaginatedStruct = import_bcs3.bcs.struct("AssetPairsResponsePaginated", {
768
- asset_pairs: import_bcs3.bcs.vector(AssetPairStruct),
769
- ...PaginationStruct
824
+ var RawPairStruct = import_bcs4.bcs.struct("RawPair", {
825
+ base: TypeNameStruct,
826
+ quote: TypeNameStruct
827
+ });
828
+ var AssetPairResponseStruct = import_bcs4.bcs.struct("AssetPairResponse", {
829
+ pair: RawPairStruct,
830
+ info: AssetPairStruct
831
+ });
832
+ var AssetPairsResponseStruct = import_bcs4.bcs.vector(AssetPairResponseStruct);
833
+ var RawPriceStruct = import_bcs4.bcs.struct("RawPrice", {
834
+ price: import_bcs4.bcs.u128(),
835
+ expiry: import_bcs4.bcs.u64()
770
836
  });
771
- var PriceDataStruct = import_bcs3.bcs.struct("PriceData", {
772
- base_symbol: import_bcs3.bcs.string(),
773
- quote_symbol: import_bcs3.bcs.string(),
774
- price: import_bcs3.bcs.u128(),
775
- expiry_time_ms: import_bcs3.bcs.u64(),
776
- last_updated_ms: import_bcs3.bcs.u64(),
837
+ var PriceDataStruct = import_bcs4.bcs.struct("PriceData", {
838
+ price: RawPriceStruct,
839
+ last_updated_ms: import_bcs4.bcs.u64(),
777
840
  updater: BcsAddressType
778
841
  });
779
- var PriceResponseStruct = import_bcs3.bcs.struct("PriceResponse", {
780
- pair_data: import_bcs3.bcs.option(PriceDataStruct)
842
+ var PriceResponseStruct = import_bcs4.bcs.struct("PriceResponse", {
843
+ pair_data: import_bcs4.bcs.option(PriceDataStruct)
781
844
  });
782
- var PricesResponsePaginatedStruct = import_bcs3.bcs.struct("PricesResponsePaginated", {
783
- prices: import_bcs3.bcs.vector(PriceDataStruct),
845
+ var PricesResponsePaginatedStruct = import_bcs4.bcs.struct("PricesResponsePaginated", {
846
+ prices: import_bcs4.bcs.vector(PriceDataStruct),
784
847
  ...PaginationStruct
785
848
  });
786
849
 
787
850
  // src/types/router.ts
788
- var import_bcs5 = require("@mysten/bcs");
789
- var RouterConfigStruct = import_bcs5.bcs.struct("Config", {
851
+ var import_bcs6 = require("@mysten/bcs");
852
+ var RouterConfigStruct = import_bcs6.bcs.struct("Config", {
790
853
  admin: BcsAddressType,
791
854
  default_price_oracle_contract: BcsAddressType,
792
855
  default_protocol_fee_recipient: BcsAddressType,
793
- default_protocol_fee: import_bcs5.bcs.u64(),
794
- default_lp_fee: import_bcs5.bcs.u64()
856
+ default_protocol_fee: import_bcs6.bcs.u64(),
857
+ default_lp_fee: import_bcs6.bcs.u64()
795
858
  });
796
- var MarketStruct = import_bcs5.bcs.struct("Market", {
797
- base_asset_symbol: import_bcs5.bcs.string(),
798
- quote_assets_symbols: import_bcs5.bcs.vector(import_bcs5.bcs.string()),
799
- market_address: import_bcs5.bcs.string(),
800
- is_permissioned: import_bcs5.bcs.bool(),
801
- created_at_ms: import_bcs5.bcs.u64()
859
+ var MarketStruct = import_bcs6.bcs.struct("Market", {
860
+ base_asset_symbol: import_bcs6.bcs.string(),
861
+ quote_assets_symbols: import_bcs6.bcs.vector(import_bcs6.bcs.string()),
862
+ market_address: import_bcs6.bcs.string(),
863
+ is_permissioned: import_bcs6.bcs.bool(),
864
+ created_at_ms: import_bcs6.bcs.u64()
802
865
  });
803
- var MarketResponseStruct = import_bcs5.bcs.struct("MarketResponse", {
804
- market: import_bcs5.bcs.option(MarketStruct)
866
+ var MarketResponseStruct = import_bcs6.bcs.struct("MarketResponse", {
867
+ market: import_bcs6.bcs.option(MarketStruct)
805
868
  });
806
- var MarketsResponseStruct = import_bcs5.bcs.struct("MarketsResponse", {
807
- markets: import_bcs5.bcs.vector(MarketStruct)
869
+ var MarketsResponseStruct = import_bcs6.bcs.struct("MarketsResponse", {
870
+ markets: import_bcs6.bcs.vector(MarketStruct)
808
871
  });
809
- var MarketsResponsePaginatedStruct = import_bcs5.bcs.struct("MarketsResponsePaginated", {
810
- markets: import_bcs5.bcs.vector(MarketStruct),
872
+ var MarketsResponsePaginatedStruct = import_bcs6.bcs.struct("MarketsResponsePaginated", {
873
+ markets: import_bcs6.bcs.vector(MarketStruct),
811
874
  ...PaginationStruct
812
875
  });
813
- var BaseLiquidityInfoStruct = import_bcs5.bcs.struct("BaseLiquidityInfo", {
814
- denom: import_bcs5.bcs.string(),
815
- amount: import_bcs5.bcs.u64()
876
+ var BaseLiquidityInfoStruct = import_bcs6.bcs.struct("BaseLiquidityInfo", {
877
+ denom: import_bcs6.bcs.string(),
878
+ amount: import_bcs6.bcs.u64()
816
879
  });
817
- var BaseLiquidityResponseStruct = import_bcs5.bcs.struct("BaseLiquidityResponse", {
818
- base_assets: import_bcs5.bcs.vector(BaseLiquidityInfoStruct),
880
+ var BaseLiquidityResponseStruct = import_bcs6.bcs.struct("BaseLiquidityResponse", {
881
+ base_assets: import_bcs6.bcs.vector(BaseLiquidityInfoStruct),
819
882
  ...PaginationStruct
820
883
  });
821
884
 
822
885
  // src/types/pool.ts
823
- var import_bcs7 = require("@mysten/bcs");
824
- var GetPoolInfoResponseStruct = [
825
- import_bcs7.bcs.u64(),
826
- import_bcs7.bcs.u128(),
827
- BcsAddressType,
828
- import_bcs7.bcs.bool()
829
- ];
830
- var GetFeesResponseStruct = [import_bcs7.bcs.u64(), import_bcs7.bcs.u64(), import_bcs7.bcs.u64()];
886
+ var import_bcs8 = require("@mysten/bcs");
887
+ var PoolInfoStruct = import_bcs8.bcs.struct("PoolInfo", {
888
+ base_liquidity: import_bcs8.bcs.u64(),
889
+ total_lp_shares: import_bcs8.bcs.u64(),
890
+ admin: BcsAddressType,
891
+ is_paused: import_bcs8.bcs.bool()
892
+ });
893
+ var PoolFeesInfoStruct = import_bcs8.bcs.struct("PoolFeesInfo", {
894
+ swap_fee_pct: import_bcs8.bcs.u64(),
895
+ lp_withdrawal_fee_pct: import_bcs8.bcs.u64(),
896
+ lp_fee_pct: import_bcs8.bcs.u64()
897
+ });
898
+ var ProtocolFeesInfoStruct = import_bcs8.bcs.struct("ProtocolFeesInfo", {
899
+ bolt_fee_addr: BcsAddressType,
900
+ swap_fee_pct: import_bcs8.bcs.u64(),
901
+ lp_withdrawal_fee_pct: import_bcs8.bcs.u64()
902
+ });
831
903
 
832
904
  // src/lib/oracle/get-asset-pairs.ts
833
905
  var getAssetPairs = async (client) => {
834
- const ASSET_PAIRS_PAGINATED_FUNCTION = "asset_pairs_paginated";
835
- const result = [];
836
- let currentCursor = null;
837
- let hasNextPage = true;
838
- while (hasNextPage) {
839
- const response = await queryDevInspect(
840
- client.suiClient,
841
- [client.packageId, PRICE_ORACLE_MODULE, ASSET_PAIRS_PAGINATED_FUNCTION],
842
- [
843
- client.contracts.oracle,
844
- import_bcs9.bcs.option(import_bcs9.bcs.u64()).serialize(DEFAULT_PAGINATION_LIMIT),
845
- import_bcs9.bcs.option(import_bcs9.bcs.string()).serialize(currentCursor)
846
- ]
847
- );
848
- const output = parseDevInspectResult(response, AssetPairsResponsePaginatedStruct);
849
- const assetPairs = parseAssetPairsResponsePaginatedStructOutput(output);
850
- result.push(...assetPairs);
851
- currentCursor = output.next_cursor;
852
- hasNextPage = output.has_next_page;
853
- }
854
- return result;
906
+ const ASSET_PAIRS_FUNCTION = "asset_pairs";
907
+ const response = await queryDevInspect(
908
+ client.suiClient,
909
+ [client.packageId, PRICE_ORACLE_MODULE, ASSET_PAIRS_FUNCTION],
910
+ [client.contracts.oracle]
911
+ );
912
+ const output = parseDevInspectResult(response, AssetPairsResponseStruct);
913
+ return parseAssetPairsResponseStructOutput(output);
855
914
  };
856
915
 
857
916
  // src/lib/oracle/get-assets.ts
917
+ var import_utils5 = require("@mysten/sui/utils");
858
918
  var getAssets = async (client) => {
859
919
  const assetPairs = await client.getAllOracleAssetPairs();
860
920
  const uniqueOracleAssets = {};
@@ -868,7 +928,7 @@ var getAssets = async (client) => {
868
928
  symbol: item.name,
869
929
  name: item.name,
870
930
  chainId: client.chainConfig.id,
871
- denom: item.symbol,
931
+ denom: (0, import_utils5.normalizeStructTag)(item.symbol),
872
932
  decimals: item.precision,
873
933
  logo: void 0,
874
934
  coingeckoId: void 0
@@ -889,248 +949,162 @@ var getOracleConfig = async (client) => {
889
949
  };
890
950
 
891
951
  // src/lib/oracle/get-price.ts
892
- var import_bcs10 = require("@mysten/bcs");
893
- var import_utils5 = require("@mysten/sui/utils");
894
952
  var getPrice = async (client, baseDenom, quoteDenom) => {
895
953
  const GET_PRICE_FUNCTION = "get_price";
896
954
  const response = await queryDevInspect(
897
955
  client.suiClient,
898
956
  [client.packageId, PRICE_ORACLE_MODULE, GET_PRICE_FUNCTION],
899
- [
900
- client.contracts.oracle,
901
- import_bcs10.bcs.string().serialize(baseDenom),
902
- import_bcs10.bcs.string().serialize(quoteDenom),
903
- import_utils5.SUI_CLOCK_OBJECT_ID
904
- ]
957
+ [client.contracts.oracle],
958
+ [baseDenom, quoteDenom]
905
959
  );
906
960
  const output = parseDevInspectResult(response, PriceResponseStruct);
907
- return parsePriceResponseStructOutput(output);
961
+ return parsePriceResponseStructOutput(output, baseDenom, quoteDenom);
908
962
  };
909
963
 
910
964
  // src/lib/oracle/get-prices.ts
911
- var import_bcs11 = require("@mysten/bcs");
965
+ var import_core6 = require("@bolt-liquidity-hq/core");
966
+ var import_utils6 = require("@mysten/sui/utils");
912
967
  var getPrices = async (client) => {
913
- const GET_PRICES_PAGINATED_FUNCTION = "get_prices_paginated";
914
- const result = [];
915
- let currentCursor = null;
916
- let hasNextPage = true;
917
- while (hasNextPage) {
918
- const response = await queryDevInspect(
919
- client.suiClient,
920
- [client.packageId, PRICE_ORACLE_MODULE, GET_PRICES_PAGINATED_FUNCTION],
921
- [
922
- client.contracts.oracle,
923
- import_bcs11.bcs.option(import_bcs11.bcs.u64()).serialize(DEFAULT_PAGINATION_LIMIT),
924
- import_bcs11.bcs.option(import_bcs11.bcs.string()).serialize(currentCursor)
925
- ]
968
+ const oracleObject = await client.suiClient.getObject({
969
+ id: client.contracts.oracle,
970
+ options: { showContent: true }
971
+ });
972
+ if (!oracleObject.data?.content || oracleObject.data.content.dataType !== "moveObject") {
973
+ throw new import_core6.NotFoundError("Oracle object");
974
+ }
975
+ const pricesTableId = oracleObject.data.content.fields?.prices?.fields?.id?.id;
976
+ if (!pricesTableId) {
977
+ throw new import_core6.NotFoundError("Prices table in the Oracle contract");
978
+ }
979
+ const prices = [];
980
+ let cursor = null;
981
+ while (true) {
982
+ const dynamicFields = await client.suiClient.getDynamicFields({
983
+ parentId: pricesTableId,
984
+ cursor,
985
+ limit: 50
986
+ // Max limit per request
987
+ });
988
+ const fieldPromises = dynamicFields.data.map(
989
+ (field) => client.suiClient.getDynamicFieldObject({
990
+ parentId: pricesTableId,
991
+ name: field.name
992
+ })
926
993
  );
927
- const output = parseDevInspectResult(response, PricesResponsePaginatedStruct);
928
- const assetPairs = parsePricesResponsePaginatedStructOutput(output);
929
- result.push(...assetPairs);
930
- currentCursor = output.next_cursor;
931
- hasNextPage = output.has_next_page;
994
+ const fieldObjects = await Promise.all(fieldPromises);
995
+ fieldObjects.forEach((obj, index) => {
996
+ if (obj.data?.content?.dataType === "moveObject") {
997
+ const fields = obj.data.content.fields?.value?.fields?.price?.fields;
998
+ const pairKey = dynamicFields.data[index]?.name?.value;
999
+ if (fields && pairKey) {
1000
+ prices.push({
1001
+ baseDenom: (0, import_utils6.normalizeStructTag)(pairKey.base.name),
1002
+ quoteDenom: (0, import_utils6.normalizeStructTag)(pairKey.quote.name),
1003
+ price: fields.price,
1004
+ expiryTime: fields.expiry
1005
+ });
1006
+ }
1007
+ }
1008
+ });
1009
+ if (!dynamicFields.hasNextPage) break;
1010
+ cursor = dynamicFields.nextCursor;
932
1011
  }
933
- return result;
1012
+ return prices;
934
1013
  };
935
1014
 
936
1015
  // src/lib/router/estimate-swap-exact-in-gas-fees.ts
937
- var import_core6 = require("@bolt-liquidity-hq/core");
938
- var import_bcs12 = require("@mysten/bcs");
939
- var import_transactions3 = require("@mysten/sui/transactions");
940
- var import_utils6 = require("@mysten/sui/utils");
941
- var estimateSwapExactInGasFees = async (client, { assetIn, amountIn, assetOut, minimumAmountOut, receiver }, signer, gasAdjustment = import_core6.DEFAULT_GAS_ADJUSTMENT) => {
942
- const SWAP_EXACT_IN_FUNCTION = "swap_exact_in";
943
- const finalSigner = client.getSigner(signer);
944
- const tx = new import_transactions3.Transaction();
945
- const coinManager = new CoinManager(client.suiClient, finalSigner.toSuiAddress());
946
- const coinInput = await coinManager.prepareCoinInput(tx, assetIn, amountIn);
1016
+ var import_core7 = require("@bolt-liquidity-hq/core");
1017
+ var estimateSwapExactInGasFees = async (client, swapParams, signer, gasAdjustment = import_core7.DEFAULT_GAS_ADJUSTMENT) => {
1018
+ const swapArgs = await buildSwapTxArgs(client, swapParams, signer);
947
1019
  return await estimateTxGasPrice(
948
1020
  client.suiClient,
949
- [client.packageId, ROUTER_MODULE, SWAP_EXACT_IN_FUNCTION],
950
- [
951
- client.contracts.router,
952
- import_bcs12.bcs.string().serialize(assetOut),
953
- "",
954
- // TODO: pass correct pool when router can actually route to the pools depending on other arguments
955
- import_bcs12.bcs.string().serialize(assetIn),
956
- import_bcs12.bcs.option(import_bcs12.bcs.string()).serialize(minimumAmountOut),
957
- import_bcs12.bcs.option(import_bcs12.bcs.string()).serialize(receiver),
958
- coinInput,
959
- import_utils6.SUI_CLOCK_OBJECT_ID
960
- ],
961
- [assetIn, assetOut],
962
- tx,
1021
+ swapArgs.signer.toSuiAddress(),
1022
+ swapArgs.target,
1023
+ swapArgs.args,
1024
+ swapArgs.typeArguments,
1025
+ swapArgs.tx,
963
1026
  gasAdjustment
964
1027
  );
965
1028
  };
966
1029
 
967
1030
  // src/lib/router/get-all-base-liquidity.ts
968
- var import_bcs13 = require("@mysten/bcs");
969
-
970
- // src/lib/router/parsers.ts
971
- var import_core7 = require("@bolt-liquidity-hq/core");
972
- var parseMarketStructOutput = (output) => {
973
- return {
974
- poolAddress: output.market_address,
975
- baseDenom: output.base_asset_symbol,
976
- quoteDenoms: output.quote_assets_symbols
977
- };
978
- };
979
- var parseMarketResponseStructOutput = (output) => {
980
- if (!output.market) {
981
- throw new import_core7.NotFoundError("Market", void 0, { output });
982
- }
983
- return parseMarketStructOutput(output.market);
984
- };
985
- var parseMarketsResponsePaginatedStructOutput = (output) => {
986
- return output.markets.map((item) => parseMarketStructOutput(item));
987
- };
988
- var parseRouterConfigStructOutput = (output) => {
989
- return {
990
- admin: output.admin,
991
- defaultPriceOracleContract: output.default_price_oracle_contract,
992
- defaultProtocolFeeRecipient: output.default_protocol_fee_recipient,
993
- defaultProtocolFee: output.default_protocol_fee,
994
- defaultLpFee: output.default_lp_fee
995
- };
1031
+ var import_core8 = require("@bolt-liquidity-hq/core");
1032
+ var getAllBaseLiquidity = async (_client) => {
1033
+ throw new import_core8.NotImplementedError("getRouterConfig on Sui Client");
996
1034
  };
997
- var parseBaseLiquidityResponseStructOutput = (output) => {
998
- return output.base_assets.map((item) => ({
999
- baseLiquidity: {
1000
- denom: item.denom,
1001
- amount: item.amount
1002
- },
1003
- totalShares: ""
1004
- // TODO: add real total shares if it is returned by the smart contract later
1005
- }));
1035
+
1036
+ // src/lib/router/get-all-quotes-for-user.ts
1037
+ var import_core9 = require("@bolt-liquidity-hq/core");
1038
+ var getAllQuotesForUser = async (_client, _lpAddress) => {
1039
+ throw new import_core9.NotImplementedError("getRouterConfig on Sui Client");
1006
1040
  };
1007
1041
 
1008
- // src/lib/router/get-all-base-liquidity.ts
1009
- var getAllBaseLiquidity = async (client) => {
1010
- const BASE_LIQUIDITY_ALL_PAGINATED_FUNCTION = "base_liquidity_all_paginated";
1011
- const result = {};
1012
- let currentCursor = null;
1013
- let hasNextPage = true;
1014
- while (hasNextPage) {
1015
- const response = await queryDevInspect(
1016
- client.suiClient,
1017
- [client.packageId, ROUTER_MODULE, BASE_LIQUIDITY_ALL_PAGINATED_FUNCTION],
1018
- [
1019
- client.contracts.router,
1020
- import_bcs13.bcs.option(import_bcs13.bcs.u64()).serialize(DEFAULT_PAGINATION_LIMIT),
1021
- import_bcs13.bcs.option(import_bcs13.bcs.string()).serialize(currentCursor)
1022
- ]
1023
- );
1024
- const output = parseDevInspectResult(response, BaseLiquidityResponseStruct);
1025
- const baseLiquidities = parseBaseLiquidityResponseStructOutput(output);
1026
- for (const item of baseLiquidities) {
1027
- result[item.baseLiquidity.denom] = item;
1028
- }
1029
- currentCursor = output.next_cursor;
1030
- hasNextPage = output.has_next_page;
1042
+ // src/lib/router/get-pool-by-denom.ts
1043
+ var import_core10 = require("@bolt-liquidity-hq/core");
1044
+ var getPoolByDenom = async (client, baseDenom, quoteDenom) => {
1045
+ const result = await client.routerClient.getPool(baseDenom, quoteDenom);
1046
+ if (!result) {
1047
+ throw new import_core10.NotFoundError("Pool", `Didn't find a pool to swap ${baseDenom} for ${quoteDenom}`);
1031
1048
  }
1032
1049
  return result;
1033
1050
  };
1034
1051
 
1035
- // src/lib/router/get-all-quotes-for-user.ts
1036
- var import_bcs14 = require("@mysten/bcs");
1037
- var getAllQuotesForUser = async (client, lpAddress) => {
1038
- const QUOTES_FOR_USER_ALL_FUNCTION = "quotes_for_user_all";
1039
- const response = await queryDevInspect(
1040
- client.suiClient,
1041
- [client.packageId, ROUTER_MODULE, QUOTES_FOR_USER_ALL_FUNCTION],
1042
- [client.contracts.router, import_bcs14.bcs.string().serialize(lpAddress)]
1043
- );
1044
- console.log(response);
1045
- return {};
1052
+ // src/lib/router/get-pools.ts
1053
+ var getPools = async (client) => {
1054
+ return await client.routerClient.getPools();
1046
1055
  };
1047
1056
 
1048
- // src/lib/router/get-pool-for-base.ts
1049
- var import_bcs15 = require("@mysten/bcs");
1050
- var getPoolForBase = async (client, baseDenom) => {
1051
- const MARKET_FOR_BASE_FUNCTION = "market_for_base";
1052
- const response = await queryDevInspect(
1053
- client.suiClient,
1054
- [client.packageId, ROUTER_MODULE, MARKET_FOR_BASE_FUNCTION],
1055
- [client.contracts.router, import_bcs15.bcs.string().serialize(baseDenom)]
1056
- );
1057
- const output = parseDevInspectResult(response, MarketResponseStruct);
1058
- return parseMarketResponseStructOutput(output);
1057
+ // src/lib/router/get-router-config.ts
1058
+ var import_core11 = require("@bolt-liquidity-hq/core");
1059
+ var getRouterConfig = async (_client) => {
1060
+ throw new import_core11.NotImplementedError("getRouterConfig on Sui Client");
1059
1061
  };
1060
1062
 
1061
- // src/lib/router/get-pools.ts
1062
- var import_bcs16 = require("@mysten/bcs");
1063
- var getPools = async (client) => {
1064
- const MARKETS_PAGINATED_FUNCTION = "markets_paginated";
1065
- const result = [];
1066
- let currentCursor = null;
1067
- let hasNextPage = true;
1068
- while (hasNextPage) {
1069
- const response = await queryDevInspect(
1070
- client.suiClient,
1071
- [client.packageId, ROUTER_MODULE, MARKETS_PAGINATED_FUNCTION],
1072
- [
1073
- client.contracts.router,
1074
- import_bcs16.bcs.option(import_bcs16.bcs.u64()).serialize(DEFAULT_PAGINATION_LIMIT),
1075
- import_bcs16.bcs.option(import_bcs16.bcs.string()).serialize(currentCursor)
1076
- ]
1063
+ // src/lib/router/router-client/RouterClient.ts
1064
+ var import_utils7 = require("@mysten/sui/utils");
1065
+ var RouterClient = class {
1066
+ constructor(pools) {
1067
+ this.pools = pools;
1068
+ }
1069
+ getPool(denomIn, denomOut) {
1070
+ const normalizedDenomIn = (0, import_utils7.normalizeStructTag)(denomIn);
1071
+ const normalizedDenomOut = (0, import_utils7.normalizeStructTag)(denomOut);
1072
+ const directPairPool = this.pools.find(
1073
+ (item) => item.baseDenom === normalizedDenomIn && item.quoteDenoms.includes(normalizedDenomOut)
1077
1074
  );
1078
- const output = parseDevInspectResult(response, MarketsResponsePaginatedStruct);
1079
- const pools = parseMarketsResponsePaginatedStructOutput(output);
1080
- result.push(...pools);
1081
- currentCursor = output.next_cursor;
1082
- hasNextPage = output.has_next_page;
1075
+ if (directPairPool) {
1076
+ return directPairPool;
1077
+ }
1078
+ const inversePairPool = this.pools.find(
1079
+ (item) => item.baseDenom === normalizedDenomOut && item.quoteDenoms.includes(normalizedDenomIn)
1080
+ );
1081
+ if (inversePairPool) {
1082
+ return inversePairPool;
1083
+ }
1084
+ return;
1085
+ }
1086
+ getPools() {
1087
+ return this.pools;
1083
1088
  }
1084
- return result;
1085
- };
1086
-
1087
- // src/lib/router/get-router-config.ts
1088
- var getRouterConfig = async (client) => {
1089
- const CONFIG_FUNCTION = "config";
1090
- const response = await queryDevInspect(
1091
- client.suiClient,
1092
- [client.packageId, ROUTER_MODULE, CONFIG_FUNCTION],
1093
- [client.contracts.router]
1094
- );
1095
- const output = parseDevInspectResult(response, RouterConfigStruct);
1096
- return parseRouterConfigStructOutput(output);
1097
1089
  };
1098
1090
 
1099
1091
  // src/lib/router/swap-exact-in.ts
1100
- var import_bcs17 = require("@mysten/bcs");
1101
- var import_transactions4 = require("@mysten/sui/transactions");
1102
- var import_utils7 = require("@mysten/sui/utils");
1103
- var swapExactIn = async (client, { assetIn, amountIn, assetOut, minimumAmountOut, receiver }, signer) => {
1104
- const SWAP_EXACT_IN_FUNCTION = "swap_exact_in";
1105
- const finalSigner = client.getSigner(signer);
1106
- const tx = new import_transactions4.Transaction();
1107
- const coinManager = new CoinManager(client.suiClient, finalSigner.toSuiAddress());
1108
- const coinInput = await coinManager.prepareCoinInput(tx, assetIn, amountIn);
1092
+ var swapExactIn = async (client, swapParams, signer) => {
1093
+ const swapArgs = await buildSwapTxArgs(client, swapParams, signer);
1109
1094
  const txOutput = await signAndExecuteTx(
1110
1095
  client.suiClient,
1111
- finalSigner,
1112
- [client.packageId, ROUTER_MODULE, SWAP_EXACT_IN_FUNCTION],
1113
- [
1114
- client.contracts.router,
1115
- import_bcs17.bcs.string().serialize(assetOut),
1116
- "",
1117
- // TODO: pass correct pool when router can actually route to the pools depending on other arguments
1118
- import_bcs17.bcs.string().serialize(assetIn),
1119
- import_bcs17.bcs.option(import_bcs17.bcs.string()).serialize(minimumAmountOut),
1120
- import_bcs17.bcs.option(import_bcs17.bcs.string()).serialize(receiver),
1121
- coinInput,
1122
- import_utils7.SUI_CLOCK_OBJECT_ID
1123
- ],
1124
- [assetIn, assetOut],
1125
- tx,
1096
+ swapArgs.signer,
1097
+ swapArgs.target,
1098
+ swapArgs.args,
1099
+ swapArgs.typeArguments,
1100
+ swapArgs.tx,
1126
1101
  { showEffects: true, showEvents: true, showBalanceChanges: true }
1127
1102
  );
1128
1103
  return {
1129
1104
  txOutput,
1130
1105
  txHash: txOutput.digest,
1131
- amountOut: "",
1132
- // TODO: implement when contract emits event
1133
- assetOut
1106
+ amountOut: txOutput.events?.at(0)?.parsedJson?.["amount_out"] ?? "0",
1107
+ assetOut: swapParams.assetOut
1134
1108
  };
1135
1109
  };
1136
1110
 
@@ -1138,67 +1112,67 @@ var swapExactIn = async (client, { assetIn, amountIn, assetOut, minimumAmountOut
1138
1112
  var import_utils8 = require("@mysten/sui/utils");
1139
1113
 
1140
1114
  // src/lib/settlement/parsers.ts
1141
- var parseSettlementConfigStructOutput = (globalConfig, feesOutput) => {
1115
+ var parseSettlementConfigStructOutput = (routerClient, poolFeesInfo, protocolFeesInfo, priceOracleContract) => {
1142
1116
  return {
1143
- priceOracleContract: "0x",
1144
- // Should come from pool config
1145
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
1146
- protocolFeeRecipient: globalConfig.data?.content?.fields.protocol_fee_recipient || "",
1147
- protocolFee: feesOutput[0],
1148
- // Protocol fee percentage
1149
- lpFee: feesOutput[2],
1150
- // LP fee percentage
1117
+ priceOracleContract,
1118
+ protocolFeeRecipient: protocolFeesInfo.bolt_fee_addr,
1119
+ protocolFee: poolFeesInfo.swap_fee_pct,
1120
+ lpFee: poolFeesInfo.lp_fee_pct,
1151
1121
  allowanceMode: "allow",
1152
1122
  // Should come from pool config
1153
- lps: ["0x"],
1154
- // Should come from pool config
1155
- minBaseOut: "1"
1156
- // Should come from pool config
1123
+ lps: routerClient.getPools().map((item) => item.poolAddress),
1124
+ minBaseOut: "0"
1125
+ // Should come from pool config
1157
1126
  };
1158
1127
  };
1159
1128
 
1160
1129
  // src/lib/settlement/get-pool-info.ts
1161
1130
  var getPoolInfo = async (client, contractAddress) => {
1162
- const GET_FEES_FUNCTION = "get_fees";
1163
- const [globalConfig, fees] = await Promise.all([
1164
- // Fetch the global pool configuration object
1165
- client.suiClient.getObject({
1166
- id: client.poolGlobalConfigId,
1167
- options: {
1168
- showContent: true,
1169
- showType: true
1170
- }
1171
- }),
1172
- // Query pool-specific fee structure
1131
+ const GET_POOL_FEES_INFO_FUNCTION = "get_pool_fees_info";
1132
+ const GET_PROTOCOL_FEES_INFO_FUNCTION = "get_protocol_fees_info";
1133
+ const [poolFeesInfo, protocolFeesInfo] = await Promise.all([
1134
+ // Query pool fee information
1135
+ queryDevInspect(
1136
+ client.suiClient,
1137
+ [client.packageId, POOL_MODULE, GET_POOL_FEES_INFO_FUNCTION],
1138
+ [contractAddress],
1139
+ // TODO: get the base token of the pool to pass it here instead of hardcoded SUI token
1140
+ [import_utils8.SUI_TYPE_ARG]
1141
+ ),
1142
+ // Query protocol fee information
1173
1143
  queryDevInspect(
1174
1144
  client.suiClient,
1175
- [client.packageId, POOL_MODULE, GET_FEES_FUNCTION],
1145
+ [client.packageId, POOL_MODULE, GET_PROTOCOL_FEES_INFO_FUNCTION],
1176
1146
  [contractAddress],
1177
1147
  // TODO: get the base token of the pool to pass it here instead of hardcoded SUI token
1178
1148
  [import_utils8.SUI_TYPE_ARG]
1179
1149
  )
1180
1150
  ]);
1181
- const feesOutput = parseMultipleResults(fees, GetFeesResponseStruct);
1182
- return parseSettlementConfigStructOutput(globalConfig, feesOutput);
1151
+ const poolFeesInfoOutput = parseDevInspectResult(poolFeesInfo, PoolFeesInfoStruct);
1152
+ const protocolFeesInfoOutput = parseDevInspectResult(protocolFeesInfo, ProtocolFeesInfoStruct);
1153
+ return parseSettlementConfigStructOutput(
1154
+ client.routerClient,
1155
+ poolFeesInfoOutput,
1156
+ protocolFeesInfoOutput,
1157
+ client.contracts.oracle
1158
+ );
1183
1159
  };
1184
1160
 
1185
- // src/tests/constants/sui-objects.ts
1186
- var TEST_POOL = "0xdd05c1caea7b6725da3f67e30e99872033fc5d3a610a4f72ac1c434bc81c3c0d";
1187
-
1188
- // src/lib/settlement/get-pool-info-for-base.ts
1189
- var getPoolInfoForBase = async (client, baseDenom) => {
1190
- const pool = await getPoolForBase(client, baseDenom && "SUI");
1191
- return await getPoolInfo(client, pool.poolAddress || TEST_POOL);
1161
+ // src/lib/settlement/get-pool-info-by-denom.ts
1162
+ var getPoolInfoByDenom = async (client, baseDenom, quoteDenom) => {
1163
+ const pool = await getPoolByDenom(client, baseDenom, quoteDenom);
1164
+ return await getPoolInfo(client, pool.poolAddress);
1192
1165
  };
1193
1166
 
1194
1167
  // src/lib/client.ts
1195
- var BoltSuiClient = class extends import_core8.BaseClient {
1168
+ var BoltSuiClient = class extends import_core12.BaseClient {
1196
1169
  /**
1197
1170
  * Creates a new instance of the BoltSuiClient.
1198
1171
  *
1199
1172
  * The client automatically configures itself based on the specified environment,
1200
1173
  * loading the appropriate contract addresses, chain configuration, native token denomination,
1201
- * and assets from configuration files.
1174
+ * and assets from configuration files. For testnet environments, the client can dynamically
1175
+ * fetch configuration from a remote URL.
1202
1176
  *
1203
1177
  * @param config - (Optional) Configuration for the client
1204
1178
  * @param config.environment - (Optional) The deployment environment ('mainnet' or 'testnet'). Defaults to 'mainnet'
@@ -1224,7 +1198,7 @@ var BoltSuiClient = class extends import_core8.BaseClient {
1224
1198
  * // Use default configuration (Sui mainnet)
1225
1199
  * const client = new BoltSuiClient();
1226
1200
  *
1227
- * // Use testnet configuration
1201
+ * // Use testnet configuration (will fetch config dynamically)
1228
1202
  * const testnetClient = new BoltSuiClient({
1229
1203
  * environment: 'testnet'
1230
1204
  * });
@@ -1267,12 +1241,14 @@ var BoltSuiClient = class extends import_core8.BaseClient {
1267
1241
  */
1268
1242
  constructor(config) {
1269
1243
  const { environment = "mainnet", customOverride, signer, suiClient } = config ?? {};
1270
- const defaultChainConfig = environment === "mainnet" ? MainnetChainConfig : TestnetChainConfig;
1271
- const defaultContracts = environment === "mainnet" ? MainnetContracts : TestnetContracts;
1272
- const defaultPackageId = environment === "mainnet" ? MainnetPackageId : TestnetPackageId;
1273
- const defaultPoolGlobalConfigId = environment === "mainnet" ? MainnetPoolGlobalConfigId : TestnetPoolGlobalConfigId;
1274
- const defaultNativeTokenDenom = environment === "mainnet" ? MainnetNativeTokenDenom : TestnetNativeTokenDenom;
1275
- const assetsConfig = environment === "mainnet" ? MainnetAssets : TestnetAssets;
1244
+ const isEnvironmentMainnet = environment === "mainnet";
1245
+ const defaultChainConfig = isEnvironmentMainnet ? MainnetChainConfig : TestnetChainConfig;
1246
+ const defaultContracts = isEnvironmentMainnet ? MainnetContracts : TestnetContracts;
1247
+ const defaultPackageId = isEnvironmentMainnet ? MainnetPackageId : TestnetPackageId;
1248
+ const defaultPoolGlobalConfigId = isEnvironmentMainnet ? MainnetPoolGlobalConfigId : TestnetPoolGlobalConfigId;
1249
+ const defaultNativeTokenDenom = isEnvironmentMainnet ? MainnetNativeTokenDenom : TestnetNativeTokenDenom;
1250
+ const assetsConfig = isEnvironmentMainnet ? MainnetAssets : TestnetAssets;
1251
+ const pools = isEnvironmentMainnet ? MainnetPools : [];
1276
1252
  const chainConfig = {
1277
1253
  id: customOverride?.chainConfig?.id ?? defaultChainConfig.id,
1278
1254
  name: customOverride?.chainConfig?.name ?? defaultChainConfig.name,
@@ -1310,18 +1286,30 @@ var BoltSuiClient = class extends import_core8.BaseClient {
1310
1286
  __publicField(this, "poolGlobalConfigId");
1311
1287
  /**
1312
1288
  * Cached instance of the Signer for transaction execution
1313
- * @private
1314
1289
  */
1315
1290
  __publicField(this, "signer");
1316
1291
  /**
1317
1292
  * Instance of the Sui client to interact with the blockchain
1318
1293
  */
1319
1294
  __publicField(this, "suiClient");
1295
+ /**
1296
+ * URL for fetching testnet configuration dynamically.
1297
+ * Used to load package IDs, oracle addresses, and asset configurations for testnet environments.
1298
+ * @private
1299
+ */
1300
+ __publicField(this, "configFileUrl");
1301
+ /**
1302
+ * Router client instance for managing pool configurations and routing calculations.
1303
+ * Handles pool discovery and optimal path finding for swaps.
1304
+ */
1305
+ __publicField(this, "routerClient");
1320
1306
  this.chainConfig = chainConfig;
1321
1307
  this.packageId = packageId;
1322
1308
  this.poolGlobalConfigId = poolGlobalConfigId;
1323
1309
  this.signer = signer;
1324
1310
  this.suiClient = suiClient ?? new import_client.SuiClient({ url: chainConfig.rpcEndpoint });
1311
+ this.routerClient = new RouterClient(pools);
1312
+ this.configFileUrl = isEnvironmentMainnet ? void 0 : TestnetConfigUrl;
1325
1313
  }
1326
1314
  /**
1327
1315
  * Gets or sets the signer for transaction execution.
@@ -1349,7 +1337,7 @@ var BoltSuiClient = class extends import_core8.BaseClient {
1349
1337
  getSigner(newSigner) {
1350
1338
  this.signer = newSigner ?? this.signer;
1351
1339
  if (!this.signer) {
1352
- throw new import_core8.MissingParameterError("signer");
1340
+ throw new import_core12.MissingParameterError("signer");
1353
1341
  }
1354
1342
  return this.signer;
1355
1343
  }
@@ -1357,51 +1345,81 @@ var BoltSuiClient = class extends import_core8.BaseClient {
1357
1345
  // Only add documentation here if you need to override or add implementation-specific details
1358
1346
  /** @inheritdoc */
1359
1347
  async getOracleConfig() {
1348
+ await this.loadConfigFromUrl();
1360
1349
  return await getOracleConfig(this);
1361
1350
  }
1362
1351
  /** @inheritdoc */
1363
1352
  async getAllOracleAssetPairs() {
1353
+ await this.loadConfigFromUrl();
1364
1354
  return await getAssetPairs(this);
1365
1355
  }
1366
1356
  /** @inheritdoc */
1367
1357
  async getPrice(baseDenom, quoteDenom) {
1358
+ await this.loadConfigFromUrl();
1368
1359
  return await getPrice(this, baseDenom, quoteDenom);
1369
1360
  }
1370
1361
  /** @inheritdoc */
1371
1362
  async getAllPrices() {
1363
+ await this.loadConfigFromUrl();
1372
1364
  return await getPrices(this);
1373
1365
  }
1374
1366
  /** @inheritdoc */
1375
1367
  async getRouterConfig() {
1368
+ await this.loadConfigFromUrl();
1376
1369
  return await getRouterConfig(this);
1377
1370
  }
1378
1371
  /** @inheritdoc */
1379
1372
  async getAllBaseAssetsLiquidity() {
1373
+ await this.loadConfigFromUrl();
1380
1374
  return await getAllBaseLiquidity(this);
1381
1375
  }
1382
1376
  /** @inheritdoc */
1383
1377
  async getAllQuotesByUser(address) {
1378
+ await this.loadConfigFromUrl();
1384
1379
  return await getAllQuotesForUser(this, address);
1385
1380
  }
1386
- /** @inheritdoc */
1387
- async getPoolByBaseAsset(baseDenom) {
1388
- return await getPoolForBase(this, baseDenom);
1381
+ /**
1382
+ * @inheritdoc
1383
+ *
1384
+ * @remarks
1385
+ * In the Sui implementation, both `baseDenom` and `quoteDenom` parameters are required.
1386
+ * The Sui architecture uses both asset types to uniquely identify pools for specific
1387
+ * trading pairs.
1388
+ *
1389
+ * @throws Will throw an error if no pool exists for the specified base/quote asset pair
1390
+ */
1391
+ async getPoolByDenom(baseDenom, quoteDenom) {
1392
+ await this.loadConfigFromUrl();
1393
+ return await getPoolByDenom(this, baseDenom, quoteDenom);
1389
1394
  }
1390
1395
  /** @inheritdoc */
1391
1396
  async getAllPools() {
1397
+ await this.loadConfigFromUrl();
1392
1398
  return await getPools(this);
1393
1399
  }
1394
- // Satisfy the base class requirement
1400
+ /** @inheritdoc */
1395
1401
  async getPoolConfig(poolContractAddress) {
1402
+ await this.loadConfigFromUrl();
1396
1403
  return await getPoolInfo(this, poolContractAddress);
1397
1404
  }
1398
1405
  /** @inheritdoc */
1399
1406
  async getAssets() {
1407
+ await this.loadConfigFromUrl();
1400
1408
  return await getAssets(this);
1401
1409
  }
1402
- /** @inheritdoc */
1403
- async getPoolConfigByBaseAsset(baseDenom) {
1404
- return await getPoolInfoForBase(this, baseDenom);
1410
+ /**
1411
+ * @inheritdoc
1412
+ *
1413
+ * @remarks
1414
+ * In the Sui implementation, both `baseDenom` and `quoteDenom` parameters are required.
1415
+ * The Sui architecture uses both asset types to uniquely identify pools for specific
1416
+ * trading pairs.
1417
+ *
1418
+ * @throws Will throw an error if no pool exists for the specified base/quote asset pair
1419
+ */
1420
+ async getPoolConfigByDenom(baseDenom, quoteDenom) {
1421
+ await this.loadConfigFromUrl();
1422
+ return await getPoolInfoByDenom(this, baseDenom, quoteDenom);
1405
1423
  }
1406
1424
  /**
1407
1425
  * @inheritdoc
@@ -1432,6 +1450,7 @@ var BoltSuiClient = class extends import_core8.BaseClient {
1432
1450
  * which includes details like gas costs, transaction effects, object changes, and events.
1433
1451
  */
1434
1452
  async swap(params, signer) {
1453
+ await this.loadConfigFromUrl();
1435
1454
  return await swapExactIn(this, params, signer);
1436
1455
  }
1437
1456
  /**
@@ -1463,7 +1482,66 @@ var BoltSuiClient = class extends import_core8.BaseClient {
1463
1482
  * - Sui's gas model includes computation, storage, and storage rebates
1464
1483
  */
1465
1484
  async estimateSwapGasFees(params, signer, gasAdjustment) {
1485
+ await this.loadConfigFromUrl();
1466
1486
  return await estimateSwapExactInGasFees(this, params, signer, gasAdjustment);
1467
1487
  }
1488
+ /**
1489
+ * Loads configuration from a remote URL for testnet environments.
1490
+ *
1491
+ * This method fetches and applies dynamic configuration including:
1492
+ * - Package ID for Bolt contracts
1493
+ * - Oracle contract address
1494
+ * - Pool global configuration ID
1495
+ * - Asset mappings and metadata
1496
+ * - Pool configurations
1497
+ *
1498
+ * The method is called automatically before API operations when a config URL is set.
1499
+ * After successful loading, the config URL is cleared to prevent redundant fetches.
1500
+ *
1501
+ * @private
1502
+ * @remarks
1503
+ * - Only executes if `configFileUrl` is set (typically for testnet)
1504
+ * - Updates testnet-specific asset denoms with their actual deployed addresses
1505
+ * - Populates the router client's pool configurations
1506
+ * - Normalizes struct tags for consistency
1507
+ */
1508
+ async loadConfigFromUrl() {
1509
+ if (!this.configFileUrl) {
1510
+ return;
1511
+ }
1512
+ const response = await import_axios.default.get(this.configFileUrl);
1513
+ const { package_id, oracle_id, global_config_id, assets, pools } = response.data ?? {};
1514
+ if (!this.packageId && package_id) {
1515
+ this.packageId = package_id;
1516
+ }
1517
+ if (!this.contracts.oracle.trim() && oracle_id) {
1518
+ this.contracts.oracle = oracle_id;
1519
+ }
1520
+ if (!this.poolGlobalConfigId && global_config_id) {
1521
+ this.poolGlobalConfigId = global_config_id;
1522
+ }
1523
+ for (const item of Object.values(assets)) {
1524
+ for (const suffix of TestnetHelperAssets) {
1525
+ if (item.includes(suffix) && this.assetsConfig[suffix]) {
1526
+ this.assetsConfig[item] = {
1527
+ ...this.assetsConfig[suffix],
1528
+ denom: item
1529
+ };
1530
+ delete this.assetsConfig[suffix];
1531
+ break;
1532
+ }
1533
+ }
1534
+ }
1535
+ if (this.routerClient.pools.length === 0) {
1536
+ for (const item of pools) {
1537
+ this.routerClient.pools.push({
1538
+ poolAddress: item.pool_object_id,
1539
+ baseDenom: (0, import_utils9.normalizeStructTag)(item.base),
1540
+ quoteDenoms: Object.values(assets).map((auxAsset) => (0, import_utils9.normalizeStructTag)(auxAsset)).filter((auxAsset) => auxAsset !== (0, import_utils9.normalizeStructTag)(item.base))
1541
+ });
1542
+ }
1543
+ }
1544
+ this.configFileUrl = void 0;
1545
+ }
1468
1546
  };
1469
1547
  //# sourceMappingURL=index.cjs.map