fix slippage

This commit is contained in:
thloyi
2026-04-20 12:31:30 +08:00
parent 1dd843c393
commit fe94888b14
6 changed files with 116 additions and 36 deletions

View File

@@ -193,6 +193,7 @@ func meteoraDammSwapAmountInfo(event string, params *struct {
Amount1 uint64
SwapMode uint8
}) (swapMode SwapMode, fixedAmount decimal.Decimal, limitAmount decimal.Decimal, ok bool) {
_ = event
if params == nil {
return SwapModeUnknown, decimal.Zero, decimal.Zero, false
}
@@ -203,21 +204,14 @@ func meteoraDammSwapAmountInfo(event string, params *struct {
// - ExactIn / PartialFill: amount0=amount_in, amount1=minimum_amount_out
// - ExactOut: amount0=amount_out, amount1=maximum_amount_in
//
// The emitted event is normalized as token A <-> token B:
// - `sell` means A -> B, so A is the input side and B is the output side
// - `buy` means B -> A, so B is the input side and A is the output side
// `SetSwapAmountInfo` derives sides from the normalized buy/sell event, so
// the instruction parameters should stay in raw IDL order here.
switch params.SwapMode {
case 0, 1: // ExactIn / PartialFill
swapMode = SwapModeExactIn
if event == TxEventSell {
return swapMode, decimal.NewFromUint64(params.Amount0), decimal.NewFromUint64(params.Amount1), true
}
return swapMode, decimal.NewFromUint64(params.Amount1), decimal.NewFromUint64(params.Amount0), true
return swapMode, decimal.NewFromUint64(params.Amount0), decimal.NewFromUint64(params.Amount1), true
case 2: // ExactOut
swapMode = SwapModeExactOut
if event == TxEventSell {
return swapMode, decimal.NewFromUint64(params.Amount1), decimal.NewFromUint64(params.Amount0), true
}
return swapMode, decimal.NewFromUint64(params.Amount0), decimal.NewFromUint64(params.Amount1), true
default:
return SwapModeUnknown, decimal.Zero, decimal.Zero, false