@augustdigital/sdk 8.3.2 → 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 +6 -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 +69 -0
- package/lib/modules/vaults/utils.js +104 -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 +137 -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);
|
|
@@ -191,6 +228,10 @@ function mapStrategists(tokenizedVault) {
|
|
|
191
228
|
website_url: s.website_url ?? null,
|
|
192
229
|
}));
|
|
193
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* Map composability integrations from backend format to vault format.
|
|
233
|
+
* Shared across all chain adapters.
|
|
234
|
+
*/
|
|
194
235
|
function mapComposabilityIntegrations(tokenizedVault) {
|
|
195
236
|
return (tokenizedVault.composability_integrations?.map((integration) => ({
|
|
196
237
|
name: integration.name,
|
|
@@ -202,6 +243,11 @@ function mapComposabilityIntegrations(tokenizedVault) {
|
|
|
202
243
|
id: integration.id,
|
|
203
244
|
})) || []);
|
|
204
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
|
+
*/
|
|
205
251
|
function backendTvlToNormalizedBn(tvl, decimals) {
|
|
206
252
|
if (tvl == null) {
|
|
207
253
|
core_1.Logger.log.warn('backendTvlToNormalizedBn', 'TVL is null/undefined, defaulting to 0 — check backend data pipeline', { decimals });
|
|
@@ -217,6 +263,10 @@ function backendTvlToNormalizedBn(tvl, decimals) {
|
|
|
217
263
|
const tvlWhole = BigInt(Math.round(tvl));
|
|
218
264
|
return (0, core_1.toNormalizedBn)(tvlWhole * scaleFactor, decimals);
|
|
219
265
|
}
|
|
266
|
+
/**
|
|
267
|
+
* Map daily PnL per share from backend Record format to array format.
|
|
268
|
+
* Shared across non-EVM adapters.
|
|
269
|
+
*/
|
|
220
270
|
function mapDailyPnlPerShare(dailyPnl) {
|
|
221
271
|
if (!dailyPnl)
|
|
222
272
|
return [];
|
|
@@ -225,6 +275,11 @@ function mapDailyPnlPerShare(dailyPnl) {
|
|
|
225
275
|
value,
|
|
226
276
|
}));
|
|
227
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
|
+
*/
|
|
228
283
|
function buildBackendVault(tokenizedVault, overrides) {
|
|
229
284
|
const apy = formatVaultApy(tokenizedVault);
|
|
230
285
|
const rewards = tokenizedVault.rewards?.length
|
|
@@ -256,6 +311,7 @@ function buildBackendVault(tokenizedVault, overrides) {
|
|
|
256
311
|
isVisible: tokenizedVault.is_visible || false,
|
|
257
312
|
reserveTarget: tokenizedVault.reserve_target || 0,
|
|
258
313
|
reserveTolerance: tokenizedVault.reserve_tolerance || 0,
|
|
314
|
+
// Vault decimals are derived from the receipt token decimals for non-EVM vaults
|
|
259
315
|
decimals: overrides.receipt.decimals,
|
|
260
316
|
maxSupply: (0, core_1.toNormalizedBn)(1000000000),
|
|
261
317
|
depositCap: null,
|
|
@@ -331,13 +387,22 @@ function buildBackendVault(tokenizedVault, overrides) {
|
|
|
331
387
|
: {}),
|
|
332
388
|
showCapFilled: tokenizedVault?.show_cap_filled ?? null,
|
|
333
389
|
apyOverride: tokenizedVault.apy_override ?? null,
|
|
390
|
+
// Spread chain-specific overrides last so they take precedence
|
|
334
391
|
...overrides,
|
|
335
392
|
};
|
|
336
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
|
+
*/
|
|
337
401
|
async function buildFormattedVault(provider, tokenizedVault, contractCalls) {
|
|
338
402
|
const strategists = mapStrategists(tokenizedVault);
|
|
339
403
|
const operators = tokenizedVault?.operators || [];
|
|
340
404
|
const eoa_operators = tokenizedVault?.eoa_operators || [];
|
|
405
|
+
// Load offchain props
|
|
341
406
|
const baseProps = {
|
|
342
407
|
chainId: tokenizedVault.chain,
|
|
343
408
|
maxDailyDrawdown: tokenizedVault.max_daily_drawdown || 0,
|
|
@@ -392,6 +457,7 @@ async function buildFormattedVault(provider, tokenizedVault, contractCalls) {
|
|
|
392
457
|
isWithdrawalPaused: contractCalls.withdrawalsPaused,
|
|
393
458
|
idleAssets: (0, core_1.toNormalizedBn)(await getIdleAssets(provider, tokenizedVault.address, contractCalls.asset, contractCalls.totalAssets), Number(contractCalls.decimals)),
|
|
394
459
|
};
|
|
460
|
+
// Version specific logic
|
|
395
461
|
const version = (0, vaults_1.getVaultVersionV2)(tokenizedVault);
|
|
396
462
|
let operator = '0x';
|
|
397
463
|
let depositAssets = [];
|
|
@@ -407,6 +473,7 @@ async function buildFormattedVault(provider, tokenizedVault, contractCalls) {
|
|
|
407
473
|
};
|
|
408
474
|
switch (version) {
|
|
409
475
|
case 'sol-0': {
|
|
476
|
+
// @todo
|
|
410
477
|
break;
|
|
411
478
|
}
|
|
412
479
|
case 'evm-2': {
|
|
@@ -431,15 +498,18 @@ async function buildFormattedVault(provider, tokenizedVault, contractCalls) {
|
|
|
431
498
|
depositAssets = [...depositAssets, ...extraAssets];
|
|
432
499
|
totalSupply = contractCalls.totalSupply;
|
|
433
500
|
(maxSupply =
|
|
434
|
-
(0, core_1.toNormalizedBn)(1000000000000)),
|
|
501
|
+
(0, core_1.toNormalizedBn)(1000000000000)), // @hardcoded: no maxSupply on here
|
|
435
502
|
(receipt = {
|
|
436
503
|
symbol: tokenizedVault.receipt_token_symbol,
|
|
437
504
|
address: contractCalls.lpTokenAddress,
|
|
438
505
|
decimals: contractCalls.decimals,
|
|
439
506
|
});
|
|
507
|
+
// @todo: get operator
|
|
508
|
+
// operator = contractCalls.loansOperator as IAddress;
|
|
440
509
|
break;
|
|
441
510
|
}
|
|
442
511
|
default: {
|
|
512
|
+
// get idle assets
|
|
443
513
|
depositAssets = [
|
|
444
514
|
{
|
|
445
515
|
address: contractCalls.asset,
|
|
@@ -462,10 +532,13 @@ async function buildFormattedVault(provider, tokenizedVault, contractCalls) {
|
|
|
462
532
|
break;
|
|
463
533
|
}
|
|
464
534
|
}
|
|
535
|
+
// Check for adapter configuration and add adapter deposit tokens
|
|
465
536
|
const adapterConfig = (0, core_1.getVaultAdapterConfig)(tokenizedVault.address);
|
|
466
537
|
if (adapterConfig) {
|
|
467
538
|
const allDepositTokens = (0, core_1.getVaultDepositTokens)(tokenizedVault.address, contractCalls.asset);
|
|
539
|
+
// Build deposit assets array including adapter tokens
|
|
468
540
|
const depositAssetsWithAdapters = await Promise.all(allDepositTokens.map(async (tokenAddress) => {
|
|
541
|
+
// Skip if already in depositAssets
|
|
469
542
|
if (depositAssets.find((a) => a.address.toLowerCase() === tokenAddress.toLowerCase())) {
|
|
470
543
|
return null;
|
|
471
544
|
}
|
|
@@ -477,6 +550,7 @@ async function buildFormattedVault(provider, tokenizedVault, contractCalls) {
|
|
|
477
550
|
decimals,
|
|
478
551
|
};
|
|
479
552
|
}));
|
|
553
|
+
// Add adapter tokens to depositAssets
|
|
480
554
|
depositAssets = [
|
|
481
555
|
...depositAssets,
|
|
482
556
|
...depositAssetsWithAdapters.filter((a) => a !== null),
|
|
@@ -527,6 +601,17 @@ async function buildFormattedVault(provider, tokenizedVault, contractCalls) {
|
|
|
527
601
|
return result;
|
|
528
602
|
}
|
|
529
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
|
+
*/
|
|
530
615
|
async function generatePermitSignature(token, owner, spender, value, deadline, signer, chainId) {
|
|
531
616
|
const tokenContract = (0, core_1.createContract)({
|
|
532
617
|
address: token,
|
|
@@ -564,10 +649,14 @@ async function generatePermitSignature(token, owner, spender, value, deadline, s
|
|
|
564
649
|
}
|
|
565
650
|
if (!matchingDomain) {
|
|
566
651
|
const name = (await tokenContract.name());
|
|
652
|
+
// Try different domain configurations to find which matches
|
|
567
653
|
const domainConfigs = [
|
|
654
|
+
// Standard EIP-2612
|
|
568
655
|
{ name, version: '1', chainId, verifyingContract: token },
|
|
569
656
|
{ name, version: '2', chainId, verifyingContract: token },
|
|
657
|
+
// Without version
|
|
570
658
|
{ name, chainId, verifyingContract: token },
|
|
659
|
+
// With different salt values (some contracts use this)
|
|
571
660
|
{
|
|
572
661
|
name,
|
|
573
662
|
version: '1',
|
|
@@ -584,6 +673,8 @@ async function generatePermitSignature(token, owner, spender, value, deadline, s
|
|
|
584
673
|
}
|
|
585
674
|
}
|
|
586
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
|
|
587
678
|
try {
|
|
588
679
|
const version = await tokenContract.version();
|
|
589
680
|
matchingDomain = { name, version, chainId, verifyingContract: token };
|
|
@@ -600,6 +691,7 @@ async function generatePermitSignature(token, owner, spender, value, deadline, s
|
|
|
600
691
|
ttl: 60 * 60 * 1000,
|
|
601
692
|
});
|
|
602
693
|
}
|
|
694
|
+
// EIP-2612 Permit type
|
|
603
695
|
const types = {
|
|
604
696
|
Permit: [
|
|
605
697
|
{ name: 'owner', type: 'address' },
|
|
@@ -616,7 +708,9 @@ async function generatePermitSignature(token, owner, spender, value, deadline, s
|
|
|
616
708
|
nonce: Number(nonce),
|
|
617
709
|
deadline: deadline,
|
|
618
710
|
};
|
|
711
|
+
// Sign the typed data
|
|
619
712
|
const signature = await signer.signTypedData(matchingDomain, types, message);
|
|
713
|
+
// Split signature into r, s, v
|
|
620
714
|
const sig = ethers_1.ethers.Signature.from(signature);
|
|
621
715
|
return {
|
|
622
716
|
r: sig.r,
|
|
@@ -625,6 +719,11 @@ async function generatePermitSignature(token, owner, spender, value, deadline, s
|
|
|
625
719
|
deadline: deadline,
|
|
626
720
|
};
|
|
627
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
|
+
*/
|
|
628
727
|
function createDeadline(offsetSeconds = 1200) {
|
|
629
728
|
return Math.floor(Date.now() / 1000) + offsetSeconds;
|
|
630
729
|
}
|