Skip to main content

Staking/Unstaking ASTRO-xASTRO

Overview

A user can stake their ASTRO tokens into the Staking contract in exchange for xASTRO. by calling the enter endpoint in the Staking contract. The enter operation should be executed from inside the ASTRO contract.

Users can unstake their xASTRO tokens by calling leave endpoint in the Staking contract. leave claims the initial staked amount + accrued ASTRO since staking.

Staking ASTRO

Cw20HookMsg

To stake our ASTRO tokens, you need to execute a contract message pointing to the send enpoint in the ASTRO token contract.

The send operation takes in a:

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

_11
{
_11
"send": {
_11
"contract": stakingAddress,
_11
"amount": "100000000",
_11
"msg": toBase64(
_11
{
_11
"enter": {}
_11
}
_11
)
_11
}
_11
}

enter

Our encoded message performs a contract call to the enter endpoint in the Staking contract.

Deposits ASTRO in the xASTRO staking contract.

No additional parameters are required.


_11
{
_11
"send": {
_11
"contract": stakingAddress,
_11
"amount": "100000000",
_11
"msg": toBase64(
_11
{
_11
"enter": {}
_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": stakingAddress,
_11
"amount": "100000000",
_11
"msg": toBase64(
_11
{
_11
"enter": {}
_11
}
_11
)
_11
}
_11
}

toBase64

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


_18
const astroAddress = 'terra167dsqkh2alurx997wmycw9ydkyu54gyswe3ygmrs4lwume3vmwks8ruqnv';
_18
const stakingAddress = 'terra19t8ffmz6q2rdm3rllyksd6sex6n650a4anttzzvz9mf8mqr4nkrq44cyu6';
_18
_18
const stake = new MsgExecuteContract(
_18
wallet.key.accAddress('terra'),
_18
astroAddress,
_18
{
_18
"send": {
_18
"contract": stakingAddress,
_18
"amount": "100000000",
_18
"msg": toBase64(
_18
{
_18
"enter": {}
_18
}
_18
)
_18
}
_18
}
_18
)

Cw20HookMsg

To stake our ASTRO tokens, you need to execute a contract message pointing to the send enpoint in the ASTRO token contract.

The send operation takes in a:

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

enter

Our encoded message performs a contract call to the enter endpoint in the Staking contract.

Deposits ASTRO in the xASTRO staking contract.

No additional 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 an enter message using feather.js to define our custom function and encode our message.


_11
{
_11
"send": {
_11
"contract": stakingAddress,
_11
"amount": "100000000",
_11
"msg": toBase64(
_11
{
_11
"enter": {}
_11
}
_11
)
_11
}
_11
}

Unstaking xASTRO

Cw20HookMsg

To unstake our xASTRO tokens, you need to execute a contract message pointing to the send enpoint in the xASTRO token contract.

The send operation takes in a:

  • contract - Address where xASTRO tokens are being withdrawn from to (Staking contract)
  • amount - Amount to send (unstake)
  • msg - Binary encoded message containing our contract call.

_11
{
_11
"send": {
_11
"contract": stakingAddress,
_11
"amount": "50000000",
_11
"msg": toBase64(
_11
{
_11
"leave": {}
_11
}
_11
)
_11
}
_11
}

leave

Our encoded message performs a contract call to the leave endpoint in the Staking contract.

This burns xASTRO and unstakes underlying ASTRO (initial staked amount + accrued ASTRO since staking).

No additional parameters are required.


_11
{
_11
"send": {
_11
"contract": stakingAddress,
_11
"amount": "50000000",
_11
"msg": toBase64(
_11
{
_11
"leave": {}
_11
}
_11
)
_11
}
_11
}

Encoding our Msg

The same logic for encoding messages is used to enter and leave the staking contract. Refer to the section above for more information on this topic.


_11
{
_11
"send": {
_11
"contract": stakingAddress,
_11
"amount": "50000000",
_11
"msg": toBase64(
_11
{
_11
"leave": {}
_11
}
_11
)
_11
}
_11
}

Cw20HookMsg

To unstake our xASTRO tokens, you need to execute a contract message pointing to the send enpoint in the xASTRO token contract.

The send operation takes in a:

  • contract - Address where xASTRO tokens are being withdrawn from to (Staking contract)
  • amount - Amount to send (unstake)
  • msg - Binary encoded message containing our contract call.

leave

Our encoded message performs a contract call to the leave endpoint in the Staking contract.

This burns xASTRO and unstakes underlying ASTRO (initial staked amount + accrued ASTRO since staking).

No additional parameters are required.

Encoding our Msg

The same logic for encoding messages is used to enter and leave the staking contract. Refer to the section above for more information on this topic.


_11
{
_11
"send": {
_11
"contract": stakingAddress,
_11
"amount": "50000000",
_11
"msg": toBase64(
_11
{
_11
"leave": {}
_11
}
_11
)
_11
}
_11
}