@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
package/LICENSE
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Copyright (c) 2021 Greymass Inc. All Rights Reserved.
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
4
|
+
are permitted provided that the following conditions are met:
|
|
5
|
+
|
|
6
|
+
1. Redistribution of source code must retain the above copyright notice, this
|
|
7
|
+
list of conditions and the following disclaimer.
|
|
8
|
+
|
|
9
|
+
2. Redistribution in binary form must reproduce the above copyright notice,
|
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
|
11
|
+
and/or other materials provided with the distribution.
|
|
12
|
+
|
|
13
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
|
14
|
+
may be used to endorse or promote products derived from this software without
|
|
15
|
+
specific prior written permission.
|
|
16
|
+
|
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
18
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
19
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
20
|
+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
|
21
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
22
|
+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
23
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
24
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
|
25
|
+
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
26
|
+
OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
|
+
|
|
28
|
+
YOU ACKNOWLEDGE THAT THIS SOFTWARE IS NOT DESIGNED, LICENSED OR INTENDED FOR USE
|
|
29
|
+
IN THE DESIGN, CONSTRUCTION, OPERATION OR MAINTENANCE OF ANY MILITARY FACILITY.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# eosio-resources
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
The `@wharfkit/resources` package is distributed on [npm](https://www.npmjs.com/package/@wharfkit/resources).
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
yarn add @wharfkit/resources
|
|
9
|
+
# or
|
|
10
|
+
npm install --save @wharfkit/resources
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
TODO
|
|
16
|
+
|
|
17
|
+
## Developing
|
|
18
|
+
|
|
19
|
+
You need [Make](https://www.gnu.org/software/make/), [node.js](https://nodejs.org/en/) and [yarn](https://classic.yarnpkg.com/en/docs/install) installed.
|
|
20
|
+
|
|
21
|
+
Clone the repository and run `make` to checkout all dependencies and build the project. See the [Makefile](./Makefile) for other useful targets. Before submitting a pull request make sure to run `make lint`.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
Made with ☕️ & ❤️ by [Greymass](https://greymass.com), if you find this useful please consider [supporting us](https://greymass.com/support-us).
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @greymass/eosio-resources v0.9.0
|
|
3
|
+
* https://github.com/greymass/eosio-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 { TimePointType, UInt64, Struct, UInt8, Int64, TimePointSec, Float64, UInt32, Asset, UInt128, API, APIClient, APIClientOptions } from '@greymass/eosio';
|
|
37
|
+
|
|
38
|
+
interface PowerUpStateOptions {
|
|
39
|
+
timestamp?: TimePointType;
|
|
40
|
+
virtual_block_cpu_limit?: UInt64;
|
|
41
|
+
virtual_block_net_limit?: UInt64;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
declare abstract class PowerUpStateResource extends Struct {
|
|
45
|
+
version: UInt8;
|
|
46
|
+
weight: Int64;
|
|
47
|
+
weight_ratio: Int64;
|
|
48
|
+
assumed_stake_weight: Int64;
|
|
49
|
+
initial_weight_ratio: Int64;
|
|
50
|
+
target_weight_ratio: Int64;
|
|
51
|
+
initial_timestamp: TimePointSec;
|
|
52
|
+
target_timestamp: TimePointSec;
|
|
53
|
+
exponent: Float64;
|
|
54
|
+
decay_secs: UInt32;
|
|
55
|
+
min_price: Asset;
|
|
56
|
+
max_price: Asset;
|
|
57
|
+
utilization: Int64;
|
|
58
|
+
adjusted_utilization: Int64;
|
|
59
|
+
utilization_timestamp: TimePointSec;
|
|
60
|
+
readonly default_block_cpu_limit: UInt64;
|
|
61
|
+
readonly default_block_net_limit: UInt64;
|
|
62
|
+
abstract per_day(options?: PowerUpStateOptions): number;
|
|
63
|
+
get allocated(): number;
|
|
64
|
+
get reserved(): number;
|
|
65
|
+
get symbol(): Asset.Symbol;
|
|
66
|
+
cast(): {
|
|
67
|
+
adjusted_utilization: number;
|
|
68
|
+
decay_secs: number;
|
|
69
|
+
exponent: number;
|
|
70
|
+
utilization: number;
|
|
71
|
+
utilization_timestamp: number;
|
|
72
|
+
weight: number;
|
|
73
|
+
weight_ratio: number;
|
|
74
|
+
};
|
|
75
|
+
utilization_increase(sample: UInt128, frac: any): number;
|
|
76
|
+
price_function(utilization: number): number;
|
|
77
|
+
price_integral_delta(start_utilization: number, end_utilization: number): number;
|
|
78
|
+
fee(utilization_increase: any, adjusted_utilization: any): number;
|
|
79
|
+
determine_adjusted_utilization(options?: PowerUpStateOptions): number;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
declare class PowerUpStateResourceCPU extends PowerUpStateResource {
|
|
83
|
+
per_day: (options?: PowerUpStateOptions | undefined) => number;
|
|
84
|
+
ms_per_day(options?: PowerUpStateOptions): number;
|
|
85
|
+
us_per_day(options?: PowerUpStateOptions): number;
|
|
86
|
+
weight_to_us(sample: UInt128, weight: number): number;
|
|
87
|
+
us_to_weight(sample: UInt128, us: number): number;
|
|
88
|
+
frac: (usage: SampleUsage, us: number) => number;
|
|
89
|
+
frac_by_ms: (usage: SampleUsage, ms: number) => number;
|
|
90
|
+
frac_by_us(usage: SampleUsage, us: number): number;
|
|
91
|
+
price_per: (usage: SampleUsage, us?: number, options?: PowerUpStateOptions | undefined) => number;
|
|
92
|
+
price_per_ms: (usage: SampleUsage, ms?: number, options?: PowerUpStateOptions | undefined) => number;
|
|
93
|
+
price_per_us(usage: SampleUsage, us?: number, options?: PowerUpStateOptions): number;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
declare class PowerUpStateResourceNET extends PowerUpStateResource {
|
|
97
|
+
per_day: (options?: PowerUpStateOptions | undefined) => number;
|
|
98
|
+
kb_per_day(options?: PowerUpStateOptions): number;
|
|
99
|
+
bytes_per_day(options?: PowerUpStateOptions): number;
|
|
100
|
+
weight_to_bytes(sample: UInt128, weight: number): number;
|
|
101
|
+
bytes_to_weight(sample: UInt128, bytes: number): number;
|
|
102
|
+
frac: (usage: SampleUsage, bytes: number) => number;
|
|
103
|
+
frac_by_kb: (usage: SampleUsage, kilobytes: number) => number;
|
|
104
|
+
frac_by_bytes(usage: SampleUsage, bytes: number): number;
|
|
105
|
+
price_per: (usage: SampleUsage, bytes?: number, options?: PowerUpStateOptions | undefined) => number;
|
|
106
|
+
price_per_kb: (usage: SampleUsage, kilobytes?: number, options?: PowerUpStateOptions | undefined) => number;
|
|
107
|
+
price_per_byte(usage: SampleUsage, bytes?: number, options?: PowerUpStateOptions): number;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
declare class PowerUpState extends Struct {
|
|
111
|
+
version: UInt8;
|
|
112
|
+
net: PowerUpStateResourceNET;
|
|
113
|
+
cpu: PowerUpStateResourceCPU;
|
|
114
|
+
powerup_days: UInt32;
|
|
115
|
+
min_powerup_fee: Asset;
|
|
116
|
+
}
|
|
117
|
+
declare class PowerUpAPI {
|
|
118
|
+
private parent;
|
|
119
|
+
constructor(parent: Resources);
|
|
120
|
+
get_state(): Promise<PowerUpState>;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
declare class Connector extends Struct {
|
|
124
|
+
balance: Asset;
|
|
125
|
+
weight: Float64;
|
|
126
|
+
}
|
|
127
|
+
declare class ExchangeState extends Struct {
|
|
128
|
+
supply: Asset;
|
|
129
|
+
base: Connector;
|
|
130
|
+
quote: Connector;
|
|
131
|
+
}
|
|
132
|
+
declare class RAMState extends ExchangeState {
|
|
133
|
+
price_per(bytes: number): number;
|
|
134
|
+
price_per_kb(kilobytes: number): number;
|
|
135
|
+
get_input(base: number, quote: number, value: number): number;
|
|
136
|
+
}
|
|
137
|
+
declare class RAMAPI {
|
|
138
|
+
private parent;
|
|
139
|
+
constructor(parent: Resources);
|
|
140
|
+
get_state(): Promise<RAMState>;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
declare class REXState extends Struct {
|
|
144
|
+
version: UInt8;
|
|
145
|
+
total_lent: Asset;
|
|
146
|
+
total_unlent: Asset;
|
|
147
|
+
total_rent: Asset;
|
|
148
|
+
total_lendable: Asset;
|
|
149
|
+
total_rex: Asset;
|
|
150
|
+
namebid_proceeds: Asset;
|
|
151
|
+
loan_num: UInt64;
|
|
152
|
+
get reserved(): number;
|
|
153
|
+
get symbol(): Asset.Symbol;
|
|
154
|
+
get precision(): number;
|
|
155
|
+
get value(): number;
|
|
156
|
+
exchange(amount: Asset): Asset;
|
|
157
|
+
price_per(sample: SampleUsage, unit?: number): number;
|
|
158
|
+
}
|
|
159
|
+
declare class REXAPI {
|
|
160
|
+
private parent;
|
|
161
|
+
constructor(parent: Resources);
|
|
162
|
+
get_state(): Promise<REXState>;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
interface ResourcesOptions extends APIClientOptions {
|
|
166
|
+
api?: APIClient;
|
|
167
|
+
sampleAccount?: string;
|
|
168
|
+
symbol?: string;
|
|
169
|
+
url?: string;
|
|
170
|
+
}
|
|
171
|
+
interface SampleUsage {
|
|
172
|
+
account: API.v1.AccountObject;
|
|
173
|
+
cpu: UInt128;
|
|
174
|
+
net: UInt128;
|
|
175
|
+
}
|
|
176
|
+
declare const BNPrecision: any;
|
|
177
|
+
declare class Resources {
|
|
178
|
+
static __className: string;
|
|
179
|
+
readonly api: APIClient;
|
|
180
|
+
sampleAccount: string;
|
|
181
|
+
symbol: string;
|
|
182
|
+
constructor(options: ResourcesOptions);
|
|
183
|
+
v1: {
|
|
184
|
+
powerup: PowerUpAPI;
|
|
185
|
+
ram: RAMAPI;
|
|
186
|
+
rex: REXAPI;
|
|
187
|
+
};
|
|
188
|
+
getSampledUsage(): Promise<SampleUsage>;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export { BNPrecision, Connector, ExchangeState, PowerUpAPI, PowerUpState, RAMAPI, RAMState, REXAPI, REXState, Resources, SampleUsage };
|