Skip to content

Commit

Permalink
feat(Names): Track dao earnings from DCLControllerV2 (decentraland#1477)
Browse files Browse the repository at this point in the history
* feat: Track dao earnings from DCLControllerV2

* feat: Use new controller

* feat: Deploy to testnet subgraphs

* chore: Update controller mainnet block num

* chore: Deploy satsuma mainnet

* chore: Update temp and mainnet hashes
  • Loading branch information
fzavalia authored Apr 13, 2023
1 parent 8b2f139 commit 74aafc3
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 9 deletions.
21 changes: 21 additions & 0 deletions indexer/.subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,27 @@ dataSources:
eventHandlers:
- event: NameRegistered(indexed address,indexed address,indexed bytes32,string,uint256)
handler: handleNameRegistered

- kind: ethereum/contract
name: DCLControllerV2
network: {{network}}
source:
address: '{{address:DCLControllerV2}}'
abi: DCLControllerV2
startBlock: {{startBlock:DCLControllerV2}}
mapping:
kind: ethereum/events
apiVersion: 0.0.4
language: wasm/assemblyscript
file: ./src/handlers/ens.ts
entities:
- DCLControllerV2
abis:
- name: DCLControllerV2
file: ./abis/DCLControllerV2.json
eventHandlers:
- event: NameBought(indexed address,indexed address,uint256,string)
handler: handleNameBought

# ---------------------------------------------------------
# BIDS ----------------------------------------------------
Expand Down
9 changes: 5 additions & 4 deletions indexer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

|Network|URL|Current|Previous|
|-|-|-|-|
|Mainnet (Hosted Services)|https://thegraph.com/hosted-service/subgraph/decentraland/marketplace|Qmf8fcWxGiKcxffcWRfhbAb36HEvXFNXsoRunuf4sPR1Bp|QmR9z6HJpRP9tSPLNPWkQ67JbDP4wzM4hBVkWmbgdKBCuo|
|Mainnet (Satsuma)|https://subgraph.satsuma-prod.com/decentraland/marketplace/playground|Qmf8fcWxGiKcxffcWRfhbAb36HEvXFNXsoRunuf4sPR1Bp|QmR9z6HJpRP9tSPLNPWkQ67JbDP4wzM4hBVkWmbgdKBCuo|
|Mainnet Temp (Hosted Services)|https://thegraph.com/hosted-service/subgraph/decentraland/marketplace-temp|QmR9z6HJpRP9tSPLNPWkQ67JbDP4wzM4hBVkWmbgdKBCuo|QmccAwofKfT9t4XKieDqwZre1UUZxuHw5ynB35BHwHAJDT|
|Goerli (Hosted Services)|https://thegraph.com/hosted-service/subgraph/decentraland/marketplace-goerli|QmRDXpMaGDL2Sq9Jfw7VfPz6aTfJNorEcY5LfhyQGgHeRY|QmfBfuQvcwpvf6da8A2LeWXvTrnu99H9fv6RLUCyYAFECJ|
|Mainnet (Hosted Services)|https://thegraph.com/hosted-service/subgraph/decentraland/marketplace|QmPdVPhDvK3bs8cmUeFeMAYRYky6yqYE9jYwpcMdi4QCdB|Qmf8fcWxGiKcxffcWRfhbAb36HEvXFNXsoRunuf4sPR1Bp|
|Mainnet (Satsuma)|https://subgraph.satsuma-prod.com/decentraland/marketplace/playground|QmPdVPhDvK3bs8cmUeFeMAYRYky6yqYE9jYwpcMdi4QCdB|Qmf8fcWxGiKcxffcWRfhbAb36HEvXFNXsoRunuf4sPR1Bp|
|Mainnet Temp (Hosted Services)|https://thegraph.com/hosted-service/subgraph/decentraland/marketplace-temp|QmPT9v6EsqqCA8BzrYtArJL54mVgfH81FzFTX2gLv9XcSp|QmR9z6HJpRP9tSPLNPWkQ67JbDP4wzM4hBVkWmbgdKBCuo|
|Goerli (Hosted Services)|https://thegraph.com/hosted-service/subgraph/decentraland/marketplace-goerli|QmS2GCuAkzH2kNDYe2pA9HkRTPLpC5DpbXRqhQW93exZEM|QmRDXpMaGDL2Sq9Jfw7VfPz6aTfJNorEcY5LfhyQGgHeRY|
|Goerli (Satsuma)|https://subgraph.satsuma-prod.com/decentraland/marketplace-goerli/playground|QmS2GCuAkzH2kNDYe2pA9HkRTPLpC5DpbXRqhQW93exZEM|-|
|Ropsten (Hosted Services)|https://thegraph.com/hosted-service/subgraph/decentraland/marketplace-ropsten|QmZTADndoP4XRoWGVoQuaz8WTATx3UDXMn5SdE3GfkErkW|QmfHCGhLTZV8v2duxDkKtPZKMEdJM7X8YGRj2UvqmrAUBB|

Using [The Graph](https://thegraph.com) and [Satsuma](https://www.satsuma.xyz/)
Expand Down
135 changes: 135 additions & 0 deletions indexer/abis/DCLControllerV2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
[
{
"inputs": [
{ "internalType": "contract IERC20Token", "name": "_acceptedToken", "type": "address" },
{ "internalType": "contract IDCLRegistrar", "name": "_registrar", "type": "address" },
{ "internalType": "address", "name": "_feeCollector", "type": "address" },
{ "internalType": "address", "name": "_owner", "type": "address" }
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "_oldFeeCollector", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "_newFeeCollector", "type": "address" }
],
"name": "FeeCollectorChanged",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "_caller", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "_beneficiary", "type": "address" },
{ "indexed": false, "internalType": "uint256", "name": "_price", "type": "uint256" },
{ "indexed": false, "internalType": "string", "name": "_name", "type": "string" }
],
"name": "NameBought",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" }
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"constant": true,
"inputs": [],
"name": "PRICE",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "acceptedToken",
"outputs": [{ "internalType": "contract IERC20Token", "name": "", "type": "address" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "feeCollector",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "isOwner",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "owner",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "string", "name": "_name", "type": "string" },
{ "internalType": "address", "name": "_beneficiary", "type": "address" }
],
"name": "register",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "registrar",
"outputs": [{ "internalType": "contract IDCLRegistrar", "name": "", "type": "address" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "renounceOwnership",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [{ "internalType": "address", "name": "_feeCollector", "type": "address" }],
"name": "setFeeCollector",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }],
"name": "transferOwnership",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}
]
12 changes: 8 additions & 4 deletions indexer/scripts/buildData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ enum ContractName {
LANDProxy = 'LANDProxy',
EstateProxy = 'EstateProxy',
MarketplaceProxy = 'MarketplaceProxy',
DCLRegistrar = 'DCLRegistrar'
DCLRegistrar = 'DCLRegistrar',
DCLControllerV2 = 'DCLControllerV2'
}
type ContractsResponse = Record<Network, Record<ContractName, string>>

