Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/randompick-multichain #62

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/ethereum/tribes/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ToastContainer } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';

// Change your Tenant ID here.
const TENANT_ID = '0xDf61226090C2475D9ec7c494684d2715b61F130c';
const TENANT_ID = '0x62a7aa79a52591Ccc62B71729329A80a666fA50f';

function MyApp({ Component, pageProps }: AppProps) {
const hyperverse = initialize({
Expand All @@ -26,7 +26,7 @@ function MyApp({ Component, pageProps }: AppProps) {
},
{
bundle: RandomPick,
tenantId: '0x45e4c90801b1a17c178bB9855aA181A886DAA603',
tenantId: null,
},
],
});
Expand Down

Large diffs are not rendered by default.

39 changes: 24 additions & 15 deletions packages/hyperverse-ethereum-randompick/contracts.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
{
"metis": {
"testnet": {
"contractAddress": "0x5536B64dA409349E3Feb5d7e949B28716506e937"
}
},
"ethereum": {
"testnet": {
"contractAddress": "0xeed9846eD6E8525eB9866835ED67b1913a5361CF"
}
},
"avalanche": {
"testnet": {
"contractAddress": "0xC7ca00A24da99Eb8AFD3eE1511801eBAFc49C368"
}
}
"metis": {
"testnet": {
"contractAddress": "0x5536B64dA409349E3Feb5d7e949B28716506e937"
},
"mainnet": {}
},
"ethereum": {
"testnet": {
"contractAddress": "0x340554DDb594ccce941709Eb976f86ed5E241F3c"
},
"mainnet": {}
},
"avalanche": {
"testnet": {
"contractAddress": "0xC7ca00A24da99Eb8AFD3eE1511801eBAFc49C368"
},
"mainnet": {}
},
"polygon": {
"testnet": {
"contractAddress": "0x995d701c0CaAeDA88DBF21727202F3a61AF01177"
},
"mainnet": {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ contract RandomPick is VRFConsumerBase {
* Key Hash: 0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311
* Fee: 0.1 LINK
*/
constructor()
constructor(address vrfCoordinator, address linkToken, bytes32 key)
VRFConsumerBase(
0xb3dCcb4Cf7a26f6cf6B120Cf5A73875B7BBc655B, // VRF Coordinator
0x01BE23585060835E02B77ef475b0Cc51aA1e0709 // LINK Token on Rinkeby
vrfCoordinator, // VRF Coordinator
linkToken // LINK Token on Rinkeby
)
{
keyHash = 0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311;
keyHash = key;
fee = 0.1 * 10**18; // 0.1 LINK (Varies by network)
}

Expand Down
18 changes: 11 additions & 7 deletions packages/hyperverse-ethereum-randompick/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,29 @@ task('accounts', 'Prints the list of accounts', async (taskArgs, hre) => {
/**
* @type import('hardhat/config').HardhatUserConfig
*/

const accounts = process.env.NEXT_PRIVATE_KEY !== undefined ? [process.env.NEXT_PRIVATE_KEY] : [];

module.exports = {
solidity: '0.8.4',
defaultNetwork: 'hardhat',
networks: {
hardhat: {},
ethereum: {
url: `https://rinkeby.infura.io/v3/${process.env.NEXT_PUBLIC_INFURA_API_KEY}`,
accounts:
process.env.NEXT_PRIVATE_KEY !== undefined ? [process.env.NEXT_PRIVATE_KEY] : [],
accounts
},
metis: {
url: 'https://stardust.metis.io/?owner=588',
accounts:
process.env.NEXT_PRIVATE_KEY !== undefined ? [process.env.NEXT_PRIVATE_KEY] : [],
accounts
},
avalanche: {
url: 'https://api.avax-test.network/ext/bc/C/rpc',
accounts:
process.env.NEXT_PRIVATE_KEY !== undefined ? [process.env.NEXT_PRIVATE_KEY] : [],
accounts
},
},
polygon: {
url: 'https://rpc-mumbai.maticvigil.com',
accounts
}
}
};
97 changes: 48 additions & 49 deletions packages/hyperverse-ethereum-randompick/package.json
Original file line number Diff line number Diff line change
@@ -1,51 +1,50 @@
{
"name": "@decentology/hyperverse-ethereum-randompick",
"version": "1.0.11",
"source": "./source/index.ts",
"types": "./distribution/index.d.ts",
"module": "./distribution/index.es.js",
"main": "./distribution/index.js",
"license": "MIT",
"scripts": {
"test": "hardhat test",
"build": "parcel build",
"clean": "rimraf ./distribution",
"deploy": "run-p deploy-ethereum deploy-metis deploy-avalanche",
"deploy-ethereum": "hardhat run scripts/deploy.js --network ethereum ",
"deploy-metis": "hardhat run scripts/deploy.js --network metis",
"deploy-avalanche": "hardhat run scripts/deploy.js --network avalanche"
},
"publishConfig": {
"access": "public"
},
"peerDependencies": {
"react": "^17.0.2"
},
"files": [
"distribution",
"utils"
],
"dependencies": {
"@chainlink/contracts": "^0.4.0",
"@decentology/hyperverse": "^1.0.9",
"@decentology/hyperverse-ethereum": "^1.0.9",
"@decentology/hyperverse-storage-skynet": "^1.0.8",
"@decentology/unstated-next": "^1.1.1",
"ethers": "^5.5.3",
"react-query": "^3.34.7",
"react-use": "^17.3.2",
"skynet-js": "^4.0.23-beta"
},
"devDependencies": {
"@decentology/config": "^1.0.0",
"@nomiclabs/hardhat-ethers": "^2.0.4",
"@nomiclabs/hardhat-waffle": "^2.0.2",
"chai": "^4.3.4",
"dotnet": "^1.1.4",
"ethereum-waffle": "^3.4.0",
"hardhat": "^2.8.3",
"npm-run-all": "^4.1.5",
"parcel": "^2.2.1",
"rimraf": "^3.0.2"
}
"name": "@decentology/hyperverse-ethereum-randompick",
"version": "1.0.11",
"source": "./source/index.ts",
"types": "./distribution/index.d.ts",
"module": "./distribution/index.es.js",
"main": "./distribution/index.js",
"license": "MIT",
"scripts": {
"test": "hardhat test",
"build": "parcel build",
"clean": "rimraf ./distribution",
"deploy": "run-p deploy-ethereum deploy-polygon",
"deploy-ethereum": "hardhat run scripts/deploy.js --network ethereum ",
"deploy-polygon": "hardhat run scripts/deploy.js --network polygon"
},
"publishConfig": {
"access": "public"
},
"peerDependencies": {
"react": "^17.0.2"
},
"files": [
"distribution",
"utils"
],
"dependencies": {
"@chainlink/contracts": "^0.4.0",
"@decentology/hyperverse": "^1.0.9",
"@decentology/hyperverse-ethereum": "^1.0.9",
"@decentology/hyperverse-storage-skynet": "^1.0.8",
"@decentology/unstated-next": "^1.1.1",
"ethers": "^5.5.3",
"react-query": "^3.34.7",
"react-use": "^17.3.2",
"skynet-js": "^4.0.23-beta"
},
"devDependencies": {
"@decentology/config": "^1.0.0",
"@nomiclabs/hardhat-ethers": "^2.0.4",
"@nomiclabs/hardhat-waffle": "^2.0.2",
"chai": "^4.3.4",
"dotnet": "^1.1.4",
"ethereum-waffle": "^3.4.0",
"hardhat": "^2.8.3",
"npm-run-all": "^4.1.5",
"parcel": "^2.2.1",
"rimraf": "^3.0.2"
}
}
27 changes: 22 additions & 5 deletions packages/hyperverse-ethereum-randompick/scripts/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,29 @@ const hre = require('hardhat');
const fs = require('fs-extra');
require('dotenv').config();
async function main() {
let vrfCoordinator, linkToken, keyHash;
switch (hre.network.name) {
case 'ethereum':
vrfCoordinator = '0x6168499c0cFfCaCD319c818142124B7A15E857ab';
linkToken = '0x01BE23585060835E02B77ef475b0Cc51aA1e0709';
keyHash = '0xd89b2bf150e3b9e13446986e571fb9cab24b13cea0a43ea20a6049a85cc807cc';
break;
case 'polygon':
vrfCoordinator = '0x8C7382F9D8f56b33781fE506E897a4F1e2d17255';
linkToken = '0x326C977E6efc84E512bB9C30f76E30c160eD06FB';
keyHash = '0x6e75b569a01ef56d18cab6a8e71e6600d6ce853834d4a5748b720d06f878b3a4';
break;
default:
throw new Error('Unsupported network');
}

const RandomPick = await ethers.getContractFactory('RandomPick');
const randomPick = await RandomPick.deploy();
const randomPick = await RandomPick.deploy(vrfCoordinator, linkToken, keyHash);
await randomPick.deployed();


console.log(`[${hre.network.name}] RandomPick deployed to: ${randomPick.address}`);
console.log(JSON.stringify(randomPick));
console.log(
`[${hre.network.name}] RandomPick deployed to: ${randomPick.address} from transaction ${randomPick.transactionHash}`
);

const env = JSON.parse(fs.readFileSync('contracts.json').toString());
env[hre.network.name] = env[hre.network.name] || {};
Expand All @@ -27,7 +44,7 @@ async function main() {
// and properly handle errors.
main()
.then(() => process.exit(0))
.catch((error) => {
.catch(error => {
console.error(error);
process.exit(1);
});
9 changes: 2 additions & 7 deletions packages/hyperverse-ethereum-randompick/source/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@ import { HyperverseModuleInstance } from '@decentology/hyperverse';
import { RandomPick } from './useRandomPick';
const client = new QueryClient();

const Provider: FC<HyperverseModuleInstance> = ({ children, tenantId }) => {
if (tenantId == null) {
throw new Error('Tenant ID is required');
}
const Provider: FC<HyperverseModuleInstance> = ({ children }) => {
return (
<QueryClientProvider client={client}>
<RandomPick.Provider initialState={{ tenantId: tenantId }}>
{children}
</RandomPick.Provider>
<RandomPick.Provider>{children}</RandomPick.Provider>
</QueryClientProvider>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function useEnvironment() {
if (blockchain == null) {
throw new Error('Blockchain is not set');
}
if (blockchain?.name !== Blockchain.Ethereum) {
if (blockchain?.name !== Blockchain.Ethereum && blockchain?.name !== Blockchain.Polygon) {
throw new Error('Blockchain is not EVM compatible');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { useEnvironment } from './environment';

type ContractState = ethers.Contract;
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
function RandomPickState(initialState: { tenantId: string } = { tenantId: '' }) {
const { tenantId } = initialState;
function RandomPickState() {
const { address, web3Provider, provider, connect } = useEthereum();
const { ContractABI, contractAddress } = useEnvironment();
const [contract, setRandomPickContract] = useState<ContractState>(
Expand Down Expand Up @@ -75,7 +74,6 @@ function RandomPickState(initialState: { tenantId: string } = { tenantId: '' })
);

return {
tenantId,
contract,
StartRandomPick: (
options?: Omit<UseMutationOptions<unknown, unknown, void, unknown>, 'mutationFn'>
Expand Down