Skip to content

Commit f1967d9

Browse files
authored
feat: expand keyed nonces to 0 key specific getters for compatibility (#899)
1 parent bea7527 commit f1967d9

File tree

9 files changed

+86
-92
lines changed

9 files changed

+86
-92
lines changed

.github/workflows/coverage.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ out/
99
.idea
1010
.vscode
1111

12-
# well, looks strange to ignore package-lock, but we have only pretter and it's temproray
1312
package-lock.json
1413
node_modules
1514

foundry.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ runs = 10000
3434
[profile.gas]
3535
gas_snapshot_check = true
3636
test = 'tests/gas'
37+
isolate = true
3738

3839
[rpc_endpoints]
3940
mainnet = "${RPC_MAINNET}"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
"prettier-plugin-solidity": "2.1.0"
1919
},
2020
"lint-staged": {
21-
"*.{sol,md,py,ts}": "prettier --write"
21+
"*.{sol,md,py,ts}": "prettier . --write"
2222
}
2323
}

snapshots/Spoke.Operations.ZeroRiskPremium.json

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
{
2-
"borrow: first": "198987",
3-
"borrow: second action, same reserve": "179508",
4-
"liquidationCall: full": "291049",
5-
"liquidationCall: partial": "315143",
6-
"permitReserve + repay (multicall)": "235508",
7-
"permitReserve + supply (multicall)": "140866",
8-
"permitReserve + supply + enable collateral (multicall)": "176163",
2+
"borrow: first": "198976",
3+
"borrow: second action, same reserve": "179497",
4+
"liquidationCall: full": "291027",
5+
"liquidationCall: partial": "315121",
6+
"permitReserve + repay (multicall)": "235530",
7+
"permitReserve + supply (multicall)": "140910",
8+
"permitReserve + supply + enable collateral (multicall)": "176141",
99
"repay: full": "151572",
1010
"repay: partial": "176035",
11-
"setUserPositionManagerWithSig: disable": "44851",
12-
"setUserPositionManagerWithSig: enable": "68880",
13-
"supply + enable collateral (multicall)": "154105",
14-
"supply: 0 borrows, collateral disabled": "115700",
15-
"supply: 0 borrows, collateral enabled": "120097",
16-
"supply: 1 borrow": "120089",
17-
"supply: second action, same reserve": "102997",
18-
"updateUserDynamicConfig: 1 collateral": "73827",
19-
"updateUserDynamicConfig: 2 collaterals": "88687",
20-
"updateUserRiskPremium: 1 borrow": "95260",
21-
"updateUserRiskPremium: 2 borrows": "111352",
22-
"usingAsCollateral: 0 borrows, enable": "59042",
23-
"usingAsCollateral: 1 borrow, disable": "105595",
24-
"usingAsCollateral: 1 borrow, enable": "32364",
25-
"usingAsCollateral: 2 borrows, disable": "128060",
26-
"usingAsCollateral: 2 borrows, enable": "41942",
11+
"setUserPositionManagerWithSig: disable": "44918",
12+
"setUserPositionManagerWithSig: enable": "68947",
13+
"supply + enable collateral (multicall)": "154083",
14+
"supply: 0 borrows, collateral disabled": "115722",
15+
"supply: 0 borrows, collateral enabled": "120119",
16+
"supply: 1 borrow": "120111",
17+
"supply: second action, same reserve": "103019",
18+
"updateUserDynamicConfig: 1 collateral": "73761",
19+
"updateUserDynamicConfig: 2 collaterals": "88621",
20+
"updateUserRiskPremium: 1 borrow": "95282",
21+
"updateUserRiskPremium: 2 borrows": "111374",
22+
"usingAsCollateral: 0 borrows, enable": "58976",
23+
"usingAsCollateral: 1 borrow, disable": "105529",
24+
"usingAsCollateral: 1 borrow, enable": "32298",
25+
"usingAsCollateral: 2 borrows, disable": "127994",
26+
"usingAsCollateral: 2 borrows, enable": "41876",
2727
"withdraw: 0 borrows, full": "127680",
2828
"withdraw: 0 borrows, partial": "132727",
2929
"withdraw: 1 borrow, partial": "161709",

snapshots/Spoke.Operations.json

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
{
2-
"borrow: first": "269156",
3-
"borrow: second action, same reserve": "212677",
4-
"liquidationCall: full": "324435",
5-
"liquidationCall: partial": "348529",
6-
"permitReserve + repay (multicall)": "268887",
7-
"permitReserve + supply (multicall)": "140866",
8-
"permitReserve + supply + enable collateral (multicall)": "176163",
2+
"borrow: first": "269145",
3+
"borrow: second action, same reserve": "212666",
4+
"liquidationCall: full": "324413",
5+
"liquidationCall: partial": "348507",
6+
"permitReserve + repay (multicall)": "268909",
7+
"permitReserve + supply (multicall)": "140910",
8+
"permitReserve + supply + enable collateral (multicall)": "176141",
99
"repay: full": "146213",
1010
"repay: partial": "209414",
11-
"setUserPositionManagerWithSig: disable": "44851",
12-
"setUserPositionManagerWithSig: enable": "68880",
13-
"supply + enable collateral (multicall)": "154105",
14-
"supply: 0 borrows, collateral disabled": "115700",
15-
"supply: 0 borrows, collateral enabled": "120097",
16-
"supply: 1 borrow": "120089",
17-
"supply: second action, same reserve": "102997",
18-
"updateUserDynamicConfig: 1 collateral": "73827",
19-
"updateUserDynamicConfig: 2 collaterals": "88687",
20-
"updateUserRiskPremium: 1 borrow": "177347",
21-
"updateUserRiskPremium: 2 borrows": "262712",
22-
"usingAsCollateral: 0 borrows, enable": "59042",
23-
"usingAsCollateral: 1 borrow, disable": "187682",
24-
"usingAsCollateral: 1 borrow, enable": "32364",
25-
"usingAsCollateral: 2 borrows, disable": "287419",
26-
"usingAsCollateral: 2 borrows, enable": "41942",
11+
"setUserPositionManagerWithSig: disable": "44918",
12+
"setUserPositionManagerWithSig: enable": "68947",
13+
"supply + enable collateral (multicall)": "154083",
14+
"supply: 0 borrows, collateral disabled": "115722",
15+
"supply: 0 borrows, collateral enabled": "120119",
16+
"supply: 1 borrow": "120111",
17+
"supply: second action, same reserve": "103019",
18+
"updateUserDynamicConfig: 1 collateral": "73761",
19+
"updateUserDynamicConfig: 2 collaterals": "88621",
20+
"updateUserRiskPremium: 1 borrow": "177369",
21+
"updateUserRiskPremium: 2 borrows": "262734",
22+
"usingAsCollateral: 0 borrows, enable": "58976",
23+
"usingAsCollateral: 1 borrow, disable": "187616",
24+
"usingAsCollateral: 1 borrow, enable": "32298",
25+
"usingAsCollateral: 2 borrows, disable": "287353",
26+
"usingAsCollateral: 2 borrows, enable": "41876",
2727
"withdraw: 0 borrows, full": "127680",
2828
"withdraw: 0 borrows, partial": "132727",
2929
"withdraw: 1 borrow, partial": "241296",

src/interfaces/INoncesKeyed.sol

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ interface INoncesKeyed {
66
/// @notice Thrown when nonce being consumed does not match `currentNonce` for `account`.
77
error InvalidAccountNonce(address account, uint256 currentNonce);
88

9+
/// @notice Allows caller to revoke their next sequential nonce at zero key.
10+
/// @dev This does not invalidate nonce at other `key`s namespace.
11+
/// @return keyNonce The revoked key-prefixed nonce.
12+
function useNonce() external returns (uint256 keyNonce);
13+
914
/// @notice Allows caller to revoke their next sequential nonce at specified `key`.
1015
/// @dev This does not invalidate nonce at other `key`s namespace.
1116
/// @param key The key which specifies namespace of the nonce.
1217
/// @return keyNonce The revoked key-prefixed nonce.
1318
function useNonce(uint192 key) external returns (uint256 keyNonce);
1419

20+
/// @notice Returns the next unused nonce for an address and zero key.
21+
/// @param owner The address of the nonce over.
22+
/// @return keyNonce The first 24 bytes are for the key, & the last 8 bytes for the nonce.
23+
function nonces(address owner) external view returns (uint256 keyNonce);
24+
1525
/// @notice Returns the next unused nonce for an address and key. Result contains the key prefix.
1626
/// @param owner The address of the nonce over.
1727
/// @param key The key which specifies namespace of the nonce.

src/utils/NoncesKeyed.sol

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,21 @@ import {INoncesKeyed} from 'src/interfaces/INoncesKeyed.sol';
1010
contract NoncesKeyed is INoncesKeyed {
1111
mapping(address owner => mapping(uint192 key => uint64 nonce)) private _nonces;
1212

13+
/// @inheritdoc INoncesKeyed
14+
function useNonce() external returns (uint256) {
15+
return _useNonce(msg.sender, 0);
16+
}
17+
1318
/// @inheritdoc INoncesKeyed
1419
function useNonce(uint192 key) external returns (uint256) {
1520
return _useNonce(msg.sender, key);
1621
}
1722

23+
/// @inheritdoc INoncesKeyed
24+
function nonces(address owner) external view returns (uint256) {
25+
return _pack(0, _nonces[owner][0]);
26+
}
27+
1828
/// @inheritdoc INoncesKeyed
1929
function nonces(address owner, uint192 key) external view returns (uint256) {
2030
return _pack(key, _nonces[owner][key]);

tests/unit/NoncesKeyed.t.sol

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@ contract NoncesKeyedTest is Base {
1212
mock = new NoncesKeyedMock();
1313
}
1414

15+
function test_useNonce_zeroKey_monotonic(bytes32) public {
16+
vm.setArbitraryStorage(address(mock));
17+
18+
address owner = vm.randomAddress();
19+
20+
uint256 keyNonce = mock.nonces(owner);
21+
(uint192 key, ) = _unpackNonce(keyNonce);
22+
assertEq(key, 0);
23+
24+
vm.prank(owner);
25+
uint256 consumedKeyNonce = mock.useNonce();
26+
(key, ) = _unpackNonce(consumedKeyNonce);
27+
assertEq(key, 0);
28+
29+
assertEq(consumedKeyNonce, keyNonce);
30+
_assertNonceIncrement(mock, owner, keyNonce);
31+
}
32+
1533
function test_useNonce_monotonic(bytes32) public {
1634
vm.setArbitraryStorage(address(mock));
1735

0 commit comments

Comments
 (0)