@myx-trade/sdk 0.1.113 → 0.1.115

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
@@ -1417,60 +1417,6 @@ declare class Markets {
1417
1417
  getMarketDetail(params: GetMarketDetailParams): Promise<MarketDetailResponse>;
1418
1418
  }
1419
1419
 
1420
- declare class Position {
1421
- private configManager;
1422
- private logger;
1423
- private utils;
1424
- constructor(configManager: ConfigManager, logger: Logger, utils: Utils);
1425
- listPositions(): Promise<{
1426
- code: number;
1427
- message: string;
1428
- data?: undefined;
1429
- } | {
1430
- code: number;
1431
- data: PositionType[];
1432
- message?: undefined;
1433
- }>;
1434
- getPositionHistory(params: GetHistoryOrdersParams): Promise<{
1435
- code: number;
1436
- data: PositionHistoryItem[];
1437
- }>;
1438
- adjustCollateral({ poolId, positionId, adjustAmount, quoteToken, poolOracleType, chainId }: {
1439
- poolId: string;
1440
- positionId: string;
1441
- adjustAmount: string;
1442
- quoteToken: string;
1443
- poolOracleType: OracleType;
1444
- chainId: number;
1445
- }): Promise<{
1446
- code: number;
1447
- data: {
1448
- hash: any;
1449
- };
1450
- message: string;
1451
- } | {
1452
- code: number;
1453
- message: any;
1454
- data?: undefined;
1455
- }>;
1456
- }
1457
-
1458
- /**
1459
- * Order related types and interfaces
1460
- */
1461
-
1462
- interface UpdateOrderParams {
1463
- orderId: string;
1464
- tpSize: string;
1465
- tpPrice: string;
1466
- slSize: string;
1467
- slPrice: string;
1468
- useOrderCollateral: boolean;
1469
- executionFeeToken: string;
1470
- size: string;
1471
- price: string;
1472
- }
1473
-
1474
1420
  declare class Account {
1475
1421
  private configManager;
1476
1422
  private logger;
@@ -1634,6 +1580,65 @@ declare class Seamless {
1634
1580
  }>;
1635
1581
  }
1636
1582
 
