Skip to content

Commit

Permalink
refactor: only wallet in generated types
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Oct 23, 2023
1 parent f66fa7e commit 4c0fc14
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 30 deletions.
2 changes: 1 addition & 1 deletion yarn-project/aztec-sandbox/src/examples/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function main() {
logger(`Created Alice and Bob accounts: ${alice.address.toString()}, ${bob.address.toString()}`);

logger('Deploying Token...');
const token = await TokenContract.deploy(pxe, alice).send().deployed();
const token = await TokenContract.deploy(aliceWallet, alice).send().deployed();
logger('Token deployed');

// Create the contract abstraction and link it to Alice's and Bob's wallet for future signing
Expand Down
9 changes: 4 additions & 5 deletions yarn-project/boxes/blank-react/src/artifacts/Blank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
EthAddressLike,
FieldLike,
Fr,
PXE,
Point,
PublicKey,
Wallet,
Expand Down Expand Up @@ -56,15 +55,15 @@ export class BlankContract extends ContractBase {
/**
* Creates a tx to deploy a new instance of this contract.
*/
public static deploy(pxe: PXE, ) {
return new DeployMethod<BlankContract>(Point.ZERO, pxe, BlankContractArtifact, Array.from(arguments).slice(1));
public static deploy(wallet: Wallet, ) {
return new DeployMethod<BlankContract>(Point.ZERO, wallet, BlankContractArtifact, Array.from(arguments).slice(1));
}

/**
* Creates a tx to deploy a new instance of this contract using the specified public key to derive the address.
*/
public static deployWithPublicKey(publicKey: PublicKey, pxe: PXE, ) {
return new DeployMethod<BlankContract>(publicKey, pxe, BlankContractArtifact, Array.from(arguments).slice(2));
public static deployWithPublicKey(publicKey: PublicKey, wallet: Wallet, ) {
return new DeployMethod<BlankContract>(publicKey, wallet, BlankContractArtifact, Array.from(arguments).slice(2));
}


Expand Down
9 changes: 4 additions & 5 deletions yarn-project/boxes/blank/src/artifacts/Blank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
EthAddressLike,
FieldLike,
Fr,
PXE,
Point,
PublicKey,
Wallet,
Expand Down Expand Up @@ -56,15 +55,15 @@ export class BlankContract extends ContractBase {
/**
* Creates a tx to deploy a new instance of this contract.
*/
public static deploy(pxe: PXE, ) {
return new DeployMethod<BlankContract>(Point.ZERO, pxe, BlankContractArtifact, Array.from(arguments).slice(1));
public static deploy(wallet: Wallet, ) {
return new DeployMethod<BlankContract>(Point.ZERO, wallet, BlankContractArtifact, Array.from(arguments).slice(1));
}

/**
* Creates a tx to deploy a new instance of this contract using the specified public key to derive the address.
*/
public static deployWithPublicKey(publicKey: PublicKey, pxe: PXE, ) {
return new DeployMethod<BlankContract>(publicKey, pxe, BlankContractArtifact, Array.from(arguments).slice(2));
public static deployWithPublicKey(publicKey: PublicKey, wallet: Wallet, ) {
return new DeployMethod<BlankContract>(publicKey, wallet, BlankContractArtifact, Array.from(arguments).slice(2));
}


Expand Down
9 changes: 4 additions & 5 deletions yarn-project/boxes/token/src/artifacts/Token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
EthAddressLike,
FieldLike,
Fr,
PXE,
Point,
PublicKey,
Wallet,
Expand Down Expand Up @@ -56,15 +55,15 @@ export class TokenContract extends ContractBase {
/**
* Creates a tx to deploy a new instance of this contract.
*/
public static deploy(pxe: PXE, admin: AztecAddressLike) {
return new DeployMethod<TokenContract>(Point.ZERO, pxe, TokenContractArtifact, Array.from(arguments).slice(1));
public static deploy(wallet: Wallet, admin: AztecAddressLike) {
return new DeployMethod<TokenContract>(Point.ZERO, wallet, TokenContractArtifact, Array.from(arguments).slice(1));
}

/**
* Creates a tx to deploy a new instance of this contract using the specified public key to derive the address.
*/
public static deployWithPublicKey(publicKey: PublicKey, pxe: PXE, admin: AztecAddressLike) {
return new DeployMethod<TokenContract>(publicKey, pxe, TokenContractArtifact, Array.from(arguments).slice(2));
public static deployWithPublicKey(publicKey: PublicKey, wallet: Wallet, admin: AztecAddressLike) {
return new DeployMethod<TokenContract>(publicKey, wallet, TokenContractArtifact, Array.from(arguments).slice(2));
}


Expand Down
5 changes: 1 addition & 4 deletions yarn-project/end-to-end/src/e2e_cheat_codes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,7 @@ describe('e2e_cheat_codes', () => {
});

it('can modify L2 block time', async () => {
const tx = TestContract.deploy(pxe).send();
await tx.isMined({ interval: 0.1 });
const receipt = await tx.getReceipt();
const contract = await TestContract.at(receipt.contractAddress!, wallet);
const contract = await TestContract.deploy(wallet).send().deployed();

// now update time:
const timestamp = await cc.eth.timestamp();
Expand Down
12 changes: 7 additions & 5 deletions yarn-project/end-to-end/src/e2e_sandbox_example.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ describe('e2e_sandbox_example', () => {
////////////// LOAD SOME ACCOUNTS FROM THE SANDBOX //////////////
// The sandbox comes with a set of created accounts. Load them
const accounts = await getSandboxAccountsWallets(pxe);
const alice = accounts[0].getAddress();
const bob = accounts[1].getAddress();
const aliceWallet = accounts[0];
const bobWallet = accounts[1];
const alice = aliceWallet.getAddress();
const bob = bobWallet.getAddress();
logger(`Loaded alice's account at ${alice.toShortString()}`);
logger(`Loaded bob's account at ${bob.toShortString()}`);
// docs:end:load_accounts
Expand All @@ -58,11 +60,11 @@ describe('e2e_sandbox_example', () => {
logger(`Deploying token contract...`);

// Deploy the contract and set Alice as the admin while doing so
const contract = await TokenContract.deploy(pxe, alice).send().deployed();
const contract = await TokenContract.deploy(aliceWallet, alice).send().deployed();
logger(`Contract successfully deployed at address ${contract.address.toShortString()}`);

// Create the contract abstraction and link it to Alice's wallet for future signing
const tokenContractAlice = await TokenContract.at(contract.address, accounts[0]);
const tokenContractAlice = await TokenContract.at(contract.address, aliceWallet);

// Create a secret and a corresponding hash that will be used to mint funds privately
const aliceSecret = Fr.random();
Expand Down Expand Up @@ -92,7 +94,7 @@ describe('e2e_sandbox_example', () => {

// Bob wants to mint some funds, the contract is already deployed, create an abstraction and link it his wallet
// Since we already have a token link, we can simply create a new instance of the contract linked to Bob's wallet
const tokenContractBob = tokenContractAlice.withWallet(accounts[1]);
const tokenContractBob = tokenContractAlice.withWallet(bobWallet);

let aliceBalance = await tokenContractAlice.methods.balance_of_private(alice).view();
logger(`Alice's balance ${aliceBalance}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ function generateDeploy(input: ContractArtifact) {
/**
* Creates a tx to deploy a new instance of this contract.
*/
public static deploy(pxe: PXE, ${args}) {
return new DeployMethod<${input.name}Contract>(Point.ZERO, pxe, ${artifactName}, Array.from(arguments).slice(1));
public static deploy(wallet: Wallet, ${args}) {
return new DeployMethod<${input.name}Contract>(Point.ZERO, wallet, ${artifactName}, Array.from(arguments).slice(1));
}
/**
* Creates a tx to deploy a new instance of this contract using the specified public key to derive the address.
*/
public static deployWithPublicKey(publicKey: PublicKey, pxe: PXE, ${args}) {
return new DeployMethod<${input.name}Contract>(publicKey, pxe, ${artifactName}, Array.from(arguments).slice(2));
public static deployWithPublicKey(publicKey: PublicKey, wallet: Wallet, ${args}) {
return new DeployMethod<${input.name}Contract>(publicKey, wallet, ${artifactName}, Array.from(arguments).slice(2));
}
`;
}
Expand Down Expand Up @@ -185,7 +185,6 @@ import {
EthAddressLike,
FieldLike,
Fr,
PXE,
Point,
PublicKey,
Wallet,
Expand Down

0 comments on commit 4c0fc14

Please sign in to comment.