@elisym/sdk 0.10.1 → 0.10.2

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.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Address, TransactionSigner, Rpc, SolanaRpcApi } from '@solana/kit';
2
2
  import { Filter, Event } from 'nostr-tools';
3
- import { A as Asset } from './assets-CMf-v55Z.cjs';
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-CMf-v55Z.cjs';
3
+ import { A as Asset } from './assets-C-nzSYD4.cjs';
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';
5
5
  import { z } from 'zod';
6
6
  export { G as GlobalConfig, a as GlobalConfigSchema, S as SessionSpendLimitEntry, b as SessionSpendLimitEntrySchema } from './global-schema-CddHP2nk.cjs';
7
7
 
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Address, TransactionSigner, Rpc, SolanaRpcApi } from '@solana/kit';
2
2
  import { Filter, Event } from 'nostr-tools';
3
- import { A as Asset } from './assets-CMf-v55Z.js';
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-CMf-v55Z.js';
3
+ import { A as Asset } from './assets-C-nzSYD4.js';
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';
5
5
  import { z } from 'zod';
6
6
  export { G as GlobalConfig, a as GlobalConfigSchema, S as SessionSpendLimitEntry, b as SessionSpendLimitEntrySchema } from './global-schema-CddHP2nk.js';
7
7
 
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { getTransferSolInstruction } from '@solana-program/system';
2
2
  import { findAssociatedTokenPda, TOKEN_PROGRAM_ADDRESS, getCreateAssociatedTokenIdempotentInstruction, ASSOCIATED_TOKEN_PROGRAM_ADDRESS, getTransferCheckedInstruction } from '@solana-program/token';
3
3
  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';
4
- import Decimal2 from 'decimal.js-light';
4
+ import Decimal3 from 'decimal.js-light';
5
5
  import { z } from 'zod';
6
6
  import { verifyEvent, finalizeEvent, getPublicKey, nip19, generateSecretKey, SimplePool } from 'nostr-tools';
7
7
  import * as nip44 from 'nostr-tools/nip44';
@@ -151,8 +151,6 @@ async function getProtocolConfig(rpc, programId, options) {
151
151
  );
152
152
  }
153
153
  }
154
-
155
- // src/payment/assets.ts
156
154
  var NATIVE_SOL = {
157
155
  chain: "solana",
158
156
  token: "sol",
@@ -233,16 +231,10 @@ function parseAssetAmount(asset, human) {
233
231
  }
234
232
  return raw;
235
233
  }
234
+ var FormatDecimal = Decimal3.clone({ toExpNeg: -100, toExpPos: 100, precision: 50 });
236
235
  function formatAssetAmount(asset, raw) {
237
- const sign = raw < 0n ? "-" : "";
238
- const abs = raw < 0n ? -raw : raw;
239
- const unit = 10n ** BigInt(asset.decimals);
240
- const whole = abs / unit;
241
- const frac = abs % unit;
242
- if (asset.decimals === 0) {
243
- return `${sign}${whole} ${asset.symbol}`;
244
- }
245
- return `${sign}${whole}.${frac.toString().padStart(asset.decimals, "0")} ${asset.symbol}`;
236
+ const value = new FormatDecimal(raw.toString()).div(new FormatDecimal(10).pow(asset.decimals));
237
+ return `${value.toString()} ${asset.symbol}`;
246
238
  }
247
239
  var BPS_DENOMINATOR = 1e4;
248
240
  function assertLamports(value, field) {
@@ -260,7 +252,7 @@ function calculateProtocolFee(amount, feeBps) {
260
252
  if (amount === 0 || feeBps === 0) {
261
253
  return 0;
262
254
  }
263
- return new Decimal2(amount).mul(feeBps).div(BPS_DENOMINATOR).toDecimalPlaces(0, Decimal2.ROUND_CEIL).toNumber();
255
+ return new Decimal3(amount).mul(feeBps).div(BPS_DENOMINATOR).toDecimalPlaces(0, Decimal3.ROUND_CEIL).toNumber();
264
256
  }
265
257
  function validateExpiry(createdAt, expirySecs) {
266
258
  if (!Number.isInteger(createdAt) || createdAt <= 0) {
@@ -2891,7 +2883,7 @@ var GlobalConfigSchema = z.object({
2891
2883
  session_spend_limits: z.array(SessionSpendLimitEntrySchema).max(16).optional()
2892
2884
  }).strict();
2893
2885
  function formatSol(lamports) {
2894
- const sol = new Decimal2(lamports).div(LAMPORTS_PER_SOL);
2886
+ const sol = new Decimal3(lamports).div(LAMPORTS_PER_SOL);
2895
2887
  if (sol.gte(1e6)) {
2896
2888
  return `${sol.idiv(1e6)}m SOL`;
2897
2889
  }
@@ -2905,12 +2897,12 @@ function compactSol(sol) {
2905
2897
  return "0";
2906
2898
  }
2907
2899
  if (sol.gte(1e3)) {
2908
- return sol.toDecimalPlaces(0, Decimal2.ROUND_FLOOR).toString();
2900
+ return sol.toDecimalPlaces(0, Decimal3.ROUND_FLOOR).toString();
2909
2901
  }
2910
2902
  const maxFrac = 9;
2911
2903
  for (let d = 1; d <= maxFrac; d++) {
2912
2904
  const s = sol.toFixed(d);
2913
- if (new Decimal2(s).eq(sol)) {
2905
+ if (new Decimal3(s).eq(sol)) {
2914
2906
  return s.replace(/0+$/, "").replace(/\.$/, "");
2915
2907
  }
2916
2908
  }