Skip to content

Commit

Permalink
fix: check balance of source account
Browse files Browse the repository at this point in the history
  • Loading branch information
uF4No committed Aug 1, 2023
1 parent 7ec6b51 commit ccb8e72
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,10 @@ export default async function (
? (L1Provider = new ethers.providers.JsonRpcProvider(ethProviderUrl))
: (L1Provider = ethers.getDefaultProvider(ethProviderUrl));

await checkBalance(results.to, results.amount, L1Provider);

const zkSyncProvider = new Provider(zksyncProviderUrl);
// Initialize the wallet.
const wallet = new Wallet(results.key, zkSyncProvider, L1Provider);
await checkBalance(wallet.address, results.amount, L1Provider);

// Deposit funds to L2
const depositHandle: PriorityOpResponse = await wallet.deposit({
Expand Down
3 changes: 2 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { ethers, utils } from "ethers";
import { Provider } from "zksync-web3";
import { track } from "./analytics";

export const checkBalance = async function (
address: string,
amount: string,
provider: ethers.providers.BaseProvider
provider: Provider | ethers.providers.BaseProvider
) {
const balance = await provider.getBalance(address);
if (utils.parseEther(amount).gte(balance)) {
Expand Down
4 changes: 2 additions & 2 deletions src/withdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ export default async function (

const zkSyncProvider = new Provider(zksyncProviderUrl);

await checkBalance(results.to, results.amount, zkSyncProvider);

// Initialize the wallet.
const wallet = new Wallet(results.key, zkSyncProvider, L1Provider);

await checkBalance(wallet.address, results.amount, zkSyncProvider);

// Withdraw funds to L1
const withdrawHandle = await wallet.withdraw({
to: results.to,
Expand Down

0 comments on commit ccb8e72

Please sign in to comment.