Skip to content

Commit 7256f0a

Browse files
committed
fix: prevent ownership update when the to address is diamond
1 parent c024e95 commit 7256f0a

File tree

6 files changed

+10
-81
lines changed

6 files changed

+10
-81
lines changed

schema.graphql

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -652,10 +652,3 @@ type ItemTypeOwnership @entity {
652652
balance: BigInt!
653653
lastUpdated: BigInt!
654654
}
655-
656-
type PendingEquip @entity {
657-
id: ID! # `${txHash}-${logIdx}` (or just txHash if one equip/tx)
658-
sender: Bytes! # original wallet
659-
itemId: BigInt!
660-
amount: BigInt!
661-
}

src/mappings/diamond.ts

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,7 @@ import {
117117
} from "../utils/constants";
118118
import { Address, BigInt, log, Bytes, store } from "@graphprotocol/graph-ts";
119119

120-
import {
121-
/*Parcel,*/ Parcel,
122-
PendingEquip,
123-
TokenCommitment,
124-
} from "../../generated/schema";
120+
import { /*Parcel,*/ Parcel, TokenCommitment } from "../../generated/schema";
125121
// import {
126122
// RealmDiamond,
127123
// MintParcel,
@@ -137,7 +133,7 @@ import {
137133
RealmDiamond,
138134
ResyncParcel,
139135
} from "../../generated/AavegotchiDiamond/RealmDiamond";
140-
import { updateOwnership } from "./helpers";
136+
import { AAVEGOTCHI_ADDRESS, updateOwnership } from "./helpers";
141137

