@@ -71,6 +71,9 @@ import {
7171 ResyncAavegotchis ,
7272 ClaimedAt ,
7373 EscrowUpdated ,
74+ SwapAndPurchase ,
75+ SwapAndPurchaseERC1155 ,
76+ TokenSwapped ,
7477} from "../../generated/AavegotchiDiamond/AavegotchiDiamond" ;
7578import {
7679 getOrCreateUser ,
@@ -118,7 +121,13 @@ import {
118121} from "../utils/constants" ;
119122import { Address , BigInt , log , Bytes } from "@graphprotocol/graph-ts" ;
120123
121- import { Parcel , TokenCommitment , ERC721Listing } from "../../generated/schema" ;
124+ import {
125+ Parcel ,
126+ TokenCommitment ,
127+ ERC721Listing ,
128+ ERC1155Purchase ,
129+ SwapAction ,
130+ } from "../../generated/schema" ;
122131
123132import { updatePermissionsFromBitmap } from "../utils/decimals" ;
124133import * as erc7589 from "./erc-7589" ;
@@ -1308,6 +1317,53 @@ export function handleERC721ExecutedToRecipient(
13081317 listing . save ( ) ;
13091318}
13101319
1320+ // Swap-and-buy helpers
1321+ export function handleSwapAndPurchase ( event : SwapAndPurchase ) : void {
1322+ let listing = getOrCreateERC721Listing ( event . params . listingId . toString ( ) ) ;
1323+ listing = updateERC721ListingInfo ( listing , event . params . listingId , event ) ;
1324+
1325+ listing . purchasedWithSwap = true ;
1326+ listing . swapTokenIn = event . params . tokenIn ;
1327+ listing . swapAmountIn = event . params . swapAmount ;
1328+ listing . swapGhstReceived = event . params . ghstReceived ;
1329+
1330+ listing . save ( ) ;
1331+ }
1332+
1333+ export function handleSwapAndPurchaseERC1155 (
1334+ event : SwapAndPurchaseERC1155
1335+ ) : void {
1336+ // Purchase id mirrors the id created in handleERC1155ExecutedListing
1337+ let purchaseID =
1338+ event . params . listingId . toString ( ) +
1339+ "_" +
1340+ event . params . buyer . toHexString ( ) +
1341+ "_" +
1342+ event . block . timestamp . toString ( ) ;
1343+
1344+ let purchase = ERC1155Purchase . load ( purchaseID ) ;
1345+ if ( purchase ) {
1346+ purchase . purchasedWithSwap = true ;
1347+ purchase . swapTokenIn = event . params . tokenIn ;
1348+ // swapAmountIn not available in this event; leave null
1349+ purchase . swapGhstReceived = event . params . ghstReceived ;
1350+ purchase . save ( ) ;
1351+ }
1352+ }
1353+
1354+ export function handleTokenSwapped ( event : TokenSwapped ) : void {
1355+ const id = event . transaction . hash . toHex ( ) + "-" + event . logIndex . toString ( ) ;
1356+ let action = new SwapAction ( id ) ;
1357+ action . tokenIn = event . params . tokenIn ;
1358+ action . tokenOut = event . params . tokenOut ;
1359+ action . amountIn = event . params . amountIn ;
1360+ action . amountOut = event . params . amountOut ;
1361+ action . recipient = event . params . recipient ;
1362+ action . createdAt = event . block . timestamp ;
1363+ action . txHash = event . transaction . hash ;
1364+ action . save ( ) ;
1365+ }
1366+
13111367export function handleWhitelistAccessRightSet (
13121368 event : WhitelistAccessRightSet
13131369) : void {
0 commit comments