Skip to content

Commit

Permalink
Add threshold temp variable
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisngyn committed Dec 17, 2024
1 parent 2200649 commit fcc721d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions pkg/source/limitorder/pool_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,11 @@ func (p *PoolSimulator) calcAmountOutWithSwapInfo(swapSide SwapSide, tokenAmount
// We will often meet edge cases that these orders can be fulfilled by a trading bot or taker on Aggregator.
// From that, the estimated amount out and filled orders are not correct. So we need to add more orders when sending to SC to the executor.
// In this case, we will some orders util total MakingAmount(remainMakingAmount)/estimated amountOut >= 1.3 (130%)
totalAmountOutWeiBigFloat := new(big.Float).SetInt64(totalAmountOutWei.Int64())
totalAmountOutWeiBigFloat := new(big.Float).SetInt(totalAmountOutWei)
// threshold = totalAmountOutWei * FallbackPercentageOfTotalMakingAmount
threshold := new(big.Float).Mul(totalAmountOutWeiBigFloat, FallbackPercentageOfTotalMakingAmount)
for j := i + 1; j < len(orderIDs); j++ {
if new(big.Float).SetInt(totalMakingAmountWei).Cmp(new(big.Float).Mul(totalAmountOutWeiBigFloat, FallbackPercentageOfTotalMakingAmount)) >= 0 {
if new(big.Float).SetInt(totalMakingAmountWei).Cmp(threshold) >= 0 {
break
}
order, ok := p.ordersMapping[orderIDs[j]]
Expand Down
7 changes: 5 additions & 2 deletions pkg/source/limitorder/pool_simulator_calc_amount_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,12 @@ func (p *PoolSimulator) calcAmountInWithSwapInfo(swapSide SwapSide, tokenAmountO
addFilledMakingAmount(filledMakingAmountByMaker, order.Maker, filledMakingAmountWei)
totalFilledTakingAmountWei.Add(totalFilledTakingAmountWei, filledTakingAmountWei)

totalAmountOutWeiBigFloat := new(big.Float).SetInt(totalAmountOutBeforeFee)
// threshold = totalAmountOutBeforeFee * FallbackPercentageOfTotalMakingAmount
threshold := new(big.Float).SetInt(totalAmountOutBeforeFee)
threshold.Mul(threshold, FallbackPercentageOfTotalMakingAmount)

for j := i + 1; j < len(orderIDs); j++ {
if new(big.Float).SetInt(totalMakingAmountWei).Cmp(new(big.Float).Mul(totalAmountOutWeiBigFloat, FallbackPercentageOfTotalMakingAmount)) >= 0 {
if new(big.Float).SetInt(totalMakingAmountWei).Cmp(threshold) >= 0 {
break
}
order, ok := p.ordersMapping[orderIDs[j]]
Expand Down

0 comments on commit fcc721d

Please sign in to comment.