@augustdigital/sdk 9.7.1 → 9.9.0

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.
@@ -1188,6 +1188,29 @@ class AugustVaults extends core_1.AugustBase {
1188
1188
  fromBlock: options?.fromBlock,
1189
1189
  });
1190
1190
  }
1191
+ /**
1192
+ * Read a SwapRouter origin code's on-chain registration through this
1193
+ * instance's provider for `chainId`. See {@link getOriginInfo} for the
1194
+ * registration rule and caching.
1195
+ *
1196
+ * @param options - `chainId` and the `bytes32` `originCode` to look up.
1197
+ * @returns {@link IOriginInfo}.
1198
+ * @throws AugustValidationError (`INVALID_CHAIN`) when no provider is
1199
+ * configured for `chainId`; (`INVALID_INPUT`) for a malformed code.
1200
+ * @throws AugustSDKError when the `origins(bytes32)` read fails.
1201
+ * @worstCaseRpcCalls 1 — one `origins(bytes32)` read, cached for 5 minutes.
1202
+ * @example
1203
+ * ```ts
1204
+ * const info = await augustSdk.getOriginInfo({ chainId: 1, originCode });
1205
+ * ```
1206
+ */
1207
+ async getOriginInfo(options) {
1208
+ (0, core_1.assertEvmProviderConfigured)(options.chainId, this.providers, 'getOriginInfo');
1209
+ return (0, core_1.getOriginInfo)({
1210
+ ...options,
1211
+ rpcUrl: this.providers[options.chainId],
1212
+ });
1213
+ }
1191
1214
  /**
1192
1215
  * @function getStakingPositions gets all available reward staking positions
1193
1216
  * @param wallet optionally passed user wallet address
@@ -1,5 +1,5 @@
1
1
  import { type Signer, type Wallet, type TransactionResponse } from 'ethers';
2
- import type { IAddress } from '../../types';
2
+ import { type IAddress } from '../../types';
3
3
  import type { ISwapAndDepositOptions, ISwapRouterDirectDepositOptions, ISwapRouterNativeDepositOptions, ISwapRouterDepositOptions } from '../../types';
4
4
  export type IContractWriteOptions = {
5
5
  target: IAddress;
@@ -28,15 +28,13 @@ export type IContractWriteOptions = {
28
28
  */
29
29
  isDepositWithPermit?: boolean;
30
30
  /**
31
- * Optional: address that receives the vault shares. Defaults to `wallet`.
32
- * Only honored on the SwapRouter dispatch path; legacy adapters mint to `wallet`.
31
+ * @deprecated Ignored — `vaultDeposit` mints to `wallet`. Use
32
+ * {@link swapRouterDeposit}'s `receiver` instead.
33
33
  */
34
34
  receiver?: IAddress;
35
35
  /**
36
- * Optional: slippage tolerance in bps (1 bp = 0.01%) applied to any swap
37
- * quote the SwapRouter dispatch path fetches when `depositAsset` differs
38
- * from the vault's reference asset. Must be in `[0, 10_000)`. Defaults to
39
- * `100` (1%). Ignored for same-asset deposits and legacy adapter paths.
36
+ * @deprecated Ignored — `vaultDeposit` never swaps. Use
37
+ * {@link swapRouterDeposit}'s `slippageBps` instead.
40
38
  */
41
39
  slippageBps?: number;
42
40
  };
@@ -171,18 +169,76 @@ export type ApproveResult =
171
169
  | {
172
170
  kind: 'native';
173
171
  };
