Skip to content

Commit

Permalink
Method to get the marketAuthority(PDA) from the Market Initialization (
Browse files Browse the repository at this point in the history
  • Loading branch information
andmart authored Nov 14, 2024
1 parent 9496e42 commit 9361006
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,3 +718,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")
}

0 comments on commit 9361006

Please sign in to comment.