Astroport
Search…
⌃K

Fine-tuning Allocation Points

In this tutorial, we will cover fine-tuning allocation points for pools. These are pools that receive ASTRO emissions every block.

Code Overview

index.js
// setup
const { LCDClient, MnemonicKey, MsgExecuteContract } = require('@terra-money/terra.js');
async function main() {
const terra = new LCDClient({
URL: 'https://pisco-lcd.terra.dev',
chainID: 'pisco-1',
});
const mk = new MnemonicKey({
mnemonic: ''
});
const wallet = terra.wallet(mk);
// contract addresses (testnet)
const assembly_address = 'terra195m6n5xq4rkjy47fn5y3s08tfmj3ryknj55jqvgq2y55zul9myzsgy06hk';
const xastro_address = 'terra1ctzthkc0nzseppqtqlwq9mjwy9gq8ht2534rtcj3yplerm06snmqfc5ucr';
const generator_address = 'terra1ksvlfex49desf4c452j6dewdjs6c48nafemetuwjyj6yexd7x3wqvwa7j9';
// custom functions
function toEncodedBinary(object) {
return Buffer.from(JSON.stringify(object)).toString('base64');
}
// generator msg
const generator_msg = {
"setup_pools": {
"pools": [
("lp_token_address", "1000"),
("lp_addr2", "10"),
... etc
]
}
}
const generator_binary = toEncodedBinary(generator_msg)
const proposal_msgs = [
{
order: "1",
msg: {
wasm: {
execute: {
contract_addr: generator_address,
msg: generator_binary,
funds: []
}
}
}
}
]
// proposal msg
const proposal_msg = {
"submit_proposal": {
"title": "testing",
"description": "testing",
"link": null,
"messages": proposal_msgs
}
}
const proposal_binary = toEncodedBinary(proposal_msg)
const msg = {
"send": {
"contract": assembly_address,
"amount": "30000000000",
"msg": proposal_binary
}
}
// execute and broadcast transaction
const execute = new MsgExecuteContract(
wallet.key.accAddress,
xastro_address,
msg,
);
const executeTx = await wallet.createAndSignTx({
msgs: [execute]
})
.then(tx => terra.tx.broadcast(tx))
.then((data) => console.log(result.txhash));
}
main().catch(console.error)

Step-by-Step

Set up

Note: This guide uses the pisco-1 testnet. For a complete guide to setting up Terra.js, visit here.
index.js
const { LCDClient, MnemonicKey, MsgExecuteContract } = require('@terra-money/terra.js');
async function main() {
const terra = new LCDClient({
URL: 'https://pisco-lcd.terra.dev',
chainID: 'pisco-1',
});
const mk = new MnemonicKey({
mnemonic: ''
});
const wallet = terra.wallet(mk);

Contract Addresses

We will be using the following 3 testnet addresses below in our proposal. For a full list of mainnet and testnet addresses, visit here.
index.js
const assembly_address = 'terra195m6n5xq4rkjy47fn5y3s08tfmj3ryknj55jqvgq2y55zul9myzsgy06hk';
const xastro_address = 'terra1ctzthkc0nzseppqtqlwq9mjwy9gq8ht2534rtcj3yplerm06snmqfc5ucr';
const generator_address = 'terra1ksvlfex49desf4c452j6dewdjs6c48nafemetuwjyj6yexd7x3wqvwa7j9';

Custom Functions

We will be using a custom function to encode our messages in binary format.
index.js
function toEncodedBinary(object) {
return Buffer.from(JSON.stringify(object)).toString('base64');
}

Generator Msg

The Generator contract allocates token rewards (ASTRO) for various LP tokens and distributes them pro-rata to LP stakers. The setup_pools endpoint within the Generator contract creates a new list of pools with allocation points and updates the contract’s config. pools is a vector that contains LP token addresses and allocation points.
Lastly, we use our toEncodedBinary function to encode our message and pass the binary into our executable message.
index.js
const generator_msg = {
"setup_pools": {
"pools": [
("lp_token_address", "1000"),
("lp_addr2", "10"),
... etc
]
}
}
const generator_binary = toEncodedBinary(generator_msg)
const proposal_msgs = [
{
order: "1",
msg: {
wasm: {
execute: {
contract_addr: generator_address,
msg: generator_binary,
funds: []
}
}
}
}
]

Proposal Msg

Now that we have our proxy messages, we can create a submit_proposal message and pass in our message. We encode our proposal message and pass our binary into a send message that will be sent to the xASTRO contract.
index.js
const proposal_msg = {
"submit_proposal": {
"title": "testing",
"description": "testing",
"link": null,
"messages": proposal_msgs
}
}
const proposal_binary = toEncodedBinary(proposal_msg)
const msg = {
"send": {
"contract": assembly_address,
"amount": "30000000000",
"msg": proposal_binary
}
}

Execute and Broadcast Transaction

Lastly, execute and broadcast the transaction.
index.js
const execute = new MsgExecuteContract(
wallet.key.accAddress,
xastro_address,
msg,
);
const executeTx = await wallet.createAndSignTx({
msgs: [execute]
})
.then(tx => terra.tx.broadcast(tx))
.then((data) => console.log(result.txhash));
}
main().catch(console.error)
That’s it! Simply use the command line and node.js to execute the script and retrieve the transaction hash along with other information such as the proposal id.