@orderly.network/core 2.9.1 → 2.10.0-alpha.1

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.js CHANGED
@@ -2049,7 +2049,6 @@ __export(index_exports, {
2049
2049
  BaseWalletAdapter: () => BaseWalletAdapter,
2050
2050
  DefaultConfigStore: () => DefaultConfigStore,
2051
2051
  EVENT_NAMES: () => EVENT_NAMES,
2052
- EtherAdapter: () => EtherAdapter,
2053
2052
  EventEmitter: () => import_eventemitter32.default,
2054
2053
  LocalStorageStore: () => LocalStorageStore,
2055
2054
  MockKeyStore: () => MockKeyStore,
@@ -5441,154 +5440,13 @@ var Assets = class {
5441
5440
  this.contractManger = contractManger;
5442
5441
  this.account = account;
5443
5442
  }
5444
- /**
5445
- * Convert non-USDC asset to USDC manually
5446
- */
5447
- async convert(inputs) {
5448
- if (!this.account.walletAdapter) {
5449
- throw new Error("walletAdapter is undefined");
5450
- }
5451
- if (!this.account.stateValue.address) {
5452
- throw new Error("account address is required");
5453
- }
5454
- const { slippage, amount, converted_asset } = inputs;
5455
- if (!converted_asset || converted_asset.toUpperCase() === "USDC") {
5456
- throw new Error("converted_asset cannot be USDC");
5457
- }
5458
- const payload = {
5459
- slippage,
5460
- amount,
5461
- converted_asset
5462
- };
5463
- const url = "/v1/asset/manual_convert";
5464
- const timestamp = getTimestamp().toString();
5465
- const message = [timestamp, "POST", url, JSON.stringify(payload)].join("");
5466
- const signer = this.account.signer;
5467
- const { publicKey, signature } = await signer.signText(message);
5468
- const res = await this._simpleFetch(url, {
5469
- method: "POST",
5470
- headers: {
5471
- "Content-Type": "application/json",
5472
- "orderly-account-id": this.account.stateValue.accountId,
5473
- "orderly-key": publicKey,
5474
- "orderly-timestamp": timestamp,
5475
- "orderly-signature": signature
5476
- },
5477
- body: JSON.stringify(payload)
5478
- });
5479
- if (!res.success) {
5480
- throw new import_types3.ApiError(res.message, res.code);
5481
- }
5482
- return res;
5483
- }
5484
- async withdraw(inputs) {
5485
- if (!this.account.walletAdapter) {
5486
- throw new Error("walletAdapter is undefined");
5487
- }
5488
- if (!this.account.stateValue.address) {
5489
- throw new Error("account address is required");
5490
- }
5491
- const { chainId, token, allowCrossChainWithdraw, decimals, receiver } = inputs;
5492
- let { amount } = inputs;
5493
- if (typeof amount === "number") {
5494
- amount = amount.toString();
5495
- }
5496
- if (decimals === void 0 || decimals === null) {
5497
- throw new Error("decimals is required");
5498
- }
5499
- const url = "/v1/withdraw_request";
5500
- const nonce = await this.getWithdrawalNonce();
5501
- const timestamp = getTimestamp();
5502
- const messageData = {
5503
- receiver: receiver || this.account.stateValue.address,
5504
- token,
5505
- brokerId: this.configStore.get("brokerId"),
5506
- amount: this.account.walletAdapter.parseUnits(amount, decimals),
5507
- nonce,
5508
- timestamp,
5509
- // domain,
5510
- verifyContract: this.contractManger.getContractInfoByEnv().verifyContractAddress
5511
- };
5512
- const agwGobalAddress = this.account.getAdditionalInfo()?.AGWAddress ?? "";
5513
- if (import_types3.ABSTRACT_CHAIN_ID_MAP.has(chainId) && agwGobalAddress) {
5514
- messageData.receiver = agwGobalAddress;
5515
- }
5516
- const { message, signatured, domain } = await this.account.walletAdapter.generateWithdrawMessage(messageData);
5517
- const data = {
5518
- signature: signatured,
5519
- message,
5520
- userAddress: this.account.stateValue.address,
5521
- verifyingContract: domain.verifyingContract
5522
- };
5523
- const payload = {
5524
- method: "POST",
5525
- url,
5526
- data
5527
- };
5528
- if (allowCrossChainWithdraw) {
5529
- data.message = {
5530
- ...data.message,
5531
- // @ts-ignore
5532
- allowCrossChainWithdraw
5533
- };
5534
- }
5535
- const signature = await this.account.signer.sign(payload, getTimestamp());
5536
- const res = await this._simpleFetch(url, {
5537
- method: "POST",
5538
- body: JSON.stringify(data),
5539
- headers: {
5540
- "Content-Type": "application/json",
5541
- "orderly-account-id": this.account.stateValue.accountId,
5542
- ...signature
5543
- }
5544
- });
5545
- if (!res.success) {
5546
- throw new import_types3.ApiError(res.message, res.code);
5547
- }
5548
- return res;
5549
- }
5550
- async getWithdrawalNonce() {
5551
- const timestamp = getTimestamp().toString();
5552
- const url = "/v1/withdraw_nonce";
5553
- const message = [timestamp, "GET", url].join("");
5554
- const signer = this.account.signer;
5555
- const { publicKey, signature } = await signer.signText(message);
5556
- const res = await this._simpleFetch(url, {
5557
- headers: {
5558
- "orderly-account-id": this.account.stateValue.accountId,
5559
- "orderly-key": publicKey,
5560
- "orderly-timestamp": timestamp,
5561
- "orderly-signature": signature
5562
- }
5563
- });
5564
- if (res.success) {
5565
- return res.data?.withdraw_nonce;
5566
- } else {
5567
- throw new Error(res.message);
5568
- }
5569
- }
5570
- async getNativeBalance(options) {
5571
- if (!this.account.walletAdapter) {
5572
- return "0";
5573
- }
5574
- const result = await this.account.walletAdapter.getBalance();
5575
- return this.account.walletAdapter?.formatUnits(result, options?.decimals);
5576
- }
5577
5443
  async getBalance(address, options) {
5578
5444
  if (!this.account.walletAdapter) {
5579
5445
  return "0";
5580
5446
  }
5581
5447
  const contractInfo = this.contractManger.getContractInfoByEnv();
5582
- const contractAddress = getContractInfoByChainId(
5583
- this.account.walletAdapter.chainId,
5584
- contractInfo
5585
- );
5586
- const tokenAddress = address || contractAddress.tokenAddress;
5587
- let userAddress = this.account.stateValue.address;
5588
- const agwGobalAddress = this.account.getAdditionalInfo()?.AGWAddress ?? "";
5589
- if (import_types3.ABSTRACT_CHAIN_ID_MAP.has(this.account.walletAdapter.chainId) && agwGobalAddress) {
5590
- userAddress = agwGobalAddress;
5591
- }
5448
+ const tokenAddress = address;
5449
+ const userAddress = this.isAbstract() ? this.getAgwGlobalAddress() : this.account.stateValue.address;
5592
5450
  const result = await this.account.walletAdapter?.call(
5593
5451
  tokenAddress,
5594
5452
  "balanceOf",
@@ -5599,44 +5457,40 @@ var Assets = class {
5599
5457
  );
5600
5458
  return this.account.walletAdapter?.formatUnits(result, options?.decimals);
5601
5459
  }
5460
+ async getNativeBalance(options) {
5461
+ if (!this.account.walletAdapter) {
5462
+ return "0";
5463
+ }
5464
+ const result = await this.account.walletAdapter.getBalance();
5465
+ return this.account.walletAdapter?.formatUnits(result, options?.decimals);
5466
+ }
5602
5467
  /**
5603
5468
  * @deprecated use getBalance instead, will be removed in the future
5604
5469
  */
5605
5470
  async getBalanceByAddress(address, options) {
5471
+ return this.getBalance(address, options);
5472
+ }
5473
+ async getBalances(tokens) {
5606
5474
  if (!this.account.walletAdapter) {
5607
- return "0";
5608
- }
5609
- const contractAddress = this.contractManger.getContractInfoByEnv();
5610
- const result = await this.account.walletAdapter?.call(
5611
- address,
5612
- "balanceOf",
5613
- [this.account.stateValue.address],
5614
- {
5615
- abi: contractAddress.erc20Abi
5616
- }
5617
- );
5618
- return this.account.walletAdapter?.formatUnits?.(
5619
- result,
5620
- options?.decimals
5621
- );
5475
+ return {};
5476
+ }
5477
+ const addresses = tokens.map((token) => token.address);
5478
+ const result = await this.account.walletAdapter.getBalances(addresses);
5479
+ const balances = {};
5480
+ result.forEach((item, index) => {
5481
+ const { symbol, decimals } = tokens[index];
5482
+ const balance = this.account.walletAdapter?.formatUnits(item, decimals);
5483
+ balances[symbol] = balance;
5484
+ });
5485
+ return balances;
5622
5486
  }
5623
5487
  async getAllowance(inputs) {
5624
- const { address, vaultAddress: inputVaultAddress, decimals } = inputs;
5488
+ const { address: tokenAddress, vaultAddress, decimals } = inputs;
5625
5489
  if (!this.account.walletAdapter) {
5626
5490
  return "0";
5627
5491
  }
5628
- let userAddress = this.account.stateValue.address;
5492
+ const userAddress = this.isAbstract() ? this.getAgwGlobalAddress() : this.account.stateValue.address;
5629
5493
  const contractInfo = this.contractManger.getContractInfoByEnv();
5630
- const contractAddress = getContractInfoByChainId(
5631
- this.account.walletAdapter.chainId,
5632
- contractInfo
5633
- );
5634
- const vaultAddress = inputVaultAddress || contractAddress.vaultAddress;
5635
- const tokenAddress = address || contractAddress.tokenAddress;
5636
- const agwGobalAddress = this.account.getAdditionalInfo()?.AGWAddress ?? "";
5637
- if (import_types3.ABSTRACT_CHAIN_ID_MAP.has(this.account.walletAdapter.chainId) && agwGobalAddress) {
5638
- userAddress = agwGobalAddress;
5639
- }
5640
5494
  console.info("get allowance", {
5641
5495
  tokenAddress,
5642
5496
  vaultAddress,
@@ -5654,13 +5508,13 @@ var Assets = class {
5654
5508
  }
5655
5509
  async approve(inputs) {
5656
5510
  const {
5657
- address,
5511
+ address: tokenAddress,
5658
5512
  amount,
5659
- vaultAddress: inputVaultAddress,
5513
+ vaultAddress,
5660
5514
  decimals,
5661
5515
  isSetMaxValue
5662
5516
  } = inputs;
5663
- if (!address) {
5517
+ if (!tokenAddress) {
5664
5518
  throw new Error("address is required");
5665
5519
  }
5666
5520
  if (!this.account.walletAdapter) {
@@ -5674,12 +5528,6 @@ var Assets = class {
5674
5528
  parsedAmount = typeof amount !== "undefined" && amount !== "" ? this.account.walletAdapter.parseUnits(amount, decimals) : import_types3.MaxUint256.toString();
5675
5529
  }
5676
5530
  const contractInfo = this.contractManger.getContractInfoByEnv();
5677
- const contractAddress = getContractInfoByChainId(
5678
- this.account.walletAdapter.chainId,
5679
- contractInfo
5680
- );
5681
- const vaultAddress = inputVaultAddress || contractAddress.vaultAddress;
5682
- const tokenAddress = address || contractAddress.tokenAddress;
5683
5531
  console.info("approve", {
5684
5532
  vaultAddress,
5685
5533
  tokenAddress,
@@ -5700,106 +5548,65 @@ var Assets = class {
5700
5548
  */
5701
5549
  async approveByAddress(inputs) {
5702
5550
  const { address, amount, decimals } = inputs;
5703
- if (!this.account.walletAdapter) {
5704
- throw new Error("walletAdapter is undefined");
5705
- }
5706
- if (decimals === void 0 || decimals === null) {
5707
- throw new Error("decimals is required");
5708
- }
5709
5551
  const contractInfo = this.contractManger.getContractInfoByEnv();
5710
5552
  const contractAddress = getContractInfoByChainId(
5711
- this.account.walletAdapter.chainId,
5553
+ this.account.walletAdapter?.chainId,
5712
5554
  contractInfo
5713
5555
  );
5714
- const vaultAddress = contractAddress.vaultAddress;
5715
- const parsedAmount = typeof amount !== "undefined" && amount !== "" ? this.account.walletAdapter.parseUnits(amount, decimals) : import_types3.MaxUint256.toString();
5716
- const result = await this.account.walletAdapter?.call(
5556
+ return this.approve({
5717
5557
  address,
5718
- "approve",
5719
- [vaultAddress, parsedAmount],
5720
- {
5721
- abi: contractInfo.erc20Abi
5722
- }
5723
- );
5724
- return result;
5725
- }
5726
- async getDepositFee(inputs) {
5727
- const {
5728
5558
  amount,
5729
- chain,
5730
- decimals,
5731
- token = "USDC",
5732
- address: tokenAddress
5733
- } = inputs;
5734
- if (!this.account.walletAdapter) {
5735
- throw new Error("walletAdapter is undefined");
5736
- }
5737
- if (decimals === void 0 || decimals === null) {
5738
- throw new Error("decimals is required");
5739
- }
5740
- const brokerId = this.configStore.get("brokerId");
5741
- if (!brokerId) throw new Error("[Assets]:brokerId is required");
5742
- const depositData = {
5743
- accountId: this.account.accountIdHashStr,
5744
- brokerHash: parseBrokerHash(brokerId),
5745
- tokenHash: parseTokenHash(token),
5746
- tokenAmount: this.account.walletAdapter?.parseUnits(amount, decimals)
5747
- };
5748
- const userAddress = this.account.stateValue.address;
5749
- const contractInfo = this.contractManger.getContractInfoByEnv();
5750
- const contractAddress = getContractInfoByChainId(
5751
- this.account.walletAdapter.chainId,
5752
- contractInfo
5753
- );
5754
- let vaultAddress = chain.vault_address;
5755
- if (this.account.walletAdapter.chainNamespace === import_types3.ChainNamespace.solana) {
5756
- if (!vaultAddress) {
5757
- vaultAddress = contractInfo.solanaVaultAddress;
5758
- }
5759
- depositData["tokenAddress"] = tokenAddress || contractInfo.solanaUSDCAddress;
5760
- }
5761
- if (!vaultAddress) {
5762
- vaultAddress = contractAddress.vaultAddress;
5763
- }
5764
- console.info("get deposit fee", {
5765
- userAddress,
5766
- vaultAddress,
5767
- depositData
5559
+ vaultAddress: contractAddress.vaultAddress,
5560
+ decimals
5768
5561
  });
5562
+ }
5563
+ async getDepositFee(inputs) {
5564
+ const { chain } = inputs;
5565
+ const { userAddress, depositData, abi } = await this.getDepositData(inputs);
5566
+ const vaultAddress = chain.vault_address;
5769
5567
  return await this.account.walletAdapter.callOnChain(
5770
5568
  chain,
5771
5569
  vaultAddress,
5772
5570
  "getDepositFee",
5773
5571
  [userAddress, depositData],
5572
+ { abi }
5573
+ );
5574
+ }
5575
+ async estimateDepositGasFee(inputs) {
5576
+ const { vaultAddress, fee } = inputs;
5577
+ const { contractMethod, fromAddress, contractData, abi } = await this.getDepositData(inputs);
5578
+ const gasFee = await this.account.walletAdapter.estimateGasFee(
5579
+ vaultAddress,
5580
+ contractMethod,
5774
5581
  {
5775
- abi: contractInfo.vaultAbi
5776
- }
5582
+ from: fromAddress,
5583
+ to: vaultAddress,
5584
+ data: contractData,
5585
+ value: fee
5586
+ },
5587
+ { abi }
5777
5588
  );
5589
+ console.info("gasFee", gasFee);
5590
+ return gasFee;
5778
5591
  }
5779
- /** deposit native token */
5780
- async depositNativeToken(inputs) {
5781
- const { amount, fee, decimals, token } = inputs;
5592
+ async estimateNativeDepositGasFee(inputs) {
5593
+ const { vaultAddress, fee, amount, decimals, token, address } = inputs;
5782
5594
  const tokenAmount = this.account.walletAdapter?.parseUnits(
5783
5595
  amount,
5784
5596
  decimals
5785
5597
  );
5786
5598
  const value = BigInt(tokenAmount) + fee;
5787
- return this.deposit({
5599
+ return this.estimateDepositGasFee({
5788
5600
  amount,
5789
5601
  fee: value,
5790
5602
  decimals,
5791
- token
5603
+ token,
5604
+ address,
5605
+ vaultAddress
5792
5606
  });
5793
5607
  }
5794
- async deposit(inputs) {
5795
- const {
5796
- amount,
5797
- fee,
5798
- decimals,
5799
- token = "USDC",
5800
- address: tokenAddress,
5801
- vaultAddress: inputVaultAddress
5802
- } = inputs;
5608
+ async getDepositData(inputs) {
5609
+ const { amount, decimals, token = "USDC", address: tokenAddress } = inputs;
5803
5610
  if (!this.account.walletAdapter) {
5804
5611
  throw new Error("walletAdapter is undefined");
5805
5612
  }
@@ -5807,50 +5614,45 @@ var Assets = class {
5807
5614
  throw new Error("decimals is required");
5808
5615
  }
5809
5616
  const brokerId = this.configStore.get("brokerId");
5810
- if (!brokerId) throw new Error("[Assets]:brokerId is required");
5617
+ if (!brokerId) {
5618
+ throw new Error("[Assets]:brokerId is required");
5619
+ }
5811
5620
  const contractInfo = this.contractManger.getContractInfoByEnv();
5812
- const contractAddress = getContractInfoByChainId(
5813
- this.account.walletAdapter.chainId,
5814
- contractInfo
5815
- );
5816
5621
  const depositData = {
5817
5622
  accountId: this.account.accountIdHashStr,
5818
5623
  brokerHash: parseBrokerHash(brokerId),
5819
5624
  tokenHash: parseTokenHash(token),
5820
5625
  tokenAmount: this.account.walletAdapter?.parseUnits(amount, decimals)
5821
5626
  };
5822
- const userAddress = this.account.stateValue.address;
5823
- let vaultAddress = inputVaultAddress;
5824
- if (this.account.walletAdapter.chainNamespace === import_types3.ChainNamespace.solana) {
5825
- if (!vaultAddress) {
5826
- vaultAddress = contractInfo.solanaVaultAddress;
5827
- }
5828
- depositData["tokenAddress"] = tokenAddress || contractInfo.solanaUSDCAddress;
5829
- }
5830
- if (!vaultAddress) {
5831
- vaultAddress = contractAddress.vaultAddress;
5627
+ if (this.isSolana()) {
5628
+ depositData["tokenAddress"] = tokenAddress;
5832
5629
  }
5833
- const agwGobalAddress = this.account.getAdditionalInfo()?.AGWAddress ?? "";
5630
+ const userAddress = this.account.stateValue.address;
5834
5631
  let contractMethod = "deposit";
5835
5632
  let fromAddress = userAddress;
5836
5633
  let contractData = [depositData];
5837
- if (import_types3.ABSTRACT_CHAIN_ID_MAP.has(this.account.walletAdapter.chainId) && agwGobalAddress) {
5838
- console.info(
5839
- "agw address",
5840
- agwGobalAddress,
5841
- this.account.walletAdapter.chainId
5842
- );
5634
+ if (this.isAbstract()) {
5843
5635
  contractMethod = "depositTo";
5844
- fromAddress = agwGobalAddress;
5636
+ fromAddress = this.getAgwGlobalAddress();
5845
5637
  contractData = [userAddress, depositData];
5846
5638
  }
5847
- console.info("xxx deposit", {
5848
- vaultAddress,
5639
+ console.info("deposit data", {
5849
5640
  fromAddress,
5850
5641
  contractMethod,
5851
- contractData,
5852
- fee
5642
+ contractData
5853
5643
  });
5644
+ return {
5645
+ contractMethod,
5646
+ userAddress,
5647
+ fromAddress,
5648
+ depositData,
5649
+ contractData,
5650
+ abi: contractInfo.vaultAbi
5651
+ };
5652
+ }
5653
+ async deposit(inputs) {
5654
+ const { fee, vaultAddress } = inputs;
5655
+ const { contractMethod, fromAddress, contractData, abi } = await this.getDepositData(inputs);
5854
5656
  const result = await this.account.walletAdapter?.sendTransaction(
5855
5657
  vaultAddress,
5856
5658
  contractMethod,
@@ -5860,12 +5662,112 @@ var Assets = class {
5860
5662
  data: contractData,
5861
5663
  value: fee
5862
5664
  },
5863
- {
5864
- abi: contractInfo.vaultAbi
5865
- }
5665
+ { abi }
5866
5666
  );
5867
5667
  return result;
5868
5668
  }
5669
+ /** deposit native token */
5670
+ async depositNativeToken(inputs) {
5671
+ const { amount, fee, decimals, token, vaultAddress } = inputs;
5672
+ const tokenAmount = this.account.walletAdapter?.parseUnits(
5673
+ amount,
5674
+ decimals
5675
+ );
5676
+ const value = BigInt(tokenAmount) + fee;
5677
+ return this.deposit({
5678
+ amount,
5679
+ fee: value,
5680
+ decimals,
5681
+ token,
5682
+ vaultAddress
5683
+ });
5684
+ }
5685
+ async withdraw(inputs) {
5686
+ if (!this.account.walletAdapter) {
5687
+ throw new Error("walletAdapter is undefined");
5688
+ }
5689
+ if (!this.account.stateValue.address) {
5690
+ throw new Error("account address is required");
5691
+ }
5692
+ const { chainId, token, allowCrossChainWithdraw, decimals, receiver } = inputs;
5693
+ let { amount } = inputs;
5694
+ if (typeof amount === "number") {
5695
+ amount = amount.toString();
5696
+ }
5697
+ if (decimals === void 0 || decimals === null) {
5698
+ throw new Error("decimals is required");
5699
+ }
5700
+ const url = "/v1/withdraw_request";
5701
+ const nonce = await this.getWithdrawalNonce();
5702
+ const timestamp = getTimestamp();
5703
+ const messageData = {
5704
+ receiver: receiver || this.account.stateValue.address,
5705
+ token,
5706
+ brokerId: this.configStore.get("brokerId"),
5707
+ amount: this.account.walletAdapter.parseUnits(amount, decimals),
5708
+ nonce,
5709
+ timestamp,
5710
+ // domain,
5711
+ verifyContract: this.contractManger.getContractInfoByEnv().verifyContractAddress
5712
+ };
5713
+ const agwGobalAddress = this.account.getAdditionalInfo()?.AGWAddress ?? "";
5714
+ if (import_types3.ABSTRACT_CHAIN_ID_MAP.has(chainId) && agwGobalAddress) {
5715
+ messageData.receiver = agwGobalAddress;
5716
+ }
5717
+ const { message, signatured, domain } = await this.account.walletAdapter.generateWithdrawMessage(messageData);
5718
+ const data = {
5719
+ signature: signatured,
5720
+ message,
5721
+ userAddress: this.account.stateValue.address,
5722
+ verifyingContract: domain.verifyingContract
5723
+ };
5724
+ const payload = {
5725
+ method: "POST",
5726
+ url,
5727
+ data
5728
+ };
5729
+ if (allowCrossChainWithdraw) {
5730
+ data.message = {
5731
+ ...data.message,
5732
+ // @ts-ignore
5733
+ allowCrossChainWithdraw
5734
+ };
5735
+ }
5736
+ const signature = await this.account.signer.sign(payload, getTimestamp());
5737
+ const res = await this._simpleFetch(url, {
5738
+ method: "POST",
5739
+ body: JSON.stringify(data),
5740
+ headers: {
5741
+ "Content-Type": "application/json",
5742
+ "orderly-account-id": this.account.stateValue.accountId,
5743
+ ...signature
5744
+ }
5745
+ });
5746
+ if (!res.success) {
5747
+ throw new import_types3.ApiError(res.message, res.code);
5748
+ }
5749
+ return res;
5750
+ }
5751
+ async getWithdrawalNonce() {
5752
+ const timestamp = getTimestamp().toString();
5753
+ const url = "/v1/withdraw_nonce";
5754
+ const message = [timestamp, "GET", url].join("");
5755
+ const signer = this.account.signer;
5756
+ const { publicKey, signature } = await signer.signText(message);
5757
+ const res = await this._simpleFetch(url, {
5758
+ headers: {
5759
+ "orderly-account-id": this.account.stateValue.accountId,
5760
+ "orderly-key": publicKey,
5761
+ "orderly-timestamp": timestamp,
5762
+ "orderly-signature": signature
5763
+ }
5764
+ });
5765
+ if (res.success) {
5766
+ return res.data?.withdraw_nonce;
5767
+ } else {
5768
+ throw new Error(res.message);
5769
+ }
5770
+ }
5869
5771
  async internalTransfer(inputs) {
5870
5772
  if (!this.account.walletAdapter) {
5871
5773
  throw new Error("walletAdapter is undefined");
@@ -5912,6 +5814,46 @@ var Assets = class {
5912
5814
  }
5913
5815
  return res;
5914
5816
  }
5817
+ /**
5818
+ * Convert non-USDC asset to USDC manually
5819
+ */
5820
+ async convert(inputs) {
5821
+ if (!this.account.walletAdapter) {
5822
+ throw new Error("walletAdapter is undefined");
5823
+ }
5824
+ if (!this.account.stateValue.address) {
5825
+ throw new Error("account address is required");
5826
+ }
5827
+ const { slippage, amount, converted_asset } = inputs;
5828
+ if (!converted_asset || converted_asset.toUpperCase() === "USDC") {
5829
+ throw new Error("converted_asset cannot be USDC");
5830
+ }
5831
+ const payload = {
5832
+ slippage,
5833
+ amount,
5834
+ converted_asset
5835
+ };
5836
+ const url = "/v1/asset/manual_convert";
5837
+ const timestamp = getTimestamp().toString();
5838
+ const message = [timestamp, "POST", url, JSON.stringify(payload)].join("");
5839
+ const signer = this.account.signer;
5840
+ const { publicKey, signature } = await signer.signText(message);
5841
+ const res = await this._simpleFetch(url, {
5842
+ method: "POST",
5843
+ headers: {
5844
+ "Content-Type": "application/json",
5845
+ "orderly-account-id": this.account.stateValue.accountId,
5846
+ "orderly-key": publicKey,
5847
+ "orderly-timestamp": timestamp,
5848
+ "orderly-signature": signature
5849
+ },
5850
+ body: JSON.stringify(payload)
5851
+ });
5852
+ if (!res.success) {
5853
+ throw new import_types3.ApiError(res.message, res.code);
5854
+ }
5855
+ return res;
5856
+ }
5915
5857
  async getTransferNonce() {
5916
5858
  const timestamp = getTimestamp().toString();
5917
5859
  const url = "/v1/transfer_nonce";
@@ -5939,6 +5881,16 @@ var Assets = class {
5939
5881
  get usdcAddress() {
5940
5882
  return this.contractManger.getContractInfoByEnv().usdcAddress;
5941
5883
  }
5884
+ isSolana() {
5885
+ return this.account.walletAdapter?.chainNamespace === import_types3.ChainNamespace.solana;
5886
+ }
5887
+ isAbstract() {
5888
+ const agwGobalAddress = this.getAgwGlobalAddress();
5889
+ return agwGobalAddress && import_types3.ABSTRACT_CHAIN_ID_MAP.has(this.account.walletAdapter?.chainId);
5890
+ }
5891
+ getAgwGlobalAddress() {
5892
+ return this.account.getAdditionalInfo()?.AGWAddress ?? "";
5893
+ }
5942
5894
  };
5943
5895
 
5944
5896
  // src/repository.ts
@@ -7086,138 +7038,6 @@ var BaseWalletAdapter = class {
7086
7038
 
7087
7039
  // src/wallet/index.ts
7088
7040
  init_shim();
7089
-
7090
- // src/wallet/etherAdapter.ts
7091
- init_shim();
7092
- var import_ethers5 = require("ethers");
7093
- var import_ethers_decode_error = require("ethers-decode-error");
7094
- var errorDecoder = import_ethers_decode_error.ErrorDecoder.create();
7095
- var EtherAdapter = class {
7096
- constructor(options) {
7097
- this._chainId = options.chain.id;
7098
- this.provider = new import_ethers5.BrowserProvider(options.provider, "any");
7099
- this._address = options.address;
7100
- }
7101
- parseUnits(amount, decimals) {
7102
- return import_ethers5.ethers.parseUnits(amount, decimals).toString();
7103
- }
7104
- formatUnits(amount, decimals) {
7105
- return import_ethers5.ethers.formatUnits(amount, decimals);
7106
- }
7107
- getBalance(userAddress) {
7108
- return this.provider.getBalance(userAddress).then(
7109
- (res) => {
7110
- return res;
7111
- },
7112
- (error) => {
7113
- }
7114
- );
7115
- }
7116
- deposit(from, to, amount) {
7117
- throw new Error("Method not implemented.");
7118
- }
7119
- async call(address, method, params, options) {
7120
- const singer = await this.provider?.getSigner();
7121
- const contract = new import_ethers5.ethers.Contract(address, options.abi, singer);
7122
- return contract[method].apply(null, params).catch(async (error) => {
7123
- const parsedEthersError = await parseError(error);
7124
- throw parsedEthersError;
7125
- });
7126
- }
7127
- async callOnChain(chain, address, method, params, options) {
7128
- const provider = new import_ethers5.ethers.JsonRpcProvider(chain.public_rpc_url);
7129
- const contract = new import_ethers5.ethers.Contract(address, options.abi, provider);
7130
- return contract[method].apply(null, params).catch(async (error) => {
7131
- const parsedEthersError = await parseError(error);
7132
- throw parsedEthersError;
7133
- });
7134
- }
7135
- get chainId() {
7136
- return this._chainId;
7137
- }
7138
- set chainId(chainId) {
7139
- this._chainId = chainId;
7140
- }
7141
- get addresses() {
7142
- return this._address;
7143
- }
7144
- async send(method, params) {
7145
- return await this.provider?.send(method, params);
7146
- }
7147
- async sendTransaction(contractAddress, method, payload, options) {
7148
- const singer = await this.provider?.getSigner();
7149
- if (!singer) {
7150
- throw new Error("singer is not exist");
7151
- }
7152
- const contract = new import_ethers5.ethers.Contract(
7153
- contractAddress,
7154
- options.abi,
7155
- this.provider
7156
- );
7157
- const encodeFunctionData = contract.interface.encodeFunctionData(
7158
- method,
7159
- payload.data
7160
- );
7161
- const tx = {
7162
- from: payload.from,
7163
- to: payload.to,
7164
- data: encodeFunctionData,
7165
- value: payload.value
7166
- };
7167
- try {
7168
- const result = await singer.sendTransaction(tx);
7169
- return result;
7170
- } catch (error) {
7171
- const parsedEthersError = await parseError(error);
7172
- throw parsedEthersError;
7173
- }
7174
- }
7175
- async getTransactionRecipect(txHash) {
7176
- await this.provider.getTransactionReceipt(txHash);
7177
- }
7178
- async pollTransactionReceiptWithBackoff(txHash, baseInterval = 1e3, maxInterval = 6e3, maxRetries = 30) {
7179
- let interval = baseInterval;
7180
- let retries = 0;
7181
- while (retries < maxRetries) {
7182
- try {
7183
- const receipt = await this.provider.getTransactionReceipt(txHash);
7184
- if (receipt) {
7185
- return receipt;
7186
- }
7187
- } catch (error) {
7188
- }
7189
- await new Promise((resolve) => setTimeout(resolve, interval));
7190
- interval = Math.min(interval * 2, maxInterval);
7191
- retries++;
7192
- }
7193
- throw new Error("Transaction did not complete after maximum retries.");
7194
- }
7195
- async estimateGas(tx) {
7196
- const gas = await this.provider.estimateGas(tx);
7197
- return (0, import_ethers5.toNumber)(gas);
7198
- }
7199
- async signTypedData(address, data) {
7200
- return await this.provider?.send("eth_signTypedData_v4", [address, data]);
7201
- }
7202
- async verify(data, signature) {
7203
- const { domain, types, message } = data;
7204
- const recovered = import_ethers5.ethers.verifyTypedData(domain, types, message, signature);
7205
- }
7206
- on(eventName, listener) {
7207
- this.provider?.on(eventName, listener);
7208
- }
7209
- off(eventName, listener) {
7210
- this.provider?.off(eventName, listener);
7211
- }
7212
- getContract(address, abi) {
7213
- const contract = new import_ethers5.ethers.Contract(address, abi, this.provider);
7214
- return contract;
7215
- }
7216
- };
7217
- async function parseError(rawError) {
7218
- const error = await errorDecoder.decode(rawError);
7219
- return error;
7220
- }
7221
7041
  // Annotate the CommonJS export names for ESM import in node:
7222
7042
  0 && (module.exports = {
7223
7043
  API_URLS,
@@ -7229,7 +7049,6 @@ async function parseError(rawError) {
7229
7049
  BaseWalletAdapter,
7230
7050
  DefaultConfigStore,
7231
7051
  EVENT_NAMES,
7232
- EtherAdapter,
7233
7052
  EventEmitter,
7234
7053
  LocalStorageStore,
7235
7054
  MockKeyStore,