EEarnwithalee7890

apeshift-pro

Production-grade Brownie to Ape Framework migration codemod - 20+ deterministic AST rules covering imports, accounts, deployments, transactions, chain APIs, testing patterns, and Wei conversions

brownieapeapeworxmigrationsmart-contractsethereumweb3pythonsolidityvyper
Public
0 executions

Run locally

npx codemod apeshift-pro

ApeShift Pro 🐒⚡

Production-grade Brownie → Ape Framework migration codemod

Built with Codemod · JSSG (ast-grep) · Python AST transformations

Registry: apeshift-pro
Live Demo
License: MIT
Tests


What is ApeShift?

ApeShift automates 93% of the code migration from Brownie (deprecated) to Ape Framework using deterministic AST transformations powered by Codemod's JSSG engine. Validated against real DeFi codebases (Yearn Finance).

No regex hacks. No string replacements. Real AST-level code understanding.


💡 Why We Built This (The Value Proposition)

The Problem:
Brownie was the industry-standard Python testing framework for Ethereum smart contracts, but it is now officially deprecated and unmaintained. Thousands of DeFi protocols (like Yearn, Curve, and countless others) have massive test suites stuck on a dying framework. Migrating these repositories to the modern Ape Framework manually is a nightmare: it takes weeks of engineering time, is highly prone to human error, and halts product development.

The Solution:
We built ApeShift to completely eliminate the friction of migrating. By leveraging Codemod and AST (Abstract Syntax Tree) parsing, ApeShift understands Python semantics and automatically translates Brownie-specific syntax into Ape-compatible code.

The Impact:

  • ⏱️ Saves Weeks of Work: What used to take a developer 2 weeks of tedious find-and-replace now takes 15 seconds.
  • 🛡️ Zero False Positives: Because it uses AST (via ast-grep), it only modifies actual code structures, ignoring comments, strings, and unrelated variables.
  • 🔄 Standardization: Helps the entire Web3 Python ecosystem safely move to Ape Framework without abandoning their legacy test suites.

🎯 Coverage — 26 Deterministic Transformation Rules

#Brownie PatternApe EquivalentType
1from brownie import Xfrom ape import XImport
2import brownieimport apeImport
3brownie.Xape.XAttribute
4accounts[N]accounts.test_accounts[N]Accounts
5Token.deploy(args, {"from": acc})project.Token.deploy(args, sender=acc)Deploy
6contract.func({"from": acc})contract.func(sender=acc)Transaction
7contract.func(args, {"from": X, "value": Y})contract.func(args, sender=X, value=Y)Tx Params
8chain.sleep(N)chain.pending_timestamp += NChain API
9chain.time()chain.pending_timestampChain API
10chain.mine(N)chain.mine(num_blocks=N)Chain API
11Wei("1 ether")"1 ether"Value
12brownie.reverts("msg")ape.reverts("msg")Testing
13Contract.at(addr)Contract(addr)Contract
14network.show_active()networks.provider.network.nameNetwork
15network.connect(X)# TODO: ape context managerNetwork
16network.disconnect()# TODO: ape context managerNetwork
17VirtualMachineErrorContractLogicErrorException
18network (import)networksImport
19accounts.at("0x...", force=True)accounts.impersonate_account("0x...")Accounts
20config["..."]# TODO: ape-config.yamlConfig
21web3.X# TODO: ape providerWeb3
22fn_isolation# TODO: ape-test handles nativelyTesting
23Wei (import)removedImport
24config (import)removedImport
25web3 (import)removedImport
26Contract names (import)auto-inject projectImport

🚀 Quick Start

Run directly from Codemod Registry (Recommended)

Run the codemod on your project without downloading the repo:

bash

Run locally from the repository

If you clone this repository, you can run the workflow locally:

bash

Run with AI edge-case handling (Local only)

bash

Run tests

bash

📁 Project Structure

text

🏗 Architecture

text

🧪 Testing

The codemod includes 3 snapshot test suites — including tests from the real Yearn Finance brownie-strategy-mix:

bash

See CASE_STUDY.md for full coverage analysis.


📦 Publishing

bash

Or via GitHub Actions with Trusted Publishers.


📚 References


License

MIT

Before

This is one example from the codemod's test cases. The codemod may handle many more cases.

Ready to contribute?

Build your own codemod and share it with the community.