@super-protocol/sdk-js 0.6.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.
Files changed (132) hide show
  1. package/build/BlockchainConnector.d.ts +48 -0
  2. package/build/BlockchainConnector.js +259 -0
  3. package/build/TIIGenerator.d.ts +21 -0
  4. package/build/TIIGenerator.js +251 -0
  5. package/build/constants.d.ts +7 -0
  6. package/build/constants.js +10 -0
  7. package/build/contracts/ActiveOffersList.json +131 -0
  8. package/build/contracts/ActiveOrdersList.json +74 -0
  9. package/build/contracts/Marks.json +79 -0
  10. package/build/contracts/Offers.json +999 -0
  11. package/build/contracts/Orders.json +984 -0
  12. package/build/contracts/Providers.json +440 -0
  13. package/build/contracts/ProvidersOffers.json +254 -0
  14. package/build/contracts/Staking.json +323 -0
  15. package/build/contracts/Superpro.json +197 -0
  16. package/build/contracts/SuperproToken.json +356 -0
  17. package/build/crypto/Crypto.d.ts +37 -0
  18. package/build/crypto/Crypto.js +181 -0
  19. package/build/crypto/index.d.ts +2 -0
  20. package/build/crypto/index.js +7 -0
  21. package/build/crypto/nodejs/AES.d.ts +24 -0
  22. package/build/crypto/nodejs/AES.js +152 -0
  23. package/build/crypto/nodejs/ARIA.d.ts +24 -0
  24. package/build/crypto/nodejs/ARIA.js +151 -0
  25. package/build/crypto/nodejs/ECIES.d.ts +6 -0
  26. package/build/crypto/nodejs/ECIES.js +94 -0
  27. package/build/crypto/nodejs/NativeCrypto.d.ts +54 -0
  28. package/build/crypto/nodejs/NativeCrypto.js +214 -0
  29. package/build/crypto/nodejs/RSA-Hybrid.d.ts +15 -0
  30. package/build/crypto/nodejs/RSA-Hybrid.js +153 -0
  31. package/build/index.d.ts +65 -0
  32. package/build/index.js +117 -0
  33. package/build/logger.d.ts +4 -0
  34. package/build/logger.js +8 -0
  35. package/build/models/Ballot.d.ts +13 -0
  36. package/build/models/Ballot.js +76 -0
  37. package/build/models/Offer.d.ts +70 -0
  38. package/build/models/Offer.js +273 -0
  39. package/build/models/Order.d.ts +125 -0
  40. package/build/models/Order.js +540 -0
  41. package/build/models/Provider.d.ts +40 -0
  42. package/build/models/Provider.js +167 -0
  43. package/build/models/TCB.d.ts +80 -0
  44. package/build/models/TCB.js +315 -0
  45. package/build/models/TeeOffer.d.ts +118 -0
  46. package/build/models/TeeOffer.js +436 -0
  47. package/build/proto/Compression.d.ts +33 -0
  48. package/build/proto/Compression.js +146 -0
  49. package/build/proto/TRI.d.ts +122 -0
  50. package/build/proto/TRI.js +316 -0
  51. package/build/providers/storage/ChunksDownloadDecorator.d.ts +38 -0
  52. package/build/providers/storage/ChunksDownloadDecorator.js +284 -0
  53. package/build/providers/storage/IStorageProvider.d.ts +17 -0
  54. package/build/providers/storage/IStorageProvider.js +2 -0
  55. package/build/providers/storage/StorjStorageProvider.d.ts +26 -0
  56. package/build/providers/storage/StorjStorageProvider.js +389 -0
  57. package/build/providers/storage/getStorageProvider.d.ts +4 -0
  58. package/build/providers/storage/getStorageProvider.js +16 -0
  59. package/build/staticModels/ActiveOffers.d.ts +29 -0
  60. package/build/staticModels/ActiveOffers.js +144 -0
  61. package/build/staticModels/ActiveOrders.d.ts +21 -0
  62. package/build/staticModels/ActiveOrders.js +120 -0
  63. package/build/staticModels/Consensus.d.ts +63 -0
  64. package/build/staticModels/Consensus.js +373 -0
  65. package/build/staticModels/Epochs.d.ts +23 -0
  66. package/build/staticModels/Epochs.js +97 -0
  67. package/build/staticModels/LastBlocks.d.ts +25 -0
  68. package/build/staticModels/LastBlocks.js +96 -0
  69. package/build/staticModels/Marks.d.ts +13 -0
  70. package/build/staticModels/Marks.js +113 -0
  71. package/build/staticModels/OffersFactory.d.ts +37 -0
  72. package/build/staticModels/OffersFactory.js +227 -0
  73. package/build/staticModels/OrdersFactory.d.ts +137 -0
  74. package/build/staticModels/OrdersFactory.js +539 -0
  75. package/build/staticModels/ProviderRegistry.d.ts +81 -0
  76. package/build/staticModels/ProviderRegistry.js +311 -0
  77. package/build/staticModels/Staking.d.ts +26 -0
  78. package/build/staticModels/Staking.js +132 -0
  79. package/build/staticModels/Superpro.d.ts +20 -0
  80. package/build/staticModels/Superpro.js +99 -0
  81. package/build/staticModels/SuperproToken.d.ts +30 -0
  82. package/build/staticModels/SuperproToken.js +125 -0
  83. package/build/staticModels/Suspicious.d.ts +26 -0
  84. package/build/staticModels/Suspicious.js +99 -0
  85. package/build/staticModels/TeeOffersFactory.d.ts +36 -0
  86. package/build/staticModels/TeeOffersFactory.js +206 -0
  87. package/build/staticModels/Voting.d.ts +35 -0
  88. package/build/staticModels/Voting.js +111 -0
  89. package/build/store.d.ts +12 -0
  90. package/build/store.js +13 -0
  91. package/build/types/Ballot.d.ts +75 -0
  92. package/build/types/Ballot.js +49 -0
  93. package/build/types/Epoch.d.ts +21 -0
  94. package/build/types/Epoch.js +18 -0
  95. package/build/types/Events.d.ts +18 -0
  96. package/build/types/Events.js +2 -0
  97. package/build/types/Marks.d.ts +5 -0
  98. package/build/types/Marks.js +9 -0
  99. package/build/types/Offer.d.ts +63 -0
  100. package/build/types/Offer.js +41 -0
  101. package/build/types/Order.d.ts +61 -0
  102. package/build/types/Order.js +36 -0
  103. package/build/types/Origins.d.ts +12 -0
  104. package/build/types/Origins.js +10 -0
  105. package/build/types/Provider.d.ts +25 -0
  106. package/build/types/Provider.js +19 -0
  107. package/build/types/Staking.d.ts +27 -0
  108. package/build/types/Staking.js +22 -0
  109. package/build/types/Superpro.d.ts +24 -0
  110. package/build/types/Superpro.js +29 -0
  111. package/build/types/TcbData.d.ts +26 -0
  112. package/build/types/TcbData.js +21 -0
  113. package/build/types/TeeOffer.d.ts +22 -0
  114. package/build/types/TeeOffer.js +15 -0
  115. package/build/types/Web3.d.ts +26 -0
  116. package/build/types/Web3.js +2 -0
  117. package/build/types/blockchainConnector/StorageAccess.d.ts +8 -0
  118. package/build/types/blockchainConnector/StorageAccess.js +2 -0
  119. package/build/types/storage/StorageAccess.d.ts +6 -0
  120. package/build/types/storage/StorageAccess.js +2 -0
  121. package/build/types/storage/StorageFileAccess.d.ts +5 -0
  122. package/build/types/storage/StorageFileAccess.js +2 -0
  123. package/build/types/storage/StorageObject.d.ts +8 -0
  124. package/build/types/storage/StorageObject.js +2 -0
  125. package/build/utils/NonceTracker.d.ts +12 -0
  126. package/build/utils/NonceTracker.js +84 -0
  127. package/build/utils/TxManager.d.ts +21 -0
  128. package/build/utils/TxManager.js +159 -0
  129. package/build/utils.d.ts +38 -0
  130. package/build/utils.js +195 -0
  131. package/package.json +68 -0
  132. package/readme.md +40 -0
