Skip to content

Commit

Permalink
Merge pull request #47 from neptune-mutual-blue/refactor/pod-fungibility
Browse files Browse the repository at this point in the history
POD Fungibility Refactor
  • Loading branch information
binpmxstn committed Apr 11, 2022
2 parents 5ab27cd + 3e3c8cd commit 7c889be
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 52 deletions.
2 changes: 1 addition & 1 deletion contracts/core/delegates/VaultDelegateBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import "../../libraries/StrategyLibV1.sol";

/**
* @title Vault POD (Proof of Deposit)
* @dev The VaultPod has `_mintPods` and `_redeemPods` features which enables
* @dev The VaultPod has `_mintPods` and `_redeemPodCalculation` features which enables
* POD minting and burning on demand. <br /> <br />
*
* **How Does This Work?**
Expand Down
4 changes: 0 additions & 4 deletions contracts/libraries/CoverUtilV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ library CoverUtilV1 {
return keccak256(abi.encodePacked(ProtoUtilV1.NS_COVER_STATUS, key, incidentDate));
}

function getCoverLiquidityAddedKey(bytes32 coverKey, address account) external pure returns (bytes32) {
return keccak256(abi.encodePacked(ProtoUtilV1.NS_COVER_LIQUIDITY_ADDED, coverKey, account));
}

function getCoverLiquidityStakeKey(bytes32 coverKey) external pure returns (bytes32) {
return keccak256(abi.encodePacked(ProtoUtilV1.NS_COVER_LIQUIDITY_STAKE, coverKey));
}
Expand Down
2 changes: 0 additions & 2 deletions contracts/libraries/ProtoUtilV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ library ProtoUtilV1 {
bytes32 public constant NS_COVER_LIQUIDITY_WITHDRAWAL_WINDOW = "ns:cover:liquidity:ww";
bytes32 public constant NS_COVER_LIQUIDITY_MIN_STAKE = "ns:cover:liquidity:min:stake";
bytes32 public constant NS_COVER_LIQUIDITY_STAKE = "ns:cover:liquidity:stake";
bytes32 public constant NS_COVER_LIQUIDITY_ADDED = "ns:cover:liquidity:add";
bytes32 public constant NS_COVER_LIQUIDITY_REMOVED = "ns:cover:liquidity:rem";
bytes32 public constant NS_COVER_LIQUIDITY_COMMITTED = "ns:cover:liquidity:committed";
bytes32 public constant NS_COVER_LIQUIDITY_NAME = "ns:cover:liquidityName";
bytes32 public constant NS_COVER_REQUIRES_WHITELIST = "ns:cover:requires:whitelist";
Expand Down
55 changes: 10 additions & 45 deletions contracts/libraries/VaultLibV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,9 @@ library VaultLibV1 {
* @param values[2] extendedBalance --> Stablecoins lent outside of the protocol
* @param values[3] totalReassurance -- > Total reassurance for this cover
* @param values[4] myPodBalance --> Your POD Balance
* @param values[5] myDeposits --> Sum of your deposits (in stablecoin)
* @param values[6] myWithdrawals --> Sum of your withdrawals (in stablecoin)
* @param values[7] myShare --> My share of the liquidity pool (in stablecoin)
* @param values[8] withdrawalOpen --> The timestamp when withdrawals are opened
* @param values[9] withdrawalClose --> The timestamp when withdrawals are closed again
* @param values[5] myShare --> My share of the liquidity pool (in stablecoin)
* @param values[6] withdrawalOpen --> The timestamp when withdrawals are opened
* @param values[7] withdrawalClose --> The timestamp when withdrawals are closed again
*/
function getInfoInternal(
IStore s,
Expand All @@ -102,27 +100,9 @@ library VaultLibV1 {
values[2] = s.getAmountInStrategies(coverKey, s.getStablecoin()); // Stablecoins lent outside of the protocol
values[3] = s.getReassuranceAmountInternal(coverKey); // Total reassurance for this cover
values[4] = IERC20(pod).balanceOf(you); // Your POD Balance
values[5] = _getCoverLiquidityAddedInternal(s, coverKey, you); // Sum of your deposits (in stablecoin)
values[6] = _getCoverLiquidityRemovedInternal(s, coverKey, you); // Sum of your withdrawals (in stablecoin)
values[7] = calculateLiquidityInternal(s, coverKey, pod, values[5]); // My share of the liquidity pool (in stablecoin)
values[8] = s.getUintByKey(RoutineInvokerLibV1.getNextWithdrawalStartKey(coverKey));
values[9] = s.getUintByKey(RoutineInvokerLibV1.getNextWithdrawalEndKey(coverKey));
}

function _getCoverLiquidityAddedInternal(
IStore s,
bytes32 coverKey,
address you
) private view returns (uint256) {
return s.getUintByKey(CoverUtilV1.getCoverLiquidityAddedKey(coverKey, you));
}

function _getCoverLiquidityRemovedInternal(
IStore s,
bytes32 coverKey,
address you
) private view returns (uint256) {
return s.getUintByKeys(ProtoUtilV1.NS_COVER_LIQUIDITY_REMOVED, coverKey, you);
values[5] = calculateLiquidityInternal(s, coverKey, pod, values[5]); // My share of the liquidity pool (in stablecoin)
values[6] = s.getUintByKey(RoutineInvokerLibV1.getNextWithdrawalStartKey(coverKey));
values[7] = s.getUintByKey(RoutineInvokerLibV1.getNextWithdrawalEndKey(coverKey));
}

/**
Expand All @@ -146,8 +126,6 @@ library VaultLibV1 {

// Update values
myPreviousStake = _updateNpmStake(s, coverKey, account, npmStakeToAdd);
_updateCoverLiquidity(s, coverKey, account, amount);

podsToMint = calculatePodsInternal(s, coverKey, pod, amount);
}

Expand All @@ -166,15 +144,6 @@ library VaultLibV1 {
}
}

function _updateCoverLiquidity(
IStore s,
bytes32 coverKey,
address account,
uint256 amount
) private {
s.addUintByKey(CoverUtilV1.getCoverLiquidityAddedKey(coverKey, account), amount); // Your liquidity
}

function _getMyNpmStake(
IStore s,
bytes32 coverKey,
Expand Down Expand Up @@ -218,9 +187,9 @@ library VaultLibV1 {

// @suppress-address-trust-issue, @suppress-malicious-erc20 The address `pod` although can only
// come from VaultBase, we still need to ensure if it is a protocol member.
// Check `_redeemPods` for more info.
// Check `_redeemPodCalculation` for more info.
// Redeem the PODs and receive DAI
releaseAmount = _redeemPods(s, account, coverKey, pod, podsToRedeem);
releaseAmount = _redeemPodCalculation(s, coverKey, pod, podsToRedeem);

// Unstake NPM tokens
if (npmStakeToRemove > 0) {
Expand All @@ -244,13 +213,12 @@ library VaultLibV1 {
s.subtractUintByKey(CoverUtilV1.getCoverLiquidityStakeIndividualKey(coverKey, account), amount); // Your stake
}

function _redeemPods(
function _redeemPodCalculation(
IStore s,
address account,
bytes32 coverKey,
address pod,
uint256 podsToRedeem
) private returns (uint256) {
) private view returns (uint256) {
if (podsToRedeem == 0) {
return 0;
}
Expand All @@ -266,9 +234,6 @@ library VaultLibV1 {
// You may need to wait till active policies expire
require(available >= releaseAmount, "Insufficient balance. Lower the amount or wait till policy expiry."); // solhint-disable-line

// Update values
s.addUintByKeys(ProtoUtilV1.NS_COVER_LIQUIDITY_REMOVED, coverKey, account, releaseAmount);

return releaseAmount;
}

Expand Down

0 comments on commit 7c889be

Please sign in to comment.