Skip to main content

Staking/Unstaking LP Tokens

Overview

A user can stake their LP tokens into the Generator contract to receive ASTRO or 3rd party emissions by calling deposit. The deposit operation should be executed from inside the contract of the LP token you want to stake.

Users can also unstake their LP tokens by calling withdraw endpoint in the Generator contract. withdraw also claims any outstanding token emissions.

Staking LP Tokens

send

To stake our LP tokens in the Generator contract, you need to execute a contract message pointing to the send enpoint of the contract associated with the LP token you want to stake.

The send operation takes in a:

  • contract - Address LP tokens are being sent to (Generator contract)
  • amount - Amount to send/stake
  • msg - Binary encoded message containing our contract call.

_11
{
_11
"send": {
_11
"contract": generatorAddress,
_11
"amount": "10000000",
_11
"msg": toBase64(
_11
{
_11
"deposit": {}
_11
}
_11
)
_11
}
_11
}

deposit

Our encoded message performs a contract call to the deposit endpoint in the Generator contract.

No other parameters are required.


_11
{
_11
"send": {
_11
"contract": generatorAddress,
_11
"amount": "10000000",
_11
"msg": toBase64(
_11
{
_11
"deposit": {}
_11
}
_11
)
_11
}
_11
}

Encoding our Msg

To encode our message, there are two common options:

The code in this section uses a custom function (toBase64) to display our binary message - this function needs to be defined elsewhere to be used. The actual string representation of our message would be an encoded binary.


_11
{
_11
"send": {
_11
"contract": generatorAddress,
_11
"amount": "10000000",
_11
"msg": toBase64(
_11
{
_11
"deposit": {}
_11
}
_11
)
_11
}
_11
}

toBase64

The code in this section is an example of a deposit message using feather.js to define our custom function and encode our message.


_29
const generatorAddress = 'terra1gc4d4v82vjgkz0ag28lrmlxx3tf6sq69tmaujjpe7jwmnqakkx0qm28j2l';
_29
_29
const stakeLPTokens = new MsgExecuteContract(
_29
wallet.key.accAddress('terra'),
_29
astrolunaLPAddress,
_29
{
_29
"send": {
_29
"contract": generatorAddress,
_29
"amount": "10000000",
_29
"msg": toBase64(
_29
{
_29
"deposit": {}
_29
}
_29
)
_29
}
_29
}
_29
)
_29
_29
const fee = new Fee(2000000, { uluna: 200000 });
_29
_29
const tx = await wallet.createAndSignTx({
_29
msgs: [stakeLPTokens],
_29
fee,
_29
chainID: 'pisco-1',
_29
});
_29
_29
const result = await lcd.tx.broadcast(tx, 'pisco-1');
_29
_29
console.log(result);

send

To stake our LP tokens in the Generator contract, you need to execute a contract message pointing to the send enpoint of the contract associated with the LP token you want to stake.

The send operation takes in a:

  • contract - Address LP tokens are being sent to (Generator contract)
  • amount - Amount to send/stake
  • msg - Binary encoded message containing our contract call.

deposit

Our encoded message performs a contract call to the deposit endpoint in the Generator contract.

No other parameters are required.

Encoding our Msg

To encode our message, there are two common options:

The code in this section uses a custom function (toBase64) to display our binary message - this function needs to be defined elsewhere to be used. The actual string representation of our message would be an encoded binary.

toBase64

The code in this section is an example of a deposit message using feather.js to define our custom function and encode our message.


_11
{
_11
"send": {
_11
"contract": generatorAddress,
_11
"amount": "10000000",
_11
"msg": toBase64(
_11
{
_11
"deposit": {}
_11
}
_11
)
_11
}
_11
}

Unstaking LP Tokens

withdraw

To unstake LP tokens from the Generator contract, you need to execute a contract message pointing to the withdraw endpoing in the Generator contract.

withdraw takes in the address lp_token you want to withdraw and an amount to withdraw.


_6
{
_6
"withdraw": {
_6
"lp_token": astrolunaLPAddress,
_6
"amount": "5000000"
_6
}
_6
}

withdraw

To unstake LP tokens from the Generator contract, you need to execute a contract message pointing to the withdraw endpoing in the Generator contract.

withdraw takes in the address lp_token you want to withdraw and an amount to withdraw.


_6
{
_6
"withdraw": {
_6
"lp_token": astrolunaLPAddress,
_6
"amount": "5000000"
_6
}
_6
}