Skip to content

Commit

Permalink
Merge pull request #9 from c-osmosis/junho
Browse files Browse the repository at this point in the history
Error fix
  • Loading branch information
Thunnini authored Oct 18, 2020
2 parents fdc0947 + 0dabe59 commit d55f82d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
20 changes: 14 additions & 6 deletions x/gamm/keeper/pool/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,13 @@ func (p poolService) SwapExactAmountIn(
return sdk.Dec{}, sdk.Dec{}, types.ErrMathApprox
}

pool.Records[tokenIn.Denom].Balance.Add(tokenAmountIn)
pool.Records[tokenOut.Denom].Balance.Sub(sdk.Int(tokenAmountOut))
p.store.SetStore(ctx, pool)
inRecord.Balance = inRecord.Balance.Add(tokenAmountIn)
pool.Records[tokenIn.Denom] = inRecord

outRecord.Balance = outRecord.Balance.Sub(sdk.Int(tokenAmountOut))
pool.Records[tokenOut.Denom] = outRecord

p.store.StorePool(ctx, pool)

return tokenAmountOut, spotPriceAfter, nil
}
Expand Down Expand Up @@ -489,9 +493,13 @@ func (p poolService) SwapExactAmountOut(
return sdk.Dec{}, sdk.Dec{}, types.ErrMathApprox
}

pool.Records[tokenIn.Denom].Balance.Add(sdk.Int(tokenAmountIn))
pool.Records[tokenOut.Denom].Balance.Sub(tokenAmountOut)
p.store.SetStore(ctx, pool)
inRecord.Balance = inRecord.Balance.Add(sdk.Int(tokenAmountIn))
pool.Records[tokenIn.Denom] = inRecord

outRecord.Balance = outRecord.Balance.Sub(tokenAmountOut)
pool.Records[tokenOut.Denom] = outRecord

p.store.StorePool(ctx, pool)

return tokenAmountIn, spotPriceAfter, nil
}
8 changes: 0 additions & 8 deletions x/gamm/keeper/pool/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
type Store interface {
GetNextPoolNumber(sdk.Context) uint64

SetStore(sdk.Context, types.Pool)

StorePool(sdk.Context, types.Pool)
FetchPool(sdk.Context, uint64) (types.Pool, error)
DeletePool(sdk.Context, uint64)
Expand All @@ -35,12 +33,6 @@ func (ps poolStore) getStore(ctx sdk.Context) prefix.Store {
return prefix.NewStore(ctx.KVStore(ps.storeKey), types.PoolPrefix)
}

func (ps poolStore) SetStore(ctx sdk.Context, pool types.Pool) {
store := ctx.KVStore(ps.storeKey)
bz := ps.cdc.MustMarshalBinaryBare(&pool)
store.Set(utils.Uint64ToBytes(pool.Id), bz)
}

func (ps poolStore) GetNextPoolNumber(ctx sdk.Context) uint64 {
var poolNumber uint64
store := ctx.KVStore(ps.storeKey)
Expand Down

0 comments on commit d55f82d

Please sign in to comment.