Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
3xHarry committed Apr 10, 2023
1 parent 8843085 commit 39bb0b5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/v2/Carousel/CarouselFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ contract CarouselFactory is VaultFactoryV2 {
tokenToOracle[_marketCalldata.token] = _marketCalldata.oracle;
}

marketId = getMarketId(_marketCalldata.token, _marketCalldata.strike);
marketId = getMarketId(_marketCalldata.token, _marketCalldata.strike, _marketCalldata.underlyingAsset);
if (marketIdToVaults[marketId][0] != address(0))
revert MarketAlreadyExists();

Expand Down
41 changes: 36 additions & 5 deletions src/v2/VaultFactoryV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ contract VaultFactoryV2 is Ownable {

mapping(uint256 => address[2]) public marketIdToVaults; //[0] premium and [1] collateral vault
mapping(uint256 => uint256[]) public marketIdToEpochs; //all epochs in the market
mapping(uint256 => MarketInfo) public marketIdInfo; // marketId configuration
mapping(uint256 => uint16) public epochFee; // epochId to fee
mapping(address => address) public tokenToOracle; //token address to respective oracle smart contract address
mapping(address => bool) public controllers;
Expand Down Expand Up @@ -85,7 +86,13 @@ contract VaultFactoryV2 is Ownable {
tokenToOracle[_marketCalldata.token] = _marketCalldata.oracle;
}

marketId = getMarketId(_marketCalldata.token, _marketCalldata.strike);
marketId = getMarketId(_marketCalldata.token, _marketCalldata.strike, _marketCalldata.underlyingAsset);
marketIdInfo[marketId] = MarketInfo(
_marketCalldata.token,
_marketCalldata.strike,
_marketCalldata.underlyingAsset
);

if (marketIdToVaults[marketId][0] != address(0))
revert MarketAlreadyExists();

Expand Down Expand Up @@ -395,16 +402,33 @@ contract VaultFactoryV2 is Ownable {

/**
@notice Function to compute the marketId from a token and a strike price
@param token Address of the token
@param strikePrice uint256 of the strike price
@param _token Address of the token
@param _strikePrice uint256 of the strike price
@param _underlying Address of the underlying
@return marketId uint256 of the marketId
*/
function getMarketId(address token, uint256 strikePrice)
function getMarketId(address _token, uint256 _strikePrice, address _underlying)
public
pure
returns (uint256 marketId)
{
return uint256(keccak256(abi.encodePacked(token, strikePrice)));
return uint256(keccak256(abi.encodePacked(_token, _strikePrice, _underlying)));
}


// get marketInfo
function getMarketInfo(uint256 _marketId)
public
view
returns (
address token,
uint256 strike,
address underlyingAsset
)
{
token = marketIdInfo[_marketId].token;
strike = marketIdInfo[_marketId].strike;
underlyingAsset = marketIdInfo[_marketId].underlyingAsset;
}

/**
Expand Down Expand Up @@ -448,6 +472,13 @@ contract VaultFactoryV2 is Ownable {
IVaultV2 collateral;
}


struct MarketInfo {
address token;
uint256 strike;
address underlyingAsset;
}

/*//////////////////////////////////////////////////////////////
MODIFIERS
//////////////////////////////////////////////////////////////*/
Expand Down
2 changes: 1 addition & 1 deletion test/V2/Carousel/CarouselFactoryTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ contract CarouselFactoryTest is Helper {

// test oracle is set
assertTrue(factory.tokenToOracle(token) == oracle);
assertEq(marketId, factory.getMarketId(token, strike));
assertEq(marketId, factory.getMarketId(token, strike, underlying));

// test if counterparty is set
assertEq(IVaultV2(premium).counterPartyVault(), collateral);
Expand Down
2 changes: 1 addition & 1 deletion test/V2/FactoryV2Test.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ contract FactoryV2Test is Helper {

// test oracle is set
assertTrue(factory.tokenToOracle(token) == oracle);
assertEq(marketId, factory.getMarketId(token, strike));
assertEq(marketId, factory.getMarketId(token, strike, underlying));

// test if counterparty is set
assertEq(IVaultV2(premium).counterPartyVault(), collateral);
Expand Down

0 comments on commit 39bb0b5

Please sign in to comment.