@@ -0,0 +1,311 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ var store_1 = __importDefault(require("../store"));
43
+ var logger_1 = __importDefault(require("../logger"));
44
+ var Providers_json_1 = __importDefault(require("../contracts/Providers.json"));
45
+ var ProvidersOffers_json_1 = __importDefault(require("../contracts/ProvidersOffers.json"));
46
+ var utils_1 = require("../utils");
47
+ var Provider_1 = require("../types/Provider");
48
+ var Superpro_1 = __importDefault(require("./Superpro"));
49
+ var TxManager_1 = __importDefault(require("../utils/TxManager"));
50
+ var ProviderRegistry = /** @class */ (function () {
51
+ function ProviderRegistry() {
52
+ }
53
+ /**
54
+ * Checks if contract has been initialized, if not - initialize contract
55
+ */
56
+ ProviderRegistry.checkInitProviders = function (transactionOptions) {
57
+ if (transactionOptions === null || transactionOptions === void 0 ? void 0 : transactionOptions.web3) {
58
+ (0, utils_1.checkIfInitialized)();
59
+ return new transactionOptions.web3.eth.Contract(Providers_json_1.default.abi, Superpro_1.default.address);
60
+ }
61
+ if (this.contract)
62
+ return this.contract;
63
+ (0, utils_1.checkIfInitialized)();
64
+ this.logger = logger_1.default.child({ className: "Providers" });
65
+ return (this.contract = new store_1.default.web3.eth.Contract(Providers_json_1.default.abi, Superpro_1.default.address));
66
+ };
67
+ ProviderRegistry.checkInitProvidersOffers = function (transactionOptions) {
68
+ if (transactionOptions === null || transactionOptions === void 0 ? void 0 : transactionOptions.web3) {
69
+ (0, utils_1.checkIfInitialized)();
70
+ return new transactionOptions.web3.eth.Contract(ProvidersOffers_json_1.default.abi, Superpro_1.default.address);
71
+ }
72
+ if (this.contract)
73
+ return this.contract;
74
+ (0, utils_1.checkIfInitialized)();
75
+ this.logger = logger_1.default.child({ className: "ProvidersOffers" });
76
+ return (this.contract = new store_1.default.web3.eth.Contract(ProvidersOffers_json_1.default.abi, Superpro_1.default.address));
77
+ };
78
+ /**
79
+ * Function for fetching list of all providers addresses
80
+ */
81
+ ProviderRegistry.getAllProviders = function () {
82
+ return __awaiter(this, void 0, void 0, function () {
83
+ var _a;
84
+ return __generator(this, function (_b) {
85
+ switch (_b.label) {
86
+ case 0:
87
+ this.checkInitProviders();
88
+ _a = this;
89
+ return [4 /*yield*/, this.contract.methods.getProvidersAuths().call()];
90
+ case 1:
91
+ _a.providers = _b.sent();
92
+ return [2 /*return*/, this.providers];
93
+ }
94
+ });
95
+ });
96
+ };
97
+ /**
98
+ * Fetch provider address by provider authority account
99
+ */
100
+ ProviderRegistry.get = function (providerAuthority) {
101
+ return __awaiter(this, void 0, void 0, function () {
102
+ return __generator(this, function (_a) {
103
+ return [2 /*return*/, providerAuthority];
104
+ });
105
+ });
106
+ };
107
+ /**
108
+ * Fetch provider security deposit by provider authority account
109
+ */
110
+ ProviderRegistry.getSecurityDeposit = function (providerAuthority) {
111
+ return __awaiter(this, void 0, void 0, function () {
112
+ return __generator(this, function (_a) {
113
+ switch (_a.label) {
114
+ case 0:
115
+ this.checkInitProviders();
116
+ return [4 /*yield*/, this.contract.methods.getProviderSecurityDeposit(providerAuthority).call()];
117
+ case 1: return [2 /*return*/, _a.sent()];
118
+ }
119
+ });
120
+ });
121
+ };
122
+ /**
123
+ * Reg new provider
124
+ * @param providerInfo - data of new provider
125
+ * @param transactionOptions - object what contains alternative action account or gas limit (optional)
126
+ */
127
+ ProviderRegistry.registerProvider = function (providerInfo, externalId, transactionOptions) {
128
+ if (externalId === void 0) { externalId = "default"; }
129
+ return __awaiter(this, void 0, void 0, function () {
130
+ var contract, providerInfoParams;
131
+ return __generator(this, function (_a) {
132
+ switch (_a.label) {
133
+ case 0:
134
+ contract = this.checkInitProviders(transactionOptions);
135
+ (0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
136
+ providerInfoParams = (0, utils_1.objectToTuple)(providerInfo, Provider_1.ProviderInfoStructure);
137
+ return [4 /*yield*/, TxManager_1.default.execute(contract.methods.registerProvider, [providerInfoParams], transactionOptions)];
138
+ case 1:
139
+ _a.sent();
140
+ return [2 /*return*/];
141
+ }
142
+ });
143
+ });
144
+ };
145
+ /**
146
+ * Refills security deposit for provider
147
+ * Call this function with provider authority account (in transactionOptions)
148
+ * @param amount - amount of additional tokens
149
+ * @param transactionOptions - object what contains alternative action account or gas limit (optional)
150
+ */
151
+ ProviderRegistry.refillSecurityDeposit = function (amount, transactionOptions) {
152
+ return __awaiter(this, void 0, void 0, function () {
153
+ var contract;
154
+ return __generator(this, function (_a) {
155
+ switch (_a.label) {
156
+ case 0:
157
+ contract = this.checkInitProviders(transactionOptions);
158
+ (0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
159
+ return [4 /*yield*/, TxManager_1.default.execute(contract.methods.refillProviderSecurityDepo, [amount], transactionOptions)];
160
+ case 1:
161
+ _a.sent();
162
+ return [2 /*return*/];
163
+ }
164
+ });
165
+ });
166
+ };
167
+ /**
168
+ * Return security deposit for provider
169
+ * Call this function with provider authority account (in transactionOptions)
170
+ * @param amount - amount of tokens to return
171
+ * @param transactionOptions - object what contains alternative action account or gas limit (optional)
172
+ */
173
+ ProviderRegistry.returnSecurityDeposit = function (amount, transactionOptions) {
174
+ return __awaiter(this, void 0, void 0, function () {
175
+ var contract;
176
+ return __generator(this, function (_a) {
177
+ switch (_a.label) {
178
+ case 0:
179
+ contract = this.checkInitProviders(transactionOptions);
180
+ (0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
181
+ return [4 /*yield*/, TxManager_1.default.execute(contract.methods.returnProviderSecurityDepo, [amount], transactionOptions)];
182
+ case 1:
183
+ _a.sent();
184
+ return [2 /*return*/];
185
+ }
186
+ });
187
+ });
188
+ };
189
+ /**
190
+ * Function for adding event listeners on provider registered event in provider registry
191
+ * @param callback - function for processing new provider
192
+ * @return unsubscribe - unsubscribe function from event
193
+ */
194
+ ProviderRegistry.onProviderRegistered = function (callback) {
195
+ var _this = this;
196
+ this.checkInitProviders();
197
+ var logger = this.logger.child({ method: "onProviderRegistered" });
198
+ var subscription = this.contract.events
199
+ .ProviderRegistred()
200
+ .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
201
+ return __generator(this, function (_a) {
202
+ callback(event.returnValues.providerInfo);
203
+ return [2 /*return*/];
204
+ });
205
+ }); })
206
+ .on("error", function (error, receipt) {
207
+ if (receipt)
208
+ return; // Used to avoid logging of transaction rejected
209
+ logger.warn(error);
210
+ });
211
+ return function () { return subscription.unsubscribe(); };
212
+ };
213
+ /**
214
+ * Function for adding event listeners on provider modified event in provider registry
215
+ * @param callback - function for processing modified provider
216
+ * @returns unsubscribe - unsubscribe function from event
217
+ */
218
+ ProviderRegistry.onProviderModified = function (callback) {
219
+ var _this = this;
220
+ this.checkInitProviders();
221
+ var logger = this.logger.child({ method: "onProviderModified" });
222
+ var subscription = this.contract.events
223
+ .ProviderModified()
224
+ .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
225
+ return __generator(this, function (_a) {
226
+ callback(event.returnValues.auth);
227
+ return [2 /*return*/];
228
+ });
229
+ }); })
230
+ .on("error", function (error, receipt) {
231
+ if (receipt)
232
+ return; // Used to avoid logging of transaction rejected
233
+ logger.warn(error);
234
+ });
235
+ return function () { return subscription.unsubscribe(); };
236
+ };
237
+ /**
238
+ * Function for adding event listeners on provider violation rate incremented event in provider registry
239
+ * @param callback - function for processing new violation rate
240
+ * @returns unsubscribe - unsubscribe function from event
241
+ */
242
+ ProviderRegistry.onProviderViolationRateIncremented = function (callback) {
243
+ var _this = this;
244
+ this.checkInitProviders();
245
+ var logger = this.logger.child({ method: "onProviderViolationRateIncremented" });
246
+ var subscription = this.contract.events
247
+ .ProviderViolationRateIncremented()
248
+ .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
249
+ return __generator(this, function (_a) {
250
+ callback(event.returnValues.auth, event.returnValues.newViolationRate);
251
+ return [2 /*return*/];
252
+ });
253
+ }); })
254
+ .on("error", function (error, receipt) {
255
+ if (receipt)
256
+ return; // Used to avoid logging of transaction rejected
257
+ logger.warn(error);
258
+ });
259
+ return function () { return subscription.unsubscribe(); };
260
+ };
261
+ /**
262
+ * Function for adding event listeners on provider security deposit refilled event in provider registry
263
+ * @param callback - function for processing refilled security deposit
264
+ * @returns unsubscribe - unsubscribe function from event
265
+ */
266
+ ProviderRegistry.onProviderSecurityDepoRefilled = function (callback) {
267
+ var _this = this;
268
+ this.checkInitProviders();
269
+ var logger = this.logger.child({ method: "onProviderSecurityDepoRefilled" });
270
+ var subscription = this.contract.events
271
+ .ProviderSecurityDepoRefilled()
272
+ .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
273
+ return __generator(this, function (_a) {
274
+ callback(event.returnValues.auth, event.returnValues.amount);
275
+ return [2 /*return*/];
276
+ });
277
+ }); })
278
+ .on("error", function (error, receipt) {
279
+ if (receipt)
280
+ return; // Used to avoid logging of transaction rejected
281
+ logger.warn(error);
282
+ });
283
+ return function () { return subscription.unsubscribe(); };
284
+ };
285
+ /**
286
+ * Function for adding event listeners on provider security deposit unlocked event in provider registry
287
+ * @param callback - function for processing unlocked security deposit
288
+ * @returns unsubscribe - unsubscribe function from event
289
+ */
290
+ ProviderRegistry.onProviderSecurityDepoUnlocked = function (callback) {
291
+ var _this = this;
292
+ this.checkInitProviders();
293
+ var logger = this.logger.child({ method: "onProviderSecurityDepoUnlocked" });
294
+ var subscription = this.contract.events
295
+ .ProviderSecurityDepoUnlocked()
296
+ .on("data", function (event) { return __awaiter(_this, void 0, void 0, function () {
297
+ return __generator(this, function (_a) {
298
+ callback(event.returnValues.auth, event.returnValues.amount);
299
+ return [2 /*return*/];
300
+ });
301
+ }); })
302
+ .on("error", function (error, receipt) {
303
+ if (receipt)
304
+ return; // Used to avoid logging of transaction rejected
305
+ logger.warn(error);
306
+ });
307
+ return function () { return subscription.unsubscribe(); };
308
+ };
309
+ return ProviderRegistry;
310
+ }());
311
+ exports.default = ProviderRegistry;
@@ -0,0 +1,26 @@
1
+ import { LockInfo, StakeInfo, Purpose } from "../types/Staking";
2
+ import { TransactionOptions } from "../types/Web3";
3
+ declare class Staking {
4
+ private static contract;
5
+ private static logger;
6
+ static get address(): string;
7
+ /**
8
+ * Checks if contract has been initialized, if not - initialize contract
9
+ */
10
+ private static checkInit;
11
+ /**
12
+ * Fetching stake info by owner address from blockchain
13
+ */
14
+ static getStakeInfo(ownerAddress: string): Promise<StakeInfo>;
15
+ /**
16
+ * Fetching locked tokens info by owner address and contract name from blockchain
17
+ */
18
+ static getLockInfo(purpose: Purpose, ownerAddress: string): Promise<LockInfo>;
19
+ /**
20
+ * Stakes tokens
21
+ * @param amount - tokens to be staked
22
+ * @param transactionOptions - object what contains alternative action account or gas limit (optional)
23
+ */
24
+ static stake(amount: string, transactionOptions?: TransactionOptions): Promise<void>;
25
+ }
26
+ export default Staking;
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ var logger_1 = __importDefault(require("../logger"));
43
+ var Staking_json_1 = __importDefault(require("../contracts/Staking.json"));
44
+ var store_1 = __importDefault(require("../store"));
45
+ var utils_1 = require("../utils");
46
+ var Staking_1 = require("../types/Staking");
47
+ var Superpro_1 = __importDefault(require("./Superpro"));
48
+ var TxManager_1 = __importDefault(require("../utils/TxManager"));
49
+ var Staking = /** @class */ (function () {
50
+ function Staking() {
51
+ }
52
+ Object.defineProperty(Staking, "address", {
53
+ get: function () {
54
+ return Superpro_1.default.address;
55
+ },
56
+ enumerable: false,
57
+ configurable: true
58
+ });
59
+ /**
60
+ * Checks if contract has been initialized, if not - initialize contract
61
+ */
62
+ Staking.checkInit = function (transactionOptions) {
63
+ if (transactionOptions === null || transactionOptions === void 0 ? void 0 : transactionOptions.web3) {
64
+ (0, utils_1.checkIfInitialized)();
65
+ return new transactionOptions.web3.eth.Contract(Staking_json_1.default.abi, Superpro_1.default.address);
66
+ }
67
+ if (this.contract)
68
+ return this.contract;
69
+ (0, utils_1.checkIfInitialized)();
70
+ this.logger = logger_1.default.child({ className: "Staking" });
71
+ return this.contract = new store_1.default.web3.eth.Contract(Staking_json_1.default.abi, Superpro_1.default.address);
72
+ };
73
+ /**
74
+ * Fetching stake info by owner address from blockchain
75
+ */
76
+ Staking.getStakeInfo = function (ownerAddress) {
77
+ return __awaiter(this, void 0, void 0, function () {
78
+ var stakeInfoParams;
79
+ return __generator(this, function (_a) {
80
+ switch (_a.label) {
81
+ case 0:
82
+ this.checkInit();
83
+ return [4 /*yield*/, this.contract.methods.getStakeInfo(ownerAddress).call()];
84
+ case 1:
85
+ stakeInfoParams = _a.sent();
86
+ return [2 /*return*/, (0, utils_1.tupleToObject)(stakeInfoParams, Staking_1.StakeInfoStructure)];
87
+ }
88
+ });
89
+ });
90
+ };
91
+ /**
92
+ * Fetching locked tokens info by owner address and contract name from blockchain
93
+ */
94
+ Staking.getLockInfo = function (purpose, ownerAddress) {
95
+ return __awaiter(this, void 0, void 0, function () {
96
+ var lockInfoParams;
97
+ return __generator(this, function (_a) {
98
+ switch (_a.label) {
99
+ case 0:
100
+ this.checkInit();
101
+ return [4 /*yield*/, this.contract.methods.getLockedTokensInfo(purpose, ownerAddress).call()];
102
+ case 1:
103
+ lockInfoParams = _a.sent();
104
+ return [2 /*return*/, (0, utils_1.tupleToObject)(lockInfoParams, Staking_1.LockInfoStructure)];
105
+ }
106
+ });
107
+ });
108
+ };
109
+ /**
110
+ * Stakes tokens
111
+ * @param amount - tokens to be staked
112
+ * @param transactionOptions - object what contains alternative action account or gas limit (optional)
113
+ */
114
+ Staking.stake = function (amount, transactionOptions) {
115
+ return __awaiter(this, void 0, void 0, function () {
116
+ var contract;
117
+ return __generator(this, function (_a) {
118
+ switch (_a.label) {
119
+ case 0:
120
+ contract = this.checkInit(transactionOptions);
121
+ (0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
122
+ return [4 /*yield*/, TxManager_1.default.execute(contract.methods.stake, [amount], transactionOptions)];
123
+ case 1:
124
+ _a.sent();
125
+ return [2 /*return*/];
126
+ }
127
+ });
128
+ });
129
+ };
130
+ return Staking;
131
+ }());
132
+ exports.default = Staking;
@@ -0,0 +1,20 @@
1
+ import { ContractName, ParamName } from "../types/Superpro";
2
+ declare class Superpro {
3
+ static address: string;
4
+ private static contract;
5
+ private static logger;
6
+ /**
7
+ * Checks if contract has been initialized, if not - initialize contract
8
+ */
9
+ private static checkInit;
10
+ /**
11
+ * Fetching address of contract by name
12
+ */
13
+ static getContractAddress(name: ContractName): Promise<string>;
14
+ static getTokenAddress(): Promise<string>;
15
+ /**
16
+ * Fetching config parameter value by name
17
+ */
18
+ static getParam(name: ParamName): Promise<string>;
19
+ }
20
+ export default Superpro;
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ var logger_1 = __importDefault(require("../logger"));
43
+ var Superpro_json_1 = __importDefault(require("../contracts/Superpro.json"));
44
+ var store_1 = __importDefault(require("../store"));
45
+ var Superpro = /** @class */ (function () {
46
+ function Superpro() {
47
+ }
48
+ /**
49
+ * Checks if contract has been initialized, if not - initialize contract
50
+ */
51
+ Superpro.checkInit = function () {
52
+ if (this.contract)
53
+ return;
54
+ if (!this.address || !store_1.default.web3)
55
+ throw new Error("BlockchainConnector is not initialized, needs to run 'await BlockchainConnector.init(CONFIG)' first");
56
+ this.contract = new store_1.default.web3.eth.Contract(Superpro_json_1.default.abi, this.address);
57
+ this.logger = logger_1.default.child({ className: "Superpro", address: this.address });
58
+ };
59
+ /**
60
+ * Fetching address of contract by name
61
+ */
62
+ Superpro.getContractAddress = function (name) {
63
+ return __awaiter(this, void 0, void 0, function () {
64
+ return __generator(this, function (_a) {
65
+ this.checkInit();
66
+ return [2 /*return*/, this.address];
67
+ });
68
+ });
69
+ };
70
+ Superpro.getTokenAddress = function () {
71
+ return __awaiter(this, void 0, void 0, function () {
72
+ return __generator(this, function (_a) {
73
+ switch (_a.label) {
74
+ case 0:
75
+ this.checkInit();
76
+ return [4 /*yield*/, this.contract.methods.getToken().call()];
77
+ case 1: return [2 /*return*/, _a.sent()];
78
+ }
79
+ });
80
+ });
81
+ };
82
+ /**
83
+ * Fetching config parameter value by name
84
+ */
85
+ Superpro.getParam = function (name) {
86
+ return __awaiter(this, void 0, void 0, function () {
87
+ return __generator(this, function (_a) {
88
+ switch (_a.label) {
89
+ case 0:
90
+ this.checkInit();
91
+ return [4 /*yield*/, this.contract.methods.getConfigParam(name).call()];
92
+ case 1: return [2 /*return*/, _a.sent()];
93
+ }
94
+ });
95
+ });
96
+ };
97
+ return Superpro;
98
+ }());
99
+ exports.default = Superpro;
@@ -0,0 +1,30 @@
1
+ import { Transaction } from "web3-core";
2
+ import { TransactionOptions } from "../types/Web3";
3
+ declare class SuperproToken {
4
+ static address: string;
5
+ private static contract;
6
+ private static logger;
7
+ /**
8
+ * Checks if contract has been initialized, if not - initialize contract
9
+ */
10
+ private static checkInit;
11
+ /**
12
+ * Fetching balance of SuperProtocol tokens on address
13
+ */
14
+ static balanceOf(address: string): Promise<string>;
15
+ /**
16
+ * Transfers specific amount of SP tokens to specific address
17
+ * @param to - address to revive tokens
18
+ * @param amount - amount of tokens to transfer
19
+ * @param transactionOptions - object what contains alternative action account or gas limit (optional)
20
+ */
21
+ static transfer(to: string, amount: string, transactionOptions?: TransactionOptions): Promise<Transaction>;
22
+ /**
23
+ * Approve tokens for specific address
24
+ * @param address - address for approval
25
+ * @param amount - number of tokens to be approved
26
+ * @param transactionOptions - object what contains alternative action account or gas limit (optional)
27
+ */
28
+ static approve(address: string, amount: string, transactionOptions?: TransactionOptions): Promise<void>;
29
+ }
30
+ export default SuperproToken;