polkamarkets-js 1.0.1 → 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 -422
@@ -0,0 +1,69 @@
1
+ const arbitration = require("../interfaces").arbitration;
2
+ const Numbers = require("../utils/Numbers");
3
+ const IContract = require('./IContract');
4
+
5
+ /**
6
+ * Arbitration Contract Object
7
+ * @constructor ArbitrationContract
8
+ * @param {Web3} web3
9
+ * @param {Integer} decimals
10
+ * @param {Address} contractAddress
11
+ */
12
+
13
+ class ArbitrationContract extends IContract {
14
+ constructor(params) {
15
+ super({ abi: arbitration, ...params });
16
+ this.contractName = 'arbitration';
17
+ }
18
+
19
+ /**
20
+ * @function getDisputeFee
21
+ * @description get cost of applying for arbitration
22
+ * @param {bytes32} questionId
23
+ * @return {Integer} decimals
24
+ */
25
+ async getDisputeFee({ questionId }) {
26
+ const fee = await this.params.contract.getContract().methods.getDisputeFee(questionId).call();
27
+
28
+ return Numbers.fromDecimalsNumber(fee, 18);
29
+ }
30
+
31
+ async getArbitrationDisputeId({ questionId }) {
32
+ const allEvents = await this.getEvents('ArbitrationCreated');
33
+ const questionEvents = allEvents.filter(event => event.returnValues._questionID === questionId);
34
+
35
+ if (questionEvents.length === 0) return null;
36
+
37
+ return Number(questionEvents[0].returnValues._disputeID);
38
+ }
39
+
40
+ async getArbitrationRequests({ questionId }) {
41
+ const allEvents = await this.getEvents('ArbitrationRequested');
42
+ const questionEvents = allEvents.filter(event => event.returnValues._questionID === questionId);
43
+
44
+ return questionEvents.map(event => ({
45
+ questionId: event.returnValues._questionID,
46
+ requester: event.returnValues._requester,
47
+ maxPrevious: Numbers.fromDecimalsNumber(event.returnValues._maxPrevious, 18)
48
+ }));
49
+ }
50
+
51
+ /**
52
+ * @function requestArbitration
53
+ * @description apply for arbitration
54
+ * @param {bytes32} questionId
55
+ * @param {Integer} maxPrevious
56
+ */
57
+ async requestArbitration({ questionId, bond }) {
58
+ const fee = await this.params.contract.getContract().methods.getDisputeFee(questionId).call();
59
+ const maxPrevious = Numbers.toSmartContractDecimals(bond, 18);
60
+
61
+ return await this.__sendTx(
62
+ this.getContract().methods.requestArbitration(questionId, maxPrevious),
63
+ false,
64
+ fee
65
+ );
66
+ }
67
+ }
68
+
69
+ module.exports = ArbitrationContract;
@@ -0,0 +1,32 @@
1
+ const arbitrationProxy = require("../interfaces").arbitrationProxy;
2
+ const Numbers = require("../utils/Numbers");
3
+ const IContract = require('./IContract');
4
+
5
+ /**
6
+ * ArbitrationProxy Contract Object
7
+ * @constructor ArbitrationProxyContract
8
+ * @param {Web3} web3
9
+ * @param {Integer} decimals
10
+ * @param {Address} contractAddress
11
+ */
12
+
13
+ class ArbitrationProxyContract extends IContract {
14
+ constructor(params) {
15
+ super({ abi: arbitrationProxy, ...params });
16
+ this.contractName = 'arbitrationProxy';
17
+ }
18
+
19
+ async getArbitrationRequestsRejected({ questionId }) {
20
+ const allEvents = await this.getEvents('RequestRejected');
21
+ const questionEvents = allEvents.filter(event => event.returnValues._questionID === questionId);
22
+
23
+ return questionEvents.map(event => ({
24
+ questionId: event.returnValues._questionID,
25
+ requester: event.returnValues._requester,
26
+ maxPrevious: Numbers.fromDecimalsNumber(event.returnValues._maxPrevious, 18),
27
+ reason: event.returnValues._reason
28
+ }));
29
+ }
30
+ }
31
+
32
+ module.exports = ArbitrationProxyContract;
@@ -0,0 +1,156 @@
1
+ const ierc20 = require("../interfaces").ierc20;
2
+ const Numbers = require("../utils/Numbers");
3
+ const IContract = require('./IContract');
4
+
5
+ class ERC20Contract extends IContract {
6
+ constructor(params, abi) {
7
+ super({...params, abi: params.abi || ierc20});
8
+ this.contractName = 'erc20';
9
+ }
10
+
11
+ async __assert() {
12
+ await super.__assert();
13
+ this.params.decimals = await this.getDecimalsAsync();
14
+ }
15
+
16
+ async transferTokenAmount({ toAddress, tokenAmount }) {
17
+ let amountWithDecimals = Numbers.toSmartContractDecimals(
18
+ tokenAmount,
19
+ this.getDecimals()
20
+ );
21
+ return await this.__sendTx(
22
+ this.getContract()
23
+ .methods.transfer(toAddress, amountWithDecimals)
24
+ );
25
+ }
26
+
27
+ async getTokenAmount(address) {
28
+ return Numbers.fromDecimals(
29
+ await this.getContract().methods.balanceOf(address).call(),
30
+ this.getDecimals()
31
+ );
32
+ }
33
+
34
+ async totalSupply() {
35
+ return Numbers.fromDecimals(await this.getContract().methods.totalSupply().call(), this.getDecimals());
36
+ }
37
+
38
+ getABI() {
39
+ return this.params.contract;
40
+ }
41
+
42
+ getDecimals() {
43
+ return this.params.decimals;
44
+ }
45
+
46
+ async getDecimalsAsync() {
47
+ return await this.getContract().methods.decimals().call();
48
+ }
49
+
50
+ async balanceOf({ address }) {
51
+ const decimals = this.getDecimals() || (await this.getDecimalsAsync());
52
+ return Numbers.fromDecimalsNumber(await this.getContract().methods.balanceOf(address).call(), decimals);
53
+ }
54
+
55
+ async isApproved({ address, amount, spenderAddress }) {
56
+ try {
57
+ let approvedAmount = Numbers.fromDecimals(
58
+ await this.getContract().methods.allowance(address, spenderAddress).call(),
59
+ this.getDecimals()
60
+ );
61
+ return (approvedAmount >= amount);
62
+ } catch (err) {
63
+ throw err;
64
+ }
65
+ }
66
+
67
+ async approve({ address, amount, callback }) {
68
+ try {
69
+ let amountWithDecimals = Numbers.toSmartContractDecimals(
70
+ amount,
71
+ this.getDecimals() || (await this.getDecimalsAsync())
72
+ );
73
+ let res = await this.__sendTx(
74
+ this.getContract().methods.approve(address, amountWithDecimals),
75
+ null,
76
+ null,
77
+ callback
78
+ );
79
+ return res;
80
+ } catch (err) {
81
+ throw err;
82
+ }
83
+ }
84
+
85
+ async burn({ amount }) {
86
+ try {
87
+ let amountWithDecimals = Numbers.toSmartContractDecimals(
88
+ amount,
89
+ this.getDecimals()
90
+ );
91
+ let res = await this.__sendTx(
92
+ this.getContract().methods.burn(amountWithDecimals),
93
+ false,
94
+ );
95
+ return res;
96
+ } catch (err) {
97
+ throw err;
98
+ }
99
+ }
100
+
101
+ async mint({ address, amount }) {
102
+ try {
103
+ let amountWithDecimals = Numbers.toSmartContractDecimals(
104
+ amount,
105
+ this.getDecimals()
106
+ );
107
+ let res = await this.__sendTx(
108
+ this.getContract().methods.mint(address, amountWithDecimals),
109
+ false,
110
+ );
111
+ return res;
112
+ } catch (err) {
113
+ throw err;
114
+ }
115
+ }
116
+
117
+ async burnEvents({ address }) {
118
+ const events = await this.getEvents(
119
+ 'Transfer',
120
+ { from: address, to: '0x0000000000000000000000000000000000000000' }
121
+ )
122
+
123
+ // attaching block timestamp to event
124
+ return await Promise.all(events.map(async (event) => {
125
+ const block = await this.getBlock(event.blockNumber);
126
+
127
+ return {
128
+ ...event,
129
+ timestamp: block.timestamp
130
+ };
131
+ }));
132
+ }
133
+
134
+ async name() {
135
+ return await this.getContract().methods.name().call();
136
+ }
137
+
138
+ async symbol() {
139
+ return await this.getContract().methods.symbol().call();
140
+ }
141
+
142
+ async paused() {
143
+ return await this.getContract().methods.paused().call();
144
+ }
145
+
146
+ async getTokenInfo() {
147
+ return {
148
+ name: await this.name(),
149
+ address: this.getAddress(),
150
+ ticker: await this.symbol(),
151
+ decimals: await this.getDecimalsAsync(),
152
+ };
153
+ }
154
+ }
155
+
156
+ module.exports = ERC20Contract;
@@ -0,0 +1,92 @@
1
+ const fantasyerc20 = require("../interfaces").fantasyerc20;
2
+ const ERC20Contract = require("./ERC20Contract");
3
+
4
+ const Numbers = require("../utils/Numbers");
5
+
6
+ /**
7
+ * Fantasy ERC20 Contract Object
8
+ * @constructor FantasyERC20Contract
9
+ * @param {Web3} web3
10
+ * @param {Integer} decimals
11
+ * @param {Address} contractAddress
12
+ */
13
+
14
+ class FantasyERC20Contract extends ERC20Contract {
15
+ constructor(params) {
16
+ super({ abi: fantasyerc20, ...params });
17
+ this.contractName = 'erc20';
18
+ }
19
+
20
+ /* Get Functions */
21
+ /**
22
+ * @function hasUserClaimedTokens
23
+ * @description Returns if the user has already claimed the tokens
24
+ * @returns {Boolean} claimedTokens
25
+ */
26
+ async hasUserClaimedTokens({ address }) {
27
+ return await this.params.contract
28
+ .getContract()
29
+ .methods
30
+ .hasUserClaimedTokens(address)
31
+ .call();
32
+ }
33
+
34
+ /**
35
+ * @function tokenAmountToClaim
36
+ * @description Returns the amount of tokens to claim
37
+ * @returns {Integer} tokenAmountToClaim
38
+ *
39
+ */
40
+ async tokenAmountToClaim() {
41
+ const tokenAmountToClaim = Numbers.fromDecimalsNumber(
42
+ await this.params.contract
43
+ .getContract()
44
+ .methods
45
+ .tokenAmountToClaim()
46
+ .call(),
47
+ this.getDecimals()
48
+ );
49
+
50
+ return tokenAmountToClaim;
51
+ }
52
+
53
+ /* POST User Functions */
54
+
55
+ /**
56
+ * @function claimTokens
57
+ * @description Claim tokens for sender
58
+ */
59
+ async claimTokens() {
60
+ return await this.__sendTx(
61
+ this.getContract().methods.claimTokens()
62
+ );
63
+ };
64
+
65
+ /**
66
+ * @function claimAndApproveTokens
67
+ * @description Claim and approve tokens for sender
68
+ */
69
+ async claimAndApproveTokens() {
70
+ return await this.__sendTx(
71
+ this.getContract().methods.claimAndApproveTokens()
72
+ );
73
+ };
74
+
75
+ /**
76
+ * @function resetBalance
77
+ * @description Reset user's balance to tokenAmountToClaim
78
+ */
79
+ async resetBalance() {
80
+ const address = await this.getMyAccount();
81
+ if (!address) return false;
82
+
83
+ const tokenAmountToClaim = await this.tokenAmountToClaim();
84
+ const balance = await this.getTokenAmount(address);
85
+
86
+ const amountToBurn = balance - tokenAmountToClaim > 0 ? balance - tokenAmountToClaim : 0;
87
+
88
+ return await this.burn({ amount: amountToBurn });
89
+ };
90
+ }
91
+
92
+ module.exports = FantasyERC20Contract;