Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Commit

Permalink
Adding Gas fee to mint/burn. Supporting stablecoin by address. Remove…
Browse files Browse the repository at this point in the history
…d KYCVerifier from Persistent storage
  • Loading branch information
hemulin committed Apr 30, 2020
1 parent b7c2cb8 commit c919bec
Show file tree
Hide file tree
Showing 10 changed files with 745 additions and 340 deletions.
32 changes: 23 additions & 9 deletions contracts/CompositionCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,17 @@ contract CompositionCalculator is Initializable {
* @dev Returns cash without fee
* @param _cash The cash provided to create token
* @param _mintingFee The minting fee to remove
* @param _minimumMintingFee The minimum minting fee in $ to remove
*/
function removeMintingFeeFromCash(uint256 _cash, uint256 _mintingFee)
public
pure
returns (uint256 cashAfterFee)
{
function removeMintingFeeFromCash(
uint256 _cash,
uint256 _mintingFee,
uint256 _minimumMintingFee
) public pure returns (uint256 cashAfterFee) {
uint256 creationFeeInCash = DSMath.wmul(_cash, _mintingFee);
if (_minimumMintingFee > creationFeeInCash) {
creationFeeInCash = _minimumMintingFee;
}
cashAfterFee = DSMath.sub(_cash, creationFeeInCash);
}

Expand Down Expand Up @@ -348,7 +352,12 @@ contract CompositionCalculator is Initializable {
returns (uint256 cashAfterFee)
{
uint256 creationFee = persistentStorage.getMintingFee(_cash);
cashAfterFee = removeMintingFeeFromCash(_cash, creationFee);
uint256 minimumMintingFee = persistentStorage.minimumMintingFee();
cashAfterFee = removeMintingFeeFromCash(
_cash,
creationFee,
minimumMintingFee
);
}

/**
Expand All @@ -359,9 +368,11 @@ contract CompositionCalculator is Initializable {
function getCurrentTokenAmountCreatedByCash(
//Create
uint256 _cash,
uint256 _spotPrice
uint256 _spotPrice,
uint256 _gasFee
) public view returns (uint256 tokenAmountCreated) {
uint256 cashAfterFee = removeCurrentMintingFeeFromCash(_cash);
uint256 cashAfterGas = DSMath.sub(_cash, _gasFee);
uint256 cashAfterFee = removeCurrentMintingFeeFromCash(cashAfterGas);
tokenAmountCreated = getTokenAmountCreatedByCash(
persistentStorage.getCashPositionPerTokenUnit(),
persistentStorage.getBalancePerTokenUnit(),
Expand All @@ -379,7 +390,8 @@ contract CompositionCalculator is Initializable {
function getCurrentCashAmountCreatedByToken(
//Redeem
uint256 _tokenAmount,
uint256 _spotPrice
uint256 _spotPrice,
uint256 _gasFee
) public view returns (uint256 cashFromTokenRedeem) {
uint256 lendingFee = persistentStorage.getLendingFee();
uint256 daysSinceLastRebalance = getDaysSinceLastRebalance() + 1;
Expand Down Expand Up @@ -408,6 +420,8 @@ contract CompositionCalculator is Initializable {
cashFromTokenRedeem = removeCurrentMintingFeeFromCash(
DSMath.sub(cashFromToken, fiatForLendingFee)
);

cashFromTokenRedeem = DSMath.sub(cashFromTokenRedeem, _gasFee);
}

function getDaysSinceLastRebalance()
Expand Down
60 changes: 53 additions & 7 deletions contracts/KYCVerifier.sol
Original file line number Diff line number Diff line change
@@ -1,21 +1,67 @@
pragma solidity ^0.5.0;

import "@openzeppelin/upgrades/contracts/Initializable.sol";
import "./Abstract/InterfaceStorage.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/ownership/Ownable.sol";


contract KYCVerifier is Initializable {
InterfaceStorage public persistentStorage;
contract KYCVerifier is Ownable {
address public bridge;

function initialize(address _persistentStorage) public initializer {
persistentStorage = InterfaceStorage(_persistentStorage);
mapping(address => bool) public whitelistedAddresses;

function initialize(address ownerAddress) public initializer {
require(ownerAddress != address(0), "owner adddress must not be empty");
Ownable.initialize(ownerAddress);
}

function isAddressWhitelisted(address userAddress)
public
view
returns (bool)
{
return persistentStorage.whitelistedAddresses(userAddress);
return whitelistedAddresses[userAddress];
}

// @dev Set whitelisted addresses
function setWhitelistedAddress(address adddressToAdd)
public
onlyOwnerOrBridge
{
require(adddressToAdd != address(0), "adddress must not be empty");

whitelistedAddresses[adddressToAdd] = true;
}

// @dev Remove whitelisted addresses
function removeWhitelistedAddress(address addressToRemove)
public
onlyOwnerOrBridge
{
require(
whitelistedAddresses[addressToRemove],
"address must be added to be removed allowed"
);

delete whitelistedAddresses[addressToRemove];
}

// @dev Updates whitelisted addresses
function updateWhitelistedAddress(address oldAddress, address newAddress)
public
{
removeWhitelistedAddress(oldAddress);
setWhitelistedAddress(newAddress);
}

function setBridge(address _bridge) public onlyOwner {
require(_bridge != address(0), "adddress must not be empty");
bridge = _bridge;
}

modifier onlyOwnerOrBridge() {
require(
isOwner() || _msgSender() == bridge,
"caller is not the owner or bridge"
);
_;
}
}
71 changes: 33 additions & 38 deletions contracts/PersistentStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ contract PersistentStorage is Ownable {
uint256 public lastActivityDay;
uint256 public minRebalanceAmount;
uint256 public managementFee;
uint256 public minimumMintingFee;
uint256 public minimumTrade;

uint8 public balancePrecision;

mapping(uint256 => Accounting[]) private accounting;

mapping(address => bool) public whitelistedAddresses;

uint256[] public mintingFeeBracket;
mapping(uint256 => uint256) public mintingFee;

Expand All @@ -49,17 +50,19 @@ contract PersistentStorage is Ownable {
function initialize(
address ownerAddress,
uint256 _managementFee,
uint256 _minRebalanceAmount
uint256 _minRebalanceAmount,
uint8 _balancePrecision,
uint256 _lastMintingFee,
uint256 _minimumMintingFee,
uint256 _minimumTrade
) public initializer {
initialize(ownerAddress);
managementFee = _managementFee;
minRebalanceAmount = _minRebalanceAmount;
mintingFeeBracket.push(50000 ether);
mintingFeeBracket.push(100000 ether);
mintingFee[50000 ether] = 3 ether / 1000; //0.3%
mintingFee[100000 ether] = 2 ether / 1000; //0.2%
mintingFee[~uint256(0)] = 1 ether / 1000; //0.1% all values higher
balancePrecision = 10;
mintingFee[~uint256(0)] = _lastMintingFee;
balancePrecision = _balancePrecision;
minimumMintingFee = _minimumMintingFee;
minimumTrade = _minimumTrade;
}

function setTokenSwapManager(address _tokenSwapManager) public onlyOwner {
Expand Down Expand Up @@ -91,6 +94,14 @@ contract PersistentStorage is Ownable {
_;
}

modifier onlyOwnerOrBridge() {
require(
isOwner() || _msgSender() == bridge,
"caller is not the owner or bridge"
);
_;
}

function setDelayedRedemptionsByUser(
uint256 amountToRedeem,
address whitelistedAddress
Expand Down Expand Up @@ -210,34 +221,6 @@ contract PersistentStorage is Ownable {
);
}

// @dev Set whitelisted addresses
function setWhitelistedAddress(address adddressToAdd) public onlyOwner {
require(adddressToAdd != address(0), "adddress must not be empty");

whitelistedAddresses[adddressToAdd] = true;
}

// @dev Remove whitelisted addresses
function removeWhitelistedAddress(address addressToRemove)
public
onlyOwner
{
require(
whitelistedAddresses[addressToRemove],
"address must be added to be removed allowed"
);

delete whitelistedAddresses[addressToRemove];
}

// @dev Updates whitelisted addresses
function updateWhitelistedAddress(address oldAddress, address newAddress)
public
{
removeWhitelistedAddress(oldAddress);
setWhitelistedAddress(newAddress);
}

// @dev Get accounting values for a specific day
// @param date format as 20200123 for 23th of January 2020
function getAccounting(uint256 date)
Expand Down Expand Up @@ -353,7 +336,9 @@ contract PersistentStorage is Ownable {
onlyOwner
{
require(
_mintingFeeLimit > mintingFeeBracket[mintingFeeBracket.length - 1],
mintingFeeBracket.length == 0 ||
_mintingFeeLimit >
mintingFeeBracket[mintingFeeBracket.length - 1],
"New minting fee bracket needs to be bigger then last one"
);
mintingFeeBracket.push(_mintingFeeLimit);
Expand Down Expand Up @@ -416,4 +401,14 @@ contract PersistentStorage is Ownable {
function setLastPrecision(uint8 _balancePrecision) public onlyOwner {
balancePrecision = _balancePrecision;
}

// @dev Sets minimum minting fee
function setMinimumMintingFee(uint256 _minimumMintingFee) public onlyOwner {
minimumMintingFee = _minimumMintingFee;
}

// @dev Sets minimum trade value
function setMinimumTrade(uint256 _minimumTrade) public onlyOwner {
minimumTrade = _minimumTrade;
}
}
Loading

0 comments on commit c919bec

Please sign in to comment.