Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39bfeb085f | ||
|
|
10885d5e08 | ||
|
|
2406f6d087 | ||
|
|
8b608889cb | ||
|
|
8d4aad1932 |
@@ -14,7 +14,7 @@ func main() {
|
|||||||
const rpcURL = "https://staked.helius-rpc.com?api-key=5adcf1f9-5719-43d1-bf3f-c2d4e1e5f94d"
|
const rpcURL = "https://staked.helius-rpc.com?api-key=5adcf1f9-5719-43d1-bf3f-c2d4e1e5f94d"
|
||||||
txHash := os.Getenv("TX_HASH")
|
txHash := os.Getenv("TX_HASH")
|
||||||
if txHash == "" {
|
if txHash == "" {
|
||||||
txHash = "29v7u2ewLr3Se6cWYC2xwN8jszqMWwvVgPz7MqkctTveMo1csWWYDBcUsjuJwb5ciugc5so1jc9QcmR7syJTjEns"
|
txHash = "24wP3rk2ZfSVDB5YGyEQbhuy1jRXKZYkzXDRrDwwoKgzD6G4Kyyh4vmnir9ye98uLVKA5bBMj5Fq4cwgbDxp2Gie"
|
||||||
}
|
}
|
||||||
|
|
||||||
if txHash == "" {
|
if txHash == "" {
|
||||||
|
|||||||
21
codex.md
Normal file
21
codex.md
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# Codex Notes
|
||||||
|
|
||||||
|
## Tx Binary enum synchronization
|
||||||
|
|
||||||
|
When adding or renaming transaction-facing enum values, keep the binary format definitions in sync.
|
||||||
|
|
||||||
|
This includes, but is not limited to:
|
||||||
|
|
||||||
|
- tx events
|
||||||
|
- programs
|
||||||
|
- platforms
|
||||||
|
- MEV agents
|
||||||
|
- swap modes, amount sides, limit types, and fee sides
|
||||||
|
|
||||||
|
Checklist:
|
||||||
|
|
||||||
|
1. Add the public constant in the normal source location, such as `enum.go`.
|
||||||
|
2. Add any address mapping in `consts.go` when the enum is account-derived, such as platform or MEV agent detection.
|
||||||
|
3. Append the new value to the matching versioned enum list in `tx_binary.go` under `txBinaryEnumTables`.
|
||||||
|
4. Do not reorder or insert into existing `tx_binary.go` enum lists unless the binary version is intentionally changed; append to preserve existing numeric IDs.
|
||||||
|
5. Add or update tx-binary round-trip coverage so encoding and decoding the new enum value is exercised.
|
||||||
18
consts.go
18
consts.go
@@ -186,6 +186,12 @@ var mevAgentFeeAddresses = map[solana.PublicKey]string{
|
|||||||
solana.MustPublicKeyFromBase58("soyasDBdKjADwPz3xk82U3TNPRDKEWJj7wWLajNHZ1L"): MevAgentSoyas,
|
solana.MustPublicKeyFromBase58("soyasDBdKjADwPz3xk82U3TNPRDKEWJj7wWLajNHZ1L"): MevAgentSoyas,
|
||||||
solana.MustPublicKeyFromBase58("soyasE2abjBAynmHbGWgEwk4ctBy7JMTUCNrMbjcnyH"): MevAgentSoyas,
|
solana.MustPublicKeyFromBase58("soyasE2abjBAynmHbGWgEwk4ctBy7JMTUCNrMbjcnyH"): MevAgentSoyas,
|
||||||
solana.MustPublicKeyFromBase58("soyasF3QPWPAKKmgA3GjfWax1kmTT1aoqSGxPzVLNUQ"): MevAgentSoyas,
|
solana.MustPublicKeyFromBase58("soyasF3QPWPAKKmgA3GjfWax1kmTT1aoqSGxPzVLNUQ"): MevAgentSoyas,
|
||||||
|
solana.MustPublicKeyFromBase58("soyasi59njacMUPvo3TM5paHjeK8pYSdovXgFi32gRt"): MevAgentSoyas,
|
||||||
|
solana.MustPublicKeyFromBase58("soyasQYhJxv8uZgWDxhg72td6piAf7XTkoyWHtSATEz"): MevAgentSoyas,
|
||||||
|
solana.MustPublicKeyFromBase58("soyastP66xyYC8XADXZjdMM5BAVGD2YRvz8dwtLsqb8"): MevAgentSoyas,
|
||||||
|
solana.MustPublicKeyFromBase58("soyasvdgUJWYcUCzDxpmjUnNjH7KamXLXTzLwFvdVPE"): MevAgentSoyas,
|
||||||
|
solana.MustPublicKeyFromBase58("soyasvxAunisNxaoRxkKGjNir7KmbwYnr37JmefkX9G"): MevAgentSoyas,
|
||||||
|
solana.MustPublicKeyFromBase58("soyas5doVFUwH8s5zK8gEvCL5KR5ogDmf52LsrJEZ9h"): MevAgentSoyas,
|
||||||
solana.MustPublicKeyFromBase58("ste11JV3MLMM7x7EJUM2sXcJC1H7F4jBLnP9a9PG8PH"): MevAgentStellium,
|
solana.MustPublicKeyFromBase58("ste11JV3MLMM7x7EJUM2sXcJC1H7F4jBLnP9a9PG8PH"): MevAgentStellium,
|
||||||
solana.MustPublicKeyFromBase58("ste11MWPjXCRfQryCshzi86SGhuXjF4Lv6xMXD2AoSt"): MevAgentStellium,
|
solana.MustPublicKeyFromBase58("ste11MWPjXCRfQryCshzi86SGhuXjF4Lv6xMXD2AoSt"): MevAgentStellium,
|
||||||
solana.MustPublicKeyFromBase58("ste11p5x8tJ53H1NbNQsRBg1YNRd4GcVpxtDw8PBpmb"): MevAgentStellium,
|
solana.MustPublicKeyFromBase58("ste11p5x8tJ53H1NbNQsRBg1YNRd4GcVpxtDw8PBpmb"): MevAgentStellium,
|
||||||
@@ -200,6 +206,8 @@ var mevAgentFeeAddresses = map[solana.PublicKey]string{
|
|||||||
solana.MustPublicKeyFromBase58("ASY4mvCtrACKFK8Jiuvqcu8fad9gGTzvfm5zp4megRes"): MevAgentAstralane,
|
solana.MustPublicKeyFromBase58("ASY4mvCtrACKFK8Jiuvqcu8fad9gGTzvfm5zp4megRes"): MevAgentAstralane,
|
||||||
solana.MustPublicKeyFromBase58("astraubkDw81n4LuutzSQ8uzHCv4BhPVhfvTcYv8SKC"): MevAgentAstralane,
|
solana.MustPublicKeyFromBase58("astraubkDw81n4LuutzSQ8uzHCv4BhPVhfvTcYv8SKC"): MevAgentAstralane,
|
||||||
solana.MustPublicKeyFromBase58("astraEJ2fEj8Xmy6KLG7B3VfbKfsHXhHrNdCQx7iGJK"): MevAgentAstralane,
|
solana.MustPublicKeyFromBase58("astraEJ2fEj8Xmy6KLG7B3VfbKfsHXhHrNdCQx7iGJK"): MevAgentAstralane,
|
||||||
|
solana.MustPublicKeyFromBase58("astraZW5GLFefxNPAatceHhYjfA1ciq9gvfEg2S47xk"): MevAgentAstralane,
|
||||||
|
solana.MustPublicKeyFromBase58("astrawVNP4xDBKT7rAdxrLYiTSTdqtUr63fSMduivXK"): MevAgentAstralane,
|
||||||
solana.MustPublicKeyFromBase58("B1ooMsWjc4SUVVuLyCu1ig2RdomQnHKgMzBMfmSo3DK"): MevAgentAstralane,
|
solana.MustPublicKeyFromBase58("B1ooMsWjc4SUVVuLyCu1ig2RdomQnHKgMzBMfmSo3DK"): MevAgentAstralane,
|
||||||
solana.MustPublicKeyFromBase58("B1ooMZfUJmAvppzc5cr7eYG8Cenig4FbQGBytr4DGCh"): MevAgentAstralane,
|
solana.MustPublicKeyFromBase58("B1ooMZfUJmAvppzc5cr7eYG8Cenig4FbQGBytr4DGCh"): MevAgentAstralane,
|
||||||
solana.MustPublicKeyFromBase58("b1ooMDLjzz4QqecNsJ8bBXzJTzfAPDCP3CxijTS2K93"): MevAgentAstralane,
|
solana.MustPublicKeyFromBase58("b1ooMDLjzz4QqecNsJ8bBXzJTzfAPDCP3CxijTS2K93"): MevAgentAstralane,
|
||||||
@@ -381,6 +389,16 @@ var mevAgentFeeAddresses = map[solana.PublicKey]string{
|
|||||||
solana.MustPublicKeyFromBase58("t7qUQU35sLpPydh42BcPmtEfTWW8gBe4Ry3gjwVnokJ"): MevAgentRaiden,
|
solana.MustPublicKeyFromBase58("t7qUQU35sLpPydh42BcPmtEfTWW8gBe4Ry3gjwVnokJ"): MevAgentRaiden,
|
||||||
solana.MustPublicKeyFromBase58("t8pPgarSK3TnuLbbHmoE1RCQdLxfxuPqNTyFjBKahok"): MevAgentRaiden,
|
solana.MustPublicKeyFromBase58("t8pPgarSK3TnuLbbHmoE1RCQdLxfxuPqNTyFjBKahok"): MevAgentRaiden,
|
||||||
solana.MustPublicKeyFromBase58("t96GGdw3MiaGR993XN8PSsRpKGXx56t5Wf6zcF1hBpY"): MevAgentRaiden,
|
solana.MustPublicKeyFromBase58("t96GGdw3MiaGR993XN8PSsRpKGXx56t5Wf6zcF1hBpY"): MevAgentRaiden,
|
||||||
|
solana.MustPublicKeyFromBase58("7HkiWXe5deJvzn4D6kgMUFCADwX9Z4DMrdjNSSxN6bPp"): MevAgentZan,
|
||||||
|
solana.MustPublicKeyFromBase58("zanrUknLZXzT9JPj968A7RfgCjp77Lx1W1xKRAtfshb"): MevAgentZan,
|
||||||
|
solana.MustPublicKeyFromBase58("zanHbk2UsiT3jKsKjD7UuEqS5Vgpmcd4pG9HycAAV8g"): MevAgentZan,
|
||||||
|
solana.MustPublicKeyFromBase58("zanNazKCXNRoKnPS9BBbFTELTpNwUDJxeKEb1JtZJer"): MevAgentZan,
|
||||||
|
solana.MustPublicKeyFromBase58("zan3gbFhXCjGLHhRe2vaXRDta5fCrYiYr3Dq4RLvpfU"): MevAgentZan,
|
||||||
|
solana.MustPublicKeyFromBase58("zan6WoE3DX5aK7FMQT1vSGsGrgZG1ngns3oCsFMnBHU"): MevAgentZan,
|
||||||
|
solana.MustPublicKeyFromBase58("zan8Nb9fB4zMDsuTRP9R65QZbc9v2Cjn5a4Hjwnj8D3"): MevAgentZan,
|
||||||
|
solana.MustPublicKeyFromBase58("zanJgoR7ALJAJ6ohoKs6aS9T71D9ZkNN9gYM5xUsi3u"): MevAgentZan,
|
||||||
|
solana.MustPublicKeyFromBase58("zanAtYifQP7Bo6kStB97mJvzqSDW1toKNibWibwcKDd"): MevAgentZan,
|
||||||
|
solana.MustPublicKeyFromBase58("GWT5UjDheZzoqinLavJkYvSRH5sakW8vDRdAgrUS5ZcS"): MevAgentTunneling,
|
||||||
}
|
}
|
||||||
|
|
||||||
var entryContractAddresses = map[solana.PublicKey]string{
|
var entryContractAddresses = map[solana.PublicKey]string{
|
||||||
|
|||||||
2
enum.go
2
enum.go
@@ -21,6 +21,8 @@ const (
|
|||||||
MevAgentSpeedlanding = "speedlanding"
|
MevAgentSpeedlanding = "speedlanding"
|
||||||
MevAgentAllenhark = "allenhark"
|
MevAgentAllenhark = "allenhark"
|
||||||
MevAgentRaiden = "raiden"
|
MevAgentRaiden = "raiden"
|
||||||
|
MevAgentZan = "zan"
|
||||||
|
MevAgentTunneling = "tunneling"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
3
pump.go
3
pump.go
@@ -777,6 +777,9 @@ func BuyOrSellParser(tx *Tx, instruction Instruction, innerInstructions InnerIns
|
|||||||
|
|
||||||
for innerIndex, innerInstr := range inners {
|
for innerIndex, innerInstr := range inners {
|
||||||
if innerInstr.ProgramIDIndex == feeEventProgramIndex && bytes.Equal(innerInstr.Data[:8], pumpGetFeesDiscriminator[:]) {
|
if innerInstr.ProgramIDIndex == feeEventProgramIndex && bytes.Equal(innerInstr.Data[:8], pumpGetFeesDiscriminator[:]) {
|
||||||
|
if tradeFound {
|
||||||
|
continue
|
||||||
|
}
|
||||||
err = agbinary.NewBorshDecoder(innerInstr.Data[8:]).Decode(&tradeFeeArg)
|
err = agbinary.NewBorshDecoder(innerInstr.Data[8:]).Decode(&tradeFeeArg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, increaseOffset(offset), fmt.Errorf("pump get fees event decode error: %v, offset, %d, %d", err, offset[0], offset[1])
|
return nil, increaseOffset(offset), fmt.Errorf("pump get fees event decode error: %v, offset, %d, %d", err, offset[0], offset[1])
|
||||||
|
|||||||
25
pump_test.go
25
pump_test.go
@@ -102,6 +102,31 @@ func TestPumpCompleteMatchesTradeEvent(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPumpExactQuoteInKeepsFeeArgBeforeMatchedTrade(t *testing.T) {
|
||||||
|
EnableAllParsers()
|
||||||
|
|
||||||
|
tx := mustParseRPCFixtureTx(t, "3jugr2KthX3cUHzPrMpaFKM7RtxXM6Gcxi8eFjDL7aZGLXpc6f1RaVdnAoB4ye5bRVYsP2fFs3aLaP19Utz91ewv")
|
||||||
|
if len(tx.Swaps) != 4 {
|
||||||
|
t.Fatalf("swaps len = %d, want 4", len(tx.Swaps))
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < 3; i++ {
|
||||||
|
swap := tx.Swaps[i]
|
||||||
|
if swap.Program != SolProgramPump || swap.Event != "buy" {
|
||||||
|
t.Fatalf("swap[%d] = %s/%s, want Pump/buy", i, swap.Program, swap.Event)
|
||||||
|
}
|
||||||
|
assertDecimalString(t, fmt.Sprintf("swap[%d].quote_amount", i), swap.QuoteAmount, "329217")
|
||||||
|
assertDecimalString(t, fmt.Sprintf("swap[%d].fixed_amount", i), swap.FixedAmount, "333333")
|
||||||
|
}
|
||||||
|
|
||||||
|
sell := tx.Swaps[3]
|
||||||
|
if sell.Program != SolProgramPump || sell.Event != "sell" {
|
||||||
|
t.Fatalf("swap[3] = %s/%s, want Pump/sell", sell.Program, sell.Event)
|
||||||
|
}
|
||||||
|
assertDecimalString(t, "swap[3].base_amount", sell.BaseAmount, "12282189230")
|
||||||
|
assertDecimalString(t, "swap[3].quote_amount", sell.QuoteAmount, "987647")
|
||||||
|
}
|
||||||
|
|
||||||
func TestPumpV2Discriminators(t *testing.T) {
|
func TestPumpV2Discriminators(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
31
tx_binary.go
31
tx_binary.go
@@ -1191,7 +1191,7 @@ func (enc *txBinaryEncoder) writeTxBinaryBody(tx *TxBinary, enumTable *txBinaryE
|
|||||||
func (enc *txBinaryEncoder) writePlatformEntries(entries []PlatformBinary, enumTable *txBinaryEnumTable) error {
|
func (enc *txBinaryEncoder) writePlatformEntries(entries []PlatformBinary, enumTable *txBinaryEnumTable) error {
|
||||||
enc.writeUint32(uint32(len(entries)))
|
enc.writeUint32(uint32(len(entries)))
|
||||||
for i, entry := range entries {
|
for i, entry := range entries {
|
||||||
enumID, err := enumTable.platforms.id(entry.Platform)
|
enumID, err := enumTable.platforms.idOrFallback(entry.Platform, PlatformNone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("platform[%d]: %w", i, err)
|
return fmt.Errorf("platform[%d]: %w", i, err)
|
||||||
}
|
}
|
||||||
@@ -1204,7 +1204,7 @@ func (enc *txBinaryEncoder) writePlatformEntries(entries []PlatformBinary, enumT
|
|||||||
func (enc *txBinaryEncoder) writeMevAgentEntries(entries []MevAgentBinary, enumTable *txBinaryEnumTable) error {
|
func (enc *txBinaryEncoder) writeMevAgentEntries(entries []MevAgentBinary, enumTable *txBinaryEnumTable) error {
|
||||||
enc.writeUint32(uint32(len(entries)))
|
enc.writeUint32(uint32(len(entries)))
|
||||||
for i, entry := range entries {
|
for i, entry := range entries {
|
||||||
enumID, err := enumTable.mevAgents.id(entry.MevAgent)
|
enumID, err := enumTable.mevAgents.idOrFallback(entry.MevAgent, MevAgentUnknown)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("mev_agent[%d]: %w", i, err)
|
return fmt.Errorf("mev_agent[%d]: %w", i, err)
|
||||||
}
|
}
|
||||||
@@ -1592,7 +1592,7 @@ func txBinaryReadPlatformEntries(dec txBinaryBodyReader, enumTable *txBinaryEnum
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
platform, err := enumTable.platforms.value(enumID)
|
platform, err := enumTable.platforms.valueOrFallback(enumID, PlatformNone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("platform[%d]: %w", i, err)
|
return nil, fmt.Errorf("platform[%d]: %w", i, err)
|
||||||
}
|
}
|
||||||
@@ -1619,7 +1619,7 @@ func txBinaryReadMevAgentEntries(dec txBinaryBodyReader, enumTable *txBinaryEnum
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
mevAgent, err := enumTable.mevAgents.value(enumID)
|
mevAgent, err := enumTable.mevAgents.valueOrFallback(enumID, MevAgentUnknown)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("mev_agent[%d]: %w", i, err)
|
return nil, fmt.Errorf("mev_agent[%d]: %w", i, err)
|
||||||
}
|
}
|
||||||
@@ -2143,6 +2143,8 @@ var txBinaryEnumTables = map[uint16]*txBinaryEnumTable{
|
|||||||
MevAgentSpeedlanding,
|
MevAgentSpeedlanding,
|
||||||
MevAgentAllenhark,
|
MevAgentAllenhark,
|
||||||
MevAgentRaiden,
|
MevAgentRaiden,
|
||||||
|
MevAgentZan,
|
||||||
|
MevAgentTunneling,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
@@ -2198,9 +2200,30 @@ func (set txBinaryEnumSet) id(value string) (uint16, error) {
|
|||||||
return id, nil
|
return id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (set txBinaryEnumSet) idOrFallback(value string, fallback string) (uint16, error) {
|
||||||
|
if id, ok := set.ids[value]; ok {
|
||||||
|
return id, nil
|
||||||
|
}
|
||||||
|
id, ok := set.ids[fallback]
|
||||||
|
if !ok {
|
||||||
|
return 0, fmt.Errorf("unsupported %s fallback enum value %q for versioned tx binary", set.name, fallback)
|
||||||
|
}
|
||||||
|
return id, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (set txBinaryEnumSet) value(id uint16) (string, error) {
|
func (set txBinaryEnumSet) value(id uint16) (string, error) {
|
||||||
if int(id) >= len(set.values) {
|
if int(id) >= len(set.values) {
|
||||||
return "", fmt.Errorf("unknown %s enum id %d", set.name, id)
|
return "", fmt.Errorf("unknown %s enum id %d", set.name, id)
|
||||||
}
|
}
|
||||||
return set.values[id], nil
|
return set.values[id], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (set txBinaryEnumSet) valueOrFallback(id uint16, fallback string) (string, error) {
|
||||||
|
if int(id) < len(set.values) {
|
||||||
|
return set.values[id], nil
|
||||||
|
}
|
||||||
|
if _, ok := set.ids[fallback]; !ok {
|
||||||
|
return "", fmt.Errorf("unsupported %s fallback enum value %q for versioned tx binary", set.name, fallback)
|
||||||
|
}
|
||||||
|
return fallback, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -41,6 +41,14 @@ func TestTxBinaryRoundTrip(t *testing.T) {
|
|||||||
MevAgent: MevAgentJito,
|
MevAgent: MevAgentJito,
|
||||||
MevAgentFee: decimal.RequireFromString("0.030000000"),
|
MevAgentFee: decimal.RequireFromString("0.030000000"),
|
||||||
},
|
},
|
||||||
|
MevAgentZan: {
|
||||||
|
MevAgent: MevAgentZan,
|
||||||
|
MevAgentFee: decimal.RequireFromString("0.040000000"),
|
||||||
|
},
|
||||||
|
MevAgentTunneling: {
|
||||||
|
MevAgent: MevAgentTunneling,
|
||||||
|
MevAgentFee: decimal.RequireFromString("0.050000000"),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Swaps: []Swap{
|
Swaps: []Swap{
|
||||||
{
|
{
|
||||||
@@ -146,6 +154,12 @@ func TestTxBinaryRoundTrip(t *testing.T) {
|
|||||||
if !decoded.MevAgent[MevAgentJito].MevAgentFee.Equal(original.MevAgent[MevAgentJito].MevAgentFee) {
|
if !decoded.MevAgent[MevAgentJito].MevAgentFee.Equal(original.MevAgent[MevAgentJito].MevAgentFee) {
|
||||||
t.Fatalf("MevAgent fee mismatch")
|
t.Fatalf("MevAgent fee mismatch")
|
||||||
}
|
}
|
||||||
|
if !decoded.MevAgent[MevAgentZan].MevAgentFee.Equal(original.MevAgent[MevAgentZan].MevAgentFee) {
|
||||||
|
t.Fatalf("Zan MevAgent fee mismatch")
|
||||||
|
}
|
||||||
|
if !decoded.MevAgent[MevAgentTunneling].MevAgentFee.Equal(original.MevAgent[MevAgentTunneling].MevAgentFee) {
|
||||||
|
t.Fatalf("Tunneling MevAgent fee mismatch")
|
||||||
|
}
|
||||||
if len(decoded.Swaps) != 1 {
|
if len(decoded.Swaps) != 1 {
|
||||||
t.Fatalf("Swaps len = %d, want 1", len(decoded.Swaps))
|
t.Fatalf("Swaps len = %d, want 1", len(decoded.Swaps))
|
||||||
}
|
}
|
||||||
@@ -225,6 +239,87 @@ func TestTxBinaryRejectsUnknownProgramEnum(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTxBinaryLabelEnumsFallbackToUnknown(t *testing.T) {
|
||||||
|
original := &Tx{
|
||||||
|
Signer: solana.WrappedSol,
|
||||||
|
Platform: map[string]platformInfo{
|
||||||
|
"future-platform": {
|
||||||
|
Platform: "future-platform",
|
||||||
|
PlatformFee: decimal.RequireFromString("0.010000000"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
MevAgent: map[string]mevInfo{
|
||||||
|
"future-mev-agent": {
|
||||||
|
MevAgent: "future-mev-agent",
|
||||||
|
MevAgentFee: decimal.RequireFromString("0.020000000"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
encoded, err := EncodeTxBinary(original)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("EncodeTxBinary() error = %v", err)
|
||||||
|
}
|
||||||
|
decoded, err := DecodeTxBinary(encoded)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("DecodeTxBinary() error = %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(decoded.Platform) != 1 {
|
||||||
|
t.Fatalf("Platform len = %d, want 1", len(decoded.Platform))
|
||||||
|
}
|
||||||
|
if _, exists := decoded.Platform["future-platform"]; exists {
|
||||||
|
t.Fatalf("future platform was preserved, want fallback")
|
||||||
|
}
|
||||||
|
if !decoded.Platform[PlatformNone].PlatformFee.Equal(original.Platform["future-platform"].PlatformFee) {
|
||||||
|
t.Fatalf("PlatformNone fee = %s, want %s", decoded.Platform[PlatformNone].PlatformFee, original.Platform["future-platform"].PlatformFee)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(decoded.MevAgent) != 1 {
|
||||||
|
t.Fatalf("MevAgent len = %d, want 1", len(decoded.MevAgent))
|
||||||
|
}
|
||||||
|
if _, exists := decoded.MevAgent["future-mev-agent"]; exists {
|
||||||
|
t.Fatalf("future mev agent was preserved, want fallback")
|
||||||
|
}
|
||||||
|
if !decoded.MevAgent[MevAgentUnknown].MevAgentFee.Equal(original.MevAgent["future-mev-agent"].MevAgentFee) {
|
||||||
|
t.Fatalf("MevAgentUnknown fee = %s, want %s", decoded.MevAgent[MevAgentUnknown].MevAgentFee, original.MevAgent["future-mev-agent"].MevAgentFee)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTxBinaryReadLabelEnumUnknownIDsFallback(t *testing.T) {
|
||||||
|
enumTable := txBinaryEnumTables[txBinaryEnumVersionV1]
|
||||||
|
|
||||||
|
platformFee := uint64(123)
|
||||||
|
platformEnc := txBinaryEncoder{}
|
||||||
|
platformEnc.writeUint32(1)
|
||||||
|
platformEnc.writeUint16(uint16(len(enumTable.platforms.values) + 10))
|
||||||
|
platformEnc.writeUint64(platformFee)
|
||||||
|
|
||||||
|
platformDec := txBinaryDecoder{reader: bytes.NewReader(platformEnc.bytes())}
|
||||||
|
platforms, err := txBinaryReadPlatformEntries(&platformDec, enumTable)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("txBinaryReadPlatformEntries() error = %v", err)
|
||||||
|
}
|
||||||
|
if len(platforms) != 1 || platforms[0].Platform != PlatformNone || platforms[0].PlatformFee != platformFee {
|
||||||
|
t.Fatalf("platform fallback = %+v, want %s/%d", platforms, PlatformNone, platformFee)
|
||||||
|
}
|
||||||
|
|
||||||
|
mevFee := uint64(456)
|
||||||
|
mevEnc := txBinaryEncoder{}
|
||||||
|
mevEnc.writeUint32(1)
|
||||||
|
mevEnc.writeUint16(uint16(len(enumTable.mevAgents.values) + 10))
|
||||||
|
mevEnc.writeUint64(mevFee)
|
||||||
|
|
||||||
|
mevDec := txBinaryDecoder{reader: bytes.NewReader(mevEnc.bytes())}
|
||||||
|
mevAgents, err := txBinaryReadMevAgentEntries(&mevDec, enumTable)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("txBinaryReadMevAgentEntries() error = %v", err)
|
||||||
|
}
|
||||||
|
if len(mevAgents) != 1 || mevAgents[0].MevAgent != MevAgentUnknown || mevAgents[0].MevAgentFee != mevFee {
|
||||||
|
t.Fatalf("mev agent fallback = %+v, want %s/%d", mevAgents, MevAgentUnknown, mevFee)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestTxBinaryAcceptsKnownEventEnums(t *testing.T) {
|
func TestTxBinaryAcceptsKnownEventEnums(t *testing.T) {
|
||||||
events := []string{
|
events := []string{
|
||||||
TxEventAddLP,
|
TxEventAddLP,
|
||||||
|
|||||||
Reference in New Issue
Block a user