Skip to content

Commit

Permalink
verifyWhitelistStatus + style guideline
Browse files Browse the repository at this point in the history
  • Loading branch information
Brean0 committed Apr 8, 2024
1 parent 810b09a commit f0d0cea
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 34 deletions.
2 changes: 1 addition & 1 deletion protocol/contracts/libraries/Silo/LibSilo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ library LibSilo {
}

// "removing" deposits is equivalent to "burning" a batch of ERC1155 tokens.
if(emission == ERC1155Event.EMIT_BATCH_EVENT) {
if (emission == ERC1155Event.EMIT_BATCH_EVENT) {
emit TransferBatch(msg.sender, account, address(0), removedDepositIDs, amounts);
}

Expand Down
78 changes: 46 additions & 32 deletions protocol/contracts/libraries/Silo/LibWhitelist.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,38 +99,9 @@ library LibWhitelist {
verifyGaugePointSelector(gaugePointSelector);
verifyLiquidityWeightSelector(liquidityWeightSelector);

// fetch the whitelist status of the token. Brackets due to stack too deep.
{
(bool isWhitelisted, bool previouslyWhitelisted) = LibWhitelistedTokens.checkWhitelisted(token);
require(isWhitelisted == false, "Whitelist: Token already whitelisted");

// add whitelist status. If previously whitelisted, update the status rather than appending.
if(previouslyWhitelisted) {
LibWhitelistedTokens.updateWhitelistStatus(
token,
true, // Whitelisted by default.
token != address(C.bean()) && !LibUnripe.isUnripe(token), // Assumes tokens that are not Unripe and not Bean are LP tokens.
selector == LibWell.WELL_BDV_SELECTOR
);
} else {
// assumes new tokens are well pool tokens.
LibWhitelistedTokens.addWhitelistStatus(
token,
true, // Whitelisted by default.
token != address(C.bean()) && !LibUnripe.isUnripe(token), // Assumes tokens that are not Unripe and not Bean are LP tokens.
selector == LibWell.WELL_BDV_SELECTOR
);
}

// if the token has previously been whitelisted, the stalkIssuedPerBdv
// cannot be updated, as previous deposits would have been made with the
// previous value.
if(previouslyWhitelisted) {
stalkIssuedPerBdv = s.ss[token].stalkIssuedPerBdv;
}
}


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

// If an LP token, initialize oracle storage variables.
if (token != address(C.bean()) && !LibUnripe.isUnripe(token)) {
Expand Down Expand Up @@ -271,5 +242,48 @@ library LibWhitelist {
(bool success, ) = address(this).staticcall(abi.encodeWithSelector(selector));
require(success, "Whitelist: Invalid LiquidityWeight selector");
}

/**
* @notice verifies whether a token is not whitelisted.
* @dev if the token has been previously whitelisted,
* return the current stalk issued per bdv.
*/
function verifyWhitelistStatus(
address token,
bytes4 selector,
uint32 stalkIssuedPerBdv
) internal returns (uint32) {
AppStorage storage s = LibAppStorage.diamondStorage();

(bool isWhitelisted, bool previouslyWhitelisted) = LibWhitelistedTokens.checkWhitelisted(token);
require(isWhitelisted == false, "Whitelist: Token already whitelisted");

// add whitelist status. If previously whitelisted, update the status rather than appending.
if (previouslyWhitelisted) {
LibWhitelistedTokens.updateWhitelistStatus(
token,
true, // Whitelisted by default.
token != address(C.bean()) && !LibUnripe.isUnripe(token), // Assumes tokens that are not Unripe and not Bean are LP tokens.
selector == LibWell.WELL_BDV_SELECTOR
);
} else {
// assumes new tokens are well pool tokens.
LibWhitelistedTokens.addWhitelistStatus(
token,
true, // Whitelisted by default.
token != address(C.bean()) && !LibUnripe.isUnripe(token), // Assumes tokens that are not Unripe and not Bean are LP tokens.
selector == LibWell.WELL_BDV_SELECTOR
);
}

// if the token has previously been whitelisted, the stalkIssuedPerBdv
// cannot be updated, as previous deposits would have been made with the
// previous value.
if (previouslyWhitelisted) {
return s.ss[token].stalkIssuedPerBdv;
} else {
return stalkIssuedPerBdv;
}
}

}
2 changes: 1 addition & 1 deletion protocol/contracts/libraries/Silo/LibWhitelistedTokens.sol
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ library LibWhitelistedTokens {
}
}

if(s.whitelistStatuses[i].isWhitelisted) {
if (s.whitelistStatuses[i].isWhitelisted) {
// token is whitelisted.
return (true, false);
} else {
Expand Down

0 comments on commit f0d0cea

Please sign in to comment.