@oobe-protocol-labs/synapse-sap-sdk 0.1.0
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 +21 -0
- package/README.md +882 -0
- package/dist/cjs/constants/index.js +43 -0
- package/dist/cjs/constants/index.js.map +1 -0
- package/dist/cjs/constants/limits.js +161 -0
- package/dist/cjs/constants/limits.js.map +1 -0
- package/dist/cjs/constants/programs.js +78 -0
- package/dist/cjs/constants/programs.js.map +1 -0
- package/dist/cjs/constants/seeds.js +57 -0
- package/dist/cjs/constants/seeds.js.map +1 -0
- package/dist/cjs/core/client.js +391 -0
- package/dist/cjs/core/client.js.map +1 -0
- package/dist/cjs/core/connection.js +319 -0
- package/dist/cjs/core/connection.js.map +1 -0
- package/dist/cjs/core/index.js +24 -0
- package/dist/cjs/core/index.js.map +1 -0
- package/dist/cjs/errors/index.js +334 -0
- package/dist/cjs/errors/index.js.map +1 -0
- package/dist/cjs/events/index.js +136 -0
- package/dist/cjs/events/index.js.map +1 -0
- package/dist/cjs/idl/index.js +63 -0
- package/dist/cjs/idl/index.js.map +1 -0
- package/dist/cjs/idl/synapse_agent_sap.json +9710 -0
- package/dist/cjs/index.js +147 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/modules/agent.js +272 -0
- package/dist/cjs/modules/agent.js.map +1 -0
- package/dist/cjs/modules/attestation.js +147 -0
- package/dist/cjs/modules/attestation.js.map +1 -0
- package/dist/cjs/modules/base.js +128 -0
- package/dist/cjs/modules/base.js.map +1 -0
- package/dist/cjs/modules/escrow.js +246 -0
- package/dist/cjs/modules/escrow.js.map +1 -0
- package/dist/cjs/modules/feedback.js +166 -0
- package/dist/cjs/modules/feedback.js.map +1 -0
- package/dist/cjs/modules/index.js +35 -0
- package/dist/cjs/modules/index.js.map +1 -0
- package/dist/cjs/modules/indexing.js +375 -0
- package/dist/cjs/modules/indexing.js.map +1 -0
- package/dist/cjs/modules/ledger.js +234 -0
- package/dist/cjs/modules/ledger.js.map +1 -0
- package/dist/cjs/modules/tools.js +319 -0
- package/dist/cjs/modules/tools.js.map +1 -0
- package/dist/cjs/modules/vault.js +410 -0
- package/dist/cjs/modules/vault.js.map +1 -0
- package/dist/cjs/pda/index.js +377 -0
- package/dist/cjs/pda/index.js.map +1 -0
- package/dist/cjs/plugin/index.js +934 -0
- package/dist/cjs/plugin/index.js.map +1 -0
- package/dist/cjs/plugin/protocols.js +282 -0
- package/dist/cjs/plugin/protocols.js.map +1 -0
- package/dist/cjs/plugin/schemas.js +831 -0
- package/dist/cjs/plugin/schemas.js.map +1 -0
- package/dist/cjs/postgres/adapter.js +715 -0
- package/dist/cjs/postgres/adapter.js.map +1 -0
- package/dist/cjs/postgres/index.js +50 -0
- package/dist/cjs/postgres/index.js.map +1 -0
- package/dist/cjs/postgres/serializers.js +381 -0
- package/dist/cjs/postgres/serializers.js.map +1 -0
- package/dist/cjs/postgres/sync.js +221 -0
- package/dist/cjs/postgres/sync.js.map +1 -0
- package/dist/cjs/postgres/types.js +44 -0
- package/dist/cjs/postgres/types.js.map +1 -0
- package/dist/cjs/registries/builder.js +414 -0
- package/dist/cjs/registries/builder.js.map +1 -0
- package/dist/cjs/registries/discovery.js +362 -0
- package/dist/cjs/registries/discovery.js.map +1 -0
- package/dist/cjs/registries/index.js +51 -0
- package/dist/cjs/registries/index.js.map +1 -0
- package/dist/cjs/registries/session.js +433 -0
- package/dist/cjs/registries/session.js.map +1 -0
- package/dist/cjs/registries/x402.js +577 -0
- package/dist/cjs/registries/x402.js.map +1 -0
- package/dist/cjs/types/accounts.js +13 -0
- package/dist/cjs/types/accounts.js.map +1 -0
- package/dist/cjs/types/common.js +13 -0
- package/dist/cjs/types/common.js.map +1 -0
- package/dist/cjs/types/enums.js +174 -0
- package/dist/cjs/types/enums.js.map +1 -0
- package/dist/cjs/types/index.js +36 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/cjs/types/instructions.js +92 -0
- package/dist/cjs/types/instructions.js.map +1 -0
- package/dist/cjs/utils/hash.js +58 -0
- package/dist/cjs/utils/hash.js.map +1 -0
- package/dist/cjs/utils/index.js +27 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/serialization.js +105 -0
- package/dist/cjs/utils/serialization.js.map +1 -0
- package/dist/cjs/utils/validation.js +36 -0
- package/dist/cjs/utils/validation.js.map +1 -0
- package/dist/esm/constants/index.js +29 -0
- package/dist/esm/constants/index.js.map +1 -0
- package/dist/esm/constants/limits.js +158 -0
- package/dist/esm/constants/limits.js.map +1 -0
- package/dist/esm/constants/programs.js +75 -0
- package/dist/esm/constants/programs.js.map +1 -0
- package/dist/esm/constants/seeds.js +54 -0
- package/dist/esm/constants/seeds.js.map +1 -0
- package/dist/esm/core/client.js +384 -0
- package/dist/esm/core/client.js.map +1 -0
- package/dist/esm/core/connection.js +315 -0
- package/dist/esm/core/connection.js.map +1 -0
- package/dist/esm/core/index.js +19 -0
- package/dist/esm/core/index.js.map +1 -0
- package/dist/esm/errors/index.js +325 -0
- package/dist/esm/errors/index.js.map +1 -0
- package/dist/esm/events/index.js +132 -0
- package/dist/esm/events/index.js.map +1 -0
- package/dist/esm/idl/index.js +57 -0
- package/dist/esm/idl/index.js.map +1 -0
- package/dist/esm/idl/synapse_agent_sap.json +9710 -0
- package/dist/esm/index.js +70 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/modules/agent.js +268 -0
- package/dist/esm/modules/agent.js.map +1 -0
- package/dist/esm/modules/attestation.js +143 -0
- package/dist/esm/modules/attestation.js.map +1 -0
- package/dist/esm/modules/base.js +124 -0
- package/dist/esm/modules/base.js.map +1 -0
- package/dist/esm/modules/escrow.js +242 -0
- package/dist/esm/modules/escrow.js.map +1 -0
- package/dist/esm/modules/feedback.js +162 -0
- package/dist/esm/modules/feedback.js.map +1 -0
- package/dist/esm/modules/index.js +23 -0
- package/dist/esm/modules/index.js.map +1 -0
- package/dist/esm/modules/indexing.js +371 -0
- package/dist/esm/modules/indexing.js.map +1 -0
- package/dist/esm/modules/ledger.js +230 -0
- package/dist/esm/modules/ledger.js.map +1 -0
- package/dist/esm/modules/tools.js +315 -0
- package/dist/esm/modules/tools.js.map +1 -0
- package/dist/esm/modules/vault.js +406 -0
- package/dist/esm/modules/vault.js.map +1 -0
- package/dist/esm/pda/index.js +357 -0
- package/dist/esm/pda/index.js.map +1 -0
- package/dist/esm/plugin/index.js +927 -0
- package/dist/esm/plugin/index.js.map +1 -0
- package/dist/esm/plugin/protocols.js +279 -0
- package/dist/esm/plugin/protocols.js.map +1 -0
- package/dist/esm/plugin/schemas.js +828 -0
- package/dist/esm/plugin/schemas.js.map +1 -0
- package/dist/esm/postgres/adapter.js +678 -0
- package/dist/esm/postgres/adapter.js.map +1 -0
- package/dist/esm/postgres/index.js +27 -0
- package/dist/esm/postgres/index.js.map +1 -0
- package/dist/esm/postgres/serializers.js +362 -0
- package/dist/esm/postgres/serializers.js.map +1 -0
- package/dist/esm/postgres/sync.js +217 -0
- package/dist/esm/postgres/sync.js.map +1 -0
- package/dist/esm/postgres/types.js +41 -0
- package/dist/esm/postgres/types.js.map +1 -0
- package/dist/esm/registries/builder.js +410 -0
- package/dist/esm/registries/builder.js.map +1 -0
- package/dist/esm/registries/discovery.js +358 -0
- package/dist/esm/registries/discovery.js.map +1 -0
- package/dist/esm/registries/index.js +44 -0
- package/dist/esm/registries/index.js.map +1 -0
- package/dist/esm/registries/session.js +429 -0
- package/dist/esm/registries/session.js.map +1 -0
- package/dist/esm/registries/x402.js +573 -0
- package/dist/esm/registries/x402.js.map +1 -0
- package/dist/esm/types/accounts.js +12 -0
- package/dist/esm/types/accounts.js.map +1 -0
- package/dist/esm/types/common.js +12 -0
- package/dist/esm/types/common.js.map +1 -0
- package/dist/esm/types/enums.js +171 -0
- package/dist/esm/types/enums.js.map +1 -0
- package/dist/esm/types/index.js +25 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/types/instructions.js +89 -0
- package/dist/esm/types/instructions.js.map +1 -0
- package/dist/esm/utils/hash.js +53 -0
- package/dist/esm/utils/hash.js.map +1 -0
- package/dist/esm/utils/index.js +19 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/serialization.js +98 -0
- package/dist/esm/utils/serialization.js.map +1 -0
- package/dist/esm/utils/validation.js +33 -0
- package/dist/esm/utils/validation.js.map +1 -0
- package/dist/types/constants/index.d.ts +27 -0
- package/dist/types/constants/index.d.ts.map +1 -0
- package/dist/types/constants/limits.d.ts +149 -0
- package/dist/types/constants/limits.d.ts.map +1 -0
- package/dist/types/constants/programs.d.ts +69 -0
- package/dist/types/constants/programs.d.ts.map +1 -0
- package/dist/types/constants/seeds.d.ts +61 -0
- package/dist/types/constants/seeds.d.ts.map +1 -0
- package/dist/types/core/client.d.ts +323 -0
- package/dist/types/core/client.d.ts.map +1 -0
- package/dist/types/core/connection.d.ts +279 -0
- package/dist/types/core/connection.d.ts.map +1 -0
- package/dist/types/core/index.d.ts +20 -0
- package/dist/types/core/index.d.ts.map +1 -0
- package/dist/types/errors/index.d.ts +276 -0
- package/dist/types/errors/index.d.ts.map +1 -0
- package/dist/types/events/index.d.ts +248 -0
- package/dist/types/events/index.d.ts.map +1 -0
- package/dist/types/idl/index.d.ts +70 -0
- package/dist/types/idl/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +68 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/modules/agent.d.ts +166 -0
- package/dist/types/modules/agent.d.ts.map +1 -0
- package/dist/types/modules/attestation.d.ts +96 -0
- package/dist/types/modules/attestation.d.ts.map +1 -0
- package/dist/types/modules/base.d.ts +126 -0
- package/dist/types/modules/base.d.ts.map +1 -0
- package/dist/types/modules/escrow.d.ts +151 -0
- package/dist/types/modules/escrow.d.ts.map +1 -0
- package/dist/types/modules/feedback.d.ts +105 -0
- package/dist/types/modules/feedback.d.ts.map +1 -0
- package/dist/types/modules/index.d.ts +24 -0
- package/dist/types/modules/index.d.ts.map +1 -0
- package/dist/types/modules/indexing.d.ts +200 -0
- package/dist/types/modules/indexing.d.ts.map +1 -0
- package/dist/types/modules/ledger.d.ts +150 -0
- package/dist/types/modules/ledger.d.ts.map +1 -0
- package/dist/types/modules/tools.d.ts +182 -0
- package/dist/types/modules/tools.d.ts.map +1 -0
- package/dist/types/modules/vault.d.ts +240 -0
- package/dist/types/modules/vault.d.ts.map +1 -0
- package/dist/types/pda/index.d.ts +296 -0
- package/dist/types/pda/index.d.ts.map +1 -0
- package/dist/types/plugin/index.d.ts +171 -0
- package/dist/types/plugin/index.d.ts.map +1 -0
- package/dist/types/plugin/protocols.d.ts +152 -0
- package/dist/types/plugin/protocols.d.ts.map +1 -0
- package/dist/types/plugin/schemas.d.ts +823 -0
- package/dist/types/plugin/schemas.d.ts.map +1 -0
- package/dist/types/postgres/adapter.d.ts +355 -0
- package/dist/types/postgres/adapter.d.ts.map +1 -0
- package/dist/types/postgres/index.d.ts +24 -0
- package/dist/types/postgres/index.d.ts.map +1 -0
- package/dist/types/postgres/serializers.d.ts +30 -0
- package/dist/types/postgres/serializers.d.ts.map +1 -0
- package/dist/types/postgres/sync.d.ts +132 -0
- package/dist/types/postgres/sync.d.ts.map +1 -0
- package/dist/types/postgres/types.d.ts +167 -0
- package/dist/types/postgres/types.d.ts.map +1 -0
- package/dist/types/registries/builder.d.ts +340 -0
- package/dist/types/registries/builder.d.ts.map +1 -0
- package/dist/types/registries/discovery.d.ts +333 -0
- package/dist/types/registries/discovery.d.ts.map +1 -0
- package/dist/types/registries/index.d.ts +48 -0
- package/dist/types/registries/index.d.ts.map +1 -0
- package/dist/types/registries/session.d.ts +323 -0
- package/dist/types/registries/session.d.ts.map +1 -0
- package/dist/types/registries/x402.d.ts +463 -0
- package/dist/types/registries/x402.d.ts.map +1 -0
- package/dist/types/types/accounts.d.ts +565 -0
- package/dist/types/types/accounts.d.ts.map +1 -0
- package/dist/types/types/common.d.ts +166 -0
- package/dist/types/types/common.d.ts.map +1 -0
- package/dist/types/types/enums.d.ts +238 -0
- package/dist/types/types/enums.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +28 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/types/instructions.d.ts +366 -0
- package/dist/types/types/instructions.d.ts.map +1 -0
- package/dist/types/utils/hash.d.ts +48 -0
- package/dist/types/utils/hash.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +19 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/dist/types/utils/serialization.d.ts +69 -0
- package/dist/types/utils/serialization.d.ts.map +1 -0
- package/dist/types/utils/validation.d.ts +29 -0
- package/dist/types/utils/validation.d.ts.map +1 -0
- package/package.json +178 -0
- package/src/constants/index.ts +44 -0
- package/src/constants/limits.ts +165 -0
- package/src/constants/programs.ts +83 -0
- package/src/constants/seeds.ts +66 -0
- package/src/core/client.ts +416 -0
- package/src/core/connection.ts +409 -0
- package/src/core/index.ts +20 -0
- package/src/errors/index.ts +346 -0
- package/src/events/index.ts +335 -0
- package/src/idl/index.ts +76 -0
- package/src/idl/synapse_agent_sap.json +9710 -0
- package/src/index.ts +253 -0
- package/src/modules/agent.ts +319 -0
- package/src/modules/attestation.ts +168 -0
- package/src/modules/base.ts +158 -0
- package/src/modules/escrow.ts +308 -0
- package/src/modules/feedback.ts +186 -0
- package/src/modules/index.ts +24 -0
- package/src/modules/indexing.ts +444 -0
- package/src/modules/ledger.ts +262 -0
- package/src/modules/tools.ts +411 -0
- package/src/modules/vault.ts +533 -0
- package/src/pda/index.ts +512 -0
- package/src/plugin/index.ts +1202 -0
- package/src/plugin/protocols.ts +404 -0
- package/src/plugin/schemas.ts +909 -0
- package/src/postgres/adapter.ts +904 -0
- package/src/postgres/index.ts +59 -0
- package/src/postgres/schema.sql +683 -0
- package/src/postgres/serializers.ts +485 -0
- package/src/postgres/sync.ts +254 -0
- package/src/postgres/types.ts +245 -0
- package/src/registries/builder.ts +607 -0
- package/src/registries/discovery.ts +572 -0
- package/src/registries/index.ts +77 -0
- package/src/registries/session.ts +613 -0
- package/src/registries/x402.ts +906 -0
- package/src/types/accounts.ts +618 -0
- package/src/types/common.ts +187 -0
- package/src/types/enums.ts +214 -0
- package/src/types/index.ts +92 -0
- package/src/types/instructions.ts +413 -0
- package/src/utils/hash.ts +57 -0
- package/src/utils/index.ts +19 -0
- package/src/utils/serialization.ts +98 -0
- package/src/utils/validation.ts +36 -0
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module core/connection
|
|
4
|
+
* @description RPC connection factory for SAP v2 SDK.
|
|
5
|
+
*
|
|
6
|
+
* Provides a high-level, synapse-client-sdk–compatible entry point
|
|
7
|
+
* for creating {@link SapClient} instances from an RPC URL and wallet.
|
|
8
|
+
*
|
|
9
|
+
* @category Core
|
|
10
|
+
* @since v0.1.0
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { SapConnection } from "@synapse-sap/sdk";
|
|
15
|
+
*
|
|
16
|
+
* // Quick start — RPC URL + Keypair
|
|
17
|
+
* const sap = SapConnection.fromKeypair("https://api.devnet.solana.com", keypair);
|
|
18
|
+
* const agent = await sap.client.agent.fetch();
|
|
19
|
+
*
|
|
20
|
+
* // Or build step-by-step
|
|
21
|
+
* const conn = new SapConnection({
|
|
22
|
+
* rpcUrl: "https://us-1-mainnet.oobeprotocol.ai/rpc?api_key=xxx",
|
|
23
|
+
* cluster: "mainnet-beta",
|
|
24
|
+
* commitment: "confirmed",
|
|
25
|
+
* });
|
|
26
|
+
* const client = conn.createClient(wallet);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.SapConnection = void 0;
|
|
31
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
32
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
33
|
+
const constants_1 = require("../constants");
|
|
34
|
+
const client_1 = require("./client");
|
|
35
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
36
|
+
// Implementation
|
|
37
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
38
|
+
/**
|
|
39
|
+
* @name SapConnection
|
|
40
|
+
* @description Lightweight RPC connection wrapper that creates
|
|
41
|
+
* properly-configured {@link SapClient} instances.
|
|
42
|
+
*
|
|
43
|
+
* Compatible with the `synapse-client-sdk` connection model:
|
|
44
|
+
* start from an RPC URL, attach a wallet, get a typed client.
|
|
45
|
+
*
|
|
46
|
+
* @category Core
|
|
47
|
+
* @since v0.1.0
|
|
48
|
+
* @see {@link SapClient}
|
|
49
|
+
* @see {@link SapConnectionConfig}
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* // Factory shortcut for devnet
|
|
54
|
+
* const conn = SapConnection.devnet();
|
|
55
|
+
* const client = conn.createClient(wallet);
|
|
56
|
+
*
|
|
57
|
+
* // One-liner with Keypair
|
|
58
|
+
* const { client } = SapConnection.fromKeypair(
|
|
59
|
+
* "https://api.devnet.solana.com",
|
|
60
|
+
* keypair,
|
|
61
|
+
* );
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
class SapConnection {
|
|
65
|
+
/**
|
|
66
|
+
* @readonly
|
|
67
|
+
* @description Raw Solana {@link Connection}. Exposed for advanced
|
|
68
|
+
* use-cases that need direct RPC access.
|
|
69
|
+
*/
|
|
70
|
+
connection;
|
|
71
|
+
/**
|
|
72
|
+
* @readonly
|
|
73
|
+
* @description The resolved Solana cluster for this connection,
|
|
74
|
+
* either explicitly provided or auto-detected from the RPC URL.
|
|
75
|
+
*/
|
|
76
|
+
cluster;
|
|
77
|
+
/**
|
|
78
|
+
* @readonly
|
|
79
|
+
* @description Commitment level used for all queries and
|
|
80
|
+
* transaction confirmations on this connection.
|
|
81
|
+
*/
|
|
82
|
+
commitment;
|
|
83
|
+
/**
|
|
84
|
+
* @readonly
|
|
85
|
+
* @description The SAP on-chain program {@link PublicKey} resolved
|
|
86
|
+
* for the current {@link cluster}.
|
|
87
|
+
* @see {@link SapConnection.programIdForCluster}
|
|
88
|
+
*/
|
|
89
|
+
programId;
|
|
90
|
+
constructor(config) {
|
|
91
|
+
this.commitment = config.commitment ?? "confirmed";
|
|
92
|
+
this.cluster = config.cluster ?? SapConnection.detectCluster(config.rpcUrl);
|
|
93
|
+
this.programId = SapConnection.programIdForCluster(this.cluster);
|
|
94
|
+
this.connection = new web3_js_1.Connection(config.rpcUrl, {
|
|
95
|
+
commitment: this.commitment,
|
|
96
|
+
wsEndpoint: config.wsUrl,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
// ─────────────────────────────────────────────
|
|
100
|
+
// Factory helpers
|
|
101
|
+
// ─────────────────────────────────────────────
|
|
102
|
+
/**
|
|
103
|
+
* Create a {@link SapConnection} for **devnet** with sensible defaults.
|
|
104
|
+
*
|
|
105
|
+
* @static
|
|
106
|
+
* @param {Commitment} [commitment="confirmed"] — Commitment level.
|
|
107
|
+
* @returns {SapConnection} A connection targeting Solana devnet.
|
|
108
|
+
* @since v0.1.0
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* const conn = SapConnection.devnet();
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
static devnet(commitment = "confirmed") {
|
|
116
|
+
return new SapConnection({
|
|
117
|
+
rpcUrl: "https://api.devnet.solana.com",
|
|
118
|
+
cluster: "devnet",
|
|
119
|
+
commitment,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Create a {@link SapConnection} for **mainnet-beta** with sensible defaults.
|
|
124
|
+
*
|
|
125
|
+
* @static
|
|
126
|
+
* @param {string} [rpcUrl="https://api.mainnet-beta.solana.com"] — Custom RPC URL.
|
|
127
|
+
* @param {Commitment} [commitment="confirmed"] — Commitment level.
|
|
128
|
+
* @returns {SapConnection} A connection targeting Solana mainnet-beta.
|
|
129
|
+
* @since v0.1.0
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* const conn = SapConnection.mainnet("https://my-rpc.example.com");
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
static mainnet(rpcUrl = "https://api.mainnet-beta.solana.com", commitment = "confirmed") {
|
|
137
|
+
return new SapConnection({ rpcUrl, cluster: "mainnet-beta", commitment });
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Create a {@link SapConnection} for **localnet** (`localhost:8899`).
|
|
141
|
+
*
|
|
142
|
+
* @static
|
|
143
|
+
* @param {Commitment} [commitment="confirmed"] — Commitment level.
|
|
144
|
+
* @returns {SapConnection} A connection targeting a local validator.
|
|
145
|
+
* @since v0.1.0
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```ts
|
|
149
|
+
* const conn = SapConnection.localnet();
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
static localnet(commitment = "confirmed") {
|
|
153
|
+
return new SapConnection({
|
|
154
|
+
rpcUrl: "http://localhost:8899",
|
|
155
|
+
cluster: "localnet",
|
|
156
|
+
commitment,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* One-liner: create a {@link SapConnection} + {@link SapClient} from
|
|
161
|
+
* an RPC URL and a `Keypair`. Perfect for scripts and CLI tools.
|
|
162
|
+
*
|
|
163
|
+
* @static
|
|
164
|
+
* @param {string} rpcUrl — Solana JSON-RPC endpoint.
|
|
165
|
+
* @param {Keypair} keypair — Signer keypair.
|
|
166
|
+
* @param {object} [opts] — Optional overrides.
|
|
167
|
+
* @param {Commitment} [opts.commitment] — Commitment level.
|
|
168
|
+
* @param {SapCluster} [opts.cluster] — Explicit cluster hint.
|
|
169
|
+
* @returns {SapConnection & { readonly client: SapClient }} Connection with an attached client.
|
|
170
|
+
* @since v0.1.0
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* const { client, connection } = SapConnection.fromKeypair(
|
|
175
|
+
* "https://api.devnet.solana.com",
|
|
176
|
+
* Keypair.generate(),
|
|
177
|
+
* );
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
static fromKeypair(rpcUrl, keypair, opts) {
|
|
181
|
+
const conn = new SapConnection({
|
|
182
|
+
rpcUrl,
|
|
183
|
+
commitment: opts?.commitment,
|
|
184
|
+
cluster: opts?.cluster,
|
|
185
|
+
});
|
|
186
|
+
const client = conn.createClient(new anchor_1.Wallet(keypair));
|
|
187
|
+
return Object.assign(conn, { client });
|
|
188
|
+
}
|
|
189
|
+
// ─────────────────────────────────────────────
|
|
190
|
+
// Client creation
|
|
191
|
+
// ─────────────────────────────────────────────
|
|
192
|
+
/**
|
|
193
|
+
* Create a {@link SapClient} from an Anchor {@link Wallet} (signer).
|
|
194
|
+
*
|
|
195
|
+
* @param {Wallet} wallet — An Anchor-compatible wallet/signer.
|
|
196
|
+
* @returns {SapClient} A fully-configured SAP client.
|
|
197
|
+
* @since v0.1.0
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```ts
|
|
201
|
+
* const client = conn.createClient(new Wallet(keypair));
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
createClient(wallet) {
|
|
205
|
+
const provider = new anchor_1.AnchorProvider(this.connection, wallet, {
|
|
206
|
+
commitment: this.commitment,
|
|
207
|
+
});
|
|
208
|
+
return client_1.SapClient.from(provider, this.programId);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Create a {@link SapClient} from a raw {@link Keypair}.
|
|
212
|
+
*
|
|
213
|
+
* @param {Keypair} keypair — The signer keypair.
|
|
214
|
+
* @returns {SapClient} A fully-configured SAP client.
|
|
215
|
+
* @since v0.1.0
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```ts
|
|
219
|
+
* const client = conn.fromKeypair(Keypair.generate());
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
fromKeypair(keypair) {
|
|
223
|
+
return this.createClient(new anchor_1.Wallet(keypair));
|
|
224
|
+
}
|
|
225
|
+
// ─────────────────────────────────────────────
|
|
226
|
+
// Utility methods
|
|
227
|
+
// ─────────────────────────────────────────────
|
|
228
|
+
/**
|
|
229
|
+
* Request an airdrop (devnet / localnet only).
|
|
230
|
+
*
|
|
231
|
+
* @param {PublicKey} to — Recipient public key.
|
|
232
|
+
* @param {number} solAmount — Amount of SOL to airdrop.
|
|
233
|
+
* @returns {Promise<string>} The confirmed transaction signature.
|
|
234
|
+
* @throws {Error} If the airdrop request or confirmation fails (e.g. on mainnet).
|
|
235
|
+
* @since v0.1.0
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```ts
|
|
239
|
+
* const sig = await conn.airdrop(wallet.publicKey, 2);
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
async airdrop(to, solAmount) {
|
|
243
|
+
const sig = await this.connection.requestAirdrop(to, solAmount * web3_js_1.LAMPORTS_PER_SOL);
|
|
244
|
+
await this.connection.confirmTransaction(sig, this.commitment);
|
|
245
|
+
return sig;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Get the SOL balance of an address in **lamports**.
|
|
249
|
+
*
|
|
250
|
+
* @param {PublicKey} address — The account to query.
|
|
251
|
+
* @returns {Promise<number>} Balance in lamports.
|
|
252
|
+
* @since v0.1.0
|
|
253
|
+
*/
|
|
254
|
+
async getBalance(address) {
|
|
255
|
+
return this.connection.getBalance(address, this.commitment);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Get the SOL balance of an address in **SOL** (human-readable).
|
|
259
|
+
*
|
|
260
|
+
* @param {PublicKey} address — The account to query.
|
|
261
|
+
* @returns {Promise<number>} Balance in SOL.
|
|
262
|
+
* @since v0.1.0
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```ts
|
|
266
|
+
* const sol = await conn.getBalanceSol(wallet.publicKey);
|
|
267
|
+
* console.log(`Balance: ${sol} SOL`);
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
async getBalanceSol(address) {
|
|
271
|
+
const lamports = await this.getBalance(address);
|
|
272
|
+
return lamports / web3_js_1.LAMPORTS_PER_SOL;
|
|
273
|
+
}
|
|
274
|
+
// ─────────────────────────────────────────────
|
|
275
|
+
// Internal helpers
|
|
276
|
+
// ─────────────────────────────────────────────
|
|
277
|
+
/**
|
|
278
|
+
* Infer the {@link SapCluster} from an RPC URL by inspecting
|
|
279
|
+
* well-known substrings (`devnet`, `localhost`, `:8899`).
|
|
280
|
+
*
|
|
281
|
+
* @static
|
|
282
|
+
* @param {string} rpcUrl — The RPC endpoint to inspect.
|
|
283
|
+
* @returns {SapCluster} The detected cluster, defaulting to `"mainnet-beta"`.
|
|
284
|
+
* @since v0.1.0
|
|
285
|
+
*/
|
|
286
|
+
static detectCluster(rpcUrl) {
|
|
287
|
+
const lower = rpcUrl.toLowerCase();
|
|
288
|
+
if (lower.includes("devnet"))
|
|
289
|
+
return "devnet";
|
|
290
|
+
if (lower.includes("localhost") ||
|
|
291
|
+
lower.includes("127.0.0.1") ||
|
|
292
|
+
lower.includes(":8899"))
|
|
293
|
+
return "localnet";
|
|
294
|
+
return "mainnet-beta";
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Map a {@link SapCluster} to the canonical SAP on-chain program ID.
|
|
298
|
+
*
|
|
299
|
+
* @static
|
|
300
|
+
* @param {SapCluster} cluster — Target cluster.
|
|
301
|
+
* @returns {PublicKey} The program {@link PublicKey} for the given cluster.
|
|
302
|
+
* @since v0.1.0
|
|
303
|
+
* @see {@link SAP_PROGRAM_ID}
|
|
304
|
+
*/
|
|
305
|
+
static programIdForCluster(cluster) {
|
|
306
|
+
switch (cluster) {
|
|
307
|
+
case "mainnet-beta":
|
|
308
|
+
return constants_1.MAINNET_SAP_PROGRAM_ID;
|
|
309
|
+
case "devnet":
|
|
310
|
+
return constants_1.DEVNET_SAP_PROGRAM_ID;
|
|
311
|
+
case "localnet":
|
|
312
|
+
return constants_1.LOCALNET_SAP_PROGRAM_ID;
|
|
313
|
+
default:
|
|
314
|
+
return constants_1.SAP_PROGRAM_ID;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
exports.SapConnection = SapConnection;
|
|
319
|
+
//# sourceMappingURL=connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../../src/core/connection.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;;;AAEH,6CAMyB;AACzB,8CAA2D;AAC3D,4CAKsB;AACtB,qCAAqC;AAoDrC,sEAAsE;AACtE,kBAAkB;AAClB,sEAAsE;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAa,aAAa;IACxB;;;;OAIG;IACM,UAAU,CAAa;IAEhC;;;;OAIG;IACM,OAAO,CAAa;IAE7B;;;;OAIG;IACM,UAAU,CAAa;IAEhC;;;;;OAKG;IACM,SAAS,CAAY;IAE9B,YAAY,MAA2B;QACrC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,WAAW,CAAC;QACnD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC5E,IAAI,CAAC,SAAS,GAAG,aAAa,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAEjE,IAAI,CAAC,UAAU,GAAG,IAAI,oBAAU,CAAC,MAAM,CAAC,MAAM,EAAE;YAC9C,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,UAAU,EAAE,MAAM,CAAC,KAAK;SACzB,CAAC,CAAC;IACL,CAAC;IAED,gDAAgD;IAChD,mBAAmB;IACnB,gDAAgD;IAEhD;;;;;;;;;;;;OAYG;IACH,MAAM,CAA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AAQ,CAAC,OAAO,CAAC;YAEvB,OAAO,UAAU,CAAC;QACpB,OAAO,cAAc,CAAC;IACxB,CAAC;IAED;;;;;;;;OAQG;IACH,MAAM,CAAC,mBAAmB,CAAC,OAAmB;QAC5C,QAAQ,OAAO,EAAE,CAAC;YAChB,KAAK,cAAc;gBACjB,OAAO,kCAAsB,CAAC;YAChC,KAAK,QAAQ;gBACX,OAAO,iCAAqB,CAAC;YAC/B,KAAK,UAAU;gBACb,OAAO,mCAAuB,CAAC;YACjC;gBACE,OAAO,0BAAc,CAAC;QAC1B,CAAC;IACH,CAAC;CACF;AA5RD,sCA4RC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module core
|
|
4
|
+
* @description Core infrastructure — client creation and RPC connection.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { SapClient, SapConnection } from "@synapse-sap/sdk";
|
|
9
|
+
*
|
|
10
|
+
* // From Anchor provider
|
|
11
|
+
* const client = SapClient.from(provider);
|
|
12
|
+
*
|
|
13
|
+
* // From RPC URL + keypair (synapse-client-sdk compatible)
|
|
14
|
+
* const conn = SapConnection.devnet();
|
|
15
|
+
* const client2 = conn.fromKeypair(keypair);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.SapConnection = exports.SapClient = void 0;
|
|
20
|
+
var client_1 = require("./client");
|
|
21
|
+
Object.defineProperty(exports, "SapClient", { enumerable: true, get: function () { return client_1.SapClient; } });
|
|
22
|
+
var connection_1 = require("./connection");
|
|
23
|
+
Object.defineProperty(exports, "SapConnection", { enumerable: true, get: function () { return connection_1.SapConnection; } });
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAEH,mCAAqC;AAA5B,mGAAA,SAAS,OAAA;AAClB,2CAA6C;AAApC,2GAAA,aAAa,OAAA"}
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module errors
|
|
4
|
+
* @description Typed error classes for the SAP v2 SDK.
|
|
5
|
+
*
|
|
6
|
+
* All SDK errors extend {@link SapError} to allow catch-all handling,
|
|
7
|
+
* while concrete subclasses enable fine-grained error matching.
|
|
8
|
+
*
|
|
9
|
+
* @category Errors
|
|
10
|
+
* @since v0.1.0
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { SapError, SapRpcError, SapAccountNotFoundError } from "@synapse-sap/sdk/errors";
|
|
15
|
+
*
|
|
16
|
+
* try {
|
|
17
|
+
* const agent = await client.agent.fetch();
|
|
18
|
+
* } catch (err) {
|
|
19
|
+
* if (err instanceof SapAccountNotFoundError) {
|
|
20
|
+
* console.log("Agent not registered yet");
|
|
21
|
+
* } else if (err instanceof SapRpcError) {
|
|
22
|
+
* console.error("RPC failure:", err.rpcCode);
|
|
23
|
+
* } else if (err instanceof SapError) {
|
|
24
|
+
* console.error("SAP error:", err.message);
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @see {@link SapError}
|
|
30
|
+
* @see {@link SapValidationError}
|
|
31
|
+
* @see {@link SapRpcError}
|
|
32
|
+
* @see {@link SapAccountNotFoundError}
|
|
33
|
+
* @see {@link SapTimeoutError}
|
|
34
|
+
* @see {@link SapPermissionError}
|
|
35
|
+
*/
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.SapPermissionError = exports.SapTimeoutError = exports.SapAccountNotFoundError = exports.SapRpcError = exports.SapValidationError = exports.SapError = void 0;
|
|
38
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
39
|
+
// Base Error
|
|
40
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
41
|
+
/**
|
|
42
|
+
* @name SapError
|
|
43
|
+
* @description Base class for all SAP SDK errors.
|
|
44
|
+
*
|
|
45
|
+
* Extends `Error` and sets `name` automatically so `instanceof`
|
|
46
|
+
* checks work correctly in both CJS and ESM environments.
|
|
47
|
+
*
|
|
48
|
+
* @category Errors
|
|
49
|
+
* @since v0.1.0
|
|
50
|
+
* @extends {Error}
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* try {
|
|
55
|
+
* await client.agent.fetch();
|
|
56
|
+
* } catch (err) {
|
|
57
|
+
* if (err instanceof SapError) {
|
|
58
|
+
* console.error(`[${err.code}] ${err.message}`);
|
|
59
|
+
* }
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @see {@link SapValidationError}
|
|
64
|
+
* @see {@link SapRpcError}
|
|
65
|
+
* @see {@link SapAccountNotFoundError}
|
|
66
|
+
* @see {@link SapTimeoutError}
|
|
67
|
+
* @see {@link SapPermissionError}
|
|
68
|
+
*/
|
|
69
|
+
class SapError extends Error {
|
|
70
|
+
/**
|
|
71
|
+
* @description Machine-readable error code for programmatic handling.
|
|
72
|
+
* @readonly
|
|
73
|
+
*/
|
|
74
|
+
code;
|
|
75
|
+
/**
|
|
76
|
+
* @param message - A human-readable description of the error.
|
|
77
|
+
* @param code - Machine-readable error code (defaults to `"SAP_ERROR"`).
|
|
78
|
+
*/
|
|
79
|
+
constructor(message, code = "SAP_ERROR") {
|
|
80
|
+
super(message);
|
|
81
|
+
this.name = "SapError";
|
|
82
|
+
this.code = code;
|
|
83
|
+
// Fix prototype chain for instanceof checks
|
|
84
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.SapError = SapError;
|
|
88
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
89
|
+
// Validation Error
|
|
90
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
91
|
+
/**
|
|
92
|
+
* @name SapValidationError
|
|
93
|
+
* @description Thrown when SDK-side input validation fails before sending a
|
|
94
|
+
* transaction or making an RPC call.
|
|
95
|
+
*
|
|
96
|
+
* @category Errors
|
|
97
|
+
* @since v0.1.0
|
|
98
|
+
* @extends {SapError}
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* try {
|
|
103
|
+
* await client.agent.register({ name: "" });
|
|
104
|
+
* } catch (err) {
|
|
105
|
+
* if (err instanceof SapValidationError) {
|
|
106
|
+
* console.error(`Validation failed on field "${err.field}": ${err.message}`);
|
|
107
|
+
* }
|
|
108
|
+
* }
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* @see {@link SapError}
|
|
112
|
+
*/
|
|
113
|
+
class SapValidationError extends SapError {
|
|
114
|
+
/**
|
|
115
|
+
* @description Field or parameter that failed validation (if applicable).
|
|
116
|
+
* @readonly
|
|
117
|
+
*/
|
|
118
|
+
field;
|
|
119
|
+
/**
|
|
120
|
+
* @param message - A human-readable description of the validation failure.
|
|
121
|
+
* @param field - The name of the field or parameter that failed validation.
|
|
122
|
+
*/
|
|
123
|
+
constructor(message, field) {
|
|
124
|
+
super(message, "SAP_VALIDATION_ERROR");
|
|
125
|
+
this.name = "SapValidationError";
|
|
126
|
+
this.field = field;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.SapValidationError = SapValidationError;
|
|
130
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
131
|
+
// RPC / Transaction Error
|
|
132
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
133
|
+
/**
|
|
134
|
+
* @name SapRpcError
|
|
135
|
+
* @description Wraps Solana RPC or Anchor transaction errors with additional
|
|
136
|
+
* context (error code, logs).
|
|
137
|
+
*
|
|
138
|
+
* @category Errors
|
|
139
|
+
* @since v0.1.0
|
|
140
|
+
* @extends {SapError}
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* try {
|
|
145
|
+
* await client.agent.register(params);
|
|
146
|
+
* } catch (err) {
|
|
147
|
+
* if (err instanceof SapRpcError) {
|
|
148
|
+
* console.error(`RPC error ${err.rpcCode}: ${err.message}`);
|
|
149
|
+
* err.logs?.forEach((log) => console.debug(log));
|
|
150
|
+
* }
|
|
151
|
+
* }
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* @see {@link SapRpcError.fromAnchor}
|
|
155
|
+
* @see {@link SapError}
|
|
156
|
+
*/
|
|
157
|
+
class SapRpcError extends SapError {
|
|
158
|
+
/**
|
|
159
|
+
* @description Anchor / program error code, if available.
|
|
160
|
+
* @readonly
|
|
161
|
+
*/
|
|
162
|
+
rpcCode;
|
|
163
|
+
/**
|
|
164
|
+
* @description Transaction logs returned by the RPC node.
|
|
165
|
+
* @readonly
|
|
166
|
+
*/
|
|
167
|
+
logs;
|
|
168
|
+
/**
|
|
169
|
+
* @param message - A human-readable description of the RPC or transaction error.
|
|
170
|
+
* @param opts - Optional additional context.
|
|
171
|
+
* @param opts.rpcCode - Anchor or Solana program error code.
|
|
172
|
+
* @param opts.logs - Raw transaction logs from the RPC node.
|
|
173
|
+
*/
|
|
174
|
+
constructor(message, opts) {
|
|
175
|
+
super(message, "SAP_RPC_ERROR");
|
|
176
|
+
this.name = "SapRpcError";
|
|
177
|
+
this.rpcCode = opts?.rpcCode;
|
|
178
|
+
this.logs = opts?.logs;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* @static
|
|
182
|
+
* @description Create a {@link SapRpcError} from an Anchor-style error object.
|
|
183
|
+
* Extracts `code` and `logs` automatically from the Anchor error shape.
|
|
184
|
+
*
|
|
185
|
+
* @param err - The raw Anchor or Solana error object.
|
|
186
|
+
* @returns A new {@link SapRpcError} populated with extracted code, logs, and message.
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts
|
|
190
|
+
* try {
|
|
191
|
+
* await program.methods.registerAgent(args).rpc();
|
|
192
|
+
* } catch (raw) {
|
|
193
|
+
* throw SapRpcError.fromAnchor(raw);
|
|
194
|
+
* }
|
|
195
|
+
* ```
|
|
196
|
+
*
|
|
197
|
+
* @see {@link SapRpcError}
|
|
198
|
+
*/
|
|
199
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
200
|
+
static fromAnchor(err) {
|
|
201
|
+
const code = err?.error?.errorCode?.number ?? err?.code;
|
|
202
|
+
const logs = err?.logs ?? err?.error?.logs ?? [];
|
|
203
|
+
const msg = err?.error?.errorMessage ?? err?.message ?? "Unknown RPC error";
|
|
204
|
+
return new SapRpcError(msg, { rpcCode: code, logs });
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
exports.SapRpcError = SapRpcError;
|
|
208
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
209
|
+
// Account Not Found
|
|
210
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
211
|
+
/**
|
|
212
|
+
* @name SapAccountNotFoundError
|
|
213
|
+
* @description Thrown when an expected on-chain account does not exist or has
|
|
214
|
+
* been closed.
|
|
215
|
+
*
|
|
216
|
+
* @category Errors
|
|
217
|
+
* @since v0.1.0
|
|
218
|
+
* @extends {SapError}
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```ts
|
|
222
|
+
* try {
|
|
223
|
+
* const agent = await client.agent.fetch(agentPda);
|
|
224
|
+
* } catch (err) {
|
|
225
|
+
* if (err instanceof SapAccountNotFoundError) {
|
|
226
|
+
* console.warn(`Missing ${err.accountType ?? "account"}: ${err.address}`);
|
|
227
|
+
* }
|
|
228
|
+
* }
|
|
229
|
+
* ```
|
|
230
|
+
*
|
|
231
|
+
* @see {@link SapError}
|
|
232
|
+
*/
|
|
233
|
+
class SapAccountNotFoundError extends SapError {
|
|
234
|
+
/**
|
|
235
|
+
* @description The base-58 encoded account address that was not found.
|
|
236
|
+
* @readonly
|
|
237
|
+
*/
|
|
238
|
+
address;
|
|
239
|
+
/**
|
|
240
|
+
* @description The expected account type (e.g. `"AgentRecord"`, `"VaultAccount"`).
|
|
241
|
+
* @readonly
|
|
242
|
+
*/
|
|
243
|
+
accountType;
|
|
244
|
+
/**
|
|
245
|
+
* @param address - The base-58 encoded address of the missing account.
|
|
246
|
+
* @param accountType - Optional label for the expected account type.
|
|
247
|
+
*/
|
|
248
|
+
constructor(address, accountType) {
|
|
249
|
+
const label = accountType ? `${accountType} account` : "Account";
|
|
250
|
+
super(`${label} not found: ${address}`, "SAP_ACCOUNT_NOT_FOUND");
|
|
251
|
+
this.name = "SapAccountNotFoundError";
|
|
252
|
+
this.address = address;
|
|
253
|
+
this.accountType = accountType;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
exports.SapAccountNotFoundError = SapAccountNotFoundError;
|
|
257
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
258
|
+
// Timeout Error
|
|
259
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
260
|
+
/**
|
|
261
|
+
* @name SapTimeoutError
|
|
262
|
+
* @description Thrown when an operation (e.g., transaction confirmation) exceeds
|
|
263
|
+
* the configured timeout.
|
|
264
|
+
*
|
|
265
|
+
* @category Errors
|
|
266
|
+
* @since v0.1.0
|
|
267
|
+
* @extends {SapError}
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* ```ts
|
|
271
|
+
* try {
|
|
272
|
+
* await client.agent.register(params, { timeoutMs: 30_000 });
|
|
273
|
+
* } catch (err) {
|
|
274
|
+
* if (err instanceof SapTimeoutError) {
|
|
275
|
+
* console.error(`Timed out after ${err.timeoutMs}ms: ${err.message}`);
|
|
276
|
+
* }
|
|
277
|
+
* }
|
|
278
|
+
* ```
|
|
279
|
+
*
|
|
280
|
+
* @see {@link SapError}
|
|
281
|
+
*/
|
|
282
|
+
class SapTimeoutError extends SapError {
|
|
283
|
+
/**
|
|
284
|
+
* @description Timeout duration in milliseconds that was exceeded.
|
|
285
|
+
* @readonly
|
|
286
|
+
*/
|
|
287
|
+
timeoutMs;
|
|
288
|
+
/**
|
|
289
|
+
* @param message - A human-readable description of the timeout.
|
|
290
|
+
* @param timeoutMs - The timeout threshold in milliseconds.
|
|
291
|
+
*/
|
|
292
|
+
constructor(message, timeoutMs) {
|
|
293
|
+
super(message, "SAP_TIMEOUT");
|
|
294
|
+
this.name = "SapTimeoutError";
|
|
295
|
+
this.timeoutMs = timeoutMs;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
exports.SapTimeoutError = SapTimeoutError;
|
|
299
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
300
|
+
// Permission Error
|
|
301
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
302
|
+
/**
|
|
303
|
+
* @name SapPermissionError
|
|
304
|
+
* @description Thrown when the current wallet lacks the required permission
|
|
305
|
+
* (authority, delegate, etc.) for an operation.
|
|
306
|
+
*
|
|
307
|
+
* @category Errors
|
|
308
|
+
* @since v0.1.0
|
|
309
|
+
* @extends {SapError}
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* ```ts
|
|
313
|
+
* try {
|
|
314
|
+
* await client.agent.update(agentPda, updates);
|
|
315
|
+
* } catch (err) {
|
|
316
|
+
* if (err instanceof SapPermissionError) {
|
|
317
|
+
* console.error(`Permission denied: ${err.message}`);
|
|
318
|
+
* }
|
|
319
|
+
* }
|
|
320
|
+
* ```
|
|
321
|
+
*
|
|
322
|
+
* @see {@link SapError}
|
|
323
|
+
*/
|
|
324
|
+
class SapPermissionError extends SapError {
|
|
325
|
+
/**
|
|
326
|
+
* @param message - A human-readable description of the permission failure.
|
|
327
|
+
*/
|
|
328
|
+
constructor(message) {
|
|
329
|
+
super(message, "SAP_PERMISSION_DENIED");
|
|
330
|
+
this.name = "SapPermissionError";
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
exports.SapPermissionError = SapPermissionError;
|
|
334
|
+
//# sourceMappingUR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