Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
kaihirota committed Feb 16, 2024
1 parent 551427d commit 7b39e17
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions src/workflows/workflows.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Signer } from '@ethersproject/abstract-signer';
import {
DepositsApi,
EncodingApi,
Expand Down Expand Up @@ -68,9 +67,11 @@ import { createTradeWorkflow } from './trades';
import { generateIMXAuthorisationHeaders } from '../utils';
import { ImmutableXConfiguration } from '../config';
import { exchangeTransfersWorkflow } from './exchangeTransfers';
import { getWithdrawalBalanceWorkflow } from './withdrawal/getBalance';
import axios, { AxiosResponse } from 'axios';
import { BigNumber } from 'ethers';
import { Signer } from '@ethersproject/abstract-signer';
import { TransactionResponse } from '@ethersproject/providers';
import { getWithdrawalBalanceWorkflow } from './withdrawal/getBalance';

export class Workflows {
private readonly depositsApi: DepositsApi;
Expand Down Expand Up @@ -319,9 +320,11 @@ export class Workflows {
);
}
} else if (majorContractVersion >= 4) {
const ethAddress = await walletConnection.ethSigner.getAddress();
return this.completeWithdrawalAll(
walletConnection,
starkPublicKey,
ethAddress,
token,
);
} else {
Expand All @@ -334,20 +337,13 @@ export class Workflows {
private async completeWithdrawalAll(
walletConnection: WalletConnection,
starkPublicKey: string,
ethAddress: string,
token: AnyToken,
): Promise<TransactionResponse> {
const ethAddress = await walletConnection.ethSigner.getAddress();
const v3Balance = await getWithdrawalBalanceWorkflow(
const { v3Balance, v4Balance } = await this.getWithdrawalBalances(
walletConnection.ethSigner,
starkPublicKey,
this.encodingApi,
this.config,
);
const v4Balance = await getWithdrawalBalanceWorkflow(
walletConnection.ethSigner,
ethAddress,
this.encodingApi,
this.config,
);

if (v3Balance.gt(0)) {
Expand Down Expand Up @@ -390,6 +386,26 @@ export class Workflows {
throw new Error('Nothing to withdraw');
}

private async getWithdrawalBalances(
signer: Signer,
starkPublicKey: string,
ethAddress: string,
): Promise<{ v3Balance: BigNumber; v4Balance: BigNumber }> {
const v3Balance = await getWithdrawalBalanceWorkflow(
signer,
starkPublicKey,
this.encodingApi,
this.config,
);
const v4Balance = await getWithdrawalBalanceWorkflow(
signer,
ethAddress,
this.encodingApi,
this.config,
);
return { v3Balance, v4Balance };
}

private async completeWithdrawalV2(
signer: Signer,
ownerKey: string,
Expand Down

0 comments on commit 7b39e17

Please sign in to comment.