@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
|
@@ -0,0 +1,49 @@
|
|
|
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 Proposal Data Structures
|
|
8
|
+
* @author Mate labs
|
|
9
|
+
* @notice Time-delayed governance proposal structures for safe parameter changes
|
|
10
|
+
* @dev Three proposal types: AddressTypeProposal, UintTypeProposal, BoolTypeProposal. Standard delay: 1 day (86400s).
|
|
11
|
+
*/
|
|
12
|
+
library ProposalStructs {
|
|
13
|
+
/**
|
|
14
|
+
* @notice Time-delayed address change proposal
|
|
15
|
+
* @dev Used for admin, executor, and contract address updates
|
|
16
|
+
* @param current Currently active address
|
|
17
|
+
* @param proposal Proposed new address
|
|
18
|
+
* @param timeToAccept Timestamp when proposal becomes acceptable
|
|
19
|
+
*/
|
|
20
|
+
struct AddressTypeProposal {
|
|
21
|
+
address current;
|
|
22
|
+
address proposal;
|
|
23
|
+
uint256 timeToAccept;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @notice Time-delayed numeric value proposal
|
|
28
|
+
* @dev Used for fees, limits, rates, and thresholds
|
|
29
|
+
* @param current Currently active value
|
|
30
|
+
* @param proposal Proposed new value
|
|
31
|
+
* @param timeToAccept Timestamp when proposal becomes acceptable
|
|
32
|
+
*/
|
|
33
|
+
struct UintTypeProposal {
|
|
34
|
+
uint256 current;
|
|
35
|
+
uint256 proposal;
|
|
36
|
+
uint256 timeToAccept;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @notice Time-delayed boolean flag proposal
|
|
41
|
+
* @dev Used for pause/unpause, enable/disable features. Not suitable for instant emergency stops.
|
|
42
|
+
* @param flag Current boolean state
|
|
43
|
+
* @param timeToAccept Timestamp when toggle allowed
|
|
44
|
+
*/
|
|
45
|
+
struct BoolTypeProposal {
|
|
46
|
+
bool flag;
|
|
47
|
+
uint256 timeToAccept;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
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 EVVM Payment Integration for Services
|
|
7
|
+
* @author Mate labs
|
|
8
|
+
* @notice Abstract contract providing Core.sol payment processing interface
|
|
9
|
+
* @dev Four payment types: requestPay (user-to-service with signature), requestDispersePay (batch user-to-service), makeCaPay (contract-authorized service-to-user), makeDisperseCaPay (batch CA).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import {ICore, CoreStructs} from "@evvm/testnet-contracts/interfaces/ICore.sol";
|
|
13
|
+
|
|
14
|
+
abstract contract CoreExecution {
|
|
15
|
+
/// @notice EVVM core contract reference
|
|
16
|
+
/// @dev Used for all payment operations
|
|
17
|
+
ICore internal core;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @notice Initializes EVVM payment integration
|
|
21
|
+
* @param _coreAddress Address of Core.sol contract
|
|
22
|
+
*/
|
|
23
|
+
constructor(address _coreAddress) {
|
|
24
|
+
core = ICore(_coreAddress);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @notice Requests payment from user to service via Evvm.pay with signature validation
|
|
29
|
+
* @dev Calls core.pay(from, address(this), "", ...). Signature validated by State.validateAndConsumeNonce.
|
|
30
|
+
* @param from User paying (signer)
|
|
31
|
+
* @param token Token address
|
|
32
|
+
* @param amount Token amount
|
|
33
|
+
* @param priorityFee Executor fee
|
|
34
|
+
* @param nonce Sequential or async nonce
|
|
35
|
+
* @param isAsyncExec Nonce type (true=async, false=sync)
|
|
36
|
+
* @param signature User's ECDSA signature
|
|
37
|
+
*/
|
|
38
|
+
function requestPay(
|
|
39
|
+
address from,
|
|
40
|
+
address token,
|
|
41
|
+
uint256 amount,
|
|
42
|
+
uint256 priorityFee,
|
|
43
|
+
uint256 nonce,
|
|
44
|
+
bool isAsyncExec,
|
|
45
|
+
bytes memory signature
|
|
46
|
+
) internal virtual {
|
|
47
|
+
core.pay(
|
|
48
|
+
from,
|
|
49
|
+
address(this),
|
|
50
|
+
"",
|
|
51
|
+
token,
|
|
52
|
+
amount,
|
|
53
|
+
priorityFee,
|
|
54
|
+
address(this),
|
|
55
|
+
nonce,
|
|
56
|
+
isAsyncExec,
|
|
57
|
+
signature
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @notice Requests batch payment from user via Evvm.dispersePay
|
|
63
|
+
* @dev Signature validated by Core.sol. Total amount must match sum of toData amounts.
|
|
64
|
+
* @param toData Array of (recipient, amount) pairs
|
|
65
|
+
* @param token Token address
|
|
66
|
+
* @param amount Total amount (must match sum)
|
|
67
|
+
* @param priorityFee Executor fee
|
|
68
|
+
* @param nonce Sequential or async nonce
|
|
69
|
+
* @param isAsyncExec Nonce type (true=async, false=sync)
|
|
70
|
+
* @param signature User's ECDSA signature
|
|
71
|
+
*/
|
|
72
|
+
function requestDispersePay(
|
|
73
|
+
CoreStructs.DispersePayMetadata[] memory toData,
|
|
74
|
+
address token,
|
|
75
|
+
uint256 amount,
|
|
76
|
+
uint256 priorityFee,
|
|
77
|
+
uint256 nonce,
|
|
78
|
+
bool isAsyncExec,
|
|
79
|
+
bytes memory signature
|
|
80
|
+
) internal virtual {
|
|
81
|
+
core.dispersePay(
|
|
82
|
+
address(this),
|
|
83
|
+
toData,
|
|
84
|
+
token,
|
|
85
|
+
amount,
|
|
86
|
+
priorityFee,
|
|
87
|
+
address(this),
|
|
88
|
+
nonce,
|
|
89
|
+
isAsyncExec,
|
|
90
|
+
signature
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @notice Sends tokens from service to recipient via contract authorization (no signature)
|
|
96
|
+
* @dev Calls core.caPay(to, token, amount). Service must have sufficient Evvm balance.
|
|
97
|
+
* @param to Recipient address
|
|
98
|
+
* @param token Token address
|
|
99
|
+
* @param amount Token amount
|
|
100
|
+
*/
|
|
101
|
+
function makeCaPay(
|
|
102
|
+
address to,
|
|
103
|
+
address token,
|
|
104
|
+
uint256 amount
|
|
105
|
+
) internal virtual {
|
|
106
|
+
core.caPay(to, token, amount);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @notice Sends tokens to multiple recipients via contract authorization (batch)
|
|
111
|
+
* @dev Calls evvm.disperseCaPay. Total amount must match sum of toData amounts.
|
|
112
|
+
* @param toData Array of (recipient, amount) pairs
|
|
113
|
+
* @param token Token address
|
|
114
|
+
* @param amount Total amount (must match sum)
|
|
115
|
+
*/
|
|
116
|
+
function makeDisperseCaPay(
|
|
117
|
+
CoreStructs.DisperseCaPayMetadata[] memory toData,
|
|
118
|
+
address token,
|
|
119
|
+
uint256 amount
|
|
120
|
+
) internal virtual {
|
|
121
|
+
core.disperseCaPay(toData, token, amount);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* @notice Gets next sequential sync nonce for user
|
|
126
|
+
* @dev View function returning core.getNextCurrentSyncNonce(user). Auto-increments after each use.
|
|
127
|
+
* @param user User address to query
|
|
128
|
+
* @return Next sync nonce for user
|
|
129
|
+
*/
|
|
130
|
+
function getNextCurrentSyncNonce(
|
|
131
|
+
address user
|
|
132
|
+
) external view returns (uint256) {
|
|
133
|
+
return core.getNextCurrentSyncNonce(user);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @notice Checks if async nonce was consumed
|
|
138
|
+
* @dev View function returning core.getIfUsedAsyncNonce(user, nonce). Reserved nonces return false until consumed.
|
|
139
|
+
* @param user User address to query
|
|
140
|
+
* @param nonce Async nonce to check
|
|
141
|
+
* @return true if consumed, false if available/reserved
|
|
142
|
+
*/
|
|
143
|
+
function getIfUsedAsyncNonce(
|
|
144
|
+
address user,
|
|
145
|
+
uint256 nonce
|
|
146
|
+
) external view returns (bool) {
|
|
147
|
+
return core.getIfUsedAsyncNonce(user, nonce);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* @notice Updates Core.sol contract address for governance-controlled upgrades
|
|
152
|
+
* @dev Should be protected with onlyAdmin and time-delay (ProposalStructs pattern recommended).
|
|
153
|
+
* @param newCoreAddress New Core.sol contract address
|
|
154
|
+
*/
|
|
155
|
+
function _changeCoreAddress(address newCoreAddress) internal virtual {
|
|
156
|
+
core = ICore(newCoreAddress);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -2,73 +2,56 @@
|
|
|
2
2
|
// Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
|
|
3
3
|
pragma solidity ^0.8.0;
|
|
4
4
|
/**
|
|
5
|
-
* @title
|
|
6
|
-
* @author Mate
|
|
7
|
-
* @notice Abstract contract
|
|
8
|
-
* @dev
|
|
9
|
-
* interact with the EVVM Staking contract. Services can stake tokens to:
|
|
10
|
-
*
|
|
11
|
-
* Benefits of Service Staking:
|
|
12
|
-
* - Earn rewards from Fisher (executor) transaction fees
|
|
13
|
-
* - Participate in the EVVM staking ecosystem
|
|
14
|
-
* - Increase service credibility and commitment
|
|
15
|
-
*
|
|
16
|
-
* Staking Flow:
|
|
17
|
-
* 1. Call _makeStakeService with desired amount
|
|
18
|
-
* 2. Contract prepares staking, transfers tokens, and confirms
|
|
19
|
-
* 3. Call _makeUnstakeService when ready to withdraw
|
|
20
|
-
*
|
|
21
|
-
* This contract is designed for use by community-developed services that want
|
|
22
|
-
* to participate in the EVVM staking mechanism.
|
|
5
|
+
* @title Staking Utilities for EVVM Services
|
|
6
|
+
* @author Mate labs
|
|
7
|
+
* @notice Abstract contract for Staking.sol integration enabling services to stake and earn Fisher fees
|
|
8
|
+
* @dev Three-step staking: prepareServiceStaking → core.caPay(5083 PT * amount) → confirmServiceStaking. Cost: 5083 PT per staking token.
|
|
23
9
|
*/
|
|
24
10
|
|
|
25
11
|
import {IStaking} from "@evvm/testnet-contracts/interfaces/IStaking.sol";
|
|
26
|
-
import {
|
|
12
|
+
import {ICore} from "@evvm/testnet-contracts/interfaces/ICore.sol";
|
|
27
13
|
|
|
28
14
|
abstract contract StakingServiceUtils {
|
|
29
|
-
/// @
|
|
15
|
+
/// @notice Staking contract reference
|
|
16
|
+
/// @dev Used for all staking operations
|
|
30
17
|
IStaking internal staking;
|
|
31
18
|
|
|
32
19
|
/**
|
|
33
|
-
* @notice Initializes
|
|
34
|
-
* @param stakingAddress Address of
|
|
20
|
+
* @notice Initializes staking integration
|
|
21
|
+
* @param stakingAddress Address of Staking.sol
|
|
35
22
|
*/
|
|
36
23
|
constructor(address stakingAddress) {
|
|
37
24
|
staking = IStaking(stakingAddress);
|
|
38
25
|
}
|
|
39
26
|
|
|
40
27
|
/**
|
|
41
|
-
* @notice Stakes tokens
|
|
42
|
-
* @dev
|
|
43
|
-
*
|
|
44
|
-
* 2. Transfers the required Principal Tokens via EVVM caPay
|
|
45
|
-
* 3. Confirms the staking operation
|
|
46
|
-
* @param amountToStake Number of staking units to purchase
|
|
28
|
+
* @notice Stakes tokens for this service via 3-step atomic process
|
|
29
|
+
* @dev Calls prepareServiceStaking → core.caPay(PT, cost) → confirmServiceStaking. Requires 5083 PT * amountToStake in service Evvm balance.
|
|
30
|
+
* @param amountToStake Number of staking tokens to purchase
|
|
47
31
|
*/
|
|
48
32
|
function _makeStakeService(uint256 amountToStake) internal {
|
|
49
33
|
staking.prepareServiceStaking(amountToStake);
|
|
50
|
-
|
|
34
|
+
ICore(staking.getCoreAddress()).caPay(
|
|
51
35
|
address(staking),
|
|
52
|
-
|
|
36
|
+
ICore(staking.getCoreAddress()).getPrincipalTokenAddress(),
|
|
53
37
|
staking.priceOfStaking() * amountToStake
|
|
54
38
|
);
|
|
55
39
|
staking.confirmServiceStaking();
|
|
56
40
|
}
|
|
57
41
|
|
|
58
42
|
/**
|
|
59
|
-
* @notice Unstakes tokens from this service
|
|
60
|
-
* @dev Calls
|
|
61
|
-
* @param amountToUnstake Number of staking
|
|
43
|
+
* @notice Unstakes tokens from this service, burning them and refunding 5083 PT per token
|
|
44
|
+
* @dev Calls staking.serviceUnstaking(amount). PT refunded to service Evvm balance.
|
|
45
|
+
* @param amountToUnstake Number of staking tokens to release
|
|
62
46
|
*/
|
|
63
47
|
function _makeUnstakeService(uint256 amountToUnstake) internal {
|
|
64
48
|
staking.serviceUnstaking(amountToUnstake);
|
|
65
49
|
}
|
|
66
50
|
|
|
67
51
|
/**
|
|
68
|
-
* @notice Updates
|
|
69
|
-
* @dev
|
|
70
|
-
*
|
|
71
|
-
* @param newStakingAddress Address of the new Staking contract
|
|
52
|
+
* @notice Updates Staking.sol contract address for governance-controlled upgrades
|
|
53
|
+
* @dev Should be protected with onlyAdmin and time-delay. Existing stakes remain in old contract.
|
|
54
|
+
* @param newStakingAddress New Staking.sol contract address
|
|
72
55
|
*/
|
|
73
56
|
function _changeStakingAddress(address newStakingAddress) internal virtual {
|
|
74
57
|
staking = IStaking(newStakingAddress);
|
|
@@ -0,0 +1,73 @@
|
|
|
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 {
|
|
6
|
+
CoreStructs
|
|
7
|
+
} from "@evvm/testnet-contracts/library/structs/CoreStructs.sol";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @title EVVM Core Hash Utilities
|
|
11
|
+
* @author Mate labs
|
|
12
|
+
* @notice Generates deterministic hashes for Core contract payment operations.
|
|
13
|
+
* @dev Reconstructs data payloads for EIP-191 signature verification within the EVVM ecosystem.
|
|
14
|
+
*/
|
|
15
|
+
library CoreHashUtils {
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @notice Generates hash for single payment operation
|
|
19
|
+
* @dev Hash: keccak256("pay", to_address, to_identity, token, amount, priorityFee, executor)
|
|
20
|
+
* @param to_address Direct recipient address
|
|
21
|
+
* @param to_identity Username for NameService resolution
|
|
22
|
+
* @param token Token address
|
|
23
|
+
* @param amount Token amount
|
|
24
|
+
* @param priorityFee Fee for executor
|
|
25
|
+
* @return Hash for Core.sol validation
|
|
26
|
+
*/
|
|
27
|
+
function hashDataForPay(
|
|
28
|
+
address to_address,
|
|
29
|
+
string memory to_identity,
|
|
30
|
+
address token,
|
|
31
|
+
uint256 amount,
|
|
32
|
+
uint256 priorityFee
|
|
33
|
+
) public pure returns (bytes32) {
|
|
34
|
+
return
|
|
35
|
+
keccak256(
|
|
36
|
+
abi.encode(
|
|
37
|
+
"pay",
|
|
38
|
+
to_address,
|
|
39
|
+
to_identity,
|
|
40
|
+
token,
|
|
41
|
+
amount,
|
|
42
|
+
priorityFee
|
|
43
|
+
)
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @notice Generates hash for batch payment operation
|
|
49
|
+
* @dev Hash: keccak256("dispersePay", toData, token, amount, priorityFee, executor). Single nonce for entire batch.
|
|
50
|
+
* @param toData Array of recipients and amounts
|
|
51
|
+
* @param token Token address
|
|
52
|
+
* @param amount Total amount (must equal sum)
|
|
53
|
+
* @param priorityFee Fee for executor
|
|
54
|
+
* @return Hash for Core.sol validation
|
|
55
|
+
*/
|
|
56
|
+
function hashDataForDispersePay(
|
|
57
|
+
CoreStructs.DispersePayMetadata[] memory toData,
|
|
58
|
+
address token,
|
|
59
|
+
uint256 amount,
|
|
60
|
+
uint256 priorityFee
|
|
61
|
+
) internal pure returns (bytes32) {
|
|
62
|
+
return
|
|
63
|
+
keccak256(
|
|
64
|
+
abi.encode(
|
|
65
|
+
"dispersePay",
|
|
66
|
+
toData,
|
|
67
|
+
token,
|
|
68
|
+
amount,
|
|
69
|
+
priorityFee
|
|
70
|
+
)
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
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 {
|
|
6
|
+
SignatureUtil
|
|
7
|
+
} from "@evvm/testnet-contracts/library/utils/SignatureUtil.sol";
|
|
8
|
+
import {
|
|
9
|
+
AdvancedStrings
|
|
10
|
+
} from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @title NameServiceHashUtils
|
|
14
|
+
* @author Mate labs
|
|
15
|
+
* @notice Hash generation for NameService.sol operations (registration, marketplace, metadata)
|
|
16
|
+
* @dev Deterministic keccak256 hashes for 10 NameService operations. Used with Core.validateAndConsumeNonce.
|
|
17
|
+
*/
|
|
18
|
+
library NameServiceHashUtils {
|
|
19
|
+
/**
|
|
20
|
+
* @notice Generates hash for username pre-registration (commit phase)
|
|
21
|
+
* @dev Hash: keccak256("preRegistrationUsername", hashUsername). Prevents front-running, valid 30 minutes.
|
|
22
|
+
* @param hashUsername Keccak256 of (username + lockNumber)
|
|
23
|
+
* @return Hash for Core.sol validation
|
|
24
|
+
*/
|
|
25
|
+
function hashDataForPreRegistrationUsername(
|
|
26
|
+
bytes32 hashUsername
|
|
27
|
+
) internal pure returns (bytes32) {
|
|
28
|
+
return keccak256(abi.encode("preRegistrationUsername", hashUsername));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @notice Generates hash for username registration (reveal phase)
|
|
33
|
+
* @dev Hash: keccak256("registrationUsername", username, lockNumber). Must match pre-reg within 30 minutes. Cost: 100x EVVM reward.
|
|
34
|
+
* @param username Username being registered
|
|
35
|
+
* @param lockNumber Random number from pre-registration
|
|
36
|
+
* @return Hash for Core.sol validation
|
|
37
|
+
*/
|
|
38
|
+
function hashDataForRegistrationUsername(
|
|
39
|
+
string memory username,
|
|
40
|
+
uint256 lockNumber
|
|
41
|
+
) internal pure returns (bytes32) {
|
|
42
|
+
return
|
|
43
|
+
keccak256(abi.encode("registrationUsername", username, lockNumber));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @notice Generates hash for creating marketplace offer
|
|
48
|
+
* @dev Hash: keccak256("makeOffer", username, amount, expirationDate). Locks PT with 0.5% fee.
|
|
49
|
+
* @param username Target username
|
|
50
|
+
* @param amount Principal Tokens offered (pre-fee)
|
|
51
|
+
* @param expirationDate Offer expiration timestamp
|
|
52
|
+
* @return Hash for Core.sol validation
|
|
53
|
+
*/
|
|
54
|
+
function hashDataForMakeOffer(
|
|
55
|
+
string memory username,
|
|
56
|
+
uint256 amount,
|
|
57
|
+
uint256 expirationDate
|
|
58
|
+
) internal pure returns (bytes32) {
|
|
59
|
+
return
|
|
60
|
+
keccak256(
|
|
61
|
+
abi.encode("makeOffer", username, amount, expirationDate)
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @notice Generates hash for withdrawing marketplace offer
|
|
67
|
+
* @dev Hash: keccak256("withdrawOffer", username, offerId). Only offer creator can withdraw.
|
|
68
|
+
* @param username Username with the offer
|
|
69
|
+
* @param offerId Offer ID to withdraw
|
|
70
|
+
* @return Hash for Core.sol validation
|
|
71
|
+
*/
|
|
72
|
+
function hashDataForWithdrawOffer(
|
|
73
|
+
string memory username,
|
|
74
|
+
uint256 offerId
|
|
75
|
+
) internal pure returns (bytes32) {
|
|
76
|
+
return keccak256(abi.encode("withdrawOffer", username, offerId));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @notice Generates hash for accepting marketplace offer
|
|
81
|
+
* @dev Hash: keccak256("acceptOffer", username, offerId). Transfers ownership to offerer.
|
|
82
|
+
* @param username Username being sold
|
|
83
|
+
* @param offerId Offer ID to accept
|
|
84
|
+
* @return Hash for Core.sol validation
|
|
85
|
+
*/
|
|
86
|
+
function hashDataForAcceptOffer(
|
|
87
|
+
string memory username,
|
|
88
|
+
uint256 offerId
|
|
89
|
+
) internal pure returns (bytes32) {
|
|
90
|
+
return keccak256(abi.encode("acceptOffer", username, offerId));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @notice Generates hash for renewing username
|
|
95
|
+
* @dev Hash: keccak256("renewUsername", username). Can renew up to 100 years in advance.
|
|
96
|
+
* @param username Username to renew
|
|
97
|
+
* @return Hash for Core.sol validation
|
|
98
|
+
*/
|
|
99
|
+
function hashDataForRenewUsername(
|
|
100
|
+
string memory username
|
|
101
|
+
) internal pure returns (bytes32) {
|
|
102
|
+
return keccak256(abi.encode("renewUsername", username));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @notice Generates hash for adding custom metadata
|
|
107
|
+
* @dev Hash: keccak256("addCustomMetadata", identity, value). Cost: 10x EVVM reward.
|
|
108
|
+
* @param identity Username or identity
|
|
109
|
+
* @param value Metadata value to store
|
|
110
|
+
* @return Hash for Core.sol validation
|
|
111
|
+
*/
|
|
112
|
+
function hashDataForAddCustomMetadata(
|
|
113
|
+
string memory identity,
|
|
114
|
+
string memory value
|
|
115
|
+
) internal pure returns (bytes32) {
|
|
116
|
+
return keccak256(abi.encode("addCustomMetadata", identity, value));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @notice Generates hash for removing custom metadata
|
|
121
|
+
* @dev Hash: keccak256("removeCustomMetadata", identity, key). Cost: 10x EVVM reward.
|
|
122
|
+
* @param identity Username or identity
|
|
123
|
+
* @param key Metadata entry key to remove
|
|
124
|
+
* @return Hash for Core.sol validation
|
|
125
|
+
*/
|
|
126
|
+
function hashDataForRemoveCustomMetadata(
|
|
127
|
+
string memory identity,
|
|
128
|
+
uint256 key
|
|
129
|
+
) internal pure returns (bytes32) {
|
|
130
|
+
return keccak256(abi.encode("removeCustomMetadata", identity, key));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @notice Generates hash for flushing all metadata
|
|
135
|
+
* @dev Hash: keccak256("flushCustomMetadata", identity). Removes ALL custom metadata entries.
|
|
136
|
+
* @param identity Username or identity to flush
|
|
137
|
+
* @return Hash for Core.sol validation
|
|
138
|
+
*/
|
|
139
|
+
function hashDataForFlushCustomMetadata(
|
|
140
|
+
string memory identity
|
|
141
|
+
) internal pure returns (bytes32) {
|
|
142
|
+
return keccak256(abi.encode("flushCustomMetadata", identity));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @notice Generates hash for flushing username (complete deletion)
|
|
147
|
+
* @dev Hash: keccak256("flushUsername", username). Irreversible. Deletes all data and makes username available.
|
|
148
|
+
* @param username Username to delete
|
|
149
|
+
* @return Hash for Core.sol validation
|
|
150
|
+
*/
|
|
151
|
+
function hashDataForFlushUsername(
|
|
152
|
+
string memory username
|
|
153
|
+
) internal pure returns (bytes32) {
|
|
154
|
+
return keccak256(abi.encode("flushUsername", username));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
/**
|
|
6
|
+
* @title P2P Swap Hash Utilities Library
|
|
7
|
+
* @author Mate labs
|
|
8
|
+
* @notice Hash generation for P2PSwap.sol operations (makeOrder, cancelOrder, dispatchOrder)
|
|
9
|
+
* @dev All hashes validated via Core.sol with async nonces. Three operation types supported.
|
|
10
|
+
*/
|
|
11
|
+
library P2PSwapHashUtils {
|
|
12
|
+
/**
|
|
13
|
+
* @notice Generates hash for makeOrder operation
|
|
14
|
+
* @dev Hash: keccak256("makeOrder", tokenA, tokenB, amountA, amountB). Uses async nonce.
|
|
15
|
+
* @param tokenA Token offered by seller
|
|
16
|
+
* @param tokenB Token requested by seller
|
|
17
|
+
* @param amountA Amount of tokenA offered
|
|
18
|
+
* @param amountB Amount of tokenB requested
|
|
19
|
+
* @return Hash for Core.sol validation
|
|
20
|
+
*/
|
|
21
|
+
function hashDataForMakeOrder(
|
|
22
|
+
address tokenA,
|
|
23
|
+
address tokenB,
|
|
24
|
+
uint256 amountA,
|
|
25
|
+
uint256 amountB
|
|
26
|
+
) internal pure returns (bytes32) {
|
|
27
|
+
return
|
|
28
|
+
keccak256(
|
|
29
|
+
abi.encode("makeOrder", tokenA, tokenB, amountA, amountB)
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @notice Generates hash for cancelOrder operation
|
|
35
|
+
* @dev Hash: keccak256("cancelOrder", tokenA, tokenB, orderId). Only order owner can cancel.
|
|
36
|
+
* @param tokenA Token A in market pair
|
|
37
|
+
* @param tokenB Token B in market pair
|
|
38
|
+
* @param orderId Order ID to cancel
|
|
39
|
+
* @return Hash for Core.sol validation
|
|
40
|
+
*/
|
|
41
|
+
function hashDataForCancelOrder(
|
|
42
|
+
address tokenA,
|
|
43
|
+
address tokenB,
|
|
44
|
+
uint256 orderId
|
|
45
|
+
) internal pure returns (bytes32) {
|
|
46
|
+
return keccak256(abi.encode("cancelOrder", tokenA, tokenB, orderId));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @notice Generates hash for dispatchOrder operation
|
|
51
|
+
* @dev Hash: keccak256("dispatchOrder", tokenA, tokenB, orderId). Used by both fillProportionalFee and fillFixedFee.
|
|
52
|
+
* @param tokenA Token A in market pair
|
|
53
|
+
* @param tokenB Token B in market pair
|
|
54
|
+
* @param orderId Order ID to dispatch
|
|
55
|
+
* @return Hash for Core.sol validation
|
|
56
|
+
*/
|
|
57
|
+
function hashDataForDispatchOrder(
|
|
58
|
+
address tokenA,
|
|
59
|
+
address tokenB,
|
|
60
|
+
uint256 orderId
|
|
61
|
+
) internal pure returns (bytes32) {
|
|
62
|
+
return
|
|
63
|
+
keccak256(abi.encode("dispatchOrder", tokenA, tokenB, orderId));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
/**
|
|
6
|
+
* @title Staking Hash Utilities
|
|
7
|
+
* @author Mate labs
|
|
8
|
+
* @notice Hash functions for staking signature validation (presale/public)
|
|
9
|
+
* @dev Generates unique hashes with operation-specific prefixes. Used with Core.sol async nonces. Cost: 5083 PT per token.
|
|
10
|
+
*/
|
|
11
|
+
library StakingHashUtils {
|
|
12
|
+
/**
|
|
13
|
+
* @notice Hashes presale staking operation parameters for signature validation
|
|
14
|
+
* @dev Hash: keccak256("presaleStaking", isStaking, amountOfStaking). Used with Core.sol async nonces. Max 2 tokens per user.
|
|
15
|
+
* @param isStaking true=stake, false=unstake
|
|
16
|
+
* @param amountOfStaking Number of staking tokens
|
|
17
|
+
* @return Hash for signature validation
|
|
18
|
+
*/
|
|
19
|
+
function hashDataForPresaleStake(
|
|
20
|
+
bool isStaking,
|
|
21
|
+
uint256 amountOfStaking
|
|
22
|
+
) internal pure returns (bytes32) {
|
|
23
|
+
return
|
|
24
|
+
keccak256(abi.encode("presaleStaking", isStaking, amountOfStaking));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @notice Hashes public staking operation parameters for signature validation
|
|
29
|
+
* @dev Hash: keccak256("publicStaking", isStaking, amountOfStaking). Used with Core.sol async nonces. Unlimited tokens per user.
|
|
30
|
+
* @param isStaking true=stake, false=unstake
|
|
31
|
+
* @param amountOfStaking Number of staking tokens
|
|
32
|
+
* @return Hash for signature validation
|
|
33
|
+
*/
|
|
34
|
+
function hashDataForPublicStake(
|
|
35
|
+
bool isStaking,
|
|
36
|
+
uint256 amountOfStaking
|
|
37
|
+
) internal pure returns (bytes32) {
|
|
38
|
+
return
|
|
39
|
+
keccak256(abi.encode("publicStaking", isStaking, amountOfStaking));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
/**
|
|
6
|
+
* @title Cross-Chain Treasury Hash Utilities
|
|
7
|
+
* @author Mate labs
|
|
8
|
+
* @notice Hash generation for Fisher bridge operations (independent from EVVM)
|
|
9
|
+
* @dev EIP-191 hashes for cross-chain bridge. Uses own nonce system (NOT Core.sol). Signature validation via SignatureRecover.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
library TreasuryCrossChainHashUtils {
|
|
13
|
+
/**
|
|
14
|
+
* @notice Generates hash for Fisher bridge operation
|
|
15
|
+
* @dev Hash: keccak256("fisherBridge", addressToReceive, tokenAddress, amount, priorityFee). Independent nonce system (NOT Core.sol).
|
|
16
|
+
* @param addressToReceive Recipient on destination chain
|
|
17
|
+
* @param tokenAddress Token to bridge (address(0) = ETH)
|
|
18
|
+
* @param priorityFee Fee for Fisher executor
|
|
19
|
+
* @param amount Token amount to bridge
|
|
20
|
+
* @return Hash for ECDSA signature validation
|
|
21
|
+
*/
|
|
22
|
+
function hashDataForFisherBridge(
|
|
23
|
+
address addressToReceive,
|
|
24
|
+
address tokenAddress,
|
|
25
|
+
uint256 priorityFee,
|
|
26
|
+
uint256 amount
|
|
27
|
+
) public pure returns (bytes32) {
|
|
28
|
+
return
|
|
29
|
+
keccak256(
|
|
30
|
+
abi.encode(
|
|
31
|
+
"fisherBridge",
|
|
32
|
+
addressToReceive,
|
|
33
|
+
tokenAddress,
|
|
34
|
+
amount,
|
|
35
|
+
priorityFee
|
|
36
|
+
)
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
}
|