@bolt-liquidity-hq/sui-client 0.1.0-beta.13 → 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 +157 -69
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -31
- package/dist/index.d.ts +26 -31
- package/dist/index.js +153 -63
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
package/dist/index.cjs
CHANGED
|
@@ -49,23 +49,27 @@ __export(index_exports, {
|
|
|
49
49
|
PoolInfoStruct: () => PoolInfoStruct,
|
|
50
50
|
PriceDataStruct: () => PriceDataStruct,
|
|
51
51
|
PriceResponseStruct: () => PriceResponseStruct,
|
|
52
|
-
PricesResponsePaginatedStruct: () => PricesResponsePaginatedStruct,
|
|
53
52
|
ProtocolFeesInfoStruct: () => ProtocolFeesInfoStruct,
|
|
54
53
|
RawPairStruct: () => RawPairStruct,
|
|
55
54
|
RawPriceStruct: () => RawPriceStruct,
|
|
56
55
|
RouterConfigStruct: () => RouterConfigStruct,
|
|
56
|
+
SwapSimulationResultStruct: () => SwapSimulationResultStruct,
|
|
57
57
|
TypeNameStruct: () => TypeNameStruct
|
|
58
58
|
});
|
|
59
59
|
module.exports = __toCommonJS(index_exports);
|
|
60
60
|
|
|
61
61
|
// src/lib/client.ts
|
|
62
|
-
var
|
|
62
|
+
var import_core15 = require("@bolt-liquidity-hq/core");
|
|
63
63
|
var import_client = require("@mysten/sui/client");
|
|
64
|
-
var
|
|
64
|
+
var import_utils10 = require("@mysten/sui/utils");
|
|
65
65
|
var import_axios = __toESM(require("axios"), 1);
|
|
66
66
|
|
|
67
|
-
// src/config/
|
|
67
|
+
// src/config/common.ts
|
|
68
68
|
var import_utils = require("@mysten/sui/utils");
|
|
69
|
+
var SUI_TOKEN_DENOM = (0, import_utils.normalizeStructTag)(import_utils.SUI_TYPE_ARG);
|
|
70
|
+
|
|
71
|
+
// src/config/mainnet.ts
|
|
72
|
+
var import_utils2 = require("@mysten/sui/utils");
|
|
69
73
|
var MainnetChainConfig = {
|
|
70
74
|
name: "Sui",
|
|
71
75
|
id: "101",
|
|
@@ -77,14 +81,14 @@ var MainnetContracts = {
|
|
|
77
81
|
};
|
|
78
82
|
var MainnetPackageId = "0x...";
|
|
79
83
|
var MainnetPoolGlobalConfigId = "0x...";
|
|
80
|
-
var MainnetNativeTokenDenom =
|
|
84
|
+
var MainnetNativeTokenDenom = SUI_TOKEN_DENOM;
|
|
81
85
|
var MainnetAssets = {
|
|
82
|
-
[
|
|
86
|
+
[SUI_TOKEN_DENOM]: {
|
|
83
87
|
symbol: "SUI",
|
|
84
88
|
name: "Sui",
|
|
85
89
|
chainId: "101",
|
|
86
|
-
denom:
|
|
87
|
-
decimals:
|
|
90
|
+
denom: SUI_TOKEN_DENOM,
|
|
91
|
+
decimals: import_utils2.SUI_DECIMALS,
|
|
88
92
|
logo: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/sui/info/logo.png",
|
|
89
93
|
coingeckoId: "sui"
|
|
90
94
|
},
|
|
@@ -101,7 +105,7 @@ var MainnetAssets = {
|
|
|
101
105
|
var MainnetPools = [];
|
|
102
106
|
|
|
103
107
|
// src/config/testnet.ts
|
|
104
|
-
var
|
|
108
|
+
var import_utils3 = require("@mysten/sui/utils");
|
|
105
109
|
var TestnetConfigUrl = "https://phi-labs-ltd.github.io/sui-outpost/testnet.json";
|
|
106
110
|
var TestnetChainConfig = {
|
|
107
111
|
name: "Sui Testnet",
|
|
@@ -114,15 +118,15 @@ var TestnetContracts = {
|
|
|
114
118
|
};
|
|
115
119
|
var TestnetPackageId = "";
|
|
116
120
|
var TestnetPoolGlobalConfigId = "";
|
|
117
|
-
var TestnetNativeTokenDenom =
|
|
121
|
+
var TestnetNativeTokenDenom = SUI_TOKEN_DENOM;
|
|
118
122
|
var TestnetHelperAssets = ["::test_btc::TEST_BTC", "::test_usdt::TEST_USDT"];
|
|
119
123
|
var TestnetAssets = {
|
|
120
|
-
[
|
|
124
|
+
[SUI_TOKEN_DENOM]: {
|
|
121
125
|
symbol: "SUI",
|
|
122
126
|
name: "Sui",
|
|
123
127
|
chainId: "103",
|
|
124
|
-
denom:
|
|
125
|
-
decimals:
|
|
128
|
+
denom: SUI_TOKEN_DENOM,
|
|
129
|
+
decimals: import_utils3.SUI_DECIMALS,
|
|
126
130
|
logo: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/sui/info/logo.png",
|
|
127
131
|
coingeckoId: "sui"
|
|
128
132
|
},
|
|
@@ -141,7 +145,7 @@ var TestnetAssets = {
|
|
|
141
145
|
chainId: "103",
|
|
142
146
|
denom: "::test_btc::TEST_BTC",
|
|
143
147
|
decimals: 8,
|
|
144
|
-
logo: "https://
|
|
148
|
+
logo: "https://raw.githubusercontent.com/cosmos/chain-registry/refs/heads/master/_non-cosmos/bitcoin/images/btc.svg",
|
|
145
149
|
coingeckoId: "bitcoin"
|
|
146
150
|
},
|
|
147
151
|
"::test_usdt::TEST_USDT": {
|
|
@@ -150,11 +154,14 @@ var TestnetAssets = {
|
|
|
150
154
|
chainId: "103",
|
|
151
155
|
denom: "::test_usdt::TEST_USDT",
|
|
152
156
|
decimals: 6,
|
|
153
|
-
logo: "https://
|
|
157
|
+
logo: "https://raw.githubusercontent.com/cosmos/chain-registry/refs/heads/master/_non-cosmos/ethereum/images/usdt.svg",
|
|
154
158
|
coingeckoId: "tether"
|
|
155
159
|
}
|
|
156
160
|
};
|
|
157
161
|
|
|
162
|
+
// src/lib/constants/defaults.ts
|
|
163
|
+
var BASIS_POINTS = 1e4;
|
|
164
|
+
|
|
158
165
|
// src/lib/constants/sui-objects.ts
|
|
159
166
|
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
160
167
|
var PRICE_ORACLE_MODULE = "price_oracle";
|
|
@@ -196,7 +203,7 @@ var parseDevInspectResult = (result, bcsType, resultIndex = 0, returnValueIndex
|
|
|
196
203
|
|
|
197
204
|
// src/lib/helpers/coin-manager.ts
|
|
198
205
|
var import_core2 = require("@bolt-liquidity-hq/core");
|
|
199
|
-
var
|
|
206
|
+
var import_utils4 = require("@mysten/sui/utils");
|
|
200
207
|
var CoinManager = class {
|
|
201
208
|
/**
|
|
202
209
|
* Creates a new CoinManager instance.
|
|
@@ -563,7 +570,7 @@ var CoinManager = class {
|
|
|
563
570
|
*/
|
|
564
571
|
async prepareCoinInput(tx, coinType, amount, options = {}, owner) {
|
|
565
572
|
const ownerAddress = this.getOwnerAddress(owner);
|
|
566
|
-
if (coinType ===
|
|
573
|
+
if ((0, import_utils4.normalizeStructTag)(coinType) === SUI_TOKEN_DENOM) {
|
|
567
574
|
const [coin] = tx.splitCoins(tx.gas, [amount]);
|
|
568
575
|
return coin;
|
|
569
576
|
}
|
|
@@ -630,7 +637,7 @@ var queryDevInspect = async (suiClient, target, args, typeArguments, senderAddre
|
|
|
630
637
|
var import_core4 = require("@bolt-liquidity-hq/core");
|
|
631
638
|
var import_bcs2 = require("@mysten/bcs");
|
|
632
639
|
var import_transactions2 = require("@mysten/sui/transactions");
|
|
633
|
-
var
|
|
640
|
+
var import_utils5 = require("@mysten/sui/utils");
|
|
634
641
|
var import_bignumber = require("bignumber.js");
|
|
635
642
|
var buildSwapTxArgs = async (client, swapParams, signer) => {
|
|
636
643
|
const { assetIn, amountIn, assetOut, minimumAmountOut, receiver } = swapParams;
|
|
@@ -638,25 +645,26 @@ var buildSwapTxArgs = async (client, swapParams, signer) => {
|
|
|
638
645
|
if (!pool) {
|
|
639
646
|
throw new import_core4.NotFoundError(`Pool for the pair ${assetIn}/${assetOut}`);
|
|
640
647
|
}
|
|
641
|
-
const
|
|
642
|
-
const FUNCTION_NAME = isSell ? "swap_sell" : "swap_buy";
|
|
648
|
+
const FUNCTION_NAME = pool.isInverse ? "swap_sell" : "swap_buy";
|
|
643
649
|
const finalSigner = client.getSigner(signer);
|
|
644
650
|
const tx = new import_transactions2.Transaction();
|
|
645
|
-
const
|
|
651
|
+
const signerAddress = getSignerAddress(finalSigner);
|
|
652
|
+
const coinManager = new CoinManager(client.suiClient, signerAddress);
|
|
646
653
|
const coinInput = await coinManager.prepareCoinInput(tx, assetIn, amountIn);
|
|
647
654
|
return {
|
|
648
655
|
signer: finalSigner,
|
|
656
|
+
signerAddress,
|
|
649
657
|
target: [client.packageId, ROUTER_MODULE, FUNCTION_NAME],
|
|
650
658
|
args: [
|
|
651
659
|
pool.poolAddress,
|
|
652
660
|
client.contracts.oracle,
|
|
653
|
-
|
|
661
|
+
import_utils5.SUI_CLOCK_OBJECT_ID,
|
|
654
662
|
coinInput,
|
|
655
663
|
import_bcs2.bcs.u64().serialize(amountIn),
|
|
656
|
-
import_bcs2.bcs.option(import_bcs2.bcs.
|
|
664
|
+
import_bcs2.bcs.option(import_bcs2.bcs.u64()).serialize(minimumAmountOut),
|
|
657
665
|
import_bcs2.bcs.option(import_bcs2.bcs.string()).serialize(receiver)
|
|
658
666
|
],
|
|
659
|
-
typeArguments: [
|
|
667
|
+
typeArguments: [pool.isInverse ? assetIn : assetOut, pool.isInverse ? assetOut : assetIn],
|
|
660
668
|
tx
|
|
661
669
|
};
|
|
662
670
|
};
|
|
@@ -672,15 +680,29 @@ var signAndExecuteTx = async (suiClient, signer, target, args, typeArguments, tr
|
|
|
672
680
|
typeArguments
|
|
673
681
|
});
|
|
674
682
|
try {
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
683
|
+
if ("toSuiAddress" in signer) {
|
|
684
|
+
const result = await suiClient.signAndExecuteTransaction({
|
|
685
|
+
signer,
|
|
686
|
+
transaction: tx,
|
|
687
|
+
options
|
|
688
|
+
});
|
|
689
|
+
if (result.effects?.status.status === "success") {
|
|
690
|
+
return result;
|
|
691
|
+
} else {
|
|
692
|
+
throw new import_core4.TransactionFailedError(result.digest, result.effects?.status.error, { result });
|
|
693
|
+
}
|
|
682
694
|
} else {
|
|
683
|
-
|
|
695
|
+
const result = await signer.signAndExecuteTransaction({
|
|
696
|
+
transaction: tx
|
|
697
|
+
});
|
|
698
|
+
if (!result.digest) {
|
|
699
|
+
throw new import_core4.TransactionFailedError("not found");
|
|
700
|
+
}
|
|
701
|
+
const fullTx = await suiClient.waitForTransaction({
|
|
702
|
+
digest: result.digest,
|
|
703
|
+
options
|
|
704
|
+
});
|
|
705
|
+
return fullTx;
|
|
684
706
|
}
|
|
685
707
|
} catch (error) {
|
|
686
708
|
throw import_core4.UnexpectedError.from(error, "Failed to execute transaction", {
|
|
@@ -723,13 +745,20 @@ var estimateTxGasPrice = async (suiClient, senderAddress, target, args, typeArgu
|
|
|
723
745
|
const totalGasCost = (0, import_bignumber.BigNumber)(gasUsed.computationCost).plus(gasUsed.storageCost).minus(gasUsed.storageRebate);
|
|
724
746
|
const adjustedGasCost = totalGasCost.times(gasAdjustment);
|
|
725
747
|
return {
|
|
726
|
-
denom:
|
|
748
|
+
denom: SUI_TOKEN_DENOM,
|
|
727
749
|
amount: adjustedGasCost.toFixed(0, import_bignumber.BigNumber.ROUND_CEIL)
|
|
728
750
|
};
|
|
729
751
|
} catch {
|
|
730
752
|
return;
|
|
731
753
|
}
|
|
732
754
|
};
|
|
755
|
+
var getSignerAddress = (signer) => {
|
|
756
|
+
const address = "address" in signer ? signer.address : signer.toSuiAddress?.();
|
|
757
|
+
if (!address) {
|
|
758
|
+
throw new import_core4.NotFoundError("Signer account's address");
|
|
759
|
+
}
|
|
760
|
+
return address;
|
|
761
|
+
};
|
|
733
762
|
|
|
734
763
|
// src/lib/oracle/parsers.ts
|
|
735
764
|
var import_core5 = require("@bolt-liquidity-hq/core");
|
|
@@ -764,20 +793,20 @@ var parseAssetPairStructOutput = (output) => {
|
|
|
764
793
|
var parseAssetPairsResponseStructOutput = (output) => {
|
|
765
794
|
return output.map((item) => parseAssetPairStructOutput(item.info));
|
|
766
795
|
};
|
|
767
|
-
var parsePriceDataStructOutput = (output, baseDenom, quoteDenom) => {
|
|
796
|
+
var parsePriceDataStructOutput = (output, baseDenom, quoteDenom, isInverted) => {
|
|
768
797
|
return {
|
|
769
798
|
baseDenom,
|
|
770
799
|
quoteDenom,
|
|
771
800
|
price: output.price.price,
|
|
772
801
|
expiryTime: (0, import_bignumber2.BigNumber)(output.price.expiry).times(1e6).toFixed(),
|
|
773
|
-
isInverse: false
|
|
802
|
+
isInverse: isInverted ?? false
|
|
774
803
|
};
|
|
775
804
|
};
|
|
776
805
|
var parsePriceResponseStructOutput = (output, baseDenom, quoteDenom) => {
|
|
777
806
|
if (!output.pair_data) {
|
|
778
807
|
throw new import_core5.InvalidObjectError("Can't find pair data price");
|
|
779
808
|
}
|
|
780
|
-
return parsePriceDataStructOutput(output.pair_data, baseDenom, quoteDenom);
|
|
809
|
+
return parsePriceDataStructOutput(output.pair_data, baseDenom, quoteDenom, output.is_inverted);
|
|
781
810
|
};
|
|
782
811
|
|
|
783
812
|
// src/types/bcs.ts
|
|
@@ -840,11 +869,8 @@ var PriceDataStruct = import_bcs4.bcs.struct("PriceData", {
|
|
|
840
869
|
updater: BcsAddressType
|
|
841
870
|
});
|
|
842
871
|
var PriceResponseStruct = import_bcs4.bcs.struct("PriceResponse", {
|
|
843
|
-
pair_data: import_bcs4.bcs.option(PriceDataStruct)
|
|
844
|
-
|
|
845
|
-
var PricesResponsePaginatedStruct = import_bcs4.bcs.struct("PricesResponsePaginated", {
|
|
846
|
-
prices: import_bcs4.bcs.vector(PriceDataStruct),
|
|
847
|
-
...PaginationStruct
|
|
872
|
+
pair_data: import_bcs4.bcs.option(PriceDataStruct),
|
|
873
|
+
is_inverted: import_bcs4.bcs.bool()
|
|
848
874
|
});
|
|
849
875
|
|
|
850
876
|
// src/types/router.ts
|
|
@@ -881,6 +907,14 @@ var BaseLiquidityResponseStruct = import_bcs6.bcs.struct("BaseLiquidityResponse"
|
|
|
881
907
|
base_assets: import_bcs6.bcs.vector(BaseLiquidityInfoStruct),
|
|
882
908
|
...PaginationStruct
|
|
883
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
|
+
});
|
|
884
918
|
|
|
885
919
|
// src/types/pool.ts
|
|
886
920
|
var import_bcs8 = require("@mysten/bcs");
|
|
@@ -914,13 +948,19 @@ var getAssetPairs = async (client) => {
|
|
|
914
948
|
};
|
|
915
949
|
|
|
916
950
|
// src/lib/oracle/get-assets.ts
|
|
917
|
-
var
|
|
951
|
+
var import_utils6 = require("@mysten/sui/utils");
|
|
918
952
|
var getAssets = async (client) => {
|
|
919
953
|
const assetPairs = await client.getAllOracleAssetPairs();
|
|
920
954
|
const uniqueOracleAssets = {};
|
|
921
955
|
for (const item of assetPairs) {
|
|
922
|
-
uniqueOracleAssets[item.base.symbol] =
|
|
923
|
-
|
|
956
|
+
uniqueOracleAssets[(0, import_utils6.normalizeStructTag)(item.base.symbol)] = {
|
|
957
|
+
...item.base,
|
|
958
|
+
symbol: (0, import_utils6.normalizeStructTag)(item.base.symbol)
|
|
959
|
+
};
|
|
960
|
+
uniqueOracleAssets[(0, import_utils6.normalizeStructTag)(item.quote.symbol)] = {
|
|
961
|
+
...item.quote,
|
|
962
|
+
symbol: (0, import_utils6.normalizeStructTag)(item.quote.symbol)
|
|
963
|
+
};
|
|
924
964
|
}
|
|
925
965
|
return Object.values(uniqueOracleAssets).map(
|
|
926
966
|
(item) => client.assetsConfig[item.symbol] ?? // Fallback to minimal asset data from oracle
|
|
@@ -928,7 +968,7 @@ var getAssets = async (client) => {
|
|
|
928
968
|
symbol: item.name,
|
|
929
969
|
name: item.name,
|
|
930
970
|
chainId: client.chainConfig.id,
|
|
931
|
-
denom: (0,
|
|
971
|
+
denom: (0, import_utils6.normalizeStructTag)(item.symbol),
|
|
932
972
|
decimals: item.precision,
|
|
933
973
|
logo: void 0,
|
|
934
974
|
coingeckoId: void 0
|
|
@@ -963,7 +1003,7 @@ var getPrice = async (client, baseDenom, quoteDenom) => {
|
|
|
963
1003
|
|
|
964
1004
|
// src/lib/oracle/get-prices.ts
|
|
965
1005
|
var import_core6 = require("@bolt-liquidity-hq/core");
|
|
966
|
-
var
|
|
1006
|
+
var import_utils7 = require("@mysten/sui/utils");
|
|
967
1007
|
var getPrices = async (client) => {
|
|
968
1008
|
const oracleObject = await client.suiClient.getObject({
|
|
969
1009
|
id: client.contracts.oracle,
|
|
@@ -998,8 +1038,8 @@ var getPrices = async (client) => {
|
|
|
998
1038
|
const pairKey = dynamicFields.data[index]?.name?.value;
|
|
999
1039
|
if (fields && pairKey) {
|
|
1000
1040
|
prices.push({
|
|
1001
|
-
baseDenom: (0,
|
|
1002
|
-
quoteDenom: (0,
|
|
1041
|
+
baseDenom: (0, import_utils7.normalizeStructTag)(pairKey.base.name),
|
|
1042
|
+
quoteDenom: (0, import_utils7.normalizeStructTag)(pairKey.quote.name),
|
|
1003
1043
|
price: fields.price,
|
|
1004
1044
|
expiryTime: fields.expiry
|
|
1005
1045
|
});
|
|
@@ -1018,7 +1058,7 @@ var estimateSwapExactInGasFees = async (client, swapParams, signer, gasAdjustmen
|
|
|
1018
1058
|
const swapArgs = await buildSwapTxArgs(client, swapParams, signer);
|
|
1019
1059
|
return await estimateTxGasPrice(
|
|
1020
1060
|
client.suiClient,
|
|
1021
|
-
swapArgs.
|
|
1061
|
+
swapArgs.signerAddress,
|
|
1022
1062
|
swapArgs.target,
|
|
1023
1063
|
swapArgs.args,
|
|
1024
1064
|
swapArgs.typeArguments,
|
|
@@ -1042,9 +1082,9 @@ var getAllQuotesForUser = async (_client, _lpAddress) => {
|
|
|
1042
1082
|
// src/lib/router/get-pool-by-denom.ts
|
|
1043
1083
|
var import_core10 = require("@bolt-liquidity-hq/core");
|
|
1044
1084
|
var getPoolByDenom = async (client, baseDenom, quoteDenom) => {
|
|
1045
|
-
const result = await client.routerClient.getPool(
|
|
1085
|
+
const result = await client.routerClient.getPool(quoteDenom, baseDenom);
|
|
1046
1086
|
if (!result) {
|
|
1047
|
-
throw new import_core10.NotFoundError("Pool", `Didn't find a pool to swap ${
|
|
1087
|
+
throw new import_core10.NotFoundError("Pool", `Didn't find a pool to swap ${quoteDenom} for ${baseDenom}`);
|
|
1048
1088
|
}
|
|
1049
1089
|
return result;
|
|
1050
1090
|
};
|
|
@@ -1060,26 +1100,47 @@ var getRouterConfig = async (_client) => {
|
|
|
1060
1100
|
throw new import_core11.NotImplementedError("getRouterConfig on Sui Client");
|
|
1061
1101
|
};
|
|
1062
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
|
+
|
|
1063
1118
|
// src/lib/router/router-client/RouterClient.ts
|
|
1064
|
-
var
|
|
1119
|
+
var import_utils8 = require("@mysten/sui/utils");
|
|
1065
1120
|
var RouterClient = class {
|
|
1066
1121
|
constructor(pools) {
|
|
1067
1122
|
this.pools = pools;
|
|
1068
1123
|
}
|
|
1069
1124
|
getPool(denomIn, denomOut) {
|
|
1070
|
-
const normalizedDenomIn = (0,
|
|
1071
|
-
const normalizedDenomOut = (0,
|
|
1125
|
+
const normalizedDenomIn = (0, import_utils8.normalizeStructTag)(denomIn);
|
|
1126
|
+
const normalizedDenomOut = (0, import_utils8.normalizeStructTag)(denomOut);
|
|
1072
1127
|
const directPairPool = this.pools.find(
|
|
1073
|
-
(item) => item.baseDenom ===
|
|
1128
|
+
(item) => item.baseDenom === normalizedDenomOut && item.quoteDenoms.includes(normalizedDenomIn)
|
|
1074
1129
|
);
|
|
1075
1130
|
if (directPairPool) {
|
|
1076
|
-
return
|
|
1131
|
+
return {
|
|
1132
|
+
...directPairPool,
|
|
1133
|
+
isInverse: false
|
|
1134
|
+
};
|
|
1077
1135
|
}
|
|
1078
1136
|
const inversePairPool = this.pools.find(
|
|
1079
|
-
(item) => item.baseDenom ===
|
|
1137
|
+
(item) => item.baseDenom === normalizedDenomIn && item.quoteDenoms.includes(normalizedDenomOut)
|
|
1080
1138
|
);
|
|
1081
1139
|
if (inversePairPool) {
|
|
1082
|
-
return
|
|
1140
|
+
return {
|
|
1141
|
+
...inversePairPool,
|
|
1142
|
+
isInverse: true
|
|
1143
|
+
};
|
|
1083
1144
|
}
|
|
1084
1145
|
return;
|
|
1085
1146
|
}
|
|
@@ -1088,6 +1149,26 @@ var RouterClient = class {
|
|
|
1088
1149
|
}
|
|
1089
1150
|
};
|
|
1090
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
|
+
|
|
1091
1172
|
// src/lib/router/swap-exact-in.ts
|
|
1092
1173
|
var swapExactIn = async (client, swapParams, signer) => {
|
|
1093
1174
|
const swapArgs = await buildSwapTxArgs(client, swapParams, signer);
|
|
@@ -1109,15 +1190,16 @@ var swapExactIn = async (client, swapParams, signer) => {
|
|
|
1109
1190
|
};
|
|
1110
1191
|
|
|
1111
1192
|
// src/lib/settlement/get-pool-info.ts
|
|
1112
|
-
var
|
|
1193
|
+
var import_core14 = require("@bolt-liquidity-hq/core");
|
|
1113
1194
|
|
|
1114
1195
|
// src/lib/settlement/parsers.ts
|
|
1196
|
+
var import_bignumber4 = require("bignumber.js");
|
|
1115
1197
|
var parseSettlementConfigStructOutput = (routerClient, poolFeesInfo, protocolFeesInfo, priceOracleContract) => {
|
|
1116
1198
|
return {
|
|
1117
1199
|
priceOracleContract,
|
|
1118
1200
|
protocolFeeRecipient: protocolFeesInfo.bolt_fee_addr,
|
|
1119
|
-
protocolFee: poolFeesInfo.swap_fee_pct,
|
|
1120
|
-
lpFee: poolFeesInfo.lp_fee_pct,
|
|
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(),
|
|
1121
1203
|
allowanceMode: "allow",
|
|
1122
1204
|
// Should come from pool config
|
|
1123
1205
|
lps: routerClient.getPools().map((item) => item.poolAddress),
|
|
@@ -1130,22 +1212,24 @@ var parseSettlementConfigStructOutput = (routerClient, poolFeesInfo, protocolFee
|
|
|
1130
1212
|
var getPoolInfo = async (client, contractAddress) => {
|
|
1131
1213
|
const GET_POOL_FEES_INFO_FUNCTION = "get_pool_fees_info";
|
|
1132
1214
|
const GET_PROTOCOL_FEES_INFO_FUNCTION = "get_protocol_fees_info";
|
|
1215
|
+
const pool = client.routerClient.pools.find((item) => item.poolAddress === contractAddress);
|
|
1216
|
+
if (!pool) {
|
|
1217
|
+
throw new import_core14.NotFoundError(`Pool with the address ${contractAddress}`);
|
|
1218
|
+
}
|
|
1133
1219
|
const [poolFeesInfo, protocolFeesInfo] = await Promise.all([
|
|
1134
1220
|
// Query pool fee information
|
|
1135
1221
|
queryDevInspect(
|
|
1136
1222
|
client.suiClient,
|
|
1137
1223
|
[client.packageId, POOL_MODULE, GET_POOL_FEES_INFO_FUNCTION],
|
|
1138
1224
|
[contractAddress],
|
|
1139
|
-
|
|
1140
|
-
[import_utils8.SUI_TYPE_ARG]
|
|
1225
|
+
[pool.baseDenom]
|
|
1141
1226
|
),
|
|
1142
1227
|
// Query protocol fee information
|
|
1143
1228
|
queryDevInspect(
|
|
1144
1229
|
client.suiClient,
|
|
1145
1230
|
[client.packageId, POOL_MODULE, GET_PROTOCOL_FEES_INFO_FUNCTION],
|
|
1146
1231
|
[contractAddress],
|
|
1147
|
-
|
|
1148
|
-
[import_utils8.SUI_TYPE_ARG]
|
|
1232
|
+
[pool.baseDenom]
|
|
1149
1233
|
)
|
|
1150
1234
|
]);
|
|
1151
1235
|
const poolFeesInfoOutput = parseDevInspectResult(poolFeesInfo, PoolFeesInfoStruct);
|
|
@@ -1165,7 +1249,7 @@ var getPoolInfoByDenom = async (client, baseDenom, quoteDenom) => {
|
|
|
1165
1249
|
};
|
|
1166
1250
|
|
|
1167
1251
|
// src/lib/client.ts
|
|
1168
|
-
var BoltSuiClient = class extends
|
|
1252
|
+
var BoltSuiClient = class extends import_core15.BaseClient {
|
|
1169
1253
|
/**
|
|
1170
1254
|
* Creates a new instance of the BoltSuiClient.
|
|
1171
1255
|
*
|
|
@@ -1337,7 +1421,7 @@ var BoltSuiClient = class extends import_core12.BaseClient {
|
|
|
1337
1421
|
getSigner(newSigner) {
|
|
1338
1422
|
this.signer = newSigner ?? this.signer;
|
|
1339
1423
|
if (!this.signer) {
|
|
1340
|
-
throw new
|
|
1424
|
+
throw new import_core15.MissingParameterError("signer");
|
|
1341
1425
|
}
|
|
1342
1426
|
return this.signer;
|
|
1343
1427
|
}
|
|
@@ -1485,6 +1569,10 @@ var BoltSuiClient = class extends import_core12.BaseClient {
|
|
|
1485
1569
|
await this.loadConfigFromUrl();
|
|
1486
1570
|
return await estimateSwapExactInGasFees(this, params, signer, gasAdjustment);
|
|
1487
1571
|
}
|
|
1572
|
+
/** @inheritdoc */
|
|
1573
|
+
async simulateSwap(params) {
|
|
1574
|
+
return await simulateSwap(this, params);
|
|
1575
|
+
}
|
|
1488
1576
|
/**
|
|
1489
1577
|
* Loads configuration from a remote URL for testnet environments.
|
|
1490
1578
|
*
|
|
@@ -1536,8 +1624,8 @@ var BoltSuiClient = class extends import_core12.BaseClient {
|
|
|
1536
1624
|
for (const item of pools) {
|
|
1537
1625
|
this.routerClient.pools.push({
|
|
1538
1626
|
poolAddress: item.pool_object_id,
|
|
1539
|
-
baseDenom: (0,
|
|
1540
|
-
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))
|
|
1541
1629
|
});
|
|
1542
1630
|
}
|
|
1543
1631
|
}
|