Skip to content

Commit

Permalink
Add test for PDA Stake Account derivation
Browse files Browse the repository at this point in the history
This test verifies the correct derivation of multiple PDA addresses using various inputs like miner, programId, staker, and oreSolMeteoraLpTokenMint. It logs the derived addresses and also deserializes the delegatedBoostAddress to ensure correct account information retrieval.
  • Loading branch information
skynetcap committed Nov 18, 2024
1 parent 43deb51 commit 441265e
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/test/java/org/p2p/solanaj/core/MainnetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,60 @@ public void getAccountInfoJsonParsed() {
}
}

@Test
public void testPdaStakeAccountDerive() throws RpcException {
PublicKey miner = new PublicKey("mineXqpDeBeMR8bPQCyy9UneJZbjFywraS3koWZ8SSH");
PublicKey programId = new PublicKey("J6XAzG8S5KmoBM8GcCFfF8NmtzD7U3QPnbhNiYwsu9we");
PublicKey boostProgramId = new PublicKey("boostmPwypNUQu8qZ8RoWt5DXyYSVYxnBXqbbrGjecc");
PublicKey staker = new PublicKey("skynetDj29GH6o6bAqoixCpDuYtWqi1rm8ZNx1hB3vq");
PublicKey oreSolMeteoraLpTokenMint = new PublicKey("DrSS5RM7zUd9qjUEdDaf31vnDUSbCrMto6mjqTrHFifN");

// Managed Proof Address
var managedProofAddress = PublicKey.findProgramAddress(
List.of(
"managed-proof-account".getBytes(),
miner.toByteArray()
),
programId
);

var delegatedBoostAddress = PublicKey.findProgramAddress(
List.of(
"v2-delegated-boost".getBytes(),
staker.toByteArray(),
oreSolMeteoraLpTokenMint.toByteArray(),
managedProofAddress.getAddress().toByteArray()
),
programId
);

var boostPda = PublicKey.findProgramAddress(
List.of(
"boost".getBytes(),
oreSolMeteoraLpTokenMint.toByteArray()
),
boostProgramId
);

var stakePda = PublicKey.findProgramAddress(
List.of(
"stake".getBytes(),
managedProofAddress.getAddress().toByteArray(),
boostPda.getAddress().toByteArray()
),
boostProgramId
);

LOGGER.info("managedProofAddress: " + managedProofAddress.getAddress());
LOGGER.info("delegatedBoostAddress: " + delegatedBoostAddress.getAddress());
LOGGER.info("boostPda: " + boostPda.getAddress());
LOGGER.info("stakePda: " + stakePda.getAddress());

// Deserialize delegatedBoostAddress
byte[] delegatedBoostAddressData = client.getApi().getAccountInfo(delegatedBoostAddress.getAddress()).getDecodedData();
LOGGER.info("delegatedBoostAddressData: " + Arrays.toString(delegatedBoostAddressData));
}

/**
* Calls sendTransaction with a call to the Memo program included.
*/
Expand Down

0 comments on commit 441265e

Please sign in to comment.