@stablechain/sdk 1.0.6 → 1.0.7

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
  /**
@@ -254,7 +275,14 @@ interface BridgeParams {
254
275
  /** Destination token contract address */
255
276
  toToken: string;
256
277
  amount: number;
257
- /** Source token decimals (default: 6) */
278
+ /**
279
+ * Source token decimals (default: 6). **LI.FI routes only.**
280
+ *
281
+ * Native OFT routes parse the amount with the decimals the token has on the
282
+ * source chain, which the SDK already knows from
283
+ * {@link BRIDGE_CHAIN_CONFIGS}. Passing a value that disagrees with those
284
+ * throws rather than silently sending a different amount.
285
+ */
258
286
  fromDecimals?: number;
259
287
  /** Recipient address — defaults to the signer */
260
288
  recipient?: string;
@@ -280,6 +308,91 @@ interface BridgeParams {
280
308
  * drop is part of what `nativeFee` pays for.
281
309
  */
282
310
  quote?: BridgeQuote;
311
+ /**
312
+ * How much to pad the quoted LayerZero messaging fee by when sending, in basis
313
+ * points (100 = 1%). Defaults to 500 (5%); 0 sends exactly the quoted fee.
314
+ * Native OFT routes only.
315
+ *
316
+ * The fee a send must carry is whatever the pathway costs at the moment it
317
+ * lands, and `send` demands an exact match: too little reverts, and the
318
+ * endpoint refunds the excess to the sender. Between the quote and the
319
+ * signature that number can only have moved, so the buffer trades a refund
320
+ * round trip for not reverting — and a revert costs the gas either way.
321
+ */
322
+ feeBufferBps?: number;
323
+ /**
324
+ * Where LayerZero returns messaging fee it did not need — the excess left over
325
+ * once the endpoint has taken what the pathway actually cost. Defaults to the
326
+ * sender. Native OFT routes only.
327
+ */
328
+ refundAddress?: string;
329
+ }
330
+ /**
331
+ * A bridge to build but not send — see
332
+ * {@link StableClient.prepareBridgeCalldata}.
333
+ */
334
+ interface PrepareBridgeParams extends BridgeParams {
335
+ /**
336
+ * The address that will sign and send these transactions. Its allowance is
337
+ * what decides whether an approval step is needed, and it is the default
338
+ * recipient and — via {@link BridgeParams.refundAddress} — refund address.
339
+ */
340
+ from: string;
341
+ }
342
+ /** One transaction to sign and broadcast, as built by an unsigned-build helper. */
343
+ interface BridgeCalldataStep {
344
+ /** The chain this must be sent on — always the bridge's source chain */
345
+ chainId: number;
346
+ to: string;
347
+ data: string;
348
+ /** Native token to attach, in wei: 0 for the approvals, the fee for the send */
349
+ value: bigint;
350
+ }
351
+ /**
352
+ * A built, unsigned bridge: the transactions, the quote behind them, and the send
353
+ * they encode in readable form.
354
+ */
355
+ interface BridgeCalldata {
356
+ /**
357
+ * Transactions to send in order, each confirmed before the next: an allowance
358
+ * reset and an approve where the pathway needs them, then the OFT `send`.
359
+ *
360
+ * Approvals appear only when the source chain's adapter pulls the token with
361
+ * `transferFrom` and the current allowance is short. A short but non-zero
362
+ * allowance takes two of them — legacy USDT refuses to overwrite a non-zero
363
+ * allowance with another non-zero value — which is why this is a list and not
364
+ * an optional single approval.
365
+ */
366
+ steps: BridgeCalldataStep[];
367
+ /** The source chain every step must be sent on */
368
+ chainId: number;
369
+ /** Which OFT mesh this send moves through */
370
+ asset: "usdt0" | "xaut0";
371
+ /** The quote these steps were built from, whether supplied or freshly read */
372
+ quote: BridgeQuote;
373
+ /**
374
+ * The `send` step's arguments, decoded — enough to check the calldata against
375
+ * what was intended without re-deriving the ABI encoding.
376
+ */
377
+ send: {
378
+ /** LayerZero endpoint ID of the destination chain */
379
+ dstEid: number;
380
+ /** Recipient address on the destination chain */
381
+ recipient: string;
382
+ /** `recipient`, left-padded to the bytes32 the OFT takes */
383
+ to: string;
384
+ /** Amount debited on the source chain, in the token's smallest unit */
385
+ amountLD: bigint;
386
+ /** Slippage floor: what the adapter quoted it would deliver */
387
+ minAmountLD: bigint;
388
+ /** Encoded LayerZero executor options, including any destination native drop */
389
+ extraOptions: string;
390
+ /** Messaging fee the send carries as its `value`, buffer included */
391
+ nativeFee: bigint;
392
+ lzTokenFee: bigint;
393
+ /** Where the endpoint returns unused fee */
394
+ refundAddress: string;
395
+ };
283
396
  }
