Providing Liquidity
Range shares, deposits, withdrawals and execution limits for liquidity integrations.
Provide liquidity to a PoolKey and tick range through its supported Hook. ERC-6909 shares represent liquidity, not a fixed token balance or guaranteed redemption value.
This SDK flow follows @masterpeach/market-sdk@1.0.1, main@b5fc5ba. Its ABI provenance is 53cb71c7…; the earlier contract reference uses 314ed215…. Verify deployment and version-sensitive behavior before execution.
Understand the position
Price relative to tickLower and tickUpper determines whether a deposit or withdrawal contains one asset or both. In-range liquidity earns trading fees; out-of-range liquidity resumes earning when price returns. Narrower ranges concentrate exposure and can leave range sooner. Fee income alone is not profit.
Obtain the complete PoolKey from getPool(poolId) or Registry discovery. Check currency order, supported Hook, initialization, tick spacing and lower < upper. Use getMarketRangeId; its hash uses standard ABI encoding with signed ticks. Token amounts use integer base units; liquidity/shares are separate units.
Add liquidity
Reuse the Quickstart client created with prepare: true, its explicit verifyDeployment() check and submitConfirmed(client, prepared, onSent) helper. Default prepare: false skips transaction preflight; deployment verification is a separate code-and-wiring check.
Supply the connected owner, chosen liquidity/slippage/deadline in params, and user-approved maximum token budgets. This prepares one action without broadcasting:
import { type MarketClient, type MarketLiquidityParams } from '@masterpeach/market-sdk';
import { isAddressEqual, type Address } from 'viem';
export async function prepareDepositStep(
client: MarketClient, owner: Address, params: MarketLiquidityParams,
maxAmount0: bigint, maxAmount1: bigint,
) {
const quote = await client.previewDeposit(params);
if (quote.data.limit0 > maxAmount0 || quote.data.limit1 > maxAmount1)
throw new Error('Quote exceeds approved token budgets');
const spend = await client.getSpendStatus({
key: params.key, owner, amount0: quote.data.limit0, amount1: quote.data.limit1,
...quote.block,
});
if (spend.data.tokens.some(token => !token.sufficientBalance))
throw new Error('Insufficient balance');
const token = spend.data.tokens.find(token => token.kind === 'erc20' && token.needsApproval);
const prepared = token
? await client.prepareApproval({
key: params.key, currency: isAddressEqual(token.token, params.key.currency0) ? 0 : 1,
amount: token.requiredAmount,
})
: await client.prepareDeposit(quote);
if (!prepared.context.preflight || !isAddressEqual(prepared.request.account, owner))
throw new Error('Use the checked client and connected owner');
return { kind: token ? 'approval' : 'deposit', quote, spend, prepared };
}Display the action, network, spender and amounts before calling submitConfirmed. After each confirmed approval, call prepareDepositStep again for a fresh quote and spend check; review new limits before depositing. Direct deposits approve the Hook for the complete requiredAmount, not an allowance shortfall. Reset-required tokens need a separate confirmed zero approval first. Native currency needs no approval.
limit0/1 are maximum spends, rounded up with token-amount slippage (50 bps = 0.5%). Choose a deadline from current chain time; never silently extend the user's deadline or budgets. Quotes normally expire after 60 seconds, bounded by that deadline (validForSeconds: 1–300). Deposits checkpoint prior earnings before minting shares. Simulation cannot guarantee later execution; use confirmed events for actual amounts/shares.
Withdraw or claim
prepareWithdraw(preview, to)
Burns selected shares and returns assets.
Settles accounting without paying fees.
prepareClaim({ …, to, maxFeeBps })
Keeps shares/principal.
Claims net earnings.
prepareWithdrawAndClaim(preview, to, maxFeeBps)
Withdraws selected principal.
Also claims net earnings.
Use a fresh previewWithdraw(params), then review its limit0/1 minimum principal, recipient and deadline. Small/one-sided positions may have a zero minimum for one asset; show the actual protection. Withdraw only owned shares. Full withdrawal can leave fees claimable. maxFeeBps caps the effective claim fee (0–2000), not a promised return. Standalone claims have no on-chain deadline. See Fees & Claims.
Native funds and Router operations
Only RampETH supports native currency0 = zeroAddress. Direct SDK deposits prepay exactly limit0; unused input refunds atomically. Wrapped tokens remain ERC-20. Spend-status balance checks exclude gas; checked native preparation requires balance >= value + gas × maxFeePerGas. Refunds cannot prefund gas. Arc native gas USDC differs from ERC-20 USDC.
ZapIn approves the selected Router for total input, then refreshes the quote, protects shares/output, simulates and prepares with quoted swapIn. The Helper receives no approvals. ZapOut needs share permission and withdraws principal only. Compound/Rebalance require their authorization reads, confirmed permissions, fresh full-operation simulation and protected positive share/principal minima. They use internal funds; shares go to the owner. includeFees: true invests all old-range fees, even for partial migration.
Claim permission is independent of share permission: an operator can choose the fee recipient until revoked. Mainnet claimOperator remains unverified; checked Compound/fee-including Rebalance need separate reviewed acceptance. See the Router guide.
Execution and recovery
The earlier 314ed215… reference blocks withdrawals during pauses; the current SDK baseline documents a principal-only withdrawal exemption. Claims/combined withdrawals remain pause-sensitive. Verify actual deployment behavior and simulate the exact request; RWA CLOSED and Registry activity are separate states.
Keep the client and persist the hash through onSent. After timeout, wait on the same hash; after ambiguous broadcast, inspect its receipt/wallet history before retrying. Check confirmed status and matching events. Reverts can consume gas; prior approvals remain effective. Earlier ABI/ledger details: Ramp, RampETH.
Last updated
Was this helpful?