Tutorial: Structuring executable messages for Assembly proposals, Part 2: Adding proxy contracts

November 3, 2022
Technical
Tutorial: Structuring executable messages for Assembly proposals, Part 2: Adding proxy contracts

Intro to Proxy Contracts

One of the issues that liquidity providers (LPs) face, is the decision of which platform to provide liquidity to, as the rewards might differ in amount or value. Astroport addresses this problem with special, proxy-based smart contracts that enable simultaneous “dual farming” of ASTRO tokens and governance tokens coming from another community seeking to incentivize LPs.

Rather than depositing Astroport LP tokens directly in third-party staking contracts, LPs can deposit their tokens into one of Astroport’s ASTRO Generators. With the use of proxy contracts, the ASTRO Generators forward LP tokens into relevant third-party staking contracts. Therefore, LPs end up accruing two sets of rewards (both ASTRO and the third-party protocol tokens).

In our previous tutorial, we covered how to structure a proposal message for fine-tuning allocation points. This allows pools to request ASTRO rewards through governance. In this tutorial, we will cover how to integrate proxy contracts. This will allow pools to integrate third-party token rewards. To clarify, these two tutorials combined would allow Assembly members to submit proposals for the following use cases:

  1. Adding ASTRO rewards to a pool (no third-party token rewards)
  2. Adding third-party token rewards to a pool (no ASTRO rewards)
  3. Adding dual rewards to a pool (combining steps 1 and 2)

Additionally, this tutorial assumes that you have 1) created a liquidity mining mechanism to distribute your governance token to LPs in the Astroport pool. And 2) that you have deployed a generator proxy contract specific to your liquidity mining mechanism and Astroport pool.

For new projects that want their liquidity mining mechanism to be integrated with Astroport, the simplest path is basing your liquidity mining contracts on the Mirror design. Alternatively, Anchor’s liquidity mining mechanism is simpler and should not require big changes to the example generator proxy contract.

And for the generator proxy contract, Astroport provides a proxy template that you can customize. Astroport also provides a full example proxy contract designed for the Mirror liquidity mining mechanism.

If you’re ready to integrate proxy contracts, continue on 👇

Code Overview

First, the entire code:

Set-up

Note: This guide uses the pisco-1 testnet. For a complete guide to setting up Terra.js, visit here.

Contract Addresses

We will be using the following 5 testnet addresses below in our proposal. For a full list of mainnet and testnet addresses, look here. Note: The proposal expects a proxy address (your proxy contract must already be deployed).

Custom Functions

We will be using 2 custom functions. The first will allow us to query any contract, the second will allow us to encode our messages in binary format.

Update Generator Config

Next, we use our queryContract custom function to query the generator contract and return its config. The return value is saved to a config variable, which we update by pushing our new proxy address contract.

Allow Proxies Msg (1st Msg)

Currently, if you want to stake LP tokens to a proxy contract you have to:

  1. Allow the proxy contract
  2. Stake LP tokens

This is done in two separate messages which will be combined in our proposal. In this section, we will focus on the first message (allowing the proxy contract). Our msg takes in our updated config variable with our proxy contract address. We encode this message and pass it into our executable message.

Move to Proxy Msg (2nd Msg)

Next, we move our lp tokens to our proxy contract. We encode our message and pass it into our second executable message.

Proposal Msg

Now that we have our proxy messages, we can create a “submit_proposal” message and pass in our messages within an array [allow_proxies_msg, move_to_proxy_msg]. We encode our proposal message and pass our binary into a “send” message that will be sent to the xASTRO contract.

Execute and Broadcast Transaction

Lastly, execute and broadcast the transaction.

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.

Integrating Dual Rewards

So far in this series, we have discussed two types of proposals in isolation — finetuning allocation points (ASTRO rewards) and integrating proxy contracts (third-party token rewards). But how exactly would we implement dual rewards or both proposals at the same time?

First, make sure you go through the entire previous tutorial on allocation points. You will need this to complete the combined message.

Second, you will need to modify our “messages” field under our “submit_proposal” message. Remember, integrating proxy contracts already requires two messages (allowing the proxy contract and staking the LP tokens in the proxy contract). We will be adding a third executable message from our previous tutorial.

You will need to add the executable message itself before your "submit_proposal" message. The ending of your code will look something like this (look through the previous tutorial for the full message):

Third, you will need to update the order of your messages. Since there are 3 messages now, starting with the astro_alloc_message, you will need to update the order of allow_proxies_msg and move_to_proxies_msg to “2” and “3” respectively.

Congrats if you’ve reached this far and have integrated proxy contracts and/or dual rewards.

Stay tuned for further tutorials and docs updates regarding executable messages and proposal types.

✦‍ Follow Astroport on Twitter and subscribe to the Astroport email newsletter to get the latest alerts from the mothership.‍

DISCLAIMER

Remember, Terra 2.0 and Astroport are experimental technologies. This article does not constitute investment advice and is subject to and limited by the Astroport disclaimers, which you should review before interacting with the protocol.

Previous post

There are no previous posts

<- Back to all posts
Next post

There are no next posts

<- Back to all posts