Skip to content

Commit

Permalink
👷🏻 Create MarginPaymaster
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyrharper committed Jul 1, 2024
1 parent a158f00 commit 08a3a71
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 46 deletions.
6 changes: 3 additions & 3 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import {OptimismGoerliParameters} from
import {OptimismParameters} from
"script/utils/parameters/OptimismParameters.sol";
import {Script} from "lib/forge-std/src/Script.sol";
import {Counter} from "src/Counter.sol";
import {MarginPaymaster} from "src/MarginPaymaster.sol";

/// @title Kwenta deployment script
/// @author JaredBorders ([email protected])
contract Setup is Script {
function deploySystem() public returns (address) {
Counter counter = new Counter();
return address(counter);
MarginPaymaster marginPaymaster = new MarginPaymaster();
return address(marginPaymaster);
}
}

Expand Down
17 changes: 0 additions & 17 deletions src/Counter.sol

This file was deleted.

13 changes: 13 additions & 0 deletions src/MarginPaymaster.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.25;

/// @title Kwenta Paymaster Contract
/// @notice Responsible for paying tx gas fees using trader margin
/// @author tommyrharper ([email protected])
contract MarginPaymaster {
uint256 public number;

function increment() public {
number++;
}
}
15 changes: 3 additions & 12 deletions test/Counter.t.sol → test/MarginPaymaster.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,17 @@ pragma solidity 0.8.25;

import {Bootstrap} from "test/utils/Bootstrap.sol";

contract CounterTest is Bootstrap {
contract MarginPaymasterTest is Bootstrap {
function setUp() public {
/// @dev uncomment the following line to test in a forked environment
/// at a specific block number
// vm.rollFork(NETWORK_BLOCK_NUMBER);

initializeOptimismGoerli();
}
}

contract Increment is CounterTest {
function testIncrement() public {
counter.increment();
assertEq(counter.number(), 1);
}
}

contract SetNumber is CounterTest {
function testSetNumber(uint256 x) public {
counter.setNumber(x);
assertEq(counter.number(), x);
marginPaymaster.increment();
assertEq(marginPaymaster.number(), 1);
}
}
28 changes: 14 additions & 14 deletions test/utils/Bootstrap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.25;

import {console2} from "lib/forge-std/src/console2.sol";
import {
Counter,
MarginPaymaster,
OptimismGoerliParameters,
OptimismParameters,
Setup
Expand All @@ -13,53 +13,53 @@ import {Test} from "lib/forge-std/src/Test.sol";
contract Bootstrap is Test {
using console2 for *;

Counter internal counter;
MarginPaymaster internal marginPaymaster;

function initializeLocal() internal {
BootstrapLocal bootstrap = new BootstrapLocal();
(address counterAddress) = bootstrap.init();
(address marginPaymasterAddress) = bootstrap.init();

counter = Counter(counterAddress);
marginPaymaster = MarginPaymaster(marginPaymasterAddress);
}

function initializeOptimismGoerli() internal {
BootstrapOptimismGoerli bootstrap = new BootstrapOptimismGoerli();
(address counterAddress) = bootstrap.init();
(address marginPaymasterAddress) = bootstrap.init();

counter = Counter(counterAddress);
marginPaymaster = MarginPaymaster(marginPaymasterAddress);
}

function initializeOptimism() internal {
BootstrapOptimismGoerli bootstrap = new BootstrapOptimismGoerli();
(address counterAddress) = bootstrap.init();
(address marginPaymasterAddress) = bootstrap.init();

counter = Counter(counterAddress);
marginPaymaster = MarginPaymaster(marginPaymasterAddress);
}

/// @dev add other networks here as needed (ex: Base, BaseGoerli)
}

contract BootstrapLocal is Setup {
function init() public returns (address) {
address counterAddress = Setup.deploySystem();
address marginPaymasterAddress = Setup.deploySystem();

return counterAddress;
return marginPaymasterAddress;
}
}

contract BootstrapOptimism is Setup, OptimismParameters {
function init() public returns (address) {
address counterAddress = Setup.deploySystem();
address marginPaymasterAddress = Setup.deploySystem();

return counterAddress;
return marginPaymasterAddress;
}
}

contract BootstrapOptimismGoerli is Setup, OptimismGoerliParameters {
function init() public returns (address) {
address counterAddress = Setup.deploySystem();
address marginPaymasterAddress = Setup.deploySystem();

return counterAddress;
return marginPaymasterAddress;
}
}

Expand Down

0 comments on commit 08a3a71

Please sign in to comment.