@oobe-protocol-labs/synapse-sap-sdk 0.6.3 → 0.8.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/dist/cjs/constants/seeds.js +9 -0
- package/dist/cjs/constants/seeds.js.map +1 -1
- package/dist/cjs/core/client.js +55 -0
- package/dist/cjs/core/client.js.map +1 -1
- package/dist/cjs/idl/synapse_agent_sap.json +8571 -4106
- package/dist/cjs/index.js +29 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/modules/escrow-v2.js +220 -0
- package/dist/cjs/modules/escrow-v2.js.map +1 -0
- package/dist/cjs/modules/escrow.js +4 -0
- package/dist/cjs/modules/escrow.js.map +1 -1
- package/dist/cjs/modules/index.js +9 -1
- package/dist/cjs/modules/index.js.map +1 -1
- package/dist/cjs/modules/receipt.js +144 -0
- package/dist/cjs/modules/receipt.js.map +1 -0
- package/dist/cjs/modules/staking.js +94 -0
- package/dist/cjs/modules/staking.js.map +1 -0
- package/dist/cjs/modules/subscription.js +96 -0
- package/dist/cjs/modules/subscription.js.map +1 -0
- package/dist/cjs/pda/index.js +166 -1
- package/dist/cjs/pda/index.js.map +1 -1
- package/dist/cjs/registries/x402.js +88 -51
- package/dist/cjs/registries/x402.js.map +1 -1
- package/dist/cjs/types/enums.js +96 -1
- package/dist/cjs/types/enums.js.map +1 -1
- package/dist/cjs/types/index.js +6 -1
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/instructions.js.map +1 -1
- package/dist/cjs/utils/escrow-validation.js +219 -0
- package/dist/cjs/utils/escrow-validation.js.map +1 -0
- package/dist/cjs/utils/index.js +12 -1
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/merchant-validator.js +246 -0
- package/dist/cjs/utils/merchant-validator.js.map +1 -0
- package/dist/cjs/utils/x402-direct.js +231 -0
- package/dist/cjs/utils/x402-direct.js.map +1 -0
- package/dist/esm/constants/seeds.js +9 -0
- package/dist/esm/constants/seeds.js.map +1 -1
- package/dist/esm/core/client.js +55 -0
- package/dist/esm/core/client.js.map +1 -1
- package/dist/esm/idl/synapse_agent_sap.json +8571 -4106
- package/dist/esm/index.js +5 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/modules/escrow-v2.js +216 -0
- package/dist/esm/modules/escrow-v2.js.map +1 -0
- package/dist/esm/modules/escrow.js +4 -0
- package/dist/esm/modules/escrow.js.map +1 -1
- package/dist/esm/modules/index.js +4 -0
- package/dist/esm/modules/index.js.map +1 -1
- package/dist/esm/modules/receipt.js +140 -0
- package/dist/esm/modules/receipt.js.map +1 -0
- package/dist/esm/modules/staking.js +90 -0
- package/dist/esm/modules/staking.js.map +1 -0
- package/dist/esm/modules/subscription.js +92 -0
- package/dist/esm/modules/subscription.js.map +1 -0
- package/dist/esm/pda/index.js +157 -0
- package/dist/esm/pda/index.js.map +1 -1
- package/dist/esm/registries/x402.js +89 -52
- package/dist/esm/registries/x402.js.map +1 -1
- package/dist/esm/types/enums.js +95 -0
- package/dist/esm/types/enums.js.map +1 -1
- package/dist/esm/types/index.js +1 -1
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/types/instructions.js.map +1 -1
- package/dist/esm/utils/escrow-validation.js +212 -0
- package/dist/esm/utils/escrow-validation.js.map +1 -0
- package/dist/esm/utils/index.js +4 -0
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/merchant-validator.js +241 -0
- package/dist/esm/utils/merchant-validator.js.map +1 -0
- package/dist/esm/utils/x402-direct.js +228 -0
- package/dist/esm/utils/x402-direct.js.map +1 -0
- package/dist/types/constants/seeds.d.ts +9 -0
- package/dist/types/constants/seeds.d.ts.map +1 -1
- package/dist/types/core/client.d.ts +43 -0
- package/dist/types/core/client.d.ts.map +1 -1
- package/dist/types/index.d.ts +6 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modules/escrow-v2.d.ts +58 -0
- package/dist/types/modules/escrow-v2.d.ts.map +1 -0
- package/dist/types/modules/escrow.d.ts +4 -0
- package/dist/types/modules/escrow.d.ts.map +1 -1
- package/dist/types/modules/index.d.ts +4 -0
- package/dist/types/modules/index.d.ts.map +1 -1
- package/dist/types/modules/receipt.d.ts +77 -0
- package/dist/types/modules/receipt.d.ts.map +1 -0
- package/dist/types/modules/staking.d.ts +32 -0
- package/dist/types/modules/staking.d.ts.map +1 -0
- package/dist/types/modules/subscription.d.ts +33 -0
- package/dist/types/modules/subscription.d.ts.map +1 -0
- package/dist/types/pda/index.d.ts +114 -0
- package/dist/types/pda/index.d.ts.map +1 -1
- package/dist/types/plugin/schemas.d.ts +2 -2
- package/dist/types/registries/x402.d.ts +14 -12
- package/dist/types/registries/x402.d.ts.map +1 -1
- package/dist/types/types/accounts.d.ts +201 -1
- package/dist/types/types/accounts.d.ts.map +1 -1
- package/dist/types/types/enums.d.ts +115 -0
- package/dist/types/types/enums.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +4 -4
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/types/types/instructions.d.ts +34 -0
- package/dist/types/types/instructions.d.ts.map +1 -1
- package/dist/types/utils/escrow-validation.d.ts +145 -0
- package/dist/types/utils/escrow-validation.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +6 -0
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/merchant-validator.d.ts +176 -0
- package/dist/types/utils/merchant-validator.d.ts.map +1 -0
- package/dist/types/utils/x402-direct.d.ts +114 -0
- package/dist/types/utils/x402-direct.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/constants/seeds.ts +9 -0
- package/src/core/client.ts +59 -0
- package/src/idl/synapse_agent_sap.json +8571 -4106
- package/src/index.ts +54 -0
- package/src/modules/escrow-v2.ts +375 -0
- package/src/modules/escrow.ts +4 -0
- package/src/modules/index.ts +4 -0
- package/src/modules/receipt.ts +207 -0
- package/src/modules/staking.ts +122 -0
- package/src/modules/subscription.ts +147 -0
- package/src/pda/index.ts +228 -0
- package/src/registries/x402.ts +108 -69
- package/src/types/accounts.ts +241 -1
- package/src/types/enums.ts +119 -0
- package/src/types/index.ts +20 -0
- package/src/types/instructions.ts +40 -0
- package/src/utils/escrow-validation.ts +301 -0
- package/src/utils/index.ts +28 -0
- package/src/utils/merchant-validator.ts +359 -0
- package/src/utils/x402-direct.ts +370 -0
package/dist/esm/index.js
CHANGED
|
@@ -45,13 +45,13 @@
|
|
|
45
45
|
*/
|
|
46
46
|
// ── Core ─────────────────────────────────────────────
|
|
47
47
|
export { SapClient, SapConnection, KeypairWallet } from "./core";
|
|
48
|
-
export { TokenType, PluginType, SettlementMode, ToolHttpMethod, ToolCategory, DelegatePermission, SchemaType, CompressionType, } from "./types";
|
|
48
|
+
export { TokenType, PluginType, SettlementMode, ToolHttpMethod, ToolCategory, DelegatePermission, SchemaType, CompressionType, SettlementSecurity, DisputeOutcome, BillingInterval, DisputeType, ResolutionLayer, } from "./types";
|
|
49
49
|
// ── Constants ────────────────────────────────────────
|
|
50
50
|
export { SAP_PROGRAM_ADDRESS, SAP_PROGRAM_ID, MAINNET_SAP_PROGRAM_ID, DEVNET_SAP_PROGRAM_ID, LOCALNET_SAP_PROGRAM_ID, SEEDS, LIMITS, AGENT_VERSION, VAULT_PROTOCOL_VERSION, TOOL_CATEGORY_VALUES, HTTP_METHOD_VALUES, SapNetwork, } from "./constants";
|
|
51
51
|
// ── IDL ──────────────────────────────────────────────
|
|
52
52
|
export { SAP_IDL, IDL_PROGRAM_ADDRESS, IDL_METADATA } from "./idl/index";
|
|
53
53
|
// ── PDA Derivation ───────────────────────────────────
|
|
54
|
-
export { deriveGlobalRegistry, deriveAgent, deriveAgentStats, deriveFeedback, deriveCapabilityIndex, deriveProtocolIndex, deriveToolCategoryIndex, deriveVault, deriveSession, deriveEpochPage, deriveVaultDelegate, deriveCheckpoint, deriveTool, deriveEscrow, deriveAttestation, deriveLedger, deriveLedgerPage, } from "./pda";
|
|
54
|
+
export { deriveGlobalRegistry, deriveAgent, deriveAgentStats, deriveFeedback, deriveCapabilityIndex, deriveProtocolIndex, deriveToolCategoryIndex, deriveVault, deriveSession, deriveEpochPage, deriveVaultDelegate, deriveCheckpoint, deriveTool, deriveEscrow, deriveEscrowV2, derivePendingSettlement, deriveDispute, deriveStake, deriveSubscription, deriveShard, deriveIndexPage, deriveAttestation, deriveLedger, deriveLedgerPage, deriveReceiptBatch, } from "./pda";
|
|
55
55
|
// ── Utilities ────────────────────────────────────────
|
|
56
56
|
export { sha256, hashToArray, assert } from "./utils";
|
|
57
57
|
export { serializeAccount, serializeValue } from "./utils";
|
|
@@ -65,6 +65,8 @@ export { getRpcUrl, getFallbackRpcUrl, createDualConnection, findATA, classifyAn
|
|
|
65
65
|
export { createEnvSchema, createEndpointDescriptorSchema, createHealthCheckSchema, createToolManifestEntrySchema, createAgentManifestSchema, createPreparePaymentSchema, createRegisterAgentSchema, createCallArgsSchema, validateOrThrow, } from "./utils";
|
|
66
66
|
// v0.6.2 — Priority fee & settle options
|
|
67
67
|
export { buildPriorityFeeIxs, buildRpcOptions, FAST_SETTLE_OPTIONS, FAST_BATCH_SETTLE_OPTIONS, DEFAULT_SETTLE_PRIORITY_FEE, DEFAULT_SETTLE_COMPUTE_UNITS, DEFAULT_BATCH_SETTLE_COMPUTE_UNITS, } from "./utils";
|
|
68
|
+
// v0.6.4 — Escrow validation, merchant middleware, x402 direct
|
|
69
|
+
export { validateEscrowState, attachSplAccounts, toAccountMetas, MissingEscrowAtaError, SapMerchantValidator, parseX402Headers, getX402DirectPayments, } from "./utils";
|
|
68
70
|
// ── Errors ───────────────────────────────────────────
|
|
69
71
|
export { SapError, SapValidationError, SapRpcError, SapAccountNotFoundError, SapTimeoutError, SapPermissionError, } from "./errors";
|
|
70
72
|
// ── Events ───────────────────────────────────────────
|
|
@@ -72,7 +74,7 @@ export { EventParser, SAP_EVENT_NAMES } from "./events";
|
|
|
72
74
|
// ── Geyser (Yellowstone gRPC) ────────────────────────
|
|
73
75
|
export { GeyserEventStream } from "./events/geyser";
|
|
74
76
|
// ── Modules (for advanced usage / tree-shaking) ──────
|
|
75
|
-
export { AgentModule, FeedbackModule, IndexingModule, ToolsModule, VaultModule, EscrowModule, AttestationModule, LedgerModule, BaseModule, } from "./modules/index";
|
|
77
|
+
export { AgentModule, FeedbackModule, IndexingModule, ToolsModule, VaultModule, EscrowModule, EscrowV2Module, ReceiptModule, StakingModule, SubscriptionModule, AttestationModule, LedgerModule, BaseModule, } from "./modules/index";
|
|
76
78
|
// ── Plugin (SynapseAgentKit integration) ─────────────
|
|
77
79
|
export { createSAPPlugin, SAPPlugin } from "./plugin/index";
|
|
78
80
|
export { SAP_PROTOCOLS } from "./plugin/protocols";
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH,wDAAwD;AACxD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH,wDAAwD;AACxD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AA2EjE,OAAO,EACL,SAAS,EACT,UAAU,EACV,cAAc,EACd,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,UAAU,EACV,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,WAAW,EACX,eAAe,GAChB,MAAM,SAAS,CAAC;AAEjB,wDAAwD;AACxD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,sBAAsB,EACtB,qBAAqB,EACrB,uBAAuB,EACvB,KAAK,EACL,MAAM,EACN,aAAa,EACb,sB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EACjB,YAAY,EACZ,cAAc,EACd,YAAY,GACb,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module escrow-v2
|
|
3
|
+
* @description V2 escrow settlement layer — supports settlement security
|
|
4
|
+
* modes (CoSigned, DisputeWindow), receipt-based dispute resolution,
|
|
5
|
+
* pending settlements, and automatic resolution via merkle proofs.
|
|
6
|
+
*
|
|
7
|
+
* @category Modules
|
|
8
|
+
* @since v0.7.0
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
import { SystemProgram, } from "@solana/web3.js";
|
|
12
|
+
import { BN } from "@coral-xyz/anchor";
|
|
13
|
+
import { BaseModule } from "./base";
|
|
14
|
+
import { deriveAgent, deriveAgentStats, deriveEscrowV2, derivePendingSettlement as derivePendingPda, deriveDispute as deriveDisputePda, } from "../pda";
|
|
15
|
+
import { buildPriorityFeeIxs, buildRpcOptions, } from "../utils/priority-fee";
|
|
16
|
+
/**
|
|
17
|
+
* @name EscrowV2Module
|
|
18
|
+
* @description Manages V2 escrow accounts with settlement security modes,
|
|
19
|
+
* dispute windows, and pending settlement flows.
|
|
20
|
+
*
|
|
21
|
+
* @category Modules
|
|
22
|
+
* @since v0.7.0
|
|
23
|
+
* @extends BaseModule
|
|
24
|
+
*/
|
|
25
|
+
export class EscrowV2Module extends BaseModule {
|
|
26
|
+
// ── Helpers ──────────────────────────────────────────
|
|
27
|
+
/** Convert BN | number | bigint → number for PDA seed functions. */
|
|
28
|
+
toNum(v) {
|
|
29
|
+
return BN.isBN(v) ? v.toNumber() : Number(v);
|
|
30
|
+
}
|
|
31
|
+
// ── PDA helpers ──────────────────────────────────────
|
|
32
|
+
deriveEscrow(agentPda, depositor, nonce = 0) {
|
|
33
|
+
return deriveEscrowV2(agentPda, depositor ?? this.walletPubkey, this.toNum(nonce));
|
|
34
|
+
}
|
|
35
|
+
derivePendingSettlement(escrowV2Pda, settlementIndex) {
|
|
36
|
+
return derivePendingPda(escrowV2Pda, this.toNum(settlementIndex));
|
|
37
|
+
}
|
|
38
|
+
deriveDispute(pendingSettlementPda) {
|
|
39
|
+
return deriveDisputePda(pendingSettlementPda);
|
|
40
|
+
}
|
|
41
|
+
// ── Instructions ─────────────────────────────────────
|
|
42
|
+
async create(agentWallet, args, splAccounts = []) {
|
|
43
|
+
const [agentPda] = deriveAgent(agentWallet);
|
|
44
|
+
const [escrowPda] = this.deriveEscrow(agentPda, undefined, args.escrowNonce);
|
|
45
|
+
return this.methods
|
|
46
|
+
.createEscrowV2(this.bn(args.escrowNonce), this.bn(args.pricePerCall), this.bn(args.maxCalls), this.bn(args.initialDeposit), args.expiresAt, args.volumeCurve, args.tokenMint, args.tokenDecimals, args.settlementSecurity, this.bn(args.disputeWindowSlots), args.coSigner, args.arbiter)
|
|
47
|
+
.accounts({
|
|
48
|
+
depositor: this.walletPubkey,
|
|
49
|
+
agent: agentPda,
|
|
50
|
+
escrow: escrowPda,
|
|
51
|
+
systemProgram: SystemProgram.programId,
|
|
52
|
+
})
|
|
53
|
+
.remainingAccounts(splAccounts)
|
|
54
|
+
.rpc();
|
|
55
|
+
}
|
|
56
|
+
async deposit(agentWallet, nonce, amount, splAccounts = []) {
|
|
57
|
+
const [agentPda] = deriveAgent(agentWallet);
|
|
58
|
+
const [escrowPda] = this.deriveEscrow(agentPda, undefined, nonce);
|
|
59
|
+
return this.methods
|
|
60
|
+
.depositEscrowV2(this.bn(nonce), this.bn(amount))
|
|
61
|
+
.accounts({
|
|
62
|
+
depositor: this.walletPubkey,
|
|
63
|
+
escrow: escrowPda,
|
|
64
|
+
systemProgram: SystemProgram.programId,
|
|
65
|
+
})
|
|
66
|
+
.remainingAccounts(splAccounts)
|
|
67
|
+
.rpc();
|
|
68
|
+
}
|
|
69
|
+
async settle(depositorWallet, nonce, callsToSettle, serviceHash, splAccounts = [], opts) {
|
|
70
|
+
const [agentPda] = deriveAgent(this.walletPubkey);
|
|
71
|
+
const [escrowPda] = this.deriveEscrow(agentPda, depositorWallet, nonce);
|
|
72
|
+
const [statsPda] = deriveAgentStats(agentPda);
|
|
73
|
+
const preIxs = buildPriorityFeeIxs(opts);
|
|
74
|
+
const rpcOpts = buildRpcOptions(opts);
|
|
75
|
+
let builder = this.methods
|
|
76
|
+
.settleCallsV2(this.bn(nonce), this.bn(callsToSettle), serviceHash)
|
|
77
|
+
.accounts({
|
|
78
|
+
wallet: this.walletPubkey,
|
|
79
|
+
agent: agentPda,
|
|
80
|
+
agentStats: statsPda,
|
|
81
|
+
escrow: escrowPda,
|
|
82
|
+
systemProgram: SystemProgram.programId,
|
|
83
|
+
})
|
|
84
|
+
.remainingAccounts(splAccounts);
|
|
85
|
+
if (preIxs.length > 0) {
|
|
86
|
+
builder = builder.preInstructions(preIxs);
|
|
87
|
+
}
|
|
88
|
+
return builder.rpc(rpcOpts);
|
|
89
|
+
}
|
|
90
|
+
async createPendingSettlement(agentWallet, depositorWallet, nonce, settlementIndex, callsToSettle, amount, serviceHash, receiptMerkleRoot = new Array(32).fill(0)) {
|
|
91
|
+
const [agentPda] = deriveAgent(agentWallet);
|
|
92
|
+
const [escrowPda] = this.deriveEscrow(agentPda, depositorWallet, nonce);
|
|
93
|
+
const [pendingPda] = this.derivePendingSettlement(escrowPda, settlementIndex);
|
|
94
|
+
return this.methods
|
|
95
|
+
.createPendingSettlement(this.bn(settlementIndex), this.bn(callsToSettle), this.bn(amount), serviceHash, receiptMerkleRoot)
|
|
96
|
+
.accounts({
|
|
97
|
+
wallet: this.walletPubkey,
|
|
98
|
+
agent: agentPda,
|
|
99
|
+
escrow: escrowPda,
|
|
100
|
+
pendingSettlement: pendingPda,
|
|
101
|
+
systemProgram: SystemProgram.programId,
|
|
102
|
+
})
|
|
103
|
+
.rpc();
|
|
104
|
+
}
|
|
105
|
+
async finalizeSettlement(agentWallet, depositorWallet, nonce, settlementIndex) {
|
|
106
|
+
const [agentPda] = deriveAgent(agentWallet);
|
|
107
|
+
const [escrowPda] = this.deriveEscrow(agentPda, depositorWallet, nonce);
|
|
108
|
+
const [pendingPda] = this.derivePendingSettlement(escrowPda, settlementIndex);
|
|
109
|
+
const [statsPda] = deriveAgentStats(agentPda);
|
|
110
|
+
return this.methods
|
|
111
|
+
.finalizeSettlement()
|
|
112
|
+
.accounts({
|
|
113
|
+
payer: this.walletPubkey,
|
|
114
|
+
agentWallet,
|
|
115
|
+
escrow: escrowPda,
|
|
116
|
+
pendingSettlement: pendingPda,
|
|
117
|
+
agentStats: statsPda,
|
|
118
|
+
})
|
|
119
|
+
.rpc();
|
|
120
|
+
}
|
|
121
|
+
async fileDispute(agentWallet, nonce, settlementIndex, evidenceHash, disputeType = 0) {
|
|
122
|
+
const [agentPda] = deriveAgent(agentWallet);
|
|
123
|
+
const [escrowPda] = this.deriveEscrow(agentPda, undefined, nonce);
|
|
124
|
+
const [pendingPda] = this.derivePendingSettlement(escrowPda, settlementIndex);
|
|
125
|
+
const [disputePda] = this.deriveDispute(pendingPda);
|
|
126
|
+
return this.methods
|
|
127
|
+
.fileDispute(evidenceHash, disputeType)
|
|
128
|
+
.accounts({
|
|
129
|
+
depositor: this.walletPubkey,
|
|
130
|
+
escrow: escrowPda,
|
|
131
|
+
pendingSettlement: pendingPda,
|
|
132
|
+
dispute: disputePda,
|
|
133
|
+
systemProgram: SystemProgram.programId,
|
|
134
|
+
})
|
|
135
|
+
.rpc();
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* @deprecated Since v0.7.0 — Arbiter-based resolution removed.
|
|
139
|
+
* Use {@link ReceiptModule.submitReceiptProof} + {@link ReceiptModule.autoResolveDispute} instead.
|
|
140
|
+
*/
|
|
141
|
+
async resolveDispute(_depositorWallet, _agentWallet, _nonce, _settlementIndex, _outcome) {
|
|
142
|
+
throw new Error("resolveDispute removed in v0.7.0 — use ReceiptModule.autoResolveDispute");
|
|
143
|
+
}
|
|
144
|
+
async closeDispute(pendingSettlementPda) {
|
|
145
|
+
const [disputePda] = this.deriveDispute(pendingSettlementPda);
|
|
146
|
+
return this.methods
|
|
147
|
+
.closeDispute()
|
|
148
|
+
.accounts({
|
|
149
|
+
depositor: this.walletPubkey,
|
|
150
|
+
dispute: disputePda,
|
|
151
|
+
})
|
|
152
|
+
.rpc();
|
|
153
|
+
}
|
|
154
|
+
async closePendingSettlement(pendingSettlementPda) {
|
|
155
|
+
return this.methods
|
|
156
|
+
.closePendingSettlement()
|
|
157
|
+
.accounts({
|
|
158
|
+
payer: this.walletPubkey,
|
|
159
|
+
pendingSettlement: pendingSettlementPda,
|
|
160
|
+
})
|
|
161
|
+
.rpc();
|
|
162
|
+
}
|
|
163
|
+
async withdraw(agentWallet, nonce, amount) {
|
|
164
|
+
const [agentPda] = deriveAgent(agentWallet);
|
|
165
|
+
const [escrowPda] = this.deriveEscrow(agentPda, undefined, nonce);
|
|
166
|
+
return this.methods
|
|
167
|
+
.withdrawEscrowV2(this.bn(amount))
|
|
168
|
+
.accounts({
|
|
169
|
+
depositor: this.walletPubkey,
|
|
170
|
+
escrow: escrowPda,
|
|
171
|
+
})
|
|
172
|
+
.rpc();
|
|
173
|
+
}
|
|
174
|
+
async close(agentWallet, nonce = 0) {
|
|
175
|
+
const [agentPda] = deriveAgent(agentWallet);
|
|
176
|
+
const [escrowPda] = this.deriveEscrow(agentPda, undefined, nonce);
|
|
177
|
+
return this.methods
|
|
178
|
+
.closeEscrowV2()
|
|
179
|
+
.accounts({
|
|
180
|
+
depositor: this.walletPubkey,
|
|
181
|
+
escrow: escrowPda,
|
|
182
|
+
})
|
|
183
|
+
.rpc();
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* @deprecated Since v0.7.0 — Migration instruction removed from program.
|
|
187
|
+
*/
|
|
188
|
+
async migrateFromV1(_agentWallet) {
|
|
189
|
+
throw new Error("migrateFromV1 removed in v0.7.0 — migration instruction was deleted");
|
|
190
|
+
}
|
|
191
|
+
// ── Fetchers ─────────────────────────────────────────
|
|
192
|
+
async fetch(agentPda, depositor, nonce = 0) {
|
|
193
|
+
const [pda] = this.deriveEscrow(agentPda, depositor, nonce);
|
|
194
|
+
return this.fetchAccount("escrowAccountV2", pda);
|
|
195
|
+
}
|
|
196
|
+
async fetchNullable(agentPda, depositor, nonce = 0) {
|
|
197
|
+
const [pda] = this.deriveEscrow(agentPda, depositor, nonce);
|
|
198
|
+
return this.fetchAccountNullable("escrowAccountV2", pda);
|
|
199
|
+
}
|
|
200
|
+
async fetchByPda(escrowPda) {
|
|
201
|
+
return this.fetchAccount("escrowAccountV2", escrowPda);
|
|
202
|
+
}
|
|
203
|
+
async fetchPendingSettlement(pendingPda) {
|
|
204
|
+
return this.fetchAccount("pendingSettlement", pendingPda);
|
|
205
|
+
}
|
|
206
|
+
async fetchPendingSettlementNullable(pendingPda) {
|
|
207
|
+
return this.fetchAccountNullable("pendingSettlement", pendingPda);
|
|
208
|
+
}
|
|
209
|
+
async fetchDispute(disputePda) {
|
|
210
|
+
return this.fetchAccount("disputeRecord", disputePda);
|
|
211
|
+
}
|
|
212
|
+
async fetchDisputeNullable(disputePda) {
|
|
213
|
+
return this.fetchAccountNullable("disputeRecord", disputePda);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
//# sourceMappingURL=escrow-v2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escrow-v2.js","sourceRoot":"","sources":["../../../src/modules/escrow-v2.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EACL,aAAa,GAId,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,uBAAuB,IAAI,gBAAgB,EAC3C,aAAa,IAAI,gBAAgB,GAClC,MAAM,QAAQ,CAAC;AAOhB,OAAO,EACL,mBAAmB,EACnB,eAAe,GAChB,MAAM,uB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AK,CAAC,CAAC;QAC5D,OAAO,IAAI,CAAC,YAAY,CAAsB,iBAAiB,EAAE,GAAG,CAAC,CAAC;IACxE,CAAC;IAED,KAAK,CAAC,aAAa,CACjB,QAAmB,EACnB,SAAqB,EACrB,QAA8B,CAAC;QAE/B,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;QAC5D,OAAO,IAAI,CAAC,oBAAoB,CAAsB,iBAAiB,EAAE,GAAG,CAAC,CAAC;IAChF,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,SAAoB;QACnC,OAAO,IAAI,CAAC,YAAY,CAAsB,iBAAiB,EAAE,SAAS,CAAC,CAAC;IAC9E,CAAC;IAED,KAAK,CAAC,sBAAsB,CAC1B,UAAqB;QAErB,OAAO,IAAI,CAAC,YAAY,CAAwB,mBAAmB,EAAE,UAAU,CAAC,CAAC;IACnF,CAAC;IAED,KAAK,CAAC,8BAA8B,CAClC,UAAqB;QAErB,OAAO,IAAI,CAAC,oBAAoB,CAAwB,mBAAmB,EAAE,UAAU,CAAC,CAAC;IAC3F,CAAC;IAED,KAAK,CAAC,YAAY,CAChB,UAAqB;QAErB,OAAO,IAAI,CAAC,YAAY,CAAoB,eAAe,EAAE,UAAU,CAAC,CAAC;IAC3E,CAAC;IAED,KAAK,CAAC,oBAAoB,CACxB,UAAqB;QAErB,OAAO,IAAI,CAAC,oBAAoB,CAAoB,eAAe,EAAE,UAAU,CAAC,CAAC;IACnF,CAAC;CACF"}
|
|
@@ -38,6 +38,10 @@ import { buildPriorityFeeIxs, buildRpcOptions, } from "../utils/priority-fee";
|
|
|
38
38
|
* tokenDecimals: null,
|
|
39
39
|
* });
|
|
40
40
|
* ```
|
|
41
|
+
*
|
|
42
|
+
* @deprecated Since v0.7.0 — Use {@link EscrowV2Module} (`client.escrowV2`) instead.
|
|
43
|
+
* V1 escrows lack settlement security, dispute resolution, and staking integration.
|
|
44
|
+
* Existing V1 escrows can be migrated via `client.escrowV2.migrateFromV1()`.
|
|
41
45
|
*/
|
|
42
46
|
export class EscrowModule extends BaseModule {
|
|
43
47
|
// ── PDA helpers ──────────────────────────────────────
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"escrow.js","sourceRoot":"","sources":["../../../src/modules/escrow.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,aAAa,GAId,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,YAAY,GACb,MAAM,QAAQ,CAAC;AAMhB,OAAO,EACL,mBAAmB,EACnB,eAAe,GAChB,MAAM,uBAAuB,CAAC;AAG/B
|
|
1
|
+
{"version":3,"file":"escrow.js","sourceRoot":"","sources":["../../../src/modules/escrow.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,aAAa,GAId,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,YAAY,GACb,MAAM,QAAQ,CAAC;AAMhB,OAAO,EACL,mBAAmB,EACnB,eAAe,GAChB,MAAM,uBAAuB,CAAC;AAG/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,OAAO,YAAa,SAAQ,UAAU;IAC1C,wDAAwD;IAExD;;;;;;;;OAQG;IACH,YAAY,CACV,QAAmB,EACnB,SAAqB;QAErB,OAAO,YAAY,CAAC,QAAQ,EAAE,SAAS,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC;IAChE,CAAC;IAED,wDAAwD;IAExD;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,MAAM,CACV,WAAsB,EACtB,IAAsB,EACtB,cAA6B,EAAE;QAE/B,MAAM,CAAC,QAAQ,CAAC,GAAG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,SAAS;YACjB,aAAa,EAAE,aAAa,CAAC,SAAS;SACvC,CAAC;aACD,iBAAiB,CAAC,WAAW,CAAC,CAAC;QAElC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,OAAO,GAAG,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;QAC5C,CAAC;QAED,OAAO,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC9B,CAAC;IAED,wDAAwD;IAExD;;;;;;;;OAQG;IACH,KAAK,CAAC,KAAK,CAAC,QAAmB,EAAE,SAAqB;QACpD,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QACrD,OAAO,IAAI,CAAC,YAAY,CAAoB,eAAe,EAAE,GAAG,CAAC,CAAC;IACpE,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,aAAa,CAAC,QAAmB,EAAE,SAAqB;QAC5D,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QACrD,OAAO,IAAI,CAAC,oBAAoB,CAAoB,eAAe,EAAE,GAAG,CAAC,CAAC;IAC5E,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,UAAU,CAAC,SAAoB;QACnC,OAAO,IAAI,CAAC,YAAY,CAAoB,eAAe,EAAE,SAAS,CAAC,CAAC;IAC1E,CAAC;CACF"}
|
|
@@ -17,6 +17,10 @@ export { IndexingModule } from "./indexing";
|
|
|
17
17
|
export { ToolsModule } from "./tools";
|
|
18
18
|
export { VaultModule } from "./vault";
|
|
19
19
|
export { EscrowModule } from "./escrow";
|
|
20
|
+
export { EscrowV2Module } from "./escrow-v2";
|
|
21
|
+
export { ReceiptModule } from "./receipt";
|
|
22
|
+
export { StakingModule } from "./staking";
|
|
23
|
+
export { SubscriptionModule } from "./subscription";
|
|
20
24
|
export { AttestationModule } from "./attestation";
|
|
21
25
|
export { LedgerModule } from "./ledger";
|
|
22
26
|
export { BaseModule } from "./base";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module receipt
|
|
3
|
+
* @description Receipt-based trustless dispute resolution (v0.7).
|
|
4
|
+
*
|
|
5
|
+
* Agents inscribe merkle roots of call receipt batches on-chain.
|
|
6
|
+
* During disputes, agents submit merkle inclusion proofs to prove delivery.
|
|
7
|
+
* After the proof deadline, anyone can trigger automatic proportional resolution.
|
|
8
|
+
*
|
|
9
|
+
* @category Modules
|
|
10
|
+
* @since v0.7.0
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
import { SystemProgram, } from "@solana/web3.js";
|
|
14
|
+
import { BN } from "@coral-xyz/anchor";
|
|
15
|
+
import { BaseModule } from "./base";
|
|
16
|
+
import { deriveAgent, deriveAgentStats, deriveEscrowV2, derivePendingSettlement as derivePendingPda, deriveDispute as deriveDisputePda, deriveReceiptBatch as deriveReceiptPda, } from "../pda";
|
|
17
|
+
/**
|
|
18
|
+
* @name ReceiptModule
|
|
19
|
+
* @description Manages receipt batch inscriptions, merkle proof submissions,
|
|
20
|
+
* and automatic dispute resolution for the v0.7 trustless settlement layer.
|
|
21
|
+
*
|
|
22
|
+
* @category Modules
|
|
23
|
+
* @since v0.7.0
|
|
24
|
+
* @extends BaseModule
|
|
25
|
+
*/
|
|
26
|
+
export class ReceiptModule extends BaseModule {
|
|
27
|
+
// ── Helpers ──────────────────────────────────────────
|
|
28
|
+
toNum(v) {
|
|
29
|
+
return BN.isBN(v) ? v.toNumber() : Number(v);
|
|
30
|
+
}
|
|
31
|
+
// ── PDA helpers ──────────────────────────────────────
|
|
32
|
+
deriveReceiptBatch(escrowV2Pda, batchIndex) {
|
|
33
|
+
return deriveReceiptPda(escrowV2Pda, batchIndex);
|
|
34
|
+
}
|
|
35
|
+
// ── Instructions ─────────────────────────────────────
|
|
36
|
+
/**
|
|
37
|
+
* Inscribe a receipt batch merkle root on-chain.
|
|
38
|
+
*
|
|
39
|
+
* Called by the **agent** to commit a cryptographic proof of calls delivered.
|
|
40
|
+
* The `merkleRoot` is the root of a merkle tree whose leaves are individual
|
|
41
|
+
* call receipt hashes.
|
|
42
|
+
*
|
|
43
|
+
* @param depositorWallet - The depositor's wallet (needed for escrow PDA derivation).
|
|
44
|
+
* @param nonce - Escrow nonce.
|
|
45
|
+
* @param batchIndex - Zero-based batch index (must equal escrow.receipt_batch_count).
|
|
46
|
+
* @param merkleRoot - 32-byte merkle root of the receipt batch.
|
|
47
|
+
* @param callCount - Number of calls in the batch.
|
|
48
|
+
* @param periodStart - Unix timestamp for the start of the covered period.
|
|
49
|
+
* @param periodEnd - Unix timestamp for the end of the covered period.
|
|
50
|
+
*/
|
|
51
|
+
async inscribeReceiptBatch(depositorWallet, nonce, batchIndex, merkleRoot, callCount, periodStart, periodEnd) {
|
|
52
|
+
const [agentPda] = deriveAgent(this.walletPubkey);
|
|
53
|
+
const [escrowPda] = deriveEscrowV2(agentPda, depositorWallet, this.toNum(nonce));
|
|
54
|
+
const [receiptPda] = this.deriveReceiptBatch(escrowPda, batchIndex);
|
|
55
|
+
return this.methods
|
|
56
|
+
.inscribeReceiptBatch(batchIndex, merkleRoot, this.bn(callCount), this.bn(periodStart), this.bn(periodEnd))
|
|
57
|
+
.accounts({
|
|
58
|
+
wallet: this.walletPubkey,
|
|
59
|
+
agent: agentPda,
|
|
60
|
+
escrow: escrowPda,
|
|
61
|
+
receiptBatch: receiptPda,
|
|
62
|
+
systemProgram: SystemProgram.programId,
|
|
63
|
+
})
|
|
64
|
+
.rpc();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Submit a merkle inclusion proof during a dispute.
|
|
68
|
+
*
|
|
69
|
+
* Called by the **agent** to prove delivery of specific calls.
|
|
70
|
+
* Each proof verifies that a set of receipt hashes are included
|
|
71
|
+
* in the previously inscribed merkle root.
|
|
72
|
+
*
|
|
73
|
+
* @param depositorWallet - The depositor's wallet.
|
|
74
|
+
* @param nonce - Escrow nonce.
|
|
75
|
+
* @param settlementIndex - Index of the disputed pending settlement.
|
|
76
|
+
* @param batchIndex - Receipt batch index containing the proof.
|
|
77
|
+
* @param provenCount - Number of calls proven in this proof submission.
|
|
78
|
+
* @param proof - Array of 32-byte merkle proof hashes.
|
|
79
|
+
* @param leaf - The 32-byte leaf hash being proven.
|
|
80
|
+
*/
|
|
81
|
+
async submitReceiptProof(depositorWallet, nonce, settlementIndex, batchIndex, provenCount, proof, leaf) {
|
|
82
|
+
const [agentPda] = deriveAgent(this.walletPubkey);
|
|
83
|
+
const [escrowPda] = deriveEscrowV2(agentPda, depositorWallet, this.toNum(nonce));
|
|
84
|
+
const [pendingPda] = derivePendingPda(escrowPda, this.toNum(settlementIndex));
|
|
85
|
+
const [disputePda] = deriveDisputePda(pendingPda);
|
|
86
|
+
const [receiptPda] = this.deriveReceiptBatch(escrowPda, batchIndex);
|
|
87
|
+
return this.methods
|
|
88
|
+
.submitReceiptProof(batchIndex, this.bn(provenCount), proof, leaf)
|
|
89
|
+
.accounts({
|
|
90
|
+
wallet: this.walletPubkey,
|
|
91
|
+
agent: agentPda,
|
|
92
|
+
escrow: escrowPda,
|
|
93
|
+
pendingSettlement: pendingPda,
|
|
94
|
+
dispute: disputePda,
|
|
95
|
+
receiptBatch: receiptPda,
|
|
96
|
+
})
|
|
97
|
+
.rpc();
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Trigger automatic dispute resolution after the proof deadline.
|
|
101
|
+
*
|
|
102
|
+
* Permissionless crank — anyone can call this once the deadline has passed.
|
|
103
|
+
* Resolution is proportional: if the agent proved N of M claimed calls,
|
|
104
|
+
* N/M of the settlement amount goes to the agent, the rest is refunded.
|
|
105
|
+
*
|
|
106
|
+
* @param agentWallet - The agent's wallet.
|
|
107
|
+
* @param depositorWallet - The depositor's wallet.
|
|
108
|
+
* @param nonce - Escrow nonce.
|
|
109
|
+
* @param settlementIndex - Index of the disputed pending settlement.
|
|
110
|
+
*/
|
|
111
|
+
async autoResolveDispute(agentWallet, depositorWallet, nonce, settlementIndex) {
|
|
112
|
+
const [agentPda] = deriveAgent(agentWallet);
|
|
113
|
+
const [escrowPda] = deriveEscrowV2(agentPda, depositorWallet, this.toNum(nonce));
|
|
114
|
+
const [pendingPda] = derivePendingPda(escrowPda, this.toNum(settlementIndex));
|
|
115
|
+
const [disputePda] = deriveDisputePda(pendingPda);
|
|
116
|
+
const [statsPda] = deriveAgentStats(agentPda);
|
|
117
|
+
return this.methods
|
|
118
|
+
.autoResolveDispute()
|
|
119
|
+
.accounts({
|
|
120
|
+
payer: this.walletPubkey,
|
|
121
|
+
depositor: depositorWallet,
|
|
122
|
+
agentWallet,
|
|
123
|
+
escrow: escrowPda,
|
|
124
|
+
pendingSettlement: pendingPda,
|
|
125
|
+
dispute: disputePda,
|
|
126
|
+
agentStats: statsPda,
|
|
127
|
+
})
|
|
128
|
+
.rpc();
|
|
129
|
+
}
|
|
130
|
+
// ── Fetchers ─────────────────────────────────────────
|
|
131
|
+
async fetchReceiptBatch(escrowV2Pda, batchIndex) {
|
|
132
|
+
const [pda] = this.deriveReceiptBatch(escrowV2Pda, batchIndex);
|
|
133
|
+
return this.fetchAccount("receiptBatch", pda);
|
|
134
|
+
}
|
|
135
|
+
async fetchReceiptBatchNullable(escrowV2Pda, batchIndex) {
|
|
136
|
+
const [pda] = this.deriveReceiptBatch(escrowV2Pda, batchIndex);
|
|
137
|
+
return this.fetchAccountNullable("receiptBatch", pda);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=receipt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"receipt.js","sourceRoot":"","sources":["../../../src/modules/receipt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL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AE,UAAU,CAAC,CAAC;QAC/D,OAAO,IAAI,CAAC,oBAAoB,CAAmB,cAAc,EAAE,GAAG,CAAC,CAAC;IAC1E,CAAC;CACF"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module staking
|
|
3
|
+
* @description Agent staking lifecycle — init, deposit, request unstake,
|
|
4
|
+
* complete unstake, and fetch stake accounts.
|
|
5
|
+
*
|
|
6
|
+
* @category Modules
|
|
7
|
+
* @since v0.7.0
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
import { SystemProgram, } from "@solana/web3.js";
|
|
11
|
+
import { BaseModule } from "./base";
|
|
12
|
+
import { deriveAgent, deriveStake } from "../pda";
|
|
13
|
+
/**
|
|
14
|
+
* @name StakingModule
|
|
15
|
+
* @description Manages agent stake accounts — init, deposit, unstake, and fetch.
|
|
16
|
+
*
|
|
17
|
+
* @category Modules
|
|
18
|
+
* @since v0.7.0
|
|
19
|
+
* @extends BaseModule
|
|
20
|
+
*/
|
|
21
|
+
export class StakingModule extends BaseModule {
|
|
22
|
+
// ── PDA helpers ──────────────────────────────────────
|
|
23
|
+
deriveStake(agentPda) {
|
|
24
|
+
return deriveStake(agentPda);
|
|
25
|
+
}
|
|
26
|
+
// ── Instructions ─────────────────────────────────────
|
|
27
|
+
async initStake(agentWallet, initialDeposit) {
|
|
28
|
+
const [agentPda] = deriveAgent(agentWallet);
|
|
29
|
+
const [stakePda] = this.deriveStake(agentPda);
|
|
30
|
+
return this.methods
|
|
31
|
+
.initStake(this.bn(initialDeposit))
|
|
32
|
+
.accounts({
|
|
33
|
+
wallet: this.walletPubkey,
|
|
34
|
+
agent: agentPda,
|
|
35
|
+
stake: stakePda,
|
|
36
|
+
systemProgram: SystemProgram.programId,
|
|
37
|
+
})
|
|
38
|
+
.rpc();
|
|
39
|
+
}
|
|
40
|
+
async deposit(agentWallet, amount) {
|
|
41
|
+
const [agentPda] = deriveAgent(agentWallet);
|
|
42
|
+
const [stakePda] = this.deriveStake(agentPda);
|
|
43
|
+
return this.methods
|
|
44
|
+
.depositStake(this.bn(amount))
|
|
45
|
+
.accounts({
|
|
46
|
+
wallet: this.walletPubkey,
|
|
47
|
+
agent: agentPda,
|
|
48
|
+
stake: stakePda,
|
|
49
|
+
systemProgram: SystemProgram.programId,
|
|
50
|
+
})
|
|
51
|
+
.rpc();
|
|
52
|
+
}
|
|
53
|
+
async requestUnstake(agentWallet, amount) {
|
|
54
|
+
const [agentPda] = deriveAgent(agentWallet);
|
|
55
|
+
const [stakePda] = this.deriveStake(agentPda);
|
|
56
|
+
return this.methods
|
|
57
|
+
.requestUnstake(this.bn(amount))
|
|
58
|
+
.accounts({
|
|
59
|
+
wallet: this.walletPubkey,
|
|
60
|
+
agent: agentPda,
|
|
61
|
+
stake: stakePda,
|
|
62
|
+
})
|
|
63
|
+
.rpc();
|
|
64
|
+
}
|
|
65
|
+
async completeUnstake(agentWallet) {
|
|
66
|
+
const [agentPda] = deriveAgent(agentWallet);
|
|
67
|
+
const [stakePda] = this.deriveStake(agentPda);
|
|
68
|
+
return this.methods
|
|
69
|
+
.completeUnstake()
|
|
70
|
+
.accounts({
|
|
71
|
+
wallet: this.walletPubkey,
|
|
72
|
+
agent: agentPda,
|
|
73
|
+
stake: stakePda,
|
|
74
|
+
})
|
|
75
|
+
.rpc();
|
|
76
|
+
}
|
|
77
|
+
// ── Fetchers ─────────────────────────────────────────
|
|
78
|
+
async fetch(agentPda) {
|
|
79
|
+
const [pda] = this.deriveStake(agentPda);
|
|
80
|
+
return this.fetchAccount("agentStake", pda);
|
|
81
|
+
}
|
|
82
|
+
async fetchNullable(agentPda) {
|
|
83
|
+
const [pda] = this.deriveStake(agentPda);
|
|
84
|
+
return this.fetchAccountNullable("agentStake", pda);
|
|
85
|
+
}
|
|
86
|
+
async fetchByPda(stakePda) {
|
|
87
|
+
return this.fetchAccount("agentStake", stakePda);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//#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