@myx-trade/sdk 0.1.80 → 0.1.82

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
@@ -1184,6 +1184,11 @@ interface AccessTokenResponse {
1184
1184
  interface MyxClientConfig {
1185
1185
  chainId: number;
1186
1186
  signer?: Signer;
1187
+ seamlessAccount?: {
1188
+ masterAddress: string;
1189
+ wallet: ethers$1.Wallet | null;
1190
+ authorized: boolean;
1191
+ };
1187
1192
  walletClient?: WalletClient;
1188
1193
  brokerAddress: string;
1189
1194
  isTestnet?: boolean;
@@ -1200,6 +1205,11 @@ declare class ConfigManager {
1200
1205
  constructor(config: MyxClientConfig);
1201
1206
  clear(): void;
1202
1207
  startSeamlessMode(open: boolean): void;
1208
+ updateSeamlessWallet({ wallet, authorized, masterAddress }: {
1209
+ wallet?: ethers$1.Wallet;
1210
+ authorized?: boolean;
1211
+ masterAddress?: string;
1212
+ }): void;
1203
1213
  updateClientChainId(chainId: number, brokerAddress: string): void;
1204
1214
  auth(params: Pick<MyxClientConfig, "signer" | "getAccessToken">): void;
1205
1215
  private validateConfig;
@@ -1514,9 +1524,6 @@ declare class Seamless {
1514
1524
  private logger;
1515
1525
  private utils;
1516
1526
  private account;
1517
- seamlessWallet: ethers$1.Wallet | null;
1518
- private seamlessWalletAuthorized;
1519
- private seamlessWalletApikey;
1520
1527
  constructor(configManager: ConfigManager, logger: Logger, utils: Utils, account: Account);
1521
1528
  onCheckRelayer(account: string, relayer: string): Promise<boolean>;
1522
1529
  getUSDPermitParams(deadline: number): Promise<{
package/dist/index.d.ts CHANGED
@@ -1184,6 +1184,11 @@ interface AccessTokenResponse {
1184
1184
  interface MyxClientConfig {
1185
1185
  chainId: number;
1186
1186
  signer?: Signer;
1187
+ seamlessAccount?: {
1188
+ masterAddress: string;
1189
+ wallet: ethers$1.Wallet | null;
1190
+ authorized: boolean;
1191
+ };
1187
1192
  walletClient?: WalletClient;
1188
1193
  brokerAddress: string;
1189
1194
  isTestnet?: boolean;
@@ -1200,6 +1205,11 @@ declare class ConfigManager {
1200
1205
  constructor(config: MyxClientConfig);
1201
1206
  clear(): void;
1202
1207
  startSeamlessMode(open: boolean): void;
1208
+ updateSeamlessWallet({ wallet, authorized, masterAddress }: {
1209
+ wallet?: ethers$1.Wallet;
1210
+ authorized?: boolean;
1211
+ masterAddress?: string;
1212
+ }): void;
1203
1213
  updateClientChainId(chainId: number, brokerAddress: string): void;
1204
1214
  auth(params: Pick<MyxClientConfig, "signer" | "getAccessToken">): void;
1205
1215
  private validateConfig;
@@ -1514,9 +1524,6 @@ declare class Seamless {
1514
1524
  private logger;
1515
1525
  private utils;
1516
1526
  private account;
1517
- seamlessWallet: ethers$1.Wallet | null;
1518
- private seamlessWalletAuthorized;
1519
- private seamlessWalletApikey;
1520
1527
  constructor(configManager: ConfigManager, logger: Logger, utils: Utils, account: Account);
1521
1528
  onCheckRelayer(account: string, relayer: string): Promise<boolean>;
1522
1529
  getUSDPermitParams(deadline: number): Promise<{
package/dist/index.js CHANGED
@@ -1841,7 +1841,7 @@ var RotationProvider = class extends import_providers.BaseProvider {
1841
1841
  // package.json
1842
1842
  var package_default = {
1843
1843
  name: "@myx-trade/sdk",
1844
- version: "0.1.80",
1844
+ version: "0.1.82",
1845
1845
  private: false,
1846
1846
  publishConfig: {
1847
1847
  access: "public"
@@ -13668,6 +13668,16 @@ var ConfigManager = class {
13668
13668
  seamlessMode: open
13669
13669
  };
13670
13670
  }
13671
+ updateSeamlessWallet({ wallet, authorized, masterAddress }) {
13672
+ this.config = {
13673
+ ...this.config,
13674
+ seamlessAccount: {
13675
+ masterAddress: masterAddress ?? "",
13676
+ wallet: wallet ?? null,
13677
+ authorized: authorized ?? false
13678
+ }
13679
+ };
13680
+ }
13671
13681
  updateClientChainId(chainId, brokerAddress) {
13672
13682
  this.config = {
13673
13683
  ...this.config,
@@ -14348,12 +14358,9 @@ var Order = class {
14348
14358
  useAccountBalance: false
14349
14359
  };
14350
14360
  this.logger.info("createIncreaseOrder position params--->", data);
14351
- if (config.seamlessMode) {
14352
- const seamlessWallet = this.seamless.seamlessWallet;
14353
- if (!seamlessWallet) {
14354
- throw new MyxSDKError("INVALID_SEAMLESS_WALLET" /* InvalidSeamlessWallet */, "Invalid seamless wallet");
14355
- }
14356
- console.log("seamlessWallet-->", seamlessWallet);
14361
+ const authorized = this.configManager.getConfig().seamlessAccount?.authorized;
14362
+ const seamlessWallet = this.configManager.getConfig().seamlessAccount?.wallet;
14363
+ if (config.seamlessMode && authorized && seamlessWallet) {
14357
14364
  const isEnoughGas = await this.utils.checkSeamlessGas(params.address);
14358
14365
  if (!isEnoughGas) {
14359
14366
  throw new MyxSDKError("INSUFFICIENT_BALANCE" /* InsufficientBalance */, "Insufficient relay fee");
@@ -14362,7 +14369,7 @@ var Order = class {
14362
14369
  const forwarderContract = await getForwarderContract(params.chainId);
14363
14370
  const brokerContract2 = await getSeamlessBrokerContract(
14364
14371
  this.configManager.getConfig().brokerAddress,
14365
- this.seamless.seamlessWallet
14372
+ seamlessWallet
14366
14373
  );
14367
14374
  let functionHash = "";
14368
14375
  if (!params.positionId) {
@@ -14383,7 +14390,7 @@ var Order = class {
14383
14390
  }
14384
14391
  const nonce = await forwarderContract.nonces(seamlessWallet.address);
14385
14392
  const forwardTxParams = {
14386
- from: this.seamless.seamlessWallet?.address ?? "",
14393
+ from: seamlessWallet.address ?? "",
14387
14394
  to: this.configManager.getConfig().brokerAddress,
14388
14395
  value: "0",
14389
14396
  gas: "350000",
@@ -14392,7 +14399,7 @@ var Order = class {
14392
14399
  nonce: nonce.toString()
14393
14400
  };
14394
14401
  this.logger.info("createIncreaseOrder forward tx params --->", forwardTxParams);
14395
- const rs = await this.seamless.forwarderTx(forwardTxParams, this.seamless.seamlessWallet);
14402
+ const rs = await this.seamless.forwarderTx(forwardTxParams, seamlessWallet);
14396
14403
  console.log("rs-->", rs);
14397
14404
  return {
14398
14405
  code: 0,
@@ -19473,14 +19480,16 @@ var Utils = class {
19473
19480
  async getUserTradingFeeRate(assetClass) {
19474
19481
  const config = this.configManager.getConfig();
19475
19482
  const brokerAddress = config.brokerAddress;
19476
- const brokerContract = new import_ethers25.ethers.Contract(
19477
- brokerAddress,
19478
- Broker_default,
19479
- config.signer
19480
- );
19481
19483
  try {
19484
+ const provider = await getJSONProvider(config.chainId);
19485
+ const brokerContract = new import_ethers25.ethers.Contract(
19486
+ brokerAddress,
19487
+ Broker_default,
19488
+ provider
19489
+ );
19490
+ const targetAddress = config.seamlessMode ? config.seamlessAccount?.masterAddress : config.signer?.getAddress();
19482
19491
  const userFeeRate = await brokerContract.getUserFeeRate(
19483
- config.signer?.getAddress(),
19492
+ targetAddress,
19484
19493
  assetClass
19485
19494
  );
19486
19495
  return {
@@ -19506,10 +19515,11 @@ var Utils = class {
19506
19515
  const orderManagerAddress = getContractAddressByChainId(
19507
19516
  config.chainId
19508
19517
  ).ORDER_MANAGER;
19518
+ const provider = await getJSONProvider(config.chainId);
19509
19519
  const orderManagerContract = new import_ethers25.ethers.Contract(
19510
19520
  orderManagerAddress,
19511
19521
  OrderManager_default,
19512
- config.signer
19522
+ provider
19513
19523
  );
19514
19524
  try {
19515
19525
  const networkFee = await orderManagerContract.getExecutionFee(
@@ -20358,13 +20368,15 @@ var Account = class {
20358
20368
  );
20359
20369
  }
20360
20370
  const contractAddress = getContractAddressByChainId(config.chainId);
20371
+ const provider = await getJSONProvider(config.chainId);
20361
20372
  const accountContract = new import_ethers26.ethers.Contract(
20362
20373
  contractAddress.Account,
20363
20374
  Account_default,
20364
- config.signer
20375
+ provider
20365
20376
  );
20366
20377
  try {
20367
- const assets = await accountContract.getTradableAmount(config.signer.getAddress(), poolId);
20378
+ const targetAddress = config.seamlessMode ? config.seamlessAccount?.masterAddress : config.signer?.getAddress();
20379
+ const assets = await accountContract.getTradableAmount(targetAddress, poolId);
20368
20380
  const data = {
20369
20381
  profitIsReleased: assets[0],
20370
20382
  freeAmount: assets[1],
@@ -20634,14 +20646,14 @@ async function signPermit(provider, contract, owner, spender, value, nonce, dead
20634
20646
  return { v, r, s };
20635
20647
  }
20636
20648
  var Seamless = class {
20649
+ // public seamlessWallet: ethers.Wallet | null
20650
+ // private seamlessWalletAuthorized: boolean
20651
+ // private seamlessWalletApikey: string
20637
20652
  constructor(configManager, logger, utils, account) {
20638
20653
  this.configManager = configManager;
20639
20654
  this.logger = logger;
20640
20655
  this.utils = utils;
20641
20656
  this.account = account;
20642
- this.seamlessWallet = null;
20643
- this.seamlessWalletAuthorized = false;
20644
- this.seamlessWalletApikey = "";
20645
20657
  }
20646
20658
  async onCheckRelayer(account, relayer) {
20647
20659
  const config = this.configManager.getConfig();
@@ -20816,9 +20828,12 @@ var Seamless = class {
20816
20828
  });
20817
20829
  const privateKey = decrypted.toString(import_crypto_js.default.enc.Utf8);
20818
20830
  const wallet = new import_ethers27.ethers.Wallet(privateKey);
20819
- this.seamlessWallet = wallet;
20820
20831
  const isAuthorized = await this.onCheckRelayer(masterAddress, wallet.address);
20821
- this.seamlessWalletAuthorized = isAuthorized;
20832
+ this.configManager.updateSeamlessWallet({
20833
+ masterAddress,
20834
+ wallet,
20835
+ authorized: isAuthorized
20836
+ });
20822
20837
  return {
20823
20838
  code: 0,
20824
20839
  data: {
@@ -20838,8 +20853,7 @@ var Seamless = class {
20838
20853
  });
20839
20854
  const privateKey = decrypted.toString(import_crypto_js.default.enc.Utf8);
20840
20855
  const wallet = new import_ethers27.ethers.Wallet(privateKey);
20841
- this.logger.info("export verify seamless wallet-->", wallet.address, this.seamlessWallet);
20842
- if (wallet.address !== this.seamlessWallet?.address) {
20856
+ if (wallet.address !== this.configManager.getConfig().seamlessAccount?.wallet?.address) {
20843
20857
  throw new MyxSDKError("INVALID_PRIVATE_KEY" /* InvalidPrivateKey */, "Invalid private key");
20844
20858
  }
20845
20859
  return {
@@ -20869,9 +20883,11 @@ var Seamless = class {
20869
20883
  padding: import_crypto_js.default.pad.Pkcs7
20870
20884
  });
20871
20885
  const apiKey = encrypted.toString();
20872
- this.seamlessWallet = wallet;
20873
- this.seamlessWalletAuthorized = isAuthorized;
20874
- this.seamlessWalletApikey = apiKey;
20886
+ this.configManager.updateSeamlessWallet({
20887
+ masterAddress,
20888
+ wallet,
20889
+ authorized: isAuthorized
20890
+ });
20875
20891
  return {
20876
20892
  code: 0,
20877
20893
  data: {
@@ -20911,9 +20927,11 @@ var Seamless = class {
20911
20927
  });
20912
20928
  const apiKey = encrypted.toString();
20913
20929
  let isAuthorized = await this.onCheckRelayer(account, wallet.address);
20914
- this.seamlessWallet = wallet;
20915
- this.seamlessWalletAuthorized = isAuthorized;
20916
- this.seamlessWalletApikey = apiKey;
20930
+ this.configManager.updateSeamlessWallet({
20931
+ masterAddress: account,
20932
+ wallet,
20933
+ authorized: isAuthorized
20934
+ });
20917
20935
  const forwarderContract = await getForwarderContract(config.chainId);
20918
20936
  const erc20Address = getContractAddressByChainId(config.chainId).ERC20;
20919
20937
  await this.utils.approveAuthorization({
package/dist/index.mjs CHANGED
@@ -1752,7 +1752,7 @@ var RotationProvider = class extends BaseProvider {
1752
1752
  // package.json
1753
1753
  var package_default = {
1754
1754
  name: "@myx-trade/sdk",
1755
- version: "0.1.80",
1755
+ version: "0.1.82",
1756
1756
  private: false,
1757
1757
  publishConfig: {
1758
1758
  access: "public"
@@ -13579,6 +13579,16 @@ var ConfigManager = class {
13579
13579
  seamlessMode: open
13580
13580
  };
13581
13581
  }
13582
+ updateSeamlessWallet({ wallet, authorized, masterAddress }) {
13583
+ this.config = {
13584
+ ...this.config,
13585
+ seamlessAccount: {
13586
+ masterAddress: masterAddress ?? "",
13587
+ wallet: wallet ?? null,
13588
+ authorized: authorized ?? false
13589
+ }
13590
+ };
13591
+ }
13582
13592
  updateClientChainId(chainId, brokerAddress) {
13583
13593
  this.config = {
13584
13594
  ...this.config,
@@ -14259,12 +14269,9 @@ var Order = class {
14259
14269
  useAccountBalance: false
14260
14270
  };
14261
14271
  this.logger.info("createIncreaseOrder position params--->", data);
14262
- if (config.seamlessMode) {
14263
- const seamlessWallet = this.seamless.seamlessWallet;
14264
- if (!seamlessWallet) {
14265
- throw new MyxSDKError("INVALID_SEAMLESS_WALLET" /* InvalidSeamlessWallet */, "Invalid seamless wallet");
14266
- }
14267
- console.log("seamlessWallet-->", seamlessWallet);
14272
+ const authorized = this.configManager.getConfig().seamlessAccount?.authorized;
14273
+ const seamlessWallet = this.configManager.getConfig().seamlessAccount?.wallet;
14274
+ if (config.seamlessMode && authorized && seamlessWallet) {
14268
14275
  const isEnoughGas = await this.utils.checkSeamlessGas(params.address);
14269
14276
  if (!isEnoughGas) {
14270
14277
  throw new MyxSDKError("INSUFFICIENT_BALANCE" /* InsufficientBalance */, "Insufficient relay fee");
@@ -14273,7 +14280,7 @@ var Order = class {
14273
14280
  const forwarderContract = await getForwarderContract(params.chainId);
14274
14281
  const brokerContract2 = await getSeamlessBrokerContract(
14275
14282
  this.configManager.getConfig().brokerAddress,
14276
- this.seamless.seamlessWallet
14283
+ seamlessWallet
14277
14284
  );
14278
14285
  let functionHash = "";
14279
14286
  if (!params.positionId) {
@@ -14294,7 +14301,7 @@ var Order = class {
14294
14301
  }
14295
14302
  const nonce = await forwarderContract.nonces(seamlessWallet.address);
14296
14303
  const forwardTxParams = {
14297
- from: this.seamless.seamlessWallet?.address ?? "",
14304
+ from: seamlessWallet.address ?? "",
14298
14305
  to: this.configManager.getConfig().brokerAddress,
14299
14306
  value: "0",
14300
14307
  gas: "350000",
@@ -14303,7 +14310,7 @@ var Order = class {
14303
14310
  nonce: nonce.toString()
14304
14311
  };
14305
14312
  this.logger.info("createIncreaseOrder forward tx params --->", forwardTxParams);
14306
- const rs = await this.seamless.forwarderTx(forwardTxParams, this.seamless.seamlessWallet);
14313
+ const rs = await this.seamless.forwarderTx(forwardTxParams, seamlessWallet);
14307
14314
  console.log("rs-->", rs);
14308
14315
  return {
14309
14316
  code: 0,
@@ -19384,14 +19391,16 @@ var Utils = class {
19384
19391
  async getUserTradingFeeRate(assetClass) {
19385
19392
  const config = this.configManager.getConfig();
19386
19393
  const brokerAddress = config.brokerAddress;
19387
- const brokerContract = new ethers7.Contract(
19388
- brokerAddress,
19389
- Broker_default,
19390
- config.signer
19391
- );
19392
19394
  try {
19395
+ const provider = await getJSONProvider(config.chainId);
19396
+ const brokerContract = new ethers7.Contract(
19397
+ brokerAddress,
19398
+ Broker_default,
19399
+ provider
19400
+ );
19401
+ const targetAddress = config.seamlessMode ? config.seamlessAccount?.masterAddress : config.signer?.getAddress();
19393
19402
  const userFeeRate = await brokerContract.getUserFeeRate(
19394
- config.signer?.getAddress(),
19403
+ targetAddress,
19395
19404
  assetClass
19396
19405
  );
19397
19406
  return {
@@ -19417,10 +19426,11 @@ var Utils = class {
19417
19426
  const orderManagerAddress = getContractAddressByChainId(
19418
19427
  config.chainId
19419
19428
  ).ORDER_MANAGER;
19429
+ const provider = await getJSONProvider(config.chainId);
19420
19430
  const orderManagerContract = new ethers7.Contract(
19421
19431
  orderManagerAddress,
19422
19432
  OrderManager_default,
19423
- config.signer
19433
+ provider
19424
19434
  );
19425
19435
  try {
19426
19436
  const networkFee = await orderManagerContract.getExecutionFee(
@@ -20269,13 +20279,15 @@ var Account = class {
20269
20279
  );
20270
20280
  }
20271
20281
  const contractAddress = getContractAddressByChainId(config.chainId);
20282
+ const provider = await getJSONProvider(config.chainId);
20272
20283
  const accountContract = new ethers8.Contract(
20273
20284
  contractAddress.Account,
20274
20285
  Account_default,
20275
- config.signer
20286
+ provider
20276
20287
  );
20277
20288
  try {
20278
- const assets = await accountContract.getTradableAmount(config.signer.getAddress(), poolId);
20289
+ const targetAddress = config.seamlessMode ? config.seamlessAccount?.masterAddress : config.signer?.getAddress();
20290
+ const assets = await accountContract.getTradableAmount(targetAddress, poolId);
20279
20291
  const data = {
20280
20292
  profitIsReleased: assets[0],
20281
20293
  freeAmount: assets[1],
@@ -20545,14 +20557,14 @@ async function signPermit(provider, contract, owner, spender, value, nonce, dead
20545
20557
  return { v, r, s };
20546
20558
  }
20547
20559
  var Seamless = class {
20560
+ // public seamlessWallet: ethers.Wallet | null
20561
+ // private seamlessWalletAuthorized: boolean
20562
+ // private seamlessWalletApikey: string
20548
20563
  constructor(configManager, logger, utils, account) {
20549
20564
  this.configManager = configManager;
20550
20565
  this.logger = logger;
20551
20566
  this.utils = utils;
20552
20567
  this.account = account;
20553
- this.seamlessWallet = null;
20554
- this.seamlessWalletAuthorized = false;
20555
- this.seamlessWalletApikey = "";
20556
20568
  }
20557
20569
  async onCheckRelayer(account, relayer) {
20558
20570
  const config = this.configManager.getConfig();
@@ -20727,9 +20739,12 @@ var Seamless = class {
20727
20739
  });
20728
20740
  const privateKey = decrypted.toString(CryptoJS.enc.Utf8);
20729
20741
  const wallet = new ethers9.Wallet(privateKey);
20730
- this.seamlessWallet = wallet;
20731
20742
  const isAuthorized = await this.onCheckRelayer(masterAddress, wallet.address);
20732
- this.seamlessWalletAuthorized = isAuthorized;
20743
+ this.configManager.updateSeamlessWallet({
20744
+ masterAddress,
20745
+ wallet,
20746
+ authorized: isAuthorized
20747
+ });
20733
20748
  return {
20734
20749
  code: 0,
20735
20750
  data: {
@@ -20749,8 +20764,7 @@ var Seamless = class {
20749
20764
  });
20750
20765
  const privateKey = decrypted.toString(CryptoJS.enc.Utf8);
20751
20766
  const wallet = new ethers9.Wallet(privateKey);
20752
- this.logger.info("export verify seamless wallet-->", wallet.address, this.seamlessWallet);
20753
- if (wallet.address !== this.seamlessWallet?.address) {
20767
+ if (wallet.address !== this.configManager.getConfig().seamlessAccount?.wallet?.address) {
20754
20768
  throw new MyxSDKError("INVALID_PRIVATE_KEY" /* InvalidPrivateKey */, "Invalid private key");
20755
20769
  }
20756
20770
  return {
@@ -20780,9 +20794,11 @@ var Seamless = class {
20780
20794
  padding: CryptoJS.pad.Pkcs7
20781
20795
  });
20782
20796
  const apiKey = encrypted.toString();
20783
- this.seamlessWallet = wallet;
20784
- this.seamlessWalletAuthorized = isAuthorized;
20785
- this.seamlessWalletApikey = apiKey;
20797
+ this.configManager.updateSeamlessWallet({
20798
+ masterAddress,
20799
+ wallet,
20800
+ authorized: isAuthorized
20801
+ });
20786
20802
  return {
20787
20803
  code: 0,
20788
20804
  data: {
@@ -20822,9 +20838,11 @@ var Seamless = class {
20822
20838
  });
20823
20839
  const apiKey = encrypted.toString();
20824
20840
  let isAuthorized = await this.onCheckRelayer(account, wallet.address);
20825
- this.seamlessWallet = wallet;
20826
- this.seamlessWalletAuthorized = isAuthorized;
20827
- this.seamlessWalletApikey = apiKey;
20841
+ this.configManager.updateSeamlessWallet({
20842
+ masterAddress: account,
20843
+ wallet,
20844
+ authorized: isAuthorized
20845
+ });
20828
20846
  const forwarderContract = await getForwarderContract(config.chainId);
20829
20847
  const erc20Address = getContractAddressByChainId(config.chainId).ERC20;
20830
20848
  await this.utils.approveAuthorization({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myx-trade/sdk",
3
- "version": "0.1.80",
3
+ "version": "0.1.82",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"