Skip to content

Commit

Permalink
add revert upon invalid stalkIssuedPerBdv
Browse files Browse the repository at this point in the history
  • Loading branch information
Brean0 committed Apr 10, 2024
1 parent 380ca41 commit f5bda85
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
10 changes: 4 additions & 6 deletions protocol/contracts/libraries/Silo/LibWhitelist.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ library LibWhitelist {
verifyLiquidityWeightSelector(liquidityWeightSelector);

// verify whitelist status of token.
// Updates stalkIssuedPerBdv in the case of an previously whitelisted token.
stalkIssuedPerBdv = verifyWhitelistStatus(token, selector, stalkIssuedPerBdv);
// reverts on an invalid stalkIssuedPerBdv if previously whitelisted.
verifyWhitelistStatus(token, selector, stalkIssuedPerBdv);

// If an LP token, initialize oracle storage variables.
if (token != address(C.bean()) && !LibUnripe.isUnripe(token)) {
Expand Down Expand Up @@ -252,7 +252,7 @@ library LibWhitelist {
address token,
bytes4 selector,
uint32 stalkIssuedPerBdv
) internal returns (uint32) {
) internal {
AppStorage storage s = LibAppStorage.diamondStorage();

(bool isWhitelisted, bool previouslyWhitelisted) = LibWhitelistedTokens.checkWhitelisted(token);
Expand Down Expand Up @@ -280,9 +280,7 @@ library LibWhitelist {
// cannot be updated, as previous deposits would have been made with the
// previous value.
if (previouslyWhitelisted) {
return s.ss[token].stalkIssuedPerBdv;
} else {
return stalkIssuedPerBdv;
require(s.ss[token].stalkIssuedPerBdv == stalkIssuedPerBdv, "Whitelist: Cannot update stalkIssuedPerBdv");
}
}

Expand Down
21 changes: 18 additions & 3 deletions protocol/test/Whitelist.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ describe('Whitelist', function () {
})

describe('rewhitelist', async function () {
it('rewhitelists a dewhitelisted token', async function () {
beforeEach(async function () {
this.whitelist.connect(owner).whitelistTokenWithEncodeType(
this.well.address,
this.bdv.interface.getSighash('wellBdv'),
Expand All @@ -274,11 +274,13 @@ describe('Whitelist', function () {
'0',
'0'
)

await this.whitelist.connect(owner).dewhitelistToken(this.well.address)

let settings = await this.siloGetters.tokenSettings(this.well.address);
expect(settings[0]).to.equal('0x00000000')
});

it('rewhitelists a dewhitelisted token', async function () {
this.result = this.whitelist.connect(owner).whitelistTokenWithEncodeType(
this.well.address,
this.bdv.interface.getSighash('wellBdv'),
Expand All @@ -289,7 +291,7 @@ describe('Whitelist', function () {
this.liquidityWeight.interface.getSighash("maxWeight()"),
'0',
'0')
settings = await this.siloGetters.tokenSettings(this.well.address)
let settings = await this.siloGetters.tokenSettings(this.well.address)

expect(settings[0]).to.equal(this.bdv.interface.getSighash('wellBdv'))
expect(settings[1]).to.equal(1)
Expand All @@ -305,7 +307,20 @@ describe('Whitelist', function () {
'0',
'0'
);
})

it('reverts on an invalid stalkIssuedPerBdv upon rewhitelisting', async function () {
await expect(this.whitelist.connect(owner).whitelistTokenWithEncodeType(
this.well.address,
this.bdv.interface.getSighash('wellBdv'),
'1',
'1',
1,
this.gaugePoint.interface.getSighash("defaultGaugePointFunction(uint256,uint256,uint256)"),
this.liquidityWeight.interface.getSighash("maxWeight()"),
'0',
'0'
)).to.be.revertedWith('Whitelist: Cannot update stalkIssuedPerBdv')
})
})
});

0 comments on commit f5bda85

Please sign in to comment.