JBSwapTerminal
Inherits: JBPermissioned, Ownable, IJBTerminal, IJBPermitTerminal, IJBSwapTerminal, IUniswapV3SwapCallback
The JBSwapTerminal
accepts payments in any token. When the JBSwapTerminal
is paid, it uses a Uniswap
pool to exchange the tokens it received for tokens that another one of its project's terminals can accept. Then, it
pays that terminal with the tokens it got from the pool, forwarding the specified beneficiary to receive any tokens
or NFTs minted by that payment, as well as payment metadata and other arguments.
To prevent excessive slippage, the user/client can specify a minimum quote and a pool to use in their payment's
metadata using the JBMetadataResolver
format. If they don't, a quote is calculated for them based on the TWAP
oracle for the project's default pool for that token (set by the project's owner).
Notes:
-
metadata-id-used: quoteForSwap and permit2
-
benediction: DEVS BENEDICAT ET PROTEGAT CONTRACTVS MEAM
State Variables
DEFAULT_PROJECT_ID
The ID to store default values in.
uint256 public constant override DEFAULT_PROJECT_ID = 0;
MAX_TWAP_SLIPPAGE_TOLERANCE
Projects cannot specify a TWAP slippage tolerance larger than this constant (out of MAX_SLIPPAGE
).
This prevents TWAP slippage tolerances so high that they would result in highly unfavorable trade conditions for the payer unless a quote was specified in the payment metadata.
uint256 public constant override MAX_TWAP_SLIPPAGE_TOLERANCE = 9000;
MIN_TWAP_SLIPPAGE_TOLERANCE
Projects cannot specify a TWAP slippage tolerance smaller than this constant (out of MAX_SLIPPAGE
).
This prevents TWAP slippage tolerances so low that the swap always reverts to default behavior unless a quote is specified in the payment metadata.
uint256 public constant override MIN_TWAP_SLIPPAGE_TOLERANCE = 100;
MAX_TWAP_WINDOW
Projects cannot specify a TWAP window longer than this constant.
This serves to avoid excessively long TWAP windows that could lead to outdated pricing information and higher gas costs due to increased computational requirements.
uint256 public constant override MAX_TWAP_WINDOW = 2 days;
MIN_TWAP_WINDOW
Projects cannot specify a TWAP window shorter than this constant.
This serves to avoid extremely short TWAP windows that could be manipulated or subject to high volatility.
uint256 public constant override MIN_TWAP_WINDOW = 2 minutes;
SLIPPAGE_DENOMINATOR
The denominator used when calculating TWAP slippage tolerance values.
uint160 public constant override SLIPPAGE_DENOMINATOR = 10_000;
MIN_DEFAULT_POOL_CARDINALITY
The minimum cardinality for a pool to be configured as a default pool.
The cardinality is automatically increased to this number when added as a default pool.
uint16 public constant override MIN_DEFAULT_POOL_CARDINALITY = 10;
DIRECTORY
The directory of terminals and controllers for PROJECTS
.
IJBDirectory public immutable DIRECTORY;
FACTORY
The factory to use for creating new pools
We rely on "a" factory, vanilla uniswap v3 or potential fork
IUniswapV3Factory public immutable FACTORY;
PERMIT2
The permit2 utility.
IPermit2 public immutable PERMIT2;
PROJECTS
Mints ERC-721s that represent project ownership and transfers.
IJBProjects public immutable PROJECTS;
TOKEN_OUT
The token which flows out of this terminal (JBConstants.NATIVE_TOKEN for the chain native token)
address public immutable TOKEN_OUT;
WETH
The ERC-20 wrapper for the native token.
"wETH" is used as a generic term throughout, but any native token wrapper can be used.
IWETH9 public immutable WETH;
_OUT_IS_NATIVE_TOKEN
A flag indicating if the token out is the chain native token (eth on mainnet for instance)
If so, the token out should be unwrapped before being sent to the next terminal
bool internal immutable _OUT_IS_NATIVE_TOKEN;