跳到主要内容

JBSwapTerminalRegistry

Git Source

Inherits: IJBSwapTerminalRegistry, JBPermissioned, Ownable, ERC2771Context

State Variables

PROJECTS

The project registry.

IJBProjects public immutable override PROJECTS;

PERMIT2

The permit2 utility.

IPermit2 public immutable PERMIT2;

defaultTerminal

The default hook to use.

IJBTerminal public override defaultTerminal;

hasLockedTerminal

Whether the terminal for the given project is locked.

mapping(uint256 projectId => bool) public override hasLockedTerminal;

terminalOf

The terminal for the given project.

mapping(uint256 projectId => IJBTerminal) public override terminalOf;

isTerminalAllowed

The address of each project's token.

mapping(IJBTerminal terminal => bool) public override isTerminalAllowed;

Functions

constructor

constructor(
IJBPermissions permissions,
IJBProjects projects,
IPermit2 permit2,
address owner,
address trustedForwarder
)
JBPermissioned(permissions)
ERC2771Context(trustedForwarder)
Ownable(owner);

Parameters

NameTypeDescription
permissionsIJBPermissionsThe permissions contract.
projectsIJBProjectsThe project registry.
permit2IPermit2The permit2 utility.
owneraddressThe owner of the contract.
trustedForwarderaddressThe trusted forwarder for the contract.

accountingContextForTokenOf

Get the accounting context for the specified project ID and token.

Accounting contexts are set up in addDefaultPool(...).

function accountingContextForTokenOf(
uint256 projectId,
address token
)
external
view
override
returns (JBAccountingContext memory context);

Parameters

NameTypeDescription
projectIduint256The ID of the project to get the accounting context for.
tokenaddressThe address of the token to get the accounting context for.

Returns

NameTypeDescription
contextJBAccountingContextA JBAccountingContext containing the accounting context for the project ID and token.

accountingContextsOf

Return all the accounting contexts for a specified project ID.

This includes both project-specific and generic accounting contexts, with the project-specific contexts taking precedence.

function accountingContextsOf(uint256 projectId)
external
view
override
returns (JBAccountingContext[] memory contexts);

Parameters

NameTypeDescription
projectIduint256The ID of the project to get the accounting contexts for.

Returns

NameTypeDescription
contextsJBAccountingContext[]An array of JBAccountingContext containing the accounting contexts for the project ID.

currentSurplusOf

Empty implementation to satisfy the interface. This terminal has no surplus.

function currentSurplusOf(
uint256 projectId,
JBAccountingContext[] memory accountingContexts,
uint256 decimals,
uint256 currency
)
external
view
returns (uint256);

supportsInterface

function supportsInterface(bytes4 interfaceId) public pure override returns (bool);

_contextSuffixLength

ERC-2771 specifies the context as being a single address (20 bytes).

function _contextSuffixLength() internal view override(ERC2771Context, Context) returns (uint256);

_msgData

The calldata. Preferred to use over msg.data.

function _msgData() internal view override(ERC2771Context, Context) returns (bytes calldata);

Returns

NameTypeDescription
<none>bytescalldata The msg.data of this call.

_msgSender

The message's sender. Preferred to use over msg.sender.

function _msgSender() internal view override(ERC2771Context, Context) returns (address sender);

Returns

NameTypeDescription
senderaddressThe address which sent this call.

addAccountingContextsFor

Empty implementation to satisfy the interface. Accounting contexts are set in addDefaultPool(...).

function addAccountingContextsFor(
uint256 projectId,
JBAccountingContext[] calldata accountingContexts
)
external
override;

addToBalanceOf

Accepts funds for a given project, swaps them if necessary, and adds them to the project's balance in the specified terminal.

This function handles the token in transfer, potentially swaps the tokens to the desired output token, and then adds the swapped tokens to the project's balance in the specified terminal.

function addToBalanceOf(
uint256 projectId,
address token,
uint256 amount,
bool shouldReturnHeldFees,
string calldata memo,
bytes calldata metadata
)
external
payable
override;

Parameters

NameTypeDescription
projectIduint256The ID of the project for which funds are being accepted and added to its balance.
tokenaddressThe address of the token being paid in.
amountuint256The amount of tokens being paid in.
shouldReturnHeldFeesboolA boolean to indicate whether held fees should be returned.
memostringA memo to pass along to the emitted event.
metadatabytesBytes in JBMetadataResolver's format which can contain additional data for the swap and adding to balance.

allowTerminal

Allow a hook.

Only the owner can allow a hook.

function allowTerminal(IJBTerminal terminal) external onlyOwner;

Parameters

NameTypeDescription
terminalIJBTerminalThe terminal to allow.

disallowTerminal

Disallow a terminal.

Only the owner can disallow a hook.

function disallowTerminal(IJBTerminal terminal) external onlyOwner;

Parameters

NameTypeDescription
terminalIJBTerminalThe terminal to disallow.

lockTerminalFor

Lock a terminal for a project.

Only the project's owner or an address with the JBPermissionIds.ADD_SWAP_TERMINAL_POOL permission from the owner can lock a terminal for a project.

function lockTerminalFor(uint256 projectId) external;

Parameters

NameTypeDescription
projectIduint256The ID of the project to lock the terminal for.

migrateBalanceOf

Empty implementation to satisfy the interface.

function migrateBalanceOf(
uint256 projectId,
address token,
IJBTerminal to
)
external
override
returns (uint256 balance);

pay

Pay a project by swapping the incoming tokens for tokens that one of the project's other terminals accepts, passing along the funds received from the swap and the specified parameters.

function pay(
uint256 projectId,
address token,
uint256 amount,
address beneficiary,
uint256 minReturnedTokens,
string calldata memo,
bytes calldata metadata
)
external
payable
virtual
override
returns (uint256);

Parameters

NameTypeDescription
projectIduint256The ID of the project being paid.
tokenaddressThe address of the token being paid in.
amountuint256The amount of tokens being paid in, as a fixed point number with the same amount of decimals as the token. If token is the native token, amount is ignored and msg.value is used in its place.
beneficiaryaddressThe beneficiary address to pass along to the other terminal. If the other terminal mints tokens, for example, they will be minted for this address.
minReturnedTokensuint256The minimum number of project tokens expected in return, as a fixed point number with the same number of decimals as the other terminal. This value will be passed along to the other terminal.
memostringA memo to pass along to the emitted event.
metadatabytesBytes in JBMetadataResolver's format which can contain a quote from the user/client. The quote should contain a minimum amount of tokens to receive from the swap and the pool to use. This metadata is also passed to the other terminal's emitted event, as well as its data hook and pay hook if applicable.

Returns

NameTypeDescription
<none>uint256The number of tokens received from the swap, as a fixed point number with the same amount of decimals as that token.

setDefaultTerminal

Set the default terminal.

Only the owner can set the default hook.

function setDefaultTerminal(IJBTerminal terminal) external onlyOwner;

Parameters

NameTypeDescription
terminalIJBTerminalThe terminal to set as the default.

setTerminalFor

Set the terminal for a project.

Only the project's owner or an address with the JBPermissionIds.ADD_SWAP_TERMINAL_POOL permission from the owner can set the terminal for a project.

function setTerminalFor(uint256 projectId, IJBTerminal terminal) external;

Parameters

NameTypeDescription
projectIduint256The ID of the project to set the terminal for.
terminalIJBTerminalThe terminal to set for the project.

_acceptFundsFor

Accepts a token being paid in.

function _acceptFundsFor(address token, uint256 amount, bytes calldata metadata) internal returns (uint256);

Parameters

NameTypeDescription
tokenaddressThe address of the token being paid in.
amountuint256The amount of tokens being paid in.
metadatabytesThe metadata in which permit2 context is provided.

Returns

NameTypeDescription
<none>uint256amount The amount of tokens that have been accepted.

_beforeTransferFor

Logic to be triggered before transferring tokens from this terminal.

function _beforeTransferFor(address to, address token, uint256 amount) internal virtual returns (uint256);

Parameters

NameTypeDescription
toaddressThe address to transfer tokens to.
tokenaddressThe token being transfered.
amountuint256The amount of tokens to transfer, as a fixed point number with the same number of decimals as the token.

Returns

NameTypeDescription
<none>uint256payValue The amount that'll be paid as a msg.value.

_transferFrom

Transfers tokens.

function _transferFrom(address from, address payable to, address token, uint256 amount) internal virtual;

Parameters

NameTypeDescription
fromaddressThe address to transfer tokens from.
toaddress payableThe address to transfer tokens to.
tokenaddressThe address of the token being transfered.
amountuint256The amount of tokens to transfer, as a fixed point number with the same number of decimals as the token.

Errors

JBSwapTerminalRegistry_NoMsgValueAllowed

error JBSwapTerminalRegistry_NoMsgValueAllowed(uint256 value);

JBSwapTerminalRegistry_PermitAllowanceNotEnough

error JBSwapTerminalRegistry_PermitAllowanceNotEnough(uint256 amount, uint256 allowanceAmount);

JBSwapTerminalRegistry_TerminalLocked

error JBSwapTerminalRegistry_TerminalLocked(uint256 projectId);

JBSwapTerminalRegistry_TerminalNotAllowed

error JBSwapTerminalRegistry_TerminalNotAllowed(IJBTerminal terminal);

JBSwapTerminalRegistry_TerminalNotSet

error JBSwapTerminalRegistry_TerminalNotSet(uint256 projectId);