augustdigital-sdk 8.20.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/LICENSE +21 -0
- package/README.md +349 -0
- package/lib/abis/AddressResolver.d.ts +28 -0
- package/lib/abis/AddressResolver.js +23 -0
- package/lib/abis/ChainlinkV3.d.ts +87 -0
- package/lib/abis/ChainlinkV3.js +117 -0
- package/lib/abis/ERC20.d.ts +168 -0
- package/lib/abis/ERC20.js +226 -0
- package/lib/abis/ERC20_Bytes32.d.ts +139 -0
- package/lib/abis/ERC20_Bytes32.js +196 -0
- package/lib/abis/ERC4626.d.ts +364 -0
- package/lib/abis/ERC4626.js +507 -0
- package/lib/abis/ERC721.d.ts +231 -0
- package/lib/abis/ERC721.js +321 -0
- package/lib/abis/FeeOracle.d.ts +120 -0
- package/lib/abis/FeeOracle.js +162 -0
- package/lib/abis/LendingPool.d.ts +1393 -0
- package/lib/abis/LendingPool.js +1807 -0
- package/lib/abis/LendingPoolV2.d.ts +1413 -0
- package/lib/abis/LendingPoolV2.js +1833 -0
- package/lib/abis/LendingPoolV3.d.ts +1677 -0
- package/lib/abis/LendingPoolV3.js +1160 -0
- package/lib/abis/Loan.d.ts +837 -0
- package/lib/abis/Loan.js +1080 -0
- package/lib/abis/MultiAssetNativeDepositWrapper.d.ts +137 -0
- package/lib/abis/MultiAssetNativeDepositWrapper.js +125 -0
- package/lib/abis/Multicall3.d.ts +30 -0
- package/lib/abis/Multicall3.js +97 -0
- package/lib/abis/OFT.d.ts +116 -0
- package/lib/abis/OFT.js +85 -0
- package/lib/abis/PoolAdapter.d.ts +36 -0
- package/lib/abis/PoolAdapter.js +51 -0
- package/lib/abis/RewardDistributor.d.ts +267 -0
- package/lib/abis/RewardDistributor.js +352 -0
- package/lib/abis/RwaRedeemSubaccount.d.ts +747 -0
- package/lib/abis/RwaRedeemSubaccount.js +548 -0
- package/lib/abis/SmartAccount.d.ts +17 -0
- package/lib/abis/SmartAccount.js +19 -0
- package/lib/abis/SwapRouter.d.ts +1043 -0
- package/lib/abis/SwapRouter.js +740 -0
- package/lib/abis/TextResolver.d.ts +16 -0
- package/lib/abis/TextResolver.js +16 -0
- package/lib/abis/TokenizedVaultV2.d.ts +1364 -0
- package/lib/abis/TokenizedVaultV2.js +1041 -0
- package/lib/abis/TokenizedVaultV2DepositWithPermit.d.ts +1456 -0
- package/lib/abis/TokenizedVaultV2DepositWithPermit.js +1878 -0
- package/lib/abis/TokenizedVaultV2Receipt.d.ts +1568 -0
- package/lib/abis/TokenizedVaultV2Receipt.js +1061 -0
- package/lib/abis/TokenizedVaultV2SenderAllocationWhitelist.d.ts +454 -0
- package/lib/abis/TokenizedVaultV2SenderAllocationWhitelist.js +327 -0
- package/lib/abis/TokenizedVaultV2WhitelistedAllocation.d.ts +1466 -0
- package/lib/abis/TokenizedVaultV2WhitelistedAllocation.js +1092 -0
- package/lib/abis/TokenizedVaultV2WhitelistedAssets.d.ts +274 -0
- package/lib/abis/TokenizedVaultV2WhitelistedAssets.js +167 -0
- package/lib/abis/UniversalResolverResolve.d.ts +69 -0
- package/lib/abis/UniversalResolverResolve.js +35 -0
- package/lib/abis/UniversalSignatureValidator.d.ts +17 -0
- package/lib/abis/UniversalSignatureValidator.js +30 -0
- package/lib/abis/WrapperAdapter.d.ts +71 -0
- package/lib/abis/WrapperAdapter.js +77 -0
- package/lib/abis/index.d.ts +34 -0
- package/lib/abis/index.js +51 -0
- package/lib/adapters/evm/getters.d.ts +19 -0
- package/lib/adapters/evm/getters.js +209 -0
- package/lib/adapters/evm/index.d.ts +353 -0
- package/lib/adapters/evm/index.js +434 -0
- package/lib/adapters/evm/utils.d.ts +8 -0
- package/lib/adapters/evm/utils.js +51 -0
- package/lib/adapters/solana/constants.d.ts +33 -0
- package/lib/adapters/solana/constants.js +52 -0
- package/lib/adapters/solana/getters.d.ts +11 -0
- package/lib/adapters/solana/getters.js +165 -0
- package/lib/adapters/solana/idl/vault-idl.d.ts +272 -0
- package/lib/adapters/solana/idl/vault-idl.js +1084 -0
- package/lib/adapters/solana/index.d.ts +233 -0
- package/lib/adapters/solana/index.js +291 -0
- package/lib/adapters/solana/types.d.ts +67 -0
- package/lib/adapters/solana/types.js +3 -0
- package/lib/adapters/solana/utils.d.ts +141 -0
- package/lib/adapters/solana/utils.js +595 -0
- package/lib/adapters/solana/vault.actions.d.ts +57 -0
- package/lib/adapters/solana/vault.actions.js +379 -0
- package/lib/adapters/stellar/actions.d.ts +28 -0
- package/lib/adapters/stellar/actions.js +77 -0
- package/lib/adapters/stellar/constants.d.ts +43 -0
- package/lib/adapters/stellar/constants.js +53 -0
- package/lib/adapters/stellar/getters.d.ts +68 -0
- package/lib/adapters/stellar/getters.js +290 -0
- package/lib/adapters/stellar/index.d.ts +114 -0
- package/lib/adapters/stellar/index.js +175 -0
- package/lib/adapters/stellar/soroban.d.ts +123 -0
- package/lib/adapters/stellar/soroban.js +613 -0
- package/lib/adapters/stellar/submit.d.ts +34 -0
- package/lib/adapters/stellar/submit.js +149 -0
- package/lib/adapters/stellar/types.d.ts +58 -0
- package/lib/adapters/stellar/types.js +6 -0
- package/lib/adapters/stellar/utils.d.ts +24 -0
- package/lib/adapters/stellar/utils.js +34 -0
- package/lib/adapters/sui/constants.d.ts +14 -0
- package/lib/adapters/sui/constants.js +29 -0
- package/lib/adapters/sui/getters.d.ts +9 -0
- package/lib/adapters/sui/getters.js +60 -0
- package/lib/adapters/sui/index.d.ts +45 -0
- package/lib/adapters/sui/index.js +101 -0
- package/lib/adapters/sui/transformer.d.ts +10 -0
- package/lib/adapters/sui/transformer.js +107 -0
- package/lib/adapters/sui/types.d.ts +66 -0
- package/lib/adapters/sui/types.js +3 -0
- package/lib/adapters/sui/utils.d.ts +10 -0
- package/lib/adapters/sui/utils.js +29 -0
- package/lib/core/analytics/chain-name.d.ts +9 -0
- package/lib/core/analytics/chain-name.js +34 -0
- package/lib/core/analytics/constants.d.ts +5 -0
- package/lib/core/analytics/constants.js +9 -0
- package/lib/core/analytics/env.d.ts +29 -0
- package/lib/core/analytics/env.js +59 -0
- package/lib/core/analytics/index.d.ts +36 -0
- package/lib/core/analytics/index.js +79 -0
- package/lib/core/analytics/instrumentation.d.ts +29 -0
- package/lib/core/analytics/instrumentation.js +277 -0
- package/lib/core/analytics/method-taxonomy.d.ts +19 -0
- package/lib/core/analytics/method-taxonomy.js +128 -0
- package/lib/core/analytics/metrics.d.ts +33 -0
- package/lib/core/analytics/metrics.js +116 -0
- package/lib/core/analytics/sanitize.d.ts +44 -0
- package/lib/core/analytics/sanitize.js +260 -0
- package/lib/core/analytics/sentry-runtime.d.ts +15 -0
- package/lib/core/analytics/sentry-runtime.js +97 -0
- package/lib/core/analytics/sentry.d.ts +67 -0
- package/lib/core/analytics/sentry.js +613 -0
- package/lib/core/analytics/types.d.ts +48 -0
- package/lib/core/analytics/types.js +3 -0
- package/lib/core/analytics/user-identity.d.ts +41 -0
- package/lib/core/analytics/user-identity.js +141 -0
- package/lib/core/analytics/version.d.ts +6 -0
- package/lib/core/analytics/version.js +10 -0
- package/lib/core/attribution.d.ts +111 -0
- package/lib/core/attribution.js +142 -0
- package/lib/core/auth/index.d.ts +1 -0
- package/lib/core/auth/index.js +18 -0
- package/lib/core/auth/verify.d.ts +2 -0
- package/lib/core/auth/verify.js +31 -0
- package/lib/core/base.class.d.ts +152 -0
- package/lib/core/base.class.js +172 -0
- package/lib/core/cache.d.ts +9 -0
- package/lib/core/cache.js +31 -0
- package/lib/core/constants/adapters.d.ts +103 -0
- package/lib/core/constants/adapters.js +180 -0
- package/lib/core/constants/core.d.ts +133 -0
- package/lib/core/constants/core.js +209 -0
- package/lib/core/constants/swap-router.d.ts +150 -0
- package/lib/core/constants/swap-router.js +169 -0
- package/lib/core/constants/vaults.d.ts +93 -0
- package/lib/core/constants/vaults.js +273 -0
- package/lib/core/constants/web3.d.ts +91 -0
- package/lib/core/constants/web3.js +229 -0
- package/lib/core/errors/index.d.ts +114 -0
- package/lib/core/errors/index.js +183 -0
- package/lib/core/fetcher.d.ts +198 -0
- package/lib/core/fetcher.js +903 -0
- package/lib/core/helpers/adapters.d.ts +13 -0
- package/lib/core/helpers/adapters.js +39 -0
- package/lib/core/helpers/chain-address.d.ts +13 -0
- package/lib/core/helpers/chain-address.js +47 -0
- package/lib/core/helpers/chain-error.d.ts +207 -0
- package/lib/core/helpers/chain-error.js +682 -0
- package/lib/core/helpers/chain-support.d.ts +80 -0
- package/lib/core/helpers/chain-support.js +115 -0
- package/lib/core/helpers/core.d.ts +68 -0
- package/lib/core/helpers/core.js +285 -0
- package/lib/core/helpers/explorer-link.d.ts +16 -0
- package/lib/core/helpers/explorer-link.js +26 -0
- package/lib/core/helpers/multicall.d.ts +68 -0
- package/lib/core/helpers/multicall.js +103 -0
- package/lib/core/helpers/revert-decode.d.ts +248 -0
- package/lib/core/helpers/revert-decode.js +515 -0
- package/lib/core/helpers/signer.d.ts +52 -0
- package/lib/core/helpers/signer.js +145 -0
- package/lib/core/helpers/swap-router.d.ts +211 -0
- package/lib/core/helpers/swap-router.js +480 -0
- package/lib/core/helpers/vault-version.d.ts +23 -0
- package/lib/core/helpers/vault-version.js +75 -0
- package/lib/core/helpers/vaults.d.ts +89 -0
- package/lib/core/helpers/vaults.js +235 -0
- package/lib/core/helpers/web3.d.ts +353 -0
- package/lib/core/helpers/web3.js +992 -0
- package/lib/core/index.d.ts +23 -0
- package/lib/core/index.js +40 -0
- package/lib/core/logger/index.d.ts +98 -0
- package/lib/core/logger/index.js +144 -0
- package/lib/core/logger/slack.d.ts +16 -0
- package/lib/core/logger/slack.js +57 -0
- package/lib/core/vault-metadata.d.ts +12 -0
- package/lib/core/vault-metadata.js +42 -0
- package/lib/core/version-check.d.ts +58 -0
- package/lib/core/version-check.js +182 -0
- package/lib/evm/index.d.ts +2 -0
- package/lib/evm/index.js +19 -0
- package/lib/evm/methods/crossChainVault.d.ts +128 -0
- package/lib/evm/methods/crossChainVault.js +853 -0
- package/lib/evm/methods/crossChainVaultRegistry.d.ts +93 -0
- package/lib/evm/methods/crossChainVaultRegistry.js +240 -0
- package/lib/evm/methods/index.d.ts +2 -0
- package/lib/evm/methods/index.js +19 -0
- package/lib/evm/types/crossChain.d.ts +363 -0
- package/lib/evm/types/crossChain.js +20 -0
- package/lib/evm/types/index.d.ts +1 -0
- package/lib/evm/types/index.js +18 -0
- package/lib/index.d.ts +30 -0
- package/lib/index.js +52 -0
- package/lib/main.d.ts +527 -0
- package/lib/main.js +601 -0
- package/lib/modules/api/fetcher.d.ts +82 -0
- package/lib/modules/api/fetcher.js +150 -0
- package/lib/modules/api/index.d.ts +1 -0
- package/lib/modules/api/index.js +6 -0
- package/lib/modules/api/main.d.ts +313 -0
- package/lib/modules/api/main.js +479 -0
- package/lib/modules/sub-accounts/fetcher.d.ts +53 -0
- package/lib/modules/sub-accounts/fetcher.js +120 -0
- package/lib/modules/sub-accounts/index.d.ts +2 -0
- package/lib/modules/sub-accounts/index.js +19 -0
- package/lib/modules/sub-accounts/main.d.ts +243 -0
- package/lib/modules/sub-accounts/main.js +205 -0
- package/lib/modules/sub-accounts/utils.d.ts +106 -0
- package/lib/modules/sub-accounts/utils.js +112 -0
- package/lib/modules/vaults/adapter.helpers.d.ts +64 -0
- package/lib/modules/vaults/adapter.helpers.js +184 -0
- package/lib/modules/vaults/fetcher.d.ts +147 -0
- package/lib/modules/vaults/fetcher.js +368 -0
- package/lib/modules/vaults/getters.d.ts +570 -0
- package/lib/modules/vaults/getters.js +3051 -0
- package/lib/modules/vaults/index.d.ts +20 -0
- package/lib/modules/vaults/index.js +44 -0
- package/lib/modules/vaults/main.d.ts +601 -0
- package/lib/modules/vaults/main.js +1623 -0
- package/lib/modules/vaults/prefetch.d.ts +65 -0
- package/lib/modules/vaults/prefetch.js +120 -0
- package/lib/modules/vaults/read.actions.d.ts +225 -0
- package/lib/modules/vaults/read.actions.js +596 -0
- package/lib/modules/vaults/types.d.ts +71 -0
- package/lib/modules/vaults/types.js +3 -0
- package/lib/modules/vaults/utils/call-data-decoder.d.ts +61 -0
- package/lib/modules/vaults/utils/call-data-decoder.js +194 -0
- package/lib/modules/vaults/utils/date-utils.d.ts +50 -0
- package/lib/modules/vaults/utils/date-utils.js +84 -0
- package/lib/modules/vaults/utils.d.ts +140 -0
- package/lib/modules/vaults/utils.js +799 -0
- package/lib/modules/vaults/write.actions.d.ts +529 -0
- package/lib/modules/vaults/write.actions.js +1749 -0
- package/lib/polyfills.d.ts +1 -0
- package/lib/polyfills.js +12 -0
- package/lib/sdk.d.ts +26721 -0
- package/lib/services/coingecko/fetcher.d.ts +15 -0
- package/lib/services/coingecko/fetcher.js +67 -0
- package/lib/services/coingecko/index.d.ts +2 -0
- package/lib/services/coingecko/index.js +19 -0
- package/lib/services/coingecko/utils.d.ts +1 -0
- package/lib/services/coingecko/utils.js +24 -0
- package/lib/services/debank/fetcher.d.ts +126 -0
- package/lib/services/debank/fetcher.js +47 -0
- package/lib/services/debank/index.d.ts +2 -0
- package/lib/services/debank/index.js +19 -0
- package/lib/services/debank/utils.d.ts +38 -0
- package/lib/services/debank/utils.js +297 -0
- package/lib/services/layerzero/deposits.d.ts +49 -0
- package/lib/services/layerzero/deposits.js +166 -0
- package/lib/services/layerzero/redeems.d.ts +20 -0
- package/lib/services/layerzero/redeems.js +92 -0
- package/lib/services/layerzero/utils.d.ts +9 -0
- package/lib/services/layerzero/utils.js +22 -0
- package/lib/services/octavfi/fetcher.d.ts +9 -0
- package/lib/services/octavfi/fetcher.js +103 -0
- package/lib/services/octavfi/index.d.ts +3 -0
- package/lib/services/octavfi/index.js +20 -0
- package/lib/services/octavfi/types.d.ts +34 -0
- package/lib/services/octavfi/types.js +3 -0
- package/lib/services/octavfi/utils.d.ts +16 -0
- package/lib/services/octavfi/utils.js +212 -0
- package/lib/services/subgraph/fetcher.d.ts +2 -0
- package/lib/services/subgraph/fetcher.js +61 -0
- package/lib/services/subgraph/index.d.ts +2 -0
- package/lib/services/subgraph/index.js +19 -0
- package/lib/services/subgraph/schema.d.ts +45 -0
- package/lib/services/subgraph/schema.js +75 -0
- package/lib/services/subgraph/vaults.d.ts +25 -0
- package/lib/services/subgraph/vaults.js +1106 -0
- package/lib/services/swap-quotes/index.d.ts +105 -0
- package/lib/services/swap-quotes/index.js +77 -0
- package/lib/services/swap-quotes/paraswap.d.ts +51 -0
- package/lib/services/swap-quotes/paraswap.js +138 -0
- package/lib/types/api.d.ts +280 -0
- package/lib/types/api.js +3 -0
- package/lib/types/index.d.ts +12 -0
- package/lib/types/index.js +28 -0
- package/lib/types/points.d.ts +28 -0
- package/lib/types/points.js +3 -0
- package/lib/types/pools.d.ts +144 -0
- package/lib/types/pools.js +3 -0
- package/lib/types/staking.d.ts +28 -0
- package/lib/types/staking.js +3 -0
- package/lib/types/sub-accounts.d.ts +140 -0
- package/lib/types/sub-accounts.js +3 -0
- package/lib/types/subgraph.d.ts +74 -0
- package/lib/types/subgraph.js +3 -0
- package/lib/types/typed-contract.d.ts +102 -0
- package/lib/types/typed-contract.js +3 -0
- package/lib/types/user.d.ts +1 -0
- package/lib/types/user.js +3 -0
- package/lib/types/vaults.d.ts +714 -0
- package/lib/types/vaults.js +24 -0
- package/lib/types/web3.d.ts +51 -0
- package/lib/types/web3.js +14 -0
- package/lib/types/webserver.d.ts +698 -0
- package/lib/types/webserver.js +3 -0
- package/package.json +78 -0
|
@@ -0,0 +1,596 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchInstantRedemptionFee = fetchInstantRedemptionFee;
|
|
4
|
+
exports.vaultAllowance = vaultAllowance;
|
|
5
|
+
exports.sendersWhitelistAddress = sendersWhitelistAddress;
|
|
6
|
+
exports.isWhitelisted = isWhitelisted;
|
|
7
|
+
exports.getDeposited = getDeposited;
|
|
8
|
+
exports.getRemainingAllocations = getRemainingAllocations;
|
|
9
|
+
exports.previewRwaRedemption = previewRwaRedemption;
|
|
10
|
+
exports.previewDeposit = previewDeposit;
|
|
11
|
+
exports.previewRedeem = previewRedeem;
|
|
12
|
+
exports.allowance = allowance;
|
|
13
|
+
exports.balanceOf = balanceOf;
|
|
14
|
+
exports.maxDeposit = maxDeposit;
|
|
15
|
+
const abis_1 = require("../../abis");
|
|
16
|
+
const core_1 = require("../../core");
|
|
17
|
+
/**
|
|
18
|
+
* Function to fetch instant redemption fee
|
|
19
|
+
* @param signer - signer / provider object
|
|
20
|
+
* @param options - object including pool contract address, user wallet address
|
|
21
|
+
* @returns normalized number object of the instant redemption fee
|
|
22
|
+
*/
|
|
23
|
+
async function fetchInstantRedemptionFee(signer, options) {
|
|
24
|
+
const { wallet, target } = options;
|
|
25
|
+
const [goodWallet, goodPool] = [
|
|
26
|
+
(0, core_1.checkAddress)(wallet, console, 'wallet'),
|
|
27
|
+
(0, core_1.checkAddress)(target, console),
|
|
28
|
+
];
|
|
29
|
+
if (!goodWallet || !goodPool)
|
|
30
|
+
return;
|
|
31
|
+
try {
|
|
32
|
+
if (signer && target) {
|
|
33
|
+
const poolContract = (0, core_1.createContract)({
|
|
34
|
+
address: target,
|
|
35
|
+
abi: abis_1.ABI_LENDING_POOL_V3,
|
|
36
|
+
provider: signer,
|
|
37
|
+
});
|
|
38
|
+
const instantRedemptionResult = await poolContract.instantRedemptionFee();
|
|
39
|
+
return (0, core_1.toNormalizedBn)(instantRedemptionResult);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
(0, core_1.logChainError)('failed to fetch instant redeem fee', e, (0, core_1.isExpectedRevertError)(e));
|
|
44
|
+
throw new Error(`Failed to fetch instant redeem fee for ${target}: ${e instanceof Error ? e.message : 'Unknown error'}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* allowance checks user's current allowance per pool
|
|
49
|
+
* @param signer - signer / provider object
|
|
50
|
+
* @param options - object including pool contract address, user wallet address
|
|
51
|
+
* @returns normalized number object of the user's current allowance
|
|
52
|
+
*/
|
|
53
|
+
async function vaultAllowance(signer, options) {
|
|
54
|
+
const { wallet, target } = options;
|
|
55
|
+
const [goodWallet, goodPool] = [
|
|
56
|
+
(0, core_1.checkAddress)(wallet, console, 'wallet'),
|
|
57
|
+
(0, core_1.checkAddress)(target, console),
|
|
58
|
+
];
|
|
59
|
+
if (!goodWallet || !goodPool)
|
|
60
|
+
return;
|
|
61
|
+
try {
|
|
62
|
+
// ERC4626 vault
|
|
63
|
+
const poolContract = (0, core_1.createContract)({
|
|
64
|
+
address: target,
|
|
65
|
+
abi: abis_1.ABI_LENDING_POOLS,
|
|
66
|
+
provider: signer,
|
|
67
|
+
});
|
|
68
|
+
// get vault asset address and decimals
|
|
69
|
+
const [asset, rawDecimals] = await Promise.all([
|
|
70
|
+
poolContract.asset(),
|
|
71
|
+
poolContract.decimals(),
|
|
72
|
+
]);
|
|
73
|
+
const decimals = Number(rawDecimals);
|
|
74
|
+
// check amount vault approves user for
|
|
75
|
+
const depositTokenContract = (0, core_1.createContract)({
|
|
76
|
+
address: asset,
|
|
77
|
+
abi: abis_1.ABI_ERC20,
|
|
78
|
+
provider: signer,
|
|
79
|
+
});
|
|
80
|
+
const _allowance = (await depositTokenContract.allowance(wallet, target));
|
|
81
|
+
const normalized = (0, core_1.toNormalizedBn)(_allowance, decimals);
|
|
82
|
+
core_1.Logger.log.info('allowance', normalized);
|
|
83
|
+
return normalized;
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
(0, core_1.logChainError)('allowance', e, (0, core_1.isExpectedRevertError)(e));
|
|
87
|
+
throw new Error(`Failed to fetch allowance: ${e instanceof Error ? e.message : 'Unknown error'}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Fetches the senders whitelist contract address from a whitelisted allocation vault
|
|
92
|
+
* @param signer - signer / provider object
|
|
93
|
+
* @param options - object including vault contract address
|
|
94
|
+
* @returns the senders whitelist contract address
|
|
95
|
+
*/
|
|
96
|
+
async function sendersWhitelistAddress(signer, options) {
|
|
97
|
+
const { vault } = options;
|
|
98
|
+
const goodTarget = (0, core_1.checkAddress)(vault, console);
|
|
99
|
+
if (!goodTarget)
|
|
100
|
+
return;
|
|
101
|
+
try {
|
|
102
|
+
const vaultContract = (0, core_1.createContract)({
|
|
103
|
+
address: vault,
|
|
104
|
+
abi: abis_1.ABI_TOKENIZED_VAULT_V2_WHITELISTED_ALLOCATION,
|
|
105
|
+
provider: signer,
|
|
106
|
+
});
|
|
107
|
+
const whitelistAddress = await vaultContract.sendersWhitelistAddress();
|
|
108
|
+
core_1.Logger.log.info('sendersWhitelistAddress', whitelistAddress);
|
|
109
|
+
return whitelistAddress;
|
|
110
|
+
}
|
|
111
|
+
catch (e) {
|
|
112
|
+
(0, core_1.logChainError)('sendersWhitelistAddress', e, (0, core_1.isExpectedRevertError)(e));
|
|
113
|
+
throw new Error(`Failed to fetch senders whitelist address: ${e instanceof Error ? e.message : 'Unknown error'}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Checks if an address is whitelisted on a whitelist contract
|
|
118
|
+
* @param signer - signer / provider object
|
|
119
|
+
* @param options - object including whitelist contract address and wallet address to check
|
|
120
|
+
* @returns boolean indicating if the address is whitelisted
|
|
121
|
+
*/
|
|
122
|
+
async function isWhitelisted(signer, options) {
|
|
123
|
+
const { whitelist, wallet } = options;
|
|
124
|
+
const [goodWhitelist, goodWallet] = [
|
|
125
|
+
(0, core_1.checkAddress)(whitelist, console, 'contract'),
|
|
126
|
+
(0, core_1.checkAddress)(wallet, console, 'wallet'),
|
|
127
|
+
];
|
|
128
|
+
if (!goodWhitelist || !goodWallet)
|
|
129
|
+
return;
|
|
130
|
+
try {
|
|
131
|
+
const whitelistContract = (0, core_1.createContract)({
|
|
132
|
+
address: whitelist,
|
|
133
|
+
abi: abis_1.ABI_TOKENIZED_VAULT_V2_SENDER_ALLOCATION_WHITELIST,
|
|
134
|
+
provider: signer,
|
|
135
|
+
});
|
|
136
|
+
const result = await whitelistContract.isWhitelisted(wallet);
|
|
137
|
+
core_1.Logger.log.info('isWhitelisted', result);
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
catch (e) {
|
|
141
|
+
(0, core_1.logChainError)('isWhitelisted', e, (0, core_1.isExpectedRevertError)(e));
|
|
142
|
+
throw new Error(`Failed to check whitelist status: ${e instanceof Error ? e.message : 'Unknown error'}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Fetches the total amount deposited by an address on a whitelist contract
|
|
147
|
+
* @param signer - signer / provider object
|
|
148
|
+
* @param options - object including whitelist contract address, wallet address, and vault address
|
|
149
|
+
* @returns normalized number of the deposited amount
|
|
150
|
+
*/
|
|
151
|
+
async function getDeposited(signer, options) {
|
|
152
|
+
const { whitelist, wallet, vault } = options;
|
|
153
|
+
const [goodWhitelist, goodWallet, goodVault] = [
|
|
154
|
+
(0, core_1.checkAddress)(whitelist, console, 'contract'),
|
|
155
|
+
(0, core_1.checkAddress)(wallet, console, 'wallet'),
|
|
156
|
+
(0, core_1.checkAddress)(vault, console, 'contract'),
|
|
157
|
+
];
|
|
158
|
+
if (!goodWhitelist || !goodWallet || !goodVault)
|
|
159
|
+
return;
|
|
160
|
+
try {
|
|
161
|
+
const vaultContract = (0, core_1.createContract)({
|
|
162
|
+
address: vault,
|
|
163
|
+
abi: abis_1.ABI_TOKENIZED_VAULT_V2_WHITELISTED_ALLOCATION,
|
|
164
|
+
provider: signer,
|
|
165
|
+
});
|
|
166
|
+
const whitelistContract = (0, core_1.createContract)({
|
|
167
|
+
address: whitelist,
|
|
168
|
+
abi: abis_1.ABI_TOKENIZED_VAULT_V2_SENDER_ALLOCATION_WHITELIST,
|
|
169
|
+
provider: signer,
|
|
170
|
+
});
|
|
171
|
+
const [deposited, asset] = await Promise.all([
|
|
172
|
+
whitelistContract.getDeposited(wallet),
|
|
173
|
+
vaultContract.asset(),
|
|
174
|
+
]);
|
|
175
|
+
const assetContract = (0, core_1.createContract)({
|
|
176
|
+
address: asset,
|
|
177
|
+
abi: abis_1.ABI_ERC20,
|
|
178
|
+
provider: signer,
|
|
179
|
+
});
|
|
180
|
+
const decimals = Number(await assetContract.decimals());
|
|
181
|
+
const normalized = (0, core_1.toNormalizedBn)(deposited, decimals);
|
|
182
|
+
core_1.Logger.log.info('getDeposited', normalized);
|
|
183
|
+
return normalized;
|
|
184
|
+
}
|
|
185
|
+
catch (e) {
|
|
186
|
+
(0, core_1.logChainError)('getDeposited', e, (0, core_1.isExpectedRevertError)(e));
|
|
187
|
+
throw new Error(`Failed to fetch deposited amount: ${e instanceof Error ? e.message : 'Unknown error'}`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Fetches the remaining allocation for an address on a whitelist contract
|
|
192
|
+
* @param signer - signer / provider object
|
|
193
|
+
* @param options - object including whitelist contract address, wallet address, vault address, and optional deposit cap amount
|
|
194
|
+
* @returns the remaining allocation as normalized number
|
|
195
|
+
*/
|
|
196
|
+
async function getRemainingAllocations(signer, options) {
|
|
197
|
+
const { whitelist, wallet, vault, depositCapAmount } = options;
|
|
198
|
+
const [goodWhitelist, goodWallet, goodVault] = [
|
|
199
|
+
(0, core_1.checkAddress)(whitelist, console, 'contract'),
|
|
200
|
+
(0, core_1.checkAddress)(wallet, console, 'wallet'),
|
|
201
|
+
(0, core_1.checkAddress)(vault, console, 'contract'),
|
|
202
|
+
];
|
|
203
|
+
if (!goodWhitelist || !goodWallet || !goodVault)
|
|
204
|
+
return;
|
|
205
|
+
try {
|
|
206
|
+
const vaultContract = (0, core_1.createContract)({
|
|
207
|
+
address: vault,
|
|
208
|
+
abi: abis_1.ABI_TOKENIZED_VAULT_V2_WHITELISTED_ALLOCATION,
|
|
209
|
+
provider: signer,
|
|
210
|
+
});
|
|
211
|
+
const whitelistContract = (0, core_1.createContract)({
|
|
212
|
+
address: whitelist,
|
|
213
|
+
abi: abis_1.ABI_TOKENIZED_VAULT_V2_SENDER_ALLOCATION_WHITELIST,
|
|
214
|
+
provider: signer,
|
|
215
|
+
});
|
|
216
|
+
// Fetch depositCap if not provided, along with asset address
|
|
217
|
+
const [capAmount, asset] = await Promise.all([
|
|
218
|
+
depositCapAmount !== undefined
|
|
219
|
+
? Promise.resolve(depositCapAmount)
|
|
220
|
+
: vaultContract.depositCap(),
|
|
221
|
+
vaultContract.asset(),
|
|
222
|
+
]);
|
|
223
|
+
const assetContract = (0, core_1.createContract)({
|
|
224
|
+
address: asset,
|
|
225
|
+
abi: abis_1.ABI_ERC20,
|
|
226
|
+
provider: signer,
|
|
227
|
+
});
|
|
228
|
+
const decimals = Number(await assetContract.decimals());
|
|
229
|
+
const remaining = await whitelistContract.getRemainingAllocation(wallet, capAmount);
|
|
230
|
+
const normalized = (0, core_1.toNormalizedBn)(remaining, decimals);
|
|
231
|
+
core_1.Logger.log.info('getRemainingAllocations', normalized);
|
|
232
|
+
return normalized;
|
|
233
|
+
}
|
|
234
|
+
catch (e) {
|
|
235
|
+
(0, core_1.logChainError)('getRemainingAllocations', e, (0, core_1.isExpectedRevertError)(e));
|
|
236
|
+
throw new Error(`Failed to fetch remaining allocations: ${e instanceof Error ? e.message : 'Unknown error'}`);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Preview the output amount for an RWA instant redemption via the RwaRedeemSubaccount contract.
|
|
241
|
+
* @param signer - signer / provider object
|
|
242
|
+
* @param options - object including subaccount address, asset, amount, decimals, and outputDecimals
|
|
243
|
+
* @returns normalized number of the expected output amount (in output asset decimals)
|
|
244
|
+
*/
|
|
245
|
+
async function previewRwaRedemption(signer, options) {
|
|
246
|
+
const { target, asset, amount, decimals, outputDecimals } = options;
|
|
247
|
+
const goodTarget = (0, core_1.checkAddress)(target, console, 'contract');
|
|
248
|
+
const goodAsset = (0, core_1.checkAddress)(asset, console, 'contract');
|
|
249
|
+
if (!goodTarget || !goodAsset)
|
|
250
|
+
return;
|
|
251
|
+
try {
|
|
252
|
+
const subaccountContract = (0, core_1.createContract)({
|
|
253
|
+
address: target,
|
|
254
|
+
provider: signer,
|
|
255
|
+
abi: abis_1.RWA_REDEEM_SUBACCOUNT,
|
|
256
|
+
});
|
|
257
|
+
if (!subaccountContract)
|
|
258
|
+
return;
|
|
259
|
+
const normalizedAmt = (0, core_1.toNormalizedBn)(amount, decimals);
|
|
260
|
+
const result = await subaccountContract.previewRedemption(asset, BigInt(normalizedAmt.raw));
|
|
261
|
+
const normalized = (0, core_1.toNormalizedBn)(result, outputDecimals);
|
|
262
|
+
core_1.Logger.log.info('previewRwaRedemption', normalized);
|
|
263
|
+
return normalized;
|
|
264
|
+
}
|
|
265
|
+
catch (e) {
|
|
266
|
+
(0, core_1.logChainError)('previewRwaRedemption', e, (0, core_1.isExpectedRevertError)(e), {
|
|
267
|
+
target,
|
|
268
|
+
asset,
|
|
269
|
+
amount,
|
|
270
|
+
});
|
|
271
|
+
throw new Error(`Preview RWA redemption failed: ${e instanceof Error ? e.message : 'Unknown error'}`);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
function toRawBigInt(value, label) {
|
|
275
|
+
if (typeof value === 'bigint')
|
|
276
|
+
return value;
|
|
277
|
+
if (typeof value === 'number') {
|
|
278
|
+
if (!Number.isFinite(value)) {
|
|
279
|
+
throw new core_1.AugustValidationError('INVALID_INPUT', `${label}: amount must be finite, got ${value}`);
|
|
280
|
+
}
|
|
281
|
+
if (value < 0) {
|
|
282
|
+
throw new core_1.AugustValidationError('INVALID_INPUT', `${label}: amount must be non-negative, got ${value}`);
|
|
283
|
+
}
|
|
284
|
+
if (!Number.isSafeInteger(value)) {
|
|
285
|
+
throw new core_1.AugustValidationError('INVALID_INPUT', `${label}: amount ${value} exceeds Number.MAX_SAFE_INTEGER; pass a string or bigint to preserve precision`);
|
|
286
|
+
}
|
|
287
|
+
return BigInt(value);
|
|
288
|
+
}
|
|
289
|
+
if (typeof value === 'string') {
|
|
290
|
+
if (value.trim() === '') {
|
|
291
|
+
throw new core_1.AugustValidationError('INVALID_INPUT', `${label}: amount string must not be empty`);
|
|
292
|
+
}
|
|
293
|
+
try {
|
|
294
|
+
const parsed = BigInt(value);
|
|
295
|
+
if (parsed < 0n) {
|
|
296
|
+
throw new core_1.AugustValidationError('INVALID_INPUT', `${label}: amount must be non-negative, got ${value}`);
|
|
297
|
+
}
|
|
298
|
+
return parsed;
|
|
299
|
+
}
|
|
300
|
+
catch (e) {
|
|
301
|
+
if (e instanceof core_1.AugustValidationError)
|
|
302
|
+
throw e;
|
|
303
|
+
throw new core_1.AugustValidationError('INVALID_INPUT', `${label}: amount "${value}" is not a valid integer`);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
throw new core_1.AugustValidationError('INVALID_INPUT', `${label}: amount must be a string, bigint, or number`);
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Preview the number of shares that would be minted for a deposit, without
|
|
310
|
+
* touching on-chain state. Routes between single-asset ERC-4626 and EVM-2
|
|
311
|
+
* multi-asset vaults using the vault version detected from backend metadata.
|
|
312
|
+
*
|
|
313
|
+
* @returns The number of shares (raw on-chain units, share-token decimals).
|
|
314
|
+
* @throws AugustValidationError on invalid vault address or amount.
|
|
315
|
+
* @throws AugustSDKError when the underlying contract call fails.
|
|
316
|
+
*
|
|
317
|
+
* @example
|
|
318
|
+
* ```ts
|
|
319
|
+
* const shares = await augustSdk.evm.previewDeposit({
|
|
320
|
+
* vault: '0xE9B725010A9E419412ed67d0fA5f3A5f40159D32',
|
|
321
|
+
* amount: 1_000_000n, // 1 USDC (6 decimals)
|
|
322
|
+
* });
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
async function previewDeposit(signer, options) {
|
|
326
|
+
const { vault, amount, asset } = options;
|
|
327
|
+
if (!(0, core_1.checkAddress)(vault, console, 'contract')) {
|
|
328
|
+
throw new core_1.AugustValidationError('INVALID_ADDRESS', `previewDeposit: invalid vault address ${vault}`);
|
|
329
|
+
}
|
|
330
|
+
const amountRaw = toRawBigInt(amount, 'previewDeposit');
|
|
331
|
+
try {
|
|
332
|
+
const tokenizedVault = (await (0, core_1.fetchTokenizedVault)(vault))?.[0];
|
|
333
|
+
const vaultVersion = (0, core_1.getVaultVersionV2)(tokenizedVault);
|
|
334
|
+
const isMultiAsset = vaultVersion === 'evm-2';
|
|
335
|
+
if (isMultiAsset) {
|
|
336
|
+
if (!asset || !(0, core_1.checkAddress)(asset, console, 'contract')) {
|
|
337
|
+
throw new core_1.AugustValidationError('INVALID_INPUT', 'previewDeposit: multi-asset vaults require an explicit `asset` parameter');
|
|
338
|
+
}
|
|
339
|
+
const contract = (0, core_1.createContract)({
|
|
340
|
+
address: vault,
|
|
341
|
+
provider: signer,
|
|
342
|
+
abi: abis_1.ABI_TOKENIZED_VAULT_V2,
|
|
343
|
+
});
|
|
344
|
+
const result = await contract.previewDeposit(asset, amountRaw);
|
|
345
|
+
// TokenizedVaultV2 previewDeposit returns (shares, _); take shares.
|
|
346
|
+
const shares = Array.isArray(result) ? result[0] : result;
|
|
347
|
+
return BigInt(shares);
|
|
348
|
+
}
|
|
349
|
+
const contract = (0, core_1.createContract)({
|
|
350
|
+
address: vault,
|
|
351
|
+
provider: signer,
|
|
352
|
+
abi: abis_1.ABI_LENDING_POOLS,
|
|
353
|
+
});
|
|
354
|
+
const result = await contract.previewDeposit(amountRaw);
|
|
355
|
+
return BigInt(result);
|
|
356
|
+
}
|
|
357
|
+
catch (e) {
|
|
358
|
+
if (e instanceof core_1.AugustValidationError || e instanceof core_1.AugustSDKError) {
|
|
359
|
+
throw e;
|
|
360
|
+
}
|
|
361
|
+
(0, core_1.logChainError)('previewDeposit', e, (0, core_1.isExpectedRevertError)(e), {
|
|
362
|
+
vault,
|
|
363
|
+
amount: amount.toString(),
|
|
364
|
+
});
|
|
365
|
+
throw new core_1.AugustSDKError('UNKNOWN', `previewDeposit failed: ${e instanceof Error ? e.message : 'Unknown error'}`, { cause: e, context: { vault, amount: amount.toString() } });
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Preview the number of underlying assets returned by redeeming a given
|
|
370
|
+
* number of shares, without touching on-chain state. Routes between single-
|
|
371
|
+
* asset ERC-4626 (`previewRedeem`) and EVM-2 multi-asset
|
|
372
|
+
* (`previewRedemption(shares, isInstant=false)`) using the vault version.
|
|
373
|
+
*
|
|
374
|
+
* @returns The assets that would be redeemed (raw on-chain units, asset
|
|
375
|
+
* decimals).
|
|
376
|
+
* @throws AugustValidationError on invalid vault or share input.
|
|
377
|
+
* @throws AugustSDKError when the underlying contract call fails.
|
|
378
|
+
*
|
|
379
|
+
* @example
|
|
380
|
+
* ```ts
|
|
381
|
+
* const assets = await augustSdk.evm.previewRedeem({
|
|
382
|
+
* vault: '0xE9B725010A9E419412ed67d0fA5f3A5f40159D32',
|
|
383
|
+
* shares: 1_000_000_000_000_000_000n, // 1 share (18 decimals)
|
|
384
|
+
* });
|
|
385
|
+
* ```
|
|
386
|
+
*/
|
|
387
|
+
async function previewRedeem(signer, options) {
|
|
388
|
+
const { vault, shares } = options;
|
|
389
|
+
if (!(0, core_1.checkAddress)(vault, console, 'contract')) {
|
|
390
|
+
throw new core_1.AugustValidationError('INVALID_ADDRESS', `previewRedeem: invalid vault address ${vault}`);
|
|
391
|
+
}
|
|
392
|
+
const sharesRaw = toRawBigInt(shares, 'previewRedeem');
|
|
393
|
+
try {
|
|
394
|
+
const tokenizedVault = (await (0, core_1.fetchTokenizedVault)(vault))?.[0];
|
|
395
|
+
const vaultVersion = (0, core_1.getVaultVersionV2)(tokenizedVault);
|
|
396
|
+
const isMultiAsset = vaultVersion === 'evm-2';
|
|
397
|
+
if (isMultiAsset) {
|
|
398
|
+
const contract = (0, core_1.createContract)({
|
|
399
|
+
address: vault,
|
|
400
|
+
provider: signer,
|
|
401
|
+
abi: abis_1.ABI_TOKENIZED_VAULT_V2,
|
|
402
|
+
});
|
|
403
|
+
const result = await contract.previewRedemption(sharesRaw, false);
|
|
404
|
+
// EVM-2 previewRedemption returns (assetsAmount, assetsAfterFee); take gross.
|
|
405
|
+
const assets = Array.isArray(result) ? result[0] : result;
|
|
406
|
+
return BigInt(assets);
|
|
407
|
+
}
|
|
408
|
+
const contract = (0, core_1.createContract)({
|
|
409
|
+
address: vault,
|
|
410
|
+
provider: signer,
|
|
411
|
+
abi: abis_1.ABI_LENDING_POOLS,
|
|
412
|
+
});
|
|
413
|
+
const result = await contract.previewRedeem(sharesRaw);
|
|
414
|
+
return BigInt(result);
|
|
415
|
+
}
|
|
416
|
+
catch (e) {
|
|
417
|
+
if (e instanceof core_1.AugustValidationError || e instanceof core_1.AugustSDKError) {
|
|
418
|
+
throw e;
|
|
419
|
+
}
|
|
420
|
+
(0, core_1.logChainError)('previewRedeem', e, (0, core_1.isExpectedRevertError)(e), {
|
|
421
|
+
vault,
|
|
422
|
+
shares: shares.toString(),
|
|
423
|
+
});
|
|
424
|
+
throw new core_1.AugustSDKError('UNKNOWN', `previewRedeem failed: ${e instanceof Error ? e.message : 'Unknown error'}`, { cause: e, context: { vault, shares: shares.toString() } });
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Read the ERC-20 allowance an `owner` has granted to a vault (the spender).
|
|
429
|
+
* If `asset` is omitted, the vault's underlying asset is resolved via
|
|
430
|
+
* `IERC4626.asset()` and used as the token.
|
|
431
|
+
*
|
|
432
|
+
* Returns a raw `bigint` to keep BigInt math precise — call
|
|
433
|
+
* {@link toNormalizedBn} if you need a UI-shaped {@link INormalizedNumber}.
|
|
434
|
+
*
|
|
435
|
+
* @returns Allowance in raw on-chain units of `asset`.
|
|
436
|
+
* @throws AugustValidationError on invalid addresses.
|
|
437
|
+
* @throws AugustSDKError when the underlying contract call fails.
|
|
438
|
+
*
|
|
439
|
+
* @example
|
|
440
|
+
* ```ts
|
|
441
|
+
* const raw = await augustSdk.evm.allowance({
|
|
442
|
+
* vault: '0xE9B725010A9E419412ed67d0fA5f3A5f40159D32',
|
|
443
|
+
* owner: walletAddress,
|
|
444
|
+
* });
|
|
445
|
+
* if (raw < requiredAmount) {
|
|
446
|
+
* await augustSdk.evm.vaultApprove({
|
|
447
|
+
* target: vault,
|
|
448
|
+
* wallet: walletAddress,
|
|
449
|
+
* amount: requiredAmount.toString(),
|
|
450
|
+
* });
|
|
451
|
+
* }
|
|
452
|
+
* ```
|
|
453
|
+
*/
|
|
454
|
+
async function allowance(signer, options) {
|
|
455
|
+
const { vault, owner, asset } = options;
|
|
456
|
+
if (!(0, core_1.checkAddress)(vault, console, 'contract')) {
|
|
457
|
+
throw new core_1.AugustValidationError('INVALID_ADDRESS', `allowance: invalid vault address ${vault}`);
|
|
458
|
+
}
|
|
459
|
+
if (!(0, core_1.checkAddress)(owner, console, 'wallet')) {
|
|
460
|
+
throw new core_1.AugustValidationError('INVALID_ADDRESS', `allowance: invalid owner address ${owner}`);
|
|
461
|
+
}
|
|
462
|
+
if (asset && !(0, core_1.checkAddress)(asset, console, 'contract')) {
|
|
463
|
+
throw new core_1.AugustValidationError('INVALID_ADDRESS', `allowance: invalid asset address ${asset}`);
|
|
464
|
+
}
|
|
465
|
+
try {
|
|
466
|
+
let tokenAddress;
|
|
467
|
+
if (asset) {
|
|
468
|
+
tokenAddress = asset;
|
|
469
|
+
}
|
|
470
|
+
else {
|
|
471
|
+
const vaultContract = (0, core_1.createContract)({
|
|
472
|
+
address: vault,
|
|
473
|
+
provider: signer,
|
|
474
|
+
abi: abis_1.ABI_LENDING_POOLS,
|
|
475
|
+
});
|
|
476
|
+
tokenAddress = (await vaultContract.asset());
|
|
477
|
+
}
|
|
478
|
+
const tokenContract = (0, core_1.createContract)({
|
|
479
|
+
address: tokenAddress,
|
|
480
|
+
provider: signer,
|
|
481
|
+
abi: abis_1.ABI_ERC20,
|
|
482
|
+
});
|
|
483
|
+
const raw = (await tokenContract.allowance(owner, vault));
|
|
484
|
+
return BigInt(raw);
|
|
485
|
+
}
|
|
486
|
+
catch (e) {
|
|
487
|
+
if (e instanceof core_1.AugustValidationError || e instanceof core_1.AugustSDKError) {
|
|
488
|
+
throw e;
|
|
489
|
+
}
|
|
490
|
+
(0, core_1.logChainError)('allowance', e, (0, core_1.isExpectedRevertError)(e), {
|
|
491
|
+
vault,
|
|
492
|
+
owner,
|
|
493
|
+
asset,
|
|
494
|
+
});
|
|
495
|
+
throw new core_1.AugustSDKError('UNKNOWN', `allowance failed: ${e instanceof Error ? e.message : 'Unknown error'}`, { cause: e, context: { vault, owner, asset } });
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Read an ERC-20 balance directly. Returns the raw on-chain value as
|
|
500
|
+
* `bigint`; call {@link toNormalizedBn} if you need a {@link INormalizedNumber}.
|
|
501
|
+
*
|
|
502
|
+
* @returns Balance in raw on-chain units of `asset`.
|
|
503
|
+
* @throws AugustValidationError on invalid asset / owner addresses.
|
|
504
|
+
* @throws AugustSDKError when the underlying contract call fails.
|
|
505
|
+
*
|
|
506
|
+
* @example
|
|
507
|
+
* ```ts
|
|
508
|
+
* const raw = await augustSdk.evm.balanceOf({
|
|
509
|
+
* asset: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
|
|
510
|
+
* owner: walletAddress,
|
|
511
|
+
* });
|
|
512
|
+
* ```
|
|
513
|
+
*/
|
|
514
|
+
async function balanceOf(signer, options) {
|
|
515
|
+
const { asset, owner } = options;
|
|
516
|
+
if (!(0, core_1.checkAddress)(asset, console, 'contract')) {
|
|
517
|
+
throw new core_1.AugustValidationError('INVALID_ADDRESS', `balanceOf: invalid asset address ${asset}`);
|
|
518
|
+
}
|
|
519
|
+
if (!(0, core_1.checkAddress)(owner, console, 'wallet')) {
|
|
520
|
+
throw new core_1.AugustValidationError('INVALID_ADDRESS', `balanceOf: invalid owner address ${owner}`);
|
|
521
|
+
}
|
|
522
|
+
try {
|
|
523
|
+
const tokenContract = (0, core_1.createContract)({
|
|
524
|
+
address: asset,
|
|
525
|
+
provider: signer,
|
|
526
|
+
abi: abis_1.ABI_ERC20,
|
|
527
|
+
});
|
|
528
|
+
const raw = (await tokenContract.balanceOf(owner));
|
|
529
|
+
return BigInt(raw);
|
|
530
|
+
}
|
|
531
|
+
catch (e) {
|
|
532
|
+
if (e instanceof core_1.AugustValidationError || e instanceof core_1.AugustSDKError) {
|
|
533
|
+
throw e;
|
|
534
|
+
}
|
|
535
|
+
(0, core_1.logChainError)('balanceOf', e, (0, core_1.isExpectedRevertError)(e), { asset, owner });
|
|
536
|
+
throw new core_1.AugustSDKError('UNKNOWN', `balanceOf failed: ${e instanceof Error ? e.message : 'Unknown error'}`, { cause: e, context: { asset, owner } });
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Read the maximum deposit currently accepted by a vault. Routes between
|
|
541
|
+
* single-asset ERC-4626 (`maxDeposit(receiver)`) and EVM-2 multi-asset
|
|
542
|
+
* (`maxDepositAmount()`, vault-level cap, no receiver dependence).
|
|
543
|
+
*
|
|
544
|
+
* @returns Max deposit in raw on-chain units of the deposit asset.
|
|
545
|
+
* @throws AugustValidationError on invalid vault address.
|
|
546
|
+
* @throws AugustSDKError when the underlying contract call fails.
|
|
547
|
+
*
|
|
548
|
+
* @example
|
|
549
|
+
* ```ts
|
|
550
|
+
* const cap = await augustSdk.evm.maxDeposit({ vault });
|
|
551
|
+
* if (cap === 0n) showVaultIsFullToast();
|
|
552
|
+
* ```
|
|
553
|
+
*/
|
|
554
|
+
async function maxDeposit(signer, options) {
|
|
555
|
+
const { vault, receiver } = options;
|
|
556
|
+
if (!(0, core_1.checkAddress)(vault, console, 'contract')) {
|
|
557
|
+
throw new core_1.AugustValidationError('INVALID_ADDRESS', `maxDeposit: invalid vault address ${vault}`);
|
|
558
|
+
}
|
|
559
|
+
if (receiver && !(0, core_1.checkAddress)(receiver, console, 'wallet')) {
|
|
560
|
+
throw new core_1.AugustValidationError('INVALID_ADDRESS', `maxDeposit: invalid receiver address ${receiver}`);
|
|
561
|
+
}
|
|
562
|
+
try {
|
|
563
|
+
const tokenizedVault = (await (0, core_1.fetchTokenizedVault)(vault))?.[0];
|
|
564
|
+
const vaultVersion = (0, core_1.getVaultVersionV2)(tokenizedVault);
|
|
565
|
+
const isMultiAsset = vaultVersion === 'evm-2';
|
|
566
|
+
if (isMultiAsset) {
|
|
567
|
+
const contract = (0, core_1.createContract)({
|
|
568
|
+
address: vault,
|
|
569
|
+
provider: signer,
|
|
570
|
+
abi: abis_1.ABI_TOKENIZED_VAULT_V2,
|
|
571
|
+
});
|
|
572
|
+
const raw = (await contract.maxDepositAmount());
|
|
573
|
+
return BigInt(raw);
|
|
574
|
+
}
|
|
575
|
+
const contract = (0, core_1.createContract)({
|
|
576
|
+
address: vault,
|
|
577
|
+
provider: signer,
|
|
578
|
+
abi: abis_1.ABI_LENDING_POOLS,
|
|
579
|
+
});
|
|
580
|
+
// Zero-address default: vaults that require a receiver arg won't revert.
|
|
581
|
+
const target = receiver ?? '0x0000000000000000000000000000000000000000';
|
|
582
|
+
const raw = (await contract.maxDeposit(target));
|
|
583
|
+
return BigInt(raw);
|
|
584
|
+
}
|
|
585
|
+
catch (e) {
|
|
586
|
+
if (e instanceof core_1.AugustValidationError || e instanceof core_1.AugustSDKError) {
|
|
587
|
+
throw e;
|
|
588
|
+
}
|
|
589
|
+
(0, core_1.logChainError)('maxDeposit', e, (0, core_1.isExpectedRevertError)(e), {
|
|
590
|
+
vault,
|
|
591
|
+
receiver,
|
|
592
|
+
});
|
|
593
|
+
throw new core_1.AugustSDKError('UNKNOWN', `maxDeposit failed: ${e instanceof Error ? e.message : 'Unknown error'}`, { cause: e, context: { vault, receiver } });
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
//# sourceMappingURL=read.actions.js.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { Connection } from '@solana/web3.js';
|
|
2
|
+
import type { IAddress, IEnv, IStellarNetwork, IWSMonitorHeaders } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* Structural interface for the Solana adapter surface used by vault operations.
|
|
5
|
+
* Avoids importing the concrete SolanaAdapter class to prevent circular dependencies.
|
|
6
|
+
*/
|
|
7
|
+
export interface ISolanaService {
|
|
8
|
+
connection: Connection;
|
|
9
|
+
getVaultState: (vaultProgramId: any, idl: any, vaultAddress?: any) => Promise<any>;
|
|
10
|
+
fetchUserShareBalance: (publicKey: any, shareMint: any) => Promise<any>;
|
|
11
|
+
/**
|
|
12
|
+
* Raw (BigInt-safe) variant. Required — `fetchUserShareBalance` alone
|
|
13
|
+
* returns a JS-number `uiAmount` which is lossy and silently encodes
|
|
14
|
+
* against 18 decimals when fed back through `toNormalizedBn` without an
|
|
15
|
+
* explicit decimals argument. Every consumer that needs a correct
|
|
16
|
+
* `walletBalance.raw` (positions, redemptions, max actions) MUST use this
|
|
17
|
+
* entry point.
|
|
18
|
+
*
|
|
19
|
+
* Returns `{ amount, decimals }`:
|
|
20
|
+
* - `amount` is the on-chain u64 as a base-units string (always set;
|
|
21
|
+
* `'0'` when no balance / no account / no args / RPC failure).
|
|
22
|
+
* - `decimals` matches the mint when a parsed `tokenAmount` is
|
|
23
|
+
* available; otherwise **`null`**. `decimals === null` is the
|
|
24
|
+
* "scale unknown" signal — callers must substitute a known decimals
|
|
25
|
+
* value (typically the deposit mint's decimals from backend metadata)
|
|
26
|
+
* before constructing an `INormalizedNumber`. Never throws.
|
|
27
|
+
*/
|
|
28
|
+
fetchUserShareBalanceRaw: (publicKey: any, shareMint: any) => Promise<{
|
|
29
|
+
amount: string;
|
|
30
|
+
decimals: number | null;
|
|
31
|
+
}>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Base configuration for vault operations.
|
|
35
|
+
*/
|
|
36
|
+
export interface IVaultBaseOptions {
|
|
37
|
+
rpcUrl: string;
|
|
38
|
+
env?: IEnv;
|
|
39
|
+
augustKey?: string;
|
|
40
|
+
subgraphKey?: string;
|
|
41
|
+
chainId?: number;
|
|
42
|
+
solanaService?: ISolanaService;
|
|
43
|
+
/**
|
|
44
|
+
* Optional Soroban RPC override (e.g. a keyed Alchemy URL) for Stellar vault
|
|
45
|
+
* reads, threaded from the SDK's `stellar` config. Carries the network it was
|
|
46
|
+
* configured for so it is only applied to matching-network vaults — a testnet
|
|
47
|
+
* override must not be used for a mainnet read. Unset → built-in endpoints.
|
|
48
|
+
*/
|
|
49
|
+
stellarRpc?: {
|
|
50
|
+
rpcUrl: string;
|
|
51
|
+
network: IStellarNetwork;
|
|
52
|
+
};
|
|
53
|
+
headers?: IWSMonitorHeaders;
|
|
54
|
+
/**
|
|
55
|
+
* Portfolio mode: when true, the per-vault EVM getter does NOT null out a
|
|
56
|
+
* closed + invisible vault. Needed so a user's position in a closed,
|
|
57
|
+
* invisible vault can still resolve its metadata. Defaults to undefined
|
|
58
|
+
* (false) so marketplace/discovery reads keep hiding closed staging vaults.
|
|
59
|
+
*/
|
|
60
|
+
includeClosed?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Optional enrichment options for vault queries.
|
|
64
|
+
*/
|
|
65
|
+
export interface IVaultCustomOptions {
|
|
66
|
+
loans?: boolean;
|
|
67
|
+
allocations?: boolean;
|
|
68
|
+
wallet?: IAddress;
|
|
69
|
+
solanaWallet?: string;
|
|
70
|
+
stellarWallet?: string;
|
|
71
|
+
}
|