npm package: @mayflower-fi/evm-bytecode
Description: Compiled bytecode and deployment helpers for May Prog EVM contracts
Author: Mayflower Protocol
Latest version: 0.0.5

# @mayflower-fi/evm-bytecode

Compiled bytecode and deployment helpers for May Prog EVM contracts.

## Installation

```bash
npm install @mayflower-fi/evm-bytecode
# or
yarn add @mayflower-fi/evm-bytecode
# or
pnpm add @mayflower-fi/evm-bytecode
```

## Usage

### Basic Contract Deployment

```typescript
import { ethers } from 'ethers';
import { ContractDeployer, contracts } from '@mayflower-fi/evm-bytecode';

// Connect to network
const provider = new ethers.JsonRpcProvider('http://localhost:8545');
const signer = await provider.getSigner();

// Create deployer
const deployer = new ContractDeployer(signer);

// Deploy TenantFactory
const tenantFactory = await deployer.deploy(contracts.TenantFactory);
console.log('TenantFactory deployed at:', await tenantFactory.getAddress());
```

### Protocol Deployment Helpers

```typescript
import { deployProtocol, deployTenant, deployMarketGroup, deployMarket } from '@mayflower-fi/evm-bytecode';

// Deploy complete protocol
const protocol = await deployProtocol({ signer });

// Deploy a tenant
const tenant = await deployTenant({
  signer,
  tenantFactory: protocol.tenantFactory,
  name: 'My Tenant',
  symbol: 'MTNT',
  platformFeeRate: 100000n, // 10% in micro-basis points
});

// Deploy a market group
const marketGroup = await deployMarketGroup({
  signer,
  tenant: tenant.tenant,
  marketGroupFactory: protocol.marketGroupFactory,
  name: 'My Markets',
  buyFeeRate: 2500n,  // 0.25%
  sellFeeRate: 2500n, // 0.25%
});
```

### Verify Deployed Contracts

```typescript
import { verifyBytecode, getContractStats, contracts } from '@mayflower-fi/evm-bytecode';

// Get on-chain bytecode
const onchainBytecode = await provider.getCode(contractAddress);

// Verify it matches expected bytecode
const matches = verifyBytecode(
  onchainBytecode,
  contracts.TenantFactory.deployedBytecode,
  true // Allow metadata changes
);

// Get contract statistics
const stats = getContractStats(contracts.TenantFactory);
console.log('Contract size:', stats.bytecodeSize, 'bytes');
console.log('Functions:', stats.functionCount);
console.log('Events:', stats.eventCount);
```

### Working with Bytecode

```typescript
import { 
  getBytecodeSize,
  isWithinSizeLimit,
  getInitCodeHash,
  encodeConstructorArgs 
} from '@mayflower-fi/evm-bytecode';

// Check bytecode size
const size = getBytecodeSize(contracts.MarketFactory.bytecode);
const withinLimit = isWithinSizeLimit(contracts.MarketFactory.deployedBytecode);

// Encode constructor arguments
const args = encodeConstructorArgs(
  ['string', 'string', 'address', 'uint256'],
  ['My Token', 'MTK', '0x...', 1000000n]
);

// Get init code hash for CREATE2
const initHash = getInitCodeHash(contracts.MarketFactory.bytecode, args);
```

## Available Contracts

- `TenantFactory` - Factory for deploying tenant contracts
- `TenantImplementation` - Implementation contract for tenants
- `MarketGroupFactory` - Factory for deploying market groups
- `MarketGroupImplementation` - Implementation contract for market groups
- `MarketFactory` - Factory for deploying markets
- `LinearMarketImplementation` - Implementation contract for linear bonding curve markets
- `MarketToken` - ERC20 token for market derivatives
- `CallOptionToken` - ERC20 token for call options
- `MockERC20` - Mock ERC20 token for testing (if available)

## Helper Functions

### Deployment
- `deployProtocol()` - Deploy complete protocol infrastructure
- `deployTenant()` - Deploy a new tenant
- `deployMarketGroup()` - Deploy a new market group
- `deployMarket()` - Deploy a new market

### Bytecode Utilities
- `getBytecodeSize()` - Get bytecode size in bytes
- `isWithinSizeLimit()` - Check if bytecode is within EIP-170 limit (24KB)
- `getInitCodeHash()` - Get init code hash for CREATE2
- `extractConstructorArgs()` - Extract constructor args from deployed bytecode
- `verifyBytecode()` - Verify on-chain bytecode matches expected
- `encodeConstructorArgs()` - Encode constructor arguments
- `decodeConstructorArgs()` - Decode constructor arguments
- `getContractStats()` - Get contract statistics

## Examples

See the `examples/` directory for complete examples:
- `deploy-protocol.ts` - Deploy the complete protocol
- `verify-deployment.ts` - Verify deployed contracts

## License

MIT