Skip to content

Commit

Permalink
Merge pull request #530 from rndquu/feature/489
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4007 authored Feb 2, 2023
2 parents f0ca041 + f5a57cb commit f64dc4c
Show file tree
Hide file tree
Showing 9 changed files with 667 additions and 223 deletions.
25 changes: 0 additions & 25 deletions packages/contracts/src/ubiquistick/UAR.sol

This file was deleted.

6 changes: 3 additions & 3 deletions packages/contracts/test/dollar/UbiquityChef.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.3;
pragma solidity 0.8.16;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../helpers/LiveTestHelper.sol";
Expand Down Expand Up @@ -110,7 +110,7 @@ contract RemoteDepositStateTest is DepositState {
}

function testWithdraw(uint256 amount, uint256 blocks) public {
blocks = bound(blocks, 1, 2**64-1);
blocks = bound(blocks, 1, 2 ** 64 - 1);
amount = bound(amount, 1, shares);
uint256 preBal = governanceToken.balanceOf(fourthAccount);
uint256 preBal_ = metapool.balanceOf(fourthAccount);
Expand All @@ -123,7 +123,7 @@ contract RemoteDepositStateTest is DepositState {
}

function testGetRewards(uint256 blocks) public {
blocks = bound(blocks, 1, 2**64-1);
blocks = bound(blocks, 1, 2 ** 64 - 1);
uint256 preBal = governanceToken.balanceOf(fourthAccount);
vm.roll(block.number + blocks);

Expand Down
65 changes: 65 additions & 0 deletions packages/contracts/test/dollar/UbiquityFormulas.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;

import "forge-std/Test.sol";

import "../../src/dollar/UbiquityFormulas.sol";

contract UbiquityFormulasTest is Test {
UbiquityFormulas ubiquityFormulas;

function setUp() public {
ubiquityFormulas = new UbiquityFormulas();
}

function testDurationMultiply_ShouldReturnAmount() public {
uint amount = ubiquityFormulas.durationMultiply(
100 ether,
1,
1000000 gwei
);
assertEq(amount, 100100000000000000000);
}

function testStaking_ShouldReturnAmount() public {
uint amount = ubiquityFormulas.staking(100 ether, 2 ether, 3 ether);
assertEq(amount, 150000000000000000000);
}

function testRedeemShares_ShouldReturnAmount() public {
uint amount = ubiquityFormulas.redeemShares(
100 ether,
2 ether,
3 ether
);
assertEq(amount, 66666666666666666666);
}

function testSharePrice_ShouldReturnAmount() public {
uint amount = ubiquityFormulas.sharePrice(
100 ether,
100 ether,
1 ether
);
assertEq(amount, 1000000000000000000);
}

function testGovernanceMultiply_ShouldReturnAmount() public {
uint amount = ubiquityFormulas.governanceMultiply(1e18, 1 ether);
assertEq(amount, 1050000000000000000);
}

function testGovernanceMultiply_ShouldReturnAmount_IfNewMultiplierIsTooBig()
public
{
uint amount = ubiquityFormulas.governanceMultiply(100e18, 1 ether);
assertEq(amount, 100000000000000000000);
}

function testGovernanceMultiply_ShouldReturnAmount_IfNewMultiplierIsTooSmall()
public
{
uint amount = ubiquityFormulas.governanceMultiply(1e6, 1 ether);
assertEq(amount, 1000000);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;

import "../../../src/dollar/core/CreditRedemptionCalculator.sol";
import "../../helpers/LocalTestHelper.sol";

contract CreditRedemptionCalculatorTest is LocalTestHelper {
CreditRedemptionCalculator creditCalc;

// test users
address user;

function setUp() public override {
super.setUp();

user = address(0x01);

creditCalc = new CreditRedemptionCalculator(manager);
}

function testConstructor_ShouldInitContract() public {
assertEq(address(creditCalc.manager()), address(manager));
}

function testSetConstant_ShouldRevert_IfCalledNotByAdmin() public {
vm.prank(user);
vm.expectRevert("CreditCalculator: not admin");
creditCalc.setConstant(2 ether);
}

function testSetConstant_ShouldUpdateCoef() public {
vm.prank(admin);
creditCalc.setConstant(2 ether);
assertEq(creditCalc.getConstant(), 2 ether);
}

function testGetCreditAmount_ShouldRevert_IfDebtIsTooHigh() public {
vm.mockCall(
manager.dollarTokenAddress(),
abi.encodeWithSelector(IERC20.totalSupply.selector),
abi.encode(1)
);
vm.expectRevert("Credit to Dollar: DEBT_TOO_HIGH");
creditCalc.getCreditAmount(1 ether, 10);
}
}
2 changes: 1 addition & 1 deletion packages/contracts/test/dollar/core/DollarMintExcess.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.3;
pragma solidity 0.8.16;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
Expand Down
23 changes: 23 additions & 0 deletions packages/contracts/test/dollar/core/UbiquityCreditToken.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;

import "../../../src/dollar/core/UbiquityCreditToken.sol";
import "../../helpers/LocalTestHelper.sol";

contract UbiquityCreditTokenTest is LocalTestHelper {
UbiquityCreditToken ubiquityCreditToken;

function setUp() public override {
super.setUp();

vm.prank(admin);
ubiquityCreditToken = new UbiquityCreditToken(manager);
}

function testRaiseCapital_ShouldMintTokens() public {
assertEq(ubiquityCreditToken.balanceOf(treasuryAddress), 0);
vm.prank(admin);
ubiquityCreditToken.raiseCapital(1e18);
assertEq(ubiquityCreditToken.balanceOf(treasuryAddress), 1e18);
}
}
2 changes: 1 addition & 1 deletion packages/contracts/test/ubiquistick/SimpleBond.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
pragma solidity 0.8.16;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
Expand Down
Loading

1 comment on commit f64dc4c

@ubiquibot
Copy link

@ubiquibot ubiquibot bot commented on f64dc4c Feb 2, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.