Skip to content

Instantly share code, notes, and snippets.

@yurenju
Created October 15, 2019 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yurenju/1b84eafe0bb576e4230071a909d54cd8 to your computer and use it in GitHub Desktop.
Save yurenju/1b84eafe0bb576e4230071a909d54cd8 to your computer and use it in GitHub Desktop.
async function deposit() {
const depositValue = 100;
console.log(chalk.green(`Deposit ${depositValue} from Bob's public erc20 to a aztec note`));
console.log(`- executing bob.signers.erc20.approve()`);
await (await bob.signers.erc20.approve(contractAddresses.ace, depositValue)).wait();
const depositNote = await note.create(bob.publicKey, depositValue);
depositNotes = [depositNote];
const proof = new JoinSplitProof([], depositNotes, bob.address, depositValue * -1, bob.address);
const data = proof.encodeABI(contractAddresses.zkAsset);
const signatures = proof.constructSignatures(contractAddresses.zkAsset, []);
const prevBalance = await erc20.balanceOf(bob.address);
console.log(`- prevBalance: ${prevBalance.toString()}`);
console.log(`- executing ace.publicApprove(ZK_ASSET_ADDRESS, ${proof.hash}, ${depositValue})`);
await (await bob.signers.ace.publicApprove(
contractAddresses.zkAsset,
proof.hash,
depositValue
)).wait();
console.log(`- executing zkAssetSigner.confidentialTransfer()`);
await (await bob.signers.zkAsset.confidentialTransfer(data, signatures, ethOptions)).wait();
const currBalance = await erc20.balanceOf(bob.address);
console.log(`- currBalance: ${currBalance.toString()}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment