From 19525042ebb253999cdd9f66d781c5f6881f9b1a Mon Sep 17 00:00:00 2001 From: chizor iwuh Date: Fri, 1 Nov 2024 09:20:40 +0100 Subject: [PATCH] transfer-switch/anchor - x metas for every mint fix --- .../transfer-switch/anchor/package.json | 10 +- .../transfer-switch/anchor/pnpm-lock.yaml | 248 +++++++----------- .../src/instructions/configure_admin.rs | 49 ++++ .../initialise_extra_account_metas_list.rs | 25 +- .../transfer-switch/src/instructions/mod.rs | 2 + .../src/instructions/switch.rs | 20 +- .../src/instructions/transfer_hook.rs | 10 +- .../programs/transfer-switch/src/lib.rs | 12 +- .../programs/transfer-switch/src/state.rs | 2 + .../anchor/tests/transfer-switch.ts | 72 ++++- 10 files changed, 246 insertions(+), 204 deletions(-) create mode 100644 tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/instructions/configure_admin.rs diff --git a/tokens/token-2022/transfer-hook/transfer-switch/anchor/package.json b/tokens/token-2022/transfer-hook/transfer-switch/anchor/package.json index feefbe04c..3dcb71d5a 100644 --- a/tokens/token-2022/transfer-hook/transfer-switch/anchor/package.json +++ b/tokens/token-2022/transfer-hook/transfer-switch/anchor/package.json @@ -4,15 +4,15 @@ "@solana/spl-token": "^0.4.0" }, "devDependencies": { - "anchor-bankrun": "^0.4.0", - "solana-bankrun": "^0.3.0", + "anchor-bankrun": "^0.5.0", + "solana-bankrun": "^0.4.0", "@types/bn.js": "^5.1.0", "@types/chai": "^4.3.0", - "@types/mocha": "^9.0.0", + "@types/mocha": "10.0.9", "chai": "^4.3.4", - "mocha": "^9.0.3", + "mocha": "^10.8.2", "prettier": "^2.6.2", "ts-mocha": "^10.0.0", - "typescript": "^4.3.5" + "typescript": "^5" } } diff --git a/tokens/token-2022/transfer-hook/transfer-switch/anchor/pnpm-lock.yaml b/tokens/token-2022/transfer-hook/transfer-switch/anchor/pnpm-lock.yaml index 5a35cf73f..56aadc27c 100644 --- a/tokens/token-2022/transfer-hook/transfer-switch/anchor/pnpm-lock.yaml +++ b/tokens/token-2022/transfer-hook/transfer-switch/anchor/pnpm-lock.yaml @@ -22,29 +22,29 @@ importers: specifier: ^4.3.0 version: 4.3.16 '@types/mocha': - specifier: ^9.0.0 - version: 9.1.1 + specifier: 10.0.9 + version: 10.0.9 anchor-bankrun: - specifier: ^0.4.0 - version: 0.4.1(@coral-xyz/anchor@0.30.1(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.1(bufferutil@4.0.8)(utf-8-validate@5.0.10)) + 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.91.8(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)) chai: specifier: ^4.3.4 version: 4.4.1 mocha: - specifier: ^9.0.3 - version: 9.2.2 + specifier: ^10.8.2 + version: 10.8.2 prettier: specifier: ^2.6.2 version: 2.8.8 solana-bankrun: - specifier: ^0.3.0 - version: 0.3.1(bufferutil@4.0.8)(utf-8-validate@5.0.10) + specifier: ^0.4.0 + version: 0.4.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) + version: 10.0.0(mocha@10.8.2) typescript: - specifier: ^4.3.5 - version: 4.9.5 + specifier: ^5 + version: 5.6.3 packages: @@ -142,8 +142,8 @@ packages: '@types/json5@0.0.29': resolution: {integrity: sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==} - '@types/mocha@9.1.1': - resolution: {integrity: sha512-Z61JK7DKDtdKTWwLeElSEBcWGRLY8g95ic5FoQqI9CMx0ns/Ghep3B4DfcEimiKMvtamNVULVNKEsiwV3aQmXw==} + '@types/mocha@10.0.9': + resolution: {integrity: sha512-sicdRoWtYevwxjOHNMPTl3vSfJM6oyW8o1wXeI7uww6b6xHg8eBznQDNSGBCDJmsE8UMxP05JgZRtsKbTqt//Q==} '@types/node@12.20.55': resolution: {integrity: sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==} @@ -154,9 +154,6 @@ packages: '@types/ws@7.4.7': resolution: {integrity: sha512-JQbbmxZTZehdc2iszGKs5oC3NFnjeay7mtAWrdt7qNtAVK0g19muApzAy4bm9byz79xa2ZnO/BOBC2R8RC5Lww==} - '@ungap/promise-all-settled@1.1.2': - resolution: {integrity: sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==} - JSONStream@1.3.5: resolution: {integrity: sha512-E+iruNOY8VV9s4JEbe1aNEm6MiszPRr/UfcHMz0TQh1BXSxHK+ASV1R6W4HpjBhSeS+54PIsAMCBmwD06LLsqQ==} hasBin: true @@ -165,16 +162,16 @@ packages: resolution: {integrity: sha512-5GG/5IbQQpC9FpkRGsSvZI5QYeSCzlJHdpBQntCsuTOxhKD8lqKhrleg2Yi7yvMIf82Ycmmqln9U8V9qwEiJew==} engines: {node: '>= 8.0.0'} - anchor-bankrun@0.4.1: - resolution: {integrity: sha512-ryCT84tw+lP4AqRpBsZJbt/KTRoVVKufkxFGd77gnx9iHkbwA5G/9cALk/eqLQm4xeUWTrJSJdEVyg2e74iP9A==} + anchor-bankrun@0.5.0: + resolution: {integrity: sha512-cNTRv7pN9dy+kiyJ3UlNVTg9hAXhY2HtNVNXJbP/2BkS9nOdLV0qKWhgW8UR9Go0gYuEOLKuPzrGL4HFAZPsVw==} engines: {node: '>= 10'} peerDependencies: '@coral-xyz/anchor': ^0.30.0 - '@solana/web3.js': '>=1.78.4 <1.92.0' - solana-bankrun: ^0.2.0 + '@solana/web3.js': '>1.92.0' + solana-bankrun: '>=0.2.0 <0.5.0' - ansi-colors@4.1.1: - resolution: {integrity: sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==} + ansi-colors@4.1.3: + resolution: {integrity: sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw==} engines: {node: '>=6'} ansi-regex@5.0.1: @@ -228,8 +225,8 @@ packages: borsh@0.7.0: resolution: {integrity: sha512-CLCsZGIBCFnPtkNnieW/a8wmreDmfUtjU2m9yHrzPXIlNbqVs0AQrSatSG6vdNYUqdc83tkQi2eHfF98ubzQLA==} - brace-expansion@1.1.11: - resolution: {integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==} + brace-expansion@2.0.1: + resolution: {integrity: sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==} braces@3.0.2: resolution: {integrity: sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==} @@ -295,9 +292,6 @@ packages: commander@2.20.3: resolution: {integrity: sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==} - concat-map@0.0.1: - resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} - cross-fetch@3.1.8: resolution: {integrity: sha512-cvA+JwZoU0Xq+h6WkMvAUqPEYy92Obet6UdKLfW60qn99ftItKjB5T+BkyWOFWe2pUyfQ+IJHmpOTznqk1M6Kg==} @@ -305,8 +299,8 @@ packages: resolution: {integrity: sha512-lyAZ0EMyjDkVvz8WOeVnuCPvKVBXcMv1l5SVqO1yC7PzTwrD/pPje/BIRbWhMoPe436U+Y2nD7f5bFx0kt+Sbg==} engines: {node: '>=8'} - debug@4.3.3: - resolution: {integrity: sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==} + debug@4.3.7: + resolution: {integrity: sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==} engines: {node: '>=6.0'} peerDependencies: supports-color: '*' @@ -330,8 +324,8 @@ packages: resolution: {integrity: sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==} engines: {node: '>=0.3.1'} - diff@5.0.0: - resolution: {integrity: sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==} + diff@5.2.0: + resolution: {integrity: sha512-uIFDxqpRZGZ6ThOk84hEfqWoHx2devRFvpTZcTHur85vImfaxUbTW9Ryh4CpCuDnToOP1CEtXKIgytHBPVff5A==} engines: {node: '>=0.3.1'} dot-case@3.0.4: @@ -401,12 +395,10 @@ packages: resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==} engines: {node: '>= 6'} - glob@7.2.0: - resolution: {integrity: sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==} - - growl@1.10.5: - resolution: {integrity: sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==} - engines: {node: '>=4.x'} + glob@8.1.0: + resolution: {integrity: sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==} + engines: {node: '>=12'} + deprecated: Glob versions prior to v9 are no longer supported has-flag@4.0.0: resolution: {integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==} @@ -424,6 +416,7 @@ packages: inflight@1.0.6: resolution: {integrity: sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==} + deprecated: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful. inherits@2.0.4: resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} @@ -456,9 +449,6 @@ packages: resolution: {integrity: sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==} engines: {node: '>=10'} - isexe@2.0.0: - resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} - isomorphic-ws@4.0.1: resolution: {integrity: sha512-BhBvN2MBpWTaSHdWRb/bwdZJ1WaehQ2L1KngkCkfLUGF0mAWAT1sQUQacEmQ0jXkFw/czDXPNQSL5u2/Krsz1w==} peerDependencies: @@ -501,11 +491,8 @@ packages: make-error@1.3.6: resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==} - minimatch@3.1.2: - resolution: {integrity: sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==} - - minimatch@4.2.1: - resolution: {integrity: sha512-9Uq1ChtSZO+Mxa/CL1eGizn2vRn3MlLgzhT0Iz8zaY8NdvxvB0d5QdPFmCKf7JKA9Lerx5vRrnwO03jsSfGG9g==} + minimatch@5.1.6: + resolution: {integrity: sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==} engines: {node: '>=10'} minimist@1.2.8: @@ -515,22 +502,14 @@ packages: resolution: {integrity: sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==} hasBin: true - mocha@9.2.2: - resolution: {integrity: sha512-L6XC3EdwT6YrIk0yXpavvLkn8h+EU+Y5UcCHKECyMbdUIxyMuZj4bX4U9e1nvnvUUvQVsV2VHQr5zLdcUkhW/g==} - engines: {node: '>= 12.0.0'} + mocha@10.8.2: + resolution: {integrity: sha512-VZlYo/WE8t1tstuRmqgeyBgCbJc/lEdopaa+axcKzTBJ+UIdlAB9XnmvTCAH4pwR4ElNInaedhEBmZD8iCSVEg==} + engines: {node: '>= 14.0.0'} hasBin: true - ms@2.1.2: - resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} - ms@2.1.3: resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} - nanoid@3.3.1: - resolution: {integrity: sha512-n6Vs/3KGyxPQd6uO0eH4Bv0ojGSUvuLlIHtC3Y0kEO23YRge8H9x1GCzLn28YX0H66pMkxuaeESFq4tKISKwdw==} - engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} - hasBin: true - no-case@3.0.4: resolution: {integrity: sha512-fgAN3jGAh+RoxUGZHTSOLJIqUc2wmoBwGR4tbpNAKmmovFoWq0OdRkb0VkldReO2a2iBT/OEulG9XSUc10r3zg==} @@ -569,10 +548,6 @@ packages: resolution: {integrity: sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==} engines: {node: '>=8'} - path-is-absolute@1.0.1: - resolution: {integrity: sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==} - engines: {node: '>=0.10.0'} - pathval@1.1.1: resolution: {integrity: sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==} @@ -605,43 +580,43 @@ packages: safe-buffer@5.2.1: resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==} - serialize-javascript@6.0.0: - resolution: {integrity: sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag==} + serialize-javascript@6.0.2: + resolution: {integrity: sha512-Saa1xPByTTq2gdeFZYLLo+RFE35NHZkAbqZeWNd3BpzppeVisAqpDjcp8dyf6uIvEqJRd46jemmyA4iFIeVk8g==} snake-case@3.0.4: resolution: {integrity: sha512-LAOh4z89bGQvl9pFfNF8V146i7o7/CqFPbqzYgP+yYzDIDeS9HaNFtXABamRW+AQzEVODcvE79ljJ+8a9YSdMg==} - solana-bankrun-darwin-arm64@0.3.1: - resolution: {integrity: sha512-9LWtH/3/WR9fs8Ve/srdo41mpSqVHmRqDoo69Dv1Cupi+o1zMU6HiEPUHEvH2Tn/6TDbPEDf18MYNfReLUqE6A==} + solana-bankrun-darwin-arm64@0.4.0: + resolution: {integrity: sha512-6dz78Teoz7ez/3lpRLDjktYLJb79FcmJk2me4/YaB8WiO6W43OdExU4h+d2FyuAryO2DgBPXaBoBNY/8J1HJmw==} engines: {node: '>= 10'} cpu: [arm64] os: [darwin] - solana-bankrun-darwin-universal@0.3.1: - resolution: {integrity: sha512-muGHpVYWT7xCd8ZxEjs/bmsbMp8XBqroYGbE4lQPMDUuLvsJEIrjGqs3MbxEFr71sa58VpyvgywWd5ifI7sGIg==} + solana-bankrun-darwin-universal@0.4.0: + resolution: {integrity: sha512-zSSw/Jx3KNU42pPMmrEWABd0nOwGJfsj7nm9chVZ3ae7WQg3Uty0hHAkn5NSDCj3OOiN0py9Dr1l9vmRJpOOxg==} engines: {node: '>= 10'} os: [darwin] - solana-bankrun-darwin-x64@0.3.1: - resolution: {integrity: sha512-oCaxfHyt7RC3ZMldrh5AbKfy4EH3YRMl8h6fSlMZpxvjQx7nK7PxlRwMeflMnVdkKKp7U8WIDak1lilIPd3/lg==} + solana-bankrun-darwin-x64@0.4.0: + resolution: {integrity: sha512-LWjs5fsgHFtyr7YdJR6r0Ho5zrtzI6CY4wvwPXr8H2m3b4pZe6RLIZjQtabCav4cguc14G0K8yQB2PTMuGub8w==} engines: {node: '>= 10'} cpu: [x64] os: [darwin] - solana-bankrun-linux-x64-gnu@0.3.1: - resolution: {integrity: sha512-PfRFhr7igGFNt2Ecfdzh3li9eFPB3Xhmk0Eib17EFIB62YgNUg3ItRnQQFaf0spazFjjJLnglY1TRKTuYlgSVA==} + solana-bankrun-linux-x64-gnu@0.4.0: + resolution: {integrity: sha512-SrlVrb82UIxt21Zr/XZFHVV/h9zd2/nP25PMpLJVLD7Pgl2yhkhfi82xj3OjxoQqWe+zkBJ+uszA0EEKr67yNw==} engines: {node: '>= 10'} cpu: [x64] os: [linux] - solana-bankrun-linux-x64-musl@0.3.1: - resolution: {integrity: sha512-6r8i0NuXg3CGURql8ISMIUqhE7Hx/O7MlIworK4oN08jYrP0CXdLeB/hywNn7Z8d1NXrox/NpYUgvRm2yIzAsQ==} + solana-bankrun-linux-x64-musl@0.4.0: + resolution: {integrity: sha512-Nv328ZanmURdYfcLL+jwB1oMzX4ZzK57NwIcuJjGlf0XSNLq96EoaO5buEiUTo4Ls7MqqMyLbClHcrPE7/aKyA==} engines: {node: '>= 10'} cpu: [x64] os: [linux] - solana-bankrun@0.3.1: - resolution: {integrity: sha512-inRwON7fBU5lPC36HdEqPeDg15FXJYcf77+o0iz9amvkUMJepcwnRwEfTNyMVpVYdgjTOBW5vg+596/3fi1kGA==} + solana-bankrun@0.4.0: + resolution: {integrity: sha512-NMmXUipPBkt8NgnyNO3SCnPERP6xT/AMNMBooljGA3+rG6NN8lmXJsKeLqQTiFsDeWD74U++QM/DgcueSWvrIg==} engines: {node: '>= 10'} source-map-support@0.5.21: @@ -719,9 +694,9 @@ packages: resolution: {integrity: sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==} engines: {node: '>=4'} - typescript@4.9.5: - resolution: {integrity: sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==} - engines: {node: '>=4.2.0'} + typescript@5.6.3: + resolution: {integrity: sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==} + engines: {node: '>=14.17'} hasBin: true undici-types@5.26.5: @@ -741,13 +716,8 @@ packages: whatwg-url@5.0.0: resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==} - which@2.0.2: - resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==} - engines: {node: '>= 8'} - hasBin: true - - workerpool@6.2.0: - resolution: {integrity: sha512-Rsk5qQHJ9eowMH28Jwhe8HEbmdYDX4lwoMWshiCXugjtHqMD9ZbiqSDLxcsfdqsETPzVUtX5s1Z5kStiIM6l4A==} + workerpool@6.5.1: + resolution: {integrity: sha512-Fs4dNYcsdpYSAfVxhnl1L5zTksjvOJxtC5hzMNl+1t9B8hTJTdKDyZ5ju7ztgPy+ft9tBFXoOlDNiOT9WUXZlA==} wrap-ansi@7.0.0: resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==} @@ -784,8 +754,8 @@ packages: resolution: {integrity: sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==} engines: {node: '>=10'} - yargs-parser@20.2.4: - resolution: {integrity: sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA==} + yargs-parser@20.2.9: + resolution: {integrity: sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==} engines: {node: '>=10'} yargs-unparser@2.0.0: @@ -972,7 +942,7 @@ snapshots: '@types/json5@0.0.29': optional: true - '@types/mocha@9.1.1': {} + '@types/mocha@10.0.9': {} '@types/node@12.20.55': {} @@ -984,8 +954,6 @@ snapshots: dependencies: '@types/node': 12.20.55 - '@ungap/promise-all-settled@1.1.2': {} - JSONStream@1.3.5: dependencies: jsonparse: 1.3.1 @@ -995,13 +963,13 @@ snapshots: dependencies: humanize-ms: 1.2.1 - anchor-bankrun@0.4.1(@coral-xyz/anchor@0.30.1(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.1(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.91.8(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.91.8(bufferutil@4.0.8)(utf-8-validate@5.0.10) - solana-bankrun: 0.3.1(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: {} + ansi-colors@4.1.3: {} ansi-regex@5.0.1: {} @@ -1048,10 +1016,9 @@ snapshots: bs58: 4.0.1 text-encoding-utf-8: 1.0.2 - brace-expansion@1.1.11: + brace-expansion@2.0.1: dependencies: balanced-match: 1.0.2 - concat-map: 0.0.1 braces@3.0.2: dependencies: @@ -1128,8 +1095,6 @@ snapshots: commander@2.20.3: {} - concat-map@0.0.1: {} - cross-fetch@3.1.8: dependencies: node-fetch: 2.7.0 @@ -1138,9 +1103,9 @@ snapshots: crypto-hash@1.3.0: {} - debug@4.3.3(supports-color@8.1.1): + debug@4.3.7(supports-color@8.1.1): dependencies: - ms: 2.1.2 + ms: 2.1.3 optionalDependencies: supports-color: 8.1.1 @@ -1154,7 +1119,7 @@ snapshots: diff@3.5.0: {} - diff@5.0.0: {} + diff@5.2.0: {} dot-case@3.0.4: dependencies: @@ -1207,16 +1172,13 @@ snapshots: dependencies: is-glob: 4.0.3 - glob@7.2.0: + glob@8.1.0: dependencies: fs.realpath: 1.0.0 inflight: 1.0.6 inherits: 2.0.4 - minimatch: 3.1.2 + minimatch: 5.1.6 once: 1.4.0 - path-is-absolute: 1.0.1 - - growl@1.10.5: {} has-flag@4.0.0: {} @@ -1253,8 +1215,6 @@ snapshots: is-unicode-supported@0.1.0: {} - isexe@2.0.0: {} - isomorphic-ws@4.0.1(ws@7.5.9(bufferutil@4.0.8)(utf-8-validate@5.0.10)): dependencies: ws: 7.5.9(bufferutil@4.0.8)(utf-8-validate@5.0.10) @@ -1309,13 +1269,9 @@ snapshots: make-error@1.3.6: {} - minimatch@3.1.2: + minimatch@5.1.6: dependencies: - brace-expansion: 1.1.11 - - minimatch@4.2.1: - dependencies: - brace-expansion: 1.1.11 + brace-expansion: 2.0.1 minimist@1.2.8: {} @@ -1323,39 +1279,31 @@ snapshots: dependencies: minimist: 1.2.8 - mocha@9.2.2: + mocha@10.8.2: dependencies: - '@ungap/promise-all-settled': 1.1.2 - ansi-colors: 4.1.1 + ansi-colors: 4.1.3 browser-stdout: 1.3.1 chokidar: 3.5.3 - debug: 4.3.3(supports-color@8.1.1) - diff: 5.0.0 + debug: 4.3.7(supports-color@8.1.1) + diff: 5.2.0 escape-string-regexp: 4.0.0 find-up: 5.0.0 - glob: 7.2.0 - growl: 1.10.5 + glob: 8.1.0 he: 1.2.0 js-yaml: 4.1.0 log-symbols: 4.1.0 - minimatch: 4.2.1 + minimatch: 5.1.6 ms: 2.1.3 - nanoid: 3.3.1 - serialize-javascript: 6.0.0 + serialize-javascript: 6.0.2 strip-json-comments: 3.1.1 supports-color: 8.1.1 - which: 2.0.2 - workerpool: 6.2.0 + workerpool: 6.5.1 yargs: 16.2.0 - yargs-parser: 20.2.4 + yargs-parser: 20.2.9 yargs-unparser: 2.0.0 - ms@2.1.2: {} - ms@2.1.3: {} - nanoid@3.3.1: {} - no-case@3.0.4: dependencies: lower-case: 2.0.2 @@ -1386,8 +1334,6 @@ snapshots: path-exists@4.0.0: {} - path-is-absolute@1.0.1: {} - pathval@1.1.1: {} picomatch@2.3.1: {} @@ -1417,7 +1363,7 @@ snapshots: safe-buffer@5.2.1: {} - serialize-javascript@6.0.0: + serialize-javascript@6.0.2: dependencies: randombytes: 2.1.0 @@ -1426,31 +1372,31 @@ snapshots: dot-case: 3.0.4 tslib: 2.6.2 - solana-bankrun-darwin-arm64@0.3.1: + solana-bankrun-darwin-arm64@0.4.0: optional: true - solana-bankrun-darwin-universal@0.3.1: + solana-bankrun-darwin-universal@0.4.0: optional: true - solana-bankrun-darwin-x64@0.3.1: + solana-bankrun-darwin-x64@0.4.0: optional: true - solana-bankrun-linux-x64-gnu@0.3.1: + solana-bankrun-linux-x64-gnu@0.4.0: optional: true - solana-bankrun-linux-x64-musl@0.3.1: + solana-bankrun-linux-x64-musl@0.4.0: optional: true - solana-bankrun@0.3.1(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: '@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.1 - solana-bankrun-darwin-universal: 0.3.1 - solana-bankrun-darwin-x64: 0.3.1 - solana-bankrun-linux-x64-gnu: 0.3.1 - solana-bankrun-linux-x64-musl: 0.3.1 + solana-bankrun-darwin-arm64: 0.4.0 + solana-bankrun-darwin-universal: 0.4.0 + solana-bankrun-darwin-x64: 0.4.0 + solana-bankrun-linux-x64-gnu: 0.4.0 + solana-bankrun-linux-x64-musl: 0.4.0 transitivePeerDependencies: - bufferutil - encoding @@ -1502,9 +1448,9 @@ snapshots: tr46@0.0.3: {} - ts-mocha@10.0.0(mocha@9.2.2): + ts-mocha@10.0.0(mocha@10.8.2): dependencies: - mocha: 9.2.2 + mocha: 10.8.2 ts-node: 7.0.1 optionalDependencies: tsconfig-paths: 3.15.0 @@ -1532,7 +1478,7 @@ snapshots: type-detect@4.0.8: {} - typescript@4.9.5: {} + typescript@5.6.3: {} undici-types@5.26.5: {} @@ -1550,11 +1496,7 @@ snapshots: tr46: 0.0.3 webidl-conversions: 3.0.1 - which@2.0.2: - dependencies: - isexe: 2.0.0 - - workerpool@6.2.0: {} + workerpool@6.5.1: {} wrap-ansi@7.0.0: dependencies: @@ -1576,7 +1518,7 @@ snapshots: y18n@5.0.8: {} - yargs-parser@20.2.4: {} + yargs-parser@20.2.9: {} yargs-unparser@2.0.0: dependencies: @@ -1593,7 +1535,7 @@ snapshots: require-directory: 2.1.1 string-width: 4.2.3 y18n: 5.0.8 - yargs-parser: 20.2.4 + yargs-parser: 20.2.9 yn@2.0.0: {} diff --git a/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/instructions/configure_admin.rs b/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/instructions/configure_admin.rs new file mode 100644 index 000000000..da6873e5c --- /dev/null +++ b/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/instructions/configure_admin.rs @@ -0,0 +1,49 @@ +use {crate::state::AdminConfig, anchor_lang::prelude::*}; + +#[derive(Accounts)] +pub struct ConfigureAdmin<'info> { + #[account(mut)] + pub admin: Signer<'info>, + + /// CHECK: the new admin + #[account(mut)] + pub new_admin: UncheckedAccount<'info>, + + /// To hold the address of the admin that controls switches + #[account( + init_if_needed, + payer=admin, + space=8+AdminConfig::INIT_SPACE, + seeds=[b"admin-config"], + bump + )] + pub admin_config: Account<'info, AdminConfig>, + + pub system_program: Program<'info, System>, +} + +impl<'info> ConfigureAdmin<'info> { + pub fn is_admin(&self) -> Result<()> { + // check if we are not creating the account for the first time, + // ensure it's the admin that is making the change + // + if self.admin_config.is_initialised { + // make sure it's the admin + // + require_keys_eq!(self.admin.key(), self.admin_config.admin,); + + // make sure the admin is not reentering their key + // + require_keys_neq!(self.admin.key(), self.new_admin.key()); + } + Ok(()) + } + + pub fn configure_admin(&mut self) -> Result<()> { + self.admin_config.set_inner(AdminConfig { + admin: self.new_admin.key(), // set the admin pubkey that can switch transfers on/off + is_initialised: true, // let us know an admin has been set + }); + Ok(()) + } +} diff --git a/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/instructions/initialise_extra_account_metas_list.rs b/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/instructions/initialise_extra_account_metas_list.rs index 9ed66788e..cdc7d3799 100644 --- a/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/instructions/initialise_extra_account_metas_list.rs +++ b/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/instructions/initialise_extra_account_metas_list.rs @@ -1,5 +1,4 @@ use { - crate::state::AdminConfig, anchor_lang::{ prelude::*, system_program::{create_account, CreateAccount}, @@ -12,24 +11,13 @@ use { }; #[derive(Accounts)] -// #[instruction(decimals: u8)] pub struct InitializeExtraAccountMetas<'info> { #[account(mut)] - pub admin: Signer<'info>, + pub payer: Signer<'info>, #[account()] pub token_mint: InterfaceAccount<'info, Mint>, - /// CHECK: this account we use to take note of listings - #[account( - init, - payer=admin, - space=8+AdminConfig::INIT_SPACE, - seeds=[b"admin-config"], - bump - )] - pub admin_config: Account<'info, AdminConfig>, - /// CHECK: extra accoumt metas list #[account( mut, @@ -42,19 +30,12 @@ pub struct InitializeExtraAccountMetas<'info> { } impl<'info> InitializeExtraAccountMetas<'info> { - pub fn init_admin_config(&mut self) -> Result<()> { - self.admin_config.set_inner(AdminConfig { - admin: self.admin.key(), // set the admin pubkey that can switch transfers on/off - }); - Ok(()) - } - pub fn initialize_extra_account_metas_list( &self, bumps: InitializeExtraAccountMetasBumps, ) -> Result<()> { let account_metas = vec![ - // 5 - user (sender) config account + // 5 - wallet (sender) config account ExtraAccountMeta::new_with_seeds( &[ Seed::AccountKey { index: 3 }, // sender index @@ -81,7 +62,7 @@ impl<'info> InitializeExtraAccountMetas<'info> { CpiContext::new( self.system_program.to_account_info(), CreateAccount { - from: self.admin.to_account_info(), + from: self.payer.to_account_info(), to: self.extra_account_metas_list.to_account_info(), }, ) diff --git a/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/instructions/mod.rs b/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/instructions/mod.rs index 1a7639af3..1bd4e8144 100644 --- a/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/instructions/mod.rs +++ b/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/instructions/mod.rs @@ -1,7 +1,9 @@ pub mod initialise_extra_account_metas_list; pub mod switch; pub mod transfer_hook; +pub mod configure_admin; pub use initialise_extra_account_metas_list::*; pub use switch::*; pub use transfer_hook::*; +pub use configure_admin::*; diff --git a/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/instructions/switch.rs b/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/instructions/switch.rs index c622fb890..a366e4b93 100644 --- a/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/instructions/switch.rs +++ b/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/instructions/switch.rs @@ -6,14 +6,15 @@ use { #[derive(Accounts)] #[instruction(decimals: u8)] pub struct Switch<'info> { + /// admin that controls the switch #[account(mut)] pub admin: Signer<'info>, - /// CHECK: sender + /// CHECK: wallet - transfer sender #[account(mut)] - pub user: UncheckedAccount<'info>, + pub wallet: UncheckedAccount<'info>, - /// CHECK: this account we use to take note of listings + /// admin config #[account( has_one=admin, seeds=[b"admin-config"], @@ -21,22 +22,27 @@ pub struct Switch<'info> { )] pub admin_config: Account<'info, AdminConfig>, - /// CHECK: this account we use to take note of listings + /// the wallet (sender) transfer switch #[account( init_if_needed, payer=admin, space=8+TransferSwitch::INIT_SPACE, - seeds=[user.key().as_ref()], + seeds=[wallet.key().as_ref()], bump, )] - pub user_switch: Account<'info, TransferSwitch>, + pub wallet_switch: Account<'info, TransferSwitch>, pub system_program: Program<'info, System>, } impl<'info> Switch<'info> { pub fn switch(&mut self, on: bool) -> Result<()> { - self.user_switch.set_inner(TransferSwitch { on }); + // toggle switch on/off for the given wallet + // + self.wallet_switch.set_inner(TransferSwitch { + wallet: self.wallet.key(), + on, + }); Ok(()) } } diff --git a/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/instructions/transfer_hook.rs b/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/instructions/transfer_hook.rs index ae8235ed4..c79e9cbb7 100644 --- a/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/instructions/transfer_hook.rs +++ b/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/instructions/transfer_hook.rs @@ -30,7 +30,7 @@ pub struct TransferHook<'info> { /// CHECK: the transfer sender #[account()] - pub sender: UncheckedAccount<'info>, + pub wallet: UncheckedAccount<'info>, /// CHECK: extra account metas #[account( @@ -39,17 +39,17 @@ pub struct TransferHook<'info> { )] pub extra_account_metas_list: UncheckedAccount<'info>, - /// sender transfer switch account + /// sender transfer switch #[account( - seeds=[sender.key().as_ref()], + seeds=[wallet.key().as_ref()], bump, )] - pub sender_switch: Account<'info, TransferSwitch>, + pub wallet_switch: Account<'info, TransferSwitch>, } impl<'info> TransferHook<'info> { pub fn assert_switch_is_on(&mut self) -> Result<()> { - if !self.sender_switch.on { + if !self.wallet_switch.on { return err!(TransferError::SwitchNotOn); } Ok(()) diff --git a/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/lib.rs b/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/lib.rs index 0c674b602..8b3d66b9e 100644 --- a/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/lib.rs +++ b/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/lib.rs @@ -11,12 +11,14 @@ declare_id!("FjcHckEgXcBhFmSGai3FRpDLiT6hbpV893n8iTxVd81g"); pub mod transfer_switch { use super::*; + pub fn configure_admin(ctx: Context) -> Result<()> { + ctx.accounts.is_admin()?; + ctx.accounts.configure_admin() + } + #[interface(spl_transfer_hook_interface::initialize_extra_account_meta_list)] - pub fn create(ctx: Context) -> Result<()> { - ctx.accounts - .initialize_extra_account_metas_list(ctx.bumps)?; - ctx.accounts.init_admin_config()?; - Ok(()) + pub fn initialize_extra_account_metas_list(ctx: Context) -> Result<()> { + ctx.accounts.initialize_extra_account_metas_list(ctx.bumps) } pub fn switch(ctx: Context, on: bool) -> Result<()> { diff --git a/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/state.rs b/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/state.rs index 7e86aa151..8130c7118 100644 --- a/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/state.rs +++ b/tokens/token-2022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/state.rs @@ -3,11 +3,13 @@ use anchor_lang::prelude::*; #[account] #[derive(InitSpace)] pub struct TransferSwitch { + pub wallet: Pubkey, pub on: bool, } #[account] #[derive(InitSpace)] pub struct AdminConfig { + pub is_initialised: bool, pub admin: Pubkey, } diff --git a/tokens/token-2022/transfer-hook/transfer-switch/anchor/tests/transfer-switch.ts b/tokens/token-2022/transfer-hook/transfer-switch/anchor/tests/transfer-switch.ts index 4886a655d..9db80fd77 100644 --- a/tokens/token-2022/transfer-hook/transfer-switch/anchor/tests/transfer-switch.ts +++ b/tokens/token-2022/transfer-hook/transfer-switch/anchor/tests/transfer-switch.ts @@ -2,6 +2,7 @@ import { describe, it } from 'node:test'; import * as anchor from '@coral-xyz/anchor'; import { ASSOCIATED_TOKEN_PROGRAM_ID, + AccountLayout, ExtensionType, TOKEN_2022_PROGRAM_ID, createAssociatedTokenAccountInstruction, @@ -12,7 +13,7 @@ import { getAssociatedTokenAddressSync, getMintLen, } from '@solana/spl-token'; -import { PublicKey, sendAndConfirmTransaction } from '@solana/web3.js'; +import { PublicKey } from '@solana/web3.js'; import { Keypair, SystemProgram } from '@solana/web3.js'; import { Transaction } from '@solana/web3.js'; import { TransactionInstruction } from '@solana/web3.js'; @@ -63,6 +64,12 @@ describe('Transfer switch', async () => { return [user, userTokenAccount, createUserTokenAccountIx]; } + // admin config address + const adminConfigAddress = PublicKey.findProgramAddressSync([Buffer.from('admin-config')], PROGRAM_ID)[0]; + + // helper for getting wallet switch + const walletTransferSwitchAddress = (wallet: PublicKey) => PublicKey.findProgramAddressSync([wallet.toBuffer()], PROGRAM_ID)[0]; + // sender const [sender, senderTokenAccount, senderTokenAccountCreateIx] = newUser(); @@ -112,27 +119,50 @@ describe('Transfer switch', async () => { }); // Account to store extra accounts required by the transfer hook instruction + // This will be called for every mint + // it('Create ExtraAccountMetaList Account', async () => { await program.methods - .create() + .initializeExtraAccountMetasList() .accounts({ - admin: payer.publicKey, + payer: payer.publicKey, tokenMint: mint.publicKey, }) .signers([payer]) .rpc(); }); + // Set the account that controls the switches for the wallet + it('Configure an admin', async () => { + await program.methods + .configureAdmin() + .accounts({ + admin: payer.publicKey, + newAdmin: payer.publicKey, + }) + .signers([payer]) + .rpc(); + + const adminConfig = await program.account.adminConfig.fetch(adminConfigAddress); + assert(adminConfig.isInitialised === true, 'admin config not initialised'); + assert(adminConfig.admin.toBase58() === payer.publicKey.toBase58(), 'admin does not match'); + }); + // Account to store extra accounts required by the transfer hook instruction it('turn transfers off for sender', async () => { await program.methods .switch(false) .accountsPartial({ - user: sender.publicKey, + wallet: sender.publicKey, admin: payer.publicKey, }) .signers([payer]) .rpc(); + + const walletSwitch = await program.account.transferSwitch.fetch(walletTransferSwitchAddress(sender.publicKey)); + + assert(walletSwitch.wallet.toBase58() === sender.publicKey.toBase58(), 'wallet key does not match'); + assert(!walletSwitch.on, 'wallet switch not set to false'); }); it('Try transfer, should fail!', async () => { @@ -142,6 +172,17 @@ describe('Transfer switch', async () => { const [recipient, recipientTokenAccount, recipientTokenAccountCreateIx] = newUser(); + // create the recipient token account ahead of the transfer, + // + let transaction = new Transaction().add( + recipientTokenAccountCreateIx, // create recipient token account + ); + + transaction.recentBlockhash = context.lastBlockhash; + transaction.sign(payer, recipient); + + client.processTransaction(transaction); + // Standard token transfer instruction const transferInstruction = await createTransferCheckedWithTransferHookInstruction( connection, @@ -156,15 +197,21 @@ describe('Transfer switch', async () => { TOKEN_2022_PROGRAM_ID, ); - const transaction = new Transaction().add( - recipientTokenAccountCreateIx, // create recipient token account + transaction = new Transaction().add( transferInstruction, // transfer instruction ); transaction.recentBlockhash = context.lastBlockhash; transaction.sign(payer, sender); + // expect the transaction to fail + // expectRevert(client.processTransaction(transaction)); + + const recipientTokenAccountData = (await client.getAccount(recipientTokenAccount)).data; + const recipientBalance = AccountLayout.decode(recipientTokenAccountData).amount; + + assert(recipientBalance === BigInt(0), 'transfer was successful'); }); // Account to store extra accounts required by the transfer hook instruction @@ -172,11 +219,16 @@ describe('Transfer switch', async () => { await program.methods .switch(true) .accountsPartial({ - user: sender.publicKey, + wallet: sender.publicKey, admin: payer.publicKey, }) .signers([payer]) .rpc(); + + const walletSwitch = await program.account.transferSwitch.fetch(walletTransferSwitchAddress(sender.publicKey)); + + assert(walletSwitch.wallet.toBase58() === sender.publicKey.toBase58(), 'wallet key does not match'); + assert(walletSwitch.on, 'wallet switch not set to true'); }); it('Send successfully', async () => { @@ -206,5 +258,11 @@ describe('Transfer switch', async () => { transaction.sign(payer, sender); await client.processTransaction(transaction); + + const recipientTokenAccountData = (await client.getAccount(recipientTokenAccount)).data; + + const recipientBalance = AccountLayout.decode(recipientTokenAccountData).amount; + + assert(recipientBalance === bigIntAmount, 'transfer was not successful'); }); });