Skip to content

Commit

Permalink
Merge pull request #612 from mysofinance/myso-token-manager-sig
Browse files Browse the repository at this point in the history
updated default behavior to ignore caps when set to 0
  • Loading branch information
jpick713 authored Apr 22, 2024
2 parents fd1bffc + f16aa5d commit 3f5ad21
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 12 deletions.
8 changes: 4 additions & 4 deletions contracts/tokenManager/MysoTokenManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ contract MysoTokenManager is Ownable2Step, IMysoTokenManager {
address public mysoIOOVault;
address public mysoToken;
address public stMysoToken;
address public accessSigner;
address public signingAuthority;
mapping(address => RewardInfo) public rewardInfos;
mapping(bytes32 => bool) public alreadyClaimed;
event RewardInfoSet(
Expand Down Expand Up @@ -59,7 +59,7 @@ contract MysoTokenManager is Ownable2Step, IMysoTokenManager {
mysoToken = _mysoToken;
stMysoToken = _stMysoToken;
minMysoWeight = _minMysoWeight;
accessSigner = _signer;
signingAuthority = _signer;
_transferOwnership(msg.sender);
}

Expand Down Expand Up @@ -213,7 +213,7 @@ contract MysoTokenManager is Ownable2Step, IMysoTokenManager {

function setSigner(address _signer) external {
_checkOwner();
accessSigner = _signer;
signingAuthority = _signer;
emit SignerSet(_signer);
}

Expand Down Expand Up @@ -243,7 +243,7 @@ contract MysoTokenManager is Ownable2Step, IMysoTokenManager {
DataTypesPeerToPeer.Loan calldata loan
) internal virtual returns (bool) {
if (isMysoIoo) {
address _signer = accessSigner;
address _signer = signingAuthority;
if (_signer == address(0)) {
return true;
} else {
Expand Down
7 changes: 6 additions & 1 deletion contracts/tokenManager/MysoTokenManagerWithCaps.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,16 @@ contract MysoTokenManagerWithCaps is MysoTokenManager {
) internal override returns (bool isAllowed) {
isAllowed = super._isAllowed(isMysoIoo, borrowInstructions, loan);
if (!isAllowed) {
return isAllowed;
return false;
}
if (isMysoIoo) {
uint256 _newPledged = totalPledged[loan.collToken] +
loan.initCollAmount;
uint256 _collatCap = collatCaps[loan.collToken];
// @dev: default 0 value means no cap
if (_collatCap == 0) {
return true;
}
isAllowed = _newPledged <= collatCaps[loan.collToken];
if (isAllowed) {
totalPledged[loan.collToken] = _newPledged;
Expand Down
2 changes: 1 addition & 1 deletion scripts/peer-to-peer/dao/manageAddressRegistry.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"actions": [
{
"type": "setWhitelistState",
"addresses": ["0xC71dBB6b1a9735F3259F0CF746C1c000BF02615c"],
"addresses": ["0xc2dDc2330C06E2A7BfE2084a9A4f1A38f83A6B6f"],
"state": 9
}
]
Expand Down
17 changes: 13 additions & 4 deletions scripts/peer-to-peer/utils/deployTestnetTokenManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,19 @@ async function main() {
logger.log('Deployer ETH balance:', ethers.utils.formatEther(deployerBal.toString()))
logger.log(`Deploying to network '${hardhatNetworkName}' (default provider network name '${network.name}')`)
logger.log(`Configured chain id '${hardhatChainId}' (default provider config chain id '${network.chainId}')`)
const TestnetTokenManager = await ethers.getContractFactory('TestnetTokenManager')
const testnetTokenManager = await TestnetTokenManager.connect(deployer).deploy()
await testnetTokenManager.deployed()
logger.log('testnetTokenManager deployed at:', testnetTokenManager.address)
const MysoTokenManagerWithCaps = await ethers.getContractFactory('MysoTokenManagerWithCaps')
const mysoIOOVault = "0x060cceb8Cc54BaD7A01E02Ba11EeCE5304314726"
const mysoToken = "0x8fF1307ba7e5FDc3A411d259bAe641e2B1d897c4"
const stMysoToken = "0x0A6cBCB5Ac7Fc6B47f06c2cE3E828b6EEBf37B06"
const minMysoWeight = 0
const signer = deployer.address
const collatCaps : any = []
const mysoTokenManagerWithCaps = await MysoTokenManagerWithCaps.connect(deployer).deploy(mysoIOOVault, mysoToken, stMysoToken, minMysoWeight, signer, collatCaps)
await mysoTokenManagerWithCaps.deployed()
logger.log('testnetTokenManager deployed at:', mysoTokenManagerWithCaps.address)
logger.log(`'${mysoIOOVault}' '${mysoToken}' '${stMysoToken}' '${0}' '${signer}' '${collatCaps}'`)

// npx hardhat verify 0xc2dDc2330C06E2A7BfE2084a9A4f1A38f83A6B6f --constructor-args .\scripts\peer-to-peer\utils\tokenManagerArgs.js --network sepolia
}

main().catch(error => {
Expand Down
8 changes: 8 additions & 0 deletions scripts/peer-to-peer/utils/tokenManagerArgs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = [
"0x060cceb8Cc54BaD7A01E02Ba11EeCE5304314726",
"0x8fF1307ba7e5FDc3A411d259bAe641e2B1d897c4",
"0x0A6cBCB5Ac7Fc6B47f06c2cE3E828b6EEBf37B06",
0,
"0xcE3d0e78c15C30ecf631ef529581Af3de0478895",
[]
];
13 changes: 11 additions & 2 deletions test/peer-to-peer/local-tests-tokenmanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ describe('Peer-to-Peer: Local Tests', function () {

await expect(mysoTokenManager.connect(borrower1).setSigner(borrower1.address)).to.be.revertedWith("Ownable: caller is not the owner")
await mysoTokenManager.connect(deployer).setSigner(borrower1.address)
expect(await mysoTokenManager.accessSigner()).to.be.equal(borrower1.address)
expect(await mysoTokenManager.signingAuthority()).to.be.equal(borrower1.address)

await expect(mysoTokenManager.connect(borrower1).setMysoToken(usdc.address)).to.be.revertedWith("Ownable: caller is not the owner")
await mysoTokenManager.connect(deployer).setMysoToken(usdc.address)
Expand Down Expand Up @@ -466,7 +466,16 @@ describe('Peer-to-Peer: Local Tests', function () {
// next one fails again
await expect(borrowerGateway
.connect(borrower2)
.borrowWithOnChainQuote(iooVault.address, borrowInstructions, iooOnChainQuote, quoteTupleIdx)).to.be.revertedWithCustomError(mysoTokenManagerWithCaps, "NotAllowed")
.borrowWithOnChainQuote(iooVault.address, borrowInstructions, iooOnChainQuote, quoteTupleIdx)).to.be.revertedWithCustomError(mysoTokenManagerWithCaps, "NotAllowed")

// set cap to zero to disable
const newCollatCaps_ = [{token: usdc.address, maxPledge: 0}]
await mysoTokenManagerWithCaps.setCollatCaps(newCollatCaps_)

// now borrow works again
await borrowerGateway
.connect(borrower2)
.borrowWithOnChainQuote(iooVault.address, borrowInstructions, iooOnChainQuote, quoteTupleIdx)
})
})
})

0 comments on commit 3f5ad21

Please sign in to comment.