Staking/Unstaking LP Tokens
Overview
LP tokens staked in the Incentives contract earn the incentive rewards scheduled for their pool. Unstaked LP tokens earn swap fees only (fees accrue inside the pool for every LP token, staked or not).
| Chain | Incentives |
|---|---|
| Terra | terra1eywh4av8sln6r45pxq45ltj798htfy0cfcf7fy3pxc2gcv6uc07se4ch9x (1.5.0) |
| Neutron | neutron173fd8wpfzyqnfnpwq2zhtgdstujrjz2wkprkjfr6gqg4gknctjyq6m3tch (1.4.0) |
Astroport no longer emits ASTRO to pools: Incentives' ASTRO rate is zero. Rewards for staked LP tokens come only from external incentive schedules that anyone can add to a pool (see Claiming Rewards). Staking a pool's LP tokens earns nothing extra unless that pool has an active schedule. The legacy Generator contracts still exist on both chains, but emissions there have ended; use Incentives.
Any LP token of a pool registered in the factory can be staked. Staking, unstaking and claiming all settle your pending rewards first: every deposit and withdraw also pays out what you have earned so far.
Staking LP Tokens
How you stake depends on the LP token type, which the pool's pair query returns as liquidity_token.
Native LP Tokens
Call deposit on Incentives and attach the LP tokens (exactly one coin) as funds:
_3{_3 "deposit": {}_3}
_11const incentives = "neutron173fd8wpfzyqnfnpwq2zhtgdstujrjz2wkprkjfr6gqg4gknctjyq6m3tch";_11const lpDenom = "factory/neutron1...pool/astroport/share";_11_11await signingClient.execute(_11 sender,_11 incentives,_11 { deposit: {} },_11 "auto",_11 "",_11 [{ denom: lpDenom, amount: "1000000" }]_11);
deposit takes an optional recipient to stake on behalf of another address: {"deposit": {"recipient": "neutron1..."}}.
CW20 LP Tokens
Call send on the LP token contract with Incentives as contract. The msg is the base64 encoding of {"deposit":{}}.
_7{_7 "send": {_7 "contract": "terra1eywh4av8sln6r45pxq45ltj798htfy0cfcf7fy3pxc2gcv6uc07se4ch9x",_7 "amount": "1000000",_7 "msg": "eyJkZXBvc2l0Ijp7fX0="_7 }_7}
_17import { toBinary } from "@cosmjs/cosmwasm-stargate";_17_17const incentives = "terra1eywh4av8sln6r45pxq45ltj798htfy0cfcf7fy3pxc2gcv6uc07se4ch9x";_17const lpToken = "terra1s275y73lfupag0g03nglxaedfnsw5z4m5zc9wk66guy503zuw5ss889tlx"; // LUNA/USDC LP_17_17await signingClient.execute(_17 sender,_17 lpToken, // the LP token contract_17 {_17 send: {_17 contract: incentives,_17 amount: "1000000",_17 msg: toBinary({ deposit: {} }),_17 },_17 },_17 "auto"_17);
Staking While Providing Liquidity
provide_liquidity with "auto_stake": true mints the LP tokens and stakes them in Incentives in the same transaction. See Providing/Withdrawing Liquidity.
Unstaking LP Tokens
Call withdraw on Incentives with the LP token (denom or CW20 address) and the amount. The LP tokens and any pending rewards are sent to you.
_6{_6 "withdraw": {_6 "lp_token": "terra1s275y73lfupag0g03nglxaedfnsw5z4m5zc9wk66guy503zuw5ss889tlx",_6 "amount": "1000000"_6 }_6}
_6await signingClient.execute(_6 sender,_6 incentives,_6 { withdraw: { lp_token: lpToken, amount: "1000000" } },_6 "auto"_6);
The amount can't be more than you have staked. To leave a withdraw-only (exit-only) pool, unstake its LP tokens here first, then withdraw them from the pool.
Checking Your Position
The amount you have staked (deposit returns a Uint128):
_6{_6 "deposit": {_6 "lp_token": "terra1s275y73lfupag0g03nglxaedfnsw5z4m5zc9wk66guy503zuw5ss889tlx",_6 "user": "terra1...you"_6 }_6}
Your pending rewards for that LP token, as a list of assets (the query fails if you have no position in that pool):
_6{_6 "pending_rewards": {_6 "lp_token": "terra1s275y73lfupag0g03nglxaedfnsw5z4m5zc9wk66guy503zuw5ss889tlx",_6 "user": "terra1...you"_6 }_6}