nara-sdk 1.0.77 → 1.0.78
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 +8 -3
- package/index.ts +2 -1
- package/package.json +1 -1
- package/src/bridge.ts +27 -11
- package/src/constants.ts +12 -8
package/README.md
CHANGED
|
@@ -127,12 +127,17 @@ registerBridgeToken('USDT', {
|
|
|
127
127
|
### Fee configuration
|
|
128
128
|
|
|
129
129
|
Default fee: **0.5%** (50 bps), deducted from the bridged amount on the source chain.
|
|
130
|
+
Fee recipients are chain-specific (one per source chain).
|
|
130
131
|
|
|
131
132
|
```ts
|
|
132
|
-
import { setBridgeFeeRecipient } from 'nara-sdk';
|
|
133
|
+
import { setBridgeFeeRecipient, getBridgeFeeRecipient } from 'nara-sdk';
|
|
133
134
|
|
|
134
|
-
// Override fee recipient at runtime
|
|
135
|
-
setBridgeFeeRecipient('
|
|
135
|
+
// Override fee recipient at runtime (per chain)
|
|
136
|
+
setBridgeFeeRecipient('solana', 'SolanaFeeRecipientPubkey...');
|
|
137
|
+
setBridgeFeeRecipient('nara', 'NaraFeeRecipientPubkey...');
|
|
138
|
+
|
|
139
|
+
// Read current recipient
|
|
140
|
+
const recipient = getBridgeFeeRecipient('solana'); // PublicKey
|
|
136
141
|
|
|
137
142
|
// Or per-call
|
|
138
143
|
await bridgeTransfer(conn, wallet, {
|
package/index.ts
CHANGED
|
@@ -16,7 +16,8 @@ export {
|
|
|
16
16
|
DEFAULT_AGENT_REGISTRY_PROGRAM_ID,
|
|
17
17
|
DEFAULT_ALT_ADDRESS,
|
|
18
18
|
DEFAULT_BRIDGE_FEE_BPS,
|
|
19
|
-
|
|
19
|
+
DEFAULT_BRIDGE_FEE_RECIPIENT_SOLANA,
|
|
20
|
+
DEFAULT_BRIDGE_FEE_RECIPIENT_NARA,
|
|
20
21
|
BRIDGE_FEE_BPS_DENOMINATOR,
|
|
21
22
|
} from "./src/constants";
|
|
22
23
|
|
package/package.json
CHANGED
package/src/bridge.ts
CHANGED
|
@@ -27,7 +27,8 @@ import {
|
|
|
27
27
|
import {
|
|
28
28
|
BRIDGE_FEE_BPS_DENOMINATOR,
|
|
29
29
|
DEFAULT_BRIDGE_FEE_BPS,
|
|
30
|
-
|
|
30
|
+
DEFAULT_BRIDGE_FEE_RECIPIENT_SOLANA,
|
|
31
|
+
DEFAULT_BRIDGE_FEE_RECIPIENT_NARA,
|
|
31
32
|
} from "./constants";
|
|
32
33
|
import { sendTx } from "./tx";
|
|
33
34
|
|
|
@@ -185,23 +186,38 @@ function getToken(symbol: string): BridgeTokenConfig {
|
|
|
185
186
|
return t;
|
|
186
187
|
}
|
|
187
188
|
|
|
188
|
-
// ─── Fee recipient (runtime override)
|
|
189
|
+
// ─── Fee recipient (runtime override, per chain) ──────────────────
|
|
189
190
|
|
|
190
|
-
|
|
191
|
+
const _feeRecipientOverrides: Record<BridgeChain, PublicKey | null> = {
|
|
192
|
+
solana: null,
|
|
193
|
+
nara: null,
|
|
194
|
+
};
|
|
191
195
|
|
|
192
|
-
/**
|
|
193
|
-
|
|
196
|
+
/**
|
|
197
|
+
* Override the bridge fee recipient for a specific source chain at runtime.
|
|
198
|
+
* Pass `null` as recipient to clear the override and fall back to the default.
|
|
199
|
+
*/
|
|
200
|
+
export function setBridgeFeeRecipient(
|
|
201
|
+
chain: BridgeChain,
|
|
202
|
+
recipient: PublicKey | string | null
|
|
203
|
+
): void {
|
|
194
204
|
if (recipient === null) {
|
|
195
|
-
|
|
205
|
+
_feeRecipientOverrides[chain] = null;
|
|
196
206
|
return;
|
|
197
207
|
}
|
|
198
|
-
|
|
208
|
+
_feeRecipientOverrides[chain] =
|
|
199
209
|
typeof recipient === "string" ? new PublicKey(recipient) : recipient;
|
|
200
210
|
}
|
|
201
211
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
212
|
+
/** Get the current fee recipient for a source chain (override or default). */
|
|
213
|
+
export function getBridgeFeeRecipient(chain: BridgeChain): PublicKey {
|
|
214
|
+
const override = _feeRecipientOverrides[chain];
|
|
215
|
+
if (override) return override;
|
|
216
|
+
const defaultAddr =
|
|
217
|
+
chain === "solana"
|
|
218
|
+
? DEFAULT_BRIDGE_FEE_RECIPIENT_SOLANA
|
|
219
|
+
: DEFAULT_BRIDGE_FEE_RECIPIENT_NARA;
|
|
220
|
+
return new PublicKey(defaultAddr);
|
|
205
221
|
}
|
|
206
222
|
|
|
207
223
|
// ─── PDA derivation ───────────────────────────────────────────────
|
|
@@ -515,7 +531,7 @@ export function makeBridgeIxs(params: BridgeTransferParams): BridgeIxsResult {
|
|
|
515
531
|
throw new Error("bridge amount after fee is zero — increase amount or lower feeBps");
|
|
516
532
|
}
|
|
517
533
|
|
|
518
|
-
const recipientForFee = feeRecipient ?? getBridgeFeeRecipient();
|
|
534
|
+
const recipientForFee = feeRecipient ?? getBridgeFeeRecipient(fromChain);
|
|
519
535
|
const feeIxs = makeBridgeFeeIxs({
|
|
520
536
|
token,
|
|
521
537
|
fromChain,
|
package/src/constants.ts
CHANGED
|
@@ -48,8 +48,8 @@ export const DEFAULT_ALT_ADDRESS = process.env.ALT_ADDRESS || "3uw7RatGTB4hdHnuV
|
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* Bridge fee in basis points (1 bps = 0.01%). 50 = 0.5%.
|
|
51
|
-
* Deducted from the bridged amount and transferred to
|
|
52
|
-
* in the same transaction.
|
|
51
|
+
* Deducted from the bridged amount and transferred to the chain-specific
|
|
52
|
+
* fee recipient in the same transaction.
|
|
53
53
|
*/
|
|
54
54
|
export const DEFAULT_BRIDGE_FEE_BPS = 50;
|
|
55
55
|
|
|
@@ -57,11 +57,15 @@ export const DEFAULT_BRIDGE_FEE_BPS = 50;
|
|
|
57
57
|
export const BRIDGE_FEE_BPS_DENOMINATOR = 10000;
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
|
-
* Default fee recipient pubkey
|
|
61
|
-
*
|
|
62
|
-
* Override at runtime via setBridgeFeeRecipient() in src/bridge.ts.
|
|
63
|
-
*
|
|
64
|
-
* NOTE: replace with actual fee recipient before mainnet usage.
|
|
60
|
+
* Default fee recipient pubkey on Solana (when bridging FROM Solana).
|
|
61
|
+
* Override at runtime via setBridgeFeeRecipient("solana", ...).
|
|
65
62
|
*/
|
|
66
|
-
export const
|
|
63
|
+
export const DEFAULT_BRIDGE_FEE_RECIPIENT_SOLANA =
|
|
64
|
+
"HaPQTvGJBunoWA3AyyWRL9etVEbQWsXVoj3fHpBprLy5";
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Default fee recipient pubkey on Nara (when bridging FROM Nara).
|
|
68
|
+
* Override at runtime via setBridgeFeeRecipient("nara", ...).
|
|
69
|
+
*/
|
|
70
|
+
export const DEFAULT_BRIDGE_FEE_RECIPIENT_NARA =
|
|
67
71
|
"FERLFwBpCyoEuvFP68eP6Fv4FCVocnNyyFUCYwpfmjqn";
|