-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathevent-controller.ts
92 lines (79 loc) · 3.64 KB
/
event-controller.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import config from '../../config';
import { BalancerSubgraphService } from '../subgraphs/balancer-subgraph/balancer-subgraph.service';
import { getV2SubgraphClient } from '../subgraphs/balancer-subgraph';
import { syncJoinExits as syncJoinExitsV2 } from '../actions/pool/v2/sync-join-exits';
import { syncJoinExits as syncJoinExitsV3 } from '../actions/pool/v3/sync-join-exits';
import { syncSwaps as syncSwapsV2, syncSwapsForLast48Hours } from '../actions/pool/v2/sync-swaps';
import { syncSwaps as syncSwapsV3 } from '../actions/pool/v3/sync-swaps';
import { Chain } from '@prisma/client';
import { updateVolumeAndFees } from '../actions/pool/update-volume-and-fees';
import { getVaultSubgraphClient } from '../sources/subgraphs/balancer-v3-vault';
import { handleSubgraphErrors } from './error-handling';
export function EventController() {
return {
async syncJoinExitsV2(chain: Chain) {
const {
subgraphs: { balancer },
} = config[chain];
// Guard against unconfigured chains
if (!balancer) {
throw new Error(`Chain not configured: ${chain}`);
}
const subgraphClient = new BalancerSubgraphService(balancer, chain);
return handleSubgraphErrors(() => syncJoinExitsV2(subgraphClient, chain));
},
async syncSwapsUpdateVolumeAndFeesV2(chain: Chain) {
const {
subgraphs: { balancer },
} = config[chain];
// Guard against unconfigured chains
if (!balancer) {
throw new Error(`Chain not configured: ${chain}`);
}
const subgraphClient = getV2SubgraphClient(balancer, chain);
return handleSubgraphErrors(async () => {
const poolsWithNewSwaps = await syncSwapsV2(subgraphClient, chain);
await syncSwapsForLast48Hours(subgraphClient, chain);
await updateVolumeAndFees(chain, poolsWithNewSwaps);
return poolsWithNewSwaps;
});
},
async syncJoinExitsV3(chain: Chain) {
const {
subgraphs: { balancerV3 },
} = config[chain];
// Guard against unconfigured chains
if (!balancerV3) {
throw new Error(`Chain not configured: ${chain}`);
}
const vaultSubgraphClient = getVaultSubgraphClient(balancerV3, chain);
return handleSubgraphErrors(() => syncJoinExitsV3(vaultSubgraphClient, chain));
},
async syncSwapsV3(chain: Chain) {
const {
subgraphs: { balancerV3 },
} = config[chain];
// Guard against unconfigured chains
if (!balancerV3) {
throw new Error(`Chain not configured: ${chain}`);
}
const vaultSubgraphClient = getVaultSubgraphClient(balancerV3, chain);
return handleSubgraphErrors(() => syncSwapsV3(vaultSubgraphClient, chain));
},
async syncSwapsUpdateVolumeAndFeesV3(chain: Chain) {
const {
subgraphs: { balancerV3 },
} = config[chain];
// Guard against unconfigured chains
if (!balancerV3) {
throw new Error(`Chain not configured: ${chain}`);
}
const vaultSubgraphClient = getVaultSubgraphClient(balancerV3, chain);
return handleSubgraphErrors(async () => {
const poolsWithNewSwaps = await syncSwapsV3(vaultSubgraphClient, chain);
await updateVolumeAndFees(chain, poolsWithNewSwaps);
return poolsWithNewSwaps;
});
},
};
}