-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'myso-oracle' of github.com:mysofinance/v2 into myso-oracle
- Loading branch information
Showing
3 changed files
with
144 additions
and
88 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
pragma solidity 0.8.19; | ||
|
||
import {MysoTokenManager} from "./MysoTokenManager.sol"; | ||
import {DataTypesPeerToPeer} from "../peer-to-peer/DataTypesPeerToPeer.sol"; | ||
|
||
contract MysoTokenManagerWithCaps is MysoTokenManager { | ||
struct CollatCapInfo { | ||
address token; | ||
uint128 maxPledge; | ||
} | ||
|
||
mapping(address => uint256) public collatCaps; | ||
mapping(address => uint256) public totalPledged; | ||
|
||
event CollatCapsSet(CollatCapInfo[] collatCaps); | ||
|
||
constructor( | ||
address _mysoIOOVault, | ||
address _mysoToken, | ||
address _stMysoToken, | ||
uint256 _minMysoWeight, | ||
address _signer, | ||
CollatCapInfo[] memory _collatCaps | ||
) | ||
MysoTokenManager( | ||
_mysoIOOVault, | ||
_mysoToken, | ||
_stMysoToken, | ||
_minMysoWeight, | ||
_signer | ||
) | ||
{ | ||
for (uint256 i = 0; i < _collatCaps.length; i++) { | ||
collatCaps[_collatCaps[i].token] = _collatCaps[i].maxPledge; | ||
} | ||
} | ||
|
||
function setCollatCaps(CollatCapInfo[] calldata _collatCaps) external { | ||
_checkOwner(); | ||
for (uint256 i = 0; i < _collatCaps.length; i++) { | ||
collatCaps[_collatCaps[i].token] = _collatCaps[i].maxPledge; | ||
} | ||
emit CollatCapsSet(_collatCaps); | ||
} | ||
|
||
function _isAllowed( | ||
bool isMysoIoo, | ||
DataTypesPeerToPeer.BorrowTransferInstructions | ||
calldata borrowInstructions, | ||
DataTypesPeerToPeer.Loan calldata loan | ||
) internal override returns (bool isAllowed) { | ||
isAllowed = super._isAllowed(isMysoIoo, borrowInstructions, loan); | ||
if (!isAllowed) { | ||
return isAllowed; | ||
} | ||
if (isMysoIoo) { | ||
uint256 _newPledged = totalPledged[loan.collToken] + | ||
loan.initCollAmount; | ||
isAllowed = _newPledged <= collatCaps[loan.collToken]; | ||
if (isAllowed) { | ||
totalPledged[loan.collToken] = _newPledged; | ||
} | ||
} else { | ||
isAllowed = true; | ||
} | ||
} | ||
} |
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