stableflow-ai-sdk 2.0.2 → 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/README.md +484 -17
- package/dist/index.d.mts +152 -68
- package/dist/index.d.ts +152 -68
- package/dist/index.js +1097 -352
- package/dist/index.mjs +1082 -339
- package/package.json +5 -1
package/dist/index.mjs
CHANGED
|
@@ -594,14 +594,17 @@ var OneClickService = class {
|
|
|
594
594
|
prices,
|
|
595
595
|
amountWei,
|
|
596
596
|
appFees = [],
|
|
597
|
+
swapType = "EXACT_INPUT",
|
|
598
|
+
isProxy = true,
|
|
597
599
|
...restParams
|
|
598
600
|
} = params;
|
|
601
|
+
const isExactOutput = swapType === "EXACT_OUTPUT";
|
|
599
602
|
const response = await request(OpenAPI, {
|
|
600
603
|
method: "POST",
|
|
601
604
|
url: "/v0/quote",
|
|
602
605
|
body: {
|
|
603
606
|
depositMode: "SIMPLE",
|
|
604
|
-
swapType
|
|
607
|
+
swapType,
|
|
605
608
|
depositType: "ORIGIN_CHAIN",
|
|
606
609
|
sessionId: `session_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
|
|
607
610
|
recipientType: "DESTINATION_CHAIN",
|
|
@@ -626,7 +629,10 @@ var OneClickService = class {
|
|
|
626
629
|
res.data.estimateTime = res.data?.quote?.timeEstimate;
|
|
627
630
|
res.data.outputAmount = numberRemoveEndZero(Big(res.data?.quote?.amountOut || 0).div(10 ** params.toToken.decimals).toFixed(params.toToken.decimals, 0));
|
|
628
631
|
try {
|
|
629
|
-
|
|
632
|
+
let netFee = Big(params.amount).div(10 ** params.fromToken.decimals).minus(Big(res.data?.quote?.amountOut || 0).div(10 ** params.toToken.decimals));
|
|
633
|
+
if (isExactOutput) {
|
|
634
|
+
netFee = Big(res.data?.quote?.amountIn || 0).div(10 ** params.fromToken.decimals).minus(Big(params.amount).div(10 ** params.toToken.decimals));
|
|
635
|
+
}
|
|
630
636
|
const bridgeFeeValue = BridgeFee.reduce((acc, item) => {
|
|
631
637
|
return acc.plus(Big(params.amount).div(10 ** params.fromToken.decimals).times(Big(item.fee).div(1e4)));
|
|
632
638
|
}, Big(0));
|
|
@@ -659,14 +665,14 @@ var OneClickService = class {
|
|
|
659
665
|
console.log("oneclick estimate failed: %o", error);
|
|
660
666
|
}
|
|
661
667
|
const proxyAddress = ONECLICK_PROXY[params.fromToken.chainName];
|
|
662
|
-
if (proxyAddress) {
|
|
668
|
+
if (proxyAddress && isProxy) {
|
|
663
669
|
const proxyResult = await params.wallet.quote(Service.OneClick, {
|
|
664
670
|
proxyAddress,
|
|
665
671
|
abi: ONECLICK_PROXY_ABI,
|
|
666
672
|
fromToken: params.fromToken,
|
|
667
673
|
refundTo: params.refundTo,
|
|
668
674
|
recipient: params.recipient,
|
|
669
|
-
amountWei: params.amount,
|
|
675
|
+
amountWei: isExactOutput ? res.data?.quote?.amountIn : params.amount,
|
|
670
676
|
prices: params.prices,
|
|
671
677
|
depositAddress: res.data?.quote?.depositAddress || DefaultAddresses[params.fromToken.chainType]
|
|
672
678
|
});
|
|
@@ -741,8 +747,10 @@ var USDT0_CONFIG = {
|
|
|
741
747
|
chainKey: "ethereum",
|
|
742
748
|
blockTime: 12,
|
|
743
749
|
// Ethereum average block time ~12 seconds
|
|
744
|
-
confirmations: 15
|
|
750
|
+
confirmations: 15,
|
|
745
751
|
// Default confirmations from layerzeroscan.com
|
|
752
|
+
lzReceiveOptionGas: 8e4,
|
|
753
|
+
lzReceiveOptionGasLegacy: 2e5
|
|
746
754
|
},
|
|
747
755
|
Arbitrum: {
|
|
748
756
|
contractAddress: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
|
|
@@ -753,8 +761,10 @@ var USDT0_CONFIG = {
|
|
|
753
761
|
chainKey: "arbitrum",
|
|
754
762
|
blockTime: 0.25,
|
|
755
763
|
// Arbitrum average block time ~0.25 seconds
|
|
756
|
-
confirmations: 20
|
|
764
|
+
confirmations: 20,
|
|
757
765
|
// Default confirmations from layerzeroscan.com
|
|
766
|
+
lzReceiveOptionGas: 8e4,
|
|
767
|
+
lzReceiveOptionGasLegacy: 2e5
|
|
758
768
|
},
|
|
759
769
|
Polygon: {
|
|
760
770
|
contractAddress: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
|
|
@@ -763,8 +773,11 @@ var USDT0_CONFIG = {
|
|
|
763
773
|
chainKey: "polygon",
|
|
764
774
|
blockTime: 2,
|
|
765
775
|
// Polygon average block time ~2 seconds
|
|
766
|
-
confirmations: 20
|
|
776
|
+
confirmations: 20,
|
|
767
777
|
// Default confirmations from layerzeroscan.com
|
|
778
|
+
lzReceiveOptionGas: 8e4,
|
|
779
|
+
lzReceiveOptionGasLegacy: 2e5,
|
|
780
|
+
composeOptionGas: 6e5
|
|
768
781
|
},
|
|
769
782
|
Optimism: {
|
|
770
783
|
contractAddress: "0x01bFF41798a0BcF287b996046Ca68b395DbC1071",
|
|
@@ -773,8 +786,11 @@ var USDT0_CONFIG = {
|
|
|
773
786
|
chainKey: "optimism",
|
|
774
787
|
blockTime: 2,
|
|
775
788
|
// Optimism average block time ~2 seconds
|
|
776
|
-
confirmations: 20
|
|
789
|
+
confirmations: 20,
|
|
777
790
|
// Default confirmations from layerzeroscan.com
|
|
791
|
+
lzReceiveOptionGas: 8e4,
|
|
792
|
+
lzReceiveOptionGasLegacy: 2e5,
|
|
793
|
+
composeOptionGas: 6e5
|
|
778
794
|
},
|
|
779
795
|
Berachain: {
|
|
780
796
|
contractAddress: "0x779Ded0c9e1022225f8E0630b35a9b54bE713736",
|
|
@@ -784,8 +800,11 @@ var USDT0_CONFIG = {
|
|
|
784
800
|
chainKey: "berachain",
|
|
785
801
|
blockTime: 2,
|
|
786
802
|
// Optimism average block time ~2 seconds
|
|
787
|
-
confirmations: 20
|
|
803
|
+
confirmations: 20,
|
|
788
804
|
// Default confirmations from layerzeroscan.com
|
|
805
|
+
lzReceiveOptionGas: 8e4,
|
|
806
|
+
lzReceiveOptionGasLegacy: 2e5,
|
|
807
|
+
composeOptionGas: 6e5
|
|
789
808
|
},
|
|
790
809
|
Solana: {
|
|
791
810
|
contractAddress: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
|
|
@@ -794,8 +813,11 @@ var USDT0_CONFIG = {
|
|
|
794
813
|
chainKey: "solana",
|
|
795
814
|
blockTime: 0.4,
|
|
796
815
|
// Solana average block time ~0.4 seconds
|
|
797
|
-
confirmations: 32
|
|
816
|
+
confirmations: 32,
|
|
798
817
|
// Default confirmations from layerzeroscan.com
|
|
818
|
+
lzReceiveOptionGas: 2e5,
|
|
819
|
+
lzReceiveOptionGasLegacy: 2e5,
|
|
820
|
+
composeOptionGas: 5e5
|
|
799
821
|
},
|
|
800
822
|
Tron: {
|
|
801
823
|
contractAddress: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
|
|
@@ -804,8 +826,11 @@ var USDT0_CONFIG = {
|
|
|
804
826
|
chainKey: "tron",
|
|
805
827
|
blockTime: 3,
|
|
806
828
|
// Tron average block time ~3 seconds
|
|
807
|
-
confirmations: 5
|
|
829
|
+
confirmations: 5,
|
|
808
830
|
// Default confirmations from layerzeroscan.com
|
|
831
|
+
lzReceiveOptionGas: 3e5,
|
|
832
|
+
lzReceiveOptionGasLegacy: 3e5,
|
|
833
|
+
composeOptionGas: 5e5
|
|
809
834
|
},
|
|
810
835
|
"X Layer": {
|
|
811
836
|
contractAddress: "0x779Ded0c9e1022225f8E0630b35a9b54bE713736",
|
|
@@ -814,12 +839,20 @@ var USDT0_CONFIG = {
|
|
|
814
839
|
chainKey: "xlayer",
|
|
815
840
|
blockTime: 3,
|
|
816
841
|
// Tron average block time ~3 seconds
|
|
817
|
-
confirmations: 20
|
|
842
|
+
confirmations: 20,
|
|
818
843
|
// Default confirmations from layerzeroscan.com
|
|
844
|
+
lzReceiveOptionGas: 8e4,
|
|
845
|
+
lzReceiveOptionGasLegacy: 2e5,
|
|
846
|
+
composeOptionGas: 6e5
|
|
819
847
|
}
|
|
820
848
|
};
|
|
849
|
+
var LZ_RECEIVE_VALUE = {
|
|
850
|
+
Solana: 2039280
|
|
851
|
+
};
|
|
821
852
|
var USDT0_DVN_COUNT = 2;
|
|
822
|
-
var
|
|
853
|
+
var USDT0_LEGACY_MESH_TRANSFTER_FEE = 3e-4;
|
|
854
|
+
var DATA_HEX_PROTOBUF_EXTRA = 3;
|
|
855
|
+
var SIGNATURE_SIZE = 67;
|
|
823
856
|
|
|
824
857
|
// src/bridges/usdt0/contract.ts
|
|
825
858
|
var OFT_ABI = [
|
|
@@ -3528,17 +3561,6 @@ function calculateEstimateTime(originChain, destinationChain) {
|
|
|
3528
3561
|
const sourceTime = sourceBlockTime * blockConfirmations;
|
|
3529
3562
|
const destinationTime = destinationBlockTime * (2 + dvnCount);
|
|
3530
3563
|
const totalTime = Math.ceil(sourceTime + destinationTime);
|
|
3531
|
-
console.log(`USDT0 estimate time calculation:`, {
|
|
3532
|
-
originChain,
|
|
3533
|
-
destinationChain,
|
|
3534
|
-
sourceBlockTime,
|
|
3535
|
-
blockConfirmations,
|
|
3536
|
-
destinationBlockTime,
|
|
3537
|
-
dvnCount,
|
|
3538
|
-
sourceTime,
|
|
3539
|
-
destinationTime,
|
|
3540
|
-
totalTime
|
|
3541
|
-
});
|
|
3542
3564
|
return totalTime;
|
|
3543
3565
|
}
|
|
3544
3566
|
var Usdt0Service = class {
|
|
@@ -3589,7 +3611,9 @@ var Usdt0Service = class {
|
|
|
3589
3611
|
multiHopComposer: USDT0_CONFIG["Arbitrum"],
|
|
3590
3612
|
isMultiHopComposer: isMultiHopComposer2,
|
|
3591
3613
|
isOriginLegacy: isOriginLegacy2,
|
|
3592
|
-
isDestinationLegacy: isDestinationLegacy2
|
|
3614
|
+
isDestinationLegacy: isDestinationLegacy2,
|
|
3615
|
+
originLayerzero,
|
|
3616
|
+
destinationLayerzero
|
|
3593
3617
|
});
|
|
3594
3618
|
result.estimateTime = estimateTime;
|
|
3595
3619
|
return result;
|
|
@@ -3623,7 +3647,9 @@ var Usdt0Service = class {
|
|
|
3623
3647
|
multiHopComposer: USDT0_CONFIG["Arbitrum"],
|
|
3624
3648
|
isMultiHopComposer,
|
|
3625
3649
|
isOriginLegacy,
|
|
3626
|
-
isDestinationLegacy
|
|
3650
|
+
isDestinationLegacy,
|
|
3651
|
+
originLayerzero,
|
|
3652
|
+
destinationLayerzero
|
|
3627
3653
|
});
|
|
3628
3654
|
result.estimateTime = estimateTime;
|
|
3629
3655
|
return result;
|
|
@@ -3646,8 +3672,11 @@ var Usdt0Service = class {
|
|
|
3646
3672
|
multiHopComposer: USDT0_CONFIG["Arbitrum"],
|
|
3647
3673
|
isMultiHopComposer,
|
|
3648
3674
|
isOriginLegacy,
|
|
3649
|
-
isDestinationLegacy
|
|
3675
|
+
isDestinationLegacy,
|
|
3676
|
+
originLayerzero,
|
|
3677
|
+
destinationLayerzero
|
|
3650
3678
|
});
|
|
3679
|
+
result.estimateTime = estimateTime;
|
|
3651
3680
|
return result;
|
|
3652
3681
|
}
|
|
3653
3682
|
}
|
|
@@ -3860,24 +3889,42 @@ var ServiceLogoMap = {
|
|
|
3860
3889
|
};
|
|
3861
3890
|
|
|
3862
3891
|
// src/services/SFA.ts
|
|
3863
|
-
import
|
|
3892
|
+
import Big3 from "big.js";
|
|
3864
3893
|
|
|
3865
3894
|
// src/wallets/config/rpcs.ts
|
|
3866
|
-
var
|
|
3867
|
-
"
|
|
3868
|
-
"
|
|
3869
|
-
"
|
|
3870
|
-
"
|
|
3871
|
-
"
|
|
3872
|
-
"
|
|
3873
|
-
"
|
|
3874
|
-
"
|
|
3875
|
-
"
|
|
3876
|
-
"
|
|
3877
|
-
"
|
|
3878
|
-
"
|
|
3879
|
-
"
|
|
3880
|
-
"
|
|
3895
|
+
var NetworkRpcUrlsMap = {
|
|
3896
|
+
"eth": ["https://eth.merkle.io"],
|
|
3897
|
+
"arb": ["https://arb1.arbitrum.io/rpc"],
|
|
3898
|
+
"bsc": ["https://56.rpc.thirdweb.com"],
|
|
3899
|
+
"avax": ["https://api.avax.network/ext/bc/C/rpc"],
|
|
3900
|
+
"base": ["https://mainnet.base.org"],
|
|
3901
|
+
"pol": ["https://polygon-rpc.com"],
|
|
3902
|
+
"gnosis": ["https://rpc.gnosischain.com"],
|
|
3903
|
+
"op": ["https://mainnet.optimism.io"],
|
|
3904
|
+
"bera": ["https://rpc.berachain.com"],
|
|
3905
|
+
"tron": ["https://api.trongrid.io"],
|
|
3906
|
+
"aptos": ["https://api.mainnet.aptoslabs.com/v1"],
|
|
3907
|
+
"sol": ["https://solana-rpc.publicnode.com"],
|
|
3908
|
+
"near": ["https://nearinner.deltarpc.com"],
|
|
3909
|
+
"xlayer": ["https://rpc.xlayer.tech"],
|
|
3910
|
+
"plasma": ["https://rpc.plasma.to"]
|
|
3911
|
+
};
|
|
3912
|
+
var getRpcUrls = (blockchain) => {
|
|
3913
|
+
return NetworkRpcUrlsMap[blockchain] || [];
|
|
3914
|
+
};
|
|
3915
|
+
var setRpcUrls = (urls) => {
|
|
3916
|
+
for (const blockchain in urls) {
|
|
3917
|
+
const prev = NetworkRpcUrlsMap[blockchain] ?? [];
|
|
3918
|
+
const next = urls[blockchain];
|
|
3919
|
+
for (let i = next.length - 1; i >= 0; i--) {
|
|
3920
|
+
const rpc = next[i];
|
|
3921
|
+
if (prev.some((_rpc) => _rpc.toLowerCase() === rpc.toLowerCase())) {
|
|
3922
|
+
continue;
|
|
3923
|
+
}
|
|
3924
|
+
prev.unshift(rpc);
|
|
3925
|
+
}
|
|
3926
|
+
}
|
|
3927
|
+
return NetworkRpcUrlsMap;
|
|
3881
3928
|
};
|
|
3882
3929
|
|
|
3883
3930
|
// src/wallets/config/chains.ts
|
|
@@ -3921,7 +3968,7 @@ var chains = {
|
|
|
3921
3968
|
symbol: "NEAR",
|
|
3922
3969
|
decimals: 24
|
|
3923
3970
|
},
|
|
3924
|
-
|
|
3971
|
+
rpcUrls: getRpcUrls("near")
|
|
3925
3972
|
},
|
|
3926
3973
|
sol: {
|
|
3927
3974
|
chainName: "Solana",
|
|
@@ -3935,7 +3982,7 @@ var chains = {
|
|
|
3935
3982
|
symbol: "SOL",
|
|
3936
3983
|
decimals: 9
|
|
3937
3984
|
},
|
|
3938
|
-
|
|
3985
|
+
rpcUrls: getRpcUrls("sol")
|
|
3939
3986
|
},
|
|
3940
3987
|
eth: {
|
|
3941
3988
|
chainName: "Ethereum",
|
|
@@ -3950,7 +3997,7 @@ var chains = {
|
|
|
3950
3997
|
symbol: "ETH",
|
|
3951
3998
|
decimals: 18
|
|
3952
3999
|
},
|
|
3953
|
-
|
|
4000
|
+
rpcUrls: getRpcUrls("eth")
|
|
3954
4001
|
},
|
|
3955
4002
|
arb: {
|
|
3956
4003
|
chainName: "Arbitrum",
|
|
@@ -3965,7 +4012,7 @@ var chains = {
|
|
|
3965
4012
|
symbol: "ETH",
|
|
3966
4013
|
decimals: 18
|
|
3967
4014
|
},
|
|
3968
|
-
|
|
4015
|
+
rpcUrls: getRpcUrls("arb")
|
|
3969
4016
|
},
|
|
3970
4017
|
bsc: {
|
|
3971
4018
|
chainName: "BNB Chain",
|
|
@@ -3980,7 +4027,7 @@ var chains = {
|
|
|
3980
4027
|
symbol: "BNB",
|
|
3981
4028
|
decimals: 18
|
|
3982
4029
|
},
|
|
3983
|
-
|
|
4030
|
+
rpcUrls: getRpcUrls("bsc")
|
|
3984
4031
|
},
|
|
3985
4032
|
avax: {
|
|
3986
4033
|
chainName: "Avalanche",
|
|
@@ -3995,7 +4042,7 @@ var chains = {
|
|
|
3995
4042
|
symbol: "AVAX",
|
|
3996
4043
|
decimals: 18
|
|
3997
4044
|
},
|
|
3998
|
-
|
|
4045
|
+
rpcUrls: getRpcUrls("avax")
|
|
3999
4046
|
},
|
|
4000
4047
|
base: {
|
|
4001
4048
|
chainName: "Base",
|
|
@@ -4010,7 +4057,7 @@ var chains = {
|
|
|
4010
4057
|
symbol: "ETH",
|
|
4011
4058
|
decimals: 18
|
|
4012
4059
|
},
|
|
4013
|
-
|
|
4060
|
+
rpcUrls: getRpcUrls("base")
|
|
4014
4061
|
},
|
|
4015
4062
|
pol: {
|
|
4016
4063
|
chainName: "Polygon",
|
|
@@ -4025,7 +4072,7 @@ var chains = {
|
|
|
4025
4072
|
symbol: "POL",
|
|
4026
4073
|
decimals: 18
|
|
4027
4074
|
},
|
|
4028
|
-
|
|
4075
|
+
rpcUrls: getRpcUrls("pol")
|
|
4029
4076
|
},
|
|
4030
4077
|
gnosis: {
|
|
4031
4078
|
chainName: "Gnosis",
|
|
@@ -4040,7 +4087,7 @@ var chains = {
|
|
|
4040
4087
|
symbol: "XDAI",
|
|
4041
4088
|
decimals: 18
|
|
4042
4089
|
},
|
|
4043
|
-
|
|
4090
|
+
rpcUrls: getRpcUrls("gnosis")
|
|
4044
4091
|
},
|
|
4045
4092
|
op: {
|
|
4046
4093
|
chainName: "Optimism",
|
|
@@ -4055,7 +4102,7 @@ var chains = {
|
|
|
4055
4102
|
symbol: "ETH",
|
|
4056
4103
|
decimals: 18
|
|
4057
4104
|
},
|
|
4058
|
-
|
|
4105
|
+
rpcUrls: getRpcUrls("op")
|
|
4059
4106
|
},
|
|
4060
4107
|
tron: {
|
|
4061
4108
|
chainName: "Tron",
|
|
@@ -4069,7 +4116,7 @@ var chains = {
|
|
|
4069
4116
|
symbol: "TRX",
|
|
4070
4117
|
decimals: 6
|
|
4071
4118
|
},
|
|
4072
|
-
|
|
4119
|
+
rpcUrls: getRpcUrls("tron")
|
|
4073
4120
|
},
|
|
4074
4121
|
aptos: {
|
|
4075
4122
|
chainName: "Aptos",
|
|
@@ -4083,7 +4130,7 @@ var chains = {
|
|
|
4083
4130
|
symbol: "APT",
|
|
4084
4131
|
decimals: 8
|
|
4085
4132
|
},
|
|
4086
|
-
|
|
4133
|
+
rpcUrls: getRpcUrls("aptos")
|
|
4087
4134
|
},
|
|
4088
4135
|
bera: {
|
|
4089
4136
|
chainName: "Berachain",
|
|
@@ -4098,7 +4145,7 @@ var chains = {
|
|
|
4098
4145
|
symbol: "BERA",
|
|
4099
4146
|
decimals: 18
|
|
4100
4147
|
},
|
|
4101
|
-
|
|
4148
|
+
rpcUrls: getRpcUrls("bera")
|
|
4102
4149
|
},
|
|
4103
4150
|
xlayer: {
|
|
4104
4151
|
chainName: "X Layer",
|
|
@@ -4113,7 +4160,22 @@ var chains = {
|
|
|
4113
4160
|
symbol: "OKB",
|
|
4114
4161
|
decimals: 18
|
|
4115
4162
|
},
|
|
4116
|
-
|
|
4163
|
+
rpcUrls: getRpcUrls("xlayer")
|
|
4164
|
+
},
|
|
4165
|
+
plasma: {
|
|
4166
|
+
chainName: "Plasma",
|
|
4167
|
+
blockchain: "plasma",
|
|
4168
|
+
chainIcon: "/chains/plasma.png",
|
|
4169
|
+
chainIconGray: "/chains/plasma-gray.png",
|
|
4170
|
+
chainType: chainTypes.evm.value,
|
|
4171
|
+
chainId: 9745,
|
|
4172
|
+
blockExplorerUrl: "https://plasmascan.to/tx/",
|
|
4173
|
+
primaryColor: "#162F29",
|
|
4174
|
+
nativeToken: {
|
|
4175
|
+
symbol: "XPL",
|
|
4176
|
+
decimals: 18
|
|
4177
|
+
},
|
|
4178
|
+
rpcUrls: getRpcUrls("plasma")
|
|
4117
4179
|
}
|
|
4118
4180
|
};
|
|
4119
4181
|
var chains_default = chains;
|
|
@@ -4122,7 +4184,8 @@ var chains_default = chains;
|
|
|
4122
4184
|
var usdt = {
|
|
4123
4185
|
symbol: "USDT",
|
|
4124
4186
|
decimals: 6,
|
|
4125
|
-
icon: "/usdt.png"
|
|
4187
|
+
icon: "/usdt.png",
|
|
4188
|
+
name: "Tether USD"
|
|
4126
4189
|
};
|
|
4127
4190
|
var usdtChains = {
|
|
4128
4191
|
eth: {
|
|
@@ -4180,7 +4243,7 @@ var usdtChains = {
|
|
|
4180
4243
|
assetId: "nep141:sol-c800a4bd850783ccb82c2b2c7e84175443606352.omft.near",
|
|
4181
4244
|
contractAddress: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
|
|
4182
4245
|
...chains_default.sol,
|
|
4183
|
-
services: [Service.OneClick]
|
|
4246
|
+
services: [Service.OneClick, Service.Usdt0]
|
|
4184
4247
|
},
|
|
4185
4248
|
tron: {
|
|
4186
4249
|
...usdt,
|
|
@@ -4209,6 +4272,13 @@ var usdtChains = {
|
|
|
4209
4272
|
contractAddress: "0x779ded0c9e1022225f8e0630b35a9b54be713736",
|
|
4210
4273
|
...chains_default.xlayer,
|
|
4211
4274
|
services: [Service.OneClick, Service.Usdt0]
|
|
4275
|
+
},
|
|
4276
|
+
plasma: {
|
|
4277
|
+
...usdt,
|
|
4278
|
+
assetId: "nep245:v2_1.omni.hot.tg:9745_3aL9skCy1yhPoDB8oKMmRHRN7SJW",
|
|
4279
|
+
contractAddress: "0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb",
|
|
4280
|
+
...chains_default.plasma,
|
|
4281
|
+
services: [Service.OneClick]
|
|
4212
4282
|
}
|
|
4213
4283
|
};
|
|
4214
4284
|
|
|
@@ -4216,7 +4286,8 @@ var usdtChains = {
|
|
|
4216
4286
|
var usdc = {
|
|
4217
4287
|
symbol: "USDC",
|
|
4218
4288
|
decimals: 6,
|
|
4219
|
-
icon: "/usdc.png"
|
|
4289
|
+
icon: "/usdc.png",
|
|
4290
|
+
name: "USD Coin"
|
|
4220
4291
|
};
|
|
4221
4292
|
var usdcChains = {
|
|
4222
4293
|
eth: {
|
|
@@ -4308,6 +4379,45 @@ var TransactionStatus = /* @__PURE__ */ ((TransactionStatus2) => {
|
|
|
4308
4379
|
return TransactionStatus2;
|
|
4309
4380
|
})(TransactionStatus || {});
|
|
4310
4381
|
|
|
4382
|
+
// src/utils/error.ts
|
|
4383
|
+
import Big2 from "big.js";
|
|
4384
|
+
var formatQuoteError = (error, options) => {
|
|
4385
|
+
const { service, fromToken } = options;
|
|
4386
|
+
const defaultErrorMessage = "Failed to get quote, please try again later";
|
|
4387
|
+
if (service === Service.OneClick) {
|
|
4388
|
+
const getQuoteErrorMessage = () => {
|
|
4389
|
+
const _messageResult = {
|
|
4390
|
+
message: defaultErrorMessage,
|
|
4391
|
+
sourceMessage: error?.response?.data?.message || defaultErrorMessage
|
|
4392
|
+
};
|
|
4393
|
+
if (error?.response?.data?.message && error?.response?.data?.message !== "Internal server error") {
|
|
4394
|
+
if (error?.response?.data?.message === "Failed to get quote") {
|
|
4395
|
+
_messageResult.message = "Amount exceeds max";
|
|
4396
|
+
return _messageResult;
|
|
4397
|
+
}
|
|
4398
|
+
if (error?.response?.data?.message?.includes("Amount is too low for bridge, try at least")) {
|
|
4399
|
+
const match = error.response.data.message.match(/try at least\s+(\d+(?:\.\d+)?)/i);
|
|
4400
|
+
let minimumAmount = match ? match[1] : Big2(1).times(10 ** fromToken.decimals).toFixed(0);
|
|
4401
|
+
minimumAmount = Big2(minimumAmount).div(10 ** fromToken.decimals).toFixed(fromToken.decimals);
|
|
4402
|
+
_messageResult.message = `Amount is too low, at least ${minimumAmount}`;
|
|
4403
|
+
return _messageResult;
|
|
4404
|
+
}
|
|
4405
|
+
return _messageResult;
|
|
4406
|
+
}
|
|
4407
|
+
return _messageResult;
|
|
4408
|
+
};
|
|
4409
|
+
const onclickErrMsg = getQuoteErrorMessage();
|
|
4410
|
+
return {
|
|
4411
|
+
serviceType: service,
|
|
4412
|
+
error: onclickErrMsg.message
|
|
4413
|
+
};
|
|
4414
|
+
}
|
|
4415
|
+
return {
|
|
4416
|
+
serviceType: service,
|
|
4417
|
+
error: error?.message || defaultErrorMessage
|
|
4418
|
+
};
|
|
4419
|
+
};
|
|
4420
|
+
|
|
4311
4421
|
// src/services/SFA.ts
|
|
4312
4422
|
var submitOneclickDepositTx = (requestBody) => {
|
|
4313
4423
|
return request(OpenAPI, {
|
|
@@ -4412,10 +4522,10 @@ var SFA = class {
|
|
|
4412
4522
|
static async getAllQuote(params) {
|
|
4413
4523
|
const results = [];
|
|
4414
4524
|
let { minInputAmount = "1" } = params;
|
|
4415
|
-
if (
|
|
4525
|
+
if (Big3(minInputAmount).lte(0)) {
|
|
4416
4526
|
minInputAmount = "1";
|
|
4417
4527
|
}
|
|
4418
|
-
if (!params.fromToken || !params.fromToken.contractAddress || !params.toToken || !params.toToken.contractAddress || !params.refundTo || !params.recipient || !params.amountWei ||
|
|
4528
|
+
if (!params.fromToken || !params.fromToken.contractAddress || !params.toToken || !params.toToken.contractAddress || !params.refundTo || !params.recipient || !params.amountWei || Big3(params.amountWei).lte(minInputAmount)) {
|
|
4419
4529
|
throw new Error("Invalid parameters");
|
|
4420
4530
|
}
|
|
4421
4531
|
const formatQuoteParams = (service) => {
|
|
@@ -4436,7 +4546,9 @@ var SFA = class {
|
|
|
4436
4546
|
_params.destinationAsset = params.toToken.assetId;
|
|
4437
4547
|
_params.amount = params.amountWei;
|
|
4438
4548
|
_params.refundType = "ORIGIN_CHAIN";
|
|
4439
|
-
_params.appFees = params.appFees;
|
|
4549
|
+
_params.appFees = params.oneclickParams?.appFees;
|
|
4550
|
+
_params.swapType = params.oneclickParams?.swapType;
|
|
4551
|
+
_params.isProxy = params.oneclickParams?.isProxy;
|
|
4440
4552
|
}
|
|
4441
4553
|
if (service === Service.Usdt0) {
|
|
4442
4554
|
_params.originChain = params.fromToken.chainName;
|
|
@@ -4465,42 +4577,6 @@ var SFA = class {
|
|
|
4465
4577
|
});
|
|
4466
4578
|
}
|
|
4467
4579
|
}
|
|
4468
|
-
const formatQuoteError = (service, error) => {
|
|
4469
|
-
const defaultErrorMessage = "Failed to get quote, please try again later";
|
|
4470
|
-
if (service === Service.OneClick) {
|
|
4471
|
-
const getQuoteErrorMessage = () => {
|
|
4472
|
-
const _messageResult = {
|
|
4473
|
-
message: defaultErrorMessage,
|
|
4474
|
-
sourceMessage: error?.response?.data?.message || defaultErrorMessage
|
|
4475
|
-
};
|
|
4476
|
-
if (error?.response?.data?.message && error?.response?.data?.message !== "Internal server error") {
|
|
4477
|
-
if (error?.response?.data?.message === "Failed to get quote") {
|
|
4478
|
-
_messageResult.message = "Amount exceeds max";
|
|
4479
|
-
return _messageResult;
|
|
4480
|
-
}
|
|
4481
|
-
if (error?.response?.data?.message?.includes("Amount is too low for bridge, try at least")) {
|
|
4482
|
-
const match = error.response.data.message.match(/try at least\s+(\d+(?:\.\d+)?)/i);
|
|
4483
|
-
let minimumAmount = match ? match[1] : Big2(1).times(10 ** fromToken.decimals).toFixed(0);
|
|
4484
|
-
minimumAmount = Big2(minimumAmount).div(10 ** fromToken.decimals).toFixed(fromToken.decimals);
|
|
4485
|
-
_messageResult.message = `Amount is too low, at least ${minimumAmount}`;
|
|
4486
|
-
return _messageResult;
|
|
4487
|
-
}
|
|
4488
|
-
return _messageResult;
|
|
4489
|
-
}
|
|
4490
|
-
return _messageResult;
|
|
4491
|
-
};
|
|
4492
|
-
const onclickErrMsg = getQuoteErrorMessage();
|
|
4493
|
-
results.push({
|
|
4494
|
-
serviceType: service,
|
|
4495
|
-
error: onclickErrMsg.message
|
|
4496
|
-
});
|
|
4497
|
-
} else {
|
|
4498
|
-
results.push({
|
|
4499
|
-
serviceType: service,
|
|
4500
|
-
error: error?.message || defaultErrorMessage
|
|
4501
|
-
});
|
|
4502
|
-
}
|
|
4503
|
-
};
|
|
4504
4580
|
if (params.singleService) {
|
|
4505
4581
|
const quoteService = quoteServices.find((service) => service.service === params.singleService);
|
|
4506
4582
|
if (quoteService) {
|
|
@@ -4511,7 +4587,8 @@ var SFA = class {
|
|
|
4511
4587
|
quote: quoteRes
|
|
4512
4588
|
});
|
|
4513
4589
|
} catch (error) {
|
|
4514
|
-
formatQuoteError(quoteService.service,
|
|
4590
|
+
const _err = formatQuoteError(error, { service: quoteService.service, fromToken });
|
|
4591
|
+
results.push(_err);
|
|
4515
4592
|
}
|
|
4516
4593
|
}
|
|
4517
4594
|
return results;
|
|
@@ -4527,7 +4604,8 @@ var SFA = class {
|
|
|
4527
4604
|
});
|
|
4528
4605
|
} catch (error) {
|
|
4529
4606
|
console.log("%s quote failed: %o", quoteService.service, error);
|
|
4530
|
-
formatQuoteError(quoteService.service,
|
|
4607
|
+
const _err = formatQuoteError(error, { service: quoteService.service, fromToken });
|
|
4608
|
+
results.push(_err);
|
|
4531
4609
|
}
|
|
4532
4610
|
})();
|
|
4533
4611
|
promises.push(promise);
|
|
@@ -4582,7 +4660,7 @@ var SFA = class {
|
|
|
4582
4660
|
project: projectMap[serviceType],
|
|
4583
4661
|
address: params.quote?.quoteParam?.refundTo,
|
|
4584
4662
|
receive_address: params.quote?.quoteParam?.recipient,
|
|
4585
|
-
amount:
|
|
4663
|
+
amount: Big3(params.quote?.quoteParam?.amountWei || 0).div(10 ** (params.quote?.fromToken?.decimals || 6)).toFixed(params.quote?.fromToken?.decimals || 6, 0)
|
|
4586
4664
|
};
|
|
4587
4665
|
if (serviceType === Service.OneClick) {
|
|
4588
4666
|
reportParams.deposit_address = params.quote?.quote?.depositAddress;
|
|
@@ -4669,13 +4747,184 @@ var SFA = class {
|
|
|
4669
4747
|
*/
|
|
4670
4748
|
SFA.submitDepositTx = submitOneclickDepositTx;
|
|
4671
4749
|
|
|
4750
|
+
// src/services/Hyperliquid.ts
|
|
4751
|
+
import { ethers } from "ethers";
|
|
4752
|
+
import Big4 from "big.js";
|
|
4753
|
+
var SPENDER = "0x2df1c51e09aecf9cacb7bc98cb1742757f163df7";
|
|
4754
|
+
var DESTINATION_TOKEN = usdcChains["arb"];
|
|
4755
|
+
var MIN_AMOUNT = Big4(5).times(10 ** DESTINATION_TOKEN.decimals).toFixed(0);
|
|
4756
|
+
var HyperliquidService = class {
|
|
4757
|
+
async quote(params) {
|
|
4758
|
+
const result = { quote: null, error: null };
|
|
4759
|
+
if (Big4(params.amountWei || 0).lt(MIN_AMOUNT)) {
|
|
4760
|
+
result.error = `Amount is too low, at least ${MIN_AMOUNT}`;
|
|
4761
|
+
return result;
|
|
4762
|
+
}
|
|
4763
|
+
const quoteParams = {
|
|
4764
|
+
...params,
|
|
4765
|
+
dry: params.dry ?? true,
|
|
4766
|
+
slippageTolerance: params.slippageTolerance * 100,
|
|
4767
|
+
originAsset: params.fromToken.assetId,
|
|
4768
|
+
toToken: DESTINATION_TOKEN,
|
|
4769
|
+
destinationAsset: DESTINATION_TOKEN.assetId,
|
|
4770
|
+
amount: params.amountWei,
|
|
4771
|
+
refundType: "ORIGIN_CHAIN",
|
|
4772
|
+
appFees: params.oneclickParams?.appFees,
|
|
4773
|
+
swapType: "EXACT_OUTPUT",
|
|
4774
|
+
isProxy: false
|
|
4775
|
+
};
|
|
4776
|
+
try {
|
|
4777
|
+
const quoteRes = await ServiceMap[Service.OneClick].quote(quoteParams);
|
|
4778
|
+
result.quote = quoteRes;
|
|
4779
|
+
} catch (error) {
|
|
4780
|
+
const _err = formatQuoteError(error, { service: Service.OneClick, fromToken: params.fromToken });
|
|
4781
|
+
result.error = _err.error;
|
|
4782
|
+
}
|
|
4783
|
+
return result;
|
|
4784
|
+
}
|
|
4785
|
+
async transfer(params) {
|
|
4786
|
+
const {
|
|
4787
|
+
quote,
|
|
4788
|
+
wallet
|
|
4789
|
+
} = params;
|
|
4790
|
+
const sendParams = {
|
|
4791
|
+
wallet,
|
|
4792
|
+
sendParam: quote?.sendParam,
|
|
4793
|
+
fromToken: quote?.quoteParam.fromToken,
|
|
4794
|
+
depositAddress: quote?.quote?.depositAddress,
|
|
4795
|
+
amountWei: quote?.quote?.amountIn
|
|
4796
|
+
};
|
|
4797
|
+
const txhash = await ServiceMap[Service.OneClick].send(sendParams);
|
|
4798
|
+
return txhash;
|
|
4799
|
+
}
|
|
4800
|
+
async deposit(params) {
|
|
4801
|
+
const {
|
|
4802
|
+
evmWallet,
|
|
4803
|
+
evmWalletAddress,
|
|
4804
|
+
quote,
|
|
4805
|
+
txhash
|
|
4806
|
+
} = params;
|
|
4807
|
+
const permitParams = await this.generatePermit({
|
|
4808
|
+
address: evmWalletAddress,
|
|
4809
|
+
evmWallet,
|
|
4810
|
+
amountWei: quote?.quote?.amountOut
|
|
4811
|
+
});
|
|
4812
|
+
const depositParams = {
|
|
4813
|
+
deposit_address: quote?.quote?.depositAddress,
|
|
4814
|
+
from_addr: quote?.quoteParam?.refundTo,
|
|
4815
|
+
from_amount: quote?.quote?.amountIn,
|
|
4816
|
+
from_chain: quote?.quoteParam?.fromToken?.blockchain,
|
|
4817
|
+
from_hash: txhash,
|
|
4818
|
+
from_token: quote?.quoteParam?.fromToken?.contractAddress,
|
|
4819
|
+
sender: quote?.quoteParam?.recipient,
|
|
4820
|
+
to_amount: quote?.quote?.amountOut,
|
|
4821
|
+
to_chain: quote?.quoteParam?.toToken?.blockchain,
|
|
4822
|
+
to_token: quote?.quoteParam?.toToken?.contractAddress,
|
|
4823
|
+
type: Service.OneClick,
|
|
4824
|
+
permit: permitParams
|
|
4825
|
+
};
|
|
4826
|
+
const depositRes = await request(OpenAPI, {
|
|
4827
|
+
method: "POST",
|
|
4828
|
+
url: "/v0/deposit",
|
|
4829
|
+
body: depositParams,
|
|
4830
|
+
mediaType: "application/json",
|
|
4831
|
+
errors: {
|
|
4832
|
+
400: `Bad Request - Invalid input data`,
|
|
4833
|
+
401: `Unauthorized - JWT token is invalid`
|
|
4834
|
+
}
|
|
4835
|
+
});
|
|
4836
|
+
return depositRes;
|
|
4837
|
+
}
|
|
4838
|
+
async getStatus(params) {
|
|
4839
|
+
return request(OpenAPI, {
|
|
4840
|
+
method: "GET",
|
|
4841
|
+
url: "/v0/deposit",
|
|
4842
|
+
query: {
|
|
4843
|
+
depositId: params.depositId
|
|
4844
|
+
},
|
|
4845
|
+
mediaType: "application/json",
|
|
4846
|
+
errors: {
|
|
4847
|
+
400: `Bad Request - Invalid input data`,
|
|
4848
|
+
401: `Unauthorized - JWT token is invalid`
|
|
4849
|
+
}
|
|
4850
|
+
});
|
|
4851
|
+
}
|
|
4852
|
+
async generatePermit(params) {
|
|
4853
|
+
const {
|
|
4854
|
+
address,
|
|
4855
|
+
evmWallet,
|
|
4856
|
+
amountWei
|
|
4857
|
+
} = params;
|
|
4858
|
+
const tokenAddress = DESTINATION_TOKEN.contractAddress;
|
|
4859
|
+
const name = DESTINATION_TOKEN.name;
|
|
4860
|
+
const chainId = DESTINATION_TOKEN.chainId;
|
|
4861
|
+
const provider = new ethers.JsonRpcProvider(getRpcUrls("arb")[0]);
|
|
4862
|
+
const erc20 = new ethers.Contract(
|
|
4863
|
+
tokenAddress,
|
|
4864
|
+
[
|
|
4865
|
+
"function name() view returns (string)",
|
|
4866
|
+
"function nonces(address) view returns (uint256)",
|
|
4867
|
+
"function decimals() view returns (uint8)"
|
|
4868
|
+
],
|
|
4869
|
+
provider
|
|
4870
|
+
);
|
|
4871
|
+
const deadline = Math.floor(Date.now() / 1e3) + 86400;
|
|
4872
|
+
const nonce = await erc20.nonces(address);
|
|
4873
|
+
const value = amountWei;
|
|
4874
|
+
const domain = {
|
|
4875
|
+
name,
|
|
4876
|
+
version: "2",
|
|
4877
|
+
chainId: Number(chainId),
|
|
4878
|
+
verifyingContract: tokenAddress
|
|
4879
|
+
};
|
|
4880
|
+
const types = {
|
|
4881
|
+
Permit: [
|
|
4882
|
+
{ name: "owner", type: "address" },
|
|
4883
|
+
{ name: "spender", type: "address" },
|
|
4884
|
+
{ name: "value", type: "uint256" },
|
|
4885
|
+
{ name: "nonce", type: "uint256" },
|
|
4886
|
+
{ name: "deadline", type: "uint256" }
|
|
4887
|
+
]
|
|
4888
|
+
};
|
|
4889
|
+
const values = {
|
|
4890
|
+
owner: address,
|
|
4891
|
+
spender: SPENDER,
|
|
4892
|
+
value,
|
|
4893
|
+
nonce: nonce.toString(),
|
|
4894
|
+
deadline
|
|
4895
|
+
};
|
|
4896
|
+
const signature = await evmWallet.signTypedData({
|
|
4897
|
+
domain,
|
|
4898
|
+
types,
|
|
4899
|
+
values
|
|
4900
|
+
});
|
|
4901
|
+
const { v, r, s } = ethers.Signature.from(signature);
|
|
4902
|
+
const permitParams = {
|
|
4903
|
+
amount: value,
|
|
4904
|
+
deadline,
|
|
4905
|
+
owner: address,
|
|
4906
|
+
r,
|
|
4907
|
+
s,
|
|
4908
|
+
spender: SPENDER,
|
|
4909
|
+
token: tokenAddress,
|
|
4910
|
+
v,
|
|
4911
|
+
nonce: Number(nonce)
|
|
4912
|
+
};
|
|
4913
|
+
return permitParams;
|
|
4914
|
+
}
|
|
4915
|
+
};
|
|
4916
|
+
var Hyperliquid = new HyperliquidService();
|
|
4917
|
+
var HyperliquidFromTokens = tokens.filter((token) => !(token.chainName === "Arbitrum" && token.symbol === "USDC"));
|
|
4918
|
+
var HyperliuquidToToken = DESTINATION_TOKEN;
|
|
4919
|
+
var HyperliuquidMinAmount = MIN_AMOUNT;
|
|
4920
|
+
|
|
4672
4921
|
// src/wallets/near.ts
|
|
4673
4922
|
import { Buffer as Buffer2 } from "buffer";
|
|
4674
|
-
import
|
|
4923
|
+
import Big5 from "big.js";
|
|
4675
4924
|
var NearWallet = class {
|
|
4676
4925
|
constructor(_selector) {
|
|
4677
4926
|
this.selector = _selector;
|
|
4678
|
-
this.rpcUrl =
|
|
4927
|
+
this.rpcUrl = getRpcUrls("near")[0];
|
|
4679
4928
|
}
|
|
4680
4929
|
async query(contractId, methodName, args = {}) {
|
|
4681
4930
|
const response = await fetch(this.rpcUrl, {
|
|
@@ -4962,10 +5211,10 @@ var NearWallet = class {
|
|
|
4962
5211
|
totalGasLimit = totalGasLimit * 120n / 100n;
|
|
4963
5212
|
const gasPrice = BigInt("100000000");
|
|
4964
5213
|
const estimateGas = totalGasLimit * gasPrice;
|
|
4965
|
-
const estimateGasUsd =
|
|
4966
|
-
result.fees.sourceGasFeeUsd = numberRemoveEndZero(
|
|
5214
|
+
const estimateGasUsd = Big5(estimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
|
|
5215
|
+
result.fees.sourceGasFeeUsd = numberRemoveEndZero(Big5(estimateGasUsd).toFixed(20));
|
|
4967
5216
|
result.estimateSourceGas = estimateGas.toString();
|
|
4968
|
-
result.estimateSourceGasUsd = numberRemoveEndZero(
|
|
5217
|
+
result.estimateSourceGasUsd = numberRemoveEndZero(Big5(estimateGasUsd).toFixed(20));
|
|
4969
5218
|
result.sendParam = {
|
|
4970
5219
|
transactions,
|
|
4971
5220
|
callbackUrl: "/"
|
|
@@ -4975,10 +5224,10 @@ var NearWallet = class {
|
|
|
4975
5224
|
const defaultGasLimit = BigInt("80000000000000");
|
|
4976
5225
|
const gasPrice = BigInt("100000000");
|
|
4977
5226
|
const estimateGas = defaultGasLimit * gasPrice;
|
|
4978
|
-
const estimateGasUsd =
|
|
4979
|
-
result.fees.sourceGasFeeUsd = numberRemoveEndZero(
|
|
5227
|
+
const estimateGasUsd = Big5(estimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
|
|
5228
|
+
result.fees.sourceGasFeeUsd = numberRemoveEndZero(Big5(estimateGasUsd).toFixed(20));
|
|
4980
5229
|
result.estimateSourceGas = estimateGas.toString();
|
|
4981
|
-
result.estimateSourceGasUsd = numberRemoveEndZero(
|
|
5230
|
+
result.estimateSourceGasUsd = numberRemoveEndZero(Big5(estimateGasUsd).toFixed(20));
|
|
4982
5231
|
}
|
|
4983
5232
|
return result;
|
|
4984
5233
|
}
|
|
@@ -5029,12 +5278,14 @@ var NearWallet = class {
|
|
|
5029
5278
|
|
|
5030
5279
|
// src/wallets/solana.ts
|
|
5031
5280
|
import {
|
|
5032
|
-
Connection,
|
|
5033
|
-
PublicKey,
|
|
5281
|
+
Connection as Connection2,
|
|
5282
|
+
PublicKey as PublicKey2,
|
|
5034
5283
|
Transaction,
|
|
5035
5284
|
VersionedTransaction,
|
|
5036
5285
|
SystemProgram,
|
|
5037
|
-
LAMPORTS_PER_SOL
|
|
5286
|
+
LAMPORTS_PER_SOL,
|
|
5287
|
+
TransactionInstruction,
|
|
5288
|
+
ComputeBudgetProgram
|
|
5038
5289
|
} from "@solana/web3.js";
|
|
5039
5290
|
import {
|
|
5040
5291
|
getAssociatedTokenAddress,
|
|
@@ -5045,7 +5296,7 @@ import {
|
|
|
5045
5296
|
getAssociatedTokenAddressSync
|
|
5046
5297
|
} from "@solana/spl-token";
|
|
5047
5298
|
import { AnchorProvider, BN, Program } from "@coral-xyz/anchor";
|
|
5048
|
-
import
|
|
5299
|
+
import Big6 from "big.js";
|
|
5049
5300
|
|
|
5050
5301
|
// src/bridges/oneclick/stableflow-proxy.json
|
|
5051
5302
|
var stableflow_proxy_default = {
|
|
@@ -5345,9 +5596,109 @@ var stableflow_proxy_default = {
|
|
|
5345
5596
|
};
|
|
5346
5597
|
|
|
5347
5598
|
// src/wallets/solana.ts
|
|
5599
|
+
import { ethers as ethers3 } from "ethers";
|
|
5600
|
+
import { addressToBytes32, Options } from "@layerzerolabs/lz-v2-utilities";
|
|
5601
|
+
|
|
5602
|
+
// src/bridges/usdt0/hop-composer.ts
|
|
5603
|
+
import { ethers as ethers2 } from "ethers";
|
|
5604
|
+
var getHopMsgFee = async (params) => {
|
|
5605
|
+
const {
|
|
5606
|
+
sendParam,
|
|
5607
|
+
toToken
|
|
5608
|
+
} = params;
|
|
5609
|
+
const originLayerzero = USDT0_CONFIG["Arbitrum"];
|
|
5610
|
+
const destinationLayerzero = USDT0_CONFIG[toToken.chainName];
|
|
5611
|
+
let arbitrumOft = originLayerzero.oft;
|
|
5612
|
+
let destinationLayerzeroAddress = destinationLayerzero.oft || destinationLayerzero.oftLegacy;
|
|
5613
|
+
const isDestinationLegacy = destinationLayerzeroAddress === destinationLayerzero.oftLegacy;
|
|
5614
|
+
if (isDestinationLegacy) {
|
|
5615
|
+
arbitrumOft = originLayerzero.oftLegacy || originLayerzero.oft;
|
|
5616
|
+
}
|
|
5617
|
+
const provider = new ethers2.JsonRpcProvider(getRpcUrls("arb")[0]);
|
|
5618
|
+
const oftContractRead = new ethers2.Contract(arbitrumOft, OFT_ABI, provider);
|
|
5619
|
+
try {
|
|
5620
|
+
const msgFee = await oftContractRead.quoteSend.staticCall(sendParam, false);
|
|
5621
|
+
const [nativeFee] = msgFee;
|
|
5622
|
+
return nativeFee * 120n / 100n;
|
|
5623
|
+
} catch (error) {
|
|
5624
|
+
console.log("getHopMsgFee failed: %o", error);
|
|
5625
|
+
throw new Error("Quote multi hop message fee failed");
|
|
5626
|
+
}
|
|
5627
|
+
};
|
|
5628
|
+
|
|
5629
|
+
// src/wallets/utils/layerzero.ts
|
|
5630
|
+
import {
|
|
5631
|
+
PublicKey
|
|
5632
|
+
} from "@solana/web3.js";
|
|
5633
|
+
import { struct, u32, u64, bytes, option, bool } from "@metaplex-foundation/umi/serializers";
|
|
5634
|
+
var SEEDS = {
|
|
5635
|
+
OFT: Buffer.from("OFT"),
|
|
5636
|
+
PEER: Buffer.from("Peer"),
|
|
5637
|
+
CREDITS: Buffer.from("Credits"),
|
|
5638
|
+
EVENT_AUTHORITY: Buffer.from("__event_authority")
|
|
5639
|
+
};
|
|
5640
|
+
var DISCRIMINATOR = {
|
|
5641
|
+
quoteSend: new Uint8Array([207, 0, 49, 214, 160, 211, 76, 211]),
|
|
5642
|
+
send: new Uint8Array([102, 251, 20, 187, 65, 75, 12, 69])
|
|
5643
|
+
};
|
|
5644
|
+
function u32be(n) {
|
|
5645
|
+
const buf = Buffer.alloc(4);
|
|
5646
|
+
buf.writeUInt32BE(n, 0);
|
|
5647
|
+
return buf;
|
|
5648
|
+
}
|
|
5649
|
+
function deriveOftPdas(programId, dstEid) {
|
|
5650
|
+
return {
|
|
5651
|
+
oftStore: PublicKey.findProgramAddressSync([SEEDS.OFT], programId)[0],
|
|
5652
|
+
peer: PublicKey.findProgramAddressSync([SEEDS.PEER, u32be(dstEid)], programId)[0],
|
|
5653
|
+
credits: PublicKey.findProgramAddressSync([SEEDS.CREDITS], programId)[0],
|
|
5654
|
+
eventAuthority: PublicKey.findProgramAddressSync([SEEDS.EVENT_AUTHORITY], programId)[0]
|
|
5655
|
+
};
|
|
5656
|
+
}
|
|
5657
|
+
async function getPeerAddress(connection, programId, dstEid) {
|
|
5658
|
+
const { peer } = deriveOftPdas(programId, dstEid);
|
|
5659
|
+
const info = await connection.getAccountInfo(peer);
|
|
5660
|
+
if (!info) throw new Error(`Peer not found for EID ${dstEid}`);
|
|
5661
|
+
return `0x${info.data.subarray(8, 40).toString("hex")}`;
|
|
5662
|
+
}
|
|
5663
|
+
var quoteSendParamsSerializer = struct([
|
|
5664
|
+
["dstEid", u32()],
|
|
5665
|
+
["to", bytes({ size: 32 })],
|
|
5666
|
+
["amountLd", u64()],
|
|
5667
|
+
["minAmountLd", u64()],
|
|
5668
|
+
["extraOptions", bytes({ size: u32() })],
|
|
5669
|
+
["composeMsg", option(bytes({ size: u32() }))],
|
|
5670
|
+
["payInLzToken", bool()]
|
|
5671
|
+
]);
|
|
5672
|
+
function encodeQuoteSend(params) {
|
|
5673
|
+
const paramsData = quoteSendParamsSerializer.serialize(params);
|
|
5674
|
+
const data = new Uint8Array(8 + paramsData.length);
|
|
5675
|
+
data.set(DISCRIMINATOR.quoteSend, 0);
|
|
5676
|
+
data.set(paramsData, 8);
|
|
5677
|
+
return data;
|
|
5678
|
+
}
|
|
5679
|
+
var sendParamsSerializer = struct([
|
|
5680
|
+
["dstEid", u32()],
|
|
5681
|
+
["to", bytes({ size: 32 })],
|
|
5682
|
+
["amountLd", u64()],
|
|
5683
|
+
["minAmountLd", u64()],
|
|
5684
|
+
["extraOptions", bytes({ size: u32() })],
|
|
5685
|
+
["composeMsg", option(bytes({ size: u32() }))],
|
|
5686
|
+
["nativeFee", u64()],
|
|
5687
|
+
["lzTokenFee", u64()]
|
|
5688
|
+
]);
|
|
5689
|
+
function encodeSend(params) {
|
|
5690
|
+
const paramsData = sendParamsSerializer.serialize(params);
|
|
5691
|
+
const data = new Uint8Array(8 + paramsData.length);
|
|
5692
|
+
data.set(DISCRIMINATOR.send, 0);
|
|
5693
|
+
data.set(paramsData, 8);
|
|
5694
|
+
return data;
|
|
5695
|
+
}
|
|
5696
|
+
|
|
5697
|
+
// src/wallets/solana.ts
|
|
5698
|
+
import { buildVersionedTransaction, SendHelper } from "@layerzerolabs/lz-solana-sdk-v2";
|
|
5348
5699
|
var SolanaWallet = class {
|
|
5349
5700
|
constructor(options) {
|
|
5350
|
-
this.connection = new
|
|
5701
|
+
this.connection = new Connection2(getRpcUrls("sol")[0], "confirmed");
|
|
5351
5702
|
this.publicKey = options.publicKey;
|
|
5352
5703
|
this.signTransaction = options.signer.signTransaction;
|
|
5353
5704
|
this.signer = options.signer;
|
|
@@ -5358,7 +5709,7 @@ var SolanaWallet = class {
|
|
|
5358
5709
|
throw new Error("Wallet not connected");
|
|
5359
5710
|
}
|
|
5360
5711
|
const fromPubkey = this.publicKey;
|
|
5361
|
-
const toPubkey = new
|
|
5712
|
+
const toPubkey = new PublicKey2(to);
|
|
5362
5713
|
const lamports = Math.floor(parseFloat(amount) * LAMPORTS_PER_SOL);
|
|
5363
5714
|
const transaction = new Transaction().add(
|
|
5364
5715
|
SystemProgram.transfer({
|
|
@@ -5383,8 +5734,8 @@ var SolanaWallet = class {
|
|
|
5383
5734
|
throw new Error("Wallet not connected");
|
|
5384
5735
|
}
|
|
5385
5736
|
const fromPubkey = this.publicKey;
|
|
5386
|
-
const toPubkey = new
|
|
5387
|
-
const mint = new
|
|
5737
|
+
const toPubkey = new PublicKey2(to);
|
|
5738
|
+
const mint = new PublicKey2(tokenMint);
|
|
5388
5739
|
const fromTokenAccount = getAssociatedTokenAddressSync(mint, fromPubkey);
|
|
5389
5740
|
const toTokenAccount = getAssociatedTokenAddressSync(mint, toPubkey);
|
|
5390
5741
|
const transaction = new Transaction();
|
|
@@ -5438,13 +5789,13 @@ var SolanaWallet = class {
|
|
|
5438
5789
|
return result;
|
|
5439
5790
|
}
|
|
5440
5791
|
async getSOLBalance(account) {
|
|
5441
|
-
const publicKey = new
|
|
5792
|
+
const publicKey = new PublicKey2(account);
|
|
5442
5793
|
const balance = await this.connection.getBalance(publicKey);
|
|
5443
5794
|
return balance;
|
|
5444
5795
|
}
|
|
5445
5796
|
async getTokenBalance(tokenMint, account) {
|
|
5446
|
-
const mint = new
|
|
5447
|
-
const owner = new
|
|
5797
|
+
const mint = new PublicKey2(tokenMint);
|
|
5798
|
+
const owner = new PublicKey2(account);
|
|
5448
5799
|
try {
|
|
5449
5800
|
const tokenAccount = await getAssociatedTokenAddress(mint, owner);
|
|
5450
5801
|
const accountInfo = await getAccount(this.connection, tokenAccount);
|
|
@@ -5477,8 +5828,8 @@ var SolanaWallet = class {
|
|
|
5477
5828
|
let estimatedFee = 5000n;
|
|
5478
5829
|
const { originAsset, depositAddress } = data;
|
|
5479
5830
|
if (originAsset !== "SOL" && originAsset !== "sol") {
|
|
5480
|
-
const mint = new
|
|
5481
|
-
const toPubkey = new
|
|
5831
|
+
const mint = new PublicKey2(originAsset);
|
|
5832
|
+
const toPubkey = new PublicKey2(depositAddress);
|
|
5482
5833
|
const toTokenAccount = getAssociatedTokenAddressSync(mint, toPubkey);
|
|
5483
5834
|
try {
|
|
5484
5835
|
await getAccount(this.connection, toTokenAccount);
|
|
@@ -5579,6 +5930,8 @@ var SolanaWallet = class {
|
|
|
5579
5930
|
return await this.quoteCCTP(params);
|
|
5580
5931
|
case Service.OneClick:
|
|
5581
5932
|
return await this.quoteOneClickProxy(params);
|
|
5933
|
+
case Service.Usdt0:
|
|
5934
|
+
return await this.quoteOFT(params);
|
|
5582
5935
|
default:
|
|
5583
5936
|
throw new Error(`Unsupported quote type: ${type}`);
|
|
5584
5937
|
}
|
|
@@ -5609,13 +5962,13 @@ var SolanaWallet = class {
|
|
|
5609
5962
|
} = params;
|
|
5610
5963
|
try {
|
|
5611
5964
|
const result = { fees: {} };
|
|
5612
|
-
const PROGRAM_ID = new
|
|
5613
|
-
const STATE_PDA = new
|
|
5614
|
-
const MINT = new
|
|
5965
|
+
const PROGRAM_ID = new PublicKey2(proxyAddress);
|
|
5966
|
+
const STATE_PDA = new PublicKey2("9E8az3Y9sdXvM2f3CCH6c9N3iFyNfDryQCZhqDxRYGUw");
|
|
5967
|
+
const MINT = new PublicKey2(fromToken.contractAddress);
|
|
5615
5968
|
const AMOUNT = new BN(amountWei);
|
|
5616
|
-
const RECIPIENT = new
|
|
5969
|
+
const RECIPIENT = new PublicKey2(depositAddress);
|
|
5617
5970
|
const sender = this.publicKey;
|
|
5618
|
-
const userPubkey = new
|
|
5971
|
+
const userPubkey = new PublicKey2(refundTo || sender.toString());
|
|
5619
5972
|
const provider = new AnchorProvider(this.connection, this.signer, {
|
|
5620
5973
|
commitment: "confirmed"
|
|
5621
5974
|
});
|
|
@@ -5662,7 +6015,7 @@ var SolanaWallet = class {
|
|
|
5662
6015
|
transaction
|
|
5663
6016
|
};
|
|
5664
6017
|
const estimatedFee = simulation.value.fee || 5000n;
|
|
5665
|
-
const estimateGasUsd =
|
|
6018
|
+
const estimateGasUsd = Big6(estimatedFee.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
|
|
5666
6019
|
const usd = numberRemoveEndZero(estimateGasUsd.toFixed(20));
|
|
5667
6020
|
const wei = estimatedFee;
|
|
5668
6021
|
result.fees.sourceGasFeeUsd = usd;
|
|
@@ -5702,13 +6055,13 @@ var SolanaWallet = class {
|
|
|
5702
6055
|
estimateSourceGas: void 0,
|
|
5703
6056
|
estimateSourceGasUsd: void 0,
|
|
5704
6057
|
estimateTime: 0,
|
|
5705
|
-
outputAmount: numberRemoveEndZero(
|
|
6058
|
+
outputAmount: numberRemoveEndZero(Big6(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0))
|
|
5706
6059
|
};
|
|
5707
|
-
const PROGRAM_ID = new
|
|
5708
|
-
const MINT = new
|
|
6060
|
+
const PROGRAM_ID = new PublicKey2(proxyAddress);
|
|
6061
|
+
const MINT = new PublicKey2(fromToken.contractAddress);
|
|
5709
6062
|
const sender = this.publicKey;
|
|
5710
|
-
const userPubkey = new
|
|
5711
|
-
const [userStatePda] =
|
|
6063
|
+
const userPubkey = new PublicKey2(refundTo || sender.toString());
|
|
6064
|
+
const [userStatePda] = PublicKey2.findProgramAddressSync(
|
|
5712
6065
|
[Buffer.from("user"), userPubkey.toBuffer()],
|
|
5713
6066
|
PROGRAM_ID
|
|
5714
6067
|
);
|
|
@@ -5725,7 +6078,7 @@ var SolanaWallet = class {
|
|
|
5725
6078
|
const userTokenAccount = getAssociatedTokenAddressSync(MINT, userPubkey);
|
|
5726
6079
|
const signatureRes = await cctp_default.quoteSignature({
|
|
5727
6080
|
address: userPubkey.toString(),
|
|
5728
|
-
amount: numberRemoveEndZero(
|
|
6081
|
+
amount: numberRemoveEndZero(Big6(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0)),
|
|
5729
6082
|
destination_domain_id: destinationDomain,
|
|
5730
6083
|
receipt_address: recipient,
|
|
5731
6084
|
source_domain_id: sourceDomain,
|
|
@@ -5739,13 +6092,13 @@ var SolanaWallet = class {
|
|
|
5739
6092
|
signature
|
|
5740
6093
|
} = signatureRes;
|
|
5741
6094
|
result.fees.estimateMintGasUsd = numberRemoveEndZero(
|
|
5742
|
-
|
|
6095
|
+
Big6(mint_fee || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals)
|
|
5743
6096
|
);
|
|
5744
6097
|
result.fees.bridgeFeeUsd = numberRemoveEndZero(
|
|
5745
|
-
|
|
6098
|
+
Big6(bridge_fee || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals)
|
|
5746
6099
|
);
|
|
5747
6100
|
result.outputAmount = numberRemoveEndZero(
|
|
5748
|
-
|
|
6101
|
+
Big6(receipt_amount || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0)
|
|
5749
6102
|
);
|
|
5750
6103
|
const operatorTx = Transaction.from(Buffer.from(signature, "base64"));
|
|
5751
6104
|
if (!operatorTx.verifySignatures(false)) {
|
|
@@ -5758,7 +6111,7 @@ var SolanaWallet = class {
|
|
|
5758
6111
|
sigVerify: false
|
|
5759
6112
|
});
|
|
5760
6113
|
const estimatedFee = simulation.value.fee || 5000n;
|
|
5761
|
-
const estimateGasUsd =
|
|
6114
|
+
const estimateGasUsd = Big6(estimatedFee.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
|
|
5762
6115
|
result.fees.estimateDepositGasUsd = numberRemoveEndZero(estimateGasUsd.toFixed(20));
|
|
5763
6116
|
result.estimateSourceGas = estimatedFee;
|
|
5764
6117
|
result.estimateSourceGasUsd = numberRemoveEndZero(estimateGasUsd.toFixed(20));
|
|
@@ -5769,15 +6122,249 @@ var SolanaWallet = class {
|
|
|
5769
6122
|
if (excludeFees4 && excludeFees4.includes(feeKey) || !/Usd$/.test(feeKey)) {
|
|
5770
6123
|
continue;
|
|
5771
6124
|
}
|
|
5772
|
-
result.totalFeesUsd =
|
|
6125
|
+
result.totalFeesUsd = Big6(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
|
|
5773
6126
|
}
|
|
5774
|
-
result.totalFeesUsd = numberRemoveEndZero(
|
|
6127
|
+
result.totalFeesUsd = numberRemoveEndZero(Big6(result.totalFeesUsd || 0).toFixed(20));
|
|
5775
6128
|
return result;
|
|
5776
6129
|
} catch (error) {
|
|
5777
6130
|
console.log("quoteCCTP failed: %o", error);
|
|
5778
6131
|
return { errMsg: error.message };
|
|
5779
6132
|
}
|
|
5780
6133
|
}
|
|
6134
|
+
async quoteOFT(params) {
|
|
6135
|
+
const {
|
|
6136
|
+
originLayerzeroAddress,
|
|
6137
|
+
destinationLayerzeroAddress,
|
|
6138
|
+
fromToken,
|
|
6139
|
+
toToken,
|
|
6140
|
+
dstEid,
|
|
6141
|
+
refundTo,
|
|
6142
|
+
recipient,
|
|
6143
|
+
amountWei,
|
|
6144
|
+
payInLzToken,
|
|
6145
|
+
slippageTolerance,
|
|
6146
|
+
multiHopComposer,
|
|
6147
|
+
isMultiHopComposer,
|
|
6148
|
+
isOriginLegacy,
|
|
6149
|
+
prices,
|
|
6150
|
+
excludeFees: excludeFees4,
|
|
6151
|
+
originLayerzero
|
|
6152
|
+
} = params;
|
|
6153
|
+
try {
|
|
6154
|
+
const result = {
|
|
6155
|
+
needApprove: false,
|
|
6156
|
+
sendParam: void 0,
|
|
6157
|
+
fees: {},
|
|
6158
|
+
estimateSourceGas: void 0,
|
|
6159
|
+
estimateSourceGasUsd: void 0,
|
|
6160
|
+
outputAmount: numberRemoveEndZero(Big6(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0)),
|
|
6161
|
+
quoteParam: {
|
|
6162
|
+
...params
|
|
6163
|
+
},
|
|
6164
|
+
totalFeesUsd: void 0,
|
|
6165
|
+
estimateTime: 0
|
|
6166
|
+
};
|
|
6167
|
+
const programId = new PublicKey2(originLayerzeroAddress);
|
|
6168
|
+
const tokenMint = new PublicKey2(fromToken.contractAddress);
|
|
6169
|
+
const quotePayer = new PublicKey2("4NkxtcfRTCxJ1N2j6xENcDLPbiJ3541T6r5BqhTzMD9J");
|
|
6170
|
+
const lookupTable = new PublicKey2("6zcTrmdkiQp6dZHYUxVr6A2XVDSYi44X1rcPtvwNcrXi");
|
|
6171
|
+
const tokenEscrow = new PublicKey2("F1YkdxaiLA1eJt12y3uMAQef48Td3zdJfYhzjphma8hG");
|
|
6172
|
+
const sender = this.publicKey;
|
|
6173
|
+
const userPubkey = new PublicKey2(refundTo || sender.toString());
|
|
6174
|
+
const mintInfo = await this.connection.getParsedAccountInfo(tokenMint);
|
|
6175
|
+
const decimals = (mintInfo.value?.data).parsed.info.decimals;
|
|
6176
|
+
const amountLd = BigInt(amountWei);
|
|
6177
|
+
const slippage = slippageTolerance || 0.01;
|
|
6178
|
+
const minAmountLd = BigInt(Big6(amountWei).times(Big6(1).minus(Big6(slippage).div(100))).toFixed(0));
|
|
6179
|
+
const lzReceiveOptionGas = isOriginLegacy ? originLayerzero.lzReceiveOptionGasLegacy : originLayerzero.lzReceiveOptionGas;
|
|
6180
|
+
const lzReceiveOptionValue = LZ_RECEIVE_VALUE[toToken.chainName] || 0;
|
|
6181
|
+
let _dstEid = dstEid;
|
|
6182
|
+
let to = new Uint8Array(Buffer.from(addressToBytes32(recipient)));
|
|
6183
|
+
let extraOptions = Options.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).toBytes();
|
|
6184
|
+
let composeMsg = null;
|
|
6185
|
+
if (isMultiHopComposer) {
|
|
6186
|
+
_dstEid = multiHopComposer.eid;
|
|
6187
|
+
to = new Uint8Array(Buffer.from(addressToBytes32(multiHopComposer.oftMultiHopComposer)));
|
|
6188
|
+
const composeMsgSendParam = {
|
|
6189
|
+
dstEid,
|
|
6190
|
+
to: addressToBytes32(recipient),
|
|
6191
|
+
amountLD: amountLd,
|
|
6192
|
+
minAmountLD: minAmountLd,
|
|
6193
|
+
extraOptions: Options.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).toHex(),
|
|
6194
|
+
composeMsg: "0x",
|
|
6195
|
+
oftCmd: "0x"
|
|
6196
|
+
};
|
|
6197
|
+
const hopMsgFee = await getHopMsgFee({
|
|
6198
|
+
sendParam: composeMsgSendParam,
|
|
6199
|
+
toToken
|
|
6200
|
+
});
|
|
6201
|
+
extraOptions = Options.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).addExecutorComposeOption(0, originLayerzero.composeOptionGas || 5e5, hopMsgFee).toBytes();
|
|
6202
|
+
const abiCoder = ethers3.AbiCoder.defaultAbiCoder();
|
|
6203
|
+
const composeEncoder = abiCoder.encode(
|
|
6204
|
+
["tuple(uint32 dstEid, bytes32 to, uint256 amountLD, uint256 minAmountLD, bytes extraOptions, bytes composeMsg, bytes oftCmd)"],
|
|
6205
|
+
[Object.values(composeMsgSendParam)]
|
|
6206
|
+
);
|
|
6207
|
+
composeMsg = ethers3.getBytes(composeEncoder);
|
|
6208
|
+
}
|
|
6209
|
+
const pdas = deriveOftPdas(programId, _dstEid);
|
|
6210
|
+
const peerAddress = await getPeerAddress(this.connection, programId, _dstEid);
|
|
6211
|
+
const tokenSource = await getAssociatedTokenAddress(
|
|
6212
|
+
tokenMint,
|
|
6213
|
+
userPubkey,
|
|
6214
|
+
false,
|
|
6215
|
+
TOKEN_PROGRAM_ID
|
|
6216
|
+
);
|
|
6217
|
+
const sendHelper = new SendHelper();
|
|
6218
|
+
const remainingAccounts = await sendHelper.getQuoteAccounts(
|
|
6219
|
+
this.connection,
|
|
6220
|
+
quotePayer,
|
|
6221
|
+
pdas.oftStore,
|
|
6222
|
+
_dstEid,
|
|
6223
|
+
peerAddress
|
|
6224
|
+
);
|
|
6225
|
+
const ix = new TransactionInstruction({
|
|
6226
|
+
programId,
|
|
6227
|
+
keys: [
|
|
6228
|
+
{ pubkey: pdas.oftStore, isSigner: false, isWritable: false },
|
|
6229
|
+
{ pubkey: pdas.credits, isSigner: false, isWritable: false },
|
|
6230
|
+
{ pubkey: pdas.peer, isSigner: false, isWritable: false },
|
|
6231
|
+
...remainingAccounts
|
|
6232
|
+
],
|
|
6233
|
+
data: Buffer.from(
|
|
6234
|
+
encodeQuoteSend({
|
|
6235
|
+
dstEid: _dstEid,
|
|
6236
|
+
to,
|
|
6237
|
+
amountLd,
|
|
6238
|
+
minAmountLd,
|
|
6239
|
+
extraOptions,
|
|
6240
|
+
composeMsg,
|
|
6241
|
+
payInLzToken: false
|
|
6242
|
+
})
|
|
6243
|
+
)
|
|
6244
|
+
});
|
|
6245
|
+
const computeIx = ComputeBudgetProgram.setComputeUnitLimit({ units: 14e5 });
|
|
6246
|
+
const tx = await buildVersionedTransaction(
|
|
6247
|
+
this.connection,
|
|
6248
|
+
quotePayer,
|
|
6249
|
+
[computeIx, ix],
|
|
6250
|
+
void 0,
|
|
6251
|
+
void 0,
|
|
6252
|
+
lookupTable
|
|
6253
|
+
);
|
|
6254
|
+
const sim = await this.connection.simulateTransaction(tx, {
|
|
6255
|
+
sigVerify: false,
|
|
6256
|
+
replaceRecentBlockhash: true
|
|
6257
|
+
});
|
|
6258
|
+
if (sim.value.err) {
|
|
6259
|
+
console.error("Simulation logs:", sim.value.logs);
|
|
6260
|
+
throw new Error(`Quote failed: ${JSON.stringify(sim.value.err)}`);
|
|
6261
|
+
}
|
|
6262
|
+
const prefix = `Program return: ${programId} `;
|
|
6263
|
+
const log = sim.value.logs?.find((l) => l.startsWith(prefix));
|
|
6264
|
+
if (!log) throw new Error("Return data not found");
|
|
6265
|
+
const data = Buffer.from(log.slice(prefix.length), "base64");
|
|
6266
|
+
const nativeFee = data.readBigUInt64LE(0);
|
|
6267
|
+
const lzTokenFee = data.readBigUInt64LE(8);
|
|
6268
|
+
if (prices && fromToken.nativeToken) {
|
|
6269
|
+
const nativeFeeUsd = Big6(nativeFee.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
|
|
6270
|
+
result.fees.nativeFeeUsd = numberRemoveEndZero(nativeFeeUsd.toFixed(20));
|
|
6271
|
+
}
|
|
6272
|
+
result.fees.nativeFee = Big6(nativeFee.toString()).div(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals, 0);
|
|
6273
|
+
if (lzTokenFee > 0n && prices && fromToken) {
|
|
6274
|
+
const lzTokenFeeUsd = Big6(lzTokenFee.toString()).div(10 ** fromToken.decimals).times(getPrice(prices, fromToken.symbol));
|
|
6275
|
+
result.fees.lzTokenFeeUsd = numberRemoveEndZero(lzTokenFeeUsd.toFixed(20));
|
|
6276
|
+
}
|
|
6277
|
+
result.fees.lzTokenFee = lzTokenFee.toString();
|
|
6278
|
+
const sendSendHelper = new SendHelper();
|
|
6279
|
+
const sendRemainingAccounts = await sendSendHelper.getSendAccounts(
|
|
6280
|
+
this.connection,
|
|
6281
|
+
userPubkey,
|
|
6282
|
+
pdas.oftStore,
|
|
6283
|
+
_dstEid,
|
|
6284
|
+
peerAddress
|
|
6285
|
+
);
|
|
6286
|
+
const sendIx = new TransactionInstruction({
|
|
6287
|
+
programId,
|
|
6288
|
+
keys: [
|
|
6289
|
+
{ pubkey: userPubkey, isSigner: true, isWritable: true },
|
|
6290
|
+
{ pubkey: pdas.peer, isSigner: false, isWritable: false },
|
|
6291
|
+
{ pubkey: pdas.oftStore, isSigner: false, isWritable: true },
|
|
6292
|
+
{ pubkey: pdas.credits, isSigner: false, isWritable: true },
|
|
6293
|
+
{ pubkey: tokenSource, isSigner: false, isWritable: true },
|
|
6294
|
+
{ pubkey: tokenEscrow, isSigner: false, isWritable: true },
|
|
6295
|
+
{ pubkey: tokenMint, isSigner: false, isWritable: false },
|
|
6296
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
6297
|
+
{ pubkey: pdas.eventAuthority, isSigner: false, isWritable: false },
|
|
6298
|
+
{ pubkey: programId, isSigner: false, isWritable: false },
|
|
6299
|
+
...sendRemainingAccounts
|
|
6300
|
+
],
|
|
6301
|
+
data: Buffer.from(
|
|
6302
|
+
encodeSend({
|
|
6303
|
+
dstEid: _dstEid,
|
|
6304
|
+
to,
|
|
6305
|
+
amountLd,
|
|
6306
|
+
minAmountLd,
|
|
6307
|
+
extraOptions,
|
|
6308
|
+
composeMsg,
|
|
6309
|
+
nativeFee,
|
|
6310
|
+
lzTokenFee: 0n
|
|
6311
|
+
})
|
|
6312
|
+
)
|
|
6313
|
+
});
|
|
6314
|
+
const computeSendIx = ComputeBudgetProgram.setComputeUnitLimit({ units: 4e5 });
|
|
6315
|
+
const sendTx = await buildVersionedTransaction(
|
|
6316
|
+
this.connection,
|
|
6317
|
+
userPubkey,
|
|
6318
|
+
[computeSendIx, sendIx],
|
|
6319
|
+
void 0,
|
|
6320
|
+
void 0,
|
|
6321
|
+
lookupTable
|
|
6322
|
+
);
|
|
6323
|
+
let estimatedFee = 5000n;
|
|
6324
|
+
try {
|
|
6325
|
+
const sendSim = await this.connection.simulateTransaction(sendTx, {
|
|
6326
|
+
sigVerify: false,
|
|
6327
|
+
replaceRecentBlockhash: true
|
|
6328
|
+
});
|
|
6329
|
+
console.log("sendSim: %o", JSON.stringify(sendSim));
|
|
6330
|
+
if (!sendSim.value.err) {
|
|
6331
|
+
estimatedFee = sendSim.value.fee || 5000n;
|
|
6332
|
+
} else {
|
|
6333
|
+
console.warn("Send simulation failed (this is normal in quote phase):", sendSim.value.err);
|
|
6334
|
+
const fee = sendSim.value.fee;
|
|
6335
|
+
if (fee) {
|
|
6336
|
+
estimatedFee = fee;
|
|
6337
|
+
}
|
|
6338
|
+
}
|
|
6339
|
+
} catch (simError) {
|
|
6340
|
+
console.warn("Send simulation error (this is normal in quote phase):", simError.message);
|
|
6341
|
+
}
|
|
6342
|
+
if (prices && fromToken.nativeToken) {
|
|
6343
|
+
const estimateGasUsd = Big6(estimatedFee.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
|
|
6344
|
+
result.fees.estimateSourceGasUsd = numberRemoveEndZero(estimateGasUsd.toFixed(20));
|
|
6345
|
+
result.estimateSourceGasUsd = numberRemoveEndZero(estimateGasUsd.toFixed(20));
|
|
6346
|
+
}
|
|
6347
|
+
result.estimateSourceGas = estimatedFee;
|
|
6348
|
+
result.fees.legacyMeshFeeUsd = numberRemoveEndZero(Big6(amountWei || 0).div(10 ** params.fromToken.decimals).times(USDT0_LEGACY_MESH_TRANSFTER_FEE).toFixed(params.fromToken.decimals));
|
|
6349
|
+
result.outputAmount = numberRemoveEndZero(Big6(Big6(amountWei || 0).div(10 ** params.fromToken.decimals)).minus(result.fees.legacyMeshFeeUsd || 0).toFixed(params.fromToken.decimals, 0));
|
|
6350
|
+
result.sendParam = {
|
|
6351
|
+
transaction: sendTx
|
|
6352
|
+
};
|
|
6353
|
+
if (prices) {
|
|
6354
|
+
for (const feeKey in result.fees) {
|
|
6355
|
+
if (excludeFees4 && excludeFees4.includes(feeKey) || !/Usd$/.test(feeKey)) {
|
|
6356
|
+
continue;
|
|
6357
|
+
}
|
|
6358
|
+
result.totalFeesUsd = Big6(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
|
|
6359
|
+
}
|
|
6360
|
+
result.totalFeesUsd = numberRemoveEndZero(Big6(result.totalFeesUsd || 0).toFixed(20));
|
|
6361
|
+
}
|
|
6362
|
+
return result;
|
|
6363
|
+
} catch (error) {
|
|
6364
|
+
console.log("quoteOFT failed: %o", error);
|
|
6365
|
+
return { errMsg: error.message };
|
|
6366
|
+
}
|
|
6367
|
+
}
|
|
5781
6368
|
async createAssociatedTokenAddress(params) {
|
|
5782
6369
|
const {
|
|
5783
6370
|
tokenMint
|
|
@@ -5786,7 +6373,7 @@ var SolanaWallet = class {
|
|
|
5786
6373
|
throw new Error("Wallet not connected");
|
|
5787
6374
|
}
|
|
5788
6375
|
const ownerPubkey = this.publicKey;
|
|
5789
|
-
const mint = new
|
|
6376
|
+
const mint = new PublicKey2(tokenMint);
|
|
5790
6377
|
const associatedTokenAccount = getAssociatedTokenAddressSync(mint, ownerPubkey);
|
|
5791
6378
|
console.log("associatedTokenAccount: %o", associatedTokenAccount);
|
|
5792
6379
|
const createTokenAccount = async () => {
|
|
@@ -5862,9 +6449,9 @@ var erc20_default = [
|
|
|
5862
6449
|
];
|
|
5863
6450
|
|
|
5864
6451
|
// src/wallets/evm.ts
|
|
5865
|
-
import
|
|
5866
|
-
import { ethers } from "ethers";
|
|
5867
|
-
import { Options } from "@layerzerolabs/lz-v2-utilities";
|
|
6452
|
+
import Big7 from "big.js";
|
|
6453
|
+
import { ethers as ethers4 } from "ethers";
|
|
6454
|
+
import { Options as Options2 } from "@layerzerolabs/lz-v2-utilities";
|
|
5868
6455
|
|
|
5869
6456
|
// src/utils/address.ts
|
|
5870
6457
|
import bs58 from "bs58";
|
|
@@ -5894,7 +6481,7 @@ function solanaAddressToBytes32(solanaAddress) {
|
|
|
5894
6481
|
}
|
|
5895
6482
|
return "0x" + Buffer.from(decoded).toString("hex");
|
|
5896
6483
|
}
|
|
5897
|
-
function
|
|
6484
|
+
function addressToBytes322(chainType, address) {
|
|
5898
6485
|
if (chainType === "evm") {
|
|
5899
6486
|
return zeroPadValue(address, 32);
|
|
5900
6487
|
}
|
|
@@ -5906,9 +6493,40 @@ function addressToBytes32(chainType, address) {
|
|
|
5906
6493
|
}
|
|
5907
6494
|
}
|
|
5908
6495
|
|
|
5909
|
-
// src/wallets/
|
|
5910
|
-
import { Connection as Connection2, PublicKey as PublicKey2 } from "@solana/web3.js";
|
|
6496
|
+
// src/wallets/utils/solana.ts
|
|
5911
6497
|
import { getAssociatedTokenAddressSync as getAssociatedTokenAddressSync2 } from "@solana/spl-token";
|
|
6498
|
+
import { Connection as Connection3, PublicKey as PublicKey3 } from "@solana/web3.js";
|
|
6499
|
+
var getDestinationAssociatedTokenAddress = async (params) => {
|
|
6500
|
+
const {
|
|
6501
|
+
recipient,
|
|
6502
|
+
toToken
|
|
6503
|
+
} = params;
|
|
6504
|
+
const result = {
|
|
6505
|
+
needCreateTokenAccount: false,
|
|
6506
|
+
associatedTokenAddress: ""
|
|
6507
|
+
};
|
|
6508
|
+
if (toToken.chainType !== "sol") {
|
|
6509
|
+
return result;
|
|
6510
|
+
}
|
|
6511
|
+
try {
|
|
6512
|
+
const connection = new Connection3(getRpcUrls("sol")[0]);
|
|
6513
|
+
const wallet = new PublicKey3(recipient);
|
|
6514
|
+
const TOKEN_MINT = new PublicKey3(toToken.contractAddress);
|
|
6515
|
+
const ata = getAssociatedTokenAddressSync2(TOKEN_MINT, wallet);
|
|
6516
|
+
const accountInfo = await connection.getAccountInfo(ata);
|
|
6517
|
+
console.log("accountInfo: %o", accountInfo);
|
|
6518
|
+
if (!accountInfo) {
|
|
6519
|
+
result.needCreateTokenAccount = true;
|
|
6520
|
+
return result;
|
|
6521
|
+
}
|
|
6522
|
+
result.associatedTokenAddress = ata.toBase58();
|
|
6523
|
+
} catch (error) {
|
|
6524
|
+
console.log("getDestinationAssociatedTokenAddress failed: %o", error);
|
|
6525
|
+
}
|
|
6526
|
+
return result;
|
|
6527
|
+
};
|
|
6528
|
+
|
|
6529
|
+
// src/wallets/evm.ts
|
|
5912
6530
|
var DEFAULT_GAS_LIMIT = 100000n;
|
|
5913
6531
|
var EVMWallet = class {
|
|
5914
6532
|
constructor(_provider, _signer) {
|
|
@@ -5920,12 +6538,12 @@ var EVMWallet = class {
|
|
|
5920
6538
|
if (originAsset === "eth") {
|
|
5921
6539
|
const tx2 = await this.signer.sendTransaction({
|
|
5922
6540
|
to: depositAddress,
|
|
5923
|
-
value:
|
|
6541
|
+
value: ethers4.parseEther(amount)
|
|
5924
6542
|
});
|
|
5925
6543
|
await tx2.wait();
|
|
5926
6544
|
return tx2;
|
|
5927
6545
|
}
|
|
5928
|
-
const contract = new
|
|
6546
|
+
const contract = new ethers4.Contract(originAsset, erc20_default, this.signer);
|
|
5929
6547
|
const tx = await contract.transfer(depositAddress, amount);
|
|
5930
6548
|
const result = await tx.wait();
|
|
5931
6549
|
return result.hash;
|
|
@@ -5933,14 +6551,15 @@ var EVMWallet = class {
|
|
|
5933
6551
|
async getBalance(token, account) {
|
|
5934
6552
|
try {
|
|
5935
6553
|
let provider = this.provider;
|
|
5936
|
-
if (token.
|
|
5937
|
-
|
|
6554
|
+
if (token.rpcUrls) {
|
|
6555
|
+
const providers = token.rpcUrls.map((url) => new ethers4.JsonRpcProvider(url));
|
|
6556
|
+
provider = new ethers4.FallbackProvider(providers);
|
|
5938
6557
|
}
|
|
5939
6558
|
if (token.symbol === "eth" || token.symbol === "ETH" || token.symbol === "native") {
|
|
5940
6559
|
const balance2 = await provider.getBalance(account);
|
|
5941
6560
|
return balance2.toString();
|
|
5942
6561
|
}
|
|
5943
|
-
const contract = new
|
|
6562
|
+
const contract = new ethers4.Contract(token.contractAddress, erc20_default, provider);
|
|
5944
6563
|
const balance = await contract.balanceOf(account);
|
|
5945
6564
|
return balance.toString();
|
|
5946
6565
|
} catch (err) {
|
|
@@ -5967,11 +6586,11 @@ var EVMWallet = class {
|
|
|
5967
6586
|
const tx = {
|
|
5968
6587
|
from: fromAddress,
|
|
5969
6588
|
to: depositAddress,
|
|
5970
|
-
value:
|
|
6589
|
+
value: ethers4.parseEther(amount)
|
|
5971
6590
|
};
|
|
5972
6591
|
gasLimit = await this.provider.estimateGas(tx);
|
|
5973
6592
|
} else {
|
|
5974
|
-
const contract = new
|
|
6593
|
+
const contract = new ethers4.Contract(originAsset, erc20_default, this.signer);
|
|
5975
6594
|
gasLimit = await contract.transfer.estimateGas(depositAddress, amount);
|
|
5976
6595
|
}
|
|
5977
6596
|
gasLimit = gasLimit * 120n / 100n;
|
|
@@ -5989,7 +6608,7 @@ var EVMWallet = class {
|
|
|
5989
6608
|
contractAddress,
|
|
5990
6609
|
abi
|
|
5991
6610
|
} = params;
|
|
5992
|
-
return new
|
|
6611
|
+
return new ethers4.Contract(contractAddress, abi, this.signer);
|
|
5993
6612
|
}
|
|
5994
6613
|
async allowance(params) {
|
|
5995
6614
|
const {
|
|
@@ -5998,7 +6617,7 @@ var EVMWallet = class {
|
|
|
5998
6617
|
address,
|
|
5999
6618
|
amountWei
|
|
6000
6619
|
} = params;
|
|
6001
|
-
const contract = new
|
|
6620
|
+
const contract = new ethers4.Contract(contractAddress, erc20_default, this.signer);
|
|
6002
6621
|
let allowance = "0";
|
|
6003
6622
|
try {
|
|
6004
6623
|
allowance = await contract.allowance(address, spender);
|
|
@@ -6009,7 +6628,7 @@ var EVMWallet = class {
|
|
|
6009
6628
|
return {
|
|
6010
6629
|
contract,
|
|
6011
6630
|
allowance,
|
|
6012
|
-
needApprove:
|
|
6631
|
+
needApprove: Big7(amountWei || 0).gt(allowance || 0)
|
|
6013
6632
|
};
|
|
6014
6633
|
}
|
|
6015
6634
|
async approve(params) {
|
|
@@ -6019,10 +6638,10 @@ var EVMWallet = class {
|
|
|
6019
6638
|
amountWei,
|
|
6020
6639
|
isApproveMax = false
|
|
6021
6640
|
} = params;
|
|
6022
|
-
const contract = new
|
|
6641
|
+
const contract = new ethers4.Contract(contractAddress, erc20_default, this.signer);
|
|
6023
6642
|
let _amountWei = amountWei;
|
|
6024
6643
|
if (isApproveMax) {
|
|
6025
|
-
_amountWei =
|
|
6644
|
+
_amountWei = ethers4.MaxUint256;
|
|
6026
6645
|
}
|
|
6027
6646
|
try {
|
|
6028
6647
|
const tx = await contract.approve(spender, _amountWei);
|
|
@@ -6041,13 +6660,13 @@ var EVMWallet = class {
|
|
|
6041
6660
|
const feeData = await this.provider.getFeeData();
|
|
6042
6661
|
const gasPrice = feeData.maxFeePerGas || feeData.gasPrice || BigInt("20000000000");
|
|
6043
6662
|
const estimateGas = BigInt(gasLimit) * BigInt(gasPrice);
|
|
6044
|
-
const estimateGasAmount =
|
|
6045
|
-
const estimateGasUsd =
|
|
6663
|
+
const estimateGasAmount = Big7(estimateGas.toString()).div(10 ** nativeToken.decimals);
|
|
6664
|
+
const estimateGasUsd = Big7(estimateGasAmount).times(price || 1);
|
|
6046
6665
|
return {
|
|
6047
6666
|
gasPrice,
|
|
6048
|
-
usd: numberRemoveEndZero(
|
|
6667
|
+
usd: numberRemoveEndZero(Big7(estimateGasUsd).toFixed(20)),
|
|
6049
6668
|
wei: estimateGas,
|
|
6050
|
-
amount: numberRemoveEndZero(
|
|
6669
|
+
amount: numberRemoveEndZero(Big7(estimateGasAmount).toFixed(nativeToken.decimals))
|
|
6051
6670
|
};
|
|
6052
6671
|
}
|
|
6053
6672
|
async quoteOFT(params) {
|
|
@@ -6068,7 +6687,8 @@ var EVMWallet = class {
|
|
|
6068
6687
|
multiHopComposer,
|
|
6069
6688
|
isMultiHopComposer,
|
|
6070
6689
|
isOriginLegacy,
|
|
6071
|
-
isDestinationLegacy
|
|
6690
|
+
isDestinationLegacy,
|
|
6691
|
+
originLayerzero
|
|
6072
6692
|
} = params;
|
|
6073
6693
|
const result = {
|
|
6074
6694
|
needApprove: false,
|
|
@@ -6085,12 +6705,11 @@ var EVMWallet = class {
|
|
|
6085
6705
|
estimateSourceGasUsd: void 0,
|
|
6086
6706
|
estimateTime: 0,
|
|
6087
6707
|
// seconds - dynamically calculated using LayerZero formula
|
|
6088
|
-
outputAmount: numberRemoveEndZero(
|
|
6708
|
+
outputAmount: numberRemoveEndZero(Big7(amountWei || 0).div(10 ** params.fromToken.decimals).toFixed(params.fromToken.decimals, 0))
|
|
6089
6709
|
};
|
|
6090
|
-
const oftContract = new
|
|
6091
|
-
const oftContractRead = new
|
|
6710
|
+
const oftContract = new ethers4.Contract(originLayerzeroAddress, abi, this.signer);
|
|
6711
|
+
const oftContractRead = new ethers4.Contract(originLayerzeroAddress, abi, this.provider);
|
|
6092
6712
|
const approvalRequired = await oftContractRead.approvalRequired();
|
|
6093
|
-
console.log("%cApprovalRequired: %o", "background:blue;color:white;", approvalRequired);
|
|
6094
6713
|
if (approvalRequired) {
|
|
6095
6714
|
try {
|
|
6096
6715
|
const allowanceResult = await this.allowance({
|
|
@@ -6104,42 +6723,52 @@ var EVMWallet = class {
|
|
|
6104
6723
|
console.log("Error checking allowance: %o", error);
|
|
6105
6724
|
}
|
|
6106
6725
|
}
|
|
6726
|
+
const lzReceiveOptionGas = isOriginLegacy ? originLayerzero.lzReceiveOptionGasLegacy : originLayerzero.lzReceiveOptionGas;
|
|
6727
|
+
let lzReceiveOptionValue = 0;
|
|
6728
|
+
const destATA = await getDestinationAssociatedTokenAddress({
|
|
6729
|
+
recipient,
|
|
6730
|
+
toToken
|
|
6731
|
+
});
|
|
6732
|
+
if (destATA.needCreateTokenAccount) {
|
|
6733
|
+
lzReceiveOptionValue = LZ_RECEIVE_VALUE[toToken.chainName] || 0;
|
|
6734
|
+
}
|
|
6107
6735
|
const sendParam = {
|
|
6108
6736
|
dstEid,
|
|
6109
|
-
to:
|
|
6737
|
+
to: addressToBytes322(toToken.chainType, recipient),
|
|
6110
6738
|
amountLD: amountWei,
|
|
6111
6739
|
minAmountLD: 0n,
|
|
6112
|
-
extraOptions:
|
|
6740
|
+
extraOptions: Options2.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).toHex(),
|
|
6113
6741
|
composeMsg: "0x",
|
|
6114
6742
|
oftCmd: "0x"
|
|
6115
6743
|
};
|
|
6116
6744
|
if (isMultiHopComposer) {
|
|
6117
6745
|
sendParam.dstEid = multiHopComposer.eid;
|
|
6118
|
-
sendParam.to =
|
|
6119
|
-
|
|
6120
|
-
|
|
6746
|
+
sendParam.to = addressToBytes322("evm", multiHopComposer.oftMultiHopComposer);
|
|
6747
|
+
const composeMsgSendParam = {
|
|
6748
|
+
dstEid,
|
|
6749
|
+
to: addressToBytes322(toToken.chainType, recipient),
|
|
6750
|
+
amountLD: sendParam.amountLD,
|
|
6751
|
+
minAmountLD: sendParam.minAmountLD,
|
|
6752
|
+
extraOptions: Options2.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).toHex(),
|
|
6753
|
+
composeMsg: "0x",
|
|
6754
|
+
oftCmd: "0x"
|
|
6755
|
+
};
|
|
6756
|
+
const hopMsgFee = await getHopMsgFee({
|
|
6757
|
+
sendParam: composeMsgSendParam,
|
|
6758
|
+
toToken
|
|
6759
|
+
});
|
|
6760
|
+
sendParam.extraOptions = Options2.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).addExecutorComposeOption(0, originLayerzero.composeOptionGas || 8e5, hopMsgFee).toHex();
|
|
6761
|
+
const abiCoder = ethers4.AbiCoder.defaultAbiCoder();
|
|
6121
6762
|
sendParam.composeMsg = abiCoder.encode(
|
|
6122
6763
|
["tuple(uint32 dstEid, bytes32 to, uint256 amountLD, uint256 minAmountLD, bytes extraOptions, bytes composeMsg, bytes oftCmd)"],
|
|
6123
|
-
[
|
|
6124
|
-
dstEid,
|
|
6125
|
-
addressToBytes32(toToken.chainType, recipient),
|
|
6126
|
-
sendParam.amountLD,
|
|
6127
|
-
sendParam.minAmountLD,
|
|
6128
|
-
"0x",
|
|
6129
|
-
"0x",
|
|
6130
|
-
"0x"
|
|
6131
|
-
]]
|
|
6764
|
+
[Object.values(composeMsgSendParam)]
|
|
6132
6765
|
);
|
|
6133
6766
|
}
|
|
6134
|
-
if (isDestinationLegacy) {
|
|
6135
|
-
result.fees.legacyMeshFeeUsd = numberRemoveEndZero(Big5(amountWei || 0).div(10 ** params.fromToken.decimals).times(3e-4).toFixed(params.fromToken.decimals));
|
|
6136
|
-
}
|
|
6137
6767
|
const oftData = await oftContractRead.quoteOFT.staticCall(sendParam);
|
|
6138
6768
|
const [, , oftReceipt] = oftData;
|
|
6139
6769
|
sendParam.minAmountLD = oftReceipt[1] * (1000000n - BigInt(slippageTolerance * 1e4)) / 1000000n;
|
|
6140
6770
|
const msgFee = await oftContractRead.quoteSend.staticCall(sendParam, payInLzToken);
|
|
6141
6771
|
result.estimateSourceGas = msgFee[0];
|
|
6142
|
-
console.log("%cMsgFee: %o", "background:blue;color:white;", msgFee);
|
|
6143
6772
|
result.sendParam = {
|
|
6144
6773
|
contract: oftContract,
|
|
6145
6774
|
method: "send",
|
|
@@ -6153,13 +6782,13 @@ var EVMWallet = class {
|
|
|
6153
6782
|
{ value: msgFee[0] }
|
|
6154
6783
|
]
|
|
6155
6784
|
};
|
|
6156
|
-
|
|
6157
|
-
|
|
6158
|
-
result.fees.nativeFeeUsd = numberRemoveEndZero(
|
|
6159
|
-
result.fees.lzTokenFeeUsd = numberRemoveEndZero(
|
|
6160
|
-
if (
|
|
6161
|
-
result.fees.legacyMeshFeeUsd = numberRemoveEndZero(
|
|
6162
|
-
result.outputAmount = numberRemoveEndZero(
|
|
6785
|
+
const nativeFeeUsd = Big7(msgFee[0]?.toString() || 0).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
|
|
6786
|
+
result.fees.nativeFee = numberRemoveEndZero(Big7(msgFee[0]?.toString() || 0).div(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals));
|
|
6787
|
+
result.fees.nativeFeeUsd = numberRemoveEndZero(Big7(nativeFeeUsd).toFixed(20));
|
|
6788
|
+
result.fees.lzTokenFeeUsd = numberRemoveEndZero(Big7(msgFee[1]?.toString() || 0).div(10 ** fromToken.decimals).toFixed(20));
|
|
6789
|
+
if (isOriginLegacy || isDestinationLegacy) {
|
|
6790
|
+
result.fees.legacyMeshFeeUsd = numberRemoveEndZero(Big7(amountWei || 0).div(10 ** params.fromToken.decimals).times(USDT0_LEGACY_MESH_TRANSFTER_FEE).toFixed(params.fromToken.decimals));
|
|
6791
|
+
result.outputAmount = numberRemoveEndZero(Big7(Big7(amountWei || 0).div(10 ** params.fromToken.decimals)).minus(result.fees.legacyMeshFeeUsd || 0).toFixed(params.fromToken.decimals, 0));
|
|
6163
6792
|
}
|
|
6164
6793
|
try {
|
|
6165
6794
|
const gasLimit = await oftContract.send.estimateGas(...result.sendParam.param);
|
|
@@ -6185,9 +6814,9 @@ var EVMWallet = class {
|
|
|
6185
6814
|
if (excludeFees4.includes(feeKey)) {
|
|
6186
6815
|
continue;
|
|
6187
6816
|
}
|
|
6188
|
-
result.totalFeesUsd =
|
|
6817
|
+
result.totalFeesUsd = Big7(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
|
|
6189
6818
|
}
|
|
6190
|
-
result.totalFeesUsd = numberRemoveEndZero(
|
|
6819
|
+
result.totalFeesUsd = numberRemoveEndZero(Big7(result.totalFeesUsd).toFixed(20));
|
|
6191
6820
|
return result;
|
|
6192
6821
|
}
|
|
6193
6822
|
async sendTransaction(params) {
|
|
@@ -6265,22 +6894,18 @@ var EVMWallet = class {
|
|
|
6265
6894
|
estimateSourceGas: void 0,
|
|
6266
6895
|
estimateSourceGasUsd: void 0,
|
|
6267
6896
|
estimateTime: Math.floor(Math.random() * 8) + 3,
|
|
6268
|
-
outputAmount: numberRemoveEndZero(
|
|
6897
|
+
outputAmount: numberRemoveEndZero(Big7(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0))
|
|
6269
6898
|
};
|
|
6270
|
-
const proxyContract = new
|
|
6271
|
-
const proxyContractRead = new
|
|
6899
|
+
const proxyContract = new ethers4.Contract(proxyAddress, abi, this.signer);
|
|
6900
|
+
const proxyContractRead = new ethers4.Contract(proxyAddress, abi, this.provider);
|
|
6272
6901
|
let realRecipient = recipient;
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
|
|
6276
|
-
|
|
6277
|
-
|
|
6278
|
-
|
|
6279
|
-
|
|
6280
|
-
result.needCreateTokenAccount = true;
|
|
6281
|
-
} else {
|
|
6282
|
-
realRecipient = ata.toBase58();
|
|
6283
|
-
}
|
|
6902
|
+
const destATA = await getDestinationAssociatedTokenAddress({
|
|
6903
|
+
recipient,
|
|
6904
|
+
toToken
|
|
6905
|
+
});
|
|
6906
|
+
result.needCreateTokenAccount = destATA.needCreateTokenAccount;
|
|
6907
|
+
if (destATA.associatedTokenAddress) {
|
|
6908
|
+
realRecipient = destATA.associatedTokenAddress;
|
|
6284
6909
|
}
|
|
6285
6910
|
let userNonce = 0n;
|
|
6286
6911
|
try {
|
|
@@ -6289,7 +6914,7 @@ var EVMWallet = class {
|
|
|
6289
6914
|
}
|
|
6290
6915
|
const signatureRes = await cctp_default.quoteSignature({
|
|
6291
6916
|
address: refundTo,
|
|
6292
|
-
amount: numberRemoveEndZero(
|
|
6917
|
+
amount: numberRemoveEndZero(Big7(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0)),
|
|
6293
6918
|
destination_domain_id: destinationDomain,
|
|
6294
6919
|
receipt_address: realRecipient,
|
|
6295
6920
|
source_domain_id: sourceDomain,
|
|
@@ -6304,10 +6929,10 @@ var EVMWallet = class {
|
|
|
6304
6929
|
signature,
|
|
6305
6930
|
destination_caller
|
|
6306
6931
|
} = signatureRes;
|
|
6307
|
-
result.fees.estimateMintGasUsd = numberRemoveEndZero(
|
|
6308
|
-
result.fees.bridgeFeeUsd = numberRemoveEndZero(
|
|
6932
|
+
result.fees.estimateMintGasUsd = numberRemoveEndZero(Big7(mint_fee || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals));
|
|
6933
|
+
result.fees.bridgeFeeUsd = numberRemoveEndZero(Big7(bridge_fee || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals));
|
|
6309
6934
|
const chargedAmount = BigInt(amountWei) - BigInt(mint_fee);
|
|
6310
|
-
result.outputAmount = numberRemoveEndZero(
|
|
6935
|
+
result.outputAmount = numberRemoveEndZero(Big7(receipt_amount || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0));
|
|
6311
6936
|
const depositParam = [
|
|
6312
6937
|
// originalAmount
|
|
6313
6938
|
amountWei,
|
|
@@ -6316,11 +6941,11 @@ var EVMWallet = class {
|
|
|
6316
6941
|
// destinationDomain
|
|
6317
6942
|
destinationDomain,
|
|
6318
6943
|
// mintRecipient
|
|
6319
|
-
|
|
6944
|
+
addressToBytes322(toToken.chainType, realRecipient),
|
|
6320
6945
|
// burnToken
|
|
6321
6946
|
fromToken.contractAddress,
|
|
6322
6947
|
// destinationCaller
|
|
6323
|
-
destination_caller ?
|
|
6948
|
+
destination_caller ? addressToBytes322(toToken.chainType, destination_caller) : "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
6324
6949
|
// maxFee
|
|
6325
6950
|
max_fee,
|
|
6326
6951
|
// minFinalityThreshold
|
|
@@ -6382,9 +7007,9 @@ var EVMWallet = class {
|
|
|
6382
7007
|
if (excludeFees4.includes(feeKey) || !/Usd$/.test(feeKey)) {
|
|
6383
7008
|
continue;
|
|
6384
7009
|
}
|
|
6385
|
-
result.totalFeesUsd =
|
|
7010
|
+
result.totalFeesUsd = Big7(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
|
|
6386
7011
|
}
|
|
6387
|
-
result.totalFeesUsd = numberRemoveEndZero(
|
|
7012
|
+
result.totalFeesUsd = numberRemoveEndZero(Big7(result.totalFeesUsd).toFixed(20));
|
|
6388
7013
|
return result;
|
|
6389
7014
|
}
|
|
6390
7015
|
async quoteOneClickProxy(params) {
|
|
@@ -6410,7 +7035,7 @@ var EVMWallet = class {
|
|
|
6410
7035
|
} catch (error) {
|
|
6411
7036
|
console.log("oneclick check allowance failed: %o", error);
|
|
6412
7037
|
}
|
|
6413
|
-
const proxyContract = new
|
|
7038
|
+
const proxyContract = new ethers4.Contract(proxyAddress, abi, this.signer);
|
|
6414
7039
|
const proxyParam = [
|
|
6415
7040
|
// tokenAddress
|
|
6416
7041
|
fromToken.contractAddress,
|
|
@@ -6428,18 +7053,18 @@ var EVMWallet = class {
|
|
|
6428
7053
|
price: getPrice(prices, fromToken.nativeToken.symbol),
|
|
6429
7054
|
nativeToken: fromToken.nativeToken
|
|
6430
7055
|
});
|
|
6431
|
-
result.fees.sourceGasFeeUsd = numberRemoveEndZero(
|
|
7056
|
+
result.fees.sourceGasFeeUsd = numberRemoveEndZero(Big7(usd).toFixed(20));
|
|
6432
7057
|
result.estimateSourceGas = wei;
|
|
6433
|
-
result.estimateSourceGasUsd = numberRemoveEndZero(
|
|
7058
|
+
result.estimateSourceGasUsd = numberRemoveEndZero(Big7(usd).toFixed(20));
|
|
6434
7059
|
} catch (error) {
|
|
6435
7060
|
const { usd, wei } = await this.getEstimateGas({
|
|
6436
7061
|
gasLimit: DEFAULT_GAS_LIMIT,
|
|
6437
7062
|
price: getPrice(prices, fromToken.nativeToken.symbol),
|
|
6438
7063
|
nativeToken: fromToken.nativeToken
|
|
6439
7064
|
});
|
|
6440
|
-
result.fees.sourceGasFeeUsd = numberRemoveEndZero(
|
|
7065
|
+
result.fees.sourceGasFeeUsd = numberRemoveEndZero(Big7(usd).toFixed(20));
|
|
6441
7066
|
result.estimateSourceGas = wei;
|
|
6442
|
-
result.estimateSourceGasUsd = numberRemoveEndZero(
|
|
7067
|
+
result.estimateSourceGasUsd = numberRemoveEndZero(Big7(usd).toFixed(20));
|
|
6443
7068
|
}
|
|
6444
7069
|
result.sendParam = {
|
|
6445
7070
|
method: "proxyTransfer",
|
|
@@ -6451,27 +7076,50 @@ var EVMWallet = class {
|
|
|
6451
7076
|
};
|
|
6452
7077
|
return result;
|
|
6453
7078
|
}
|
|
7079
|
+
async signTypedData(params) {
|
|
7080
|
+
const { domain, types, values } = params;
|
|
7081
|
+
return await this.signer?.signTypedData(domain, types, values);
|
|
7082
|
+
}
|
|
6454
7083
|
};
|
|
6455
7084
|
|
|
6456
7085
|
// src/wallets/tron.ts
|
|
6457
|
-
import { Options as
|
|
6458
|
-
import { ethers as
|
|
6459
|
-
import
|
|
7086
|
+
import { Options as Options3 } from "@layerzerolabs/lz-v2-utilities";
|
|
7087
|
+
import { ethers as ethers5 } from "ethers";
|
|
7088
|
+
import Big8 from "big.js";
|
|
6460
7089
|
import { TronWeb } from "tronweb";
|
|
7090
|
+
var DefaultTronWalletAddress = DefaultAddresses["tron"];
|
|
7091
|
+
var getCustomTronWeb = () => {
|
|
7092
|
+
return new TronWeb({
|
|
7093
|
+
fullHost: getRpcUrls("tron")[0],
|
|
7094
|
+
headers: {},
|
|
7095
|
+
privateKey: ""
|
|
7096
|
+
});
|
|
7097
|
+
};
|
|
6461
7098
|
var TronWallet = class {
|
|
6462
7099
|
constructor(options) {
|
|
6463
7100
|
this.signAndSendTransaction = options.signAndSendTransaction;
|
|
6464
|
-
this.
|
|
7101
|
+
this.address = options.address;
|
|
7102
|
+
const customTronWeb = getCustomTronWeb();
|
|
7103
|
+
customTronWeb.setAddress(this.address || DefaultTronWalletAddress);
|
|
7104
|
+
this.tronWeb = customTronWeb;
|
|
6465
7105
|
}
|
|
6466
7106
|
async waitForTronWeb() {
|
|
6467
|
-
return new Promise((resolve2
|
|
7107
|
+
return new Promise((resolve2) => {
|
|
6468
7108
|
if (this.tronWeb) {
|
|
7109
|
+
const address = this.tronWeb.defaultAddress.base58 || DefaultTronWalletAddress;
|
|
7110
|
+
const customTronWeb = getCustomTronWeb();
|
|
7111
|
+
customTronWeb.setAddress(address);
|
|
7112
|
+
this.tronWeb = customTronWeb;
|
|
6469
7113
|
resolve2(this.tronWeb);
|
|
6470
7114
|
return;
|
|
6471
7115
|
}
|
|
6472
7116
|
const checkTronWeb = () => {
|
|
6473
7117
|
if (window.tronWeb) {
|
|
6474
7118
|
this.tronWeb = window.tronWeb;
|
|
7119
|
+
const address = this.tronWeb.defaultAddress.base58 || DefaultTronWalletAddress;
|
|
7120
|
+
const customTronWeb = getCustomTronWeb();
|
|
7121
|
+
customTronWeb.setAddress(address);
|
|
7122
|
+
this.tronWeb = customTronWeb;
|
|
6475
7123
|
resolve2(this.tronWeb);
|
|
6476
7124
|
} else {
|
|
6477
7125
|
setTimeout(checkTronWeb, 100);
|
|
@@ -6479,12 +7127,9 @@ var TronWallet = class {
|
|
|
6479
7127
|
};
|
|
6480
7128
|
checkTronWeb();
|
|
6481
7129
|
setTimeout(() => {
|
|
6482
|
-
|
|
6483
|
-
|
|
6484
|
-
|
|
6485
|
-
privateKey: ""
|
|
6486
|
-
});
|
|
6487
|
-
this.tronWeb.setAddress(DefaultAddresses["tron"]);
|
|
7130
|
+
const customTronWeb = getCustomTronWeb();
|
|
7131
|
+
customTronWeb.setAddress(DefaultTronWalletAddress);
|
|
7132
|
+
this.tronWeb = customTronWeb;
|
|
6488
7133
|
resolve2(this.tronWeb);
|
|
6489
7134
|
console.log(new Error("TronWeb initialization timeout"));
|
|
6490
7135
|
}, 1e4);
|
|
@@ -6548,10 +7193,10 @@ var TronWallet = class {
|
|
|
6548
7193
|
return await this.getBalance(token, account);
|
|
6549
7194
|
}
|
|
6550
7195
|
/**
|
|
6551
|
-
|
|
6552
|
-
|
|
6553
|
-
|
|
6554
|
-
|
|
7196
|
+
* Estimate gas limit for transfer transaction
|
|
7197
|
+
* @param data Transfer data
|
|
7198
|
+
* @returns Gas limit estimate (bandwidth or energy), gas price, and estimated gas cost
|
|
7199
|
+
*/
|
|
6555
7200
|
async estimateTransferGas(data) {
|
|
6556
7201
|
const { originAsset } = data;
|
|
6557
7202
|
await this.waitForTronWeb();
|
|
@@ -6562,14 +7207,7 @@ var TronWallet = class {
|
|
|
6562
7207
|
gasLimit = 30000n;
|
|
6563
7208
|
}
|
|
6564
7209
|
gasLimit = gasLimit * 120n / 100n;
|
|
6565
|
-
let gasPrice;
|
|
6566
|
-
try {
|
|
6567
|
-
const chainParameters = await this.tronWeb.trx.getChainParameters();
|
|
6568
|
-
const energyPrice = chainParameters?.find((p) => p.key === "getEnergyFee")?.value || 420;
|
|
6569
|
-
gasPrice = BigInt(energyPrice);
|
|
6570
|
-
} catch (error) {
|
|
6571
|
-
gasPrice = 420n;
|
|
6572
|
-
}
|
|
7210
|
+
let gasPrice = 100n;
|
|
6573
7211
|
const estimateGas = gasLimit * gasPrice;
|
|
6574
7212
|
return {
|
|
6575
7213
|
gasLimit,
|
|
@@ -6589,6 +7227,15 @@ var TronWallet = class {
|
|
|
6589
7227
|
return false;
|
|
6590
7228
|
}
|
|
6591
7229
|
}
|
|
7230
|
+
async getTransactionResult(txHash) {
|
|
7231
|
+
await this.waitForTronWeb();
|
|
7232
|
+
try {
|
|
7233
|
+
const txInfo = await this.tronWeb.trx.getTransactionInfo(txHash);
|
|
7234
|
+
return txInfo;
|
|
7235
|
+
} catch (error) {
|
|
7236
|
+
return {};
|
|
7237
|
+
}
|
|
7238
|
+
}
|
|
6592
7239
|
async allowance(params) {
|
|
6593
7240
|
const {
|
|
6594
7241
|
contractAddress,
|
|
@@ -6609,7 +7256,7 @@ var TronWallet = class {
|
|
|
6609
7256
|
return {
|
|
6610
7257
|
contract,
|
|
6611
7258
|
allowance,
|
|
6612
|
-
needApprove:
|
|
7259
|
+
needApprove: Big8(amountWei || 0).gt(allowance || 0)
|
|
6613
7260
|
};
|
|
6614
7261
|
} catch (error) {
|
|
6615
7262
|
console.log("Error in allowance: %o", error);
|
|
@@ -6656,14 +7303,7 @@ var TronWallet = class {
|
|
|
6656
7303
|
}
|
|
6657
7304
|
async getEnergyPrice() {
|
|
6658
7305
|
await this.waitForTronWeb();
|
|
6659
|
-
let energyFee =
|
|
6660
|
-
try {
|
|
6661
|
-
const params = await this.tronWeb.trx.getChainParameters();
|
|
6662
|
-
energyFee = params.find((p) => p.key === "getEnergyFee")?.value || 280;
|
|
6663
|
-
console.log("Energy Fee:", energyFee, "Sun/Energy");
|
|
6664
|
-
} catch (err) {
|
|
6665
|
-
console.error("Error getting energy price:", err);
|
|
6666
|
-
}
|
|
7306
|
+
let energyFee = 100;
|
|
6667
7307
|
return energyFee;
|
|
6668
7308
|
}
|
|
6669
7309
|
toBytes32(addr) {
|
|
@@ -6686,9 +7326,10 @@ var TronWallet = class {
|
|
|
6686
7326
|
excludeFees: excludeFees4,
|
|
6687
7327
|
refundTo,
|
|
6688
7328
|
multiHopComposer,
|
|
6689
|
-
isMultiHopComposer
|
|
6690
|
-
|
|
6691
|
-
|
|
7329
|
+
isMultiHopComposer,
|
|
7330
|
+
isOriginLegacy,
|
|
7331
|
+
isDestinationLegacy,
|
|
7332
|
+
originLayerzero
|
|
6692
7333
|
} = params;
|
|
6693
7334
|
const result = {
|
|
6694
7335
|
needApprove: false,
|
|
@@ -6705,12 +7346,11 @@ var TronWallet = class {
|
|
|
6705
7346
|
estimateSourceGasUsd: void 0,
|
|
6706
7347
|
estimateTime: 0,
|
|
6707
7348
|
// seconds - dynamically calculated using LayerZero formula
|
|
6708
|
-
outputAmount: numberRemoveEndZero(
|
|
7349
|
+
outputAmount: numberRemoveEndZero(Big8(amountWei || 0).div(10 ** params.fromToken.decimals).toFixed(params.fromToken.decimals, 0))
|
|
6709
7350
|
};
|
|
6710
7351
|
await this.waitForTronWeb();
|
|
6711
7352
|
const oftContract = await this.tronWeb.contract(abi, originLayerzeroAddress);
|
|
6712
7353
|
const approvalRequired = await oftContract.approvalRequired().call();
|
|
6713
|
-
console.log("%cApprovalRequired: %o", "background:blue;color:white;", result.needApprove);
|
|
6714
7354
|
if (approvalRequired) {
|
|
6715
7355
|
try {
|
|
6716
7356
|
const userAddress = refundTo || this.tronWeb.defaultAddress.base58;
|
|
@@ -6725,18 +7365,27 @@ var TronWallet = class {
|
|
|
6725
7365
|
console.log("Error checking allowance: %o", error);
|
|
6726
7366
|
}
|
|
6727
7367
|
}
|
|
7368
|
+
const lzReceiveOptionGas = isOriginLegacy ? originLayerzero.lzReceiveOptionGasLegacy : originLayerzero.lzReceiveOptionGas;
|
|
7369
|
+
let lzReceiveOptionValue = 0;
|
|
7370
|
+
const destATA = await getDestinationAssociatedTokenAddress({
|
|
7371
|
+
recipient,
|
|
7372
|
+
toToken
|
|
7373
|
+
});
|
|
7374
|
+
if (destATA.needCreateTokenAccount) {
|
|
7375
|
+
lzReceiveOptionValue = LZ_RECEIVE_VALUE[toToken.chainName] || 0;
|
|
7376
|
+
}
|
|
6728
7377
|
const sendParam = [
|
|
6729
7378
|
// dstEid
|
|
6730
7379
|
dstEid,
|
|
6731
7380
|
// to
|
|
6732
7381
|
// "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
6733
|
-
|
|
7382
|
+
addressToBytes322(toToken.chainType, recipient),
|
|
6734
7383
|
// amountLD
|
|
6735
7384
|
amountWei,
|
|
6736
7385
|
// minAmountLD
|
|
6737
7386
|
"0",
|
|
6738
7387
|
// extraOptions
|
|
6739
|
-
|
|
7388
|
+
Options3.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).toHex(),
|
|
6740
7389
|
// composeMsg
|
|
6741
7390
|
"0x",
|
|
6742
7391
|
// oftCmd
|
|
@@ -6744,71 +7393,63 @@ var TronWallet = class {
|
|
|
6744
7393
|
];
|
|
6745
7394
|
if (isMultiHopComposer) {
|
|
6746
7395
|
sendParam[0] = multiHopComposer.eid;
|
|
6747
|
-
sendParam[1] =
|
|
7396
|
+
sendParam[1] = addressToBytes322("evm", multiHopComposer.oftMultiHopComposer);
|
|
6748
7397
|
}
|
|
6749
7398
|
const oftData = await oftContract.quoteOFT(sendParam).call();
|
|
6750
|
-
console.log("oftData: %o", oftData);
|
|
6751
7399
|
const [, , oftReceipt] = oftData;
|
|
6752
|
-
sendParam[3] =
|
|
7400
|
+
sendParam[3] = Big8(oftReceipt[1].toString()).times(Big8(1).minus(Big8(slippageTolerance || 0).div(100))).toFixed(0);
|
|
6753
7401
|
const msgFee = await oftContract.quoteSend(sendParam, payInLzToken).call();
|
|
6754
|
-
|
|
7402
|
+
let nativeMsgFee = msgFee[0]["nativeFee"];
|
|
7403
|
+
if (nativeMsgFee) {
|
|
7404
|
+
nativeMsgFee = BigInt(Big8(nativeMsgFee.toString()).times(1.2).toFixed(0));
|
|
7405
|
+
}
|
|
7406
|
+
result.estimateSourceGas = nativeMsgFee;
|
|
6755
7407
|
if (isMultiHopComposer) {
|
|
6756
|
-
|
|
6757
|
-
|
|
7408
|
+
const composeMsgSendParam = {
|
|
7409
|
+
dstEid,
|
|
7410
|
+
to: addressToBytes322(toToken.chainType, recipient),
|
|
7411
|
+
amountLD: sendParam[2],
|
|
7412
|
+
minAmountLD: sendParam[3],
|
|
7413
|
+
extraOptions: Options3.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).toHex(),
|
|
7414
|
+
composeMsg: "0x",
|
|
7415
|
+
oftCmd: "0x"
|
|
7416
|
+
};
|
|
7417
|
+
const hopMsgFee = await getHopMsgFee({
|
|
7418
|
+
sendParam: composeMsgSendParam,
|
|
7419
|
+
toToken
|
|
7420
|
+
});
|
|
7421
|
+
sendParam[4] = Options3.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).addExecutorComposeOption(0, originLayerzero.composeOptionGas || 8e5, hopMsgFee).toHex();
|
|
7422
|
+
const abiCoder = ethers5.AbiCoder.defaultAbiCoder();
|
|
6758
7423
|
sendParam[5] = abiCoder.encode(
|
|
6759
7424
|
["tuple(uint32 dstEid, bytes32 to, uint256 amountLD, uint256 minAmountLD, bytes extraOptions, bytes composeMsg, bytes oftCmd)"],
|
|
6760
|
-
[
|
|
6761
|
-
dstEid,
|
|
6762
|
-
addressToBytes32(toToken.chainType, recipient),
|
|
6763
|
-
sendParam[2],
|
|
6764
|
-
// amountLD
|
|
6765
|
-
sendParam[3],
|
|
6766
|
-
// minAmountLD
|
|
6767
|
-
"0x",
|
|
6768
|
-
"0x",
|
|
6769
|
-
"0x"
|
|
6770
|
-
]]
|
|
7425
|
+
[Object.values(composeMsgSendParam)]
|
|
6771
7426
|
);
|
|
6772
7427
|
}
|
|
6773
|
-
console.log("%cMsgFee: %o", "background:blue;color:white;", msgFee);
|
|
6774
7428
|
result.sendParam = {
|
|
6775
|
-
contract: oftContract,
|
|
6776
7429
|
param: [
|
|
6777
7430
|
// sendParam
|
|
6778
7431
|
sendParam,
|
|
6779
7432
|
// feeParam
|
|
6780
7433
|
[
|
|
6781
7434
|
// nativeFee
|
|
6782
|
-
|
|
7435
|
+
nativeMsgFee.toString(),
|
|
6783
7436
|
// lzTokenFee
|
|
6784
7437
|
msgFee[0]["lzTokenFee"].toString()
|
|
6785
7438
|
],
|
|
6786
7439
|
// refundAddress
|
|
6787
7440
|
refundTo
|
|
6788
7441
|
],
|
|
6789
|
-
options: { callValue:
|
|
7442
|
+
options: { callValue: nativeMsgFee.toString() }
|
|
6790
7443
|
};
|
|
6791
|
-
|
|
6792
|
-
|
|
6793
|
-
result.fees.nativeFeeUsd = numberRemoveEndZero(
|
|
6794
|
-
result.fees.lzTokenFeeUsd = numberRemoveEndZero(
|
|
6795
|
-
|
|
6796
|
-
|
|
6797
|
-
|
|
6798
|
-
|
|
6799
|
-
|
|
6800
|
-
result.estimateSourceGasUsd = usd;
|
|
6801
|
-
} catch (error) {
|
|
6802
|
-
console.log("usdt0 estimate gas failed: %o", error);
|
|
6803
|
-
}
|
|
6804
|
-
for (const feeKey in result.fees) {
|
|
6805
|
-
if (excludeFees4.includes(feeKey)) {
|
|
6806
|
-
continue;
|
|
6807
|
-
}
|
|
6808
|
-
result.totalFeesUsd = Big6(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
|
|
6809
|
-
}
|
|
6810
|
-
result.totalFeesUsd = numberRemoveEndZero(Big6(result.totalFeesUsd).toFixed(20));
|
|
6811
|
-
const tx = await this.tronWeb.transactionBuilder.triggerSmartContract(
|
|
7444
|
+
const nativeFeeUsd = Big8(nativeMsgFee?.toString() || 0).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
|
|
7445
|
+
result.fees.nativeFee = numberRemoveEndZero(Big8(nativeMsgFee?.toString() || 0).div(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals));
|
|
7446
|
+
result.fees.nativeFeeUsd = numberRemoveEndZero(Big8(nativeFeeUsd).toFixed(20));
|
|
7447
|
+
result.fees.lzTokenFeeUsd = numberRemoveEndZero(Big8(msgFee[0]["lzTokenFee"]?.toString() || 0).div(10 ** fromToken.decimals).toFixed(20));
|
|
7448
|
+
if (isOriginLegacy || isDestinationLegacy) {
|
|
7449
|
+
result.fees.legacyMeshFeeUsd = numberRemoveEndZero(Big8(amountWei || 0).div(10 ** fromToken.decimals).times(USDT0_LEGACY_MESH_TRANSFTER_FEE).toFixed(fromToken.decimals));
|
|
7450
|
+
result.outputAmount = numberRemoveEndZero(Big8(Big8(amountWei || 0).div(10 ** params.fromToken.decimals)).minus(result.fees.legacyMeshFeeUsd || 0).toFixed(params.fromToken.decimals, 0));
|
|
7451
|
+
}
|
|
7452
|
+
const transactionParams = [
|
|
6812
7453
|
originLayerzeroAddress,
|
|
6813
7454
|
"send((uint32,bytes32,uint256,uint256,bytes,bytes,bytes),(uint256,uint256),address)",
|
|
6814
7455
|
result.sendParam.options,
|
|
@@ -6826,9 +7467,41 @@ var TronWallet = class {
|
|
|
6826
7467
|
value: result.sendParam.param[2]
|
|
6827
7468
|
}
|
|
6828
7469
|
],
|
|
6829
|
-
this.tronWeb.defaultAddress.base58
|
|
6830
|
-
|
|
7470
|
+
this.tronWeb.defaultAddress.base58 || refundTo
|
|
7471
|
+
];
|
|
7472
|
+
const energyPrice = await this.getEnergyPrice();
|
|
7473
|
+
const tx = await this.tronWeb.transactionBuilder.triggerSmartContract(...transactionParams);
|
|
6831
7474
|
result.sendParam.tx = tx;
|
|
7475
|
+
try {
|
|
7476
|
+
const transaction = await this.tronWeb.transactionBuilder.triggerConstantContract(...transactionParams);
|
|
7477
|
+
const energyUsed = transaction.energy_used || 2e5;
|
|
7478
|
+
const rawDataHexLength = transaction.transaction.raw_data_hex.length || 1e3;
|
|
7479
|
+
const bandwidthAmount = (rawDataHexLength / 2 + DATA_HEX_PROTOBUF_EXTRA + SIGNATURE_SIZE) * 1e-3;
|
|
7480
|
+
const amount = Big8(energyUsed || 0).times(energyPrice).div(10 ** fromToken.nativeToken.decimals);
|
|
7481
|
+
const totalAmount = Big8(amount).plus(bandwidthAmount);
|
|
7482
|
+
const usd = numberRemoveEndZero(Big8(totalAmount).times(getPrice(prices, fromToken.nativeToken.symbol)).toFixed(20));
|
|
7483
|
+
result.fees.estimateGasUsd = usd;
|
|
7484
|
+
result.estimateSourceGas = numberRemoveEndZero(Big8(totalAmount).times(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals));
|
|
7485
|
+
result.estimateSourceGasUsd = usd;
|
|
7486
|
+
} catch (error) {
|
|
7487
|
+
const energyUsed = 2e5;
|
|
7488
|
+
const rawDataHexLength = 1e3;
|
|
7489
|
+
const bandwidthAmount = (rawDataHexLength / 2 + DATA_HEX_PROTOBUF_EXTRA + SIGNATURE_SIZE) * 1e-3;
|
|
7490
|
+
const amount = Big8(energyUsed || 0).times(energyPrice).div(10 ** fromToken.nativeToken.decimals);
|
|
7491
|
+
const totalAmount = Big8(amount).plus(bandwidthAmount);
|
|
7492
|
+
const usd = numberRemoveEndZero(Big8(totalAmount).times(getPrice(prices, fromToken.nativeToken.symbol)).toFixed(20));
|
|
7493
|
+
result.fees.estimateGasUsd = usd;
|
|
7494
|
+
result.estimateSourceGas = numberRemoveEndZero(Big8(totalAmount).times(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals));
|
|
7495
|
+
result.estimateSourceGasUsd = usd;
|
|
7496
|
+
}
|
|
7497
|
+
for (const feeKey in result.fees) {
|
|
7498
|
+
if (excludeFees4.includes(feeKey) || !/Usd$/.test(feeKey)) {
|
|
7499
|
+
continue;
|
|
7500
|
+
}
|
|
7501
|
+
result.totalFeesUsd = Big8(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
|
|
7502
|
+
}
|
|
7503
|
+
result.totalFeesUsd = numberRemoveEndZero(Big8(result.totalFeesUsd).toFixed(20));
|
|
7504
|
+
result.sendParam.transactionParams = transactionParams;
|
|
6832
7505
|
return result;
|
|
6833
7506
|
}
|
|
6834
7507
|
async sendTransaction(params) {
|
|
@@ -6837,7 +7510,6 @@ var TronWallet = class {
|
|
|
6837
7510
|
} = params;
|
|
6838
7511
|
const result = await this.signAndSendTransaction(tx.transaction);
|
|
6839
7512
|
if (typeof result === "object" && result.message) {
|
|
6840
|
-
console.log("%cTron send transaction message: %o", "background:#f00;color:#fff;", result.message);
|
|
6841
7513
|
if (/user rejected the transaction/i.test(result.message)) {
|
|
6842
7514
|
throw new Error("User rejected the transaction");
|
|
6843
7515
|
}
|
|
@@ -6902,7 +7574,6 @@ var TronWallet = class {
|
|
|
6902
7574
|
} catch (error) {
|
|
6903
7575
|
console.log("oneclick check allowance failed: %o", error);
|
|
6904
7576
|
}
|
|
6905
|
-
const proxyContract = await this.tronWeb.contract(abi, proxyAddress);
|
|
6906
7577
|
const proxyParam = [
|
|
6907
7578
|
// tokenAddress
|
|
6908
7579
|
fromToken.contractAddress,
|
|
@@ -6912,22 +7583,9 @@ var TronWallet = class {
|
|
|
6912
7583
|
amountWei
|
|
6913
7584
|
];
|
|
6914
7585
|
result.sendParam = {
|
|
6915
|
-
contract: proxyContract,
|
|
6916
7586
|
param: proxyParam
|
|
6917
7587
|
};
|
|
6918
|
-
|
|
6919
|
-
const gasLimit = 30000n;
|
|
6920
|
-
const energyPrice = await this.getEnergyPrice();
|
|
6921
|
-
const gasPrice = BigInt(energyPrice);
|
|
6922
|
-
const estimateGas = gasLimit * gasPrice;
|
|
6923
|
-
const estimateGasUsd = Big6(estimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
|
|
6924
|
-
result.fees.sourceGasFeeUsd = numberRemoveEndZero(Big6(estimateGasUsd).toFixed(20));
|
|
6925
|
-
result.estimateSourceGas = estimateGas.toString();
|
|
6926
|
-
result.estimateSourceGasUsd = numberRemoveEndZero(Big6(estimateGasUsd).toFixed(20));
|
|
6927
|
-
} catch (error) {
|
|
6928
|
-
console.log("onclick estimate proxy failed: %o", error);
|
|
6929
|
-
}
|
|
6930
|
-
const tx = await this.tronWeb.transactionBuilder.triggerSmartContract(
|
|
7588
|
+
const transactionParams = [
|
|
6931
7589
|
proxyAddress,
|
|
6932
7590
|
"proxyTransfer(address,address,uint256)",
|
|
6933
7591
|
{},
|
|
@@ -6948,20 +7606,99 @@ var TronWallet = class {
|
|
|
6948
7606
|
// amount
|
|
6949
7607
|
}
|
|
6950
7608
|
],
|
|
6951
|
-
this.tronWeb.defaultAddress.base58
|
|
6952
|
-
|
|
7609
|
+
this.tronWeb.defaultAddress.base58 || refundTo
|
|
7610
|
+
];
|
|
7611
|
+
const energyPrice = await this.getEnergyPrice();
|
|
7612
|
+
const tx = await this.tronWeb.transactionBuilder.triggerSmartContract(...transactionParams);
|
|
6953
7613
|
result.sendParam.tx = tx;
|
|
7614
|
+
try {
|
|
7615
|
+
const transaction = await this.tronWeb.transactionBuilder.triggerConstantContract(...transactionParams);
|
|
7616
|
+
const energyUsed = transaction.energy_used || 3e4;
|
|
7617
|
+
const rawDataHexLength = transaction.transaction.raw_data_hex.length || 500;
|
|
7618
|
+
const bandwidthAmount = (rawDataHexLength / 2 + DATA_HEX_PROTOBUF_EXTRA + SIGNATURE_SIZE) * 1e-3;
|
|
7619
|
+
const amount = Big8(energyUsed || 0).times(energyPrice).div(10 ** fromToken.nativeToken.decimals);
|
|
7620
|
+
const totalAmount = Big8(amount).plus(bandwidthAmount);
|
|
7621
|
+
const usd = numberRemoveEndZero(Big8(totalAmount).times(getPrice(prices, fromToken.nativeToken.symbol)).toFixed(20));
|
|
7622
|
+
result.fees.sourceGasFeeUsd = usd;
|
|
7623
|
+
result.estimateSourceGas = numberRemoveEndZero(Big8(totalAmount).times(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals));
|
|
7624
|
+
result.estimateSourceGasUsd = usd;
|
|
7625
|
+
} catch (error) {
|
|
7626
|
+
const energyUsed = 169e3;
|
|
7627
|
+
const rawDataHexLength = 500;
|
|
7628
|
+
const bandwidthAmount = (rawDataHexLength / 2 + DATA_HEX_PROTOBUF_EXTRA + SIGNATURE_SIZE) * 1e-3;
|
|
7629
|
+
const amount = Big8(energyUsed || 0).times(energyPrice).div(10 ** fromToken.nativeToken.decimals);
|
|
7630
|
+
const totalAmount = Big8(amount).plus(bandwidthAmount);
|
|
7631
|
+
const usd = numberRemoveEndZero(Big8(totalAmount).times(getPrice(prices, fromToken.nativeToken.symbol)).toFixed(20));
|
|
7632
|
+
result.fees.estimateGasUsd = usd;
|
|
7633
|
+
result.estimateSourceGas = numberRemoveEndZero(Big8(totalAmount).times(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals));
|
|
7634
|
+
result.estimateSourceGasUsd = usd;
|
|
7635
|
+
}
|
|
7636
|
+
result.sendParam.transactionParams = transactionParams;
|
|
7637
|
+
return result;
|
|
7638
|
+
}
|
|
7639
|
+
async getAccountResources(params) {
|
|
7640
|
+
const { account } = params;
|
|
7641
|
+
const result = {
|
|
7642
|
+
energy: 0,
|
|
7643
|
+
bandwidth: 0,
|
|
7644
|
+
success: false,
|
|
7645
|
+
error: "TronWeb is not initialized or the wallet is not connected"
|
|
7646
|
+
};
|
|
7647
|
+
await this.waitForTronWeb();
|
|
7648
|
+
if (!this.tronWeb || !account) {
|
|
7649
|
+
return result;
|
|
7650
|
+
}
|
|
7651
|
+
try {
|
|
7652
|
+
let availableEnergy;
|
|
7653
|
+
let availableBandwidth;
|
|
7654
|
+
try {
|
|
7655
|
+
if (this.tronWeb.trx.getAccountResources) {
|
|
7656
|
+
const resources = await this.tronWeb.trx.getAccountResources(account);
|
|
7657
|
+
console.log("resources: %o", resources);
|
|
7658
|
+
if (resources) {
|
|
7659
|
+
availableEnergy = (resources.EnergyLimit || 0) - (resources.EnergyUsed || 0);
|
|
7660
|
+
availableBandwidth = (resources.freeNetLimit || 0) - (resources.freeNetUsed || 0);
|
|
7661
|
+
}
|
|
7662
|
+
}
|
|
7663
|
+
} catch (resourcesErr) {
|
|
7664
|
+
console.warn("getAccountResources API is not available, try other way:", resourcesErr);
|
|
7665
|
+
}
|
|
7666
|
+
if (availableEnergy === void 0 && availableBandwidth === void 0) {
|
|
7667
|
+
const accountInfo = await this.tronWeb.trx.getAccount(account);
|
|
7668
|
+
if (accountInfo.account_resource) {
|
|
7669
|
+
const accountResource = accountInfo.account_resource;
|
|
7670
|
+
availableEnergy = (accountResource.EnergyLimit || 0) - (accountResource.EnergyUsed || 0);
|
|
7671
|
+
availableBandwidth = (accountResource.NetLimit || 0) - (accountResource.NetUsed || 0);
|
|
7672
|
+
} else if (accountInfo.energy !== void 0) {
|
|
7673
|
+
availableEnergy = accountInfo.energy || 0;
|
|
7674
|
+
}
|
|
7675
|
+
if (accountInfo.bandwidth !== void 0) {
|
|
7676
|
+
if (typeof accountInfo.bandwidth === "number") {
|
|
7677
|
+
availableBandwidth = accountInfo.bandwidth;
|
|
7678
|
+
} else if (accountInfo.bandwidth) {
|
|
7679
|
+
availableBandwidth = accountInfo.bandwidth.available || accountInfo.bandwidth.freeNetUsage || 0;
|
|
7680
|
+
}
|
|
7681
|
+
}
|
|
7682
|
+
}
|
|
7683
|
+
result.energy = Math.max(0, availableEnergy);
|
|
7684
|
+
result.bandwidth = Math.max(0, availableBandwidth);
|
|
7685
|
+
result.success = true;
|
|
7686
|
+
result.error = null;
|
|
7687
|
+
} catch (error) {
|
|
7688
|
+
console.error("Failed to get account resources:", error);
|
|
7689
|
+
}
|
|
6954
7690
|
return result;
|
|
6955
7691
|
}
|
|
6956
7692
|
};
|
|
6957
7693
|
|
|
6958
7694
|
// src/wallets/aptos.ts
|
|
6959
7695
|
import { Aptos, AptosConfig, Network, parseTypeTag, TypeTagAddress, TypeTagU64 } from "@aptos-labs/ts-sdk";
|
|
6960
|
-
import
|
|
7696
|
+
import Big9 from "big.js";
|
|
6961
7697
|
var AptosWallet = class {
|
|
6962
7698
|
constructor(options) {
|
|
6963
7699
|
const config = new AptosConfig({
|
|
6964
|
-
network: Network.MAINNET
|
|
7700
|
+
network: Network.MAINNET,
|
|
7701
|
+
fullnode: getRpcUrls("aptos")[0]
|
|
6965
7702
|
});
|
|
6966
7703
|
const aptos = new Aptos(config);
|
|
6967
7704
|
this.aptos = aptos;
|
|
@@ -7265,10 +8002,10 @@ var AptosWallet = class {
|
|
|
7265
8002
|
const defaultGasLimit = 5000n;
|
|
7266
8003
|
const defaultGasPrice = 100n;
|
|
7267
8004
|
const defaultEstimateGas = defaultGasLimit * defaultGasPrice;
|
|
7268
|
-
const estimateGasUsd2 =
|
|
7269
|
-
result.fees.sourceGasFeeUsd = numberRemoveEndZero(
|
|
8005
|
+
const estimateGasUsd2 = Big9(defaultEstimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
|
|
8006
|
+
result.fees.sourceGasFeeUsd = numberRemoveEndZero(Big9(estimateGasUsd2).toFixed(20));
|
|
7270
8007
|
result.estimateSourceGas = defaultEstimateGas.toString();
|
|
7271
|
-
result.estimateSourceGasUsd = numberRemoveEndZero(
|
|
8008
|
+
result.estimateSourceGasUsd = numberRemoveEndZero(Big9(estimateGasUsd2).toFixed(20));
|
|
7272
8009
|
result.sendParam = {
|
|
7273
8010
|
function: functionId,
|
|
7274
8011
|
typeArguments: [typeArgument],
|
|
@@ -7281,10 +8018,10 @@ var AptosWallet = class {
|
|
|
7281
8018
|
const defaultGasLimit = 5000n;
|
|
7282
8019
|
const defaultGasPrice = 100n;
|
|
7283
8020
|
const defaultEstimateGas = defaultGasLimit * defaultGasPrice;
|
|
7284
|
-
const estimateGasUsd2 =
|
|
7285
|
-
result.fees.sourceGasFeeUsd = numberRemoveEndZero(
|
|
8021
|
+
const estimateGasUsd2 = Big9(defaultEstimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
|
|
8022
|
+
result.fees.sourceGasFeeUsd = numberRemoveEndZero(Big9(estimateGasUsd2).toFixed(20));
|
|
7286
8023
|
result.estimateSourceGas = defaultEstimateGas.toString();
|
|
7287
|
-
result.estimateSourceGasUsd = numberRemoveEndZero(
|
|
8024
|
+
result.estimateSourceGasUsd = numberRemoveEndZero(Big9(estimateGasUsd2).toFixed(20));
|
|
7288
8025
|
result.sendParam = {
|
|
7289
8026
|
function: functionId,
|
|
7290
8027
|
typeArguments: [typeArgument],
|
|
@@ -7296,10 +8033,10 @@ var AptosWallet = class {
|
|
|
7296
8033
|
const gasLimit = gasUsed * 150n / 100n;
|
|
7297
8034
|
const gasPrice = BigInt(simulation.gas_unit_price || 100);
|
|
7298
8035
|
const estimateGas = gasLimit * gasPrice;
|
|
7299
|
-
const estimateGasUsd =
|
|
7300
|
-
result.fees.sourceGasFeeUsd = numberRemoveEndZero(
|
|
8036
|
+
const estimateGasUsd = Big9(estimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
|
|
8037
|
+
result.fees.sourceGasFeeUsd = numberRemoveEndZero(Big9(estimateGasUsd).toFixed(20));
|
|
7301
8038
|
result.estimateSourceGas = estimateGas.toString();
|
|
7302
|
-
result.estimateSourceGasUsd = numberRemoveEndZero(
|
|
8039
|
+
result.estimateSourceGasUsd = numberRemoveEndZero(Big9(estimateGasUsd).toFixed(20));
|
|
7303
8040
|
result.sendParam = {
|
|
7304
8041
|
function: functionId,
|
|
7305
8042
|
typeArguments: [typeArgument],
|
|
@@ -7310,10 +8047,10 @@ var AptosWallet = class {
|
|
|
7310
8047
|
const defaultGasLimit = 5000n;
|
|
7311
8048
|
const defaultGasPrice = 100n;
|
|
7312
8049
|
const defaultEstimateGas = defaultGasLimit * defaultGasPrice;
|
|
7313
|
-
const estimateGasUsd =
|
|
7314
|
-
result.fees.sourceGasFeeUsd = numberRemoveEndZero(
|
|
8050
|
+
const estimateGasUsd = Big9(defaultEstimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
|
|
8051
|
+
result.fees.sourceGasFeeUsd = numberRemoveEndZero(Big9(estimateGasUsd).toFixed(20));
|
|
7315
8052
|
result.estimateSourceGas = defaultEstimateGas.toString();
|
|
7316
|
-
result.estimateSourceGasUsd = numberRemoveEndZero(
|
|
8053
|
+
result.estimateSourceGasUsd = numberRemoveEndZero(Big9(estimateGasUsd).toFixed(20));
|
|
7317
8054
|
}
|
|
7318
8055
|
return result;
|
|
7319
8056
|
}
|
|
@@ -7390,7 +8127,12 @@ export {
|
|
|
7390
8127
|
CancelablePromise,
|
|
7391
8128
|
EVMWallet,
|
|
7392
8129
|
GetExecutionStatusResponse,
|
|
8130
|
+
Hyperliquid,
|
|
8131
|
+
HyperliquidFromTokens,
|
|
8132
|
+
HyperliuquidMinAmount,
|
|
8133
|
+
HyperliuquidToToken,
|
|
7393
8134
|
NearWallet,
|
|
8135
|
+
NetworkRpcUrlsMap,
|
|
7394
8136
|
OpenAPI,
|
|
7395
8137
|
QuoteRequest,
|
|
7396
8138
|
SFA,
|
|
@@ -7400,7 +8142,8 @@ export {
|
|
|
7400
8142
|
TokenResponse,
|
|
7401
8143
|
TransactionStatus,
|
|
7402
8144
|
TronWallet,
|
|
7403
|
-
|
|
8145
|
+
getRpcUrls,
|
|
8146
|
+
setRpcUrls,
|
|
7404
8147
|
tokens,
|
|
7405
8148
|
usdcChains,
|
|
7406
8149
|
usdcTokens,
|