polkamarkets-js 1.0.2 → 3.1.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.
Files changed (164) hide show
  1. package/.openzeppelin/unknown-1337.json +2056 -0
  2. package/CONTRIBUTING.md +36 -0
  3. package/README.md +24 -25
  4. package/_book/README.md +590 -0
  5. package/_book/core.md +50 -0
  6. package/_book/gitbook/fonts/fontawesome/FontAwesome.otf +0 -0
  7. package/_book/gitbook/fonts/fontawesome/fontawesome-webfont.eot +0 -0
  8. package/_book/gitbook/fonts/fontawesome/fontawesome-webfont.svg +685 -0
  9. package/_book/gitbook/fonts/fontawesome/fontawesome-webfont.ttf +0 -0
  10. package/_book/gitbook/fonts/fontawesome/fontawesome-webfont.woff +0 -0
  11. package/_book/gitbook/fonts/fontawesome/fontawesome-webfont.woff2 +0 -0
  12. package/_book/gitbook/gitbook-plugin-fontsettings/fontsettings.js +240 -0
  13. package/_book/gitbook/gitbook-plugin-fontsettings/website.css +291 -0
  14. package/_book/gitbook/gitbook-plugin-highlight/ebook.css +135 -0
  15. package/_book/gitbook/gitbook-plugin-highlight/website.css +434 -0
  16. package/_book/gitbook/gitbook-plugin-lunr/lunr.min.js +7 -0
  17. package/_book/gitbook/gitbook-plugin-lunr/search-lunr.js +59 -0
  18. package/_book/gitbook/gitbook-plugin-search/lunr.min.js +7 -0
  19. package/_book/gitbook/gitbook-plugin-search/search-engine.js +50 -0
  20. package/_book/gitbook/gitbook-plugin-search/search.css +35 -0
  21. package/_book/gitbook/gitbook-plugin-search/search.js +213 -0
  22. package/_book/gitbook/gitbook-plugin-sharing/buttons.js +90 -0
  23. package/_book/gitbook/gitbook.js +4 -0
  24. package/_book/gitbook/images/apple-touch-icon-precomposed-152.png +0 -0
  25. package/_book/gitbook/images/favicon.ico +0 -0
  26. package/_book/gitbook/style.css +9 -0
  27. package/_book/gitbook/theme.js +4 -0
  28. package/_book/index.html +705 -0
  29. package/_book/intro.md +32 -0
  30. package/_book/search_index.json +1 -0
  31. package/book.json +8 -0
  32. package/build/contracts/AccessControl.json +1 -0
  33. package/build/contracts/AccessControlEnumerable.json +1 -0
  34. package/build/contracts/Achievements.json +1 -0
  35. package/build/contracts/Address.json +1 -0
  36. package/build/contracts/BalanceHolder.json +1 -0
  37. package/build/contracts/BalanceHolder_ERC20.json +1 -0
  38. package/build/contracts/CeilDiv.json +1 -0
  39. package/build/contracts/Clones.json +1 -0
  40. package/build/contracts/Context.json +1 -0
  41. package/build/contracts/Counters.json +1 -0
  42. package/build/contracts/ERC165.json +1 -0
  43. package/build/contracts/ERC20.json +1 -0
  44. package/build/contracts/ERC20Burnable.json +1 -0
  45. package/build/contracts/ERC20Pausable.json +1 -0
  46. package/build/contracts/ERC20PresetMinterPauser.json +1 -0
  47. package/build/contracts/ERC721.json +1 -0
  48. package/build/contracts/EnumerableMap.json +1 -0
  49. package/build/contracts/EnumerableSet.json +1 -0
  50. package/build/contracts/FantasyERC20.json +1 -0
  51. package/build/contracts/IAccessControl.json +1 -0
  52. package/build/contracts/IAccessControlEnumerable.json +1 -0
  53. package/build/contracts/IBalanceHolder_ERC20.json +1 -0
  54. package/build/contracts/IERC165.json +1 -0
  55. package/build/contracts/IERC20.json +1 -0
  56. package/build/contracts/IERC20Metadata.json +1 -0
  57. package/build/contracts/IERC20Permit.json +1 -0
  58. package/build/contracts/IERC721.json +1 -0
  59. package/build/contracts/IERC721Enumerable.json +1 -0
  60. package/build/contracts/IERC721Metadata.json +1 -0
  61. package/build/contracts/IERC721Receiver.json +1 -0
  62. package/build/contracts/IFantasyERC20.json +1 -0
  63. package/build/contracts/IPredictionMarketV3.json +1 -0
  64. package/build/contracts/IPredictionMarketV3Factory.json +1 -0
  65. package/build/contracts/IPredictionMarketV3Manager.json +1 -0
  66. package/build/contracts/IRealityETH_ERC20.json +1 -0
  67. package/build/contracts/IRealityETH_IERC20.json +1 -0
  68. package/build/contracts/IWETH.json +1 -0
  69. package/build/contracts/LandFactory.json +1 -0
  70. package/build/contracts/Math.json +1 -0
  71. package/build/contracts/Migrations.json +1 -0
  72. package/build/contracts/Ownable.json +1 -0
  73. package/build/contracts/Pausable.json +1 -0
  74. package/build/contracts/PredictionMarket.json +1 -0
  75. package/build/contracts/PredictionMarketV2.json +1 -0
  76. package/build/contracts/PredictionMarketV3.json +1 -0
  77. package/build/contracts/PredictionMarketV3Controller.json +1 -0
  78. package/build/contracts/PredictionMarketV3Factory.json +1 -0
  79. package/build/contracts/PredictionMarketV3Manager.json +1 -0
  80. package/build/contracts/PredictionMarketV3Querier.json +1 -0
  81. package/build/contracts/RealitioERC20.json +1 -0
  82. package/build/contracts/RealitioForeignArbitrationProxyWithAppeals.json +1 -0
  83. package/build/contracts/RealitioHomeArbitrationProxy.json +1 -0
  84. package/build/contracts/RealitioSafeMath256.json +1 -0
  85. package/build/contracts/RealitioSafeMath32.json +1 -0
  86. package/build/contracts/RealityETH_ERC20_Factory.json +1 -0
  87. package/build/contracts/RealityETH_ERC20_v3_0.json +1 -0
  88. package/build/contracts/ReentrancyGuard.json +1 -0
  89. package/build/contracts/SafeERC20.json +1 -0
  90. package/build/contracts/SafeMath.json +1 -0
  91. package/build/contracts/Strings.json +1 -0
  92. package/build/contracts/Voting.json +1 -0
  93. package/build/contracts/WETH9.json +1 -0
  94. package/build/contracts/test.json +1 -0
  95. package/cleanContracts.js +22 -0
  96. package/contracts/FantasyERC20.sol +81 -0
  97. package/contracts/IFantasyERC20.sol +20 -0
  98. package/contracts/IPredictionMarketV3.sol +207 -0
  99. package/contracts/IPredictionMarketV3Factory.sol +10 -0
  100. package/contracts/IPredictionMarketV3Manager.sol +12 -0
  101. package/contracts/IRealityETH_ERC20.sol +64 -0
  102. package/contracts/LandFactory.sol +248 -0
  103. package/contracts/Migrations.sol +24 -0
  104. package/contracts/PredictionMarketV3.sol +1332 -0
  105. package/contracts/PredictionMarketV3Controller.sol +87 -0
  106. package/contracts/PredictionMarketV3Factory.sol +205 -0
  107. package/contracts/PredictionMarketV3Manager.sol +45 -0
  108. package/contracts/PredictionMarketV3Querier.sol +79 -0
  109. package/contracts/RealityETH_ERC20_Factory.sol +54 -0
  110. package/contracts/Voting.sol +153 -0
  111. package/contracts/WETH9.sol +62 -0
  112. package/hardhat.config.js +4 -0
  113. package/help.txt +8 -0
  114. package/index.js +3 -0
  115. package/migrations/10_deploy_weth.js +5 -0
  116. package/migrations/11_deploy_full_flow.js +99 -0
  117. package/migrations/12_deploy_pm_v3_querier.js +7 -0
  118. package/migrations/13_deploy_pm_v3_factory.js +14 -0
  119. package/migrations/1_initial_migration.js +5 -0
  120. package/migrations/2_deploy_erc20.js +10 -0
  121. package/migrations/3_deploy_realitio.js +11 -0
  122. package/migrations/4_deploy_pm.js +20 -0
  123. package/migrations/5_seed_markets.js +51 -0
  124. package/migrations/6_deploy_achievements.js +5 -0
  125. package/migrations/7_deploy_voting.js +14 -0
  126. package/migrations/8_deploy_pm_v2.js +20 -0
  127. package/migrations/9_seed_markets_v2.js +68 -0
  128. package/package.json +106 -13
  129. package/src/Application.js +421 -0
  130. package/src/interfaces/index.js +19 -0
  131. package/src/models/AchievementsContract.js +217 -0
  132. package/src/models/ArbitrationContract.js +69 -0
  133. package/src/models/ArbitrationProxyContract.js +32 -0
  134. package/src/models/ERC20Contract.js +156 -0
  135. package/src/models/FantasyERC20Contract.js +92 -0
  136. package/src/models/IContract.js +1002 -0
  137. package/src/models/PolkamarketsSmartAccount.js +100 -0
  138. package/src/models/PredictionMarketContract.js +562 -0
  139. package/src/models/PredictionMarketV2Contract.js +830 -0
  140. package/src/models/PredictionMarketV3Contract.js +256 -0
  141. package/src/models/PredictionMarketV3ControllerContract.js +102 -0
  142. package/src/models/PredictionMarketV3FactoryContract.js +96 -0
  143. package/src/models/PredictionMarketV3ManagerContract.js +111 -0
  144. package/src/models/PredictionMarketV3QuerierContract.js +24 -0
  145. package/src/models/RealitioERC20Contract.js +286 -0
  146. package/src/models/VotingContract.js +182 -0
  147. package/src/models/WETH9Contract.js +92 -0
  148. package/src/models/index.js +33 -0
  149. package/src/utils/Account.js +40 -0
  150. package/src/utils/Contract.js +120 -0
  151. package/src/utils/Numbers.js +94 -0
  152. package/tests/fantasyERC20Contract.js +225 -0
  153. package/tests/index.js +10 -0
  154. package/tests/predictionMarketContract.js +466 -0
  155. package/tests/predictionMarketV2Contract.js +1042 -0
  156. package/tests/predictionMarketV3Contract.js +1079 -0
  157. package/tests/predictionMarketV3ControllerContract.js +613 -0
  158. package/tests/predictionMarketV3FactoryContract.js +469 -0
  159. package/tests/predictionMarketV3ManagerContract.js +610 -0
  160. package/tests/utils.js +16 -0
  161. package/tests/votingContract.js +490 -0
  162. package/tooling/docs/jsdoc.json +6 -0
  163. package/truffle-config.js +134 -0
  164. package/polkamarkets.js +0 -436
