polkamarkets-js 1.0.2 → 3.1.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 (163) 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/help.txt +8 -0
  113. package/index.js +3 -0
  114. package/migrations/10_deploy_weth.js +5 -0
  115. package/migrations/11_deploy_full_flow.js +99 -0
  116. package/migrations/12_deploy_pm_v3_querier.js +7 -0
  117. package/migrations/13_deploy_pm_v3_factory.js +14 -0
  118. package/migrations/1_initial_migration.js +5 -0
  119. package/migrations/2_deploy_erc20.js +10 -0
  120. package/migrations/3_deploy_realitio.js +11 -0
  121. package/migrations/4_deploy_pm.js +20 -0
  122. package/migrations/5_seed_markets.js +51 -0
  123. package/migrations/6_deploy_achievements.js +5 -0
  124. package/migrations/7_deploy_voting.js +14 -0
  125. package/migrations/8_deploy_pm_v2.js +20 -0
  126. package/migrations/9_seed_markets_v2.js +68 -0
  127. package/package.json +106 -13
  128. package/src/Application.js +421 -0
  129. package/src/interfaces/index.js +19 -0
  130. package/src/models/AchievementsContract.js +217 -0
  131. package/src/models/ArbitrationContract.js +69 -0
  132. package/src/models/ArbitrationProxyContract.js +32 -0
  133. package/src/models/ERC20Contract.js +156 -0
  134. package/src/models/FantasyERC20Contract.js +92 -0
  135. package/src/models/IContract.js +1002 -0
  136. package/src/models/PolkamarketsSmartAccount.js +100 -0
  137. package/src/models/PredictionMarketContract.js +562 -0
  138. package/src/models/PredictionMarketV2Contract.js +830 -0
  139. package/src/models/PredictionMarketV3Contract.js +233 -0
  140. package/src/models/PredictionMarketV3ControllerContract.js +102 -0
  141. package/src/models/PredictionMarketV3FactoryContract.js +96 -0
  142. package/src/models/PredictionMarketV3ManagerContract.js +111 -0
  143. package/src/models/PredictionMarketV3QuerierContract.js +24 -0
  144. package/src/models/RealitioERC20Contract.js +286 -0
  145. package/src/models/VotingContract.js +182 -0
  146. package/src/models/WETH9Contract.js +92 -0
  147. package/src/models/index.js +33 -0
  148. package/src/utils/Account.js +40 -0
  149. package/src/utils/Contract.js +120 -0
  150. package/src/utils/Numbers.js +94 -0
  151. package/tests/fantasyERC20Contract.js +225 -0
  152. package/tests/index.js +10 -0
  153. package/tests/predictionMarketContract.js +466 -0
  154. package/tests/predictionMarketV2Contract.js +1042 -0
  155. package/tests/predictionMarketV3Contract.js +1079 -0
  156. package/tests/predictionMarketV3ControllerContract.js +613 -0
  157. package/tests/predictionMarketV3FactoryContract.js +469 -0
  158. package/tests/predictionMarketV3ManagerContract.js +610 -0
  159. package/tests/utils.js +16 -0
  160. package/tests/votingContract.js +490 -0
  161. package/tooling/docs/jsdoc.json +6 -0
  162. package/truffle-config.js +134 -0
  163. package/polkamarkets.js +0 -436
