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

feat(examples): Governance Token Precompile #55

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions examples/exec-scripts/Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ gen fork_url: install-opt8n forge-updates
# Generates the execution test fixture for the weth9 precompile script
gen-weth9 fork_url: install-opt8n forge-updates
opt8n --output ../../fixtures/execution/Weth9Precompile.json --fork-url {{fork_url}} script Weth9Precompile

# Generates the execution test fixture for the governance token precompile script
gen-governance-token fork_url: install-opt8n forge-updates
opt8n --output ../../fixtures/execution/GovernanceTokenPrecompile.json --fork-url {{fork_url}} script GovernanceTokenPrecompile
37 changes: 37 additions & 0 deletions examples/exec-scripts/script/GovernanceTokenPrecompile.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Script} from "forge-std/Script.sol";
import { StdAssertions } from "forge-std/StdAssertions.sol";

interface GovernanceToken {
function name() external view returns (string memory);
function approve(address spender, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
}

/// Calls the Governance Token Precompile
contract GovernanceTokenPrecompile is Script, StdAssertions {
GovernanceToken constant TOKEN = GovernanceToken(address(0x4200000000000000000000000000000000000042));

function setUp() public {}

function run() public {
// Validation
assertEq(TOKEN.name(), "Optimism");

address spender = address(0xdeadeee);

// Check the allowance of the spender
uint256 allowance = TOKEN.allowance(msg.sender, spender);
assertEq(allowance, 0);

// Increase allowance of the spender
vm.broadcast();
TOKEN.approve(spender, 100);

// Check the allowance of the spender
allowance = TOKEN.allowance(msg.sender, spender);
assertEq(allowance, 100);
}
}
44 changes: 22 additions & 22 deletions fixtures/execution/Weth9Precompile.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"env": {
"currentCoinbase": "0x0000000000000000000000000000000000000000",
"currentDifficulty": "0x7642a519106489a25ccce64b86090c8e7db9372f32e9eda11200bd1c717f2625",
"currentDifficulty": "0x4f6a6d3433b9380ef1f0ab29f91afdc2842da78fe17b52a2ab86e1b5f9ed6c2f",
"currentGasLimit": "0x1c9c380",
"previousHash": "0xcf51399fdee5e4825ae91080390d0aa107c460e1056792ff0800ae02538825d3",
"currentNumber": "0x759ffd8",
"currentTimestamp": "0x66a7d969"
"previousHash": "0x5a0f993d31f37229f27db27c90268a12356bb442873168c9c3ea4a47257b5239",
"currentNumber": "0x75a029f",
"currentTimestamp": "0x66a7def8"
},
"alloc": {
"0x4200000000000000000000000000000000000006": {
"balance": "0x86ab06629fccad08705",
"balance": "0x86c982bf9e41e41d251",
"code": "0x6080604052600436106100bc5760003560e01c8063313ce56711610074578063a9059cbb1161004e578063a9059cbb146102cb578063d0e30db0146100bc578063dd62ed3e14610311576100bc565b8063313ce5671461024b57806370a082311461027657806395d89b41146102b6576100bc565b806318160ddd116100a557806318160ddd146101aa57806323b872dd146101d15780632e1a7d4d14610221576100bc565b806306fdde03146100c6578063095ea7b314610150575b6100c4610359565b005b3480156100d257600080fd5b506100db6103a8565b6040805160208082528351818301528351919283929083019185019080838360005b838110156101155781810151838201526020016100fd565b50505050905090810190601f1680156101425780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561015c57600080fd5b506101966004803603604081101561017357600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610454565b604080519115158252519081900360200190f35b3480156101b657600080fd5b506101bf6104c7565b60408051918252519081900360200190f35b3480156101dd57600080fd5b50610196600480360360608110156101f457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135811691602081013590911690604001356104cb565b34801561022d57600080fd5b506100c46004803603602081101561024457600080fd5b503561066b565b34801561025757600080fd5b50610260610700565b6040805160ff9092168252519081900360200190f35b34801561028257600080fd5b506101bf6004803603602081101561029957600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610709565b3480156102c257600080fd5b506100db61071b565b3480156102d757600080fd5b50610196600480360360408110156102ee57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610793565b34801561031d57600080fd5b506101bf6004803603604081101561033457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160200135166107a7565b33600081815260036020908152604091829020805434908101909155825190815291517fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c9281900390910190a2565b6000805460408051602060026001851615610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190941693909304601f8101849004840282018401909252818152929183018282801561044c5780601f106104215761010080835404028352916020019161044c565b820191906000526020600020905b81548152906001019060200180831161042f57829003601f168201915b505050505081565b33600081815260046020908152604080832073ffffffffffffffffffffffffffffffffffffffff8716808552908352818420869055815186815291519394909390927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925928290030190a350600192915050565b4790565b73ffffffffffffffffffffffffffffffffffffffff83166000908152600360205260408120548211156104fd57600080fd5b73ffffffffffffffffffffffffffffffffffffffff84163314801590610573575073ffffffffffffffffffffffffffffffffffffffff841660009081526004602090815260408083203384529091529020547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14155b156105ed5773ffffffffffffffffffffffffffffffffffffffff841660009081526004602090815260408083203384529091529020548211156105b557600080fd5b73ffffffffffffffffffffffffffffffffffffffff841660009081526004602090815260408083203384529091529020805483900390555b73ffffffffffffffffffffffffffffffffffffffff808516600081815260036020908152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060019392505050565b3360009081526003602052604090205481111561068757600080fd5b33600081815260036020526040808220805485900390555183156108fc0291849190818181858888f193505050501580156106c6573d6000803e3d6000fd5b5060408051828152905133917f7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65919081900360200190a250565b60025460ff1681565b60036020526000908152604090205481565b60018054604080516020600284861615610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190941693909304601f8101849004840282018401909252818152929183018282801561044c5780601f106104215761010080835404028352916020019161044c565b60006107a03384846104cb565b9392505050565b60046020908152600092835260408084209091529082529020548156fea265627a7a7231582091c18790e0cca5011d2518024840ee00fecc67e11f56fd746f2cf84d5b583e0064736f6c63430005110032"
},
"0xa0ee7a142d267c1f36714e4a8f75612f20a79720": {
Expand All @@ -21,15 +21,15 @@
}
},
"outAlloc": {
"0x0000000000000000000000000000000000000000": {
"balance": "0x117b08b953355564"
},
"0xa0ee7a142d267c1f36714e4a8f75612f20a79720": {
"balance": "0x21e0c0012fca42e977a",
"balance": "0x21e0c0012febdab24b2",
"nonce": 1
},
"0x0000000000000000000000000000000000000000": {
"balance": "0x117b08bb864b91a6"
},
"0x4200000000000000000000000000000000000006": {
"balance": "0x86abe46e0b072348705",
"balance": "0x86ca60cb097c5a5d251",
"storage": {
"0x6a706e96617ceafd46f24757f71aad32b88c8bf0b8ae22ec3de611582d2d4a6c": "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000"
}
Expand All @@ -41,30 +41,30 @@
"chainId": "0xa",
"nonce": "0x0",
"gasLimit": "0x10050",
"maxFeePerGas": "0x13742c",
"maxPriorityFeePerGas": "0xa52e0",
"maxFeePerGas": "0x103d91",
"maxPriorityFeePerGas": "0x71c5f",
"to": "0x4200000000000000000000000000000000000006",
"value": "0xde0b6b3a7640000",
"accessList": [],
"input": "0xd0e30db0",
"r": "0xf59b22eebd70918b8c00865574d3c50a2ea431e3b305bf1d3dbc6cd9fb5f473d",
"s": "0x4063dd1731c08ec0983dc4be06d4f134528549b08464bed5ba3f367750939ea6",
"r": "0xf7a167e8540149a29c8a44f519c78b2ff5c059d3959607df8aa8ed308c43bc3b",
"s": "0x4a2b02ea301282f4c06b9b4d6f1033b8b3978cab082a77e1185520b60acce444",
"yParity": "0x1",
"hash": "0x09f71cc85e9af7422e76d7db6d9510b85a627f5972f150a0d8727fd2f1eb6cc8"
"hash": "0xbfa05b7c2c5e50db6cf7f83469a996e1306712a17fe890e1b1e81856257b1d34"
}
}
],
"result": {
"stateRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"txRoot": "0x39195e50de80168acf9316a7ebd991daca9ca041faebe8355153c3ac5212ad89",
"txRoot": "0x90006ffb096a52c332d94153d66ae1aca204f36e2348660621ff1b80053990b6",
"receiptRoot": "0xc4b290f69c74db3a91e2758c1489a26e40885f0e07e93a5158ffbb86ddbe36c0",
"logsBloom": "0x00000000000000000000040000000000000000000000000000040000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000400000000000000000",
"receipts": [
{
"root": "0x0000000000000000000000000000000000000000000000000000000000000000",
"transactionHash": "0x09f71cc85e9af7422e76d7db6d9510b85a627f5972f150a0d8727fd2f1eb6cc8",
"transactionHash": "0xbfa05b7c2c5e50db6cf7f83469a996e1306712a17fe890e1b1e81856257b1d34",
"gasUsed": "0xaf42",
"blockHash": "0x32da196d87e53a77c0aef14839a1272afac5757efc3f99a29c90149a1000c4bb",
"blockHash": "0x62043c412f3c10da9cefcf9165211b2b35c2c69ac52731852940120128604ebb",
"transactionIndex": "0x0",
"type": "0x2",
"status": "0x1",
Expand All @@ -77,10 +77,10 @@
"0x000000000000000000000000a0ee7a142d267c1f36714e4a8f75612f20a79720"
],
"data": "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000",
"blockHash": "0x32da196d87e53a77c0aef14839a1272afac5757efc3f99a29c90149a1000c4bb",
"blockNumber": "0x759ffd8",
"blockTimestamp": "0x66a7d969",
"transactionHash": "0x09f71cc85e9af7422e76d7db6d9510b85a627f5972f150a0d8727fd2f1eb6cc8",
"blockHash": "0x62043c412f3c10da9cefcf9165211b2b35c2c69ac52731852940120128604ebb",
"blockNumber": "0x75a029f",
"blockTimestamp": "0x66a7def8",
"transactionHash": "0xbfa05b7c2c5e50db6cf7f83469a996e1306712a17fe890e1b1e81856257b1d34",
"transactionIndex": "0x0",
"logIndex": "0x0",
"removed": false
Expand Down