Skip to main content

Generator

The Generator contract allocates token rewards (ASTRO) for various LP tokens and distributes them pro-rata to LP stakers. The Generator supports proxy staking via 3rd party contracts that offer a second reward besides ASTRO token emissions.

InstantiateMsg

Initializes the contract with required addresses and contracts used for reward distributions.

json
generator.rs
Copy

_7
{
_7
"owner": "terra...",
_7
"astro_token": "...",
_7
"tokens_per_block": "123",
_7
"start_block": "123",
_7
"vesting_contract": "terra..."
_7
}

ParamsTypeDescription
ownerStringAddress that can change contract settings
astro_tokenStringASTRO token contract address
tokens_per_blockUint128Amount of ASTRO distributed per block among all pairs
start_blockUint64Start block for distributing ASTRO
vesting_contractStringThe ASTRO vesting contract that drips ASTRO rewards

ExecuteMsg

update_config

Update the vesting contract address, generator controller contract address or generator guardian address. Only the contract owner can execute this.

json
generator.rs
Copy

_10
{
_10
"update_config": {
_10
"vesting_contract": "...",
_10
"generator_controller": "...",
_10
"guardian": "...",
_10
"voting_escrow_delegation": "...",
_10
"voting_escrow": "...",
_10
"checkpoint_generator_limit": 20
_10
}
_10
}

ParamsTypeDescription
vesting_contractOption<String>The new vesting contract address
generator_controllerOption<String>The new generator controller contract address
guardianOption<String>The new generator guardian
voting_escrow_delegationOption<String>The new voting escrow delegation contract address
voting_escrowOption<String>The new voting escrow contract address
checkpoint_generator_limitOption<u32>The amount of generators

setup_pools

Set up a new list of pools with allocation points.

json
generator.rs
Copy

_9
{
_9
"setup_pools": {
_9
"pools": [
_9
("lp_token_address", "1000"),
_9
("lp_addr2", "10"),
_9
etc...
_9
]
_9
}
_9
}

ParamsTypeDescription
poolsVec<(String, Uint128)>The list of pools with allocation point

update_pool

Update has_asset_rewards parameter for the given pool.

json
generator.rs
Copy

_6
{
_6
"update_pool": {
_6
"lp_token": "...",
_6
"has_asset_rewards": true
_6
}
_6
}

ParamsTypeDescription
lp_tokenStringThe address of the LP token contract address whose allocation we change
has_asset_rewardsboolThis flag determines whether the pool gets 3rd party token rewards

claim_rewards

Updates rewards and returns it to user.

json
generator.rs
Copy

_5
{
_5
"claim_rewards": {
_5
"lp_tokens": "..."
_5
}
_5
}

ParamsTypeDescription
lp_tokensVec<String>The LP token contract address

deposit

Stakes LP tokens in a specific generator (inside the Generator contract).

NOTE

In order to stake in the Generator contract, you should execute this message inside the contract of the LP token you want to stake.

json
Copy

_7
{
_7
"send": {
_7
"contract": "GeneratorContractAddress",
_7
"amount": "999",
_7
"msg": "base64-encodedStringOfWithdrawMsg"
_7
}
_7
}

ParamsTypeDescription
sendCw20ReceiveMsgCW20 receive message

Inside send.msg, you may encode this JSON string into base64 encoding:

json
generator.rs
Copy

_3
{
_3
"deposit": {}
_3
}

deposit_for

Stakes LP tokens in the Generator on behalf of another address.

NOTE

In order to stake in the Generator contract, you should execute this message inside the LP token you want to stake.

json
Copy

_7
{
_7
"send": {
_7
"contract": "GeneratorContractAddress",
_7
"amount": "999",
_7
"msg": "base64-encodedStringOfWithdrawMsg"
_7
}
_7
}

ParamsTypeDescription
sendCw20ReceiveMsgCW20 receive message

Inside send.msg, you may encode this JSON string into base64 encoding:

json
generator.rs
Copy

_3
{
_3
"deposit_for": "..."
_3
}

withdraw

Unstakes LP tokens from the Generator contract and claims outstanding token emissions.

json
generator.rs
Copy

_6
{
_6
"withdraw": {
_6
"lp_token": "...",
_6
"amount": "123"
_6
}
_6
}

ParamsTypeDescription
lp_tokenStringThe address of the LP token to withdraw
amountUint128The amount to withdraw

emergency_withdraw

Unstakes LP tokens without caring about rewards. To be used only in emergencies such as a critical bug found in the Generator contract.

json
generator.rs
Copy

_5
{
_5
"emergency_withdraw": {
_5
"lp_token": "..."
_5
}
_5
}

ParamsTypeDescription
lp_tokenStringThe address of the LP token to withdraw

