@solana/programs 2.0.0-experimental.5e737f9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2023 Solana Labs, Inc
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,79 @@
1
+ [![npm][npm-image]][npm-url]
2
+ [![npm-downloads][npm-downloads-image]][npm-url]
3
+ [![semantic-release][semantic-release-image]][semantic-release-url]
4
+ <br />
5
+ [![code-style-prettier][code-style-prettier-image]][code-style-prettier-url]
6
+
7
+ [code-style-prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square
8
+ [code-style-prettier-url]: https://github.com/prettier/prettier
9
+ [npm-downloads-image]: https://img.shields.io/npm/dm/@solana/programs/experimental.svg?style=flat
10
+ [npm-image]: https://img.shields.io/npm/v/@solana/programs/experimental.svg?style=flat
11
+ [npm-url]: https://www.npmjs.com/package/@solana/programs/v/experimental
12
+ [semantic-release-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
13
+ [semantic-release-url]: https://github.com/semantic-release/semantic-release
14
+
15
+ # @solana/programs
16
+
17
+ This package contains types for defining programs and helpers for resolving program errors. It can be used standalone, but it is also exported as part of the Solana JavaScript SDK [`@solana/web3.js@experimental`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/library).
18
+
19
+ ## Types
20
+
21
+ ### `Program`
22
+
23
+ The `Program` type defines a Solana program.
24
+
25
+ ```ts
26
+ const myProgram: Program<'1234..5678'> = {
27
+ name: 'myProgramName',
28
+ address: '1234..5678' as Address<'1234..5678'>,
29
+ };
30
+ ```
31
+
32
+ ### `ProgramWithErrors`
33
+
34
+ The `ProgramWithErrors` type helps extend the `Program` type by defining a `getErrorFromCode` function that can be used to resolve a custom program error from a transaction error code.
35
+
36
+ ```ts
37
+ enum MyProgramErrorCode {
38
+ UNINITIALIZED_ACCOUNT = 0,
39
+ INVALID_ACCOUNT_OWNER = 1,
40
+ INVALID_ACCOUNT_DATA = 2,
41
+ SOME_OTHER_ERROR = 3,
42
+ }
43
+
44
+ class MyProgramError extends Error {
45
+ // ...
46
+ }
47
+
48
+ const myProgram: Program<'1234..5678'> & ProgramWithErrors<MyProgramErrorCode, MyProgramError> = {
49
+ name: 'myProgramName',
50
+ address: '1234..5678' as Address<'1234..5678'>,
51
+ getErrorFromCode: (code: MyProgramErrorCode, originalError: Error): MyProgramError => {
52
+ // ...
53
+ },
54
+ };
55
+ ```
56
+
57
+ ## Functions
58
+
59
+ ### `resolveTransactionError()`
60
+
61
+ This function takes a raw error caused by a transaction failure and attempts to resolve it into a custom program error.
62
+
63
+ For this to work, the `resolveTransactionError` function also needs the following parameters:
64
+
65
+ - The `transaction` object that failed to execute. This allows us to identify the failing instruction and correctly identify the program that caused the error.
66
+ - An array of all `programs` that can be used to resolve the error. If the program that caused the error is not present in the array, the function won't be able to return a custom program error.
67
+
68
+ Note that, if the error cannot be resolved into a custom program error, the original error is returned as-is.
69
+
70
+ ```ts
71
+ // Store your programs.
72
+ const programs = [createSplSystemProgram(), createSplComputeBudgetProgram(), createSplAddressLookupTableProgram()];
73
+
74
+ try {
75
+ // Send and confirm your transaction.
76
+ } catch (error) {
77
+ throw resolveTransactionError(error, transaction, programs);
78
+ }
79
+ ```
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ // src/resolve-transaction-error.ts
4
+ function resolveTransactionError(error, transaction, programs) {
5
+ const fullLogs = error.message + "\n" + (error.logs ?? []).join("\n");
6
+ const instructionRegex = /Error processing Instruction (\d+)/;
7
+ const instructionIndexString = fullLogs.match(instructionRegex)?.[1] ?? null;
8
+ const instructionIndex = instructionIndexString ? parseInt(instructionIndexString, 10) : null;
9
+ if (instructionIndex === null)
10
+ return error;
11
+ const errorCodeRegex = /Custom program error: (0x[a-f0-9]+)/i;
12
+ const errorCodeString = fullLogs.match(errorCodeRegex)?.[1] ?? null;
13
+ const errorCode = errorCodeString ? parseInt(errorCodeString, 16) : null;
14
+ if (errorCode === null)
15
+ return error;
16
+ const programAddress = transaction.instructions[instructionIndex]?.programAddress ?? null;
17
+ if (!programAddress)
18
+ return error;
19
+ const program = programs.find(
20
+ (program2) => program2.address === programAddress && typeof program2.getErrorFromCode !== "undefined"
21
+ ) ?? null;
22
+ if (!program)
23
+ return error;
24
+ return program.getErrorFromCode(errorCode, error);
25
+ }
26
+
27
+ exports.resolveTransactionError = resolveTransactionError;
28
+ //# sourceMappingURL=out.js.map
29
+ //# sourceMappingURL=index.browser.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/resolve-transaction-error.ts"],"names":["program"],"mappings":";AAkBO,SAAS,wBACZ,OACA,aACA,UACK;AAEL,QAAM,WAAW,MAAM,UAAU,QAAQ,MAAM,QAAQ,CAAC,GAAG,KAAK,IAAI;AAGpE,QAAM,mBAAmB;AACzB,QAAM,yBAAyB,SAAS,MAAM,gBAAgB,IAAI,CAAC,KAAK;AACxE,QAAM,mBAAmB,yBAAyB,SAAS,wBAAwB,EAAE,IAAI;AACzF,MAAI,qBAAqB;AAAM,WAAO;AAGtC,QAAM,iBAAiB;AACvB,QAAM,kBAAkB,SAAS,MAAM,cAAc,IAAI,CAAC,KAAK;AAC/D,QAAM,YAAY,kBAAkB,SAAS,iBAAiB,EAAE,IAAI;AACpE,MAAI,cAAc;AAAM,WAAO;AAG/B,QAAM,iBAAiC,YAAY,aAAa,gBAAgB,GAAG,kBAAkB;AACrG,MAAI,CAAC;AAAgB,WAAO;AAG5B,QAAM,UACF,SAAS;AAAA,IACL,CAACA,aACGA,SAAQ,YAAY,kBAAkB,OAAOA,SAAQ,qBAAqB;AAAA,EAClF,KAAK;AACT,MAAI,CAAC;AAAS,WAAO;AAGrB,SAAO,QAAQ,iBAAiB,WAAW,KAAK;AACpD","sourcesContent":["import type { Address } from '@solana/addresses';\nimport type { Transaction } from '@solana/transactions';\n\nimport { Program, ProgramWithErrors } from './program';\n\n/**\n * Resolves a custom program error from a transaction error\n * with logs using the provided list of programs.\n * The original error is returned if the error cannot be\n * resolved from the given programs.\n *\n * @param error The raw error to resolve containing the program logs.\n * @param transaction The transaction that caused the error.\n * @param programs The list of programs to go through when resolving the transaction error.\n * They should ideally contain all programs the transaction is sending instructions to.\n * @returns The resolved program error, or the original transaction error\n * if the error cannot be resolved using the provided programs.\n */\nexport function resolveTransactionError(\n error: Error & Readonly<{ logs?: readonly string[] }>,\n transaction: Transaction,\n programs: Program[],\n): Error {\n // Compute the full logs from which to parse the instruction index and error code.\n const fullLogs = error.message + '\\n' + (error.logs ?? []).join('\\n');\n\n // Parse the instruction number, or return the original error.\n const instructionRegex = /Error processing Instruction (\\d+)/;\n const instructionIndexString = fullLogs.match(instructionRegex)?.[1] ?? null;\n const instructionIndex = instructionIndexString ? parseInt(instructionIndexString, 10) : null;\n if (instructionIndex === null) return error;\n\n // Parse the error code, or return the original error.\n const errorCodeRegex = /Custom program error: (0x[a-f0-9]+)/i;\n const errorCodeString = fullLogs.match(errorCodeRegex)?.[1] ?? null;\n const errorCode = errorCodeString ? parseInt(errorCodeString, 16) : null;\n if (errorCode === null) return error;\n\n // Get the program address from the instruction in the transaction, or return the original error.\n const programAddress: Address | null = transaction.instructions[instructionIndex]?.programAddress ?? null;\n if (!programAddress) return error;\n\n // Find a matching program with error handling, or return the original error.\n const program: ProgramWithErrors | null =\n programs.find(\n (program): program is Program & ProgramWithErrors =>\n program.address === programAddress && typeof program.getErrorFromCode !== 'undefined',\n ) ?? null;\n if (!program) return error;\n\n // Resolve the error from the identified program.\n return program.getErrorFromCode(errorCode, error);\n}\n"]}
@@ -0,0 +1,27 @@
1
+ // src/resolve-transaction-error.ts
2
+ function resolveTransactionError(error, transaction, programs) {
3
+ const fullLogs = error.message + "\n" + (error.logs ?? []).join("\n");
4
+ const instructionRegex = /Error processing Instruction (\d+)/;
5
+ const instructionIndexString = fullLogs.match(instructionRegex)?.[1] ?? null;
6
+ const instructionIndex = instructionIndexString ? parseInt(instructionIndexString, 10) : null;
7
+ if (instructionIndex === null)
8
+ return error;
9
+ const errorCodeRegex = /Custom program error: (0x[a-f0-9]+)/i;
10
+ const errorCodeString = fullLogs.match(errorCodeRegex)?.[1] ?? null;
11
+ const errorCode = errorCodeString ? parseInt(errorCodeString, 16) : null;
12
+ if (errorCode === null)
13
+ return error;
14
+ const programAddress = transaction.instructions[instructionIndex]?.programAddress ?? null;
15
+ if (!programAddress)
16
+ return error;
17
+ const program = programs.find(
18
+ (program2) => program2.address === programAddress && typeof program2.getErrorFromCode !== "undefined"
19
+ ) ?? null;
20
+ if (!program)
21
+ return error;
22
+ return program.getErrorFromCode(errorCode, error);
23
+ }
24
+
25
+ export { resolveTransactionError };
26
+ //# sourceMappingURL=out.js.map
27
+ //# sourceMappingURL=index.browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/resolve-transaction-error.ts"],"names":["program"],"mappings":";AAkBO,SAAS,wBACZ,OACA,aACA,UACK;AAEL,QAAM,WAAW,MAAM,UAAU,QAAQ,MAAM,QAAQ,CAAC,GAAG,KAAK,IAAI;AAGpE,QAAM,mBAAmB;AACzB,QAAM,yBAAyB,SAAS,MAAM,gBAAgB,IAAI,CAAC,KAAK;AACxE,QAAM,mBAAmB,yBAAyB,SAAS,wBAAwB,EAAE,IAAI;AACzF,MAAI,qBAAqB;AAAM,WAAO;AAGtC,QAAM,iBAAiB;AACvB,QAAM,kBAAkB,SAAS,MAAM,cAAc,IAAI,CAAC,KAAK;AAC/D,QAAM,YAAY,kBAAkB,SAAS,iBAAiB,EAAE,IAAI;AACpE,MAAI,cAAc;AAAM,WAAO;AAG/B,QAAM,iBAAiC,YAAY,aAAa,gBAAgB,GAAG,kBAAkB;AACrG,MAAI,CAAC;AAAgB,WAAO;AAG5B,QAAM,UACF,SAAS;AAAA,IACL,CAACA,aACGA,SAAQ,YAAY,kBAAkB,OAAOA,SAAQ,qBAAqB;AAAA,EAClF,KAAK;AACT,MAAI,CAAC;AAAS,WAAO;AAGrB,SAAO,QAAQ,iBAAiB,WAAW,KAAK;AACpD","sourcesContent":["import type { Address } from '@solana/addresses';\nimport type { Transaction } from '@solana/transactions';\n\nimport { Program, ProgramWithErrors } from './program';\n\n/**\n * Resolves a custom program error from a transaction error\n * with logs using the provided list of programs.\n * The original error is returned if the error cannot be\n * resolved from the given programs.\n *\n * @param error The raw error to resolve containing the program logs.\n * @param transaction The transaction that caused the error.\n * @param programs The list of programs to go through when resolving the transaction error.\n * They should ideally contain all programs the transaction is sending instructions to.\n * @returns The resolved program error, or the original transaction error\n * if the error cannot be resolved using the provided programs.\n */\nexport function resolveTransactionError(\n error: Error & Readonly<{ logs?: readonly string[] }>,\n transaction: Transaction,\n programs: Program[],\n): Error {\n // Compute the full logs from which to parse the instruction index and error code.\n const fullLogs = error.message + '\\n' + (error.logs ?? []).join('\\n');\n\n // Parse the instruction number, or return the original error.\n const instructionRegex = /Error processing Instruction (\\d+)/;\n const instructionIndexString = fullLogs.match(instructionRegex)?.[1] ?? null;\n const instructionIndex = instructionIndexString ? parseInt(instructionIndexString, 10) : null;\n if (instructionIndex === null) return error;\n\n // Parse the error code, or return the original error.\n const errorCodeRegex = /Custom program error: (0x[a-f0-9]+)/i;\n const errorCodeString = fullLogs.match(errorCodeRegex)?.[1] ?? null;\n const errorCode = errorCodeString ? parseInt(errorCodeString, 16) : null;\n if (errorCode === null) return error;\n\n // Get the program address from the instruction in the transaction, or return the original error.\n const programAddress: Address | null = transaction.instructions[instructionIndex]?.programAddress ?? null;\n if (!programAddress) return error;\n\n // Find a matching program with error handling, or return the original error.\n const program: ProgramWithErrors | null =\n programs.find(\n (program): program is Program & ProgramWithErrors =>\n program.address === programAddress && typeof program.getErrorFromCode !== 'undefined',\n ) ?? null;\n if (!program) return error;\n\n // Resolve the error from the identified program.\n return program.getErrorFromCode(errorCode, error);\n}\n"]}
@@ -0,0 +1,54 @@
1
+ this.globalThis = this.globalThis || {};
2
+ this.globalThis.solanaWeb3 = (function (exports) {
3
+ 'use strict';
4
+
5
+ // src/roles.ts
6
+ var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
7
+ AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
8
+ 3] = "WRITABLE_SIGNER";
9
+ AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */
10
+ 2] = "READONLY_SIGNER";
11
+ AccountRole2[AccountRole2["WRITABLE"] = /* 1 */
12
+ 1] = "WRITABLE";
13
+ AccountRole2[AccountRole2["READONLY"] = /* 0 */
14
+ 0] = "READONLY";
15
+ return AccountRole2;
16
+ })(AccountRole || {});
17
+ var IS_SIGNER_BITMASK = 2;
18
+ var IS_WRITABLE_BITMASK = 1;
19
+ function downgradeRoleToNonSigner(role) {
20
+ return role & ~IS_SIGNER_BITMASK;
21
+ }
22
+ function downgradeRoleToReadonly(role) {
23
+ return role & ~IS_WRITABLE_BITMASK;
24
+ }
25
+ function isSignerRole(role) {
26
+ return role >= 2 /* READONLY_SIGNER */;
27
+ }
28
+ function isWritableRole(role) {
29
+ return (role & IS_WRITABLE_BITMASK) !== 0;
30
+ }
31
+ function mergeRoles(roleA, roleB) {
32
+ return roleA | roleB;
33
+ }
34
+ function upgradeRoleToSigner(role) {
35
+ return role | IS_SIGNER_BITMASK;
36
+ }
37
+ function upgradeRoleToWritable(role) {
38
+ return role | IS_WRITABLE_BITMASK;
39
+ }
40
+
41
+ exports.AccountRole = AccountRole;
42
+ exports.downgradeRoleToNonSigner = downgradeRoleToNonSigner;
43
+ exports.downgradeRoleToReadonly = downgradeRoleToReadonly;
44
+ exports.isSignerRole = isSignerRole;
45
+ exports.isWritableRole = isWritableRole;
46
+ exports.mergeRoles = mergeRoles;
47
+ exports.upgradeRoleToSigner = upgradeRoleToSigner;
48
+ exports.upgradeRoleToWritable = upgradeRoleToWritable;
49
+
50
+ return exports;
51
+
52
+ })({});
53
+ //# sourceMappingURL=out.js.map
54
+ //# sourceMappingURL=index.development.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/roles.ts"],"names":["AccountRole"],"mappings":";AAIO,IAAK,cAAL,kBAAKA,iBAAL;AAEH,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AALQ,SAAAA;AAAA,GAAA;AAQZ,IAAM,oBAAoB;AAC1B,IAAM,sBAAsB;AAKrB,SAAS,yBAAyB,MAAgC;AACrE,SAAO,OAAO,CAAC;AACnB;AAKO,SAAS,wBAAwB,MAAgC;AACpE,SAAO,OAAO,CAAC;AACnB;AAEO,SAAS,aAAa,MAAsF;AAC/G,SAAO,QAAQ;AACnB;AAEO,SAAS,eAAe,MAA+E;AAC1G,UAAQ,OAAO,yBAAyB;AAC5C;AAYO,SAAS,WAAW,OAAoB,OAAiC;AAC5E,SAAO,QAAQ;AACnB;AAKO,SAAS,oBAAoB,MAAgC;AAChE,SAAO,OAAO;AAClB;AAKO,SAAS,sBAAsB,MAAgC;AAClE,SAAO,OAAO;AAClB","sourcesContent":["/**\n * Quick primer on bitwise operations: https://stackoverflow.com/a/1436448/802047\n */\n\nexport enum AccountRole {\n // Bitflag guide: is signer ⌄⌄ is writable\n WRITABLE_SIGNER = /* 3 */ 0b11, // prettier-ignore\n READONLY_SIGNER = /* 2 */ 0b10, // prettier-ignore\n WRITABLE = /* 1 */ 0b01, // prettier-ignore\n READONLY = /* 0 */ 0b00, // prettier-ignore\n}\n\nconst IS_SIGNER_BITMASK = 0b10;\nconst IS_WRITABLE_BITMASK = 0b01;\n\nexport function downgradeRoleToNonSigner(role: AccountRole.READONLY_SIGNER): AccountRole.READONLY;\nexport function downgradeRoleToNonSigner(role: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE;\nexport function downgradeRoleToNonSigner(role: AccountRole): AccountRole;\nexport function downgradeRoleToNonSigner(role: AccountRole): AccountRole {\n return role & ~IS_SIGNER_BITMASK;\n}\n\nexport function downgradeRoleToReadonly(role: AccountRole.WRITABLE): AccountRole.READONLY;\nexport function downgradeRoleToReadonly(role: AccountRole.WRITABLE_SIGNER): AccountRole.READONLY_SIGNER;\nexport function downgradeRoleToReadonly(role: AccountRole): AccountRole;\nexport function downgradeRoleToReadonly(role: AccountRole): AccountRole {\n return role & ~IS_WRITABLE_BITMASK;\n}\n\nexport function isSignerRole(role: AccountRole): role is AccountRole.READONLY_SIGNER | AccountRole.WRITABLE_SIGNER {\n return role >= AccountRole.READONLY_SIGNER;\n}\n\nexport function isWritableRole(role: AccountRole): role is AccountRole.WRITABLE | AccountRole.WRITABLE_SIGNER {\n return (role & IS_WRITABLE_BITMASK) !== 0;\n}\n\nexport function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.WRITABLE_SIGNER, roleB: AccountRole): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.READONLY_SIGNER): AccountRole.READONLY_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole): AccountRole.READONLY_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole): AccountRole.WRITABLE; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY, roleB: AccountRole.READONLY): AccountRole.READONLY; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole {\n return roleA | roleB;\n}\n\nexport function upgradeRoleToSigner(role: AccountRole.READONLY): AccountRole.READONLY_SIGNER;\nexport function upgradeRoleToSigner(role: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER;\nexport function upgradeRoleToSigner(role: AccountRole): AccountRole;\nexport function upgradeRoleToSigner(role: AccountRole): AccountRole {\n return role | IS_SIGNER_BITMASK;\n}\n\nexport function upgradeRoleToWritable(role: AccountRole.READONLY): AccountRole.WRITABLE;\nexport function upgradeRoleToWritable(role: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER;\nexport function upgradeRoleToWritable(role: AccountRole): AccountRole;\nexport function upgradeRoleToWritable(role: AccountRole): AccountRole {\n return role | IS_WRITABLE_BITMASK;\n}\n"]}
@@ -0,0 +1,27 @@
1
+ // src/resolve-transaction-error.ts
2
+ function resolveTransactionError(error, transaction, programs) {
3
+ const fullLogs = error.message + "\n" + (error.logs ?? []).join("\n");
4
+ const instructionRegex = /Error processing Instruction (\d+)/;
5
+ const instructionIndexString = fullLogs.match(instructionRegex)?.[1] ?? null;
6
+ const instructionIndex = instructionIndexString ? parseInt(instructionIndexString, 10) : null;
7
+ if (instructionIndex === null)
8
+ return error;
9
+ const errorCodeRegex = /Custom program error: (0x[a-f0-9]+)/i;
10
+ const errorCodeString = fullLogs.match(errorCodeRegex)?.[1] ?? null;
11
+ const errorCode = errorCodeString ? parseInt(errorCodeString, 16) : null;
12
+ if (errorCode === null)
13
+ return error;
14
+ const programAddress = transaction.instructions[instructionIndex]?.programAddress ?? null;
15
+ if (!programAddress)
16
+ return error;
17
+ const program = programs.find(
18
+ (program2) => program2.address === programAddress && typeof program2.getErrorFromCode !== "undefined"
19
+ ) ?? null;
20
+ if (!program)
21
+ return error;
22
+ return program.getErrorFromCode(errorCode, error);
23
+ }
24
+
25
+ export { resolveTransactionError };
26
+ //# sourceMappingURL=out.js.map
27
+ //# sourceMappingURL=index.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/resolve-transaction-error.ts"],"names":["program"],"mappings":";AAkBO,SAAS,wBACZ,OACA,aACA,UACK;AAEL,QAAM,WAAW,MAAM,UAAU,QAAQ,MAAM,QAAQ,CAAC,GAAG,KAAK,IAAI;AAGpE,QAAM,mBAAmB;AACzB,QAAM,yBAAyB,SAAS,MAAM,gBAAgB,IAAI,CAAC,KAAK;AACxE,QAAM,mBAAmB,yBAAyB,SAAS,wBAAwB,EAAE,IAAI;AACzF,MAAI,qBAAqB;AAAM,WAAO;AAGtC,QAAM,iBAAiB;AACvB,QAAM,kBAAkB,SAAS,MAAM,cAAc,IAAI,CAAC,KAAK;AAC/D,QAAM,YAAY,kBAAkB,SAAS,iBAAiB,EAAE,IAAI;AACpE,MAAI,cAAc;AAAM,WAAO;AAG/B,QAAM,iBAAiC,YAAY,aAAa,gBAAgB,GAAG,kBAAkB;AACrG,MAAI,CAAC;AAAgB,WAAO;AAG5B,QAAM,UACF,SAAS;AAAA,IACL,CAACA,aACGA,SAAQ,YAAY,kBAAkB,OAAOA,SAAQ,qBAAqB;AAAA,EAClF,KAAK;AACT,MAAI,CAAC;AAAS,WAAO;AAGrB,SAAO,QAAQ,iBAAiB,WAAW,KAAK;AACpD","sourcesContent":["import type { Address } from '@solana/addresses';\nimport type { Transaction } from '@solana/transactions';\n\nimport { Program, ProgramWithErrors } from './program';\n\n/**\n * Resolves a custom program error from a transaction error\n * with logs using the provided list of programs.\n * The original error is returned if the error cannot be\n * resolved from the given programs.\n *\n * @param error The raw error to resolve containing the program logs.\n * @param transaction The transaction that caused the error.\n * @param programs The list of programs to go through when resolving the transaction error.\n * They should ideally contain all programs the transaction is sending instructions to.\n * @returns The resolved program error, or the original transaction error\n * if the error cannot be resolved using the provided programs.\n */\nexport function resolveTransactionError(\n error: Error & Readonly<{ logs?: readonly string[] }>,\n transaction: Transaction,\n programs: Program[],\n): Error {\n // Compute the full logs from which to parse the instruction index and error code.\n const fullLogs = error.message + '\\n' + (error.logs ?? []).join('\\n');\n\n // Parse the instruction number, or return the original error.\n const instructionRegex = /Error processing Instruction (\\d+)/;\n const instructionIndexString = fullLogs.match(instructionRegex)?.[1] ?? null;\n const instructionIndex = instructionIndexString ? parseInt(instructionIndexString, 10) : null;\n if (instructionIndex === null) return error;\n\n // Parse the error code, or return the original error.\n const errorCodeRegex = /Custom program error: (0x[a-f0-9]+)/i;\n const errorCodeString = fullLogs.match(errorCodeRegex)?.[1] ?? null;\n const errorCode = errorCodeString ? parseInt(errorCodeString, 16) : null;\n if (errorCode === null) return error;\n\n // Get the program address from the instruction in the transaction, or return the original error.\n const programAddress: Address | null = transaction.instructions[instructionIndex]?.programAddress ?? null;\n if (!programAddress) return error;\n\n // Find a matching program with error handling, or return the original error.\n const program: ProgramWithErrors | null =\n programs.find(\n (program): program is Program & ProgramWithErrors =>\n program.address === programAddress && typeof program.getErrorFromCode !== 'undefined',\n ) ?? null;\n if (!program) return error;\n\n // Resolve the error from the identified program.\n return program.getErrorFromCode(errorCode, error);\n}\n"]}
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ // src/resolve-transaction-error.ts
4
+ function resolveTransactionError(error, transaction, programs) {
5
+ const fullLogs = error.message + "\n" + (error.logs ?? []).join("\n");
6
+ const instructionRegex = /Error processing Instruction (\d+)/;
7
+ const instructionIndexString = fullLogs.match(instructionRegex)?.[1] ?? null;
8
+ const instructionIndex = instructionIndexString ? parseInt(instructionIndexString, 10) : null;
9
+ if (instructionIndex === null)
10
+ return error;
11
+ const errorCodeRegex = /Custom program error: (0x[a-f0-9]+)/i;
12
+ const errorCodeString = fullLogs.match(errorCodeRegex)?.[1] ?? null;
13
+ const errorCode = errorCodeString ? parseInt(errorCodeString, 16) : null;
14
+ if (errorCode === null)
15
+ return error;
16
+ const programAddress = transaction.instructions[instructionIndex]?.programAddress ?? null;
17
+ if (!programAddress)
18
+ return error;
19
+ const program = programs.find(
20
+ (program2) => program2.address === programAddress && typeof program2.getErrorFromCode !== "undefined"
21
+ ) ?? null;
22
+ if (!program)
23
+ return error;
24
+ return program.getErrorFromCode(errorCode, error);
25
+ }
26
+
27
+ exports.resolveTransactionError = resolveTransactionError;
28
+ //# sourceMappingURL=out.js.map
29
+ //# sourceMappingURL=index.node.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/resolve-transaction-error.ts"],"names":["program"],"mappings":";AAkBO,SAAS,wBACZ,OACA,aACA,UACK;AAEL,QAAM,WAAW,MAAM,UAAU,QAAQ,MAAM,QAAQ,CAAC,GAAG,KAAK,IAAI;AAGpE,QAAM,mBAAmB;AACzB,QAAM,yBAAyB,SAAS,MAAM,gBAAgB,IAAI,CAAC,KAAK;AACxE,QAAM,mBAAmB,yBAAyB,SAAS,wBAAwB,EAAE,IAAI;AACzF,MAAI,qBAAqB;AAAM,WAAO;AAGtC,QAAM,iBAAiB;AACvB,QAAM,kBAAkB,SAAS,MAAM,cAAc,IAAI,CAAC,KAAK;AAC/D,QAAM,YAAY,kBAAkB,SAAS,iBAAiB,EAAE,IAAI;AACpE,MAAI,cAAc;AAAM,WAAO;AAG/B,QAAM,iBAAiC,YAAY,aAAa,gBAAgB,GAAG,kBAAkB;AACrG,MAAI,CAAC;AAAgB,WAAO;AAG5B,QAAM,UACF,SAAS;AAAA,IACL,CAACA,aACGA,SAAQ,YAAY,kBAAkB,OAAOA,SAAQ,qBAAqB;AAAA,EAClF,KAAK;AACT,MAAI,CAAC;AAAS,WAAO;AAGrB,SAAO,QAAQ,iBAAiB,WAAW,KAAK;AACpD","sourcesContent":["import type { Address } from '@solana/addresses';\nimport type { Transaction } from '@solana/transactions';\n\nimport { Program, ProgramWithErrors } from './program';\n\n/**\n * Resolves a custom program error from a transaction error\n * with logs using the provided list of programs.\n * The original error is returned if the error cannot be\n * resolved from the given programs.\n *\n * @param error The raw error to resolve containing the program logs.\n * @param transaction The transaction that caused the error.\n * @param programs The list of programs to go through when resolving the transaction error.\n * They should ideally contain all programs the transaction is sending instructions to.\n * @returns The resolved program error, or the original transaction error\n * if the error cannot be resolved using the provided programs.\n */\nexport function resolveTransactionError(\n error: Error & Readonly<{ logs?: readonly string[] }>,\n transaction: Transaction,\n programs: Program[],\n): Error {\n // Compute the full logs from which to parse the instruction index and error code.\n const fullLogs = error.message + '\\n' + (error.logs ?? []).join('\\n');\n\n // Parse the instruction number, or return the original error.\n const instructionRegex = /Error processing Instruction (\\d+)/;\n const instructionIndexString = fullLogs.match(instructionRegex)?.[1] ?? null;\n const instructionIndex = instructionIndexString ? parseInt(instructionIndexString, 10) : null;\n if (instructionIndex === null) return error;\n\n // Parse the error code, or return the original error.\n const errorCodeRegex = /Custom program error: (0x[a-f0-9]+)/i;\n const errorCodeString = fullLogs.match(errorCodeRegex)?.[1] ?? null;\n const errorCode = errorCodeString ? parseInt(errorCodeString, 16) : null;\n if (errorCode === null) return error;\n\n // Get the program address from the instruction in the transaction, or return the original error.\n const programAddress: Address | null = transaction.instructions[instructionIndex]?.programAddress ?? null;\n if (!programAddress) return error;\n\n // Find a matching program with error handling, or return the original error.\n const program: ProgramWithErrors | null =\n programs.find(\n (program): program is Program & ProgramWithErrors =>\n program.address === programAddress && typeof program.getErrorFromCode !== 'undefined',\n ) ?? null;\n if (!program) return error;\n\n // Resolve the error from the identified program.\n return program.getErrorFromCode(errorCode, error);\n}\n"]}
@@ -0,0 +1,27 @@
1
+ // src/resolve-transaction-error.ts
2
+ function resolveTransactionError(error, transaction, programs) {
3
+ const fullLogs = error.message + "\n" + (error.logs ?? []).join("\n");
4
+ const instructionRegex = /Error processing Instruction (\d+)/;
5
+ const instructionIndexString = fullLogs.match(instructionRegex)?.[1] ?? null;
6
+ const instructionIndex = instructionIndexString ? parseInt(instructionIndexString, 10) : null;
7
+ if (instructionIndex === null)
8
+ return error;
9
+ const errorCodeRegex = /Custom program error: (0x[a-f0-9]+)/i;
10
+ const errorCodeString = fullLogs.match(errorCodeRegex)?.[1] ?? null;
11
+ const errorCode = errorCodeString ? parseInt(errorCodeString, 16) : null;
12
+ if (errorCode === null)
13
+ return error;
14
+ const programAddress = transaction.instructions[instructionIndex]?.programAddress ?? null;
15
+ if (!programAddress)
16
+ return error;
17
+ const program = programs.find(
18
+ (program2) => program2.address === programAddress && typeof program2.getErrorFromCode !== "undefined"
19
+ ) ?? null;
20
+ if (!program)
21
+ return error;
22
+ return program.getErrorFromCode(errorCode, error);
23
+ }
24
+
25
+ export { resolveTransactionError };
26
+ //# sourceMappingURL=out.js.map
27
+ //# sourceMappingURL=index.node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/resolve-transaction-error.ts"],"names":["program"],"mappings":";AAkBO,SAAS,wBACZ,OACA,aACA,UACK;AAEL,QAAM,WAAW,MAAM,UAAU,QAAQ,MAAM,QAAQ,CAAC,GAAG,KAAK,IAAI;AAGpE,QAAM,mBAAmB;AACzB,QAAM,yBAAyB,SAAS,MAAM,gBAAgB,IAAI,CAAC,KAAK;AACxE,QAAM,mBAAmB,yBAAyB,SAAS,wBAAwB,EAAE,IAAI;AACzF,MAAI,qBAAqB;AAAM,WAAO;AAGtC,QAAM,iBAAiB;AACvB,QAAM,kBAAkB,SAAS,MAAM,cAAc,IAAI,CAAC,KAAK;AAC/D,QAAM,YAAY,kBAAkB,SAAS,iBAAiB,EAAE,IAAI;AACpE,MAAI,cAAc;AAAM,WAAO;AAG/B,QAAM,iBAAiC,YAAY,aAAa,gBAAgB,GAAG,kBAAkB;AACrG,MAAI,CAAC;AAAgB,WAAO;AAG5B,QAAM,UACF,SAAS;AAAA,IACL,CAACA,aACGA,SAAQ,YAAY,kBAAkB,OAAOA,SAAQ,qBAAqB;AAAA,EAClF,KAAK;AACT,MAAI,CAAC;AAAS,WAAO;AAGrB,SAAO,QAAQ,iBAAiB,WAAW,KAAK;AACpD","sourcesContent":["import type { Address } from '@solana/addresses';\nimport type { Transaction } from '@solana/transactions';\n\nimport { Program, ProgramWithErrors } from './program';\n\n/**\n * Resolves a custom program error from a transaction error\n * with logs using the provided list of programs.\n * The original error is returned if the error cannot be\n * resolved from the given programs.\n *\n * @param error The raw error to resolve containing the program logs.\n * @param transaction The transaction that caused the error.\n * @param programs The list of programs to go through when resolving the transaction error.\n * They should ideally contain all programs the transaction is sending instructions to.\n * @returns The resolved program error, or the original transaction error\n * if the error cannot be resolved using the provided programs.\n */\nexport function resolveTransactionError(\n error: Error & Readonly<{ logs?: readonly string[] }>,\n transaction: Transaction,\n programs: Program[],\n): Error {\n // Compute the full logs from which to parse the instruction index and error code.\n const fullLogs = error.message + '\\n' + (error.logs ?? []).join('\\n');\n\n // Parse the instruction number, or return the original error.\n const instructionRegex = /Error processing Instruction (\\d+)/;\n const instructionIndexString = fullLogs.match(instructionRegex)?.[1] ?? null;\n const instructionIndex = instructionIndexString ? parseInt(instructionIndexString, 10) : null;\n if (instructionIndex === null) return error;\n\n // Parse the error code, or return the original error.\n const errorCodeRegex = /Custom program error: (0x[a-f0-9]+)/i;\n const errorCodeString = fullLogs.match(errorCodeRegex)?.[1] ?? null;\n const errorCode = errorCodeString ? parseInt(errorCodeString, 16) : null;\n if (errorCode === null) return error;\n\n // Get the program address from the instruction in the transaction, or return the original error.\n const programAddress: Address | null = transaction.instructions[instructionIndex]?.programAddress ?? null;\n if (!programAddress) return error;\n\n // Find a matching program with error handling, or return the original error.\n const program: ProgramWithErrors | null =\n programs.find(\n (program): program is Program & ProgramWithErrors =>\n program.address === programAddress && typeof program.getErrorFromCode !== 'undefined',\n ) ?? null;\n if (!program) return error;\n\n // Resolve the error from the identified program.\n return program.getErrorFromCode(errorCode, error);\n}\n"]}
@@ -0,0 +1,18 @@
1
+ this.globalThis = this.globalThis || {};
2
+ this.globalThis.solanaWeb3 = (function (exports) {
3
+ 'use strict';
4
+
5
+ var n=(e=>(e[e.WRITABLE_SIGNER=3]="WRITABLE_SIGNER",e[e.READONLY_SIGNER=2]="READONLY_SIGNER",e[e.WRITABLE=1]="WRITABLE",e[e.READONLY=0]="READONLY",e))(n||{});function l(o){return o&-3}function A(o){return o&-2}function r(o){return o>=2}function u(o){return (o&1)!==0}function E(o,R){return o|R}function I(o){return o|2}function N(o){return o|1}
6
+
7
+ exports.AccountRole = n;
8
+ exports.downgradeRoleToNonSigner = l;
9
+ exports.downgradeRoleToReadonly = A;
10
+ exports.isSignerRole = r;
11
+ exports.isWritableRole = u;
12
+ exports.mergeRoles = E;
13
+ exports.upgradeRoleToSigner = I;
14
+ exports.upgradeRoleToWritable = N;
15
+
16
+ return exports;
17
+
18
+ })({});
@@ -0,0 +1,31 @@
1
+ import { Address } from '@solana/addresses';
2
+ import { AccountRole } from './roles.js.js.js';
3
+ export interface IAccountMeta<TAddress extends string = string> {
4
+ readonly address: Address<TAddress>;
5
+ readonly role: AccountRole;
6
+ }
7
+ export type ReadonlyAccount<TAddress extends string = string> = IAccountMeta<TAddress> & {
8
+ readonly role: AccountRole.READONLY;
9
+ };
10
+ export type WritableAccount<TAddress extends string = string> = IAccountMeta<TAddress> & {
11
+ role: AccountRole.WRITABLE;
12
+ };
13
+ export type ReadonlySignerAccount<TAddress extends string = string> = IAccountMeta<TAddress> & {
14
+ role: AccountRole.READONLY_SIGNER;
15
+ };
16
+ export type WritableSignerAccount<TAddress extends string = string> = IAccountMeta<TAddress> & {
17
+ role: AccountRole.WRITABLE_SIGNER;
18
+ };
19
+ export interface IAccountLookupMeta<TAddress extends string = string, TLookupTableAddress extends string = string> {
20
+ readonly address: Address<TAddress>;
21
+ readonly addressIndex: number;
22
+ readonly lookupTableAddress: Address<TLookupTableAddress>;
23
+ readonly role: AccountRole.READONLY | AccountRole.WRITABLE;
24
+ }
25
+ export type ReadonlyAccountLookup<TAddress extends string = string, TLookupTableAddress extends string = string> = IAccountLookupMeta<TAddress, TLookupTableAddress> & {
26
+ readonly role: AccountRole.READONLY;
27
+ };
28
+ export type WritableAccountLookup<TAddress extends string = string, TLookupTableAddress extends string = string> = IAccountLookupMeta<TAddress, TLookupTableAddress> & {
29
+ readonly role: AccountRole.WRITABLE;
30
+ };
31
+ //# sourceMappingURL=accounts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../../src/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,MAAM,WAAW,YAAY,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM;IAC1D,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;CAC9B;AAED,MAAM,MAAM,eAAe,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG;IACrF,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,QAAQ,CAAC;CACvC,CAAC;AACF,MAAM,MAAM,eAAe,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG;IAAE,IAAI,EAAE,WAAW,CAAC,QAAQ,CAAA;CAAE,CAAC;AACxH,MAAM,MAAM,qBAAqB,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG;IAC3F,IAAI,EAAE,WAAW,CAAC,eAAe,CAAC;CACrC,CAAC;AACF,MAAM,MAAM,qBAAqB,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG;IAC3F,IAAI,EAAE,WAAW,CAAC,eAAe,CAAC;CACrC,CAAC;AAEF,MAAM,WAAW,kBAAkB,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,EAAE,mBAAmB,SAAS,MAAM,GAAG,MAAM;IAC7G,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC1D,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC;CAC9D;AAED,MAAM,MAAM,qBAAqB,CAC7B,QAAQ,SAAS,MAAM,GAAG,MAAM,EAChC,mBAAmB,SAAS,MAAM,GAAG,MAAM,IAC3C,kBAAkB,CAAC,QAAQ,EAAE,mBAAmB,CAAC,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,QAAQ,CAAA;CAAE,CAAC;AAChG,MAAM,MAAM,qBAAqB,CAC7B,QAAQ,SAAS,MAAM,GAAG,MAAM,EAChC,mBAAmB,SAAS,MAAM,GAAG,MAAM,IAC3C,kBAAkB,CAAC,QAAQ,EAAE,mBAAmB,CAAC,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,QAAQ,CAAA;CAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './program.js';
2
+ export * from './resolve-transaction-error.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,6BAA6B,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { Address } from '@solana/addresses';
2
+ import { IAccountLookupMeta, IAccountMeta } from './accounts.js.js.js';
3
+ export interface IInstruction<TProgramAddress extends string = string, TAccounts extends readonly (IAccountMeta | IAccountLookupMeta)[] = readonly (IAccountMeta | IAccountLookupMeta)[]> {
4
+ readonly accounts?: TAccounts;
5
+ readonly data?: Uint8Array;
6
+ readonly programAddress: Address<TProgramAddress>;
7
+ }
8
+ export interface IInstructionWithAccounts<TAccounts extends readonly (IAccountMeta | IAccountLookupMeta)[]> extends IInstruction {
9
+ readonly accounts: TAccounts;
10
+ }
11
+ export interface IInstructionWithData<TData extends Uint8Array> extends IInstruction {
12
+ readonly data: TData;
13
+ }
14
+ //# sourceMappingURL=instruction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instruction.d.ts","sourceRoot":"","sources":["../../src/instruction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE9D,MAAM,WAAW,YAAY,CACzB,eAAe,SAAS,MAAM,GAAG,MAAM,EACvC,SAAS,SAAS,SAAS,CAAC,YAAY,GAAG,kBAAkB,CAAC,EAAE,GAAG,SAAS,CAAC,YAAY,GAAG,kBAAkB,CAAC,EAAE;IAEjH,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;CACrD;AAED,MAAM,WAAW,wBAAwB,CAAC,SAAS,SAAS,SAAS,CAAC,YAAY,GAAG,kBAAkB,CAAC,EAAE,CACtG,SAAQ,YAAY;IACpB,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;CAChC;AAED,MAAM,WAAW,oBAAoB,CAAC,KAAK,SAAS,UAAU,CAAE,SAAQ,YAAY;IAChF,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;CACxB"}
@@ -0,0 +1,31 @@
1
+ import type { Address } from '@solana/addresses';
2
+ /**
3
+ * Defines a Solana program.
4
+ */
5
+ export type Program<TAddress extends string = string> = {
6
+ /**
7
+ * A unique name for the Program.
8
+ *
9
+ * To avoid conflict with other organizations, it is recommended
10
+ * to prefix the program name with a namespace that is unique to
11
+ * your organization. For instance, programs belonging to the
12
+ * Solana Program Library are prefixed with `spl` like so:
13
+ * `splMemo` or `splToken`.
14
+ */
15
+ name: string;
16
+ /**
17
+ * The base58 address of the program.
18
+ */
19
+ address: Address<TAddress>;
20
+ /**
21
+ * Retrieves a program-specific error from a given error code.
22
+ */
23
+ getErrorFromCode?: (code: number, cause?: Error) => Error;
24
+ };
25
+ /**
26
+ * Defines a Solana program that can return custom errors from a provided error code.
27
+ */
28
+ export type ProgramWithErrors<TErrorCode extends number = number, TError extends Error = Error> = {
29
+ getErrorFromCode: (code: TErrorCode, cause?: Error) => TError;
30
+ };
31
+ //# sourceMappingURL=program.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../src/program.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;GAEG;AACH,MAAM,MAAM,OAAO,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,IAAI;IACpD;;;;;;;;OAQG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE3B;;OAEG;IACH,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,KAAK,KAAK,CAAC;CAC7D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,UAAU,SAAS,MAAM,GAAG,MAAM,EAAE,MAAM,SAAS,KAAK,GAAG,KAAK,IAAI;IAC9F,gBAAgB,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE,KAAK,KAAK,MAAM,CAAC;CACjE,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { Transaction } from '@solana/transactions';
2
+ import { Program } from './program.js';
3
+ /**
4
+ * Resolves a custom program error from a transaction error
5
+ * with logs using the provided list of programs.
6
+ * The original error is returned if the error cannot be
7
+ * resolved from the given programs.
8
+ *
9
+ * @param error The raw error to resolve containing the program logs.
10
+ * @param transaction The transaction that caused the error.
11
+ * @param programs The list of programs to go through when resolving the transaction error.
12
+ * They should ideally contain all programs the transaction is sending instructions to.
13
+ * @returns The resolved program error, or the original transaction error
14
+ * if the error cannot be resolved using the provided programs.
15
+ */
16
+ export declare function resolveTransactionError(error: Error & Readonly<{
17
+ logs?: readonly string[];
18
+ }>, transaction: Transaction, programs: Program[]): Error;
19
+ //# sourceMappingURL=resolve-transaction-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-transaction-error.d.ts","sourceRoot":"","sources":["../../src/resolve-transaction-error.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,EAAE,OAAO,EAAqB,MAAM,WAAW,CAAC;AAEvD;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CACnC,KAAK,EAAE,KAAK,GAAG,QAAQ,CAAC;IAAE,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC,EACrD,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,OAAO,EAAE,GACpB,KAAK,CA8BP"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Quick primer on bitwise operations: https://stackoverflow.com/a/1436448/802047
3
+ */
4
+ export declare enum AccountRole {
5
+ WRITABLE_SIGNER = 3,
6
+ READONLY_SIGNER = 2,
7
+ WRITABLE = 1,
8
+ READONLY = 0
9
+ }
10
+ export declare function downgradeRoleToNonSigner(role: AccountRole.READONLY_SIGNER): AccountRole.READONLY;
11
+ export declare function downgradeRoleToNonSigner(role: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE;
12
+ export declare function downgradeRoleToNonSigner(role: AccountRole): AccountRole;
13
+ export declare function downgradeRoleToReadonly(role: AccountRole.WRITABLE): AccountRole.READONLY;
14
+ export declare function downgradeRoleToReadonly(role: AccountRole.WRITABLE_SIGNER): AccountRole.READONLY_SIGNER;
15
+ export declare function downgradeRoleToReadonly(role: AccountRole): AccountRole;
16
+ export declare function isSignerRole(role: AccountRole): role is AccountRole.READONLY_SIGNER | AccountRole.WRITABLE_SIGNER;
17
+ export declare function isWritableRole(role: AccountRole): role is AccountRole.WRITABLE | AccountRole.WRITABLE_SIGNER;
18
+ export declare function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER;
19
+ export declare function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER;
20
+ export declare function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE_SIGNER;
21
+ export declare function mergeRoles(roleA: AccountRole.WRITABLE_SIGNER, roleB: AccountRole): AccountRole.WRITABLE_SIGNER;
22
+ export declare function mergeRoles(roleA: AccountRole, roleB: AccountRole.READONLY_SIGNER): AccountRole.READONLY_SIGNER;
23
+ export declare function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole): AccountRole.READONLY_SIGNER;
24
+ export declare function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE;
25
+ export declare function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole): AccountRole.WRITABLE;
26
+ export declare function mergeRoles(roleA: AccountRole.READONLY, roleB: AccountRole.READONLY): AccountRole.READONLY;
27
+ export declare function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole;
28
+ export declare function upgradeRoleToSigner(role: AccountRole.READONLY): AccountRole.READONLY_SIGNER;
29
+ export declare function upgradeRoleToSigner(role: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER;
30
+ export declare function upgradeRoleToSigner(role: AccountRole): AccountRole;
31
+ export declare function upgradeRoleToWritable(role: AccountRole.READONLY): AccountRole.WRITABLE;
32
+ export declare function upgradeRoleToWritable(role: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER;
33
+ export declare function upgradeRoleToWritable(role: AccountRole): AccountRole;
34
+ //# sourceMappingURL=roles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roles.d.ts","sourceRoot":"","sources":["../../src/roles.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,oBAAY,WAAW;IAEnB,eAAe,IAAe;IAC9B,eAAe,IAAe;IAC9B,QAAQ,IAAsB;IAC9B,QAAQ,IAAsB;CACjC;AAKD,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,WAAW,CAAC,eAAe,GAAG,WAAW,CAAC,QAAQ,CAAC;AAClG,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,WAAW,CAAC,eAAe,GAAG,WAAW,CAAC,QAAQ,CAAC;AAClG,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,WAAW,GAAG,WAAW,CAAC;AAKzE,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC;AAC1F,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,WAAW,CAAC,eAAe,GAAG,WAAW,CAAC,eAAe,CAAC;AACxG,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,WAAW,GAAG,WAAW,CAAC;AAKxE,wBAAgB,YAAY,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,IAAI,WAAW,CAAC,eAAe,GAAG,WAAW,CAAC,eAAe,CAEjH;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,IAAI,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,eAAe,CAE5G;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC,QAAQ,EAAE,KAAK,EAAE,WAAW,CAAC,eAAe,GAAG,WAAW,CAAC,eAAe,CAAC;AACzH,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC,eAAe,EAAE,KAAK,EAAE,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,eAAe,CAAC;AACzH,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,CAAC,eAAe,GAAG,WAAW,CAAC,eAAe,CAAC;AAChH,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC,eAAe,EAAE,KAAK,EAAE,WAAW,GAAG,WAAW,CAAC,eAAe,CAAC;AAChH,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,CAAC,eAAe,GAAG,WAAW,CAAC,eAAe,CAAC;AAChH,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC,eAAe,EAAE,KAAK,EAAE,WAAW,GAAG,WAAW,CAAC,eAAe,CAAC;AAChH,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC;AAClG,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC,QAAQ,EAAE,KAAK,EAAE,WAAW,GAAG,WAAW,CAAC,QAAQ,CAAC;AAClG,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC,QAAQ,EAAE,KAAK,EAAE,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC;AAC3G,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,GAAG,WAAW,CAAC;AAKhF,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,eAAe,CAAC;AAC7F,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,eAAe,CAAC;AAC7F,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,WAAW,GAAG,WAAW,CAAC;AAKpE,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC;AACxF,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,WAAW,CAAC,eAAe,GAAG,WAAW,CAAC,eAAe,CAAC;AACtG,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,WAAW,GAAG,WAAW,CAAC"}
package/package.json ADDED
@@ -0,0 +1,94 @@
1
+ {
2
+ "name": "@solana/programs",
3
+ "version": "2.0.0-experimental.5e737f9",
4
+ "description": "Helpers for defining programs and resolving program errors",
5
+ "exports": {
6
+ "browser": {
7
+ "import": "./dist/index.browser.js",
8
+ "require": "./dist/index.browser.cjs"
9
+ },
10
+ "node": {
11
+ "import": "./dist/index.node.js",
12
+ "require": "./dist/index.node.cjs"
13
+ },
14
+ "react-native": "./dist/index.native.js",
15
+ "types": "./dist/types/index.d.ts"
16
+ },
17
+ "browser": {
18
+ "./dist/index.node.cjs": "./dist/index.browser.cjs",
19
+ "./dist/index.node.js": "./dist/index.browser.js"
20
+ },
21
+ "main": "./dist/index.node.cjs",
22
+ "module": "./dist/index.node.js",
23
+ "react-native": "./dist/index.native.js",
24
+ "types": "./dist/types/index.d.ts",
25
+ "type": "module",
26
+ "files": [
27
+ "./dist/"
28
+ ],
29
+ "sideEffects": false,
30
+ "keywords": [
31
+ "blockchain",
32
+ "solana",
33
+ "web3"
34
+ ],
35
+ "author": "Solana Labs Maintainers <maintainers@solanalabs.com>",
36
+ "license": "MIT",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "https://github.com/solana-labs/solana-web3.js"
40
+ },
41
+ "bugs": {
42
+ "url": "http://github.com/solana-labs/solana-web3.js/issues"
43
+ },
44
+ "browserslist": [
45
+ "supports bigint and not dead",
46
+ "maintained node versions"
47
+ ],
48
+ "devDependencies": {
49
+ "@solana/eslint-config-solana": "^1.0.2",
50
+ "@swc/jest": "^0.2.29",
51
+ "@types/jest": "^29.5.11",
52
+ "@typescript-eslint/eslint-plugin": "^6.13.2",
53
+ "@typescript-eslint/parser": "^6.3.0",
54
+ "agadoo": "^3.0.0",
55
+ "eslint": "^8.45.0",
56
+ "eslint-plugin-sort-keys-fix": "^1.1.2",
57
+ "jest": "^29.7.0",
58
+ "jest-runner-eslint": "^2.1.2",
59
+ "jest-runner-prettier": "^1.0.0",
60
+ "prettier": "^3.1",
61
+ "tsup": "^8.0.1",
62
+ "typescript": "^5.2.2",
63
+ "version-from-git": "^1.1.1",
64
+ "@solana/addresses": "2.0.0-development",
65
+ "@solana/transactions": "2.0.0-development",
66
+ "test-config": "0.0.0",
67
+ "tsconfig": "0.0.0",
68
+ "@solana/functional": "2.0.0-development",
69
+ "build-scripts": "0.0.0"
70
+ },
71
+ "bundlewatch": {
72
+ "defaultCompression": "gzip",
73
+ "files": [
74
+ {
75
+ "path": "./dist/index*.js"
76
+ }
77
+ ]
78
+ },
79
+ "scripts": {
80
+ "compile:js": "tsup --config build-scripts/tsup.config.package.ts",
81
+ "compile:typedefs": "tsc -p ./tsconfig.declarations.json && node node_modules/build-scripts/add-js-extension-to-types.mjs",
82
+ "dev": "jest -c node_modules/test-config/jest-dev.config.ts --rootDir . --watch",
83
+ "publish-packages": "pnpm publish --tag experimental --access public --no-git-checks",
84
+ "style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/* package.json",
85
+ "test:lint": "jest -c node_modules/test-config/jest-lint.config.ts --rootDir . --silent",
86
+ "test:prettier": "jest -c node_modules/test-config/jest-prettier.config.ts --rootDir . --silent",
87
+ "test:treeshakability:browser": "agadoo dist/index.browser.js",
88
+ "test:treeshakability:native": "agadoo dist/index.native.js",
89
+ "test:treeshakability:node": "agadoo dist/index.node.js",
90
+ "test:typecheck": "tsc --noEmit",
91
+ "test:unit:browser": "jest -c node_modules/test-config/jest-unit.config.browser.ts --rootDir . --silent",
92
+ "test:unit:node": "jest -c node_modules/test-config/jest-unit.config.node.ts --rootDir . --silent"
93
+ }
94
+ }