@evvm/testnet-contracts 2.1.3 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +2 -2
- package/README.md +355 -55
- package/contracts/evvm/Evvm.sol +39 -38
- package/contracts/evvm/lib/ErrorsLib.sol +2 -1
- package/contracts/evvm/lib/EvvmStorage.sol +2 -0
- package/contracts/evvm/lib/EvvmStructs.sol +27 -1
- package/contracts/evvm/lib/SignatureUtils.sol +14 -17
- package/contracts/nameService/NameService.sol +124 -366
- package/contracts/nameService/lib/ErrorsLib.sol +2 -8
- package/contracts/nameService/lib/IdentityValidation.sol +182 -0
- package/contracts/nameService/lib/NameServiceStructs.sol +69 -0
- package/contracts/nameService/lib/SignatureUtils.sol +47 -41
- package/contracts/p2pSwap/P2PSwap.sol +54 -535
- package/contracts/p2pSwap/lib/P2PSwapStructs.sol +59 -0
- package/contracts/p2pSwap/lib/SignatureUtils.sol +16 -18
- package/contracts/staking/Estimator.sol +7 -6
- package/contracts/staking/Staking.sol +70 -159
- package/contracts/staking/lib/ErrorsLib.sol +0 -1
- package/contracts/staking/lib/SignatureUtils.sol +7 -36
- package/contracts/staking/lib/StakingStructs.sol +94 -0
- package/contracts/treasury/Treasury.sol +18 -20
- package/contracts/treasuryTwoChains/TreasuryExternalChainStation.sol +88 -35
- package/contracts/treasuryTwoChains/TreasuryHostChainStation.sol +81 -47
- package/contracts/treasuryTwoChains/lib/ErrorsLib.sol +2 -0
- package/contracts/treasuryTwoChains/lib/ExternalChainStationStructs.sol +3 -14
- package/contracts/treasuryTwoChains/lib/HostChainStationStructs.sol +3 -7
- package/contracts/treasuryTwoChains/lib/SignatureUtils.sol +12 -14
- package/interfaces/IEstimator.sol +7 -50
- package/interfaces/IEvvm.sol +17 -91
- package/interfaces/INameService.sol +37 -88
- package/interfaces/IP2PSwap.sol +19 -15
- package/interfaces/IStaking.sol +20 -50
- package/interfaces/ITreasury.sol +1 -4
- package/interfaces/ITreasuryExternalChainStation.sol +11 -15
- package/interfaces/ITreasuryHostChainStation.sol +7 -10
- package/library/Erc191TestBuilder.sol +56 -57
- package/library/EvvmService.sol +40 -0
- package/library/primitives/IERC20.sol +79 -0
- package/library/primitives/Math.sol +415 -0
- package/library/primitives/SignatureRecover.sol +42 -0
- package/library/utils/AdvancedStrings.sol +89 -0
- package/library/utils/GovernanceUtils.sol +81 -0
- package/library/utils/SignatureUtil.sol +29 -0
- package/library/utils/nonces/AsyncNonce.sol +32 -0
- package/library/utils/nonces/SyncNonce.sol +27 -0
- package/library/utils/service/EvvmPayments.sol +77 -0
- package/library/utils/service/StakingServiceUtils.sol +32 -0
- package/package.json +11 -13
- package/contracts/evvm/EvvmLegacy.sol +0 -1553
- package/library/AdvancedStrings.sol +0 -77
- package/library/SignatureRecover.sol +0 -140
- package/library/StakingServiceHooks.sol +0 -116
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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 {SignatureRecover} from "@evvm/testnet-contracts/library/primitives/SignatureRecover.sol";
|
|
7
|
+
import {AdvancedStrings} from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
|
|
8
|
+
|
|
9
|
+
library SignatureUtil {
|
|
10
|
+
function verifySignature(
|
|
11
|
+
uint256 evvmID,
|
|
12
|
+
string memory functionName,
|
|
13
|
+
string memory inputs,
|
|
14
|
+
bytes memory signature,
|
|
15
|
+
address expectedSigner
|
|
16
|
+
) internal pure returns (bool) {
|
|
17
|
+
return
|
|
18
|
+
SignatureRecover.recoverSigner(
|
|
19
|
+
string.concat(
|
|
20
|
+
AdvancedStrings.uintToString(evvmID),
|
|
21
|
+
",",
|
|
22
|
+
functionName,
|
|
23
|
+
",",
|
|
24
|
+
inputs
|
|
25
|
+
),
|
|
26
|
+
signature
|
|
27
|
+
) == expectedSigner;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
abstract contract AsyncNonce {
|
|
7
|
+
error AsyncNonceAlreadyUsed();
|
|
8
|
+
|
|
9
|
+
mapping(address user => mapping(uint256 nonce => bool availability))
|
|
10
|
+
private asyncNonce;
|
|
11
|
+
|
|
12
|
+
function markAsyncNonceAsUsed(
|
|
13
|
+
address user,
|
|
14
|
+
uint256 nonce
|
|
15
|
+
) internal virtual {
|
|
16
|
+
asyncNonce[user][nonce] = true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function verifyAsyncNonce(
|
|
20
|
+
address user,
|
|
21
|
+
uint256 nonce
|
|
22
|
+
) internal view virtual {
|
|
23
|
+
if (asyncNonce[user][nonce]) revert AsyncNonceAlreadyUsed();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function getIfUsedAsyncNonce(
|
|
27
|
+
address user,
|
|
28
|
+
uint256 nonce
|
|
29
|
+
) public view virtual returns (bool) {
|
|
30
|
+
return asyncNonce[user][nonce];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
abstract contract SyncNonce {
|
|
7
|
+
error SyncNonceMismatch();
|
|
8
|
+
|
|
9
|
+
mapping(address user => uint256 nonce) private syncNonce;
|
|
10
|
+
|
|
11
|
+
function incrementSyncNonce(address user) internal virtual {
|
|
12
|
+
syncNonce[user]++;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function verifySyncNonce(
|
|
16
|
+
address user,
|
|
17
|
+
uint256 nonce
|
|
18
|
+
) internal view virtual {
|
|
19
|
+
if (syncNonce[user] != nonce) revert SyncNonceMismatch();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function getNextCurrentSyncNonce(
|
|
23
|
+
address user
|
|
24
|
+
) public view virtual returns (uint256) {
|
|
25
|
+
return syncNonce[user];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -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 {IEvvm, EvvmStructs} from "@evvm/testnet-contracts/interfaces/IEvvm.sol";
|
|
7
|
+
|
|
8
|
+
abstract contract EvvmPayments {
|
|
9
|
+
IEvvm internal evvm;
|
|
10
|
+
|
|
11
|
+
constructor(address evvmAddress) {}
|
|
12
|
+
|
|
13
|
+
function requestPay(
|
|
14
|
+
address from,
|
|
15
|
+
address token,
|
|
16
|
+
uint256 amount,
|
|
17
|
+
uint256 priorityFee,
|
|
18
|
+
uint256 nonce,
|
|
19
|
+
bool priorityFlag,
|
|
20
|
+
bytes memory signature
|
|
21
|
+
) internal virtual {
|
|
22
|
+
evvm.pay(
|
|
23
|
+
from,
|
|
24
|
+
address(this),
|
|
25
|
+
"",
|
|
26
|
+
token,
|
|
27
|
+
amount,
|
|
28
|
+
priorityFee,
|
|
29
|
+
nonce,
|
|
30
|
+
priorityFlag,
|
|
31
|
+
address(this),
|
|
32
|
+
signature
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function requestDispersePay(
|
|
37
|
+
EvvmStructs.DispersePayMetadata[] memory toData,
|
|
38
|
+
address token,
|
|
39
|
+
uint256 amount,
|
|
40
|
+
uint256 priorityFee,
|
|
41
|
+
uint256 nonce,
|
|
42
|
+
bool priorityFlag,
|
|
43
|
+
bytes memory signature
|
|
44
|
+
) internal virtual {
|
|
45
|
+
evvm.dispersePay(
|
|
46
|
+
address(this),
|
|
47
|
+
toData,
|
|
48
|
+
token,
|
|
49
|
+
amount,
|
|
50
|
+
priorityFee,
|
|
51
|
+
nonce,
|
|
52
|
+
priorityFlag,
|
|
53
|
+
address(this),
|
|
54
|
+
signature
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function makeCaPay(
|
|
59
|
+
address to,
|
|
60
|
+
address token,
|
|
61
|
+
uint256 amount
|
|
62
|
+
) internal virtual {
|
|
63
|
+
evvm.caPay(to, token, amount);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function makeDisperseCaPay(
|
|
67
|
+
EvvmStructs.DisperseCaPayMetadata[] memory toData,
|
|
68
|
+
address token,
|
|
69
|
+
uint256 amount
|
|
70
|
+
) internal virtual {
|
|
71
|
+
evvm.disperseCaPay(toData, token, amount);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function _changeEvvmAddress(address newEvvmAddress) internal virtual {
|
|
75
|
+
evvm = IEvvm(newEvvmAddress);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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 {IStaking} from "@evvm/testnet-contracts/interfaces/IStaking.sol";
|
|
6
|
+
import {IEvvm} from "@evvm/testnet-contracts/interfaces/IEvvm.sol";
|
|
7
|
+
|
|
8
|
+
abstract contract StakingServiceUtils {
|
|
9
|
+
IStaking internal staking;
|
|
10
|
+
|
|
11
|
+
constructor(address stakingAddress) {
|
|
12
|
+
staking = IStaking(stakingAddress);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function _makeStakeService(uint256 amountToStake) internal {
|
|
16
|
+
staking.prepareServiceStaking(amountToStake);
|
|
17
|
+
IEvvm(staking.getEvvmAddress()).caPay(
|
|
18
|
+
address(staking),
|
|
19
|
+
IEvvm(staking.getEvvmAddress()).getPrincipalTokenAddress(),
|
|
20
|
+
staking.priceOfStaking() * amountToStake
|
|
21
|
+
);
|
|
22
|
+
staking.confirmServiceStaking();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function _makeUnstakeService(uint256 amountToUnstake) internal {
|
|
26
|
+
staking.serviceUnstaking(amountToUnstake);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function _changeStakingAddress(address newStakingAddress) internal virtual {
|
|
30
|
+
staking = IStaking(newStakingAddress);
|
|
31
|
+
}
|
|
32
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evvm/testnet-contracts",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "EVVM Testnet Contracts - Smart contracts and tools for scalable, modular, and cross-chain EVM virtualization",
|
|
6
6
|
"files": [
|
|
@@ -36,18 +36,17 @@
|
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
|
-
"
|
|
39
|
+
"publish-package": "bun run copy-files && bun publish && bun run clean",
|
|
40
|
+
"prepare-publish": "bun run copy-files && bun run pack",
|
|
41
|
+
"build": "bun run copy-files",
|
|
40
42
|
"copy-files": "cp -r src/contracts . && cp -r src/interfaces . && cp -r src/library .",
|
|
41
43
|
"clean": "rm -rf contracts interfaces library",
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"deploy:arbitrum": "make deployTestnet NETWORK=arb",
|
|
49
|
-
"wizard": "tsx scripts/evvm-init.ts",
|
|
50
|
-
"wizard:deploy": "tsx scripts/evvm-init.ts --deploy"
|
|
44
|
+
"evvm": "bun run cli/index.ts",
|
|
45
|
+
"buildCli": "bun build cli/index.ts --compile --outfile evvm",
|
|
46
|
+
"build-all": "bun run build-linux && bun run build-windows && bun run build-macos",
|
|
47
|
+
"build-linux": "bun build cli/index.ts --compile --outfile .executables/evvm-linux-x64 && bun build cli/index.ts --compile --outfile .executables/evvm-linux-arm64 && bun build cli/index.ts --compile --outfile .executables/evvm-linux-x64-musl && bun build cli/index.ts --compile --outfile .executables/evvm-linux-arm64-musl",
|
|
48
|
+
"build-windows": "bun build cli/index.ts --compile --outfile .executables/evvm-windows-x64.exe",
|
|
49
|
+
"build-macos": "bun build cli/index.ts --compile --outfile .executables/evvm-darwin-x64 && bun build cli/index.ts --compile --outfile .executables/evvm-darwin-arm64"
|
|
51
50
|
},
|
|
52
51
|
"peerDependencies": {
|
|
53
52
|
"@openzeppelin/contracts": "^5.0.0"
|
|
@@ -58,13 +57,12 @@
|
|
|
58
57
|
"dotenv": "^16.4.5",
|
|
59
58
|
"execa": "^8.0.1",
|
|
60
59
|
"prompts": "^2.4.2",
|
|
61
|
-
"viem": "^2.
|
|
60
|
+
"viem": "^2.43.3"
|
|
62
61
|
},
|
|
63
62
|
"devDependencies": {
|
|
64
63
|
"@types/node": "^20.11.0",
|
|
65
64
|
"@types/prompts": "^2.4.9",
|
|
66
65
|
"forge-std": "^1.0.0",
|
|
67
|
-
"tsx": "^4.7.0",
|
|
68
66
|
"typescript": "^5.3.0"
|
|
69
67
|
}
|
|
70
68
|
}
|