Skip to content

Commit

Permalink
feat: uni-directional trading pair taker fee support (sqs ingester) (#…
Browse files Browse the repository at this point in the history
…8690)

* bidirectional taker fee support on sqs

* lint

* Removed outdated comment in ingest/sqs/pools/transformer/taker_fee.go

Co-authored-by: Matt, Park <45252226+mattverse@users.noreply.github.com>

---------

Co-authored-by: Matt, Park <45252226+mattverse@users.noreply.github.com>
  • Loading branch information
cryptomatictrader and mattverse authored Sep 11, 2024
1 parent 0a76887 commit 9d103ce
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions ingest/sqs/pools/transformer/taker_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,27 @@ import (
)

// retrieveTakerFeeToMapIfNotExists retrieves the taker fee for the denom pair if it does not exist in the map
// Mutates the map with the taker fee for every uniquer denom pair in the denoms list.
// Mutates the map with the taker fee for every uniquer denom pair combination in the denoms list.
// Since bi-directional taker fee is supported, the taker fee for a denom pair is stored in both directions.
// For example, the taker fees for a pair of denoms (A, B) is stored BOTH as (A, B) and (B, A).
// If the taker fee for a denom pair already exists in the map, it is not retrieved again.
// Note that the denoms in denomPair must always be lexicographically sorted to avoid duplicates.
// Returns error if fails to retrieve taker fee from chain. Nil otherwise
func retrieveTakerFeeToMapIfNotExists(ctx sdk.Context, denoms []string, denomPairToTakerFeeMap sqsdomain.TakerFeeMap, poolManagerKeeper commondomain.PoolManagerKeeper) error {
for i, denomI := range denoms {
for j := i + 1; j < len(denoms); j++ {
if !denomPairToTakerFeeMap.Has(denomI, denoms[j]) {
takerFee, err := poolManagerKeeper.GetTradingPairTakerFee(ctx, denomI, denoms[j])
if err != nil {
// This error should not happen. As a result, we do not skip it
return err
}
for j, denomJ := range denoms {
if i != j {
if !denomPairToTakerFeeMap.Has(denomI, denomJ) {
takerFee, err := poolManagerKeeper.GetTradingPairTakerFee(ctx, denomI, denomJ)
if err != nil {
// This error should not happen. As a result, we do not skip it
return err
}

denomPairToTakerFeeMap.SetTakerFee(denomI, denoms[j], takerFee)
denomPairToTakerFeeMap.SetTakerFee(denomI, denomJ, takerFee)
}
}
}
}

return nil
}

0 comments on commit 9d103ce

Please sign in to comment.