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

[VS Incentives]: Implement trackVolume helper #6090

Closed
Tracked by #6057
AlpinYukseloglu opened this issue Aug 17, 2023 · 0 comments · Fixed by #6108
Closed
Tracked by #6057

[VS Incentives]: Implement trackVolume helper #6090

AlpinYukseloglu opened this issue Aug 17, 2023 · 0 comments · Fixed by #6108
Assignees
Labels
F: volume-splitting feat: Volume-splitting incentives

Comments

@AlpinYukseloglu
Copy link
Contributor

AlpinYukseloglu commented Aug 17, 2023

Background

Second step of the volume tracking implementation outlined in this design doc. As a core part of the volume tracking process, I propose we implement the trackVolume abstraction and call it in every swap function in the pool manager module.

Since the process for actually calling this helper in the swap functions will require heavy testing, it is separated out into another issue/PR to keep PRs small and easy to review

Suggested Design

  • While we have gone back and forth on the best way to track volume, I believe the simplest and most modular approach is to simply track all volume in OSMO. This essentially amounts to implementing the following function:
func (k Keeper) trackVolume(ctx sdk.Context, poolId uint64, volumeGenerated sdk.Coin) {
   // Validate that `volumeGenerated`'s denom is one of the denoms in the pool

   // If the denom is BaseDenom/OSMO, call `addVolume` on `volumeGenerated` and return

   // Get the most liquid OSMO-paired pool with `volumeGenerated`'s denom using `GetPoolForDenomPair`

   // Validate that the denoms match (to minimize attack surface if exploit in protorev)

   // Get that pool's spot price (ensuring it's OSMO/nonOSMO)

   // Multiply `volumeGenerated.Amount.ToDec()` by this spot price

   // Run `addVolume` on sdk.NewCoin(OSMO, result) and return
}
  • Notice that this requires us to also implement an addVolume(input sdk.NewCoin) function, which should fetch the existing volume from state (treat as empty if not found), add the input amount to the total, and then set back into state. The key should probably look something like:
"VolumeTrackingPrefix | PoolID |"

Testing Strategy

Tests should follow closely to how swap tests (and especially swap fee tests) are currently conducted.

Test fields:

  • OSMO-paired pool exists
  • Same test fields as swap logic

Test outline:

// Testing strategy:
// 1. If applicable, create an OSMO-paired pool
// 2. Set OSMO-paired pool as canonical for that denom pair in state
// 3. Run `trackVolume` on test input amount (cases include both OSMO and non-OSMO volumes)
// 4. Assert correct amount was added to pool volume

Acceptance Criteria

  • The helper is implemented and thoroughly tested
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: volume-splitting feat: Volume-splitting incentives
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant