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

Oracle v1pool #270

Merged
merged 12 commits into from
Jul 13, 2021
1 change: 0 additions & 1 deletion contracts/connectors/loantoken/LoanTokenLogicLM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,4 @@ contract LoanTokenLogicLM is LoanTokenLogicStandard {
_safeTransfer(loanTokenAddress, receiver, redeemed, "asset transfer failed");
}
}

}
3 changes: 1 addition & 2 deletions contracts/connectors/loantoken/LoanTokenLogicStandard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,7 @@ contract LoanTokenLogicStandard is LoanTokenSettingsLowerAdmin {
}

function _burnFromLM(uint256 burnAmount) internal returns (uint256) {
uint balanceOnLM = ILiquidityMining(liquidityMiningAddress).getUserPoolTokenBalance(address(this), msg.sender);
uint256 balanceOnLM = ILiquidityMining(liquidityMiningAddress).getUserPoolTokenBalance(address(this), msg.sender);
require(balanceOnLM.add(balanceOf(msg.sender)) >= burnAmount, "not enough balance");

if (balanceOnLM > 0) {
Expand All @@ -1495,5 +1495,4 @@ contract LoanTokenLogicStandard is LoanTokenSettingsLowerAdmin {
//burn the tokens of the msg.sender
return _burnToken(burnAmount);
}

}
23 changes: 23 additions & 0 deletions contracts/feeds/IV1PoolOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pragma solidity >=0.5.0 <0.6.0;

interface IV1PoolOracle {
function read(uint256 price, uint256 timestamp)
external
view
returns (
uint256,
uint256,
uint256,
uint256,
uint256,
uint256
);

function latestAnswer() external view returns (uint256);

function liquidityPool() external view returns (address);
}

interface ILiquidityPoolV1Converter {
function reserveTokens(uint256 index) external view returns (address);
}
111 changes: 111 additions & 0 deletions contracts/feeds/PriceFeedV1PoolOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
pragma solidity >=0.5.0 <0.6.0;

import "./PriceFeeds.sol";
import "./IV1PoolOracle.sol";
import "../openzeppelin/Ownable.sol";
import "../openzeppelin/Address.sol";
import "./IPriceFeeds.sol";

/**
* @notice The Price Feed V1 Pool Oracle contract.
*
* This contract implements V1 Pool Oracle query functionality,
* getting the price and the last timestamp from an external oracle contract.
* */
contract PriceFeedV1PoolOracle is IPriceFeedsExt, Ownable {
/* Storage */

address public v1PoolOracleAddress;
address public rBTCAddress;
cwsnt marked this conversation as resolved.
Show resolved Hide resolved
address public docAddress;

/* Events */
event SetV1PoolOracleAddress(address indexed v1PoolOracleAddress, address changerAddress);
event SetRBTCAddress(address indexed rBTCAddress, address changerAddress);
event SetDOCAddress(address indexed docAddress, address changerAddress);

/* Functions */

/**
* @notice Initialize a new V1 Pool Oracle.
*
* @param _v1PoolOracleAddress The V1 Pool Oracle address.
cwsnt marked this conversation as resolved.
Show resolved Hide resolved
* */
constructor(
address _v1PoolOracleAddress,
address _rBTCAddress,
address _docAddress
) public {
setV1PoolOracleAddress(_v1PoolOracleAddress);
setRBTCAddress(_rBTCAddress);
setDOCAddress(_docAddress);
}

/**
* @notice Get the oracle price.
* @return The price from Oracle.
* */
function latestAnswer() external view returns (uint256) {
require(rBTCAddress != address(0), "rBTC address has not been set");
require(docAddress != address(0), "DOC address has not been set");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls move this to the constructor not to waste gas on every call


IV1PoolOracle _v1PoolOracle = IV1PoolOracle(v1PoolOracleAddress);
// Need to check, if the requested asset is BTC
address liquidityPool = _v1PoolOracle.liquidityPool();
require(
ILiquidityPoolV1Converter(liquidityPool).reserveTokens(0) != rBTCAddress ||
ILiquidityPoolV1Converter(liquidityPool).reserveTokens(1) != rBTCAddress,
tjcloa marked this conversation as resolved.
Show resolved Hide resolved
"wrBTC price feed cannot use the oracle v1 pool"
);

uint256 _price = _v1PoolOracle.latestAnswer();

// Need to convert to USD, since the V1 pool return value is based on BTC
uint256 priceInUSD = _convertAnswerToUsd(_price);
require(priceInUSD != 0, "price error");

return priceInUSD;
}

function _convertAnswerToUsd(uint256 _valueInBTC) private view returns (uint256) {
uint256 valueInUSD;
address _priceFeeds = msg.sender;

valueInUSD = IPriceFeeds(_priceFeeds).queryReturn(rBTCAddress, docAddress, _valueInBTC);

return valueInUSD;
}

/**
* @notice Set the V1 Pool Oracle address.
*
* @param _v1PoolOracleAddress The V1 Pool Oracle address.
*/
function setV1PoolOracleAddress(address _v1PoolOracleAddress) public onlyOwner {
require(Address.isContract(_v1PoolOracleAddress), "_v1PoolOracleAddress not a contract");
v1PoolOracleAddress = _v1PoolOracleAddress;
emit SetV1PoolOracleAddress(v1PoolOracleAddress, msg.sender);
}

/**
* @notice Set the rBtc address. V1 pool based price is BTC, so need to convert the value from v1 pool to USD. That's why we need to get the price of the rBtc
*
* @param _rBTCAddress The rBTC address
*/
function setRBTCAddress(address _rBTCAddress) public onlyOwner {
require(_rBTCAddress != address(0), "rBTC address cannot be zero address");
rBTCAddress = _rBTCAddress;
emit SetRBTCAddress(rBTCAddress, msg.sender);
}

/**
* @notice Set the rBtc address. V1 pool based price is BTC, so need to convert the value from v1 pool to USD. That's why we need to get the price of the rBtc
*
* @param _docAddress The rBTC address
*/
function setDOCAddress(address _docAddress) public onlyOwner {
require(_docAddress != address(0), "DOC address cannot be zero address");
docAddress = _docAddress;
emit SetDOCAddress(_docAddress, msg.sender);
}
}
12 changes: 12 additions & 0 deletions contracts/mockup/LiquidityPoolV1ConverterMockup.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pragma solidity 0.5.17;

import "../interfaces/IERC20.sol";

contract LiquidityPoolV1ConverterMockup {
IERC20[] public reserveTokens;

constructor(IERC20 _token0, IERC20 _token1) public {
reserveTokens.push(_token0);
reserveTokens.push(_token1);
}
}
Comment on lines +1 to +12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider using hh waffle mock https://ethereum-waffle.readthedocs.io/en/latest/mock-contract.html
it prevents polluting the codebase, easy to use and flexible: just name methods and return values right in the test

23 changes: 23 additions & 0 deletions contracts/mockup/PriceFeedV1PoolOracleMockup.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pragma solidity 0.5.17;

contract PriceFeedV1PoolOracleMockup {
uint256 value;
address public liquidityPool;

constructor(uint256 _value, address _liquidityPool) public {
value = _value;
liquidityPool = _liquidityPool;
}

function latestAnswer() external view returns (uint256) {
return value;
}

function setValue(uint256 _value) public {
value = _value;
}

function setLiquidityPool(address _liquidityPool) public {
liquidityPool = _liquidityPool;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider using hh waffle mock https://ethereum-waffle.readthedocs.io/en/latest/mock-contract.html
it prevents polluting the codebase, easy to use and flexible: just name methods and return values right in the test

}
}
5 changes: 2 additions & 3 deletions contracts/mockup/StakingMockup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ contract StakingMockup is Staking {
}

/**
* @dev We need this function to simulate zero delegate checkpoint value.
*/
* @dev We need this function to simulate zero delegate checkpoint value.
*/
function setDelegateStake(
address delegatee,
uint256 lockedTS,
Expand All @@ -60,5 +60,4 @@ contract StakingMockup is Staking {
bytes32 codeHash = _getCodeHash(_contract);
return vestingCodeHashes[codeHash];
}

}
30 changes: 14 additions & 16 deletions contracts/mockup/VestingLogicMockup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@ pragma experimental ABIEncoderV2;
import "../governance/Vesting/VestingLogic.sol";

contract VestingLogicMockup is VestingLogic {
/**
* @dev we had a bug in a loop: "i < endDate" instead of "i <= endDate"
*/
function delegate(address _delegatee) public onlyTokenOwner {
require(_delegatee != address(0), "delegatee address invalid");
Comment on lines +7 to +11
Copy link
Contributor

@tjcloa tjcloa Jul 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls check that your formatter settings correspond to those in development branch and prettier is active


/**
* @dev we had a bug in a loop: "i < endDate" instead of "i <= endDate"
*/
function delegate(address _delegatee) public onlyTokenOwner {
require(_delegatee != address(0), "delegatee address invalid");

/// @dev Withdraw for each unlocked position.
/// @dev Don't change FOUR_WEEKS to TWO_WEEKS, a lot of vestings already deployed with FOUR_WEEKS
/// workaround found, but it doesn't work with TWO_WEEKS
for (uint256 i = startDate + cliff; i < endDate; i += FOUR_WEEKS) {
staking.delegate(_delegatee, i);
}
emit VotesDelegated(msg.sender, _delegatee);
}

}
/// @dev Withdraw for each unlocked position.
/// @dev Don't change FOUR_WEEKS to TWO_WEEKS, a lot of vestings already deployed with FOUR_WEEKS
/// workaround found, but it doesn't work with TWO_WEEKS
for (uint256 i = startDate + cliff; i < endDate; i += FOUR_WEEKS) {
staking.delegate(_delegatee, i);
}
emit VotesDelegated(msg.sender, _delegatee);
}
}
40 changes: 1 addition & 39 deletions scripts/contractInteraction/contract_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,42 +28,4 @@ def main():
conf.loadConfig()

