Переглянути джерело

Upgrade to `@coral-xyz/anchor` 0.28.0 (#50)

acheron 2 роки тому
батько
коміт
bbe74eee4d
40 змінених файлів з 761 додано та 682 видалено
  1. 12 12
      basics/account-data/anchor/package.json
  2. 5 9
      basics/account-data/anchor/tests/test.ts
  3. 12 12
      basics/checking-accounts/anchor/package.json
  4. 13 15
      basics/checking-accounts/anchor/tests/test.ts
  5. 1 1
      basics/close-account/anchor/migrations/deploy.ts
  6. 17 17
      basics/close-account/anchor/package.json
  7. 84 67
      basics/close-account/anchor/tests/close-account.ts
  8. 1 1
      basics/counter/anchor/migrations/deploy.ts
  9. 17 17
      basics/counter/anchor/package.json
  10. 12 8
      basics/counter/anchor/tests/counter_anchor.ts
  11. 1 1
      basics/counter/seahorse/migrations/deploy.ts
  12. 17 17
      basics/counter/seahorse/package.json
  13. 7 9
      basics/counter/seahorse/tests/counter_seahorse.ts
  14. 12 12
      basics/create-account/anchor/package.json
  15. 12 14
      basics/create-account/anchor/tests/test.ts
  16. 12 12
      basics/cross-program-invocation/anchor/package.json
  17. 24 28
      basics/cross-program-invocation/anchor/tests/test.ts
  18. 12 12
      basics/hello-solana/anchor/package.json
  19. 2 7
      basics/hello-solana/anchor/tests/test.ts
  20. 1 1
      basics/hello-solana/seahorse/hello_solana/migrations/deploy.ts
  21. 17 17
      basics/hello-solana/seahorse/hello_solana/package.json
  22. 8 9
      basics/hello-solana/seahorse/hello_solana/tests/hello_solana.ts
  23. 12 12
      basics/pda-rent-payer/anchor/package.json
  24. 26 25
      basics/pda-rent-payer/anchor/tests/test.ts
  25. 12 12
      basics/processing-instructions/anchor/package.json
  26. 5 12
      basics/processing-instructions/anchor/tests/test.ts
  27. 12 12
      basics/program-derived-addresses/anchor/package.json
  28. 11 8
      basics/program-derived-addresses/anchor/tests/test.ts
  29. 12 12
      basics/rent/anchor/package.json
  30. 15 15
      basics/rent/anchor/tests/test.ts
  31. 12 12
      basics/repository-layout/anchor/package.json
  32. 30 31
      basics/repository-layout/anchor/tests/test.ts
  33. 12 12
      basics/transfer-sol/anchor/package.json
  34. 24 20
      basics/transfer-sol/anchor/tests/test.ts
  35. 20 20
      compression/cnft-vault/anchor/package.json
  36. 9 5
      compression/cnft-vault/anchor/tests/scripts/constants.ts
  37. 18 10
      compression/cnft-vault/anchor/tests/scripts/withdraw.ts
  38. 34 18
      compression/cnft-vault/anchor/tests/scripts/withdrawTwo.ts
  39. 63 29
      compression/cnft-vault/anchor/tests/scripts/withdrawWithLookup.ts
  40. 135 119
      compression/cnft-vault/anchor/tests/tests.ts

+ 12 - 12
basics/account-data/anchor/package.json

@@ -1,14 +1,14 @@
 {
-    "dependencies": {
-        "@project-serum/anchor": "^0.24.2"
-    },
-    "devDependencies": {
-        "@types/bn.js": "^5.1.0",
-        "@types/chai": "^4.3.0",
-        "@types/mocha": "^9.0.0",
-        "chai": "^4.3.4",
-        "mocha": "^9.0.3",
-        "ts-mocha": "^10.0.0",
-        "typescript": "^4.3.5"
-    }
+  "dependencies": {
+    "@coral-xyz/anchor": "^0.28.0"
+  },
+  "devDependencies": {
+    "@types/bn.js": "^5.1.0",
+    "@types/chai": "^4.3.0",
+    "@types/mocha": "^9.0.0",
+    "chai": "^4.3.4",
+    "mocha": "^9.0.3",
+    "ts-mocha": "^10.0.0",
+    "typescript": "^4.3.5"
+  }
 }

+ 5 - 9
basics/account-data/anchor/tests/test.ts

@@ -1,24 +1,20 @@
-import * as anchor from "@project-serum/anchor";
+import * as anchor from "@coral-xyz/anchor";
 import { AnchorProgramExample } from "../target/types/anchor_program_example";
 
 describe("Account Data!", () => {
-
   const provider = anchor.AnchorProvider.env();
   anchor.setProvider(provider);
   const payer = provider.wallet as anchor.Wallet;
-  const program = anchor.workspace.AnchorProgramExample as anchor.Program<AnchorProgramExample>;
+  const program = anchor.workspace
+    .AnchorProgramExample as anchor.Program<AnchorProgramExample>;
 
   const addressInfoAccount = anchor.web3.Keypair.generate();
 
   it("Create the address info account", async () => {
     console.log(`Payer Address      : ${payer.publicKey}`);
     console.log(`Address Info Acct  : ${addressInfoAccount.publicKey}`);
-    await program.methods.createAddressInfo(
-      "Joe C",
-      136,
-      "Mile High Dr.",
-      "Solana Beach",
-    )
+    await program.methods
+      .createAddressInfo("Joe C", 136, "Mile High Dr.", "Solana Beach")
       .accounts({
         addressInfo: addressInfoAccount.publicKey,
         payer: payer.publicKey,

+ 12 - 12
basics/checking-accounts/anchor/package.json

@@ -1,14 +1,14 @@
 {
-    "dependencies": {
-        "@project-serum/anchor": "^0.24.2"
-    },
-    "devDependencies": {
-        "@types/bn.js": "^5.1.0",
-        "@types/chai": "^4.3.0",
-        "@types/mocha": "^9.0.0",
-        "chai": "^4.3.4",
-        "mocha": "^9.0.3",
-        "ts-mocha": "^10.0.0",
-        "typescript": "^4.3.5"
-    }
+  "dependencies": {
+    "@coral-xyz/anchor": "^0.28.0"
+  },
+  "devDependencies": {
+    "@types/bn.js": "^5.1.0",
+    "@types/chai": "^4.3.0",
+    "@types/mocha": "^9.0.0",
+    "chai": "^4.3.4",
+    "mocha": "^9.0.3",
+    "ts-mocha": "^10.0.0",
+    "typescript": "^4.3.5"
+  }
 }

+ 13 - 15
basics/checking-accounts/anchor/tests/test.ts

@@ -1,11 +1,11 @@
-import * as anchor from "@project-serum/anchor";
+import * as anchor from "@coral-xyz/anchor";
 import { AnchorProgramExample } from "../target/types/anchor_program_example";
 
 describe("Anchor example", () => {
-
   const provider = anchor.AnchorProvider.env();
   anchor.setProvider(provider);
-  const program = anchor.workspace.AnchorProgramExample as anchor.Program<AnchorProgramExample>;
+  const program = anchor.workspace
+    .AnchorProgramExample as anchor.Program<AnchorProgramExample>;
   const payer = provider.wallet as anchor.Wallet;
 
   // We'll create this ahead of time.
@@ -15,25 +15,24 @@ describe("Anchor example", () => {
   const accountToCreate = anchor.web3.Keypair.generate();
 
   it("Create an account owned by our program", async () => {
-
     let ix = anchor.web3.SystemProgram.createAccount({
-        fromPubkey: provider.wallet.publicKey,
-        newAccountPubkey: accountToChange.publicKey,
-        lamports: await provider.connection.getMinimumBalanceForRentExemption(0),
-        space: 0,
-        programId: program.programId, // Our program
+      fromPubkey: provider.wallet.publicKey,
+      newAccountPubkey: accountToChange.publicKey,
+      lamports: await provider.connection.getMinimumBalanceForRentExemption(0),
+      space: 0,
+      programId: program.programId, // Our program
     });
 
     await anchor.web3.sendAndConfirmTransaction(
-        provider.connection, 
-        new anchor.web3.Transaction().add(ix),
-        [payer.payer, accountToChange]
+      provider.connection,
+      new anchor.web3.Transaction().add(ix),
+      [payer.payer, accountToChange]
     );
   });
 
   it("Check accounts", async () => {
-    
-    await program.methods.checkAccounts()
+    await program.methods
+      .checkAccounts()
       .accounts({
         payer: provider.wallet.publicKey,
         accountToCreate: accountToCreate.publicKey,
@@ -42,6 +41,5 @@ describe("Anchor example", () => {
       })
       .signers([payer.payer])
       .rpc();
-
   });
 });

+ 1 - 1
basics/close-account/anchor/migrations/deploy.ts

@@ -2,7 +2,7 @@
 // single deploy script that's invoked from the CLI, injecting a provider
 // configured from the workspace's Anchor.toml.
 
-const anchor = require("@project-serum/anchor");
+const anchor = require("@coral-xyz/anchor");
 
 module.exports = async function (provider) {
   // Configure client to use the provider.

+ 17 - 17
basics/close-account/anchor/package.json

@@ -1,19 +1,19 @@
 {
-    "scripts": {
-        "lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
-        "lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
-    },
-    "dependencies": {
-        "@project-serum/anchor": "^0.25.0"
-    },
-    "devDependencies": {
-        "chai": "^4.3.4",
-        "mocha": "^9.0.3",
-        "ts-mocha": "^10.0.0",
-        "@types/bn.js": "^5.1.0",
-        "@types/chai": "^4.3.0",
-        "@types/mocha": "^9.0.0",
-        "typescript": "^4.3.5",
-        "prettier": "^2.6.2"
-    }
+  "scripts": {
+    "lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
+    "lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
+  },
+  "dependencies": {
+    "@coral-xyz/anchor": "^0.28.0"
+  },
+  "devDependencies": {
+    "chai": "^4.3.4",
+    "mocha": "^9.0.3",
+    "ts-mocha": "^10.0.0",
+    "@types/bn.js": "^5.1.0",
+    "@types/chai": "^4.3.0",
+    "@types/mocha": "^9.0.0",
+    "typescript": "^4.3.5",
+    "prettier": "^2.6.2"
+  }
 }

+ 84 - 67
basics/close-account/anchor/tests/close-account.ts

@@ -1,82 +1,99 @@
-import * as anchor from "@project-serum/anchor";
-import { Program } from "@project-serum/anchor";
-import {Keypair, LAMPORTS_PER_SOL} from "@solana/web3.js";
+import * as anchor from "@coral-xyz/anchor";
+import { Program } from "@coral-xyz/anchor";
+import { Keypair, LAMPORTS_PER_SOL } from "@solana/web3.js";
 import { CloseAccountProgram } from "../target/types/close_account_program";
-import {BlockheightBasedTransactionConfirmationStrategy, PublicKey} from "@solana/web3.js";
+import {
+  BlockheightBasedTransactionConfirmationStrategy,
+  PublicKey,
+} from "@solana/web3.js";
 import assert from "assert";
 
 describe("close-an-account", () => {
-    // Configure the client to use the local cluster.
-    anchor.setProvider(anchor.AnchorProvider.env());
+  // Configure the client to use the local cluster.
+  anchor.setProvider(anchor.AnchorProvider.env());
 
-    const program = anchor.workspace.CloseAccountProgram as Program<CloseAccountProgram>;
-    const connection = program.provider.connection;
-    const payer = Keypair.generate();
+  const program = anchor.workspace
+    .CloseAccountProgram as Program<CloseAccountProgram>;
+  const connection = program.provider.connection;
+  const payer = Keypair.generate();
 
-    async function airdrop(receiver: PublicKey, amount: number) {
-        const sig = await program.provider.connection.requestAirdrop(receiver, amount);
-        const blockStats = await program.provider.connection.getLatestBlockhash();
-        const strategy: BlockheightBasedTransactionConfirmationStrategy = {
-            signature: sig,
-            blockhash: blockStats.blockhash,
-            lastValidBlockHeight: blockStats.lastValidBlockHeight
-        }
-        await program.provider.connection.confirmTransaction(strategy, "confirmed");
-    }
+  async function airdrop(receiver: PublicKey, amount: number) {
+    const sig = await program.provider.connection.requestAirdrop(
+      receiver,
+      amount
+    );
+    const blockStats = await program.provider.connection.getLatestBlockhash();
+    const strategy: BlockheightBasedTransactionConfirmationStrategy = {
+      signature: sig,
+      blockhash: blockStats.blockhash,
+      lastValidBlockHeight: blockStats.lastValidBlockHeight,
+    };
+    await program.provider.connection.confirmTransaction(strategy, "confirmed");
+  }
 
-    function getUserAccount(user: PublicKey): [PublicKey, number] {
-        return PublicKey.findProgramAddressSync(
-            [
-                Buffer.from("USER"),
-                user.toBuffer()
-            ], program.programId)
-    }
+  function getUserAccount(user: PublicKey): [PublicKey, number] {
+    return PublicKey.findProgramAddressSync(
+      [Buffer.from("USER"), user.toBuffer()],
+      program.programId
+    );
+  }
 
-    it("Airdrop", async () => {
-        const balanceBefore = await connection.getBalance(payer.publicKey);
-        await airdrop(payer.publicKey, LAMPORTS_PER_SOL);
-        const balanceAfter = await connection.getBalance(payer.publicKey);
-        assert.equal(balanceAfter, balanceBefore + LAMPORTS_PER_SOL);
-    });
+  it("Airdrop", async () => {
+    const balanceBefore = await connection.getBalance(payer.publicKey);
+    await airdrop(payer.publicKey, LAMPORTS_PER_SOL);
+    const balanceAfter = await connection.getBalance(payer.publicKey);
+    assert.equal(balanceAfter, balanceBefore + LAMPORTS_PER_SOL);
+  });
 
+  it("Create Account", async () => {
+    const [userAccountAddress] = getUserAccount(payer.publicKey);
+    const userAccountBefore = await program.account.user.fetchNullable(
+      userAccountAddress,
+      "confirmed"
+    );
+    assert.equal(userAccountBefore, null);
 
-    it("Create Account", async () => {
-        const [userAccountAddress] = getUserAccount(payer.publicKey);
-        const userAccountBefore = await program.account.user.fetchNullable(userAccountAddress, "confirmed");
-        assert.equal(userAccountBefore, null);
+    await program.methods
+      .createUser({
+        name: "John Doe",
+      })
+      .accounts({
+        payer: payer.publicKey,
+        userAccount: userAccountAddress,
+      })
+      .signers([payer])
+      .rpc({ commitment: "confirmed", skipPreflight: true });
 
-        await program.methods
-            .createUser({
-                name: "John Doe"
-            })
-            .accounts({
-                payer: payer.publicKey,
-                userAccount: userAccountAddress
-            })
-            .signers([payer])
-            .rpc({commitment: "confirmed", skipPreflight: true});
+    const userAccountAfter = await program.account.user.fetchNullable(
+      userAccountAddress,
+      "confirmed"
+    );
+    assert.notEqual(userAccountAfter, null);
+    assert.equal(userAccountAfter.name, "John Doe");
+    assert.equal(userAccountAfter.user.toBase58(), payer.publicKey.toBase58());
+  });
 
-        const userAccountAfter = await program.account.user.fetchNullable(userAccountAddress, "confirmed");
-        assert.notEqual(userAccountAfter, null);
-        assert.equal(userAccountAfter.name, "John Doe");
-        assert.equal(userAccountAfter.user.toBase58(), payer.publicKey.toBase58());
-    })
+  it("Close Account", async () => {
+    const [userAccountAddress] = getUserAccount(payer.publicKey);
+    const userAccountBefore = await program.account.user.fetchNullable(
+      userAccountAddress,
+      "confirmed"
+    );
+    assert.notEqual(userAccountBefore, null);
 
-    it("Close Account", async () => {
-        const [userAccountAddress] = getUserAccount(payer.publicKey);
-        const userAccountBefore = await program.account.user.fetchNullable(userAccountAddress, "confirmed");
-        assert.notEqual(userAccountBefore, null);
+    await program.methods
+      .closeUser()
+      .accounts({
+        user: payer.publicKey,
+        userAccount: userAccountAddress,
+      })
+      .signers([payer])
+      .rpc({ commitment: "confirmed" });
 
-        await program.methods
-            .closeUser()
-            .accounts({
-                user: payer.publicKey,
-                userAccount: userAccountAddress
-            })
-            .signers([payer])
-            .rpc({commitment: "confirmed"});
-
-        const userAccountAfter = await program.account.user.fetchNullable(userAccountAddress, "processed");
-        assert.equal(userAccountAfter, null);
-    })
+    const userAccountAfter = await program.account.user.fetchNullable(
+      userAccountAddress,
+      "processed"
+    );
+    assert.equal(userAccountAfter, null);
+  });
 });

+ 1 - 1
basics/counter/anchor/migrations/deploy.ts

@@ -2,7 +2,7 @@
 // single deploy script that's invoked from the CLI, injecting a provider
 // configured from the workspace's Anchor.toml.
 
-const anchor = require("@project-serum/anchor");
+const anchor = require("@coral-xyz/anchor");
 
 module.exports = async function (provider) {
   // Configure client to use the provider.

+ 17 - 17
basics/counter/anchor/package.json

@@ -1,19 +1,19 @@
 {
-    "scripts": {
-        "lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
-        "lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
-    },
-    "dependencies": {
-        "@project-serum/anchor": "^0.25.0"
-    },
-    "devDependencies": {
-        "chai": "^4.3.4",
-        "mocha": "^9.0.3",
-        "ts-mocha": "^10.0.0",
-        "@types/bn.js": "^5.1.0",
-        "@types/chai": "^4.3.0",
-        "@types/mocha": "^9.0.0",
-        "typescript": "^4.3.5",
-        "prettier": "^2.6.2"
-    }
+  "scripts": {
+    "lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
+    "lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
+  },
+  "dependencies": {
+    "@coral-xyz/anchor": "^0.28.0"
+  },
+  "devDependencies": {
+    "chai": "^4.3.4",
+    "mocha": "^9.0.3",
+    "ts-mocha": "^10.0.0",
+    "@types/bn.js": "^5.1.0",
+    "@types/chai": "^4.3.0",
+    "@types/mocha": "^9.0.0",
+    "typescript": "^4.3.5",
+    "prettier": "^2.6.2"
+  }
 }

+ 12 - 8
basics/counter/anchor/tests/counter_anchor.ts

@@ -1,8 +1,6 @@
-import * as anchor from "@project-serum/anchor";
-import { Program } from "@project-serum/anchor";
-import {
-  Keypair
-} from '@solana/web3.js'
+import * as anchor from "@coral-xyz/anchor";
+import { Program } from "@coral-xyz/anchor";
+import { Keypair } from "@solana/web3.js";
 import { assert } from "chai";
 import { CounterAnchor } from "../target/types/counter_anchor";
 
@@ -22,7 +20,9 @@ describe("counter_anchor", () => {
       .accounts({ counter, payer: program.provider.publicKey })
       .signers([counterKeypair])
       .rpc({ skipPreflight: true, commitment: "confirmed" });
-    let currentCount = (await program.account.counter.fetch(counter, "confirmed")).count.toNumber();
+    let currentCount = (
+      await program.account.counter.fetch(counter, "confirmed")
+    ).count.toNumber();
     assert(currentCount === 0, "Expected initialized count to be 0");
 
     // Increment counter
@@ -30,7 +30,9 @@ describe("counter_anchor", () => {
       .increment()
       .accounts({ counter })
       .rpc({ skipPreflight: true, commitment: "confirmed" });
-    currentCount = (await program.account.counter.fetch(counter, "confirmed")).count.toNumber();
+    currentCount = (
+      await program.account.counter.fetch(counter, "confirmed")
+    ).count.toNumber();
     assert(currentCount === 1, "Expected count to be 1");
 
     // Increment counter
@@ -38,7 +40,9 @@ describe("counter_anchor", () => {
       .increment()
       .accounts({ counter })
       .rpc({ skipPreflight: true, commitment: "confirmed" });
-    currentCount = (await program.account.counter.fetch(counter, "confirmed")).count.toNumber();
+    currentCount = (
+      await program.account.counter.fetch(counter, "confirmed")
+    ).count.toNumber();
     assert(currentCount === 2, "Expected count to be 2");
   });
 });

+ 1 - 1
basics/counter/seahorse/migrations/deploy.ts

@@ -2,7 +2,7 @@
 // single deploy script that's invoked from the CLI, injecting a provider
 // configured from the workspace's Anchor.toml.
 
-const anchor = require("@project-serum/anchor");
+const anchor = require("@coral-xyz/anchor");
 
 module.exports = async function (provider) {
   // Configure client to use the provider.

+ 17 - 17
basics/counter/seahorse/package.json

@@ -1,19 +1,19 @@
 {
-    "scripts": {
-        "lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
-        "lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
-    },
-    "dependencies": {
-        "@project-serum/anchor": "^0.25.0"
-    },
-    "devDependencies": {
-        "chai": "^4.3.4",
-        "mocha": "^9.0.3",
-        "ts-mocha": "^10.0.0",
-        "@types/bn.js": "^5.1.0",
-        "@types/chai": "^4.3.0",
-        "@types/mocha": "^9.0.0",
-        "typescript": "^4.3.5",
-        "prettier": "^2.6.2"
-    }
+  "scripts": {
+    "lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
+    "lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
+  },
+  "dependencies": {
+    "@coral-xyz/anchor": "^0.28.0"
+  },
+  "devDependencies": {
+    "chai": "^4.3.4",
+    "mocha": "^9.0.3",
+    "ts-mocha": "^10.0.0",
+    "@types/bn.js": "^5.1.0",
+    "@types/chai": "^4.3.0",
+    "@types/mocha": "^9.0.0",
+    "typescript": "^4.3.5",
+    "prettier": "^2.6.2"
+  }
 }

+ 7 - 9
basics/counter/seahorse/tests/counter_seahorse.ts

@@ -1,10 +1,6 @@
-import * as anchor from "@project-serum/anchor";
-import { Program } from "@project-serum/anchor";
-import {
-  Keypair,
-  PublicKey,
-  SystemProgram
-} from '@solana/web3.js';
+import * as anchor from "@coral-xyz/anchor";
+import { Program } from "@coral-xyz/anchor";
+import { Keypair, PublicKey, SystemProgram } from "@solana/web3.js";
 import { assert } from "chai";
 import { CounterSeahorse } from "../target/types/counter_seahorse";
 
@@ -33,11 +29,13 @@ describe("counter_seahorse", () => {
     await program.methods
       .increment()
       .accounts({
-        counter
+        counter,
       })
       .rpc();
 
-    const count = (await program.account.counter.fetch(counter)).count.toNumber();
+    const count = (
+      await program.account.counter.fetch(counter)
+    ).count.toNumber();
     assert(count === 1, "Expected count to be 1");
   });
 });

+ 12 - 12
basics/create-account/anchor/package.json

@@ -1,14 +1,14 @@
 {
-    "dependencies": {
-        "@project-serum/anchor": "^0.24.2"
-    },
-    "devDependencies": {
-        "@types/bn.js": "^5.1.0",
-        "@types/chai": "^4.3.0",
-        "@types/mocha": "^9.0.0",
-        "chai": "^4.3.4",
-        "mocha": "^9.0.3",
-        "ts-mocha": "^10.0.0",
-        "typescript": "^4.3.5"
-    }
+  "dependencies": {
+    "@coral-xyz/anchor": "^0.28.0"
+  },
+  "devDependencies": {
+    "@types/bn.js": "^5.1.0",
+    "@types/chai": "^4.3.0",
+    "@types/mocha": "^9.0.0",
+    "chai": "^4.3.4",
+    "mocha": "^9.0.3",
+    "ts-mocha": "^10.0.0",
+    "typescript": "^4.3.5"
+  }
 }

+ 12 - 14
basics/create-account/anchor/tests/test.ts

@@ -1,26 +1,24 @@
-import * as anchor from "@project-serum/anchor";
+import * as anchor from "@coral-xyz/anchor";
 import { CreateSystemAccount } from "../target/types/create_system_account";
 
-
 describe("Create a system account", () => {
-
   const provider = anchor.AnchorProvider.env();
   anchor.setProvider(provider);
   const wallet = provider.wallet as anchor.Wallet;
-  const program = anchor.workspace.CreateSystemAccount as anchor.Program<CreateSystemAccount>;
+  const program = anchor.workspace
+    .CreateSystemAccount as anchor.Program<CreateSystemAccount>;
 
   it("Create the account", async () => {
-
     const newKeypair = anchor.web3.Keypair.generate();
-    
-    await program.methods.createSystemAccount()
-    .accounts({
-      payer: wallet.publicKey,
-      newAccount: newKeypair.publicKey,
-      systemProgram: anchor.web3.SystemProgram.programId
-    })
-    .signers([wallet.payer, newKeypair])
-    .rpc();
 
+    await program.methods
+      .createSystemAccount()
+      .accounts({
+        payer: wallet.publicKey,
+        newAccount: newKeypair.publicKey,
+        systemProgram: anchor.web3.SystemProgram.programId,
+      })
+      .signers([wallet.payer, newKeypair])
+      .rpc();
   });
 });

+ 12 - 12
basics/cross-program-invocation/anchor/package.json

@@ -1,14 +1,14 @@
 {
-    "dependencies": {
-        "@project-serum/anchor": "^0.24.2"
-    },
-    "devDependencies": {
-        "@types/bn.js": "^5.1.0",
-        "@types/chai": "^4.3.0",
-        "@types/mocha": "^9.0.0",
-        "chai": "^4.3.4",
-        "mocha": "^9.0.3",
-        "ts-mocha": "^10.0.0",
-        "typescript": "^4.3.5"
-    }
+  "dependencies": {
+    "@coral-xyz/anchor": "^0.28.0"
+  },
+  "devDependencies": {
+    "@types/bn.js": "^5.1.0",
+    "@types/chai": "^4.3.0",
+    "@types/mocha": "^9.0.0",
+    "chai": "^4.3.4",
+    "mocha": "^9.0.3",
+    "ts-mocha": "^10.0.0",
+    "typescript": "^4.3.5"
+  }
 }

+ 24 - 28
basics/cross-program-invocation/anchor/tests/test.ts

@@ -1,9 +1,8 @@
-import * as anchor from "@project-serum/anchor";
+import * as anchor from "@coral-xyz/anchor";
 import { Hand } from "../target/types/hand";
 import { Lever } from "../target/types/lever";
 
 describe("CPI Example", () => {
-  
   const provider = anchor.AnchorProvider.env();
   anchor.setProvider(provider);
   const hand = anchor.workspace.Hand as anchor.Program<Hand>;
@@ -12,37 +11,34 @@ describe("CPI Example", () => {
   const powerAccount = anchor.web3.Keypair.generate();
 
   it("Initialize the lever!", async () => {
-    
-    await lever.methods.initialize()
-    .accounts({
-      power: powerAccount.publicKey,
-      user: provider.wallet.publicKey,
-      systemProgram: anchor.web3.SystemProgram.programId,
-    })
-    .signers([powerAccount])
-    .rpc();
-
+    await lever.methods
+      .initialize()
+      .accounts({
+        power: powerAccount.publicKey,
+        user: provider.wallet.publicKey,
+        systemProgram: anchor.web3.SystemProgram.programId,
+      })
+      .signers([powerAccount])
+      .rpc();
   });
 
   it("Pull the lever!", async () => {
-
-    await hand.methods.pullLever("Chris")
-    .accounts({
-      power: powerAccount.publicKey,
-      leverProgram: lever.programId,
-    })
-    .rpc();
-
+    await hand.methods
+      .pullLever("Chris")
+      .accounts({
+        power: powerAccount.publicKey,
+        leverProgram: lever.programId,
+      })
+      .rpc();
   });
 
   it("Pull it again!", async () => {
-
-    await hand.methods.pullLever("Ashley")
-    .accounts({
-      power: powerAccount.publicKey,
-      leverProgram: lever.programId,
-    })
-    .rpc();
-
+    await hand.methods
+      .pullLever("Ashley")
+      .accounts({
+        power: powerAccount.publicKey,
+        leverProgram: lever.programId,
+      })
+      .rpc();
   });
 });

+ 12 - 12
basics/hello-solana/anchor/package.json

@@ -1,14 +1,14 @@
 {
-    "dependencies": {
-        "@project-serum/anchor": "^0.24.2"
-    },
-    "devDependencies": {
-        "@types/bn.js": "^5.1.0",
-        "@types/chai": "^4.3.0",
-        "@types/mocha": "^9.0.0",
-        "chai": "^4.3.4",
-        "mocha": "^9.0.3",
-        "ts-mocha": "^10.0.0",
-        "typescript": "^4.3.5"
-    }
+  "dependencies": {
+    "@coral-xyz/anchor": "^0.28.0"
+  },
+  "devDependencies": {
+    "@types/bn.js": "^5.1.0",
+    "@types/chai": "^4.3.0",
+    "@types/mocha": "^9.0.0",
+    "chai": "^4.3.4",
+    "mocha": "^9.0.3",
+    "ts-mocha": "^10.0.0",
+    "typescript": "^4.3.5"
+  }
 }

+ 2 - 7
basics/hello-solana/anchor/tests/test.ts

@@ -1,8 +1,7 @@
-import * as anchor from "@project-serum/anchor";
+import * as anchor from "@coral-xyz/anchor";
 import { HelloSolana } from "../target/types/hello_solana";
 
 describe("hello-solana", () => {
-  
   // Configure the Anchor provider & load the program IDL
   // The IDL gives you a typescript module
   //
@@ -11,12 +10,8 @@ describe("hello-solana", () => {
   const program = anchor.workspace.HelloSolana as anchor.Program<HelloSolana>;
 
   it("Say hello!", async () => {
-    
     // Just run Anchor's IDL method to build a transaction!
     //
-    await program.methods.hello()
-    .accounts({})
-    .rpc();
-
+    await program.methods.hello().accounts({}).rpc();
   });
 });

+ 1 - 1
basics/hello-solana/seahorse/hello_solana/migrations/deploy.ts

@@ -2,7 +2,7 @@
 // single deploy script that's invoked from the CLI, injecting a provider
 // configured from the workspace's Anchor.toml.
 
-const anchor = require("@project-serum/anchor");
+const anchor = require("@coral-xyz/anchor");
 
 module.exports = async function (provider) {
   // Configure client to use the provider.

+ 17 - 17
basics/hello-solana/seahorse/hello_solana/package.json

@@ -1,19 +1,19 @@
 {
-    "scripts": {
-        "lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
-        "lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
-    },
-    "dependencies": {
-        "@project-serum/anchor": "^0.24.2"
-    },
-    "devDependencies": {
-        "@types/bn.js": "^5.1.0",
-        "@types/chai": "^4.3.0",
-        "@types/mocha": "^9.0.0",
-        "chai": "^4.3.4",
-        "mocha": "^9.0.3",
-        "prettier": "^2.6.2",
-        "ts-mocha": "^10.0.0",
-        "typescript": "^4.3.5"
-    }
+  "scripts": {
+    "lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
+    "lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
+  },
+  "dependencies": {
+    "@coral-xyz/anchor": "^0.28.0"
+  },
+  "devDependencies": {
+    "@types/bn.js": "^5.1.0",
+    "@types/chai": "^4.3.0",
+    "@types/mocha": "^9.0.0",
+    "chai": "^4.3.4",
+    "mocha": "^9.0.3",
+    "prettier": "^2.6.2",
+    "ts-mocha": "^10.0.0",
+    "typescript": "^4.3.5"
+  }
 }

+ 8 - 9
basics/hello-solana/seahorse/hello_solana/tests/hello_solana.ts

@@ -1,8 +1,7 @@
-import * as anchor from "@project-serum/anchor";
+import * as anchor from "@coral-xyz/anchor";
 import { HelloSolana } from "../target/types/hello_solana";
 
 describe("hello_solana", () => {
-
   // Configure the client to use the local cluster.
   const provider = anchor.AnchorProvider.env();
   anchor.setProvider(provider);
@@ -10,14 +9,14 @@ describe("hello_solana", () => {
   const payer = provider.wallet as anchor.Wallet;
 
   it("Say hello!", async () => {
-
     // Just run Anchor's IDL method to build a transaction
     // and sign it via a signer.
-    await program.methods.hello()
-        .accounts({
-          signer: provider.wallet.publicKey,
-        })
-        .signers([payer.payer])
-        .rpc();
+    await program.methods
+      .hello()
+      .accounts({
+        signer: provider.wallet.publicKey,
+      })
+      .signers([payer.payer])
+      .rpc();
   });
 });

+ 12 - 12
basics/pda-rent-payer/anchor/package.json

@@ -1,14 +1,14 @@
 {
-    "dependencies": {
-        "@project-serum/anchor": "^0.24.2"
-    },
-    "devDependencies": {
-        "@types/bn.js": "^5.1.0",
-        "@types/chai": "^4.3.0",
-        "@types/mocha": "^9.0.0",
-        "chai": "^4.3.4",
-        "mocha": "^9.0.3",
-        "ts-mocha": "^10.0.0",
-        "typescript": "^4.3.5"
-    }
+  "dependencies": {
+    "@coral-xyz/anchor": "^0.28.0"
+  },
+  "devDependencies": {
+    "@types/bn.js": "^5.1.0",
+    "@types/chai": "^4.3.0",
+    "@types/mocha": "^9.0.0",
+    "chai": "^4.3.4",
+    "mocha": "^9.0.3",
+    "ts-mocha": "^10.0.0",
+    "typescript": "^4.3.5"
+  }
 }

+ 26 - 25
basics/pda-rent-payer/anchor/tests/test.ts

@@ -1,42 +1,43 @@
-import * as anchor from "@project-serum/anchor";
+import * as anchor from "@coral-xyz/anchor";
 import { PdaRentPayer } from "../target/types/pda_rent_payer";
 
 describe("PDA Rent-Payer", () => {
-
   const provider = anchor.AnchorProvider.env();
   anchor.setProvider(provider);
   const wallet = provider.wallet as anchor.Wallet;
   const program = anchor.workspace.PdaRentPayer as anchor.Program<PdaRentPayer>;
 
   function deriveRentVaultPda() {
-      const pda = anchor.web3.PublicKey.findProgramAddressSync(
-          [Buffer.from("rent_vault")],
-          program.programId,
-      )
-      console.log(`PDA: ${pda[0].toBase58()}`)
-      return pda
+    const pda = anchor.web3.PublicKey.findProgramAddressSync(
+      [Buffer.from("rent_vault")],
+      program.programId
+    );
+    console.log(`PDA: ${pda[0].toBase58()}`);
+    return pda;
   }
 
   it("Initialize the Rent Vault", async () => {
-      const [rentVaultPda, _] = deriveRentVaultPda();
-      await program.methods.initRentVault(new anchor.BN(1000000000))
-        .accounts({
-          rentVault: rentVaultPda,
-          payer: wallet.publicKey,
-        })
-        .signers([wallet.payer])
-        .rpc()
+    const [rentVaultPda, _] = deriveRentVaultPda();
+    await program.methods
+      .initRentVault(new anchor.BN(1000000000))
+      .accounts({
+        rentVault: rentVaultPda,
+        payer: wallet.publicKey,
+      })
+      .signers([wallet.payer])
+      .rpc();
   });
 
   it("Create a new account using the Rent Vault", async () => {
-      const newAccount = anchor.web3.Keypair.generate();
-      const [rentVaultPda, _] = deriveRentVaultPda();
-      await program.methods.createNewAccount()
-        .accounts({
-          newAccount: newAccount.publicKey,
-          rentVault: rentVaultPda,
-        })
-        .signers([wallet.payer])
-        .rpc()
+    const newAccount = anchor.web3.Keypair.generate();
+    const [rentVaultPda, _] = deriveRentVaultPda();
+    await program.methods
+      .createNewAccount()
+      .accounts({
+        newAccount: newAccount.publicKey,
+        rentVault: rentVaultPda,
+      })
+      .signers([wallet.payer])
+      .rpc();
   });
 });

+ 12 - 12
basics/processing-instructions/anchor/package.json

@@ -1,14 +1,14 @@
 {
-    "dependencies": {
-        "@project-serum/anchor": "^0.24.2"
-    },
-    "devDependencies": {
-        "@types/bn.js": "^5.1.0",
-        "@types/chai": "^4.3.0",
-        "@types/mocha": "^9.0.0",
-        "chai": "^4.3.4",
-        "mocha": "^9.0.3",
-        "ts-mocha": "^10.0.0",
-        "typescript": "^4.3.5"
-    }
+  "dependencies": {
+    "@coral-xyz/anchor": "^0.28.0"
+  },
+  "devDependencies": {
+    "@types/bn.js": "^5.1.0",
+    "@types/chai": "^4.3.0",
+    "@types/mocha": "^9.0.0",
+    "chai": "^4.3.4",
+    "mocha": "^9.0.3",
+    "ts-mocha": "^10.0.0",
+    "typescript": "^4.3.5"
+  }
 }

+ 5 - 12
basics/processing-instructions/anchor/tests/test.ts

@@ -1,23 +1,16 @@
-import * as anchor from "@project-serum/anchor";
+import * as anchor from "@coral-xyz/anchor";
 import { ProcessingInstructions } from "../target/types/processing_instructions";
 
-
 describe("custom-instruction-data", () => {
-
   const provider = anchor.AnchorProvider.env();
   anchor.setProvider(provider);
-  const program = anchor.workspace.ProcessingInstructions as anchor.Program<ProcessingInstructions>;
+  const program = anchor.workspace
+    .ProcessingInstructions as anchor.Program<ProcessingInstructions>;
 
   it("Go to the park!", async () => {
-    
     // Again, Anchor makes it super simple.
     //
-    await program.methods.goToPark("Jimmy", 3)
-    .accounts({})
-    .rpc();
-    await program.methods.goToPark("Mary", 10)
-    .accounts({})
-    .rpc();
-
+    await program.methods.goToPark("Jimmy", 3).accounts({}).rpc();
+    await program.methods.goToPark("Mary", 10).accounts({}).rpc();
   });
 });

+ 12 - 12
basics/program-derived-addresses/anchor/package.json

@@ -1,14 +1,14 @@
 {
-    "dependencies": {
-        "@project-serum/anchor": "^0.24.2"
-    },
-    "devDependencies": {
-        "@types/bn.js": "^5.1.0",
-        "@types/chai": "^4.3.0",
-        "@types/mocha": "^9.0.0",
-        "chai": "^4.3.4",
-        "mocha": "^9.0.3",
-        "ts-mocha": "^10.0.0",
-        "typescript": "^4.3.5"
-    }
+  "dependencies": {
+    "@coral-xyz/anchor": "^0.28.0"
+  },
+  "devDependencies": {
+    "@types/bn.js": "^5.1.0",
+    "@types/chai": "^4.3.0",
+    "@types/mocha": "^9.0.0",
+    "chai": "^4.3.4",
+    "mocha": "^9.0.3",
+    "ts-mocha": "^10.0.0",
+    "typescript": "^4.3.5"
+  }
 }

+ 11 - 8
basics/program-derived-addresses/anchor/tests/test.ts

@@ -1,12 +1,12 @@
-import * as anchor from "@project-serum/anchor";
+import * as anchor from "@coral-xyz/anchor";
 import { AnchorProgramExample } from "../target/types/anchor_program_example";
 
 describe("PDAs", () => {
-
   const provider = anchor.AnchorProvider.env();
   anchor.setProvider(provider);
   const payer = provider.wallet as anchor.Wallet;
-  const program = anchor.workspace.AnchorProgramExample as anchor.Program<AnchorProgramExample>;
+  const program = anchor.workspace
+    .AnchorProgramExample as anchor.Program<AnchorProgramExample>;
 
   let testUser = anchor.web3.Keypair.generate();
 
@@ -30,12 +30,13 @@ describe("PDAs", () => {
   function derivePageVisitsPda(userPubkey: anchor.web3.PublicKey) {
     return anchor.web3.PublicKey.findProgramAddressSync(
       [Buffer.from("page_visits"), userPubkey.toBuffer()],
-      program.programId,
-    )[0]
+      program.programId
+    )[0];
   }
 
   it("Create the page visits tracking PDA", async () => {
-    await program.methods.createPageVisits()
+    await program.methods
+      .createPageVisits()
       .accounts({
         pageVisits: derivePageVisitsPda(testUser.publicKey),
         user: testUser.publicKey,
@@ -47,7 +48,8 @@ describe("PDAs", () => {
   });
 
   it("Visit the page!", async () => {
-    await program.methods.incrementPageVisits()
+    await program.methods
+      .incrementPageVisits()
       .accounts({
         pageVisits: derivePageVisitsPda(testUser.publicKey),
         user: testUser.publicKey,
@@ -58,7 +60,8 @@ describe("PDAs", () => {
   });
 
   it("Visit the page!", async () => {
-    await program.methods.incrementPageVisits()
+    await program.methods
+      .incrementPageVisits()
       .accounts({
         pageVisits: derivePageVisitsPda(testUser.publicKey),
         user: testUser.publicKey,

+ 12 - 12
basics/rent/anchor/package.json

@@ -1,14 +1,14 @@
 {
-    "dependencies": {
-        "@project-serum/anchor": "0.25.0"
-    },
-    "devDependencies": {
-        "@types/bn.js": "^5.1.0",
-        "@types/chai": "^4.3.0",
-        "@types/mocha": "^9.0.0",
-        "chai": "^4.3.4",
-        "mocha": "^9.0.3",
-        "ts-mocha": "^10.0.0",
-        "typescript": "^4.3.5"
-    }
+  "dependencies": {
+    "@coral-xyz/anchor": "^0.28.0"
+  },
+  "devDependencies": {
+    "@types/bn.js": "^5.1.0",
+    "@types/chai": "^4.3.0",
+    "@types/mocha": "^9.0.0",
+    "chai": "^4.3.4",
+    "mocha": "^9.0.3",
+    "ts-mocha": "^10.0.0",
+    "typescript": "^4.3.5"
+  }
 }

+ 15 - 15
basics/rent/anchor/tests/test.ts

@@ -1,37 +1,37 @@
-import * as anchor from "@project-serum/anchor";
+import * as anchor from "@coral-xyz/anchor";
 import { RentExample, IDL } from "../target/types/rent_example";
 
-
 describe("Create a system account", () => {
-
   const provider = anchor.AnchorProvider.env();
   anchor.setProvider(provider);
   const wallet = provider.wallet as anchor.Wallet;
   const program = anchor.workspace.RentExample as anchor.Program<RentExample>;
 
   it("Create the account", async () => {
-
     const newKeypair = anchor.web3.Keypair.generate();
 
     const addressData: anchor.IdlTypes<RentExample>["AddressData"] = {
       name: "Marcus",
-      address: "123 Main St. San Francisco, CA"
+      address: "123 Main St. San Francisco, CA",
     };
 
     // We're just going to serialize our object here so we can check
     //  the size on the client side against the program logs
     //
-    const addressDataBuffer = new anchor.BorshCoder(IDL).types.encode("AddressData", addressData);
+    const addressDataBuffer = new anchor.BorshCoder(IDL).types.encode(
+      "AddressData",
+      addressData
+    );
     console.log(`Address data buffer length: ${addressDataBuffer.length}`);
-    
-    await program.methods.createSystemAccount(addressData)
-    .accounts({
-      payer: wallet.publicKey,
-      newAccount: newKeypair.publicKey,
-      systemProgram: anchor.web3.SystemProgram.programId
-    })
-    .signers([wallet.payer, newKeypair])
-    .rpc();
 
+    await program.methods
+      .createSystemAccount(addressData)
+      .accounts({
+        payer: wallet.publicKey,
+        newAccount: newKeypair.publicKey,
+        systemProgram: anchor.web3.SystemProgram.programId,
+      })
+      .signers([wallet.payer, newKeypair])
+      .rpc();
   });
 });

+ 12 - 12
basics/repository-layout/anchor/package.json

@@ -1,14 +1,14 @@
 {
-    "dependencies": {
-        "@project-serum/anchor": "^0.24.2"
-    },
-    "devDependencies": {
-        "@types/bn.js": "^5.1.0",
-        "@types/chai": "^4.3.0",
-        "@types/mocha": "^9.0.0",
-        "chai": "^4.3.4",
-        "mocha": "^9.0.3",
-        "ts-mocha": "^10.0.0",
-        "typescript": "^4.3.5"
-    }
+  "dependencies": {
+    "@coral-xyz/anchor": "^0.28.0"
+  },
+  "devDependencies": {
+    "@types/bn.js": "^5.1.0",
+    "@types/chai": "^4.3.0",
+    "@types/mocha": "^9.0.0",
+    "chai": "^4.3.4",
+    "mocha": "^9.0.3",
+    "ts-mocha": "^10.0.0",
+    "typescript": "^4.3.5"
+  }
 }

+ 30 - 31
basics/repository-layout/anchor/tests/test.ts

@@ -1,57 +1,56 @@
-import * as anchor from "@project-serum/anchor";
+import * as anchor from "@coral-xyz/anchor";
 import { Carnival } from "../target/types/carnival";
 
-
-
 describe("Carnival", () => {
-
   const provider = anchor.AnchorProvider.env();
   anchor.setProvider(provider);
   const wallet = provider.wallet as anchor.Wallet;
   const program = anchor.workspace.Carnival as anchor.Program<Carnival>;
 
-  async function sendCarnivalInstructions(instructionsList: anchor.web3.TransactionInstruction[]) {
+  async function sendCarnivalInstructions(
+    instructionsList: anchor.web3.TransactionInstruction[]
+  ) {
     let tx = new anchor.web3.Transaction();
     for (var ix of instructionsList) {
-        tx.add(ix);
-    };
-    await anchor.web3.sendAndConfirmTransaction(
-        provider.connection, 
-        tx,
-        [wallet.payer]
-    );
-}
-
+      tx.add(ix);
+    }
+    await anchor.web3.sendAndConfirmTransaction(provider.connection, tx, [
+      wallet.payer,
+    ]);
+  }
 
   it("Go on some rides!", async () => {
-
     await sendCarnivalInstructions([
-        await program.methods.goOnRide("Jimmy", 36, 15, "Scrambler").instruction(),
-        await program.methods.goOnRide("Mary", 52, 1, "Ferris Wheel").instruction(),
-        await program.methods.goOnRide("Alice", 56, 15, "Scrambler").instruction(),
-        await program.methods.goOnRide("Bob", 49, 6, "Tilt-a-Whirl").instruction(),
+      await program.methods
+        .goOnRide("Jimmy", 36, 15, "Scrambler")
+        .instruction(),
+      await program.methods
+        .goOnRide("Mary", 52, 1, "Ferris Wheel")
+        .instruction(),
+      await program.methods
+        .goOnRide("Alice", 56, 15, "Scrambler")
+        .instruction(),
+      await program.methods
+        .goOnRide("Bob", 49, 6, "Tilt-a-Whirl")
+        .instruction(),
     ]);
   });
 
-
   it("Play some games!", async () => {
-
     await sendCarnivalInstructions([
-        await program.methods.playGame("Jimmy", 15, "I Got It!").instruction(),
-        await program.methods.playGame("Mary", 1, "Ring Toss").instruction(),
-        await program.methods.playGame("Alice", 15, "Ladder Climb").instruction(),
-        await program.methods.playGame("Bob", 6, "Ring Toss").instruction(),
+      await program.methods.playGame("Jimmy", 15, "I Got It!").instruction(),
+      await program.methods.playGame("Mary", 1, "Ring Toss").instruction(),
+      await program.methods.playGame("Alice", 15, "Ladder Climb").instruction(),
+      await program.methods.playGame("Bob", 6, "Ring Toss").instruction(),
     ]);
   });
 
-
   it("Eat some food!", async () => {
-
     await sendCarnivalInstructions([
-        await program.methods.eatFood("Jimmy", 15, "Taco Shack").instruction(),
-        await program.methods.eatFood("Mary", 1, "Larry's Pizza").instruction(),
-        await program.methods.eatFood("Alice", 15, "Dough Boy's").instruction(),
-        await program.methods.eatFood("Bob", 6, "Dough Boy's").instruction(),
+      await program.methods.eatFood("Jimmy", 15, "Taco Shack").instruction(),
+      await program.methods.eatFood("Mary", 1, "Larry's Pizza").instruction(),
+      await program.methods.eatFood("Alice", 15, "Dough Boy's").instruction(),
+      await program.methods.eatFood("Bob", 6, "Dough Boy's").instruction(),
     ]);
   });
 });

+ 12 - 12
basics/transfer-sol/anchor/package.json

@@ -1,14 +1,14 @@
 {
-    "dependencies": {
-        "@project-serum/anchor": "^0.24.2"
-    },
-    "devDependencies": {
-        "@types/bn.js": "^5.1.0",
-        "@types/chai": "^4.3.0",
-        "@types/mocha": "^9.0.0",
-        "chai": "^4.3.4",
-        "mocha": "^9.0.3",
-        "ts-mocha": "^10.0.0",
-        "typescript": "^4.3.5"
-    }
+  "dependencies": {
+    "@coral-xyz/anchor": "^0.28.0"
+  },
+  "devDependencies": {
+    "@types/bn.js": "^5.1.0",
+    "@types/chai": "^4.3.0",
+    "@types/mocha": "^9.0.0",
+    "chai": "^4.3.4",
+    "mocha": "^9.0.3",
+    "ts-mocha": "^10.0.0",
+    "typescript": "^4.3.5"
+  }
 }

+ 24 - 20
basics/transfer-sol/anchor/tests/test.ts

@@ -1,8 +1,7 @@
-import * as anchor from "@project-serum/anchor";
+import * as anchor from "@coral-xyz/anchor";
 import { TransferSol } from "../target/types/transfer_sol";
 
 describe("transfer-sol", () => {
-  
   const provider = anchor.AnchorProvider.env();
   anchor.setProvider(provider);
   const payer = provider.wallet as anchor.Wallet;
@@ -14,10 +13,10 @@ describe("transfer-sol", () => {
   const test2Recipient2 = anchor.web3.Keypair.generate();
 
   it("Transfer between accounts using the system program", async () => {
-
     await getBalances(payer.publicKey, test1Recipient.publicKey, "Beginning");
-    
-    await program.methods.transferSolWithCpi(new anchor.BN(transferAmount))
+
+    await program.methods
+      .transferSolWithCpi(new anchor.BN(transferAmount))
       .accounts({
         payer: payer.publicKey,
         recipient: test1Recipient.publicKey,
@@ -27,11 +26,9 @@ describe("transfer-sol", () => {
       .rpc();
 
     await getBalances(payer.publicKey, test1Recipient.publicKey, "Resulting");
-
   });
 
   it("Create two accounts for the following test", async () => {
-
     const ix = (pubkey: anchor.web3.PublicKey) => {
       return anchor.web3.SystemProgram.createAccount({
         fromPubkey: payer.publicKey,
@@ -39,24 +36,27 @@ describe("transfer-sol", () => {
         space: 0,
         lamports: 2 * anchor.web3.LAMPORTS_PER_SOL,
         programId: program.programId,
-      })
+      });
     };
 
     await anchor.web3.sendAndConfirmTransaction(
       provider.connection,
       new anchor.web3.Transaction()
         .add(ix(test2Recipient1.publicKey))
-        .add(ix(test2Recipient2.publicKey))
-      ,
+        .add(ix(test2Recipient2.publicKey)),
       [payer.payer, test2Recipient1, test2Recipient2]
     );
   });
 
   it("Transfer between accounts using our program", async () => {
+    await getBalances(
+      test2Recipient1.publicKey,
+      test2Recipient2.publicKey,
+      "Beginning"
+    );
 
-    await getBalances(test2Recipient1.publicKey, test2Recipient2.publicKey, "Beginning");
-    
-    await program.methods.transferSolWithProgram(new anchor.BN(transferAmount))
+    await program.methods
+      .transferSolWithProgram(new anchor.BN(transferAmount))
       .accounts({
         payer: test2Recipient1.publicKey,
         recipient: test2Recipient2.publicKey,
@@ -64,20 +64,24 @@ describe("transfer-sol", () => {
       })
       .rpc();
 
-    await getBalances(test2Recipient1.publicKey, test2Recipient2.publicKey, "Resulting");
-
+    await getBalances(
+      test2Recipient1.publicKey,
+      test2Recipient2.publicKey,
+      "Resulting"
+    );
   });
 
   async function getBalances(
-    payerPubkey: anchor.web3.PublicKey, 
-    recipientPubkey: anchor.web3.PublicKey, 
+    payerPubkey: anchor.web3.PublicKey,
+    recipientPubkey: anchor.web3.PublicKey,
     timeframe: string
   ) {
-
     let payerBalance = await provider.connection.getBalance(payerPubkey);
-    let recipientBalance = await provider.connection.getBalance(recipientPubkey);
+    let recipientBalance = await provider.connection.getBalance(
+      recipientPubkey
+    );
     console.log(`${timeframe} balances:`);
     console.log(`   Payer: ${payerBalance}`);
     console.log(`   Recipient: ${recipientBalance}`);
-  };
+  }
 });

+ 20 - 20
compression/cnft-vault/anchor/package.json

@@ -1,22 +1,22 @@
 {
-    "scripts": {
-        "lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
-        "lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
-    },
-    "dependencies": {
-        "@metaplex-foundation/mpl-bubblegum": "^0.6.2",
-        "@project-serum/anchor": "^0.26.0",
-        "@solana/spl-account-compression": "^0.1.8",
-        "axios": "^1.4.0"
-    },
-    "devDependencies": {
-        "@types/bn.js": "^5.1.0",
-        "@types/chai": "^4.3.0",
-        "@types/mocha": "^9.0.0",
-        "chai": "^4.3.4",
-        "mocha": "^9.0.3",
-        "prettier": "^2.6.2",
-        "ts-mocha": "^10.0.0",
-        "typescript": "^4.3.5"
-    }
+  "scripts": {
+    "lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
+    "lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
+  },
+  "dependencies": {
+    "@coral-xyz/anchor": "^0.28.0",
+    "@metaplex-foundation/mpl-bubblegum": "^0.6.2",
+    "@solana/spl-account-compression": "^0.1.8",
+    "axios": "^1.4.0"
+  },
+  "devDependencies": {
+    "@types/bn.js": "^5.1.0",
+    "@types/chai": "^4.3.0",
+    "@types/mocha": "^9.0.0",
+    "chai": "^4.3.4",
+    "mocha": "^9.0.3",
+    "prettier": "^2.6.2",
+    "ts-mocha": "^10.0.0",
+    "typescript": "^4.3.5"
+  }
 }

+ 9 - 5
compression/cnft-vault/anchor/tests/scripts/constants.ts

@@ -1,11 +1,15 @@
-import * as anchor from "@project-serum/anchor";
+import * as anchor from "@coral-xyz/anchor";
 import { CnftVault } from "../../target/types/cnft_vault";
 import { loadWalletKey } from "../utils";
-import { IDL } from "../../target/types/cnft_vault"
+import { IDL } from "../../target/types/cnft_vault";
 
-export const connection = new anchor.web3.Connection("https://api.devnet.solana.com");
+export const connection = new anchor.web3.Connection(
+  "https://api.devnet.solana.com"
+);
 export const keypair = loadWalletKey("~/.config/solana/id.json");
 export const wallet = new anchor.Wallet(keypair);
 export const provider = new anchor.AnchorProvider(connection, wallet, {});
-export const programID = new anchor.web3.PublicKey("CNftyK7T8udPwYRzZUMWzbh79rKrz9a5GwV2wv7iEHpk")
-export const program = new anchor.Program<CnftVault>(IDL, programID, provider);
+export const programID = new anchor.web3.PublicKey(
+  "CNftyK7T8udPwYRzZUMWzbh79rKrz9a5GwV2wv7iEHpk"
+);
+export const program = new anchor.Program<CnftVault>(IDL, programID, provider);

+ 18 - 10
compression/cnft-vault/anchor/tests/scripts/withdraw.ts

@@ -1,7 +1,10 @@
-import * as anchor from "@project-serum/anchor";
+import * as anchor from "@coral-xyz/anchor";
 import { decode, mapProof } from "../utils";
 import { PROGRAM_ID as BUBBLEGUM_PROGRAM_ID } from "@metaplex-foundation/mpl-bubblegum";
-import { SPL_ACCOUNT_COMPRESSION_PROGRAM_ID, SPL_NOOP_PROGRAM_ID } from "@solana/spl-account-compression";
+import {
+  SPL_ACCOUNT_COMPRESSION_PROGRAM_ID,
+  SPL_NOOP_PROGRAM_ID,
+} from "@solana/spl-account-compression";
 import { getAsset, getAssetProof } from "../readAPI";
 
 import { program, programID } from "./constants";
@@ -9,16 +12,20 @@ import { program, programID } from "./constants";
 async function main() {
   const [vaultPDA, _bump] = anchor.web3.PublicKey.findProgramAddressSync(
     [Buffer.from("cNFT-vault", "utf8")],
-    programID,
+    programID
   );
 
-  const tree = new anchor.web3.PublicKey("trezdkTFPKyj4gE9LAJYPpxn8AYVCvM7Mc4JkTb9X5B")
+  const tree = new anchor.web3.PublicKey(
+    "trezdkTFPKyj4gE9LAJYPpxn8AYVCvM7Mc4JkTb9X5B"
+  );
 
-  const receiver = new anchor.web3.PublicKey("Andys9wuoMdUeRiZLgRS5aJwYNFv4Ut6qQi8PNDTAPEM")
+  const receiver = new anchor.web3.PublicKey(
+    "Andys9wuoMdUeRiZLgRS5aJwYNFv4Ut6qQi8PNDTAPEM"
+  );
 
   const [treeAuthority, _bump2] = anchor.web3.PublicKey.findProgramAddressSync(
     [tree.toBuffer()],
-    BUBBLEGUM_PROGRAM_ID,
+    BUBBLEGUM_PROGRAM_ID
   );
 
   const assetId = "DGWU3mHenDerCvjkeDsKYEbsvXbWvqdo1bVoXy3dkeTd";
@@ -34,7 +41,8 @@ async function main() {
   const nonce = new anchor.BN(asset.compression.leaf_id);
   const index = asset.compression.leaf_id;
 
-  const tx = await program.methods.withdrawCnft(root, dataHash, creatorHash, nonce, index)
+  const tx = await program.methods
+    .withdrawCnft(root, dataHash, creatorHash, nonce, index)
     .accounts({
       leafOwner: vaultPDA,
       merkleTree: tree,
@@ -43,11 +51,11 @@ async function main() {
       bubblegumProgram: BUBBLEGUM_PROGRAM_ID,
       compressionProgram: SPL_ACCOUNT_COMPRESSION_PROGRAM_ID,
       logWrapper: SPL_NOOP_PROGRAM_ID,
-      systemProgram: anchor.web3.SystemProgram.programId
+      systemProgram: anchor.web3.SystemProgram.programId,
     })
     .remainingAccounts(proofPathAsAccounts)
     .rpc();
   console.log(tx);
-};
+}
 
-main();
+main();

+ 34 - 18
compression/cnft-vault/anchor/tests/scripts/withdrawTwo.ts

@@ -1,37 +1,47 @@
-import * as anchor from "@project-serum/anchor";
+import * as anchor from "@coral-xyz/anchor";
 import { decode, mapProof } from "../utils";
 import { PROGRAM_ID as BUBBLEGUM_PROGRAM_ID } from "@metaplex-foundation/mpl-bubblegum";
-import { SPL_ACCOUNT_COMPRESSION_PROGRAM_ID, SPL_NOOP_PROGRAM_ID } from "@solana/spl-account-compression";
+import {
+  SPL_ACCOUNT_COMPRESSION_PROGRAM_ID,
+  SPL_NOOP_PROGRAM_ID,
+} from "@solana/spl-account-compression";
 import { getAsset, getAssetProof } from "../readAPI";
 import { AccountMeta } from "@solana/web3.js";
 
 import { program, programID } from "./constants";
 
 async function main() {
-
   // TODO change all of these to your values
   const assetId1 = "DGWU3mHenDerCvjkeDsKYEbsvXbWvqdo1bVoXy3dkeTd";
-  const assetId2 = "14JojSTdBZvP7f77rCxB3oQK78skTVD6DiXrXUL4objg";//"D2CoMLCRfsfv1EAiNbaBHfoU1Sqf1964KXLGxEfyUwWo";
+  const assetId2 = "14JojSTdBZvP7f77rCxB3oQK78skTVD6DiXrXUL4objg"; //"D2CoMLCRfsfv1EAiNbaBHfoU1Sqf1964KXLGxEfyUwWo";
 
-  const tree1 = new anchor.web3.PublicKey("trezdkTFPKyj4gE9LAJYPpxn8AYVCvM7Mc4JkTb9X5B")
-  const tree2 = new anchor.web3.PublicKey("Feywkti8LLBLfxhSGmYgzUBqpq89qehfB1SMTYV1zCu")
+  const tree1 = new anchor.web3.PublicKey(
+    "trezdkTFPKyj4gE9LAJYPpxn8AYVCvM7Mc4JkTb9X5B"
+  );
+  const tree2 = new anchor.web3.PublicKey(
+    "Feywkti8LLBLfxhSGmYgzUBqpq89qehfB1SMTYV1zCu"
+  );
 
-  const receiver1 = new anchor.web3.PublicKey("Andys9wuoMdUeRiZLgRS5aJwYNFv4Ut6qQi8PNDTAPEM")
-  const receiver2 = new anchor.web3.PublicKey("Andys9wuoMdUeRiZLgRS5aJwYNFv4Ut6qQi8PNDTAPEM")
+  const receiver1 = new anchor.web3.PublicKey(
+    "Andys9wuoMdUeRiZLgRS5aJwYNFv4Ut6qQi8PNDTAPEM"
+  );
+  const receiver2 = new anchor.web3.PublicKey(
+    "Andys9wuoMdUeRiZLgRS5aJwYNFv4Ut6qQi8PNDTAPEM"
+  );
   // ---
 
   const [vaultPDA, _bump] = anchor.web3.PublicKey.findProgramAddressSync(
     [Buffer.from("cNFT-vault", "utf8")],
-    programID,
+    programID
   );
 
   const [treeAuthority1, _bump2] = anchor.web3.PublicKey.findProgramAddressSync(
     [tree1.toBuffer()],
-    BUBBLEGUM_PROGRAM_ID,
+    BUBBLEGUM_PROGRAM_ID
   );
   const [treeAuthority2, _bump3] = anchor.web3.PublicKey.findProgramAddressSync(
     [tree2.toBuffer()],
-    BUBBLEGUM_PROGRAM_ID,
+    BUBBLEGUM_PROGRAM_ID
   );
 
   const asset1 = await getAsset(assetId1);
@@ -45,9 +55,13 @@ async function main() {
   const ixData1 = getInstructionData(asset1, proof1);
   const ixData2 = getInstructionData(asset2, proof2);
 
-  const remainingAccounts: AccountMeta[] = [...proofPathAsAccounts1, ...proofPathAsAccounts2];
+  const remainingAccounts: AccountMeta[] = [
+    ...proofPathAsAccounts1,
+    ...proofPathAsAccounts2,
+  ];
 
-  const tx = await program.methods.withdrawTwoCnfts(...ixData1, ...ixData2)
+  const tx = await program.methods
+    .withdrawTwoCnfts(...ixData1, ...ixData2)
     .accounts({
       leafOwner: vaultPDA,
       merkleTree1: tree1,
@@ -59,15 +73,17 @@ async function main() {
       bubblegumProgram: BUBBLEGUM_PROGRAM_ID,
       compressionProgram: SPL_ACCOUNT_COMPRESSION_PROGRAM_ID,
       logWrapper: SPL_NOOP_PROGRAM_ID,
-      systemProgram: anchor.web3.SystemProgram.programId
+      systemProgram: anchor.web3.SystemProgram.programId,
     })
     .remainingAccounts(remainingAccounts)
     .rpc();
   console.log(tx);
-};
+}
 
-function getInstructionData(asset: any, proof: any):
-  [number[], number[], number[], anchor.BN, number, number] {
+function getInstructionData(
+  asset: any,
+  proof: any
+): [number[], number[], number[], anchor.BN, number, number] {
   const root = decode(proof.root);
   const dataHash = decode(asset.compression.data_hash);
   const creatorHash = decode(asset.compression.creator_hash);
@@ -77,4 +93,4 @@ function getInstructionData(asset: any, proof: any):
   return [root, dataHash, creatorHash, nonce, index, proofLength];
 }
 
-main();
+main();

+ 63 - 29
compression/cnft-vault/anchor/tests/scripts/withdrawWithLookup.ts

@@ -1,39 +1,58 @@
-import * as anchor from "@project-serum/anchor";
+import * as anchor from "@coral-xyz/anchor";
 import { decode, mapProof } from "../utils";
 import { PROGRAM_ID as BUBBLEGUM_PROGRAM_ID } from "@metaplex-foundation/mpl-bubblegum";
-import { SPL_ACCOUNT_COMPRESSION_PROGRAM_ID, SPL_NOOP_PROGRAM_ID } from "@solana/spl-account-compression";
+import {
+  SPL_ACCOUNT_COMPRESSION_PROGRAM_ID,
+  SPL_NOOP_PROGRAM_ID,
+} from "@solana/spl-account-compression";
 import { getAsset, getAssetProof } from "../readAPI";
-import { AccountMeta, AddressLookupTableProgram, PublicKey, SystemProgram, Transaction, TransactionMessage, VersionedTransaction, sendAndConfirmTransaction } from "@solana/web3.js";
+import {
+  AccountMeta,
+  AddressLookupTableProgram,
+  PublicKey,
+  SystemProgram,
+  Transaction,
+  TransactionMessage,
+  VersionedTransaction,
+  sendAndConfirmTransaction,
+} from "@solana/web3.js";
 
 import { connection, keypair, program, programID } from "./constants";
 
 async function main() {
-
   // TODO change all of these to your values
   const assetId1 = "DGWU3mHenDerCvjkeDsKYEbsvXbWvqdo1bVoXy3dkeTd";
-  const assetId2 = "14JojSTdBZvP7f77rCxB3oQK78skTVD6DiXrXUL4objg";//"D2CoMLCRfsfv1EAiNbaBHfoU1Sqf1964KXLGxEfyUwWo";
+  const assetId2 = "14JojSTdBZvP7f77rCxB3oQK78skTVD6DiXrXUL4objg"; //"D2CoMLCRfsfv1EAiNbaBHfoU1Sqf1964KXLGxEfyUwWo";
 
-  const tree1 = new anchor.web3.PublicKey("trezdkTFPKyj4gE9LAJYPpxn8AYVCvM7Mc4JkTb9X5B")
-  const tree2 = new anchor.web3.PublicKey("trezdkTFPKyj4gE9LAJYPpxn8AYVCvM7Mc4JkTb9X5B")
+  const tree1 = new anchor.web3.PublicKey(
+    "trezdkTFPKyj4gE9LAJYPpxn8AYVCvM7Mc4JkTb9X5B"
+  );
+  const tree2 = new anchor.web3.PublicKey(
+    "trezdkTFPKyj4gE9LAJYPpxn8AYVCvM7Mc4JkTb9X5B"
+  );
 
-  const receiver1 = new anchor.web3.PublicKey("Andys9wuoMdUeRiZLgRS5aJwYNFv4Ut6qQi8PNDTAPEM")
-  const receiver2 = new anchor.web3.PublicKey("Andys9wuoMdUeRiZLgRS5aJwYNFv4Ut6qQi8PNDTAPEM")
+  const receiver1 = new anchor.web3.PublicKey(
+    "Andys9wuoMdUeRiZLgRS5aJwYNFv4Ut6qQi8PNDTAPEM"
+  );
+  const receiver2 = new anchor.web3.PublicKey(
+    "Andys9wuoMdUeRiZLgRS5aJwYNFv4Ut6qQi8PNDTAPEM"
+  );
   // ---
 
   const lookupTable = await createLookupTable();
 
   const [vaultPDA, _bump] = anchor.web3.PublicKey.findProgramAddressSync(
     [Buffer.from("cNFT-vault", "utf8")],
-    programID,
+    programID
   );
 
   const [treeAuthority1, _bump2] = anchor.web3.PublicKey.findProgramAddressSync(
     [tree1.toBuffer()],
-    BUBBLEGUM_PROGRAM_ID,
+    BUBBLEGUM_PROGRAM_ID
   );
   const [treeAuthority2, _bump3] = anchor.web3.PublicKey.findProgramAddressSync(
     [tree2.toBuffer()],
-    BUBBLEGUM_PROGRAM_ID,
+    BUBBLEGUM_PROGRAM_ID
   );
 
   const asset1 = await getAsset(assetId1);
@@ -47,9 +66,13 @@ async function main() {
   const ixData1 = getInstructionData(asset1, proof1);
   const ixData2 = getInstructionData(asset2, proof2);
 
-  const remainingAccounts: AccountMeta[] = [...proofPathAsAccounts1, ...proofPathAsAccounts2];
+  const remainingAccounts: AccountMeta[] = [
+    ...proofPathAsAccounts1,
+    ...proofPathAsAccounts2,
+  ];
 
-  const ix = await program.methods.withdrawTwoCnfts(...ixData1, ...ixData2)
+  const ix = await program.methods
+    .withdrawTwoCnfts(...ixData1, ...ixData2)
     .accounts({
       leafOwner: vaultPDA,
       merkleTree1: tree1,
@@ -61,14 +84,19 @@ async function main() {
       bubblegumProgram: BUBBLEGUM_PROGRAM_ID,
       compressionProgram: SPL_ACCOUNT_COMPRESSION_PROGRAM_ID,
       logWrapper: SPL_NOOP_PROGRAM_ID,
-      systemProgram: anchor.web3.SystemProgram.programId
+      systemProgram: anchor.web3.SystemProgram.programId,
     })
     .remainingAccounts(remainingAccounts)
     .instruction();
 
-
-  await extendLookupTable(lookupTable, proofPathAsAccounts1.map(acc => acc.pubkey));
-  await extendLookupTable(lookupTable, proofPathAsAccounts2.map(acc => acc.pubkey));
+  await extendLookupTable(
+    lookupTable,
+    proofPathAsAccounts1.map((acc) => acc.pubkey)
+  );
+  await extendLookupTable(
+    lookupTable,
+    proofPathAsAccounts2.map((acc) => acc.pubkey)
+  );
 
   const lookupTableAccount = await connection
     .getAddressLookupTable(lookupTable)
@@ -79,7 +107,7 @@ async function main() {
     return;
   }
 
-  await new Promise(_ => setTimeout(_, 30000));
+  await new Promise((_) => setTimeout(_, 30000));
 
   const messageV0 = new TransactionMessage({
     payerKey: keypair.publicKey,
@@ -92,10 +120,12 @@ async function main() {
 
   const txid = await connection.sendTransaction(transactionV0);
   console.log(txid);
-};
+}
 
-function getInstructionData(asset: any, proof: any):
-  [number[], number[], number[], anchor.BN, number, number] {
+function getInstructionData(
+  asset: any,
+  proof: any
+): [number[], number[], number[], anchor.BN, number, number] {
   const root = decode(proof.root);
   const dataHash = decode(asset.compression.data_hash);
   const creatorHash = decode(asset.compression.creator_hash);
@@ -107,21 +137,23 @@ function getInstructionData(asset: any, proof: any):
 
 main();
 
-async function extendLookupTable(lookupTableAddress: PublicKey, proofHashes: PublicKey[]) {
-
+async function extendLookupTable(
+  lookupTableAddress: PublicKey,
+  proofHashes: PublicKey[]
+) {
   const extendInstruction = AddressLookupTableProgram.extendLookupTable({
     payer: keypair.publicKey,
     authority: keypair.publicKey,
     lookupTable: lookupTableAddress,
-    addresses: [
-      ...proofHashes
-    ],
+    addresses: [...proofHashes],
   });
 
   const tx = new Transaction();
   tx.add(extendInstruction);
 
-  const sx = await sendAndConfirmTransaction(connection, tx, [keypair], { commitment: "finalized" });
+  const sx = await sendAndConfirmTransaction(connection, tx, [keypair], {
+    commitment: "finalized",
+  });
   console.log(sx);
   console.log("ALT extended!");
 }
@@ -154,7 +186,9 @@ async function createLookupTable(): Promise<PublicKey> {
   const tx = new Transaction();
   tx.add(lookupTableInst).add(extendInstruction);
 
-  const sx = await sendAndConfirmTransaction(connection, tx, [keypair], { commitment: "finalized" });
+  const sx = await sendAndConfirmTransaction(connection, tx, [keypair], {
+    commitment: "finalized",
+  });
   console.log(sx);
   console.log("ALT created");
 

+ 135 - 119
compression/cnft-vault/anchor/tests/tests.ts

@@ -1,131 +1,147 @@
-import * as anchor from "@project-serum/anchor";
+import * as anchor from "@coral-xyz/anchor";
 import { loadWalletKey, decode, mapProof } from "./utils";
-import { IDL, CnftVault } from "../target/types/cnft_vault"
+import { IDL, CnftVault } from "../target/types/cnft_vault";
 import { PROGRAM_ID as BUBBLEGUM_PROGRAM_ID } from "@metaplex-foundation/mpl-bubblegum";
-import { SPL_ACCOUNT_COMPRESSION_PROGRAM_ID, SPL_NOOP_PROGRAM_ID } from "@solana/spl-account-compression";
+import {
+  SPL_ACCOUNT_COMPRESSION_PROGRAM_ID,
+  SPL_NOOP_PROGRAM_ID,
+} from "@solana/spl-account-compression";
 import { getAsset, getAssetProof } from "./readAPI";
 import { AccountMeta } from "@solana/web3.js";
 
 describe("cNFT Vault", () => {
-
-    const provider = anchor.AnchorProvider.env();
-    anchor.setProvider(provider);
-    const payer = provider.wallet as anchor.Wallet;
-    const program = anchor.workspace.CnftVault as anchor.Program<CnftVault>;
-
-    const [vaultPDA, _bump] = anchor.web3.PublicKey.findProgramAddressSync(
-        [Buffer.from("cNFT-vault", "utf8")],
-        program.programId,
+  const provider = anchor.AnchorProvider.env();
+  anchor.setProvider(provider);
+  const payer = provider.wallet as anchor.Wallet;
+  const program = anchor.workspace.CnftVault as anchor.Program<CnftVault>;
+
+  const [vaultPDA, _bump] = anchor.web3.PublicKey.findProgramAddressSync(
+    [Buffer.from("cNFT-vault", "utf8")],
+    program.programId
+  );
+  console.log("Vault address: " + vaultPDA.toBase58());
+
+  it("Withdraw a cNFT!", async () => {
+    // we expect the cNFT to already be in the vault
+    // you can send it there (to vaultPDA) using any regular wallet
+    // the cNFT has the following asset id
+    const assetId = "DGWU3mHenDerCvjkeDsKYEbsvXbWvqdo1bVoXy3dkeTd"; // TODO
+    // and is compressed in the following tree
+    const tree = new anchor.web3.PublicKey(
+      "trezdkTFPKyj4gE9LAJYPpxn8AYVCvM7Mc4JkTb9X5B"
+    ); // TODO
+
+    const receiver = payer.publicKey; // you can define any pubkey as the receiver here
+
+    const [treeAuthority, _bump2] =
+      anchor.web3.PublicKey.findProgramAddressSync(
+        [tree.toBuffer()],
+        BUBBLEGUM_PROGRAM_ID
+      );
+
+    const asset = await getAsset(assetId);
+
+    const proof = await getAssetProof(assetId);
+    const proofPathAsAccounts = mapProof(proof);
+
+    const root = decode(proof.root);
+    const dataHash = decode(asset.compression.data_hash);
+    const creatorHash = decode(asset.compression.creator_hash);
+    const nonce = new anchor.BN(asset.compression.leaf_id);
+    const index = asset.compression.leaf_id;
+
+    const sx = await program.methods
+      .withdrawCnft(root, dataHash, creatorHash, nonce, index)
+      .accounts({
+        leafOwner: vaultPDA,
+        merkleTree: tree,
+        newLeafOwner: receiver,
+        treeAuthority: treeAuthority,
+        bubblegumProgram: BUBBLEGUM_PROGRAM_ID,
+        compressionProgram: SPL_ACCOUNT_COMPRESSION_PROGRAM_ID,
+        logWrapper: SPL_NOOP_PROGRAM_ID,
+        systemProgram: anchor.web3.SystemProgram.programId,
+      })
+      .remainingAccounts(proofPathAsAccounts)
+      .rpc();
+
+    console.log("Success!");
+    console.log(`   Tx Signature: ${sx}`);
+  });
+
+  it("Withdraw two cNFTs!", async () => {
+    // TODO change all of these to your values
+    const assetId1 = "DGWU3mHenDerCvjkeDsKYEbsvXbWvqdo1bVoXy3dkeTd";
+    const assetId2 = "14JojSTdBZvP7f77rCxB3oQK78skTVD6DiXrXUL4objg";
+
+    const tree1 = new anchor.web3.PublicKey(
+      "trezdkTFPKyj4gE9LAJYPpxn8AYVCvM7Mc4JkTb9X5B"
+    );
+    const tree2 = new anchor.web3.PublicKey(
+      "Feywkti8LLBLfxhSGmYgzUBqpq89qehfB1SMTYV1zCu"
     );
-    console.log("Vault address: " + vaultPDA.toBase58());
-
-    it("Withdraw a cNFT!", async () => {
-
-        // we expect the cNFT to already be in the vault
-        // you can send it there (to vaultPDA) using any regular wallet
-        // the cNFT has the following asset id
-        const assetId = "DGWU3mHenDerCvjkeDsKYEbsvXbWvqdo1bVoXy3dkeTd"; // TODO 
-        // and is compressed in the following tree
-        const tree = new anchor.web3.PublicKey("trezdkTFPKyj4gE9LAJYPpxn8AYVCvM7Mc4JkTb9X5B"); // TODO 
-
-        const receiver = payer.publicKey; // you can define any pubkey as the receiver here
-
-        const [treeAuthority, _bump2] = anchor.web3.PublicKey.findProgramAddressSync(
-            [tree.toBuffer()],
-            BUBBLEGUM_PROGRAM_ID,
-        );
-
-        const asset = await getAsset(assetId);
-
-        const proof = await getAssetProof(assetId);
-        const proofPathAsAccounts = mapProof(proof);
-
-        const root = decode(proof.root);
-        const dataHash = decode(asset.compression.data_hash);
-        const creatorHash = decode(asset.compression.creator_hash);
-        const nonce = new anchor.BN(asset.compression.leaf_id);
-        const index = asset.compression.leaf_id;
-
-        const sx = await program.methods.withdrawCnft(root, dataHash, creatorHash, nonce, index)
-            .accounts({
-                leafOwner: vaultPDA,
-                merkleTree: tree,
-                newLeafOwner: receiver,
-                treeAuthority: treeAuthority,
-                bubblegumProgram: BUBBLEGUM_PROGRAM_ID,
-                compressionProgram: SPL_ACCOUNT_COMPRESSION_PROGRAM_ID,
-                logWrapper: SPL_NOOP_PROGRAM_ID,
-                systemProgram: anchor.web3.SystemProgram.programId
-            })
-            .remainingAccounts(proofPathAsAccounts)
-            .rpc();
-
-        console.log("Success!");
-        console.log(`   Tx Signature: ${sx}`);
-    });
-
-
-    it("Withdraw two cNFTs!", async () => {
-
-        // TODO change all of these to your values
-        const assetId1 = "DGWU3mHenDerCvjkeDsKYEbsvXbWvqdo1bVoXy3dkeTd";
-        const assetId2 = "14JojSTdBZvP7f77rCxB3oQK78skTVD6DiXrXUL4objg";
-
-        const tree1 = new anchor.web3.PublicKey("trezdkTFPKyj4gE9LAJYPpxn8AYVCvM7Mc4JkTb9X5B")
-        const tree2 = new anchor.web3.PublicKey("Feywkti8LLBLfxhSGmYgzUBqpq89qehfB1SMTYV1zCu")
-
-        const receiver1 = new anchor.web3.PublicKey("Andys9wuoMdUeRiZLgRS5aJwYNFv4Ut6qQi8PNDTAPEM")
-        const receiver2 = new anchor.web3.PublicKey("Andys9wuoMdUeRiZLgRS5aJwYNFv4Ut6qQi8PNDTAPEM")
-        // ---
-
-        const [treeAuthority1, _bump2] = anchor.web3.PublicKey.findProgramAddressSync(
-            [tree1.toBuffer()],
-            BUBBLEGUM_PROGRAM_ID,
-        );
-        const [treeAuthority2, _bump3] = anchor.web3.PublicKey.findProgramAddressSync(
-            [tree2.toBuffer()],
-            BUBBLEGUM_PROGRAM_ID,
-        );
-
-        const asset1 = await getAsset(assetId1);
-        const asset2 = await getAsset(assetId2);
-
-        const proof1 = await getAssetProof(assetId1);
-        const proofPathAsAccounts1 = mapProof(proof1);
-        const proof2 = await getAssetProof(assetId2);
-        const proofPathAsAccounts2 = mapProof(proof2);
-
-        const ixData1 = getInstructionData(asset1, proof1);
-        const ixData2 = getInstructionData(asset2, proof2);
-
-        const remainingAccounts: AccountMeta[] = [...proofPathAsAccounts1, ...proofPathAsAccounts2];
-
-        const sx = await program.methods.withdrawTwoCnfts(...ixData1, ...ixData2)
-            .accounts({
-                leafOwner: vaultPDA,
-                merkleTree1: tree1,
-                newLeafOwner1: receiver1,
-                treeAuthority1: treeAuthority1,
-                merkleTree2: tree2,
-                newLeafOwner2: receiver2,
-                treeAuthority2: treeAuthority2,
-                bubblegumProgram: BUBBLEGUM_PROGRAM_ID,
-                compressionProgram: SPL_ACCOUNT_COMPRESSION_PROGRAM_ID,
-                logWrapper: SPL_NOOP_PROGRAM_ID,
-                systemProgram: anchor.web3.SystemProgram.programId
-            })
-            .remainingAccounts(remainingAccounts)
-            .rpc();
-        console.log("Success!");
-        console.log(`   Tx Signature: ${sx}`);
-    });
-
 
+    const receiver1 = new anchor.web3.PublicKey(
+      "Andys9wuoMdUeRiZLgRS5aJwYNFv4Ut6qQi8PNDTAPEM"
+    );
+    const receiver2 = new anchor.web3.PublicKey(
+      "Andys9wuoMdUeRiZLgRS5aJwYNFv4Ut6qQi8PNDTAPEM"
+    );
+    // ---
+
+    const [treeAuthority1, _bump2] =
+      anchor.web3.PublicKey.findProgramAddressSync(
+        [tree1.toBuffer()],
+        BUBBLEGUM_PROGRAM_ID
+      );
+    const [treeAuthority2, _bump3] =
+      anchor.web3.PublicKey.findProgramAddressSync(
+        [tree2.toBuffer()],
+        BUBBLEGUM_PROGRAM_ID
+      );
+
+    const asset1 = await getAsset(assetId1);
+    const asset2 = await getAsset(assetId2);
+
+    const proof1 = await getAssetProof(assetId1);
+    const proofPathAsAccounts1 = mapProof(proof1);
+    const proof2 = await getAssetProof(assetId2);
+    const proofPathAsAccounts2 = mapProof(proof2);
+
+    const ixData1 = getInstructionData(asset1, proof1);
+    const ixData2 = getInstructionData(asset2, proof2);
+
+    const remainingAccounts: AccountMeta[] = [
+      ...proofPathAsAccounts1,
+      ...proofPathAsAccounts2,
+    ];
+
+    const sx = await program.methods
+      .withdrawTwoCnfts(...ixData1, ...ixData2)
+      .accounts({
+        leafOwner: vaultPDA,
+        merkleTree1: tree1,
+        newLeafOwner1: receiver1,
+        treeAuthority1: treeAuthority1,
+        merkleTree2: tree2,
+        newLeafOwner2: receiver2,
+        treeAuthority2: treeAuthority2,
+        bubblegumProgram: BUBBLEGUM_PROGRAM_ID,
+        compressionProgram: SPL_ACCOUNT_COMPRESSION_PROGRAM_ID,
+        logWrapper: SPL_NOOP_PROGRAM_ID,
+        systemProgram: anchor.web3.SystemProgram.programId,
+      })
+      .remainingAccounts(remainingAccounts)
+      .rpc();
+    console.log("Success!");
+    console.log(`   Tx Signature: ${sx}`);
+  });
 });
 
-
-function getInstructionData(asset: any, proof: any):
-  [number[], number[], number[], anchor.BN, number, number] {
+function getInstructionData(
+  asset: any,
+  proof: any
+): [number[], number[], number[], anchor.BN, number, number] {
   const root = decode(proof.root);
   const dataHash = decode(asset.compression.data_hash);
   const creatorHash = decode(asset.compression.creator_hash);
@@ -133,4 +149,4 @@ function getInstructionData(asset: any, proof: any):
   const index = asset.compression.leaf_id;
   const proofLength = proof.proof.length;
   return [root, dataHash, creatorHash, nonce, index, proofLength];
-}
+}