Skip to main content
There are several ways you can offer swaps against your pool for your users. The most straighforward is to direct them to the swap UI that Forte hosts on your behalf. If you’re looking for a more integrated experience you can create and send transactions to the pool in your own application.

Forte AMM Website

After your pool is deployed you can locate it on the pools page in the Forte Swap UI.
Forte Swap UI screenshot of a $TEST pool

Screenshot of a demo $TEST/USDC pair

After connecting a wallet, user’s can click the “Swap pair” button to trade against your pool!

Making a swap via cast command

Now let’s walk through constructing a cast command to swap directly against the pool onchain without any UI. This will help build up the understanding to build a custom UI so that users can trade against the token pool in your own application or website. The swap function that needs to be called has the following signature:
function swap(
        address _tokenIn,
        uint256 _amountIn,
        uint256 _minOut,
        address _recipient,
        uint256 _expires
    ) external returns (uint256 amountOut, uint256 lpFeeAmount, uint256 protocolFeeAmount)
ParameterTypeDescription
_tokenInaddressThe address of the token you’re swapping into the pool.
This can be either side of the token pair.
_amountInuint256The amount of _tokenIn to exchange.
_minOutuint256Minimum amount of output token to accept. This is slippage protection, see below for more details.
_recipientaddressAddress that will receive the output tokens
_expiresuint256Block timestamp expiration.

Determine the _minOut argument

The _minOut parameter in the swap() function protects your transactions from unfavorable price movements by setting a minimum acceptable output amount. If the actual output falls below this threshold, the transaction will revert, preventing execution at a worse price than you’re willing to accept. Depending on your use case, you’ll calculate _minOut differently:

Scenario 1: Specify how much you want to receive

Use case: You want to receive a specific amount of tokens (e.g., “I want exactly 100 $TEST”). Steps:
  1. Call simSwapReversed(_tokenOut, _amountOut) where _amountOut is your desired output amount
  2. This returns the amountIn you need to pay
  3. Calculate _minOut = _amountOut × slippageTolerance

Scenario 2: Specify how much you want to spend

Use case: You have a fixed amount to spend (e.g., “I want to spend 100 USDC”). Steps:
  1. Call simSwap(_tokenIn, _amountIn) where _amountIn is what you’re paying
  2. This returns the expected amountOut you’ll receive
  3. Calculate _minOut = amountOut × slippageTolerance
// for example, to allow 5% slippage
_minOut = _amountOut * 0.95;

Integrating a swap UI into your own Application

This is a more involved integration process, but enables you to keep users within your own app ecosystem. You can see an example of this in our Martian Mining demo site.
Martian Mining demo site

Screenshot of our Martian Mining demo swap UI

If you’d like access to the code repository for this demo site, contact us!