send_orphan_proxy_reward

Sends orphaned rewards (left behind by emergency withdraws) to another address. Only the contract owner can transfer orphan rewards.

json
generator.rs
Copy

_6
{
_6
"send_orphan_proxy_reward": {
_6
"recipient": "...",
_6
"lp_token": "..."
_6
}
_6
}

ParamsTypeDescription
recipientStringThe transfer recipient
lp_tokenStringThe address of the LP token contract for which we send orphaned rewards

receive

CW20 receive msg.

json
generator.rs
Copy

_7
{
_7
"receive": {
_7
"sender": "terra...",
_7
"amount": "123",
_7
"msg": "<base64_encoded_json_string>"
_7
}
_7
}

ParamsTypeDescription
receiveCw20ReceiveMsgCW20 receive message

set_tokens_per_block

Sets the total amount of ASTRO distributed per block among all active generators. Only the owner can execute this.

json
generator.rs
Copy

_5
{
_5
"set_tokens_per_block": {
_5
"amount": "123"
_5
}
_5
}

ParamsTypeDescription
amountUint128The new amount of ASTRO to distro per block

propose_new_owner

Creates a request to change contract ownership. The validity period of the offer is set by the expires_in variable. Only the current owner can execute this.

json
generator.rs
Copy

_6
{
_6
"propose_new_owner": {
_6
"owner": "...",
_6
"expires_in": 1234567
_6
}
_6
}

ParamsTypeDescription
ownerStringThe newly proposed owner
expires_inu64The validity period of the proposal to change the contract owner

drop_ownership_proposal

Removes the existing offer to change contract ownership. Only the contract owner can execute this.

json
generator.rs
Copy

_3
{
_3
"drop_ownership_proposal": {}
_3
}

claim_ownership

Used by the newly proposed contract owner to claim contract ownership.

json
generator.rs
Copy

_3
{
_3
"claim_ownership": {}
_3
}

move_to_proxy

Change the current dual rewards proxy for a specific LP token. Only the contract owner can execute this.

json
generator.rs
Copy

_6
{
_6
"move_to_proxy": {
_6
"lp_token": "...",
_6
"proxy": "..."
_6
}
_6
}

ParamsTypeDescription
lp_tokenStringLP token address
proxyStringProxy address

migrate_proxy

Migrates LP tokens and collected rewards to new proxy.

json
generator.rs
Copy

_6
{
_6
"migrate_proxy": {
_6
"lp_token": "...",
_6
"new_proxy": "..."
_6
}
_6
}

ParamsTypeDescription
lp_tokenStringLP token address
new_proxyStringNew proxy address

update_blocked_tokens_list

Add or remove tokens to and from the tokens blocked list. Only the owner contract or generator guardian can execute this.

json
generator.rs
Copy

_6
{
_6
"update_blocked_tokens_list": {
_6
"add": ["...", "...", "..."],
_6
"remove": ["...", "...", "..."]
_6
}
_6
}

ParamsTypeDescription
addOption<Vec<AssetInfo>>LP token address
removeOption<Vec<AssetInfo>>New proxy address

deactivate_pool

Sets the allocation point to zero for specified pool. Only the factory contract can execute this.

json
generator.rs
Copy

_5
{
_5
"deactivate_pool": {
_5
"lp_token": "..."
_5
}
_5
}

ParamsTypeDescription
lp_tokenStringLP token address

deactivate_pools

Sets the allocation point to zero for each pool by the pair type.

json
generator.rs
Copy

_12
{
_12
"deactivate_pools": {
_12
"pair_types": [
_12
{
_12
"xyk": {}
_12
},
_12
{
_12
"stable": {}
_12
}
_12
]
_12
}
_12
}

ParamsTypeDescription
pair_typesVec<PairType>Pair types to deactivate

checkpoint_user_boost

Updates emissions boost for specified generators.

json
generator.rs
Copy

_6
{
_6
"checkpoint_user_boost": {
_6
"generators": ["...", "..."],
_6
"user": "..."
_6
}
_6
}

ParamsTypeDescription
generatorsVec<String>Vector of generator addresses
userOption<String>User address

callback

Process action after the callback

json
generator.rs
Copy

_10
{
_10
"callback": {
_10
"action": {
_10
"claim_rewards": {
_10
"lp_tokens": "...",
_10
"account": "..."
_10
}
_10
}
_10
}
_10
}

ParamsTypeDescription
actionExecuteOnReplyAction to process callback for stored in an ExecuteOnReply enum

ExecuteOnReply

generator.rs
Copy

_26
#[cw_serde]
_26
pub enum ExecuteOnReply {
_26
ClaimRewards {
_26
lp_tokens: Vec<Addr>,
_26
account: Addr,
_26
},
_26
Deposit {
_26
lp_token: Addr,
_26
account: Addr,
_26
amount: Uint128,
_26
},
_26
Withdraw {
_26
lp_token: Addr,
_26
account: Addr,
_26
amount: Uint128,
_26
},
_26
SetTokensPerBlock {
_26
amount: Uint128,
_26
},
_26
MigrateProxy { lp_addr: Addr, new_proxy_addr: Addr },
_26
MigrateProxyDepositLP {
_26
lp_addr: Addr,
_26
prev_proxy_addr: Addr,
_26
amount: Uint128,
_26
},
_26
}

VariantsDescription
ClaimRewardsUpdates reward and returns it to user
DepositStake LP tokens in the Generator to receive token emissions
WithdrawWithdraw LP tokens from the Generator
SetTokensPerBlockSets a new amount of ASTRO to distribute per block between all active generators
MigrateProxyMigrate LP tokens and collected rewards to new proxy
MigrateProxyDepositLPStake LP tokens into new reward proxy

QueryMsg

active_pool_length

Queries the total amount of active generators.

json
generator.rs
Copy

_3
{
_3
"active_pool_length": {}
_3
}

Returns usize

pool_length

Queries the total amount of generators that have been created until now.

json
generator.rs
Copy

_3
{
_3
"pool_length": {}
_3
}

Returns usize

deposit

Queries the amount of a specific LP token that a user currently has staked in the Generator.

json
generator.rs
Copy

_6
{
_6
"deposit": {
_6
"lp_token": "...",
_6
"user": "..."
_6
}
_6
}

ParamsTypeDescription
lp_tokenStringLP token address
userStringUser address

Returns Uint128

user_virtual_amount

Queries the current virtual amount in a specific generator.

json
generator.rs
Copy

_6
{
_6
"user_virtual_amount": {
_6
"lp_token": "...",
_6
"user": "..."
_6
}
_6
}

ParamsTypeDescription
lp_tokenStringLP token address
userStringUser address

Returns Uint128

total_virtual_supply

Queries the total virtual supply of generator.

json
generator.rs
Copy

_5
{
_5
"total_virtual_supply": {
_5
"generator": "..."
_5
}
_5
}

ParamsTypeDescription
generatorStringGenerator address

Returns Uint128

pending_token

Queries the amount of pending ASTRO and 3rd party token rewards that can be claimed by a user that staked a specific LP token.

json
generator.rs
Copy

_6
{
_6
"pending_token": {
_6
"lp_token": "...",
_6
"user": "..."
_6
}
_6
}

ParamsTypeDescription
lp_tokenStringLP token address
userStringUser address

PendingTokenResponse

json
generator.rs
Copy

_4
{
_4
"pending": "1000000",
_4
"pending_on_proxy": "1000000"
_4
}

ParamsTypeDescription
pendingStringThe amount of pending ASTRO
pending_on_proxyOption<Vec<Asset>>The amount of pending 3rd party reward tokens

config

Queries the main Generator contract configuration.

json
generator.rs
Copy

_3
{
_3
"config": {}
_3
}

Config (response)

json
generator.rs
Copy

_29
{
_29
"owner": "terra...",
_29
"factory": "terra...",
_29
"generator_controller": null,
_29
"voting_escrow": null,
_29
"astro_token": "terra...",
_29
"tokens_per_block": "123",
_29
"total_alloc_point": "123",
_29
"allowed_reward_proxies": [
_29
"...",
_29
"...",
_29
"..."
_29
],
_29
"vesting_contract": "...",
_29
"active_pools": [
_29
[
_29
"..."
_29
"123"
_29
],
_29
[
_29
"..."
_29
"123"
_29
]
_29
etc...
_29
],
_29
"blocked_tokens_list": [],
_29
"guardian": null,
_29
"checkpoint_generator_limit": null
_29
}

ParamsTypeDescription
ownerAddrAddress allowed to change contract parameters
factoryAddrThe Factory address
generator_controllerOption<Addr>Contract address which can only set active generators and their alloc points
voting_escrowOption<Addr>The voting escrow contract address
astro_tokenAddrThe ASTRO token address
tokens_per_blockUint128Total amount of ASTRO rewards per block
total_alloc_pointUint128Total allocation points. Must be the sum of all allocation points in all active generators
vesting_contractAddrThe vesting contract from which rewards are distributed
active_poolsVec<(Addr, Uint128)>The list of active pools with allocation points
blocked_tokens_listVec<AssetInfo>The list of blocked tokens
guardianOption<Addr>The guardian address which can add or remove tokens from blacklist
checkpoint_generator_limitOption<u32>The amount of generators

