@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.
Files changed (34) hide show
  1. package/LICENSE +166 -0
  2. package/README.md +216 -0
  3. package/package.json +51 -0
  4. package/src/contracts/evvm/Evvm.sol +1327 -0
  5. package/src/contracts/evvm/EvvmLegacy.sol +1553 -0
  6. package/src/contracts/evvm/lib/ErrorsLib.sol +17 -0
  7. package/src/contracts/evvm/lib/EvvmStorage.sol +60 -0
  8. package/src/contracts/evvm/lib/EvvmStructs.sol +64 -0
  9. package/src/contracts/evvm/lib/SignatureUtils.sol +124 -0
  10. package/src/contracts/nameService/NameService.sol +1751 -0
  11. package/src/contracts/nameService/lib/ErrorsLib.sol +27 -0
  12. package/src/contracts/nameService/lib/SignatureUtils.sol +239 -0
  13. package/src/contracts/staking/Estimator.sol +358 -0
  14. package/src/contracts/staking/Staking.sol +1148 -0
  15. package/src/contracts/staking/lib/ErrorsLib.sol +19 -0
  16. package/src/contracts/staking/lib/SignatureUtils.sol +68 -0
  17. package/src/contracts/treasury/Treasury.sol +104 -0
  18. package/src/contracts/treasury/lib/ErrorsLib.sol +11 -0
  19. package/src/contracts/treasuryTwoChains/TreasuryExternalChainStation.sol +551 -0
  20. package/src/contracts/treasuryTwoChains/TreasuryHostChainStation.sol +512 -0
  21. package/src/contracts/treasuryTwoChains/lib/ErrorsLib.sol +15 -0
  22. package/src/contracts/treasuryTwoChains/lib/ExternalChainStationStructs.sol +41 -0
  23. package/src/contracts/treasuryTwoChains/lib/HostChainStationStructs.sol +52 -0
  24. package/src/contracts/treasuryTwoChains/lib/SignatureUtils.sol +47 -0
  25. package/src/interfaces/IEstimator.sol +102 -0
  26. package/src/interfaces/IEvvm.sol +195 -0
  27. package/src/interfaces/INameService.sol +283 -0
  28. package/src/interfaces/IStaking.sol +202 -0
  29. package/src/interfaces/ITreasury.sol +17 -0
  30. package/src/interfaces/ITreasuryExternalChainStation.sol +262 -0
  31. package/src/interfaces/ITreasuryHostChainStation.sol +251 -0
  32. package/src/lib/AdvancedStrings.sol +77 -0
  33. package/src/lib/Erc191TestBuilder.sol +402 -0
  34. package/src/lib/SignatureRecover.sol +56 -0
@@ -0,0 +1,251 @@
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 HostChainStationStructs {
7
+ struct AddressTypeProposal {
8
+ address current;
9
+ address proposal;
10
+ uint256 timeToAccept;
11
+ }
12
+
13
+ struct AxelarConfig {
14
+ string externalChainStationChainName;
15
+ string externalChainStationAddress;
16
+ address gasServiceAddress;
17
+ address gatewayAddress;
18
+ }
19
+
20
+ struct CrosschainConfig {
21
+ uint32 externalChainStationDomainId;
22
+ address mailboxAddress;
23
+ uint32 externalChainStationEid;
24
+ address endpointAddress;
25
+ string externalChainStationChainName;
26
+ address gasServiceAddress;
27
+ address gatewayAddress;
28
+ }
29
+
30
+ struct HyperlaneConfig {
31
+ uint32 externalChainStationDomainId;
32
+ bytes32 externalChainStationAddress;
33
+ address mailboxAddress;
34
+ }
35
+
36
+ struct LayerZeroConfig {
37
+ uint32 externalChainStationEid;
38
+ bytes32 externalChainStationAddress;
39
+ address endpointAddress;
40
+ }
41
+ }
42
+
43
+ interface ITreasuryHostChainStation {
44
+ struct EnforcedOptionParam {
45
+ uint32 eid;
46
+ uint16 msgType;
47
+ bytes options;
48
+ }
49
+
50
+ struct Origin {
51
+ uint32 srcEid;
52
+ bytes32 sender;
53
+ uint64 nonce;
54
+ }
55
+
56
+ error AddressEmptyCode(address target);
57
+ error AddressInsufficientBalance(address account);
58
+ error ChainIdNotAuthorized();
59
+ error FailedInnerCall();
60
+ error InsufficientBalance();
61
+ error InvalidAddress();
62
+ error InvalidDelegate();
63
+ error InvalidEndpointCall();
64
+ error InvalidOptionType(uint16 optionType);
65
+ error InvalidOptions(bytes options);
66
+ error InvalidSignature();
67
+ error LzTokenUnavailable();
68
+ error MailboxNotAuthorized();
69
+ error NoPeer(uint32 eid);
70
+ error NotApprovedByGateway();
71
+ error NotEnoughNative(uint256 msgValue);
72
+ error OnlyEndpoint(address addr);
73
+ error OnlyPeer(uint32 eid, bytes32 sender);
74
+ error OwnableInvalidOwner(address owner);
75
+ error OwnableUnauthorizedAccount(address account);
76
+ error PrincipalTokenIsNotWithdrawable();
77
+ error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
78
+ error SafeERC20FailedOperation(address token);
79
+ error SenderNotAuthorized();
80
+
81
+ event EnforcedOptionSet(EnforcedOptionParam[] _enforcedOptions);
82
+ event FisherBridgeSend(
83
+ address indexed from,
84
+ address indexed addressToReceive,
85
+ address indexed tokenAddress,
86
+ uint256 priorityFee,
87
+ uint256 amount,
88
+ uint256 nonce
89
+ );
90
+ event OwnershipTransferred(
91
+ address indexed previousOwner,
92
+ address indexed newOwner
93
+ );
94
+ event PeerSet(uint32 eid, bytes32 peer);
95
+
96
+ function acceptAdmin() external;
97
+
98
+ function acceptFisherExecutor() external;
99
+
100
+ function allowInitializePath(
101
+ Origin memory origin
102
+ ) external view returns (bool);
103
+
104
+ function combineOptions(
105
+ uint32 _eid,
106
+ uint16 _msgType,
107
+ bytes memory _extraOptions
108
+ ) external view returns (bytes memory);
109
+
110
+ function endpoint() external view returns (address);
111
+
112
+ function enforcedOptions(
113
+ uint32 eid,
114
+ uint16 msgType
115
+ ) external view returns (bytes memory enforcedOption);
116
+
117
+ function execute(
118
+ bytes32 commandId,
119
+ string memory sourceChain,
120
+ string memory sourceAddress,
121
+ bytes memory payload
122
+ ) external;
123
+
124
+ function fisherBridgeReceive(
125
+ address from,
126
+ address addressToReceive,
127
+ address tokenAddress,
128
+ uint256 priorityFee,
129
+ uint256 amount,
130
+ bytes memory signature
131
+ ) external;
132
+
133
+ function fisherBridgeSend(
134
+ address from,
135
+ address addressToReceive,
136
+ address tokenAddress,
137
+ uint256 priorityFee,
138
+ uint256 amount,
139
+ bytes memory signature
140
+ ) external;
141
+
142
+ function gateway() external view returns (address);
143
+
144
+ function getAdmin()
145
+ external
146
+ view
147
+ returns (HostChainStationStructs.AddressTypeProposal memory);
148
+
149
+ function getAxelarConfig()
150
+ external
151
+ view
152
+ returns (HostChainStationStructs.AxelarConfig memory);
153
+
154
+ function getEvvmAddress() external view returns (address);
155
+
156
+ function getFisherExecutor()
157
+ external
158
+ view
159
+ returns (HostChainStationStructs.AddressTypeProposal memory);
160
+
161
+ function getHyperlaneConfig()
162
+ external
163
+ view
164
+ returns (HostChainStationStructs.HyperlaneConfig memory);
165
+
166
+ function getLayerZeroConfig()
167
+ external
168
+ view
169
+ returns (HostChainStationStructs.LayerZeroConfig memory);
170
+
171
+ function getNextFisherExecutionNonce(
172
+ address user
173
+ ) external view returns (uint256);
174
+
175
+ function getOptions() external view returns (bytes memory);
176
+
177
+ function getQuoteHyperlane(
178
+ address toAddress,
179
+ address token,
180
+ uint256 amount
181
+ ) external view returns (uint256);
182
+
183
+ function handle(
184
+ uint32 _origin,
185
+ bytes32 _sender,
186
+ bytes memory _data
187
+ ) external payable;
188
+
189
+ function isComposeMsgSender(
190
+ Origin memory,
191
+ bytes memory,
192
+ address _sender
193
+ ) external view returns (bool);
194
+
195
+ function lzReceive(
196
+ Origin memory _origin,
197
+ bytes32 _guid,
198
+ bytes memory _message,
199
+ address _executor,
200
+ bytes memory _extraData
201
+ ) external payable;
202
+
203
+ function nextNonce(uint32, bytes32) external view returns (uint64 nonce);
204
+
205
+ function oAppVersion()
206
+ external
207
+ pure
208
+ returns (uint64 senderVersion, uint64 receiverVersion);
209
+
210
+ function owner() external view returns (address);
211
+
212
+ function peers(uint32 eid) external view returns (bytes32 peer);
213
+
214
+ function proposeAdmin(address _newOwner) external;
215
+
216
+ function proposeFisherExecutor(address _newFisherExecutor) external;
217
+
218
+ function quoteLayerZero(
219
+ address toAddress,
220
+ address token,
221
+ uint256 amount
222
+ ) external view returns (uint256);
223
+
224
+ function rejectProposalAdmin() external;
225
+
226
+ function rejectProposalFisherExecutor() external;
227
+
228
+ function renounceOwnership() external;
229
+
230
+ function setDelegate(address _delegate) external;
231
+
232
+ function setEnforcedOptions(
233
+ EnforcedOptionParam[] memory _enforcedOptions
234
+ ) external;
235
+
236
+ function setExternalChainAddress(
237
+ address externalChainStationAddress,
238
+ string memory externalChainStationAddressString
239
+ ) external;
240
+
241
+ function setPeer(uint32 _eid, bytes32 _peer) external;
242
+
243
+ function transferOwnership(address newOwner) external;
244
+
245
+ function withdraw(
246
+ address toAddress,
247
+ address token,
248
+ uint256 amount,
249
+ bytes1 protocolToExecute
250
+ ) external payable;
251
+ }
@@ -0,0 +1,77 @@
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 {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
7
+
8
+ library AdvancedStrings {
9
+ function addressToString(
10
+ address _address
11
+ ) internal pure returns (string memory) {
12
+ bytes32 _bytes = bytes32(uint256(uint160(_address)));
13
+ bytes memory HEX = "0123456789abcdef";
14
+ bytes memory _string = new bytes(42);
15
+ _string[0] = "0";
16
+ _string[1] = "x";
17
+ for (uint256 i = 0; i < 20; i++) {
18
+ _string[2 + i * 2] = HEX[uint8(_bytes[i + 12] >> 4)];
19
+ _string[3 + i * 2] = HEX[uint8(_bytes[i + 12] & 0x0f)];
20
+ }
21
+ return string(_string);
22
+ }
23
+
24
+ function toHex16(bytes16 data) internal pure returns (bytes32 result) {
25
+ result =
26
+ (bytes32(data) &
27
+ 0xFFFFFFFFFFFFFFFF000000000000000000000000000000000000000000000000) |
28
+ ((bytes32(data) &
29
+ 0x0000000000000000FFFFFFFFFFFFFFFF00000000000000000000000000000000) >>
30
+ 64);
31
+ result =
32
+ (result &
33
+ 0xFFFFFFFF000000000000000000000000FFFFFFFF000000000000000000000000) |
34
+ ((result &
35
+ 0x00000000FFFFFFFF000000000000000000000000FFFFFFFF0000000000000000) >>
36
+ 32);
37
+ result =
38
+ (result &
39
+ 0xFFFF000000000000FFFF000000000000FFFF000000000000FFFF000000000000) |
40
+ ((result &
41
+ 0x0000FFFF000000000000FFFF000000000000FFFF000000000000FFFF00000000) >>
42
+ 16);
43
+ result =
44
+ (result &
45
+ 0xFF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000) |
46
+ ((result &
47
+ 0x00FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF0000) >>
48
+ 8);
49
+ result =
50
+ ((result &
51
+ 0xF000F000F000F000F000F000F000F000F000F000F000F000F000F000F000F000) >>
52
+ 4) |
53
+ ((result &
54
+ 0x0F000F000F000F000F000F000F000F000F000F000F000F000F000F000F000F00) >>
55
+ 8);
56
+ result = bytes32(
57
+ 0x3030303030303030303030303030303030303030303030303030303030303030 +
58
+ uint256(result) +
59
+ (((uint256(result) +
60
+ 0x0606060606060606060606060606060606060606060606060606060606060606) >>
61
+ 4) &
62
+ 0x0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F) *
63
+ 7
64
+ );
65
+ }
66
+
67
+ function bytes32ToString(bytes32 data) public pure returns (string memory) {
68
+ return
69
+ string(
70
+ abi.encodePacked(
71
+ "0x",
72
+ toHex16(bytes16(data)),
73
+ toHex16(bytes16(data << 128))
74
+ )
75
+ );
76
+ }
77
+ }