Adds formal verification DSL, multi-sig contract, and Hardhat plugin: synor-verifier crate: - Verification DSL for contract invariants and properties - SMT solver integration (Z3 backend optional) - Symbolic execution engine for path exploration - Automatic vulnerability detection (reentrancy, overflow, etc.) - 29 tests passing contracts/multi-sig: - M-of-N multi-signature wallet contract - Transaction proposals with timelock - Owner management (add/remove) - Emergency pause functionality - Native token and contract call support apps/hardhat-plugin (@synor/hardhat-plugin): - Network configuration for mainnet/testnet/devnet - Contract deployment with gas estimation - Contract verification on explorer - WASM compilation support - TypeScript type generation - Testing utilities (fork, impersonate, time manipulation) - Synor-specific RPC methods (quantum status, shard info, DAG)
187 lines
4.7 KiB
Markdown
187 lines
4.7 KiB
Markdown
# @synor/hardhat-plugin
|
|
|
|
Hardhat plugin for Synor blockchain development. Provides seamless integration between Hardhat and Synor network.
|
|
|
|
## Features
|
|
|
|
- 🔗 **Network Configuration**: Pre-configured Synor mainnet, testnet, and devnet
|
|
- 📦 **Smart Deployment**: Deploy contracts with gas estimation and verification
|
|
- 🔐 **Quantum-Safe**: Support for post-quantum cryptographic signatures
|
|
- 🧪 **Testing Utilities**: Fork network, time manipulation, account impersonation
|
|
- 📊 **DAG Integration**: Access GHOSTDAG/DAGKnight consensus data
|
|
- 🌐 **Cross-Shard**: Support for sharded architecture
|
|
|
|
## Installation
|
|
|
|
```bash
|
|
npm install @synor/hardhat-plugin
|
|
# or
|
|
yarn add @synor/hardhat-plugin
|
|
# or
|
|
pnpm add @synor/hardhat-plugin
|
|
```
|
|
|
|
## Setup
|
|
|
|
Add the plugin to your `hardhat.config.ts`:
|
|
|
|
```typescript
|
|
import "@synor/hardhat-plugin";
|
|
|
|
const config: HardhatUserConfig = {
|
|
solidity: "0.8.20",
|
|
synor: {
|
|
defaultNetwork: "testnet",
|
|
verifyContracts: true,
|
|
quantumSafe: true,
|
|
},
|
|
networks: {
|
|
"synor-mainnet": {
|
|
url: "https://rpc.synor.cc",
|
|
chainId: 1337,
|
|
accounts: [process.env.PRIVATE_KEY!],
|
|
},
|
|
"synor-testnet": {
|
|
url: "https://testnet-rpc.synor.cc",
|
|
chainId: 1338,
|
|
accounts: [process.env.PRIVATE_KEY!],
|
|
},
|
|
},
|
|
};
|
|
|
|
export default config;
|
|
```
|
|
|
|
## Usage
|
|
|
|
### Deploy a Contract
|
|
|
|
```bash
|
|
npx hardhat synor:deploy --contract MyContract --network synor-testnet
|
|
```
|
|
|
|
Or programmatically:
|
|
|
|
```typescript
|
|
import { ethers } from "hardhat";
|
|
|
|
async function main() {
|
|
const contract = await hre.synor.deployer.deploy("MyContract", [arg1, arg2]);
|
|
console.log("Deployed to:", contract.address);
|
|
}
|
|
```
|
|
|
|
### Verify a Contract
|
|
|
|
```bash
|
|
npx hardhat synor:verify --address 0x... --contract MyContract --network synor-testnet
|
|
```
|
|
|
|
### Get Network Info
|
|
|
|
```bash
|
|
npx hardhat synor:info --network synor-testnet
|
|
```
|
|
|
|
### Request Testnet Tokens
|
|
|
|
```bash
|
|
npx hardhat synor:faucet --address 0x... --network synor-testnet
|
|
```
|
|
|
|
### Compile to WASM
|
|
|
|
```bash
|
|
npx hardhat synor:compile
|
|
```
|
|
|
|
## API Reference
|
|
|
|
### `hre.synor.provider`
|
|
|
|
Synor-specific JSON-RPC provider with methods:
|
|
|
|
- `getBalance(address)` - Get account balance
|
|
- `getBlockNumber()` - Get current block number
|
|
- `getTransaction(hash)` - Get transaction by hash
|
|
- `sendTransaction(tx)` - Send a transaction
|
|
- `call(tx)` - Call a contract (read-only)
|
|
- `estimateGas(tx)` - Estimate gas for transaction
|
|
- `getQuantumStatus()` - Get quantum signature status
|
|
- `getShardInfo()` - Get shard information
|
|
- `getDagBlock(hash)` - Get DAG block information
|
|
|
|
### `hre.synor.deployer`
|
|
|
|
Contract deployment utilities:
|
|
|
|
- `deploy(name, args, options)` - Deploy a contract
|
|
- `deployDeterministic(name, args, salt)` - CREATE2 deployment
|
|
- `compileToWasm()` - Compile contracts to WASM
|
|
- `generateTypes()` - Generate TypeScript types
|
|
|
|
### `hre.synor.network`
|
|
|
|
Network utilities:
|
|
|
|
- `getNetworkInfo()` - Get network information
|
|
- `verifyContract(address, args)` - Verify on explorer
|
|
- `requestFaucet(address, amount)` - Request testnet tokens
|
|
- `fork(blockNumber)` - Fork network at block
|
|
- `impersonate(address)` - Impersonate account
|
|
- `setBalance(address, balance)` - Set account balance
|
|
- `increaseTime(seconds)` - Advance blockchain time
|
|
- `snapshot()` - Take state snapshot
|
|
- `revert(snapshotId)` - Revert to snapshot
|
|
|
|
## Configuration Options
|
|
|
|
| Option | Type | Default | Description |
|
|
|--------|------|---------|-------------|
|
|
| `defaultNetwork` | `string` | `"devnet"` | Default Synor network |
|
|
| `gasPrice` | `"auto" \| number` | `"auto"` | Gas price setting |
|
|
| `gasLimit` | `number` | `3000000` | Default gas limit |
|
|
| `confirmations` | `number` | `1` | Confirmations to wait |
|
|
| `timeout` | `number` | `60000` | Transaction timeout (ms) |
|
|
| `verifyContracts` | `boolean` | `true` | Auto-verify on deploy |
|
|
| `quantumSafe` | `boolean` | `true` | Use quantum signatures |
|
|
|
|
## Testing
|
|
|
|
The plugin provides testing utilities for Synor-specific features:
|
|
|
|
```typescript
|
|
import { expect } from "chai";
|
|
import { ethers } from "hardhat";
|
|
|
|
describe("MyContract", function () {
|
|
beforeEach(async function () {
|
|
// Fork testnet
|
|
await hre.synor.network.fork("latest");
|
|
});
|
|
|
|
it("should deploy and interact", async function () {
|
|
const contract = await hre.synor.deployer.deploy("MyContract", []);
|
|
|
|
// Test cross-shard messaging
|
|
const messages = await hre.synor.provider.getPendingCrossShardMessages(
|
|
contract.address
|
|
);
|
|
expect(messages).to.be.empty;
|
|
});
|
|
|
|
it("should handle time-based logic", async function () {
|
|
const contract = await hre.synor.deployer.deploy("TimeLock", []);
|
|
|
|
// Advance time by 1 day
|
|
await hre.synor.network.increaseTime(86400);
|
|
|
|
// Now timelock should be expired
|
|
expect(await contract.isExpired()).to.be.true;
|
|
});
|
|
});
|
|
```
|
|
|
|
## License
|
|
|
|
MIT
|