Skip to content

Commit

Permalink
Smart account changes (#40)
Browse files Browse the repository at this point in the history
* init

* fix eip712. paymaster

* remove logs

* fix

* rename `pureSign` to `signMessageWithPrivateKey`

* Add docs Folder to .gitignore

* zkSync Should be ZKsync

* Mostly Plugin Documentation

Also some wallet documentation

* Remove ethers References

* Remove Ethers References from smart-accounts.ts

* Cleanup utils.ts

* Export paymaster-utils.ts

* Cleanup Paymaster Utils Docs

* fix ignore

* Remove Ethers References from smart-account-utils.ts

* Fix @example Captions

* Use Correct Casing for ZKsync Naming

* Export Contracts Collection, RPC, & Typed Data Encoder

* local tests

* Fix Wallet @examples

* Wallet Withdraw Docs

* local tests

* add account abstractions tests

* fix finalization

* fixes

* fix integration tests

* fix integrations tests

* fix calim failed deposit

* Contract deployment (#38)

* draft for contract deployment

* fix build

* relocate register transaction type

* fix contract deploy. estimate gas. populate. format with customData

* fix paymaster params

* Updates to `ContractFactory` Docs

* remove a TODO and fix 2 tests at contract deployment

* estimate gas for deploy transaction

---------

Co-authored-by: Muhammad-Altabba <[email protected]>
Co-authored-by: Dan Forbes <[email protected]>

* Update README and Add License

* little refactor

* fix tests and smart accounts

* fix value formatting

* add test:all

* prepare for publish

* fix test

* new version

* add smart accounts interfaces to the plugin

* + version

---------

Co-authored-by: Muhammad Altabba <[email protected]>
Co-authored-by: Dan Forbes <[email protected]>
  • Loading branch information
3 people authored Aug 22, 2024
1 parent 6ba6d24 commit ad70f85
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 49 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web3-plugin-zksync",
"version": "1.0.0-alpha.1",
"version": "1.0.0-alpha.4",
"description": "web3.js plugin for ZkSync",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -50,4 +50,4 @@
"peerDependencies": {
"web3": ">= 4.0.3"
}
}
}
87 changes: 45 additions & 42 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,21 @@ import { INonceHolderABI } from './contracts/INonceHolder';
import { ZKsyncWallet } from './zksync-wallet';
import { Web3ZKsyncL2 } from './web3zksync-l2';
import { Web3ZKsyncL1 } from './web3zksync-l1';
import type { ContractsAddresses, ZKSyncContractsCollection } from './types';
import { ContractsAddresses, SmartAccountSigner, ZKSyncContractsCollection } from './types';
import { ECDSASmartAccount, MultisigECDSASmartAccount, SmartAccount } from './smart-account';

interface ZKSyncWalletConstructor {
interface ZKsyncWalletConstructor {
new (privateKey: string): ZKsyncWallet;
}
interface ZKsyncAccountConstructor {
new (signer: SmartAccountSigner): SmartAccount;
}
interface ZKsyncECDSASmartAccountConstructor {
create(address: string, secret: string): SmartAccount;
}
interface ZKsyncMultisigECDSASmartAccountConstructor {
create(address: string, secret: string[]): SmartAccount;
}

export class ZKsyncPlugin extends Web3PluginBase {
/**
Expand Down Expand Up @@ -81,8 +91,10 @@ export class ZKsyncPlugin extends Web3PluginBase {
* const zkWallet = new web3.ZKsync.ZkWallet(PRIVATE_KEY);
*/
// the wallet type in this class is different from the parent class. So, they should have different names.
ZkWallet: ZKSyncWalletConstructor;

Wallet: ZKsyncWalletConstructor;
SmartAccount: ZKsyncAccountConstructor;
ECDSASmartAccount: ZKsyncECDSASmartAccountConstructor;
MultisigECDSASmartAccount: ZKsyncMultisigECDSASmartAccountConstructor;
/**
* Create a new ZKsync plugin for the provided L2 network
* @param providerOrContextL2 - The provider or context for the L2 network
Expand All @@ -95,32 +107,45 @@ export class ZKsyncPlugin extends Web3PluginBase {
| Web3ZKsyncL2,
) {
super(
providerOrContextL2 as
| string
| web3Types.SupportedProviders<any>
| Web3ContextInitOptions,
providerOrContextL2 as string | web3Types.SupportedProviders<any> | Web3ContextInitOptions,
);
if (providerOrContextL2 instanceof Web3ZKsyncL2) {
this.L2 = providerOrContextL2;
} else {
this.L2 = new Web3ZKsyncL2(providerOrContextL2);
}
// @ts-ignore-next-line
// TransactionFactory.registerTransactionType(constants.EIP712_TX_TYPE, EIP712Transaction);

this._l2BridgeContracts = {};
this._erc20Contracts = {};

this.contractsAddresses = this.initContractsAddresses();

const self = this;
class ZKSyncWalletWithFullContext extends ZKsyncWallet {
class ZKsyncWalletWithFullContext extends ZKsyncWallet {
constructor(privateKey: string) {
super(privateKey, self.L2, self.L1);
}
}
class ZKsyncAccountWithFullContext extends SmartAccount {
constructor(signer: SmartAccountSigner) {
super(signer, self.L2);
}
}
class ZKsyncECDSASmartAccountWithFullContext {
static create(address: string, secret: string): SmartAccount {
return ECDSASmartAccount.create(address, secret, self.L2);
}
}
class ZKsyncMultisigECDSASmartAccountWithFullContext extends MultisigECDSASmartAccount {
static create(address: string, secret: string[]): SmartAccount {
return MultisigECDSASmartAccount.create(address, secret, self.L2);
}
}

this.ZkWallet = ZKSyncWalletWithFullContext;
this.Wallet = ZKsyncWalletWithFullContext;
this.SmartAccount = ZKsyncAccountWithFullContext;
this.ECDSASmartAccount = ZKsyncECDSASmartAccountWithFullContext;
this.MultisigECDSASmartAccount = ZKsyncMultisigECDSASmartAccountWithFullContext;
this.initWallet();
}

Expand Down Expand Up @@ -162,16 +187,8 @@ export class ZKsyncPlugin extends Web3PluginBase {
constants.CONTRACT_DEPLOYER_ADDRESS,
this.L2,
),
L1MessengerContract: new Contract(
IL1MessengerABI,
constants.L1_MESSENGER_ADDRESS,
this.L2,
),
NonceHolderContract: new Contract(
INonceHolderABI,
constants.NONCE_HOLDER_ADDRESS,
this.L2,
),
L1MessengerContract: new Contract(IL1MessengerABI, constants.L1_MESSENGER_ADDRESS, this.L2),
NonceHolderContract: new Contract(INonceHolderABI, constants.NONCE_HOLDER_ADDRESS, this.L2),
L2BridgeContract: new Contract(IL2BridgeABI, l2SharedDefaultBridge, this.L2),
},
};
Expand Down Expand Up @@ -218,17 +235,15 @@ export class ZKsyncPlugin extends Web3PluginBase {
}
}

this.ZkWallet = ZKSyncWalletWithFullContext;
this.Wallet = ZKSyncWalletWithFullContext;
}

/**
* Get RPC methods instance
*/
get rpc(): RpcMethods {
if (!this._rpc) {
this._rpc = new RpcMethods(
this.L2.requestManager as unknown as Web3RequestManager<unknown>,
);
this._rpc = new RpcMethods(this.L2.requestManager as unknown as Web3RequestManager<unknown>);
}
return this._rpc;
}
Expand All @@ -243,16 +258,8 @@ export class ZKsyncPlugin extends Web3PluginBase {
* For example, if the L1 or L2 providers were changed from testnet to mainnet, this method should be called.
*/
public updateProviders(
contextL1:
| Web3ZKsyncL1
| web3Types.SupportedProviders<any>
| Web3ContextInitOptions
| string,
contextL2:
| Web3ZKsyncL2
| web3Types.SupportedProviders<any>
| Web3ContextInitOptions
| string,
contextL1: Web3ZKsyncL1 | web3Types.SupportedProviders<any> | Web3ContextInitOptions | string,
contextL2: Web3ZKsyncL2 | web3Types.SupportedProviders<any> | Web3ContextInitOptions | string,
) {
this.L1 = contextL1 instanceof Web3ZKsyncL1 ? contextL1 : new Web3ZKsyncL1(contextL1);
this.L2 = contextL2 instanceof Web3ZKsyncL2 ? contextL2 : new Web3ZKsyncL2(contextL2);
Expand Down Expand Up @@ -301,9 +308,7 @@ export class ZKsyncPlugin extends Web3PluginBase {
return l1Token;
}
} catch (e) {
throw new Error(
`Error getting L1 address for token ${token}. ${JSON.stringify(e)}`,
);
throw new Error(`Error getting L1 address for token ${token}. ${JSON.stringify(e)}`);
}
}

Expand All @@ -329,9 +334,7 @@ export class ZKsyncPlugin extends Web3PluginBase {
return l2WethToken;
}
} catch (e) {
throw new Error(
`Error getting L2 address for token ${token}. ${JSON.stringify(e)}`,
);
throw new Error(`Error getting L2 address for token ${token}. ${JSON.stringify(e)}`);
}
}

Expand Down
5 changes: 0 additions & 5 deletions test.ts

This file was deleted.

0 comments on commit ad70f85

Please sign in to comment.