Skip to content

Commit

Permalink
fix SampleImpactAsk and SampleImpactBid
Browse files Browse the repository at this point in the history
  • Loading branch information
vipulsharma21 committed Aug 31, 2023
1 parent b292714 commit a396fbc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions precompile/contracts/juror/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2200,7 +2200,8 @@ func TestSampleImpactBid(t *testing.T) {
}
unfulFilledQuote := big.NewInt(0).Sub(impactMarginNotional, filledQuote)
fmt.Println("unfulFilledQuote", unfulFilledQuote, "totalBaseQ", totalBaseQ, "filledQuote", filledQuote)
baseQAtTick := big.NewInt(0).Div(big.NewInt(0).Mul(unfulFilledQuote, big.NewInt(1e6)), bids[3])
// as quantity is in 1e18 baseQ = price * 1e18 / price
baseQAtTick := big.NewInt(0).Div(big.NewInt(0).Mul(unfulFilledQuote, big.NewInt(1e18)), bids[3])
expectedOutput := big.NewInt(0).Div(big.NewInt(0).Mul(impactMarginNotional, big.NewInt(1e18)), big.NewInt(0).Add(totalBaseQ, baseQAtTick))
assert.Equal(t, expectedOutput, output)
})
Expand Down Expand Up @@ -2300,7 +2301,7 @@ func TestSampleImpactAsk(t *testing.T) {
filledQuote.Add(filledQuote, (divideTwoBigInts(multiplyTwoBigInts(asks[i], size), big.NewInt(1e18))))
}
unfulFilledQuote := big.NewInt(0).Sub(impactMarginNotional, filledQuote)
baseQAtTick := big.NewInt(0).Div(big.NewInt(0).Mul(unfulFilledQuote, big.NewInt(1e6)), asks[3])
baseQAtTick := big.NewInt(0).Div(big.NewInt(0).Mul(unfulFilledQuote, big.NewInt(1e18)), asks[3])
expectedOutput := big.NewInt(0).Div(big.NewInt(0).Mul(impactMarginNotional, big.NewInt(1e18)), big.NewInt(0).Add(totalBaseQ, baseQAtTick))
assert.Equal(t, expectedOutput, output)
})
Expand Down
4 changes: 2 additions & 2 deletions precompile/contracts/juror/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func SampleImpactBid(bibliophile b.BibliophileClient, ammAddress common.Address)
if tick.Sign() == 0 {
return big.NewInt(0).Div(big.NewInt(0).Mul(accNotional, big.NewInt(1e18)), accBaseQ)
}
baseQAtTick := new(big.Int).Div(new(big.Int).Mul(new(big.Int).Sub(impactMarginNotional, accNotional), big.NewInt(1e6)), tick)
baseQAtTick := new(big.Int).Div(new(big.Int).Mul(new(big.Int).Sub(impactMarginNotional, accNotional), big.NewInt(1e18)), tick)
return new(big.Int).Div(new(big.Int).Mul(impactMarginNotional, big.NewInt(1e18)), new(big.Int).Add(baseQAtTick, accBaseQ))
}

Expand Down Expand Up @@ -479,7 +479,7 @@ func SampleImpactAsk(bibliophile b.BibliophileClient, ammAddress common.Address)
if tick.Sign() == 0 {
return big.NewInt(0).Div(big.NewInt(0).Mul(accNotional, big.NewInt(1e18)), accBaseQ)
}
baseQAtTick := new(big.Int).Div(new(big.Int).Mul(new(big.Int).Sub(impactMarginNotional, accNotional), big.NewInt(1e6)), tick)
baseQAtTick := new(big.Int).Div(new(big.Int).Mul(new(big.Int).Sub(impactMarginNotional, accNotional), big.NewInt(1e18)), tick)
return new(big.Int).Div(new(big.Int).Mul(impactMarginNotional, big.NewInt(1e18)), new(big.Int).Add(baseQAtTick, accBaseQ))
}

Expand Down

0 comments on commit a396fbc

Please sign in to comment.