Skip to content
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
126 changes: 116 additions & 10 deletions contracts/BondDepository.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,63 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity 0.7.5;

/**
* @title Initializable
*
* @dev Helper contract to support initializer functions. To use it, replace
* the constructor with a function that has the `initializer` modifier.
* WARNING: Unlike constructors, initializer functions must be manually
* invoked. This applies both to deploying an Initializable contract, as well
* as extending an Initializable contract via inheritance.
* WARNING: When used with inheritance, manual care must be taken to not invoke
* a parent initializer twice, or ensure that all initializers are idempotent,
* because this is not dealt with automatically as with constructors.
*/
contract Initializable {

/**
* @dev Indicates that the contract has been initialized.
*/
bool private initialized;

/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private initializing;

/**
* @dev Modifier to use in the initializer function of a contract.
*/
modifier initializer() {
require(initializing || isConstructor() || !initialized, "Contract instance has already been initialized");

bool isTopLevelCall = !initializing;
if (isTopLevelCall) {
initializing = true;
initialized = true;
}

_;

if (isTopLevelCall) {
initializing = false;
}
}

/// @dev Returns true if and only if the function is running in the constructor
function isConstructor() private view returns (bool) {
// extcodesize checks the size of the code stored in an address, and
// address returns the current address. Since the code is still not
// deployed when running a constructor, any checks on its code size will
// yield zero, making it an effective way to detect if a contract is
// under construction or not.
address self = address(this);
uint256 cs;
assembly { cs := extcodesize(self) }
return cs == 0;
}
}

