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

Feature/pool v2 #832

Merged
merged 11 commits into from
Nov 17, 2023
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
"UbiquiStick",
"Unassigns",
"uncollateralized",
"unneccessary",
rndquu marked this conversation as resolved.
Show resolved Hide resolved
"usedapp",
"Vitalik",
"wagmi",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {CreditNftRedemptionCalculatorFacet} from "../../../../src/dollar/facets/
import {CreditRedemptionCalculatorFacet} from "../../../../src/dollar/facets/CreditRedemptionCalculatorFacet.sol";
import {DollarMintCalculatorFacet} from "../../../../src/dollar/facets/DollarMintCalculatorFacet.sol";
import {DollarMintExcessFacet} from "../../../../src/dollar/facets/DollarMintExcessFacet.sol";
import {UbiquityPoolFacet} from "../../../../src/dollar/facets/UbiquityPoolFacet.sol";
import {Diamond, DiamondArgs} from "../../../../src/dollar/Diamond.sol";
import {DiamondInit} from "../../../../src/dollar/upgradeInitializers/DiamondInit.sol";
import {UbiquityDollarToken} from "../../../../src/dollar/core/UbiquityDollarToken.sol";
Expand Down Expand Up @@ -48,6 +49,7 @@ contract DiamondScript is Constants {
bytes4[] selectorsOfStakingFacet;
bytes4[] selectorsOfStakingFormulasFacet;
bytes4[] selectorsOfTWAPOracleDollar3poolFacet;
bytes4[] selectorsOfUbiquityPoolFacet;

// contract types of facets to be deployed
Diamond diamond;
Expand All @@ -66,6 +68,7 @@ contract DiamondScript is Constants {
ChefFacet chefFacet;
StakingFacet stakingFacet;
StakingFormulasFacet stakingFormulasFacet;
UbiquityPoolFacet ubiquityPoolFacet;

CreditNftManagerFacet creditNftManagerFacet;
CreditNftRedemptionCalculatorFacet creditNftRedemptionCalculatorFacet;
Expand All @@ -91,6 +94,7 @@ contract DiamondScript is Constants {
chefFacet = new ChefFacet();
stakingFacet = new StakingFacet();
stakingFormulasFacet = new StakingFormulasFacet();
ubiquityPoolFacet = new UbiquityPoolFacet();

creditNftManagerFacet = new CreditNftManagerFacet();
creditNftRedemptionCalculatorFacet = new CreditNftRedemptionCalculatorFacet();
Expand All @@ -117,7 +121,8 @@ contract DiamondScript is Constants {
"CreditRedemptionCalculatorFacet",
"DollarMintCalculatorFacet",
"DollarMintExcessFacet",
"CreditClockFacet"
"CreditClockFacet",
"UbiquityPoolFacet"
];

DiamondInit.Args memory initArgs = DiamondInit.Args({
Expand All @@ -137,7 +142,7 @@ contract DiamondScript is Constants {
initArgs
)
});
IDiamondCut.FacetCut[] memory cuts = new IDiamondCut.FacetCut[](16);
IDiamondCut.FacetCut[] memory cuts = new IDiamondCut.FacetCut[](17);
setFacet(cuts);
// deploy diamond

Expand All @@ -146,6 +151,28 @@ contract DiamondScript is Constants {
IAccessControl = AccessControlFacet(address(diamond));
StakingFacet IStakingFacet = StakingFacet(address(diamond));
IStakingFacet.setBlockCountInAWeek(420);

// init UbiquityPool
// add collateral LUSD token
uint256 poolCeiling = 50_000e18; // max 50_000 of collateral tokens is allowed
rndquu marked this conversation as resolved.
Show resolved Hide resolved
address lusdAddress = 0x5f98805A4E8be255a32880FDeC7F6728C6568bA0;
UbiquityPoolFacet(address(diamond)).addCollateralToken(
lusdAddress,
poolCeiling
);
// enable collateral at index 0
UbiquityPoolFacet(address(diamond)).toggleCollateral(0);
// set mint and redeem fees
UbiquityPoolFacet(address(diamond)).setFees(
0, // collateral index
0, // 0% mint fee
0 // 0% redeem fee
);
// set redemption delay to 2 blocks
UbiquityPoolFacet(address(diamond)).setRedemptionDelay(2);
// set mint price threshold to $1.01 and redeem price to $0.99
UbiquityPoolFacet(address(diamond)).setPriceThresholds(1010000, 990000);

vm.stopBroadcast();
}

Expand Down Expand Up @@ -267,6 +294,13 @@ contract DiamondScript is Constants {
functionSelectors: selectorsOfCreditClockFacet
})
);
cuts[16] = (
IDiamondCut.FacetCut({
facetAddress: address(ubiquityPoolFacet),
action: IDiamondCut.FacetCutAction.Add,
functionSelectors: selectorsOfUbiquityPoolFacet
})
);
}

