@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,485 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module postgres/serializers
|
|
3
|
+
* @description Transforms on-chain account data into PostgreSQL-ready row objects.
|
|
4
|
+
*
|
|
5
|
+
* Each serializer takes the deserialized Anchor account data and the PDA
|
|
6
|
+
* address, then returns a flat key-value record suitable for SQL INSERT/UPSERT.
|
|
7
|
+
*
|
|
8
|
+
* @category Postgres
|
|
9
|
+
* @since v0.1.0
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { PublicKey } from "@solana/web3.js";
|
|
14
|
+
import type BN from "bn.js";
|
|
15
|
+
import type {
|
|
16
|
+
AgentAccountData,
|
|
17
|
+
AgentStatsData,
|
|
18
|
+
FeedbackAccountData,
|
|
19
|
+
CapabilityIndexData,
|
|
20
|
+
ProtocolIndexData,
|
|
21
|
+
ToolCategoryIndexData,
|
|
22
|
+
GlobalRegistryData,
|
|
23
|
+
MemoryVaultData,
|
|
24
|
+
SessionLedgerData,
|
|
25
|
+
EpochPageData,
|
|
26
|
+
VaultDelegateData,
|
|
27
|
+
SessionCheckpointData,
|
|
28
|
+
ToolDescriptorData,
|
|
29
|
+
EscrowAccountData,
|
|
30
|
+
AgentAttestationData,
|
|
31
|
+
MemoryLedgerData,
|
|
32
|
+
LedgerPageData,
|
|
33
|
+
} from "../types";
|
|
34
|
+
|
|
35
|
+
// ── Helpers ──────────────────────────────────────────
|
|
36
|
+
|
|
37
|
+
/** Convert BN to string for BIGINT columns. */
|
|
38
|
+
const bn = (v: BN | null | undefined): string | null =>
|
|
39
|
+
v ? v.toString() : null;
|
|
40
|
+
|
|
41
|
+
/** Convert PublicKey to base58 string. */
|
|
42
|
+
const pk = (v: PublicKey | null | undefined): string | null =>
|
|
43
|
+
v ? v.toBase58() : null;
|
|
44
|
+
|
|
45
|
+
/** Convert a number[] (byte array) to Buffer for BYTEA columns. */
|
|
46
|
+
const bytes = (v: number[] | Uint8Array | null | undefined): Buffer | null =>
|
|
47
|
+
v ? Buffer.from(v) : null;
|
|
48
|
+
|
|
49
|
+
/** Resolve Anchor enum variant to string. */
|
|
50
|
+
function enumVariant(v: Record<string, unknown> | null | undefined): string | null {
|
|
51
|
+
if (!v) return null;
|
|
52
|
+
const keys = Object.keys(v);
|
|
53
|
+
return keys.length > 0 ? (keys[0] ?? null) : null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** PublicKey[] → TEXT[] */
|
|
57
|
+
const pks = (arr: PublicKey[]): string[] => arr.map((p) => p.toBase58());
|
|
58
|
+
|
|
59
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
60
|
+
// Serializers — one per account type
|
|
61
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
62
|
+
|
|
63
|
+
export function serializeGlobalRegistry(
|
|
64
|
+
pda: string,
|
|
65
|
+
d: GlobalRegistryData,
|
|
66
|
+
slot: number,
|
|
67
|
+
): Record<string, unknown> {
|
|
68
|
+
return {
|
|
69
|
+
pda,
|
|
70
|
+
bump: d.bump,
|
|
71
|
+
total_agents: bn(d.totalAgents),
|
|
72
|
+
active_agents: bn(d.activeAgents),
|
|
73
|
+
total_feedbacks: bn(d.totalFeedbacks),
|
|
74
|
+
total_capabilities: d.totalCapabilities,
|
|
75
|
+
total_protocols: d.totalProtocols,
|
|
76
|
+
last_registered_at: bn(d.lastRegisteredAt),
|
|
77
|
+
initialized_at: bn(d.initializedAt),
|
|
78
|
+
authority: pk(d.authority),
|
|
79
|
+
total_tools: d.totalTools,
|
|
80
|
+
total_vaults: d.totalVaults,
|
|
81
|
+
total_escrows: d.totalEscrows,
|
|
82
|
+
total_attestations: d.totalAttestations,
|
|
83
|
+
slot,
|
|
84
|
+
synced_at: new Date(),
|
|
85
|
+
raw_data: JSON.parse(JSON.stringify(d)),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function serializeAgent(
|
|
90
|
+
pda: string,
|
|
91
|
+
d: AgentAccountData,
|
|
92
|
+
slot: number,
|
|
93
|
+
): Record<string, unknown> {
|
|
94
|
+
return {
|
|
95
|
+
pda,
|
|
96
|
+
bump: d.bump,
|
|
97
|
+
version: d.version,
|
|
98
|
+
wallet: pk(d.wallet),
|
|
99
|
+
name: d.name,
|
|
100
|
+
description: d.description,
|
|
101
|
+
agent_id: d.agentId,
|
|
102
|
+
agent_uri: d.agentUri,
|
|
103
|
+
x402_endpoint: d.x402Endpoint,
|
|
104
|
+
is_active: d.isActive,
|
|
105
|
+
created_at: bn(d.createdAt),
|
|
106
|
+
updated_at: bn(d.updatedAt),
|
|
107
|
+
reputation_score: d.reputationScore,
|
|
108
|
+
total_feedbacks: d.totalFeedbacks,
|
|
109
|
+
reputation_sum: bn(d.reputationSum),
|
|
110
|
+
total_calls_served: bn(d.totalCallsServed),
|
|
111
|
+
avg_latency_ms: d.avgLatencyMs,
|
|
112
|
+
uptime_percent: d.uptimePercent,
|
|
113
|
+
capabilities: JSON.stringify(d.capabilities),
|
|
114
|
+
pricing: JSON.stringify(
|
|
115
|
+
d.pricing.map((t) => ({
|
|
116
|
+
...t,
|
|
117
|
+
pricePerCall: t.pricePerCall?.toString(),
|
|
118
|
+
minPricePerCall: t.minPricePerCall?.toString(),
|
|
119
|
+
maxPricePerCall: t.maxPricePerCall?.toString(),
|
|
120
|
+
minEscrowDeposit: t.minEscrowDeposit?.toString(),
|
|
121
|
+
tokenMint: t.tokenMint ? pk(t.tokenMint) : null,
|
|
122
|
+
tokenType: enumVariant(t.tokenType as Record<string, unknown>),
|
|
123
|
+
settlementMode: enumVariant(
|
|
124
|
+
t.settlementMode as Record<string, unknown> | null,
|
|
125
|
+
),
|
|
126
|
+
volumeCurve: t.volumeCurve?.map((v) => ({
|
|
127
|
+
afterCalls: v.afterCalls,
|
|
128
|
+
pricePerCall: v.pricePerCall?.toString(),
|
|
129
|
+
})),
|
|
130
|
+
})),
|
|
131
|
+
),
|
|
132
|
+
protocols: d.protocols,
|
|
133
|
+
active_plugins: JSON.stringify(
|
|
134
|
+
d.activePlugins.map((p) => ({
|
|
135
|
+
pluginType: enumVariant(p.pluginType as Record<string, unknown>),
|
|
136
|
+
pda: pk(p.pda),
|
|
137
|
+
})),
|
|
138
|
+
),
|
|
139
|
+
slot,
|
|
140
|
+
synced_at: new Date(),
|
|
141
|
+
raw_data: JSON.parse(JSON.stringify(d)),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function serializeAgentStats(
|
|
146
|
+
pda: string,
|
|
147
|
+
d: AgentStatsData,
|
|
148
|
+
slot: number,
|
|
149
|
+
): Record<string, unknown> {
|
|
150
|
+
return {
|
|
151
|
+
pda,
|
|
152
|
+
bump: d.bump,
|
|
153
|
+
agent: pk(d.agent),
|
|
154
|
+
wallet: pk(d.wallet),
|
|
155
|
+
total_calls_served: bn(d.totalCallsServed),
|
|
156
|
+
is_active: d.isActive,
|
|
157
|
+
updated_at: bn(d.updatedAt),
|
|
158
|
+
slot,
|
|
159
|
+
synced_at: new Date(),
|
|
160
|
+
raw_data: JSON.parse(JSON.stringify(d)),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function serializeFeedback(
|
|
165
|
+
pda: string,
|
|
166
|
+
d: FeedbackAccountData,
|
|
167
|
+
slot: number,
|
|
168
|
+
): Record<string, unknown> {
|
|
169
|
+
return {
|
|
170
|
+
pda,
|
|
171
|
+
bump: d.bump,
|
|
172
|
+
agent: pk(d.agent),
|
|
173
|
+
reviewer: pk(d.reviewer),
|
|
174
|
+
score: d.score,
|
|
175
|
+
tag: d.tag,
|
|
176
|
+
comment_hash: bytes(d.commentHash),
|
|
177
|
+
created_at: bn(d.createdAt),
|
|
178
|
+
updated_at: bn(d.updatedAt),
|
|
179
|
+
is_revoked: d.isRevoked,
|
|
180
|
+
slot,
|
|
181
|
+
synced_at: new Date(),
|
|
182
|
+
raw_data: JSON.parse(JSON.stringify(d)),
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function serializeCapabilityIndex(
|
|
187
|
+
pda: string,
|
|
188
|
+
d: CapabilityIndexData,
|
|
189
|
+
slot: number,
|
|
190
|
+
): Record<string, unknown> {
|
|
191
|
+
return {
|
|
192
|
+
pda,
|
|
193
|
+
bump: d.bump,
|
|
194
|
+
capability_id: d.capabilityId,
|
|
195
|
+
capability_hash: bytes(d.capabilityHash),
|
|
196
|
+
agents: pks(d.agents),
|
|
197
|
+
total_pages: d.totalPages,
|
|
198
|
+
last_updated: bn(d.lastUpdated),
|
|
199
|
+
slot,
|
|
200
|
+
synced_at: new Date(),
|
|
201
|
+
raw_data: JSON.parse(JSON.stringify(d)),
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function serializeProtocolIndex(
|
|
206
|
+
pda: string,
|
|
207
|
+
d: ProtocolIndexData,
|
|
208
|
+
slot: number,
|
|
209
|
+
): Record<string, unknown> {
|
|
210
|
+
return {
|
|
211
|
+
pda,
|
|
212
|
+
bump: d.bump,
|
|
213
|
+
protocol_id: d.protocolId,
|
|
214
|
+
protocol_hash: bytes(d.protocolHash),
|
|
215
|
+
agents: pks(d.agents),
|
|
216
|
+
total_pages: d.totalPages,
|
|
217
|
+
last_updated: bn(d.lastUpdated),
|
|
218
|
+
slot,
|
|
219
|
+
synced_at: new Date(),
|
|
220
|
+
raw_data: JSON.parse(JSON.stringify(d)),
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function serializeVault(
|
|
225
|
+
pda: string,
|
|
226
|
+
d: MemoryVaultData,
|
|
227
|
+
slot: number,
|
|
228
|
+
): Record<string, unknown> {
|
|
229
|
+
return {
|
|
230
|
+
pda,
|
|
231
|
+
bump: d.bump,
|
|
232
|
+
agent: pk(d.agent),
|
|
233
|
+
wallet: pk(d.wallet),
|
|
234
|
+
vault_nonce: bytes(d.vaultNonce),
|
|
235
|
+
total_sessions: d.totalSessions,
|
|
236
|
+
total_inscriptions: bn(d.totalInscriptions),
|
|
237
|
+
total_bytes_inscribed: bn(d.totalBytesInscribed),
|
|
238
|
+
created_at: bn(d.createdAt),
|
|
239
|
+
protocol_version: d.protocolVersion,
|
|
240
|
+
nonce_version: d.nonceVersion,
|
|
241
|
+
last_nonce_rotation: bn(d.lastNonceRotation),
|
|
242
|
+
slot,
|
|
243
|
+
synced_at: new Date(),
|
|
244
|
+
raw_data: JSON.parse(JSON.stringify(d)),
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export function serializeSession(
|
|
249
|
+
pda: string,
|
|
250
|
+
d: SessionLedgerData,
|
|
251
|
+
slot: number,
|
|
252
|
+
): Record<string, unknown> {
|
|
253
|
+
return {
|
|
254
|
+
pda,
|
|
255
|
+
bump: d.bump,
|
|
256
|
+
vault: pk(d.vault),
|
|
257
|
+
session_hash: bytes(d.sessionHash),
|
|
258
|
+
sequence_counter: d.sequenceCounter,
|
|
259
|
+
total_bytes: bn(d.totalBytes),
|
|
260
|
+
current_epoch: d.currentEpoch,
|
|
261
|
+
total_epochs: d.totalEpochs,
|
|
262
|
+
created_at: bn(d.createdAt),
|
|
263
|
+
last_inscribed_at: bn(d.lastInscribedAt),
|
|
264
|
+
is_closed: d.isClosed,
|
|
265
|
+
merkle_root: bytes(d.merkleRoot),
|
|
266
|
+
total_checkpoints: d.totalCheckpoints,
|
|
267
|
+
tip_hash: bytes(d.tipHash),
|
|
268
|
+
slot,
|
|
269
|
+
synced_at: new Date(),
|
|
270
|
+
raw_data: JSON.parse(JSON.stringify(d)),
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export function serializeEpochPage(
|
|
275
|
+
pda: string,
|
|
276
|
+
d: EpochPageData,
|
|
277
|
+
slot: number,
|
|
278
|
+
): Record<string, unknown> {
|
|
279
|
+
return {
|
|
280
|
+
pda,
|
|
281
|
+
bump: d.bump,
|
|
282
|
+
session: pk(d.session),
|
|
283
|
+
epoch_index: d.epochIndex,
|
|
284
|
+
start_sequence: d.startSequence,
|
|
285
|
+
inscription_count: d.inscriptionCount,
|
|
286
|
+
total_bytes: d.totalBytes,
|
|
287
|
+
first_ts: bn(d.firstTs),
|
|
288
|
+
last_ts: bn(d.lastTs),
|
|
289
|
+
slot,
|
|
290
|
+
synced_at: new Date(),
|
|
291
|
+
raw_data: JSON.parse(JSON.stringify(d)),
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export function serializeDelegate(
|
|
296
|
+
pda: string,
|
|
297
|
+
d: VaultDelegateData,
|
|
298
|
+
slot: number,
|
|
299
|
+
): Record<string, unknown> {
|
|
300
|
+
return {
|
|
301
|
+
pda,
|
|
302
|
+
bump: d.bump,
|
|
303
|
+
vault: pk(d.vault),
|
|
304
|
+
delegate: pk(d.delegate),
|
|
305
|
+
permissions: d.permissions,
|
|
306
|
+
expires_at: bn(d.expiresAt),
|
|
307
|
+
created_at: bn(d.createdAt),
|
|
308
|
+
slot,
|
|
309
|
+
synced_at: new Date(),
|
|
310
|
+
raw_data: JSON.parse(JSON.stringify(d)),
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export function serializeTool(
|
|
315
|
+
pda: string,
|
|
316
|
+
d: ToolDescriptorData,
|
|
317
|
+
slot: number,
|
|
318
|
+
): Record<string, unknown> {
|
|
319
|
+
return {
|
|
320
|
+
pda,
|
|
321
|
+
bump: d.bump,
|
|
322
|
+
agent: pk(d.agent),
|
|
323
|
+
tool_name_hash: bytes(d.toolNameHash),
|
|
324
|
+
tool_name: d.toolName,
|
|
325
|
+
protocol_hash: bytes(d.protocolHash),
|
|
326
|
+
version: d.version,
|
|
327
|
+
description_hash: bytes(d.descriptionHash),
|
|
328
|
+
input_schema_hash: bytes(d.inputSchemaHash),
|
|
329
|
+
output_schema_hash: bytes(d.outputSchemaHash),
|
|
330
|
+
http_method: enumVariant(d.httpMethod as Record<string, unknown>),
|
|
331
|
+
category: enumVariant(d.category as Record<string, unknown>),
|
|
332
|
+
params_count: d.paramsCount,
|
|
333
|
+
required_params: d.requiredParams,
|
|
334
|
+
is_compound: d.isCompound,
|
|
335
|
+
is_active: d.isActive,
|
|
336
|
+
total_invocations: bn(d.totalInvocations),
|
|
337
|
+
created_at: bn(d.createdAt),
|
|
338
|
+
updated_at: bn(d.updatedAt),
|
|
339
|
+
previous_version: pk(d.previousVersion),
|
|
340
|
+
slot,
|
|
341
|
+
synced_at: new Date(),
|
|
342
|
+
raw_data: JSON.parse(JSON.stringify(d)),
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export function serializeCheckpoint(
|
|
347
|
+
pda: string,
|
|
348
|
+
d: SessionCheckpointData,
|
|
349
|
+
slot: number,
|
|
350
|
+
): Record<string, unknown> {
|
|
351
|
+
return {
|
|
352
|
+
pda,
|
|
353
|
+
bump: d.bump,
|
|
354
|
+
session: pk(d.session),
|
|
355
|
+
checkpoint_index: d.checkpointIndex,
|
|
356
|
+
merkle_root: bytes(d.merkleRoot),
|
|
357
|
+
sequence_at: d.sequenceAt,
|
|
358
|
+
epoch_at: d.epochAt,
|
|
359
|
+
total_bytes_at: bn(d.totalBytesAt),
|
|
360
|
+
inscriptions_at: bn(d.inscriptionsAt),
|
|
361
|
+
created_at: bn(d.createdAt),
|
|
362
|
+
slot,
|
|
363
|
+
synced_at: new Date(),
|
|
364
|
+
raw_data: JSON.parse(JSON.stringify(d)),
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export function serializeEscrow(
|
|
369
|
+
pda: string,
|
|
370
|
+
d: EscrowAccountData,
|
|
371
|
+
slot: number,
|
|
372
|
+
): Record<string, unknown> {
|
|
373
|
+
return {
|
|
374
|
+
pda,
|
|
375
|
+
bump: d.bump,
|
|
376
|
+
agent: pk(d.agent),
|
|
377
|
+
depositor: pk(d.depositor),
|
|
378
|
+
agent_wallet: pk(d.agentWallet),
|
|
379
|
+
balance: bn(d.balance),
|
|
380
|
+
total_deposited: bn(d.totalDeposited),
|
|
381
|
+
total_settled: bn(d.totalSettled),
|
|
382
|
+
total_calls_settled: bn(d.totalCallsSettled),
|
|
383
|
+
price_per_call: bn(d.pricePerCall),
|
|
384
|
+
max_calls: bn(d.maxCalls),
|
|
385
|
+
created_at: bn(d.createdAt),
|
|
386
|
+
last_settled_at: bn(d.lastSettledAt),
|
|
387
|
+
expires_at: bn(d.expiresAt),
|
|
388
|
+
volume_curve: JSON.stringify(
|
|
389
|
+
d.volumeCurve.map((v) => ({
|
|
390
|
+
afterCalls: v.afterCalls,
|
|
391
|
+
pricePerCall: v.pricePerCall?.toString(),
|
|
392
|
+
})),
|
|
393
|
+
),
|
|
394
|
+
token_mint: pk(d.tokenMint),
|
|
395
|
+
token_decimals: d.tokenDecimals,
|
|
396
|
+
slot,
|
|
397
|
+
synced_at: new Date(),
|
|
398
|
+
raw_data: JSON.parse(JSON.stringify(d)),
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
export function serializeToolCategoryIndex(
|
|
403
|
+
pda: string,
|
|
404
|
+
d: ToolCategoryIndexData,
|
|
405
|
+
slot: number,
|
|
406
|
+
): Record<string, unknown> {
|
|
407
|
+
return {
|
|
408
|
+
pda,
|
|
409
|
+
bump: d.bump,
|
|
410
|
+
category: enumVariant({ [d.category]: {} } as Record<string, unknown>) ?? String(d.category),
|
|
411
|
+
tools: pks(d.tools),
|
|
412
|
+
total_pages: d.totalPages,
|
|
413
|
+
last_updated: bn(d.lastUpdated),
|
|
414
|
+
slot,
|
|
415
|
+
synced_at: new Date(),
|
|
416
|
+
raw_data: JSON.parse(JSON.stringify(d)),
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export function serializeAttestation(
|
|
421
|
+
pda: string,
|
|
422
|
+
d: AgentAttestationData,
|
|
423
|
+
slot: number,
|
|
424
|
+
): Record<string, unknown> {
|
|
425
|
+
return {
|
|
426
|
+
pda,
|
|
427
|
+
bump: d.bump,
|
|
428
|
+
agent: pk(d.agent),
|
|
429
|
+
attester: pk(d.attester),
|
|
430
|
+
attestation_type: d.attestationType,
|
|
431
|
+
metadata_hash: bytes(d.metadataHash),
|
|
432
|
+
is_active: d.isActive,
|
|
433
|
+
expires_at: bn(d.expiresAt),
|
|
434
|
+
created_at: bn(d.createdAt),
|
|
435
|
+
updated_at: bn(d.updatedAt),
|
|
436
|
+
slot,
|
|
437
|
+
synced_at: new Date(),
|
|
438
|
+
raw_data: JSON.parse(JSON.stringify(d)),
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
export function serializeLedger(
|
|
443
|
+
pda: string,
|
|
444
|
+
d: MemoryLedgerData,
|
|
445
|
+
slot: number,
|
|
446
|
+
): Record<string, unknown> {
|
|
447
|
+
return {
|
|
448
|
+
pda,
|
|
449
|
+
bump: d.bump,
|
|
450
|
+
session: pk(d.session),
|
|
451
|
+
authority: pk(d.authority),
|
|
452
|
+
num_entries: d.numEntries,
|
|
453
|
+
merkle_root: bytes(d.merkleRoot),
|
|
454
|
+
latest_hash: bytes(d.latestHash),
|
|
455
|
+
total_data_size: bn(d.totalDataSize),
|
|
456
|
+
created_at: bn(d.createdAt),
|
|
457
|
+
updated_at: bn(d.updatedAt),
|
|
458
|
+
num_pages: d.numPages,
|
|
459
|
+
ring: bytes(d.ring),
|
|
460
|
+
slot,
|
|
461
|
+
synced_at: new Date(),
|
|
462
|
+
raw_data: JSON.parse(JSON.stringify(d)),
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
export function serializeLedgerPage(
|
|
467
|
+
pda: string,
|
|
468
|
+
d: LedgerPageData,
|
|
469
|
+
slot: number,
|
|
470
|
+
): Record<string, unknown> {
|
|
471
|
+
return {
|
|
472
|
+
pda,
|
|
473
|
+
bump: d.bump,
|
|
474
|
+
ledger: pk(d.ledger),
|
|
475
|
+
page_index: d.pageIndex,
|
|
476
|
+
sealed_at: bn(d.sealedAt),
|
|
477
|
+
entries_in_page: d.entriesInPage,
|
|
478
|
+
data_size: d.dataSize,
|
|
479
|
+
merkle_root_at_seal: bytes(d.merkleRootAtSeal),
|
|
480
|
+
data: bytes(d.data),
|
|
481
|
+
slot,
|
|
482
|
+
synced_at: new Date(),
|
|
483
|
+
raw_data: JSON.parse(JSON.stringify(d)),
|
|
484
|
+
};
|
|
485
|
+
}
|