package/polkamarkets.js DELETED
@@ -1,436 +0,0 @@
1
- import * as realitioLib from '@reality.eth/reality-eth-lib/formatters/question';
2
- import * as beprojs from 'bepro-js';
3
-
4
- export default class Polkamarkets {
5
- constructor(web3Provider, web3EventsProvider = null) {
6
- // bepro app
7
- this.bepro = new beprojs.Application({ web3Provider, web3EventsProvider });
8
- this.bepro.start();
9
-
10
- // bepro smart contract instances
11
- this.contracts = {};
12
-
13
- // indicates if user has already done a successful metamask login
14
- this.loggedIn = false;
15
-
16
- // user eth address
17
- this.address = '';
18
- }
19
-
20
- getPredictionMarketContract(contractAddress) {
21
- this.contracts.pm = this.bepro.getPredictionMarketContract({ contractAddress });
22
- }
23
-
24
- getERC20Contract(contractAddress) {
25
- this.contracts.erc20 = this.bepro.getERC20Contract({ contractAddress });
26
- }
27
-
28
- getRealitioERC20Contract(contractAddress) {
29
- this.contracts.realitio = this.bepro.getRealitioERC20Contract({ contractAddress });
30
- }
31
-
32
- getContracts() {
33
- // re-fetching contracts
34
- if (this.contracts.pm && this.contracts.pm.params.contractAddress) {
35
- this.getPredictionMarketContract(this.contracts.pm.params.contractAddress);
36
- }
37
- if (this.contracts.realitio && this.contracts.realitio.params.contractAddress) {
38
- this.getRealitioERC20Contract(this.contracts.realitio.params.contractAddress);
39
- }
40
- if (this.contracts.erc20 && this.contracts.erc20.params.contractAddress) {
41
- this.getERC20Contract(this.contracts.erc20.params.contractAddress);
42
- }
43
- }
44
-
45
- // returns wether wallet is connected to service or not
46
- async isLoggedIn() {
47
- return this.bepro.isLoggedIn();
48
- }
49
-
50
- async login() {
51
- if (this.loggedIn) return true;
52
-
53
- try {
54
- this.loggedIn = await this.bepro.login();
55
- // successful login
56
- if (this.loggedIn) {
57
- this.address = await this.getAddress();
58
- // TODO: set this in bepro
59
- this.bepro.web3.eth.defaultAccount = this.address;
60
- // re-fetching contracts
61
- this.getContracts();
62
- }
63
- } catch (e) {
64
- // should be non-blocking
65
- return false;
66
- }
67
-
68
- return this.loggedIn;
69
- }
70
-
71
- async getAddress() {
72
- if (this.address) return this.address;
73
-
74
- return this.bepro.getAddress() || '';
75
- }
76
-
77
- async getBalance() {
78
- if (!this.address) return 0;
79
-
80
- // returns user balance in ETH
81
- const balance = await this.bepro.getETHBalance();
82
-
83
- return parseFloat(balance) || 0;
84
- }
85
-
86
- // PredictionMarket contract functions
87
-
88
- async getMinimumRequiredBalance() {
89
- const requiredBalance = await this.contracts.pm.getMinimumRequiredBalance();
90
-
91
- return requiredBalance;
92
- }
93
-
94
- async getMarketFee() {
95
- const fee = await this.contracts.pm.getFee();
96
-
97
- return fee;
98
- }
99
-
100
- async createMarket(
101
- name,
102
- image,
103
- duration,
104
- outcomes,
105
- category,
106
- ethAmount
107
- ) {
108
- // ensuring user has wallet connected
109
- await this.login();
110
-
111
- const response = await this.contracts.pm.createMarket({
112
- name,
113
- image,
114
- duration,
115
- outcomes,
116
- category,
117
- ethAmount,
118
- oracleAddress: this.address
119
- });
120
-
121
- return response;
122
- }
123
-
124
- async buy(
125
- marketId,
126
- outcomeId,
127
- ethAmount,
128
- minOutcomeSharesToBuy
129
- ) {
130
- // ensuring user has wallet connected
131
- await this.login();
132
-
133
- const response = await this.contracts.pm.buy({
134
- marketId,
135
- outcomeId,
136
- ethAmount,
137
- minOutcomeSharesToBuy
138
- });
139
-
140
- return response;
141
- }
142
-
143
- async sell(
144
- marketId,
145
- outcomeId,
146
- ethAmount,
147
- maxOutcomeSharesToSell
148
- ) {
149
- // ensuring user has wallet connected
150
- await this.login();
151
-
152
- const response = await this.contracts.pm.sell({
153
- marketId,
154
- outcomeId,
155
- ethAmount,
156
- maxOutcomeSharesToSell
157
- });
158
-
159
- return response;
160
- }
161
-
162
- async addLiquidity(marketId, ethAmount) {
163
- // ensuring user has wallet connected
164
- await this.login();
165
-
166
- const response = await this.contracts.pm.addLiquidity({
167
- marketId,
168
- ethAmount
169
- });
170
-
171
- return response;
172
- }
173
-
174
- async removeLiquidity(marketId, shares) {
175
- // ensuring user has wallet connected
176
- await this.login();
177
-
178
- const response = await this.contracts.pm.removeLiquidity({
179
- marketId,
180
- shares
181
- });
182
-
183
- return response;
184
- }
185
-
186
- async claimWinnings(marketId) {
187
- // ensuring user has wallet connected
188
- await this.login();
189
-
190
- const response = await this.contracts.pm.claimWinnings({
191
- marketId
192
- });
193
-
194
- return response;
195
- }
196
-
197
- async claimVoidedOutcomeShares(marketId, outcomeId) {
198
- // ensuring user has wallet connected
199
- await this.login();
200
-
201
- const response = await this.contracts.pm.claimVoidedOutcomeShares({
202
- marketId,
203
- outcomeId
204
- });
205
-
206
- return response;
207
- }
208
-
209
- async claimLiquidity(marketId) {
210
- // ensuring user has wallet connected
211
- await this.login();
212
-
213
- const response = await this.contracts.pm.claimLiquidity({
214
- marketId
215
- });
216
-
217
- return response;
218
- }
219
-
220
- async getMarketData(marketId) {
221
- // ensuring user has wallet connected
222
- await this.login();
223
-
224
- const marketData = await this.contracts.pm.getMarketData({ marketId });
225
-
226
- marketData.outcomes = await Promise.all(
227
- marketData.outcomeIds.map(async outcomeId => {
228
- const outcomeData = await this.contracts.pm.getOutcomeData({
229
- marketId,
230
- outcomeId
231
- });
232
-
233
- return outcomeData;
234
- })
235
- );
236
-
237
- return marketData;
238
- }
239
-
240
- async getMarketPrices(marketId) {
241
- // ensuring user has wallet connected
242
- await this.login();
243
-
244
- const response = await this.contracts.pm.getMarketPrices({ marketId });
245
-
246
- return response;
247
- }
248
-
249
- async getPortfolio() {
250
- // ensuring user has wallet connected
251
- if (!this.address) return {};
252
-
253
- const response = await this.contracts.pm.getMyPortfolio();
254
-
255
- return response;
256
- }
257
-
258
- async getActions() {
259
- // ensuring user has wallet connected
260
- if (!this.address) return [];
261
-
262
- const response = await this.contracts.pm.getMyActions();
263
-
264
- return response;
265
- }
266
-
267
- async resolveMarket(marketId) {
268
- // ensuring user has wallet connected
269
- await this.login();
270
-
271
- const response = await this.contracts.pm.resolveMarketOutcome({
272
- marketId
273
- });
274
-
275
- return response;
276
- }
277
-
278
- // ERC20 contract functions
279
-
280
- async getERC20Balance() {
281
- if (!this.address) return 0;
282
-
283
- // TODO improve this: ensuring erc20 contract is initialized
284
- // eslint-disable-next-line no-underscore-dangle
285
- await this.contracts.erc20.__init__();
286
-
287
- // returns user balance in ETH
288
- const balance = await this.contracts.erc20.getTokenAmount(this.address);
289
-
290
- return parseFloat(balance) || 0;
291
- }
292
-
293
- async approveERC20(address, amount) {
294
- // ensuring user has wallet connected
295
- await this.login();
296
-
297
- // ensuring erc20 contract is initialized
298
- // eslint-disable-next-line no-underscore-dangle
299
- await this.contracts.erc20.__init__();
300
-
301
- const response = await this.contracts.erc20.approve({
302
- address,
303
- amount
304
- });
305
-
306
- return response;
307
- }
308
-
309
- async calcBuyAmount(marketId, outcomeId, ethAmount) {
310
- const response = await this.contracts.pm.calcBuyAmount({
311
- marketId,
312
- outcomeId,
313
- ethAmount
314
- });
315
-
316
- return response;
317
- }
318
-
319
- async calcSellAmount(
320
- marketId,
321
- outcomeId,
322
- ethAmount
323
- ) {
324
- const response = await this.contracts.pm.calcSellAmount({
325
- marketId,
326
- outcomeId,
327
- ethAmount
328
- });
329
-
330
- return response;
331
- }
332
-
333
- // Realitio contract functions
334
-
335
- async isRealitioERC20Approved() {
336
- if (!this.address) return false;
337
-
338
- // TODO improve this: ensuring erc20 contract is initialized
339
- // eslint-disable-next-line no-underscore-dangle
340
- await this.contracts.erc20.__init__();
341
-
342
- // returns user balance in ETH
343
- const isApproved = await this.contracts.erc20.isApproved({
344
- address: this.address,
345
- amount: 1,
346
- spenderAddress: this.contracts.realitio.getAddress()
347
- });
348
-
349
- return isApproved;
350
- }
351
-
352
- async approveRealitioERC20() {
353
- // ensuring user has wallet connected
354
- await this.login();
355
-
356
- if (!this.address) return false;
357
-
358
- // TODO improve this: ensuring erc20 contract is initialized
359
- // eslint-disable-next-line no-underscore-dangle
360
- await this.contracts.erc20.__init__();
361
-
362
- return this.approveERC20(
363
- this.contracts.realitio.getAddress(),
364
- 2 ** 128 - 1
365
- );
366
- }
367
-
368
- async getQuestionBonds(questionId, user = null) {
369
- const bonds = await this.contracts.realitio.getQuestionBondsByAnswer({
370
- questionId,
371
- user
372
- });
373
-
374
- // mapping answer ids to outcome ids
375
- Object.keys(bonds).forEach(answerId => {
376
- const outcomeId = Number(
377
- realitioLib.bytes32ToString(answerId, { type: 'int' })
378
- );
379
- bonds[outcomeId] = bonds[answerId];
380
- delete bonds[answerId];
381
- });
382
-
383
- return bonds;
384
- }
385
-
386
- async placeBond(questionId, outcomeId, amount) {
387
- // ensuring user has wallet connected
388
- await this.login();
389
-
390
- // translating outcome id to answerId
391
- const answerId = realitioLib.answerToBytes32(outcomeId, { type: 'int' });
392
-
393
- const response = await this.contracts.realitio.submitAnswerERC20({
394
- questionId,
395
- answerId,
396
- amount
397
- });
398
-
399
- return response;
400
- }
401
-
402
- async claimWinningsAndWithdraw(questionId) {
403
- // ensuring user has wallet connected
404
- await this.login();
405
-
406
- const response = await this.contracts.realitio.claimWinningsAndWithdraw({
407
- questionId
408
- });
409
-
410
- return response;
411
- }
412
-
413
- async getBonds() {
414
- // ensuring user has wallet connected
415
- if (!this.address) return {};
416
-
417
- const bonds = await this.contracts.realitio.getMyBonds();
418
-
419
- return bonds;
420
- }
421
-
422
- async getBondActions() {
423
- // ensuring user has wallet connected
424
- if (!this.address) return [];
425
-
426
- const response = await this.contracts.realitio.getMyActions();
427
-
428
- return response;
429
- }
430
-
431
- async getQuestion(questionId) {
432
- const question = await this.contracts.realitio.getQuestion({ questionId });
433
-
434
- return question;
435
- }
436
- }