@stablechain/sdk 1.0.6 → 1.0.8

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.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { erc3009Actions } from './erc3009.js';
2
2
  export { Authorization, AuthorizationUsage, CancelAuthorizationParameters, ERC3009_ABI, Erc3009DomainOverrides, GetAuthorizationStateParameters, GetAuthorizationUsageParameters, PreparedAuthorizationCall, ReceiveWithAuthorizationParameters, SignReceiveAuthorizationParameters, SignTransferAuthorizationParameters, SignedAuthorization, TransferWithAuthorizationParameters, VerifyAuthorizationParameters, VerifyAuthorizationResult, VerifyFailureReason, cancelAuthorization, getAuthorizationState, getAuthorizationUsage, prepareTransferWithAuthorization, receiveWithAuthorization, signReceiveAuthorization, signTransferAuthorization, transferWithAuthorization, verifyAuthorization } from './erc3009.js';
3
- import { Account, Transport, WalletClient, Address, BaseError } from 'viem';
3
+ import { Account, Transport, WalletClient, Address, Hex, BaseError } from 'viem';
4
4
 
5
5
  interface EarnConfig {
6
6
  /** MetaMorpho V2 vault address */
@@ -11,6 +11,17 @@ interface StableConfig {
11
11
  network?: Network;
12
12
  /** Optional RPC override — defaults to the public RPC for the selected network */
13
13
  rpc?: string;
14
+ /**
15
+ * Per-chain RPC overrides for the cross-chain bridge routes, e.g.
16
+ * `{ [Chain.Ethereum]: "https://..." }`.
17
+ *
18
+ * {@link StableConfig.rpc} covers the Stable chain only — transfers, earn and
19
+ * authorizations. A bridge reads and broadcasts on whichever chain it starts
20
+ * from, and by default that is this SDK's built-in public endpoint for that
21
+ * chain. Override the chains you quote on to keep a backend off a shared
22
+ * rate limit; chains left out keep the public endpoint.
23
+ */
24
+ rpcOverrides?: Partial<Record<Chain, string>>;
14
25
  /** Server-side signing: pass a viem Account, e.g. privateKeyToAccount("0x...") */
15
26
  account?: Account;
16
27
  /** Browser-wallet signing: pass a viem Transport, e.g. custom(window.ethereum) */
@@ -118,6 +129,16 @@ interface BridgeQuote {
118
129
  * destination native drop, bundled. `quoteSend` returns no breakdown of it.
119
130
  */
120
131
  nativeFee?: bigint;
132
+ /**
133
+ * The messaging fee a send built from this quote will actually carry, in wei:
134
+ * {@link BridgeQuote.nativeFee} padded by `feeBufferBps`.
135
+ *
136
+ * `nativeFee` is the honest quote and the number to show a user. This is the
137
+ * number to check a native balance against, because it is what leaves the
138
+ * wallet — the endpoint keeps what the pathway costs at inclusion time and
139
+ * refunds the rest. Only present for native OFT routes.
140
+ */
141
+ nativeFeeMax?: bigint;
121
142
  /** LayerZero fee paid in LZ token (wei) — only present for native OFT routes */
122
143
  lzTokenFee?: bigint;
123
144
  /**
@@ -201,17 +222,23 @@ interface BridgeGasEstimate {
201
222
  interface BridgeTimeEstimate {
202
223
  /** Best available estimate, in seconds — prefer this for display */
203
224
  seconds: number;
204
- /** Which input produced `seconds` — see {@link BridgeTimeEstimate.observedSeconds} */
205
- source: "observed" | "formula";
206
225
  /**
207
- * Median delivery time of recent delivered messages on this exact pathway,
208
- * from LayerZero Scan. More trustworthy than `formulaSeconds` — notably on
209
- * rollup sources, where DVNs wait for L1 finality rather than raw block count.
226
+ * Which input produced `seconds`. `"formula"` normally; `"floor"` when the
227
+ * source chain's measured minimum exceeded it (Ethereum, Arbitrum, Polygon,
228
+ * Bera, Flare); `"observed"` only when the pathway's ULN config could not be read.
229
+ */
230
+ source: "formula" | "floor" | "observed";
231
+ /**
232
+ * Median delivery time of recent delivered messages on this exact pathway, from
233
+ * LayerZero Scan. Reported for comparison but no longer preferred: a 50-message
234
+ * window can reach back months, so it answers from a ULN config the pathway has
235
+ * since moved off.
210
236
  */
211
237
  observedSeconds?: number;
212
238
  /**
213
239
  * LayerZero's documented estimate:
214
- * `srcBlockTime × confirmations + dstBlockTime × (2 + dvnCount)`.
240
+ * `srcBlockTime × confirmations + dstBlockTime × (2 + dvnCount)`. What `seconds`
241
+ * reports unless the source chain's measured floor is higher.
215
242
  */
216
243
  formulaSeconds?: number;
217
244
  /** Source-chain block confirmations the DVNs wait for before attesting */
@@ -254,7 +281,14 @@ interface BridgeParams {
254
281
  /** Destination token contract address */
255
282
  toToken: string;
256
283
  amount: number;
257
- /** Source token decimals (default: 6) */
284
+ /**
285
+ * Source token decimals (default: 6). **LI.FI routes only.**
286
+ *
287
+ * Native OFT routes parse the amount with the decimals the token has on the
288
+ * source chain, which the SDK already knows from
289
+ * {@link BRIDGE_CHAIN_CONFIGS}. Passing a value that disagrees with those
290
+ * throws rather than silently sending a different amount.
291
+ */
258
292
  fromDecimals?: number;
259
293
  /** Recipient address — defaults to the signer */
260
294
  recipient?: string;
@@ -280,6 +314,91 @@ interface BridgeParams {
280
314
  * drop is part of what `nativeFee` pays for.
281
315
  */
282
316
  quote?: BridgeQuote;
317
+ /**
318
+ * How much to pad the quoted LayerZero messaging fee by when sending, in basis
319
+ * points (100 = 1%). Defaults to 500 (5%); 0 sends exactly the quoted fee.
320
+ * Native OFT routes only.
321
+ *
322
+ * The fee a send must carry is whatever the pathway costs at the moment it
323
+ * lands, and `send` demands an exact match: too little reverts, and the
324
+ * endpoint refunds the excess to the sender. Between the quote and the
325
+ * signature that number can only have moved, so the buffer trades a refund
326
+ * round trip for not reverting — and a revert costs the gas either way.
327
+ */
328
+ feeBufferBps?: number;
329
+ /**
330
+ * Where LayerZero returns messaging fee it did not need — the excess left over
331
+ * once the endpoint has taken what the pathway actually cost. Defaults to the
332
+ * sender. Native OFT routes only.
333
+ */
334
+ refundAddress?: string;
335
+ }
336
+ /**
337
+ * A bridge to build but not send — see
338
+ * {@link StableClient.prepareBridgeCalldata}.
339
+ */
340
+ interface PrepareBridgeParams extends BridgeParams {
341
+ /**
342
+ * The address that will sign and send these transactions. Its allowance is
343
+ * what decides whether an approval step is needed, and it is the default
344
+ * recipient and — via {@link BridgeParams.refundAddress} — refund address.
345
+ */
346
+ from: string;
347
+ }
348
+ /** One transaction to sign and broadcast, as built by an unsigned-build helper. */
349
+ interface BridgeCalldataStep {
350
+ /** The chain this must be sent on — always the bridge's source chain */
351
+ chainId: number;
352
+ to: string;
353
+ data: string;
354
+ /** Native token to attach, in wei: 0 for the approvals, the fee for the send */
355
+ value: bigint;
356
+ }
357
+ /**
358
+ * A built, unsigned bridge: the transactions, the quote behind them, and the send
359
+ * they encode in readable form.
360
+ */
361
+ interface BridgeCalldata {
362
+ /**
363
+ * Transactions to send in order, each confirmed before the next: an allowance
364
+ * reset and an approve where the pathway needs them, then the OFT `send`.
365
+ *
366
+ * Approvals appear only when the source chain's adapter pulls the token with
367
+ * `transferFrom` and the current allowance is short. A short but non-zero
368
+ * allowance takes two of them — legacy USDT refuses to overwrite a non-zero
369
+ * allowance with another non-zero value — which is why this is a list and not
370
+ * an optional single approval.
371
+ */
372
+ steps: BridgeCalldataStep[];
373
+ /** The source chain every step must be sent on */
374
+ chainId: number;
375
+ /** Which OFT mesh this send moves through */
376
+ asset: "usdt0" | "xaut0";
377
+ /** The quote these steps were built from, whether supplied or freshly read */
378
+ quote: BridgeQuote;
379
+ /**
380
+ * The `send` step's arguments, decoded — enough to check the calldata against
381
+ * what was intended without re-deriving the ABI encoding.
382
+ */
383
+ send: {
384
+ /** LayerZero endpoint ID of the destination chain */
385
+ dstEid: number;
386
+ /** Recipient address on the destination chain */
387
+ recipient: string;
388
+ /** `recipient`, left-padded to the bytes32 the OFT takes */
389
+ to: string;
390
+ /** Amount debited on the source chain, in the token's smallest unit */
391
+ amountLD: bigint;
392
+ /** Slippage floor: what the adapter quoted it would deliver */
393
+ minAmountLD: bigint;
394
+ /** Encoded LayerZero executor options, including any destination native drop */
395
+ extraOptions: string;
396
+ /** Messaging fee the send carries as its `value`, buffer included */
397
+ nativeFee: bigint;
398
+ lzTokenFee: bigint;
399
+ /** Where the endpoint returns unused fee */
400
+ refundAddress: string;
401
+ };
283
402
  }
284
403
  interface EarnDepositParams {
285
404
  /** Amount of underlying assets to deposit (human-readable) */
@@ -510,6 +629,15 @@ interface StableClient {
510
629
  transfer(params: TransferParams): Promise<OperationResult>;
511
630
  quoteBridge(params: BridgeParams): Promise<BridgeQuote>;
512
631
  bridge(params: BridgeParams): Promise<OperationResult>;
632
+ /**
633
+ * Build a bridge's transactions without signing or sending them — for a
634
+ * backend that quotes, builds and checks while the holder's wallet only signs.
635
+ *
636
+ * Native OFT routes only: LI.FI hands back its own transaction request from
637
+ * its API, so a pair that resolves to LI.FI throws rather than returning
638
+ * something shaped the same but built elsewhere.
639
+ */
640
+ prepareBridgeCalldata(params: PrepareBridgeParams): Promise<BridgeCalldata>;
513
641
  /**
514
642
  * Expected delivery time for a native OFT (LayerZero) bridge, before sending.
515
643
  * Throws for chain pairs with no OFT adapter — LI.FI carries its own ETA.
@@ -570,7 +698,7 @@ interface StableReader {
570
698
  };
571
699
  };
572
700
  }
573
- declare function createStable({ network, rpc: rpcOverride, account, transport, walletClient, earn: earnConfig, merklApiBase, }: StableConfig): StableClient;
701
+ declare function createStable({ network, rpc: rpcOverride, rpcOverrides, account, transport, walletClient, earn: earnConfig, merklApiBase, }: StableConfig): StableClient;
574
702
  declare function createStableReader(config: StableReaderConfig): StableReader;
575
703
 
576
704
  interface ChainConfig {
@@ -621,6 +749,26 @@ interface BridgeChainConfig extends ChainConfig {
621
749
  * requirement into a wall-clock estimate. Measured from mainnet, 2026-07-30.
622
750
  */
623
751
  blockTimeSec?: number;
752
+ /**
753
+ * Floor on delivery time, in seconds, for sends *from* this chain — set only
754
+ * where the confirmation count is demonstrably not the whole wait.
755
+ *
756
+ * Two things sit outside the formula: DVN attestation and destination execution,
757
+ * a roughly fixed overhead, and on Ethereum and Arbitrum a hold until the send
758
+ * finalizes on the beacon chain. Where confirmations are high the overhead is lost
759
+ * in the rounding — Optimism's 1000 and X Layer's 9000 both land within 0.5% of
760
+ * observed. Where they are low it dominates: Arbitrum's 60 confirmations compute
761
+ * to ~19s against a real ~18min, Ethereum's 65 to ~13min against ~17min, Polygon's
762
+ * 32 to ~52s against a real ~70s, Flare's 500 to ~9min against a real ~10min.
763
+ *
764
+ * Each figure is taken from deliveries LayerZero Scan held on 2026-08-27, no older
765
+ * than 45 days — the ceiling of that spread for the two finality-bound chains, so
766
+ * the estimate errs long, and the median for the rest. Flare's is a median across
767
+ * its destinations rather than one pathway's, since the hub pathway alone had only
768
+ * six recent sends to go on; those settled at ~9m30s and the busier pathways to
769
+ * Ethereum, Arbitrum, Plasma, Polygon and Optimism between ~9m20s and ~10m10s.
770
+ */
771
+ minDeliverySec?: number;
624
772
  }
625
773
  declare const BRIDGE_CHAIN_CONFIGS: Partial<Record<Chain, BridgeChainConfig>>;
626
774
  /**
@@ -628,8 +776,170 @@ declare const BRIDGE_CHAIN_CONFIGS: Partial<Record<Chain, BridgeChainConfig>>;
628
776
  * chain has no OFT deployment matching it.
629
777
  */
630
778
  declare function bridgeAssetFor(cfg: BridgeChainConfig, token: string): BridgeAsset | undefined;
779
+ declare const OFT_ADAPTER_ABI: readonly [{
780
+ readonly name: "quoteSend";
781
+ readonly type: "function";
782
+ readonly inputs: readonly [{
783
+ readonly name: "_sendParam";
784
+ readonly type: "tuple";
785
+ readonly components: readonly [{
786
+ readonly name: "dstEid";
787
+ readonly type: "uint32";
788
+ }, {
789
+ readonly name: "to";
790
+ readonly type: "bytes32";
791
+ }, {
792
+ readonly name: "amountLD";
793
+ readonly type: "uint256";
794
+ }, {
795
+ readonly name: "minAmountLD";
796
+ readonly type: "uint256";
797
+ }, {
798
+ readonly name: "extraOptions";
799
+ readonly type: "bytes";
800
+ }, {
801
+ readonly name: "composeMsg";
802
+ readonly type: "bytes";
803
+ }, {
804
+ readonly name: "oftCmd";
805
+ readonly type: "bytes";
806
+ }];
807
+ }, {
808
+ readonly name: "_payInLzToken";
809
+ readonly type: "bool";
810
+ }];
811
+ readonly outputs: readonly [{
812
+ readonly name: "msgFee";
813
+ readonly type: "tuple";
814
+ readonly components: readonly [{
815
+ readonly name: "nativeFee";
816
+ readonly type: "uint256";
817
+ }, {
818
+ readonly name: "lzTokenFee";
819
+ readonly type: "uint256";
820
+ }];
821
+ }];
822
+ readonly stateMutability: "view";
823
+ }, {
824
+ readonly name: "quoteOFT";
825
+ readonly type: "function";
826
+ readonly inputs: readonly [{
827
+ readonly name: "_sendParam";
828
+ readonly type: "tuple";
829
+ readonly components: readonly [{
830
+ readonly name: "dstEid";
831
+ readonly type: "uint32";
832
+ }, {
833
+ readonly name: "to";
834
+ readonly type: "bytes32";
835
+ }, {
836
+ readonly name: "amountLD";
837
+ readonly type: "uint256";
838
+ }, {
839
+ readonly name: "minAmountLD";
840
+ readonly type: "uint256";
841
+ }, {
842
+ readonly name: "extraOptions";
843
+ readonly type: "bytes";
844
+ }, {
845
+ readonly name: "composeMsg";
846
+ readonly type: "bytes";
847
+ }, {
848
+ readonly name: "oftCmd";
849
+ readonly type: "bytes";
850
+ }];
851
+ }];
852
+ readonly outputs: readonly [{
853
+ readonly name: "oftLimit";
854
+ readonly type: "tuple";
855
+ readonly components: readonly [{
856
+ readonly name: "minAmountLD";
857
+ readonly type: "uint256";
858
+ }, {
859
+ readonly name: "maxAmountLD";
860
+ readonly type: "uint256";
861
+ }];
862
+ }, {
863
+ readonly name: "oftFeeDetails";
864
+ readonly type: "tuple[]";
865
+ readonly components: readonly [{
866
+ readonly name: "feeAmountLD";
867
+ readonly type: "int256";
868
+ }, {
869
+ readonly name: "description";
870
+ readonly type: "string";
871
+ }];
872
+ }, {
873
+ readonly name: "oftReceipt";
874
+ readonly type: "tuple";
875
+ readonly components: readonly [{
876
+ readonly name: "amountSentLD";
877
+ readonly type: "uint256";
878
+ }, {
879
+ readonly name: "amountReceivedLD";
880
+ readonly type: "uint256";
881
+ }];
882
+ }];
883
+ readonly stateMutability: "view";
884
+ }, {
885
+ readonly name: "send";
886
+ readonly type: "function";
887
+ readonly inputs: readonly [{
888
+ readonly name: "_sendParam";
889
+ readonly type: "tuple";
890
+ readonly components: readonly [{
891
+ readonly name: "dstEid";
892
+ readonly type: "uint32";
893
+ }, {
894
+ readonly name: "to";
895
+ readonly type: "bytes32";
896
+ }, {
897
+ readonly name: "amountLD";
898
+ readonly type: "uint256";
899
+ }, {
900
+ readonly name: "minAmountLD";
901
+ readonly type: "uint256";
902
+ }, {
903
+ readonly name: "extraOptions";
904
+ readonly type: "bytes";
905
+ }, {
906
+ readonly name: "composeMsg";
907
+ readonly type: "bytes";
908
+ }, {
909
+ readonly name: "oftCmd";
910
+ readonly type: "bytes";
911
+ }];
912
+ }, {
913
+ readonly name: "_fee";
914
+ readonly type: "tuple";
915
+ readonly components: readonly [{
916
+ readonly name: "nativeFee";
917
+ readonly type: "uint256";
918
+ }, {
919
+ readonly name: "lzTokenFee";
920
+ readonly type: "uint256";
921
+ }];
922
+ }, {
923
+ readonly name: "_refundAddress";
924
+ readonly type: "address";
925
+ }];
926
+ readonly outputs: readonly [];
927
+ readonly stateMutability: "payable";
928
+ }];
631
929
  /** Drop cached pathway configs and observed timings — forces the next estimate to refetch. */
632
930
  declare function clearBridgeEstimateCache(): void;
931
+ /**
932
+ * Encode LayerZero V2 executor options.
933
+ *
934
+ * `gasLimit = 0` tells the executor to use its built-in minimum for lzReceive —
935
+ * matches the Stable bridge tutorial, and is what every plain token transfer wants.
936
+ *
937
+ * A non-zero `nativeDrop` appends the executor's native-drop option: that many wei
938
+ * of the *destination* chain's native token, airdropped to `dropReceiver` when the
939
+ * message is executed. The executor prices it into `quoteSend`'s `nativeFee`, and
940
+ * rejects a drop above the pathway's configured `nativeCap`.
941
+ */
942
+ declare function buildLzOptions(gasLimit?: bigint, nativeDrop?: bigint, dropReceiver?: Address): Hex;
633
943
 
634
944
  declare const STABLE_USDT_ADDRESS: Address;
635
945
  declare const STABLE_VAULT_ADDRESS: Address;
@@ -691,4 +1001,4 @@ declare class StableBulkError extends StableError {
691
1001
  });
692
1002
  }
693
1003
 
694
- export { BRIDGE_CHAIN_CONFIGS, type BridgeAsset, type BridgeChainConfig, type BridgeDeliveryState, type BridgeGasEstimate, type BridgeOftFee, type BridgeOftQuote, type BridgeParams, type BridgeQuote, type BridgeRoute, type BridgeStatus, type BridgeTimeEstimate, type BridgeTokenConfig, type BulkDepositOptions, type BulkEarnResult, type BulkEarnResultItem, type BulkWithdrawOptions, CHAIN_CONFIGS, Chain, type ChainConfig, type EarnConfig, type EarnDepositCalldata, type EarnDepositParams, type EarnRedeemParams, type EarnResult, type EarnWithdrawCalldata, type EarnWithdrawParams, type ForceDeallocation, type ForceRedeemParams, type ForceWithdrawParams, type MerklClaimCalldata, type MerklClaimResult, type MerklReward, type MerklRewardToken, type MerklRewardsResult, Network, type OperationResult, STABLE_USDT_ADDRESS, STABLE_VAULT_ADDRESS, StableBulkError, type StableClient, type StableConfig, StableError, StableNetworkError, StableQuoteError, type StableReader, type StableReaderConfig, StableTransactionError, StableValidationError, type SwapParams, type SwapQuote, type TransferParams, type VaultPosition, type VaultYield, type VaultYieldReward, type WithdrawStatus, type YieldPreview, bridgeAssetFor, clearBridgeEstimateCache, createStable, createStableReader, erc3009Actions };
1004
+ export { BRIDGE_CHAIN_CONFIGS, type BridgeAsset, type BridgeCalldata, type BridgeCalldataStep, type BridgeChainConfig, type BridgeDeliveryState, type BridgeGasEstimate, type BridgeOftFee, type BridgeOftQuote, type BridgeParams, type BridgeQuote, type BridgeRoute, type BridgeStatus, type BridgeTimeEstimate, type BridgeTokenConfig, type BulkDepositOptions, type BulkEarnResult, type BulkEarnResultItem, type BulkWithdrawOptions, CHAIN_CONFIGS, Chain, type ChainConfig, type EarnConfig, type EarnDepositCalldata, type EarnDepositParams, type EarnRedeemParams, type EarnResult, type EarnWithdrawCalldata, type EarnWithdrawParams, type ForceDeallocation, type ForceRedeemParams, type ForceWithdrawParams, type MerklClaimCalldata, type MerklClaimResult, type MerklReward, type MerklRewardToken, type MerklRewardsResult, Network, OFT_ADAPTER_ABI, type OperationResult, type PrepareBridgeParams, STABLE_USDT_ADDRESS, STABLE_VAULT_ADDRESS, StableBulkError, type StableClient, type StableConfig, StableError, StableNetworkError, StableQuoteError, type StableReader, type StableReaderConfig, StableTransactionError, StableValidationError, type SwapParams, type SwapQuote, type TransferParams, type VaultPosition, type VaultYield, type VaultYieldReward, type WithdrawStatus, type YieldPreview, bridgeAssetFor, buildLzOptions, clearBridgeEstimateCache, createStable, createStableReader, erc3009Actions };