@evvm/testnet-contracts 2.2.2 → 2.3.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 +145 -118
- package/README.md +135 -42
- package/contracts/evvm/Evvm.sol +154 -181
- package/contracts/evvm/lib/ErrorsLib.sol +119 -6
- package/contracts/evvm/lib/EvvmStorage.sol +164 -9
- package/contracts/evvm/lib/EvvmStructs.sol +124 -6
- package/contracts/evvm/lib/SignatureUtils.sol +103 -61
- package/contracts/nameService/NameService.sol +165 -155
- package/contracts/nameService/lib/ErrorsLib.sol +142 -8
- package/contracts/nameService/lib/IdentityValidation.sol +21 -0
- package/contracts/nameService/lib/NameServiceStructs.sol +75 -19
- package/contracts/nameService/lib/SignatureUtils.sol +235 -60
- package/contracts/p2pSwap/P2PSwap.sol +205 -164
- package/contracts/staking/Estimator.sol +131 -24
- package/contracts/staking/Staking.sol +98 -113
- package/contracts/staking/lib/ErrorsLib.sol +79 -3
- package/contracts/staking/lib/SignatureUtils.sol +82 -16
- package/contracts/staking/lib/StakingStructs.sol +12 -0
- package/contracts/treasury/Treasury.sol +30 -12
- package/contracts/treasury/lib/ErrorsLib.sol +30 -0
- package/contracts/treasuryTwoChains/TreasuryHostChainStation.sol +3 -3
- package/interfaces/IEvvm.sol +9 -4
- package/interfaces/INameService.sol +12 -3
- package/interfaces/IStaking.sol +2 -1
- package/library/Erc191TestBuilder.sol +188 -0
- package/library/EvvmService.sol +55 -0
- package/library/primitives/SignatureRecover.sol +33 -0
- package/library/utils/AdvancedStrings.sol +61 -0
- package/library/utils/SignatureUtil.sol +34 -0
- package/library/utils/nonces/AsyncNonce.sol +42 -0
- package/library/utils/nonces/SyncNonce.sol +44 -0
- package/library/utils/service/EvvmPayments.sol +68 -1
- package/library/utils/service/StakingServiceUtils.sol +44 -0
- package/package.json +2 -1
|
@@ -2,11 +2,33 @@
|
|
|
2
2
|
// Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
|
|
3
3
|
|
|
4
4
|
pragma solidity ^0.8.0;
|
|
5
|
+
/**
|
|
6
|
+
* @title SignatureRecover
|
|
7
|
+
* @author Mate Labs
|
|
8
|
+
* @notice Library for recovering signer addresses from EIP-191 signed messages
|
|
9
|
+
* @dev Provides utilities for signature verification following the EIP-191 standard.
|
|
10
|
+
* This library is used throughout the EVVM ecosystem for gasless transaction validation.
|
|
11
|
+
*
|
|
12
|
+
* EIP-191 Format:
|
|
13
|
+
* The signed message follows the format:
|
|
14
|
+
* "\x19Ethereum Signed Message:\n" + message.length + message
|
|
15
|
+
*
|
|
16
|
+
* This library can be used by community-developed services to implement
|
|
17
|
+
* signature verification compatible with the EVVM ecosystem.
|
|
18
|
+
*/
|
|
5
19
|
|
|
6
20
|
import {AdvancedStrings} from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
|
|
7
21
|
|
|
8
22
|
library SignatureRecover {
|
|
9
23
|
|
|
24
|
+
/**
|
|
25
|
+
* @notice Recovers the signer address from an EIP-191 signed message
|
|
26
|
+
* @dev Uses ecrecover to extract the signer address from the signature components.
|
|
27
|
+
* The message is hashed with the EIP-191 prefix before recovery.
|
|
28
|
+
* @param message The original message that was signed (without prefix)
|
|
29
|
+
* @param signature 65-byte signature in the format (r, s, v)
|
|
30
|
+
* @return The address that signed the message, or address(0) if invalid
|
|
31
|
+
*/
|
|
10
32
|
function recoverSigner(
|
|
11
33
|
string memory message,
|
|
12
34
|
bytes memory signature
|
|
@@ -22,6 +44,17 @@ library SignatureRecover {
|
|
|
22
44
|
return ecrecover(messageHash, v, r, s);
|
|
23
45
|
}
|
|
24
46
|
|
|
47
|
+
/**
|
|
48
|
+
* @notice Splits a 65-byte signature into its r, s, and v components
|
|
49
|
+
* @dev Extracts signature components using assembly for gas efficiency.
|
|
50
|
+
* Handles both pre-EIP-155 and post-EIP-155 signature formats.
|
|
51
|
+
* @param signature 65-byte signature to split
|
|
52
|
+
* @return r First 32 bytes of the signature
|
|
53
|
+
* @return s Second 32 bytes of the signature
|
|
54
|
+
* @return v Recovery identifier (27 or 28)
|
|
55
|
+
* @custom:throws "Invalid signature length" if signature is not 65 bytes
|
|
56
|
+
* @custom:throws "Invalid signature value" if v is not 27 or 28
|
|
57
|
+
*/
|
|
25
58
|
function splitSignature(
|
|
26
59
|
bytes memory signature
|
|
27
60
|
) internal pure returns (bytes32 r, bytes32 s, uint8 v) {
|
|
@@ -2,12 +2,37 @@
|
|
|
2
2
|
// Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
|
|
3
3
|
|
|
4
4
|
pragma solidity ^0.8.0;
|
|
5
|
+
/**
|
|
6
|
+
* @title AdvancedStrings
|
|
7
|
+
* @author Mate Labs
|
|
8
|
+
* @notice Library for advanced string manipulation and type conversions
|
|
9
|
+
* @dev Provides utility functions for converting various Solidity types to their string
|
|
10
|
+
* representations. These functions are essential for building EIP-191 signature messages
|
|
11
|
+
* in the EVVM ecosystem.
|
|
12
|
+
*
|
|
13
|
+
* Key Features:
|
|
14
|
+
* - Unsigned integer to string conversion
|
|
15
|
+
* - Address to hexadecimal string conversion
|
|
16
|
+
* - Bytes and bytes32 to hexadecimal string conversion
|
|
17
|
+
* - Boolean to string conversion
|
|
18
|
+
* - String equality comparison
|
|
19
|
+
*
|
|
20
|
+
* All hexadecimal outputs use lowercase letters and include the "0x" prefix where applicable.
|
|
21
|
+
* This library can be used by community-developed services for message construction.
|
|
22
|
+
*/
|
|
5
23
|
|
|
6
24
|
import {Math} from "@evvm/testnet-contracts/library/primitives/Math.sol";
|
|
7
25
|
|
|
8
26
|
library AdvancedStrings {
|
|
27
|
+
/// @dev Hexadecimal character lookup table for efficient conversion
|
|
9
28
|
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
|
|
10
29
|
|
|
30
|
+
/**
|
|
31
|
+
* @notice Converts an unsigned integer to its decimal string representation
|
|
32
|
+
* @dev Uses assembly for gas-efficient string construction. Works for any uint256 value.
|
|
33
|
+
* @param value The unsigned integer to convert
|
|
34
|
+
* @return The decimal string representation of the value
|
|
35
|
+
*/
|
|
11
36
|
function uintToString(uint256 value) internal pure returns (string memory) {
|
|
12
37
|
unchecked {
|
|
13
38
|
uint256 length = Math.log10(value) + 1;
|
|
@@ -30,6 +55,12 @@ library AdvancedStrings {
|
|
|
30
55
|
}
|
|
31
56
|
}
|
|
32
57
|
|
|
58
|
+
/**
|
|
59
|
+
* @notice Converts an address to its hexadecimal string representation
|
|
60
|
+
* @dev Returns a 42-character string including the "0x" prefix with lowercase hex digits
|
|
61
|
+
* @param _address The address to convert
|
|
62
|
+
* @return The hexadecimal string representation (e.g., "0x1234...abcd")
|
|
63
|
+
*/
|
|
33
64
|
function addressToString(
|
|
34
65
|
address _address
|
|
35
66
|
) internal pure returns (string memory) {
|
|
@@ -44,6 +75,13 @@ library AdvancedStrings {
|
|
|
44
75
|
return string(_string);
|
|
45
76
|
}
|
|
46
77
|
|
|
78
|
+
/**
|
|
79
|
+
* @notice Compares two strings for equality
|
|
80
|
+
* @dev First compares lengths, then compares keccak256 hashes for efficiency
|
|
81
|
+
* @param a First string to compare
|
|
82
|
+
* @param b Second string to compare
|
|
83
|
+
* @return True if both strings are identical, false otherwise
|
|
84
|
+
*/
|
|
47
85
|
function equal(
|
|
48
86
|
string memory a,
|
|
49
87
|
string memory b
|
|
@@ -53,6 +91,13 @@ library AdvancedStrings {
|
|
|
53
91
|
keccak256(bytes(a)) == keccak256(bytes(b));
|
|
54
92
|
}
|
|
55
93
|
|
|
94
|
+
/**
|
|
95
|
+
* @notice Converts a dynamic bytes array to its hexadecimal string representation
|
|
96
|
+
* @dev Returns a string with "0x" prefix followed by lowercase hex digits.
|
|
97
|
+
* Empty input returns "0x".
|
|
98
|
+
* @param data The bytes array to convert
|
|
99
|
+
* @return The hexadecimal string representation with "0x" prefix
|
|
100
|
+
*/
|
|
56
101
|
function bytesToString(
|
|
57
102
|
bytes memory data
|
|
58
103
|
) internal pure returns (string memory) {
|
|
@@ -72,6 +117,12 @@ library AdvancedStrings {
|
|
|
72
117
|
return string(result);
|
|
73
118
|
}
|
|
74
119
|
|
|
120
|
+
/**
|
|
121
|
+
* @notice Converts a bytes32 value to its hexadecimal string representation
|
|
122
|
+
* @dev Returns a 66-character string ("0x" + 64 hex characters) with lowercase letters
|
|
123
|
+
* @param data The bytes32 value to convert
|
|
124
|
+
* @return The hexadecimal string representation with "0x" prefix
|
|
125
|
+
*/
|
|
75
126
|
function bytes32ToString(
|
|
76
127
|
bytes32 data
|
|
77
128
|
) internal pure returns (string memory) {
|
|
@@ -86,4 +137,14 @@ library AdvancedStrings {
|
|
|
86
137
|
|
|
87
138
|
return string(result);
|
|
88
139
|
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @notice Converts a boolean value to its string representation
|
|
143
|
+
* @dev Returns "true" or "false" as lowercase strings
|
|
144
|
+
* @param value The boolean value to convert
|
|
145
|
+
* @return "true" if value is true, "false" otherwise
|
|
146
|
+
*/
|
|
147
|
+
function boolToString(bool value) internal pure returns (string memory) {
|
|
148
|
+
return value ? "true" : "false";
|
|
149
|
+
}
|
|
89
150
|
}
|
|
@@ -2,11 +2,45 @@
|
|
|
2
2
|
// Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
|
|
3
3
|
|
|
4
4
|
pragma solidity ^0.8.0;
|
|
5
|
+
/**
|
|
6
|
+
* @title SignatureUtil
|
|
7
|
+
* @author Mate Labs
|
|
8
|
+
* @notice Library for EIP-191 signature verification in EVVM services
|
|
9
|
+
* @dev Provides a standardized method for verifying signatures in EVVM-compatible services.
|
|
10
|
+
* The signature message format follows a consistent pattern:
|
|
11
|
+
* "[evvmID],[functionName],[inputs]"
|
|
12
|
+
*
|
|
13
|
+
* This library is designed for use by community-developed services to implement
|
|
14
|
+
* signature verification that is compatible with the EVVM ecosystem standard.
|
|
15
|
+
*
|
|
16
|
+
* Example Usage:
|
|
17
|
+
* ```solidity
|
|
18
|
+
* bool isValid = SignatureUtil.verifySignature(
|
|
19
|
+
* evvmID,
|
|
20
|
+
* "myFunction",
|
|
21
|
+
* "param1,param2,param3",
|
|
22
|
+
* signature,
|
|
23
|
+
* expectedSigner
|
|
24
|
+
* );
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
5
27
|
|
|
6
28
|
import {SignatureRecover} from "@evvm/testnet-contracts/library/primitives/SignatureRecover.sol";
|
|
7
29
|
import {AdvancedStrings} from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
|
|
8
30
|
|
|
9
31
|
library SignatureUtil {
|
|
32
|
+
/**
|
|
33
|
+
* @notice Verifies an EIP-191 signature for a service function call
|
|
34
|
+
* @dev Constructs the expected message from the provided parameters and verifies
|
|
35
|
+
* the signature was created by the expected signer. The message format is:
|
|
36
|
+
* "[evvmID],[functionName],[inputs]"
|
|
37
|
+
* @param evvmID Unique identifier of the EVVM instance (for chain-specific signatures)
|
|
38
|
+
* @param functionName Name of the function being called
|
|
39
|
+
* @param inputs Comma-separated string of function input values
|
|
40
|
+
* @param signature 65-byte EIP-191 signature to verify
|
|
41
|
+
* @param expectedSigner Address that should have signed the message
|
|
42
|
+
* @return True if the signature is valid and matches the expected signer
|
|
43
|
+
*/
|
|
10
44
|
function verifySignature(
|
|
11
45
|
uint256 evvmID,
|
|
12
46
|
string memory functionName,
|
|
@@ -2,13 +2,41 @@
|
|
|
2
2
|
// Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
|
|
3
3
|
|
|
4
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
|
+
*/
|
|
5
25
|
|
|
6
26
|
abstract contract AsyncNonce {
|
|
27
|
+
/// @dev Thrown when attempting to use a nonce that has already been consumed
|
|
7
28
|
error AsyncNonceAlreadyUsed();
|
|
8
29
|
|
|
30
|
+
/// @dev Mapping to track used nonces: user address => nonce value => used flag
|
|
9
31
|
mapping(address user => mapping(uint256 nonce => bool availability))
|
|
10
32
|
private asyncNonce;
|
|
11
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
|
+
*/
|
|
12
40
|
function markAsyncNonceAsUsed(
|
|
13
41
|
address user,
|
|
14
42
|
uint256 nonce
|
|
@@ -16,6 +44,13 @@ abstract contract AsyncNonce {
|
|
|
16
44
|
asyncNonce[user][nonce] = true;
|
|
17
45
|
}
|
|
18
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
|
+
*/
|
|
19
54
|
function verifyAsyncNonce(
|
|
20
55
|
address user,
|
|
21
56
|
uint256 nonce
|
|
@@ -23,6 +58,13 @@ abstract contract AsyncNonce {
|
|
|
23
58
|
if (asyncNonce[user][nonce]) revert AsyncNonceAlreadyUsed();
|
|
24
59
|
}
|
|
25
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
|
+
*/
|
|
26
68
|
function getIfUsedAsyncNonce(
|
|
27
69
|
address user,
|
|
28
70
|
uint256 nonce
|
|
@@ -2,16 +2,54 @@
|
|
|
2
2
|
// Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
|
|
3
3
|
|
|
4
4
|
pragma solidity ^0.8.0;
|
|
5
|
+
/**
|
|
6
|
+
* @title SyncNonce
|
|
7
|
+
* @author Mate Labs
|
|
8
|
+
* @notice Abstract contract for synchronous (sequential) nonce management in EVVM services
|
|
9
|
+
* @dev Provides replay protection using a sequential nonce system where nonces must be
|
|
10
|
+
* used in strict ascending order starting from 0.
|
|
11
|
+
*
|
|
12
|
+
* Key Features:
|
|
13
|
+
* - Sequential nonce enforcement (must use nonce N before N+1)
|
|
14
|
+
* - Gas-efficient single uint256 counter per user
|
|
15
|
+
* - Guarantees transaction ordering
|
|
16
|
+
*
|
|
17
|
+
* Use Cases:
|
|
18
|
+
* - Operations requiring strict ordering guarantees
|
|
19
|
+
* - Financial transactions where sequence matters
|
|
20
|
+
* - State-dependent operations that must execute in order
|
|
21
|
+
*
|
|
22
|
+
* Trade-offs:
|
|
23
|
+
* - Cannot submit parallel transactions (must wait for confirmation)
|
|
24
|
+
* - Transaction N+1 cannot be mined before transaction N
|
|
25
|
+
*
|
|
26
|
+
* This contract is designed for use by community-developed services that need
|
|
27
|
+
* strict sequential ordering for their operations.
|
|
28
|
+
*/
|
|
5
29
|
|
|
6
30
|
abstract contract SyncNonce {
|
|
31
|
+
/// @dev Thrown when the provided nonce does not match the expected next nonce
|
|
7
32
|
error SyncNonceMismatch();
|
|
8
33
|
|
|
34
|
+
/// @dev Mapping to track the next expected nonce for each user
|
|
9
35
|
mapping(address user => uint256 nonce) private syncNonce;
|
|
10
36
|
|
|
37
|
+
/**
|
|
38
|
+
* @notice Increments the nonce counter for a user after successful operation
|
|
39
|
+
* @dev Should be called after operation validation to advance the nonce
|
|
40
|
+
* @param user Address of the user whose nonce counter should be incremented
|
|
41
|
+
*/
|
|
11
42
|
function incrementSyncNonce(address user) internal virtual {
|
|
12
43
|
syncNonce[user]++;
|
|
13
44
|
}
|
|
14
45
|
|
|
46
|
+
/**
|
|
47
|
+
* @notice Verifies that the provided nonce matches the expected next nonce
|
|
48
|
+
* @dev Reverts with SyncNonceMismatch if the nonce is not the expected value
|
|
49
|
+
* @param user Address of the user to verify the nonce for
|
|
50
|
+
* @param nonce The nonce value to verify
|
|
51
|
+
* @custom:throws SyncNonceMismatch If nonce does not match the expected value
|
|
52
|
+
*/
|
|
15
53
|
function verifySyncNonce(
|
|
16
54
|
address user,
|
|
17
55
|
uint256 nonce
|
|
@@ -19,6 +57,12 @@ abstract contract SyncNonce {
|
|
|
19
57
|
if (syncNonce[user] != nonce) revert SyncNonceMismatch();
|
|
20
58
|
}
|
|
21
59
|
|
|
60
|
+
/**
|
|
61
|
+
* @notice Gets the current (next expected) nonce for a user
|
|
62
|
+
* @dev Public view function for external queries and transaction preparation
|
|
63
|
+
* @param user Address of the user to query
|
|
64
|
+
* @return The next nonce value that must be used by the user
|
|
65
|
+
*/
|
|
22
66
|
function getNextCurrentSyncNonce(
|
|
23
67
|
address user
|
|
24
68
|
) public view virtual returns (uint256) {
|
|
@@ -2,14 +2,48 @@
|
|
|
2
2
|
// Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
|
|
3
3
|
|
|
4
4
|
pragma solidity ^0.8.0;
|
|
5
|
+
/**
|
|
6
|
+
* @title EvvmPayments
|
|
7
|
+
* @author Mate Labs
|
|
8
|
+
* @notice Abstract contract providing EVVM payment integration for services
|
|
9
|
+
* @dev This contract provides a standardized interface for interacting with
|
|
10
|
+
* the EVVM core contract for payment operations. It supports:
|
|
11
|
+
*
|
|
12
|
+
* Payment Types:
|
|
13
|
+
* - Single payments (pay): Transfer tokens from a user to the service
|
|
14
|
+
* - Disperse payments (dispersePay): Batch payments from multiple sources
|
|
15
|
+
* - Contract-authorized payments (caPay): Service-initiated token distributions
|
|
16
|
+
* - Disperse CA payments: Batch service-initiated distributions
|
|
17
|
+
*
|
|
18
|
+
* This contract is designed for use by community-developed services that need
|
|
19
|
+
* to process payments through the EVVM ecosystem.
|
|
20
|
+
*/
|
|
5
21
|
|
|
6
22
|
import {IEvvm, EvvmStructs} from "@evvm/testnet-contracts/interfaces/IEvvm.sol";
|
|
7
23
|
|
|
8
24
|
abstract contract EvvmPayments {
|
|
25
|
+
/// @dev Reference to the EVVM core contract for payment operations
|
|
9
26
|
IEvvm internal evvm;
|
|
10
27
|
|
|
11
|
-
|
|
28
|
+
/**
|
|
29
|
+
* @notice Initializes the EvvmPayments contract with the EVVM address
|
|
30
|
+
* @param evvmAddress Address of the EVVM core contract
|
|
31
|
+
*/
|
|
32
|
+
constructor(address evvmAddress) {
|
|
33
|
+
evvm = IEvvm(evvmAddress);
|
|
34
|
+
}
|
|
12
35
|
|
|
36
|
+
/**
|
|
37
|
+
* @notice Requests a payment from a user to this contract
|
|
38
|
+
* @dev Calls the EVVM pay function to transfer tokens with signature verification
|
|
39
|
+
* @param from Address of the user making the payment
|
|
40
|
+
* @param token Address of the token being transferred
|
|
41
|
+
* @param amount Amount of tokens to transfer
|
|
42
|
+
* @param priorityFee Additional fee for priority processing
|
|
43
|
+
* @param nonce Nonce for replay protection in EVVM
|
|
44
|
+
* @param priorityFlag True for async nonce, false for sync nonce in EVVM
|
|
45
|
+
* @param signature EIP-191 signature authorizing the payment
|
|
46
|
+
*/
|
|
13
47
|
function requestPay(
|
|
14
48
|
address from,
|
|
15
49
|
address token,
|
|
@@ -33,6 +67,17 @@ abstract contract EvvmPayments {
|
|
|
33
67
|
);
|
|
34
68
|
}
|
|
35
69
|
|
|
70
|
+
/**
|
|
71
|
+
* @notice Requests a batch payment from the caller to multiple recipients
|
|
72
|
+
* @dev Calls the EVVM dispersePay function for efficient batch transfers
|
|
73
|
+
* @param toData Array of recipient addresses and amounts
|
|
74
|
+
* @param token Address of the token being transferred
|
|
75
|
+
* @param amount Total amount being transferred (for signature verification)
|
|
76
|
+
* @param priorityFee Additional fee for priority processing
|
|
77
|
+
* @param nonce Nonce for replay protection in EVVM
|
|
78
|
+
* @param priorityFlag True for async nonce, false for sync nonce in EVVM
|
|
79
|
+
* @param signature EIP-191 signature authorizing the batch payment
|
|
80
|
+
*/
|
|
36
81
|
function requestDispersePay(
|
|
37
82
|
EvvmStructs.DispersePayMetadata[] memory toData,
|
|
38
83
|
address token,
|
|
@@ -55,6 +100,14 @@ abstract contract EvvmPayments {
|
|
|
55
100
|
);
|
|
56
101
|
}
|
|
57
102
|
|
|
103
|
+
/**
|
|
104
|
+
* @notice Sends tokens from this contract to a recipient (contract-authorized)
|
|
105
|
+
* @dev Calls the EVVM caPay function for service-initiated token transfers.
|
|
106
|
+
* This function does not require user signature as it's authorized by the contract.
|
|
107
|
+
* @param to Address of the recipient
|
|
108
|
+
* @param token Address of the token to transfer
|
|
109
|
+
* @param amount Amount of tokens to transfer
|
|
110
|
+
*/
|
|
58
111
|
function makeCaPay(
|
|
59
112
|
address to,
|
|
60
113
|
address token,
|
|
@@ -63,6 +116,14 @@ abstract contract EvvmPayments {
|
|
|
63
116
|
evvm.caPay(to, token, amount);
|
|
64
117
|
}
|
|
65
118
|
|
|
119
|
+
/**
|
|
120
|
+
* @notice Sends tokens from this contract to multiple recipients (batch CA pay)
|
|
121
|
+
* @dev Calls the EVVM disperseCaPay for efficient batch distributions.
|
|
122
|
+
* This function does not require user signatures.
|
|
123
|
+
* @param toData Array of recipient addresses and amounts
|
|
124
|
+
* @param token Address of the token to transfer
|
|
125
|
+
* @param amount Total amount being distributed
|
|
126
|
+
*/
|
|
66
127
|
function makeDisperseCaPay(
|
|
67
128
|
EvvmStructs.DisperseCaPayMetadata[] memory toData,
|
|
68
129
|
address token,
|
|
@@ -71,6 +132,12 @@ abstract contract EvvmPayments {
|
|
|
71
132
|
evvm.disperseCaPay(toData, token, amount);
|
|
72
133
|
}
|
|
73
134
|
|
|
135
|
+
/**
|
|
136
|
+
* @notice Updates the EVVM contract address
|
|
137
|
+
* @dev Internal function for governance-controlled EVVM address changes.
|
|
138
|
+
* Should be protected by time-delayed governance in implementing contracts.
|
|
139
|
+
* @param newEvvmAddress Address of the new EVVM contract
|
|
140
|
+
*/
|
|
74
141
|
function _changeEvvmAddress(address newEvvmAddress) internal virtual {
|
|
75
142
|
evvm = IEvvm(newEvvmAddress);
|
|
76
143
|
}
|
|
@@ -1,17 +1,50 @@
|
|
|
1
1
|
// SPDX-License-Identifier: EVVM-NONCOMMERCIAL-1.0
|
|
2
2
|
// Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
|
|
3
3
|
pragma solidity ^0.8.0;
|
|
4
|
+
/**
|
|
5
|
+
* @title StakingServiceUtils
|
|
6
|
+
* @author Mate Labs
|
|
7
|
+
* @notice Abstract contract providing staking utilities for EVVM services
|
|
8
|
+
* @dev This contract provides helper functions for services that need to
|
|
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.
|
|
23
|
+
*/
|
|
4
24
|
|
|
5
25
|
import {IStaking} from "@evvm/testnet-contracts/interfaces/IStaking.sol";
|
|
6
26
|
import {IEvvm} from "@evvm/testnet-contracts/interfaces/IEvvm.sol";
|
|
7
27
|
|
|
8
28
|
abstract contract StakingServiceUtils {
|
|
29
|
+
/// @dev Reference to the Staking contract for staking operations
|
|
9
30
|
IStaking internal staking;
|
|
10
31
|
|
|
32
|
+
/**
|
|
33
|
+
* @notice Initializes the StakingServiceUtils with the Staking contract address
|
|
34
|
+
* @param stakingAddress Address of the EVVM Staking contract
|
|
35
|
+
*/
|
|
11
36
|
constructor(address stakingAddress) {
|
|
12
37
|
staking = IStaking(stakingAddress);
|
|
13
38
|
}
|
|
14
39
|
|
|
40
|
+
/**
|
|
41
|
+
* @notice Stakes tokens on behalf of this service contract
|
|
42
|
+
* @dev Performs the full staking flow:
|
|
43
|
+
* 1. Prepares staking in the Staking contract
|
|
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
|
|
47
|
+
*/
|
|
15
48
|
function _makeStakeService(uint256 amountToStake) internal {
|
|
16
49
|
staking.prepareServiceStaking(amountToStake);
|
|
17
50
|
IEvvm(staking.getEvvmAddress()).caPay(
|
|
@@ -22,10 +55,21 @@ abstract contract StakingServiceUtils {
|
|
|
22
55
|
staking.confirmServiceStaking();
|
|
23
56
|
}
|
|
24
57
|
|
|
58
|
+
/**
|
|
59
|
+
* @notice Unstakes tokens from this service contract
|
|
60
|
+
* @dev Calls the Staking contract to release staked tokens
|
|
61
|
+
* @param amountToUnstake Number of staking units to release
|
|
62
|
+
*/
|
|
25
63
|
function _makeUnstakeService(uint256 amountToUnstake) internal {
|
|
26
64
|
staking.serviceUnstaking(amountToUnstake);
|
|
27
65
|
}
|
|
28
66
|
|
|
67
|
+
/**
|
|
68
|
+
* @notice Updates the Staking contract address
|
|
69
|
+
* @dev Internal function for governance-controlled Staking address changes.
|
|
70
|
+
* Should be protected by time-delayed governance in implementing contracts.
|
|
71
|
+
* @param newStakingAddress Address of the new Staking contract
|
|
72
|
+
*/
|
|
29
73
|
function _changeStakingAddress(address newStakingAddress) internal virtual {
|
|
30
74
|
staking = IStaking(newStakingAddress);
|
|
31
75
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evvm/testnet-contracts",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
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": [
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@hyperlane-xyz/core": "^3.6.1",
|
|
56
56
|
"chalk": "^5.3.0",
|
|
57
|
+
"cli-loading-animation": "^1.0.6",
|
|
57
58
|
"dotenv": "^16.4.5",
|
|
58
59
|
"execa": "^8.0.1",
|
|
59
60
|
"prompts": "^2.4.2",
|