1583
+ declare class Position {
1584
+ private configManager;
1585
+ private logger;
1586
+ private utils;
1587
+ private seamless;
1588
+ constructor(configManager: ConfigManager, logger: Logger, utils: Utils, seamless: Seamless);
1589
+ listPositions(): Promise<{
1590
+ code: number;
1591
+ message: string;
1592
+ data?: undefined;
1593
+ } | {
1594
+ code: number;
1595
+ data: PositionType[];
1596
+ message?: undefined;
1597
+ }>;
1598
+ getPositionHistory(params: GetHistoryOrdersParams): Promise<{
1599
+ code: number;
1600
+ data: PositionHistoryItem[];
1601
+ }>;
1602
+ adjustCollateral({ poolId, positionId, adjustAmount, quoteToken, poolOracleType, chainId }: {
1603
+ poolId: string;
1604
+ positionId: string;
1605
+ adjustAmount: string;
1606
+ quoteToken: string;
1607
+ poolOracleType: OracleType;
1608
+ chainId: number;
1609
+ }): Promise<{
1610
+ code: number;
1611
+ message: string;
1612
+ data: ApiResponse<any>;
1613
+ } | {
1614
+ code: number;
1615
+ data: {
1616
+ hash: any;
1617
+ };
1618
+ message: string;
1619
+ } | {
1620
+ code: number;
1621
+ message: any;
1622
+ data?: undefined;
1623
+ }>;
1624
+ }
1625
+
1626
+ /**
1627
+ * Order related types and interfaces
1628
+ */
1629
+
1630
+ interface UpdateOrderParams {
1631
+ orderId: string;
1632
+ tpSize: string;
1633
+ tpPrice: string;
1634
+ slSize: string;
1635
+ slPrice: string;
1636
+ useOrderCollateral: boolean;
1637
+ executionFeeToken: string;
1638
+ size: string;
1639
+ price: string;
1640
+ }
1641
+
1637
1642
  declare class Order {
1638
1643
  private configManager;
1639
1644
  private logger;
package/dist/index.d.ts CHANGED
@@ -1417,60 +1417,6 @@ declare class Markets {
1417
1417
  getMarketDetail(params: GetMarketDetailParams): Promise<MarketDetailResponse>;
1418
1418
  }
1419
1419
 
1420
- declare class Position {
1421
- private configManager;
1422
- private logger;
1423
- private utils;
1424
- constructor(configManager: ConfigManager, logger: Logger, utils: Utils);
1425
- listPositions(): Promise<{
1426
- code: number;
1427
- message: string;
1428
- data?: undefined;
1429
- } | {
1430
- code: number;
1431
- data: PositionType[];
1432
- message?: undefined;
1433
- }>;
1434
- getPositionHistory(params: GetHistoryOrdersParams): Promise<{
1435
- code: number;
1436
- data: PositionHistoryItem[];
1437
- }>;
1438
- adjustCollateral({ poolId, positionId, adjustAmount, quoteToken, poolOracleType, chainId }: {
1439
- poolId: string;
1440
- positionId: string;
1441
- adjustAmount: string;
1442
- quoteToken: string;
1443
- poolOracleType: OracleType;
1444
- chainId: number;
1445
- }): Promise<{
1446
- code: number;
1447
- data: {
1448
- hash: any;
1449
- };
1450
- message: string;
1451
- } | {
1452
- code: number;
1453
- message: any;
1454
- data?: undefined;
1455
- }>;
1456
- }
1457
-
1458
- /**
1459
- * Order related types and interfaces
1460
- */
1461
-
1462
- interface UpdateOrderParams {
1463
- orderId: string;
1464
- tpSize: string;
1465
- tpPrice: string;
1466
- slSize: string;
1467
- slPrice: string;
1468
- useOrderCollateral: boolean;
1469
- executionFeeToken: string;
1470
- size: string;
1471
- price: string;
1472
- }
1473
-
1474
1420
  declare class Account {
1475
1421
  private configManager;
1476
1422
  private logger;
@@ -1634,6 +1580,65 @@ declare class Seamless {
1634
1580
  }>;
1635
1581
  }
1636
1582
 
1583
+ declare class Position {
1584
+ private configManager;
1585
+ private logger;
1586
+ private utils;
1587
+ private seamless;
1588
+ constructor(configManager: ConfigManager, logger: Logger, utils: Utils, seamless: Seamless);
1589
+ listPositions(): Promise<{
1590
+ code: number;
1591
+ message: string;
1592
+ data?: undefined;
1593
+ } | {
1594
+ code: number;
1595
+ data: PositionType[];
1596
+ message?: undefined;
1597
+ }>;
1598
+ getPositionHistory(params: GetHistoryOrdersParams): Promise<{
1599
+ code: number;
1600
+ data: PositionHistoryItem[];
1601
+ }>;
1602
+ adjustCollateral({ poolId, positionId, adjustAmount, quoteToken, poolOracleType, chainId }: {
1603
+ poolId: string;
1604
+ positionId: string;
1605
+ adjustAmount: string;
1606
+ quoteToken: string;
1607
+ poolOracleType: OracleType;
1608
+ chainId: number;
1609
+ }): Promise<{
1610
+ code: number;
1611
+ message: string;
1612
+ data: ApiResponse<any>;
1613
+ } | {
1614
+ code: number;
1615
+ data: {
1616
+ hash: any;
1617
+ };
1618
+ message: string;
1619
+ } | {
1620
+ code: number;
1621
+ message: any;
1622
+ data?: undefined;
1623
+ }>;
1624
+ }
1625
+
1626
+ /**
1627
+ * Order related types and interfaces
1628
+ */
1629
+
1630
+ interface UpdateOrderParams {
1631
+ orderId: string;
1632
+ tpSize: string;
1633
+ tpPrice: string;
1634
+ slSize: string;
1635
+ slPrice: string;
1636
+ useOrderCollateral: boolean;
1637
+ executionFeeToken: string;
1638
+ size: string;
1639
+ price: string;
1640
+ }
1641
+
1637
1642
  declare class Order {
1638
1643
  private configManager;
1639
1644
  private logger;
package/dist/index.js CHANGED
@@ -1822,7 +1822,7 @@ var RotationProvider = class extends import_providers.BaseProvider {
1822
1822
  // package.json
1823
1823
  var package_default = {
1824
1824
  name: "@myx-trade/sdk",
1825
- version: "0.1.113",
1825
+ version: "0.1.115",
1826
1826
  private: false,
1827
1827
  publishConfig: {
1828
1828
  access: "public"
@@ -14022,25 +14022,15 @@ var Markets = class {
14022
14022
  }
14023
14023
  };
14024
14024
 
14025
- // src/config/address/index.ts
14026
- var getContractAddressByChainId = (chainId) => {
14027
- switch (chainId) {
14028
- case 421614 /* ARB_TESTNET */:
14029
- return ARB_TEST_SEPOLIA;
14030
- case 59141 /* LINEA_SEPOLIA */:
14031
- return LINEA_SEPOLIA;
14032
- default:
14033
- return {};
14034
- }
14035
- };
14036
-
14037
14025
  // src/manager/position/index.ts
14038
14026
  var import_ethers23 = require("ethers");
14027
+ var import_dayjs = __toESM(require("dayjs"));
14039
14028
  var Position = class {
14040
- constructor(configManager, logger, utils) {
14029
+ constructor(configManager, logger, utils, seamless) {
14041
14030
  this.configManager = configManager;
14042
14031
  this.logger = logger;
14043
14032
  this.utils = utils;
14033
+ this.seamless = seamless;
14044
14034
  }
14045
14035
  async listPositions() {
14046
14036
  const accessToken = await this.configManager.getAccessToken();
@@ -14087,10 +14077,7 @@ var Position = class {
14087
14077
  chainId
14088
14078
  }) {
14089
14079
  const config = this.configManager.getConfig();
14090
- if (!config.signer) {
14091
- throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
14092
- }
14093
- this.logger.debug("adjustCollateral-->", {
14080
+ this.logger.debug("adjustCollateral params-->", {
14094
14081
  poolId,
14095
14082
  positionId,
14096
14083
  adjustAmount,
@@ -14108,55 +14095,90 @@ var Position = class {
14108
14095
  publishTime: priceData.publishTime,
14109
14096
  oracleType: poolOracleType
14110
14097
  };
14111
- const contractAddress = getContractAddressByChainId(chainId);
14098
+ let needsApproval = false;
14112
14099
  if (Number(adjustAmount) > 0) {
14113
- this.logger.debug("adjust collateral check and approve-->", {
14114
- quoteToken,
14115
- adjustAmount,
14116
- spenderAddress: contractAddress.Account
14117
- });
14118
- const needsApproval = await this.utils.needsApproval(
14100
+ needsApproval = await this.utils.needsApproval(
14119
14101
  chainId,
14120
14102
  quoteToken,
14121
14103
  adjustAmount
14122
14104
  );
14123
- this.logger.debug("adjust collateral needs approval-->", {
14124
- needsApproval
14125
- });
14105
+ }
14106
+ const authorized = this.configManager.getConfig().seamlessAccount?.authorized;
14107
+ const seamlessWallet = this.configManager.getConfig().seamlessAccount?.wallet;
14108
+ const networkFee = await this.utils.getNetworkFee(quoteToken, chainId);
14109
+ const depositAmount = BigInt(networkFee) + (BigInt(adjustAmount) > 0 ? BigInt(adjustAmount) : 0n);
14110
+ const depositData = {
14111
+ token: quoteToken,
14112
+ amount: depositAmount.toString()
14113
+ };
14114
+ if (config.seamlessMode && authorized && seamlessWallet) {
14126
14115
  if (needsApproval) {
14127
- this.logger.debug("adjust collateral approve-->", {
14128
- quoteToken,
14129
- amount: import_ethers23.ethers.MaxUint256.toString(),
14130
- spenderAddress: contractAddress.Account
14131
- });
14132
14116
  const approvalResult = await this.utils.approveAuthorization({
14133
14117
  chainId,
14134
14118
  quoteAddress: quoteToken,
14135
14119
  amount: import_ethers23.ethers.MaxUint256.toString(),
14136
- spenderAddress: contractAddress.Account
14120
+ signer: seamlessWallet
14137
14121
  });
14138
14122
  if (approvalResult.code !== 0) {
14139
14123
  throw new Error(approvalResult.message);
14140
14124
  }
14141
14125
  }
14126
+ const isEnoughGas = await this.utils.checkSeamlessGas(config.seamlessAccount?.masterAddress);
14127
+ if (!isEnoughGas) {
14128
+ throw new MyxSDKError("INSUFFICIENT_BALANCE" /* InsufficientBalance */, "Insufficient relay fee");
14129
+ }
14130
+ const forwarderContract = await getForwarderContract(chainId);
14131
+ const brokerContract2 = await getSeamlessBrokerContract(
14132
+ this.configManager.getConfig().brokerAddress,
14133
+ seamlessWallet
14134
+ );
14135
+ const functionHash = brokerContract2.interface.encodeFunctionData("updatePriceAndAdjustCollateral", [
14136
+ [updateParams],
14137
+ depositData,
14138
+ positionId,
14139
+ adjustAmount
14140
+ // {
14141
+ // value: BigInt(priceData?.value ?? "1"),
14142
+ // gas: 10000000n,
14143
+ // }
14144
+ ]);
14145
+ const nonce = await forwarderContract.nonces(seamlessWallet.address);
14146
+ const forwardTxParams = {
14147
+ from: seamlessWallet.address ?? "",
14148
+ to: this.configManager.getConfig().brokerAddress,
14149
+ value: "0",
14150
+ gas: "350000",
14151
+ deadline: (0, import_dayjs.default)().add(60, "minute").unix(),
14152
+ data: functionHash,
14153
+ nonce: nonce.toString()
14154
+ };
14155
+ this.logger.info("adjust collateral forward tx params --->", forwardTxParams);
14156
+ const rs = await this.seamless.forwarderTx(forwardTxParams, seamlessWallet);
14157
+ console.log("rs-->", rs);
14158
+ return {
14159
+ code: 0,
14160
+ message: "adjust collateral success",
14161
+ data: rs
14162
+ };
14163
+ }
14164
+ if (!config.signer) {
14165
+ throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
14142
14166
  }
14143
14167
  const brokerContract = getContract(
14144
14168
  config.brokerAddress,
14145
14169
  Broker_default,
14146
14170
  config.signer
14147
14171
  );
14148
- this.logger.debug("updatePriceAndAdjustCollateral-->", {
14149
- updateParams,
14150
- positionId,
14151
- adjustAmount,
14152
- useAccountBalance: false
14153
- });
14154
- const networkFee = await this.utils.getNetworkFee(quoteToken, chainId);
14155
- const depositAmount = BigInt(networkFee) + (BigInt(adjustAmount) > 0 ? BigInt(adjustAmount) : 0n);
14156
- const depositData = {
14157
- token: quoteToken,
14158
- amount: depositAmount.toString()
14159
- };
14172
+ if (needsApproval) {
14173
+ const approvalResult = await this.utils.approveAuthorization({
14174
+ chainId,
14175
+ quoteAddress: quoteToken,
14176
+ amount: import_ethers23.ethers.MaxUint256.toString()
14177
+ });
14178
+ if (approvalResult.code !== 0) {
14179
+ throw new Error(approvalResult.message);
14180
+ }
14181
+ }
14160
14182
  const transaction = await brokerContract.updatePriceAndAdjustCollateral(
14161
14183
  [updateParams],
14162
14184
  depositData,
@@ -14243,7 +14265,7 @@ var OrderStatus = {
14243
14265
 
14244
14266
  // src/manager/order/index.ts
14245
14267
  var import_ethers24 = require("ethers");
14246
- var import_dayjs = __toESM(require("dayjs"));
14268
+ var import_dayjs2 = __toESM(require("dayjs"));
14247
14269
  var Order = class {
14248
14270
  constructor(configManager, logger, utils, seamless, account) {
14249
14271
  this.configManager = configManager;
@@ -14358,7 +14380,7 @@ var Order = class {
14358
14380
  to: this.configManager.getConfig().brokerAddress,
14359
14381
  value: "0",
14360
14382
  gas: "350000",
14361
- deadline: (0, import_dayjs.default)().add(60, "minute").unix(),
14383
+ deadline: (0, import_dayjs2.default)().add(60, "minute").unix(),
14362
14384
  data: functionHash,
14363
14385
  nonce: nonce.toString()
14364
14386
  };
@@ -14526,7 +14548,7 @@ var Order = class {
14526
14548
  to: this.configManager.getConfig().brokerAddress,
14527
14549
  value: "0",
14528
14550
  gas: "350000",
14529
- deadline: (0, import_dayjs.default)().add(60, "minute").unix(),
14551
+ deadline: (0, import_dayjs2.default)().add(60, "minute").unix(),
14530
14552
  data: functionHash,
14531
14553
  nonce: nonce.toString()
14532
14554
  };
@@ -14666,7 +14688,7 @@ var Order = class {
14666
14688
  to: this.configManager.getConfig().brokerAddress,
14667
14689
  value: "0",
14668
14690
  gas: "350000",
14669
- deadline: (0, import_dayjs.default)().add(60, "minute").unix(),
14691
+ deadline: (0, import_dayjs2.default)().add(60, "minute").unix(),
14670
14692
  data: functionHash,
14671
14693
  nonce: nonce.toString()
14672
14694
  };
@@ -14862,7 +14884,7 @@ var Order = class {
14862
14884
  to: this.configManager.getConfig().brokerAddress,
14863
14885
  value: "0",
14864
14886
  gas: "350000",
14865
- deadline: (0, import_dayjs.default)().add(60, "minute").unix(),
14887
+ deadline: (0, import_dayjs2.default)().add(60, "minute").unix(),
14866
14888
  data: functionHash,
14867
14889
  nonce: nonce.toString()
14868
14890
  };
@@ -15001,7 +15023,7 @@ var Order = class {
15001
15023
  to: this.configManager.getConfig().brokerAddress,
15002
15024
  value: "0",
15003
15025
  gas: "350000",
15004
- deadline: (0, import_dayjs.default)().add(60, "minute").unix(),
15026
+ deadline: (0, import_dayjs2.default)().add(60, "minute").unix(),
15005
15027
  data: functionHash,
15006
15028
  nonce: nonce.toString()
15007
15029
  };
@@ -15105,7 +15127,7 @@ var Order = class {
15105
15127
  to: this.configManager.getConfig().brokerAddress,
15106
15128
  value: "0",
15107
15129
  gas: "350000",
15108
- deadline: (0, import_dayjs.default)().add(60, "minute").unix(),
15130
+ deadline: (0, import_dayjs2.default)().add(60, "minute").unix(),
15109
15131
  data: functionHash,
15110
15132
  nonce: nonce.toString()
15111
15133
  };
@@ -19380,6 +19402,18 @@ var Emiter_default = [
19380
19402
  }
19381
19403
  ];
19382
19404
 
19405
+ // src/config/address/index.ts
19406
+ var getContractAddressByChainId = (chainId) => {
19407
+ switch (chainId) {
19408
+ case 421614 /* ARB_TESTNET */:
19409
+ return ARB_TEST_SEPOLIA;
19410
+ case 59141 /* LINEA_SEPOLIA */:
19411
+ return LINEA_SEPOLIA;
19412
+ default:
19413
+ return {};
19414
+ }
19415
+ };
19416
+
19383
19417
  // src/abi/ERC20Token.json
19384
19418
  var ERC20Token_default = [
19385
19419
  {
@@ -20932,7 +20966,7 @@ var Account_default = [
20932
20966
  ];
20933
20967
 
20934
20968
  // src/manager/account/index.ts
20935
- var import_dayjs2 = __toESM(require("dayjs"));
20969
+ var import_dayjs3 = __toESM(require("dayjs"));
20936
20970
  var Account = class {
20937
20971
  constructor(configManager, logger, utils, client2) {
20938
20972
  this.configManager = configManager;
@@ -21035,7 +21069,7 @@ var Account = class {
21035
21069
  to: this.configManager.getConfig().brokerAddress,
21036
21070
  value: "0",
21037
21071
  gas: "350000",
21038
- deadline: (0, import_dayjs2.default)().add(60, "minute").unix(),
21072
+ deadline: (0, import_dayjs3.default)().add(60, "minute").unix(),
21039
21073
  data: functionHash,
21040
21074
  nonce: nonce.toString()
21041
21075
  };
@@ -21097,7 +21131,7 @@ var Account = class {
21097
21131
  to: this.configManager.getConfig().brokerAddress,
21098
21132
  value: "0",
21099
21133
  gas: "350000",
21100
- deadline: (0, import_dayjs2.default)().add(60, "minute").unix(),
21134
+ deadline: (0, import_dayjs3.default)().add(60, "minute").unix(),
21101
21135
  data: functionHash,
21102
21136
  nonce: nonce.toString()
21103
21137
  };
@@ -21144,7 +21178,7 @@ var Account = class {
21144
21178
  // src/manager/seamless/index.ts
21145
21179
  var import_crypto_js = __toESM(require("crypto-js"));
21146
21180
  var import_ethers27 = require("ethers");
21147
- var import_dayjs3 = __toESM(require("dayjs"));
21181
+ var import_dayjs4 = __toESM(require("dayjs"));
21148
21182
 
21149
21183
  // src/utils/index.ts
21150
21184
  function getChainDomainConfig(chainId, address) {
@@ -21417,7 +21451,7 @@ var Seamless = class {
21417
21451
  throw new MyxSDKError("INSUFFICIENT_BALANCE" /* InsufficientBalance */, "Insufficient balance");
21418
21452
  }
21419
21453
  }
21420
- const deadline = (0, import_dayjs3.default)().add(60, "minute").unix();
21454
+ const deadline = (0, import_dayjs4.default)().add(60, "minute").unix();
21421
21455
  let permitParams = [];
21422
21456
  if (approve2) {
21423
21457
  try {
@@ -21642,7 +21676,7 @@ var MyxClient = class {
21642
21676
  this.account = new Account(this.configManager, this.logger, this.utils, this);
21643
21677
  this.seamless = new Seamless(this.configManager, this.logger, this.utils, this.account);
21644
21678
  this.markets = new Markets(this.configManager, this.utils);
21645
- this.position = new Position(this.configManager, this.logger, this.utils);
21679
+ this.position = new Position(this.configManager, this.logger, this.utils, this.seamless);
21646
21680
  this.order = new Order(this.configManager, this.logger, this.utils, this.seamless, this.account);
21647
21681
  this.subscription = new SubScription(this.configManager, this.logger);
21648
21682
  const lp = MxSDK.getInstance();
package/dist/index.mjs CHANGED
@@ -1732,7 +1732,7 @@ var RotationProvider = class extends BaseProvider {
1732
1732
  // package.json
1733
1733
  var package_default = {
1734
1734
  name: "@myx-trade/sdk",
1735
- version: "0.1.113",
1735
+ version: "0.1.115",
1736
1736
  private: false,
1737
1737
  publishConfig: {
1738
1738
  access: "public"
@@ -13932,25 +13932,15 @@ var Markets = class {
13932
13932
  }
13933
13933
  };
13934
13934
 
13935
- // src/config/address/index.ts
13936
- var getContractAddressByChainId = (chainId) => {
13937
- switch (chainId) {
13938
- case 421614 /* ARB_TESTNET */:
13939
- return ARB_TEST_SEPOLIA;
13940
- case 59141 /* LINEA_SEPOLIA */:
13941
- return LINEA_SEPOLIA;
13942
- default:
13943
- return {};
13944
- }
13945
- };
13946
-
13947
13935
  // src/manager/position/index.ts
13948
13936
  import { ethers as ethers5 } from "ethers";
13937
+ import dayjs from "dayjs";
13949
13938
  var Position = class {
13950
- constructor(configManager, logger, utils) {
13939
+ constructor(configManager, logger, utils, seamless) {
13951
13940
  this.configManager = configManager;
13952
13941
  this.logger = logger;
13953
13942
  this.utils = utils;
13943
+ this.seamless = seamless;
13954
13944
  }
13955
13945
  async listPositions() {
13956
13946
  const accessToken = await this.configManager.getAccessToken();
@@ -13997,10 +13987,7 @@ var Position = class {
13997
13987
  chainId
13998
13988
  }) {
13999
13989
  const config = this.configManager.getConfig();
14000
- if (!config.signer) {
14001
- throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
14002
- }
14003
- this.logger.debug("adjustCollateral-->", {
13990
+ this.logger.debug("adjustCollateral params-->", {
14004
13991
  poolId,
14005
13992
  positionId,
14006
13993
  adjustAmount,
@@ -14018,55 +14005,90 @@ var Position = class {
14018
14005
  publishTime: priceData.publishTime,
14019
14006
  oracleType: poolOracleType
14020
14007
  };
14021
- const contractAddress = getContractAddressByChainId(chainId);
14008
+ let needsApproval = false;
14022
14009
  if (Number(adjustAmount) > 0) {
14023
- this.logger.debug("adjust collateral check and approve-->", {
14024
- quoteToken,
14025
- adjustAmount,
14026
- spenderAddress: contractAddress.Account
14027
- });
14028
- const needsApproval = await this.utils.needsApproval(
14010
+ needsApproval = await this.utils.needsApproval(
14029
14011
  chainId,
14030
14012
  quoteToken,
14031
14013
  adjustAmount
14032
14014
  );
14033
- this.logger.debug("adjust collateral needs approval-->", {
14034
- needsApproval
14035
- });
14015
+ }
14016
+ const authorized = this.configManager.getConfig().seamlessAccount?.authorized;
14017
+ const seamlessWallet = this.configManager.getConfig().seamlessAccount?.wallet;
14018
+ const networkFee = await this.utils.getNetworkFee(quoteToken, chainId);
14019
+ const depositAmount = BigInt(networkFee) + (BigInt(adjustAmount) > 0 ? BigInt(adjustAmount) : 0n);
14020
+ const depositData = {
14021
+ token: quoteToken,
14022
+ amount: depositAmount.toString()
14023
+ };
14024
+ if (config.seamlessMode && authorized && seamlessWallet) {
14036
14025
  if (needsApproval) {
14037
- this.logger.debug("adjust collateral approve-->", {
14038
- quoteToken,
14039
- amount: ethers5.MaxUint256.toString(),
14040
- spenderAddress: contractAddress.Account
14041
- });
14042
14026
  const approvalResult = await this.utils.approveAuthorization({
14043
14027
  chainId,
14044
14028
  quoteAddress: quoteToken,
14045
14029
  amount: ethers5.MaxUint256.toString(),
14046
- spenderAddress: contractAddress.Account
14030
+ signer: seamlessWallet
14047
14031
  });
14048
14032
  if (approvalResult.code !== 0) {
14049
14033
  throw new Error(approvalResult.message);
14050
14034
  }
14051
14035
  }
14036
+ const isEnoughGas = await this.utils.checkSeamlessGas(config.seamlessAccount?.masterAddress);
14037
+ if (!isEnoughGas) {
14038
+ throw new MyxSDKError("INSUFFICIENT_BALANCE" /* InsufficientBalance */, "Insufficient relay fee");
14039
+ }
14040
+ const forwarderContract = await getForwarderContract(chainId);
14041
+ const brokerContract2 = await getSeamlessBrokerContract(
14042
+ this.configManager.getConfig().brokerAddress,
14043
+ seamlessWallet
14044
+ );
14045
+ const functionHash = brokerContract2.interface.encodeFunctionData("updatePriceAndAdjustCollateral", [
14046
+ [updateParams],
14047
+ depositData,
14048
+ positionId,
14049
+ adjustAmount
14050
+ // {
14051
+ // value: BigInt(priceData?.value ?? "1"),
14052
+ // gas: 10000000n,
14053
+ // }
14054
+ ]);
14055
+ const nonce = await forwarderContract.nonces(seamlessWallet.address);
14056
+ const forwardTxParams = {
14057
+ from: seamlessWallet.address ?? "",
14058
+ to: this.configManager.getConfig().brokerAddress,
14059
+ value: "0",
14060
+ gas: "350000",
14061
+ deadline: dayjs().add(60, "minute").unix(),
14062
+ data: functionHash,
14063
+ nonce: nonce.toString()
14064
+ };
14065
+ this.logger.info("adjust collateral forward tx params --->", forwardTxParams);
14066
+ const rs = await this.seamless.forwarderTx(forwardTxParams, seamlessWallet);
14067
+ console.log("rs-->", rs);
14068
+ return {
14069
+ code: 0,
14070
+ message: "adjust collateral success",
14071
+ data: rs
14072
+ };
14073
+ }
14074
+ if (!config.signer) {
14075
+ throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
14052
14076
  }
14053
14077
  const brokerContract = getContract(
14054
14078
  config.brokerAddress,
14055
14079
  Broker_default,
14056
14080
  config.signer
14057
14081
  );
14058
- this.logger.debug("updatePriceAndAdjustCollateral-->", {
14059
- updateParams,
14060
- positionId,
14061
- adjustAmount,
14062
- useAccountBalance: false
14063
- });
14064
- const networkFee = await this.utils.getNetworkFee(quoteToken, chainId);
14065
- const depositAmount = BigInt(networkFee) + (BigInt(adjustAmount) > 0 ? BigInt(adjustAmount) : 0n);
14066
- const depositData = {
14067
- token: quoteToken,
14068
- amount: depositAmount.toString()
14069
- };
14082
+ if (needsApproval) {
14083
+ const approvalResult = await this.utils.approveAuthorization({
14084
+ chainId,
14085
+ quoteAddress: quoteToken,
14086
+ amount: ethers5.MaxUint256.toString()
14087
+ });
14088
+ if (approvalResult.code !== 0) {
14089
+ throw new Error(approvalResult.message);
14090
+ }
14091
+ }
14070
14092
  const transaction = await brokerContract.updatePriceAndAdjustCollateral(
14071
14093
  [updateParams],
14072
14094
  depositData,
@@ -14153,7 +14175,7 @@ var OrderStatus = {
14153
14175
 
14154
14176
  // src/manager/order/index.ts
14155
14177
  import { ethers as ethers6 } from "ethers";
14156
- import dayjs from "dayjs";
14178
+ import dayjs2 from "dayjs";
14157
14179
  var Order = class {
14158
14180
  constructor(configManager, logger, utils, seamless, account) {
14159
14181
  this.configManager = configManager;
@@ -14268,7 +14290,7 @@ var Order = class {
14268
14290
  to: this.configManager.getConfig().brokerAddress,
14269
14291
  value: "0",
14270
14292
  gas: "350000",
14271
- deadline: dayjs().add(60, "minute").unix(),
14293
+ deadline: dayjs2().add(60, "minute").unix(),
14272
14294
  data: functionHash,
14273
14295
  nonce: nonce.toString()
14274
14296
  };
@@ -14436,7 +14458,7 @@ var Order = class {
14436
14458
  to: this.configManager.getConfig().brokerAddress,
14437
14459
  value: "0",
14438
14460
  gas: "350000",
14439
- deadline: dayjs().add(60, "minute").unix(),
14461
+ deadline: dayjs2().add(60, "minute").unix(),
14440
14462
  data: functionHash,
14441
14463
  nonce: nonce.toString()
14442
14464
  };
@@ -14576,7 +14598,7 @@ var Order = class {
14576
14598
  to: this.configManager.getConfig().brokerAddress,
14577
14599
  value: "0",
14578
14600
  gas: "350000",
14579
- deadline: dayjs().add(60, "minute").unix(),
14601
+ deadline: dayjs2().add(60, "minute").unix(),
14580
14602
  data: functionHash,
14581
14603
  nonce: nonce.toString()
14582
14604
  };
@@ -14772,7 +14794,7 @@ var Order = class {
14772
14794
  to: this.configManager.getConfig().brokerAddress,
14773
14795
  value: "0",
14774
14796
  gas: "350000",
14775
- deadline: dayjs().add(60, "minute").unix(),
14797
+ deadline: dayjs2().add(60, "minute").unix(),
14776
14798
  data: functionHash,
14777
14799
  nonce: nonce.toString()
14778
14800
  };
@@ -14911,7 +14933,7 @@ var Order = class {
14911
14933
  to: this.configManager.getConfig().brokerAddress,
14912
14934
  value: "0",
14913
14935
  gas: "350000",
14914
- deadline: dayjs().add(60, "minute").unix(),
14936
+ deadline: dayjs2().add(60, "minute").unix(),
14915
14937
  data: functionHash,
14916
14938
  nonce: nonce.toString()
14917
14939
  };
@@ -15015,7 +15037,7 @@ var Order = class {
15015
15037
  to: this.configManager.getConfig().brokerAddress,
15016
15038
  value: "0",
15017
15039
  gas: "350000",
15018
- deadline: dayjs().add(60, "minute").unix(),
15040
+ deadline: dayjs2().add(60, "minute").unix(),
15019
15041
  data: functionHash,
15020
15042
  nonce: nonce.toString()
15021
15043
  };
@@ -19290,6 +19312,18 @@ var Emiter_default = [
19290
19312
  }
19291
19313
  ];
19292
19314
 
19315
+ // src/config/address/index.ts
19316
+ var getContractAddressByChainId = (chainId) => {
19317
+ switch (chainId) {
19318
+ case 421614 /* ARB_TESTNET */:
19319
+ return ARB_TEST_SEPOLIA;
19320
+ case 59141 /* LINEA_SEPOLIA */:
19321
+ return LINEA_SEPOLIA;
19322
+ default:
19323
+ return {};
19324
+ }
19325
+ };
19326
+
19293
19327
  // src/abi/ERC20Token.json
19294
19328
  var ERC20Token_default = [
19295
19329
  {
@@ -20842,7 +20876,7 @@ var Account_default = [
20842
20876
  ];
20843
20877
 
20844
20878
  // src/manager/account/index.ts
20845
- import dayjs2 from "dayjs";
20879
+ import dayjs3 from "dayjs";
20846
20880
  var Account = class {
20847
20881
  constructor(configManager, logger, utils, client2) {
20848
20882
  this.configManager = configManager;
@@ -20945,7 +20979,7 @@ var Account = class {
20945
20979
  to: this.configManager.getConfig().brokerAddress,
20946
20980
  value: "0",
20947
20981
  gas: "350000",
20948
- deadline: dayjs2().add(60, "minute").unix(),
20982
+ deadline: dayjs3().add(60, "minute").unix(),
20949
20983
  data: functionHash,
20950
20984
  nonce: nonce.toString()
20951
20985
  };
@@ -21007,7 +21041,7 @@ var Account = class {
21007
21041
  to: this.configManager.getConfig().brokerAddress,
21008
21042
  value: "0",
21009
21043
  gas: "350000",
21010
- deadline: dayjs2().add(60, "minute").unix(),
21044
+ deadline: dayjs3().add(60, "minute").unix(),
21011
21045
  data: functionHash,
21012
21046
  nonce: nonce.toString()
21013
21047
  };
@@ -21054,7 +21088,7 @@ var Account = class {
21054
21088
  // src/manager/seamless/index.ts
21055
21089
  import CryptoJS from "crypto-js";
21056
21090
  import { toUtf8Bytes, keccak256, hexlify, ethers as ethers9, isHexString, getBytes, ZeroAddress as ZeroAddress2 } from "ethers";
21057
- import dayjs3 from "dayjs";
21091
+ import dayjs4 from "dayjs";
21058
21092
 
21059
21093
  // src/utils/index.ts
21060
21094
  function getChainDomainConfig(chainId, address) {
@@ -21327,7 +21361,7 @@ var Seamless = class {
21327
21361
  throw new MyxSDKError("INSUFFICIENT_BALANCE" /* InsufficientBalance */, "Insufficient balance");
21328
21362
  }
21329
21363
  }
21330
- const deadline = dayjs3().add(60, "minute").unix();
21364
+ const deadline = dayjs4().add(60, "minute").unix();
21331
21365
  let permitParams = [];
21332
21366
  if (approve2) {
21333
21367
  try {
@@ -21552,7 +21586,7 @@ var MyxClient = class {
21552
21586
  this.account = new Account(this.configManager, this.logger, this.utils, this);
21553
21587
  this.seamless = new Seamless(this.configManager, this.logger, this.utils, this.account);
21554
21588
  this.markets = new Markets(this.configManager, this.utils);
21555
- this.position = new Position(this.configManager, this.logger, this.utils);
21589
+ this.position = new Position(this.configManager, this.logger, this.utils, this.seamless);
21556
21590
  this.order = new Order(this.configManager, this.logger, this.utils, this.seamless, this.account);
21557
21591
  this.subscription = new SubScription(this.configManager, this.logger);
21558
21592
  const lp = MxSDK.getInstance();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myx-trade/sdk",
3
- "version": "0.1.113",
3
+ "version": "0.1.115",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"