function getSelectors() internal {
Expand Down Expand Up @@ -319,5 +353,8 @@ contract DiamondScript is Constants {
selectorsOfTWAPOracleDollar3poolFacet = getSelectorsFromAbi(
"/out/TWAPOracleDollar3poolFacet.sol/TWAPOracleDollar3poolFacet.json"
);
selectorsOfUbiquityPoolFacet = getSelectorsFromAbi(
"/out/UbiquityPoolFacet.sol/UbiquityPoolFacet.json"
);
}
}
204 changes: 151 additions & 53 deletions packages/contracts/src/dollar/facets/UbiquityPoolFacet.sol
Original file line number Diff line number Diff line change
@@ -1,99 +1,197 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.19;

// Modified from FraxPool.sol by Frax Finance
// https://github.com/FraxFinance/frax-solidity/blob/master/src/hardhat/contracts/Frax/Pools/FraxPool.sol

import {LibUbiquityPool} from "../libraries/LibUbiquityPool.sol";
import {IUbiquityPool} from "../interfaces/IUbiquityPool.sol";
import {Modifiers} from "../libraries/LibAppStorage.sol";
import {IMetaPool} from "../interfaces/IMetaPool.sol";
import "../interfaces/IUbiquityPool.sol";
import {LibUbiquityPool} from "../libraries/LibUbiquityPool.sol";

