JBSucker
Inherits: ERC2771Context, JBPermissioned, Initializable, ERC165, IJBSuckerExtended
An abstract contract for bridging a Juicebox project's tokens and the corresponding funds to and from a remote chain.
Beneficiaries and balances are tracked on two merkle trees: the outbox tree is used to send from the local chain to the remote chain, and the inbox tree is used to receive from the remote chain to the local chain.
Throughout this contract, "terminal token" refers to any token accepted by a project's terminal.
This contract does NOT support tokens that have a fee on regular transfers and rebasing tokens.
State Variables
MESSENGER_BASE_GAS_LIMIT
A reasonable minimum gas limit for a basic cross-chain call. The minimum amount of gas required to call
the fromRemote
(successfully/safely) on the remote chain.
uint32 public constant override MESSENGER_BASE_GAS_LIMIT = 300_000;
MESSENGER_ERC20_MIN_GAS_LIMIT
A reasonable minimum gas limit used when bridging ERC-20s. The minimum amount of gas required to (successfully/safely) perform a transfer on the remote chain.
uint32 public constant override MESSENGER_ERC20_MIN_GAS_LIMIT = 200_000;
_TREE_DEPTH
The depth of the merkle tree used to store the outbox and inbox.
uint32 constant _TREE_DEPTH = 32;
ADD_TO_BALANCE_MODE
Whether the amountToAddToBalance
gets added to the project's balance automatically when claim
is
called or manually by calling addOutstandingAmountToBalance
.
JBAddToBalanceMode public immutable override ADD_TO_BALANCE_MODE;
DEPLOYER
The address of this contract's deployer.
address public immutable override DEPLOYER;
DIRECTORY
The directory of terminals and controllers for projects.
IJBDirectory public immutable override DIRECTORY;
TOKENS
The contract that manages token minting and burning.
IJBTokens public immutable override TOKENS;
_deprecatedAfter
The timestamp after which the sucker is entirely deprecated.
uint256 internal _deprecatedAfter;
_localProjectId
The ID of the project (on the local chain) that this sucker is associated with.
uint256 private _localProjectId;
_executedFor
Tracks whether individual leaves in a given token's merkle tree have been executed (to prevent double-spending).
A leaf is "executed" when the tokens it represents are minted for its beneficiary.
mapping(address token => BitMaps.BitMap) internal _executedFor;
_inboxOf
The inbox merkle tree root for a given token.
mapping(address token => JBInboxTreeRoot root) internal _inboxOf;
_outboxOf
The outbox merkle tree for a given token.
mapping(address token => JBOutboxTree) internal _outboxOf;
_remoteTokenFor
Information about the token on the remote chain that the given token on the local chain is mapped to.
mapping(address token => JBRemoteToken remoteToken) internal _remoteTokenFor;
Functions
constructor
constructor(
IJBDirectory directory,
IJBPermissions permissions,
IJBTokens tokens,
JBAddToBalanceMode addToBalanceMode,
address trusted_forwarder
)
ERC2771Context(trusted_forwarder)
JBPermissioned(permissions);
Parameters
Name | Type | Description |
---|---|---|
directory | IJBDirectory | A contract storing directories of terminals and controllers for each project. |
permissions | IJBPermissions | A contract storing permissions. |
tokens | IJBTokens | A contract that manages token minting and burning. |
addToBalanceMode | JBAddToBalanceMode | The mode of adding tokens to balance. |
trusted_forwarder | address |
amountToAddToBalanceOf
The outstanding amount of tokens to be added to the project's balance by claim
or
addOutstandingAmountToBalance
.
function amountToAddToBalanceOf(address token) public view override returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
token | address | The local terminal token to get the amount to add to balance for. |
inboxOf
The inbox merkle tree root for a given token.
function inboxOf(address token) external view returns (JBInboxTreeRoot memory);
Parameters
Name | Type | Description |
---|---|---|
token | address | The local terminal token to get the inbox for. |
isMapped
Checks whether the specified token is mapped to a remote token.
function isMapped(address token) external view override returns (bool);
Parameters
Name | Type | Description |
---|---|---|
token | address | The terminal token to check. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | A boolean which is true if the token is mapped to a remote token and false if it is not. |
outboxOf
Information about the token on the remote chain that the given token on the local chain is mapped to.
function outboxOf(address token) external view returns (JBOutboxTree memory);
Parameters
Name | Type | Description |
---|---|---|
token | address | The local terminal token to get the remote token for. |
peerChainId
Returns the chain on which the peer is located.
function peerChainId() external view virtual returns (uint256);
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | chain ID of the peer. |
remoteTokenFor
Information about the token on the remote chain that the given token on the local chain is mapped to.
function remoteTokenFor(address token) external view returns (JBRemoteToken memory);
Parameters
Name | Type | Description |
---|---|---|
token | address | The local terminal token to get the remote token for. |
peer
The peer sucker on the remote chain.
function peer() public view virtual returns (address);
projectId
This can be overridden by the inheriting contract to return a different address. This is fully supported by the sucker implementation and all its off-chain infrastructure, This does however break some invariants/assumptions, for revnets it would break the assumption of matching configurations on both chains, for this reason we only support a matching address.
The ID of the project (on the local chain) that this sucker is associated with.
function projectId() public view returns (uint256);
state
Reports the deprecation state of the sucker.
function state() public view override returns (JBSuckerState);
Returns
Name | Type | Description |
---|---|---|
<none> | JBSuckerState | state The current deprecation state |
supportsInterface
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool);