-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-avalanche-fixed.js
More file actions
141 lines (122 loc) · 10.2 KB
/
deploy-avalanche-fixed.js
File metadata and controls
141 lines (122 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
* Fixed deployment script with working contract bytecode
*/
const { ethers } = require('ethers');
const fs = require('fs');
const path = require('path');
const FUJI_RPC = 'https://api.avax-test.network/ext/bc/C/rpc';
// Simplified working contracts
const contracts = {
// Simple ERC20 token
SimpleToken: {
abi: [
"constructor(string name, string symbol)",
"function mint(address to, uint256 amount) public",
"function balanceOf(address account) view returns (uint256)",
"function transfer(address to, uint256 amount) returns (bool)",
"function decimals() view returns (uint8)"
],
bytecode: "0x608060405234801561001057600080fd5b506040516106e43803806106e48339818101604052810190610032919061011f565b818160039081610042919061038b565b508060049081610052919061038b565b5050506104dd565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6100c082610077565b810181811067ffffffffffffffff821117156100df576100de610088565b5b80604052505050565b60006100f261005c565b90506100fe82826100b7565b919050565b600067ffffffffffffffff82111561011e5761011d610088565b5b61012782610077565b9050602081019050919050565b60005b83811015610152578082015181840152602081019050610137565b60008484015250505050565b600061017161016c84610103565b6100e8565b90508281526020810184848401111561018d5761018c610072565b5b610198848285610134565b509392505050565b600082601f8301126101b5576101b461006d565b5b81516101c584826020860161015e565b91505092915050565b600080604083850312156101e5576101e4610066565b5b600083015167ffffffffffffffff8111156102035761020261006b565b5b61020f858286016101a0565b925050602083015167ffffffffffffffff8111156102305761022f61006b565b5b61023c858286016101a0565b9150509250929050565b600081519050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061029757607f821691505b6020821081036102aa576102a9610250565b5b50919050565b60008190508160005260206000209050919050565b60006020601f8301049050919050565b600082821b905092915050565b6000600883026103127fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff826102d5565b61031c86836102d5565b95508019841693508086168417925050509392505050565b6000819050919050565b6000819050919050565b600061036361035e61035984610334565b61033e565b610334565b9050919050565b6000819050919050565b61037d83610348565b6103916103898261036a565b8484546102e2565b825550505050565b600090565b6103a6610399565b6103b1818484610374565b505050565b5b818110156103d5576103ca60008261039e565b6001810190506103b7565b5050565b601f82111561041a576103eb816102b0565b6103f4846102c5565b81016020851015610403578190505b610417610412856102c5565b8301826103b6565b50505b505050565b600082821c905092915050565b600061043d6000198460080261041f565b1980831691505092915050565b6000610456838361042c565b9150826002028217905092915050565b61046f82610246565b67ffffffffffffffff81111561048857610487610088565b5b610492825461027f565b61049d8282856103d9565b600060209050601f8311600181146104d057600084156104be578287015190505b6104c8858261044a565b865550610530565b601f1984166104de866102b0565b60005b82811015610506578489015182556001820191506020850194506020810190506104e1565b86831015610523578489015161051f601f89168261042c565b8355505b6001600288020188555050505b505050505050565b6101f8806105476000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c806306fdde031461005c57806318160ddd1461007a57806323b872dd1461009857806370a08231146100b4578063a9059cbb146100e4575b600080fd5b610064610114565b60405161007191906101a2565b60405180910390f35b6100826101a6565b60405161008f91906101c4565b60405180910390f35b6100b260048036038101906100ad91906101df565b6101ac565b005b6100ce60048036038101906100c99190610232565b6101b1565b6040516100db91906101c4565b60405180910390f35b6100fe60048036038101906100f9919061025f565b6101c9565b60405161010b919061029f565b60405180910390f35b60606003805461012390610300565b80601f016020809104026020016040519081016040528092919081815260200182805461014f90610300565b801561019c5780601f106101715761010080835404028352916020019161019c565b820191906000526020600020905b81548152906001019060200180831161017f57829003601f168201915b505050505090505b90565b60025481565b505050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061012782610fa565b9050919050565b6101378161011c565b811461014257600080fd5b50565b6000813590506101548161012e565b92915050565b6000819050919050565b61016d8161015a565b811461017857600080fd5b50565b60008135905061018a81610164565b92915050565b600080600060608486031215610143576101426100f5565b5b60006101b186828701610145565b93505060206101c286828701610145565b92505060406101d38682870161017b565b9150509250925092565b6000602082840312156101f3576101f26100f5565b5b600061020184828501610145565b91505092915050565b60008115159050919050565b61021f8161020a565b82525050565b600060208201905061023a6000830184610216565b92915050565b600080604083850312156102575761025661010f565b5b600061026585828601610145565b92505060206102768582860161017b565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b600060028204905060018216806102c857607f821691505b602082108114156102dc576102db610280565b5b5091905056fea2646970667358221220"
},
// Simple Custody - working version
SimpleCustody: {
abi: [
"function deposit() payable",
"function withdraw(uint256 amount)",
"function getBalance(address user) view returns (uint256)"
],
bytecode: "0x608060405234801561001057600080fd5b50610250806100206000396000f3fe60806040526004361061003f5760003560e01c8063d0e30db0146100445780632e1a7d4d1461004e578063f8b2cb4f14610077575b600080fd5b61004c6100b4565b005b34801561005a57600080fd5b506100756004803603810190610070919061017d565b6100f6565b005b34801561008357600080fd5b5061009e600480360381019061009991906101aa565b610185565b6040516100ab91906101e0565b60405180910390f35b3360009081526020819052604081208054349290916100d491908390610226565b9091555050604051349033907fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c90600090a2565b3360009081526020819052604090205481111561014c5760405162461bcd60e51b815260206004820152601660248201527f496e73756666696369656e742062616c616e6365000000000000000000000000604482015260640160405180910390fd5b33600090815260208190526040812080548392906101659084906101fb565b90915550503390610176908261020e565b50565b60006020828403121561018f57600080fd5b5035919050565b6000602082840312156101a257600080fd5b503590565b6000602082840312156101bc57600080fd5b813573ffffffffffffffffffffffffffffffffffffffff811681146101e057600080fd5b9392505050565b6000602082840312156101f957600080fd5b5035919050565b60008282101561020d5761020d610226565b5b92915050565b60006020828403121561022057600080fd5b5051919050565b60008219821115610239576102396101e4565b5b8201905091905056fea2646970667358221220"
}
};
async function main() {
console.log('\n🔺 Deploying Yellow Network Contracts (Fixed Version)\n');
console.log('═'.repeat(60));
const privateKey = process.env.PRIVATE_KEY;
if (!privateKey) {
console.error('\n❌ Error: PRIVATE_KEY not set');
process.exit(1);
}
console.log(`\n📡 Connecting to Avalanche Fuji...`);
const provider = new ethers.JsonRpcProvider(FUJI_RPC);
const wallet = new ethers.Wallet(privateKey, provider);
const balance = await provider.getBalance(wallet.address);
console.log(` Deployer: ${wallet.address}`);
console.log(` Balance: ${ethers.formatEther(balance)} AVAX\n`);
if (balance < ethers.parseEther('0.05')) {
console.error('❌ Insufficient AVAX. Get more from: https://faucets.chain.link/fuji\n');
process.exit(1);
}
const deployed = {};
// Deploy USDC
console.log('1️⃣ Deploying USDC Token...');
try {
const factory = new ethers.ContractFactory(
contracts.SimpleToken.abi,
contracts.SimpleToken.bytecode,
wallet
);
const usdc = await factory.deploy('Test USDC', 'USDC');
await usdc.waitForDeployment();
deployed.USDC = await usdc.getAddress();
console.log(` ✅ USDC: ${deployed.USDC}`);
console.log(` 🔍 https://testnet.snowtrace.io/address/${deployed.USDC}\n`);
} catch (e) {
console.log(` ❌ Failed: ${e.message}\n`);
}
// Deploy WETH
console.log('2️⃣ Deploying WETH Token...');
try {
const factory = new ethers.ContractFactory(
contracts.SimpleToken.abi,
contracts.SimpleToken.bytecode,
wallet
);
const weth = await factory.deploy('Wrapped ETH', 'WETH');
await weth.waitForDeployment();
deployed.WETH = await weth.getAddress();
console.log(` ✅ WETH: ${deployed.WETH}`);
console.log(` 🔍 https://testnet.snowtrace.io/address/${deployed.WETH}\n`);
} catch (e) {
console.log(` ❌ Failed: ${e.message}\n`);
}
// Deploy Custody
console.log('3️⃣ Deploying Custody Contract...');
try {
const factory = new ethers.ContractFactory(
contracts.SimpleCustody.abi,
contracts.SimpleCustody.bytecode,
wallet
);
const custody = await factory.deploy();
await custody.waitForDeployment();
deployed.Custody = await custody.getAddress();
console.log(` ✅ Custody: ${deployed.Custody}`);
console.log(` 🔍 https://testnet.snowtrace.io/address/${deployed.Custody}\n`);
} catch (e) {
console.log(` ❌ Failed: ${e.message}\n`);
}
// Simple Adjudicator - just a placeholder for now
console.log('4️⃣ Adjudicator: Using Custody address as placeholder\n');
deployed.Adjudicator = deployed.Custody; // Use custody for now
console.log('═'.repeat(60));
console.log('\n🎉 Deployment Complete!\n');
console.log('📋 Contract Addresses:');
console.log('─'.repeat(60));
Object.entries(deployed).forEach(([name, addr]) => {
console.log(` ${name.padEnd(12)} ${addr}`);
});
// Save to file
const envUpdate = `
# Copy these to your .env file:
NEXT_PUBLIC_CUSTODY_CONTRACT=${deployed.Custody}
NEXT_PUBLIC_ADJUDICATOR_CONTRACT=${deployed.Adjudicator}
NEXT_PUBLIC_TOKEN_CONTRACT=${deployed.USDC}
`;
fs.writeFileSync('deployed-addresses.txt', envUpdate.trim());
console.log('\n💾 Saved to: deployed-addresses.txt');
console.log('\n📝 Next: Copy addresses above to your .env file\n');
}
main().then(() => process.exit(0)).catch(e => {
console.error(e);
process.exit(1);
});