Skip to content

Commit

Permalink
Feature/challenge bug (#430)
Browse files Browse the repository at this point in the history
* subgraph fixed

* fix challenge bug if token addresses are the same
  • Loading branch information
novaknole authored Jul 7, 2021
1 parent a53bf16 commit 26d61bb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
35 changes: 22 additions & 13 deletions packages/govern-console/src/services/QueueApprovals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { TokenDeposit } from '@aragon/govern';
import { erc20ApprovalTransaction } from 'utils/transactionHelper';
import { CustomTransaction } from 'utils/types';
import { Account } from 'utils/types';
import { toBigNum } from 'utils/lib';

export default class QueueApprovals {
constructor(private account: Account, private queue: string, private resolver: string) {}
Expand Down Expand Up @@ -41,36 +42,44 @@ export default class QueueApprovals {
public async challengeApprovals(tokenDeposit: TokenDeposit) {
let transactionsQueue: CustomTransaction[] = [];

const contract = new ethers.Contract(this.resolver, CourtABI, this.account.signer);
const resolver = new ethers.Contract(this.resolver, CourtABI, this.account.signer);
const [, feeToken, feeAmount] = await resolver.getDisputeFees();

let approvalTransactions = [];

// add approval transaction for the challenge deposit token
try {
const approvalTransactions = await erc20ApprovalTransaction(
// if equal, we need to approve only one time...
if (feeToken.toLowerCase() === tokenDeposit.token.toLowerCase()) {
approvalTransactions = await erc20ApprovalTransaction(
feeToken,
toBigNum(tokenDeposit.amount).add(feeAmount),
this.queue,
this.account,
);
return [...approvalTransactions];
}

// add approval transaction for the challenge deposit token
approvalTransactions = await erc20ApprovalTransaction(
tokenDeposit.token,
tokenDeposit.amount,
this.queue,
this.account,
);

transactionsQueue = [...transactionsQueue, ...approvalTransactions];
} catch (error) {
throw new Error(error);
}

// add approval transaction for the fee token from the aragon's court
const [, feeToken, feeAmount] = await contract.getDisputeFees();
try {
const approvalTransactions = await erc20ApprovalTransaction(
// add approval transaction for the fee token from the aragon's court
approvalTransactions = await erc20ApprovalTransaction(
feeToken,
feeAmount,
this.queue,
this.account,
);
transactionsQueue = [...transactionsQueue, ...approvalTransactions];

return transactionsQueue;
} catch (error) {
throw new Error(error);
}

return transactionsQueue;
}
}
4 changes: 4 additions & 0 deletions packages/govern-console/src/utils/lib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ export function formatUnits(amount: BigNumberish, decimals: number) {
export function parseUnits(amount: BigNumberish, decimals: number) {
return ethers.utils.parseUnits(amount.toString(), decimals);
}

export function toBigNum(value: BigNumberish) {
return ethers.BigNumber.from(value);
}
7 changes: 4 additions & 3 deletions packages/govern-console/src/utils/transactionHelper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { BigNumberish } from '@ethersproject/bignumber';
import { Account } from 'utils/types';
import { getTokenInfo } from 'utils/token';
import { formatUnits } from 'utils/lib';
import { toBigNum } from 'utils/lib';

/**
* @param token address of the token
Expand All @@ -26,12 +27,12 @@ export async function erc20ApprovalTransaction(
return [];
}

const amountInBigNumber: BigNumber = ethers.BigNumber.from(amount);
const amountInBigNumber: BigNumber = toBigNum(amount);

const contract = new ethers.Contract(token, erc20TokenABI, account.signer);

let allowance: BigNumber = ethers.BigNumber.from(0);
let userBalance: BigNumber = ethers.BigNumber.from(0);
let allowance: BigNumber = toBigNum(0);
let userBalance: BigNumber = toBigNum(0);
let amountForHuman: string = amount.toString();

const tokenInfo = await getTokenInfo(token, account.signer);
Expand Down

0 comments on commit 26d61bb

Please sign in to comment.