-
Notifications
You must be signed in to change notification settings - Fork 561
/
taker_fee.go
31 lines (26 loc) · 1.2 KB
/
taker_fee.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package poolsingester
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/osmosis-labs/sqs/sqsdomain"
"github.com/osmosis-labs/osmosis/v23/ingest/sqs/domain"
)
// 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.
// 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 domain.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
}
denomPairToTakerFeeMap.SetTakerFee(denomI, denoms[j], takerFee)
}
}
}
return nil
}