@augustdigital/sdk 8.6.1 → 8.7.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.
- 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/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 +71 -0
- package/lib/modules/vaults/write.actions.d.ts +51 -2
- package/lib/modules/vaults/write.actions.js +149 -44
- package/lib/sdk.d.ts +1158 -922
- package/lib/services/subgraph/vaults.d.ts +3 -1
- package/lib/services/subgraph/vaults.js +57 -11
- package/lib/types/vaults.d.ts +37 -0
- package/package.json +1 -1
|
@@ -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
|