Skip to content

Commit

Permalink
feat: dont withdraw unless there is eth to withdraw
Browse files Browse the repository at this point in the history
  • Loading branch information
eccentricexit committed May 18, 2020
1 parent 3eec8a0 commit 71b70f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/types/enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum PARTY {
NONE,
REQUESTER,
CHALLENGER
}
13 changes: 10 additions & 3 deletions src/utils/withdraw-rewards.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ethers } from "ethers"
import { BigNumber } from "ethers/utils"
import { BigNumber, bigNumberify } from "ethers/utils"
import Store from "./store"
import { PARTY } from "../types/enums"

export default async function withdrawRewardsRemoveWatchlist(
itemID: string,
Expand Down Expand Up @@ -32,10 +33,14 @@ export default async function withdrawRewardsRemoveWatchlist(
// for the same contributor more than once by using a set.
const done = new Set()
let nonce = (await signer.getTransactionCount())
let withdrewRewards
for (let contributionEvent of contributionEvents) {
const { values: { _contributor, itemID, _request } } = contributionEvent
const { values: { _contributor, _request, _round, _itemID } } = contributionEvent
if (done.has(_contributor)) return

const contributions = await tcr.getContributions(_itemID, _request, _round, _contributor)
if (contributions[PARTY.REQUESTER].eq(bigNumberify(0)) && contributions[PARTY.CHALLENGER].eq(bigNumberify(0))) continue

console.info(` Withdrawing ${_contributor} rewards for item ${itemID} of TCR at ${tcr.address}`.cyan)
await batchWithdraw.batchRoundWithdraw(
tcr.address,
Expand All @@ -46,11 +51,13 @@ export default async function withdrawRewardsRemoveWatchlist(
0,
{ nonce }
)
withdrewRewards = true

nonce++
done.add(_contributor)
}

await store.removeFromWatchlist(tcr.address, itemID)
console.info(` Removed item ${itemID} of TCR at ${tcr.address} from watchlist.`.cyan)
if (withdrewRewards)
console.info(` Removed item ${itemID} of TCR at ${tcr.address} from watchlist.`.cyan)
}

0 comments on commit 71b70f8

Please sign in to comment.