Skip to content

Commit bf5d148

Browse files
committed
style: fix code styling
1 parent 5ab683b commit bf5d148

File tree

10 files changed

+380
-297
lines changed

10 files changed

+380
-297
lines changed

src/gtcr.ts

Lines changed: 216 additions & 169 deletions
Large diffs are not rendered by default.

src/handlers/index.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { ethers } from 'ethers'
1+
import { ethers } from "ethers";
22

3-
import requestSubmittedHandler from './request-submitted'
4-
import requestResolvedHandler from './request-resolved'
5-
import Store from '../utils/store'
3+
import requestSubmittedHandler from "./request-submitted";
4+
import requestResolvedHandler from "./request-resolved";
5+
import Store from "../utils/store";
66

77
async function addTCRListeners(
88
tcr: ethers.Contract,
@@ -13,10 +13,7 @@ async function addTCRListeners(
1313
signer: ethers.Wallet
1414
) {
1515
// Submissions and removal requests.
16-
tcr.on(
17-
tcr.filters.RequestSubmitted(),
18-
requestSubmittedHandler(store ,tcr)
19-
)
16+
tcr.on(tcr.filters.RequestSubmitted(), requestSubmittedHandler(store, tcr));
2017

2118
// Request resolved.
2219
tcr.on(
@@ -29,9 +26,9 @@ async function addTCRListeners(
2926
store,
3027
signer
3128
)
32-
)
29+
);
3330

34-
console.info(`Setup listeners for ${tcr.address}`)
31+
console.info(`Setup listeners for ${tcr.address}`);
3532
}
3633

37-
export { addTCRListeners }
34+
export { addTCRListeners };

src/handlers/request-resolved.ts

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
1-
import { BigNumber, ethers } from "ethers"
2-
import withdrawRewardsRemoveWatchlist from "../utils/withdraw-rewards"
3-
import Store from "../utils/store"
1+
import { BigNumber, ethers } from "ethers";
2+
import withdrawRewardsRemoveWatchlist from "../utils/withdraw-rewards";
3+
import Store from "../utils/store";
44

55
/**
66
* Builds a handler for request resolved events (or rather, ItemStatusChange events with resolved value set to true.)
77
*/
88
export default (
9-
tcr: ethers.Contract,
10-
batchWithdraw: ethers.Contract,
11-
intervals: BlockInterval[],
12-
provider: ethers.providers.Provider,
13-
store: Store,
14-
signer: ethers.Wallet
15-
) => async (
16-
itemID: string,
17-
requestIndex: BigNumber,
18-
_roundIndex: BigNumber,
19-
disputed: boolean,
20-
_resolved: boolean
21-
) => {
22-
if (!_resolved) return
9+
tcr: ethers.Contract,
10+
batchWithdraw: ethers.Contract,
11+
intervals: BlockInterval[],
12+
provider: ethers.providers.Provider,
13+
store: Store,
14+
signer: ethers.Wallet
15+
) =>
16+
async (
17+
itemID: string,
18+
requestIndex: BigNumber,
19+
_roundIndex: BigNumber,
20+
disputed: boolean,
21+
_resolved: boolean
22+
) => {
23+
if (!_resolved) return;
2324

24-
console.info('')
25-
console.info(`Request executed for item ${itemID} of TCR at ${tcr.address}`)
25+
console.info("");
26+
console.info(
27+
`Request executed for item ${itemID} of TCR at ${tcr.address}`
28+
);
2629
if (disputed) {
2730
await withdrawRewardsRemoveWatchlist(
2831
itemID,
@@ -33,6 +36,6 @@ export default (
3336
provider,
3437
store,
3538
signer
36-
)
39+
);
3740
}
38-
}
41+
};

src/handlers/request-submitted.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
import { BigNumber, ethers } from "ethers"
2-
import Store from "../utils/store"
1+
import { BigNumber, ethers } from "ethers";
2+
import Store from "../utils/store";
33

44
/**
55
* Builds a handler for request submitted events.
66
*/
7-
export default (store: Store, tcr: ethers.Contract) => async (
8-
itemID: string,
9-
requestIndex: BigNumber
10-
) => {
11-
const challengePeriodDuration = await tcr.challengePeriodDuration()
12-
const { submissionTime } = await tcr.getRequestInfo(itemID, requestIndex)
7+
export default (store: Store, tcr: ethers.Contract) =>
8+
async (itemID: string, requestIndex: BigNumber) => {
9+
const challengePeriodDuration = await tcr.challengePeriodDuration();
10+
const { submissionTime } = await tcr.getRequestInfo(itemID, requestIndex);
1311

14-
// Save the end the challenge period on local storage.
15-
await store.addToWatchlist(
16-
tcr.address,
17-
itemID,
18-
submissionTime.add(challengePeriodDuration).toNumber()
19-
)
12+
// Save the end the challenge period on local storage.
13+
await store.addToWatchlist(
14+
tcr.address,
15+
itemID,
16+
submissionTime.add(challengePeriodDuration).toNumber()
17+
);
2018

21-
console.info('')
22-
console.info(`New request! Added item ${itemID} of TCR at ${tcr.address} to watchlist`.cyan)
23-
}
19+
console.info("");
20+
console.info(
21+
`New request! Added item ${itemID} of TCR at ${tcr.address} to watchlist`
22+
.cyan
23+
);
24+
};

src/types/enums.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export enum PARTY {
22
NONE,
33
REQUESTER,
4-
CHALLENGER
5-
}
4+
CHALLENGER,
5+
}

src/types/environment.d.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import 'typescript'
1+
import "typescript";
22

