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.js CHANGED
@@ -43,7 +43,12 @@ __export(index_exports, {
43
43
  CancelablePromise: () => CancelablePromise,
44
44
  EVMWallet: () => EVMWallet,
45
45
  GetExecutionStatusResponse: () => GetExecutionStatusResponse,
46
+ Hyperliquid: () => Hyperliquid,
47
+ HyperliquidFromTokens: () => HyperliquidFromTokens,
48
+ HyperliuquidMinAmount: () => HyperliuquidMinAmount,
49
+ HyperliuquidToToken: () => HyperliuquidToToken,
46
50
  NearWallet: () => NearWallet,
51
+ NetworkRpcUrlsMap: () => NetworkRpcUrlsMap,
47
52
  OpenAPI: () => OpenAPI,
48
53
  QuoteRequest: () => QuoteRequest,
49
54
  SFA: () => SFA,
@@ -53,7 +58,8 @@ __export(index_exports, {
53
58
  TokenResponse: () => TokenResponse,
54
59
  TransactionStatus: () => TransactionStatus,
55
60
  TronWallet: () => TronWallet,
56
- chainsRpcUrls: () => chainsRpcUrls,
61
+ getRpcUrls: () => getRpcUrls,
62
+ setRpcUrls: () => setRpcUrls,
57
63
  tokens: () => tokens,
58
64
  usdcChains: () => usdcChains,
59
65
  usdcTokens: () => usdcTokens,
@@ -554,7 +560,8 @@ var ONECLICK_PROXY = {
554
560
  ["Solana"]: "HWk6MsFEGzXxpe9B4mfEHpvVoCwNeVVMFxb5Mi7qNTM",
555
561
  ["Near"]: "stbflow.near",
556
562
  ["Aptos"]: "0x3000ceb3211d23ef73ad1b602a7a99b72020c9ce9537f580ac5bba556ec3bff9",
557
- ["Base"]: "0x7A18854b695BA7efB7229c17D0E1Cd2679481D28"
563
+ ["Base"]: "0x7A18854b695BA7efB7229c17D0E1Cd2679481D28",
564
+ ["X Layer"]: "0xc8dB1175132C64e311D01258dD05D4e2e75fD7b8"
558
565
  };
559
566
  var ONECLICK_PROXY_ABI = [
560
567
  {
@@ -642,26 +649,35 @@ var OneClickService = class {
642
649
  this.offsetTime = 1e3 * 60 * 30;
643
650
  }
644
651
  async quote(params) {
652
+ const {
653
+ wallet,
654
+ fromToken,
655
+ toToken,
656
+ prices,
657
+ amountWei,
658
+ appFees = [],
659
+ swapType = "EXACT_INPUT",
660
+ isProxy = true,
661
+ ...restParams
662
+ } = params;
663
+ const isExactOutput = swapType === "EXACT_OUTPUT";
645
664
  const response = await request(OpenAPI, {
646
665
  method: "POST",
647
666
  url: "/v0/quote",
648
667
  body: {
649
668
  depositMode: "SIMPLE",
650
- swapType: "EXACT_INPUT",
669
+ swapType,
651
670
  depositType: "ORIGIN_CHAIN",
652
671
  sessionId: `session_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
653
672
  recipientType: "DESTINATION_CHAIN",
654
673
  deadline: new Date(Date.now() + this.offsetTime).toISOString(),
655
674
  quoteWaitingTimeMs: 3e3,
656
- appFees: BridgeFee,
675
+ appFees: [
676
+ ...BridgeFee,
677
+ ...appFees
678
+ ],
657
679
  referral: "stableflow",
658
- ...params,
659
- // delete params
660
- wallet: void 0,
661
- fromToken: void 0,
662
- toToken: void 0,
663
- prices: void 0,
664
- amountWei: void 0
680
+ ...restParams
665
681
  },
666
682
  mediaType: "application/json",
667
683
  errors: {
@@ -675,7 +691,10 @@ var OneClickService = class {
675
691
  res.data.estimateTime = res.data?.quote?.timeEstimate;
676
692
  res.data.outputAmount = numberRemoveEndZero((0, import_big.default)(res.data?.quote?.amountOut || 0).div(10 ** params.toToken.decimals).toFixed(params.toToken.decimals, 0));
677
693
  try {
678
- const netFee = (0, import_big.default)(params.amount).div(10 ** params.fromToken.decimals).minus((0, import_big.default)(res.data?.quote?.amountOut || 0).div(10 ** params.toToken.decimals));
694
+ let netFee = (0, import_big.default)(params.amount).div(10 ** params.fromToken.decimals).minus((0, import_big.default)(res.data?.quote?.amountOut || 0).div(10 ** params.toToken.decimals));
695
+ if (isExactOutput) {
696
+ netFee = (0, import_big.default)(res.data?.quote?.amountIn || 0).div(10 ** params.fromToken.decimals).minus((0, import_big.default)(params.amount).div(10 ** params.toToken.decimals));
697
+ }
679
698
  const bridgeFeeValue = BridgeFee.reduce((acc, item) => {
680
699
  return acc.plus((0, import_big.default)(params.amount).div(10 ** params.fromToken.decimals).times((0, import_big.default)(item.fee).div(1e4)));
681
700
  }, (0, import_big.default)(0));
@@ -708,14 +727,14 @@ var OneClickService = class {
708
727
  console.log("oneclick estimate failed: %o", error);
709
728
  }
710
729
  const proxyAddress = ONECLICK_PROXY[params.fromToken.chainName];
711
- if (proxyAddress) {
730
+ if (proxyAddress && isProxy) {
712
731
  const proxyResult = await params.wallet.quote(Service.OneClick, {
713
732
  proxyAddress,
714
733
  abi: ONECLICK_PROXY_ABI,
715
734
  fromToken: params.fromToken,
716
735
  refundTo: params.refundTo,
717
736
  recipient: params.recipient,
718
- amountWei: params.amount,
737
+ amountWei: isExactOutput ? res.data?.quote?.amountIn : params.amount,
719
738
  prices: params.prices,
720
739
  depositAddress: res.data?.quote?.depositAddress || DefaultAddresses[params.fromToken.chainType]
721
740
  });
@@ -790,8 +809,10 @@ var USDT0_CONFIG = {
790
809
  chainKey: "ethereum",
791
810
  blockTime: 12,
792
811
  // Ethereum average block time ~12 seconds
793
- confirmations: 15
812
+ confirmations: 15,
794
813
  // Default confirmations from layerzeroscan.com
814
+ lzReceiveOptionGas: 8e4,
815
+ lzReceiveOptionGasLegacy: 2e5
795
816
  },
796
817
  Arbitrum: {
797
818
  contractAddress: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
@@ -802,8 +823,10 @@ var USDT0_CONFIG = {
802
823
  chainKey: "arbitrum",
803
824
  blockTime: 0.25,
804
825
  // Arbitrum average block time ~0.25 seconds
805
- confirmations: 20
826
+ confirmations: 20,
806
827
  // Default confirmations from layerzeroscan.com
828
+ lzReceiveOptionGas: 8e4,
829
+ lzReceiveOptionGasLegacy: 2e5
807
830
  },
808
831
  Polygon: {
809
832
  contractAddress: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
@@ -812,8 +835,11 @@ var USDT0_CONFIG = {
812
835
  chainKey: "polygon",
813
836
  blockTime: 2,
814
837
  // Polygon average block time ~2 seconds
815
- confirmations: 20
838
+ confirmations: 20,
816
839
  // Default confirmations from layerzeroscan.com
840
+ lzReceiveOptionGas: 8e4,
841
+ lzReceiveOptionGasLegacy: 2e5,
842
+ composeOptionGas: 6e5
817
843
  },
818
844
  Optimism: {
819
845
  contractAddress: "0x01bFF41798a0BcF287b996046Ca68b395DbC1071",
@@ -822,8 +848,11 @@ var USDT0_CONFIG = {
822
848
  chainKey: "optimism",
823
849
  blockTime: 2,
824
850
  // Optimism average block time ~2 seconds
825
- confirmations: 20
851
+ confirmations: 20,
826
852
  // Default confirmations from layerzeroscan.com
853
+ lzReceiveOptionGas: 8e4,
854
+ lzReceiveOptionGasLegacy: 2e5,
855
+ composeOptionGas: 6e5
827
856
  },
828
857
  Berachain: {
829
858
  contractAddress: "0x779Ded0c9e1022225f8E0630b35a9b54bE713736",
@@ -833,8 +862,11 @@ var USDT0_CONFIG = {
833
862
  chainKey: "berachain",
834
863
  blockTime: 2,
835
864
  // Optimism average block time ~2 seconds
836
- confirmations: 20
865
+ confirmations: 20,
837
866
  // Default confirmations from layerzeroscan.com
867
+ lzReceiveOptionGas: 8e4,
868
+ lzReceiveOptionGasLegacy: 2e5,
869
+ composeOptionGas: 6e5
838
870
  },
839
871
  Solana: {
840
872
  contractAddress: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
@@ -843,8 +875,11 @@ var USDT0_CONFIG = {
843
875
  chainKey: "solana",
844
876
  blockTime: 0.4,
845
877
  // Solana average block time ~0.4 seconds
846
- confirmations: 32
878
+ confirmations: 32,
847
879
  // Default confirmations from layerzeroscan.com
880
+ lzReceiveOptionGas: 2e5,
881
+ lzReceiveOptionGasLegacy: 2e5,
882
+ composeOptionGas: 5e5
848
883
  },
849
884
  Tron: {
850
885
  contractAddress: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
@@ -853,12 +888,33 @@ var USDT0_CONFIG = {
853
888
  chainKey: "tron",
854
889
  blockTime: 3,
855
890
  // Tron average block time ~3 seconds
856
- confirmations: 5
891
+ confirmations: 5,
892
+ // Default confirmations from layerzeroscan.com
893
+ lzReceiveOptionGas: 3e5,
894
+ lzReceiveOptionGasLegacy: 3e5,
895
+ composeOptionGas: 5e5
896
+ },
897
+ "X Layer": {
898
+ contractAddress: "0x779Ded0c9e1022225f8E0630b35a9b54bE713736",
899
+ oft: "0x94bcca6bdfd6a61817ab0e960bfede4984505554",
900
+ eid: 30274,
901
+ chainKey: "xlayer",
902
+ blockTime: 3,
903
+ // Tron average block time ~3 seconds
904
+ confirmations: 20,
857
905
  // Default confirmations from layerzeroscan.com
906
+ lzReceiveOptionGas: 8e4,
907
+ lzReceiveOptionGasLegacy: 2e5,
908
+ composeOptionGas: 6e5
858
909
  }
859
910
  };
911
+ var LZ_RECEIVE_VALUE = {
912
+ Solana: 2039280
913
+ };
860
914
  var USDT0_DVN_COUNT = 2;
861
- var USDT0_LEGACY_FEE = 1e-4;
915
+ var USDT0_LEGACY_MESH_TRANSFTER_FEE = 3e-4;
916
+ var DATA_HEX_PROTOBUF_EXTRA = 3;
917
+ var SIGNATURE_SIZE = 67;
862
918
 
863
919
  // src/bridges/usdt0/contract.ts
864
920
  var OFT_ABI = [
@@ -3567,17 +3623,6 @@ function calculateEstimateTime(originChain, destinationChain) {
3567
3623
  const sourceTime = sourceBlockTime * blockConfirmations;
3568
3624
  const destinationTime = destinationBlockTime * (2 + dvnCount);
3569
3625
  const totalTime = Math.ceil(sourceTime + destinationTime);
3570
- console.log(`USDT0 estimate time calculation:`, {
3571
- originChain,
3572
- destinationChain,
3573
- sourceBlockTime,
3574
- blockConfirmations,
3575
- destinationBlockTime,
3576
- dvnCount,
3577
- sourceTime,
3578
- destinationTime,
3579
- totalTime
3580
- });
3581
3626
  return totalTime;
3582
3627
  }
3583
3628
  var Usdt0Service = class {
@@ -3628,7 +3673,9 @@ var Usdt0Service = class {
3628
3673
  multiHopComposer: USDT0_CONFIG["Arbitrum"],
3629
3674
  isMultiHopComposer: isMultiHopComposer2,
3630
3675
  isOriginLegacy: isOriginLegacy2,
3631
- isDestinationLegacy: isDestinationLegacy2
3676
+ isDestinationLegacy: isDestinationLegacy2,
3677
+ originLayerzero,
3678
+ destinationLayerzero
3632
3679
  });
3633
3680
  result.estimateTime = estimateTime;
3634
3681
  return result;
@@ -3662,7 +3709,9 @@ var Usdt0Service = class {
3662
3709
  multiHopComposer: USDT0_CONFIG["Arbitrum"],
3663
3710
  isMultiHopComposer,
3664
3711
  isOriginLegacy,
3665
- isDestinationLegacy
3712
+ isDestinationLegacy,
3713
+ originLayerzero,
3714
+ destinationLayerzero
3666
3715
  });
3667
3716
  result.estimateTime = estimateTime;
3668
3717
  return result;
@@ -3685,8 +3734,11 @@ var Usdt0Service = class {
3685
3734
  multiHopComposer: USDT0_CONFIG["Arbitrum"],
3686
3735
  isMultiHopComposer,
3687
3736
  isOriginLegacy,
3688
- isDestinationLegacy
3737
+ isDestinationLegacy,
3738
+ originLayerzero,
3739
+ destinationLayerzero
3689
3740
  });
3741
+ result.estimateTime = estimateTime;
3690
3742
  return result;
3691
3743
  }
3692
3744
  }
@@ -3899,23 +3951,42 @@ var ServiceLogoMap = {
3899
3951
  };
3900
3952
 
3901
3953
  // src/services/SFA.ts
3902
- var import_big2 = __toESM(require("big.js"));
3954
+ var import_big3 = __toESM(require("big.js"));
3903
3955
 
3904
3956
  // src/wallets/config/rpcs.ts
3905
- var chainsRpcUrls = {
3906
- "Ethereum": "https://eth.merkle.io",
3907
- "Arbitrum": "https://arb1.arbitrum.io/rpc",
3908
- "BNB Chain": "https://56.rpc.thirdweb.com",
3909
- "Avalanche": "https://api.avax.network/ext/bc/C/rpc",
3910
- "Base": "https://mainnet.base.org",
3911
- "Polygon": "https://polygon-rpc.com",
3912
- "Gnosis": "https://rpc.gnosischain.com",
3913
- "Optimism": "https://mainnet.optimism.io",
3914
- "Berachain": "https://rpc.berachain.com",
3915
- "Tron": "https://api.trongrid.io",
3916
- "Aptos": "https://api.mainnet.aptoslabs.com/v1",
3917
- "Solana": "https://mainnet.helius-rpc.com/?api-key=28fc7f18-acf0-48a1-9e06-bd1b6cba1170",
3918
- "Near": "https://nearinner.deltarpc.com"
3957
+ var NetworkRpcUrlsMap = {
3958
+ "eth": ["https://eth.merkle.io"],
3959
+ "arb": ["https://arb1.arbitrum.io/rpc"],
3960
+ "bsc": ["https://56.rpc.thirdweb.com"],
3961
+ "avax": ["https://api.avax.network/ext/bc/C/rpc"],
3962
+ "base": ["https://mainnet.base.org"],
3963
+ "pol": ["https://polygon-rpc.com"],
3964
+ "gnosis": ["https://rpc.gnosischain.com"],
3965
+ "op": ["https://mainnet.optimism.io"],
3966
+ "bera": ["https://rpc.berachain.com"],
3967
+ "tron": ["https://api.trongrid.io"],
3968
+ "aptos": ["https://api.mainnet.aptoslabs.com/v1"],
3969
+ "sol": ["https://solana-rpc.publicnode.com"],
3970
+ "near": ["https://nearinner.deltarpc.com"],
3971
+ "xlayer": ["https://rpc.xlayer.tech"],
3972
+ "plasma": ["https://rpc.plasma.to"]
3973
+ };
3974
+ var getRpcUrls = (blockchain) => {
3975
+ return NetworkRpcUrlsMap[blockchain] || [];
3976
+ };
3977
+ var setRpcUrls = (urls) => {
3978
+ for (const blockchain in urls) {
3979
+ const prev = NetworkRpcUrlsMap[blockchain] ?? [];
3980
+ const next = urls[blockchain];
3981
+ for (let i = next.length - 1; i >= 0; i--) {
3982
+ const rpc = next[i];
3983
+ if (prev.some((_rpc) => _rpc.toLowerCase() === rpc.toLowerCase())) {
3984
+ continue;
3985
+ }
3986
+ prev.unshift(rpc);
3987
+ }
3988
+ }
3989
+ return NetworkRpcUrlsMap;
3919
3990
  };
3920
3991
 
3921
3992
  // src/wallets/config/chains.ts
@@ -3949,6 +4020,7 @@ var chainTypes = {
3949
4020
  var chains = {
3950
4021
  near: {
3951
4022
  chainName: "Near",
4023
+ blockchain: "near",
3952
4024
  chainIcon: "/chains/near.png",
3953
4025
  chainIconGray: "/chains/near-gray.png",
3954
4026
  chainType: chainTypes.near.value,
@@ -3958,10 +4030,11 @@ var chains = {
3958
4030
  symbol: "NEAR",
3959
4031
  decimals: 24
3960
4032
  },
3961
- rpcUrl: chainsRpcUrls["Near"]
4033
+ rpcUrls: getRpcUrls("near")
3962
4034
  },
3963
4035
  sol: {
3964
4036
  chainName: "Solana",
4037
+ blockchain: "sol",
3965
4038
  chainIcon: "/chains/solana.png",
3966
4039
  chainIconGray: "/chains/solana-gray.png",
3967
4040
  chainType: chainTypes.sol.value,
@@ -3971,10 +4044,11 @@ var chains = {
3971
4044
  symbol: "SOL",
3972
4045
  decimals: 9
3973
4046
  },
3974
- rpcUrl: chainsRpcUrls["Solana"]
4047
+ rpcUrls: getRpcUrls("sol")
3975
4048
  },
3976
4049
  eth: {
3977
4050
  chainName: "Ethereum",
4051
+ blockchain: "eth",
3978
4052
  chainIcon: "/chains/ethereum.png",
3979
4053
  chainIconGray: "/chains/ethereum-gray.png",
3980
4054
  chainType: chainTypes.evm.value,
@@ -3985,10 +4059,11 @@ var chains = {
3985
4059
  symbol: "ETH",
3986
4060
  decimals: 18
3987
4061
  },
3988
- rpcUrl: chainsRpcUrls["Ethereum"]
4062
+ rpcUrls: getRpcUrls("eth")
3989
4063
  },
3990
4064
  arb: {
3991
4065
  chainName: "Arbitrum",
4066
+ blockchain: "arb",
3992
4067
  chainIcon: "/chains/arbitrum.png",
3993
4068
  chainIconGray: "/chains/arbitrum-gray.png",
3994
4069
  chainType: chainTypes.evm.value,
@@ -3999,10 +4074,11 @@ var chains = {
3999
4074
  symbol: "ETH",
4000
4075
  decimals: 18
4001
4076
  },
4002
- rpcUrl: chainsRpcUrls["Arbitrum"]
4077
+ rpcUrls: getRpcUrls("arb")
4003
4078
  },
4004
4079
  bsc: {
4005
4080
  chainName: "BNB Chain",
4081
+ blockchain: "bsc",
4006
4082
  chainIcon: "/chains/bsc.png",
4007
4083
  chainIconGray: "/chains/bsc-gray.png",
4008
4084
  chainType: chainTypes.evm.value,
@@ -4013,10 +4089,11 @@ var chains = {
4013
4089
  symbol: "BNB",
4014
4090
  decimals: 18
4015
4091
  },
4016
- rpcUrl: chainsRpcUrls["BNB Chain"]
4092
+ rpcUrls: getRpcUrls("bsc")
4017
4093
  },
4018
4094
  avax: {
4019
4095
  chainName: "Avalanche",
4096
+ blockchain: "avax",
4020
4097
  chainIcon: "/chains/avalanche.png",
4021
4098
  chainIconGray: "/chains/avalanche-gray.png",
4022
4099
  chainType: chainTypes.evm.value,
@@ -4027,10 +4104,11 @@ var chains = {
4027
4104
  symbol: "AVAX",
4028
4105
  decimals: 18
4029
4106
  },
4030
- rpcUrl: chainsRpcUrls["Avalanche"]
4107
+ rpcUrls: getRpcUrls("avax")
4031
4108
  },
4032
4109
  base: {
4033
4110
  chainName: "Base",
4111
+ blockchain: "base",
4034
4112
  chainIcon: "/chains/base.png",
4035
4113
  chainIconGray: "/chains/base-gray.png",
4036
4114
  chainType: chainTypes.evm.value,
@@ -4041,10 +4119,11 @@ var chains = {
4041
4119
  symbol: "ETH",
4042
4120
  decimals: 18
4043
4121
  },
4044
- rpcUrl: chainsRpcUrls["Base"]
4122
+ rpcUrls: getRpcUrls("base")
4045
4123
  },
4046
4124
  pol: {
4047
4125
  chainName: "Polygon",
4126
+ blockchain: "pol",
4048
4127
  chainIcon: "/chains/polygon.png",
4049
4128
  chainIconGray: "/chains/polygon-gray.png",
4050
4129
  chainType: chainTypes.evm.value,
@@ -4055,10 +4134,11 @@ var chains = {
4055
4134
  symbol: "POL",
4056
4135
  decimals: 18
4057
4136
  },
4058
- rpcUrl: chainsRpcUrls["Polygon"]
4137
+ rpcUrls: getRpcUrls("pol")
4059
4138
  },
4060
4139
  gnosis: {
4061
4140
  chainName: "Gnosis",
4141
+ blockchain: "gnosis",
4062
4142
  chainIcon: "/chains/gnosis.png",
4063
4143
  chainIconGray: "/chains/gnosis-gray.png",
4064
4144
  chainType: chainTypes.evm.value,
@@ -4069,10 +4149,11 @@ var chains = {
4069
4149
  symbol: "XDAI",
4070
4150
  decimals: 18
4071
4151
  },
4072
- rpcUrl: chainsRpcUrls["Gnosis"]
4152
+ rpcUrls: getRpcUrls("gnosis")
4073
4153
  },
4074
4154
  op: {
4075
4155
  chainName: "Optimism",
4156
+ blockchain: "op",
4076
4157
  chainIcon: "/chains/optimism.png",
4077
4158
  chainIconGray: "/chains/optimism-gray.png",
4078
4159
  chainType: chainTypes.evm.value,
@@ -4083,10 +4164,11 @@ var chains = {
4083
4164
  symbol: "ETH",
4084
4165
  decimals: 18
4085
4166
  },
4086
- rpcUrl: chainsRpcUrls["Optimism"]
4167
+ rpcUrls: getRpcUrls("op")
4087
4168
  },
4088
4169
  tron: {
4089
4170
  chainName: "Tron",
4171
+ blockchain: "tron",
4090
4172
  chainIcon: "/chains/tron.png",
4091
4173
  chainIconGray: "/chains/tron-gray.png",
4092
4174
  chainType: chainTypes.tron.value,
@@ -4096,10 +4178,11 @@ var chains = {
4096
4178
  symbol: "TRX",
4097
4179
  decimals: 6
4098
4180
  },
4099
- rpcUrl: chainsRpcUrls["Tron"]
4181
+ rpcUrls: getRpcUrls("tron")
4100
4182
  },
4101
4183
  aptos: {
4102
4184
  chainName: "Aptos",
4185
+ blockchain: "aptos",
4103
4186
  chainIcon: "/chains/aptos.png",
4104
4187
  chainIconGray: "/chains/aptos-gray.png",
4105
4188
  chainType: chainTypes.aptos.value,
@@ -4109,10 +4192,11 @@ var chains = {
4109
4192
  symbol: "APT",
4110
4193
  decimals: 8
4111
4194
  },
4112
- rpcUrl: chainsRpcUrls["Aptos"]
4195
+ rpcUrls: getRpcUrls("aptos")
4113
4196
  },
4114
4197
  bera: {
4115
4198
  chainName: "Berachain",
4199
+ blockchain: "bera",
4116
4200
  chainIcon: "/chains/berachain.png",
4117
4201
  chainIconGray: "/chains/berachain-gray.png",
4118
4202
  chainType: chainTypes.evm.value,
@@ -4123,7 +4207,37 @@ var chains = {
4123
4207
  symbol: "BERA",
4124
4208
  decimals: 18
4125
4209
  },
4126
- rpcUrl: chainsRpcUrls["Berachain"]
4210
+ rpcUrls: getRpcUrls("bera")
4211
+ },
4212
+ xlayer: {
4213
+ chainName: "X Layer",
4214
+ blockchain: "xlayer",
4215
+ chainIcon: "/chains/xlayer.png",
4216
+ chainIconGray: "/chains/xlayer-gray.png",
4217
+ chainType: chainTypes.evm.value,
4218
+ chainId: 196,
4219
+ blockExplorerUrl: "https://www.oklink.com/xlayer/tx/",
4220
+ primaryColor: "#000000",
4221
+ nativeToken: {
4222
+ symbol: "OKB",
4223
+ decimals: 18
4224
+ },
4225
+ rpcUrls: getRpcUrls("xlayer")
4226
+ },
4227
+ plasma: {
4228
+ chainName: "Plasma",
4229
+ blockchain: "plasma",
4230
+ chainIcon: "/chains/plasma.png",
4231
+ chainIconGray: "/chains/plasma-gray.png",
4232
+ chainType: chainTypes.evm.value,
4233
+ chainId: 9745,
4234
+ blockExplorerUrl: "https://plasmascan.to/tx/",
4235
+ primaryColor: "#162F29",
4236
+ nativeToken: {
4237
+ symbol: "XPL",
4238
+ decimals: 18
4239
+ },
4240
+ rpcUrls: getRpcUrls("plasma")
4127
4241
  }
4128
4242
  };
4129
4243
  var chains_default = chains;
@@ -4132,7 +4246,8 @@ var chains_default = chains;
4132
4246
  var usdt = {
4133
4247
  symbol: "USDT",
4134
4248
  decimals: 6,
4135
- icon: "/usdt.png"
4249
+ icon: "/usdt.png",
4250
+ name: "Tether USD"
4136
4251
  };
4137
4252
  var usdtChains = {
4138
4253
  eth: {
@@ -4190,7 +4305,7 @@ var usdtChains = {
4190
4305
  assetId: "nep141:sol-c800a4bd850783ccb82c2b2c7e84175443606352.omft.near",
4191
4306
  contractAddress: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
4192
4307
  ...chains_default.sol,
4193
- services: [Service.OneClick]
4308
+ services: [Service.OneClick, Service.Usdt0]
4194
4309
  },
4195
4310
  tron: {
4196
4311
  ...usdt,
@@ -4212,6 +4327,20 @@ var usdtChains = {
4212
4327
  contractAddress: "0x779Ded0c9e1022225f8E0630b35a9b54bE713736",
4213
4328
  ...chains_default.bera,
4214
4329
  services: [Service.OneClick, Service.Usdt0]
4330
+ },
4331
+ xlayer: {
4332
+ ...usdt,
4333
+ assetId: "nep245:v2_1.omni.hot.tg:196_2fezDCvVYRsG8wrK6deJ2VRPiAS1",
4334
+ contractAddress: "0x779ded0c9e1022225f8e0630b35a9b54be713736",
4335
+ ...chains_default.xlayer,
4336
+ services: [Service.OneClick, Service.Usdt0]
4337
+ },
4338
+ plasma: {
4339
+ ...usdt,
4340
+ assetId: "nep245:v2_1.omni.hot.tg:9745_3aL9skCy1yhPoDB8oKMmRHRN7SJW",
4341
+ contractAddress: "0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb",
4342
+ ...chains_default.plasma,
4343
+ services: [Service.OneClick]
4215
4344
  }
4216
4345
  };
4217
4346
 
@@ -4219,7 +4348,8 @@ var usdtChains = {
4219
4348
  var usdc = {
4220
4349
  symbol: "USDC",
4221
4350
  decimals: 6,
4222
- icon: "/usdc.png"
4351
+ icon: "/usdc.png",
4352
+ name: "USD Coin"
4223
4353
  };
4224
4354
  var usdcChains = {
4225
4355
  eth: {
@@ -4285,6 +4415,13 @@ var usdcChains = {
4285
4415
  contractAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
4286
4416
  ...chains_default.sol,
4287
4417
  services: [Service.OneClick, Service.CCTP]
4418
+ },
4419
+ xlayer: {
4420
+ ...usdc,
4421
+ assetId: "nep245:v2_1.omni.hot.tg:196_2dK9kLNR7Ekq7su8FxNGiUW3djTw",
4422
+ contractAddress: "0x74b7f16337b8972027f6196a17a631ac6de26d22",
4423
+ ...chains_default.xlayer,
4424
+ services: [Service.OneClick]
4288
4425
  }
4289
4426
  };
4290
4427
 
@@ -4304,6 +4441,45 @@ var TransactionStatus = /* @__PURE__ */ ((TransactionStatus2) => {
4304
4441
  return TransactionStatus2;
4305
4442
  })(TransactionStatus || {});
4306
4443
 
4444
+ // src/utils/error.ts
4445
+ var import_big2 = __toESM(require("big.js"));
4446
+ var formatQuoteError = (error, options) => {
4447
+ const { service, fromToken } = options;
4448
+ const defaultErrorMessage = "Failed to get quote, please try again later";
4449
+ if (service === Service.OneClick) {
4450
+ const getQuoteErrorMessage = () => {
4451
+ const _messageResult = {
4452
+ message: defaultErrorMessage,
4453
+ sourceMessage: error?.response?.data?.message || defaultErrorMessage
4454
+ };
4455
+ if (error?.response?.data?.message && error?.response?.data?.message !== "Internal server error") {
4456
+ if (error?.response?.data?.message === "Failed to get quote") {
4457
+ _messageResult.message = "Amount exceeds max";
4458
+ return _messageResult;
4459
+ }
4460
+ if (error?.response?.data?.message?.includes("Amount is too low for bridge, try at least")) {
4461
+ const match = error.response.data.message.match(/try at least\s+(\d+(?:\.\d+)?)/i);
4462
+ let minimumAmount = match ? match[1] : (0, import_big2.default)(1).times(10 ** fromToken.decimals).toFixed(0);
4463
+ minimumAmount = (0, import_big2.default)(minimumAmount).div(10 ** fromToken.decimals).toFixed(fromToken.decimals);
4464
+ _messageResult.message = `Amount is too low, at least ${minimumAmount}`;
4465
+ return _messageResult;
4466
+ }
4467
+ return _messageResult;
4468
+ }
4469
+ return _messageResult;
4470
+ };
4471
+ const onclickErrMsg = getQuoteErrorMessage();
4472
+ return {
4473
+ serviceType: service,
4474
+ error: onclickErrMsg.message
4475
+ };
4476
+ }
4477
+ return {
4478
+ serviceType: service,
4479
+ error: error?.message || defaultErrorMessage
4480
+ };
4481
+ };
4482
+
4307
4483
  // src/services/SFA.ts
4308
4484
  var submitOneclickDepositTx = (requestBody) => {
4309
4485
  return request(OpenAPI, {
@@ -4408,10 +4584,10 @@ var SFA = class {
4408
4584
  static async getAllQuote(params) {
4409
4585
  const results = [];
4410
4586
  let { minInputAmount = "1" } = params;
4411
- if ((0, import_big2.default)(minInputAmount).lte(0)) {
4587
+ if ((0, import_big3.default)(minInputAmount).lte(0)) {
4412
4588
  minInputAmount = "1";
4413
4589
  }
4414
- if (!params.fromToken || !params.fromToken.contractAddress || !params.toToken || !params.toToken.contractAddress || !params.refundTo || !params.recipient || !params.amountWei || (0, import_big2.default)(params.amountWei).lte(minInputAmount)) {
4590
+ if (!params.fromToken || !params.fromToken.contractAddress || !params.toToken || !params.toToken.contractAddress || !params.refundTo || !params.recipient || !params.amountWei || (0, import_big3.default)(params.amountWei).lte(minInputAmount)) {
4415
4591
  throw new Error("Invalid parameters");
4416
4592
  }
4417
4593
  const formatQuoteParams = (service) => {
@@ -4432,6 +4608,9 @@ var SFA = class {
4432
4608
  _params.destinationAsset = params.toToken.assetId;
4433
4609
  _params.amount = params.amountWei;
4434
4610
  _params.refundType = "ORIGIN_CHAIN";
4611
+ _params.appFees = params.oneclickParams?.appFees;
4612
+ _params.swapType = params.oneclickParams?.swapType;
4613
+ _params.isProxy = params.oneclickParams?.isProxy;
4435
4614
  }
4436
4615
  if (service === Service.Usdt0) {
4437
4616
  _params.originChain = params.fromToken.chainName;
@@ -4460,42 +4639,6 @@ var SFA = class {
4460
4639
  });
4461
4640
  }
4462
4641
  }
4463
- const formatQuoteError = (service, error) => {
4464
- const defaultErrorMessage = "Failed to get quote, please try again later";
4465
- if (service === Service.OneClick) {
4466
- const getQuoteErrorMessage = () => {
4467
- const _messageResult = {
4468
- message: defaultErrorMessage,
4469
- sourceMessage: error?.response?.data?.message || defaultErrorMessage
4470
- };
4471
- if (error?.response?.data?.message && error?.response?.data?.message !== "Internal server error") {
4472
- if (error?.response?.data?.message === "Failed to get quote") {
4473
- _messageResult.message = "Amount exceeds max";
4474
- return _messageResult;
4475
- }
4476
- if (error?.response?.data?.message?.includes("Amount is too low for bridge, try at least")) {
4477
- const match = error.response.data.message.match(/try at least\s+(\d+(?:\.\d+)?)/i);
4478
- let minimumAmount = match ? match[1] : (0, import_big2.default)(1).times(10 ** fromToken.decimals).toFixed(0);
4479
- minimumAmount = (0, import_big2.default)(minimumAmount).div(10 ** fromToken.decimals).toFixed(fromToken.decimals);
4480
- _messageResult.message = `Amount is too low, at least ${minimumAmount}`;
4481
- return _messageResult;
4482
- }
4483
- return _messageResult;
4484
- }
4485
- return _messageResult;
4486
- };
4487
- const onclickErrMsg = getQuoteErrorMessage();
4488
- results.push({
4489
- serviceType: service,
4490
- error: onclickErrMsg.message
4491
- });
4492
- } else {
4493
- results.push({
4494
- serviceType: service,
4495
- error: error?.message || defaultErrorMessage
4496
- });
4497
- }
4498
- };
4499
4642
  if (params.singleService) {
4500
4643
  const quoteService = quoteServices.find((service) => service.service === params.singleService);
4501
4644
  if (quoteService) {
@@ -4506,7 +4649,8 @@ var SFA = class {
4506
4649
  quote: quoteRes
4507
4650
  });
4508
4651
  } catch (error) {
4509
- formatQuoteError(quoteService.service, error);
4652
+ const _err = formatQuoteError(error, { service: quoteService.service, fromToken });
4653
+ results.push(_err);
4510
4654
  }
4511
4655
  }
4512
4656
  return results;
@@ -4522,7 +4666,8 @@ var SFA = class {
4522
4666
  });
4523
4667
  } catch (error) {
4524
4668
  console.log("%s quote failed: %o", quoteService.service, error);
4525
- formatQuoteError(quoteService.service, error);
4669
+ const _err = formatQuoteError(error, { service: quoteService.service, fromToken });
4670
+ results.push(_err);
4526
4671
  }
4527
4672
  })();
4528
4673
  promises.push(promise);
@@ -4577,7 +4722,7 @@ var SFA = class {
4577
4722
  project: projectMap[serviceType],
4578
4723
  address: params.quote?.quoteParam?.refundTo,
4579
4724
  receive_address: params.quote?.quoteParam?.recipient,
4580
- amount: (0, import_big2.default)(params.quote?.quoteParam?.amountWei || 0).div(10 ** (params.quote?.fromToken?.decimals || 6)).toFixed(params.quote?.fromToken?.decimals || 6, 0)
4725
+ amount: (0, import_big3.default)(params.quote?.quoteParam?.amountWei || 0).div(10 ** (params.quote?.fromToken?.decimals || 6)).toFixed(params.quote?.fromToken?.decimals || 6, 0)
4581
4726
  };
4582
4727
  if (serviceType === Service.OneClick) {
4583
4728
  reportParams.deposit_address = params.quote?.quote?.depositAddress;
@@ -4664,13 +4809,184 @@ var SFA = class {
4664
4809
  */
4665
4810
  SFA.submitDepositTx = submitOneclickDepositTx;
4666
4811
 
4812
+ // src/services/Hyperliquid.ts
4813
+ var import_ethers = require("ethers");
4814
+ var import_big4 = __toESM(require("big.js"));
4815
+ var SPENDER = "0x2df1c51e09aecf9cacb7bc98cb1742757f163df7";
4816
+ var DESTINATION_TOKEN = usdcChains["arb"];
4817
+ var MIN_AMOUNT = (0, import_big4.default)(5).times(10 ** DESTINATION_TOKEN.decimals).toFixed(0);
4818
+ var HyperliquidService = class {
4819
+ async quote(params) {
4820
+ const result = { quote: null, error: null };
4821
+ if ((0, import_big4.default)(params.amountWei || 0).lt(MIN_AMOUNT)) {
4822
+ result.error = `Amount is too low, at least ${MIN_AMOUNT}`;
4823
+ return result;
4824
+ }
4825
+ const quoteParams = {
4826
+ ...params,
4827
+ dry: params.dry ?? true,
4828
+ slippageTolerance: params.slippageTolerance * 100,
4829
+ originAsset: params.fromToken.assetId,
4830
+ toToken: DESTINATION_TOKEN,
4831
+ destinationAsset: DESTINATION_TOKEN.assetId,
4832
+ amount: params.amountWei,
4833
+ refundType: "ORIGIN_CHAIN",
4834
+ appFees: params.oneclickParams?.appFees,
4835
+ swapType: "EXACT_OUTPUT",
4836
+ isProxy: false
4837
+ };
4838
+ try {
4839
+ const quoteRes = await ServiceMap[Service.OneClick].quote(quoteParams);
4840
+ result.quote = quoteRes;
4841
+ } catch (error) {
4842
+ const _err = formatQuoteError(error, { service: Service.OneClick, fromToken: params.fromToken });
4843
+ result.error = _err.error;
4844
+ }
4845
+ return result;
4846
+ }
4847
+ async transfer(params) {
4848
+ const {
4849
+ quote,
4850
+ wallet
4851
+ } = params;
4852
+ const sendParams = {
4853
+ wallet,
4854
+ sendParam: quote?.sendParam,
4855
+ fromToken: quote?.quoteParam.fromToken,
4856
+ depositAddress: quote?.quote?.depositAddress,
4857
+ amountWei: quote?.quote?.amountIn
4858
+ };
4859
+ const txhash = await ServiceMap[Service.OneClick].send(sendParams);
4860
+ return txhash;
4861
+ }
4862
+ async deposit(params) {
4863
+ const {
4864
+ evmWallet,
4865
+ evmWalletAddress,
4866
+ quote,
4867
+ txhash
4868
+ } = params;
4869
+ const permitParams = await this.generatePermit({
4870
+ address: evmWalletAddress,
4871
+ evmWallet,
4872
+ amountWei: quote?.quote?.amountOut
4873
+ });
4874
+ const depositParams = {
4875
+ deposit_address: quote?.quote?.depositAddress,
4876
+ from_addr: quote?.quoteParam?.refundTo,
4877
+ from_amount: quote?.quote?.amountIn,
4878
+ from_chain: quote?.quoteParam?.fromToken?.blockchain,
4879
+ from_hash: txhash,
4880
+ from_token: quote?.quoteParam?.fromToken?.contractAddress,
4881
+ sender: quote?.quoteParam?.recipient,
4882
+ to_amount: quote?.quote?.amountOut,
4883
+ to_chain: quote?.quoteParam?.toToken?.blockchain,
4884
+ to_token: quote?.quoteParam?.toToken?.contractAddress,
4885
+ type: Service.OneClick,
4886
+ permit: permitParams
4887
+ };
4888
+ const depositRes = await request(OpenAPI, {
4889
+ method: "POST",
4890
+ url: "/v0/deposit",
4891
+ body: depositParams,
4892
+ mediaType: "application/json",
4893
+ errors: {
4894
+ 400: `Bad Request - Invalid input data`,
4895
+ 401: `Unauthorized - JWT token is invalid`
4896
+ }
4897
+ });
4898
+ return depositRes;
4899
+ }
4900
+ async getStatus(params) {
4901
+ return request(OpenAPI, {
4902
+ method: "GET",
4903
+ url: "/v0/deposit",
4904
+ query: {
4905
+ depositId: params.depositId
4906
+ },
4907
+ mediaType: "application/json",
4908
+ errors: {
4909
+ 400: `Bad Request - Invalid input data`,
4910
+ 401: `Unauthorized - JWT token is invalid`
4911
+ }
4912
+ });
4913
+ }
4914
+ async generatePermit(params) {
4915
+ const {
4916
+ address,
4917
+ evmWallet,
4918
+ amountWei
4919
+ } = params;
4920
+ const tokenAddress = DESTINATION_TOKEN.contractAddress;
4921
+ const name = DESTINATION_TOKEN.name;
4922
+ const chainId = DESTINATION_TOKEN.chainId;
4923
+ const provider = new import_ethers.ethers.JsonRpcProvider(getRpcUrls("arb")[0]);
4924
+ const erc20 = new import_ethers.ethers.Contract(
4925
+ tokenAddress,
4926
+ [
4927
+ "function name() view returns (string)",
4928
+ "function nonces(address) view returns (uint256)",
4929
+ "function decimals() view returns (uint8)"
4930
+ ],
4931
+ provider
4932
+ );
4933
+ const deadline = Math.floor(Date.now() / 1e3) + 86400;
4934
+ const nonce = await erc20.nonces(address);
4935
+ const value = amountWei;
4936
+ const domain = {
4937
+ name,
4938
+ version: "2",
4939
+ chainId: Number(chainId),
4940
+ verifyingContract: tokenAddress
4941
+ };
4942
+ const types = {
4943
+ Permit: [
4944
+ { name: "owner", type: "address" },
4945
+ { name: "spender", type: "address" },
4946
+ { name: "value", type: "uint256" },
4947
+ { name: "nonce", type: "uint256" },
4948
+ { name: "deadline", type: "uint256" }
4949
+ ]
4950
+ };
4951
+ const values = {
4952
+ owner: address,
4953
+ spender: SPENDER,
4954
+ value,
4955
+ nonce: nonce.toString(),
4956
+ deadline
4957
+ };
4958
+ const signature = await evmWallet.signTypedData({
4959
+ domain,
4960
+ types,
4961
+ values
4962
+ });
4963
+ const { v, r, s } = import_ethers.ethers.Signature.from(signature);
4964
+ const permitParams = {
4965
+ amount: value,
4966
+ deadline,
4967
+ owner: address,
4968
+ r,
4969
+ s,
4970
+ spender: SPENDER,
4971
+ token: tokenAddress,
4972
+ v,
4973
+ nonce: Number(nonce)
4974
+ };
4975
+ return permitParams;
4976
+ }
4977
+ };
4978
+ var Hyperliquid = new HyperliquidService();
4979
+ var HyperliquidFromTokens = tokens.filter((token) => !(token.chainName === "Arbitrum" && token.symbol === "USDC"));
4980
+ var HyperliuquidToToken = DESTINATION_TOKEN;
4981
+ var HyperliuquidMinAmount = MIN_AMOUNT;
4982
+
4667
4983
  // src/wallets/near.ts
4668
4984
  var import_buffer = require("buffer");
4669
- var import_big3 = __toESM(require("big.js"));
4985
+ var import_big5 = __toESM(require("big.js"));
4670
4986
  var NearWallet = class {
4671
4987
  constructor(_selector) {
4672
4988
  this.selector = _selector;
4673
- this.rpcUrl = chainsRpcUrls["Near"];
4989
+ this.rpcUrl = getRpcUrls("near")[0];
4674
4990
  }
4675
4991
  async query(contractId, methodName, args = {}) {
4676
4992
  const response = await fetch(this.rpcUrl, {
@@ -4957,10 +5273,10 @@ var NearWallet = class {
4957
5273
  totalGasLimit = totalGasLimit * 120n / 100n;
4958
5274
  const gasPrice = BigInt("100000000");
4959
5275
  const estimateGas = totalGasLimit * gasPrice;
4960
- const estimateGasUsd = (0, import_big3.default)(estimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
4961
- result.fees.sourceGasFeeUsd = numberRemoveEndZero((0, import_big3.default)(estimateGasUsd).toFixed(20));
5276
+ const estimateGasUsd = (0, import_big5.default)(estimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
5277
+ result.fees.sourceGasFeeUsd = numberRemoveEndZero((0, import_big5.default)(estimateGasUsd).toFixed(20));
4962
5278
  result.estimateSourceGas = estimateGas.toString();
4963
- result.estimateSourceGasUsd = numberRemoveEndZero((0, import_big3.default)(estimateGasUsd).toFixed(20));
5279
+ result.estimateSourceGasUsd = numberRemoveEndZero((0, import_big5.default)(estimateGasUsd).toFixed(20));
4964
5280
  result.sendParam = {
4965
5281
  transactions,
4966
5282
  callbackUrl: "/"
@@ -4970,10 +5286,10 @@ var NearWallet = class {
4970
5286
  const defaultGasLimit = BigInt("80000000000000");
4971
5287
  const gasPrice = BigInt("100000000");
4972
5288
  const estimateGas = defaultGasLimit * gasPrice;
4973
- const estimateGasUsd = (0, import_big3.default)(estimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
4974
- result.fees.sourceGasFeeUsd = numberRemoveEndZero((0, import_big3.default)(estimateGasUsd).toFixed(20));
5289
+ const estimateGasUsd = (0, import_big5.default)(estimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
5290
+ result.fees.sourceGasFeeUsd = numberRemoveEndZero((0, import_big5.default)(estimateGasUsd).toFixed(20));
4975
5291
  result.estimateSourceGas = estimateGas.toString();
4976
- result.estimateSourceGasUsd = numberRemoveEndZero((0, import_big3.default)(estimateGasUsd).toFixed(20));
5292
+ result.estimateSourceGasUsd = numberRemoveEndZero((0, import_big5.default)(estimateGasUsd).toFixed(20));
4977
5293
  }
4978
5294
  return result;
4979
5295
  }
@@ -5023,10 +5339,10 @@ var NearWallet = class {
5023
5339
  };
5024
5340
 
5025
5341
  // src/wallets/solana.ts
5026
- var import_web3 = require("@solana/web3.js");
5342
+ var import_web32 = require("@solana/web3.js");
5027
5343
  var import_spl_token = require("@solana/spl-token");
5028
5344
  var import_anchor = require("@coral-xyz/anchor");
5029
- var import_big4 = __toESM(require("big.js"));
5345
+ var import_big6 = __toESM(require("big.js"));
5030
5346
 
5031
5347
  // src/bridges/oneclick/stableflow-proxy.json
5032
5348
  var stableflow_proxy_default = {
@@ -5326,9 +5642,107 @@ var stableflow_proxy_default = {
5326
5642
  };
5327
5643
 
5328
5644
  // src/wallets/solana.ts
5645
+ var import_ethers3 = require("ethers");
5646
+ var import_lz_v2_utilities = require("@layerzerolabs/lz-v2-utilities");
5647
+
5648
+ // src/bridges/usdt0/hop-composer.ts
5649
+ var import_ethers2 = require("ethers");
5650
+ var getHopMsgFee = async (params) => {
5651
+ const {
5652
+ sendParam,
5653
+ toToken
5654
+ } = params;
5655
+ const originLayerzero = USDT0_CONFIG["Arbitrum"];
5656
+ const destinationLayerzero = USDT0_CONFIG[toToken.chainName];
5657
+ let arbitrumOft = originLayerzero.oft;
5658
+ let destinationLayerzeroAddress = destinationLayerzero.oft || destinationLayerzero.oftLegacy;
5659
+ const isDestinationLegacy = destinationLayerzeroAddress === destinationLayerzero.oftLegacy;
5660
+ if (isDestinationLegacy) {
5661
+ arbitrumOft = originLayerzero.oftLegacy || originLayerzero.oft;
5662
+ }
5663
+ const provider = new import_ethers2.ethers.JsonRpcProvider(getRpcUrls("arb")[0]);
5664
+ const oftContractRead = new import_ethers2.ethers.Contract(arbitrumOft, OFT_ABI, provider);
5665
+ try {
5666
+ const msgFee = await oftContractRead.quoteSend.staticCall(sendParam, false);
5667
+ const [nativeFee] = msgFee;
5668
+ return nativeFee * 120n / 100n;
5669
+ } catch (error) {
5670
+ console.log("getHopMsgFee failed: %o", error);
5671
+ throw new Error("Quote multi hop message fee failed");
5672
+ }
5673
+ };
5674
+
5675
+ // src/wallets/utils/layerzero.ts
5676
+ var import_web3 = require("@solana/web3.js");
5677
+ var import_serializers = require("@metaplex-foundation/umi/serializers");
5678
+ var SEEDS = {
5679
+ OFT: Buffer.from("OFT"),
5680
+ PEER: Buffer.from("Peer"),
5681
+ CREDITS: Buffer.from("Credits"),
5682
+ EVENT_AUTHORITY: Buffer.from("__event_authority")
5683
+ };
5684
+ var DISCRIMINATOR = {
5685
+ quoteSend: new Uint8Array([207, 0, 49, 214, 160, 211, 76, 211]),
5686
+ send: new Uint8Array([102, 251, 20, 187, 65, 75, 12, 69])
5687
+ };
5688
+ function u32be(n) {
5689
+ const buf = Buffer.alloc(4);
5690
+ buf.writeUInt32BE(n, 0);
5691
+ return buf;
5692
+ }
5693
+ function deriveOftPdas(programId, dstEid) {
5694
+ return {
5695
+ oftStore: import_web3.PublicKey.findProgramAddressSync([SEEDS.OFT], programId)[0],
5696
+ peer: import_web3.PublicKey.findProgramAddressSync([SEEDS.PEER, u32be(dstEid)], programId)[0],
5697
+ credits: import_web3.PublicKey.findProgramAddressSync([SEEDS.CREDITS], programId)[0],
5698
+ eventAuthority: import_web3.PublicKey.findProgramAddressSync([SEEDS.EVENT_AUTHORITY], programId)[0]
5699
+ };
5700
+ }
5701
+ async function getPeerAddress(connection, programId, dstEid) {
5702
+ const { peer } = deriveOftPdas(programId, dstEid);
5703
+ const info = await connection.getAccountInfo(peer);
5704
+ if (!info) throw new Error(`Peer not found for EID ${dstEid}`);
5705
+ return `0x${info.data.subarray(8, 40).toString("hex")}`;
5706
+ }
5707
+ var quoteSendParamsSerializer = (0, import_serializers.struct)([
5708
+ ["dstEid", (0, import_serializers.u32)()],
5709
+ ["to", (0, import_serializers.bytes)({ size: 32 })],
5710
+ ["amountLd", (0, import_serializers.u64)()],
5711
+ ["minAmountLd", (0, import_serializers.u64)()],
5712
+ ["extraOptions", (0, import_serializers.bytes)({ size: (0, import_serializers.u32)() })],
5713
+ ["composeMsg", (0, import_serializers.option)((0, import_serializers.bytes)({ size: (0, import_serializers.u32)() }))],
5714
+ ["payInLzToken", (0, import_serializers.bool)()]
5715
+ ]);
5716
+ function encodeQuoteSend(params) {
5717
+ const paramsData = quoteSendParamsSerializer.serialize(params);
5718
+ const data = new Uint8Array(8 + paramsData.length);
5719
+ data.set(DISCRIMINATOR.quoteSend, 0);
5720
+ data.set(paramsData, 8);
5721
+ return data;
5722
+ }
5723
+ var sendParamsSerializer = (0, import_serializers.struct)([
5724
+ ["dstEid", (0, import_serializers.u32)()],
5725
+ ["to", (0, import_serializers.bytes)({ size: 32 })],
5726
+ ["amountLd", (0, import_serializers.u64)()],
5727
+ ["minAmountLd", (0, import_serializers.u64)()],
5728
+ ["extraOptions", (0, import_serializers.bytes)({ size: (0, import_serializers.u32)() })],
5729
+ ["composeMsg", (0, import_serializers.option)((0, import_serializers.bytes)({ size: (0, import_serializers.u32)() }))],
5730
+ ["nativeFee", (0, import_serializers.u64)()],
5731
+ ["lzTokenFee", (0, import_serializers.u64)()]
5732
+ ]);
5733
+ function encodeSend(params) {
5734
+ const paramsData = sendParamsSerializer.serialize(params);
5735
+ const data = new Uint8Array(8 + paramsData.length);
5736
+ data.set(DISCRIMINATOR.send, 0);
5737
+ data.set(paramsData, 8);
5738
+ return data;
5739
+ }
5740
+
5741
+ // src/wallets/solana.ts
5742
+ var import_lz_solana_sdk_v2 = require("@layerzerolabs/lz-solana-sdk-v2");
5329
5743
  var SolanaWallet = class {
5330
5744
  constructor(options) {
5331
- this.connection = new import_web3.Connection(chainsRpcUrls["Solana"], "confirmed");
5745
+ this.connection = new import_web32.Connection(getRpcUrls("sol")[0], "confirmed");
5332
5746
  this.publicKey = options.publicKey;
5333
5747
  this.signTransaction = options.signer.signTransaction;
5334
5748
  this.signer = options.signer;
@@ -5339,10 +5753,10 @@ var SolanaWallet = class {
5339
5753
  throw new Error("Wallet not connected");
5340
5754
  }
5341
5755
  const fromPubkey = this.publicKey;
5342
- const toPubkey = new import_web3.PublicKey(to);
5343
- const lamports = Math.floor(parseFloat(amount) * import_web3.LAMPORTS_PER_SOL);
5344
- const transaction = new import_web3.Transaction().add(
5345
- import_web3.SystemProgram.transfer({
5756
+ const toPubkey = new import_web32.PublicKey(to);
5757
+ const lamports = Math.floor(parseFloat(amount) * import_web32.LAMPORTS_PER_SOL);
5758
+ const transaction = new import_web32.Transaction().add(
5759
+ import_web32.SystemProgram.transfer({
5346
5760
  fromPubkey,
5347
5761
  toPubkey,
5348
5762
  lamports
@@ -5364,11 +5778,11 @@ var SolanaWallet = class {
5364
5778
  throw new Error("Wallet not connected");
5365
5779
  }
5366
5780
  const fromPubkey = this.publicKey;
5367
- const toPubkey = new import_web3.PublicKey(to);
5368
- const mint = new import_web3.PublicKey(tokenMint);
5781
+ const toPubkey = new import_web32.PublicKey(to);
5782
+ const mint = new import_web32.PublicKey(tokenMint);
5369
5783
  const fromTokenAccount = (0, import_spl_token.getAssociatedTokenAddressSync)(mint, fromPubkey);
5370
5784
  const toTokenAccount = (0, import_spl_token.getAssociatedTokenAddressSync)(mint, toPubkey);
5371
- const transaction = new import_web3.Transaction();
5785
+ const transaction = new import_web32.Transaction();
5372
5786
  try {
5373
5787
  await (0, import_spl_token.getAccount)(this.connection, toTokenAccount);
5374
5788
  } catch (error) {
@@ -5419,13 +5833,13 @@ var SolanaWallet = class {
5419
5833
  return result;
5420
5834
  }
5421
5835
  async getSOLBalance(account) {
5422
- const publicKey = new import_web3.PublicKey(account);
5836
+ const publicKey = new import_web32.PublicKey(account);
5423
5837
  const balance = await this.connection.getBalance(publicKey);
5424
5838
  return balance;
5425
5839
  }
5426
5840
  async getTokenBalance(tokenMint, account) {
5427
- const mint = new import_web3.PublicKey(tokenMint);
5428
- const owner = new import_web3.PublicKey(account);
5841
+ const mint = new import_web32.PublicKey(tokenMint);
5842
+ const owner = new import_web32.PublicKey(account);
5429
5843
  try {
5430
5844
  const tokenAccount = await (0, import_spl_token.getAssociatedTokenAddress)(mint, owner);
5431
5845
  const accountInfo = await (0, import_spl_token.getAccount)(this.connection, tokenAccount);
@@ -5458,8 +5872,8 @@ var SolanaWallet = class {
5458
5872
  let estimatedFee = 5000n;
5459
5873
  const { originAsset, depositAddress } = data;
5460
5874
  if (originAsset !== "SOL" && originAsset !== "sol") {
5461
- const mint = new import_web3.PublicKey(originAsset);
5462
- const toPubkey = new import_web3.PublicKey(depositAddress);
5875
+ const mint = new import_web32.PublicKey(originAsset);
5876
+ const toPubkey = new import_web32.PublicKey(depositAddress);
5463
5877
  const toTokenAccount = (0, import_spl_token.getAssociatedTokenAddressSync)(mint, toPubkey);
5464
5878
  try {
5465
5879
  await (0, import_spl_token.getAccount)(this.connection, toTokenAccount);
@@ -5508,12 +5922,12 @@ var SolanaWallet = class {
5508
5922
  return false;
5509
5923
  }
5510
5924
  async simulateIx(ix) {
5511
- const tx = new import_web3.Transaction().add(ix);
5925
+ const tx = new import_web32.Transaction().add(ix);
5512
5926
  const { blockhash } = await this.connection.getLatestBlockhash();
5513
5927
  tx.recentBlockhash = blockhash;
5514
5928
  tx.feePayer = this.publicKey;
5515
5929
  const message = tx.compileMessage();
5516
- const versionedTx = new import_web3.VersionedTransaction(message);
5930
+ const versionedTx = new import_web32.VersionedTransaction(message);
5517
5931
  const sim = await this.connection.simulateTransaction(versionedTx, {
5518
5932
  // commitment: "confirmed",
5519
5933
  sigVerify: false
@@ -5560,6 +5974,8 @@ var SolanaWallet = class {
5560
5974
  return await this.quoteCCTP(params);
5561
5975
  case Service.OneClick:
5562
5976
  return await this.quoteOneClickProxy(params);
5977
+ case Service.Usdt0:
5978
+ return await this.quoteOFT(params);
5563
5979
  default:
5564
5980
  throw new Error(`Unsupported quote type: ${type}`);
5565
5981
  }
@@ -5590,20 +6006,20 @@ var SolanaWallet = class {
5590
6006
  } = params;
5591
6007
  try {
5592
6008
  const result = { fees: {} };
5593
- const PROGRAM_ID = new import_web3.PublicKey(proxyAddress);
5594
- const STATE_PDA = new import_web3.PublicKey("9E8az3Y9sdXvM2f3CCH6c9N3iFyNfDryQCZhqDxRYGUw");
5595
- const MINT = new import_web3.PublicKey(fromToken.contractAddress);
6009
+ const PROGRAM_ID = new import_web32.PublicKey(proxyAddress);
6010
+ const STATE_PDA = new import_web32.PublicKey("9E8az3Y9sdXvM2f3CCH6c9N3iFyNfDryQCZhqDxRYGUw");
6011
+ const MINT = new import_web32.PublicKey(fromToken.contractAddress);
5596
6012
  const AMOUNT = new import_anchor.BN(amountWei);
5597
- const RECIPIENT = new import_web3.PublicKey(depositAddress);
6013
+ const RECIPIENT = new import_web32.PublicKey(depositAddress);
5598
6014
  const sender = this.publicKey;
5599
- const userPubkey = new import_web3.PublicKey(refundTo || sender.toString());
6015
+ const userPubkey = new import_web32.PublicKey(refundTo || sender.toString());
5600
6016
  const provider = new import_anchor.AnchorProvider(this.connection, this.signer, {
5601
6017
  commitment: "confirmed"
5602
6018
  });
5603
6019
  const program = new import_anchor.Program(stableflow_proxy_default, PROGRAM_ID, provider);
5604
6020
  const userTokenAccount = (0, import_spl_token.getAssociatedTokenAddressSync)(MINT, userPubkey);
5605
6021
  const toTokenAccount = (0, import_spl_token.getAssociatedTokenAddressSync)(MINT, RECIPIENT);
5606
- const transaction = new import_web3.Transaction();
6022
+ const transaction = new import_web32.Transaction();
5607
6023
  try {
5608
6024
  await (0, import_spl_token.getAccount)(this.connection, toTokenAccount);
5609
6025
  } catch (error) {
@@ -5628,14 +6044,14 @@ var SolanaWallet = class {
5628
6044
  tokenProgram: import_spl_token.TOKEN_PROGRAM_ID,
5629
6045
  user: userPubkey,
5630
6046
  toUser: RECIPIENT,
5631
- systemProgram: import_web3.SystemProgram.programId
6047
+ systemProgram: import_web32.SystemProgram.programId
5632
6048
  }).instruction();
5633
6049
  transaction.add(transferInstruction);
5634
6050
  const { blockhash } = await this.connection.getLatestBlockhash();
5635
6051
  transaction.recentBlockhash = blockhash;
5636
6052
  transaction.feePayer = userPubkey;
5637
6053
  const message = transaction.compileMessage();
5638
- const versionedTx = new import_web3.VersionedTransaction(message);
6054
+ const versionedTx = new import_web32.VersionedTransaction(message);
5639
6055
  const simulation = await this.connection.simulateTransaction(versionedTx, {
5640
6056
  sigVerify: false
5641
6057
  });
@@ -5643,7 +6059,7 @@ var SolanaWallet = class {
5643
6059
  transaction
5644
6060
  };
5645
6061
  const estimatedFee = simulation.value.fee || 5000n;
5646
- const estimateGasUsd = (0, import_big4.default)(estimatedFee.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
6062
+ const estimateGasUsd = (0, import_big6.default)(estimatedFee.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
5647
6063
  const usd = numberRemoveEndZero(estimateGasUsd.toFixed(20));
5648
6064
  const wei = estimatedFee;
5649
6065
  result.fees.sourceGasFeeUsd = usd;
@@ -5683,13 +6099,13 @@ var SolanaWallet = class {
5683
6099
  estimateSourceGas: void 0,
5684
6100
  estimateSourceGasUsd: void 0,
5685
6101
  estimateTime: 0,
5686
- outputAmount: numberRemoveEndZero((0, import_big4.default)(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0))
6102
+ outputAmount: numberRemoveEndZero((0, import_big6.default)(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0))
5687
6103
  };
5688
- const PROGRAM_ID = new import_web3.PublicKey(proxyAddress);
5689
- const MINT = new import_web3.PublicKey(fromToken.contractAddress);
6104
+ const PROGRAM_ID = new import_web32.PublicKey(proxyAddress);
6105
+ const MINT = new import_web32.PublicKey(fromToken.contractAddress);
5690
6106
  const sender = this.publicKey;
5691
- const userPubkey = new import_web3.PublicKey(refundTo || sender.toString());
5692
- const [userStatePda] = import_web3.PublicKey.findProgramAddressSync(
6107
+ const userPubkey = new import_web32.PublicKey(refundTo || sender.toString());
6108
+ const [userStatePda] = import_web32.PublicKey.findProgramAddressSync(
5693
6109
  [Buffer.from("user"), userPubkey.toBuffer()],
5694
6110
  PROGRAM_ID
5695
6111
  );
@@ -5706,7 +6122,7 @@ var SolanaWallet = class {
5706
6122
  const userTokenAccount = (0, import_spl_token.getAssociatedTokenAddressSync)(MINT, userPubkey);
5707
6123
  const signatureRes = await cctp_default.quoteSignature({
5708
6124
  address: userPubkey.toString(),
5709
- amount: numberRemoveEndZero((0, import_big4.default)(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0)),
6125
+ amount: numberRemoveEndZero((0, import_big6.default)(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0)),
5710
6126
  destination_domain_id: destinationDomain,
5711
6127
  receipt_address: recipient,
5712
6128
  source_domain_id: sourceDomain,
@@ -5720,26 +6136,26 @@ var SolanaWallet = class {
5720
6136
  signature
5721
6137
  } = signatureRes;
5722
6138
  result.fees.estimateMintGasUsd = numberRemoveEndZero(
5723
- (0, import_big4.default)(mint_fee || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals)
6139
+ (0, import_big6.default)(mint_fee || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals)
5724
6140
  );
5725
6141
  result.fees.bridgeFeeUsd = numberRemoveEndZero(
5726
- (0, import_big4.default)(bridge_fee || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals)
6142
+ (0, import_big6.default)(bridge_fee || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals)
5727
6143
  );
5728
6144
  result.outputAmount = numberRemoveEndZero(
5729
- (0, import_big4.default)(receipt_amount || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0)
6145
+ (0, import_big6.default)(receipt_amount || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0)
5730
6146
  );
5731
- const operatorTx = import_web3.Transaction.from(Buffer.from(signature, "base64"));
6147
+ const operatorTx = import_web32.Transaction.from(Buffer.from(signature, "base64"));
5732
6148
  if (!operatorTx.verifySignatures(false)) {
5733
6149
  console.log("\u274C Signature verification failed");
5734
6150
  } else {
5735
6151
  }
5736
6152
  const message = operatorTx.compileMessage();
5737
- const versionedTx = new import_web3.VersionedTransaction(message);
6153
+ const versionedTx = new import_web32.VersionedTransaction(message);
5738
6154
  const simulation = await this.connection.simulateTransaction(versionedTx, {
5739
6155
  sigVerify: false
5740
6156
  });
5741
6157
  const estimatedFee = simulation.value.fee || 5000n;
5742
- const estimateGasUsd = (0, import_big4.default)(estimatedFee.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
6158
+ const estimateGasUsd = (0, import_big6.default)(estimatedFee.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
5743
6159
  result.fees.estimateDepositGasUsd = numberRemoveEndZero(estimateGasUsd.toFixed(20));
5744
6160
  result.estimateSourceGas = estimatedFee;
5745
6161
  result.estimateSourceGasUsd = numberRemoveEndZero(estimateGasUsd.toFixed(20));
@@ -5750,15 +6166,249 @@ var SolanaWallet = class {
5750
6166
  if (excludeFees4 && excludeFees4.includes(feeKey) || !/Usd$/.test(feeKey)) {
5751
6167
  continue;
5752
6168
  }
5753
- result.totalFeesUsd = (0, import_big4.default)(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
6169
+ result.totalFeesUsd = (0, import_big6.default)(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
5754
6170
  }
5755
- result.totalFeesUsd = numberRemoveEndZero((0, import_big4.default)(result.totalFeesUsd || 0).toFixed(20));
6171
+ result.totalFeesUsd = numberRemoveEndZero((0, import_big6.default)(result.totalFeesUsd || 0).toFixed(20));
5756
6172
  return result;
5757
6173
  } catch (error) {
5758
6174
  console.log("quoteCCTP failed: %o", error);
5759
6175
  return { errMsg: error.message };
5760
6176
  }
5761
6177
  }
6178
+ async quoteOFT(params) {
6179
+ const {
6180
+ originLayerzeroAddress,
6181
+ destinationLayerzeroAddress,
6182
+ fromToken,
6183
+ toToken,
6184
+ dstEid,
6185
+ refundTo,
6186
+ recipient,
6187
+ amountWei,
6188
+ payInLzToken,
6189
+ slippageTolerance,
6190
+ multiHopComposer,
6191
+ isMultiHopComposer,
6192
+ isOriginLegacy,
6193
+ prices,
6194
+ excludeFees: excludeFees4,
6195
+ originLayerzero
6196
+ } = params;
6197
+ try {
6198
+ const result = {
6199
+ needApprove: false,
6200
+ sendParam: void 0,
6201
+ fees: {},
6202
+ estimateSourceGas: void 0,
6203
+ estimateSourceGasUsd: void 0,
6204
+ outputAmount: numberRemoveEndZero((0, import_big6.default)(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0)),
6205
+ quoteParam: {
6206
+ ...params
6207
+ },
6208
+ totalFeesUsd: void 0,
6209
+ estimateTime: 0
6210
+ };
6211
+ const programId = new import_web32.PublicKey(originLayerzeroAddress);
6212
+ const tokenMint = new import_web32.PublicKey(fromToken.contractAddress);
6213
+ const quotePayer = new import_web32.PublicKey("4NkxtcfRTCxJ1N2j6xENcDLPbiJ3541T6r5BqhTzMD9J");
6214
+ const lookupTable = new import_web32.PublicKey("6zcTrmdkiQp6dZHYUxVr6A2XVDSYi44X1rcPtvwNcrXi");
6215
+ const tokenEscrow = new import_web32.PublicKey("F1YkdxaiLA1eJt12y3uMAQef48Td3zdJfYhzjphma8hG");
6216
+ const sender = this.publicKey;
6217
+ const userPubkey = new import_web32.PublicKey(refundTo || sender.toString());
6218
+ const mintInfo = await this.connection.getParsedAccountInfo(tokenMint);
6219
+ const decimals = (mintInfo.value?.data).parsed.info.decimals;
6220
+ const amountLd = BigInt(amountWei);
6221
+ const slippage = slippageTolerance || 0.01;
6222
+ const minAmountLd = BigInt((0, import_big6.default)(amountWei).times((0, import_big6.default)(1).minus((0, import_big6.default)(slippage).div(100))).toFixed(0));
6223
+ const lzReceiveOptionGas = isOriginLegacy ? originLayerzero.lzReceiveOptionGasLegacy : originLayerzero.lzReceiveOptionGas;
6224
+ const lzReceiveOptionValue = LZ_RECEIVE_VALUE[toToken.chainName] || 0;
6225
+ let _dstEid = dstEid;
6226
+ let to = new Uint8Array(Buffer.from((0, import_lz_v2_utilities.addressToBytes32)(recipient)));
6227
+ let extraOptions = import_lz_v2_utilities.Options.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).toBytes();
6228
+ let composeMsg = null;
6229
+ if (isMultiHopComposer) {
6230
+ _dstEid = multiHopComposer.eid;
6231
+ to = new Uint8Array(Buffer.from((0, import_lz_v2_utilities.addressToBytes32)(multiHopComposer.oftMultiHopComposer)));
6232
+ const composeMsgSendParam = {
6233
+ dstEid,
6234
+ to: (0, import_lz_v2_utilities.addressToBytes32)(recipient),
6235
+ amountLD: amountLd,
6236
+ minAmountLD: minAmountLd,
6237
+ extraOptions: import_lz_v2_utilities.Options.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).toHex(),
6238
+ composeMsg: "0x",
6239
+ oftCmd: "0x"
6240
+ };
6241
+ const hopMsgFee = await getHopMsgFee({
6242
+ sendParam: composeMsgSendParam,
6243
+ toToken
6244
+ });
6245
+ extraOptions = import_lz_v2_utilities.Options.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).addExecutorComposeOption(0, originLayerzero.composeOptionGas || 5e5, hopMsgFee).toBytes();
6246
+ const abiCoder = import_ethers3.ethers.AbiCoder.defaultAbiCoder();
6247
+ const composeEncoder = abiCoder.encode(
6248
+ ["tuple(uint32 dstEid, bytes32 to, uint256 amountLD, uint256 minAmountLD, bytes extraOptions, bytes composeMsg, bytes oftCmd)"],
6249
+ [Object.values(composeMsgSendParam)]
6250
+ );
6251
+ composeMsg = import_ethers3.ethers.getBytes(composeEncoder);
6252
+ }
6253
+ const pdas = deriveOftPdas(programId, _dstEid);
6254
+ const peerAddress = await getPeerAddress(this.connection, programId, _dstEid);
6255
+ const tokenSource = await (0, import_spl_token.getAssociatedTokenAddress)(
6256
+ tokenMint,
6257
+ userPubkey,
6258
+ false,
6259
+ import_spl_token.TOKEN_PROGRAM_ID
6260
+ );
6261
+ const sendHelper = new import_lz_solana_sdk_v2.SendHelper();
6262
+ const remainingAccounts = await sendHelper.getQuoteAccounts(
6263
+ this.connection,
6264
+ quotePayer,
6265
+ pdas.oftStore,
6266
+ _dstEid,
6267
+ peerAddress
6268
+ );
6269
+ const ix = new import_web32.TransactionInstruction({
6270
+ programId,
6271
+ keys: [
6272
+ { pubkey: pdas.oftStore, isSigner: false, isWritable: false },
6273
+ { pubkey: pdas.credits, isSigner: false, isWritable: false },
6274
+ { pubkey: pdas.peer, isSigner: false, isWritable: false },
6275
+ ...remainingAccounts
6276
+ ],
6277
+ data: Buffer.from(
6278
+ encodeQuoteSend({
6279
+ dstEid: _dstEid,
6280
+ to,
6281
+ amountLd,
6282
+ minAmountLd,
6283
+ extraOptions,
6284
+ composeMsg,
6285
+ payInLzToken: false
6286
+ })
6287
+ )
6288
+ });
6289
+ const computeIx = import_web32.ComputeBudgetProgram.setComputeUnitLimit({ units: 14e5 });
6290
+ const tx = await (0, import_lz_solana_sdk_v2.buildVersionedTransaction)(
6291
+ this.connection,
6292
+ quotePayer,
6293
+ [computeIx, ix],
6294
+ void 0,
6295
+ void 0,
6296
+ lookupTable
6297
+ );
6298
+ const sim = await this.connection.simulateTransaction(tx, {
6299
+ sigVerify: false,
6300
+ replaceRecentBlockhash: true
6301
+ });
6302
+ if (sim.value.err) {
6303
+ console.error("Simulation logs:", sim.value.logs);
6304
+ throw new Error(`Quote failed: ${JSON.stringify(sim.value.err)}`);
6305
+ }
6306
+ const prefix = `Program return: ${programId} `;
6307
+ const log = sim.value.logs?.find((l) => l.startsWith(prefix));
6308
+ if (!log) throw new Error("Return data not found");
6309
+ const data = Buffer.from(log.slice(prefix.length), "base64");
6310
+ const nativeFee = data.readBigUInt64LE(0);
6311
+ const lzTokenFee = data.readBigUInt64LE(8);
6312
+ if (prices && fromToken.nativeToken) {
6313
+ const nativeFeeUsd = (0, import_big6.default)(nativeFee.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
6314
+ result.fees.nativeFeeUsd = numberRemoveEndZero(nativeFeeUsd.toFixed(20));
6315
+ }
6316
+ result.fees.nativeFee = (0, import_big6.default)(nativeFee.toString()).div(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals, 0);
6317
+ if (lzTokenFee > 0n && prices && fromToken) {
6318
+ const lzTokenFeeUsd = (0, import_big6.default)(lzTokenFee.toString()).div(10 ** fromToken.decimals).times(getPrice(prices, fromToken.symbol));
6319
+ result.fees.lzTokenFeeUsd = numberRemoveEndZero(lzTokenFeeUsd.toFixed(20));
6320
+ }
6321
+ result.fees.lzTokenFee = lzTokenFee.toString();
6322
+ const sendSendHelper = new import_lz_solana_sdk_v2.SendHelper();
6323
+ const sendRemainingAccounts = await sendSendHelper.getSendAccounts(
6324
+ this.connection,
6325
+ userPubkey,
6326
+ pdas.oftStore,
6327
+ _dstEid,
6328
+ peerAddress
6329
+ );
6330
+ const sendIx = new import_web32.TransactionInstruction({
6331
+ programId,
6332
+ keys: [
6333
+ { pubkey: userPubkey, isSigner: true, isWritable: true },
6334
+ { pubkey: pdas.peer, isSigner: false, isWritable: false },
6335
+ { pubkey: pdas.oftStore, isSigner: false, isWritable: true },
6336
+ { pubkey: pdas.credits, isSigner: false, isWritable: true },
6337
+ { pubkey: tokenSource, isSigner: false, isWritable: true },
6338
+ { pubkey: tokenEscrow, isSigner: false, isWritable: true },
6339
+ { pubkey: tokenMint, isSigner: false, isWritable: false },
6340
+ { pubkey: import_spl_token.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
6341
+ { pubkey: pdas.eventAuthority, isSigner: false, isWritable: false },
6342
+ { pubkey: programId, isSigner: false, isWritable: false },
6343
+ ...sendRemainingAccounts
6344
+ ],
6345
+ data: Buffer.from(
6346
+ encodeSend({
6347
+ dstEid: _dstEid,
6348
+ to,
6349
+ amountLd,
6350
+ minAmountLd,
6351
+ extraOptions,
6352
+ composeMsg,
6353
+ nativeFee,
6354
+ lzTokenFee: 0n
6355
+ })
6356
+ )
6357
+ });
6358
+ const computeSendIx = import_web32.ComputeBudgetProgram.setComputeUnitLimit({ units: 4e5 });
6359
+ const sendTx = await (0, import_lz_solana_sdk_v2.buildVersionedTransaction)(
6360
+ this.connection,
6361
+ userPubkey,
6362
+ [computeSendIx, sendIx],
6363
+ void 0,
6364
+ void 0,
6365
+ lookupTable
6366
+ );
6367
+ let estimatedFee = 5000n;
6368
+ try {
6369
+ const sendSim = await this.connection.simulateTransaction(sendTx, {
6370
+ sigVerify: false,
6371
+ replaceRecentBlockhash: true
6372
+ });
6373
+ console.log("sendSim: %o", JSON.stringify(sendSim));
6374
+ if (!sendSim.value.err) {
6375
+ estimatedFee = sendSim.value.fee || 5000n;
6376
+ } else {
6377
+ console.warn("Send simulation failed (this is normal in quote phase):", sendSim.value.err);
6378
+ const fee = sendSim.value.fee;
6379
+ if (fee) {
6380
+ estimatedFee = fee;
6381
+ }
6382
+ }
6383
+ } catch (simError) {
6384
+ console.warn("Send simulation error (this is normal in quote phase):", simError.message);
6385
+ }
6386
+ if (prices && fromToken.nativeToken) {
6387
+ const estimateGasUsd = (0, import_big6.default)(estimatedFee.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
6388
+ result.fees.estimateSourceGasUsd = numberRemoveEndZero(estimateGasUsd.toFixed(20));
6389
+ result.estimateSourceGasUsd = numberRemoveEndZero(estimateGasUsd.toFixed(20));
6390
+ }
6391
+ result.estimateSourceGas = estimatedFee;
6392
+ result.fees.legacyMeshFeeUsd = numberRemoveEndZero((0, import_big6.default)(amountWei || 0).div(10 ** params.fromToken.decimals).times(USDT0_LEGACY_MESH_TRANSFTER_FEE).toFixed(params.fromToken.decimals));
6393
+ result.outputAmount = numberRemoveEndZero((0, import_big6.default)((0, import_big6.default)(amountWei || 0).div(10 ** params.fromToken.decimals)).minus(result.fees.legacyMeshFeeUsd || 0).toFixed(params.fromToken.decimals, 0));
6394
+ result.sendParam = {
6395
+ transaction: sendTx
6396
+ };
6397
+ if (prices) {
6398
+ for (const feeKey in result.fees) {
6399
+ if (excludeFees4 && excludeFees4.includes(feeKey) || !/Usd$/.test(feeKey)) {
6400
+ continue;
6401
+ }
6402
+ result.totalFeesUsd = (0, import_big6.default)(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
6403
+ }
6404
+ result.totalFeesUsd = numberRemoveEndZero((0, import_big6.default)(result.totalFeesUsd || 0).toFixed(20));
6405
+ }
6406
+ return result;
6407
+ } catch (error) {
6408
+ console.log("quoteOFT failed: %o", error);
6409
+ return { errMsg: error.message };
6410
+ }
6411
+ }
5762
6412
  async createAssociatedTokenAddress(params) {
5763
6413
  const {
5764
6414
  tokenMint
@@ -5767,11 +6417,11 @@ var SolanaWallet = class {
5767
6417
  throw new Error("Wallet not connected");
5768
6418
  }
5769
6419
  const ownerPubkey = this.publicKey;
5770
- const mint = new import_web3.PublicKey(tokenMint);
6420
+ const mint = new import_web32.PublicKey(tokenMint);
5771
6421
  const associatedTokenAccount = (0, import_spl_token.getAssociatedTokenAddressSync)(mint, ownerPubkey);
5772
6422
  console.log("associatedTokenAccount: %o", associatedTokenAccount);
5773
6423
  const createTokenAccount = async () => {
5774
- const transaction = new import_web3.Transaction();
6424
+ const transaction = new import_web32.Transaction();
5775
6425
  transaction.add(
5776
6426
  (0, import_spl_token.createAssociatedTokenAccountInstruction)(
5777
6427
  ownerPubkey,
@@ -5843,13 +6493,13 @@ var erc20_default = [
5843
6493
  ];
5844
6494
 
5845
6495
  // src/wallets/evm.ts
5846
- var import_big5 = __toESM(require("big.js"));
5847
- var import_ethers2 = require("ethers");
5848
- var import_lz_v2_utilities = require("@layerzerolabs/lz-v2-utilities");
6496
+ var import_big7 = __toESM(require("big.js"));
6497
+ var import_ethers5 = require("ethers");
6498
+ var import_lz_v2_utilities2 = require("@layerzerolabs/lz-v2-utilities");
5849
6499
 
5850
6500
  // src/utils/address.ts
5851
6501
  var import_bs58 = __toESM(require("bs58"));
5852
- var import_ethers = require("ethers");
6502
+ var import_ethers4 = require("ethers");
5853
6503
  function tronAddressToBytes32(tronAddress) {
5854
6504
  try {
5855
6505
  const decoded = import_bs58.default.decode(tronAddress);
@@ -5875,9 +6525,9 @@ function solanaAddressToBytes32(solanaAddress) {
5875
6525
  }
5876
6526
  return "0x" + Buffer.from(decoded).toString("hex");
5877
6527
  }
5878
- function addressToBytes32(chainType, address) {
6528
+ function addressToBytes322(chainType, address) {
5879
6529
  if (chainType === "evm") {
5880
- return (0, import_ethers.zeroPadValue)(address, 32);
6530
+ return (0, import_ethers4.zeroPadValue)(address, 32);
5881
6531
  }
5882
6532
  if (chainType === "sol") {
5883
6533
  return solanaAddressToBytes32(address);
@@ -5887,9 +6537,40 @@ function addressToBytes32(chainType, address) {
5887
6537
  }
5888
6538
  }
5889
6539
 
5890
- // src/wallets/evm.ts
5891
- var import_web32 = require("@solana/web3.js");
6540
+ // src/wallets/utils/solana.ts
5892
6541
  var import_spl_token2 = require("@solana/spl-token");
6542
+ var import_web33 = require("@solana/web3.js");
6543
+ var getDestinationAssociatedTokenAddress = async (params) => {
6544
+ const {
6545
+ recipient,
6546
+ toToken
6547
+ } = params;
6548
+ const result = {
6549
+ needCreateTokenAccount: false,
6550
+ associatedTokenAddress: ""
6551
+ };
6552
+ if (toToken.chainType !== "sol") {
6553
+ return result;
6554
+ }
6555
+ try {
6556
+ const connection = new import_web33.Connection(getRpcUrls("sol")[0]);
6557
+ const wallet = new import_web33.PublicKey(recipient);
6558
+ const TOKEN_MINT = new import_web33.PublicKey(toToken.contractAddress);
6559
+ const ata = (0, import_spl_token2.getAssociatedTokenAddressSync)(TOKEN_MINT, wallet);
6560
+ const accountInfo = await connection.getAccountInfo(ata);
6561
+ console.log("accountInfo: %o", accountInfo);
6562
+ if (!accountInfo) {
6563
+ result.needCreateTokenAccount = true;
6564
+ return result;
6565
+ }
6566
+ result.associatedTokenAddress = ata.toBase58();
6567
+ } catch (error) {
6568
+ console.log("getDestinationAssociatedTokenAddress failed: %o", error);
6569
+ }
6570
+ return result;
6571
+ };
6572
+
6573
+ // src/wallets/evm.ts
5893
6574
  var DEFAULT_GAS_LIMIT = 100000n;
5894
6575
  var EVMWallet = class {
5895
6576
  constructor(_provider, _signer) {
@@ -5901,12 +6582,12 @@ var EVMWallet = class {
5901
6582
  if (originAsset === "eth") {
5902
6583
  const tx2 = await this.signer.sendTransaction({
5903
6584
  to: depositAddress,
5904
- value: import_ethers2.ethers.parseEther(amount)
6585
+ value: import_ethers5.ethers.parseEther(amount)
5905
6586
  });
5906
6587
  await tx2.wait();
5907
6588
  return tx2;
5908
6589
  }
5909
- const contract = new import_ethers2.ethers.Contract(originAsset, erc20_default, this.signer);
6590
+ const contract = new import_ethers5.ethers.Contract(originAsset, erc20_default, this.signer);
5910
6591
  const tx = await contract.transfer(depositAddress, amount);
5911
6592
  const result = await tx.wait();
5912
6593
  return result.hash;
@@ -5914,14 +6595,15 @@ var EVMWallet = class {
5914
6595
  async getBalance(token, account) {
5915
6596
  try {
5916
6597
  let provider = this.provider;
5917
- if (token.rpcUrl) {
5918
- provider = new import_ethers2.ethers.JsonRpcProvider(token.rpcUrl);
6598
+ if (token.rpcUrls) {
6599
+ const providers = token.rpcUrls.map((url) => new import_ethers5.ethers.JsonRpcProvider(url));
6600
+ provider = new import_ethers5.ethers.FallbackProvider(providers);
5919
6601
  }
5920
6602
  if (token.symbol === "eth" || token.symbol === "ETH" || token.symbol === "native") {
5921
6603
  const balance2 = await provider.getBalance(account);
5922
6604
  return balance2.toString();
5923
6605
  }
5924
- const contract = new import_ethers2.ethers.Contract(token.contractAddress, erc20_default, provider);
6606
+ const contract = new import_ethers5.ethers.Contract(token.contractAddress, erc20_default, provider);
5925
6607
  const balance = await contract.balanceOf(account);
5926
6608
  return balance.toString();
5927
6609
  } catch (err) {
@@ -5948,11 +6630,11 @@ var EVMWallet = class {
5948
6630
  const tx = {
5949
6631
  from: fromAddress,
5950
6632
  to: depositAddress,
5951
- value: import_ethers2.ethers.parseEther(amount)
6633
+ value: import_ethers5.ethers.parseEther(amount)
5952
6634
  };
5953
6635
  gasLimit = await this.provider.estimateGas(tx);
5954
6636
  } else {
5955
- const contract = new import_ethers2.ethers.Contract(originAsset, erc20_default, this.signer);
6637
+ const contract = new import_ethers5.ethers.Contract(originAsset, erc20_default, this.signer);
5956
6638
  gasLimit = await contract.transfer.estimateGas(depositAddress, amount);
5957
6639
  }
5958
6640
  gasLimit = gasLimit * 120n / 100n;
@@ -5970,7 +6652,7 @@ var EVMWallet = class {
5970
6652
  contractAddress,
5971
6653
  abi
5972
6654
  } = params;
5973
- return new import_ethers2.ethers.Contract(contractAddress, abi, this.signer);
6655
+ return new import_ethers5.ethers.Contract(contractAddress, abi, this.signer);
5974
6656
  }
5975
6657
  async allowance(params) {
5976
6658
  const {
@@ -5979,7 +6661,7 @@ var EVMWallet = class {
5979
6661
  address,
5980
6662
  amountWei
5981
6663
  } = params;
5982
- const contract = new import_ethers2.ethers.Contract(contractAddress, erc20_default, this.signer);
6664
+ const contract = new import_ethers5.ethers.Contract(contractAddress, erc20_default, this.signer);
5983
6665
  let allowance = "0";
5984
6666
  try {
5985
6667
  allowance = await contract.allowance(address, spender);
@@ -5990,7 +6672,7 @@ var EVMWallet = class {
5990
6672
  return {
5991
6673
  contract,
5992
6674
  allowance,
5993
- needApprove: (0, import_big5.default)(amountWei || 0).gt(allowance || 0)
6675
+ needApprove: (0, import_big7.default)(amountWei || 0).gt(allowance || 0)
5994
6676
  };
5995
6677
  }
5996
6678
  async approve(params) {
@@ -6000,10 +6682,10 @@ var EVMWallet = class {
6000
6682
  amountWei,
6001
6683
  isApproveMax = false
6002
6684
  } = params;
6003
- const contract = new import_ethers2.ethers.Contract(contractAddress, erc20_default, this.signer);
6685
+ const contract = new import_ethers5.ethers.Contract(contractAddress, erc20_default, this.signer);
6004
6686
  let _amountWei = amountWei;
6005
6687
  if (isApproveMax) {
6006
- _amountWei = import_ethers2.ethers.MaxUint256;
6688
+ _amountWei = import_ethers5.ethers.MaxUint256;
6007
6689
  }
6008
6690
  try {
6009
6691
  const tx = await contract.approve(spender, _amountWei);
@@ -6022,13 +6704,13 @@ var EVMWallet = class {
6022
6704
  const feeData = await this.provider.getFeeData();
6023
6705
  const gasPrice = feeData.maxFeePerGas || feeData.gasPrice || BigInt("20000000000");
6024
6706
  const estimateGas = BigInt(gasLimit) * BigInt(gasPrice);
6025
- const estimateGasAmount = (0, import_big5.default)(estimateGas.toString()).div(10 ** nativeToken.decimals);
6026
- const estimateGasUsd = (0, import_big5.default)(estimateGasAmount).times(price || 1);
6707
+ const estimateGasAmount = (0, import_big7.default)(estimateGas.toString()).div(10 ** nativeToken.decimals);
6708
+ const estimateGasUsd = (0, import_big7.default)(estimateGasAmount).times(price || 1);
6027
6709
  return {
6028
6710
  gasPrice,
6029
- usd: numberRemoveEndZero((0, import_big5.default)(estimateGasUsd).toFixed(20)),
6711
+ usd: numberRemoveEndZero((0, import_big7.default)(estimateGasUsd).toFixed(20)),
6030
6712
  wei: estimateGas,
6031
- amount: numberRemoveEndZero((0, import_big5.default)(estimateGasAmount).toFixed(nativeToken.decimals))
6713
+ amount: numberRemoveEndZero((0, import_big7.default)(estimateGasAmount).toFixed(nativeToken.decimals))
6032
6714
  };
6033
6715
  }
6034
6716
  async quoteOFT(params) {
@@ -6049,7 +6731,8 @@ var EVMWallet = class {
6049
6731
  multiHopComposer,
6050
6732
  isMultiHopComposer,
6051
6733
  isOriginLegacy,
6052
- isDestinationLegacy
6734
+ isDestinationLegacy,
6735
+ originLayerzero
6053
6736
  } = params;
6054
6737
  const result = {
6055
6738
  needApprove: false,
@@ -6066,12 +6749,11 @@ var EVMWallet = class {
6066
6749
  estimateSourceGasUsd: void 0,
6067
6750
  estimateTime: 0,
6068
6751
  // seconds - dynamically calculated using LayerZero formula
6069
- outputAmount: numberRemoveEndZero((0, import_big5.default)(amountWei || 0).div(10 ** params.fromToken.decimals).toFixed(params.fromToken.decimals, 0))
6752
+ outputAmount: numberRemoveEndZero((0, import_big7.default)(amountWei || 0).div(10 ** params.fromToken.decimals).toFixed(params.fromToken.decimals, 0))
6070
6753
  };
6071
- const oftContract = new import_ethers2.ethers.Contract(originLayerzeroAddress, abi, this.signer);
6072
- const oftContractRead = new import_ethers2.ethers.Contract(originLayerzeroAddress, abi, this.provider);
6754
+ const oftContract = new import_ethers5.ethers.Contract(originLayerzeroAddress, abi, this.signer);
6755
+ const oftContractRead = new import_ethers5.ethers.Contract(originLayerzeroAddress, abi, this.provider);
6073
6756
  const approvalRequired = await oftContractRead.approvalRequired();
6074
- console.log("%cApprovalRequired: %o", "background:blue;color:white;", approvalRequired);
6075
6757
  if (approvalRequired) {
6076
6758
  try {
6077
6759
  const allowanceResult = await this.allowance({
@@ -6085,42 +6767,52 @@ var EVMWallet = class {
6085
6767
  console.log("Error checking allowance: %o", error);
6086
6768
  }
6087
6769
  }
6770
+ const lzReceiveOptionGas = isOriginLegacy ? originLayerzero.lzReceiveOptionGasLegacy : originLayerzero.lzReceiveOptionGas;
6771
+ let lzReceiveOptionValue = 0;
6772
+ const destATA = await getDestinationAssociatedTokenAddress({
6773
+ recipient,
6774
+ toToken
6775
+ });
6776
+ if (destATA.needCreateTokenAccount) {
6777
+ lzReceiveOptionValue = LZ_RECEIVE_VALUE[toToken.chainName] || 0;
6778
+ }
6088
6779
  const sendParam = {
6089
6780
  dstEid,
6090
- to: addressToBytes32(toToken.chainType, recipient),
6781
+ to: addressToBytes322(toToken.chainType, recipient),
6091
6782
  amountLD: amountWei,
6092
6783
  minAmountLD: 0n,
6093
- extraOptions: "0x0003",
6784
+ extraOptions: import_lz_v2_utilities2.Options.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).toHex(),
6094
6785
  composeMsg: "0x",
6095
6786
  oftCmd: "0x"
6096
6787
  };
6097
6788
  if (isMultiHopComposer) {
6098
6789
  sendParam.dstEid = multiHopComposer.eid;
6099
- sendParam.to = addressToBytes32("evm", multiHopComposer.oftMultiHopComposer);
6100
- sendParam.extraOptions = import_lz_v2_utilities.Options.newOptions().addExecutorLzReceiveOption(250000000n, 0n).toHex();
6101
- const abiCoder = import_ethers2.ethers.AbiCoder.defaultAbiCoder();
6790
+ sendParam.to = addressToBytes322("evm", multiHopComposer.oftMultiHopComposer);
6791
+ const composeMsgSendParam = {
6792
+ dstEid,
6793
+ to: addressToBytes322(toToken.chainType, recipient),
6794
+ amountLD: sendParam.amountLD,
6795
+ minAmountLD: sendParam.minAmountLD,
6796
+ extraOptions: import_lz_v2_utilities2.Options.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).toHex(),
6797
+ composeMsg: "0x",
6798
+ oftCmd: "0x"
6799
+ };
6800
+ const hopMsgFee = await getHopMsgFee({
6801
+ sendParam: composeMsgSendParam,
6802
+ toToken
6803
+ });
6804
+ sendParam.extraOptions = import_lz_v2_utilities2.Options.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).addExecutorComposeOption(0, originLayerzero.composeOptionGas || 8e5, hopMsgFee).toHex();
6805
+ const abiCoder = import_ethers5.ethers.AbiCoder.defaultAbiCoder();
6102
6806
  sendParam.composeMsg = abiCoder.encode(
6103
6807
  ["tuple(uint32 dstEid, bytes32 to, uint256 amountLD, uint256 minAmountLD, bytes extraOptions, bytes composeMsg, bytes oftCmd)"],
6104
- [[
6105
- dstEid,
6106
- addressToBytes32(toToken.chainType, recipient),
6107
- sendParam.amountLD,
6108
- sendParam.minAmountLD,
6109
- "0x",
6110
- "0x",
6111
- "0x"
6112
- ]]
6808
+ [Object.values(composeMsgSendParam)]
6113
6809
  );
6114
6810
  }
6115
- if (isDestinationLegacy) {
6116
- result.fees.legacyMeshFeeUsd = numberRemoveEndZero((0, import_big5.default)(amountWei || 0).div(10 ** params.fromToken.decimals).times(3e-4).toFixed(params.fromToken.decimals));
6117
- }
6118
6811
  const oftData = await oftContractRead.quoteOFT.staticCall(sendParam);
6119
6812
  const [, , oftReceipt] = oftData;
6120
6813
  sendParam.minAmountLD = oftReceipt[1] * (1000000n - BigInt(slippageTolerance * 1e4)) / 1000000n;
6121
6814
  const msgFee = await oftContractRead.quoteSend.staticCall(sendParam, payInLzToken);
6122
6815
  result.estimateSourceGas = msgFee[0];
6123
- console.log("%cMsgFee: %o", "background:blue;color:white;", msgFee);
6124
6816
  result.sendParam = {
6125
6817
  contract: oftContract,
6126
6818
  method: "send",
@@ -6134,13 +6826,13 @@ var EVMWallet = class {
6134
6826
  { value: msgFee[0] }
6135
6827
  ]
6136
6828
  };
6137
- console.log("%cParams: %o", "background:blue;color:white;", result.sendParam);
6138
- const nativeFeeUsd = (0, import_big5.default)(msgFee[0]?.toString() || 0).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
6139
- result.fees.nativeFeeUsd = numberRemoveEndZero((0, import_big5.default)(nativeFeeUsd).toFixed(20));
6140
- result.fees.lzTokenFeeUsd = numberRemoveEndZero((0, import_big5.default)(msgFee[1]?.toString() || 0).div(10 ** fromToken.decimals).toFixed(20));
6141
- if (!isOriginLegacy && isDestinationLegacy) {
6142
- result.fees.legacyMeshFeeUsd = numberRemoveEndZero((0, import_big5.default)(amountWei || 0).div(10 ** fromToken.decimals).times(USDT0_LEGACY_FEE).toFixed(fromToken.decimals));
6143
- result.outputAmount = numberRemoveEndZero((0, import_big5.default)((0, import_big5.default)(amountWei || 0).div(10 ** params.fromToken.decimals)).minus(result.fees.legacyMeshFeeUsd || 0).toFixed(params.fromToken.decimals, 0));
6829
+ const nativeFeeUsd = (0, import_big7.default)(msgFee[0]?.toString() || 0).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
6830
+ result.fees.nativeFee = numberRemoveEndZero((0, import_big7.default)(msgFee[0]?.toString() || 0).div(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals));
6831
+ result.fees.nativeFeeUsd = numberRemoveEndZero((0, import_big7.default)(nativeFeeUsd).toFixed(20));
6832
+ result.fees.lzTokenFeeUsd = numberRemoveEndZero((0, import_big7.default)(msgFee[1]?.toString() || 0).div(10 ** fromToken.decimals).toFixed(20));
6833
+ if (isOriginLegacy || isDestinationLegacy) {
6834
+ result.fees.legacyMeshFeeUsd = numberRemoveEndZero((0, import_big7.default)(amountWei || 0).div(10 ** params.fromToken.decimals).times(USDT0_LEGACY_MESH_TRANSFTER_FEE).toFixed(params.fromToken.decimals));
6835
+ result.outputAmount = numberRemoveEndZero((0, import_big7.default)((0, import_big7.default)(amountWei || 0).div(10 ** params.fromToken.decimals)).minus(result.fees.legacyMeshFeeUsd || 0).toFixed(params.fromToken.decimals, 0));
6144
6836
  }
6145
6837
  try {
6146
6838
  const gasLimit = await oftContract.send.estimateGas(...result.sendParam.param);
@@ -6166,9 +6858,9 @@ var EVMWallet = class {
6166
6858
  if (excludeFees4.includes(feeKey)) {
6167
6859
  continue;
6168
6860
  }
6169
- result.totalFeesUsd = (0, import_big5.default)(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
6861
+ result.totalFeesUsd = (0, import_big7.default)(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
6170
6862
  }
6171
- result.totalFeesUsd = numberRemoveEndZero((0, import_big5.default)(result.totalFeesUsd).toFixed(20));
6863
+ result.totalFeesUsd = numberRemoveEndZero((0, import_big7.default)(result.totalFeesUsd).toFixed(20));
6172
6864
  return result;
6173
6865
  }
6174
6866
  async sendTransaction(params) {
@@ -6246,22 +6938,18 @@ var EVMWallet = class {
6246
6938
  estimateSourceGas: void 0,
6247
6939
  estimateSourceGasUsd: void 0,
6248
6940
  estimateTime: Math.floor(Math.random() * 8) + 3,
6249
- outputAmount: numberRemoveEndZero((0, import_big5.default)(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0))
6941
+ outputAmount: numberRemoveEndZero((0, import_big7.default)(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0))
6250
6942
  };
6251
- const proxyContract = new import_ethers2.ethers.Contract(proxyAddress, abi, this.signer);
6252
- const proxyContractRead = new import_ethers2.ethers.Contract(proxyAddress, abi, this.provider);
6943
+ const proxyContract = new import_ethers5.ethers.Contract(proxyAddress, abi, this.signer);
6944
+ const proxyContractRead = new import_ethers5.ethers.Contract(proxyAddress, abi, this.provider);
6253
6945
  let realRecipient = recipient;
6254
- if (toToken.chainType === "sol") {
6255
- const connection = new import_web32.Connection(chainsRpcUrls.Solana);
6256
- const wallet = new import_web32.PublicKey(recipient);
6257
- const USDC_MINT = new import_web32.PublicKey(toToken.contractAddress);
6258
- const ata = (0, import_spl_token2.getAssociatedTokenAddressSync)(USDC_MINT, wallet);
6259
- const accountInfo = await connection.getAccountInfo(ata);
6260
- if (!accountInfo) {
6261
- result.needCreateTokenAccount = true;
6262
- } else {
6263
- realRecipient = ata.toBase58();
6264
- }
6946
+ const destATA = await getDestinationAssociatedTokenAddress({
6947
+ recipient,
6948
+ toToken
6949
+ });
6950
+ result.needCreateTokenAccount = destATA.needCreateTokenAccount;
6951
+ if (destATA.associatedTokenAddress) {
6952
+ realRecipient = destATA.associatedTokenAddress;
6265
6953
  }
6266
6954
  let userNonce = 0n;
6267
6955
  try {
@@ -6270,7 +6958,7 @@ var EVMWallet = class {
6270
6958
  }
6271
6959
  const signatureRes = await cctp_default.quoteSignature({
6272
6960
  address: refundTo,
6273
- amount: numberRemoveEndZero((0, import_big5.default)(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0)),
6961
+ amount: numberRemoveEndZero((0, import_big7.default)(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0)),
6274
6962
  destination_domain_id: destinationDomain,
6275
6963
  receipt_address: realRecipient,
6276
6964
  source_domain_id: sourceDomain,
@@ -6285,10 +6973,10 @@ var EVMWallet = class {
6285
6973
  signature,
6286
6974
  destination_caller
6287
6975
  } = signatureRes;
6288
- result.fees.estimateMintGasUsd = numberRemoveEndZero((0, import_big5.default)(mint_fee || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals));
6289
- result.fees.bridgeFeeUsd = numberRemoveEndZero((0, import_big5.default)(bridge_fee || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals));
6976
+ result.fees.estimateMintGasUsd = numberRemoveEndZero((0, import_big7.default)(mint_fee || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals));
6977
+ result.fees.bridgeFeeUsd = numberRemoveEndZero((0, import_big7.default)(bridge_fee || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals));
6290
6978
  const chargedAmount = BigInt(amountWei) - BigInt(mint_fee);
6291
- result.outputAmount = numberRemoveEndZero((0, import_big5.default)(receipt_amount || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0));
6979
+ result.outputAmount = numberRemoveEndZero((0, import_big7.default)(receipt_amount || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0));
6292
6980
  const depositParam = [
6293
6981
  // originalAmount
6294
6982
  amountWei,
@@ -6297,11 +6985,11 @@ var EVMWallet = class {
6297
6985
  // destinationDomain
6298
6986
  destinationDomain,
6299
6987
  // mintRecipient
6300
- addressToBytes32(toToken.chainType, realRecipient),
6988
+ addressToBytes322(toToken.chainType, realRecipient),
6301
6989
  // burnToken
6302
6990
  fromToken.contractAddress,
6303
6991
  // destinationCaller
6304
- destination_caller ? addressToBytes32(toToken.chainType, destination_caller) : "0x0000000000000000000000000000000000000000000000000000000000000000",
6992
+ destination_caller ? addressToBytes322(toToken.chainType, destination_caller) : "0x0000000000000000000000000000000000000000000000000000000000000000",
6305
6993
  // maxFee
6306
6994
  max_fee,
6307
6995
  // minFinalityThreshold
@@ -6363,9 +7051,9 @@ var EVMWallet = class {
6363
7051
  if (excludeFees4.includes(feeKey) || !/Usd$/.test(feeKey)) {
6364
7052
  continue;
6365
7053
  }
6366
- result.totalFeesUsd = (0, import_big5.default)(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
7054
+ result.totalFeesUsd = (0, import_big7.default)(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
6367
7055
  }
6368
- result.totalFeesUsd = numberRemoveEndZero((0, import_big5.default)(result.totalFeesUsd).toFixed(20));
7056
+ result.totalFeesUsd = numberRemoveEndZero((0, import_big7.default)(result.totalFeesUsd).toFixed(20));
6369
7057
  return result;
6370
7058
  }
6371
7059
  async quoteOneClickProxy(params) {
@@ -6391,7 +7079,7 @@ var EVMWallet = class {
6391
7079
  } catch (error) {
6392
7080
  console.log("oneclick check allowance failed: %o", error);
6393
7081
  }
6394
- const proxyContract = new import_ethers2.ethers.Contract(proxyAddress, abi, this.signer);
7082
+ const proxyContract = new import_ethers5.ethers.Contract(proxyAddress, abi, this.signer);
6395
7083
  const proxyParam = [
6396
7084
  // tokenAddress
6397
7085
  fromToken.contractAddress,
@@ -6409,18 +7097,18 @@ var EVMWallet = class {
6409
7097
  price: getPrice(prices, fromToken.nativeToken.symbol),
6410
7098
  nativeToken: fromToken.nativeToken
6411
7099
  });
6412
- result.fees.sourceGasFeeUsd = numberRemoveEndZero((0, import_big5.default)(usd).toFixed(20));
7100
+ result.fees.sourceGasFeeUsd = numberRemoveEndZero((0, import_big7.default)(usd).toFixed(20));
6413
7101
  result.estimateSourceGas = wei;
6414
- result.estimateSourceGasUsd = numberRemoveEndZero((0, import_big5.default)(usd).toFixed(20));
7102
+ result.estimateSourceGasUsd = numberRemoveEndZero((0, import_big7.default)(usd).toFixed(20));
6415
7103
  } catch (error) {
6416
7104
  const { usd, wei } = await this.getEstimateGas({
6417
7105
  gasLimit: DEFAULT_GAS_LIMIT,
6418
7106
  price: getPrice(prices, fromToken.nativeToken.symbol),
6419
7107
  nativeToken: fromToken.nativeToken
6420
7108
  });
6421
- result.fees.sourceGasFeeUsd = numberRemoveEndZero((0, import_big5.default)(usd).toFixed(20));
7109
+ result.fees.sourceGasFeeUsd = numberRemoveEndZero((0, import_big7.default)(usd).toFixed(20));
6422
7110
  result.estimateSourceGas = wei;
6423
- result.estimateSourceGasUsd = numberRemoveEndZero((0, import_big5.default)(usd).toFixed(20));
7111
+ result.estimateSourceGasUsd = numberRemoveEndZero((0, import_big7.default)(usd).toFixed(20));
6424
7112
  }
6425
7113
  result.sendParam = {
6426
7114
  method: "proxyTransfer",
@@ -6432,27 +7120,50 @@ var EVMWallet = class {
6432
7120
  };
6433
7121
  return result;
6434
7122
  }
7123
+ async signTypedData(params) {
7124
+ const { domain, types, values } = params;
7125
+ return await this.signer?.signTypedData(domain, types, values);
7126
+ }
6435
7127
  };
6436
7128
 
6437
7129
  // src/wallets/tron.ts
6438
- var import_lz_v2_utilities2 = require("@layerzerolabs/lz-v2-utilities");
6439
- var import_ethers3 = require("ethers");
6440
- var import_big6 = __toESM(require("big.js"));
7130
+ var import_lz_v2_utilities3 = require("@layerzerolabs/lz-v2-utilities");
7131
+ var import_ethers6 = require("ethers");
7132
+ var import_big8 = __toESM(require("big.js"));
6441
7133
  var import_tronweb = require("tronweb");
7134
+ var DefaultTronWalletAddress = DefaultAddresses["tron"];
7135
+ var getCustomTronWeb = () => {
7136
+ return new import_tronweb.TronWeb({
7137
+ fullHost: getRpcUrls("tron")[0],
7138
+ headers: {},
7139
+ privateKey: ""
7140
+ });
7141
+ };
6442
7142
  var TronWallet = class {
6443
7143
  constructor(options) {
6444
7144
  this.signAndSendTransaction = options.signAndSendTransaction;
6445
- this.tronWeb = options.tronWeb;
7145
+ this.address = options.address;
7146
+ const customTronWeb = getCustomTronWeb();
7147
+ customTronWeb.setAddress(this.address || DefaultTronWalletAddress);
7148
+ this.tronWeb = customTronWeb;
6446
7149
  }
6447
7150
  async waitForTronWeb() {
6448
- return new Promise((resolve2, reject) => {
7151
+ return new Promise((resolve2) => {
6449
7152
  if (this.tronWeb) {
7153
+ const address = this.tronWeb.defaultAddress.base58 || DefaultTronWalletAddress;
7154
+ const customTronWeb = getCustomTronWeb();
7155
+ customTronWeb.setAddress(address);
7156
+ this.tronWeb = customTronWeb;
6450
7157
  resolve2(this.tronWeb);
6451
7158
  return;
6452
7159
  }
6453
7160
  const checkTronWeb = () => {
6454
7161
  if (window.tronWeb) {
6455
7162
  this.tronWeb = window.tronWeb;
7163
+ const address = this.tronWeb.defaultAddress.base58 || DefaultTronWalletAddress;
7164
+ const customTronWeb = getCustomTronWeb();
7165
+ customTronWeb.setAddress(address);
7166
+ this.tronWeb = customTronWeb;
6456
7167
  resolve2(this.tronWeb);
6457
7168
  } else {
6458
7169
  setTimeout(checkTronWeb, 100);
@@ -6460,12 +7171,9 @@ var TronWallet = class {
6460
7171
  };
6461
7172
  checkTronWeb();
6462
7173
  setTimeout(() => {
6463
- this.tronWeb = new import_tronweb.TronWeb({
6464
- fullHost: chainsRpcUrls["Tron"],
6465
- headers: {},
6466
- privateKey: ""
6467
- });
6468
- this.tronWeb.setAddress(DefaultAddresses["tron"]);
7174
+ const customTronWeb = getCustomTronWeb();
7175
+ customTronWeb.setAddress(DefaultTronWalletAddress);
7176
+ this.tronWeb = customTronWeb;
6469
7177
  resolve2(this.tronWeb);
6470
7178
  console.log(new Error("TronWeb initialization timeout"));
6471
7179
  }, 1e4);
@@ -6529,10 +7237,10 @@ var TronWallet = class {
6529
7237
  return await this.getBalance(token, account);
6530
7238
  }
6531
7239
  /**
6532
- * Estimate gas limit for transfer transaction
6533
- * @param data Transfer data
6534
- * @returns Gas limit estimate (bandwidth or energy), gas price, and estimated gas cost
6535
- */
7240
+ * Estimate gas limit for transfer transaction
7241
+ * @param data Transfer data
7242
+ * @returns Gas limit estimate (bandwidth or energy), gas price, and estimated gas cost
7243
+ */
6536
7244
  async estimateTransferGas(data) {
6537
7245
  const { originAsset } = data;
6538
7246
  await this.waitForTronWeb();
@@ -6543,14 +7251,7 @@ var TronWallet = class {
6543
7251
  gasLimit = 30000n;
6544
7252
  }
6545
7253
  gasLimit = gasLimit * 120n / 100n;
6546
- let gasPrice;
6547
- try {
6548
- const chainParameters = await this.tronWeb.trx.getChainParameters();
6549
- const energyPrice = chainParameters?.find((p) => p.key === "getEnergyFee")?.value || 420;
6550
- gasPrice = BigInt(energyPrice);
6551
- } catch (error) {
6552
- gasPrice = 420n;
6553
- }
7254
+ let gasPrice = 100n;
6554
7255
  const estimateGas = gasLimit * gasPrice;
6555
7256
  return {
6556
7257
  gasLimit,
@@ -6570,6 +7271,15 @@ var TronWallet = class {
6570
7271
  return false;
6571
7272
  }
6572
7273
  }
7274
+ async getTransactionResult(txHash) {
7275
+ await this.waitForTronWeb();
7276
+ try {
7277
+ const txInfo = await this.tronWeb.trx.getTransactionInfo(txHash);
7278
+ return txInfo;
7279
+ } catch (error) {
7280
+ return {};
7281
+ }
7282
+ }
6573
7283
  async allowance(params) {
6574
7284
  const {
6575
7285
  contractAddress,
@@ -6590,7 +7300,7 @@ var TronWallet = class {
6590
7300
  return {
6591
7301
  contract,
6592
7302
  allowance,
6593
- needApprove: (0, import_big6.default)(amountWei || 0).gt(allowance || 0)
7303
+ needApprove: (0, import_big8.default)(amountWei || 0).gt(allowance || 0)
6594
7304
  };
6595
7305
  } catch (error) {
6596
7306
  console.log("Error in allowance: %o", error);
@@ -6637,14 +7347,7 @@ var TronWallet = class {
6637
7347
  }
6638
7348
  async getEnergyPrice() {
6639
7349
  await this.waitForTronWeb();
6640
- let energyFee = 280;
6641
- try {
6642
- const params = await this.tronWeb.trx.getChainParameters();
6643
- energyFee = params.find((p) => p.key === "getEnergyFee")?.value || 280;
6644
- console.log("Energy Fee:", energyFee, "Sun/Energy");
6645
- } catch (err) {
6646
- console.error("Error getting energy price:", err);
6647
- }
7350
+ let energyFee = 100;
6648
7351
  return energyFee;
6649
7352
  }
6650
7353
  toBytes32(addr) {
@@ -6667,9 +7370,10 @@ var TronWallet = class {
6667
7370
  excludeFees: excludeFees4,
6668
7371
  refundTo,
6669
7372
  multiHopComposer,
6670
- isMultiHopComposer
6671
- // isOriginLegacy,
6672
- // isDestinationLegacy,
7373
+ isMultiHopComposer,
7374
+ isOriginLegacy,
7375
+ isDestinationLegacy,
7376
+ originLayerzero
6673
7377
  } = params;
6674
7378
  const result = {
6675
7379
  needApprove: false,
@@ -6686,12 +7390,11 @@ var TronWallet = class {
6686
7390
  estimateSourceGasUsd: void 0,
6687
7391
  estimateTime: 0,
6688
7392
  // seconds - dynamically calculated using LayerZero formula
6689
- outputAmount: numberRemoveEndZero((0, import_big6.default)(amountWei || 0).div(10 ** params.fromToken.decimals).toFixed(params.fromToken.decimals, 0))
7393
+ outputAmount: numberRemoveEndZero((0, import_big8.default)(amountWei || 0).div(10 ** params.fromToken.decimals).toFixed(params.fromToken.decimals, 0))
6690
7394
  };
6691
7395
  await this.waitForTronWeb();
6692
7396
  const oftContract = await this.tronWeb.contract(abi, originLayerzeroAddress);
6693
7397
  const approvalRequired = await oftContract.approvalRequired().call();
6694
- console.log("%cApprovalRequired: %o", "background:blue;color:white;", result.needApprove);
6695
7398
  if (approvalRequired) {
6696
7399
  try {
6697
7400
  const userAddress = refundTo || this.tronWeb.defaultAddress.base58;
@@ -6706,18 +7409,27 @@ var TronWallet = class {
6706
7409
  console.log("Error checking allowance: %o", error);
6707
7410
  }
6708
7411
  }
7412
+ const lzReceiveOptionGas = isOriginLegacy ? originLayerzero.lzReceiveOptionGasLegacy : originLayerzero.lzReceiveOptionGas;
7413
+ let lzReceiveOptionValue = 0;
7414
+ const destATA = await getDestinationAssociatedTokenAddress({
7415
+ recipient,
7416
+ toToken
7417
+ });
7418
+ if (destATA.needCreateTokenAccount) {
7419
+ lzReceiveOptionValue = LZ_RECEIVE_VALUE[toToken.chainName] || 0;
7420
+ }
6709
7421
  const sendParam = [
6710
7422
  // dstEid
6711
7423
  dstEid,
6712
7424
  // to
6713
7425
  // "0x0000000000000000000000000000000000000000000000000000000000000000",
6714
- addressToBytes32(toToken.chainType, recipient),
7426
+ addressToBytes322(toToken.chainType, recipient),
6715
7427
  // amountLD
6716
7428
  amountWei,
6717
7429
  // minAmountLD
6718
7430
  "0",
6719
7431
  // extraOptions
6720
- "0x",
7432
+ import_lz_v2_utilities3.Options.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).toHex(),
6721
7433
  // composeMsg
6722
7434
  "0x",
6723
7435
  // oftCmd
@@ -6725,71 +7437,63 @@ var TronWallet = class {
6725
7437
  ];
6726
7438
  if (isMultiHopComposer) {
6727
7439
  sendParam[0] = multiHopComposer.eid;
6728
- sendParam[1] = addressToBytes32("evm", multiHopComposer.oftMultiHopComposer);
7440
+ sendParam[1] = addressToBytes322("evm", multiHopComposer.oftMultiHopComposer);
6729
7441
  }
6730
7442
  const oftData = await oftContract.quoteOFT(sendParam).call();
6731
- console.log("oftData: %o", oftData);
6732
7443
  const [, , oftReceipt] = oftData;
6733
- sendParam[3] = (0, import_big6.default)(oftReceipt[1].toString()).times((0, import_big6.default)(1).minus((0, import_big6.default)(slippageTolerance || 0).div(100))).toFixed(0);
7444
+ sendParam[3] = (0, import_big8.default)(oftReceipt[1].toString()).times((0, import_big8.default)(1).minus((0, import_big8.default)(slippageTolerance || 0).div(100))).toFixed(0);
6734
7445
  const msgFee = await oftContract.quoteSend(sendParam, payInLzToken).call();
6735
- result.estimateSourceGas = msgFee[0]["nativeFee"];
7446
+ let nativeMsgFee = msgFee[0]["nativeFee"];
7447
+ if (nativeMsgFee) {
7448
+ nativeMsgFee = BigInt((0, import_big8.default)(nativeMsgFee.toString()).times(1.2).toFixed(0));
7449
+ }
7450
+ result.estimateSourceGas = nativeMsgFee;
6736
7451
  if (isMultiHopComposer) {
6737
- sendParam[4] = import_lz_v2_utilities2.Options.newOptions().addExecutorLzReceiveOption(250000000n, 0n).toHex();
6738
- const abiCoder = import_ethers3.ethers.AbiCoder.defaultAbiCoder();
7452
+ const composeMsgSendParam = {
7453
+ dstEid,
7454
+ to: addressToBytes322(toToken.chainType, recipient),
7455
+ amountLD: sendParam[2],
7456
+ minAmountLD: sendParam[3],
7457
+ extraOptions: import_lz_v2_utilities3.Options.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).toHex(),
7458
+ composeMsg: "0x",
7459
+ oftCmd: "0x"
7460
+ };
7461
+ const hopMsgFee = await getHopMsgFee({
7462
+ sendParam: composeMsgSendParam,
7463
+ toToken
7464
+ });
7465
+ sendParam[4] = import_lz_v2_utilities3.Options.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).addExecutorComposeOption(0, originLayerzero.composeOptionGas || 8e5, hopMsgFee).toHex();
7466
+ const abiCoder = import_ethers6.ethers.AbiCoder.defaultAbiCoder();
6739
7467
  sendParam[5] = abiCoder.encode(
6740
7468
  ["tuple(uint32 dstEid, bytes32 to, uint256 amountLD, uint256 minAmountLD, bytes extraOptions, bytes composeMsg, bytes oftCmd)"],
6741
- [[
6742
- dstEid,
6743
- addressToBytes32(toToken.chainType, recipient),
6744
- sendParam[2],
6745
- // amountLD
6746
- sendParam[3],
6747
- // minAmountLD
6748
- "0x",
6749
- "0x",
6750
- "0x"
6751
- ]]
7469
+ [Object.values(composeMsgSendParam)]
6752
7470
  );
6753
7471
  }
6754
- console.log("%cMsgFee: %o", "background:blue;color:white;", msgFee);
6755
7472
  result.sendParam = {
6756
- contract: oftContract,
6757
7473
  param: [
6758
7474
  // sendParam
6759
7475
  sendParam,
6760
7476
  // feeParam
6761
7477
  [
6762
7478
  // nativeFee
6763
- msgFee[0]["nativeFee"].toString(),
7479
+ nativeMsgFee.toString(),
6764
7480
  // lzTokenFee
6765
7481
  msgFee[0]["lzTokenFee"].toString()
6766
7482
  ],
6767
7483
  // refundAddress
6768
7484
  refundTo
6769
7485
  ],
6770
- options: { callValue: msgFee[0]["nativeFee"].toString() }
7486
+ options: { callValue: nativeMsgFee.toString() }
6771
7487
  };
6772
- console.log("%cParams: %o", "background:blue;color:white;", result.sendParam);
6773
- const nativeFeeUsd = (0, import_big6.default)(msgFee[0]["nativeFee"]?.toString() || 0).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
6774
- result.fees.nativeFeeUsd = numberRemoveEndZero((0, import_big6.default)(nativeFeeUsd).toFixed(20));
6775
- result.fees.lzTokenFeeUsd = numberRemoveEndZero((0, import_big6.default)(msgFee[0]["lzTokenFee"]?.toString() || 0).div(10 ** fromToken.decimals).toFixed(20));
6776
- try {
6777
- const energyUsed = msgFee[0]["nativeFee"] || 15e5;
6778
- const usd = numberRemoveEndZero((0, import_big6.default)(energyUsed || 0).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol)).toFixed(20));
6779
- result.fees.estimateGasUsd = usd;
6780
- result.estimateSourceGas = energyUsed;
6781
- result.estimateSourceGasUsd = usd;
6782
- } catch (error) {
6783
- console.log("usdt0 estimate gas failed: %o", error);
6784
- }
6785
- for (const feeKey in result.fees) {
6786
- if (excludeFees4.includes(feeKey)) {
6787
- continue;
6788
- }
6789
- result.totalFeesUsd = (0, import_big6.default)(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
6790
- }
6791
- result.totalFeesUsd = numberRemoveEndZero((0, import_big6.default)(result.totalFeesUsd).toFixed(20));
6792
- const tx = await this.tronWeb.transactionBuilder.triggerSmartContract(
7488
+ const nativeFeeUsd = (0, import_big8.default)(nativeMsgFee?.toString() || 0).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
7489
+ result.fees.nativeFee = numberRemoveEndZero((0, import_big8.default)(nativeMsgFee?.toString() || 0).div(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals));
7490
+ result.fees.nativeFeeUsd = numberRemoveEndZero((0, import_big8.default)(nativeFeeUsd).toFixed(20));
7491
+ result.fees.lzTokenFeeUsd = numberRemoveEndZero((0, import_big8.default)(msgFee[0]["lzTokenFee"]?.toString() || 0).div(10 ** fromToken.decimals).toFixed(20));
7492
+ if (isOriginLegacy || isDestinationLegacy) {
7493
+ result.fees.legacyMeshFeeUsd = numberRemoveEndZero((0, import_big8.default)(amountWei || 0).div(10 ** fromToken.decimals).times(USDT0_LEGACY_MESH_TRANSFTER_FEE).toFixed(fromToken.decimals));
7494
+ result.outputAmount = numberRemoveEndZero((0, import_big8.default)((0, import_big8.default)(amountWei || 0).div(10 ** params.fromToken.decimals)).minus(result.fees.legacyMeshFeeUsd || 0).toFixed(params.fromToken.decimals, 0));
7495
+ }
7496
+ const transactionParams = [
6793
7497
  originLayerzeroAddress,
6794
7498
  "send((uint32,bytes32,uint256,uint256,bytes,bytes,bytes),(uint256,uint256),address)",
6795
7499
  result.sendParam.options,
@@ -6807,9 +7511,41 @@ var TronWallet = class {
6807
7511
  value: result.sendParam.param[2]
6808
7512
  }
6809
7513
  ],
6810
- this.tronWeb.defaultAddress.base58
6811
- );
7514
+ this.tronWeb.defaultAddress.base58 || refundTo
7515
+ ];
7516
+ const energyPrice = await this.getEnergyPrice();
7517
+ const tx = await this.tronWeb.transactionBuilder.triggerSmartContract(...transactionParams);
6812
7518
  result.sendParam.tx = tx;
7519
+ try {
7520
+ const transaction = await this.tronWeb.transactionBuilder.triggerConstantContract(...transactionParams);
7521
+ const energyUsed = transaction.energy_used || 2e5;
7522
+ const rawDataHexLength = transaction.transaction.raw_data_hex.length || 1e3;
7523
+ const bandwidthAmount = (rawDataHexLength / 2 + DATA_HEX_PROTOBUF_EXTRA + SIGNATURE_SIZE) * 1e-3;
7524
+ const amount = (0, import_big8.default)(energyUsed || 0).times(energyPrice).div(10 ** fromToken.nativeToken.decimals);
7525
+ const totalAmount = (0, import_big8.default)(amount).plus(bandwidthAmount);
7526
+ const usd = numberRemoveEndZero((0, import_big8.default)(totalAmount).times(getPrice(prices, fromToken.nativeToken.symbol)).toFixed(20));
7527
+ result.fees.estimateGasUsd = usd;
7528
+ result.estimateSourceGas = numberRemoveEndZero((0, import_big8.default)(totalAmount).times(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals));
7529
+ result.estimateSourceGasUsd = usd;
7530
+ } catch (error) {
7531
+ const energyUsed = 2e5;
7532
+ const rawDataHexLength = 1e3;
7533
+ const bandwidthAmount = (rawDataHexLength / 2 + DATA_HEX_PROTOBUF_EXTRA + SIGNATURE_SIZE) * 1e-3;
7534
+ const amount = (0, import_big8.default)(energyUsed || 0).times(energyPrice).div(10 ** fromToken.nativeToken.decimals);
7535
+ const totalAmount = (0, import_big8.default)(amount).plus(bandwidthAmount);
7536
+ const usd = numberRemoveEndZero((0, import_big8.default)(totalAmount).times(getPrice(prices, fromToken.nativeToken.symbol)).toFixed(20));
7537
+ result.fees.estimateGasUsd = usd;
7538
+ result.estimateSourceGas = numberRemoveEndZero((0, import_big8.default)(totalAmount).times(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals));
7539
+ result.estimateSourceGasUsd = usd;
7540
+ }
7541
+ for (const feeKey in result.fees) {
7542
+ if (excludeFees4.includes(feeKey) || !/Usd$/.test(feeKey)) {
7543
+ continue;
7544
+ }
7545
+ result.totalFeesUsd = (0, import_big8.default)(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
7546
+ }
7547
+ result.totalFeesUsd = numberRemoveEndZero((0, import_big8.default)(result.totalFeesUsd).toFixed(20));
7548
+ result.sendParam.transactionParams = transactionParams;
6813
7549
  return result;
6814
7550
  }
6815
7551
  async sendTransaction(params) {
@@ -6818,7 +7554,6 @@ var TronWallet = class {
6818
7554
  } = params;
6819
7555
  const result = await this.signAndSendTransaction(tx.transaction);
6820
7556
  if (typeof result === "object" && result.message) {
6821
- console.log("%cTron send transaction message: %o", "background:#f00;color:#fff;", result.message);
6822
7557
  if (/user rejected the transaction/i.test(result.message)) {
6823
7558
  throw new Error("User rejected the transaction");
6824
7559
  }
@@ -6883,7 +7618,6 @@ var TronWallet = class {
6883
7618
  } catch (error) {
6884
7619
  console.log("oneclick check allowance failed: %o", error);
6885
7620
  }
6886
- const proxyContract = await this.tronWeb.contract(abi, proxyAddress);
6887
7621
  const proxyParam = [
6888
7622
  // tokenAddress
6889
7623
  fromToken.contractAddress,
@@ -6893,22 +7627,9 @@ var TronWallet = class {
6893
7627
  amountWei
6894
7628
  ];
6895
7629
  result.sendParam = {
6896
- contract: proxyContract,
6897
7630
  param: proxyParam
6898
7631
  };
6899
- try {
6900
- const gasLimit = 30000n;
6901
- const energyPrice = await this.getEnergyPrice();
6902
- const gasPrice = BigInt(energyPrice);
6903
- const estimateGas = gasLimit * gasPrice;
6904
- const estimateGasUsd = (0, import_big6.default)(estimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
6905
- result.fees.sourceGasFeeUsd = numberRemoveEndZero((0, import_big6.default)(estimateGasUsd).toFixed(20));
6906
- result.estimateSourceGas = estimateGas.toString();
6907
- result.estimateSourceGasUsd = numberRemoveEndZero((0, import_big6.default)(estimateGasUsd).toFixed(20));
6908
- } catch (error) {
6909
- console.log("onclick estimate proxy failed: %o", error);
6910
- }
6911
- const tx = await this.tronWeb.transactionBuilder.triggerSmartContract(
7632
+ const transactionParams = [
6912
7633
  proxyAddress,
6913
7634
  "proxyTransfer(address,address,uint256)",
6914
7635
  {},
@@ -6929,20 +7650,99 @@ var TronWallet = class {
6929
7650
  // amount
6930
7651
  }
6931
7652
  ],
6932
- this.tronWeb.defaultAddress.base58
6933
- );
7653
+ this.tronWeb.defaultAddress.base58 || refundTo
7654
+ ];
7655
+ const energyPrice = await this.getEnergyPrice();
7656
+ const tx = await this.tronWeb.transactionBuilder.triggerSmartContract(...transactionParams);
6934
7657
  result.sendParam.tx = tx;
7658
+ try {
7659
+ const transaction = await this.tronWeb.transactionBuilder.triggerConstantContract(...transactionParams);
7660
+ const energyUsed = transaction.energy_used || 3e4;
7661
+ const rawDataHexLength = transaction.transaction.raw_data_hex.length || 500;
7662
+ const bandwidthAmount = (rawDataHexLength / 2 + DATA_HEX_PROTOBUF_EXTRA + SIGNATURE_SIZE) * 1e-3;
7663
+ const amount = (0, import_big8.default)(energyUsed || 0).times(energyPrice).div(10 ** fromToken.nativeToken.decimals);
7664
+ const totalAmount = (0, import_big8.default)(amount).plus(bandwidthAmount);
7665
+ const usd = numberRemoveEndZero((0, import_big8.default)(totalAmount).times(getPrice(prices, fromToken.nativeToken.symbol)).toFixed(20));
7666
+ result.fees.sourceGasFeeUsd = usd;
7667
+ result.estimateSourceGas = numberRemoveEndZero((0, import_big8.default)(totalAmount).times(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals));
7668
+ result.estimateSourceGasUsd = usd;
7669
+ } catch (error) {
7670
+ const energyUsed = 169e3;
7671
+ const rawDataHexLength = 500;
7672
+ const bandwidthAmount = (rawDataHexLength / 2 + DATA_HEX_PROTOBUF_EXTRA + SIGNATURE_SIZE) * 1e-3;
7673
+ const amount = (0, import_big8.default)(energyUsed || 0).times(energyPrice).div(10 ** fromToken.nativeToken.decimals);
7674
+ const totalAmount = (0, import_big8.default)(amount).plus(bandwidthAmount);
7675
+ const usd = numberRemoveEndZero((0, import_big8.default)(totalAmount).times(getPrice(prices, fromToken.nativeToken.symbol)).toFixed(20));
7676
+ result.fees.estimateGasUsd = usd;
7677
+ result.estimateSourceGas = numberRemoveEndZero((0, import_big8.default)(totalAmount).times(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals));
7678
+ result.estimateSourceGasUsd = usd;
7679
+ }
7680
+ result.sendParam.transactionParams = transactionParams;
7681
+ return result;
7682
+ }
7683
+ async getAccountResources(params) {
7684
+ const { account } = params;
7685
+ const result = {
7686
+ energy: 0,
7687
+ bandwidth: 0,
7688
+ success: false,
7689
+ error: "TronWeb is not initialized or the wallet is not connected"
7690
+ };
7691
+ await this.waitForTronWeb();
7692
+ if (!this.tronWeb || !account) {
7693
+ return result;
7694
+ }
7695
+ try {
7696
+ let availableEnergy;
7697
+ let availableBandwidth;
7698
+ try {
7699
+ if (this.tronWeb.trx.getAccountResources) {
7700
+ const resources = await this.tronWeb.trx.getAccountResources(account);
7701
+ console.log("resources: %o", resources);
7702
+ if (resources) {
7703
+ availableEnergy = (resources.EnergyLimit || 0) - (resources.EnergyUsed || 0);
7704
+ availableBandwidth = (resources.freeNetLimit || 0) - (resources.freeNetUsed || 0);
7705
+ }
7706
+ }
7707
+ } catch (resourcesErr) {
7708
+ console.warn("getAccountResources API is not available, try other way:", resourcesErr);
7709
+ }
7710
+ if (availableEnergy === void 0 && availableBandwidth === void 0) {
7711
+ const accountInfo = await this.tronWeb.trx.getAccount(account);
7712
+ if (accountInfo.account_resource) {
7713
+ const accountResource = accountInfo.account_resource;
7714
+ availableEnergy = (accountResource.EnergyLimit || 0) - (accountResource.EnergyUsed || 0);
7715
+ availableBandwidth = (accountResource.NetLimit || 0) - (accountResource.NetUsed || 0);
7716
+ } else if (accountInfo.energy !== void 0) {
7717
+ availableEnergy = accountInfo.energy || 0;
7718
+ }
7719
+ if (accountInfo.bandwidth !== void 0) {
7720
+ if (typeof accountInfo.bandwidth === "number") {
7721
+ availableBandwidth = accountInfo.bandwidth;
7722
+ } else if (accountInfo.bandwidth) {
7723
+ availableBandwidth = accountInfo.bandwidth.available || accountInfo.bandwidth.freeNetUsage || 0;
7724
+ }
7725
+ }
7726
+ }
7727
+ result.energy = Math.max(0, availableEnergy);
7728
+ result.bandwidth = Math.max(0, availableBandwidth);
7729
+ result.success = true;
7730
+ result.error = null;
7731
+ } catch (error) {
7732
+ console.error("Failed to get account resources:", error);
7733
+ }
6935
7734
  return result;
6936
7735
  }
6937
7736
  };
6938
7737
 
6939
7738
  // src/wallets/aptos.ts
6940
7739
  var import_ts_sdk = require("@aptos-labs/ts-sdk");
6941
- var import_big7 = __toESM(require("big.js"));
7740
+ var import_big9 = __toESM(require("big.js"));
6942
7741
  var AptosWallet = class {
6943
7742
  constructor(options) {
6944
7743
  const config = new import_ts_sdk.AptosConfig({
6945
- network: import_ts_sdk.Network.MAINNET
7744
+ network: import_ts_sdk.Network.MAINNET,
7745
+ fullnode: getRpcUrls("aptos")[0]
6946
7746
  });
6947
7747
  const aptos = new import_ts_sdk.Aptos(config);
6948
7748
  this.aptos = aptos;
@@ -7246,10 +8046,10 @@ var AptosWallet = class {
7246
8046
  const defaultGasLimit = 5000n;
7247
8047
  const defaultGasPrice = 100n;
7248
8048
  const defaultEstimateGas = defaultGasLimit * defaultGasPrice;
7249
- const estimateGasUsd2 = (0, import_big7.default)(defaultEstimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
7250
- result.fees.sourceGasFeeUsd = numberRemoveEndZero((0, import_big7.default)(estimateGasUsd2).toFixed(20));
8049
+ const estimateGasUsd2 = (0, import_big9.default)(defaultEstimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
8050
+ result.fees.sourceGasFeeUsd = numberRemoveEndZero((0, import_big9.default)(estimateGasUsd2).toFixed(20));
7251
8051
  result.estimateSourceGas = defaultEstimateGas.toString();
7252
- result.estimateSourceGasUsd = numberRemoveEndZero((0, import_big7.default)(estimateGasUsd2).toFixed(20));
8052
+ result.estimateSourceGasUsd = numberRemoveEndZero((0, import_big9.default)(estimateGasUsd2).toFixed(20));
7253
8053
  result.sendParam = {
7254
8054
  function: functionId,
7255
8055
  typeArguments: [typeArgument],
@@ -7262,10 +8062,10 @@ var AptosWallet = class {
7262
8062
  const defaultGasLimit = 5000n;
7263
8063
  const defaultGasPrice = 100n;
7264
8064
  const defaultEstimateGas = defaultGasLimit * defaultGasPrice;
7265
- const estimateGasUsd2 = (0, import_big7.default)(defaultEstimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
7266
- result.fees.sourceGasFeeUsd = numberRemoveEndZero((0, import_big7.default)(estimateGasUsd2).toFixed(20));
8065
+ const estimateGasUsd2 = (0, import_big9.default)(defaultEstimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
8066
+ result.fees.sourceGasFeeUsd = numberRemoveEndZero((0, import_big9.default)(estimateGasUsd2).toFixed(20));
7267
8067
  result.estimateSourceGas = defaultEstimateGas.toString();
7268
- result.estimateSourceGasUsd = numberRemoveEndZero((0, import_big7.default)(estimateGasUsd2).toFixed(20));
8068
+ result.estimateSourceGasUsd = numberRemoveEndZero((0, import_big9.default)(estimateGasUsd2).toFixed(20));
7269
8069
  result.sendParam = {
7270
8070
  function: functionId,
7271
8071
  typeArguments: [typeArgument],
@@ -7277,10 +8077,10 @@ var AptosWallet = class {
7277
8077
  const gasLimit = gasUsed * 150n / 100n;
7278
8078
  const gasPrice = BigInt(simulation.gas_unit_price || 100);
7279
8079
  const estimateGas = gasLimit * gasPrice;
7280
- const estimateGasUsd = (0, import_big7.default)(estimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
7281
- result.fees.sourceGasFeeUsd = numberRemoveEndZero((0, import_big7.default)(estimateGasUsd).toFixed(20));
8080
+ const estimateGasUsd = (0, import_big9.default)(estimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
8081
+ result.fees.sourceGasFeeUsd = numberRemoveEndZero((0, import_big9.default)(estimateGasUsd).toFixed(20));
7282
8082
  result.estimateSourceGas = estimateGas.toString();
7283
- result.estimateSourceGasUsd = numberRemoveEndZero((0, import_big7.default)(estimateGasUsd).toFixed(20));
8083
+ result.estimateSourceGasUsd = numberRemoveEndZero((0, import_big9.default)(estimateGasUsd).toFixed(20));
7284
8084
  result.sendParam = {
7285
8085
  function: functionId,
7286
8086
  typeArguments: [typeArgument],
@@ -7291,10 +8091,10 @@ var AptosWallet = class {
7291
8091
  const defaultGasLimit = 5000n;
7292
8092
  const defaultGasPrice = 100n;
7293
8093
  const defaultEstimateGas = defaultGasLimit * defaultGasPrice;
7294
- const estimateGasUsd = (0, import_big7.default)(defaultEstimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
7295
- result.fees.sourceGasFeeUsd = numberRemoveEndZero((0, import_big7.default)(estimateGasUsd).toFixed(20));
8094
+ const estimateGasUsd = (0, import_big9.default)(defaultEstimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
8095
+ result.fees.sourceGasFeeUsd = numberRemoveEndZero((0, import_big9.default)(estimateGasUsd).toFixed(20));
7296
8096
  result.estimateSourceGas = defaultEstimateGas.toString();
7297
- result.estimateSourceGasUsd = numberRemoveEndZero((0, import_big7.default)(estimateGasUsd).toFixed(20));
8097
+ result.estimateSourceGasUsd = numberRemoveEndZero((0, import_big9.default)(estimateGasUsd).toFixed(20));
7298
8098
  }
7299
8099
  return result;
7300
8100
  }
@@ -7372,7 +8172,12 @@ var faTransferAbi = {
7372
8172
  CancelablePromise,
7373
8173
  EVMWallet,
7374
8174
  GetExecutionStatusResponse,
8175
+ Hyperliquid,
8176
+ HyperliquidFromTokens,
8177
+ HyperliuquidMinAmount,
8178
+ HyperliuquidToToken,
7375
8179
  NearWallet,
8180
+ NetworkRpcUrlsMap,
7376
8181
  OpenAPI,
7377
8182
  QuoteRequest,
7378
8183
  SFA,
@@ -7382,7 +8187,8 @@ var faTransferAbi = {
7382
8187
  TokenResponse,
7383
8188
  TransactionStatus,
7384
8189
  TronWallet,
7385
- chainsRpcUrls,
8190
+ getRpcUrls,
8191
+ setRpcUrls,
7386
8192
  tokens,
7387
8193
  usdcChains,
7388
8194
  usdcTokens,