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

F/rewards distribution send #96

Merged
merged 29 commits into from
Jan 4, 2025
Merged

F/rewards distribution send #96

merged 29 commits into from
Jan 4, 2025

Conversation

maurolacy
Copy link
Contributor

@maurolacy maurolacy commented Dec 10, 2024

#97 follow-up. Sends the rewards along with the distribution table to Babylon using ICS-20 with a json payload in the Memo field.

Comment on lines 287 to 288
// Route to babylon over IBC
let channel = IBC_CHANNEL.load(deps.storage)?;
Copy link
Member

Choose a reason for hiding this comment

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

Hmm I guess IBC_CHANNEL is the channel that this contract involves, but not necessarily a channel for IBC transfer. Probably we need to confirm this in some e2e test.

Maybe as a part of the integration, one needs to establish an IBC channel for interchain transfer, and the contract side needs to remember this channel ID in the config, for facilitating the reward mechanism.

Copy link
Contributor Author

@maurolacy maurolacy Dec 11, 2024

Choose a reason for hiding this comment

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

Yes, this was my suspicion as well. Implemented it this way for simplicity. Perhaps we can configure a single channel to do / support both, custom messages and ICS20 transfers?

Will write an e2e test and confirm this in any case.

Copy link
Contributor Author

@maurolacy maurolacy Dec 18, 2024

Choose a reason for hiding this comment

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

Was finally able to e2e test this.

Using a single channel doesn't work, as CosmWasm's IbcMsg::Transfer requires an established channel against the ibctransfer module, not the contract address under wasm.

I think this is a design decision that makes sense, as in general you don't want to establish a channel for every contract that needs / wants to use ICS20 transfers.

Update: Ref.: https://github.com/CosmWasm/cosmwasm/blob/4da538debc73065f9aa8f489895cb54393db0f7c/packages/std/src/ibc.rs#L26-L54

Copy link
Member

Choose a reason for hiding this comment

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

Using a single channel doesn't work, as CosmWasm's IbcMsg::Transfer requires an established channel against the ibctransfer module, not the contract address under wasm.

Yes that's right, even though we can wire up a IBC transfer packet in the contract side, babylon side's zone concerige won't recognise it.

If we really, really want to let zone concerige handle IBC tansfer, then zone concierge has to invoke IBC transfer module (in particular this code snippet) to handle the IBC transfer packets. But I'm not sure if it's worth it

So I'd recommend we consider consolidating IBC channels as future work, and for now start with having 2 IBC channels. This also creates a clean separation between channels' functionalities following IBC channels' best practices

@maurolacy maurolacy force-pushed the f/rewards-distribution-send branch from 961ca90 to da5dbc2 Compare December 11, 2024 10:47
@maurolacy maurolacy changed the base branch from f/rewards-distribution to f/rewards-distribution-2 December 11, 2024 11:06
@maurolacy maurolacy force-pushed the f/rewards-distribution-2 branch from 934aabc to 5a3698e Compare December 15, 2024 16:07
@maurolacy maurolacy force-pushed the f/rewards-distribution-send branch from da5dbc2 to 54e733f Compare December 16, 2024 07:26
Base automatically changed from f/rewards-distribution-2 to main December 16, 2024 07:44
@maurolacy maurolacy force-pushed the f/rewards-distribution-send branch 2 times, most recently from da78c91 to e528d44 Compare December 16, 2024 16:33
@maurolacy maurolacy changed the base branch from main to f/btc-lc-feature December 16, 2024 16:33
@maurolacy maurolacy force-pushed the f/rewards-distribution-send branch 2 times, most recently from 9455a91 to cb8e897 Compare December 22, 2024 21:03
@@ -632,14 +632,20 @@ pub fn distribute_rewards(deps: &mut DepsMut, env: &Env) -> Result<(), ContractE
};
// Get the voting power of the active FPS
let total_voting_power = active_fps.iter().map(|fp| fp.power as u128).sum::<u128>();
// Get the rewards to distribute (bank balance of the finality contract)
// Get the rewards to distribute (bank balance of the finality contract minus already distributed rewards)
let distributed_rewards = TOTAL_REWARDS.load(deps.storage)?;
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to get the total reward by querying the contract's balance, rather than tracking it in a Kv store?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem with this is, that TOTAL_REWARDS are the rounded sum of the distributed rewards over finality providers. They are not necessarily the same. With this impl, we left the remainder in the balance, and it'll be distributed later eventually. Better than send an amount that doesn't match the sum of the distributed rewards, IMO.

@maurolacy maurolacy force-pushed the f/rewards-distribution-send branch from a8e320c to f42067d Compare January 3, 2025 16:18
@maurolacy maurolacy changed the base branch from f/btc-lc-feature to main January 3, 2025 16:19
@maurolacy
Copy link
Contributor Author

Merging as approved. Please take a look at recent changes (IBC transfer channel info) and comment back in any case.

TODOs (custom rewards distribution protocol) will be done in follow-up PRs.

@maurolacy maurolacy merged commit 9fdc9a1 into main Jan 4, 2025
@maurolacy maurolacy deleted the f/rewards-distribution-send branch January 4, 2025 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants