Skip to content
This repository was archived by the owner on Jan 24, 2024. It is now read-only.

Commit 0fe14c8

Browse files
authored
feat(dopex): add voting escrow (#1080)
1 parent dec19e9 commit 0fe14c8

13 files changed

+4783
-8
lines changed

src/apps/dopex/arbitrum/dopex.balance-fetcher.ts

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Web3 from 'web3';
55
import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface';
66
import { Register } from '~app-toolkit/decorators';
77
import { presentBalanceFetcherResponse } from '~app-toolkit/helpers/presentation/balance-fetcher-response.present';
8+
import { CurveVotingEscrowContractPositionBalanceHelper } from '~apps/curve/helpers/curve.voting-escrow.contract-position-balance-helper';
89
import { BalanceFetcher } from '~balance/balance-fetcher.interface';
910
import { Network } from '~types/network.interface';
1011

@@ -16,15 +17,18 @@ import {
1617
DopexGOhmSsov,
1718
DopexRdpxSsov,
1819
DopexStaking,
20+
DopexVotingEscrow,
21+
DopexVotingEscrowRewards,
1922
} from '../contracts';
2023
import { DOPEX_DEFINITION } from '../dopex.definition';
2124
import { DopexSsovClaimableBalancesStrategy } from '../helpers/dopex.ssov.claimable-balances-strategy';
2225
import { DopexSsovContractPositionBalanceHelper } from '../helpers/dopex.ssov.contract-position-balance-helper';
2326
import { DopexSsovDepositBalanceStrategy } from '../helpers/dopex.ssov.deposit-balance-strategy';
2427

2528
const network = Network.ARBITRUM_MAINNET;
29+
const appId = DOPEX_DEFINITION.id;
2630

27-
@Register.BalanceFetcher(DOPEX_DEFINITION.id, network)
31+
@Register.BalanceFetcher(appId, network)
2832
export class ArbitrumDopexBalanceFetcher implements BalanceFetcher {
2933
constructor(
3034
@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit,
@@ -36,13 +40,15 @@ export class ArbitrumDopexBalanceFetcher implements BalanceFetcher {
3640
private readonly dopexSsovDepositBalanceStrategy: DopexSsovDepositBalanceStrategy,
3741
@Inject(DopexSsovClaimableBalancesStrategy)
3842
private readonly dopexSsovClaimableBalancesStrategy: DopexSsovClaimableBalancesStrategy,
43+
@Inject(CurveVotingEscrowContractPositionBalanceHelper)
44+
private readonly curveVotingEscrowContractPositionBalanceHelper: CurveVotingEscrowContractPositionBalanceHelper,
3945
) {}
4046

4147
private async getSsovBalances(address: string) {
4248
return Promise.all([
4349
this.dopexSsovContractPositionBalanceHelper.getBalances<DopexDpxSsov>({
4450
address,
45-
appId: DOPEX_DEFINITION.id,
51+
appId,
4652
groupId: DOPEX_DEFINITION.groups.dpxSsov.id,
4753
network,
4854
resolveSsovContract: ({ address, network }) => this.dopexContractFactory.dopexDpxSsov({ address, network }),
@@ -61,7 +67,7 @@ export class ArbitrumDopexBalanceFetcher implements BalanceFetcher {
6167
}),
6268
this.dopexSsovContractPositionBalanceHelper.getBalances<DopexRdpxSsov>({
6369
address,
64-
appId: DOPEX_DEFINITION.id,
70+
appId,
6571
groupId: DOPEX_DEFINITION.groups.rdpxSsov.id,
6672
network,
6773
resolveSsovContract: ({ address, network }) => this.dopexContractFactory.dopexRdpxSsov({ address, network }),
@@ -80,7 +86,7 @@ export class ArbitrumDopexBalanceFetcher implements BalanceFetcher {
8086
}),
8187
this.dopexSsovContractPositionBalanceHelper.getBalances<DopexEthSsov>({
8288
address,
83-
appId: DOPEX_DEFINITION.id,
89+
appId,
8490
groupId: DOPEX_DEFINITION.groups.ethSsov.id,
8591
network,
8692
resolveSsovContract: ({ address, network }) => this.dopexContractFactory.dopexEthSsov({ address, network }),
@@ -109,7 +115,7 @@ export class ArbitrumDopexBalanceFetcher implements BalanceFetcher {
109115
}),
110116
this.dopexSsovContractPositionBalanceHelper.getBalances<DopexGOhmSsov>({
111117
address,
112-
appId: DOPEX_DEFINITION.id,
118+
appId,
113119
groupId: DOPEX_DEFINITION.groups.gohmSsov.id,
114120
network,
115121
resolveSsovContract: ({ address, network }) => this.dopexContractFactory.dopexGOhmSsov({ address, network }),
@@ -122,7 +128,7 @@ export class ArbitrumDopexBalanceFetcher implements BalanceFetcher {
122128
}),
123129
this.dopexSsovContractPositionBalanceHelper.getBalances<DopexGmxSsov>({
124130
address,
125-
appId: DOPEX_DEFINITION.id,
131+
appId,
126132
groupId: DOPEX_DEFINITION.groups.gmxSsov.id,
127133
network,
128134
resolveSsovContract: ({ address, network }) => this.dopexContractFactory.dopexGmxSsov({ address, network }),
@@ -157,7 +163,7 @@ export class ArbitrumDopexBalanceFetcher implements BalanceFetcher {
157163
private async getStakedBalances(address: string) {
158164
return this.appToolkit.helpers.singleStakingContractPositionBalanceHelper.getBalances<DopexStaking>({
159165
address,
160-
appId: DOPEX_DEFINITION.id,
166+
appId,
161167
groupId: DOPEX_DEFINITION.groups.farm.id,
162168
network,
163169
resolveContract: ({ address, network }) => this.dopexContractFactory.dopexStaking({ address, network }),
@@ -170,10 +176,31 @@ export class ArbitrumDopexBalanceFetcher implements BalanceFetcher {
170176
});
171177
}
172178

179+
private async getVotingEscrowBalances(address: string) {
180+
return this.curveVotingEscrowContractPositionBalanceHelper.getBalances<DopexVotingEscrow, DopexVotingEscrowRewards>(
181+
{
182+
address,
183+
appId,
184+
groupId: DOPEX_DEFINITION.groups.votingEscrow.id,
185+
network,
186+
resolveContract: ({ address }) => this.dopexContractFactory.dopexVotingEscrow({ network, address }),
187+
resolveRewardContract: ({ address }) =>
188+
this.dopexContractFactory.dopexVotingEscrowRewards({ network, address }),
189+
resolveLockedTokenBalance: ({ contract, multicall }) =>
190+
multicall
191+
.wrap(contract)
192+
.locked(address)
193+
.then(v => v.amount),
194+
resolveRewardTokenBalance: ({ contract, multicall }) => multicall.wrap(contract).earned(address),
195+
},
196+
);
197+
}
198+
173199
async getBalances(address: string) {
174-
const [ssovBalances, stakedBalances] = await Promise.all([
200+
const [ssovBalances, stakedBalances, votingEscrowBalances] = await Promise.all([
175201
this.getSsovBalances(address),
176202
this.getStakedBalances(address),
203+
this.getVotingEscrowBalances(address),
177204
]);
178205

179206
return presentBalanceFetcherResponse([
@@ -185,6 +212,10 @@ export class ArbitrumDopexBalanceFetcher implements BalanceFetcher {
185212
label: 'Staking',
186213
assets: [...stakedBalances],
187214
},
215+
{
216+
label: 'Voting Escrow',
217+
assets: votingEscrowBalances,
218+
},
188219
]);
189220
}
190221
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { Inject } from '@nestjs/common';
2+
3+
import { Register } from '~app-toolkit/decorators';
4+
import { CurveVotingEscrowContractPositionHelper } from '~apps/curve/helpers/curve.voting-escrow.contract-position-helper';
5+
import { PositionFetcher } from '~position/position-fetcher.interface';
6+
import { ContractPosition } from '~position/position.interface';
7+
import { Network } from '~types/network.interface';
8+
9+
import { DopexContractFactory, DopexVotingEscrow, DopexVotingEscrowRewards } from '../contracts';
10+
import { DOPEX_DEFINITION } from '../dopex.definition';
11+
12+
const appId = DOPEX_DEFINITION.id;
13+
const groupId = DOPEX_DEFINITION.groups.votingEscrow.id;
14+
const network = Network.ARBITRUM_MAINNET;
15+
16+
@Register.ContractPositionFetcher({ appId, groupId, network })
17+
export class ArbitrumDopexVotingEscrowContractPositionFetcher implements PositionFetcher<ContractPosition> {
18+
constructor(
19+
@Inject(DopexContractFactory)
20+
private readonly dopexContractFactory: DopexContractFactory,
21+
@Inject(CurveVotingEscrowContractPositionHelper)
22+
private readonly curveVotingEscrowContractPositionHelper: CurveVotingEscrowContractPositionHelper,
23+
) {}
24+
25+
async getPositions() {
26+
return this.curveVotingEscrowContractPositionHelper.getContractPositions<
27+
DopexVotingEscrow,
28+
DopexVotingEscrowRewards
29+
>({
30+
votingEscrowAddress: '0x80789d252a288e93b01d82373d767d71a75d9f16',
31+
votingEscrowRewardAddress: '0xcbbfb7e0e6782df0d3e91f8d785a5bf9e8d9775f',
32+
appId,
33+
groupId,
34+
network,
35+
resolveContract: ({ address }) => this.dopexContractFactory.dopexVotingEscrow({ network, address }),
36+
resolveRewardContract: ({ address }) => this.dopexContractFactory.dopexVotingEscrowRewards({ network, address }),
37+
resolveLockedTokenAddress: ({ contract, multicall }) => multicall.wrap(contract).token(),
38+
resolveRewardTokenAddress: ({ contract, multicall }) => multicall.wrap(contract).emittedToken(),
39+
});
40+
}
41+
}

0 commit comments

Comments
 (0)