Skip to content

Commit 8c41779

Browse files
authored
add small fix to support dms (#571)
* 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
1 parent c0fd30b commit 8c41779

21 files changed

+811
-312
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,11 @@ JSON document must be signed by its owner. Only the owner can update or delete t
109109
|----------|:-------------:|:------:|
110110
| Arweave | :heavy_check_mark: | :heavy_check_mark:|
111111
| Polygon | :heavy_check_mark: [Mumbai](https://mumbai.polygonscan.com/address/0xb9709cE5E749b80978182db1bEdfb8c7340039A9) | :soon: |
112-
| Zksync | :soon: | :soon: |
113-
| Scroll | :soon: | :soon: |
112+
| Zksync | :heavy_check_mark:[testnet](https://goerli.explorer.zksync.io/address/0xB4Ec19674A67dB002fFDeB83e14f9849DA3D1020) | :soon: |
113+
| Scroll | :heavy_check_mark: [alpha](https://scroll.l2scan.co/address/0x91B4BB6c2e6F70F93D89B04c049bFB2D36839d9A) | :soon: |
114114
| Arbitrum | :soon: | :soon: |
115115
| Optimism | :soon: | :soon: |
116+
| Linea| :heavy_check_mark: [testnet](https://goerli.lineascan.build/address/0xfFe5128735D2EFC1bFDF2eD18A99D1eD8d096D94) | :soon: |
116117

117118
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=)
118119

metadata/contracts/DB3MetaStore.sol

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ contract DB3MetaStore is IDB3MetaStore {
5353
string[] memory indexNodeUrls,
5454
address[] memory indexNodeAddresses
5555
) public {
56+
require(networkId != 0, "invalid data network");
5657
// Check the network must be registered
5758
require(networkId <= _networkCounter, "Network is not registered");
5859
Types.DataNetwork storage dataNetwork = _dataNetworks[networkId];
@@ -71,6 +72,7 @@ contract DB3MetaStore is IDB3MetaStore {
7172
function getDataNetwork(
7273
uint256 networkId
7374
) external view returns (Types.DataNetwork memory dataNetwork) {
75+
require(networkId != 0, "invalid data network");
7476
// Check the data network must be registered
7577
require(networkId <= _networkCounter, "Data Network is not registered");
7678
// Get data network struct
@@ -84,6 +86,7 @@ contract DB3MetaStore is IDB3MetaStore {
8486
string memory rollupNodeUrl,
8587
address rollupNodeAddress
8688
) public {
89+
require(networkId != 0, "invalid data network");
8790
// Check the data network must be registered
8891
require(networkId <= _networkCounter, "Data Network is not registered");
8992
// Check if network is registered
@@ -107,6 +110,7 @@ contract DB3MetaStore is IDB3MetaStore {
107110
uint256 networkId,
108111
bytes32 latestArweaveTx
109112
) public {
113+
require(networkId != 0, "invalid data network");
110114
// Check if network is registered
111115
require(networkId <= _networkCounter, "Data Network is not registered");
112116
// Check the latestarweavetx
@@ -127,6 +131,7 @@ contract DB3MetaStore is IDB3MetaStore {
127131

128132
function createDocDatabase(uint256 networkId, bytes32 description) public {
129133
// Check if network is registered
134+
require(networkId != 0, "invalid data network");
130135
require(networkId <= _networkCounter, "Data Network is not registered");
131136
// Everyone can create a database currently
132137
_databaseCounter++;
@@ -159,6 +164,7 @@ contract DB3MetaStore is IDB3MetaStore {
159164
bytes32 licenseName,
160165
bytes32 licenseContent
161166
) public {
167+
require(networkId != 0, "invalid data network");
162168
// Check if network is registered
163169
require(networkId <= _networkCounter, "Data Network is not registered");
164170
require(name != bytes32(0), "name is empty");
@@ -200,6 +206,7 @@ contract DB3MetaStore is IDB3MetaStore {
200206
}
201207

202208
function transferNetwork(uint256 networkId, address to) public {
209+
require(networkId != 0, "invalid data network");
203210
// Check if network is registered
204211
require(networkId <= _networkCounter, "Data Network is not registered");
205212
require(
@@ -221,6 +228,7 @@ contract DB3MetaStore is IDB3MetaStore {
221228
address db,
222229
address to
223230
) public {
231+
require(networkId != 0, "invalid data network");
224232
// Check if network is registered
225233
require(networkId <= _networkCounter, "Data Network is not registered");
226234
Types.Database storage database = _databases[networkId][db];
@@ -245,6 +253,7 @@ contract DB3MetaStore is IDB3MetaStore {
245253
}
246254

247255
function forkNetwork(uint256 networkId) public {
256+
require(networkId != 0, "invalid data network");
248257
// Check if network is registered
249258
require(networkId <= _networkCounter, "Data Network is not registered");
250259
Types.DataNetwork storage dataNetwork = _dataNetworks[_networkCounter];
File renamed without changes.

metadata/deploy/deploy_metadata.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
//
2+
// deploy_metadata.ts
3+
// Copyright (C) 2023 db3.network Author imotai <[email protected]>
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
//
17+
18+
import { Wallet, utils } from "zksync-web3";
19+
import * as ethers from "ethers";
20+
import { HardhatRuntimeEnvironment } from "hardhat/types";
21+
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
22+
23+
// load env file
24+
//import dotenv from "dotenv";
25+
//dotenv.config();
26+
27+
// load wallet private key from env file
28+
const PRIVATE_KEY = process.env.PRIVATE_KEY || "";
29+
30+
if (!PRIVATE_KEY)
31+
throw "⛔️ Private key not detected! Add it to the .env file!";
32+
33+
// An example of a deploy script that will deploy and call a simple contract.
34+
export default async function (hre: HardhatRuntimeEnvironment) {
35+
console.log(`Running deploy script for the MetaStore contract`);
36+
37+
// Initialize the wallet.
38+
const wallet = new Wallet(PRIVATE_KEY);
39+
40+
// Create deployer object and load the artifact of the contract you want to deploy.
41+
const deployer = new Deployer(hre, wallet);
42+
const artifact = await deployer.loadArtifact("DB3MetaStore");
43+
44+
// Estimate contract deployment fee
45+
const greeting = "Hi there!";
46+
const deploymentFee = await deployer.estimateDeployFee(artifact, []);
47+
48+
// ⚠️ OPTIONAL: You can skip this block if your account already has funds in L2
49+
// Deposit funds to L2
50+
// const depositHandle = await deployer.zkWallet.deposit({
51+
// to: deployer.zkWallet.address,
52+
// token: utils.ETH_ADDRESS,
53+
// amount: deploymentFee.mul(2),
54+
// });
55+
// // Wait until the deposit is processed on zkSync
56+
// await depositHandle.wait();
57+
58+
// Deploy this contract. The returned object will be of a `Contract` type, similarly to ones in `ethers`.
59+
// `greeting` is an argument for contract constructor.
60+
const parsedFee = ethers.utils.formatEther(deploymentFee.toString());
61+
console.log(`The deployment is estimated to cost ${parsedFee} ETH`);
62+
const greeterContract = await deployer.deploy(artifact, []);
63+
// Show the contract info.
64+
const contractAddress = greeterContract.address;
65+
console.log(`${artifact.contractName} was deployed to ${contractAddress}`);
66+
// verify contract for tesnet & mainnet
67+
if (process.env.NODE_ENV != "test") {
68+
// Contract MUST be fully qualified name (e.g. path/sourceName:contractName)
69+
const contractFullyQualifedName = "contracts/Greeter.sol:Greeter";
70+
71+
// Verify contract programmatically
72+
const verificationId = await hre.run("verify:verify", {
73+
address: contractAddress,
74+
contract: contractFullyQualifedName,
75+
constructorArguments: [greeting],
76+
bytecode: artifact.bytecode,
77+
});
78+
} else {
79+
console.log(`Contract not verified, deployed locally.`);
80+
}
81+
}

metadata/deploy_to_local.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
# deploy_to_scoll.sh
44

55
export PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
6-
npx hardhat run --network localhost scripts/deploy.ts
6+
npx hardhat run --network localhost deploy/deploy.ts

metadata/hardhat.config.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,44 @@
11
import { HardhatUserConfig } from "hardhat/config";
22
import "@nomicfoundation/hardhat-toolbox";
3+
//import "@matterlabs/hardhat-zksync-deploy";
4+
//import "@matterlabs/hardhat-zksync-solc";
35

46
const config: HardhatUserConfig = {
57
solidity: "0.8.17",
8+
zksolc: {
9+
version: "latest",
10+
settings: {},
11+
},
12+
//defaultNetwork: "localhost",
613
networks: {
14+
lineaTest: {
15+
url: "https://linea-goerli.infura.io/v3/1ff2ead2c89442d290c2b99ec01cbab8" || "",
16+
accounts:
17+
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
18+
zksync: false,
19+
},
20+
zkSyncTest: {
21+
url:"https://zksync2-testnet.zksync.dev" || "",
22+
accounts: process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
23+
ethNetwork: "goerli",
24+
zksync: true
25+
26+
},
727
mumbai: {
828
url: "https://polygon-mumbai.infura.io/v3/4458cf4d1689497b9a38b1d6bbf05e78" || "",
29+
zksync: false,
930
accounts:
1031
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
1132
},
1233
scrollalpha: {
1334
url: "https://alpha-rpc.scroll.io/l2" || "",
35+
zksync: false,
1436
accounts:
1537
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
1638
},
17-
1839
localhost: {
1940
url: "http://127.0.0.1:8545" || "",
41+
zksync: false,
2042
accounts:
2143
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
2244
},

metadata/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{
2-
"name": "bridge",
2+
"name": "metadata",
33
"version": "1.0.0",
44
"main": "index.js",
55
"license": "MIT",
66
"devDependencies": {
77
"@ethersproject/abi": "^5.4.7",
88
"@ethersproject/providers": "^5.4.7",
9+
"@matterlabs/hardhat-zksync-deploy": "^0.6.3",
10+
"@matterlabs/hardhat-zksync-solc": "^0.4.1",
911
"@nomicfoundation/hardhat-chai-matchers": "^1.0.0",
1012
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
1113
"@nomicfoundation/hardhat-toolbox": "^2.0.0",
@@ -17,6 +19,7 @@
1719
"@types/mocha": ">=9.1.0",
1820
"@types/node": ">=12.0.0",
1921
"chai": "^4.2.0",
22+
"dotenv": "^16.3.1",
2023
"ethers": "^5.4.7",
2124
"hardhat": "^2.17.0",
2225
"hardhat-abi-exporter": "^2.10.1",
@@ -26,7 +29,8 @@
2629
"solidity-coverage": "^0.8.0",
2730
"ts-node": ">=8.0.0",
2831
"typechain": "^8.1.0",
29-
"typescript": "^4.9.5"
32+
"typescript": "^4.9.5",
33+
"zksync-web3": "^0.14.3"
3034
},
3135
"dependencies": {
3236
"@openzeppelin/contracts": "^4.8.1",

0 commit comments

Comments
 (0)