Skip to content

Commit

Permalink
Refactored the Term "Assurance"
Browse files Browse the repository at this point in the history
Renamed `assurance` to `reassurance` for clarity
  • Loading branch information
heyaibi committed Dec 21, 2021
1 parent a5a5367 commit b2a981f
Show file tree
Hide file tree
Showing 114 changed files with 436 additions and 436 deletions.
6 changes: 3 additions & 3 deletions contracts/core/Protocol.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract Protocol is IProtocol, ProtoBase {
address uniswapV2RouterLike,
address npm,
address treasury,
address assuranceVault,
address reassuranceVault,
uint256 coverFee,
uint256 minStake,
uint256 minReportingStake,
Expand All @@ -36,7 +36,7 @@ contract Protocol is IProtocol, ProtoBase {
require(npm != address(0), "Invalid NPM");
require(uniswapV2RouterLike != address(0), "Invalid Router");
require(treasury != address(0), "Invalid Treasury");
require(assuranceVault != address(0), "Invalid Vault");
require(reassuranceVault != address(0), "Invalid Vault");

s.setAddressByKey(ProtoUtilV1.NS_CORE, address(this));
s.setBoolByKeys(ProtoUtilV1.NS_CONTRACTS, address(this), true);
Expand All @@ -45,7 +45,7 @@ contract Protocol is IProtocol, ProtoBase {
s.setAddressByKey(ProtoUtilV1.NS_SETUP_NPM, npm);
s.setAddressByKey(ProtoUtilV1.NS_SETUP_UNISWAP_V2_ROUTER, uniswapV2RouterLike);
s.setAddressByKey(ProtoUtilV1.NS_TREASURY, treasury);
s.setAddressByKey(ProtoUtilV1.NS_ASSURANCE_VAULT, assuranceVault);
s.setAddressByKey(ProtoUtilV1.NS_REASSURANCE_VAULT, reassuranceVault);

_setCoverFees(coverFee);
_setMinStake(minStake);
Expand Down
32 changes: 16 additions & 16 deletions contracts/core/lifecycle/Cover.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ contract Cover is CoverBase {
*
* @param key Enter a unique key for this cover
* @param info IPFS info of the cover contract
* @param assuranceToken **Optional.** Token added as an assurance of this cover. <br /><br />
* @param reassuranceToken **Optional.** Token added as an reassurance of this cover. <br /><br />
*
* Assurance tokens can be added by a project to demonstrate coverage support
* Reassurance tokens can be added by a project to demonstrate coverage support
* for their own project. This helps bring the cover fee down and enhances
* liquidity provider confidence. Along with the NPM tokens, the assurance tokens are rewarded
* liquidity provider confidence. Along with the NPM tokens, the reassurance tokens are rewarded
* as a support to the liquidity providers when a cover incident occurs.
* @param reportingPeriod The period during when reporting happens.
* @param initialAssuranceAmount **Optional.** Enter the initial amount of
* assurance tokens you'd like to add to this pool.
* @param initialReassuranceAmount **Optional.** Enter the initial amount of
* reassurance tokens you'd like to add to this pool.
* @param stakeWithFee Enter the total NPM amount (stake + fee) to transfer to this contract.
* @param initialLiquidity **Optional.** Enter the initial stablecoin liquidity for this cover.
*/
Expand All @@ -86,8 +86,8 @@ contract Cover is CoverBase {
bytes32 info,
uint256 reportingPeriod,
uint256 stakeWithFee,
address assuranceToken,
uint256 initialAssuranceAmount,
address reassuranceToken,
uint256 initialReassuranceAmount,
uint256 initialLiquidity
) external override nonReentrant {
// @supress-acl Can only be called by a whitelisted address
Expand All @@ -101,14 +101,14 @@ contract Cover is CoverBase {
uint256 fee = _validateAndGetFee(key, info, stakeWithFee);

// Set the basic cover info
_addCover(key, info, reportingPeriod, fee, assuranceToken);
_addCover(key, info, reportingPeriod, fee, reassuranceToken);

// Stake the supplied NPM tokens and burn the fees
s.getStakingContract().increaseStake(key, msg.sender, stakeWithFee, fee);

// Add cover assurance
if (initialAssuranceAmount > 0) {
s.getAssuranceContract().addAssurance(key, msg.sender, initialAssuranceAmount);
// Add cover reassurance
if (initialReassuranceAmount > 0) {
s.getReassuranceContract().addReassurance(key, msg.sender, initialReassuranceAmount);
}

// Add initial liquidity
Expand All @@ -130,14 +130,14 @@ contract Cover is CoverBase {
* @param info IPFS info of the cover contract
* @param reportingPeriod The period during when reporting happens.
* @param fee Fee paid to create this cover
* @param assuranceToken **Optional.** Token added as an assurance of this cover.
* @param reassuranceToken **Optional.** Token added as an reassurance of this cover.
*/
function _addCover(
bytes32 key,
bytes32 info,
uint256 reportingPeriod,
uint256 fee,
address assuranceToken
address reassuranceToken
) private {
// Add a new cover
s.setBoolByKeys(ProtoUtilV1.NS_COVER, key, true);
Expand All @@ -149,9 +149,9 @@ contract Cover is CoverBase {
s.setBytes32ByKeys(ProtoUtilV1.NS_COVER_INFO, key, info);
s.setUintByKeys(ProtoUtilV1.NS_REPORTING_PERIOD, key, reportingPeriod);

// Set assurance token
s.setAddressByKeys(ProtoUtilV1.NS_COVER_ASSURANCE_TOKEN, key, assuranceToken);
s.setUintByKeys(ProtoUtilV1.NS_COVER_ASSURANCE_WEIGHT, key, 500000000 gwei); // Default 50% weight
// Set reassurance token
s.setAddressByKeys(ProtoUtilV1.NS_COVER_REASSURANCE_TOKEN, key, reassuranceToken);
s.setUintByKeys(ProtoUtilV1.NS_COVER_REASSURANCE_WEIGHT, key, 500000000 gwei); // Default 50% weight

// Set the fee charged during cover creation
s.setUintByKeys(ProtoUtilV1.NS_COVER_FEE, key, fee);
Expand Down
2 changes: 1 addition & 1 deletion contracts/core/lifecycle/CoverProvision.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import "../Recoverable.sol";
* for any given cover. This not only fosters community participation but also incentivizes
* the liquidity providers or acts as a defense/support during cover incidents.
*
* Along with the NPM provisions, the liquidity providers also have `[Assurance Token Support](CoverAssurance.md)`
* Along with the NPM provisions, the liquidity providers also have `[Reassurance Token Support](CoverReassurance.md)`
* for the rainy day.
*/
contract CoverProvision is ICoverProvision, Recoverable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.0;
import "../../interfaces/IStore.sol";
import "../../interfaces/ICoverAssurance.sol";
import "../../interfaces/ICoverReassurance.sol";
import "../../libraries/ProtoUtilV1.sol";
import "../../libraries/CoverUtilV1.sol";
import "../../libraries/ValidationLibV1.sol";
Expand All @@ -11,17 +11,17 @@ import "../../libraries/NTransferUtilV2.sol";
import "../Recoverable.sol";

/**
* @title Cover Assurance
* @dev Assurance tokens can be added by a covered project to demonstrate coverage support
* @title Cover Reassurance
* @dev Reassurance tokens can be added by a covered project to demonstrate coverage support
* for their project. This helps bring the cover fee down and enhances
* liquidity provider confidence. Along with the NPM tokens, the assurance tokens are rewarded
* liquidity provider confidence. Along with the NPM tokens, the reassurance tokens are rewarded
* as a support to the liquidity providers when a cover incident occurs.
*
* Without negatively affecting the price much,
* the protocol will gradually convert the assurance tokens
* the protocol will gradually convert the reassurance tokens
* to stablecoin liquidity.
*/
contract CoverAssurance is ICoverAssurance, Recoverable {
contract CoverReassurance is ICoverReassurance, Recoverable {
using ProtoUtilV1 for bytes;
using ProtoUtilV1 for IStore;
using StoreKeyUtil for IStore;
Expand All @@ -34,11 +34,11 @@ contract CoverAssurance is ICoverAssurance, Recoverable {
}

/**
* @dev Adds assurance to the specified cover contract
* @dev Adds reassurance to the specified cover contract
* @param key Enter the cover key
* @param amount Enter the amount you would like to supply
*/
function addAssurance(
function addReassurance(
bytes32 key,
address account,
uint256 amount
Expand All @@ -48,14 +48,14 @@ contract CoverAssurance is ICoverAssurance, Recoverable {

require(amount > 0, "Provide valid amount");

IERC20 assuranceToken = IERC20(s.getAddressByKeys(ProtoUtilV1.NS_COVER_ASSURANCE_TOKEN, key));
address vault = s.getAssuranceVault();
IERC20 reassuranceToken = IERC20(s.getAddressByKeys(ProtoUtilV1.NS_COVER_REASSURANCE_TOKEN, key));
address vault = s.getReassuranceVault();

s.addUintByKeys(ProtoUtilV1.NS_COVER_ASSURANCE, key, amount);
s.addUintByKeys(ProtoUtilV1.NS_COVER_REASSURANCE, key, amount);

assuranceToken.ensureTransferFrom(account, vault, amount);
reassuranceToken.ensureTransferFrom(account, vault, amount);

emit AssuranceAdded(key, amount);
emit ReassuranceAdded(key, amount);
}

function setWeight(bytes32 key, uint256 weight) external override nonReentrant {
Expand All @@ -64,15 +64,15 @@ contract CoverAssurance is ICoverAssurance, Recoverable {

s.mustBeValidCoverKey(key);

s.setUintByKeys(ProtoUtilV1.NS_COVER_ASSURANCE_WEIGHT, key, weight);
s.setUintByKeys(ProtoUtilV1.NS_COVER_REASSURANCE_WEIGHT, key, weight);
}

/**
* @dev Gets the assurance amount of the specified cover contract
* @dev Gets the reassurance amount of the specified cover contract
* @param key Enter the cover key
*/
function getAssurance(bytes32 key) external view override returns (uint256) {
return s.getUintByKeys(ProtoUtilV1.NS_COVER_ASSURANCE, key);
function getReassurance(bytes32 key) external view override returns (uint256) {
return s.getUintByKeys(ProtoUtilV1.NS_COVER_REASSURANCE, key);
}

/**
Expand All @@ -86,6 +86,6 @@ contract CoverAssurance is ICoverAssurance, Recoverable {
* @dev Name of this contract
*/
function getName() public pure override returns (bytes32) {
return ProtoUtilV1.CNAME_COVER_ASSURANCE;
return ProtoUtilV1.CNAME_COVER_REASSURANCE;
}
}
2 changes: 1 addition & 1 deletion contracts/core/liquidity/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import "./VaultBase.sol";
* - The protocol supplies a small portion of idle assets to lending protocols (v2).
* - Flash loan interest also gets added back to the pool.
* - To protect liquidity providers from cover incidents, they can redeem upto 25% of the cover payouts through NPM provision.
* - To protect liquidity providers from cover incidents, they can redeem upto 25% of the cover payouts through `assurance token` allocation.
* - To protect liquidity providers from cover incidents, they can redeem upto 25% of the cover payouts through `reassurance token` allocation.
*/
contract Vault is VaultBase {
constructor(
Expand Down
8 changes: 4 additions & 4 deletions contracts/core/policy/Policy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ contract Policy is IPolicy, Recoverable {
// UTILIZATION RATIO = COVER_COMMITMENT / AMOUNT_IN_COVER_POOL
utilizationRatio = (1 ether * values[1]) / values[0];

// TOTAL AVAILABLE LIQUIDITY = AMOUNT_IN_COVER_POOL - COVER_COMMITMENT + (NEP_REWARD_POOL_SUPPORT * NEP_PRICE) + (ASSURANCE_POOL_SUPPORT * ASSURANCE_TOKEN_PRICE * ASSURANCE_POOL_WEIGHT)
// TOTAL AVAILABLE LIQUIDITY = AMOUNT_IN_COVER_POOL - COVER_COMMITMENT + (NEP_REWARD_POOL_SUPPORT * NEP_PRICE) + (REASSURANCE_POOL_SUPPORT * REASSURANCE_TOKEN_PRICE * REASSURANCE_POOL_WEIGHT)
totalAvailableLiquidity = values[0] - values[1] + ((values[2] * values[3]) / 1 ether) + ((values[4] * values[5] * values[6]) / (1 ether * 1 ether));

// COVER RATIO = UTILIZATION_RATIO + COVER_DURATION * AMOUNT_TO_COVER / AVAILABLE_LIQUIDITY
Expand All @@ -249,9 +249,9 @@ contract Policy is IPolicy, Recoverable {
* @param _values[1] The total commitment amount
* @param _values[2] The total amount of NPM provision
* @param _values[3] NPM price
* @param _values[4] The total amount of assurance tokens
* @param _values[5] Assurance token price
* @param _values[6] Assurance pool weight
* @param _values[4] The total amount of reassurance tokens
* @param _values[5] Reassurance token price
* @param _values[6] Reassurance pool weight
*/
function getCoverPoolSummary(bytes32 key) external view override returns (uint256[] memory _values) {
return s.getCoverPoolSummary(key);
Expand Down
14 changes: 7 additions & 7 deletions contracts/interfaces/ICover.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ interface ICover is IMember {
*
* @param key Enter a unique key for this cover
* @param info IPFS info of the cover contract
* @param assuranceToken **Optional.** Token added as an assurance of this cover. <br /><br />
* @param reassuranceToken **Optional.** Token added as an reassurance of this cover. <br /><br />
*
* Assurance tokens can be added by a project to demonstrate coverage support
* Reassurance tokens can be added by a project to demonstrate coverage support
* for their own project. This helps bring the cover fee down and enhances
* liquidity provider confidence. Along with the NPM tokens, the assurance tokens are rewarded
* liquidity provider confidence. Along with the NPM tokens, the reassurance tokens are rewarded
* as a support to the liquidity providers when a cover incident occurs.
* @param reportingPeriod The period during when reporting happens.
* @param initialAssuranceAmount **Optional.** Enter the initial amount of
* assurance tokens you'd like to add to this pool.
* @param initialReassuranceAmount **Optional.** Enter the initial amount of
* reassurance tokens you'd like to add to this pool.
* @param stakeWithFee Enter the total NPM amount (stake + fee) to transfer to this contract.
* @param initialLiquidity **Optional.** Enter the initial stablecoin liquidity for this cover.
*/
Expand All @@ -52,8 +52,8 @@ interface ICover is IMember {
bytes32 info,
uint256 reportingPeriod,
uint256 stakeWithFee,
address assuranceToken,
uint256 initialAssuranceAmount,
address reassuranceToken,
uint256 initialReassuranceAmount,
uint256 initialLiquidity
) external;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
pragma solidity 0.8.0;
import "./IMember.sol";

interface ICoverAssurance is IMember {
event AssuranceAdded(bytes32 key, uint256 amount);
interface ICoverReassurance is IMember {
event ReassuranceAdded(bytes32 key, uint256 amount);

/**
* @dev Adds assurance to the specified cover contract
* @dev Adds reassurance to the specified cover contract
* @param key Enter the cover key
* @param amount Enter the amount you would like to supply
*/
function addAssurance(
function addReassurance(
bytes32 key,
address account,
uint256 amount
Expand All @@ -20,8 +20,8 @@ interface ICoverAssurance is IMember {
function setWeight(bytes32 key, uint256 weight) external;

/**
* @dev Gets the assurance amount of the specified cover contract
* @dev Gets the reassurance amount of the specified cover contract
* @param key Enter the cover key
*/
function getAssurance(bytes32 key) external view returns (uint256);
function getReassurance(bytes32 key) external view returns (uint256);
}
6 changes: 3 additions & 3 deletions contracts/interfaces/IPolicy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ interface IPolicy is IMember {
* @param _values[1] The total commitment amount
* @param _values[2] The total amount of NPM provision
* @param _values[3] NPM price
* @param _values[4] The total amount of assurance tokens
* @param _values[5] Assurance token price
* @param _values[6] Assurance pool weight
* @param _values[4] The total amount of reassurance tokens
* @param _values[5] Reassurance token price
* @param _values[6] Reassurance pool weight
*/
function getCoverPoolSummary(bytes32 key) external view returns (uint256[] memory _values);

Expand Down
12 changes: 6 additions & 6 deletions contracts/libraries/CoverUtilV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ library CoverUtilV1 {
* @param _values[1] The total commitment amount
* @param _values[2] The total amount of NPM provision
* @param _values[3] NPM price
* @param _values[4] The total amount of assurance tokens
* @param _values[5] Assurance token price
* @param _values[6] Assurance pool weight
* @param _values[4] The total amount of reassurance tokens
* @param _values[5] Reassurance token price
* @param _values[6] Reassurance pool weight
*/
function getCoverPoolSummary(IStore s, bytes32 key) external view returns (uint256[] memory _values) {
require(getCoverStatus(s, key) == CoverStatus.Normal, "Invalid cover");
Expand All @@ -83,9 +83,9 @@ library CoverUtilV1 {
_values[1] = s.getUintByKeys(ProtoUtilV1.NS_COVER_LIQUIDITY_COMMITTED, key); // <-- Todo: liquidity commitment should expire as policies expire
_values[2] = s.getUintByKeys(ProtoUtilV1.NS_COVER_PROVISION, key);
_values[3] = discovery.getTokenPriceInStableCoin(address(s.npmToken()), 1 ether);
_values[4] = s.getUintByKeys(ProtoUtilV1.NS_COVER_ASSURANCE, key);
_values[5] = discovery.getTokenPriceInStableCoin(address(s.getAddressByKeys(ProtoUtilV1.NS_COVER_ASSURANCE_TOKEN, key)), 1 ether);
_values[6] = s.getUintByKeys(ProtoUtilV1.NS_COVER_ASSURANCE_WEIGHT, key);
_values[4] = s.getUintByKeys(ProtoUtilV1.NS_COVER_REASSURANCE, key);
_values[5] = discovery.getTokenPriceInStableCoin(address(s.getAddressByKeys(ProtoUtilV1.NS_COVER_REASSURANCE_TOKEN, key)), 1 ether);
_values[6] = s.getUintByKeys(ProtoUtilV1.NS_COVER_REASSURANCE_WEIGHT, key);
}

function getPolicyRates(IStore s, bytes32 key) external view returns (uint256 floor, uint256 ceiling) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/libraries/GovernanceUtilV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "../interfaces/IStore.sol";
import "../interfaces/IPolicy.sol";
import "../interfaces/ICoverStake.sol";
import "../interfaces/IPriceDiscovery.sol";
import "../interfaces/ICoverAssurance.sol";
import "../interfaces/ICoverReassurance.sol";
import "../interfaces/IVault.sol";
import "../interfaces/IVaultFactory.sol";
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
Expand Down
14 changes: 7 additions & 7 deletions contracts/libraries/ProtoUtilV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ library ProtoUtilV1 {
using StoreKeyUtil for IStore;

bytes32 public constant NS_CORE = "proto:core";
bytes32 public constant NS_ASSURANCE_VAULT = "proto:core:assurance:vault";
bytes32 public constant NS_REASSURANCE_VAULT = "proto:core:reassurance:vault";

/// @dev The address where burn tokens are sent or collected.
/// This behavior (collection) is required if the instance of
Expand Down Expand Up @@ -54,9 +54,9 @@ library ProtoUtilV1 {
/// @dev Claims processor contract address
bytes32 public constant NS_CLAIMS_PROCESSOR = "proto:claims:processor";

bytes32 public constant NS_COVER_ASSURANCE = "proto:cover:assurance";
bytes32 public constant NS_COVER_ASSURANCE_TOKEN = "proto:cover:assurance:token";
bytes32 public constant NS_COVER_ASSURANCE_WEIGHT = "proto:cover:assurance:weight";
bytes32 public constant NS_COVER_REASSURANCE = "proto:cover:reassurance";
bytes32 public constant NS_COVER_REASSURANCE_TOKEN = "proto:cover:reassurance:token";
bytes32 public constant NS_COVER_REASSURANCE_WEIGHT = "proto:cover:reassurance:weight";
bytes32 public constant NS_COVER_CLAIMABLE = "proto:cover:claimable";
bytes32 public constant NS_COVER_FEE = "proto:cover:fee";
bytes32 public constant NS_COVER_INFO = "proto:cover:info";
Expand Down Expand Up @@ -147,7 +147,7 @@ library ProtoUtilV1 {
bytes32 public constant CNAME_CXTOKEN_FACTORY = "cxTokenFactory";
bytes32 public constant CNAME_COVER_PROVISION = "CoverProvison";
bytes32 public constant CNAME_COVER_STAKE = "CoverStake";
bytes32 public constant CNAME_COVER_ASSURANCE = "CoverAssurance";
bytes32 public constant CNAME_COVER_REASSURANCE = "CoverReassurance";
bytes32 public constant CNAME_LIQUIDITY_VAULT = "Vault";

function getProtocol(IStore s) external view returns (IProtocol) {
Expand Down Expand Up @@ -209,8 +209,8 @@ library ProtoUtilV1 {
return s.getAddressByKey(NS_TREASURY);
}

function getAssuranceVault(IStore s) external view returns (address) {
return s.getAddressByKey(NS_ASSURANCE_VAULT);
function getReassuranceVault(IStore s) external view returns (address) {
return s.getAddressByKey(NS_REASSURANCE_VAULT);
}

function getLiquidityToken(IStore s) public view returns (address) {
Expand Down
Loading

0 comments on commit b2a981f

Please sign in to comment.