polkamarkets-js 3.2.0 → 3.3.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.
Files changed (149) hide show
  1. package/abis/AddAdminToLand.json +1 -0
  2. package/abis/ClaimMerkleRoot.json +1 -0
  3. package/abis/CreateLand.json +1 -0
  4. package/abis/CreateMarkets.json +1 -0
  5. package/abis/DeployContracts.json +1 -0
  6. package/abis/DeployMerkleRewardsDistributor.json +1 -0
  7. package/abis/DeployToken.json +1 -0
  8. package/abis/DeployUSDT.json +1 -0
  9. package/abis/MintTokens.json +1 -0
  10. package/abis/PredictionMarketV3_3.json +1 -0
  11. package/abis/PublishMerkleRoot.json +1 -0
  12. package/abis/ResolveMarket.json +1 -0
  13. package/abis/TradeMarket.json +1 -0
  14. package/abis/USDT.json +1 -0
  15. package/package.json +1 -1
  16. package/script/UpdateMarket.s.sol +56 -0
  17. package/scripts/AddAdminToLand.s.sol +29 -0
  18. package/scripts/ClaimMerkleRoot.s.sol +34 -0
  19. package/scripts/CreateLand.s.sol +28 -0
  20. package/scripts/CreateMarkets.s.sol +71 -0
  21. package/scripts/DeployContracts.s.sol +94 -0
  22. package/scripts/DeployMerkleRewardsDistributor.s.sol +27 -0
  23. package/scripts/DeployToken.s.sol +17 -0
  24. package/scripts/DeployUSDT.s.sol +24 -0
  25. package/scripts/MintTokens.s.sol +21 -0
  26. package/scripts/PublishMerkleRoot.s.sol +50 -0
  27. package/scripts/ResolveMarket.s.sol +23 -0
  28. package/scripts/TradeMarket.s.sol +28 -0
  29. package/scripts/UpdateMarket.s.sol +55 -0
  30. package/src/Application.js +2 -1
  31. package/src/interfaces/index.js +2 -0
  32. package/src/models/PredictionMarketV3Contract.js +5 -1
  33. package/src/models/PredictionMarketV3PlusContract.js +39 -2
  34. package/test/UpdateTest.t.sol +55 -0
  35. package/test/WhaleTest.t.sol +188 -0
  36. package/contracts/PredictionMarketV3_4Bad.sol +0 -1487
  37. package/contracts/PredictionMarketV3_4Good.sol +0 -1508
  38. package/dist/Application.d.ts +0 -201
  39. package/dist/Application.d.ts.map +0 -1
  40. package/dist/Application.js +0 -411
  41. package/dist/Application.js.map +0 -1
  42. package/dist/index.d.ts +0 -7
  43. package/dist/index.d.ts.map +0 -1
  44. package/dist/index.js +0 -16
  45. package/dist/index.js.map +0 -1
  46. package/dist/interfaces/index.d.ts +0 -4
  47. package/dist/interfaces/index.d.ts.map +0 -1
  48. package/dist/interfaces/index.js +0 -22
  49. package/dist/interfaces/index.js.map +0 -1
  50. package/dist/models/AchievementsContract.d.ts +0 -43
  51. package/dist/models/AchievementsContract.d.ts.map +0 -1
  52. package/dist/models/AchievementsContract.js +0 -177
  53. package/dist/models/AchievementsContract.js.map +0 -1
  54. package/dist/models/ArbitrationContract.d.ts +0 -23
  55. package/dist/models/ArbitrationContract.d.ts.map +0 -1
  56. package/dist/models/ArbitrationContract.js +0 -47
  57. package/dist/models/ArbitrationContract.js.map +0 -1
  58. package/dist/models/ArbitrationProxyContract.d.ts +0 -14
  59. package/dist/models/ArbitrationProxyContract.d.ts.map +0 -1
  60. package/dist/models/ArbitrationProxyContract.js +0 -26
  61. package/dist/models/ArbitrationProxyContract.js.map +0 -1
  62. package/dist/models/ERC20Contract.d.ts +0 -50
  63. package/dist/models/ERC20Contract.d.ts.map +0 -1
  64. package/dist/models/ERC20Contract.js +0 -99
  65. package/dist/models/ERC20Contract.js.map +0 -1
  66. package/dist/models/FantasyERC20Contract.d.ts +0 -13
  67. package/dist/models/FantasyERC20Contract.d.ts.map +0 -1
  68. package/dist/models/FantasyERC20Contract.js +0 -43
  69. package/dist/models/FantasyERC20Contract.js.map +0 -1
  70. package/dist/models/IContract.d.ts +0 -57
  71. package/dist/models/IContract.d.ts.map +0 -1
  72. package/dist/models/IContract.js +0 -515
  73. package/dist/models/IContract.js.map +0 -1
  74. package/dist/models/PolkamarketsSmartAccount.d.ts +0 -26
  75. package/dist/models/PolkamarketsSmartAccount.d.ts.map +0 -1
  76. package/dist/models/PolkamarketsSmartAccount.js +0 -100
  77. package/dist/models/PolkamarketsSmartAccount.js.map +0 -1
  78. package/dist/models/PredictionMarketContract.d.ts +0 -113
  79. package/dist/models/PredictionMarketContract.d.ts.map +0 -1
  80. package/dist/models/PredictionMarketContract.js +0 -298
  81. package/dist/models/PredictionMarketContract.js.map +0 -1
  82. package/dist/models/PredictionMarketV2Contract.d.ts +0 -157
  83. package/dist/models/PredictionMarketV2Contract.d.ts.map +0 -1
  84. package/dist/models/PredictionMarketV2Contract.js +0 -431
  85. package/dist/models/PredictionMarketV2Contract.js.map +0 -1
  86. package/dist/models/PredictionMarketV3Contract.d.ts +0 -42
  87. package/dist/models/PredictionMarketV3Contract.d.ts.map +0 -1
  88. package/dist/models/PredictionMarketV3Contract.js +0 -277
  89. package/dist/models/PredictionMarketV3Contract.js.map +0 -1
  90. package/dist/models/PredictionMarketV3ControllerContract.d.ts +0 -128
  91. package/dist/models/PredictionMarketV3ControllerContract.d.ts.map +0 -1
  92. package/dist/models/PredictionMarketV3ControllerContract.js +0 -174
  93. package/dist/models/PredictionMarketV3ControllerContract.js.map +0 -1
  94. package/dist/models/PredictionMarketV3FactoryContract.d.ts +0 -31
  95. package/dist/models/PredictionMarketV3FactoryContract.d.ts.map +0 -1
  96. package/dist/models/PredictionMarketV3FactoryContract.js +0 -81
  97. package/dist/models/PredictionMarketV3FactoryContract.js.map +0 -1
  98. package/dist/models/PredictionMarketV3ManagerContract.d.ts +0 -67
  99. package/dist/models/PredictionMarketV3ManagerContract.d.ts.map +0 -1
  100. package/dist/models/PredictionMarketV3ManagerContract.js +0 -97
  101. package/dist/models/PredictionMarketV3ManagerContract.js.map +0 -1
  102. package/dist/models/PredictionMarketV3QuerierContract.d.ts +0 -33
  103. package/dist/models/PredictionMarketV3QuerierContract.d.ts.map +0 -1
  104. package/dist/models/PredictionMarketV3QuerierContract.js +0 -61
  105. package/dist/models/PredictionMarketV3QuerierContract.js.map +0 -1
  106. package/dist/models/PredictionMarketV3_2Contract.d.ts +0 -32
  107. package/dist/models/PredictionMarketV3_2Contract.d.ts.map +0 -1
  108. package/dist/models/PredictionMarketV3_2Contract.js +0 -169
  109. package/dist/models/PredictionMarketV3_2Contract.js.map +0 -1
  110. package/dist/models/RealitioERC20Contract.d.ts +0 -16
  111. package/dist/models/RealitioERC20Contract.d.ts.map +0 -1
  112. package/dist/models/RealitioERC20Contract.js +0 -18
  113. package/dist/models/RealitioERC20Contract.js.map +0 -1
  114. package/dist/models/VotingContract.d.ts +0 -38
  115. package/dist/models/VotingContract.d.ts.map +0 -1
  116. package/dist/models/VotingContract.js +0 -85
  117. package/dist/models/VotingContract.js.map +0 -1
  118. package/dist/models/WETH9Contract.d.ts +0 -29
  119. package/dist/models/WETH9Contract.d.ts.map +0 -1
  120. package/dist/models/WETH9Contract.js +0 -44
  121. package/dist/models/WETH9Contract.js.map +0 -1
  122. package/dist/models/index.d.ts +0 -18
  123. package/dist/models/index.d.ts.map +0 -1
  124. package/dist/models/index.js +0 -37
  125. package/dist/models/index.js.map +0 -1
  126. package/dist/types/contracts.d.ts +0 -46
  127. package/dist/types/contracts.d.ts.map +0 -1
  128. package/dist/types/contracts.js +0 -3
  129. package/dist/types/contracts.js.map +0 -1
  130. package/dist/types/index.d.ts +0 -1
  131. package/dist/types/index.d.ts.map +0 -1
  132. package/dist/types/index.js +0 -3
  133. package/dist/types/index.js.map +0 -1
  134. package/dist/utils/Account.d.ts +0 -34
  135. package/dist/utils/Account.d.ts.map +0 -1
  136. package/dist/utils/Account.js +0 -38
  137. package/dist/utils/Account.js.map +0 -1
  138. package/dist/utils/Contract.d.ts +0 -31
  139. package/dist/utils/Contract.d.ts.map +0 -1
  140. package/dist/utils/Contract.js +0 -123
  141. package/dist/utils/Contract.js.map +0 -1
  142. package/dist/utils/Numbers.d.ts +0 -27
  143. package/dist/utils/Numbers.d.ts.map +0 -1
  144. package/dist/utils/Numbers.js +0 -87
  145. package/dist/utils/Numbers.js.map +0 -1
  146. package/script/CreateMarketLib.sol +0 -1873
  147. package/script/DeployProxy.s.sol +0 -27
  148. package/script/DeployUpgradeablePM.s.sol +0 -47
  149. package/script/PredictionMarketV3_3Flow.s.sol +0 -132
