Skip to content

Commit

Permalink
naming improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
JonahGroendal committed Sep 27, 2022
1 parent b676e76 commit a6e88d1
Show file tree
Hide file tree
Showing 16 changed files with 327 additions and 207 deletions.
113 changes: 113 additions & 0 deletions .openzeppelin/goerli.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@
"address": "0x748b032161b2070C6DFeEe3a05C622ad61A71900",
"txHash": "0xd23716d690380bf809c32922f31aba9e71fad50d664788abe0a5b756a334cef6",
"kind": "uups"
},
{
"address": "0x130947FE7a04921faD22D9c3400ecf7e16AEbE98",
"txHash": "0x407585ada6fcf2de6ee2cc1ea59d61b4fa2606226524c45805581ca215a337de",
"kind": "uups"
},
{
"address": "0xEdaE78BbaB80eE01dC4C703e40b795a77e18D7fc",
"txHash": "0xd2cfab40a54861b80d310bb1b1a2472b963f146c8e7ee74f7cfc6fb00427ae10",
"kind": "uups"
},
{
"address": "0x92785E3144218F1e7b755a2D090B0c2AC1FdD5aD",
"txHash": "0xfde1bf383479cb6427ccb315dde9c2fec2439a5d1dd8d59024efc35ca9bc146b",
"kind": "uups"
}
],
"impls": {
Expand Down Expand Up @@ -414,6 +429,104 @@
}
}
}
},
"d94a563ee2ea501994af8e583b0d6415e05c7bac65b807555e2cda7536f50b22": {
"address": "0x621E8B109Ee1FbE8FdBC92Bd54F225d6305B40ed",
"txHash": "0xc231d459e6639a0fa940c0ace8e43f179b66406ac38e679480acccee0be4c082",
"layout": {
"storage": [
{
"contract": "Initializable",
"label": "_initialized",
"type": "t_uint8",
"src": "../@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:62",
"retypedFrom": "bool"
},
{
"contract": "Initializable",
"label": "_initializing",
"type": "t_bool",
"src": "../@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:67"
},
{
"contract": "ContextUpgradeable",
"label": "__gap",
"type": "t_array(t_uint256)50_storage",
"src": "../@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol:36"
},
{
"contract": "OwnableUpgradeable",
"label": "_owner",
"type": "t_address",
"src": "../@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:22"
},
{
"contract": "OwnableUpgradeable",
"label": "__gap",
"type": "t_array(t_uint256)49_storage",
"src": "../@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:94"
},
{
"contract": "ERC1967UpgradeUpgradeable",
"label": "__gap",
"type": "t_array(t_uint256)50_storage",
"src": "../@openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol:211"
},
{
"contract": "UUPSUpgradeable",
"label": "__gap",
"type": "t_array(t_uint256)50_storage",
"src": "../@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol:107"
},
{
"contract": "Rates",
"label": "interest",
"type": "t_uint256",
"src": "../project:/contracts/Rates.sol:25"
},
{
"contract": "Rates",
"label": "startTime",
"type": "t_uint256",
"src": "../project:/contracts/Rates.sol:29"
},
{
"contract": "Rates",
"label": "startValue",
"type": "t_uint256",
"src": "../project:/contracts/Rates.sol:32"
},
{
"contract": "Swap",
"label": "params",
"type": "t_contract(IParameters)9264",
"src": "../project:/contracts/Swap.sol:13"
}
],
"types": {
"t_contract(IParameters)9264": {
"label": "contract IParameters"
},
"t_uint256": {
"label": "uint256"
},
"t_array(t_uint256)50_storage": {
"label": "uint256[50]"
},
"t_address": {
"label": "address"
},
"t_array(t_uint256)49_storage": {
"label": "uint256[49]"
},
"t_uint8": {
"label": "uint8"
},
"t_bool": {
"label": "bool"
}
}
}
}
}
}
69 changes: 42 additions & 27 deletions .openzeppelin/unknown-1337.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@
"txHash": "0x0e86054bfa506da31a00d83825491f0bbc9f1fd624fd70095d407f538c4db1fd",
"kind": "uups"
},
{
"address": "0xEdaE78BbaB80eE01dC4C703e40b795a77e18D7fc",
"txHash": "0xb83f2d3606ed85b0a67503eeed658d9fef7c4bea16c8ef6817a1d864840045e6",
"kind": "uups"
},
{
"address": "0x758B1FF29c5eba7A07bA7B3564A0416E6FF8e98e",
"txHash": "0x8d36a848fb82d8ffa174a4536980822ab74df6f7d4517040e697a9414d30a695",
"kind": "uups"
},
{
"address": "0x6719f470ae32b505e12c3F46DfC8998Da07E7e50",
"txHash": "0x8000394d4eda7619792ff565146d656cb2b99509ccd6eba14162c8920f35e419",
"kind": "uups"
},
{
"address": "0xAa588d3737B611baFD7bD713445b314BD453a5C8",
"txHash": "0xe215cd0bac333cbcd9f4d20302fdb381a7b3997d13cc14103c9df6e46f3af080",
Expand All @@ -83,7 +98,7 @@
},
{
"address": "0xdDA6327139485221633A1FcD65f4aC932E60A2e1",
"txHash": "0x91288dab174ee81556228076c0dbce933249837f16badee402e2ac34f8fa8c14",
"txHash": "0x06de3dde6acfd6fa0bc4f82599d78f45986d7aa80ab9e48a2af53635ed3cd183",
"kind": "uups"
}
],
Expand Down Expand Up @@ -619,9 +634,9 @@
}
}
},
"b22b03d9ce0849d8240b7ce54382ffe5a5b5b776a5e92e3b3de62fa16c568063": {
"e210f914b37b6e85931720ed5311b831f5d21029d3c21f679688a48ea4db965f": {
"address": "0x82D50AD3C1091866E258Fd0f1a7cC9674609D254",
"txHash": "0x200f977d25cf3b0f5692d4a2203f1c0a424f71933407d792e8ae9e0d28425312",
"txHash": "0xf8aea681428662ed06a3b6d581268eb411b709c94766eec93131bb31ddc19996",
"layout": {
"storage": [
{
Expand All @@ -637,6 +652,24 @@
"type": "t_bool",
"src": "../@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:67"
},
{
"contract": "Interest",
"label": "rate",
"type": "t_uint256",
"src": "../project:/contracts/Interest.sol:19"
},
{
"contract": "Interest",
"label": "startTime",
"type": "t_uint256",
"src": "../project:/contracts/Interest.sol:23"
},
{
"contract": "Interest",
"label": "startValue",
"type": "t_uint256",
"src": "../project:/contracts/Interest.sol:27"
},
{
"contract": "ContextUpgradeable",
"label": "__gap",
Expand Down Expand Up @@ -667,41 +700,23 @@
"type": "t_array(t_uint256)50_storage",
"src": "../@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol:107"
},
{
"contract": "Rates",
"label": "interest",
"type": "t_uint256",
"src": "../project:/contracts/Rates.sol:25"
},
{
"contract": "Rates",
"label": "startTime",
"type": "t_uint256",
"src": "../project:/contracts/Rates.sol:29"
},
{
"contract": "Rates",
"label": "startValue",
"type": "t_uint256",
"src": "../project:/contracts/Rates.sol:32"
},
{
"contract": "Swap",
"label": "params",
"type": "t_contract(IParameters)9264",
"src": "../project:/contracts/Swap.sol:13"
"type": "t_contract(IParameters)9276",
"src": "../project:/contracts/Swap.sol:15"
}
],
"types": {
"t_contract(IParameters)9264": {
"t_contract(IParameters)9276": {
"label": "contract IParameters"
},
"t_uint256": {
"label": "uint256"
},
"t_array(t_uint256)50_storage": {
"label": "uint256[50]"
},
"t_uint256": {
"label": "uint256"
},
"t_address": {
"label": "address"
},
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ VSSS has two product offerings, a stablecoin and an unstable (i.e. leveraged) co

Both tokens are collateralized with the same underlying asset. The stablecoin maintains a peg to a target asset, for example USD, via a price feed. Conversely, the unstablecoin offeres leveraged exposure to the underlying asset.

Essentially, it's an equity swap contract with tokenized fixed and floating legs, with payments and collateral in the reference asset.
Essentially, it's an equity swap contract with tokenized floating and equity legs, with payments and collateral in the reference equity.

# How It Works
Each Swap contract creates two synthetic assets whose values are determined by a price feed and backed by an underlying asset. Either synthetic asset can be minted or burned on-demand by depositing/withdrawing some of the underlying asset into/out of the Swap contract. For example, in an ETH/USD contract, you can deposit ETH to mint either synthetic USD or leveraged ETH, or you can withdraw ETH by burning synthetic USD or leveraged ETH.
Expand Down Expand Up @@ -37,7 +37,9 @@ L varies with R such that the following is always true:


# Fees
All fees are used to serve cryptoeconomic goals such as maintaining a target collateralization ratio. They are taken from some participants and given to others. They don't go to a DAO.
There's a 0.1% fee on trades, given to equity and floating leg holders. The fee is put into the equity leg pool and, in turn, factored into the interest rate via market forces.

Value is conserved within each swap contract. No disbursements of any kind are transferred out of the system.

## One-time Fees
Every buy (mint) or sell (burn) has an associated fee that's proportional to the value of the trade. All proceeds from fees are put into the floating-leg pool, meaning they're given to floating-leg token holders.
Expand Down Expand Up @@ -181,7 +183,11 @@ cons:


# TODO
- subtract the cost of gas from the premium so small transactions aren't disencentivized
- update solidity version
- change naming
- fixedLeg -> floatingLeg
- floatLeg -> equityLeg
- Volatility Swap -> Equity Swap
- look into using super cheap exp() function
- consolidate premium rates functions
- make sure not vulnerable to erc 777 reentry
Expand Down
8 changes: 4 additions & 4 deletions contractAddrs-goerli-fork.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"fixedLeg": "0xe7FD3ee1d1c70c87234ec57C2B036Ad8c0Fd0173",
"floatLeg": "0x6ae11ef30f1eC6e641E9B43725b20a172b0F090E",
"swap": "0x748b032161b2070C6DFeEe3a05C622ad61A71900",
"timelock": "0x205C15322d223E4DC66976F7E0f62fC2Fc3D0a86"
"fixedLeg": "0xEdaE78BbaB80eE01dC4C703e40b795a77e18D7fc",
"floatLeg": "0x758B1FF29c5eba7A07bA7B3564A0416E6FF8e98e",
"swap": "0x6719f470ae32b505e12c3F46DfC8998Da07E7e50",
"timelock": "0x5e7E4584973305B901B950E66249D90C8099858F"
}
8 changes: 4 additions & 4 deletions contractAddrs-goerli.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"fixedLeg": "0xe7FD3ee1d1c70c87234ec57C2B036Ad8c0Fd0173",
"floatLeg": "0x6ae11ef30f1eC6e641E9B43725b20a172b0F090E",
"swap": "0x748b032161b2070C6DFeEe3a05C622ad61A71900",
"timelock": "0x205C15322d223E4DC66976F7E0f62fC2Fc3D0a86"
"fixedLeg": "0x130947FE7a04921faD22D9c3400ecf7e16AEbE98",
"floatLeg": "0xEdaE78BbaB80eE01dC4C703e40b795a77e18D7fc",
"swap": "0x92785E3144218F1e7b755a2D090B0c2AC1FdD5aD",
"timelock": "0x5e7E4584973305B901B950E66249D90C8099858F"
}
5 changes: 0 additions & 5 deletions contractAddrsTest.json

This file was deleted.

6 changes: 6 additions & 0 deletions contracts/IInterest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pragma solidity >=0.4.22 <0.9.0;

interface IInterest {
function rate() external view returns (uint);
function accrewedMul() external view returns (uint);
}
1 change: 0 additions & 1 deletion contracts/IParameters.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pragma solidity ^0.8.11;

import "./IRates.sol";
import "./IPrice.sol";
import "./IModel.sol";
import "./IToken.sol";
Expand Down
6 changes: 0 additions & 6 deletions contracts/IRates.sol

This file was deleted.

58 changes: 58 additions & 0 deletions contracts/Interest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
pragma solidity ^0.8.11;

import "./IInterest.sol";
import "./Math.sol";
import "./IModel.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

/// @notice Tracks accrewed interest
contract Interest is IInterest, Initializable {
using Math for uint;

uint constant ONE = 10**18;
uint constant ONE_26 = 10**26;
uint constant ONE_8 = 10**8;
uint constant COMPOUNDING_PERIOD = 3600; // 1 hour

/// @notice 1 + hourly interest rate. < 1 represents a negative rate
/// @dev 18-decimal fixed-point
uint public rate;

/// @notice Timestamp of when interest began accrewing
/// @dev start at a perfect multiple of COMPOUNDING_PERIOD so all contracts are synced
uint internal startTime;

/// @notice Value of accumulated interest multiplier when interest began accrewing
/// @dev 26-decimal fixed-point
uint internal startValue;

function initialize() internal onlyInitializing {
rate = ONE;
startTime = (block.timestamp / COMPOUNDING_PERIOD) * COMPOUNDING_PERIOD;
startValue = ONE_26;
}

/// @notice Accrewed interest multiplier. Nominal value of 1 fixedLeg token in denominating currency
/// @return Target currency-fixed exchange rate, expressed as denominating currency per fixed. 26-decimal fixed-point
function accrewedMul() public view returns (uint) {
unchecked {
return startValue * (rate*ONE_8).pow((block.timestamp - startTime) / COMPOUNDING_PERIOD) / ONE_26;
}
}

/// @notice Update interest rate according to model
function _updateRate(IModel model, uint potValue, uint fixedTV, uint _accrewedMul) internal {
uint _rate = uint(int(ONE) + model.getInterestRate(potValue, fixedTV));
if (_rate != rate) {
_setRate(_rate, _accrewedMul);
}
}

/// @notice Change the hourly interest rate. May represent a negative rate.
/// @param _rate 18-decimal fixed-point. 1 + hourly interest rate.
function _setRate(uint _rate, uint _accrewedMul) internal {
startValue = _accrewedMul;
startTime = startTime + (((block.timestamp - startTime) / COMPOUNDING_PERIOD) * COMPOUNDING_PERIOD);
rate = _rate;
}
}
Loading

0 comments on commit a6e88d1

Please sign in to comment.