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

bug (perp): can't open position on master when there's more than 1 vpool #922

Closed
matthiasmatt opened this issue Sep 15, 2022 · 0 comments · Fixed by #925
Closed

bug (perp): can't open position on master when there's more than 1 vpool #922

matthiasmatt opened this issue Sep 15, 2022 · 0 comments · Fixed by #925
Assignees

Comments

@matthiasmatt
Copy link
Contributor

On master currently opening a position is broken if there's more than one vpool. The tx fails with the message error updating reserve: price is over fluctuation limit.

Reason is that the checkFluctuationLimitRatio function look for a snapshot to compare with, but the GetLatestReserveSnapshot function returns a random vpool snapshot:

// GetLatestReserveSnapshot returns the last snapshot that was saved
func (k Keeper) GetLatestReserveSnapshot(ctx sdk.Context, pair common.AssetPair) (
	snapshot types.ReserveSnapshot, err error,
) {
	store := prefix.NewStore(ctx.KVStore(k.storeKey), types.SnapshotsKeyPrefix)
	iter := store.ReverseIterator(nil, nil)

	defer iter.Close()

	for ; iter.Valid(); iter.Next() {
		k.codec.MustUnmarshal(iter.Value(), &snapshot)
		return snapshot, nil
	}

	return types.ReserveSnapshot{}, types.ErrNoLastSnapshotSaved
}

This results on using the eth:usd vpool to check the fluctuation limit of the btc:usd vpool:

price 20000.000000004000000000
lastPrice 1500.001500001500001500
upperLimit 1650.001650001650001650
lowerLimit 1350.001350001350001350
price.GT(upperLimit) true
price.LT(lowerLimit) false
@matthiasmatt matthiasmatt added this to the Testnet V1 milestone Sep 15, 2022
@matthiasmatt matthiasmatt self-assigned this Sep 15, 2022
@matthiasmatt matthiasmatt linked a pull request Sep 15, 2022 that will close this issue
@NibiruHeisenberg NibiruHeisenberg linked a pull request Sep 16, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants