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

feat: allow rewards to be paid in any currency #860

Merged
merged 2 commits into from
Jan 18, 2023

Conversation

gregdhill
Copy link
Member

@gregdhill gregdhill commented Jan 17, 2023

Signed-off-by: Gregory Hill [email protected]

An oversight required for #826 to pay rewards in all currencies, otherwise we would get undefined results when distributing currencies that were not KINT/INTR or kBTC/iBTC. I have not updated the staking pallet since this is only required for farming rewards, Vaults are unaffected.

I wanted to simply iterate over the currencies in RewardPerToken but there was no way to do that just for the first key / prefix so the complexity for collecting and de-duplicating that list would be too great. Instead I have added a new storage value for all the reward currencies.

See also: paritytech/substrate#13162

@sander2
Copy link
Member

sander2 commented Jan 17, 2023

I wanted to simply iterate over the currencies in RewardPerToken but there was no way to do that just for the first key / prefix

Can't you use https://github.com/paritytech/substrate/blob/f7e53fe1a8c0e15604cc30177c312241624831bf/frame/support/src/storage/types/double_map.rs#L319 ?

@sander2
Copy link
Member

sander2 commented Jan 17, 2023

Hmm vault rewards iteration will remain unchanged, but I'm a little bit worried that this may result in a lot of unnecessary iteration in for amm farming rewards. It's not unthinkable that each pool will have some reward for each of the currencies in the pool, so it adds up.. Maybe we should have the rewards api functions take an explicit vec of reward currencies? Or perhaps a config trait item that gets the reward currencies for the given item

@gregdhill
Copy link
Member Author

Hmm vault rewards iteration will remain unchanged, but I'm a little bit worried that this may result in a lot of unnecessary iteration in for amm farming rewards. It's not unthinkable that each pool will have some reward for each of the currencies in the pool, so it adds up.. Maybe we should have the rewards api functions take an explicit vec of reward currencies? Or perhaps a config trait item that gets the reward currencies for the given item

In practice I don't think it will be so bad but we should definitely parameterize the weights here at some point. The point of this approach is that you would not need to do a runtime upgrade every time we add a rewards currency, besides this would only add an additional loop when we start using a rewards currency which is required regardless.

@sander2
Copy link
Member

sander2 commented Jan 17, 2023

besides this would only add an additional loop when we start using a rewards currency which is required regardless.

A loop is necessary, but the loop doesn't necessarily need to be over all currencies, right? If LpToken(DOT, IBTC) has rewards in DOT and IBTC, and LpToken(INTR, MOVR) has rewards in INTR and MOVR, then when you operate on the LpToken(DOT, IBTC) token, there is no need to iterate over INTR and MOVR

In practice I don't think it will be so bad

Maybe you're right, idk. That depends on how many pools with how many rewards we'll launch, and on what period we use for reward distribution. It's a lot more scalable when you don't iterate over all currencies but maybe it's premature optimization..

@gregdhill
Copy link
Member Author

A loop is necessary, but the loop doesn't necessarily need to be over all currencies, right? If LpToken(DOT, IBTC) has rewards in DOT and IBTC, and LpToken(INTR, MOVR) has rewards in INTR and MOVR, then when you operate on the LpToken(DOT, IBTC) token, there is no need to iterate over INTR and MOVR

Ah yeah that is true, maybe this RewardCurrencies storage value can instead be a map over each pool id? Although that does increase the storage cost vs the computational complexity.

@sander2 sander2 merged commit 3519e07 into interlay:master Jan 18, 2023
@gregdhill gregdhill deleted the feat/reward-currencies branch January 18, 2023 10:55
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