@bolt-liquidity-hq/sui-client 0.2.0 → 0.3.1

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/README.md CHANGED
@@ -23,20 +23,24 @@ import { BoltSuiClient } from '@bolt-liquidity-hq/sui-client';
23
23
  // Initialize client
24
24
  const client = new BoltSuiClient();
25
25
 
26
- // Get current price
26
+ // Get current price, in raw units: multiply by 10^(9 - 6) for USDC per SUI
27
27
  const price = await client.getPrice(
28
28
  '0x2::sui::SUI', // SUI
29
- '0x168da5bf1f48dafc111b0a488fa454aca95e0b5e::usdc::USDC' // USDC
29
+ '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC' // USDC
30
30
  );
31
- console.log(`ARCH/USDC: ${price.price}`);
31
+ console.log(`SUI/USDC (raw units): ${price.price}`);
32
32
 
33
- // Execute a swap
34
- const result = await client.swap({
35
- '0x2::sui::SUI', // SUI
33
+ // Execute a swap, accepting up to 0.5% less than the simulation expects
34
+ const swap = {
35
+ assetIn: '0x2::sui::SUI', // SUI
36
36
  amountIn: '1000000000', // 1 SUI
37
- '0x168da5bf1f48dafc111b0a488fa454aca95e0b5e::usdc::USDC' // USDC
38
- minimumAmountOut: '3500000', // 3.5 USDC minimum
39
- }, signer);
37
+ assetOut: '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC', // USDC
38
+ };
39
+ const { amountOut } = await client.simulateSwap(swap);
40
+ const result = await client.swap(
41
+ { ...swap, minimumAmountOut: ((BigInt(amountOut) * 995n) / 1000n).toString() },
42
+ signer
43
+ );
40
44
  ```
41
45
 
42
46
  ## 📖 API Reference
package/dist/index.cjs CHANGED
@@ -735,6 +735,8 @@ var TX_INCLUDE = {
735
735
  var unwrapTransaction = (result) => result.$kind === "Transaction" ? result.Transaction : result.FailedTransaction;
736
736
  var buildSwapTxArgs = async (client, swapParams, signer) => {
737
737
  const { assetIn, amountIn, assetOut, minimumAmountOut, receiver, swapType = "buy" } = swapParams;
738
+ const amount = (0, import_core4.toAmount)(amountIn, "amountIn");
739
+ const minimumAmount = minimumAmountOut ? (0, import_core4.toAmount)(minimumAmountOut, "minimumAmountOut") : void 0;
738
740
  const pool = client.routerClient.getPool(assetIn, assetOut, swapType);
739
741
  if (!pool) {
740
742
  throw new import_core4.NotFoundError(`Pool for the pair ${assetIn}/${assetOut}`);
@@ -754,8 +756,8 @@ var buildSwapTxArgs = async (client, swapParams, signer) => {
754
756
  client.contracts.oracle,
755
757
  import_utils5.SUI_CLOCK_OBJECT_ID,
756
758
  coinInput,
757
- import_bcs2.bcs.u64().serialize(amountIn),
758
- import_bcs2.bcs.option(import_bcs2.bcs.u64()).serialize(minimumAmountOut),
759
+ import_bcs2.bcs.u64().serialize(amount),
760
+ import_bcs2.bcs.option(import_bcs2.bcs.u64()).serialize(minimumAmount),
759
761
  import_bcs2.bcs.option(import_bcs2.bcs.string()).serialize(receiver)
760
762
  ],
761
763
  typeArguments: [pool.isInverse ? assetIn : assetOut, pool.isInverse ? assetOut : assetIn],
@@ -1342,6 +1344,7 @@ var import_core14 = require("@bolt-liquidity-hq/core");
1342
1344
  var import_bcs10 = require("@mysten/bcs");
1343
1345
  var import_utils10 = require("@mysten/sui/utils");
1344
1346
  var simulateSwap = async (client, { assetIn, amountIn, assetOut, swapType }) => {
1347
+ const amount = (0, import_core14.toAmount)(amountIn, "amountIn");
1345
1348
  const pool = client.routerClient.getPool(assetIn, assetOut, swapType);
1346
1349
  if (!pool) {
1347
1350
  throw new import_core14.NotFoundError("Pool", `Didn't find a pool to swap ${assetIn} for ${assetOut}`);
@@ -1350,7 +1353,7 @@ var simulateSwap = async (client, { assetIn, amountIn, assetOut, swapType }) =>
1350
1353
  const response = await queryDevInspect(
1351
1354
  client.suiClient,
1352
1355
  [client.packageId, POOL_MODULE, FUNCTION_NAME],
1353
- [pool.poolAddress, client.contracts.oracle, import_utils10.SUI_CLOCK_OBJECT_ID, import_bcs10.bcs.u64().serialize(amountIn)],
1356
+ [pool.poolAddress, client.contracts.oracle, import_utils10.SUI_CLOCK_OBJECT_ID, import_bcs10.bcs.u64().serialize(amount)],
1354
1357
  [pool.isInverse ? assetIn : assetOut, pool.isInverse ? assetOut : assetIn]
1355
1358
  );
1356
1359
  const output = parseDevInspectResult(response, SwapSimulationResultStruct);
@@ -1501,10 +1504,6 @@ var BoltSuiClient = class extends import_core15.BaseClient {
1501
1504
  * Object Id for the GlobalConfig of the deployed Pool contracts
1502
1505
  */
1503
1506
  __publicField(this, "poolGlobalConfigId");
1504
- /**
1505
- * Cached instance of the Signer for transaction execution
1506
- */
1507
- __publicField(this, "signer");
1508
1507
  /**
1509
1508
  * Instance of the Sui client to interact with the blockchain.
1510
1509
  */
@@ -1531,36 +1530,6 @@ var BoltSuiClient = class extends import_core15.BaseClient {
1531
1530
  this.routerClient = new RouterClient(pools);
1532
1531
  this.configFileUrl = isEnvironmentMainnet ? void 0 : TestnetConfigUrl;
1533
1532
  }
1534
- /**
1535
- * Gets or sets the signer for transaction execution.
1536
- *
1537
- * This method manages the signer instance used for signing transactions.
1538
- * A signer must be provided either when creating the client, on first call,
1539
- * or to replace the existing signer.
1540
- *
1541
- * @param newSigner - Optional new signer to replace the existing one
1542
- *
1543
- * @returns The current signer instance
1544
- *
1545
- * @throws {MissingParameterError} Thrown when no signer is available and none is provided
1546
- *
1547
- * @example
1548
- * ```typescript
1549
- * // Get the current signer (throws if none exists)
1550
- * const currentSigner = client.getSigner();
1551
- *
1552
- * // Set a new signer
1553
- * const newSigner = // ... obtain signer from wallet
1554
- * const signer = client.getSigner(newSigner);
1555
- * ```
1556
- */
1557
- getSigner(newSigner) {
1558
- this.signer = newSigner ?? this.signer;
1559
- if (!this.signer) {
1560
- throw new import_core15.MissingParameterError("signer");
1561
- }
1562
- return this.signer;
1563
- }
1564
1533
  // The following methods inherit their documentation from BaseClient
1565
1534
  // Only add documentation here if you need to override or add implementation-specific details
1566
1535
  /** @inheritdoc */