Skip to content

Commit

Permalink
add small fix to support dms (#571)
Browse files Browse the repository at this point in the history
* feat: add doc store

* fix: add some fix to support dms

* fix: fix compile error

* fix: revert eve sercet

* fix: add log to send mutation

* feat: update version

* fix: fix the code style

* fix: add zksync contract
  • Loading branch information
imotai authored Jul 24, 2023
1 parent c0fd30b commit 8c41779
Show file tree
Hide file tree
Showing 21 changed files with 811 additions and 312 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ JSON document must be signed by its owner. Only the owner can update or delete t
|----------|:-------------:|:------:|
| Arweave | :heavy_check_mark: | :heavy_check_mark:|
| Polygon | :heavy_check_mark: [Mumbai](https://mumbai.polygonscan.com/address/0xb9709cE5E749b80978182db1bEdfb8c7340039A9) | :soon: |
| Zksync | :soon: | :soon: |
| Scroll | :soon: | :soon: |
| Zksync | :heavy_check_mark:[testnet](https://goerli.explorer.zksync.io/address/0xB4Ec19674A67dB002fFDeB83e14f9849DA3D1020) | :soon: |
| Scroll | :heavy_check_mark: [alpha](https://scroll.l2scan.co/address/0x91B4BB6c2e6F70F93D89B04c049bFB2D36839d9A) | :soon: |
| Arbitrum | :soon: | :soon: |
| Optimism | :soon: | :soon: |
| Linea| :heavy_check_mark: [testnet](https://goerli.lineascan.build/address/0xfFe5128735D2EFC1bFDF2eD18A99D1eD8d096D94) | :soon: |

If you want us to support the other public chains, just give us an [issue](https://github.com/dbpunk-labs/db3/issues/new?assignees=&labels=enhancement&projects=&template=feature_request.md&title=)

Expand Down
9 changes: 9 additions & 0 deletions metadata/contracts/DB3MetaStore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ contract DB3MetaStore is IDB3MetaStore {
string[] memory indexNodeUrls,
address[] memory indexNodeAddresses
) public {
require(networkId != 0, "invalid data network");
// Check the network must be registered
require(networkId <= _networkCounter, "Network is not registered");
Types.DataNetwork storage dataNetwork = _dataNetworks[networkId];
Expand All @@ -71,6 +72,7 @@ contract DB3MetaStore is IDB3MetaStore {
function getDataNetwork(
uint256 networkId
) external view returns (Types.DataNetwork memory dataNetwork) {
require(networkId != 0, "invalid data network");
// Check the data network must be registered
require(networkId <= _networkCounter, "Data Network is not registered");
// Get data network struct
Expand All @@ -84,6 +86,7 @@ contract DB3MetaStore is IDB3MetaStore {
string memory rollupNodeUrl,
address rollupNodeAddress
) public {
require(networkId != 0, "invalid data network");
// Check the data network must be registered
require(networkId <= _networkCounter, "Data Network is not registered");
// Check if network is registered
Expand All @@ -107,6 +110,7 @@ contract DB3MetaStore is IDB3MetaStore {
uint256 networkId,
bytes32 latestArweaveTx
) public {
require(networkId != 0, "invalid data network");
// Check if network is registered
require(networkId <= _networkCounter, "Data Network is not registered");
// Check the latestarweavetx
Expand All @@ -127,6 +131,7 @@ contract DB3MetaStore is IDB3MetaStore {

function createDocDatabase(uint256 networkId, bytes32 description) public {
// Check if network is registered
require(networkId != 0, "invalid data network");
require(networkId <= _networkCounter, "Data Network is not registered");
// Everyone can create a database currently
_databaseCounter++;
Expand Down Expand Up @@ -159,6 +164,7 @@ contract DB3MetaStore is IDB3MetaStore {
bytes32 licenseName,
bytes32 licenseContent
) public {
require(networkId != 0, "invalid data network");
// Check if network is registered
require(networkId <= _networkCounter, "Data Network is not registered");
require(name != bytes32(0), "name is empty");
Expand Down Expand Up @@ -200,6 +206,7 @@ contract DB3MetaStore is IDB3MetaStore {
}

function transferNetwork(uint256 networkId, address to) public {
require(networkId != 0, "invalid data network");
// Check if network is registered
require(networkId <= _networkCounter, "Data Network is not registered");
require(
Expand All @@ -221,6 +228,7 @@ contract DB3MetaStore is IDB3MetaStore {
address db,
address to
) public {
require(networkId != 0, "invalid data network");
// Check if network is registered
require(networkId <= _networkCounter, "Data Network is not registered");
Types.Database storage database = _databases[networkId][db];
Expand All @@ -245,6 +253,7 @@ contract DB3MetaStore is IDB3MetaStore {
}

function forkNetwork(uint256 networkId) public {
require(networkId != 0, "invalid data network");
// Check if network is registered
require(networkId <= _networkCounter, "Data Network is not registered");
Types.DataNetwork storage dataNetwork = _dataNetworks[_networkCounter];
Expand Down
File renamed without changes.
81 changes: 81 additions & 0 deletions metadata/deploy/deploy_metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//
// deploy_metadata.ts
// Copyright (C) 2023 db3.network Author imotai <[email protected]>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import { Wallet, utils } from "zksync-web3";
import * as ethers from "ethers";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";

// load env file
//import dotenv from "dotenv";
//dotenv.config();

// load wallet private key from env file
const PRIVATE_KEY = process.env.PRIVATE_KEY || "";

if (!PRIVATE_KEY)
throw "⛔️ Private key not detected! Add it to the .env file!";

// An example of a deploy script that will deploy and call a simple contract.
export default async function (hre: HardhatRuntimeEnvironment) {
console.log(`Running deploy script for the MetaStore contract`);

// Initialize the wallet.
const wallet = new Wallet(PRIVATE_KEY);

// Create deployer object and load the artifact of the contract you want to deploy.
const deployer = new Deployer(hre, wallet);
const artifact = await deployer.loadArtifact("DB3MetaStore");

// Estimate contract deployment fee
const greeting = "Hi there!";
const deploymentFee = await deployer.estimateDeployFee(artifact, []);

// ⚠️ OPTIONAL: You can skip this block if your account already has funds in L2
// Deposit funds to L2
// const depositHandle = await deployer.zkWallet.deposit({
// to: deployer.zkWallet.address,
// token: utils.ETH_ADDRESS,
// amount: deploymentFee.mul(2),
// });
// // Wait until the deposit is processed on zkSync
// await depositHandle.wait();

// Deploy this contract. The returned object will be of a `Contract` type, similarly to ones in `ethers`.
// `greeting` is an argument for contract constructor.
const parsedFee = ethers.utils.formatEther(deploymentFee.toString());
console.log(`The deployment is estimated to cost ${parsedFee} ETH`);
const greeterContract = await deployer.deploy(artifact, []);
// Show the contract info.
const contractAddress = greeterContract.address;
console.log(`${artifact.contractName} was deployed to ${contractAddress}`);
// verify contract for tesnet & mainnet
if (process.env.NODE_ENV != "test") {
// Contract MUST be fully qualified name (e.g. path/sourceName:contractName)
const contractFullyQualifedName = "contracts/Greeter.sol:Greeter";

// Verify contract programmatically
const verificationId = await hre.run("verify:verify", {
address: contractAddress,
contract: contractFullyQualifedName,
constructorArguments: [greeting],
bytecode: artifact.bytecode,
});
} else {
console.log(`Contract not verified, deployed locally.`);
}
}
2 changes: 1 addition & 1 deletion metadata/deploy_to_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# deploy_to_scoll.sh

export PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
npx hardhat run --network localhost scripts/deploy.ts
npx hardhat run --network localhost deploy/deploy.ts
24 changes: 23 additions & 1 deletion metadata/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,44 @@
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
//import "@matterlabs/hardhat-zksync-deploy";
//import "@matterlabs/hardhat-zksync-solc";

const config: HardhatUserConfig = {
solidity: "0.8.17",
zksolc: {
version: "latest",
settings: {},
},
//defaultNetwork: "localhost",
networks: {
lineaTest: {
url: "https://linea-goerli.infura.io/v3/1ff2ead2c89442d290c2b99ec01cbab8" || "",
accounts:
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
zksync: false,
},
zkSyncTest: {
url:"https://zksync2-testnet.zksync.dev" || "",
accounts: process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
ethNetwork: "goerli",
zksync: true

},
mumbai: {
url: "https://polygon-mumbai.infura.io/v3/4458cf4d1689497b9a38b1d6bbf05e78" || "",
zksync: false,
accounts:
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
},
scrollalpha: {
url: "https://alpha-rpc.scroll.io/l2" || "",
zksync: false,
accounts:
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
},

localhost: {
url: "http://127.0.0.1:8545" || "",
zksync: false,
accounts:
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
},
Expand Down
8 changes: 6 additions & 2 deletions metadata/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"name": "bridge",
"name": "metadata",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"devDependencies": {
"@ethersproject/abi": "^5.4.7",
"@ethersproject/providers": "^5.4.7",
"@matterlabs/hardhat-zksync-deploy": "^0.6.3",
"@matterlabs/hardhat-zksync-solc": "^0.4.1",
"@nomicfoundation/hardhat-chai-matchers": "^1.0.0",
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
"@nomicfoundation/hardhat-toolbox": "^2.0.0",
Expand All @@ -17,6 +19,7 @@
"@types/mocha": ">=9.1.0",
"@types/node": ">=12.0.0",
"chai": "^4.2.0",
"dotenv": "^16.3.1",
"ethers": "^5.4.7",
"hardhat": "^2.17.0",
"hardhat-abi-exporter": "^2.10.1",
Expand All @@ -26,7 +29,8 @@
"solidity-coverage": "^0.8.0",
"ts-node": ">=8.0.0",
"typechain": "^8.1.0",
"typescript": "^4.9.5"
"typescript": "^4.9.5",
"zksync-web3": "^0.14.3"
},
"dependencies": {
"@openzeppelin/contracts": "^4.8.1",
Expand Down
Loading

0 comments on commit 8c41779

Please sign in to comment.