Files
pump-parser/budget.go

48 lines
1.2 KiB
Go
Raw Normal View History

2025-11-20 17:56:45 +08:00
package pump_parser
import (
"encoding/binary"
"github.com/shopspring/decimal"
)
type setComputeData struct {
Units uint64
}
2025-11-21 12:01:44 +08:00
func budgetParser(tx *Tx, instr Instruction, _ InnerInstructions, offset [2]uint) ([2]uint, error) {
2025-11-20 17:56:45 +08:00
if offset[1] != 0 {
return increaseOffset(offset), nil
}
2025-11-21 12:01:44 +08:00
decode := instr.Data
2025-11-20 17:56:45 +08:00
discriminator := decode[0]
switch discriminator {
case setComputeUnitLimitDiscriminator:
2025-11-21 12:01:44 +08:00
return computeUnitLimitParser(offset, tx, decode[1:])
2025-11-20 17:56:45 +08:00
case setComputeUnitPriceDiscriminator:
2025-11-21 12:01:44 +08:00
return computeUnitPriceParser(offset, tx, decode[1:])
2025-11-20 17:56:45 +08:00
default:
return increaseOffset(offset), nil
}
}
2026-02-11 17:49:43 +08:00
func computeUnitLimitParser(offset [2]uint, tx *Tx, decodedData []byte) ([2]uint, error) {
if len(decodedData) < 4 {
2025-11-20 17:56:45 +08:00
return increaseOffset(offset), nil
}
2026-02-12 10:11:29 +08:00
tx.CuLimit = binary.LittleEndian.Uint32(decodedData[:4])
2025-11-20 17:56:45 +08:00
return increaseOffset(offset), nil
}
2025-11-21 12:01:44 +08:00
func computeUnitPriceParser(offset [2]uint, tx *Tx, decodedData []byte) ([2]uint, error) {
2025-11-20 17:56:45 +08:00
if len(decodedData) < 8 {
return increaseOffset(offset), nil
}
cuPrice := binary.LittleEndian.Uint64(decodedData[:8])
tx.CUPrice = decimal.NewFromInt(int64(cuPrice)).Div(decimal.NewFromInt(1000000)) // cu decimals
return increaseOffset(offset), nil
}