reward_info

Queries information about token emissions for the specified LP token.

json
generator.rs
Copy

_5
{
_5
"reward_info": {
_5
"lp_token": "..."
_5
}
_5
}

ParamsTypeDescription
lp_tokenStringLP token address

RewardInfoResponse

This structure holds the response returned when querying for the token addresses used to reward a specific generator.

json
generator.rs
Copy

_4
{
_4
"base_reward_token": "...",
_4
"proxy_reward_token": "..."
_4
}

ParamsTypeDescription
base_reward_tokenStringThe address of the base reward token
proxy_reward_tokenStringThe address of the 3rd party reward token

orphan_proxy_rewards

Queries the amount of orphaned proxy rewards left behind by emergency withdrawals.

json
generator.rs
Copy

_5
{
_5
"orphan_proxy_rewards": {
_5
"lp_token": "..."
_5
}
_5
}

ParamsTypeDescription
lp_tokenStringLP token address

Returns a vector that contains objects of type (AssetInfo, Uint128)

pool_info

Queries pool information for the specified LP token.

json
generator.rs
Copy

_5
{
_5
"pool_info": {
_5
"lp_token": "..."
_5
}
_5
}

ParamsTypeDescription
lp_tokenStringLP token address

PoolInfoResponse

This structure holds the response returned when querying for a pool's information.

json
generator.rs
Copy

_14
{
_14
"alloc_point": "123",
_14
"astro_tokens_per_block": "123",
_14
"last_reward_block": 1000000,
_14
"current_block": 1000000,
_14
"global_reward_index": "1.2345",
_14
"pending_astro_rewards": "123",
_14
"reward_proxy": null,
_14
"pending_proxy_rewards": null,
_14
"accumulated_proxy_rewards_per_share": [],
_14
"proxy_reward_balance_before_update": "0",
_14
"orphan_proxy_rewards": [],
_14
"lp_supply": "123"
_14
}

ParamsTypeDescription
alloc_pointUint128The slice of ASTRO that this pool's generator gets per block
astro_tokens_per_blockUint128Amount of ASTRO tokens being distributed per block to this LP pool
last_reward_blocku64The last block when token emissions were snapshotted (distributed)
current_blocku64Current block number. Useful for computing APRs off-chain
global_reward_indexDecimalTotal amount of ASTRO rewards already accumulated per LP token staked
pending_astro_rewardsUint128Pending amount of total ASTRO rewards which are claimable by stakers right now
reward_proxyOption<Addr>The address of the 3rd party reward proxy contract
pending_proxy_rewardsOption<Uint128>Pending amount of total proxy rewards which are claimable by stakers right now
accumulated_proxy_rewards_per_shareVec<(Addr, Decimal)>Total amount of 3rd party token rewards already accumulated per LP token staked per proxy
proxy_reward_balance_before_updateUint128Reward balance for the dual rewards proxy before updating accrued rewards
orphan_proxy_rewardsVec<(Addr, Uint128)>The amount of orphan proxy rewards which are left behind by emergency withdrawals and not yet transferred out
lp_supplyUint128Total amount of lp tokens staked in the pool's generator

simulate_future_reward

Queries the amount of ASTRO that will be distributed up to a future block and for a specific LP token.

json
generator.rs
Copy

_6
{
_6
"simulate_future_reward": {
_6
"lp_token": "...",
_6
"future_block": 999
_6
}
_6
}

ParamsTypeDescription
lp_tokenStringLP token addres
future_blocku64Future block

Returns Uint128

pool_stakers

Queries a list of stakers that currently have funds in a specific generator.

json
generator.rs
Copy

_7
{
_7
"pool_stakers": {
_7
"lp_token": "...",
_7
"start_after": "...",
_7
"limit": 5
_7
}
_7
}

ParamsTypeDescription
lp_tokenStringLP token addres
start_afterOption<String>Staker address to start after
limitOption<u32>Amount of stakers to list

Returns a vector that contains objects of type StakerResponse

StakerResponse

This structure holds the parameters used to return information about a staked in a specific generator.

json
generator.rs
Copy

_4
{
_4
"account": "...",
_4
"amount": "123"
_4
}

ParamsTypeDescription
accountStringThe staker's address
amountUint128The amount that the staker currently has in the generator

blocked_tokens_list

Queries the list of blocked tokens.

json
generator.rs
Copy

_3
{
_3
"blocked_tokens_list": {}
_3
}

Returns a vector that contains objects of type AssetInfo

reward_proxies_list

Queries a list of reward proxy contracts which have been ever used.

json
generator.rs
Copy

_3
{
_3
"reward_proxies_list": {}
_3
}

Returns a vector that contains objects of type Addr