⚙️Liquidity Provision Mechanics
Creating a Deposit Request
Creation of a deposit request is done by calling the createDeposit
function in the Router
smart contract.
solidity
Parameters:
MarketId _id: A bytes32 value identifying the specific market being deposited into. MarketIds can be fetched through the
MarketFactory
smart contract by the callinggetMarketForTicker
function.address _owner: The address of the creator of the deposit. Here you can simply pass in the address you're calling the function with.
address _tokenIn: The address of the deposit token. This should be either the WETH or USDC smart contract address for the specific chain the function is being called on.
uint256 _amountIn: The amount of tokens being deposited in the tokens respective base unit. For ETH / WETH, this will be 18 decimal places, and for USDC this will be 6 decimal places. E.g 1 USDC = 1000000.
uint256 _executionFee: The amount, in wei to pay to the keeper who executes the transaction. This value can be estimated by calling this function on the
Gas
smart contract and adding both values together.soliditybool _shouldWrap: This value should be false by default, unless the token being deposited is Ether.
Errors:
69be4eee
Router_InvalidOwner: Owner should be msg.sendera53687bb
Router_InvalidAmountIn: Amount in can't be 0, and the execution fee + amountIn parameters must be accounted for correctly.1caef9c0
Router_InvalidTokenIn: _shouldWrap is incorrectly false.317ebaad
Market_FailedToAddRequest: The request failed to add to storage for some reason. In this case, we'd suggest debugging with Tenderly and reporting the error within Discord.
Note: The function is payable, meaning you need to send the exact amount of ETH equal to the execution fee when calling this function.
Creating a Withdrawal Request
Creation of a withdrawal request is done by calling the createWithdrawal
function in the Router smart contract.
solidity
Parameters:
MarketId _id: A bytes32 value identifying the specific market being withdrawn from. MarketIds can be fetched through the MarketFactory smart contract by calling the getMarketForTicker function.
address _owner: The address of the creator of the withdrawal. Here you can simply pass in the address you're calling the function with.
address _tokenOut: The address of the token to receive upon withdrawal. This should be either the WETH or USDC smart contract address for the specific chain the function is being called on.
uint256 _marketTokenAmountIn: The amount of market tokens being withdrawn. This should be in the token's base unit (typically 18 decimal places for most tokens).
uint256 _executionFee: The amount, in wei, to pay to the keeper who executes the transaction. This value can be estimated by calling this function on the Gas smart contract and adding both returned values together:solidity
bool _shouldUnwrap: This value should be true if you want to receive ETH instead of WETH, false otherwise.
Errors:
69be4eee
Router_InvalidOwner: Owner should be msg.sendera53687bb
Router_InvalidAmountIn: MarketTokenAmountIn can't be 01caef9c0
Router_InvalidTokenOut: The token out is not valid (must be USDC or WETH, or ETH if shouldUnwrap is true)317ebaad
Market_FailedToAddRequest: The request failed to add to storage for some reason. In this case, we'd suggest debugging with Tenderly and reporting the error within Discord.
Note: The function is payable, meaning you need to send the exact amount of ETH equal to the execution fee when calling this function.
Executing Requests
Executing Deposit / Withdrawal Requests is extremely straight forward and only required 2 parameters.
Parameters:
MarketId _id: The id of the market that the deposit / withdrawal request is for.
bytes32 _key: The unique identifier (key) of the deposit / withdrawal request.
Both of these values can be easily retrieved from the following events on the Market
smart contract.
From this event Market.RequestCreated
the key can be retrieved:
solidity
Every time the event above fires, within the same block, these logs can also be found from the same transaction, but from the Router
smart contract, to retrieve the marketId:
After both the marketId
and requestKey
have been obtained, the position can easily be executed, given a price has been signed, which may take up to 30 seconds to occur.
Common Errors:
69be95d5
MarketUtils_AmountTooSmall: The deposited / withdrawn amount is too insignificant.1c6b687e
Vault_InsufficientAvailableTokens: Their aren't sufficient unreserved tokens to facilitate the withdrawal request.7a203bfd
Vault_InvalidDeposit: The deposit request is invalid.7e8aeaf6
Vault_InvalidWithdrawal: The withdrawal request is invalid.633240a4
PriceFeed_PriceRequired(string memory token): The price hasn't been signed for the request yet.
Last updated