@mayflower-fi/evm-bytecode
v0.0.5
Published
Compiled bytecode and deployment helpers for May Prog EVM contracts
Readme
@mayflower-fi/evm-bytecode
Compiled bytecode and deployment helpers for May Prog EVM contracts.
Installation
npm install @mayflower-fi/evm-bytecode
# or
yarn add @mayflower-fi/evm-bytecode
# or
pnpm add @mayflower-fi/evm-bytecodeUsage
Basic Contract Deployment
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
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
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
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 contractsTenantImplementation- Implementation contract for tenantsMarketGroupFactory- Factory for deploying market groupsMarketGroupImplementation- Implementation contract for market groupsMarketFactory- Factory for deploying marketsLinearMarketImplementation- Implementation contract for linear bonding curve marketsMarketToken- ERC20 token for market derivativesCallOptionToken- ERC20 token for call optionsMockERC20- Mock ERC20 token for testing (if available)
Helper Functions
Deployment
deployProtocol()- Deploy complete protocol infrastructuredeployTenant()- Deploy a new tenantdeployMarketGroup()- Deploy a new market groupdeployMarket()- Deploy a new market
Bytecode Utilities
getBytecodeSize()- Get bytecode size in bytesisWithinSizeLimit()- Check if bytecode is within EIP-170 limit (24KB)getInitCodeHash()- Get init code hash for CREATE2extractConstructorArgs()- Extract constructor args from deployed bytecodeverifyBytecode()- Verify on-chain bytecode matches expectedencodeConstructorArgs()- Encode constructor argumentsdecodeConstructorArgs()- Decode constructor argumentsgetContractStats()- Get contract statistics
Examples
See the examples/ directory for complete examples:
deploy-protocol.ts- Deploy the complete protocolverify-deployment.ts- Verify deployed contracts
License
MIT
