stableflow-ai-sdk 2.0.1 → 2.0.3

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.mjs CHANGED
@@ -498,7 +498,8 @@ var ONECLICK_PROXY = {
498
498
  ["Solana"]: "HWk6MsFEGzXxpe9B4mfEHpvVoCwNeVVMFxb5Mi7qNTM",
499
499
  ["Near"]: "stbflow.near",
500
500
  ["Aptos"]: "0x3000ceb3211d23ef73ad1b602a7a99b72020c9ce9537f580ac5bba556ec3bff9",
501
- ["Base"]: "0x7A18854b695BA7efB7229c17D0E1Cd2679481D28"
501
+ ["Base"]: "0x7A18854b695BA7efB7229c17D0E1Cd2679481D28",
502
+ ["X Layer"]: "0xc8dB1175132C64e311D01258dD05D4e2e75fD7b8"
502
503
  };
503
504
  var ONECLICK_PROXY_ABI = [
504
505
  {
@@ -586,26 +587,35 @@ var OneClickService = class {
586
587
  this.offsetTime = 1e3 * 60 * 30;
587
588
  }
588
589
  async quote(params) {
590
+ const {
591
+ wallet,
592
+ fromToken,
593
+ toToken,
594
+ prices,
595
+ amountWei,
596
+ appFees = [],
597
+ swapType = "EXACT_INPUT",
598
+ isProxy = true,
599
+ ...restParams
600
+ } = params;
601
+ const isExactOutput = swapType === "EXACT_OUTPUT";
589
602
  const response = await request(OpenAPI, {
590
603
  method: "POST",
591
604
  url: "/v0/quote",
592
605
  body: {
593
606
  depositMode: "SIMPLE",
594
- swapType: "EXACT_INPUT",
607
+ swapType,
595
608
  depositType: "ORIGIN_CHAIN",
596
609
  sessionId: `session_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
597
610
  recipientType: "DESTINATION_CHAIN",
598
611
  deadline: new Date(Date.now() + this.offsetTime).toISOString(),
599
612
  quoteWaitingTimeMs: 3e3,
600
- appFees: BridgeFee,
613
+ appFees: [
614
+ ...BridgeFee,
615
+ ...appFees
616
+ ],
601
617
  referral: "stableflow",
602
- ...params,
603
- // delete params
604
- wallet: void 0,
605
- fromToken: void 0,
606
- toToken: void 0,
607
- prices: void 0,
608
- amountWei: void 0
618
+ ...restParams
609
619
  },
610
620
  mediaType: "application/json",
611
621
  errors: {
@@ -619,7 +629,10 @@ var OneClickService = class {
619
629
  res.data.estimateTime = res.data?.quote?.timeEstimate;
620
630
  res.data.outputAmount = numberRemoveEndZero(Big(res.data?.quote?.amountOut || 0).div(10 ** params.toToken.decimals).toFixed(params.toToken.decimals, 0));
621
631
  try {
622
- const netFee = Big(params.amount).div(10 ** params.fromToken.decimals).minus(Big(res.data?.quote?.amountOut || 0).div(10 ** params.toToken.decimals));
632
+ let netFee = Big(params.amount).div(10 ** params.fromToken.decimals).minus(Big(res.data?.quote?.amountOut || 0).div(10 ** params.toToken.decimals));
633
+ if (isExactOutput) {
634
+ netFee = Big(res.data?.quote?.amountIn || 0).div(10 ** params.fromToken.decimals).minus(Big(params.amount).div(10 ** params.toToken.decimals));
635
+ }
623
636
  const bridgeFeeValue = BridgeFee.reduce((acc, item) => {
624
637
  return acc.plus(Big(params.amount).div(10 ** params.fromToken.decimals).times(Big(item.fee).div(1e4)));
625
638
  }, Big(0));
@@ -652,14 +665,14 @@ var OneClickService = class {
652
665
  console.log("oneclick estimate failed: %o", error);
653
666
  }
654
667
  const proxyAddress = ONECLICK_PROXY[params.fromToken.chainName];
655
- if (proxyAddress) {
668
+ if (proxyAddress && isProxy) {
656
669
  const proxyResult = await params.wallet.quote(Service.OneClick, {
657
670
  proxyAddress,
658
671
  abi: ONECLICK_PROXY_ABI,
659
672
  fromToken: params.fromToken,
660
673
  refundTo: params.refundTo,
661
674
  recipient: params.recipient,
662
- amountWei: params.amount,
675
+ amountWei: isExactOutput ? res.data?.quote?.amountIn : params.amount,
663
676
  prices: params.prices,
664
677
  depositAddress: res.data?.quote?.depositAddress || DefaultAddresses[params.fromToken.chainType]
665
678
  });
@@ -734,8 +747,10 @@ var USDT0_CONFIG = {
734
747
  chainKey: "ethereum",
735
748
  blockTime: 12,
736
749
  // Ethereum average block time ~12 seconds
737
- confirmations: 15
750
+ confirmations: 15,
738
751
  // Default confirmations from layerzeroscan.com
752
+ lzReceiveOptionGas: 8e4,
753
+ lzReceiveOptionGasLegacy: 2e5
739
754
  },
740
755
  Arbitrum: {
741
756
  contractAddress: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
@@ -746,8 +761,10 @@ var USDT0_CONFIG = {
746
761
  chainKey: "arbitrum",
747
762
  blockTime: 0.25,
748
763
  // Arbitrum average block time ~0.25 seconds
749
- confirmations: 20
764
+ confirmations: 20,
750
765
  // Default confirmations from layerzeroscan.com
766
+ lzReceiveOptionGas: 8e4,
767
+ lzReceiveOptionGasLegacy: 2e5
751
768
  },
752
769
  Polygon: {
753
770
  contractAddress: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
@@ -756,8 +773,11 @@ var USDT0_CONFIG = {
756
773
  chainKey: "polygon",
757
774
  blockTime: 2,
758
775
  // Polygon average block time ~2 seconds
759
- confirmations: 20
776
+ confirmations: 20,
760
777
  // Default confirmations from layerzeroscan.com
778
+ lzReceiveOptionGas: 8e4,
779
+ lzReceiveOptionGasLegacy: 2e5,
780
+ composeOptionGas: 6e5
761
781
  },
762
782
  Optimism: {
763
783
  contractAddress: "0x01bFF41798a0BcF287b996046Ca68b395DbC1071",
@@ -766,8 +786,11 @@ var USDT0_CONFIG = {
766
786
  chainKey: "optimism",
767
787
  blockTime: 2,
768
788
  // Optimism average block time ~2 seconds
769
- confirmations: 20
789
+ confirmations: 20,
770
790
  // Default confirmations from layerzeroscan.com
791
+ lzReceiveOptionGas: 8e4,
792
+ lzReceiveOptionGasLegacy: 2e5,
793
+ composeOptionGas: 6e5
771
794
  },
772
795
  Berachain: {
773
796
  contractAddress: "0x779Ded0c9e1022225f8E0630b35a9b54bE713736",
@@ -777,8 +800,11 @@ var USDT0_CONFIG = {
777
800
  chainKey: "berachain",
778
801
  blockTime: 2,
779
802
  // Optimism average block time ~2 seconds
780
- confirmations: 20
803
+ confirmations: 20,
781
804
  // Default confirmations from layerzeroscan.com
805
+ lzReceiveOptionGas: 8e4,
806
+ lzReceiveOptionGasLegacy: 2e5,
807
+ composeOptionGas: 6e5
782
808
  },
783
809
  Solana: {
784
810
  contractAddress: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
@@ -787,8 +813,11 @@ var USDT0_CONFIG = {
787
813
  chainKey: "solana",
788
814
  blockTime: 0.4,
789
815
  // Solana average block time ~0.4 seconds
790
- confirmations: 32
816
+ confirmations: 32,
791
817
  // Default confirmations from layerzeroscan.com
818
+ lzReceiveOptionGas: 2e5,
819
+ lzReceiveOptionGasLegacy: 2e5,
820
+ composeOptionGas: 5e5
792
821
  },
793
822
  Tron: {
794
823
  contractAddress: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
@@ -797,12 +826,33 @@ var USDT0_CONFIG = {
797
826
  chainKey: "tron",
798
827
  blockTime: 3,
799
828
  // Tron average block time ~3 seconds
800
- confirmations: 5
829
+ confirmations: 5,
830
+ // Default confirmations from layerzeroscan.com
831
+ lzReceiveOptionGas: 3e5,
832
+ lzReceiveOptionGasLegacy: 3e5,
833
+ composeOptionGas: 5e5
834
+ },
835
+ "X Layer": {
836
+ contractAddress: "0x779Ded0c9e1022225f8E0630b35a9b54bE713736",
837
+ oft: "0x94bcca6bdfd6a61817ab0e960bfede4984505554",
838
+ eid: 30274,
839
+ chainKey: "xlayer",
840
+ blockTime: 3,
841
+ // Tron average block time ~3 seconds
842
+ confirmations: 20,
801
843
  // Default confirmations from layerzeroscan.com
844
+ lzReceiveOptionGas: 8e4,
845
+ lzReceiveOptionGasLegacy: 2e5,
846
+ composeOptionGas: 6e5
802
847
  }
803
848
  };
849
+ var LZ_RECEIVE_VALUE = {
850
+ Solana: 2039280
851
+ };
804
852
  var USDT0_DVN_COUNT = 2;
805
- var USDT0_LEGACY_FEE = 1e-4;
853
+ var USDT0_LEGACY_MESH_TRANSFTER_FEE = 3e-4;
854
+ var DATA_HEX_PROTOBUF_EXTRA = 3;
855
+ var SIGNATURE_SIZE = 67;
806
856
 
807
857
  // src/bridges/usdt0/contract.ts
808
858
  var OFT_ABI = [
@@ -3511,17 +3561,6 @@ function calculateEstimateTime(originChain, destinationChain) {
3511
3561
  const sourceTime = sourceBlockTime * blockConfirmations;
3512
3562
  const destinationTime = destinationBlockTime * (2 + dvnCount);
3513
3563
  const totalTime = Math.ceil(sourceTime + destinationTime);
3514
- console.log(`USDT0 estimate time calculation:`, {
3515
- originChain,
3516
- destinationChain,
3517
- sourceBlockTime,
3518
- blockConfirmations,
3519
- destinationBlockTime,
3520
- dvnCount,
3521
- sourceTime,
3522
- destinationTime,
3523
- totalTime
3524
- });
3525
3564
  return totalTime;
3526
3565
  }
3527
3566
  var Usdt0Service = class {
@@ -3572,7 +3611,9 @@ var Usdt0Service = class {
3572
3611
  multiHopComposer: USDT0_CONFIG["Arbitrum"],
3573
3612
  isMultiHopComposer: isMultiHopComposer2,
3574
3613
  isOriginLegacy: isOriginLegacy2,
3575
- isDestinationLegacy: isDestinationLegacy2
3614
+ isDestinationLegacy: isDestinationLegacy2,
3615
+ originLayerzero,
3616
+ destinationLayerzero
3576
3617
  });
3577
3618
  result.estimateTime = estimateTime;
3578
3619
  return result;
@@ -3606,7 +3647,9 @@ var Usdt0Service = class {
3606
3647
  multiHopComposer: USDT0_CONFIG["Arbitrum"],
3607
3648
  isMultiHopComposer,
3608
3649
  isOriginLegacy,
3609
- isDestinationLegacy
3650
+ isDestinationLegacy,
3651
+ originLayerzero,
3652
+ destinationLayerzero
3610
3653
  });
3611
3654
  result.estimateTime = estimateTime;
3612
3655
  return result;
@@ -3629,8 +3672,11 @@ var Usdt0Service = class {
3629
3672
  multiHopComposer: USDT0_CONFIG["Arbitrum"],
3630
3673
  isMultiHopComposer,
3631
3674
  isOriginLegacy,
3632
- isDestinationLegacy
3675
+ isDestinationLegacy,
3676
+ originLayerzero,
3677
+ destinationLayerzero
3633
3678
  });
3679
+ result.estimateTime = estimateTime;
3634
3680
  return result;
3635
3681
  }
3636
3682
  }
@@ -3843,23 +3889,42 @@ var ServiceLogoMap = {
3843
3889
  };
3844
3890
 
3845
3891
  // src/services/SFA.ts
3846
- import Big2 from "big.js";
3892
+ import Big3 from "big.js";
3847
3893
 
3848
3894
  // src/wallets/config/rpcs.ts
3849
- var chainsRpcUrls = {
3850
- "Ethereum": "https://eth.merkle.io",
3851
- "Arbitrum": "https://arb1.arbitrum.io/rpc",
3852
- "BNB Chain": "https://56.rpc.thirdweb.com",
3853
- "Avalanche": "https://api.avax.network/ext/bc/C/rpc",
3854
- "Base": "https://mainnet.base.org",
3855
- "Polygon": "https://polygon-rpc.com",
3856
- "Gnosis": "https://rpc.gnosischain.com",
3857
- "Optimism": "https://mainnet.optimism.io",
3858
- "Berachain": "https://rpc.berachain.com",
3859
- "Tron": "https://api.trongrid.io",
3860
- "Aptos": "https://api.mainnet.aptoslabs.com/v1",
3861
- "Solana": "https://mainnet.helius-rpc.com/?api-key=28fc7f18-acf0-48a1-9e06-bd1b6cba1170",
3862
- "Near": "https://nearinner.deltarpc.com"
3895
+ var NetworkRpcUrlsMap = {
3896
+ "eth": ["https://eth.merkle.io"],
3897
+ "arb": ["https://arb1.arbitrum.io/rpc"],
3898
+ "bsc": ["https://56.rpc.thirdweb.com"],
3899
+ "avax": ["https://api.avax.network/ext/bc/C/rpc"],
3900
+ "base": ["https://mainnet.base.org"],
3901
+ "pol": ["https://polygon-rpc.com"],
3902
+ "gnosis": ["https://rpc.gnosischain.com"],
3903
+ "op": ["https://mainnet.optimism.io"],
3904
+ "bera": ["https://rpc.berachain.com"],
3905
+ "tron": ["https://api.trongrid.io"],
3906
+ "aptos": ["https://api.mainnet.aptoslabs.com/v1"],
3907
+ "sol": ["https://solana-rpc.publicnode.com"],
3908
+ "near": ["https://nearinner.deltarpc.com"],
3909
+ "xlayer": ["https://rpc.xlayer.tech"],
3910
+ "plasma": ["https://rpc.plasma.to"]
3911
+ };
3912
+ var getRpcUrls = (blockchain) => {
3913
+ return NetworkRpcUrlsMap[blockchain] || [];
3914
+ };
3915
+ var setRpcUrls = (urls) => {
3916
+ for (const blockchain in urls) {
3917
+ const prev = NetworkRpcUrlsMap[blockchain] ?? [];
3918
+ const next = urls[blockchain];
3919
+ for (let i = next.length - 1; i >= 0; i--) {
3920
+ const rpc = next[i];
3921
+ if (prev.some((_rpc) => _rpc.toLowerCase() === rpc.toLowerCase())) {
3922
+ continue;
3923
+ }
3924
+ prev.unshift(rpc);
3925
+ }
3926
+ }
3927
+ return NetworkRpcUrlsMap;
3863
3928
  };
3864
3929
 
3865
3930
  // src/wallets/config/chains.ts
@@ -3893,6 +3958,7 @@ var chainTypes = {
3893
3958
  var chains = {
3894
3959
  near: {
3895
3960
  chainName: "Near",
3961
+ blockchain: "near",
3896
3962
  chainIcon: "/chains/near.png",
3897
3963
  chainIconGray: "/chains/near-gray.png",
3898
3964
  chainType: chainTypes.near.value,
@@ -3902,10 +3968,11 @@ var chains = {
3902
3968
  symbol: "NEAR",
3903
3969
  decimals: 24
3904
3970
  },
3905
- rpcUrl: chainsRpcUrls["Near"]
3971
+ rpcUrls: getRpcUrls("near")
3906
3972
  },
3907
3973
  sol: {
3908
3974
  chainName: "Solana",
3975
+ blockchain: "sol",
3909
3976
  chainIcon: "/chains/solana.png",
3910
3977
  chainIconGray: "/chains/solana-gray.png",
3911
3978
  chainType: chainTypes.sol.value,
@@ -3915,10 +3982,11 @@ var chains = {
3915
3982
  symbol: "SOL",
3916
3983
  decimals: 9
3917
3984
  },
3918
- rpcUrl: chainsRpcUrls["Solana"]
3985
+ rpcUrls: getRpcUrls("sol")
3919
3986
  },
3920
3987
  eth: {
3921
3988
  chainName: "Ethereum",
3989
+ blockchain: "eth",
3922
3990
  chainIcon: "/chains/ethereum.png",
3923
3991
  chainIconGray: "/chains/ethereum-gray.png",
3924
3992
  chainType: chainTypes.evm.value,
@@ -3929,10 +3997,11 @@ var chains = {
3929
3997
  symbol: "ETH",
3930
3998
  decimals: 18
3931
3999
  },
3932
- rpcUrl: chainsRpcUrls["Ethereum"]
4000
+ rpcUrls: getRpcUrls("eth")
3933
4001
  },
3934
4002
  arb: {
3935
4003
  chainName: "Arbitrum",
4004
+ blockchain: "arb",
3936
4005
  chainIcon: "/chains/arbitrum.png",
3937
4006
  chainIconGray: "/chains/arbitrum-gray.png",
3938
4007
  chainType: chainTypes.evm.value,
@@ -3943,10 +4012,11 @@ var chains = {
3943
4012
  symbol: "ETH",
3944
4013
  decimals: 18
3945
4014
  },
3946
- rpcUrl: chainsRpcUrls["Arbitrum"]
4015
+ rpcUrls: getRpcUrls("arb")
3947
4016
  },
3948
4017
  bsc: {
3949
4018
  chainName: "BNB Chain",
4019
+ blockchain: "bsc",
3950
4020
  chainIcon: "/chains/bsc.png",
3951
4021
  chainIconGray: "/chains/bsc-gray.png",
3952
4022
  chainType: chainTypes.evm.value,
@@ -3957,10 +4027,11 @@ var chains = {
3957
4027
  symbol: "BNB",
3958
4028
  decimals: 18
3959
4029
  },
3960
- rpcUrl: chainsRpcUrls["BNB Chain"]
4030
+ rpcUrls: getRpcUrls("bsc")
3961
4031
  },
3962
4032
  avax: {
3963
4033
  chainName: "Avalanche",
4034
+ blockchain: "avax",
3964
4035
  chainIcon: "/chains/avalanche.png",
3965
4036
  chainIconGray: "/chains/avalanche-gray.png",
3966
4037
  chainType: chainTypes.evm.value,
@@ -3971,10 +4042,11 @@ var chains = {
3971
4042
  symbol: "AVAX",
3972
4043
  decimals: 18
3973
4044
  },
3974
- rpcUrl: chainsRpcUrls["Avalanche"]
4045
+ rpcUrls: getRpcUrls("avax")
3975
4046
  },
3976
4047
  base: {
3977
4048
  chainName: "Base",
4049
+ blockchain: "base",
3978
4050
  chainIcon: "/chains/base.png",
3979
4051
  chainIconGray: "/chains/base-gray.png",
3980
4052
  chainType: chainTypes.evm.value,
@@ -3985,10 +4057,11 @@ var chains = {
3985
4057
  symbol: "ETH",
3986
4058
  decimals: 18
3987
4059
  },
3988
- rpcUrl: chainsRpcUrls["Base"]
4060
+ rpcUrls: getRpcUrls("base")
3989
4061
  },
3990
4062
  pol: {
3991
4063
  chainName: "Polygon",
4064
+ blockchain: "pol",
3992
4065
  chainIcon: "/chains/polygon.png",
3993
4066
  chainIconGray: "/chains/polygon-gray.png",
3994
4067
  chainType: chainTypes.evm.value,
@@ -3999,10 +4072,11 @@ var chains = {
3999
4072
  symbol: "POL",
4000
4073
  decimals: 18
4001
4074
  },
4002
- rpcUrl: chainsRpcUrls["Polygon"]
4075
+ rpcUrls: getRpcUrls("pol")
4003
4076
  },
4004
4077
  gnosis: {
4005
4078
  chainName: "Gnosis",
4079
+ blockchain: "gnosis",
4006
4080
  chainIcon: "/chains/gnosis.png",
4007
4081
  chainIconGray: "/chains/gnosis-gray.png",
4008
4082
  chainType: chainTypes.evm.value,
@@ -4013,10 +4087,11 @@ var chains = {
4013
4087
  symbol: "XDAI",
4014
4088
  decimals: 18
4015
4089
  },
4016
- rpcUrl: chainsRpcUrls["Gnosis"]
4090
+ rpcUrls: getRpcUrls("gnosis")
4017
4091
  },
4018
4092
  op: {
4019
4093
  chainName: "Optimism",
4094
+ blockchain: "op",
4020
4095
  chainIcon: "/chains/optimism.png",
4021
4096
  chainIconGray: "/chains/optimism-gray.png",
4022
4097
  chainType: chainTypes.evm.value,
@@ -4027,10 +4102,11 @@ var chains = {
4027
4102
  symbol: "ETH",
4028
4103
  decimals: 18
4029
4104
  },
4030
- rpcUrl: chainsRpcUrls["Optimism"]
4105
+ rpcUrls: getRpcUrls("op")
4031
4106
  },
4032
4107
  tron: {
4033
4108
  chainName: "Tron",
4109
+ blockchain: "tron",
4034
4110
  chainIcon: "/chains/tron.png",
4035
4111
  chainIconGray: "/chains/tron-gray.png",
4036
4112
  chainType: chainTypes.tron.value,
@@ -4040,10 +4116,11 @@ var chains = {
4040
4116
  symbol: "TRX",
4041
4117
  decimals: 6
4042
4118
  },
4043
- rpcUrl: chainsRpcUrls["Tron"]
4119
+ rpcUrls: getRpcUrls("tron")
4044
4120
  },
4045
4121
  aptos: {
4046
4122
  chainName: "Aptos",
4123
+ blockchain: "aptos",
4047
4124
  chainIcon: "/chains/aptos.png",
4048
4125
  chainIconGray: "/chains/aptos-gray.png",
4049
4126
  chainType: chainTypes.aptos.value,
@@ -4053,10 +4130,11 @@ var chains = {
4053
4130
  symbol: "APT",
4054
4131
  decimals: 8
4055
4132
  },
4056
- rpcUrl: chainsRpcUrls["Aptos"]
4133
+ rpcUrls: getRpcUrls("aptos")
4057
4134
  },
4058
4135
  bera: {
4059
4136
  chainName: "Berachain",
4137
+ blockchain: "bera",
4060
4138
  chainIcon: "/chains/berachain.png",
4061
4139
  chainIconGray: "/chains/berachain-gray.png",
4062
4140
  chainType: chainTypes.evm.value,
@@ -4067,7 +4145,37 @@ var chains = {
4067
4145
  symbol: "BERA",
4068
4146
  decimals: 18
4069
4147
  },
4070
- rpcUrl: chainsRpcUrls["Berachain"]
4148
+ rpcUrls: getRpcUrls("bera")
4149
+ },
4150
+ xlayer: {
4151
+ chainName: "X Layer",
4152
+ blockchain: "xlayer",
4153
+ chainIcon: "/chains/xlayer.png",
4154
+ chainIconGray: "/chains/xlayer-gray.png",
4155
+ chainType: chainTypes.evm.value,
4156
+ chainId: 196,
4157
+ blockExplorerUrl: "https://www.oklink.com/xlayer/tx/",
4158
+ primaryColor: "#000000",
4159
+ nativeToken: {
4160
+ symbol: "OKB",
4161
+ decimals: 18
4162
+ },
4163
+ rpcUrls: getRpcUrls("xlayer")
4164
+ },
4165
+ plasma: {
4166
+ chainName: "Plasma",
4167
+ blockchain: "plasma",
4168
+ chainIcon: "/chains/plasma.png",
4169
+ chainIconGray: "/chains/plasma-gray.png",
4170
+ chainType: chainTypes.evm.value,
4171
+ chainId: 9745,
4172
+ blockExplorerUrl: "https://plasmascan.to/tx/",
4173
+ primaryColor: "#162F29",
4174
+ nativeToken: {
4175
+ symbol: "XPL",
4176
+ decimals: 18
4177
+ },
4178
+ rpcUrls: getRpcUrls("plasma")
4071
4179
  }
4072
4180
  };
4073
4181
  var chains_default = chains;
@@ -4076,7 +4184,8 @@ var chains_default = chains;
4076
4184
  var usdt = {
4077
4185
  symbol: "USDT",
4078
4186
  decimals: 6,
4079
- icon: "/usdt.png"
4187
+ icon: "/usdt.png",
4188
+ name: "Tether USD"
4080
4189
  };
4081
4190
  var usdtChains = {
4082
4191
  eth: {
@@ -4134,7 +4243,7 @@ var usdtChains = {
4134
4243
  assetId: "nep141:sol-c800a4bd850783ccb82c2b2c7e84175443606352.omft.near",
4135
4244
  contractAddress: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
4136
4245
  ...chains_default.sol,
4137
- services: [Service.OneClick]
4246
+ services: [Service.OneClick, Service.Usdt0]
4138
4247
  },
4139
4248
  tron: {
4140
4249
  ...usdt,
@@ -4156,6 +4265,20 @@ var usdtChains = {
4156
4265
  contractAddress: "0x779Ded0c9e1022225f8E0630b35a9b54bE713736",
4157
4266
  ...chains_default.bera,
4158
4267
  services: [Service.OneClick, Service.Usdt0]
4268
+ },
4269
+ xlayer: {
4270
+ ...usdt,
4271
+ assetId: "nep245:v2_1.omni.hot.tg:196_2fezDCvVYRsG8wrK6deJ2VRPiAS1",
4272
+ contractAddress: "0x779ded0c9e1022225f8e0630b35a9b54be713736",
4273
+ ...chains_default.xlayer,
4274
+ services: [Service.OneClick, Service.Usdt0]
4275
+ },
4276
+ plasma: {
4277
+ ...usdt,
4278
+ assetId: "nep245:v2_1.omni.hot.tg:9745_3aL9skCy1yhPoDB8oKMmRHRN7SJW",
4279
+ contractAddress: "0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb",
4280
+ ...chains_default.plasma,
4281
+ services: [Service.OneClick]
4159
4282
  }
4160
4283
  };
4161
4284
 
@@ -4163,7 +4286,8 @@ var usdtChains = {
4163
4286
  var usdc = {
4164
4287
  symbol: "USDC",
4165
4288
  decimals: 6,
4166
- icon: "/usdc.png"
4289
+ icon: "/usdc.png",
4290
+ name: "USD Coin"
4167
4291
  };
4168
4292
  var usdcChains = {
4169
4293
  eth: {
@@ -4229,6 +4353,13 @@ var usdcChains = {
4229
4353
  contractAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
4230
4354
  ...chains_default.sol,
4231
4355
  services: [Service.OneClick, Service.CCTP]
4356
+ },
4357
+ xlayer: {
4358
+ ...usdc,
4359
+ assetId: "nep245:v2_1.omni.hot.tg:196_2dK9kLNR7Ekq7su8FxNGiUW3djTw",
4360
+ contractAddress: "0x74b7f16337b8972027f6196a17a631ac6de26d22",
4361
+ ...chains_default.xlayer,
4362
+ services: [Service.OneClick]
4232
4363
  }
4233
4364
  };
4234
4365
 
@@ -4248,6 +4379,45 @@ var TransactionStatus = /* @__PURE__ */ ((TransactionStatus2) => {
4248
4379
  return TransactionStatus2;
4249
4380
  })(TransactionStatus || {});
4250
4381
 
4382
+ // src/utils/error.ts
4383
+ import Big2 from "big.js";
4384
+ var formatQuoteError = (error, options) => {
4385
+ const { service, fromToken } = options;
4386
+ const defaultErrorMessage = "Failed to get quote, please try again later";
4387
+ if (service === Service.OneClick) {
4388
+ const getQuoteErrorMessage = () => {
4389
+ const _messageResult = {
4390
+ message: defaultErrorMessage,
4391
+ sourceMessage: error?.response?.data?.message || defaultErrorMessage
4392
+ };
4393
+ if (error?.response?.data?.message && error?.response?.data?.message !== "Internal server error") {
4394
+ if (error?.response?.data?.message === "Failed to get quote") {
4395
+ _messageResult.message = "Amount exceeds max";
4396
+ return _messageResult;
4397
+ }
4398
+ if (error?.response?.data?.message?.includes("Amount is too low for bridge, try at least")) {
4399
+ const match = error.response.data.message.match(/try at least\s+(\d+(?:\.\d+)?)/i);
4400
+ let minimumAmount = match ? match[1] : Big2(1).times(10 ** fromToken.decimals).toFixed(0);
4401
+ minimumAmount = Big2(minimumAmount).div(10 ** fromToken.decimals).toFixed(fromToken.decimals);
4402
+ _messageResult.message = `Amount is too low, at least ${minimumAmount}`;
4403
+ return _messageResult;
4404
+ }
4405
+ return _messageResult;
4406
+ }
4407
+ return _messageResult;
4408
+ };
4409
+ const onclickErrMsg = getQuoteErrorMessage();
4410
+ return {
4411
+ serviceType: service,
4412
+ error: onclickErrMsg.message
4413
+ };
4414
+ }
4415
+ return {
4416
+ serviceType: service,
4417
+ error: error?.message || defaultErrorMessage
4418
+ };
4419
+ };
4420
+
4251
4421
  // src/services/SFA.ts
4252
4422
  var submitOneclickDepositTx = (requestBody) => {
4253
4423
  return request(OpenAPI, {
@@ -4352,10 +4522,10 @@ var SFA = class {
4352
4522
  static async getAllQuote(params) {
4353
4523
  const results = [];
4354
4524
  let { minInputAmount = "1" } = params;
4355
- if (Big2(minInputAmount).lte(0)) {
4525
+ if (Big3(minInputAmount).lte(0)) {
4356
4526
  minInputAmount = "1";
4357
4527
  }
4358
- if (!params.fromToken || !params.fromToken.contractAddress || !params.toToken || !params.toToken.contractAddress || !params.refundTo || !params.recipient || !params.amountWei || Big2(params.amountWei).lte(minInputAmount)) {
4528
+ if (!params.fromToken || !params.fromToken.contractAddress || !params.toToken || !params.toToken.contractAddress || !params.refundTo || !params.recipient || !params.amountWei || Big3(params.amountWei).lte(minInputAmount)) {
4359
4529
  throw new Error("Invalid parameters");
4360
4530
  }
4361
4531
  const formatQuoteParams = (service) => {
@@ -4376,6 +4546,9 @@ var SFA = class {
4376
4546
  _params.destinationAsset = params.toToken.assetId;
4377
4547
  _params.amount = params.amountWei;
4378
4548
  _params.refundType = "ORIGIN_CHAIN";
4549
+ _params.appFees = params.oneclickParams?.appFees;
4550
+ _params.swapType = params.oneclickParams?.swapType;
4551
+ _params.isProxy = params.oneclickParams?.isProxy;
4379
4552
  }
4380
4553
  if (service === Service.Usdt0) {
4381
4554
  _params.originChain = params.fromToken.chainName;
@@ -4404,42 +4577,6 @@ var SFA = class {
4404
4577
  });
4405
4578
  }
4406
4579
  }
4407
- const formatQuoteError = (service, error) => {
4408
- const defaultErrorMessage = "Failed to get quote, please try again later";
4409
- if (service === Service.OneClick) {
4410
- const getQuoteErrorMessage = () => {
4411
- const _messageResult = {
4412
- message: defaultErrorMessage,
4413
- sourceMessage: error?.response?.data?.message || defaultErrorMessage
4414
- };
4415
- if (error?.response?.data?.message && error?.response?.data?.message !== "Internal server error") {
4416
- if (error?.response?.data?.message === "Failed to get quote") {
4417
- _messageResult.message = "Amount exceeds max";
4418
- return _messageResult;
4419
- }
4420
- if (error?.response?.data?.message?.includes("Amount is too low for bridge, try at least")) {
4421
- const match = error.response.data.message.match(/try at least\s+(\d+(?:\.\d+)?)/i);
4422
- let minimumAmount = match ? match[1] : Big2(1).times(10 ** fromToken.decimals).toFixed(0);
4423
- minimumAmount = Big2(minimumAmount).div(10 ** fromToken.decimals).toFixed(fromToken.decimals);
4424
- _messageResult.message = `Amount is too low, at least ${minimumAmount}`;
4425
- return _messageResult;
4426
- }
4427
- return _messageResult;
4428
- }
4429
- return _messageResult;
4430
- };
4431
- const onclickErrMsg = getQuoteErrorMessage();
4432
- results.push({
4433
- serviceType: service,
4434
- error: onclickErrMsg.message
4435
- });
4436
- } else {
4437
- results.push({
4438
- serviceType: service,
4439
- error: error?.message || defaultErrorMessage
4440
- });
4441
- }
4442
- };
4443
4580
  if (params.singleService) {
4444
4581
  const quoteService = quoteServices.find((service) => service.service === params.singleService);
4445
4582
  if (quoteService) {
@@ -4450,7 +4587,8 @@ var SFA = class {
4450
4587
  quote: quoteRes
4451
4588
  });
4452
4589
  } catch (error) {
4453
- formatQuoteError(quoteService.service, error);
4590
+ const _err = formatQuoteError(error, { service: quoteService.service, fromToken });
4591
+ results.push(_err);
4454
4592
  }
4455
4593
  }
4456
4594
  return results;
@@ -4466,7 +4604,8 @@ var SFA = class {
4466
4604
  });
4467
4605
  } catch (error) {
4468
4606
  console.log("%s quote failed: %o", quoteService.service, error);
4469
- formatQuoteError(quoteService.service, error);
4607
+ const _err = formatQuoteError(error, { service: quoteService.service, fromToken });
4608
+ results.push(_err);
4470
4609
  }
4471
4610
  })();
4472
4611
  promises.push(promise);
@@ -4521,7 +4660,7 @@ var SFA = class {
4521
4660
  project: projectMap[serviceType],
4522
4661
  address: params.quote?.quoteParam?.refundTo,
4523
4662
  receive_address: params.quote?.quoteParam?.recipient,
4524
- amount: Big2(params.quote?.quoteParam?.amountWei || 0).div(10 ** (params.quote?.fromToken?.decimals || 6)).toFixed(params.quote?.fromToken?.decimals || 6, 0)
4663
+ amount: Big3(params.quote?.quoteParam?.amountWei || 0).div(10 ** (params.quote?.fromToken?.decimals || 6)).toFixed(params.quote?.fromToken?.decimals || 6, 0)
4525
4664
  };
4526
4665
  if (serviceType === Service.OneClick) {
4527
4666
  reportParams.deposit_address = params.quote?.quote?.depositAddress;
@@ -4608,13 +4747,184 @@ var SFA = class {
4608
4747
  */
4609
4748
  SFA.submitDepositTx = submitOneclickDepositTx;
4610
4749
 
4750
+ // src/services/Hyperliquid.ts
4751
+ import { ethers } from "ethers";
4752
+ import Big4 from "big.js";
4753
+ var SPENDER = "0x2df1c51e09aecf9cacb7bc98cb1742757f163df7";
4754
+ var DESTINATION_TOKEN = usdcChains["arb"];
4755
+ var MIN_AMOUNT = Big4(5).times(10 ** DESTINATION_TOKEN.decimals).toFixed(0);
4756
+ var HyperliquidService = class {
4757
+ async quote(params) {
4758
+ const result = { quote: null, error: null };
4759
+ if (Big4(params.amountWei || 0).lt(MIN_AMOUNT)) {
4760
+ result.error = `Amount is too low, at least ${MIN_AMOUNT}`;
4761
+ return result;
4762
+ }
4763
+ const quoteParams = {
4764
+ ...params,
4765
+ dry: params.dry ?? true,
4766
+ slippageTolerance: params.slippageTolerance * 100,
4767
+ originAsset: params.fromToken.assetId,
4768
+ toToken: DESTINATION_TOKEN,
4769
+ destinationAsset: DESTINATION_TOKEN.assetId,
4770
+ amount: params.amountWei,
4771
+ refundType: "ORIGIN_CHAIN",
4772
+ appFees: params.oneclickParams?.appFees,
4773
+ swapType: "EXACT_OUTPUT",
4774
+ isProxy: false
4775
+ };
4776
+ try {
4777
+ const quoteRes = await ServiceMap[Service.OneClick].quote(quoteParams);
4778
+ result.quote = quoteRes;
4779
+ } catch (error) {
4780
+ const _err = formatQuoteError(error, { service: Service.OneClick, fromToken: params.fromToken });
4781
+ result.error = _err.error;
4782
+ }
4783
+ return result;
4784
+ }
4785
+ async transfer(params) {
4786
+ const {
4787
+ quote,
4788
+ wallet
4789
+ } = params;
4790
+ const sendParams = {
4791
+ wallet,
4792
+ sendParam: quote?.sendParam,
4793
+ fromToken: quote?.quoteParam.fromToken,
4794
+ depositAddress: quote?.quote?.depositAddress,
4795
+ amountWei: quote?.quote?.amountIn
4796
+ };
4797
+ const txhash = await ServiceMap[Service.OneClick].send(sendParams);
4798
+ return txhash;
4799
+ }
4800
+ async deposit(params) {
4801
+ const {
4802
+ evmWallet,
4803
+ evmWalletAddress,
4804
+ quote,
4805
+ txhash
4806
+ } = params;
4807
+ const permitParams = await this.generatePermit({
4808
+ address: evmWalletAddress,
4809
+ evmWallet,
4810
+ amountWei: quote?.quote?.amountOut
4811
+ });
4812
+ const depositParams = {
4813
+ deposit_address: quote?.quote?.depositAddress,
4814
+ from_addr: quote?.quoteParam?.refundTo,
4815
+ from_amount: quote?.quote?.amountIn,
4816
+ from_chain: quote?.quoteParam?.fromToken?.blockchain,
4817
+ from_hash: txhash,
4818
+ from_token: quote?.quoteParam?.fromToken?.contractAddress,
4819
+ sender: quote?.quoteParam?.recipient,
4820
+ to_amount: quote?.quote?.amountOut,
4821
+ to_chain: quote?.quoteParam?.toToken?.blockchain,
4822
+ to_token: quote?.quoteParam?.toToken?.contractAddress,
4823
+ type: Service.OneClick,
4824
+ permit: permitParams
4825
+ };
4826
+ const depositRes = await request(OpenAPI, {
4827
+ method: "POST",
4828
+ url: "/v0/deposit",
4829
+ body: depositParams,
4830
+ mediaType: "application/json",
4831
+ errors: {
4832
+ 400: `Bad Request - Invalid input data`,
4833
+ 401: `Unauthorized - JWT token is invalid`
4834
+ }
4835
+ });
4836
+ return depositRes;
4837
+ }
4838
+ async getStatus(params) {
4839
+ return request(OpenAPI, {
4840
+ method: "GET",
4841
+ url: "/v0/deposit",
4842
+ query: {
4843
+ depositId: params.depositId
4844
+ },
4845
+ mediaType: "application/json",
4846
+ errors: {
4847
+ 400: `Bad Request - Invalid input data`,
4848
+ 401: `Unauthorized - JWT token is invalid`
4849
+ }
4850
+ });
4851
+ }
4852
+ async generatePermit(params) {
4853
+ const {
4854
+ address,
4855
+ evmWallet,
4856
+ amountWei
4857
+ } = params;
4858
+ const tokenAddress = DESTINATION_TOKEN.contractAddress;
4859
+ const name = DESTINATION_TOKEN.name;
4860
+ const chainId = DESTINATION_TOKEN.chainId;
4861
+ const provider = new ethers.JsonRpcProvider(getRpcUrls("arb")[0]);
4862
+ const erc20 = new ethers.Contract(
4863
+ tokenAddress,
4864
+ [
4865
+ "function name() view returns (string)",
4866
+ "function nonces(address) view returns (uint256)",
4867
+ "function decimals() view returns (uint8)"
4868
+ ],
4869
+ provider
4870
+ );
4871
+ const deadline = Math.floor(Date.now() / 1e3) + 86400;
4872
+ const nonce = await erc20.nonces(address);
4873
+ const value = amountWei;
4874
+ const domain = {
4875
+ name,
4876
+ version: "2",
4877
+ chainId: Number(chainId),
4878
+ verifyingContract: tokenAddress
4879
+ };
4880
+ const types = {
4881
+ Permit: [
4882
+ { name: "owner", type: "address" },
4883
+ { name: "spender", type: "address" },
4884
+ { name: "value", type: "uint256" },
4885
+ { name: "nonce", type: "uint256" },
4886
+ { name: "deadline", type: "uint256" }
4887
+ ]
4888
+ };
4889
+ const values = {
4890
+ owner: address,
4891
+ spender: SPENDER,
4892
+ value,
4893
+ nonce: nonce.toString(),
4894
+ deadline
4895
+ };
4896
+ const signature = await evmWallet.signTypedData({
4897
+ domain,
4898
+ types,
4899
+ values
4900
+ });
4901
+ const { v, r, s } = ethers.Signature.from(signature);
4902
+ const permitParams = {
4903
+ amount: value,
4904
+ deadline,
4905
+ owner: address,
4906
+ r,
4907
+ s,
4908
+ spender: SPENDER,
4909
+ token: tokenAddress,
4910
+ v,
4911
+ nonce: Number(nonce)
4912
+ };
4913
+ return permitParams;
4914
+ }
4915
+ };
4916
+ var Hyperliquid = new HyperliquidService();
4917
+ var HyperliquidFromTokens = tokens.filter((token) => !(token.chainName === "Arbitrum" && token.symbol === "USDC"));
4918
+ var HyperliuquidToToken = DESTINATION_TOKEN;
4919
+ var HyperliuquidMinAmount = MIN_AMOUNT;
4920
+
4611
4921
  // src/wallets/near.ts
4612
4922
  import { Buffer as Buffer2 } from "buffer";
4613
- import Big3 from "big.js";
4923
+ import Big5 from "big.js";
4614
4924
  var NearWallet = class {
4615
4925
  constructor(_selector) {
4616
4926
  this.selector = _selector;
4617
- this.rpcUrl = chainsRpcUrls["Near"];
4927
+ this.rpcUrl = getRpcUrls("near")[0];
4618
4928
  }
4619
4929
  async query(contractId, methodName, args = {}) {
4620
4930
  const response = await fetch(this.rpcUrl, {
@@ -4901,10 +5211,10 @@ var NearWallet = class {
4901
5211
  totalGasLimit = totalGasLimit * 120n / 100n;
4902
5212
  const gasPrice = BigInt("100000000");
4903
5213
  const estimateGas = totalGasLimit * gasPrice;
4904
- const estimateGasUsd = Big3(estimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
4905
- result.fees.sourceGasFeeUsd = numberRemoveEndZero(Big3(estimateGasUsd).toFixed(20));
5214
+ const estimateGasUsd = Big5(estimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
5215
+ result.fees.sourceGasFeeUsd = numberRemoveEndZero(Big5(estimateGasUsd).toFixed(20));
4906
5216
  result.estimateSourceGas = estimateGas.toString();
4907
- result.estimateSourceGasUsd = numberRemoveEndZero(Big3(estimateGasUsd).toFixed(20));
5217
+ result.estimateSourceGasUsd = numberRemoveEndZero(Big5(estimateGasUsd).toFixed(20));
4908
5218
  result.sendParam = {
4909
5219
  transactions,
4910
5220
  callbackUrl: "/"
@@ -4914,10 +5224,10 @@ var NearWallet = class {
4914
5224
  const defaultGasLimit = BigInt("80000000000000");
4915
5225
  const gasPrice = BigInt("100000000");
4916
5226
  const estimateGas = defaultGasLimit * gasPrice;
4917
- const estimateGasUsd = Big3(estimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
4918
- result.fees.sourceGasFeeUsd = numberRemoveEndZero(Big3(estimateGasUsd).toFixed(20));
5227
+ const estimateGasUsd = Big5(estimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
5228
+ result.fees.sourceGasFeeUsd = numberRemoveEndZero(Big5(estimateGasUsd).toFixed(20));
4919
5229
  result.estimateSourceGas = estimateGas.toString();
4920
- result.estimateSourceGasUsd = numberRemoveEndZero(Big3(estimateGasUsd).toFixed(20));
5230
+ result.estimateSourceGasUsd = numberRemoveEndZero(Big5(estimateGasUsd).toFixed(20));
4921
5231
  }
4922
5232
  return result;
4923
5233
  }
@@ -4968,12 +5278,14 @@ var NearWallet = class {
4968
5278
 
4969
5279
  // src/wallets/solana.ts
4970
5280
  import {
4971
- Connection,
4972
- PublicKey,
5281
+ Connection as Connection2,
5282
+ PublicKey as PublicKey2,
4973
5283
  Transaction,
4974
5284
  VersionedTransaction,
4975
5285
  SystemProgram,
4976
- LAMPORTS_PER_SOL
5286
+ LAMPORTS_PER_SOL,
5287
+ TransactionInstruction,
5288
+ ComputeBudgetProgram
4977
5289
  } from "@solana/web3.js";
4978
5290
  import {
4979
5291
  getAssociatedTokenAddress,
@@ -4984,7 +5296,7 @@ import {
4984
5296
  getAssociatedTokenAddressSync
4985
5297
  } from "@solana/spl-token";
4986
5298
  import { AnchorProvider, BN, Program } from "@coral-xyz/anchor";
4987
- import Big4 from "big.js";
5299
+ import Big6 from "big.js";
4988
5300
 
4989
5301
  // src/bridges/oneclick/stableflow-proxy.json
4990
5302
  var stableflow_proxy_default = {
@@ -5284,9 +5596,109 @@ var stableflow_proxy_default = {
5284
5596
  };
5285
5597
 
5286
5598
  // src/wallets/solana.ts
5599
+ import { ethers as ethers3 } from "ethers";
5600
+ import { addressToBytes32, Options } from "@layerzerolabs/lz-v2-utilities";
5601
+
5602
+ // src/bridges/usdt0/hop-composer.ts
5603
+ import { ethers as ethers2 } from "ethers";
5604
+ var getHopMsgFee = async (params) => {
5605
+ const {
5606
+ sendParam,
5607
+ toToken
5608
+ } = params;
5609
+ const originLayerzero = USDT0_CONFIG["Arbitrum"];
5610
+ const destinationLayerzero = USDT0_CONFIG[toToken.chainName];
5611
+ let arbitrumOft = originLayerzero.oft;
5612
+ let destinationLayerzeroAddress = destinationLayerzero.oft || destinationLayerzero.oftLegacy;
5613
+ const isDestinationLegacy = destinationLayerzeroAddress === destinationLayerzero.oftLegacy;
5614
+ if (isDestinationLegacy) {
5615
+ arbitrumOft = originLayerzero.oftLegacy || originLayerzero.oft;
5616
+ }
5617
+ const provider = new ethers2.JsonRpcProvider(getRpcUrls("arb")[0]);
5618
+ const oftContractRead = new ethers2.Contract(arbitrumOft, OFT_ABI, provider);
5619
+ try {
5620
+ const msgFee = await oftContractRead.quoteSend.staticCall(sendParam, false);
5621
+ const [nativeFee] = msgFee;
5622
+ return nativeFee * 120n / 100n;
5623
+ } catch (error) {
5624
+ console.log("getHopMsgFee failed: %o", error);
5625
+ throw new Error("Quote multi hop message fee failed");
5626
+ }
5627
+ };
5628
+
5629
+ // src/wallets/utils/layerzero.ts
5630
+ import {
5631
+ PublicKey
5632
+ } from "@solana/web3.js";
5633
+ import { struct, u32, u64, bytes, option, bool } from "@metaplex-foundation/umi/serializers";
5634
+ var SEEDS = {
5635
+ OFT: Buffer.from("OFT"),
5636
+ PEER: Buffer.from("Peer"),
5637
+ CREDITS: Buffer.from("Credits"),
5638
+ EVENT_AUTHORITY: Buffer.from("__event_authority")
5639
+ };
5640
+ var DISCRIMINATOR = {
5641
+ quoteSend: new Uint8Array([207, 0, 49, 214, 160, 211, 76, 211]),
5642
+ send: new Uint8Array([102, 251, 20, 187, 65, 75, 12, 69])
5643
+ };
5644
+ function u32be(n) {
5645
+ const buf = Buffer.alloc(4);
5646
+ buf.writeUInt32BE(n, 0);
5647
+ return buf;
5648
+ }
5649
+ function deriveOftPdas(programId, dstEid) {
5650
+ return {
5651
+ oftStore: PublicKey.findProgramAddressSync([SEEDS.OFT], programId)[0],
5652
+ peer: PublicKey.findProgramAddressSync([SEEDS.PEER, u32be(dstEid)], programId)[0],
5653
+ credits: PublicKey.findProgramAddressSync([SEEDS.CREDITS], programId)[0],
5654
+ eventAuthority: PublicKey.findProgramAddressSync([SEEDS.EVENT_AUTHORITY], programId)[0]
5655
+ };
5656
+ }
5657
+ async function getPeerAddress(connection, programId, dstEid) {
5658
+ const { peer } = deriveOftPdas(programId, dstEid);
5659
+ const info = await connection.getAccountInfo(peer);
5660
+ if (!info) throw new Error(`Peer not found for EID ${dstEid}`);
5661
+ return `0x${info.data.subarray(8, 40).toString("hex")}`;
5662
+ }
5663
+ var quoteSendParamsSerializer = struct([
5664
+ ["dstEid", u32()],
5665
+ ["to", bytes({ size: 32 })],
5666
+ ["amountLd", u64()],
5667
+ ["minAmountLd", u64()],
5668
+ ["extraOptions", bytes({ size: u32() })],
5669
+ ["composeMsg", option(bytes({ size: u32() }))],
5670
+ ["payInLzToken", bool()]
5671
+ ]);
5672
+ function encodeQuoteSend(params) {
5673
+ const paramsData = quoteSendParamsSerializer.serialize(params);
5674
+ const data = new Uint8Array(8 + paramsData.length);
5675
+ data.set(DISCRIMINATOR.quoteSend, 0);
5676
+ data.set(paramsData, 8);
5677
+ return data;
5678
+ }
5679
+ var sendParamsSerializer = struct([
5680
+ ["dstEid", u32()],
5681
+ ["to", bytes({ size: 32 })],
5682
+ ["amountLd", u64()],
5683
+ ["minAmountLd", u64()],
5684
+ ["extraOptions", bytes({ size: u32() })],
5685
+ ["composeMsg", option(bytes({ size: u32() }))],
5686
+ ["nativeFee", u64()],
5687
+ ["lzTokenFee", u64()]
5688
+ ]);
5689
+ function encodeSend(params) {
5690
+ const paramsData = sendParamsSerializer.serialize(params);
5691
+ const data = new Uint8Array(8 + paramsData.length);
5692
+ data.set(DISCRIMINATOR.send, 0);
5693
+ data.set(paramsData, 8);
5694
+ return data;
5695
+ }
5696
+
5697
+ // src/wallets/solana.ts
5698
+ import { buildVersionedTransaction, SendHelper } from "@layerzerolabs/lz-solana-sdk-v2";
5287
5699
  var SolanaWallet = class {
5288
5700
  constructor(options) {
5289
- this.connection = new Connection(chainsRpcUrls["Solana"], "confirmed");
5701
+ this.connection = new Connection2(getRpcUrls("sol")[0], "confirmed");
5290
5702
  this.publicKey = options.publicKey;
5291
5703
  this.signTransaction = options.signer.signTransaction;
5292
5704
  this.signer = options.signer;
@@ -5297,7 +5709,7 @@ var SolanaWallet = class {
5297
5709
  throw new Error("Wallet not connected");
5298
5710
  }
5299
5711
  const fromPubkey = this.publicKey;
5300
- const toPubkey = new PublicKey(to);
5712
+ const toPubkey = new PublicKey2(to);
5301
5713
  const lamports = Math.floor(parseFloat(amount) * LAMPORTS_PER_SOL);
5302
5714
  const transaction = new Transaction().add(
5303
5715
  SystemProgram.transfer({
@@ -5322,8 +5734,8 @@ var SolanaWallet = class {
5322
5734
  throw new Error("Wallet not connected");
5323
5735
  }
5324
5736
  const fromPubkey = this.publicKey;
5325
- const toPubkey = new PublicKey(to);
5326
- const mint = new PublicKey(tokenMint);
5737
+ const toPubkey = new PublicKey2(to);
5738
+ const mint = new PublicKey2(tokenMint);
5327
5739
  const fromTokenAccount = getAssociatedTokenAddressSync(mint, fromPubkey);
5328
5740
  const toTokenAccount = getAssociatedTokenAddressSync(mint, toPubkey);
5329
5741
  const transaction = new Transaction();
@@ -5377,13 +5789,13 @@ var SolanaWallet = class {
5377
5789
  return result;
5378
5790
  }
5379
5791
  async getSOLBalance(account) {
5380
- const publicKey = new PublicKey(account);
5792
+ const publicKey = new PublicKey2(account);
5381
5793
  const balance = await this.connection.getBalance(publicKey);
5382
5794
  return balance;
5383
5795
  }
5384
5796
  async getTokenBalance(tokenMint, account) {
5385
- const mint = new PublicKey(tokenMint);
5386
- const owner = new PublicKey(account);
5797
+ const mint = new PublicKey2(tokenMint);
5798
+ const owner = new PublicKey2(account);
5387
5799
  try {
5388
5800
  const tokenAccount = await getAssociatedTokenAddress(mint, owner);
5389
5801
  const accountInfo = await getAccount(this.connection, tokenAccount);
@@ -5416,8 +5828,8 @@ var SolanaWallet = class {
5416
5828
  let estimatedFee = 5000n;
5417
5829
  const { originAsset, depositAddress } = data;
5418
5830
  if (originAsset !== "SOL" && originAsset !== "sol") {
5419
- const mint = new PublicKey(originAsset);
5420
- const toPubkey = new PublicKey(depositAddress);
5831
+ const mint = new PublicKey2(originAsset);
5832
+ const toPubkey = new PublicKey2(depositAddress);
5421
5833
  const toTokenAccount = getAssociatedTokenAddressSync(mint, toPubkey);
5422
5834
  try {
5423
5835
  await getAccount(this.connection, toTokenAccount);
@@ -5518,6 +5930,8 @@ var SolanaWallet = class {
5518
5930
  return await this.quoteCCTP(params);
5519
5931
  case Service.OneClick:
5520
5932
  return await this.quoteOneClickProxy(params);
5933
+ case Service.Usdt0:
5934
+ return await this.quoteOFT(params);
5521
5935
  default:
5522
5936
  throw new Error(`Unsupported quote type: ${type}`);
5523
5937
  }
@@ -5548,13 +5962,13 @@ var SolanaWallet = class {
5548
5962
  } = params;
5549
5963
  try {
5550
5964
  const result = { fees: {} };
5551
- const PROGRAM_ID = new PublicKey(proxyAddress);
5552
- const STATE_PDA = new PublicKey("9E8az3Y9sdXvM2f3CCH6c9N3iFyNfDryQCZhqDxRYGUw");
5553
- const MINT = new PublicKey(fromToken.contractAddress);
5965
+ const PROGRAM_ID = new PublicKey2(proxyAddress);
5966
+ const STATE_PDA = new PublicKey2("9E8az3Y9sdXvM2f3CCH6c9N3iFyNfDryQCZhqDxRYGUw");
5967
+ const MINT = new PublicKey2(fromToken.contractAddress);
5554
5968
  const AMOUNT = new BN(amountWei);
5555
- const RECIPIENT = new PublicKey(depositAddress);
5969
+ const RECIPIENT = new PublicKey2(depositAddress);
5556
5970
  const sender = this.publicKey;
5557
- const userPubkey = new PublicKey(refundTo || sender.toString());
5971
+ const userPubkey = new PublicKey2(refundTo || sender.toString());
5558
5972
  const provider = new AnchorProvider(this.connection, this.signer, {
5559
5973
  commitment: "confirmed"
5560
5974
  });
@@ -5601,7 +6015,7 @@ var SolanaWallet = class {
5601
6015
  transaction
5602
6016
  };
5603
6017
  const estimatedFee = simulation.value.fee || 5000n;
5604
- const estimateGasUsd = Big4(estimatedFee.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
6018
+ const estimateGasUsd = Big6(estimatedFee.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
5605
6019
  const usd = numberRemoveEndZero(estimateGasUsd.toFixed(20));
5606
6020
  const wei = estimatedFee;
5607
6021
  result.fees.sourceGasFeeUsd = usd;
@@ -5641,13 +6055,13 @@ var SolanaWallet = class {
5641
6055
  estimateSourceGas: void 0,
5642
6056
  estimateSourceGasUsd: void 0,
5643
6057
  estimateTime: 0,
5644
- outputAmount: numberRemoveEndZero(Big4(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0))
6058
+ outputAmount: numberRemoveEndZero(Big6(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0))
5645
6059
  };
5646
- const PROGRAM_ID = new PublicKey(proxyAddress);
5647
- const MINT = new PublicKey(fromToken.contractAddress);
6060
+ const PROGRAM_ID = new PublicKey2(proxyAddress);
6061
+ const MINT = new PublicKey2(fromToken.contractAddress);
5648
6062
  const sender = this.publicKey;
5649
- const userPubkey = new PublicKey(refundTo || sender.toString());
5650
- const [userStatePda] = PublicKey.findProgramAddressSync(
6063
+ const userPubkey = new PublicKey2(refundTo || sender.toString());
6064
+ const [userStatePda] = PublicKey2.findProgramAddressSync(
5651
6065
  [Buffer.from("user"), userPubkey.toBuffer()],
5652
6066
  PROGRAM_ID
5653
6067
  );
@@ -5664,7 +6078,7 @@ var SolanaWallet = class {
5664
6078
  const userTokenAccount = getAssociatedTokenAddressSync(MINT, userPubkey);
5665
6079
  const signatureRes = await cctp_default.quoteSignature({
5666
6080
  address: userPubkey.toString(),
5667
- amount: numberRemoveEndZero(Big4(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0)),
6081
+ amount: numberRemoveEndZero(Big6(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0)),
5668
6082
  destination_domain_id: destinationDomain,
5669
6083
  receipt_address: recipient,
5670
6084
  source_domain_id: sourceDomain,
@@ -5678,13 +6092,13 @@ var SolanaWallet = class {
5678
6092
  signature
5679
6093
  } = signatureRes;
5680
6094
  result.fees.estimateMintGasUsd = numberRemoveEndZero(
5681
- Big4(mint_fee || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals)
6095
+ Big6(mint_fee || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals)
5682
6096
  );
5683
6097
  result.fees.bridgeFeeUsd = numberRemoveEndZero(
5684
- Big4(bridge_fee || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals)
6098
+ Big6(bridge_fee || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals)
5685
6099
  );
5686
6100
  result.outputAmount = numberRemoveEndZero(
5687
- Big4(receipt_amount || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0)
6101
+ Big6(receipt_amount || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0)
5688
6102
  );
5689
6103
  const operatorTx = Transaction.from(Buffer.from(signature, "base64"));
5690
6104
  if (!operatorTx.verifySignatures(false)) {
@@ -5697,7 +6111,7 @@ var SolanaWallet = class {
5697
6111
  sigVerify: false
5698
6112
  });
5699
6113
  const estimatedFee = simulation.value.fee || 5000n;
5700
- const estimateGasUsd = Big4(estimatedFee.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
6114
+ const estimateGasUsd = Big6(estimatedFee.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
5701
6115
  result.fees.estimateDepositGasUsd = numberRemoveEndZero(estimateGasUsd.toFixed(20));
5702
6116
  result.estimateSourceGas = estimatedFee;
5703
6117
  result.estimateSourceGasUsd = numberRemoveEndZero(estimateGasUsd.toFixed(20));
@@ -5708,15 +6122,249 @@ var SolanaWallet = class {
5708
6122
  if (excludeFees4 && excludeFees4.includes(feeKey) || !/Usd$/.test(feeKey)) {
5709
6123
  continue;
5710
6124
  }
5711
- result.totalFeesUsd = Big4(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
6125
+ result.totalFeesUsd = Big6(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
5712
6126
  }
5713
- result.totalFeesUsd = numberRemoveEndZero(Big4(result.totalFeesUsd || 0).toFixed(20));
6127
+ result.totalFeesUsd = numberRemoveEndZero(Big6(result.totalFeesUsd || 0).toFixed(20));
5714
6128
  return result;
5715
6129
  } catch (error) {
5716
6130
  console.log("quoteCCTP failed: %o", error);
5717
6131
  return { errMsg: error.message };
5718
6132
  }
5719
6133
  }
6134
+ async quoteOFT(params) {
6135
+ const {
6136
+ originLayerzeroAddress,
6137
+ destinationLayerzeroAddress,
6138
+ fromToken,
6139
+ toToken,
6140
+ dstEid,
6141
+ refundTo,
6142
+ recipient,
6143
+ amountWei,
6144
+ payInLzToken,
6145
+ slippageTolerance,
6146
+ multiHopComposer,
6147
+ isMultiHopComposer,
6148
+ isOriginLegacy,
6149
+ prices,
6150
+ excludeFees: excludeFees4,
6151
+ originLayerzero
6152
+ } = params;
6153
+ try {
6154
+ const result = {
6155
+ needApprove: false,
6156
+ sendParam: void 0,
6157
+ fees: {},
6158
+ estimateSourceGas: void 0,
6159
+ estimateSourceGasUsd: void 0,
6160
+ outputAmount: numberRemoveEndZero(Big6(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0)),
6161
+ quoteParam: {
6162
+ ...params
6163
+ },
6164
+ totalFeesUsd: void 0,
6165
+ estimateTime: 0
6166
+ };
6167
+ const programId = new PublicKey2(originLayerzeroAddress);
6168
+ const tokenMint = new PublicKey2(fromToken.contractAddress);
6169
+ const quotePayer = new PublicKey2("4NkxtcfRTCxJ1N2j6xENcDLPbiJ3541T6r5BqhTzMD9J");
6170
+ const lookupTable = new PublicKey2("6zcTrmdkiQp6dZHYUxVr6A2XVDSYi44X1rcPtvwNcrXi");
6171
+ const tokenEscrow = new PublicKey2("F1YkdxaiLA1eJt12y3uMAQef48Td3zdJfYhzjphma8hG");
6172
+ const sender = this.publicKey;
6173
+ const userPubkey = new PublicKey2(refundTo || sender.toString());
6174
+ const mintInfo = await this.connection.getParsedAccountInfo(tokenMint);
6175
+ const decimals = (mintInfo.value?.data).parsed.info.decimals;
6176
+ const amountLd = BigInt(amountWei);
6177
+ const slippage = slippageTolerance || 0.01;
6178
+ const minAmountLd = BigInt(Big6(amountWei).times(Big6(1).minus(Big6(slippage).div(100))).toFixed(0));
6179
+ const lzReceiveOptionGas = isOriginLegacy ? originLayerzero.lzReceiveOptionGasLegacy : originLayerzero.lzReceiveOptionGas;
6180
+ const lzReceiveOptionValue = LZ_RECEIVE_VALUE[toToken.chainName] || 0;
6181
+ let _dstEid = dstEid;
6182
+ let to = new Uint8Array(Buffer.from(addressToBytes32(recipient)));
6183
+ let extraOptions = Options.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).toBytes();
6184
+ let composeMsg = null;
6185
+ if (isMultiHopComposer) {
6186
+ _dstEid = multiHopComposer.eid;
6187
+ to = new Uint8Array(Buffer.from(addressToBytes32(multiHopComposer.oftMultiHopComposer)));
6188
+ const composeMsgSendParam = {
6189
+ dstEid,
6190
+ to: addressToBytes32(recipient),
6191
+ amountLD: amountLd,
6192
+ minAmountLD: minAmountLd,
6193
+ extraOptions: Options.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).toHex(),
6194
+ composeMsg: "0x",
6195
+ oftCmd: "0x"
6196
+ };
6197
+ const hopMsgFee = await getHopMsgFee({
6198
+ sendParam: composeMsgSendParam,
6199
+ toToken
6200
+ });
6201
+ extraOptions = Options.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).addExecutorComposeOption(0, originLayerzero.composeOptionGas || 5e5, hopMsgFee).toBytes();
6202
+ const abiCoder = ethers3.AbiCoder.defaultAbiCoder();
6203
+ const composeEncoder = abiCoder.encode(
6204
+ ["tuple(uint32 dstEid, bytes32 to, uint256 amountLD, uint256 minAmountLD, bytes extraOptions, bytes composeMsg, bytes oftCmd)"],
6205
+ [Object.values(composeMsgSendParam)]
6206
+ );
6207
+ composeMsg = ethers3.getBytes(composeEncoder);
6208
+ }
6209
+ const pdas = deriveOftPdas(programId, _dstEid);
6210
+ const peerAddress = await getPeerAddress(this.connection, programId, _dstEid);
6211
+ const tokenSource = await getAssociatedTokenAddress(
6212
+ tokenMint,
6213
+ userPubkey,
6214
+ false,
6215
+ TOKEN_PROGRAM_ID
6216
+ );
6217
+ const sendHelper = new SendHelper();
6218
+ const remainingAccounts = await sendHelper.getQuoteAccounts(
6219
+ this.connection,
6220
+ quotePayer,
6221
+ pdas.oftStore,
6222
+ _dstEid,
6223
+ peerAddress
6224
+ );
6225
+ const ix = new TransactionInstruction({
6226
+ programId,
6227
+ keys: [
6228
+ { pubkey: pdas.oftStore, isSigner: false, isWritable: false },
6229
+ { pubkey: pdas.credits, isSigner: false, isWritable: false },
6230
+ { pubkey: pdas.peer, isSigner: false, isWritable: false },
6231
+ ...remainingAccounts
6232
+ ],
6233
+ data: Buffer.from(
6234
+ encodeQuoteSend({
6235
+ dstEid: _dstEid,
6236
+ to,
6237
+ amountLd,
6238
+ minAmountLd,
6239
+ extraOptions,
6240
+ composeMsg,
6241
+ payInLzToken: false
6242
+ })
6243
+ )
6244
+ });
6245
+ const computeIx = ComputeBudgetProgram.setComputeUnitLimit({ units: 14e5 });
6246
+ const tx = await buildVersionedTransaction(
6247
+ this.connection,
6248
+ quotePayer,
6249
+ [computeIx, ix],
6250
+ void 0,
6251
+ void 0,
6252
+ lookupTable
6253
+ );
6254
+ const sim = await this.connection.simulateTransaction(tx, {
6255
+ sigVerify: false,
6256
+ replaceRecentBlockhash: true
6257
+ });
6258
+ if (sim.value.err) {
6259
+ console.error("Simulation logs:", sim.value.logs);
6260
+ throw new Error(`Quote failed: ${JSON.stringify(sim.value.err)}`);
6261
+ }
6262
+ const prefix = `Program return: ${programId} `;
6263
+ const log = sim.value.logs?.find((l) => l.startsWith(prefix));
6264
+ if (!log) throw new Error("Return data not found");
6265
+ const data = Buffer.from(log.slice(prefix.length), "base64");
6266
+ const nativeFee = data.readBigUInt64LE(0);
6267
+ const lzTokenFee = data.readBigUInt64LE(8);
6268
+ if (prices && fromToken.nativeToken) {
6269
+ const nativeFeeUsd = Big6(nativeFee.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
6270
+ result.fees.nativeFeeUsd = numberRemoveEndZero(nativeFeeUsd.toFixed(20));
6271
+ }
6272
+ result.fees.nativeFee = Big6(nativeFee.toString()).div(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals, 0);
6273
+ if (lzTokenFee > 0n && prices && fromToken) {
6274
+ const lzTokenFeeUsd = Big6(lzTokenFee.toString()).div(10 ** fromToken.decimals).times(getPrice(prices, fromToken.symbol));
6275
+ result.fees.lzTokenFeeUsd = numberRemoveEndZero(lzTokenFeeUsd.toFixed(20));
6276
+ }
6277
+ result.fees.lzTokenFee = lzTokenFee.toString();
6278
+ const sendSendHelper = new SendHelper();
6279
+ const sendRemainingAccounts = await sendSendHelper.getSendAccounts(
6280
+ this.connection,
6281
+ userPubkey,
6282
+ pdas.oftStore,
6283
+ _dstEid,
6284
+ peerAddress
6285
+ );
6286
+ const sendIx = new TransactionInstruction({
6287
+ programId,
6288
+ keys: [
6289
+ { pubkey: userPubkey, isSigner: true, isWritable: true },
6290
+ { pubkey: pdas.peer, isSigner: false, isWritable: false },
6291
+ { pubkey: pdas.oftStore, isSigner: false, isWritable: true },
6292
+ { pubkey: pdas.credits, isSigner: false, isWritable: true },
6293
+ { pubkey: tokenSource, isSigner: false, isWritable: true },
6294
+ { pubkey: tokenEscrow, isSigner: false, isWritable: true },
6295
+ { pubkey: tokenMint, isSigner: false, isWritable: false },
6296
+ { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
6297
+ { pubkey: pdas.eventAuthority, isSigner: false, isWritable: false },
6298
+ { pubkey: programId, isSigner: false, isWritable: false },
6299
+ ...sendRemainingAccounts
6300
+ ],
6301
+ data: Buffer.from(
6302
+ encodeSend({
6303
+ dstEid: _dstEid,
6304
+ to,
6305
+ amountLd,
6306
+ minAmountLd,
6307
+ extraOptions,
6308
+ composeMsg,
6309
+ nativeFee,
6310
+ lzTokenFee: 0n
6311
+ })
6312
+ )
6313
+ });
6314
+ const computeSendIx = ComputeBudgetProgram.setComputeUnitLimit({ units: 4e5 });
6315
+ const sendTx = await buildVersionedTransaction(
6316
+ this.connection,
6317
+ userPubkey,
6318
+ [computeSendIx, sendIx],
6319
+ void 0,
6320
+ void 0,
6321
+ lookupTable
6322
+ );
6323
+ let estimatedFee = 5000n;
6324
+ try {
6325
+ const sendSim = await this.connection.simulateTransaction(sendTx, {
6326
+ sigVerify: false,
6327
+ replaceRecentBlockhash: true
6328
+ });
6329
+ console.log("sendSim: %o", JSON.stringify(sendSim));
6330
+ if (!sendSim.value.err) {
6331
+ estimatedFee = sendSim.value.fee || 5000n;
6332
+ } else {
6333
+ console.warn("Send simulation failed (this is normal in quote phase):", sendSim.value.err);
6334
+ const fee = sendSim.value.fee;
6335
+ if (fee) {
6336
+ estimatedFee = fee;
6337
+ }
6338
+ }
6339
+ } catch (simError) {
6340
+ console.warn("Send simulation error (this is normal in quote phase):", simError.message);
6341
+ }
6342
+ if (prices && fromToken.nativeToken) {
6343
+ const estimateGasUsd = Big6(estimatedFee.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
6344
+ result.fees.estimateSourceGasUsd = numberRemoveEndZero(estimateGasUsd.toFixed(20));
6345
+ result.estimateSourceGasUsd = numberRemoveEndZero(estimateGasUsd.toFixed(20));
6346
+ }
6347
+ result.estimateSourceGas = estimatedFee;
6348
+ result.fees.legacyMeshFeeUsd = numberRemoveEndZero(Big6(amountWei || 0).div(10 ** params.fromToken.decimals).times(USDT0_LEGACY_MESH_TRANSFTER_FEE).toFixed(params.fromToken.decimals));
6349
+ result.outputAmount = numberRemoveEndZero(Big6(Big6(amountWei || 0).div(10 ** params.fromToken.decimals)).minus(result.fees.legacyMeshFeeUsd || 0).toFixed(params.fromToken.decimals, 0));
6350
+ result.sendParam = {
6351
+ transaction: sendTx
6352
+ };
6353
+ if (prices) {
6354
+ for (const feeKey in result.fees) {
6355
+ if (excludeFees4 && excludeFees4.includes(feeKey) || !/Usd$/.test(feeKey)) {
6356
+ continue;
6357
+ }
6358
+ result.totalFeesUsd = Big6(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
6359
+ }
6360
+ result.totalFeesUsd = numberRemoveEndZero(Big6(result.totalFeesUsd || 0).toFixed(20));
6361
+ }
6362
+ return result;
6363
+ } catch (error) {
6364
+ console.log("quoteOFT failed: %o", error);
6365
+ return { errMsg: error.message };
6366
+ }
6367
+ }
5720
6368
  async createAssociatedTokenAddress(params) {
5721
6369
  const {
5722
6370
  tokenMint
@@ -5725,7 +6373,7 @@ var SolanaWallet = class {
5725
6373
  throw new Error("Wallet not connected");
5726
6374
  }
5727
6375
  const ownerPubkey = this.publicKey;
5728
- const mint = new PublicKey(tokenMint);
6376
+ const mint = new PublicKey2(tokenMint);
5729
6377
  const associatedTokenAccount = getAssociatedTokenAddressSync(mint, ownerPubkey);
5730
6378
  console.log("associatedTokenAccount: %o", associatedTokenAccount);
5731
6379
  const createTokenAccount = async () => {
@@ -5801,9 +6449,9 @@ var erc20_default = [
5801
6449
  ];
5802
6450
 
5803
6451
  // src/wallets/evm.ts
5804
- import Big5 from "big.js";
5805
- import { ethers } from "ethers";
5806
- import { Options } from "@layerzerolabs/lz-v2-utilities";
6452
+ import Big7 from "big.js";
6453
+ import { ethers as ethers4 } from "ethers";
6454
+ import { Options as Options2 } from "@layerzerolabs/lz-v2-utilities";
5807
6455
 
5808
6456
  // src/utils/address.ts
5809
6457
  import bs58 from "bs58";
@@ -5833,7 +6481,7 @@ function solanaAddressToBytes32(solanaAddress) {
5833
6481
  }
5834
6482
  return "0x" + Buffer.from(decoded).toString("hex");
5835
6483
  }
5836
- function addressToBytes32(chainType, address) {
6484
+ function addressToBytes322(chainType, address) {
5837
6485
  if (chainType === "evm") {
5838
6486
  return zeroPadValue(address, 32);
5839
6487
  }
@@ -5845,9 +6493,40 @@ function addressToBytes32(chainType, address) {
5845
6493
  }
5846
6494
  }
5847
6495
 
5848
- // src/wallets/evm.ts
5849
- import { Connection as Connection2, PublicKey as PublicKey2 } from "@solana/web3.js";
6496
+ // src/wallets/utils/solana.ts
5850
6497
  import { getAssociatedTokenAddressSync as getAssociatedTokenAddressSync2 } from "@solana/spl-token";
6498
+ import { Connection as Connection3, PublicKey as PublicKey3 } from "@solana/web3.js";
6499
+ var getDestinationAssociatedTokenAddress = async (params) => {
6500
+ const {
6501
+ recipient,
6502
+ toToken
6503
+ } = params;
6504
+ const result = {
6505
+ needCreateTokenAccount: false,
6506
+ associatedTokenAddress: ""
6507
+ };
6508
+ if (toToken.chainType !== "sol") {
6509
+ return result;
6510
+ }
6511
+ try {
6512
+ const connection = new Connection3(getRpcUrls("sol")[0]);
6513
+ const wallet = new PublicKey3(recipient);
6514
+ const TOKEN_MINT = new PublicKey3(toToken.contractAddress);
6515
+ const ata = getAssociatedTokenAddressSync2(TOKEN_MINT, wallet);
6516
+ const accountInfo = await connection.getAccountInfo(ata);
6517
+ console.log("accountInfo: %o", accountInfo);
6518
+ if (!accountInfo) {
6519
+ result.needCreateTokenAccount = true;
6520
+ return result;
6521
+ }
6522
+ result.associatedTokenAddress = ata.toBase58();
6523
+ } catch (error) {
6524
+ console.log("getDestinationAssociatedTokenAddress failed: %o", error);
6525
+ }
6526
+ return result;
6527
+ };
6528
+
6529
+ // src/wallets/evm.ts
5851
6530
  var DEFAULT_GAS_LIMIT = 100000n;
5852
6531
  var EVMWallet = class {
5853
6532
  constructor(_provider, _signer) {
@@ -5859,12 +6538,12 @@ var EVMWallet = class {
5859
6538
  if (originAsset === "eth") {
5860
6539
  const tx2 = await this.signer.sendTransaction({
5861
6540
  to: depositAddress,
5862
- value: ethers.parseEther(amount)
6541
+ value: ethers4.parseEther(amount)
5863
6542
  });
5864
6543
  await tx2.wait();
5865
6544
  return tx2;
5866
6545
  }
5867
- const contract = new ethers.Contract(originAsset, erc20_default, this.signer);
6546
+ const contract = new ethers4.Contract(originAsset, erc20_default, this.signer);
5868
6547
  const tx = await contract.transfer(depositAddress, amount);
5869
6548
  const result = await tx.wait();
5870
6549
  return result.hash;
@@ -5872,14 +6551,15 @@ var EVMWallet = class {
5872
6551
  async getBalance(token, account) {
5873
6552
  try {
5874
6553
  let provider = this.provider;
5875
- if (token.rpcUrl) {
5876
- provider = new ethers.JsonRpcProvider(token.rpcUrl);
6554
+ if (token.rpcUrls) {
6555
+ const providers = token.rpcUrls.map((url) => new ethers4.JsonRpcProvider(url));
6556
+ provider = new ethers4.FallbackProvider(providers);
5877
6557
  }
5878
6558
  if (token.symbol === "eth" || token.symbol === "ETH" || token.symbol === "native") {
5879
6559
  const balance2 = await provider.getBalance(account);
5880
6560
  return balance2.toString();
5881
6561
  }
5882
- const contract = new ethers.Contract(token.contractAddress, erc20_default, provider);
6562
+ const contract = new ethers4.Contract(token.contractAddress, erc20_default, provider);
5883
6563
  const balance = await contract.balanceOf(account);
5884
6564
  return balance.toString();
5885
6565
  } catch (err) {
@@ -5906,11 +6586,11 @@ var EVMWallet = class {
5906
6586
  const tx = {
5907
6587
  from: fromAddress,
5908
6588
  to: depositAddress,
5909
- value: ethers.parseEther(amount)
6589
+ value: ethers4.parseEther(amount)
5910
6590
  };
5911
6591
  gasLimit = await this.provider.estimateGas(tx);
5912
6592
  } else {
5913
- const contract = new ethers.Contract(originAsset, erc20_default, this.signer);
6593
+ const contract = new ethers4.Contract(originAsset, erc20_default, this.signer);
5914
6594
  gasLimit = await contract.transfer.estimateGas(depositAddress, amount);
5915
6595
  }
5916
6596
  gasLimit = gasLimit * 120n / 100n;
@@ -5928,7 +6608,7 @@ var EVMWallet = class {
5928
6608
  contractAddress,
5929
6609
  abi
5930
6610
  } = params;
5931
- return new ethers.Contract(contractAddress, abi, this.signer);
6611
+ return new ethers4.Contract(contractAddress, abi, this.signer);
5932
6612
  }
5933
6613
  async allowance(params) {
5934
6614
  const {
@@ -5937,7 +6617,7 @@ var EVMWallet = class {
5937
6617
  address,
5938
6618
  amountWei
5939
6619
  } = params;
5940
- const contract = new ethers.Contract(contractAddress, erc20_default, this.signer);
6620
+ const contract = new ethers4.Contract(contractAddress, erc20_default, this.signer);
5941
6621
  let allowance = "0";
5942
6622
  try {
5943
6623
  allowance = await contract.allowance(address, spender);
@@ -5948,7 +6628,7 @@ var EVMWallet = class {
5948
6628
  return {
5949
6629
  contract,
5950
6630
  allowance,
5951
- needApprove: Big5(amountWei || 0).gt(allowance || 0)
6631
+ needApprove: Big7(amountWei || 0).gt(allowance || 0)
5952
6632
  };
5953
6633
  }
5954
6634
  async approve(params) {
@@ -5958,10 +6638,10 @@ var EVMWallet = class {
5958
6638
  amountWei,
5959
6639
  isApproveMax = false
5960
6640
  } = params;
5961
- const contract = new ethers.Contract(contractAddress, erc20_default, this.signer);
6641
+ const contract = new ethers4.Contract(contractAddress, erc20_default, this.signer);
5962
6642
  let _amountWei = amountWei;
5963
6643
  if (isApproveMax) {
5964
- _amountWei = ethers.MaxUint256;
6644
+ _amountWei = ethers4.MaxUint256;
5965
6645
  }
5966
6646
  try {
5967
6647
  const tx = await contract.approve(spender, _amountWei);
@@ -5980,13 +6660,13 @@ var EVMWallet = class {
5980
6660
  const feeData = await this.provider.getFeeData();
5981
6661
  const gasPrice = feeData.maxFeePerGas || feeData.gasPrice || BigInt("20000000000");
5982
6662
  const estimateGas = BigInt(gasLimit) * BigInt(gasPrice);
5983
- const estimateGasAmount = Big5(estimateGas.toString()).div(10 ** nativeToken.decimals);
5984
- const estimateGasUsd = Big5(estimateGasAmount).times(price || 1);
6663
+ const estimateGasAmount = Big7(estimateGas.toString()).div(10 ** nativeToken.decimals);
6664
+ const estimateGasUsd = Big7(estimateGasAmount).times(price || 1);
5985
6665
  return {
5986
6666
  gasPrice,
5987
- usd: numberRemoveEndZero(Big5(estimateGasUsd).toFixed(20)),
6667
+ usd: numberRemoveEndZero(Big7(estimateGasUsd).toFixed(20)),
5988
6668
  wei: estimateGas,
5989
- amount: numberRemoveEndZero(Big5(estimateGasAmount).toFixed(nativeToken.decimals))
6669
+ amount: numberRemoveEndZero(Big7(estimateGasAmount).toFixed(nativeToken.decimals))
5990
6670
  };
5991
6671
  }
5992
6672
  async quoteOFT(params) {
@@ -6007,7 +6687,8 @@ var EVMWallet = class {
6007
6687
  multiHopComposer,
6008
6688
  isMultiHopComposer,
6009
6689
  isOriginLegacy,
6010
- isDestinationLegacy
6690
+ isDestinationLegacy,
6691
+ originLayerzero
6011
6692
  } = params;
6012
6693
  const result = {
6013
6694
  needApprove: false,
@@ -6024,12 +6705,11 @@ var EVMWallet = class {
6024
6705
  estimateSourceGasUsd: void 0,
6025
6706
  estimateTime: 0,
6026
6707
  // seconds - dynamically calculated using LayerZero formula
6027
- outputAmount: numberRemoveEndZero(Big5(amountWei || 0).div(10 ** params.fromToken.decimals).toFixed(params.fromToken.decimals, 0))
6708
+ outputAmount: numberRemoveEndZero(Big7(amountWei || 0).div(10 ** params.fromToken.decimals).toFixed(params.fromToken.decimals, 0))
6028
6709
  };
6029
- const oftContract = new ethers.Contract(originLayerzeroAddress, abi, this.signer);
6030
- const oftContractRead = new ethers.Contract(originLayerzeroAddress, abi, this.provider);
6710
+ const oftContract = new ethers4.Contract(originLayerzeroAddress, abi, this.signer);
6711
+ const oftContractRead = new ethers4.Contract(originLayerzeroAddress, abi, this.provider);
6031
6712
  const approvalRequired = await oftContractRead.approvalRequired();
6032
- console.log("%cApprovalRequired: %o", "background:blue;color:white;", approvalRequired);
6033
6713
  if (approvalRequired) {
6034
6714
  try {
6035
6715
  const allowanceResult = await this.allowance({
@@ -6043,42 +6723,52 @@ var EVMWallet = class {
6043
6723
  console.log("Error checking allowance: %o", error);
6044
6724
  }
6045
6725
  }
6726
+ const lzReceiveOptionGas = isOriginLegacy ? originLayerzero.lzReceiveOptionGasLegacy : originLayerzero.lzReceiveOptionGas;
6727
+ let lzReceiveOptionValue = 0;
6728
+ const destATA = await getDestinationAssociatedTokenAddress({
6729
+ recipient,
6730
+ toToken
6731
+ });
6732
+ if (destATA.needCreateTokenAccount) {
6733
+ lzReceiveOptionValue = LZ_RECEIVE_VALUE[toToken.chainName] || 0;
6734
+ }
6046
6735
  const sendParam = {
6047
6736
  dstEid,
6048
- to: addressToBytes32(toToken.chainType, recipient),
6737
+ to: addressToBytes322(toToken.chainType, recipient),
6049
6738
  amountLD: amountWei,
6050
6739
  minAmountLD: 0n,
6051
- extraOptions: "0x0003",
6740
+ extraOptions: Options2.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).toHex(),
6052
6741
  composeMsg: "0x",
6053
6742
  oftCmd: "0x"
6054
6743
  };
6055
6744
  if (isMultiHopComposer) {
6056
6745
  sendParam.dstEid = multiHopComposer.eid;
6057
- sendParam.to = addressToBytes32("evm", multiHopComposer.oftMultiHopComposer);
6058
- sendParam.extraOptions = Options.newOptions().addExecutorLzReceiveOption(250000000n, 0n).toHex();
6059
- const abiCoder = ethers.AbiCoder.defaultAbiCoder();
6746
+ sendParam.to = addressToBytes322("evm", multiHopComposer.oftMultiHopComposer);
6747
+ const composeMsgSendParam = {
6748
+ dstEid,
6749
+ to: addressToBytes322(toToken.chainType, recipient),
6750
+ amountLD: sendParam.amountLD,
6751
+ minAmountLD: sendParam.minAmountLD,
6752
+ extraOptions: Options2.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).toHex(),
6753
+ composeMsg: "0x",
6754
+ oftCmd: "0x"
6755
+ };
6756
+ const hopMsgFee = await getHopMsgFee({
6757
+ sendParam: composeMsgSendParam,
6758
+ toToken
6759
+ });
6760
+ sendParam.extraOptions = Options2.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).addExecutorComposeOption(0, originLayerzero.composeOptionGas || 8e5, hopMsgFee).toHex();
6761
+ const abiCoder = ethers4.AbiCoder.defaultAbiCoder();
6060
6762
  sendParam.composeMsg = abiCoder.encode(
6061
6763
  ["tuple(uint32 dstEid, bytes32 to, uint256 amountLD, uint256 minAmountLD, bytes extraOptions, bytes composeMsg, bytes oftCmd)"],
6062
- [[
6063
- dstEid,
6064
- addressToBytes32(toToken.chainType, recipient),
6065
- sendParam.amountLD,
6066
- sendParam.minAmountLD,
6067
- "0x",
6068
- "0x",
6069
- "0x"
6070
- ]]
6764
+ [Object.values(composeMsgSendParam)]
6071
6765
  );
6072
6766
  }
6073
- if (isDestinationLegacy) {
6074
- result.fees.legacyMeshFeeUsd = numberRemoveEndZero(Big5(amountWei || 0).div(10 ** params.fromToken.decimals).times(3e-4).toFixed(params.fromToken.decimals));
6075
- }
6076
6767
  const oftData = await oftContractRead.quoteOFT.staticCall(sendParam);
6077
6768
  const [, , oftReceipt] = oftData;
6078
6769
  sendParam.minAmountLD = oftReceipt[1] * (1000000n - BigInt(slippageTolerance * 1e4)) / 1000000n;
6079
6770
  const msgFee = await oftContractRead.quoteSend.staticCall(sendParam, payInLzToken);
6080
6771
  result.estimateSourceGas = msgFee[0];
6081
- console.log("%cMsgFee: %o", "background:blue;color:white;", msgFee);
6082
6772
  result.sendParam = {
6083
6773
  contract: oftContract,
6084
6774
  method: "send",
@@ -6092,13 +6782,13 @@ var EVMWallet = class {
6092
6782
  { value: msgFee[0] }
6093
6783
  ]
6094
6784
  };
6095
- console.log("%cParams: %o", "background:blue;color:white;", result.sendParam);
6096
- const nativeFeeUsd = Big5(msgFee[0]?.toString() || 0).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
6097
- result.fees.nativeFeeUsd = numberRemoveEndZero(Big5(nativeFeeUsd).toFixed(20));
6098
- result.fees.lzTokenFeeUsd = numberRemoveEndZero(Big5(msgFee[1]?.toString() || 0).div(10 ** fromToken.decimals).toFixed(20));
6099
- if (!isOriginLegacy && isDestinationLegacy) {
6100
- result.fees.legacyMeshFeeUsd = numberRemoveEndZero(Big5(amountWei || 0).div(10 ** fromToken.decimals).times(USDT0_LEGACY_FEE).toFixed(fromToken.decimals));
6101
- result.outputAmount = numberRemoveEndZero(Big5(Big5(amountWei || 0).div(10 ** params.fromToken.decimals)).minus(result.fees.legacyMeshFeeUsd || 0).toFixed(params.fromToken.decimals, 0));
6785
+ const nativeFeeUsd = Big7(msgFee[0]?.toString() || 0).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
6786
+ result.fees.nativeFee = numberRemoveEndZero(Big7(msgFee[0]?.toString() || 0).div(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals));
6787
+ result.fees.nativeFeeUsd = numberRemoveEndZero(Big7(nativeFeeUsd).toFixed(20));
6788
+ result.fees.lzTokenFeeUsd = numberRemoveEndZero(Big7(msgFee[1]?.toString() || 0).div(10 ** fromToken.decimals).toFixed(20));
6789
+ if (isOriginLegacy || isDestinationLegacy) {
6790
+ result.fees.legacyMeshFeeUsd = numberRemoveEndZero(Big7(amountWei || 0).div(10 ** params.fromToken.decimals).times(USDT0_LEGACY_MESH_TRANSFTER_FEE).toFixed(params.fromToken.decimals));
6791
+ result.outputAmount = numberRemoveEndZero(Big7(Big7(amountWei || 0).div(10 ** params.fromToken.decimals)).minus(result.fees.legacyMeshFeeUsd || 0).toFixed(params.fromToken.decimals, 0));
6102
6792
  }
6103
6793
  try {
6104
6794
  const gasLimit = await oftContract.send.estimateGas(...result.sendParam.param);
@@ -6124,9 +6814,9 @@ var EVMWallet = class {
6124
6814
  if (excludeFees4.includes(feeKey)) {
6125
6815
  continue;
6126
6816
  }
6127
- result.totalFeesUsd = Big5(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
6817
+ result.totalFeesUsd = Big7(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
6128
6818
  }
6129
- result.totalFeesUsd = numberRemoveEndZero(Big5(result.totalFeesUsd).toFixed(20));
6819
+ result.totalFeesUsd = numberRemoveEndZero(Big7(result.totalFeesUsd).toFixed(20));
6130
6820
  return result;
6131
6821
  }
6132
6822
  async sendTransaction(params) {
@@ -6204,22 +6894,18 @@ var EVMWallet = class {
6204
6894
  estimateSourceGas: void 0,
6205
6895
  estimateSourceGasUsd: void 0,
6206
6896
  estimateTime: Math.floor(Math.random() * 8) + 3,
6207
- outputAmount: numberRemoveEndZero(Big5(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0))
6897
+ outputAmount: numberRemoveEndZero(Big7(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0))
6208
6898
  };
6209
- const proxyContract = new ethers.Contract(proxyAddress, abi, this.signer);
6210
- const proxyContractRead = new ethers.Contract(proxyAddress, abi, this.provider);
6899
+ const proxyContract = new ethers4.Contract(proxyAddress, abi, this.signer);
6900
+ const proxyContractRead = new ethers4.Contract(proxyAddress, abi, this.provider);
6211
6901
  let realRecipient = recipient;
6212
- if (toToken.chainType === "sol") {
6213
- const connection = new Connection2(chainsRpcUrls.Solana);
6214
- const wallet = new PublicKey2(recipient);
6215
- const USDC_MINT = new PublicKey2(toToken.contractAddress);
6216
- const ata = getAssociatedTokenAddressSync2(USDC_MINT, wallet);
6217
- const accountInfo = await connection.getAccountInfo(ata);
6218
- if (!accountInfo) {
6219
- result.needCreateTokenAccount = true;
6220
- } else {
6221
- realRecipient = ata.toBase58();
6222
- }
6902
+ const destATA = await getDestinationAssociatedTokenAddress({
6903
+ recipient,
6904
+ toToken
6905
+ });
6906
+ result.needCreateTokenAccount = destATA.needCreateTokenAccount;
6907
+ if (destATA.associatedTokenAddress) {
6908
+ realRecipient = destATA.associatedTokenAddress;
6223
6909
  }
6224
6910
  let userNonce = 0n;
6225
6911
  try {
@@ -6228,7 +6914,7 @@ var EVMWallet = class {
6228
6914
  }
6229
6915
  const signatureRes = await cctp_default.quoteSignature({
6230
6916
  address: refundTo,
6231
- amount: numberRemoveEndZero(Big5(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0)),
6917
+ amount: numberRemoveEndZero(Big7(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0)),
6232
6918
  destination_domain_id: destinationDomain,
6233
6919
  receipt_address: realRecipient,
6234
6920
  source_domain_id: sourceDomain,
@@ -6243,10 +6929,10 @@ var EVMWallet = class {
6243
6929
  signature,
6244
6930
  destination_caller
6245
6931
  } = signatureRes;
6246
- result.fees.estimateMintGasUsd = numberRemoveEndZero(Big5(mint_fee || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals));
6247
- result.fees.bridgeFeeUsd = numberRemoveEndZero(Big5(bridge_fee || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals));
6932
+ result.fees.estimateMintGasUsd = numberRemoveEndZero(Big7(mint_fee || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals));
6933
+ result.fees.bridgeFeeUsd = numberRemoveEndZero(Big7(bridge_fee || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals));
6248
6934
  const chargedAmount = BigInt(amountWei) - BigInt(mint_fee);
6249
- result.outputAmount = numberRemoveEndZero(Big5(receipt_amount || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0));
6935
+ result.outputAmount = numberRemoveEndZero(Big7(receipt_amount || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0));
6250
6936
  const depositParam = [
6251
6937
  // originalAmount
6252
6938
  amountWei,
@@ -6255,11 +6941,11 @@ var EVMWallet = class {
6255
6941
  // destinationDomain
6256
6942
  destinationDomain,
6257
6943
  // mintRecipient
6258
- addressToBytes32(toToken.chainType, realRecipient),
6944
+ addressToBytes322(toToken.chainType, realRecipient),
6259
6945
  // burnToken
6260
6946
  fromToken.contractAddress,
6261
6947
  // destinationCaller
6262
- destination_caller ? addressToBytes32(toToken.chainType, destination_caller) : "0x0000000000000000000000000000000000000000000000000000000000000000",
6948
+ destination_caller ? addressToBytes322(toToken.chainType, destination_caller) : "0x0000000000000000000000000000000000000000000000000000000000000000",
6263
6949
  // maxFee
6264
6950
  max_fee,
6265
6951
  // minFinalityThreshold
@@ -6321,9 +7007,9 @@ var EVMWallet = class {
6321
7007
  if (excludeFees4.includes(feeKey) || !/Usd$/.test(feeKey)) {
6322
7008
  continue;
6323
7009
  }
6324
- result.totalFeesUsd = Big5(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
7010
+ result.totalFeesUsd = Big7(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
6325
7011
  }
6326
- result.totalFeesUsd = numberRemoveEndZero(Big5(result.totalFeesUsd).toFixed(20));
7012
+ result.totalFeesUsd = numberRemoveEndZero(Big7(result.totalFeesUsd).toFixed(20));
6327
7013
  return result;
6328
7014
  }
6329
7015
  async quoteOneClickProxy(params) {
@@ -6349,7 +7035,7 @@ var EVMWallet = class {
6349
7035
  } catch (error) {
6350
7036
  console.log("oneclick check allowance failed: %o", error);
6351
7037
  }
6352
- const proxyContract = new ethers.Contract(proxyAddress, abi, this.signer);
7038
+ const proxyContract = new ethers4.Contract(proxyAddress, abi, this.signer);
6353
7039
  const proxyParam = [
6354
7040
  // tokenAddress
6355
7041
  fromToken.contractAddress,
@@ -6367,18 +7053,18 @@ var EVMWallet = class {
6367
7053
  price: getPrice(prices, fromToken.nativeToken.symbol),
6368
7054
  nativeToken: fromToken.nativeToken
6369
7055
  });
6370
- result.fees.sourceGasFeeUsd = numberRemoveEndZero(Big5(usd).toFixed(20));
7056
+ result.fees.sourceGasFeeUsd = numberRemoveEndZero(Big7(usd).toFixed(20));
6371
7057
  result.estimateSourceGas = wei;
6372
- result.estimateSourceGasUsd = numberRemoveEndZero(Big5(usd).toFixed(20));
7058
+ result.estimateSourceGasUsd = numberRemoveEndZero(Big7(usd).toFixed(20));
6373
7059
  } catch (error) {
6374
7060
  const { usd, wei } = await this.getEstimateGas({
6375
7061
  gasLimit: DEFAULT_GAS_LIMIT,
6376
7062
  price: getPrice(prices, fromToken.nativeToken.symbol),
6377
7063
  nativeToken: fromToken.nativeToken
6378
7064
  });
6379
- result.fees.sourceGasFeeUsd = numberRemoveEndZero(Big5(usd).toFixed(20));
7065
+ result.fees.sourceGasFeeUsd = numberRemoveEndZero(Big7(usd).toFixed(20));
6380
7066
  result.estimateSourceGas = wei;
6381
- result.estimateSourceGasUsd = numberRemoveEndZero(Big5(usd).toFixed(20));
7067
+ result.estimateSourceGasUsd = numberRemoveEndZero(Big7(usd).toFixed(20));
6382
7068
  }
6383
7069
  result.sendParam = {
6384
7070
  method: "proxyTransfer",
@@ -6390,27 +7076,50 @@ var EVMWallet = class {
6390
7076
  };
6391
7077
  return result;
6392
7078
  }
7079
+ async signTypedData(params) {
7080
+ const { domain, types, values } = params;
7081
+ return await this.signer?.signTypedData(domain, types, values);
7082
+ }
6393
7083
  };
6394
7084
 
6395
7085
  // src/wallets/tron.ts
6396
- import { Options as Options2 } from "@layerzerolabs/lz-v2-utilities";
6397
- import { ethers as ethers2 } from "ethers";
6398
- import Big6 from "big.js";
7086
+ import { Options as Options3 } from "@layerzerolabs/lz-v2-utilities";
7087
+ import { ethers as ethers5 } from "ethers";
7088
+ import Big8 from "big.js";
6399
7089
  import { TronWeb } from "tronweb";
7090
+ var DefaultTronWalletAddress = DefaultAddresses["tron"];
7091
+ var getCustomTronWeb = () => {
7092
+ return new TronWeb({
7093
+ fullHost: getRpcUrls("tron")[0],
7094
+ headers: {},
7095
+ privateKey: ""
7096
+ });
7097
+ };
6400
7098
  var TronWallet = class {
6401
7099
  constructor(options) {
6402
7100
  this.signAndSendTransaction = options.signAndSendTransaction;
6403
- this.tronWeb = options.tronWeb;
7101
+ this.address = options.address;
7102
+ const customTronWeb = getCustomTronWeb();
7103
+ customTronWeb.setAddress(this.address || DefaultTronWalletAddress);
7104
+ this.tronWeb = customTronWeb;
6404
7105
  }
6405
7106
  async waitForTronWeb() {
6406
- return new Promise((resolve2, reject) => {
7107
+ return new Promise((resolve2) => {
6407
7108
  if (this.tronWeb) {
7109
+ const address = this.tronWeb.defaultAddress.base58 || DefaultTronWalletAddress;
7110
+ const customTronWeb = getCustomTronWeb();
7111
+ customTronWeb.setAddress(address);
7112
+ this.tronWeb = customTronWeb;
6408
7113
  resolve2(this.tronWeb);
6409
7114
  return;
6410
7115
  }
6411
7116
  const checkTronWeb = () => {
6412
7117
  if (window.tronWeb) {
6413
7118
  this.tronWeb = window.tronWeb;
7119
+ const address = this.tronWeb.defaultAddress.base58 || DefaultTronWalletAddress;
7120
+ const customTronWeb = getCustomTronWeb();
7121
+ customTronWeb.setAddress(address);
7122
+ this.tronWeb = customTronWeb;
6414
7123
  resolve2(this.tronWeb);
6415
7124
  } else {
6416
7125
  setTimeout(checkTronWeb, 100);
@@ -6418,12 +7127,9 @@ var TronWallet = class {
6418
7127
  };
6419
7128
  checkTronWeb();
6420
7129
  setTimeout(() => {
6421
- this.tronWeb = new TronWeb({
6422
- fullHost: chainsRpcUrls["Tron"],
6423
- headers: {},
6424
- privateKey: ""
6425
- });
6426
- this.tronWeb.setAddress(DefaultAddresses["tron"]);
7130
+ const customTronWeb = getCustomTronWeb();
7131
+ customTronWeb.setAddress(DefaultTronWalletAddress);
7132
+ this.tronWeb = customTronWeb;
6427
7133
  resolve2(this.tronWeb);
6428
7134
  console.log(new Error("TronWeb initialization timeout"));
6429
7135
  }, 1e4);
@@ -6487,10 +7193,10 @@ var TronWallet = class {
6487
7193
  return await this.getBalance(token, account);
6488
7194
  }
6489
7195
  /**
6490
- * Estimate gas limit for transfer transaction
6491
- * @param data Transfer data
6492
- * @returns Gas limit estimate (bandwidth or energy), gas price, and estimated gas cost
6493
- */
7196
+ * Estimate gas limit for transfer transaction
7197
+ * @param data Transfer data
7198
+ * @returns Gas limit estimate (bandwidth or energy), gas price, and estimated gas cost
7199
+ */
6494
7200
  async estimateTransferGas(data) {
6495
7201
  const { originAsset } = data;
6496
7202
  await this.waitForTronWeb();
@@ -6501,14 +7207,7 @@ var TronWallet = class {
6501
7207
  gasLimit = 30000n;
6502
7208
  }
6503
7209
  gasLimit = gasLimit * 120n / 100n;
6504
- let gasPrice;
6505
- try {
6506
- const chainParameters = await this.tronWeb.trx.getChainParameters();
6507
- const energyPrice = chainParameters?.find((p) => p.key === "getEnergyFee")?.value || 420;
6508
- gasPrice = BigInt(energyPrice);
6509
- } catch (error) {
6510
- gasPrice = 420n;
6511
- }
7210
+ let gasPrice = 100n;
6512
7211
  const estimateGas = gasLimit * gasPrice;
6513
7212
  return {
6514
7213
  gasLimit,
@@ -6528,6 +7227,15 @@ var TronWallet = class {
6528
7227
  return false;
6529
7228
  }
6530
7229
  }
7230
+ async getTransactionResult(txHash) {
7231
+ await this.waitForTronWeb();
7232
+ try {
7233
+ const txInfo = await this.tronWeb.trx.getTransactionInfo(txHash);
7234
+ return txInfo;
7235
+ } catch (error) {
7236
+ return {};
7237
+ }
7238
+ }
6531
7239
  async allowance(params) {
6532
7240
  const {
6533
7241
  contractAddress,
@@ -6548,7 +7256,7 @@ var TronWallet = class {
6548
7256
  return {
6549
7257
  contract,
6550
7258
  allowance,
6551
- needApprove: Big6(amountWei || 0).gt(allowance || 0)
7259
+ needApprove: Big8(amountWei || 0).gt(allowance || 0)
6552
7260
  };
6553
7261
  } catch (error) {
6554
7262
  console.log("Error in allowance: %o", error);
@@ -6595,14 +7303,7 @@ var TronWallet = class {
6595
7303
  }
6596
7304
  async getEnergyPrice() {
6597
7305
  await this.waitForTronWeb();
6598
- let energyFee = 280;
6599
- try {
6600
- const params = await this.tronWeb.trx.getChainParameters();
6601
- energyFee = params.find((p) => p.key === "getEnergyFee")?.value || 280;
6602
- console.log("Energy Fee:", energyFee, "Sun/Energy");
6603
- } catch (err) {
6604
- console.error("Error getting energy price:", err);
6605
- }
7306
+ let energyFee = 100;
6606
7307
  return energyFee;
6607
7308
  }
6608
7309
  toBytes32(addr) {
@@ -6625,9 +7326,10 @@ var TronWallet = class {
6625
7326
  excludeFees: excludeFees4,
6626
7327
  refundTo,
6627
7328
  multiHopComposer,
6628
- isMultiHopComposer
6629
- // isOriginLegacy,
6630
- // isDestinationLegacy,
7329
+ isMultiHopComposer,
7330
+ isOriginLegacy,
7331
+ isDestinationLegacy,
7332
+ originLayerzero
6631
7333
  } = params;
6632
7334
  const result = {
6633
7335
  needApprove: false,
@@ -6644,12 +7346,11 @@ var TronWallet = class {
6644
7346
  estimateSourceGasUsd: void 0,
6645
7347
  estimateTime: 0,
6646
7348
  // seconds - dynamically calculated using LayerZero formula
6647
- outputAmount: numberRemoveEndZero(Big6(amountWei || 0).div(10 ** params.fromToken.decimals).toFixed(params.fromToken.decimals, 0))
7349
+ outputAmount: numberRemoveEndZero(Big8(amountWei || 0).div(10 ** params.fromToken.decimals).toFixed(params.fromToken.decimals, 0))
6648
7350
  };
6649
7351
  await this.waitForTronWeb();
6650
7352
  const oftContract = await this.tronWeb.contract(abi, originLayerzeroAddress);
6651
7353
  const approvalRequired = await oftContract.approvalRequired().call();
6652
- console.log("%cApprovalRequired: %o", "background:blue;color:white;", result.needApprove);
6653
7354
  if (approvalRequired) {
6654
7355
  try {
6655
7356
  const userAddress = refundTo || this.tronWeb.defaultAddress.base58;
@@ -6664,18 +7365,27 @@ var TronWallet = class {
6664
7365
  console.log("Error checking allowance: %o", error);
6665
7366
  }
6666
7367
  }
7368
+ const lzReceiveOptionGas = isOriginLegacy ? originLayerzero.lzReceiveOptionGasLegacy : originLayerzero.lzReceiveOptionGas;
7369
+ let lzReceiveOptionValue = 0;
7370
+ const destATA = await getDestinationAssociatedTokenAddress({
7371
+ recipient,
7372
+ toToken
7373
+ });
7374
+ if (destATA.needCreateTokenAccount) {
7375
+ lzReceiveOptionValue = LZ_RECEIVE_VALUE[toToken.chainName] || 0;
7376
+ }
6667
7377
  const sendParam = [
6668
7378
  // dstEid
6669
7379
  dstEid,
6670
7380
  // to
6671
7381
  // "0x0000000000000000000000000000000000000000000000000000000000000000",
6672
- addressToBytes32(toToken.chainType, recipient),
7382
+ addressToBytes322(toToken.chainType, recipient),
6673
7383
  // amountLD
6674
7384
  amountWei,
6675
7385
  // minAmountLD
6676
7386
  "0",
6677
7387
  // extraOptions
6678
- "0x",
7388
+ Options3.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).toHex(),
6679
7389
  // composeMsg
6680
7390
  "0x",
6681
7391
  // oftCmd
@@ -6683,71 +7393,63 @@ var TronWallet = class {
6683
7393
  ];
6684
7394
  if (isMultiHopComposer) {
6685
7395
  sendParam[0] = multiHopComposer.eid;
6686
- sendParam[1] = addressToBytes32("evm", multiHopComposer.oftMultiHopComposer);
7396
+ sendParam[1] = addressToBytes322("evm", multiHopComposer.oftMultiHopComposer);
6687
7397
  }
6688
7398
  const oftData = await oftContract.quoteOFT(sendParam).call();
6689
- console.log("oftData: %o", oftData);
6690
7399
  const [, , oftReceipt] = oftData;
6691
- sendParam[3] = Big6(oftReceipt[1].toString()).times(Big6(1).minus(Big6(slippageTolerance || 0).div(100))).toFixed(0);
7400
+ sendParam[3] = Big8(oftReceipt[1].toString()).times(Big8(1).minus(Big8(slippageTolerance || 0).div(100))).toFixed(0);
6692
7401
  const msgFee = await oftContract.quoteSend(sendParam, payInLzToken).call();
6693
- result.estimateSourceGas = msgFee[0]["nativeFee"];
7402
+ let nativeMsgFee = msgFee[0]["nativeFee"];
7403
+ if (nativeMsgFee) {
7404
+ nativeMsgFee = BigInt(Big8(nativeMsgFee.toString()).times(1.2).toFixed(0));
7405
+ }
7406
+ result.estimateSourceGas = nativeMsgFee;
6694
7407
  if (isMultiHopComposer) {
6695
- sendParam[4] = Options2.newOptions().addExecutorLzReceiveOption(250000000n, 0n).toHex();
6696
- const abiCoder = ethers2.AbiCoder.defaultAbiCoder();
7408
+ const composeMsgSendParam = {
7409
+ dstEid,
7410
+ to: addressToBytes322(toToken.chainType, recipient),
7411
+ amountLD: sendParam[2],
7412
+ minAmountLD: sendParam[3],
7413
+ extraOptions: Options3.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).toHex(),
7414
+ composeMsg: "0x",
7415
+ oftCmd: "0x"
7416
+ };
7417
+ const hopMsgFee = await getHopMsgFee({
7418
+ sendParam: composeMsgSendParam,
7419
+ toToken
7420
+ });
7421
+ sendParam[4] = Options3.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).addExecutorComposeOption(0, originLayerzero.composeOptionGas || 8e5, hopMsgFee).toHex();
7422
+ const abiCoder = ethers5.AbiCoder.defaultAbiCoder();
6697
7423
  sendParam[5] = abiCoder.encode(
6698
7424
  ["tuple(uint32 dstEid, bytes32 to, uint256 amountLD, uint256 minAmountLD, bytes extraOptions, bytes composeMsg, bytes oftCmd)"],
6699
- [[
6700
- dstEid,
6701
- addressToBytes32(toToken.chainType, recipient),
6702
- sendParam[2],
6703
- // amountLD
6704
- sendParam[3],
6705
- // minAmountLD
6706
- "0x",
6707
- "0x",
6708
- "0x"
6709
- ]]
7425
+ [Object.values(composeMsgSendParam)]
6710
7426
  );
6711
7427
  }
6712
- console.log("%cMsgFee: %o", "background:blue;color:white;", msgFee);
6713
7428
  result.sendParam = {
6714
- contract: oftContract,
6715
7429
  param: [
6716
7430
  // sendParam
6717
7431
  sendParam,
6718
7432
  // feeParam
6719
7433
  [
6720
7434
  // nativeFee
6721
- msgFee[0]["nativeFee"].toString(),
7435
+ nativeMsgFee.toString(),
6722
7436
  // lzTokenFee
6723
7437
  msgFee[0]["lzTokenFee"].toString()
6724
7438
  ],
6725
7439
  // refundAddress
6726
7440
  refundTo
6727
7441
  ],
6728
- options: { callValue: msgFee[0]["nativeFee"].toString() }
7442
+ options: { callValue: nativeMsgFee.toString() }
6729
7443
  };
6730
- console.log("%cParams: %o", "background:blue;color:white;", result.sendParam);
6731
- const nativeFeeUsd = Big6(msgFee[0]["nativeFee"]?.toString() || 0).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
6732
- result.fees.nativeFeeUsd = numberRemoveEndZero(Big6(nativeFeeUsd).toFixed(20));
6733
- result.fees.lzTokenFeeUsd = numberRemoveEndZero(Big6(msgFee[0]["lzTokenFee"]?.toString() || 0).div(10 ** fromToken.decimals).toFixed(20));
6734
- try {
6735
- const energyUsed = msgFee[0]["nativeFee"] || 15e5;
6736
- const usd = numberRemoveEndZero(Big6(energyUsed || 0).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol)).toFixed(20));
6737
- result.fees.estimateGasUsd = usd;
6738
- result.estimateSourceGas = energyUsed;
6739
- result.estimateSourceGasUsd = usd;
6740
- } catch (error) {
6741
- console.log("usdt0 estimate gas failed: %o", error);
6742
- }
6743
- for (const feeKey in result.fees) {
6744
- if (excludeFees4.includes(feeKey)) {
6745
- continue;
6746
- }
6747
- result.totalFeesUsd = Big6(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
6748
- }
6749
- result.totalFeesUsd = numberRemoveEndZero(Big6(result.totalFeesUsd).toFixed(20));
6750
- const tx = await this.tronWeb.transactionBuilder.triggerSmartContract(
7444
+ const nativeFeeUsd = Big8(nativeMsgFee?.toString() || 0).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
7445
+ result.fees.nativeFee = numberRemoveEndZero(Big8(nativeMsgFee?.toString() || 0).div(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals));
7446
+ result.fees.nativeFeeUsd = numberRemoveEndZero(Big8(nativeFeeUsd).toFixed(20));
7447
+ result.fees.lzTokenFeeUsd = numberRemoveEndZero(Big8(msgFee[0]["lzTokenFee"]?.toString() || 0).div(10 ** fromToken.decimals).toFixed(20));
7448
+ if (isOriginLegacy || isDestinationLegacy) {
7449
+ result.fees.legacyMeshFeeUsd = numberRemoveEndZero(Big8(amountWei || 0).div(10 ** fromToken.decimals).times(USDT0_LEGACY_MESH_TRANSFTER_FEE).toFixed(fromToken.decimals));
7450
+ result.outputAmount = numberRemoveEndZero(Big8(Big8(amountWei || 0).div(10 ** params.fromToken.decimals)).minus(result.fees.legacyMeshFeeUsd || 0).toFixed(params.fromToken.decimals, 0));
7451
+ }
7452
+ const transactionParams = [
6751
7453
  originLayerzeroAddress,
6752
7454
  "send((uint32,bytes32,uint256,uint256,bytes,bytes,bytes),(uint256,uint256),address)",
6753
7455
  result.sendParam.options,
@@ -6765,9 +7467,41 @@ var TronWallet = class {
6765
7467
  value: result.sendParam.param[2]
6766
7468
  }
6767
7469
  ],
6768
- this.tronWeb.defaultAddress.base58
6769
- );
7470
+ this.tronWeb.defaultAddress.base58 || refundTo
7471
+ ];
7472
+ const energyPrice = await this.getEnergyPrice();
7473
+ const tx = await this.tronWeb.transactionBuilder.triggerSmartContract(...transactionParams);
6770
7474
  result.sendParam.tx = tx;
7475
+ try {
7476
+ const transaction = await this.tronWeb.transactionBuilder.triggerConstantContract(...transactionParams);
7477
+ const energyUsed = transaction.energy_used || 2e5;
7478
+ const rawDataHexLength = transaction.transaction.raw_data_hex.length || 1e3;
7479
+ const bandwidthAmount = (rawDataHexLength / 2 + DATA_HEX_PROTOBUF_EXTRA + SIGNATURE_SIZE) * 1e-3;
7480
+ const amount = Big8(energyUsed || 0).times(energyPrice).div(10 ** fromToken.nativeToken.decimals);
7481
+ const totalAmount = Big8(amount).plus(bandwidthAmount);
7482
+ const usd = numberRemoveEndZero(Big8(totalAmount).times(getPrice(prices, fromToken.nativeToken.symbol)).toFixed(20));
7483
+ result.fees.estimateGasUsd = usd;
7484
+ result.estimateSourceGas = numberRemoveEndZero(Big8(totalAmount).times(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals));
7485
+ result.estimateSourceGasUsd = usd;
7486
+ } catch (error) {
7487
+ const energyUsed = 2e5;
7488
+ const rawDataHexLength = 1e3;
7489
+ const bandwidthAmount = (rawDataHexLength / 2 + DATA_HEX_PROTOBUF_EXTRA + SIGNATURE_SIZE) * 1e-3;
7490
+ const amount = Big8(energyUsed || 0).times(energyPrice).div(10 ** fromToken.nativeToken.decimals);
7491
+ const totalAmount = Big8(amount).plus(bandwidthAmount);
7492
+ const usd = numberRemoveEndZero(Big8(totalAmount).times(getPrice(prices, fromToken.nativeToken.symbol)).toFixed(20));
7493
+ result.fees.estimateGasUsd = usd;
7494
+ result.estimateSourceGas = numberRemoveEndZero(Big8(totalAmount).times(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals));
7495
+ result.estimateSourceGasUsd = usd;
7496
+ }
7497
+ for (const feeKey in result.fees) {
7498
+ if (excludeFees4.includes(feeKey) || !/Usd$/.test(feeKey)) {
7499
+ continue;
7500
+ }
7501
+ result.totalFeesUsd = Big8(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
7502
+ }
7503
+ result.totalFeesUsd = numberRemoveEndZero(Big8(result.totalFeesUsd).toFixed(20));
7504
+ result.sendParam.transactionParams = transactionParams;
6771
7505
  return result;
6772
7506
  }
6773
7507
  async sendTransaction(params) {
@@ -6776,7 +7510,6 @@ var TronWallet = class {
6776
7510
  } = params;
6777
7511
  const result = await this.signAndSendTransaction(tx.transaction);
6778
7512
  if (typeof result === "object" && result.message) {
6779
- console.log("%cTron send transaction message: %o", "background:#f00;color:#fff;", result.message);
6780
7513
  if (/user rejected the transaction/i.test(result.message)) {
6781
7514
  throw new Error("User rejected the transaction");
6782
7515
  }
@@ -6841,7 +7574,6 @@ var TronWallet = class {
6841
7574
  } catch (error) {
6842
7575
  console.log("oneclick check allowance failed: %o", error);
6843
7576
  }
6844
- const proxyContract = await this.tronWeb.contract(abi, proxyAddress);
6845
7577
  const proxyParam = [
6846
7578
  // tokenAddress
6847
7579
  fromToken.contractAddress,
@@ -6851,22 +7583,9 @@ var TronWallet = class {
6851
7583
  amountWei
6852
7584
  ];
6853
7585
  result.sendParam = {
6854
- contract: proxyContract,
6855
7586
  param: proxyParam
6856
7587
  };
6857
- try {
6858
- const gasLimit = 30000n;
6859
- const energyPrice = await this.getEnergyPrice();
6860
- const gasPrice = BigInt(energyPrice);
6861
- const estimateGas = gasLimit * gasPrice;
6862
- const estimateGasUsd = Big6(estimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
6863
- result.fees.sourceGasFeeUsd = numberRemoveEndZero(Big6(estimateGasUsd).toFixed(20));
6864
- result.estimateSourceGas = estimateGas.toString();
6865
- result.estimateSourceGasUsd = numberRemoveEndZero(Big6(estimateGasUsd).toFixed(20));
6866
- } catch (error) {
6867
- console.log("onclick estimate proxy failed: %o", error);
6868
- }
6869
- const tx = await this.tronWeb.transactionBuilder.triggerSmartContract(
7588
+ const transactionParams = [
6870
7589
  proxyAddress,
6871
7590
  "proxyTransfer(address,address,uint256)",
6872
7591
  {},
@@ -6887,20 +7606,99 @@ var TronWallet = class {
6887
7606
  // amount
6888
7607
  }
6889
7608
  ],
6890
- this.tronWeb.defaultAddress.base58
6891
- );
7609
+ this.tronWeb.defaultAddress.base58 || refundTo
7610
+ ];
7611
+ const energyPrice = await this.getEnergyPrice();
7612
+ const tx = await this.tronWeb.transactionBuilder.triggerSmartContract(...transactionParams);
6892
7613
  result.sendParam.tx = tx;
7614
+ try {
7615
+ const transaction = await this.tronWeb.transactionBuilder.triggerConstantContract(...transactionParams);
7616
+ const energyUsed = transaction.energy_used || 3e4;
7617
+ const rawDataHexLength = transaction.transaction.raw_data_hex.length || 500;
7618
+ const bandwidthAmount = (rawDataHexLength / 2 + DATA_HEX_PROTOBUF_EXTRA + SIGNATURE_SIZE) * 1e-3;
7619
+ const amount = Big8(energyUsed || 0).times(energyPrice).div(10 ** fromToken.nativeToken.decimals);
7620
+ const totalAmount = Big8(amount).plus(bandwidthAmount);
7621
+ const usd = numberRemoveEndZero(Big8(totalAmount).times(getPrice(prices, fromToken.nativeToken.symbol)).toFixed(20));
7622
+ result.fees.sourceGasFeeUsd = usd;
7623
+ result.estimateSourceGas = numberRemoveEndZero(Big8(totalAmount).times(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals));
7624
+ result.estimateSourceGasUsd = usd;
7625
+ } catch (error) {
7626
+ const energyUsed = 169e3;
7627
+ const rawDataHexLength = 500;
7628
+ const bandwidthAmount = (rawDataHexLength / 2 + DATA_HEX_PROTOBUF_EXTRA + SIGNATURE_SIZE) * 1e-3;
7629
+ const amount = Big8(energyUsed || 0).times(energyPrice).div(10 ** fromToken.nativeToken.decimals);
7630
+ const totalAmount = Big8(amount).plus(bandwidthAmount);
7631
+ const usd = numberRemoveEndZero(Big8(totalAmount).times(getPrice(prices, fromToken.nativeToken.symbol)).toFixed(20));
7632
+ result.fees.estimateGasUsd = usd;
7633
+ result.estimateSourceGas = numberRemoveEndZero(Big8(totalAmount).times(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals));
7634
+ result.estimateSourceGasUsd = usd;
7635
+ }
7636
+ result.sendParam.transactionParams = transactionParams;
7637
+ return result;
7638
+ }
7639
+ async getAccountResources(params) {
7640
+ const { account } = params;
7641
+ const result = {
7642
+ energy: 0,
7643
+ bandwidth: 0,
7644
+ success: false,
7645
+ error: "TronWeb is not initialized or the wallet is not connected"
7646
+ };
7647
+ await this.waitForTronWeb();
7648
+ if (!this.tronWeb || !account) {
7649
+ return result;
7650
+ }
7651
+ try {
7652
+ let availableEnergy;
7653
+ let availableBandwidth;
7654
+ try {
7655
+ if (this.tronWeb.trx.getAccountResources) {
7656
+ const resources = await this.tronWeb.trx.getAccountResources(account);
7657
+ console.log("resources: %o", resources);
7658
+ if (resources) {
7659
+ availableEnergy = (resources.EnergyLimit || 0) - (resources.EnergyUsed || 0);
7660
+ availableBandwidth = (resources.freeNetLimit || 0) - (resources.freeNetUsed || 0);
7661
+ }
7662
+ }
7663
+ } catch (resourcesErr) {
7664
+ console.warn("getAccountResources API is not available, try other way:", resourcesErr);
7665
+ }
7666
+ if (availableEnergy === void 0 && availableBandwidth === void 0) {
7667
+ const accountInfo = await this.tronWeb.trx.getAccount(account);
7668
+ if (accountInfo.account_resource) {
7669
+ const accountResource = accountInfo.account_resource;
7670
+ availableEnergy = (accountResource.EnergyLimit || 0) - (accountResource.EnergyUsed || 0);
7671
+ availableBandwidth = (accountResource.NetLimit || 0) - (accountResource.NetUsed || 0);
7672
+ } else if (accountInfo.energy !== void 0) {
7673
+ availableEnergy = accountInfo.energy || 0;
7674
+ }
7675
+ if (accountInfo.bandwidth !== void 0) {
7676
+ if (typeof accountInfo.bandwidth === "number") {
7677
+ availableBandwidth = accountInfo.bandwidth;
7678
+ } else if (accountInfo.bandwidth) {
7679
+ availableBandwidth = accountInfo.bandwidth.available || accountInfo.bandwidth.freeNetUsage || 0;
7680
+ }
7681
+ }
7682
+ }
7683
+ result.energy = Math.max(0, availableEnergy);
7684
+ result.bandwidth = Math.max(0, availableBandwidth);
7685
+ result.success = true;
7686
+ result.error = null;
7687
+ } catch (error) {
7688
+ console.error("Failed to get account resources:", error);
7689
+ }
6893
7690
  return result;
6894
7691
  }
6895
7692
  };
6896
7693
 
6897
7694
  // src/wallets/aptos.ts
6898
7695
  import { Aptos, AptosConfig, Network, parseTypeTag, TypeTagAddress, TypeTagU64 } from "@aptos-labs/ts-sdk";
6899
- import Big7 from "big.js";
7696
+ import Big9 from "big.js";
6900
7697
  var AptosWallet = class {
6901
7698
  constructor(options) {
6902
7699
  const config = new AptosConfig({
6903
- network: Network.MAINNET
7700
+ network: Network.MAINNET,
7701
+ fullnode: getRpcUrls("aptos")[0]
6904
7702
  });
6905
7703
  const aptos = new Aptos(config);
6906
7704
  this.aptos = aptos;
@@ -7204,10 +8002,10 @@ var AptosWallet = class {
7204
8002
  const defaultGasLimit = 5000n;
7205
8003
  const defaultGasPrice = 100n;
7206
8004
  const defaultEstimateGas = defaultGasLimit * defaultGasPrice;
7207
- const estimateGasUsd2 = Big7(defaultEstimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
7208
- result.fees.sourceGasFeeUsd = numberRemoveEndZero(Big7(estimateGasUsd2).toFixed(20));
8005
+ const estimateGasUsd2 = Big9(defaultEstimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
8006
+ result.fees.sourceGasFeeUsd = numberRemoveEndZero(Big9(estimateGasUsd2).toFixed(20));
7209
8007
  result.estimateSourceGas = defaultEstimateGas.toString();
7210
- result.estimateSourceGasUsd = numberRemoveEndZero(Big7(estimateGasUsd2).toFixed(20));
8008
+ result.estimateSourceGasUsd = numberRemoveEndZero(Big9(estimateGasUsd2).toFixed(20));
7211
8009
  result.sendParam = {
7212
8010
  function: functionId,
7213
8011
  typeArguments: [typeArgument],
@@ -7220,10 +8018,10 @@ var AptosWallet = class {
7220
8018
  const defaultGasLimit = 5000n;
7221
8019
  const defaultGasPrice = 100n;
7222
8020
  const defaultEstimateGas = defaultGasLimit * defaultGasPrice;
7223
- const estimateGasUsd2 = Big7(defaultEstimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
7224
- result.fees.sourceGasFeeUsd = numberRemoveEndZero(Big7(estimateGasUsd2).toFixed(20));
8021
+ const estimateGasUsd2 = Big9(defaultEstimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
8022
+ result.fees.sourceGasFeeUsd = numberRemoveEndZero(Big9(estimateGasUsd2).toFixed(20));
7225
8023
  result.estimateSourceGas = defaultEstimateGas.toString();
7226
- result.estimateSourceGasUsd = numberRemoveEndZero(Big7(estimateGasUsd2).toFixed(20));
8024
+ result.estimateSourceGasUsd = numberRemoveEndZero(Big9(estimateGasUsd2).toFixed(20));
7227
8025
  result.sendParam = {
7228
8026
  function: functionId,
7229
8027
  typeArguments: [typeArgument],
@@ -7235,10 +8033,10 @@ var AptosWallet = class {
7235
8033
  const gasLimit = gasUsed * 150n / 100n;
7236
8034
  const gasPrice = BigInt(simulation.gas_unit_price || 100);
7237
8035
  const estimateGas = gasLimit * gasPrice;
7238
- const estimateGasUsd = Big7(estimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
7239
- result.fees.sourceGasFeeUsd = numberRemoveEndZero(Big7(estimateGasUsd).toFixed(20));
8036
+ const estimateGasUsd = Big9(estimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
8037
+ result.fees.sourceGasFeeUsd = numberRemoveEndZero(Big9(estimateGasUsd).toFixed(20));
7240
8038
  result.estimateSourceGas = estimateGas.toString();
7241
- result.estimateSourceGasUsd = numberRemoveEndZero(Big7(estimateGasUsd).toFixed(20));
8039
+ result.estimateSourceGasUsd = numberRemoveEndZero(Big9(estimateGasUsd).toFixed(20));
7242
8040
  result.sendParam = {
7243
8041
  function: functionId,
7244
8042
  typeArguments: [typeArgument],
@@ -7249,10 +8047,10 @@ var AptosWallet = class {
7249
8047
  const defaultGasLimit = 5000n;
7250
8048
  const defaultGasPrice = 100n;
7251
8049
  const defaultEstimateGas = defaultGasLimit * defaultGasPrice;
7252
- const estimateGasUsd = Big7(defaultEstimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
7253
- result.fees.sourceGasFeeUsd = numberRemoveEndZero(Big7(estimateGasUsd).toFixed(20));
8050
+ const estimateGasUsd = Big9(defaultEstimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
8051
+ result.fees.sourceGasFeeUsd = numberRemoveEndZero(Big9(estimateGasUsd).toFixed(20));
7254
8052
  result.estimateSourceGas = defaultEstimateGas.toString();
7255
- result.estimateSourceGasUsd = numberRemoveEndZero(Big7(estimateGasUsd).toFixed(20));
8053
+ result.estimateSourceGasUsd = numberRemoveEndZero(Big9(estimateGasUsd).toFixed(20));
7256
8054
  }
7257
8055
  return result;
7258
8056
  }
@@ -7329,7 +8127,12 @@ export {
7329
8127
  CancelablePromise,
7330
8128
  EVMWallet,
7331
8129
  GetExecutionStatusResponse,
8130
+ Hyperliquid,
8131
+ HyperliquidFromTokens,
8132
+ HyperliuquidMinAmount,
8133
+ HyperliuquidToToken,
7332
8134
  NearWallet,
8135
+ NetworkRpcUrlsMap,
7333
8136
  OpenAPI,
7334
8137
  QuoteRequest,
7335
8138
  SFA,
@@ -7339,7 +8142,8 @@ export {
7339
8142
  TokenResponse,
7340
8143
  TransactionStatus,
7341
8144
  TronWallet,
7342
- chainsRpcUrls,
8145
+ getRpcUrls,
8146
+ setRpcUrls,
7343
8147
  tokens,
7344
8148
  usdcChains,
7345
8149
  usdcTokens,