@augustdigital/sdk 8.3.1 → 8.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/abis/ERC20_Bytes32.d.ts +4 -0
- package/lib/abis/ERC20_Bytes32.js +4 -0
- package/lib/abis/ERC4626.d.ts +1 -0
- package/lib/abis/ERC4626.js +1 -0
- package/lib/abis/ERC721.d.ts +1 -0
- package/lib/abis/ERC721.js +1 -0
- package/lib/abis/FeeOracle.js +1 -0
- package/lib/abis/LendingPool.js +1 -0
- package/lib/abis/LendingPoolV2.js +1 -0
- package/lib/abis/Multicall3.js +3 -0
- package/lib/abis/OFT.d.ts +20 -0
- package/lib/abis/OFT.js +20 -0
- package/lib/abis/SmartAccount.d.ts +1 -0
- package/lib/abis/SmartAccount.js +3 -0
- package/lib/abis/SwapRouter.d.ts +1 -0
- package/lib/abis/SwapRouter.js +1 -0
- package/lib/abis/UniversalSignatureValidator.js +3 -0
- package/lib/abis/index.d.ts +5 -0
- package/lib/abis/index.js +5 -0
- package/lib/adapters/evm/getters.d.ts +17 -2
- package/lib/adapters/evm/getters.js +35 -3
- package/lib/adapters/evm/index.d.ts +262 -0
- package/lib/adapters/evm/index.js +268 -1
- package/lib/adapters/evm/utils.d.ts +6 -0
- package/lib/adapters/evm/utils.js +7 -0
- package/lib/adapters/solana/constants.js +4 -1
- package/lib/adapters/solana/getters.d.ts +8 -0
- package/lib/adapters/solana/getters.js +21 -0
- package/lib/adapters/solana/idl/vault-idl.js +9 -0
- package/lib/adapters/solana/index.d.ts +55 -0
- package/lib/adapters/solana/index.js +57 -0
- package/lib/adapters/solana/utils.d.ts +28 -0
- package/lib/adapters/solana/utils.js +79 -4
- package/lib/adapters/solana/vault.actions.d.ts +19 -0
- package/lib/adapters/solana/vault.actions.js +47 -3
- package/lib/adapters/stellar/actions.d.ts +25 -0
- package/lib/adapters/stellar/actions.js +33 -0
- package/lib/adapters/stellar/constants.d.ts +26 -0
- package/lib/adapters/stellar/constants.js +29 -0
- package/lib/adapters/stellar/getters.d.ts +56 -0
- package/lib/adapters/stellar/getters.js +81 -0
- package/lib/adapters/stellar/index.d.ts +48 -0
- package/lib/adapters/stellar/index.js +48 -0
- package/lib/adapters/stellar/soroban.d.ts +20 -0
- package/lib/adapters/stellar/soroban.js +46 -0
- package/lib/adapters/stellar/submit.d.ts +12 -0
- package/lib/adapters/stellar/submit.js +19 -0
- package/lib/adapters/stellar/types.d.ts +27 -0
- package/lib/adapters/stellar/types.js +3 -0
- package/lib/adapters/stellar/utils.d.ts +10 -0
- package/lib/adapters/stellar/utils.js +10 -0
- package/lib/adapters/sui/getters.d.ts +6 -0
- package/lib/adapters/sui/getters.js +6 -0
- package/lib/adapters/sui/index.d.ts +15 -0
- package/lib/adapters/sui/index.js +15 -0
- package/lib/adapters/sui/transformer.d.ts +6 -0
- package/lib/adapters/sui/transformer.js +7 -0
- package/lib/adapters/sui/utils.d.ts +6 -0
- package/lib/adapters/sui/utils.js +6 -0
- package/lib/core/analytics/chain-name.d.ts +8 -0
- package/lib/core/analytics/chain-name.js +8 -0
- package/lib/core/analytics/constants.d.ts +4 -0
- package/lib/core/analytics/constants.js +4 -0
- package/lib/core/analytics/env.d.ts +25 -0
- package/lib/core/analytics/env.js +26 -0
- package/lib/core/analytics/index.d.ts +26 -0
- package/lib/core/analytics/index.js +35 -0
- package/lib/core/analytics/instrumentation.d.ts +26 -0
- package/lib/core/analytics/instrumentation.js +66 -2
- package/lib/core/analytics/method-taxonomy.d.ts +16 -0
- package/lib/core/analytics/method-taxonomy.js +18 -0
- package/lib/core/analytics/metrics.d.ts +23 -0
- package/lib/core/analytics/metrics.js +40 -0
- package/lib/core/analytics/sanitize.d.ts +38 -0
- package/lib/core/analytics/sanitize.js +46 -0
- package/lib/core/analytics/sentry-runtime.d.ts +11 -0
- package/lib/core/analytics/sentry-runtime.js +19 -0
- package/lib/core/analytics/sentry.d.ts +45 -0
- package/lib/core/analytics/sentry.js +115 -2
- package/lib/core/analytics/types.d.ts +27 -0
- package/lib/core/analytics/user-identity.d.ts +34 -0
- package/lib/core/analytics/user-identity.js +42 -0
- package/lib/core/analytics/version.d.ts +6 -1
- package/lib/core/analytics/version.js +6 -1
- package/lib/core/auth/verify.js +5 -0
- package/lib/core/base.class.d.ts +75 -0
- package/lib/core/base.class.js +56 -0
- package/lib/core/cache.d.ts +5 -0
- package/lib/core/cache.js +6 -0
- package/lib/core/constants/adapters.d.ts +15 -0
- package/lib/core/constants/adapters.js +28 -8
- package/lib/core/constants/core.d.ts +12 -1
- package/lib/core/constants/core.js +12 -0
- package/lib/core/constants/swap-router.d.ts +46 -0
- package/lib/core/constants/swap-router.js +50 -0
- package/lib/core/constants/vaults.d.ts +56 -0
- package/lib/core/constants/vaults.js +66 -1
- package/lib/core/constants/web3.d.ts +3 -0
- package/lib/core/constants/web3.js +18 -5
- package/lib/core/errors/index.d.ts +36 -0
- package/lib/core/errors/index.js +29 -0
- package/lib/core/fetcher.d.ts +134 -0
- package/lib/core/fetcher.js +191 -5
- package/lib/core/helpers/adapters.d.ts +9 -0
- package/lib/core/helpers/adapters.js +11 -0
- package/lib/core/helpers/chain-address.d.ts +10 -0
- package/lib/core/helpers/chain-address.js +11 -0
- package/lib/core/helpers/core.d.ts +42 -0
- package/lib/core/helpers/core.js +66 -1
- package/lib/core/helpers/explorer-link.d.ts +14 -0
- package/lib/core/helpers/explorer-link.js +14 -0
- package/lib/core/helpers/signer.d.ts +26 -0
- package/lib/core/helpers/signer.js +39 -0
- package/lib/core/helpers/swap-router.d.ts +32 -0
- package/lib/core/helpers/swap-router.js +32 -0
- package/lib/core/helpers/vault-version.d.ts +1 -0
- package/lib/core/helpers/vault-version.js +2 -0
- package/lib/core/helpers/vaults.d.ts +8 -0
- package/lib/core/helpers/vaults.js +22 -8
- package/lib/core/helpers/web3.d.ts +152 -0
- package/lib/core/helpers/web3.js +183 -6
- package/lib/core/logger/index.d.ts +55 -0
- package/lib/core/logger/index.js +19 -0
- package/lib/core/logger/slack.d.ts +3 -0
- package/lib/core/logger/slack.js +3 -0
- package/lib/core/vault-metadata.d.ts +6 -0
- package/lib/core/vault-metadata.js +6 -0
- package/lib/core/version-check.d.ts +52 -0
- package/lib/core/version-check.js +81 -0
- package/lib/evm/methods/crossChainVault.d.ts +90 -0
- package/lib/evm/methods/crossChainVault.js +186 -1
- package/lib/evm/methods/crossChainVaultRegistry.d.ts +93 -0
- package/lib/evm/methods/crossChainVaultRegistry.js +240 -0
- package/lib/evm/methods/index.d.ts +1 -0
- package/lib/evm/methods/index.js +1 -0
- package/lib/evm/types/crossChain.d.ts +202 -0
- package/lib/evm/types/crossChain.js +11 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +19 -0
- package/lib/main.d.ts +288 -5
- package/lib/main.js +305 -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 +52 -0
- package/lib/modules/api/main.js +130 -0
- package/lib/modules/sub-accounts/fetcher.d.ts +15 -0
- package/lib/modules/sub-accounts/fetcher.js +15 -0
- package/lib/modules/sub-accounts/main.d.ts +33 -0
- package/lib/modules/sub-accounts/main.js +38 -0
- package/lib/modules/sub-accounts/utils.d.ts +3 -0
- package/lib/modules/sub-accounts/utils.js +3 -0
- package/lib/modules/vaults/adapter.helpers.d.ts +18 -0
- package/lib/modules/vaults/adapter.helpers.js +34 -0
- package/lib/modules/vaults/fetcher.d.ts +20 -0
- package/lib/modules/vaults/fetcher.js +40 -3
- package/lib/modules/vaults/getters.d.ts +295 -0
- package/lib/modules/vaults/getters.js +552 -12
- package/lib/modules/vaults/index.d.ts +12 -0
- package/lib/modules/vaults/index.js +12 -0
- package/lib/modules/vaults/main.d.ts +292 -4
- package/lib/modules/vaults/main.js +379 -7
- package/lib/modules/vaults/read.actions.d.ts +168 -0
- package/lib/modules/vaults/read.actions.js +143 -0
- package/lib/modules/vaults/types.d.ts +34 -0
- package/lib/modules/vaults/utils/call-data-decoder.d.ts +47 -0
- package/lib/modules/vaults/utils/call-data-decoder.js +56 -0
- package/lib/modules/vaults/utils/date-utils.d.ts +39 -0
- package/lib/modules/vaults/utils/date-utils.js +47 -1
- package/lib/modules/vaults/utils.d.ts +70 -0
- package/lib/modules/vaults/utils.js +108 -5
- package/lib/modules/vaults/write.actions.d.ts +363 -3
- package/lib/modules/vaults/write.actions.js +364 -2
- package/lib/polyfills.js +2 -0
- package/lib/sdk.d.ts +23705 -0
- package/lib/services/coingecko/fetcher.d.ts +13 -0
- package/lib/services/coingecko/fetcher.js +17 -0
- package/lib/services/debank/fetcher.d.ts +14 -0
- package/lib/services/debank/fetcher.js +12 -0
- package/lib/services/debank/utils.js +17 -0
- package/lib/services/layerzero/deposits.d.ts +11 -0
- package/lib/services/layerzero/deposits.js +34 -11
- package/lib/services/layerzero/redeems.d.ts +10 -0
- package/lib/services/layerzero/redeems.js +13 -0
- package/lib/services/layerzero/utils.d.ts +8 -0
- package/lib/services/layerzero/utils.js +11 -0
- package/lib/services/octavfi/fetcher.d.ts +7 -0
- package/lib/services/octavfi/fetcher.js +25 -0
- package/lib/services/octavfi/utils.d.ts +12 -0
- package/lib/services/octavfi/utils.js +44 -10
- package/lib/services/subgraph/fetcher.js +4 -2
- package/lib/services/subgraph/vaults.d.ts +12 -0
- package/lib/services/subgraph/vaults.js +43 -2
- package/lib/services/swap-quotes/index.d.ts +71 -0
- package/lib/services/swap-quotes/index.js +25 -0
- package/lib/services/swap-quotes/paraswap.d.ts +17 -0
- package/lib/services/swap-quotes/paraswap.js +14 -0
- package/lib/types/pools.d.ts +3 -0
- package/lib/types/typed-contract.d.ts +64 -0
- package/lib/types/vaults.d.ts +139 -2
- package/lib/types/vaults.js +10 -0
- package/lib/types/web3.d.ts +8 -0
- package/lib/types/web3.js +1 -0
- package/lib/types/webserver.d.ts +45 -0
- package/package.json +6 -5
|
@@ -17,6 +17,10 @@ const abis_1 = require("../../abis");
|
|
|
17
17
|
const core_1 = require("../../core");
|
|
18
18
|
const vaults_1 = require("../../core/helpers/vaults");
|
|
19
19
|
const ethers_1 = require("ethers");
|
|
20
|
+
/**
|
|
21
|
+
* @param walletClient a wagmi-derived client (from useWalletClient)
|
|
22
|
+
* @returns An ethers JsonRpcSigner object used in sdk.evm.setSigner
|
|
23
|
+
*/
|
|
20
24
|
async function walletClientToSigner(walletClient) {
|
|
21
25
|
const { account, chain, transport } = walletClient;
|
|
22
26
|
const network = {
|
|
@@ -24,14 +28,23 @@ async function walletClientToSigner(walletClient) {
|
|
|
24
28
|
name: chain.name,
|
|
25
29
|
ensAddress: chain.contracts?.ensRegistry?.address,
|
|
26
30
|
};
|
|
31
|
+
//@ts-expect-error
|
|
27
32
|
const provider = new ethers_1.BrowserProvider(transport, network);
|
|
28
33
|
const signer = await provider.getSigner(account.address);
|
|
29
34
|
return signer;
|
|
30
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Calculates the reward multiplier based on the vault and optional timestamp.
|
|
38
|
+
* Returns the applicable multiplier for a given vault at a specific timestamp,
|
|
39
|
+
* or the latest multiplier if no timestamp is provided.
|
|
40
|
+
* @param foundPool The vault to get the multiplier for
|
|
41
|
+
* @param timestamp Optional timestamp to get historical multiplier
|
|
42
|
+
* @returns The reward multiplier value
|
|
43
|
+
*/
|
|
31
44
|
const getRewardMultiplierByTimestamp = (foundPool, timestamp) => {
|
|
32
45
|
const multipliers = foundPool.rewards?.multipliers;
|
|
33
46
|
if (!multipliers?.length) {
|
|
34
|
-
return 1;
|
|
47
|
+
return 1; // default multiplier if multipliers are not found
|
|
35
48
|
}
|
|
36
49
|
const multipliersByTimestamp = multipliers.reduce((acc, curr) => {
|
|
37
50
|
return {
|
|
@@ -40,8 +53,9 @@ const getRewardMultiplierByTimestamp = (foundPool, timestamp) => {
|
|
|
40
53
|
};
|
|
41
54
|
}, {});
|
|
42
55
|
if (!multipliersByTimestamp) {
|
|
43
|
-
return 1;
|
|
56
|
+
return 1; // default multiplier if pool is not found
|
|
44
57
|
}
|
|
58
|
+
// return the latest if timestamp not provided
|
|
45
59
|
if (!timestamp) {
|
|
46
60
|
const latest = Object.keys(multipliersByTimestamp)
|
|
47
61
|
.map(Number)
|
|
@@ -50,13 +64,18 @@ const getRewardMultiplierByTimestamp = (foundPool, timestamp) => {
|
|
|
50
64
|
}
|
|
51
65
|
const applicableTimestamp = Object.keys(multipliersByTimestamp)
|
|
52
66
|
.map(Number)
|
|
53
|
-
.filter((ts) => ts <= timestamp)
|
|
54
|
-
.sort((a, b) => b - a)[0];
|
|
67
|
+
.filter((ts) => ts <= timestamp) // filter only timestamps before or equal to the given timestamp
|
|
68
|
+
.sort((a, b) => b - a)[0]; // get the latest applicable timestamp
|
|
55
69
|
return applicableTimestamp !== undefined
|
|
56
70
|
? (multipliersByTimestamp[applicableTimestamp] ?? 1)
|
|
57
71
|
: 1;
|
|
58
72
|
};
|
|
59
73
|
exports.getRewardMultiplierByTimestamp = getRewardMultiplierByTimestamp;
|
|
74
|
+
/**
|
|
75
|
+
* Get the rewards for the vault
|
|
76
|
+
* @param tokenizedVault - The tokenized vault
|
|
77
|
+
* @returns The rewards
|
|
78
|
+
*/
|
|
60
79
|
function getVaultRewards(tokenizedVault) {
|
|
61
80
|
const upshiftPointRewards = tokenizedVault.rewards?.filter((r) => r.text === 'Upshift Points');
|
|
62
81
|
const sortedPointsMultipliers = upshiftPointRewards?.sort((a, b) => new Date(b.start_datetime).getTime() -
|
|
@@ -76,12 +95,20 @@ function getVaultRewards(tokenizedVault) {
|
|
|
76
95
|
};
|
|
77
96
|
return rewards;
|
|
78
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Get the idle assets for the vault
|
|
100
|
+
* @param provider - The provider
|
|
101
|
+
* @param vaultAddress - The vault address
|
|
102
|
+
* @param totalAssets - The total assets of the vault
|
|
103
|
+
* @returns The idle assets
|
|
104
|
+
*/
|
|
79
105
|
async function getIdleAssets(provider, vaultAddress, underlying, totalAssets) {
|
|
80
106
|
const tokenizedVault = (await (0, core_1.fetchTokenizedVault)(vaultAddress))?.[0];
|
|
81
107
|
const version = (0, vaults_1.getVaultVersionV2)(tokenizedVault);
|
|
82
108
|
let idleAssets;
|
|
83
109
|
switch (version) {
|
|
84
110
|
case 'evm-0': {
|
|
111
|
+
// old lending pool
|
|
85
112
|
const globalLoansAmount = await (0, core_1.createContract)({
|
|
86
113
|
provider,
|
|
87
114
|
address: vaultAddress,
|
|
@@ -105,6 +132,7 @@ async function getIdleAssets(provider, vaultAddress, underlying, totalAssets) {
|
|
|
105
132
|
break;
|
|
106
133
|
}
|
|
107
134
|
default: {
|
|
135
|
+
// tokenized vault
|
|
108
136
|
idleAssets = await (0, core_1.createContract)({
|
|
109
137
|
provider,
|
|
110
138
|
address: underlying,
|
|
@@ -146,6 +174,7 @@ async function getYieldLastRealizedOn(provider, vaultAddress) {
|
|
|
146
174
|
return 0;
|
|
147
175
|
}
|
|
148
176
|
default: {
|
|
177
|
+
// Default to V3 ABI which has assetsUpdatedOn
|
|
149
178
|
const contract = (0, core_1.createContract)({
|
|
150
179
|
provider,
|
|
151
180
|
address: vaultAddress,
|
|
@@ -157,6 +186,10 @@ async function getYieldLastRealizedOn(provider, vaultAddress) {
|
|
|
157
186
|
}
|
|
158
187
|
return Number(assetsUpdatedOn);
|
|
159
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* Format APY data from backend tokenized vault into the unified IVaultApy shape.
|
|
191
|
+
* Shared across all chain adapters (EVM, Solana, Stellar).
|
|
192
|
+
*/
|
|
160
193
|
function formatVaultApy(tokenizedVault) {
|
|
161
194
|
const { reported_apy, campaign_apy } = tokenizedVault;
|
|
162
195
|
return {
|
|
@@ -170,6 +203,10 @@ function formatVaultApy(tokenizedVault) {
|
|
|
170
203
|
underlyingApy: (reported_apy?.underlying_apy ?? 0) * 100,
|
|
171
204
|
};
|
|
172
205
|
}
|
|
206
|
+
/**
|
|
207
|
+
* Map strategists from backend subaccounts or hardcoded list.
|
|
208
|
+
* Shared across all chain adapters.
|
|
209
|
+
*/
|
|
173
210
|
function mapStrategists(tokenizedVault) {
|
|
174
211
|
const hasValidStrategists = tokenizedVault.subaccounts?.length > 0 &&
|
|
175
212
|
tokenizedVault.subaccounts.some((s) => s.strategist !== null);
|
|
@@ -181,14 +218,20 @@ function mapStrategists(tokenizedVault) {
|
|
|
181
218
|
logo: s.strategist?.strategist_logo,
|
|
182
219
|
name: s.strategist?.strategist_name,
|
|
183
220
|
type: 'subaccount',
|
|
221
|
+
website_url: s.strategist?.website_url ?? null,
|
|
184
222
|
}))
|
|
185
223
|
: (tokenizedVault.hardcoded_strategists || []).map((s) => ({
|
|
186
224
|
address: '0x',
|
|
187
225
|
logo: s.strategist_logo,
|
|
188
226
|
name: s.strategist_name,
|
|
189
227
|
type: 'subaccount',
|
|
228
|
+
website_url: s.website_url ?? null,
|
|
190
229
|
}));
|
|
191
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* Map composability integrations from backend format to vault format.
|
|
233
|
+
* Shared across all chain adapters.
|
|
234
|
+
*/
|
|
192
235
|
function mapComposabilityIntegrations(tokenizedVault) {
|
|
193
236
|
return (tokenizedVault.composability_integrations?.map((integration) => ({
|
|
194
237
|
name: integration.name,
|
|
@@ -200,6 +243,11 @@ function mapComposabilityIntegrations(tokenizedVault) {
|
|
|
200
243
|
id: integration.id,
|
|
201
244
|
})) || []);
|
|
202
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* Convert a backend-reported TVL (whole token units) to a NormalizedBn.
|
|
248
|
+
* Handles null, undefined, and non-finite values (NaN, Infinity) safely, defaulting to 0.
|
|
249
|
+
* Shared between non-EVM adapters (Solana, Stellar) and the module-level getVaultTvl handler.
|
|
250
|
+
*/
|
|
203
251
|
function backendTvlToNormalizedBn(tvl, decimals) {
|
|
204
252
|
if (tvl == null) {
|
|
205
253
|
core_1.Logger.log.warn('backendTvlToNormalizedBn', 'TVL is null/undefined, defaulting to 0 — check backend data pipeline', { decimals });
|
|
@@ -215,6 +263,10 @@ function backendTvlToNormalizedBn(tvl, decimals) {
|
|
|
215
263
|
const tvlWhole = BigInt(Math.round(tvl));
|
|
216
264
|
return (0, core_1.toNormalizedBn)(tvlWhole * scaleFactor, decimals);
|
|
217
265
|
}
|
|
266
|
+
/**
|
|
267
|
+
* Map daily PnL per share from backend Record format to array format.
|
|
268
|
+
* Shared across non-EVM adapters.
|
|
269
|
+
*/
|
|
218
270
|
function mapDailyPnlPerShare(dailyPnl) {
|
|
219
271
|
if (!dailyPnl)
|
|
220
272
|
return [];
|
|
@@ -223,6 +275,11 @@ function mapDailyPnlPerShare(dailyPnl) {
|
|
|
223
275
|
value,
|
|
224
276
|
}));
|
|
225
277
|
}
|
|
278
|
+
/**
|
|
279
|
+
* Build a base IVault from backend data, shared across non-EVM adapters (Solana, Stellar).
|
|
280
|
+
* Chain-specific fields (chainId, version, name, totalAssets, totalSupply, depositAssets, receipt)
|
|
281
|
+
* must be provided via the overrides parameter.
|
|
282
|
+
*/
|
|
226
283
|
function buildBackendVault(tokenizedVault, overrides) {
|
|
227
284
|
const apy = formatVaultApy(tokenizedVault);
|
|
228
285
|
const rewards = tokenizedVault.rewards?.length
|
|
@@ -254,6 +311,7 @@ function buildBackendVault(tokenizedVault, overrides) {
|
|
|
254
311
|
isVisible: tokenizedVault.is_visible || false,
|
|
255
312
|
reserveTarget: tokenizedVault.reserve_target || 0,
|
|
256
313
|
reserveTolerance: tokenizedVault.reserve_tolerance || 0,
|
|
314
|
+
// Vault decimals are derived from the receipt token decimals for non-EVM vaults
|
|
257
315
|
decimals: overrides.receipt.decimals,
|
|
258
316
|
maxSupply: (0, core_1.toNormalizedBn)(1000000000),
|
|
259
317
|
depositCap: null,
|
|
@@ -328,13 +386,23 @@ function buildBackendVault(tokenizedVault, overrides) {
|
|
|
328
386
|
}
|
|
329
387
|
: {}),
|
|
330
388
|
showCapFilled: tokenizedVault?.show_cap_filled ?? null,
|
|
389
|
+
apyOverride: tokenizedVault.apy_override ?? null,
|
|
390
|
+
// Spread chain-specific overrides last so they take precedence
|
|
331
391
|
...overrides,
|
|
332
392
|
};
|
|
333
393
|
}
|
|
394
|
+
/**
|
|
395
|
+
* Build the formatted vault
|
|
396
|
+
* @param provider - The provider
|
|
397
|
+
* @param tokenizedVault - The tokenized vault
|
|
398
|
+
* @param contractCalls - The contract calls
|
|
399
|
+
* @returns The formatted vault
|
|
400
|
+
*/
|
|
334
401
|
async function buildFormattedVault(provider, tokenizedVault, contractCalls) {
|
|
335
402
|
const strategists = mapStrategists(tokenizedVault);
|
|
336
403
|
const operators = tokenizedVault?.operators || [];
|
|
337
404
|
const eoa_operators = tokenizedVault?.eoa_operators || [];
|
|
405
|
+
// Load offchain props
|
|
338
406
|
const baseProps = {
|
|
339
407
|
chainId: tokenizedVault.chain,
|
|
340
408
|
maxDailyDrawdown: tokenizedVault.max_daily_drawdown || 0,
|
|
@@ -389,6 +457,7 @@ async function buildFormattedVault(provider, tokenizedVault, contractCalls) {
|
|
|
389
457
|
isWithdrawalPaused: contractCalls.withdrawalsPaused,
|
|
390
458
|
idleAssets: (0, core_1.toNormalizedBn)(await getIdleAssets(provider, tokenizedVault.address, contractCalls.asset, contractCalls.totalAssets), Number(contractCalls.decimals)),
|
|
391
459
|
};
|
|
460
|
+
// Version specific logic
|
|
392
461
|
const version = (0, vaults_1.getVaultVersionV2)(tokenizedVault);
|
|
393
462
|
let operator = '0x';
|
|
394
463
|
let depositAssets = [];
|
|
@@ -404,6 +473,7 @@ async function buildFormattedVault(provider, tokenizedVault, contractCalls) {
|
|
|
404
473
|
};
|
|
405
474
|
switch (version) {
|
|
406
475
|
case 'sol-0': {
|
|
476
|
+
// @todo
|
|
407
477
|
break;
|
|
408
478
|
}
|
|
409
479
|
case 'evm-2': {
|
|
@@ -428,15 +498,18 @@ async function buildFormattedVault(provider, tokenizedVault, contractCalls) {
|
|
|
428
498
|
depositAssets = [...depositAssets, ...extraAssets];
|
|
429
499
|
totalSupply = contractCalls.totalSupply;
|
|
430
500
|
(maxSupply =
|
|
431
|
-
(0, core_1.toNormalizedBn)(1000000000000)),
|
|
501
|
+
(0, core_1.toNormalizedBn)(1000000000000)), // @hardcoded: no maxSupply on here
|
|
432
502
|
(receipt = {
|
|
433
503
|
symbol: tokenizedVault.receipt_token_symbol,
|
|
434
504
|
address: contractCalls.lpTokenAddress,
|
|
435
505
|
decimals: contractCalls.decimals,
|
|
436
506
|
});
|
|
507
|
+
// @todo: get operator
|
|
508
|
+
// operator = contractCalls.loansOperator as IAddress;
|
|
437
509
|
break;
|
|
438
510
|
}
|
|
439
511
|
default: {
|
|
512
|
+
// get idle assets
|
|
440
513
|
depositAssets = [
|
|
441
514
|
{
|
|
442
515
|
address: contractCalls.asset,
|
|
@@ -459,10 +532,13 @@ async function buildFormattedVault(provider, tokenizedVault, contractCalls) {
|
|
|
459
532
|
break;
|
|
460
533
|
}
|
|
461
534
|
}
|
|
535
|
+
// Check for adapter configuration and add adapter deposit tokens
|
|
462
536
|
const adapterConfig = (0, core_1.getVaultAdapterConfig)(tokenizedVault.address);
|
|
463
537
|
if (adapterConfig) {
|
|
464
538
|
const allDepositTokens = (0, core_1.getVaultDepositTokens)(tokenizedVault.address, contractCalls.asset);
|
|
539
|
+
// Build deposit assets array including adapter tokens
|
|
465
540
|
const depositAssetsWithAdapters = await Promise.all(allDepositTokens.map(async (tokenAddress) => {
|
|
541
|
+
// Skip if already in depositAssets
|
|
466
542
|
if (depositAssets.find((a) => a.address.toLowerCase() === tokenAddress.toLowerCase())) {
|
|
467
543
|
return null;
|
|
468
544
|
}
|
|
@@ -474,6 +550,7 @@ async function buildFormattedVault(provider, tokenizedVault, contractCalls) {
|
|
|
474
550
|
decimals,
|
|
475
551
|
};
|
|
476
552
|
}));
|
|
553
|
+
// Add adapter tokens to depositAssets
|
|
477
554
|
depositAssets = [
|
|
478
555
|
...depositAssets,
|
|
479
556
|
...depositAssetsWithAdapters.filter((a) => a !== null),
|
|
@@ -504,6 +581,7 @@ async function buildFormattedVault(provider, tokenizedVault, contractCalls) {
|
|
|
504
581
|
latest_reported_tvl: tokenizedVault?.latest_reported_tvl,
|
|
505
582
|
cachedAt: tokenizedVault?.cached_at ?? null,
|
|
506
583
|
showCapFilled: tokenizedVault?.show_cap_filled ?? null,
|
|
584
|
+
apyOverride: tokenizedVault?.apy_override ?? null,
|
|
507
585
|
};
|
|
508
586
|
if (tokenizedVault.instant_redeem_config) {
|
|
509
587
|
const config = tokenizedVault.instant_redeem_config;
|
|
@@ -523,6 +601,17 @@ async function buildFormattedVault(provider, tokenizedVault, contractCalls) {
|
|
|
523
601
|
return result;
|
|
524
602
|
}
|
|
525
603
|
exports.ERC_20_PERMIT_HASH = '0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9';
|
|
604
|
+
/**
|
|
605
|
+
* Generate an ERC2612 permit signature
|
|
606
|
+
* @param token - The ERC20 token contract address
|
|
607
|
+
* @param owner - The token owner's address (signer)
|
|
608
|
+
* @param spender - The address that will be approved to spend (your pool contract)
|
|
609
|
+
* @param value - The amount to approve
|
|
610
|
+
* @param deadline - Unix timestamp for when the permit expires
|
|
611
|
+
* @param signer - The ethers.js Signer (wallet)
|
|
612
|
+
* @param provider - The ethers.js Provider
|
|
613
|
+
* @returns The signature components (v, r, s) and deadline
|
|
614
|
+
*/
|
|
526
615
|
async function generatePermitSignature(token, owner, spender, value, deadline, signer, chainId) {
|
|
527
616
|
const tokenContract = (0, core_1.createContract)({
|
|
528
617
|
address: token,
|
|
@@ -560,10 +649,14 @@ async function generatePermitSignature(token, owner, spender, value, deadline, s
|
|
|
560
649
|
}
|
|
561
650
|
if (!matchingDomain) {
|
|
562
651
|
const name = (await tokenContract.name());
|
|
652
|
+
// Try different domain configurations to find which matches
|
|
563
653
|
const domainConfigs = [
|
|
654
|
+
// Standard EIP-2612
|
|
564
655
|
{ name, version: '1', chainId, verifyingContract: token },
|
|
565
656
|
{ name, version: '2', chainId, verifyingContract: token },
|
|
657
|
+
// Without version
|
|
566
658
|
{ name, chainId, verifyingContract: token },
|
|
659
|
+
// With different salt values (some contracts use this)
|
|
567
660
|
{
|
|
568
661
|
name,
|
|
569
662
|
version: '1',
|
|
@@ -580,6 +673,8 @@ async function generatePermitSignature(token, owner, spender, value, deadline, s
|
|
|
580
673
|
}
|
|
581
674
|
}
|
|
582
675
|
if (!matchingDomain) {
|
|
676
|
+
// If no match, try to get the version from the contract
|
|
677
|
+
// Some token contracts have a version() method for EIP-2612 domain
|
|
583
678
|
try {
|
|
584
679
|
const version = await tokenContract.version();
|
|
585
680
|
matchingDomain = { name, version, chainId, verifyingContract: token };
|
|
@@ -596,6 +691,7 @@ async function generatePermitSignature(token, owner, spender, value, deadline, s
|
|
|
596
691
|
ttl: 60 * 60 * 1000,
|
|
597
692
|
});
|
|
598
693
|
}
|
|
694
|
+
// EIP-2612 Permit type
|
|
599
695
|
const types = {
|
|
600
696
|
Permit: [
|
|
601
697
|
{ name: 'owner', type: 'address' },
|
|
@@ -612,7 +708,9 @@ async function generatePermitSignature(token, owner, spender, value, deadline, s
|
|
|
612
708
|
nonce: Number(nonce),
|
|
613
709
|
deadline: deadline,
|
|
614
710
|
};
|
|
711
|
+
// Sign the typed data
|
|
615
712
|
const signature = await signer.signTypedData(matchingDomain, types, message);
|
|
713
|
+
// Split signature into r, s, v
|
|
616
714
|
const sig = ethers_1.ethers.Signature.from(signature);
|
|
617
715
|
return {
|
|
618
716
|
r: sig.r,
|
|
@@ -621,6 +719,11 @@ async function generatePermitSignature(token, owner, spender, value, deadline, s
|
|
|
621
719
|
deadline: deadline,
|
|
622
720
|
};
|
|
623
721
|
}
|
|
722
|
+
/**
|
|
723
|
+
* Helper to create a deadline (current time + offset in seconds)
|
|
724
|
+
* @param offsetSeconds - Number of seconds from now (default: 20 minutes)
|
|
725
|
+
* @returns Unix timestamp
|
|
726
|
+
*/
|
|
624
727
|
function createDeadline(offsetSeconds = 1200) {
|
|
625
728
|
return Math.floor(Date.now() / 1000) + offsetSeconds;
|
|
626
729
|
}
|