From 8e3abca60ff6855f2d2fb424b917881c2f80011e Mon Sep 17 00:00:00 2001 From: adpthegreat Date: Thu, 28 Nov 2024 07:52:45 +0100 Subject: [PATCH] added close-account program --- .../{close_account_program => }/Anchor.toml | 2 +- .../{close_account_program => }/Cargo.toml | 0 .../poseidon/close_account_program/.gitignore | 7 - .../close_account_program/.prettierignore | 7 - .../tests/close_account_program.ts | 122 ---------------- .../ts-programs/pnpm-lock.yaml | 22 --- .../migrations/deploy.ts | 0 .../{close_account_program => }/package.json | 14 +- .../pnpm-lock.yaml | 130 +++++++++--------- .../programs/close-account-program/Cargo.toml | 20 +++ .../programs/close-account-program/Xargo.toml | 2 + .../programs/close-account-program/src/lib.rs | 44 ++++++ .../tests/bankrun.test.ts | 6 +- .../ts-programs/package.json | 2 +- .../poseidon/ts-programs/pnpm-lock.yaml | 22 +++ .../src/closeAccountProgram.ts} | 6 +- .../{close_account_program => }/tsconfig.json | 0 17 files changed, 171 insertions(+), 235 deletions(-) rename basics/close-account/poseidon/{close_account_program => }/Anchor.toml (79%) rename basics/close-account/poseidon/{close_account_program => }/Cargo.toml (100%) delete mode 100644 basics/close-account/poseidon/close_account_program/.gitignore delete mode 100644 basics/close-account/poseidon/close_account_program/.prettierignore delete mode 100644 basics/close-account/poseidon/close_account_program/tests/close_account_program.ts delete mode 100644 basics/close-account/poseidon/close_account_program/ts-programs/pnpm-lock.yaml rename basics/close-account/poseidon/{close_account_program => }/migrations/deploy.ts (100%) rename basics/close-account/poseidon/{close_account_program => }/package.json (80%) rename basics/close-account/poseidon/{close_account_program => }/pnpm-lock.yaml (92%) create mode 100644 basics/close-account/poseidon/programs/close-account-program/Cargo.toml create mode 100644 basics/close-account/poseidon/programs/close-account-program/Xargo.toml create mode 100644 basics/close-account/poseidon/programs/close-account-program/src/lib.rs rename basics/close-account/poseidon/{close_account_program => }/tests/bankrun.test.ts (93%) rename basics/close-account/poseidon/{close_account_program => }/ts-programs/package.json (85%) create mode 100644 basics/close-account/poseidon/ts-programs/pnpm-lock.yaml rename basics/close-account/poseidon/{close_account_program/ts-programs/src/close_account_program.ts => ts-programs/src/closeAccountProgram.ts} (72%) rename basics/close-account/poseidon/{close_account_program => }/tsconfig.json (100%) diff --git a/basics/close-account/poseidon/close_account_program/Anchor.toml b/basics/close-account/poseidon/Anchor.toml similarity index 79% rename from basics/close-account/poseidon/close_account_program/Anchor.toml rename to basics/close-account/poseidon/Anchor.toml index 1dade236..16f8c248 100644 --- a/basics/close-account/poseidon/close_account_program/Anchor.toml +++ b/basics/close-account/poseidon/Anchor.toml @@ -5,7 +5,7 @@ resolution = true skip-lint = false [programs.localnet] -close_account_program = "AtUc6zMfozxrQoK4PbDUnd5daS86XCPuT2og1293P5XX" +close_account_program = "Cp1rfMVrJoD9aNT8dGVoPAf2BrY6HBMXbsTPfd2heV6C" [registry] url = "https://api.apr.dev" diff --git a/basics/close-account/poseidon/close_account_program/Cargo.toml b/basics/close-account/poseidon/Cargo.toml similarity index 100% rename from basics/close-account/poseidon/close_account_program/Cargo.toml rename to basics/close-account/poseidon/Cargo.toml diff --git a/basics/close-account/poseidon/close_account_program/.gitignore b/basics/close-account/poseidon/close_account_program/.gitignore deleted file mode 100644 index 2e0446b0..00000000 --- a/basics/close-account/poseidon/close_account_program/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -.anchor -.DS_Store -target -**/*.rs.bk -node_modules -test-ledger -.yarn diff --git a/basics/close-account/poseidon/close_account_program/.prettierignore b/basics/close-account/poseidon/close_account_program/.prettierignore deleted file mode 100644 index 41425834..00000000 --- a/basics/close-account/poseidon/close_account_program/.prettierignore +++ /dev/null @@ -1,7 +0,0 @@ -.anchor -.DS_Store -target -node_modules -dist -build -test-ledger diff --git a/basics/close-account/poseidon/close_account_program/tests/close_account_program.ts b/basics/close-account/poseidon/close_account_program/tests/close_account_program.ts deleted file mode 100644 index 94d37abd..00000000 --- a/basics/close-account/poseidon/close_account_program/tests/close_account_program.ts +++ /dev/null @@ -1,122 +0,0 @@ -import assert from 'node:assert'; -import * as anchor from '@coral-xyz/anchor'; -import type { Program } from '@coral-xyz/anchor'; -import { - Connection, - Keypair, - LAMPORTS_PER_SOL, - PublicKey, - SystemProgram, - Transaction, - TransactionInstruction, - TransactionMessage, - VersionedTransaction, -} from '@solana/web3.js'; -import type { CloseAccount } from '../target/types/close_account'; - -const connection = new Connection('https://api.devnet.solana.com'); - -async function createAndProcessTransaction( - payer: Keypair, - instruction: TransactionInstruction, - additionalSigners: Keypair[] = [], -): Promise<{ transaction: VersionedTransaction; signature: string | null }> { - // Get the latest blockhash - const { blockhash, lastValidBlockHeight } = await getLatestBlockhash(); - const message = new TransactionMessage({ - payerKey: payer.publicKey, - recentBlockhash: blockhash, - instructions: [instruction], - }).compileToV0Message(); - - const tx = new VersionedTransaction(message); - - try { - const signature = await sendAndConfirmTransaction(tx); - return { transaction: tx, signature }; - } catch (err) { - return { transaction: tx, signature: null }; - } -} - -async function getLatestBlockhash(): Promise<{ - blockhash: string; - lastValidBlockHeight: number; -}> { - const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('finalized'); - return { blockhash, lastValidBlockHeight }; -} - -async function sendAndConfirmTransaction(tx: VersionedTransaction): Promise { - const signature = await connection.sendTransaction(tx); - - const { blockhash, lastValidBlockHeight } = await getLatestBlockhash(); - - await connection.confirmTransaction({ - blockhash: blockhash, - lastValidBlockHeight: lastValidBlockHeight, - signature: signature, - }); - - return signature; -} - -describe('Close an account', () => { - // Configure the client to use the local cluster. - const provider = anchor.AnchorProvider.env(); - anchor.setProvider(provider); - - const program = anchor.workspace.CloseAccountProgram as Program; - const payer = provider.wallet as anchor.Wallet; - - const user = Keypair.generate(); // Generate a new user keypair - - before(async () => { - //Transfer SOL to the user account to cover rent - const transferInstruction = SystemProgram.transfer({ - fromPubkey: payer.publicKey, - toPubkey: user.publicKey, - lamports: 2 * LAMPORTS_PER_SOL, - }); - - await createAndProcessTransaction(payer.payer, transferInstruction, [payer.payer]); - }); - - // Derive the PDA for the user's account. - const [userAccount, userAccountBump] = PublicKey.findProgramAddressSync([Buffer.from('USER'), payer.publicKey.toBuffer()], program.programId); - - it('Can create an account', async () => { - await program.methods - .createUser('Jacob') - .accounts({ - user: user.publicKey, - }) - .signers([user]) - .rpc(); - - // Fetch the account data - const userAccountData = await program.account.userState.fetch(userAccount); - assert.equal(userAccountData.name, 'Jacob'); - assert.equal(userAccountData.user.toBase58(), user.publicKey.toBase58()); - assert.notEqual(userAccountData, null); - }); - - it('Can close an Account', async () => { - await program.methods - .closeUser() - .accounts({ - user: user.publicKey, - }) - .signers([user]) - .rpc(); - - // The account should no longer exist, returning null. - try { - const userAccountData = await program.account.userState.fetchNullable(userAccount); - assert.equal(userAccountData, null); - } catch (err) { - // Won't return null and will throw an error in anchor-bankrun' - assert.equal(err.message, `Could not find ${userAccount}`); - } - }); -}); diff --git a/basics/close-account/poseidon/close_account_program/ts-programs/pnpm-lock.yaml b/basics/close-account/poseidon/close_account_program/ts-programs/pnpm-lock.yaml deleted file mode 100644 index 0d509282..00000000 --- a/basics/close-account/poseidon/close_account_program/ts-programs/pnpm-lock.yaml +++ /dev/null @@ -1,22 +0,0 @@ -lockfileVersion: '9.0' - -settings: - autoInstallPeers: true - excludeLinksFromLockfile: false - -importers: - - .: - dependencies: - '@solanaturbine/poseidon': - specifier: ^0.0.4 - version: 0.0.4 - -packages: - - '@solanaturbine/poseidon@0.0.4': - resolution: {integrity: sha512-VNQRtqobzBT+Wkh8fdPb0WVt12aIlgRJuGDxptclkphXi5w+VHUfMPcBshWSFPZg1nheXYgJABwvffYcyirw1g==} - -snapshots: - - '@solanaturbine/poseidon@0.0.4': {} diff --git a/basics/close-account/poseidon/close_account_program/migrations/deploy.ts b/basics/close-account/poseidon/migrations/deploy.ts similarity index 100% rename from basics/close-account/poseidon/close_account_program/migrations/deploy.ts rename to basics/close-account/poseidon/migrations/deploy.ts diff --git a/basics/close-account/poseidon/close_account_program/package.json b/basics/close-account/poseidon/package.json similarity index 80% rename from basics/close-account/poseidon/close_account_program/package.json rename to basics/close-account/poseidon/package.json index 1321fd8f..ae34cfea 100644 --- a/basics/close-account/poseidon/close_account_program/package.json +++ b/basics/close-account/poseidon/package.json @@ -7,18 +7,18 @@ }, "dependencies": { "@coral-xyz/anchor": "^0.30.1", + "@solana/web3.js": "^1.95.4", "anchor-bankrun": "^0.5.0", - "solana-bankrun": "^0.4.0", - "@solana/web3.js": "^1.95.4" + "solana-bankrun": "^0.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" + "@types/bn.js": "^5.1.0", + "@types/chai": "^4.3.0", + "@types/mocha": "^9.0.0", + "typescript": "^4.3.5", + "prettier": "^2.6.2" } } diff --git a/basics/close-account/poseidon/close_account_program/pnpm-lock.yaml b/basics/close-account/poseidon/pnpm-lock.yaml similarity index 92% rename from basics/close-account/poseidon/close_account_program/pnpm-lock.yaml rename to basics/close-account/poseidon/pnpm-lock.yaml index 9c99347b..92ebc0a6 100644 --- a/basics/close-account/poseidon/close_account_program/pnpm-lock.yaml +++ b/basics/close-account/poseidon/pnpm-lock.yaml @@ -13,10 +13,10 @@ importers: version: 0.30.1(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@solana/web3.js': specifier: ^1.95.4 - version: 1.95.4(bufferutil@4.0.8)(utf-8-validate@5.0.10) + version: 1.95.5(bufferutil@4.0.8)(utf-8-validate@5.0.10) anchor-bankrun: specifier: ^0.5.0 - version: 0.5.0(@coral-xyz/anchor@0.30.1(bufferutil@4.0.8)(utf-8-validate@5.0.10))(@solana/web3.js@1.95.4(bufferutil@4.0.8)(utf-8-validate@5.0.10))(solana-bankrun@0.4.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)) + version: 0.5.0(@coral-xyz/anchor@0.30.1(bufferutil@4.0.8)(utf-8-validate@5.0.10))(@solana/web3.js@1.95.5(bufferutil@4.0.8)(utf-8-validate@5.0.10))(solana-bankrun@0.4.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)) solana-bankrun: specifier: ^0.4.0 version: 0.4.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) @@ -48,8 +48,8 @@ importers: packages: - '@babel/runtime@7.25.7': - resolution: {integrity: sha512-FjoyLe754PMiYsFaN5C94ttGiOmBNYTf6pLr4xXHAT5uctHb092PBszndLDR5XA/jghQvn4n7JMHl7dmTgbm9w==} + '@babel/runtime@7.26.0': + resolution: {integrity: sha512-FDSOghenHTiToteC/QRlv2q3DhPZ/oOXTBoirfWNx1Cx3TMVcGWQtMMmQcSvb/JjpNeGzx8Pq/b4fKEJuWm1sw==} engines: {node: '>=6.9.0'} '@coral-xyz/anchor-errors@0.30.1': @@ -66,23 +66,27 @@ packages: peerDependencies: '@solana/web3.js': ^1.68.0 - '@noble/curves@1.6.0': - resolution: {integrity: sha512-TlaHRXDehJuRNR9TfZDNQ45mMEd5dwUwmicsafcIX4SsNiqnCHKjE/1alYPd/lDRVhxdhUAlv8uEhMCI5zjIJQ==} + '@noble/curves@1.7.0': + resolution: {integrity: sha512-UTMhXK9SeDhFJVrHeUJ5uZlI6ajXg10O6Ddocf9S6GjbSBVZsJo88HzKwXznNfGpMTRDyJkqMjNDPYgf0qFWnw==} engines: {node: ^14.21.3 || >=16} - '@noble/hashes@1.5.0': - resolution: {integrity: sha512-1j6kQFb7QRru7eKN3ZDvRcP13rugwdxZqCjbiAVZfIJwgj2A65UmT4TgARXGlXgnRkORLTDTrO19ZErt7+QXgA==} + '@noble/hashes@1.6.0': + resolution: {integrity: sha512-YUULf0Uk4/mAA89w+k3+yUYh6NrEvxZa5T6SY3wlMvE2chHkxFUUIDI8/XW1QSC357iA5pSnqt7XEhvFOqmDyQ==} + engines: {node: ^14.21.3 || >=16} + + '@noble/hashes@1.6.1': + resolution: {integrity: sha512-pq5D8h10hHBjyqX+cfBm0i8JUXJ0UhczFc4r74zbuT9XgewFo2E3J1cOaGtdZynILNmQ685YWGzGE1Zv6io50w==} engines: {node: ^14.21.3 || >=16} '@solana/buffer-layout@4.0.1': resolution: {integrity: sha512-E1ImOIAD1tBZFRdjeM4/pzTiTApC0AOBGwyAMS4fwIodCWArzJ3DWdoh8cKxeFM2fElkxBh2Aqts1BPC373rHA==} engines: {node: '>=5.10'} - '@solana/web3.js@1.95.4': - resolution: {integrity: sha512-sdewnNEA42ZSMxqkzdwEWi6fDgzwtJHaQa5ndUGEJYtoOnM6X5cvPmjoTUp7/k7bRrVAxfBgDnvQQHD6yhlLYw==} + '@solana/web3.js@1.95.5': + resolution: {integrity: sha512-hU9cBrbg1z6gEjLH9vwIckGBVB78Ijm0iZFNk4ocm5OD82piPwuk3MeQ1rfiKD9YQtr95krrcaopb49EmQJlRg==} - '@swc/helpers@0.5.13': - resolution: {integrity: sha512-UoKGxQ3r5kYI9dALKJapMmuK+1zWM/H17Z1+iwnNmzcJRnfFuevZs375TA5rW31pu4BS4NoSy1fRsexDXfWn5w==} + '@swc/helpers@0.5.15': + resolution: {integrity: sha512-JQ5TuMi45Owi4/BIMAJBoSQoOJu12oOk/gADqlcUL9JEdHB8vyjUSsxqeNXnmXHjYKMi2WcYtezGEEhqUI/E2g==} '@types/bn.js@5.1.6': resolution: {integrity: sha512-Xh8vSwUeMKeYYrj3cX4lGQgFSF/N03r+tv4AiLl1SucqV+uTQpxRcnM8AkXKHwYP9ZPXOYXRr2KPXpVlIvqh9w==} @@ -102,8 +106,8 @@ packages: '@types/node@12.20.55': resolution: {integrity: sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==} - '@types/node@22.7.7': - resolution: {integrity: sha512-SRxCrrg9CL/y54aiMCG3edPKdprgMVGDXjA3gB8UmmBW5TcXzRUYAh8EWzTnSJFAd1rgImPELza+A3bJ+qxz8Q==} + '@types/node@22.10.0': + resolution: {integrity: sha512-XC70cRZVElFHfIUB40FgZOBbgJYFKKMa5nb9lxcwYstFG/Mi+/Y0bGS+rs6Dmhmkpq4pnNiLiuZAbc02YCOnmA==} '@types/uuid@8.3.4': resolution: {integrity: sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==} @@ -111,8 +115,8 @@ packages: '@types/ws@7.4.7': resolution: {integrity: sha512-JQbbmxZTZehdc2iszGKs5oC3NFnjeay7mtAWrdt7qNtAVK0g19muApzAy4bm9byz79xa2ZnO/BOBC2R8RC5Lww==} - '@types/ws@8.5.12': - resolution: {integrity: sha512-3tPRkv1EtkDpzlgyKyI8pGsGZAGPEaXeu0DOj5DI25Ja91bdAYddYHbADRYVrZMRbfW+1l5YwXVDKohDJNQxkQ==} + '@types/ws@8.5.13': + resolution: {integrity: sha512-osM/gWBTPKgHV8XkTunnegTRIsvF6owmf5w+JtAfOw472dptdm0dlGv4xCt6GwQRcC2XVOvvRE/0bAoQcL2QkA==} '@ungap/promise-all-settled@1.1.2': resolution: {integrity: sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==} @@ -415,8 +419,8 @@ packages: peerDependencies: ws: '*' - jayson@4.1.2: - resolution: {integrity: sha512-5nzMWDHy6f+koZOuYsArh2AXs73NfWYVlFyJJuCedr93GpY+Ku8qq10ropSXVfHK+H0T6paA88ww+/dV+1fBNA==} + jayson@4.1.3: + resolution: {integrity: sha512-LtXh5aYZodBZ9Fc3j6f2w+MTNcnxteMOrb+QgIouguGOulWi0lieEkOUg+HkjjFs0DGoWDds6bi4E9hpNFLulQ==} engines: {node: '>=8'} hasBin: true @@ -494,8 +498,8 @@ packages: encoding: optional: true - node-gyp-build@4.8.2: - resolution: {integrity: sha512-IRUxE4BVsHWXkV/SFOut4qTlagw2aM8T5/vnTsmrHJvVoKueJHRc/JaFND7QDDc61kLYUJ6qlZM3sqTSyx2dTw==} + node-gyp-build@4.8.4: + resolution: {integrity: sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ==} hasBin: true normalize-path@3.0.0: @@ -664,8 +668,8 @@ packages: tsconfig-paths@3.15.0: resolution: {integrity: sha512-2Ac2RgzDe/cn48GvOe3M+o82pEFewD3UPbyoUHHdKasHwJKjds4fLXWf/Ux5kATBKN20oaFGu+jbElp1pos0mg==} - tslib@2.8.0: - resolution: {integrity: sha512-jWVzBLplnCmoaTr13V9dYbiQ99wvZRd0vNWaDRg+aVYRcjDF3nDksxFDE/+fkXnKhpnUUkmx5pK/v8mCtLVqZA==} + tslib@2.8.1: + resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==} type-detect@4.1.0: resolution: {integrity: sha512-Acylog8/luQ8L7il+geoSxhEkazvkslg7PSNKOX59mbB9cOveP5aq9h74Y7YU8yDpJwetzQQrfIwtf4Wp4LKcw==} @@ -676,8 +680,8 @@ packages: engines: {node: '>=4.2.0'} hasBin: true - undici-types@6.19.8: - resolution: {integrity: sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==} + undici-types@6.20.0: + resolution: {integrity: sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==} utf-8-validate@5.0.10: resolution: {integrity: sha512-Z6czzLq4u8fPOyx7TU6X3dvUZVvoJmxSQ+IcrlmagKhilxlhZgxPK6C5Jqbkw1IDUmFTM+cz9QDnnLTwDz/2gQ==} @@ -758,7 +762,7 @@ packages: snapshots: - '@babel/runtime@7.25.7': + '@babel/runtime@7.26.0': dependencies: regenerator-runtime: 0.14.1 @@ -767,9 +771,9 @@ snapshots: '@coral-xyz/anchor@0.30.1(bufferutil@4.0.8)(utf-8-validate@5.0.10)': dependencies: '@coral-xyz/anchor-errors': 0.30.1 - '@coral-xyz/borsh': 0.30.1(@solana/web3.js@1.95.4(bufferutil@4.0.8)(utf-8-validate@5.0.10)) - '@noble/hashes': 1.5.0 - '@solana/web3.js': 1.95.4(bufferutil@4.0.8)(utf-8-validate@5.0.10) + '@coral-xyz/borsh': 0.30.1(@solana/web3.js@1.95.5(bufferutil@4.0.8)(utf-8-validate@5.0.10)) + '@noble/hashes': 1.6.1 + '@solana/web3.js': 1.95.5(bufferutil@4.0.8)(utf-8-validate@5.0.10) bn.js: 5.2.1 bs58: 4.0.1 buffer-layout: 1.2.2 @@ -786,27 +790,29 @@ snapshots: - encoding - utf-8-validate - '@coral-xyz/borsh@0.30.1(@solana/web3.js@1.95.4(bufferutil@4.0.8)(utf-8-validate@5.0.10))': + '@coral-xyz/borsh@0.30.1(@solana/web3.js@1.95.5(bufferutil@4.0.8)(utf-8-validate@5.0.10))': dependencies: - '@solana/web3.js': 1.95.4(bufferutil@4.0.8)(utf-8-validate@5.0.10) + '@solana/web3.js': 1.95.5(bufferutil@4.0.8)(utf-8-validate@5.0.10) bn.js: 5.2.1 buffer-layout: 1.2.2 - '@noble/curves@1.6.0': + '@noble/curves@1.7.0': dependencies: - '@noble/hashes': 1.5.0 + '@noble/hashes': 1.6.0 + + '@noble/hashes@1.6.0': {} - '@noble/hashes@1.5.0': {} + '@noble/hashes@1.6.1': {} '@solana/buffer-layout@4.0.1': dependencies: buffer: 6.0.3 - '@solana/web3.js@1.95.4(bufferutil@4.0.8)(utf-8-validate@5.0.10)': + '@solana/web3.js@1.95.5(bufferutil@4.0.8)(utf-8-validate@5.0.10)': dependencies: - '@babel/runtime': 7.25.7 - '@noble/curves': 1.6.0 - '@noble/hashes': 1.5.0 + '@babel/runtime': 7.26.0 + '@noble/curves': 1.7.0 + '@noble/hashes': 1.6.1 '@solana/buffer-layout': 4.0.1 agentkeepalive: 4.5.0 bigint-buffer: 1.1.5 @@ -815,7 +821,7 @@ snapshots: bs58: 4.0.1 buffer: 6.0.3 fast-stable-stringify: 1.0.0 - jayson: 4.1.2(bufferutil@4.0.8)(utf-8-validate@5.0.10) + jayson: 4.1.3(bufferutil@4.0.8)(utf-8-validate@5.0.10) node-fetch: 2.7.0 rpc-websockets: 9.0.4 superstruct: 2.0.2 @@ -824,19 +830,19 @@ snapshots: - encoding - utf-8-validate - '@swc/helpers@0.5.13': + '@swc/helpers@0.5.15': dependencies: - tslib: 2.8.0 + tslib: 2.8.1 '@types/bn.js@5.1.6': dependencies: - '@types/node': 22.7.7 + '@types/node': 22.10.0 '@types/chai@4.3.20': {} '@types/connect@3.4.38': dependencies: - '@types/node': 22.7.7 + '@types/node': 22.10.0 '@types/json5@0.0.29': optional: true @@ -845,19 +851,19 @@ snapshots: '@types/node@12.20.55': {} - '@types/node@22.7.7': + '@types/node@22.10.0': dependencies: - undici-types: 6.19.8 + undici-types: 6.20.0 '@types/uuid@8.3.4': {} '@types/ws@7.4.7': dependencies: - '@types/node': 22.7.7 + '@types/node': 22.10.0 - '@types/ws@8.5.12': + '@types/ws@8.5.13': dependencies: - '@types/node': 22.7.7 + '@types/node': 22.10.0 '@ungap/promise-all-settled@1.1.2': {} @@ -870,10 +876,10 @@ snapshots: dependencies: humanize-ms: 1.2.1 - anchor-bankrun@0.5.0(@coral-xyz/anchor@0.30.1(bufferutil@4.0.8)(utf-8-validate@5.0.10))(@solana/web3.js@1.95.4(bufferutil@4.0.8)(utf-8-validate@5.0.10))(solana-bankrun@0.4.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)): + anchor-bankrun@0.5.0(@coral-xyz/anchor@0.30.1(bufferutil@4.0.8)(utf-8-validate@5.0.10))(@solana/web3.js@1.95.5(bufferutil@4.0.8)(utf-8-validate@5.0.10))(solana-bankrun@0.4.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)): dependencies: '@coral-xyz/anchor': 0.30.1(bufferutil@4.0.8)(utf-8-validate@5.0.10) - '@solana/web3.js': 1.95.4(bufferutil@4.0.8)(utf-8-validate@5.0.10) + '@solana/web3.js': 1.95.5(bufferutil@4.0.8)(utf-8-validate@5.0.10) solana-bankrun: 0.4.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) ansi-colors@4.1.1: {} @@ -947,7 +953,7 @@ snapshots: bufferutil@4.0.8: dependencies: - node-gyp-build: 4.8.2 + node-gyp-build: 4.8.4 optional: true camelcase@6.3.0: {} @@ -1028,7 +1034,7 @@ snapshots: dot-case@3.0.4: dependencies: no-case: 3.0.4 - tslib: 2.8.0 + tslib: 2.8.1 emoji-regex@8.0.0: {} @@ -1128,7 +1134,7 @@ snapshots: dependencies: ws: 7.5.10(bufferutil@4.0.8)(utf-8-validate@5.0.10) - jayson@4.1.2(bufferutil@4.0.8)(utf-8-validate@5.0.10): + jayson@4.1.3(bufferutil@4.0.8)(utf-8-validate@5.0.10): dependencies: '@types/connect': 3.4.38 '@types/node': 12.20.55 @@ -1174,7 +1180,7 @@ snapshots: lower-case@2.0.2: dependencies: - tslib: 2.8.0 + tslib: 2.8.1 make-error@1.3.6: {} @@ -1228,13 +1234,13 @@ snapshots: no-case@3.0.4: dependencies: lower-case: 2.0.2 - tslib: 2.8.0 + tslib: 2.8.1 node-fetch@2.7.0: dependencies: whatwg-url: 5.0.0 - node-gyp-build@4.8.2: + node-gyp-build@4.8.4: optional: true normalize-path@3.0.0: {} @@ -1277,9 +1283,9 @@ snapshots: rpc-websockets@9.0.4: dependencies: - '@swc/helpers': 0.5.13 + '@swc/helpers': 0.5.15 '@types/uuid': 8.3.4 - '@types/ws': 8.5.12 + '@types/ws': 8.5.13 buffer: 6.0.3 eventemitter3: 5.0.1 uuid: 8.3.2 @@ -1297,7 +1303,7 @@ snapshots: snake-case@3.0.4: dependencies: dot-case: 3.0.4 - tslib: 2.8.0 + tslib: 2.8.1 solana-bankrun-darwin-arm64@0.4.0: optional: true @@ -1316,7 +1322,7 @@ snapshots: solana-bankrun@0.4.0(bufferutil@4.0.8)(utf-8-validate@5.0.10): dependencies: - '@solana/web3.js': 1.95.4(bufferutil@4.0.8)(utf-8-validate@5.0.10) + '@solana/web3.js': 1.95.5(bufferutil@4.0.8)(utf-8-validate@5.0.10) bs58: 4.0.1 optionalDependencies: solana-bankrun-darwin-arm64: 0.4.0 @@ -1401,17 +1407,17 @@ snapshots: strip-bom: 3.0.0 optional: true - tslib@2.8.0: {} + tslib@2.8.1: {} type-detect@4.1.0: {} typescript@4.9.5: {} - undici-types@6.19.8: {} + undici-types@6.20.0: {} utf-8-validate@5.0.10: dependencies: - node-gyp-build: 4.8.2 + node-gyp-build: 4.8.4 optional: true uuid@8.3.2: {} diff --git a/basics/close-account/poseidon/programs/close-account-program/Cargo.toml b/basics/close-account/poseidon/programs/close-account-program/Cargo.toml new file mode 100644 index 00000000..41ba2a5a --- /dev/null +++ b/basics/close-account/poseidon/programs/close-account-program/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "close-account-program" +version = "0.1.0" +description = "Created with Anchor" +edition = "2021" + +[lib] +crate-type = ["cdylib", "lib"] +name = "close_account_program" + +[features] +default = [] +cpi = ["no-entrypoint"] +no-entrypoint = [] +no-idl = [] +no-log-ix-name = [] +idl-build = ["anchor-lang/idl-build"] + +[dependencies] +anchor-lang = "0.30.1" diff --git a/basics/close-account/poseidon/programs/close-account-program/Xargo.toml b/basics/close-account/poseidon/programs/close-account-program/Xargo.toml new file mode 100644 index 00000000..475fb71e --- /dev/null +++ b/basics/close-account/poseidon/programs/close-account-program/Xargo.toml @@ -0,0 +1,2 @@ +[target.bpfel-unknown-unknown.dependencies.std] +features = [] diff --git a/basics/close-account/poseidon/programs/close-account-program/src/lib.rs b/basics/close-account/poseidon/programs/close-account-program/src/lib.rs new file mode 100644 index 00000000..63b150f2 --- /dev/null +++ b/basics/close-account/poseidon/programs/close-account-program/src/lib.rs @@ -0,0 +1,44 @@ +use anchor_lang::prelude::*; +declare_id!("Cp1rfMVrJoD9aNT8dGVoPAf2BrY6HBMXbsTPfd2heV6C"); +#[program] +pub mod close_account_program { + use super::*; + pub fn create_user(ctx: Context, name: String) -> Result<()> { + ctx.accounts.user_state.user_bump = ctx.bumps.user_state; + ctx.accounts.user_state.user = ctx.accounts.user.key(); + ctx.accounts.user_state.name = name; + Ok(()) + } + pub fn close_user(ctx: Context) -> Result<()> { + Ok(()) + } +} +#[derive(Accounts)] +pub struct CreateUserContext<'info> { + #[account(mut)] + pub user: Signer<'info>, + #[account( + init, + payer = user, + space = 95, + seeds = [b"USER", + user.key().as_ref()], + bump, + )] + pub user_state: Account<'info, UserState>, + pub system_program: Program<'info, System>, +} +#[derive(Accounts)] +pub struct CloseUserContext<'info> { + #[account(mut)] + pub user: Signer<'info>, + #[account(mut, seeds = [b"USER", user.key().as_ref()], bump, close = user)] + pub user_account: Account<'info, UserState>, + pub system_program: Program<'info, System>, +} +#[account] +pub struct UserState { + pub user_bump: u8, + pub name: String, + pub user: Pubkey, +} diff --git a/basics/close-account/poseidon/close_account_program/tests/bankrun.test.ts b/basics/close-account/poseidon/tests/bankrun.test.ts similarity index 93% rename from basics/close-account/poseidon/close_account_program/tests/bankrun.test.ts rename to basics/close-account/poseidon/tests/bankrun.test.ts index 9400c31e..535949ac 100644 --- a/basics/close-account/poseidon/close_account_program/tests/bankrun.test.ts +++ b/basics/close-account/poseidon/tests/bankrun.test.ts @@ -14,9 +14,9 @@ import { } from '@solana/web3.js'; import { BankrunProvider } from 'anchor-bankrun'; import { BanksClient, BanksTransactionResultWithMeta, startAnchor } from 'solana-bankrun'; -import type { CloseAccount } from '../target/types/close_account'; +import type { CloseAccountProgram } from '../target/types/close_account_program'; -const IDL = require('../target/idl/close_account.json'); +const IDL = require('../target/idl/close_account_program.json'); const PROGRAM_ID = new PublicKey(IDL.address); async function createAndProcessTransaction( @@ -45,7 +45,7 @@ describe('Close an account', async () => { const provider = new BankrunProvider(context); const payer = provider.wallet as anchor.Wallet; - const program = new anchor.Program(IDL, provider); + const program = new anchor.Program(IDL, provider); const user = Keypair.generate(); // Generate a new user keypair diff --git a/basics/close-account/poseidon/close_account_program/ts-programs/package.json b/basics/close-account/poseidon/ts-programs/package.json similarity index 85% rename from basics/close-account/poseidon/close_account_program/ts-programs/package.json rename to basics/close-account/poseidon/ts-programs/package.json index 966692b9..6382941c 100644 --- a/basics/close-account/poseidon/close_account_program/ts-programs/package.json +++ b/basics/close-account/poseidon/ts-programs/package.json @@ -10,6 +10,6 @@ "author": "", "license": "ISC", "dependencies": { - "@solanaturbine/poseidon": "^0.0.8" + "@solanaturbine/poseidon": "^0.0.10" } } diff --git a/basics/close-account/poseidon/ts-programs/pnpm-lock.yaml b/basics/close-account/poseidon/ts-programs/pnpm-lock.yaml new file mode 100644 index 00000000..64f3eedd --- /dev/null +++ b/basics/close-account/poseidon/ts-programs/pnpm-lock.yaml @@ -0,0 +1,22 @@ +lockfileVersion: '9.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +importers: + + .: + dependencies: + '@solanaturbine/poseidon': + specifier: ^0.0.10 + version: 0.0.10 + +packages: + + '@solanaturbine/poseidon@0.0.10': + resolution: {integrity: sha512-4C8niySNUp+qArCrtZ9WZszfwntynSzJUq8go7QSh63xUv2s5ACHfwLs73ajaH95NGmEcgpl6raENv0u0GeCqg==} + +snapshots: + + '@solanaturbine/poseidon@0.0.10': {} diff --git a/basics/close-account/poseidon/close_account_program/ts-programs/src/close_account_program.ts b/basics/close-account/poseidon/ts-programs/src/closeAccountProgram.ts similarity index 72% rename from basics/close-account/poseidon/close_account_program/ts-programs/src/close_account_program.ts rename to basics/close-account/poseidon/ts-programs/src/closeAccountProgram.ts index e6f92743..8e26d4b8 100644 --- a/basics/close-account/poseidon/close_account_program/ts-programs/src/close_account_program.ts +++ b/basics/close-account/poseidon/ts-programs/src/closeAccountProgram.ts @@ -1,7 +1,7 @@ -import { Account, String, Pubkey, Result, Signer, u8 } from '@solanaturbine/poseidon'; +import { Account, Pubkey, Result, Signer, String, u8 } from '@solanaturbine/poseidon'; -export default class CloseAccount { - static PROGRAM_ID = new Pubkey('AtUc6zMfozxrQoK4PbDUnd5daS86XCPuT2og1293P5XXo'); +export default class CloseAccountProgram { + static PROGRAM_ID = new Pubkey('Cp1rfMVrJoD9aNT8dGVoPAf2BrY6HBMXbsTPfd2heV6C'); createUser(user: Signer, userState: UserState, name: String<50>): Result { userState.derive(['USER', user.key]).init(user); diff --git a/basics/close-account/poseidon/close_account_program/tsconfig.json b/basics/close-account/poseidon/tsconfig.json similarity index 100% rename from basics/close-account/poseidon/close_account_program/tsconfig.json rename to basics/close-account/poseidon/tsconfig.json