diff --git a/biome.json b/biome.json index a7cf5f06..27c63675 100644 --- a/biome.json +++ b/biome.json @@ -52,6 +52,6 @@ }, "files": { "ignore": ["node_modules"], - "include": ["**/*.ts", "**/*.js", "**/*.json"] + "include": ["**/*.ts", "**/*.js", "**/*.json", "**/*.mjs"] } } diff --git a/tokens/create-token/anchor/prepare.mjs b/tokens/create-token/anchor/prepare.mjs index 71c10a05..7c5ec464 100644 --- a/tokens/create-token/anchor/prepare.mjs +++ b/tokens/create-token/anchor/prepare.mjs @@ -1,31 +1,34 @@ #!/usr/bin/env zx -import { $ } from 'zx' -import { mkdir, rm } from 'node:fs/promises' -import { join } from 'node:path' +import { mkdir, rm } from 'node:fs/promises'; +import { join } from 'node:path'; +import { $ } from 'zx'; -const programs = [{ - id: 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - name: 'token_metadata.so', -}] +const programs = [ + { + id: 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + name: 'token_metadata.so', + }, +]; -const outputDir = 'tests/fixtures' -const overwrite = true +const outputDir = 'tests/fixtures'; +const overwrite = true; try { for (const program of programs) { const { id, name } = program; - const outputFile = join(outputDir, name) + const outputFile = join(outputDir, name); + await $`solana config set -um`; try { - await mkdir(outputDir, { recursive: true }) - if (overwrite) await rm(outputFile, { force: true }) - await $`solana program dump ${id} ${outputFile}` - console.log(`Program ${id} dumped to ${outputFile}`) + await mkdir(outputDir, { recursive: true }); + if (overwrite) await rm(outputFile, { force: true }); + await $`solana program dump ${id} ${outputFile}`; + console.log(`Program ${id} dumped to ${outputFile}`); } catch (error) { - console.error(`Error dumping ${id}: ${error.message}`) + console.error(`Error dumping ${id}: ${error.message}`); } } } catch (error) { - console.error(`Error preparing programs: ${error.message}`) + console.error(`Error preparing programs: ${error.message}`); } diff --git a/tokens/nft-minter/anchor/prepare.mjs b/tokens/nft-minter/anchor/prepare.mjs index 71c10a05..7c5ec464 100644 --- a/tokens/nft-minter/anchor/prepare.mjs +++ b/tokens/nft-minter/anchor/prepare.mjs @@ -1,31 +1,34 @@ #!/usr/bin/env zx -import { $ } from 'zx' -import { mkdir, rm } from 'node:fs/promises' -import { join } from 'node:path' +import { mkdir, rm } from 'node:fs/promises'; +import { join } from 'node:path'; +import { $ } from 'zx'; -const programs = [{ - id: 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - name: 'token_metadata.so', -}] +const programs = [ + { + id: 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + name: 'token_metadata.so', + }, +]; -const outputDir = 'tests/fixtures' -const overwrite = true +const outputDir = 'tests/fixtures'; +const overwrite = true; try { for (const program of programs) { const { id, name } = program; - const outputFile = join(outputDir, name) + const outputFile = join(outputDir, name); + await $`solana config set -um`; try { - await mkdir(outputDir, { recursive: true }) - if (overwrite) await rm(outputFile, { force: true }) - await $`solana program dump ${id} ${outputFile}` - console.log(`Program ${id} dumped to ${outputFile}`) + await mkdir(outputDir, { recursive: true }); + if (overwrite) await rm(outputFile, { force: true }); + await $`solana program dump ${id} ${outputFile}`; + console.log(`Program ${id} dumped to ${outputFile}`); } catch (error) { - console.error(`Error dumping ${id}: ${error.message}`) + console.error(`Error dumping ${id}: ${error.message}`); } } } catch (error) { - console.error(`Error preparing programs: ${error.message}`) + console.error(`Error preparing programs: ${error.message}`); } diff --git a/tokens/nft-operations/anchor/prepare.mjs b/tokens/nft-operations/anchor/prepare.mjs index 71c10a05..7c5ec464 100644 --- a/tokens/nft-operations/anchor/prepare.mjs +++ b/tokens/nft-operations/anchor/prepare.mjs @@ -1,31 +1,34 @@ #!/usr/bin/env zx -import { $ } from 'zx' -import { mkdir, rm } from 'node:fs/promises' -import { join } from 'node:path' +import { mkdir, rm } from 'node:fs/promises'; +import { join } from 'node:path'; +import { $ } from 'zx'; -const programs = [{ - id: 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - name: 'token_metadata.so', -}] +const programs = [ + { + id: 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + name: 'token_metadata.so', + }, +]; -const outputDir = 'tests/fixtures' -const overwrite = true +const outputDir = 'tests/fixtures'; +const overwrite = true; try { for (const program of programs) { const { id, name } = program; - const outputFile = join(outputDir, name) + const outputFile = join(outputDir, name); + await $`solana config set -um`; try { - await mkdir(outputDir, { recursive: true }) - if (overwrite) await rm(outputFile, { force: true }) - await $`solana program dump ${id} ${outputFile}` - console.log(`Program ${id} dumped to ${outputFile}`) + await mkdir(outputDir, { recursive: true }); + if (overwrite) await rm(outputFile, { force: true }); + await $`solana program dump ${id} ${outputFile}`; + console.log(`Program ${id} dumped to ${outputFile}`); } catch (error) { - console.error(`Error dumping ${id}: ${error.message}`) + console.error(`Error dumping ${id}: ${error.message}`); } } } catch (error) { - console.error(`Error preparing programs: ${error.message}`) + console.error(`Error preparing programs: ${error.message}`); } diff --git a/tokens/pda-mint-authority/anchor/prepare.mjs b/tokens/pda-mint-authority/anchor/prepare.mjs index 71c10a05..7c5ec464 100644 --- a/tokens/pda-mint-authority/anchor/prepare.mjs +++ b/tokens/pda-mint-authority/anchor/prepare.mjs @@ -1,31 +1,34 @@ #!/usr/bin/env zx -import { $ } from 'zx' -import { mkdir, rm } from 'node:fs/promises' -import { join } from 'node:path' +import { mkdir, rm } from 'node:fs/promises'; +import { join } from 'node:path'; +import { $ } from 'zx'; -const programs = [{ - id: 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - name: 'token_metadata.so', -}] +const programs = [ + { + id: 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + name: 'token_metadata.so', + }, +]; -const outputDir = 'tests/fixtures' -const overwrite = true +const outputDir = 'tests/fixtures'; +const overwrite = true; try { for (const program of programs) { const { id, name } = program; - const outputFile = join(outputDir, name) + const outputFile = join(outputDir, name); + await $`solana config set -um`; try { - await mkdir(outputDir, { recursive: true }) - if (overwrite) await rm(outputFile, { force: true }) - await $`solana program dump ${id} ${outputFile}` - console.log(`Program ${id} dumped to ${outputFile}`) + await mkdir(outputDir, { recursive: true }); + if (overwrite) await rm(outputFile, { force: true }); + await $`solana program dump ${id} ${outputFile}`; + console.log(`Program ${id} dumped to ${outputFile}`); } catch (error) { - console.error(`Error dumping ${id}: ${error.message}`) + console.error(`Error dumping ${id}: ${error.message}`); } } } catch (error) { - console.error(`Error preparing programs: ${error.message}`) + console.error(`Error preparing programs: ${error.message}`); } diff --git a/tokens/spl-token-minter/anchor/prepare.mjs b/tokens/spl-token-minter/anchor/prepare.mjs index 71c10a05..7c5ec464 100644 --- a/tokens/spl-token-minter/anchor/prepare.mjs +++ b/tokens/spl-token-minter/anchor/prepare.mjs @@ -1,31 +1,34 @@ #!/usr/bin/env zx -import { $ } from 'zx' -import { mkdir, rm } from 'node:fs/promises' -import { join } from 'node:path' +import { mkdir, rm } from 'node:fs/promises'; +import { join } from 'node:path'; +import { $ } from 'zx'; -const programs = [{ - id: 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - name: 'token_metadata.so', -}] +const programs = [ + { + id: 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + name: 'token_metadata.so', + }, +]; -const outputDir = 'tests/fixtures' -const overwrite = true +const outputDir = 'tests/fixtures'; +const overwrite = true; try { for (const program of programs) { const { id, name } = program; - const outputFile = join(outputDir, name) + const outputFile = join(outputDir, name); + await $`solana config set -um`; try { - await mkdir(outputDir, { recursive: true }) - if (overwrite) await rm(outputFile, { force: true }) - await $`solana program dump ${id} ${outputFile}` - console.log(`Program ${id} dumped to ${outputFile}`) + await mkdir(outputDir, { recursive: true }); + if (overwrite) await rm(outputFile, { force: true }); + await $`solana program dump ${id} ${outputFile}`; + console.log(`Program ${id} dumped to ${outputFile}`); } catch (error) { - console.error(`Error dumping ${id}: ${error.message}`) + console.error(`Error dumping ${id}: ${error.message}`); } } } catch (error) { - console.error(`Error preparing programs: ${error.message}`) + console.error(`Error preparing programs: ${error.message}`); } diff --git a/tokens/transfer-tokens/anchor/package.json b/tokens/transfer-tokens/anchor/package.json index 9fab27f5..c48b5636 100644 --- a/tokens/transfer-tokens/anchor/package.json +++ b/tokens/transfer-tokens/anchor/package.json @@ -3,13 +3,19 @@ "@coral-xyz/anchor": "^0.30.0", "@solana/spl-token": "^0.3.8" }, + "scripts": { + "postinstall": "zx prepare.mjs" + }, "devDependencies": { "@types/bn.js": "^5.1.0", "@types/chai": "^4.3.0", "@types/mocha": "^9.0.0", + "anchor-bankrun": "^0.4.0", "chai": "^4.3.4", "mocha": "^9.0.3", + "solana-bankrun": "^0.3.0", "ts-mocha": "^10.0.0", - "typescript": "^4.3.5" + "typescript": "^4.3.5", + "zx": "^8.1.4" } } diff --git a/tokens/transfer-tokens/anchor/pnpm-lock.yaml b/tokens/transfer-tokens/anchor/pnpm-lock.yaml index d26c2c48..c4f54089 100644 --- a/tokens/transfer-tokens/anchor/pnpm-lock.yaml +++ b/tokens/transfer-tokens/anchor/pnpm-lock.yaml @@ -10,10 +10,10 @@ importers: dependencies: '@coral-xyz/anchor': specifier: ^0.30.0 - version: 0.30.0 + version: 0.30.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@solana/spl-token': specifier: ^0.3.8 - version: 0.3.11(@solana/web3.js@1.91.8)(fastestsmallesttextencoderdecoder@1.0.22) + version: 0.3.11(@solana/web3.js@1.91.8(bufferutil@4.0.8)(utf-8-validate@5.0.10))(bufferutil@4.0.8)(fastestsmallesttextencoderdecoder@1.0.22)(utf-8-validate@5.0.10) devDependencies: '@types/bn.js': specifier: ^5.1.0 @@ -24,18 +24,27 @@ importers: '@types/mocha': specifier: ^9.0.0 version: 9.1.1 + anchor-bankrun: + specifier: ^0.4.0 + version: 0.4.0(@coral-xyz/anchor@0.30.0(bufferutil@4.0.8)(utf-8-validate@5.0.10))(@solana/web3.js@1.91.8(bufferutil@4.0.8)(utf-8-validate@5.0.10))(solana-bankrun@0.3.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)) chai: specifier: ^4.3.4 version: 4.4.1 mocha: specifier: ^9.0.3 version: 9.2.2 + solana-bankrun: + specifier: ^0.3.0 + version: 0.3.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) ts-mocha: specifier: ^10.0.0 version: 10.0.0(mocha@9.2.2) typescript: specifier: ^4.3.5 version: 4.9.5 + zx: + specifier: ^8.1.4 + version: 8.1.4 packages: @@ -120,9 +129,15 @@ packages: '@types/connect@3.4.38': resolution: {integrity: sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==} + '@types/fs-extra@11.0.4': + resolution: {integrity: sha512-yTbItCNreRooED33qjunPthRcSjERP1r4MqCZc7wv0u2sUkzTFp45tgUfS5+r7FrZPdmCCNflLhVSP/o+SemsQ==} + '@types/json5@0.0.29': resolution: {integrity: sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==} + '@types/jsonfile@6.1.4': + resolution: {integrity: sha512-D5qGUYwjvnNNextdU59/+fI+spnwtTFmyQP0h+PfIOSkNfpU6AOICUOkm4i0OnSk+NyjdPJrxCDro0sJsWlRpQ==} + '@types/mocha@9.1.1': resolution: {integrity: sha512-Z61JK7DKDtdKTWwLeElSEBcWGRLY8g95ic5FoQqI9CMx0ns/Ghep3B4DfcEimiKMvtamNVULVNKEsiwV3aQmXw==} @@ -146,6 +161,14 @@ packages: resolution: {integrity: sha512-5GG/5IbQQpC9FpkRGsSvZI5QYeSCzlJHdpBQntCsuTOxhKD8lqKhrleg2Yi7yvMIf82Ycmmqln9U8V9qwEiJew==} engines: {node: '>= 8.0.0'} + anchor-bankrun@0.4.0: + resolution: {integrity: sha512-s+K7E0IGAlmkhuo8nbiqVsQf2yJ+3l9GjNQJSmkRDe25dQj4Yef9rJh77FH6EQ5H6yQYfzuhgm/5GD6JMjdTZg==} + engines: {node: '>= 10'} + peerDependencies: + '@coral-xyz/anchor': ^0.30.0 + '@solana/web3.js': ^1.78.4 + solana-bankrun: ^0.2.0 + ansi-colors@4.1.1: resolution: {integrity: sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==} engines: {node: '>=6'} @@ -579,6 +602,39 @@ packages: snake-case@3.0.4: resolution: {integrity: sha512-LAOh4z89bGQvl9pFfNF8V146i7o7/CqFPbqzYgP+yYzDIDeS9HaNFtXABamRW+AQzEVODcvE79ljJ+8a9YSdMg==} + solana-bankrun-darwin-arm64@0.3.0: + resolution: {integrity: sha512-+NbDncf0U6l3knuacRBiqpjZ2DSp+5lZaAU518gH7/x6qubbui/d000STaIBK+uNTPBS/AL/bCN+7PkXqmA3lA==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [darwin] + + solana-bankrun-darwin-universal@0.3.0: + resolution: {integrity: sha512-1/F0xdMa4qvc5o6z16FCCbZ5jbdvKvxpx5kyPcMWRiRPwyvi+zltMxciPAYMlg3wslQqGz88uFhrBEzq2eTumQ==} + engines: {node: '>= 10'} + os: [darwin] + + solana-bankrun-darwin-x64@0.3.0: + resolution: {integrity: sha512-U6CANjkmMl+lgNA7UH0GKs5V7LtVIUDzJBZefGGqLfqUNv3EjA/PrrToM0hAOWJgkxSwdz6zW+p5sw5FmnbXtg==} + engines: {node: '>= 10'} + cpu: [x64] + os: [darwin] + + solana-bankrun-linux-x64-gnu@0.3.0: + resolution: {integrity: sha512-qJSkCFs0k2n4XtTnyxGMiZsuqO2TiqTYgWjQ+3mZhGNUAMys/Vq8bd7/SyBm6RR7EfVuRXRxZvh+F8oKZ77V4w==} + engines: {node: '>= 10'} + cpu: [x64] + os: [linux] + + solana-bankrun-linux-x64-musl@0.3.0: + resolution: {integrity: sha512-xsS2CS2xb1Sw4ivNXM0gPz/qpW9BX0neSvt/pnok5L330Nu9xlTnKAY8FhzzqOP9P9sJlGRM787Y6d0yYwt6xQ==} + engines: {node: '>= 10'} + cpu: [x64] + os: [linux] + + solana-bankrun@0.3.0: + resolution: {integrity: sha512-YkH7sa8TB/AoRPzG17CXJtYsRIQHEkEqGLz1Vwc13taXhDBkjO7z6NI5JYw7n0ybRymDHwMYTc7sd+5J40TyVQ==} + engines: {node: '>= 10'} + source-map-support@0.5.21: resolution: {integrity: sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==} @@ -739,17 +795,22 @@ packages: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} engines: {node: '>=10'} + zx@8.1.4: + resolution: {integrity: sha512-QFDYYpnzdpRiJ3dL2102Cw26FpXpWshW4QLTGxiYfIcwdAqg084jRCkK/kuP/NOSkxOjydRwNFG81qzA5r1a6w==} + engines: {node: '>= 12.17.0'} + hasBin: true + snapshots: '@babel/runtime@7.24.5': dependencies: regenerator-runtime: 0.14.1 - '@coral-xyz/anchor@0.30.0': + '@coral-xyz/anchor@0.30.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)': dependencies: - '@coral-xyz/borsh': 0.30.0(@solana/web3.js@1.91.8) + '@coral-xyz/borsh': 0.30.0(@solana/web3.js@1.91.8(bufferutil@4.0.8)(utf-8-validate@5.0.10)) '@noble/hashes': 1.4.0 - '@solana/web3.js': 1.91.8 + '@solana/web3.js': 1.91.8(bufferutil@4.0.8)(utf-8-validate@5.0.10) bn.js: 5.2.1 bs58: 4.0.1 buffer-layout: 1.2.2 @@ -766,9 +827,9 @@ snapshots: - encoding - utf-8-validate - '@coral-xyz/borsh@0.30.0(@solana/web3.js@1.91.8)': + '@coral-xyz/borsh@0.30.0(@solana/web3.js@1.91.8(bufferutil@4.0.8)(utf-8-validate@5.0.10))': dependencies: - '@solana/web3.js': 1.91.8 + '@solana/web3.js': 1.91.8(bufferutil@4.0.8)(utf-8-validate@5.0.10) bn.js: 5.2.1 buffer-layout: 1.2.2 @@ -778,10 +839,10 @@ snapshots: '@noble/hashes@1.4.0': {} - '@solana/buffer-layout-utils@0.2.0': + '@solana/buffer-layout-utils@0.2.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)': dependencies: '@solana/buffer-layout': 4.0.1 - '@solana/web3.js': 1.91.8 + '@solana/web3.js': 1.91.8(bufferutil@4.0.8)(utf-8-validate@5.0.10) bigint-buffer: 1.1.5 bignumber.js: 9.1.2 transitivePeerDependencies: @@ -835,20 +896,20 @@ snapshots: '@solana/codecs-core': 2.0.0-preview.2 '@solana/codecs-numbers': 2.0.0-preview.2 - '@solana/spl-token-metadata@0.1.4(@solana/web3.js@1.91.8)(fastestsmallesttextencoderdecoder@1.0.22)': + '@solana/spl-token-metadata@0.1.4(@solana/web3.js@1.91.8(bufferutil@4.0.8)(utf-8-validate@5.0.10))(fastestsmallesttextencoderdecoder@1.0.22)': dependencies: '@solana/codecs': 2.0.0-preview.2(fastestsmallesttextencoderdecoder@1.0.22) '@solana/spl-type-length-value': 0.1.0 - '@solana/web3.js': 1.91.8 + '@solana/web3.js': 1.91.8(bufferutil@4.0.8)(utf-8-validate@5.0.10) transitivePeerDependencies: - fastestsmallesttextencoderdecoder - '@solana/spl-token@0.3.11(@solana/web3.js@1.91.8)(fastestsmallesttextencoderdecoder@1.0.22)': + '@solana/spl-token@0.3.11(@solana/web3.js@1.91.8(bufferutil@4.0.8)(utf-8-validate@5.0.10))(bufferutil@4.0.8)(fastestsmallesttextencoderdecoder@1.0.22)(utf-8-validate@5.0.10)': dependencies: '@solana/buffer-layout': 4.0.1 - '@solana/buffer-layout-utils': 0.2.0 - '@solana/spl-token-metadata': 0.1.4(@solana/web3.js@1.91.8)(fastestsmallesttextencoderdecoder@1.0.22) - '@solana/web3.js': 1.91.8 + '@solana/buffer-layout-utils': 0.2.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) + '@solana/spl-token-metadata': 0.1.4(@solana/web3.js@1.91.8(bufferutil@4.0.8)(utf-8-validate@5.0.10))(fastestsmallesttextencoderdecoder@1.0.22) + '@solana/web3.js': 1.91.8(bufferutil@4.0.8)(utf-8-validate@5.0.10) buffer: 6.0.3 transitivePeerDependencies: - bufferutil @@ -860,7 +921,7 @@ snapshots: dependencies: buffer: 6.0.3 - '@solana/web3.js@1.91.8': + '@solana/web3.js@1.91.8(bufferutil@4.0.8)(utf-8-validate@5.0.10)': dependencies: '@babel/runtime': 7.24.5 '@noble/curves': 1.4.0 @@ -873,7 +934,7 @@ snapshots: bs58: 4.0.1 buffer: 6.0.3 fast-stable-stringify: 1.0.0 - jayson: 4.1.0 + jayson: 4.1.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) node-fetch: 2.7.0 rpc-websockets: 7.11.0 superstruct: 0.14.2 @@ -892,9 +953,20 @@ snapshots: dependencies: '@types/node': 12.20.55 + '@types/fs-extra@11.0.4': + dependencies: + '@types/jsonfile': 6.1.4 + '@types/node': 20.12.11 + optional: true + '@types/json5@0.0.29': optional: true + '@types/jsonfile@6.1.4': + dependencies: + '@types/node': 20.12.11 + optional: true + '@types/mocha@9.1.1': {} '@types/node@12.20.55': {} @@ -918,6 +990,12 @@ snapshots: dependencies: humanize-ms: 1.2.1 + anchor-bankrun@0.4.0(@coral-xyz/anchor@0.30.0(bufferutil@4.0.8)(utf-8-validate@5.0.10))(@solana/web3.js@1.91.8(bufferutil@4.0.8)(utf-8-validate@5.0.10))(solana-bankrun@0.3.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)): + dependencies: + '@coral-xyz/anchor': 0.30.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) + '@solana/web3.js': 1.91.8(bufferutil@4.0.8)(utf-8-validate@5.0.10) + solana-bankrun: 0.3.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) + ansi-colors@4.1.1: {} ansi-regex@5.0.1: {} @@ -992,6 +1070,7 @@ snapshots: bufferutil@4.0.8: dependencies: node-gyp-build: 4.8.1 + optional: true camelcase@6.3.0: {} @@ -1057,6 +1136,7 @@ snapshots: debug@4.3.3(supports-color@8.1.1): dependencies: ms: 2.1.2 + optionalDependencies: supports-color: 8.1.1 decamelize@4.0.0: {} @@ -1170,11 +1250,11 @@ snapshots: isexe@2.0.0: {} - isomorphic-ws@4.0.1(ws@7.5.9): + isomorphic-ws@4.0.1(ws@7.5.9(bufferutil@4.0.8)(utf-8-validate@5.0.10)): dependencies: - ws: 7.5.9 + ws: 7.5.9(bufferutil@4.0.8)(utf-8-validate@5.0.10) - jayson@4.1.0: + jayson@4.1.0(bufferutil@4.0.8)(utf-8-validate@5.0.10): dependencies: '@types/connect': 3.4.38 '@types/node': 12.20.55 @@ -1184,10 +1264,10 @@ snapshots: delay: 5.0.0 es6-promisify: 5.0.0 eyes: 0.1.8 - isomorphic-ws: 4.0.1(ws@7.5.9) + isomorphic-ws: 4.0.1(ws@7.5.9(bufferutil@4.0.8)(utf-8-validate@5.0.10)) json-stringify-safe: 5.0.1 uuid: 8.3.2 - ws: 7.5.9 + ws: 7.5.9(bufferutil@4.0.8)(utf-8-validate@5.0.10) transitivePeerDependencies: - bufferutil - utf-8-validate @@ -1280,7 +1360,8 @@ snapshots: dependencies: whatwg-url: 5.0.0 - node-gyp-build@4.8.1: {} + node-gyp-build@4.8.1: + optional: true normalize-path@3.0.0: {} @@ -1338,6 +1419,36 @@ snapshots: dot-case: 3.0.4 tslib: 2.6.2 + solana-bankrun-darwin-arm64@0.3.0: + optional: true + + solana-bankrun-darwin-universal@0.3.0: + optional: true + + solana-bankrun-darwin-x64@0.3.0: + optional: true + + solana-bankrun-linux-x64-gnu@0.3.0: + optional: true + + solana-bankrun-linux-x64-musl@0.3.0: + optional: true + + solana-bankrun@0.3.0(bufferutil@4.0.8)(utf-8-validate@5.0.10): + dependencies: + '@solana/web3.js': 1.91.8(bufferutil@4.0.8)(utf-8-validate@5.0.10) + bs58: 4.0.1 + optionalDependencies: + solana-bankrun-darwin-arm64: 0.3.0 + solana-bankrun-darwin-universal: 0.3.0 + solana-bankrun-darwin-x64: 0.3.0 + solana-bankrun-linux-x64-gnu: 0.3.0 + solana-bankrun-linux-x64-musl: 0.3.0 + transitivePeerDependencies: + - bufferutil + - encoding + - utf-8-validate + source-map-support@0.5.21: dependencies: buffer-from: 1.1.2 @@ -1421,6 +1532,7 @@ snapshots: utf-8-validate@5.0.10: dependencies: node-gyp-build: 4.8.1 + optional: true uuid@8.3.2: {} @@ -1445,10 +1557,13 @@ snapshots: wrappy@1.0.2: {} - ws@7.5.9: {} + ws@7.5.9(bufferutil@4.0.8)(utf-8-validate@5.0.10): + optionalDependencies: + bufferutil: 4.0.8 + utf-8-validate: 5.0.10 ws@8.17.0(bufferutil@4.0.8)(utf-8-validate@5.0.10): - dependencies: + optionalDependencies: bufferutil: 4.0.8 utf-8-validate: 5.0.10 @@ -1476,3 +1591,8 @@ snapshots: yn@2.0.0: {} yocto-queue@0.1.0: {} + + zx@8.1.4: + optionalDependencies: + '@types/fs-extra': 11.0.4 + '@types/node': 20.12.11 diff --git a/tokens/transfer-tokens/anchor/prepare.mjs b/tokens/transfer-tokens/anchor/prepare.mjs new file mode 100644 index 00000000..7c5ec464 --- /dev/null +++ b/tokens/transfer-tokens/anchor/prepare.mjs @@ -0,0 +1,34 @@ +#!/usr/bin/env zx + +import { mkdir, rm } from 'node:fs/promises'; +import { join } from 'node:path'; +import { $ } from 'zx'; + +const programs = [ + { + id: 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + name: 'token_metadata.so', + }, +]; + +const outputDir = 'tests/fixtures'; +const overwrite = true; + +try { + for (const program of programs) { + const { id, name } = program; + const outputFile = join(outputDir, name); + await $`solana config set -um`; + + try { + await mkdir(outputDir, { recursive: true }); + if (overwrite) await rm(outputFile, { force: true }); + await $`solana program dump ${id} ${outputFile}`; + console.log(`Program ${id} dumped to ${outputFile}`); + } catch (error) { + console.error(`Error dumping ${id}: ${error.message}`); + } + } +} catch (error) { + console.error(`Error preparing programs: ${error.message}`); +} diff --git a/tokens/transfer-tokens/anchor/tests/bankrun.test.ts b/tokens/transfer-tokens/anchor/tests/bankrun.test.ts new file mode 100644 index 00000000..f78e76eb --- /dev/null +++ b/tokens/transfer-tokens/anchor/tests/bankrun.test.ts @@ -0,0 +1,99 @@ +import { describe, it } from 'node:test'; +import * as anchor from '@coral-xyz/anchor'; +import { getAssociatedTokenAddressSync } from '@solana/spl-token'; +import { Keypair } from '@solana/web3.js'; +import { PublicKey } from '@solana/web3.js'; +import { BankrunProvider } from 'anchor-bankrun'; +import { startAnchor } from 'solana-bankrun'; +import type { TransferTokens } from '../target/types/transfer_tokens'; + +const IDL = require('../target/idl/transfer_tokens.json'); +const PROGRAM_ID = new PublicKey(IDL.address); +const METADATA_PROGRAM_ID = new PublicKey('metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'); + +describe('Transfer Tokens Bankrun', async () => { + const context = await startAnchor( + '', + [ + { name: 'transfer_tokens', programId: PROGRAM_ID }, + { name: 'token_metadata', programId: METADATA_PROGRAM_ID }, + ], + [], + ); + const provider = new BankrunProvider(context); + anchor.setProvider(provider); + const payer = provider.wallet as anchor.Wallet; + const program = new anchor.Program(IDL, provider); + + const metadata = { + name: 'Solana Gold', + symbol: 'GOLDSOL', + uri: 'https://raw.githubusercontent.com/solana-developers/program-examples/new-examples/tokens/tokens/.assets/spl-token.json', + }; + + // Generate new keypair to use as address for mint account. + const mintKeypair = new Keypair(); + + // Generate new keypair to use as address for recipient wallet. + const recipient = new Keypair(); + + // Derive the associated token address account for the mint and payer. + const senderTokenAddress = getAssociatedTokenAddressSync(mintKeypair.publicKey, payer.publicKey); + + // Derive the associated token address account for the mint and recipient. + const recepientTokenAddress = getAssociatedTokenAddressSync(mintKeypair.publicKey, recipient.publicKey); + + it('Create an SPL Token!', async () => { + const transactionSignature = await program.methods + .createToken(metadata.name, metadata.symbol, metadata.uri) + .accounts({ + payer: payer.publicKey, + mintAccount: mintKeypair.publicKey, + }) + .signers([mintKeypair]) + .rpc(); + + console.log('Success!'); + console.log(` Mint Address: ${mintKeypair.publicKey}`); + console.log(` Transaction Signature: ${transactionSignature}`); + }); + + it('Mint tokens!', async () => { + // Amount of tokens to mint. + const amount = new anchor.BN(100); + + // Mint the tokens to the associated token account. + const transactionSignature = await program.methods + .mintToken(amount) + .accounts({ + mintAuthority: payer.publicKey, + recipient: payer.publicKey, + mintAccount: mintKeypair.publicKey, + associatedTokenAccount: senderTokenAddress, + }) + .rpc(); + + console.log('Success!'); + console.log(` Associated Token Account Address: ${senderTokenAddress}`); + console.log(` Transaction Signature: ${transactionSignature}`); + }); + + it('Transfer tokens!', async () => { + // Amount of tokens to transfer. + const amount = new anchor.BN(50); + + const transactionSignature = await program.methods + .transferTokens(amount) + .accounts({ + sender: payer.publicKey, + recipient: recipient.publicKey, + mintAccount: mintKeypair.publicKey, + senderTokenAccount: senderTokenAddress, + recipientTokenAccount: recepientTokenAddress, + }) + .rpc(); + + console.log('Success!'); + console.log(` Transaction Signature: ${transactionSignature}`); + }); +});