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.
- package/.openzeppelin/unknown-1337.json +2056 -0
- package/CONTRIBUTING.md +36 -0
- package/README.md +24 -25
- package/_book/README.md +590 -0
- package/_book/core.md +50 -0
- package/_book/gitbook/fonts/fontawesome/FontAwesome.otf +0 -0
- package/_book/gitbook/fonts/fontawesome/fontawesome-webfont.eot +0 -0
- package/_book/gitbook/fonts/fontawesome/fontawesome-webfont.svg +685 -0
- package/_book/gitbook/fonts/fontawesome/fontawesome-webfont.ttf +0 -0
- package/_book/gitbook/fonts/fontawesome/fontawesome-webfont.woff +0 -0
- package/_book/gitbook/fonts/fontawesome/fontawesome-webfont.woff2 +0 -0
- package/_book/gitbook/gitbook-plugin-fontsettings/fontsettings.js +240 -0
- package/_book/gitbook/gitbook-plugin-fontsettings/website.css +291 -0
- package/_book/gitbook/gitbook-plugin-highlight/ebook.css +135 -0
- package/_book/gitbook/gitbook-plugin-highlight/website.css +434 -0
- package/_book/gitbook/gitbook-plugin-lunr/lunr.min.js +7 -0
- package/_book/gitbook/gitbook-plugin-lunr/search-lunr.js +59 -0
- package/_book/gitbook/gitbook-plugin-search/lunr.min.js +7 -0
- package/_book/gitbook/gitbook-plugin-search/search-engine.js +50 -0
- package/_book/gitbook/gitbook-plugin-search/search.css +35 -0
- package/_book/gitbook/gitbook-plugin-search/search.js +213 -0
- package/_book/gitbook/gitbook-plugin-sharing/buttons.js +90 -0
- package/_book/gitbook/gitbook.js +4 -0
- package/_book/gitbook/images/apple-touch-icon-precomposed-152.png +0 -0
- package/_book/gitbook/images/favicon.ico +0 -0
- package/_book/gitbook/style.css +9 -0
- package/_book/gitbook/theme.js +4 -0
- package/_book/index.html +705 -0
- package/_book/intro.md +32 -0
- package/_book/search_index.json +1 -0
- package/book.json +8 -0
- package/build/contracts/AccessControl.json +1 -0
- package/build/contracts/AccessControlEnumerable.json +1 -0
- package/build/contracts/Achievements.json +1 -0
- package/build/contracts/Address.json +1 -0
- package/build/contracts/BalanceHolder.json +1 -0
- package/build/contracts/BalanceHolder_ERC20.json +1 -0
- package/build/contracts/CeilDiv.json +1 -0
- package/build/contracts/Clones.json +1 -0
- package/build/contracts/Context.json +1 -0
- package/build/contracts/Counters.json +1 -0
- package/build/contracts/ERC165.json +1 -0
- package/build/contracts/ERC20.json +1 -0
- package/build/contracts/ERC20Burnable.json +1 -0
- package/build/contracts/ERC20Pausable.json +1 -0
- package/build/contracts/ERC20PresetMinterPauser.json +1 -0
- package/build/contracts/ERC721.json +1 -0
- package/build/contracts/EnumerableMap.json +1 -0
- package/build/contracts/EnumerableSet.json +1 -0
- package/build/contracts/FantasyERC20.json +1 -0
- package/build/contracts/IAccessControl.json +1 -0
- package/build/contracts/IAccessControlEnumerable.json +1 -0
- package/build/contracts/IBalanceHolder_ERC20.json +1 -0
- package/build/contracts/IERC165.json +1 -0
- package/build/contracts/IERC20.json +1 -0
- package/build/contracts/IERC20Metadata.json +1 -0
- package/build/contracts/IERC20Permit.json +1 -0
- package/build/contracts/IERC721.json +1 -0
- package/build/contracts/IERC721Enumerable.json +1 -0
- package/build/contracts/IERC721Metadata.json +1 -0
- package/build/contracts/IERC721Receiver.json +1 -0
- package/build/contracts/IFantasyERC20.json +1 -0
- package/build/contracts/IPredictionMarketV3.json +1 -0
- package/build/contracts/IPredictionMarketV3Factory.json +1 -0
- package/build/contracts/IPredictionMarketV3Manager.json +1 -0
- package/build/contracts/IRealityETH_ERC20.json +1 -0
- package/build/contracts/IRealityETH_IERC20.json +1 -0
- package/build/contracts/IWETH.json +1 -0
- package/build/contracts/LandFactory.json +1 -0
- package/build/contracts/Math.json +1 -0
- package/build/contracts/Migrations.json +1 -0
- package/build/contracts/Ownable.json +1 -0
- package/build/contracts/Pausable.json +1 -0
- package/build/contracts/PredictionMarket.json +1 -0
- package/build/contracts/PredictionMarketV2.json +1 -0
- package/build/contracts/PredictionMarketV3.json +1 -0
- package/build/contracts/PredictionMarketV3Controller.json +1 -0
- package/build/contracts/PredictionMarketV3Factory.json +1 -0
- package/build/contracts/PredictionMarketV3Manager.json +1 -0
- package/build/contracts/PredictionMarketV3Querier.json +1 -0
- package/build/contracts/RealitioERC20.json +1 -0
- package/build/contracts/RealitioForeignArbitrationProxyWithAppeals.json +1 -0
- package/build/contracts/RealitioHomeArbitrationProxy.json +1 -0
- package/build/contracts/RealitioSafeMath256.json +1 -0
- package/build/contracts/RealitioSafeMath32.json +1 -0
- package/build/contracts/RealityETH_ERC20_Factory.json +1 -0
- package/build/contracts/RealityETH_ERC20_v3_0.json +1 -0
- package/build/contracts/ReentrancyGuard.json +1 -0
- package/build/contracts/SafeERC20.json +1 -0
- package/build/contracts/SafeMath.json +1 -0
- package/build/contracts/Strings.json +1 -0
- package/build/contracts/Voting.json +1 -0
- package/build/contracts/WETH9.json +1 -0
- package/build/contracts/test.json +1 -0
- package/cleanContracts.js +22 -0
- package/contracts/FantasyERC20.sol +81 -0
- package/contracts/IFantasyERC20.sol +20 -0
- package/contracts/IPredictionMarketV3.sol +207 -0
- package/contracts/IPredictionMarketV3Factory.sol +10 -0
- package/contracts/IPredictionMarketV3Manager.sol +12 -0
- package/contracts/IRealityETH_ERC20.sol +64 -0
- package/contracts/LandFactory.sol +248 -0
- package/contracts/Migrations.sol +24 -0
- package/contracts/PredictionMarketV3.sol +1332 -0
- package/contracts/PredictionMarketV3Controller.sol +87 -0
- package/contracts/PredictionMarketV3Factory.sol +205 -0
- package/contracts/PredictionMarketV3Manager.sol +45 -0
- package/contracts/PredictionMarketV3Querier.sol +79 -0
- package/contracts/RealityETH_ERC20_Factory.sol +54 -0
- package/contracts/Voting.sol +153 -0
- package/contracts/WETH9.sol +62 -0
- package/help.txt +8 -0
- package/index.js +3 -0
- package/migrations/10_deploy_weth.js +5 -0
- package/migrations/11_deploy_full_flow.js +99 -0
- package/migrations/12_deploy_pm_v3_querier.js +7 -0
- package/migrations/13_deploy_pm_v3_factory.js +14 -0
- package/migrations/1_initial_migration.js +5 -0
- package/migrations/2_deploy_erc20.js +10 -0
- package/migrations/3_deploy_realitio.js +11 -0
- package/migrations/4_deploy_pm.js +20 -0
- package/migrations/5_seed_markets.js +51 -0
- package/migrations/6_deploy_achievements.js +5 -0
- package/migrations/7_deploy_voting.js +14 -0
- package/migrations/8_deploy_pm_v2.js +20 -0
- package/migrations/9_seed_markets_v2.js +68 -0
- package/package.json +106 -13
- package/src/Application.js +421 -0
- package/src/interfaces/index.js +19 -0
- package/src/models/AchievementsContract.js +217 -0
- package/src/models/ArbitrationContract.js +69 -0
- package/src/models/ArbitrationProxyContract.js +32 -0
- package/src/models/ERC20Contract.js +156 -0
- package/src/models/FantasyERC20Contract.js +92 -0
- package/src/models/IContract.js +1002 -0
- package/src/models/PolkamarketsSmartAccount.js +100 -0
- package/src/models/PredictionMarketContract.js +562 -0
- package/src/models/PredictionMarketV2Contract.js +830 -0
- package/src/models/PredictionMarketV3Contract.js +233 -0
- package/src/models/PredictionMarketV3ControllerContract.js +102 -0
- package/src/models/PredictionMarketV3FactoryContract.js +96 -0
- package/src/models/PredictionMarketV3ManagerContract.js +111 -0
- package/src/models/PredictionMarketV3QuerierContract.js +24 -0
- package/src/models/RealitioERC20Contract.js +286 -0
- package/src/models/VotingContract.js +182 -0
- package/src/models/WETH9Contract.js +92 -0
- package/src/models/index.js +33 -0
- package/src/utils/Account.js +40 -0
- package/src/utils/Contract.js +120 -0
- package/src/utils/Numbers.js +94 -0
- package/tests/fantasyERC20Contract.js +225 -0
- package/tests/index.js +10 -0
- package/tests/predictionMarketContract.js +466 -0
- package/tests/predictionMarketV2Contract.js +1042 -0
- package/tests/predictionMarketV3Contract.js +1079 -0
- package/tests/predictionMarketV3ControllerContract.js +613 -0
- package/tests/predictionMarketV3FactoryContract.js +469 -0
- package/tests/predictionMarketV3ManagerContract.js +610 -0
- package/tests/utils.js +16 -0
- package/tests/votingContract.js +490 -0
- package/tooling/docs/jsdoc.json +6 -0
- package/truffle-config.js +134 -0
- package/polkamarkets.js +0 -422
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
const Web3 = require("web3");
|
|
2
|
+
|
|
3
|
+
const PolkamarketsSmartAccount = require("./models/PolkamarketsSmartAccount");
|
|
4
|
+
|
|
5
|
+
const ERC20Contract = require("./models/index").ERC20Contract;
|
|
6
|
+
const PredictionMarketContract = require("./models/index").PredictionMarketContract;
|
|
7
|
+
const PredictionMarketV2Contract = require("./models/index").PredictionMarketV2Contract;
|
|
8
|
+
const PredictionMarketV3Contract = require("./models/index").PredictionMarketV3Contract;
|
|
9
|
+
const PredictionMarketV3ManagerContract = require("./models/index").PredictionMarketV3ManagerContract;
|
|
10
|
+
const PredictionMarketV3ControllerContract = require("./models/index").PredictionMarketV3ControllerContract;
|
|
11
|
+
const PredictionMarketV3FactoryContract = require("./models/index").PredictionMarketV3FactoryContract;
|
|
12
|
+
const AchievementsContract = require("./models/index").AchievementsContract;
|
|
13
|
+
const RealitioERC20Contract = require("./models/index").RealitioERC20Contract;
|
|
14
|
+
const VotingContract = require("./models/index").VotingContract;
|
|
15
|
+
const FantasyERC20Contract = require("./models/index").FantasyERC20Contract;
|
|
16
|
+
const WETH9Contract = require("./models/index").WETH9Contract;
|
|
17
|
+
const ArbitrationContract = require("./models/index").ArbitrationContract;
|
|
18
|
+
const ArbitrationProxyContract = require("./models/index").ArbitrationProxyContract;
|
|
19
|
+
|
|
20
|
+
const Account = require('./utils/Account');
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
const networksEnum = Object.freeze({
|
|
24
|
+
1: "Main",
|
|
25
|
+
2: "Morden",
|
|
26
|
+
3: "Ropsten",
|
|
27
|
+
4: "Rinkeby",
|
|
28
|
+
42: "Kovan",
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
class Application {
|
|
32
|
+
constructor({
|
|
33
|
+
web3Provider,
|
|
34
|
+
web3PrivateKey,
|
|
35
|
+
web3EventsProvider,
|
|
36
|
+
gasPrice,
|
|
37
|
+
isSocialLogin = false,
|
|
38
|
+
socialLoginParams,
|
|
39
|
+
startBlock,
|
|
40
|
+
defaultDecimals
|
|
41
|
+
}) {
|
|
42
|
+
this.web3Provider = web3Provider;
|
|
43
|
+
// evm logs http source (optional)
|
|
44
|
+
this.web3EventsProvider = web3EventsProvider;
|
|
45
|
+
// fixed gas price for txs (optional)
|
|
46
|
+
this.gasPrice = gasPrice;
|
|
47
|
+
this.isSocialLogin = isSocialLogin;
|
|
48
|
+
this.startBlock = startBlock;
|
|
49
|
+
this.defaultDecimals = defaultDecimals;
|
|
50
|
+
|
|
51
|
+
if (this.isSocialLogin) {
|
|
52
|
+
this.socialLoginParams = socialLoginParams;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// IMPORTANT: this parameter should only be used for testing purposes
|
|
56
|
+
if (web3PrivateKey && !this.isSocialLogin) {
|
|
57
|
+
this.start();
|
|
58
|
+
this.login();
|
|
59
|
+
this.account = new Account(this.web3, this.web3.eth.accounts.privateKeyToAccount(web3PrivateKey));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**********/
|
|
64
|
+
/** CORE **/
|
|
65
|
+
/**********/
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @name start
|
|
69
|
+
* @description Start the Application
|
|
70
|
+
*/
|
|
71
|
+
start() {
|
|
72
|
+
this.web3 = new Web3(new Web3.providers.HttpProvider(this.web3Provider));
|
|
73
|
+
this.web3.eth.handleRevert = true;
|
|
74
|
+
if (typeof window !== "undefined") {
|
|
75
|
+
window.web3 = this.web3;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @name login
|
|
81
|
+
* @description Login with Metamask or a web3 provider
|
|
82
|
+
*/
|
|
83
|
+
async login(provider = null, isConnectedWallet = null) {
|
|
84
|
+
if (this.isSocialLogin) {
|
|
85
|
+
if (!this.provider) {
|
|
86
|
+
this.smartAccount = PolkamarketsSmartAccount.singleton.getInstanceIfExists()
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if ((!this.smartAccount || !this.smartAccount.provider) && provider) {
|
|
90
|
+
PolkamarketsSmartAccount.singleton.clearInstance();
|
|
91
|
+
this.smartAccount = PolkamarketsSmartAccount.singleton.getInstance(provider, this.socialLoginParams.networkConfig, isConnectedWallet);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return true;
|
|
95
|
+
} else {
|
|
96
|
+
try {
|
|
97
|
+
if (typeof window === "undefined") { return false; }
|
|
98
|
+
if (window.ethereum) {
|
|
99
|
+
window.web3 = new Web3(window.ethereum);
|
|
100
|
+
this.web3 = window.web3;
|
|
101
|
+
await window.ethereum.enable();
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
return false;
|
|
105
|
+
} catch (err) {
|
|
106
|
+
throw err;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @name isLoggedIn
|
|
113
|
+
* @description Returns wether metamask account is connected to service or not
|
|
114
|
+
*/
|
|
115
|
+
async isLoggedIn() {
|
|
116
|
+
if (this.isSocialLogin) {
|
|
117
|
+
return !!(this.smartAccount && this.smartAccount.provider);
|
|
118
|
+
} else {
|
|
119
|
+
try {
|
|
120
|
+
if (typeof window === "undefined" || typeof window.ethereum === "undefined") { return false; }
|
|
121
|
+
const accounts = await ethereum.request({ method: 'eth_accounts' });
|
|
122
|
+
|
|
123
|
+
return accounts.length > 0;
|
|
124
|
+
} catch (err) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
contractDefaultParams(contractAddress) {
|
|
131
|
+
return {
|
|
132
|
+
web3: this.web3,
|
|
133
|
+
contractAddress,
|
|
134
|
+
acc: this.account,
|
|
135
|
+
web3EventsProvider: this.web3EventsProvider,
|
|
136
|
+
gasPrice: this.gasPrice,
|
|
137
|
+
isSocialLogin: this.isSocialLogin,
|
|
138
|
+
startBlock: this.startBlock,
|
|
139
|
+
defaultDecimals: this.defaultDecimals
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/*************/
|
|
144
|
+
/** GETTERS **/
|
|
145
|
+
/*************/
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @name getPredictionMarketContract
|
|
149
|
+
* @param {Address} ContractAddress (Opt) If it is deployed
|
|
150
|
+
* @description Create a PredictionMarket Contract
|
|
151
|
+
*/
|
|
152
|
+
getPredictionMarketContract({ contractAddress = null } = {}) {
|
|
153
|
+
try {
|
|
154
|
+
return new PredictionMarketContract({
|
|
155
|
+
...this.contractDefaultParams(contractAddress)
|
|
156
|
+
});
|
|
157
|
+
} catch (err) {
|
|
158
|
+
throw err;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @name getPredictionMarketV2Contract
|
|
164
|
+
* @param {Address} ContractAddress (Opt) If it is deployed
|
|
165
|
+
* @description Create a PredictionMarketV2 Contract
|
|
166
|
+
*/
|
|
167
|
+
getPredictionMarketV2Contract({ contractAddress = null } = {}) {
|
|
168
|
+
try {
|
|
169
|
+
return new PredictionMarketV2Contract({
|
|
170
|
+
...this.contractDefaultParams(contractAddress)
|
|
171
|
+
});
|
|
172
|
+
} catch (err) {
|
|
173
|
+
throw err;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* @name getPredictionMarketV3Contract
|
|
179
|
+
* @param {Address} ContractAddress (Opt) If it is deployed
|
|
180
|
+
* @description Create a PredictionMarketV3 Contract
|
|
181
|
+
*/
|
|
182
|
+
getPredictionMarketV3Contract({ contractAddress = null, querierContractAddress = null } = {}) {
|
|
183
|
+
try {
|
|
184
|
+
return new PredictionMarketV3Contract({
|
|
185
|
+
...this.contractDefaultParams(contractAddress),
|
|
186
|
+
querierContractAddress,
|
|
187
|
+
});
|
|
188
|
+
} catch (err) {
|
|
189
|
+
throw err;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* @name getPredictionMarketV3FactoryContract
|
|
195
|
+
* @param {Address} ContractAddress (Opt) If it is deployed
|
|
196
|
+
* @description Create a PredictionMarketV3Factory Contract
|
|
197
|
+
*/
|
|
198
|
+
getPredictionMarketV3FactoryContract({ contractAddress = null } = {}) {
|
|
199
|
+
try {
|
|
200
|
+
return new PredictionMarketV3FactoryContract({
|
|
201
|
+
...this.contractDefaultParams(contractAddress)
|
|
202
|
+
});
|
|
203
|
+
} catch (err) {
|
|
204
|
+
throw err;
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* @name PredictionMarketV3ControllerContract
|
|
210
|
+
* @param {Address} ContractAddress (Opt) If it is deployed
|
|
211
|
+
* @description Create a PredictionMarketV3ControllerContract Contract
|
|
212
|
+
*/
|
|
213
|
+
getPredictionMarketV3ControllerContract({ contractAddress = null } = {}) {
|
|
214
|
+
try {
|
|
215
|
+
return new PredictionMarketV3ControllerContract({
|
|
216
|
+
...this.contractDefaultParams(contractAddress)
|
|
217
|
+
});
|
|
218
|
+
} catch (err) {
|
|
219
|
+
throw err;
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* @name getPredictionMarketV3ManagerContract
|
|
225
|
+
* @param {Address} ContractAddress (Opt) If it is deployed
|
|
226
|
+
* @description Create a PredictionMarketV3Manager Contract
|
|
227
|
+
*/
|
|
228
|
+
getPredictionMarketV3ManagerContract({ contractAddress = null } = {}) {
|
|
229
|
+
try {
|
|
230
|
+
return new PredictionMarketV3ManagerContract({
|
|
231
|
+
...this.contractDefaultParams(contractAddress)
|
|
232
|
+
});
|
|
233
|
+
} catch (err) {
|
|
234
|
+
throw err;
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* @name getAchievementsContract
|
|
240
|
+
* @param {Address} ContractAddress (Opt) If it is deployed
|
|
241
|
+
* @description Create a PredictionMarket Contract
|
|
242
|
+
*/
|
|
243
|
+
getAchievementsContract({
|
|
244
|
+
contractAddress = null,
|
|
245
|
+
predictionMarketContractAddress = null,
|
|
246
|
+
realitioERC20ContractAddress = null
|
|
247
|
+
} = {}) {
|
|
248
|
+
try {
|
|
249
|
+
return new AchievementsContract({
|
|
250
|
+
...this.contractDefaultParams(contractAddress),
|
|
251
|
+
predictionMarketContractAddress,
|
|
252
|
+
realitioERC20ContractAddress,
|
|
253
|
+
});
|
|
254
|
+
} catch (err) {
|
|
255
|
+
throw err;
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* @name getVotingContract
|
|
261
|
+
* @param {Address} ContractAddress (Opt) If it is deployed
|
|
262
|
+
* @description Create a Voting Contract
|
|
263
|
+
*/
|
|
264
|
+
getVotingContract({ contractAddress = null } = {}) {
|
|
265
|
+
try {
|
|
266
|
+
return new VotingContract({
|
|
267
|
+
...this.contractDefaultParams(contractAddress)
|
|
268
|
+
});
|
|
269
|
+
} catch (err) {
|
|
270
|
+
throw err;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* @name getFantasyERC20Contract
|
|
276
|
+
* @param {Address} ContractAddress (Opt) If it is deployed
|
|
277
|
+
* @description Create a Fantasy ERC20 Contract
|
|
278
|
+
*/
|
|
279
|
+
getFantasyERC20Contract({ contractAddress = null } = {}) {
|
|
280
|
+
try {
|
|
281
|
+
return new FantasyERC20Contract({
|
|
282
|
+
...this.contractDefaultParams(contractAddress)
|
|
283
|
+
});
|
|
284
|
+
} catch (err) {
|
|
285
|
+
throw err;
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* @name getRealitioERC20Contract
|
|
291
|
+
* @param {Address} ContractAddress (Opt) If it is deployed
|
|
292
|
+
* @description Create a RealitioERC20 Contract
|
|
293
|
+
*/
|
|
294
|
+
getRealitioERC20Contract({ contractAddress = null } = {}) {
|
|
295
|
+
try {
|
|
296
|
+
return new RealitioERC20Contract({
|
|
297
|
+
...this.contractDefaultParams(contractAddress)
|
|
298
|
+
});
|
|
299
|
+
} catch (err) {
|
|
300
|
+
throw err;
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* @name getERC20Contract
|
|
306
|
+
* @param {Address} ContractAddress (Opt) If it is deployed
|
|
307
|
+
* @description Create a ERC20 Contract
|
|
308
|
+
*/
|
|
309
|
+
getERC20Contract({ contractAddress = null }) {
|
|
310
|
+
try {
|
|
311
|
+
return new ERC20Contract({
|
|
312
|
+
...this.contractDefaultParams(contractAddress)
|
|
313
|
+
});
|
|
314
|
+
} catch (err) {
|
|
315
|
+
throw err;
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* @name getWETH9Contract
|
|
321
|
+
* @param {Address} ContractAddress (Opt) If it is deployed
|
|
322
|
+
* @description Create a WETH9 Contract
|
|
323
|
+
*/
|
|
324
|
+
getWETH9Contract({ contractAddress = null }) {
|
|
325
|
+
try {
|
|
326
|
+
return new WETH9Contract({
|
|
327
|
+
...this.contractDefaultParams(contractAddress)
|
|
328
|
+
});
|
|
329
|
+
} catch (err) {
|
|
330
|
+
throw err;
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* @name getArbitrationContract
|
|
336
|
+
* @param {Address} ContractAddress (Opt) If it is deployed
|
|
337
|
+
* @description Create a Arbitration Contract
|
|
338
|
+
*/
|
|
339
|
+
getArbitrationContract({ contractAddress = null }) {
|
|
340
|
+
try {
|
|
341
|
+
return new ArbitrationContract({
|
|
342
|
+
...this.contractDefaultParams(contractAddress)
|
|
343
|
+
});
|
|
344
|
+
} catch (err) {
|
|
345
|
+
throw err;
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* @name getArbitrationProxyContract
|
|
351
|
+
* @param {Address} ContractAddress (Opt) If it is deployed
|
|
352
|
+
* @description Create a Arbitration Proxy Contract
|
|
353
|
+
*/
|
|
354
|
+
getArbitrationProxyContract({ contractAddress = null }) {
|
|
355
|
+
try {
|
|
356
|
+
return new ArbitrationProxyContract({
|
|
357
|
+
...this.contractDefaultParams(contractAddress)
|
|
358
|
+
});
|
|
359
|
+
} catch (err) {
|
|
360
|
+
throw err;
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
/***********/
|
|
365
|
+
/** UTILS **/
|
|
366
|
+
/***********/
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* @name getETHNetwork
|
|
370
|
+
* @description Access current ETH Network used
|
|
371
|
+
* @returns {String} Eth Network
|
|
372
|
+
*/
|
|
373
|
+
async getETHNetwork() {
|
|
374
|
+
const netId = await this.web3.eth.net.getId();
|
|
375
|
+
const networkName = networksEnum.hasOwnProperty(netId)
|
|
376
|
+
? networksEnum[netId]
|
|
377
|
+
: "Unknown";
|
|
378
|
+
return networkName;
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* @name getAddress
|
|
383
|
+
* @description Access current Address Being Used under Web3 Injector (ex : Metamask)
|
|
384
|
+
* @returns {Address} Address
|
|
385
|
+
*/
|
|
386
|
+
async getAddress() {
|
|
387
|
+
if (this.isSocialLogin) {
|
|
388
|
+
if (this.smartAccount && this.smartAccount.provider) {
|
|
389
|
+
return await this.smartAccount.getAddress();
|
|
390
|
+
}
|
|
391
|
+
return '';
|
|
392
|
+
} else {
|
|
393
|
+
const accounts = await this.web3.eth.getAccounts();
|
|
394
|
+
return accounts[0];
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* @name getETHBalance
|
|
400
|
+
* @description Access current ETH Balance Available for the Injected Web3 Address
|
|
401
|
+
* @returns {Integer} Balance
|
|
402
|
+
*/
|
|
403
|
+
async getETHBalance() {
|
|
404
|
+
const address = await this.getAddress();
|
|
405
|
+
let wei = await window.web3.eth.getBalance(address);
|
|
406
|
+
return this.web3.utils.fromWei(wei, "ether");
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
async socialLoginWithJWT(id, jwtToken) {
|
|
410
|
+
throw new Error("Not implemented");
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
async socialLoginLogout() {
|
|
414
|
+
if (this.smartAccount) {
|
|
415
|
+
PolkamarketsSmartAccount.singleton.clearInstance();
|
|
416
|
+
this.smartAccount = null;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
module.exports = Application;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
let index = {
|
|
2
|
+
achievements: require("../../build/contracts/Achievements.json"),
|
|
3
|
+
arbitration: require("../../build/contracts/RealitioForeignArbitrationProxyWithAppeals.json"),
|
|
4
|
+
arbitrationProxy: require("../../build/contracts/RealitioHomeArbitrationProxy.json"),
|
|
5
|
+
fantasyerc20: require("../../build/contracts/FantasyERC20.json"),
|
|
6
|
+
ierc20: require("../../build/contracts/ERC20PresetMinterPauser.json"),
|
|
7
|
+
prediction: require("../../build/contracts/PredictionMarket.json"),
|
|
8
|
+
predictionV2: require("../../build/contracts/PredictionMarketV2.json"),
|
|
9
|
+
predictionV3: require("../../build/contracts/PredictionMarketV3.json"),
|
|
10
|
+
predictionV3Manager: require("../../build/contracts/PredictionMarketV3Manager.json"),
|
|
11
|
+
predictionV3Controller: require("../../build/contracts/PredictionMarketV3Controller.json"),
|
|
12
|
+
predictionMarketV3Factory: require("../../build/contracts/PredictionMarketV3Factory.json"),
|
|
13
|
+
predictionV3Querier: require("../../build/contracts/PredictionMarketV3Querier.json"),
|
|
14
|
+
realitio: require("../../build/contracts/RealitioERC20.json"),
|
|
15
|
+
voting: require("../../build/contracts/Voting.json"),
|
|
16
|
+
weth: require("../../build/contracts/WETH9.json"),
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
module.exports = index;
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
const achievements = require("../interfaces").achievements;
|
|
2
|
+
|
|
3
|
+
const Numbers = require("../utils/Numbers");
|
|
4
|
+
const IContract = require('./IContract');
|
|
5
|
+
const PredictionMarketContract = require('./PredictionMarketContract');
|
|
6
|
+
const RealitioERC20Contract = require('./RealitioERC20Contract');
|
|
7
|
+
|
|
8
|
+
const axios = require('axios');
|
|
9
|
+
|
|
10
|
+
const actions = {
|
|
11
|
+
0: 'Buy',
|
|
12
|
+
1: 'Add Liquidity',
|
|
13
|
+
2: 'Bond',
|
|
14
|
+
3: 'Claim Winnings',
|
|
15
|
+
4: 'Create Market',
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* PredictionMarket Contract Object
|
|
20
|
+
* @constructor PredictionMarketContract
|
|
21
|
+
* @param {Web3} web3
|
|
22
|
+
* @param {Integer} decimals
|
|
23
|
+
* @param {Address} contractAddress
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
class AchievementsContract extends IContract {
|
|
27
|
+
constructor(params) {
|
|
28
|
+
super({ abi: achievements, ...params });
|
|
29
|
+
this.contractName = 'achievements';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async getUserStats({ user }) {
|
|
33
|
+
await this.initializePredictionMarketContract();
|
|
34
|
+
await this.initializeRealitioERC20Contract();
|
|
35
|
+
|
|
36
|
+
const portfolio = await this.predictionMarket.getPortfolio({ user });
|
|
37
|
+
// fetching unique buy actions per market
|
|
38
|
+
const buyMarkets = Object.keys(portfolio).filter(marketId => {
|
|
39
|
+
return portfolio[marketId].outcomes[0].shares > 0 || portfolio[marketId].outcomes[1].shares > 0
|
|
40
|
+
});
|
|
41
|
+
// fetching unique liquidity actions per market
|
|
42
|
+
const liquidityMarkets = Object.keys(portfolio).filter(marketId => portfolio[marketId].liquidity.shares > 0);
|
|
43
|
+
// fetching unique claim winnings actions per market
|
|
44
|
+
const winningsMarkets = Object.keys(portfolio).filter(marketId => portfolio[marketId].claimStatus.winningsClaimed);
|
|
45
|
+
|
|
46
|
+
// fetching create market actions
|
|
47
|
+
const createMarketEvents = await this.predictionMarket.getEvents('MarketCreated', { user });
|
|
48
|
+
|
|
49
|
+
// fetching unique bonds actions per market
|
|
50
|
+
const bondsEvents = await this.realitioERC20.getEvents('LogNewAnswer', { user });
|
|
51
|
+
const bondsQuestions = bondsEvents.map(e => e.returnValues.question_id).filter((x, i, a) => a.indexOf(x) == i);
|
|
52
|
+
let bondsMarkets = [];
|
|
53
|
+
|
|
54
|
+
if (bondsQuestions.length > 0) {
|
|
55
|
+
// filtering by bonds placed in PredictionMarket contract
|
|
56
|
+
// TODO: optimize this
|
|
57
|
+
const allMarketIds = await this.predictionMarket.getMarkets();
|
|
58
|
+
const allMarketQuestions = await Promise.all(allMarketIds.map(async marketId => {
|
|
59
|
+
const questionId = await this.predictionMarket.getMarketQuestionId({ marketId });
|
|
60
|
+
return questionId;
|
|
61
|
+
}));
|
|
62
|
+
|
|
63
|
+
const marketQuestions = bondsQuestions.filter(questionId => allMarketQuestions.includes(questionId));
|
|
64
|
+
bondsMarkets = marketQuestions.map(questionId => allMarketQuestions.indexOf(questionId));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// returning stats mapped by action id
|
|
68
|
+
return {
|
|
69
|
+
0: { markets: buyMarkets, occurrences: buyMarkets.length },
|
|
70
|
+
1: { markets: liquidityMarkets, occurrences: liquidityMarkets.length },
|
|
71
|
+
2: { markets: bondsMarkets, occurrences: bondsMarkets.length },
|
|
72
|
+
3: { markets: winningsMarkets, occurrences: winningsMarkets.length },
|
|
73
|
+
4: { markets: createMarketEvents.map(e => e.returnValues.marketId), occurrences: createMarketEvents.length },
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async getAchievementIds() {
|
|
78
|
+
const achievementIndex = await this.getContract().methods.achievementIndex().call();
|
|
79
|
+
|
|
80
|
+
return [...Array(parseInt(achievementIndex)).keys()];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async getAchievement({ achievementId }) {
|
|
84
|
+
const achievement = await this.getContract().methods.achievements(achievementId).call();
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
action: actions[Numbers.fromBigNumberToInteger(achievement[0], 18)],
|
|
88
|
+
actionId: Numbers.fromBigNumberToInteger(achievement[0], 18),
|
|
89
|
+
occurrences: Numbers.fromBigNumberToInteger(achievement[1], 18)
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async getUserAchievements({ user }) {
|
|
94
|
+
const achievementIds = await this.getAchievementIds();
|
|
95
|
+
const userStats = await this.getUserStats({ user });
|
|
96
|
+
let userTokens;
|
|
97
|
+
try {
|
|
98
|
+
userTokens = await this.getUserTokens({ user });
|
|
99
|
+
} catch (err) {
|
|
100
|
+
// should be non-blocking
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return await achievementIds.reduce(async (obj, achievementId) => {
|
|
104
|
+
const achievement = await this.getAchievement({ achievementId });
|
|
105
|
+
const canClaim = userStats[achievement.actionId].occurrences >= achievement.occurrences;
|
|
106
|
+
const claimed = canClaim && (await this.getContract().methods.hasUserClaimedAchievement(user, achievementId).call());
|
|
107
|
+
const token = userTokens && userTokens.find(token => token.achievementId == achievementId);
|
|
108
|
+
|
|
109
|
+
const status = {
|
|
110
|
+
canClaim,
|
|
111
|
+
claimed,
|
|
112
|
+
token
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return await {
|
|
116
|
+
...(await obj),
|
|
117
|
+
[achievementId]: status,
|
|
118
|
+
};
|
|
119
|
+
}, {});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async getUserTokens({ user }) {
|
|
123
|
+
const tokenCount = await this.getContract().methods.balanceOf(user).call();
|
|
124
|
+
const tokens = [];
|
|
125
|
+
|
|
126
|
+
for (let i = 0; i < tokenCount; i++) {
|
|
127
|
+
const tokenIndex = await this.getContract().methods.tokenOfOwnerByIndex(user, i).call();
|
|
128
|
+
const tokenAchievement = await this.getContract().methods.tokens(tokenIndex).call();
|
|
129
|
+
const tokenURI = await this.getContract().methods.tokenURI(tokenIndex).call();
|
|
130
|
+
const { data } = await axios.get(tokenURI);
|
|
131
|
+
|
|
132
|
+
tokens.push({
|
|
133
|
+
id: tokenIndex,
|
|
134
|
+
achievementId: tokenAchievement,
|
|
135
|
+
uri: tokenURI,
|
|
136
|
+
data
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return tokens;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async claimAchievement({ achievementId }) {
|
|
144
|
+
const user = await this.getMyAccount();
|
|
145
|
+
if (!user) return false;
|
|
146
|
+
|
|
147
|
+
const achievement = await this.getAchievement({ achievementId });
|
|
148
|
+
const userStats = await this.getUserStats({ user });
|
|
149
|
+
|
|
150
|
+
// user not eligible to claim
|
|
151
|
+
if (userStats[achievement.actionId].occurrences < achievement.occurrences) return false;
|
|
152
|
+
|
|
153
|
+
if (achievement.actionId == 2) {
|
|
154
|
+
const marketIds = userStats[achievement.actionId].markets.slice(0, achievement.occurrences);
|
|
155
|
+
const lengths = [];
|
|
156
|
+
const hhashes = [];
|
|
157
|
+
const addrs = [];
|
|
158
|
+
const bonds = [];
|
|
159
|
+
const answers = [];
|
|
160
|
+
|
|
161
|
+
for (const marketId of marketIds) {
|
|
162
|
+
const questionId = await this.predictionMarket.getMarketQuestionId({ marketId });
|
|
163
|
+
const events = await this.realitioERC20.getEvents('LogNewAnswer', { question_id: questionId });
|
|
164
|
+
|
|
165
|
+
hhashes.push(...events.map((event) => event.returnValues.history_hash).slice(0, -1).reverse());
|
|
166
|
+
// adding an empty hash to the history hashes
|
|
167
|
+
hhashes.push(Numbers.nullHash());
|
|
168
|
+
|
|
169
|
+
addrs.push(...events.map((event) => event.returnValues.user).reverse());
|
|
170
|
+
bonds.push(...events.map((event) => event.returnValues.bond).reverse());
|
|
171
|
+
answers.push(...events.map((event) => event.returnValues.answer).reverse());
|
|
172
|
+
lengths.push(events.length);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return await this.__sendTx(
|
|
176
|
+
this.getContract().methods.claimAchievement(
|
|
177
|
+
achievementId,
|
|
178
|
+
marketIds,
|
|
179
|
+
lengths,
|
|
180
|
+
hhashes,
|
|
181
|
+
addrs,
|
|
182
|
+
bonds,
|
|
183
|
+
answers
|
|
184
|
+
),
|
|
185
|
+
false
|
|
186
|
+
);
|
|
187
|
+
} else {
|
|
188
|
+
return await this.__sendTx(
|
|
189
|
+
this.getContract().methods.claimAchievement(
|
|
190
|
+
achievementId,
|
|
191
|
+
userStats[achievement.actionId].markets.slice(0, achievement.occurrences)
|
|
192
|
+
),
|
|
193
|
+
false,
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async initializePredictionMarketContract() {
|
|
199
|
+
// predictionMarket already initialized
|
|
200
|
+
if (this.predictionMarket) return;
|
|
201
|
+
|
|
202
|
+
const contractAddress = await this.getContract().methods.predictionMarket().call();
|
|
203
|
+
|
|
204
|
+
this.predictionMarket = new PredictionMarketContract({ ...this.params, contractAddress });
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
async initializeRealitioERC20Contract() {
|
|
208
|
+
// predictionMarket already initialized
|
|
209
|
+
if (this.realitioERC20) return;
|
|
210
|
+
|
|
211
|
+
const contractAddress = await this.getContract().methods.realitioERC20().call();
|
|
212
|
+
|
|
213
|
+
this.realitioERC20 = new RealitioERC20Contract({ ...this.params, contractAddress });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
module.exports = AchievementsContract;
|