@@ -0,0 +1,24 @@
1
+ // SPDX-License-Identifier: GPL-2.0
2
+ pragma solidity ^0.8.26;
3
+
4
+ import {Script} from "forge-std/Script.sol";
5
+ import {ERC20MinterPauser} from "../contracts/ERC20MinterPauser.sol";
6
+
7
+ contract USDT is ERC20MinterPauser {
8
+ constructor(string memory _name, string memory _symbol) ERC20MinterPauser(_name, _symbol) {}
9
+
10
+ function decimals() public pure override returns (uint8) {
11
+ return 18;
12
+ }
13
+ }
14
+
15
+
16
+ contract DeployUSDT is Script {
17
+ function run() public {
18
+ vm.startBroadcast();
19
+
20
+ new USDT("Tether USD", "USDT");
21
+
22
+ vm.stopBroadcast();
23
+ }
24
+ }
@@ -0,0 +1,21 @@
1
+ // SPDX-License-Identifier: GPL-2.0
2
+ pragma solidity ^0.8.26;
3
+
4
+ import {Script} from "forge-std/Script.sol";
5
+ import {console} from "forge-std/console.sol";
6
+ import {ERC20MinterPauser} from "../contracts/ERC20MinterPauser.sol";
7
+
8
+ contract MintTokens is Script {
9
+ function run() public {
10
+ vm.startBroadcast();
11
+
12
+ address token = address(0x49Ff827F0C8835ebd8109Cc3b51b80435ce44F09);
13
+ address user = address(0x68FcB3Db1BA4Abb85D9f9420A110948e6459d613);
14
+ uint256 amount = 1000000000000000000000000;
15
+
16
+ ERC20MinterPauser(token).mint(user, amount);
17
+ console.log("Tokens minted to:", user);
18
+
19
+ vm.stopBroadcast();
20
+ }
21
+ }
@@ -0,0 +1,50 @@
1
+ // SPDX-License-Identifier: GPL-2.0
2
+ pragma solidity ^0.8.26;
3
+
4
+ import {Script} from "forge-std/Script.sol";
5
+ import {console} from "forge-std/console.sol";
6
+ import {MerkleRewardsDistributor} from "../contracts/MerkleRewardsDistributor.sol";
7
+ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
8
+
9
+ contract PublishMerkleRoot is Script {
10
+ function run() public {
11
+ vm.startBroadcast();
12
+
13
+ MerkleRewardsDistributor distributor = MerkleRewardsDistributor(address(0x846BBEF1e62c211a16fD3F4Cd15C54B010D85036));
14
+ IERC20 token = IERC20(address(0xf74B14ecbAdC9fBb283Fb3c8ae11E186856eae6f));
15
+ bytes32 root = bytes32(0x07b1c91af93eaf54d8cf1644d632ddee695267f4044167b88842e90be3e4878e);
16
+ string memory contestId = "55d2ca19-fee9-4320-a7c6-aea620ba7588";
17
+
18
+ string[5] memory contestIds = [
19
+ "8c8f733c-ecca-4a8b-8ce9-a1208f04de2a",
20
+ "4f29b3d5-097a-404c-9014-9e5ba7cb38a0",
21
+ "1577b57f-e763-4d07-8c58-56d36a49563e",
22
+ "9fbcd4d2-3fb3-4c0b-9fcd-82e7604d1673",
23
+ "b72746ec-8046-4ae5-9a34-92270ab6c3f7"
24
+ ];
25
+
26
+ bytes32[5] memory roots = [
27
+ bytes32(0x29512536af9410dc44a47a16eeff9e65ebb3e05fd5c8369c2dfa59a5bee9e2ac),
28
+ bytes32(0x66af758212a3c1ee876654b4e354908f57caf337178f3895dcc059e2b507ee83),
29
+ bytes32(0x8d022151e97cfb76f08c309f24d13bea76d1f2d7d81c38f46c49d1584912f988),
30
+ bytes32(0x1936d0d67853de21b9f4bd6f369c545e77b63c98596e95d61306f1ac1c0848f9),
31
+ bytes32(0xe84504014594f44045abdb598af6253ac00d41f3da59002dcaa7fd4d3acaaf40)
32
+ ];
33
+
34
+ for (uint256 i = 0; i < contestIds.length; i++) {
35
+ distributor.publishRoot(
36
+ contestIds[i],
37
+ IERC20(address(token)),
38
+ roots[i]
39
+ );
40
+ }
41
+
42
+ // distributor.publishRoot(
43
+ // contestId,
44
+ // IERC20(address(token)),
45
+ // root
46
+ // );
47
+
48
+ vm.stopBroadcast();
49
+ }
50
+ }
@@ -0,0 +1,23 @@
1
+ // SPDX-License-Identifier: GPL-2.0
2
+ pragma solidity ^0.8.26;
3
+
4
+ import {Script} from "forge-std/Script.sol";
5
+ import {console} from "forge-std/console.sol";
6
+ import {PredictionMarketV3_4} from "../contracts/PredictionMarketV3_4.sol";
7
+ import {IPredictionMarketV3Manager} from "../contracts/IPredictionMarketV3Manager.sol";
8
+ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
9
+
10
+ contract ResolveMarket is Script {
11
+ function run() public {
12
+ vm.startBroadcast();
13
+
14
+ address predictionMarket = address(0x289E3908ECDc3c8CcceC5b6801E758549846Ab19);
15
+ uint256 marketId = 5;
16
+ uint256 outcomeId = 0;
17
+
18
+ PredictionMarketV3_4(payable(predictionMarket)).adminResolveMarketOutcome(
19
+ marketId,
20
+ outcomeId
21
+ );
22
+ }
23
+ }
@@ -0,0 +1,28 @@
1
+ // SPDX-License-Identifier: GPL-2.0
2
+ pragma solidity ^0.8.26;
3
+
4
+ import {Script} from "forge-std/Script.sol";
5
+ import {console} from "forge-std/console.sol";
6
+ import {PredictionMarketV3_4} from "../contracts/PredictionMarketV3_4.sol";
7
+ import {IPredictionMarketV3Manager} from "../contracts/IPredictionMarketV3Manager.sol";
8
+ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
9
+
10
+ contract TradeMarket is Script {
11
+ function run() public {
12
+ vm.startBroadcast();
13
+
14
+ address predictionMarket = address(0x289E3908ECDc3c8CcceC5b6801E758549846Ab19);
15
+ uint256 marketId = 4;
16
+ uint256 outcomeId = 0;
17
+ uint256 minOutcomeSharesToBuy = 1;
18
+ uint256 amount = 1000000;
19
+
20
+ // PredictionMarketV3_4(payable(predictionMarket)).buy(
21
+ // marketId,
22
+ // outcomeId,
23
+ // minOutcomeSharesToBuy,
24
+ // amount
25
+ // );
26
+ PredictionMarketV3_4(payable(predictionMarket)).addLiquidity(marketId, amount, 0);
27
+ }
28
+ }
@@ -0,0 +1,55 @@
1
+ // SPDX-License-Identifier: GPL-2.0
2
+ pragma solidity ^0.8.26;
3
+
4
+ import {Script} from "forge-std/Script.sol";
5
+ import {console} from "forge-std/console.sol";
6
+ // Import your contracts here
7
+ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
8
+ import {PredictionMarketV3_3, IWETH} from "../contracts/PredictionMarketV3_3.sol";
9
+ import {IPredictionMarketV3Manager} from "../contracts/IPredictionMarketV3Manager.sol";
10
+ import {PredictionMarketV3Manager, FantasyERC20} from "../contracts/PredictionMarketV3Manager.sol";
11
+ import {IRealityETH_ERC20} from "../contracts/IRealityETH_ERC20.sol";
12
+
13
+ contract UpdateMarket is Script {
14
+ function run() public {
15
+
16
+ vm.startBroadcast();
17
+
18
+ address payable PREDICTION_MARKET_V3_3 = payable(address(0x3e0F5F8F5Fb043aBFA475C0308417Bf72c463289));
19
+ address PREDICTION_MARKET_V3_MANAGER = address(0x68dDc91CCC06e63d74905D901A30edEA7C77EebE);
20
+
21
+ PredictionMarketV3_3.MarketState state = PredictionMarketV3_3(PREDICTION_MARKET_V3_3).getMarketState(486);
22
+ console2.log("state: ", state);
23
+
24
+ PredictionMarketV3_3.MarketUpdateDescription memory description = PredictionMarketV3_3.MarketUpdateDescription({
25
+ closesAtTimestamp: 1762066800,
26
+ balance: 456538064447348172635074428,
27
+ liquidity: 120000000000000000000000000,
28
+ sharesAvailable: 1272835104225672313766121101,
29
+ state: PredictionMarketV3_3.MarketState.open,
30
+ resolution: PredictionMarketV3_3.MarketResolution({
31
+ resolved: false,
32
+ realitio: IRealityETH_ERC20(0x71D76Ff3C2729071B2c52A667197d9f715029F2c),
33
+ outcomeId: 115792089237316195423570985008687907853269984665640564039457584007913129639935,
34
+ questionId: 0x21d6c6c195572d82a7d0a7ba677251dfd3839b21e09df9b39ae36ec99fa6744d,
35
+ realitioTimeout: 3600
36
+ }),
37
+ feesPoolWeight: 0,
38
+ feesTreasury: address(0xBc30e9765Dc8c735206c76DE96d369754eBbcc1f),
39
+ feesDistributor: address(0xBc30e9765Dc8c735206c76DE96d369754eBbcc1f),
40
+ buyFees: PredictionMarketV3_3.Fees({fee: 0, treasuryFee: 0, distributorFee: 0}),
41
+ sellFees: PredictionMarketV3_3.Fees({fee: 0, treasuryFee: 0, distributorFee: 0}),
42
+ outcomeCount: 5,
43
+ token: IERC20(0x0b07cf011B6e2b7E0803b892d97f751659940F23),
44
+ manager: IPredictionMarketV3Manager(0x2EbD002d755bdFadb9e5549aA00a80bd7fa408AE),
45
+ creator: address(0xBc30e9765Dc8c735206c76DE96d369754eBbcc1f),
46
+ paused: false
47
+ });
48
+
49
+ PredictionMarketV3_3(PREDICTION_MARKET_V3_3).updateMarket(486, description);
50
+ PredictionMarketV3_3(PREDICTION_MARKET_V3_3).updateMarketResolution(486, description);
51
+
52
+ state = PredictionMarketV3_3(PREDICTION_MARKET_V3_3).getMarketState(486);
53
+ console2.log("new state: ", state);
54
+ }
55
+ }
@@ -196,11 +196,12 @@ class Application {
196
196
  * @param {Address} ContractAddress (Opt) If it is deployed
197
197
  * @description Create a PredictionMarketV3 Contract
198
198
  */
199
- getPredictionMarketV3PlusContract({ contractAddress = null, querierContractAddress = null } = {}) {
199
+ getPredictionMarketV3PlusContract({ contractAddress = null, querierContractAddress = null, contractVersion = null } = {}) {
200
200
  try {
201
201
  return new PredictionMarketV3PlusContract({
202
202
  ...this.contractDefaultParams(contractAddress),
203
203
  querierContractAddress,
204
+ contractVersion,
204
205
  });
205
206
  } catch (err) {
206
207
  throw err;
@@ -7,6 +7,8 @@ let index = {
7
7
  prediction: require("../../abis/PredictionMarket.json"),
8
8
  predictionV2: require("../../abis/PredictionMarketV2.json"),
9
9
  predictionV3: require("../../abis/PredictionMarketV3.json"),
10
+ predictionV3_2: require("../../abis/PredictionMarketV3_2.json"),
11
+ predictionV3_3: require("../../abis/PredictionMarketV3_3.json"),
10
12
  predictionV3Plus: require("../../abis/PredictionMarketV3_4.json"),
11
13
  predictionV3Manager: require("../../abis/PredictionMarketV3Manager.json"),
12
14
  predictionV3Controller: require("../../abis/PredictionMarketV3Controller.json"),
@@ -1,6 +1,7 @@
1
1
  const predictionV3 = require("../interfaces").predictionV3;
2
2
  const PredictionMarketV2Contract = require("./PredictionMarketV2Contract");
3
3
  const PredictionMarketV3QuerierContract = require("./PredictionMarketV3QuerierContract");
4
+ const _ = require('lodash');
4
5
 
5
6
  const Numbers = require('../utils/Numbers');
6
7
 
@@ -217,6 +218,8 @@ class PredictionMarketV3Contract extends PredictionMarketV2Contract {
217
218
  ];
218
219
  }));
219
220
 
221
+ const liquidityFeesClaimed = _.sumBy(_.filter(events, { action: 'Claim Fees' }), 'value');
222
+
220
223
  const item = {
221
224
  liquidity: {
222
225
  shares: Numbers.fromDecimalsNumber(marketData.liquidityShares, decimals),
@@ -230,7 +233,8 @@ class PredictionMarketV3Contract extends PredictionMarketV2Contract {
230
233
  liquidityClaimed: marketData.liquidityClaimed,
231
234
  voidedWinningsToClaim: marketData.voidedSharesToClaim,
232
235
  voidedWinningsClaimed: false,
233
- liquidityFees: 0 // discontinued
236
+ liquidityFees: 0, // discontinued
237
+ liquidityFeesClaimed
234
238
  }
235
239
  };
236
240
 
@@ -1,4 +1,6 @@
1
- const predictionV3 = require("../interfaces").predictionV3Plus;
1
+ const predictionV3_2 = require("../interfaces").predictionV3_2;
2
+ const predictionV3_3 = require("../interfaces").predictionV3_3;
3
+ const predictionV3Plus = require("../interfaces").predictionV3Plus;
2
4
  const PredictionMarketV3Contract = require("./PredictionMarketV3Contract");
3
5
  const PredictionMarketV3QuerierContract = require("./PredictionMarketV3QuerierContract");
4
6
 
@@ -8,7 +10,11 @@ const realitioLib = require('@reality.eth/reality-eth-lib/formatters/question');
8
10
 
9
11
  class PredictionMarketV3PlusContract extends PredictionMarketV3Contract {
10
12
  constructor(params) {
11
- super({ abi: predictionV3, ...params });
13
+ let abi = predictionV3Plus;
14
+ if (params.contractVersion && params.contractVersion < 3.4) {
15
+ abi = params.contractVersion === 3.3 ? predictionV3_3 : predictionV3_2;
16
+ }
17
+ super({ abi, ...params });
12
18
  this.contractName = 'predictionMarketV3';
13
19
  if (params.defaultDecimals) {
14
20
  this.defaultDecimals = params.defaultDecimals;
@@ -19,6 +25,9 @@ class PredictionMarketV3PlusContract extends PredictionMarketV3Contract {
19
25
  contractAddress: params.querierContractAddress
20
26
  });
21
27
  }
28
+ if (params.contractVersion) {
29
+ this.contractVersion = params.contractVersion;
30
+ }
22
31
  this.marketDecimals = {};
23
32
  }
24
33
 
@@ -205,6 +214,34 @@ class PredictionMarketV3PlusContract extends PredictionMarketV3Contract {
205
214
  this.getContract().methods.referralSell(marketId, outcomeId, valueToWei, maxOutcomeSharesToSell, code),
206
215
  );
207
216
  };
217
+
218
+ async addLiquidity({marketId, value, wrapped = false, minSharesIn = null}) {
219
+ if (!this.contractVersion || this.contractVersion < 3.4) {
220
+ return super.addLiquidity({marketId, value, wrapped});
221
+ }
222
+
223
+ const decimals = await this.getMarketDecimals({marketId});
224
+ const valueToWei = Numbers.toSmartContractDecimals(value, decimals);
225
+ const minSharesInToWei = minSharesIn === null ? 0 : Numbers.toSmartContractDecimals(minSharesIn, decimals);
226
+
227
+ return await this.__sendTx(
228
+ this.getContract().methods.addLiquidity(marketId, valueToWei, minSharesInToWei)
229
+ );
230
+ };
231
+
232
+ async removeLiquidity({marketId, shares, wrapped = false, minValueOut = null}) {
233
+ if (!this.contractVersion || this.contractVersion < 3.4) {
234
+ return super.removeLiquidity({marketId, shares, wrapped});
235
+ }
236
+
237
+ const decimals = await this.getMarketDecimals({marketId});
238
+ const sharesToWei = Numbers.toSmartContractDecimals(shares, decimals);
239
+ const minValueOutToWei = minValueOut === null ? 0 : Numbers.toSmartContractDecimals(minValueOut, decimals);
240
+
241
+ return await this.__sendTx(
242
+ this.getContract().methods.removeLiquidity(marketId, sharesToWei, minValueOutToWei)
243
+ );
244
+ }
208
245
  }
209
246
 
210
247
  module.exports = PredictionMarketV3PlusContract;
@@ -0,0 +1,55 @@
1
+ // SPDX-License-Identifier: GPL-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ import "forge-std/console2.sol";
5
+ import "../contracts/PredictionMarketV3_3.sol";
6
+
7
+ import {Test} from "forge-std/Test.sol";
8
+ import {console} from "forge-std/console.sol";
9
+
10
+ // forge test --match-contract POC -vvvvv --fork-url $RPC_URL --fork-block-number 13292408 --zksync
11
+ contract UpdateTest is Test {
12
+ function test_POC() public {
13
+ address predictionMarketV3 = 0x3e0F5F8F5Fb043aBFA475C0308417Bf72c463289;
14
+ address admin = 0x0a70f6F09caa802D8d62dE9C7EdacE1d3b5Ca160;
15
+
16
+ vm.startPrank(admin);
17
+
18
+ address payable PREDICTION_MARKET_V3_3 = payable(address(0x3e0F5F8F5Fb043aBFA475C0308417Bf72c463289));
19
+
20
+ (PredictionMarketV3_3.MarketState state, uint256 closesAt, uint256 liquidity, uint256 balance, uint256 sharesAvailable, int256 resolvedOutcomeId) = PredictionMarketV3_3(payable(predictionMarketV3)).getMarketData(486);
21
+ console.log("state: ", uint256(state));
22
+
23
+ PredictionMarketV3_3.MarketUpdateDescription memory description = PredictionMarketV3_3.MarketUpdateDescription({
24
+ closesAtTimestamp: 1762066800,
25
+ balance: 456538064447348172635074428,
26
+ liquidity: 120000000000000000000000000,
27
+ sharesAvailable: 1272835104225672313766121101,
28
+ state: PredictionMarketV3_3.MarketState.open,
29
+ resolution: PredictionMarketV3_3.MarketResolution({
30
+ resolved: false,
31
+ realitio: IRealityETH_ERC20(0x71D76Ff3C2729071B2c52A667197d9f715029F2c),
32
+ outcomeId: 115792089237316195423570985008687907853269984665640564039457584007913129639935,
33
+ questionId: 0x21d6c6c195572d82a7d0a7ba677251dfd3839b21e09df9b39ae36ec99fa6744d,
34
+ realitioTimeout: 3600
35
+ }),
36
+ feesPoolWeight: 0,
37
+ feesTreasury: address(0xBc30e9765Dc8c735206c76DE96d369754eBbcc1f),
38
+ feesDistributor: address(0xBc30e9765Dc8c735206c76DE96d369754eBbcc1f),
39
+ buyFees: PredictionMarketV3_3.Fees({fee: 0, treasuryFee: 0, distributorFee: 0}),
40
+ sellFees: PredictionMarketV3_3.Fees({fee: 0, treasuryFee: 0, distributorFee: 0}),
41
+ outcomeCount: 5,
42
+ token: IERC20(0x0b07cf011B6e2b7E0803b892d97f751659940F23),
43
+ manager: IPredictionMarketV3Manager(0x2EbD002d755bdFadb9e5549aA00a80bd7fa408AE),
44
+ creator: address(0xBc30e9765Dc8c735206c76DE96d369754eBbcc1f),
45
+ paused: false
46
+ });
47
+
48
+ PredictionMarketV3_3(PREDICTION_MARKET_V3_3).updateMarket(486, description);
49
+ PredictionMarketV3_3(PREDICTION_MARKET_V3_3).updateMarketResolution(486, description);
50
+
51
+ (state, closesAt, liquidity, balance, sharesAvailable, resolvedOutcomeId) = PredictionMarketV3_3(PREDICTION_MARKET_V3_3).getMarketData(486);
52
+ console2.log("new state: ", uint256(state));
53
+
54
+ }
55
+ }
@@ -0,0 +1,188 @@
1
+ // SPDX-License-Identifier: GPL-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ import "forge-std/console2.sol";
5
+
6
+ import {Test} from "forge-std/Test.sol";
7
+ import {ERC20, IERC20} from "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
8
+
9
+ // forge test --match-contract POC -vvvvv --fork-url $RPC_URL --fork-block-number 13292408 --zksync
10
+ contract WhaleTest is Test {
11
+ function test_POC() public {
12
+ address predictionMarketV3 = 0x39E66eE6b2ddaf4DEfDEd3038E0162180dbeF340;
13
+ address predictionMarketV3Manager = 0xDeFb36c47754D2e37d44b8b8C647D4D643e03bAd;
14
+ address usdc = 0x176211869cA2b568f2A7D4EE941E073a821EE1ff;
15
+ address admin = 0x7836D709E750F6A2D6ff9362457028e8Cd901EB3;
16
+ address whale = 0x374D7860c4f2f604De0191298dD393703Cce84f3;
17
+
18
+ vm.deal(address(this), 200000e6); // Small eth amount needed to trick contract accounting, 0.000000000001 eth would be enough to steal 10_000 usdc
19
+
20
+ // take usdc from the whale
21
+ vm.startPrank(whale);
22
+ IERC20(usdc).transfer(admin, 250000e6);
23
+ vm.stopPrank();
24
+
25
+ console2.log("admin's usdc balance at the start: ", IERC20(usdc).balanceOf(admin));
26
+
27
+
28
+ vm.startPrank(admin);
29
+ uint256[] memory distribution = new uint256[](2);
30
+ distribution[0] = 100e6;
31
+ distribution[1] = 100e6;
32
+
33
+ IERC20(usdc).approve(predictionMarketV3, type(uint256).max);
34
+
35
+
36
+ uint256 marketId = PredictionMarketV3(predictionMarketV3).createMarket(CreateMarketDescription({
37
+ value: 10_000e6,
38
+ closesAt: uint32(block.timestamp + 3600),
39
+ outcomes: 2,
40
+ token: IERC20(usdc),
41
+ distribution: distribution,
42
+ question: "test",
43
+ image: "test",
44
+ arbitrator: address(this),
45
+ buyFees: Fees({fee: 1e16, treasuryFee: 0, distributorFee: 0}),
46
+ sellFees: Fees({fee: 0, treasuryFee: 0, distributorFee: 0}),
47
+ treasury: address(0),
48
+ distributor: address(0),
49
+ realitioTimeout: 3600,
50
+ manager: IPredictionMarketV3Manager(predictionMarketV3Manager)
51
+ }));
52
+
53
+ for (uint256 i = 0; i < 100; i++) {
54
+ PredictionMarketV3(predictionMarketV3).buy(marketId, 0, 0, 1000e6);
55
+ PredictionMarketV3(predictionMarketV3).buy(marketId, 1, 0, 1000e6);
56
+ }
57
+
58
+ (uint256 liquidity, uint256[] memory outcomes) = PredictionMarketV3(predictionMarketV3).getUserMarketShares(marketId, admin);
59
+ console2.log("liquidity: ", liquidity);
60
+ console2.log("outcome 0: ", outcomes[0]);
61
+ console2.log("outcome 1: ", outcomes[1]);
62
+
63
+ vm.stopPrank();
64
+
65
+ console2.log("admin's usdc balance at the end: ", IERC20(usdc).balanceOf(admin));
66
+ }
67
+ }
68
+
69
+ interface IPredictionMarketV3Manager {
70
+ function getERC20RealitioAddress(IERC20 token) external view returns (address);
71
+ function isAllowedToCreateMarket(address, address) external view returns (bool);
72
+ function askQuestionERC20(uint256 template_id, string calldata question, address arbitrator, uint32 timeout, uint32 opening_ts, uint256 nonce, uint256 tokens) external returns (bytes32);
73
+ }
74
+
75
+ contract Manager is IPredictionMarketV3Manager {
76
+ function getERC20RealitioAddress(IERC20 token) external view returns (address) {
77
+ return address(this);
78
+ }
79
+
80
+ function isAllowedToCreateMarket(address, address) external view returns (bool) {
81
+ return true;
82
+ }
83
+
84
+ function askQuestionERC20 (uint256 template_id, string calldata question, address arbitrator, uint32 timeout, uint32 opening_ts, uint256 nonce, uint256 tokens) external returns (bytes32) {
85
+ return bytes32(uint256(1));
86
+ }
87
+
88
+ }
89
+
90
+ interface PredictionMarketV3 {
91
+ function buy(uint256 marketId, uint256 outcomeId, uint256 minOutcomeSharesToBuy, uint256 value) external;
92
+ function sell(uint256 marketId, uint256 outcomeId, uint256 value, uint256 maxOutcomeSharesToSell) external ;
93
+ function createMarket(CreateMarketDescription calldata desc) external returns (uint256);
94
+ function getUserMarketShares(uint256 marketId, address user) external view returns (uint256 liquidity, uint256[] memory outcomes);
95
+ }
96
+
97
+
98
+ enum MarketState {
99
+ open,
100
+ closed,
101
+ resolved
102
+ }
103
+ enum MarketAction {
104
+ buy,
105
+ sell,
106
+ addLiquidity,
107
+ removeLiquidity,
108
+ claimWinnings,
109
+ claimLiquidity,
110
+ claimFees,
111
+ claimVoided
112
+ }
113
+
114
+
115
+ struct Market {
116
+ // market details
117
+ uint256 closesAtTimestamp;
118
+ uint256 balance; // total stake
119
+ uint256 liquidity; // stake held
120
+ uint256 sharesAvailable; // shares held (all outcomes)
121
+ mapping(address => uint256) liquidityShares;
122
+ mapping(address => bool) liquidityClaims; // wether user has claimed liquidity earnings
123
+ MarketState state; // resolution variables
124
+ MarketResolution resolution; // fees
125
+ MarketFees fees;
126
+ // market outcomes
127
+ uint256 outcomeCount;
128
+ mapping(uint256 => MarketOutcome) outcomes;
129
+ IERC20 token; // ERC20 token market will use for trading
130
+ IPredictionMarketV3Manager manager; // manager contract
131
+ address creator; // market creator
132
+ bool paused; // market paused, no trading allowed
133
+ }
134
+
135
+ struct Fees {
136
+ uint256 fee; // fee % taken from every transaction
137
+ uint256 treasuryFee; // fee % taken from every transaction to a treasury address
138
+ uint256 distributorFee; // fee % taken from every transaction to a distributor address
139
+ }
140
+
141
+ struct MarketFees {
142
+ uint256 poolWeight; // internal var used to ensure pro-rate fee distribution
143
+ mapping(address => uint256) claimed;
144
+ address treasury; // address to send treasury fees to
145
+ address distributor; // fee % taken from every transaction to a treasury address
146
+ Fees buyFees; // fees for buy transactions
147
+ Fees sellFees; // fees for sell transactions
148
+ }
149
+
150
+ struct MarketResolution {
151
+ bool resolved;
152
+ address realitio;
153
+ uint256 outcomeId;
154
+ bytes32 questionId; // realitio questionId
155
+ // realitio
156
+ uint256 realitioTimeout;
157
+ }
158
+
159
+ struct MarketOutcome {
160
+ uint256 marketId;
161
+ uint256 id;
162
+ Shares shares;
163
+ }
164
+
165
+ struct Shares {
166
+ uint256 total; // number of shares
167
+ uint256 available; // available shares
168
+ mapping(address => uint256) holders;
169
+ mapping(address => bool) claims; // wether user has claimed winnings
170
+ mapping(address => bool) voidedClaims; // wether user has claimed voided market shares
171
+ }
172
+
173
+ struct CreateMarketDescription {
174
+ uint256 value;
175
+ uint32 closesAt;
176
+ uint256 outcomes;
177
+ IERC20 token;
178
+ uint256[] distribution;
179
+ string question;
180
+ string image;
181
+ address arbitrator;
182
+ Fees buyFees;
183
+ Fees sellFees;
184
+ address treasury;
185
+ address distributor;
186
+ uint32 realitioTimeout;
187
+ IPredictionMarketV3Manager manager;
188
+ }