Expand All @@ -25,23 +26,26 @@ const startBlockByNetwork: Record<Network, Record<ContractName, number>> = {
LANDProxy: 4944642,
EstateProxy: 6236547,
MarketplaceProxy: 6496012,
DCLRegistrar: 9412979
DCLRegistrar: 9412979,
DCLControllerV2: 16977347
},
[Network.ROPSTEN]: {
MANAToken: 1891200,
ERC721Bid: 5058246,
LANDProxy: 2482847,
EstateProxy: 3890399,
MarketplaceProxy: 4202120,
DCLRegistrar: 7170497
DCLRegistrar: 7170497,
DCLControllerV2: 7170497
},
[Network.GOERLI]: {
MANAToken: 4045806,
ERC721Bid: 7098754,
LANDProxy: 7059003,
EstateProxy: 7059236,
MarketplaceProxy: 7097561,
DCLRegistrar: 7098224
DCLRegistrar: 7098224,
DCLControllerV2: 8767204
}
}

Expand Down
10 changes: 10 additions & 0 deletions indexer/src/handlers/ens.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { NameRegistered } from '../entities/DCLRegistrar/DCLRegistrar'
import { NameBought } from '../entities/DCLControllerV2/DCLControllerV2'
import { ENS, NFT } from '../entities/schema'
import { getNFTId } from '../modules/nft'
import { getTokenIdFromLabelHash } from '../modules/ens'
import { createOrLoadAccount } from '../modules/account'
import { toLowerCase } from '../modules/utils'
import { getOrCreateAnalyticsDayData } from '../modules/analytics'
import * as categories from '../modules/category/categories'
import * as addresses from '../data/addresses'

Expand All @@ -29,3 +31,11 @@ export function handleNameRegistered(event: NameRegistered): void {

createOrLoadAccount(event.params._caller)
}

export function handleNameBought(event: NameBought): void {
let dayData = getOrCreateAnalyticsDayData(event.block.timestamp)

dayData.daoEarnings = dayData.daoEarnings.plus(event.params._price)

dayData.save()
}
2 changes: 1 addition & 1 deletion indexer/src/modules/analytics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function trackSale(
analyticsDayData.save()
}

function getOrCreateAnalyticsDayData(blockTimestamp: BigInt): AnalyticsDayData {
export function getOrCreateAnalyticsDayData(blockTimestamp: BigInt): AnalyticsDayData {
let timestamp = blockTimestamp.toI32()
let dayID = timestamp / 86400 // unix timestamp for start of day / 86400 giving a unique day index
let dayStartTimestamp = dayID * 86400
Expand Down

0 comments on commit 74aafc3

Please sign in to comment.