@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/browser/index.js +6 -6
- package/dist/browser/index.js.map +1 -1
- package/dist/index.cjs +126 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.mjs +131 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
package/dist/index.d.cts
CHANGED
|
@@ -788,7 +788,12 @@ declare class Quoting {
|
|
|
788
788
|
private getSingleQuote;
|
|
789
789
|
private getSingleQuoteExactInput;
|
|
790
790
|
private getSingleQuoteExactOutput;
|
|
791
|
-
private
|
|
791
|
+
private sendGetCompositePoolRequest;
|
|
792
|
+
/**
|
|
793
|
+
* Converts response data from GetCompositePool API into a proper CompositePoolDto
|
|
794
|
+
* Based on the working implementation in quote-local.mjs
|
|
795
|
+
*/
|
|
796
|
+
private createCompositePoolDtoFromResponse;
|
|
792
797
|
}
|
|
793
798
|
|
|
794
799
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -788,7 +788,12 @@ declare class Quoting {
|
|
|
788
788
|
private getSingleQuote;
|
|
789
789
|
private getSingleQuoteExactInput;
|
|
790
790
|
private getSingleQuoteExactOutput;
|
|
791
|
-
private
|
|
791
|
+
private sendGetCompositePoolRequest;
|
|
792
|
+
/**
|
|
793
|
+
* Converts response data from GetCompositePool API into a proper CompositePoolDto
|
|
794
|
+
* Based on the working implementation in quote-local.mjs
|
|
795
|
+
*/
|
|
796
|
+
private createCompositePoolDtoFromResponse;
|
|
792
797
|
}
|
|
793
798
|
|
|
794
799
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1001,7 +1001,8 @@ var Positions = class {
|
|
|
1001
1001
|
amount1Desired: BigNumber3(ordering.token1Attributes[0]).toFixed(),
|
|
1002
1002
|
amount0Min: BigNumber3(ordering.token0Attributes[1]).toFixed(),
|
|
1003
1003
|
amount1Min: BigNumber3(ordering.token1Attributes[1]).toFixed(),
|
|
1004
|
-
positionId: args.positionId
|
|
1004
|
+
positionId: args.positionId,
|
|
1005
|
+
liquidityProvider: args.walletAddress
|
|
1005
1006
|
};
|
|
1006
1007
|
const token0StringKey = stringifyTokenClassKey(ordering.token0, "$");
|
|
1007
1008
|
const token1StringKey = stringifyTokenClassKey(ordering.token1, "$");
|
|
@@ -1178,7 +1179,8 @@ var Positions = class {
|
|
|
1178
1179
|
amount: BigNumber3(args.amount).toFixed(),
|
|
1179
1180
|
amount0Min: ((_b = ordering == null ? void 0 : ordering.token0Attributes) == null ? void 0 : _b[0]) || "0",
|
|
1180
1181
|
amount1Min: ((_c = ordering == null ? void 0 : ordering.token1Attributes) == null ? void 0 : _c[0]) || "0",
|
|
1181
|
-
positionId: args.positionId
|
|
1182
|
+
positionId: args.positionId,
|
|
1183
|
+
recipient: args.walletAddress
|
|
1182
1184
|
};
|
|
1183
1185
|
const token0StringKey = stringifyTokenClassKey(ordering.token0, "$");
|
|
1184
1186
|
const token1StringKey = stringifyTokenClassKey(ordering.token1, "$");
|
|
@@ -1253,7 +1255,8 @@ var Positions = class {
|
|
|
1253
1255
|
amount1Requested: BigNumber3(ordering.token1Attributes[0]).toFixed(),
|
|
1254
1256
|
tickLower: args.tickLower,
|
|
1255
1257
|
tickUpper: args.tickUpper,
|
|
1256
|
-
positionId: args.positionId
|
|
1258
|
+
positionId: args.positionId,
|
|
1259
|
+
recipient: args.walletAddress
|
|
1257
1260
|
};
|
|
1258
1261
|
const token0StringKey = stringifyTokenClassKey(ordering.token0, "$");
|
|
1259
1262
|
const token1StringKey = stringifyTokenClassKey(ordering.token1, "$");
|
|
@@ -1319,6 +1322,16 @@ var Positions = class {
|
|
|
1319
1322
|
};
|
|
1320
1323
|
|
|
1321
1324
|
// src/classes/quoting.ts
|
|
1325
|
+
import { createValidDTO, TokenBalance, TokenClassKey } from "@gala-chain/api";
|
|
1326
|
+
import {
|
|
1327
|
+
CompositePoolDto,
|
|
1328
|
+
DexFeePercentageTypes,
|
|
1329
|
+
GetCompositePoolDto,
|
|
1330
|
+
Pool,
|
|
1331
|
+
quoteExactAmount,
|
|
1332
|
+
QuoteExactAmountDto,
|
|
1333
|
+
TickData
|
|
1334
|
+
} from "@gala-chain/dex";
|
|
1322
1335
|
import BigNumber4 from "bignumber.js";
|
|
1323
1336
|
|
|
1324
1337
|
// src/types/fees.ts
|
|
@@ -1407,14 +1420,59 @@ var Quoting = class {
|
|
|
1407
1420
|
}
|
|
1408
1421
|
async getSingleQuote(tokenIn, tokenOut, fee, amount, isExactInput) {
|
|
1409
1422
|
const tokenInClass = parseTokenClassKey(tokenIn);
|
|
1423
|
+
const tokenInClassKey = await createValidDTO(TokenClassKey, tokenInClass);
|
|
1410
1424
|
const tokenOutClass = parseTokenClassKey(tokenOut);
|
|
1425
|
+
const tokenOutClassKey = await createValidDTO(TokenClassKey, tokenOutClass);
|
|
1411
1426
|
const ordering = getTokenOrdering(tokenInClass, tokenOutClass, false);
|
|
1427
|
+
const token0ClassKey = await createValidDTO(
|
|
1428
|
+
TokenClassKey,
|
|
1429
|
+
ordering.token0
|
|
1430
|
+
);
|
|
1431
|
+
const token1ClassKey = await createValidDTO(
|
|
1432
|
+
TokenClassKey,
|
|
1433
|
+
ordering.token1
|
|
1434
|
+
);
|
|
1412
1435
|
const formattedAmount = isExactInput ? BigNumber4(amount).toFixed() : BigNumber4(amount).multipliedBy(-1).toFixed();
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1436
|
+
let feeType;
|
|
1437
|
+
switch (fee) {
|
|
1438
|
+
case 500 /* PERCENT_00_05 */:
|
|
1439
|
+
feeType = DexFeePercentageTypes.FEE_0_05_PERCENT;
|
|
1440
|
+
break;
|
|
1441
|
+
case 3e3 /* PERCENT_00_30 */:
|
|
1442
|
+
feeType = DexFeePercentageTypes.FEE_0_3_PERCENT;
|
|
1443
|
+
break;
|
|
1444
|
+
case 1e4 /* PERCENT_01_00 */:
|
|
1445
|
+
feeType = DexFeePercentageTypes.FEE_1_PERCENT;
|
|
1446
|
+
break;
|
|
1447
|
+
default:
|
|
1448
|
+
throw new Error(`Invalid fee tier: ${fee}`);
|
|
1449
|
+
}
|
|
1450
|
+
const zeroForOne = compareTokens(tokenIn, tokenOut) < 0;
|
|
1451
|
+
const getCompositePoolDto = new GetCompositePoolDto(
|
|
1452
|
+
zeroForOne ? tokenInClassKey : tokenOutClassKey,
|
|
1453
|
+
zeroForOne ? tokenOutClassKey : tokenInClassKey,
|
|
1454
|
+
feeType
|
|
1455
|
+
);
|
|
1456
|
+
const compositePoolResponse = await this.sendGetCompositePoolRequest(getCompositePoolDto);
|
|
1457
|
+
const compositePool = this.createCompositePoolDtoFromResponse(compositePoolResponse);
|
|
1458
|
+
const quoteDto = new QuoteExactAmountDto(
|
|
1459
|
+
token0ClassKey,
|
|
1460
|
+
token1ClassKey,
|
|
1461
|
+
feeType,
|
|
1462
|
+
BigNumber4(formattedAmount),
|
|
1463
|
+
zeroForOne,
|
|
1464
|
+
compositePool
|
|
1465
|
+
);
|
|
1466
|
+
const context = {
|
|
1467
|
+
callingUser: "eth|123...abc",
|
|
1468
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1469
|
+
stub: null,
|
|
1470
|
+
clientIdentity: {
|
|
1471
|
+
getMSPID: () => "UsersOrg"
|
|
1472
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1473
|
+
}
|
|
1474
|
+
};
|
|
1475
|
+
const response = await quoteExactAmount(context, quoteDto);
|
|
1418
1476
|
const tokenInAmount = ordering.zeroForOne ? response.amount0 : response.amount1;
|
|
1419
1477
|
const tokenOutAmount = ordering.zeroForOne ? response.amount1 : response.amount0;
|
|
1420
1478
|
let currentPrice = response.currentSqrtPrice.pow(2);
|
|
@@ -1443,20 +1501,76 @@ var Quoting = class {
|
|
|
1443
1501
|
async getSingleQuoteExactOutput(tokenIn, tokenOut, amountOut, fee) {
|
|
1444
1502
|
return this.getSingleQuote(tokenIn, tokenOut, fee, amountOut, false);
|
|
1445
1503
|
}
|
|
1446
|
-
async
|
|
1504
|
+
async sendGetCompositePoolRequest(getCompositePoolDto) {
|
|
1447
1505
|
const response = await this.httpClient.sendPostRequest(
|
|
1448
1506
|
this.gatewayBaseUrl,
|
|
1449
1507
|
this.dexContractBasePath,
|
|
1450
|
-
|
|
1451
|
-
|
|
1508
|
+
"/GetCompositePool",
|
|
1509
|
+
getCompositePoolDto
|
|
1452
1510
|
);
|
|
1453
1511
|
const responseBody = response;
|
|
1454
|
-
return
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1512
|
+
return responseBody.Data;
|
|
1513
|
+
}
|
|
1514
|
+
/**
|
|
1515
|
+
* Converts response data from GetCompositePool API into a proper CompositePoolDto
|
|
1516
|
+
* Based on the working implementation in quote-local.mjs
|
|
1517
|
+
*/
|
|
1518
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1519
|
+
createCompositePoolDtoFromResponse(responseData) {
|
|
1520
|
+
const pool = new Pool(
|
|
1521
|
+
responseData.pool.token0,
|
|
1522
|
+
responseData.pool.token1,
|
|
1523
|
+
responseData.pool.token0ClassKey,
|
|
1524
|
+
responseData.pool.token1ClassKey,
|
|
1525
|
+
responseData.pool.fee,
|
|
1526
|
+
new BigNumber4(responseData.pool.sqrtPrice),
|
|
1527
|
+
responseData.pool.protocolFees
|
|
1528
|
+
);
|
|
1529
|
+
pool.bitmap = responseData.pool.bitmap;
|
|
1530
|
+
pool.grossPoolLiquidity = new BigNumber4(responseData.pool.grossPoolLiquidity);
|
|
1531
|
+
pool.liquidity = new BigNumber4(responseData.pool.liquidity);
|
|
1532
|
+
pool.feeGrowthGlobal0 = new BigNumber4(responseData.pool.feeGrowthGlobal0);
|
|
1533
|
+
pool.feeGrowthGlobal1 = new BigNumber4(responseData.pool.feeGrowthGlobal1);
|
|
1534
|
+
pool.protocolFeesToken0 = new BigNumber4(responseData.pool.protocolFeesToken0);
|
|
1535
|
+
pool.protocolFeesToken1 = new BigNumber4(responseData.pool.protocolFeesToken1);
|
|
1536
|
+
pool.tickSpacing = responseData.pool.tickSpacing;
|
|
1537
|
+
pool.maxLiquidityPerTick = new BigNumber4(responseData.pool.maxLiquidityPerTick);
|
|
1538
|
+
const tickDataMap = {};
|
|
1539
|
+
Object.keys(responseData.tickDataMap).forEach((tickKey) => {
|
|
1540
|
+
const tickData = responseData.tickDataMap[tickKey];
|
|
1541
|
+
tickDataMap[tickKey] = new TickData(tickData.poolHash, tickData.tick);
|
|
1542
|
+
tickDataMap[tickKey].initialised = tickData.initialised;
|
|
1543
|
+
tickDataMap[tickKey].liquidityNet = new BigNumber4(tickData.liquidityNet);
|
|
1544
|
+
tickDataMap[tickKey].liquidityGross = new BigNumber4(tickData.liquidityGross);
|
|
1545
|
+
tickDataMap[tickKey].feeGrowthOutside0 = new BigNumber4(tickData.feeGrowthOutside0);
|
|
1546
|
+
tickDataMap[tickKey].feeGrowthOutside1 = new BigNumber4(tickData.feeGrowthOutside1);
|
|
1547
|
+
});
|
|
1548
|
+
const token0Balance = new TokenBalance({
|
|
1549
|
+
owner: responseData.token0Balance.owner,
|
|
1550
|
+
collection: responseData.token0Balance.collection,
|
|
1551
|
+
category: responseData.token0Balance.category,
|
|
1552
|
+
type: responseData.token0Balance.type,
|
|
1553
|
+
additionalKey: responseData.token0Balance.additionalKey
|
|
1554
|
+
});
|
|
1555
|
+
token0Balance.quantity = new BigNumber4(responseData.token0Balance.quantity);
|
|
1556
|
+
const token1Balance = new TokenBalance({
|
|
1557
|
+
owner: responseData.token1Balance.owner,
|
|
1558
|
+
collection: responseData.token1Balance.collection,
|
|
1559
|
+
category: responseData.token1Balance.category,
|
|
1560
|
+
type: responseData.token1Balance.type,
|
|
1561
|
+
additionalKey: responseData.token1Balance.additionalKey
|
|
1562
|
+
});
|
|
1563
|
+
token1Balance.quantity = new BigNumber4(responseData.token1Balance.quantity);
|
|
1564
|
+
return new CompositePoolDto(
|
|
1565
|
+
pool,
|
|
1566
|
+
tickDataMap,
|
|
1567
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1568
|
+
token0Balance,
|
|
1569
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1570
|
+
token1Balance,
|
|
1571
|
+
responseData.token0Decimals,
|
|
1572
|
+
responseData.token1Decimals
|
|
1573
|
+
);
|
|
1460
1574
|
}
|
|
1461
1575
|
};
|
|
1462
1576
|
|