@evvm/testnet-contracts 1.0.0
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 +166 -0
- package/README.md +216 -0
- package/package.json +51 -0
- package/src/contracts/evvm/Evvm.sol +1327 -0
- package/src/contracts/evvm/EvvmLegacy.sol +1553 -0
- package/src/contracts/evvm/lib/ErrorsLib.sol +17 -0
- package/src/contracts/evvm/lib/EvvmStorage.sol +60 -0
- package/src/contracts/evvm/lib/EvvmStructs.sol +64 -0
- package/src/contracts/evvm/lib/SignatureUtils.sol +124 -0
- package/src/contracts/nameService/NameService.sol +1751 -0
- package/src/contracts/nameService/lib/ErrorsLib.sol +27 -0
- package/src/contracts/nameService/lib/SignatureUtils.sol +239 -0
- package/src/contracts/staking/Estimator.sol +358 -0
- package/src/contracts/staking/Staking.sol +1148 -0
- package/src/contracts/staking/lib/ErrorsLib.sol +19 -0
- package/src/contracts/staking/lib/SignatureUtils.sol +68 -0
- package/src/contracts/treasury/Treasury.sol +104 -0
- package/src/contracts/treasury/lib/ErrorsLib.sol +11 -0
- package/src/contracts/treasuryTwoChains/TreasuryExternalChainStation.sol +551 -0
- package/src/contracts/treasuryTwoChains/TreasuryHostChainStation.sol +512 -0
- package/src/contracts/treasuryTwoChains/lib/ErrorsLib.sol +15 -0
- package/src/contracts/treasuryTwoChains/lib/ExternalChainStationStructs.sol +41 -0
- package/src/contracts/treasuryTwoChains/lib/HostChainStationStructs.sol +52 -0
- package/src/contracts/treasuryTwoChains/lib/SignatureUtils.sol +47 -0
- package/src/interfaces/IEstimator.sol +102 -0
- package/src/interfaces/IEvvm.sol +195 -0
- package/src/interfaces/INameService.sol +283 -0
- package/src/interfaces/IStaking.sol +202 -0
- package/src/interfaces/ITreasury.sol +17 -0
- package/src/interfaces/ITreasuryExternalChainStation.sol +262 -0
- package/src/interfaces/ITreasuryHostChainStation.sol +251 -0
- package/src/lib/AdvancedStrings.sol +77 -0
- package/src/lib/Erc191TestBuilder.sol +402 -0
- package/src/lib/SignatureRecover.sol +56 -0
|
@@ -0,0 +1,17 @@
|
|
|
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 ErrorsLib {
|
|
7
|
+
error InvalidSignature();
|
|
8
|
+
error SenderIsNotTheExecutor();
|
|
9
|
+
error UpdateBalanceFailed();
|
|
10
|
+
error InvalidAsyncNonce();
|
|
11
|
+
error NotAnStaker();
|
|
12
|
+
error InsufficientBalance();
|
|
13
|
+
error InvalidAmount(uint256, uint256);
|
|
14
|
+
error NotAnCA();
|
|
15
|
+
error SenderIsNotTreasury();
|
|
16
|
+
error WindowToChangeEvvmIDExpired();
|
|
17
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
import {EvvmStructs} from "./EvvmStructs.sol";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @title EvvmStorage
|
|
10
|
+
* @author jistro.eth
|
|
11
|
+
* @dev Storage layout contract for EVVM proxy pattern implementation.
|
|
12
|
+
* This contract inherits all structures from EvvmStructs and
|
|
13
|
+
* defines the storage layout that will be used by the proxy pattern.
|
|
14
|
+
*
|
|
15
|
+
* @notice This contract should not be deployed directly, it's meant to be
|
|
16
|
+
* inherited by the implementation contracts to ensure they maintain
|
|
17
|
+
* the same storage layout.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
abstract contract EvvmStorage is EvvmStructs {
|
|
21
|
+
address constant ETH_ADDRESS = address(0);
|
|
22
|
+
bytes1 constant FLAG_IS_STAKER = 0x01;
|
|
23
|
+
|
|
24
|
+
address nameServiceAddress;
|
|
25
|
+
|
|
26
|
+
address stakingContractAddress;
|
|
27
|
+
|
|
28
|
+
address treasuryAddress;
|
|
29
|
+
|
|
30
|
+
address whitelistTokenToBeAdded_address;
|
|
31
|
+
address whitelistTokenToBeAdded_pool;
|
|
32
|
+
uint256 whitelistTokenToBeAdded_dateToSet;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @dev The address of the implementation contract is stored
|
|
36
|
+
* separately because of the way the proxy pattern works,
|
|
37
|
+
* rather than in a struct.
|
|
38
|
+
*/
|
|
39
|
+
address currentImplementation;
|
|
40
|
+
address proposalImplementation;
|
|
41
|
+
uint256 timeToAcceptImplementation;
|
|
42
|
+
|
|
43
|
+
uint256 windowTimeToChangeEvvmID;
|
|
44
|
+
|
|
45
|
+
EvvmMetadata evvmMetadata;
|
|
46
|
+
|
|
47
|
+
AddressTypeProposal admin;
|
|
48
|
+
|
|
49
|
+
bytes1 breakerSetupNameServiceAddress;
|
|
50
|
+
|
|
51
|
+
mapping(address => bytes1) stakerList;
|
|
52
|
+
|
|
53
|
+
mapping(address user => mapping(address token => uint256 quantity)) balances;
|
|
54
|
+
|
|
55
|
+
mapping(address user => uint256 nonce) nextSyncUsedNonce;
|
|
56
|
+
|
|
57
|
+
mapping(address user => mapping(uint256 nonce => bool isUsed)) asyncUsedNonce;
|
|
58
|
+
|
|
59
|
+
mapping(address user => uint256 nonce) nextFisherDepositNonce;
|
|
60
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
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 EvvmStructs
|
|
8
|
+
* @dev Library of common structures used across EVVM and its services.
|
|
9
|
+
* This contract serves as a shared type system for the entire ecosystem,
|
|
10
|
+
* ensuring consistency in data structures between the core EVVM and
|
|
11
|
+
* external service contracts.
|
|
12
|
+
*
|
|
13
|
+
* @notice This contract should be inherited by both EVVM and service contracts
|
|
14
|
+
* that need to interact with these data structures.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
abstract contract EvvmStructs {
|
|
18
|
+
struct PayData {
|
|
19
|
+
address from;
|
|
20
|
+
address to_address;
|
|
21
|
+
string to_identity;
|
|
22
|
+
address token;
|
|
23
|
+
uint256 amount;
|
|
24
|
+
uint256 priorityFee;
|
|
25
|
+
uint256 nonce;
|
|
26
|
+
bool priorityFlag;
|
|
27
|
+
address executor;
|
|
28
|
+
bytes signature;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
struct DispersePayMetadata {
|
|
32
|
+
uint256 amount;
|
|
33
|
+
address to_address;
|
|
34
|
+
string to_identity;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
struct DisperseCaPayMetadata {
|
|
38
|
+
uint256 amount;
|
|
39
|
+
address toAddress;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
struct EvvmMetadata {
|
|
43
|
+
string EvvmName;
|
|
44
|
+
uint256 EvvmID;
|
|
45
|
+
string principalTokenName;
|
|
46
|
+
string principalTokenSymbol;
|
|
47
|
+
address principalTokenAddress;
|
|
48
|
+
uint256 totalSupply;
|
|
49
|
+
uint256 eraTokens;
|
|
50
|
+
uint256 reward;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
struct AddressTypeProposal {
|
|
54
|
+
address current;
|
|
55
|
+
address proposal;
|
|
56
|
+
uint256 timeToAccept;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
struct UintTypeProposal {
|
|
60
|
+
uint256 current;
|
|
61
|
+
uint256 proposal;
|
|
62
|
+
uint256 timeToAccept;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// SPDX-License-Identifier: EVVM-NONCOMMERCIAL-1.0
|
|
2
|
+
// Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
|
|
3
|
+
|
|
4
|
+
import {SignatureRecover} from "@evvm/testnet-contracts/lib/SignatureRecover.sol";
|
|
5
|
+
import {AdvancedStrings} from "@evvm/testnet-contracts/lib/AdvancedStrings.sol";
|
|
6
|
+
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
|
|
7
|
+
|
|
8
|
+
pragma solidity ^0.8.0;
|
|
9
|
+
|
|
10
|
+
library SignatureUtils {
|
|
11
|
+
/**
|
|
12
|
+
* @dev using EIP-191 (https://eips.ethereum.org/EIPS/eip-191) can be used to sign and
|
|
13
|
+
* verify messages, the next functions are used to verify the messages signed
|
|
14
|
+
* by the users
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @notice This function is used to verify the message signed for the payment
|
|
20
|
+
* @param signer user who signed the message
|
|
21
|
+
* @param _receiverAddress address of the receiver
|
|
22
|
+
* @param _receiverIdentity identity of the receiver
|
|
23
|
+
*
|
|
24
|
+
* @notice if the _receiverAddress is 0x0 the function will use the _receiverIdentity
|
|
25
|
+
*
|
|
26
|
+
* @param _token address of the token to send
|
|
27
|
+
* @param _amount amount to send
|
|
28
|
+
* @param _priorityFee priorityFee to send to the staking holder
|
|
29
|
+
* @param _nonce nonce of the transaction
|
|
30
|
+
* @param _priorityFlag if the transaction is priority or not
|
|
31
|
+
* @param _executor the executor of the transaction
|
|
32
|
+
* @param signature signature of the user who wants to send the message
|
|
33
|
+
* @return true if the signature is valid
|
|
34
|
+
*/
|
|
35
|
+
function verifyMessageSignedForPay(
|
|
36
|
+
uint256 evvmID,
|
|
37
|
+
address signer,
|
|
38
|
+
address _receiverAddress,
|
|
39
|
+
string memory _receiverIdentity,
|
|
40
|
+
address _token,
|
|
41
|
+
uint256 _amount,
|
|
42
|
+
uint256 _priorityFee,
|
|
43
|
+
uint256 _nonce,
|
|
44
|
+
bool _priorityFlag,
|
|
45
|
+
address _executor,
|
|
46
|
+
bytes memory signature
|
|
47
|
+
) internal pure returns (bool) {
|
|
48
|
+
return
|
|
49
|
+
SignatureRecover.signatureVerification(
|
|
50
|
+
Strings.toString(evvmID),
|
|
51
|
+
"pay",
|
|
52
|
+
string.concat(
|
|
53
|
+
_receiverAddress == address(0)
|
|
54
|
+
? _receiverIdentity
|
|
55
|
+
: AdvancedStrings.addressToString(_receiverAddress),
|
|
56
|
+
",",
|
|
57
|
+
AdvancedStrings.addressToString(_token),
|
|
58
|
+
",",
|
|
59
|
+
Strings.toString(_amount),
|
|
60
|
+
",",
|
|
61
|
+
Strings.toString(_priorityFee),
|
|
62
|
+
",",
|
|
63
|
+
Strings.toString(_nonce),
|
|
64
|
+
",",
|
|
65
|
+
_priorityFlag ? "true" : "false",
|
|
66
|
+
",",
|
|
67
|
+
AdvancedStrings.addressToString(_executor)
|
|
68
|
+
),
|
|
69
|
+
signature,
|
|
70
|
+
signer
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @notice This function is used to verify the message signed for the dispersePay
|
|
76
|
+
* @param signer user who signed the message
|
|
77
|
+
* @param hashList hash of the list of the transactions, the hash is calculated
|
|
78
|
+
* using sha256(abi.encode(toData))
|
|
79
|
+
* @param _token token address to send
|
|
80
|
+
* @param _amount amount to send
|
|
81
|
+
* @param _priorityFee priorityFee to send to the fisher who wants to send the message
|
|
82
|
+
* @param _nonce nonce of the transaction
|
|
83
|
+
* @param _priorityFlag if the transaction is priority or not
|
|
84
|
+
* @param _executor the executor of the transaction
|
|
85
|
+
* @param signature signature of the user who wants to send the message
|
|
86
|
+
* @return true if the signature is valid
|
|
87
|
+
*/
|
|
88
|
+
function verifyMessageSignedForDispersePay(
|
|
89
|
+
uint256 evvmID,
|
|
90
|
+
address signer,
|
|
91
|
+
bytes32 hashList,
|
|
92
|
+
address _token,
|
|
93
|
+
uint256 _amount,
|
|
94
|
+
uint256 _priorityFee,
|
|
95
|
+
uint256 _nonce,
|
|
96
|
+
bool _priorityFlag,
|
|
97
|
+
address _executor,
|
|
98
|
+
bytes memory signature
|
|
99
|
+
) internal pure returns (bool) {
|
|
100
|
+
return
|
|
101
|
+
SignatureRecover.signatureVerification(
|
|
102
|
+
Strings.toString(evvmID),
|
|
103
|
+
"dispersePay",
|
|
104
|
+
string.concat(
|
|
105
|
+
AdvancedStrings.bytes32ToString(hashList),
|
|
106
|
+
",",
|
|
107
|
+
AdvancedStrings.addressToString(_token),
|
|
108
|
+
",",
|
|
109
|
+
Strings.toString(_amount),
|
|
110
|
+
",",
|
|
111
|
+
Strings.toString(_priorityFee),
|
|
112
|
+
",",
|
|
113
|
+
Strings.toString(_nonce),
|
|
114
|
+
",",
|
|
115
|
+
_priorityFlag ? "true" : "false",
|
|
116
|
+
",",
|
|
117
|
+
AdvancedStrings.addressToString(_executor)
|
|
118
|
+
),
|
|
119
|
+
signature,
|
|
120
|
+
signer
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
}
|