#call the function you want here








































12 changes: 12 additions & 0 deletions scripts/contractInteraction/prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,15 @@ def checkRates():
def readPriceFeedFor(tokenAddress):
feeds = Contract.from_abi("PriceFeeds", address= conf.contracts['PriceFeeds'], abi = PriceFeeds.abi, owner = conf.acct)
print(feeds.pricesFeeds(tokenAddress))

def deployOracleV1Pool():
oraclePoolAsset = "0x28A05da0939853F7Bc9D5A17C9550D2769eE93D3" #SOV/WRBTC -- for SOV asset
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why hardcoded?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one, is the v1 pool asset that's just created by rahne. I will put it in testnet_contracts.json later

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change it to pulling from the contracts lists as otherwise it is a potential issue

oracleV1PoolPriceFeed = conf.acct.deploy(PriceFeedV1PoolOracle, oraclePoolAsset, conf.contracts['WRBTC'], conf.contracts['DoC'])
print("new oracle v1 pool price feed: ", oracleV1PoolPriceFeed.address)

feeds = Contract.from_abi("PriceFeeds", address= conf.contracts['PriceFeeds'], abi = PriceFeeds.abi, owner = conf.acct)
data = feeds.setPriceFeed.encode_input([conf.contracts['SOV']], [oracleV1PoolPriceFeed.address])
multisig = Contract.from_abi("MultiSig", address=conf.contracts['multisig'], abi=MultiSigWallet.abi, owner=conf.acct)
tx = multisig.submitTransaction(feeds.address,0,data)
txId = tx.events["Submission"]["transactionId"]
print("txid: ",txId)
5 changes: 4 additions & 1 deletion tests-js/Governance/GovernorAlpha/QueueTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ contract("GovernorAlpha#queue/1", (accounts) => {
const txVote2 = await gov.castVote(proposalId2, true, { from: a2 });
await advanceBlocks(30);

await expectRevert(gov.queueProposals([proposalId1, proposalId2]), "revert GovernorAlpha::_queueOrRevert: proposal action already queued at eta");
await expectRevert(
gov.queueProposals([proposalId1, proposalId2]),
"revert GovernorAlpha::_queueOrRevert: proposal action already queued at eta"
);

await gov.queue(proposalId1);
await increaseTime(60);
Expand Down
4 changes: 3 additions & 1 deletion tests-js/affiliates.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ contract("Affiliates", (accounts) => {

// Creating the instance of newLockedSOV Contract.
await sovryn.setLockedSOVAddress(
(await LockedSOV.new(tokenSOV.address, vestingRegistry.address, cliff, duration, [owner])).address
(
await LockedSOV.new(tokenSOV.address, vestingRegistry.address, cliff, duration, [owner])
).address
Comment on lines +109 to +111
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is false positive
shouldn't change with proper formatting switched on

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be because of "Fit code within this line limit" parameters in visual code? what is the correct value should i use?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be
try to switch it off and see the result

);
lockedSOV = await LockedSOV.at(await sovryn.lockedSOVAddress());
});
Expand Down
Loading