Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Review #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Fix Review #2

wants to merge 1 commit into from

Conversation

sherlock-admin4
Copy link

Fix Review of

Repo: RedDuck-Software/midas-contracts
Commit Hash: 21ab5ffa59ed9265c771bc9df37f6794b9b4f73a

@@ -325,14 +325,18 @@ contract RedemptionVault is ManageableVault, IRedemptionVault {

mToken.burn(address(this), request.amountMToken);

if (request.tokenOut != MANUAL_FULLFILMENT_TOKEN) {
uint256 tokenDecimals = _tokenDecimals(request.tokenOut);
bool isFiat = request.tokenOut == MANUAL_FULLFILMENT_TOKEN;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#69.

Fixes issues: #102

(request.amountMToken * newMTokenRate) / request.tokenOutRate,
tokenDecimals
);
uint256 tokenDecimals = isFiat ? 18 : _tokenDecimals(request.tokenOut);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#69.

Fixes issues: #102

Comment on lines +332 to +339
uint256 amountTokenOutWithoutFee = _truncate(
(request.amountMToken * newMTokenRate) / request.tokenOutRate,
tokenDecimals
);

_requireAndUpdateAllowance(request.tokenOut, amountTokenOutWithoutFee);

if (!isFiat) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#69.

Fixes issues: #102

Comment on lines +397 to +400
// assigning the default value which is gonna be used
// only for fiat redemptions
uint256 tokenOutRate = 1e18;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#69.

Fixes issues: #102

Comment on lines +21 to +24
/**
* @notice minimum amount of BUIDL to redeem. Will redeem at least this amount of BUIDL.
*/
uint256 public minBuidlToRedeem;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#68.

Fixes issues: #100

Comment on lines +32 to +37
/**
* @param minBuidlToRedeem new min amount of BUIDL to redeem
* @param sender address who set new min amount of BUIDL to redeem
*/
event SetMinBuidlToRedeem(uint256 minBuidlToRedeem, address sender);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#68.

Fixes issues: #100

@@ -53,7 +64,9 @@ contract RedemptionVaultWIthBUIDL is RedemptionVault {
uint256 _minAmount,
FiatRedeptionInitParams calldata _fiatRedemptionInitParams,
address _requestRedeemer,
address _buidlRedemption
address _buidlRedemption,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#68.

Fixes issues: #100

buidlSettlement = ISettlement(buidlRedemption.settlement());
buidlLiquiditySource = ILiquiditySource(buidlRedemption.liquidity());
buidl = IERC20(buidlRedemption.asset());
minBuidlToRedeem = _minBuidlToRedeem;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#68.

Fixes issues: #100

Comment on lines +86 to +98
}

/**
* @notice set min amount of BUIDL to redeem.
* @param _minBuidlToRedeem min amount of BUIDL to redeem
*/
function setMinBuidlToRedeem(uint256 _minBuidlToRedeem)
external
onlyVaultAdmin
{
minBuidlToRedeem = _minBuidlToRedeem;

emit SetMinBuidlToRedeem(_minBuidlToRedeem, msg.sender);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#68.

Fixes issues: #100

@@ -97,7 +135,7 @@ contract RedemptionVaultWIthBUIDL is RedemptionVault {
{
address user = msg.sender;

tokenOut = buidlLiquiditySource.token();
require(buidlRedemption.liquidity() == tokenOut, "RVB: invalid token");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#71.

Fixes issues: #41

Comment on lines 210 to +213
uint256 buidlToRedeem = amountTokenOut - contractBalanceTokenOut;

if (buidlToRedeem < minBuidlToRedeem) {
buidlToRedeem = minBuidlToRedeem;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#68.

Fixes issues: #100

Comment on lines +214 to +216
IERC20 buidl = IERC20(buidlRedemption.asset());
uint256 buidlBalance = buidl.balanceOf(address(this));
require(buidlBalance >= buidlToRedeem, "RVB: buidlToRedeem > balance");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#68.

Fixes issues: #100

Comment on lines +221 to +222
buidlToRedeem = buidlBalance;
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#68.

Fixes issues: #100

Comment on lines 223 to 224
buidl.safeIncreaseAllowance(address(buidlRedemption), buidlToRedeem);
buidlRedemption.redeem(buidlToRedeem);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#68.

Fixes issues: #100

Comment on lines +240 to +243
if (token != MANUAL_FULLFILMENT_TOKEN) {
_requireTokenExists(token);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#69.

Fixes issues: #102

Comment on lines +315 to +326
/**
* @inheritdoc IManageableVault
* @dev reverts address zero or equal address(this)
*/
function setTokensReceiver(address receiver) external onlyVaultAdmin {
_validateAddress(receiver, true);

tokensReceiver = receiver;

emit SetTokensReceiver(msg.sender, receiver);
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#66.

Fixes issues: #111

@@ -17,6 +17,11 @@ abstract contract WithSanctionsList is WithMidasAccessControl {
*/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#64.

Fixes issues: #103

@@ -17,6 +17,11 @@ abstract contract WithSanctionsList is WithMidasAccessControl {
*/
address public sanctionsList;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#64.

Fixes issues: #103

Comment on lines +13 to +17
/**
* @dev leaving a storage gap for futures updates
*/
uint256[50] private __gap;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#64.

Fixes issues: #103

Comment on lines +24 to +28
/**
* @dev leaving a storage gap for futures updates
*/
uint256[50] private __gap;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#64.

Fixes issues: #103

Comment on lines +16 to +20
/**
* @dev leaving a storage gap for futures updates
*/
uint256[50] private __gap;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#64.

Fixes issues: #103

Comment on lines +144 to +149
/**
* @param caller function caller (msg.sender)
* @param reciever new reciever address
*/
event SetTokensReceiver(address indexed caller, address indexed reciever);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#66.

Fixes issues: #111

Comment on lines +256 to +262
/**
* @notice set new reciever for tokens.
* can be called only from permissioned actor.
* @param reciever new token reciever address
*/
function setTokensReceiver(address reciever) external;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#66.

Fixes issues: #111

Comment on lines +138 to +140
_requireAndUpdateLimit(amountMTokenInCopy);
_requireAndUpdateAllowance(tokenOutCopy, amountTokenOut);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#65.

Fixes issues: #110

address _liquidity,
address _settlement
) {
constructor(address _asset, address _liquidity) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#68.

Fixes issues: #100

Comment on lines +19 to +20
function settlement() external view returns (address) {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#68.

Fixes issues: #100

Comment on lines +22 to +23
IERC20(asset).transferFrom(msg.sender, address(this), amount);
IERC20(liquidity).transfer(msg.sender, amount);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#68.

Fixes issues: #100

@@ -25,6 +25,8 @@ import {
setVariabilityToleranceTest,
withdrawTest,
changeTokenFeeTest,
setTokensReceiverTest,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#66.

Fixes issues: #111

Comment on lines +1452 to +1503
describe('setTokensReceiver()', () => {
it('should fail: call from address without REDEMPTION_VAULT_ADMIN_ROLE role', async () => {
const { owner, redemptionVault, regularAccounts } = await loadFixture(
defaultDeploy,
);

await setTokensReceiverTest(
{ vault: redemptionVault, owner },
regularAccounts[0].address,
{
from: regularAccounts[0],
revertMessage: acErrors.WMAC_HASNT_ROLE,
},
);
});

it('should fail: call with zero address receiver', async () => {
const { owner, redemptionVault } = await loadFixture(defaultDeploy);

await setTokensReceiverTest(
{ vault: redemptionVault, owner },
constants.AddressZero,
{
revertMessage: 'zero address',
},
);
});

it('should fail: call with address(this) receiver', async () => {
const { owner, redemptionVault } = await loadFixture(defaultDeploy);

await setTokensReceiverTest(
{ vault: redemptionVault, owner },
redemptionVault.address,
{
revertMessage: 'invalid address',
},
);
});

it('call from address without REDEMPTION_VAULT_ADMIN_ROLE role', async () => {
const { owner, redemptionVault, regularAccounts } = await loadFixture(
defaultDeploy,
);

await setTokensReceiverTest(
{ vault: redemptionVault, owner },
regularAccounts[0].address,
);
});
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#66.

Fixes issues: #111

Comment on lines +4113 to +4118
await changeTokenAllowanceTest(
{ vault: redemptionVault, owner },
constants.AddressZero,
parseUnits('100'),
);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#69.

Fixes issues: #102

@@ -25,6 +25,7 @@ import {
setVariabilityToleranceTest,
withdrawTest,
changeTokenFeeTest,
setMinBuidlToRedeem,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#68.

Fixes issues: #100

Comment on lines +102 to +104
expect(await redemptionVaultWithBUIDL.minBuidlToRedeem()).eq(
parseUnits('250000', 6),
);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#68.

Fixes issues: #100

Comment on lines +376 to +401
describe('setMinBuidlToRedeem()', () => {
it('should fail: call from address without REDEMPTION_VAULT_ADMIN_ROLE role', async () => {
const { owner, redemptionVaultWithBUIDL, regularAccounts } =
await loadFixture(defaultDeploy);

await setMinBuidlToRedeem(
{ vault: redemptionVaultWithBUIDL, owner },
parseUnits('100000', 6),
{
from: regularAccounts[0],
revertMessage: acErrors.WMAC_HASNT_ROLE,
},
);
});

it('call from address with REDEMPTION_VAULT_ADMIN_ROLE role', async () => {
const { owner, redemptionVaultWithBUIDL } = await loadFixture(
defaultDeploy,
);
await setMinBuidlToRedeem(
{ vault: redemptionVaultWithBUIDL, owner },
parseUnits('100000', 6),
);
});
});

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#68.

Fixes issues: #100

@@ -1169,7 +1197,7 @@ describe('RedemptionVaultWithBUIDL', function () {
mTBILL,
mTokenToUsdDataFeed,
},
stableCoins.dai,
stableCoins.usdc,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#71.

Fixes issues: #41

@@ -1200,7 +1228,7 @@ describe('RedemptionVaultWithBUIDL', function () {
mTBILL,
mTokenToUsdDataFeed,
},
stableCoins.dai,
stableCoins.usdc,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#71.

Fixes issues: #41

@@ -1277,7 +1305,7 @@ describe('RedemptionVaultWithBUIDL', function () {
mTBILL,
mTokenToUsdDataFeed,
},
stableCoins.dai,
stableCoins.usdc,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#71.

Fixes issues: #41

@@ -1352,7 +1380,7 @@ describe('RedemptionVaultWithBUIDL', function () {
mTBILL,
mTokenToUsdDataFeed,
},
stableCoins.dai,
stableCoins.usdc,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#71.

Fixes issues: #41

@@ -1367,14 +1395,53 @@ describe('RedemptionVaultWithBUIDL', function () {
mTBILL,
mTokenToUsdDataFeed,
},
stableCoins.dai,
stableCoins.usdc,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#71.

Fixes issues: #41

@@ -1387,7 +1454,7 @@ describe('RedemptionVaultWithBUIDL', function () {
} = await loadFixture(defaultDeploy);
await addPaymentTokenTest(
{ vault: redemptionVaultWithBUIDL, owner },
stableCoins.dai,
stableCoins.usdc,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#71.

Fixes issues: #41

@@ -1409,14 +1476,46 @@ describe('RedemptionVaultWithBUIDL', function () {
mTBILL,
mTokenToUsdDataFeed,
},
stableCoins.dai,
stableCoins.usdc,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#71.

Fixes issues: #41

Comment on lines +1487 to +1518
it('should fail: call when token is invalid', async () => {
const {
redemptionVaultWithBUIDL,
mockedAggregator,
owner,
mTBILL,
stableCoins,
dataFeed,
mTokenToUsdDataFeed,
} = await loadFixture(defaultDeploy);
await addPaymentTokenTest(
{ vault: redemptionVaultWithBUIDL, owner },
stableCoins.usdc,
dataFeed.address,
0,
true,
);
await redeemInstantTest(
{
redemptionVault: redemptionVaultWithBUIDL,
owner,
mTBILL,
mTokenToUsdDataFeed,
},
stableCoins.dai,
99_999,
{
revertMessage: 'RVB: invalid token',
},
);
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#71.

Fixes issues: #41

@@ -1685,10 +1784,10 @@ describe('RedemptionVaultWithBUIDL', function () {
mTBILL,
mTokenToUsdDataFeed,
},
constants.AddressZero,
stableCoins.usdc,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#71.

Fixes issues: #41

100000,
{
revertMessage: 'ERC20: transfer amount exceeds balance',
revertMessage: 'RVB: buidlToRedeem > balance',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#68.

Fixes issues: #100

@@ -1772,7 +1871,7 @@ describe('RedemptionVaultWithBUIDL', function () {
redemptionVaultWithBUIDL.address,
);
expect(buidlBalanceAfter).eq(
buidlBalanceBefore.sub(parseUnits('1000', 8)),
buidlBalanceBefore.sub(parseUnits('250000', 6)),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#68.

Fixes issues: #100

Comment on lines +3239 to +3243
await changeTokenAllowanceTest(
{ vault: redemptionVault, owner },
constants.AddressZero,
parseUnits('100'),
);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#69.

Fixes issues: #102

const buidlRedemption = await new RedemptionTest__factory(owner).deploy(
buidl.address,
liquiditySource.address,
settlement.address,
stableCoins.usdc.address,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#68.

Fixes issues: #100

);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#68.

Fixes issues: #100

@@ -775,6 +765,8 @@ export const defaultDeploy = async () => {
},
requestRedeemer.address,
buidlRedemption.address,
parseUnits('250000', 6),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#68.

Fixes issues: #100

@@ -1,6 +1,6 @@
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { expect } from 'chai';
import { BigNumberish } from 'ethers';
import { BigNumber, BigNumberish } from 'ethers';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#68.

Fixes issues: #100

Comment on lines +227 to +249
export const setTokensReceiverTest = async (
{ vault, owner }: CommonParamsChangePaymentToken,
newReceiver: string,
opt?: OptionalCommonParams,
) => {
if (opt?.revertMessage) {
await expect(
vault.connect(opt?.from ?? owner).setTokensReceiver(newReceiver),
).revertedWith(opt?.revertMessage);
return;
}

await expect(vault.connect(opt?.from ?? owner).setTokensReceiver(newReceiver))
.to.emit(
vault,
vault.interface.events['SetTokensReceiver(address,address)'].name,
)
.withArgs((opt?.from ?? owner).address, newReceiver).to.not.reverted;

const feeReceiver = await vault.tokensReceiver();
expect(feeReceiver).eq(newReceiver);
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#66.

Fixes issues: #111

@@ -276,7 +276,7 @@ export const redeemFiatRequestTest = async (
expect(request.tokenOut).eq(manualToken);
expect(request.amountMToken).eq(amountInWithoutFee);
expect(request.mTokenRate).eq(mTokenRate);
expect(request.tokenOutRate).eq(0);
expect(request.tokenOutRate).eq(parseUnits('1'));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#69.

Fixes issues: #102

@@ -462,6 +462,8 @@ export const safeApproveRedeemRequestTest = async (

const tokenDecimals = await tokenContract.decimals();

console.log(requestDataBefore.amountMToken, requestDataBefore.tokenOutRate);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to RedDuck-Software/midas-contracts#69.

Fixes issues: #102

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants