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.js
CHANGED
|
@@ -43,7 +43,12 @@ __export(index_exports, {
|
|
|
43
43
|
CancelablePromise: () => CancelablePromise,
|
|
44
44
|
EVMWallet: () => EVMWallet,
|
|
45
45
|
GetExecutionStatusResponse: () => GetExecutionStatusResponse,
|
|
46
|
+
Hyperliquid: () => Hyperliquid,
|
|
47
|
+
HyperliquidFromTokens: () => HyperliquidFromTokens,
|
|
48
|
+
HyperliuquidMinAmount: () => HyperliuquidMinAmount,
|
|
49
|
+
HyperliuquidToToken: () => HyperliuquidToToken,
|
|
46
50
|
NearWallet: () => NearWallet,
|
|
51
|
+
NetworkRpcUrlsMap: () => NetworkRpcUrlsMap,
|
|
47
52
|
OpenAPI: () => OpenAPI,
|
|
48
53
|
QuoteRequest: () => QuoteRequest,
|
|
49
54
|
SFA: () => SFA,
|
|
@@ -53,7 +58,8 @@ __export(index_exports, {
|
|
|
53
58
|
TokenResponse: () => TokenResponse,
|
|
54
59
|
TransactionStatus: () => TransactionStatus,
|
|
55
60
|
TronWallet: () => TronWallet,
|
|
56
|
-
|
|
61
|
+
getRpcUrls: () => getRpcUrls,
|
|
62
|
+
setRpcUrls: () => setRpcUrls,
|
|
57
63
|
tokens: () => tokens,
|
|
58
64
|
usdcChains: () => usdcChains,
|
|
59
65
|
usdcTokens: () => usdcTokens,
|
|
@@ -650,14 +656,17 @@ var OneClickService = class {
|
|
|
650
656
|
prices,
|
|
651
657
|
amountWei,
|
|
652
658
|
appFees = [],
|
|
659
|
+
swapType = "EXACT_INPUT",
|
|
660
|
+
isProxy = true,
|
|
653
661
|
...restParams
|
|
654
662
|
} = params;
|
|
663
|
+
const isExactOutput = swapType === "EXACT_OUTPUT";
|
|
655
664
|
const response = await request(OpenAPI, {
|
|
656
665
|
method: "POST",
|
|
657
666
|
url: "/v0/quote",
|
|
658
667
|
body: {
|
|
659
668
|
depositMode: "SIMPLE",
|
|
660
|
-
swapType
|
|
669
|
+
swapType,
|
|
661
670
|
depositType: "ORIGIN_CHAIN",
|
|
662
671
|
sessionId: `session_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
|
|
663
672
|
recipientType: "DESTINATION_CHAIN",
|
|
@@ -682,7 +691,10 @@ var OneClickService = class {
|
|
|
682
691
|
res.data.estimateTime = res.data?.quote?.timeEstimate;
|
|
683
692
|
res.data.outputAmount = numberRemoveEndZero((0, import_big.default)(res.data?.quote?.amountOut || 0).div(10 ** params.toToken.decimals).toFixed(params.toToken.decimals, 0));
|
|
684
693
|
try {
|
|
685
|
-
|
|
694
|
+
let netFee = (0, import_big.default)(params.amount).div(10 ** params.fromToken.decimals).minus((0, import_big.default)(res.data?.quote?.amountOut || 0).div(10 ** params.toToken.decimals));
|
|
695
|
+
if (isExactOutput) {
|
|
696
|
+
netFee = (0, import_big.default)(res.data?.quote?.amountIn || 0).div(10 ** params.fromToken.decimals).minus((0, import_big.default)(params.amount).div(10 ** params.toToken.decimals));
|
|
697
|
+
}
|
|
686
698
|
const bridgeFeeValue = BridgeFee.reduce((acc, item) => {
|
|
687
699
|
return acc.plus((0, import_big.default)(params.amount).div(10 ** params.fromToken.decimals).times((0, import_big.default)(item.fee).div(1e4)));
|
|
688
700
|
}, (0, import_big.default)(0));
|
|
@@ -715,14 +727,14 @@ var OneClickService = class {
|
|
|
715
727
|
console.log("oneclick estimate failed: %o", error);
|
|
716
728
|
}
|
|
717
729
|
const proxyAddress = ONECLICK_PROXY[params.fromToken.chainName];
|
|
718
|
-
if (proxyAddress) {
|
|
730
|
+
if (proxyAddress && isProxy) {
|
|
719
731
|
const proxyResult = await params.wallet.quote(Service.OneClick, {
|
|
720
732
|
proxyAddress,
|
|
721
733
|
abi: ONECLICK_PROXY_ABI,
|
|
722
734
|
fromToken: params.fromToken,
|
|
723
735
|
refundTo: params.refundTo,
|
|
724
736
|
recipient: params.recipient,
|
|
725
|
-
amountWei: params.amount,
|
|
737
|
+
amountWei: isExactOutput ? res.data?.quote?.amountIn : params.amount,
|
|
726
738
|
prices: params.prices,
|
|
727
739
|
depositAddress: res.data?.quote?.depositAddress || DefaultAddresses[params.fromToken.chainType]
|
|
728
740
|
});
|
|
@@ -797,8 +809,10 @@ var USDT0_CONFIG = {
|
|
|
797
809
|
chainKey: "ethereum",
|
|
798
810
|
blockTime: 12,
|
|
799
811
|
// Ethereum average block time ~12 seconds
|
|
800
|
-
confirmations: 15
|
|
812
|
+
confirmations: 15,
|
|
801
813
|
// Default confirmations from layerzeroscan.com
|
|
814
|
+
lzReceiveOptionGas: 8e4,
|
|
815
|
+
lzReceiveOptionGasLegacy: 2e5
|
|
802
816
|
},
|
|
803
817
|
Arbitrum: {
|
|
804
818
|
contractAddress: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
|
|
@@ -809,8 +823,10 @@ var USDT0_CONFIG = {
|
|
|
809
823
|
chainKey: "arbitrum",
|
|
810
824
|
blockTime: 0.25,
|
|
811
825
|
// Arbitrum average block time ~0.25 seconds
|
|
812
|
-
confirmations: 20
|
|
826
|
+
confirmations: 20,
|
|
813
827
|
// Default confirmations from layerzeroscan.com
|
|
828
|
+
lzReceiveOptionGas: 8e4,
|
|
829
|
+
lzReceiveOptionGasLegacy: 2e5
|
|
814
830
|
},
|
|
815
831
|
Polygon: {
|
|
816
832
|
contractAddress: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
|
|
@@ -819,8 +835,11 @@ var USDT0_CONFIG = {
|
|
|
819
835
|
chainKey: "polygon",
|
|
820
836
|
blockTime: 2,
|
|
821
837
|
// Polygon average block time ~2 seconds
|
|
822
|
-
confirmations: 20
|
|
838
|
+
confirmations: 20,
|
|
823
839
|
// Default confirmations from layerzeroscan.com
|
|
840
|
+
lzReceiveOptionGas: 8e4,
|
|
841
|
+
lzReceiveOptionGasLegacy: 2e5,
|
|
842
|
+
composeOptionGas: 6e5
|
|
824
843
|
},
|
|
825
844
|
Optimism: {
|
|
826
845
|
contractAddress: "0x01bFF41798a0BcF287b996046Ca68b395DbC1071",
|
|
@@ -829,8 +848,11 @@ var USDT0_CONFIG = {
|
|
|
829
848
|
chainKey: "optimism",
|
|
830
849
|
blockTime: 2,
|
|
831
850
|
// Optimism average block time ~2 seconds
|
|
832
|
-
confirmations: 20
|
|
851
|
+
confirmations: 20,
|
|
833
852
|
// Default confirmations from layerzeroscan.com
|
|
853
|
+
lzReceiveOptionGas: 8e4,
|
|
854
|
+
lzReceiveOptionGasLegacy: 2e5,
|
|
855
|
+
composeOptionGas: 6e5
|
|
834
856
|
},
|
|
835
857
|
Berachain: {
|
|
836
858
|
contractAddress: "0x779Ded0c9e1022225f8E0630b35a9b54bE713736",
|
|
@@ -840,8 +862,11 @@ var USDT0_CONFIG = {
|
|
|
840
862
|
chainKey: "berachain",
|
|
841
863
|
blockTime: 2,
|
|
842
864
|
// Optimism average block time ~2 seconds
|
|
843
|
-
confirmations: 20
|
|
865
|
+
confirmations: 20,
|
|
844
866
|
// Default confirmations from layerzeroscan.com
|
|
867
|
+
lzReceiveOptionGas: 8e4,
|
|
868
|
+
lzReceiveOptionGasLegacy: 2e5,
|
|
869
|
+
composeOptionGas: 6e5
|
|
845
870
|
},
|
|
846
871
|
Solana: {
|
|
847
872
|
contractAddress: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
|
|
@@ -850,8 +875,11 @@ var USDT0_CONFIG = {
|
|
|
850
875
|
chainKey: "solana",
|
|
851
876
|
blockTime: 0.4,
|
|
852
877
|
// Solana average block time ~0.4 seconds
|
|
853
|
-
confirmations: 32
|
|
878
|
+
confirmations: 32,
|
|
854
879
|
// Default confirmations from layerzeroscan.com
|
|
880
|
+
lzReceiveOptionGas: 2e5,
|
|
881
|
+
lzReceiveOptionGasLegacy: 2e5,
|
|
882
|
+
composeOptionGas: 5e5
|
|
855
883
|
},
|
|
856
884
|
Tron: {
|
|
857
885
|
contractAddress: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
|
|
@@ -860,8 +888,11 @@ var USDT0_CONFIG = {
|
|
|
860
888
|
chainKey: "tron",
|
|
861
889
|
blockTime: 3,
|
|
862
890
|
// Tron average block time ~3 seconds
|
|
863
|
-
confirmations: 5
|
|
891
|
+
confirmations: 5,
|
|
864
892
|
// Default confirmations from layerzeroscan.com
|
|
893
|
+
lzReceiveOptionGas: 3e5,
|
|
894
|
+
lzReceiveOptionGasLegacy: 3e5,
|
|
895
|
+
composeOptionGas: 5e5
|
|
865
896
|
},
|
|
866
897
|
"X Layer": {
|
|
867
898
|
contractAddress: "0x779Ded0c9e1022225f8E0630b35a9b54bE713736",
|
|
@@ -870,12 +901,20 @@ var USDT0_CONFIG = {
|
|
|
870
901
|
chainKey: "xlayer",
|
|
871
902
|
blockTime: 3,
|
|
872
903
|
// Tron average block time ~3 seconds
|
|
873
|
-
confirmations: 20
|
|
904
|
+
confirmations: 20,
|
|
874
905
|
// Default confirmations from layerzeroscan.com
|
|
906
|
+
lzReceiveOptionGas: 8e4,
|
|
907
|
+
lzReceiveOptionGasLegacy: 2e5,
|
|
908
|
+
composeOptionGas: 6e5
|
|
875
909
|
}
|
|
876
910
|
};
|
|
911
|
+
var LZ_RECEIVE_VALUE = {
|
|
912
|
+
Solana: 2039280
|
|
913
|
+
};
|
|
877
914
|
var USDT0_DVN_COUNT = 2;
|
|
878
|
-
var
|
|
915
|
+
var USDT0_LEGACY_MESH_TRANSFTER_FEE = 3e-4;
|
|
916
|
+
var DATA_HEX_PROTOBUF_EXTRA = 3;
|
|
917
|
+
var SIGNATURE_SIZE = 67;
|
|
879
918
|
|
|
880
919
|
// src/bridges/usdt0/contract.ts
|
|
881
920
|
var OFT_ABI = [
|
|
@@ -3584,17 +3623,6 @@ function calculateEstimateTime(originChain, destinationChain) {
|
|
|
3584
3623
|
const sourceTime = sourceBlockTime * blockConfirmations;
|
|
3585
3624
|
const destinationTime = destinationBlockTime * (2 + dvnCount);
|
|
3586
3625
|
const totalTime = Math.ceil(sourceTime + destinationTime);
|
|
3587
|
-
console.log(`USDT0 estimate time calculation:`, {
|
|
3588
|
-
originChain,
|
|
3589
|
-
destinationChain,
|
|
3590
|
-
sourceBlockTime,
|
|
3591
|
-
blockConfirmations,
|
|
3592
|
-
destinationBlockTime,
|
|
3593
|
-
dvnCount,
|
|
3594
|
-
sourceTime,
|
|
3595
|
-
destinationTime,
|
|
3596
|
-
totalTime
|
|
3597
|
-
});
|
|
3598
3626
|
return totalTime;
|
|
3599
3627
|
}
|
|
3600
3628
|
var Usdt0Service = class {
|
|
@@ -3645,7 +3673,9 @@ var Usdt0Service = class {
|
|
|
3645
3673
|
multiHopComposer: USDT0_CONFIG["Arbitrum"],
|
|
3646
3674
|
isMultiHopComposer: isMultiHopComposer2,
|
|
3647
3675
|
isOriginLegacy: isOriginLegacy2,
|
|
3648
|
-
isDestinationLegacy: isDestinationLegacy2
|
|
3676
|
+
isDestinationLegacy: isDestinationLegacy2,
|
|
3677
|
+
originLayerzero,
|
|
3678
|
+
destinationLayerzero
|
|
3649
3679
|
});
|
|
3650
3680
|
result.estimateTime = estimateTime;
|
|
3651
3681
|
return result;
|
|
@@ -3679,7 +3709,9 @@ var Usdt0Service = class {
|
|
|
3679
3709
|
multiHopComposer: USDT0_CONFIG["Arbitrum"],
|
|
3680
3710
|
isMultiHopComposer,
|
|
3681
3711
|
isOriginLegacy,
|
|
3682
|
-
isDestinationLegacy
|
|
3712
|
+
isDestinationLegacy,
|
|
3713
|
+
originLayerzero,
|
|
3714
|
+
destinationLayerzero
|
|
3683
3715
|
});
|
|
3684
3716
|
result.estimateTime = estimateTime;
|
|
3685
3717
|
return result;
|
|
@@ -3702,8 +3734,11 @@ var Usdt0Service = class {
|
|
|
3702
3734
|
multiHopComposer: USDT0_CONFIG["Arbitrum"],
|
|
3703
3735
|
isMultiHopComposer,
|
|
3704
3736
|
isOriginLegacy,
|
|
3705
|
-
isDestinationLegacy
|
|
3737
|
+
isDestinationLegacy,
|
|
3738
|
+
originLayerzero,
|
|
3739
|
+
destinationLayerzero
|
|
3706
3740
|
});
|
|
3741
|
+
result.estimateTime = estimateTime;
|
|
3707
3742
|
return result;
|
|
3708
3743
|
}
|
|
3709
3744
|
}
|
|
@@ -3916,24 +3951,42 @@ var ServiceLogoMap = {
|
|
|
3916
3951
|
};
|
|
3917
3952
|
|
|
3918
3953
|
// src/services/SFA.ts
|
|
3919
|
-
var
|
|
3954
|
+
var import_big3 = __toESM(require("big.js"));
|
|
3920
3955
|
|
|
3921
3956
|
// src/wallets/config/rpcs.ts
|
|
3922
|
-
var
|
|
3923
|
-
"
|
|
3924
|
-
"
|
|
3925
|
-
"
|
|
3926
|
-
"
|
|
3927
|
-
"
|
|
3928
|
-
"
|
|
3929
|
-
"
|
|
3930
|
-
"
|
|
3931
|
-
"
|
|
3932
|
-
"
|
|
3933
|
-
"
|
|
3934
|
-
"
|
|
3935
|
-
"
|
|
3936
|
-
"
|
|
3957
|
+
var NetworkRpcUrlsMap = {
|
|
3958
|
+
"eth": ["https://eth.merkle.io"],
|
|
3959
|
+
"arb": ["https://arb1.arbitrum.io/rpc"],
|
|
3960
|
+
"bsc": ["https://56.rpc.thirdweb.com"],
|
|
3961
|
+
"avax": ["https://api.avax.network/ext/bc/C/rpc"],
|
|
3962
|
+
"base": ["https://mainnet.base.org"],
|
|
3963
|
+
"pol": ["https://polygon-rpc.com"],
|
|
3964
|
+
"gnosis": ["https://rpc.gnosischain.com"],
|
|
3965
|
+
"op": ["https://mainnet.optimism.io"],
|
|
3966
|
+
"bera": ["https://rpc.berachain.com"],
|
|
3967
|
+
"tron": ["https://api.trongrid.io"],
|
|
3968
|
+
"aptos": ["https://api.mainnet.aptoslabs.com/v1"],
|
|
3969
|
+
"sol": ["https://solana-rpc.publicnode.com"],
|
|
3970
|
+
"near": ["https://nearinner.deltarpc.com"],
|
|
3971
|
+
"xlayer": ["https://rpc.xlayer.tech"],
|
|
3972
|
+
"plasma": ["https://rpc.plasma.to"]
|
|
3973
|
+
};
|
|
3974
|
+
var getRpcUrls = (blockchain) => {
|
|
3975
|
+
return NetworkRpcUrlsMap[blockchain] || [];
|
|
3976
|
+
};
|
|
3977
|
+
var setRpcUrls = (urls) => {
|
|
3978
|
+
for (const blockchain in urls) {
|
|
3979
|
+
const prev = NetworkRpcUrlsMap[blockchain] ?? [];
|
|
3980
|
+
const next = urls[blockchain];
|
|
3981
|
+
for (let i = next.length - 1; i >= 0; i--) {
|
|
3982
|
+
const rpc = next[i];
|
|
3983
|
+
if (prev.some((_rpc) => _rpc.toLowerCase() === rpc.toLowerCase())) {
|
|
3984
|
+
continue;
|
|
3985
|
+
}
|
|
3986
|
+
prev.unshift(rpc);
|
|
3987
|
+
}
|
|
3988
|
+
}
|
|
3989
|
+
return NetworkRpcUrlsMap;
|
|
3937
3990
|
};
|
|
3938
3991
|
|
|
3939
3992
|
// src/wallets/config/chains.ts
|
|
@@ -3977,7 +4030,7 @@ var chains = {
|
|
|
3977
4030
|
symbol: "NEAR",
|
|
3978
4031
|
decimals: 24
|
|
3979
4032
|
},
|
|
3980
|
-
|
|
4033
|
+
rpcUrls: getRpcUrls("near")
|
|
3981
4034
|
},
|
|
3982
4035
|
sol: {
|
|
3983
4036
|
chainName: "Solana",
|
|
@@ -3991,7 +4044,7 @@ var chains = {
|
|
|
3991
4044
|
symbol: "SOL",
|
|
3992
4045
|
decimals: 9
|
|
3993
4046
|
},
|
|
3994
|
-
|
|
4047
|
+
rpcUrls: getRpcUrls("sol")
|
|
3995
4048
|
},
|
|
3996
4049
|
eth: {
|
|
3997
4050
|
chainName: "Ethereum",
|
|
@@ -4006,7 +4059,7 @@ var chains = {
|
|
|
4006
4059
|
symbol: "ETH",
|
|
4007
4060
|
decimals: 18
|
|
4008
4061
|
},
|
|
4009
|
-
|
|
4062
|
+
rpcUrls: getRpcUrls("eth")
|
|
4010
4063
|
},
|
|
4011
4064
|
arb: {
|
|
4012
4065
|
chainName: "Arbitrum",
|
|
@@ -4021,7 +4074,7 @@ var chains = {
|
|
|
4021
4074
|
symbol: "ETH",
|
|
4022
4075
|
decimals: 18
|
|
4023
4076
|
},
|
|
4024
|
-
|
|
4077
|
+
rpcUrls: getRpcUrls("arb")
|
|
4025
4078
|
},
|
|
4026
4079
|
bsc: {
|
|
4027
4080
|
chainName: "BNB Chain",
|
|
@@ -4036,7 +4089,7 @@ var chains = {
|
|
|
4036
4089
|
symbol: "BNB",
|
|
4037
4090
|
decimals: 18
|
|
4038
4091
|
},
|
|
4039
|
-
|
|
4092
|
+
rpcUrls: getRpcUrls("bsc")
|
|
4040
4093
|
},
|
|
4041
4094
|
avax: {
|
|
4042
4095
|
chainName: "Avalanche",
|
|
@@ -4051,7 +4104,7 @@ var chains = {
|
|
|
4051
4104
|
symbol: "AVAX",
|
|
4052
4105
|
decimals: 18
|
|
4053
4106
|
},
|
|
4054
|
-
|
|
4107
|
+
rpcUrls: getRpcUrls("avax")
|
|
4055
4108
|
},
|
|
4056
4109
|
base: {
|
|
4057
4110
|
chainName: "Base",
|
|
@@ -4066,7 +4119,7 @@ var chains = {
|
|
|
4066
4119
|
symbol: "ETH",
|
|
4067
4120
|
decimals: 18
|
|
4068
4121
|
},
|
|
4069
|
-
|
|
4122
|
+
rpcUrls: getRpcUrls("base")
|
|
4070
4123
|
},
|
|
4071
4124
|
pol: {
|
|
4072
4125
|
chainName: "Polygon",
|
|
@@ -4081,7 +4134,7 @@ var chains = {
|
|
|
4081
4134
|
symbol: "POL",
|
|
4082
4135
|
decimals: 18
|
|
4083
4136
|
},
|
|
4084
|
-
|
|
4137
|
+
rpcUrls: getRpcUrls("pol")
|
|
4085
4138
|
},
|
|
4086
4139
|
gnosis: {
|
|
4087
4140
|
chainName: "Gnosis",
|
|
@@ -4096,7 +4149,7 @@ var chains = {
|
|
|
4096
4149
|
symbol: "XDAI",
|
|
4097
4150
|
decimals: 18
|
|
4098
4151
|
},
|
|
4099
|
-
|
|
4152
|
+
rpcUrls: getRpcUrls("gnosis")
|
|
4100
4153
|
},
|
|
4101
4154
|
op: {
|
|
4102
4155
|
chainName: "Optimism",
|
|
@@ -4111,7 +4164,7 @@ var chains = {
|
|
|
4111
4164
|
symbol: "ETH",
|
|
4112
4165
|
decimals: 18
|
|
4113
4166
|
},
|
|
4114
|
-
|
|
4167
|
+
rpcUrls: getRpcUrls("op")
|
|
4115
4168
|
},
|
|
4116
4169
|
tron: {
|
|
4117
4170
|
chainName: "Tron",
|
|
@@ -4125,7 +4178,7 @@ var chains = {
|
|
|
4125
4178
|
symbol: "TRX",
|
|
4126
4179
|
decimals: 6
|
|
4127
4180
|
},
|
|
4128
|
-
|
|
4181
|
+
rpcUrls: getRpcUrls("tron")
|
|
4129
4182
|
},
|
|
4130
4183
|
aptos: {
|
|
4131
4184
|
chainName: "Aptos",
|
|
@@ -4139,7 +4192,7 @@ var chains = {
|
|
|
4139
4192
|
symbol: "APT",
|
|
4140
4193
|
decimals: 8
|
|
4141
4194
|
},
|
|
4142
|
-
|
|
4195
|
+
rpcUrls: getRpcUrls("aptos")
|
|
4143
4196
|
},
|
|
4144
4197
|
bera: {
|
|
4145
4198
|
chainName: "Berachain",
|
|
@@ -4154,7 +4207,7 @@ var chains = {
|
|
|
4154
4207
|
symbol: "BERA",
|
|
4155
4208
|
decimals: 18
|
|
4156
4209
|
},
|
|
4157
|
-
|
|
4210
|
+
rpcUrls: getRpcUrls("bera")
|
|
4158
4211
|
},
|
|
4159
4212
|
xlayer: {
|
|
4160
4213
|
chainName: "X Layer",
|
|
@@ -4169,7 +4222,22 @@ var chains = {
|
|
|
4169
4222
|
symbol: "OKB",
|
|
4170
4223
|
decimals: 18
|
|
4171
4224
|
},
|
|
4172
|
-
|
|
4225
|
+
rpcUrls: getRpcUrls("xlayer")
|
|
4226
|
+
},
|
|
4227
|
+
plasma: {
|
|
4228
|
+
chainName: "Plasma",
|
|
4229
|
+
blockchain: "plasma",
|
|
4230
|
+
chainIcon: "/chains/plasma.png",
|
|
4231
|
+
chainIconGray: "/chains/plasma-gray.png",
|
|
4232
|
+
chainType: chainTypes.evm.value,
|
|
4233
|
+
chainId: 9745,
|
|
4234
|
+
blockExplorerUrl: "https://plasmascan.to/tx/",
|
|
4235
|
+
primaryColor: "#162F29",
|
|
4236
|
+
nativeToken: {
|
|
4237
|
+
symbol: "XPL",
|
|
4238
|
+
decimals: 18
|
|
4239
|
+
},
|
|
4240
|
+
rpcUrls: getRpcUrls("plasma")
|
|
4173
4241
|
}
|
|
4174
4242
|
};
|
|
4175
4243
|
var chains_default = chains;
|
|
@@ -4178,7 +4246,8 @@ var chains_default = chains;
|
|
|
4178
4246
|
var usdt = {
|
|
4179
4247
|
symbol: "USDT",
|
|
4180
4248
|
decimals: 6,
|
|
4181
|
-
icon: "/usdt.png"
|
|
4249
|
+
icon: "/usdt.png",
|
|
4250
|
+
name: "Tether USD"
|
|
4182
4251
|
};
|
|
4183
4252
|
var usdtChains = {
|
|
4184
4253
|
eth: {
|
|
@@ -4236,7 +4305,7 @@ var usdtChains = {
|
|
|
4236
4305
|
assetId: "nep141:sol-c800a4bd850783ccb82c2b2c7e84175443606352.omft.near",
|
|
4237
4306
|
contractAddress: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
|
|
4238
4307
|
...chains_default.sol,
|
|
4239
|
-
services: [Service.OneClick]
|
|
4308
|
+
services: [Service.OneClick, Service.Usdt0]
|
|
4240
4309
|
},
|
|
4241
4310
|
tron: {
|
|
4242
4311
|
...usdt,
|
|
@@ -4265,6 +4334,13 @@ var usdtChains = {
|
|
|
4265
4334
|
contractAddress: "0x779ded0c9e1022225f8e0630b35a9b54be713736",
|
|
4266
4335
|
...chains_default.xlayer,
|
|
4267
4336
|
services: [Service.OneClick, Service.Usdt0]
|
|
4337
|
+
},
|
|
4338
|
+
plasma: {
|
|
4339
|
+
...usdt,
|
|
4340
|
+
assetId: "nep245:v2_1.omni.hot.tg:9745_3aL9skCy1yhPoDB8oKMmRHRN7SJW",
|
|
4341
|
+
contractAddress: "0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb",
|
|
4342
|
+
...chains_default.plasma,
|
|
4343
|
+
services: [Service.OneClick]
|
|
4268
4344
|
}
|
|
4269
4345
|
};
|
|
4270
4346
|
|
|
@@ -4272,7 +4348,8 @@ var usdtChains = {
|
|
|
4272
4348
|
var usdc = {
|
|
4273
4349
|
symbol: "USDC",
|
|
4274
4350
|
decimals: 6,
|
|
4275
|
-
icon: "/usdc.png"
|
|
4351
|
+
icon: "/usdc.png",
|
|
4352
|
+
name: "USD Coin"
|
|
4276
4353
|
};
|
|
4277
4354
|
var usdcChains = {
|
|
4278
4355
|
eth: {
|
|
@@ -4364,6 +4441,45 @@ var TransactionStatus = /* @__PURE__ */ ((TransactionStatus2) => {
|
|
|
4364
4441
|
return TransactionStatus2;
|
|
4365
4442
|
})(TransactionStatus || {});
|
|
4366
4443
|
|
|
4444
|
+
// src/utils/error.ts
|
|
4445
|
+
var import_big2 = __toESM(require("big.js"));
|
|
4446
|
+
var formatQuoteError = (error, options) => {
|
|
4447
|
+
const { service, fromToken } = options;
|
|
4448
|
+
const defaultErrorMessage = "Failed to get quote, please try again later";
|
|
4449
|
+
if (service === Service.OneClick) {
|
|
4450
|
+
const getQuoteErrorMessage = () => {
|
|
4451
|
+
const _messageResult = {
|
|
4452
|
+
message: defaultErrorMessage,
|
|
4453
|
+
sourceMessage: error?.response?.data?.message || defaultErrorMessage
|
|
4454
|
+
};
|
|
4455
|
+
if (error?.response?.data?.message && error?.response?.data?.message !== "Internal server error") {
|
|
4456
|
+
if (error?.response?.data?.message === "Failed to get quote") {
|
|
4457
|
+
_messageResult.message = "Amount exceeds max";
|
|
4458
|
+
return _messageResult;
|
|
4459
|
+
}
|
|
4460
|
+
if (error?.response?.data?.message?.includes("Amount is too low for bridge, try at least")) {
|
|
4461
|
+
const match = error.response.data.message.match(/try at least\s+(\d+(?:\.\d+)?)/i);
|
|
4462
|
+
let minimumAmount = match ? match[1] : (0, import_big2.default)(1).times(10 ** fromToken.decimals).toFixed(0);
|
|
4463
|
+
minimumAmount = (0, import_big2.default)(minimumAmount).div(10 ** fromToken.decimals).toFixed(fromToken.decimals);
|
|
4464
|
+
_messageResult.message = `Amount is too low, at least ${minimumAmount}`;
|
|
4465
|
+
return _messageResult;
|
|
4466
|
+
}
|
|
4467
|
+
return _messageResult;
|
|
4468
|
+
}
|
|
4469
|
+
return _messageResult;
|
|
4470
|
+
};
|
|
4471
|
+
const onclickErrMsg = getQuoteErrorMessage();
|
|
4472
|
+
return {
|
|
4473
|
+
serviceType: service,
|
|
4474
|
+
error: onclickErrMsg.message
|
|
4475
|
+
};
|
|
4476
|
+
}
|
|
4477
|
+
return {
|
|
4478
|
+
serviceType: service,
|
|
4479
|
+
error: error?.message || defaultErrorMessage
|
|
4480
|
+
};
|
|
4481
|
+
};
|
|
4482
|
+
|
|
4367
4483
|
// src/services/SFA.ts
|
|
4368
4484
|
var submitOneclickDepositTx = (requestBody) => {
|
|
4369
4485
|
return request(OpenAPI, {
|
|
@@ -4468,10 +4584,10 @@ var SFA = class {
|
|
|
4468
4584
|
static async getAllQuote(params) {
|
|
4469
4585
|
const results = [];
|
|
4470
4586
|
let { minInputAmount = "1" } = params;
|
|
4471
|
-
if ((0,
|
|
4587
|
+
if ((0, import_big3.default)(minInputAmount).lte(0)) {
|
|
4472
4588
|
minInputAmount = "1";
|
|
4473
4589
|
}
|
|
4474
|
-
if (!params.fromToken || !params.fromToken.contractAddress || !params.toToken || !params.toToken.contractAddress || !params.refundTo || !params.recipient || !params.amountWei || (0,
|
|
4590
|
+
if (!params.fromToken || !params.fromToken.contractAddress || !params.toToken || !params.toToken.contractAddress || !params.refundTo || !params.recipient || !params.amountWei || (0, import_big3.default)(params.amountWei).lte(minInputAmount)) {
|
|
4475
4591
|
throw new Error("Invalid parameters");
|
|
4476
4592
|
}
|
|
4477
4593
|
const formatQuoteParams = (service) => {
|
|
@@ -4492,7 +4608,9 @@ var SFA = class {
|
|
|
4492
4608
|
_params.destinationAsset = params.toToken.assetId;
|
|
4493
4609
|
_params.amount = params.amountWei;
|
|
4494
4610
|
_params.refundType = "ORIGIN_CHAIN";
|
|
4495
|
-
_params.appFees = params.appFees;
|
|
4611
|
+
_params.appFees = params.oneclickParams?.appFees;
|
|
4612
|
+
_params.swapType = params.oneclickParams?.swapType;
|
|
4613
|
+
_params.isProxy = params.oneclickParams?.isProxy;
|
|
4496
4614
|
}
|
|
4497
4615
|
if (service === Service.Usdt0) {
|
|
4498
4616
|
_params.originChain = params.fromToken.chainName;
|
|
@@ -4521,42 +4639,6 @@ var SFA = class {
|
|
|
4521
4639
|
});
|
|
4522
4640
|
}
|
|
4523
4641
|
}
|
|
4524
|
-
const formatQuoteError = (service, error) => {
|
|
4525
|
-
const defaultErrorMessage = "Failed to get quote, please try again later";
|
|
4526
|
-
if (service === Service.OneClick) {
|
|
4527
|
-
const getQuoteErrorMessage = () => {
|
|
4528
|
-
const _messageResult = {
|
|
4529
|
-
message: defaultErrorMessage,
|
|
4530
|
-
sourceMessage: error?.response?.data?.message || defaultErrorMessage
|
|
4531
|
-
};
|
|
4532
|
-
if (error?.response?.data?.message && error?.response?.data?.message !== "Internal server error") {
|
|
4533
|
-
if (error?.response?.data?.message === "Failed to get quote") {
|
|
4534
|
-
_messageResult.message = "Amount exceeds max";
|
|
4535
|
-
return _messageResult;
|
|
4536
|
-
}
|
|
4537
|
-
if (error?.response?.data?.message?.includes("Amount is too low for bridge, try at least")) {
|
|
4538
|
-
const match = error.response.data.message.match(/try at least\s+(\d+(?:\.\d+)?)/i);
|
|
4539
|
-
let minimumAmount = match ? match[1] : (0, import_big2.default)(1).times(10 ** fromToken.decimals).toFixed(0);
|
|
4540
|
-
minimumAmount = (0, import_big2.default)(minimumAmount).div(10 ** fromToken.decimals).toFixed(fromToken.decimals);
|
|
4541
|
-
_messageResult.message = `Amount is too low, at least ${minimumAmount}`;
|
|
4542
|
-
return _messageResult;
|
|
4543
|
-
}
|
|
4544
|
-
return _messageResult;
|
|
4545
|
-
}
|
|
4546
|
-
return _messageResult;
|
|
4547
|
-
};
|
|
4548
|
-
const onclickErrMsg = getQuoteErrorMessage();
|
|
4549
|
-
results.push({
|
|
4550
|
-
serviceType: service,
|
|
4551
|
-
error: onclickErrMsg.message
|
|
4552
|
-
});
|
|
4553
|
-
} else {
|
|
4554
|
-
results.push({
|
|
4555
|
-
serviceType: service,
|
|
4556
|
-
error: error?.message || defaultErrorMessage
|
|
4557
|
-
});
|
|
4558
|
-
}
|
|
4559
|
-
};
|
|
4560
4642
|
if (params.singleService) {
|
|
4561
4643
|
const quoteService = quoteServices.find((service) => service.service === params.singleService);
|
|
4562
4644
|
if (quoteService) {
|
|
@@ -4567,7 +4649,8 @@ var SFA = class {
|
|
|
4567
4649
|
quote: quoteRes
|
|
4568
4650
|
});
|
|
4569
4651
|
} catch (error) {
|
|
4570
|
-
formatQuoteError(quoteService.service,
|
|
4652
|
+
const _err = formatQuoteError(error, { service: quoteService.service, fromToken });
|
|
4653
|
+
results.push(_err);
|
|
4571
4654
|
}
|
|
4572
4655
|
}
|
|
4573
4656
|
return results;
|
|
@@ -4583,7 +4666,8 @@ var SFA = class {
|
|
|
4583
4666
|
});
|
|
4584
4667
|
} catch (error) {
|
|
4585
4668
|
console.log("%s quote failed: %o", quoteService.service, error);
|
|
4586
|
-
formatQuoteError(quoteService.service,
|
|
4669
|
+
const _err = formatQuoteError(error, { service: quoteService.service, fromToken });
|
|
4670
|
+
results.push(_err);
|
|
4587
4671
|
}
|
|
4588
4672
|
})();
|
|
4589
4673
|
promises.push(promise);
|
|
@@ -4638,7 +4722,7 @@ var SFA = class {
|
|
|
4638
4722
|
project: projectMap[serviceType],
|
|
4639
4723
|
address: params.quote?.quoteParam?.refundTo,
|
|
4640
4724
|
receive_address: params.quote?.quoteParam?.recipient,
|
|
4641
|
-
amount: (0,
|
|
4725
|
+
amount: (0, import_big3.default)(params.quote?.quoteParam?.amountWei || 0).div(10 ** (params.quote?.fromToken?.decimals || 6)).toFixed(params.quote?.fromToken?.decimals || 6, 0)
|
|
4642
4726
|
};
|
|
4643
4727
|
if (serviceType === Service.OneClick) {
|
|
4644
4728
|
reportParams.deposit_address = params.quote?.quote?.depositAddress;
|
|
@@ -4725,13 +4809,184 @@ var SFA = class {
|
|
|
4725
4809
|
*/
|
|
4726
4810
|
SFA.submitDepositTx = submitOneclickDepositTx;
|
|
4727
4811
|
|
|
4812
|
+
// src/services/Hyperliquid.ts
|
|
4813
|
+
var import_ethers = require("ethers");
|
|
4814
|
+
var import_big4 = __toESM(require("big.js"));
|
|
4815
|
+
var SPENDER = "0x2df1c51e09aecf9cacb7bc98cb1742757f163df7";
|
|
4816
|
+
var DESTINATION_TOKEN = usdcChains["arb"];
|
|
4817
|
+
var MIN_AMOUNT = (0, import_big4.default)(5).times(10 ** DESTINATION_TOKEN.decimals).toFixed(0);
|
|
4818
|
+
var HyperliquidService = class {
|
|
4819
|
+
async quote(params) {
|
|
4820
|
+
const result = { quote: null, error: null };
|
|
4821
|
+
if ((0, import_big4.default)(params.amountWei || 0).lt(MIN_AMOUNT)) {
|
|
4822
|
+
result.error = `Amount is too low, at least ${MIN_AMOUNT}`;
|
|
4823
|
+
return result;
|
|
4824
|
+
}
|
|
4825
|
+
const quoteParams = {
|
|
4826
|
+
...params,
|
|
4827
|
+
dry: params.dry ?? true,
|
|
4828
|
+
slippageTolerance: params.slippageTolerance * 100,
|
|
4829
|
+
originAsset: params.fromToken.assetId,
|
|
4830
|
+
toToken: DESTINATION_TOKEN,
|
|
4831
|
+
destinationAsset: DESTINATION_TOKEN.assetId,
|
|
4832
|
+
amount: params.amountWei,
|
|
4833
|
+
refundType: "ORIGIN_CHAIN",
|
|
4834
|
+
appFees: params.oneclickParams?.appFees,
|
|
4835
|
+
swapType: "EXACT_OUTPUT",
|
|
4836
|
+
isProxy: false
|
|
4837
|
+
};
|
|
4838
|
+
try {
|
|
4839
|
+
const quoteRes = await ServiceMap[Service.OneClick].quote(quoteParams);
|
|
4840
|
+
result.quote = quoteRes;
|
|
4841
|
+
} catch (error) {
|
|
4842
|
+
const _err = formatQuoteError(error, { service: Service.OneClick, fromToken: params.fromToken });
|
|
4843
|
+
result.error = _err.error;
|
|
4844
|
+
}
|
|
4845
|
+
return result;
|
|
4846
|
+
}
|
|
4847
|
+
async transfer(params) {
|
|
4848
|
+
const {
|
|
4849
|
+
quote,
|
|
4850
|
+
wallet
|
|
4851
|
+
} = params;
|
|
4852
|
+
const sendParams = {
|
|
4853
|
+
wallet,
|
|
4854
|
+
sendParam: quote?.sendParam,
|
|
4855
|
+
fromToken: quote?.quoteParam.fromToken,
|
|
4856
|
+
depositAddress: quote?.quote?.depositAddress,
|
|
4857
|
+
amountWei: quote?.quote?.amountIn
|
|
4858
|
+
};
|
|
4859
|
+
const txhash = await ServiceMap[Service.OneClick].send(sendParams);
|
|
4860
|
+
return txhash;
|
|
4861
|
+
}
|
|
4862
|
+
async deposit(params) {
|
|
4863
|
+
const {
|
|
4864
|
+
evmWallet,
|
|
4865
|
+
evmWalletAddress,
|
|
4866
|
+
quote,
|
|
4867
|
+
txhash
|
|
4868
|
+
} = params;
|
|
4869
|
+
const permitParams = await this.generatePermit({
|
|
4870
|
+
address: evmWalletAddress,
|
|
4871
|
+
evmWallet,
|
|
4872
|
+
amountWei: quote?.quote?.amountOut
|
|
4873
|
+
});
|
|
4874
|
+
const depositParams = {
|
|
4875
|
+
deposit_address: quote?.quote?.depositAddress,
|
|
4876
|
+
from_addr: quote?.quoteParam?.refundTo,
|
|
4877
|
+
from_amount: quote?.quote?.amountIn,
|
|
4878
|
+
from_chain: quote?.quoteParam?.fromToken?.blockchain,
|
|
4879
|
+
from_hash: txhash,
|
|
4880
|
+
from_token: quote?.quoteParam?.fromToken?.contractAddress,
|
|
4881
|
+
sender: quote?.quoteParam?.recipient,
|
|
4882
|
+
to_amount: quote?.quote?.amountOut,
|
|
4883
|
+
to_chain: quote?.quoteParam?.toToken?.blockchain,
|
|
4884
|
+
to_token: quote?.quoteParam?.toToken?.contractAddress,
|
|
4885
|
+
type: Service.OneClick,
|
|
4886
|
+
permit: permitParams
|
|
4887
|
+
};
|
|
4888
|
+
const depositRes = await request(OpenAPI, {
|
|
4889
|
+
method: "POST",
|
|
4890
|
+
url: "/v0/deposit",
|
|
4891
|
+
body: depositParams,
|
|
4892
|
+
mediaType: "application/json",
|
|
4893
|
+
errors: {
|
|
4894
|
+
400: `Bad Request - Invalid input data`,
|
|
4895
|
+
401: `Unauthorized - JWT token is invalid`
|
|
4896
|
+
}
|
|
4897
|
+
});
|
|
4898
|
+
return depositRes;
|
|
4899
|
+
}
|
|
4900
|
+
async getStatus(params) {
|
|
4901
|
+
return request(OpenAPI, {
|
|
4902
|
+
method: "GET",
|
|
4903
|
+
url: "/v0/deposit",
|
|
4904
|
+
query: {
|
|
4905
|
+
depositId: params.depositId
|
|
4906
|
+
},
|
|
4907
|
+
mediaType: "application/json",
|
|
4908
|
+
errors: {
|
|
4909
|
+
400: `Bad Request - Invalid input data`,
|
|
4910
|
+
401: `Unauthorized - JWT token is invalid`
|
|
4911
|
+
}
|
|
4912
|
+
});
|
|
4913
|
+
}
|
|
4914
|
+
async generatePermit(params) {
|
|
4915
|
+
const {
|
|
4916
|
+
address,
|
|
4917
|
+
evmWallet,
|
|
4918
|
+
amountWei
|
|
4919
|
+
} = params;
|
|
4920
|
+
const tokenAddress = DESTINATION_TOKEN.contractAddress;
|
|
4921
|
+
const name = DESTINATION_TOKEN.name;
|
|
4922
|
+
const chainId = DESTINATION_TOKEN.chainId;
|
|
4923
|
+
const provider = new import_ethers.ethers.JsonRpcProvider(getRpcUrls("arb")[0]);
|
|
4924
|
+
const erc20 = new import_ethers.ethers.Contract(
|
|
4925
|
+
tokenAddress,
|
|
4926
|
+
[
|
|
4927
|
+
"function name() view returns (string)",
|
|
4928
|
+
"function nonces(address) view returns (uint256)",
|
|
4929
|
+
"function decimals() view returns (uint8)"
|
|
4930
|
+
],
|
|
4931
|
+
provider
|
|
4932
|
+
);
|
|
4933
|
+
const deadline = Math.floor(Date.now() / 1e3) + 86400;
|
|
4934
|
+
const nonce = await erc20.nonces(address);
|
|
4935
|
+
const value = amountWei;
|
|
4936
|
+
const domain = {
|
|
4937
|
+
name,
|
|
4938
|
+
version: "2",
|
|
4939
|
+
chainId: Number(chainId),
|
|
4940
|
+
verifyingContract: tokenAddress
|
|
4941
|
+
};
|
|
4942
|
+
const types = {
|
|
4943
|
+
Permit: [
|
|
4944
|
+
{ name: "owner", type: "address" },
|
|
4945
|
+
{ name: "spender", type: "address" },
|
|
4946
|
+
{ name: "value", type: "uint256" },
|
|
4947
|
+
{ name: "nonce", type: "uint256" },
|
|
4948
|
+
{ name: "deadline", type: "uint256" }
|
|
4949
|
+
]
|
|
4950
|
+
};
|
|
4951
|
+
const values = {
|
|
4952
|
+
owner: address,
|
|
4953
|
+
spender: SPENDER,
|
|
4954
|
+
value,
|
|
4955
|
+
nonce: nonce.toString(),
|
|
4956
|
+
deadline
|
|
4957
|
+
};
|
|
4958
|
+
const signature = await evmWallet.signTypedData({
|
|
4959
|
+
domain,
|
|
4960
|
+
types,
|
|
4961
|
+
values
|
|
4962
|
+
});
|
|
4963
|
+
const { v, r, s } = import_ethers.ethers.Signature.from(signature);
|
|
4964
|
+
const permitParams = {
|
|
4965
|
+
amount: value,
|
|
4966
|
+
deadline,
|
|
4967
|
+
owner: address,
|
|
4968
|
+
r,
|
|
4969
|
+
s,
|
|
4970
|
+
spender: SPENDER,
|
|
4971
|
+
token: tokenAddress,
|
|
4972
|
+
v,
|
|
4973
|
+
nonce: Number(nonce)
|
|
4974
|
+
};
|
|
4975
|
+
return permitParams;
|
|
4976
|
+
}
|
|
4977
|
+
};
|
|
4978
|
+
var Hyperliquid = new HyperliquidService();
|
|
4979
|
+
var HyperliquidFromTokens = tokens.filter((token) => !(token.chainName === "Arbitrum" && token.symbol === "USDC"));
|
|
4980
|
+
var HyperliuquidToToken = DESTINATION_TOKEN;
|
|
4981
|
+
var HyperliuquidMinAmount = MIN_AMOUNT;
|
|
4982
|
+
|
|
4728
4983
|
// src/wallets/near.ts
|
|
4729
4984
|
var import_buffer = require("buffer");
|
|
4730
|
-
var
|
|
4985
|
+
var import_big5 = __toESM(require("big.js"));
|
|
4731
4986
|
var NearWallet = class {
|
|
4732
4987
|
constructor(_selector) {
|
|
4733
4988
|
this.selector = _selector;
|
|
4734
|
-
this.rpcUrl =
|
|
4989
|
+
this.rpcUrl = getRpcUrls("near")[0];
|
|
4735
4990
|
}
|
|
4736
4991
|
async query(contractId, methodName, args = {}) {
|
|
4737
4992
|
const response = await fetch(this.rpcUrl, {
|
|
@@ -5018,10 +5273,10 @@ var NearWallet = class {
|
|
|
5018
5273
|
totalGasLimit = totalGasLimit * 120n / 100n;
|
|
5019
5274
|
const gasPrice = BigInt("100000000");
|
|
5020
5275
|
const estimateGas = totalGasLimit * gasPrice;
|
|
5021
|
-
const estimateGasUsd = (0,
|
|
5022
|
-
result.fees.sourceGasFeeUsd = numberRemoveEndZero((0,
|
|
5276
|
+
const estimateGasUsd = (0, import_big5.default)(estimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
|
|
5277
|
+
result.fees.sourceGasFeeUsd = numberRemoveEndZero((0, import_big5.default)(estimateGasUsd).toFixed(20));
|
|
5023
5278
|
result.estimateSourceGas = estimateGas.toString();
|
|
5024
|
-
result.estimateSourceGasUsd = numberRemoveEndZero((0,
|
|
5279
|
+
result.estimateSourceGasUsd = numberRemoveEndZero((0, import_big5.default)(estimateGasUsd).toFixed(20));
|
|
5025
5280
|
result.sendParam = {
|
|
5026
5281
|
transactions,
|
|
5027
5282
|
callbackUrl: "/"
|
|
@@ -5031,10 +5286,10 @@ var NearWallet = class {
|
|
|
5031
5286
|
const defaultGasLimit = BigInt("80000000000000");
|
|
5032
5287
|
const gasPrice = BigInt("100000000");
|
|
5033
5288
|
const estimateGas = defaultGasLimit * gasPrice;
|
|
5034
|
-
const estimateGasUsd = (0,
|
|
5035
|
-
result.fees.sourceGasFeeUsd = numberRemoveEndZero((0,
|
|
5289
|
+
const estimateGasUsd = (0, import_big5.default)(estimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
|
|
5290
|
+
result.fees.sourceGasFeeUsd = numberRemoveEndZero((0, import_big5.default)(estimateGasUsd).toFixed(20));
|
|
5036
5291
|
result.estimateSourceGas = estimateGas.toString();
|
|
5037
|
-
result.estimateSourceGasUsd = numberRemoveEndZero((0,
|
|
5292
|
+
result.estimateSourceGasUsd = numberRemoveEndZero((0, import_big5.default)(estimateGasUsd).toFixed(20));
|
|
5038
5293
|
}
|
|
5039
5294
|
return result;
|
|
5040
5295
|
}
|
|
@@ -5084,10 +5339,10 @@ var NearWallet = class {
|
|
|
5084
5339
|
};
|
|
5085
5340
|
|
|
5086
5341
|
// src/wallets/solana.ts
|
|
5087
|
-
var
|
|
5342
|
+
var import_web32 = require("@solana/web3.js");
|
|
5088
5343
|
var import_spl_token = require("@solana/spl-token");
|
|
5089
5344
|
var import_anchor = require("@coral-xyz/anchor");
|
|
5090
|
-
var
|
|
5345
|
+
var import_big6 = __toESM(require("big.js"));
|
|
5091
5346
|
|
|
5092
5347
|
// src/bridges/oneclick/stableflow-proxy.json
|
|
5093
5348
|
var stableflow_proxy_default = {
|
|
@@ -5387,9 +5642,107 @@ var stableflow_proxy_default = {
|
|
|
5387
5642
|
};
|
|
5388
5643
|
|
|
5389
5644
|
// src/wallets/solana.ts
|
|
5645
|
+
var import_ethers3 = require("ethers");
|
|
5646
|
+
var import_lz_v2_utilities = require("@layerzerolabs/lz-v2-utilities");
|
|
5647
|
+
|
|
5648
|
+
// src/bridges/usdt0/hop-composer.ts
|
|
5649
|
+
var import_ethers2 = require("ethers");
|
|
5650
|
+
var getHopMsgFee = async (params) => {
|
|
5651
|
+
const {
|
|
5652
|
+
sendParam,
|
|
5653
|
+
toToken
|
|
5654
|
+
} = params;
|
|
5655
|
+
const originLayerzero = USDT0_CONFIG["Arbitrum"];
|
|
5656
|
+
const destinationLayerzero = USDT0_CONFIG[toToken.chainName];
|
|
5657
|
+
let arbitrumOft = originLayerzero.oft;
|
|
5658
|
+
let destinationLayerzeroAddress = destinationLayerzero.oft || destinationLayerzero.oftLegacy;
|
|
5659
|
+
const isDestinationLegacy = destinationLayerzeroAddress === destinationLayerzero.oftLegacy;
|
|
5660
|
+
if (isDestinationLegacy) {
|
|
5661
|
+
arbitrumOft = originLayerzero.oftLegacy || originLayerzero.oft;
|
|
5662
|
+
}
|
|
5663
|
+
const provider = new import_ethers2.ethers.JsonRpcProvider(getRpcUrls("arb")[0]);
|
|
5664
|
+
const oftContractRead = new import_ethers2.ethers.Contract(arbitrumOft, OFT_ABI, provider);
|
|
5665
|
+
try {
|
|
5666
|
+
const msgFee = await oftContractRead.quoteSend.staticCall(sendParam, false);
|
|
5667
|
+
const [nativeFee] = msgFee;
|
|
5668
|
+
return nativeFee * 120n / 100n;
|
|
5669
|
+
} catch (error) {
|
|
5670
|
+
console.log("getHopMsgFee failed: %o", error);
|
|
5671
|
+
throw new Error("Quote multi hop message fee failed");
|
|
5672
|
+
}
|
|
5673
|
+
};
|
|
5674
|
+
|
|
5675
|
+
// src/wallets/utils/layerzero.ts
|
|
5676
|
+
var import_web3 = require("@solana/web3.js");
|
|
5677
|
+
var import_serializers = require("@metaplex-foundation/umi/serializers");
|
|
5678
|
+
var SEEDS = {
|
|
5679
|
+
OFT: Buffer.from("OFT"),
|
|
5680
|
+
PEER: Buffer.from("Peer"),
|
|
5681
|
+
CREDITS: Buffer.from("Credits"),
|
|
5682
|
+
EVENT_AUTHORITY: Buffer.from("__event_authority")
|
|
5683
|
+
};
|
|
5684
|
+
var DISCRIMINATOR = {
|
|
5685
|
+
quoteSend: new Uint8Array([207, 0, 49, 214, 160, 211, 76, 211]),
|
|
5686
|
+
send: new Uint8Array([102, 251, 20, 187, 65, 75, 12, 69])
|
|
5687
|
+
};
|
|
5688
|
+
function u32be(n) {
|
|
5689
|
+
const buf = Buffer.alloc(4);
|
|
5690
|
+
buf.writeUInt32BE(n, 0);
|
|
5691
|
+
return buf;
|
|
5692
|
+
}
|
|
5693
|
+
function deriveOftPdas(programId, dstEid) {
|
|
5694
|
+
return {
|
|
5695
|
+
oftStore: import_web3.PublicKey.findProgramAddressSync([SEEDS.OFT], programId)[0],
|
|
5696
|
+
peer: import_web3.PublicKey.findProgramAddressSync([SEEDS.PEER, u32be(dstEid)], programId)[0],
|
|
5697
|
+
credits: import_web3.PublicKey.findProgramAddressSync([SEEDS.CREDITS], programId)[0],
|
|
5698
|
+
eventAuthority: import_web3.PublicKey.findProgramAddressSync([SEEDS.EVENT_AUTHORITY], programId)[0]
|
|
5699
|
+
};
|
|
5700
|
+
}
|
|
5701
|
+
async function getPeerAddress(connection, programId, dstEid) {
|
|
5702
|
+
const { peer } = deriveOftPdas(programId, dstEid);
|
|
5703
|
+
const info = await connection.getAccountInfo(peer);
|
|
5704
|
+
if (!info) throw new Error(`Peer not found for EID ${dstEid}`);
|
|
5705
|
+
return `0x${info.data.subarray(8, 40).toString("hex")}`;
|
|
5706
|
+
}
|
|
5707
|
+
var quoteSendParamsSerializer = (0, import_serializers.struct)([
|
|
5708
|
+
["dstEid", (0, import_serializers.u32)()],
|
|
5709
|
+
["to", (0, import_serializers.bytes)({ size: 32 })],
|
|
5710
|
+
["amountLd", (0, import_serializers.u64)()],
|
|
5711
|
+
["minAmountLd", (0, import_serializers.u64)()],
|
|
5712
|
+
["extraOptions", (0, import_serializers.bytes)({ size: (0, import_serializers.u32)() })],
|
|
5713
|
+
["composeMsg", (0, import_serializers.option)((0, import_serializers.bytes)({ size: (0, import_serializers.u32)() }))],
|
|
5714
|
+
["payInLzToken", (0, import_serializers.bool)()]
|
|
5715
|
+
]);
|
|
5716
|
+
function encodeQuoteSend(params) {
|
|
5717
|
+
const paramsData = quoteSendParamsSerializer.serialize(params);
|
|
5718
|
+
const data = new Uint8Array(8 + paramsData.length);
|
|
5719
|
+
data.set(DISCRIMINATOR.quoteSend, 0);
|
|
5720
|
+
data.set(paramsData, 8);
|
|
5721
|
+
return data;
|
|
5722
|
+
}
|
|
5723
|
+
var sendParamsSerializer = (0, import_serializers.struct)([
|
|
5724
|
+
["dstEid", (0, import_serializers.u32)()],
|
|
5725
|
+
["to", (0, import_serializers.bytes)({ size: 32 })],
|
|
5726
|
+
["amountLd", (0, import_serializers.u64)()],
|
|
5727
|
+
["minAmountLd", (0, import_serializers.u64)()],
|
|
5728
|
+
["extraOptions", (0, import_serializers.bytes)({ size: (0, import_serializers.u32)() })],
|
|
5729
|
+
["composeMsg", (0, import_serializers.option)((0, import_serializers.bytes)({ size: (0, import_serializers.u32)() }))],
|
|
5730
|
+
["nativeFee", (0, import_serializers.u64)()],
|
|
5731
|
+
["lzTokenFee", (0, import_serializers.u64)()]
|
|
5732
|
+
]);
|
|
5733
|
+
function encodeSend(params) {
|
|
5734
|
+
const paramsData = sendParamsSerializer.serialize(params);
|
|
5735
|
+
const data = new Uint8Array(8 + paramsData.length);
|
|
5736
|
+
data.set(DISCRIMINATOR.send, 0);
|
|
5737
|
+
data.set(paramsData, 8);
|
|
5738
|
+
return data;
|
|
5739
|
+
}
|
|
5740
|
+
|
|
5741
|
+
// src/wallets/solana.ts
|
|
5742
|
+
var import_lz_solana_sdk_v2 = require("@layerzerolabs/lz-solana-sdk-v2");
|
|
5390
5743
|
var SolanaWallet = class {
|
|
5391
5744
|
constructor(options) {
|
|
5392
|
-
this.connection = new
|
|
5745
|
+
this.connection = new import_web32.Connection(getRpcUrls("sol")[0], "confirmed");
|
|
5393
5746
|
this.publicKey = options.publicKey;
|
|
5394
5747
|
this.signTransaction = options.signer.signTransaction;
|
|
5395
5748
|
this.signer = options.signer;
|
|
@@ -5400,10 +5753,10 @@ var SolanaWallet = class {
|
|
|
5400
5753
|
throw new Error("Wallet not connected");
|
|
5401
5754
|
}
|
|
5402
5755
|
const fromPubkey = this.publicKey;
|
|
5403
|
-
const toPubkey = new
|
|
5404
|
-
const lamports = Math.floor(parseFloat(amount) *
|
|
5405
|
-
const transaction = new
|
|
5406
|
-
|
|
5756
|
+
const toPubkey = new import_web32.PublicKey(to);
|
|
5757
|
+
const lamports = Math.floor(parseFloat(amount) * import_web32.LAMPORTS_PER_SOL);
|
|
5758
|
+
const transaction = new import_web32.Transaction().add(
|
|
5759
|
+
import_web32.SystemProgram.transfer({
|
|
5407
5760
|
fromPubkey,
|
|
5408
5761
|
toPubkey,
|
|
5409
5762
|
lamports
|
|
@@ -5425,11 +5778,11 @@ var SolanaWallet = class {
|
|
|
5425
5778
|
throw new Error("Wallet not connected");
|
|
5426
5779
|
}
|
|
5427
5780
|
const fromPubkey = this.publicKey;
|
|
5428
|
-
const toPubkey = new
|
|
5429
|
-
const mint = new
|
|
5781
|
+
const toPubkey = new import_web32.PublicKey(to);
|
|
5782
|
+
const mint = new import_web32.PublicKey(tokenMint);
|
|
5430
5783
|
const fromTokenAccount = (0, import_spl_token.getAssociatedTokenAddressSync)(mint, fromPubkey);
|
|
5431
5784
|
const toTokenAccount = (0, import_spl_token.getAssociatedTokenAddressSync)(mint, toPubkey);
|
|
5432
|
-
const transaction = new
|
|
5785
|
+
const transaction = new import_web32.Transaction();
|
|
5433
5786
|
try {
|
|
5434
5787
|
await (0, import_spl_token.getAccount)(this.connection, toTokenAccount);
|
|
5435
5788
|
} catch (error) {
|
|
@@ -5480,13 +5833,13 @@ var SolanaWallet = class {
|
|
|
5480
5833
|
return result;
|
|
5481
5834
|
}
|
|
5482
5835
|
async getSOLBalance(account) {
|
|
5483
|
-
const publicKey = new
|
|
5836
|
+
const publicKey = new import_web32.PublicKey(account);
|
|
5484
5837
|
const balance = await this.connection.getBalance(publicKey);
|
|
5485
5838
|
return balance;
|
|
5486
5839
|
}
|
|
5487
5840
|
async getTokenBalance(tokenMint, account) {
|
|
5488
|
-
const mint = new
|
|
5489
|
-
const owner = new
|
|
5841
|
+
const mint = new import_web32.PublicKey(tokenMint);
|
|
5842
|
+
const owner = new import_web32.PublicKey(account);
|
|
5490
5843
|
try {
|
|
5491
5844
|
const tokenAccount = await (0, import_spl_token.getAssociatedTokenAddress)(mint, owner);
|
|
5492
5845
|
const accountInfo = await (0, import_spl_token.getAccount)(this.connection, tokenAccount);
|
|
@@ -5519,8 +5872,8 @@ var SolanaWallet = class {
|
|
|
5519
5872
|
let estimatedFee = 5000n;
|
|
5520
5873
|
const { originAsset, depositAddress } = data;
|
|
5521
5874
|
if (originAsset !== "SOL" && originAsset !== "sol") {
|
|
5522
|
-
const mint = new
|
|
5523
|
-
const toPubkey = new
|
|
5875
|
+
const mint = new import_web32.PublicKey(originAsset);
|
|
5876
|
+
const toPubkey = new import_web32.PublicKey(depositAddress);
|
|
5524
5877
|
const toTokenAccount = (0, import_spl_token.getAssociatedTokenAddressSync)(mint, toPubkey);
|
|
5525
5878
|
try {
|
|
5526
5879
|
await (0, import_spl_token.getAccount)(this.connection, toTokenAccount);
|
|
@@ -5569,12 +5922,12 @@ var SolanaWallet = class {
|
|
|
5569
5922
|
return false;
|
|
5570
5923
|
}
|
|
5571
5924
|
async simulateIx(ix) {
|
|
5572
|
-
const tx = new
|
|
5925
|
+
const tx = new import_web32.Transaction().add(ix);
|
|
5573
5926
|
const { blockhash } = await this.connection.getLatestBlockhash();
|
|
5574
5927
|
tx.recentBlockhash = blockhash;
|
|
5575
5928
|
tx.feePayer = this.publicKey;
|
|
5576
5929
|
const message = tx.compileMessage();
|
|
5577
|
-
const versionedTx = new
|
|
5930
|
+
const versionedTx = new import_web32.VersionedTransaction(message);
|
|
5578
5931
|
const sim = await this.connection.simulateTransaction(versionedTx, {
|
|
5579
5932
|
// commitment: "confirmed",
|
|
5580
5933
|
sigVerify: false
|
|
@@ -5621,6 +5974,8 @@ var SolanaWallet = class {
|
|
|
5621
5974
|
return await this.quoteCCTP(params);
|
|
5622
5975
|
case Service.OneClick:
|
|
5623
5976
|
return await this.quoteOneClickProxy(params);
|
|
5977
|
+
case Service.Usdt0:
|
|
5978
|
+
return await this.quoteOFT(params);
|
|
5624
5979
|
default:
|
|
5625
5980
|
throw new Error(`Unsupported quote type: ${type}`);
|
|
5626
5981
|
}
|
|
@@ -5651,20 +6006,20 @@ var SolanaWallet = class {
|
|
|
5651
6006
|
} = params;
|
|
5652
6007
|
try {
|
|
5653
6008
|
const result = { fees: {} };
|
|
5654
|
-
const PROGRAM_ID = new
|
|
5655
|
-
const STATE_PDA = new
|
|
5656
|
-
const MINT = new
|
|
6009
|
+
const PROGRAM_ID = new import_web32.PublicKey(proxyAddress);
|
|
6010
|
+
const STATE_PDA = new import_web32.PublicKey("9E8az3Y9sdXvM2f3CCH6c9N3iFyNfDryQCZhqDxRYGUw");
|
|
6011
|
+
const MINT = new import_web32.PublicKey(fromToken.contractAddress);
|
|
5657
6012
|
const AMOUNT = new import_anchor.BN(amountWei);
|
|
5658
|
-
const RECIPIENT = new
|
|
6013
|
+
const RECIPIENT = new import_web32.PublicKey(depositAddress);
|
|
5659
6014
|
const sender = this.publicKey;
|
|
5660
|
-
const userPubkey = new
|
|
6015
|
+
const userPubkey = new import_web32.PublicKey(refundTo || sender.toString());
|
|
5661
6016
|
const provider = new import_anchor.AnchorProvider(this.connection, this.signer, {
|
|
5662
6017
|
commitment: "confirmed"
|
|
5663
6018
|
});
|
|
5664
6019
|
const program = new import_anchor.Program(stableflow_proxy_default, PROGRAM_ID, provider);
|
|
5665
6020
|
const userTokenAccount = (0, import_spl_token.getAssociatedTokenAddressSync)(MINT, userPubkey);
|
|
5666
6021
|
const toTokenAccount = (0, import_spl_token.getAssociatedTokenAddressSync)(MINT, RECIPIENT);
|
|
5667
|
-
const transaction = new
|
|
6022
|
+
const transaction = new import_web32.Transaction();
|
|
5668
6023
|
try {
|
|
5669
6024
|
await (0, import_spl_token.getAccount)(this.connection, toTokenAccount);
|
|
5670
6025
|
} catch (error) {
|
|
@@ -5689,14 +6044,14 @@ var SolanaWallet = class {
|
|
|
5689
6044
|
tokenProgram: import_spl_token.TOKEN_PROGRAM_ID,
|
|
5690
6045
|
user: userPubkey,
|
|
5691
6046
|
toUser: RECIPIENT,
|
|
5692
|
-
systemProgram:
|
|
6047
|
+
systemProgram: import_web32.SystemProgram.programId
|
|
5693
6048
|
}).instruction();
|
|
5694
6049
|
transaction.add(transferInstruction);
|
|
5695
6050
|
const { blockhash } = await this.connection.getLatestBlockhash();
|
|
5696
6051
|
transaction.recentBlockhash = blockhash;
|
|
5697
6052
|
transaction.feePayer = userPubkey;
|
|
5698
6053
|
const message = transaction.compileMessage();
|
|
5699
|
-
const versionedTx = new
|
|
6054
|
+
const versionedTx = new import_web32.VersionedTransaction(message);
|
|
5700
6055
|
const simulation = await this.connection.simulateTransaction(versionedTx, {
|
|
5701
6056
|
sigVerify: false
|
|
5702
6057
|
});
|
|
@@ -5704,7 +6059,7 @@ var SolanaWallet = class {
|
|
|
5704
6059
|
transaction
|
|
5705
6060
|
};
|
|
5706
6061
|
const estimatedFee = simulation.value.fee || 5000n;
|
|
5707
|
-
const estimateGasUsd = (0,
|
|
6062
|
+
const estimateGasUsd = (0, import_big6.default)(estimatedFee.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
|
|
5708
6063
|
const usd = numberRemoveEndZero(estimateGasUsd.toFixed(20));
|
|
5709
6064
|
const wei = estimatedFee;
|
|
5710
6065
|
result.fees.sourceGasFeeUsd = usd;
|
|
@@ -5744,13 +6099,13 @@ var SolanaWallet = class {
|
|
|
5744
6099
|
estimateSourceGas: void 0,
|
|
5745
6100
|
estimateSourceGasUsd: void 0,
|
|
5746
6101
|
estimateTime: 0,
|
|
5747
|
-
outputAmount: numberRemoveEndZero((0,
|
|
6102
|
+
outputAmount: numberRemoveEndZero((0, import_big6.default)(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0))
|
|
5748
6103
|
};
|
|
5749
|
-
const PROGRAM_ID = new
|
|
5750
|
-
const MINT = new
|
|
6104
|
+
const PROGRAM_ID = new import_web32.PublicKey(proxyAddress);
|
|
6105
|
+
const MINT = new import_web32.PublicKey(fromToken.contractAddress);
|
|
5751
6106
|
const sender = this.publicKey;
|
|
5752
|
-
const userPubkey = new
|
|
5753
|
-
const [userStatePda] =
|
|
6107
|
+
const userPubkey = new import_web32.PublicKey(refundTo || sender.toString());
|
|
6108
|
+
const [userStatePda] = import_web32.PublicKey.findProgramAddressSync(
|
|
5754
6109
|
[Buffer.from("user"), userPubkey.toBuffer()],
|
|
5755
6110
|
PROGRAM_ID
|
|
5756
6111
|
);
|
|
@@ -5767,7 +6122,7 @@ var SolanaWallet = class {
|
|
|
5767
6122
|
const userTokenAccount = (0, import_spl_token.getAssociatedTokenAddressSync)(MINT, userPubkey);
|
|
5768
6123
|
const signatureRes = await cctp_default.quoteSignature({
|
|
5769
6124
|
address: userPubkey.toString(),
|
|
5770
|
-
amount: numberRemoveEndZero((0,
|
|
6125
|
+
amount: numberRemoveEndZero((0, import_big6.default)(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0)),
|
|
5771
6126
|
destination_domain_id: destinationDomain,
|
|
5772
6127
|
receipt_address: recipient,
|
|
5773
6128
|
source_domain_id: sourceDomain,
|
|
@@ -5781,26 +6136,26 @@ var SolanaWallet = class {
|
|
|
5781
6136
|
signature
|
|
5782
6137
|
} = signatureRes;
|
|
5783
6138
|
result.fees.estimateMintGasUsd = numberRemoveEndZero(
|
|
5784
|
-
(0,
|
|
6139
|
+
(0, import_big6.default)(mint_fee || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals)
|
|
5785
6140
|
);
|
|
5786
6141
|
result.fees.bridgeFeeUsd = numberRemoveEndZero(
|
|
5787
|
-
(0,
|
|
6142
|
+
(0, import_big6.default)(bridge_fee || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals)
|
|
5788
6143
|
);
|
|
5789
6144
|
result.outputAmount = numberRemoveEndZero(
|
|
5790
|
-
(0,
|
|
6145
|
+
(0, import_big6.default)(receipt_amount || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0)
|
|
5791
6146
|
);
|
|
5792
|
-
const operatorTx =
|
|
6147
|
+
const operatorTx = import_web32.Transaction.from(Buffer.from(signature, "base64"));
|
|
5793
6148
|
if (!operatorTx.verifySignatures(false)) {
|
|
5794
6149
|
console.log("\u274C Signature verification failed");
|
|
5795
6150
|
} else {
|
|
5796
6151
|
}
|
|
5797
6152
|
const message = operatorTx.compileMessage();
|
|
5798
|
-
const versionedTx = new
|
|
6153
|
+
const versionedTx = new import_web32.VersionedTransaction(message);
|
|
5799
6154
|
const simulation = await this.connection.simulateTransaction(versionedTx, {
|
|
5800
6155
|
sigVerify: false
|
|
5801
6156
|
});
|
|
5802
6157
|
const estimatedFee = simulation.value.fee || 5000n;
|
|
5803
|
-
const estimateGasUsd = (0,
|
|
6158
|
+
const estimateGasUsd = (0, import_big6.default)(estimatedFee.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
|
|
5804
6159
|
result.fees.estimateDepositGasUsd = numberRemoveEndZero(estimateGasUsd.toFixed(20));
|
|
5805
6160
|
result.estimateSourceGas = estimatedFee;
|
|
5806
6161
|
result.estimateSourceGasUsd = numberRemoveEndZero(estimateGasUsd.toFixed(20));
|
|
@@ -5811,15 +6166,249 @@ var SolanaWallet = class {
|
|
|
5811
6166
|
if (excludeFees4 && excludeFees4.includes(feeKey) || !/Usd$/.test(feeKey)) {
|
|
5812
6167
|
continue;
|
|
5813
6168
|
}
|
|
5814
|
-
result.totalFeesUsd = (0,
|
|
6169
|
+
result.totalFeesUsd = (0, import_big6.default)(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
|
|
5815
6170
|
}
|
|
5816
|
-
result.totalFeesUsd = numberRemoveEndZero((0,
|
|
6171
|
+
result.totalFeesUsd = numberRemoveEndZero((0, import_big6.default)(result.totalFeesUsd || 0).toFixed(20));
|
|
5817
6172
|
return result;
|
|
5818
6173
|
} catch (error) {
|
|
5819
6174
|
console.log("quoteCCTP failed: %o", error);
|
|
5820
6175
|
return { errMsg: error.message };
|
|
5821
6176
|
}
|
|
5822
6177
|
}
|
|
6178
|
+
async quoteOFT(params) {
|
|
6179
|
+
const {
|
|
6180
|
+
originLayerzeroAddress,
|
|
6181
|
+
destinationLayerzeroAddress,
|
|
6182
|
+
fromToken,
|
|
6183
|
+
toToken,
|
|
6184
|
+
dstEid,
|
|
6185
|
+
refundTo,
|
|
6186
|
+
recipient,
|
|
6187
|
+
amountWei,
|
|
6188
|
+
payInLzToken,
|
|
6189
|
+
slippageTolerance,
|
|
6190
|
+
multiHopComposer,
|
|
6191
|
+
isMultiHopComposer,
|
|
6192
|
+
isOriginLegacy,
|
|
6193
|
+
prices,
|
|
6194
|
+
excludeFees: excludeFees4,
|
|
6195
|
+
originLayerzero
|
|
6196
|
+
} = params;
|
|
6197
|
+
try {
|
|
6198
|
+
const result = {
|
|
6199
|
+
needApprove: false,
|
|
6200
|
+
sendParam: void 0,
|
|
6201
|
+
fees: {},
|
|
6202
|
+
estimateSourceGas: void 0,
|
|
6203
|
+
estimateSourceGasUsd: void 0,
|
|
6204
|
+
outputAmount: numberRemoveEndZero((0, import_big6.default)(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0)),
|
|
6205
|
+
quoteParam: {
|
|
6206
|
+
...params
|
|
6207
|
+
},
|
|
6208
|
+
totalFeesUsd: void 0,
|
|
6209
|
+
estimateTime: 0
|
|
6210
|
+
};
|
|
6211
|
+
const programId = new import_web32.PublicKey(originLayerzeroAddress);
|
|
6212
|
+
const tokenMint = new import_web32.PublicKey(fromToken.contractAddress);
|
|
6213
|
+
const quotePayer = new import_web32.PublicKey("4NkxtcfRTCxJ1N2j6xENcDLPbiJ3541T6r5BqhTzMD9J");
|
|
6214
|
+
const lookupTable = new import_web32.PublicKey("6zcTrmdkiQp6dZHYUxVr6A2XVDSYi44X1rcPtvwNcrXi");
|
|
6215
|
+
const tokenEscrow = new import_web32.PublicKey("F1YkdxaiLA1eJt12y3uMAQef48Td3zdJfYhzjphma8hG");
|
|
6216
|
+
const sender = this.publicKey;
|
|
6217
|
+
const userPubkey = new import_web32.PublicKey(refundTo || sender.toString());
|
|
6218
|
+
const mintInfo = await this.connection.getParsedAccountInfo(tokenMint);
|
|
6219
|
+
const decimals = (mintInfo.value?.data).parsed.info.decimals;
|
|
6220
|
+
const amountLd = BigInt(amountWei);
|
|
6221
|
+
const slippage = slippageTolerance || 0.01;
|
|
6222
|
+
const minAmountLd = BigInt((0, import_big6.default)(amountWei).times((0, import_big6.default)(1).minus((0, import_big6.default)(slippage).div(100))).toFixed(0));
|
|
6223
|
+
const lzReceiveOptionGas = isOriginLegacy ? originLayerzero.lzReceiveOptionGasLegacy : originLayerzero.lzReceiveOptionGas;
|
|
6224
|
+
const lzReceiveOptionValue = LZ_RECEIVE_VALUE[toToken.chainName] || 0;
|
|
6225
|
+
let _dstEid = dstEid;
|
|
6226
|
+
let to = new Uint8Array(Buffer.from((0, import_lz_v2_utilities.addressToBytes32)(recipient)));
|
|
6227
|
+
let extraOptions = import_lz_v2_utilities.Options.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).toBytes();
|
|
6228
|
+
let composeMsg = null;
|
|
6229
|
+
if (isMultiHopComposer) {
|
|
6230
|
+
_dstEid = multiHopComposer.eid;
|
|
6231
|
+
to = new Uint8Array(Buffer.from((0, import_lz_v2_utilities.addressToBytes32)(multiHopComposer.oftMultiHopComposer)));
|
|
6232
|
+
const composeMsgSendParam = {
|
|
6233
|
+
dstEid,
|
|
6234
|
+
to: (0, import_lz_v2_utilities.addressToBytes32)(recipient),
|
|
6235
|
+
amountLD: amountLd,
|
|
6236
|
+
minAmountLD: minAmountLd,
|
|
6237
|
+
extraOptions: import_lz_v2_utilities.Options.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).toHex(),
|
|
6238
|
+
composeMsg: "0x",
|
|
6239
|
+
oftCmd: "0x"
|
|
6240
|
+
};
|
|
6241
|
+
const hopMsgFee = await getHopMsgFee({
|
|
6242
|
+
sendParam: composeMsgSendParam,
|
|
6243
|
+
toToken
|
|
6244
|
+
});
|
|
6245
|
+
extraOptions = import_lz_v2_utilities.Options.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).addExecutorComposeOption(0, originLayerzero.composeOptionGas || 5e5, hopMsgFee).toBytes();
|
|
6246
|
+
const abiCoder = import_ethers3.ethers.AbiCoder.defaultAbiCoder();
|
|
6247
|
+
const composeEncoder = abiCoder.encode(
|
|
6248
|
+
["tuple(uint32 dstEid, bytes32 to, uint256 amountLD, uint256 minAmountLD, bytes extraOptions, bytes composeMsg, bytes oftCmd)"],
|
|
6249
|
+
[Object.values(composeMsgSendParam)]
|
|
6250
|
+
);
|
|
6251
|
+
composeMsg = import_ethers3.ethers.getBytes(composeEncoder);
|
|
6252
|
+
}
|
|
6253
|
+
const pdas = deriveOftPdas(programId, _dstEid);
|
|
6254
|
+
const peerAddress = await getPeerAddress(this.connection, programId, _dstEid);
|
|
6255
|
+
const tokenSource = await (0, import_spl_token.getAssociatedTokenAddress)(
|
|
6256
|
+
tokenMint,
|
|
6257
|
+
userPubkey,
|
|
6258
|
+
false,
|
|
6259
|
+
import_spl_token.TOKEN_PROGRAM_ID
|
|
6260
|
+
);
|
|
6261
|
+
const sendHelper = new import_lz_solana_sdk_v2.SendHelper();
|
|
6262
|
+
const remainingAccounts = await sendHelper.getQuoteAccounts(
|
|
6263
|
+
this.connection,
|
|
6264
|
+
quotePayer,
|
|
6265
|
+
pdas.oftStore,
|
|
6266
|
+
_dstEid,
|
|
6267
|
+
peerAddress
|
|
6268
|
+
);
|
|
6269
|
+
const ix = new import_web32.TransactionInstruction({
|
|
6270
|
+
programId,
|
|
6271
|
+
keys: [
|
|
6272
|
+
{ pubkey: pdas.oftStore, isSigner: false, isWritable: false },
|
|
6273
|
+
{ pubkey: pdas.credits, isSigner: false, isWritable: false },
|
|
6274
|
+
{ pubkey: pdas.peer, isSigner: false, isWritable: false },
|
|
6275
|
+
...remainingAccounts
|
|
6276
|
+
],
|
|
6277
|
+
data: Buffer.from(
|
|
6278
|
+
encodeQuoteSend({
|
|
6279
|
+
dstEid: _dstEid,
|
|
6280
|
+
to,
|
|
6281
|
+
amountLd,
|
|
6282
|
+
minAmountLd,
|
|
6283
|
+
extraOptions,
|
|
6284
|
+
composeMsg,
|
|
6285
|
+
payInLzToken: false
|
|
6286
|
+
})
|
|
6287
|
+
)
|
|
6288
|
+
});
|
|
6289
|
+
const computeIx = import_web32.ComputeBudgetProgram.setComputeUnitLimit({ units: 14e5 });
|
|
6290
|
+
const tx = await (0, import_lz_solana_sdk_v2.buildVersionedTransaction)(
|
|
6291
|
+
this.connection,
|
|
6292
|
+
quotePayer,
|
|
6293
|
+
[computeIx, ix],
|
|
6294
|
+
void 0,
|
|
6295
|
+
void 0,
|
|
6296
|
+
lookupTable
|
|
6297
|
+
);
|
|
6298
|
+
const sim = await this.connection.simulateTransaction(tx, {
|
|
6299
|
+
sigVerify: false,
|
|
6300
|
+
replaceRecentBlockhash: true
|
|
6301
|
+
});
|
|
6302
|
+
if (sim.value.err) {
|
|
6303
|
+
console.error("Simulation logs:", sim.value.logs);
|
|
6304
|
+
throw new Error(`Quote failed: ${JSON.stringify(sim.value.err)}`);
|
|
6305
|
+
}
|
|
6306
|
+
const prefix = `Program return: ${programId} `;
|
|
6307
|
+
const log = sim.value.logs?.find((l) => l.startsWith(prefix));
|
|
6308
|
+
if (!log) throw new Error("Return data not found");
|
|
6309
|
+
const data = Buffer.from(log.slice(prefix.length), "base64");
|
|
6310
|
+
const nativeFee = data.readBigUInt64LE(0);
|
|
6311
|
+
const lzTokenFee = data.readBigUInt64LE(8);
|
|
6312
|
+
if (prices && fromToken.nativeToken) {
|
|
6313
|
+
const nativeFeeUsd = (0, import_big6.default)(nativeFee.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
|
|
6314
|
+
result.fees.nativeFeeUsd = numberRemoveEndZero(nativeFeeUsd.toFixed(20));
|
|
6315
|
+
}
|
|
6316
|
+
result.fees.nativeFee = (0, import_big6.default)(nativeFee.toString()).div(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals, 0);
|
|
6317
|
+
if (lzTokenFee > 0n && prices && fromToken) {
|
|
6318
|
+
const lzTokenFeeUsd = (0, import_big6.default)(lzTokenFee.toString()).div(10 ** fromToken.decimals).times(getPrice(prices, fromToken.symbol));
|
|
6319
|
+
result.fees.lzTokenFeeUsd = numberRemoveEndZero(lzTokenFeeUsd.toFixed(20));
|
|
6320
|
+
}
|
|
6321
|
+
result.fees.lzTokenFee = lzTokenFee.toString();
|
|
6322
|
+
const sendSendHelper = new import_lz_solana_sdk_v2.SendHelper();
|
|
6323
|
+
const sendRemainingAccounts = await sendSendHelper.getSendAccounts(
|
|
6324
|
+
this.connection,
|
|
6325
|
+
userPubkey,
|
|
6326
|
+
pdas.oftStore,
|
|
6327
|
+
_dstEid,
|
|
6328
|
+
peerAddress
|
|
6329
|
+
);
|
|
6330
|
+
const sendIx = new import_web32.TransactionInstruction({
|
|
6331
|
+
programId,
|
|
6332
|
+
keys: [
|
|
6333
|
+
{ pubkey: userPubkey, isSigner: true, isWritable: true },
|
|
6334
|
+
{ pubkey: pdas.peer, isSigner: false, isWritable: false },
|
|
6335
|
+
{ pubkey: pdas.oftStore, isSigner: false, isWritable: true },
|
|
6336
|
+
{ pubkey: pdas.credits, isSigner: false, isWritable: true },
|
|
6337
|
+
{ pubkey: tokenSource, isSigner: false, isWritable: true },
|
|
6338
|
+
{ pubkey: tokenEscrow, isSigner: false, isWritable: true },
|
|
6339
|
+
{ pubkey: tokenMint, isSigner: false, isWritable: false },
|
|
6340
|
+
{ pubkey: import_spl_token.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
6341
|
+
{ pubkey: pdas.eventAuthority, isSigner: false, isWritable: false },
|
|
6342
|
+
{ pubkey: programId, isSigner: false, isWritable: false },
|
|
6343
|
+
...sendRemainingAccounts
|
|
6344
|
+
],
|
|
6345
|
+
data: Buffer.from(
|
|
6346
|
+
encodeSend({
|
|
6347
|
+
dstEid: _dstEid,
|
|
6348
|
+
to,
|
|
6349
|
+
amountLd,
|
|
6350
|
+
minAmountLd,
|
|
6351
|
+
extraOptions,
|
|
6352
|
+
composeMsg,
|
|
6353
|
+
nativeFee,
|
|
6354
|
+
lzTokenFee: 0n
|
|
6355
|
+
})
|
|
6356
|
+
)
|
|
6357
|
+
});
|
|
6358
|
+
const computeSendIx = import_web32.ComputeBudgetProgram.setComputeUnitLimit({ units: 4e5 });
|
|
6359
|
+
const sendTx = await (0, import_lz_solana_sdk_v2.buildVersionedTransaction)(
|
|
6360
|
+
this.connection,
|
|
6361
|
+
userPubkey,
|
|
6362
|
+
[computeSendIx, sendIx],
|
|
6363
|
+
void 0,
|
|
6364
|
+
void 0,
|
|
6365
|
+
lookupTable
|
|
6366
|
+
);
|
|
6367
|
+
let estimatedFee = 5000n;
|
|
6368
|
+
try {
|
|
6369
|
+
const sendSim = await this.connection.simulateTransaction(sendTx, {
|
|
6370
|
+
sigVerify: false,
|
|
6371
|
+
replaceRecentBlockhash: true
|
|
6372
|
+
});
|
|
6373
|
+
console.log("sendSim: %o", JSON.stringify(sendSim));
|
|
6374
|
+
if (!sendSim.value.err) {
|
|
6375
|
+
estimatedFee = sendSim.value.fee || 5000n;
|
|
6376
|
+
} else {
|
|
6377
|
+
console.warn("Send simulation failed (this is normal in quote phase):", sendSim.value.err);
|
|
6378
|
+
const fee = sendSim.value.fee;
|
|
6379
|
+
if (fee) {
|
|
6380
|
+
estimatedFee = fee;
|
|
6381
|
+
}
|
|
6382
|
+
}
|
|
6383
|
+
} catch (simError) {
|
|
6384
|
+
console.warn("Send simulation error (this is normal in quote phase):", simError.message);
|
|
6385
|
+
}
|
|
6386
|
+
if (prices && fromToken.nativeToken) {
|
|
6387
|
+
const estimateGasUsd = (0, import_big6.default)(estimatedFee.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
|
|
6388
|
+
result.fees.estimateSourceGasUsd = numberRemoveEndZero(estimateGasUsd.toFixed(20));
|
|
6389
|
+
result.estimateSourceGasUsd = numberRemoveEndZero(estimateGasUsd.toFixed(20));
|
|
6390
|
+
}
|
|
6391
|
+
result.estimateSourceGas = estimatedFee;
|
|
6392
|
+
result.fees.legacyMeshFeeUsd = numberRemoveEndZero((0, import_big6.default)(amountWei || 0).div(10 ** params.fromToken.decimals).times(USDT0_LEGACY_MESH_TRANSFTER_FEE).toFixed(params.fromToken.decimals));
|
|
6393
|
+
result.outputAmount = numberRemoveEndZero((0, import_big6.default)((0, import_big6.default)(amountWei || 0).div(10 ** params.fromToken.decimals)).minus(result.fees.legacyMeshFeeUsd || 0).toFixed(params.fromToken.decimals, 0));
|
|
6394
|
+
result.sendParam = {
|
|
6395
|
+
transaction: sendTx
|
|
6396
|
+
};
|
|
6397
|
+
if (prices) {
|
|
6398
|
+
for (const feeKey in result.fees) {
|
|
6399
|
+
if (excludeFees4 && excludeFees4.includes(feeKey) || !/Usd$/.test(feeKey)) {
|
|
6400
|
+
continue;
|
|
6401
|
+
}
|
|
6402
|
+
result.totalFeesUsd = (0, import_big6.default)(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
|
|
6403
|
+
}
|
|
6404
|
+
result.totalFeesUsd = numberRemoveEndZero((0, import_big6.default)(result.totalFeesUsd || 0).toFixed(20));
|
|
6405
|
+
}
|
|
6406
|
+
return result;
|
|
6407
|
+
} catch (error) {
|
|
6408
|
+
console.log("quoteOFT failed: %o", error);
|
|
6409
|
+
return { errMsg: error.message };
|
|
6410
|
+
}
|
|
6411
|
+
}
|
|
5823
6412
|
async createAssociatedTokenAddress(params) {
|
|
5824
6413
|
const {
|
|
5825
6414
|
tokenMint
|
|
@@ -5828,11 +6417,11 @@ var SolanaWallet = class {
|
|
|
5828
6417
|
throw new Error("Wallet not connected");
|
|
5829
6418
|
}
|
|
5830
6419
|
const ownerPubkey = this.publicKey;
|
|
5831
|
-
const mint = new
|
|
6420
|
+
const mint = new import_web32.PublicKey(tokenMint);
|
|
5832
6421
|
const associatedTokenAccount = (0, import_spl_token.getAssociatedTokenAddressSync)(mint, ownerPubkey);
|
|
5833
6422
|
console.log("associatedTokenAccount: %o", associatedTokenAccount);
|
|
5834
6423
|
const createTokenAccount = async () => {
|
|
5835
|
-
const transaction = new
|
|
6424
|
+
const transaction = new import_web32.Transaction();
|
|
5836
6425
|
transaction.add(
|
|
5837
6426
|
(0, import_spl_token.createAssociatedTokenAccountInstruction)(
|
|
5838
6427
|
ownerPubkey,
|
|
@@ -5904,13 +6493,13 @@ var erc20_default = [
|
|
|
5904
6493
|
];
|
|
5905
6494
|
|
|
5906
6495
|
// src/wallets/evm.ts
|
|
5907
|
-
var
|
|
5908
|
-
var
|
|
5909
|
-
var
|
|
6496
|
+
var import_big7 = __toESM(require("big.js"));
|
|
6497
|
+
var import_ethers5 = require("ethers");
|
|
6498
|
+
var import_lz_v2_utilities2 = require("@layerzerolabs/lz-v2-utilities");
|
|
5910
6499
|
|
|
5911
6500
|
// src/utils/address.ts
|
|
5912
6501
|
var import_bs58 = __toESM(require("bs58"));
|
|
5913
|
-
var
|
|
6502
|
+
var import_ethers4 = require("ethers");
|
|
5914
6503
|
function tronAddressToBytes32(tronAddress) {
|
|
5915
6504
|
try {
|
|
5916
6505
|
const decoded = import_bs58.default.decode(tronAddress);
|
|
@@ -5936,9 +6525,9 @@ function solanaAddressToBytes32(solanaAddress) {
|
|
|
5936
6525
|
}
|
|
5937
6526
|
return "0x" + Buffer.from(decoded).toString("hex");
|
|
5938
6527
|
}
|
|
5939
|
-
function
|
|
6528
|
+
function addressToBytes322(chainType, address) {
|
|
5940
6529
|
if (chainType === "evm") {
|
|
5941
|
-
return (0,
|
|
6530
|
+
return (0, import_ethers4.zeroPadValue)(address, 32);
|
|
5942
6531
|
}
|
|
5943
6532
|
if (chainType === "sol") {
|
|
5944
6533
|
return solanaAddressToBytes32(address);
|
|
@@ -5948,9 +6537,40 @@ function addressToBytes32(chainType, address) {
|
|
|
5948
6537
|
}
|
|
5949
6538
|
}
|
|
5950
6539
|
|
|
5951
|
-
// src/wallets/
|
|
5952
|
-
var import_web32 = require("@solana/web3.js");
|
|
6540
|
+
// src/wallets/utils/solana.ts
|
|
5953
6541
|
var import_spl_token2 = require("@solana/spl-token");
|
|
6542
|
+
var import_web33 = require("@solana/web3.js");
|
|
6543
|
+
var getDestinationAssociatedTokenAddress = async (params) => {
|
|
6544
|
+
const {
|
|
6545
|
+
recipient,
|
|
6546
|
+
toToken
|
|
6547
|
+
} = params;
|
|
6548
|
+
const result = {
|
|
6549
|
+
needCreateTokenAccount: false,
|
|
6550
|
+
associatedTokenAddress: ""
|
|
6551
|
+
};
|
|
6552
|
+
if (toToken.chainType !== "sol") {
|
|
6553
|
+
return result;
|
|
6554
|
+
}
|
|
6555
|
+
try {
|
|
6556
|
+
const connection = new import_web33.Connection(getRpcUrls("sol")[0]);
|
|
6557
|
+
const wallet = new import_web33.PublicKey(recipient);
|
|
6558
|
+
const TOKEN_MINT = new import_web33.PublicKey(toToken.contractAddress);
|
|
6559
|
+
const ata = (0, import_spl_token2.getAssociatedTokenAddressSync)(TOKEN_MINT, wallet);
|
|
6560
|
+
const accountInfo = await connection.getAccountInfo(ata);
|
|
6561
|
+
console.log("accountInfo: %o", accountInfo);
|
|
6562
|
+
if (!accountInfo) {
|
|
6563
|
+
result.needCreateTokenAccount = true;
|
|
6564
|
+
return result;
|
|
6565
|
+
}
|
|
6566
|
+
result.associatedTokenAddress = ata.toBase58();
|
|
6567
|
+
} catch (error) {
|
|
6568
|
+
console.log("getDestinationAssociatedTokenAddress failed: %o", error);
|
|
6569
|
+
}
|
|
6570
|
+
return result;
|
|
6571
|
+
};
|
|
6572
|
+
|
|
6573
|
+
// src/wallets/evm.ts
|
|
5954
6574
|
var DEFAULT_GAS_LIMIT = 100000n;
|
|
5955
6575
|
var EVMWallet = class {
|
|
5956
6576
|
constructor(_provider, _signer) {
|
|
@@ -5962,12 +6582,12 @@ var EVMWallet = class {
|
|
|
5962
6582
|
if (originAsset === "eth") {
|
|
5963
6583
|
const tx2 = await this.signer.sendTransaction({
|
|
5964
6584
|
to: depositAddress,
|
|
5965
|
-
value:
|
|
6585
|
+
value: import_ethers5.ethers.parseEther(amount)
|
|
5966
6586
|
});
|
|
5967
6587
|
await tx2.wait();
|
|
5968
6588
|
return tx2;
|
|
5969
6589
|
}
|
|
5970
|
-
const contract = new
|
|
6590
|
+
const contract = new import_ethers5.ethers.Contract(originAsset, erc20_default, this.signer);
|
|
5971
6591
|
const tx = await contract.transfer(depositAddress, amount);
|
|
5972
6592
|
const result = await tx.wait();
|
|
5973
6593
|
return result.hash;
|
|
@@ -5975,14 +6595,15 @@ var EVMWallet = class {
|
|
|
5975
6595
|
async getBalance(token, account) {
|
|
5976
6596
|
try {
|
|
5977
6597
|
let provider = this.provider;
|
|
5978
|
-
if (token.
|
|
5979
|
-
|
|
6598
|
+
if (token.rpcUrls) {
|
|
6599
|
+
const providers = token.rpcUrls.map((url) => new import_ethers5.ethers.JsonRpcProvider(url));
|
|
6600
|
+
provider = new import_ethers5.ethers.FallbackProvider(providers);
|
|
5980
6601
|
}
|
|
5981
6602
|
if (token.symbol === "eth" || token.symbol === "ETH" || token.symbol === "native") {
|
|
5982
6603
|
const balance2 = await provider.getBalance(account);
|
|
5983
6604
|
return balance2.toString();
|
|
5984
6605
|
}
|
|
5985
|
-
const contract = new
|
|
6606
|
+
const contract = new import_ethers5.ethers.Contract(token.contractAddress, erc20_default, provider);
|
|
5986
6607
|
const balance = await contract.balanceOf(account);
|
|
5987
6608
|
return balance.toString();
|
|
5988
6609
|
} catch (err) {
|
|
@@ -6009,11 +6630,11 @@ var EVMWallet = class {
|
|
|
6009
6630
|
const tx = {
|
|
6010
6631
|
from: fromAddress,
|
|
6011
6632
|
to: depositAddress,
|
|
6012
|
-
value:
|
|
6633
|
+
value: import_ethers5.ethers.parseEther(amount)
|
|
6013
6634
|
};
|
|
6014
6635
|
gasLimit = await this.provider.estimateGas(tx);
|
|
6015
6636
|
} else {
|
|
6016
|
-
const contract = new
|
|
6637
|
+
const contract = new import_ethers5.ethers.Contract(originAsset, erc20_default, this.signer);
|
|
6017
6638
|
gasLimit = await contract.transfer.estimateGas(depositAddress, amount);
|
|
6018
6639
|
}
|
|
6019
6640
|
gasLimit = gasLimit * 120n / 100n;
|
|
@@ -6031,7 +6652,7 @@ var EVMWallet = class {
|
|
|
6031
6652
|
contractAddress,
|
|
6032
6653
|
abi
|
|
6033
6654
|
} = params;
|
|
6034
|
-
return new
|
|
6655
|
+
return new import_ethers5.ethers.Contract(contractAddress, abi, this.signer);
|
|
6035
6656
|
}
|
|
6036
6657
|
async allowance(params) {
|
|
6037
6658
|
const {
|
|
@@ -6040,7 +6661,7 @@ var EVMWallet = class {
|
|
|
6040
6661
|
address,
|
|
6041
6662
|
amountWei
|
|
6042
6663
|
} = params;
|
|
6043
|
-
const contract = new
|
|
6664
|
+
const contract = new import_ethers5.ethers.Contract(contractAddress, erc20_default, this.signer);
|
|
6044
6665
|
let allowance = "0";
|
|
6045
6666
|
try {
|
|
6046
6667
|
allowance = await contract.allowance(address, spender);
|
|
@@ -6051,7 +6672,7 @@ var EVMWallet = class {
|
|
|
6051
6672
|
return {
|
|
6052
6673
|
contract,
|
|
6053
6674
|
allowance,
|
|
6054
|
-
needApprove: (0,
|
|
6675
|
+
needApprove: (0, import_big7.default)(amountWei || 0).gt(allowance || 0)
|
|
6055
6676
|
};
|
|
6056
6677
|
}
|
|
6057
6678
|
async approve(params) {
|
|
@@ -6061,10 +6682,10 @@ var EVMWallet = class {
|
|
|
6061
6682
|
amountWei,
|
|
6062
6683
|
isApproveMax = false
|
|
6063
6684
|
} = params;
|
|
6064
|
-
const contract = new
|
|
6685
|
+
const contract = new import_ethers5.ethers.Contract(contractAddress, erc20_default, this.signer);
|
|
6065
6686
|
let _amountWei = amountWei;
|
|
6066
6687
|
if (isApproveMax) {
|
|
6067
|
-
_amountWei =
|
|
6688
|
+
_amountWei = import_ethers5.ethers.MaxUint256;
|
|
6068
6689
|
}
|
|
6069
6690
|
try {
|
|
6070
6691
|
const tx = await contract.approve(spender, _amountWei);
|
|
@@ -6083,13 +6704,13 @@ var EVMWallet = class {
|
|
|
6083
6704
|
const feeData = await this.provider.getFeeData();
|
|
6084
6705
|
const gasPrice = feeData.maxFeePerGas || feeData.gasPrice || BigInt("20000000000");
|
|
6085
6706
|
const estimateGas = BigInt(gasLimit) * BigInt(gasPrice);
|
|
6086
|
-
const estimateGasAmount = (0,
|
|
6087
|
-
const estimateGasUsd = (0,
|
|
6707
|
+
const estimateGasAmount = (0, import_big7.default)(estimateGas.toString()).div(10 ** nativeToken.decimals);
|
|
6708
|
+
const estimateGasUsd = (0, import_big7.default)(estimateGasAmount).times(price || 1);
|
|
6088
6709
|
return {
|
|
6089
6710
|
gasPrice,
|
|
6090
|
-
usd: numberRemoveEndZero((0,
|
|
6711
|
+
usd: numberRemoveEndZero((0, import_big7.default)(estimateGasUsd).toFixed(20)),
|
|
6091
6712
|
wei: estimateGas,
|
|
6092
|
-
amount: numberRemoveEndZero((0,
|
|
6713
|
+
amount: numberRemoveEndZero((0, import_big7.default)(estimateGasAmount).toFixed(nativeToken.decimals))
|
|
6093
6714
|
};
|
|
6094
6715
|
}
|
|
6095
6716
|
async quoteOFT(params) {
|
|
@@ -6110,7 +6731,8 @@ var EVMWallet = class {
|
|
|
6110
6731
|
multiHopComposer,
|
|
6111
6732
|
isMultiHopComposer,
|
|
6112
6733
|
isOriginLegacy,
|
|
6113
|
-
isDestinationLegacy
|
|
6734
|
+
isDestinationLegacy,
|
|
6735
|
+
originLayerzero
|
|
6114
6736
|
} = params;
|
|
6115
6737
|
const result = {
|
|
6116
6738
|
needApprove: false,
|
|
@@ -6127,12 +6749,11 @@ var EVMWallet = class {
|
|
|
6127
6749
|
estimateSourceGasUsd: void 0,
|
|
6128
6750
|
estimateTime: 0,
|
|
6129
6751
|
// seconds - dynamically calculated using LayerZero formula
|
|
6130
|
-
outputAmount: numberRemoveEndZero((0,
|
|
6752
|
+
outputAmount: numberRemoveEndZero((0, import_big7.default)(amountWei || 0).div(10 ** params.fromToken.decimals).toFixed(params.fromToken.decimals, 0))
|
|
6131
6753
|
};
|
|
6132
|
-
const oftContract = new
|
|
6133
|
-
const oftContractRead = new
|
|
6754
|
+
const oftContract = new import_ethers5.ethers.Contract(originLayerzeroAddress, abi, this.signer);
|
|
6755
|
+
const oftContractRead = new import_ethers5.ethers.Contract(originLayerzeroAddress, abi, this.provider);
|
|
6134
6756
|
const approvalRequired = await oftContractRead.approvalRequired();
|
|
6135
|
-
console.log("%cApprovalRequired: %o", "background:blue;color:white;", approvalRequired);
|
|
6136
6757
|
if (approvalRequired) {
|
|
6137
6758
|
try {
|
|
6138
6759
|
const allowanceResult = await this.allowance({
|
|
@@ -6146,42 +6767,52 @@ var EVMWallet = class {
|
|
|
6146
6767
|
console.log("Error checking allowance: %o", error);
|
|
6147
6768
|
}
|
|
6148
6769
|
}
|
|
6770
|
+
const lzReceiveOptionGas = isOriginLegacy ? originLayerzero.lzReceiveOptionGasLegacy : originLayerzero.lzReceiveOptionGas;
|
|
6771
|
+
let lzReceiveOptionValue = 0;
|
|
6772
|
+
const destATA = await getDestinationAssociatedTokenAddress({
|
|
6773
|
+
recipient,
|
|
6774
|
+
toToken
|
|
6775
|
+
});
|
|
6776
|
+
if (destATA.needCreateTokenAccount) {
|
|
6777
|
+
lzReceiveOptionValue = LZ_RECEIVE_VALUE[toToken.chainName] || 0;
|
|
6778
|
+
}
|
|
6149
6779
|
const sendParam = {
|
|
6150
6780
|
dstEid,
|
|
6151
|
-
to:
|
|
6781
|
+
to: addressToBytes322(toToken.chainType, recipient),
|
|
6152
6782
|
amountLD: amountWei,
|
|
6153
6783
|
minAmountLD: 0n,
|
|
6154
|
-
extraOptions:
|
|
6784
|
+
extraOptions: import_lz_v2_utilities2.Options.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).toHex(),
|
|
6155
6785
|
composeMsg: "0x",
|
|
6156
6786
|
oftCmd: "0x"
|
|
6157
6787
|
};
|
|
6158
6788
|
if (isMultiHopComposer) {
|
|
6159
6789
|
sendParam.dstEid = multiHopComposer.eid;
|
|
6160
|
-
sendParam.to =
|
|
6161
|
-
|
|
6162
|
-
|
|
6790
|
+
sendParam.to = addressToBytes322("evm", multiHopComposer.oftMultiHopComposer);
|
|
6791
|
+
const composeMsgSendParam = {
|
|
6792
|
+
dstEid,
|
|
6793
|
+
to: addressToBytes322(toToken.chainType, recipient),
|
|
6794
|
+
amountLD: sendParam.amountLD,
|
|
6795
|
+
minAmountLD: sendParam.minAmountLD,
|
|
6796
|
+
extraOptions: import_lz_v2_utilities2.Options.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).toHex(),
|
|
6797
|
+
composeMsg: "0x",
|
|
6798
|
+
oftCmd: "0x"
|
|
6799
|
+
};
|
|
6800
|
+
const hopMsgFee = await getHopMsgFee({
|
|
6801
|
+
sendParam: composeMsgSendParam,
|
|
6802
|
+
toToken
|
|
6803
|
+
});
|
|
6804
|
+
sendParam.extraOptions = import_lz_v2_utilities2.Options.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).addExecutorComposeOption(0, originLayerzero.composeOptionGas || 8e5, hopMsgFee).toHex();
|
|
6805
|
+
const abiCoder = import_ethers5.ethers.AbiCoder.defaultAbiCoder();
|
|
6163
6806
|
sendParam.composeMsg = abiCoder.encode(
|
|
6164
6807
|
["tuple(uint32 dstEid, bytes32 to, uint256 amountLD, uint256 minAmountLD, bytes extraOptions, bytes composeMsg, bytes oftCmd)"],
|
|
6165
|
-
[
|
|
6166
|
-
dstEid,
|
|
6167
|
-
addressToBytes32(toToken.chainType, recipient),
|
|
6168
|
-
sendParam.amountLD,
|
|
6169
|
-
sendParam.minAmountLD,
|
|
6170
|
-
"0x",
|
|
6171
|
-
"0x",
|
|
6172
|
-
"0x"
|
|
6173
|
-
]]
|
|
6808
|
+
[Object.values(composeMsgSendParam)]
|
|
6174
6809
|
);
|
|
6175
6810
|
}
|
|
6176
|
-
if (isDestinationLegacy) {
|
|
6177
|
-
result.fees.legacyMeshFeeUsd = numberRemoveEndZero((0, import_big5.default)(amountWei || 0).div(10 ** params.fromToken.decimals).times(3e-4).toFixed(params.fromToken.decimals));
|
|
6178
|
-
}
|
|
6179
6811
|
const oftData = await oftContractRead.quoteOFT.staticCall(sendParam);
|
|
6180
6812
|
const [, , oftReceipt] = oftData;
|
|
6181
6813
|
sendParam.minAmountLD = oftReceipt[1] * (1000000n - BigInt(slippageTolerance * 1e4)) / 1000000n;
|
|
6182
6814
|
const msgFee = await oftContractRead.quoteSend.staticCall(sendParam, payInLzToken);
|
|
6183
6815
|
result.estimateSourceGas = msgFee[0];
|
|
6184
|
-
console.log("%cMsgFee: %o", "background:blue;color:white;", msgFee);
|
|
6185
6816
|
result.sendParam = {
|
|
6186
6817
|
contract: oftContract,
|
|
6187
6818
|
method: "send",
|
|
@@ -6195,13 +6826,13 @@ var EVMWallet = class {
|
|
|
6195
6826
|
{ value: msgFee[0] }
|
|
6196
6827
|
]
|
|
6197
6828
|
};
|
|
6198
|
-
|
|
6199
|
-
|
|
6200
|
-
result.fees.nativeFeeUsd = numberRemoveEndZero((0,
|
|
6201
|
-
result.fees.lzTokenFeeUsd = numberRemoveEndZero((0,
|
|
6202
|
-
if (
|
|
6203
|
-
result.fees.legacyMeshFeeUsd = numberRemoveEndZero((0,
|
|
6204
|
-
result.outputAmount = numberRemoveEndZero((0,
|
|
6829
|
+
const nativeFeeUsd = (0, import_big7.default)(msgFee[0]?.toString() || 0).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
|
|
6830
|
+
result.fees.nativeFee = numberRemoveEndZero((0, import_big7.default)(msgFee[0]?.toString() || 0).div(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals));
|
|
6831
|
+
result.fees.nativeFeeUsd = numberRemoveEndZero((0, import_big7.default)(nativeFeeUsd).toFixed(20));
|
|
6832
|
+
result.fees.lzTokenFeeUsd = numberRemoveEndZero((0, import_big7.default)(msgFee[1]?.toString() || 0).div(10 ** fromToken.decimals).toFixed(20));
|
|
6833
|
+
if (isOriginLegacy || isDestinationLegacy) {
|
|
6834
|
+
result.fees.legacyMeshFeeUsd = numberRemoveEndZero((0, import_big7.default)(amountWei || 0).div(10 ** params.fromToken.decimals).times(USDT0_LEGACY_MESH_TRANSFTER_FEE).toFixed(params.fromToken.decimals));
|
|
6835
|
+
result.outputAmount = numberRemoveEndZero((0, import_big7.default)((0, import_big7.default)(amountWei || 0).div(10 ** params.fromToken.decimals)).minus(result.fees.legacyMeshFeeUsd || 0).toFixed(params.fromToken.decimals, 0));
|
|
6205
6836
|
}
|
|
6206
6837
|
try {
|
|
6207
6838
|
const gasLimit = await oftContract.send.estimateGas(...result.sendParam.param);
|
|
@@ -6227,9 +6858,9 @@ var EVMWallet = class {
|
|
|
6227
6858
|
if (excludeFees4.includes(feeKey)) {
|
|
6228
6859
|
continue;
|
|
6229
6860
|
}
|
|
6230
|
-
result.totalFeesUsd = (0,
|
|
6861
|
+
result.totalFeesUsd = (0, import_big7.default)(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
|
|
6231
6862
|
}
|
|
6232
|
-
result.totalFeesUsd = numberRemoveEndZero((0,
|
|
6863
|
+
result.totalFeesUsd = numberRemoveEndZero((0, import_big7.default)(result.totalFeesUsd).toFixed(20));
|
|
6233
6864
|
return result;
|
|
6234
6865
|
}
|
|
6235
6866
|
async sendTransaction(params) {
|
|
@@ -6307,22 +6938,18 @@ var EVMWallet = class {
|
|
|
6307
6938
|
estimateSourceGas: void 0,
|
|
6308
6939
|
estimateSourceGasUsd: void 0,
|
|
6309
6940
|
estimateTime: Math.floor(Math.random() * 8) + 3,
|
|
6310
|
-
outputAmount: numberRemoveEndZero((0,
|
|
6941
|
+
outputAmount: numberRemoveEndZero((0, import_big7.default)(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0))
|
|
6311
6942
|
};
|
|
6312
|
-
const proxyContract = new
|
|
6313
|
-
const proxyContractRead = new
|
|
6943
|
+
const proxyContract = new import_ethers5.ethers.Contract(proxyAddress, abi, this.signer);
|
|
6944
|
+
const proxyContractRead = new import_ethers5.ethers.Contract(proxyAddress, abi, this.provider);
|
|
6314
6945
|
let realRecipient = recipient;
|
|
6315
|
-
|
|
6316
|
-
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
|
|
6322
|
-
result.needCreateTokenAccount = true;
|
|
6323
|
-
} else {
|
|
6324
|
-
realRecipient = ata.toBase58();
|
|
6325
|
-
}
|
|
6946
|
+
const destATA = await getDestinationAssociatedTokenAddress({
|
|
6947
|
+
recipient,
|
|
6948
|
+
toToken
|
|
6949
|
+
});
|
|
6950
|
+
result.needCreateTokenAccount = destATA.needCreateTokenAccount;
|
|
6951
|
+
if (destATA.associatedTokenAddress) {
|
|
6952
|
+
realRecipient = destATA.associatedTokenAddress;
|
|
6326
6953
|
}
|
|
6327
6954
|
let userNonce = 0n;
|
|
6328
6955
|
try {
|
|
@@ -6331,7 +6958,7 @@ var EVMWallet = class {
|
|
|
6331
6958
|
}
|
|
6332
6959
|
const signatureRes = await cctp_default.quoteSignature({
|
|
6333
6960
|
address: refundTo,
|
|
6334
|
-
amount: numberRemoveEndZero((0,
|
|
6961
|
+
amount: numberRemoveEndZero((0, import_big7.default)(amountWei || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0)),
|
|
6335
6962
|
destination_domain_id: destinationDomain,
|
|
6336
6963
|
receipt_address: realRecipient,
|
|
6337
6964
|
source_domain_id: sourceDomain,
|
|
@@ -6346,10 +6973,10 @@ var EVMWallet = class {
|
|
|
6346
6973
|
signature,
|
|
6347
6974
|
destination_caller
|
|
6348
6975
|
} = signatureRes;
|
|
6349
|
-
result.fees.estimateMintGasUsd = numberRemoveEndZero((0,
|
|
6350
|
-
result.fees.bridgeFeeUsd = numberRemoveEndZero((0,
|
|
6976
|
+
result.fees.estimateMintGasUsd = numberRemoveEndZero((0, import_big7.default)(mint_fee || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals));
|
|
6977
|
+
result.fees.bridgeFeeUsd = numberRemoveEndZero((0, import_big7.default)(bridge_fee || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals));
|
|
6351
6978
|
const chargedAmount = BigInt(amountWei) - BigInt(mint_fee);
|
|
6352
|
-
result.outputAmount = numberRemoveEndZero((0,
|
|
6979
|
+
result.outputAmount = numberRemoveEndZero((0, import_big7.default)(receipt_amount || 0).div(10 ** fromToken.decimals).toFixed(fromToken.decimals, 0));
|
|
6353
6980
|
const depositParam = [
|
|
6354
6981
|
// originalAmount
|
|
6355
6982
|
amountWei,
|
|
@@ -6358,11 +6985,11 @@ var EVMWallet = class {
|
|
|
6358
6985
|
// destinationDomain
|
|
6359
6986
|
destinationDomain,
|
|
6360
6987
|
// mintRecipient
|
|
6361
|
-
|
|
6988
|
+
addressToBytes322(toToken.chainType, realRecipient),
|
|
6362
6989
|
// burnToken
|
|
6363
6990
|
fromToken.contractAddress,
|
|
6364
6991
|
// destinationCaller
|
|
6365
|
-
destination_caller ?
|
|
6992
|
+
destination_caller ? addressToBytes322(toToken.chainType, destination_caller) : "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
6366
6993
|
// maxFee
|
|
6367
6994
|
max_fee,
|
|
6368
6995
|
// minFinalityThreshold
|
|
@@ -6424,9 +7051,9 @@ var EVMWallet = class {
|
|
|
6424
7051
|
if (excludeFees4.includes(feeKey) || !/Usd$/.test(feeKey)) {
|
|
6425
7052
|
continue;
|
|
6426
7053
|
}
|
|
6427
|
-
result.totalFeesUsd = (0,
|
|
7054
|
+
result.totalFeesUsd = (0, import_big7.default)(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
|
|
6428
7055
|
}
|
|
6429
|
-
result.totalFeesUsd = numberRemoveEndZero((0,
|
|
7056
|
+
result.totalFeesUsd = numberRemoveEndZero((0, import_big7.default)(result.totalFeesUsd).toFixed(20));
|
|
6430
7057
|
return result;
|
|
6431
7058
|
}
|
|
6432
7059
|
async quoteOneClickProxy(params) {
|
|
@@ -6452,7 +7079,7 @@ var EVMWallet = class {
|
|
|
6452
7079
|
} catch (error) {
|
|
6453
7080
|
console.log("oneclick check allowance failed: %o", error);
|
|
6454
7081
|
}
|
|
6455
|
-
const proxyContract = new
|
|
7082
|
+
const proxyContract = new import_ethers5.ethers.Contract(proxyAddress, abi, this.signer);
|
|
6456
7083
|
const proxyParam = [
|
|
6457
7084
|
// tokenAddress
|
|
6458
7085
|
fromToken.contractAddress,
|
|
@@ -6470,18 +7097,18 @@ var EVMWallet = class {
|
|
|
6470
7097
|
price: getPrice(prices, fromToken.nativeToken.symbol),
|
|
6471
7098
|
nativeToken: fromToken.nativeToken
|
|
6472
7099
|
});
|
|
6473
|
-
result.fees.sourceGasFeeUsd = numberRemoveEndZero((0,
|
|
7100
|
+
result.fees.sourceGasFeeUsd = numberRemoveEndZero((0, import_big7.default)(usd).toFixed(20));
|
|
6474
7101
|
result.estimateSourceGas = wei;
|
|
6475
|
-
result.estimateSourceGasUsd = numberRemoveEndZero((0,
|
|
7102
|
+
result.estimateSourceGasUsd = numberRemoveEndZero((0, import_big7.default)(usd).toFixed(20));
|
|
6476
7103
|
} catch (error) {
|
|
6477
7104
|
const { usd, wei } = await this.getEstimateGas({
|
|
6478
7105
|
gasLimit: DEFAULT_GAS_LIMIT,
|
|
6479
7106
|
price: getPrice(prices, fromToken.nativeToken.symbol),
|
|
6480
7107
|
nativeToken: fromToken.nativeToken
|
|
6481
7108
|
});
|
|
6482
|
-
result.fees.sourceGasFeeUsd = numberRemoveEndZero((0,
|
|
7109
|
+
result.fees.sourceGasFeeUsd = numberRemoveEndZero((0, import_big7.default)(usd).toFixed(20));
|
|
6483
7110
|
result.estimateSourceGas = wei;
|
|
6484
|
-
result.estimateSourceGasUsd = numberRemoveEndZero((0,
|
|
7111
|
+
result.estimateSourceGasUsd = numberRemoveEndZero((0, import_big7.default)(usd).toFixed(20));
|
|
6485
7112
|
}
|
|
6486
7113
|
result.sendParam = {
|
|
6487
7114
|
method: "proxyTransfer",
|
|
@@ -6493,27 +7120,50 @@ var EVMWallet = class {
|
|
|
6493
7120
|
};
|
|
6494
7121
|
return result;
|
|
6495
7122
|
}
|
|
7123
|
+
async signTypedData(params) {
|
|
7124
|
+
const { domain, types, values } = params;
|
|
7125
|
+
return await this.signer?.signTypedData(domain, types, values);
|
|
7126
|
+
}
|
|
6496
7127
|
};
|
|
6497
7128
|
|
|
6498
7129
|
// src/wallets/tron.ts
|
|
6499
|
-
var
|
|
6500
|
-
var
|
|
6501
|
-
var
|
|
7130
|
+
var import_lz_v2_utilities3 = require("@layerzerolabs/lz-v2-utilities");
|
|
7131
|
+
var import_ethers6 = require("ethers");
|
|
7132
|
+
var import_big8 = __toESM(require("big.js"));
|
|
6502
7133
|
var import_tronweb = require("tronweb");
|
|
7134
|
+
var DefaultTronWalletAddress = DefaultAddresses["tron"];
|
|
7135
|
+
var getCustomTronWeb = () => {
|
|
7136
|
+
return new import_tronweb.TronWeb({
|
|
7137
|
+
fullHost: getRpcUrls("tron")[0],
|
|
7138
|
+
headers: {},
|
|
7139
|
+
privateKey: ""
|
|
7140
|
+
});
|
|
7141
|
+
};
|
|
6503
7142
|
var TronWallet = class {
|
|
6504
7143
|
constructor(options) {
|
|
6505
7144
|
this.signAndSendTransaction = options.signAndSendTransaction;
|
|
6506
|
-
this.
|
|
7145
|
+
this.address = options.address;
|
|
7146
|
+
const customTronWeb = getCustomTronWeb();
|
|
7147
|
+
customTronWeb.setAddress(this.address || DefaultTronWalletAddress);
|
|
7148
|
+
this.tronWeb = customTronWeb;
|
|
6507
7149
|
}
|
|
6508
7150
|
async waitForTronWeb() {
|
|
6509
|
-
return new Promise((resolve2
|
|
7151
|
+
return new Promise((resolve2) => {
|
|
6510
7152
|
if (this.tronWeb) {
|
|
7153
|
+
const address = this.tronWeb.defaultAddress.base58 || DefaultTronWalletAddress;
|
|
7154
|
+
const customTronWeb = getCustomTronWeb();
|
|
7155
|
+
customTronWeb.setAddress(address);
|
|
7156
|
+
this.tronWeb = customTronWeb;
|
|
6511
7157
|
resolve2(this.tronWeb);
|
|
6512
7158
|
return;
|
|
6513
7159
|
}
|
|
6514
7160
|
const checkTronWeb = () => {
|
|
6515
7161
|
if (window.tronWeb) {
|
|
6516
7162
|
this.tronWeb = window.tronWeb;
|
|
7163
|
+
const address = this.tronWeb.defaultAddress.base58 || DefaultTronWalletAddress;
|
|
7164
|
+
const customTronWeb = getCustomTronWeb();
|
|
7165
|
+
customTronWeb.setAddress(address);
|
|
7166
|
+
this.tronWeb = customTronWeb;
|
|
6517
7167
|
resolve2(this.tronWeb);
|
|
6518
7168
|
} else {
|
|
6519
7169
|
setTimeout(checkTronWeb, 100);
|
|
@@ -6521,12 +7171,9 @@ var TronWallet = class {
|
|
|
6521
7171
|
};
|
|
6522
7172
|
checkTronWeb();
|
|
6523
7173
|
setTimeout(() => {
|
|
6524
|
-
|
|
6525
|
-
|
|
6526
|
-
|
|
6527
|
-
privateKey: ""
|
|
6528
|
-
});
|
|
6529
|
-
this.tronWeb.setAddress(DefaultAddresses["tron"]);
|
|
7174
|
+
const customTronWeb = getCustomTronWeb();
|
|
7175
|
+
customTronWeb.setAddress(DefaultTronWalletAddress);
|
|
7176
|
+
this.tronWeb = customTronWeb;
|
|
6530
7177
|
resolve2(this.tronWeb);
|
|
6531
7178
|
console.log(new Error("TronWeb initialization timeout"));
|
|
6532
7179
|
}, 1e4);
|
|
@@ -6590,10 +7237,10 @@ var TronWallet = class {
|
|
|
6590
7237
|
return await this.getBalance(token, account);
|
|
6591
7238
|
}
|
|
6592
7239
|
/**
|
|
6593
|
-
|
|
6594
|
-
|
|
6595
|
-
|
|
6596
|
-
|
|
7240
|
+
* Estimate gas limit for transfer transaction
|
|
7241
|
+
* @param data Transfer data
|
|
7242
|
+
* @returns Gas limit estimate (bandwidth or energy), gas price, and estimated gas cost
|
|
7243
|
+
*/
|
|
6597
7244
|
async estimateTransferGas(data) {
|
|
6598
7245
|
const { originAsset } = data;
|
|
6599
7246
|
await this.waitForTronWeb();
|
|
@@ -6604,14 +7251,7 @@ var TronWallet = class {
|
|
|
6604
7251
|
gasLimit = 30000n;
|
|
6605
7252
|
}
|
|
6606
7253
|
gasLimit = gasLimit * 120n / 100n;
|
|
6607
|
-
let gasPrice;
|
|
6608
|
-
try {
|
|
6609
|
-
const chainParameters = await this.tronWeb.trx.getChainParameters();
|
|
6610
|
-
const energyPrice = chainParameters?.find((p) => p.key === "getEnergyFee")?.value || 420;
|
|
6611
|
-
gasPrice = BigInt(energyPrice);
|
|
6612
|
-
} catch (error) {
|
|
6613
|
-
gasPrice = 420n;
|
|
6614
|
-
}
|
|
7254
|
+
let gasPrice = 100n;
|
|
6615
7255
|
const estimateGas = gasLimit * gasPrice;
|
|
6616
7256
|
return {
|
|
6617
7257
|
gasLimit,
|
|
@@ -6631,6 +7271,15 @@ var TronWallet = class {
|
|
|
6631
7271
|
return false;
|
|
6632
7272
|
}
|
|
6633
7273
|
}
|
|
7274
|
+
async getTransactionResult(txHash) {
|
|
7275
|
+
await this.waitForTronWeb();
|
|
7276
|
+
try {
|
|
7277
|
+
const txInfo = await this.tronWeb.trx.getTransactionInfo(txHash);
|
|
7278
|
+
return txInfo;
|
|
7279
|
+
} catch (error) {
|
|
7280
|
+
return {};
|
|
7281
|
+
}
|
|
7282
|
+
}
|
|
6634
7283
|
async allowance(params) {
|
|
6635
7284
|
const {
|
|
6636
7285
|
contractAddress,
|
|
@@ -6651,7 +7300,7 @@ var TronWallet = class {
|
|
|
6651
7300
|
return {
|
|
6652
7301
|
contract,
|
|
6653
7302
|
allowance,
|
|
6654
|
-
needApprove: (0,
|
|
7303
|
+
needApprove: (0, import_big8.default)(amountWei || 0).gt(allowance || 0)
|
|
6655
7304
|
};
|
|
6656
7305
|
} catch (error) {
|
|
6657
7306
|
console.log("Error in allowance: %o", error);
|
|
@@ -6698,14 +7347,7 @@ var TronWallet = class {
|
|
|
6698
7347
|
}
|
|
6699
7348
|
async getEnergyPrice() {
|
|
6700
7349
|
await this.waitForTronWeb();
|
|
6701
|
-
let energyFee =
|
|
6702
|
-
try {
|
|
6703
|
-
const params = await this.tronWeb.trx.getChainParameters();
|
|
6704
|
-
energyFee = params.find((p) => p.key === "getEnergyFee")?.value || 280;
|
|
6705
|
-
console.log("Energy Fee:", energyFee, "Sun/Energy");
|
|
6706
|
-
} catch (err) {
|
|
6707
|
-
console.error("Error getting energy price:", err);
|
|
6708
|
-
}
|
|
7350
|
+
let energyFee = 100;
|
|
6709
7351
|
return energyFee;
|
|
6710
7352
|
}
|
|
6711
7353
|
toBytes32(addr) {
|
|
@@ -6728,9 +7370,10 @@ var TronWallet = class {
|
|
|
6728
7370
|
excludeFees: excludeFees4,
|
|
6729
7371
|
refundTo,
|
|
6730
7372
|
multiHopComposer,
|
|
6731
|
-
isMultiHopComposer
|
|
6732
|
-
|
|
6733
|
-
|
|
7373
|
+
isMultiHopComposer,
|
|
7374
|
+
isOriginLegacy,
|
|
7375
|
+
isDestinationLegacy,
|
|
7376
|
+
originLayerzero
|
|
6734
7377
|
} = params;
|
|
6735
7378
|
const result = {
|
|
6736
7379
|
needApprove: false,
|
|
@@ -6747,12 +7390,11 @@ var TronWallet = class {
|
|
|
6747
7390
|
estimateSourceGasUsd: void 0,
|
|
6748
7391
|
estimateTime: 0,
|
|
6749
7392
|
// seconds - dynamically calculated using LayerZero formula
|
|
6750
|
-
outputAmount: numberRemoveEndZero((0,
|
|
7393
|
+
outputAmount: numberRemoveEndZero((0, import_big8.default)(amountWei || 0).div(10 ** params.fromToken.decimals).toFixed(params.fromToken.decimals, 0))
|
|
6751
7394
|
};
|
|
6752
7395
|
await this.waitForTronWeb();
|
|
6753
7396
|
const oftContract = await this.tronWeb.contract(abi, originLayerzeroAddress);
|
|
6754
7397
|
const approvalRequired = await oftContract.approvalRequired().call();
|
|
6755
|
-
console.log("%cApprovalRequired: %o", "background:blue;color:white;", result.needApprove);
|
|
6756
7398
|
if (approvalRequired) {
|
|
6757
7399
|
try {
|
|
6758
7400
|
const userAddress = refundTo || this.tronWeb.defaultAddress.base58;
|
|
@@ -6767,18 +7409,27 @@ var TronWallet = class {
|
|
|
6767
7409
|
console.log("Error checking allowance: %o", error);
|
|
6768
7410
|
}
|
|
6769
7411
|
}
|
|
7412
|
+
const lzReceiveOptionGas = isOriginLegacy ? originLayerzero.lzReceiveOptionGasLegacy : originLayerzero.lzReceiveOptionGas;
|
|
7413
|
+
let lzReceiveOptionValue = 0;
|
|
7414
|
+
const destATA = await getDestinationAssociatedTokenAddress({
|
|
7415
|
+
recipient,
|
|
7416
|
+
toToken
|
|
7417
|
+
});
|
|
7418
|
+
if (destATA.needCreateTokenAccount) {
|
|
7419
|
+
lzReceiveOptionValue = LZ_RECEIVE_VALUE[toToken.chainName] || 0;
|
|
7420
|
+
}
|
|
6770
7421
|
const sendParam = [
|
|
6771
7422
|
// dstEid
|
|
6772
7423
|
dstEid,
|
|
6773
7424
|
// to
|
|
6774
7425
|
// "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
6775
|
-
|
|
7426
|
+
addressToBytes322(toToken.chainType, recipient),
|
|
6776
7427
|
// amountLD
|
|
6777
7428
|
amountWei,
|
|
6778
7429
|
// minAmountLD
|
|
6779
7430
|
"0",
|
|
6780
7431
|
// extraOptions
|
|
6781
|
-
|
|
7432
|
+
import_lz_v2_utilities3.Options.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).toHex(),
|
|
6782
7433
|
// composeMsg
|
|
6783
7434
|
"0x",
|
|
6784
7435
|
// oftCmd
|
|
@@ -6786,71 +7437,63 @@ var TronWallet = class {
|
|
|
6786
7437
|
];
|
|
6787
7438
|
if (isMultiHopComposer) {
|
|
6788
7439
|
sendParam[0] = multiHopComposer.eid;
|
|
6789
|
-
sendParam[1] =
|
|
7440
|
+
sendParam[1] = addressToBytes322("evm", multiHopComposer.oftMultiHopComposer);
|
|
6790
7441
|
}
|
|
6791
7442
|
const oftData = await oftContract.quoteOFT(sendParam).call();
|
|
6792
|
-
console.log("oftData: %o", oftData);
|
|
6793
7443
|
const [, , oftReceipt] = oftData;
|
|
6794
|
-
sendParam[3] = (0,
|
|
7444
|
+
sendParam[3] = (0, import_big8.default)(oftReceipt[1].toString()).times((0, import_big8.default)(1).minus((0, import_big8.default)(slippageTolerance || 0).div(100))).toFixed(0);
|
|
6795
7445
|
const msgFee = await oftContract.quoteSend(sendParam, payInLzToken).call();
|
|
6796
|
-
|
|
7446
|
+
let nativeMsgFee = msgFee[0]["nativeFee"];
|
|
7447
|
+
if (nativeMsgFee) {
|
|
7448
|
+
nativeMsgFee = BigInt((0, import_big8.default)(nativeMsgFee.toString()).times(1.2).toFixed(0));
|
|
7449
|
+
}
|
|
7450
|
+
result.estimateSourceGas = nativeMsgFee;
|
|
6797
7451
|
if (isMultiHopComposer) {
|
|
6798
|
-
|
|
6799
|
-
|
|
7452
|
+
const composeMsgSendParam = {
|
|
7453
|
+
dstEid,
|
|
7454
|
+
to: addressToBytes322(toToken.chainType, recipient),
|
|
7455
|
+
amountLD: sendParam[2],
|
|
7456
|
+
minAmountLD: sendParam[3],
|
|
7457
|
+
extraOptions: import_lz_v2_utilities3.Options.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).toHex(),
|
|
7458
|
+
composeMsg: "0x",
|
|
7459
|
+
oftCmd: "0x"
|
|
7460
|
+
};
|
|
7461
|
+
const hopMsgFee = await getHopMsgFee({
|
|
7462
|
+
sendParam: composeMsgSendParam,
|
|
7463
|
+
toToken
|
|
7464
|
+
});
|
|
7465
|
+
sendParam[4] = import_lz_v2_utilities3.Options.newOptions().addExecutorLzReceiveOption(lzReceiveOptionGas, lzReceiveOptionValue).addExecutorComposeOption(0, originLayerzero.composeOptionGas || 8e5, hopMsgFee).toHex();
|
|
7466
|
+
const abiCoder = import_ethers6.ethers.AbiCoder.defaultAbiCoder();
|
|
6800
7467
|
sendParam[5] = abiCoder.encode(
|
|
6801
7468
|
["tuple(uint32 dstEid, bytes32 to, uint256 amountLD, uint256 minAmountLD, bytes extraOptions, bytes composeMsg, bytes oftCmd)"],
|
|
6802
|
-
[
|
|
6803
|
-
dstEid,
|
|
6804
|
-
addressToBytes32(toToken.chainType, recipient),
|
|
6805
|
-
sendParam[2],
|
|
6806
|
-
// amountLD
|
|
6807
|
-
sendParam[3],
|
|
6808
|
-
// minAmountLD
|
|
6809
|
-
"0x",
|
|
6810
|
-
"0x",
|
|
6811
|
-
"0x"
|
|
6812
|
-
]]
|
|
7469
|
+
[Object.values(composeMsgSendParam)]
|
|
6813
7470
|
);
|
|
6814
7471
|
}
|
|
6815
|
-
console.log("%cMsgFee: %o", "background:blue;color:white;", msgFee);
|
|
6816
7472
|
result.sendParam = {
|
|
6817
|
-
contract: oftContract,
|
|
6818
7473
|
param: [
|
|
6819
7474
|
// sendParam
|
|
6820
7475
|
sendParam,
|
|
6821
7476
|
// feeParam
|
|
6822
7477
|
[
|
|
6823
7478
|
// nativeFee
|
|
6824
|
-
|
|
7479
|
+
nativeMsgFee.toString(),
|
|
6825
7480
|
// lzTokenFee
|
|
6826
7481
|
msgFee[0]["lzTokenFee"].toString()
|
|
6827
7482
|
],
|
|
6828
7483
|
// refundAddress
|
|
6829
7484
|
refundTo
|
|
6830
7485
|
],
|
|
6831
|
-
options: { callValue:
|
|
7486
|
+
options: { callValue: nativeMsgFee.toString() }
|
|
6832
7487
|
};
|
|
6833
|
-
|
|
6834
|
-
|
|
6835
|
-
result.fees.nativeFeeUsd = numberRemoveEndZero((0,
|
|
6836
|
-
result.fees.lzTokenFeeUsd = numberRemoveEndZero((0,
|
|
6837
|
-
|
|
6838
|
-
|
|
6839
|
-
|
|
6840
|
-
|
|
6841
|
-
|
|
6842
|
-
result.estimateSourceGasUsd = usd;
|
|
6843
|
-
} catch (error) {
|
|
6844
|
-
console.log("usdt0 estimate gas failed: %o", error);
|
|
6845
|
-
}
|
|
6846
|
-
for (const feeKey in result.fees) {
|
|
6847
|
-
if (excludeFees4.includes(feeKey)) {
|
|
6848
|
-
continue;
|
|
6849
|
-
}
|
|
6850
|
-
result.totalFeesUsd = (0, import_big6.default)(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
|
|
6851
|
-
}
|
|
6852
|
-
result.totalFeesUsd = numberRemoveEndZero((0, import_big6.default)(result.totalFeesUsd).toFixed(20));
|
|
6853
|
-
const tx = await this.tronWeb.transactionBuilder.triggerSmartContract(
|
|
7488
|
+
const nativeFeeUsd = (0, import_big8.default)(nativeMsgFee?.toString() || 0).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
|
|
7489
|
+
result.fees.nativeFee = numberRemoveEndZero((0, import_big8.default)(nativeMsgFee?.toString() || 0).div(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals));
|
|
7490
|
+
result.fees.nativeFeeUsd = numberRemoveEndZero((0, import_big8.default)(nativeFeeUsd).toFixed(20));
|
|
7491
|
+
result.fees.lzTokenFeeUsd = numberRemoveEndZero((0, import_big8.default)(msgFee[0]["lzTokenFee"]?.toString() || 0).div(10 ** fromToken.decimals).toFixed(20));
|
|
7492
|
+
if (isOriginLegacy || isDestinationLegacy) {
|
|
7493
|
+
result.fees.legacyMeshFeeUsd = numberRemoveEndZero((0, import_big8.default)(amountWei || 0).div(10 ** fromToken.decimals).times(USDT0_LEGACY_MESH_TRANSFTER_FEE).toFixed(fromToken.decimals));
|
|
7494
|
+
result.outputAmount = numberRemoveEndZero((0, import_big8.default)((0, import_big8.default)(amountWei || 0).div(10 ** params.fromToken.decimals)).minus(result.fees.legacyMeshFeeUsd || 0).toFixed(params.fromToken.decimals, 0));
|
|
7495
|
+
}
|
|
7496
|
+
const transactionParams = [
|
|
6854
7497
|
originLayerzeroAddress,
|
|
6855
7498
|
"send((uint32,bytes32,uint256,uint256,bytes,bytes,bytes),(uint256,uint256),address)",
|
|
6856
7499
|
result.sendParam.options,
|
|
@@ -6868,9 +7511,41 @@ var TronWallet = class {
|
|
|
6868
7511
|
value: result.sendParam.param[2]
|
|
6869
7512
|
}
|
|
6870
7513
|
],
|
|
6871
|
-
this.tronWeb.defaultAddress.base58
|
|
6872
|
-
|
|
7514
|
+
this.tronWeb.defaultAddress.base58 || refundTo
|
|
7515
|
+
];
|
|
7516
|
+
const energyPrice = await this.getEnergyPrice();
|
|
7517
|
+
const tx = await this.tronWeb.transactionBuilder.triggerSmartContract(...transactionParams);
|
|
6873
7518
|
result.sendParam.tx = tx;
|
|
7519
|
+
try {
|
|
7520
|
+
const transaction = await this.tronWeb.transactionBuilder.triggerConstantContract(...transactionParams);
|
|
7521
|
+
const energyUsed = transaction.energy_used || 2e5;
|
|
7522
|
+
const rawDataHexLength = transaction.transaction.raw_data_hex.length || 1e3;
|
|
7523
|
+
const bandwidthAmount = (rawDataHexLength / 2 + DATA_HEX_PROTOBUF_EXTRA + SIGNATURE_SIZE) * 1e-3;
|
|
7524
|
+
const amount = (0, import_big8.default)(energyUsed || 0).times(energyPrice).div(10 ** fromToken.nativeToken.decimals);
|
|
7525
|
+
const totalAmount = (0, import_big8.default)(amount).plus(bandwidthAmount);
|
|
7526
|
+
const usd = numberRemoveEndZero((0, import_big8.default)(totalAmount).times(getPrice(prices, fromToken.nativeToken.symbol)).toFixed(20));
|
|
7527
|
+
result.fees.estimateGasUsd = usd;
|
|
7528
|
+
result.estimateSourceGas = numberRemoveEndZero((0, import_big8.default)(totalAmount).times(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals));
|
|
7529
|
+
result.estimateSourceGasUsd = usd;
|
|
7530
|
+
} catch (error) {
|
|
7531
|
+
const energyUsed = 2e5;
|
|
7532
|
+
const rawDataHexLength = 1e3;
|
|
7533
|
+
const bandwidthAmount = (rawDataHexLength / 2 + DATA_HEX_PROTOBUF_EXTRA + SIGNATURE_SIZE) * 1e-3;
|
|
7534
|
+
const amount = (0, import_big8.default)(energyUsed || 0).times(energyPrice).div(10 ** fromToken.nativeToken.decimals);
|
|
7535
|
+
const totalAmount = (0, import_big8.default)(amount).plus(bandwidthAmount);
|
|
7536
|
+
const usd = numberRemoveEndZero((0, import_big8.default)(totalAmount).times(getPrice(prices, fromToken.nativeToken.symbol)).toFixed(20));
|
|
7537
|
+
result.fees.estimateGasUsd = usd;
|
|
7538
|
+
result.estimateSourceGas = numberRemoveEndZero((0, import_big8.default)(totalAmount).times(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals));
|
|
7539
|
+
result.estimateSourceGasUsd = usd;
|
|
7540
|
+
}
|
|
7541
|
+
for (const feeKey in result.fees) {
|
|
7542
|
+
if (excludeFees4.includes(feeKey) || !/Usd$/.test(feeKey)) {
|
|
7543
|
+
continue;
|
|
7544
|
+
}
|
|
7545
|
+
result.totalFeesUsd = (0, import_big8.default)(result.totalFeesUsd || 0).plus(result.fees[feeKey] || 0);
|
|
7546
|
+
}
|
|
7547
|
+
result.totalFeesUsd = numberRemoveEndZero((0, import_big8.default)(result.totalFeesUsd).toFixed(20));
|
|
7548
|
+
result.sendParam.transactionParams = transactionParams;
|
|
6874
7549
|
return result;
|
|
6875
7550
|
}
|
|
6876
7551
|
async sendTransaction(params) {
|
|
@@ -6879,7 +7554,6 @@ var TronWallet = class {
|
|
|
6879
7554
|
} = params;
|
|
6880
7555
|
const result = await this.signAndSendTransaction(tx.transaction);
|
|
6881
7556
|
if (typeof result === "object" && result.message) {
|
|
6882
|
-
console.log("%cTron send transaction message: %o", "background:#f00;color:#fff;", result.message);
|
|
6883
7557
|
if (/user rejected the transaction/i.test(result.message)) {
|
|
6884
7558
|
throw new Error("User rejected the transaction");
|
|
6885
7559
|
}
|
|
@@ -6944,7 +7618,6 @@ var TronWallet = class {
|
|
|
6944
7618
|
} catch (error) {
|
|
6945
7619
|
console.log("oneclick check allowance failed: %o", error);
|
|
6946
7620
|
}
|
|
6947
|
-
const proxyContract = await this.tronWeb.contract(abi, proxyAddress);
|
|
6948
7621
|
const proxyParam = [
|
|
6949
7622
|
// tokenAddress
|
|
6950
7623
|
fromToken.contractAddress,
|
|
@@ -6954,22 +7627,9 @@ var TronWallet = class {
|
|
|
6954
7627
|
amountWei
|
|
6955
7628
|
];
|
|
6956
7629
|
result.sendParam = {
|
|
6957
|
-
contract: proxyContract,
|
|
6958
7630
|
param: proxyParam
|
|
6959
7631
|
};
|
|
6960
|
-
|
|
6961
|
-
const gasLimit = 30000n;
|
|
6962
|
-
const energyPrice = await this.getEnergyPrice();
|
|
6963
|
-
const gasPrice = BigInt(energyPrice);
|
|
6964
|
-
const estimateGas = gasLimit * gasPrice;
|
|
6965
|
-
const estimateGasUsd = (0, import_big6.default)(estimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
|
|
6966
|
-
result.fees.sourceGasFeeUsd = numberRemoveEndZero((0, import_big6.default)(estimateGasUsd).toFixed(20));
|
|
6967
|
-
result.estimateSourceGas = estimateGas.toString();
|
|
6968
|
-
result.estimateSourceGasUsd = numberRemoveEndZero((0, import_big6.default)(estimateGasUsd).toFixed(20));
|
|
6969
|
-
} catch (error) {
|
|
6970
|
-
console.log("onclick estimate proxy failed: %o", error);
|
|
6971
|
-
}
|
|
6972
|
-
const tx = await this.tronWeb.transactionBuilder.triggerSmartContract(
|
|
7632
|
+
const transactionParams = [
|
|
6973
7633
|
proxyAddress,
|
|
6974
7634
|
"proxyTransfer(address,address,uint256)",
|
|
6975
7635
|
{},
|
|
@@ -6990,20 +7650,99 @@ var TronWallet = class {
|
|
|
6990
7650
|
// amount
|
|
6991
7651
|
}
|
|
6992
7652
|
],
|
|
6993
|
-
this.tronWeb.defaultAddress.base58
|
|
6994
|
-
|
|
7653
|
+
this.tronWeb.defaultAddress.base58 || refundTo
|
|
7654
|
+
];
|
|
7655
|
+
const energyPrice = await this.getEnergyPrice();
|
|
7656
|
+
const tx = await this.tronWeb.transactionBuilder.triggerSmartContract(...transactionParams);
|
|
6995
7657
|
result.sendParam.tx = tx;
|
|
7658
|
+
try {
|
|
7659
|
+
const transaction = await this.tronWeb.transactionBuilder.triggerConstantContract(...transactionParams);
|
|
7660
|
+
const energyUsed = transaction.energy_used || 3e4;
|
|
7661
|
+
const rawDataHexLength = transaction.transaction.raw_data_hex.length || 500;
|
|
7662
|
+
const bandwidthAmount = (rawDataHexLength / 2 + DATA_HEX_PROTOBUF_EXTRA + SIGNATURE_SIZE) * 1e-3;
|
|
7663
|
+
const amount = (0, import_big8.default)(energyUsed || 0).times(energyPrice).div(10 ** fromToken.nativeToken.decimals);
|
|
7664
|
+
const totalAmount = (0, import_big8.default)(amount).plus(bandwidthAmount);
|
|
7665
|
+
const usd = numberRemoveEndZero((0, import_big8.default)(totalAmount).times(getPrice(prices, fromToken.nativeToken.symbol)).toFixed(20));
|
|
7666
|
+
result.fees.sourceGasFeeUsd = usd;
|
|
7667
|
+
result.estimateSourceGas = numberRemoveEndZero((0, import_big8.default)(totalAmount).times(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals));
|
|
7668
|
+
result.estimateSourceGasUsd = usd;
|
|
7669
|
+
} catch (error) {
|
|
7670
|
+
const energyUsed = 169e3;
|
|
7671
|
+
const rawDataHexLength = 500;
|
|
7672
|
+
const bandwidthAmount = (rawDataHexLength / 2 + DATA_HEX_PROTOBUF_EXTRA + SIGNATURE_SIZE) * 1e-3;
|
|
7673
|
+
const amount = (0, import_big8.default)(energyUsed || 0).times(energyPrice).div(10 ** fromToken.nativeToken.decimals);
|
|
7674
|
+
const totalAmount = (0, import_big8.default)(amount).plus(bandwidthAmount);
|
|
7675
|
+
const usd = numberRemoveEndZero((0, import_big8.default)(totalAmount).times(getPrice(prices, fromToken.nativeToken.symbol)).toFixed(20));
|
|
7676
|
+
result.fees.estimateGasUsd = usd;
|
|
7677
|
+
result.estimateSourceGas = numberRemoveEndZero((0, import_big8.default)(totalAmount).times(10 ** fromToken.nativeToken.decimals).toFixed(fromToken.nativeToken.decimals));
|
|
7678
|
+
result.estimateSourceGasUsd = usd;
|
|
7679
|
+
}
|
|
7680
|
+
result.sendParam.transactionParams = transactionParams;
|
|
7681
|
+
return result;
|
|
7682
|
+
}
|
|
7683
|
+
async getAccountResources(params) {
|
|
7684
|
+
const { account } = params;
|
|
7685
|
+
const result = {
|
|
7686
|
+
energy: 0,
|
|
7687
|
+
bandwidth: 0,
|
|
7688
|
+
success: false,
|
|
7689
|
+
error: "TronWeb is not initialized or the wallet is not connected"
|
|
7690
|
+
};
|
|
7691
|
+
await this.waitForTronWeb();
|
|
7692
|
+
if (!this.tronWeb || !account) {
|
|
7693
|
+
return result;
|
|
7694
|
+
}
|
|
7695
|
+
try {
|
|
7696
|
+
let availableEnergy;
|
|
7697
|
+
let availableBandwidth;
|
|
7698
|
+
try {
|
|
7699
|
+
if (this.tronWeb.trx.getAccountResources) {
|
|
7700
|
+
const resources = await this.tronWeb.trx.getAccountResources(account);
|
|
7701
|
+
console.log("resources: %o", resources);
|
|
7702
|
+
if (resources) {
|
|
7703
|
+
availableEnergy = (resources.EnergyLimit || 0) - (resources.EnergyUsed || 0);
|
|
7704
|
+
availableBandwidth = (resources.freeNetLimit || 0) - (resources.freeNetUsed || 0);
|
|
7705
|
+
}
|
|
7706
|
+
}
|
|
7707
|
+
} catch (resourcesErr) {
|
|
7708
|
+
console.warn("getAccountResources API is not available, try other way:", resourcesErr);
|
|
7709
|
+
}
|
|
7710
|
+
if (availableEnergy === void 0 && availableBandwidth === void 0) {
|
|
7711
|
+
const accountInfo = await this.tronWeb.trx.getAccount(account);
|
|
7712
|
+
if (accountInfo.account_resource) {
|
|
7713
|
+
const accountResource = accountInfo.account_resource;
|
|
7714
|
+
availableEnergy = (accountResource.EnergyLimit || 0) - (accountResource.EnergyUsed || 0);
|
|
7715
|
+
availableBandwidth = (accountResource.NetLimit || 0) - (accountResource.NetUsed || 0);
|
|
7716
|
+
} else if (accountInfo.energy !== void 0) {
|
|
7717
|
+
availableEnergy = accountInfo.energy || 0;
|
|
7718
|
+
}
|
|
7719
|
+
if (accountInfo.bandwidth !== void 0) {
|
|
7720
|
+
if (typeof accountInfo.bandwidth === "number") {
|
|
7721
|
+
availableBandwidth = accountInfo.bandwidth;
|
|
7722
|
+
} else if (accountInfo.bandwidth) {
|
|
7723
|
+
availableBandwidth = accountInfo.bandwidth.available || accountInfo.bandwidth.freeNetUsage || 0;
|
|
7724
|
+
}
|
|
7725
|
+
}
|
|
7726
|
+
}
|
|
7727
|
+
result.energy = Math.max(0, availableEnergy);
|
|
7728
|
+
result.bandwidth = Math.max(0, availableBandwidth);
|
|
7729
|
+
result.success = true;
|
|
7730
|
+
result.error = null;
|
|
7731
|
+
} catch (error) {
|
|
7732
|
+
console.error("Failed to get account resources:", error);
|
|
7733
|
+
}
|
|
6996
7734
|
return result;
|
|
6997
7735
|
}
|
|
6998
7736
|
};
|
|
6999
7737
|
|
|
7000
7738
|
// src/wallets/aptos.ts
|
|
7001
7739
|
var import_ts_sdk = require("@aptos-labs/ts-sdk");
|
|
7002
|
-
var
|
|
7740
|
+
var import_big9 = __toESM(require("big.js"));
|
|
7003
7741
|
var AptosWallet = class {
|
|
7004
7742
|
constructor(options) {
|
|
7005
7743
|
const config = new import_ts_sdk.AptosConfig({
|
|
7006
|
-
network: import_ts_sdk.Network.MAINNET
|
|
7744
|
+
network: import_ts_sdk.Network.MAINNET,
|
|
7745
|
+
fullnode: getRpcUrls("aptos")[0]
|
|
7007
7746
|
});
|
|
7008
7747
|
const aptos = new import_ts_sdk.Aptos(config);
|
|
7009
7748
|
this.aptos = aptos;
|
|
@@ -7307,10 +8046,10 @@ var AptosWallet = class {
|
|
|
7307
8046
|
const defaultGasLimit = 5000n;
|
|
7308
8047
|
const defaultGasPrice = 100n;
|
|
7309
8048
|
const defaultEstimateGas = defaultGasLimit * defaultGasPrice;
|
|
7310
|
-
const estimateGasUsd2 = (0,
|
|
7311
|
-
result.fees.sourceGasFeeUsd = numberRemoveEndZero((0,
|
|
8049
|
+
const estimateGasUsd2 = (0, import_big9.default)(defaultEstimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
|
|
8050
|
+
result.fees.sourceGasFeeUsd = numberRemoveEndZero((0, import_big9.default)(estimateGasUsd2).toFixed(20));
|
|
7312
8051
|
result.estimateSourceGas = defaultEstimateGas.toString();
|
|
7313
|
-
result.estimateSourceGasUsd = numberRemoveEndZero((0,
|
|
8052
|
+
result.estimateSourceGasUsd = numberRemoveEndZero((0, import_big9.default)(estimateGasUsd2).toFixed(20));
|
|
7314
8053
|
result.sendParam = {
|
|
7315
8054
|
function: functionId,
|
|
7316
8055
|
typeArguments: [typeArgument],
|
|
@@ -7323,10 +8062,10 @@ var AptosWallet = class {
|
|
|
7323
8062
|
const defaultGasLimit = 5000n;
|
|
7324
8063
|
const defaultGasPrice = 100n;
|
|
7325
8064
|
const defaultEstimateGas = defaultGasLimit * defaultGasPrice;
|
|
7326
|
-
const estimateGasUsd2 = (0,
|
|
7327
|
-
result.fees.sourceGasFeeUsd = numberRemoveEndZero((0,
|
|
8065
|
+
const estimateGasUsd2 = (0, import_big9.default)(defaultEstimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
|
|
8066
|
+
result.fees.sourceGasFeeUsd = numberRemoveEndZero((0, import_big9.default)(estimateGasUsd2).toFixed(20));
|
|
7328
8067
|
result.estimateSourceGas = defaultEstimateGas.toString();
|
|
7329
|
-
result.estimateSourceGasUsd = numberRemoveEndZero((0,
|
|
8068
|
+
result.estimateSourceGasUsd = numberRemoveEndZero((0, import_big9.default)(estimateGasUsd2).toFixed(20));
|
|
7330
8069
|
result.sendParam = {
|
|
7331
8070
|
function: functionId,
|
|
7332
8071
|
typeArguments: [typeArgument],
|
|
@@ -7338,10 +8077,10 @@ var AptosWallet = class {
|
|
|
7338
8077
|
const gasLimit = gasUsed * 150n / 100n;
|
|
7339
8078
|
const gasPrice = BigInt(simulation.gas_unit_price || 100);
|
|
7340
8079
|
const estimateGas = gasLimit * gasPrice;
|
|
7341
|
-
const estimateGasUsd = (0,
|
|
7342
|
-
result.fees.sourceGasFeeUsd = numberRemoveEndZero((0,
|
|
8080
|
+
const estimateGasUsd = (0, import_big9.default)(estimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
|
|
8081
|
+
result.fees.sourceGasFeeUsd = numberRemoveEndZero((0, import_big9.default)(estimateGasUsd).toFixed(20));
|
|
7343
8082
|
result.estimateSourceGas = estimateGas.toString();
|
|
7344
|
-
result.estimateSourceGasUsd = numberRemoveEndZero((0,
|
|
8083
|
+
result.estimateSourceGasUsd = numberRemoveEndZero((0, import_big9.default)(estimateGasUsd).toFixed(20));
|
|
7345
8084
|
result.sendParam = {
|
|
7346
8085
|
function: functionId,
|
|
7347
8086
|
typeArguments: [typeArgument],
|
|
@@ -7352,10 +8091,10 @@ var AptosWallet = class {
|
|
|
7352
8091
|
const defaultGasLimit = 5000n;
|
|
7353
8092
|
const defaultGasPrice = 100n;
|
|
7354
8093
|
const defaultEstimateGas = defaultGasLimit * defaultGasPrice;
|
|
7355
|
-
const estimateGasUsd = (0,
|
|
7356
|
-
result.fees.sourceGasFeeUsd = numberRemoveEndZero((0,
|
|
8094
|
+
const estimateGasUsd = (0, import_big9.default)(defaultEstimateGas.toString()).div(10 ** fromToken.nativeToken.decimals).times(getPrice(prices, fromToken.nativeToken.symbol));
|
|
8095
|
+
result.fees.sourceGasFeeUsd = numberRemoveEndZero((0, import_big9.default)(estimateGasUsd).toFixed(20));
|
|
7357
8096
|
result.estimateSourceGas = defaultEstimateGas.toString();
|
|
7358
|
-
result.estimateSourceGasUsd = numberRemoveEndZero((0,
|
|
8097
|
+
result.estimateSourceGasUsd = numberRemoveEndZero((0, import_big9.default)(estimateGasUsd).toFixed(20));
|
|
7359
8098
|
}
|
|
7360
8099
|
return result;
|
|
7361
8100
|
}
|
|
@@ -7433,7 +8172,12 @@ var faTransferAbi = {
|
|
|
7433
8172
|
CancelablePromise,
|
|
7434
8173
|
EVMWallet,
|
|
7435
8174
|
GetExecutionStatusResponse,
|
|
8175
|
+
Hyperliquid,
|
|
8176
|
+
HyperliquidFromTokens,
|
|
8177
|
+
HyperliuquidMinAmount,
|
|
8178
|
+
HyperliuquidToToken,
|
|
7436
8179
|
NearWallet,
|
|
8180
|
+
NetworkRpcUrlsMap,
|
|
7437
8181
|
OpenAPI,
|
|
7438
8182
|
QuoteRequest,
|
|
7439
8183
|
SFA,
|
|
@@ -7443,7 +8187,8 @@ var faTransferAbi = {
|
|
|
7443
8187
|
TokenResponse,
|
|
7444
8188
|
TransactionStatus,
|
|
7445
8189
|
TronWallet,
|
|
7446
|
-
|
|
8190
|
+
getRpcUrls,
|
|
8191
|
+
setRpcUrls,
|
|
7447
8192
|
tokens,
|
|
7448
8193
|
usdcChains,
|
|
7449
8194
|
usdcTokens,
|