Skip to content

Commit

Permalink
Merge pull request #235 from pods-finance/develop
Browse files Browse the repository at this point in the history
Pods Release candidate v1.0.1
  • Loading branch information
Robsonsjre authored Apr 29, 2021
2 parents 3214b2c + 94a670f commit f9397d2
Show file tree
Hide file tree
Showing 37 changed files with 501 additions and 489 deletions.
13 changes: 13 additions & 0 deletions abi/FeePool.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,19 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "feeToken",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "feeValue",
Expand Down
43 changes: 19 additions & 24 deletions abi/OptionAMMPool.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,25 @@
"name": "TradeExactBOutput",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "spotPrice",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "newIV",
"type": "uint256"
}
],
"name": "TradeInfo",
"type": "event"
},
{
"inputs": [],
"name": "FIMP_DECIMALS",
Expand Down Expand Up @@ -593,30 +612,6 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "asset",
"type": "address"
},
{
"internalType": "uint256",
"name": "decimalsOutput",
"type": "uint256"
}
],
"name": "getSpotPrice",
"outputs": [
{
"internalType": "uint256",
"name": "spotPrice",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down
33 changes: 20 additions & 13 deletions abi/PriceProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,6 @@
"name": "OwnershipTransferred",
"type": "event"
},
{
"inputs": [],
"name": "MIN_UPDATE_INTERVAL",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "configurationManager",
Expand Down Expand Up @@ -199,6 +186,19 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "minUpdateInterval",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
Expand Down Expand Up @@ -262,5 +262,12 @@
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "updateMinUpdateInterval",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
40 changes: 39 additions & 1 deletion abi/SigmaGuesser.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
[
{
"inputs": [
{
"internalType": "contract IConfigurationManager",
"name": "_configurationManager",
"type": "address"
},
{
"internalType": "address",
"name": "blackScholes",
Expand All @@ -12,7 +17,20 @@
},
{
"inputs": [],
"name": "ACCEPTABLE_ERROR",
"name": "MIN_ACCEPTABLE_RANGE",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "acceptableRange",
"outputs": [
{
"internalType": "uint256",
Expand All @@ -36,6 +54,19 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "configurationManager",
"outputs": [
{
"internalType": "contract IConfigurationManager",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -233,5 +264,12 @@
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "updateAcceptableRange",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
7 changes: 7 additions & 0 deletions contracts/amm/FeePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ contract FeePool is IFeePool, Ownable {
emit ShareMinted(_token, to, amount);
}

/**
* @notice Return the current fee token
*/
function feeToken() external override view returns (address) {
return _token;
}

/**
* @notice Return the current fee value
*/
Expand Down
4 changes: 2 additions & 2 deletions contracts/amm/OptionAMMFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ contract OptionAMMFactory is IOptionAMMFactory {
) external override returns (address) {
require(address(_pools[_optionAddress]) == address(0), "OptionAMMFactory: Pool already exists");

FeePool feePoolTokenA = new FeePool(_stableAsset, 15, 6);
FeePool feePoolTokenB = new FeePool(_stableAsset, 15, 6);
FeePool feePoolTokenA = new FeePool(_stableAsset, 35, 4);
FeePool feePoolTokenB = new FeePool(_stableAsset, 15, 4);

OptionAMMPool pool = new OptionAMMPool(
_optionAddress,
Expand Down
46 changes: 29 additions & 17 deletions contracts/amm/OptionAMMPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ contract OptionAMMPool is AMM, IOptionAMMPool, CappedPool, FlashloanProtection {
*/
PriceProperties public priceProperties;

event TradeInfo(uint256 spotPrice, uint256 newIV);

constructor(
address _optionAddress,
address _stableAsset,
Expand Down Expand Up @@ -123,6 +125,7 @@ contract OptionAMMPool is AMM, IOptionAMMPool, CappedPool, FlashloanProtection {
_beforeStartOfExerciseWindow();
_emergencyStopCheck();
_addLiquidity(amountOfA, amountOfB, owner);
_getTradeInfo();
}

/**
Expand All @@ -135,6 +138,7 @@ contract OptionAMMPool is AMM, IOptionAMMPool, CappedPool, FlashloanProtection {
_nonReentrant();
_emergencyStopCheck();
_removeLiquidity(amountOfA, amountOfB);
_getTradeInfo();
}

/**
Expand All @@ -161,7 +165,11 @@ contract OptionAMMPool is AMM, IOptionAMMPool, CappedPool, FlashloanProtection {
_beforeStartOfExerciseWindow();
_emergencyStopCheck();
priceProperties.sigmaInitialGuess = sigmaInitialGuess;
return _tradeExactAInput(exactAmountAIn, minAmountBOut, owner);

uint256 amountBOut = _tradeExactAInput(exactAmountAIn, minAmountBOut, owner);

_getTradeInfo();
return amountBOut;
}

/**
Expand All @@ -188,7 +196,11 @@ contract OptionAMMPool is AMM, IOptionAMMPool, CappedPool, FlashloanProtection {
_beforeStartOfExerciseWindow();
_emergencyStopCheck();
priceProperties.sigmaInitialGuess = sigmaInitialGuess;
return _tradeExactAOutput(exactAmountAOut, maxAmountBIn, owner);

uint256 amountBIn = _tradeExactAOutput(exactAmountAOut, maxAmountBIn, owner);

_getTradeInfo();
return amountBIn;
}

/**
Expand All @@ -214,7 +226,11 @@ contract OptionAMMPool is AMM, IOptionAMMPool, CappedPool, FlashloanProtection {
_beforeStartOfExerciseWindow();
_emergencyStopCheck();
priceProperties.sigmaInitialGuess = sigmaInitialGuess;
return _tradeExactBInput(exactAmountBIn, minAmountAOut, owner);

uint256 amountAOut = _tradeExactBInput(exactAmountBIn, minAmountAOut, owner);

_getTradeInfo();
return amountAOut;
}

/**
Expand All @@ -241,7 +257,11 @@ contract OptionAMMPool is AMM, IOptionAMMPool, CappedPool, FlashloanProtection {
_beforeStartOfExerciseWindow();
_emergencyStopCheck();
priceProperties.sigmaInitialGuess = sigmaInitialGuess;
return _tradeExactBOutput(exactAmountBOut, maxAmountAIn, owner);

uint256 amountAIn = _tradeExactBOutput(exactAmountBOut, maxAmountAIn, owner);

_getTradeInfo();
return amountAIn;
}

/**
Expand Down Expand Up @@ -359,19 +379,6 @@ contract OptionAMMPool is AMM, IOptionAMMPool, CappedPool, FlashloanProtection {
return _getOptionTradeDetailsExactBOutput(exactAmountBOut);
}

/**
* @notice getSpotPrice Check the spot price of given asset with a certain precision controlled by decimalsOutput
*
* @param asset address to check the spot price
* @param decimalsOutput number of decimals of the response
*
* @return spotPrice amount of A that will be transfer from msg.sender to the pool
*/

function getSpotPrice(address asset, uint256 decimalsOutput) external override view returns (uint256 spotPrice) {
return _getSpotPrice(asset, decimalsOutput);
}

function _calculateNewABPrice(uint256 spotPrice, uint256 timeToMaturity) internal view returns (uint256) {
if (timeToMaturity == 0) {
return 0;
Expand Down Expand Up @@ -826,4 +833,9 @@ contract OptionAMMPool is AMM, IOptionAMMPool, CappedPool, FlashloanProtection {
"Pool: Pool is stopped"
);
}

function _getTradeInfo() private {
uint256 spotPrice = _getSpotPrice(priceProperties.underlyingAsset, PRICING_DECIMALS);
emit TradeInfo(spotPrice, priceProperties.currentSigma);
}
}
Loading

0 comments on commit f9397d2

Please sign in to comment.