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: OLAS burner contract #159

Merged
merged 1 commit into from
Oct 28, 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
70 changes: 70 additions & 0 deletions abis/0.8.28/Burner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "Burner",
"sourceName": "contracts/Burner.sol",
"abi": [
{
"inputs": [
{
"internalType": "address",
"name": "_olas",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "ReentrancyGuard",
"type": "error"
},
{
"inputs": [],
"name": "ZeroAddress",
"type": "error"
},
{
"inputs": [],
"name": "ZeroValue",
"type": "error"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "Burned",
"type": "event"
},
{
"inputs": [],
"name": "burn",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "olas",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
}
],
"bytecode": "0x60a060405260015f55348015610013575f5ffd5b5060405161039e38038061039e8339810160408190526100329161006a565b6001600160a01b0381166100595760405163d92e233d60e01b815260040160405180910390fd5b6001600160a01b0316608052610097565b5f6020828403121561007a575f5ffd5b81516001600160a01b0381168114610090575f5ffd5b9392505050565b6080516102e26100bc5f395f8181603c0152818161010101526101e901526102e25ff3fe608060405234801561000f575f5ffd5b5060043610610033575f3560e01c806231d1151461003757806344df8e7014610087575b5f5ffd5b61005e7f000000000000000000000000000000000000000000000000000000000000000081565b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200160405180910390f35b61008f610091565b005b60015f5411156100cd576040517f8beb9d1600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60025f9081556040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201527f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16906370a0823190602401602060405180830381865afa15801561015b573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061017f9190610295565b9050805f036101ba576040517f7c946ed700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f42966c68000000000000000000000000000000000000000000000000000000008152600481018290527f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16906342966c68906024015f604051808303815f87803b15801561023f575f5ffd5b505af1158015610251573d5f5f3e3d5ffd5b505050507fd83c63197e8e676d80ab0122beba9a9d20f3828839e9a1d6fe81d242e9cd7e6e8160405161028691815260200190565b60405180910390a15060015f55565b5f602082840312156102a5575f5ffd5b505191905056fea264697066735822122081e9dea49c6f1f8ecd56cd03169c0ccbd30c2383dc8d4434d17aa7b5b3b6f1e264736f6c634300081c0033",
"deployedBytecode": "0x608060405234801561000f575f5ffd5b5060043610610033575f3560e01c806231d1151461003757806344df8e7014610087575b5f5ffd5b61005e7f000000000000000000000000000000000000000000000000000000000000000081565b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200160405180910390f35b61008f610091565b005b60015f5411156100cd576040517f8beb9d1600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60025f9081556040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201527f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16906370a0823190602401602060405180830381865afa15801561015b573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061017f9190610295565b9050805f036101ba576040517f7c946ed700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f42966c68000000000000000000000000000000000000000000000000000000008152600481018290527f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16906342966c68906024015f604051808303815f87803b15801561023f575f5ffd5b505af1158015610251573d5f5f3e3d5ffd5b505050507fd83c63197e8e676d80ab0122beba9a9d20f3828839e9a1d6fe81d242e9cd7e6e8160405161028691815260200190565b60405180910390a15060015f55565b5f602082840312156102a5575f5ffd5b505191905056fea264697066735822122081e9dea49c6f1f8ecd56cd03169c0ccbd30c2383dc8d4434d17aa7b5b3b6f1e264736f6c634300081c0033",
"linkReferences": {},
"deployedLinkReferences": {}
}
66 changes: 66 additions & 0 deletions contracts/Burner.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

interface IToken {
/// @dev Gets the amount of tokens owned by a specified account.
/// @param account Account address.
/// @return Amount of tokens owned.
function balanceOf(address account) external view returns (uint256);

/// @dev Burns tokens.
/// @param amount Token amount to burn.
function burn(uint256 amount) external;
}

/// @dev Provided zero address.
error ZeroAddress();

/// @dev Provided value provided.
error ZeroValue();

/// @dev Caught reentrancy violation.
error ReentrancyGuard();

/// @title Burner - Smart contract for burning OLAS token.
contract Burner {
event Burned(uint256 amount);

// OLAS address
address public immutable olas;

Check warning on line 29 in contracts/Burner.sol

View workflow job for this annotation

GitHub Actions / build

Immutable variables name are set to be in capitalized SNAKE_CASE
// Reentrancy lock
uint256 internal _locked = 1;

/// @dev Burner constructor.
/// @param _olas OLAS address.
constructor(address _olas) {
if (_olas == address(0)) {
revert ZeroAddress();
}

olas = _olas;
}

/// @dev Burns OLAS tokens owned by this contract.
function burn() external {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/valory-xyz/autonolas-governance/blob/main/contracts/OLAS.sol#L118
What is the meaning of this contract, anyone can call this function for themselves.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

// Reentrancy guard
if (_locked > 1) {
revert ReentrancyGuard();
}
_locked = 2;

// Get OLAS balance
uint256 olasBalance = IToken(olas).balanceOf(address(this));

// Check for zero value
if (olasBalance == 0) {
revert ZeroValue();
}

// Burn tokens
IToken(olas).burn(olasBalance);

emit Burned(olasBalance);

_locked = 1;
}
}
8 changes: 4 additions & 4 deletions scripts/audit_chains/audit_contracts_setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,19 +513,19 @@ async function main() {

const initLog = "ChainId: " + configs[i]["chainId"] + ", network: " + configs[i]["name"];

if (configs[i]["chainId"] == "137" || configs[i]["chainId"] == "80001") {
if (configs[i]["chainId"] == "137") {
let log = initLog + ", contract: " + "FxGovernorTunnel";
await checkFxGovernorTunnel(configs[i]["chainId"], providers[i], globals[i], configs[i]["contracts"], "FxGovernorTunnel", log);

log = initLog + ", contract: " + "FxERC20ChildTunnel";
await checkFxERC20ChildTunnel(configs[i]["chainId"], providers[i], globals[i], configs[i]["contracts"], "FxERC20ChildTunnel", log);
} else if (configs[i]["chainId"] == "100" || configs[i]["chainId"] == "10200") {
} else if (configs[i]["chainId"] == "100") {
let log = initLog + ", contract: " + "HomeMediator";
await checkHomeMediator(configs[i]["chainId"], providers[i], globals[i], configs[i]["contracts"], "HomeMediator", log);
} else if (configs[i]["chainId"] == "10" || configs[i]["chainId"] == "11155420" || configs[i]["chainId"] == "8453" || configs[i]["chainId"] == "84532" || configs[i]["chainId"] == "34443") {
} else if (configs[i]["chainId"] == "10" || configs[i]["chainId"] == "8453" || configs[i]["chainId"] == "34443") {
let log = initLog + ", contract: " + "OptimismMessenger";
await checkOptimismMessenger(configs[i]["chainId"], providers[i], globals[i], configs[i]["contracts"], "OptimismMessenger", log);
} else if (configs[i]["chainId"] == "42220" || configs[i]["chainId"] == "44787") {
} else if (configs[i]["chainId"] == "42220") {
let log = initLog + ", contract: " + "WormholeMessenger";
await checkWormholeMessenger(configs[i]["chainId"], providers[i], globals[i], configs[i]["contracts"], "WormholeMessenger", log);
}
Expand Down
62 changes: 62 additions & 0 deletions scripts/deployment/deploy_24_burner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*global process*/

const { expect } = require("chai");

Check warning on line 3 in scripts/deployment/deploy_24_burner.js

View workflow job for this annotation

GitHub Actions / build

'expect' is assigned a value but never used
const { ethers } = require("hardhat");
const { LedgerSigner } = require("@anders-t/ethers-ledger");

async function main() {
const fs = require("fs");
const globalsFile = "globals.json";
const dataFromJSON = fs.readFileSync(globalsFile, "utf8");
let parsedData = JSON.parse(dataFromJSON);
const derivationPath = parsedData.derivationPath;
const useLedger = parsedData.useLedger;
const providerName = parsedData.providerName;
let EOA;

const provider = await ethers.providers.getDefaultProvider(providerName);
const signers = await ethers.getSigners();

if (useLedger) {
EOA = new LedgerSigner(provider, derivationPath);
} else {
EOA = signers[0];
}
// EOA address
const deployer = await EOA.getAddress();
console.log("EOA is:", deployer);

// Transaction signing and execution
console.log("24. EOA to deploy Burner contract pointed to OLAS");
const Burner = await ethers.getContractFactory("Burner");
console.log("You are signing the following transaction: Burner.connect(EOA).deploy(OLAS)");
const burner = await Burner.connect(EOA).deploy(parsedData.olasAddress);
const result = await burner.deployed();

// Transaction details
console.log("Contract deployment: burner");
console.log("Contract address:", burner.address);
console.log("Transaction:", result.deployTransaction.hash);

// If on sepolia, wait half a minute for the transaction completion
if (providerName === "sepolia") {
await new Promise(r => setTimeout(r, 30000));
}

// Contract verification
if (parsedData.contractVerification) {
const execSync = require("child_process").execSync;
execSync("npx hardhat verify --constructor-args scripts/deployment/verify_24_burner.js --network " + providerName + " " + burner.address, { encoding: "utf-8" });
}

// Writing updated parameters back to the JSON file
parsedData.burnerAddress = burner.address;
fs.writeFileSync(globalsFile, JSON.stringify(parsedData));
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
8 changes: 8 additions & 0 deletions scripts/deployment/verify_24_burner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const fs = require("fs");
const globalsFile = "globals.json";
const dataFromJSON = fs.readFileSync(globalsFile, "utf8");
const parsedData = JSON.parse(dataFromJSON);

module.exports = [
parsedData.olasAddress
];
Loading