142138
export function handleBuyPortals(event: BuyPortals): void {
143139
let contract = AavegotchiDiamond.bind(event.address);
@@ -1995,7 +1991,9 @@ export function handleTransferSingle(e: TransferSingle): void {
19951991
const from = e.params._from;
19961992
const to = e.params._to;
19971993

1998-
// 1) Normal balance book-keeping
1994+
// prevent updating balances when equipping/unequipping and delegating?
1995+
if (to.equals(AAVEGOTCHI_ADDRESS)) return;
1996+
19991997
if (from.notEqual(Address.zero()))
20001998
updateOwnership(
20011999
e.params._id.toString(),
@@ -2011,17 +2009,6 @@ export function handleTransferSingle(e: TransferSingle): void {
20112009
e.params._value,
20122010
e.block.timestamp
20132011
);
2014-
2015-
// 2) If it went _into_ the diamond it MIGHT be an equip leg,
2016-
// so remember who sent it.
2017-
if (to.equals(e.address)) {
2018-
const key = `${e.transaction.hash.toHex()}-${e.logIndex.toString()}`;
2019-
let p = new PendingEquip(key);
2020-
p.sender = from; // wallet that paid the item
2021-
p.itemId = e.params._id;
2022-
p.amount = e.params._value;
2023-
p.save();
2024-
}
20252012
}
20262013

20272014
export function handleTransferBatch(event: TransferBatch): void {
@@ -2044,36 +2031,3 @@ export function handleTransferBatch(event: TransferBatch): void {
20442031
}
20452032
}
20462033
}
2047-
2048-
export function handleTransferToParent(e: TransferToParent): void {
2049-
const itemId = e.params._tokenTypeId.toString(); // 👈 field names from ABI
2050-
const amt = e.params._value;
2051-
const ts = e.block.timestamp;
2052-
const pendId = `${e.transaction.hash.toHex()}-${(
2053-
e.logIndex.toI32() - 1
2054-
).toString()}`;
2055-
2056-
let p = PendingEquip.load(pendId);
2057-
2058-
if (p) {
2059-
// 1) undo diamond’s +amt
2060-
updateOwnership(itemId, e.params._toContract, amt.neg(), ts);
2061-
2062-
// 2) give item back to original wallet
2063-
updateOwnership(itemId, Address.fromBytes(p.sender), amt, ts);
2064-
2065-
store.remove("PendingEquip", pendId);
2066-
} else {
2067-
// diamond really owned it already
2068-
updateOwnership(itemId, e.params._toContract, amt.neg(), ts);
2069-
}
2070-
}
2071-
2072-
export function handleTransferFromParent(e: TransferFromParent): void {
2073-
const itemId = e.params._tokenTypeId.toString();
2074-
const amt = e.params._value;
2075-
const ts = e.block.timestamp;
2076-
2077-
// 1) diamond temporarily regains it
2078-
updateOwnership(itemId, e.params._fromContract, amt, ts);
2079-
}

src/mappings/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { BigInt, Address, ethereum, store } from "@graphprotocol/graph-ts";
22
import { ItemTypeOwnership } from "../../generated/schema";
33

44
const MIGRATION_BLOCK = BigInt.fromI32(35999793);
5-
const AAVEGOTCHI_ADDRESS = Address.fromString(
5+
export const AAVEGOTCHI_ADDRESS = Address.fromString(
66
"0x86935F11C86623deC8a25696E1C19a8659CbF95d"
77
);
88

src/mappings/itemTransfers.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import { Address } from "@graphprotocol/graph-ts";
22

3-
import { updateOwnership } from "./helpers";
3+
import { AAVEGOTCHI_ADDRESS, updateOwnership } from "./helpers";
44
import {
55
TransferBatch,
66
TransferSingle,
77
} from "../../generated/AavegotchiDiamond/AavegotchiDiamond";
8-
import { PendingEquip } from "../../generated/schema";
98

109
export function handleTransferSingle(e: TransferSingle): void {
1110
const from = e.params._from;
1211
const to = e.params._to;
1312

14-
// 1) Normal balance book-keeping
13+
// prevent updating balances when equipping/unequipping and delegating?
14+
if (to.equals(AAVEGOTCHI_ADDRESS)) return;
15+
1516
if (from.notEqual(Address.zero()))
1617
updateOwnership(
1718
e.params._id.toString(),
@@ -27,17 +28,6 @@ export function handleTransferSingle(e: TransferSingle): void {
2728
e.params._value,
2829
e.block.timestamp
2930
);
30-
31-
// 2) If it went _into_ the diamond it MIGHT be an equip leg,
32-
// so remember who sent it.
33-
if (to.equals(e.address)) {
34-
const key = `${e.transaction.hash.toHex()}-${e.logIndex.toString()}`;
35-
let p = new PendingEquip(key);
36-
p.sender = from; // wallet that paid the item
37-
p.itemId = e.params._id;
38-
p.amount = e.params._value;
39-
p.save();
40-
}
4131
}
4232

4333
export function handleTransferBatch(event: TransferBatch): void {

subgraph.template.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,6 @@ dataSources:
177177
handler: handleWearablesConfigCreated
178178
- event: WearablesConfigUpdated(indexed address,indexed uint256,indexed uint16,uint16[16])
179179
handler: handleWearablesConfigUpdated
180-
- event: TransferToParent(indexed address,indexed uint256,indexed uint256,uint256)
181-
handler: handleTransferToParent
182-
- event: TransferFromParent(indexed address,indexed uint256,indexed uint256,uint256)
183-
handler: handleTransferFromParent
184180

185181
- kind: ethereum/contract
186182
name: RealmDiamond

subgraph.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,6 @@ dataSources:
177177
handler: handleWearablesConfigCreated
178178
- event: WearablesConfigUpdated(indexed address,indexed uint256,indexed uint16,uint16[16])
179179
handler: handleWearablesConfigUpdated
180-
- event: TransferToParent(indexed address,indexed uint256,indexed uint256,uint256)
181-
handler: handleTransferToParent
182-
- event: TransferFromParent(indexed address,indexed uint256,indexed uint256,uint256)
183-
handler: handleTransferFromParent
184180

185181
- kind: ethereum/contract
186182
name: RealmDiamond

0 commit comments

Comments
 (0)