@wharfkit/resources 1.0.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 +29 -0
- package/README.md +25 -0
- package/lib/eosio-resources.d.ts +191 -0
- package/lib/eosio-resources.js +552 -0
- package/lib/eosio-resources.js.map +1 -0
- package/lib/eosio-resources.m.js +532 -0
- package/lib/eosio-resources.m.js.map +1 -0
- package/lib/wharfkit-resources.d.ts +191 -0
- package/lib/wharfkit-resources.js +552 -0
- package/lib/wharfkit-resources.js.map +1 -0
- package/lib/wharfkit-resources.m.js +532 -0
- package/lib/wharfkit-resources.m.js.map +1 -0
- package/package.json +48 -0
- package/src/index.ts +87 -0
- package/src/powerup/abstract.ts +144 -0
- package/src/powerup/cpu.ts +76 -0
- package/src/powerup/net.ts +77 -0
- package/src/powerup/options.ts +9 -0
- package/src/powerup.ts +28 -0
- package/src/ram.ts +52 -0
- package/src/rex.ts +75 -0
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @wharfkit/resources v1.0.0
|
|
3
|
+
* https://github.com/wharfkit/resources
|
|
4
|
+
*
|
|
5
|
+
* @license
|
|
6
|
+
* Copyright (c) 2021 Greymass Inc. All Rights Reserved.
|
|
7
|
+
*
|
|
8
|
+
* Redistribution and use in source and binary forms, with or without modification,
|
|
9
|
+
* are permitted provided that the following conditions are met:
|
|
10
|
+
*
|
|
11
|
+
* 1. Redistribution of source code must retain the above copyright notice, this
|
|
12
|
+
* list of conditions and the following disclaimer.
|
|
13
|
+
*
|
|
14
|
+
* 2. Redistribution in binary form must reproduce the above copyright notice,
|
|
15
|
+
* this list of conditions and the following disclaimer in the documentation
|
|
16
|
+
* and/or other materials provided with the distribution.
|
|
17
|
+
*
|
|
18
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
19
|
+
* may be used to endorse or promote products derived from this software without
|
|
20
|
+
* specific prior written permission.
|
|
21
|
+
*
|
|
22
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
23
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
24
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
25
|
+
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
|
26
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
27
|
+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
28
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
29
|
+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
|
30
|
+
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
31
|
+
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
32
|
+
*
|
|
33
|
+
* YOU ACKNOWLEDGE THAT THIS SOFTWARE IS NOT DESIGNED, LICENSED OR INTENDED FOR USE
|
|
34
|
+
* IN THE DESIGN, CONSTRUCTION, OPERATION OR MAINTENANCE OF ANY MILITARY FACILITY.
|
|
35
|
+
*/
|
|
36
|
+
import { Struct, UInt64, UInt128, TimePointSec, Asset, APIClient, FetchProvider } from '@wharfkit/antelope';
|
|
37
|
+
import BN from 'bn.js';
|
|
38
|
+
import { __decorate } from 'tslib';
|
|
39
|
+
|
|
40
|
+
class PowerUpStateResource extends Struct {
|
|
41
|
+
constructor() {
|
|
42
|
+
super(...arguments);
|
|
43
|
+
this.default_block_cpu_limit = UInt64.from(200000);
|
|
44
|
+
this.default_block_net_limit = UInt64.from(1048576000);
|
|
45
|
+
}
|
|
46
|
+
// Get the current number of allocated units (shift from REX -> PowerUp)
|
|
47
|
+
get allocated() {
|
|
48
|
+
return 1 - Number(this.weight_ratio) / Number(this.target_weight_ratio) / 100;
|
|
49
|
+
}
|
|
50
|
+
// Get the current percentage of reserved units
|
|
51
|
+
get reserved() {
|
|
52
|
+
return Number(this.utilization) / Number(this.weight);
|
|
53
|
+
}
|
|
54
|
+
// Get the symbol definition for the token
|
|
55
|
+
get symbol() {
|
|
56
|
+
return this.min_price.symbol;
|
|
57
|
+
}
|
|
58
|
+
// Common casting for typed values to numbers
|
|
59
|
+
cast() {
|
|
60
|
+
return {
|
|
61
|
+
adjusted_utilization: Number(this.adjusted_utilization),
|
|
62
|
+
decay_secs: Number(this.decay_secs.value),
|
|
63
|
+
exponent: Number(this.exponent),
|
|
64
|
+
utilization: Number(this.utilization),
|
|
65
|
+
utilization_timestamp: Number(this.utilization_timestamp.value),
|
|
66
|
+
weight: Number(this.weight),
|
|
67
|
+
weight_ratio: Number(this.weight_ratio),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
// Mimic: https://github.com/EOSIO/eosio.contracts/blob/d7bc0a5cc8c0c2edd4dc61b0126517d0cb46fd94/contracts/eosio.system/src/powerup.cpp#L358
|
|
71
|
+
utilization_increase(sample, frac) {
|
|
72
|
+
const { weight } = this;
|
|
73
|
+
const frac128 = UInt128.from(frac);
|
|
74
|
+
const utilization_increase = new BN(weight.value.mul(new BN(frac128.value))) / Math.pow(10, 15);
|
|
75
|
+
return Math.ceil(utilization_increase);
|
|
76
|
+
}
|
|
77
|
+
// Mimic: https://github.com/EOSIO/eosio.contracts/blob/d7bc0a5cc8c0c2edd4dc61b0126517d0cb46fd94/contracts/eosio.system/src/powerup.cpp#L284-L298
|
|
78
|
+
price_function(utilization) {
|
|
79
|
+
const { exponent, weight } = this.cast();
|
|
80
|
+
const max_price = this.max_price.value;
|
|
81
|
+
const min_price = this.min_price.value;
|
|
82
|
+
let price = min_price;
|
|
83
|
+
const new_exponent = exponent - 1.0;
|
|
84
|
+
if (new_exponent <= 0.0) {
|
|
85
|
+
return max_price;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
price += (max_price - min_price) * Math.pow(utilization / weight, new_exponent);
|
|
89
|
+
}
|
|
90
|
+
return price;
|
|
91
|
+
}
|
|
92
|
+
// Mimic: https://github.com/EOSIO/eosio.contracts/blob/d7bc0a5cc8c0c2edd4dc61b0126517d0cb46fd94/contracts/eosio.system/src/powerup.cpp#L274-L280
|
|
93
|
+
price_integral_delta(start_utilization, end_utilization) {
|
|
94
|
+
const { exponent, weight } = this.cast();
|
|
95
|
+
const max_price = this.max_price.value;
|
|
96
|
+
const min_price = this.min_price.value;
|
|
97
|
+
const coefficient = (max_price - min_price) / exponent;
|
|
98
|
+
const start_u = start_utilization / weight;
|
|
99
|
+
const end_u = end_utilization / weight;
|
|
100
|
+
const delta = min_price * end_u -
|
|
101
|
+
min_price * start_u +
|
|
102
|
+
coefficient * Math.pow(end_u, exponent) -
|
|
103
|
+
coefficient * Math.pow(start_u, exponent);
|
|
104
|
+
return delta;
|
|
105
|
+
}
|
|
106
|
+
// Mimic: https://github.com/EOSIO/eosio.contracts/blob/d7bc0a5cc8c0c2edd4dc61b0126517d0cb46fd94/contracts/eosio.system/src/powerup.cpp#L262-L315
|
|
107
|
+
fee(utilization_increase, adjusted_utilization) {
|
|
108
|
+
const { utilization, weight } = this.cast();
|
|
109
|
+
let start_utilization = utilization;
|
|
110
|
+
const end_utilization = start_utilization + utilization_increase;
|
|
111
|
+
let fee = 0;
|
|
112
|
+
if (start_utilization < adjusted_utilization) {
|
|
113
|
+
fee +=
|
|
114
|
+
(this.price_function(adjusted_utilization) *
|
|
115
|
+
Math.min(utilization_increase, adjusted_utilization - start_utilization)) /
|
|
116
|
+
weight;
|
|
117
|
+
start_utilization = adjusted_utilization;
|
|
118
|
+
}
|
|
119
|
+
if (start_utilization < end_utilization) {
|
|
120
|
+
fee += this.price_integral_delta(start_utilization, end_utilization);
|
|
121
|
+
}
|
|
122
|
+
return fee;
|
|
123
|
+
}
|
|
124
|
+
// Mimic: https://github.com/EOSIO/eosio.contracts/blob/d7bc0a5cc8c0c2edd4dc61b0126517d0cb46fd94/contracts/eosio.system/src/powerup.cpp#L105-L117
|
|
125
|
+
determine_adjusted_utilization(options) {
|
|
126
|
+
// Casting EOSIO types to usable formats for JS calculations
|
|
127
|
+
const { decay_secs, utilization, utilization_timestamp } = this.cast();
|
|
128
|
+
let { adjusted_utilization } = this.cast();
|
|
129
|
+
// If utilization is less than adjusted, calculate real time value
|
|
130
|
+
if (utilization < adjusted_utilization) {
|
|
131
|
+
// Create now & adjust JS timestamp to match EOSIO timestamp values
|
|
132
|
+
const ts = options && options.timestamp ? options.timestamp : new Date();
|
|
133
|
+
const now = TimePointSec.from(ts).toMilliseconds() / 1000;
|
|
134
|
+
const diff = adjusted_utilization - utilization;
|
|
135
|
+
let delta = diff * Math.exp(-(now - utilization_timestamp) / decay_secs);
|
|
136
|
+
delta = Math.min(Math.max(delta, 0), diff); // Clamp the delta
|
|
137
|
+
adjusted_utilization = utilization + delta;
|
|
138
|
+
}
|
|
139
|
+
return adjusted_utilization;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
__decorate([
|
|
143
|
+
Struct.field('uint8')
|
|
144
|
+
], PowerUpStateResource.prototype, "version", void 0);
|
|
145
|
+
__decorate([
|
|
146
|
+
Struct.field('int64')
|
|
147
|
+
], PowerUpStateResource.prototype, "weight", void 0);
|
|
148
|
+
__decorate([
|
|
149
|
+
Struct.field('int64')
|
|
150
|
+
], PowerUpStateResource.prototype, "weight_ratio", void 0);
|
|
151
|
+
__decorate([
|
|
152
|
+
Struct.field('int64')
|
|
153
|
+
], PowerUpStateResource.prototype, "assumed_stake_weight", void 0);
|
|
154
|
+
__decorate([
|
|
155
|
+
Struct.field('int64')
|
|
156
|
+
], PowerUpStateResource.prototype, "initial_weight_ratio", void 0);
|
|
157
|
+
__decorate([
|
|
158
|
+
Struct.field('int64')
|
|
159
|
+
], PowerUpStateResource.prototype, "target_weight_ratio", void 0);
|
|
160
|
+
__decorate([
|
|
161
|
+
Struct.field('time_point_sec')
|
|
162
|
+
], PowerUpStateResource.prototype, "initial_timestamp", void 0);
|
|
163
|
+
__decorate([
|
|
164
|
+
Struct.field('time_point_sec')
|
|
165
|
+
], PowerUpStateResource.prototype, "target_timestamp", void 0);
|
|
166
|
+
__decorate([
|
|
167
|
+
Struct.field('float64')
|
|
168
|
+
], PowerUpStateResource.prototype, "exponent", void 0);
|
|
169
|
+
__decorate([
|
|
170
|
+
Struct.field('uint32')
|
|
171
|
+
], PowerUpStateResource.prototype, "decay_secs", void 0);
|
|
172
|
+
__decorate([
|
|
173
|
+
Struct.field('asset')
|
|
174
|
+
], PowerUpStateResource.prototype, "min_price", void 0);
|
|
175
|
+
__decorate([
|
|
176
|
+
Struct.field('asset')
|
|
177
|
+
], PowerUpStateResource.prototype, "max_price", void 0);
|
|
178
|
+
__decorate([
|
|
179
|
+
Struct.field('int64')
|
|
180
|
+
], PowerUpStateResource.prototype, "utilization", void 0);
|
|
181
|
+
__decorate([
|
|
182
|
+
Struct.field('int64')
|
|
183
|
+
], PowerUpStateResource.prototype, "adjusted_utilization", void 0);
|
|
184
|
+
__decorate([
|
|
185
|
+
Struct.field('time_point_sec')
|
|
186
|
+
], PowerUpStateResource.prototype, "utilization_timestamp", void 0);
|
|
187
|
+
|
|
188
|
+
let PowerUpStateResourceCPU = class PowerUpStateResourceCPU extends PowerUpStateResource {
|
|
189
|
+
constructor() {
|
|
190
|
+
super(...arguments);
|
|
191
|
+
// Return smallest units per day, μs (microseconds)
|
|
192
|
+
this.per_day = (options) => this.us_per_day(options);
|
|
193
|
+
// Default frac generation by smallest unit type
|
|
194
|
+
this.frac = (usage, us) => this.frac_by_us(usage, us);
|
|
195
|
+
// Frac generation by ms (milliseconds)
|
|
196
|
+
this.frac_by_ms = (usage, ms) => this.frac_by_us(usage, ms * 1000);
|
|
197
|
+
// Price generation by smallest units, μs (microseconds)
|
|
198
|
+
this.price_per = (usage, us = 1000, options) => this.price_per_us(usage, us, options);
|
|
199
|
+
// Price generation by ms (milliseconds)
|
|
200
|
+
this.price_per_ms = (usage, ms = 1, options) => this.price_per_us(usage, ms * 1000, options);
|
|
201
|
+
}
|
|
202
|
+
// Return ms (milliseconds) per day
|
|
203
|
+
ms_per_day(options) {
|
|
204
|
+
return this.us_per_day(options) / 1000;
|
|
205
|
+
}
|
|
206
|
+
// Return μs (microseconds) per day
|
|
207
|
+
us_per_day(options) {
|
|
208
|
+
const limit = options && options.virtual_block_cpu_limit
|
|
209
|
+
? options.virtual_block_cpu_limit
|
|
210
|
+
: this.default_block_cpu_limit;
|
|
211
|
+
return Number(limit) * 2 * 60 * 60 * 24;
|
|
212
|
+
}
|
|
213
|
+
// Convert weight to μs (microseconds)
|
|
214
|
+
weight_to_us(sample, weight) {
|
|
215
|
+
return Math.ceil((weight * Number(sample)) / BNPrecision);
|
|
216
|
+
}
|
|
217
|
+
// Convert μs (microseconds) to weight
|
|
218
|
+
us_to_weight(sample, us) {
|
|
219
|
+
return Math.floor((us / Number(sample)) * BNPrecision);
|
|
220
|
+
}
|
|
221
|
+
// Frac generation by μs (microseconds)
|
|
222
|
+
frac_by_us(usage, us) {
|
|
223
|
+
const { weight } = this.cast();
|
|
224
|
+
const frac = this.us_to_weight(usage.cpu, us) / weight;
|
|
225
|
+
return Math.floor(frac * Math.pow(10, 15));
|
|
226
|
+
}
|
|
227
|
+
// Price generation by μs (microseconds)
|
|
228
|
+
price_per_us(usage, us = 1000, options) {
|
|
229
|
+
// Determine the utilization increase by this action
|
|
230
|
+
const frac = UInt128.from(this.frac(usage, us));
|
|
231
|
+
const utilization_increase = this.utilization_increase(usage.cpu, frac);
|
|
232
|
+
// Determine the adjusted utilization if needed
|
|
233
|
+
const adjusted_utilization = this.determine_adjusted_utilization(options);
|
|
234
|
+
// Derive the fee from the increase and utilization
|
|
235
|
+
const fee = this.fee(utilization_increase, adjusted_utilization);
|
|
236
|
+
// Force the fee up to the next highest value of precision
|
|
237
|
+
const precision = Math.pow(10, 4);
|
|
238
|
+
const value = Math.ceil(fee * precision) / precision;
|
|
239
|
+
// Return the modified fee
|
|
240
|
+
return value;
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
PowerUpStateResourceCPU = __decorate([
|
|
244
|
+
Struct.type('powerupstateresourcecpu')
|
|
245
|
+
], PowerUpStateResourceCPU);
|
|
246
|
+
|
|
247
|
+
let PowerUpStateResourceNET = class PowerUpStateResourceNET extends PowerUpStateResource {
|
|
248
|
+
constructor() {
|
|
249
|
+
super(...arguments);
|
|
250
|
+
// Return smallest units per day, bytes
|
|
251
|
+
this.per_day = (options) => this.bytes_per_day(options);
|
|
252
|
+
// Default frac generation by smallest unit type
|
|
253
|
+
this.frac = (usage, bytes) => this.frac_by_bytes(usage, bytes);
|
|
254
|
+
// Frac generation by kb
|
|
255
|
+
this.frac_by_kb = (usage, kilobytes) => this.frac_by_bytes(usage, kilobytes * 1000);
|
|
256
|
+
// Price generation by smallest units, bytes
|
|
257
|
+
this.price_per = (usage, bytes = 1000, options) => this.price_per_byte(usage, bytes, options);
|
|
258
|
+
// Price generation by kb
|
|
259
|
+
this.price_per_kb = (usage, kilobytes = 1, options) => this.price_per_byte(usage, kilobytes * 1000, options);
|
|
260
|
+
}
|
|
261
|
+
// Return kb per day
|
|
262
|
+
kb_per_day(options) {
|
|
263
|
+
return this.bytes_per_day(options) / 1000;
|
|
264
|
+
}
|
|
265
|
+
// Return bytes per day
|
|
266
|
+
bytes_per_day(options) {
|
|
267
|
+
const limit = options && options.virtual_block_net_limit
|
|
268
|
+
? options.virtual_block_net_limit
|
|
269
|
+
: this.default_block_net_limit;
|
|
270
|
+
return Number(limit) * 2 * 60 * 60 * 24;
|
|
271
|
+
}
|
|
272
|
+
// Convert weight to bytes
|
|
273
|
+
weight_to_bytes(sample, weight) {
|
|
274
|
+
return Math.ceil((weight * Number(sample)) / BNPrecision);
|
|
275
|
+
}
|
|
276
|
+
// Convert bytes to weight
|
|
277
|
+
bytes_to_weight(sample, bytes) {
|
|
278
|
+
return Math.floor((bytes / Number(sample)) * BNPrecision);
|
|
279
|
+
}
|
|
280
|
+
// Frac generation by bytes
|
|
281
|
+
frac_by_bytes(usage, bytes) {
|
|
282
|
+
const { weight } = this.cast();
|
|
283
|
+
const frac = this.bytes_to_weight(usage.net, bytes) / weight;
|
|
284
|
+
return Math.floor(frac * Math.pow(10, 15));
|
|
285
|
+
}
|
|
286
|
+
// Price generation by bytes
|
|
287
|
+
price_per_byte(usage, bytes = 1000, options) {
|
|
288
|
+
// Determine the utilization increase by this action
|
|
289
|
+
const frac = UInt128.from(this.frac(usage, bytes));
|
|
290
|
+
const utilization_increase = this.utilization_increase(usage.net, frac);
|
|
291
|
+
// Determine the adjusted utilization if needed
|
|
292
|
+
const adjusted_utilization = this.determine_adjusted_utilization(options);
|
|
293
|
+
// Derive the fee from the increase and utilization
|
|
294
|
+
const fee = this.fee(utilization_increase, adjusted_utilization);
|
|
295
|
+
// Force the fee up to the next highest value of precision
|
|
296
|
+
const precision = Math.pow(10, 4);
|
|
297
|
+
const value = Math.ceil(fee * precision) / precision;
|
|
298
|
+
// Return the modified fee
|
|
299
|
+
return value;
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
PowerUpStateResourceNET = __decorate([
|
|
303
|
+
Struct.type('powerupstateresourcenet')
|
|
304
|
+
], PowerUpStateResourceNET);
|
|
305
|
+
|
|
306
|
+
let PowerUpState = class PowerUpState extends Struct {
|
|
307
|
+
};
|
|
308
|
+
__decorate([
|
|
309
|
+
Struct.field('uint8')
|
|
310
|
+
], PowerUpState.prototype, "version", void 0);
|
|
311
|
+
__decorate([
|
|
312
|
+
Struct.field(PowerUpStateResourceNET)
|
|
313
|
+
], PowerUpState.prototype, "net", void 0);
|
|
314
|
+
__decorate([
|
|
315
|
+
Struct.field(PowerUpStateResourceCPU)
|
|
316
|
+
], PowerUpState.prototype, "cpu", void 0);
|
|
317
|
+
__decorate([
|
|
318
|
+
Struct.field('uint32')
|
|
319
|
+
], PowerUpState.prototype, "powerup_days", void 0);
|
|
320
|
+
__decorate([
|
|
321
|
+
Struct.field('asset')
|
|
322
|
+
], PowerUpState.prototype, "min_powerup_fee", void 0);
|
|
323
|
+
PowerUpState = __decorate([
|
|
324
|
+
Struct.type('powerupstate')
|
|
325
|
+
], PowerUpState);
|
|
326
|
+
class PowerUpAPI {
|
|
327
|
+
constructor(parent) {
|
|
328
|
+
this.parent = parent;
|
|
329
|
+
}
|
|
330
|
+
async get_state() {
|
|
331
|
+
const response = await this.parent.api.v1.chain.get_table_rows({
|
|
332
|
+
code: 'eosio',
|
|
333
|
+
scope: '',
|
|
334
|
+
table: 'powup.state',
|
|
335
|
+
type: PowerUpState,
|
|
336
|
+
});
|
|
337
|
+
return response.rows[0];
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
let Connector = class Connector extends Struct {
|
|
342
|
+
};
|
|
343
|
+
__decorate([
|
|
344
|
+
Struct.field('asset')
|
|
345
|
+
], Connector.prototype, "balance", void 0);
|
|
346
|
+
__decorate([
|
|
347
|
+
Struct.field('float64')
|
|
348
|
+
], Connector.prototype, "weight", void 0);
|
|
349
|
+
Connector = __decorate([
|
|
350
|
+
Struct.type('connector')
|
|
351
|
+
], Connector);
|
|
352
|
+
let ExchangeState = class ExchangeState extends Struct {
|
|
353
|
+
};
|
|
354
|
+
__decorate([
|
|
355
|
+
Struct.field('asset')
|
|
356
|
+
], ExchangeState.prototype, "supply", void 0);
|
|
357
|
+
__decorate([
|
|
358
|
+
Struct.field(Connector)
|
|
359
|
+
], ExchangeState.prototype, "base", void 0);
|
|
360
|
+
__decorate([
|
|
361
|
+
Struct.field(Connector)
|
|
362
|
+
], ExchangeState.prototype, "quote", void 0);
|
|
363
|
+
ExchangeState = __decorate([
|
|
364
|
+
Struct.type('exchange_state')
|
|
365
|
+
], ExchangeState);
|
|
366
|
+
let RAMState = class RAMState extends ExchangeState {
|
|
367
|
+
price_per(bytes) {
|
|
368
|
+
const base = this.base.balance.units.toNumber();
|
|
369
|
+
const quote = this.quote.balance.value;
|
|
370
|
+
return this.get_input(base, quote, bytes);
|
|
371
|
+
}
|
|
372
|
+
price_per_kb(kilobytes) {
|
|
373
|
+
return this.price_per(kilobytes * 1000);
|
|
374
|
+
}
|
|
375
|
+
// Derived from https://github.com/EOSIO/eosio.contracts/blob/f6578c45c83ec60826e6a1eeb9ee71de85abe976/contracts/eosio.system/src/exchange_state.cpp#L96
|
|
376
|
+
get_input(base, quote, value) {
|
|
377
|
+
const result = (quote * value) / (base - value);
|
|
378
|
+
if (result < 0) {
|
|
379
|
+
return 0;
|
|
380
|
+
}
|
|
381
|
+
return result;
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
RAMState = __decorate([
|
|
385
|
+
Struct.type('ramstate')
|
|
386
|
+
], RAMState);
|
|
387
|
+
class RAMAPI {
|
|
388
|
+
constructor(parent) {
|
|
389
|
+
this.parent = parent;
|
|
390
|
+
}
|
|
391
|
+
async get_state() {
|
|
392
|
+
const response = await this.parent.api.v1.chain.get_table_rows({
|
|
393
|
+
code: 'eosio',
|
|
394
|
+
scope: 'eosio',
|
|
395
|
+
table: 'rammarket',
|
|
396
|
+
type: RAMState,
|
|
397
|
+
});
|
|
398
|
+
return response.rows[0];
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
let REXState = class REXState extends Struct {
|
|
403
|
+
get reserved() {
|
|
404
|
+
return Number(this.total_lent.units) / Number(this.total_lendable.units);
|
|
405
|
+
}
|
|
406
|
+
get symbol() {
|
|
407
|
+
return this.total_lent.symbol;
|
|
408
|
+
}
|
|
409
|
+
get precision() {
|
|
410
|
+
return this.total_lent.symbol.precision;
|
|
411
|
+
}
|
|
412
|
+
get value() {
|
|
413
|
+
return ((Number(this.total_lent.units) + Number(this.total_unlent.units)) /
|
|
414
|
+
Number(this.total_rex.units));
|
|
415
|
+
}
|
|
416
|
+
exchange(amount) {
|
|
417
|
+
return Asset.from((amount.value * this.total_lendable.value) / this.total_rex.value, this.symbol);
|
|
418
|
+
}
|
|
419
|
+
price_per(sample, unit = 1000) {
|
|
420
|
+
// Sample token units
|
|
421
|
+
const tokens = Asset.fromUnits(10000, this.symbol);
|
|
422
|
+
// Spending 1 EOS (10000 units) on REX gives this many tokens
|
|
423
|
+
const bancor = Number(tokens.units) / (this.total_rent.value / this.total_unlent.value);
|
|
424
|
+
// The ratio of the number of tokens received vs the sampled values
|
|
425
|
+
const unitPrice = bancor * (Number(sample.cpu) / BNPrecision);
|
|
426
|
+
// The token units spent per unit
|
|
427
|
+
const perunit = Number(tokens.units) / unitPrice;
|
|
428
|
+
// Multiply the per unit cost by the units requested
|
|
429
|
+
const cost = perunit * unit;
|
|
430
|
+
// Converting to an Asset
|
|
431
|
+
return cost / Math.pow(10, this.precision);
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
__decorate([
|
|
435
|
+
Struct.field('uint8')
|
|
436
|
+
], REXState.prototype, "version", void 0);
|
|
437
|
+
__decorate([
|
|
438
|
+
Struct.field('asset')
|
|
439
|
+
], REXState.prototype, "total_lent", void 0);
|
|
440
|
+
__decorate([
|
|
441
|
+
Struct.field('asset')
|
|
442
|
+
], REXState.prototype, "total_unlent", void 0);
|
|
443
|
+
__decorate([
|
|
444
|
+
Struct.field('asset')
|
|
445
|
+
], REXState.prototype, "total_rent", void 0);
|
|
446
|
+
__decorate([
|
|
447
|
+
Struct.field('asset')
|
|
448
|
+
], REXState.prototype, "total_lendable", void 0);
|
|
449
|
+
__decorate([
|
|
450
|
+
Struct.field('asset')
|
|
451
|
+
], REXState.prototype, "total_rex", void 0);
|
|
452
|
+
__decorate([
|
|
453
|
+
Struct.field('asset')
|
|
454
|
+
], REXState.prototype, "namebid_proceeds", void 0);
|
|
455
|
+
__decorate([
|
|
456
|
+
Struct.field('uint64')
|
|
457
|
+
], REXState.prototype, "loan_num", void 0);
|
|
458
|
+
REXState = __decorate([
|
|
459
|
+
Struct.type('rexstate')
|
|
460
|
+
], REXState);
|
|
461
|
+
class REXAPI {
|
|
462
|
+
constructor(parent) {
|
|
463
|
+
this.parent = parent;
|
|
464
|
+
}
|
|
465
|
+
async get_state() {
|
|
466
|
+
const response = await this.parent.api.v1.chain.get_table_rows({
|
|
467
|
+
code: 'eosio',
|
|
468
|
+
scope: 'eosio',
|
|
469
|
+
table: 'rexpool',
|
|
470
|
+
type: REXState,
|
|
471
|
+
});
|
|
472
|
+
return response.rows[0];
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
const BNPrecision = new BN(1000 * 1000);
|
|
477
|
+
class Resources {
|
|
478
|
+
constructor(options) {
|
|
479
|
+
// the account to use when sampling usage
|
|
480
|
+
this.sampleAccount = 'b1';
|
|
481
|
+
// token precision/symbol
|
|
482
|
+
this.symbol = '4,EOS';
|
|
483
|
+
this.v1 = {
|
|
484
|
+
powerup: new PowerUpAPI(this),
|
|
485
|
+
ram: new RAMAPI(this),
|
|
486
|
+
rex: new REXAPI(this),
|
|
487
|
+
};
|
|
488
|
+
// Allow overriding of the sample account name
|
|
489
|
+
if (options.sampleAccount) {
|
|
490
|
+
this.sampleAccount = options.sampleAccount;
|
|
491
|
+
}
|
|
492
|
+
// Allow overriding of the system token symbol
|
|
493
|
+
if (options.symbol) {
|
|
494
|
+
this.symbol = options.symbol;
|
|
495
|
+
}
|
|
496
|
+
// Allow variations on how to specify the API configuration
|
|
497
|
+
if (options.api) {
|
|
498
|
+
this.api = options.api;
|
|
499
|
+
}
|
|
500
|
+
else if (options.url) {
|
|
501
|
+
this.api = new APIClient({ provider: new FetchProvider(options.url, options) });
|
|
502
|
+
}
|
|
503
|
+
else {
|
|
504
|
+
throw new Error('Missing url or api client');
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
async getSampledUsage() {
|
|
508
|
+
const account = await this.api.v1.chain.get_account(this.sampleAccount);
|
|
509
|
+
const us = UInt128.from(account.cpu_limit.max.value.mul(BNPrecision));
|
|
510
|
+
const byte = UInt128.from(account.net_limit.max.value.mul(BNPrecision));
|
|
511
|
+
const cpu_weight = UInt128.from(account.cpu_weight.value);
|
|
512
|
+
const net_weight = UInt128.from(account.net_weight.value);
|
|
513
|
+
return {
|
|
514
|
+
account,
|
|
515
|
+
cpu: divCeil(us.value, cpu_weight.value),
|
|
516
|
+
net: divCeil(byte.value, net_weight.value),
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
Resources.__className = 'Resources';
|
|
521
|
+
function divCeil(num, den) {
|
|
522
|
+
let v = num.div(den);
|
|
523
|
+
const zero = new BN(0);
|
|
524
|
+
const one = new BN(1);
|
|
525
|
+
if (num.mod(den).gt(zero)) {
|
|
526
|
+
v = v.sub(one);
|
|
527
|
+
}
|
|
528
|
+
return UInt128.from(v);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
export { BNPrecision, Connector, ExchangeState, PowerUpAPI, PowerUpState, RAMAPI, RAMState, REXAPI, REXState, Resources };
|
|
532
|
+
//# sourceMappingURL=wharfkit-resources.m.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wharfkit-resources.m.js","sources":["../src/powerup/abstract.ts","../src/powerup/cpu.ts","../src/powerup/net.ts","../src/powerup.ts","../src/ram.ts","../src/rex.ts","../src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAesB,oBAAqB,SAAQ,MAAM;IAAzD;;QAiBa,4BAAuB,GAAW,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACrD,4BAAuB,GAAW,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;KA8GrE;;IAzGG,IAAW,SAAS;QAChB,OAAO,CAAC,GAAG,MAAM,CAAC,IA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E,CAAC,CAAC,CAAC,CAAA;IACrB,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE;QACvB,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;KACjB;IACD,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AAC1B;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wharfkit/resources",
|
|
3
|
+
"description": "Library to assist in Antelope-blockchain resource calculations.",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"homepage": "https://github.com/wharfkit/resources",
|
|
6
|
+
"license": "BSD-3-Clause",
|
|
7
|
+
"main": "lib/wharfkit-resources.js",
|
|
8
|
+
"module": "lib/wharfkit-resources.m.js",
|
|
9
|
+
"types": "lib/wharfkit-resources.d.ts",
|
|
10
|
+
"browser": {
|
|
11
|
+
"buffer": false,
|
|
12
|
+
"crypto": false
|
|
13
|
+
},
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"files": [
|
|
16
|
+
"lib/*",
|
|
17
|
+
"src/*"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"prepare": "make"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@wharfkit/antelope": "^0.7.3",
|
|
24
|
+
"bn.js": "^4.11.9",
|
|
25
|
+
"tslib": "^2.1.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@rollup/plugin-typescript": "^8.1.1",
|
|
29
|
+
"@types/mocha": "^8.0.3",
|
|
30
|
+
"@types/node": "^14.14.28",
|
|
31
|
+
"@typescript-eslint/eslint-plugin": "^4.15.1",
|
|
32
|
+
"@typescript-eslint/parser": "^4.15.1",
|
|
33
|
+
"assert": "^2.0.0",
|
|
34
|
+
"eslint": "^7.19.0",
|
|
35
|
+
"eslint-config-prettier": "^7.0.0",
|
|
36
|
+
"eslint-plugin-prettier": "^3.2.0",
|
|
37
|
+
"gh-pages": "^3.1.0",
|
|
38
|
+
"mocha": "^8.2.1",
|
|
39
|
+
"node-fetch": "^2.6.1",
|
|
40
|
+
"nyc": "^15.1.0",
|
|
41
|
+
"prettier": "^2.2.1",
|
|
42
|
+
"rollup": "^2.38.2",
|
|
43
|
+
"rollup-plugin-dts": "^2.0.0",
|
|
44
|
+
"ts-node": "^9.1.0",
|
|
45
|
+
"typedoc": "^0.20.25",
|
|
46
|
+
"typescript": "^4.1.2"
|
|
47
|
+
}
|
|
48
|
+
}
|