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

Feature/suspendable treasury #38

Merged
merged 2 commits into from
Aug 17, 2022
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
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"terminal.integrated.defaultProfile.linux": "zsh",
"solidity.remappingsUnix": [
"@openzeppelin/=/home/vscode/.brownie/packages/OpenZeppelin/openzeppelin-contracts@4.7.0",
"@etherisc/gif-interface/=/home/vscode/.brownie/packages/etherisc/gif-interface@3ee6b81",
"@etherisc/gif-interface/=/home/vscode/.brownie/packages/etherisc/gif-interface@66e3fe8",
"@chainlink/=/home/vscode/.brownie/packages/smartcontractkit/chainlink@1.6.0",
]
}
4 changes: 2 additions & 2 deletions brownie-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ compiler:
remappings:
- "@openzeppelin=OpenZeppelin/openzeppelin-contracts@4.7.0"
- "@chainlink=smartcontractkit/chainlink@1.6.0"
- "@etherisc/gif-interface=etherisc/gif-interface@3ee6b81"
- "@etherisc/gif-interface=etherisc/gif-interface@66e3fe8"

# packages below will be added to brownie
# you may use 'brownie pm list' after 'brownie compile'
Expand All @@ -33,7 +33,7 @@ dependencies:
# github dependency format: <owner>/<repository>@<release>
- OpenZeppelin/openzeppelin-contracts@4.7.0
- smartcontractkit/chainlink@1.6.0
- etherisc/gif-interface@3ee6b81
- etherisc/gif-interface@66e3fe8

# exclude open zeppeling contracts when calculating test coverage
# https://eth-brownie.readthedocs.io/en/v1.10.3/config.html#exclude_paths
Expand Down
36 changes: 35 additions & 1 deletion contracts/modules/TreasuryModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import "@etherisc/gif-interface/contracts/components/IProduct.sol";
import "@etherisc/gif-interface/contracts/modules/IPolicy.sol";
import "@etherisc/gif-interface/contracts/modules/ITreasury.sol";

import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/Strings.sol";

contract TreasuryModule is
ITreasury,
CoreController
CoreController,
Pausable
{
uint256 public constant FRACTION_FULL_UNIT = 10**18;

Expand Down Expand Up @@ -54,6 +56,12 @@ contract TreasuryModule is
_;
}

// surrogate modifier for whenNotPaused to create treasury specific error message
modifier whenNotSuspended() {
require(!paused(), "ERROR:TRS-004:TREASURY_SUSPENDED");
_;
}


function _afterInitialize() internal override onlyInitializing {
_bundle = BundleController(_getContractAddress("Bundle"));
Expand All @@ -62,8 +70,25 @@ contract TreasuryModule is
_pool = PoolController(_getContractAddress("Pool"));
}

function suspend()
external
onlyInstanceOperator
{
_pause();
emit LogTreasurySuspended();
}

function resume()
external
onlyInstanceOperator
{
_unpause();
emit LogTreasuryResumed();
}

function setProductToken(uint256 productId, address erc20Address)
external override
whenNotSuspended
onlyInstanceOperator
{
require(erc20Address != address(0), "ERROR:TRS-010:TOKEN_ADDRESS_ZERO");
Expand All @@ -87,6 +112,7 @@ contract TreasuryModule is

function setInstanceWallet(address instanceWalletAddress)
external override
whenNotSuspended
onlyInstanceOperator
{
require(instanceWalletAddress != address(0), "ERROR:TRS-015:WALLET_ADDRESS_ZERO");
Expand All @@ -97,6 +123,7 @@ contract TreasuryModule is

function setRiskpoolWallet(uint256 riskpoolId, address riskpoolWalletAddress)
external override
whenNotSuspended
onlyInstanceOperator
{
IComponent component = _component.getComponent(riskpoolId);
Expand Down Expand Up @@ -130,6 +157,7 @@ contract TreasuryModule is

function setPremiumFees(FeeSpecification calldata feeSpec)
external override
whenNotSuspended
onlyInstanceOperator
{
IComponent component = _component.getComponent(feeSpec.componentId);
Expand All @@ -145,6 +173,7 @@ contract TreasuryModule is

function setCapitalFees(FeeSpecification calldata feeSpec)
external override
whenNotSuspended
onlyInstanceOperator
{
IComponent component = _component.getComponent(feeSpec.componentId);
Expand Down Expand Up @@ -180,6 +209,7 @@ contract TreasuryModule is
*/
function processPremium(bytes32 processId)
external override
whenNotSuspended
returns(
bool success,
uint256 feeAmount,
Expand All @@ -201,6 +231,7 @@ contract TreasuryModule is
*/
function processPremium(bytes32 processId, uint256 amount)
public override
whenNotSuspended
instanceWalletDefined
riskpoolWalletDefinedForProcess(processId)
returns(
Expand Down Expand Up @@ -244,6 +275,7 @@ contract TreasuryModule is

function processPayout(bytes32 processId, uint256 payoutId)
external override
whenNotSuspended
instanceWalletDefined
riskpoolWalletDefinedForProcess(processId)
returns(
Expand Down Expand Up @@ -284,6 +316,7 @@ contract TreasuryModule is

function processCapital(uint256 bundleId, uint256 capitalAmount)
external override
whenNotSuspended
instanceWalletDefined
riskpoolWalletDefinedForBundle(bundleId)
returns(
Expand Down Expand Up @@ -323,6 +356,7 @@ contract TreasuryModule is

function processWithdrawal(uint256 bundleId, uint256 amount)
external override
whenNotSuspended
instanceWalletDefined
riskpoolWalletDefinedForBundle(bundleId)
returns(
Expand Down
14 changes: 14 additions & 0 deletions contracts/services/InstanceOperatorService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,20 @@ contract InstanceOperatorService is
}

/* treasury */
function suspendTreasury()
external override
onlyInstanceOperatorAddress
{
_treasury.suspend();
}

function resumeTreasury()
external override
onlyInstanceOperatorAddress
{
_treasury.resume();
}

function setInstanceWallet(address walletAddress)
external override
onlyInstanceOperatorAddress
Expand Down
7 changes: 6 additions & 1 deletion scripts/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ def fund_riskpool(

applicationFilter = bytes(0)

bundleId = None

if (createBundle):
riskpool.createBundle(
tx = riskpool.createBundle(
applicationFilter,
amount,
{'from': bundleOwner})
bundleId = tx.return_value

return bundleId


def fund_customer(
Expand Down
9 changes: 7 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ def run_around_tests():
dummy_account = get_account(ACCOUNTS_MNEMONIC, 999)
execute_simple_incrementer_trx(dummy_account)

# DEPRECATED: use erc20Token instead
@pytest.fixture(scope="module")
def testCoin(erc20Token) -> TestCoin:
return erc20Token

# DEPRECATED: use instanceOperator instead
@pytest.fixture(scope="module")
def owner(instanceOperator) -> Account:
Expand Down Expand Up @@ -264,8 +269,8 @@ def registry(registryController, owner) -> RegistryController:
return registry

@pytest.fixture(scope="module")
def testCoin(owner) -> TestCoin:
return TestCoin.deploy({'from': owner})
def erc20Token(instanceOperator) -> TestCoin:
return TestCoin.deploy({'from': instanceOperator})

@pytest.fixture(scope="module")
def testCoinX(owner) -> TestCoinX:
Expand Down
Loading