Skip to content

Commit f482468

Browse files
authored
fix rewards calculation (#39)
1 parent 5607e7c commit f482468

File tree

6 files changed

+22
-28
lines changed

6 files changed

+22
-28
lines changed

subgraphs/stakewise/src/entities/merkleDistributor.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ export function calculateDistributorPoints(
4040
principal: BigInt,
4141
prevDistributorPoints: BigInt,
4242
updatedAtBlock: BigInt,
43-
rewardsUpdatedAtBlock: BigInt,
43+
fromBlock: BigInt,
4444
currentBlock: BigInt
4545
): BigInt {
46-
if (rewardsUpdatedAtBlock.ge(updatedAtBlock)) {
47-
return principal.times(currentBlock.minus(rewardsUpdatedAtBlock));
46+
if (fromBlock.ge(updatedAtBlock)) {
47+
return principal.times(currentBlock.minus(fromBlock));
4848
}
4949

5050
return prevDistributorPoints.plus(

subgraphs/stakewise/src/entities/poolValidators.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ import {
55
Validator,
66
OperatorAllocation,
77
} from "../../generated/schema";
8-
import {
9-
calculateDistributorPoints,
10-
createOrLoadMerkleDistributor,
11-
} from "./merkleDistributor";
8+
import { calculateDistributorPoints } from "./merkleDistributor";
9+
import { createOrLoadRewardEthToken } from "./rewardEthToken";
1210

1311
export function createOrLoadOperator(
1412
operatorAddress: Address,
@@ -32,12 +30,12 @@ export function createOrLoadOperator(
3230
operator.updatedAtTimestamp = BIG_INT_ZERO;
3331
operator.save();
3432
} else {
35-
let distributor = createOrLoadMerkleDistributor();
33+
let rewardEthToken = createOrLoadRewardEthToken();
3634
operator.distributorPoints = calculateDistributorPoints(
3735
operator.revenueShare.times(operator.validatorsCount),
3836
operator.distributorPoints,
3937
operator.updatedAtBlock,
40-
distributor.rewardsUpdatedAtBlock,
38+
rewardEthToken.updatedAtBlock,
4139
currentBlock
4240
);
4341
}

subgraphs/stakewise/src/entities/roles.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts";
22
import { BIG_INT_ZERO } from "const";
3-
import {
4-
calculateDistributorPoints,
5-
createOrLoadMerkleDistributor,
6-
} from "./merkleDistributor";
3+
import { calculateDistributorPoints } from "./merkleDistributor";
74
import { Partner, Referrer } from "../../generated/schema";
5+
import { createOrLoadRewardEthToken } from "./rewardEthToken";
86

97
export function loadPartner(
108
partnerAddress: Address,
119
currentBlock: BigInt
1210
): Partner | null {
1311
let partner = Partner.load(partnerAddress.toHexString());
1412
if (partner != null) {
15-
let distributor = createOrLoadMerkleDistributor();
13+
let rewardEthToken = createOrLoadRewardEthToken();
1614
partner.distributorPoints = calculateDistributorPoints(
1715
partner.revenueShare.times(partner.contributedAmount),
1816
partner.distributorPoints,
1917
partner.updatedAtBlock,
20-
distributor.rewardsUpdatedAtBlock,
18+
rewardEthToken.updatedAtBlock,
2119
currentBlock
2220
);
2321
}

subgraphs/stakewise/src/entities/stakeWiseToken.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ import {
99
CONTRACT_CHECKER_DEPLOYMENT_BLOCK,
1010
} from "const";
1111
import { StakeWiseTokenHolder, VestingEscrow } from "../../generated/schema";
12-
import {
13-
calculateDistributorPoints,
14-
createOrLoadMerkleDistributor,
15-
} from "./merkleDistributor";
12+
import { calculateDistributorPoints } from "./merkleDistributor";
1613
import { ContractChecker } from "../../generated/StakeWiseToken/ContractChecker";
14+
import { createOrLoadRewardEthToken } from "./rewardEthToken";
1715

1816
export function createOrLoadStakeWiseTokenHolder(
1917
holderAddress: Address,
@@ -38,13 +36,13 @@ export function createOrLoadStakeWiseTokenHolder(
3836
holder.updatedAtTimestamp = BIG_INT_ZERO;
3937
holder.save();
4038
} else {
41-
let distributor = createOrLoadMerkleDistributor();
39+
let rewardEthToken = createOrLoadRewardEthToken();
4240
holder.isContract = isContract;
4341
holder.distributorPoints = calculateDistributorPoints(
4442
holder.balance,
4543
holder.distributorPoints,
4644
holder.updatedAtBlock,
47-
distributor.rewardsUpdatedAtBlock,
45+
rewardEthToken.updatedAtBlock,
4846
currentBlock
4947
);
5048
}

subgraphs/stakewise/src/mappings/stakeWiseToken.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { log } from "@graphprotocol/graph-ts";
22
import { CONTRACT_CHECKER_ADDRESS, MERKLE_DISTRIBUTOR_ADDRESS } from "const";
33
import {
4-
createOrLoadMerkleDistributor,
54
createOrLoadNetwork,
5+
createOrLoadRewardEthToken,
66
createOrLoadStakeWiseTokenHolder,
77
isSupportedSwiseHolder,
88
} from "../entities";
@@ -38,10 +38,10 @@ export function handleTransfer(event: Transfer): void {
3838

3939
if (event.params.from.equals(MERKLE_DISTRIBUTOR_ADDRESS)) {
4040
// SWISE located in Merkle Distributor belongs to the claimer
41-
let distributor = createOrLoadMerkleDistributor();
41+
let rewardEthToken = createOrLoadRewardEthToken();
4242
toHolder.distributorPoints = toHolder.distributorPoints.plus(
4343
event.params.value.times(
44-
event.block.number.minus(distributor.rewardsUpdatedAtBlock)
44+
event.block.number.minus(rewardEthToken.updatedAtBlock)
4545
)
4646
);
4747
}

subgraphs/stakewise/subgraph.template.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dataSources:
1818
file: ./src/mappings/pool.ts
1919
entities:
2020
- Pool
21-
- MerkleDistributor
21+
- RewardEthToken
2222
- Partner
2323
- Referrer
2424
- DepositActivation
@@ -68,7 +68,7 @@ dataSources:
6868
entities:
6969
- Operator
7070
- OperatorSnapshot
71-
- MerkleDistributor
71+
- RewardEthToken
7272
- Validator
7373
- Network
7474
abis:
@@ -221,7 +221,7 @@ dataSources:
221221
file: ./src/mappings/stakeWiseToken.ts
222222
entities:
223223
- StakeWiseTokenHolder
224-
- MerkleDistributor
224+
- RewardEthToken
225225
- Network
226226
- VestingEscrow
227227
abis:
@@ -367,7 +367,7 @@ dataSources:
367367
- Referrer
368368
- Operator
369369
- Network
370-
- MerkleDistributor
370+
- RewardEthToken
371371
abis:
372372
- name: Roles
373373
file: ./packages/abis/Roles.json

0 commit comments

Comments
 (0)