Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf and style changes #574

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
62 changes: 28 additions & 34 deletions contracts/predicate/scripts/run-predicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,39 @@ if (!NEXT_PUBLIC_FUEL_CHAIN_NAME || !PRIVATE_KEY) {

const providerUrl = FUEL_CHAIN.providerUrl;

async function main() {
const binHex = hexlify(await fs.readFile(BIN_PATH));
const provider = await Provider.create(providerUrl);
const wallet = Wallet.fromPrivateKey(PRIVATE_KEY!, provider);
const { minGasPrice: gasPrice } = wallet.provider.getGasConfig();
const walletAddress = wallet.address.toB256();
const abiPath = resolve(__dirname, '../out/debug/predicate-app-abi.json');
const abi = await fs.readFile(abiPath, 'utf-8');
const abiJson = JSON.parse(abi);
const predicate = new Predicate(binHex, provider, abiJson);

console.log('💰 Funding predicate...');
const tx1 = await wallet.transfer(predicate.address, AMOUNT, BaseAssetId, {
gasPrice,
});

const res1 = await tx1.waitForResult();
const predicateBalance = bn(await predicate.getBalance());
console.log(`→ Transaction Id: ${res1.id}`);
console.log(`→ Predicate balance: ${predicateBalance.format()}`);
console.log(`→ Predicate Id: ${predicate.address.toB256()}`);
console.log(`📝 Wallet address: ${walletAddress}\n`);

console.log('⌛️ Running predicate...');
predicate.setData(walletAddress);
async function loadFile(filePath: string): Promise<string> {
return fs.readFile(filePath, 'utf-8');
}

async function main() {
try {
const tx2 = await predicate.transfer(
wallet.address,
AMOUNT - 150_000,
BaseAssetId,
{
gasPrice,
},
);
const binHex = hexlify(await fs.readFile(BIN_PATH));
const provider = await Provider.create(providerUrl);
const wallet = Wallet.fromPrivateKey(PRIVATE_KEY!, provider);
const { minGasPrice: gasPrice } = await wallet.provider.getGasConfig();
const walletAddress = wallet.address.toB256();
const abiPath = resolve(__dirname, '../out/debug/predicate-app-abi.json');
const abiJson = JSON.parse(await loadFile(abiPath));
const predicate = new Predicate(binHex, provider, abiJson);

console.log('💰 Funding predicate...');
const tx1 = await wallet.transfer(predicate.address, AMOUNT, BaseAssetId, { gasPrice });
const res1 = await tx1.waitForResult();
const predicateBalance = bn(await predicate.getBalance());

console.log(`→ Transaction Id: ${res1.id}`);
console.log(`→ Predicate balance: ${predicateBalance.format()}`);
console.log(`→ Predicate Id: ${predicate.address.toB256()}`);
console.log(`📝 Wallet address: ${walletAddress}\n`);

console.log('⌛️ Running predicate...');
predicate.setData(walletAddress);

const tx2 = await predicate.transfer(wallet.address, AMOUNT - 150_000, BaseAssetId, { gasPrice });
const res2 = await tx2.waitForResult();
console.log(`→ Transaction Id: ${res2.id}`);
} catch (error: any) {
console.error(error?.response?.errors?.[0].message);
console.error(error?.response?.errors?.[0]?.message || error.message);
}
}

Expand Down
13 changes: 12 additions & 1 deletion docker/erc20-deployer/deployer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
setupEnvironment,
} from '@fuel-bridge/test-utils';

// Environment variables
const {
PORT,
L1_CHAIN_HTTP,
Expand All @@ -16,24 +17,32 @@ const {
const APP_PORT = PORT || 9090;

async function main() {
// Setup environment
const env = await setupEnvironment({
http_ethereum_client: L1_CHAIN_HTTP,
http_fuel_client: FUEL_GRAPHQL_ENDPOINT,
http_deployer: DEPLOYMENTS_HTTP,
pk_eth_signer2: PK_ETH_WALLET,
});

// Deploy or get existing ERC20 contract
const ETHToken = await getOrDeployECR20Contract(env);

// Deploy or get existing L2 bridge
const { contract, implementation } = await getOrDeployL2Bridge(
env,
env.eth.fuelERC20Gateway,
);

// Set asset issuer ID
const fuelContractId = contract.id.toHexString();
await env.eth.fuelERC20Gateway.setAssetIssuerId(fuelContractId);

// Get ERC20 address and token ID
const erc20Address = (await ETHToken.getAddress()).toLowerCase();
const tokenId = getTokenId(contract, erc20Address);

// Start the server with deployment details
await startServer({
ETH_ERC20: erc20Address,
FUEL_TokenContract: fuelContractId,
Expand All @@ -45,11 +54,12 @@ async function main() {
function startServer(deployments: Record<string, string>) {
return new Promise((resolve) => {
createServer((req, res) => {
// add cors headers
// Add CORS headers
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Request-Method', '*');
res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET');
res.setHeader('Access-Control-Allow-Headers', '*');

if (req.method === 'OPTIONS') {
res.writeHead(200);
res.end();
Expand All @@ -74,6 +84,7 @@ function startServer(deployments: Record<string, string>) {
});
}

// Start the main function
main()
.then(() => {
console.log(`Server listening on port ${APP_PORT}`);
Expand Down