Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/eip 7702 #1262

Open
wants to merge 139 commits into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 134 commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
2b8d046
add: getEip7702Authorization method
borislav-itskov Jan 16, 2025
5ab8685
add: AmbireAccount7702
borislav-itskov Jan 16, 2025
ef40feb
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Jan 17, 2025
250763e
add: sign7702 implementation for the KeystoreSigner
borislav-itskov Jan 17, 2025
3b79bd9
add: test Sign eip-7702 authorization
borislav-itskov Jan 17, 2025
91a6973
add: start the Authorization sign message request
borislav-itskov Jan 17, 2025
63a5e0e
KeystoreSigner to KeystoreSignerInterface
borislav-itskov Jan 17, 2025
1871ed7
add an Authorization message type for signing and handle it in sign()…
borislav-itskov Jan 17, 2025
d386047
write a test for verifying the authorization
borislav-itskov Jan 17, 2025
28d41bd
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Jan 20, 2025
18b8ec0
make getEip7702Authorization accept an addr as a param
borislav-itskov Jan 20, 2025
122c61c
add: a banner on each EOA that can transform to EIP-7702 smarter EOA
borislav-itskov Jan 20, 2025
3937bb0
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Jan 20, 2025
b99972c
add a humanizer module for eip-7702 authorization; add authorization-…
borislav-itskov Jan 20, 2025
936441c
add: detect at account state level whether the account is a smarter EOA
borislav-itskov Jan 21, 2025
f80854a
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Jan 21, 2025
717d1bc
add: deploy script for ambire 7702 & verification
borislav-itskov Jan 22, 2025
9185968
add: an explanation in the readme on how to deploy 7702
borislav-itskov Jan 22, 2025
38fc1ef
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Jan 22, 2025
f68f29a
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Jan 22, 2025
459d1e3
Merge branch 'feature/eip-7702' of github.com:AmbireTech/ambire-commo…
borislav-itskov Jan 22, 2025
99d8ec5
add: a flag at networks level to say which network supports 7702 and …
borislav-itskov Jan 22, 2025
e80122f
make hasAuthorized7702 better - more encapsulated logic
borislav-itskov Jan 22, 2025
9c31bf1
add: pectra deploy for 7702 & the addr of the deployed 7702
borislav-itskov Jan 22, 2025
730fd60
move PECTRA_7702 to its own 7702 file
borislav-itskov Jan 22, 2025
edb53f6
add: the odyssey network to 7702 config
borislav-itskov Jan 23, 2025
b8b161e
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Jan 23, 2025
af33379
add: a bundler estimate request for 7702; authorization in account st…
borislav-itskov Jan 23, 2025
3f6daac
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Jan 23, 2025
8758cce
make 7702 estimation reach the bundler estimation
borislav-itskov Jan 23, 2025
e55c3fb
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Jan 23, 2025
e5816cb
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Jan 23, 2025
99709f0
add: first successfull estimate for pimlico 7702 with current contract
borislav-itskov Jan 23, 2025
8c24c42
changes to AmbireAccount7702 to allow sending from entry point
borislav-itskov Jan 23, 2025
5714d2b
the ambire 7702 contract
borislav-itskov Jan 24, 2025
e26cbac
privilegeLevel to return bytes32
borislav-itskov Jan 24, 2025
fa164db
newets ambire 7702 acc
borislav-itskov Jan 24, 2025
1ccc2d9
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Jan 24, 2025
5302c28
add: new pimlico schema for 7702
borislav-itskov Jan 24, 2025
ba86d8d
fix: discrepancy nonce failure because of state overrides
borislav-itskov Jan 24, 2025
daba0ab
configure 7702 broadcast
borislav-itskov Jan 24, 2025
3ea511a
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Jan 25, 2025
b89840f
add: ambire storage to 7702 contract to prevent conflicts
borislav-itskov Jan 25, 2025
d7b6910
add: odyssey test network correct 7702 addr
borislav-itskov Jan 27, 2025
0e74e32
correct account state for delegated EOAs; new 7702 contract
borislav-itskov Jan 27, 2025
54652a9
correct 7702 broadcast
borislav-itskov Jan 27, 2025
c6b5d5e
Merge branch 'feature/eip-7702' of github.com:AmbireTech/ambire-commo…
borislav-itskov Jan 27, 2025
921b82e
fix: an account state bug that marked the deploy as failure because o…
borislav-itskov Jan 27, 2025
69ba195
Merge branch 'feature/eip-7702' of github.com:AmbireTech/ambire-commo…
borislav-itskov Jan 27, 2025
945438e
fix: once delegation is complete, return the SA nonce as nonce in the…
borislav-itskov Jan 27, 2025
c00ded9
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Jan 27, 2025
2ca39f2
allow EOA txn batching
borislav-itskov Jan 28, 2025
9694513
resolve conflicts with v2
borislav-itskov Jan 28, 2025
1f6f1b4
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Jan 29, 2025
f4a6996
getEip7702Authorization to getAuthorizationHash; fix an issue with 0 …
borislav-itskov Jan 29, 2025
2056814
add: affectedNetworks to Authorization
borislav-itskov Jan 29, 2025
d099f5f
add addPreUserRequestIfAny method in main to keep all user actions th…
borislav-itskov Jan 29, 2025
afea999
handle signMessage callbacks: entry point auth or 7702 auth
borislav-itskov Jan 29, 2025
12024cf
add the BA authorization only if the account can actually become smarter
borislav-itskov Jan 29, 2025
cdf84a4
make basic tests work with the new AmbireAccount
borislav-itskov Jan 30, 2025
b45f9e4
Merge branch 'feature/eip-7702' of github.com:AmbireTech/ambire-commo…
borislav-itskov Jan 30, 2025
fb36985
complete getExecute712Hash for seeing calls in EIP-712 format
borislav-itskov Jan 30, 2025
9b3ac34
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
Jan 31, 2025
b731e2a
fix: basic execute tests for new AmbireAccount
Jan 31, 2025
23b2c0f
make validateUserOp work with EIP-712 that displays a lot of info to …
Feb 3, 2025
4bd24de
rewrite the contract tests so they work with the latest version of th…
borislav-itskov Feb 3, 2025
ca74902
merge v2
borislav-itskov Feb 3, 2025
81b1a2a
latest ambire 7702
borislav-itskov Feb 3, 2025
13fc244
rejecting the authorization should allow the user to broadcast in EOA…
borislav-itskov Feb 3, 2025
94e358f
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Feb 3, 2025
0b72dbd
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Feb 4, 2025
96f5580
delete a var in AmbireAccount.sol because it's not needed
borislav-itskov Feb 4, 2025
324a015
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Feb 4, 2025
41d8449
remove fetching of account state in buildUserReq from dapp as the use…
borislav-itskov Feb 4, 2025
e7db5e0
resolve conflicts with develop
borislav-itskov Feb 4, 2025
8fa9207
remove callData from hash commitment as we have the calls there; fix …
borislav-itskov Feb 4, 2025
4c5a4c1
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Feb 5, 2025
dfa29e5
implement a 7702 flag that will stop asking the user if he wants to m…
borislav-itskov Feb 5, 2025
b7f59f0
add: callData and a decode for execute(); code does not revert on any…
borislav-itskov Feb 5, 2025
ec2e2ca
Merge branch 'feature/eip-7702' of github.com:AmbireTech/ambire-commo…
borislav-itskov Feb 5, 2025
33da16e
make the banner for 7702 lead to a account specific page for 7702
borislav-itskov Feb 5, 2025
ba623a0
7702 banner improvements; hide banner if disabled for wallet
borislav-itskov Feb 5, 2025
70e1978
make the 7702 disable option per account
borislav-itskov Feb 5, 2025
15a898c
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Feb 5, 2025
01652ac
add an option to disable the 7702 banner; change place where we keep …
borislav-itskov Feb 6, 2025
91c5930
add a script to deploy the singleton on odyssey net
borislav-itskov Feb 7, 2025
3ed6b20
newest 7702 contract + deploy on testnet
borislav-itskov Feb 7, 2025
b71ec1d
the authrorization is valid only if the impl contract is our
borislav-itskov Feb 10, 2025
e31bed9
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Feb 10, 2025
d533b31
use the sender from the user op as a verifying address
borislav-itskov Feb 10, 2025
aa68b13
enable odyssey hardhat verification
borislav-itskov Feb 10, 2025
0da9399
add: a 7702 user operation request type and sign 7702 user op
borislav-itskov Feb 10, 2025
881a53d
resolve conflicts
borislav-itskov Feb 10, 2025
3565e56
fix: make 7702 work with the latest contract
borislav-itskov Feb 10, 2025
3cb8ecd
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Feb 10, 2025
a4c1a2a
latest package.lock json
borislav-itskov Feb 10, 2025
04eca4c
delete a hardhat test for a non-existent contract
borislav-itskov Feb 10, 2025
d4cf336
fix some of the broken unit tests because of outdated interfaces
borislav-itskov Feb 10, 2025
8b8eab5
fix: different error message texts for insufficient native errors; sk…
borislav-itskov Feb 10, 2025
0895d7d
disable 7702 for most networks; banner improvements; authorization 77…
borislav-itskov Feb 10, 2025
cde081d
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Feb 10, 2025
7029275
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Feb 11, 2025
51a51b4
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Feb 11, 2025
bf9f951
latest v2
borislav-itskov Feb 11, 2025
cac79b2
add: features controller to determine which feature is active and whi…
borislav-itskov Feb 12, 2025
82ba2cd
resolve conflicts with v2
borislav-itskov Feb 12, 2025
c71c467
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Feb 13, 2025
4b41519
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Feb 13, 2025
4e0f57a
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Feb 14, 2025
e74cded
Refactor: make sure to enable when "true"
superKalo Feb 14, 2025
547fc9e
Refactor: prop re-use
superKalo Feb 14, 2025
4cc14e0
add: make swap&bridge work with 7702 eoa; make portfolio state overri…
borislav-itskov Feb 14, 2025
ec03c47
Merge branch 'feature/eip-7702' of github.com:AmbireTech/ambire-commo…
borislav-itskov Feb 14, 2025
dd970a2
fix portfolio lib tests
borislav-itskov Feb 14, 2025
574958a
fix: portfolio controller tests
borislav-itskov Feb 14, 2025
774d86d
pass undefined for accountOp instead of a empty object when there are…
borislav-itskov Feb 17, 2025
de88e26
fix: contracts wrong comments and spacing
borislav-itskov Feb 17, 2025
c882d34
Refactor: refine the feature flags controller set-up
superKalo Feb 17, 2025
c961507
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Feb 17, 2025
5fa079d
Merge branch 'feature/eip-7702' of github.com:AmbireTech/ambire-commo…
borislav-itskov Feb 17, 2025
d5da88e
add: Ambire erc 20 deploy script + contract; add it to the gas tank o…
borislav-itskov Feb 17, 2025
2b3c33c
get prices and icons for odyssey
borislav-itskov Feb 17, 2025
e72b90f
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Feb 17, 2025
de8f3cf
account that use the paymaster may not have a creation anymore
borislav-itskov Feb 18, 2025
1b0f580
fix: make eip7702Auth into eip7702auth
borislav-itskov Feb 18, 2025
f40ecb1
add: eip7702auth to getUserOperation() function if available, removin…
borislav-itskov Feb 18, 2025
2a1dc1d
resolve conflicts with v2
borislav-itskov Feb 18, 2025
d64f584
resolve conflcits
borislav-itskov Feb 19, 2025
f12c6f3
disable odyssey tokens for top up
borislav-itskov Feb 19, 2025
e307397
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Feb 19, 2025
b41b92a
use the paymaster request url instead of the sign as the request work…
borislav-itskov Feb 19, 2025
ae7c300
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Feb 19, 2025
7a31fb9
add: a missing 7702 prop to network initializer
borislav-itskov Feb 20, 2025
f39d729
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Feb 20, 2025
797752b
add: a temp solution to paymaster factory / paymaster.ts that users d…
borislav-itskov Feb 20, 2025
3081d76
start fixing post reject handlign of authorization
borislav-itskov Feb 21, 2025
9cc81f4
resolve conflicts
borislav-itskov Feb 21, 2025
2f75881
fix bugs with sign account op window closing at strange times after a…
borislav-itskov Feb 21, 2025
e0a4c35
Merge branch 'v2' of github.com:AmbireTech/ambire-common into feature…
borislav-itskov Feb 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@ yarn generate:contractInfo
## Editor Config

