@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,322 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bid Selection Helpers
|
|
3
|
+
*
|
|
4
|
+
* Provides pre-built selection strategies and filtering utilities for choosing
|
|
5
|
+
* providers based on different criteria. These functions can be used directly
|
|
6
|
+
* as bidSelectors in the deployment flow, or combined to create custom
|
|
7
|
+
* selection logic.
|
|
8
|
+
*
|
|
9
|
+
* **Selection Strategies:**
|
|
10
|
+
* - `selectCheapestBid` - Lowest price (perMonth basis)
|
|
11
|
+
* - `selectMostReliableBid` - Highest uptime percentage
|
|
12
|
+
* - `selectBalancedBid` - Weighted combination of price and reliability
|
|
13
|
+
*
|
|
14
|
+
* **Filtering:**
|
|
15
|
+
* - `filterBids` - Apply multiple criteria to narrow down options
|
|
16
|
+
*
|
|
17
|
+
* @module targets/akash/bid-selectors
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Select the cheapest bid based on monthly price
|
|
21
|
+
*
|
|
22
|
+
* Compares all bids and returns the one with the lowest cost per month.
|
|
23
|
+
* Useful when price is the primary concern and provider quality is
|
|
24
|
+
* less critical (e.g., development/testing deployments).
|
|
25
|
+
*
|
|
26
|
+
* **Note:** This only considers price, not provider reliability, location,
|
|
27
|
+
* or audit status. For production deployments, consider using `filterBids`
|
|
28
|
+
* first to ensure minimum quality standards, then select the cheapest
|
|
29
|
+
* from the filtered set.
|
|
30
|
+
*
|
|
31
|
+
* @param bids - Array of enhanced bids to choose from
|
|
32
|
+
* @returns The cheapest bid, or null if array is empty
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import { deployToAkash, selectCheapestBid } from 'deploy-ability/akash';
|
|
37
|
+
*
|
|
38
|
+
* const result = await deployToAkash({
|
|
39
|
+
* wallet,
|
|
40
|
+
* certificate,
|
|
41
|
+
* projectRoot: './',
|
|
42
|
+
* profile: 'dev',
|
|
43
|
+
* bidSelector: selectCheapestBid
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @example With quality filtering
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const result = await deployToAkash({
|
|
50
|
+
* wallet,
|
|
51
|
+
* certificate,
|
|
52
|
+
* projectRoot: './',
|
|
53
|
+
* profile: 'prod',
|
|
54
|
+
* bidSelector: (bids) => {
|
|
55
|
+
* // Only consider audited providers with good uptime
|
|
56
|
+
* const qualityBids = filterBids(bids, {
|
|
57
|
+
* requireAudited: true,
|
|
58
|
+
* minUptime: { value: 0.95, period: '7d' }
|
|
59
|
+
* });
|
|
60
|
+
* // Then pick cheapest among quality providers
|
|
61
|
+
* return selectCheapestBid(qualityBids);
|
|
62
|
+
* }
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export function selectCheapestBid(bids) {
|
|
67
|
+
if (bids.length === 0)
|
|
68
|
+
return null;
|
|
69
|
+
return bids.reduce((cheapest, current) => current.pricing.uakt.perMonth < cheapest.pricing.uakt.perMonth
|
|
70
|
+
? current
|
|
71
|
+
: cheapest);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Select the most reliable provider based on uptime
|
|
75
|
+
*
|
|
76
|
+
* Chooses the provider with the highest uptime percentage for the specified
|
|
77
|
+
* time period. Providers without reliability data are considered last.
|
|
78
|
+
*
|
|
79
|
+
* **Uptime Periods:**
|
|
80
|
+
* - `1d`: Last 24 hours (most recent, but limited sample)
|
|
81
|
+
* - `7d`: Last 7 days (good balance, recommended default)
|
|
82
|
+
* - `30d`: Last 30 days (long-term stability indicator)
|
|
83
|
+
*
|
|
84
|
+
* **Fallback Behavior:**
|
|
85
|
+
* If no providers have reliability data, returns the first bid from the
|
|
86
|
+
* original array (maintains deterministic behavior).
|
|
87
|
+
*
|
|
88
|
+
* @param bids - Array of enhanced bids to choose from
|
|
89
|
+
* @param period - Uptime period to evaluate (default: '7d')
|
|
90
|
+
* @returns The most reliable bid, or null if array is empty
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* import { deployToAkash, selectMostReliableBid } from 'deploy-ability/akash';
|
|
95
|
+
*
|
|
96
|
+
* const result = await deployToAkash({
|
|
97
|
+
* wallet,
|
|
98
|
+
* certificate,
|
|
99
|
+
* projectRoot: './',
|
|
100
|
+
* profile: 'production',
|
|
101
|
+
* bidSelector: selectMostReliableBid // Uses 7d default
|
|
102
|
+
* });
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* @example With custom period
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const result = await deployToAkash({
|
|
108
|
+
* wallet,
|
|
109
|
+
* certificate,
|
|
110
|
+
* projectRoot: './',
|
|
111
|
+
* profile: 'production',
|
|
112
|
+
* bidSelector: (bids) => selectMostReliableBid(bids, '30d')
|
|
113
|
+
* });
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
export function selectMostReliableBid(bids, period = '7d') {
|
|
117
|
+
if (bids.length === 0)
|
|
118
|
+
return null;
|
|
119
|
+
// Filter bids that have reliability data
|
|
120
|
+
const withReliability = bids.filter((bid) => bid.provider.reliability !== undefined);
|
|
121
|
+
// If no providers have reliability data, return first bid
|
|
122
|
+
if (withReliability.length === 0) {
|
|
123
|
+
return bids[0] ?? null;
|
|
124
|
+
}
|
|
125
|
+
// Determine uptime key based on period
|
|
126
|
+
const uptimeKey = `uptime${period}`;
|
|
127
|
+
// Find provider with highest uptime
|
|
128
|
+
return withReliability.reduce((best, current) => {
|
|
129
|
+
const bestUptime = best.provider.reliability[uptimeKey];
|
|
130
|
+
const currentUptime = current.provider.reliability[uptimeKey];
|
|
131
|
+
return currentUptime > bestUptime ? current : best;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Select bid using balanced scoring (price + reliability)
|
|
136
|
+
*
|
|
137
|
+
* Calculates a composite score for each bid based on normalized price
|
|
138
|
+
* and reliability metrics, then selects the highest-scoring option.
|
|
139
|
+
*
|
|
140
|
+
* **Scoring Methodology:**
|
|
141
|
+
* - Price score: Normalized 0-1 (lower price = higher score)
|
|
142
|
+
* - Reliability score: Uptime percentage (0-1)
|
|
143
|
+
* - Total score = (price score × price weight) + (reliability score × reliability weight)
|
|
144
|
+
*
|
|
145
|
+
* **Default Weights:**
|
|
146
|
+
* Equal balance (0.5 each) - adjust based on your priorities.
|
|
147
|
+
*
|
|
148
|
+
* **Use Cases:**
|
|
149
|
+
* - Production deployments where both cost and reliability matter
|
|
150
|
+
* - Finding "best value" providers (good balance of quality and price)
|
|
151
|
+
* - Avoiding both the cheapest-but-unreliable and expensive-but-reliable extremes
|
|
152
|
+
*
|
|
153
|
+
* @param bids - Array of enhanced bids to choose from
|
|
154
|
+
* @param weights - Scoring weights (default: equal balance)
|
|
155
|
+
* @param weights.price - Weight for price score (0-1)
|
|
156
|
+
* @param weights.reliability - Weight for reliability score (0-1)
|
|
157
|
+
* @returns The best balanced bid, or null if array is empty
|
|
158
|
+
*
|
|
159
|
+
* @example Equal balance (default)
|
|
160
|
+
* ```typescript
|
|
161
|
+
* import { deployToAkash, selectBalancedBid } from 'deploy-ability/akash';
|
|
162
|
+
*
|
|
163
|
+
* const result = await deployToAkash({
|
|
164
|
+
* wallet,
|
|
165
|
+
* certificate,
|
|
166
|
+
* projectRoot: './',
|
|
167
|
+
* profile: 'production',
|
|
168
|
+
* bidSelector: selectBalancedBid // 50/50 price/reliability
|
|
169
|
+
* });
|
|
170
|
+
* ```
|
|
171
|
+
*
|
|
172
|
+
* @example Prioritize reliability
|
|
173
|
+
* ```typescript
|
|
174
|
+
* const result = await deployToAkash({
|
|
175
|
+
* wallet,
|
|
176
|
+
* certificate,
|
|
177
|
+
* projectRoot: './',
|
|
178
|
+
* profile: 'critical-prod',
|
|
179
|
+
* bidSelector: (bids) => selectBalancedBid(bids, {
|
|
180
|
+
* price: 0.3,
|
|
181
|
+
* reliability: 0.7
|
|
182
|
+
* })
|
|
183
|
+
* });
|
|
184
|
+
* ```
|
|
185
|
+
*
|
|
186
|
+
* @example Prioritize cost
|
|
187
|
+
* ```typescript
|
|
188
|
+
* const result = await deployToAkash({
|
|
189
|
+
* wallet,
|
|
190
|
+
* certificate,
|
|
191
|
+
* projectRoot: './',
|
|
192
|
+
* profile: 'dev',
|
|
193
|
+
* bidSelector: (bids) => selectBalancedBid(bids, {
|
|
194
|
+
* price: 0.8,
|
|
195
|
+
* reliability: 0.2
|
|
196
|
+
* })
|
|
197
|
+
* });
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
export function selectBalancedBid(bids, weights = { price: 0.5, reliability: 0.5 }) {
|
|
201
|
+
if (bids.length === 0)
|
|
202
|
+
return null;
|
|
203
|
+
// Calculate price range for normalization
|
|
204
|
+
const prices = bids.map((bid) => bid.pricing.uakt.perMonth);
|
|
205
|
+
const minPrice = Math.min(...prices);
|
|
206
|
+
const maxPrice = Math.max(...prices);
|
|
207
|
+
const priceRange = maxPrice - minPrice;
|
|
208
|
+
// Calculate scores for each bid
|
|
209
|
+
const scored = bids.map((bid) => {
|
|
210
|
+
// Price score: 1.0 for cheapest, 0.0 for most expensive
|
|
211
|
+
// Handle case where all bids have same price
|
|
212
|
+
const priceScore = priceRange === 0
|
|
213
|
+
? 1.0
|
|
214
|
+
: 1.0 - (bid.pricing.uakt.perMonth - minPrice) / priceRange;
|
|
215
|
+
// Reliability score: uptime7d (0.0 to 1.0)
|
|
216
|
+
// Default to 0.5 if no reliability data available
|
|
217
|
+
const reliabilityScore = bid.provider.reliability?.uptime7d ?? 0.5;
|
|
218
|
+
// Weighted total score
|
|
219
|
+
const totalScore = priceScore * weights.price + reliabilityScore * weights.reliability;
|
|
220
|
+
return { bid, score: totalScore };
|
|
221
|
+
});
|
|
222
|
+
// Return bid with highest score
|
|
223
|
+
return scored.reduce((best, current) => current.score > best.score ? current : best).bid;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Filter bids by multiple criteria
|
|
227
|
+
*
|
|
228
|
+
* Apply various filters to narrow down bid options based on price,
|
|
229
|
+
* reliability, audit status, location, and provider status.
|
|
230
|
+
*
|
|
231
|
+
* **All criteria are optional** - only specify the ones you care about.
|
|
232
|
+
* Multiple criteria are combined with AND logic (all must match).
|
|
233
|
+
*
|
|
234
|
+
* **Filtering Philosophy:**
|
|
235
|
+
* Use this to establish minimum quality standards, then apply a selection
|
|
236
|
+
* strategy to the filtered results. This ensures you never select a provider
|
|
237
|
+
* that doesn't meet your requirements, even if they're the cheapest.
|
|
238
|
+
*
|
|
239
|
+
* @param bids - Array of enhanced bids to filter
|
|
240
|
+
* @param criteria - Filtering criteria (all optional)
|
|
241
|
+
* @returns Filtered array of bids matching all specified criteria
|
|
242
|
+
*
|
|
243
|
+
* @example Filter by price and uptime
|
|
244
|
+
* ```typescript
|
|
245
|
+
* import { filterBids, selectCheapestBid } from 'deploy-ability/akash';
|
|
246
|
+
*
|
|
247
|
+
* const result = await deployToAkash({
|
|
248
|
+
* wallet,
|
|
249
|
+
* certificate,
|
|
250
|
+
* projectRoot: './',
|
|
251
|
+
* profile: 'prod',
|
|
252
|
+
* bidSelector: (bids) => {
|
|
253
|
+
* // Only providers under $50/month with >95% uptime
|
|
254
|
+
* const filtered = filterBids(bids, {
|
|
255
|
+
* maxPricePerMonth: { usd: 50, aktPrice: 0.45 },
|
|
256
|
+
* minUptime: { value: 0.95, period: '7d' }
|
|
257
|
+
* });
|
|
258
|
+
* return selectCheapestBid(filtered);
|
|
259
|
+
* }
|
|
260
|
+
* });
|
|
261
|
+
* ```
|
|
262
|
+
*
|
|
263
|
+
* @example Filter by audit status and location
|
|
264
|
+
* ```typescript
|
|
265
|
+
* const filtered = filterBids(bids, {
|
|
266
|
+
* requireAudited: true,
|
|
267
|
+
* preferredRegions: ['US', 'EU'], // Country codes
|
|
268
|
+
* requireOnline: true
|
|
269
|
+
* });
|
|
270
|
+
* ```
|
|
271
|
+
*
|
|
272
|
+
* @example Price filtering in uAKT
|
|
273
|
+
* ```typescript
|
|
274
|
+
* const filtered = filterBids(bids, {
|
|
275
|
+
* maxPricePerMonth: { uakt: 500_000_000 } // 500M uAKT/month
|
|
276
|
+
* });
|
|
277
|
+
* ```
|
|
278
|
+
*/
|
|
279
|
+
export function filterBids(bids, criteria) {
|
|
280
|
+
return bids.filter((bid) => {
|
|
281
|
+
// Price filter
|
|
282
|
+
if (criteria.maxPricePerMonth) {
|
|
283
|
+
const maxPrice = 'uakt' in criteria.maxPricePerMonth
|
|
284
|
+
? criteria.maxPricePerMonth.uakt
|
|
285
|
+
: bid.pricing.toUSD(criteria.maxPricePerMonth.aktPrice).perMonth;
|
|
286
|
+
const bidPrice = 'uakt' in criteria.maxPricePerMonth
|
|
287
|
+
? bid.pricing.uakt.perMonth
|
|
288
|
+
: bid.pricing.toUSD(criteria.maxPricePerMonth.aktPrice).perMonth;
|
|
289
|
+
if (bidPrice > maxPrice)
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
292
|
+
// Uptime filter
|
|
293
|
+
if (criteria.minUptime) {
|
|
294
|
+
const { value, period } = criteria.minUptime;
|
|
295
|
+
const uptimeKey = `uptime${period}`;
|
|
296
|
+
const uptime = bid.provider.reliability?.[uptimeKey];
|
|
297
|
+
// If no reliability data, exclude this bid
|
|
298
|
+
if (uptime === undefined || uptime < value)
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
// Audit status filter
|
|
302
|
+
if (criteria.requireAudited && !bid.provider.isAudited) {
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
// Region filter
|
|
306
|
+
if (criteria.preferredRegions && criteria.preferredRegions.length > 0) {
|
|
307
|
+
const countryCode = bid.provider.location?.countryCode;
|
|
308
|
+
if (!countryCode || !criteria.preferredRegions.includes(countryCode)) {
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
// Online status filter
|
|
313
|
+
if (criteria.requireOnline) {
|
|
314
|
+
const isOnline = bid.provider.reliability?.isOnline;
|
|
315
|
+
if (isOnline !== true)
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
// All filters passed
|
|
319
|
+
return true;
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
//# sourceMappingURL=bid-selectors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bid-selectors.js","sourceRoot":"","sources":["../../../src/targets/akash/bid-selectors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAG,GAAG,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,CAAC;YAErD,2CAA2C;YAC3C,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,GAAG,KAAK;gBAAE,OAAO,KAAK,CAAC;QAC3D,CAAC;QAED,sBAAsB;QACtB,IAAI,QAAQ,CAAC,cAAc,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;YACvD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,gBAAgB;QAChB,IAAI,QAAQ,CAAC,gBAAgB,IAAI,QAAQ,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtE,MAAM,WAAW,GAAG,GAAG,CAAC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;YACvD,IAAI,CAAC,WAAW,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;gBACrE,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QAED,uBAAuB;QACvB,IAAI,QAAQ,CAAC,aAAa,EAAE,CAAC;YAC3B,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC;YACpD,IAAI,QAAQ,KAAK,IAAI;gBAAE,OAAO,KAAK,CAAC;QACtC,CAAC;QAED,qBAAqB;QACrB,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bid Types and Pricing
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for enhanced provider bids including comprehensive pricing
|
|
5
|
+
* calculations across multiple time periods (hour, day, week, month) and
|
|
6
|
+
* currencies (uAKT, AKT, USD).
|
|
7
|
+
*
|
|
8
|
+
* @module targets/akash/bid-types
|
|
9
|
+
*/
|
|
10
|
+
import type { Bid as ProviderBid } from '@akashnetwork/akash-api/akash/market/v1beta4';
|
|
11
|
+
import type { ProviderInfo } from './provider-metadata.js';
|
|
12
|
+
/**
|
|
13
|
+
* Comprehensive bid pricing across multiple time periods and currencies
|
|
14
|
+
*
|
|
15
|
+
* Provides pre-calculated pricing for a lease in various formats to support
|
|
16
|
+
* different use cases and display preferences. All calculations are derived
|
|
17
|
+
* from the raw per-block price returned by the blockchain.
|
|
18
|
+
*
|
|
19
|
+
* **Price Calculation Background:**
|
|
20
|
+
*
|
|
21
|
+
* Akash leases are priced per block on the blockchain. The raw price from
|
|
22
|
+
* providers is in uAKT (micro AKT) per block. We calculate prices for
|
|
23
|
+
* different time periods using:
|
|
24
|
+
* - Blocks per hour = 3600 seconds/hour ÷ 6.098 seconds/block ≈ 590.8 blocks
|
|
25
|
+
* - Blocks per day = 24 hours × blocks per hour ≈ 14,179 blocks
|
|
26
|
+
* - Blocks per week = 7 days × blocks per day ≈ 99,254 blocks
|
|
27
|
+
* - Blocks per month = 30.437 days × blocks per day ≈ 431,572 blocks
|
|
28
|
+
*
|
|
29
|
+
* **USD Conversion:**
|
|
30
|
+
*
|
|
31
|
+
* USD prices require the current AKT market price, which must be provided
|
|
32
|
+
* by the caller via the `toUSD()` method. This keeps the library free from
|
|
33
|
+
* external API dependencies while allowing flexible price display.
|
|
34
|
+
*
|
|
35
|
+
* @example Display pricing in multiple formats
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const bid: EnhancedBid = // ... from queryBids
|
|
38
|
+
*
|
|
39
|
+
* // Display in uAKT
|
|
40
|
+
* console.log(`${bid.pricing.uakt.perMonth} uAKT/month`);
|
|
41
|
+
*
|
|
42
|
+
* // Display in AKT
|
|
43
|
+
* console.log(`${bid.pricing.akt.perMonth.toFixed(2)} AKT/month`);
|
|
44
|
+
*
|
|
45
|
+
* // Display in USD (requires AKT price)
|
|
46
|
+
* const aktPrice = 0.50; // $0.50 per AKT
|
|
47
|
+
* const usd = bid.pricing.toUSD(aktPrice);
|
|
48
|
+
* console.log(`$${usd.perMonth.toFixed(2)}/month`);
|
|
49
|
+
* console.log(`$${usd.perHour.toFixed(4)}/hour`);
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export interface BidPricing {
|
|
53
|
+
/**
|
|
54
|
+
* Raw price from blockchain (per block)
|
|
55
|
+
*
|
|
56
|
+
* This is the authoritative source - all other prices are computed from this.
|
|
57
|
+
*/
|
|
58
|
+
readonly raw: {
|
|
59
|
+
/** Denomination (typically "uakt") */
|
|
60
|
+
readonly denom: string;
|
|
61
|
+
/** Amount per block as string */
|
|
62
|
+
readonly amount: string;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Pre-computed prices in uAKT for different time periods
|
|
66
|
+
*
|
|
67
|
+
* All values are in micro AKT (uAKT). To convert to AKT, divide by 1,000,000.
|
|
68
|
+
*/
|
|
69
|
+
readonly uakt: {
|
|
70
|
+
/** Price in uAKT per block */
|
|
71
|
+
readonly perBlock: number;
|
|
72
|
+
/** Price in uAKT per hour (~590.8 blocks) */
|
|
73
|
+
readonly perHour: number;
|
|
74
|
+
/** Price in uAKT per day (~14,179 blocks) */
|
|
75
|
+
readonly perDay: number;
|
|
76
|
+
/** Price in uAKT per week (~99,254 blocks) */
|
|
77
|
+
readonly perWeek: number;
|
|
78
|
+
/** Price in uAKT per month (~431,572 blocks, 30.437 days) */
|
|
79
|
+
readonly perMonth: number;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Pre-computed prices in AKT (1 AKT = 1,000,000 uAKT)
|
|
83
|
+
*
|
|
84
|
+
* Convenient for display without manual conversion.
|
|
85
|
+
*/
|
|
86
|
+
readonly akt: {
|
|
87
|
+
/** Price in AKT per block */
|
|
88
|
+
readonly perBlock: number;
|
|
89
|
+
/** Price in AKT per hour */
|
|
90
|
+
readonly perHour: number;
|
|
91
|
+
/** Price in AKT per day */
|
|
92
|
+
readonly perDay: number;
|
|
93
|
+
/** Price in AKT per week */
|
|
94
|
+
readonly perWeek: number;
|
|
95
|
+
/** Price in AKT per month */
|
|
96
|
+
readonly perMonth: number;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Convert prices to USD using current AKT market price
|
|
100
|
+
*
|
|
101
|
+
* **Important:** This method requires you to provide the current AKT price.
|
|
102
|
+
* deploy-ability does not fetch market data to remain pure and dependency-free.
|
|
103
|
+
*
|
|
104
|
+
* **Where to get AKT price:**
|
|
105
|
+
* - CoinGecko API: https://api.coingecko.com/api/v3/simple/price?ids=akash-network&vs_currencies=usd
|
|
106
|
+
* - Your own price oracle
|
|
107
|
+
* - Akash Console API (if available)
|
|
108
|
+
* - Cached/hardcoded value for estimates
|
|
109
|
+
*
|
|
110
|
+
* @param aktPriceUSD - Current price of 1 AKT in USD
|
|
111
|
+
* @returns Prices in USD for different time periods
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* const aktPrice = 0.50; // $0.50 per AKT
|
|
116
|
+
* const usdPricing = bid.pricing.toUSD(aktPrice);
|
|
117
|
+
* console.log(`$${usdPricing.perMonth.toFixed(2)}/month`);
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
toUSD(aktPriceUSD: number): {
|
|
121
|
+
readonly perHour: number;
|
|
122
|
+
readonly perDay: number;
|
|
123
|
+
readonly perWeek: number;
|
|
124
|
+
readonly perMonth: number;
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Create BidPricing instance from blockchain price data
|
|
129
|
+
*
|
|
130
|
+
* Calculates all time-period prices from the raw per-block price.
|
|
131
|
+
*
|
|
132
|
+
* @param price - Price object from blockchain bid
|
|
133
|
+
* @param price.denom - Denomination (typically "uakt")
|
|
134
|
+
* @param price.amount - Amount per block as string
|
|
135
|
+
* @returns Complete pricing information across all time periods
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* const pricing = createBidPricing({
|
|
140
|
+
* denom: 'uakt',
|
|
141
|
+
* amount: '1234'
|
|
142
|
+
* });
|
|
143
|
+
* console.log(pricing.akt.perMonth); // Monthly cost in AKT
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
export declare function createBidPricing(price: {
|
|
147
|
+
denom: string;
|
|
148
|
+
amount: string;
|
|
149
|
+
}): BidPricing;
|
|
150
|
+
/**
|
|
151
|
+
* Enhanced provider bid with complete information
|
|
152
|
+
*
|
|
153
|
+
* Combines the raw blockchain bid data with enriched provider information
|
|
154
|
+
* and pre-calculated pricing. This is the primary type developers work with
|
|
155
|
+
* when selecting providers for their deployments.
|
|
156
|
+
*
|
|
157
|
+
* **Design Philosophy:**
|
|
158
|
+
*
|
|
159
|
+
* This type provides all the information needed to make an informed provider
|
|
160
|
+
* selection decision in a single, convenient package:
|
|
161
|
+
* - Provider identity and metadata
|
|
162
|
+
* - Location information for latency/compliance needs
|
|
163
|
+
* - Reliability metrics for quality assessment
|
|
164
|
+
* - Comprehensive pricing in multiple formats
|
|
165
|
+
* - Raw bid data for advanced use cases
|
|
166
|
+
*
|
|
167
|
+
* **Data Availability:**
|
|
168
|
+
*
|
|
169
|
+
* Not all fields will be populated for all providers:
|
|
170
|
+
* - New providers may not have reliability data yet
|
|
171
|
+
* - Some providers may not expose location information
|
|
172
|
+
* - Provider metadata (name, email, website) is optional
|
|
173
|
+
*
|
|
174
|
+
* Always check for undefined before using optional provider fields.
|
|
175
|
+
*
|
|
176
|
+
* @example Displaying bid information
|
|
177
|
+
* ```typescript
|
|
178
|
+
* function displayBid(bid: EnhancedBid, aktPrice: number): void {
|
|
179
|
+
* const usd = bid.pricing.toUSD(aktPrice);
|
|
180
|
+
*
|
|
181
|
+
* console.log(`
|
|
182
|
+
* Provider: ${bid.provider.name || 'Unknown'}
|
|
183
|
+
* Location: ${bid.provider.location?.country || 'Unknown'}
|
|
184
|
+
* Uptime (7d): ${bid.provider.reliability
|
|
185
|
+
* ? (bid.provider.reliability.uptime7d * 100).toFixed(1) + '%'
|
|
186
|
+
* : 'No data'}
|
|
187
|
+
* Price: $${usd.perMonth.toFixed(2)}/month
|
|
188
|
+
* Audited: ${bid.provider.isAudited ? 'Yes' : 'No'}
|
|
189
|
+
* `);
|
|
190
|
+
* }
|
|
191
|
+
* ```
|
|
192
|
+
*
|
|
193
|
+
* @example Filtering by criteria
|
|
194
|
+
* ```typescript
|
|
195
|
+
* function selectAffordableReliableBid(
|
|
196
|
+
* bids: EnhancedBid[],
|
|
197
|
+
* maxUsdPerMonth: number,
|
|
198
|
+
* aktPrice: number,
|
|
199
|
+
* minUptime: number
|
|
200
|
+
* ): EnhancedBid | null {
|
|
201
|
+
* const filtered = bids.filter(bid => {
|
|
202
|
+
* const usd = bid.pricing.toUSD(aktPrice);
|
|
203
|
+
* const uptime = bid.provider.reliability?.uptime7d ?? 0;
|
|
204
|
+
* return usd.perMonth <= maxUsdPerMonth && uptime >= minUptime;
|
|
205
|
+
* });
|
|
206
|
+
*
|
|
207
|
+
* return filtered[0] ?? null;
|
|
208
|
+
* }
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
export interface EnhancedBid {
|
|
212
|
+
/**
|
|
213
|
+
* Unique identifier for this bid
|
|
214
|
+
*
|
|
215
|
+
* Constructed from the bid coordinates (owner/dseq/gseq/oseq/provider).
|
|
216
|
+
* Useful for React keys, logging, and bid tracking.
|
|
217
|
+
*/
|
|
218
|
+
readonly id: string;
|
|
219
|
+
/**
|
|
220
|
+
* Raw bid data from Akash blockchain
|
|
221
|
+
*
|
|
222
|
+
* Contains the original protobuf bid object with all coordinates
|
|
223
|
+
* (bidId, price, state, etc.). Useful for advanced operations that
|
|
224
|
+
* need direct access to blockchain data.
|
|
225
|
+
*/
|
|
226
|
+
readonly bid: ProviderBid;
|
|
227
|
+
/**
|
|
228
|
+
* Complete provider information
|
|
229
|
+
*
|
|
230
|
+
* Includes identity, location, reliability metrics, and audit status.
|
|
231
|
+
* Some fields may be undefined for providers without complete metadata.
|
|
232
|
+
*/
|
|
233
|
+
readonly provider: ProviderInfo;
|
|
234
|
+
/**
|
|
235
|
+
* Pre-calculated pricing across all time periods
|
|
236
|
+
*
|
|
237
|
+
* Includes pricing in uAKT, AKT, and a method for USD conversion.
|
|
238
|
+
* Makes it easy to display prices in user-friendly formats.
|
|
239
|
+
*/
|
|
240
|
+
readonly pricing: BidPricing;
|
|
241
|
+
/**
|
|
242
|
+
* When this bid was created
|
|
243
|
+
*
|
|
244
|
+
* Timestamp when the provider submitted the bid to the blockchain.
|
|
245
|
+
* Useful for sorting by bid age or showing "time since bid" UI.
|
|
246
|
+
*/
|
|
247
|
+
readonly createdAt: Date;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Bid selection function signature
|
|
251
|
+
*
|
|
252
|
+
* A function that takes an array of enhanced bids and returns the selected bid
|
|
253
|
+
* (or null if none are acceptable). Can be synchronous or asynchronous to support
|
|
254
|
+
* different selection strategies:
|
|
255
|
+
*
|
|
256
|
+
* - **Synchronous**: Simple algorithmic selection (cheapest, most reliable, etc.)
|
|
257
|
+
* - **Asynchronous**: Interactive selection (user prompts, API calls, external validation)
|
|
258
|
+
*
|
|
259
|
+
* **Contract:**
|
|
260
|
+
* - Input: Array of at least one EnhancedBid
|
|
261
|
+
* - Output: Selected EnhancedBid or null if none are acceptable
|
|
262
|
+
* - Throws: Should not throw - return null instead for unacceptable bids
|
|
263
|
+
*
|
|
264
|
+
* **Return null when:**
|
|
265
|
+
* - No bids meet your criteria
|
|
266
|
+
* - User cancels selection (in interactive mode)
|
|
267
|
+
* - External validation fails
|
|
268
|
+
*
|
|
269
|
+
* @example Simple synchronous selector
|
|
270
|
+
* ```typescript
|
|
271
|
+
* const selectCheapest: BidSelector = (bids) => {
|
|
272
|
+
* if (bids.length === 0) return null;
|
|
273
|
+
* return bids.reduce((cheapest, current) =>
|
|
274
|
+
* current.pricing.uakt.perMonth < cheapest.pricing.uakt.perMonth
|
|
275
|
+
* ? current
|
|
276
|
+
* : cheapest
|
|
277
|
+
* );
|
|
278
|
+
* };
|
|
279
|
+
* ```
|
|
280
|
+
*
|
|
281
|
+
* @example Asynchronous interactive selector
|
|
282
|
+
* ```typescript
|
|
283
|
+
* const selectInteractive: BidSelector = async (bids) => {
|
|
284
|
+
* console.log('Available providers:');
|
|
285
|
+
* bids.forEach((bid, i) => {
|
|
286
|
+
* console.log(`${i + 1}. ${bid.provider.name} - ${bid.pricing.akt.perMonth} AKT/month`);
|
|
287
|
+
* });
|
|
288
|
+
*
|
|
289
|
+
* const choice = await promptUser('Select provider (1-' + bids.length + '): ');
|
|
290
|
+
* const index = parseInt(choice) - 1;
|
|
291
|
+
*
|
|
292
|
+
* return bids[index] ?? null;
|
|
293
|
+
* };
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
export type BidSelector = ((bids: EnhancedBid[]) => Promise<EnhancedBid | null>) | ((bids: EnhancedBid[]) => EnhancedBid | null);
|
|
297
|
+
//# sourceMappingURL=bid-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bid-types.d.ts","sourceRoot":"","sources":["../../../src/targets/akash/bid-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,8CAA8C,CAAC;AACvF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAyB3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,WAAW,UAAU;IACzB;;;;OAIG;IACH,QAAQ,CAAC,GAAG,EAAE;QACZ,sCAAsC;QACtC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,iCAAiC;QACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;KACzB,CAAC;IAEF;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE;QACb,8BAA8B;QAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC1B,6CAA6C;QAC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