diff --git a/enum.go b/enum.go index cc3f089..a7feddf 100644 --- a/enum.go +++ b/enum.go @@ -126,4 +126,17 @@ const ( TxEventBuyFailed = "buy_failed" TxEventSellFailed = "sell_failed" TxEventBurn = "burn" + TxEventCreate = "create" + TxEventComplete = "complete" + TxEventMigrate = "migrate" + TxEventDeposit = "deposit" + TxEventWithdraw = "withdraw" + TxEventOpen = "open" + TxEventClose = "close" + TxEventClaimFee = "claim_fee" + + TxEventAddLiquidity = "add_liquidity" + TxEventAddLiquidityOneSide = "add_liquidity_one_side" + TxEventRemoveLiquidity = "remove_liquidity" + TxEventRemoveLiquidityOneSide = "remove_liquidity_one_side" ) diff --git a/tx_binary.go b/tx_binary.go index 3620967..796810b 100644 --- a/tx_binary.go +++ b/tx_binary.go @@ -2055,6 +2055,18 @@ var txBinaryEnumTables = map[uint16]*txBinaryEnumTable{ TxEventBuyFailed, TxEventSellFailed, TxEventBurn, + TxEventCreate, + TxEventComplete, + TxEventMigrate, + TxEventDeposit, + TxEventWithdraw, + TxEventOpen, + TxEventClose, + TxEventClaimFee, + TxEventAddLiquidity, + TxEventAddLiquidityOneSide, + TxEventRemoveLiquidity, + TxEventRemoveLiquidityOneSide, }, "platform", []string{ diff --git a/tx_binary_test.go b/tx_binary_test.go index 1fb71e9..acf4ed0 100644 --- a/tx_binary_test.go +++ b/tx_binary_test.go @@ -225,6 +225,74 @@ func TestTxBinaryRejectsUnknownProgramEnum(t *testing.T) { } } +func TestTxBinaryAcceptsKnownEventEnums(t *testing.T) { + events := []string{ + TxEventAddLP, + TxEventRemoveLP, + TxEventBuy, + TxEventSell, + TxEventBuyFailed, + TxEventSellFailed, + TxEventBurn, + TxEventCreate, + TxEventComplete, + TxEventMigrate, + TxEventDeposit, + TxEventWithdraw, + TxEventOpen, + TxEventClose, + TxEventClaimFee, + TxEventAddLiquidity, + TxEventAddLiquidityOneSide, + TxEventRemoveLiquidity, + TxEventRemoveLiquidityOneSide, + } + + for _, event := range events { + t.Run(event, func(t *testing.T) { + txBinary := &TxBinary{ + SchemaVersion: txBinarySchemaVersionCurrent, + EnumVersion: txBinaryEnumVersionV1, + AddressTable: []solana.PublicKey{ + mustPubKey("11111111111111111111111111111111"), + mustPubKey("So11111111111111111111111111111111111111112"), + solana.TokenProgramID, + mustPubKey("BPFLoader1111111111111111111111111111111111"), + mustPubKey("SysvarRent111111111111111111111111111111111"), + }, + Swaps: []SwapBinary{ + { + Program: SolProgramPump, + Event: event, + Pool: 0, + BaseMint: 1, + QuoteMint: 1, + BaseTokenProgram: 2, + QuoteTokenProgram: 2, + Creator: 3, + User: 4, + FixedMint: 1, + LimitMint: 1, + }, + }, + } + + encoded, err := txBinary.MarshalBinary() + if err != nil { + t.Fatalf("MarshalBinary() error = %v", err) + } + + var decoded TxBinary + if err := decoded.UnmarshalBinary(encoded); err != nil { + t.Fatalf("UnmarshalBinary() error = %v", err) + } + if got := decoded.Swaps[0].Event; got != event { + t.Fatalf("decoded event = %q, want %q", got, event) + } + }) + } +} + func TestTxsBinaryRoundTripWithSharedAddressTable(t *testing.T) { tx1 := Tx{ Signer: mustPubKey("So11111111111111111111111111111111111111112"),