diff --git a/pkg/source/kyber-pmm/pool_simulator.go b/pkg/source/kyber-pmm/pool_simulator.go index 0e9bc74c3..cc81a01e2 100644 --- a/pkg/source/kyber-pmm/pool_simulator.go +++ b/pkg/source/kyber-pmm/pool_simulator.go @@ -135,7 +135,7 @@ func (p *PoolSimulator) CalcAmountOut( inventoryLimit = limit.GetLimit(p.baseToken.Address) } - if result.TokenAmountOut.Amount.Cmp(inventoryLimit) > 0 { + if inventoryLimit != nil && result.TokenAmountOut.Amount.Cmp(inventoryLimit) > 0 { return nil, errors.New("not enough inventory") } return result, nil @@ -349,12 +349,13 @@ func NewInventory(balance map[string]*big.Int) *Inventory { } // GetLimit returns a copy of balance for the token in Inventory +// return nil if there is no limit func (i *Inventory) GetLimit(tokenAddress string) *big.Int { i.lock.RLock() defer i.lock.RUnlock() balance, avail := i.Balance[tokenAddress] if !avail { - return big.NewInt(0) + return nil } return big.NewInt(0).Set(balance) } diff --git a/pkg/source/pool/swap_limit.go b/pkg/source/pool/swap_limit.go index 829d95cc9..cd78f9b64 100644 --- a/pkg/source/pool/swap_limit.go +++ b/pkg/source/pool/swap_limit.go @@ -6,6 +6,7 @@ import "math/big" // i.e: SwapLimit must be something affect multiple pools once it is change. type SwapLimit interface { // GetLimit return a limit for a certain key. Normally each dex will have different limit values + // return nil in case there is no limit // For example: PMM's key is token's string and its value is the inventory's balance of that token GetLimit(key string) *big.Int // UpdateLimit update both limits for a trade (assuming each trade is from 1 token to another token) diff --git a/pkg/source/synthetix/pool_simulator.go b/pkg/source/synthetix/pool_simulator.go index a8e824ef8..18562b764 100644 --- a/pkg/source/synthetix/pool_simulator.go +++ b/pkg/source/synthetix/pool_simulator.go @@ -110,7 +110,7 @@ func (p *PoolSimulator) CalcAmountOut( if synthetixTradeVolume != nil { allowedVol := limit.GetLimit(strconv.FormatUint(p.poolState.BlockTimestamp, 10)) - if allowedVol.Cmp(synthetixTradeVolume) < 0 { + if allowedVol != nil && allowedVol.Cmp(synthetixTradeVolume) < 0 { return nil, ErrSurpassedVolumeLimit } } @@ -230,6 +230,9 @@ func (p *PoolSimulator) GetPoolStateVersion() PoolStateVersion { } func (p *PoolSimulator) CalculateLimit() map[string]*big.Int { + if p.poolState.AtomicMaxVolumePerBlock == nil { + return nil + } var ( s = p.poolState maxVol = big.NewInt(0).Set(p.poolState.AtomicMaxVolumePerBlock) @@ -259,12 +262,13 @@ func NewLimits(atomicMaxVolumePerBlocks map[string]*big.Int) pool.SwapLimit { } // GetLimit returns a copy of balance for the token in Inventory + func (i *AtomicLimits) GetLimit(blockTimeStamp string) *big.Int { i.lock.RLock() defer i.lock.RUnlock() balance, avail := i.Limits[blockTimeStamp] if !avail { - return big.NewInt(0) + return nil } return big.NewInt(0).Set(balance) }