@elisym/sdk 0.10.4 → 0.11.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/README.md +32 -0
- package/dist/agent-store.cjs.map +1 -1
- package/dist/agent-store.js.map +1 -1
- package/dist/index.cjs +109 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +69 -7
- package/dist/index.d.ts +69 -7
- package/dist/index.js +108 -28
- package/dist/index.js.map +1 -1
- package/dist/skills.cjs.map +1 -1
- package/dist/skills.js.map +1 -1
- package/package.json +3 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Address, TransactionSigner, Rpc, SolanaRpcApi } from '@solana/kit';
|
|
1
|
+
import { Address, TransactionSigner, Rpc, SolanaRpcApi, Signature } from '@solana/kit';
|
|
2
2
|
import { Filter, Event } from 'nostr-tools';
|
|
3
3
|
import { A as Asset } from './assets-C-nzSYD4.cjs';
|
|
4
4
|
export { C as Chain, K as KNOWN_ASSETS, N as NATIVE_SOL, U as USDC_SOLANA_DEVNET, a as assetByKey, b as assetKey, f as formatAssetAmount, p as parseAssetAmount, r as resolveAssetFromPaymentRequest, c as resolveKnownAsset } from './assets-C-nzSYD4.cjs';
|
|
@@ -183,8 +183,6 @@ interface PaymentValidationError {
|
|
|
183
183
|
message: string;
|
|
184
184
|
}
|
|
185
185
|
interface NetworkStats {
|
|
186
|
-
totalAgentCount: number;
|
|
187
|
-
agentCount: number;
|
|
188
186
|
jobCount: number;
|
|
189
187
|
totalLamports: number;
|
|
190
188
|
}
|
|
@@ -285,6 +283,14 @@ interface BuildTransactionOptions {
|
|
|
285
283
|
* quartile (default), 90 = aggressive.
|
|
286
284
|
*/
|
|
287
285
|
priorityFeePercentile?: number;
|
|
286
|
+
/**
|
|
287
|
+
* Nostr job request event id (hex) to embed in an SPL Memo instruction
|
|
288
|
+
* with payload `elisym:v1:<jobEventId>`. Off-chain indexers join the memo
|
|
289
|
+
* back to the originating job for per-provider/per-capability analytics.
|
|
290
|
+
* Memo is omitted when this option is absent; the protocol tag is still
|
|
291
|
+
* attached either way.
|
|
292
|
+
*/
|
|
293
|
+
jobEventId?: string;
|
|
288
294
|
}
|
|
289
295
|
|
|
290
296
|
declare class NostrPool {
|
|
@@ -358,8 +364,6 @@ declare function compareAgentsByRank(a: Agent, b: Agent): number;
|
|
|
358
364
|
declare class DiscoveryService {
|
|
359
365
|
private pool;
|
|
360
366
|
constructor(pool: NostrPool);
|
|
361
|
-
/** Count elisym agents (kind:31990 with "elisym" tag). */
|
|
362
|
-
fetchAllAgentCount(): Promise<number>;
|
|
363
367
|
/**
|
|
364
368
|
* Fetch a single page of elisym agents with relay-side pagination.
|
|
365
369
|
* Uses `until` cursor for Nostr cursor-based pagination.
|
|
@@ -591,12 +595,24 @@ declare class SolanaPaymentStrategy implements PaymentStrategy {
|
|
|
591
595
|
* extra read-only account (canonical Solana Pay pattern);
|
|
592
596
|
* 4. `TransferChecked` from payer ATA to treasury ATA if a fee applies.
|
|
593
597
|
*
|
|
598
|
+
* Every provider transfer instruction also carries `ELISYM_PROTOCOL_TAG` as a
|
|
599
|
+
* read-only marker account so off-chain indexers can enumerate every elisym
|
|
600
|
+
* transaction with a single `getSignaturesForAddress(ELISYM_PROTOCOL_TAG)`
|
|
601
|
+
* call, regardless of fee size.
|
|
602
|
+
*
|
|
603
|
+
* If `options.jobEventId` is provided, an SPL Memo instruction with payload
|
|
604
|
+
* `elisym:v1:<jobEventId>` is prepended so explorers display the originating
|
|
605
|
+
* Nostr job id and indexers can join on-chain payments back to off-chain
|
|
606
|
+
* job context.
|
|
607
|
+
*
|
|
594
608
|
* Async because SPL ATAs are PDAs and `findAssociatedTokenPda` is async.
|
|
595
609
|
*
|
|
596
610
|
* Caller is responsible for validating `paymentRequest` upstream;
|
|
597
611
|
* `buildTransaction` already does that before invoking this helper.
|
|
598
612
|
*/
|
|
599
|
-
declare function buildPaymentInstructions(paymentRequest: PaymentRequestData, payerSigner: Signer
|
|
613
|
+
declare function buildPaymentInstructions(paymentRequest: PaymentRequestData, payerSigner: Signer, options?: {
|
|
614
|
+
jobEventId?: string;
|
|
615
|
+
}): Promise<readonly unknown[]>;
|
|
600
616
|
/**
|
|
601
617
|
* Convenience wrapper: fetch the on-chain protocol config first, then build a
|
|
602
618
|
* payment request using its current fee/treasury values.
|
|
@@ -838,6 +854,40 @@ interface QuickVerifyResult {
|
|
|
838
854
|
declare function clearQuickVerifyCache(): void;
|
|
839
855
|
declare function verifyJobPaymentQuick(rpc: Rpc<SolanaRpcApi>, txSignature: string, expectedRecipient: Address): Promise<QuickVerifyResult>;
|
|
840
856
|
|
|
857
|
+
/**
|
|
858
|
+
* Aggregated on-chain stats across the entire elisym network. Volume is
|
|
859
|
+
* keyed by `'native'` for SOL or by SPL mint address; values are subunits
|
|
860
|
+
* (lamports for native, raw token units for SPL).
|
|
861
|
+
*/
|
|
862
|
+
interface NetworkStatsResult {
|
|
863
|
+
jobCount: number;
|
|
864
|
+
volumeByAsset: Record<string, bigint>;
|
|
865
|
+
/** Most-recent signature returned by the RPC (use as cursor for forward sync). */
|
|
866
|
+
latestSignature?: string;
|
|
867
|
+
/** Oldest signature scanned in this batch (use as `before` for next page). */
|
|
868
|
+
oldestSignature?: string;
|
|
869
|
+
}
|
|
870
|
+
interface AggregateNetworkStatsOptions {
|
|
871
|
+
/** Cap on signatures fetched in one call. Defaults to 1000 (RPC max). */
|
|
872
|
+
limit?: number;
|
|
873
|
+
/** Page backwards from this signature for historical scans. */
|
|
874
|
+
before?: Signature;
|
|
875
|
+
/** Parallel `getTransaction` calls. Defaults to `DEFAULTS.QUERY_MAX_CONCURRENCY`. */
|
|
876
|
+
concurrency?: number;
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* Enumerate every elisym payment transaction reachable from the protocol tag
|
|
880
|
+
* pubkey and aggregate gross volume + count.
|
|
881
|
+
*
|
|
882
|
+
* Implementation detail: for SPL txs we sum positive token-balance deltas per
|
|
883
|
+
* mint (ignores ATA rent that would inflate native lamport deltas in the same
|
|
884
|
+
* tx). For native SOL txs we sum positive lamport deltas across all non-payer
|
|
885
|
+
* accounts - elisym native txs only emit provider + optional fee transfers,
|
|
886
|
+
* so this equals gross volume. The `tx_fee` paid by the fee-payer never shows
|
|
887
|
+
* up as a positive delta, so it is naturally excluded.
|
|
888
|
+
*/
|
|
889
|
+
declare function aggregateNetworkStats(rpc: Rpc<SolanaRpcApi>, options?: AggregateNetworkStatsOptions): Promise<NetworkStatsResult>;
|
|
890
|
+
|
|
841
891
|
/**
|
|
842
892
|
* Snapshot of the on-chain elisym-config program state.
|
|
843
893
|
*
|
|
@@ -1015,6 +1065,18 @@ declare const PROTOCOL_TREASURY: Address;
|
|
|
1015
1065
|
* treasury address, and admin rotation state. Read via `getProtocolConfig`.
|
|
1016
1066
|
*/
|
|
1017
1067
|
declare const PROTOCOL_PROGRAM_ID_DEVNET: Address;
|
|
1068
|
+
/**
|
|
1069
|
+
* Read-only marker pubkey attached as a non-signer account to every elisym
|
|
1070
|
+
* payment transaction. Lets indexers enumerate every elisym tx network-wide
|
|
1071
|
+
* via a single `getSignaturesForAddress(ELISYM_PROTOCOL_TAG)` call,
|
|
1072
|
+
* independent of fee size or recipient.
|
|
1073
|
+
*
|
|
1074
|
+
* The account does not need to exist on-chain; including its pubkey as an
|
|
1075
|
+
* extra read-only account in the provider transfer instruction is enough for
|
|
1076
|
+
* Solana's tx-by-account index to pick it up. The corresponding secret key
|
|
1077
|
+
* was generated and discarded - the tag never signs and never holds funds.
|
|
1078
|
+
*/
|
|
1079
|
+
declare const ELISYM_PROTOCOL_TAG: Address;
|
|
1018
1080
|
type ProtocolCluster = 'devnet' | 'mainnet' | 'localnet';
|
|
1019
1081
|
/**
|
|
1020
1082
|
* Resolve the elisym-config program ID for a given Solana cluster.
|
|
@@ -1050,4 +1112,4 @@ declare const LIMITS: {
|
|
|
1050
1112
|
readonly MAX_CAPABILITY_LENGTH: 64;
|
|
1051
1113
|
};
|
|
1052
1114
|
|
|
1053
|
-
export { type Agent, Asset, BoundedSet, type BuildTransactionOptions, type CapabilityCard, DEFAULTS, DEFAULT_KIND_OFFSET, DEFAULT_REDACT_PATHS, DiscoveryService, ElisymClient, type ElisymClientConfig, type ElisymClientFullConfig, ElisymIdentity, type EstimatePriorityFeeOptions, type EstimateSolFeeOptions, type GetProtocolConfigOptions, INPUT_REDACT_PATHS, type Job, type JobStatus, type JobSubscriptionOptions, type JobUpdateCallbacks, KIND_APP_HANDLER, KIND_JOB_FEEDBACK, KIND_JOB_REQUEST, KIND_JOB_REQUEST_BASE, KIND_JOB_RESULT, KIND_JOB_RESULT_BASE, KIND_PING, KIND_PONG, LAMPORTS_PER_SOL, LIMITS, MarketplaceService, MediaService, type Network, type NetworkStats, NostrPool, PROTOCOL_FEE_BPS, PROTOCOL_PROGRAM_ID_DEVNET, PROTOCOL_TREASURY, type ParseOptions, type ParseResult, type ParsedPaymentRequest, type PaymentAssetRef, type PaymentInfo, type PaymentRequestData, PaymentRequestSchema, type PaymentStrategy, type PaymentValidationCode, type PaymentValidationError, type PingResult, PingService, type ProtocolCluster, type ProtocolConfig, type ProtocolConfigInput, type QuickVerifyReason, type QuickVerifyResult, RELAYS, type RankKey, type RateLimitDecision, SECRET_REDACT_PATHS, type Signer, type SlidingWindowLimiter, type SlidingWindowLimiterOptions, type SolFeeEstimate, SolanaPaymentStrategy, type SubCloser, type SubmitJobOptions, type VerifyOptions, type VerifyResult, assertExpiry, assertLamports, buildPaymentInstructions, calculateProtocolFee, clearPriorityFeeCache, clearProtocolConfigCache, clearQuickVerifyCache, compareAgentsByRank, computeRankKey, createPaymentRequestWithOnchainConfig, createSlidingWindowLimiter, estimatePriorityFeeMicroLamports, estimateSolFeeLamports, formatFeeBreakdown, formatSol, getProtocolConfig, getProtocolProgramId, jobRequestKind, jobResultKind, makeCensor, nip44Decrypt, nip44Encrypt, parsePaymentRequest, pickPercentileFee, timeAgo, toDTag, truncateKey, validateAgentName, validateExpiry, verifyJobPaymentQuick };
|
|
1115
|
+
export { type Agent, type AggregateNetworkStatsOptions, Asset, BoundedSet, type BuildTransactionOptions, type CapabilityCard, DEFAULTS, DEFAULT_KIND_OFFSET, DEFAULT_REDACT_PATHS, DiscoveryService, ELISYM_PROTOCOL_TAG, ElisymClient, type ElisymClientConfig, type ElisymClientFullConfig, ElisymIdentity, type EstimatePriorityFeeOptions, type EstimateSolFeeOptions, type GetProtocolConfigOptions, INPUT_REDACT_PATHS, type Job, type JobStatus, type JobSubscriptionOptions, type JobUpdateCallbacks, KIND_APP_HANDLER, KIND_JOB_FEEDBACK, KIND_JOB_REQUEST, KIND_JOB_REQUEST_BASE, KIND_JOB_RESULT, KIND_JOB_RESULT_BASE, KIND_PING, KIND_PONG, LAMPORTS_PER_SOL, LIMITS, MarketplaceService, MediaService, type Network, type NetworkStats, type NetworkStatsResult, NostrPool, PROTOCOL_FEE_BPS, PROTOCOL_PROGRAM_ID_DEVNET, PROTOCOL_TREASURY, type ParseOptions, type ParseResult, type ParsedPaymentRequest, type PaymentAssetRef, type PaymentInfo, type PaymentRequestData, PaymentRequestSchema, type PaymentStrategy, type PaymentValidationCode, type PaymentValidationError, type PingResult, PingService, type ProtocolCluster, type ProtocolConfig, type ProtocolConfigInput, type QuickVerifyReason, type QuickVerifyResult, RELAYS, type RankKey, type RateLimitDecision, SECRET_REDACT_PATHS, type Signer, type SlidingWindowLimiter, type SlidingWindowLimiterOptions, type SolFeeEstimate, SolanaPaymentStrategy, type SubCloser, type SubmitJobOptions, type VerifyOptions, type VerifyResult, aggregateNetworkStats, assertExpiry, assertLamports, buildPaymentInstructions, calculateProtocolFee, clearPriorityFeeCache, clearProtocolConfigCache, clearQuickVerifyCache, compareAgentsByRank, computeRankKey, createPaymentRequestWithOnchainConfig, createSlidingWindowLimiter, estimatePriorityFeeMicroLamports, estimateSolFeeLamports, formatFeeBreakdown, formatSol, getProtocolConfig, getProtocolProgramId, jobRequestKind, jobResultKind, makeCensor, nip44Decrypt, nip44Encrypt, parsePaymentRequest, pickPercentileFee, timeAgo, toDTag, truncateKey, validateAgentName, validateExpiry, verifyJobPaymentQuick };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Address, TransactionSigner, Rpc, SolanaRpcApi } from '@solana/kit';
|
|
1
|
+
import { Address, TransactionSigner, Rpc, SolanaRpcApi, Signature } from '@solana/kit';
|
|
2
2
|
import { Filter, Event } from 'nostr-tools';
|
|
3
3
|
import { A as Asset } from './assets-C-nzSYD4.js';
|
|
4
4
|
export { C as Chain, K as KNOWN_ASSETS, N as NATIVE_SOL, U as USDC_SOLANA_DEVNET, a as assetByKey, b as assetKey, f as formatAssetAmount, p as parseAssetAmount, r as resolveAssetFromPaymentRequest, c as resolveKnownAsset } from './assets-C-nzSYD4.js';
|
|
@@ -183,8 +183,6 @@ interface PaymentValidationError {
|
|
|
183
183
|
message: string;
|
|
184
184
|
}
|
|
185
185
|
interface NetworkStats {
|
|
186
|
-
totalAgentCount: number;
|
|
187
|
-
agentCount: number;
|
|
188
186
|
jobCount: number;
|
|
189
187
|
totalLamports: number;
|
|
190
188
|
}
|
|
@@ -285,6 +283,14 @@ interface BuildTransactionOptions {
|
|
|
285
283
|
* quartile (default), 90 = aggressive.
|
|
286
284
|
*/
|
|
287
285
|
priorityFeePercentile?: number;
|
|
286
|
+
/**
|
|
287
|
+
* Nostr job request event id (hex) to embed in an SPL Memo instruction
|
|
288
|
+
* with payload `elisym:v1:<jobEventId>`. Off-chain indexers join the memo
|
|
289
|
+
* back to the originating job for per-provider/per-capability analytics.
|
|
290
|
+
* Memo is omitted when this option is absent; the protocol tag is still
|
|
291
|
+
* attached either way.
|
|
292
|
+
*/
|
|
293
|
+
jobEventId?: string;
|
|
288
294
|
}
|
|
289
295
|
|
|
290
296
|
declare class NostrPool {
|
|
@@ -358,8 +364,6 @@ declare function compareAgentsByRank(a: Agent, b: Agent): number;
|
|
|
358
364
|
declare class DiscoveryService {
|
|
359
365
|
private pool;
|
|
360
366
|
constructor(pool: NostrPool);
|
|
361
|
-
/** Count elisym agents (kind:31990 with "elisym" tag). */
|
|
362
|
-
fetchAllAgentCount(): Promise<number>;
|
|
363
367
|
/**
|
|
364
368
|
* Fetch a single page of elisym agents with relay-side pagination.
|
|
365
369
|
* Uses `until` cursor for Nostr cursor-based pagination.
|
|
@@ -591,12 +595,24 @@ declare class SolanaPaymentStrategy implements PaymentStrategy {
|
|
|
591
595
|
* extra read-only account (canonical Solana Pay pattern);
|
|
592
596
|
* 4. `TransferChecked` from payer ATA to treasury ATA if a fee applies.
|
|
593
597
|
*
|
|
598
|
+
* Every provider transfer instruction also carries `ELISYM_PROTOCOL_TAG` as a
|
|
599
|
+
* read-only marker account so off-chain indexers can enumerate every elisym
|
|
600
|
+
* transaction with a single `getSignaturesForAddress(ELISYM_PROTOCOL_TAG)`
|
|
601
|
+
* call, regardless of fee size.
|
|
602
|
+
*
|
|
603
|
+
* If `options.jobEventId` is provided, an SPL Memo instruction with payload
|
|
604
|
+
* `elisym:v1:<jobEventId>` is prepended so explorers display the originating
|
|
605
|
+
* Nostr job id and indexers can join on-chain payments back to off-chain
|
|
606
|
+
* job context.
|
|
607
|
+
*
|
|
594
608
|
* Async because SPL ATAs are PDAs and `findAssociatedTokenPda` is async.
|
|
595
609
|
*
|
|
596
610
|
* Caller is responsible for validating `paymentRequest` upstream;
|
|
597
611
|
* `buildTransaction` already does that before invoking this helper.
|
|
598
612
|
*/
|
|
599
|
-
declare function buildPaymentInstructions(paymentRequest: PaymentRequestData, payerSigner: Signer
|
|
613
|
+
declare function buildPaymentInstructions(paymentRequest: PaymentRequestData, payerSigner: Signer, options?: {
|
|
614
|
+
jobEventId?: string;
|
|
615
|
+
}): Promise<readonly unknown[]>;
|
|
600
616
|
/**
|
|
601
617
|
* Convenience wrapper: fetch the on-chain protocol config first, then build a
|
|
602
618
|
* payment request using its current fee/treasury values.
|
|
@@ -838,6 +854,40 @@ interface QuickVerifyResult {
|
|
|
838
854
|
declare function clearQuickVerifyCache(): void;
|
|
839
855
|
declare function verifyJobPaymentQuick(rpc: Rpc<SolanaRpcApi>, txSignature: string, expectedRecipient: Address): Promise<QuickVerifyResult>;
|
|
840
856
|
|
|
857
|
+
/**
|
|
858
|
+
* Aggregated on-chain stats across the entire elisym network. Volume is
|
|
859
|
+
* keyed by `'native'` for SOL or by SPL mint address; values are subunits
|
|
860
|
+
* (lamports for native, raw token units for SPL).
|
|
861
|
+
*/
|
|
862
|
+
interface NetworkStatsResult {
|
|
863
|
+
jobCount: number;
|
|
864
|
+
volumeByAsset: Record<string, bigint>;
|
|
865
|
+
/** Most-recent signature returned by the RPC (use as cursor for forward sync). */
|
|
866
|
+
latestSignature?: string;
|
|
867
|
+
/** Oldest signature scanned in this batch (use as `before` for next page). */
|
|
868
|
+
oldestSignature?: string;
|
|
869
|
+
}
|
|
870
|
+
interface AggregateNetworkStatsOptions {
|
|
871
|
+
/** Cap on signatures fetched in one call. Defaults to 1000 (RPC max). */
|
|
872
|
+
limit?: number;
|
|
873
|
+
/** Page backwards from this signature for historical scans. */
|
|
874
|
+
before?: Signature;
|
|
875
|
+
/** Parallel `getTransaction` calls. Defaults to `DEFAULTS.QUERY_MAX_CONCURRENCY`. */
|
|
876
|
+
concurrency?: number;
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* Enumerate every elisym payment transaction reachable from the protocol tag
|
|
880
|
+
* pubkey and aggregate gross volume + count.
|
|
881
|
+
*
|
|
882
|
+
* Implementation detail: for SPL txs we sum positive token-balance deltas per
|
|
883
|
+
* mint (ignores ATA rent that would inflate native lamport deltas in the same
|
|
884
|
+
* tx). For native SOL txs we sum positive lamport deltas across all non-payer
|
|
885
|
+
* accounts - elisym native txs only emit provider + optional fee transfers,
|
|
886
|
+
* so this equals gross volume. The `tx_fee` paid by the fee-payer never shows
|
|
887
|
+
* up as a positive delta, so it is naturally excluded.
|
|
888
|
+
*/
|
|
889
|
+
declare function aggregateNetworkStats(rpc: Rpc<SolanaRpcApi>, options?: AggregateNetworkStatsOptions): Promise<NetworkStatsResult>;
|
|
890
|
+
|
|
841
891
|
/**
|
|
842
892
|
* Snapshot of the on-chain elisym-config program state.
|
|
843
893
|
*
|
|
@@ -1015,6 +1065,18 @@ declare const PROTOCOL_TREASURY: Address;
|
|
|
1015
1065
|
* treasury address, and admin rotation state. Read via `getProtocolConfig`.
|
|
1016
1066
|
*/
|
|
1017
1067
|
declare const PROTOCOL_PROGRAM_ID_DEVNET: Address;
|
|
1068
|
+
/**
|
|
1069
|
+
* Read-only marker pubkey attached as a non-signer account to every elisym
|
|
1070
|
+
* payment transaction. Lets indexers enumerate every elisym tx network-wide
|
|
1071
|
+
* via a single `getSignaturesForAddress(ELISYM_PROTOCOL_TAG)` call,
|
|
1072
|
+
* independent of fee size or recipient.
|
|
1073
|
+
*
|
|
1074
|
+
* The account does not need to exist on-chain; including its pubkey as an
|
|
1075
|
+
* extra read-only account in the provider transfer instruction is enough for
|
|
1076
|
+
* Solana's tx-by-account index to pick it up. The corresponding secret key
|
|
1077
|
+
* was generated and discarded - the tag never signs and never holds funds.
|
|
1078
|
+
*/
|
|
1079
|
+
declare const ELISYM_PROTOCOL_TAG: Address;
|
|
1018
1080
|
type ProtocolCluster = 'devnet' | 'mainnet' | 'localnet';
|
|
1019
1081
|
/**
|
|
1020
1082
|
* Resolve the elisym-config program ID for a given Solana cluster.
|
|
@@ -1050,4 +1112,4 @@ declare const LIMITS: {
|
|
|
1050
1112
|
readonly MAX_CAPABILITY_LENGTH: 64;
|
|
1051
1113
|
};
|
|
1052
1114
|
|
|
1053
|
-
export { type Agent, Asset, BoundedSet, type BuildTransactionOptions, type CapabilityCard, DEFAULTS, DEFAULT_KIND_OFFSET, DEFAULT_REDACT_PATHS, DiscoveryService, ElisymClient, type ElisymClientConfig, type ElisymClientFullConfig, ElisymIdentity, type EstimatePriorityFeeOptions, type EstimateSolFeeOptions, type GetProtocolConfigOptions, INPUT_REDACT_PATHS, type Job, type JobStatus, type JobSubscriptionOptions, type JobUpdateCallbacks, KIND_APP_HANDLER, KIND_JOB_FEEDBACK, KIND_JOB_REQUEST, KIND_JOB_REQUEST_BASE, KIND_JOB_RESULT, KIND_JOB_RESULT_BASE, KIND_PING, KIND_PONG, LAMPORTS_PER_SOL, LIMITS, MarketplaceService, MediaService, type Network, type NetworkStats, NostrPool, PROTOCOL_FEE_BPS, PROTOCOL_PROGRAM_ID_DEVNET, PROTOCOL_TREASURY, type ParseOptions, type ParseResult, type ParsedPaymentRequest, type PaymentAssetRef, type PaymentInfo, type PaymentRequestData, PaymentRequestSchema, type PaymentStrategy, type PaymentValidationCode, type PaymentValidationError, type PingResult, PingService, type ProtocolCluster, type ProtocolConfig, type ProtocolConfigInput, type QuickVerifyReason, type QuickVerifyResult, RELAYS, type RankKey, type RateLimitDecision, SECRET_REDACT_PATHS, type Signer, type SlidingWindowLimiter, type SlidingWindowLimiterOptions, type SolFeeEstimate, SolanaPaymentStrategy, type SubCloser, type SubmitJobOptions, type VerifyOptions, type VerifyResult, assertExpiry, assertLamports, buildPaymentInstructions, calculateProtocolFee, clearPriorityFeeCache, clearProtocolConfigCache, clearQuickVerifyCache, compareAgentsByRank, computeRankKey, createPaymentRequestWithOnchainConfig, createSlidingWindowLimiter, estimatePriorityFeeMicroLamports, estimateSolFeeLamports, formatFeeBreakdown, formatSol, getProtocolConfig, getProtocolProgramId, jobRequestKind, jobResultKind, makeCensor, nip44Decrypt, nip44Encrypt, parsePaymentRequest, pickPercentileFee, timeAgo, toDTag, truncateKey, validateAgentName, validateExpiry, verifyJobPaymentQuick };
|
|
1115
|
+
export { type Agent, type AggregateNetworkStatsOptions, Asset, BoundedSet, type BuildTransactionOptions, type CapabilityCard, DEFAULTS, DEFAULT_KIND_OFFSET, DEFAULT_REDACT_PATHS, DiscoveryService, ELISYM_PROTOCOL_TAG, ElisymClient, type ElisymClientConfig, type ElisymClientFullConfig, ElisymIdentity, type EstimatePriorityFeeOptions, type EstimateSolFeeOptions, type GetProtocolConfigOptions, INPUT_REDACT_PATHS, type Job, type JobStatus, type JobSubscriptionOptions, type JobUpdateCallbacks, KIND_APP_HANDLER, KIND_JOB_FEEDBACK, KIND_JOB_REQUEST, KIND_JOB_REQUEST_BASE, KIND_JOB_RESULT, KIND_JOB_RESULT_BASE, KIND_PING, KIND_PONG, LAMPORTS_PER_SOL, LIMITS, MarketplaceService, MediaService, type Network, type NetworkStats, type NetworkStatsResult, NostrPool, PROTOCOL_FEE_BPS, PROTOCOL_PROGRAM_ID_DEVNET, PROTOCOL_TREASURY, type ParseOptions, type ParseResult, type ParsedPaymentRequest, type PaymentAssetRef, type PaymentInfo, type PaymentRequestData, PaymentRequestSchema, type PaymentStrategy, type PaymentValidationCode, type PaymentValidationError, type PingResult, PingService, type ProtocolCluster, type ProtocolConfig, type ProtocolConfigInput, type QuickVerifyReason, type QuickVerifyResult, RELAYS, type RankKey, type RateLimitDecision, SECRET_REDACT_PATHS, type Signer, type SlidingWindowLimiter, type SlidingWindowLimiterOptions, type SolFeeEstimate, SolanaPaymentStrategy, type SubCloser, type SubmitJobOptions, type VerifyOptions, type VerifyResult, aggregateNetworkStats, assertExpiry, assertLamports, buildPaymentInstructions, calculateProtocolFee, clearPriorityFeeCache, clearProtocolConfigCache, clearQuickVerifyCache, compareAgentsByRank, computeRankKey, createPaymentRequestWithOnchainConfig, createSlidingWindowLimiter, estimatePriorityFeeMicroLamports, estimateSolFeeLamports, formatFeeBreakdown, formatSol, getProtocolConfig, getProtocolProgramId, jobRequestKind, jobResultKind, makeCensor, nip44Decrypt, nip44Encrypt, parsePaymentRequest, pickPercentileFee, timeAgo, toDTag, truncateKey, validateAgentName, validateExpiry, verifyJobPaymentQuick };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getAddMemoInstruction } from '@solana-program/memo';
|
|
1
2
|
import { getTransferSolInstruction } from '@solana-program/system';
|
|
2
3
|
import { findAssociatedTokenPda, TOKEN_PROGRAM_ADDRESS, getCreateAssociatedTokenIdempotentInstruction, ASSOCIATED_TOKEN_PROGRAM_ADDRESS, getTransferCheckedInstruction } from '@solana-program/token';
|
|
3
4
|
import { pipe, createTransactionMessage, setTransactionMessageFeePayerSigner, setTransactionMessageLifetimeUsingBlockhash, setTransactionMessageComputeUnitLimit, setTransactionMessageComputeUnitPrice, appendTransactionMessageInstructions, signTransactionMessageWithSigners, address, AccountRole, isAddress, getProgramDerivedAddress, assertAccountExists, getAddressDecoder, fetchEncodedAccount, decodeAccount, getStructDecoder, fixDecoderSize, getBytesDecoder, getU8Decoder, getOptionDecoder, getU16Decoder, getBooleanDecoder, getI64Decoder } from '@solana/kit';
|
|
@@ -39,6 +40,7 @@ var LAMPORTS_PER_SOL = 1e9;
|
|
|
39
40
|
var PROTOCOL_FEE_BPS = 300;
|
|
40
41
|
var PROTOCOL_TREASURY = "GY7vnWMkKpftU4nQ16C2ATkj1JwrQpHhknkaBUn67VTy";
|
|
41
42
|
var PROTOCOL_PROGRAM_ID_DEVNET = "BrX1CRkSgvcjxBvc2bgc3QqgWjinusofDmeP7ZVxvwrE";
|
|
43
|
+
var ELISYM_PROTOCOL_TAG = "ELiZksgwDt41LaeuPDLkUfWgFXhGgVayTMP7L5nTSEL8";
|
|
42
44
|
function getProtocolProgramId(cluster) {
|
|
43
45
|
switch (cluster) {
|
|
44
46
|
case "devnet":
|
|
@@ -94,13 +96,13 @@ function decodeConfig(encodedAccount) {
|
|
|
94
96
|
getConfigDecoder()
|
|
95
97
|
);
|
|
96
98
|
}
|
|
97
|
-
async function fetchConfig(rpc,
|
|
98
|
-
const maybeAccount = await fetchMaybeConfig(rpc,
|
|
99
|
+
async function fetchConfig(rpc, address4, config) {
|
|
100
|
+
const maybeAccount = await fetchMaybeConfig(rpc, address4, config);
|
|
99
101
|
assertAccountExists(maybeAccount);
|
|
100
102
|
return maybeAccount;
|
|
101
103
|
}
|
|
102
|
-
async function fetchMaybeConfig(rpc,
|
|
103
|
-
const maybeAccount = await fetchEncodedAccount(rpc,
|
|
104
|
+
async function fetchMaybeConfig(rpc, address4, config) {
|
|
105
|
+
const maybeAccount = await fetchEncodedAccount(rpc, address4, config);
|
|
104
106
|
return decodeConfig(maybeAccount);
|
|
105
107
|
}
|
|
106
108
|
if (process.env.NODE_ENV !== "production") ;
|
|
@@ -572,7 +574,9 @@ var SolanaPaymentStrategy = class {
|
|
|
572
574
|
if (!Number.isInteger(computeUnitLimit) || computeUnitLimit <= 0) {
|
|
573
575
|
throw new Error(`Invalid computeUnitLimit: ${computeUnitLimit}. Must be a positive integer.`);
|
|
574
576
|
}
|
|
575
|
-
const paymentInstructions = await buildPaymentInstructions(paymentRequest, payerSigner
|
|
577
|
+
const paymentInstructions = await buildPaymentInstructions(paymentRequest, payerSigner, {
|
|
578
|
+
jobEventId: options?.jobEventId
|
|
579
|
+
});
|
|
576
580
|
const priorityFeeMicroLamports = options?.priorityFeeMicroLamports ?? await estimatePriorityFeeMicroLamports(rpc, {
|
|
577
581
|
percentile: options?.priorityFeePercentile ?? DEFAULT_PRIORITY_FEE_PERCENTILE
|
|
578
582
|
});
|
|
@@ -869,9 +873,10 @@ function bigIntDelta(post, pre) {
|
|
|
869
873
|
function waitMs(ms) {
|
|
870
874
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
871
875
|
}
|
|
872
|
-
async function buildPaymentInstructions(paymentRequest, payerSigner) {
|
|
876
|
+
async function buildPaymentInstructions(paymentRequest, payerSigner, options) {
|
|
873
877
|
const recipient = address(paymentRequest.recipient);
|
|
874
878
|
const reference = address(paymentRequest.reference);
|
|
879
|
+
const protocolTag = address(ELISYM_PROTOCOL_TAG);
|
|
875
880
|
const feeAmount = paymentRequest.fee_amount ?? 0;
|
|
876
881
|
const providerAmount = paymentRequest.fee_address && feeAmount > 0 ? paymentRequest.amount - feeAmount : paymentRequest.amount;
|
|
877
882
|
if (providerAmount <= 0) {
|
|
@@ -879,6 +884,7 @@ async function buildPaymentInstructions(paymentRequest, payerSigner) {
|
|
|
879
884
|
`Fee amount (${feeAmount}) exceeds or equals total amount (${paymentRequest.amount}). Cannot create transaction with non-positive provider amount.`
|
|
880
885
|
);
|
|
881
886
|
}
|
|
887
|
+
const memoInstruction = options?.jobEventId ? getAddMemoInstruction({ memo: `elisym:v1:${options.jobEventId}` }) : null;
|
|
882
888
|
const asset = resolveAssetFromPaymentRequest(paymentRequest);
|
|
883
889
|
if (!asset.mint) {
|
|
884
890
|
const providerTransferIx2 = getTransferSolInstruction({
|
|
@@ -886,14 +892,19 @@ async function buildPaymentInstructions(paymentRequest, payerSigner) {
|
|
|
886
892
|
destination: recipient,
|
|
887
893
|
amount: BigInt(providerAmount)
|
|
888
894
|
});
|
|
889
|
-
const
|
|
895
|
+
const providerTransferIxWithMarkers2 = {
|
|
890
896
|
...providerTransferIx2,
|
|
891
897
|
accounts: [
|
|
892
898
|
...providerTransferIx2.accounts,
|
|
893
|
-
{ address: reference, role: AccountRole.READONLY }
|
|
899
|
+
{ address: reference, role: AccountRole.READONLY },
|
|
900
|
+
{ address: protocolTag, role: AccountRole.READONLY }
|
|
894
901
|
]
|
|
895
902
|
};
|
|
896
|
-
const instructions2 = [
|
|
903
|
+
const instructions2 = [];
|
|
904
|
+
if (memoInstruction) {
|
|
905
|
+
instructions2.push(memoInstruction);
|
|
906
|
+
}
|
|
907
|
+
instructions2.push(providerTransferIxWithMarkers2);
|
|
897
908
|
if (paymentRequest.fee_address && feeAmount > 0) {
|
|
898
909
|
instructions2.push(
|
|
899
910
|
getTransferSolInstruction({
|
|
@@ -918,6 +929,9 @@ async function buildPaymentInstructions(paymentRequest, payerSigner) {
|
|
|
918
929
|
mint
|
|
919
930
|
});
|
|
920
931
|
const instructions = [];
|
|
932
|
+
if (memoInstruction) {
|
|
933
|
+
instructions.push(memoInstruction);
|
|
934
|
+
}
|
|
921
935
|
instructions.push(
|
|
922
936
|
getCreateAssociatedTokenIdempotentInstruction(
|
|
923
937
|
{
|
|
@@ -957,11 +971,15 @@ async function buildPaymentInstructions(paymentRequest, payerSigner) {
|
|
|
957
971
|
amount: BigInt(providerAmount),
|
|
958
972
|
decimals: asset.decimals
|
|
959
973
|
});
|
|
960
|
-
const
|
|
974
|
+
const providerTransferIxWithMarkers = {
|
|
961
975
|
...providerTransferIx,
|
|
962
|
-
accounts: [
|
|
976
|
+
accounts: [
|
|
977
|
+
...providerTransferIx.accounts,
|
|
978
|
+
{ address: reference, role: AccountRole.READONLY },
|
|
979
|
+
{ address: protocolTag, role: AccountRole.READONLY }
|
|
980
|
+
]
|
|
963
981
|
};
|
|
964
|
-
instructions.push(
|
|
982
|
+
instructions.push(providerTransferIxWithMarkers);
|
|
965
983
|
if (treasuryAta && paymentRequest.fee_address && feeAmount > 0) {
|
|
966
984
|
instructions.push(
|
|
967
985
|
getTransferCheckedInstruction({
|
|
@@ -1116,21 +1134,6 @@ var DiscoveryService = class {
|
|
|
1116
1134
|
constructor(pool) {
|
|
1117
1135
|
this.pool = pool;
|
|
1118
1136
|
}
|
|
1119
|
-
/** Count elisym agents (kind:31990 with "elisym" tag). */
|
|
1120
|
-
async fetchAllAgentCount() {
|
|
1121
|
-
const events = await this.pool.querySync({
|
|
1122
|
-
kinds: [KIND_APP_HANDLER],
|
|
1123
|
-
"#t": ["elisym"]
|
|
1124
|
-
});
|
|
1125
|
-
const uniquePubkeys = /* @__PURE__ */ new Set();
|
|
1126
|
-
for (const event of events) {
|
|
1127
|
-
if (!verifyEvent(event)) {
|
|
1128
|
-
continue;
|
|
1129
|
-
}
|
|
1130
|
-
uniquePubkeys.add(event.pubkey);
|
|
1131
|
-
}
|
|
1132
|
-
return uniquePubkeys.size;
|
|
1133
|
-
}
|
|
1134
1137
|
/**
|
|
1135
1138
|
* Fetch a single page of elisym agents with relay-side pagination.
|
|
1136
1139
|
* Uses `until` cursor for Nostr cursor-based pagination.
|
|
@@ -2893,6 +2896,83 @@ async function doVerifyOnce(rpc, txSignature, expectedRecipient) {
|
|
|
2893
2896
|
}
|
|
2894
2897
|
return { verified: false, txSignature: sigStr, reason: "recipient_mismatch" };
|
|
2895
2898
|
}
|
|
2899
|
+
var DEFAULT_LIMIT = 1e3;
|
|
2900
|
+
var NATIVE_KEY = "native";
|
|
2901
|
+
async function aggregateNetworkStats(rpc, options) {
|
|
2902
|
+
const limit = options?.limit ?? DEFAULT_LIMIT;
|
|
2903
|
+
const concurrency = options?.concurrency ?? DEFAULTS.QUERY_MAX_CONCURRENCY;
|
|
2904
|
+
const tag = address(ELISYM_PROTOCOL_TAG);
|
|
2905
|
+
const signatures = await rpc.getSignaturesForAddress(tag, { limit, before: options?.before }).send();
|
|
2906
|
+
const validSigs = signatures.filter((entry) => entry.err === null);
|
|
2907
|
+
if (validSigs.length === 0) {
|
|
2908
|
+
return { jobCount: 0, volumeByAsset: {} };
|
|
2909
|
+
}
|
|
2910
|
+
const volumeByAsset = {};
|
|
2911
|
+
let jobCount = 0;
|
|
2912
|
+
for (let start = 0; start < validSigs.length; start += concurrency) {
|
|
2913
|
+
const batch = validSigs.slice(start, start + concurrency);
|
|
2914
|
+
const txResults = await Promise.all(
|
|
2915
|
+
batch.map(
|
|
2916
|
+
(entry) => rpc.getTransaction(entry.signature, {
|
|
2917
|
+
commitment: "confirmed",
|
|
2918
|
+
encoding: "json",
|
|
2919
|
+
maxSupportedTransactionVersion: 0
|
|
2920
|
+
}).send().catch(() => null)
|
|
2921
|
+
)
|
|
2922
|
+
);
|
|
2923
|
+
for (const tx of txResults) {
|
|
2924
|
+
if (!tx?.meta || tx.meta.err) {
|
|
2925
|
+
continue;
|
|
2926
|
+
}
|
|
2927
|
+
jobCount += 1;
|
|
2928
|
+
accumulateTransfers(tx, volumeByAsset);
|
|
2929
|
+
}
|
|
2930
|
+
}
|
|
2931
|
+
const latest = validSigs[0]?.signature;
|
|
2932
|
+
const oldest = validSigs.at(-1)?.signature;
|
|
2933
|
+
return {
|
|
2934
|
+
jobCount,
|
|
2935
|
+
volumeByAsset,
|
|
2936
|
+
latestSignature: latest,
|
|
2937
|
+
oldestSignature: oldest
|
|
2938
|
+
};
|
|
2939
|
+
}
|
|
2940
|
+
function accumulateTransfers(tx, volumeByAsset) {
|
|
2941
|
+
const raw = tx;
|
|
2942
|
+
const meta = raw.meta;
|
|
2943
|
+
if (!meta) {
|
|
2944
|
+
return;
|
|
2945
|
+
}
|
|
2946
|
+
const preTokens = meta.preTokenBalances ?? [];
|
|
2947
|
+
const postTokens = meta.postTokenBalances ?? [];
|
|
2948
|
+
const isSpl = postTokens.length > 0 || preTokens.length > 0;
|
|
2949
|
+
if (isSpl) {
|
|
2950
|
+
accumulateSplDeltas(preTokens, postTokens, volumeByAsset);
|
|
2951
|
+
return;
|
|
2952
|
+
}
|
|
2953
|
+
accumulateNativeDeltas(meta.preBalances, meta.postBalances, volumeByAsset);
|
|
2954
|
+
}
|
|
2955
|
+
function accumulateSplDeltas(pre, post, volumeByAsset) {
|
|
2956
|
+
for (const postEntry of post) {
|
|
2957
|
+
const preEntry = pre.find((entry) => entry.accountIndex === postEntry.accountIndex);
|
|
2958
|
+
const preAmount = preEntry ? BigInt(preEntry.uiTokenAmount.amount) : 0n;
|
|
2959
|
+
const postAmount = BigInt(postEntry.uiTokenAmount.amount);
|
|
2960
|
+
const delta = postAmount - preAmount;
|
|
2961
|
+
if (delta > 0n) {
|
|
2962
|
+
volumeByAsset[postEntry.mint] = (volumeByAsset[postEntry.mint] ?? 0n) + delta;
|
|
2963
|
+
}
|
|
2964
|
+
}
|
|
2965
|
+
}
|
|
2966
|
+
function accumulateNativeDeltas(pre, post, volumeByAsset) {
|
|
2967
|
+
for (let i = 1; i < post.length; i++) {
|
|
2968
|
+
const preValue = pre[i] ?? 0n;
|
|
2969
|
+
const postValue = post[i] ?? 0n;
|
|
2970
|
+
const delta = BigInt(postValue) - BigInt(preValue);
|
|
2971
|
+
if (delta > 0n) {
|
|
2972
|
+
volumeByAsset[NATIVE_KEY] = (volumeByAsset[NATIVE_KEY] ?? 0n) + delta;
|
|
2973
|
+
}
|
|
2974
|
+
}
|
|
2975
|
+
}
|
|
2896
2976
|
var SessionSpendLimitEntrySchema = z.object({
|
|
2897
2977
|
chain: z.enum(["solana"]),
|
|
2898
2978
|
token: z.string().min(1).max(16).regex(/^[a-z0-9]+$/, "token must be lowercase alphanumeric"),
|
|
@@ -3093,6 +3173,6 @@ function makeCensor() {
|
|
|
3093
3173
|
};
|
|
3094
3174
|
}
|
|
3095
3175
|
|
|
3096
|
-
export { BoundedSet, DEFAULTS, DEFAULT_KIND_OFFSET, DEFAULT_REDACT_PATHS, DiscoveryService, ElisymClient, ElisymIdentity, GlobalConfigSchema, INPUT_REDACT_PATHS, KIND_APP_HANDLER, KIND_JOB_FEEDBACK, KIND_JOB_REQUEST, KIND_JOB_REQUEST_BASE, KIND_JOB_RESULT, KIND_JOB_RESULT_BASE, KIND_PING, KIND_PONG, KNOWN_ASSETS, LAMPORTS_PER_SOL, LIMITS, MarketplaceService, MediaService, NATIVE_SOL, NostrPool, PROTOCOL_FEE_BPS, PROTOCOL_PROGRAM_ID_DEVNET, PROTOCOL_TREASURY, PaymentRequestSchema, PingService, RELAYS, SECRET_REDACT_PATHS, SessionSpendLimitEntrySchema, SolanaPaymentStrategy, USDC_SOLANA_DEVNET, assertExpiry, assertLamports, assetByKey, assetKey, buildPaymentInstructions, calculateProtocolFee, clearPriorityFeeCache, clearProtocolConfigCache, clearQuickVerifyCache, compareAgentsByRank, computeRankKey, createPaymentRequestWithOnchainConfig, createSlidingWindowLimiter, estimatePriorityFeeMicroLamports, estimateSolFeeLamports, formatAssetAmount, formatFeeBreakdown, formatSol, getProtocolConfig, getProtocolProgramId, jobRequestKind, jobResultKind, makeCensor, nip44Decrypt, nip44Encrypt, parseAssetAmount, parsePaymentRequest, pickPercentileFee, resolveAssetFromPaymentRequest, resolveKnownAsset, timeAgo, toDTag, truncateKey, validateAgentName, validateExpiry, verifyJobPaymentQuick };
|
|
3176
|
+
export { BoundedSet, DEFAULTS, DEFAULT_KIND_OFFSET, DEFAULT_REDACT_PATHS, DiscoveryService, ELISYM_PROTOCOL_TAG, ElisymClient, ElisymIdentity, GlobalConfigSchema, INPUT_REDACT_PATHS, KIND_APP_HANDLER, KIND_JOB_FEEDBACK, KIND_JOB_REQUEST, KIND_JOB_REQUEST_BASE, KIND_JOB_RESULT, KIND_JOB_RESULT_BASE, KIND_PING, KIND_PONG, KNOWN_ASSETS, LAMPORTS_PER_SOL, LIMITS, MarketplaceService, MediaService, NATIVE_SOL, NostrPool, PROTOCOL_FEE_BPS, PROTOCOL_PROGRAM_ID_DEVNET, PROTOCOL_TREASURY, PaymentRequestSchema, PingService, RELAYS, SECRET_REDACT_PATHS, SessionSpendLimitEntrySchema, SolanaPaymentStrategy, USDC_SOLANA_DEVNET, aggregateNetworkStats, assertExpiry, assertLamports, assetByKey, assetKey, buildPaymentInstructions, calculateProtocolFee, clearPriorityFeeCache, clearProtocolConfigCache, clearQuickVerifyCache, compareAgentsByRank, computeRankKey, createPaymentRequestWithOnchainConfig, createSlidingWindowLimiter, estimatePriorityFeeMicroLamports, estimateSolFeeLamports, formatAssetAmount, formatFeeBreakdown, formatSol, getProtocolConfig, getProtocolProgramId, jobRequestKind, jobResultKind, makeCensor, nip44Decrypt, nip44Encrypt, parseAssetAmount, parsePaymentRequest, pickPercentileFee, resolveAssetFromPaymentRequest, resolveKnownAsset, timeAgo, toDTag, truncateKey, validateAgentName, validateExpiry, verifyJobPaymentQuick };
|
|
3097
3177
|
//# sourceMappingURL=index.js.map
|
|
3098
3178
|
//# sourceMappingURL=index.js.map
|