33
declare global {
44
namespace NodeJS {
55
interface ProcessEnv {
6-
FACTORY_ADDRESS: string
7-
PROVIDER_URL: string
8-
BLOCK_TIME_SECONDS: string
9-
WALLET_KEY: string
10-
BATCH_WITHDRAW_ADDRESS: string,
11-
POLL_PERIOD_MINUTES: string,
12-
LFACTORY_ADDRESS: string,
13-
LBATCH_WITHDRAW_ADDRESS: string
14-
GTCR_SUBGRAPH_URL: string
6+
FACTORY_ADDRESS: string;
7+
PROVIDER_URL: string;
8+
BLOCK_TIME_SECONDS: string;
9+
WALLET_KEY: string;
10+
BATCH_WITHDRAW_ADDRESS: string;
11+
POLL_PERIOD_MINUTES: string;
12+
LFACTORY_ADDRESS: string;
13+
LBATCH_WITHDRAW_ADDRESS: string;
14+
GTCR_SUBGRAPH_URL: string;
1515
}
1616
}
1717
}

src/types/global.d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
declare module 'level'
2-
declare module 'node-fetch'
1+
declare module "level";
2+
declare module "node-fetch";
33

44
interface BlockInterval {
5-
fromBlock: number
6-
toBlock: number
5+
fromBlock: number;
6+
toBlock: number;
77
}
88

99
interface Level {
10-
get: Function
11-
put: Function
12-
}
10+
get: Function;
11+
put: Function;
12+
}

src/utils/get-intervals.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default function (
88
fromBlock: number,
99
currentBlock: number,
1010
blocksPerRequest: number = 1000000
11-
) : BlockInterval[] {
11+
): BlockInterval[] {
1212
// Fetching event logs in a single request can (this was happening) cause
1313
// the provider to timeout the request.
1414
// To get around this we can split it into multiple, smaller requests.
@@ -18,8 +18,11 @@ export default function (
1818
for (let i = 1; i < numRequests; i++) {
1919
intervals[i] = {
2020
fromBlock: intervals[i - 1].toBlock + 1,
21-
toBlock: Math.min(intervals[i - 1].toBlock + 1 + blocksPerRequest, currentBlock),
21+
toBlock: Math.min(
22+
intervals[i - 1].toBlock + 1 + blocksPerRequest,
23+
currentBlock
24+
),
2225
};
2326
}
2427
return intervals;
25-
}
28+
}

src/utils/store.ts

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,56 @@
11
// Wrap level.get and level.put to parse and stringify JSON values.
22
export default class Store {
3-
private readonly db: Level
4-
private readonly key: string
3+
private readonly db: Level;
4+
private readonly key: string;
55
constructor(db: Level, key: string) {
6-
this.db = db
7-
this.key = key
6+
this.db = db;
7+
this.key = key;
88
}
99

10-
async getDB () {
11-
let dbState: { [tcrAddress: string]: {[itemID: string]: number} } = {}
10+
async getDB() {
11+
let dbState: { [tcrAddress: string]: { [itemID: string]: number } } = {};
1212
try {
13-
dbState = JSON.parse(await this.db.get(this.key))
13+
dbState = JSON.parse(await this.db.get(this.key));
1414
} catch (err) {
15-
if (err.type !== 'NotFoundError') throw new Error(err)
15+
if (err.type !== "NotFoundError") throw new Error(err);
1616
// No-op, we just return an empty object which will be
1717
// saved on put.
1818
}
19-
return dbState
19+
return dbState;
2020
}
2121

22-
async addToWatchlist (tcrAddress: string, itemID: string, challengePeriodEnd: number) {
23-
const tcrState = await this.getTCR(tcrAddress)
24-
tcrState[itemID] = challengePeriodEnd
25-
await this.putTCR(tcrAddress, tcrState)
22+
async addToWatchlist(
23+
tcrAddress: string,
24+
itemID: string,
25+
challengePeriodEnd: number
26+
) {
27+
const tcrState = await this.getTCR(tcrAddress);
28+
tcrState[itemID] = challengePeriodEnd;
29+
await this.putTCR(tcrAddress, tcrState);
2630
}
2731

28-
async removeFromWatchlist (tcrAddress: string, itemID: string) {
29-
const tcrState = await this.getTCR(tcrAddress)
30-
delete tcrState[itemID]
31-
await this.putTCR(tcrAddress, tcrState)
32+
async removeFromWatchlist(tcrAddress: string, itemID: string) {
33+
const tcrState = await this.getTCR(tcrAddress);
34+
delete tcrState[itemID];
35+
await this.putTCR(tcrAddress, tcrState);
3236
}
3337

34-
private async putDB (dbState: object) { this.db.put(this.key, JSON.stringify(dbState)) }
35-
36-
private async getTCR (tcrAddress: string){
37-
const dbState: { [tcrAddress: string]: { [itemID: string]: number} } = await this.getDB()
38-
return dbState[tcrAddress] || {}
38+
private async putDB(dbState: object) {
39+
this.db.put(this.key, JSON.stringify(dbState));
3940
}
4041

41-
private async putTCR (tcrAddress: string, tcrState: {[tcrAddress: string]: number}) {
42-
const dbState = await this.getDB()
43-
dbState[tcrAddress] = tcrState
44-
await this.putDB(dbState)
42+
private async getTCR(tcrAddress: string) {
43+
const dbState: { [tcrAddress: string]: { [itemID: string]: number } } =
44+
await this.getDB();
45+
return dbState[tcrAddress] || {};
4546
}
4647

48+
private async putTCR(
49+
tcrAddress: string,
50+
tcrState: { [tcrAddress: string]: number }
51+
) {
52+
const dbState = await this.getDB();
53+
dbState[tcrAddress] = tcrState;
54+
await this.putDB(dbState);
55+
}
4756
}

0 commit comments

Comments
 (0)