|
|
@@ -35,6 +35,7 @@ import { getPoolContract, getPoolState, getPointDelta } from 'iziswap-sdk/lib/po
|
|
|
import { getQuoterContract, quoterSwapChainWithExactOutput } from 'iziswap-sdk/lib/quoter'
|
|
|
import { getSwapContract, getSwapChainWithExactOutputCall } from 'iziswap-sdk/lib/swap'
|
|
|
import mintSquareAbi from './mintSquareAbi.json'
|
|
|
+import { Network } from './network.enum'
|
|
|
|
|
|
@Injectable()
|
|
|
export class Web3Service {
|
|
|
@@ -71,7 +72,7 @@ export class Web3Service {
|
|
|
private readonly accountService: AccountsService
|
|
|
) {}
|
|
|
|
|
|
- async zkDeposit(accountId, amount, network: NetworkType) {
|
|
|
+ async zkDeposit(accountId, amount, network: Network) {
|
|
|
const account = await this.accountService.findById(accountId)
|
|
|
const provider = new Provider(this.config[network].zksyncRpcUrl)
|
|
|
const ethProvider = new ethers.providers.InfuraProvider(
|
|
|
@@ -102,7 +103,7 @@ export class Web3Service {
|
|
|
// Logger.log('finalizedEthBalance', ethers.utils.formatEther(finalizedEthBalance))
|
|
|
}
|
|
|
|
|
|
- async zkWidthdraw(accountId, amount, network: NetworkType) {
|
|
|
+ async zkWidthdraw(accountId, amount, network: Network) {
|
|
|
const account = await this.accountService.findById(accountId)
|
|
|
const provider = new Provider(this.config[network].zksyncRpcUrl)
|
|
|
const ethProvider = new ethers.providers.InfuraProvider(
|
|
|
@@ -133,7 +134,7 @@ export class Web3Service {
|
|
|
// Logger.log('finalizedEthBalance', ethers.utils.formatEther(finalizedEthBalance))
|
|
|
}
|
|
|
|
|
|
- async addLiquidity(accountId, amount, network: NetworkType) {
|
|
|
+ async addLiquidity(accountId, amount, network: Network) {
|
|
|
const chainId = this.config[network].ethereumNetwork == 'goerli' ? ChainId.ZkSyncAlphaTest : ChainId.ZkSyncEra
|
|
|
const account = await this.accountService.findById(accountId)
|
|
|
const provider = new Provider(this.config[network].zksyncRpcUrl)
|
|
|
@@ -225,7 +226,7 @@ export class Web3Service {
|
|
|
console.log('tx: ', tx)
|
|
|
}
|
|
|
|
|
|
- async removeLiquidity(accountId, network: NetworkType) {
|
|
|
+ async removeLiquidity(accountId, network: Network) {
|
|
|
const chainId = this.config[network].ethereumNetwork == 'goerli' ? ChainId.ZkSyncAlphaTest : ChainId.ZkSyncEra
|
|
|
const account = await this.accountService.findById(accountId)
|
|
|
const provider = new Provider(this.config[network].zksyncRpcUrl)
|
|
|
@@ -292,7 +293,7 @@ export class Web3Service {
|
|
|
console.log('decLiquidityCalling tx: ', JSON.stringify(tx0, null, 4))
|
|
|
}
|
|
|
|
|
|
- async allowance(tokenAddress, spender, wallet: Wallet, network: NetworkType): Promise<number> {
|
|
|
+ async allowance(tokenAddress, spender, wallet: Wallet, network: Network): Promise<number> {
|
|
|
const web3 = new Web3(new Web3.providers.HttpProvider(this.config[network].zksyncRpcUrl))
|
|
|
const tokenAContract = new web3.eth.Contract(erc20, tokenAddress)
|
|
|
// @ts-ignore
|
|
|
@@ -302,7 +303,7 @@ export class Web3Service {
|
|
|
return out as unknown as number
|
|
|
}
|
|
|
|
|
|
- async approve(tokenAddress, spender, wallet: Wallet, network: NetworkType) {
|
|
|
+ async approve(tokenAddress, spender, wallet: Wallet, network: Network) {
|
|
|
const allowance = await this.allowance(tokenAddress, spender, wallet, network)
|
|
|
if (allowance > 0) {
|
|
|
return
|
|
|
@@ -323,7 +324,7 @@ export class Web3Service {
|
|
|
console.log('approve tx: ', JSON.stringify(tx0, null, 4))
|
|
|
}
|
|
|
|
|
|
- async swapWithExactOutput(accountId, amount, network: NetworkType) {
|
|
|
+ async swapWithExactOutput(accountId, amount, network: Network) {
|
|
|
const account = await this.accountService.findById(accountId)
|
|
|
const chainId = this.config[network].ethereumNetwork == 'goerli' ? ChainId.ZkSyncAlphaTest : ChainId.ZkSyncEra
|
|
|
const chain = initialChainTable[chainId]
|
|
|
@@ -395,7 +396,7 @@ export class Web3Service {
|
|
|
console.log(tx)
|
|
|
}
|
|
|
|
|
|
- async mint(accountId, network: NetworkType) {
|
|
|
+ async mint(accountId, network: Network) {
|
|
|
const account = await this.accountService.findById(accountId)
|
|
|
const chainId = this.config[network].ethereumNetwork == 'goerli' ? ChainId.ZkSyncAlphaTest : ChainId.ZkSyncEra
|
|
|
const chain = initialChainTable[chainId]
|