Skip to content

Commit

Permalink
Fix crash if delegate.xyz doesn't support current chain
Browse files Browse the repository at this point in the history
  • Loading branch information
boyuanx committed Apr 19, 2024
1 parent 05181cc commit 8da5ec1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
23 changes: 22 additions & 1 deletion contracts/core/TokenTableUnlockerV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ contract TokenTableUnlockerV2 is
bool isCancelable;
bool isHookable;
bool isWithdrawable;
bool currentChainSupportsExternalDelegateRegistry;
mapping(bytes32 => Preset) _presets;
mapping(uint256 => Actual) actuals;
mapping(uint256 => uint256) pendingAmountClaimableForCancelledActuals;
Expand Down Expand Up @@ -165,6 +166,7 @@ contract TokenTableUnlockerV2 is
for (uint256 i = 0; i < actualIds.length; i++) {
if (
!callerIsClaimingDelegate &&
$.currentChainSupportsExternalDelegateRegistry &&
!externalDelegateRegistry.checkDelegateForContract(
_msgSender(),
$.futureToken.ownerOf(actualIds[i]),
Expand Down Expand Up @@ -239,6 +241,14 @@ contract TokenTableUnlockerV2 is
emit ClaimingDelegateSet(delegate, status);
}

function setCurrentChainSupportsExternalDelegateRegistry(
bool status
) external override onlyOwner {
TokenTableUnlockerV2Storage
storage $ = _getTokenTableUnlockerV2Storage();
$.currentChainSupportsExternalDelegateRegistry = status;
}

function disableCreate() external virtual override onlyOwner {
TokenTableUnlockerV2Storage
storage $ = _getTokenTableUnlockerV2Storage();
Expand Down Expand Up @@ -464,7 +474,18 @@ contract TokenTableUnlockerV2 is
}

function version() external pure returns (string memory) {
return "2.5.7";
return "2.6.0";
}

function currentChainSupportsExternalDelegateRegistry()
public
view
override
returns (bool)
{
TokenTableUnlockerV2Storage
storage $ = _getTokenTableUnlockerV2Storage();
return $.currentChainSupportsExternalDelegateRegistry;
}

function calculateAmountClaimable(
Expand Down
16 changes: 16 additions & 0 deletions contracts/interfaces/ITokenTableUnlockerV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ abstract contract ITokenTableUnlockerV2 is IOwnable, IVersionable {
bool status
) external virtual;

/**
* @notice Sets if the current chain is supported by delegate.xyz
*/
function setCurrentChainSupportsExternalDelegateRegistry(
bool status
) external virtual;

/**
* @notice Permanently disables the `createActuals()` function.
* @dev Only callable by the owner.
Expand Down Expand Up @@ -294,6 +301,15 @@ abstract contract ITokenTableUnlockerV2 is IOwnable, IVersionable {
*/
function BIPS_PRECISION() external pure virtual returns (uint256);

/**
* @notice Returns if the current chain is supported by delegate.xyz
*/
function currentChainSupportsExternalDelegateRegistry()
public
view
virtual
returns (bool);

/**
* @notice Calculates the amount of unlocked tokens that have yet to be claimed in an actual unlocking schedule.
* @dev This is the most complex part of the smart contract. Quite a bit of calculations are performed here.
Expand Down

0 comments on commit 8da5ec1

Please sign in to comment.