@augustdigital/sdk 8.6.1 → 8.7.1
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/lib/adapters/evm/index.d.ts +24 -1
- package/lib/adapters/evm/index.js +26 -0
- package/lib/adapters/solana/vault.actions.d.ts +18 -0
- package/lib/adapters/solana/vault.actions.js +43 -2
- package/lib/core/analytics/method-taxonomy.js +2 -0
- package/lib/core/analytics/version.d.ts +1 -1
- package/lib/core/analytics/version.js +1 -1
- package/lib/core/constants/swap-router.d.ts +26 -8
- package/lib/core/constants/swap-router.js +31 -15
- package/lib/core/helpers/swap-router.d.ts +16 -4
- package/lib/core/helpers/swap-router.js +19 -6
- package/lib/core/helpers/vaults.d.ts +23 -1
- package/lib/core/helpers/vaults.js +24 -2
- package/lib/main.d.ts +26 -0
- package/lib/main.js +22 -0
- package/lib/modules/vaults/main.d.ts +46 -0
- package/lib/modules/vaults/main.js +88 -7
- package/lib/modules/vaults/write.actions.d.ts +51 -2
- package/lib/modules/vaults/write.actions.js +149 -44
- package/lib/sdk.d.ts +1181 -923
- package/lib/services/subgraph/schema.d.ts +45 -0
- package/lib/services/subgraph/schema.js +75 -0
- package/lib/services/subgraph/vaults.d.ts +3 -1
- package/lib/services/subgraph/vaults.js +148 -53
- package/lib/types/vaults.d.ts +37 -0
- package/package.json +1 -1
|
@@ -771,24 +771,34 @@ class AugustVaults extends core_1.AugustBase {
|
|
|
771
771
|
}
|
|
772
772
|
return formattedStandard;
|
|
773
773
|
};
|
|
774
|
-
// If vault is provided, return history for that vault
|
|
774
|
+
// If vault is provided, return history for that vault. This path is
|
|
775
|
+
// EVM-only (see fetchVaultHistory → getSubgraphUserHistory); a non-EVM
|
|
776
|
+
// vault address would drive eth_chainId against a Solana/Stellar RPC.
|
|
775
777
|
if (vault) {
|
|
776
|
-
finalArray =
|
|
778
|
+
finalArray = (0, ethers_1.isAddress)(vault)
|
|
779
|
+
? await fetchVaultHistory(vault, chainId)
|
|
780
|
+
: [];
|
|
777
781
|
}
|
|
778
782
|
else {
|
|
779
783
|
// Fetch all vaults
|
|
780
784
|
const allVaults = await (0, core_1.fetchTokenizedVaults)(undefined, this.headers, false, false);
|
|
781
|
-
// If chainId is provided, return history for all vaults on that chain
|
|
785
|
+
// If chainId is provided, return history for all vaults on that chain.
|
|
786
|
+
// EVM-only: skip non-EVM (Solana/Stellar) vault addresses.
|
|
782
787
|
if (chainId) {
|
|
783
|
-
const vaultsPerChain = allVaults.filter((v) => v.chain === chainId);
|
|
788
|
+
const vaultsPerChain = allVaults.filter((v) => v.chain === chainId && (0, ethers_1.isAddress)(v.address));
|
|
784
789
|
const vaultResponses = await Promise.all(vaultsPerChain.map((v) => fetchVaultHistory(v.address, v.chain)));
|
|
785
790
|
const flattened = vaultResponses.flat();
|
|
786
791
|
finalArray = flattened;
|
|
787
792
|
}
|
|
788
793
|
else {
|
|
789
|
-
// Else, fetch all history for all vaults across all initialized chains
|
|
790
|
-
//
|
|
791
|
-
|
|
794
|
+
// Else, fetch all history for all vaults across all initialized chains.
|
|
795
|
+
// Gate on isAddress(v.address): the Solana provider is registered under
|
|
796
|
+
// chainId -1, so without this a Solana vault passes `providers?.[v.chain]`
|
|
797
|
+
// and gets routed into the EVM subgraph path, throwing
|
|
798
|
+
// "eth_chainId is not available on SOLANA_MAINNET" on every fetch.
|
|
799
|
+
// LayerZero vaults query subgraphs directly and don't need a provider.
|
|
800
|
+
const vaultsPerAvailableProviders = allVaults.filter((v) => (0, ethers_1.isAddress)(v.address) &&
|
|
801
|
+
(this.providers?.[v?.chain] || (0, deposits_1.isLayerZeroVault)(v.address)));
|
|
792
802
|
const vaultResponses = await Promise.all(vaultsPerAvailableProviders.map((v) => fetchVaultHistory(v.address, v.chain)));
|
|
793
803
|
const flattened = vaultResponses.flat();
|
|
794
804
|
finalArray = flattened;
|
|
@@ -905,6 +915,77 @@ class AugustVaults extends core_1.AugustBase {
|
|
|
905
915
|
core_1.Logger.log.info('getUserTransfers', `${wallet}::${finalArray.length}`);
|
|
906
916
|
return finalArray;
|
|
907
917
|
}
|
|
918
|
+
/**
|
|
919
|
+
* Fetch a vault's deposit/withdrawal activity across every participant.
|
|
920
|
+
*
|
|
921
|
+
* This is the vault-wide counterpart to {@link getUserHistory}: instead of
|
|
922
|
+
* filtering the subgraph to one wallet, it returns every deposit,
|
|
923
|
+
* withdrawal-request, and processed-withdrawal event for the pool. Use it to
|
|
924
|
+
* answer flow questions ("how many deposits in the last 7 days", "net flow
|
|
925
|
+
* this week") that point-in-time TVL cannot.
|
|
926
|
+
*
|
|
927
|
+
* Rows are read from the Goldsky subgraph, paginated internally so busy
|
|
928
|
+
* vaults are not truncated at the 1000-row page cap. When `sinceTs` is
|
|
929
|
+
* supplied the reader stops paging once it passes the window boundary, so a
|
|
930
|
+
* short lookback stays cheap even on high-volume vaults.
|
|
931
|
+
*
|
|
932
|
+
* @param params - Query parameters.
|
|
933
|
+
* @param params.vault - Vault (pool) address to read activity for.
|
|
934
|
+
* @param params.chainId - Chain id of the vault; falls back to the active
|
|
935
|
+
* network when omitted. Required for the subgraph lookup.
|
|
936
|
+
* @param params.sinceTs - Lower bound (inclusive) as a Unix timestamp in
|
|
937
|
+
* seconds. Events at or after this time are returned.
|
|
938
|
+
* @param params.untilTs - Upper bound (inclusive) as a Unix timestamp in
|
|
939
|
+
* seconds. Events at or before this time are returned.
|
|
940
|
+
* @param params.types - Restrict to a subset of event types (e.g.
|
|
941
|
+
* `['deposit']`). Returns all types when omitted.
|
|
942
|
+
* @returns Activity items sorted oldest-first, each with a normalized
|
|
943
|
+
* `amount`, actor `address`, `type`, and `transactionHash`.
|
|
944
|
+
* @throws If `vault` is not a valid address, or no chain id can be resolved.
|
|
945
|
+
* @example
|
|
946
|
+
* ```ts
|
|
947
|
+
* const weekAgo = Math.floor(Date.now() / 1000) - 7 * 86_400;
|
|
948
|
+
* const deposits = await sdk.getVaultActivity({
|
|
949
|
+
* vault: '0x36eDbF0C834591BFdfCaC0Ef9605528c75c406aA',
|
|
950
|
+
* chainId: 143,
|
|
951
|
+
* sinceTs: weekAgo,
|
|
952
|
+
* types: ['deposit'],
|
|
953
|
+
* });
|
|
954
|
+
* console.log(`${deposits.length} deposits in the last 7 days`);
|
|
955
|
+
* ```
|
|
956
|
+
*/
|
|
957
|
+
async getVaultActivity({ vault, chainId, sinceTs, untilTs, types, }) {
|
|
958
|
+
if (!(0, ethers_1.isAddress)(vault))
|
|
959
|
+
throw new Error(`Vault parameter is not an address: ${String(vault)}`);
|
|
960
|
+
const _chainId = chainId || this.activeNetwork?.chainId;
|
|
961
|
+
if (!_chainId) {
|
|
962
|
+
throw new Error('Chain ID is required for getVaultActivity. Pass chainId explicitly or configure an active network.');
|
|
963
|
+
}
|
|
964
|
+
const provider = (0, core_1.createProvider)(this.providers?.[_chainId]);
|
|
965
|
+
const raw = await (0, vaults_1.getSubgraphVaultHistory)(provider, vault, undefined, {
|
|
966
|
+
sinceTs,
|
|
967
|
+
});
|
|
968
|
+
const typeFilter = types?.length ? new Set(types) : undefined;
|
|
969
|
+
return raw
|
|
970
|
+
.map((h) => ({
|
|
971
|
+
timestamp: Number(h.timestamp_),
|
|
972
|
+
address: h.address,
|
|
973
|
+
amount: (0, core_1.toNormalizedBn)(BigInt(h.amount), h.decimals),
|
|
974
|
+
pool: h.contractId_,
|
|
975
|
+
chainId: _chainId,
|
|
976
|
+
type: h.type,
|
|
977
|
+
transactionHash: h.transactionHash_,
|
|
978
|
+
}))
|
|
979
|
+
.filter((h) => {
|
|
980
|
+
if (sinceTs !== undefined && h.timestamp < sinceTs)
|
|
981
|
+
return false;
|
|
982
|
+
if (untilTs !== undefined && h.timestamp > untilTs)
|
|
983
|
+
return false;
|
|
984
|
+
if (typeFilter && !typeFilter.has(h.type))
|
|
985
|
+
return false;
|
|
986
|
+
return true;
|
|
987
|
+
});
|
|
988
|
+
}
|
|
908
989
|
/**
|
|
909
990
|
* @function getStakingPositions gets all available reward staking positions
|
|
910
991
|
* @param wallet optionally passed user wallet address
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Signer, type Wallet, type TransactionResponse } from 'ethers';
|
|
2
2
|
import type { IAddress } from '../../types';
|
|
3
|
-
import type { ISwapAndDepositOptions, ISwapRouterDirectDepositOptions, ISwapRouterNativeDepositOptions } from '../../types';
|
|
3
|
+
import type { ISwapAndDepositOptions, ISwapRouterDirectDepositOptions, ISwapRouterNativeDepositOptions, ISwapRouterDepositOptions } from '../../types';
|
|
4
4
|
export type IContractWriteOptions = {
|
|
5
5
|
target: IAddress;
|
|
6
6
|
wallet: IAddress;
|
|
@@ -76,7 +76,6 @@ export declare function resolveSpender(args: {
|
|
|
76
76
|
isMultiAssetVault: boolean;
|
|
77
77
|
isAdapterDeposit: boolean;
|
|
78
78
|
adapterWrapperAddress?: IAddress;
|
|
79
|
-
swapRouterAddress?: IAddress;
|
|
80
79
|
}): IAddress;
|
|
81
80
|
/** @internal */
|
|
82
81
|
export declare function validateAmountPrecision(amount: string | bigint | number): void;
|
|
@@ -438,3 +437,53 @@ export declare function depositViaSwapRouter(signer: Signer | Wallet, options: I
|
|
|
438
437
|
* addresses, or zero amount.
|
|
439
438
|
*/
|
|
440
439
|
export declare function depositNativeViaSwapRouter(signer: Signer | Wallet, options: ISwapRouterNativeDepositOptions): Promise<string>;
|
|
440
|
+
/**
|
|
441
|
+
* Deposit into an August vault through the on-chain `SwapRouter`, selecting the
|
|
442
|
+
* correct router path from the deposit asset. This is the high-level, explicit
|
|
443
|
+
* counterpart to the SwapRouter branch inside {@link vaultDeposit}.
|
|
444
|
+
*
|
|
445
|
+
* Where `vaultDeposit` decides whether to use the SwapRouter from the
|
|
446
|
+
* `VAULTS_USING_SWAP_ROUTER` allowlist, this function always routes through the
|
|
447
|
+
* SwapRouter because the caller asked it to. Making the intent explicit is the
|
|
448
|
+
* point: a native-deposit vault (e.g. a multi-asset Tokenized Vault V2 whose
|
|
449
|
+
* non-reference assets are accepted directly) is never accidentally swapped —
|
|
450
|
+
* the regression that implicit, allowlist-driven routing caused. Use
|
|
451
|
+
* `vaultDeposit` for native / adapter deposits and this for SwapRouter deposits.
|
|
452
|
+
*
|
|
453
|
+
* The vault's reference asset and its decimals are read on-chain (never trusted
|
|
454
|
+
* from the caller — a wrong reference asset would mis-route the swap). The path
|
|
455
|
+
* is then chosen from `depositAsset`:
|
|
456
|
+
* - equals the reference asset → direct router deposit, no swap
|
|
457
|
+
* ({@link depositViaSwapRouter});
|
|
458
|
+
* - the zero address → native-token deposit ({@link depositNativeViaSwapRouter}),
|
|
459
|
+
* valid only when the reference asset is the chain's wrapped-native token;
|
|
460
|
+
* - any other ERC-20 → a swap to the reference asset (Paraswap quote pinned to
|
|
461
|
+
* the chain's whitelisted aggregator, fail-closed on router/selector drift)
|
|
462
|
+
* bundled into {@link swapAndDeposit}.
|
|
463
|
+
*
|
|
464
|
+
* Side effects: reads tokenized-vault metadata, the vault's reference asset and
|
|
465
|
+
* decimals, and (on the swap path) one Paraswap quote; sends one ERC-20
|
|
466
|
+
* `approve` to the SwapRouter when allowance is short, then the deposit tx.
|
|
467
|
+
*
|
|
468
|
+
* @param signer - ethers `Signer` or `Wallet` that signs the approval + deposit.
|
|
469
|
+
* @param options - {@link ISwapRouterDepositOptions}.
|
|
470
|
+
* @returns The transaction hash of the router deposit call.
|
|
471
|
+
* @throws {@link AugustValidationError} for an unsupported chain (no SwapRouter
|
|
472
|
+
* deployment), an invalid vault or deposit-asset address, a missing or zero
|
|
473
|
+
* amount, a native deposit into a non-wrapped-native vault, or drift between
|
|
474
|
+
* the aggregator quote and the on-chain router whitelist.
|
|
475
|
+
* @worstCaseRpcCalls 5 on the swap path — tokenized-vault metadata, reference
|
|
476
|
+
* asset + decimals, deposit-token decimals, the quote, and the allowance read.
|
|
477
|
+
* @example
|
|
478
|
+
* ```ts
|
|
479
|
+
* // USDT deposited into a USDC-reference vault → swapped to USDC en route.
|
|
480
|
+
* const hash = await augustSdk.evm.swapRouterDeposit({
|
|
481
|
+
* chainId: 1,
|
|
482
|
+
* vault: '0xe9b725010a9e419412ed67d0fa5f3a5f40159d32',
|
|
483
|
+
* depositAsset: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
|
|
484
|
+
* amount: '100',
|
|
485
|
+
* slippageBps: 50,
|
|
486
|
+
* });
|
|
487
|
+
* ```
|
|
488
|
+
*/
|
|
489
|
+
export declare function swapRouterDeposit(signer: Signer | Wallet, options: ISwapRouterDepositOptions): Promise<string>;
|
|
@@ -18,6 +18,7 @@ exports.rwaRedeemAsset = rwaRedeemAsset;
|
|
|
18
18
|
exports.swapAndDeposit = swapAndDeposit;
|
|
19
19
|
exports.depositViaSwapRouter = depositViaSwapRouter;
|
|
20
20
|
exports.depositNativeViaSwapRouter = depositNativeViaSwapRouter;
|
|
21
|
+
exports.swapRouterDeposit = swapRouterDeposit;
|
|
21
22
|
const ethers_1 = require("ethers");
|
|
22
23
|
const abis_1 = require("../../abis");
|
|
23
24
|
const core_1 = require("../../core");
|
|
@@ -64,8 +65,6 @@ async function resolveDepositTokenDecimals(args) {
|
|
|
64
65
|
}
|
|
65
66
|
/** @internal */
|
|
66
67
|
function resolveSpender(args) {
|
|
67
|
-
if (args.swapRouterAddress)
|
|
68
|
-
return args.swapRouterAddress;
|
|
69
68
|
if (args.isMultiAssetVault)
|
|
70
69
|
return args.target;
|
|
71
70
|
if (args.isAdapterDeposit && args.adapterWrapperAddress)
|
|
@@ -245,16 +244,11 @@ async function approveCore(signer, options) {
|
|
|
245
244
|
if (isNativeToken)
|
|
246
245
|
return { kind: 'native' };
|
|
247
246
|
const isAdapterDeposit = actualDepositAsset.toLowerCase() !== underlyingAsset.toLowerCase();
|
|
248
|
-
const resolvedChainId = options.chainId ?? tokenizedVault?.chain;
|
|
249
|
-
const swapRouterAddress = resolvedChainId !== undefined && (0, core_1.vaultUsesSwapRouter)(target)
|
|
250
|
-
? (0, core_1.getSwapRouterAddress)(resolvedChainId)
|
|
251
|
-
: undefined;
|
|
252
247
|
const spenderAddress = resolveSpender({
|
|
253
248
|
target,
|
|
254
249
|
isMultiAssetVault,
|
|
255
250
|
isAdapterDeposit,
|
|
256
251
|
adapterWrapperAddress: adapterConfig?.wrapperAddress,
|
|
257
|
-
swapRouterAddress,
|
|
258
252
|
});
|
|
259
253
|
const depositTokenDecimals = await resolveDepositTokenDecimals({
|
|
260
254
|
actualDepositAsset,
|
|
@@ -470,26 +464,12 @@ async function vaultDeposit(signer, options) {
|
|
|
470
464
|
actualDepositAsset === '0x0000000000000000000000000000000000000000';
|
|
471
465
|
const isAdapterDeposit = actualDepositAsset.toLowerCase() !== underlyingAsset.toLowerCase();
|
|
472
466
|
const isMultiAssetVault = vaultVersion === 'evm-2';
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
if (wantsSwapRouter && !swapRouterAddress) {
|
|
480
|
-
throw new core_1.AugustValidationError('INVALID_CHAIN', resolvedChainId === undefined
|
|
481
|
-
? `vaultDeposit: vault ${target} requires SwapRouter routing but chainId could not be resolved — pass options.chainId or ensure tokenized-vault metadata is loaded`
|
|
482
|
-
: `vaultDeposit: vault ${target} is registered on SwapRouter but no SwapRouter is deployed for chainId ${resolvedChainId}`, { context: { vault: target, chainId: resolvedChainId } });
|
|
483
|
-
}
|
|
484
|
-
// SwapRouter has no permit variant; throw rather than silently drop the signature.
|
|
485
|
-
if (wantsSwapRouter && options?.isDepositWithPermit) {
|
|
486
|
-
throw new core_1.AugustValidationError('INVALID_INPUT', `vaultDeposit: isDepositWithPermit is not supported on SwapRouter-routed vaults (${target}). Call vaultDeposit without isDepositWithPermit, or use the legacy vault.deposit path directly.`, { context: { vault: target } });
|
|
487
|
-
}
|
|
488
|
-
if (isAdapterDeposit &&
|
|
489
|
-
!isMultiAssetVault &&
|
|
490
|
-
!adapterConfig &&
|
|
491
|
-
!swapRouterAddress) {
|
|
492
|
-
throw new core_1.AugustValidationError('INVALID_INPUT', `vaultDeposit: depositAsset ${actualDepositAsset} differs from vault underlying ${underlyingAsset} but no adapter is configured for vault ${target}`);
|
|
467
|
+
// vaultDeposit is the NATIVE path only — it never routes through the
|
|
468
|
+
// SwapRouter. Any-token swap deposits are the explicit, opt-in job of
|
|
469
|
+
// {@link swapRouterDeposit}; keeping them out of here is what stops a
|
|
470
|
+
// natively-accepted asset from being silently swapped.
|
|
471
|
+
if (isAdapterDeposit && !isMultiAssetVault && !adapterConfig) {
|
|
472
|
+
throw new core_1.AugustValidationError('INVALID_INPUT', `vaultDeposit: depositAsset ${actualDepositAsset} differs from vault underlying ${underlyingAsset} but no adapter is configured for vault ${target}. For an any-token deposit into a SwapRouter-eligible vault, use swapRouterDeposit instead.`);
|
|
493
473
|
}
|
|
494
474
|
const depositTokenDecimals = await resolveDepositTokenDecimals({
|
|
495
475
|
actualDepositAsset,
|
|
@@ -507,23 +487,6 @@ async function vaultDeposit(signer, options) {
|
|
|
507
487
|
},
|
|
508
488
|
});
|
|
509
489
|
const normalizedAmt = (0, core_1.toNormalizedBn)(amount, depositTokenDecimals);
|
|
510
|
-
if (swapRouterAddress && resolvedChainId !== undefined) {
|
|
511
|
-
return dispatchViaSwapRouter({
|
|
512
|
-
signer,
|
|
513
|
-
routerAddress: swapRouterAddress,
|
|
514
|
-
chainId: resolvedChainId,
|
|
515
|
-
target,
|
|
516
|
-
wallet,
|
|
517
|
-
receiver: options.receiver,
|
|
518
|
-
actualDepositAsset,
|
|
519
|
-
underlyingAsset,
|
|
520
|
-
isNativeToken,
|
|
521
|
-
depositTokenDecimals,
|
|
522
|
-
normalizedAmt,
|
|
523
|
-
slippageBps: options.slippageBps,
|
|
524
|
-
wait,
|
|
525
|
-
});
|
|
526
|
-
}
|
|
527
490
|
if (!isNativeToken) {
|
|
528
491
|
const spenderAddress = resolveSpender({
|
|
529
492
|
target,
|
|
@@ -1355,4 +1318,146 @@ async function depositNativeViaSwapRouter(signer, options) {
|
|
|
1355
1318
|
core_1.Logger.log.info('depositNativeViaSwapRouter:tx_hash', hash);
|
|
1356
1319
|
return hash;
|
|
1357
1320
|
}
|
|
1321
|
+
/**
|
|
1322
|
+
* Deposit into an August vault through the on-chain `SwapRouter`, selecting the
|
|
1323
|
+
* correct router path from the deposit asset. This is the high-level, explicit
|
|
1324
|
+
* counterpart to the SwapRouter branch inside {@link vaultDeposit}.
|
|
1325
|
+
*
|
|
1326
|
+
* Where `vaultDeposit` decides whether to use the SwapRouter from the
|
|
1327
|
+
* `VAULTS_USING_SWAP_ROUTER` allowlist, this function always routes through the
|
|
1328
|
+
* SwapRouter because the caller asked it to. Making the intent explicit is the
|
|
1329
|
+
* point: a native-deposit vault (e.g. a multi-asset Tokenized Vault V2 whose
|
|
1330
|
+
* non-reference assets are accepted directly) is never accidentally swapped —
|
|
1331
|
+
* the regression that implicit, allowlist-driven routing caused. Use
|
|
1332
|
+
* `vaultDeposit` for native / adapter deposits and this for SwapRouter deposits.
|
|
1333
|
+
*
|
|
1334
|
+
* The vault's reference asset and its decimals are read on-chain (never trusted
|
|
1335
|
+
* from the caller — a wrong reference asset would mis-route the swap). The path
|
|
1336
|
+
* is then chosen from `depositAsset`:
|
|
1337
|
+
* - equals the reference asset → direct router deposit, no swap
|
|
1338
|
+
* ({@link depositViaSwapRouter});
|
|
1339
|
+
* - the zero address → native-token deposit ({@link depositNativeViaSwapRouter}),
|
|
1340
|
+
* valid only when the reference asset is the chain's wrapped-native token;
|
|
1341
|
+
* - any other ERC-20 → a swap to the reference asset (Paraswap quote pinned to
|
|
1342
|
+
* the chain's whitelisted aggregator, fail-closed on router/selector drift)
|
|
1343
|
+
* bundled into {@link swapAndDeposit}.
|
|
1344
|
+
*
|
|
1345
|
+
* Side effects: reads tokenized-vault metadata, the vault's reference asset and
|
|
1346
|
+
* decimals, and (on the swap path) one Paraswap quote; sends one ERC-20
|
|
1347
|
+
* `approve` to the SwapRouter when allowance is short, then the deposit tx.
|
|
1348
|
+
*
|
|
1349
|
+
* @param signer - ethers `Signer` or `Wallet` that signs the approval + deposit.
|
|
1350
|
+
* @param options - {@link ISwapRouterDepositOptions}.
|
|
1351
|
+
* @returns The transaction hash of the router deposit call.
|
|
1352
|
+
* @throws {@link AugustValidationError} for an unsupported chain (no SwapRouter
|
|
1353
|
+
* deployment), an invalid vault or deposit-asset address, a missing or zero
|
|
1354
|
+
* amount, a native deposit into a non-wrapped-native vault, or drift between
|
|
1355
|
+
* the aggregator quote and the on-chain router whitelist.
|
|
1356
|
+
* @worstCaseRpcCalls 5 on the swap path — tokenized-vault metadata, reference
|
|
1357
|
+
* asset + decimals, deposit-token decimals, the quote, and the allowance read.
|
|
1358
|
+
* @example
|
|
1359
|
+
* ```ts
|
|
1360
|
+
* // USDT deposited into a USDC-reference vault → swapped to USDC en route.
|
|
1361
|
+
* const hash = await augustSdk.evm.swapRouterDeposit({
|
|
1362
|
+
* chainId: 1,
|
|
1363
|
+
* vault: '0xe9b725010a9e419412ed67d0fa5f3a5f40159d32',
|
|
1364
|
+
* depositAsset: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
|
|
1365
|
+
* amount: '100',
|
|
1366
|
+
* slippageBps: 50,
|
|
1367
|
+
* });
|
|
1368
|
+
* ```
|
|
1369
|
+
*/
|
|
1370
|
+
async function swapRouterDeposit(signer, options) {
|
|
1371
|
+
const { chainId, vault, depositAsset, amount, receiver, slippageBps, wait } = options;
|
|
1372
|
+
if (!(0, core_1.checkAddress)(vault, console, 'contract')) {
|
|
1373
|
+
throw new core_1.AugustValidationError('INVALID_ADDRESS', `swapRouterDeposit: invalid vault address "${vault}"`);
|
|
1374
|
+
}
|
|
1375
|
+
if (!(0, core_1.checkAddress)(depositAsset, console, 'contract')) {
|
|
1376
|
+
throw new core_1.AugustValidationError('INVALID_ADDRESS', `swapRouterDeposit: invalid depositAsset address "${depositAsset}"`);
|
|
1377
|
+
}
|
|
1378
|
+
if (amount === undefined || amount === null) {
|
|
1379
|
+
throw new core_1.AugustValidationError('INVALID_INPUT', 'swapRouterDeposit: amount is required');
|
|
1380
|
+
}
|
|
1381
|
+
validateAmountPrecision(amount);
|
|
1382
|
+
// Explicit opt-in: resolve the router straight from chainId rather than
|
|
1383
|
+
// consulting VAULTS_USING_SWAP_ROUTER, so this path never depends on the
|
|
1384
|
+
// implicit allowlist that could route a native-deposit vault through a swap.
|
|
1385
|
+
const routerAddress = resolveSwapRouterOrThrow(chainId);
|
|
1386
|
+
const eoa = await resolveSignerEOA(signer, 'swapRouterDeposit');
|
|
1387
|
+
// Reference asset + decimals from the vault on-chain. Mirrors vaultDeposit's
|
|
1388
|
+
// metadata resolution so the deposit-token decimals (and therefore the raw
|
|
1389
|
+
// amount) match exactly; kept separate to leave the vaultDeposit money path
|
|
1390
|
+
// untouched.
|
|
1391
|
+
const tokenizedVault = (await (0, core_1.fetchTokenizedVault)(vault))?.[0];
|
|
1392
|
+
const isMultiAssetVault = (0, core_1.getVaultVersionV2)(tokenizedVault) === 'evm-2';
|
|
1393
|
+
let underlyingAsset;
|
|
1394
|
+
let vaultDecimals;
|
|
1395
|
+
if (isMultiAssetVault) {
|
|
1396
|
+
const poolContract = (0, core_1.createContract)({
|
|
1397
|
+
address: vault,
|
|
1398
|
+
provider: signer,
|
|
1399
|
+
abi: abis_1.ABI_TOKENIZED_VAULT_V2,
|
|
1400
|
+
});
|
|
1401
|
+
const [asset, receiptTokenAddr] = await Promise.all([
|
|
1402
|
+
poolContract.asset(),
|
|
1403
|
+
poolContract.lpTokenAddress(),
|
|
1404
|
+
]);
|
|
1405
|
+
underlyingAsset = asset;
|
|
1406
|
+
const receiptContract = (0, core_1.createContract)({
|
|
1407
|
+
address: receiptTokenAddr,
|
|
1408
|
+
provider: signer,
|
|
1409
|
+
abi: abis_1.ABI_ERC20,
|
|
1410
|
+
});
|
|
1411
|
+
vaultDecimals = Number(await receiptContract.decimals());
|
|
1412
|
+
}
|
|
1413
|
+
else {
|
|
1414
|
+
const poolContract = (0, core_1.createContract)({
|
|
1415
|
+
address: vault,
|
|
1416
|
+
provider: signer,
|
|
1417
|
+
abi: abis_1.ABI_LENDING_POOLS,
|
|
1418
|
+
});
|
|
1419
|
+
const [asset, rawDecimals] = await Promise.all([
|
|
1420
|
+
poolContract.asset(),
|
|
1421
|
+
poolContract.decimals(),
|
|
1422
|
+
]);
|
|
1423
|
+
underlyingAsset = asset;
|
|
1424
|
+
vaultDecimals = Number(rawDecimals);
|
|
1425
|
+
}
|
|
1426
|
+
const isNativeToken = depositAsset === ethers_1.ZeroAddress ||
|
|
1427
|
+
depositAsset === '0x0000000000000000000000000000000000000000';
|
|
1428
|
+
const depositTokenDecimals = await resolveDepositTokenDecimals({
|
|
1429
|
+
actualDepositAsset: depositAsset,
|
|
1430
|
+
underlyingAsset,
|
|
1431
|
+
isNativeToken,
|
|
1432
|
+
isMultiAssetVault,
|
|
1433
|
+
vaultDecimals,
|
|
1434
|
+
readErc20Decimals: async (addr) => {
|
|
1435
|
+
const erc20 = (0, core_1.createContract)({
|
|
1436
|
+
address: addr,
|
|
1437
|
+
provider: signer,
|
|
1438
|
+
abi: abis_1.ABI_ERC20,
|
|
1439
|
+
});
|
|
1440
|
+
return Number(await erc20.decimals());
|
|
1441
|
+
},
|
|
1442
|
+
});
|
|
1443
|
+
const normalizedAmt = (0, core_1.toNormalizedBn)(amount, depositTokenDecimals);
|
|
1444
|
+
if (BigInt(normalizedAmt.raw) === 0n) {
|
|
1445
|
+
throw new core_1.AugustValidationError('INVALID_INPUT', 'swapRouterDeposit: amount must be greater than zero');
|
|
1446
|
+
}
|
|
1447
|
+
return dispatchViaSwapRouter({
|
|
1448
|
+
signer,
|
|
1449
|
+
routerAddress,
|
|
1450
|
+
chainId,
|
|
1451
|
+
target: vault,
|
|
1452
|
+
wallet: eoa,
|
|
1453
|
+
receiver,
|
|
1454
|
+
actualDepositAsset: depositAsset,
|
|
1455
|
+
underlyingAsset,
|
|
1456
|
+
isNativeToken,
|
|
1457
|
+
depositTokenDecimals,
|
|
1458
|
+
normalizedAmt,
|
|
1459
|
+
slippageBps,
|
|
1460
|
+
wait,
|
|
1461
|
+
});
|
|
1462
|
+
}
|
|
1358
1463
|
//# sourceMappingURL=write.actions.js.map
|