|
|
@@ -42,11 +42,14 @@ import { getSwapContract, getSwapChainWithExactOutputCall, getSwapChainWithExact
|
|
|
import mintSquareAbi from './mintSquareAbi.json'
|
|
|
import { Network } from './network.enum'
|
|
|
import { Cron } from '@nestjs/schedule'
|
|
|
+import { Web3Result } from './model/web3-result'
|
|
|
|
|
|
@Injectable()
|
|
|
export class Web3Service {
|
|
|
constructor(private readonly accountService: AccountsService) {}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
async zkDeposit(accountId, amount) {
|
|
|
const account = await this.accountService.findById(accountId)
|
|
|
const provider = new Provider(web3Config[account.network].zksyncRpcUrl)
|
|
|
@@ -60,6 +63,7 @@ export class Web3Service {
|
|
|
amount: ethers.utils.parseEther(amount)
|
|
|
})
|
|
|
Logger.log('Deposit sent. Awaiting confirmation...')
|
|
|
+ return new Web3Result(account.address, deposit.hash, web3Config[account.network], false)
|
|
|
// // Await processing of the deposit on L1
|
|
|
// const ethereumTxReceipt = await deposit.waitL1Commit()
|
|
|
|
|
|
@@ -91,6 +95,7 @@ export class Web3Service {
|
|
|
amount: ethers.utils.parseEther(amount)
|
|
|
})
|
|
|
Logger.log(`Widthdraw sent. ${web3Config[account.network].zksyncExplorer}/tx/${withdrawL2.hash}`)
|
|
|
+ return new Web3Result(account.address, withdrawL2.hash, web3Config[account.network], true)
|
|
|
// // Await processing of the deposit on L1
|
|
|
// const ethereumTxReceipt = await deposit.waitL1Commit()
|
|
|
|
|
|
@@ -121,14 +126,22 @@ export class Web3Service {
|
|
|
to: web3Config[account.network].orbiterEthAddress,
|
|
|
value: ethers.utils.parseEther(amount).add(web3Config[account.network].orbiterIdCodeZk)
|
|
|
})
|
|
|
- console.log('Mining transaction...')
|
|
|
- // Waiting for the transaction to be mined
|
|
|
- const receipt = await tx.wait()
|
|
|
- console.log('Transaction mined!', receipt)
|
|
|
+ return new Web3Result(account.address, tx.hash, web3Config[account.network], false)
|
|
|
}
|
|
|
|
|
|
async orbiterWithdraw(accountId, amount) {
|
|
|
- throw new Error('Method not implemented.')
|
|
|
+ const account = await this.accountService.findById(accountId)
|
|
|
+ const provider = new ethers.providers.InfuraProvider(
|
|
|
+ web3Config[account.network].ethereumNetwork,
|
|
|
+ web3Config[account.network].infuraApiKey
|
|
|
+ )
|
|
|
+ const wallet = new ethers.Wallet(account.privateKey, provider)
|
|
|
+ const tx = await wallet.sendTransaction({
|
|
|
+ from: wallet.address,
|
|
|
+ to: web3Config[account.network].orbiterZkAddress,
|
|
|
+ value: ethers.utils.parseEther(amount).add(web3Config[account.network].orbiterIdCodeEth)
|
|
|
+ })
|
|
|
+ return new Web3Result(account.address, tx.hash, web3Config[account.network], true)
|
|
|
}
|
|
|
|
|
|
async addLiquidity(accountId, amount) {
|
|
|
@@ -221,6 +234,7 @@ export class Web3Service {
|
|
|
gasLimit
|
|
|
})
|
|
|
console.log('tx: ', tx)
|
|
|
+ return new Web3Result(account.address, tx.hash, web3Config[account.network], true)
|
|
|
}
|
|
|
|
|
|
async removeLiquidity(accountId) {
|
|
|
@@ -288,6 +302,7 @@ export class Web3Service {
|
|
|
gasLimit
|
|
|
})
|
|
|
console.log('decLiquidityCalling tx: ', JSON.stringify(tx0, null, 4))
|
|
|
+ return new Web3Result(account.address, tx0.hash, web3Config[account.network], true)
|
|
|
}
|
|
|
|
|
|
async allowance(tokenAddress, spender, wallet: Wallet, network: Network): Promise<number> {
|
|
|
@@ -391,6 +406,7 @@ export class Web3Service {
|
|
|
gasLimit
|
|
|
})
|
|
|
console.log(tx)
|
|
|
+ return new Web3Result(account.address, tx.hash, web3Config[account.network], true)
|
|
|
}
|
|
|
|
|
|
async swapWithExactInput(accountId, amount) {
|
|
|
@@ -454,6 +470,7 @@ export class Web3Service {
|
|
|
gasLimit
|
|
|
})
|
|
|
console.log(JSON.stringify(tx, null, 4))
|
|
|
+ return new Web3Result(account.address, tx.hash, web3Config[account.network], true)
|
|
|
}
|
|
|
|
|
|
async mint(accountId) {
|
|
|
@@ -477,5 +494,6 @@ export class Web3Service {
|
|
|
gasLimit
|
|
|
})
|
|
|
console.log(tx)
|
|
|
+ return new Web3Result(account.address, tx.hash, web3Config[account.network], true)
|
|
|
}
|
|
|
}
|