@evvm/testnet-contracts 2.1.3 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +2 -2
- package/README.md +355 -55
- package/contracts/evvm/Evvm.sol +39 -38
- package/contracts/evvm/lib/ErrorsLib.sol +2 -1
- package/contracts/evvm/lib/EvvmStorage.sol +2 -0
- package/contracts/evvm/lib/EvvmStructs.sol +27 -1
- package/contracts/evvm/lib/SignatureUtils.sol +14 -17
- package/contracts/nameService/NameService.sol +124 -366
- package/contracts/nameService/lib/ErrorsLib.sol +2 -8
- package/contracts/nameService/lib/IdentityValidation.sol +182 -0
- package/contracts/nameService/lib/NameServiceStructs.sol +69 -0
- package/contracts/nameService/lib/SignatureUtils.sol +47 -41
- package/contracts/p2pSwap/P2PSwap.sol +54 -535
- package/contracts/p2pSwap/lib/P2PSwapStructs.sol +59 -0
- package/contracts/p2pSwap/lib/SignatureUtils.sol +16 -18
- package/contracts/staking/Estimator.sol +7 -6
- package/contracts/staking/Staking.sol +70 -159
- package/contracts/staking/lib/ErrorsLib.sol +0 -1
- package/contracts/staking/lib/SignatureUtils.sol +7 -36
- package/contracts/staking/lib/StakingStructs.sol +94 -0
- package/contracts/treasury/Treasury.sol +18 -20
- package/contracts/treasuryTwoChains/TreasuryExternalChainStation.sol +88 -35
- package/contracts/treasuryTwoChains/TreasuryHostChainStation.sol +81 -47
- package/contracts/treasuryTwoChains/lib/ErrorsLib.sol +2 -0
- package/contracts/treasuryTwoChains/lib/ExternalChainStationStructs.sol +3 -14
- package/contracts/treasuryTwoChains/lib/HostChainStationStructs.sol +3 -7
- package/contracts/treasuryTwoChains/lib/SignatureUtils.sol +12 -14
- package/interfaces/IEstimator.sol +7 -50
- package/interfaces/IEvvm.sol +17 -91
- package/interfaces/INameService.sol +37 -88
- package/interfaces/IP2PSwap.sol +19 -15
- package/interfaces/IStaking.sol +20 -50
- package/interfaces/ITreasury.sol +1 -4
- package/interfaces/ITreasuryExternalChainStation.sol +11 -15
- package/interfaces/ITreasuryHostChainStation.sol +7 -10
- package/library/Erc191TestBuilder.sol +56 -57
- package/library/EvvmService.sol +40 -0
- package/library/primitives/IERC20.sol +79 -0
- package/library/primitives/Math.sol +415 -0
- package/library/primitives/SignatureRecover.sol +42 -0
- package/library/utils/AdvancedStrings.sol +89 -0
- package/library/utils/GovernanceUtils.sol +81 -0
- package/library/utils/SignatureUtil.sol +29 -0
- package/library/utils/nonces/AsyncNonce.sol +32 -0
- package/library/utils/nonces/SyncNonce.sol +27 -0
- package/library/utils/service/EvvmPayments.sol +77 -0
- package/library/utils/service/StakingServiceUtils.sol +32 -0
- package/package.json +11 -13
- package/contracts/evvm/EvvmLegacy.sol +0 -1553
- package/library/AdvancedStrings.sol +0 -77
- package/library/SignatureRecover.sol +0 -140
- package/library/StakingServiceHooks.sol +0 -116
|
@@ -27,21 +27,23 @@ pragma solidity ^0.8.0;
|
|
|
27
27
|
* @dev Secure vault for ETH and ERC20 tokens with EVVM integration and input validation
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
|
-
import {IERC20} from "@
|
|
30
|
+
import {IERC20} from "@evvm/testnet-contracts/library/primitives/IERC20.sol";
|
|
31
31
|
import {SafeTransferLib} from "@solady/utils/SafeTransferLib.sol";
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
32
|
+
import {IEvvm} from "@evvm/testnet-contracts/interfaces/IEvvm.sol";
|
|
33
|
+
import {
|
|
34
|
+
ErrorsLib
|
|
35
|
+
} from "@evvm/testnet-contracts/contracts/treasury/lib/ErrorsLib.sol";
|
|
34
36
|
|
|
35
37
|
contract Treasury {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
|
|
39
|
+
IEvvm evvm;
|
|
38
40
|
|
|
39
41
|
/**
|
|
40
42
|
* @notice Initialize Treasury with EVVM contract address
|
|
41
43
|
* @param _evvmAddress Address of the EVVM core contract
|
|
42
44
|
*/
|
|
43
45
|
constructor(address _evvmAddress) {
|
|
44
|
-
|
|
46
|
+
evvm = IEvvm(_evvmAddress);
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
/**
|
|
@@ -56,11 +58,7 @@ contract Treasury {
|
|
|
56
58
|
revert ErrorsLib.DepositAmountMustBeGreaterThanZero();
|
|
57
59
|
if (amount != msg.value) revert ErrorsLib.InvalidDepositAmount();
|
|
58
60
|
|
|
59
|
-
|
|
60
|
-
msg.sender,
|
|
61
|
-
address(0),
|
|
62
|
-
msg.value
|
|
63
|
-
);
|
|
61
|
+
evvm.addAmountToUser(msg.sender, address(0), msg.value);
|
|
64
62
|
} else {
|
|
65
63
|
/// user is sending ERC20 tokens
|
|
66
64
|
|
|
@@ -69,7 +67,7 @@ contract Treasury {
|
|
|
69
67
|
revert ErrorsLib.DepositAmountMustBeGreaterThanZero();
|
|
70
68
|
|
|
71
69
|
IERC20(token).transferFrom(msg.sender, address(this), amount);
|
|
72
|
-
|
|
70
|
+
evvm.addAmountToUser(msg.sender, token, amount);
|
|
73
71
|
}
|
|
74
72
|
}
|
|
75
73
|
|
|
@@ -79,26 +77,26 @@ contract Treasury {
|
|
|
79
77
|
* @param amount Amount to withdraw
|
|
80
78
|
*/
|
|
81
79
|
function withdraw(address token, uint256 amount) external {
|
|
82
|
-
if (token ==
|
|
80
|
+
if (token == evvm.getEvvmMetadata().principalTokenAddress)
|
|
83
81
|
revert ErrorsLib.PrincipalTokenIsNotWithdrawable();
|
|
84
82
|
|
|
85
|
-
if (
|
|
83
|
+
if (evvm.getBalance(msg.sender, token) < amount)
|
|
86
84
|
revert ErrorsLib.InsufficientBalance();
|
|
87
85
|
|
|
88
86
|
if (token == address(0)) {
|
|
89
87
|
/// user is trying to withdraw native coin
|
|
90
88
|
|
|
91
|
-
|
|
92
|
-
msg.sender,
|
|
93
|
-
address(0),
|
|
94
|
-
amount
|
|
95
|
-
);
|
|
89
|
+
evvm.removeAmountFromUser(msg.sender, address(0), amount);
|
|
96
90
|
SafeTransferLib.safeTransferETH(msg.sender, amount);
|
|
97
91
|
} else {
|
|
98
92
|
/// user is trying to withdraw ERC20 tokens
|
|
99
93
|
|
|
100
|
-
|
|
94
|
+
evvm.removeAmountFromUser(msg.sender, token, amount);
|
|
101
95
|
IERC20(token).transfer(msg.sender, amount);
|
|
102
96
|
}
|
|
103
97
|
}
|
|
98
|
+
|
|
99
|
+
function getEvvmAddress() external view returns (address) {
|
|
100
|
+
return address(evvm);
|
|
101
|
+
}
|
|
104
102
|
}
|
|
@@ -31,27 +31,54 @@ pragma solidity ^0.8.0;
|
|
|
31
31
|
* @author Mate labs
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
|
-
import {IERC20} from "@
|
|
35
|
-
import {
|
|
36
|
-
|
|
34
|
+
import {IERC20} from "@evvm/testnet-contracts/library/primitives/IERC20.sol";
|
|
35
|
+
import {
|
|
36
|
+
ErrorsLib
|
|
37
|
+
} from "@evvm/testnet-contracts/contracts/treasuryTwoChains/lib/ErrorsLib.sol";
|
|
38
|
+
import {
|
|
39
|
+
ExternalChainStationStructs
|
|
40
|
+
} from "@evvm/testnet-contracts/contracts/treasuryTwoChains/lib/ExternalChainStationStructs.sol";
|
|
37
41
|
|
|
38
42
|
import {SafeTransferLib} from "@solady/utils/SafeTransferLib.sol";
|
|
39
43
|
|
|
40
|
-
import {
|
|
41
|
-
|
|
44
|
+
import {
|
|
45
|
+
SignatureUtils
|
|
46
|
+
} from "@evvm/testnet-contracts/contracts/treasuryTwoChains/lib/SignatureUtils.sol";
|
|
47
|
+
import {
|
|
48
|
+
PayloadUtils
|
|
49
|
+
} from "@evvm/testnet-contracts/contracts/treasuryTwoChains/lib/PayloadUtils.sol";
|
|
42
50
|
|
|
43
51
|
import {IMailbox} from "@hyperlane-xyz/core/contracts/interfaces/IMailbox.sol";
|
|
44
52
|
|
|
45
|
-
import {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
import {
|
|
54
|
+
MessagingParams,
|
|
55
|
+
MessagingReceipt
|
|
56
|
+
} from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
|
|
57
|
+
import {
|
|
58
|
+
OApp,
|
|
59
|
+
Origin,
|
|
60
|
+
MessagingFee
|
|
61
|
+
} from "@layerzerolabs/oapp-evm/contracts/oapp/OApp.sol";
|
|
62
|
+
import {
|
|
63
|
+
OAppOptionsType3
|
|
64
|
+
} from "@layerzerolabs/oapp-evm/contracts/oapp/libs/OAppOptionsType3.sol";
|
|
65
|
+
import {
|
|
66
|
+
OptionsBuilder
|
|
67
|
+
} from "@layerzerolabs/oapp-evm/contracts/oapp/libs/OptionsBuilder.sol";
|
|
49
68
|
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
|
|
50
69
|
|
|
51
|
-
import {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
import {
|
|
70
|
+
import {
|
|
71
|
+
AxelarExecutable
|
|
72
|
+
} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/executable/AxelarExecutable.sol";
|
|
73
|
+
import {
|
|
74
|
+
IAxelarGasService
|
|
75
|
+
} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGasService.sol";
|
|
76
|
+
import {
|
|
77
|
+
IInterchainGasEstimation
|
|
78
|
+
} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IInterchainGasEstimation.sol";
|
|
79
|
+
import {
|
|
80
|
+
AdvancedStrings
|
|
81
|
+
} from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
|
|
55
82
|
|
|
56
83
|
contract TreasuryExternalChainStation is
|
|
57
84
|
ExternalChainStationStructs,
|
|
@@ -85,7 +112,9 @@ contract TreasuryExternalChainStation is
|
|
|
85
112
|
|
|
86
113
|
/// @notice Unique identifier for the EVVM instance this station belongs to
|
|
87
114
|
/// @dev Immutable value set at deployment for signature verification
|
|
88
|
-
uint256
|
|
115
|
+
uint256 evvmID;
|
|
116
|
+
|
|
117
|
+
uint256 windowTimeToChangeEvvmID;
|
|
89
118
|
|
|
90
119
|
/// @notice Tracks the next nonce for Fisher bridge operations per user address
|
|
91
120
|
/// @dev Prevents replay attacks in Fisher bridge transactions
|
|
@@ -142,15 +171,13 @@ contract TreasuryExternalChainStation is
|
|
|
142
171
|
/// @dev Sets up Hyperlane, LayerZero, and Axelar configurations for multi-protocol support
|
|
143
172
|
/// @param _admin Initial admin address with full administrative privileges
|
|
144
173
|
/// @param _crosschainConfig Configuration struct containing all cross-chain protocol settings
|
|
145
|
-
/// @param _evvmId Unique identifier for the EVVM instance this station serves
|
|
146
174
|
constructor(
|
|
147
175
|
address _admin,
|
|
148
|
-
CrosschainConfig memory _crosschainConfig
|
|
149
|
-
uint256 _evvmId
|
|
176
|
+
CrosschainConfig memory _crosschainConfig
|
|
150
177
|
)
|
|
151
|
-
OApp(_crosschainConfig.endpointAddress, _admin)
|
|
178
|
+
OApp(_crosschainConfig.layerZero.endpointAddress, _admin)
|
|
152
179
|
Ownable(_admin)
|
|
153
|
-
AxelarExecutable(_crosschainConfig.gatewayAddress)
|
|
180
|
+
AxelarExecutable(_crosschainConfig.axelar.gatewayAddress)
|
|
154
181
|
{
|
|
155
182
|
admin = AddressTypeProposal({
|
|
156
183
|
current: _admin,
|
|
@@ -159,23 +186,26 @@ contract TreasuryExternalChainStation is
|
|
|
159
186
|
});
|
|
160
187
|
hyperlane = HyperlaneConfig({
|
|
161
188
|
hostChainStationDomainId: _crosschainConfig
|
|
189
|
+
.hyperlane
|
|
162
190
|
.hostChainStationDomainId,
|
|
163
191
|
hostChainStationAddress: "",
|
|
164
|
-
mailboxAddress: _crosschainConfig.mailboxAddress
|
|
192
|
+
mailboxAddress: _crosschainConfig.hyperlane.mailboxAddress
|
|
165
193
|
});
|
|
166
194
|
layerZero = LayerZeroConfig({
|
|
167
|
-
hostChainStationEid: _crosschainConfig
|
|
195
|
+
hostChainStationEid: _crosschainConfig
|
|
196
|
+
.layerZero
|
|
197
|
+
.hostChainStationEid,
|
|
168
198
|
hostChainStationAddress: "",
|
|
169
|
-
endpointAddress: _crosschainConfig.endpointAddress
|
|
199
|
+
endpointAddress: _crosschainConfig.layerZero.endpointAddress
|
|
170
200
|
});
|
|
171
201
|
axelar = AxelarConfig({
|
|
172
202
|
hostChainStationChainName: _crosschainConfig
|
|
203
|
+
.axelar
|
|
173
204
|
.hostChainStationChainName,
|
|
174
205
|
hostChainStationAddress: "",
|
|
175
|
-
gasServiceAddress: _crosschainConfig.gasServiceAddress,
|
|
176
|
-
gatewayAddress: _crosschainConfig.gatewayAddress
|
|
206
|
+
gasServiceAddress: _crosschainConfig.axelar.gasServiceAddress,
|
|
207
|
+
gatewayAddress: _crosschainConfig.axelar.gatewayAddress
|
|
177
208
|
});
|
|
178
|
-
EVVM_ID = _evvmId;
|
|
179
209
|
}
|
|
180
210
|
|
|
181
211
|
/// @notice One-time setup of host chain station address across all protocols
|
|
@@ -203,6 +233,21 @@ contract TreasuryExternalChainStation is
|
|
|
203
233
|
fuseSetHostChainAddress = 0x00;
|
|
204
234
|
}
|
|
205
235
|
|
|
236
|
+
/**
|
|
237
|
+
* @notice Updates the EVVM ID with a new value, restricted to admin and time-limited
|
|
238
|
+
* @dev Allows the admin to change the EVVM ID within a 1-day window after deployment
|
|
239
|
+
*/
|
|
240
|
+
function setEvvmID(uint256 newEvvmID) external onlyAdmin {
|
|
241
|
+
if (evvmID != 0) {
|
|
242
|
+
if (block.timestamp > windowTimeToChangeEvvmID)
|
|
243
|
+
revert ErrorsLib.WindowToChangeEvvmIDExpired();
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
evvmID = newEvvmID;
|
|
247
|
+
|
|
248
|
+
windowTimeToChangeEvvmID = block.timestamp + 24 hours;
|
|
249
|
+
}
|
|
250
|
+
|
|
206
251
|
/// @notice Deposits ERC20 tokens and sends them to host chain via selected protocol
|
|
207
252
|
/// @dev Supports Hyperlane (0x01), LayerZero (0x02), and Axelar (0x03) protocols
|
|
208
253
|
/// @param toAddress Recipient address on the host chain
|
|
@@ -341,7 +386,7 @@ contract TreasuryExternalChainStation is
|
|
|
341
386
|
) external onlyFisherExecutor {
|
|
342
387
|
if (
|
|
343
388
|
!SignatureUtils.verifyMessageSignedForFisherBridge(
|
|
344
|
-
|
|
389
|
+
evvmID,
|
|
345
390
|
from,
|
|
346
391
|
addressToReceive,
|
|
347
392
|
nextFisherExecutionNonce[from],
|
|
@@ -373,7 +418,7 @@ contract TreasuryExternalChainStation is
|
|
|
373
418
|
) external onlyFisherExecutor {
|
|
374
419
|
if (
|
|
375
420
|
!SignatureUtils.verifyMessageSignedForFisherBridge(
|
|
376
|
-
|
|
421
|
+
evvmID,
|
|
377
422
|
from,
|
|
378
423
|
addressToReceive,
|
|
379
424
|
nextFisherExecutionNonce[from],
|
|
@@ -414,7 +459,7 @@ contract TreasuryExternalChainStation is
|
|
|
414
459
|
) external payable onlyFisherExecutor {
|
|
415
460
|
if (
|
|
416
461
|
!SignatureUtils.verifyMessageSignedForFisherBridge(
|
|
417
|
-
|
|
462
|
+
evvmID,
|
|
418
463
|
from,
|
|
419
464
|
addressToReceive,
|
|
420
465
|
nextFisherExecutionNonce[from],
|
|
@@ -441,7 +486,7 @@ contract TreasuryExternalChainStation is
|
|
|
441
486
|
}
|
|
442
487
|
|
|
443
488
|
// Hyperlane Specific Functions //
|
|
444
|
-
|
|
489
|
+
|
|
445
490
|
/// @notice Calculates the fee required for Hyperlane cross-chain message dispatch
|
|
446
491
|
/// @dev Queries the Hyperlane mailbox for accurate fee estimation
|
|
447
492
|
/// @param toAddress Recipient address on the destination chain
|
|
@@ -572,11 +617,19 @@ contract TreasuryExternalChainStation is
|
|
|
572
617
|
string calldata _sourceAddress,
|
|
573
618
|
bytes calldata _payload
|
|
574
619
|
) internal override {
|
|
575
|
-
if (
|
|
576
|
-
|
|
620
|
+
if (
|
|
621
|
+
!AdvancedStrings.equal(
|
|
622
|
+
_sourceChain,
|
|
623
|
+
axelar.hostChainStationChainName
|
|
624
|
+
)
|
|
625
|
+
) revert ErrorsLib.ChainIdNotAuthorized();
|
|
577
626
|
|
|
578
|
-
if (
|
|
579
|
-
|
|
627
|
+
if (
|
|
628
|
+
!AdvancedStrings.equal(
|
|
629
|
+
_sourceAddress,
|
|
630
|
+
axelar.hostChainStationAddress
|
|
631
|
+
)
|
|
632
|
+
) revert ErrorsLib.SenderNotAuthorized();
|
|
580
633
|
|
|
581
634
|
decodeAndGive(_payload);
|
|
582
635
|
}
|
|
@@ -705,7 +758,7 @@ contract TreasuryExternalChainStation is
|
|
|
705
758
|
}
|
|
706
759
|
|
|
707
760
|
// Getter functions //
|
|
708
|
-
|
|
761
|
+
|
|
709
762
|
/// @notice Returns the complete admin configuration including proposals and timelock
|
|
710
763
|
/// @return Current admin address, proposed admin, and acceptance timestamp
|
|
711
764
|
function getAdmin() external view returns (AddressTypeProposal memory) {
|
|
@@ -798,4 +851,4 @@ contract TreasuryExternalChainStation is
|
|
|
798
851
|
/// @notice Disabled ownership renouncement function for security
|
|
799
852
|
/// @dev Prevents accidental loss of administrative control over the contract
|
|
800
853
|
function renounceOwnership() public virtual override onlyOwner {}
|
|
801
|
-
}
|
|
854
|
+
}
|
|
@@ -31,26 +31,53 @@ pragma solidity ^0.8.0;
|
|
|
31
31
|
* @author Mate labs
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
|
-
import {IERC20} from "@
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
import {
|
|
40
|
-
|
|
34
|
+
import {IERC20} from "@evvm/testnet-contracts/library/primitives/IERC20.sol";
|
|
35
|
+
import {IEvvm} from "@evvm/testnet-contracts/interfaces/IEvvm.sol";
|
|
36
|
+
import {
|
|
37
|
+
ErrorsLib
|
|
38
|
+
} from "@evvm/testnet-contracts/contracts/treasuryTwoChains/lib/ErrorsLib.sol";
|
|
39
|
+
import {
|
|
40
|
+
HostChainStationStructs
|
|
41
|
+
} from "@evvm/testnet-contracts/contracts/treasuryTwoChains/lib/HostChainStationStructs.sol";
|
|
42
|
+
|
|
43
|
+
import {
|
|
44
|
+
SignatureUtils
|
|
45
|
+
} from "@evvm/testnet-contracts/contracts/treasuryTwoChains/lib/SignatureUtils.sol";
|
|
46
|
+
import {
|
|
47
|
+
PayloadUtils
|
|
48
|
+
} from "@evvm/testnet-contracts/contracts/treasuryTwoChains/lib/PayloadUtils.sol";
|
|
41
49
|
|
|
42
50
|
import {IMailbox} from "@hyperlane-xyz/core/contracts/interfaces/IMailbox.sol";
|
|
43
51
|
|
|
44
|
-
import {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
import {
|
|
53
|
+
MessagingParams,
|
|
54
|
+
MessagingReceipt
|
|
55
|
+
} from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
|
|
56
|
+
import {
|
|
57
|
+
OApp,
|
|
58
|
+
Origin,
|
|
59
|
+
MessagingFee
|
|
60
|
+
} from "@layerzerolabs/oapp-evm/contracts/oapp/OApp.sol";
|
|
61
|
+
import {
|
|
62
|
+
OAppOptionsType3
|
|
63
|
+
} from "@layerzerolabs/oapp-evm/contracts/oapp/libs/OAppOptionsType3.sol";
|
|
64
|
+
import {
|
|
65
|
+
OptionsBuilder
|
|
66
|
+
} from "@layerzerolabs/oapp-evm/contracts/oapp/libs/OptionsBuilder.sol";
|
|
48
67
|
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
|
|
49
68
|
|
|
50
|
-
import {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
import {
|
|
69
|
+
import {
|
|
70
|
+
AxelarExecutable
|
|
71
|
+
} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/executable/AxelarExecutable.sol";
|
|
72
|
+
import {
|
|
73
|
+
IAxelarGasService
|
|
74
|
+
} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGasService.sol";
|
|
75
|
+
import {
|
|
76
|
+
IInterchainGasEstimation
|
|
77
|
+
} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IInterchainGasEstimation.sol";
|
|
78
|
+
import {
|
|
79
|
+
AdvancedStrings
|
|
80
|
+
} from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
|
|
54
81
|
|
|
55
82
|
contract TreasuryHostChainStation is
|
|
56
83
|
HostChainStationStructs,
|
|
@@ -58,9 +85,9 @@ contract TreasuryHostChainStation is
|
|
|
58
85
|
OAppOptionsType3,
|
|
59
86
|
AxelarExecutable
|
|
60
87
|
{
|
|
61
|
-
/// @notice
|
|
88
|
+
/// @notice EVVM core contract for balance operations
|
|
62
89
|
/// @dev Used to integrate with EVVM's balance management and token operations
|
|
63
|
-
|
|
90
|
+
IEvvm evvm;
|
|
64
91
|
|
|
65
92
|
/// @notice Admin address management with time-delayed proposals
|
|
66
93
|
/// @dev Stores current admin, proposed admin, and acceptance timestamp
|
|
@@ -147,11 +174,12 @@ contract TreasuryHostChainStation is
|
|
|
147
174
|
address _admin,
|
|
148
175
|
CrosschainConfig memory _crosschainConfig
|
|
149
176
|
)
|
|
150
|
-
OApp(_crosschainConfig.endpointAddress, _admin)
|
|
177
|
+
OApp(_crosschainConfig.layerZero.endpointAddress, _admin)
|
|
151
178
|
Ownable(_admin)
|
|
152
|
-
AxelarExecutable(_crosschainConfig.gatewayAddress)
|
|
179
|
+
AxelarExecutable(_crosschainConfig.axelar.gatewayAddress)
|
|
153
180
|
{
|
|
154
|
-
|
|
181
|
+
evvm = IEvvm(_evvmAddress);
|
|
182
|
+
|
|
155
183
|
admin = AddressTypeProposal({
|
|
156
184
|
current: _admin,
|
|
157
185
|
proposal: address(0),
|
|
@@ -159,21 +187,25 @@ contract TreasuryHostChainStation is
|
|
|
159
187
|
});
|
|
160
188
|
hyperlane = HyperlaneConfig({
|
|
161
189
|
externalChainStationDomainId: _crosschainConfig
|
|
190
|
+
.hyperlane
|
|
162
191
|
.externalChainStationDomainId,
|
|
163
192
|
externalChainStationAddress: "",
|
|
164
|
-
mailboxAddress: _crosschainConfig.mailboxAddress
|
|
193
|
+
mailboxAddress: _crosschainConfig.hyperlane.mailboxAddress
|
|
165
194
|
});
|
|
166
195
|
layerZero = LayerZeroConfig({
|
|
167
|
-
externalChainStationEid: _crosschainConfig
|
|
196
|
+
externalChainStationEid: _crosschainConfig
|
|
197
|
+
.layerZero
|
|
198
|
+
.externalChainStationEid,
|
|
168
199
|
externalChainStationAddress: "",
|
|
169
|
-
endpointAddress: _crosschainConfig.endpointAddress
|
|
200
|
+
endpointAddress: _crosschainConfig.layerZero.endpointAddress
|
|
170
201
|
});
|
|
171
202
|
axelar = AxelarConfig({
|
|
172
203
|
externalChainStationChainName: _crosschainConfig
|
|
204
|
+
.axelar
|
|
173
205
|
.externalChainStationChainName,
|
|
174
206
|
externalChainStationAddress: "",
|
|
175
|
-
gasServiceAddress: _crosschainConfig.gasServiceAddress,
|
|
176
|
-
gatewayAddress: _crosschainConfig.gatewayAddress
|
|
207
|
+
gasServiceAddress: _crosschainConfig.axelar.gasServiceAddress,
|
|
208
|
+
gatewayAddress: _crosschainConfig.axelar.gatewayAddress
|
|
177
209
|
});
|
|
178
210
|
}
|
|
179
211
|
|
|
@@ -214,10 +246,10 @@ contract TreasuryHostChainStation is
|
|
|
214
246
|
uint256 amount,
|
|
215
247
|
bytes1 protocolToExecute
|
|
216
248
|
) external payable {
|
|
217
|
-
if (token ==
|
|
249
|
+
if (token == evvm.getEvvmMetadata().principalTokenAddress)
|
|
218
250
|
revert ErrorsLib.PrincipalTokenIsNotWithdrawable();
|
|
219
251
|
|
|
220
|
-
if (
|
|
252
|
+
if (evvm.getBalance(msg.sender, token) < amount)
|
|
221
253
|
revert ErrorsLib.InsufficientBalance();
|
|
222
254
|
|
|
223
255
|
executerEVVM(false, msg.sender, token, amount);
|
|
@@ -285,7 +317,7 @@ contract TreasuryHostChainStation is
|
|
|
285
317
|
) external onlyFisherExecutor {
|
|
286
318
|
if (
|
|
287
319
|
!SignatureUtils.verifyMessageSignedForFisherBridge(
|
|
288
|
-
|
|
320
|
+
evvm.getEvvmID(),
|
|
289
321
|
from,
|
|
290
322
|
addressToReceive,
|
|
291
323
|
nextFisherExecutionNonce[from],
|
|
@@ -320,17 +352,15 @@ contract TreasuryHostChainStation is
|
|
|
320
352
|
uint256 amount,
|
|
321
353
|
bytes memory signature
|
|
322
354
|
) external onlyFisherExecutor {
|
|
323
|
-
if (
|
|
324
|
-
|
|
325
|
-
Evvm(evvmAddress).getEvvmMetadata().principalTokenAddress
|
|
326
|
-
) revert ErrorsLib.PrincipalTokenIsNotWithdrawable();
|
|
355
|
+
if (tokenAddress == evvm.getEvvmMetadata().principalTokenAddress)
|
|
356
|
+
revert ErrorsLib.PrincipalTokenIsNotWithdrawable();
|
|
327
357
|
|
|
328
|
-
if (
|
|
358
|
+
if (evvm.getBalance(from, tokenAddress) < amount)
|
|
329
359
|
revert ErrorsLib.InsufficientBalance();
|
|
330
360
|
|
|
331
361
|
if (
|
|
332
362
|
!SignatureUtils.verifyMessageSignedForFisherBridge(
|
|
333
|
-
|
|
363
|
+
evvm.getEvvmID(),
|
|
334
364
|
from,
|
|
335
365
|
addressToReceive,
|
|
336
366
|
nextFisherExecutionNonce[from],
|
|
@@ -359,7 +389,7 @@ contract TreasuryHostChainStation is
|
|
|
359
389
|
}
|
|
360
390
|
|
|
361
391
|
// Hyperlane Specific Functions //
|
|
362
|
-
|
|
392
|
+
|
|
363
393
|
/// @notice Calculates the fee required for Hyperlane cross-chain message dispatch
|
|
364
394
|
/// @dev Queries the Hyperlane mailbox for accurate fee estimation
|
|
365
395
|
/// @param toAddress Recipient address on the destination chain
|
|
@@ -490,11 +520,19 @@ contract TreasuryHostChainStation is
|
|
|
490
520
|
string calldata _sourceAddress,
|
|
491
521
|
bytes calldata _payload
|
|
492
522
|
) internal override {
|
|
493
|
-
if (
|
|
494
|
-
|
|
523
|
+
if (
|
|
524
|
+
!AdvancedStrings.equal(
|
|
525
|
+
_sourceChain,
|
|
526
|
+
axelar.externalChainStationChainName
|
|
527
|
+
)
|
|
528
|
+
) revert ErrorsLib.ChainIdNotAuthorized();
|
|
495
529
|
|
|
496
|
-
if (
|
|
497
|
-
|
|
530
|
+
if (
|
|
531
|
+
!AdvancedStrings.equal(
|
|
532
|
+
_sourceAddress,
|
|
533
|
+
axelar.externalChainStationAddress
|
|
534
|
+
)
|
|
535
|
+
) revert ErrorsLib.SenderNotAuthorized();
|
|
498
536
|
|
|
499
537
|
decodeAndDeposit(_payload);
|
|
500
538
|
}
|
|
@@ -624,7 +662,7 @@ contract TreasuryHostChainStation is
|
|
|
624
662
|
}
|
|
625
663
|
|
|
626
664
|
// Getter functions //
|
|
627
|
-
|
|
665
|
+
|
|
628
666
|
/// @notice Returns the complete admin configuration including proposals and timelock
|
|
629
667
|
/// @return Current admin address, proposed admin, and acceptance timestamp
|
|
630
668
|
function getAdmin() external view returns (AddressTypeProposal memory) {
|
|
@@ -654,7 +692,7 @@ contract TreasuryHostChainStation is
|
|
|
654
692
|
/// @notice Returns the EVVM core contract address
|
|
655
693
|
/// @return Address of the EVVM contract used for balance operations
|
|
656
694
|
function getEvvmAddress() external view returns (address) {
|
|
657
|
-
return
|
|
695
|
+
return address(evvm);
|
|
658
696
|
}
|
|
659
697
|
|
|
660
698
|
/// @notice Returns the complete Hyperlane protocol configuration
|
|
@@ -714,14 +752,10 @@ contract TreasuryHostChainStation is
|
|
|
714
752
|
) internal {
|
|
715
753
|
if (typeOfExecution) {
|
|
716
754
|
// true = add
|
|
717
|
-
|
|
755
|
+
evvm.addAmountToUser(userToExecute, token, amount);
|
|
718
756
|
} else {
|
|
719
757
|
// false = remove
|
|
720
|
-
|
|
721
|
-
userToExecute,
|
|
722
|
-
token,
|
|
723
|
-
amount
|
|
724
|
-
);
|
|
758
|
+
evvm.removeAmountFromUser(userToExecute, token, amount);
|
|
725
759
|
}
|
|
726
760
|
}
|
|
727
761
|
|
|
@@ -43,4 +43,6 @@ library ErrorsLib {
|
|
|
43
43
|
/// @notice Thrown when Fisher bridge signature verification fails
|
|
44
44
|
/// @dev Security check for Fisher bridge operations to ensure transaction authenticity and prevent replay attacks
|
|
45
45
|
error InvalidSignature();
|
|
46
|
+
|
|
47
|
+
error WindowToChangeEvvmIDExpired();
|
|
46
48
|
}
|
|
@@ -60,21 +60,10 @@ abstract contract ExternalChainStationStructs {
|
|
|
60
60
|
|
|
61
61
|
/// @notice Unified cross-chain configuration for all supported protocols
|
|
62
62
|
/// @dev Single structure containing all protocol configurations for deployment
|
|
63
|
-
/// @param hostChainStationDomainId Hyperlane domain ID for host chain
|
|
64
|
-
/// @param mailboxAddress Hyperlane mailbox contract address
|
|
65
|
-
/// @param hostChainStationEid LayerZero endpoint ID for host chain
|
|
66
|
-
/// @param endpointAddress LayerZero V2 endpoint contract address
|
|
67
|
-
/// @param hostChainStationChainName Axelar chain name for host chain
|
|
68
|
-
/// @param gasServiceAddress Axelar gas service contract address
|
|
69
|
-
/// @param gatewayAddress Axelar gateway contract address
|
|
70
63
|
struct CrosschainConfig {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
address endpointAddress;
|
|
75
|
-
string hostChainStationChainName;
|
|
76
|
-
address gasServiceAddress;
|
|
77
|
-
address gatewayAddress;
|
|
64
|
+
HyperlaneConfig hyperlane;
|
|
65
|
+
LayerZeroConfig layerZero;
|
|
66
|
+
AxelarConfig axelar;
|
|
78
67
|
}
|
|
79
68
|
|
|
80
69
|
/// @notice Parameters for coordinated host chain address changes across all protocols
|
|
@@ -69,13 +69,9 @@ abstract contract HostChainStationStructs {
|
|
|
69
69
|
/// @param gasServiceAddress Axelar gas service contract address
|
|
70
70
|
/// @param gatewayAddress Axelar gateway contract address
|
|
71
71
|
struct CrosschainConfig {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
address endpointAddress;
|
|
76
|
-
string externalChainStationChainName;
|
|
77
|
-
address gasServiceAddress;
|
|
78
|
-
address gatewayAddress;
|
|
72
|
+
HyperlaneConfig hyperlane;
|
|
73
|
+
LayerZeroConfig layerZero;
|
|
74
|
+
AxelarConfig axelar;
|
|
79
75
|
}
|
|
80
76
|
|
|
81
77
|
/// @notice Parameters for coordinated external chain address changes across all protocols
|