@evvm/testnet-contracts 2.3.0 → 3.0.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/README.md +44 -24
- package/contracts/core/Core.sol +1392 -0
- package/contracts/core/lib/CoreStorage.sol +171 -0
- package/contracts/nameService/NameService.sol +613 -543
- package/contracts/nameService/lib/IdentityValidation.sol +15 -21
- package/contracts/p2pSwap/P2PSwap.sol +258 -145
- package/contracts/staking/Estimator.sol +25 -44
- package/contracts/staking/Staking.sol +284 -262
- package/contracts/treasury/Treasury.sol +40 -47
- package/contracts/treasuryTwoChains/TreasuryExternalChainStation.sol +585 -198
- package/contracts/treasuryTwoChains/TreasuryHostChainStation.sol +425 -174
- package/contracts/treasuryTwoChains/lib/PayloadUtils.sol +2 -4
- package/interfaces/{IEvvm.sol → ICore.sol} +58 -25
- package/interfaces/IEstimator.sol +1 -1
- package/interfaces/INameService.sol +46 -49
- package/interfaces/IP2PSwap.sol +16 -17
- package/interfaces/IStaking.sol +21 -17
- package/interfaces/ITreasury.sol +2 -1
- package/interfaces/ITreasuryExternalChainStation.sol +15 -9
- package/interfaces/ITreasuryHostChainStation.sol +14 -11
- package/interfaces/IUserValidator.sol +6 -0
- package/library/Erc191TestBuilder.sol +336 -471
- package/library/EvvmService.sol +27 -71
- package/library/errors/CoreError.sol +116 -0
- package/library/errors/CrossChainTreasuryError.sol +36 -0
- package/library/errors/NameServiceError.sol +79 -0
- package/library/errors/StakingError.sol +79 -0
- package/{contracts/treasury/lib/ErrorsLib.sol → library/errors/TreasuryError.sol} +9 -17
- package/library/structs/CoreStructs.sol +146 -0
- package/library/structs/ExternalChainStationStructs.sol +92 -0
- package/library/structs/HostChainStationStructs.sol +77 -0
- package/library/structs/NameServiceStructs.sol +47 -0
- package/library/structs/P2PSwapStructs.sol +127 -0
- package/library/structs/StakingStructs.sol +67 -0
- package/library/utils/AdvancedStrings.sol +62 -44
- package/library/utils/CAUtils.sol +29 -0
- package/library/utils/governance/Admin.sol +66 -0
- package/library/utils/governance/ProposalStructs.sol +49 -0
- package/library/utils/service/CoreExecution.sol +158 -0
- package/library/utils/service/StakingServiceUtils.sol +20 -37
- package/library/utils/signature/CoreHashUtils.sol +73 -0
- package/library/utils/signature/NameServiceHashUtils.sol +156 -0
- package/library/utils/signature/P2PSwapHashUtils.sol +65 -0
- package/library/utils/signature/StakingHashUtils.sol +41 -0
- package/library/utils/signature/TreasuryCrossChainHashUtils.sol +40 -0
- package/package.json +1 -1
- package/contracts/evvm/Evvm.sol +0 -1300
- package/contracts/evvm/lib/ErrorsLib.sol +0 -131
- package/contracts/evvm/lib/EvvmStorage.sol +0 -217
- package/contracts/evvm/lib/EvvmStructs.sol +0 -208
- package/contracts/evvm/lib/SignatureUtils.sol +0 -162
- package/contracts/nameService/lib/ErrorsLib.sol +0 -155
- package/contracts/nameService/lib/NameServiceStructs.sol +0 -125
- package/contracts/nameService/lib/SignatureUtils.sol +0 -420
- package/contracts/p2pSwap/lib/P2PSwapStructs.sol +0 -59
- package/contracts/p2pSwap/lib/SignatureUtils.sol +0 -98
- package/contracts/staking/lib/ErrorsLib.sol +0 -98
- package/contracts/staking/lib/SignatureUtils.sol +0 -105
- package/contracts/staking/lib/StakingStructs.sol +0 -106
- package/contracts/treasuryTwoChains/lib/ErrorsLib.sol +0 -48
- package/contracts/treasuryTwoChains/lib/ExternalChainStationStructs.sol +0 -80
- package/contracts/treasuryTwoChains/lib/HostChainStationStructs.sol +0 -87
- package/contracts/treasuryTwoChains/lib/SignatureUtils.sol +0 -79
- package/library/utils/GovernanceUtils.sol +0 -81
- package/library/utils/nonces/AsyncNonce.sol +0 -74
- package/library/utils/nonces/SyncNonce.sol +0 -71
- package/library/utils/service/EvvmPayments.sol +0 -144
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: EVVM-NONCOMMERCIAL-1.0
|
|
2
|
-
// Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
|
|
3
|
-
pragma solidity ^0.8.0;
|
|
4
|
-
/**
|
|
5
|
-
* @title SignatureUtils
|
|
6
|
-
* @author Mate Labs
|
|
7
|
-
* @notice Library for EIP-191 signature verification in the Staking contract
|
|
8
|
-
* @dev This library is exclusive to the Staking.sol contract and provides
|
|
9
|
-
* functions to verify signatures for staking operations.
|
|
10
|
-
*
|
|
11
|
-
* Signature Format:
|
|
12
|
-
* All signatures follow the EIP-191 standard with message format:
|
|
13
|
-
* "[evvmID],[functionName],[isStaking],[amountOfStaking],[nonce]"
|
|
14
|
-
*
|
|
15
|
-
* Supported Operations:
|
|
16
|
-
* - Presale staking: Limited staking for pre-approved addresses
|
|
17
|
-
* - Public staking: Open staking for all users when enabled
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
import {
|
|
21
|
-
SignatureUtil
|
|
22
|
-
} from "@evvm/testnet-contracts/library/utils/SignatureUtil.sol";
|
|
23
|
-
import {
|
|
24
|
-
AdvancedStrings
|
|
25
|
-
} from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
|
|
26
|
-
|
|
27
|
-
library SignatureUtils {
|
|
28
|
-
/**
|
|
29
|
-
* @dev Uses EIP-191 (https://eips.ethereum.org/EIPS/eip-191) for message signing
|
|
30
|
-
* and verification. The following functions verify messages signed by users
|
|
31
|
-
* for staking operations.
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @notice Verifies an EIP-191 signature for presale staking operations
|
|
36
|
-
* @dev Message format: "[evvmID],presaleStaking,[isStaking],[amountOfStaking],[nonce]"
|
|
37
|
-
* Presale staking has a limit of 2 staking tokens per user
|
|
38
|
-
* @param evvmID Unique identifier of the EVVM instance
|
|
39
|
-
* @param signer Address that should have signed the message
|
|
40
|
-
* @param isStaking True for staking operation, false for unstaking
|
|
41
|
-
* @param amountOfStaking Amount of staking tokens (always 1 for presale)
|
|
42
|
-
* @param nonce Unique nonce to prevent replay attacks
|
|
43
|
-
* @param signature 65-byte EIP-191 signature to verify
|
|
44
|
-
* @return True if the signature is valid and matches the expected signer
|
|
45
|
-
*/
|
|
46
|
-
function verifyMessageSignedForPresaleStake(
|
|
47
|
-
uint256 evvmID,
|
|
48
|
-
address signer,
|
|
49
|
-
bool isStaking,
|
|
50
|
-
uint256 amountOfStaking,
|
|
51
|
-
uint256 nonce,
|
|
52
|
-
bytes memory signature
|
|
53
|
-
) internal pure returns (bool) {
|
|
54
|
-
return
|
|
55
|
-
SignatureUtil.verifySignature(
|
|
56
|
-
evvmID,
|
|
57
|
-
"presaleStaking",
|
|
58
|
-
string.concat(
|
|
59
|
-
AdvancedStrings.boolToString(isStaking),
|
|
60
|
-
",",
|
|
61
|
-
AdvancedStrings.uintToString(amountOfStaking),
|
|
62
|
-
",",
|
|
63
|
-
AdvancedStrings.uintToString(nonce)
|
|
64
|
-
),
|
|
65
|
-
signature,
|
|
66
|
-
signer
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @notice Verifies an EIP-191 signature for public staking operations
|
|
72
|
-
* @dev Message format: "[evvmID],publicStaking,[isStaking],[amountOfStaking],[nonce]"
|
|
73
|
-
* Public staking is available to all users when the feature is enabled
|
|
74
|
-
* @param evvmID Unique identifier of the EVVM instance
|
|
75
|
-
* @param signer Address that should have signed the message
|
|
76
|
-
* @param isStaking True for staking operation, false for unstaking
|
|
77
|
-
* @param amountOfStaking Amount of staking tokens to stake/unstake
|
|
78
|
-
* @param nonce Unique nonce to prevent replay attacks
|
|
79
|
-
* @param signature 65-byte EIP-191 signature to verify
|
|
80
|
-
* @return True if the signature is valid and matches the expected signer
|
|
81
|
-
*/
|
|
82
|
-
function verifyMessageSignedForPublicStake(
|
|
83
|
-
uint256 evvmID,
|
|
84
|
-
address signer,
|
|
85
|
-
bool isStaking,
|
|
86
|
-
uint256 amountOfStaking,
|
|
87
|
-
uint256 nonce,
|
|
88
|
-
bytes memory signature
|
|
89
|
-
) internal pure returns (bool) {
|
|
90
|
-
return
|
|
91
|
-
SignatureUtil.verifySignature(
|
|
92
|
-
evvmID,
|
|
93
|
-
"publicStaking",
|
|
94
|
-
string.concat(
|
|
95
|
-
AdvancedStrings.boolToString(isStaking),
|
|
96
|
-
",",
|
|
97
|
-
AdvancedStrings.uintToString(amountOfStaking),
|
|
98
|
-
",",
|
|
99
|
-
AdvancedStrings.uintToString(nonce)
|
|
100
|
-
),
|
|
101
|
-
signature,
|
|
102
|
-
signer
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: EVVM-NONCOMMERCIAL-1.0
|
|
2
|
-
// Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
|
|
3
|
-
|
|
4
|
-
pragma solidity ^0.8.0;
|
|
5
|
-
/**
|
|
6
|
-
* @title StakingStructs
|
|
7
|
-
* @author Mate Labs
|
|
8
|
-
* @notice Abstract contract containing all data structures used by the Staking contract
|
|
9
|
-
* @dev This contract is exclusive to the Staking.sol contract and defines the data
|
|
10
|
-
* structures for managing staking operations, governance proposals, and user history.
|
|
11
|
-
*
|
|
12
|
-
* Structure Categories:
|
|
13
|
-
* - Staker Metadata: presaleStakerMetadata, HistoryMetadata
|
|
14
|
-
* - Governance Proposals: AddressTypeProposal, UintTypeProposal, BoolTypeProposal
|
|
15
|
-
* - Service Staking: ServiceStakingMetadata, AccountMetadata
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
abstract contract StakingStructs {
|
|
19
|
-
/**
|
|
20
|
-
* @dev Metadata for presale stakers
|
|
21
|
-
* @param isAllow Whether the address is allowed to participate in presale staking
|
|
22
|
-
* @param stakingAmount Current number of staking tokens staked (max 2 for presale)
|
|
23
|
-
*/
|
|
24
|
-
struct presaleStakerMetadata {
|
|
25
|
-
bool isAllow;
|
|
26
|
-
uint256 stakingAmount;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @dev Struct to store the history of the user
|
|
31
|
-
* @param transactionType Type of transaction:
|
|
32
|
-
* - 0x01 for staking
|
|
33
|
-
* - 0x02 for unstaking
|
|
34
|
-
* - Other values for yield/reward transactions
|
|
35
|
-
* @param amount Amount of staking staked/unstaked or reward received
|
|
36
|
-
* @param timestamp Timestamp when the transaction occurred
|
|
37
|
-
* @param totalStaked Total amount of staking currently staked after this transaction
|
|
38
|
-
*/
|
|
39
|
-
struct HistoryMetadata {
|
|
40
|
-
bytes32 transactionType;
|
|
41
|
-
uint256 amount;
|
|
42
|
-
uint256 timestamp;
|
|
43
|
-
uint256 totalStaked;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* @dev Struct for managing address change proposals with time delay
|
|
48
|
-
* @param actual Current active address
|
|
49
|
-
* @param proposal Proposed new address
|
|
50
|
-
* @param timeToAccept Timestamp when the proposal can be accepted
|
|
51
|
-
*/
|
|
52
|
-
struct AddressTypeProposal {
|
|
53
|
-
address actual;
|
|
54
|
-
address proposal;
|
|
55
|
-
uint256 timeToAccept;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @dev Struct for managing uint256 change proposals with time delay
|
|
60
|
-
* @param actual Current active value
|
|
61
|
-
* @param proposal Proposed new value
|
|
62
|
-
* @param timeToAccept Timestamp when the proposal can be accepted
|
|
63
|
-
*/
|
|
64
|
-
struct UintTypeProposal {
|
|
65
|
-
uint256 actual;
|
|
66
|
-
uint256 proposal;
|
|
67
|
-
uint256 timeToAccept;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @dev Struct for managing boolean flag changes with time delay
|
|
72
|
-
* @param flag Current boolean state
|
|
73
|
-
* @param timeToAccept Timestamp when the flag change can be executed
|
|
74
|
-
*/
|
|
75
|
-
struct BoolTypeProposal {
|
|
76
|
-
bool flag;
|
|
77
|
-
uint256 timeToAccept;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* @dev Struct to store service staking metadata during the staking process
|
|
82
|
-
* @param service Address of the service or contract account
|
|
83
|
-
* @param timestamp Timestamp when the prepareServiceStaking was called
|
|
84
|
-
* @param amountOfStaking Amount of staking tokens to be staked
|
|
85
|
-
* @param amountServiceBeforeStaking Service's Principal Token balance before staking
|
|
86
|
-
* @param amountStakingBeforeStaking Staking contract's Principal Token balance before staking
|
|
87
|
-
*/
|
|
88
|
-
struct ServiceStakingMetadata {
|
|
89
|
-
address service;
|
|
90
|
-
uint256 timestamp;
|
|
91
|
-
uint256 amountOfStaking;
|
|
92
|
-
uint256 amountServiceBeforeStaking;
|
|
93
|
-
uint256 amountStakingBeforeStaking;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* @dev Struct to encapsulate account metadata for staking operations
|
|
98
|
-
* @param Address Address of the account
|
|
99
|
-
* @param IsAService Boolean indicating if the account is a smart contract (service) account
|
|
100
|
-
*/
|
|
101
|
-
struct AccountMetadata {
|
|
102
|
-
address Address;
|
|
103
|
-
bool IsAService;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: EVVM-NONCOMMERCIAL-1.0
|
|
2
|
-
// Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
|
|
3
|
-
|
|
4
|
-
pragma solidity ^0.8.0;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @title ErrorsLib
|
|
8
|
-
* @author Mate labs
|
|
9
|
-
* @notice Custom error definitions for Treasury Cross-Chain operations
|
|
10
|
-
* @dev Centralized error library for both TreasuryHostChainStation and TreasuryExternalChainStation
|
|
11
|
-
* Provides gas-efficient custom errors with descriptive names for better debugging
|
|
12
|
-
* and user experience across all cross-chain treasury operations
|
|
13
|
-
*/
|
|
14
|
-
library ErrorsLib {
|
|
15
|
-
/// @notice Thrown when a user has insufficient balance for the requested operation
|
|
16
|
-
/// @dev Used in withdraw operations and Fisher bridge transfers when EVVM balance is too low
|
|
17
|
-
error InsufficientBalance();
|
|
18
|
-
|
|
19
|
-
/// @notice Thrown when attempting to withdraw or bridge the Principal Token (MATE)
|
|
20
|
-
/// @dev Principal Token is reserved for EVVM ecosystem operations and cannot be withdrawn cross-chain
|
|
21
|
-
error PrincipalTokenIsNotWithdrawable();
|
|
22
|
-
|
|
23
|
-
/// @notice Thrown when deposit amount validation fails
|
|
24
|
-
/// @dev Generic validation error for deposit amount issues beyond zero checks
|
|
25
|
-
error InvalidDepositAmount();
|
|
26
|
-
|
|
27
|
-
/// @notice Thrown when deposit or transfer amount is zero or negative
|
|
28
|
-
/// @dev Prevents meaningless transactions and ensures positive value transfers
|
|
29
|
-
error DepositAmountMustBeGreaterThanZero();
|
|
30
|
-
|
|
31
|
-
/// @notice Thrown when Hyperlane message sender is not the authorized mailbox contract
|
|
32
|
-
/// @dev Security check to prevent unauthorized cross-chain message execution via Hyperlane
|
|
33
|
-
error MailboxNotAuthorized();
|
|
34
|
-
|
|
35
|
-
/// @notice Thrown when cross-chain message sender is not the authorized counterpart station
|
|
36
|
-
/// @dev Security check across all protocols (Hyperlane, LayerZero, Axelar) to prevent impersonation
|
|
37
|
-
error SenderNotAuthorized();
|
|
38
|
-
|
|
39
|
-
/// @notice Thrown when cross-chain message originates from non-authorized chain
|
|
40
|
-
/// @dev Prevents cross-chain attacks from unauthorized chains or wrong network configurations
|
|
41
|
-
error ChainIdNotAuthorized();
|
|
42
|
-
|
|
43
|
-
/// @notice Thrown when Fisher bridge signature verification fails
|
|
44
|
-
/// @dev Security check for Fisher bridge operations to ensure transaction authenticity and prevent replay attacks
|
|
45
|
-
error InvalidSignature();
|
|
46
|
-
|
|
47
|
-
error WindowToChangeEvvmIDExpired();
|
|
48
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: EVVM-NONCOMMERCIAL-1.0
|
|
2
|
-
// Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
|
|
3
|
-
|
|
4
|
-
pragma solidity ^0.8.0;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @title ExternalChainStationStructs
|
|
8
|
-
* @author Mate labs
|
|
9
|
-
* @notice Shared data structures for External Chain Station cross-chain treasury operations
|
|
10
|
-
* @dev Defines all structural types used by TreasuryExternalChainStation contract
|
|
11
|
-
* These structures ensure type safety and consistency for cross-chain operations
|
|
12
|
-
* from external chains to the host chain in the EVVM ecosystem
|
|
13
|
-
*/
|
|
14
|
-
abstract contract ExternalChainStationStructs {
|
|
15
|
-
/// @notice Time-delayed address change proposal structure for governance
|
|
16
|
-
/// @dev Used for admin and Fisher executor address changes with 1-day delay
|
|
17
|
-
/// @param current Currently active address with full privileges
|
|
18
|
-
/// @param proposal Proposed new address waiting for acceptance
|
|
19
|
-
/// @param timeToAccept Timestamp when the proposal becomes acceptable
|
|
20
|
-
struct AddressTypeProposal {
|
|
21
|
-
address current;
|
|
22
|
-
address proposal;
|
|
23
|
-
uint256 timeToAccept;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/// @notice Hyperlane protocol configuration for cross-chain messaging
|
|
27
|
-
/// @dev Configuration for reliable cross-chain communication via Hyperlane
|
|
28
|
-
/// @param hostChainStationDomainId Hyperlane domain identifier for the host chain
|
|
29
|
-
/// @param hostChainStationAddress Host chain station address in bytes32 format
|
|
30
|
-
/// @param mailboxAddress Hyperlane mailbox contract address on this chain
|
|
31
|
-
struct HyperlaneConfig {
|
|
32
|
-
uint32 hostChainStationDomainId;
|
|
33
|
-
bytes32 hostChainStationAddress;
|
|
34
|
-
address mailboxAddress;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/// @notice LayerZero protocol configuration for omnichain messaging
|
|
38
|
-
/// @dev Configuration for omnichain interoperability via LayerZero V2
|
|
39
|
-
/// @param hostChainStationEid LayerZero endpoint identifier for the host chain
|
|
40
|
-
/// @param hostChainStationAddress Host chain station address in bytes32 format
|
|
41
|
-
/// @param endpointAddress LayerZero V2 endpoint contract address on this chain
|
|
42
|
-
struct LayerZeroConfig {
|
|
43
|
-
uint32 hostChainStationEid;
|
|
44
|
-
bytes32 hostChainStationAddress;
|
|
45
|
-
address endpointAddress;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/// @notice Axelar protocol configuration for cross-chain communication
|
|
49
|
-
/// @dev Configuration for secure cross-chain transfers via Axelar Network
|
|
50
|
-
/// @param hostChainStationChainName Axelar chain identifier for the host chain
|
|
51
|
-
/// @param hostChainStationAddress Host chain station address in string format
|
|
52
|
-
/// @param gasServiceAddress Axelar gas service contract address for fee payments
|
|
53
|
-
/// @param gatewayAddress Axelar gateway contract address for message routing
|
|
54
|
-
struct AxelarConfig {
|
|
55
|
-
string hostChainStationChainName;
|
|
56
|
-
string hostChainStationAddress;
|
|
57
|
-
address gasServiceAddress;
|
|
58
|
-
address gatewayAddress;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/// @notice Unified cross-chain configuration for all supported protocols
|
|
62
|
-
/// @dev Single structure containing all protocol configurations for deployment
|
|
63
|
-
struct CrosschainConfig {
|
|
64
|
-
HyperlaneConfig hyperlane;
|
|
65
|
-
LayerZeroConfig layerZero;
|
|
66
|
-
AxelarConfig axelar;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/// @notice Parameters for coordinated host chain address changes across all protocols
|
|
70
|
-
/// @dev Used to propose and execute synchronized address updates with time delay
|
|
71
|
-
/// @param porposeAddress_AddressType Address format for Hyperlane and LayerZero protocols
|
|
72
|
-
/// @param porposeAddress_StringType String format for Axelar protocol compatibility
|
|
73
|
-
/// @param timeToAccept Timestamp when the address change proposal can be executed
|
|
74
|
-
struct ChangeHostChainAddressParams {
|
|
75
|
-
address porposeAddress_AddressType;
|
|
76
|
-
string porposeAddress_StringType;
|
|
77
|
-
uint256 timeToAccept;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: EVVM-NONCOMMERCIAL-1.0
|
|
2
|
-
// Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
|
|
3
|
-
|
|
4
|
-
pragma solidity ^0.8.0;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @title HostChainStationStructs
|
|
8
|
-
* @author Mate labs
|
|
9
|
-
* @notice Shared data structures for Host Chain Station cross-chain treasury operations
|
|
10
|
-
* @dev Defines all structural types used by TreasuryHostChainStation contract
|
|
11
|
-
* These structures ensure type safety and consistency for cross-chain operations
|
|
12
|
-
* from the host chain to external chains in the EVVM ecosystem
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
abstract contract HostChainStationStructs {
|
|
16
|
-
/// @notice Time-delayed address change proposal structure for governance
|
|
17
|
-
/// @dev Used for admin and Fisher executor address changes with 1-day delay
|
|
18
|
-
/// @param current Currently active address with full privileges
|
|
19
|
-
/// @param proposal Proposed new address waiting for acceptance
|
|
20
|
-
/// @param timeToAccept Timestamp when the proposal becomes acceptable
|
|
21
|
-
struct AddressTypeProposal {
|
|
22
|
-
address current;
|
|
23
|
-
address proposal;
|
|
24
|
-
uint256 timeToAccept;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/// @notice Hyperlane protocol configuration for cross-chain messaging
|
|
28
|
-
/// @dev Configuration for reliable cross-chain communication via Hyperlane
|
|
29
|
-
/// @param externalChainStationDomainId Hyperlane domain identifier for the external chain
|
|
30
|
-
/// @param externalChainStationAddress External chain station address in bytes32 format
|
|
31
|
-
/// @param mailboxAddress Hyperlane mailbox contract address on this host chain
|
|
32
|
-
struct HyperlaneConfig {
|
|
33
|
-
uint32 externalChainStationDomainId;
|
|
34
|
-
bytes32 externalChainStationAddress;
|
|
35
|
-
address mailboxAddress;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/// @notice LayerZero protocol configuration for omnichain messaging
|
|
39
|
-
/// @dev Configuration for omnichain interoperability via LayerZero V2
|
|
40
|
-
/// @param externalChainStationEid LayerZero endpoint identifier for the external chain
|
|
41
|
-
/// @param externalChainStationAddress External chain station address in bytes32 format
|
|
42
|
-
/// @param endpointAddress LayerZero V2 endpoint contract address on this host chain
|
|
43
|
-
struct LayerZeroConfig {
|
|
44
|
-
uint32 externalChainStationEid;
|
|
45
|
-
bytes32 externalChainStationAddress;
|
|
46
|
-
address endpointAddress;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/// @notice Axelar protocol configuration for cross-chain communication
|
|
50
|
-
/// @dev Configuration for secure cross-chain transfers via Axelar Network
|
|
51
|
-
/// @param externalChainStationChainName Axelar chain identifier for the external chain
|
|
52
|
-
/// @param externalChainStationAddress External chain station address in string format
|
|
53
|
-
/// @param gasServiceAddress Axelar gas service contract address for fee payments
|
|
54
|
-
/// @param gatewayAddress Axelar gateway contract address for message routing
|
|
55
|
-
struct AxelarConfig {
|
|
56
|
-
string externalChainStationChainName;
|
|
57
|
-
string externalChainStationAddress;
|
|
58
|
-
address gasServiceAddress;
|
|
59
|
-
address gatewayAddress;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/// @notice Unified cross-chain configuration for all supported protocols
|
|
63
|
-
/// @dev Single structure containing all protocol configurations for deployment
|
|
64
|
-
/// @param externalChainStationDomainId Hyperlane domain ID for external chain
|
|
65
|
-
/// @param mailboxAddress Hyperlane mailbox contract address
|
|
66
|
-
/// @param externalChainStationEid LayerZero endpoint ID for external chain
|
|
67
|
-
/// @param endpointAddress LayerZero V2 endpoint contract address
|
|
68
|
-
/// @param externalChainStationChainName Axelar chain name for external chain
|
|
69
|
-
/// @param gasServiceAddress Axelar gas service contract address
|
|
70
|
-
/// @param gatewayAddress Axelar gateway contract address
|
|
71
|
-
struct CrosschainConfig {
|
|
72
|
-
HyperlaneConfig hyperlane;
|
|
73
|
-
LayerZeroConfig layerZero;
|
|
74
|
-
AxelarConfig axelar;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/// @notice Parameters for coordinated external chain address changes across all protocols
|
|
78
|
-
/// @dev Used to propose and execute synchronized address updates with time delay
|
|
79
|
-
/// @param porposeAddress_AddressType Address format for Hyperlane and LayerZero protocols
|
|
80
|
-
/// @param porposeAddress_StringType String format for Axelar protocol compatibility
|
|
81
|
-
/// @param timeToAccept Timestamp when the address change proposal can be executed
|
|
82
|
-
struct ChangeExternalChainAddressParams {
|
|
83
|
-
address porposeAddress_AddressType;
|
|
84
|
-
string porposeAddress_StringType;
|
|
85
|
-
uint256 timeToAccept;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: EVVM-NONCOMMERCIAL-1.0
|
|
2
|
-
// Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
|
|
3
|
-
pragma solidity ^0.8.0;
|
|
4
|
-
|
|
5
|
-
import {SignatureUtil} from "@evvm/testnet-contracts/library/utils/SignatureUtil.sol";
|
|
6
|
-
import {AdvancedStrings} from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @title SignatureUtils
|
|
10
|
-
* @author Mate labs
|
|
11
|
-
* @notice Signature verification utilities for Treasury Cross-Chain Fisher Bridge operations
|
|
12
|
-
* @dev Specialized signature verification for Fisher Bridge transactions in the EVVM cross-chain treasury system
|
|
13
|
-
* Provides EIP-191 compliant signature verification with structured message format for enhanced security
|
|
14
|
-
*
|
|
15
|
-
* Key Features:
|
|
16
|
-
* - EIP-191 standard message signing format for wallet compatibility
|
|
17
|
-
* - Fisher Bridge specific message structure for transaction authenticity
|
|
18
|
-
* - Nonce-based replay attack prevention
|
|
19
|
-
* - EVVM ID integration for cross-instance security
|
|
20
|
-
* - Support for both ETH and ERC20 token bridge operations
|
|
21
|
-
*
|
|
22
|
-
* Security Model:
|
|
23
|
-
* - Structured message format: "{evvmID},fisherBridge,{parameters}"
|
|
24
|
-
* - Nonce validation prevents replay attacks across chains
|
|
25
|
-
* - EVVM ID ensures signatures are valid only for specific EVVM instances
|
|
26
|
-
* - Address and amount validation through signature verification
|
|
27
|
-
*/
|
|
28
|
-
library SignatureUtils {
|
|
29
|
-
/// @notice Verifies Fisher Bridge transaction signatures using EIP-191 standard
|
|
30
|
-
/// @dev Constructs and verifies structured message for Fisher Bridge cross-chain operations
|
|
31
|
-
/// Message format: "{evvmID},fisherBridge,{addressToReceive},{nonce},{tokenAddress},{priorityFee},{amount}"
|
|
32
|
-
/// This ensures each signature is unique and prevents cross-chain replay attacks
|
|
33
|
-
///
|
|
34
|
-
/// @param evvmID Unique identifier of the EVVM instance (prevents cross-instance replay)
|
|
35
|
-
/// @param signer Address that should have signed the message (transaction originator)
|
|
36
|
-
/// @param addressToReceive Destination address on the target chain for the bridged tokens
|
|
37
|
-
/// @param nonce Sequential nonce for the user to prevent replay attacks
|
|
38
|
-
/// @param tokenAddress Contract address of the token being bridged (address(0) for ETH)
|
|
39
|
-
/// @param priorityFee Fee amount paid to Fisher executor for priority processing
|
|
40
|
-
/// @param amount Total amount of tokens being bridged across chains
|
|
41
|
-
/// @param signature ECDSA signature (65 bytes) created by the signer using their private key
|
|
42
|
-
/// @return bool True if the signature is valid and matches the expected signer, false otherwise
|
|
43
|
-
///
|
|
44
|
-
/// @dev Security Features:
|
|
45
|
-
/// - EIP-191 compliance ensures wallet compatibility (MetaMask, WalletConnect, etc.)
|
|
46
|
-
/// - Structured message prevents parameter manipulation
|
|
47
|
-
/// - EVVM ID binding prevents cross-instance attacks
|
|
48
|
-
/// - Nonce inclusion prevents replay attacks
|
|
49
|
-
/// - All parameters are included in signature for integrity verification
|
|
50
|
-
function verifyMessageSignedForFisherBridge(
|
|
51
|
-
uint256 evvmID,
|
|
52
|
-
address signer,
|
|
53
|
-
address addressToReceive,
|
|
54
|
-
uint256 nonce,
|
|
55
|
-
address tokenAddress,
|
|
56
|
-
uint256 priorityFee,
|
|
57
|
-
uint256 amount,
|
|
58
|
-
bytes memory signature
|
|
59
|
-
) internal pure returns (bool) {
|
|
60
|
-
return
|
|
61
|
-
SignatureUtil.verifySignature(
|
|
62
|
-
evvmID,
|
|
63
|
-
"fisherBridge",
|
|
64
|
-
string.concat(
|
|
65
|
-
AdvancedStrings.addressToString(addressToReceive),
|
|
66
|
-
",",
|
|
67
|
-
AdvancedStrings.uintToString(nonce),
|
|
68
|
-
",",
|
|
69
|
-
AdvancedStrings.addressToString(tokenAddress),
|
|
70
|
-
",",
|
|
71
|
-
AdvancedStrings.uintToString(priorityFee),
|
|
72
|
-
",",
|
|
73
|
-
AdvancedStrings.uintToString(amount)
|
|
74
|
-
),
|
|
75
|
-
signature,
|
|
76
|
-
signer
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: EVVM-NONCOMMERCIAL-1.0
|
|
2
|
-
// Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
|
|
3
|
-
|
|
4
|
-
pragma solidity ^0.8.0;
|
|
5
|
-
|
|
6
|
-
library ProposalStructs {
|
|
7
|
-
/**
|
|
8
|
-
* @dev Struct for managing address change proposals with time delay
|
|
9
|
-
* @param current Currently active address
|
|
10
|
-
* @param proposal Proposed new address waiting for approval
|
|
11
|
-
* @param timeToAccept Timestamp when the proposal can be accepted
|
|
12
|
-
*/
|
|
13
|
-
struct AddressTypeProposal {
|
|
14
|
-
address current;
|
|
15
|
-
address proposal;
|
|
16
|
-
uint256 timeToAccept;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @dev Struct for managing uint256 value proposals with time delay
|
|
21
|
-
* @param current Currently active value
|
|
22
|
-
* @param proposal Proposed new value waiting for approval
|
|
23
|
-
* @param timeToAccept Timestamp when the proposal can be accepted
|
|
24
|
-
*/
|
|
25
|
-
struct UintTypeProposal {
|
|
26
|
-
uint256 current;
|
|
27
|
-
uint256 proposal;
|
|
28
|
-
uint256 timeToAccept;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @dev Struct for managing boolean flag changes with time delay
|
|
33
|
-
* @param flag Current boolean state
|
|
34
|
-
* @param timeToAcceptChange Timestamp when the flag change can be executed
|
|
35
|
-
*/
|
|
36
|
-
struct BoolTypeProposal {
|
|
37
|
-
bool flag;
|
|
38
|
-
uint256 timeToAcceptChange;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @title AdminControlled
|
|
44
|
-
* @notice Base contract for admin-controlled contracts with time-delayed governance
|
|
45
|
-
*/
|
|
46
|
-
abstract contract AdminControlled {
|
|
47
|
-
ProposalStructs.AddressTypeProposal public admin;
|
|
48
|
-
|
|
49
|
-
event AdminProposed(address indexed newAdmin, uint256 timeToAccept);
|
|
50
|
-
event AdminAccepted(address indexed newAdmin);
|
|
51
|
-
|
|
52
|
-
error SenderIsNotAdmin();
|
|
53
|
-
error ProposalNotReady();
|
|
54
|
-
|
|
55
|
-
modifier onlyAdmin() {
|
|
56
|
-
if (msg.sender != admin.current) revert SenderIsNotAdmin();
|
|
57
|
-
_;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* @notice Proposes a new admin with time delay
|
|
62
|
-
* @param newAdmin Address of proposed admin
|
|
63
|
-
* @param delay Time delay before proposal can be accepted
|
|
64
|
-
*/
|
|
65
|
-
function proposeAdmin(address newAdmin, uint256 delay) external onlyAdmin {
|
|
66
|
-
admin.proposal = newAdmin;
|
|
67
|
-
admin.timeToAccept = block.timestamp + delay;
|
|
68
|
-
emit AdminProposed(newAdmin, admin.timeToAccept);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* @notice Accepts the admin proposal after time delay
|
|
73
|
-
*/
|
|
74
|
-
function acceptAdminProposal() external onlyAdmin {
|
|
75
|
-
if (block.timestamp < admin.timeToAccept) revert ProposalNotReady();
|
|
76
|
-
admin.current = admin.proposal;
|
|
77
|
-
admin.proposal = address(0);
|
|
78
|
-
admin.timeToAccept = 0;
|
|
79
|
-
emit AdminAccepted(admin.current);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: EVVM-NONCOMMERCIAL-1.0
|
|
2
|
-
// Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
|
|
3
|
-
|
|
4
|
-
pragma solidity ^0.8.0;
|
|
5
|
-
/**
|
|
6
|
-
* @title AsyncNonce
|
|
7
|
-
* @author Mate Labs
|
|
8
|
-
* @notice Abstract contract for asynchronous nonce management in EVVM services
|
|
9
|
-
* @dev Provides replay protection using a bitmap-style nonce system where each nonce
|
|
10
|
-
* can be used only once, but nonces can be used in any order (non-sequential).
|
|
11
|
-
*
|
|
12
|
-
* Key Features:
|
|
13
|
-
* - Non-sequential nonce usage (any unused nonce is valid)
|
|
14
|
-
* - Gas-efficient O(1) lookup and marking
|
|
15
|
-
* - Suitable for parallel transaction submission
|
|
16
|
-
*
|
|
17
|
-
* Use Cases:
|
|
18
|
-
* - Services that allow users to submit multiple transactions simultaneously
|
|
19
|
-
* - Operations where transaction ordering is not critical
|
|
20
|
-
* - Batch operations where sequential nonces would be a bottleneck
|
|
21
|
-
*
|
|
22
|
-
* This contract is designed for use by community-developed services that need
|
|
23
|
-
* flexible replay protection without strict ordering requirements.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
abstract contract AsyncNonce {
|
|
27
|
-
/// @dev Thrown when attempting to use a nonce that has already been consumed
|
|
28
|
-
error AsyncNonceAlreadyUsed();
|
|
29
|
-
|
|
30
|
-
/// @dev Mapping to track used nonces: user address => nonce value => used flag
|
|
31
|
-
mapping(address user => mapping(uint256 nonce => bool availability))
|
|
32
|
-
private asyncNonce;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @notice Marks a nonce as used for a specific user
|
|
36
|
-
* @dev Should be called after successful operation validation to prevent replay
|
|
37
|
-
* @param user Address of the user whose nonce is being marked
|
|
38
|
-
* @param nonce The nonce value to mark as used
|
|
39
|
-
*/
|
|
40
|
-
function markAsyncNonceAsUsed(
|
|
41
|
-
address user,
|
|
42
|
-
uint256 nonce
|
|
43
|
-
) internal virtual {
|
|
44
|
-
asyncNonce[user][nonce] = true;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @notice Verifies that a nonce has not been used yet
|
|
49
|
-
* @dev Reverts with AsyncNonceAlreadyUsed if the nonce was previously consumed
|
|
50
|
-
* @param user Address of the user to check the nonce for
|
|
51
|
-
* @param nonce The nonce value to verify
|
|
52
|
-
* @custom:throws AsyncNonceAlreadyUsed If the nonce has already been used
|
|
53
|
-
*/
|
|
54
|
-
function verifyAsyncNonce(
|
|
55
|
-
address user,
|
|
56
|
-
uint256 nonce
|
|
57
|
-
) internal view virtual {
|
|
58
|
-
if (asyncNonce[user][nonce]) revert AsyncNonceAlreadyUsed();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* @notice Checks if a specific nonce has been used by a user
|
|
63
|
-
* @dev Public view function for external queries and UI integration
|
|
64
|
-
* @param user Address of the user to check
|
|
65
|
-
* @param nonce The nonce value to query
|
|
66
|
-
* @return True if the nonce has been used, false if available
|
|
67
|
-
*/
|
|
68
|
-
function getIfUsedAsyncNonce(
|
|
69
|
-
address user,
|
|
70
|
-
uint256 nonce
|
|
71
|
-
) public view virtual returns (bool) {
|
|
72
|
-
return asyncNonce[user][nonce];
|
|
73
|
-
}
|
|
74
|
-
}
|