This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c919bec
commit f1801e3
Showing
57 changed files
with
8,993 additions
and
4,266 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
contracts/TestStorageExample/StorageVersionUpgradeExample.sol
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Here will live leverage tokens smart contracts |
28 changes: 28 additions & 0 deletions
28
contracts/leverage-tokens/Abstract/InterfaceCalculator.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
pragma solidity ^0.5.0; | ||
|
||
|
||
interface InterfaceCalculator { | ||
function getTokensCreatedByCash( | ||
uint256 mintingPrice, | ||
uint256 cash, | ||
uint256 gasFee | ||
) external view returns (uint256 tokensCreated); | ||
|
||
function getCashCreatedByTokens( | ||
uint256 burningPrice, | ||
uint256 elapsedTime, | ||
uint256 tokens, | ||
uint256 gasFee | ||
) external view returns (uint256 stablecoinRedeemed); | ||
|
||
function removeCurrentMintingFeeFromCash(uint256 _cash) | ||
external | ||
view | ||
returns (uint256 cashAfterFee); | ||
|
||
function removeMintingFeeFromCash( | ||
uint256 _cash, | ||
uint256 _mintingFee, | ||
uint256 _minimumMintingFee | ||
) external pure returns (uint256 cashAfterFee); | ||
} |
66 changes: 66 additions & 0 deletions
66
contracts/leverage-tokens/Abstract/InterfaceStorageLeverage.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
pragma solidity ^0.5.0; | ||
|
||
|
||
|
||
interface InterfaceStorageLeverage { | ||
function whitelistedAddresses(address) external view returns (bool); | ||
|
||
function isPaused() external view returns (bool); | ||
|
||
function isShutdown() external view returns (bool); | ||
|
||
function tokenSwapManager() external view returns (address); | ||
|
||
function bridge() external view returns (address); | ||
|
||
function managementFee() external view returns (uint256); | ||
|
||
function getExecutionPrice() external view returns (uint256); | ||
|
||
function getMarkPrice() external view returns (uint256); | ||
|
||
function getNotional() external view returns (uint256); | ||
|
||
function getTokenValue() external view returns (uint256); | ||
|
||
function getFundingRate() external view returns (uint256); | ||
|
||
function getMintingFee(uint256 cash) external view returns (uint256); | ||
|
||
function minimumMintingFee() external view returns (uint256); | ||
|
||
function minRebalanceAmount() external view returns (uint8); | ||
|
||
function delayedRedemptionsByUser(address) external view returns (uint256); | ||
|
||
function setDelayedRedemptionsByUser( | ||
uint256 amountToRedeem, | ||
address whitelistedAddress | ||
) external; | ||
|
||
function setOrderByUser( | ||
address whitelistedAddress, | ||
string calldata orderType, | ||
uint256 tokensGiven, | ||
uint256 tokensRecieved, | ||
uint256 mintingPrice, | ||
uint256 orderIndex, | ||
bool overwrite | ||
) external; | ||
|
||
function setAccounting( | ||
uint256 _bestExecutionPrice, | ||
uint256 _markPrice, | ||
uint256 _notional, | ||
uint256 _tokenValue, | ||
uint256 _effectiveFundingRate | ||
) external; | ||
|
||
function setAccountingForLastActivityDay( | ||
uint256 _bestExecutionPrice, | ||
uint256 _markPrice, | ||
uint256 _notional, | ||
uint256 _tokenValue, | ||
uint256 _effectiveFundingRate | ||
) external; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
pragma solidity ^0.5.0; | ||
|
||
import "@openzeppelin/upgrades/contracts/Initializable.sol"; | ||
import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol"; | ||
|
||
import "../short-tokens/utils/Math.sol"; | ||
import "../short-tokens/utils/DateTimeLibrary.sol"; | ||
import "./Abstract/InterfaceStorageLeverage.sol"; | ||
import "../short-tokens/Abstract/InterfaceInverseToken.sol"; | ||
|
||
|
||
/** | ||
* @dev uint256 are expected to use last 18 numbers as decimal points except when specifid differently in @params | ||
*/ | ||
contract CalculatorLeverage is Initializable { | ||
using SafeMath for uint256; | ||
|
||
InterfaceStorageLeverage public persistentStorage; | ||
InterfaceInverseToken public inverseToken; | ||
|
||
function initialize( | ||
address _persistentStorageAddress, | ||
address _inverseTokenAddress | ||
) public initializer { | ||
persistentStorage = InterfaceStorageLeverage(_persistentStorageAddress); | ||
inverseToken = InterfaceInverseToken(_inverseTokenAddress); | ||
} | ||
|
||
// Start fill in the values | ||
// Creation 3x Long | ||
|
||
function getTokensCreatedByCash( | ||
uint256 mintingPrice, | ||
uint256 cash, | ||
uint256 gasFee | ||
) public view returns (uint256 tokensCreated) { | ||
// Cash Remove Gas Fee | ||
// Cash Remove Minting Fee (Cash Proceeds) | ||
// Cash Proceeds / Minting Price (# of Tokens to Mint) | ||
|
||
uint256 cashAfterGas = DSMath.sub(cash, gasFee); | ||
uint256 cashAfterFee = removeCurrentMintingFeeFromCash(cashAfterGas); | ||
|
||
uint256 tokensMinted = DSMath.wdiv(cashAfterFee, mintingPrice); | ||
|
||
return tokensMinted; | ||
} | ||
|
||
function getCashCreatedByTokens( | ||
uint256 burningPrice, | ||
uint256 elapsedTime, | ||
uint256 tokens, | ||
uint256 gasFee | ||
) public view returns (uint256 stablecoinAfterFees) { | ||
uint256 stablecoin = DSMath.wmul(tokens, burningPrice); | ||
uint256 stablecoinAfterGas = DSMath.sub(stablecoin, gasFee); | ||
uint256 stablecoinRedeemed = removeCurrentMintingFeeFromCash( | ||
stablecoinAfterGas | ||
); | ||
uint256 managementFeeDaily = DSMath.wdiv( | ||
persistentStorage.managementFee(), | ||
365 ether | ||
); | ||
uint256 managementFeeHourly = DSMath.wdiv( | ||
DSMath.wmul(managementFeeDaily, elapsedTime), | ||
24 ether | ||
); | ||
uint256 normalizedManagementFee = DSMath.sub( | ||
1 ether, | ||
DSMath.wdiv(managementFeeHourly, 100 ether) | ||
); | ||
|
||
stablecoinAfterFees = DSMath.wmul( | ||
stablecoinRedeemed, | ||
normalizedManagementFee | ||
); | ||
} | ||
|
||
function removeCurrentMintingFeeFromCash(uint256 _cash) | ||
public | ||
view | ||
returns (uint256 cashAfterFee) | ||
{ | ||
uint256 creationFee = persistentStorage.getMintingFee(_cash); | ||
uint256 minimumMintingFee = persistentStorage.minimumMintingFee(); | ||
cashAfterFee = removeMintingFeeFromCash( | ||
_cash, | ||
creationFee, | ||
minimumMintingFee | ||
); | ||
} | ||
|
||
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); | ||
} | ||
|
||
int256 constant WAD = 10**18; | ||
|
||
function addInt256(int256 x, int256 y) internal pure returns (int256 z) { | ||
require((z = x + y) >= x, "ds-math-add-overflow"); | ||
} | ||
|
||
function mulInt256(int256 x, int256 y) internal pure returns (int256 z) { | ||
require(y == 0 || (z = x * y) / y == x, "ds-math-mul-overflow"); | ||
} | ||
|
||
function wmulInt256(int256 x, int256 y) internal pure returns (int256 z) { | ||
z = addInt256(mulInt256(x, y), WAD / 2) / WAD; | ||
} | ||
} |
Oops, something went wrong.