@lagoon-protocol/lagoon-mcp 0.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/LICENSE +201 -0
- package/README.md +618 -0
- package/dist/cache/index.d.ts +97 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +106 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/config.d.ts +34 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +40 -0
- package/dist/config.js.map +1 -0
- package/dist/core/cache-adapter.d.ts +73 -0
- package/dist/core/cache-adapter.d.ts.map +1 -0
- package/dist/core/cache-adapter.js +47 -0
- package/dist/core/cache-adapter.js.map +1 -0
- package/dist/core/cache-invalidation.d.ts +72 -0
- package/dist/core/cache-invalidation.d.ts.map +1 -0
- package/dist/core/cache-invalidation.js +114 -0
- package/dist/core/cache-invalidation.js.map +1 -0
- package/dist/core/container.d.ts +34 -0
- package/dist/core/container.d.ts.map +1 -0
- package/dist/core/container.js +75 -0
- package/dist/core/container.js.map +1 -0
- package/dist/graphql/client.d.ts +32 -0
- package/dist/graphql/client.d.ts.map +1 -0
- package/dist/graphql/client.js +49 -0
- package/dist/graphql/client.js.map +1 -0
- package/dist/graphql/fragments/apr-breakdown.fragment.d.ts +64 -0
- package/dist/graphql/fragments/apr-breakdown.fragment.d.ts.map +1 -0
- package/dist/graphql/fragments/apr-breakdown.fragment.js +62 -0
- package/dist/graphql/fragments/apr-breakdown.fragment.js.map +1 -0
- package/dist/graphql/fragments/asset-info.fragment.d.ts +18 -0
- package/dist/graphql/fragments/asset-info.fragment.d.ts.map +1 -0
- package/dist/graphql/fragments/asset-info.fragment.js +36 -0
- package/dist/graphql/fragments/asset-info.fragment.js.map +1 -0
- package/dist/graphql/fragments/chain-info.fragment.d.ts +18 -0
- package/dist/graphql/fragments/chain-info.fragment.d.ts.map +1 -0
- package/dist/graphql/fragments/chain-info.fragment.js +32 -0
- package/dist/graphql/fragments/chain-info.fragment.js.map +1 -0
- package/dist/graphql/fragments/index.d.ts +15 -0
- package/dist/graphql/fragments/index.d.ts.map +1 -0
- package/dist/graphql/fragments/index.js +21 -0
- package/dist/graphql/fragments/index.js.map +1 -0
- package/dist/graphql/fragments/pageinfo.fragment.d.ts +33 -0
- package/dist/graphql/fragments/pageinfo.fragment.d.ts.map +1 -0
- package/dist/graphql/fragments/pageinfo.fragment.js +47 -0
- package/dist/graphql/fragments/pageinfo.fragment.js.map +1 -0
- package/dist/graphql/fragments/transaction-base.fragment.d.ts +19 -0
- package/dist/graphql/fragments/transaction-base.fragment.d.ts.map +1 -0
- package/dist/graphql/fragments/transaction-base.fragment.js +32 -0
- package/dist/graphql/fragments/transaction-base.fragment.js.map +1 -0
- package/dist/graphql/fragments/vault-list.fragment.d.ts +53 -0
- package/dist/graphql/fragments/vault-list.fragment.d.ts.map +1 -0
- package/dist/graphql/fragments/vault-list.fragment.js +51 -0
- package/dist/graphql/fragments/vault-list.fragment.js.map +1 -0
- package/dist/graphql/fragments/vault-summary.fragment.d.ts +68 -0
- package/dist/graphql/fragments/vault-summary.fragment.d.ts.map +1 -0
- package/dist/graphql/fragments/vault-summary.fragment.js +66 -0
- package/dist/graphql/fragments/vault-summary.fragment.js.map +1 -0
- package/dist/graphql/fragments/vault.fragment.d.ts +133 -0
- package/dist/graphql/fragments/vault.fragment.d.ts.map +1 -0
- package/dist/graphql/fragments/vault.fragment.js +119 -0
- package/dist/graphql/fragments/vault.fragment.js.map +1 -0
- package/dist/graphql/fragments.d.ts +183 -0
- package/dist/graphql/fragments.d.ts.map +1 -0
- package/dist/graphql/fragments.js +297 -0
- package/dist/graphql/fragments.js.map +1 -0
- package/dist/graphql/queries/export.queries.d.ts +72 -0
- package/dist/graphql/queries/export.queries.d.ts.map +1 -0
- package/dist/graphql/queries/export.queries.js +202 -0
- package/dist/graphql/queries/export.queries.js.map +1 -0
- package/dist/graphql/queries/index.d.ts +15 -0
- package/dist/graphql/queries/index.d.ts.map +1 -0
- package/dist/graphql/queries/index.js +23 -0
- package/dist/graphql/queries/index.js.map +1 -0
- package/dist/graphql/queries/performance.queries.d.ts +63 -0
- package/dist/graphql/queries/performance.queries.d.ts.map +1 -0
- package/dist/graphql/queries/performance.queries.js +133 -0
- package/dist/graphql/queries/performance.queries.js.map +1 -0
- package/dist/graphql/queries/period-summaries.d.ts +15 -0
- package/dist/graphql/queries/period-summaries.d.ts.map +1 -0
- package/dist/graphql/queries/period-summaries.js +24 -0
- package/dist/graphql/queries/period-summaries.js.map +1 -0
- package/dist/graphql/queries/portfolio.queries.d.ts +78 -0
- package/dist/graphql/queries/portfolio.queries.d.ts.map +1 -0
- package/dist/graphql/queries/portfolio.queries.js +198 -0
- package/dist/graphql/queries/portfolio.queries.js.map +1 -0
- package/dist/graphql/queries/prediction.queries.d.ts +38 -0
- package/dist/graphql/queries/prediction.queries.d.ts.map +1 -0
- package/dist/graphql/queries/prediction.queries.js +100 -0
- package/dist/graphql/queries/prediction.queries.js.map +1 -0
- package/dist/graphql/queries/risk.queries.d.ts +37 -0
- package/dist/graphql/queries/risk.queries.d.ts.map +1 -0
- package/dist/graphql/queries/risk.queries.js +90 -0
- package/dist/graphql/queries/risk.queries.js.map +1 -0
- package/dist/graphql/queries/search.queries.d.ts +61 -0
- package/dist/graphql/queries/search.queries.d.ts.map +1 -0
- package/dist/graphql/queries/search.queries.js +103 -0
- package/dist/graphql/queries/search.queries.js.map +1 -0
- package/dist/graphql/queries/transaction.queries.d.ts +60 -0
- package/dist/graphql/queries/transaction.queries.d.ts.map +1 -0
- package/dist/graphql/queries/transaction.queries.js +252 -0
- package/dist/graphql/queries/transaction.queries.js.map +1 -0
- package/dist/graphql/queries/vault.queries.d.ts +54 -0
- package/dist/graphql/queries/vault.queries.d.ts.map +1 -0
- package/dist/graphql/queries/vault.queries.js +78 -0
- package/dist/graphql/queries/vault.queries.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/prompts/competitor-comparison.d.ts +8 -0
- package/dist/prompts/competitor-comparison.d.ts.map +1 -0
- package/dist/prompts/competitor-comparison.js +432 -0
- package/dist/prompts/competitor-comparison.js.map +1 -0
- package/dist/prompts/curator-performance.d.ts +8 -0
- package/dist/prompts/curator-performance.d.ts.map +1 -0
- package/dist/prompts/curator-performance.js +383 -0
- package/dist/prompts/curator-performance.js.map +1 -0
- package/dist/prompts/financial-analysis.d.ts +8 -0
- package/dist/prompts/financial-analysis.d.ts.map +1 -0
- package/dist/prompts/financial-analysis.js +480 -0
- package/dist/prompts/financial-analysis.js.map +1 -0
- package/dist/prompts/index.d.ts +21 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +50 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/prompts/onboarding-first-vault.d.ts +8 -0
- package/dist/prompts/onboarding-first-vault.d.ts.map +1 -0
- package/dist/prompts/onboarding-first-vault.js +317 -0
- package/dist/prompts/onboarding-first-vault.js.map +1 -0
- package/dist/prompts/portfolio-optimization.d.ts +8 -0
- package/dist/prompts/portfolio-optimization.d.ts.map +1 -0
- package/dist/prompts/portfolio-optimization.js +412 -0
- package/dist/prompts/portfolio-optimization.js.map +1 -0
- package/dist/prompts/protocol-overview.d.ts +8 -0
- package/dist/prompts/protocol-overview.d.ts.map +1 -0
- package/dist/prompts/protocol-overview.js +398 -0
- package/dist/prompts/protocol-overview.js.map +1 -0
- package/dist/prompts/shared/disclaimers.d.ts +54 -0
- package/dist/prompts/shared/disclaimers.d.ts.map +1 -0
- package/dist/prompts/shared/disclaimers.js +400 -0
- package/dist/prompts/shared/disclaimers.js.map +1 -0
- package/dist/resources/glossary.d.ts +8 -0
- package/dist/resources/glossary.d.ts.map +1 -0
- package/dist/resources/glossary.js +407 -0
- package/dist/resources/glossary.js.map +1 -0
- package/dist/resources/index.d.ts +18 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +29 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/resources/schema.d.ts +22 -0
- package/dist/resources/schema.d.ts.map +1 -0
- package/dist/resources/schema.js +67 -0
- package/dist/resources/schema.js.map +1 -0
- package/dist/schemas/config.schema.d.ts +46 -0
- package/dist/schemas/config.schema.d.ts.map +1 -0
- package/dist/schemas/config.schema.js +48 -0
- package/dist/schemas/config.schema.js.map +1 -0
- package/dist/sdk/__tests__/apr-service.test.d.ts +7 -0
- package/dist/sdk/__tests__/apr-service.test.d.ts.map +1 -0
- package/dist/sdk/__tests__/apr-service.test.js +385 -0
- package/dist/sdk/__tests__/apr-service.test.js.map +1 -0
- package/dist/sdk/__tests__/math-utils.test.d.ts +7 -0
- package/dist/sdk/__tests__/math-utils.test.d.ts.map +1 -0
- package/dist/sdk/__tests__/math-utils.test.js +185 -0
- package/dist/sdk/__tests__/math-utils.test.js.map +1 -0
- package/dist/sdk/__tests__/simulation-service.test.d.ts +5 -0
- package/dist/sdk/__tests__/simulation-service.test.d.ts.map +1 -0
- package/dist/sdk/__tests__/simulation-service.test.js +397 -0
- package/dist/sdk/__tests__/simulation-service.test.js.map +1 -0
- package/dist/sdk/__tests__/vault-utils.test.d.ts +7 -0
- package/dist/sdk/__tests__/vault-utils.test.d.ts.map +1 -0
- package/dist/sdk/__tests__/vault-utils.test.js +189 -0
- package/dist/sdk/__tests__/vault-utils.test.js.map +1 -0
- package/dist/sdk/apr-service.d.ts +101 -0
- package/dist/sdk/apr-service.d.ts.map +1 -0
- package/dist/sdk/apr-service.js +175 -0
- package/dist/sdk/apr-service.js.map +1 -0
- package/dist/sdk/math-utils.d.ts +138 -0
- package/dist/sdk/math-utils.d.ts.map +1 -0
- package/dist/sdk/math-utils.js +218 -0
- package/dist/sdk/math-utils.js.map +1 -0
- package/dist/sdk/simulation-service.d.ts +106 -0
- package/dist/sdk/simulation-service.d.ts.map +1 -0
- package/dist/sdk/simulation-service.js +143 -0
- package/dist/sdk/simulation-service.js.map +1 -0
- package/dist/sdk/vault-utils.d.ts +125 -0
- package/dist/sdk/vault-utils.d.ts.map +1 -0
- package/dist/sdk/vault-utils.js +165 -0
- package/dist/sdk/vault-utils.js.map +1 -0
- package/dist/server.d.ts +21 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +225 -0
- package/dist/server.js.map +1 -0
- package/dist/services/analytics/protocol-overview.service.d.ts +61 -0
- package/dist/services/analytics/protocol-overview.service.d.ts.map +1 -0
- package/dist/services/analytics/protocol-overview.service.js +182 -0
- package/dist/services/analytics/protocol-overview.service.js.map +1 -0
- package/dist/services/analytics/risk.service.d.ts +92 -0
- package/dist/services/analytics/risk.service.d.ts.map +1 -0
- package/dist/services/analytics/risk.service.js +423 -0
- package/dist/services/analytics/risk.service.js.map +1 -0
- package/dist/services/base.service.d.ts +39 -0
- package/dist/services/base.service.d.ts.map +1 -0
- package/dist/services/base.service.js +37 -0
- package/dist/services/base.service.js.map +1 -0
- package/dist/services/index.d.ts +30 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +101 -0
- package/dist/services/index.js.map +1 -0
- package/dist/tools/__tests__/simulate-vault.test.d.ts +5 -0
- package/dist/tools/__tests__/simulate-vault.test.d.ts.map +1 -0
- package/dist/tools/__tests__/simulate-vault.test.js +363 -0
- package/dist/tools/__tests__/simulate-vault.test.js.map +1 -0
- package/dist/tools/analyze-risk.d.ts +34 -0
- package/dist/tools/analyze-risk.d.ts.map +1 -0
- package/dist/tools/analyze-risk.js +100 -0
- package/dist/tools/analyze-risk.js.map +1 -0
- package/dist/tools/compare-vaults.d.ts +29 -0
- package/dist/tools/compare-vaults.d.ts.map +1 -0
- package/dist/tools/compare-vaults.js +285 -0
- package/dist/tools/compare-vaults.js.map +1 -0
- package/dist/tools/export-data.d.ts +34 -0
- package/dist/tools/export-data.d.ts.map +1 -0
- package/dist/tools/export-data.js +309 -0
- package/dist/tools/export-data.js.map +1 -0
- package/dist/tools/get-price-history.d.ts +29 -0
- package/dist/tools/get-price-history.d.ts.map +1 -0
- package/dist/tools/get-price-history.js +236 -0
- package/dist/tools/get-price-history.js.map +1 -0
- package/dist/tools/get-transactions.d.ts +29 -0
- package/dist/tools/get-transactions.d.ts.map +1 -0
- package/dist/tools/get-transactions.js +181 -0
- package/dist/tools/get-transactions.js.map +1 -0
- package/dist/tools/index.d.ts +26 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +32 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/optimize-portfolio.d.ts +37 -0
- package/dist/tools/optimize-portfolio.d.ts.map +1 -0
- package/dist/tools/optimize-portfolio.js +459 -0
- package/dist/tools/optimize-portfolio.js.map +1 -0
- package/dist/tools/predict-yield.d.ts +30 -0
- package/dist/tools/predict-yield.d.ts.map +1 -0
- package/dist/tools/predict-yield.js +248 -0
- package/dist/tools/predict-yield.js.map +1 -0
- package/dist/tools/query-graphql.d.ts +35 -0
- package/dist/tools/query-graphql.d.ts.map +1 -0
- package/dist/tools/query-graphql.js +54 -0
- package/dist/tools/query-graphql.js.map +1 -0
- package/dist/tools/registry.d.ts +42 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +231 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/search-vaults.d.ts +40 -0
- package/dist/tools/search-vaults.d.ts.map +1 -0
- package/dist/tools/search-vaults.js +184 -0
- package/dist/tools/search-vaults.js.map +1 -0
- package/dist/tools/simulate-vault.d.ts +80 -0
- package/dist/tools/simulate-vault.d.ts.map +1 -0
- package/dist/tools/simulate-vault.js +281 -0
- package/dist/tools/simulate-vault.js.map +1 -0
- package/dist/tools/user-portfolio.d.ts +30 -0
- package/dist/tools/user-portfolio.d.ts.map +1 -0
- package/dist/tools/user-portfolio.js +142 -0
- package/dist/tools/user-portfolio.js.map +1 -0
- package/dist/tools/vault-data.d.ts +23 -0
- package/dist/tools/vault-data.d.ts.map +1 -0
- package/dist/tools/vault-data.js +68 -0
- package/dist/tools/vault-data.js.map +1 -0
- package/dist/tools/vault-performance.d.ts +30 -0
- package/dist/tools/vault-performance.d.ts.map +1 -0
- package/dist/tools/vault-performance.js +275 -0
- package/dist/tools/vault-performance.js.map +1 -0
- package/dist/types/generated.d.ts +1109 -0
- package/dist/types/generated.d.ts.map +1 -0
- package/dist/types/generated.js +2 -0
- package/dist/types/generated.js.map +1 -0
- package/dist/types/index.d.ts +46 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/comparison-metrics.d.ts +120 -0
- package/dist/utils/comparison-metrics.d.ts.map +1 -0
- package/dist/utils/comparison-metrics.js +215 -0
- package/dist/utils/comparison-metrics.js.map +1 -0
- package/dist/utils/config-loader.d.ts +17 -0
- package/dist/utils/config-loader.d.ts.map +1 -0
- package/dist/utils/config-loader.js +45 -0
- package/dist/utils/config-loader.js.map +1 -0
- package/dist/utils/csv-generator.d.ts +89 -0
- package/dist/utils/csv-generator.d.ts.map +1 -0
- package/dist/utils/csv-generator.js +97 -0
- package/dist/utils/csv-generator.js.map +1 -0
- package/dist/utils/disclaimers.d.ts +70 -0
- package/dist/utils/disclaimers.d.ts.map +1 -0
- package/dist/utils/disclaimers.js +161 -0
- package/dist/utils/disclaimers.js.map +1 -0
- package/dist/utils/errors.d.ts +66 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +86 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/execute-tool-with-cache.d.ts +97 -0
- package/dist/utils/execute-tool-with-cache.d.ts.map +1 -0
- package/dist/utils/execute-tool-with-cache.js +105 -0
- package/dist/utils/execute-tool-with-cache.js.map +1 -0
- package/dist/utils/portfolio-optimization.d.ts +100 -0
- package/dist/utils/portfolio-optimization.d.ts.map +1 -0
- package/dist/utils/portfolio-optimization.js +283 -0
- package/dist/utils/portfolio-optimization.js.map +1 -0
- package/dist/utils/risk-scoring.d.ts +226 -0
- package/dist/utils/risk-scoring.d.ts.map +1 -0
- package/dist/utils/risk-scoring.js +523 -0
- package/dist/utils/risk-scoring.js.map +1 -0
- package/dist/utils/tool-error-handler.d.ts +16 -0
- package/dist/utils/tool-error-handler.d.ts.map +1 -0
- package/dist/utils/tool-error-handler.js +43 -0
- package/dist/utils/tool-error-handler.js.map +1 -0
- package/dist/utils/tool-handler.d.ts +33 -0
- package/dist/utils/tool-handler.d.ts.map +1 -0
- package/dist/utils/tool-handler.js +59 -0
- package/dist/utils/tool-handler.js.map +1 -0
- package/dist/utils/tool-response.d.ts +16 -0
- package/dist/utils/tool-response.d.ts.map +1 -0
- package/dist/utils/tool-response.js +25 -0
- package/dist/utils/tool-response.js.map +1 -0
- package/dist/utils/validators.d.ts +359 -0
- package/dist/utils/validators.d.ts.map +1 -0
- package/dist/utils/validators.js +233 -0
- package/dist/utils/validators.js.map +1 -0
- package/dist/utils/yield-prediction.d.ts +69 -0
- package/dist/utils/yield-prediction.d.ts.map +1 -0
- package/dist/utils/yield-prediction.js +290 -0
- package/dist/utils/yield-prediction.js.map +1 -0
- package/package.json +83 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vault Simulation Service
|
|
3
|
+
*
|
|
4
|
+
* Provides vault simulation functionality using Lagoon SDK's simulate() function.
|
|
5
|
+
* Production patterns from frontend-dapp-v2.
|
|
6
|
+
*
|
|
7
|
+
* @module simulation-service
|
|
8
|
+
*/
|
|
9
|
+
import type { SimulationInput, SimulationResult, VersionOrLatest } from '@lagoon-protocol/v0-computation';
|
|
10
|
+
import type { VaultData } from '../graphql/fragments/index.js';
|
|
11
|
+
import type { APRHistoricalData } from './apr-service.js';
|
|
12
|
+
/**
|
|
13
|
+
* Map vault data to SDK simulation format
|
|
14
|
+
*
|
|
15
|
+
* Transforms VaultData from GraphQL into the format expected by the SDK's simulate() function.
|
|
16
|
+
* Handles decimal offset calculations and fee rate conversions.
|
|
17
|
+
*
|
|
18
|
+
* @param vault - Vault data from GraphQL
|
|
19
|
+
* @param newTotalAssets - Proposed total assets for simulation (in wei)
|
|
20
|
+
* @returns Vault object in SDK format
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const vaultForSimulation = mapVaultToSimulationFormat(vault, BigInt('1000000000000'));
|
|
25
|
+
* // Returns: { decimals, underlyingDecimals, newTotalAssets, totalSupply, ... }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function mapVaultToSimulationFormat(vault: VaultData, newTotalAssets: bigint): {
|
|
29
|
+
decimals: number;
|
|
30
|
+
underlyingDecimals: number;
|
|
31
|
+
newTotalAssets: bigint;
|
|
32
|
+
totalSupply: bigint;
|
|
33
|
+
totalAssets: bigint;
|
|
34
|
+
highWaterMark: bigint;
|
|
35
|
+
lastFeeTime: bigint;
|
|
36
|
+
feeRates: {
|
|
37
|
+
managementRate: number;
|
|
38
|
+
performanceRate: number;
|
|
39
|
+
};
|
|
40
|
+
version: VersionOrLatest;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Construct simulation input from vault state and parameters
|
|
44
|
+
*
|
|
45
|
+
* Builds the complete input object required by SDK's simulate() function,
|
|
46
|
+
* including pending balances, settlement data, and optional APR historical data.
|
|
47
|
+
*
|
|
48
|
+
* @param vault - Vault data from GraphQL
|
|
49
|
+
* @param newTotalAssets - Proposed total assets for simulation (in wei)
|
|
50
|
+
* @param aprData - Optional APR historical data for yield calculations
|
|
51
|
+
* @param settleDeposit - Whether to settle pending deposits (default: true)
|
|
52
|
+
* @returns Complete simulation input object
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const input = constructSimulationInput(
|
|
57
|
+
* vault,
|
|
58
|
+
* BigInt('5000000000'),
|
|
59
|
+
* aprData,
|
|
60
|
+
* true
|
|
61
|
+
* );
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function constructSimulationInput(vault: VaultData, newTotalAssets: bigint, aprData?: APRHistoricalData, settleDeposit?: boolean): SimulationInput;
|
|
65
|
+
/**
|
|
66
|
+
* Simulate vault management with new total assets
|
|
67
|
+
*
|
|
68
|
+
* Main simulation function that orchestrates the complete simulation workflow:
|
|
69
|
+
* 1. Validates input parameters
|
|
70
|
+
* 2. Maps vault data to SDK format
|
|
71
|
+
* 3. Constructs simulation input
|
|
72
|
+
* 4. Executes SDK simulation
|
|
73
|
+
* 5. Returns detailed simulation results
|
|
74
|
+
*
|
|
75
|
+
* This function uses the Lagoon SDK's simulate() function which performs
|
|
76
|
+
* protocol-accurate calculations for:
|
|
77
|
+
* - Fee accruals (management and performance)
|
|
78
|
+
* - Share price changes
|
|
79
|
+
* - Settlement requirements
|
|
80
|
+
* - APR calculations (when historical data provided)
|
|
81
|
+
*
|
|
82
|
+
* @param vault - Vault data from GraphQL (required)
|
|
83
|
+
* @param newTotalAssets - Proposed total assets after deposit/withdrawal (required, must be > 0)
|
|
84
|
+
* @param aprData - Optional APR historical data for yield projections
|
|
85
|
+
* @param settleDeposit - Whether to settle pending deposits (default: true)
|
|
86
|
+
* @returns Detailed simulation results from SDK
|
|
87
|
+
* @throws {Error} If vault data is missing
|
|
88
|
+
* @throws {Error} If newTotalAssets is <= 0
|
|
89
|
+
* @throws {Error} If SDK simulation fails
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* // Simulate a deposit
|
|
94
|
+
* const result = await simulateVaultManagement(
|
|
95
|
+
* vault,
|
|
96
|
+
* BigInt('2000000000000'), // +1000 tokens
|
|
97
|
+
* aprData,
|
|
98
|
+
* true
|
|
99
|
+
* );
|
|
100
|
+
*
|
|
101
|
+
* console.log(result.totalSupply); // New share supply
|
|
102
|
+
* console.log(result.feesAccrued); // Fees charged
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare function simulateVaultManagement(vault: VaultData, newTotalAssets: bigint, aprData?: APRHistoricalData, settleDeposit?: boolean): SimulationResult;
|
|
106
|
+
//# sourceMappingURL=simulation-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simulation-service.d.ts","sourceRoot":"","sources":["../../src/sdk/simulation-service.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,eAAe,EAChB,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE1D;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,SAAS,EAChB,cAAc,EAAE,MAAM,GACrB;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE;QACR,cAAc,EAAE,MAAM,CAAC;QACvB,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;IACF,OAAO,EAAE,eAAe,CAAC;CAC1B,CAkBA;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,SAAS,EAChB,cAAc,EAAE,MAAM,EACtB,OAAO,CAAC,EAAE,iBAAiB,EAC3B,aAAa,GAAE,OAAc,GAC5B,eAAe,CAgBjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,SAAS,EAChB,cAAc,EAAE,MAAM,EACtB,OAAO,CAAC,EAAE,iBAAiB,EAC3B,aAAa,GAAE,OAAc,GAC5B,gBAAgB,CAwBlB"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vault Simulation Service
|
|
3
|
+
*
|
|
4
|
+
* Provides vault simulation functionality using Lagoon SDK's simulate() function.
|
|
5
|
+
* Production patterns from frontend-dapp-v2.
|
|
6
|
+
*
|
|
7
|
+
* @module simulation-service
|
|
8
|
+
*/
|
|
9
|
+
import { simulate } from '@lagoon-protocol/v0-computation';
|
|
10
|
+
/**
|
|
11
|
+
* Map vault data to SDK simulation format
|
|
12
|
+
*
|
|
13
|
+
* Transforms VaultData from GraphQL into the format expected by the SDK's simulate() function.
|
|
14
|
+
* Handles decimal offset calculations and fee rate conversions.
|
|
15
|
+
*
|
|
16
|
+
* @param vault - Vault data from GraphQL
|
|
17
|
+
* @param newTotalAssets - Proposed total assets for simulation (in wei)
|
|
18
|
+
* @returns Vault object in SDK format
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const vaultForSimulation = mapVaultToSimulationFormat(vault, BigInt('1000000000000'));
|
|
23
|
+
* // Returns: { decimals, underlyingDecimals, newTotalAssets, totalSupply, ... }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export function mapVaultToSimulationFormat(vault, newTotalAssets) {
|
|
27
|
+
const vaultDecimals = Number(vault.decimals ?? 18);
|
|
28
|
+
const assetDecimals = Number(vault.asset.decimals);
|
|
29
|
+
return {
|
|
30
|
+
decimals: vaultDecimals,
|
|
31
|
+
underlyingDecimals: assetDecimals,
|
|
32
|
+
newTotalAssets,
|
|
33
|
+
totalSupply: BigInt(vault.state.totalSupply),
|
|
34
|
+
totalAssets: BigInt(vault.state.totalAssets),
|
|
35
|
+
highWaterMark: BigInt(vault.state.highWaterMark),
|
|
36
|
+
lastFeeTime: BigInt(vault.state.lastFeeTime),
|
|
37
|
+
feeRates: {
|
|
38
|
+
managementRate: Number(vault.state.managementFee),
|
|
39
|
+
performanceRate: Number(vault.state.performanceFee),
|
|
40
|
+
},
|
|
41
|
+
version: vault.state.version || 'latest',
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Construct simulation input from vault state and parameters
|
|
46
|
+
*
|
|
47
|
+
* Builds the complete input object required by SDK's simulate() function,
|
|
48
|
+
* including pending balances, settlement data, and optional APR historical data.
|
|
49
|
+
*
|
|
50
|
+
* @param vault - Vault data from GraphQL
|
|
51
|
+
* @param newTotalAssets - Proposed total assets for simulation (in wei)
|
|
52
|
+
* @param aprData - Optional APR historical data for yield calculations
|
|
53
|
+
* @param settleDeposit - Whether to settle pending deposits (default: true)
|
|
54
|
+
* @returns Complete simulation input object
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const input = constructSimulationInput(
|
|
59
|
+
* vault,
|
|
60
|
+
* BigInt('5000000000'),
|
|
61
|
+
* aprData,
|
|
62
|
+
* true
|
|
63
|
+
* );
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export function constructSimulationInput(vault, newTotalAssets, aprData, settleDeposit = true) {
|
|
67
|
+
return {
|
|
68
|
+
totalAssetsForSimulation: newTotalAssets,
|
|
69
|
+
assetsInSafe: BigInt(vault.state.safeAssetBalance ?? '0'),
|
|
70
|
+
pendingSiloBalances: {
|
|
71
|
+
assets: BigInt(vault.state.pendingSiloBalances?.assets ?? '0'),
|
|
72
|
+
shares: BigInt(vault.state.pendingSiloBalances?.shares ?? '0'),
|
|
73
|
+
},
|
|
74
|
+
pendingSettlement: {
|
|
75
|
+
assets: BigInt(vault.state.pendingSettlement?.assets ?? '0'),
|
|
76
|
+
shares: BigInt(vault.state.pendingSettlement?.shares ?? '0'),
|
|
77
|
+
},
|
|
78
|
+
settleDeposit,
|
|
79
|
+
inception: aprData?.inception,
|
|
80
|
+
thirtyDay: aprData?.thirtyDay,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Simulate vault management with new total assets
|
|
85
|
+
*
|
|
86
|
+
* Main simulation function that orchestrates the complete simulation workflow:
|
|
87
|
+
* 1. Validates input parameters
|
|
88
|
+
* 2. Maps vault data to SDK format
|
|
89
|
+
* 3. Constructs simulation input
|
|
90
|
+
* 4. Executes SDK simulation
|
|
91
|
+
* 5. Returns detailed simulation results
|
|
92
|
+
*
|
|
93
|
+
* This function uses the Lagoon SDK's simulate() function which performs
|
|
94
|
+
* protocol-accurate calculations for:
|
|
95
|
+
* - Fee accruals (management and performance)
|
|
96
|
+
* - Share price changes
|
|
97
|
+
* - Settlement requirements
|
|
98
|
+
* - APR calculations (when historical data provided)
|
|
99
|
+
*
|
|
100
|
+
* @param vault - Vault data from GraphQL (required)
|
|
101
|
+
* @param newTotalAssets - Proposed total assets after deposit/withdrawal (required, must be > 0)
|
|
102
|
+
* @param aprData - Optional APR historical data for yield projections
|
|
103
|
+
* @param settleDeposit - Whether to settle pending deposits (default: true)
|
|
104
|
+
* @returns Detailed simulation results from SDK
|
|
105
|
+
* @throws {Error} If vault data is missing
|
|
106
|
+
* @throws {Error} If newTotalAssets is <= 0
|
|
107
|
+
* @throws {Error} If SDK simulation fails
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* // Simulate a deposit
|
|
112
|
+
* const result = await simulateVaultManagement(
|
|
113
|
+
* vault,
|
|
114
|
+
* BigInt('2000000000000'), // +1000 tokens
|
|
115
|
+
* aprData,
|
|
116
|
+
* true
|
|
117
|
+
* );
|
|
118
|
+
*
|
|
119
|
+
* console.log(result.totalSupply); // New share supply
|
|
120
|
+
* console.log(result.feesAccrued); // Fees charged
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export function simulateVaultManagement(vault, newTotalAssets, aprData, settleDeposit = true) {
|
|
124
|
+
// Validation
|
|
125
|
+
if (!vault) {
|
|
126
|
+
throw new Error('Vault data is required for simulation');
|
|
127
|
+
}
|
|
128
|
+
if (newTotalAssets <= 0n) {
|
|
129
|
+
throw new Error('New total assets must be positive');
|
|
130
|
+
}
|
|
131
|
+
// Map vault to SDK format
|
|
132
|
+
const vaultForSimulation = mapVaultToSimulationFormat(vault, newTotalAssets);
|
|
133
|
+
// Construct simulation input
|
|
134
|
+
const simulationInput = constructSimulationInput(vault, newTotalAssets, aprData, settleDeposit);
|
|
135
|
+
// Execute simulation
|
|
136
|
+
try {
|
|
137
|
+
return simulate(vaultForSimulation, simulationInput);
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
throw new Error(`Simulation failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=simulation-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simulation-service.js","sourceRoot":"","sources":["../../src/sdk/simulation-service.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vault Utilities
|
|
3
|
+
*
|
|
4
|
+
* Internal wrapper utilities for Lagoon SDK VaultUtils.
|
|
5
|
+
* Production-validated patterns from frontend-dapp-v2 for share/asset conversions.
|
|
6
|
+
*
|
|
7
|
+
* @module sdk/vault-utils
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Vault state for conversions
|
|
11
|
+
*/
|
|
12
|
+
export interface VaultState {
|
|
13
|
+
totalAssets: bigint;
|
|
14
|
+
totalSupply: bigint;
|
|
15
|
+
decimalsOffset: bigint;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Calculate price per share
|
|
19
|
+
*
|
|
20
|
+
* Internal utility for computing current vault share price.
|
|
21
|
+
* Used by simulation and performance tools internally.
|
|
22
|
+
*
|
|
23
|
+
* Production pattern from pricePerShareCalculations.ts - handles edge cases:
|
|
24
|
+
* - Zero total supply (returns 1:1 ratio)
|
|
25
|
+
* - Decimal offset mismatches
|
|
26
|
+
* - Rounding modes for safety
|
|
27
|
+
*
|
|
28
|
+
* @param totalAssets - Total assets under management (in asset decimals)
|
|
29
|
+
* @param totalSupply - Total shares outstanding (in vault decimals)
|
|
30
|
+
* @param vaultDecimals - Vault token decimals (typically 18)
|
|
31
|
+
* @param assetDecimals - Underlying asset decimals (e.g., 6 for USDC)
|
|
32
|
+
* @returns Price per share in asset decimals (1 share = X assets)
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* // Vault with 1000 USDC (6 decimals) and 950 shares (18 decimals)
|
|
37
|
+
* const pricePerShare = calculatePricePerShare(
|
|
38
|
+
* 1000000000n, // 1000 USDC in 6 decimals
|
|
39
|
+
* 950000000000000000000n, // 950 shares in 18 decimals
|
|
40
|
+
* 18,
|
|
41
|
+
* 6
|
|
42
|
+
* );
|
|
43
|
+
* // => ~1052631n (1.052631 USDC per share)
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function calculatePricePerShare(totalAssets: bigint, totalSupply: bigint, vaultDecimals: number, assetDecimals: number): bigint;
|
|
47
|
+
/**
|
|
48
|
+
* Convert shares to assets
|
|
49
|
+
*
|
|
50
|
+
* Internal utility for calculating asset amount from shares.
|
|
51
|
+
* Uses SDK's VaultUtils.convertToAssets with proper rounding.
|
|
52
|
+
*
|
|
53
|
+
* @param shares - Share amount to convert (in vault decimals)
|
|
54
|
+
* @param totalAssets - Current total assets (in asset decimals)
|
|
55
|
+
* @param totalSupply - Current total supply (in vault decimals)
|
|
56
|
+
* @param decimalsOffset - Vault decimals - asset decimals
|
|
57
|
+
* @param roundingMode - Rounding direction ('Up' for user favorable, 'Down' for protocol favorable)
|
|
58
|
+
* @returns Asset amount (in asset decimals)
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* // Convert 10 shares to USDC
|
|
63
|
+
* const assets = convertSharesToAssets(
|
|
64
|
+
* 10000000000000000000n, // 10 shares (18 decimals)
|
|
65
|
+
* 1000000000n, // 1000 USDC total (6 decimals)
|
|
66
|
+
* 950000000000000000000n, // 950 shares total (18 decimals)
|
|
67
|
+
* 12, // 18 - 6 = 12
|
|
68
|
+
* 'Down' // Conservative for withdrawals
|
|
69
|
+
* );
|
|
70
|
+
* // => ~10526315n (~10.526315 USDC)
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare function convertSharesToAssets(shares: bigint, totalAssets: bigint, totalSupply: bigint, decimalsOffset: number, roundingMode?: 'Up' | 'Down'): bigint;
|
|
74
|
+
/**
|
|
75
|
+
* Convert assets to shares
|
|
76
|
+
*
|
|
77
|
+
* Internal utility for calculating share amount from assets.
|
|
78
|
+
* Uses SDK's VaultUtils.convertToShares with proper rounding.
|
|
79
|
+
*
|
|
80
|
+
* @param assets - Asset amount to convert (in asset decimals)
|
|
81
|
+
* @param totalAssets - Current total assets (in asset decimals)
|
|
82
|
+
* @param totalSupply - Current total supply (in vault decimals)
|
|
83
|
+
* @param decimalsOffset - Vault decimals - asset decimals
|
|
84
|
+
* @param roundingMode - Rounding direction ('Up' for protocol favorable, 'Down' for user favorable)
|
|
85
|
+
* @returns Share amount (in vault decimals)
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* // Convert 100 USDC to shares
|
|
90
|
+
* const shares = convertAssetsToShares(
|
|
91
|
+
* 100000000n, // 100 USDC (6 decimals)
|
|
92
|
+
* 1000000000n, // 1000 USDC total (6 decimals)
|
|
93
|
+
* 950000000000000000000n, // 950 shares total (18 decimals)
|
|
94
|
+
* 12, // 18 - 6 = 12
|
|
95
|
+
* 'Up' // Conservative for deposits
|
|
96
|
+
* );
|
|
97
|
+
* // => ~95000000000000000000n (~95 shares)
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare function convertAssetsToShares(assets: bigint, totalAssets: bigint, totalSupply: bigint, decimalsOffset: number, roundingMode?: 'Up' | 'Down'): bigint;
|
|
101
|
+
/**
|
|
102
|
+
* Build vault state object
|
|
103
|
+
*
|
|
104
|
+
* Convenience helper to construct VaultState from raw values.
|
|
105
|
+
* Validates inputs and handles type conversions.
|
|
106
|
+
*
|
|
107
|
+
* @param totalAssets - Total assets (can be bigint or string)
|
|
108
|
+
* @param totalSupply - Total supply (can be bigint or string)
|
|
109
|
+
* @param vaultDecimals - Vault decimals
|
|
110
|
+
* @param assetDecimals - Asset decimals
|
|
111
|
+
* @returns Validated vault state object
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* const state = buildVaultState(
|
|
116
|
+
* "1000000000",
|
|
117
|
+
* "950000000000000000000",
|
|
118
|
+
* 18,
|
|
119
|
+
* 6
|
|
120
|
+
* );
|
|
121
|
+
* // => { totalAssets: 1000000000n, totalSupply: 950...n, decimalsOffset: 12n }
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export declare function buildVaultState(totalAssets: bigint | string, totalSupply: bigint | string, vaultDecimals: number, assetDecimals: number): VaultState;
|
|
125
|
+
//# sourceMappingURL=vault-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vault-utils.d.ts","sourceRoot":"","sources":["../../src/sdk/vault-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,GACpB,MAAM,CAyBR;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,MAAM,EACtB,YAAY,GAAE,IAAI,GAAG,MAAe,GACnC,MAAM,CAUR;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,MAAM,EACtB,YAAY,GAAE,IAAI,GAAG,MAAa,GACjC,MAAM,CAUR;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,eAAe,CAC7B,WAAW,EAAE,MAAM,GAAG,MAAM,EAC5B,WAAW,EAAE,MAAM,GAAG,MAAM,EAC5B,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,GACpB,UAAU,CAmBZ"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vault Utilities
|
|
3
|
+
*
|
|
4
|
+
* Internal wrapper utilities for Lagoon SDK VaultUtils.
|
|
5
|
+
* Production-validated patterns from frontend-dapp-v2 for share/asset conversions.
|
|
6
|
+
*
|
|
7
|
+
* @module sdk/vault-utils
|
|
8
|
+
*/
|
|
9
|
+
import * as LagoonCore from '@lagoon-protocol/v0-core';
|
|
10
|
+
/**
|
|
11
|
+
* Calculate price per share
|
|
12
|
+
*
|
|
13
|
+
* Internal utility for computing current vault share price.
|
|
14
|
+
* Used by simulation and performance tools internally.
|
|
15
|
+
*
|
|
16
|
+
* Production pattern from pricePerShareCalculations.ts - handles edge cases:
|
|
17
|
+
* - Zero total supply (returns 1:1 ratio)
|
|
18
|
+
* - Decimal offset mismatches
|
|
19
|
+
* - Rounding modes for safety
|
|
20
|
+
*
|
|
21
|
+
* @param totalAssets - Total assets under management (in asset decimals)
|
|
22
|
+
* @param totalSupply - Total shares outstanding (in vault decimals)
|
|
23
|
+
* @param vaultDecimals - Vault token decimals (typically 18)
|
|
24
|
+
* @param assetDecimals - Underlying asset decimals (e.g., 6 for USDC)
|
|
25
|
+
* @returns Price per share in asset decimals (1 share = X assets)
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // Vault with 1000 USDC (6 decimals) and 950 shares (18 decimals)
|
|
30
|
+
* const pricePerShare = calculatePricePerShare(
|
|
31
|
+
* 1000000000n, // 1000 USDC in 6 decimals
|
|
32
|
+
* 950000000000000000000n, // 950 shares in 18 decimals
|
|
33
|
+
* 18,
|
|
34
|
+
* 6
|
|
35
|
+
* );
|
|
36
|
+
* // => ~1052631n (1.052631 USDC per share)
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export function calculatePricePerShare(totalAssets, totalSupply, vaultDecimals, assetDecimals) {
|
|
40
|
+
// Validate inputs
|
|
41
|
+
if (vaultDecimals < 0 || assetDecimals < 0) {
|
|
42
|
+
throw new Error('Decimals must be non-negative');
|
|
43
|
+
}
|
|
44
|
+
const decimalsOffset = vaultDecimals - assetDecimals;
|
|
45
|
+
try {
|
|
46
|
+
// Calculate price for 1 share (1e18 in wei)
|
|
47
|
+
return LagoonCore.VaultUtils.convertToAssets(BigInt(1e18), // 1 share in wei (18 decimals)
|
|
48
|
+
{
|
|
49
|
+
totalAssets,
|
|
50
|
+
totalSupply,
|
|
51
|
+
decimalsOffset: BigInt(decimalsOffset),
|
|
52
|
+
}, 'Down' // Round down for safety (conservative pricing)
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
// Graceful fallback: 1:1 ratio if calculation fails
|
|
57
|
+
// This happens for new vaults with zero supply
|
|
58
|
+
console.warn('Price per share calculation failed, using 1:1 ratio:', error);
|
|
59
|
+
return BigInt(10 ** assetDecimals);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Convert shares to assets
|
|
64
|
+
*
|
|
65
|
+
* Internal utility for calculating asset amount from shares.
|
|
66
|
+
* Uses SDK's VaultUtils.convertToAssets with proper rounding.
|
|
67
|
+
*
|
|
68
|
+
* @param shares - Share amount to convert (in vault decimals)
|
|
69
|
+
* @param totalAssets - Current total assets (in asset decimals)
|
|
70
|
+
* @param totalSupply - Current total supply (in vault decimals)
|
|
71
|
+
* @param decimalsOffset - Vault decimals - asset decimals
|
|
72
|
+
* @param roundingMode - Rounding direction ('Up' for user favorable, 'Down' for protocol favorable)
|
|
73
|
+
* @returns Asset amount (in asset decimals)
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* // Convert 10 shares to USDC
|
|
78
|
+
* const assets = convertSharesToAssets(
|
|
79
|
+
* 10000000000000000000n, // 10 shares (18 decimals)
|
|
80
|
+
* 1000000000n, // 1000 USDC total (6 decimals)
|
|
81
|
+
* 950000000000000000000n, // 950 shares total (18 decimals)
|
|
82
|
+
* 12, // 18 - 6 = 12
|
|
83
|
+
* 'Down' // Conservative for withdrawals
|
|
84
|
+
* );
|
|
85
|
+
* // => ~10526315n (~10.526315 USDC)
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export function convertSharesToAssets(shares, totalAssets, totalSupply, decimalsOffset, roundingMode = 'Down') {
|
|
89
|
+
if (shares < 0n || totalAssets < 0n || totalSupply < 0n) {
|
|
90
|
+
throw new Error('Values must be non-negative');
|
|
91
|
+
}
|
|
92
|
+
return LagoonCore.VaultUtils.convertToAssets(shares, { totalAssets, totalSupply, decimalsOffset: BigInt(decimalsOffset) }, roundingMode);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Convert assets to shares
|
|
96
|
+
*
|
|
97
|
+
* Internal utility for calculating share amount from assets.
|
|
98
|
+
* Uses SDK's VaultUtils.convertToShares with proper rounding.
|
|
99
|
+
*
|
|
100
|
+
* @param assets - Asset amount to convert (in asset decimals)
|
|
101
|
+
* @param totalAssets - Current total assets (in asset decimals)
|
|
102
|
+
* @param totalSupply - Current total supply (in vault decimals)
|
|
103
|
+
* @param decimalsOffset - Vault decimals - asset decimals
|
|
104
|
+
* @param roundingMode - Rounding direction ('Up' for protocol favorable, 'Down' for user favorable)
|
|
105
|
+
* @returns Share amount (in vault decimals)
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* // Convert 100 USDC to shares
|
|
110
|
+
* const shares = convertAssetsToShares(
|
|
111
|
+
* 100000000n, // 100 USDC (6 decimals)
|
|
112
|
+
* 1000000000n, // 1000 USDC total (6 decimals)
|
|
113
|
+
* 950000000000000000000n, // 950 shares total (18 decimals)
|
|
114
|
+
* 12, // 18 - 6 = 12
|
|
115
|
+
* 'Up' // Conservative for deposits
|
|
116
|
+
* );
|
|
117
|
+
* // => ~95000000000000000000n (~95 shares)
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export function convertAssetsToShares(assets, totalAssets, totalSupply, decimalsOffset, roundingMode = 'Up') {
|
|
121
|
+
if (assets < 0n || totalAssets < 0n || totalSupply < 0n) {
|
|
122
|
+
throw new Error('Values must be non-negative');
|
|
123
|
+
}
|
|
124
|
+
return LagoonCore.VaultUtils.convertToShares(assets, { totalAssets, totalSupply, decimalsOffset: BigInt(decimalsOffset) }, roundingMode);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Build vault state object
|
|
128
|
+
*
|
|
129
|
+
* Convenience helper to construct VaultState from raw values.
|
|
130
|
+
* Validates inputs and handles type conversions.
|
|
131
|
+
*
|
|
132
|
+
* @param totalAssets - Total assets (can be bigint or string)
|
|
133
|
+
* @param totalSupply - Total supply (can be bigint or string)
|
|
134
|
+
* @param vaultDecimals - Vault decimals
|
|
135
|
+
* @param assetDecimals - Asset decimals
|
|
136
|
+
* @returns Validated vault state object
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* const state = buildVaultState(
|
|
141
|
+
* "1000000000",
|
|
142
|
+
* "950000000000000000000",
|
|
143
|
+
* 18,
|
|
144
|
+
* 6
|
|
145
|
+
* );
|
|
146
|
+
* // => { totalAssets: 1000000000n, totalSupply: 950...n, decimalsOffset: 12n }
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
export function buildVaultState(totalAssets, totalSupply, vaultDecimals, assetDecimals) {
|
|
150
|
+
const assets = typeof totalAssets === 'string' ? BigInt(totalAssets) : totalAssets;
|
|
151
|
+
const supply = typeof totalSupply === 'string' ? BigInt(totalSupply) : totalSupply;
|
|
152
|
+
if (assets < 0n || supply < 0n) {
|
|
153
|
+
throw new Error('Vault state values must be non-negative');
|
|
154
|
+
}
|
|
155
|
+
if (vaultDecimals < 0 || assetDecimals < 0) {
|
|
156
|
+
throw new Error('Decimals must be non-negative');
|
|
157
|
+
}
|
|
158
|
+
const decimalsOffset = BigInt(vaultDecimals - assetDecimals);
|
|
159
|
+
return {
|
|
160
|
+
totalAssets: assets,
|
|
161
|
+
totalSupply: supply,
|
|
162
|
+
decimalsOffset,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=vault-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vault-utils.js","sourceRoot":"","sources":["../../src/sdk/vault-utils.ts"],"names":[],"mappings":"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"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lagoon MCP Server
|
|
3
|
+
*
|
|
4
|
+
* Modern implementation using McpServer API for:
|
|
5
|
+
* - Automatic capability management
|
|
6
|
+
* - Clean tool/resource/prompt registration
|
|
7
|
+
* - Future-proof architecture
|
|
8
|
+
*/
|
|
9
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
10
|
+
/**
|
|
11
|
+
* Create and configure the MCP server instance
|
|
12
|
+
*
|
|
13
|
+
* Uses modern McpServer API for automatic capability management
|
|
14
|
+
* and clean registration patterns.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createServer(): McpServer;
|
|
17
|
+
/**
|
|
18
|
+
* Run the MCP server
|
|
19
|
+
*/
|
|
20
|
+
export declare function runServer(): Promise<void>;
|
|
21
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAyBpE;;;;;GAKG;AACH,wBAAgB,YAAY,IAAI,SAAS,CA2NxC;AAED;;GAEG;AACH,wBAAsB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CA8B/C"}
|