Merge pull request #1 from L0STE/master

Templates for Vault
This commit is contained in:
Leonardo Donatacci
2023-11-28 14:29:13 +01:00
committed by GitHub
10 changed files with 485 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
export type WbaVault = {
}
export const IDL: WbaVault = {
}

View File

@@ -0,0 +1,46 @@
import { Connection, Keypair, SystemProgram, PublicKey, Commitment } from "@solana/web3.js"
import { Program, Wallet, AnchorProvider, Address, BN } from "@project-serum/anchor"
import { WbaVault, IDL } from "../programs/wba_vault";
import wallet from "../wba-wallet.json"
// Import our keypair from the wallet file
const keypair = Keypair.fromSecretKey(new Uint8Array(wallet));
// Commitment
const commitment: Commitment = "confirmed";
// Create a devnet connection
const connection = new Connection("https://api.devnet.solana.com");
// Create our anchor provider
const provider = new AnchorProvider(connection, new Wallet(keypair), { commitment });
// Create our program
const program = new Program<WbaVault>(IDL, "<address>" as Address, provider);
// Create a random keypair
const vaultState = new PublicKey("<address>");
// Create a random keypair
// const closeVaultState = ???
(async () => {
try {
// const signature = await program.methods
// .closeAccount()
// .accounts({
// owner: ,
// vaultState: ,
// closeVaultState: ,
// systemProgram: ,
// })
// .signers([
// keypair
// ]).rpc();
// console.log(`Close success! Check out your TX here:\n\nhttps://explorer.solana.com/tx/${signature}?cluster=devnet`);
} catch(e) {
console.error(`Oops, something went wrong: ${e}`)
}
})();

View File

@@ -0,0 +1,52 @@
import { Connection, Keypair, SystemProgram, PublicKey, Commitment } from "@solana/web3.js"
import { Program, Wallet, AnchorProvider, Address, BN } from "@project-serum/anchor"
import { WbaVault, IDL } from "../programs/wba_vault";
import wallet from "../wba-wallet.json"
// Import our keypair from the wallet file
const keypair = Keypair.fromSecretKey(new Uint8Array(wallet));
// Commitment
const commitment: Commitment = "confirmed";
// Create a devnet connection
const connection = new Connection("https://api.devnet.solana.com");
// Create our anchor provider
const provider = new AnchorProvider(connection, new Wallet(keypair), { commitment });
// Create our program
const program = new Program<WbaVault>(IDL, "<address>" as Address, provider);
// Create a random keypair
const vaultState = new PublicKey("<address>")
// Create the PDA for our enrollment account
// const vaultAuth = ???
// Create the vault key
// const vault = ???
// Execute our enrollment transaction
(async () => {
try {
// const signature = await program.methods
// .deposit(new BN(<number>) )
// .accounts({
// owner: ,
// vaultState: ,
// vaultAuth: ,
// vault: ,
// systemProgram: SystemProgram.programId,
// })
// .signers([
// keypair
// ]).rpc();
// console.log(`Deposit success! Check out your TX here:\n\nhttps://explorer.solana.com/tx/${signature}?cluster=devnet`);
} catch(e) {
console.error(`Oops, something went wrong: ${e}`)
}
})();

View File

@@ -0,0 +1,77 @@
import { Connection, Keypair, SystemProgram, PublicKey, Commitment } from "@solana/web3.js"
import { Program, Wallet, AnchorProvider, Address, BN } from "@project-serum/anchor"
import { WbaVault, IDL } from "../programs/wba_vault";
import wallet from "../wba-wallet.json"
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount } from "@solana/spl-token";
// Import our keypair from the wallet file
const keypair = Keypair.fromSecretKey(new Uint8Array(wallet));
// Commitment
const commitment: Commitment = "confirmed";
// Create a devnet connection
const connection = new Connection("https://api.devnet.solana.com");
// Create our anchor provider
const provider = new AnchorProvider(connection, new Wallet(keypair), { commitment });
// Create our program
const program = new Program<WbaVault>(IDL, "<address>" as Address, provider);
// Create a random keypair
const vaultState = new PublicKey("<address>")
// Create the PDA for our vault auth
// const vaultAuth = ???
// Create the vault key
// const vault = ???
// Mint address
const mint = new PublicKey("<address>");
// Execute our deposit transaction
(async () => {
try {
const metadataProgram = new PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
const metadataAccount = PublicKey.findProgramAddressSync([Buffer.from("metadata"), metadataProgram.toBuffer(), mint.toBuffer()],metadataProgram)[0];
const masterEdition = PublicKey.findProgramAddressSync([Buffer.from("metadata"), metadataProgram.toBuffer(), mint.toBuffer(), Buffer.from("edition")],metadataProgram)[0];
// b"metadata", MetadataProgramID.key.as_ref(), mint.key.as_ref() "master"
// Get the token account of the fromWallet address, and if it does not exist, create it
// const ownerAta = await getOrCreateAssociatedTokenAccount(
// ???
// );
// // Get the token account of the fromWallet address, and if it does not exist, create it
// const vaultAta = await getOrCreateAssociatedTokenAccount(
// ???
// );
// const signature = await program.methods
// .depositNft()
// .accounts({
// owner: ,
// ownerAta: ,
// vaultState: ,
// vaultAuth: ,
// vaultAta: ,
// tokenMint: ,
// nftMetadata: ,
// nftMasterEdition: ,
// tokenProgram: TOKEN_PROGRAM_ID,
// associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
// metadataProgram: metadataProgram,
// systemProgram: SystemProgram.programId,
// })
// .signers([
// keypair
// ]).rpc();
// console.log(`Deposit success! Check out your TX here:\n\nhttps://explorer.solana.com/tx/${signature}?cluster=devnet`);
} catch(e) {
console.error(`Oops, something went wrong: ${e}`)
}
})();

View File

@@ -0,0 +1,71 @@
import { Connection, Keypair, SystemProgram, PublicKey, Commitment } from "@solana/web3.js"
import { Program, Wallet, AnchorProvider, Address, BN } from "@project-serum/anchor"
import { WbaVault, IDL } from "../programs/wba_vault";
import wallet from "../wba-wallet.json"
import { TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount } from "@solana/spl-token";
// Import our keypair from the wallet file
const keypair = Keypair.fromSecretKey(new Uint8Array(wallet));
// Commitment
const commitment: Commitment = "confirmed";
// Create a devnet connection
const connection = new Connection("https://api.devnet.solana.com");
// Create our anchor provider
const provider = new AnchorProvider(connection, new Wallet(keypair), { commitment });
// Create our program
const program = new Program<WbaVault>(IDL, "<address>" as Address, provider);
// Create a random keypair
const vaultState = new PublicKey("<address>")
// Create the PDA for our vault auth
// const vaultAuth = ???
// Create the vault key
// const vault = ???
// const token_decimals = ???
// Mint address
const mint = new PublicKey("<address>");
// Execute our enrollment transaction
(async () => {
try {
// Get the token account of the fromWallet address, and if it does not exist, create it
// const ownerAta = await getOrCreateAssociatedTokenAccount(
// ???
// );
// Get the token account of the fromWallet address, and if it does not exist, create it
// const vaultAta = await getOrCreateAssociatedTokenAccount(
// ???
// );
// const signature = await program.methods
// .depositSpl(new BN(<number>))
// .accounts({
// owner: ,
// ownerAta: ,
// vaultState: ,
// vaultAuth: ,
// vaultAta: ,
// tokenMint: ,
// tokenProgram: TOKEN_PROGRAM_ID,
// systemProgram: SystemProgram.programId,
// })
// .signers([
// keypair
// ]).rpc();
// console.log(`Deposit success! Check out your TX here:\n\nhttps://explorer.solana.com/tx/${signature}?cluster=devnet`);
} catch(e) {
console.error(`Oops, something went wrong: ${e}`)
}
})();

50
ts/cluster1/vault_init.ts Normal file
View File

@@ -0,0 +1,50 @@
import { Connection, Keypair, SystemProgram, PublicKey, Commitment } from "@solana/web3.js"
import { Program, Wallet, AnchorProvider, Address } from "@project-serum/anchor"
import { WbaVault, IDL } from "./programs/wba_vault";
import wallet from "./wallet/wba-wallet.json"
// Import our keypair from the wallet file
const keypair = Keypair.fromSecretKey(new Uint8Array(wallet));
// Commitment
const commitment: Commitment = "confirmed";
// Create a devnet connection
const connection = new Connection("https://api.devnet.solana.com");
// Create our anchor provider
const provider = new AnchorProvider(connection, new Wallet(keypair), { commitment });
// Create our program
const program = new Program<WbaVault>(IDL, "<addressIDL>" as Address, provider);
// Create a random keypair
const vaultState = Keypair.generate();
console.log(`Vault public key: ${vaultState.publicKey.toBase58()}`);
// Create the PDA for our enrollment account
// const vaultAuth = ???
// Create the vault key
// const vault = ???
// Execute our enrollment transaction
(async () => {
try {
// const signature = await program.methods.initialize()
// .accounts({
// owner:
// vaultState:
// vaultAuth: ,
// vault: ,
// systemProgram: SystemProgram.programId
// }).signers([keypair, vaultState]).rpc();
// console.log(`Init success! Check out your TX here:\n\nhttps://explorer.solana.com/tx/${signature}?cluster=devnet`);
} catch(e) {
console.error(`Oops, something went wrong: ${e}`)
}
})();

View File

@@ -0,0 +1,52 @@
import { Connection, Keypair, SystemProgram, PublicKey, Commitment } from "@solana/web3.js"
import { Program, Wallet, AnchorProvider, Address, BN } from "@project-serum/anchor"
import { WbaVault, IDL } from "../programs/wba_vault";
import wallet from "../wba-wallet.json"
// Import our keypair from the wallet file
const keypair = Keypair.fromSecretKey(new Uint8Array(wallet));
// Commitment
const commitment: Commitment = "confirmed";
// Create a devnet connection
const connection = new Connection("https://api.devnet.solana.com");
// Create our anchor provider
const provider = new AnchorProvider(connection, new Wallet(keypair), { commitment });
// Create our program
const program = new Program<WbaVault>(IDL, "<address>" as Address, provider);
// Create a random keypair
const vaultState = new PublicKey("<address>")
// Create the PDA for our enrollment account
// const vaultAuth = ???
// Create the vault key
// const vault = ???
// Execute our enrollment transaction
(async () => {
try {
// const signature = await program.methods
// .withdraw(new BN(<number>))
// .accounts({
// owner: ,
// vaultState: ,
// vaultAuth: ,
// vault: ,
// systemProgram: SystemProgram.programId,
// })
// .signers([
// keypair
// ]).rpc();
// console.log(`Withdraw success! Check out your TX here:\n\nhttps://explorer.solana.com/tx/${signature}?cluster=devnet`);
} catch(e) {
console.error(`Oops, something went wrong: ${e}`)
}
})();

View File

@@ -0,0 +1,76 @@
import { Connection, Keypair, SystemProgram, PublicKey, Commitment } from "@solana/web3.js"
import { Program, Wallet, AnchorProvider, Address, BN } from "@project-serum/anchor"
import { WbaVault, IDL } from "../programs/wba_vault";
import wallet from "../wba-wallet.json"
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount } from "@solana/spl-token";
// Import our keypair from the wallet file
const keypair = Keypair.fromSecretKey(new Uint8Array(wallet));
// Commitment
const commitment: Commitment = "confirmed";
// Create a devnet connection
const connection = new Connection("https://api.devnet.solana.com");
// Create our anchor provider
const provider = new AnchorProvider(connection, new Wallet(keypair), { commitment });
// Create our program
const program = new Program<WbaVault>(IDL, "<address>" as Address, provider);
// Create a random keypair
const vaultState = new PublicKey("<address>")
// Create the PDA for our vault auth
// const vaultAuth = ???
// Create the vault key
// const vault = ???
// Mint address
const mint = new PublicKey("<address>");
// Execute our enrollment transaction
(async () => {
try {
const metadataProgram = new PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
const metadataAccount = PublicKey.findProgramAddressSync([Buffer.from("metadata"), metadataProgram.toBuffer(), mint.toBuffer()],metadataProgram)[0];
const masterEdition = PublicKey.findProgramAddressSync([Buffer.from("metadata"), metadataProgram.toBuffer(), mint.toBuffer(), Buffer.from("edition")],metadataProgram)[0];
// Get the token account of the fromWallet address, and if it does not exist, create it
// const ownerAta = await getOrCreateAssociatedTokenAccount(
// ???
// );
// Get the token account of the fromWallet address, and if it does not exist, create it
// const vaultAta = await getOrCreateAssociatedTokenAccount(
// ???
// );
// const signature = await program.methods
// .withdrawNft()
// .accounts({
// owner: ,
// ownerAta: ,
// vaultState: ,
// vaultAuth: ,
// vaultAta: ,
// tokenMint: ,
// nftMetadata: ,
// nftMasterEdition: ,
// tokenProgram: TOKEN_PROGRAM_ID,
// associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
// metadataProgram: metadataProgram,
// systemProgram: SystemProgram.programId,
// })
// .signers([
// keypair
// ]).rpc();
// console.log(`Deposit success! Check out your TX here:\n\nhttps://explorer.solana.com/tx/${signature}?cluster=devnet`);
} catch(e) {
console.error(`Oops, something went wrong: ${e}`)
}
})();

View File

@@ -0,0 +1,51 @@
import { Connection, Keypair, SystemProgram, PublicKey, Commitment } from "@solana/web3.js"
import { Program, Wallet, AnchorProvider, Address, BN } from "@project-serum/anchor"
import { WbaVault, IDL } from "../programs/wba_vault";
import wallet from "../wba-wallet.json"
// Import our keypair from the wallet file
const keypair = Keypair.fromSecretKey(new Uint8Array(wallet));
// Commitment
const commitment: Commitment = "confirmed";
// Create a devnet connection
const connection = new Connection("https://api.devnet.solana.com");
// Create our anchor provider
const provider = new AnchorProvider(connection, new Wallet(keypair), { commitment });
// Create our program
const program = new Program<WbaVault>(IDL, "<address>" as Address, provider);
// Create a random keypair
const vaultState = new PublicKey("<address>")
// Create the PDA for our enrollment account
// const vaultAuth = ???
// Create the vault key
// const vault = ???
// Execute our enrollment transaction
(async () => {
try {
// const signature = await program.methods
// .withdraw(new BN(<number>))
// .accounts({
// owner: ,
// vaultState: ,
// vaultAuth: ,
// vault: ,
// systemProgram: SystemProgram.programId,
// })
// .signers([
// keypair
// ]).rpc();
// console.log(`Withdraw success! Check out your TX here:\n\nhttps://explorer.solana.com/tx/${signature}?cluster=devnet`);
} catch(e) {
console.error(`Oops, something went wrong: ${e}`)
}
})();

3
ts/cluster1/wallet/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
*wallet.json