Skip to content

Commit 4304bb4

Browse files
author
sklppy88
committed
refactor: portal managers in cli
fixing build
1 parent 854ab45 commit 4304bb4

File tree

6 files changed

+154
-114
lines changed

6 files changed

+154
-114
lines changed

yarn-project/cli-wallet/src/cmds/bridge_fee_juice.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,23 @@ export async function bridgeL1FeeJuice(
2525
const client = await createCompatibleClient(rpcUrl, debugLogger);
2626

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

3131
if (json) {
3232
const out = {
33-
claimAmount: amount,
34-
claimSecret: secret,
33+
claimAmount,
34+
claimSecret,
3535
};
3636
log(prettyPrintJSON(out));
3737
} else {
3838
if (mint) {
39-
log(`Minted ${amount} fee juice on L1 and pushed to L2 portal`);
39+
log(`Minted ${claimAmount} fee juice on L1 and pushed to L2 portal`);
4040
} else {
41-
log(`Bridged ${amount} fee juice to L2 portal`);
41+
log(`Bridged ${claimAmount} fee juice to L2 portal`);
4242
}
43-
log(`claimAmount=${amount},claimSecret=${secret}\n`);
43+
log(`claimAmount=${claimAmount},claimSecret=${claimSecret}\n`);
4444
log(`Note: You need to wait for two L2 blocks before pulling them from the L2 side`);
4545
}
46-
return secret;
46+
return claimSecret;
4747
}

yarn-project/cli-wallet/src/cmds/index.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL
354354
.requiredOption('-a, --address <string>', 'The Aztec address of the note owner.', address =>
355355
aliasedAddressParser('accounts', address, db),
356356
)
357+
.addOption(createSecretKeyOption("The sender's secret key", !db, sk => aliasedSecretKeyParser(sk, db)))
357358
.requiredOption('-h, --hash <string>', 'The tx hash of the tx containing the note.', txHash =>
358359
aliasedTxHashParser(txHash, db),
359360
)
@@ -372,10 +373,18 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL
372373
.action(async (noteName, storageFieldName, _options, command) => {
373374
const { addNote } = await import('./add_note.js');
374375
const options = command.optsWithGlobals();
375-
const { contractArtifact: artifactPathPromise, contractAddress, address, rpcUrl, fields, hash } = options;
376+
const {
377+
contractArtifact: artifactPathPromise,
378+
contractAddress,
379+
address,
380+
secretKey,
381+
rpcUrl,
382+
fields,
383+
hash,
384+
} = options;
376385
const artifactPath = await artifactPathFromPromiseOrAlias(artifactPathPromise, contractAddress, db);
377386
const client = await createCompatibleClient(rpcUrl, debugLogger);
378-
const account = await createOrRetrieveAccount(client, address, db);
387+
const account = await createOrRetrieveAccount(client, address, db, undefined, secretKey);
379388
const wallet = await account.getWallet();
380389

381390
await addNote(wallet, address, contractAddress, noteName, storageFieldName, artifactPath, hash, fields, log);

yarn-project/cli/src/cmds/devnet/bootstrap_network.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,15 @@ async function fundFPC(
231231

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

234-
const feeJuicePortal = await FeeJuicePortalManager.create(
234+
const feeJuicePortal = await FeeJuicePortalManager.new(
235235
wallet,
236236
l1Clients.publicClient,
237237
l1Clients.walletClient,
238238
debugLog,
239239
);
240240

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

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

@@ -254,5 +254,5 @@ async function fundFPC(
254254
.send()
255255
.wait({ proven: true, provenTimeout: 600 });
256256

257-
await feeJuiceContract.methods.claim(fpcAddress, amount, secret).send().wait({ proven: true, provenTimeout: 600 });
257+
await feeJuiceContract.methods.claim(fpcAddress, claimAmount, claimSecret).send().wait({ proven: true, provenTimeout: 600 });
258258
}

yarn-project/cli/src/cmds/l1/bridge_erc20.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { type AztecAddress, type EthAddress } from '@aztec/circuits.js';
1+
import { type AztecAddress, type EthAddress, type Fr } from '@aztec/circuits.js';
22
import { createEthereumChain, createL1Clients } from '@aztec/ethereum';
33
import { type DebugLogger, type LogFn } from '@aztec/foundation/log';
44

55
import { prettyPrintJSON } from '../../utils/commands.js';
6-
import { ERC20PortalManager } from '../../utils/portal_manager.js';
6+
import { L1PortalManager } from '../../utils/portal_manager.js';
77

88
export async function bridgeERC20(
99
amount: bigint,
@@ -14,6 +14,7 @@ export async function bridgeERC20(
1414
mnemonic: string,
1515
tokenAddress: EthAddress,
1616
portalAddress: EthAddress,
17+
privateTransfer: boolean,
1718
mint: boolean,
1819
json: boolean,
1920
log: LogFn,
@@ -24,14 +25,19 @@ export async function bridgeERC20(
2425
const { publicClient, walletClient } = createL1Clients(chain.rpcUrl, privateKey ?? mnemonic, chain.chainInfo);
2526

2627
// Setup portal manager
27-
const portal = await ERC20PortalManager.create(tokenAddress, portalAddress, publicClient, walletClient, debugLogger);
28-
const { secret } = await portal.prepareTokensOnL1(amount, amount, recipient, mint);
28+
const manager = new L1PortalManager(portalAddress, tokenAddress, publicClient, walletClient, debugLogger);
29+
let claimSecret: Fr;
30+
if (privateTransfer) {
31+
({ claimSecret } = await manager.bridgeTokensPrivate(recipient, amount, mint));
32+
} else {
33+
({ claimSecret } = await manager.bridgeTokensPublic(recipient, amount, mint));
34+
}
2935

3036
if (json) {
3137
log(
3238
prettyPrintJSON({
3339
claimAmount: amount,
34-
claimSecret: secret,
40+
claimSecret: claimSecret,
3541
}),
3642
);
3743
} else {
@@ -40,7 +46,7 @@ export async function bridgeERC20(
4046
} else {
4147
log(`Bridged ${amount} tokens to L2 portal`);
4248
}
43-
log(`claimAmount=${amount},claimSecret=${secret}\n`);
49+
log(`claimAmount=${amount},claimSecret=${claimSecret}\n`);
4450
log(`Note: You need to wait for two L2 blocks before pulling them from the L2 side`);
4551
}
4652
}

yarn-project/cli/src/cmds/l1/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL
108108
'test test test test test test test test test test test junk',
109109
)
110110
.option('--mint', 'Mint the tokens on L1', false)
111+
.option('--private', 'If the bridge should use the private flow', false)
111112
.addOption(l1ChainIdOption)
112113
.requiredOption('-t, --token <string>', 'The address of the token to bridge', parseEthereumAddress)
113114
.requiredOption('-p, --portal <string>', 'The address of the portal contract', parseEthereumAddress)
@@ -124,6 +125,7 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL
124125
options.mnemonic,
125126
options.token,
126127
options.portal,
128+
options.private,
127129
options.mint,
128130
options.json,
129131
log,

0 commit comments

Comments
 (0)