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

1623-king-proxy-contract #1624

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
49 changes: 49 additions & 0 deletions contracts/KingERC20BridgeProxyContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
pragma solidity ^0.6.0;

import "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "./interfaces/IERC20BridgeProxy.sol";
import "./Promos.sol";


contract KingERC20BridgeProxyContract is Initializable, AccessControlUpgradeable, IERC20BridgeProxy {

bytes32 public constant GAME_ADMIN = keccak256("GAME_ADMIN");

Promos public promos;
bool enabled;

modifier restricted() {
_restricted();
_;
}

function _restricted() internal view {
require(hasRole(GAME_ADMIN, msg.sender) || hasRole(DEFAULT_ADMIN_ROLE, msg.sender), "NA");
}

function initialize(Promos _promos) public initializer {
__AccessControl_init();

_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);

promos = _promos;
}

// for future use, bot will probe the returned value to know if the proxy contract has proper signature behavior
function sigVersion() external view override returns (uint256) {
return 1;
}

function isEnabled() external view override returns (bool) {
return enabled;
}

function setEnabled(bool _enabled) external restricted {
enabled = _enabled;
}

function canBridge(address wallet, uint256 amount, uint256 targetChain) external view override returns (bool) {
return promos.getBit(msg.sender, promos.BIT_BAD_ACTOR()) == false;
}
}
10 changes: 10 additions & 0 deletions migrations/187_king_erc20_proxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { upgradeProxy, deployProxy } = require("@openzeppelin/truffle-upgrades");

const KingERC20BridgeProxyContract = artifacts.require("KingERC20BridgeProxyContract");
const Promos = artifacts.require("Promos");

module.exports = async function (deployer, network) {

let promos = await Promos.deployed();
await deployProxy(KingERC20BridgeProxyContract, [promos.address], { deployer });
};