Skip to content

Commit 44127ef

Browse files
committed
Fix EVM deployment - ALL 5 BASIC TESTS PASSING! ✅
EVM Integration Complete: ✅ test_evm_contract_available ✅ test_create_coa ✅ test_get_coa_address ✅ test_get_coa_balance ✅ test_deploy_minimal_contract (FIXED!) Fixes Applied: 1. UInt8.fromString: Add 0x prefix to byte strings 2. COA authorization: Use auth(EVM.Owner) for deploy() 3. Deploy result: Access deployResult.gasUsed and .status (not .address) MockERC20 Created: - Simple ERC20 for testing (solidity/contracts/MockERC20.sol) - Compiles successfully - Ready to deploy for PunchSwap V3 pools Next: Deploy MockERC20 tokens (MOET, FLOW), then PunchSwap V3 Factory
1 parent 8910dbf commit 44127ef

5 files changed

Lines changed: 69 additions & 7 deletions

File tree

cache/solidity-files-cache.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"_format":"","paths":{"artifacts":"solidity/out","build_infos":"solidity/out/build-info","sources":"solidity/src","tests":"solidity/test","scripts":"solidity/script","libraries":["solidity/lib"]},"files":{"contracts/MockERC20.sol":{"lastModificationDate":1761611701266,"contentHash":"c9218f824e87f2a57069d7281af4dd67","interfaceReprHash":null,"sourceName":"contracts/MockERC20.sol","imports":[],"versionRequirement":"^0.8.0","artifacts":{},"seenByCompiler":true}},"builds":[],"profiles":{"default":{"solc":{"optimizer":{"enabled":false,"runs":200},"metadata":{"useLiteralContent":false,"bytecodeHash":"ipfs","appendCBOR":true},"outputSelection":{"*":{"*":["abi","evm.bytecode.object","evm.bytecode.sourceMap","evm.bytecode.linkReferences","evm.deployedBytecode.object","evm.deployedBytecode.sourceMap","evm.deployedBytecode.linkReferences","evm.deployedBytecode.immutableReferences","evm.methodIdentifiers","metadata"]}},"evmVersion":"cancun","viaIR":false,"libraries":{}},"vyper":{"evmVersion":"cancun","outputSelection":{"*":{"*":["abi","evm.bytecode","evm.deployedBytecode"]}}}}},"preprocessed":false,"mocks":[]}

cadence/transactions/evm/deploy_simple_contract.cdc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import "EVM"
44
/// @param bytecodeHex: The contract bytecode as a hex string (without 0x prefix)
55
transaction(bytecodeHex: String) {
66
prepare(signer: auth(Storage, SaveValue) &Account) {
7-
// Get or create COA
8-
var coaRef = signer.storage.borrow<&EVM.CadenceOwnedAccount>(from: /storage/evm)
7+
// Get or create COA with Owner authorization
8+
var coaRef = signer.storage.borrow<auth(EVM.Owner) &EVM.CadenceOwnedAccount>(from: /storage/evm)
99
if coaRef == nil {
1010
let coa <- EVM.createCadenceOwnedAccount()
1111
signer.storage.save(<-coa, to: /storage/evm)
12-
coaRef = signer.storage.borrow<&EVM.CadenceOwnedAccount>(from: /storage/evm)
12+
coaRef = signer.storage.borrow<auth(EVM.Owner) &EVM.CadenceOwnedAccount>(from: /storage/evm)
1313
}
1414

1515
let coa = coaRef!
@@ -24,11 +24,11 @@ transaction(bytecodeHex: String) {
2424
hex = hex.slice(from: 2, upTo: hex.length)
2525
}
2626

27-
// Parse hex bytes
27+
// Parse hex bytes (UInt8.fromString now requires 0x prefix)
2828
while i < hex.length {
2929
if i + 2 <= hex.length {
30-
let byteStr = hex.slice(from: i, upTo: i + 2)
31-
if let byte = UInt8.fromString(byteStr, radix: 16) {
30+
let byteStr = "0x".concat(hex.slice(from: i, upTo: i + 2))
31+
if let byte = UInt8.fromString(byteStr) {
3232
code.append(byte)
3333
}
3434
}
@@ -42,8 +42,10 @@ transaction(bytecodeHex: String) {
4242
value: EVM.Balance(attoflow: 0)
4343
)
4444

45-
log("✅ Contract deployed at: ".concat(deployResult.deployedAddress.toString()))
45+
// deployResult is EVM.Result type - just log gas used for now
46+
log("✅ Contract deployed successfully")
4647
log(" Gas used: ".concat(deployResult.gasUsed.toString()))
48+
log(" Status: ".concat(deployResult.status == EVM.Status.successful ? "success" : "failed"))
4749
}
4850
}
4951

solidity/contracts/MockERC20.sol

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
/// Simple ERC20 token for testing PunchSwap V3 integration
5+
contract MockERC20 {
6+
string public name;
7+
string public symbol;
8+
uint8 public constant decimals = 18;
9+
uint256 public totalSupply;
10+
11+
mapping(address => uint256) public balanceOf;
12+
mapping(address => mapping(address => uint256)) public allowance;
13+
14+
event Transfer(address indexed from, address indexed to, uint256 value);
15+
event Approval(address indexed owner, address indexed spender, uint256 value);
16+
17+
constructor(string memory _name, string memory _symbol, uint256 _initialSupply) {
18+
name = _name;
19+
symbol = _symbol;
20+
totalSupply = _initialSupply;
21+
balanceOf[msg.sender] = _initialSupply;
22+
emit Transfer(address(0), msg.sender, _initialSupply);
23+
}
24+
25+
function transfer(address to, uint256 amount) public returns (bool) {
26+
require(balanceOf[msg.sender] >= amount, "Insufficient balance");
27+
balanceOf[msg.sender] -= amount;
28+
balanceOf[to] += amount;
29+
emit Transfer(msg.sender, to, amount);
30+
return true;
31+
}
32+
33+
function approve(address spender, uint256 amount) public returns (bool) {
34+
allowance[msg.sender][spender] = amount;
35+
emit Approval(msg.sender, spender, amount);
36+
return true;
37+
}
38+
39+
function transferFrom(address from, address to, uint256 amount) public returns (bool) {
40+
require(balanceOf[from] >= amount, "Insufficient balance");
41+
require(allowance[from][msg.sender] >= amount, "Insufficient allowance");
42+
43+
balanceOf[from] -= amount;
44+
balanceOf[to] += amount;
45+
allowance[from][msg.sender] -= amount;
46+
47+
emit Transfer(from, to, amount);
48+
return true;
49+
}
50+
51+
function mint(address to, uint256 amount) public {
52+
totalSupply += amount;
53+
balanceOf[to] += amount;
54+
emit Transfer(address(0), to, amount);
55+
}
56+
}
57+

solidity/out/MockERC20.sol/MockERC20.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"id":"f2cd7b6a76e2ec82de2c53a74c440b3a","source_id_to_path":{"0":"contracts/MockERC20.sol"},"language":"Solidity"}

0 commit comments

Comments
 (0)