polkamarkets-js 1.0.2 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/hardhat.config.js +4 -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 +256 -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,207 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.18;
|
|
3
|
+
|
|
4
|
+
interface IPredictionMarketV3 {
|
|
5
|
+
struct CreateMarketDescription {
|
|
6
|
+
uint256 value;
|
|
7
|
+
uint256 closesAt;
|
|
8
|
+
uint256 outcomes;
|
|
9
|
+
address token;
|
|
10
|
+
uint256[] distribution;
|
|
11
|
+
string question;
|
|
12
|
+
string image;
|
|
13
|
+
address arbitrator;
|
|
14
|
+
uint256 fee;
|
|
15
|
+
uint256 treasuryFee;
|
|
16
|
+
address treasury;
|
|
17
|
+
address realitio;
|
|
18
|
+
uint256 realitioTimeout;
|
|
19
|
+
address manager;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
event MarketActionTx(
|
|
23
|
+
address indexed user,
|
|
24
|
+
uint8 indexed action,
|
|
25
|
+
uint256 indexed marketId,
|
|
26
|
+
uint256 outcomeId,
|
|
27
|
+
uint256 shares,
|
|
28
|
+
uint256 value,
|
|
29
|
+
uint256 timestamp
|
|
30
|
+
);
|
|
31
|
+
event MarketCreated(
|
|
32
|
+
address indexed user,
|
|
33
|
+
uint256 indexed marketId,
|
|
34
|
+
uint256 outcomes,
|
|
35
|
+
string question,
|
|
36
|
+
string image,
|
|
37
|
+
address token
|
|
38
|
+
);
|
|
39
|
+
event MarketLiquidity(uint256 indexed marketId, uint256 value, uint256 price, uint256 timestamp);
|
|
40
|
+
event MarketOutcomePrice(uint256 indexed marketId, uint256 indexed outcomeId, uint256 value, uint256 timestamp);
|
|
41
|
+
event MarketOutcomeShares(uint256 indexed marketId, uint256 timestamp, uint256[] outcomeShares, uint256 liquidity);
|
|
42
|
+
event MarketResolved(
|
|
43
|
+
address indexed user,
|
|
44
|
+
uint256 indexed marketId,
|
|
45
|
+
uint256 outcomeId,
|
|
46
|
+
uint256 timestamp,
|
|
47
|
+
bool admin
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
function MAX_FEE() external view returns (uint256);
|
|
51
|
+
|
|
52
|
+
function MAX_OUTCOMES() external view returns (uint256);
|
|
53
|
+
|
|
54
|
+
function MAX_UINT_256() external view returns (uint256);
|
|
55
|
+
|
|
56
|
+
function ONE() external view returns (uint256);
|
|
57
|
+
|
|
58
|
+
function WETH() external view returns (address);
|
|
59
|
+
|
|
60
|
+
function marketIndex() external view returns (uint256);
|
|
61
|
+
|
|
62
|
+
function createMarket(CreateMarketDescription memory desc) external returns (uint256);
|
|
63
|
+
|
|
64
|
+
function createMarketWithETH(CreateMarketDescription memory desc) external payable returns (uint256);
|
|
65
|
+
|
|
66
|
+
function mintAndCreateMarket(CreateMarketDescription memory desc) external returns (uint256);
|
|
67
|
+
|
|
68
|
+
function calcBuyAmount(
|
|
69
|
+
uint256 amount,
|
|
70
|
+
uint256 marketId,
|
|
71
|
+
uint256 outcomeId
|
|
72
|
+
) external view returns (uint256);
|
|
73
|
+
|
|
74
|
+
function calcSellAmount(
|
|
75
|
+
uint256 amount,
|
|
76
|
+
uint256 marketId,
|
|
77
|
+
uint256 outcomeId
|
|
78
|
+
) external view returns (uint256 outcomeTokenSellAmount);
|
|
79
|
+
|
|
80
|
+
function buy(
|
|
81
|
+
uint256 marketId,
|
|
82
|
+
uint256 outcomeId,
|
|
83
|
+
uint256 minOutcomeSharesToBuy,
|
|
84
|
+
uint256 value
|
|
85
|
+
) external;
|
|
86
|
+
|
|
87
|
+
function buyWithETH(
|
|
88
|
+
uint256 marketId,
|
|
89
|
+
uint256 outcomeId,
|
|
90
|
+
uint256 minOutcomeSharesToBuy
|
|
91
|
+
) external payable;
|
|
92
|
+
|
|
93
|
+
function sell(
|
|
94
|
+
uint256 marketId,
|
|
95
|
+
uint256 outcomeId,
|
|
96
|
+
uint256 value,
|
|
97
|
+
uint256 maxOutcomeSharesToSell
|
|
98
|
+
) external;
|
|
99
|
+
|
|
100
|
+
function sellToETH(
|
|
101
|
+
uint256 marketId,
|
|
102
|
+
uint256 outcomeId,
|
|
103
|
+
uint256 value,
|
|
104
|
+
uint256 maxOutcomeSharesToSell
|
|
105
|
+
) external;
|
|
106
|
+
|
|
107
|
+
function addLiquidity(uint256 marketId, uint256 value) external;
|
|
108
|
+
|
|
109
|
+
function addLiquidityWithETH(uint256 marketId) external payable;
|
|
110
|
+
|
|
111
|
+
function removeLiquidity(uint256 marketId, uint256 shares) external;
|
|
112
|
+
|
|
113
|
+
function removeLiquidityToETH(uint256 marketId, uint256 shares) external;
|
|
114
|
+
|
|
115
|
+
function resolveMarketOutcome(uint256 marketId) external returns (uint256);
|
|
116
|
+
|
|
117
|
+
function adminResolveMarketOutcome(uint256 marketId, uint256 outcomeId) external returns (uint256);
|
|
118
|
+
|
|
119
|
+
function claimWinnings(uint256 marketId) external;
|
|
120
|
+
|
|
121
|
+
function claimWinningsToETH(uint256 marketId) external;
|
|
122
|
+
|
|
123
|
+
function claimVoidedOutcomeShares(uint256 marketId, uint256 outcomeId) external;
|
|
124
|
+
|
|
125
|
+
function claimVoidedOutcomeSharesToETH(uint256 marketId, uint256 outcomeId) external;
|
|
126
|
+
|
|
127
|
+
function claimLiquidity(uint256 marketId) external;
|
|
128
|
+
|
|
129
|
+
function claimLiquidityToETH(uint256 marketId) external;
|
|
130
|
+
|
|
131
|
+
function claimFees(uint256 marketId) external;
|
|
132
|
+
|
|
133
|
+
function claimFeesToETH(uint256 marketId) external;
|
|
134
|
+
|
|
135
|
+
function getUserMarketShares(uint256 marketId, address user) external view returns (uint256, uint256[] memory);
|
|
136
|
+
|
|
137
|
+
function getUserClaimStatus(uint256 marketId, address user)
|
|
138
|
+
external
|
|
139
|
+
view
|
|
140
|
+
returns (
|
|
141
|
+
bool,
|
|
142
|
+
bool,
|
|
143
|
+
bool,
|
|
144
|
+
bool,
|
|
145
|
+
uint256
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
function getUserLiquidityPoolShare(uint256 marketId, address user) external view returns (uint256);
|
|
149
|
+
|
|
150
|
+
function getUserClaimableFees(uint256 marketId, address user) external view returns (uint256);
|
|
151
|
+
|
|
152
|
+
function getMarkets() external view returns (uint256[] memory);
|
|
153
|
+
|
|
154
|
+
function getMarketData(uint256 marketId)
|
|
155
|
+
external
|
|
156
|
+
view
|
|
157
|
+
returns (
|
|
158
|
+
uint8,
|
|
159
|
+
uint256,
|
|
160
|
+
uint256,
|
|
161
|
+
uint256,
|
|
162
|
+
uint256,
|
|
163
|
+
int256
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
function getMarketAltData(uint256 marketId)
|
|
167
|
+
external
|
|
168
|
+
view
|
|
169
|
+
returns (
|
|
170
|
+
uint256,
|
|
171
|
+
bytes32,
|
|
172
|
+
uint256,
|
|
173
|
+
address,
|
|
174
|
+
uint256,
|
|
175
|
+
address,
|
|
176
|
+
address,
|
|
177
|
+
uint256,
|
|
178
|
+
address
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
function getMarketQuestion(uint256 marketId) external view returns (bytes32);
|
|
182
|
+
|
|
183
|
+
function getMarketPrices(uint256 marketId) external view returns (uint256, uint256[] memory);
|
|
184
|
+
|
|
185
|
+
function getMarketShares(uint256 marketId) external view returns (uint256, uint256[] memory);
|
|
186
|
+
|
|
187
|
+
function getMarketLiquidityPrice(uint256 marketId) external view returns (uint256);
|
|
188
|
+
|
|
189
|
+
function getMarketResolvedOutcome(uint256 marketId) external view returns (int256);
|
|
190
|
+
|
|
191
|
+
function isMarketVoided(uint256 marketId) external view returns (bool);
|
|
192
|
+
|
|
193
|
+
function getMarketFee(uint256 marketId) external view returns (uint256);
|
|
194
|
+
|
|
195
|
+
function getMarketOutcomeIds(uint256 marketId) external view returns (uint256[] memory);
|
|
196
|
+
|
|
197
|
+
function getMarketOutcomePrice(uint256 marketId, uint256 outcomeId) external view returns (uint256);
|
|
198
|
+
|
|
199
|
+
function getMarketOutcomeData(uint256 marketId, uint256 outcomeId)
|
|
200
|
+
external
|
|
201
|
+
view
|
|
202
|
+
returns (
|
|
203
|
+
uint256,
|
|
204
|
+
uint256,
|
|
205
|
+
uint256
|
|
206
|
+
);
|
|
207
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.18;
|
|
3
|
+
|
|
4
|
+
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
5
|
+
|
|
6
|
+
interface IPredictionMarketV3Factory {
|
|
7
|
+
function isPMControllerAdmin(address controllerAddress, address user) external view returns (bool);
|
|
8
|
+
|
|
9
|
+
function isPMControllerActive(address controllerAddress) external view returns (bool);
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.18;
|
|
3
|
+
|
|
4
|
+
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
5
|
+
|
|
6
|
+
interface IPredictionMarketV3Manager {
|
|
7
|
+
function isAllowedToCreateMarket(IERC20 token, address user) external view returns (bool);
|
|
8
|
+
|
|
9
|
+
function isAllowedToResolveMarket(IERC20 token, address user) external view returns (bool);
|
|
10
|
+
|
|
11
|
+
function isIERC20TokenSocial(IERC20 token) external view returns (bool);
|
|
12
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
// Based on https://github.com/RealityETH/reality-eth-monorepo/blob/main/packages/contracts/development/contracts/IRealityETH_ERC20.sol
|
|
3
|
+
|
|
4
|
+
pragma solidity ^0.8.18;
|
|
5
|
+
|
|
6
|
+
interface IRealityETH_ERC20 {
|
|
7
|
+
event LogAnswerReveal (bytes32 indexed question_id, address indexed user, bytes32 indexed answer_hash, bytes32 answer, uint256 nonce, uint256 bond);
|
|
8
|
+
event LogCancelArbitration (bytes32 indexed question_id);
|
|
9
|
+
event LogClaim (bytes32 indexed question_id, address indexed user, uint256 amount);
|
|
10
|
+
event LogFinalize (bytes32 indexed question_id, bytes32 indexed answer);
|
|
11
|
+
event LogFundAnswerBounty (bytes32 indexed question_id, uint256 bounty_added, uint256 bounty, address indexed user);
|
|
12
|
+
event LogMinimumBond (bytes32 indexed question_id, uint256 min_bond);
|
|
13
|
+
event LogNewAnswer (bytes32 answer, bytes32 indexed question_id, bytes32 history_hash, address indexed user, uint256 bond, uint256 ts, bool is_commitment);
|
|
14
|
+
event LogNewQuestion (bytes32 indexed question_id, address indexed user, uint256 template_id, string question, bytes32 indexed content_hash, address arbitrator, uint32 timeout, uint32 opening_ts, uint256 nonce, uint256 created);
|
|
15
|
+
event LogNewTemplate (uint256 indexed template_id, address indexed user, string question_text);
|
|
16
|
+
event LogNotifyOfArbitrationRequest (bytes32 indexed question_id, address indexed user);
|
|
17
|
+
event LogReopenQuestion (bytes32 indexed question_id, bytes32 indexed reopened_question_id);
|
|
18
|
+
event LogSetQuestionFee (address arbitrator, uint256 amount);
|
|
19
|
+
|
|
20
|
+
function askQuestion (uint256 template_id, string calldata question, address arbitrator, uint32 timeout, uint32 opening_ts, uint256 nonce) external returns (bytes32);
|
|
21
|
+
function askQuestionERC20 (uint256 template_id, string calldata question, address arbitrator, uint32 timeout, uint32 opening_ts, uint256 nonce, uint256 tokens) external returns (bytes32);
|
|
22
|
+
function askQuestionWithMinBondERC20 (uint256 template_id, string calldata question, address arbitrator, uint32 timeout, uint32 opening_ts, uint256 nonce, uint256 min_bond, uint256 tokens) external returns (bytes32);
|
|
23
|
+
function assignWinnerAndSubmitAnswerByArbitrator (bytes32 question_id, bytes32 answer, address payee_if_wrong, bytes32 last_history_hash, bytes32 last_answer_or_commitment_id, address last_answerer) external;
|
|
24
|
+
function cancelArbitration (bytes32 question_id) external;
|
|
25
|
+
function claimMultipleAndWithdrawBalance (bytes32[] calldata question_ids, uint256[] calldata lengths, bytes32[] calldata hist_hashes, address[] calldata addrs, uint256[] calldata bonds, bytes32[] calldata answers) external;
|
|
26
|
+
function claimWinnings (bytes32 question_id, bytes32[] calldata history_hashes, address[] calldata addrs, uint256[] calldata bonds, bytes32[] calldata answers) external;
|
|
27
|
+
function createTemplate (string calldata content) external returns (uint256);
|
|
28
|
+
function createTemplateAndAskQuestion (string calldata content, string calldata question, address arbitrator, uint32 timeout, uint32 opening_ts, uint256 nonce) external returns (bytes32);
|
|
29
|
+
function fundAnswerBountyERC20 (bytes32 question_id, uint256 tokens) external;
|
|
30
|
+
function notifyOfArbitrationRequest (bytes32 question_id, address requester, uint256 max_previous) external;
|
|
31
|
+
function reopenQuestionERC20 (uint256 template_id, string calldata question, address arbitrator, uint32 timeout, uint32 opening_ts, uint256 nonce, uint256 min_bond, bytes32 reopens_question_id, uint256 tokens) external returns (bytes32);
|
|
32
|
+
function setQuestionFee (uint256 fee) external;
|
|
33
|
+
function setToken (address _token) external;
|
|
34
|
+
function submitAnswerByArbitrator (bytes32 question_id, bytes32 answer, address answerer) external;
|
|
35
|
+
function submitAnswerCommitmentERC20 (bytes32 question_id, bytes32 answer_hash, uint256 max_previous, address _answerer, uint256 tokens) external;
|
|
36
|
+
function submitAnswerERC20 (bytes32 question_id, bytes32 answer, uint256 max_previous, uint256 tokens) external;
|
|
37
|
+
function submitAnswerForERC20 (bytes32 question_id, bytes32 answer, uint256 max_previous, address answerer, uint256 tokens) external;
|
|
38
|
+
function submitAnswerReveal (bytes32 question_id, bytes32 answer, uint256 nonce, uint256 bond) external;
|
|
39
|
+
function arbitrator_question_fees (address) external view returns (uint256);
|
|
40
|
+
function commitments (bytes32) external view returns (uint32 reveal_ts, bool is_revealed, bytes32 revealed_answer);
|
|
41
|
+
function getArbitrator (bytes32 question_id) external view returns (address);
|
|
42
|
+
function getBestAnswer (bytes32 question_id) external view returns (bytes32);
|
|
43
|
+
function getBond (bytes32 question_id) external view returns (uint256);
|
|
44
|
+
function getBounty (bytes32 question_id) external view returns (uint256);
|
|
45
|
+
function getContentHash (bytes32 question_id) external view returns (bytes32);
|
|
46
|
+
function getFinalAnswer (bytes32 question_id) external view returns (bytes32);
|
|
47
|
+
function getFinalAnswerIfMatches (bytes32 question_id, bytes32 content_hash, address arbitrator, uint32 min_timeout, uint256 min_bond) external view returns (bytes32);
|
|
48
|
+
function getFinalizeTS (bytes32 question_id) external view returns (uint32);
|
|
49
|
+
function getHistoryHash (bytes32 question_id) external view returns (bytes32);
|
|
50
|
+
function getMinBond (bytes32 question_id) external view returns (uint256);
|
|
51
|
+
function getOpeningTS (bytes32 question_id) external view returns (uint32);
|
|
52
|
+
function getTimeout (bytes32 question_id) external view returns (uint32);
|
|
53
|
+
function isFinalized (bytes32 question_id) external view returns (bool);
|
|
54
|
+
function isPendingArbitration (bytes32 question_id) external view returns (bool);
|
|
55
|
+
function isSettledTooSoon (bytes32 question_id) external view returns (bool);
|
|
56
|
+
function question_claims (bytes32) external view returns (address payee, uint256 last_bond, uint256 queued_funds);
|
|
57
|
+
function questions (bytes32) external view returns (bytes32 content_hash, address arbitrator, uint32 opening_ts, uint32 timeout, uint32 finalize_ts, bool is_pending_arbitration, uint256 bounty, bytes32 best_answer, bytes32 history_hash, uint256 bond, uint256 min_bond);
|
|
58
|
+
function reopened_questions (bytes32) external view returns (bytes32);
|
|
59
|
+
function reopener_questions (bytes32) external view returns (bool);
|
|
60
|
+
function resultFor (bytes32 question_id) external view returns (bytes32);
|
|
61
|
+
function resultForOnceSettled (bytes32 question_id) external view returns (bytes32);
|
|
62
|
+
function template_hashes (uint256) external view returns (bytes32);
|
|
63
|
+
function templates (uint256) external view returns (uint256);
|
|
64
|
+
}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.18;
|
|
3
|
+
|
|
4
|
+
import "./FantasyERC20.sol";
|
|
5
|
+
import "./RealityETH_ERC20_Factory.sol";
|
|
6
|
+
|
|
7
|
+
// openzeppelin ownable contract import
|
|
8
|
+
import "@openzeppelin/contracts/access/Ownable.sol";
|
|
9
|
+
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
|
|
10
|
+
|
|
11
|
+
abstract contract LandFactory is Ownable, ReentrancyGuard {
|
|
12
|
+
struct Land {
|
|
13
|
+
FantasyERC20 token;
|
|
14
|
+
bool active;
|
|
15
|
+
mapping(address => bool) admins;
|
|
16
|
+
uint256 lockAmount;
|
|
17
|
+
address lockUser;
|
|
18
|
+
IRealityETH_IERC20 realitio;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
address public PMV3; // PredictionMarketV3 contract
|
|
22
|
+
IERC20 public token; // Governance IERC20
|
|
23
|
+
uint256 public lockAmount; // amount necessary to lock to create a land
|
|
24
|
+
RealityETH_ERC20_Factory public realitioFactory;
|
|
25
|
+
|
|
26
|
+
mapping(address => Land) public lands;
|
|
27
|
+
address[] public landTokens;
|
|
28
|
+
uint256 public landTokensLength;
|
|
29
|
+
mapping(address => bool) public fantasyTokens;
|
|
30
|
+
|
|
31
|
+
event LandCreated(address indexed user, address indexed token, address indexed tokenToAnswer, uint256 amountLocked);
|
|
32
|
+
|
|
33
|
+
event LandDisabled(address indexed user, address indexed token, uint256 amountUnlocked);
|
|
34
|
+
|
|
35
|
+
event LandEnabled(address indexed user, address indexed token, uint256 amountLocked);
|
|
36
|
+
|
|
37
|
+
event LandOffsetUnlocked(address indexed user, address indexed token, uint256 amountUnlocked);
|
|
38
|
+
|
|
39
|
+
event LandAdminAdded(address indexed user, address indexed token, address indexed admin);
|
|
40
|
+
|
|
41
|
+
event LandAdminRemoved(address indexed user, address indexed token, address indexed admin);
|
|
42
|
+
|
|
43
|
+
// lockAmount is the amount of tokens that the user needs to lock to create a land
|
|
44
|
+
// by locking the amount the factory will create a fantasyERC20 token and store it in the contract
|
|
45
|
+
// the user will be the admin of the land
|
|
46
|
+
function createLand(
|
|
47
|
+
string memory name,
|
|
48
|
+
string memory symbol,
|
|
49
|
+
uint256 tokenAmountToClaim,
|
|
50
|
+
IERC20 tokenToAnswer
|
|
51
|
+
) external virtual returns (FantasyERC20) {
|
|
52
|
+
return _createLand(name, symbol, tokenAmountToClaim, tokenToAnswer, address(0), address(0));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function createLand(FantasyERC20 landToken, IERC20 tokenToAnswer) external virtual returns (FantasyERC20) {
|
|
56
|
+
return _createLand(landToken, tokenToAnswer);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function _createLand(
|
|
60
|
+
string memory name,
|
|
61
|
+
string memory symbol,
|
|
62
|
+
uint256 tokenAmountToClaim,
|
|
63
|
+
IERC20 tokenToAnswer,
|
|
64
|
+
address PMV3Factory,
|
|
65
|
+
address PMV3Controller
|
|
66
|
+
) internal returns (FantasyERC20) {
|
|
67
|
+
// create a new fantasyERC20 token
|
|
68
|
+
FantasyERC20 landToken = new FantasyERC20(
|
|
69
|
+
name,
|
|
70
|
+
symbol,
|
|
71
|
+
tokenAmountToClaim,
|
|
72
|
+
address(PMV3),
|
|
73
|
+
PMV3Factory,
|
|
74
|
+
PMV3Controller
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
// adding minting privileges to the PMV3 contract
|
|
78
|
+
landToken.grantRole(keccak256("MINTER_ROLE"), address(PMV3));
|
|
79
|
+
// adding minting privileges to the msg.sender
|
|
80
|
+
landToken.grantRole(keccak256("MINTER_ROLE"), msg.sender);
|
|
81
|
+
|
|
82
|
+
fantasyTokens[address(landToken)] = true;
|
|
83
|
+
|
|
84
|
+
return _createLand(landToken, tokenToAnswer);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function _createLand(FantasyERC20 landToken, IERC20 tokenToAnswer) internal returns (FantasyERC20) {
|
|
88
|
+
// checking if land with same token was already created
|
|
89
|
+
require(!lands[address(landToken)].active, "Land already exists");
|
|
90
|
+
|
|
91
|
+
if (lockAmount > 0) {
|
|
92
|
+
// transfer the lockAmount to the contract
|
|
93
|
+
require(token.balanceOf(msg.sender) >= lockAmount, "Not enough tokens to lock");
|
|
94
|
+
token.transferFrom(msg.sender, address(this), lockAmount);
|
|
95
|
+
}
|
|
96
|
+
require(address(tokenToAnswer) != address(0), "Token to answer cannot be 0 address");
|
|
97
|
+
|
|
98
|
+
// store the new token in the contract
|
|
99
|
+
Land storage land = lands[address(landToken)];
|
|
100
|
+
land.token = landToken;
|
|
101
|
+
land.active = true;
|
|
102
|
+
land.admins[msg.sender] = true;
|
|
103
|
+
land.lockAmount = lockAmount;
|
|
104
|
+
land.lockUser = msg.sender;
|
|
105
|
+
landTokens.push(address(landToken));
|
|
106
|
+
landTokensLength++;
|
|
107
|
+
|
|
108
|
+
// creating the realityETH_ERC20 contract
|
|
109
|
+
if (realitioFactory.deployments(address(tokenToAnswer)) == address(0)) {
|
|
110
|
+
realitioFactory.createInstance(address(tokenToAnswer));
|
|
111
|
+
}
|
|
112
|
+
land.realitio = IRealityETH_IERC20(realitioFactory.deployments(address(tokenToAnswer)));
|
|
113
|
+
|
|
114
|
+
emit LandCreated(msg.sender, address(landToken), address(tokenToAnswer), lockAmount);
|
|
115
|
+
|
|
116
|
+
return landToken;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function disableLand(IERC20 landToken) external virtual {
|
|
120
|
+
Land storage land = lands[address(landToken)];
|
|
121
|
+
|
|
122
|
+
require(land.active, "Land is not active");
|
|
123
|
+
require(isLandAdmin(landToken, msg.sender), "Not admin of the land");
|
|
124
|
+
|
|
125
|
+
uint256 amountToUnlock = land.lockAmount;
|
|
126
|
+
|
|
127
|
+
if (amountToUnlock > 0) {
|
|
128
|
+
token.transfer(land.lockUser, amountToUnlock);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// disable the land
|
|
132
|
+
land.active = false;
|
|
133
|
+
land.lockAmount = 0;
|
|
134
|
+
land.lockUser = address(0);
|
|
135
|
+
|
|
136
|
+
if (fantasyTokens[address(landToken)]) {
|
|
137
|
+
// pausing token
|
|
138
|
+
land.token.pause();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
emit LandDisabled(msg.sender, address(landToken), amountToUnlock);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function enableLand(IERC20 landToken) external virtual {
|
|
145
|
+
Land storage land = lands[address(landToken)];
|
|
146
|
+
|
|
147
|
+
require(!land.active, "Land is already active");
|
|
148
|
+
require(isLandAdmin(landToken, msg.sender), "Not admin of the land");
|
|
149
|
+
|
|
150
|
+
uint256 amountToLock = lockAmount > land.lockAmount ? lockAmount - land.lockAmount : 0;
|
|
151
|
+
|
|
152
|
+
// transfer the lockAmount to the contract
|
|
153
|
+
if (amountToLock > 0) {
|
|
154
|
+
token.transferFrom(msg.sender, address(this), amountToLock);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// enable the land
|
|
158
|
+
land.active = true;
|
|
159
|
+
land.lockAmount = land.lockAmount + amountToLock;
|
|
160
|
+
land.lockUser = msg.sender;
|
|
161
|
+
|
|
162
|
+
if (fantasyTokens[address(landToken)]) {
|
|
163
|
+
// unpausing token
|
|
164
|
+
land.token.unpause();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
emit LandEnabled(msg.sender, address(landToken), amountToLock);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function unlockOffsetFromLand(IERC20 landToken) external virtual {
|
|
171
|
+
Land storage land = lands[address(landToken)];
|
|
172
|
+
|
|
173
|
+
require(land.active, "Land is not active");
|
|
174
|
+
require(isLandAdmin(landToken, msg.sender), "Not admin of the land");
|
|
175
|
+
|
|
176
|
+
uint256 amountToUnlock = land.lockAmount > lockAmount ? land.lockAmount - lockAmount : 0;
|
|
177
|
+
|
|
178
|
+
if (amountToUnlock > 0) {
|
|
179
|
+
token.transfer(msg.sender, amountToUnlock);
|
|
180
|
+
land.lockAmount = land.lockAmount - amountToUnlock;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
emit LandOffsetUnlocked(msg.sender, address(landToken), amountToUnlock);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function updateLockAmount(uint256 newLockAmount) external onlyOwner {
|
|
187
|
+
require(newLockAmount > 0, "Lock amount must be greater than 0");
|
|
188
|
+
require(newLockAmount != lockAmount, "Lock amount is the same");
|
|
189
|
+
|
|
190
|
+
lockAmount = newLockAmount;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function addAdminToLand(IERC20 landToken, address admin) external virtual {
|
|
194
|
+
Land storage land = lands[address(landToken)];
|
|
195
|
+
|
|
196
|
+
require(land.active, "Land does not exist");
|
|
197
|
+
require(isLandAdmin(landToken, msg.sender), "Not admin of the land");
|
|
198
|
+
|
|
199
|
+
// adding minting privileges to the admin
|
|
200
|
+
if (fantasyTokens[address(landToken)]) {
|
|
201
|
+
land.token.grantRole(keccak256("MINTER_ROLE"), admin);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
land.admins[admin] = true;
|
|
205
|
+
|
|
206
|
+
emit LandAdminAdded(msg.sender, address(landToken), admin);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function removeAdminFromLand(IERC20 landToken, address admin) external virtual {
|
|
210
|
+
Land storage land = lands[address(landToken)];
|
|
211
|
+
|
|
212
|
+
require(land.active, "Land does not exist");
|
|
213
|
+
require(isLandAdmin(landToken, msg.sender), "Not admin of the land");
|
|
214
|
+
|
|
215
|
+
// removing minting privileges from the admin
|
|
216
|
+
if (fantasyTokens[address(landToken)]) {
|
|
217
|
+
land.token.revokeRole(keccak256("MINTER_ROLE"), admin);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
land.admins[admin] = false;
|
|
221
|
+
|
|
222
|
+
emit LandAdminRemoved(msg.sender, address(landToken), admin);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function isAllowedToCreateMarket(IERC20 marketToken, address user) public view virtual returns (bool) {
|
|
226
|
+
Land storage land = lands[address(marketToken)];
|
|
227
|
+
|
|
228
|
+
return land.active && land.admins[user];
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function isAllowedToResolveMarket(IERC20 marketToken, address user) external view virtual returns (bool) {
|
|
232
|
+
Land storage land = lands[address(marketToken)];
|
|
233
|
+
|
|
234
|
+
return land.active && land.admins[user];
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function isIERC20TokenSocial(IERC20 marketToken) external view virtual returns (bool) {
|
|
238
|
+
Land storage land = lands[address(marketToken)];
|
|
239
|
+
|
|
240
|
+
return land.active;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function isLandAdmin(IERC20 marketToken, address user) public view virtual returns (bool) {
|
|
244
|
+
Land storage land = lands[address(marketToken)];
|
|
245
|
+
|
|
246
|
+
return land.admins[user];
|
|
247
|
+
}
|
|
248
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity >=0.5.1;
|
|
3
|
+
|
|
4
|
+
contract Migrations {
|
|
5
|
+
address public owner;
|
|
6
|
+
uint256 public lastCompletedMigration;
|
|
7
|
+
|
|
8
|
+
modifier restricted() {
|
|
9
|
+
if (msg.sender == owner) _;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
constructor() public {
|
|
13
|
+
owner = msg.sender;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function setCompleted(uint256 completed) public restricted {
|
|
17
|
+
lastCompletedMigration = completed;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function upgrade(address newAddress) public restricted {
|
|
21
|
+
Migrations upgraded = Migrations(newAddress);
|
|
22
|
+
upgraded.setCompleted(lastCompletedMigration);
|
|
23
|
+
}
|
|
24
|
+
}
|