-
Notifications
You must be signed in to change notification settings - Fork 0
share tokens and new deployment process #17
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
Open
KillariDev
wants to merge
5
commits into
security-pool-draft
Choose a base branch
from
sharetokens-and-new-factory-deployment-process
base: security-pool-draft
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // SPDX-License-Identifier: UNICENSE | ||
| pragma solidity 0.8.30; | ||
| import { Auction } from './Auction.sol'; | ||
|
|
||
| contract AuctionFactory { | ||
| function deployAuction(bytes32 salt) external returns (Auction) { | ||
| return new Auction{ salt: keccak256(abi.encodePacked(msg.sender, salt)) }(); | ||
| } | ||
| } |
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
15 changes: 15 additions & 0 deletions
15
solidity/contracts/peripherals/PriceOracleManagerAndOperatorQueuerFactory.sol
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,15 @@ | ||
| // SPDX-License-Identifier: UNICENSE | ||
| pragma solidity 0.8.30; | ||
| import { IShareToken } from './interfaces/IShareToken.sol'; | ||
| import { ShareToken } from './tokens/ShareToken.sol'; | ||
| import { ISecurityPool } from './interfaces/ISecurityPool.sol'; | ||
| import { Zoltar } from '../Zoltar.sol'; | ||
| import { OpenOracle } from './openOracle/OpenOracle.sol'; | ||
| import { ReputationToken } from '../ReputationToken.sol'; | ||
| import { PriceOracleManagerAndOperatorQueuer } from './PriceOracleManagerAndOperatorQueuer.sol'; | ||
|
|
||
| contract PriceOracleManagerAndOperatorQueuerFactory { | ||
| function deployPriceOracleManagerAndOperatorQueuer(OpenOracle _openOracle, ReputationToken _reputationToken, bytes32 salt) external returns (PriceOracleManagerAndOperatorQueuer) { | ||
| return new PriceOracleManagerAndOperatorQueuer{ salt: keccak256(abi.encodePacked(msg.sender, salt)) }(_openOracle, _reputationToken); | ||
| } | ||
| } |
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,7 @@ pragma solidity 0.8.30; | |||||
| import { Auction } from './Auction.sol'; | ||||||
| import { Zoltar } from '../Zoltar.sol'; | ||||||
| import { ReputationToken } from '../ReputationToken.sol'; | ||||||
| import { CompleteSet } from './CompleteSet.sol'; | ||||||
| import { IShareToken } from './interfaces/IShareToken.sol'; | ||||||
| import { PriceOracleManagerAndOperatorQueuer } from './PriceOracleManagerAndOperatorQueuer.sol'; | ||||||
| import { ISecurityPool, SecurityVault, SystemState, QuestionOutcome, ISecurityPoolFactory } from './interfaces/ISecurityPool.sol'; | ||||||
| import { OpenOracle } from './openOracle/OpenOracle.sol'; | ||||||
|
|
@@ -38,8 +38,9 @@ contract SecurityPool is ISecurityPool { | |||||
| uint256 public truthAuctionStarted; | ||||||
| SystemState public systemState; | ||||||
|
|
||||||
| CompleteSet public immutable completeSet; | ||||||
| IShareToken public immutable shareToken; | ||||||
| Auction public immutable truthAuction; | ||||||
|
|
||||||
| ReputationToken public repToken; | ||||||
| ISecurityPoolFactory public immutable securityPoolFactory; | ||||||
|
|
||||||
|
|
@@ -64,22 +65,22 @@ contract SecurityPool is ISecurityPool { | |||||
| _; | ||||||
| } | ||||||
|
|
||||||
| constructor(ISecurityPoolFactory _securityPoolFactory, OpenOracle _openOracle, ISecurityPool _parent, Zoltar _zoltar, uint192 _universeId, uint56 _questionId, uint256 _securityMultiplier) { | ||||||
| constructor(ISecurityPoolFactory _securityPoolFactory, Auction _truthAuction, PriceOracleManagerAndOperatorQueuer _priceOracleManagerAndOperatorQueuer, IShareToken _shareToken, OpenOracle _openOracle, ISecurityPool _parent, Zoltar _zoltar, uint192 _universeId, uint56 _questionId, uint256 _securityMultiplier) { | ||||||
| universeId = _universeId; | ||||||
| securityPoolFactory = _securityPoolFactory; | ||||||
| questionId = _questionId; | ||||||
| securityMultiplier = _securityMultiplier; | ||||||
| zoltar = _zoltar; | ||||||
| parent = _parent; | ||||||
| openOracle = _openOracle; | ||||||
| truthAuction = _truthAuction; | ||||||
| priceOracleManagerAndOperatorQueuer = _priceOracleManagerAndOperatorQueuer; | ||||||
| if (address(parent) == address(0x0)) { // origin universe never does truthAuction | ||||||
| systemState = SystemState.Operational; | ||||||
| } else { | ||||||
| systemState = SystemState.ForkMigration; | ||||||
| truthAuction = new Auction{ salt: bytes32(uint256(0x1)) }(address(this)); | ||||||
| } | ||||||
| // todo, we can probably do these smarter so that we don't need migration | ||||||
| completeSet = new CompleteSet{ salt: bytes32(uint256(0x1)) }(address(this)); | ||||||
| shareToken = _shareToken; | ||||||
| } | ||||||
|
|
||||||
| function setStartingParams(uint256 _currentRetentionRate, uint256 _repEthPrice, uint256 _completeSetCollateralAmount) public { | ||||||
|
|
@@ -88,7 +89,6 @@ contract SecurityPool is ISecurityPool { | |||||
| currentRetentionRate = _currentRetentionRate; | ||||||
| completeSetCollateralAmount = _completeSetCollateralAmount; | ||||||
| (repToken,,) = zoltar.universes(universeId); | ||||||
| priceOracleManagerAndOperatorQueuer = new PriceOracleManagerAndOperatorQueuer{ salt: bytes32(uint256(0x1)) }(openOracle, this, repToken); | ||||||
| priceOracleManagerAndOperatorQueuer.setRepEthPrice(_repEthPrice); | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -231,8 +231,9 @@ contract SecurityPool is ISecurityPool { | |||||
| require(systemState == SystemState.Operational, 'system is not Operational'); //todo, we want to be able to create complete sets in the children right away, figure accounting out | ||||||
| updateCollateralAmount(); | ||||||
| require(securityBondAllowance - completeSetCollateralAmount >= msg.value, 'no capacity to create that many sets'); | ||||||
| uint256 amountToMint = completeSet.totalSupply() == completeSetCollateralAmount ? msg.value : msg.value * completeSet.totalSupply() / completeSetCollateralAmount; | ||||||
| completeSet.mint(msg.sender, amountToMint); | ||||||
| uint256 totalSupply = shareToken.totalSupplyForUniverse(universeId); | ||||||
| uint256 amountToMint = totalSupply == completeSetCollateralAmount ? msg.value : msg.value * totalSupply / completeSetCollateralAmount; // todo this is wrong | ||||||
| shareToken.mintCompleteSets(universeId, msg.sender, amountToMint); | ||||||
| completeSetCollateralAmount += msg.value; | ||||||
| updateRetentionRate(); | ||||||
| } | ||||||
|
|
@@ -241,20 +242,25 @@ contract SecurityPool is ISecurityPool { | |||||
| require(systemState == SystemState.Operational, 'system is not Operational'); // todo, we want to allow people to exit, but for accounting purposes that is difficult but maybe there's a way? | ||||||
| updateCollateralAmount(); | ||||||
| // takes in complete set and releases security bond and eth | ||||||
| uint256 ethValue = amount * completeSetCollateralAmount / completeSet.totalSupply(); | ||||||
| completeSet.burn(msg.sender, amount); | ||||||
| uint256 totalSupply = shareToken.totalSupplyForUniverse(universeId); | ||||||
| uint256 ethValue = amount * completeSetCollateralAmount / totalSupply; // this is wrong | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| shareToken.burnCompleteSets(universeId, msg.sender, amount); | ||||||
| completeSetCollateralAmount -= ethValue; | ||||||
| updateRetentionRate(); | ||||||
| (bool sent, ) = payable(msg.sender).call{value: ethValue}(''); | ||||||
| (bool sent, ) = payable(msg.sender).call{ value: ethValue }(''); | ||||||
| require(sent, 'Failed to send Ether'); | ||||||
| } | ||||||
|
|
||||||
| /* | ||||||
| function redeemShare() isOperational public { | ||||||
| require(zoltar.isFinalized(universeId, questionId), 'Question has not finalized!'); | ||||||
| //convertes yes,no or invalid share to 1 eth each, depending on market outcome | ||||||
| function redeemShares() isOperational external { | ||||||
| Zoltar.Outcome outcome = zoltar.finalizeQuestion(universeId, questionId); | ||||||
| require(outcome != Zoltar.Outcome.None, 'Question has not finalized!'); | ||||||
| uint256 tokenId = shareToken.getTokenId(universeId, outcome); | ||||||
| uint256 amount = shareToken.burnTokenId(tokenId, msg.sender); | ||||||
| uint256 totalSupply = shareToken.totalSupplyForUniverse(universeId); | ||||||
| uint256 ethValue = amount * completeSetCollateralAmount / totalSupply; // this is wrong | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| (bool sent, ) = payable(msg.sender).call{ value: ethValue }(''); | ||||||
| require(sent, 'Failed to send Ether'); | ||||||
| } | ||||||
| */ | ||||||
|
|
||||||
| //////////////////////////////////////// | ||||||
| // FORKING (migrate vault (oi+rep), truth truthAuction) | ||||||
|
|
@@ -263,7 +269,6 @@ contract SecurityPool is ISecurityPool { | |||||
| (,, uint256 forkTime) = zoltar.universes(universeId); | ||||||
| require(forkTime > 0, 'Zoltar needs to have forked before Security Pool can do so'); | ||||||
| require(systemState == SystemState.Operational, 'System needs to be operational to trigger fork'); | ||||||
| require(securityPoolForkTriggeredTimestamp == 0, 'fork already triggered'); | ||||||
| require(!zoltar.isFinalized(universeId, questionId), 'question has been finalized already'); | ||||||
| systemState = SystemState.PoolForked; | ||||||
| securityPoolForkTriggeredTimestamp = block.timestamp; | ||||||
|
|
@@ -285,7 +290,8 @@ contract SecurityPool is ISecurityPool { | |||||
| if (address(children[uint8(outcome)]) == address(0x0)) { | ||||||
| // first vault migrater creates new pool and transfers all REP to it | ||||||
| uint192 childUniverseId = (universeId << 2) + uint192(outcome) + 1; | ||||||
| children[uint8(outcome)] = securityPoolFactory.deploySecurityPool(openOracle, this, zoltar, childUniverseId, questionId, securityMultiplier, currentRetentionRate, priceOracleManagerAndOperatorQueuer.lastPrice(), 0); | ||||||
| children[uint8(outcome)] = securityPoolFactory.deployChildSecurityPool(shareToken, childUniverseId, questionId, securityMultiplier, currentRetentionRate, priceOracleManagerAndOperatorQueuer.lastPrice(), 0); | ||||||
| shareToken.authorize(children[uint8(outcome)]); | ||||||
| ReputationToken childReputationToken = children[uint8(outcome)].repToken(); | ||||||
| childReputationToken.transfer(address(children[uint8(outcome)]), childReputationToken.balanceOf(address(this))); | ||||||
| } | ||||||
|
|
@@ -321,7 +327,6 @@ contract SecurityPool is ISecurityPool { | |||||
| function startTruthAuction() public { | ||||||
| require(systemState == SystemState.ForkMigration, 'System needs to be in migration'); | ||||||
| require(block.timestamp > securityPoolForkTriggeredTimestamp + SecurityPoolUtils.MIGRATION_TIME, 'migration time needs to pass first'); | ||||||
| require(truthAuctionStarted == 0, 'Auction already started'); | ||||||
| systemState = SystemState.ForkTruthAuction; | ||||||
| truthAuctionStarted = block.timestamp; | ||||||
| parent.updateCollateralAmount(); | ||||||
|
|
||||||
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 |
|---|---|---|
| @@ -1,15 +1,68 @@ | ||
| // SPDX-License-Identifier: UNICENSE | ||
| pragma solidity 0.8.30; | ||
| import { IShareToken } from './interfaces/IShareToken.sol'; | ||
| import { SecurityPool } from './SecurityPool.sol'; | ||
| import { ISecurityPool, ISecurityPoolFactory } from './interfaces/ISecurityPool.sol'; | ||
| import { OpenOracle } from './openOracle/OpenOracle.sol'; | ||
| import { Zoltar } from '../Zoltar.sol'; | ||
| import { ShareTokenFactory } from './ShareTokenFactory.sol'; | ||
| import { AuctionFactory } from './AuctionFactory.sol'; | ||
| import { Auction } from './Auction.sol'; | ||
| import { ShareToken } from './tokens/ShareToken.sol'; | ||
| import { PriceOracleManagerAndOperatorQueuerFactory } from './PriceOracleManagerAndOperatorQueuerFactory.sol'; | ||
| import { PriceOracleManagerAndOperatorQueuer } from './PriceOracleManagerAndOperatorQueuer.sol'; | ||
| import { ReputationToken } from '../ReputationToken.sol'; | ||
|
|
||
| contract SecurityPoolFactory is ISecurityPoolFactory { | ||
| event DeploySecurityPool(ISecurityPool securityPool, OpenOracle openOracle, ISecurityPool parent, Zoltar zoltar, uint192 universeId, uint56 questionId, uint256 securityMultiplier, uint256 currentRetentionRate, uint256 startingRepEthPrice, uint256 completeSetCollateralAmount); | ||
| function deploySecurityPool(OpenOracle openOracle, ISecurityPool parent, Zoltar zoltar, uint192 universeId, uint56 questionId, uint256 securityMultiplier, uint256 currentRetentionRate, uint256 startingRepEthPrice, uint256 completeSetCollateralAmount) external returns (ISecurityPool securityPoolAddress) { | ||
| securityPoolAddress = new SecurityPool{salt: bytes32(uint256(0x1))}(this, openOracle, parent, zoltar, universeId, questionId, securityMultiplier); | ||
| securityPoolAddress.setStartingParams(currentRetentionRate, startingRepEthPrice, completeSetCollateralAmount); | ||
| emit DeploySecurityPool(securityPoolAddress, openOracle, parent, zoltar, universeId, questionId, securityMultiplier, currentRetentionRate, startingRepEthPrice, completeSetCollateralAmount); | ||
| ShareTokenFactory shareTokenFactory; | ||
| AuctionFactory auctionFactory; | ||
| PriceOracleManagerAndOperatorQueuerFactory priceOracleManagerAndOperatorQueuerFactory; | ||
| Zoltar zoltar; | ||
| OpenOracle openOracle; | ||
|
|
||
| event DeploySecurityPool(ISecurityPool securityPool, Auction truthAuction, PriceOracleManagerAndOperatorQueuer priceOracleManagerAndOperatorQueuer, IShareToken shareToken, ISecurityPool parent, uint192 universeId, uint56 questionId, uint256 securityMultiplier, uint256 currentRetentionRate, uint256 startingRepEthPrice, uint256 completeSetCollateralAmount); | ||
|
|
||
| constructor(OpenOracle _openOracle, Zoltar _zoltar, ShareTokenFactory _shareTokenFactory, AuctionFactory _auctionFactory, PriceOracleManagerAndOperatorQueuerFactory _priceOracleManagerAndOperatorQueuerFactory) { | ||
| shareTokenFactory = _shareTokenFactory; | ||
| auctionFactory = _auctionFactory; | ||
| priceOracleManagerAndOperatorQueuerFactory = _priceOracleManagerAndOperatorQueuerFactory; | ||
| zoltar = _zoltar; | ||
| openOracle = _openOracle; | ||
| } | ||
|
|
||
| function deployChildSecurityPool(IShareToken shareToken, uint192 universeId, uint56 questionId, uint256 securityMultiplier, uint256 currentRetentionRate, uint256 startingRepEthPrice, uint256 completeSetCollateralAmount) external returns (ISecurityPool securityPool) { | ||
| ISecurityPool parent = ISecurityPool(payable(msg.sender)); | ||
| bytes32 securityPoolSalt = keccak256(abi.encodePacked(parent, universeId, questionId, securityMultiplier)); | ||
| (ReputationToken reputationToken,,) = zoltar.universes(universeId); | ||
| PriceOracleManagerAndOperatorQueuer priceOracleManagerAndOperatorQueuer = priceOracleManagerAndOperatorQueuerFactory.deployPriceOracleManagerAndOperatorQueuer(openOracle, reputationToken, securityPoolSalt); | ||
|
|
||
| Auction truthAuction = auctionFactory.deployAuction(securityPoolSalt); | ||
|
|
||
| securityPool = new SecurityPool{ salt: bytes32(uint256(0x0)) }(this, truthAuction, priceOracleManagerAndOperatorQueuer, shareToken, openOracle, parent, zoltar, universeId, questionId, securityMultiplier); | ||
|
|
||
| priceOracleManagerAndOperatorQueuer.setSecurityPool(securityPool); | ||
| securityPool.setStartingParams(currentRetentionRate, startingRepEthPrice, completeSetCollateralAmount); | ||
|
|
||
| truthAuction.setOwner(address(securityPool)); | ||
| emit DeploySecurityPool(securityPool, truthAuction, priceOracleManagerAndOperatorQueuer, shareToken, parent, universeId, questionId, securityMultiplier, currentRetentionRate, startingRepEthPrice, completeSetCollateralAmount); | ||
| } | ||
|
|
||
| function deployOriginSecurityPool(uint192 universeId, uint56 questionId, uint256 securityMultiplier, uint256 currentRetentionRate, uint256 startingRepEthPrice, uint256 completeSetCollateralAmount) external returns (ISecurityPool securityPool) { | ||
| bytes32 securityPoolSalt = keccak256(abi.encodePacked(address(0x0), universeId, questionId, securityMultiplier)); | ||
| (ReputationToken reputationToken,,) = zoltar.universes(universeId); | ||
| PriceOracleManagerAndOperatorQueuer priceOracleManagerAndOperatorQueuer = priceOracleManagerAndOperatorQueuerFactory.deployPriceOracleManagerAndOperatorQueuer(openOracle, reputationToken, securityPoolSalt); | ||
|
|
||
| // sharetoken has different salt as sharetoken address does not change in forks | ||
| bytes32 shareTokenSalt = keccak256(abi.encodePacked(securityMultiplier)); | ||
| IShareToken shareToken = shareTokenFactory.deployShareToken(questionId, shareTokenSalt); | ||
|
|
||
| securityPool = new SecurityPool{ salt: bytes32(uint256(0x0)) }(this, Auction(address(0x0)), priceOracleManagerAndOperatorQueuer, shareToken, openOracle, ISecurityPool(payable(0x0)), zoltar, universeId, questionId, securityMultiplier); | ||
|
|
||
| priceOracleManagerAndOperatorQueuer.setSecurityPool(securityPool); | ||
| securityPool.setStartingParams(currentRetentionRate, startingRepEthPrice, completeSetCollateralAmount); | ||
|
|
||
| shareToken.authorize(securityPool); | ||
|
|
||
| emit DeploySecurityPool(securityPool, Auction(address(0x0)), priceOracleManagerAndOperatorQueuer, shareToken, ISecurityPool(payable(0x0)), universeId, questionId, securityMultiplier, currentRetentionRate, startingRepEthPrice, completeSetCollateralAmount); | ||
| } | ||
| } |
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,18 @@ | ||
| // SPDX-License-Identifier: UNICENSE | ||
| pragma solidity 0.8.30; | ||
| import { IShareToken } from './interfaces/IShareToken.sol'; | ||
| import { ShareToken } from './tokens/ShareToken.sol'; | ||
| import { ISecurityPool } from './interfaces/ISecurityPool.sol'; | ||
| import { Zoltar } from '../Zoltar.sol'; | ||
|
|
||
| contract ShareTokenFactory { | ||
| Zoltar zoltar; | ||
|
|
||
| constructor(Zoltar _zoltar) { | ||
| zoltar = _zoltar; | ||
| } | ||
|
|
||
| function deployShareToken(uint56 questionId, bytes32 salt) external returns (IShareToken shareToken) { | ||
| return new ShareToken{ salt: salt }(msg.sender, zoltar, questionId); | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no way to remove the cyclic dependency that results in this being necessary? I really don't like mutable variables if there is any option for immutability. IIUC, the owner should never change, this is just necessary because you have a cyclic dependency between this contract and another?