@myx-trade/sdk 0.1.53 → 0.1.55

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
@@ -1504,6 +1504,29 @@ declare class Order {
1504
1504
  message: any;
1505
1505
  data?: undefined;
1506
1506
  }>;
1507
+ closeAllPositions(chainId: number, params: PlaceOrderParams[]): Promise<{
1508
+ code: number;
1509
+ message: string;
1510
+ data: string | null;
1511
+ transactionHash: string;
1512
+ blockNumber: number | undefined;
1513
+ gasUsed: string | undefined;
1514
+ status: string;
1515
+ confirmations: number;
1516
+ timestamp: number;
1517
+ receipt: ethers$1.ContractTransactionReceipt | null;
1518
+ } | {
1519
+ code: number;
1520
+ message: any;
1521
+ data?: undefined;
1522
+ transactionHash?: undefined;
1523
+ blockNumber?: undefined;
1524
+ gasUsed?: undefined;
1525
+ status?: undefined;
1526
+ confirmations?: undefined;
1527
+ timestamp?: undefined;
1528
+ receipt?: undefined;
1529
+ }>;
1507
1530
  createDecreaseOrder(params: PlaceOrderParams): Promise<{
1508
1531
  code: number;
1509
1532
  message: string;
package/dist/index.d.ts CHANGED
@@ -1504,6 +1504,29 @@ declare class Order {
1504
1504
  message: any;
1505
1505
  data?: undefined;
1506
1506
  }>;
1507
+ closeAllPositions(chainId: number, params: PlaceOrderParams[]): Promise<{
1508
+ code: number;
1509
+ message: string;
1510
+ data: string | null;
1511
+ transactionHash: string;
1512
+ blockNumber: number | undefined;
1513
+ gasUsed: string | undefined;
1514
+ status: string;
1515
+ confirmations: number;
1516
+ timestamp: number;
1517
+ receipt: ethers$1.ContractTransactionReceipt | null;
1518
+ } | {
1519
+ code: number;
1520
+ message: any;
1521
+ data?: undefined;
1522
+ transactionHash?: undefined;
1523
+ blockNumber?: undefined;
1524
+ gasUsed?: undefined;
1525
+ status?: undefined;
1526
+ confirmations?: undefined;
1527
+ timestamp?: undefined;
1528
+ receipt?: undefined;
1529
+ }>;
1507
1530
  createDecreaseOrder(params: PlaceOrderParams): Promise<{
1508
1531
  code: number;
1509
1532
  message: string;
package/dist/index.js CHANGED
@@ -1836,7 +1836,7 @@ var RotationProvider = class extends import_providers.BaseProvider {
1836
1836
  // package.json
1837
1837
  var package_default = {
1838
1838
  name: "@myx-trade/sdk",
1839
- version: "0.1.53",
1839
+ version: "0.1.55",
1840
1840
  private: false,
1841
1841
  publishConfig: {
1842
1842
  access: "public"
@@ -13166,6 +13166,75 @@ var Order = class {
13166
13166
  };
13167
13167
  }
13168
13168
  }
13169
+ async closeAllPositions(chainId, params) {
13170
+ try {
13171
+ const config = this.configManager.getConfig();
13172
+ if (!config.signer) {
13173
+ throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
13174
+ }
13175
+ const brokerContract = await getBrokerSingerContract(
13176
+ chainId
13177
+ );
13178
+ const networkFee = await this.utils.getNetworkFee(
13179
+ params[0].executionFeeToken
13180
+ );
13181
+ const positionIds = params.map((param) => param.positionId.toString());
13182
+ const dataMap = params.map((param) => {
13183
+ const collateralWithNetworkFee = BigInt(param.collateralAmount) + BigInt(networkFee);
13184
+ return {
13185
+ user: param.address,
13186
+ poolId: param.poolId,
13187
+ orderType: param.orderType,
13188
+ triggerType: param.triggerType,
13189
+ operation: OperationType.DECREASE,
13190
+ direction: param.direction,
13191
+ collateralAmount: collateralWithNetworkFee,
13192
+ size: param.size,
13193
+ price: param.price,
13194
+ timeInForce: TIME_IN_FORCE,
13195
+ postOnly: param.postOnly,
13196
+ slippagePct: param.slippagePct,
13197
+ executionFeeToken: param.executionFeeToken,
13198
+ leverage: param.leverage,
13199
+ tpSize: 0,
13200
+ tpPrice: 0,
13201
+ slSize: 0,
13202
+ slPrice: 0,
13203
+ useAccountBalance: false
13204
+ };
13205
+ });
13206
+ this.logger.info("closeAllPositions positionIds--->", positionIds);
13207
+ this.logger.info("closeAllPositions dataMap--->", dataMap);
13208
+ const gasLimit = await brokerContract.placeOrdersWithSalt.estimateGas(positionIds, dataMap);
13209
+ const transaction = await brokerContract.placeOrdersWithSalt(positionIds, dataMap, {
13210
+ gasLimit: gasLimit * 120n / 100n
13211
+ });
13212
+ this.logger.info("Transaction sent:", transaction.hash);
13213
+ this.logger.info("Waiting for confirmation...");
13214
+ const receipt = await transaction.wait();
13215
+ this.logger.info("Transaction confirmed in block:", receipt?.blockNumber);
13216
+ this.logger.info("closeAllPositions receipt--->", receipt);
13217
+ const orderId = this.utils.getOrderIdFromTransaction(receipt);
13218
+ return {
13219
+ code: 0,
13220
+ message: "close all positions success",
13221
+ data: orderId,
13222
+ transactionHash: transaction.hash,
13223
+ blockNumber: receipt?.blockNumber,
13224
+ gasUsed: receipt?.gasUsed?.toString(),
13225
+ status: receipt?.status === 1 ? "success" : "failed",
13226
+ confirmations: 1,
13227
+ timestamp: Date.now(),
13228
+ receipt
13229
+ };
13230
+ } catch (error) {
13231
+ return {
13232
+ code: -1,
13233
+ // @ts-ignore
13234
+ message: error?.message
13235
+ };
13236
+ }
13237
+ }
13169
13238
  async createDecreaseOrder(params) {
13170
13239
  try {
13171
13240
  const config = this.configManager.getConfig();
package/dist/index.mjs CHANGED
@@ -1751,7 +1751,7 @@ var RotationProvider = class extends BaseProvider {
1751
1751
  // package.json
1752
1752
  var package_default = {
1753
1753
  name: "@myx-trade/sdk",
1754
- version: "0.1.53",
1754
+ version: "0.1.55",
1755
1755
  private: false,
1756
1756
  publishConfig: {
1757
1757
  access: "public"
@@ -13081,6 +13081,75 @@ var Order = class {
13081
13081
  };
13082
13082
  }
13083
13083
  }
13084
+ async closeAllPositions(chainId, params) {
13085
+ try {
13086
+ const config = this.configManager.getConfig();
13087
+ if (!config.signer) {
13088
+ throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
13089
+ }
13090
+ const brokerContract = await getBrokerSingerContract(
13091
+ chainId
13092
+ );
13093
+ const networkFee = await this.utils.getNetworkFee(
13094
+ params[0].executionFeeToken
13095
+ );
13096
+ const positionIds = params.map((param) => param.positionId.toString());
13097
+ const dataMap = params.map((param) => {
13098
+ const collateralWithNetworkFee = BigInt(param.collateralAmount) + BigInt(networkFee);
13099
+ return {
13100
+ user: param.address,
13101
+ poolId: param.poolId,
13102
+ orderType: param.orderType,
13103
+ triggerType: param.triggerType,
13104
+ operation: OperationType.DECREASE,
13105
+ direction: param.direction,
13106
+ collateralAmount: collateralWithNetworkFee,
13107
+ size: param.size,
13108
+ price: param.price,
13109
+ timeInForce: TIME_IN_FORCE,
13110
+ postOnly: param.postOnly,
13111
+ slippagePct: param.slippagePct,
13112
+ executionFeeToken: param.executionFeeToken,
13113
+ leverage: param.leverage,
13114
+ tpSize: 0,
13115
+ tpPrice: 0,
13116
+ slSize: 0,
13117
+ slPrice: 0,
13118
+ useAccountBalance: false
13119
+ };
13120
+ });
13121
+ this.logger.info("closeAllPositions positionIds--->", positionIds);
13122
+ this.logger.info("closeAllPositions dataMap--->", dataMap);
13123
+ const gasLimit = await brokerContract.placeOrdersWithSalt.estimateGas(positionIds, dataMap);
13124
+ const transaction = await brokerContract.placeOrdersWithSalt(positionIds, dataMap, {
13125
+ gasLimit: gasLimit * 120n / 100n
13126
+ });
13127
+ this.logger.info("Transaction sent:", transaction.hash);
13128
+ this.logger.info("Waiting for confirmation...");
13129
+ const receipt = await transaction.wait();
13130
+ this.logger.info("Transaction confirmed in block:", receipt?.blockNumber);
13131
+ this.logger.info("closeAllPositions receipt--->", receipt);
13132
+ const orderId = this.utils.getOrderIdFromTransaction(receipt);
13133
+ return {
13134
+ code: 0,
13135
+ message: "close all positions success",
13136
+ data: orderId,
13137
+ transactionHash: transaction.hash,
13138
+ blockNumber: receipt?.blockNumber,
13139
+ gasUsed: receipt?.gasUsed?.toString(),
13140
+ status: receipt?.status === 1 ? "success" : "failed",
13141
+ confirmations: 1,
13142
+ timestamp: Date.now(),
13143
+ receipt
13144
+ };
13145
+ } catch (error) {
13146
+ return {
13147
+ code: -1,
13148
+ // @ts-ignore
13149
+ message: error?.message
13150
+ };
13151
+ }
13152
+ }
13084
13153
  async createDecreaseOrder(params) {
13085
13154
  try {
13086
13155
  const config = this.configManager.getConfig();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myx-trade/sdk",
3
- "version": "0.1.53",
3
+ "version": "0.1.55",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"