@forevermoney/sdk 0.5.1 → 0.5.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/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.2 — 2026-09-16
4
+
5
+ - Added opt-in stake rounding adjustment to Subtensor bridge preparation, with an explicit disable option and adjusted amount/plan metadata. Searches only on `StrandedStake`, preserves minimum output, requotes candidates and checks source balances, minimum remainders and partner-fee allocations. Approval-required plans are explicitly marked as not yet simulated.
6
+ - Exported the same provider-neutral search (`estimateRoundedStake`), nested revert decoder and dust minimum helper so integrations do not need their own rounding implementation.
7
+
3
8
  ## 0.5.1 — 2026-09-16
4
9
 
5
10
  - Added optional `minAmountOutWei` to Subtensor-to-EVM bridge requests. Callers can explicitly bound output slippage, including staking rounding dust. Defaults to the input amount; rejects zero, negative, non-bigint, and above-input minima before RPC calls. The same minimum is used for gas estimation and final calldata, for single- and multi-validator routes with or without partner fees.
package/README.md CHANGED
@@ -442,3 +442,59 @@ steps are in [`docs/releasing.md`](./docs/releasing.md).
442
442
  ### Minimum bridge output
443
443
 
444
444
  Subtensor-to-EVM builders and preparation methods accept optional `minAmountOutWei` (destination token units, 18 decimals, after partner fees). It must be positive and no greater than `amountWei`; omission preserves the exact-output default. Choose the minimum explicitly to cover your acceptable slippage or native staking rounding dust. The SDK uses the same value for gas estimation and final transaction calldata. For example, `minAmountOutWei: amountWei - 4n * EVM_WEI_PER_RAO` allows four native RAO of dust when the amount exceeds that budget. This does not change the input amount or approval amount.
445
+
446
+ ### Optional stake rounding adjustment
447
+
448
+ `client.bridge.prepareSubtensorToEvm` (and `prepareSubtensorToBase`) accepts
449
+ `stakeRounding: { enabled: true, positions, minStakeRao }`. Omit it, pass `false`,
450
+ or set `enabled: false` to preserve the exact requested input with no search.
451
+ Synchronous `build*Plan` methods never simulate or adjust amounts.
452
+
453
+ ```ts
454
+ import { stakedMinimumOutput } from '@forevermoney/sdk'
455
+
456
+ const prepared = await client.bridge.prepareSubtensorToEvm({
457
+ evmChain: 'base',
458
+ asset: 'sn80',
459
+ source: 'staked',
460
+ sender,
461
+ recipient,
462
+ amountWei,
463
+ stakePulls,
464
+ minAmountOutWei: stakedMinimumOutput(amountWei, stakePulls.length),
465
+ stakeRounding: {
466
+ enabled: true,
467
+ positions, // [{ hotkey, stakeRao }], freshly read source balances
468
+ minStakeRao: 0n, // caller's minimum positive remainder per validator
469
+ },
470
+ })
471
+ ```
472
+
473
+ Only `StrandedStake(bytes32,uint256)` triggers adjustment. The SDK reduces the
474
+ named validator's pull by one alpha base unit per attempt, for at most eight
475
+ reductions, re-quotes fees and simulates the exact candidate. It keeps the
476
+ **original absolute minimum output**, checks balances and remaining stake,
477
+ including the partner fee apportioned on top, and propagates unrelated errors.
478
+ The search stops if no valid candidate fits that budget. `stakedMinimumOutput`
479
+ provides an explicit dust tolerance of two base units per source plus two for
480
+ the deposit; tiny inputs retain an exact minimum. It is not a guarantee of
481
+ successful execution.
482
+
483
+ When enabled, `prepared.stakeRounding` reports `requestedAmountWei`, the actual
484
+ `amountWei`, `minAmountOutWei`, `pulls`, and `simulationComplete`. Display the
485
+ returned amount and use **the returned plan**, rather than rebuilding from the
486
+ original request. If approval is required, `simulationComplete` is false:
487
+ confirm approval, refresh balances, and prepare again before sending the bridge.
488
+ Revalidate before signing; if the amount changes again, show it for review.
489
+ Keep the original `minAmountOutWei` when re-preparing an adjusted amount so
490
+ successive attempts cannot gradually lower output protection. Never automatically
491
+ retry a broadcast transaction.
492
+
493
+ For custom ethers/wallet quote flows, the SDK also exports
494
+ `estimateRoundedStake({ amountWei, minAmountOutWei, pulls, positions,
495
+ minStakeRao, adjustRounding, partnerFeeBps, quoteAndEstimate, isActive })`.
496
+ `adjustRounding` defaults to true **for this explicitly invoked helper**; false
497
+ performs one exact estimate. Its callback must quote and estimate the supplied
498
+ candidate and minimum, and must never sign or broadcast. An optional `isActive`
499
+ callback stops obsolete work between requests. `strandedStakeSource(error)`
500
+ decodes nested RPC/ethers/viem errors for UI error messages.