/**
* @notice Ubiquity pool facet
* @notice Allows users to:
* - deposit collateral in exchange for Ubiquity Dollars
* - redeem Ubiquity Dollars in exchange for the earlier provided collateral
*/
contract UbiquityPoolFacet is Modifiers, IUbiquityPool {
contract UbiquityPoolFacet is IUbiquityPool, Modifiers {
//=====================
// Views
//=====================

/// @inheritdoc IUbiquityPool
function allCollaterals() external view returns (address[] memory) {
return LibUbiquityPool.allCollaterals();
}

/// @inheritdoc IUbiquityPool
function collateralInformation(
address collateralAddress
)
external
view
returns (LibUbiquityPool.CollateralInformation memory returnData)
{
return LibUbiquityPool.collateralInformation(collateralAddress);
}

/// @inheritdoc IUbiquityPool
function collateralUsdBalance()
external
view
returns (uint256 balanceTally)
{
return LibUbiquityPool.collateralUsdBalance();
}

/// @inheritdoc IUbiquityPool
function freeCollateralBalance(
uint256 collateralIndex
) external view returns (uint256) {
return LibUbiquityPool.freeCollateralBalance(collateralIndex);
}

/// @inheritdoc IUbiquityPool
function getDollarInCollateral(
uint256 collateralIndex,
uint256 dollarAmount
) external view returns (uint256) {
return
LibUbiquityPool.getDollarInCollateral(
collateralIndex,
dollarAmount
);
}

/// @inheritdoc IUbiquityPool
function getDollarPriceUsd()
external
view
returns (uint256 dollarPriceUsd)
{
return LibUbiquityPool.getDollarPriceUsd();
}

//====================
// Public functions
//====================

/// @inheritdoc IUbiquityPool
function mintDollar(
address collateralAddress,
uint256 collateralAmount,
uint256 dollarOutMin
) external {
LibUbiquityPool.mintDollar(
collateralAddress,
collateralAmount,
dollarOutMin
);
uint256 collateralIndex,
uint256 dollarAmount,
uint256 dollarOutMin,
uint256 maxCollateralIn
) external returns (uint256 totalDollarMint, uint256 collateralNeeded) {
return
LibUbiquityPool.mintDollar(
collateralIndex,
dollarAmount,
dollarOutMin,
maxCollateralIn
);
}

/// @inheritdoc IUbiquityPool
function redeemDollar(
address collateralAddress,
uint256 collateralIndex,
uint256 dollarAmount,
uint256 collateralOutMin
) external {
LibUbiquityPool.redeemDollar(
collateralAddress,
dollarAmount,
collateralOutMin
);
) external returns (uint256 collateralOut) {
return
LibUbiquityPool.redeemDollar(
collateralIndex,
dollarAmount,
collateralOutMin
);
}

/// @inheritdoc IUbiquityPool
function collectRedemption(
uint256 collateralIndex
) external returns (uint256 collateralAmount) {
return LibUbiquityPool.collectRedemption(collateralIndex);
}

//=========================
// AMO minters functions
//=========================

/// @inheritdoc IUbiquityPool
function amoMinterBorrow(uint256 collateralAmount) external {
LibUbiquityPool.amoMinterBorrow(collateralAmount);
}

//========================
// Restricted functions
//========================

/// @inheritdoc IUbiquityPool
function collectRedemption(address collateralAddress) external {
LibUbiquityPool.collectRedemption(collateralAddress);
function addAmoMinter(address amoMinterAddress) external onlyAdmin {
LibUbiquityPool.addAmoMinter(amoMinterAddress);
}

/// @inheritdoc IUbiquityPool
function addToken(
function addCollateralToken(
address collateralAddress,
IMetaPool collateralMetaPool
uint256 poolCeiling
) external onlyAdmin {
LibUbiquityPool.addToken(collateralAddress, collateralMetaPool);
LibUbiquityPool.addCollateralToken(collateralAddress, poolCeiling);
}

/// @inheritdoc IUbiquityPool
function setRedeemActive(
address collateralAddress,
bool notRedeemPaused
function removeAmoMinter(address amoMinterAddress) external onlyAdmin {
LibUbiquityPool.removeAmoMinter(amoMinterAddress);
}

/// @inheritdoc IUbiquityPool
function setCollateralPrice(
uint256 collateralIndex,
uint256 newPrice
) external onlyAdmin {
LibUbiquityPool.setRedeemActive(collateralAddress, notRedeemPaused);
LibUbiquityPool.setCollateralPrice(collateralIndex, newPrice);
}

/// @inheritdoc IUbiquityPool
function getRedeemActive(
address _collateralAddress
) external view returns (bool) {
return LibUbiquityPool.getRedeemActive(_collateralAddress);
function setFees(
uint256 collateralIndex,
uint256 newMintFee,
uint256 newRedeemFee
) external onlyAdmin {
LibUbiquityPool.setFees(collateralIndex, newMintFee, newRedeemFee);
}

/// @inheritdoc IUbiquityPool
function setMintActive(
address collateralAddress,
bool notMintPaused
function setPoolCeiling(
uint256 collateralIndex,
uint256 newCeiling
) external onlyAdmin {
LibUbiquityPool.setMintActive(collateralAddress, notMintPaused);
LibUbiquityPool.setPoolCeiling(collateralIndex, newCeiling);
}

/// @inheritdoc IUbiquityPool
function getMintActive(
address _collateralAddress
) external view returns (bool) {
return LibUbiquityPool.getMintActive(_collateralAddress);
function setPriceThresholds(
uint256 newMintPriceThreshold,
uint256 newRedeemPriceThreshold
) external onlyAdmin {
LibUbiquityPool.setPriceThresholds(
newMintPriceThreshold,
newRedeemPriceThreshold
);
}

/// @inheritdoc IUbiquityPool
function getRedeemCollateralBalances(
address account,
address collateralAddress
) external view returns (uint256) {
return
LibUbiquityPool.getRedeemCollateralBalances(
account,
collateralAddress
);
function setRedemptionDelay(uint256 newRedemptionDelay) external onlyAdmin {
LibUbiquityPool.setRedemptionDelay(newRedemptionDelay);
}

/// @inheritdoc IUbiquityPool
function toggleCollateral(uint256 collateralIndex) external onlyAdmin {
LibUbiquityPool.toggleCollateral(collateralIndex);
}

/// @inheritdoc IUbiquityPool
function toggleMRB(
uint256 collateralIndex,
uint8 toggleIndex
) external onlyAdmin {
LibUbiquityPool.toggleMRB(collateralIndex, toggleIndex);
}
}
14 changes: 14 additions & 0 deletions packages/contracts/src/dollar/interfaces/IDollarAmoMinter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

/// @notice AMO minter interface
/// @dev AMO minter can borrow collateral from the Ubiquity Pool to make some yield
interface IDollarAmoMinter {
/// @notice Returns collateral Dollar balance
/// @return Collateral Dollar balance
function collateralDollarBalance() external view returns (uint256);

/// @notice Returns collateral index (from the Ubiquity Pool) for which AMO minter is responsible
/// @return Collateral token index
function collateralIndex() external view returns (uint256);
}
Loading
Loading