Skip to content

Instantly share code, notes, and snippets.

@fxfactorial
Created May 18, 2021 20:35
Show Gist options
  • Save fxfactorial/ec10cc67a16a20591d4518b4551872e3 to your computer and use it in GitHub Desktop.
Save fxfactorial/ec10cc67a16a20591d4518b4551872e3 to your computer and use it in GitHub Desktop.
type Point struct {
GasPriceX *big.Int
EthProfitY *big.Int
}
func (b *Bot) MaxProfitPossible(p1, p2 Point) *big.Int {
rise := new(big.Int).Sub(p2.EthProfitY, p1.EthProfitY)
run := new(big.Int).Sub(p2.GasPriceX, p1.GasPriceX)
slope := new(big.Float).Quo(
new(big.Float).SetInt(rise),
new(big.Float).SetInt(run),
)
intercept := new(big.Float).Sub(
new(big.Float).SetInt(p2.EthProfitY),
new(big.Float).Mul(slope,
new(big.Float).SetInt(p2.GasPriceX)),
)
intercept.Mul(intercept, big.NewFloat(-1))
reciprocoal := new(big.Float).Quo(
new(big.Float).SetInt(run),
new(big.Float).SetInt(rise),
)
thing := new(big.Float).Mul(intercept, reciprocoal)
result := new(big.Int)
thing.Int(result)
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment