@elisym/sdk 0.14.0 → 0.15.1
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/index.cjs +144 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +27 -45
- package/dist/index.d.ts +27 -45
- package/dist/index.js +144 -3
- package/dist/index.js.map +1 -1
- package/dist/llm-health.cjs +426 -0
- package/dist/llm-health.cjs.map +1 -0
- package/dist/llm-health.d.cts +179 -0
- package/dist/llm-health.d.ts +179 -0
- package/dist/llm-health.js +410 -0
- package/dist/llm-health.js.map +1 -0
- package/dist/rateLimiter-CoEmZkSX.d.cts +45 -0
- package/dist/rateLimiter-CoEmZkSX.d.ts +45 -0
- package/dist/skills.cjs +40 -4
- package/dist/skills.cjs.map +1 -1
- package/dist/skills.d.cts +30 -1
- package/dist/skills.d.ts +30 -1
- package/dist/skills.js +40 -4
- package/dist/skills.js.map +1 -1
- package/dist/types-8vJ1I2KQ.d.cts +66 -0
- package/dist/types-8vJ1I2KQ.d.ts +66 -0
- package/package.json +11 -1
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var kit = require('@solana/kit');
|
|
3
4
|
var memo = require('@solana-program/memo');
|
|
4
5
|
var system = require('@solana-program/system');
|
|
5
6
|
var token = require('@solana-program/token');
|
|
6
|
-
var kit = require('@solana/kit');
|
|
7
7
|
var Decimal3 = require('decimal.js-light');
|
|
8
8
|
var zod = require('zod');
|
|
9
9
|
var nostrTools = require('nostr-tools');
|
|
@@ -128,8 +128,107 @@ async function fetchMaybeConfig(rpc, address4, config) {
|
|
|
128
128
|
const maybeAccount = await kit.fetchEncodedAccount(rpc, address4, config);
|
|
129
129
|
return decodeConfig(maybeAccount);
|
|
130
130
|
}
|
|
131
|
+
function getNetworkStatsDecoder() {
|
|
132
|
+
return kit.getStructDecoder([
|
|
133
|
+
["discriminator", kit.fixDecoderSize(kit.getBytesDecoder(), 8)],
|
|
134
|
+
["version", kit.getU8Decoder()],
|
|
135
|
+
["bump", kit.getU8Decoder()],
|
|
136
|
+
["jobCount", kit.getU64Decoder()],
|
|
137
|
+
["volumeNative", kit.getU128Decoder()],
|
|
138
|
+
["volumeUsdc", kit.getU128Decoder()],
|
|
139
|
+
["lastUpdated", kit.getI64Decoder()],
|
|
140
|
+
["reserved", kit.fixDecoderSize(kit.getBytesDecoder(), 128)]
|
|
141
|
+
]);
|
|
142
|
+
}
|
|
143
|
+
function decodeNetworkStats(encodedAccount) {
|
|
144
|
+
return kit.decodeAccount(
|
|
145
|
+
encodedAccount,
|
|
146
|
+
getNetworkStatsDecoder()
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
async function fetchMaybeNetworkStats(rpc, address4, config) {
|
|
150
|
+
const maybeAccount = await kit.fetchEncodedAccount(rpc, address4, config);
|
|
151
|
+
return decodeNetworkStats(maybeAccount);
|
|
152
|
+
}
|
|
153
|
+
var ELISYM_CONFIG_PROGRAM_ADDRESS = "BrX1CRkSgvcjxBvc2bgc3QqgWjinusofDmeP7ZVxvwrE";
|
|
131
154
|
if (process.env.NODE_ENV !== "production") ;
|
|
155
|
+
function expectAddress(value) {
|
|
156
|
+
if (!value) {
|
|
157
|
+
throw new Error("Expected a Address.");
|
|
158
|
+
}
|
|
159
|
+
if (typeof value === "object" && "address" in value) {
|
|
160
|
+
return value.address;
|
|
161
|
+
}
|
|
162
|
+
if (Array.isArray(value)) {
|
|
163
|
+
return value[0];
|
|
164
|
+
}
|
|
165
|
+
return value;
|
|
166
|
+
}
|
|
167
|
+
function getAccountMetaFactory(programAddress, optionalAccountStrategy) {
|
|
168
|
+
return (account) => {
|
|
169
|
+
if (!account.value) {
|
|
170
|
+
return Object.freeze({
|
|
171
|
+
address: programAddress,
|
|
172
|
+
role: kit.AccountRole.READONLY
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
const writableRole = account.isWritable ? kit.AccountRole.WRITABLE : kit.AccountRole.READONLY;
|
|
176
|
+
return Object.freeze({
|
|
177
|
+
address: expectAddress(account.value),
|
|
178
|
+
role: isTransactionSigner(account.value) ? kit.upgradeRoleToSigner(writableRole) : writableRole,
|
|
179
|
+
...isTransactionSigner(account.value) ? { signer: account.value } : {}
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function isTransactionSigner(value) {
|
|
184
|
+
return !!value && typeof value === "object" && "address" in value && kit.isTransactionSigner(value);
|
|
185
|
+
}
|
|
186
|
+
var INCREMENT_STATS_DISCRIMINATOR = new Uint8Array([
|
|
187
|
+
145,
|
|
188
|
+
78,
|
|
189
|
+
96,
|
|
190
|
+
206,
|
|
191
|
+
45,
|
|
192
|
+
21,
|
|
193
|
+
111,
|
|
194
|
+
175
|
|
195
|
+
]);
|
|
196
|
+
function getIncrementStatsInstructionDataEncoder() {
|
|
197
|
+
return kit.transformEncoder(
|
|
198
|
+
kit.getStructEncoder([
|
|
199
|
+
["discriminator", kit.fixEncoderSize(kit.getBytesEncoder(), 8)],
|
|
200
|
+
["amount", kit.getU64Encoder()],
|
|
201
|
+
["isNative", kit.getBooleanEncoder()]
|
|
202
|
+
]),
|
|
203
|
+
(value) => ({ ...value, discriminator: INCREMENT_STATS_DISCRIMINATOR })
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
function getIncrementStatsInstruction(input, config) {
|
|
207
|
+
const programAddress = config?.programAddress ?? ELISYM_CONFIG_PROGRAM_ADDRESS;
|
|
208
|
+
const originalAccounts = {
|
|
209
|
+
stats: { value: input.stats ?? null, isWritable: true },
|
|
210
|
+
eventAuthority: { value: input.eventAuthority ?? null, isWritable: false },
|
|
211
|
+
program: { value: input.program ?? null, isWritable: false }
|
|
212
|
+
};
|
|
213
|
+
const accounts = originalAccounts;
|
|
214
|
+
const args = { ...input };
|
|
215
|
+
const getAccountMeta = getAccountMetaFactory(programAddress);
|
|
216
|
+
const instruction = {
|
|
217
|
+
accounts: [
|
|
218
|
+
getAccountMeta(accounts.stats),
|
|
219
|
+
getAccountMeta(accounts.eventAuthority),
|
|
220
|
+
getAccountMeta(accounts.program)
|
|
221
|
+
],
|
|
222
|
+
programAddress,
|
|
223
|
+
data: getIncrementStatsInstructionDataEncoder().encode(
|
|
224
|
+
args
|
|
225
|
+
)
|
|
226
|
+
};
|
|
227
|
+
return instruction;
|
|
228
|
+
}
|
|
132
229
|
var CONFIG_SEED = "config";
|
|
230
|
+
var STATS_SEED = "network_stats";
|
|
231
|
+
var EVENT_AUTHORITY_SEED = "__event_authority";
|
|
133
232
|
async function deriveConfigAddress(programId) {
|
|
134
233
|
const [pda] = await kit.getProgramDerivedAddress({
|
|
135
234
|
programAddress: programId,
|
|
@@ -137,6 +236,20 @@ async function deriveConfigAddress(programId) {
|
|
|
137
236
|
});
|
|
138
237
|
return pda;
|
|
139
238
|
}
|
|
239
|
+
async function deriveNetworkStatsAddress(programId) {
|
|
240
|
+
const [pda] = await kit.getProgramDerivedAddress({
|
|
241
|
+
programAddress: programId,
|
|
242
|
+
seeds: [new TextEncoder().encode(STATS_SEED)]
|
|
243
|
+
});
|
|
244
|
+
return pda;
|
|
245
|
+
}
|
|
246
|
+
async function deriveEventAuthorityAddress(programId) {
|
|
247
|
+
const [pda] = await kit.getProgramDerivedAddress({
|
|
248
|
+
programAddress: programId,
|
|
249
|
+
seeds: [new TextEncoder().encode(EVENT_AUTHORITY_SEED)]
|
|
250
|
+
});
|
|
251
|
+
return pda;
|
|
252
|
+
}
|
|
140
253
|
|
|
141
254
|
// src/config/onchain.ts
|
|
142
255
|
var CACHE_TTL_MS = 6e4;
|
|
@@ -598,7 +711,8 @@ var SolanaPaymentStrategy = class {
|
|
|
598
711
|
throw new Error(`Invalid computeUnitLimit: ${computeUnitLimit}. Must be a positive integer.`);
|
|
599
712
|
}
|
|
600
713
|
const paymentInstructions = await buildPaymentInstructions(paymentRequest, payerSigner, {
|
|
601
|
-
jobEventId: options?.jobEventId
|
|
714
|
+
jobEventId: options?.jobEventId,
|
|
715
|
+
programId: options?.programId
|
|
602
716
|
});
|
|
603
717
|
const priorityFeeMicroLamports = options?.priorityFeeMicroLamports ?? await estimatePriorityFeeMicroLamports(rpc, {
|
|
604
718
|
percentile: options?.priorityFeePercentile ?? DEFAULT_PRIORITY_FEE_PERCENTILE
|
|
@@ -900,8 +1014,21 @@ async function buildPaymentInstructions(paymentRequest, payerSigner, options) {
|
|
|
900
1014
|
const recipient = kit.address(paymentRequest.recipient);
|
|
901
1015
|
const reference = kit.address(paymentRequest.reference);
|
|
902
1016
|
const protocolTag = kit.address(ELISYM_PROTOCOL_TAG);
|
|
1017
|
+
const programId = options?.programId ?? getProtocolProgramId("devnet");
|
|
903
1018
|
const feeAmount = paymentRequest.fee_amount ?? 0;
|
|
904
1019
|
const providerAmount = paymentRequest.fee_address && feeAmount > 0 ? paymentRequest.amount - feeAmount : paymentRequest.amount;
|
|
1020
|
+
const statsPda = await deriveNetworkStatsAddress(programId);
|
|
1021
|
+
const eventAuthority = await deriveEventAuthorityAddress(programId);
|
|
1022
|
+
const incrementStatsIx = getIncrementStatsInstruction(
|
|
1023
|
+
{
|
|
1024
|
+
stats: statsPda,
|
|
1025
|
+
eventAuthority,
|
|
1026
|
+
program: programId,
|
|
1027
|
+
amount: BigInt(paymentRequest.amount),
|
|
1028
|
+
isNative: !resolveAssetFromPaymentRequest(paymentRequest).mint
|
|
1029
|
+
},
|
|
1030
|
+
{ programAddress: programId }
|
|
1031
|
+
);
|
|
905
1032
|
if (providerAmount <= 0) {
|
|
906
1033
|
throw new Error(
|
|
907
1034
|
`Fee amount (${feeAmount}) exceeds or equals total amount (${paymentRequest.amount}). Cannot create transaction with non-positive provider amount.`
|
|
@@ -937,6 +1064,7 @@ async function buildPaymentInstructions(paymentRequest, payerSigner, options) {
|
|
|
937
1064
|
})
|
|
938
1065
|
);
|
|
939
1066
|
}
|
|
1067
|
+
instructions2.push(incrementStatsIx);
|
|
940
1068
|
return instructions2;
|
|
941
1069
|
}
|
|
942
1070
|
const mint = kit.address(asset.mint);
|
|
@@ -1015,6 +1143,7 @@ async function buildPaymentInstructions(paymentRequest, payerSigner, options) {
|
|
|
1015
1143
|
})
|
|
1016
1144
|
);
|
|
1017
1145
|
}
|
|
1146
|
+
instructions.push(incrementStatsIx);
|
|
1018
1147
|
return instructions;
|
|
1019
1148
|
}
|
|
1020
1149
|
async function createPaymentRequestWithOnchainConfig(rpc, programId, recipient, amount, options) {
|
|
@@ -3218,6 +3347,18 @@ function accumulateNativeDeltas(pre, post, volumeByAsset) {
|
|
|
3218
3347
|
}
|
|
3219
3348
|
}
|
|
3220
3349
|
}
|
|
3350
|
+
async function getNetworkStats(rpc, programId) {
|
|
3351
|
+
const statsPda = await deriveNetworkStatsAddress(programId);
|
|
3352
|
+
const account = await fetchMaybeNetworkStats(rpc, statsPda);
|
|
3353
|
+
if (!account.exists) {
|
|
3354
|
+
return null;
|
|
3355
|
+
}
|
|
3356
|
+
return {
|
|
3357
|
+
jobCount: Number(account.data.jobCount),
|
|
3358
|
+
volumeNative: account.data.volumeNative,
|
|
3359
|
+
volumeUsdc: account.data.volumeUsdc
|
|
3360
|
+
};
|
|
3361
|
+
}
|
|
3221
3362
|
var SessionSpendLimitEntrySchema = zod.z.object({
|
|
3222
3363
|
chain: zod.z.enum(["solana"]),
|
|
3223
3364
|
token: zod.z.string().min(1).max(16).regex(/^[a-z0-9]+$/, "token must be lowercase alphanumeric"),
|
|
@@ -3476,6 +3617,7 @@ exports.formatAssetAmount = formatAssetAmount;
|
|
|
3476
3617
|
exports.formatFeeBreakdown = formatFeeBreakdown;
|
|
3477
3618
|
exports.formatNetworkBaseline = formatNetworkBaseline;
|
|
3478
3619
|
exports.formatSol = formatSol;
|
|
3620
|
+
exports.getNetworkStats = getNetworkStats;
|
|
3479
3621
|
exports.getProtocolConfig = getProtocolConfig;
|
|
3480
3622
|
exports.getProtocolProgramId = getProtocolProgramId;
|
|
3481
3623
|
exports.jobRequestKind = jobRequestKind;
|