interface IOwnable {
function policy() external view returns (address);

Expand All @@ -11,15 +68,24 @@ interface IOwnable {
function pullManagement() external;
}

contract Ownable is IOwnable {
contract Ownable is IOwnable, Initializable {

address internal _owner;
address internal _newOwner;

event OwnershipPushed(address indexed previousOwner, address indexed newOwner);
event OwnershipPulled(address indexed previousOwner, address indexed newOwner);

constructor () {
// constructor () {
// _owner = msg.sender;
// emit OwnershipPushed( address(0), _owner );
// }

function __Ownable_initialize() internal initializer {
__Ownable_init_unchain();
}

function __Ownable_init_unchain() internal initializer {
_owner = msg.sender;
emit OwnershipPushed( address(0), _owner );
}
Expand Down Expand Up @@ -623,13 +689,13 @@ contract SynassetsBondDepository is Ownable {

/* ======== STATE VARIABLES ======== */

address public immutable SYNASSETS; // token given as payment for bond
address public immutable principle; // token used to create bond
address public immutable treasury; // mints SYNASSETS when receives principle
address public immutable DAO; // receives profit share from bond
address public SYNASSETS; // token given as payment for bond
address public principle; // token used to create bond
address public treasury; // mints SYNASSETS when receives principle
address public DAO; // receives profit share from bond

bool public immutable isLiquidityBond; // LP and Reserve bonds are treated slightly different
address public immutable bondCalculator; // calculates value of LP tokens
bool public isLiquidityBond; // LP and Reserve bonds are treated slightly different
address public bondCalculator; // calculates value of LP tokens

address public staking; // to auto-stake payout
address public stakingHelper; // to stake and claim if no staking warmup
Expand Down Expand Up @@ -681,13 +747,53 @@ contract SynassetsBondDepository is Ownable {

/* ======== INITIALIZATION ======== */

constructor (
// constructor (
// address _SYNASSETS,
// address _principle,
// address _treasury,
// address _DAO,
// address _bondCalculator
// ) {
// require( _SYNASSETS != address(0) );
// SYNASSETS = _SYNASSETS;
// require( _principle != address(0) );
// principle = _principle;
// require( _treasury != address(0) );
// treasury = _treasury;
// require( _DAO != address(0) );
// DAO = _DAO;
// // bondCalculator should be address(0) if not LP bond
// bondCalculator = _bondCalculator;
// isLiquidityBond = ( _bondCalculator != address(0) );
// }

function __SynassetsBondDepository_initialize(
address _SYNASSETS,
address _principle,
address _treasury,
address _DAO,
address _bondCalculator
) external initializer {
__SynassetsBondDepository_init_unchain(_SYNASSETS, _principle, _treasury, _DAO, _bondCalculator);
}

function __setParameters(
address _SYNASSETS,
address _principle,
address _treasury,
address _DAO,
address _bondCalculator
) external onlyPolicy {
__SynassetsBondDepository_init_unchain(_SYNASSETS, _principle, _treasury, _DAO, _bondCalculator);
}

function __SynassetsBondDepository_init_unchain(
address _SYNASSETS,
address _principle,
address _treasury,
address _DAO,
address _bondCalculator
) {
) internal {
require( _SYNASSETS != address(0) );
SYNASSETS = _SYNASSETS;
require( _principle != address(0) );
Expand Down
141 changes: 136 additions & 5 deletions contracts/ConsensusPool.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,112 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity 0.7.5;

/**
* @title Initializable
*
* @dev Helper contract to support initializer functions. To use it, replace
* the constructor with a function that has the `initializer` modifier.
* WARNING: Unlike constructors, initializer functions must be manually
* invoked. This applies both to deploying an Initializable contract, as well
* as extending an Initializable contract via inheritance.
* WARNING: When used with inheritance, manual care must be taken to not invoke
* a parent initializer twice, or ensure that all initializers are idempotent,
* because this is not dealt with automatically as with constructors.
*/
contract Initializable {

/**
* @dev Indicates that the contract has been initialized.
*/
bool private initialized;

/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private initializing;

/**
* @dev Modifier to use in the initializer function of a contract.
*/
modifier initializer() {
require(initializing || isConstructor() || !initialized, "Contract instance has already been initialized");

bool isTopLevelCall = !initializing;
if (isTopLevelCall) {
initializing = true;
initialized = true;
}

_;

if (isTopLevelCall) {
initializing = false;
}
}

/// @dev Returns true if and only if the function is running in the constructor
function isConstructor() private view returns (bool) {
// extcodesize checks the size of the code stored in an address, and
// address returns the current address. Since the code is still not
// deployed when running a constructor, any checks on its code size will
// yield zero, making it an effective way to detect if a contract is
// under construction or not.
address self = address(this);
uint256 cs;
assembly { cs := extcodesize(self) }
return cs == 0;
}
}

interface IOwnable {
function owner() external view returns (address);

function renounceOwnership() external;

function transferOwnership( address newOwner_ ) external;
}

contract Ownable is IOwnable, Initializable {

address internal _owner;
address internal _pendingOwner;

event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
event OwnershipTransferring(address indexed owner, address indexed pendingOwner);

function __Ownable_init_unchain() internal initializer {
require(_owner == address(0));
_owner = msg.sender;
emit OwnershipTransferred( address(0), _owner );
}

function owner() public view override returns (address) {
return _owner;
}

modifier onlyOwner() {
require( _owner == msg.sender, "Ownable: caller is not the owner" );
_;
}

function renounceOwnership() public virtual override onlyOwner() {
emit OwnershipTransferred( _owner, address(0) );
_owner = address(0);
}

function transferOwnership( address newOwner_ ) public virtual override onlyOwner() {
require( newOwner_ != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferring( _owner, newOwner_ );
_pendingOwner = newOwner_;
}

function acceptOwnership() external {
require(_pendingOwner == msg.sender, "Permission denied");
emit OwnershipTransferred( _owner, msg.sender );
_owner = msg.sender;
}
}

library LowGasSafeMath {
/// @notice Returns x + y, reverts if sum overflows uint256
/// @param x The augend
Expand Down Expand Up @@ -173,7 +279,7 @@ interface IDistributor {
}

// 7.97%
contract ConsensusPool {
contract ConsensusPool is Ownable {

using LowGasSafeMath for uint256;
using SafeERC20 for IERC20;
Expand Down Expand Up @@ -234,16 +340,41 @@ contract ConsensusPool {
event Unstaked(address indexed unstaker, address indexed inviter, uint256 amount);
event RewardPaid(address indexed user, uint256 reward);

function initialize (
function __ConsensusPool_initialize (
address _SYNASSETS,
address _sSYNASSETS,
uint256 _epochLength,
uint256 _firstEpochNumber,
uint256 _firstEpochBlock,
address _stakingContract,
address _distributor
) external initializer {
__ConsensusPool_init_unchain(_SYNASSETS, _sSYNASSETS, _epochLength, _firstEpochNumber, _firstEpochBlock, _stakingContract, _distributor);
__Ownable_init_unchain();
}

function setParameter(
address _SYNASSETS,
address _sSYNASSETS,
uint256 _epochLength,
uint256 _firstEpochNumber,
uint256 _firstEpochBlock,
address _stakingContract,
address _distributor
) external onlyOwner {
__ConsensusPool_init_unchain(_SYNASSETS, _sSYNASSETS, _epochLength, _firstEpochNumber, _firstEpochBlock, _stakingContract, _distributor);
}

function __ConsensusPool_init_unchain(
address _SYNASSETS,
address _sSYNASSETS,
uint256 _epochLength,
uint256 _firstEpochNumber,
uint256 _firstEpochBlock,
address _stakingContract,
address _distributor
) external {
require( SYNASSETS == address(0), 'AI' );
) internal {
// require( SYNASSETS == address(0), 'AI' );

require( _SYNASSETS != address(0) );
SYNASSETS = _SYNASSETS;
Expand All @@ -256,7 +387,7 @@ contract ConsensusPool {
number: _firstEpochNumber,
endBlock: _firstEpochBlock,
distribute: 0
});
});

stakingContract = _stakingContract;
distributor = _distributor;
Expand Down
2 changes: 1 addition & 1 deletion contracts/SATTimelock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ contract SATTimelock is Ownable {
IERC20(token).safeTransfer(claimAddress, unlocked_);
}

function increaseReward() external {
function increaseReward() public {
uint256 balance_ = IERC20(token).balanceOf(address(this));
uint256 amount_ = balance_.sub(reserveToken);

Expand Down
Loading