From 652bccc45d23c565824d2a4bd5c5d58329610a53 Mon Sep 17 00:00:00 2001 From: Andre Martins Date: Tue, 1 Oct 2024 00:17:11 +0100 Subject: [PATCH] Method to get the marketAuthority(PDA) from the Market Initialization Reference: https://github.com/raydium-io/raydium-sdk/blob/f4b7f47e744c12a8b0119b85e16d0d8274aa5ba9/src/serum/serum.ts#L41 --- keys.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/keys.go b/keys.go index fa650fe7..75afe257 100644 --- a/keys.go +++ b/keys.go @@ -675,3 +675,19 @@ func FindTokenMetadataAddress(mint PublicKey) (PublicKey, uint8, error) { } return FindProgramAddress(seed, TokenMetadataProgramID) } + +// Get the marketAuthority(PDA) from the Market Initialization +func GetAssociatedAuthority(programID PublicKey, marketAddr PublicKey) (PublicKey, uint8, error) { + var address PublicKey + var err error + bumpSeed := uint8(0) + endSeed := []byte{0, 0, 0, 0, 0, 0, 0} + for bumpSeed < 100 { + address, err = CreateProgramAddress([][]byte{marketAddr[:], []byte{byte(bumpSeed)}, endSeed}, programID) + if err == nil { + return address, bumpSeed, nil + } + bumpSeed++ + } + return PublicKey{}, bumpSeed, errors.New("unable to find a valid program address") +}