Skip to content

Commit

Permalink
Ready for another review, improved the wallet options
Browse files Browse the repository at this point in the history
  • Loading branch information
shirren committed Dec 11, 2023
1 parent c97b111 commit bafcfad
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
7 changes: 2 additions & 5 deletions scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ async function main(): Promise<EnvironmentInfo> {

// Setup wallet
const wallets: WalletOptions = await newWalletOptions(environment);
/*
console.log(`[${network}] Contract Deployer Address: ${await wallets.getContractDeployer().getAddress()}`);
//console.log(`[${network}] Contract Deployer Address: ${await wallets.getContractDeployer().getAddress()}`);
console.log(
`[${network}] Wallet Impl Locator Changer Address: ${await wallets.getWalletImplLocatorChanger().getAddress()}`
);*/
);

// TOTAL deployment cost = 0.009766773 GWEI = 0.000000000009766773 ETHER
// Deployments with esimated gas costs (GWEI)
Expand All @@ -50,8 +49,6 @@ async function main(): Promise<EnvironmentInfo> {
await multiCallDeploy.deployTransaction.wait();
console.log(`[${network}] Multi Call Deploy deployed to: ${multiCallDeploy.address}`);

return environment;

// 2. Deploy factory with multi call deploy address as deployer role EST
// EST gas cost: 0.001239658
const factoryCF: ContractFactory = await newContractFactory(wallets.getContractDeployer(), 'Factory');
Expand Down
5 changes: 0 additions & 5 deletions scripts/ledger-signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export class LedgerSigner extends ethers.Signer {
try {
const eth = new Eth(transport);
await eth.getAppConfiguration();
console.log(`?: ${eth}`);
return eth;
} catch (error) {
throw 'LedgerSigner: unable to initialize TransportNodeHid: ' + error;
Expand All @@ -58,20 +57,16 @@ export class LedgerSigner extends ethers.Signer {
}

public async getAddress(): Promise<string> {
console.log(`getAddress: on LedgerSigner for path: ${this.path}`);
const eth = await this._eth;

const MAX_RETRY_COUNT = 50;
const WAIT_INTERVAL = 100;

for (let i = 0; i < MAX_RETRY_COUNT; i++) {
console.log('In loop');
try {
const account = await eth!.getAddress(this.path);
console.log(`account: ${account.address}`);
return ethers.utils.getAddress(account.address);
} catch (error) {
console.log('getAddress: failed');
if ((error as any).id !== 'TransportLocked') {
throw error;
}
Expand Down
15 changes: 5 additions & 10 deletions scripts/wallet-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ const mainnetEnv = 'mainnet';
* which used the following type to configure the connect function.
*/
export class WalletOptions {
useLedger: boolean;
private contractDeployerLedger: LedgerSigner;
private walletImplLocatorImplChangerLedger: LedgerSigner;
private useLedger: boolean;
private ledger: LedgerSigner;
private contractDeployer: Signer;
private walletImplLocatorImplChanger: Signer;

Expand All @@ -25,25 +24,21 @@ export class WalletOptions {
this.useLedger = false;
}

// Setup the 2 ledgers
const accountIndex0 = 0;
const derivationPath0 = `m/44'/60'/${accountIndex0.toString()}'/0/0`;
this.contractDeployerLedger = new LedgerSigner(hardhat.provider, derivationPath0);
const accountIndex1 = 1;
const derivationPath1 = `m/44'/60'/${accountIndex1.toString()}'/0/0`;
this.walletImplLocatorImplChangerLedger = new LedgerSigner(hardhat.provider, derivationPath1);
this.ledger = new LedgerSigner(hardhat.provider, derivationPath0);

// Setup the 2 programmatic wallets
this.contractDeployer = contractDeployer;
this.walletImplLocatorImplChanger = walletImplLocatorImplChanger;
}

public getContractDeployer(): Signer {
return this.useLedger ? this.contractDeployerLedger : this.contractDeployer;
return this.useLedger ? this.ledger : this.contractDeployer;
}

public getWalletImplLocatorChanger(): Signer {
return this.useLedger ? this.walletImplLocatorImplChangerLedger : this.walletImplLocatorImplChanger;
return this.walletImplLocatorImplChanger;
}
}

Expand Down

0 comments on commit bafcfad

Please sign in to comment.