Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@
logs
*.log
.env

npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

codegen/*.ts
codegen/*.json
codegen/abi/*
codegen/pvm/*
codegen/evm/*
*.sha256.txt

# Benchmark artifacts
stats.db
benchmark/.ipynb_checkpoints/

node_modules
dist
dist-ssr
Expand Down
125 changes: 125 additions & 0 deletions benchmark/contracts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/usr/bin/env -S deno run --env-file --allow-all
import { deploy as deployContract, env } from '../tools/lib/index.ts'
import { abis } from '../codegen/abis.ts'
import { logger } from '../utils/logger.ts'
import {
Artifacts,
build,
deleteChainData,
deploy,
execute,
ink,
rust,
solidity,
} from './lib.ts'
import { parseArgs } from '@std/cli'
import { parseEther } from 'viem'

export const contracts: Artifacts = [
{
id: 'Fibonacci',
srcs: [
ink('fibonacci'),
rust('fibonacci'),
rust('fibonacci_u128'),
rust('fibonacci_u256'),
...solidity('fibonacci.sol', 'Fibonacci'),
],
deploy: (id, name, bytecode) => {
return deployContract({
name: { id, name },
bytecode,
args: [],
})
},
calls: [
{
name: 'fib_10',
exec: async (address) => {
return await env.wallet.writeContract({
address,
abi: abis.Fibonacci,
functionName: 'fibonacci',
args: [10],
})
},
},
],
},
{
id: 'SimpleToken',
srcs: [
ink('simple_token'),
rust('simple_token_no_alloc'),
...solidity('simple_token.sol', 'SimpleToken'),
],
deploy: (id, name, bytecode) => {
return deployContract({
name: { id, name },
bytecode,
args: [],
})
},
calls: [
{
name: 'mint',
exec: (address) => {
return env.wallet.writeContract({
address,
abi: abis.SimpleToken,
functionName: 'mint',
args: [
env.wallet.account.address,
10_000_000_000_000_000_000_000_000n,
],
})
},
},
{
name: 'transfer',
exec: async (address) => {
// fund destination first
await env.wallet.sendTransaction({
to: '0x3d26c9637dFaB74141bA3C466224C0DBFDfF4A63',
value: parseEther('1'),
})

return env.wallet.writeContract({
address,
abi: abis.SimpleToken,
functionName: 'transfer',
args: [
'0x3d26c9637dFaB74141bA3C466224C0DBFDfF4A63',
10_000_000_000_000_000_000_000_000n,
],
})
},
},
],
},
]

const cli = parseArgs(Deno.args, {
boolean: ['build', 'execute', 'report', 'clean'],
})

if (cli.build) {
logger.info(`Building contracts...`)
await build(contracts)
}
if (cli.execute) {
logger.info(`Deleting existing data for chain: ${env.chain.name}`)
deleteChainData(env.chain.name)

logger.info(`Deploying contracts...`)
await deploy(contracts)

logger.info(`Executing contracts...`)
await execute(contracts)
}

if (cli.report) {
logger.info(`Generating reports...`)
const { report } = await import('./reports.ts')
await report(contracts)
}
Loading