@gala-chain/gswap-sdk 0.0.8 → 0.0.10

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
@@ -1062,7 +1062,8 @@ var Positions = class {
1062
1062
  amount1Desired: (0, import_bignumber3.default)(ordering.token1Attributes[0]).toFixed(),
1063
1063
  amount0Min: (0, import_bignumber3.default)(ordering.token0Attributes[1]).toFixed(),
1064
1064
  amount1Min: (0, import_bignumber3.default)(ordering.token1Attributes[1]).toFixed(),
1065
- positionId: args.positionId
1065
+ positionId: args.positionId,
1066
+ liquidityProvider: args.walletAddress
1066
1067
  };
1067
1068
  const token0StringKey = stringifyTokenClassKey(ordering.token0, "$");
1068
1069
  const token1StringKey = stringifyTokenClassKey(ordering.token1, "$");
@@ -1239,7 +1240,8 @@ var Positions = class {
1239
1240
  amount: (0, import_bignumber3.default)(args.amount).toFixed(),
1240
1241
  amount0Min: ((_b = ordering == null ? void 0 : ordering.token0Attributes) == null ? void 0 : _b[0]) || "0",
1241
1242
  amount1Min: ((_c = ordering == null ? void 0 : ordering.token1Attributes) == null ? void 0 : _c[0]) || "0",
1242
- positionId: args.positionId
1243
+ positionId: args.positionId,
1244
+ recipient: args.walletAddress
1243
1245
  };
1244
1246
  const token0StringKey = stringifyTokenClassKey(ordering.token0, "$");
1245
1247
  const token1StringKey = stringifyTokenClassKey(ordering.token1, "$");
@@ -1314,7 +1316,8 @@ var Positions = class {
1314
1316
  amount1Requested: (0, import_bignumber3.default)(ordering.token1Attributes[0]).toFixed(),
1315
1317
  tickLower: args.tickLower,
1316
1318
  tickUpper: args.tickUpper,
1317
- positionId: args.positionId
1319
+ positionId: args.positionId,
1320
+ recipient: args.walletAddress
1318
1321
  };
1319
1322
  const token0StringKey = stringifyTokenClassKey(ordering.token0, "$");
1320
1323
  const token1StringKey = stringifyTokenClassKey(ordering.token1, "$");
@@ -1380,6 +1383,8 @@ var Positions = class {
1380
1383
  };
1381
1384
 
1382
1385
  // src/classes/quoting.ts
1386
+ var import_api = require("@gala-chain/api");
1387
+ var import_dex = require("@gala-chain/dex");
1383
1388
  var import_bignumber4 = __toESM(require("bignumber.js"), 1);
1384
1389
 
1385
1390
  // src/types/fees.ts
@@ -1468,14 +1473,59 @@ var Quoting = class {
1468
1473
  }
