-
Notifications
You must be signed in to change notification settings - Fork 2
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 #69 from valory-xyz/testdepository
test: deep investigate ProductSupplyLow vs ds-math-sub-underflow
- Loading branch information
Showing
14 changed files
with
161 additions
and
87 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 |
---|---|---|
|
@@ -9,9 +9,9 @@ import "./interfaces/IErrors.sol"; | |
import "./interfaces/ITreasury.sol"; | ||
import "./interfaces/ITokenomics.sol"; | ||
|
||
|
||
/// @title Bond Depository - Smart contract for OLA Bond Depository | ||
/// @author AL | ||
/// @author Aleksandr Kuperman - <[email protected]> | ||
contract Depository is IErrors, Ownable { | ||
using SafeERC20 for IERC20; | ||
|
||
|
@@ -100,10 +100,10 @@ contract Depository is IErrors, Ownable { | |
} | ||
|
||
// Calculate the payout in OLA tokens based on the LP pair with the discount factor (DF) calculation | ||
uint256 _epoch = block.number / ITokenomics(tokenomics).epochLen(); | ||
uint256 epoch = block.number / ITokenomics(tokenomics).epochLen(); | ||
// df uint with defined decimals | ||
payout = ITokenomics(tokenomics).calculatePayoutFromLP(token, tokenAmount, _epoch); | ||
|
||
payout = ITokenomics(tokenomics).calculatePayoutFromLP(token, tokenAmount, epoch); | ||
// Check for the sufficient supply | ||
if (payout > product.supply) { | ||
revert ProductSupplyLow(token, productId, payout, product.supply); | ||
|
@@ -124,6 +124,10 @@ contract Depository is IErrors, Ownable { | |
// Take into account this bond in current epoch | ||
ITokenomics(tokenomics).usedBond(payout); | ||
|
||
// Uniswap allowance implementation does not revert with the accurate message, check before SafeMath is engaged | ||
if (product.token.allowance(msg.sender, address(this)) < tokenAmount) { | ||
revert InsufficientAllowance(product.token.allowance((msg.sender), address(this)), tokenAmount); | ||
} | ||
// Transfer tokens to the depository | ||
product.token.safeTransferFrom(msg.sender, address(this), tokenAmount); | ||
// Approve treasury for the specified token amount | ||
|
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 |
---|---|---|
|
@@ -15,6 +15,7 @@ import "./interfaces/ITokenomics.sol"; | |
|
||
/// @title Dispenser - Smart contract for rewards | ||
/// @author AL | ||
/// @author Aleksandr Kuperman - <[email protected]> | ||
contract Dispenser is IErrors, IStructs, Ownable, Pausable, ReentrancyGuard { | ||
using SafeERC20 for IERC20; | ||
|
||
|
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 |
---|---|---|
|
@@ -11,8 +11,10 @@ import "./interfaces/IStructs.sol"; | |
import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol"; | ||
|
||
|
||
|
||
/// @title Tokenomics - Smart contract for store/interface for key tokenomics params | ||
/// @author AL | ||
/// @author Aleksandr Kuperman - <[email protected]> | ||
contract Tokenomics is IErrors, IStructs, Ownable { | ||
using FixedPoint for *; | ||
|
||
|
@@ -488,16 +490,16 @@ contract Tokenomics is IErrors, IStructs, Ownable { | |
// @dev Calculates the amount of OLA tokens based on LP (see the doc for explanation of price computation). Any can do it | ||
/// @param token Token address. | ||
/// @param tokenAmount Token amount. | ||
/// @param _epoch epoch number | ||
/// @param epoch epoch number | ||
/// @return resAmount Resulting amount of OLA tokens. | ||
function calculatePayoutFromLP(address token, uint256 tokenAmount, uint _epoch) external view | ||
function calculatePayoutFromLP(address token, uint256 tokenAmount, uint256 epoch) external view | ||
returns (uint256 resAmount) | ||
{ | ||
uint256 df; | ||
PointEcomonics memory _PE; | ||
// avoid start checkpoint from calculatePayoutFromLP | ||
uint256 _epochC = _epoch + 1; | ||
for (uint256 i = _epochC; i > 0; i--) { | ||
uint256 epochC = epoch + 1; | ||
for (uint256 i = epochC; i > 0; i--) { | ||
_PE = mapEpochEconomics[i-1]; | ||
// if current point undefined, so calculatePayoutFromLP called before mined tx(checkpoint) | ||
if(_PE.exists) { | ||
|
@@ -545,6 +547,7 @@ contract Tokenomics is IErrors, IStructs, Ownable { | |
balance1 -= amount1; | ||
uint256 reserveIn = (token0 == ola) ? balance1 : balance0; | ||
uint256 reserveOut = (token0 == ola) ? balance0 : balance1; | ||
|
||
amountOLA = amountOLA + getAmountOut(amountPairForOLA, reserveIn, reserveOut); | ||
|
||
// The resulting DF amount cannot be bigger than the maximum possible one | ||
|
@@ -584,10 +587,10 @@ contract Tokenomics is IErrors, IStructs, Ownable { | |
} | ||
|
||
/// @dev get Point by epoch | ||
/// @param _epoch number of a epoch | ||
/// @param epoch number of a epoch | ||
/// @return _PE raw point | ||
function getPoint(uint256 _epoch) public view returns (PointEcomonics memory _PE) { | ||
_PE = mapEpochEconomics[_epoch]; | ||
function getPoint(uint256 epoch) public view returns (PointEcomonics memory _PE) { | ||
_PE = mapEpochEconomics[epoch]; | ||
} | ||
|
||
/// @dev Get last epoch Point. | ||
|
@@ -597,10 +600,10 @@ contract Tokenomics is IErrors, IStructs, Ownable { | |
} | ||
|
||
// decode a uq112x112 into a uint with 18 decimals of precision (cycle into the past), INITIAL_DF if not exist | ||
function getDF(uint256 _epoch) public view returns (uint256 df) { | ||
function getDF(uint256 epoch) public view returns (uint256 df) { | ||
PointEcomonics memory _PE; | ||
uint256 _epochC = _epoch + 1; | ||
for (uint256 i = _epochC; i > 0; i--) { | ||
uint256 epochC = epoch + 1; | ||
for (uint256 i = epochC; i > 0; i--) { | ||
_PE = mapEpochEconomics[i-1]; | ||
// if current point undefined, so getDF called before mined tx(checkpoint) | ||
if(_PE.exists) { | ||
|
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 |
---|---|---|
|
@@ -12,6 +12,7 @@ import "./interfaces/IStructs.sol"; | |
|
||
/// @title Treasury - Smart contract for managing OLA Treasury | ||
/// @author AL | ||
/// @author Aleksandr Kuperman - <[email protected]> | ||
contract Treasury is IErrors, IStructs, Ownable, ReentrancyGuard { | ||
using SafeERC20 for IERC20; | ||
|
||
|
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
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.