Skip to content

Commit feb0196

Browse files
committed
fix: tokenization updated
1 parent 62a6927 commit feb0196

4 files changed

Lines changed: 30 additions & 27 deletions

File tree

src/helpers/v3/initializers.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,12 @@ export function getOrInitSubToken(subTokenAddress: Address): SubToken {
248248
}
249249

250250
export function getOrInitReserveParamsHistoryItem(
251-
id: Bytes,
251+
id: string,
252252
reserve: Reserve
253253
): ReserveParamsHistoryItem {
254-
let itemId = id.toHexString() + reserve.id;
255-
let reserveParamsHistoryItem = ReserveParamsHistoryItem.load(itemId);
254+
let reserveParamsHistoryItem = ReserveParamsHistoryItem.load(id);
256255
if (!reserveParamsHistoryItem) {
257-
reserveParamsHistoryItem = new ReserveParamsHistoryItem(itemId);
256+
reserveParamsHistoryItem = new ReserveParamsHistoryItem(id);
258257
reserveParamsHistoryItem.variableBorrowRate = zeroBI();
259258
reserveParamsHistoryItem.variableBorrowIndex = zeroBI();
260259
reserveParamsHistoryItem.utilizationRate = zeroBD();

src/mapping/tokenization/initialization-v3.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
import {
2-
Burn,
3-
Initialized as ATokenInitialized,
4-
Mint,
5-
} from '../../../generated/templates/AToken/AToken';
1+
import { Initialized as ATokenInitialized } from '../../../generated/templates/AToken/AToken';
62
import { Initialized as VTokenInitialized } from '../../../generated/templates/VariableDebtToken/VariableDebtToken';
73
import { Initialized as STokenInitialized } from '../../../generated/templates/StableDebtToken/StableDebtToken';
8-
import { IncentivesControllerV2 } from '../../../generated/templates';
4+
import { RewardsController } from '../../../generated/templates';
95

106
import { Address, log } from '@graphprotocol/graph-ts';
117
import { zeroAddress } from '../../utils/converters';
128
import {
139
ContractToPoolMapping,
14-
IncentivesController,
10+
RewardsController as RewardsControllerEntity,
1511
MapAssetPool,
1612
} from '../../../generated/schema';
1713
export {
@@ -41,11 +37,11 @@ function createIncentivesController(
4137
return;
4238
}
4339

44-
let iController = IncentivesController.load(incentivesController.toHexString());
40+
let iController = RewardsControllerEntity.load(incentivesController.toHexString());
4541
if (!iController) {
46-
iController = new IncentivesController(incentivesController.toHexString());
42+
iController = new RewardsControllerEntity(incentivesController.toHexString());
4743
iController.save();
48-
IncentivesControllerV2.create(incentivesController);
44+
RewardsController.create(incentivesController);
4945
}
5046

5147
let poolAddressProvider = ContractToPoolMapping.load(pool.toHexString());

src/mapping/tokenization/tokenization-v3.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
BalanceTransfer as ATokenTransfer,
2+
BalanceTransfer,
33
Mint as ATokenMint,
44
Burn as ATokenBurn,
55
} from '../../../generated/templates/AToken/AToken';
@@ -34,6 +34,7 @@ import { zeroBI } from '../../utils/converters';
3434
import { calculateUtilizationRate } from '../../helpers/reserve-logic';
3535
import { Address, BigInt, ethereum, log } from '@graphprotocol/graph-ts';
3636
import { rayDiv, rayMul } from '../../helpers/math';
37+
import { getHistoryEntityId } from '../../utils/id-generation';
3738

3839
// TODO: check if we need to add stuff to history
3940
function saveUserReserveAHistory(
@@ -74,9 +75,7 @@ function saveUserReserveSHistory(
7475
event: ethereum.Event,
7576
rate: BigInt
7677
): void {
77-
let sTokenBalanceHistoryItem = new STokenBalanceHistoryItem(
78-
userReserve.id + event.transaction.hash.toHexString()
79-
);
78+
let sTokenBalanceHistoryItem = new STokenBalanceHistoryItem(getHistoryEntityId(event));
8079
//TODO: add rserve things new stable things
8180
sTokenBalanceHistoryItem.principalStableDebt = userReserve.principalStableDebt;
8281
sTokenBalanceHistoryItem.currentStableDebt = userReserve.currentStableDebt;
@@ -90,7 +89,10 @@ function saveReserve(reserve: Reserve, event: ethereum.Event): void {
9089
reserve.utilizationRate = calculateUtilizationRate(reserve);
9190
reserve.save();
9291

93-
let reserveParamsHistoryItem = getOrInitReserveParamsHistoryItem(event.transaction.hash, reserve);
92+
let reserveParamsHistoryItem = getOrInitReserveParamsHistoryItem(
93+
getHistoryEntityId(event),
94+
reserve
95+
);
9496
reserveParamsHistoryItem.totalScaledVariableDebt = reserve.totalScaledVariableDebt;
9597
reserveParamsHistoryItem.totalCurrentVariableDebt = reserve.totalCurrentVariableDebt;
9698
reserveParamsHistoryItem.totalPrincipalStableDebt = reserve.totalPrincipalStableDebt;
@@ -163,14 +165,20 @@ function tokenBurn(event: ethereum.Event, from: Address, value: BigInt, index: B
163165
saveUserReserveAHistory(userReserve, event, index);
164166
}
165167

166-
function tokenMint(event: ethereum.Event, from: Address, value: BigInt, index: BigInt): void {
167-
log.error('---------------------------------------------------', []);
168+
function tokenMint(event: ethereum.Event, onBehalf: Address, value: BigInt, index: BigInt): void {
168169
let aToken = getOrInitSubToken(event.address);
169170
let poolReserve = getOrInitReserve(aToken.underlyingAssetAddress, event);
170171
poolReserve.totalATokenSupply = poolReserve.totalATokenSupply.plus(value);
171172
// Check if we are minting to treasury for mainnet and polygon
172-
if (from.toHexString() != 'TODO: add here arbitrum treasury') {
173-
let userReserve = getOrInitUserReserve(from, aToken.underlyingAssetAddress, event);
173+
if (
174+
onBehalf.toHexString() != '0xB2289E329D2F85F1eD31Adbb30eA345278F21bcf'.toLowerCase() &&
175+
onBehalf.toHexString() != '0xe8599F3cc5D38a9aD6F3684cd5CEa72f10Dbc383'.toLowerCase() &&
176+
onBehalf.toHexString() != '0xBe85413851D195fC6341619cD68BfDc26a25b928'.toLowerCase() &&
177+
onBehalf.toHexString() != '0x5ba7fd868c40c16f7aDfAe6CF87121E13FC2F7a0'.toLowerCase() &&
178+
onBehalf.toHexString() != '0x8A020d92D6B119978582BE4d3EdFdC9F7b28BF31'.toLowerCase() &&
179+
onBehalf.toHexString() != '0x053D55f9B5AF8694c503EB288a1B7E552f590710'.toLowerCase()
180+
) {
181+
let userReserve = getOrInitUserReserve(onBehalf, aToken.underlyingAssetAddress, event);
174182
let calculatedAmount = rayDiv(value, index);
175183

176184
userReserve.scaledATokenBalance = userReserve.scaledATokenBalance.plus(calculatedAmount);
@@ -211,10 +219,10 @@ export function handleATokenBurn(event: ATokenBurn): void {
211219

212220
export function handleATokenMint(event: ATokenMint): void {
213221
log.error('Mint ---------------------------------', []);
214-
tokenMint(event, event.params.from, event.params.value, event.params.index);
222+
tokenMint(event, event.params.onBehalfOf, event.params.value, event.params.index);
215223
}
216224

217-
export function handleATokenTransfer(event: ATokenTransfer): void {
225+
export function handleBalanceTransfer(event: BalanceTransfer): void {
218226
log.error('Transfer ---------------------------------', []);
219227
tokenBurn(event, event.params.from, event.params.value, event.params.index);
220228
tokenMint(event, event.params.to, event.params.value, event.params.index);

templates/v3.subgraph.template.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ dataSources:
104104
# --------------------------------------
105105
templates:
106106
# --------------------------------------
107-
# INCENTIVES
107+
# REWARDS
108108
# --------------------------------------
109109
- kind: ethereum/contract
110110
name: RewardsController
@@ -208,7 +208,7 @@ templates:
208208
- event: Burn(indexed address,indexed address,uint256,uint256,uint256)
209209
handler: handleATokenBurn
210210
- event: BalanceTransfer(indexed address,indexed address,uint256,uint256)
211-
handler: handleATokenTransfer
211+
handler: handleBalanceTransfer
212212
- event: Mint(indexed address,indexed address,uint256,uint256,uint256)
213213
handler: handleATokenMint
214214
- event: Initialized(indexed address,indexed address,address,address,uint8,string,string,bytes)

0 commit comments

Comments
 (0)