@bolt-liquidity-hq/sui-client 0.1.0-beta.14 → 0.1.0-beta.15
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 +72 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -3
- package/dist/index.d.ts +17 -3
- package/dist/index.js +84 -26
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -53,14 +53,15 @@ __export(index_exports, {
|
|
|
53
53
|
RawPairStruct: () => RawPairStruct,
|
|
54
54
|
RawPriceStruct: () => RawPriceStruct,
|
|
55
55
|
RouterConfigStruct: () => RouterConfigStruct,
|
|
56
|
+
SwapSimulationResultStruct: () => SwapSimulationResultStruct,
|
|
56
57
|
TypeNameStruct: () => TypeNameStruct
|
|
57
58
|
});
|
|
58
59
|
module.exports = __toCommonJS(index_exports);
|
|
59
60
|
|
|
60
61
|
// src/lib/client.ts
|
|
61
|
-
var
|
|
62
|
+
var import_core15 = require("@bolt-liquidity-hq/core");
|
|
62
63
|
var import_client = require("@mysten/sui/client");
|
|
63
|
-
var
|
|
64
|
+
var import_utils10 = require("@mysten/sui/utils");
|
|
64
65
|
var import_axios = __toESM(require("axios"), 1);
|
|
65
66
|
|
|
66
67
|
// src/config/common.ts
|
|
@@ -158,6 +159,9 @@ var TestnetAssets = {
|
|
|
158
159
|
}
|
|
159
160
|
};
|
|
160
161
|
|
|
162
|
+
// src/lib/constants/defaults.ts
|
|
163
|
+
var BASIS_POINTS = 1e4;
|
|
164
|
+
|
|
161
165
|
// src/lib/constants/sui-objects.ts
|
|
162
166
|
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
163
167
|
var PRICE_ORACLE_MODULE = "price_oracle";
|
|
@@ -641,8 +645,7 @@ var buildSwapTxArgs = async (client, swapParams, signer) => {
|
|
|
641
645
|
if (!pool) {
|
|
642
646
|
throw new import_core4.NotFoundError(`Pool for the pair ${assetIn}/${assetOut}`);
|
|
643
647
|
}
|
|
644
|
-
const
|
|
645
|
-
const FUNCTION_NAME = isSell ? "swap_sell" : "swap_buy";
|
|
648
|
+
const FUNCTION_NAME = pool.isInverse ? "swap_sell" : "swap_buy";
|
|
646
649
|
const finalSigner = client.getSigner(signer);
|
|
647
650
|
const tx = new import_transactions2.Transaction();
|
|
648
651
|
const signerAddress = getSignerAddress(finalSigner);
|
|
@@ -661,7 +664,7 @@ var buildSwapTxArgs = async (client, swapParams, signer) => {
|
|
|
661
664
|
import_bcs2.bcs.option(import_bcs2.bcs.u64()).serialize(minimumAmountOut),
|
|
662
665
|
import_bcs2.bcs.option(import_bcs2.bcs.string()).serialize(receiver)
|
|
663
666
|
],
|
|
664
|
-
typeArguments: [
|
|
667
|
+
typeArguments: [pool.isInverse ? assetIn : assetOut, pool.isInverse ? assetOut : assetIn],
|
|
665
668
|
tx
|
|
666
669
|
};
|
|
667
670
|
};
|
|
@@ -904,6 +907,14 @@ var BaseLiquidityResponseStruct = import_bcs6.bcs.struct("BaseLiquidityResponse"
|
|
|
904
907
|
base_assets: import_bcs6.bcs.vector(BaseLiquidityInfoStruct),
|
|
905
908
|
...PaginationStruct
|
|
906
909
|
});
|
|
910
|
+
var SwapSimulationResultStruct = import_bcs6.bcs.struct("SwapSimulationResult", {
|
|
911
|
+
amount_out: import_bcs6.bcs.u128(),
|
|
912
|
+
dynamic_fee_pct: import_bcs6.bcs.u64(),
|
|
913
|
+
ideal_quote_amt: import_bcs6.bcs.u128(),
|
|
914
|
+
swap_fee: import_bcs6.bcs.u64(),
|
|
915
|
+
lp_fee: import_bcs6.bcs.u64(),
|
|
916
|
+
protocol_fee: import_bcs6.bcs.u64()
|
|
917
|
+
});
|
|
907
918
|
|
|
908
919
|
// src/types/pool.ts
|
|
909
920
|
var import_bcs8 = require("@mysten/bcs");
|
|
@@ -1089,6 +1100,21 @@ var getRouterConfig = async (_client) => {
|
|
|
1089
1100
|
throw new import_core11.NotImplementedError("getRouterConfig on Sui Client");
|
|
1090
1101
|
};
|
|
1091
1102
|
|
|
1103
|
+
// src/lib/router/parsers.ts
|
|
1104
|
+
var import_core12 = require("@bolt-liquidity-hq/core");
|
|
1105
|
+
var import_bignumber3 = require("bignumber.js");
|
|
1106
|
+
var parseSwapSimulationResultStructOutput = (output, poolAddress, assetOut) => {
|
|
1107
|
+
return {
|
|
1108
|
+
poolAddress,
|
|
1109
|
+
amountOut: output.amount_out,
|
|
1110
|
+
assetOut,
|
|
1111
|
+
protocolFee: output.protocol_fee,
|
|
1112
|
+
lpFee: output.lp_fee,
|
|
1113
|
+
dynamicFeePercentage: (0, import_bignumber3.BigNumber)(output.dynamic_fee_pct).div(BASIS_POINTS).toFixed(),
|
|
1114
|
+
totalFees: output.swap_fee
|
|
1115
|
+
};
|
|
1116
|
+
};
|
|
1117
|
+
|
|
1092
1118
|
// src/lib/router/router-client/RouterClient.ts
|
|
1093
1119
|
var import_utils8 = require("@mysten/sui/utils");
|
|
1094
1120
|
var RouterClient = class {
|
|
@@ -1102,13 +1128,19 @@ var RouterClient = class {
|
|
|
1102
1128
|
(item) => item.baseDenom === normalizedDenomOut && item.quoteDenoms.includes(normalizedDenomIn)
|
|
1103
1129
|
);
|
|
1104
1130
|
if (directPairPool) {
|
|
1105
|
-
return
|
|
1131
|
+
return {
|
|
1132
|
+
...directPairPool,
|
|
1133
|
+
isInverse: false
|
|
1134
|
+
};
|
|
1106
1135
|
}
|
|
1107
1136
|
const inversePairPool = this.pools.find(
|
|
1108
1137
|
(item) => item.baseDenom === normalizedDenomIn && item.quoteDenoms.includes(normalizedDenomOut)
|
|
1109
1138
|
);
|
|
1110
1139
|
if (inversePairPool) {
|
|
1111
|
-
return
|
|
1140
|
+
return {
|
|
1141
|
+
...inversePairPool,
|
|
1142
|
+
isInverse: true
|
|
1143
|
+
};
|
|
1112
1144
|
}
|
|
1113
1145
|
return;
|
|
1114
1146
|
}
|
|
@@ -1117,6 +1149,26 @@ var RouterClient = class {
|
|
|
1117
1149
|
}
|
|
1118
1150
|
};
|
|
1119
1151
|
|
|
1152
|
+
// src/lib/router/simulate-swap.ts
|
|
1153
|
+
var import_core13 = require("@bolt-liquidity-hq/core");
|
|
1154
|
+
var import_bcs10 = require("@mysten/bcs");
|
|
1155
|
+
var import_utils9 = require("@mysten/sui/utils");
|
|
1156
|
+
var simulateSwap = async (client, { assetIn, amountIn, assetOut }) => {
|
|
1157
|
+
const pool = await client.routerClient.getPool(assetIn, assetOut);
|
|
1158
|
+
if (!pool) {
|
|
1159
|
+
throw new import_core13.NotFoundError("Pool", `Didn't find a pool to swap ${assetIn} for ${assetOut}`);
|
|
1160
|
+
}
|
|
1161
|
+
const FUNCTION_NAME = pool.isInverse ? "simulate_sell_swap" : "simulate_buy_swap";
|
|
1162
|
+
const response = await queryDevInspect(
|
|
1163
|
+
client.suiClient,
|
|
1164
|
+
[client.packageId, POOL_MODULE, FUNCTION_NAME],
|
|
1165
|
+
[pool.poolAddress, client.contracts.oracle, import_utils9.SUI_CLOCK_OBJECT_ID, import_bcs10.bcs.u64().serialize(amountIn)],
|
|
1166
|
+
[pool.isInverse ? assetIn : assetOut, pool.isInverse ? assetOut : assetIn]
|
|
1167
|
+
);
|
|
1168
|
+
const output = parseDevInspectResult(response, SwapSimulationResultStruct);
|
|
1169
|
+
return parseSwapSimulationResultStructOutput(output, pool.poolAddress, assetOut);
|
|
1170
|
+
};
|
|
1171
|
+
|
|
1120
1172
|
// src/lib/router/swap-exact-in.ts
|
|
1121
1173
|
var swapExactIn = async (client, swapParams, signer) => {
|
|
1122
1174
|
const swapArgs = await buildSwapTxArgs(client, swapParams, signer);
|
|
@@ -1138,16 +1190,16 @@ var swapExactIn = async (client, swapParams, signer) => {
|
|
|
1138
1190
|
};
|
|
1139
1191
|
|
|
1140
1192
|
// src/lib/settlement/get-pool-info.ts
|
|
1141
|
-
var
|
|
1193
|
+
var import_core14 = require("@bolt-liquidity-hq/core");
|
|
1142
1194
|
|
|
1143
1195
|
// src/lib/settlement/parsers.ts
|
|
1144
|
-
var
|
|
1196
|
+
var import_bignumber4 = require("bignumber.js");
|
|
1145
1197
|
var parseSettlementConfigStructOutput = (routerClient, poolFeesInfo, protocolFeesInfo, priceOracleContract) => {
|
|
1146
1198
|
return {
|
|
1147
1199
|
priceOracleContract,
|
|
1148
1200
|
protocolFeeRecipient: protocolFeesInfo.bolt_fee_addr,
|
|
1149
|
-
protocolFee: (0,
|
|
1150
|
-
lpFee: (0,
|
|
1201
|
+
protocolFee: (0, import_bignumber4.BigNumber)(poolFeesInfo.swap_fee_pct).div(BASIS_POINTS).toFixed(),
|
|
1202
|
+
lpFee: (0, import_bignumber4.BigNumber)(poolFeesInfo.lp_fee_pct).div(BASIS_POINTS).toFixed(),
|
|
1151
1203
|
allowanceMode: "allow",
|
|
1152
1204
|
// Should come from pool config
|
|
1153
1205
|
lps: routerClient.getPools().map((item) => item.poolAddress),
|
|
@@ -1162,7 +1214,7 @@ var getPoolInfo = async (client, contractAddress) => {
|
|
|
1162
1214
|
const GET_PROTOCOL_FEES_INFO_FUNCTION = "get_protocol_fees_info";
|
|
1163
1215
|
const pool = client.routerClient.pools.find((item) => item.poolAddress === contractAddress);
|
|
1164
1216
|
if (!pool) {
|
|
1165
|
-
throw new
|
|
1217
|
+
throw new import_core14.NotFoundError(`Pool with the address ${contractAddress}`);
|
|
1166
1218
|
}
|
|
1167
1219
|
const [poolFeesInfo, protocolFeesInfo] = await Promise.all([
|
|
1168
1220
|
// Query pool fee information
|
|
@@ -1197,7 +1249,7 @@ var getPoolInfoByDenom = async (client, baseDenom, quoteDenom) => {
|
|
|
1197
1249
|
};
|
|
1198
1250
|
|
|
1199
1251
|
// src/lib/client.ts
|
|
1200
|
-
var BoltSuiClient = class extends
|
|
1252
|
+
var BoltSuiClient = class extends import_core15.BaseClient {
|
|
1201
1253
|
/**
|
|
1202
1254
|
* Creates a new instance of the BoltSuiClient.
|
|
1203
1255
|
*
|
|
@@ -1369,7 +1421,7 @@ var BoltSuiClient = class extends import_core13.BaseClient {
|
|
|
1369
1421
|
getSigner(newSigner) {
|
|
1370
1422
|
this.signer = newSigner ?? this.signer;
|
|
1371
1423
|
if (!this.signer) {
|
|
1372
|
-
throw new
|
|
1424
|
+
throw new import_core15.MissingParameterError("signer");
|
|
1373
1425
|
}
|
|
1374
1426
|
return this.signer;
|
|
1375
1427
|
}
|
|
@@ -1517,6 +1569,10 @@ var BoltSuiClient = class extends import_core13.BaseClient {
|
|
|
1517
1569
|
await this.loadConfigFromUrl();
|
|
1518
1570
|
return await estimateSwapExactInGasFees(this, params, signer, gasAdjustment);
|
|
1519
1571
|
}
|
|
1572
|
+
/** @inheritdoc */
|
|
1573
|
+
async simulateSwap(params) {
|
|
1574
|
+
return await simulateSwap(this, params);
|
|
1575
|
+
}
|
|
1520
1576
|
/**
|
|
1521
1577
|
* Loads configuration from a remote URL for testnet environments.
|
|
1522
1578
|
*
|
|
@@ -1568,8 +1624,8 @@ var BoltSuiClient = class extends import_core13.BaseClient {
|
|
|
1568
1624
|
for (const item of pools) {
|
|
1569
1625
|
this.routerClient.pools.push({
|
|
1570
1626
|
poolAddress: item.pool_object_id,
|
|
1571
|
-
baseDenom: (0,
|
|
1572
|
-
quoteDenoms: Object.values(assets).map((auxAsset) => (0,
|
|
1627
|
+
baseDenom: (0, import_utils10.normalizeStructTag)(item.base),
|
|
1628
|
+
quoteDenoms: Object.values(assets).map((auxAsset) => (0, import_utils10.normalizeStructTag)(auxAsset)).filter((auxAsset) => auxAsset !== (0, import_utils10.normalizeStructTag)(item.base))
|
|
1573
1629
|
});
|
|
1574
1630
|
}
|
|
1575
1631
|
}
|