|
| 1 | +#!/usr/bin/env -S deno run --env-file --allow-all |
| 2 | +import { deploy as deployContract, env } from '../tools/lib/index.ts' |
| 3 | +import { abis } from '../codegen/abis.ts' |
| 4 | +import { logger } from '../utils/logger.ts' |
| 5 | +import { |
| 6 | + Artifacts, |
| 7 | + build, |
| 8 | + deleteChainData, |
| 9 | + deploy, |
| 10 | + execute, |
| 11 | + ink, |
| 12 | + rust, |
| 13 | + solidity, |
| 14 | +} from './lib.ts' |
| 15 | +import { parseArgs } from '@std/cli' |
| 16 | +import { parseEther } from 'viem' |
| 17 | + |
| 18 | +export const contracts: Artifacts = [ |
| 19 | + { |
| 20 | + id: 'Fibonacci', |
| 21 | + srcs: [ |
| 22 | + ink('fibonacci'), |
| 23 | + rust('fibonacci'), |
| 24 | + rust('fibonacci_u128'), |
| 25 | + rust('fibonacci_u256'), |
| 26 | + ...solidity('fibonacci.sol', 'Fibonacci'), |
| 27 | + ], |
| 28 | + deploy: (id, name, bytecode) => { |
| 29 | + return deployContract({ |
| 30 | + name: { id, name }, |
| 31 | + bytecode, |
| 32 | + args: [], |
| 33 | + }) |
| 34 | + }, |
| 35 | + calls: [ |
| 36 | + { |
| 37 | + name: 'fib_10', |
| 38 | + exec: async (address) => { |
| 39 | + return await env.wallet.writeContract({ |
| 40 | + address, |
| 41 | + abi: abis.Fibonacci, |
| 42 | + functionName: 'fibonacci', |
| 43 | + args: [10], |
| 44 | + }) |
| 45 | + }, |
| 46 | + }, |
| 47 | + ], |
| 48 | + }, |
| 49 | + { |
| 50 | + id: 'SimpleToken', |
| 51 | + srcs: [ |
| 52 | + ink('simple_token'), |
| 53 | + rust('simple_token_no_alloc'), |
| 54 | + ...solidity('simple_token.sol', 'SimpleToken'), |
| 55 | + ], |
| 56 | + deploy: (id, name, bytecode) => { |
| 57 | + return deployContract({ |
| 58 | + name: { id, name }, |
| 59 | + bytecode, |
| 60 | + args: [], |
| 61 | + }) |
| 62 | + }, |
| 63 | + calls: [ |
| 64 | + { |
| 65 | + name: 'mint', |
| 66 | + exec: (address) => { |
| 67 | + return env.wallet.writeContract({ |
| 68 | + address, |
| 69 | + abi: abis.SimpleToken, |
| 70 | + functionName: 'mint', |
| 71 | + args: [ |
| 72 | + env.wallet.account.address, |
| 73 | + 10_000_000_000_000_000_000_000_000n, |
| 74 | + ], |
| 75 | + }) |
| 76 | + }, |
| 77 | + }, |
| 78 | + { |
| 79 | + name: 'transfer', |
| 80 | + exec: async (address) => { |
| 81 | + // fund destination first |
| 82 | + await env.wallet.sendTransaction({ |
| 83 | + to: '0x3d26c9637dFaB74141bA3C466224C0DBFDfF4A63', |
| 84 | + value: parseEther('1'), |
| 85 | + }) |
| 86 | + |
| 87 | + return env.wallet.writeContract({ |
| 88 | + address, |
| 89 | + abi: abis.SimpleToken, |
| 90 | + functionName: 'transfer', |
| 91 | + args: [ |
| 92 | + '0x3d26c9637dFaB74141bA3C466224C0DBFDfF4A63', |
| 93 | + 10_000_000_000_000_000_000_000_000n, |
| 94 | + ], |
| 95 | + }) |
| 96 | + }, |
| 97 | + }, |
| 98 | + ], |
| 99 | + }, |
| 100 | +] |
| 101 | + |
| 102 | +const cli = parseArgs(Deno.args, { |
| 103 | + boolean: ['build', 'execute', 'report', 'clean'], |
| 104 | +}) |
| 105 | + |
| 106 | +if (cli.build) { |
| 107 | + logger.info(`Building contracts...`) |
| 108 | + await build(contracts) |
| 109 | +} |
| 110 | +if (cli.execute) { |
| 111 | + logger.info(`Deleting existing data for chain: ${env.chain.name}`) |
| 112 | + deleteChainData(env.chain.name) |
| 113 | + |
| 114 | + logger.info(`Deploying contracts...`) |
| 115 | + await deploy(contracts) |
| 116 | + |
| 117 | + logger.info(`Executing contracts...`) |
| 118 | + await execute(contracts) |
| 119 | +} |
| 120 | + |
| 121 | +if (cli.report) { |
| 122 | + logger.info(`Generating reports...`) |
| 123 | + const { report } = await import('./reports.ts') |
| 124 | + await report(contracts) |
| 125 | +} |
0 commit comments