polkamarkets-js 3.4.2 → 3.4.4
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/abis/AccessControlUpgradeable.json +1 -0
- package/abis/ERC165Upgradeable.json +1 -0
- package/abis/Hashes.json +1 -0
- package/abis/Math.json +1 -1
- package/abis/MerkleProof.json +1 -0
- package/abis/MerkleRewardsDistributor.json +1 -0
- package/abis/MerkleRewardsDistributorTest.json +1 -0
- package/abis/Panic.json +1 -0
- package/abis/SafeCast.json +1 -0
- package/abis/SignedMath.json +1 -0
- package/abis/Strings.json +1 -1
- package/contracts/MerkleRewardsDistributor.sol +194 -0
- package/package.json +1 -1
- package/script/copy-abis.js +57 -0
- package/scripts/AddAdminToLand.s.sol +29 -0
- package/scripts/ClaimMerkleRoot.s.sol +34 -0
- package/scripts/CreateLand.s.sol +28 -0
- package/scripts/CreateMarkets.s.sol +71 -0
- package/scripts/DeployContracts.s.sol +94 -0
- package/scripts/DeployMerkleRewardsDistributor.s.sol +27 -0
- package/scripts/DeployToken.s.sol +17 -0
- package/scripts/DeployUSDT.s.sol +24 -0
- package/scripts/MintTokens.s.sol +21 -0
- package/scripts/PublishMerkleRoot.s.sol +50 -0
- package/scripts/ResolveMarket.s.sol +23 -0
- package/scripts/TradeMarket.s.sol +28 -0
- package/scripts/UpdateMarket.s.sol +55 -0
- package/src/Application.js +28 -1
- package/src/interfaces/index.js +1 -0
- package/src/models/IContract.js +101 -1
- package/src/models/MerkleRewardsDistributorContract.js +107 -0
- package/src/models/PolkamarketsSmartAccount.js +23 -0
- package/src/models/index.js +3 -1
- package/test/MerkleRewardsDistributor.t.sol +316 -0
- /package/abis/{test.json → Test.json} +0 -0
|
@@ -0,0 +1,94 @@
|
|
|
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 {PredictionMarketV3_4, IWETH} from "../contracts/PredictionMarketV3_4.sol";
|
|
8
|
+
import {PredictionMarketV3Manager} from "../contracts/PredictionMarketV3Manager.sol";
|
|
9
|
+
import {PredictionMarketV3Querier} from "../contracts/PredictionMarketV3Querier.sol";
|
|
10
|
+
import {IPredictionMarketV3Manager} from "../contracts/IPredictionMarketV3Manager.sol";
|
|
11
|
+
import {IPredictionMarketV3_4} from "../contracts/IPredictionMarketV3_4.sol";
|
|
12
|
+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
13
|
+
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
|
|
14
|
+
import {RealityETH_ERC20_v3_0} from "@reality.eth/contracts/development/contracts/RealityETH_ERC20-3.0.sol";
|
|
15
|
+
import {ERC20MinterPauser} from "../contracts/ERC20MinterPauser.sol";
|
|
16
|
+
import {IRealityETH_ERC20} from "../contracts/IRealityETH_ERC20.sol";
|
|
17
|
+
|
|
18
|
+
contract DeployContracts is Script {
|
|
19
|
+
function run() public {
|
|
20
|
+
vm.startBroadcast();
|
|
21
|
+
|
|
22
|
+
address TOKEN = address(0x0);
|
|
23
|
+
address admin = address(0x0a70f6F09caa802D8d62dE9C7EdacE1d3b5Ca160);
|
|
24
|
+
address self = address(0x7C0F97fb24E8712E97285C7Ba7527ed6d0eb6995);
|
|
25
|
+
address WETH = address(0x0);
|
|
26
|
+
address REALITIO = address(0x0);
|
|
27
|
+
address PREDICTION_MARKET_V3_MANAGER = address(0x0);
|
|
28
|
+
address PREDICTION_MARKET_V3_QUERIER = address(0x0);
|
|
29
|
+
address payable PREDICTION_MARKET_V3_4 = payable(address(0x0));
|
|
30
|
+
|
|
31
|
+
// self transfer 0 ETH to trigger dummy transaction
|
|
32
|
+
// payable(self).transfer(0 ether);
|
|
33
|
+
// payable(self).transfer(0 ether);
|
|
34
|
+
// payable(self).transfer(0 ether);
|
|
35
|
+
// payable(self).transfer(0 ether);
|
|
36
|
+
// payable(self).transfer(0 ether);
|
|
37
|
+
// payable(self).transfer(0 ether);
|
|
38
|
+
// payable(self).transfer(0 ether);
|
|
39
|
+
// payable(self).transfer(0 ether);
|
|
40
|
+
|
|
41
|
+
// deploy PredictionMarketV3_4
|
|
42
|
+
PredictionMarketV3_4 impl = new PredictionMarketV3_4();
|
|
43
|
+
console.log("Implementation deployed at:", address(impl));
|
|
44
|
+
|
|
45
|
+
// Show initialization data for manual proxy deployment
|
|
46
|
+
bytes memory initData = abi.encodeCall(PredictionMarketV3_4.initialize, (IWETH(WETH), admin));
|
|
47
|
+
console.log("Initialization data for proxy:");
|
|
48
|
+
console.logBytes(initData);
|
|
49
|
+
|
|
50
|
+
console.log("\nFor proxy deployment, use OpenZeppelin's ERC1967Proxy:");
|
|
51
|
+
console.log("new ERC1967Proxy(", vm.toString(address(impl)), ", initData)");
|
|
52
|
+
|
|
53
|
+
ERC1967Proxy proxy = new ERC1967Proxy(
|
|
54
|
+
address(impl),
|
|
55
|
+
initData
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
console.log("PredictionMarketV3_4 deployed at:", address(proxy));
|
|
59
|
+
PREDICTION_MARKET_V3_4 = payable(address(proxy));
|
|
60
|
+
|
|
61
|
+
// deploy PredictionMarketV3Querier
|
|
62
|
+
PredictionMarketV3Querier querier = new PredictionMarketV3Querier(IPredictionMarketV3_4(PREDICTION_MARKET_V3_4));
|
|
63
|
+
console.log("PredictionMarketV3Querier deployed at:", address(querier));
|
|
64
|
+
PREDICTION_MARKET_V3_QUERIER = address(querier);
|
|
65
|
+
|
|
66
|
+
// deploy TOKEN
|
|
67
|
+
ERC20MinterPauser token = new ERC20MinterPauser("Myriad Cure", "MYRCURE");
|
|
68
|
+
console.log("TOKEN deployed at:", address(token));
|
|
69
|
+
TOKEN = address(token);
|
|
70
|
+
token.mint(admin, 10000000000000000000);
|
|
71
|
+
|
|
72
|
+
// deploy RealityETH_ERC20
|
|
73
|
+
RealityETH_ERC20_v3_0 realitio = new RealityETH_ERC20_v3_0();
|
|
74
|
+
console.log("RealityETH_ERC20 deployed at:", address(realitio));
|
|
75
|
+
IRealityETH_ERC20(address(realitio)).setToken(address(TOKEN));
|
|
76
|
+
REALITIO = address(realitio);
|
|
77
|
+
|
|
78
|
+
// deploy PredictionMarketV3_4Manager
|
|
79
|
+
PredictionMarketV3Manager manager = new PredictionMarketV3Manager(
|
|
80
|
+
PREDICTION_MARKET_V3_4,
|
|
81
|
+
IERC20(TOKEN),
|
|
82
|
+
1 ether,
|
|
83
|
+
address(REALITIO),
|
|
84
|
+
admin
|
|
85
|
+
);
|
|
86
|
+
console.log("PredictionMarketV3Manager deployed at:", address(manager));
|
|
87
|
+
PREDICTION_MARKET_V3_MANAGER = address(manager);
|
|
88
|
+
|
|
89
|
+
// IERC20(TOKEN).approve(PREDICTION_MARKET_V3_MANAGER, 1000 ether);
|
|
90
|
+
// PredictionMarketV3_4(PREDICTION_MARKET_V3_4).setAllowedManager(PREDICTION_MARKET_V3_MANAGER, true);
|
|
91
|
+
|
|
92
|
+
vm.stopBroadcast();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
|
|
8
|
+
|
|
9
|
+
contract DeployMerkleRewardsDistributor is Script {
|
|
10
|
+
function run() public {
|
|
11
|
+
vm.startBroadcast();
|
|
12
|
+
|
|
13
|
+
address admin = address(0xAE7Bfff784EeEe7812D6527B72c77A7Ed773Ed9D);
|
|
14
|
+
|
|
15
|
+
// it's a proxy
|
|
16
|
+
address implementation = address(new MerkleRewardsDistributor());
|
|
17
|
+
bytes memory initData = abi.encodeCall(MerkleRewardsDistributor.initialize, (admin));
|
|
18
|
+
console.log("Initialization data for proxy:");
|
|
19
|
+
console.logBytes(initData);
|
|
20
|
+
|
|
21
|
+
ERC1967Proxy proxy = new ERC1967Proxy(implementation, initData);
|
|
22
|
+
MerkleRewardsDistributor distributor = MerkleRewardsDistributor(address(proxy));
|
|
23
|
+
console.log("MerkleRewardsDistributor deployed at:", address(distributor));
|
|
24
|
+
|
|
25
|
+
vm.stopBroadcast();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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 DeployToken is Script {
|
|
9
|
+
function run() public {
|
|
10
|
+
vm.startBroadcast();
|
|
11
|
+
|
|
12
|
+
ERC20MinterPauser token = new ERC20MinterPauser("Myriad Cure", "MYRCURE");
|
|
13
|
+
console.log("Token deployed at:", address(token));
|
|
14
|
+
|
|
15
|
+
vm.stopBroadcast();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -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(0x54eC4711c4a429D7b0466dd169079f276a868462);
|
|
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
|
+
// }
|
package/src/Application.js
CHANGED
|
@@ -17,6 +17,7 @@ const FantasyERC20Contract = require("./models/index").FantasyERC20Contract;
|
|
|
17
17
|
const WETH9Contract = require("./models/index").WETH9Contract;
|
|
18
18
|
const ArbitrationContract = require("./models/index").ArbitrationContract;
|
|
19
19
|
const ArbitrationProxyContract = require("./models/index").ArbitrationProxyContract;
|
|
20
|
+
const MerkleRewardsDistributorContract = require("./models/index").MerkleRewardsDistributorContract;
|
|
20
21
|
|
|
21
22
|
const DualProvider = require("./utils/DualProvider");
|
|
22
23
|
const Account = require('./utils/Account');
|
|
@@ -37,6 +38,7 @@ class Application {
|
|
|
37
38
|
web3EventsProvider,
|
|
38
39
|
gasPrice,
|
|
39
40
|
isSocialLogin = false,
|
|
41
|
+
useGaslessTransactions,
|
|
40
42
|
socialLoginParams,
|
|
41
43
|
startBlock,
|
|
42
44
|
defaultDecimals,
|
|
@@ -48,6 +50,8 @@ class Application {
|
|
|
48
50
|
// fixed gas price for txs (optional)
|
|
49
51
|
this.gasPrice = gasPrice;
|
|
50
52
|
this.isSocialLogin = isSocialLogin;
|
|
53
|
+
// If useGaslessTransactions is not explicitly set, default to true when isSocialLogin is true, otherwise false (backwards compatibility)
|
|
54
|
+
this.useGaslessTransactions = useGaslessTransactions !== undefined ? useGaslessTransactions : isSocialLogin;
|
|
51
55
|
this.startBlock = startBlock;
|
|
52
56
|
this.defaultDecimals = defaultDecimals;
|
|
53
57
|
// use DualProvider to separate read (HttpProvider) and write (window.ethereum) operations
|
|
@@ -91,6 +95,8 @@ class Application {
|
|
|
91
95
|
/**
|
|
92
96
|
* @name login
|
|
93
97
|
* @description Login with Metamask or a web3 provider
|
|
98
|
+
* @param {Object} provider
|
|
99
|
+
* @param {Boolean} isConnectedWallet
|
|
94
100
|
*/
|
|
95
101
|
async login(provider = null, isConnectedWallet = null) {
|
|
96
102
|
if (this.isSocialLogin) {
|
|
@@ -98,9 +104,14 @@ class Application {
|
|
|
98
104
|
this.smartAccount = PolkamarketsSmartAccount.singleton.getInstanceIfExists()
|
|
99
105
|
}
|
|
100
106
|
|
|
101
|
-
if (
|
|
107
|
+
if (provider) {
|
|
102
108
|
PolkamarketsSmartAccount.singleton.clearInstance();
|
|
103
109
|
this.smartAccount = PolkamarketsSmartAccount.singleton.getInstance(provider, this.socialLoginParams.networkConfig, isConnectedWallet);
|
|
110
|
+
|
|
111
|
+
// Store thirdweb account reference if provider has sendTransaction method
|
|
112
|
+
if (typeof provider.sendTransaction === 'function') {
|
|
113
|
+
this.smartAccount.thirdwebAccount = provider;
|
|
114
|
+
}
|
|
104
115
|
}
|
|
105
116
|
|
|
106
117
|
return true;
|
|
@@ -157,6 +168,7 @@ class Application {
|
|
|
157
168
|
web3EventsProvider: this.web3EventsProvider,
|
|
158
169
|
gasPrice: this.gasPrice,
|
|
159
170
|
isSocialLogin: this.isSocialLogin,
|
|
171
|
+
useGaslessTransactions: this.useGaslessTransactions,
|
|
160
172
|
startBlock: this.startBlock,
|
|
161
173
|
defaultDecimals: this.defaultDecimals
|
|
162
174
|
};
|
|
@@ -401,6 +413,21 @@ class Application {
|
|
|
401
413
|
}
|
|
402
414
|
};
|
|
403
415
|
|
|
416
|
+
/**
|
|
417
|
+
* @name getMerkleRewardsDistributorContract
|
|
418
|
+
* @param {Address} ContractAddress (Opt) If it is deployed
|
|
419
|
+
* @description Create a Merkle Rewards Distributor Contract
|
|
420
|
+
*/
|
|
421
|
+
getMerkleRewardsDistributorContract({ contractAddress = null }) {
|
|
422
|
+
try {
|
|
423
|
+
return new MerkleRewardsDistributorContract({
|
|
424
|
+
...this.contractDefaultParams(contractAddress)
|
|
425
|
+
});
|
|
426
|
+
} catch (err) {
|
|
427
|
+
throw err;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
404
431
|
/***********/
|
|
405
432
|
/** UTILS **/
|
|
406
433
|
/***********/
|
package/src/interfaces/index.js
CHANGED
|
@@ -15,6 +15,7 @@ let index = {
|
|
|
15
15
|
predictionMarketV3Factory: require("../../abis/PredictionMarketV3Factory.json"),
|
|
16
16
|
predictionV3Querier: require("../../abis/PredictionMarketV3Querier.json"),
|
|
17
17
|
realitio: require("../../abis/RealitioERC20.json"),
|
|
18
|
+
merkleRewardsDistributor: require("../../abis/MerkleRewardsDistributor.json"),
|
|
18
19
|
voting: require("../../abis/Voting.json"),
|
|
19
20
|
weth: require("../../abis/WETH9.json"),
|
|
20
21
|
};
|
package/src/models/IContract.js
CHANGED
|
@@ -34,6 +34,7 @@ class IContract {
|
|
|
34
34
|
web3EventsProvider,
|
|
35
35
|
gasPrice,
|
|
36
36
|
isSocialLogin = false,
|
|
37
|
+
useGaslessTransactions,
|
|
37
38
|
startBlock
|
|
38
39
|
}) {
|
|
39
40
|
try {
|
|
@@ -58,6 +59,8 @@ class IContract {
|
|
|
58
59
|
gasPrice,
|
|
59
60
|
contract: new Contract(web3, abi, contractAddress),
|
|
60
61
|
isSocialLogin,
|
|
62
|
+
// (For backwards compatibility) If useGaslessTransactions is not explicitly set, default to true when isSocialLogin is true, otherwise false
|
|
63
|
+
useGaslessTransactions: useGaslessTransactions !== undefined ? useGaslessTransactions : isSocialLogin,
|
|
61
64
|
startBlock,
|
|
62
65
|
};
|
|
63
66
|
} catch (err) {
|
|
@@ -590,6 +593,30 @@ class IContract {
|
|
|
590
593
|
return receipt;
|
|
591
594
|
}
|
|
592
595
|
|
|
596
|
+
async useThirdWebWithUserPaidGas(tx, networkConfig, smartAccount) {
|
|
597
|
+
const client = createThirdwebClient({ clientId: networkConfig.thirdWebClientId });
|
|
598
|
+
const chain = defineChain(networkConfig.chainId);
|
|
599
|
+
|
|
600
|
+
if (!smartAccount || typeof smartAccount.sendTransaction !== 'function') {
|
|
601
|
+
throw new Error('Invalid account provided - expected thirdweb Account object with sendTransaction method');
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
const res = await smartAccount.sendTransaction({
|
|
605
|
+
to: tx.to,
|
|
606
|
+
data: tx.data,
|
|
607
|
+
gas: BigInt(500000),
|
|
608
|
+
chain: chain,
|
|
609
|
+
});
|
|
610
|
+
|
|
611
|
+
const receipt = await waitForReceipt({
|
|
612
|
+
client,
|
|
613
|
+
chain,
|
|
614
|
+
transactionHash: res.transactionHash,
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
return receipt;
|
|
618
|
+
}
|
|
619
|
+
|
|
593
620
|
async sendGaslessTransactions(f) {
|
|
594
621
|
const smartAccount = PolkamarketsSmartAccount.singleton.getInstance();
|
|
595
622
|
const networkConfig = smartAccount.networkConfig;
|
|
@@ -799,9 +826,68 @@ class IContract {
|
|
|
799
826
|
return transformedEvents;
|
|
800
827
|
}
|
|
801
828
|
|
|
829
|
+
async sendSocialLoginGasTransactions(f) {
|
|
830
|
+
const smartAccount = PolkamarketsSmartAccount.singleton.getInstance();
|
|
831
|
+
const networkConfig = smartAccount.networkConfig;
|
|
832
|
+
|
|
833
|
+
const { isConnectedWallet, signer } = await smartAccount.providerIsConnectedWallet();
|
|
834
|
+
|
|
835
|
+
const methodName = f._method.name;
|
|
836
|
+
|
|
837
|
+
const contractInterface = new ethers.utils.Interface(this.params.abi.abi);
|
|
838
|
+
const methodCallData = contractInterface.encodeFunctionData(methodName, f.arguments);
|
|
839
|
+
|
|
840
|
+
const tx = {
|
|
841
|
+
to: this.params.contractAddress,
|
|
842
|
+
data: methodCallData,
|
|
843
|
+
};
|
|
844
|
+
|
|
845
|
+
try {
|
|
846
|
+
let receipt;
|
|
847
|
+
|
|
848
|
+
if (isConnectedWallet) {
|
|
849
|
+
const txResponse = await signer.sendTransaction({ ...tx, gasLimit: 210000 });
|
|
850
|
+
receipt = await txResponse.wait();
|
|
851
|
+
} else {
|
|
852
|
+
if (networkConfig.useThirdWeb) {
|
|
853
|
+
const thirdwebAccount = smartAccount.getThirdwebAccount();
|
|
854
|
+
if (!thirdwebAccount) {
|
|
855
|
+
throw new Error('ThirdWeb account not found. Make sure you passed the thirdweb account when calling login()');
|
|
856
|
+
}
|
|
857
|
+
receipt = await this.useThirdWebWithUserPaidGas(tx, networkConfig, thirdwebAccount);
|
|
858
|
+
} else {
|
|
859
|
+
throw new Error('User-paid transactions are only supported with ThirdWeb configuration');
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
console.log('receipt:', receipt.status, receipt.transactionHash);
|
|
864
|
+
|
|
865
|
+
if (receipt.logs) {
|
|
866
|
+
const events = receipt.logs.map(log => {
|
|
867
|
+
try {
|
|
868
|
+
const event = contractInterface.parseLog(log);
|
|
869
|
+
return event;
|
|
870
|
+
} catch (error) {
|
|
871
|
+
return null;
|
|
872
|
+
}
|
|
873
|
+
});
|
|
874
|
+
receipt.events = this.convertEtherEventsToWeb3Events(events);
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
return receipt;
|
|
878
|
+
} catch (error) {
|
|
879
|
+
console.error(error);
|
|
880
|
+
throw error;
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
|
|
802
884
|
async __sendTx(f, call = false, value, callback = () => { }) {
|
|
803
885
|
if (this.params.isSocialLogin && !call) {
|
|
804
|
-
|
|
886
|
+
if (this.params.useGaslessTransactions) {
|
|
887
|
+
return await this.sendGaslessTransactions(f);
|
|
888
|
+
} else {
|
|
889
|
+
return await this.sendSocialLoginGasTransactions(f);
|
|
890
|
+
}
|
|
805
891
|
} else {
|
|
806
892
|
var res;
|
|
807
893
|
if (!this.acc && !call) {
|
|
@@ -1052,6 +1138,20 @@ class IContract {
|
|
|
1052
1138
|
async getBlock(blockNumber) {
|
|
1053
1139
|
return await this.params.web3.eth.getBlock(blockNumber);
|
|
1054
1140
|
}
|
|
1141
|
+
|
|
1142
|
+
async soliditySha3(args) {
|
|
1143
|
+
return this.params.web3.utils.soliditySha3(...args)
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
async signMessage(message) {
|
|
1147
|
+
if (this.acc) {
|
|
1148
|
+
return await this.acc.account.sign(message);
|
|
1149
|
+
} else {
|
|
1150
|
+
// TODO need to test with forntend
|
|
1151
|
+
// return await this.params.web3.eth.sign(message, await this.getMyAccount());
|
|
1152
|
+
return await this.params.web3.eth.personal.sign(message, await this.getMyAccount());
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1055
1155
|
}
|
|
1056
1156
|
|
|
1057
1157
|
module.exports = IContract;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// const _ = require("lodash");
|
|
2
|
+
|
|
3
|
+
const merkleRewardsDistributor = require("../interfaces").merkleRewardsDistributor;
|
|
4
|
+
|
|
5
|
+
const Numbers = require("../utils/Numbers");
|
|
6
|
+
const IContract = require('./IContract');
|
|
7
|
+
|
|
8
|
+
class MerkleRewardsDistributorContract extends IContract {
|
|
9
|
+
constructor(params) {
|
|
10
|
+
super({ abi: merkleRewardsDistributor, ...params });
|
|
11
|
+
this.contractName = 'merkleRewardsDistributor';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// ----- Views -----
|
|
15
|
+
async getRoot({ contestId, tokenAddress }) {
|
|
16
|
+
return await this.params.contract
|
|
17
|
+
.getContract()
|
|
18
|
+
.methods
|
|
19
|
+
.getRoot(contestId, tokenAddress)
|
|
20
|
+
.call();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async isClaimed({ contestId, tokenAddress, index }) {
|
|
24
|
+
return await this.params.contract
|
|
25
|
+
.getContract()
|
|
26
|
+
.methods
|
|
27
|
+
.isClaimed(contestId, tokenAddress, index)
|
|
28
|
+
.call();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async isClaimedMany({ contestIds, tokenAddresses, indices }) {
|
|
32
|
+
return await this.params.contract
|
|
33
|
+
.getContract()
|
|
34
|
+
.methods
|
|
35
|
+
.isClaimedMany(contestIds, tokenAddresses, indices)
|
|
36
|
+
.call();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async isAdmin({ user }) {
|
|
40
|
+
return await this.params.contract
|
|
41
|
+
.getContract()
|
|
42
|
+
.methods
|
|
43
|
+
.isAdmin(user)
|
|
44
|
+
.call();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async getClaims({ user, tokenAddress, index }) {
|
|
48
|
+
return await this.getEvents(
|
|
49
|
+
'Claim',
|
|
50
|
+
{
|
|
51
|
+
user,
|
|
52
|
+
tokenAddress,
|
|
53
|
+
index
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// ----- Admin -----
|
|
59
|
+
async publishRoot({ contestId, tokenAddress, root }) {
|
|
60
|
+
return await this.__sendTx(
|
|
61
|
+
this.getContract().methods.publishRoot(contestId, tokenAddress, root)
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async addAdmin({ user }) {
|
|
66
|
+
return await this.__sendTx(
|
|
67
|
+
this.getContract().methods.addAdmin(user)
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async removeAdmin({ user }) {
|
|
72
|
+
return await this.__sendTx(
|
|
73
|
+
this.getContract().methods.removeAdmin(user)
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async withdraw({ tokenAddress, amount }) {
|
|
78
|
+
const amountDecimals = Numbers.toSmartContractDecimals(amount, 18);
|
|
79
|
+
return await this.__sendTx(
|
|
80
|
+
this.getContract().methods.withdraw(tokenAddress, amountDecimals)
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ----- Claims -----
|
|
85
|
+
async claim({ contestId, tokenAddress, index, user, amount, proof }) {
|
|
86
|
+
const amountDecimals = Numbers.toSmartContractDecimals(amount, 18);
|
|
87
|
+
return await this.__sendTx(
|
|
88
|
+
this.getContract().methods.claim(contestId, tokenAddress, index, user, amountDecimals, proof)
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async claimMany({ entries }) {
|
|
93
|
+
// entries: array of { contestId, tokenAddress, index, user, amount, proof }
|
|
94
|
+
const contestIds = entries.map(e => e.contestId);
|
|
95
|
+
const tokens = entries.map(e => e.tokenAddress);
|
|
96
|
+
const indices = entries.map(e => e.index);
|
|
97
|
+
const users = entries.map(e => e.user);
|
|
98
|
+
const amounts = entries.map(e => Numbers.toSmartContractDecimals(e.amount, 18));
|
|
99
|
+
const proofs = entries.map(e => e.proof);
|
|
100
|
+
|
|
101
|
+
return await this.__sendTx(
|
|
102
|
+
this.getContract().methods.claimMany(contestIds, tokens, indices, users, amounts, proofs)
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
module.exports = MerkleRewardsDistributorContract;
|