Make sure your code editor has plugins that support the following configuration files: `.editorconfig`, `.prettierrc`, `tsconfig.json`, `eslintrc.js`, [`import-sorter.json`](https://github.com/SoominHan/import-sorter).

## Deploy scripts

How to deploy Ambire 7702:

- npx hardhat compile
- npx hardhat run scripts/deploy7702.js --network optimism
- npx hardhat verify --network optimism 0xfe77D030Ac0531f5A62bAe502712b1F1cf976DD9
62 changes: 42 additions & 20 deletions contracts/AmbireAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import './ExternalSigValidator.sol';
import './libs/erc4337/PackedUserOperation.sol';
import './libs/erc4337/UserOpHelper.sol';
import './deployless/IAmbireAccount.sol';
import './libs/Eip712HashBuilder.sol';

/**
* @notice A validator that performs DKIM signature recovery
Expand All @@ -20,14 +21,12 @@ contract AmbireAccount is IAmbireAccount {
address private constant FALLBACK_HANDLER_SLOT = address(0x6969);

// @dev This is how we understand if msg.sender is the entry point
bytes32 private constant ENTRY_POINT_MARKER = 0x0000000000000000000000000000000000000000000000000000000000007171;
bytes32 constant ENTRY_POINT_MARKER = 0x0000000000000000000000000000000000000000000000000000000000007171;

// Externally validated signatures
uint8 private constant SIGMODE_EXTERNALLY_VALIDATED = 255;

// Variables
mapping(address => bytes32) public privileges;
uint256 public nonce;
bytes32 constant AMBIRE_STORAGE_POSITION = keccak256("ambire.smart.contracts.storage");

// Events
event LogPrivilegeChanged(address indexed addr, bytes32 priv);
Expand Down Expand Up @@ -73,7 +72,7 @@ contract AmbireAccount is IAmbireAccount {
*/
fallback() external payable {
// We store the fallback handler at this magic slot
address fallbackHandler = address(uint160(uint(privileges[FALLBACK_HANDLER_SLOT])));
address fallbackHandler = address(uint160(uint(privileges(FALLBACK_HANDLER_SLOT))));
if (fallbackHandler == address(0)) return;
assembly {
// we can use addr 0 because logic is taking full control of the
Expand All @@ -90,6 +89,21 @@ contract AmbireAccount is IAmbireAccount {
}
}

function getAmbireStorage() internal pure returns (AmbireStorage storage ds) {
bytes32 position = AMBIRE_STORAGE_POSITION;
assembly {
ds.slot := position
}
}

function nonce() external view returns (uint256) {
return getAmbireStorage().nonce;
}

function privileges(address key) public virtual view returns (bytes32) {
return getAmbireStorage().privileges[key];
}

/**
* @notice used to set the privilege of a key (by `addr`)
* @dev normal signatures will be considered valid if the
Expand All @@ -100,7 +114,7 @@ contract AmbireAccount is IAmbireAccount {
*/
function setAddrPrivilege(address addr, bytes32 priv) external payable {
require(msg.sender == address(this), 'ONLY_ACCOUNT_CAN_CALL');
privileges[addr] = priv;
getAmbireStorage().privileges[addr] = priv;
emit LogPrivilegeChanged(addr, priv);
}

Expand Down Expand Up @@ -144,9 +158,9 @@ contract AmbireAccount is IAmbireAccount {
function execute(Transaction[] calldata calls, bytes calldata signature) public payable {
address signerKey;
uint8 sigMode = uint8(signature[signature.length - 1]);
uint256 currentNonce = nonce;
uint256 currentNonce = getAmbireStorage().nonce;
// we increment the nonce here (not using `nonce++` to save some gas)
nonce = currentNonce + 1;
getAmbireStorage().nonce = currentNonce + 1;

if (sigMode == SIGMODE_EXTERNALLY_VALIDATED) {
bool isValidSig;
Expand All @@ -157,18 +171,22 @@ contract AmbireAccount is IAmbireAccount {
revert('SIGNATURE_VALIDATION_FAIL');
}
} else {
signerKey = SignatureValidator.recoverAddr(
keccak256(abi.encode(address(this), block.chainid, currentNonce, calls)),
(signerKey, ) = SignatureValidator.recoverAddrAllowUnprotected(
Eip712HashBuilder.getExecute712Hash(
currentNonce,
calls,
keccak256(abi.encode(address(this), block.chainid, currentNonce, calls))
),
signature,
true
);
require(privileges[signerKey] != bytes32(0), 'INSUFFICIENT_PRIVILEGE');
require(privileges(signerKey) != bytes32(0), 'INSUFFICIENT_PRIVILEGE');
}

executeBatch(calls);

// The actual anti-bricking mechanism - do not allow a signerKey to drop their own privileges
require(privileges[signerKey] != bytes32(0), 'PRIVILEGE_NOT_DOWNGRADED');
require(privileges(signerKey) != bytes32(0), 'PRIVILEGE_NOT_DOWNGRADED');
}

/**
Expand All @@ -185,10 +203,10 @@ contract AmbireAccount is IAmbireAccount {
* @param calls the transaction we're executing
*/
function executeBySender(Transaction[] calldata calls) external payable {
require(privileges[msg.sender] != bytes32(0), 'INSUFFICIENT_PRIVILEGE');
require(privileges(msg.sender) != bytes32(0), 'INSUFFICIENT_PRIVILEGE');
executeBatch(calls);
// again, anti-bricking
require(privileges[msg.sender] != bytes32(0), 'PRIVILEGE_NOT_DOWNGRADED');
require(privileges(msg.sender) != bytes32(0), 'PRIVILEGE_NOT_DOWNGRADED');
}

/**
Expand Down Expand Up @@ -253,7 +271,7 @@ contract AmbireAccount is IAmbireAccount {
*/
function isValidSignature(bytes32 hash, bytes calldata signature) external view returns (bytes4) {
(address recovered, bool usedUnprotected) = SignatureValidator.recoverAddrAllowUnprotected(hash, signature, false);
if (uint256(privileges[recovered]) > (usedUnprotected ? 1 : 0)) {
if (uint256(privileges(recovered)) > (usedUnprotected ? 1 : 0)) {
// bytes4(keccak256("isValidSignature(bytes32,bytes)")
return 0x1626ba7e;
} else {
Expand All @@ -273,7 +291,7 @@ contract AmbireAccount is IAmbireAccount {
interfaceID == 0x4e2312e0 || // ERC-1155 `ERC1155TokenReceiver` support (i.e. `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)")) ^ bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`).
interfaceID == 0x0a417632; // used for checking whether the account is v2 or not
if (supported) return true;
address payable fallbackHandler = payable(address(uint160(uint256(privileges[FALLBACK_HANDLER_SLOT]))));
address payable fallbackHandler = payable(address(uint160(uint256(privileges(FALLBACK_HANDLER_SLOT)))));
if (fallbackHandler == address(0)) return false;
return AmbireAccount(fallbackHandler).supportsInterface(interfaceID);
}
Expand Down Expand Up @@ -335,7 +353,7 @@ contract AmbireAccount is IAmbireAccount {
return SIG_VALIDATION_SUCCESS;
}

require(privileges[msg.sender] == ENTRY_POINT_MARKER, 'validateUserOp: not from entryPoint');
require(privileges(msg.sender) == ENTRY_POINT_MARKER, 'validateUserOp: not from entryPoint');

// @estimation
// paying should happen even if signature validation fails
Expand All @@ -347,8 +365,12 @@ contract AmbireAccount is IAmbireAccount {
}

// this is replay-safe because userOpHash is retrieved like this: keccak256(abi.encode(userOp.hash(), address(this), block.chainid))
address signer = SignatureValidator.recoverAddr(userOpHash, op.signature, true);
if (privileges[signer] == bytes32(0)) return SIG_VALIDATION_FAILED;
(address signer, ) = SignatureValidator.recoverAddrAllowUnprotected(
Eip712HashBuilder.getUserOp712Hash(op, userOpHash),
op.signature,
true
);
if (privileges(signer) == bytes32(0)) return SIG_VALIDATION_FAILED;

return SIG_VALIDATION_SUCCESS;
}
Expand Down Expand Up @@ -377,7 +399,7 @@ contract AmbireAccount is IAmbireAccount {
// the privileges key
(signerKey, validatorAddr, validatorData, innerSig) = abi.decode(sig, (address, address, bytes, bytes));
require(
privileges[signerKey] == keccak256(abi.encode(validatorAddr, validatorData)),
privileges(signerKey) == keccak256(abi.encode(validatorAddr, validatorData)),
'EXTERNAL_VALIDATION_NOT_SET'
);

Expand Down
24 changes: 24 additions & 0 deletions contracts/AmbireAccount7702.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.19;

import './AmbireAccount.sol';

/**
* @notice A contract that extends AmbireAccount to make it 7702 adaptable
* @dev We hardcode the entry point address so we don't have to use
* any storage slots after authorization. If it changes, the users
* will have to authrorize another contract with the new entry point addr
* to continue
*/
contract AmbireAccount7702 is AmbireAccount {
address private constant ENTRY_POINT = address(0x0000000071727De22E5E9d8BAf0edAc6f37da032);

function privileges(address key) public override view returns (bytes32) {
if (key == address(this)) return bytes32(uint256(2));

// if the entry point is the sender, we return the marker priv
if (key == ENTRY_POINT) return ENTRY_POINT_MARKER;

return getAmbireStorage().privileges[key];
}
}
27 changes: 27 additions & 0 deletions contracts/AmbireToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.19;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract AmbireToken is ERC20 {
mapping (address => uint) lastMint;

uint256 public constant WAIT_TIME = 24 hours;

uint256 public constant MINT_AMOUNT = 5 * 10 ** 18;

constructor(uint256 initialSupply) ERC20("Ambire", "AMW") {
_mint(msg.sender, initialSupply);
}

function mint() public {
require(
block.timestamp >= lastMint[msg.sender] + WAIT_TIME,
"Wait 24 hours before minting again"
);

lastMint[msg.sender] = block.timestamp;

_mint(msg.sender, MINT_AMOUNT);
}
}
Loading