@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.mjs CHANGED
@@ -1416,6 +1416,7 @@ var address_default = {
1416
1416
 
1417
1417
  // src/web3/index.ts
1418
1418
  import {
1419
+ BrowserProvider,
1419
1420
  Contract,
1420
1421
  ethers,
1421
1422
  JsonRpcProvider,
@@ -1741,7 +1742,7 @@ var RotationProvider = class extends BaseProvider {
1741
1742
  // package.json
1742
1743
  var package_default = {
1743
1744
  name: "@myx-trade/sdk",
1744
- version: "0.1.17",
1745
+ version: "0.1.19",
1745
1746
  private: false,
1746
1747
  publishConfig: {
1747
1748
  access: "public"
@@ -1872,17 +1873,10 @@ if (typeof window !== "undefined") {
1872
1873
  }
1873
1874
  var getWalletProvider = async (chainId2) => {
1874
1875
  try {
1875
- const provider = sdk.provider;
1876
+ const walletClient = sdk.getConfigManager()?.getConfig().walletClient;
1877
+ const provider = new BrowserProvider(walletClient?.transport);
1876
1878
  if (!provider) {
1877
- throw new Error("Provider missing in provider");
1878
- }
1879
- if (chainId2) {
1880
- const network = await provider.getNetwork();
1881
- console.log(provider);
1882
- console.log(`Connected to chain: ${network.chainId}, requested: ${chainId2}`);
1883
- if (Number(network.chainId) !== chainId2) {
1884
- await provider.send("wallet_switchEthereumChain", [{ chainId: BigInt(chainId2) }]);
1885
- }
1879
+ throw new Error("missing provider");
1886
1880
  }
1887
1881
  return provider;
1888
1882
  } catch (error) {
@@ -1892,7 +1886,6 @@ var getWalletProvider = async (chainId2) => {
1892
1886
  };
1893
1887
  var getSignerProvider = async (chainId2) => {
1894
1888
  const provider = await getWalletProvider(chainId2);
1895
- console.log(provider);
1896
1889
  return provider?.getSigner?.();
1897
1890
  };
1898
1891
 
@@ -9099,10 +9092,10 @@ var getLiquidityRouterContract = async (chainId2) => {
9099
9092
  const provider = await getSignerProvider(chainId2);
9100
9093
  return getContract(address, LiquidityRouter_default, provider);
9101
9094
  };
9102
- var getPoolManagerContract = async (chainId2) => {
9095
+ var getPoolManagerContract = async (chainId2, type = 1 /* Signer */) => {
9103
9096
  const addresses = address_default[chainId2];
9104
9097
  const address = addresses.POOL_MANAGER;
9105
- const provider = await getSignerProvider(chainId2);
9098
+ const provider = type === 0 /* JSON */ ? getJSONProvider(chainId2) : await getSignerProvider(chainId2);
9106
9099
  return getContract(address, PoolManager_default, provider);
9107
9100
  };
9108
9101
  var getQuotePoolContract = async (chainId2, type = 0 /* JSON */) => {
@@ -9410,18 +9403,13 @@ var getAllowanceApproved = async (chainId2, account, tokenAddress, approveAddres
9410
9403
  const provider = getJSONProvider(chainId2);
9411
9404
  const contractInterface = new ethers3.Interface(IERC20Metadata_default);
9412
9405
  const data = contractInterface.encodeFunctionData("allowance", [account, approveAddress]);
9413
- console.log("approve token ", tokenAddress);
9414
- console.log("approve address ", approveAddress);
9415
9406
  const callData = {
9416
9407
  to: tokenAddress,
9417
9408
  data
9418
9409
  };
9419
9410
  const result = await provider.call(callData);
9420
9411
  const allowance = BigInt(result);
9421
- console.log("Allowance:", allowance.toString());
9422
- console.log("ApproveAmount:", approveAmount.toString());
9423
9412
  if (allowance >= approveAmount) {
9424
- console.log("Allowance approved.");
9425
9413
  return true;
9426
9414
  }
9427
9415
  return false;
@@ -9434,10 +9422,7 @@ var getAllowanceApproved = async (chainId2, account, tokenAddress, approveAddres
9434
9422
  var approve = async (chainId2, account, tokenAddress, approveAddress, amount) => {
9435
9423
  try {
9436
9424
  const TokenContract = await getERC20Contract(chainId2, tokenAddress);
9437
- console.log("approve token Address", tokenAddress);
9438
9425
  const response = await TokenContract.approve(approveAddress, amount);
9439
- console.log("approve amount", approveAddress);
9440
- console.log("approve amount", amount);
9441
9426
  const receipt = await response?.wait();
9442
9427
  const isApproved = await getAllowanceApproved(chainId2, account, tokenAddress, approveAddress, amount);
9443
9428
  if (!isApproved) {
@@ -9466,13 +9451,11 @@ var checkParams = async (params) => {
9466
9451
  throw new Error(Errors[4004 /* Invalid_Amount */]);
9467
9452
  }
9468
9453
  }
9469
- console.log("checkbalance");
9470
9454
  const { tokenAddress, contractAddress, chainId: chainId2, amount, decimals, account } = params;
9471
9455
  if (amount && chainId2 && decimals && account) {
9472
9456
  const amountIn = parseUnits2(amount.toString(), decimals);
9473
9457
  if (tokenAddress) {
9474
9458
  const balance = await getBalanceOf(chainId2, account, tokenAddress);
9475
- console.log("balance", balance, tokenAddress);
9476
9459
  if (!balance || balance < amountIn) {
9477
9460
  throw new Error(Errors[3 /* Insufficient_Balance */]);
9478
9461
  }
@@ -9506,9 +9489,7 @@ var bigintTradingGasPriceWithRatio = async (chainId2) => {
9506
9489
  if (!gasPrice) {
9507
9490
  throw new Error("Network Error");
9508
9491
  }
9509
- console.log("gasPrice", gasPrice);
9510
9492
  const gasPriceWithRatio = bigintTradingGasToRatioCalculator(gasPrice, chainInfo.gasPriceRatio);
9511
- console.log("gasPriceWithRatio--->", gasPriceWithRatio);
9512
9493
  return {
9513
9494
  gasPrice: gasPriceWithRatio
9514
9495
  };
@@ -9609,10 +9590,10 @@ var MarketPoolState = /* @__PURE__ */ ((MarketPoolState3) => {
9609
9590
  MarketPoolState3[MarketPoolState3["Bench"] = 4] = "Bench";
9610
9591
  return MarketPoolState3;
9611
9592
  })(MarketPoolState || {});
9612
- var OracleType = /* @__PURE__ */ ((OracleType6) => {
9613
- OracleType6[OracleType6["Chainlink"] = 1] = "Chainlink";
9614
- OracleType6[OracleType6["Pyth"] = 2] = "Pyth";
9615
- return OracleType6;
9593
+ var OracleType = /* @__PURE__ */ ((OracleType7) => {
9594
+ OracleType7[OracleType7["Chainlink"] = 1] = "Chainlink";
9595
+ OracleType7[OracleType7["Pyth"] = 2] = "Pyth";
9596
+ return OracleType7;
9616
9597
  })(OracleType || {});
9617
9598
  var HttpKlineIntervalEnum = /* @__PURE__ */ ((HttpKlineIntervalEnum2) => {
9618
9599
  HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Minute1"] = 1] = "Minute1";
@@ -9702,6 +9683,19 @@ var getHistoryOrders = async ({
9702
9683
  }
9703
9684
  );
9704
9685
  };
9686
+ var CloseTypeEnum = /* @__PURE__ */ ((CloseTypeEnum2) => {
9687
+ CloseTypeEnum2[CloseTypeEnum2["Open"] = 0] = "Open";
9688
+ CloseTypeEnum2[CloseTypeEnum2["PartialClose"] = 1] = "PartialClose";
9689
+ CloseTypeEnum2[CloseTypeEnum2["FullClose"] = 2] = "FullClose";
9690
+ CloseTypeEnum2[CloseTypeEnum2["Liquidation"] = 3] = "Liquidation";
9691
+ CloseTypeEnum2[CloseTypeEnum2["EarlyClose"] = 4] = "EarlyClose";
9692
+ CloseTypeEnum2[CloseTypeEnum2["MarketClose"] = 5] = "MarketClose";
9693
+ CloseTypeEnum2[CloseTypeEnum2["ADL"] = 6] = "ADL";
9694
+ CloseTypeEnum2[CloseTypeEnum2["TP"] = 7] = "TP";
9695
+ CloseTypeEnum2[CloseTypeEnum2["SL"] = 8] = "SL";
9696
+ CloseTypeEnum2[CloseTypeEnum2["Increase"] = 9] = "Increase";
9697
+ return CloseTypeEnum2;
9698
+ })(CloseTypeEnum || {});
9705
9699
  var getPositionHistory = async ({
9706
9700
  accessToken,
9707
9701
  ...params
@@ -9971,7 +9965,6 @@ var claimBasePoolRebate = async (params) => {
9971
9965
  poolId,
9972
9966
  recipient: account
9973
9967
  };
9974
- console.log("base claim", data);
9975
9968
  const contract = await getLiquidityRouterContract(chainId2);
9976
9969
  const _gasLimit = await contract["claimBasePoolRebate((bytes32,uint8,uint256,bytes,uint64)[],bytes32,address)"].estimateGas(prices, poolId, account, {
9977
9970
  value: values[0]
@@ -9983,7 +9976,6 @@ var claimBasePoolRebate = async (params) => {
9983
9976
  gasPrice,
9984
9977
  value: values[0]
9985
9978
  });
9986
- console.log("base claim", response);
9987
9979
  return response;
9988
9980
  } catch (error) {
9989
9981
  console.error(error);
@@ -10019,7 +10011,6 @@ var claimBasePoolRebates = async (params) => {
10019
10011
  value,
10020
10012
  recipient: account
10021
10013
  };
10022
- console.log("base claim pool rebates", data);
10023
10014
  const contract = await getLiquidityRouterContract(chainId2);
10024
10015
  const _gasLimit = await contract["claimBasePoolRebates((bytes32,uint8,uint256,bytes,uint64)[],bytes32[],address)"].estimateGas(prices, poolIds, account, {
10025
10016
  value
@@ -10031,7 +10022,6 @@ var claimBasePoolRebates = async (params) => {
10031
10022
  gasPrice,
10032
10023
  value
10033
10024
  });
10034
- console.log("base claim rebates", response);
10035
10025
  return response;
10036
10026
  } catch (error) {
10037
10027
  console.error(error);
@@ -10067,7 +10057,6 @@ var Market = {
10067
10057
  var previewLpAmountOut = async ({ chainId: chainId2, amountIn, poolId, price = 0n }) => {
10068
10058
  try {
10069
10059
  const chainInfo = CHAIN_INFO[chainId2];
10070
- console.log("previewLpAmountOut data", [poolId, amountIn, price]);
10071
10060
  const basePoolContract = await getBasePoolContract(chainId2);
10072
10061
  const _gasLimit = await basePoolContract.previewLpAmountOut.estimateGas(poolId, amountIn, price);
10073
10062
  const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
@@ -10076,7 +10065,6 @@ var previewLpAmountOut = async ({ chainId: chainId2, amountIn, poolId, price = 0
10076
10065
  gasLimit,
10077
10066
  gasPrice
10078
10067
  });
10079
- console.log(request);
10080
10068
  return request;
10081
10069
  } catch (error) {
10082
10070
  console.error(error);
@@ -10086,7 +10074,6 @@ var previewLpAmountOut = async ({ chainId: chainId2, amountIn, poolId, price = 0
10086
10074
  var previewBaseAmountOut = async ({ chainId: chainId2, amountIn, poolId, price = 0n }) => {
10087
10075
  try {
10088
10076
  const chainInfo = CHAIN_INFO[chainId2];
10089
- console.log("previewQuoteAmountOut data", [poolId, amountIn, price]);
10090
10077
  const basePoolContract = await getBasePoolContract(chainId2);
10091
10078
  const _gasLimit = await basePoolContract.previewBaseAmountOut.estimateGas(poolId, amountIn, price);
10092
10079
  const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
@@ -10095,7 +10082,6 @@ var previewBaseAmountOut = async ({ chainId: chainId2, amountIn, poolId, price =
10095
10082
  gasLimit,
10096
10083
  gasPrice
10097
10084
  });
10098
- console.log("previewBaseAmountOut response", request);
10099
10085
  return request;
10100
10086
  } catch (error) {
10101
10087
  console.error(error);
@@ -10124,7 +10110,6 @@ var previewUserWithdrawData = async ({ chainId: chainId2, account, poolId, amoun
10124
10110
  const priceResponse = await getOraclePrice(chainId2, [poolId]);
10125
10111
  const _price = priceResponse.data?.[0]?.price || "0";
10126
10112
  const price = parseUnits5(_price, COMMON_PRICE_DECIMALS);
10127
- console.log("previewUserWithdrawData data", [poolId, amountIn, account, price]);
10128
10113
  const basePoolContract = await getBasePoolContract(chainId2);
10129
10114
  const _gasLimit = await basePoolContract.previewUserWithdrawData.estimateGas(poolId, amountIn, account, price);
10130
10115
  const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
@@ -10134,7 +10119,6 @@ var previewUserWithdrawData = async ({ chainId: chainId2, account, poolId, amoun
10134
10119
  gasPrice
10135
10120
  });
10136
10121
  const { baseAmountOut, rebateAmount } = request;
10137
- console.log("previewUserWithdrawData result:", { baseAmountOut, rebateAmount });
10138
10122
  return {
10139
10123
  baseAmountOut,
10140
10124
  rebateAmount
@@ -10250,7 +10234,6 @@ var deposit = async (params) => {
10250
10234
  recipient: account,
10251
10235
  tpslParams
10252
10236
  };
10253
- console.log("deposit base", price, data, value);
10254
10237
  const contract = await getLiquidityRouterContract(chainId2);
10255
10238
  const _gasLimit = await contract["depositBase((bytes32,uint8,uint256,bytes,uint64)[],(bytes32,uint256,uint256,address,(uint256,uint256,uint8,uint256)[]))"].estimateGas(price, data, { value });
10256
10239
  const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
@@ -10260,7 +10243,6 @@ var deposit = async (params) => {
10260
10243
  gasPrice,
10261
10244
  value
10262
10245
  });
10263
- console.log("deposit", result);
10264
10246
  return result;
10265
10247
  } catch (error) {
10266
10248
  console.error(error);
@@ -10322,7 +10304,6 @@ var withdraw = async (params) => {
10322
10304
  value
10323
10305
  });
10324
10306
  const receipt = await response?.wait();
10325
- console.log("base withdraw", response);
10326
10307
  return receipt;
10327
10308
  } catch (error) {
10328
10309
  console.error(error);
@@ -10341,7 +10322,6 @@ var getRewards = async (params) => {
10341
10322
  const priceResponse = await getOraclePrice(chainId2, [poolId]);
10342
10323
  const _price = priceResponse.data?.[0]?.price || "0";
10343
10324
  const price = parseUnits9(_price, COMMON_PRICE_DECIMALS);
10344
- console.log("pendingUserRebates base data:", [poolId, lpAmountIn, account, price]);
10345
10325
  const basePoolContract = await getBasePoolContract(chainId2);
10346
10326
  const _gasLimit = await basePoolContract.pendingUserRebates.estimateGas(poolId, account, price);
10347
10327
  const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
@@ -10350,7 +10330,6 @@ var getRewards = async (params) => {
10350
10330
  gasLimit,
10351
10331
  gasPrice
10352
10332
  });
10353
- console.log("pendingUserRebates base result:", request);
10354
10333
  return request;
10355
10334
  } catch (error) {
10356
10335
  console.error(error);
@@ -10373,7 +10352,6 @@ var getLpPrice = async (chainId2, poolId) => {
10373
10352
  }
10374
10353
  }
10375
10354
  const data = await contract.getPoolTokenPrice(poolId, price);
10376
- console.log(`pool ${poolId} price: `, data);
10377
10355
  return data;
10378
10356
  } catch (error) {
10379
10357
  console.error(error);
@@ -10400,7 +10378,6 @@ import { parseUnits as parseUnits11 } from "ethers";
10400
10378
  var previewLpAmountOut2 = async ({ chainId: chainId2, amountIn, poolId, price = 0n }) => {
10401
10379
  try {
10402
10380
  const chainInfo = CHAIN_INFO[chainId2];
10403
- console.log("previewLpAmountOut data", [poolId, amountIn, price]);
10404
10381
  const quotePoolContract = await getQuotePoolContract(chainId2);
10405
10382
  const _gasLimit = await quotePoolContract.previewLpAmountOut.estimateGas(poolId, amountIn, price);
10406
10383
  const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
@@ -10409,7 +10386,6 @@ var previewLpAmountOut2 = async ({ chainId: chainId2, amountIn, poolId, price =
10409
10386
  gasLimit,
10410
10387
  gasPrice
10411
10388
  });
10412
- console.log(request);
10413
10389
  return request;
10414
10390
  } catch (error) {
10415
10391
  console.error(error);
@@ -10419,7 +10395,6 @@ var previewLpAmountOut2 = async ({ chainId: chainId2, amountIn, poolId, price =
10419
10395
  var previewQuoteAmountOut = async ({ chainId: chainId2, amountIn, poolId, price = 0n }) => {
10420
10396
  try {
10421
10397
  const chainInfo = CHAIN_INFO[chainId2];
10422
- console.log("previewQuoteAmountOut data", [poolId, amountIn, price]);
10423
10398
  const quotePoolContract = await getQuotePoolContract(chainId2);
10424
10399
  const _gasLimit = await quotePoolContract.previewQuoteAmountOut.estimateGas(poolId, amountIn, price);
10425
10400
  const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
@@ -10428,7 +10403,6 @@ var previewQuoteAmountOut = async ({ chainId: chainId2, amountIn, poolId, price
10428
10403
  gasLimit,
10429
10404
  gasPrice
10430
10405
  });
10431
- console.log("previewQuoteAmountOut response", request);
10432
10406
  return request;
10433
10407
  } catch (error) {
10434
10408
  console.error(error);
@@ -10496,7 +10470,6 @@ var deposit2 = async (params) => {
10496
10470
  recipient: account,
10497
10471
  tpslParams
10498
10472
  };
10499
- console.log("deposit params: price, data, value :", price, data, value);
10500
10473
  const contract = await getLiquidityRouterContract(chainId2);
10501
10474
  const _gasLimit = await contract["depositQuote((bytes32,uint8,uint256,bytes,uint64)[],(bytes32,uint256,uint256,address,(uint256,uint256,uint8,uint256)[]))"].estimateGas(price, data, { value });
10502
10475
  const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
@@ -10506,7 +10479,6 @@ var deposit2 = async (params) => {
10506
10479
  gasPrice,
10507
10480
  value
10508
10481
  });
10509
- console.log("deposit", result);
10510
10482
  return result;
10511
10483
  } catch (error) {
10512
10484
  console.error(error);
@@ -10559,7 +10531,6 @@ var withdraw2 = async (params) => {
10559
10531
  // todo 调合约获取
10560
10532
  recipient: account
10561
10533
  };
10562
- console.log("withdraw", data);
10563
10534
  const contract = await getLiquidityRouterContract(chainId2);
10564
10535
  const _gasLimit = await contract["withdrawQuote((bytes32,uint8,uint256,bytes,uint64)[],(bytes32,uint256,uint256,address))"].estimateGas(price, data, { value });
10565
10536
  const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
@@ -10569,9 +10540,7 @@ var withdraw2 = async (params) => {
10569
10540
  gasPrice,
10570
10541
  value
10571
10542
  });
10572
- console.log("withdraw quote with price", request);
10573
10543
  const receipt = await request?.wait();
10574
- console.log("withdraw quote receipt", receipt);
10575
10544
  return receipt;
10576
10545
  } catch (error) {
10577
10546
  console.error(error);
@@ -10599,7 +10568,6 @@ var transfer = async (chainId2, fromPoolId, toPoolId, amount) => {
10599
10568
  minLpOut: 0n,
10600
10569
  amount: parseUnits13(amount.toString(), decimals)
10601
10570
  };
10602
- console.log("migrateLiquiditydata", data);
10603
10571
  const contract = await getLiquidityRouterContract(chainId2);
10604
10572
  const _gasLimit = await contract.migrateLiquidity.estimateGas(data);
10605
10573
  const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
@@ -10608,7 +10576,6 @@ var transfer = async (chainId2, fromPoolId, toPoolId, amount) => {
10608
10576
  gasLimit,
10609
10577
  gasPrice
10610
10578
  });
10611
- console.log("migrateLiquidity", result);
10612
10579
  return result;
10613
10580
  } catch (error) {
10614
10581
  throw typeof error === "string" ? error : await getErrorTextFormError(error);
@@ -10625,7 +10592,6 @@ var getRewards2 = async (params) => {
10625
10592
  const priceResponse = await getOraclePrice(chainId2, [poolId]);
10626
10593
  const _price = priceResponse.data?.[0]?.price || "0";
10627
10594
  const price = parseUnits14(_price, COMMON_PRICE_DECIMALS);
10628
- console.log("pendingUserRebates quote data", [poolId, account, price]);
10629
10595
  const contract = await getQuotePoolContract(chainId2);
10630
10596
  const _gasLimit = await contract.pendingUserRebates.estimateGas(poolId, account, price);
10631
10597
  const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
@@ -10634,7 +10600,6 @@ var getRewards2 = async (params) => {
10634
10600
  gasLimit,
10635
10601
  gasPrice
10636
10602
  });
10637
- console.log("pendingUserRebates quote result:", request);
10638
10603
  return request;
10639
10604
  } catch (error) {
10640
10605
  console.error(error);
@@ -10675,7 +10640,6 @@ var claimQuotePoolRebate = async (params) => {
10675
10640
  recipient: account
10676
10641
  };
10677
10642
  const contract = await getLiquidityRouterContract(chainId2);
10678
- console.log("quote claim params", data);
10679
10643
  const _gasLimit = await contract["claimQuotePoolRebate((bytes32,uint8,uint256,bytes,uint64)[],bytes32,address)"].estimateGas(prices, poolId, account, {
10680
10644
  value: values[0]
10681
10645
  });
@@ -10686,7 +10650,6 @@ var claimQuotePoolRebate = async (params) => {
10686
10650
  gasPrice,
10687
10651
  value: values[0]
10688
10652
  });
10689
- console.log("quote claim", response);
10690
10653
  return response;
10691
10654
  } catch (error) {
10692
10655
  console.error(error);
@@ -10723,7 +10686,6 @@ var claimQuotePoolRebates = async (params) => {
10723
10686
  poolIds,
10724
10687
  recipient: account
10725
10688
  };
10726
- console.log("quote claim Rebates params", data);
10727
10689
  const contract = await getLiquidityRouterContract(chainId2);
10728
10690
  const _gasLimit = await contract["claimQuotePoolRebates((bytes32,uint8,uint256,bytes,uint64)[],bytes32[],address)"].estimateGas(prices, poolIds, account, {
10729
10691
  value
@@ -10735,7 +10697,6 @@ var claimQuotePoolRebates = async (params) => {
10735
10697
  gasPrice,
10736
10698
  value
10737
10699
  });
10738
- console.log("quote claim rebates", response);
10739
10700
  return response;
10740
10701
  } catch (error) {
10741
10702
  console.error(error);
@@ -10758,7 +10719,6 @@ var getLpPrice2 = async (chainId2, poolId) => {
10758
10719
  }
10759
10720
  }
10760
10721
  const data = await contract.getPoolTokenPrice(poolId, price);
10761
- console.log(`pool ${poolId} price: `, data);
10762
10722
  return data;
10763
10723
  } catch (error) {
10764
10724
  console.error(error);
@@ -10800,7 +10760,7 @@ var getMarketPoolId = async ({
10800
10760
  const chainInfo = CHAIN_INFO[chainId2];
10801
10761
  const addresses = address_default[chainId2];
10802
10762
  const address = addresses.POOL_MANAGER;
10803
- const contract = await getPoolManagerContract(chainId2);
10763
+ const contract = await getPoolManagerContract(chainId2, 0 /* JSON */);
10804
10764
  const data = [marketId2, baseToken];
10805
10765
  const request = await contract.getMarketPool(marketId2, baseToken);
10806
10766
  return request.poolId === "0x0000000000000000000000000000000000000000000000000000000000000000" || !request.poolId ? void 0 : request.poolId;
@@ -10899,7 +10859,6 @@ var getUserGenesisShare = async (chainId2, tokenAddress, account) => {
10899
10859
  try {
10900
10860
  const contract = await getPoolTokenContract(chainId2, tokenAddress);
10901
10861
  const request = await contract.userGenesisShare(account);
10902
- console.log(`UserGenesisShare : `, request);
10903
10862
  return request;
10904
10863
  } catch (error) {
10905
10864
  console.error(error);
@@ -10926,19 +10885,14 @@ var addTpSl = async (params) => {
10926
10885
  poolType: BigInt(poolType),
10927
10886
  tpslParams
10928
10887
  };
10929
- console.log("add tpSl params:", data);
10930
10888
  const _gasLimit = await contract.addTpsl.estimateGas(data);
10931
10889
  const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
10932
- console.log("gasLimit", _gasLimit, gasLimit);
10933
10890
  const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId2);
10934
- console.log("gasPrice", gasPrice);
10935
10891
  const request = await contract.addTpsl(data, {
10936
10892
  gasLimit,
10937
10893
  gasPrice
10938
10894
  });
10939
- console.log("addTpsl request", request);
10940
10895
  const receipt = await request?.wait();
10941
- console.log(request);
10942
10896
  return receipt;
10943
10897
  } catch (error) {
10944
10898
  console.error(error);
@@ -10955,16 +10909,12 @@ var cancelTpSl = async (params) => {
10955
10909
  const contract = await getLiquidityRouterContract(chainId2);
10956
10910
  const _gasLimit = await contract.cancelTpsl.estimateGas(orderId);
10957
10911
  const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
10958
- console.log("gasLimit", _gasLimit, gasLimit);
10959
10912
  const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId2);
10960
- console.log("gasPrice", gasPrice);
10961
10913
  const request = await contract.cancelTpsl(orderId, {
10962
10914
  gasLimit,
10963
10915
  gasPrice
10964
10916
  });
10965
- console.log("cancelTpSl request", request);
10966
10917
  const receipt = await request?.wait();
10967
- console.log(request);
10968
10918
  return receipt;
10969
10919
  } catch (error) {
10970
10920
  console.error(error);
@@ -11045,8 +10995,6 @@ var getOracleFee = async (chainId2, marketId2) => {
11045
10995
  if (!marketId2) return;
11046
10996
  const contract = await getMarketManageContract(chainId2);
11047
10997
  const request = await contract.getOracleFee(marketId2);
11048
- console.log("MarketManage.getOracleFee request", request);
11049
- console.log(request);
11050
10998
  return request;
11051
10999
  } catch (error) {
11052
11000
  console.error(error);
@@ -11069,7 +11017,6 @@ var reprime = async (chainId2, poolId) => {
11069
11017
  if (!_amount) {
11070
11018
  throw new Error("Invalid Market");
11071
11019
  }
11072
- console.log(Number(formatUnits(_amount, pool.quoteDecimals)));
11073
11020
  await checkParams({
11074
11021
  tokenAddress: pool.quoteToken,
11075
11022
  contractAddress: address_default[chainId2].ORACLE_RESERVE,
@@ -11082,13 +11029,9 @@ var reprime = async (chainId2, poolId) => {
11082
11029
  const contract = await getPoolManagerContract(chainId2);
11083
11030
  const _gasLimit = await contract.reprimePool.estimateGas({ poolId });
11084
11031
  const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
11085
- console.log("gasLimit", _gasLimit, gasLimit);
11086
11032
  const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId2);
11087
- console.log("gasPrice", gasPrice);
11088
11033
  const request = await contract.reprimePool({ poolId });
11089
- console.log("PoolManager.reprimePool request", request);
11090
11034
  const receipt = await request?.wait();
11091
- console.log(receipt);
11092
11035
  return receipt;
11093
11036
  } catch (error) {
11094
11037
  console.error(error);
@@ -11881,6 +11824,22 @@ var ConfigManager = class {
11881
11824
  this.validateConfig(mergedConfig);
11882
11825
  this.config = mergedConfig;
11883
11826
  }
11827
+ clear() {
11828
+ this.accessToken = void 0;
11829
+ this.accessTokenExpiry = void 0;
11830
+ this.config = {
11831
+ ...this.config,
11832
+ signer: void 0,
11833
+ getAccessToken: void 0
11834
+ };
11835
+ }
11836
+ auth(params) {
11837
+ this.config = {
11838
+ ...this.config,
11839
+ ...params
11840
+ };
11841
+ this.validateConfig(this.config);
11842
+ }
11884
11843
  validateConfig(config) {
11885
11844
  const { isTestnet, chainId: chainId2 } = config;
11886
11845
  if (isTestnet) {
@@ -12297,9 +12256,13 @@ var Position = class {
12297
12256
  poolId,
12298
12257
  positionId,
12299
12258
  adjustAmount,
12300
- quoteToken
12259
+ quoteToken,
12260
+ poolOracleType
12301
12261
  }) {
12302
12262
  const config = this.configManager.getConfig();
12263
+ if (!config.signer) {
12264
+ throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
12265
+ }
12303
12266
  this.logger.debug("adjustCollateral-->", {
12304
12267
  poolId,
12305
12268
  positionId,
@@ -12315,7 +12278,8 @@ var Position = class {
12315
12278
  poolId,
12316
12279
  referencePrice: ethers5.parseUnits(priceData?.price ?? "0", 30),
12317
12280
  oracleUpdateData: priceData?.vaa ?? "0",
12318
- publishTime: priceData.publishTime
12281
+ publishTime: priceData.publishTime,
12282
+ oracleType: poolOracleType
12319
12283
  };
12320
12284
  const contractAddress = getContractAddressByChainId(config.chainId);
12321
12285
  if (Number(adjustAmount) > 0) {
@@ -12376,6 +12340,7 @@ var Position = class {
12376
12340
  message: "Adjust collateral transaction submitted"
12377
12341
  };
12378
12342
  } catch (error) {
12343
+ console.log(error, "error");
12379
12344
  const errorMessage = await this.utils.getErrorMessage(error);
12380
12345
  this.logger.error("adjustCollateral error-->", errorMessage);
12381
12346
  return {
@@ -12452,6 +12417,9 @@ var Order = class {
12452
12417
  async createIncreaseOrder(params) {
12453
12418
  try {
12454
12419
  const config = this.configManager.getConfig();
12420
+ if (!config.signer) {
12421
+ throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
12422
+ }
12455
12423
  const brokerContract = await getBrokerSingerContract(
12456
12424
  params.chainId,
12457
12425
  config.signer
@@ -12568,6 +12536,9 @@ var Order = class {
12568
12536
  async createDecreaseOrder(params) {
12569
12537
  try {
12570
12538
  const config = this.configManager.getConfig();
12539
+ if (!config.signer) {
12540
+ throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
12541
+ }
12571
12542
  const brokerContract = await getBrokerSingerContract(
12572
12543
  params.chainId,
12573
12544
  config.signer
@@ -12680,6 +12651,9 @@ var Order = class {
12680
12651
  async createPositionTpSlOrder(params) {
12681
12652
  try {
12682
12653
  const config = this.configManager.getConfig();
12654
+ if (!config.signer) {
12655
+ throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
12656
+ }
12683
12657
  const brokerContract = await getBrokerSingerContract(
12684
12658
  params.chainId,
12685
12659
  config.signer
@@ -12844,6 +12818,9 @@ var Order = class {
12844
12818
  async cancelOrder(orderId) {
12845
12819
  try {
12846
12820
  const config = this.configManager.getConfig();
12821
+ if (!config.signer) {
12822
+ throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
12823
+ }
12847
12824
  const brokerContract = await getBrokerSingerContract(
12848
12825
  config.chainId,
12849
12826
  config.signer
@@ -12865,6 +12842,9 @@ var Order = class {
12865
12842
  async cancelOrders(orderIds) {
12866
12843
  try {
12867
12844
  const config = this.configManager.getConfig();
12845
+ if (!config.signer) {
12846
+ throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
12847
+ }
12868
12848
  const brokerContract = await getBrokerSingerContract(
12869
12849
  config.chainId,
12870
12850
  config.signer
@@ -12886,6 +12866,9 @@ var Order = class {
12886
12866
  }
12887
12867
  async updateOrderTpSl(params) {
12888
12868
  const config = this.configManager.getConfig();
12869
+ if (!config.signer) {
12870
+ throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
12871
+ }
12889
12872
  console.log("updateOrderTpSl params", params);
12890
12873
  const brokerContract = await getBrokerSingerContract(
12891
12874
  config.chainId,
@@ -16696,6 +16679,12 @@ var Utils = class {
16696
16679
  "function allowance(address owner, address spender) external view returns (uint256)"
16697
16680
  ];
16698
16681
  const config = this.configManager.getConfig();
16682
+ if (!config.signer) {
16683
+ throw new MyxSDKError(
16684
+ "INVALID_SIGNER" /* InvalidSigner */,
16685
+ "Invalid signer"
16686
+ );
16687
+ }
16699
16688
  const owner = await config.signer.getAddress();
16700
16689
  const spender = spenderAddress ?? getContractAddressByChainId(config.chainId).ORDER_MANAGER;
16701
16690
  const tokenContract = new ethers6.Contract(
@@ -18006,6 +17995,12 @@ var Account = class {
18006
17995
  }
18007
17996
  async getWalletQuoteTokenBalance() {
18008
17997
  const config = this.configManager.getConfig();
17998
+ if (!config.signer) {
17999
+ throw new MyxSDKError(
18000
+ "INVALID_SIGNER" /* InvalidSigner */,
18001
+ "Invalid signer"
18002
+ );
18003
+ }
18009
18004
  const contractAddress = getContractAddressByChainId(config.chainId);
18010
18005
  const erc20Contract = new ethers7.Contract(
18011
18006
  contractAddress.ERC20,
@@ -18023,6 +18018,12 @@ var Account = class {
18023
18018
  */
18024
18019
  async getTradableAmount({ poolId }) {
18025
18020
  const config = this.configManager.getConfig();
18021
+ if (!config.signer) {
18022
+ throw new MyxSDKError(
18023
+ "INVALID_SIGNER" /* InvalidSigner */,
18024
+ "Invalid signer"
18025
+ );
18026
+ }
18026
18027
  const contractAddress = getContractAddressByChainId(config.chainId);
18027
18028
  const accountContract = new ethers7.Contract(
18028
18029
  contractAddress.Account,
@@ -18063,7 +18064,6 @@ var Account = class {
18063
18064
  };
18064
18065
 
18065
18066
  // src/manager/index.ts
18066
- import { BrowserProvider as BrowserProvider2 } from "ethers";
18067
18067
  var MyxClient = class {
18068
18068
  /**
18069
18069
  * 获取配置管理器(用于访问 accessToken 相关方法)
@@ -18083,19 +18083,27 @@ var MyxClient = class {
18083
18083
  this.account = new Account(this.configManager, this.logger, this.utils);
18084
18084
  this.subscription = new SubScription(this.configManager, this.logger);
18085
18085
  const lp = MxSDK.getInstance();
18086
- if (options.walletClient?.transport) {
18087
- const provider = new BrowserProvider2(options.walletClient?.transport);
18088
- if (provider) {
18089
- lp.setProvider(provider);
18090
- }
18091
- }
18092
18086
  lp.setConfigManager(this.configManager);
18093
18087
  }
18088
+ /**
18089
+ * auth the client
18090
+ */
18091
+ auth(params) {
18092
+ this.configManager.auth(params);
18093
+ }
18094
+ /**
18095
+ * close the client
18096
+ */
18097
+ close() {
18098
+ this.configManager.clear();
18099
+ this.subscription.disconnect();
18100
+ }
18094
18101
  };
18095
18102
  export {
18096
18103
  COMMON_LP_AMOUNT_DECIMALS,
18097
18104
  COMMON_PRICE_DECIMALS,
18098
18105
  ChainId,
18106
+ CloseTypeEnum,
18099
18107
  Direction,
18100
18108
  DirectionEnum,
18101
18109
  ErrorCode2 as ErrorCode,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myx-trade/sdk",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"