1469
1474
  async getSingleQuote(tokenIn, tokenOut, fee, amount, isExactInput) {
1470
1475
  const tokenInClass = parseTokenClassKey(tokenIn);
1476
+ const tokenInClassKey = await (0, import_api.createValidDTO)(import_api.TokenClassKey, tokenInClass);
1471
1477
  const tokenOutClass = parseTokenClassKey(tokenOut);
1478
+ const tokenOutClassKey = await (0, import_api.createValidDTO)(import_api.TokenClassKey, tokenOutClass);
1472
1479
  const ordering = getTokenOrdering(tokenInClass, tokenOutClass, false);
1480
+ const token0ClassKey = await (0, import_api.createValidDTO)(
1481
+ import_api.TokenClassKey,
1482
+ ordering.token0
1483
+ );
1484
+ const token1ClassKey = await (0, import_api.createValidDTO)(
1485
+ import_api.TokenClassKey,
1486
+ ordering.token1
1487
+ );
1473
1488
  const formattedAmount = isExactInput ? (0, import_bignumber4.default)(amount).toFixed() : (0, import_bignumber4.default)(amount).multipliedBy(-1).toFixed();
1474
- const response = await this.sendQuoteRequest("/QuoteExactAmount", {
1475
- ...ordering,
1476
- fee,
1477
- amount: formattedAmount
1478
- });
1489
+ let feeType;
1490
+ switch (fee) {
1491
+ case 500 /* PERCENT_00_05 */:
1492
+ feeType = import_dex.DexFeePercentageTypes.FEE_0_05_PERCENT;
1493
+ break;
1494
+ case 3e3 /* PERCENT_00_30 */:
1495
+ feeType = import_dex.DexFeePercentageTypes.FEE_0_3_PERCENT;
1496
+ break;
1497
+ case 1e4 /* PERCENT_01_00 */:
1498
+ feeType = import_dex.DexFeePercentageTypes.FEE_1_PERCENT;
1499
+ break;
1500
+ default:
1501
+ throw new Error(`Invalid fee tier: ${fee}`);
1502
+ }
1503
+ const zeroForOne = compareTokens(tokenIn, tokenOut) < 0;
1504
+ const getCompositePoolDto = new import_dex.GetCompositePoolDto(
1505
+ zeroForOne ? tokenInClassKey : tokenOutClassKey,
1506
+ zeroForOne ? tokenOutClassKey : tokenInClassKey,
1507
+ feeType
1508
+ );
1509
+ const compositePoolResponse = await this.sendGetCompositePoolRequest(getCompositePoolDto);
1510
+ const compositePool = this.createCompositePoolDtoFromResponse(compositePoolResponse);
1511
+ const quoteDto = new import_dex.QuoteExactAmountDto(
1512
+ token0ClassKey,
1513
+ token1ClassKey,
1514
+ feeType,
1515
+ (0, import_bignumber4.default)(formattedAmount),
1516
+ zeroForOne,
1517
+ compositePool
1518
+ );
1519
+ const context = {
1520
+ callingUser: "eth|123...abc",
1521
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1522
+ stub: null,
1523
+ clientIdentity: {
1524
+ getMSPID: () => "UsersOrg"
1525
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1526
+ }
1527
+ };
1528
+ const response = await (0, import_dex.quoteExactAmount)(context, quoteDto);
1479
1529
  const tokenInAmount = ordering.zeroForOne ? response.amount0 : response.amount1;
1480
1530
  const tokenOutAmount = ordering.zeroForOne ? response.amount1 : response.amount0;
1481
1531
  let currentPrice = response.currentSqrtPrice.pow(2);
@@ -1504,20 +1554,76 @@ var Quoting = class {
1504
1554
  async getSingleQuoteExactOutput(tokenIn, tokenOut, amountOut, fee) {
1505
1555
  return this.getSingleQuote(tokenIn, tokenOut, fee, amountOut, false);
1506
1556
  }
1507
- async sendQuoteRequest(endpoint, body) {
1557
+ async sendGetCompositePoolRequest(getCompositePoolDto) {
1508
1558
  const response = await this.httpClient.sendPostRequest(
1509
1559
  this.gatewayBaseUrl,
1510
1560
  this.dexContractBasePath,
1511
- endpoint,
1512
- body
1561
+ "/GetCompositePool",
1562
+ getCompositePoolDto
1513
1563
  );
1514
1564
  const responseBody = response;
1515
- return {
1516
- amount0: (0, import_bignumber4.default)(responseBody.Data.amount0),
1517
- amount1: (0, import_bignumber4.default)(responseBody.Data.amount1),
1518
- currentSqrtPrice: (0, import_bignumber4.default)(responseBody.Data.currentSqrtPrice),
1519
- newSqrtPrice: (0, import_bignumber4.default)(responseBody.Data.newSqrtPrice)
1520
- };
1565
+ return responseBody.Data;
1566
+ }
1567
+ /**
1568
+ * Converts response data from GetCompositePool API into a proper CompositePoolDto
1569
+ * Based on the working implementation in quote-local.mjs
1570
+ */
1571
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1572
+ createCompositePoolDtoFromResponse(responseData) {
1573
+ const pool = new import_dex.Pool(
1574
+ responseData.pool.token0,
1575
+ responseData.pool.token1,
1576
+ responseData.pool.token0ClassKey,
1577
+ responseData.pool.token1ClassKey,
1578
+ responseData.pool.fee,
1579
+ new import_bignumber4.default(responseData.pool.sqrtPrice),
1580
+ responseData.pool.protocolFees
1581
+ );
1582
+ pool.bitmap = responseData.pool.bitmap;
1583
+ pool.grossPoolLiquidity = new import_bignumber4.default(responseData.pool.grossPoolLiquidity);
1584
+ pool.liquidity = new import_bignumber4.default(responseData.pool.liquidity);
1585
+ pool.feeGrowthGlobal0 = new import_bignumber4.default(responseData.pool.feeGrowthGlobal0);
1586
+ pool.feeGrowthGlobal1 = new import_bignumber4.default(responseData.pool.feeGrowthGlobal1);
1587
+ pool.protocolFeesToken0 = new import_bignumber4.default(responseData.pool.protocolFeesToken0);
1588
+ pool.protocolFeesToken1 = new import_bignumber4.default(responseData.pool.protocolFeesToken1);
1589
+ pool.tickSpacing = responseData.pool.tickSpacing;
1590
+ pool.maxLiquidityPerTick = new import_bignumber4.default(responseData.pool.maxLiquidityPerTick);
1591
+ const tickDataMap = {};
1592
+ Object.keys(responseData.tickDataMap).forEach((tickKey) => {
1593
+ const tickData = responseData.tickDataMap[tickKey];
1594
+ tickDataMap[tickKey] = new import_dex.TickData(tickData.poolHash, tickData.tick);
1595
+ tickDataMap[tickKey].initialised = tickData.initialised;
1596
+ tickDataMap[tickKey].liquidityNet = new import_bignumber4.default(tickData.liquidityNet);
1597
+ tickDataMap[tickKey].liquidityGross = new import_bignumber4.default(tickData.liquidityGross);
1598
+ tickDataMap[tickKey].feeGrowthOutside0 = new import_bignumber4.default(tickData.feeGrowthOutside0);
1599
+ tickDataMap[tickKey].feeGrowthOutside1 = new import_bignumber4.default(tickData.feeGrowthOutside1);
1600
+ });
1601
+ const token0Balance = new import_api.TokenBalance({
1602
+ owner: responseData.token0Balance.owner,
1603
+ collection: responseData.token0Balance.collection,
1604
+ category: responseData.token0Balance.category,
1605
+ type: responseData.token0Balance.type,
1606
+ additionalKey: responseData.token0Balance.additionalKey
1607
+ });
1608
+ token0Balance.quantity = new import_bignumber4.default(responseData.token0Balance.quantity);
1609
+ const token1Balance = new import_api.TokenBalance({
1610
+ owner: responseData.token1Balance.owner,
1611
+ collection: responseData.token1Balance.collection,
1612
+ category: responseData.token1Balance.category,
1613
+ type: responseData.token1Balance.type,
1614
+ additionalKey: responseData.token1Balance.additionalKey
1615
+ });
1616
+ token1Balance.quantity = new import_bignumber4.default(responseData.token1Balance.quantity);
1617
+ return new import_dex.CompositePoolDto(
1618
+ pool,
1619
+ tickDataMap,
1620
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1621
+ token0Balance,
1622
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1623
+ token1Balance,
1624
+ responseData.token0Decimals,
1625
+ responseData.token1Decimals
1626
+ );
1521
1627
  }
1522
1628
  };
1523
1629
 
@@ -1749,15 +1855,15 @@ var GSwap = class {
1749
1855
  };
1750
1856
 
1751
1857
  // src/classes/signers.ts
1752
- var import_api = require("@gala-chain/api");
1858
+ var import_api2 = require("@gala-chain/api");
1753
1859
  var import_connect = require("@gala-chain/connect");
1754
1860
  var PrivateKeySigner = class {
1755
1861
  keyBuffer;
1756
1862
  constructor(privateKey) {
1757
- this.keyBuffer = import_api.signatures.normalizePrivateKey(privateKey);
1863
+ this.keyBuffer = import_api2.signatures.normalizePrivateKey(privateKey);
1758
1864
  }
1759
1865
  async signObject(_methodName, obj) {
1760
- const signature = import_api.signatures.getSignature(obj, this.keyBuffer);
1866
+ const signature = import_api2.signatures.getSignature(obj, this.keyBuffer);
1761
1867
  return { ...obj, signature };
1762
1868
  }
1763
1869
  };