Skip to content

Commit

Permalink
Agave v2.0 Migration
Browse files Browse the repository at this point in the history
Updated the RPC client and removed deprecated code from the SDK.
Cleaned up all the warnings across the solution and added a few sys-vars that were missing.
Generate Seed in Mnemonic class now uses System.Security.Cryptography instead of bouncy castle sdk
  • Loading branch information
BifrostTitan committed Sep 2, 2024
1 parent 7bada11 commit bcb3144
Show file tree
Hide file tree
Showing 83 changed files with 146 additions and 1,805 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ var fromAccount = wallet.GetAccount(0);
// Get the destination account
var toAccount = wallet.GetAccount(1);
// Get a recent block hash to include in the transaction
var blockHash = rpcClient.GetRecentBlockHash();
var blockHash = rpcClient.GetLatestBlockHash();

// Initialize a transaction builder and chain as many instructions as you want before building the message
var tx = new TransactionBuilder().
Expand All @@ -228,7 +228,7 @@ var firstSig = rpcClient.SendTransaction(tx);
```c#
var wallet = new Wallet.Wallet(MnemonicWords);

var blockHash = rpcClient.GetRecentBlockHash();
var blockHash = rpcClient.GetLatestBlockHash();
var minBalanceForExemptionAcc = rpcClient.GetMinimumBalanceForRentExemption(TokenProgram.TokenAccountDataSize).Result;

var minBalanceForExemptionMint =rpcClient.GetMinimumBalanceForRentExemption(TokenProgram.MintAccountDataSize).Result;
Expand Down Expand Up @@ -277,7 +277,7 @@ var tx = new TransactionBuilder().
var rpcClient = ClientFactory.GetClient(Cluster.MainNet);
var wallet = new Wallet();

var blockHash = rpcClient.GetRecentBlockHash();
var blockHash = rpcClient.GetLatestBlockHash();
var minBalanceForExemptionAcc =
rpcClient.GetMinimumBalanceForRentExemption(TokenProgram.TokenAccountDataSize).Result;

Expand Down
2 changes: 1 addition & 1 deletion src/Solnet.Examples/AssociatedTokenAccountsExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void Run()
#region Create and Initialize a token Mint Account


RequestResult<ResponseValue<BlockHash>> blockHash = RpcClient.GetRecentBlockHash();
RequestResult<ResponseValue<LatestBlockHash>> blockHash = RpcClient.GetLatestBlockHash();

ulong minBalanceForExemptionAcc =
RpcClient.GetMinimumBalanceForRentExemption(TokenProgram.TokenAccountDataSize).Result;
Expand Down
2 changes: 1 addition & 1 deletion src/Solnet.Examples/HelloWorldExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void Run()

var memoInstruction = MemoProgram.NewMemoV2("Hello Solana World, using Solnet :)");

var recentHash = rpcClient.GetRecentBlockHash();
var recentHash = rpcClient.GetLatestBlockHash();

var tx = new TransactionBuilder().AddInstruction(memoInstruction).SetFeePayer(wallet.Account)
.SetRecentBlockHash(recentHash.Result.Value.Blockhash).Build(wallet.Account);
Expand Down
2 changes: 1 addition & 1 deletion src/Solnet.Examples/InstructionDecoderExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void Run()
var fromAccount = wallet.GetAccount(10);
var toAccount = wallet.GetAccount(8);

var blockHash = rpcClient.GetRecentBlockHash();
var blockHash = rpcClient.GetLatestBlockHash();
Console.WriteLine($"BlockHash >> {blockHash.Result.Value.Blockhash}");

var msgBytes = new TransactionBuilder()
Expand Down
30 changes: 15 additions & 15 deletions src/Solnet.Examples/MultisigExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void Run()
{
Wallet.Wallet wallet = new(MnemonicWords);

RequestResult<ResponseValue<BlockHash>> blockHash = rpcClient.GetRecentBlockHash();
RequestResult<ResponseValue<LatestBlockHash>> blockHash = rpcClient.GetLatestBlockHash();

ulong minBalanceForExemptionMultiSig =
rpcClient.GetMinimumBalanceForRentExemption(TokenProgram.MultisigAccountDataSize).Result;
Expand Down Expand Up @@ -91,7 +91,7 @@ public void Run()
string createMultiSigAndMintSignature = Examples.SubmitTxSendAndLog(txBytes);
Examples.PollConfirmedTx(createMultiSigAndMintSignature);

blockHash = rpcClient.GetRecentBlockHash();
blockHash = rpcClient.GetLatestBlockHash();

msgData = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash)
.SetFeePayer(ownerAccount)
Expand Down Expand Up @@ -154,7 +154,7 @@ public void Run()
{
Wallet.Wallet wallet = new(MnemonicWords);

RequestResult<ResponseValue<BlockHash>> blockHash = rpcClient.GetRecentBlockHash();
RequestResult<ResponseValue<LatestBlockHash>> blockHash = rpcClient.GetLatestBlockHash();

ulong minBalanceForExemptionMultiSig =
rpcClient.GetMinimumBalanceForRentExemption(TokenProgram.MultisigAccountDataSize).Result;
Expand Down Expand Up @@ -227,7 +227,7 @@ public void Run()
{
Wallet.Wallet wallet = new(MnemonicWords);

RequestResult<ResponseValue<BlockHash>> blockHash = rpcClient.GetRecentBlockHash();
RequestResult<ResponseValue<LatestBlockHash>> blockHash = rpcClient.GetLatestBlockHash();

ulong minBalanceForExemptionMultiSig =
rpcClient.GetMinimumBalanceForRentExemption(TokenProgram.MultisigAccountDataSize).Result;
Expand Down Expand Up @@ -359,7 +359,7 @@ public void Run()
{
Wallet.Wallet wallet = new(MnemonicWords);

RequestResult<ResponseValue<BlockHash>> blockHash = rpcClient.GetRecentBlockHash();
RequestResult<ResponseValue<LatestBlockHash>> blockHash = rpcClient.GetLatestBlockHash();

ulong minBalanceForExemptionMultiSig =
rpcClient.GetMinimumBalanceForRentExemption(TokenProgram.MultisigAccountDataSize).Result;
Expand Down Expand Up @@ -427,7 +427,7 @@ public void Run()
string signature = Examples.SubmitTxSendAndLog(txBytes);
Examples.PollConfirmedTx(signature);

blockHash = rpcClient.GetRecentBlockHash();
blockHash = rpcClient.GetLatestBlockHash();


// Then we create an account which will be the token's mint authority
Expand Down Expand Up @@ -479,7 +479,7 @@ public void Run()
signature = Examples.SubmitTxSendAndLog(txBytes);
Examples.PollConfirmedTx(signature);

blockHash = rpcClient.GetRecentBlockHash();
blockHash = rpcClient.GetLatestBlockHash();

// Here we mint tokens to an account using the mint authority multi sig
msgData = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash)
Expand Down Expand Up @@ -526,7 +526,7 @@ public void Run()
signature = Examples.SubmitTxSendAndLog(txBytes);
Examples.PollConfirmedTx(signature);

blockHash = rpcClient.GetRecentBlockHash();
blockHash = rpcClient.GetLatestBlockHash();

// After doing this, we freeze the account to which we just minted tokens
// Notice how the signers used are different, because the `freezeAuthority` has different signers
Expand Down Expand Up @@ -563,7 +563,7 @@ public void Run()
signature = Examples.SubmitTxSendAndLog(txBytes);
Examples.PollConfirmedTx(signature);

blockHash = rpcClient.GetRecentBlockHash();
blockHash = rpcClient.GetLatestBlockHash();

// Because we're actually cool people, we now thaw that same account and then set the authority to nothing
msgData = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash)
Expand Down Expand Up @@ -627,7 +627,7 @@ public void Run()
{
Wallet.Wallet wallet = new(MnemonicWords);

RequestResult<ResponseValue<BlockHash>> blockHash = rpcClient.GetRecentBlockHash();
RequestResult<ResponseValue<LatestBlockHash>> blockHash = rpcClient.GetLatestBlockHash();

ulong minBalanceForExemptionMultiSig =
rpcClient.GetMinimumBalanceForRentExemption(TokenProgram.MultisigAccountDataSize).Result;
Expand Down Expand Up @@ -703,7 +703,7 @@ public void Run()
string signature = Examples.SubmitTxSendAndLog(txBytes);
Examples.PollConfirmedTx(signature);

blockHash = rpcClient.GetRecentBlockHash();
blockHash = rpcClient.GetLatestBlockHash();

msgData = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash)
.SetFeePayer(ownerAccount)
Expand Down Expand Up @@ -749,7 +749,7 @@ public void Run()
signature = Examples.SubmitTxSendAndLog(txBytes);
Examples.PollConfirmedTx(signature);

blockHash = rpcClient.GetRecentBlockHash();
blockHash = rpcClient.GetLatestBlockHash();

msgData = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash)
.SetFeePayer(ownerAccount)
Expand Down Expand Up @@ -786,7 +786,7 @@ public void Run()
signature = Examples.SubmitTxSendAndLog(txBytes);
Examples.PollConfirmedTx(signature);

blockHash = rpcClient.GetRecentBlockHash();
blockHash = rpcClient.GetLatestBlockHash();


msgData = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash)
Expand Down Expand Up @@ -845,7 +845,7 @@ public void Run()
{
Wallet.Wallet wallet = new(MnemonicWords);

RequestResult<ResponseValue<BlockHash>> blockHash = rpcClient.GetRecentBlockHash();
RequestResult<ResponseValue<LatestBlockHash>> blockHash = rpcClient.GetLatestBlockHash();

ulong minBalanceForExemptionMultiSig =
rpcClient.GetMinimumBalanceForRentExemption(TokenProgram.MultisigAccountDataSize).Result;
Expand Down Expand Up @@ -946,7 +946,7 @@ public void Run()
{
Wallet.Wallet wallet = new(MnemonicWords);

RequestResult<ResponseValue<BlockHash>> blockHash = rpcClient.GetRecentBlockHash();
RequestResult<ResponseValue<LatestBlockHash>> blockHash = rpcClient.GetLatestBlockHash();

ulong minBalanceForExemptionMultiSig =
rpcClient.GetMinimumBalanceForRentExemption(TokenProgram.MultisigAccountDataSize).Result;
Expand Down
2 changes: 1 addition & 1 deletion src/Solnet.Examples/NameServiceProgramExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void Run()
{
var wallet = new Wallet.Wallet(MnemonicWords);

var blockHash = rpcClient.GetRecentBlockHash();
var blockHash = rpcClient.GetLatestBlockHash();
var minBalanceForExemptionNameAcc =
rpcClient.GetMinimumBalanceForRentExemption(NameServiceProgram.NameAccountSize + 96).Result;

Expand Down
12 changes: 6 additions & 6 deletions src/Solnet.Examples/StakeExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void Run()
{
var wallet = new Wallet.Wallet(new Mnemonic(MnemonicWords));
rpcClient.RequestAirdrop(wallet.Account.PublicKey, 100_000_000);
RequestResult<ResponseValue<BlockHash>> blockHash = rpcClient.GetRecentBlockHash();
RequestResult<ResponseValue<LatestBlockHash>> blockHash = rpcClient.GetLatestBlockHash();
ulong minBalance = rpcClient.GetMinimumBalanceForRentExemption(StakeProgram.StakeAccountDataSize).Result;
Account fromAccount = wallet.Account;
PublicKey.TryCreateWithSeed(fromAccount.PublicKey, "yrdy1", StakeProgram.ProgramIdKey, out PublicKey stakeAccount);
Expand Down Expand Up @@ -68,7 +68,7 @@ public void Run()
var b58 = new Base58Encoder();
string f = b58.EncodeData(seed);
rpcClient.RequestAirdrop(wallet.Account.PublicKey, 100_000_000);
RequestResult<ResponseValue<BlockHash>> blockHash = rpcClient.GetRecentBlockHash();
RequestResult<ResponseValue<LatestBlockHash>> blockHash = rpcClient.GetLatestBlockHash();
ulong minbalanceforexception = rpcClient.GetMinimumBalanceForRentExemption(StakeProgram.StakeAccountDataSize).Result;
Account fromAccount = wallet.Account;
Account toAccount = wallet.GetAccount(1);
Expand Down Expand Up @@ -109,7 +109,7 @@ public void Run()
{
var wallet = new Wallet.Wallet(new Mnemonic(MnemonicWords));
rpcClient.RequestAirdrop(wallet.Account.PublicKey, 100_000_000);
RequestResult<ResponseValue<BlockHash>> blockHash = rpcClient.GetRecentBlockHash();
RequestResult<ResponseValue<LatestBlockHash>> blockHash = rpcClient.GetLatestBlockHash();

Account fromAccount = wallet.Account;
Account toAccount = wallet.GetAccount(1);
Expand Down Expand Up @@ -146,7 +146,7 @@ public void Run()
{
var wallet = new Wallet.Wallet(new Mnemonic(MnemonicWords));
rpcClient.RequestAirdrop(wallet.Account.PublicKey, 100_000_000);
RequestResult<ResponseValue<BlockHash>> blockHash = rpcClient.GetRecentBlockHash();
RequestResult<ResponseValue<LatestBlockHash>> blockHash = rpcClient.GetLatestBlockHash();
ulong minbalanceforexception = rpcClient.GetMinimumBalanceForRentExemption(StakeProgram.StakeAccountDataSize).Result;
Account fromAccount = wallet.Account;
PublicKey.TryCreateWithSeed(fromAccount.PublicKey, "dog5", StakeProgram.ProgramIdKey, out PublicKey stakeAccount);
Expand Down Expand Up @@ -201,7 +201,7 @@ public void Run()
{
var wallet = new Wallet.Wallet(new Mnemonic(MnemonicWords));
rpcClient.RequestAirdrop(wallet.Account.PublicKey, 100_000_000);
RequestResult<ResponseValue<BlockHash>> blockHash = rpcClient.GetRecentBlockHash();
RequestResult<ResponseValue<LatestBlockHash>> blockHash = rpcClient.GetLatestBlockHash();
ulong minbalanceforexception = rpcClient.GetMinimumBalanceForRentExemption(StakeProgram.StakeAccountDataSize).Result;
Account fromAccount = wallet.Account;
Account stakeAccount = wallet.GetAccount(22);
Expand Down Expand Up @@ -254,7 +254,7 @@ public void Run()
{
var wallet = new Wallet.Wallet(new Mnemonic(MnemonicWords));
rpcClient.RequestAirdrop(wallet.Account.PublicKey, 100_000_000);
RequestResult<ResponseValue<BlockHash>> blockHash = rpcClient.GetRecentBlockHash();
RequestResult<ResponseValue<LatestBlockHash>> blockHash = rpcClient.GetLatestBlockHash();
ulong minBalance = rpcClient.GetMinimumBalanceForRentExemption(StakeProgram.StakeAccountDataSize).Result;

Account a6 = wallet.GetAccount(6);
Expand Down
18 changes: 9 additions & 9 deletions src/Solnet.Examples/TokenSwapExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void Run()
var tokenBUserAccount = new Account();

//setup some mints and tokens owned by wallet
RequestResult<ResponseValue<BlockHash>> blockHash = RpcClient.GetRecentBlockHash();
RequestResult<ResponseValue<LatestBlockHash>> blockHash = RpcClient.GetLatestBlockHash();
var tx = new TransactionBuilder()
.SetRecentBlockHash(blockHash.Result.Value.Blockhash)
.SetFeePayer(wallet.Account)
Expand Down Expand Up @@ -112,7 +112,7 @@ public void Run()
var swapTokenBAccount = new Account();

//init the swap authority's token accounts
blockHash = RpcClient.GetRecentBlockHash();
blockHash = RpcClient.GetLatestBlockHash();
tx = new TransactionBuilder()
.SetRecentBlockHash(blockHash.Result.Value.Blockhash)
.SetFeePayer(wallet.Account)
Expand Down Expand Up @@ -161,7 +161,7 @@ public void Run()
var poolFeeAccount = new Account();

//create the pool mint and the user and fee pool token accounts
blockHash = RpcClient.GetRecentBlockHash();
blockHash = RpcClient.GetLatestBlockHash();
tx = new TransactionBuilder()
.SetRecentBlockHash(blockHash.Result.Value.Blockhash)
.SetFeePayer(wallet.Account)
Expand Down Expand Up @@ -206,7 +206,7 @@ public void Run()
Examples.PollConfirmedTx(txSig);

//create the swap
blockHash = RpcClient.GetRecentBlockHash();
blockHash = RpcClient.GetLatestBlockHash();
tx = new TransactionBuilder()
.SetRecentBlockHash(blockHash.Result.Value.Blockhash)
.SetFeePayer(wallet.Account)
Expand Down Expand Up @@ -247,7 +247,7 @@ public void Run()
Examples.PollConfirmedTx(txSig);

//now a user can swap in the pool
blockHash = RpcClient.GetRecentBlockHash();
blockHash = RpcClient.GetLatestBlockHash();
tx = new TransactionBuilder()
.SetRecentBlockHash(blockHash.Result.Value.Blockhash)
.SetFeePayer(wallet.Account)
Expand All @@ -268,7 +268,7 @@ public void Run()
Examples.PollConfirmedTx(txSig);

//user can add liq
blockHash = RpcClient.GetRecentBlockHash();
blockHash = RpcClient.GetLatestBlockHash();
tx = new TransactionBuilder()
.SetRecentBlockHash(blockHash.Result.Value.Blockhash)
.SetFeePayer(wallet.Account)
Expand All @@ -289,7 +289,7 @@ public void Run()
Examples.PollConfirmedTx(txSig);

//user can remove liq
blockHash = RpcClient.GetRecentBlockHash();
blockHash = RpcClient.GetLatestBlockHash();
tx = new TransactionBuilder()
.SetRecentBlockHash(blockHash.Result.Value.Blockhash)
.SetFeePayer(wallet.Account)
Expand All @@ -311,7 +311,7 @@ public void Run()
Examples.PollConfirmedTx(txSig);

//user can deposit single
blockHash = RpcClient.GetRecentBlockHash();
blockHash = RpcClient.GetLatestBlockHash();
tx = new TransactionBuilder()
.SetRecentBlockHash(blockHash.Result.Value.Blockhash)
.SetFeePayer(wallet.Account)
Expand All @@ -330,7 +330,7 @@ public void Run()
Examples.PollConfirmedTx(txSig);

//user can withdraw single
blockHash = RpcClient.GetRecentBlockHash();
blockHash = RpcClient.GetLatestBlockHash();
tx = new TransactionBuilder()
.SetRecentBlockHash(blockHash.Result.Value.Blockhash)
.SetFeePayer(wallet.Account)
Expand Down
Loading

0 comments on commit bcb3144

Please sign in to comment.