-
Notifications
You must be signed in to change notification settings - Fork 66
Feature/Add product management function setProducts() #401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5febcb8
Add ability to initialize and edit/add/remove products in StakingPool
0xdewy 74c25af
Fix total capacity decimals
0xdewy 94cba2d
Clean up setProducts and cast smaller uints to 256 when used in memory
0xdewy e0b2b20
Verify targetPrice is above globalMinPriceRatio. Fix createStakingPoo…
0xdewy f1d006e
Rename setPrice to setTargetPrice. Add check that product isn't initi…
0xdewy 15820a5
Move targetPrice verification to CoverUtilsLib
0xdewy c33d757
Lint fixes
0xdewy e30b19b
Change ytcUnderlyingAsset to yieldTokenAddress in StakingPool tests
shark0der File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 contains hidden or 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 contains hidden or 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 contains hidden or 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,88 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "../../interfaces/IStakingPool.sol"; | ||
import "../../interfaces/ICover.sol"; | ||
import "../../modules/cover/CoverUtilsLib.sol"; | ||
|
||
contract SPMockCoverProducts { | ||
uint24 public constant globalCapacityRatio = 2; | ||
uint256 public constant globalRewardsRatio = 1; | ||
|
||
uint public constant GLOBAL_MIN_PRICE_RATIO = 100; // 1% | ||
|
||
mapping(uint => address) public stakingPool; | ||
mapping(uint256 => Product) public products; | ||
mapping(uint256 => ProductType) public productTypes; | ||
|
||
function setStakingPool(address addr, uint id) public { | ||
stakingPool[id] = addr; | ||
} | ||
|
||
function setProduct(Product memory product, uint256 id) public { | ||
products[id] = product; | ||
} | ||
|
||
function setProductType(ProductType calldata product, uint256 id) public { | ||
productTypes[id] = product; | ||
} | ||
|
||
|
||
function getPriceAndCapacityRatios(uint[] calldata productIds) public view returns ( | ||
uint _globalCapacityRatio, | ||
uint _globalMinPriceRatio, | ||
uint[] memory _initialPrices, | ||
uint[] memory _capacityReductionRatios | ||
) { | ||
_globalCapacityRatio = uint(globalCapacityRatio); | ||
_globalMinPriceRatio = GLOBAL_MIN_PRICE_RATIO; | ||
_capacityReductionRatios = new uint[](productIds.length); | ||
_initialPrices = new uint[](productIds.length); | ||
for (uint i = 0; i < productIds.length; i++) { | ||
Product memory product = products[productIds[i]]; | ||
require(product.initialPriceRatio > 0, "Cover: Product deprecated or not initialized"); | ||
_initialPrices[i] = uint(product.initialPriceRatio); | ||
_capacityReductionRatios[i] = uint(product.capacityReductionRatio); | ||
} | ||
} | ||
|
||
function allocateCapacity( | ||
BuyCoverParams memory params, | ||
uint256 coverId, | ||
IStakingPool _stakingPool | ||
) public returns (uint256 coveredAmountInNXM, uint256 premiumInNXM, uint256 rewardsInNXM) { | ||
Product memory product = products[params.productId]; | ||
uint256 gracePeriod = uint256(productTypes[product.productType].gracePeriodInDays) * 1 days; | ||
|
||
return _stakingPool.allocateStake( | ||
CoverRequest( | ||
coverId, | ||
params.productId, | ||
params.amount, | ||
params.period, | ||
gracePeriod, | ||
globalCapacityRatio, | ||
product.capacityReductionRatio, | ||
globalRewardsRatio | ||
) | ||
); | ||
} | ||
|
||
function initializeStaking( | ||
address staking_, | ||
address _manager, | ||
bool _isPrivatePool, | ||
uint256 _initialPoolFee, | ||
uint256 _maxPoolFee, | ||
ProductInitializationParams[] memory params, | ||
uint256 _poolId | ||
) external { | ||
|
||
for (uint i = 0; i < params.length; i++) { | ||
params[i].initialPrice = products[params[i].productId].initialPriceRatio; | ||
require(params[i].targetPrice >= GLOBAL_MIN_PRICE_RATIO, "CoverUtilsLib: Target price below GLOBAL_MIN_PRICE_RATIO"); | ||
} | ||
IStakingPool(staking_).initialize(_manager, _isPrivatePool, _initialPoolFee, _maxPoolFee, params, _poolId); | ||
} | ||
} |
This file contains hidden or 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 contains hidden or 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 contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.