Skip to content

Commit

Permalink
refactor: portal managers in cli
Browse files Browse the repository at this point in the history
fixing build
  • Loading branch information
sklppy88 committed Aug 20, 2024
1 parent 2bbcc7b commit 8ea59a0
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 114 deletions.
16 changes: 8 additions & 8 deletions yarn-project/cli-wallet/src/cmds/bridge_fee_juice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ export async function bridgeL1FeeJuice(
const client = await createCompatibleClient(rpcUrl, debugLogger);

// Setup portal manager
const portal = await FeeJuicePortalManager.create(client, publicClient, walletClient, debugLogger);
const { secret } = await portal.prepareTokensOnL1(amount, amount, recipient, mint);
const portal = await FeeJuicePortalManager.new(client, publicClient, walletClient, debugLogger);
const { claimAmount, claimSecret } = await portal.bridgeTokensPublic(recipient, amount, mint);

if (json) {
const out = {
claimAmount: amount,
claimSecret: secret,
claimAmount,
claimSecret,
};
log(prettyPrintJSON(out));
} else {
if (mint) {
log(`Minted ${amount} fee juice on L1 and pushed to L2 portal`);
log(`Minted ${claimAmount} fee juice on L1 and pushed to L2 portal`);
} else {
log(`Bridged ${amount} fee juice to L2 portal`);
log(`Bridged ${claimAmount} fee juice to L2 portal`);
}
log(`claimAmount=${amount},claimSecret=${secret}\n`);
log(`claimAmount=${claimAmount},claimSecret=${claimSecret}\n`);
log(`Note: You need to wait for two L2 blocks before pulling them from the L2 side`);
}
return secret;
return claimSecret;
}
13 changes: 11 additions & 2 deletions yarn-project/cli-wallet/src/cmds/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL
.requiredOption('-a, --address <string>', 'The Aztec address of the note owner.', address =>
aliasedAddressParser('accounts', address, db),
)
.addOption(createSecretKeyOption("The sender's secret key", !db, sk => aliasedSecretKeyParser(sk, db)))
.requiredOption('-h, --hash <string>', 'The tx hash of the tx containing the note.', txHash =>
aliasedTxHashParser(txHash, db),
)
Expand All @@ -372,10 +373,18 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL
.action(async (noteName, storageFieldName, _options, command) => {
const { addNote } = await import('./add_note.js');
const options = command.optsWithGlobals();
const { contractArtifact: artifactPathPromise, contractAddress, address, rpcUrl, fields, hash } = options;
const {
contractArtifact: artifactPathPromise,
contractAddress,
address,
secretKey,
rpcUrl,
fields,
hash,
} = options;
const artifactPath = await artifactPathFromPromiseOrAlias(artifactPathPromise, contractAddress, db);
const client = await createCompatibleClient(rpcUrl, debugLogger);
const account = await createOrRetrieveAccount(client, address, db);
const account = await createOrRetrieveAccount(client, address, db, undefined, secretKey);
const wallet = await account.getWallet();

await addNote(wallet, address, contractAddress, noteName, storageFieldName, artifactPath, hash, fields, log);
Expand Down
9 changes: 6 additions & 3 deletions yarn-project/cli/src/cmds/devnet/bootstrap_network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,15 @@ async function fundFPC(

const feeJuiceContract = await FeeJuiceContract.at(feeJuice, wallet);

const feeJuicePortal = await FeeJuicePortalManager.create(
const feeJuicePortal = await FeeJuicePortalManager.new(
wallet,
l1Clients.publicClient,
l1Clients.walletClient,
debugLog,
);

const amount = 10n ** 21n;
const { secret } = await feeJuicePortal.prepareTokensOnL1(amount, amount, fpcAddress, true);
const { claimAmount, claimSecret } = await feeJuicePortal.bridgeTokensPublic(fpcAddress, amount, true);

const counter = await CounterContract.at(counterAddress, wallet);

Expand All @@ -254,5 +254,8 @@ async function fundFPC(
.send()
.wait({ proven: true, provenTimeout: 600 });

await feeJuiceContract.methods.claim(fpcAddress, amount, secret).send().wait({ proven: true, provenTimeout: 600 });
await feeJuiceContract.methods
.claim(fpcAddress, claimAmount, claimSecret)
.send()
.wait({ proven: true, provenTimeout: 600 });
}
18 changes: 12 additions & 6 deletions yarn-project/cli/src/cmds/l1/bridge_erc20.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { type AztecAddress, type EthAddress } from '@aztec/circuits.js';
import { type AztecAddress, type EthAddress, type Fr } from '@aztec/circuits.js';
import { createEthereumChain, createL1Clients } from '@aztec/ethereum';
import { type DebugLogger, type LogFn } from '@aztec/foundation/log';

import { prettyPrintJSON } from '../../utils/commands.js';
import { ERC20PortalManager } from '../../utils/portal_manager.js';
import { L1PortalManager } from '../../utils/portal_manager.js';

export async function bridgeERC20(
amount: bigint,
Expand All @@ -14,6 +14,7 @@ export async function bridgeERC20(
mnemonic: string,
tokenAddress: EthAddress,
portalAddress: EthAddress,
privateTransfer: boolean,
mint: boolean,
json: boolean,
log: LogFn,
Expand All @@ -24,14 +25,19 @@ export async function bridgeERC20(
const { publicClient, walletClient } = createL1Clients(chain.rpcUrl, privateKey ?? mnemonic, chain.chainInfo);

// Setup portal manager
const portal = await ERC20PortalManager.create(tokenAddress, portalAddress, publicClient, walletClient, debugLogger);
const { secret } = await portal.prepareTokensOnL1(amount, amount, recipient, mint);
const manager = new L1PortalManager(portalAddress, tokenAddress, publicClient, walletClient, debugLogger);
let claimSecret: Fr;
if (privateTransfer) {
({ claimSecret } = await manager.bridgeTokensPrivate(recipient, amount, mint));
} else {
({ claimSecret } = await manager.bridgeTokensPublic(recipient, amount, mint));
}

if (json) {
log(
prettyPrintJSON({
claimAmount: amount,
claimSecret: secret,
claimSecret: claimSecret,
}),
);
} else {
Expand All @@ -40,7 +46,7 @@ export async function bridgeERC20(
} else {
log(`Bridged ${amount} tokens to L2 portal`);
}
log(`claimAmount=${amount},claimSecret=${secret}\n`);
log(`claimAmount=${amount},claimSecret=${claimSecret}\n`);
log(`Note: You need to wait for two L2 blocks before pulling them from the L2 side`);
}
}
2 changes: 2 additions & 0 deletions yarn-project/cli/src/cmds/l1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL
'test test test test test test test test test test test junk',
)
.option('--mint', 'Mint the tokens on L1', false)
.option('--private', 'If the bridge should use the private flow', false)
.addOption(l1ChainIdOption)
.requiredOption('-t, --token <string>', 'The address of the token to bridge', parseEthereumAddress)
.requiredOption('-p, --portal <string>', 'The address of the portal contract', parseEthereumAddress)
Expand All @@ -124,6 +125,7 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL
options.mnemonic,
options.token,
options.portal,
options.private,
options.mint,
options.json,
log,
Expand Down
Loading

0 comments on commit 8ea59a0

Please sign in to comment.