Skip to content

Commit 3e1209c

Browse files
committed
refactor: move pumpfun-related type definitions to pumpfun package
1 parent b5581b5 commit 3e1209c

File tree

6 files changed

+26
-24
lines changed

6 files changed

+26
-24
lines changed

solana/parser_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestPumpFunSell_0(t *testing.T) {
5353
}
5454
results, _ := Parser(byteValue)
5555
action := results[0].Actions[3]
56-
if sellAction, ok := action.(*types.PumpFunSellAction); ok {
56+
if sellAction, ok := action.(*pumpfun.SellAction); ok {
5757
assert.Equal(t, sellAction.ProgramID, pumpfun.Program)
5858
assert.Equal(t, sellAction.ProgramName, "PumpFun")
5959
assert.Equal(t, sellAction.InstructionName, "Sell")
@@ -75,7 +75,7 @@ func TestPumpFunBuy_0(t *testing.T) {
7575
}
7676
results, _ := Parser(byteValue)
7777
action := results[0].Actions[2]
78-
if buyAction, ok := action.(*types.PumpFunBuyAction); ok {
78+
if buyAction, ok := action.(*pumpfun.BuyAction); ok {
7979
assert.Equal(t, buyAction.ProgramID, pumpfun.Program)
8080
assert.Equal(t, buyAction.ProgramName, "PumpFun")
8181
assert.Equal(t, buyAction.InstructionName, "Buy")
@@ -98,7 +98,7 @@ func TestPumpFunBuy_1(t *testing.T) {
9898
}
9999
results, _ := Parser(byteValue)
100100
action := results[0].Actions[4]
101-
if buyAction, ok := action.(*types.PumpFunBuyAction); ok {
101+
if buyAction, ok := action.(*pumpfun.BuyAction); ok {
102102
assert.Equal(t, buyAction.ProgramID, pumpfun.Program)
103103
assert.Equal(t, buyAction.ProgramName, "PumpFun")
104104
assert.Equal(t, buyAction.InstructionName, "Buy")
@@ -121,7 +121,7 @@ func TestPumpFunBuyBundle(t *testing.T) {
121121
}
122122
results, _ := Parser(byteValue)
123123
action := results[0].Actions[1]
124-
if buyAction, ok := action.(*types.PumpFunBuyAction); ok {
124+
if buyAction, ok := action.(*pumpfun.BuyAction); ok {
125125
assert.Equal(t, buyAction.ProgramID, pumpfun.Program)
126126
assert.Equal(t, buyAction.ProgramName, "PumpFun")
127127
assert.Equal(t, buyAction.InstructionName, "Buy")
@@ -136,7 +136,7 @@ func TestPumpFunBuyBundle(t *testing.T) {
136136
}
137137

138138
action = results[0].Actions[3]
139-
if buyAction, ok := action.(*types.PumpFunBuyAction); ok {
139+
if buyAction, ok := action.(*pumpfun.BuyAction); ok {
140140
assert.Equal(t, buyAction.ProgramID, pumpfun.Program)
141141
assert.Equal(t, buyAction.ProgramName, "PumpFun")
142142
assert.Equal(t, buyAction.InstructionName, "Buy")
@@ -151,7 +151,7 @@ func TestPumpFunBuyBundle(t *testing.T) {
151151
}
152152

153153
action = results[0].Actions[5]
154-
if buyAction, ok := action.(*types.PumpFunBuyAction); ok {
154+
if buyAction, ok := action.(*pumpfun.BuyAction); ok {
155155
assert.Equal(t, buyAction.ProgramID, pumpfun.Program)
156156
assert.Equal(t, buyAction.ProgramName, "PumpFun")
157157
assert.Equal(t, buyAction.InstructionName, "Buy")
@@ -173,7 +173,7 @@ func TestPumpFunCreate_0(t *testing.T) {
173173
}
174174
results, _ := Parser(byteValue)
175175
action := results[0].Actions[3]
176-
if createAction, ok := action.(*types.PumpFunCreateAction); ok {
176+
if createAction, ok := action.(*pumpfun.CreateAction); ok {
177177
assert.Equal(t, createAction.ProgramID, pumpfun.Program)
178178
assert.Equal(t, createAction.ProgramName, "PumpFun")
179179
assert.Equal(t, createAction.InstructionName, "Create")

solana/programs/pumpfun/parsers/anchorSelfCPILogSwap.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ type AnchorSelfCPILogSwapData struct {
1919
VirtualTokenReserves uint64
2020
}
2121

22-
func AnchorSelfCPILogSwapParser(decodedData []byte) (*types.PumpFunAnchorSelfCPILogSwapAction, error) {
22+
func AnchorSelfCPILogSwapParser(decodedData []byte) (*pumpfun.AnchorSelfCPILogSwapAction, error) {
2323
var data AnchorSelfCPILogSwapData
2424
err := borsh.Deserialize(&data, decodedData)
2525
if err != nil {
2626
return nil, err
2727
}
2828

29-
action := types.PumpFunAnchorSelfCPILogSwapAction{
29+
action := pumpfun.AnchorSelfCPILogSwapAction{
3030
BaseAction: types.BaseAction{
3131
ProgramID: pumpfun.Program,
3232
ProgramName: "pumpfun",

solana/programs/pumpfun/parsers/buy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type BuyData struct {
1717
MaxSolCost uint64
1818
}
1919

20-
func BuyParser(result *types.ParsedResult, instruction types.Instruction, decodedData []byte) (*types.PumpFunBuyAction, error) {
20+
func BuyParser(result *types.ParsedResult, instruction types.Instruction, decodedData []byte) (*pumpfun.BuyAction, error) {
2121
var buyData BuyData
2222
err := borsh.Deserialize(&buyData, decodedData)
2323
if err != nil {
@@ -79,7 +79,7 @@ func BuyParser(result *types.ParsedResult, instruction types.Instruction, decode
7979
}
8080
}
8181

82-
action := types.PumpFunBuyAction{
82+
action := pumpfun.BuyAction{
8383
BaseAction: types.BaseAction{
8484
ProgramID: pumpfun.Program,
8585
ProgramName: pumpfun.ProgramName,

solana/programs/pumpfun/parsers/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ type CreateData struct {
1313
Uri string
1414
}
1515

16-
func CreateParser(result *types.ParsedResult, instruction types.Instruction, decodedData []byte) (*types.PumpFunCreateAction, error) {
16+
func CreateParser(result *types.ParsedResult, instruction types.Instruction, decodedData []byte) (*pumpfun.CreateAction, error) {
1717
var createData CreateData
1818
err := borsh.Deserialize(&createData, decodedData)
1919
if err != nil {
2020
return nil, err
2121
}
2222

23-
action := types.PumpFunCreateAction{
23+
action := pumpfun.CreateAction{
2424
BaseAction: types.BaseAction{
2525
ProgramID: pumpfun.Program,
2626
ProgramName: pumpfun.ProgramName,

solana/programs/pumpfun/parsers/sell.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type SellData struct {
1414
MinSolOutput uint64
1515
}
1616

17-
func SellParser(result *types.ParsedResult, instruction types.Instruction, decodedData []byte) (*types.PumpFunSellAction, error) {
17+
func SellParser(result *types.ParsedResult, instruction types.Instruction, decodedData []byte) (*pumpfun.SellAction, error) {
1818
var sellData SellData
1919
err := borsh.Deserialize(&sellData, decodedData)
2020
if err != nil {
@@ -62,7 +62,7 @@ func SellParser(result *types.ParsedResult, instruction types.Instruction, decod
6262
}
6363
}
6464

65-
action := types.PumpFunSellAction{
65+
action := pumpfun.SellAction{
6666
BaseAction: types.BaseAction{
6767
ProgramID: pumpfun.Program,
6868
ProgramName: pumpfun.ProgramName,

solana/types/pumpFunAction.go renamed to solana/programs/pumpfun/types.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
package types
1+
package pumpfun
22

3-
type PumpFunBuyAction struct {
4-
BaseAction
3+
import "github.com/0xjeffro/tx-parser/solana/types"
4+
5+
type BuyAction struct {
6+
types.BaseAction
57
Who string `json:"who"`
68
FromToken string `json:"fromToken"`
79
FromTokenAmount uint64 `json:"fromTokenAmount"`
@@ -11,8 +13,8 @@ type PumpFunBuyAction struct {
1113
FeeAmount uint64 `json:"feeAmount"`
1214
}
1315

14-
type PumpFunSellAction struct {
15-
BaseAction
16+
type SellAction struct {
17+
types.BaseAction
1618
Who string `json:"who"`
1719
FromToken string `json:"fromToken"`
1820
FromTokenAmount uint64 `json:"fromTokenAmount"`
@@ -21,8 +23,8 @@ type PumpFunSellAction struct {
2123
MinSolOutput uint64 `json:"minSolOutput"`
2224
}
2325

24-
type PumpFunCreateAction struct {
25-
BaseAction
26+
type CreateAction struct {
27+
types.BaseAction
2628
Who string `json:"who"`
2729
Mint string `json:"mint"`
2830
MintAuthority string `json:"mintAuthority"`
@@ -36,8 +38,8 @@ type PumpFunCreateAction struct {
3638
Uri string `json:"uri"`
3739
}
3840

39-
type PumpFunAnchorSelfCPILogSwapAction struct {
40-
BaseAction
41+
type AnchorSelfCPILogSwapAction struct {
42+
types.BaseAction
4143
Mint string `json:"mint"`
4244
SolAmount uint64 `json:"solAmount"`
4345
TokenAmount uint64 `json:"tokenAmount"`

0 commit comments

Comments
 (0)