Skip to content

Commit

Permalink
Merge pull request #608 from mysofinance/myt-token-manager
Browse files Browse the repository at this point in the history
Myt token manager
  • Loading branch information
jpick713 authored Apr 11, 2024
2 parents 2fe6a9c + 251f69f commit be25020
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 29 deletions.
11 changes: 7 additions & 4 deletions contracts/tokenManager/MysoTokenManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ contract MysoTokenManager is Ownable2Step, IMysoTokenManager {
applicableProtocolFeeParams = currProtocolFeeParams;
address _mysoToken = mysoToken;
if (_mysoToken != address(0)) {
if (loan.loanToken == _mysoToken && lenderVault == mysoIOOVault) {
totalMysoLoanAmount += loan.initLoanAmount;
}
if (!_isAllowed(loan)) {
bool isMysoIoo = loan.loanToken == _mysoToken &&
lenderVault == mysoIOOVault;
if (!_isAllowed(isMysoIoo, loan)) {
revert NotAllowed();
}
if (isMysoIoo) {
totalMysoLoanAmount += loan.initLoanAmount;
}
address _stMysoToken = stMysoToken;
if (
_stMysoToken != address(0) &&
Expand Down Expand Up @@ -210,6 +212,7 @@ contract MysoTokenManager is Ownable2Step, IMysoTokenManager {
}

function _isAllowed(
bool /*isMysoIoo*/,
DataTypesPeerToPeer.Loan calldata /*loan*/
) internal virtual returns (bool) {
return true;
Expand Down
50 changes: 31 additions & 19 deletions contracts/tokenManager/MysoTokenManagerArbitrum.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@ contract MysoTokenManagerArbitrum is MysoTokenManager {
0xd3443ee1e91aF28e5FB858Fbd0D72A63bA8046E0;
address internal constant GETH = 0x5977A9682D7AF81D347CFc338c61692163a2784C;
mapping(address => uint256) public gVolume;
uint256 public gVolumeCap;
mapping(address => uint256) public gVolumeCaps;

event GVolumeSet(address gToken, uint256 gVolume);
event GVolumeCapSet(uint256 gVolumeCap);
event GVolumeCapSet(address gToken, uint256 gVolumeCap);

error NoGToken();

constructor(
address _mysoIOOVault,
address _mysoToken,
address _stMysoToken,
uint256 _minMysoWeight,
uint256 _gVolumeCap
uint256 _gDaiCap,
uint256 _gUsdcCap,
uint256 _gEthCap
)
MysoTokenManager(
_mysoIOOVault,
Expand All @@ -30,7 +34,9 @@ contract MysoTokenManagerArbitrum is MysoTokenManager {
_minMysoWeight
)
{
gVolumeCap = _gVolumeCap;
gVolumeCaps[GDAI] = _gDaiCap;
gVolumeCaps[GUSDC] = _gUsdcCap;
gVolumeCaps[GETH] = _gEthCap;
}

function setGVolume(address _gToken, uint256 _gVolume) external {
Expand All @@ -39,27 +45,33 @@ contract MysoTokenManagerArbitrum is MysoTokenManager {
emit GVolumeSet(_gToken, _gVolume);
}

function setGVolumeCap(uint256 _gVolumeCap) external {
function setGVolumeCap(address gToken, uint256 _gVolumeCap) external {
_checkOwner();
gVolumeCap = _gVolumeCap;
emit GVolumeCapSet(_gVolumeCap);
if (gToken != GDAI && gToken != GDAI && gToken != GDAI) {
revert NoGToken();
}
gVolumeCaps[gToken] = _gVolumeCap;
emit GVolumeCapSet(gToken, _gVolumeCap);
}

function _isAllowed(
bool isMysoIoo,
DataTypesPeerToPeer.Loan calldata loan
) internal override returns (bool isAllowed) {
if (
loan.collToken == GDAI ||
loan.collToken == GUSDC ||
loan.collToken == GETH
) {
uint256 _gVolume = gVolume[loan.collToken];
_gVolume +=
(loan.collToken == GETH ? 3500 : 1) *
loan.initCollAmount;
isAllowed = _gVolume <= gVolumeCap;
if (isAllowed) {
gVolume[loan.collToken] = _gVolume;
if (isMysoIoo) {
if (
loan.collToken == GDAI ||
loan.collToken == GUSDC ||
loan.collToken == GETH
) {
uint256 _newGVolume = gVolume[loan.collToken] +
loan.initCollAmount;
isAllowed = _newGVolume <= gVolumeCaps[loan.collToken];
if (isAllowed) {
gVolume[loan.collToken] = _newGVolume;
}
} else {
isAllowed = true;
}
} else {
isAllowed = true;
Expand Down
17 changes: 11 additions & 6 deletions contracts/tokenManager/MysoTokenManagerMainnet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,20 @@ contract MysoTokenManagerMainnet is MysoTokenManager {
}

function _isAllowed(
bool isMysoIoo,
DataTypesPeerToPeer.Loan calldata loan
) internal virtual override returns (bool) {
address _degenscoreBeaconReader = degenscoreBeaconReader;
if (_degenscoreBeaconReader == address(0)) {
if (isMysoIoo) {
address _degenscoreBeaconReader = degenscoreBeaconReader;
if (_degenscoreBeaconReader == address(0)) {
return true;
}
BeaconData memory beaconData = IDegenScoreBeaconReader(
_degenscoreBeaconReader
).beaconDataOf(loan.borrower);
return beaconData.updatedAt != 0;
} else {
return true;
}
BeaconData memory beaconData = IDegenScoreBeaconReader(
_degenscoreBeaconReader
).beaconDataOf(loan.borrower);
return beaconData.updatedAt != 0;
}
}

0 comments on commit be25020

Please sign in to comment.