This repository has been archived by the owner on Jan 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
C4 token fixes #121
Open
mikeyrf
wants to merge
3
commits into
main
Choose a base branch
from
c4-ovl
base: main
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
C4 token fixes #121
Changes from all commits
Commits
Show all changes
3 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 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 |
---|---|---|
|
@@ -10,7 +10,7 @@ compiler: | |
solc: | ||
version: 0.8.7 | ||
remappings: | ||
- "@openzeppelin=OpenZeppelin/[email protected].2" | ||
- "@openzeppelin=OpenZeppelin/[email protected].3" | ||
optimizer: | ||
enabled: true | ||
runs: 400 | ||
|
@@ -21,4 +21,4 @@ compiler: | |
|
||
autofetch_sources: True | ||
dependencies: | ||
- OpenZeppelin/[email protected].2 | ||
- OpenZeppelin/[email protected].3 |
This file contains 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 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 |
---|---|---|
|
@@ -8,7 +8,6 @@ import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol"; | |
import "../interfaces/IOverlayV1Market.sol"; | ||
import "../interfaces/IOverlayV1Mothership.sol"; | ||
import "../interfaces/IOverlayToken.sol"; | ||
import "../interfaces/IOverlayTokenNew.sol"; | ||
|
||
contract OverlayV1OVLCollateral is ERC1155Supply { | ||
|
||
|
@@ -32,7 +31,7 @@ contract OverlayV1OVLCollateral is ERC1155Supply { | |
Position.Info[] public positions; | ||
|
||
IOverlayV1Mothership public immutable mothership; | ||
IOverlayTokenNew immutable public ovl; | ||
IOverlayToken immutable public ovl; | ||
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. I don't understand the removal of the new token. The auditors found a bug in it that would not have been good. But not one of them chimed in about the pattern itself being a no go. I don't find a risk in this pattern. It's a highly specialized permissioned function that is only invoked from non manipulable immutable smart contracts. This is essentially the nature of our entire system. Our entire system does these things and I find no anxiety in collapsing some of the functions in this highly controlled and narrow domain. |
||
|
||
uint256 public fees; | ||
uint256 public liquidations; | ||
|
@@ -178,7 +177,7 @@ contract OverlayV1OVLCollateral is ERC1155Supply { | |
_liqBurn | ||
); | ||
|
||
ovl.burn(address(this), _feeBurn + _liqBurn); | ||
ovl.burn(_feeBurn + _liqBurn); | ||
ovl.transfer(_feeTo, _feeForward + _liqForward); | ||
|
||
} | ||
|
@@ -236,7 +235,7 @@ contract OverlayV1OVLCollateral is ERC1155Supply { | |
|
||
/** | ||
@notice Build a position on Overlay with OVL collateral | ||
@dev This interacts with an Overlay Market to register oi and hold | ||
@dev This interacts with an Overlay Market to register oi and hold | ||
positions on behalf of users. | ||
@dev Build event emitted | ||
@param _market The address of the desired market to interact with | ||
|
@@ -289,9 +288,9 @@ contract OverlayV1OVLCollateral is ERC1155Supply { | |
|
||
emit Build(_market, _positionId, _oiAdjusted, _debtAdjusted); | ||
|
||
ovl.transferFromBurn(msg.sender, address(this), _collateralAdjusted + _fee, _impact); | ||
ovl.transferFrom(msg.sender, address(this), _collateralAdjusted + _impact + _fee); | ||
|
||
// ovl.burn(msg.sender, _impact); | ||
ovl.burn(_impact); | ||
|
||
_mint(msg.sender, _positionId, _oiAdjusted, ""); // WARNING: last b/c erc1155 callback | ||
|
||
|
@@ -326,7 +325,7 @@ contract OverlayV1OVLCollateral is ERC1155Supply { | |
pos.pricePoint | ||
); | ||
|
||
uint _totalPosShares = totalSupply(_positionId); | ||
uint _totalPosShares = pos.oiShares; | ||
|
||
uint _userOiShares = _shares; | ||
uint _userNotional = _shares * pos.notional(_oi, _oiShares, _priceFrame) / _totalPosShares; | ||
|
@@ -349,35 +348,26 @@ contract OverlayV1OVLCollateral is ERC1155Supply { | |
pos.cost -= _userCost; | ||
pos.oiShares -= _userOiShares; | ||
|
||
// ovl.transfer(msg.sender, _userCost); | ||
IOverlayV1Market(pos.market).exitOI( | ||
pos.isLong, | ||
_userOi, | ||
_userOiShares, | ||
_userCost < _userValueAdjusted ? _userValueAdjusted - _userCost : 0, | ||
_userCost < _userValueAdjusted ? 0 : _userCost - _userValueAdjusted | ||
); | ||
|
||
// mint/burn excess PnL = valueAdjusted - cost | ||
if (_userCost < _userValueAdjusted) { | ||
|
||
ovl.transferMint( | ||
msg.sender, | ||
_userCost, | ||
_userValueAdjusted - _userCost | ||
); | ||
ovl.mint(address(this), _userValueAdjusted - _userCost); | ||
|
||
} else { | ||
|
||
ovl.transferBurn( | ||
msg.sender, | ||
_userValueAdjusted, | ||
_userCost - _userValueAdjusted | ||
); | ||
ovl.burn(_userCost - _userValueAdjusted); | ||
|
||
} | ||
|
||
|
||
IOverlayV1Market(pos.market).exitOI( | ||
pos.isLong, | ||
_userOi, | ||
_userOiShares, | ||
_userCost < _userValueAdjusted ? _userValueAdjusted - _userCost : 0, | ||
_userCost < _userValueAdjusted ? 0 : _userCost - _userValueAdjusted | ||
); | ||
ovl.transfer(msg.sender, _userValueAdjusted); | ||
|
||
} | ||
|
||
|
@@ -446,8 +436,8 @@ contract OverlayV1OVLCollateral is ERC1155Supply { | |
_rewardsTo | ||
); | ||
|
||
// ovl.burn(address(this), pos.cost - _value); | ||
ovl.transferBurn(_rewardsTo, _toReward, pos.cost - _value); | ||
ovl.burn(pos.cost - _value); | ||
ovl.transfer(_rewardsTo, _toReward); | ||
|
||
} | ||
|
||
|
This file contains 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 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 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 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 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 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 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 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
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.
This appears to be contradictory to the advice from one of the reviewers that burn shall not be able to burn from any account.
We should consider if that is a desired system design where tokens are only burnt whence owned by a collateral manager at the time. Burn on transfer in. Burn on transfer out.
A well designed transferBurn function could also satisfy these requirements.