Skip to content

Commit

Permalink
👷🏻 Add perps to Account contract
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyrharper committed Jul 9, 2024
1 parent c6c2299 commit cef0274
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/Account.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import "@openzeppelin/contracts/utils/Create2.sol";
contract Account is IAccount {
uint256 public count;
address public owner;
address public perpsMarketSNXV3;

constructor(address _owner) {
constructor(address _owner, address _perpsMarketSNXV3) {
owner = _owner;
perpsMarketSNXV3 = _perpsMarketSNXV3;
}

function validateUserOp(
Expand All @@ -35,13 +37,19 @@ contract Account is IAccount {
}

contract AccountFactory {
address public perpsMarketSNXV3;

constructor(address _perpsMarketSNXV3) {
perpsMarketSNXV3 = _perpsMarketSNXV3;
}

function createAccount(address owner) external returns (address) {
// create2 is needed so it is deterministic and can have the gas useage confirmed by the bundler (disallowed opcodes)
// amount, salt, bytecode
bytes32 salt = bytes32(uint256(uint160(owner)));
bytes memory bytecode = abi.encodePacked(
type(Account).creationCode,
abi.encode(owner)
abi.encode(owner, perpsMarketSNXV3)
);

// dont deploy if addr already exists
Expand Down
2 changes: 1 addition & 1 deletion test/MarginPaymaster.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract MarginPaymasterTest is Bootstrap {

initializeBase();

accountFactory = new AccountFactory();
accountFactory = new AccountFactory(perpsMarketProxyAddress);
vm.deal(address(this), initialPaymasterBalance);
entryPoint.depositTo{value: initialPaymasterBalance}(
marginPaymasterAddress
Expand Down

0 comments on commit cef0274

Please sign in to comment.