Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rarible ens and opensea subgraphs changes #45

Open
wants to merge 53 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
1e4bbda
fixed seaport issues,added test cases
sharathkrml Mar 8, 2023
5993452
refactored code,added one edge case fix & tested
sharathkrml Mar 9, 2023
d97b93b
fixed case with more transactions
sharathkrml Mar 9, 2023
deec9bc
fixed failing due to division by zero
sharathkrml Mar 12, 2023
f13b6a7
Merge branch 'rahul-main-changes-release' into sharatkrml/seaport-fix
sharathkrml Mar 13, 2023
98ecc8a
hanlding multiple tokenIds in random mint 721
rahul7668gupta Mar 15, 2023
3a2cf67
dynamic datasourcing of 721 gen contracts and listening to them
rahul7668gupta Mar 15, 2023
8168829
Merge rahul-main-changes-release to seaport-fix
sharathkrml Mar 16, 2023
1c38219
applied fixes for missing decoding & error
sharathkrml Mar 16, 2023
914c1aa
added new decodings
sharathkrml Mar 17, 2023
ad68bc7
added SharedStorefront support
sharathkrml Mar 17, 2023
0188c3d
added fix for Enjin tokens
sharathkrml Mar 18, 2023
244f4ef
added one more missing case
sharathkrml Mar 19, 2023
fdf5cdc
added missing functionSelector #14052754
sharathkrml Mar 20, 2023
4febef9
duplicate ens names fix
rahul7668gupta Mar 21, 2023
ab1ca0b
added entity to track address variation
sharathkrml Mar 21, 2023
66aaf47
added isBundle input
sharathkrml Mar 22, 2023
ffb3da0
updated test cases
sharathkrml Mar 23, 2023
3f64bc0
pickeup up bundle changes from #52
rahul7668gupta Mar 23, 2023
fe29470
added test case for zero beneficiary
sharathkrml Mar 23, 2023
e7115f7
bundle sale updates for rarible v2
rahul7668gupta Mar 23, 2023
8101b5c
handling abc.def labelNames in newOwner txns
rahul7668gupta Mar 23, 2023
f7bda5e
nft marketplace v3 schema and modules
rahul7668gupta Mar 24, 2023
3e58909
indexing 5 more rarible exchange v1 contracts (#51)
rahul7668gupta Mar 24, 2023
e71bb3e
v3 nft module update in rarible v1
rahul7668gupta Mar 24, 2023
6ba2615
rarible exchange v2 nft v3 schema updates
rahul7668gupta Mar 24, 2023
8173107
ens subgraph null trackback fix wrt labelHash
rahul7668gupta Mar 25, 2023
f54df4a
added decoding for bundle in single
sharathkrml Mar 25, 2023
2cdc192
updated nft v3 module with airnft and royalty id logic
rahul7668gupta Mar 25, 2023
bbcff03
fixed event.transaction.index in rarible v1
rahul7668gupta Mar 27, 2023
b86b1a0
implemented schema v3 on opensea_wyvern
sharathkrml Mar 29, 2023
f7bdd8f
tested tokenAmount Gt 1
sharathkrml Mar 29, 2023
9a3a00c
fixed bundle issue(from<->to)
sharathkrml Apr 3, 2023
d5c7d98
added fix for phising case
sharathkrml Apr 4, 2023
aa9c16a
updated primary domain txn schema with prevDomain
rahul7668gupta Apr 5, 2023
5c21e98
fixed multiTransfer issue
sharathkrml Apr 7, 2023
11e2167
ens primary and name [] fix
rahul7668gupta Apr 7, 2023
67f02f4
ens graft
rahul7668gupta Apr 12, 2023
fd03284
Merge pull request #57 from Airstack-xyz/ens-updates-reverse-registra…
sharathkrml Apr 13, 2023
d1755e5
setting primary to false when domain is transferred
rahul7668gupta Apr 25, 2023
24c0894
addressed PR comments
sharathkrml Apr 30, 2023
f569b18
lastUpdatedIndex and name wapped event
rahul7668gupta May 2, 2023
a7b2a36
yaml update, remoevd grafting
rahul7668gupta May 2, 2023
d3484d1
added test for decodeName
rahul7668gupta May 3, 2023
ae047da
addresed changes
rahul7668gupta May 18, 2023
1c25fe0
Merge pull request #63 from Airstack-xyz/ens-last-updated-feature
0xsarvesh May 18, 2023
d2c365a
added some comments
sharathkrml May 23, 2023
064ad6d
Merge pull request #47 from Airstack-xyz/sharatkrml/seaport-fix
0xsarvesh May 31, 2023
d557971
removed unwanted loop
sharathkrml Jun 1, 2023
9e72c12
Merge pull request #56 from Airstack-xyz/sharathkrml/wyvern-v3
0xsarvesh Jun 2, 2023
cb628a3
Merge branch 'main' into rahul-main-changes-releas
sharathkrml Jun 2, 2023
cb0c790
fixed ens merge conflicts, copied from ens last updated index branch
rahul7668gupta Jun 2, 2023
95aec5c
removed generatable entities
sharathkrml Jun 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type AirDomain @entity {
createdAt: AirBlock!
lastUpdatedBlock: AirBlock #- NA
extras: [AirExtra!]
lastUpdatedIndex: BigInt!
}

type AirDomainTransferTransaction implements AirDomainEvent @entity {
Expand Down Expand Up @@ -167,6 +168,7 @@ type AirNameRenewedTransaction implements AirDomainEvent & AirDomainRegistration

type AirPrimaryDomainTransaction implements AirDomainEvent @entity {
id: ID!
previousDomain: AirDomain
block: AirBlock!
transactionHash: String!
tokenId: String # dec(labelhash) # - NA
Expand Down
88 changes: 35 additions & 53 deletions airstack-modules/modules/airstack/domain-name/domain-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import {
Bytes,
crypto,
log,
ByteArray,
ens,
ethereum,
} from "@graphprotocol/graph-ts";

Expand All @@ -25,7 +23,7 @@ import {
PrimaryDomain,
AirExtra,
} from "../../../generated/schema";
import { createAirExtra, AIR_EXTRA_TTL, AIR_SET_PRIMARY_DOMAIN_ENTITY_COUNTER_ID, AIR_DOMAIN_OWNER_CHANGED_ENTITY_COUNTER_ID, AIR_ADDR_CHANGED_ENTITY_COUNTER_ID, AIR_NAME_RENEWED_ENTITY_COUNTER_ID, AIR_NAME_REGISTERED_ENTITY_COUNTER_ID, AIR_DOMAIN_NEW_TTL_ENTITY_COUNTER_ID, AIR_DOMAIN_NEW_RESOLVER_ENTITY_COUNTER_ID, AIR_DOMAIN_TRANSFER_ENTITY_COUNTER_ID, ZERO_ADDRESS, ETHEREUM_MAINNET_ID } from "./utils";
import { createAirExtra, AIR_EXTRA_TTL, AIR_SET_PRIMARY_DOMAIN_ENTITY_COUNTER_ID, AIR_DOMAIN_OWNER_CHANGED_ENTITY_COUNTER_ID, AIR_ADDR_CHANGED_ENTITY_COUNTER_ID, AIR_NAME_RENEWED_ENTITY_COUNTER_ID, AIR_NAME_REGISTERED_ENTITY_COUNTER_ID, AIR_DOMAIN_NEW_TTL_ENTITY_COUNTER_ID, AIR_DOMAIN_NEW_RESOLVER_ENTITY_COUNTER_ID, AIR_DOMAIN_TRANSFER_ENTITY_COUNTER_ID, ZERO_ADDRESS, ETHEREUM_MAINNET_ID, checkValidLabel, saveDomainEntity } from "./utils";
import { BIGINT_ONE, BIG_INT_ZERO, EMPTY_STRING, getChainId, updateAirEntityCounter, getOrCreateAirBlock, getOrCreateAirAccount, getOrCreateAirToken } from "../common";

export namespace domain {
Expand Down Expand Up @@ -69,7 +67,6 @@ export namespace domain {
));
if (domain.parent == null) {
parentDomain.subdomainCount = parentDomain.subdomainCount.plus(BIGINT_ONE);
parentDomain.lastUpdatedBlock = airBlock.id;
}
domain.name = name;
domain.labelName = labelName;
Expand All @@ -79,9 +76,8 @@ export namespace domain {
domain.parent = parentDomain.id;
domain.labelHash = labelHash;
domain.tokenId = tokenId;
domain.lastUpdatedBlock = airBlock.id;
parentDomain.save();
domain.save();
saveDomainEntity(parentDomain, airBlock);
saveDomainEntity(domain, airBlock);
recurseSubdomainCountDecrement(domain, chainId, airBlock, tokenAddress);

let txn = getOrCreateAirDomainOwnerChangedTransaction(
Expand Down Expand Up @@ -128,8 +124,9 @@ export namespace domain {
let newOwnerAccount = getOrCreateAirAccount(chainId, newOwnerAddress, airBlock);
newOwnerAccount.save();
domain.owner = newOwnerAccount.id;
domain.lastUpdatedBlock = airBlock.id;
domain.save();
// set primary to false when domain is transferred
domain.isPrimary = false;
saveDomainEntity(domain, airBlock);
let id = createEntityId(transactionHash, block.number, logOrCallIndex);
let entity = AirDomainTransferTransaction.load(id);
if (entity == null) {
Expand Down Expand Up @@ -180,8 +177,7 @@ export namespace domain {
domain.resolvedAddress = resolverEntity.resolvedAddress;
}
// do recursive subdomain count decrement
domain.lastUpdatedBlock = airBlock.id;
domain.save();
saveDomainEntity(domain, airBlock);
recurseSubdomainCountDecrement(domain, chainId, airBlock, tokenAddress);

// create new resolver transaction
Expand Down Expand Up @@ -244,8 +240,7 @@ export namespace domain {
}
}
domain.extras = extrasArray;
domain.lastUpdatedBlock = airBlock.id;
domain.save();
saveDomainEntity(domain, airBlock);
// create AirDomainNewTTLTransaction
let txn = getOrCreateAirDomainNewTTLTransaction(
transactionHash,
Expand Down Expand Up @@ -298,14 +293,13 @@ export namespace domain {
domain.labelName = labelName
}
domain.expiryTimestamp = expiryTimestamp;
domain.lastUpdatedBlock = airBlock.id;
if (cost) {
domain.registrationCost = cost;
}
let airToken = getOrCreateAirToken(chainId, paymentToken);
airToken.save();
domain.paymentToken = airToken.id;
domain.save();
saveDomainEntity(domain, airBlock);
// create name registered transaction
let txn = getOrCreateAirNameRegisteredTransaction(
chainId,
Expand Down Expand Up @@ -351,8 +345,7 @@ export namespace domain {
tokenAddress,
));
domain.expiryTimestamp = expiryTimestamp;
domain.lastUpdatedBlock = airBlock.id;
domain.save();
saveDomainEntity(domain, airBlock);
// create name renewed transaction
let txn = getOrCreateAirNameRenewedTransaction(
transactionHash,
Expand All @@ -372,8 +365,7 @@ export namespace domain {
* @param block ethereum block
* @param transactionHash transaction hash
* @param domainId air domain id
* @param name domain name
* @param labelHash label hash
* @param labelName domain labelName
* @param cost cost of registration or renewal
* @param paymentToken payment token address
* @param renewerOrRegistrant renewer or registrant address
Expand All @@ -385,8 +377,7 @@ export namespace domain {
block: ethereum.Block,
transactionHash: string,
domainId: string,
name: string,
labelHash: Bytes,
labelName: string,
cost: BigInt,
paymentToken: string,
renewerOrRegistrant: string,
Expand All @@ -395,19 +386,6 @@ export namespace domain {
tokenAddress: string,
): void {
let chainId = getChainId();
const calculatedLabelHash = crypto.keccak256(ByteArray.fromUTF8(name));
if (!calculatedLabelHash.equals(labelHash)) {
log.warning(
"Expected '{}' to hash to {}, but got {} instead. Skipping.",
[name, calculatedLabelHash.toHex(), labelHash.toHex()]
);
return;
}

if (name.indexOf(".") !== -1) {
log.warning("Invalid label '{}'. Skipping.", [name]);
return;
}
let airBlock = getOrCreateAirBlock(chainId, block.number, block.hash.toHexString(), block.timestamp);
airBlock.save();
let domain = getOrCreateAirDomain(new Domain(
Expand All @@ -416,7 +394,6 @@ export namespace domain {
airBlock,
tokenAddress,
));

// tracking registration cost in domain entity - renewal cost is not being tracked yet
if (fromRegistrationEvent) {
domain.registrationCost = cost;
Expand Down Expand Up @@ -450,17 +427,20 @@ export namespace domain {
);
txn.save();
}
if (domain.labelName !== name) {
domain.labelName = name
domain.name = name + '.eth'
if (domain.labelName !== labelName) {
if (!checkValidLabel(labelName, transactionHash) && domain.labelHash) {
const labelHash = domain.labelHash!;
labelName = '[' + labelHash.slice(2) + ']';
}
domain.labelName = labelName
domain.name = labelName + '.eth'
// creating reverse registrar to get domainId when setting primary domain
if (domain.name) {
let reverseRegistrar = createReverseRegistrar(domain.name!, domain.id, airBlock);
reverseRegistrar.save();
}
}
domain.lastUpdatedBlock = airBlock.id;
domain.save();
saveDomainEntity(domain, airBlock);
//new name registered event
}

Expand Down Expand Up @@ -496,8 +476,7 @@ export namespace domain {

if (domain.resolver == resolver.id) {
domain.resolvedAddress = addrAccount.id;
domain.lastUpdatedBlock = airBlock.id;
domain.save();
saveDomainEntity(domain, airBlock);
let txn = getOrCreateAirResolvedAddressChanged(
chainId,
logOrCallIndex,
Expand Down Expand Up @@ -533,8 +512,7 @@ export namespace domain {
resolver.save();
if (domain && domain.resolver == resolver.id) {
domain.resolvedAddress = null
domain.lastUpdatedBlock = airBlock.id;
domain.save();
saveDomainEntity(domain, airBlock);
}
}

Expand Down Expand Up @@ -565,6 +543,7 @@ export namespace domain {
let domain = getOrCreateAirDomain(new Domain(reverseRegistrar.domain, chainId, airBlock, tokenAddress));
let fromAccount = getOrCreateAirAccount(chainId, from, airBlock);
fromAccount.save();
let oldPrimaryDomain: AirDomain | null = null;
// when domain's resolvedAddress is set as from address
if (domain.resolvedAddress == fromAccount.id) {
// get or create primary domain entity
Expand All @@ -573,24 +552,23 @@ export namespace domain {
if (primaryDomainEntity.domain != domain.id) {
log.info("Primary domain already exists for resolvedAddressId {} oldDomain {} newDomain {}", [fromAccount.id, primaryDomainEntity.domain, domain.id])
// unset isPrimary on old domain
let oldPrimaryDomain = getOrCreateAirDomain(new Domain(primaryDomainEntity.domain, chainId, airBlock, tokenAddress));
oldPrimaryDomain = getOrCreateAirDomain(new Domain(primaryDomainEntity.domain, chainId, airBlock, tokenAddress));
oldPrimaryDomain.isPrimary = false;
oldPrimaryDomain.lastUpdatedBlock = airBlock.id;
oldPrimaryDomain.save();
saveDomainEntity(oldPrimaryDomain, airBlock);
// set new primary domain for resolved address
primaryDomainEntity.domain = domain.id;
primaryDomainEntity.lastUpdatedAt = airBlock.id;
primaryDomainEntity.save();
}
primaryDomainEntity.save();
// set isPrimary on new domain
domain.isPrimary = true;
domain.lastUpdatedBlock = airBlock.id;
domain.save();
saveDomainEntity(domain, airBlock);
}
// record a set primary domain transaction with new domain
let txn = getOrCreateAirPrimaryDomainTransaction(
airBlock,
transactionHash,
oldPrimaryDomain,
domain,
from,
chainId,
Expand Down Expand Up @@ -629,6 +607,7 @@ export namespace domain {
* @dev This function gets or creates a air primary domain transaction
* @param block air block
* @param transactionHash transaction hash
* @param previousDomain previous domain or null
* @param domain air domain
* @param resolvedAddress domain resolved address
* @param chainId chain id
Expand All @@ -637,6 +616,7 @@ export namespace domain {
function getOrCreateAirPrimaryDomainTransaction(
block: AirBlock,
transactionHash: string,
previousDomain: AirDomain | null,
domain: AirDomain,
resolvedAddress: string,
chainId: string,
Expand All @@ -648,6 +628,9 @@ export namespace domain {
entity.block = block.id;
entity.transactionHash = transactionHash;
entity.tokenId = domain.tokenId;
if (previousDomain != null) {
entity.previousDomain = previousDomain.id;
}
entity.domain = domain.id;
entity.index = updateAirEntityCounter(AIR_SET_PRIMARY_DOMAIN_ENTITY_COUNTER_ID, block);
let resolvedAddressAccount = getOrCreateAirAccount(chainId, resolvedAddress, block); //make sure to remove the old primary ens if changed
Expand Down Expand Up @@ -960,7 +943,7 @@ export namespace domain {
* @param domain Domain class object
* @returns AirDomain entity
*/
function getOrCreateAirDomain(
export function getOrCreateAirDomain(
domain: Domain,
): AirDomain {
let entity = AirDomain.load(domain.id);
Expand Down Expand Up @@ -1047,8 +1030,7 @@ export namespace domain {
const parentDomain = getOrCreateAirDomain(new Domain(domain.parent!, chainId, block, tokenAddress));
if (parentDomain) {
parentDomain.subdomainCount = parentDomain.subdomainCount.minus(BIGINT_ONE)
parentDomain.lastUpdatedBlock = block.id;
parentDomain.save();
saveDomainEntity(parentDomain, block);
recurseSubdomainCountDecrement(parentDomain, chainId, block, tokenAddress)
}
}
Expand Down
40 changes: 40 additions & 0 deletions airstack-modules/modules/airstack/domain-name/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { log } from "@graphprotocol/graph-ts";
import {
AirExtra,
AirDomain,
AirBlock,
} from "../../../generated/schema";
import {
updateAirEntityCounter
} from "../common/index";

export const AIR_DOMAIN_OWNER_CHANGED_ENTITY_COUNTER_ID = "AIR_DOMAIN_OWNER_CHANGED_ENTITY_COUNTER";
export const AIR_DOMAIN_TRANSFER_ENTITY_COUNTER_ID = "AIR_DOMAIN_TRANSFER_ENTITY_COUNTER";
Expand All @@ -11,6 +17,8 @@ export const AIR_NAME_RENEWED_ENTITY_COUNTER_ID = "AIR_NAME_RENEWED_ENTITY_COUNT
export const AIR_ADDR_CHANGED_ENTITY_COUNTER_ID = "AIR_ADDR_CHANGED_ENTITY_COUNTER";
export const AIR_SET_PRIMARY_DOMAIN_ENTITY_COUNTER_ID = "AIR_SET_PRIMARY_DOMAIN_ENTITY_COUNTER";

export const AIR_DOMAIN_LAST_UPDATED_INDEX_ENTITY_COUNTER_ID = "AIR_DOMAIN_LAST_UPDATED_INDEX_ENTITY_COUNTER";

export const AIR_META_ID = "AIR_META";
export const ETHEREUM_MAINNET_ID = "1";
export const AIR_EXTRA_TTL = 'ttl';
Expand Down Expand Up @@ -38,4 +46,36 @@ export function createAirExtra(
entity.value = value;
}
return entity as AirExtra;
}

//specific to ens
/**
* @dev this function is used to check if the label is valid to prevent homoglyph attacks (which ens is prone to)
* @param name ens label name
* @param txHash transaction hash
* @returns boolean - true if label is valid
*/
export function checkValidLabel(name: string, txHash: string): boolean {
for (let i = 0; i < name.length; i++) {
let c = name.charCodeAt(i);
if (c === 0) {
log.warning("Invalid label '{}' contained null byte. Skipping. txhash {}", [name, txHash]);
return false;
} else if (c === 46) {
log.warning("Invalid label '{}' contained separator char '.'. Skipping. txhash {}", [name, txHash]);
return false;
}
}
return true;
}

/**
* @dev this function is used to save air domain entity and update the last updated index and block
* @param domain air domain entity to be saved
* @param airBlock air block entity
*/
export function saveDomainEntity(domain: AirDomain, airBlock: AirBlock): void {
domain.lastUpdatedIndex = updateAirEntityCounter(AIR_DOMAIN_LAST_UPDATED_INDEX_ENTITY_COUNTER_ID, airBlock);
domain.lastUpdatedBlock = airBlock.id;
domain.save();
}
4 changes: 2 additions & 2 deletions airstack-modules/modules/airstack/nft-marketplace/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
```
1. Track NFT trade transaction
trackNFTSaleTransactions(
block: string, #block ethereum block
block: ethereum.Block, #block ethereum block
transactionHash: string, #transaction hash
logOrCallIndex: BigInt, #transaction index - call or log index
sale: Sale, #sale object
protocolType: string #protocol type (eg: NFT_MARKET_PLACE)
protocolType: string, #protocol type (eg: NFT_MARKET_PLACE)
protocolActionType: string, #protocol action type - ["BUY", "SELL"]
)
```
Expand Down
Loading