Skip to content

Commit

Permalink
improve naming: floatLeg -> equityLeg, fixedLeg -> floatLeg
Browse files Browse the repository at this point in the history
  • Loading branch information
JonahGroendal committed Sep 27, 2022
1 parent a6e88d1 commit 0cfdf6c
Show file tree
Hide file tree
Showing 12 changed files with 217 additions and 219 deletions.
6 changes: 3 additions & 3 deletions .openzeppelin/unknown-1337.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
},
{
"address": "0xdDA6327139485221633A1FcD65f4aC932E60A2e1",
"txHash": "0x06de3dde6acfd6fa0bc4f82599d78f45986d7aa80ab9e48a2af53635ed3cd183",
"txHash": "0x5aa4875b29d47808bc743f748fce799a3c9224660ae849d74947f236b7e0224c",
"kind": "uups"
}
],
Expand Down Expand Up @@ -634,9 +634,9 @@
}
}
},
"e210f914b37b6e85931720ed5311b831f5d21029d3c21f679688a48ea4db965f": {
"7d2a76f3d9396e587cd59c0e5a7d94977db58c7ba3baf7f585d32236f551f483": {
"address": "0x82D50AD3C1091866E258Fd0f1a7cC9674609D254",
"txHash": "0xf8aea681428662ed06a3b6d581268eb411b709c94766eec93131bb31ddc19996",
"txHash": "0xb36fbd522ccdbdf1c19e010abfbd8cc97369400f3c704dcaa8db2585478dc145",
"layout": {
"storage": [
{
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ cons:
# TODO
- update solidity version
- change naming
- fixedLeg -> floatingLeg
- floatLeg -> equityLeg
- Volatility Swap -> Equity Swap
- look into using super cheap exp() function
- consolidate premium rates functions
Expand Down
2 changes: 1 addition & 1 deletion contracts/IModel.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pragma solidity ^0.8.11;

interface IModel {
function getInterestRate(uint potValue, uint fixedTV) external view returns (int);
function getInterestRate(uint potValue, uint floatTV) external view returns (int);
}
14 changes: 7 additions & 7 deletions contracts/ISwap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ pragma solidity ^0.8.11;
import "./IToken.sol";

interface ISwap {
function buyFixed (uint amount, address to) external;
function sellFixed(uint amount, address to) external;
function buyFloat (uint amount, address to) external;
function sellFloat(uint amount, address to) external;
function buyFloat (uint amount, address to) external;
function sellFloat (uint amount, address to) external;
function buyEquity (uint amount, address to) external;
function sellEquity(uint amount, address to) external;

function floatValue(uint amount) external view returns (uint);
function fixedValue(uint amount) external view returns (uint, uint);
function fixedValueNominal(uint amount) external view returns (uint);
function equityValue(uint amount) external view returns (uint);
function floatValue (uint amount) external view returns (uint, uint);
function floatValueNominal(uint amount) external view returns (uint);

function updateInterestRate() external;

Expand Down
8 changes: 4 additions & 4 deletions contracts/Interest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ contract Interest is IInterest, Initializable {
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
/// @notice Accrewed interest multiplier. Nominal value of 1 floatLeg token in denominating currency
/// @return Target currency-float exchange rate, expressed as denominating currency per float. 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));
function _updateRate(IModel model, uint potValue, uint floatTV, uint _accrewedMul) internal {
uint _rate = uint(int(ONE) + model.getInterestRate(potValue, floatTV));
if (_rate != rate) {
_setRate(_rate, _accrewedMul);
}
Expand Down
24 changes: 12 additions & 12 deletions contracts/Model.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ abstract contract Model is IModel {
int constant ONE = 10**18;
int constant STEP = ONE / 8765820; // 0.1% annually, compounded hourly

function getInterestRate(uint potValue, uint fixedTV) external pure returns (int) {
return(f(potValue, fixedTV) / STEP) * STEP;
function getInterestRate(uint potValue, uint floatTV) external pure returns (int) {
return(f(potValue, floatTV) / STEP) * STEP;
}

function f(uint potValue, uint fixedTV) internal virtual pure returns (int);
function f(uint potValue, uint floatTV) internal virtual pure returns (int);
}

/// @notice Interest rate changes linearly wrt collateral ratio
Expand All @@ -21,28 +21,28 @@ contract LinearModel is Model {
int constant B = -28 * ONE / 876582;

/// @notice M * collateral ratio + B
/// @dev collateral ratio = pot value / fixed-leg total value
function f(uint potValue, uint fixedTV) internal override pure returns (int) {
if (fixedTV == 0) {
/// @dev collateral ratio = pot value / float-leg total value
function f(uint potValue, uint floatTV) internal override pure returns (int) {
if (floatTV == 0) {
return 0;
}
unchecked {
return ((M * int(potValue)) / int(fixedTV)) + B;
return ((M * int(potValue)) / int(floatTV)) + B;
}
}
}

/// @notice Maintain a constant interest rate wrt value of float-leg tokens
/// @notice Maintain a constant interest rate wrt value of equity-leg tokens
contract ConstantFloatModel is Model {
// there are 8765.82 hours in a year
int constant FLOAT_RATE = 4 * ONE / 876582; // 4% APR, compounded hourly

function f(uint potValue, uint fixedTV) internal override pure returns (int) {
if (fixedTV == 0) {
function f(uint potValue, uint floatTV) internal override pure returns (int) {
if (floatTV == 0) {
return 0;
}
unchecked {
return ((FLOAT_RATE * int(potValue)) / int(fixedTV)) - FLOAT_RATE;
return ((FLOAT_RATE * int(potValue)) / int(floatTV)) - FLOAT_RATE;
}
}
}
Expand All @@ -53,7 +53,7 @@ contract NonlinearModel is Model {
// current idea:
// (.001 / (x - 1)) + Mx + B
// verticle asymtote at x = 1 and is about linear when x is larger
// also a plus: interest rate wrt value of float-leg tokens is monotonically increasing with x
// also a plus: interest rate wrt value of equity-leg tokens is monotonically increasing with x
// would need a minimum interest rate to avoid exploits
}
*/
16 changes: 8 additions & 8 deletions contracts/Parameters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,37 @@ contract Parameters is IParameters {
/// @notice Price of underlying in target asset
IPrice immutable price;

/// @notice Tokens comprising the swap's fixed leg
/// @notice Tokens comprising the swap's float leg
/// @notice Pegged to denominating asset + accrewed interest
/// @dev Must use 18 decimals
IToken immutable fixedLeg;
IToken immutable floatLeg;

/// @notice Tokens comprising the swap's floating leg
/// @notice Tokens comprising the swap's equity leg
/// @notice Pegged to [R/(R-1)]x leveraged underlying
/// @dev Must use 18 decimals
IToken immutable floatLeg;
IToken immutable equityLeg;

/// @notice Token collateralizing fixedLeg / underlying floatLeg
/// @notice Token collateralizing floatLeg / underlying equityLeg
/// @dev Must use 18 decimals
IToken immutable underlying;

constructor(
uint _fee,
IModel _model,
IPrice _price,
IToken _fixedLeg,
IToken _floatLeg,
IToken _equityLeg,
IToken _underlying)
{
fee = _fee;
model = _model;
price = _price;
fixedLeg = _fixedLeg;
floatLeg = _floatLeg;
equityLeg = _equityLeg;
underlying = _underlying;
}

function get() public view returns (uint, IModel, IPrice, IToken, IToken, IToken) {
return (fee, model, price, fixedLeg, floatLeg, underlying);
return (fee, model, price, floatLeg, equityLeg, underlying);
}
}
Loading

0 comments on commit 0cfdf6c

Please sign in to comment.