@kadi.build/deploy-ability 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +523 -0
- package/dist/constants.d.ts +82 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +82 -0
- package/dist/constants.js.map +1 -0
- package/dist/errors/certificate-error.d.ts +95 -0
- package/dist/errors/certificate-error.d.ts.map +1 -0
- package/dist/errors/certificate-error.js +111 -0
- package/dist/errors/certificate-error.js.map +1 -0
- package/dist/errors/deployment-error.d.ts +122 -0
- package/dist/errors/deployment-error.d.ts.map +1 -0
- package/dist/errors/deployment-error.js +185 -0
- package/dist/errors/deployment-error.js.map +1 -0
- package/dist/errors/index.d.ts +13 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +18 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/profile-error.d.ts +106 -0
- package/dist/errors/profile-error.d.ts.map +1 -0
- package/dist/errors/profile-error.js +127 -0
- package/dist/errors/profile-error.js.map +1 -0
- package/dist/errors/provider-error.d.ts +104 -0
- package/dist/errors/provider-error.d.ts.map +1 -0
- package/dist/errors/provider-error.js +120 -0
- package/dist/errors/provider-error.js.map +1 -0
- package/dist/errors/wallet-error.d.ts +131 -0
- package/dist/errors/wallet-error.d.ts.map +1 -0
- package/dist/errors/wallet-error.js +154 -0
- package/dist/errors/wallet-error.js.map +1 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/targets/akash/bid-selectors.d.ts +251 -0
- package/dist/targets/akash/bid-selectors.d.ts.map +1 -0
- package/dist/targets/akash/bid-selectors.js +322 -0
- package/dist/targets/akash/bid-selectors.js.map +1 -0
- package/dist/targets/akash/bid-types.d.ts +297 -0
- package/dist/targets/akash/bid-types.d.ts.map +1 -0
- package/dist/targets/akash/bid-types.js +89 -0
- package/dist/targets/akash/bid-types.js.map +1 -0
- package/dist/targets/akash/blockchain-client.d.ts +577 -0
- package/dist/targets/akash/blockchain-client.d.ts.map +1 -0
- package/dist/targets/akash/blockchain-client.js +803 -0
- package/dist/targets/akash/blockchain-client.js.map +1 -0
- package/dist/targets/akash/certificate-manager.d.ts +228 -0
- package/dist/targets/akash/certificate-manager.d.ts.map +1 -0
- package/dist/targets/akash/certificate-manager.js +395 -0
- package/dist/targets/akash/certificate-manager.js.map +1 -0
- package/dist/targets/akash/constants.d.ts +231 -0
- package/dist/targets/akash/constants.d.ts.map +1 -0
- package/dist/targets/akash/constants.js +225 -0
- package/dist/targets/akash/constants.js.map +1 -0
- package/dist/targets/akash/deployer.d.ts +136 -0
- package/dist/targets/akash/deployer.d.ts.map +1 -0
- package/dist/targets/akash/deployer.js +599 -0
- package/dist/targets/akash/deployer.js.map +1 -0
- package/dist/targets/akash/environment.d.ts +241 -0
- package/dist/targets/akash/environment.d.ts.map +1 -0
- package/dist/targets/akash/environment.js +245 -0
- package/dist/targets/akash/environment.js.map +1 -0
- package/dist/targets/akash/index.d.ts +1113 -0
- package/dist/targets/akash/index.d.ts.map +1 -0
- package/dist/targets/akash/index.js +909 -0
- package/dist/targets/akash/index.js.map +1 -0
- package/dist/targets/akash/lease-monitor.d.ts +51 -0
- package/dist/targets/akash/lease-monitor.d.ts.map +1 -0
- package/dist/targets/akash/lease-monitor.js +110 -0
- package/dist/targets/akash/lease-monitor.js.map +1 -0
- package/dist/targets/akash/logs.d.ts +71 -0
- package/dist/targets/akash/logs.d.ts.map +1 -0
- package/dist/targets/akash/logs.js +311 -0
- package/dist/targets/akash/logs.js.map +1 -0
- package/dist/targets/akash/logs.types.d.ts +102 -0
- package/dist/targets/akash/logs.types.d.ts.map +1 -0
- package/dist/targets/akash/logs.types.js +9 -0
- package/dist/targets/akash/logs.types.js.map +1 -0
- package/dist/targets/akash/pricing.d.ts +247 -0
- package/dist/targets/akash/pricing.d.ts.map +1 -0
- package/dist/targets/akash/pricing.js +246 -0
- package/dist/targets/akash/pricing.js.map +1 -0
- package/dist/targets/akash/provider-client.d.ts +114 -0
- package/dist/targets/akash/provider-client.d.ts.map +1 -0
- package/dist/targets/akash/provider-client.js +318 -0
- package/dist/targets/akash/provider-client.js.map +1 -0
- package/dist/targets/akash/provider-metadata.d.ts +228 -0
- package/dist/targets/akash/provider-metadata.d.ts.map +1 -0
- package/dist/targets/akash/provider-metadata.js +14 -0
- package/dist/targets/akash/provider-metadata.js.map +1 -0
- package/dist/targets/akash/provider-service.d.ts +133 -0
- package/dist/targets/akash/provider-service.d.ts.map +1 -0
- package/dist/targets/akash/provider-service.js +391 -0
- package/dist/targets/akash/provider-service.js.map +1 -0
- package/dist/targets/akash/query-client.d.ts +125 -0
- package/dist/targets/akash/query-client.d.ts.map +1 -0
- package/dist/targets/akash/query-client.js +332 -0
- package/dist/targets/akash/query-client.js.map +1 -0
- package/dist/targets/akash/sdl-generator.d.ts +31 -0
- package/dist/targets/akash/sdl-generator.d.ts.map +1 -0
- package/dist/targets/akash/sdl-generator.js +279 -0
- package/dist/targets/akash/sdl-generator.js.map +1 -0
- package/dist/targets/akash/types.d.ts +285 -0
- package/dist/targets/akash/types.d.ts.map +1 -0
- package/dist/targets/akash/types.js +54 -0
- package/dist/targets/akash/types.js.map +1 -0
- package/dist/targets/akash/wallet-manager.d.ts +526 -0
- package/dist/targets/akash/wallet-manager.d.ts.map +1 -0
- package/dist/targets/akash/wallet-manager.js +953 -0
- package/dist/targets/akash/wallet-manager.js.map +1 -0
- package/dist/targets/local/compose-generator.d.ts +244 -0
- package/dist/targets/local/compose-generator.d.ts.map +1 -0
- package/dist/targets/local/compose-generator.js +324 -0
- package/dist/targets/local/compose-generator.js.map +1 -0
- package/dist/targets/local/deployer.d.ts +82 -0
- package/dist/targets/local/deployer.d.ts.map +1 -0
- package/dist/targets/local/deployer.js +367 -0
- package/dist/targets/local/deployer.js.map +1 -0
- package/dist/targets/local/engine-manager.d.ts +155 -0
- package/dist/targets/local/engine-manager.d.ts.map +1 -0
- package/dist/targets/local/engine-manager.js +250 -0
- package/dist/targets/local/engine-manager.js.map +1 -0
- package/dist/targets/local/index.d.ts +40 -0
- package/dist/targets/local/index.d.ts.map +1 -0
- package/dist/targets/local/index.js +43 -0
- package/dist/targets/local/index.js.map +1 -0
- package/dist/targets/local/network-manager.d.ts +160 -0
- package/dist/targets/local/network-manager.d.ts.map +1 -0
- package/dist/targets/local/network-manager.js +337 -0
- package/dist/targets/local/network-manager.js.map +1 -0
- package/dist/targets/local/types.d.ts +327 -0
- package/dist/targets/local/types.d.ts.map +1 -0
- package/dist/targets/local/types.js +9 -0
- package/dist/targets/local/types.js.map +1 -0
- package/dist/types/common.d.ts +585 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +13 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +12 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/options.d.ts +329 -0
- package/dist/types/options.d.ts.map +1 -0
- package/dist/types/options.js +10 -0
- package/dist/types/options.js.map +1 -0
- package/dist/types/profiles.d.ts +329 -0
- package/dist/types/profiles.d.ts.map +1 -0
- package/dist/types/profiles.js +27 -0
- package/dist/types/profiles.js.map +1 -0
- package/dist/types/results.d.ts +443 -0
- package/dist/types/results.d.ts.map +1 -0
- package/dist/types/results.js +64 -0
- package/dist/types/results.js.map +1 -0
- package/dist/types/validators.d.ts +118 -0
- package/dist/types/validators.d.ts.map +1 -0
- package/dist/types/validators.js +198 -0
- package/dist/types/validators.js.map +1 -0
- package/dist/utils/command-runner.d.ts +128 -0
- package/dist/utils/command-runner.d.ts.map +1 -0
- package/dist/utils/command-runner.js +210 -0
- package/dist/utils/command-runner.js.map +1 -0
- package/dist/utils/index.d.ts +10 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +10 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger.d.ts +68 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +93 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/profile-loader.d.ts +76 -0
- package/dist/utils/profile-loader.d.ts.map +1 -0
- package/dist/utils/profile-loader.js +194 -0
- package/dist/utils/profile-loader.js.map +1 -0
- package/dist/utils/registry/index.d.ts +27 -0
- package/dist/utils/registry/index.d.ts.map +1 -0
- package/dist/utils/registry/index.js +29 -0
- package/dist/utils/registry/index.js.map +1 -0
- package/dist/utils/registry/manager.d.ts +319 -0
- package/dist/utils/registry/manager.d.ts.map +1 -0
- package/dist/utils/registry/manager.js +671 -0
- package/dist/utils/registry/manager.js.map +1 -0
- package/dist/utils/registry/setup.d.ts +135 -0
- package/dist/utils/registry/setup.d.ts.map +1 -0
- package/dist/utils/registry/setup.js +207 -0
- package/dist/utils/registry/setup.js.map +1 -0
- package/dist/utils/registry/transformer.d.ts +92 -0
- package/dist/utils/registry/transformer.d.ts.map +1 -0
- package/dist/utils/registry/transformer.js +131 -0
- package/dist/utils/registry/transformer.js.map +1 -0
- package/dist/utils/registry/types.d.ts +241 -0
- package/dist/utils/registry/types.d.ts.map +1 -0
- package/dist/utils/registry/types.js +10 -0
- package/dist/utils/registry/types.js.map +1 -0
- package/docs/EXAMPLES.md +293 -0
- package/docs/PLACEMENT.md +433 -0
- package/docs/STORAGE.md +318 -0
- package/docs/building-provider-reliability-tracker.md +2581 -0
- package/package.json +109 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Akash Deployment Log Streaming Types
|
|
3
|
+
*
|
|
4
|
+
* Provides type-safe interfaces for streaming container logs from Akash deployments.
|
|
5
|
+
*
|
|
6
|
+
* @module targets/akash/logs.types
|
|
7
|
+
*/
|
|
8
|
+
import type { EventEmitter } from 'node:events';
|
|
9
|
+
import type { AkashDeploymentData } from '../../types/index.js';
|
|
10
|
+
import type { WalletContext } from './types.js';
|
|
11
|
+
import type { AkashProviderTlsCertificate } from './types.js';
|
|
12
|
+
import type { Network } from '../../types/common.js';
|
|
13
|
+
/**
|
|
14
|
+
* Options for streaming deployment logs
|
|
15
|
+
*/
|
|
16
|
+
export interface StreamLogsOptions {
|
|
17
|
+
/** Deployment data returned from deployToAkash() */
|
|
18
|
+
readonly deployment: AkashDeploymentData;
|
|
19
|
+
/** Wallet context (for provider address verification) */
|
|
20
|
+
readonly wallet: WalletContext;
|
|
21
|
+
/** Akash certificate (for mTLS authentication) */
|
|
22
|
+
readonly certificate: AkashProviderTlsCertificate;
|
|
23
|
+
/** Network (mainnet or testnet) */
|
|
24
|
+
readonly network: Network;
|
|
25
|
+
/** Optional: Filter logs by service names (default: all services) */
|
|
26
|
+
readonly services?: readonly string[];
|
|
27
|
+
/** Keep connection open and stream new logs (default: true) */
|
|
28
|
+
readonly follow?: boolean;
|
|
29
|
+
/** Show last N lines before streaming (default: 100) */
|
|
30
|
+
readonly tail?: number;
|
|
31
|
+
/** Optional: Custom logger for debugging */
|
|
32
|
+
readonly logger?: {
|
|
33
|
+
readonly debug?: (msg: string) => void;
|
|
34
|
+
readonly warn?: (msg: string) => void;
|
|
35
|
+
readonly error?: (msg: string) => void;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Options for getting logs as an array (non-streaming)
|
|
40
|
+
*/
|
|
41
|
+
export interface GetLogsOptions extends Omit<StreamLogsOptions, 'follow'> {
|
|
42
|
+
/** Maximum logs to retrieve (default: 1000) */
|
|
43
|
+
readonly maxLogs?: number;
|
|
44
|
+
/** Timeout in milliseconds (default: 30000) */
|
|
45
|
+
readonly timeout?: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Parsed log entry from Akash provider
|
|
49
|
+
*/
|
|
50
|
+
export interface LogEntry {
|
|
51
|
+
/** Service name (e.g., "ollama", "vllm") */
|
|
52
|
+
readonly service: string;
|
|
53
|
+
/** Log message content */
|
|
54
|
+
readonly message: string;
|
|
55
|
+
/** Raw log data from provider */
|
|
56
|
+
readonly raw: {
|
|
57
|
+
/** Full service name with replica suffix */
|
|
58
|
+
readonly name: string;
|
|
59
|
+
/** Original message before parsing */
|
|
60
|
+
readonly message: string;
|
|
61
|
+
/** ISO timestamp from provider */
|
|
62
|
+
readonly timestamp?: string;
|
|
63
|
+
};
|
|
64
|
+
/** When this log was received by deploy-ability */
|
|
65
|
+
readonly receivedAt: Date;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Log stream emitter
|
|
69
|
+
*
|
|
70
|
+
* Events:
|
|
71
|
+
* - 'log': Emitted for each log line
|
|
72
|
+
* - 'connected': WebSocket connection established
|
|
73
|
+
* - 'error': Connection or parsing error
|
|
74
|
+
* - 'end': Stream ended (natural or via close())
|
|
75
|
+
*/
|
|
76
|
+
export interface LogStream extends EventEmitter {
|
|
77
|
+
/** Close the stream and disconnect */
|
|
78
|
+
close(): void;
|
|
79
|
+
/** Check if stream is currently connected */
|
|
80
|
+
isConnected(): boolean;
|
|
81
|
+
on(event: 'log', listener: (log: LogEntry) => void): this;
|
|
82
|
+
on(event: 'connected', listener: () => void): this;
|
|
83
|
+
on(event: 'error', listener: (error: Error) => void): this;
|
|
84
|
+
on(event: 'end', listener: () => void): this;
|
|
85
|
+
once(event: 'log', listener: (log: LogEntry) => void): this;
|
|
86
|
+
once(event: 'connected', listener: () => void): this;
|
|
87
|
+
once(event: 'error', listener: (error: Error) => void): this;
|
|
88
|
+
once(event: 'end', listener: () => void): this;
|
|
89
|
+
off(event: 'log', listener: (log: LogEntry) => void): this;
|
|
90
|
+
off(event: 'connected', listener: () => void): this;
|
|
91
|
+
off(event: 'error', listener: (error: Error) => void): this;
|
|
92
|
+
off(event: 'end', listener: () => void): this;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Internal raw log message from Akash provider
|
|
96
|
+
*/
|
|
97
|
+
export interface RawProviderLogMessage {
|
|
98
|
+
readonly name: string;
|
|
99
|
+
readonly message: string;
|
|
100
|
+
readonly timestamp?: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
+
* Provides accurate price calculations for Akash Network deployments using the same
|
|
5
|
+
* formulas as Akash Console. Supports multiple price formats (per block, per hour,
|
|
6
|
+
* per month) and USD conversion.
|
|
7
|
+
*
|
|
8
|
+
* **Price Calculation Background:**
|
|
9
|
+
*
|
|
10
|
+
* Akash leases are priced per block on the blockchain. The raw price from the
|
|
11
|
+
* blockchain is in uAKT (micro AKT, where 1 AKT = 1,000,000 uAKT) per block.
|
|
12
|
+
*
|
|
13
|
+
* To make this human-readable, we calculate:
|
|
14
|
+
* - Price per hour: Based on average blocks per hour
|
|
15
|
+
* - Price per month: Based on average blocks per month
|
|
16
|
+
* - Price in USD: Requires current AKT market price
|
|
17
|
+
*
|
|
18
|
+
* **Constants (from Akash Console):**
|
|
19
|
+
* - Average block time: 6.098 seconds
|
|
20
|
+
* - Average days in month: 30.437 days (365.25 / 12)
|
|
21
|
+
*
|
|
22
|
+
* @module targets/akash/pricing
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Average time between blocks on Akash Network (in seconds)
|
|
26
|
+
*
|
|
27
|
+
* This value is determined empirically by observing actual block times.
|
|
28
|
+
* Akash Console uses 6.098 seconds as the average.
|
|
29
|
+
*
|
|
30
|
+
* @see https://github.com/akash-network/console
|
|
31
|
+
*/
|
|
32
|
+
export declare const AVERAGE_BLOCK_TIME_SECONDS = 6.098;
|
|
33
|
+
/**
|
|
34
|
+
* Average number of days in a month (365.25 / 12)
|
|
35
|
+
*
|
|
36
|
+
* Using the astronomical year (365.25 days) divided by 12 months
|
|
37
|
+
* provides accurate monthly cost estimates.
|
|
38
|
+
*/
|
|
39
|
+
export declare const AVERAGE_DAYS_IN_MONTH = 30.437;
|
|
40
|
+
/**
|
|
41
|
+
* Conversion factor: 1 AKT = 1,000,000 uAKT
|
|
42
|
+
*/
|
|
43
|
+
export declare const UAKT_PER_AKT = 1000000;
|
|
44
|
+
/**
|
|
45
|
+
* Lease price information with multiple time periods and currencies
|
|
46
|
+
*
|
|
47
|
+
* This class encapsulates all pricing information for an Akash lease and provides
|
|
48
|
+
* methods to convert between different formats (per block, per hour, per month)
|
|
49
|
+
* and currencies (uAKT, AKT, USD).
|
|
50
|
+
*
|
|
51
|
+
* **Usage Philosophy:**
|
|
52
|
+
*
|
|
53
|
+
* The blockchain provides raw price per block in uAKT. This class:
|
|
54
|
+
* 1. Stores the raw value (immutable)
|
|
55
|
+
* 2. Pre-computes common formats (per hour, per month)
|
|
56
|
+
* 3. Provides USD conversion only when caller provides AKT price
|
|
57
|
+
*
|
|
58
|
+
* This design keeps deploy-ability pure (no external API dependencies) while
|
|
59
|
+
* giving callers maximum flexibility in displaying prices.
|
|
60
|
+
*
|
|
61
|
+
* @example Basic usage - uAKT prices
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const price = new LeasePrice({ denom: 'uakt', amount: '1234' });
|
|
64
|
+
*
|
|
65
|
+
* console.log(price.uakt.perBlock); // 1234
|
|
66
|
+
* console.log(price.uakt.perHour); // ~720,000
|
|
67
|
+
* console.log(price.uakt.perMonth); // ~522,000,000
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @example USD conversion
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const price = new LeasePrice({ denom: 'uakt', amount: '1234' });
|
|
73
|
+
*
|
|
74
|
+
* // Fetch current AKT price from your preferred source
|
|
75
|
+
* const aktPrice = 0.50; // $0.50 per AKT
|
|
76
|
+
*
|
|
77
|
+
* const usd = price.toUSD(aktPrice);
|
|
78
|
+
* console.log(`$${usd.perMonth.toFixed(2)}/month`); // "$0.26/month"
|
|
79
|
+
* console.log(`$${usd.perHour.toFixed(4)}/hour`); // "$0.0004/hour"
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @example Displaying in kadi-deploy CLI
|
|
83
|
+
* ```typescript
|
|
84
|
+
* const result = await deployToAkash({ ... });
|
|
85
|
+
*
|
|
86
|
+
* if (result.success) {
|
|
87
|
+
* const { leasePrice } = result.data;
|
|
88
|
+
*
|
|
89
|
+
* // Fetch AKT price
|
|
90
|
+
* const aktPrice = await fetchAktPriceFromCoinGecko();
|
|
91
|
+
* const usd = leasePrice.toUSD(aktPrice);
|
|
92
|
+
*
|
|
93
|
+
* logger.log('Lease Pricing:');
|
|
94
|
+
* logger.log(` ${leasePrice.uakt.perMonth} uAKT/month ($${usd.perMonth.toFixed(2)}/month)`);
|
|
95
|
+
* logger.log(` ${leasePrice.uakt.perHour} uAKT/hour ($${usd.perHour.toFixed(4)}/hour)`);
|
|
96
|
+
* logger.log(` ${leasePrice.perBlock.amount} uAKT/block ($${usd.perBlock.toFixed(6)}/block)`);
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare class LeasePrice {
|
|
101
|
+
/**
|
|
102
|
+
* Raw price from blockchain (per block)
|
|
103
|
+
*
|
|
104
|
+
* This is the authoritative source - all other prices are computed from this.
|
|
105
|
+
*/
|
|
106
|
+
readonly perBlock: {
|
|
107
|
+
readonly denom: string;
|
|
108
|
+
readonly amount: string;
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Pre-computed prices in uAKT for different time periods
|
|
112
|
+
*
|
|
113
|
+
* All values are in micro AKT (uAKT). To convert to AKT, divide by 1,000,000.
|
|
114
|
+
*/
|
|
115
|
+
readonly uakt: {
|
|
116
|
+
/** Price in uAKT per block (same as perBlock.amount, but as number) */
|
|
117
|
+
readonly perBlock: number;
|
|
118
|
+
/** Price in uAKT per hour */
|
|
119
|
+
readonly perHour: number;
|
|
120
|
+
/** Price in uAKT per month (30.437 days) */
|
|
121
|
+
readonly perMonth: number;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Pre-computed prices in AKT (1 AKT = 1,000,000 uAKT)
|
|
125
|
+
*
|
|
126
|
+
* Convenient for display without manual conversion.
|
|
127
|
+
*/
|
|
128
|
+
readonly akt: {
|
|
129
|
+
/** Price in AKT per block */
|
|
130
|
+
readonly perBlock: number;
|
|
131
|
+
/** Price in AKT per hour */
|
|
132
|
+
readonly perHour: number;
|
|
133
|
+
/** Price in AKT per month */
|
|
134
|
+
readonly perMonth: number;
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Create a LeasePrice instance from blockchain price data
|
|
138
|
+
*
|
|
139
|
+
* @param price - Price object from blockchain query
|
|
140
|
+
* @param price.denom - Denomination (typically "uakt")
|
|
141
|
+
* @param price.amount - Amount per block as string
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* const price = new LeasePrice({
|
|
146
|
+
* denom: 'uakt',
|
|
147
|
+
* amount: '1234'
|
|
148
|
+
* });
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
constructor(price: {
|
|
152
|
+
denom: string;
|
|
153
|
+
amount: string;
|
|
154
|
+
});
|
|
155
|
+
/**
|
|
156
|
+
* Convert prices to USD using current AKT market price
|
|
157
|
+
*
|
|
158
|
+
* **Important:** This method requires you to provide the current AKT price.
|
|
159
|
+
* deploy-ability does not fetch market data to remain pure and dependency-free.
|
|
160
|
+
*
|
|
161
|
+
* **Where to get AKT price:**
|
|
162
|
+
* - CoinGecko API: https://api.coingecko.com/api/v3/simple/price?ids=akash-network&vs_currencies=usd
|
|
163
|
+
* - Your own price oracle
|
|
164
|
+
* - Akash Console API (if available)
|
|
165
|
+
* - Cached/hardcoded value for estimates
|
|
166
|
+
*
|
|
167
|
+
* @param aktPriceUSD - Current price of 1 AKT in USD
|
|
168
|
+
* @returns Prices in USD for different time periods
|
|
169
|
+
*
|
|
170
|
+
* @example Fetch from CoinGecko
|
|
171
|
+
* ```typescript
|
|
172
|
+
* const aktPrice = await fetch(
|
|
173
|
+
* 'https://api.coingecko.com/api/v3/simple/price?ids=akash-network&vs_currencies=usd'
|
|
174
|
+
* )
|
|
175
|
+
* .then(r => r.json())
|
|
176
|
+
* .then(data => data['akash-network'].usd);
|
|
177
|
+
*
|
|
178
|
+
* const usdPricing = leasePrice.toUSD(aktPrice);
|
|
179
|
+
* console.log(`Cost: $${usdPricing.perMonth.toFixed(2)}/month`);
|
|
180
|
+
* ```
|
|
181
|
+
*
|
|
182
|
+
* @example Use hardcoded estimate
|
|
183
|
+
* ```typescript
|
|
184
|
+
* // For quick estimates (update periodically)
|
|
185
|
+
* const aktPrice = 0.50; // $0.50 per AKT
|
|
186
|
+
* const usdPricing = leasePrice.toUSD(aktPrice);
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
toUSD(aktPriceUSD: number): {
|
|
190
|
+
readonly perBlock: number;
|
|
191
|
+
readonly perHour: number;
|
|
192
|
+
readonly perMonth: number;
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Get a formatted summary of all pricing information
|
|
196
|
+
*
|
|
197
|
+
* Useful for logging or debugging. Returns a plain object with all computed prices.
|
|
198
|
+
*
|
|
199
|
+
* @returns Complete pricing breakdown
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* console.log(leasePrice.toJSON());
|
|
204
|
+
* // {
|
|
205
|
+
* // perBlock: { denom: 'uakt', amount: '1234' },
|
|
206
|
+
* // uakt: { perBlock: 1234, perHour: 729234, perMonth: 522456789 },
|
|
207
|
+
* // akt: { perBlock: 0.001234, perHour: 0.729234, perMonth: 522.456789 }
|
|
208
|
+
* // }
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
toJSON(): {
|
|
212
|
+
perBlock: {
|
|
213
|
+
readonly denom: string;
|
|
214
|
+
readonly amount: string;
|
|
215
|
+
};
|
|
216
|
+
uakt: {
|
|
217
|
+
/** Price in uAKT per block (same as perBlock.amount, but as number) */
|
|
218
|
+
readonly perBlock: number;
|
|
219
|
+
/** Price in uAKT per hour */
|
|
220
|
+
readonly perHour: number;
|
|
221
|
+
/** Price in uAKT per month (30.437 days) */
|
|
222
|
+
readonly perMonth: number;
|
|
223
|
+
};
|
|
224
|
+
akt: {
|
|
225
|
+
/** Price in AKT per block */
|
|
226
|
+
readonly perBlock: number;
|
|
227
|
+
/** Price in AKT per hour */
|
|
228
|
+
readonly perHour: number;
|
|
229
|
+
/** Price in AKT per month */
|
|
230
|
+
readonly perMonth: number;
|
|
231
|
+
};
|
|
232
|
+
};
|
|
233
|
+
/**
|
|
234
|
+
* Create LeasePrice from uAKT amount (convenience method)
|
|
235
|
+
*
|
|
236
|
+
* @param amountUakt - Price per block in uAKT
|
|
237
|
+
* @returns New LeasePrice instance
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* const price = LeasePrice.fromUakt(1234);
|
|
242
|
+
* // Equivalent to: new LeasePrice({ denom: 'uakt', amount: '1234' })
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
static fromUakt(amountUakt: number): LeasePrice;
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=pricing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pricing.d.ts","sourceRoot":"","sources":["../../../src/targets/akash/pricing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,0BAA0B,QAAQ,CAAC;AAEhD;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,SAAS,CAAC;AAE5C;;GAEG;AACH,eAAO,MAAM,YAAY,UAAY,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,qBAAa,UAAU;IACrB;;;;OAIG;IACH,SAAgB,QAAQ,EAAE;QACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;KACzB,CAAC;IAEF;;;;OAIG;IACH,SAAgB,IAAI,EAAE;QACpB,uEAAuE;QACvE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC1B,6BAA6B;QAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QACzB,4CAA4C;QAC5C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;KAC3B,CAAC;IAEF;;;;OAIG;IACH,SAAgB,GAAG,EAAE;QACnB,6BAA6B;QAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC1B,4BAA4B;QAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QACzB,6BAA6B;QAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;KAC3B,CAAC;IAEF;;;;;;;;;;;;;;OAcG;gBACS,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;IAkCpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,KAAK,CAAC,WAAW,EAAE,MAAM,GAAG;QAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;KAC3B;IASD;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM;;4BAjJY,MAAM;6BACL,MAAM;;;YASvB,uEAAuE;+BACpD,MAAM;YACzB,6BAA6B;8BACX,MAAM;YACxB,4CAA4C;+BACzB,MAAM;;;YASzB,6BAA6B;+BACV,MAAM;YACzB,4BAA4B;8BACV,MAAM;YACxB,6BAA6B;+BACV,MAAM;;;IA4H3B;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU;CAMhD"}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Akash Lease Pricing Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides accurate price calculations for Akash Network deployments using the same
|
|
5
|
+
* formulas as Akash Console. Supports multiple price formats (per block, per hour,
|
|
6
|
+
* per month) and USD conversion.
|
|
7
|
+
*
|
|
8
|
+
* **Price Calculation Background:**
|
|
9
|
+
*
|
|
10
|
+
* Akash leases are priced per block on the blockchain. The raw price from the
|
|
11
|
+
* blockchain is in uAKT (micro AKT, where 1 AKT = 1,000,000 uAKT) per block.
|
|
12
|
+
*
|
|
13
|
+
* To make this human-readable, we calculate:
|
|
14
|
+
* - Price per hour: Based on average blocks per hour
|
|
15
|
+
* - Price per month: Based on average blocks per month
|
|
16
|
+
* - Price in USD: Requires current AKT market price
|
|
17
|
+
*
|
|
18
|
+
* **Constants (from Akash Console):**
|
|
19
|
+
* - Average block time: 6.098 seconds
|
|
20
|
+
* - Average days in month: 30.437 days (365.25 / 12)
|
|
21
|
+
*
|
|
22
|
+
* @module targets/akash/pricing
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Average time between blocks on Akash Network (in seconds)
|
|
26
|
+
*
|
|
27
|
+
* This value is determined empirically by observing actual block times.
|
|
28
|
+
* Akash Console uses 6.098 seconds as the average.
|
|
29
|
+
*
|
|
30
|
+
* @see https://github.com/akash-network/console
|
|
31
|
+
*/
|
|
32
|
+
export const AVERAGE_BLOCK_TIME_SECONDS = 6.098;
|
|
33
|
+
/**
|
|
34
|
+
* Average number of days in a month (365.25 / 12)
|
|
35
|
+
*
|
|
36
|
+
* Using the astronomical year (365.25 days) divided by 12 months
|
|
37
|
+
* provides accurate monthly cost estimates.
|
|
38
|
+
*/
|
|
39
|
+
export const AVERAGE_DAYS_IN_MONTH = 30.437;
|
|
40
|
+
/**
|
|
41
|
+
* Conversion factor: 1 AKT = 1,000,000 uAKT
|
|
42
|
+
*/
|
|
43
|
+
export const UAKT_PER_AKT = 1_000_000;
|
|
44
|
+
/**
|
|
45
|
+
* Lease price information with multiple time periods and currencies
|
|
46
|
+
*
|
|
47
|
+
* This class encapsulates all pricing information for an Akash lease and provides
|
|
48
|
+
* methods to convert between different formats (per block, per hour, per month)
|
|
49
|
+
* and currencies (uAKT, AKT, USD).
|
|
50
|
+
*
|
|
51
|
+
* **Usage Philosophy:**
|
|
52
|
+
*
|
|
53
|
+
* The blockchain provides raw price per block in uAKT. This class:
|
|
54
|
+
* 1. Stores the raw value (immutable)
|
|
55
|
+
* 2. Pre-computes common formats (per hour, per month)
|
|
56
|
+
* 3. Provides USD conversion only when caller provides AKT price
|
|
57
|
+
*
|
|
58
|
+
* This design keeps deploy-ability pure (no external API dependencies) while
|
|
59
|
+
* giving callers maximum flexibility in displaying prices.
|
|
60
|
+
*
|
|
61
|
+
* @example Basic usage - uAKT prices
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const price = new LeasePrice({ denom: 'uakt', amount: '1234' });
|
|
64
|
+
*
|
|
65
|
+
* console.log(price.uakt.perBlock); // 1234
|
|
66
|
+
* console.log(price.uakt.perHour); // ~720,000
|
|
67
|
+
* console.log(price.uakt.perMonth); // ~522,000,000
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @example USD conversion
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const price = new LeasePrice({ denom: 'uakt', amount: '1234' });
|
|
73
|
+
*
|
|
74
|
+
* // Fetch current AKT price from your preferred source
|
|
75
|
+
* const aktPrice = 0.50; // $0.50 per AKT
|
|
76
|
+
*
|
|
77
|
+
* const usd = price.toUSD(aktPrice);
|
|
78
|
+
* console.log(`$${usd.perMonth.toFixed(2)}/month`); // "$0.26/month"
|
|
79
|
+
* console.log(`$${usd.perHour.toFixed(4)}/hour`); // "$0.0004/hour"
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @example Displaying in kadi-deploy CLI
|
|
83
|
+
* ```typescript
|
|
84
|
+
* const result = await deployToAkash({ ... });
|
|
85
|
+
*
|
|
86
|
+
* if (result.success) {
|
|
87
|
+
* const { leasePrice } = result.data;
|
|
88
|
+
*
|
|
89
|
+
* // Fetch AKT price
|
|
90
|
+
* const aktPrice = await fetchAktPriceFromCoinGecko();
|
|
91
|
+
* const usd = leasePrice.toUSD(aktPrice);
|
|
92
|
+
*
|
|
93
|
+
* logger.log('Lease Pricing:');
|
|
94
|
+
* logger.log(` ${leasePrice.uakt.perMonth} uAKT/month ($${usd.perMonth.toFixed(2)}/month)`);
|
|
95
|
+
* logger.log(` ${leasePrice.uakt.perHour} uAKT/hour ($${usd.perHour.toFixed(4)}/hour)`);
|
|
96
|
+
* logger.log(` ${leasePrice.perBlock.amount} uAKT/block ($${usd.perBlock.toFixed(6)}/block)`);
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export class LeasePrice {
|
|
101
|
+
/**
|
|
102
|
+
* Raw price from blockchain (per block)
|
|
103
|
+
*
|
|
104
|
+
* This is the authoritative source - all other prices are computed from this.
|
|
105
|
+
*/
|
|
106
|
+
perBlock;
|
|
107
|
+
/**
|
|
108
|
+
* Pre-computed prices in uAKT for different time periods
|
|
109
|
+
*
|
|
110
|
+
* All values are in micro AKT (uAKT). To convert to AKT, divide by 1,000,000.
|
|
111
|
+
*/
|
|
112
|
+
uakt;
|
|
113
|
+
/**
|
|
114
|
+
* Pre-computed prices in AKT (1 AKT = 1,000,000 uAKT)
|
|
115
|
+
*
|
|
116
|
+
* Convenient for display without manual conversion.
|
|
117
|
+
*/
|
|
118
|
+
akt;
|
|
119
|
+
/**
|
|
120
|
+
* Create a LeasePrice instance from blockchain price data
|
|
121
|
+
*
|
|
122
|
+
* @param price - Price object from blockchain query
|
|
123
|
+
* @param price.denom - Denomination (typically "uakt")
|
|
124
|
+
* @param price.amount - Amount per block as string
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* const price = new LeasePrice({
|
|
129
|
+
* denom: 'uakt',
|
|
130
|
+
* amount: '1234'
|
|
131
|
+
* });
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
constructor(price) {
|
|
135
|
+
// Store raw blockchain price
|
|
136
|
+
this.perBlock = {
|
|
137
|
+
denom: price.denom,
|
|
138
|
+
amount: price.amount,
|
|
139
|
+
};
|
|
140
|
+
// Parse amount to number for calculations
|
|
141
|
+
const pricePerBlock = parseFloat(price.amount);
|
|
142
|
+
// Calculate blocks per hour
|
|
143
|
+
// 60 seconds/minute * 60 minutes/hour / 6.098 seconds/block = ~590.8 blocks/hour
|
|
144
|
+
const blocksPerHour = (60 * 60) / AVERAGE_BLOCK_TIME_SECONDS;
|
|
145
|
+
// Calculate blocks per month
|
|
146
|
+
// 30.437 days/month * 24 hours/day * 60 minutes/hour * 60 seconds/minute / 6.098 seconds/block
|
|
147
|
+
const blocksPerMonth = (AVERAGE_DAYS_IN_MONTH * 24 * 60 * 60) / AVERAGE_BLOCK_TIME_SECONDS;
|
|
148
|
+
// Pre-compute uAKT prices
|
|
149
|
+
this.uakt = {
|
|
150
|
+
perBlock: pricePerBlock,
|
|
151
|
+
perHour: pricePerBlock * blocksPerHour,
|
|
152
|
+
perMonth: pricePerBlock * blocksPerMonth,
|
|
153
|
+
};
|
|
154
|
+
// Pre-compute AKT prices (divide uAKT by 1,000,000)
|
|
155
|
+
this.akt = {
|
|
156
|
+
perBlock: pricePerBlock / UAKT_PER_AKT,
|
|
157
|
+
perHour: this.uakt.perHour / UAKT_PER_AKT,
|
|
158
|
+
perMonth: this.uakt.perMonth / UAKT_PER_AKT,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Convert prices to USD using current AKT market price
|
|
163
|
+
*
|
|
164
|
+
* **Important:** This method requires you to provide the current AKT price.
|
|
165
|
+
* deploy-ability does not fetch market data to remain pure and dependency-free.
|
|
166
|
+
*
|
|
167
|
+
* **Where to get AKT price:**
|
|
168
|
+
* - CoinGecko API: https://api.coingecko.com/api/v3/simple/price?ids=akash-network&vs_currencies=usd
|
|
169
|
+
* - Your own price oracle
|
|
170
|
+
* - Akash Console API (if available)
|
|
171
|
+
* - Cached/hardcoded value for estimates
|
|
172
|
+
*
|
|
173
|
+
* @param aktPriceUSD - Current price of 1 AKT in USD
|
|
174
|
+
* @returns Prices in USD for different time periods
|
|
175
|
+
*
|
|
176
|
+
* @example Fetch from CoinGecko
|
|
177
|
+
* ```typescript
|
|
178
|
+
* const aktPrice = await fetch(
|
|
179
|
+
* 'https://api.coingecko.com/api/v3/simple/price?ids=akash-network&vs_currencies=usd'
|
|
180
|
+
* )
|
|
181
|
+
* .then(r => r.json())
|
|
182
|
+
* .then(data => data['akash-network'].usd);
|
|
183
|
+
*
|
|
184
|
+
* const usdPricing = leasePrice.toUSD(aktPrice);
|
|
185
|
+
* console.log(`Cost: $${usdPricing.perMonth.toFixed(2)}/month`);
|
|
186
|
+
* ```
|
|
187
|
+
*
|
|
188
|
+
* @example Use hardcoded estimate
|
|
189
|
+
* ```typescript
|
|
190
|
+
* // For quick estimates (update periodically)
|
|
191
|
+
* const aktPrice = 0.50; // $0.50 per AKT
|
|
192
|
+
* const usdPricing = leasePrice.toUSD(aktPrice);
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
toUSD(aktPriceUSD) {
|
|
196
|
+
// Convert AKT prices to USD by multiplying by AKT price
|
|
197
|
+
return {
|
|
198
|
+
perBlock: this.akt.perBlock * aktPriceUSD,
|
|
199
|
+
perHour: this.akt.perHour * aktPriceUSD,
|
|
200
|
+
perMonth: this.akt.perMonth * aktPriceUSD,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Get a formatted summary of all pricing information
|
|
205
|
+
*
|
|
206
|
+
* Useful for logging or debugging. Returns a plain object with all computed prices.
|
|
207
|
+
*
|
|
208
|
+
* @returns Complete pricing breakdown
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```typescript
|
|
212
|
+
* console.log(leasePrice.toJSON());
|
|
213
|
+
* // {
|
|
214
|
+
* // perBlock: { denom: 'uakt', amount: '1234' },
|
|
215
|
+
* // uakt: { perBlock: 1234, perHour: 729234, perMonth: 522456789 },
|
|
216
|
+
* // akt: { perBlock: 0.001234, perHour: 0.729234, perMonth: 522.456789 }
|
|
217
|
+
* // }
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
toJSON() {
|
|
221
|
+
return {
|
|
222
|
+
perBlock: this.perBlock,
|
|
223
|
+
uakt: this.uakt,
|
|
224
|
+
akt: this.akt,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Create LeasePrice from uAKT amount (convenience method)
|
|
229
|
+
*
|
|
230
|
+
* @param amountUakt - Price per block in uAKT
|
|
231
|
+
* @returns New LeasePrice instance
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* const price = LeasePrice.fromUakt(1234);
|
|
236
|
+
* // Equivalent to: new LeasePrice({ denom: 'uakt', amount: '1234' })
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
239
|
+
static fromUakt(amountUakt) {
|
|
240
|
+
return new LeasePrice({
|
|
241
|
+
denom: 'uakt',
|
|
242
|
+
amount: String(amountUakt),
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
//# sourceMappingURL=pricing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pricing.js","sourceRoot":"","sources":["../../../src/targets/akash/pricing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,KAAK,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC;AAE5C;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,SAAS,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,MAAM,OAAO,UAAU;IACrB;;;;OAIG;IACa,QAAQ,CAGtB;IAEF;;;;OAIG;IACa,IAAI,CAOlB;IAEF;;;;OAIG;IACa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