Skip to content

Commit

Permalink
feat: upgrade dice and coinflip to retrieve multiple player results
Browse files Browse the repository at this point in the history
  • Loading branch information
RasenGUY committed Nov 29, 2023
1 parent c697dad commit ec8cd31
Show file tree
Hide file tree
Showing 26 changed files with 418 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50009,6 +50009,6 @@
"signature": "a504f1960fcd275cc72e8d25ff333a0b76fcf239790f41370997a3e6e67199ac47fe0603e3f149c744f1ba1b36993a55"
}
],
"lastStoredIndex": 600
"lastStoredIndex": 1100
}
}
1 change: 1 addition & 0 deletions contracts/FeeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ contract FeeManager is WegaProtocolAdminRole, IFeeManager, IFeeManagerEvents, UU
mapping(address => FeeConfig) public _feeRules;

function initialize() public initializer {
__UUPSUpgradeable_init();
__FeeManager_init();
}

Expand Down
8 changes: 7 additions & 1 deletion contracts/games/IWega.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ interface IWega is IWegaDiceGame, IWegaCoinFlipGame {
function winners(bytes32 escrowHash) external view returns (address[] memory);

/**
* @notice returns players of a game
* @notice returns reesults of players of a game
* @param escrowHash id of the escrow
* @param player player address
*/
function playerResults(bytes32 escrowHash, address player) external view returns (uint256[] memory);
/**
* @notice returns results of players of a game
* @param escrowHash id of the escrow
* @param players player addresseses
*/
function multiplePlayersResults(bytes32 escrowHash, address[] memory players) external view returns (uint256[][] memory results);

/**
* @notice returns player points for a game
Expand Down
11 changes: 10 additions & 1 deletion contracts/games/Wega.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,19 @@ abstract contract Wega is IWega, WegaProtocolAdminRole, UUPSUpgradeable {
return _winners[escrowHash].values();
}

function playerResults(bytes32 escrowHash, address player) external view override returns(uint256[] memory) {
function playerResults(bytes32 escrowHash, address player) public view override returns(uint256[] memory) {
return _gameResults[escrowHash][player];
}

function multiplePlayersResults(bytes32 escrowHash, address[] memory players) external view override returns (
uint256[][] memory results
){
results = new uint256[][](players.length);
for(uint i = 0; i< players.length;i++) {
results[i] = playerResults(escrowHash, players[i]);
}
}

function playerScore(bytes32 escrowHash, address player) external view override returns(uint256){
return _playerScores[escrowHash][player];
}
Expand Down
1 change: 1 addition & 0 deletions contracts/randomizer/WegaRandomizer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ contract WegaRandomizer is IWegaRandomizer, Ownable, Nonces {

using EnumerableMap for EnumerableMap.UintToUintMap;
using Math for uint256;

EnumerableMap.UintToUintMap private _randomNumbers;

constructor(uint256[] memory randomNumbers) Ownable(_msgSender()) {
Expand Down
81 changes: 61 additions & 20 deletions deployed-addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,48 @@
"1337": {
"contracts": {
"WegaERC20Escrow": {
"address": "0xa82fF9aFd8f496c3d6ac40E2a0F282E47488CFc9",
"address": "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707",
"legacyAddresses": [
"0x5FC8d32690cc91D4c39d9d3abcBD16989F875707"
],
"deploymentBlock": "130",
"implementation": "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853"
"implementation": "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9"
},
"WegaERC20Dummy": {
"address": "0xc3e53F4d16Ae77Db1c982e75a937B9f60FE63690",
"address": "0x5FbDB2315678afecb367f032d93F642f64180aa3",
"legacyAddresses": [],
"deploymentBlock": "12c"
},
"WegaGameController": {
"address": "0x0E801D84Fa97b50751Dbf25036d067dCf18858bF",
"address": "0x9A9f2CCfdE556A7E9Ff0848998Aa4a0CFD8863AE",
"legacyAddresses": [
"0x5FC8d32690cc91D4c39d9d3abcBD16989F875707"
],
"deploymentBlock": "138",
"implementation": "0x09635F643e140090A9A8Dcd712eD6285858ceBef"
"implementation": "0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1"
},
"WegaRandomizerController": {
"address": "0xf5059a5D33d5853360D16C683c16e67980206f36",
"address": "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6",
"legacyAddresses": [],
"implementation": "0x851356ae760d987E095750cCeb3bC6014560891C"
"implementation": "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853"
},
"WegaDiceGame": {
"address": "0x4826533B4897376654Bb4d4AD88B7faFD0C98528",
"address": "0x9A676e781A523b5d0C0e43731313A708CB607508",
"legacyAddresses": [],
"deploymentBlock": "136",
"implementation": "0xa85233C63b9Ee964Add6F2cffe00Fd84eb32338f"
"implementation": "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82"
},
"WegaCoinFlipGame": {
"address": "0x998abeb3E57409262aE5b751f60747921B33613E",
"address": "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
"legacyAddresses": [],
"deploymentBlock": "134",
"implementation": "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82"
"implementation": "0x610178dA211FEF7D417bC0e6FeD39F05609AD788"
},
"FeeManager": {
"address": "0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB",
"address": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0",
"legacyAddresses": [],
"deploymentBlock": "12e",
"implementation": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0"
"implementation": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512"
},
"WegaRandomizer": {
"address": "0x0000000000000000000000000000000000000000"
Expand All @@ -67,28 +67,69 @@
"80001": {
"contracts": {
"WegaERC20Escrow": {
"address": "0x0000000000000000000000000000000000000000"
"address": "0xCEBc6b24362cA2F4fA625d340BeF8Af4F91DB5bB",
"legacyAddresses": [],
"deploymentBlock": "263113a",
"implementation": "0x0993a07880aD59E02e72E745dC5b623409Ad24af"
},
"WegaERC20Dummy": {
"address": "0x0000000000000000000000000000000000000000"
"address": "0x802361100a4772847DBc29BC59F76FD1F186E002",
"legacyAddresses": [],
"deploymentBlock": "263112e"
},
"WegaGameController": {
"address": "0x0000000000000000000000000000000000000000"
"address": "0xe4da6EE02D91b7C03DB000B9295A815D6BEeC4ca",
"legacyAddresses": [
"0x760D87Ce891F301d19F608044D42356De2D50D14",
"0x740e1416aE865E2bff8f95aa5776F5Fa0a3706e7",
"0x02D7EF0f678BCd9323f2FA88e7197528D113f24a",
"0x0000000000000000000000000000000000000000"
],
"deploymentBlock": "272c37b",
"implementation": "0x21A8Eda1B590268410e520B70635467720B41418"
},
"WegaRandomizerController": {
"address": "0x0000000000000000000000000000000000000000"
"address": "0xcd44090c1BC8DC05298540488ca6FA058d27Ac70",
"legacyAddresses": [],
"implementation": "0x24F9E5E74976661E3784E258986Ee9ee6AAe8132",
"deploymentBlock": null
},
"WegaDiceGame": {
"address": "0x0000000000000000000000000000000000000000"
"address": "0x5581147651B29D44d4eD95099F1a53aAE052f797",
"legacyAddresses": [
"0x4f2Fe30D48961581d65C0a486AE5e83A9b8356b0"
],
"deploymentBlock": null,
"implementation": "0x6c55167230Fb4abD7258755f5c3a1e50ff4321dD"
},
"WegaCoinFlipGame": {
"address": "0x0000000000000000000000000000000000000000"
"address": "0x24133b29067AC3858B4F58112bCAC243941538c8",
"legacyAddresses": [
"0x0C438E3C3B7b629044573e7cc3B0FBe55DB1b8b6"
],
"deploymentBlock": null,
"implementation": "0x9d31BD6EABAaa5Bf0aCceF23c834E870d2e194B4"
},
"FeeManager": {
"address": "0x0000000000000000000000000000000000000000"
"address": "0xe2cDC641b8AF26a208402a3e218EE022E954Afd0",
"legacyAddresses": [],
"implementation": "0x30D1C9b043014820cC878ea023bd9Ae53238B395",
"deploymentBlock": null
},
"WegaRandomizer": {
"address": "0x0000000000000000000000000000000000000000"
},
"WegaChanceGame": {
"address": "0x85c5165800E4f43489912beEc115a77E312142ca",
"legacyAddresses": [],
"deploymentBlock": "25e6a43",
"implementation": "0x945Fbb4138040e2ab766CB59A7Aa6D882AfBCcF4"
},
"WegaRandomNumberController": {
"address": "0xaBC8837A5756aF9a915a8cC77b80b06c1997e17e",
"legacyAddresses": [],
"deploymentBlock": "2631148",
"implementation": "0xCC6e334201974DF201EBb4bd84b97ac232fE7380"
}
}
},
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@openzeppelin/contracts": "^5.0.0",
"@openzeppelin/contracts-upgradeable": "^5.0.0",
"@openzeppelin/hardhat-upgrades": "^2.4.1",
"@openzeppelin/upgrades-core": "^1.20.5",
"@openzeppelin/upgrades-core": "^1.31.1",
"@typechain/ethers-v6": "^0.5.1",
"@typechain/hardhat": "^9.1.0",
"@types/chai": "^4.3.4",
Expand All @@ -43,7 +43,7 @@
"scripts": {
"compile": "hardhat compile --force",
"compile:size": "env ENABLE_CONTRACT_SIZER=true yarn compile",
"deploy:localhost": "hardhat run --network localhost scripts/deploy_full.ts",
"deploy:localhost": "hardhat run --network localhost scripts/deploy_full.ts && UI_PATH=../wega-platform-app yarn run exp:demo-ui",
"deploy:localhost:erc20-dummy": "hardhat run --network localhost scripts/deploy_erc20-dummy.ts",
"deploy:localhost:erc20-escrow": "hardhat run --network localhost scripts/deploy_escrow.ts",
"deploy:localhost:random-number-controller": "hardhat run --network localhost scripts/deploy_random-number-controller.ts",
Expand All @@ -62,7 +62,10 @@
"upgrade:localhost:contract": "hardhat run --network localhost scripts/upgrade_contract.ts",
"upgrade:localhost:game-controller": "hardhat run --network localhost scripts/upgrade_game-controller.ts",
"upgrade:mumbai:contract": "hardhat run --network mumbai scripts/upgrade_contract.ts",
"verify:mumbai:contract": "hardhat run --network mumbai scripts/verify_contract.ts",
"upgrade:mumbai:game-controller": "hardhat run --network mumbai scripts/upgrade_game-controller.ts",
"configure:mumbai": "hardhat run --network mumbai scripts/configure_protocol.ts",
"configure-fees:mumbai": "hardhat run --network mumbai scripts/set_fee-rules.ts",
"exp:demo-ui": "rm -rf $UI_PATH/deployed-addresses.json && cp -rf deployed-addresses.json $UI_PATH",
"start:node": "hardhat node",
"drand": "ts-node ./scripts/crawl-random-numbers.ts",
Expand All @@ -75,6 +78,7 @@
"debug": "^4.3.4",
"ethereum-cryptography": "^1.1.2",
"ethereumjs-tx": "^2.1.2",
"ethereumjs-util": "^7.1.5",
"ganache": "^7.7.2",
"immer": "^9.0.19",
"lodash": "^4.17.21",
Expand Down
30 changes: 25 additions & 5 deletions scripts/configure_protocol.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
import { network } from 'hardhat';
import { getNetworkConfig } from '../src/config';
import { toBigInt } from 'ethers';
import {
getNetworkConfig,
getRandomNumbersConfig,
mergeRandomNumConfig
} from '../src/config';
import { Deployer } from '../src/deployer';
import { unwrap } from '../src/helpers';

async function main () {
const deployer = await Deployer.create();
deployer.log('Network:', network.name);
const chainId: number = unwrap(network.config, 'chainId');
const drandChainhash: string = "dbd506d6ef76e5f386f41c651dcb808c5bcbd75471cc4eafa3f4df7ad4e4c493";
const randomNumConfig = getRandomNumbersConfig(drandChainhash);
const config = getNetworkConfig(chainId);

if (!config) {
throw new Error(`HDNS config not found for network ${chainId}`);
}
await deployer.execute(['configure_protocol'], config);
const deployer = await Deployer.create();
const drandIndexesToAdd = 1000;
const initialDrands = randomNumConfig[chainId].drands.map(({ randomness }) => toBigInt(randomness)).slice(0, 101);
const drands = randomNumConfig[chainId].drands.map(({ randomness }) => toBigInt(randomness)).slice(101, drandIndexesToAdd + 1);
deployer.log('Network:', network.name);


await deployer.execute(['configure_wega_protocol'], config, {
initialDrands,
drands
});
// adds all the relevant access control info
deployer.log('Upgrade: Contract', network.name);
deployer.log('Configure Prototocol', network.name);
mergeRandomNumConfig({[chainId]: {
...randomNumConfig[chainId],
lastStoredIndex: drandIndexesToAdd + 100,
}}, drandChainhash);
}

main()
Expand Down
4 changes: 2 additions & 2 deletions scripts/crawl-random-numbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ async function getRandomNumber(
headers: {
'Access-Control-Allow-Origin': '*'
},
credentials: 'same-origin' as RequestCredentials,
cache: 'no-cache' as RequestCache
credentials: 'strict-origin-when-cross-origin' as RequestCredentials,
cache: 'no-cache' as RequestCache,
}

const url = `https://api.drand.sh/dbd506d6ef76e5f386f41c651dcb808c5bcbd75471cc4eafa3f4df7ad4e4c493/public/4000`;
Expand Down
13 changes: 8 additions & 5 deletions scripts/deploy_full.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { unwrap } from '../src/helpers';
import { toBigInt } from 'ethers';

async function main() {
console.log('Network:', network.name);

const chainId: number = unwrap(network.config, 'chainId');
const drandChainhash: string = "dbd506d6ef76e5f386f41c651dcb808c5bcbd75471cc4eafa3f4df7ad4e4c493";
Expand All @@ -21,9 +20,11 @@ async function main() {
}

const deployer = await Deployer.create();
const drandIndexesToAdd = 500;
const drandIndexesToAdd = 1000;
const initialDrands = randomNumConfig[chainId].drands.map(({ randomness }) => toBigInt(randomness)).slice(0, 101);
const drands = randomNumConfig[chainId].drands.map(({ randomness }) => toBigInt(randomness)).slice(101, drandIndexesToAdd + 1);
const drands = randomNumConfig[chainId].drands.map(({ randomness }) => toBigInt(randomness)).slice(101, drandIndexesToAdd + 1);
deployer.log('Network:', network.name);

const deployConfig = await deployer.execute(['full'], config, {
tokenReceivers: chainId == 1337 ? [
'0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
Expand All @@ -40,12 +41,14 @@ async function main() {
] : [
"0x34fc161801F76173352b1C43f904d2F7cC5cB6C9",
"0x6f915E4e31755c09CCCc0B12DA730377913802f3",
"0x24597c5c68687e816ffc0c69e064cb70bb62a9cd"
"0x24597c5c68687e816ffc0c69e064cb70bb62a9cd",
"0x011dF297Da65Cb87a9a8878fF4C8F7d0D3814314",
"0xd3d52Ea63F1b89b7567CCEa367Dc641A66fD2507"
],
escrow: ['Wega ERC20 Escrow Service', '0.0.0'],
initialDrands,
drands,
feeTaker: chainId == 1337 ? '0xBcd4042DE499D14e55001CcbB24a551F3b954096' : '0x13C38b2bd4cF15985a1505fc4FAA65aE2AdE45A5',
feeTaker: chainId == 1337 ? '0xBcd4042DE499D14e55001CcbB24a551F3b954096' : chainId === 80001 ? "0x011dF297Da65Cb87a9a8878fF4C8F7d0D3814314" : '0x13C38b2bd4cF15985a1505fc4FAA65aE2AdE45A5',
});
mergeNetworkConfig(deployConfig);
mergeRandomNumConfig({[chainId]: {
Expand Down
4 changes: 3 additions & 1 deletion scripts/set_fee-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ async function main () {
if (!config) {
throw new Error(`HDNS config not found for network ${chainId}`);
}
await deployer.execute(['set_fee_rules'], config);
await deployer.execute(['set_fee_rules'], config, {
feeTaker: chainId == 1337 ? '0xBcd4042DE499D14e55001CcbB24a551F3b954096' : chainId === 80001 ? "0x011dF297Da65Cb87a9a8878fF4C8F7d0D3814314" : '0x13C38b2bd4cF15985a1505fc4FAA65aE2AdE45A5'
});
deployer.log('Fee rules set');
}

Expand Down
8 changes: 6 additions & 2 deletions scripts/upgrade_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ async function main () {
}
await deployer.execute(['upgrade_contract'], config, [
{
artifactName: ArtifactName.WegaERC20Escrow,
contractName: ContractName.WegaERC20Escrow,
artifactName: ArtifactName.WegaDiceGame,
contractName: ContractName.WegaDiceGame,
},
{
artifactName: ArtifactName.WegaCoinFlipGame,
contractName: ContractName.WegaCoinFlipGame,
},
]);
deployer.log('Upgrade: Contract', network.name);
Expand Down
33 changes: 33 additions & 0 deletions scripts/verify_contract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { network } from 'hardhat';
import { getNetworkConfig } from '../src/config';
import { Deployer } from '../src/deployer';
import { unwrap } from '../src/helpers';
import { ArtifactName, ContractName } from '../src/types';

async function main () {
const deployer = await Deployer.create();
deployer.log('Network:', network.name);
const chainId: number = unwrap(network.config, 'chainId');
const config = getNetworkConfig(chainId);
if (!config) {
throw new Error(`HDNS config not found for network ${chainId}`);
}
await deployer.execute(['verify_contract'], config, [
{
artifactName: ArtifactName.WegaDiceGame,
contractName: ContractName.WegaDiceGame,
},
{
artifactName: ArtifactName.WegaCoinFlipGame,
contractName: ContractName.WegaCoinFlipGame,
},
]);
deployer.log('Verify: Contract', network.name);
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
Loading

0 comments on commit ec8cd31

Please sign in to comment.