@augustdigital/sdk 4.1.0-alpha → 4.1.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/README.md +189 -11
- package/lib/abis/Multicall3.js.map +1 -1
- package/lib/abis/PoolAdapter.d.ts +36 -76
- package/lib/abis/PoolAdapter.js +18 -379
- package/lib/abis/PoolAdapter.js.map +1 -1
- package/lib/abis/WrapperAdapter.d.ts +71 -60
- package/lib/abis/WrapperAdapter.js +41 -114
- package/lib/abis/WrapperAdapter.js.map +1 -1
- package/lib/abis/index.d.ts +3 -0
- package/lib/abis/index.js +3 -0
- package/lib/abis/index.js.map +1 -1
- package/lib/adapters/evm/getters.d.ts +1 -1
- package/lib/adapters/evm/getters.js +26 -37
- package/lib/adapters/evm/getters.js.map +1 -1
- package/lib/adapters/evm/index.d.ts +8 -6
- package/lib/adapters/evm/index.js +27 -21
- package/lib/adapters/evm/index.js.map +1 -1
- package/lib/adapters/evm/utils.d.ts +2 -28
- package/lib/adapters/evm/utils.js +29 -322
- package/lib/adapters/evm/utils.js.map +1 -1
- package/lib/adapters/solana/getters.js +35 -28
- package/lib/adapters/solana/getters.js.map +1 -1
- package/lib/adapters/solana/index.d.ts +27 -2
- package/lib/adapters/solana/utils.d.ts +15 -2
- package/lib/adapters/solana/utils.js +96 -21
- package/lib/adapters/solana/utils.js.map +1 -1
- package/lib/adapters/solana/vault.actions.js +11 -2
- package/lib/adapters/solana/vault.actions.js.map +1 -1
- package/lib/adapters/sui/constants.d.ts +13 -0
- package/lib/adapters/sui/constants.js +17 -0
- package/lib/adapters/sui/constants.js.map +1 -0
- package/lib/adapters/sui/getters.d.ts +3 -0
- package/lib/adapters/sui/getters.js +53 -0
- package/lib/adapters/sui/getters.js.map +1 -0
- package/lib/adapters/sui/index.d.ts +30 -0
- package/lib/adapters/sui/index.js +83 -0
- package/lib/adapters/sui/index.js.map +1 -1
- package/lib/adapters/sui/transformer.d.ts +4 -0
- package/lib/adapters/sui/transformer.js +87 -0
- package/lib/adapters/sui/transformer.js.map +1 -0
- package/lib/adapters/sui/types.d.ts +62 -0
- package/lib/{services/solana → adapters/sui}/types.js.map +1 -1
- package/lib/adapters/sui/utils.d.ts +4 -0
- package/lib/adapters/sui/utils.js +27 -0
- package/lib/adapters/sui/utils.js.map +1 -0
- package/lib/core/auth/verify.js +2 -2
- package/lib/core/auth/verify.js.map +1 -1
- package/lib/core/base.class.d.ts +1 -2
- package/lib/core/base.class.js +11 -6
- package/lib/core/base.class.js.map +1 -1
- package/lib/core/constants.adapters.d.ts +89 -0
- package/lib/core/constants.adapters.js +160 -0
- package/lib/core/constants.adapters.js.map +1 -0
- package/lib/{utils/constants/august.d.ts → core/constants.core.d.ts} +10 -1
- package/lib/{utils/constants/august.js → core/constants.core.js} +11 -2
- package/lib/core/constants.core.js.map +1 -0
- package/lib/core/constants.vaults.d.ts +19 -0
- package/lib/{utils/vaults.js → core/constants.vaults.js} +56 -75
- package/lib/core/constants.vaults.js.map +1 -0
- package/lib/{utils/constants/web3.d.ts → core/constants.web3.d.ts} +4 -6
- package/lib/{utils/constants/web3.js → core/constants.web3.js} +21 -27
- package/lib/core/constants.web3.js.map +1 -0
- package/lib/core/fetcher.d.ts +1 -1
- package/lib/core/fetcher.js +177 -64
- package/lib/core/fetcher.js.map +1 -1
- package/lib/core/helpers.adapters.d.ts +4 -0
- package/lib/core/helpers.adapters.js +28 -0
- package/lib/core/helpers.adapters.js.map +1 -0
- package/lib/core/helpers.core.d.ts +1 -1
- package/lib/core/helpers.core.js +6 -6
- package/lib/core/helpers.core.js.map +1 -1
- package/lib/core/helpers.signer.d.ts +5 -0
- package/lib/core/helpers.signer.js +54 -0
- package/lib/core/helpers.signer.js.map +1 -0
- package/lib/core/helpers.vaults.d.ts +15 -0
- package/lib/core/helpers.vaults.js +123 -0
- package/lib/core/helpers.vaults.js.map +1 -0
- package/lib/core/helpers.web3.d.ts +5 -2
- package/lib/core/helpers.web3.js +84 -26
- package/lib/core/helpers.web3.js.map +1 -1
- package/lib/core/index.d.ts +9 -5
- package/lib/core/index.js +9 -5
- package/lib/core/index.js.map +1 -1
- package/lib/core/logger/index.d.ts +9 -0
- package/lib/core/logger/index.js +29 -0
- package/lib/core/logger/index.js.map +1 -1
- package/lib/core/logger/slack.js +3 -3
- package/lib/index.d.ts +6 -6
- package/lib/index.js +14 -7
- package/lib/index.js.map +1 -1
- package/lib/main.d.ts +90 -14
- package/lib/main.js +56 -17
- package/lib/main.js.map +1 -1
- package/lib/modules/vaults/adapter.helpers.d.ts +46 -0
- package/lib/modules/vaults/adapter.helpers.js +149 -0
- package/lib/modules/vaults/adapter.helpers.js.map +1 -0
- package/lib/{vaults/utils.d.ts → modules/vaults/fetcher.d.ts} +0 -20
- package/lib/{vaults/utils.js → modules/vaults/fetcher.js} +19 -176
- package/lib/modules/vaults/fetcher.js.map +1 -0
- package/lib/modules/vaults/getters.d.ts +32 -3
- package/lib/modules/vaults/getters.js +367 -71
- package/lib/modules/vaults/getters.js.map +1 -1
- package/lib/modules/vaults/index.d.ts +2 -83
- package/lib/modules/vaults/index.js +2 -480
- package/lib/modules/vaults/index.js.map +1 -1
- package/lib/modules/vaults/main.d.ts +29 -47
- package/lib/modules/vaults/main.js +142 -201
- package/lib/modules/vaults/main.js.map +1 -1
- package/lib/modules/vaults/read.actions.d.ts +3 -0
- package/lib/{adapters/evm → modules/vaults}/read.actions.js +12 -12
- package/lib/modules/vaults/read.actions.js.map +1 -0
- package/lib/modules/vaults/utils.d.ts +2 -106
- package/lib/modules/vaults/utils.js +139 -337
- package/lib/modules/vaults/utils.js.map +1 -1
- package/lib/modules/vaults/{vault.actions.d.ts → write.actions.d.ts} +11 -1
- package/lib/modules/vaults/write.actions.js +301 -0
- package/lib/modules/vaults/write.actions.js.map +1 -0
- package/lib/services/debank/utils.js +4 -4
- package/lib/services/subgraph/fetcher.js +3 -2
- package/lib/services/subgraph/fetcher.js.map +1 -1
- package/lib/services/subgraph/vaults.js +25 -27
- package/lib/services/subgraph/vaults.js.map +1 -1
- package/lib/types/pools.d.ts +1 -1
- package/lib/types/vaults.d.ts +21 -1
- package/lib/types/webserver.d.ts +15 -1
- package/package.json +24 -10
- package/lib/adapters/evm/core.actions.d.ts +0 -9
- package/lib/adapters/evm/core.actions.js +0 -51
- package/lib/adapters/evm/core.actions.js.map +0 -1
- package/lib/adapters/evm/read.actions.d.ts +0 -3
- package/lib/adapters/evm/read.actions.js.map +0 -1
- package/lib/adapters/evm/vaults.actions.d.ts +0 -10
- package/lib/adapters/evm/vaults.actions.js +0 -97
- package/lib/adapters/evm/vaults.actions.js.map +0 -1
- package/lib/adapters/solana/actions.d.ts +0 -20
- package/lib/adapters/solana/actions.js +0 -225
- package/lib/adapters/solana/actions.js.map +0 -1
- package/lib/adapters/solana/class.d.ts +0 -45
- package/lib/adapters/solana/class.js +0 -135
- package/lib/adapters/solana/class.js.map +0 -1
- package/lib/adapters/solana/vault-idl.d.ts +0 -338
- package/lib/adapters/solana/vault-idl.js +0 -1075
- package/lib/adapters/solana/vault-idl.js.map +0 -1
- package/lib/core/base-class.d.ts +0 -34
- package/lib/core/base-class.js +0 -55
- package/lib/core/base-class.js.map +0 -1
- package/lib/core/constants.d.ts +0 -86
- package/lib/core/constants.js +0 -146
- package/lib/core/constants.js.map +0 -1
- package/lib/core/core.helpers.d.ts +0 -23
- package/lib/core/core.helpers.js +0 -210
- package/lib/core/core.helpers.js.map +0 -1
- package/lib/core/helpers.d.ts +0 -23
- package/lib/core/helpers.js +0 -210
- package/lib/core/helpers.js.map +0 -1
- package/lib/core/read.actions.d.ts +0 -3
- package/lib/core/read.actions.js +0 -39
- package/lib/core/read.actions.js.map +0 -1
- package/lib/core/web3.helpers.d.ts +0 -28
- package/lib/core/web3.helpers.js +0 -336
- package/lib/core/web3.helpers.js.map +0 -1
- package/lib/core/write.actions.d.ts +0 -9
- package/lib/core/write.actions.js +0 -51
- package/lib/core/write.actions.js.map +0 -1
- package/lib/modules/vaults/admin-actions.d.ts +0 -0
- package/lib/modules/vaults/admin-actions.js +0 -1
- package/lib/modules/vaults/admin-actions.js.map +0 -1
- package/lib/modules/vaults/constants.d.ts +0 -63
- package/lib/modules/vaults/constants.js +0 -190
- package/lib/modules/vaults/constants.js.map +0 -1
- package/lib/modules/vaults/user-actions.d.ts +0 -19
- package/lib/modules/vaults/user-actions.js +0 -172
- package/lib/modules/vaults/user-actions.js.map +0 -1
- package/lib/modules/vaults/user.actions.d.ts +0 -10
- package/lib/modules/vaults/user.actions.js +0 -95
- package/lib/modules/vaults/user.actions.js.map +0 -1
- package/lib/modules/vaults/vault.actions.js +0 -95
- package/lib/modules/vaults/vault.actions.js.map +0 -1
- package/lib/services/auth/index.d.ts +0 -1
- package/lib/services/auth/index.js +0 -18
- package/lib/services/auth/index.js.map +0 -1
- package/lib/services/auth/verify.d.ts +0 -2
- package/lib/services/auth/verify.js +0 -20
- package/lib/services/auth/verify.js.map +0 -1
- package/lib/services/index.d.ts +0 -4
- package/lib/services/index.js +0 -21
- package/lib/services/index.js.map +0 -1
- package/lib/services/logger/index.d.ts +0 -12
- package/lib/services/logger/index.js +0 -51
- package/lib/services/logger/index.js.map +0 -1
- package/lib/services/logger/slack.d.ts +0 -12
- package/lib/services/logger/slack.js +0 -48
- package/lib/services/logger/slack.js.map +0 -1
- package/lib/services/solana/actions.d.ts +0 -20
- package/lib/services/solana/actions.js +0 -225
- package/lib/services/solana/actions.js.map +0 -1
- package/lib/services/solana/class.d.ts +0 -45
- package/lib/services/solana/class.js +0 -135
- package/lib/services/solana/class.js.map +0 -1
- package/lib/services/solana/constants.d.ts +0 -25
- package/lib/services/solana/constants.js +0 -32
- package/lib/services/solana/constants.js.map +0 -1
- package/lib/services/solana/index.d.ts +0 -84
- package/lib/services/solana/index.js +0 -50
- package/lib/services/solana/index.js.map +0 -1
- package/lib/services/solana/types.d.ts +0 -58
- package/lib/services/solana/utils.d.ts +0 -96
- package/lib/services/solana/utils.js +0 -355
- package/lib/services/solana/utils.js.map +0 -1
- package/lib/services/solana/vault-idl.d.ts +0 -338
- package/lib/services/solana/vault-idl.js +0 -1075
- package/lib/services/solana/vault-idl.js.map +0 -1
- package/lib/utils/base-class.d.ts +0 -34
- package/lib/utils/base-class.js +0 -55
- package/lib/utils/base-class.js.map +0 -1
- package/lib/utils/constants/august.js.map +0 -1
- package/lib/utils/constants/fallbacks.d.ts +0 -3
- package/lib/utils/constants/fallbacks.js +0 -26
- package/lib/utils/constants/fallbacks.js.map +0 -1
- package/lib/utils/constants/index.d.ts +0 -3
- package/lib/utils/constants/index.js +0 -20
- package/lib/utils/constants/index.js.map +0 -1
- package/lib/utils/constants/web3.js.map +0 -1
- package/lib/utils/fetcher.d.ts +0 -25
- package/lib/utils/fetcher.js +0 -334
- package/lib/utils/fetcher.js.map +0 -1
- package/lib/utils/helpers/array.d.ts +0 -6
- package/lib/utils/helpers/array.js +0 -40
- package/lib/utils/helpers/array.js.map +0 -1
- package/lib/utils/helpers/datetime.d.ts +0 -5
- package/lib/utils/helpers/datetime.js +0 -32
- package/lib/utils/helpers/datetime.js.map +0 -1
- package/lib/utils/helpers/formatters.d.ts +0 -8
- package/lib/utils/helpers/formatters.js +0 -113
- package/lib/utils/helpers/formatters.js.map +0 -1
- package/lib/utils/helpers/index.d.ts +0 -6
- package/lib/utils/helpers/index.js +0 -23
- package/lib/utils/helpers/index.js.map +0 -1
- package/lib/utils/helpers/responses.d.ts +0 -32
- package/lib/utils/helpers/responses.js +0 -229
- package/lib/utils/helpers/responses.js.map +0 -1
- package/lib/utils/helpers/verify-keys.d.ts +0 -2
- package/lib/utils/helpers/verify-keys.js +0 -21
- package/lib/utils/helpers/verify-keys.js.map +0 -1
- package/lib/utils/helpers/web3.d.ts +0 -27
- package/lib/utils/helpers/web3.js +0 -339
- package/lib/utils/helpers/web3.js.map +0 -1
- package/lib/utils/index.d.ts +0 -5
- package/lib/utils/index.js +0 -22
- package/lib/utils/index.js.map +0 -1
- package/lib/utils/vaults.d.ts +0 -53
- package/lib/utils/vaults.js.map +0 -1
- package/lib/vaults/admin-actions.d.ts +0 -0
- package/lib/vaults/admin-actions.js +0 -1
- package/lib/vaults/admin-actions.js.map +0 -1
- package/lib/vaults/getters.d.ts +0 -38
- package/lib/vaults/getters.js +0 -760
- package/lib/vaults/getters.js.map +0 -1
- package/lib/vaults/index.d.ts +0 -4
- package/lib/vaults/index.js +0 -21
- package/lib/vaults/index.js.map +0 -1
- package/lib/vaults/main.d.ts +0 -118
- package/lib/vaults/main.js +0 -591
- package/lib/vaults/main.js.map +0 -1
- package/lib/vaults/rpc-config.d.ts +0 -4
- package/lib/vaults/rpc-config.js +0 -27
- package/lib/vaults/rpc-config.js.map +0 -1
- package/lib/vaults/subgraph.d.ts +0 -10
- package/lib/vaults/subgraph.js +0 -470
- package/lib/vaults/subgraph.js.map +0 -1
- package/lib/vaults/user-actions.d.ts +0 -19
- package/lib/vaults/user-actions.js +0 -172
- package/lib/vaults/user-actions.js.map +0 -1
- package/lib/vaults/utils.js.map +0 -1
- package/lib/verify.d.ts +0 -2
- package/lib/verify.js +0 -20
- package/lib/verify.js.map +0 -1
- /package/lib/{services/solana → adapters/sui}/types.js +0 -0
package/lib/vaults/getters.js
DELETED
|
@@ -1,760 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getVault = getVault;
|
|
4
|
-
exports.getVaultLoans = getVaultLoans;
|
|
5
|
-
exports.getVaultAllocations = getVaultAllocations;
|
|
6
|
-
exports.getVaultAvailableRedemptions = getVaultAvailableRedemptions;
|
|
7
|
-
exports.getVaultRedemptionHistory = getVaultRedemptionHistory;
|
|
8
|
-
exports.getVaultPositions = getVaultPositions;
|
|
9
|
-
exports.getVaultApy = getVaultApy;
|
|
10
|
-
exports.getRewardsStakingPositions = getRewardsStakingPositions;
|
|
11
|
-
const abis_1 = require("../abis");
|
|
12
|
-
const utils_1 = require("../utils");
|
|
13
|
-
const ethers_1 = require("ethers");
|
|
14
|
-
const services_1 = require("../services");
|
|
15
|
-
const utils_2 = require("./utils");
|
|
16
|
-
const subgraph_1 = require("./subgraph");
|
|
17
|
-
async function getVault({ vault, loans = false, allocations = false, options, }) {
|
|
18
|
-
let returnedVault;
|
|
19
|
-
try {
|
|
20
|
-
const tokenizedVault = (await (0, utils_1.fetchTokenizedVaults)(vault))?.[0];
|
|
21
|
-
const isSolana = services_1.Solana.utils.isSolanaAddress(vault);
|
|
22
|
-
if (isSolana) {
|
|
23
|
-
const solanaRpcUrl = options.rpcUrl;
|
|
24
|
-
const vaultState = await services_1.Solana.utils.getVaultStateReadOnly({
|
|
25
|
-
idl: services_1.Solana.constants.vaultIdl,
|
|
26
|
-
vaultProgramId: vault,
|
|
27
|
-
endpoint: solanaRpcUrl,
|
|
28
|
-
connection: options.solanaService?.connection,
|
|
29
|
-
});
|
|
30
|
-
let depositMint = null;
|
|
31
|
-
if (vaultState.vaultState && vaultState.vaultState.depositMint) {
|
|
32
|
-
depositMint = await services_1.Solana.utils.getToken({
|
|
33
|
-
mintAddress: vaultState.vaultState.depositMint,
|
|
34
|
-
endpoint: solanaRpcUrl,
|
|
35
|
-
connection: options.solanaService?.connection,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
const returnObj = {
|
|
39
|
-
address: vault,
|
|
40
|
-
chainId: utils_1.SPECIAL_CHAINS.solana.chainId,
|
|
41
|
-
name: tokenizedVault?.vault_name || 'Solana Program',
|
|
42
|
-
logoUrl: tokenizedVault?.vault_logo_url || '/img/strategist/august.svg',
|
|
43
|
-
symbol: tokenizedVault?.receipt_token_symbol || 'upSOL',
|
|
44
|
-
description: tokenizedVault?.description || 'Description here',
|
|
45
|
-
startDatetime: new Date(tokenizedVault?.start_datetime).toISOString() ||
|
|
46
|
-
new Date().toISOString(),
|
|
47
|
-
status: 'active',
|
|
48
|
-
internalType: tokenizedVault?.internal_type ||
|
|
49
|
-
'tokenizedVault',
|
|
50
|
-
publicType: tokenizedVault?.public_type || 'Defi Yield',
|
|
51
|
-
tags: [tokenizedVault?.public_type || 'Defi Yield'],
|
|
52
|
-
isFeatured: tokenizedVault?.is_featured || false,
|
|
53
|
-
isVisible: tokenizedVault?.is_visible || true,
|
|
54
|
-
reserveTarget: tokenizedVault?.reserve_target || 0,
|
|
55
|
-
reserveTolerance: tokenizedVault?.reserve_tolerance || 0,
|
|
56
|
-
decimals: vaultState.depositMintDecimals || 0,
|
|
57
|
-
totalAssets: (0, utils_1.toNormalizedBn)(vaultState.vaultToken?.balance, vaultState.depositMintDecimals),
|
|
58
|
-
totalSupply: (0, utils_1.toNormalizedBn)(vaultState.vaultToken?.balance, vaultState.depositMintDecimals),
|
|
59
|
-
loansOperator: '0x',
|
|
60
|
-
maxSupply: (0, utils_1.toNormalizedBn)(1000000000000),
|
|
61
|
-
underlying: {
|
|
62
|
-
address: depositMint?.address,
|
|
63
|
-
symbol: depositMint?.symbol,
|
|
64
|
-
decimals: depositMint?.decimals || services_1.Solana.constants.fallbackDecimals,
|
|
65
|
-
name: depositMint?.name,
|
|
66
|
-
},
|
|
67
|
-
apy: tokenizedVault?.reported_apy?.apy || 0,
|
|
68
|
-
apyBreakdown: tokenizedVault?.reported_apy || {
|
|
69
|
-
apy: 0,
|
|
70
|
-
explainer: '',
|
|
71
|
-
liquidApy: 0,
|
|
72
|
-
rewardsClaimable: 0,
|
|
73
|
-
rewardsCompounded: 0,
|
|
74
|
-
underlyingApy: 0,
|
|
75
|
-
},
|
|
76
|
-
rewards: {
|
|
77
|
-
upshiftPoints: '0',
|
|
78
|
-
latestUpshiftPointMultiplier: 0,
|
|
79
|
-
upshiftPointsMultipliers: [],
|
|
80
|
-
additionalPoints: [],
|
|
81
|
-
},
|
|
82
|
-
weeklyPerformanceFee: tokenizedVault?.weekly_performance_fee_bps || 0,
|
|
83
|
-
platformFee: {
|
|
84
|
-
fee: tokenizedVault?.platform_fee_override?.management_fee || 0,
|
|
85
|
-
isWaived: false,
|
|
86
|
-
},
|
|
87
|
-
lagDuration: 0,
|
|
88
|
-
maxDailyDrawdown: tokenizedVault?.max_daily_drawdown || 0,
|
|
89
|
-
risk: tokenizedVault?.risk || 'low',
|
|
90
|
-
isWithdrawalPaused: false,
|
|
91
|
-
isDepositPaused: false,
|
|
92
|
-
idleAssets: (0, utils_1.toNormalizedBn)(0),
|
|
93
|
-
loans: [],
|
|
94
|
-
allocations: {
|
|
95
|
-
unfilteredTokens: [],
|
|
96
|
-
defi: [],
|
|
97
|
-
tokens: [],
|
|
98
|
-
cefi: [],
|
|
99
|
-
otc: {},
|
|
100
|
-
exposurePerCategory: {
|
|
101
|
-
borrowing: [],
|
|
102
|
-
supplying: [],
|
|
103
|
-
lending: [],
|
|
104
|
-
wallet: [],
|
|
105
|
-
cefiBalance: 0,
|
|
106
|
-
defiBalance: 0,
|
|
107
|
-
walletBalance: 0,
|
|
108
|
-
loanBalance: 0,
|
|
109
|
-
},
|
|
110
|
-
netValue: 0,
|
|
111
|
-
defiPerBorrower: {},
|
|
112
|
-
},
|
|
113
|
-
position: {
|
|
114
|
-
vault: vault,
|
|
115
|
-
status: 'active',
|
|
116
|
-
availableRedemptions: [],
|
|
117
|
-
pendingRedemptions: [],
|
|
118
|
-
redeemable: (0, utils_1.toNormalizedBn)(0),
|
|
119
|
-
walletBalance: (0, utils_1.toNormalizedBn)(0),
|
|
120
|
-
},
|
|
121
|
-
strategists: [
|
|
122
|
-
{
|
|
123
|
-
address: '0xE926502EdBcE3d56A409ef5dA352B5b522542D7c',
|
|
124
|
-
logo: '/img/strategist/august.svg',
|
|
125
|
-
name: 'August',
|
|
126
|
-
},
|
|
127
|
-
],
|
|
128
|
-
};
|
|
129
|
-
returnedVault = returnObj;
|
|
130
|
-
return returnObj;
|
|
131
|
-
}
|
|
132
|
-
else if ((0, ethers_1.isAddress)(vault)) {
|
|
133
|
-
const provider = (0, utils_1.createProvider)(options.rpcUrl);
|
|
134
|
-
const tokenizedVault = (await (0, utils_1.fetchTokenizedVaults)(vault, options?.headers))?.[0];
|
|
135
|
-
if (tokenizedVault.status === 'closed' &&
|
|
136
|
-
tokenizedVault.is_visible === false) {
|
|
137
|
-
console.log('#getVault::closed:', tokenizedVault.vault_name);
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
const vaultContract = (0, utils_1.createContract)({
|
|
141
|
-
address: vault,
|
|
142
|
-
abi: abis_1.ABI_LENDING_POOL_V2,
|
|
143
|
-
provider,
|
|
144
|
-
});
|
|
145
|
-
const vaultContractCalls = await Promise.all(utils_2.POOL_FUNCTIONS.map((f) => {
|
|
146
|
-
if ((f === 'totalSupply' || f === 'totalAssets') &&
|
|
147
|
-
utils_2.MULTI_ASSET_VAULTS.includes(vault)) {
|
|
148
|
-
return 0;
|
|
149
|
-
}
|
|
150
|
-
if (f === 'symbol') {
|
|
151
|
-
return (0, utils_1.getSymbol)(provider, vault);
|
|
152
|
-
}
|
|
153
|
-
if (f === 'decimals') {
|
|
154
|
-
return (0, utils_1.getDecimals)(provider, vault);
|
|
155
|
-
}
|
|
156
|
-
return vaultContract[f]();
|
|
157
|
-
}));
|
|
158
|
-
const formattedContractCalls = vaultContractCalls.reduce((acc, curr, i) => {
|
|
159
|
-
let val;
|
|
160
|
-
if (utils_2.POOL_FUNCTIONS[i] === 'totalSupply' ||
|
|
161
|
-
utils_2.POOL_FUNCTIONS[i] === 'totalAssets' ||
|
|
162
|
-
utils_2.POOL_FUNCTIONS[i] === 'globalLoansAmount' ||
|
|
163
|
-
utils_2.POOL_FUNCTIONS[i] === 'maxSupply') {
|
|
164
|
-
val = (0, utils_1.toNormalizedBn)(curr, vaultContractCalls[0]);
|
|
165
|
-
}
|
|
166
|
-
else if (utils_2.POOL_FUNCTIONS[i] === 'getTotalLoansDeployed') {
|
|
167
|
-
val = (0, utils_1.toNormalizedBn)(curr, 0);
|
|
168
|
-
}
|
|
169
|
-
else if (utils_2.POOL_FUNCTIONS[i] === 'withdrawalFee') {
|
|
170
|
-
val = (0, utils_1.toNormalizedBn)(curr, 2);
|
|
171
|
-
}
|
|
172
|
-
else if (utils_2.POOL_FUNCTIONS[i] === 'decimals') {
|
|
173
|
-
val = Number(curr.toString());
|
|
174
|
-
}
|
|
175
|
-
else if (utils_2.POOL_FUNCTIONS[i] === 'loansOperator') {
|
|
176
|
-
val = '0x4DCb388488622e47683EAd1a147947140a31e485';
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
val = curr;
|
|
180
|
-
}
|
|
181
|
-
return { ...acc, [utils_2.POOL_FUNCTIONS[i]]: val };
|
|
182
|
-
}, {});
|
|
183
|
-
const returnObj = await (0, utils_2.buildFormattedVault)(provider, tokenizedVault, formattedContractCalls);
|
|
184
|
-
returnedVault = returnObj;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
catch (err) {
|
|
188
|
-
console.error(`#getVault::${vault}:`, err);
|
|
189
|
-
throw new Error(`#getVault::${vault}:${err?.message}`);
|
|
190
|
-
}
|
|
191
|
-
if (!(0, utils_1.isBadVault)(vault)) {
|
|
192
|
-
if (loans) {
|
|
193
|
-
try {
|
|
194
|
-
returnedVault = {
|
|
195
|
-
...returnedVault,
|
|
196
|
-
loans: await getVaultLoans(returnedVault, options),
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
catch (e) {
|
|
200
|
-
console.error(`getVault::${returnedVault.symbol}:`, e?.message);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
if (allocations) {
|
|
204
|
-
try {
|
|
205
|
-
const vaultAllocations = await getVaultAllocations(vault, options);
|
|
206
|
-
returnedVault = {
|
|
207
|
-
...returnedVault,
|
|
208
|
-
allocations: vaultAllocations,
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
catch (e) {
|
|
212
|
-
console.error(`getVault::${returnedVault.symbol}:`, e?.message);
|
|
213
|
-
throw new Error('Failure fetching debank res');
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return returnedVault;
|
|
218
|
-
}
|
|
219
|
-
async function getVaultLoans(vault, options) {
|
|
220
|
-
const vaultAddress = typeof vault === 'string' ? vault : vault.address;
|
|
221
|
-
const isOldLendingPool = utils_1.OLD_LENDING_POOLS.includes(vaultAddress);
|
|
222
|
-
if (!isOldLendingPool)
|
|
223
|
-
return [];
|
|
224
|
-
try {
|
|
225
|
-
let poolTotalSupply;
|
|
226
|
-
let poolDecimals;
|
|
227
|
-
const tokenizedVault = (await (0, utils_1.fetchTokenizedVaults)(vaultAddress, options?.headers))?.[0];
|
|
228
|
-
const chainId = options?.chainId || tokenizedVault?.chain;
|
|
229
|
-
const provider = (0, utils_1.createProvider)(options.rpcUrl);
|
|
230
|
-
const tokenizedVaultLoans = await (0, utils_1.fetchTokenizedVaultLoans)(vaultAddress, chainId);
|
|
231
|
-
if (typeof vault === 'string') {
|
|
232
|
-
const poolContract = (0, utils_1.createContract)({
|
|
233
|
-
provider,
|
|
234
|
-
address: vaultAddress,
|
|
235
|
-
abi: abis_1.ABI_LENDING_POOL_V2,
|
|
236
|
-
});
|
|
237
|
-
[poolTotalSupply, poolDecimals] = await Promise.all([
|
|
238
|
-
poolContract.totalSupply(),
|
|
239
|
-
(0, utils_1.getDecimals)(provider, vaultAddress),
|
|
240
|
-
]);
|
|
241
|
-
poolTotalSupply = BigInt(poolTotalSupply).toString();
|
|
242
|
-
poolDecimals = Number(poolDecimals);
|
|
243
|
-
}
|
|
244
|
-
else {
|
|
245
|
-
poolTotalSupply = vault.totalSupply.raw;
|
|
246
|
-
poolDecimals = vault.decimals;
|
|
247
|
-
}
|
|
248
|
-
const newLoans = (await Promise.all((Array.isArray(tokenizedVaultLoans) ? tokenizedVaultLoans : [])?.map(async (l) => {
|
|
249
|
-
const borrower = l.borrower;
|
|
250
|
-
const allocation = l.principal_amount /
|
|
251
|
-
Number((0, ethers_1.formatUnits)(poolTotalSupply, poolDecimals));
|
|
252
|
-
const loanFeeRate = await (0, utils_1.getLoanOracleFeeRate)(provider, 'LOAN.REPAY.INTERESTS', l.address, chainId);
|
|
253
|
-
const loanApr = Number(l.apr || 0) / 100;
|
|
254
|
-
const loanAprAfterFees = loanApr * (1 - loanFeeRate / 100);
|
|
255
|
-
const isIdleCapital = utils_1.IDLE_CAPITAL_BORROWER_ADDRESS.includes(borrower);
|
|
256
|
-
const newLoanObj = {
|
|
257
|
-
vault: vaultAddress,
|
|
258
|
-
address: l.address,
|
|
259
|
-
lender: l.lender,
|
|
260
|
-
borrower: l.borrower,
|
|
261
|
-
state: l.state,
|
|
262
|
-
totalRepaid: l.total_repaid,
|
|
263
|
-
principalToken: l.principal_token,
|
|
264
|
-
principalAmount: l.principal_amount,
|
|
265
|
-
interestAmount: l.interest_amount,
|
|
266
|
-
upcomingPayment: {
|
|
267
|
-
amount: l.upcoming_payment.amount,
|
|
268
|
-
dueDate: l.upcoming_payment.due_date,
|
|
269
|
-
},
|
|
270
|
-
apr: loanAprAfterFees,
|
|
271
|
-
initialPrincipalAmount: l.initial_principal_amount,
|
|
272
|
-
deployedDate: l.deployed_date,
|
|
273
|
-
isIdleCapital,
|
|
274
|
-
paymentInterval: l.payment_interval,
|
|
275
|
-
allocation,
|
|
276
|
-
};
|
|
277
|
-
return newLoanObj;
|
|
278
|
-
}))).filter((l) => l !== undefined);
|
|
279
|
-
return newLoans;
|
|
280
|
-
}
|
|
281
|
-
catch (e) {
|
|
282
|
-
console.error('#getVaultLoans:', e);
|
|
283
|
-
throw new Error(`#getVaultLoans::${vault}:${e?.message}`);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
async function getVaultAllocations(vault, options) {
|
|
287
|
-
let protocolExposure = [];
|
|
288
|
-
let tokenExposure = [];
|
|
289
|
-
let cefiExposure = [];
|
|
290
|
-
let cefiBorrowerResponses = {};
|
|
291
|
-
let otcPositions = {};
|
|
292
|
-
let defiPerBorrower = {};
|
|
293
|
-
let exposurePerCategory = {
|
|
294
|
-
supplying: [],
|
|
295
|
-
borrowing: [],
|
|
296
|
-
wallet: [],
|
|
297
|
-
walletBalance: 0,
|
|
298
|
-
cefiBalance: 0,
|
|
299
|
-
defiBalance: 0,
|
|
300
|
-
lending: [],
|
|
301
|
-
loanBalance: 0,
|
|
302
|
-
};
|
|
303
|
-
let netValue = { value: 0 };
|
|
304
|
-
let debankErr = false;
|
|
305
|
-
let unfilteredTokens = [];
|
|
306
|
-
let uniqueBorrowers;
|
|
307
|
-
const isOldLendingPool = utils_1.OLD_LENDING_POOLS.includes(vault);
|
|
308
|
-
const tokenizedVault = (await (0, utils_1.fetchTokenizedVaults)(vault, options?.headers))?.[0];
|
|
309
|
-
try {
|
|
310
|
-
if (isOldLendingPool) {
|
|
311
|
-
const loans = await getVaultLoans(vault, options);
|
|
312
|
-
uniqueBorrowers = [...new Set(loans.map((l) => l.borrower))];
|
|
313
|
-
}
|
|
314
|
-
else {
|
|
315
|
-
uniqueBorrowers = tokenizedVault.subaccounts.map((s) => s.address);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
catch (e) {
|
|
319
|
-
console.error('#getVaultAllocations::borrowers:', e);
|
|
320
|
-
}
|
|
321
|
-
if (vault.toLowerCase() === utils_2.VAULT_AgoraAUSD.toLowerCase()) {
|
|
322
|
-
const debankRes = await (0, utils_1.fetchDebankResponse)(utils_2.SUBACCOUNT_CALEB);
|
|
323
|
-
console.log('debankRes:', debankRes);
|
|
324
|
-
if (debankRes === false) {
|
|
325
|
-
debankErr = true;
|
|
326
|
-
}
|
|
327
|
-
(0, utils_1.parseVaultLevelDebank)(debankRes, protocolExposure, tokenExposure, utils_2.SUBACCOUNT_CALEB, exposurePerCategory, netValue);
|
|
328
|
-
unfilteredTokens = debankRes?.subaccount?.tokens;
|
|
329
|
-
const debankPerLoan = (0, utils_1.parseLoanLevelDebank)(debankRes);
|
|
330
|
-
defiPerBorrower[utils_2.SUBACCOUNT_CALEB] = debankPerLoan;
|
|
331
|
-
}
|
|
332
|
-
else {
|
|
333
|
-
for (const borrower of uniqueBorrowers) {
|
|
334
|
-
try {
|
|
335
|
-
const debankRes = await (0, utils_1.fetchDebankResponse)(borrower);
|
|
336
|
-
if (debankRes === false) {
|
|
337
|
-
debankErr = true;
|
|
338
|
-
}
|
|
339
|
-
(0, utils_1.parseVaultLevelDebank)(debankRes, protocolExposure, tokenExposure, borrower, exposurePerCategory, netValue);
|
|
340
|
-
unfilteredTokens = debankRes?.subaccount?.tokens;
|
|
341
|
-
const debankPerLoan = (0, utils_1.parseLoanLevelDebank)(debankRes);
|
|
342
|
-
defiPerBorrower[borrower] = debankPerLoan;
|
|
343
|
-
}
|
|
344
|
-
catch (e) {
|
|
345
|
-
console.error('#getVaultAllocations::debank:', e);
|
|
346
|
-
}
|
|
347
|
-
try {
|
|
348
|
-
const cefiResponse = await (0, utils_1.fetchAugustWithKey)(options.augustKey, utils_1.WEBSERVER_ENDPOINTS.subaccount.cefi(borrower), { headers: options?.headers });
|
|
349
|
-
if (cefiResponse.status !== 200) {
|
|
350
|
-
console.error('#getVaultAllocations::cefi:', cefiResponse.status, cefiResponse.statusText);
|
|
351
|
-
}
|
|
352
|
-
if (cefiResponse.status === 200) {
|
|
353
|
-
const cefiRes = (await cefiResponse.json());
|
|
354
|
-
cefiBorrowerResponses[borrower] = cefiRes;
|
|
355
|
-
cefiExposure = cefiRes;
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
catch (e) {
|
|
359
|
-
console.error('#getVaultAllocations::cefi:', e);
|
|
360
|
-
}
|
|
361
|
-
try {
|
|
362
|
-
const otcResponse = await (0, utils_1.fetchAugustWithKey)(options.augustKey, utils_1.WEBSERVER_ENDPOINTS.subaccount.otc_positions(borrower), { headers: options?.headers });
|
|
363
|
-
if (otcResponse.status !== 200) {
|
|
364
|
-
console.error('#getVaultAllocations::otc:', otcResponse.status, otcResponse.statusText);
|
|
365
|
-
}
|
|
366
|
-
if (otcResponse.status === 200) {
|
|
367
|
-
const otcRes = (await otcResponse.json());
|
|
368
|
-
otcPositions[borrower] = otcRes;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
catch (e) {
|
|
372
|
-
console.error('#getVaultAllocations::otc:', e);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
const walletBalance = exposurePerCategory.wallet.reduce((sum, item) => sum + item.amount, 0);
|
|
377
|
-
const defiBalance = protocolExposure.reduce((sum, item) => sum + item.netUsdValue, 0);
|
|
378
|
-
const cefiBalance = cefiExposure.reduce((sum, item) => sum + item.value, 0);
|
|
379
|
-
exposurePerCategory.walletBalance = walletBalance;
|
|
380
|
-
exposurePerCategory.defiBalance = defiBalance;
|
|
381
|
-
exposurePerCategory.cefiBalance = cefiBalance;
|
|
382
|
-
netValue.value += cefiBalance;
|
|
383
|
-
if (debankErr) {
|
|
384
|
-
throw Error('failure to fetch debank response');
|
|
385
|
-
}
|
|
386
|
-
if (vault === '0x828BC5895b78b2fb591018Ca5bDC2064742D6D0f') {
|
|
387
|
-
console.log('protocolExposure:', {
|
|
388
|
-
defi: protocolExposure,
|
|
389
|
-
cefi: cefiExposure,
|
|
390
|
-
otc: otcPositions,
|
|
391
|
-
tokens: tokenExposure,
|
|
392
|
-
defiPerBorrower,
|
|
393
|
-
exposurePerCategory,
|
|
394
|
-
netValue: netValue.value,
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
return {
|
|
398
|
-
defi: protocolExposure,
|
|
399
|
-
cefi: cefiExposure,
|
|
400
|
-
otc: otcPositions,
|
|
401
|
-
tokens: tokenExposure,
|
|
402
|
-
defiPerBorrower,
|
|
403
|
-
exposurePerCategory,
|
|
404
|
-
netValue: netValue.value,
|
|
405
|
-
unfilteredTokens: unfilteredTokens,
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
async function getVaultAvailableRedemptions({ vault, wallet, options, }) {
|
|
409
|
-
try {
|
|
410
|
-
const provider = (0, utils_1.createProvider)(options.rpcUrl);
|
|
411
|
-
const tokenizedVault = (await (0, utils_1.fetchTokenizedVaults)(vault, options?.headers))?.[0];
|
|
412
|
-
if (!tokenizedVault) {
|
|
413
|
-
return { availableRedemptions: [], pendingRedemptions: [] };
|
|
414
|
-
}
|
|
415
|
-
const poolContract = (0, utils_1.createContract)({
|
|
416
|
-
address: vault,
|
|
417
|
-
abi: abis_1.ABI_LENDING_POOL_V2,
|
|
418
|
-
provider,
|
|
419
|
-
});
|
|
420
|
-
const { withdrawalRequesteds, withdrawalProcesseds } = await (0, subgraph_1.getSubgraphAllWithdrawals)(vault, provider);
|
|
421
|
-
const decimals = await (0, utils_1.getDecimals)(provider, vault);
|
|
422
|
-
const availableRedemptions = [];
|
|
423
|
-
const pendingRedemptions = [];
|
|
424
|
-
for (const ev of withdrawalRequesteds) {
|
|
425
|
-
if (!ev || typeof ev !== 'object') {
|
|
426
|
-
console.warn('#getVaultAvailableRedemptions: Skipping invalid event:', ev);
|
|
427
|
-
continue;
|
|
428
|
-
}
|
|
429
|
-
if (!ev.year || !ev.month || !ev.day || !ev.receiverAddr) {
|
|
430
|
-
console.warn('#getVaultAvailableRedemptions: Skipping event with missing required properties:', ev);
|
|
431
|
-
continue;
|
|
432
|
-
}
|
|
433
|
-
const fullDate = new Date(Number(ev.year), Number(ev.month) - 1, Number(ev.day));
|
|
434
|
-
const foundRedemptionAgainstClaim = withdrawalProcesseds.find((h) => new Date(h.processedOn).toDateString() === fullDate.toDateString() &&
|
|
435
|
-
h.receiverAddr === ev.receiverAddr);
|
|
436
|
-
if (wallet) {
|
|
437
|
-
if (ev?.receiverAddr?.toLowerCase() === wallet.toLowerCase()) {
|
|
438
|
-
const alreadyRedeemed = availableRedemptions.find((red) => BigInt(red.day.raw) === BigInt(ev.day) &&
|
|
439
|
-
BigInt(red.month.raw) === BigInt(ev.month) &&
|
|
440
|
-
BigInt(red.year.raw) === BigInt(ev.year));
|
|
441
|
-
if (!(foundRedemptionAgainstClaim && alreadyRedeemed)) {
|
|
442
|
-
try {
|
|
443
|
-
const trueClaimableAmount = await poolContract?.getClaimableAmountByReceiver?.(BigInt(ev.year), BigInt(ev.month), BigInt(ev.day), (0, ethers_1.getAddress)(wallet));
|
|
444
|
-
if (trueClaimableAmount > BigInt(0)) {
|
|
445
|
-
availableRedemptions.push({
|
|
446
|
-
id: ev.transactionHash_ || ev.id,
|
|
447
|
-
hash: ev.transactionHash_ || ev.id,
|
|
448
|
-
timestamp: Number(ev.timestamp_),
|
|
449
|
-
receiver: ev.receiverAddr,
|
|
450
|
-
day: (0, utils_1.toNormalizedBn)(ev.day, 0),
|
|
451
|
-
month: (0, utils_1.toNormalizedBn)(ev.month, 0),
|
|
452
|
-
year: (0, utils_1.toNormalizedBn)(ev.year, 0),
|
|
453
|
-
amount: (0, utils_1.toNormalizedBn)(trueClaimableAmount, decimals),
|
|
454
|
-
date: fullDate,
|
|
455
|
-
vault,
|
|
456
|
-
});
|
|
457
|
-
}
|
|
458
|
-
pendingRedemptions.push({
|
|
459
|
-
id: ev.transactionHash_ || ev.id,
|
|
460
|
-
hash: ev.transactionHash_ || ev.id,
|
|
461
|
-
timestamp: Number(ev.timestamp_),
|
|
462
|
-
receiver: ev.receiverAddr,
|
|
463
|
-
day: (0, utils_1.toNormalizedBn)(ev.day, 0),
|
|
464
|
-
month: (0, utils_1.toNormalizedBn)(ev.month, 0),
|
|
465
|
-
year: (0, utils_1.toNormalizedBn)(ev.year, 0),
|
|
466
|
-
amount: (0, utils_1.toNormalizedBn)(trueClaimableAmount || BigInt(0), decimals),
|
|
467
|
-
date: fullDate,
|
|
468
|
-
vault,
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
catch (contractError) {
|
|
472
|
-
console.error('#getVaultAvailableRedemptions: Contract call failed:', contractError);
|
|
473
|
-
pendingRedemptions.push({
|
|
474
|
-
id: ev.transactionHash_ || ev.id,
|
|
475
|
-
hash: ev.transactionHash_ || ev.id,
|
|
476
|
-
timestamp: Number(ev.timestamp_),
|
|
477
|
-
receiver: ev.receiverAddr,
|
|
478
|
-
day: (0, utils_1.toNormalizedBn)(ev.day, 0),
|
|
479
|
-
month: (0, utils_1.toNormalizedBn)(ev.month, 0),
|
|
480
|
-
year: (0, utils_1.toNormalizedBn)(ev.year, 0),
|
|
481
|
-
amount: (0, utils_1.toNormalizedBn)(BigInt(0), decimals),
|
|
482
|
-
date: fullDate,
|
|
483
|
-
vault,
|
|
484
|
-
});
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
else {
|
|
490
|
-
if (!!foundRedemptionAgainstClaim) {
|
|
491
|
-
availableRedemptions.push({
|
|
492
|
-
id: ev.transactionHash_ || ev.id,
|
|
493
|
-
hash: ev.transactionHash_ || ev.id,
|
|
494
|
-
timestamp: Number(ev.timestamp_),
|
|
495
|
-
receiver: ev.receiverAddr,
|
|
496
|
-
day: (0, utils_1.toNormalizedBn)(ev.day, 0),
|
|
497
|
-
month: (0, utils_1.toNormalizedBn)(ev.month, 0),
|
|
498
|
-
year: (0, utils_1.toNormalizedBn)(ev.year, 0),
|
|
499
|
-
amount: (0, utils_1.toNormalizedBn)(ev.assets || BigInt(0), decimals),
|
|
500
|
-
date: fullDate,
|
|
501
|
-
vault,
|
|
502
|
-
});
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
return { availableRedemptions, pendingRedemptions };
|
|
507
|
-
}
|
|
508
|
-
catch (e) {
|
|
509
|
-
console.error('#getVaultAvailableRedemptions:', e);
|
|
510
|
-
return { availableRedemptions: [], pendingRedemptions: [] };
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
async function getVaultRedemptionHistory({ vault, wallet, options, }) {
|
|
514
|
-
try {
|
|
515
|
-
const provider = (0, utils_1.createProvider)(options.rpcUrl);
|
|
516
|
-
const tokenizedVault = (await (0, utils_1.fetchTokenizedVaults)(vault, options?.headers))?.[0];
|
|
517
|
-
if (!tokenizedVault) {
|
|
518
|
-
return [];
|
|
519
|
-
}
|
|
520
|
-
const chainId = tokenizedVault.chain;
|
|
521
|
-
const poolContract = (0, utils_1.createContract)({
|
|
522
|
-
address: vault,
|
|
523
|
-
abi: abis_1.ABI_LENDING_POOL_V2,
|
|
524
|
-
provider,
|
|
525
|
-
});
|
|
526
|
-
let logPromises = [];
|
|
527
|
-
const currentBlock = await provider.getBlockNumber();
|
|
528
|
-
let startingBlock = currentBlock - (0, utils_2.determineBlockSkipInternal)(chainId);
|
|
529
|
-
let endBlock = currentBlock;
|
|
530
|
-
const cutoffBlock = currentBlock - (0, utils_2.determineBlockCutoff)(chainId);
|
|
531
|
-
while (endBlock >= cutoffBlock) {
|
|
532
|
-
const logBloomsPromises = poolContract.queryFilter('WithdrawalProcessed', BigInt(startingBlock), BigInt(endBlock));
|
|
533
|
-
logPromises.push(logBloomsPromises);
|
|
534
|
-
startingBlock -= (0, utils_2.determineBlockSkipInternal)(chainId);
|
|
535
|
-
endBlock -= (0, utils_2.determineBlockSkipInternal)(chainId);
|
|
536
|
-
}
|
|
537
|
-
const logs = (await Promise.all(logPromises.flat())).flat();
|
|
538
|
-
const iface = new ethers_1.ethers.Interface([
|
|
539
|
-
'event WithdrawalProcessed (uint256 assetsAmount, uint256 processedOn, address receiverAddr, uint256 requestedOn)',
|
|
540
|
-
]);
|
|
541
|
-
const events = logs.map((log) => iface.parseLog(log));
|
|
542
|
-
const decimals = await (0, utils_1.getDecimals)(provider, vault);
|
|
543
|
-
const redemptions = [];
|
|
544
|
-
events?.forEach((ev) => {
|
|
545
|
-
if (!ev?.args)
|
|
546
|
-
return;
|
|
547
|
-
const [assetsAmount, processedOn, receiverAddr, requestedOn] = ev.args;
|
|
548
|
-
if (wallet) {
|
|
549
|
-
if (String(receiverAddr)?.toLowerCase() === wallet.toLowerCase()) {
|
|
550
|
-
redemptions.push({
|
|
551
|
-
receiver: receiverAddr,
|
|
552
|
-
amount: (0, utils_1.toNormalizedBn)(assetsAmount, decimals),
|
|
553
|
-
processed: new Date(Number(processedOn) * 1000),
|
|
554
|
-
requested: new Date(Number(requestedOn) * 1000),
|
|
555
|
-
vault,
|
|
556
|
-
});
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
else {
|
|
560
|
-
redemptions.push({
|
|
561
|
-
receiver: receiverAddr,
|
|
562
|
-
amount: (0, utils_1.toNormalizedBn)(assetsAmount, decimals),
|
|
563
|
-
processed: new Date(Number(processedOn) * 1000),
|
|
564
|
-
requested: new Date(Number(requestedOn) * 1000),
|
|
565
|
-
vault,
|
|
566
|
-
});
|
|
567
|
-
}
|
|
568
|
-
});
|
|
569
|
-
if (options.env === 'DEV')
|
|
570
|
-
console.log('#getVaultRedemptionHistory:', redemptions.slice(0, 1));
|
|
571
|
-
return redemptions;
|
|
572
|
-
}
|
|
573
|
-
catch (e) {
|
|
574
|
-
console.error('#getVaultRedemptionHistory:', e);
|
|
575
|
-
return [];
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
async function getVaultPositions({ vault, wallet, solanaWallet, options, }) {
|
|
579
|
-
try {
|
|
580
|
-
const tokenizedVaults = await (0, utils_1.fetchTokenizedVaults)(vault ? vault : undefined, options?.headers);
|
|
581
|
-
if (!tokenizedVaults || tokenizedVaults.length === 0) {
|
|
582
|
-
return [];
|
|
583
|
-
}
|
|
584
|
-
function renderStatus(_redemptions, _balance) {
|
|
585
|
-
if (_redemptions?.length)
|
|
586
|
-
return 'REDEEM';
|
|
587
|
-
if (BigInt(_balance.raw) > BigInt(0))
|
|
588
|
-
return 'STAKED';
|
|
589
|
-
return 'PENDING';
|
|
590
|
-
}
|
|
591
|
-
const promises = await Promise.all(tokenizedVaults.map(async (v) => {
|
|
592
|
-
try {
|
|
593
|
-
if (services_1.Solana.utils.isSolanaAddress(v.address)) {
|
|
594
|
-
let balance = (0, utils_1.toNormalizedBn)(0);
|
|
595
|
-
if (services_1.Solana.utils.isSolanaAddress(solanaWallet)) {
|
|
596
|
-
const vaultStateRes = await options.solanaService.getVaultState(String(v.address), services_1.Solana.constants.vaultIdl);
|
|
597
|
-
if (vaultStateRes &&
|
|
598
|
-
vaultStateRes?.vaultState?.shareMint) {
|
|
599
|
-
balance = (0, utils_1.toNormalizedBn)(await options.solanaService.fetchUserShareBalance(solanaWallet, vaultStateRes?.vaultState?.shareMint));
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
return {
|
|
603
|
-
vault,
|
|
604
|
-
status: renderStatus([], balance),
|
|
605
|
-
availableRedemptions: [],
|
|
606
|
-
pendingRedemptions: [],
|
|
607
|
-
redeemable: balance,
|
|
608
|
-
walletBalance: balance,
|
|
609
|
-
};
|
|
610
|
-
}
|
|
611
|
-
const provider = (0, utils_1.createProvider)(options.rpcUrl);
|
|
612
|
-
const decimals = await (0, utils_1.getDecimals)(provider, vault);
|
|
613
|
-
const poolContract = (0, utils_1.createContract)({
|
|
614
|
-
provider,
|
|
615
|
-
abi: abis_1.ABI_LENDING_POOL_V2,
|
|
616
|
-
address: v.address,
|
|
617
|
-
});
|
|
618
|
-
const bal = await poolContract.balanceOf(wallet);
|
|
619
|
-
const balance = (0, utils_1.toNormalizedBn)(bal || 0, decimals);
|
|
620
|
-
const { availableRedemptions, pendingRedemptions } = await getVaultAvailableRedemptions({
|
|
621
|
-
vault: v.address,
|
|
622
|
-
wallet,
|
|
623
|
-
options,
|
|
624
|
-
});
|
|
625
|
-
const aggregateAvailableRedemptions = availableRedemptions?.reduce((acc, curr) => acc + BigInt(curr.amount.raw), BigInt(0));
|
|
626
|
-
return {
|
|
627
|
-
vault,
|
|
628
|
-
status: renderStatus(availableRedemptions, balance),
|
|
629
|
-
availableRedemptions,
|
|
630
|
-
pendingRedemptions,
|
|
631
|
-
redeemable: (0, utils_1.toNormalizedBn)(aggregateAvailableRedemptions, decimals),
|
|
632
|
-
walletBalance: balance,
|
|
633
|
-
};
|
|
634
|
-
}
|
|
635
|
-
catch (vaultError) {
|
|
636
|
-
console.error(`#getVaultPositions: Error processing vault ${v.address}:`, vaultError);
|
|
637
|
-
return {
|
|
638
|
-
vault,
|
|
639
|
-
status: 'PENDING',
|
|
640
|
-
availableRedemptions: [],
|
|
641
|
-
pendingRedemptions: [],
|
|
642
|
-
redeemable: (0, utils_1.toNormalizedBn)(0),
|
|
643
|
-
walletBalance: (0, utils_1.toNormalizedBn)(0),
|
|
644
|
-
};
|
|
645
|
-
}
|
|
646
|
-
}));
|
|
647
|
-
return promises.flat();
|
|
648
|
-
}
|
|
649
|
-
catch (e) {
|
|
650
|
-
console.error('#getVaultPositions:', e);
|
|
651
|
-
throw new Error(`#getVaultPositions::${vault}:${e?.message}`);
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
async function getVaultApy({ vault, options, }) {
|
|
655
|
-
try {
|
|
656
|
-
const tokenizedVault = (await (0, utils_1.fetchTokenizedVaults)(vault, options?.headers))?.[0];
|
|
657
|
-
return tokenizedVault?.reported_apy?.apy || 0;
|
|
658
|
-
}
|
|
659
|
-
catch (e) {
|
|
660
|
-
console.error('#getVaultApy:', e);
|
|
661
|
-
throw new Error(`#getVaultApy::${vault}:${e?.message}`);
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
async function getRewardsStakingPositions({ rpcUrl, wallet, coinGeckoKey, }) {
|
|
665
|
-
const REWARDS_CHAIN = 43114;
|
|
666
|
-
const REWARDS_SYMBOL = 'AVAX';
|
|
667
|
-
const REWARDS_DECIMALS = 18;
|
|
668
|
-
const REWARDS_NAME = 'Avalanche';
|
|
669
|
-
const APR_MULTIPLIER = 31536000;
|
|
670
|
-
const UP_AUSD_SYMBOL = 'upAUSD';
|
|
671
|
-
try {
|
|
672
|
-
const provider = (0, utils_1.createProvider)(rpcUrl);
|
|
673
|
-
const chainId = await (0, utils_1.getChainId)(provider);
|
|
674
|
-
if (chainId !== REWARDS_CHAIN) {
|
|
675
|
-
console.warn('#getStakingPositions: no rewards distributor on chain_id', chainId);
|
|
676
|
-
return [];
|
|
677
|
-
}
|
|
678
|
-
if (wallet && !(0, ethers_1.isAddress)(wallet)) {
|
|
679
|
-
console.warn('#getStakingPositions: wallet passed is not a valid address', wallet);
|
|
680
|
-
return [];
|
|
681
|
-
}
|
|
682
|
-
const rewardDistributorAddresses = (0, utils_1.REWARD_DISTRIBUTOR_ADDRESS)(chainId);
|
|
683
|
-
const positions = await Promise.all(rewardDistributorAddresses.map(async (contract, i) => {
|
|
684
|
-
const rewardContract = (0, utils_1.createContract)({
|
|
685
|
-
address: contract,
|
|
686
|
-
provider: provider,
|
|
687
|
-
abi: abis_1.ABI_REWARD_DISTRIBUTOR,
|
|
688
|
-
});
|
|
689
|
-
const totalStaked = await rewardContract.totalStaked();
|
|
690
|
-
const rewardsPerSecond = await rewardContract.rewardsPerSecond();
|
|
691
|
-
const stakingTokenCalls = ['decimals', 'symbol', 'name', 'totalSupply'];
|
|
692
|
-
const stakingTokenAddress = (await rewardContract.stakingToken());
|
|
693
|
-
const stakingTokenContract = (0, utils_1.createContract)({
|
|
694
|
-
address: stakingTokenAddress,
|
|
695
|
-
provider: provider,
|
|
696
|
-
abi: abis_1.ABI_ERC20,
|
|
697
|
-
});
|
|
698
|
-
const [decimals, symbol, name, totalSupply] = await Promise.all(stakingTokenCalls.map((staking) => stakingTokenContract[staking]()));
|
|
699
|
-
let balance;
|
|
700
|
-
let earned;
|
|
701
|
-
if (wallet) {
|
|
702
|
-
const formattedWallet = (0, ethers_1.getAddress)(wallet);
|
|
703
|
-
balance = await rewardContract.balanceOf(formattedWallet);
|
|
704
|
-
earned = await rewardContract.earned(formattedWallet);
|
|
705
|
-
}
|
|
706
|
-
const rewardTokenPriceInUsd = await (0, utils_1.fetchTokenPrice)(REWARDS_SYMBOL, null, coinGeckoKey);
|
|
707
|
-
const normalizedRewardTokenPrice = (0, utils_1.toNormalizedBn)(rewardTokenPriceInUsd);
|
|
708
|
-
const normalizedTotalStakedInPool = (0, utils_1.toNormalizedBn)(totalStaked, decimals);
|
|
709
|
-
const normalizedRedeemable = (0, utils_1.toNormalizedBn)(earned, REWARDS_DECIMALS);
|
|
710
|
-
const normalizedRewardsPerSecond = (0, utils_1.toNormalizedBn)(rewardsPerSecond, REWARDS_DECIMALS);
|
|
711
|
-
const normalizedTotalStakedBalance = (0, utils_1.toNormalizedBn)(balance, decimals);
|
|
712
|
-
const rewardTokenPriceToMultiply = symbol === UP_AUSD_SYMBOL
|
|
713
|
-
? Number(normalizedRewardTokenPrice?.normalized)
|
|
714
|
-
: 1;
|
|
715
|
-
const STAKED_APR = ((Number(normalizedRewardsPerSecond?.normalized) *
|
|
716
|
-
APR_MULTIPLIER *
|
|
717
|
-
rewardTokenPriceToMultiply) /
|
|
718
|
-
(Number(normalizedTotalStakedInPool?.normalized) * Number(1))) *
|
|
719
|
-
100;
|
|
720
|
-
const MAX_APR = ((Number(normalizedRewardsPerSecond?.normalized) *
|
|
721
|
-
APR_MULTIPLIER *
|
|
722
|
-
rewardTokenPriceToMultiply) /
|
|
723
|
-
(Number(normalizedTotalStakedInPool?.normalized) * Number(1))) *
|
|
724
|
-
100;
|
|
725
|
-
const activePosition = {
|
|
726
|
-
id: String(i),
|
|
727
|
-
rewardToken: {
|
|
728
|
-
decimals: REWARDS_DECIMALS,
|
|
729
|
-
symbol: REWARDS_SYMBOL,
|
|
730
|
-
address: ethers_1.ZeroAddress,
|
|
731
|
-
chain: REWARDS_CHAIN,
|
|
732
|
-
redeemable: normalizedRedeemable,
|
|
733
|
-
usd: normalizedRewardTokenPrice,
|
|
734
|
-
name: REWARDS_NAME,
|
|
735
|
-
},
|
|
736
|
-
stakingToken: {
|
|
737
|
-
decimals: Number(decimals),
|
|
738
|
-
symbol: symbol,
|
|
739
|
-
address: stakingTokenAddress,
|
|
740
|
-
chain: REWARDS_CHAIN,
|
|
741
|
-
totalStaked: normalizedTotalStakedBalance,
|
|
742
|
-
usd: normalizedRewardTokenPrice,
|
|
743
|
-
totalSupply: normalizedTotalStakedInPool,
|
|
744
|
-
name: name,
|
|
745
|
-
},
|
|
746
|
-
rewardDistributor: contract,
|
|
747
|
-
rewardPerSecond: (0, utils_1.toNormalizedBn)(rewardsPerSecond),
|
|
748
|
-
apy: STAKED_APR,
|
|
749
|
-
maxApy: MAX_APR,
|
|
750
|
-
chainId: REWARDS_CHAIN,
|
|
751
|
-
};
|
|
752
|
-
return activePosition;
|
|
753
|
-
}));
|
|
754
|
-
return positions;
|
|
755
|
-
}
|
|
756
|
-
catch (e) {
|
|
757
|
-
console.error('#getStakingPositions:', e);
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
//# sourceMappingURL=getters.js.map
|