Browse Source

✅ Fixing Anchor TS usage (#173)

Danilo Guanabara 5 months ago
parent
commit
303322d3f4

+ 21 - 31
clients/typescript/package-lock.json

@@ -1,15 +1,15 @@
 {
   "name": "@magicblock-labs/bolt-sdk",
-  "version": "0.2.1",
+  "version": "0.2.2",
   "lockfileVersion": 3,
   "requires": true,
   "packages": {
     "": {
       "name": "@magicblock-labs/bolt-sdk",
-      "version": "0.2.1",
+      "version": "0.2.2",
       "license": "MIT",
       "dependencies": {
-        "@coral-xyz/anchor": "^0.30.1",
+        "@coral-xyz/anchor": "^0.31.1",
         "@magicblock-labs/ephemeral-rollups-sdk": "0.2.1",
         "@metaplex-foundation/beet": "^0.7.1",
         "@metaplex-foundation/beet-solana": "^0.4.0"
@@ -36,44 +36,42 @@
       }
     },
     "node_modules/@coral-xyz/anchor": {
-      "version": "0.30.1",
-      "resolved": "https://registry.npmjs.org/@coral-xyz/anchor/-/anchor-0.30.1.tgz",
-      "integrity": "sha512-gDXFoF5oHgpriXAaLpxyWBHdCs8Awgf/gLHIo6crv7Aqm937CNdY+x+6hoj7QR5vaJV7MxWSQ0NGFzL3kPbWEQ==",
+      "version": "0.31.1",
+      "resolved": "https://registry.npmjs.org/@coral-xyz/anchor/-/anchor-0.31.1.tgz",
+      "integrity": "sha512-QUqpoEK+gi2S6nlYc2atgT2r41TT3caWr/cPUEL8n8Md9437trZ68STknq897b82p5mW0XrTBNOzRbmIRJtfsA==",
       "license": "(MIT OR Apache-2.0)",
       "dependencies": {
-        "@coral-xyz/anchor-errors": "^0.30.1",
-        "@coral-xyz/borsh": "^0.30.1",
+        "@coral-xyz/anchor-errors": "^0.31.1",
+        "@coral-xyz/borsh": "^0.31.1",
         "@noble/hashes": "^1.3.1",
-        "@solana/web3.js": "^1.68.0",
+        "@solana/web3.js": "^1.69.0",
         "bn.js": "^5.1.2",
         "bs58": "^4.0.1",
         "buffer-layout": "^1.2.2",
         "camelcase": "^6.3.0",
         "cross-fetch": "^3.1.5",
-        "crypto-hash": "^1.3.0",
         "eventemitter3": "^4.0.7",
         "pako": "^2.0.3",
-        "snake-case": "^3.0.4",
         "superstruct": "^0.15.4",
         "toml": "^3.0.0"
       },
       "engines": {
-        "node": ">=11"
+        "node": ">=17"
       }
     },
     "node_modules/@coral-xyz/anchor-errors": {
-      "version": "0.30.1",
-      "resolved": "https://registry.npmjs.org/@coral-xyz/anchor-errors/-/anchor-errors-0.30.1.tgz",
-      "integrity": "sha512-9Mkradf5yS5xiLWrl9WrpjqOrAV+/W2RQHDlbnAZBivoGpOs1ECjoDCkVk4aRG8ZdiFiB8zQEVlxf+8fKkmSfQ==",
+      "version": "0.31.1",
+      "resolved": "https://registry.npmjs.org/@coral-xyz/anchor-errors/-/anchor-errors-0.31.1.tgz",
+      "integrity": "sha512-NhNEku4F3zzUSBtrYz84FzYWm48+9OvmT1Hhnwr6GnPQry2dsEqH/ti/7ASjjpoFTWRnPXrjAIT1qM6Isop+LQ==",
       "license": "Apache-2.0",
       "engines": {
         "node": ">=10"
       }
     },
     "node_modules/@coral-xyz/borsh": {
-      "version": "0.30.1",
-      "resolved": "https://registry.npmjs.org/@coral-xyz/borsh/-/borsh-0.30.1.tgz",
-      "integrity": "sha512-aaxswpPrCFKl8vZTbxLssA2RvwX2zmKLlRCIktJOwW+VpVwYtXRtlWiIP+c2pPRKneiTiWCN2GEMSH9j1zTlWQ==",
+      "version": "0.31.1",
+      "resolved": "https://registry.npmjs.org/@coral-xyz/borsh/-/borsh-0.31.1.tgz",
+      "integrity": "sha512-9N8AU9F0ubriKfNE3g1WF0/4dtlGXoBN/hd1PvbNBamBNwRgHxH4P+o3Zt7rSEloW1HUs6LfZEchlx9fW7POYw==",
       "license": "Apache-2.0",
       "dependencies": {
         "bn.js": "^5.1.2",
@@ -83,7 +81,7 @@
         "node": ">=10"
       },
       "peerDependencies": {
-        "@solana/web3.js": "^1.68.0"
+        "@solana/web3.js": "^1.69.0"
       }
     },
     "node_modules/@isaacs/cliui": {
@@ -716,18 +714,6 @@
         "node": ">= 8"
       }
     },
-    "node_modules/crypto-hash": {
-      "version": "1.3.0",
-      "resolved": "https://registry.npmjs.org/crypto-hash/-/crypto-hash-1.3.0.tgz",
-      "integrity": "sha512-lyAZ0EMyjDkVvz8WOeVnuCPvKVBXcMv1l5SVqO1yC7PzTwrD/pPje/BIRbWhMoPe436U+Y2nD7f5bFx0kt+Sbg==",
-      "license": "MIT",
-      "engines": {
-        "node": ">=8"
-      },
-      "funding": {
-        "url": "https://github.com/sponsors/sindresorhus"
-      }
-    },
     "node_modules/debug": {
       "version": "4.4.0",
       "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz",
@@ -795,6 +781,7 @@
       "version": "3.0.4",
       "resolved": "https://registry.npmjs.org/dot-case/-/dot-case-3.0.4.tgz",
       "integrity": "sha512-Kv5nKlh6yRrdrGvxeJ2e5y2eRUpkUosIW4A2AS38zwSz27zu7ufDwQPi5Jhs3XAlGNetl3bmnGhQsMtkKJnj3w==",
+      "dev": true,
       "license": "MIT",
       "dependencies": {
         "no-case": "^3.0.4",
@@ -1380,6 +1367,7 @@
       "version": "2.0.2",
       "resolved": "https://registry.npmjs.org/lower-case/-/lower-case-2.0.2.tgz",
       "integrity": "sha512-7fm3l3NAF9WfN6W3JOmf5drwpVqX78JtoGJ3A6W0a6ZnldM41w2fV5D490psKFTpMds8TJse/eHLFFsNHHjHgg==",
+      "dev": true,
       "license": "MIT",
       "dependencies": {
         "tslib": "^2.0.3"
@@ -1474,6 +1462,7 @@
       "version": "3.0.4",
       "resolved": "https://registry.npmjs.org/no-case/-/no-case-3.0.4.tgz",
       "integrity": "sha512-fgAN3jGAh+RoxUGZHTSOLJIqUc2wmoBwGR4tbpNAKmmovFoWq0OdRkb0VkldReO2a2iBT/OEulG9XSUc10r3zg==",
+      "dev": true,
       "license": "MIT",
       "dependencies": {
         "lower-case": "^2.0.2",
@@ -1823,6 +1812,7 @@
       "version": "3.0.4",
       "resolved": "https://registry.npmjs.org/snake-case/-/snake-case-3.0.4.tgz",
       "integrity": "sha512-LAOh4z89bGQvl9pFfNF8V146i7o7/CqFPbqzYgP+yYzDIDeS9HaNFtXABamRW+AQzEVODcvE79ljJ+8a9YSdMg==",
+      "dev": true,
       "license": "MIT",
       "dependencies": {
         "dot-case": "^3.0.4",

+ 1 - 1
clients/typescript/package.json

@@ -9,7 +9,7 @@
     "@magicblock-labs/ephemeral-rollups-sdk": "0.2.1",
     "@metaplex-foundation/beet": "^0.7.1",
     "@metaplex-foundation/beet-solana": "^0.4.0",
-    "@coral-xyz/anchor": "^0.30.1"
+    "@coral-xyz/anchor": "^0.31.1"
   },
   "devDependencies": {
     "@metaplex-foundation/solita": "^0.20.1",

+ 77 - 5
clients/typescript/src/generated/idl/world.json

@@ -2,7 +2,7 @@
   "address": "WorLD15A7CrDwLcLy4fRqtaTb9fbd8o8iqiEMUDse2n",
   "metadata": {
     "name": "world",
-    "version": "0.2.1",
+    "version": "0.2.2",
     "spec": "0.1.0",
     "description": "Bolt World program",
     "repository": "https://github.com/magicblock-labs/bolt"
@@ -31,7 +31,25 @@
         },
         {
           "name": "world",
-          "writable": true
+          "writable": true,
+          "pda": {
+            "seeds": [
+              {
+                "kind": "const",
+                "value": [
+                  119,
+                  111,
+                  114,
+                  108,
+                  100
+                ]
+              },
+              {
+                "kind": "arg",
+                "path": "world_id"
+              }
+            ]
+          }
         },
         {
           "name": "system_program",
@@ -298,7 +316,26 @@
         },
         {
           "name": "world",
-          "writable": true
+          "writable": true,
+          "pda": {
+            "seeds": [
+              {
+                "kind": "const",
+                "value": [
+                  119,
+                  111,
+                  114,
+                  108,
+                  100
+                ]
+              },
+              {
+                "kind": "account",
+                "path": "registry.worlds",
+                "account": "Registry"
+              }
+            ]
+          }
         },
         {
           "name": "registry",
@@ -326,7 +363,24 @@
       "accounts": [
         {
           "name": "registry",
-          "writable": true
+          "writable": true,
+          "pda": {
+            "seeds": [
+              {
+                "kind": "const",
+                "value": [
+                  114,
+                  101,
+                  103,
+                  105,
+                  115,
+                  116,
+                  114,
+                  121
+                ]
+              }
+            ]
+          }
         },
         {
           "name": "payer",
@@ -363,7 +417,25 @@
         },
         {
           "name": "world",
-          "writable": true
+          "writable": true,
+          "pda": {
+            "seeds": [
+              {
+                "kind": "const",
+                "value": [
+                  119,
+                  111,
+                  114,
+                  108,
+                  100
+                ]
+              },
+              {
+                "kind": "arg",
+                "path": "world_id"
+              }
+            ]
+          }
         },
         {
           "name": "system_program",

+ 46 - 1
clients/typescript/src/generated/types/world.ts

@@ -8,7 +8,7 @@ export type World = {
   address: "WorLD15A7CrDwLcLy4fRqtaTb9fbd8o8iqiEMUDse2n";
   metadata: {
     name: "world";
-    version: "0.2.1";
+    version: "0.2.2";
     spec: "0.1.0";
     description: "Bolt World program";
     repository: "https://github.com/magicblock-labs/bolt";
@@ -29,6 +29,18 @@ export type World = {
         {
           name: "world";
           writable: true;
+          pda: {
+            seeds: [
+              {
+                kind: "const";
+                value: [119, 111, 114, 108, 100];
+              },
+              {
+                kind: "arg";
+                path: "worldId";
+              },
+            ];
+          };
         },
         {
           name: "systemProgram";
@@ -233,6 +245,19 @@ export type World = {
         {
           name: "world";
           writable: true;
+          pda: {
+            seeds: [
+              {
+                kind: "const";
+                value: [119, 111, 114, 108, 100];
+              },
+              {
+                kind: "account";
+                path: "registry.worlds";
+                account: "registry";
+              },
+            ];
+          };
         },
         {
           name: "registry";
@@ -252,6 +277,14 @@ export type World = {
         {
           name: "registry";
           writable: true;
+          pda: {
+            seeds: [
+              {
+                kind: "const";
+                value: [114, 101, 103, 105, 115, 116, 114, 121];
+              },
+            ];
+          };
         },
         {
           name: "payer";
@@ -280,6 +313,18 @@ export type World = {
         {
           name: "world";
           writable: true;
+          pda: {
+            seeds: [
+              {
+                kind: "const";
+                value: [119, 111, 114, 108, 100];
+              },
+              {
+                kind: "arg";
+                path: "worldId";
+              },
+            ];
+          };
         },
         {
           name: "systemProgram";

+ 2 - 2
clients/typescript/src/world/transactions.ts

@@ -157,7 +157,7 @@ export async function AddAuthority({
   const worldId = new BN(worldInstance.id);
   const instruction = await program.methods
     .addAuthority(worldId)
-    .accounts({
+    .accountsPartial({
       authority,
       newAuthority,
       world,
@@ -199,7 +199,7 @@ export async function RemoveAuthority({
   const worldId = new BN(worldInstance.id);
   const instruction = await program.methods
     .removeAuthority(worldId)
-    .accounts({
+    .accountsPartial({
       authority,
       authorityToDelete,
       world,

+ 18 - 25
clients/typescript/yarn.lock

@@ -9,36 +9,34 @@
   dependencies:
     regenerator-runtime "^0.14.0"
 
-"@coral-xyz/anchor-errors@^0.30.1":
-  version "0.30.1"
-  resolved "https://registry.npmjs.org/@coral-xyz/anchor-errors/-/anchor-errors-0.30.1.tgz"
-  integrity sha512-9Mkradf5yS5xiLWrl9WrpjqOrAV+/W2RQHDlbnAZBivoGpOs1ECjoDCkVk4aRG8ZdiFiB8zQEVlxf+8fKkmSfQ==
-
-"@coral-xyz/anchor@^0.30.1":
-  version "0.30.1"
-  resolved "https://registry.npmjs.org/@coral-xyz/anchor/-/anchor-0.30.1.tgz"
-  integrity sha512-gDXFoF5oHgpriXAaLpxyWBHdCs8Awgf/gLHIo6crv7Aqm937CNdY+x+6hoj7QR5vaJV7MxWSQ0NGFzL3kPbWEQ==
-  dependencies:
-    "@coral-xyz/anchor-errors" "^0.30.1"
-    "@coral-xyz/borsh" "^0.30.1"
+"@coral-xyz/anchor-errors@^0.31.1":
+  version "0.31.1"
+  resolved "https://registry.npmjs.org/@coral-xyz/anchor-errors/-/anchor-errors-0.31.1.tgz"
+  integrity sha512-NhNEku4F3zzUSBtrYz84FzYWm48+9OvmT1Hhnwr6GnPQry2dsEqH/ti/7ASjjpoFTWRnPXrjAIT1qM6Isop+LQ==
+
+"@coral-xyz/anchor@^0.31.1":
+  version "0.31.1"
+  resolved "https://registry.npmjs.org/@coral-xyz/anchor/-/anchor-0.31.1.tgz"
+  integrity sha512-QUqpoEK+gi2S6nlYc2atgT2r41TT3caWr/cPUEL8n8Md9437trZ68STknq897b82p5mW0XrTBNOzRbmIRJtfsA==
+  dependencies:
+    "@coral-xyz/anchor-errors" "^0.31.1"
+    "@coral-xyz/borsh" "^0.31.1"
     "@noble/hashes" "^1.3.1"
-    "@solana/web3.js" "^1.68.0"
+    "@solana/web3.js" "^1.69.0"
     bn.js "^5.1.2"
     bs58 "^4.0.1"
     buffer-layout "^1.2.2"
     camelcase "^6.3.0"
     cross-fetch "^3.1.5"
-    crypto-hash "^1.3.0"
     eventemitter3 "^4.0.7"
     pako "^2.0.3"
-    snake-case "^3.0.4"
     superstruct "^0.15.4"
     toml "^3.0.0"
 
-"@coral-xyz/borsh@^0.30.1":
-  version "0.30.1"
-  resolved "https://registry.npmjs.org/@coral-xyz/borsh/-/borsh-0.30.1.tgz"
-  integrity sha512-aaxswpPrCFKl8vZTbxLssA2RvwX2zmKLlRCIktJOwW+VpVwYtXRtlWiIP+c2pPRKneiTiWCN2GEMSH9j1zTlWQ==
+"@coral-xyz/borsh@^0.31.1":
+  version "0.31.1"
+  resolved "https://registry.npmjs.org/@coral-xyz/borsh/-/borsh-0.31.1.tgz"
+  integrity sha512-9N8AU9F0ubriKfNE3g1WF0/4dtlGXoBN/hd1PvbNBamBNwRgHxH4P+o3Zt7rSEloW1HUs6LfZEchlx9fW7POYw==
   dependencies:
     bn.js "^5.1.2"
     buffer-layout "^1.2.0"
@@ -145,7 +143,7 @@
   dependencies:
     buffer "~6.0.3"
 
-"@solana/web3.js@^1.56.2", "@solana/web3.js@^1.68.0", "@solana/web3.js@^1.98.0":
+"@solana/web3.js@^1.56.2", "@solana/web3.js@^1.69.0", "@solana/web3.js@^1.98.0":
   version "1.98.0"
   resolved "https://registry.npmjs.org/@solana/web3.js/-/web3.js-1.98.0.tgz"
   integrity sha512-nz3Q5OeyGFpFCR+erX2f6JPt3sKhzhYcSycBCSPkWjzSVDh/Rr1FqTVMRe58FKO16/ivTUcuJjeS5MyBvpkbzA==
@@ -434,11 +432,6 @@ cross-spawn@^7.0.0:
     shebang-command "^2.0.0"
     which "^2.0.1"
 
-crypto-hash@^1.3.0:
-  version "1.3.0"
-  resolved "https://registry.npmjs.org/crypto-hash/-/crypto-hash-1.3.0.tgz"
-  integrity sha512-lyAZ0EMyjDkVvz8WOeVnuCPvKVBXcMv1l5SVqO1yC7PzTwrD/pPje/BIRbWhMoPe436U+Y2nD7f5bFx0kt+Sbg==
-
 debug@^4.3.3, debug@^4.3.4:
   version "4.4.0"
   resolved "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz"

+ 1 - 1
crates/bolt-cli/src/templates/component/mod.rs

@@ -25,7 +25,7 @@ pub fn component_type(idl: &Idl, component_id: &str) -> Result<String> {
     let component_account = idl
         .accounts
         .iter()
-        .filter(|a| a.name.to_lowercase() != "Entity")
+        .filter(|a| a.name.to_lowercase() != "entity")
         .next_back();
     let component_account =
         component_account.ok_or_else(|| anyhow::anyhow!("Component account not found in IDL"))?;