@gearbox-protocol/sdk 3.0.0-next.121 → 3.0.0-next.122
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/apy/auraAPY.d.ts +1 -0
- package/lib/apy/auraAPY.js +23 -0
- package/lib/apy/auraAbi.d.ts +17 -0
- package/lib/apy/auraAbi.js +26 -0
- package/lib/core/rewardClaimer.d.ts +4 -2
- package/lib/core/rewardConvex.d.ts +26 -9
- package/lib/core/rewardConvex.js +183 -56
- package/lib/core/rewardConvex.spec.js +32 -68
- package/lib/parsers/convexBaseRewardPoolAdapterParser.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getAURAMintAmount(amount: bigint, totalSupply: bigint, multiplier: bigint): bigint;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAURAMintAmount = void 0;
|
|
4
|
+
const CVX_MAX_SUPPLY = 50000000000000000000000000n;
|
|
5
|
+
const CVX_REDUCTION_PER_CLIFF = 100000000000000000000000n;
|
|
6
|
+
const CVX_TOTAL_CLIFFS = 500n;
|
|
7
|
+
const INITIAL_SUPPLY = 5n * 10n ** 25n;
|
|
8
|
+
const INITIAL_CLIFFS = 700n;
|
|
9
|
+
function getAURAMintAmount(amount, totalSupply, multiplier) {
|
|
10
|
+
if (totalSupply <= 0n)
|
|
11
|
+
return 0n;
|
|
12
|
+
const effectiveAmount = (amount * multiplier) / 10000n;
|
|
13
|
+
const emissionMinted = totalSupply - INITIAL_SUPPLY;
|
|
14
|
+
const cliff = emissionMinted / CVX_REDUCTION_PER_CLIFF;
|
|
15
|
+
if (cliff < CVX_TOTAL_CLIFFS) {
|
|
16
|
+
const reduction = INITIAL_CLIFFS + ((CVX_TOTAL_CLIFFS - cliff) * 5n) / 2n;
|
|
17
|
+
const mintedAmount = (effectiveAmount * reduction) / CVX_TOTAL_CLIFFS;
|
|
18
|
+
const amountTillMax = CVX_MAX_SUPPLY - emissionMinted;
|
|
19
|
+
return mintedAmount > amountTillMax ? amountTillMax : mintedAmount;
|
|
20
|
+
}
|
|
21
|
+
return 0n;
|
|
22
|
+
}
|
|
23
|
+
exports.getAURAMintAmount = getAURAMintAmount;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Interface } from "ethers/lib/utils";
|
|
2
|
+
export declare const AURA_BOOSTER_ABI: {
|
|
3
|
+
inputs: {
|
|
4
|
+
internalType: string;
|
|
5
|
+
name: string;
|
|
6
|
+
type: string;
|
|
7
|
+
}[];
|
|
8
|
+
name: string;
|
|
9
|
+
outputs: {
|
|
10
|
+
internalType: string;
|
|
11
|
+
name: string;
|
|
12
|
+
type: string;
|
|
13
|
+
}[];
|
|
14
|
+
stateMutability: string;
|
|
15
|
+
type: string;
|
|
16
|
+
}[];
|
|
17
|
+
export declare const AURA_BOOSTER_INTERFACE: Interface;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AURA_BOOSTER_INTERFACE = exports.AURA_BOOSTER_ABI = void 0;
|
|
4
|
+
const utils_1 = require("ethers/lib/utils");
|
|
5
|
+
exports.AURA_BOOSTER_ABI = [
|
|
6
|
+
{
|
|
7
|
+
inputs: [
|
|
8
|
+
{
|
|
9
|
+
internalType: "address",
|
|
10
|
+
name: "input",
|
|
11
|
+
type: "address",
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
name: "getRewardMultipliers",
|
|
15
|
+
outputs: [
|
|
16
|
+
{
|
|
17
|
+
internalType: "uint256",
|
|
18
|
+
name: "multiplier",
|
|
19
|
+
type: "uint256",
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
stateMutability: "view",
|
|
23
|
+
type: "function",
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
exports.AURA_BOOSTER_INTERFACE = new utils_1.Interface(exports.AURA_BOOSTER_ABI);
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { NetworkType, SupportedContract, SupportedToken } from "@gearbox-protocol/sdk-gov";
|
|
1
|
+
import { NetworkType, PartialRecord, Protocols, SupportedContract, SupportedToken } from "@gearbox-protocol/sdk-gov";
|
|
2
2
|
import { providers } from "ethers";
|
|
3
3
|
import { MultiCall } from "../pathfinder/core";
|
|
4
4
|
import { CreditAccountData } from "./creditAccount";
|
|
5
5
|
import { CreditManagerData } from "./creditManager";
|
|
6
6
|
export interface Rewards {
|
|
7
7
|
contract: SupportedContract;
|
|
8
|
-
|
|
8
|
+
totalSupply: bigint;
|
|
9
|
+
protocol: Protocols.Aura | Protocols.Convex;
|
|
10
|
+
rewards: PartialRecord<SupportedToken, bigint>;
|
|
9
11
|
calls: Array<MultiCall>;
|
|
10
12
|
}
|
|
11
13
|
export interface AdapterWithType {
|
|
@@ -1,24 +1,41 @@
|
|
|
1
|
-
import { MCall, NetworkType,
|
|
1
|
+
import { MCall, NetworkType, Protocols, SupportedToken } from "@gearbox-protocol/sdk-gov";
|
|
2
2
|
import { BigNumber, providers } from "ethers";
|
|
3
|
+
import { Interface } from "ethers/lib/utils";
|
|
3
4
|
import { IBaseRewardPoolInterface } from "../types/IBaseRewardPool";
|
|
5
|
+
import { IConvexTokenInterface } from "../types/IConvexToken";
|
|
4
6
|
import { CreditAccountData } from "./creditAccount";
|
|
5
7
|
import { CreditManagerData } from "./creditManager";
|
|
6
8
|
import { AdapterWithType, Rewards } from "./rewardClaimer";
|
|
9
|
+
type DistributionList = Array<Array<RewardDistribution>>;
|
|
10
|
+
type CallsList = Array<Array<MCall<IConvexTokenInterface> | MCall<IBaseRewardPoolInterface> | MCall<Interface>>>;
|
|
7
11
|
export interface RewardDistribution {
|
|
12
|
+
contract: Rewards["contract"];
|
|
13
|
+
protocol: Rewards["protocol"];
|
|
14
|
+
token: SupportedToken;
|
|
8
15
|
adapter: string;
|
|
9
16
|
contractAddress: string;
|
|
10
|
-
contract: SupportedContract;
|
|
11
|
-
token: SupportedToken;
|
|
12
17
|
}
|
|
13
|
-
interface
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
interface ParseProps {
|
|
19
|
+
convexResponse: Array<BigNumber>;
|
|
20
|
+
convexDistribution: DistributionList;
|
|
21
|
+
convexTotalSupply: bigint;
|
|
22
|
+
auraResponse: Array<BigNumber>;
|
|
23
|
+
auraDistribution: DistributionList;
|
|
24
|
+
auraTotalSupply: bigint;
|
|
16
25
|
}
|
|
17
26
|
export declare class RewardConvex {
|
|
18
27
|
static poolInterface: IBaseRewardPoolInterface;
|
|
19
28
|
static findRewards(ca: CreditAccountData, cm: CreditManagerData, network: NetworkType, provider: providers.Provider): Promise<Array<Rewards>>;
|
|
20
|
-
static findAdapters(cm: CreditManagerData):
|
|
21
|
-
static prepareMultiCalls(creditAccount: string, cm: CreditManagerData, network: NetworkType):
|
|
22
|
-
|
|
29
|
+
static findAdapters(cm: CreditManagerData): AdapterWithType[];
|
|
30
|
+
static prepareMultiCalls(creditAccount: string, cm: CreditManagerData, network: NetworkType): {
|
|
31
|
+
convexDistribution: DistributionList;
|
|
32
|
+
auraDistribution: DistributionList;
|
|
33
|
+
convexCalls: CallsList;
|
|
34
|
+
auraCalls: CallsList;
|
|
35
|
+
};
|
|
36
|
+
static parseResults({ convexDistribution, convexResponse, convexTotalSupply, auraDistribution, auraResponse, auraTotalSupply, }: ParseProps): Array<Rewards>;
|
|
37
|
+
static getRewardObject(baseReward: bigint, baseDistribution: RewardDistribution, boostedRewardToken: SupportedToken, extraDistribution: Array<RewardDistribution>, rewardsResp: Array<BigNumber>, totalSupply: bigint, callData: string, multiplier: bigint): Rewards | undefined;
|
|
38
|
+
static getBaseRewardToken(protocol: Protocols): SupportedToken | undefined;
|
|
39
|
+
static getBBoostedRewardToken(protocol: Protocols): SupportedToken | undefined;
|
|
23
40
|
}
|
|
24
41
|
export {};
|
package/lib/core/rewardConvex.js
CHANGED
|
@@ -3,100 +3,227 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RewardConvex = void 0;
|
|
4
4
|
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
5
5
|
const apy_1 = require("../apy");
|
|
6
|
+
const auraAbi_1 = require("../apy/auraAbi");
|
|
7
|
+
const auraAPY_1 = require("../apy/auraAPY");
|
|
6
8
|
const types_1 = require("../types");
|
|
9
|
+
// convex[totalSupply, ...tokens] aura[totalSupply, multiplier, ...tokens]
|
|
7
10
|
class RewardConvex {
|
|
8
11
|
static poolInterface = types_1.IBaseRewardPool__factory.createInterface();
|
|
9
12
|
static async findRewards(ca, cm, network, provider) {
|
|
10
13
|
if (network !== "Mainnet")
|
|
11
14
|
return [];
|
|
12
|
-
const {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
const { auraCalls, auraDistribution, convexCalls, convexDistribution } = RewardConvex.prepareMultiCalls(ca.addr, cm, network);
|
|
16
|
+
const auraTotal = auraCalls.flat(1);
|
|
17
|
+
const convexTotal = convexCalls.flat(1);
|
|
18
|
+
const response = await (0, sdk_gov_1.multicall)([...auraTotal, ...convexTotal], provider);
|
|
19
|
+
const auraEnd = auraTotal.length;
|
|
20
|
+
const [auraTotalSupply, ...auraResponse] = response.slice(0, auraEnd);
|
|
21
|
+
const convexEnd = auraEnd + convexTotal.length;
|
|
22
|
+
const [convexTotalSupply, ...convexResponse] = response.slice(auraEnd, convexEnd);
|
|
23
|
+
const results = RewardConvex.parseResults({
|
|
24
|
+
auraDistribution,
|
|
25
|
+
auraResponse,
|
|
26
|
+
auraTotalSupply: (0, sdk_gov_1.toBigInt)(auraTotalSupply),
|
|
27
|
+
convexDistribution,
|
|
28
|
+
convexResponse,
|
|
29
|
+
convexTotalSupply: (0, sdk_gov_1.toBigInt)(convexTotalSupply),
|
|
24
30
|
});
|
|
25
31
|
return results;
|
|
26
32
|
}
|
|
27
33
|
static findAdapters(cm) {
|
|
28
|
-
const convexPools =
|
|
29
|
-
.filter(([_, params]) => params.type === sdk_gov_1.AdapterInterface.CONVEX_V1_BASE_REWARD_POOL)
|
|
30
|
-
.map(([contract]) => contract);
|
|
34
|
+
const convexPools = sdk_gov_1.TypedObjectUtils.fromEntries(sdk_gov_1.TypedObjectUtils.entries(sdk_gov_1.contractParams).filter(([, params]) => params.type === sdk_gov_1.AdapterInterface.CONVEX_V1_BASE_REWARD_POOL));
|
|
31
35
|
return Object.entries(cm.adapters)
|
|
36
|
+
.filter(([contract]) => !!convexPools[sdk_gov_1.contractsByAddress[contract.toLowerCase()]])
|
|
32
37
|
.map(([contract, adapter]) => ({
|
|
33
38
|
adapter,
|
|
34
39
|
contractAddress: contract,
|
|
35
40
|
contract: sdk_gov_1.contractsByAddress[contract.toLowerCase()],
|
|
36
|
-
}))
|
|
37
|
-
.filter(a => convexPools.includes(a.contract));
|
|
41
|
+
}));
|
|
38
42
|
}
|
|
39
43
|
static prepareMultiCalls(creditAccount, cm, network) {
|
|
40
|
-
const
|
|
41
|
-
const
|
|
44
|
+
const tokens = sdk_gov_1.tokenDataByNetwork[network];
|
|
45
|
+
const contracts = sdk_gov_1.contractsByNetwork[network];
|
|
42
46
|
const adapters = this.findAdapters(cm);
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
const res = adapters.reduce((acc, a) => {
|
|
48
|
+
const currentContract = sdk_gov_1.contractParams[a.contract];
|
|
49
|
+
const baseRewardToken = this.getBaseRewardToken(currentContract.protocol);
|
|
50
|
+
if (!baseRewardToken) {
|
|
51
|
+
throw new Error(`Unknown rewards protocol: ${currentContract.protocol}`);
|
|
52
|
+
}
|
|
53
|
+
const currentCalls = [
|
|
54
|
+
...(currentContract.protocol === sdk_gov_1.Protocols.Aura
|
|
55
|
+
? [
|
|
56
|
+
{
|
|
57
|
+
address: contracts.AURA_BOOSTER,
|
|
58
|
+
interface: auraAbi_1.AURA_BOOSTER_INTERFACE,
|
|
59
|
+
method: "getRewardMultipliers(address)",
|
|
60
|
+
params: [tokens[currentContract.stakedToken]],
|
|
61
|
+
},
|
|
62
|
+
]
|
|
63
|
+
: []),
|
|
64
|
+
];
|
|
65
|
+
const currentDistribution = [];
|
|
66
|
+
currentCalls.push({
|
|
45
67
|
address: a.contractAddress,
|
|
46
68
|
interface: RewardConvex.poolInterface,
|
|
47
69
|
method: "earned(address)",
|
|
48
70
|
params: [creditAccount],
|
|
49
71
|
});
|
|
50
|
-
|
|
72
|
+
currentDistribution.push({
|
|
73
|
+
protocol: currentContract.protocol,
|
|
74
|
+
contract: a.contract,
|
|
75
|
+
token: baseRewardToken,
|
|
51
76
|
contractAddress: a.contractAddress,
|
|
52
77
|
adapter: a.adapter,
|
|
53
|
-
contract: a.contract,
|
|
54
|
-
token: "CRV",
|
|
55
78
|
});
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
address: er.poolAddress[network],
|
|
79
|
+
currentContract.extraRewards.forEach(extra => {
|
|
80
|
+
currentCalls.push({
|
|
81
|
+
address: extra.poolAddress[network],
|
|
60
82
|
interface: RewardConvex.poolInterface,
|
|
61
83
|
method: "earned(address)",
|
|
62
84
|
params: [creditAccount],
|
|
63
85
|
});
|
|
64
|
-
|
|
86
|
+
currentDistribution.push({
|
|
87
|
+
protocol: currentContract.protocol,
|
|
88
|
+
contract: a.contract,
|
|
89
|
+
token: extra.rewardToken,
|
|
65
90
|
contractAddress: a.contractAddress,
|
|
66
91
|
adapter: a.adapter,
|
|
67
|
-
contract: a.contract,
|
|
68
|
-
token: er.rewardToken,
|
|
69
92
|
});
|
|
93
|
+
});
|
|
94
|
+
if (currentContract.protocol === sdk_gov_1.Protocols.Aura) {
|
|
95
|
+
acc.auraCalls.push(currentCalls);
|
|
96
|
+
acc.auraDistribution.push(currentDistribution);
|
|
70
97
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
98
|
+
else if (currentContract.protocol === sdk_gov_1.Protocols.Convex) {
|
|
99
|
+
acc.convexCalls.push(currentCalls);
|
|
100
|
+
acc.convexDistribution.push(currentDistribution);
|
|
101
|
+
}
|
|
102
|
+
return acc;
|
|
103
|
+
}, {
|
|
104
|
+
convexDistribution: [],
|
|
105
|
+
auraDistribution: [],
|
|
106
|
+
convexCalls: [
|
|
107
|
+
[
|
|
108
|
+
{
|
|
109
|
+
address: tokens.CVX,
|
|
110
|
+
interface: types_1.IConvexToken__factory.createInterface(),
|
|
111
|
+
method: "totalSupply()",
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
],
|
|
115
|
+
auraCalls: [
|
|
116
|
+
[
|
|
117
|
+
{
|
|
118
|
+
address: tokens.AURA,
|
|
119
|
+
interface: types_1.IConvexToken__factory.createInterface(),
|
|
120
|
+
method: "totalSupply()",
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
],
|
|
124
|
+
});
|
|
125
|
+
return res;
|
|
76
126
|
}
|
|
77
|
-
static parseResults(
|
|
78
|
-
const result = {};
|
|
127
|
+
static parseResults({ convexDistribution, convexResponse, convexTotalSupply, auraDistribution, auraResponse, auraTotalSupply, }) {
|
|
79
128
|
const callData = RewardConvex.poolInterface.encodeFunctionData("getReward()");
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
},
|
|
93
|
-
],
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
result[contract].rewards[token] = BigInt(reward.toString());
|
|
129
|
+
const rewardsRecord = {};
|
|
130
|
+
let start = 0;
|
|
131
|
+
convexDistribution.forEach(list => {
|
|
132
|
+
// rewards[]
|
|
133
|
+
const end = start + list.length;
|
|
134
|
+
const [baseRewardResp, ...rewardsResp] = convexResponse.slice(start, end);
|
|
135
|
+
start = end;
|
|
136
|
+
const [baseDistribution, ...extraDistribution] = list;
|
|
137
|
+
const boostedRewardToken = this.getBBoostedRewardToken(baseDistribution.protocol);
|
|
138
|
+
if (rewardsResp.length !== extraDistribution.length ||
|
|
139
|
+
baseRewardResp === undefined) {
|
|
140
|
+
throw new Error(`Rewards response length mismatch: expected: ${extraDistribution.length}, got: ${rewardsResp.length}`);
|
|
97
141
|
}
|
|
142
|
+
if (!boostedRewardToken) {
|
|
143
|
+
throw new Error(`Unknown rewards protocol: ${baseDistribution.protocol}`);
|
|
144
|
+
}
|
|
145
|
+
// create base
|
|
146
|
+
const rewardObject = this.getRewardObject((0, sdk_gov_1.toBigInt)(baseRewardResp || 0n), baseDistribution, boostedRewardToken, extraDistribution, rewardsResp, convexTotalSupply, callData, 0n);
|
|
147
|
+
if (rewardObject)
|
|
148
|
+
rewardsRecord[baseDistribution.contract] = rewardObject;
|
|
149
|
+
});
|
|
150
|
+
start = 0;
|
|
151
|
+
auraDistribution.forEach(list => {
|
|
152
|
+
// multiplier + rewards[]
|
|
153
|
+
const end = start + list.length + 1;
|
|
154
|
+
const [mp, baseRewardResp, ...rewardsResp] = auraResponse.slice(start, end);
|
|
155
|
+
start = end;
|
|
156
|
+
const multiplier = (0, sdk_gov_1.toBigInt)(mp);
|
|
157
|
+
const [baseDistribution, ...extraDistribution] = list;
|
|
158
|
+
const boostedRewardToken = this.getBBoostedRewardToken(baseDistribution.protocol);
|
|
159
|
+
if (rewardsResp.length !== extraDistribution.length ||
|
|
160
|
+
mp === undefined ||
|
|
161
|
+
baseRewardResp === undefined) {
|
|
162
|
+
throw new Error(`Rewards response length mismatch: expected: ${extraDistribution.length}, got: ${rewardsResp.length}`);
|
|
163
|
+
}
|
|
164
|
+
if (!boostedRewardToken) {
|
|
165
|
+
throw new Error(`Unknown rewards protocol: ${baseDistribution.protocol}`);
|
|
166
|
+
}
|
|
167
|
+
// create base
|
|
168
|
+
const rewardObject = this.getRewardObject((0, sdk_gov_1.toBigInt)(baseRewardResp || 0n), baseDistribution, boostedRewardToken, extraDistribution, rewardsResp, auraTotalSupply, callData, multiplier);
|
|
169
|
+
if (rewardObject)
|
|
170
|
+
rewardsRecord[baseDistribution.contract] = rewardObject;
|
|
171
|
+
});
|
|
172
|
+
const result = Object.values(rewardsRecord);
|
|
173
|
+
return result;
|
|
174
|
+
}
|
|
175
|
+
static getRewardObject(baseReward, baseDistribution, boostedRewardToken, extraDistribution, rewardsResp, totalSupply, callData, multiplier) {
|
|
176
|
+
// create base
|
|
177
|
+
const base = {
|
|
178
|
+
contract: baseDistribution.contract,
|
|
179
|
+
totalSupply: totalSupply,
|
|
180
|
+
protocol: baseDistribution.protocol,
|
|
181
|
+
rewards: {
|
|
182
|
+
[baseDistribution.token]: baseReward,
|
|
183
|
+
},
|
|
184
|
+
calls: [
|
|
185
|
+
{
|
|
186
|
+
target: baseDistribution.adapter,
|
|
187
|
+
callData,
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
};
|
|
191
|
+
// add boosted
|
|
192
|
+
const boostedReward = baseDistribution.protocol === sdk_gov_1.Protocols.Aura
|
|
193
|
+
? (0, auraAPY_1.getAURAMintAmount)(baseReward, totalSupply, multiplier)
|
|
194
|
+
: (0, apy_1.getCVXMintAmount)(baseReward, totalSupply);
|
|
195
|
+
base.rewards = {
|
|
196
|
+
...base.rewards,
|
|
197
|
+
[boostedRewardToken]: boostedReward,
|
|
198
|
+
};
|
|
199
|
+
// extra
|
|
200
|
+
extraDistribution.forEach((distribution, j) => {
|
|
201
|
+
const token = distribution.token;
|
|
202
|
+
const prevReward = base.rewards[token] || 0n;
|
|
203
|
+
const reward = (0, sdk_gov_1.toBigInt)(rewardsResp[j] || 0n);
|
|
204
|
+
base.rewards = {
|
|
205
|
+
...base.rewards,
|
|
206
|
+
[token]: prevReward + reward,
|
|
207
|
+
};
|
|
208
|
+
});
|
|
209
|
+
if (Object.values(base.rewards).some(r => r > 0)) {
|
|
210
|
+
return base;
|
|
98
211
|
}
|
|
99
|
-
return
|
|
212
|
+
return undefined;
|
|
213
|
+
}
|
|
214
|
+
static getBaseRewardToken(protocol) {
|
|
215
|
+
return protocol === sdk_gov_1.Protocols.Aura
|
|
216
|
+
? "BAL"
|
|
217
|
+
: protocol === sdk_gov_1.Protocols.Convex
|
|
218
|
+
? "CRV"
|
|
219
|
+
: undefined;
|
|
220
|
+
}
|
|
221
|
+
static getBBoostedRewardToken(protocol) {
|
|
222
|
+
return protocol === sdk_gov_1.Protocols.Aura
|
|
223
|
+
? "AURA"
|
|
224
|
+
: protocol === sdk_gov_1.Protocols.Convex
|
|
225
|
+
? "CVX"
|
|
226
|
+
: undefined;
|
|
100
227
|
}
|
|
101
228
|
}
|
|
102
229
|
exports.RewardConvex = RewardConvex;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
4
4
|
const chai_1 = require("chai");
|
|
5
5
|
const ethers_1 = require("ethers");
|
|
6
|
+
const types_1 = require("../types");
|
|
6
7
|
const rewardConvex_1 = require("./rewardConvex");
|
|
7
8
|
const ADAPTER_CONVEX_3CRV_POOL = sdk_gov_1.DUMB_ADDRESS;
|
|
8
9
|
const ADAPTER_CURVE_FRAX_POOL = sdk_gov_1.DUMB_ADDRESS2;
|
|
@@ -23,11 +24,6 @@ describe("RewardConvex test", () => {
|
|
|
23
24
|
contractAddress: sdk_gov_1.contractsByNetwork.Mainnet.CONVEX_3CRV_POOL,
|
|
24
25
|
adapter: ADAPTER_CONVEX_3CRV_POOL,
|
|
25
26
|
},
|
|
26
|
-
// {
|
|
27
|
-
// contract: "CONVEX_FRAX3CRV_POOL",
|
|
28
|
-
// contractAddress: contractsByNetwork.Goerli.CONVEX_FRAX3CRV_POOL,
|
|
29
|
-
// adapter: ADAPTER_CONVEX_FRAX3CRV_POOL,
|
|
30
|
-
// },
|
|
31
27
|
];
|
|
32
28
|
const result = rewardConvex_1.RewardConvex.findAdapters(cm);
|
|
33
29
|
(0, chai_1.expect)(result).to.be.eql(expectedResult);
|
|
@@ -41,25 +37,21 @@ describe("RewardConvex test", () => {
|
|
|
41
37
|
},
|
|
42
38
|
};
|
|
43
39
|
const calls = [
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
// interface: RewardConvex.poolInterface,
|
|
60
|
-
// method: "earned(address)",
|
|
61
|
-
// params: [CREDIT_ACCOUNT],
|
|
62
|
-
// },
|
|
40
|
+
[
|
|
41
|
+
{
|
|
42
|
+
address: sdk_gov_1.tokenDataByNetwork.Mainnet.CVX,
|
|
43
|
+
interface: types_1.IConvexToken__factory.createInterface(),
|
|
44
|
+
method: "totalSupply()",
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
[
|
|
48
|
+
{
|
|
49
|
+
address: sdk_gov_1.contractsByNetwork.Mainnet.CONVEX_3CRV_POOL,
|
|
50
|
+
interface: rewardConvex_1.RewardConvex.poolInterface,
|
|
51
|
+
method: "earned(address)",
|
|
52
|
+
params: [CREDIT_ACCOUNT],
|
|
53
|
+
},
|
|
54
|
+
],
|
|
63
55
|
];
|
|
64
56
|
const distribution = [
|
|
65
57
|
{
|
|
@@ -67,56 +59,41 @@ describe("RewardConvex test", () => {
|
|
|
67
59
|
contractAddress: sdk_gov_1.contractsByNetwork.Mainnet.CONVEX_3CRV_POOL,
|
|
68
60
|
contract: "CONVEX_3CRV_POOL",
|
|
69
61
|
token: "CRV",
|
|
62
|
+
protocol: sdk_gov_1.Protocols.Convex,
|
|
70
63
|
},
|
|
71
|
-
// {
|
|
72
|
-
// adapter: ADAPTER_CONVEX_FRAX3CRV_POOL,
|
|
73
|
-
// contractAddress: contractsByNetwork.Goerli.CONVEX_FRAX3CRV_POOL,
|
|
74
|
-
// contract: "CONVEX_FRAX3CRV_POOL",
|
|
75
|
-
// token: "CRV",
|
|
76
|
-
// },
|
|
77
|
-
// {
|
|
78
|
-
// adapter: ADAPTER_CONVEX_FRAX3CRV_POOL,
|
|
79
|
-
// contractAddress: contractsByNetwork.Goerli.CONVEX_FRAX3CRV_POOL,
|
|
80
|
-
// contract: "CONVEX_FRAX3CRV_POOL",
|
|
81
|
-
// token: "FXS",
|
|
82
|
-
// },
|
|
83
64
|
];
|
|
84
65
|
const result = rewardConvex_1.RewardConvex.prepareMultiCalls(CREDIT_ACCOUNT, cm, "Mainnet");
|
|
85
|
-
(0, chai_1.expect)(result).to.be.eql(
|
|
66
|
+
(0, chai_1.expect)(result.convexDistribution).to.be.eql([distribution]);
|
|
67
|
+
(0, chai_1.expect)(result.convexCalls).to.be.eql(calls);
|
|
86
68
|
});
|
|
87
69
|
it("parseResults parse data correctly", () => {
|
|
88
|
-
const rewards = [
|
|
89
|
-
ethers_1.BigNumber.from(1000n),
|
|
90
|
-
// BigNumber.from(2000n),
|
|
91
|
-
// BigNumber.from(4000n),
|
|
92
|
-
];
|
|
70
|
+
const rewards = [ethers_1.BigNumber.from(1000n)];
|
|
93
71
|
const distribution = [
|
|
94
72
|
{
|
|
95
73
|
adapter: ADAPTER_CONVEX_3CRV_POOL,
|
|
96
74
|
contractAddress: sdk_gov_1.contractsByNetwork.Mainnet.CONVEX_3CRV_POOL,
|
|
97
75
|
contract: "CONVEX_3CRV_POOL",
|
|
98
76
|
token: "CRV",
|
|
77
|
+
protocol: sdk_gov_1.Protocols.Convex,
|
|
99
78
|
},
|
|
100
|
-
// {
|
|
101
|
-
// adapter: ADAPTER_CONVEX_FRAX3CRV_POOL,
|
|
102
|
-
// contractAddress: contractsByNetwork.Goerli.CONVEX_FRAX3CRV_POOL,
|
|
103
|
-
// contract: "CONVEX_FRAX3CRV_POOL",
|
|
104
|
-
// token: "CRV",
|
|
105
|
-
// },
|
|
106
|
-
// {
|
|
107
|
-
// adapter: ADAPTER_CONVEX_FRAX3CRV_POOL,
|
|
108
|
-
// contractAddress: contractsByNetwork.Goerli.CONVEX_FRAX3CRV_POOL,
|
|
109
|
-
// contract: "CONVEX_FRAX3CRV_POOL",
|
|
110
|
-
// token: "FXS",
|
|
111
|
-
// },
|
|
112
79
|
];
|
|
113
|
-
const parsed = rewardConvex_1.RewardConvex.parseResults(
|
|
80
|
+
const parsed = rewardConvex_1.RewardConvex.parseResults({
|
|
81
|
+
convexDistribution: [distribution],
|
|
82
|
+
convexResponse: rewards,
|
|
83
|
+
convexTotalSupply: 0n,
|
|
84
|
+
auraDistribution: [],
|
|
85
|
+
auraResponse: [],
|
|
86
|
+
auraTotalSupply: 0n,
|
|
87
|
+
});
|
|
114
88
|
const callData = rewardConvex_1.RewardConvex.poolInterface.encodeFunctionData("getReward()");
|
|
115
89
|
const expected = [
|
|
116
90
|
{
|
|
91
|
+
protocol: sdk_gov_1.Protocols.Convex,
|
|
92
|
+
totalSupply: 0n,
|
|
117
93
|
contract: "CONVEX_3CRV_POOL",
|
|
118
94
|
rewards: {
|
|
119
95
|
CRV: 1000n,
|
|
96
|
+
CVX: 1000n,
|
|
120
97
|
},
|
|
121
98
|
calls: [
|
|
122
99
|
{
|
|
@@ -125,19 +102,6 @@ describe("RewardConvex test", () => {
|
|
|
125
102
|
},
|
|
126
103
|
],
|
|
127
104
|
},
|
|
128
|
-
// {
|
|
129
|
-
// contract: "CONVEX_FRAX3CRV_POOL",
|
|
130
|
-
// rewards: {
|
|
131
|
-
// CRV: 2000n,
|
|
132
|
-
// FXS: 4000n,
|
|
133
|
-
// },
|
|
134
|
-
// calls: [
|
|
135
|
-
// {
|
|
136
|
-
// target: ADAPTER_CONVEX_FRAX3CRV_POOL,
|
|
137
|
-
// callData,
|
|
138
|
-
// },
|
|
139
|
-
// ],
|
|
140
|
-
// },
|
|
141
105
|
];
|
|
142
106
|
(0, chai_1.expect)(parsed).to.be.eql(expected);
|
|
143
107
|
});
|
|
@@ -36,6 +36,8 @@ class ConvexBaseRewardPoolAdapterParser extends abstractParser_1.AbstractParser
|
|
|
36
36
|
return `${functionName}()`;
|
|
37
37
|
case "totalSupply":
|
|
38
38
|
return `${functionName}()`;
|
|
39
|
+
case "getReward":
|
|
40
|
+
return `${functionName}()`;
|
|
39
41
|
default:
|
|
40
42
|
return this.reportUnknownFragment(functionName, functionFragment, calldata);
|
|
41
43
|
}
|