Skip to content

Commit

Permalink
test(pool-facet-handler): add usd price manipulations
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandr-masl committed Aug 31, 2024
1 parent 989d9c6 commit 1b7f1da
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ contract PoolFacetHandler is Test {
using SafeMath for uint256;

MockChainLinkFeed collateralTokenPriceFeed;
MockChainLinkFeed stableUsdPriceFeed;
UbiquityPoolFacet ubiquityPoolFacet;
address admin;
address user;
Expand All @@ -25,12 +26,14 @@ contract PoolFacetHandler is Test {

constructor(
MockChainLinkFeed _collateralTokenPriceFeed,
MockChainLinkFeed _stableUsdPriceFeed,
UbiquityPoolFacet _ubiquityPoolFacet,
address _admin,
address _user,
MockCurveStableSwapNG _curveDollarPlainPool
) {
collateralTokenPriceFeed = _collateralTokenPriceFeed;
stableUsdPriceFeed = _stableUsdPriceFeed;
ubiquityPoolFacet = _ubiquityPoolFacet;
admin = _admin;
user = _user;
Expand Down Expand Up @@ -115,12 +118,12 @@ contract PoolFacetHandler is Test {

// Collateral price manipulations
//========================
function updateCollateralPrice(int256 _newPrice) public {
function setCollateralPrice(int256 _newPrice) public {
vm.assume(_newPrice >= 50_000_000 && _newPrice <= 200_000_000);

collateralTokenPriceFeed.updateMockParams(
1, // round id
_newPrice, // new price (8 decimals)
_newPrice,
block.timestamp, // started at
block.timestamp, // updated at
1 // answered in round
Expand All @@ -132,6 +135,23 @@ contract PoolFacetHandler is Test {
ubiquityPoolFacet.setCollateralRatio(newCollateralRatio);
}

// USD stablecoin price manipulations
//========================
function setStableUsdPrice(uint256 _newPrice) public {
vm.assume(_newPrice >= 0.5e8 && _newPrice <= 1.5e8); // Assume a range for testing

stableUsdPriceFeed.updateMockParams(
1, // round id
int256(_newPrice),
block.timestamp, // started at
block.timestamp, // updated at
1 // answered in round
);

uint256 newCollateralRatio = uint256(1e6 * 1e8).div(_newPrice);
ubiquityPoolFacet.setCollateralRatio(newCollateralRatio);
}

function mintUbiquityDollars(
uint256 _dollarAmount,
uint256 _dollarOutMin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ contract UbiquityPoolFacetInvariantTest is DiamondTestSetup {

handler = new PoolFacetHandler(
collateralTokenPriceFeed,
stableUsdPriceFeed,
ubiquityPoolFacet,
admin,
user,
Expand Down Expand Up @@ -178,21 +179,6 @@ contract UbiquityPoolFacetInvariantTest is DiamondTestSetup {
uint256 totalDollarSupplyInUsd = (totalDollarSupply * dollarPrice) /
1e6;

uint256 ratio = ubiquityPoolFacet.collateralRatio();

console.log(
":::::::| UbiquityPoolFacetInvariantTest | collateralRatio:",
ratio
);

console.log(
":::::::| UbiquityPoolFacetInvariantTest | dollarPrice:",
dollarPrice
);
console.log(
":::::::| UbiquityPoolFacetInvariantTest | totalDollarSupply:",
totalDollarSupply
);
console.log(
":::::::| UbiquityPoolFacetInvariantTest11 | totalDollarSupplyInUsd:",
totalDollarSupplyInUsd
Expand Down

0 comments on commit 1b7f1da

Please sign in to comment.