nara-sdk 1.0.82 → 1.0.83

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/bridge.ts +27 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nara-sdk",
3
- "version": "1.0.82",
3
+ "version": "1.0.83",
4
4
  "description": "SDK for the Nara chain (Solana-compatible)",
5
5
  "module": "index.ts",
6
6
  "main": "index.ts",
package/src/bridge.ts CHANGED
@@ -51,6 +51,8 @@ export interface BridgeTokenConfig {
51
51
  decimals: number;
52
52
  /** Minimum per-transfer amount in raw units (rejected if below) */
53
53
  minAmount: bigint;
54
+ /** Minimum fee floor in raw units (fee = max(amount * bps, minFee)) */
55
+ minFee: bigint;
54
56
  solana: BridgeTokenSide;
55
57
  nara: BridgeTokenSide;
56
58
  }
@@ -130,7 +132,8 @@ export const BRIDGE_TOKENS: Record<string, BridgeTokenConfig> = {
130
132
  USDC: {
131
133
  symbol: "USDC",
132
134
  decimals: 6,
133
- minAmount: 100_000n, // 0.1 USDC
135
+ minAmount: 5_000_000n, // 5 USDC
136
+ minFee: 500_000n, // 0.5 USDC (fee floor)
134
137
  solana: {
135
138
  warpProgram: new PublicKey("4GcZJTa8s9vxtTz97Vj1RrwKMqPkT3DiiJkvUQDwsuZP"),
136
139
  mode: "collateral",
@@ -147,7 +150,8 @@ export const BRIDGE_TOKENS: Record<string, BridgeTokenConfig> = {
147
150
  USDT: {
148
151
  symbol: "USDT",
149
152
  decimals: 6,
150
- minAmount: 100_000n, // 0.1 USDT
153
+ minAmount: 5_000_000n, // 5 USDT
154
+ minFee: 500_000n, // 0.5 USDT (fee floor)
151
155
  solana: {
152
156
  warpProgram: new PublicKey("DCTt9H3pwwU89qC3Z4voYNThZypV68AwhYNzMNBxWXoy"),
153
157
  mode: "collateral",
@@ -164,7 +168,8 @@ export const BRIDGE_TOKENS: Record<string, BridgeTokenConfig> = {
164
168
  SOL: {
165
169
  symbol: "SOL",
166
170
  decimals: 9,
167
- minAmount: 1_000_000n, // 0.001 SOL
171
+ minAmount: 100_000_000n, // 0.1 SOL
172
+ minFee: 10_000_000n, // 0.01 SOL (fee floor)
168
173
  solana: {
169
174
  warpProgram: new PublicKey("46MmAWwKRAt9uvn7m44NXbVq2DCWBQE2r1TDw25nyXrt"),
170
175
  mode: "native",
@@ -326,19 +331,32 @@ export function encodeTransferRemote(
326
331
  // ─── Fee calculation ──────────────────────────────────────────────
327
332
 
328
333
  export interface FeeSplit {
334
+ /** Total fee (max of percentage and minFee) in raw units */
329
335
  feeAmount: bigint;
336
+ /** Net amount bridged after fee */
330
337
  bridgeAmount: bigint;
338
+ /** Percentage part (bps) used */
331
339
  feeBps: number;
340
+ /** Fee floor in raw units */
341
+ minFee: bigint;
332
342
  }
333
343
 
334
- export function calculateBridgeFee(amount: bigint, feeBps?: number): FeeSplit {
344
+ /**
345
+ * Calculate the bridge fee: max(amount * bps / 10000, minFee)
346
+ */
347
+ export function calculateBridgeFee(
348
+ amount: bigint,
349
+ feeBps?: number,
350
+ minFee: bigint = 0n
351
+ ): FeeSplit {
335
352
  const bps = feeBps ?? DEFAULT_BRIDGE_FEE_BPS;
336
353
  if (bps < 0 || bps > BRIDGE_FEE_BPS_DENOMINATOR) {
337
354
  throw new Error(`Invalid feeBps: ${bps}`);
338
355
  }
339
- const feeAmount = (amount * BigInt(bps)) / BigInt(BRIDGE_FEE_BPS_DENOMINATOR);
356
+ const pctFee = (amount * BigInt(bps)) / BigInt(BRIDGE_FEE_BPS_DENOMINATOR);
357
+ const feeAmount = pctFee > minFee ? pctFee : minFee;
340
358
  const bridgeAmount = amount - feeAmount;
341
- return { feeAmount, bridgeAmount, feeBps: bps };
359
+ return { feeAmount, bridgeAmount, feeBps: bps, minFee };
342
360
  }
343
361
 
344
362
  // ─── Fee instruction builder ──────────────────────────────────────
@@ -538,11 +556,11 @@ export function makeBridgeIxs(params: BridgeTransferParams): BridgeIxsResult {
538
556
  }
539
557
 
540
558
  const split = skipFee
541
- ? { feeAmount: 0n, bridgeAmount: amount, feeBps: 0 }
542
- : calculateBridgeFee(amount, feeBps);
559
+ ? { feeAmount: 0n, bridgeAmount: amount, feeBps: 0, minFee: 0n }
560
+ : calculateBridgeFee(amount, feeBps, tokenCfg.minFee);
543
561
 
544
562
  if (split.bridgeAmount <= 0n) {
545
- throw new Error("bridge amount after fee is zero — increase amount or lower feeBps");
563
+ throw new Error("bridge amount after fee is zero — increase amount or lower fee");
546
564
  }
547
565
 
548
566
  const recipientForFee = feeRecipient ?? getBridgeFeeRecipient(fromChain);