Building with Smart Pools
The flexibility of Steer's Smart Pool contracts make them a great option for protocols looking to incorperate them into their stack.
There are two fundamental ways Smart Pool contracts can be leveraged:
- Direct interaction with Smart Pool vault
- Trading Smart Pool LP tokens in secondary market
Integrating with Smart Pool Vaults
This guide provides an overview of how to integrate with Steer's Liquidity Manager Vault smart contracts. This interface is the same for all CLAMM vault types and allows users to deposit and withdraw funds proportionally to the vault's current holdings.
Key Functions for Integration
1. Getting Vault Holdings
To retrieve the total holdings of the vault, use the getTotalAmounts()
function:
function getTotalAmounts() external view returns (uint256 total0, uint256 total1)
This function returns the total amounts of token0 and token1 held by the vault, including the liquidity currently in liquidity pools.
2. Valuing LP Tokens
To value the LP tokens in terms of underlying assets, use the totalSupply()
function in conjunction with getTotalAmounts()
:
function totalSupply() external view returns (uint256)
You can calculate the value of one LP token as follows:
value_of_1_LP_token = (total0 + total1 * price_of_token1_in_token0) / totalSupply
Where total0
and total1
are obtained from getTotalAmounts()
, and price_of_token1_in_token0
is the current market price of token1 denominated in token0.
3. Depositing Funds
To deposit funds into the vault, use the deposit()
function:
function deposit(
uint256 amount0Desired,
uint256 amount1Desired,
uint256 amount0Min,
uint256 amount1Min,
address to
) external returns (uint256 shares, uint256 amount0, uint256 amount1)
Important notes for depositing:
- The ratio of
amount0Desired
toamount1Desired
should match the current ratio of the vault's holdings (obtained fromgetTotalAmounts()
). - Set
amount0Min
andamount1Min
to protect against slippage. - The
to
address will receive the minted LP tokens.
4. Withdrawing Funds
To withdraw funds from the vault, use the withdraw()
function:
function withdraw(
uint256 shares,
uint256 amount0Min,
uint256 amount1Min,
address to
) external returns (uint256 amount0, uint256 amount1)
Important notes for withdrawing:
- The
shares
parameter specifies how many LP tokens to burn. - Set
amount0Min
andamount1Min
to protect against slippage. - The
to
address will receive the withdrawn tokens.
Integration Flow
Check Vault Holdings: Call
getTotalAmounts()
to get the current ratio of token0 to token1 in the vault.Prepare Deposit: Calculate the desired deposit amounts based on the current ratio of holdings.
Approve Tokens: Ensure that your contract or user has approved the UniLiquidityManager contract to spend the required token amounts.
Deposit Funds: Call the
deposit()
function with the calculated amounts.Monitor LP Token Value: Use
totalSupply()
andgetTotalAmounts()
to track the value of LP tokens over time.Withdraw Funds: When ready to withdraw, call the
withdraw()
function with the desired number of shares to burn.
Example Integration Code
contract VaultInteractor {
UniLiquidityManager public vault;
constructor(address _vault) {
vault = UniLiquidityManager(_vault);
}
function depositProportionally(uint256 totalValue) external {
(uint256 total0, uint256 total1) = vault.getTotalAmounts();
uint256 ratio = (total0 * 1e18) / total1;
uint256 amount0Desired = (totalValue * ratio) / (ratio + 1e18);
uint256 amount1Desired = totalValue - amount0Desired;
// Approve tokens here
vault.deposit(
amount0Desired,
amount1Desired,
amount0Desired * 99 / 100, // 1% slippage protection
amount1Desired * 99 / 100, // 1% slippage protection
address(this)
);
}
function withdrawAll() external {
uint256 shares = vault.balanceOf(address(this));
vault.withdraw(
shares,
0, // Minimum amounts set to 0 for simplicity, use with caution
0,
address(this)
);
}
}
This guide provides a basic overview of integrating with Steer vault contracts. Always ensure to handle errors, check return values, and implement proper security measures when interacting with smart contracts.
If you are building on top of smart pool and having issues, Talk to team
LP Token Markets
The second way to interact with Smart Pools is to create a market where the assets can be bought and traded. This is helpful as it leaves the underlying liquidity in the Smart Pool and then as fees accrue and the value of the LP token rises the market can price in the current value of the LP tokens.
All Steer Vaults use the ERC-20 standard for the liquidity provision token representing a share of the vault's holdings. LP tokens can be used to withdraw liquidity at any time.
Smart Bonds
A popular use case of this method is protocols buying LP tokens for Smart Pools market making pools of the protocol's token. This allows a protocol to get permanent liquidity at a reduced cost. Read more about Smart Bonds here.