@bolt-liquidity-hq/sui-client 0.1.0-beta.25 → 0.1.0-beta.27

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/LICENSE CHANGED
@@ -186,7 +186,7 @@
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright [2021] Archway Network
189
+ Copyright [2025] Bolt Liquidity
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
package/README.md CHANGED
@@ -31,12 +31,12 @@ const price = await client.getPrice(
31
31
  console.log(`ARCH/USDC: ${price.price}`);
32
32
 
33
33
  // Execute a swap
34
- const result = await client.swap(signer, {
34
+ const result = await client.swap({
35
35
  '0x2::sui::SUI', // SUI
36
36
  amountIn: '1000000000', // 1 SUI
37
37
  '0x168da5bf1f48dafc111b0a488fa454aca95e0b5e::usdc::USDC' // USDC
38
38
  minimumAmountOut: '3500000', // 3.5 USDC minimum
39
- });
39
+ }, signer);
40
40
  ```
41
41
 
42
42
  ## 📖 API Reference
package/dist/index.cjs CHANGED
@@ -85,7 +85,7 @@ var MainnetAssets = {
85
85
  [SUI_TOKEN_DENOM]: {
86
86
  symbol: "SUI",
87
87
  name: "Sui",
88
- chainId: "101",
88
+ chainId: MainnetChainConfig.id,
89
89
  denom: SUI_TOKEN_DENOM,
90
90
  decimals: import_utils2.SUI_DECIMALS,
91
91
  logo: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/sui/info/logo.png",
@@ -94,7 +94,7 @@ var MainnetAssets = {
94
94
  "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC": {
95
95
  symbol: "USDC",
96
96
  name: "Circle USDC",
97
- chainId: "101",
97
+ chainId: MainnetChainConfig.id,
98
98
  denom: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
99
99
  decimals: 6,
100
100
  logo: "https://raw.githubusercontent.com/cosmos/chain-registry/refs/heads/master/_non-cosmos/ethereum/images/usdc.png",
@@ -103,7 +103,7 @@ var MainnetAssets = {
103
103
  "0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL": {
104
104
  symbol: "WAL",
105
105
  name: "Walrus",
106
- chainId: "101",
106
+ chainId: MainnetChainConfig.id,
107
107
  denom: "0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL",
108
108
  decimals: 9,
109
109
  logo: "https://app.lotusfinance.io/images/coins/wal-icon.svg",
@@ -112,7 +112,7 @@ var MainnetAssets = {
112
112
  "0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT": {
113
113
  symbol: "suiUSDT",
114
114
  name: "Tether by Sui Bridge",
115
- chainId: "101",
115
+ chainId: MainnetChainConfig.id,
116
116
  denom: "0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT",
117
117
  decimals: 6,
118
118
  logo: "https://raw.githubusercontent.com/cosmos/chain-registry/refs/heads/master/_non-cosmos/ethereum/images/usdt.svg",
@@ -151,7 +151,7 @@ var TestnetAssets = {
151
151
  [SUI_TOKEN_DENOM]: {
152
152
  symbol: "SUI",
153
153
  name: "Sui",
154
- chainId: "103",
154
+ chainId: TestnetChainConfig.id,
155
155
  denom: SUI_TOKEN_DENOM,
156
156
  decimals: import_utils3.SUI_DECIMALS,
157
157
  logo: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/sui/info/logo.png",
@@ -160,7 +160,7 @@ var TestnetAssets = {
160
160
  "0xa1ec7fc00a6f40db9693ad1415d0c193ad3906494428cf252621037bd7117e29::usdc::USDC": {
161
161
  symbol: "USDC",
162
162
  name: "Circle USDC",
163
- chainId: "103",
163
+ chainId: TestnetChainConfig.id,
164
164
  denom: "0xa1ec7fc00a6f40db9693ad1415d0c193ad3906494428cf252621037bd7117e29::usdc::USDC",
165
165
  decimals: 6,
166
166
  logo: "https://raw.githubusercontent.com/cosmos/chain-registry/refs/heads/master/_non-cosmos/ethereum/images/usdc.png",
@@ -169,7 +169,7 @@ var TestnetAssets = {
169
169
  "::test_btc::TEST_BTC": {
170
170
  symbol: "TEST_BTC",
171
171
  name: "Test BTC",
172
- chainId: "103",
172
+ chainId: TestnetChainConfig.id,
173
173
  denom: "::test_btc::TEST_BTC",
174
174
  decimals: 8,
175
175
  logo: "https://raw.githubusercontent.com/cosmos/chain-registry/refs/heads/master/_non-cosmos/bitcoin/images/btc.svg",
@@ -178,7 +178,7 @@ var TestnetAssets = {
178
178
  "::test_usdt::TEST_USDT": {
179
179
  symbol: "TEST_USDT",
180
180
  name: "Test USDT",
181
- chainId: "103",
181
+ chainId: TestnetChainConfig.id,
182
182
  denom: "::test_usdt::TEST_USDT",
183
183
  decimals: 6,
184
184
  logo: "https://raw.githubusercontent.com/cosmos/chain-registry/refs/heads/master/_non-cosmos/ethereum/images/usdt.svg",
@@ -187,7 +187,7 @@ var TestnetAssets = {
187
187
  "::test_deep::TEST_DEEP": {
188
188
  symbol: "TEST_DEEP",
189
189
  name: "TEST_DEEP",
190
- chainId: "103",
190
+ chainId: TestnetChainConfig.id,
191
191
  denom: "::test_deep::TEST_DEEP",
192
192
  decimals: 6,
193
193
  logo: "https://app.lotusfinance.io/images/coins/deepbook-icon.svg",
@@ -196,7 +196,7 @@ var TestnetAssets = {
196
196
  "::test_wal::TEST_WAL": {
197
197
  symbol: "TEST_WAL",
198
198
  name: "TEST_WAL",
199
- chainId: "103",
199
+ chainId: TestnetChainConfig.id,
200
200
  denom: "::test_wal::TEST_WAL",
201
201
  decimals: 9,
202
202
  logo: "https://app.lotusfinance.io/images/coins/wal-icon.svg",
@@ -206,6 +206,7 @@ var TestnetAssets = {
206
206
 
207
207
  // src/lib/constants/defaults.ts
208
208
  var BASIS_POINTS = 1e4;
209
+ var PRICE_PRECISION = 18;
209
210
 
210
211
  // src/lib/constants/sui-objects.ts
211
212
  var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000000";
@@ -685,8 +686,8 @@ var import_transactions2 = require("@mysten/sui/transactions");
685
686
  var import_utils5 = require("@mysten/sui/utils");
686
687
  var import_bignumber = require("bignumber.js");
687
688
  var buildSwapTxArgs = async (client, swapParams, signer) => {
688
- const { assetIn, amountIn, assetOut, minimumAmountOut, receiver } = swapParams;
689
- const pool = client.routerClient.getPool(assetIn, assetOut);
689
+ const { assetIn, amountIn, assetOut, minimumAmountOut, receiver, swapType = "buy" } = swapParams;
690
+ const pool = client.routerClient.getPool(assetIn, assetOut, swapType);
690
691
  if (!pool) {
691
692
  throw new import_core4.NotFoundError(`Pool for the pair ${assetIn}/${assetOut}`);
692
693
  }
@@ -836,7 +837,7 @@ var parsePriceDataStructOutput = (output, baseDenom, quoteDenom, isInverted) =>
836
837
  return {
837
838
  baseDenom,
838
839
  quoteDenom,
839
- price: (0, import_bignumber2.BigNumber)(output.price.price).shiftedBy(-18).toFixed(),
840
+ price: (0, import_bignumber2.BigNumber)(output.price.price).shiftedBy(-PRICE_PRECISION).toFixed(),
840
841
  expiryTime: (0, import_bignumber2.BigNumber)(output.price.expiry).times(1e6).toFixed(),
841
842
  isInverse: isInverted ?? false
842
843
  };
@@ -1116,7 +1117,7 @@ var import_core8 = require("@bolt-liquidity-hq/core");
1116
1117
 
1117
1118
  // src/lib/settlement/parsers.ts
1118
1119
  var import_bignumber4 = require("bignumber.js");
1119
- var parsePoolConfigStructOutput = (routerClient, poolConfig, priceOracleContract) => {
1120
+ var parsePoolConfigStructOutput = (poolConfig, priceOracleContract) => {
1120
1121
  return {
1121
1122
  priceOracleContract,
1122
1123
  protocolFeeRecipient: "0x",
@@ -1125,7 +1126,8 @@ var parsePoolConfigStructOutput = (routerClient, poolConfig, priceOracleContract
1125
1126
  lpFee: (0, import_bignumber4.BigNumber)(poolConfig.lp_fee_pct).div(BASIS_POINTS).toFixed(),
1126
1127
  allowanceMode: "allow",
1127
1128
  // Should come from pool config
1128
- lps: routerClient.getPools().map((item) => item.poolAddress),
1129
+ lps: [],
1130
+ // TODO: update with lp list
1129
1131
  minBaseOut: (0, import_bignumber4.BigNumber)(poolConfig.min_base_out).toFixed()
1130
1132
  };
1131
1133
  };
@@ -1171,7 +1173,7 @@ var getPoolConfig = async (client, contractAddress) => {
1171
1173
  [pool.baseDenom]
1172
1174
  );
1173
1175
  const output = parseDevInspectResult(poolConfig, PoolConfigStruct);
1174
- return parsePoolConfigStructOutput(client.routerClient, output, client.contracts.oracle);
1176
+ return parsePoolConfigStructOutput(output, client.contracts.oracle);
1175
1177
  };
1176
1178
 
1177
1179
  // src/lib/settlement/get-pool-config-by-denom.ts
@@ -1206,8 +1208,8 @@ var getPoolByDenom = async (client, baseDenom, quoteDenom) => {
1206
1208
  return result;
1207
1209
  };
1208
1210
 
1209
- // src/lib/router/get-pools.ts
1210
- var getPools = async (client) => {
1211
+ // src/lib/router/get-all-pools.ts
1212
+ var getAllPools = async (client) => {
1211
1213
  return await client.routerClient.getPools();
1212
1214
  };
1213
1215
 
@@ -1238,9 +1240,20 @@ var RouterClient = class {
1238
1240
  constructor(pools) {
1239
1241
  this.pools = pools;
1240
1242
  }
1241
- getPool(denomIn, denomOut) {
1243
+ getPool(denomIn, denomOut, swapType = "buy") {
1242
1244
  const normalizedDenomIn = (0, import_utils9.normalizeStructTag)(denomIn);
1243
1245
  const normalizedDenomOut = (0, import_utils9.normalizeStructTag)(denomOut);
1246
+ if (swapType === "sell") {
1247
+ const inversePairPool = this.pools.find(
1248
+ (item) => item.baseDenom === normalizedDenomIn && item.quoteDenoms.includes(normalizedDenomOut)
1249
+ );
1250
+ if (inversePairPool) {
1251
+ return {
1252
+ ...inversePairPool,
1253
+ isInverse: true
1254
+ };
1255
+ }
1256
+ }
1244
1257
  const directPairPool = this.pools.find(
1245
1258
  (item) => item.baseDenom === normalizedDenomOut && item.quoteDenoms.includes(normalizedDenomIn)
1246
1259
  );
@@ -1250,14 +1263,16 @@ var RouterClient = class {
1250
1263
  isInverse: false
1251
1264
  };
1252
1265
  }
1253
- const inversePairPool = this.pools.find(
1254
- (item) => item.baseDenom === normalizedDenomIn && item.quoteDenoms.includes(normalizedDenomOut)
1255
- );
1256
- if (inversePairPool) {
1257
- return {
1258
- ...inversePairPool,
1259
- isInverse: true
1260
- };
1266
+ if (swapType === "buy") {
1267
+ const inversePairPool = this.pools.find(
1268
+ (item) => item.baseDenom === normalizedDenomIn && item.quoteDenoms.includes(normalizedDenomOut)
1269
+ );
1270
+ if (inversePairPool) {
1271
+ return {
1272
+ ...inversePairPool,
1273
+ isInverse: true
1274
+ };
1275
+ }
1261
1276
  }
1262
1277
  return;
1263
1278
  }
@@ -1270,8 +1285,8 @@ var RouterClient = class {
1270
1285
  var import_core14 = require("@bolt-liquidity-hq/core");
1271
1286
  var import_bcs10 = require("@mysten/bcs");
1272
1287
  var import_utils10 = require("@mysten/sui/utils");
1273
- var simulateSwap = async (client, { assetIn, amountIn, assetOut }) => {
1274
- const pool = client.routerClient.getPool(assetIn, assetOut);
1288
+ var simulateSwap = async (client, { assetIn, amountIn, assetOut, swapType }) => {
1289
+ const pool = client.routerClient.getPool(assetIn, assetOut, swapType);
1275
1290
  if (!pool) {
1276
1291
  throw new import_core14.NotFoundError("Pool", `Didn't find a pool to swap ${assetIn} for ${assetOut}`);
1277
1292
  }
@@ -1537,7 +1552,7 @@ var BoltSuiClient = class extends import_core15.BaseClient {
1537
1552
  /** @inheritdoc */
1538
1553
  async getAllPools() {
1539
1554
  await this.loadConfigFromUrl();
1540
- return await getPools(this);
1555
+ return await getAllPools(this);
1541
1556
  }
1542
1557
  /** @inheritdoc */
1543
1558
  async getPoolConfig(poolContractAddress) {
@@ -1583,6 +1598,7 @@ var BoltSuiClient = class extends import_core15.BaseClient {
1583
1598
  * assetOut: "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN", // USDC address
1584
1599
  * minimumAmountOut: "1950000", // Minimum 1.95 USDC expected (6 decimals)
1585
1600
  * receiver: "0x..." // Optional custom receiver address
1601
+ * swapType: 'buy' | 'sell' // Optional swap type (default is 'buy')
1586
1602
  * }, signer);
1587
1603
  *
1588
1604
  * console.log(`Swap successful!`);