Skip to content

Commit

Permalink
fix: native restake limit + non whitelist check
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxMustermann2 committed Sep 7, 2024
1 parent 4f3f463 commit 5f898e9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
14 changes: 10 additions & 4 deletions src/core/ClientChainGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,16 @@ contract ClientChainGateway is
onlyCalledFromThis
whenNotPaused
{
(address token, uint256 newSupply) = _decodeTokenUint256(requestPayload, false);
IVault vault = _getVault(token);
uint256 tvlLimit = vault.getTvlLimit();
bool success = tvlLimit <= newSupply && tvlLimitIncreasesInFlight[token] == 0;
(address token, uint256 newSupply) = _decodeTokenUint256(requestPayload, true);
bool success = false;
if (token == VIRTUAL_STAKED_ETH_ADDRESS) {
// native restaking has no tvl limit hence no need to limit the supply changes.
success = true;
} else {
IVault vault = _getVault(token);
uint256 tvlLimit = vault.getTvlLimit();
success = tvlLimit <= newSupply && tvlLimitIncreasesInFlight[token] == 0;
}
_sendMsgToExocore(Action.RESPOND, abi.encodePacked(lzNonce, success));
}

Expand Down
15 changes: 10 additions & 5 deletions src/core/ClientGatewayLzReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ abstract contract ClientGatewayLzReceiver is PausableUpgradeable, OAppReceiverUp
onlyCalledFromThis
whenNotPaused
{
(address token, uint256 tvlLimit) = _decodeTokenUint256(requestPayload, true);
(address token, uint256 tvlLimit) = _decodeTokenUint256(requestPayload, false);
isWhitelistedToken[token] = true;
whitelistTokens.push(token);
// since tokens cannot be removed from the whitelist, it is not possible for a vault
Expand All @@ -335,7 +335,7 @@ abstract contract ClientGatewayLzReceiver is PausableUpgradeable, OAppReceiverUp
emit BootstrappedAlready();
}

function _decodeTokenUint256(bytes calldata payload, bool failIfWhitelisted)
function _decodeTokenUint256(bytes calldata payload, bool shouldBeWhitelisted)
internal
view
returns (address, uint256)
Expand All @@ -346,9 +346,14 @@ abstract contract ClientGatewayLzReceiver is PausableUpgradeable, OAppReceiverUp
// cannot happen since ExocoreGateway checks for this
revert Errors.ZeroAddress();
}
if ((failIfWhitelisted) && (isWhitelistedToken[token])) {
// grave error, should never happen
revert Errors.ClientChainGatewayAlreadyWhitelisted(token);
if (isWhitelistedToken[token] != shouldBeWhitelisted) {
if (shouldBeWhitelisted) {
// we are receiving a request to edit the total supply of a non-whitelist token
revert Errors.TokenNotWhitelisted(token);
} else {
// we are receiving a request to whitelist a token that is already whitelisted
revert Errors.ClientChainGatewayAlreadyWhitelisted(token);
}
}
return (token, value);
}
Expand Down

0 comments on commit 5f898e9

Please sign in to comment.