Skip to content

Commit 340ff9c

Browse files
authored
Honey x402 plus minor fixes (#93)
* Feat/honey eip3009 (#91) * feat/eip-3009 integration * using OZ libs for signature verification * delete unused interface * refactor EIP3009 * rename:eip3009 error strings * version * nits * lint * add eip3009 tests * eip2612 impl * fix test revert * make version EIP712 specific * nit * introduce diamond inheritence * nits * updated honey impl address * Feat honey v3 (#92) * Feat(Honey): Skip paused vault inside withdrawAllFee (#79) * skip paused vault inside withdrawAllFee * nit * add comment * nit * nit * honey: migrate collected fee for new receiver (#80) * honey: migrate collected fee for new receiver * comment * Fix: Refund leftover honey from factory wrapper (#81) * refund lefterover honey in factory wrapper * nit * nit * update honeyFactory impl address on testnet * test domain separator * keep same permit errors * override versionHash * update predicted addresses
1 parent 3534f87 commit 340ff9c

File tree

12 files changed

+1123
-10
lines changed

12 files changed

+1123
-10
lines changed

script/base/actions/ValidateHoneyUpgrade.s.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ contract ValidateHoneyUpgrade is Script {
3434
console2.log("HoneyFactoryReader can be upgraded successfully.");
3535

3636
// check Honey safe upgrade
37-
options.referenceContract = "Honey_V0.sol:Honey_V0";
37+
options.referenceContract = "Honey_V1.sol:Honey_V1";
3838
Upgrades.validateUpgrade("Honey.sol", options);
3939
console2.log("Honey can be upgraded successfully.");
4040

script/honey/HoneyAddresses.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ abstract contract HoneyAddressBook {
3535
function _getMainnetHoneyAddresses() private pure returns (HoneyAddresses memory) {
3636
return HoneyAddresses({
3737
honey: 0xFCBD14DC51f0A4d49d5E53C2E0950e0bC26d0Dce,
38-
honeyImpl: 0x3caE8dC9A2E2D2106CE1a0ffDBdF21AbcC870bF8,
38+
honeyImpl: 0x96b1a552A97dA5503343d0F9FF2766c616E62905,
3939
honeyFactory: 0xA4aFef880F5cE1f63c9fb48F661E27F8B4216401,
4040
honeyFactoryReader: 0x285e147060CDc5ba902786d3A471224ee6cE0F91,
41-
honeyFactoryImpl: 0xF51C5a7B48410c4c4f99d353622d365481BDE7e7,
41+
honeyFactoryImpl: 0x6331F0a4E0220a14Be27BD31aF091F0a1AC036A1,
4242
honeyFactoryReaderImpl: 0x91C54526A9f8D0391F64392f24C7E8ff94A5f4fB,
4343
collateralVaultImpl: 0xAa4f2Bc7a06c89BEAB5125D82e25D4166b4a4681,
44-
honeyFactoryPythWrapper: 0x4b7cb1c197f8EE4d309866B16C2c12E3B4E7E606
44+
honeyFactoryPythWrapper: 0xF5686e448BE103beA465105bEb9d284a34ae7e95
4545
});
4646
}
4747

@@ -51,13 +51,13 @@ abstract contract HoneyAddressBook {
5151
function _getTestnetHoneyAddresses() private pure returns (HoneyAddresses memory) {
5252
return HoneyAddresses({
5353
honey: 0xFCBD14DC51f0A4d49d5E53C2E0950e0bC26d0Dce,
54-
honeyImpl: 0x114Af1Ad4c6FeBCB9222B7D6AF6141E7a34775Fe,
54+
honeyImpl: 0xD1886E0659Ed88812aeA75862Cc9891097c25542,
5555
honeyFactory: 0xA4aFef880F5cE1f63c9fb48F661E27F8B4216401,
5656
honeyFactoryReader: 0x285e147060CDc5ba902786d3A471224ee6cE0F91,
57-
honeyFactoryImpl: 0x3Ba6452ED6C57f4E1A6334E0C3b810c481AdaC64,
57+
honeyFactoryImpl: 0xD38a1fD3E943a61066903889b8e0889EcAc6Dedd,
5858
honeyFactoryReaderImpl: 0x22ee76216B1b7E4f34CF1417da3E4773F7cbA8E6,
5959
collateralVaultImpl: 0xE3689043e7F860FbC0c814839cd7dF5022223172,
60-
honeyFactoryPythWrapper: 0x4b7cb1c197f8EE4d309866B16C2c12E3B4E7E606
60+
honeyFactoryPythWrapper: 0xE5Ad9BA751714ec8cdd554b5a9f12BFcA13980cB
6161
});
6262
}
6363

src/base/EIP2612.sol

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/**
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright (c) 2023, Circle Internet Financial, LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* ---------------------------------------------------------------------
19+
*
20+
* Adapted and modified by Berachain for greater flexibility and reusability
21+
*/
22+
pragma solidity 0.8.26;
23+
24+
import { ERC20 } from "solady/src/tokens/ERC20.sol";
25+
import { SignatureChecker } from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";
26+
import { MessageHashUtils } from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
27+
28+
/**
29+
* @title EIP-2612
30+
* @notice Provide implementation for gas-abstracted approvals with smart account support
31+
* @dev Extends ERC20 to use its EIP712 logic and EIP2612 nonce management.
32+
*/
33+
abstract contract EIP2612 is ERC20 {
34+
// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)")
35+
bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
36+
37+
/**
38+
* @notice Verify a signed approval permit and execute if valid
39+
* @dev Overrides Solady's permit to support smart account (EIP-1271) signatures.
40+
* @param owner Token owner's address (Authorizer)
41+
* @param spender Spender's address
42+
* @param value Amount of allowance
43+
* @param deadline The time at which the signature expires (unix time), or max uint256 value to signal no
44+
* expiration
45+
* @param v v of the signature
46+
* @param r r of the signature
47+
* @param s s of the signature
48+
*/
49+
function permit(
50+
address owner,
51+
address spender,
52+
uint256 value,
53+
uint256 deadline,
54+
uint8 v,
55+
bytes32 r,
56+
bytes32 s
57+
)
58+
public
59+
virtual
60+
override
61+
{
62+
_permit(owner, spender, value, deadline, abi.encodePacked(r, s, v));
63+
}
64+
65+
/**
66+
* @notice Verify a signed approval permit and execute if valid (bytes signature version)
67+
* @dev EOA wallet signatures should be packed in the order of r, s, v.
68+
* @param owner Token owner's address (Authorizer)
69+
* @param spender Spender's address
70+
* @param value Amount of allowance
71+
* @param deadline The time at which the signature expires (unix time), or max uint256 value to signal no
72+
* expiration
73+
* @param signature Signature byte array signed by an EOA wallet or a contract wallet
74+
*/
75+
function permit(
76+
address owner,
77+
address spender,
78+
uint256 value,
79+
uint256 deadline,
80+
bytes memory signature
81+
)
82+
public
83+
virtual
84+
{
85+
_permit(owner, spender, value, deadline, signature);
86+
}
87+
88+
/**
89+
* @notice Internal permit implementation with bytes signature
90+
* @param owner Token owner's address (Authorizer)
91+
* @param spender Spender's address
92+
* @param value Amount of allowance
93+
* @param deadline The time at which the signature expires (unix time), or max uint256 value to signal no
94+
* expiration
95+
* @param signature Signature byte array signed by an EOA wallet or a contract wallet
96+
*/
97+
function _permit(
98+
address owner,
99+
address spender,
100+
uint256 value,
101+
uint256 deadline,
102+
bytes memory signature
103+
)
104+
internal
105+
{
106+
if (deadline < block.timestamp) {
107+
revert PermitExpired();
108+
}
109+
110+
bytes32 typedDataHash = MessageHashUtils.toTypedDataHash(
111+
DOMAIN_SEPARATOR(), keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces(owner), deadline))
112+
);
113+
_incrementNonce(owner);
114+
if (!SignatureChecker.isValidSignatureNow(owner, typedDataHash, signature)) {
115+
revert InvalidPermit();
116+
}
117+
118+
_approve(owner, spender, value);
119+
}
120+
}

0 commit comments

Comments
 (0)