Skip to content

Commit 2136ff8

Browse files
authored
Merge pull request #70 from AztecProtocol/jc/add-fee-juice
add bridge script
2 parents 0aaba10 + 6addd7b commit 2136ff8

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed

.github/workflows/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ jobs:
4747
run: script -e -c "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --no-cache --runInBand --config jest.integration.config.json && aztec test"
4848

4949
- name: Run scripts
50-
run: script -e -c "yarn deploy && yarn deploy-account"
50+
run: script -e -c "yarn deploy && yarn deploy-account && yarn bridge-juice"

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"private": true,
99
"type": "module",
1010
"scripts": {
11+
"bridge-juice": "node --loader ts-node/esm scripts/bridgeFeeJuice.ts",
1112
"clean": "rm -rf ./src/artifacts ./target",
1213
"codegen": "aztec codegen target --outdir src/artifacts",
1314
"compile": "${AZTEC_NARGO:-aztec-nargo} compile",

scripts/bridgeFeeJuice.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { AccountWallet, CompleteAddress, createLogger, L1FeeJuicePortalManager, PXE, waitForPXE, createPXEClient, Logger } from "@aztec/aztec.js";
2+
import { getInitialTestAccountsWallets } from "@aztec/accounts/testing";
3+
import {
4+
createPublicClient,
5+
createWalletClient,
6+
getContract,
7+
http,
8+
} from 'viem';
9+
import { foundry } from 'viem/chains'
10+
import { mnemonicToAccount } from 'viem/accounts';
11+
import { FeeJuiceContract } from "@aztec/noir-contracts.js/FeeJuice";
12+
13+
const setupSandbox = async () => {
14+
const { PXE_URL = 'http://localhost:8080' } = process.env;
15+
const pxe = await createPXEClient(PXE_URL);
16+
await waitForPXE(pxe);
17+
return pxe;
18+
};
19+
20+
const MNEMONIC = 'test test test test test test test test test test test junk';
21+
22+
let walletClient = getL1WalletClient(foundry.rpcUrls.default.http[0], 0);
23+
const ownerEthAddress = walletClient.account.address;
24+
25+
const publicClient = createPublicClient({
26+
chain: foundry,
27+
transport: http("http://127.0.0.1:8545"),
28+
});
29+
30+
async function main() {
31+
32+
let pxe: PXE;
33+
let wallets: AccountWallet[] = [];
34+
let accounts: CompleteAddress[] = [];
35+
let logger: Logger;
36+
37+
const amount = 100n;
38+
39+
logger = createLogger('aztec:aztec-starter');
40+
41+
pxe = await setupSandbox();
42+
wallets = await getInitialTestAccountsWallets(pxe);
43+
const nodeInfo = (await pxe.getNodeInfo())
44+
const l1ContractAddresses = nodeInfo.l1ContractAddresses;
45+
46+
const feeJuiceReceipient = wallets[0].getAddress()
47+
48+
const feeJuicePortalManager = new L1FeeJuicePortalManager(
49+
l1ContractAddresses.feeJuicePortalAddress,
50+
l1ContractAddresses.feeJuiceAddress,
51+
//@ts-ignore
52+
publicClient,
53+
walletClient,
54+
logger,
55+
);
56+
57+
let feeJuiceTokenManager = feeJuicePortalManager.getTokenManager()
58+
await feeJuicePortalManager.bridgeTokensPublic(feeJuiceReceipient, amount, true);
59+
60+
const feeJuice = await FeeJuiceContract.at(nodeInfo.protocolContractAddresses.feeJuice, wallets[0])
61+
const balance = await feeJuice.methods.balance_of_public(feeJuiceReceipient).simulate()
62+
logger.info(`${balance} Fee Juice minted to ${feeJuiceReceipient} on L2.`)
63+
}
64+
65+
main();
66+
67+
// from here: https://github.com/AztecProtocol/aztec-packages/blob/ecbd59e58006533c8885a8b2fadbd9507489300c/yarn-project/end-to-end/src/fixtures/utils.ts#L534
68+
function getL1WalletClient(rpcUrl: string, index: number) {
69+
const hdAccount = mnemonicToAccount(MNEMONIC, { addressIndex: index });
70+
return createWalletClient({
71+
account: hdAccount,
72+
chain: foundry,
73+
transport: http(rpcUrl),
74+
});
75+
}

0 commit comments

Comments
 (0)