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: arbitrum deployment script #443

Closed
wants to merge 11 commits into from
Closed
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
5 changes: 5 additions & 0 deletions contracts/core/AddressBook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ contract AddressBook is Ownable {
/// @notice emits an event when a new address is added
event AddressAdded(bytes32 indexed id, address indexed add);

event WhitelistUpdated(address whitelist);
event OtokenImplUpdated(address implementation);

/**
* @notice return Otoken implementation address
* @return Otoken implementation address
Expand Down Expand Up @@ -107,6 +110,7 @@ contract AddressBook is Ownable {
*/
function setOtokenImpl(address _otokenImpl) external onlyOwner {
setAddress(OTOKEN_IMPL, _otokenImpl);
emit OtokenImplUpdated(_otokenImpl);
}

/**
Expand All @@ -125,6 +129,7 @@ contract AddressBook is Ownable {
*/
function setWhitelist(address _whitelist) external onlyOwner {
setAddress(WHITELIST, _whitelist);
emit WhitelistUpdated(_whitelist);
}

/**
Expand Down
23 changes: 23 additions & 0 deletions contracts/core/Otoken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ contract Otoken is ERC20PermitUpgradeable {
uint256 private constant STRIKE_PRICE_SCALE = 1e8;
uint256 private constant STRIKE_PRICE_DIGITS = 8;

event OTokenInitiated(
string name,
string symbol,
address indexed underlying,
address indexed strike,
address indexed collateral,
uint256 strikePrice,
uint256 expiry,
bool isPut
);

/**
* @notice initialize the oToken
* @param _addressBook addressbook module
Expand Down Expand Up @@ -65,6 +76,18 @@ contract Otoken is ERC20PermitUpgradeable {
expiryTimestamp = _expiryTimestamp;
isPut = _isPut;
(string memory tokenName, string memory tokenSymbol) = _getNameAndSymbol();

emit OTokenInitiated(
tokenName,
tokenSymbol,
_underlyingAsset,
_strikeAsset,
_collateralAsset,
_strikePrice,
_expiryTimestamp,
_isPut
);

__ERC20_init_unchained(tokenName, tokenSymbol);
__ERC20Permit_init(tokenName);
_setupDecimals(8);
Expand Down
6 changes: 6 additions & 0 deletions contracts/interfaces/OtokenInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
pragma solidity 0.6.10;

interface OtokenInterface {
function name() external view returns (string memory);

function symbol() external view returns (string memory);

function decimals() external view returns (uint256);

function addressBook() external view returns (address);

function underlyingAsset() external view returns (address);
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/MockDumbERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ contract MockDumbERC20 {
return true;
}

function allowance(address owner, address spender) public view virtual returns (uint256) {
function allowance(address owner, address spender) public virtual view returns (uint256) {
return _allowances[owner][spender];
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/packages/oz/Context.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ pragma solidity 0.6.10;
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
function _msgSender() internal virtual view returns (address payable) {
return msg.sender;
}

function _msgData() internal view virtual returns (bytes memory) {
function _msgData() internal virtual view returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/packages/oz/upgradeability/ERC20Upgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeabl
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
function totalSupply() public override view returns (uint256) {
return _totalSupply;
}

/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
function balanceOf(address account) public override view returns (uint256) {
return _balances[account];
}

Expand All @@ -127,7 +127,7 @@ contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeabl
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
function allowance(address owner, address spender) public virtual override view returns (uint256) {
return _allowances[owner][spender];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ abstract contract ContextUpgradeable is Initializable {

function __Context_init_unchained() internal initializer {}

function _msgSender() internal view virtual returns (address payable) {
function _msgSender() internal virtual view returns (address payable) {
return msg.sender;
}

function _msgData() internal view virtual returns (bytes memory) {
function _msgData() internal virtual view returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
Expand Down
14 changes: 7 additions & 7 deletions contracts/packages/oz/upgradeability/Proxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ abstract contract Proxy {
* @dev Tells the address of the implementation where every call will be delegated.
* @return address of the implementation to which it will be delegated
*/
function implementation() public view virtual returns (address);
function implementation() public virtual view returns (address);

/**
* @dev Fallback function allowing to perform a delegatecall to the given implementation.
Expand All @@ -30,12 +30,12 @@ abstract contract Proxy {
returndatacopy(ptr, 0, size)

switch result
case 0 {
revert(ptr, size)
}
default {
return(ptr, size)
}
case 0 {
revert(ptr, size)
}
default {
return(ptr, size)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract UpgradeabilityProxy is Proxy {
* @dev Tells the address of the current implementation
* @return impl address of the current implementation
*/
function implementation() public view override returns (address impl) {
function implementation() public override view returns (address impl) {
bytes32 position = implementationPosition;
assembly {
impl := sload(position)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ abstract contract EIP712Upgradeable is Initializable {
/* solhint-disable var-name-mixedcase */
bytes32 private _HASHED_NAME;
bytes32 private _HASHED_VERSION;
bytes32 private constant _TYPE_HASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
bytes32 private constant _TYPE_HASH = keccak256(
"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
);

/* solhint-enable var-name-mixedcase */

Expand Down Expand Up @@ -101,7 +102,7 @@ abstract contract EIP712Upgradeable is Initializable {
* NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs
* are a concern.
*/
function _EIP712NameHash() internal view virtual returns (bytes32) {
function _EIP712NameHash() internal virtual view returns (bytes32) {
return _HASHED_NAME;
}

Expand All @@ -111,7 +112,7 @@ abstract contract EIP712Upgradeable is Initializable {
* NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs
* are a concern.
*/
function _EIP712VersionHash() internal view virtual returns (bytes32) {
function _EIP712VersionHash() internal virtual view returns (bytes32) {
return _HASHED_VERSION;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ abstract contract ERC20PermitUpgradeable is
/**
* @dev See {IERC20Permit-nonces}.
*/
function nonces(address owner) public view override returns (uint256) {
function nonces(address owner) public override view returns (uint256) {
return _nonces[owner].current();
}

/**
* @dev See {IERC20Permit-DOMAIN_SEPARATOR}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view override returns (bytes32) {
function DOMAIN_SEPARATOR() external override view returns (bytes32) {
return _domainSeparatorV4();
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/pricers/ChainlinkPricer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ contract ChainLinkPricer is OpynPricerInterface {
* @dev overides the getPrice function in OpynPricerInterface
* @return price of the asset in USD, scaled by 1e8
*/
function getPrice() external view override returns (uint256) {
function getPrice() external override view returns (uint256) {
(, int256 answer, , , ) = aggregator.latestRoundData();
require(answer > 0, "ChainLinkPricer: price is lower than 0");
// chainlink's answer is already 1e8
Expand All @@ -92,7 +92,7 @@ contract ChainLinkPricer is OpynPricerInterface {
* @param _roundId chainlink round id
* @return round price and timestamp
*/
function getHistoricalPrice(uint80 _roundId) external view override returns (uint256, uint256) {
function getHistoricalPrice(uint80 _roundId) external override view returns (uint256, uint256) {
(, int256 price, , uint256 roundTimestamp, ) = aggregator.getRoundData(_roundId);
return (_scaleToBase(uint256(price)), roundTimestamp);
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/pricers/WstethPricer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ contract WstethPricer is OpynPricerInterface {
* @dev overrides the getPrice function in OpynPricerInterface
* @return price of 1 wstETH in USD, scaled by 1e8
*/
function getPrice() external view override returns (uint256) {
function getPrice() external override view returns (uint256) {
uint256 underlyingPrice = oracle.getPrice(underlying);
require(underlyingPrice > 0, "W4");
return _underlyingPriceToWstethPrice(underlyingPrice);
Expand Down Expand Up @@ -86,7 +86,7 @@ contract WstethPricer is OpynPricerInterface {
return stEthPerWsteth.mul(_underlyingPrice).div(1e18);
}

function getHistoricalPrice(uint80) external view override returns (uint256, uint256) {
function getHistoricalPrice(uint80) external override view returns (uint256, uint256) {
revert("W6");
}
}
4 changes: 2 additions & 2 deletions contracts/pricers/YearnPricer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ contract YearnPricer is OpynPricerInterface {
* @dev overrides the getPrice function in OpynPricerInterface
* @return price of 1e8 yToken in USD, scaled by 1e8
*/
function getPrice() external view override returns (uint256) {
function getPrice() external override view returns (uint256) {
uint256 underlyingPrice = oracle.getPrice(address(underlying));
require(underlyingPrice > 0, "YearnPricer: underlying price is 0");
return _underlyingPriceToYtokenPrice(underlyingPrice);
Expand Down Expand Up @@ -76,7 +76,7 @@ contract YearnPricer is OpynPricerInterface {
return pricePerShare.mul(_underlyingPrice).div(10**uint256(underlyingDecimals));
}

function getHistoricalPrice(uint80 _roundId) external view override returns (uint256, uint256) {
function getHistoricalPrice(uint80 _roundId) external override view returns (uint256, uint256) {
revert("YearnPricer: Deprecated");
}
}
3 changes: 1 addition & 2 deletions migrations/1_initial_migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ const Migrations = artifacts.require('Migrations')

module.exports = function(deployer, network, accounts) {
const account = accounts[0]
console.log(`deploying with account ${account}`)
deployer.deploy(Migrations)
deployer.deploy(Migrations, {from: account})
}
19 changes: 12 additions & 7 deletions migrations/2_deploy_contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@ const Controller = artifacts.require('Controller')
module.exports = async function(deployer, network, accounts) {
const [deployerAddress] = accounts

// arbitrum networks count gas differently, will need to set a higher gas limit for big contracts
const txOptionOverride = network.contains('arbitrum') ? {gas: 200000000} : {}

// deploy AddressBook & transfer ownership
await deployer.deploy(AddressBook, {from: deployerAddress})
const addressbook = await AddressBook.deployed()

// deploy Otoken implementation & set address
await deployer.deploy(Otoken, {from: deployerAddress, ...txOptionOverride})
const otokenImpl = await Otoken.deployed()
await addressbook.setOtokenImpl(otokenImpl.address, {from: deployerAddress})

// deploy OtokenFactory & set address
await deployer.deploy(OtokenFactory, addressbook.address, {from: deployerAddress})
const otokenFactory = await OtokenFactory.deployed()
await addressbook.setOtokenFactory(otokenFactory.address, {from: deployerAddress})

// deploy Otoken implementation & set address
await deployer.deploy(Otoken, {from: deployerAddress})
const otokenImpl = await Otoken.deployed()
await addressbook.setOtokenImpl(otokenImpl.address, {from: deployerAddress})

// deploy Whitelist module & set address
await deployer.deploy(Whitelist, addressbook.address, {from: deployerAddress})
const whitelist = await Whitelist.deployed()
Expand All @@ -43,15 +46,17 @@ module.exports = async function(deployer, network, accounts) {
await addressbook.setMarginPool(pool.address, {from: deployerAddress})

// deploy Calculator module & set address
await deployer.deploy(MarginCalculator, oracle.address, {from: deployerAddress})
await deployer.deploy(MarginCalculator, addressbook.address, {from: deployerAddress, txOptionOverride})
const calculator = await MarginCalculator.deployed()
await addressbook.setMarginCalculator(calculator.address, {from: deployerAddress})

// deploy Controller & set address
// deploy MarginVault library
await deployer.deploy(MarginVault, {from: deployerAddress})
await deployer.link(MarginVault, Controller)
await deployer.deploy(Controller, {from: deployerAddress})
await deployer.deploy(Controller, {from: deployerAddress, txOptionOverride})
const controller = await Controller.deployed()
await addressbook.setController(controller.address, {from: deployerAddress})

console.log(`controller proxy address`, await addressbook.getController())
}
16 changes: 10 additions & 6 deletions migrations/3_setup_ownership.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@ const MarginPool = artifacts.require('MarginPool')
const AddressBook = artifacts.require('AddressBook')
const Controller = artifacts.require('Controller')

const MarginCalculator = artifacts.require('MarginCalculator')

// import config file
const deploymentConfig = require('./deployment-config.json')

module.exports = async function(deployer, network, accounts) {
const [deployerAddress] = accounts

// new protocol owner
const newOwner = deploymentConfig.MULTISIG

// // new protocol owner
const newOwner = deploymentConfig.MULTISIG[network]
if (!newOwner) {
console.log(`No multisig address found on network ${network}, skipping this step..`)
return
}
const addressbook = await AddressBook.deployed()
const whitelist = await Whitelist.deployed()
const oracle = await Oracle.deployed()
const pool = await MarginPool.deployed()
const calculator = await MarginCalculator.deployed()
const controller = await Controller.at(await addressbook.getController())

// transfer ownership
await calculator.transferOwnership(newOwner, {from: deployerAddress})
await addressbook.transferOwnership(newOwner, {from: deployerAddress})
await whitelist.transferOwnership(newOwner, {from: deployerAddress})
await oracle.transferOwnership(newOwner, {from: deployerAddress})
Expand Down
Loading