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

Replaced AragonVault with the FundsManager interface. #2

Merged
merged 8 commits into from Oct 16, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions arapp.json
Expand Up @@ -35,6 +35,16 @@
"registry": "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",
"appName": "dynamic-issuance.1hive.aragonpm.eth",
"network": "mainnet"
},
"mumbai": {
"registry": "0xB1576a9bE5EC445368740161174f3Dd1034fF8be",
"appName": "dynamic-issuance.open.aragonpm.eth",
"network": "mumbai"
},
"polygon": {
"registry": "0x4E065c622d584Fbe5D9078C3081840155FA69581",
"appName": "dynamic-issuance.open.aragonpm.eth",
"network": "polygon"
}
},
"path": "contracts/Issuance.sol"
Expand Down
10 changes: 10 additions & 0 deletions buidler.config.js
Expand Up @@ -32,6 +32,16 @@ module.exports = {
accounts: [process.env.ETH_KEY],
gasPrice: 0,
},
mumbai: {
url: 'https://rpc-mumbai.maticvigil.com/v1/21b0f704769b8850d4e5b7a3adb9d436230ce014',
accounts: [process.env.ETH_KEY],
gasPrice: 1000000000
},
polygon: {
url: 'https://rpc-mainnet.maticvigil.com/v1/21b0f704769b8850d4e5b7a3adb9d436230ce014',
accounts: [process.env.ETH_KEY],
gasPrice: 60000000000
}
},
solc: {
version: '0.4.24',
Expand Down
26 changes: 18 additions & 8 deletions contracts/Issuance.sol
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.4.24;
import "@aragon/os/contracts/apps/AragonApp.sol";
import "@aragon/os/contracts/lib/math/SafeMath.sol";
import "@1hive/apps-token-manager/contracts/HookedTokenManager.sol";
import "@aragon/apps-vault/contracts/Vault.sol";
import "@1hive/funds-manager/contracts/FundsManager.sol";


contract Issuance is AragonApp {
Expand All @@ -17,27 +17,28 @@ contract Issuance is AragonApp {
uint256 constant public RATIO_PRECISION = 1e10;

HookedTokenManager public commonPoolTokenManager;
Vault public commonPoolVault;
FundsManager public commonPoolFundsManager;
MiniMeToken public commonPoolToken;
uint256 public targetRatio;
uint256 public maxAdjustmentRatioPerSecond;
uint256 public previousAdjustmentSecond;

event AdjustmentMade(uint256 adjustmentAmount, bool positive);
event TargetRatioUpdated(uint256 targetRatio);
event FundsManagerUpdated(FundsManager fundsManager);
event MaxAdjustmentRatioPerSecondUpdated(uint256 maxAdjustmentRatioPerSecond);

/**
* @notice Initialise the Issuance app
* @param _commonPoolTokenManager Token Manager managing the common pool token
* @param _commonPoolVault Vault holding the common pools token balance
* @param _commonPoolFundsManager Vault holding the common pools token balance
0xGabi marked this conversation as resolved.
Show resolved Hide resolved
* @param _targetRatio Fractional ratio value multiplied by RATIO_PRECISION, eg target ratio of 0.2 would be 2e9
* @param _maxAdjustmentRatioPerSecond Eg A max adjustment ratio of 0.1 would be 0.1 / 31536000 (seconds in year) = 0.000000003170979198
adjusted by multiplying by EXTRA_PRECISION = 3170979198
*/
function initialize(
HookedTokenManager _commonPoolTokenManager,
Vault _commonPoolVault,
FundsManager _commonPoolFundsManager,
uint256 _targetRatio,
uint256 _maxAdjustmentRatioPerSecond
)
Expand All @@ -46,7 +47,7 @@ contract Issuance is AragonApp {
require(_targetRatio <= RATIO_PRECISION, ERROR_TARGET_RATIO_TOO_HIGH);

commonPoolTokenManager = _commonPoolTokenManager;
commonPoolVault = _commonPoolVault;
commonPoolFundsManager = _commonPoolFundsManager;
commonPoolToken = _commonPoolTokenManager.token();
targetRatio = _targetRatio;
maxAdjustmentRatioPerSecond = _maxAdjustmentRatioPerSecond;
Expand All @@ -56,6 +57,15 @@ contract Issuance is AragonApp {
initialized();
}

/**
* @notice Update the funds manager
* @param _commonPoolFundsManager The new funds manager
*/
function updateFundsManager(FundsManager _commonPoolFundsManager) external auth(UPDATE_SETTINGS_ROLE) {
commonPoolFundsManager = _commonPoolFundsManager;
emit FundsManagerUpdated(_commonPoolFundsManager);
}

/**
* @notice Update the target ratio to `_targetRatio`
* @param _targetRatio The new target ratio
Expand All @@ -79,7 +89,7 @@ contract Issuance is AragonApp {
* @notice Execute the adjustment to the total supply of the common pool token and burn or mint to the common pool vault
*/
function executeAdjustment() external {
uint256 commonPoolBalance = commonPoolVault.balance(commonPoolToken);
uint256 commonPoolBalance = commonPoolFundsManager.balance(commonPoolToken);
uint256 tokenTotalSupply = commonPoolToken.totalSupply();
uint256 targetBalance = tokenTotalSupply.mul(targetRatio).div(RATIO_PRECISION);

Expand All @@ -99,7 +109,7 @@ contract Issuance is AragonApp {
totalToBurn = commonPoolBalance.sub(targetBalance);
}

commonPoolTokenManager.burn(commonPoolVault, totalToBurn);
commonPoolTokenManager.burn(commonPoolFundsManager.fundsOwner(), totalToBurn);

emit AdjustmentMade(totalToBurn, false);

Expand All @@ -111,7 +121,7 @@ contract Issuance is AragonApp {
totalToMint = targetBalance.sub(commonPoolBalance);
}

commonPoolTokenManager.mint(commonPoolVault, totalToMint);
commonPoolTokenManager.mint(commonPoolFundsManager.fundsOwner(), totalToMint);

emit AdjustmentMade(totalToMint, true);
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/test/Imports.sol
Expand Up @@ -4,6 +4,6 @@ import "@aragon/os/contracts/acl/ACL.sol";
import "@aragon/os/contracts/kernel/Kernel.sol";
import "@aragon/os/contracts/factory/DAOFactory.sol";
import "@aragon/os/contracts/factory/EVMScriptRegistryFactory.sol";
import "@1hive/funds-manager/contracts/AragonVaultFundsManager.sol";

contract Imports {
}
contract Imports {}
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -14,7 +14,8 @@
"dependencies": {
"@aragon/os": "5.0.0-rc.0",
"@aragon/apps-vault": "4.1.0",
"@1hive/apps-token-manager": "3.0.4"
"@1hive/apps-token-manager": "3.0.4",
"@1hive/funds-manager": "1.0.4"
},
"devDependencies": {
"@aragon/contract-helpers-test": "^0.1.0",
Expand Down
23 changes: 19 additions & 4 deletions test/issuance.js
Expand Up @@ -7,11 +7,12 @@ const Issuance = artifacts.require('MockIssuance.sol')
const TokenManager = artifacts.require('HookedTokenManager.sol')
const Vault = artifacts.require('Vault.sol')
const MiniMeToken = artifacts.require('MiniMeToken.sol')
const AragonVaultFundsManager = artifacts.require('AragonVaultFundsManager.sol')

contract('Issuance', ([appManager]) => {
contract('Issuance', ([appManager, newFundsManager]) => {

let dao, acl
let tokenManagerBase, tokenManager, vaultBase, vault, issuanceBase, issuance, commonPoolToken
let tokenManagerBase, tokenManager, vaultBase, vault, issuanceBase, issuance, commonPoolToken, aragonVaultFundsManager

const ANY_ADDRESS = '0xffffffffffffffffffffffffffffffffffffffff'
const EXTRA_PRECISION = bigExp(1,18);
Expand Down Expand Up @@ -73,6 +74,7 @@ contract('Issuance', ([appManager]) => {
const vaultAddress = await newApp(dao, 'vault', vaultBase.address, appManager)
vault = await Vault.at(vaultAddress)
await vault.initialize()
aragonVaultFundsManager = await AragonVaultFundsManager.new(vault.address)
})

context('initialize()', () => {
Expand All @@ -81,13 +83,14 @@ contract('Issuance', ([appManager]) => {

beforeEach(async () => {
secondDeployed = await issuance.getTimestampPublic()
await issuance.initialize(tokenManager.address, vault.address,
await issuance.initialize(tokenManager.address, aragonVaultFundsManager.address,
INITIAL_TARGET_RATIO, INITIAL_MAX_ADJUSTMENT_PER_SECOND)
await aragonVaultFundsManager.addFundsUser(issuance.address)
})

it('should set init params correctly', async () => {
assert.equal(await issuance.commonPoolTokenManager(), tokenManager.address, 'Incorrect token manager')
assert.equal(await issuance.commonPoolVault(), vault.address, 'Incorrect vault')
assert.equal(await issuance.commonPoolFundsManager(), aragonVaultFundsManager.address, 'Incorrect funds manager')
assert.equal(await issuance.commonPoolToken(), commonPoolToken.address, 'Incorrect token')
assertBn(await issuance.targetRatio(), INITIAL_TARGET_RATIO, 'Incorrect target ratio')
assertBn(await issuance.maxAdjustmentRatioPerSecond(), INITIAL_MAX_ADJUSTMENT_PER_SECOND, 'Incorrect max adjustment per second')
Expand All @@ -101,6 +104,18 @@ contract('Issuance', ([appManager]) => {
RATIO_PRECISION.add(bn(1)), INITIAL_MAX_ADJUSTMENT_PER_SECOND), 'ISSUANCE_TARGET_RATIO_TOO_HIGH')
})

context('updateFundsManager(fundsManager)', () => {
it('updates the funds manager', async () => {
await issuance.updateFundsManager(newFundsManager)
assert.equal(await issuance.commonPoolFundsManager(), newFundsManager, 'Incorrect funds manager')
})

it('reverts when no permission', async () => {
await acl.revokePermission(ANY_ADDRESS, issuance.address, await issuance.UPDATE_SETTINGS_ROLE())
await assertRevert(issuance.updateFundsManager(newFundsManager), 'APP_AUTH_FAILED')
})
})

context('updateTargetRatio(uint256 _targetRatio)', async () => {
it('updates target ratio', async() => {
const expectedTargetRatio = bigExp(5, 9)
Expand Down