172
+ /**
173
+ * Why {@link getDepositRoute} kept a deposit on the vault's native path.
174
+ * `no-origin-code` is what every SDK without `attribution.originCode` gets.
175
+ */
176
+ export type DepositRouteReason = 'no-origin-code' | 'no-router' | 'chain-not-supported' | 'permit' | 'native-token' | 'adapter' | 'vault-not-registered' | 'asset-not-accepted' | 'router-token-not-whitelisted' | 'origin-not-registered';
177
+ /** A deposit's route — the SwapRouter or the vault's native path — and the address to approve. */
178
+ export type IDepositRoute = {
179
+ /**
180
+ * `router`: `SwapRouter.deposit` carrying the instance origin code (a direct
181
+ * deposit, never a swap). `native`: the vault's own deposit path.
182
+ */
183
+ via: 'native' | 'router';
184
+ /** Address to approve for the deposit token; `null` for a native-token deposit (`msg.value`). */
185
+ spender: IAddress | null;
186
+ /** Why the deposit stays native; absent on the router route. */
187
+ reason?: DepositRouteReason;
188
+ };
189
+ /** Options for {@link getDepositRoute} — the same fields `vaultDeposit` reads. */
190
+ export type IGetDepositRouteOptions = Pick<IContractWriteOptions, 'target' | 'depositAsset' | 'chainId' | 'isDepositWithPermit'>;
191
+ /**
192
+ * Resolve whether a deposit can go through the SwapRouter carrying the
193
+ * instance origin code (`router`) or takes the vault's native path
194
+ * (`native`), and which address to approve. Read-only. `vaultDeposit` and
195
+ * `approve` follow this route, so integrators that manage approvals
196
+ * themselves must approve `route.spender`, not the vault.
197
+ *
198
+ * The route is `router` only when an origin code is configured, the chain is
199
+ * Ethereum mainnet ({@link ORIGIN_ATTRIBUTION_CHAINS}) and has a SwapRouter,
200
+ * the vault is registered on it, the vault accepts the asset directly (its
201
+ * reference asset, or a Tokenized Vault V2 whitelisted asset — deposited
202
+ * as-is, never swapped), the router whitelists the asset, the deposit is not a
203
+ * permit, native-token or adapter deposit, and the code is registered.
204
+ * Otherwise it is `native` with a `reason`.
205
+ *
206
+ * @param signer - ethers `Signer` / `Wallet` used for the reads.
207
+ * @param options - {@link IGetDepositRouteOptions}; `depositAsset` defaults
208
+ * to the vault's underlying.
209
+ * @returns {@link IDepositRoute}.
210
+ * @throws AugustValidationError on an invalid `target`, or an unregistered
211
+ * code under `attribution.strictOrigin`.
212
+ * @throws AugustSDKError when a backend, vault or router read fails.
213
+ * @worstCaseRpcCalls 7 — the backend vault row, `asset()`, the router's
214
+ * `vaultInfo`, the vault's `assetsWhitelistAddress()` and
215
+ * `getWhitelistedAssets()` (Tokenized Vault V2 non-reference asset only),
216
+ * the router's `whitelistedTokens(asset)`, and the router's `origins`. The
217
+ * router reads and `getWhitelistedAssets()` are cached for 5 minutes. No
218
+ * router read without a code or off Ethereum mainnet.
219
+ * @example
220
+ * ```ts
221
+ * const route = await augustSdk.evm.getDepositRoute({ target: vault, depositAsset: usdt });
222
+ * if (route.spender) await approveToken(usdt, route.spender, amount);
223
+ * ```
224
+ */
225
+ export declare function getDepositRoute(signer: Signer | Wallet, options: IGetDepositRouteOptions): Promise<IDepositRoute>;
174
226
  /**
175
227
  * Approve a vault (or the appropriate adapter wrapper) to spend a token
176
228
  * ahead of a separate deposit call. Spender routing mirrors
177
229
  * {@link vaultDeposit} (multi-asset → vault, adapter → wrapper, standard →
178
- * vault). Returns `undefined` when the existing allowance already covers
179
- * `amount` **or** when the deposit asset is native.
230
+ * vault, SwapRouter when {@link getDepositRoute} routes there). Returns
231
+ * `undefined` when the existing allowance already covers `amount` **or**
232
+ * when the deposit asset is native.
180
233
  *
181
234
  * @returns Transaction hash when an approval was sent, `undefined` when
182
235
  * the existing allowance already covers `amount` or the deposit asset is
183
236
  * native (no ERC-20 allowance applies). Use {@link approve} for a
184
237
  * discriminated `ApproveResult` if you need to tell those two cases apart.
185
238
  * @throws AugustValidationError on invalid wallet/target/amount.
239
+ * @throws AugustValidationError when `attribution.strictOrigin` is set and the
240
+ * configured origin code is not registered on the SwapRouter (the spender
241
+ * follows {@link getDepositRoute}).
186
242
  *
187
243
  * @example
188
244
  * ```ts
@@ -225,6 +281,9 @@ export declare function vaultApprove(signer: Signer | Wallet, options: IContract
225
281
  * ```
226
282
  *
227
283
  * @throws AugustValidationError on invalid wallet/target/amount.
284
+ * @throws AugustValidationError when `attribution.strictOrigin` is set and the
285
+ * configured origin code is not registered on the SwapRouter (the spender
286
+ * follows {@link getDepositRoute}).
228
287
  * @throws AugustSDKError when the approval submission fails.
229
288
  */
230
289
  export declare function approve(signer: Signer | Wallet, options: IContractWriteOptions): Promise<ApproveResult>;
@@ -234,6 +293,11 @@ export declare function approve(signer: Signer | Wallet, options: IContractWrite
234
293
  * Paraswap adapter, native-token wrapper, depositWithPermit) based on the
