Skip to content

Commit

Permalink
ref: update deployment repo
Browse files Browse the repository at this point in the history
  • Loading branch information
RasenGUY committed Nov 22, 2023
1 parent 80a8314 commit 5a11828
Show file tree
Hide file tree
Showing 33 changed files with 787 additions and 598 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25003,7 +25003,7 @@
"signature": "a504f1960fcd275cc72e8d25ff333a0b76fcf239790f41370997a3e6e67199ac47fe0603e3f149c744f1ba1b36993a55"
}
],
"lastStoredIndex": 100
"lastStoredIndex": 600
},
"80001": {
"lastParsedRound": 4999,
Expand Down
12 changes: 6 additions & 6 deletions contracts/FeeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ contract FeeManager is WegaProtocolAdminRole, IFeeManager, IFeeManagerEvents, UU

function __FeeManager_init_unchained() internal onlyInitializing {}

function _setFeeConfig(address applier, FeeConfig memory config) internal {
_feeRules[applier] = config;
emit SetFeeRule(applier, config.feeTaker, config.feeShare);
function _setFeeConfig(FeeConfig memory config) internal {
_feeRules[config.applier] = config;
emit SetFeeRule(config.applier, config.feeTaker, config.feeShare);
}

function setFeeConfigs(address[] memory appliers, FeeConfig[] memory configs) external onlyWegaProtocolAdmin {
for(uint i = 0; i < appliers.length; i++) {
_setFeeConfig(appliers[i], configs[i]);
function setFeeConfigs(FeeConfig[] memory configs) external onlyWegaProtocolAdmin {
for(uint i = 0; i < configs.length; i++) {
_setFeeConfig(configs[i]);
}
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/IFeeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.14;
interface IFeeManager {

struct FeeConfig {
address applier;
address feeTaker;
uint256 feeShare;
bool shouldApply;
Expand All @@ -16,10 +17,9 @@ interface IFeeManager {
function calculateFeesForTransfer(address applier, uint256 transferAmount) external returns (address feeTaker, uint256 feeAmount, uint256 sendAmount);
/**
* @notice allows an admin to set fee rules
* @param appliers list of addresses that wil apply the fee
* @param configs fee rules to be applied
*/
function setFeeConfigs(address[] memory appliers, FeeConfig[] memory configs) external;
function setFeeConfigs(FeeConfig[] memory configs) external;
/**
* @notice returns configurations on a fee rule
* @param applier list of addresses that wil apply the fee
Expand Down
29 changes: 13 additions & 16 deletions contracts/WegaGameController.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma solidity ^0.8.14;

import "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableSetUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableMapUpgradeable.sol";
Expand Down Expand Up @@ -52,30 +52,27 @@ contract WegaGameController is
function initialize(
address erc20EscrowAddress,
address randomNumberController,
string[] memory games,
GameSettings[] memory gameSettings
) initializer public {
__WegaGameController_init(erc20EscrowAddress, games, gameSettings);
__WegaController_init(erc20EscrowAddress, gameSettings);
__WegaProtocolAdminRole_init();
__UUPSUpgradeable_init();
randomizer = IWegaRandomNumberController(randomNumberController);
}

function __WegaGameController_init(
function __WegaController_init(
address erc20EscrowAddress,
string[] memory games,
GameSettings[] memory gameSettings
) public onlyInitializing {
__WegaGameController_init_unchained(erc20EscrowAddress, games, gameSettings);
__WegaController_init_unchained(erc20EscrowAddress, gameSettings);
}

function __WegaGameController_init_unchained(
function __WegaController_init_unchained(
address erc20EscrowAddress,
string[] memory games,
GameSettings[] memory gameSettings
) public onlyInitializing {
erc20Escrow = IWegaERC20Escrow(erc20EscrowAddress);
for(uint256 i = 0; i < games.length; i++) {
for(uint256 i = 0; i < gameSettings.length; i++) {
_registeredGames[gameSettings[i].name.keyHash()] = gameSettings[i].proxy;
_gameNameHashes.add(gameSettings[i].name.keyHash());
_setGameConfiguration(gameSettings[i]);
Expand All @@ -90,7 +87,7 @@ contract WegaGameController is
) public override {
require(_gameNameHashes.contains(name.keyHash()), INVALID_WEGA_GAME);
GameSettings memory settings = getGameSettings(name);
_beforeCreateOrDeposit(randomNumbers);
_seedRandomizerBeforeCreateOrDeposit(randomNumbers);
bytes32 escrowHash = erc20Escrow.createWagerRequest(
tokenAddress,
_msgSender(),
Expand All @@ -111,8 +108,8 @@ contract WegaGameController is
function depositOrPlay(bytes32 escrowHash, uint256[] memory randomNumbers) public override {
IWega.Wega memory game =_games[escrowHash];
GameSettings memory settings = getGameSettings(game.name);
_deposit(escrowHash);
_beforeCreateOrDeposit(randomNumbers);
_depositWagerTo(escrowHash);
_seedRandomizerBeforeCreateOrDeposit(randomNumbers);
if(_games[escrowHash].deposited == settings.requiredPlayers) {
_playDice(settings.proxy, escrowHash, _games[escrowHash].currentPlayers, settings.denominator, settings.minRounds);
}
Expand All @@ -125,8 +122,8 @@ contract WegaGameController is
) public override {
IWega.Wega memory game =_games[escrowHash];
GameSettings memory settings = getGameSettings(game.name);
_deposit(escrowHash);
_beforeCreateOrDeposit(randomNumbers);
_depositWagerTo(escrowHash);
_seedRandomizerBeforeCreateOrDeposit(randomNumbers);
if(_games[escrowHash].deposited == settings.requiredPlayers) {
_playCoinFlip(
settings.proxy,
Expand Down Expand Up @@ -177,7 +174,7 @@ contract WegaGameController is
emit WinnerDeclaration(escrowHash, gameWinners);
}

function _deposit(bytes32 escrowHash) internal {
function _depositWagerTo(bytes32 escrowHash) internal {
IWega.Wega memory game =_games[escrowHash];
GameSettings memory settings = getGameSettings(game.name);
IEscrow.ERC20WagerRequest memory wagerRequest = erc20Escrow.getWagerRequest(escrowHash);
Expand Down Expand Up @@ -266,7 +263,7 @@ contract WegaGameController is

function _authorizeUpgrade(address newImplementation) internal onlyOwner override {}

function _beforeCreateOrDeposit(uint256[] memory randomNumbers) internal {
function _seedRandomizerBeforeCreateOrDeposit(uint256[] memory randomNumbers) internal {
randomizer.addRandomNumbers(randomNumbers);
}
}
19 changes: 11 additions & 8 deletions contracts/games/Wega.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";

import "../escrow/WegaERC20Escrow.sol";
import "../roles/WegaGameManagerRole.sol";
import "../roles/WegaProtocolAdminRole.sol";
import "../IWegaRandomNumberController.sol";
import "../errors/AccessControlErrors.sol";
import "../utils/Arrays.sol";
import "./IWega.sol";


abstract contract Wega is IWega, WegaGameManagerRole, UUPSUpgradeable {
abstract contract Wega is IWega, WegaProtocolAdminRole, UUPSUpgradeable {

using EnumerableMap for EnumerableMap.UintToUintMap;
using EnumerableSetUpgradeable for EnumerableSetUpgradeable.AddressSet;
Expand All @@ -39,22 +39,25 @@ abstract contract Wega is IWega, WegaGameManagerRole, UUPSUpgradeable {
mapping(bytes32 => mapping(address => uint256)) private _playerScores;
mapping(bytes32 => EnumerableSetUpgradeable.AddressSet) private _winners;
CountersUpgradeable.Counter internal _nonces;
bytes32 public GAME_CONTROLLER_ROLE;



function initialize(
address randomNumberController
) initializer public {
__UUPSUpgradeable_init();
__WegaGameManagerRole_init();
__Wega(randomNumberController);
_addWegaGameManager(owner());
__WegaProtocolAdminRole_init();
__Wega_init(randomNumberController);
GAME_CONTROLLER_ROLE = keccak256('GAME_CONTROLLER_ROLE');
_setRoleAdmin(GAME_CONTROLLER_ROLE, WEGA_PROTOCOL_ADMIN_ROLE);
}

function __Wega(address randomNumberController) public onlyInitializing {
__Wega_unchained(randomNumberController);
function __Wega_init(address randomNumberController) public onlyInitializing {
__Wega_init_unchained(randomNumberController);
}

function __Wega_unchained(address randomNumberController) public onlyInitializing {
function __Wega_init_unchained(address randomNumberController) public onlyInitializing {
randomNumberGen = IWegaRandomNumberController(randomNumberController);
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/games/WegaCoinFlipGame.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ contract WegaCoinFlipGame is Wega {
uint256[] memory playerChoices,
uint256 denominator,
uint256 minRounds
) external override onlyWegaGameManager returns (address[] memory winners) {
) external override onlyRole(GAME_CONTROLLER_ROLE) returns (address[] memory winners) {
_play(escrowHash, currentPlayers, playerChoices, denominator, 1, minRounds);
winners = _declareWinners(escrowHash, currentPlayers);
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/games/WegaDiceGame.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ contract WegaDiceGame is Wega {
address[] memory currentPlayers,
uint256 denominator,
uint256 minRounds
) external override onlyWegaGameManager returns (address[] memory winners) {
) external override onlyRole(GAME_CONTROLLER_ROLE) returns (address[] memory winners) {
_play(escrowHash, currentPlayers, denominator, 1, minRounds);
winners = _declareWinners(escrowHash, currentPlayers);
}
Expand Down
7 changes: 7 additions & 0 deletions contracts/randomizer/IRandomizer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.14;

interface IRandomizer {
function request(uint256 callbackGasLimit) external returns (uint256);
function clientWithdrawTo(address _to, uint256 _amount) external;
}
62 changes: 62 additions & 0 deletions contracts/randomizer/Randomizer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// // SPDX-License-Identifier: MIT
// pragma solidity ^0.8.14;

// import './IRandomizer.sol';

// /**
// * @title Randomizer (MVP)
// * @author @RasenGUY @Daosourced.
// * The contract that handles the business logic for randomness in game
// * We use Randomizer.ai as the random number generator for most if not all games on wega platform
// * Users can withdraw any left over fees from this contract if they have any through withdrawLeftOverFees()
// */
// contract RandomNumberRequester {
// IRandomizer public randomizer;
// address public owner;
// mapping(uint256 => bytes32) private requestToEscrowHash;
// mapping(address => uint256) private balances;

// event Requested(uint256 id, address requester);
// event NumberRetrieved(uint256 id, uint256 randomNumber, address requester);
// event BalanceWithdrawn(address user, uint256 amount);

// constructor(address _randomizerAddress) {
// randomizer = IRandomizer(_randomizerAddress);
// owner = msg.sender;
// }

// modifier onlyOwner() {
// require(msg.sender == owner, "Not owner");
// _;
// }

// // Users call this function to request a random number.
// function rollOnce() external payable {
// uint256 id = randomizer.request(50000); // Example gas limit
// requestToAddress[id] = msg.sender;
// balances[msg.sender] += msg.value; // Track the user's balance
// emit Requested(id, msg.sender);
// }

// // Randomizer calls this function to provide the random number.
// function randomizerCallback(uint256 _id, bytes32 _value) external {
// require(msg.sender == address(randomizer), "Unauthorized caller");
// address user = requestToAddress[_id];
// uint256 randomNumber = uint256(_value);
// emit NumberRetrieved(_id, randomNumber, user);
// }

// // Users call this function to withdraw their balance (if any).
// function withdrawBalance() external {
// uint256 amount = balances[msg.sender];
// require(amount > 0, "No balance to withdraw");
// balances[msg.sender] = 0;
// payable(msg.sender).transfer(amount);
// emit BalanceWithdrawn(msg.sender, amount);
// }

// // Owner can withdraw funds from Randomizer.
// function withdrawFundsFromRandomizer(uint256 amount) external onlyOwner {
// randomizer.clientWithdrawTo(owner, amount);
// }
// }
2 changes: 2 additions & 0 deletions contracts/utils/Distribution.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @author Daosourced
// @date November 7 2023
pragma solidity ^0.8.14;
import "@openzeppelin/contracts/utils/math/Math.sol";

library Distribution {
using Math for uint256;

Expand Down
2 changes: 1 addition & 1 deletion contracts/utils/Strings.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// @author Daosourced
// @date August 21 2023
pragma solidity ^0.8.19;

import "@openzeppelin/contracts/utils/math/Math.sol";

pragma solidity ^0.8.0;

library Strings {
struct Slice {
Expand Down
34 changes: 17 additions & 17 deletions deployed-addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,49 @@
"1337": {
"contracts": {
"WegaERC20Escrow": {
"address": "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707",
"address": "0x8ac87219a0F5639BC01b470F87BA2b26356CB2B9",
"legacyAddresses": [
"0x5FC8d32690cc91D4c39d9d3abcBD16989F875707"
],
"deploymentBlock": "0x06",
"deploymentBlock": "0x0130",
"implementation": "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9"
},
"WegaERC20Dummy": {
"address": "0x5FbDB2315678afecb367f032d93F642f64180aa3",
"address": "0x572316aC11CB4bc5daf6BDae68f43EA3CCE3aE0e",
"legacyAddresses": [],
"deploymentBlock": "0x01"
"deploymentBlock": "0x012c"
},
"WegaGameController": {
"address": "0x99bbA657f2BbC93c02D617f8bA121cB8Fc104Acf",
"address": "0x742489F22807ebB4C36ca6cD95c3e1C044B7B6c8",
"legacyAddresses": [
"0x5FC8d32690cc91D4c39d9d3abcBD16989F875707"
],
"deploymentBlock": "0x2b",
"implementation": "0x4826533B4897376654Bb4d4AD88B7faFD0C98528"
"deploymentBlock": "0x0138",
"implementation": "0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1"
},
"WegaRandomNumberController": {
"address": "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6",
"address": "0xCa1D199b6F53Af7387ac543Af8e8a34455BBe5E0",
"legacyAddresses": [],
"deploymentBlock": "0x09",
"deploymentBlock": "0x0132",
"implementation": "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853"
},
"WegaDiceGame": {
"address": "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82",
"address": "0xB22C255250d74B0ADD1bfB936676D2a299BF48Bd",
"legacyAddresses": [],
"deploymentBlock": "0x0e",
"implementation": "0xA51c1fc2f0D1a1b8494Ed1FE312d7C3a78Ed91C0"
"deploymentBlock": "0x0136",
"implementation": "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82"
},
"WegaCoinFlipGame": {
"address": "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
"address": "0xf5c4a909455C00B99A90d93b48736F3196DB5621",
"legacyAddresses": [],
"deploymentBlock": "0x0c",
"deploymentBlock": "0x0134",
"implementation": "0x610178dA211FEF7D417bC0e6FeD39F05609AD788"
},
"FeeManager": {
"address": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0",
"address": "0x4593ed9CbE6003e687e5e77368534bb04b162503",
"legacyAddresses": [],
"deploymentBlock": "0x03",
"implementation": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512"
"deploymentBlock": "0x012e",
"implementation": "0x975Ab64F4901Af5f0C96636deA0b9de3419D0c2F"
},
"WegaChanceGame": {
"address": "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9",
Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ const config: HardhatUserConfig = {
localhost: ['0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'],
polygon: [process.env.POLYGON_PROTOCOL_ADMIN_ADDRESS as string],
mumbai: [process.env.MUMBAI_PROTOCOL_ADMIN_ADDRESS as string],
}
},
},
};
export default config;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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_bridge.ts",
"deploy:localhost": "hardhat run --network localhost scripts/deploy_full.ts",
"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 Down
1 change: 1 addition & 0 deletions scripts/deploy_full.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ async function main() {
escrow: ['Wega ERC20 Escrow Service', '0.0.0'],
initialDrands,
drands,
feeTaker: chainId == 1337 ? '0xBcd4042DE499D14e55001CcbB24a551F3b954096' : '0x13C38b2bd4cF15985a1505fc4FAA65aE2AdE45A5',
});
mergeNetworkConfig(deployConfig);
mergeRandomNumConfig({[chainId]: {
Expand Down
Loading

0 comments on commit 5a11828

Please sign in to comment.