From 298bfa90f5f5413382a26089a5669c7c06cee6e9 Mon Sep 17 00:00:00 2001 From: asardon Date: Wed, 17 Apr 2024 12:39:06 +0400 Subject: [PATCH 1/2] updated default behavior to ignore caps when set to 0 --- contracts/tokenManager/MysoTokenManager.sol | 8 ++++---- contracts/tokenManager/MysoTokenManagerWithCaps.sol | 7 ++++++- test/peer-to-peer/local-tests-tokenmanager.ts | 13 +++++++++++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/contracts/tokenManager/MysoTokenManager.sol b/contracts/tokenManager/MysoTokenManager.sol index ee4e7a81..5e1a5099 100644 --- a/contracts/tokenManager/MysoTokenManager.sol +++ b/contracts/tokenManager/MysoTokenManager.sol @@ -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( @@ -59,7 +59,7 @@ contract MysoTokenManager is Ownable2Step, IMysoTokenManager { mysoToken = _mysoToken; stMysoToken = _stMysoToken; minMysoWeight = _minMysoWeight; - accessSigner = _signer; + signingAuthority = _signer; _transferOwnership(msg.sender); } @@ -213,7 +213,7 @@ contract MysoTokenManager is Ownable2Step, IMysoTokenManager { function setSigner(address _signer) external { _checkOwner(); - accessSigner = _signer; + signingAuthority = _signer; emit SignerSet(_signer); } @@ -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 { diff --git a/contracts/tokenManager/MysoTokenManagerWithCaps.sol b/contracts/tokenManager/MysoTokenManagerWithCaps.sol index ae2e15de..4591ce25 100644 --- a/contracts/tokenManager/MysoTokenManagerWithCaps.sol +++ b/contracts/tokenManager/MysoTokenManagerWithCaps.sol @@ -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; diff --git a/test/peer-to-peer/local-tests-tokenmanager.ts b/test/peer-to-peer/local-tests-tokenmanager.ts index a7fb47c0..793132bf 100644 --- a/test/peer-to-peer/local-tests-tokenmanager.ts +++ b/test/peer-to-peer/local-tests-tokenmanager.ts @@ -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) @@ -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) }) }) }) From f16aa5db864b268081b895b32b476898e9533d62 Mon Sep 17 00:00:00 2001 From: asardon Date: Wed, 17 Apr 2024 13:21:38 +0400 Subject: [PATCH 2/2] updated deployment script --- .../peer-to-peer/dao/manageAddressRegistry.json | 2 +- .../utils/deployTestnetTokenManager.ts | 17 +++++++++++++---- scripts/peer-to-peer/utils/tokenManagerArgs.js | 8 ++++++++ 3 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 scripts/peer-to-peer/utils/tokenManagerArgs.js diff --git a/scripts/peer-to-peer/dao/manageAddressRegistry.json b/scripts/peer-to-peer/dao/manageAddressRegistry.json index 8ce00f9c..3875a052 100644 --- a/scripts/peer-to-peer/dao/manageAddressRegistry.json +++ b/scripts/peer-to-peer/dao/manageAddressRegistry.json @@ -24,7 +24,7 @@ "actions": [ { "type": "setWhitelistState", - "addresses": ["0xC71dBB6b1a9735F3259F0CF746C1c000BF02615c"], + "addresses": ["0xc2dDc2330C06E2A7BfE2084a9A4f1A38f83A6B6f"], "state": 9 } ] diff --git a/scripts/peer-to-peer/utils/deployTestnetTokenManager.ts b/scripts/peer-to-peer/utils/deployTestnetTokenManager.ts index ecc738b7..ab869582 100644 --- a/scripts/peer-to-peer/utils/deployTestnetTokenManager.ts +++ b/scripts/peer-to-peer/utils/deployTestnetTokenManager.ts @@ -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 => { diff --git a/scripts/peer-to-peer/utils/tokenManagerArgs.js b/scripts/peer-to-peer/utils/tokenManagerArgs.js new file mode 100644 index 00000000..24f5970b --- /dev/null +++ b/scripts/peer-to-peer/utils/tokenManagerArgs.js @@ -0,0 +1,8 @@ +module.exports = [ + "0x060cceb8Cc54BaD7A01E02Ba11EeCE5304314726", + "0x8fF1307ba7e5FDc3A411d259bAe641e2B1d897c4", + "0x0A6cBCB5Ac7Fc6B47f06c2cE3E828b6EEBf37B06", + 0, + "0xcE3d0e78c15C30ecf631ef529581Af3de0478895", + [] + ]; \ No newline at end of file