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.
- 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 -436
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
const predictionV3 = require("../interfaces").predictionV3;
|
|
2
|
+
const PredictionMarketV2Contract = require("./PredictionMarketV2Contract");
|
|
3
|
+
const PredictionMarketV3QuerierContract = require("./PredictionMarketV3QuerierContract");
|
|
4
|
+
|
|
5
|
+
const Numbers = require('../utils/Numbers');
|
|
6
|
+
|
|
7
|
+
class PredictionMarketV3Contract extends PredictionMarketV2Contract {
|
|
8
|
+
constructor(params) {
|
|
9
|
+
super({ abi: predictionV3, ...params });
|
|
10
|
+
this.contractName = 'predictionMarketV3';
|
|
11
|
+
if (params.defaultDecimals) {
|
|
12
|
+
this.defaultDecimals = params.defaultDecimals;
|
|
13
|
+
}
|
|
14
|
+
if (params.querierContractAddress) {
|
|
15
|
+
this.querier = new PredictionMarketV3QuerierContract({
|
|
16
|
+
...this.params,
|
|
17
|
+
contractAddress: params.querierContractAddress
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async mintAndCreateMarket ({
|
|
23
|
+
value,
|
|
24
|
+
name,
|
|
25
|
+
description = '',
|
|
26
|
+
image,
|
|
27
|
+
duration,
|
|
28
|
+
oracleAddress,
|
|
29
|
+
outcomes,
|
|
30
|
+
category,
|
|
31
|
+
token,
|
|
32
|
+
odds = [],
|
|
33
|
+
fee = 0,
|
|
34
|
+
treasuryFee = 0,
|
|
35
|
+
treasury = '0x0000000000000000000000000000000000000000',
|
|
36
|
+
realitioAddress,
|
|
37
|
+
realitioTimeout,
|
|
38
|
+
PM3ManagerAddress
|
|
39
|
+
}) {
|
|
40
|
+
const desc = await this.prepareCreateMarketDescription({
|
|
41
|
+
value,
|
|
42
|
+
name,
|
|
43
|
+
description,
|
|
44
|
+
image,
|
|
45
|
+
duration,
|
|
46
|
+
oracleAddress,
|
|
47
|
+
outcomes,
|
|
48
|
+
category,
|
|
49
|
+
token,
|
|
50
|
+
odds,
|
|
51
|
+
fee,
|
|
52
|
+
treasuryFee,
|
|
53
|
+
treasury,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return await this.__sendTx(this.getContract().methods.mintAndCreateMarket({
|
|
57
|
+
...desc,
|
|
58
|
+
realitio: realitioAddress,
|
|
59
|
+
realitioTimeout,
|
|
60
|
+
manager: PM3ManagerAddress
|
|
61
|
+
}));
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
async createMarket ({
|
|
65
|
+
value,
|
|
66
|
+
name,
|
|
67
|
+
description = '',
|
|
68
|
+
image,
|
|
69
|
+
duration,
|
|
70
|
+
oracleAddress,
|
|
71
|
+
outcomes,
|
|
72
|
+
category,
|
|
73
|
+
token,
|
|
74
|
+
odds = [],
|
|
75
|
+
fee = 0,
|
|
76
|
+
treasuryFee = 0,
|
|
77
|
+
treasury = '0x0000000000000000000000000000000000000000',
|
|
78
|
+
realitioAddress,
|
|
79
|
+
realitioTimeout,
|
|
80
|
+
PM3ManagerAddress
|
|
81
|
+
}) {
|
|
82
|
+
const desc = await this.prepareCreateMarketDescription({
|
|
83
|
+
value,
|
|
84
|
+
name,
|
|
85
|
+
description,
|
|
86
|
+
image,
|
|
87
|
+
duration,
|
|
88
|
+
oracleAddress,
|
|
89
|
+
outcomes,
|
|
90
|
+
category,
|
|
91
|
+
token,
|
|
92
|
+
odds,
|
|
93
|
+
fee,
|
|
94
|
+
treasuryFee,
|
|
95
|
+
treasury,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
return await this.__sendTx(this.getContract().methods.createMarket({
|
|
99
|
+
...desc,
|
|
100
|
+
realitio: realitioAddress,
|
|
101
|
+
realitioTimeout,
|
|
102
|
+
manager: PM3ManagerAddress
|
|
103
|
+
}));
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
async createMarketWithETH ({
|
|
107
|
+
value,
|
|
108
|
+
name,
|
|
109
|
+
description = '',
|
|
110
|
+
image,
|
|
111
|
+
duration,
|
|
112
|
+
oracleAddress,
|
|
113
|
+
outcomes,
|
|
114
|
+
category,
|
|
115
|
+
odds = [],
|
|
116
|
+
fee = 0,
|
|
117
|
+
treasuryFee = 0,
|
|
118
|
+
treasury = '0x0000000000000000000000000000000000000000',
|
|
119
|
+
realitioAddress,
|
|
120
|
+
realitioTimeout,
|
|
121
|
+
PM3ManagerAddress
|
|
122
|
+
}) {
|
|
123
|
+
const token = await this.getWETHAddress();
|
|
124
|
+
const desc = await this.prepareCreateMarketDescription({
|
|
125
|
+
value,
|
|
126
|
+
name,
|
|
127
|
+
description,
|
|
128
|
+
image,
|
|
129
|
+
duration,
|
|
130
|
+
oracleAddress,
|
|
131
|
+
outcomes,
|
|
132
|
+
category,
|
|
133
|
+
token,
|
|
134
|
+
odds,
|
|
135
|
+
fee,
|
|
136
|
+
treasuryFee,
|
|
137
|
+
treasury,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
return await this.__sendTx(
|
|
141
|
+
this.getContract().methods.createMarketWithETH({
|
|
142
|
+
...desc,
|
|
143
|
+
realitio: realitioAddress,
|
|
144
|
+
realitioTimeout,
|
|
145
|
+
manager: PM3ManagerAddress
|
|
146
|
+
}),
|
|
147
|
+
false,
|
|
148
|
+
desc.value
|
|
149
|
+
);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
async adminResolveMarketOutcome({marketId, outcomeId}) {
|
|
153
|
+
return await this.__sendTx(
|
|
154
|
+
this.getContract().methods.adminResolveMarketOutcome(marketId, outcomeId),
|
|
155
|
+
false,
|
|
156
|
+
);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
async getPortfolio({ user }) {
|
|
160
|
+
if (!this.querier) {
|
|
161
|
+
return super.getPortfolio({ user });
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
let events = [];
|
|
165
|
+
try {
|
|
166
|
+
events = await this.getActions({ user });
|
|
167
|
+
} catch (err) {
|
|
168
|
+
// should be non-blocking
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const userMarketsData = await this.querier.getUserAllMarketsData({ user });
|
|
172
|
+
const marketIds = Object.keys(userMarketsData).map(Number);
|
|
173
|
+
// fetching all markets decimals asynchrounously
|
|
174
|
+
const marketDecimals = await Promise.all(marketIds.map(marketId => this.getMarketDecimals({ marketId })));
|
|
175
|
+
|
|
176
|
+
const portfolio = marketIds.reduce((obj, marketId) => {
|
|
177
|
+
const marketData = userMarketsData[marketId];
|
|
178
|
+
const decimals = marketDecimals[marketIds.indexOf(marketId)];
|
|
179
|
+
|
|
180
|
+
const outcomeShares = Object.fromEntries(marketData.outcomeShares.map((item, index) => {
|
|
181
|
+
return [
|
|
182
|
+
index,
|
|
183
|
+
{
|
|
184
|
+
shares: Numbers.fromDecimalsNumber(item, decimals),
|
|
185
|
+
price: this.getAverageOutcomeBuyPrice({events, marketId, outcomeId: index})
|
|
186
|
+
}
|
|
187
|
+
];
|
|
188
|
+
}));
|
|
189
|
+
|
|
190
|
+
const item = {
|
|
191
|
+
liquidity: {
|
|
192
|
+
shares: Numbers.fromDecimalsNumber(marketData.liquidityShares, decimals),
|
|
193
|
+
price: this.getAverageAddLiquidityPrice({events, marketId}),
|
|
194
|
+
},
|
|
195
|
+
outcomes: outcomeShares,
|
|
196
|
+
claimStatus: {
|
|
197
|
+
winningsToClaim: marketData.winningsToClaim,
|
|
198
|
+
winningsClaimed: marketData.winningsClaimed,
|
|
199
|
+
liquidityToClaim: marketData.liquidityToClaim,
|
|
200
|
+
liquidityClaimed: marketData.liquidityClaimed,
|
|
201
|
+
voidedWinningsToClaim: marketData.voidedSharesToClaim,
|
|
202
|
+
voidedWinningsClaimed: false,
|
|
203
|
+
liquidityFees: 0 // discontinued
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
return {
|
|
208
|
+
...obj,
|
|
209
|
+
[marketId]: item
|
|
210
|
+
};
|
|
211
|
+
}, {});
|
|
212
|
+
|
|
213
|
+
// calculationg voidedWinningsClaimed, if there's any voidedWinningsToClaim
|
|
214
|
+
Object.keys(portfolio).map(Number).forEach(marketId => {
|
|
215
|
+
const item = portfolio[marketId];
|
|
216
|
+
if (item.claimStatus.voidedWinningsToClaim) {
|
|
217
|
+
item.claimStatus.voidedWinningsClaimed =
|
|
218
|
+
events.some(event => event.action === 'Claim Voided' && event.marketId === marketId);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
return portfolio;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
async adminResolveMarketOutcome({marketId, outcomeId}) {
|
|
226
|
+
return await this.__sendTx(
|
|
227
|
+
this.getContract().methods.adminResolveMarketOutcome(marketId, outcomeId),
|
|
228
|
+
false,
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
module.exports = PredictionMarketV3Contract;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
const IContract = require('./IContract');
|
|
2
|
+
|
|
3
|
+
const predictionV3Controller = require("../interfaces").predictionV3Controller;
|
|
4
|
+
|
|
5
|
+
const Numbers = require('../utils/Numbers');
|
|
6
|
+
|
|
7
|
+
class PredictionMarketV3ControllerContract extends IContract {
|
|
8
|
+
constructor(params) {
|
|
9
|
+
super({ abi: predictionV3Controller, ...params });
|
|
10
|
+
this.contractName = 'PredictionMarketV3Controller';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async getLandById({ id }) {
|
|
14
|
+
const token = await this.getContract().methods.landTokens(id).call();
|
|
15
|
+
|
|
16
|
+
return await this.getLandByAddress({ token });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async getLandByAddress({ token }) {
|
|
20
|
+
const res = await this.getContract().methods.lands(token).call();
|
|
21
|
+
const landPermissions = await this.getContract().methods.landPermissions(token).call();
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
token: res.token,
|
|
25
|
+
active: res.active,
|
|
26
|
+
realitio: res.realitio,
|
|
27
|
+
everyoneCanCreateMarkets: landPermissions.openMarketCreation
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async getLandTokensLength() {
|
|
32
|
+
const index = await this.getContract().methods.landTokensLength().call();
|
|
33
|
+
|
|
34
|
+
return parseInt(index);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async isAllowedToCreateMarket({ token, user }) {
|
|
38
|
+
return await this.params.contract.getContract().methods.isAllowedToCreateMarket(token, user).call();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async isAllowedToResolveMarket({ token, user }) {
|
|
42
|
+
return await this.params.contract.getContract().methods.isAllowedToResolveMarket(token, user).call();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async isIERC20TokenSocial({ token }) {
|
|
46
|
+
return await this.params.contract.getContract().methods.isIERC20TokenSocial(token, user).call();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async isLandAdmin({ token, user }) {
|
|
50
|
+
return await this.params.contract.getContract().methods.isLandAdmin(token, user).call();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async createLand({ name, symbol, tokenAmountToClaim, tokenToAnswer, everyoneCanCreateMarkets }) {
|
|
54
|
+
const transaction = await this.__sendTx(
|
|
55
|
+
this.getContract().methods.createLand(
|
|
56
|
+
name,
|
|
57
|
+
symbol,
|
|
58
|
+
Numbers.toSmartContractDecimals(tokenAmountToClaim, 18),
|
|
59
|
+
tokenToAnswer
|
|
60
|
+
)
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const token = transaction.events.LandCreated[0].returnValues.token;
|
|
64
|
+
|
|
65
|
+
// fetching land on index
|
|
66
|
+
const land = await this.getLandByAddress({ token });
|
|
67
|
+
|
|
68
|
+
if (everyoneCanCreateMarkets) {
|
|
69
|
+
await this.__sendTx(
|
|
70
|
+
this.getContract().methods.setLandEveryoneCanCreateMarkets(land.token, everyoneCanCreateMarkets)
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return land;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
async disableLand({ token }) {
|
|
78
|
+
return await this.__sendTx(
|
|
79
|
+
this.getContract().methods.disableLand(token)
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async enableLand({ token }) {
|
|
84
|
+
return await this.__sendTx(
|
|
85
|
+
this.getContract().methods.enableLand(token)
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async addAdminToLand({ token, user }) {
|
|
90
|
+
return await this.__sendTx(
|
|
91
|
+
this.getContract().methods.addAdminToLand(token, user)
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async removeAdminFromLand({ token, user }) {
|
|
96
|
+
return await this.__sendTx(
|
|
97
|
+
this.getContract().methods.removeAdminFromLand(token, user)
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
module.exports = PredictionMarketV3ControllerContract;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
const IContract = require('./IContract');
|
|
2
|
+
|
|
3
|
+
const predictionMarketFactory = require("../interfaces").predictionMarketV3Factory;
|
|
4
|
+
|
|
5
|
+
const Numbers = require('../utils/Numbers');
|
|
6
|
+
|
|
7
|
+
class PredictionMarketV3FactoryContract extends IContract {
|
|
8
|
+
constructor(params) {
|
|
9
|
+
super({ abi: predictionMarketFactory, ...params });
|
|
10
|
+
this.contractName = 'PredictionMarketFactory';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async getPMControllerById({ id }) {
|
|
14
|
+
const controllerAddress = await this.getPMControllerAddressById({ id });
|
|
15
|
+
|
|
16
|
+
return await this.getPMControllerByAddress({ controllerAddress });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async getPMControllerAddressById({ id }) {
|
|
20
|
+
return this.getContract().methods.controllersAddresses(id).call();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async getPMControllerByAddress({ controllerAddress }) {
|
|
24
|
+
const res = await this.getContract().methods.controllers(controllerAddress).call();
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
active: res.active,
|
|
28
|
+
lockAmount: Numbers.fromDecimalsNumber(res.lockAmount, 18),
|
|
29
|
+
lockUser: res.lockUser,
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async getControllersLength() {
|
|
34
|
+
const index = await this.getContract().methods.controllersLength().call();
|
|
35
|
+
|
|
36
|
+
return parseInt(index);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async isPMControllerAdmin({ controllerAddress, user }) {
|
|
40
|
+
return await this.params.contract.getContract().methods.isPMControllerAdmin(controllerAddress, user).call();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async lockAmount() {
|
|
44
|
+
const amount = await this.params.contract.getContract().methods.lockAmount().call();
|
|
45
|
+
// TODO: fetch ERC20 decimals
|
|
46
|
+
return Numbers.fromDecimalsNumber(amount, 18);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async updateLockAmount({ amount }) {
|
|
50
|
+
return await this.__sendTx(
|
|
51
|
+
this.getContract().methods.updateLockAmount(Numbers.toSmartContractDecimals(amount, 18))
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async createPMController({
|
|
56
|
+
PMV3,
|
|
57
|
+
}) {
|
|
58
|
+
return await this.__sendTx(
|
|
59
|
+
this.getContract().methods.createPMController(
|
|
60
|
+
PMV3,
|
|
61
|
+
)
|
|
62
|
+
);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
async disablePMController({ controllerAddress }) {
|
|
66
|
+
return await this.__sendTx(
|
|
67
|
+
this.getContract().methods.disablePMController(controllerAddress)
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async enablePMController({ controllerAddress }) {
|
|
72
|
+
return await this.__sendTx(
|
|
73
|
+
this.getContract().methods.enablePMController(controllerAddress)
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async unlockOffsetFromPMController({ controllerAddress }) {
|
|
78
|
+
return await this.__sendTx(
|
|
79
|
+
this.getContract().methods.unlockOffsetFromPMController(controllerAddress)
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async addAdminToPMController({ controllerAddress, user }) {
|
|
84
|
+
return await this.__sendTx(
|
|
85
|
+
this.getContract().methods.addAdminToPMController(controllerAddress, user)
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async removeAdminFromPMController({ controllerAddress, user }) {
|
|
90
|
+
return await this.__sendTx(
|
|
91
|
+
this.getContract().methods.removeAdminFromPMController(controllerAddress, user)
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
module.exports = PredictionMarketV3FactoryContract;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
const IContract = require('./IContract');
|
|
2
|
+
|
|
3
|
+
const predictionV3Manager = require("../interfaces").predictionV3Manager;
|
|
4
|
+
|
|
5
|
+
const Numbers = require('../utils/Numbers');
|
|
6
|
+
|
|
7
|
+
class PredictionMarketV3ManagerContract extends IContract {
|
|
8
|
+
constructor(params) {
|
|
9
|
+
super({ abi: predictionV3Manager, ...params });
|
|
10
|
+
this.contractName = 'PredictionMarketV3Manager';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async getLandById({ id }) {
|
|
14
|
+
const token = await this.getContract().methods.landTokens(id).call();
|
|
15
|
+
|
|
16
|
+
return await this.getLandByAddress({ token });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async getLandByAddress({ token }) {
|
|
20
|
+
const res = await this.getContract().methods.lands(token).call();
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
token: res.token,
|
|
24
|
+
active: res.active,
|
|
25
|
+
lockAmount: Numbers.fromDecimalsNumber(res.lockAmount, 18),
|
|
26
|
+
lockUser: res.lockUser,
|
|
27
|
+
realitio: res.realitio,
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async getLandTokensLength() {
|
|
32
|
+
const index = await this.getContract().methods.landTokensLength().call();
|
|
33
|
+
|
|
34
|
+
return parseInt(index);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async isAllowedToCreateMarket({ token, user }) {
|
|
38
|
+
return await this.params.contract.getContract().methods.isAllowedToCreateMarket(token, user).call();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async isAllowedToResolveMarket({ token, user }) {
|
|
42
|
+
return await this.params.contract.getContract().methods.isAllowedToResolveMarket(token, user).call();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async isIERC20TokenSocial({ token }) {
|
|
46
|
+
return await this.params.contract.getContract().methods.isIERC20TokenSocial(token, user).call();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async isLandAdmin({ token, user }) {
|
|
50
|
+
return await this.params.contract.getContract().methods.isLandAdmin(token, user).call();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async lockAmount() {
|
|
54
|
+
const amount = await this.params.contract.getContract().methods.lockAmount().call();
|
|
55
|
+
// TODO: fetch ERC20 decimals
|
|
56
|
+
return Numbers.fromDecimalsNumber(amount, 18);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async lockToken() {
|
|
60
|
+
return await this.params.contract.getContract().methods.token().call();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async updateLockAmount({ amount }) {
|
|
64
|
+
return await this.__sendTx(
|
|
65
|
+
this.getContract().methods.updateLockAmount(Numbers.toSmartContractDecimals(amount, 18))
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async createLand({ name, symbol, tokenAmountToClaim, tokenToAnswer }) {
|
|
70
|
+
return await this.__sendTx(
|
|
71
|
+
this.getContract().methods.createLand(
|
|
72
|
+
name,
|
|
73
|
+
symbol,
|
|
74
|
+
Numbers.toSmartContractDecimals(tokenAmountToClaim, 18),
|
|
75
|
+
tokenToAnswer
|
|
76
|
+
)
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
async disableLand({ token }) {
|
|
81
|
+
return await this.__sendTx(
|
|
82
|
+
this.getContract().methods.disableLand(token)
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async enableLand({ token }) {
|
|
87
|
+
return await this.__sendTx(
|
|
88
|
+
this.getContract().methods.enableLand(token)
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async unlockOffsetFromLand({ token }) {
|
|
93
|
+
return await this.__sendTx(
|
|
94
|
+
this.getContract().methods.unlockOffsetFromLand(token)
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async addAdminToLand({ token, user }) {
|
|
99
|
+
return await this.__sendTx(
|
|
100
|
+
this.getContract().methods.addAdminToLand(token, user)
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async removeAdminFromLand({ token, user }) {
|
|
105
|
+
return await this.__sendTx(
|
|
106
|
+
this.getContract().methods.removeAdminFromLand(token, user)
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
module.exports = PredictionMarketV3ManagerContract;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const IContract = require('./IContract');
|
|
2
|
+
|
|
3
|
+
const predictionV3Querier = require("../interfaces").predictionV3Querier;
|
|
4
|
+
|
|
5
|
+
class PredictionMarketV3QuerierContract extends IContract {
|
|
6
|
+
constructor(params) {
|
|
7
|
+
super({ ...params, abi: predictionV3Querier });
|
|
8
|
+
this.contractName = 'PredictionMarketV3Querier';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async getUserMarketsData({ user, marketId }) {
|
|
12
|
+
return await this.params.contract.getContract().methods.getUserMarketData(user, marketId).call();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async getUserMarketsData({ user, marketIds }) {
|
|
16
|
+
return await this.params.contract.getContract().methods.getUserMarketsData(user, marketIds).call();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async getUserAllMarketsData({ user }) {
|
|
20
|
+
return await this.params.contract.getContract().methods.getUserAllMarketsData(user).call();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = PredictionMarketV3QuerierContract;
|