Skip to content

Commit

Permalink
test(lib-ubiquity-pool): add conservative estimates for price and fees
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandr-masl committed Aug 31, 2024
1 parent 5407774 commit dd94c7e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ contract PoolFacetHandler is Test {
//========================
function setDollarPriceAboveThreshold() public {
vm.prank(admin);
curveDollarPlainPool.updateMockParams(1.02e18);
curveDollarPlainPool.updateMockParams(1.01e18);
// curveDollarPlainPool.updateMockParams(1.02e18);
}

function setDollarPriceBelowThreshold() public {
Expand All @@ -48,14 +49,17 @@ contract PoolFacetHandler is Test {

// Redeem manipulations
//========================
function setMintAndRedeemFees(uint256 mintFee, uint256 redeemFee) public {
function setRedemptionDelay(uint256 delay) public {
vm.prank(admin);
ubiquityPoolFacet.setFees(0, mintFee, redeemFee);
ubiquityPoolFacet.setRedemptionDelayBlocks(delay);
}

function setRedemptionDelay(uint256 delay) public {
function setMintAndRedeemFees(uint256 mintFee, uint256 redeemFee) public {
vm.assume(mintFee >= 100000 && mintFee <= 200000);
vm.assume(redeemFee >= 100000 && redeemFee <= 200000);

vm.prank(admin);
ubiquityPoolFacet.setRedemptionDelayBlocks(delay);
ubiquityPoolFacet.setFees(0, mintFee, redeemFee);
}

function collectRedemption() public {
Expand Down Expand Up @@ -96,7 +100,7 @@ contract PoolFacetHandler is Test {
// Collateral price manipulations
//========================
function updateCollateralPrice(int256 _newPrice) public {
vm.assume(_newPrice >= 50_000_000 && _newPrice <= 200_000_000);
vm.assume(_newPrice >= 100_000_000 && _newPrice <= 200_000_000);

collateralTokenPriceFeed.updateMockParams(
1, // round id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ contract UbiquityPoolFacetInvariantTest is DiamondTestSetup {
// set ETH/Governance initial price to 20k in Curve pool mock (20k GOV == 1 ETH)
curveGovernanceEthPool.updateMockParams(20_000e18);

curveDollarPlainPool.updateMockParams(1.01e18);

// set price feed for collateral token
ubiquityPoolFacet.setCollateralChainLinkPriceFeed(
address(collateralToken), // collateral token address
Expand Down Expand Up @@ -153,6 +155,9 @@ contract UbiquityPoolFacetInvariantTest is DiamondTestSetup {
user,
curveDollarPlainPool
);

handler.mintUbiquityDollars(1e18, 0.9e18, 1e18, 0, true);

targetContract(address(handler));
}

Expand All @@ -162,30 +167,13 @@ contract UbiquityPoolFacetInvariantTest is DiamondTestSetup {
).totalSupply();

uint256 collateralUsdBalance = ubiquityPoolFacet.collateralUsdBalance();
console.log(
":::::::| UbiquityPoolFacetInvariantTest | collateralUsdBalance:",
collateralUsdBalance
);

vm.assume(collateralUsdBalance > 0 && totalDollarSupply > 0);

uint256 dollarPrice = ubiquityPoolFacet.getDollarPriceUsd();
uint256 totalDollarSupplyInUsd = (totalDollarSupply * dollarPrice) /
1e6;

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

assertTrue(
totalDollarSupplyInUsd <= collateralUsdBalance,
"Minted dollars exceed collateral value"
Expand Down

0 comments on commit dd94c7e

Please sign in to comment.