-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Payroll: Fix exchange rates request call (#797)
- Loading branch information
1 parent
475b883
commit 57d8978
Showing
19 changed files
with
286 additions
and
236 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
43 changes: 25 additions & 18 deletions
43
future-apps/payroll/contracts/test/mocks/PriceFeedMock.sol
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 |
---|---|---|
@@ -1,29 +1,36 @@ | ||
pragma solidity ^0.4.24; | ||
|
||
import "@aragon/ppf-contracts/contracts/IFeed.sol"; | ||
import "@aragon/ppf-contracts/contracts/PPF.sol"; | ||
import "@aragon/test-helpers/contracts/TimeHelpersMock.sol"; | ||
|
||
|
||
contract PriceFeedMock is IFeed, TimeHelpersMock { | ||
contract PriceFeedMock is PPF, TimeHelpersMock { | ||
// Set operator to address(0) so invalid signatures can pass | ||
constructor () PPF(address(0), msg.sender) public { | ||
// solium-disable-previous-line no-empty-blocks | ||
} | ||
|
||
event PriceFeedLogSetRate(address sender, address token, uint128 value); | ||
// Overriding function for testing purposes, removing check for zero address operator | ||
function _setOperator(address _operator) internal { | ||
// require(_operator != address(0)); | ||
operator = _operator; | ||
emit SetOperator(_operator); | ||
} | ||
|
||
function get(address base, address quote) external view returns (uint128 xrt, uint64 when) { | ||
xrt = toInt(quote); | ||
when = getTimestamp64(); | ||
// Overwrite function using TimeHelpers and allowing to set past rates | ||
function update(address base, address quote, uint128 xrt, uint64 when, bytes sig) public { | ||
bytes32 pair = super.pairId(base, quote); | ||
|
||
emit PriceFeedLogSetRate(msg.sender, quote, xrt); | ||
} | ||
// Remove check that ensures a given rate is more recent than the current value | ||
// require(when > feed[pair].when && when <= getTimestamp()); | ||
require(xrt > 0); // Make sure xrt is not 0, as the math would break (Dividing by 0 sucks big time) | ||
require(base != quote); // Assumption that currency units are fungible and xrt should always be 1 | ||
|
||
/// Gets the first byte of an address as an integer | ||
function toInt(address x) public pure returns(uint128 i) { | ||
uint256 j = uint256(x); | ||
j = j >> 152; | ||
if (j == 0) | ||
j = 10**15; | ||
else | ||
j = j * 10**18; | ||
i = uint128(j); | ||
} | ||
bytes32 h = super.setHash(base, quote, xrt, when); | ||
require(h.personalRecover(sig) == operator); // Make sure the update was signed by the operator | ||
|
||
feed[pair] = Price(super.pairXRT(base, quote, xrt), when); | ||
|
||
emit SetRate(base, quote, xrt, when); | ||
} | ||
} |
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
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.