@@ -0,0 +1,286 @@
1
+ const _ = require("lodash");
2
+
3
+ const realitio = require("../interfaces").realitio;
4
+ const ierc20 = require("../interfaces").ierc20;
5
+
6
+ const Numbers = require("../utils/Numbers");
7
+ const IContract = require('./IContract');
8
+
9
+ const ERC20Contract = require('./ERC20Contract');
10
+
11
+ /**
12
+ * RealitioERC20 Contract Object
13
+ * @constructor RealitioERC20Contract
14
+ * @param {Web3} web3
15
+ * @param {Integer} decimals
16
+ * @param {Address} contractAddress
17
+ */
18
+
19
+ class RealitioERC20Contract extends IContract {
20
+ constructor(params) {
21
+ super({ abi: realitio, ...params });
22
+ this.contractName = 'realitio';
23
+ }
24
+
25
+ /**
26
+ * @function getTokenDecimals
27
+ * @description Get Token Decimals
28
+ * @return {Integer} decimals
29
+ */
30
+ async getTokenDecimals() {
31
+ try {
32
+ const contractAddress = await this.params.contract.getContract().methods.token().call();
33
+ const erc20Contract = new ERC20Contract({ ...this.params, contractAddress, abi: ierc20 });
34
+
35
+ return await erc20Contract.getDecimalsAsync();
36
+ } catch (err) {
37
+ // defaulting to 18 decimals
38
+ return 18;
39
+ }
40
+ }
41
+
42
+ /**
43
+ * @function getQuestion
44
+ * @description getQuestion
45
+ * @param {bytes32} questionId
46
+ * @returns {Object} question
47
+ */
48
+ async getQuestion({ questionId }) {
49
+ const question = await this.getContract().methods.questions(questionId).call();
50
+ const isFinalized = await this.getContract().methods.isFinalized(questionId).call();
51
+ const isClaimed = isFinalized && question.history_hash === Numbers.nullHash();
52
+ const decimals = await this.getTokenDecimals();
53
+
54
+ return {
55
+ id: questionId,
56
+ bond: Numbers.fromDecimalsNumber(question.bond, decimals),
57
+ bestAnswer: question.best_answer,
58
+ finalizeTs: question.finalize_ts,
59
+ isFinalized,
60
+ isClaimed,
61
+ isPendingArbitration: question.is_pending_arbitration,
62
+ arbitrator: question.arbitrator,
63
+ };
64
+ }
65
+
66
+ /**
67
+ * @function getQuestionBestAnswer
68
+ * @description getQuestionBestAnswer
69
+ * @param {bytes32} questionId
70
+ * @returns {bytes32} answerId
71
+ */
72
+ async getQuestionBestAnswer({ questionId }) {
73
+ return await this.getContract().methods.getBestAnswer(questionId).call();
74
+ }
75
+
76
+ /**
77
+ * @function resultForQuestion
78
+ * @description resultForQuestion - throws an error if question is not finalized
79
+ * @param {bytes32} questionId
80
+ * @returns {bytes32} answerId
81
+ */
82
+ async getResultForQuestion({ questionId }) {
83
+ return await this.getContract().methods.resultFor(questionId).call();
84
+ }
85
+
86
+ /**
87
+ * @function getQuestionBondsByAnswer
88
+ * @description getQuestionBondsByAnswer - throws an error if question is not finalized
89
+ * @param {bytes32} questionId
90
+ * @returns {Object} bonds
91
+ */
92
+ async getQuestionBondsByAnswer({ questionId, user }) {
93
+ const bonds = {};
94
+
95
+ const answers = await this.getEvents('LogNewAnswer', { question_id: questionId, user });
96
+
97
+ const decimals = await this.getTokenDecimals();
98
+
99
+ answers.forEach((answer) => {
100
+ const answerId = answer.returnValues.answer;
101
+
102
+ if (!bonds[answerId]) bonds[answerId] = 0;
103
+
104
+ bonds[answerId] += Numbers.fromDecimalsNumber(answer.returnValues.bond, decimals);
105
+ });
106
+
107
+ return bonds;
108
+ }
109
+
110
+ /**
111
+ * @function submitAnswerERC20
112
+ * @description Submit Answer for a Question
113
+ * @param {bytes32} questionId
114
+ * @param {bytes32} answerId
115
+ * @param {Integer} amount
116
+ */
117
+ async submitAnswerERC20({ questionId, answerId, amount }) {
118
+ const decimals = await this.getTokenDecimals();
119
+ let amountDecimals = Numbers.toSmartContractDecimals(amount, decimals);
120
+
121
+ return await this.__sendTx(
122
+ this.getContract().methods.submitAnswerERC20(
123
+ questionId,
124
+ answerId,
125
+ 0,
126
+ amountDecimals
127
+ ),
128
+ false
129
+ );
130
+ }
131
+
132
+ async getMyBonds() {
133
+ const user = await this.getMyAccount();
134
+ if (!user) return {};
135
+
136
+ return await this.getUserBonds({ user });
137
+ }
138
+
139
+ /**
140
+ * @function getMyBonds
141
+ * @description Get My Bonds
142
+ * @returns {Array} Outcome Shares
143
+ */
144
+ async getUserBonds({ user }) {
145
+ const events = await this.getEvents('LogNewAnswer', { user });
146
+ const claimEvents = await this.getEvents('LogClaim', { user });
147
+ const withdrawEvents = await this.getEvents('LogWithdraw', { user });
148
+ const decimals = await this.getTokenDecimals();
149
+
150
+ const lastWithdrawBlockNumber = withdrawEvents[withdrawEvents.length - 1]
151
+ ? withdrawEvents[withdrawEvents.length - 1].blockNumber
152
+ : 0;
153
+
154
+ const bonds = {};
155
+
156
+ // iterating through every answer and summing up the bonds
157
+ events.forEach((event) => {
158
+ const questionId = event.returnValues.question_id;
159
+
160
+ // initializing bond vars
161
+ if (!bonds[questionId]) bonds[questionId] = { total: 0, answers: {}, claimed: 0, withdrawn: false };
162
+ if (!bonds[questionId].answers[event.returnValues.answer]) {
163
+ bonds[questionId].answers[event.returnValues.answer] = 0;
164
+ }
165
+
166
+ const bond = Numbers.fromDecimalsNumber(event.returnValues.bond, decimals)
167
+
168
+ bonds[questionId].total += bond;
169
+ bonds[questionId].answers[event.returnValues.answer] += bond;
170
+ });
171
+
172
+ claimEvents.forEach((event) => {
173
+ const questionId = event.returnValues.question_id;
174
+
175
+ const amount = Numbers.fromDecimalsNumber(event.returnValues.amount, decimals);
176
+
177
+ bonds[questionId].claimed += amount;
178
+
179
+ // withdraw occurred after claim, marking as withdrawn
180
+ if (lastWithdrawBlockNumber >= event.blockNumber) bonds[questionId].withdrawn = true;
181
+ });
182
+
183
+ return bonds;
184
+ }
185
+
186
+ async getMyActions() {
187
+ const user = await this.getMyAccount();
188
+ if (!user) return [];
189
+
190
+ return await this.getUserActions({ user });
191
+ }
192
+
193
+ /**
194
+ * @function getMyActions
195
+ * @description Get My Actions
196
+ * @returns {Array} Actions
197
+ */
198
+ async getUserActions({ user }) {
199
+ const events = await this.getEvents('LogNewAnswer', { user });
200
+ const decimals = await this.getTokenDecimals();
201
+
202
+ return events.map(event => {
203
+ return {
204
+ action: 'Bond',
205
+ questionId: event.returnValues.question_id,
206
+ answerId: event.returnValues.answer,
207
+ value: Numbers.fromDecimalsNumber(event.returnValues.bond, decimals),
208
+ timestamp: Numbers.fromBigNumberToInteger(event.returnValues.ts, 18),
209
+ transactionHash: event.transactionHash
210
+ }
211
+ })
212
+ }
213
+
214
+ async getMyQuestions() {
215
+ const user = await this.getMyAccount();
216
+ if (!user) return [];
217
+
218
+ return await this.getUserQuestions({ user });
219
+ }
220
+
221
+ /**
222
+ * @function getMyQuestions
223
+ * @description Get My Questions
224
+ * @returns {Array} Questions
225
+ */
226
+ async getUserQuestions({ user }) {
227
+ const events = await this.getEvents('LogNewAnswer', { user });
228
+ const logQuestionEvents = await this.getEvents('LogNewQuestion');
229
+
230
+ // getting unique question ids
231
+ const questionIds = events.map(event => event.returnValues.question_id).filter((value, index, self) => self.indexOf(value) === index);
232
+ const questions = logQuestionEvents.filter(event => questionIds.includes(event.returnValues.question_id));
233
+
234
+ return questions.map(event => {
235
+ return {
236
+ questionId: event.returnValues.question_id,
237
+ question: event.returnValues.question,
238
+ transactionHash: event.transactionHash
239
+ }
240
+ });
241
+ }
242
+
243
+ /**
244
+ * @function claimWinnings
245
+ * @description claimWinnings
246
+ * @param {bytes32} questionId
247
+ */
248
+ async claimWinningsAndWithdraw({ questionId }) {
249
+ const question = await this.getQuestion({ questionId });
250
+
251
+ // assuring question state is finalized
252
+ if (!question.isFinalized) return false;
253
+
254
+ if (question.isClaimed) {
255
+ // question already claimed, only performing a withdraw action
256
+ return await this.__sendTx(
257
+ this.getContract().methods.withdraw(),
258
+ false
259
+ );
260
+ }
261
+
262
+ const events = await this.getEvents('LogNewAnswer', { question_id: questionId });
263
+
264
+ const historyHashes = events.map((event) => event.returnValues.history_hash).slice(0, -1).reverse();
265
+ // adding an empty hash to the history hashes
266
+ historyHashes.push(Numbers.nullHash());
267
+
268
+ const addrs = events.map((event) => event.returnValues.user).reverse();
269
+ const bonds = events.map((event) => event.returnValues.bond).reverse();
270
+ const answers = events.map((event) => event.returnValues.answer).reverse();
271
+
272
+ return await this.__sendTx(
273
+ this.getContract().methods.claimMultipleAndWithdrawBalance(
274
+ [questionId],
275
+ [historyHashes.length],
276
+ historyHashes,
277
+ addrs,
278
+ bonds,
279
+ answers
280
+ ),
281
+ false
282
+ );
283
+ }
284
+ }
285
+
286
+ module.exports = RealitioERC20Contract;
@@ -0,0 +1,182 @@
1
+ // const _ = require("lodash");
2
+ // const moment = require("moment");
3
+
4
+ const voting = require("../interfaces").voting;
5
+
6
+ const Numbers = require("../utils/Numbers");
7
+ const IContract = require('./IContract');
8
+
9
+ const actions = {
10
+ 0: 'Upvote',
11
+ 1: 'Remove Upvote',
12
+ 2: 'Downvote',
13
+ 3: 'Remove Downvote',
14
+ }
15
+
16
+ /**
17
+ * Voting Contract Object
18
+ * @constructor VotingContract
19
+ * @param {Web3} web3
20
+ * @param {Integer} decimals
21
+ * @param {Address} contractAddress
22
+ */
23
+
24
+ class VotingContract extends IContract {
25
+ constructor(params) {
26
+ super({ abi: voting, ...params });
27
+ this.contractName = 'voting';
28
+ }
29
+
30
+ /* Get Functions */
31
+ /**
32
+ * @function getMinimumRequiredBalance
33
+ * @description Returns minimum required ERC20 balance to vote
34
+ * @returns {Integer} requiredBalance
35
+ */
36
+ async getMinimumRequiredBalance() {
37
+ const requiredBalance = await this.params.contract
38
+ .getContract()
39
+ .methods
40
+ .requiredBalance()
41
+ .call();
42
+
43
+ return Numbers.fromDecimalsNumber(requiredBalance, 18)
44
+ }
45
+
46
+ /**
47
+ * @function getItemVotes
48
+ * @description Get Item Total upvotes and downvotes
49
+ * @param {Integer} itemId
50
+ * @returns {Integer} upvotes
51
+ * @returns {Integer} downvotes
52
+ */
53
+ async getItemVotes({ itemId }) {
54
+ let res = await this.params.contract
55
+ .getContract()
56
+ .methods
57
+ .getItemVotes(itemId)
58
+ .call();
59
+
60
+ return {
61
+ upvotes: Number(res[0]),
62
+ downvotes: Number(res[1]),
63
+ }
64
+ }
65
+
66
+ /**
67
+ * @function hasUserVotedItem
68
+ * @description Get info if user has voted the item
69
+ * @param {Integer} itemId
70
+ * @param {Address} user
71
+ * @returns {Boolean} upvoted
72
+ * @returns {Boolean} downvoted
73
+ */
74
+ async hasUserVotedItem({ user, itemId }) {
75
+ let res = await this.params.contract
76
+ .getContract()
77
+ .methods
78
+ .hasUserVotedItem(user, itemId)
79
+ .call();
80
+
81
+ return {
82
+ upvoted: res[0],
83
+ downvoted: res[1],
84
+ }
85
+ }
86
+
87
+ /**
88
+ * @function getUserActions
89
+ * @description Get user voting actions
90
+ * @param {Address} user
91
+ * @returns {Array} Voted Actions
92
+ */
93
+ async getUserActions({ user }) {
94
+ const events = await this.getEvents('ItemVoteAction', { user });
95
+
96
+ return events.map(event => {
97
+ return {
98
+ action: actions[Numbers.fromBigNumberToInteger(event.returnValues.action, 18)],
99
+ itemId: Numbers.fromBigNumberToInteger(event.returnValues.itemId, 18),
100
+ timestamp: Numbers.fromBigNumberToInteger(event.returnValues.timestamp, 18),
101
+ transactionHash: event.transactionHash,
102
+ }
103
+ });
104
+ }
105
+
106
+ /**
107
+ * @function getUserVotes
108
+ * @description Get user voting status for every item he has voted
109
+ * @param {Address} user
110
+ * @returns {Object} Voting status
111
+ */
112
+ async getUserVotes({ user }) {
113
+ const events = await this.getEvents('ItemVoteAction', { user });
114
+
115
+ const eventMap = new Map();
116
+
117
+ // go through all events and get the latest event per each item
118
+ events.forEach(event => {
119
+ eventMap.set(
120
+ Numbers.fromBigNumberToInteger(event.returnValues.itemId, 18),
121
+ actions[Numbers.fromBigNumberToInteger(event.returnValues.action, 18)]
122
+ );
123
+ });
124
+
125
+ const userVotes = {};
126
+ [...eventMap].forEach(([itemId, action]) => userVotes[itemId] = {
127
+ upvoted: action === actions[0],
128
+ downvoted: action === actions[2],
129
+ });
130
+
131
+ return userVotes;
132
+ }
133
+
134
+ /* POST User Functions */
135
+
136
+ /**
137
+ * @function upvoteItem
138
+ * @description Upvote an item
139
+ * @param {Integer} itemId
140
+ */
141
+ async upvoteItem({ itemId }) {
142
+ return await this.__sendTx(
143
+ this.getContract().methods.upvoteItem(itemId)
144
+ );
145
+ };
146
+
147
+ /**
148
+ * @function downvoteItem
149
+ * @description Downvote an item
150
+ * @param {Integer} itemId
151
+ */
152
+ async downvoteItem({ itemId }) {
153
+ return await this.__sendTx(
154
+ this.getContract().methods.downvoteItem(itemId)
155
+ );
156
+ };
157
+
158
+
159
+ /**
160
+ * @function removeUpvoteItem
161
+ * @description Remove Upvote from an item
162
+ * @param {Integer} itemId
163
+ */
164
+ async removeUpvoteItem({ itemId }) {
165
+ return await this.__sendTx(
166
+ this.getContract().methods.removeUpvoteItem(itemId)
167
+ );
168
+ };
169
+
170
+ /**
171
+ * @function removeDownvoteItem
172
+ * @description Remove Downvote from an item
173
+ * @param {Integer} itemId
174
+ */
175
+ async removeDownvoteItem({ itemId }) {
176
+ return await this.__sendTx(
177
+ this.getContract().methods.removeDownvoteItem(itemId)
178
+ );
179
+ };
180
+ }
181
+
182
+ module.exports = VotingContract;
@@ -0,0 +1,92 @@
1
+ const weth = require("../interfaces").weth;
2
+ const Numbers = require("../utils/Numbers");
3
+ const IContract = require('./IContract');
4
+
5
+ class WETH9Contract extends IContract {
6
+ constructor(params) {
7
+ super({ abi: weth, ...params });
8
+ this.contractName = 'weth';
9
+ }
10
+
11
+ getDecimals() {
12
+ return 18;
13
+ }
14
+
15
+ async totalSupply() {
16
+ return Numbers.fromDecimals(await this.getContract().methods.totalSupply().call(), this.getDecimals());
17
+ }
18
+
19
+ async balanceOf({ address }) {
20
+ return Numbers.fromDecimalsNumber(await this.getContract().methods.balanceOf(address).call(), this.getDecimals());
21
+ }
22
+
23
+ async isApproved({ address, amount, spenderAddress }) {
24
+ try {
25
+ let approvedAmount = Numbers.fromDecimals(
26
+ await this.getContract().methods.allowance(address, spenderAddress).call(),
27
+ this.getDecimals()
28
+ );
29
+ return (approvedAmount >= amount);
30
+ } catch (err) {
31
+ throw err;
32
+ }
33
+ }
34
+
35
+ async approve({ address, amount, callback }) {
36
+ try {
37
+ let amountWithDecimals = Numbers.toSmartContractDecimals(
38
+ amount,
39
+ this.getDecimals()
40
+ );
41
+ let res = await this.__sendTx(
42
+ this.getContract()
43
+ .methods.approve(address, amountWithDecimals),
44
+ null,
45
+ null,
46
+ callback
47
+ );
48
+ return res;
49
+ } catch (err) {
50
+ throw err;
51
+ }
52
+ }
53
+
54
+ async deposit({ amount, callback }) {
55
+ try {
56
+ let amountWithDecimals = Numbers.toSmartContractDecimals(
57
+ amount,
58
+ this.getDecimals()
59
+ );
60
+ let res = await this.__sendTx(
61
+ this.getContract().methods.deposit(),
62
+ false,
63
+ amountWithDecimals,
64
+ callback
65
+ );
66
+ return res;
67
+ } catch (err) {
68
+ throw err;
69
+ }
70
+ }
71
+
72
+ async withdraw({ amount, callback }) {
73
+ try {
74
+ let amountWithDecimals = Numbers.toSmartContractDecimals(
75
+ amount,
76
+ this.getDecimals()
77
+ );
78
+ let res = await this.__sendTx(
79
+ this.getContract()
80
+ .methods.withdraw(amountWithDecimals),
81
+ null,
82
+ null,
83
+ callback
84
+ );
85
+ return res;
86
+ } catch (err) {
87
+ throw err;
88
+ }
89
+ }
90
+ }
91
+
92
+ module.exports = WETH9Contract;
@@ -0,0 +1,33 @@
1
+ const ERC20Contract = require('./ERC20Contract');
2
+ const PredictionMarketContract = require('./PredictionMarketContract');
3
+ const PredictionMarketV2Contract = require('./PredictionMarketV2Contract');
4
+ const PredictionMarketV3Contract = require('./PredictionMarketV3Contract');
5
+ const PredictionMarketV3ManagerContract = require('./PredictionMarketV3ManagerContract');
6
+ const PredictionMarketV3ControllerContract = require('./PredictionMarketV3ControllerContract');
7
+ const PredictionMarketV3FactoryContract = require('./PredictionMarketV3FactoryContract');
8
+ const PredictionMarketV3QuerierContract = require('./PredictionMarketV3QuerierContract');
9
+ const AchievementsContract = require('./AchievementsContract');
10
+ const RealitioERC20Contract = require('./RealitioERC20Contract');
11
+ const VotingContract = require('./VotingContract');
12
+ const FantasyERC20Contract = require('./FantasyERC20Contract');
13
+ const WETH9Contract = require('./WETH9Contract');
14
+ const ArbitrationContract = require('./ArbitrationContract');
15
+ const ArbitrationProxyContract = require('./ArbitrationProxyContract');
16
+
17
+ module.exports = {
18
+ ERC20Contract,
19
+ PredictionMarketContract,
20
+ PredictionMarketV2Contract,
21
+ PredictionMarketV3Contract,
22
+ PredictionMarketV3ManagerContract,
23
+ PredictionMarketV3QuerierContract,
24
+ AchievementsContract,
25
+ RealitioERC20Contract,
26
+ VotingContract,
27
+ FantasyERC20Contract,
28
+ WETH9Contract,
29
+ ArbitrationContract,
30
+ ArbitrationProxyContract,
31
+ PredictionMarketV3FactoryContract,
32
+ PredictionMarketV3ControllerContract
33
+ }
@@ -0,0 +1,40 @@
1
+ class Account {
2
+
3
+ constructor(web3, account) {
4
+ this.web3 = web3;
5
+ this.account = account;
6
+ }
7
+
8
+
9
+ async getBalance() {
10
+ let wei = await this.web3.eth.getBalance(this.getAddress());
11
+ return this.web3.utils.fromWei(wei, 'ether')
12
+ }
13
+
14
+ getAddress() {
15
+ return this.account.address;
16
+ }
17
+
18
+ getPrivateKey() {
19
+ return this.account.privateKey;
20
+ }
21
+
22
+ getAccount() {
23
+ return this.account
24
+ }
25
+
26
+ async sendEther(amount, address, data = null) {
27
+ let tx = {
28
+ data: data,
29
+ from: this.getAddress(),
30
+ to: address,
31
+ gas: 443000,
32
+ value: amount
33
+ };
34
+ let result = await this.account.signTransaction(tx);
35
+ let transaction = await this.web3.eth.sendSignedTransaction(result.rawTransaction);
36
+ return transaction;
37
+ }
38
+ }
39
+
40
+ module.exports = Account;