Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phase 2: auto-trade reward token revenue via routes in params #955

Merged
merged 34 commits into from
Dec 9, 2023

Conversation

ethan-stride
Copy link
Contributor

@ethan-stride ethan-stride commented Oct 16, 2023

This PR is the logic for phase 2 of the community pools where foreign ibc denoms can be treated as revenue.

Tech Spec and Diagrams

https://docs.google.com/document/d/1U9ah95DABkg_ofSGgkDnhzr4wyJdHCCBExCKCX-t_WM/edit
https://app.excalidraw.com/l/9UFOCMAZLAI/2ErXWeealJE

Phase 2: Automatically convert revenue of foreign "reward" denom to host denom

There are 4 logical steps kicked off by epochly triggered ICQs:

  1. ICQ the reward denom in the withdrawal address on hostZone, transfer all found tokens with unwinding through the reward chain to a trade ICA on the trade chain (Osmosis). ICQ is number 1 in the excalidraw, transfer is number 2.
  2. ICQ the reward denom in the trade ICA, callback fires ICA messages to perform a swap to the host chain's denom up to the allowed max swap size. ICQ is number 3 in the excalidraw, swap ICA is number 4.
  3. ICQ the host chain denom in the trade ICA, transfer all found tokens back to the withdrawal ICA on the hostZone. ICQ is number 5 in the excalidraw, transfer is number 6.

The first and last ICQs here are done on a stride epoch cadence, because the swap is limited by a max swap size to prevent slippage, the swaps can happen in smaller more frequent triggers so the middle ICQ is done on an hourly cadence.

Also for safety, a min acceptable output amount is computed using the last known swap price. There is an independent hourly ICQ to get this "spot price" for the pool (which is a ratio of input to output denom in that pool) and this value is persisted to the TradeConfig type inside the TradeRoute information on the keeper state. Swaps use whatever value is found (which could be up to 1 hour out of date) when computing the minimum expected output for the swap. If a swap fails, the tokens just remain in the trade ICA and will be attempted again on the next epochly call to the swap action.

There are governance gated transactions to create, delete, and update the TradeRoute data stored on the keeper state. The most common expected use case is to update which pool the TradeRoute uses to do the swap or to change the max swap size.

Testing

bash ./dockernet/tests/run_all_tests.sh
integration_tests.bats
 ✓ [INTEGRATION-BASIC-GAIA] host zones successfully registered
 ✓ [INTEGRATION-BASIC-GAIA] ibc transfer updates all balances
 ✓ [INTEGRATION-BASIC-GAIA] liquid stake mint and transfer
 ✓ [INTEGRATION-BASIC-GAIA] tokens on GAIA were staked
 ✓ [INTEGRATION-BASIC-GAIA] LSM liquid stake
 ✓ [INTEGRATION-BASIC-GAIA] LSM liquid stake with slash query
 ✓ [INTEGRATION-BASIC-GAIA] packet forwarding automatically liquid stakes
 ✓ [INTEGRATION-BASIC-GAIA] redemption works
 ✓ [INTEGRATION-BASIC-GAIA] claimed tokens are properly distributed
 ✓ [INTEGRATION-BASIC-GAIA] rewards are being reinvested, exchange rate updating
 ✓ [INTEGRATION-BASIC-GAIA] rewards are being distributed to stakers

11 tests, 0 failures

@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

@github-actions github-actions bot added the Stale label Oct 31, 2023
@github-actions github-actions bot closed this Nov 7, 2023
@sampocs
Copy link
Collaborator

sampocs commented Nov 8, 2023

open

@sampocs sampocs reopened this Nov 8, 2023
@github-actions github-actions bot removed the Stale label Nov 9, 2023
ethan-stride and others added 2 commits November 20, 2023 05:38
Co-authored-by: sampocs <sam@stridelabs.co>
Co-authored-by: sampocs <sam.pochyly@gmail.com>
@sampocs sampocs changed the base branch from community-pool-revenue-staking to main November 21, 2023 20:25
Copy link
Collaborator

@sampocs sampocs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautifully done once again!!

One larger open question - should we handle the case where the price query fails? Would be a bit messy to keep track of how recent it is, but I'd be worried of the case where we just keeping using a stale value.

Feels like our options are:

  • Include no staleness check
  • Include a staleness check (would require additional state to track when the price was last updated)
  • Update the price to indicate if the query failed (e.g. set it to zero/nil)

x/stakeibc/keeper/reward_converter.go Outdated Show resolved Hide resolved
x/stakeibc/keeper/hooks.go Outdated Show resolved Hide resolved
x/stakeibc/keeper/reward_converter.go Outdated Show resolved Hide resolved
x/stakeibc/keeper/reward_converter.go Outdated Show resolved Hide resolved
x/stakeibc/keeper/reward_converter.go Outdated Show resolved Hide resolved
@github-actions github-actions bot added C:CLI C:proto C:stakeibc dependencies Pull requests that update a dependency file T:build labels Nov 27, 2023
@github-actions github-actions bot removed the dependencies Pull requests that update a dependency file label Nov 27, 2023
@sampocs sampocs added the v17 label Dec 6, 2023
Copy link
Collaborator

@sampocs sampocs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢!

@sampocs sampocs merged commit 0abf3ea into main Dec 9, 2023
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants