@myx-trade/sdk 0.1.19 → 0.1.21

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as ethers from 'ethers';
2
- import { ZeroAddress, AddressLike, Signer } from 'ethers';
2
+ import { ZeroAddress, AddressLike, Signer, ethers as ethers$1 } from 'ethers';
3
3
  export { formatUnits, parseUnits } from 'ethers';
4
4
  import { Options, Event } from 'reconnecting-websocket';
5
5
  import { WalletClient } from 'viem';
@@ -1420,7 +1420,7 @@ declare class Order {
1420
1420
  status: string;
1421
1421
  confirmations: number;
1422
1422
  timestamp: number;
1423
- receipt: ethers.ContractTransactionReceipt | null;
1423
+ receipt: ethers$1.ContractTransactionReceipt | null;
1424
1424
  };
1425
1425
  } | {
1426
1426
  code: number;
@@ -1439,7 +1439,7 @@ declare class Order {
1439
1439
  status: string;
1440
1440
  confirmations: number;
1441
1441
  timestamp: number;
1442
- receipt: ethers.ContractTransactionReceipt | null;
1442
+ receipt: ethers$1.ContractTransactionReceipt | null;
1443
1443
  };
1444
1444
  } | {
1445
1445
  code: number;
@@ -1458,7 +1458,7 @@ declare class Order {
1458
1458
  status: string;
1459
1459
  confirmations: number;
1460
1460
  timestamp: number;
1461
- receipt: ethers.ContractTransactionReceipt | null;
1461
+ receipt: ethers$1.ContractTransactionReceipt | null;
1462
1462
  };
1463
1463
  } | {
1464
1464
  code: number;
@@ -1473,7 +1473,7 @@ declare class Order {
1473
1473
  code: number;
1474
1474
  message: any;
1475
1475
  }>;
1476
- updateOrderTpSl(params: UpdateOrderParams): Promise<ethers.ContractTransactionReceipt | {
1476
+ updateOrderTpSl(params: UpdateOrderParams): Promise<ethers$1.ContractTransactionReceipt | {
1477
1477
  code: number;
1478
1478
  message: string;
1479
1479
  } | null>;
@@ -1521,6 +1521,30 @@ declare class Account {
1521
1521
  code: number;
1522
1522
  data: TradeFlowItem[];
1523
1523
  }>;
1524
+ withdraw({ poolId, amount }: {
1525
+ poolId: string;
1526
+ amount: string;
1527
+ }): Promise<{
1528
+ code: number;
1529
+ data: any;
1530
+ message?: undefined;
1531
+ } | {
1532
+ code: number;
1533
+ message: string;
1534
+ data?: undefined;
1535
+ }>;
1536
+ deposit({ poolId, amount }: {
1537
+ poolId: string;
1538
+ amount: string;
1539
+ }): Promise<{
1540
+ code: number;
1541
+ data: any;
1542
+ message?: undefined;
1543
+ } | {
1544
+ code: number;
1545
+ message: string;
1546
+ data?: undefined;
1547
+ }>;
1524
1548
  }
1525
1549
 
1526
1550
  declare class MyxClient {
@@ -1546,7 +1570,7 @@ declare class MyxClient {
1546
1570
  /**
1547
1571
  * auth the client
1548
1572
  */
1549
- auth(params: Pick<MyxClientConfig, "signer" | "getAccessToken" | "walletClient">): void;
1573
+ auth(params: Required<Pick<MyxClientConfig, "signer" | "getAccessToken" | "walletClient">>): void;
1550
1574
  /**
1551
1575
  * close the client
1552
1576
  */
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as ethers from 'ethers';
2
- import { ZeroAddress, AddressLike, Signer } from 'ethers';
2
+ import { ZeroAddress, AddressLike, Signer, ethers as ethers$1 } from 'ethers';
3
3
  export { formatUnits, parseUnits } from 'ethers';
4
4
  import { Options, Event } from 'reconnecting-websocket';
5
5
  import { WalletClient } from 'viem';
@@ -1420,7 +1420,7 @@ declare class Order {
1420
1420
  status: string;
1421
1421
  confirmations: number;
1422
1422
  timestamp: number;
1423
- receipt: ethers.ContractTransactionReceipt | null;
1423
+ receipt: ethers$1.ContractTransactionReceipt | null;
1424
1424
  };
1425
1425
  } | {
1426
1426
  code: number;
@@ -1439,7 +1439,7 @@ declare class Order {
1439
1439
  status: string;
1440
1440
  confirmations: number;
1441
1441
  timestamp: number;
1442
- receipt: ethers.ContractTransactionReceipt | null;
1442
+ receipt: ethers$1.ContractTransactionReceipt | null;
1443
1443
  };
1444
1444
  } | {
1445
1445
  code: number;
@@ -1458,7 +1458,7 @@ declare class Order {
1458
1458
  status: string;
1459
1459
  confirmations: number;
1460
1460
  timestamp: number;
1461
- receipt: ethers.ContractTransactionReceipt | null;
1461
+ receipt: ethers$1.ContractTransactionReceipt | null;
1462
1462
  };
1463
1463
  } | {
1464
1464
  code: number;
@@ -1473,7 +1473,7 @@ declare class Order {
1473
1473
  code: number;
1474
1474
  message: any;
1475
1475
  }>;
1476
- updateOrderTpSl(params: UpdateOrderParams): Promise<ethers.ContractTransactionReceipt | {
1476
+ updateOrderTpSl(params: UpdateOrderParams): Promise<ethers$1.ContractTransactionReceipt | {
1477
1477
  code: number;
1478
1478
  message: string;
1479
1479
  } | null>;
@@ -1521,6 +1521,30 @@ declare class Account {
1521
1521
  code: number;
1522
1522
  data: TradeFlowItem[];
1523
1523
  }>;
1524
+ withdraw({ poolId, amount }: {
1525
+ poolId: string;
1526
+ amount: string;
1527
+ }): Promise<{
1528
+ code: number;
1529
+ data: any;
1530
+ message?: undefined;
1531
+ } | {
1532
+ code: number;
1533
+ message: string;
1534
+ data?: undefined;
1535
+ }>;
1536
+ deposit({ poolId, amount }: {
1537
+ poolId: string;
1538
+ amount: string;
1539
+ }): Promise<{
1540
+ code: number;
1541
+ data: any;
1542
+ message?: undefined;
1543
+ } | {
1544
+ code: number;
1545
+ message: string;
1546
+ data?: undefined;
1547
+ }>;
1524
1548
  }
1525
1549
 
1526
1550
  declare class MyxClient {
@@ -1546,7 +1570,7 @@ declare class MyxClient {
1546
1570
  /**
1547
1571
  * auth the client
1548
1572
  */
1549
- auth(params: Pick<MyxClientConfig, "signer" | "getAccessToken" | "walletClient">): void;
1573
+ auth(params: Required<Pick<MyxClientConfig, "signer" | "getAccessToken" | "walletClient">>): void;
1550
1574
  /**
1551
1575
  * close the client
1552
1576
  */
package/dist/index.js CHANGED
@@ -1827,7 +1827,7 @@ var RotationProvider = class extends import_providers.BaseProvider {
1827
1827
  // package.json
1828
1828
  var package_default = {
1829
1829
  name: "@myx-trade/sdk",
1830
- version: "0.1.19",
1830
+ version: "0.1.21",
1831
1831
  private: false,
1832
1832
  publishConfig: {
1833
1833
  access: "public"
@@ -1958,7 +1958,7 @@ if (typeof window !== "undefined") {
1958
1958
  }
1959
1959
  var getWalletProvider = async (chainId2) => {
1960
1960
  try {
1961
- const walletClient = sdk.getConfigManager()?.getConfig().walletClient;
1961
+ const walletClient = sdk.getConfigManager()?.getConfig()?.walletClient;
1962
1962
  const provider = new import_ethers3.BrowserProvider(walletClient?.transport);
1963
1963
  if (!provider) {
1964
1964
  throw new Error("missing provider");
@@ -9167,9 +9167,9 @@ var getERC20Contract = async (chainId2, tokenAddress) => {
9167
9167
  return getContract(tokenAddress, IERC20Metadata_default, provider);
9168
9168
  };
9169
9169
  var getAccount = async (chainId2) => {
9170
- const provider = await getWalletProvider(chainId2);
9171
- const accounts = await provider.send("eth_requestAccounts", []);
9172
- return accounts?.[0] ?? void 0;
9170
+ const provider = await getSignerProvider(chainId2);
9171
+ const account = await provider?.getAddress();
9172
+ return account ?? void 0;
9173
9173
  };
9174
9174
  var getLiquidityRouterContract = async (chainId2) => {
9175
9175
  const addresses = address_default[chainId2];
@@ -12493,6 +12493,7 @@ var OrderStatus = {
12493
12493
  };
12494
12494
 
12495
12495
  // src/manager/order/index.ts
12496
+ var import_ethers25 = require("ethers");
12496
12497
  var Order = class {
12497
12498
  constructor(configManager, logger, utils) {
12498
12499
  this.configManager = configManager;
@@ -12513,6 +12514,21 @@ var Order = class {
12513
12514
  params.executionFeeToken
12514
12515
  );
12515
12516
  const collateralWithNetworkFee = BigInt(params.collateralAmount) + BigInt(networkFee);
12517
+ const needsApproval = await this.utils.needsApproval(
12518
+ params.executionFeeToken,
12519
+ collateralWithNetworkFee.toString(),
12520
+ config.brokerAddress
12521
+ );
12522
+ if (needsApproval) {
12523
+ const approvalResult = await this.utils.approveAuthorization({
12524
+ quoteAddress: params.executionFeeToken,
12525
+ amount: import_ethers25.ethers.MaxUint256.toString(),
12526
+ spenderAddress: config.brokerAddress
12527
+ });
12528
+ if (approvalResult.code !== 0) {
12529
+ throw new Error(approvalResult.message);
12530
+ }
12531
+ }
12516
12532
  console.log("createIncreaseOrder params--->", {
12517
12533
  user: params.address,
12518
12534
  poolId: params.poolId,
@@ -12532,7 +12548,8 @@ var Order = class {
12532
12548
  tpSize: params.tpSize ? params.tpSize : 0,
12533
12549
  tpPrice: params.tpPrice ? params.tpPrice : 0,
12534
12550
  slSize: params.slSize ? params.slSize : 0,
12535
- slPrice: params.slPrice ? params.slPrice : 0
12551
+ slPrice: params.slPrice ? params.slPrice : 0,
12552
+ useAccountBalance: false
12536
12553
  });
12537
12554
  const gasLimit = await brokerContract.placeOrder.estimateGas({
12538
12555
  user: params.address,
@@ -12583,10 +12600,7 @@ var Order = class {
12583
12600
  gasLimit: gasLimit * 120n / 100n
12584
12601
  }
12585
12602
  );
12586
- this.logger.info("Transaction sent:", transaction.hash);
12587
- this.logger.info("Waiting for confirmation...");
12588
12603
  const receipt = await transaction.wait();
12589
- this.logger.info("Transaction confirmed in block:", receipt?.blockNumber);
12590
12604
  this.logger.info("createIncreaseOrder receipt--->", receipt);
12591
12605
  const orderId = this.utils.getOrderIdFromTransaction(receipt);
12592
12606
  const result = {
@@ -13032,7 +13046,7 @@ var Order = class {
13032
13046
  };
13033
13047
 
13034
13048
  // src/manager/utils/index.ts
13035
- var import_ethers25 = require("ethers");
13049
+ var import_ethers26 = require("ethers");
13036
13050
 
13037
13051
  // src/abi/Emiter.json
13038
13052
  var Emiter_default = [
@@ -16714,7 +16728,7 @@ var Utils = class {
16714
16728
  if (!receipt || !receipt.logs) {
16715
16729
  return null;
16716
16730
  }
16717
- const emiterInterface = new import_ethers25.ethers.Interface(Emiter_default);
16731
+ const emiterInterface = new import_ethers26.ethers.Interface(Emiter_default);
16718
16732
  const orderPlacedEvent = Emiter_default.find(
16719
16733
  (item) => item.type === "event" && item.name === "OrderPlaced"
16720
16734
  );
@@ -16722,7 +16736,7 @@ var Utils = class {
16722
16736
  this.logger.error("OrderPlaced event not found in Emiter ABI");
16723
16737
  return null;
16724
16738
  }
16725
- const eventTopic = import_ethers25.ethers.id(
16739
+ const eventTopic = import_ethers26.ethers.id(
16726
16740
  "OrderPlaced(address,address,bytes32,uint256,uint256,uint8,uint8,uint8,uint8,uint256,uint256,uint256,uint8,bool,uint16,address,uint256,uint16)"
16727
16741
  );
16728
16742
  this.logger.info("Looking for OrderPlaced events with topic:", eventTopic);
@@ -16772,7 +16786,7 @@ var Utils = class {
16772
16786
  }
16773
16787
  const owner = await config.signer.getAddress();
16774
16788
  const spender = spenderAddress ?? getContractAddressByChainId(config.chainId).ORDER_MANAGER;
16775
- const tokenContract = new import_ethers25.ethers.Contract(
16789
+ const tokenContract = new import_ethers26.ethers.Contract(
16776
16790
  quoteAddress,
16777
16791
  erc20Abi,
16778
16792
  config.signer
@@ -16794,8 +16808,8 @@ var Utils = class {
16794
16808
  spenderAddress
16795
16809
  );
16796
16810
  const currentAllowance = currentAllowanceRes.data;
16797
- const allowanceBigInt = import_ethers25.ethers.getBigInt(currentAllowance);
16798
- const requiredBigInt = import_ethers25.ethers.getBigInt(requiredAmount);
16811
+ const allowanceBigInt = import_ethers26.ethers.getBigInt(currentAllowance);
16812
+ const requiredBigInt = import_ethers26.ethers.getBigInt(requiredAmount);
16799
16813
  const needsApproval = allowanceBigInt < requiredBigInt;
16800
16814
  return needsApproval;
16801
16815
  } catch (error) {
@@ -16813,12 +16827,12 @@ var Utils = class {
16813
16827
  "function approve(address spender, uint256 amount) external returns (bool)"
16814
16828
  ];
16815
16829
  const config = this.configManager.getConfig();
16816
- const usdcContract = new import_ethers25.ethers.Contract(
16830
+ const usdcContract = new import_ethers26.ethers.Contract(
16817
16831
  quoteAddress,
16818
16832
  erc20Abi,
16819
16833
  config.signer
16820
16834
  );
16821
- const approveAmount = amount ?? import_ethers25.ethers.MaxUint256;
16835
+ const approveAmount = amount ?? import_ethers26.ethers.MaxUint256;
16822
16836
  const spender = spenderAddress ?? getContractAddressByChainId(config.chainId).ORDER_MANAGER;
16823
16837
  const tx = await usdcContract.approve(spender, approveAmount);
16824
16838
  await tx.wait();
@@ -16840,7 +16854,7 @@ var Utils = class {
16840
16854
  const orderManagerAddress = getContractAddressByChainId(
16841
16855
  config.chainId
16842
16856
  ).ORDER_MANAGER;
16843
- const orderManagerContract = new import_ethers25.ethers.Contract(
16857
+ const orderManagerContract = new import_ethers26.ethers.Contract(
16844
16858
  orderManagerAddress,
16845
16859
  OrderManager_default,
16846
16860
  config.signer
@@ -16920,7 +16934,7 @@ var Utils = class {
16920
16934
  };
16921
16935
 
16922
16936
  // src/manager/account/index.ts
16923
- var import_ethers26 = require("ethers");
16937
+ var import_ethers27 = require("ethers");
16924
16938
 
16925
16939
  // src/abi/Account.json
16926
16940
  var Account_default = [
@@ -18087,7 +18101,7 @@ var Account = class {
18087
18101
  );
18088
18102
  }
18089
18103
  const contractAddress = getContractAddressByChainId(config.chainId);
18090
- const erc20Contract = new import_ethers26.ethers.Contract(
18104
+ const erc20Contract = new import_ethers27.ethers.Contract(
18091
18105
  contractAddress.ERC20,
18092
18106
  ERC20Token_default,
18093
18107
  config.signer
@@ -18110,7 +18124,7 @@ var Account = class {
18110
18124
  );
18111
18125
  }
18112
18126
  const contractAddress = getContractAddressByChainId(config.chainId);
18113
- const accountContract = new import_ethers26.ethers.Contract(
18127
+ const accountContract = new import_ethers27.ethers.Contract(
18114
18128
  contractAddress.Account,
18115
18129
  Account_default,
18116
18130
  config.signer
@@ -18146,6 +18160,50 @@ var Account = class {
18146
18160
  data: res.data
18147
18161
  };
18148
18162
  }
18163
+ async withdraw({ poolId, amount }) {
18164
+ const config = this.configManager.getConfig();
18165
+ const contractAddress = getContractAddressByChainId(config.chainId);
18166
+ const accountContract = new import_ethers27.ethers.Contract(
18167
+ contractAddress.Account,
18168
+ Account_default,
18169
+ config.signer
18170
+ );
18171
+ try {
18172
+ const rs = await accountContract.withdraw(poolId, amount, config.signer?.getAddress() ?? "");
18173
+ const receipt = await rs?.wait(1);
18174
+ return {
18175
+ code: 0,
18176
+ data: receipt
18177
+ };
18178
+ } catch (error) {
18179
+ return {
18180
+ code: -1,
18181
+ message: error.message
18182
+ };
18183
+ }
18184
+ }
18185
+ async deposit({ poolId, amount }) {
18186
+ const config = this.configManager.getConfig();
18187
+ const contractAddress = getContractAddressByChainId(config.chainId);
18188
+ const accountContract = new import_ethers27.ethers.Contract(
18189
+ contractAddress.Account,
18190
+ Account_default,
18191
+ config.signer
18192
+ );
18193
+ try {
18194
+ const rs = await accountContract.deposit(config.signer?.getAddress() ?? "", poolId, amount);
18195
+ const receipt = await rs?.wait(1);
18196
+ return {
18197
+ code: 0,
18198
+ data: receipt
18199
+ };
18200
+ } catch (error) {
18201
+ return {
18202
+ code: -1,
18203
+ message: error.message
18204
+ };
18205
+ }
18206
+ }
18149
18207
  };
18150
18208
 
18151
18209
  // src/manager/index.ts
package/dist/index.mjs CHANGED
@@ -1742,7 +1742,7 @@ var RotationProvider = class extends BaseProvider {
1742
1742
  // package.json
1743
1743
  var package_default = {
1744
1744
  name: "@myx-trade/sdk",
1745
- version: "0.1.19",
1745
+ version: "0.1.21",
1746
1746
  private: false,
1747
1747
  publishConfig: {
1748
1748
  access: "public"
@@ -1873,7 +1873,7 @@ if (typeof window !== "undefined") {
1873
1873
  }
1874
1874
  var getWalletProvider = async (chainId2) => {
1875
1875
  try {
1876
- const walletClient = sdk.getConfigManager()?.getConfig().walletClient;
1876
+ const walletClient = sdk.getConfigManager()?.getConfig()?.walletClient;
1877
1877
  const provider = new BrowserProvider(walletClient?.transport);
1878
1878
  if (!provider) {
1879
1879
  throw new Error("missing provider");
@@ -9082,9 +9082,9 @@ var getERC20Contract = async (chainId2, tokenAddress) => {
9082
9082
  return getContract(tokenAddress, IERC20Metadata_default, provider);
9083
9083
  };
9084
9084
  var getAccount = async (chainId2) => {
9085
- const provider = await getWalletProvider(chainId2);
9086
- const accounts = await provider.send("eth_requestAccounts", []);
9087
- return accounts?.[0] ?? void 0;
9085
+ const provider = await getSignerProvider(chainId2);
9086
+ const account = await provider?.getAddress();
9087
+ return account ?? void 0;
9088
9088
  };
9089
9089
  var getLiquidityRouterContract = async (chainId2) => {
9090
9090
  const addresses = address_default[chainId2];
@@ -12408,6 +12408,7 @@ var OrderStatus = {
12408
12408
  };
12409
12409
 
12410
12410
  // src/manager/order/index.ts
12411
+ import { ethers as ethers6 } from "ethers";
12411
12412
  var Order = class {
12412
12413
  constructor(configManager, logger, utils) {
12413
12414
  this.configManager = configManager;
@@ -12428,6 +12429,21 @@ var Order = class {
12428
12429
  params.executionFeeToken
12429
12430
  );
12430
12431
  const collateralWithNetworkFee = BigInt(params.collateralAmount) + BigInt(networkFee);
12432
+ const needsApproval = await this.utils.needsApproval(
12433
+ params.executionFeeToken,
12434
+ collateralWithNetworkFee.toString(),
12435
+ config.brokerAddress
12436
+ );
12437
+ if (needsApproval) {
12438
+ const approvalResult = await this.utils.approveAuthorization({
12439
+ quoteAddress: params.executionFeeToken,
12440
+ amount: ethers6.MaxUint256.toString(),
12441
+ spenderAddress: config.brokerAddress
12442
+ });
12443
+ if (approvalResult.code !== 0) {
12444
+ throw new Error(approvalResult.message);
12445
+ }
12446
+ }
12431
12447
  console.log("createIncreaseOrder params--->", {
12432
12448
  user: params.address,
12433
12449
  poolId: params.poolId,
@@ -12447,7 +12463,8 @@ var Order = class {
12447
12463
  tpSize: params.tpSize ? params.tpSize : 0,
12448
12464
  tpPrice: params.tpPrice ? params.tpPrice : 0,
12449
12465
  slSize: params.slSize ? params.slSize : 0,
12450
- slPrice: params.slPrice ? params.slPrice : 0
12466
+ slPrice: params.slPrice ? params.slPrice : 0,
12467
+ useAccountBalance: false
12451
12468
  });
12452
12469
  const gasLimit = await brokerContract.placeOrder.estimateGas({
12453
12470
  user: params.address,
@@ -12498,10 +12515,7 @@ var Order = class {
12498
12515
  gasLimit: gasLimit * 120n / 100n
12499
12516
  }
12500
12517
  );
12501
- this.logger.info("Transaction sent:", transaction.hash);
12502
- this.logger.info("Waiting for confirmation...");
12503
12518
  const receipt = await transaction.wait();
12504
- this.logger.info("Transaction confirmed in block:", receipt?.blockNumber);
12505
12519
  this.logger.info("createIncreaseOrder receipt--->", receipt);
12506
12520
  const orderId = this.utils.getOrderIdFromTransaction(receipt);
12507
12521
  const result = {
@@ -12947,7 +12961,7 @@ var Order = class {
12947
12961
  };
12948
12962
 
12949
12963
  // src/manager/utils/index.ts
12950
- import { ethers as ethers6 } from "ethers";
12964
+ import { ethers as ethers7 } from "ethers";
12951
12965
 
12952
12966
  // src/abi/Emiter.json
12953
12967
  var Emiter_default = [
@@ -16629,7 +16643,7 @@ var Utils = class {
16629
16643
  if (!receipt || !receipt.logs) {
16630
16644
  return null;
16631
16645
  }
16632
- const emiterInterface = new ethers6.Interface(Emiter_default);
16646
+ const emiterInterface = new ethers7.Interface(Emiter_default);
16633
16647
  const orderPlacedEvent = Emiter_default.find(
16634
16648
  (item) => item.type === "event" && item.name === "OrderPlaced"
16635
16649
  );
@@ -16637,7 +16651,7 @@ var Utils = class {
16637
16651
  this.logger.error("OrderPlaced event not found in Emiter ABI");
16638
16652
  return null;
16639
16653
  }
16640
- const eventTopic = ethers6.id(
16654
+ const eventTopic = ethers7.id(
16641
16655
  "OrderPlaced(address,address,bytes32,uint256,uint256,uint8,uint8,uint8,uint8,uint256,uint256,uint256,uint8,bool,uint16,address,uint256,uint16)"
16642
16656
  );
16643
16657
  this.logger.info("Looking for OrderPlaced events with topic:", eventTopic);
@@ -16687,7 +16701,7 @@ var Utils = class {
16687
16701
  }
16688
16702
  const owner = await config.signer.getAddress();
16689
16703
  const spender = spenderAddress ?? getContractAddressByChainId(config.chainId).ORDER_MANAGER;
16690
- const tokenContract = new ethers6.Contract(
16704
+ const tokenContract = new ethers7.Contract(
16691
16705
  quoteAddress,
16692
16706
  erc20Abi,
16693
16707
  config.signer
@@ -16709,8 +16723,8 @@ var Utils = class {
16709
16723
  spenderAddress
16710
16724
  );
16711
16725
  const currentAllowance = currentAllowanceRes.data;
16712
- const allowanceBigInt = ethers6.getBigInt(currentAllowance);
16713
- const requiredBigInt = ethers6.getBigInt(requiredAmount);
16726
+ const allowanceBigInt = ethers7.getBigInt(currentAllowance);
16727
+ const requiredBigInt = ethers7.getBigInt(requiredAmount);
16714
16728
  const needsApproval = allowanceBigInt < requiredBigInt;
16715
16729
  return needsApproval;
16716
16730
  } catch (error) {
@@ -16728,12 +16742,12 @@ var Utils = class {
16728
16742
  "function approve(address spender, uint256 amount) external returns (bool)"
16729
16743
  ];
16730
16744
  const config = this.configManager.getConfig();
16731
- const usdcContract = new ethers6.Contract(
16745
+ const usdcContract = new ethers7.Contract(
16732
16746
  quoteAddress,
16733
16747
  erc20Abi,
16734
16748
  config.signer
16735
16749
  );
16736
- const approveAmount = amount ?? ethers6.MaxUint256;
16750
+ const approveAmount = amount ?? ethers7.MaxUint256;
16737
16751
  const spender = spenderAddress ?? getContractAddressByChainId(config.chainId).ORDER_MANAGER;
16738
16752
  const tx = await usdcContract.approve(spender, approveAmount);
16739
16753
  await tx.wait();
@@ -16755,7 +16769,7 @@ var Utils = class {
16755
16769
  const orderManagerAddress = getContractAddressByChainId(
16756
16770
  config.chainId
16757
16771
  ).ORDER_MANAGER;
16758
- const orderManagerContract = new ethers6.Contract(
16772
+ const orderManagerContract = new ethers7.Contract(
16759
16773
  orderManagerAddress,
16760
16774
  OrderManager_default,
16761
16775
  config.signer
@@ -16835,7 +16849,7 @@ var Utils = class {
16835
16849
  };
16836
16850
 
16837
16851
  // src/manager/account/index.ts
16838
- import { ethers as ethers7 } from "ethers";
16852
+ import { ethers as ethers8 } from "ethers";
16839
16853
 
16840
16854
  // src/abi/Account.json
16841
16855
  var Account_default = [
@@ -18002,7 +18016,7 @@ var Account = class {
18002
18016
  );
18003
18017
  }
18004
18018
  const contractAddress = getContractAddressByChainId(config.chainId);
18005
- const erc20Contract = new ethers7.Contract(
18019
+ const erc20Contract = new ethers8.Contract(
18006
18020
  contractAddress.ERC20,
18007
18021
  ERC20Token_default,
18008
18022
  config.signer
@@ -18025,7 +18039,7 @@ var Account = class {
18025
18039
  );
18026
18040
  }
18027
18041
  const contractAddress = getContractAddressByChainId(config.chainId);
18028
- const accountContract = new ethers7.Contract(
18042
+ const accountContract = new ethers8.Contract(
18029
18043
  contractAddress.Account,
18030
18044
  Account_default,
18031
18045
  config.signer
@@ -18061,6 +18075,50 @@ var Account = class {
18061
18075
  data: res.data
18062
18076
  };
18063
18077
  }
18078
+ async withdraw({ poolId, amount }) {
18079
+ const config = this.configManager.getConfig();
18080
+ const contractAddress = getContractAddressByChainId(config.chainId);
18081
+ const accountContract = new ethers8.Contract(
18082
+ contractAddress.Account,
18083
+ Account_default,
18084
+ config.signer
18085
+ );
18086
+ try {
18087
+ const rs = await accountContract.withdraw(poolId, amount, config.signer?.getAddress() ?? "");
18088
+ const receipt = await rs?.wait(1);
18089
+ return {
18090
+ code: 0,
18091
+ data: receipt
18092
+ };
18093
+ } catch (error) {
18094
+ return {
18095
+ code: -1,
18096
+ message: error.message
18097
+ };
18098
+ }
18099
+ }
18100
+ async deposit({ poolId, amount }) {
18101
+ const config = this.configManager.getConfig();
18102
+ const contractAddress = getContractAddressByChainId(config.chainId);
18103
+ const accountContract = new ethers8.Contract(
18104
+ contractAddress.Account,
18105
+ Account_default,
18106
+ config.signer
18107
+ );
18108
+ try {
18109
+ const rs = await accountContract.deposit(config.signer?.getAddress() ?? "", poolId, amount);
18110
+ const receipt = await rs?.wait(1);
18111
+ return {
18112
+ code: 0,
18113
+ data: receipt
18114
+ };
18115
+ } catch (error) {
18116
+ return {
18117
+ code: -1,
18118
+ message: error.message
18119
+ };
18120
+ }
18121
+ }
18064
18122
  };
18065
18123
 
18066
18124
  // src/manager/index.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myx-trade/sdk",
3
- "version": "0.1.19",
3
+ "version": "0.1.21",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"