@elisym/sdk 0.10.1 → 0.10.3
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/{assets-CMf-v55Z.d.cts → assets-C-nzSYD4.d.cts} +5 -1
- package/dist/{assets-CMf-v55Z.d.ts → assets-C-nzSYD4.d.ts} +5 -1
- package/dist/index.cjs +12 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +11 -16
- package/dist/index.js.map +1 -1
- package/dist/skills.cjs +3 -2
- package/dist/skills.cjs.map +1 -1
- package/dist/skills.d.cts +1 -1
- package/dist/skills.d.ts +1 -1
- package/dist/skills.js +2 -2
- package/dist/skills.js.map +1 -1
- package/package.json +1 -1
|
@@ -52,7 +52,11 @@ declare function resolveAssetFromPaymentRequest(request: {
|
|
|
52
52
|
* call-sites safe).
|
|
53
53
|
*/
|
|
54
54
|
declare function parseAssetAmount(asset: Asset, human: string): bigint;
|
|
55
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* Format raw subunits back to `"<value> <SYMBOL>"`. Trailing zeros and a bare
|
|
57
|
+
* trailing dot are stripped, so 0.01 USDC renders as `"0.01 USDC"` rather than
|
|
58
|
+
* `"0.010000 USDC"`.
|
|
59
|
+
*/
|
|
56
60
|
declare function formatAssetAmount(asset: Asset, raw: bigint): string;
|
|
57
61
|
|
|
58
62
|
export { type Asset as A, type Chain as C, KNOWN_ASSETS as K, NATIVE_SOL as N, USDC_SOLANA_DEVNET as U, assetByKey as a, assetKey as b, resolveKnownAsset as c, formatAssetAmount as f, parseAssetAmount as p, resolveAssetFromPaymentRequest as r };
|
|
@@ -52,7 +52,11 @@ declare function resolveAssetFromPaymentRequest(request: {
|
|
|
52
52
|
* call-sites safe).
|
|
53
53
|
*/
|
|
54
54
|
declare function parseAssetAmount(asset: Asset, human: string): bigint;
|
|
55
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* Format raw subunits back to `"<value> <SYMBOL>"`. Trailing zeros and a bare
|
|
57
|
+
* trailing dot are stripped, so 0.01 USDC renders as `"0.01 USDC"` rather than
|
|
58
|
+
* `"0.010000 USDC"`.
|
|
59
|
+
*/
|
|
56
60
|
declare function formatAssetAmount(asset: Asset, raw: bigint): string;
|
|
57
61
|
|
|
58
62
|
export { type Asset as A, type Chain as C, KNOWN_ASSETS as K, NATIVE_SOL as N, USDC_SOLANA_DEVNET as U, assetByKey as a, assetKey as b, resolveKnownAsset as c, formatAssetAmount as f, parseAssetAmount as p, resolveAssetFromPaymentRequest as r };
|
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var system = require('@solana-program/system');
|
|
4
4
|
var token = require('@solana-program/token');
|
|
5
5
|
var kit = require('@solana/kit');
|
|
6
|
-
var
|
|
6
|
+
var Decimal3 = require('decimal.js-light');
|
|
7
7
|
var zod = require('zod');
|
|
8
8
|
var nostrTools = require('nostr-tools');
|
|
9
9
|
var nip44 = require('nostr-tools/nip44');
|
|
@@ -28,7 +28,7 @@ function _interopNamespace(e) {
|
|
|
28
28
|
return Object.freeze(n);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
var
|
|
31
|
+
var Decimal3__default = /*#__PURE__*/_interopDefault(Decimal3);
|
|
32
32
|
var nip44__namespace = /*#__PURE__*/_interopNamespace(nip44);
|
|
33
33
|
|
|
34
34
|
// src/constants.ts
|
|
@@ -176,8 +176,6 @@ async function getProtocolConfig(rpc, programId, options) {
|
|
|
176
176
|
);
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
|
-
|
|
180
|
-
// src/payment/assets.ts
|
|
181
179
|
var NATIVE_SOL = {
|
|
182
180
|
chain: "solana",
|
|
183
181
|
token: "sol",
|
|
@@ -258,16 +256,10 @@ function parseAssetAmount(asset, human) {
|
|
|
258
256
|
}
|
|
259
257
|
return raw;
|
|
260
258
|
}
|
|
259
|
+
var FormatDecimal = Decimal3__default.default.clone({ toExpNeg: -100, toExpPos: 100, precision: 50 });
|
|
261
260
|
function formatAssetAmount(asset, raw) {
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
const unit = 10n ** BigInt(asset.decimals);
|
|
265
|
-
const whole = abs / unit;
|
|
266
|
-
const frac = abs % unit;
|
|
267
|
-
if (asset.decimals === 0) {
|
|
268
|
-
return `${sign}${whole} ${asset.symbol}`;
|
|
269
|
-
}
|
|
270
|
-
return `${sign}${whole}.${frac.toString().padStart(asset.decimals, "0")} ${asset.symbol}`;
|
|
261
|
+
const value = new FormatDecimal(raw.toString()).div(new FormatDecimal(10).pow(asset.decimals));
|
|
262
|
+
return `${value.toString()} ${asset.symbol}`;
|
|
271
263
|
}
|
|
272
264
|
var BPS_DENOMINATOR = 1e4;
|
|
273
265
|
function assertLamports(value, field) {
|
|
@@ -285,7 +277,7 @@ function calculateProtocolFee(amount, feeBps) {
|
|
|
285
277
|
if (amount === 0 || feeBps === 0) {
|
|
286
278
|
return 0;
|
|
287
279
|
}
|
|
288
|
-
return new
|
|
280
|
+
return new Decimal3__default.default(amount).mul(feeBps).div(BPS_DENOMINATOR).toDecimalPlaces(0, Decimal3__default.default.ROUND_CEIL).toNumber();
|
|
289
281
|
}
|
|
290
282
|
function validateExpiry(createdAt, expirySecs) {
|
|
291
283
|
if (!Number.isInteger(createdAt) || createdAt <= 0) {
|
|
@@ -1224,6 +1216,9 @@ var DiscoveryService = class {
|
|
|
1224
1216
|
if (typeof meta.picture === "string") {
|
|
1225
1217
|
agent.picture = meta.picture;
|
|
1226
1218
|
}
|
|
1219
|
+
if (typeof meta.banner === "string") {
|
|
1220
|
+
agent.banner = meta.banner;
|
|
1221
|
+
}
|
|
1227
1222
|
if (typeof meta.name === "string") {
|
|
1228
1223
|
agent.name = meta.name;
|
|
1229
1224
|
}
|
|
@@ -2916,7 +2911,7 @@ var GlobalConfigSchema = zod.z.object({
|
|
|
2916
2911
|
session_spend_limits: zod.z.array(SessionSpendLimitEntrySchema).max(16).optional()
|
|
2917
2912
|
}).strict();
|
|
2918
2913
|
function formatSol(lamports) {
|
|
2919
|
-
const sol = new
|
|
2914
|
+
const sol = new Decimal3__default.default(lamports).div(LAMPORTS_PER_SOL);
|
|
2920
2915
|
if (sol.gte(1e6)) {
|
|
2921
2916
|
return `${sol.idiv(1e6)}m SOL`;
|
|
2922
2917
|
}
|
|
@@ -2930,12 +2925,12 @@ function compactSol(sol) {
|
|
|
2930
2925
|
return "0";
|
|
2931
2926
|
}
|
|
2932
2927
|
if (sol.gte(1e3)) {
|
|
2933
|
-
return sol.toDecimalPlaces(0,
|
|
2928
|
+
return sol.toDecimalPlaces(0, Decimal3__default.default.ROUND_FLOOR).toString();
|
|
2934
2929
|
}
|
|
2935
2930
|
const maxFrac = 9;
|
|
2936
2931
|
for (let d = 1; d <= maxFrac; d++) {
|
|
2937
2932
|
const s = sol.toFixed(d);
|
|
2938
|
-
if (new
|
|
2933
|
+
if (new Decimal3__default.default(s).eq(sol)) {
|
|
2939
2934
|
return s.replace(/0+$/, "").replace(/\.$/, "");
|
|
2940
2935
|
}
|
|
2941
2936
|
}
|