Raydium-Go is a Go library for parsing the Raydium DEX events.
go get github.com/Umiiii/raydium-go
Protocol | Repository | Status | Notes |
---|---|---|---|
OpenBook AMM (Raydium V4) | raydium-amm | DONE | - |
AMM Stable | raydium-amm | NO PLAN | For stablecoins only |
Concentrated Liquidity (CLMM/V3) | raydium-clmm | WORKING | Solana Mainnet 2023-02-28 |
Standard AMM (CP-Swap) | raydium-cp-swap | NO PLAN | Solana Mainnet 2024-05-15 |
import (
"github.com/Umiiii/raydium-go/logs"
)
...
rayLog := "Program: ray_log: AAAAAAAAAAAABglkAAAAAAAAAICWmAAAAAAAAAgBqSy8AACRHBZlEgAAAG7jUV5vrTnToQOjEWYfoQjU/LCcxQ2ys5IotRcUlt8O"
log, err := logs.GetRaydiumAmmLogsFromRayLog(rayLog)
if err != nil {
panic(err)
}
fmt.Println(log)
...
import (
"github.com/Umiiii/raydium-go/instructions"
)
...
instructions.DecodeRaydiumCreatePoolData(outerInst.Data)
...
import (
"github.com/Umiiii/raydium-go/parameters"
)
...
parameters.DecodeRaydiumCreatePoolParams(outerInst.Data)
...
import (
"github.com/Umiiii/raydium-go/accounts"
"github.com/Umiiii/raydium-go/types"
)
....
acc := accounts.ParseAccountsIntoStruct[types.ClmmCreatePoolAccounts](outerInst.Accounts)
....
Actually you can infer the swap details from the log message ONLY, but it is quite tricky.
So a log function is provided to group the log message first.
import (
"github.com/Umiiii/raydium-go/logs"
)
func main() {
logs := logs.ParseProgramLogs(parsedTransaction.Meta.LogMessages)
for idx, singleLog := range allLogs {
if singleLog.Address == CLMMAddress {
var swapRawData *types.ClmmSwapEvent
var ok bool
if swapRawData, ok = (logsData).(*types.ClmmSwapEvent); !ok {
return swapEvent, errors.New("failed to parse clmm logs")
}
poolAddress := swapRawData.PoolAddress
tokenMint0 := swapRawData.TokenMint0
tokenMint1 := swapRawData.TokenMint1
amount0 := swapRawData.Amount0
amount1 := swapRawData.Amount1
if swapRawData.ZeroForOne {
// swap from token0 to token1
} else {
// swap from token1 to token0
}
}
}
}
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.