| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import { Inject, Injectable, Logger } from '@nestjs/common'
- import { ethers } from 'ethers'
- import { Wallet, Provider, utils } from 'zksync-web3'
- import web3Config from './web3.config'
- import { ConfigType } from '@nestjs/config'
- import { AccountsService } from 'src/accounts/accounts.service'
- @Injectable()
- export class Web3Service {
- constructor(
- @Inject(web3Config.KEY)
- private readonly web3Configuration: ConfigType<typeof web3Config>,
- private readonly accountService: AccountsService
- ) {}
- async zkDeposite(accountId, amount) {
- const account = await this.accountService.findById(accountId)
- const provider = new Provider(this.web3Configuration.zksyncRpcUrl)
- const ethProvider = new ethers.providers.InfuraProvider(
- this.web3Configuration.ethereumNetwork,
- this.web3Configuration.infuraApiKey
- )
- const wallet = new Wallet(account.privateKey, provider, ethProvider)
- const deposit = await wallet.deposit({
- token: utils.ETH_ADDRESS,
- amount: ethers.utils.parseEther(amount)
- })
- Logger.log('Deposit sent. Awaiting confirmation...')
- // // Await processing of the deposit on L1
- // const ethereumTxReceipt = await deposit.waitL1Commit()
- // Logger.log('L1 deposit confirmed! Waiting for zkSync...')
- // // Await processing the deposit on zkSync
- // const depositReceipt = await deposit.wait()
- // Logger.log('zkSync deposit committed.')
- // Logger.log('Checking zkSync account balance')
- // // Retrieving the current (committed) zkSync ETH balance of an account
- // const committedEthBalance = await wallet.getBalance()
- // Logger.log('committedEthBalance', ethers.utils.formatEther(committedEthBalance))
- // // Retrieving the ETH balance of an account in the last finalized zkSync block.
- // const finalizedEthBalance = await wallet.getBalance(utils.ETH_ADDRESS, 'finalized')
- // Logger.log('finalizedEthBalance', ethers.utils.formatEther(finalizedEthBalance))
- }
- async zkWidthdraw() {}
- }
|