@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.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainConfig, ClientConfig, Pool, BaseClient, OracleConfig, OracleAssetPair, InvertiblePrice, Price, RouterConfig, Address, BaseLiquidityDetails, Coin, PoolConfig, Asset, SwapParams, SwapResult } from '@bolt-liquidity-hq/core';
|
|
1
|
+
import { ChainConfig, ClientConfig, Pool, BaseClient, OracleConfig, OracleAssetPair, InvertiblePrice, Price, RouterConfig, Address, BaseLiquidityDetails, Coin, PoolConfig, Asset, SwapParams, SwapResult, SwapRequiredParams, SimulateSwapResult } from '@bolt-liquidity-hq/core';
|
|
2
2
|
import { SuiClient, SuiTransactionBlockResponse } from '@mysten/sui/client';
|
|
3
3
|
import { Signer } from '@mysten/sui/cryptography';
|
|
4
4
|
import { WalletContextState } from '@suiet/wallet-kit';
|
|
@@ -238,6 +238,18 @@ declare const BaseLiquidityResponseStruct: _mysten_bcs.BcsStruct<{
|
|
|
238
238
|
}, string>;
|
|
239
239
|
}, string>;
|
|
240
240
|
type BaseLiquidityResponseStructOutput = BcsParsed<typeof BaseLiquidityResponseStruct>;
|
|
241
|
+
declare const SwapSimulationResultStruct: _mysten_bcs.BcsStruct<{
|
|
242
|
+
amount_out: _mysten_bcs.BcsType<string, string | number | bigint, "u128">;
|
|
243
|
+
dynamic_fee_pct: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
244
|
+
ideal_quote_amt: _mysten_bcs.BcsType<string, string | number | bigint, "u128">;
|
|
245
|
+
swap_fee: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
246
|
+
lp_fee: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
247
|
+
protocol_fee: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
248
|
+
}, string>;
|
|
249
|
+
type SwapSimulationResultStructOutput = BcsParsed<typeof SwapSimulationResultStruct>;
|
|
250
|
+
type RouterPool = Pool & {
|
|
251
|
+
isInverse: boolean;
|
|
252
|
+
};
|
|
241
253
|
|
|
242
254
|
declare const PoolInfoStruct: _mysten_bcs.BcsStruct<{
|
|
243
255
|
base_liquidity: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
@@ -262,7 +274,7 @@ type ProtocolFeesInfoStructOutput = BcsParsed<typeof ProtocolFeesInfoStruct>;
|
|
|
262
274
|
declare class RouterClient {
|
|
263
275
|
pools: Pool[];
|
|
264
276
|
constructor(pools: Pool[]);
|
|
265
|
-
getPool(denomIn: string, denomOut: string):
|
|
277
|
+
getPool(denomIn: string, denomOut: string): RouterPool | undefined;
|
|
266
278
|
getPools(): Pool[];
|
|
267
279
|
}
|
|
268
280
|
|
|
@@ -524,6 +536,8 @@ declare class BoltSuiClient extends BaseClient<Signer, SuiTransactionBlockRespon
|
|
|
524
536
|
* - Sui's gas model includes computation, storage, and storage rebates
|
|
525
537
|
*/
|
|
526
538
|
estimateSwapGasFees(params: SwapParams, signer?: Signer | WalletSigner, gasAdjustment?: number): Promise<Coin | undefined>;
|
|
539
|
+
/** @inheritdoc */
|
|
540
|
+
simulateSwap(params: SwapRequiredParams): Promise<SimulateSwapResult>;
|
|
527
541
|
/**
|
|
528
542
|
* Loads configuration from a remote URL for testnet environments.
|
|
529
543
|
*
|
|
@@ -547,4 +561,4 @@ declare class BoltSuiClient extends BaseClient<Signer, SuiTransactionBlockRespon
|
|
|
547
561
|
private loadConfigFromUrl;
|
|
548
562
|
}
|
|
549
563
|
|
|
550
|
-
export { AssetPairResponseStruct, type AssetPairResponseStructOutput, AssetPairStruct, type AssetPairStructOutput, AssetPairsResponseStruct, type AssetPairsResponseStructOutput, BaseLiquidityInfoStruct, type BaseLiquidityInfoStructOutput, BaseLiquidityResponseStruct, type BaseLiquidityResponseStructOutput, BcsAddressType, type BcsParsed, type BcsParsedMultiple, BoltSuiClient, MarketResponseStruct, type MarketResponseStructOutput, MarketStruct, type MarketStructOutput, MarketsResponsePaginatedStruct, type MarketsResponsePaginatedStructOutput, MarketsResponseStruct, type MarketsResponseStructOutput, OracleConfigStruct, type OracleConfigStructOutput, PaginationStruct, PoolFeesInfoStruct, type PoolFeesInfoStructOutput, PoolInfoStruct, type PoolInfoStructOutput, PriceDataStruct, type PriceDataStructOutput, PriceResponseStruct, type PriceResponseStructOutput, ProtocolFeesInfoStruct, type ProtocolFeesInfoStructOutput, RawPairStruct, type RawPairStructOutput, RawPriceStruct, type RawPriceStructOutput, RouterConfigStruct, type RouterConfigStructOutput, type SuiChainConfig, type SuiClientConfig, TypeNameStruct, type TypeNameStructOutput, type WalletSigner };
|
|
564
|
+
export { AssetPairResponseStruct, type AssetPairResponseStructOutput, AssetPairStruct, type AssetPairStructOutput, AssetPairsResponseStruct, type AssetPairsResponseStructOutput, BaseLiquidityInfoStruct, type BaseLiquidityInfoStructOutput, BaseLiquidityResponseStruct, type BaseLiquidityResponseStructOutput, BcsAddressType, type BcsParsed, type BcsParsedMultiple, BoltSuiClient, MarketResponseStruct, type MarketResponseStructOutput, MarketStruct, type MarketStructOutput, MarketsResponsePaginatedStruct, type MarketsResponsePaginatedStructOutput, MarketsResponseStruct, type MarketsResponseStructOutput, OracleConfigStruct, type OracleConfigStructOutput, PaginationStruct, PoolFeesInfoStruct, type PoolFeesInfoStructOutput, PoolInfoStruct, type PoolInfoStructOutput, PriceDataStruct, type PriceDataStructOutput, PriceResponseStruct, type PriceResponseStructOutput, ProtocolFeesInfoStruct, type ProtocolFeesInfoStructOutput, RawPairStruct, type RawPairStructOutput, RawPriceStruct, type RawPriceStructOutput, RouterConfigStruct, type RouterConfigStructOutput, type RouterPool, type SuiChainConfig, type SuiClientConfig, SwapSimulationResultStruct, type SwapSimulationResultStructOutput, TypeNameStruct, type TypeNameStructOutput, type WalletSigner };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainConfig, ClientConfig, Pool, BaseClient, OracleConfig, OracleAssetPair, InvertiblePrice, Price, RouterConfig, Address, BaseLiquidityDetails, Coin, PoolConfig, Asset, SwapParams, SwapResult } from '@bolt-liquidity-hq/core';
|
|
1
|
+
import { ChainConfig, ClientConfig, Pool, BaseClient, OracleConfig, OracleAssetPair, InvertiblePrice, Price, RouterConfig, Address, BaseLiquidityDetails, Coin, PoolConfig, Asset, SwapParams, SwapResult, SwapRequiredParams, SimulateSwapResult } from '@bolt-liquidity-hq/core';
|
|
2
2
|
import { SuiClient, SuiTransactionBlockResponse } from '@mysten/sui/client';
|
|
3
3
|
import { Signer } from '@mysten/sui/cryptography';
|
|
4
4
|
import { WalletContextState } from '@suiet/wallet-kit';
|
|
@@ -238,6 +238,18 @@ declare const BaseLiquidityResponseStruct: _mysten_bcs.BcsStruct<{
|
|
|
238
238
|
}, string>;
|
|
239
239
|
}, string>;
|
|
240
240
|
type BaseLiquidityResponseStructOutput = BcsParsed<typeof BaseLiquidityResponseStruct>;
|
|
241
|
+
declare const SwapSimulationResultStruct: _mysten_bcs.BcsStruct<{
|
|
242
|
+
amount_out: _mysten_bcs.BcsType<string, string | number | bigint, "u128">;
|
|
243
|
+
dynamic_fee_pct: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
244
|
+
ideal_quote_amt: _mysten_bcs.BcsType<string, string | number | bigint, "u128">;
|
|
245
|
+
swap_fee: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
246
|
+
lp_fee: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
247
|
+
protocol_fee: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
248
|
+
}, string>;
|
|
249
|
+
type SwapSimulationResultStructOutput = BcsParsed<typeof SwapSimulationResultStruct>;
|
|
250
|
+
type RouterPool = Pool & {
|
|
251
|
+
isInverse: boolean;
|
|
252
|
+
};
|
|
241
253
|
|
|
242
254
|
declare const PoolInfoStruct: _mysten_bcs.BcsStruct<{
|
|
243
255
|
base_liquidity: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
|
|
@@ -262,7 +274,7 @@ type ProtocolFeesInfoStructOutput = BcsParsed<typeof ProtocolFeesInfoStruct>;
|
|
|
262
274
|
declare class RouterClient {
|
|
263
275
|
pools: Pool[];
|
|
264
276
|
constructor(pools: Pool[]);
|
|
265
|
-
getPool(denomIn: string, denomOut: string):
|
|
277
|
+
getPool(denomIn: string, denomOut: string): RouterPool | undefined;
|
|
266
278
|
getPools(): Pool[];
|
|
267
279
|
}
|
|
268
280
|
|
|
@@ -524,6 +536,8 @@ declare class BoltSuiClient extends BaseClient<Signer, SuiTransactionBlockRespon
|
|
|
524
536
|
* - Sui's gas model includes computation, storage, and storage rebates
|
|
525
537
|
*/
|
|
526
538
|
estimateSwapGasFees(params: SwapParams, signer?: Signer | WalletSigner, gasAdjustment?: number): Promise<Coin | undefined>;
|
|
539
|
+
/** @inheritdoc */
|
|
540
|
+
simulateSwap(params: SwapRequiredParams): Promise<SimulateSwapResult>;
|
|
527
541
|
/**
|
|
528
542
|
* Loads configuration from a remote URL for testnet environments.
|
|
529
543
|
*
|
|
@@ -547,4 +561,4 @@ declare class BoltSuiClient extends BaseClient<Signer, SuiTransactionBlockRespon
|
|
|
547
561
|
private loadConfigFromUrl;
|
|
548
562
|
}
|
|
549
563
|
|
|
550
|
-
export { AssetPairResponseStruct, type AssetPairResponseStructOutput, AssetPairStruct, type AssetPairStructOutput, AssetPairsResponseStruct, type AssetPairsResponseStructOutput, BaseLiquidityInfoStruct, type BaseLiquidityInfoStructOutput, BaseLiquidityResponseStruct, type BaseLiquidityResponseStructOutput, BcsAddressType, type BcsParsed, type BcsParsedMultiple, BoltSuiClient, MarketResponseStruct, type MarketResponseStructOutput, MarketStruct, type MarketStructOutput, MarketsResponsePaginatedStruct, type MarketsResponsePaginatedStructOutput, MarketsResponseStruct, type MarketsResponseStructOutput, OracleConfigStruct, type OracleConfigStructOutput, PaginationStruct, PoolFeesInfoStruct, type PoolFeesInfoStructOutput, PoolInfoStruct, type PoolInfoStructOutput, PriceDataStruct, type PriceDataStructOutput, PriceResponseStruct, type PriceResponseStructOutput, ProtocolFeesInfoStruct, type ProtocolFeesInfoStructOutput, RawPairStruct, type RawPairStructOutput, RawPriceStruct, type RawPriceStructOutput, RouterConfigStruct, type RouterConfigStructOutput, type SuiChainConfig, type SuiClientConfig, TypeNameStruct, type TypeNameStructOutput, type WalletSigner };
|
|
564
|
+
export { AssetPairResponseStruct, type AssetPairResponseStructOutput, AssetPairStruct, type AssetPairStructOutput, AssetPairsResponseStruct, type AssetPairsResponseStructOutput, BaseLiquidityInfoStruct, type BaseLiquidityInfoStructOutput, BaseLiquidityResponseStruct, type BaseLiquidityResponseStructOutput, BcsAddressType, type BcsParsed, type BcsParsedMultiple, BoltSuiClient, MarketResponseStruct, type MarketResponseStructOutput, MarketStruct, type MarketStructOutput, MarketsResponsePaginatedStruct, type MarketsResponsePaginatedStructOutput, MarketsResponseStruct, type MarketsResponseStructOutput, OracleConfigStruct, type OracleConfigStructOutput, PaginationStruct, PoolFeesInfoStruct, type PoolFeesInfoStructOutput, PoolInfoStruct, type PoolInfoStructOutput, PriceDataStruct, type PriceDataStructOutput, PriceResponseStruct, type PriceResponseStructOutput, ProtocolFeesInfoStruct, type ProtocolFeesInfoStructOutput, RawPairStruct, type RawPairStructOutput, RawPriceStruct, type RawPriceStructOutput, RouterConfigStruct, type RouterConfigStructOutput, type RouterPool, type SuiChainConfig, type SuiClientConfig, SwapSimulationResultStruct, type SwapSimulationResultStructOutput, TypeNameStruct, type TypeNameStructOutput, type WalletSigner };
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
5
5
|
// src/lib/client.ts
|
|
6
6
|
import { BaseClient, MissingParameterError as MissingParameterError2 } from "@bolt-liquidity-hq/core";
|
|
7
7
|
import { SuiClient } from "@mysten/sui/client";
|
|
8
|
-
import { normalizeStructTag as
|
|
8
|
+
import { normalizeStructTag as normalizeStructTag6 } from "@mysten/sui/utils";
|
|
9
9
|
import axios from "axios";
|
|
10
10
|
|
|
11
11
|
// src/config/common.ts
|
|
@@ -103,6 +103,9 @@ var TestnetAssets = {
|
|
|
103
103
|
}
|
|
104
104
|
};
|
|
105
105
|
|
|
106
|
+
// src/lib/constants/defaults.ts
|
|
107
|
+
var BASIS_POINTS = 1e4;
|
|
108
|
+
|
|
106
109
|
// src/lib/constants/sui-objects.ts
|
|
107
110
|
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
108
111
|
var PRICE_ORACLE_MODULE = "price_oracle";
|
|
@@ -583,7 +586,7 @@ import {
|
|
|
583
586
|
} from "@bolt-liquidity-hq/core";
|
|
584
587
|
import { bcs as bcs2 } from "@mysten/bcs";
|
|
585
588
|
import { Transaction as Transaction2 } from "@mysten/sui/transactions";
|
|
586
|
-
import {
|
|
589
|
+
import { SUI_CLOCK_OBJECT_ID } from "@mysten/sui/utils";
|
|
587
590
|
import { BigNumber } from "bignumber.js";
|
|
588
591
|
var buildSwapTxArgs = async (client, swapParams, signer) => {
|
|
589
592
|
const { assetIn, amountIn, assetOut, minimumAmountOut, receiver } = swapParams;
|
|
@@ -591,8 +594,7 @@ var buildSwapTxArgs = async (client, swapParams, signer) => {
|
|
|
591
594
|
if (!pool) {
|
|
592
595
|
throw new NotFoundError(`Pool for the pair ${assetIn}/${assetOut}`);
|
|
593
596
|
}
|
|
594
|
-
const
|
|
595
|
-
const FUNCTION_NAME = isSell ? "swap_sell" : "swap_buy";
|
|
597
|
+
const FUNCTION_NAME = pool.isInverse ? "swap_sell" : "swap_buy";
|
|
596
598
|
const finalSigner = client.getSigner(signer);
|
|
597
599
|
const tx = new Transaction2();
|
|
598
600
|
const signerAddress = getSignerAddress(finalSigner);
|
|
@@ -611,7 +613,7 @@ var buildSwapTxArgs = async (client, swapParams, signer) => {
|
|
|
611
613
|
bcs2.option(bcs2.u64()).serialize(minimumAmountOut),
|
|
612
614
|
bcs2.option(bcs2.string()).serialize(receiver)
|
|
613
615
|
],
|
|
614
|
-
typeArguments: [
|
|
616
|
+
typeArguments: [pool.isInverse ? assetIn : assetOut, pool.isInverse ? assetOut : assetIn],
|
|
615
617
|
tx
|
|
616
618
|
};
|
|
617
619
|
};
|
|
@@ -854,6 +856,14 @@ var BaseLiquidityResponseStruct = bcs5.struct("BaseLiquidityResponse", {
|
|
|
854
856
|
base_assets: bcs5.vector(BaseLiquidityInfoStruct),
|
|
855
857
|
...PaginationStruct
|
|
856
858
|
});
|
|
859
|
+
var SwapSimulationResultStruct = bcs5.struct("SwapSimulationResult", {
|
|
860
|
+
amount_out: bcs5.u128(),
|
|
861
|
+
dynamic_fee_pct: bcs5.u64(),
|
|
862
|
+
ideal_quote_amt: bcs5.u128(),
|
|
863
|
+
swap_fee: bcs5.u64(),
|
|
864
|
+
lp_fee: bcs5.u64(),
|
|
865
|
+
protocol_fee: bcs5.u64()
|
|
866
|
+
});
|
|
857
867
|
|
|
858
868
|
// src/types/pool.ts
|
|
859
869
|
import { bcs as bcs6 } from "@mysten/bcs";
|
|
@@ -887,18 +897,18 @@ var getAssetPairs = async (client) => {
|
|
|
887
897
|
};
|
|
888
898
|
|
|
889
899
|
// src/lib/oracle/get-assets.ts
|
|
890
|
-
import { normalizeStructTag as
|
|
900
|
+
import { normalizeStructTag as normalizeStructTag3 } from "@mysten/sui/utils";
|
|
891
901
|
var getAssets = async (client) => {
|
|
892
902
|
const assetPairs = await client.getAllOracleAssetPairs();
|
|
893
903
|
const uniqueOracleAssets = {};
|
|
894
904
|
for (const item of assetPairs) {
|
|
895
|
-
uniqueOracleAssets[
|
|
905
|
+
uniqueOracleAssets[normalizeStructTag3(item.base.symbol)] = {
|
|
896
906
|
...item.base,
|
|
897
|
-
symbol:
|
|
907
|
+
symbol: normalizeStructTag3(item.base.symbol)
|
|
898
908
|
};
|
|
899
|
-
uniqueOracleAssets[
|
|
909
|
+
uniqueOracleAssets[normalizeStructTag3(item.quote.symbol)] = {
|
|
900
910
|
...item.quote,
|
|
901
|
-
symbol:
|
|
911
|
+
symbol: normalizeStructTag3(item.quote.symbol)
|
|
902
912
|
};
|
|
903
913
|
}
|
|
904
914
|
return Object.values(uniqueOracleAssets).map(
|
|
@@ -907,7 +917,7 @@ var getAssets = async (client) => {
|
|
|
907
917
|
symbol: item.name,
|
|
908
918
|
name: item.name,
|
|
909
919
|
chainId: client.chainConfig.id,
|
|
910
|
-
denom:
|
|
920
|
+
denom: normalizeStructTag3(item.symbol),
|
|
911
921
|
decimals: item.precision,
|
|
912
922
|
logo: void 0,
|
|
913
923
|
coingeckoId: void 0
|
|
@@ -942,7 +952,7 @@ var getPrice = async (client, baseDenom, quoteDenom) => {
|
|
|
942
952
|
|
|
943
953
|
// src/lib/oracle/get-prices.ts
|
|
944
954
|
import { NotFoundError as NotFoundError2 } from "@bolt-liquidity-hq/core";
|
|
945
|
-
import { normalizeStructTag as
|
|
955
|
+
import { normalizeStructTag as normalizeStructTag4 } from "@mysten/sui/utils";
|
|
946
956
|
var getPrices = async (client) => {
|
|
947
957
|
const oracleObject = await client.suiClient.getObject({
|
|
948
958
|
id: client.contracts.oracle,
|
|
@@ -977,8 +987,8 @@ var getPrices = async (client) => {
|
|
|
977
987
|
const pairKey = dynamicFields.data[index]?.name?.value;
|
|
978
988
|
if (fields && pairKey) {
|
|
979
989
|
prices.push({
|
|
980
|
-
baseDenom:
|
|
981
|
-
quoteDenom:
|
|
990
|
+
baseDenom: normalizeStructTag4(pairKey.base.name),
|
|
991
|
+
quoteDenom: normalizeStructTag4(pairKey.quote.name),
|
|
982
992
|
price: fields.price,
|
|
983
993
|
expiryTime: fields.expiry
|
|
984
994
|
});
|
|
@@ -1041,26 +1051,47 @@ var getRouterConfig = async (_client) => {
|
|
|
1041
1051
|
throw new NotImplementedError3("getRouterConfig on Sui Client");
|
|
1042
1052
|
};
|
|
1043
1053
|
|
|
1054
|
+
// src/lib/router/parsers.ts
|
|
1055
|
+
import { NotFoundError as NotFoundError4 } from "@bolt-liquidity-hq/core";
|
|
1056
|
+
import { BigNumber as BigNumber3 } from "bignumber.js";
|
|
1057
|
+
var parseSwapSimulationResultStructOutput = (output, poolAddress, assetOut) => {
|
|
1058
|
+
return {
|
|
1059
|
+
poolAddress,
|
|
1060
|
+
amountOut: output.amount_out,
|
|
1061
|
+
assetOut,
|
|
1062
|
+
protocolFee: output.protocol_fee,
|
|
1063
|
+
lpFee: output.lp_fee,
|
|
1064
|
+
dynamicFeePercentage: BigNumber3(output.dynamic_fee_pct).div(BASIS_POINTS).toFixed(),
|
|
1065
|
+
totalFees: output.swap_fee
|
|
1066
|
+
};
|
|
1067
|
+
};
|
|
1068
|
+
|
|
1044
1069
|
// src/lib/router/router-client/RouterClient.ts
|
|
1045
|
-
import { normalizeStructTag as
|
|
1070
|
+
import { normalizeStructTag as normalizeStructTag5 } from "@mysten/sui/utils";
|
|
1046
1071
|
var RouterClient = class {
|
|
1047
1072
|
constructor(pools) {
|
|
1048
1073
|
this.pools = pools;
|
|
1049
1074
|
}
|
|
1050
1075
|
getPool(denomIn, denomOut) {
|
|
1051
|
-
const normalizedDenomIn =
|
|
1052
|
-
const normalizedDenomOut =
|
|
1076
|
+
const normalizedDenomIn = normalizeStructTag5(denomIn);
|
|
1077
|
+
const normalizedDenomOut = normalizeStructTag5(denomOut);
|
|
1053
1078
|
const directPairPool = this.pools.find(
|
|
1054
1079
|
(item) => item.baseDenom === normalizedDenomOut && item.quoteDenoms.includes(normalizedDenomIn)
|
|
1055
1080
|
);
|
|
1056
1081
|
if (directPairPool) {
|
|
1057
|
-
return
|
|
1082
|
+
return {
|
|
1083
|
+
...directPairPool,
|
|
1084
|
+
isInverse: false
|
|
1085
|
+
};
|
|
1058
1086
|
}
|
|
1059
1087
|
const inversePairPool = this.pools.find(
|
|
1060
1088
|
(item) => item.baseDenom === normalizedDenomIn && item.quoteDenoms.includes(normalizedDenomOut)
|
|
1061
1089
|
);
|
|
1062
1090
|
if (inversePairPool) {
|
|
1063
|
-
return
|
|
1091
|
+
return {
|
|
1092
|
+
...inversePairPool,
|
|
1093
|
+
isInverse: true
|
|
1094
|
+
};
|
|
1064
1095
|
}
|
|
1065
1096
|
return;
|
|
1066
1097
|
}
|
|
@@ -1069,6 +1100,28 @@ var RouterClient = class {
|
|
|
1069
1100
|
}
|
|
1070
1101
|
};
|
|
1071
1102
|
|
|
1103
|
+
// src/lib/router/simulate-swap.ts
|
|
1104
|
+
import {
|
|
1105
|
+
NotFoundError as NotFoundError5
|
|
1106
|
+
} from "@bolt-liquidity-hq/core";
|
|
1107
|
+
import { bcs as bcs7 } from "@mysten/bcs";
|
|
1108
|
+
import { SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID2 } from "@mysten/sui/utils";
|
|
1109
|
+
var simulateSwap = async (client, { assetIn, amountIn, assetOut }) => {
|
|
1110
|
+
const pool = await client.routerClient.getPool(assetIn, assetOut);
|
|
1111
|
+
if (!pool) {
|
|
1112
|
+
throw new NotFoundError5("Pool", `Didn't find a pool to swap ${assetIn} for ${assetOut}`);
|
|
1113
|
+
}
|
|
1114
|
+
const FUNCTION_NAME = pool.isInverse ? "simulate_sell_swap" : "simulate_buy_swap";
|
|
1115
|
+
const response = await queryDevInspect(
|
|
1116
|
+
client.suiClient,
|
|
1117
|
+
[client.packageId, POOL_MODULE, FUNCTION_NAME],
|
|
1118
|
+
[pool.poolAddress, client.contracts.oracle, SUI_CLOCK_OBJECT_ID2, bcs7.u64().serialize(amountIn)],
|
|
1119
|
+
[pool.isInverse ? assetIn : assetOut, pool.isInverse ? assetOut : assetIn]
|
|
1120
|
+
);
|
|
1121
|
+
const output = parseDevInspectResult(response, SwapSimulationResultStruct);
|
|
1122
|
+
return parseSwapSimulationResultStructOutput(output, pool.poolAddress, assetOut);
|
|
1123
|
+
};
|
|
1124
|
+
|
|
1072
1125
|
// src/lib/router/swap-exact-in.ts
|
|
1073
1126
|
var swapExactIn = async (client, swapParams, signer) => {
|
|
1074
1127
|
const swapArgs = await buildSwapTxArgs(client, swapParams, signer);
|
|
@@ -1090,16 +1143,16 @@ var swapExactIn = async (client, swapParams, signer) => {
|
|
|
1090
1143
|
};
|
|
1091
1144
|
|
|
1092
1145
|
// src/lib/settlement/get-pool-info.ts
|
|
1093
|
-
import { NotFoundError as
|
|
1146
|
+
import { NotFoundError as NotFoundError6 } from "@bolt-liquidity-hq/core";
|
|
1094
1147
|
|
|
1095
1148
|
// src/lib/settlement/parsers.ts
|
|
1096
|
-
import { BigNumber as
|
|
1149
|
+
import { BigNumber as BigNumber4 } from "bignumber.js";
|
|
1097
1150
|
var parseSettlementConfigStructOutput = (routerClient, poolFeesInfo, protocolFeesInfo, priceOracleContract) => {
|
|
1098
1151
|
return {
|
|
1099
1152
|
priceOracleContract,
|
|
1100
1153
|
protocolFeeRecipient: protocolFeesInfo.bolt_fee_addr,
|
|
1101
|
-
protocolFee:
|
|
1102
|
-
lpFee:
|
|
1154
|
+
protocolFee: BigNumber4(poolFeesInfo.swap_fee_pct).div(BASIS_POINTS).toFixed(),
|
|
1155
|
+
lpFee: BigNumber4(poolFeesInfo.lp_fee_pct).div(BASIS_POINTS).toFixed(),
|
|
1103
1156
|
allowanceMode: "allow",
|
|
1104
1157
|
// Should come from pool config
|
|
1105
1158
|
lps: routerClient.getPools().map((item) => item.poolAddress),
|
|
@@ -1114,7 +1167,7 @@ var getPoolInfo = async (client, contractAddress) => {
|
|
|
1114
1167
|
const GET_PROTOCOL_FEES_INFO_FUNCTION = "get_protocol_fees_info";
|
|
1115
1168
|
const pool = client.routerClient.pools.find((item) => item.poolAddress === contractAddress);
|
|
1116
1169
|
if (!pool) {
|
|
1117
|
-
throw new
|
|
1170
|
+
throw new NotFoundError6(`Pool with the address ${contractAddress}`);
|
|
1118
1171
|
}
|
|
1119
1172
|
const [poolFeesInfo, protocolFeesInfo] = await Promise.all([
|
|
1120
1173
|
// Query pool fee information
|
|
@@ -1469,6 +1522,10 @@ var BoltSuiClient = class extends BaseClient {
|
|
|
1469
1522
|
await this.loadConfigFromUrl();
|
|
1470
1523
|
return await estimateSwapExactInGasFees(this, params, signer, gasAdjustment);
|
|
1471
1524
|
}
|
|
1525
|
+
/** @inheritdoc */
|
|
1526
|
+
async simulateSwap(params) {
|
|
1527
|
+
return await simulateSwap(this, params);
|
|
1528
|
+
}
|
|
1472
1529
|
/**
|
|
1473
1530
|
* Loads configuration from a remote URL for testnet environments.
|
|
1474
1531
|
*
|
|
@@ -1520,8 +1577,8 @@ var BoltSuiClient = class extends BaseClient {
|
|
|
1520
1577
|
for (const item of pools) {
|
|
1521
1578
|
this.routerClient.pools.push({
|
|
1522
1579
|
poolAddress: item.pool_object_id,
|
|
1523
|
-
baseDenom:
|
|
1524
|
-
quoteDenoms: Object.values(assets).map((auxAsset) =>
|
|
1580
|
+
baseDenom: normalizeStructTag6(item.base),
|
|
1581
|
+
quoteDenoms: Object.values(assets).map((auxAsset) => normalizeStructTag6(auxAsset)).filter((auxAsset) => auxAsset !== normalizeStructTag6(item.base))
|
|
1525
1582
|
});
|
|
1526
1583
|
}
|
|
1527
1584
|
}
|
|
@@ -1550,6 +1607,7 @@ export {
|
|
|
1550
1607
|
RawPairStruct,
|
|
1551
1608
|
RawPriceStruct,
|
|
1552
1609
|
RouterConfigStruct,
|
|
1610
|
+
SwapSimulationResultStruct,
|
|
1553
1611
|
TypeNameStruct
|
|
1554
1612
|
};
|
|
1555
1613
|
//# sourceMappingURL=index.js.map
|