@myx-trade/sdk 0.1.17 → 0.1.19
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.d.mts +32 -3
- package/dist/index.d.ts +32 -3
- package/dist/index.js +99 -91
- package/dist/index.mjs +99 -91
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -33,6 +33,7 @@ __export(index_exports, {
|
|
|
33
33
|
COMMON_LP_AMOUNT_DECIMALS: () => COMMON_LP_AMOUNT_DECIMALS,
|
|
34
34
|
COMMON_PRICE_DECIMALS: () => COMMON_PRICE_DECIMALS,
|
|
35
35
|
ChainId: () => ChainId,
|
|
36
|
+
CloseTypeEnum: () => CloseTypeEnum,
|
|
36
37
|
Direction: () => Direction,
|
|
37
38
|
DirectionEnum: () => DirectionEnum,
|
|
38
39
|
ErrorCode: () => ErrorCode2,
|
|
@@ -1826,7 +1827,7 @@ var RotationProvider = class extends import_providers.BaseProvider {
|
|
|
1826
1827
|
// package.json
|
|
1827
1828
|
var package_default = {
|
|
1828
1829
|
name: "@myx-trade/sdk",
|
|
1829
|
-
version: "0.1.
|
|
1830
|
+
version: "0.1.19",
|
|
1830
1831
|
private: false,
|
|
1831
1832
|
publishConfig: {
|
|
1832
1833
|
access: "public"
|
|
@@ -1957,17 +1958,10 @@ if (typeof window !== "undefined") {
|
|
|
1957
1958
|
}
|
|
1958
1959
|
var getWalletProvider = async (chainId2) => {
|
|
1959
1960
|
try {
|
|
1960
|
-
const
|
|
1961
|
+
const walletClient = sdk.getConfigManager()?.getConfig().walletClient;
|
|
1962
|
+
const provider = new import_ethers3.BrowserProvider(walletClient?.transport);
|
|
1961
1963
|
if (!provider) {
|
|
1962
|
-
throw new Error("
|
|
1963
|
-
}
|
|
1964
|
-
if (chainId2) {
|
|
1965
|
-
const network = await provider.getNetwork();
|
|
1966
|
-
console.log(provider);
|
|
1967
|
-
console.log(`Connected to chain: ${network.chainId}, requested: ${chainId2}`);
|
|
1968
|
-
if (Number(network.chainId) !== chainId2) {
|
|
1969
|
-
await provider.send("wallet_switchEthereumChain", [{ chainId: BigInt(chainId2) }]);
|
|
1970
|
-
}
|
|
1964
|
+
throw new Error("missing provider");
|
|
1971
1965
|
}
|
|
1972
1966
|
return provider;
|
|
1973
1967
|
} catch (error) {
|
|
@@ -1977,7 +1971,6 @@ var getWalletProvider = async (chainId2) => {
|
|
|
1977
1971
|
};
|
|
1978
1972
|
var getSignerProvider = async (chainId2) => {
|
|
1979
1973
|
const provider = await getWalletProvider(chainId2);
|
|
1980
|
-
console.log(provider);
|
|
1981
1974
|
return provider?.getSigner?.();
|
|
1982
1975
|
};
|
|
1983
1976
|
|
|
@@ -9184,10 +9177,10 @@ var getLiquidityRouterContract = async (chainId2) => {
|
|
|
9184
9177
|
const provider = await getSignerProvider(chainId2);
|
|
9185
9178
|
return getContract(address, LiquidityRouter_default, provider);
|
|
9186
9179
|
};
|
|
9187
|
-
var getPoolManagerContract = async (chainId2) => {
|
|
9180
|
+
var getPoolManagerContract = async (chainId2, type = 1 /* Signer */) => {
|
|
9188
9181
|
const addresses = address_default[chainId2];
|
|
9189
9182
|
const address = addresses.POOL_MANAGER;
|
|
9190
|
-
const provider = await getSignerProvider(chainId2);
|
|
9183
|
+
const provider = type === 0 /* JSON */ ? getJSONProvider(chainId2) : await getSignerProvider(chainId2);
|
|
9191
9184
|
return getContract(address, PoolManager_default, provider);
|
|
9192
9185
|
};
|
|
9193
9186
|
var getQuotePoolContract = async (chainId2, type = 0 /* JSON */) => {
|
|
@@ -9495,18 +9488,13 @@ var getAllowanceApproved = async (chainId2, account, tokenAddress, approveAddres
|
|
|
9495
9488
|
const provider = getJSONProvider(chainId2);
|
|
9496
9489
|
const contractInterface = new import_ethers5.ethers.Interface(IERC20Metadata_default);
|
|
9497
9490
|
const data = contractInterface.encodeFunctionData("allowance", [account, approveAddress]);
|
|
9498
|
-
console.log("approve token ", tokenAddress);
|
|
9499
|
-
console.log("approve address ", approveAddress);
|
|
9500
9491
|
const callData = {
|
|
9501
9492
|
to: tokenAddress,
|
|
9502
9493
|
data
|
|
9503
9494
|
};
|
|
9504
9495
|
const result = await provider.call(callData);
|
|
9505
9496
|
const allowance = BigInt(result);
|
|
9506
|
-
console.log("Allowance:", allowance.toString());
|
|
9507
|
-
console.log("ApproveAmount:", approveAmount.toString());
|
|
9508
9497
|
if (allowance >= approveAmount) {
|
|
9509
|
-
console.log("Allowance approved.");
|
|
9510
9498
|
return true;
|
|
9511
9499
|
}
|
|
9512
9500
|
return false;
|
|
@@ -9519,10 +9507,7 @@ var getAllowanceApproved = async (chainId2, account, tokenAddress, approveAddres
|
|
|
9519
9507
|
var approve = async (chainId2, account, tokenAddress, approveAddress, amount) => {
|
|
9520
9508
|
try {
|
|
9521
9509
|
const TokenContract = await getERC20Contract(chainId2, tokenAddress);
|
|
9522
|
-
console.log("approve token Address", tokenAddress);
|
|
9523
9510
|
const response = await TokenContract.approve(approveAddress, amount);
|
|
9524
|
-
console.log("approve amount", approveAddress);
|
|
9525
|
-
console.log("approve amount", amount);
|
|
9526
9511
|
const receipt = await response?.wait();
|
|
9527
9512
|
const isApproved = await getAllowanceApproved(chainId2, account, tokenAddress, approveAddress, amount);
|
|
9528
9513
|
if (!isApproved) {
|
|
@@ -9551,13 +9536,11 @@ var checkParams = async (params) => {
|
|
|
9551
9536
|
throw new Error(Errors[4004 /* Invalid_Amount */]);
|
|
9552
9537
|
}
|
|
9553
9538
|
}
|
|
9554
|
-
console.log("checkbalance");
|
|
9555
9539
|
const { tokenAddress, contractAddress, chainId: chainId2, amount, decimals, account } = params;
|
|
9556
9540
|
if (amount && chainId2 && decimals && account) {
|
|
9557
9541
|
const amountIn = (0, import_ethers6.parseUnits)(amount.toString(), decimals);
|
|
9558
9542
|
if (tokenAddress) {
|
|
9559
9543
|
const balance = await getBalanceOf(chainId2, account, tokenAddress);
|
|
9560
|
-
console.log("balance", balance, tokenAddress);
|
|
9561
9544
|
if (!balance || balance < amountIn) {
|
|
9562
9545
|
throw new Error(Errors[3 /* Insufficient_Balance */]);
|
|
9563
9546
|
}
|
|
@@ -9591,9 +9574,7 @@ var bigintTradingGasPriceWithRatio = async (chainId2) => {
|
|
|
9591
9574
|
if (!gasPrice) {
|
|
9592
9575
|
throw new Error("Network Error");
|
|
9593
9576
|
}
|
|
9594
|
-
console.log("gasPrice", gasPrice);
|
|
9595
9577
|
const gasPriceWithRatio = bigintTradingGasToRatioCalculator(gasPrice, chainInfo.gasPriceRatio);
|
|
9596
|
-
console.log("gasPriceWithRatio--->", gasPriceWithRatio);
|
|
9597
9578
|
return {
|
|
9598
9579
|
gasPrice: gasPriceWithRatio
|
|
9599
9580
|
};
|
|
@@ -9694,10 +9675,10 @@ var MarketPoolState = /* @__PURE__ */ ((MarketPoolState3) => {
|
|
|
9694
9675
|
MarketPoolState3[MarketPoolState3["Bench"] = 4] = "Bench";
|
|
9695
9676
|
return MarketPoolState3;
|
|
9696
9677
|
})(MarketPoolState || {});
|
|
9697
|
-
var OracleType = /* @__PURE__ */ ((
|
|
9698
|
-
|
|
9699
|
-
|
|
9700
|
-
return
|
|
9678
|
+
var OracleType = /* @__PURE__ */ ((OracleType7) => {
|
|
9679
|
+
OracleType7[OracleType7["Chainlink"] = 1] = "Chainlink";
|
|
9680
|
+
OracleType7[OracleType7["Pyth"] = 2] = "Pyth";
|
|
9681
|
+
return OracleType7;
|
|
9701
9682
|
})(OracleType || {});
|
|
9702
9683
|
var HttpKlineIntervalEnum = /* @__PURE__ */ ((HttpKlineIntervalEnum2) => {
|
|
9703
9684
|
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Minute1"] = 1] = "Minute1";
|
|
@@ -9787,6 +9768,19 @@ var getHistoryOrders = async ({
|
|
|
9787
9768
|
}
|
|
9788
9769
|
);
|
|
9789
9770
|
};
|
|
9771
|
+
var CloseTypeEnum = /* @__PURE__ */ ((CloseTypeEnum2) => {
|
|
9772
|
+
CloseTypeEnum2[CloseTypeEnum2["Open"] = 0] = "Open";
|
|
9773
|
+
CloseTypeEnum2[CloseTypeEnum2["PartialClose"] = 1] = "PartialClose";
|
|
9774
|
+
CloseTypeEnum2[CloseTypeEnum2["FullClose"] = 2] = "FullClose";
|
|
9775
|
+
CloseTypeEnum2[CloseTypeEnum2["Liquidation"] = 3] = "Liquidation";
|
|
9776
|
+
CloseTypeEnum2[CloseTypeEnum2["EarlyClose"] = 4] = "EarlyClose";
|
|
9777
|
+
CloseTypeEnum2[CloseTypeEnum2["MarketClose"] = 5] = "MarketClose";
|
|
9778
|
+
CloseTypeEnum2[CloseTypeEnum2["ADL"] = 6] = "ADL";
|
|
9779
|
+
CloseTypeEnum2[CloseTypeEnum2["TP"] = 7] = "TP";
|
|
9780
|
+
CloseTypeEnum2[CloseTypeEnum2["SL"] = 8] = "SL";
|
|
9781
|
+
CloseTypeEnum2[CloseTypeEnum2["Increase"] = 9] = "Increase";
|
|
9782
|
+
return CloseTypeEnum2;
|
|
9783
|
+
})(CloseTypeEnum || {});
|
|
9790
9784
|
var getPositionHistory = async ({
|
|
9791
9785
|
accessToken,
|
|
9792
9786
|
...params
|
|
@@ -10056,7 +10050,6 @@ var claimBasePoolRebate = async (params) => {
|
|
|
10056
10050
|
poolId,
|
|
10057
10051
|
recipient: account
|
|
10058
10052
|
};
|
|
10059
|
-
console.log("base claim", data);
|
|
10060
10053
|
const contract = await getLiquidityRouterContract(chainId2);
|
|
10061
10054
|
const _gasLimit = await contract["claimBasePoolRebate((bytes32,uint8,uint256,bytes,uint64)[],bytes32,address)"].estimateGas(prices, poolId, account, {
|
|
10062
10055
|
value: values[0]
|
|
@@ -10068,7 +10061,6 @@ var claimBasePoolRebate = async (params) => {
|
|
|
10068
10061
|
gasPrice,
|
|
10069
10062
|
value: values[0]
|
|
10070
10063
|
});
|
|
10071
|
-
console.log("base claim", response);
|
|
10072
10064
|
return response;
|
|
10073
10065
|
} catch (error) {
|
|
10074
10066
|
console.error(error);
|
|
@@ -10104,7 +10096,6 @@ var claimBasePoolRebates = async (params) => {
|
|
|
10104
10096
|
value,
|
|
10105
10097
|
recipient: account
|
|
10106
10098
|
};
|
|
10107
|
-
console.log("base claim pool rebates", data);
|
|
10108
10099
|
const contract = await getLiquidityRouterContract(chainId2);
|
|
10109
10100
|
const _gasLimit = await contract["claimBasePoolRebates((bytes32,uint8,uint256,bytes,uint64)[],bytes32[],address)"].estimateGas(prices, poolIds, account, {
|
|
10110
10101
|
value
|
|
@@ -10116,7 +10107,6 @@ var claimBasePoolRebates = async (params) => {
|
|
|
10116
10107
|
gasPrice,
|
|
10117
10108
|
value
|
|
10118
10109
|
});
|
|
10119
|
-
console.log("base claim rebates", response);
|
|
10120
10110
|
return response;
|
|
10121
10111
|
} catch (error) {
|
|
10122
10112
|
console.error(error);
|
|
@@ -10152,7 +10142,6 @@ var Market = {
|
|
|
10152
10142
|
var previewLpAmountOut = async ({ chainId: chainId2, amountIn, poolId, price = 0n }) => {
|
|
10153
10143
|
try {
|
|
10154
10144
|
const chainInfo = CHAIN_INFO[chainId2];
|
|
10155
|
-
console.log("previewLpAmountOut data", [poolId, amountIn, price]);
|
|
10156
10145
|
const basePoolContract = await getBasePoolContract(chainId2);
|
|
10157
10146
|
const _gasLimit = await basePoolContract.previewLpAmountOut.estimateGas(poolId, amountIn, price);
|
|
10158
10147
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
@@ -10161,7 +10150,6 @@ var previewLpAmountOut = async ({ chainId: chainId2, amountIn, poolId, price = 0
|
|
|
10161
10150
|
gasLimit,
|
|
10162
10151
|
gasPrice
|
|
10163
10152
|
});
|
|
10164
|
-
console.log(request);
|
|
10165
10153
|
return request;
|
|
10166
10154
|
} catch (error) {
|
|
10167
10155
|
console.error(error);
|
|
@@ -10171,7 +10159,6 @@ var previewLpAmountOut = async ({ chainId: chainId2, amountIn, poolId, price = 0
|
|
|
10171
10159
|
var previewBaseAmountOut = async ({ chainId: chainId2, amountIn, poolId, price = 0n }) => {
|
|
10172
10160
|
try {
|
|
10173
10161
|
const chainInfo = CHAIN_INFO[chainId2];
|
|
10174
|
-
console.log("previewQuoteAmountOut data", [poolId, amountIn, price]);
|
|
10175
10162
|
const basePoolContract = await getBasePoolContract(chainId2);
|
|
10176
10163
|
const _gasLimit = await basePoolContract.previewBaseAmountOut.estimateGas(poolId, amountIn, price);
|
|
10177
10164
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
@@ -10180,7 +10167,6 @@ var previewBaseAmountOut = async ({ chainId: chainId2, amountIn, poolId, price =
|
|
|
10180
10167
|
gasLimit,
|
|
10181
10168
|
gasPrice
|
|
10182
10169
|
});
|
|
10183
|
-
console.log("previewBaseAmountOut response", request);
|
|
10184
10170
|
return request;
|
|
10185
10171
|
} catch (error) {
|
|
10186
10172
|
console.error(error);
|
|
@@ -10209,7 +10195,6 @@ var previewUserWithdrawData = async ({ chainId: chainId2, account, poolId, amoun
|
|
|
10209
10195
|
const priceResponse = await getOraclePrice(chainId2, [poolId]);
|
|
10210
10196
|
const _price = priceResponse.data?.[0]?.price || "0";
|
|
10211
10197
|
const price = (0, import_ethers9.parseUnits)(_price, COMMON_PRICE_DECIMALS);
|
|
10212
|
-
console.log("previewUserWithdrawData data", [poolId, amountIn, account, price]);
|
|
10213
10198
|
const basePoolContract = await getBasePoolContract(chainId2);
|
|
10214
10199
|
const _gasLimit = await basePoolContract.previewUserWithdrawData.estimateGas(poolId, amountIn, account, price);
|
|
10215
10200
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
@@ -10219,7 +10204,6 @@ var previewUserWithdrawData = async ({ chainId: chainId2, account, poolId, amoun
|
|
|
10219
10204
|
gasPrice
|
|
10220
10205
|
});
|
|
10221
10206
|
const { baseAmountOut, rebateAmount } = request;
|
|
10222
|
-
console.log("previewUserWithdrawData result:", { baseAmountOut, rebateAmount });
|
|
10223
10207
|
return {
|
|
10224
10208
|
baseAmountOut,
|
|
10225
10209
|
rebateAmount
|
|
@@ -10335,7 +10319,6 @@ var deposit = async (params) => {
|
|
|
10335
10319
|
recipient: account,
|
|
10336
10320
|
tpslParams
|
|
10337
10321
|
};
|
|
10338
|
-
console.log("deposit base", price, data, value);
|
|
10339
10322
|
const contract = await getLiquidityRouterContract(chainId2);
|
|
10340
10323
|
const _gasLimit = await contract["depositBase((bytes32,uint8,uint256,bytes,uint64)[],(bytes32,uint256,uint256,address,(uint256,uint256,uint8,uint256)[]))"].estimateGas(price, data, { value });
|
|
10341
10324
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
@@ -10345,7 +10328,6 @@ var deposit = async (params) => {
|
|
|
10345
10328
|
gasPrice,
|
|
10346
10329
|
value
|
|
10347
10330
|
});
|
|
10348
|
-
console.log("deposit", result);
|
|
10349
10331
|
return result;
|
|
10350
10332
|
} catch (error) {
|
|
10351
10333
|
console.error(error);
|
|
@@ -10407,7 +10389,6 @@ var withdraw = async (params) => {
|
|
|
10407
10389
|
value
|
|
10408
10390
|
});
|
|
10409
10391
|
const receipt = await response?.wait();
|
|
10410
|
-
console.log("base withdraw", response);
|
|
10411
10392
|
return receipt;
|
|
10412
10393
|
} catch (error) {
|
|
10413
10394
|
console.error(error);
|
|
@@ -10426,7 +10407,6 @@ var getRewards = async (params) => {
|
|
|
10426
10407
|
const priceResponse = await getOraclePrice(chainId2, [poolId]);
|
|
10427
10408
|
const _price = priceResponse.data?.[0]?.price || "0";
|
|
10428
10409
|
const price = (0, import_ethers13.parseUnits)(_price, COMMON_PRICE_DECIMALS);
|
|
10429
|
-
console.log("pendingUserRebates base data:", [poolId, lpAmountIn, account, price]);
|
|
10430
10410
|
const basePoolContract = await getBasePoolContract(chainId2);
|
|
10431
10411
|
const _gasLimit = await basePoolContract.pendingUserRebates.estimateGas(poolId, account, price);
|
|
10432
10412
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
@@ -10435,7 +10415,6 @@ var getRewards = async (params) => {
|
|
|
10435
10415
|
gasLimit,
|
|
10436
10416
|
gasPrice
|
|
10437
10417
|
});
|
|
10438
|
-
console.log("pendingUserRebates base result:", request);
|
|
10439
10418
|
return request;
|
|
10440
10419
|
} catch (error) {
|
|
10441
10420
|
console.error(error);
|
|
@@ -10458,7 +10437,6 @@ var getLpPrice = async (chainId2, poolId) => {
|
|
|
10458
10437
|
}
|
|
10459
10438
|
}
|
|
10460
10439
|
const data = await contract.getPoolTokenPrice(poolId, price);
|
|
10461
|
-
console.log(`pool ${poolId} price: `, data);
|
|
10462
10440
|
return data;
|
|
10463
10441
|
} catch (error) {
|
|
10464
10442
|
console.error(error);
|
|
@@ -10485,7 +10463,6 @@ var import_ethers15 = require("ethers");
|
|
|
10485
10463
|
var previewLpAmountOut2 = async ({ chainId: chainId2, amountIn, poolId, price = 0n }) => {
|
|
10486
10464
|
try {
|
|
10487
10465
|
const chainInfo = CHAIN_INFO[chainId2];
|
|
10488
|
-
console.log("previewLpAmountOut data", [poolId, amountIn, price]);
|
|
10489
10466
|
const quotePoolContract = await getQuotePoolContract(chainId2);
|
|
10490
10467
|
const _gasLimit = await quotePoolContract.previewLpAmountOut.estimateGas(poolId, amountIn, price);
|
|
10491
10468
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
@@ -10494,7 +10471,6 @@ var previewLpAmountOut2 = async ({ chainId: chainId2, amountIn, poolId, price =
|
|
|
10494
10471
|
gasLimit,
|
|
10495
10472
|
gasPrice
|
|
10496
10473
|
});
|
|
10497
|
-
console.log(request);
|
|
10498
10474
|
return request;
|
|
10499
10475
|
} catch (error) {
|
|
10500
10476
|
console.error(error);
|
|
@@ -10504,7 +10480,6 @@ var previewLpAmountOut2 = async ({ chainId: chainId2, amountIn, poolId, price =
|
|
|
10504
10480
|
var previewQuoteAmountOut = async ({ chainId: chainId2, amountIn, poolId, price = 0n }) => {
|
|
10505
10481
|
try {
|
|
10506
10482
|
const chainInfo = CHAIN_INFO[chainId2];
|
|
10507
|
-
console.log("previewQuoteAmountOut data", [poolId, amountIn, price]);
|
|
10508
10483
|
const quotePoolContract = await getQuotePoolContract(chainId2);
|
|
10509
10484
|
const _gasLimit = await quotePoolContract.previewQuoteAmountOut.estimateGas(poolId, amountIn, price);
|
|
10510
10485
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
@@ -10513,7 +10488,6 @@ var previewQuoteAmountOut = async ({ chainId: chainId2, amountIn, poolId, price
|
|
|
10513
10488
|
gasLimit,
|
|
10514
10489
|
gasPrice
|
|
10515
10490
|
});
|
|
10516
|
-
console.log("previewQuoteAmountOut response", request);
|
|
10517
10491
|
return request;
|
|
10518
10492
|
} catch (error) {
|
|
10519
10493
|
console.error(error);
|
|
@@ -10581,7 +10555,6 @@ var deposit2 = async (params) => {
|
|
|
10581
10555
|
recipient: account,
|
|
10582
10556
|
tpslParams
|
|
10583
10557
|
};
|
|
10584
|
-
console.log("deposit params: price, data, value :", price, data, value);
|
|
10585
10558
|
const contract = await getLiquidityRouterContract(chainId2);
|
|
10586
10559
|
const _gasLimit = await contract["depositQuote((bytes32,uint8,uint256,bytes,uint64)[],(bytes32,uint256,uint256,address,(uint256,uint256,uint8,uint256)[]))"].estimateGas(price, data, { value });
|
|
10587
10560
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
@@ -10591,7 +10564,6 @@ var deposit2 = async (params) => {
|
|
|
10591
10564
|
gasPrice,
|
|
10592
10565
|
value
|
|
10593
10566
|
});
|
|
10594
|
-
console.log("deposit", result);
|
|
10595
10567
|
return result;
|
|
10596
10568
|
} catch (error) {
|
|
10597
10569
|
console.error(error);
|
|
@@ -10644,7 +10616,6 @@ var withdraw2 = async (params) => {
|
|
|
10644
10616
|
// todo 调合约获取
|
|
10645
10617
|
recipient: account
|
|
10646
10618
|
};
|
|
10647
|
-
console.log("withdraw", data);
|
|
10648
10619
|
const contract = await getLiquidityRouterContract(chainId2);
|
|
10649
10620
|
const _gasLimit = await contract["withdrawQuote((bytes32,uint8,uint256,bytes,uint64)[],(bytes32,uint256,uint256,address))"].estimateGas(price, data, { value });
|
|
10650
10621
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
@@ -10654,9 +10625,7 @@ var withdraw2 = async (params) => {
|
|
|
10654
10625
|
gasPrice,
|
|
10655
10626
|
value
|
|
10656
10627
|
});
|
|
10657
|
-
console.log("withdraw quote with price", request);
|
|
10658
10628
|
const receipt = await request?.wait();
|
|
10659
|
-
console.log("withdraw quote receipt", receipt);
|
|
10660
10629
|
return receipt;
|
|
10661
10630
|
} catch (error) {
|
|
10662
10631
|
console.error(error);
|
|
@@ -10684,7 +10653,6 @@ var transfer = async (chainId2, fromPoolId, toPoolId, amount) => {
|
|
|
10684
10653
|
minLpOut: 0n,
|
|
10685
10654
|
amount: (0, import_ethers17.parseUnits)(amount.toString(), decimals)
|
|
10686
10655
|
};
|
|
10687
|
-
console.log("migrateLiquiditydata", data);
|
|
10688
10656
|
const contract = await getLiquidityRouterContract(chainId2);
|
|
10689
10657
|
const _gasLimit = await contract.migrateLiquidity.estimateGas(data);
|
|
10690
10658
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
@@ -10693,7 +10661,6 @@ var transfer = async (chainId2, fromPoolId, toPoolId, amount) => {
|
|
|
10693
10661
|
gasLimit,
|
|
10694
10662
|
gasPrice
|
|
10695
10663
|
});
|
|
10696
|
-
console.log("migrateLiquidity", result);
|
|
10697
10664
|
return result;
|
|
10698
10665
|
} catch (error) {
|
|
10699
10666
|
throw typeof error === "string" ? error : await getErrorTextFormError(error);
|
|
@@ -10710,7 +10677,6 @@ var getRewards2 = async (params) => {
|
|
|
10710
10677
|
const priceResponse = await getOraclePrice(chainId2, [poolId]);
|
|
10711
10678
|
const _price = priceResponse.data?.[0]?.price || "0";
|
|
10712
10679
|
const price = (0, import_ethers18.parseUnits)(_price, COMMON_PRICE_DECIMALS);
|
|
10713
|
-
console.log("pendingUserRebates quote data", [poolId, account, price]);
|
|
10714
10680
|
const contract = await getQuotePoolContract(chainId2);
|
|
10715
10681
|
const _gasLimit = await contract.pendingUserRebates.estimateGas(poolId, account, price);
|
|
10716
10682
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
@@ -10719,7 +10685,6 @@ var getRewards2 = async (params) => {
|
|
|
10719
10685
|
gasLimit,
|
|
10720
10686
|
gasPrice
|
|
10721
10687
|
});
|
|
10722
|
-
console.log("pendingUserRebates quote result:", request);
|
|
10723
10688
|
return request;
|
|
10724
10689
|
} catch (error) {
|
|
10725
10690
|
console.error(error);
|
|
@@ -10760,7 +10725,6 @@ var claimQuotePoolRebate = async (params) => {
|
|
|
10760
10725
|
recipient: account
|
|
10761
10726
|
};
|
|
10762
10727
|
const contract = await getLiquidityRouterContract(chainId2);
|
|
10763
|
-
console.log("quote claim params", data);
|
|
10764
10728
|
const _gasLimit = await contract["claimQuotePoolRebate((bytes32,uint8,uint256,bytes,uint64)[],bytes32,address)"].estimateGas(prices, poolId, account, {
|
|
10765
10729
|
value: values[0]
|
|
10766
10730
|
});
|
|
@@ -10771,7 +10735,6 @@ var claimQuotePoolRebate = async (params) => {
|
|
|
10771
10735
|
gasPrice,
|
|
10772
10736
|
value: values[0]
|
|
10773
10737
|
});
|
|
10774
|
-
console.log("quote claim", response);
|
|
10775
10738
|
return response;
|
|
10776
10739
|
} catch (error) {
|
|
10777
10740
|
console.error(error);
|
|
@@ -10808,7 +10771,6 @@ var claimQuotePoolRebates = async (params) => {
|
|
|
10808
10771
|
poolIds,
|
|
10809
10772
|
recipient: account
|
|
10810
10773
|
};
|
|
10811
|
-
console.log("quote claim Rebates params", data);
|
|
10812
10774
|
const contract = await getLiquidityRouterContract(chainId2);
|
|
10813
10775
|
const _gasLimit = await contract["claimQuotePoolRebates((bytes32,uint8,uint256,bytes,uint64)[],bytes32[],address)"].estimateGas(prices, poolIds, account, {
|
|
10814
10776
|
value
|
|
@@ -10820,7 +10782,6 @@ var claimQuotePoolRebates = async (params) => {
|
|
|
10820
10782
|
gasPrice,
|
|
10821
10783
|
value
|
|
10822
10784
|
});
|
|
10823
|
-
console.log("quote claim rebates", response);
|
|
10824
10785
|
return response;
|
|
10825
10786
|
} catch (error) {
|
|
10826
10787
|
console.error(error);
|
|
@@ -10843,7 +10804,6 @@ var getLpPrice2 = async (chainId2, poolId) => {
|
|
|
10843
10804
|
}
|
|
10844
10805
|
}
|
|
10845
10806
|
const data = await contract.getPoolTokenPrice(poolId, price);
|
|
10846
|
-
console.log(`pool ${poolId} price: `, data);
|
|
10847
10807
|
return data;
|
|
10848
10808
|
} catch (error) {
|
|
10849
10809
|
console.error(error);
|
|
@@ -10885,7 +10845,7 @@ var getMarketPoolId = async ({
|
|
|
10885
10845
|
const chainInfo = CHAIN_INFO[chainId2];
|
|
10886
10846
|
const addresses = address_default[chainId2];
|
|
10887
10847
|
const address = addresses.POOL_MANAGER;
|
|
10888
|
-
const contract = await getPoolManagerContract(chainId2);
|
|
10848
|
+
const contract = await getPoolManagerContract(chainId2, 0 /* JSON */);
|
|
10889
10849
|
const data = [marketId2, baseToken];
|
|
10890
10850
|
const request = await contract.getMarketPool(marketId2, baseToken);
|
|
10891
10851
|
return request.poolId === "0x0000000000000000000000000000000000000000000000000000000000000000" || !request.poolId ? void 0 : request.poolId;
|
|
@@ -10984,7 +10944,6 @@ var getUserGenesisShare = async (chainId2, tokenAddress, account) => {
|
|
|
10984
10944
|
try {
|
|
10985
10945
|
const contract = await getPoolTokenContract(chainId2, tokenAddress);
|
|
10986
10946
|
const request = await contract.userGenesisShare(account);
|
|
10987
|
-
console.log(`UserGenesisShare : `, request);
|
|
10988
10947
|
return request;
|
|
10989
10948
|
} catch (error) {
|
|
10990
10949
|
console.error(error);
|
|
@@ -11011,19 +10970,14 @@ var addTpSl = async (params) => {
|
|
|
11011
10970
|
poolType: BigInt(poolType),
|
|
11012
10971
|
tpslParams
|
|
11013
10972
|
};
|
|
11014
|
-
console.log("add tpSl params:", data);
|
|
11015
10973
|
const _gasLimit = await contract.addTpsl.estimateGas(data);
|
|
11016
10974
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
11017
|
-
console.log("gasLimit", _gasLimit, gasLimit);
|
|
11018
10975
|
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId2);
|
|
11019
|
-
console.log("gasPrice", gasPrice);
|
|
11020
10976
|
const request = await contract.addTpsl(data, {
|
|
11021
10977
|
gasLimit,
|
|
11022
10978
|
gasPrice
|
|
11023
10979
|
});
|
|
11024
|
-
console.log("addTpsl request", request);
|
|
11025
10980
|
const receipt = await request?.wait();
|
|
11026
|
-
console.log(request);
|
|
11027
10981
|
return receipt;
|
|
11028
10982
|
} catch (error) {
|
|
11029
10983
|
console.error(error);
|
|
@@ -11040,16 +10994,12 @@ var cancelTpSl = async (params) => {
|
|
|
11040
10994
|
const contract = await getLiquidityRouterContract(chainId2);
|
|
11041
10995
|
const _gasLimit = await contract.cancelTpsl.estimateGas(orderId);
|
|
11042
10996
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
11043
|
-
console.log("gasLimit", _gasLimit, gasLimit);
|
|
11044
10997
|
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId2);
|
|
11045
|
-
console.log("gasPrice", gasPrice);
|
|
11046
10998
|
const request = await contract.cancelTpsl(orderId, {
|
|
11047
10999
|
gasLimit,
|
|
11048
11000
|
gasPrice
|
|
11049
11001
|
});
|
|
11050
|
-
console.log("cancelTpSl request", request);
|
|
11051
11002
|
const receipt = await request?.wait();
|
|
11052
|
-
console.log(request);
|
|
11053
11003
|
return receipt;
|
|
11054
11004
|
} catch (error) {
|
|
11055
11005
|
console.error(error);
|
|
@@ -11130,8 +11080,6 @@ var getOracleFee = async (chainId2, marketId2) => {
|
|
|
11130
11080
|
if (!marketId2) return;
|
|
11131
11081
|
const contract = await getMarketManageContract(chainId2);
|
|
11132
11082
|
const request = await contract.getOracleFee(marketId2);
|
|
11133
|
-
console.log("MarketManage.getOracleFee request", request);
|
|
11134
|
-
console.log(request);
|
|
11135
11083
|
return request;
|
|
11136
11084
|
} catch (error) {
|
|
11137
11085
|
console.error(error);
|
|
@@ -11154,7 +11102,6 @@ var reprime = async (chainId2, poolId) => {
|
|
|
11154
11102
|
if (!_amount) {
|
|
11155
11103
|
throw new Error("Invalid Market");
|
|
11156
11104
|
}
|
|
11157
|
-
console.log(Number((0, import_ethers22.formatUnits)(_amount, pool.quoteDecimals)));
|
|
11158
11105
|
await checkParams({
|
|
11159
11106
|
tokenAddress: pool.quoteToken,
|
|
11160
11107
|
contractAddress: address_default[chainId2].ORACLE_RESERVE,
|
|
@@ -11167,13 +11114,9 @@ var reprime = async (chainId2, poolId) => {
|
|
|
11167
11114
|
const contract = await getPoolManagerContract(chainId2);
|
|
11168
11115
|
const _gasLimit = await contract.reprimePool.estimateGas({ poolId });
|
|
11169
11116
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
11170
|
-
console.log("gasLimit", _gasLimit, gasLimit);
|
|
11171
11117
|
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId2);
|
|
11172
|
-
console.log("gasPrice", gasPrice);
|
|
11173
11118
|
const request = await contract.reprimePool({ poolId });
|
|
11174
|
-
console.log("PoolManager.reprimePool request", request);
|
|
11175
11119
|
const receipt = await request?.wait();
|
|
11176
|
-
console.log(receipt);
|
|
11177
11120
|
return receipt;
|
|
11178
11121
|
} catch (error) {
|
|
11179
11122
|
console.error(error);
|
|
@@ -11966,6 +11909,22 @@ var ConfigManager = class {
|
|
|
11966
11909
|
this.validateConfig(mergedConfig);
|
|
11967
11910
|
this.config = mergedConfig;
|
|
11968
11911
|
}
|
|
11912
|
+
clear() {
|
|
11913
|
+
this.accessToken = void 0;
|
|
11914
|
+
this.accessTokenExpiry = void 0;
|
|
11915
|
+
this.config = {
|
|
11916
|
+
...this.config,
|
|
11917
|
+
signer: void 0,
|
|
11918
|
+
getAccessToken: void 0
|
|
11919
|
+
};
|
|
11920
|
+
}
|
|
11921
|
+
auth(params) {
|
|
11922
|
+
this.config = {
|
|
11923
|
+
...this.config,
|
|
11924
|
+
...params
|
|
11925
|
+
};
|
|
11926
|
+
this.validateConfig(this.config);
|
|
11927
|
+
}
|
|
11969
11928
|
validateConfig(config) {
|
|
11970
11929
|
const { isTestnet, chainId: chainId2 } = config;
|
|
11971
11930
|
if (isTestnet) {
|
|
@@ -12382,9 +12341,13 @@ var Position = class {
|
|
|
12382
12341
|
poolId,
|
|
12383
12342
|
positionId,
|
|
12384
12343
|
adjustAmount,
|
|
12385
|
-
quoteToken
|
|
12344
|
+
quoteToken,
|
|
12345
|
+
poolOracleType
|
|
12386
12346
|
}) {
|
|
12387
12347
|
const config = this.configManager.getConfig();
|
|
12348
|
+
if (!config.signer) {
|
|
12349
|
+
throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
|
|
12350
|
+
}
|
|
12388
12351
|
this.logger.debug("adjustCollateral-->", {
|
|
12389
12352
|
poolId,
|
|
12390
12353
|
positionId,
|
|
@@ -12400,7 +12363,8 @@ var Position = class {
|
|
|
12400
12363
|
poolId,
|
|
12401
12364
|
referencePrice: import_ethers24.ethers.parseUnits(priceData?.price ?? "0", 30),
|
|
12402
12365
|
oracleUpdateData: priceData?.vaa ?? "0",
|
|
12403
|
-
publishTime: priceData.publishTime
|
|
12366
|
+
publishTime: priceData.publishTime,
|
|
12367
|
+
oracleType: poolOracleType
|
|
12404
12368
|
};
|
|
12405
12369
|
const contractAddress = getContractAddressByChainId(config.chainId);
|
|
12406
12370
|
if (Number(adjustAmount) > 0) {
|
|
@@ -12461,6 +12425,7 @@ var Position = class {
|
|
|
12461
12425
|
message: "Adjust collateral transaction submitted"
|
|
12462
12426
|
};
|
|
12463
12427
|
} catch (error) {
|
|
12428
|
+
console.log(error, "error");
|
|
12464
12429
|
const errorMessage = await this.utils.getErrorMessage(error);
|
|
12465
12430
|
this.logger.error("adjustCollateral error-->", errorMessage);
|
|
12466
12431
|
return {
|
|
@@ -12537,6 +12502,9 @@ var Order = class {
|
|
|
12537
12502
|
async createIncreaseOrder(params) {
|
|
12538
12503
|
try {
|
|
12539
12504
|
const config = this.configManager.getConfig();
|
|
12505
|
+
if (!config.signer) {
|
|
12506
|
+
throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
|
|
12507
|
+
}
|
|
12540
12508
|
const brokerContract = await getBrokerSingerContract(
|
|
12541
12509
|
params.chainId,
|
|
12542
12510
|
config.signer
|
|
@@ -12653,6 +12621,9 @@ var Order = class {
|
|
|
12653
12621
|
async createDecreaseOrder(params) {
|
|
12654
12622
|
try {
|
|
12655
12623
|
const config = this.configManager.getConfig();
|
|
12624
|
+
if (!config.signer) {
|
|
12625
|
+
throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
|
|
12626
|
+
}
|
|
12656
12627
|
const brokerContract = await getBrokerSingerContract(
|
|
12657
12628
|
params.chainId,
|
|
12658
12629
|
config.signer
|
|
@@ -12765,6 +12736,9 @@ var Order = class {
|
|
|
12765
12736
|
async createPositionTpSlOrder(params) {
|
|
12766
12737
|
try {
|
|
12767
12738
|
const config = this.configManager.getConfig();
|
|
12739
|
+
if (!config.signer) {
|
|
12740
|
+
throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
|
|
12741
|
+
}
|
|
12768
12742
|
const brokerContract = await getBrokerSingerContract(
|
|
12769
12743
|
params.chainId,
|
|
12770
12744
|
config.signer
|
|
@@ -12929,6 +12903,9 @@ var Order = class {
|
|
|
12929
12903
|
async cancelOrder(orderId) {
|
|
12930
12904
|
try {
|
|
12931
12905
|
const config = this.configManager.getConfig();
|
|
12906
|
+
if (!config.signer) {
|
|
12907
|
+
throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
|
|
12908
|
+
}
|
|
12932
12909
|
const brokerContract = await getBrokerSingerContract(
|
|
12933
12910
|
config.chainId,
|
|
12934
12911
|
config.signer
|
|
@@ -12950,6 +12927,9 @@ var Order = class {
|
|
|
12950
12927
|
async cancelOrders(orderIds) {
|
|
12951
12928
|
try {
|
|
12952
12929
|
const config = this.configManager.getConfig();
|
|
12930
|
+
if (!config.signer) {
|
|
12931
|
+
throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
|
|
12932
|
+
}
|
|
12953
12933
|
const brokerContract = await getBrokerSingerContract(
|
|
12954
12934
|
config.chainId,
|
|
12955
12935
|
config.signer
|
|
@@ -12971,6 +12951,9 @@ var Order = class {
|
|
|
12971
12951
|
}
|
|
12972
12952
|
async updateOrderTpSl(params) {
|
|
12973
12953
|
const config = this.configManager.getConfig();
|
|
12954
|
+
if (!config.signer) {
|
|
12955
|
+
throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
|
|
12956
|
+
}
|
|
12974
12957
|
console.log("updateOrderTpSl params", params);
|
|
12975
12958
|
const brokerContract = await getBrokerSingerContract(
|
|
12976
12959
|
config.chainId,
|
|
@@ -16781,6 +16764,12 @@ var Utils = class {
|
|
|
16781
16764
|
"function allowance(address owner, address spender) external view returns (uint256)"
|
|
16782
16765
|
];
|
|
16783
16766
|
const config = this.configManager.getConfig();
|
|
16767
|
+
if (!config.signer) {
|
|
16768
|
+
throw new MyxSDKError(
|
|
16769
|
+
"INVALID_SIGNER" /* InvalidSigner */,
|
|
16770
|
+
"Invalid signer"
|
|
16771
|
+
);
|
|
16772
|
+
}
|
|
16784
16773
|
const owner = await config.signer.getAddress();
|
|
16785
16774
|
const spender = spenderAddress ?? getContractAddressByChainId(config.chainId).ORDER_MANAGER;
|
|
16786
16775
|
const tokenContract = new import_ethers25.ethers.Contract(
|
|
@@ -18091,6 +18080,12 @@ var Account = class {
|
|
|
18091
18080
|
}
|
|
18092
18081
|
async getWalletQuoteTokenBalance() {
|
|
18093
18082
|
const config = this.configManager.getConfig();
|
|
18083
|
+
if (!config.signer) {
|
|
18084
|
+
throw new MyxSDKError(
|
|
18085
|
+
"INVALID_SIGNER" /* InvalidSigner */,
|
|
18086
|
+
"Invalid signer"
|
|
18087
|
+
);
|
|
18088
|
+
}
|
|
18094
18089
|
const contractAddress = getContractAddressByChainId(config.chainId);
|
|
18095
18090
|
const erc20Contract = new import_ethers26.ethers.Contract(
|
|
18096
18091
|
contractAddress.ERC20,
|
|
@@ -18108,6 +18103,12 @@ var Account = class {
|
|
|
18108
18103
|
*/
|
|
18109
18104
|
async getTradableAmount({ poolId }) {
|
|
18110
18105
|
const config = this.configManager.getConfig();
|
|
18106
|
+
if (!config.signer) {
|
|
18107
|
+
throw new MyxSDKError(
|
|
18108
|
+
"INVALID_SIGNER" /* InvalidSigner */,
|
|
18109
|
+
"Invalid signer"
|
|
18110
|
+
);
|
|
18111
|
+
}
|
|
18111
18112
|
const contractAddress = getContractAddressByChainId(config.chainId);
|
|
18112
18113
|
const accountContract = new import_ethers26.ethers.Contract(
|
|
18113
18114
|
contractAddress.Account,
|
|
@@ -18148,7 +18149,6 @@ var Account = class {
|
|
|
18148
18149
|
};
|
|
18149
18150
|
|
|
18150
18151
|
// src/manager/index.ts
|
|
18151
|
-
var import_ethers27 = require("ethers");
|
|
18152
18152
|
var MyxClient = class {
|
|
18153
18153
|
/**
|
|
18154
18154
|
* 获取配置管理器(用于访问 accessToken 相关方法)
|
|
@@ -18168,20 +18168,28 @@ var MyxClient = class {
|
|
|
18168
18168
|
this.account = new Account(this.configManager, this.logger, this.utils);
|
|
18169
18169
|
this.subscription = new SubScription(this.configManager, this.logger);
|
|
18170
18170
|
const lp = MxSDK.getInstance();
|
|
18171
|
-
if (options.walletClient?.transport) {
|
|
18172
|
-
const provider = new import_ethers27.BrowserProvider(options.walletClient?.transport);
|
|
18173
|
-
if (provider) {
|
|
18174
|
-
lp.setProvider(provider);
|
|
18175
|
-
}
|
|
18176
|
-
}
|
|
18177
18171
|
lp.setConfigManager(this.configManager);
|
|
18178
18172
|
}
|
|
18173
|
+
/**
|
|
18174
|
+
* auth the client
|
|
18175
|
+
*/
|
|
18176
|
+
auth(params) {
|
|
18177
|
+
this.configManager.auth(params);
|
|
18178
|
+
}
|
|
18179
|
+
/**
|
|
18180
|
+
* close the client
|
|
18181
|
+
*/
|
|
18182
|
+
close() {
|
|
18183
|
+
this.configManager.clear();
|
|
18184
|
+
this.subscription.disconnect();
|
|
18185
|
+
}
|
|
18179
18186
|
};
|
|
18180
18187
|
// Annotate the CommonJS export names for ESM import in node:
|
|
18181
18188
|
0 && (module.exports = {
|
|
18182
18189
|
COMMON_LP_AMOUNT_DECIMALS,
|
|
18183
18190
|
COMMON_PRICE_DECIMALS,
|
|
18184
18191
|
ChainId,
|
|
18192
|
+
CloseTypeEnum,
|
|
18185
18193
|
Direction,
|
|
18186
18194
|
DirectionEnum,
|
|
18187
18195
|
ErrorCode,
|