forked from aragon/aragon-court
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request aragon#9 from 1Hive/fees-updater
Added FeesUpdater contract for updating fees using stable coin value.
- Loading branch information
Showing
11 changed files
with
325 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
pragma solidity ^0.5.8; | ||
|
||
import "../court/AragonCourt.sol"; | ||
import "./IPriceOracle.sol"; | ||
import "../lib/os/ERC20.sol"; | ||
|
||
contract FeesUpdater { | ||
|
||
IPriceOracle public priceOracle; | ||
AragonCourt public court; | ||
address public courtStableToken; | ||
uint256[3] public courtStableValueFees; | ||
|
||
constructor( | ||
IPriceOracle _priceOracle, | ||
AragonCourt _court, | ||
address _courtStableToken, | ||
uint256[3] memory _courtStableValueFees | ||
) public { | ||
priceOracle = _priceOracle; | ||
court = _court; | ||
courtStableToken = _courtStableToken; | ||
courtStableValueFees = _courtStableValueFees; | ||
} | ||
|
||
function getStableFees() external view returns (uint256[3] memory) { | ||
return courtStableValueFees; | ||
} | ||
|
||
/** | ||
* @notice Convert the court fees from their stable value to the fee token value and update the court config from the | ||
* next term with them. This function can be called any number of times during a court term, the closer to the | ||
* start of the following term the more accurate the configured fees will be. | ||
*/ | ||
function updateCourtFees() external { | ||
uint64 currentTerm = court.ensureCurrentTerm(); | ||
|
||
// We use the latest possible term to ensure that if the config has been updated by an account other | ||
// than this oracle, the config fetched will be the updated one. However, this does mean that a config update | ||
// that is scheduled for a future term will be scheduled for the next term instead. | ||
uint64 latestPossibleTerm = uint64(-1); | ||
(ERC20 feeToken,, | ||
uint64[5] memory roundStateDurations, | ||
uint16[2] memory pcts, | ||
uint64[4] memory roundParams, | ||
uint256[2] memory appealCollateralParams, | ||
uint256[3] memory jurorsParams | ||
) = court.getConfig(latestPossibleTerm); | ||
|
||
uint256[3] memory convertedFees; | ||
convertedFees[0] = priceOracle.consult(courtStableToken, courtStableValueFees[0], address(feeToken)); | ||
convertedFees[1] = priceOracle.consult(courtStableToken, courtStableValueFees[1], address(feeToken)); | ||
convertedFees[2] = priceOracle.consult(courtStableToken, courtStableValueFees[2], address(feeToken)); | ||
|
||
court.setConfig(currentTerm + 1, feeToken, convertedFees, roundStateDurations, pcts, roundParams, | ||
appealCollateralParams, jurorsParams); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pragma solidity ^0.5.8; | ||
|
||
contract IPriceOracle { | ||
function consult(address tokenIn, uint256 amountIn, address tokenOut) external view returns (uint256 amountOut); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
pragma solidity ^0.5.8; | ||
|
||
import "../../feesUpdater/IPriceOracle.sol"; | ||
|
||
contract MockPriceOracle is IPriceOracle { | ||
|
||
uint256 public feeTokenPriceInStableToken; | ||
|
||
constructor(uint256 _feeTokenPriceInStableToken) public { | ||
feeTokenPriceInStableToken = _feeTokenPriceInStableToken; | ||
} | ||
|
||
function consult(address tokenIn, uint256 amountIn, address tokenOut) external view returns (uint256 amountOut) { | ||
return amountIn / feeTokenPriceInStableToken; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.