235
294
  * vault version and `depositAsset`.
236
295
  *
296
+ * With `attribution.originCode` configured, a deposit the SwapRouter can take
297
+ * directly goes through `SwapRouter.deposit` carrying that code, and the
298
+ * router is approved instead of the vault — see {@link getDepositRoute} for
299
+ * the rules and the fallback reasons. Without a code nothing changes.
300
+ *
237
301
  * Amounts are encoded against the **deposit token's** decimals, not the
238
302
  * vault's share decimals. The SDK reads the appropriate decimals via the
239
303
  * vault metadata and the asset's ERC-20.
@@ -249,6 +313,8 @@ export declare function approve(signer: Signer | Wallet, options: IContractWrite
249
313
  * @returns Deposit transaction hash.
250
314
  * @throws AugustValidationError on invalid wallet/target/amount or missing
251
315
  * adapter config when `depositAsset` differs from the vault underlying.
316
+ * @throws AugustValidationError when `attribution.strictOrigin` is set and the
317
+ * configured origin code is not registered on the SwapRouter.
252
318
  * @throws AugustSDKError when the deposit submission or on-chain call fails.
253
319
  *
254
320
  * @example
@@ -486,7 +552,9 @@ export declare function rwaRedeemAsset(signer: Signer | Wallet, options: IRwaRed
486
552
  * @returns The transaction hash of the `swapAndDeposit` call.
487
553
  *
488
554
  * @throws {@link AugustValidationError} for unsupported chains, invalid
489
- * addresses, empty/oversized swap arrays.
555
+ * addresses, empty/oversized swap arrays, or an origin code not registered on
556
+ * the router (a per-call code, or the instance code under
557
+ * `attribution.strictOrigin`), before any approval.
490
558
  * @throws {@link AugustSDKError} on unrecoverable contract or RPC failure.
491
559
  *
492
560
  * @example
@@ -526,7 +594,11 @@ export declare function swapAndDeposit(signer: Signer | Wallet, options: ISwapAn
526
594
  * @returns The transaction hash of the `deposit` call.
527
595
  *
528
596
  * @throws {@link AugustValidationError} for unsupported chains, invalid
529
- * addresses, or zero amount.
597
+ * addresses, zero amount, or an origin code not registered on the router (a
598
+ * per-call code, or the instance code under `attribution.strictOrigin`),
599
+ * before any approval; with code `ACCOUNT_NOT_FUNDED` when the account cannot
600
+ * cover gas.
601
+ * @throws {@link AugustSDKError} on unrecoverable contract or RPC failure.
530
602
  */
531
603
  export declare function depositViaSwapRouter(signer: Signer | Wallet, options: ISwapRouterDirectDepositOptions): Promise<string>;
532
604
  /**
@@ -550,7 +622,11 @@ export declare function depositViaSwapRouter(signer: Signer | Wallet, options: I
550
622
  * @returns The transaction hash of the `depositNativeToken` call.
551
623
  *
552
624
  * @throws {@link AugustValidationError} for unsupported chains, invalid
553
- * addresses, or zero amount.
625
+ * addresses, zero amount, or an origin code not registered on the router (a
626
+ * per-call code, or the instance code under `attribution.strictOrigin`),
627
+ * before any approval; with code `ACCOUNT_NOT_FUNDED` when the account cannot
628
+ * cover gas.
629
+ * @throws {@link AugustSDKError} on unrecoverable contract or RPC failure.
554
630
  */
555
631
  export declare function depositNativeViaSwapRouter(signer: Signer | Wallet, options: ISwapRouterNativeDepositOptions): Promise<string>;
556
632
  /**
@@ -600,21 +676,22 @@ export declare function isNativeSwapRouterDepositSupported(chainId: number, vaul
600
676
  }): Promise<boolean>;
601
677
  /**
602
678
  * Deposit into an August vault through the on-chain `SwapRouter`, selecting the
603
- * correct router path from the deposit asset. This is the high-level, explicit
604
- * counterpart to the SwapRouter branch inside {@link vaultDeposit}.
679
+ * correct router path from the deposit asset.
605
680
  *
606
- * Where `vaultDeposit` decides whether to use the SwapRouter from the
607
- * `VAULTS_USING_SWAP_ROUTER` allowlist, this function always routes through the
608
- * SwapRouter because the caller asked it to. Making the intent explicit is the
681
+ * {@link vaultDeposit} never swaps; this function always routes through the
682
+ * SwapRouter, because the caller asked it to. Keeping swaps opt-in is the
609
683
  * point: a native-deposit vault (e.g. a multi-asset Tokenized Vault V2 whose
610
684
  * non-reference assets are accepted directly) is never accidentally swapped —
611
- * the regression that implicit, allowlist-driven routing caused. Use
612
- * `vaultDeposit` for native / adapter deposits and this for SwapRouter deposits.
685
+ * the regression that implicit, allowlist-driven routing inside `vaultDeposit`
686
+ * caused before it was removed. Use `vaultDeposit` for native / adapter
687
+ * deposits and this for SwapRouter deposits.
613
688
  *
614
689
  * The vault's reference asset and its decimals are read on-chain (never trusted
615
690
  * from the caller — a wrong reference asset would mis-route the swap). The path
616
691
  * is then chosen from `depositAsset`:
617
- * - equals the reference asset → direct router deposit, no swap
692
+ * - equals the reference asset, or is an asset a Tokenized Vault V2 accepts
693
+ * as-is that the router also whitelists (e.g. USDT into Sentora USD) →
694
+ * direct router deposit, no swap and no swap fee
618
695
  * ({@link depositViaSwapRouter});
619
696
  * - the zero address → native-token deposit ({@link depositNativeViaSwapRouter}),
620
697
  * valid only when the reference asset is the chain's wrapped-native token —
@@ -625,23 +702,36 @@ export declare function isNativeSwapRouterDepositSupported(chainId: number, vaul
625
702
  * the chain's whitelisted aggregator, fail-closed on router/selector drift)
626
703
  * bundled into {@link swapAndDeposit}.
627
704
  *
628
- * An `originCode` is forwarded verbatim to whichever of those three entry points
629
- * runs, so a partner's origin fee accrues on every path. Omitting it sends the
630
- * all-zero sentinel, which the router reads as "no origin fee".
705
+ * The origin code — the per-call `originCode`, else the SDK instance's
706
+ * `attribution.originCode` on Ethereum mainnet, else the all-zero sentinel
707
+ * ("no origin fee") — is forwarded to whichever of those three entry points
708
+ * runs, so a partner's origin fee accrues on every path.
631
709
  *
632
710
  * Side effects: reads tokenized-vault metadata, the vault's reference asset and
633
- * decimals, and (on the swap path) one Paraswap quote; sends one ERC-20
634
- * `approve` to the SwapRouter when allowance is short, then the deposit tx.
711
+ * decimals, for a Tokenized Vault V2 non-reference asset the router's
712
+ * `vaultInfo` and `whitelistedTokens` and the vault's assets whitelist, the
713
+ * origin code's registration, and (on the swap path) one Paraswap quote;
714
+ * sends one ERC-20 `approve` to the SwapRouter when allowance is short, then
715
+ * the deposit tx.
635
716
  *
636
717
  * @param signer - ethers `Signer` or `Wallet` that signs the approval + deposit.
637
718
  * @param options - {@link ISwapRouterDepositOptions}.
638
719
  * @returns The transaction hash of the router deposit call.
639
720
  * @throws {@link AugustValidationError} for an unsupported chain (no SwapRouter
640
721
  * deployment), an invalid vault or deposit-asset address, a missing or zero
641
- * amount, a native deposit into a non-wrapped-native vault, or drift between
642
- * the aggregator quote and the on-chain router whitelist.
643
- * @worstCaseRpcCalls 5 on the swap path — tokenized-vault metadata, reference
644
- * asset + decimals, deposit-token decimals, the quote, and the allowance read.
722
+ * amount, a native deposit into a non-wrapped-native vault, drift between
723
+ * the aggregator quote and the on-chain router whitelist, or an origin code
724
+ * not registered on the router (a per-call code, or the instance code under
725
+ * `attribution.strictOrigin`), before any approval; with code
726
+ * `ACCOUNT_NOT_FUNDED` when the account cannot cover gas.
727
+ * @throws {@link AugustSDKError} on unrecoverable contract or RPC failure.
728
+ * @worstCaseRpcCalls 10 on the swap path into a Tokenized Vault V2 —
729
+ * tokenized-vault metadata, reference asset + decimals, deposit-token
730
+ * decimals, the router's `vaultInfo` and `whitelistedTokens`, the vault's
731
+ * `assetsWhitelistAddress()` and `getWhitelistedAssets()`, the quote, the
732
+ * origin code's `origins` (none for the zero sentinel), and the allowance
733
+ * read. The router reads and `getWhitelistedAssets()` are cached for 5
734
+ * minutes.
645
735
  * @example
646
736
  * ```ts
647
737
  * // USDT deposited into a USDC-reference vault → swapped to USDC en route.