Skip to content

Commit

Permalink
Update WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
richardpringle committed Apr 4, 2023
1 parent 11967e3 commit 010bbe2
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 47 deletions.
67 changes: 66 additions & 1 deletion contract-examples/contracts/ExampleFeeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import "ds-test/src/test.sol";
import "./AllowList.sol";
import "./IFeeManager.sol";

address constant FEE_MANAGER_ADDRESS = 0x0200000000000000000000000000000000000003;

// ExampleFeeManager shows how FeeManager precompile can be used in a smart contract
// All methods of [allowList] can be directly called. There are example calls as tasks in hardhat.config.ts file.
contract ExampleFeeManager is AllowList {
// Precompiled Fee Manager Contract Address
address constant FEE_MANAGER_ADDRESS = 0x0200000000000000000000000000000000000003;
IFeeManager feeManager = IFeeManager(FEE_MANAGER_ADDRESS);

struct FeeConfig {
Expand Down Expand Up @@ -99,4 +100,68 @@ contract ExampleFeeManagerTest is DSTest {

assertEq(owner, manager.owner());
}

function test_enableWAGMIFeesFailure() public {
ExampleFeeManager example = new ExampleFeeManager();

IFeeManager manager = IFeeManager(FEE_MANAGER_ADDRESS);

// TODO: make roles const (role: None = 0)
assertEq(manager.readAllowList(address(example)), 0);

try example.enableWAGMIFees() {
revert();
} catch Error(string memory) {
return;
} catch (bytes memory) {
return;
}
}

function test_addContractToManagerList() public {
ExampleFeeManager example = new ExampleFeeManager();
address exampleAddress = address(example);
// TODO: make this a const
address adminAddress = 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC;
assertEq(adminAddress, msg.sender);

address managerAddress = FEE_MANAGER_ADDRESS;

IFeeManager manager = IFeeManager(managerAddress);

// TODO: make this a const (role: ADMIN = 2)
assertEq(manager.readAllowList(msg.sender), 2);
assertEq(manager.readAllowList(exampleAddress), 0);

managerAddress.delegatecall(abi.encodeWithSelector(manager.setEnabled.selector, exampleAddress));

// TODO: make this a const (role: ENABLED = 1)
assertEq(manager.readAllowList(exampleAddress), 1);
}

function test_enableCustomFees() public {
ExampleFeeManager example = new ExampleFeeManager();
address exampleAddress = address(example);

IFeeManager manager = IFeeManager(FEE_MANAGER_ADDRESS);

FEE_MANAGER_ADDRESS.delegatecall(abi.encodeWithSelector(manager.setEnabled.selector, exampleAddress));

ExampleFeeManager.FeeConfig memory config = example.getCurrentFeeConfig();

uint256 newGasLimit = config.gasLimit + 10;
uint256 newMinBaseFee = config.minBaseFee + 10;

config.gasLimit = newGasLimit;
config.minBaseFee = newMinBaseFee;

exampleAddress.delegatecall(abi.encodeWithSelector(example.enableCustomFees.selector, config));

ExampleFeeManager.FeeConfig memory newConfig = example.getCurrentFeeConfig();

assertEq(newConfig.gasLimit, newGasLimit);
assertEq(newConfig.minBaseFee, newMinBaseFee);

assertEq(example.getFeeConfigLastChangedAt(), block.number);
}
}
53 changes: 7 additions & 46 deletions contract-examples/test/fee_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,55 +101,16 @@ describe("ExampleFeeManager", function () {
await testContract.test_addContractDeployerAsOwner()
});

it.skip("contract should not be able to change fee without enabled", async function () {
let contractRole = await managerPrecompile.readAllowList(contract.address);
expect(contractRole).to.be.equal(ROLES.NONE)
try {
let tx = await contract.enableWAGMIFees()
await tx.wait()
}
catch (err) {
return
}
expect.fail("should have errored")
})

it.skip("contract should be added to manager list", async function () {
let adminRole = await ownerPrecompile.readAllowList(adminAddress);
expect(adminRole).to.be.equal(ROLES.ADMIN)
let contractRole = await ownerPrecompile.readAllowList(contract.address);
expect(contractRole).to.be.equal(ROLES.NONE)

let enableTx = await ownerPrecompile.setEnabled(contract.address);
await enableTx.wait()
contractRole = await ownerPrecompile.readAllowList(contract.address);
expect(contractRole).to.be.equal(ROLES.ENABLED)
it("contract should not be able to change fee without enabled", async function () {
await testContract.test_enableWAGMIFeesFailure()
});

it.skip("admin should be able to change fees through contract", async function () {
const testFees = {
gasLimit: 12_345_678, // gasLimit
targetBlockRate: 2, // targetBlockRate
minBaseFee: 1_234_567, // minBaseFee
targetGas: 100_000_000, // targetGas
baseFeeChangeDenominator: 48, // baseFeeChangeDenominator
minBlockGasCost: 0, // minBlockGasCost
maxBlockGasCost: 10_000_000, // maxBlockGasCost
blockGasCostStep: 100_000 // blockGasCostStep
}
var res = await contract.getCurrentFeeConfig()
expect(res.gasLimit).to.be.not.equal(testFees.gasLimit)
expect(res.minBaseFee).to.be.not.equal(testFees.minBaseFee)

let enableTx = await contract.enableCustomFees(testFees)
let txRes = await enableTx.wait()

var res = await contract.getCurrentFeeConfig()
expect(res.gasLimit).to.be.equal(testFees.gasLimit)
expect(res.minBaseFee).to.be.equal(testFees.minBaseFee)
it("contract should be added to manager list", async function () {
await testContract.test_addContractToManagerList()
});

var res = await contract.getFeeConfigLastChangedAt()
expect(res).to.be.equal(txRes.blockNumber)
it("admin should be able to change fees through contract", async function () {
await testContract.test_enableCustomFees()
})

it.skip("admin should be able to enable wagmi fees through contract", async function () {
Expand Down

0 comments on commit 010bbe2

Please sign in to comment.