284
397
  interface EarnDepositParams {
285
398
  /** Amount of underlying assets to deposit (human-readable) */
@@ -510,6 +623,15 @@ interface StableClient {
510
623
  transfer(params: TransferParams): Promise<OperationResult>;
511
624
  quoteBridge(params: BridgeParams): Promise<BridgeQuote>;
512
625
  bridge(params: BridgeParams): Promise<OperationResult>;
626
+ /**
627
+ * Build a bridge's transactions without signing or sending them — for a
628
+ * backend that quotes, builds and checks while the holder's wallet only signs.
629
+ *
630
+ * Native OFT routes only: LI.FI hands back its own transaction request from
631
+ * its API, so a pair that resolves to LI.FI throws rather than returning
632
+ * something shaped the same but built elsewhere.
633
+ */
634
+ prepareBridgeCalldata(params: PrepareBridgeParams): Promise<BridgeCalldata>;
513
635
  /**
514
636
  * Expected delivery time for a native OFT (LayerZero) bridge, before sending.
515
637
  * Throws for chain pairs with no OFT adapter — LI.FI carries its own ETA.
@@ -570,7 +692,7 @@ interface StableReader {
570
692
  };
571
693
  };
572
694
  }
573
- declare function createStable({ network, rpc: rpcOverride, account, transport, walletClient, earn: earnConfig, merklApiBase, }: StableConfig): StableClient;
695
+ declare function createStable({ network, rpc: rpcOverride, rpcOverrides, account, transport, walletClient, earn: earnConfig, merklApiBase, }: StableConfig): StableClient;
574
696
  declare function createStableReader(config: StableReaderConfig): StableReader;
575
697
 
576
698
  interface ChainConfig {
@@ -628,8 +750,170 @@ declare const BRIDGE_CHAIN_CONFIGS: Partial<Record<Chain, BridgeChainConfig>>;
628
750
  * chain has no OFT deployment matching it.
629
751
  */
630
752
  declare function bridgeAssetFor(cfg: BridgeChainConfig, token: string): BridgeAsset | undefined;
753
+ declare const OFT_ADAPTER_ABI: readonly [{
754
+ readonly name: "quoteSend";
755
+ readonly type: "function";
756
+ readonly inputs: readonly [{
757
+ readonly name: "_sendParam";
758
+ readonly type: "tuple";
759
+ readonly components: readonly [{
760
+ readonly name: "dstEid";
761
+ readonly type: "uint32";
762
+ }, {
763
+ readonly name: "to";
764
+ readonly type: "bytes32";
765
+ }, {
766
+ readonly name: "amountLD";
767
+ readonly type: "uint256";
768
+ }, {
769
+ readonly name: "minAmountLD";
770
+ readonly type: "uint256";
771
+ }, {
772
+ readonly name: "extraOptions";
773
+ readonly type: "bytes";
774
+ }, {
775
+ readonly name: "composeMsg";
776
+ readonly type: "bytes";
777
+ }, {
778
+ readonly name: "oftCmd";
779
+ readonly type: "bytes";
780
+ }];
781
+ }, {
782
+ readonly name: "_payInLzToken";
783
+ readonly type: "bool";
784
+ }];
785
+ readonly outputs: readonly [{
786
+ readonly name: "msgFee";
787
+ readonly type: "tuple";
788
+ readonly components: readonly [{
789
+ readonly name: "nativeFee";
790
+ readonly type: "uint256";
791
+ }, {
792
+ readonly name: "lzTokenFee";
793
+ readonly type: "uint256";
794
+ }];
795
+ }];
796
+ readonly stateMutability: "view";
797
+ }, {
798
+ readonly name: "quoteOFT";
799
+ readonly type: "function";
800
+ readonly inputs: readonly [{
801
+ readonly name: "_sendParam";
802
+ readonly type: "tuple";
803
+ readonly components: readonly [{
804
+ readonly name: "dstEid";
805
+ readonly type: "uint32";
806
+ }, {
807
+ readonly name: "to";
808
+ readonly type: "bytes32";
809
+ }, {
810
+ readonly name: "amountLD";
811
+ readonly type: "uint256";
812
+ }, {
813
+ readonly name: "minAmountLD";
814
+ readonly type: "uint256";
815
+ }, {
816
+ readonly name: "extraOptions";
817
+ readonly type: "bytes";
818
+ }, {
819
+ readonly name: "composeMsg";
820
+ readonly type: "bytes";
821
+ }, {
822
+ readonly name: "oftCmd";
823
+ readonly type: "bytes";
824
+ }];
825
+ }];
826
+ readonly outputs: readonly [{
827
+ readonly name: "oftLimit";
828
+ readonly type: "tuple";
829
+ readonly components: readonly [{
830
+ readonly name: "minAmountLD";
831
+ readonly type: "uint256";
832
+ }, {
833
+ readonly name: "maxAmountLD";
834
+ readonly type: "uint256";
835
+ }];
836
+ }, {
837
+ readonly name: "oftFeeDetails";
838
+ readonly type: "tuple[]";
839
+ readonly components: readonly [{
840
+ readonly name: "feeAmountLD";
841
+ readonly type: "int256";
842
+ }, {
843
+ readonly name: "description";
844
+ readonly type: "string";
845
+ }];
846
+ }, {
847
+ readonly name: "oftReceipt";
848
+ readonly type: "tuple";
849
+ readonly components: readonly [{
850
+ readonly name: "amountSentLD";
851
+ readonly type: "uint256";
852
+ }, {
853
+ readonly name: "amountReceivedLD";
854
+ readonly type: "uint256";
855
+ }];
856
+ }];
857
+ readonly stateMutability: "view";
858
+ }, {
859
+ readonly name: "send";
860
+ readonly type: "function";
861
+ readonly inputs: readonly [{
862
+ readonly name: "_sendParam";
863
+ readonly type: "tuple";
864
+ readonly components: readonly [{
865
+ readonly name: "dstEid";
866
+ readonly type: "uint32";
867
+ }, {
868
+ readonly name: "to";
869
+ readonly type: "bytes32";
870
+ }, {
871
+ readonly name: "amountLD";
872
+ readonly type: "uint256";
873
+ }, {
874
+ readonly name: "minAmountLD";
875
+ readonly type: "uint256";
876
+ }, {
877
+ readonly name: "extraOptions";
878
+ readonly type: "bytes";
879
+ }, {
880
+ readonly name: "composeMsg";
881
+ readonly type: "bytes";
882
+ }, {
883
+ readonly name: "oftCmd";
884
+ readonly type: "bytes";
885
+ }];
886
+ }, {
887
+ readonly name: "_fee";
888
+ readonly type: "tuple";
889
+ readonly components: readonly [{
890
+ readonly name: "nativeFee";
891
+ readonly type: "uint256";
892
+ }, {
893
+ readonly name: "lzTokenFee";
894
+ readonly type: "uint256";
895
+ }];
896
+ }, {
897
+ readonly name: "_refundAddress";
898
+ readonly type: "address";
899
+ }];
900
+ readonly outputs: readonly [];
901
+ readonly stateMutability: "payable";
902
+ }];
631
903
  /** Drop cached pathway configs and observed timings — forces the next estimate to refetch. */
632
904
  declare function clearBridgeEstimateCache(): void;
905
+ /**
906
+ * Encode LayerZero V2 executor options.
907
+ *
908
+ * `gasLimit = 0` tells the executor to use its built-in minimum for lzReceive —
909
+ * matches the Stable bridge tutorial, and is what every plain token transfer wants.
910
+ *
911
+ * A non-zero `nativeDrop` appends the executor's native-drop option: that many wei
912
+ * of the *destination* chain's native token, airdropped to `dropReceiver` when the
913
+ * message is executed. The executor prices it into `quoteSend`'s `nativeFee`, and
914
+ * rejects a drop above the pathway's configured `nativeCap`.
915
+ */
916
+ declare function buildLzOptions(gasLimit?: bigint, nativeDrop?: bigint, dropReceiver?: Address): Hex;
633
917
 
634
918
  declare const STABLE_USDT_ADDRESS: Address;
635
919
  declare const STABLE_VAULT_ADDRESS: Address;
@@ -691,4 +975,4 @@ declare class StableBulkError extends StableError {
691
975
  });
692
976
  }
693
977
 
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 };
978
+ 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 };