-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from orochi-network/misc/integrate_testnet_chain
Misc: Add more testnet chain info & modify deploy Orochi script
- Loading branch information
Showing
27 changed files
with
4,579 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
import '@openzeppelin/contracts/access/Ownable.sol'; | ||
import '@orochi-network/contracts/IOrandConsumerV3.sol'; | ||
import '@orochi-network/contracts/IOrocleAggregatorV2.sol'; | ||
|
||
error WrongGuessingValue(uint128 guessing); | ||
|
||
// Application should be an implement of IOrandConsumerV2 interface | ||
contract DiceGameV3 is IOrandConsumerV3, Ownable { | ||
// Set new provider | ||
event SetProvider(address indexed oldProvider, address indexed newProvider); | ||
|
||
// Set new oracle | ||
event SetOracle(address indexed oldProvider, address indexed newProvider); | ||
|
||
// Fulfill awaiting result | ||
event Fulfilled(uint256 indexed gameId, uint256 guessed, uint256 indexed result); | ||
|
||
// New guess from player | ||
event NewGuess(address indexed player, uint256 indexed gameId, uint128 indexed guessed); | ||
|
||
// Game structure | ||
struct Game { | ||
uint128 guessed; | ||
uint128 result; | ||
} | ||
|
||
// Provider address | ||
address private orandProvider; | ||
|
||
// Orochi Network oracle | ||
address private oracle; | ||
|
||
// Game result storage | ||
mapping(uint256 => Game) private gameResult; | ||
|
||
// Total game | ||
uint256 private totalGame; | ||
|
||
// Fulfiled randomness | ||
uint256 private fulfilled; | ||
|
||
// We batching the radomness in one epoch | ||
uint256 private maximumBatching; | ||
|
||
// Only allow Orand to submit result | ||
modifier onlyOrandProvider() { | ||
if (msg.sender != orandProvider) { | ||
revert InvalidProvider(); | ||
} | ||
_; | ||
} | ||
|
||
// Constructor | ||
constructor(address provider, address oracleAddress) { | ||
_setProvider(provider); | ||
_setOracle(oracleAddress); | ||
} | ||
|
||
//=======================[ Internal ]==================== | ||
|
||
// Set provider | ||
function _setOracle(address oracleAddress) internal { | ||
emit SetOracle(oracle, oracleAddress); | ||
oracle = oracleAddress; | ||
} | ||
|
||
// Set provider | ||
function _getOracle() internal view returns (address) { | ||
return oracle; | ||
} | ||
|
||
// Set provider | ||
function _setProvider(address provider) internal { | ||
emit SetProvider(orandProvider, provider); | ||
orandProvider = provider; | ||
} | ||
|
||
// Set provider | ||
function _getProvider() internal view returns (address) { | ||
return orandProvider; | ||
} | ||
|
||
//=======================[ Owner ]==================== | ||
|
||
// Set provider | ||
function setProvider(address provider) external onlyOwner returns (bool) { | ||
_setProvider(provider); | ||
return true; | ||
} | ||
|
||
// Set oracle | ||
function setOracle(address oracleAddress) external onlyOwner returns (bool) { | ||
_setOracle(oracleAddress); | ||
return true; | ||
} | ||
|
||
//=======================[ OrandProviderV2 ]==================== | ||
|
||
// Consume the result of Orand V2 with batching feature | ||
function consumeRandomness(uint256 randomness) external override onlyOrandProvider returns (bool) { | ||
// We keep batching < maximumBatching | ||
if (fulfilled < totalGame) { | ||
Game memory currentGame = gameResult[fulfilled]; | ||
currentGame.result = uint128((randomness % 6) + 1); | ||
gameResult[fulfilled] = currentGame; | ||
emit Fulfilled(fulfilled, currentGame.guessed, currentGame.result); | ||
fulfilled += 1; | ||
return true; | ||
} | ||
// We will let the provider know that all are fulfilled | ||
return false; | ||
} | ||
|
||
//=======================[ External ]==================== | ||
|
||
// Player can guessing any number in range of 1-6 | ||
function guessingDiceNumber(uint128 guessing) external returns (bool) { | ||
// Player only able to guessing between 1-6 since it's dice number | ||
if (guessing < 1 || guessing > 6) { | ||
revert WrongGuessingValue(guessing); | ||
} | ||
gameResult[totalGame] = Game({ guessed: guessing, result: 0 }); | ||
|
||
// Request randomness from Orand | ||
IOrocleAggregatorV2(oracle).request(0, '0x'); | ||
|
||
emit NewGuess(msg.sender, totalGame, guessing); | ||
totalGame += 1; | ||
return true; | ||
} | ||
|
||
//=======================[ External View ]==================== | ||
|
||
// Get provider | ||
function getProvider() external view returns (address) { | ||
return _getProvider(); | ||
} | ||
|
||
// Get oracle | ||
function getOracle() external view returns (address) { | ||
return _getOracle(); | ||
} | ||
|
||
// Get result from smart contract | ||
function getResult(uint256 gameId) external view returns (Game memory result) { | ||
return gameResult[gameId]; | ||
} | ||
|
||
function getStateOfGame() external view returns (uint256 fulfill, uint256 total) { | ||
return (fulfilled, totalGame); | ||
} | ||
|
||
function isFulfilled() external view returns (bool) { | ||
if (fulfilled < totalGame) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity 0.8.19; | ||
|
||
import '@openzeppelin/contracts/token/ERC721/ERC721.sol'; | ||
import '@openzeppelin/contracts/utils/Counters.sol'; | ||
import '@openzeppelin/contracts/access/Ownable.sol'; | ||
|
||
// An ambition is hiding in the bush | ||
contract TestERC721 is ERC721, Ownable { | ||
using Counters for Counters.Counter; | ||
Counters.Counter private _tokenIds; | ||
|
||
constructor() ERC721('TestBigO', 'TestO') {} | ||
|
||
function mintNFT(address recipient) public returns (uint256) onlyOwner { | ||
_tokenIds.increment(); | ||
uint256 newTokenId = _tokenIds.current(); | ||
_mint(recipient, newTokenId); | ||
return newTokenId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
error InvalidProvider(); | ||
|
||
/** | ||
* @dev IOrandConsumerV3 must be implemented for all service that use Orand | ||
*/ | ||
interface IOrandConsumerV3 { | ||
/** | ||
* Consume the verifiable randomness from Orand provider | ||
* @param randomness Randomness value | ||
* @return return false if you want to stop batching otherwise return true | ||
*/ | ||
function consumeRandomness(uint256 randomness) external returns (bool); | ||
/** | ||
* Check the fulfill status of randomness batching | ||
* @return true if all requests are fulfilled otherwise return false | ||
*/ | ||
function isFulfilled() external returns (bool); | ||
} |
Oops, something went wrong.