Skip to content

Commit

Permalink
Feat/update grants data (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
aliXsed authored Dec 16, 2024
2 parents a3e656e + 76f8f5f commit adef145
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 60 deletions.
10 changes: 6 additions & 4 deletions subquery/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ services:
- 5432:5432
volumes:
- .data/postgres:/var/lib/postgresql/data
- ./docker/pg.conf:/usr/share/postgresql/postgresql.conf
command: ["postgres", "-c", "config_file=/usr/share/postgresql/postgresql.conf"]
environment:
POSTGRES_PASSWORD: postgres
shm_size: '1gb'
Expand Down Expand Up @@ -36,8 +38,8 @@ services:
- ${SUB_COMMAND:-} # set SUB_COMMAND env variable to "test" to run tests
- -f=/app
- --db-schema=app
- --workers=4
- --batch-size=30
- --workers=2
- --batch-size=20
- --unfinalized-blocks=false
- --unsafe
- --block-confirmations=0
Expand Down Expand Up @@ -67,9 +69,9 @@ services:
DB_DATABASE: postgres
DB_HOST: postgres
DB_PORT: 5432
# NODE_ENV: production
NODE_ENV: production
command:
- --name=app
#- --log-level=silent
- --playground
- --indexer=http://subquery-node:3000
- --indexer=http://subquery-node:3000
38 changes: 38 additions & 0 deletions subquery/docker/pg.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Custom conf for 4GB RAM and 2-4 cores
shared_buffers = 1GB
work_mem = 12MB
maintenance_work_mem = 128MB

effective_cache_size = 3GB
random_page_cost = 1.1
seq_page_cost = 1.0

max_connections = 50
max_worker_processes = 4
max_parallel_workers_per_gather = 2
max_parallel_workers = 4

autovacuum = on
autovacuum_naptime = 20s
autovacuum_vacuum_scale_factor = 0.2
autovacuum_analyze_scale_factor = 0.1
autovacuum_max_workers = 2

checkpoint_timeout = 10min
checkpoint_completion_target = 0.7
max_wal_size = 2GB
min_wal_size = 512MB

logging_collector = on
log_directory = 'pg_log'
log_filename = 'postgresql-%Y-%m-%d.log'
log_statement = 'none'
log_min_duration_statement = 1000

# open as it is in a container
listen_addresses = '*'
port = 5432

# adjust depeding on the resources available
parallel_setup_cost = 1000
parallel_tuple_cost = 0.1
8 changes: 4 additions & 4 deletions subquery/mainnet-click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const project: EthereumProject = {
kind: EthereumHandlerKind.Event,
handler: "handleTransfer",
filter: {
topics: ["Transfer(address from,address to,uint256 tokenId)"],
topics: ["Transfer(address,address,uint256)"],
},
},
],
Expand Down Expand Up @@ -133,7 +133,7 @@ const project: EthereumProject = {
kind: EthereumHandlerKind.Event,
handler: "handleTransfer",
filter: {
topics: ["Transfer(address from,address to,uint256 tokenId)"],
topics: ["Transfer(address,address,uint256)"],
},
},
],
Expand Down Expand Up @@ -189,7 +189,7 @@ const project: EthereumProject = {
kind: EthereumHandlerKind.Event,
handler: "handleTransfer",
filter: {
topics: ["Transfer(address from,address to,uint256 tokenId)"],
topics: ["Transfer(address,address,uint256)"],
},
},
],
Expand Down Expand Up @@ -245,7 +245,7 @@ const project: EthereumProject = {
kind: EthereumHandlerKind.Event,
handler: "handleTransfer",
filter: {
topics: ["Transfer(address from,address to,uint256 tokenId)"],
topics: ["Transfer(address,address,uint256)"],
},
},
],
Expand Down
4 changes: 2 additions & 2 deletions subquery/mainnet-complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const project: EthereumProject = {
startBlock: 42332281, // This is the block that the contract was deployed on
options: {
abi: "Grants",
address: "0xdAdF329E8b30D878b139074De163D3A591aAB394",
address: "0x5855c486d2381ba41762876f18684951d5902829",
},
assets: new Map([
[
Expand Down Expand Up @@ -197,7 +197,7 @@ const project: EthereumProject = {
startBlock: 42332281, // This is the block that the contract was deployed on
options: {
abi: "GrantsMigration",
address: "0xF81b3b954221BeDcf762cd18FEc1A22D25016B2E",
address: "0x1A89C10456A78a41B55c3aEAcfc865E079bE5690",
},
assets: new Map([
[
Expand Down
27 changes: 17 additions & 10 deletions subquery/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ type ERC721Token @entity @compositeIndexes(fields: [["owner", "contract"]]) {
transfers: [ERC721Transfer!]! @derivedFrom(field: "token")
application: String
duration: Int
captureDate: BigInt @index
longitude: Float @index
latitude: Float @index
captureDate: BigInt
longitude: Float
latitude: Float
locationPrecision: String
contentHash: String
}
Expand Down Expand Up @@ -239,6 +239,7 @@ type VestingSchedule @entity {
period: BigInt
periodCount: Int
perPeriodAmount: BigInt
total: BigInt
transaction: Transaction!
cancelled: Boolean
cancelTransaction: Transaction
Expand All @@ -251,6 +252,8 @@ type VestingSchedule @entity {
type VestingScheduleCanceled @entity {
id: ID!
beneficiary: Account! @index
start: BigInt
end: BigInt
cancelAuthority: Account @index
affectedVestingSchedules: [String!]
transaction: Transaction!
Expand All @@ -259,6 +262,8 @@ type VestingScheduleCanceled @entity {
type VestingScheduleRenounced @entity {
id: ID!
beneficiary: Account! @index
start: BigInt
end: BigInt
cancelAuthority: Account @index
affectedVestingSchedules: [String!]
transaction: Transaction!
Expand All @@ -267,6 +272,8 @@ type VestingScheduleRenounced @entity {
type VestingScheduleClaimed @entity {
id: ID!
beneficiary: Account! @index
start: BigInt
end: BigInt
amount: BigInt
transaction: Transaction!
}
Expand All @@ -284,9 +291,9 @@ type Reward @entity {
amount: BigInt @index
transaction: Transaction!
BatchMetadata: BatchMetadata
sequence: BigInt @index
status: Boolean @index
signature: String @index
sequence: BigInt
status: Boolean
signature: String
}

type AccountSnapshot @entity {
Expand Down Expand Up @@ -328,10 +335,10 @@ type TokenSnapshotV2 @entity {
tokensMinted: Int!
fistBlockTimestamp: BigInt! @index
latestBlockTimestamp: BigInt @index
latestBlockNumber: Int @index
firstBlockNumber: Int! @index
firstToken: ERC721Token! @index
latestToken: ERC721Token @index
latestBlockNumber: Int
firstBlockNumber: Int!
firstToken: ERC721Token!
latestToken: ERC721Token
}

type ERC20TransferV2 implements Event
Expand Down
15 changes: 7 additions & 8 deletions subquery/src/mappings/click-content-sign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
SafeMintTransaction,
} from "../types/abi-interfaces/ClickContentSignAbi";
import { fetchAccount, fetchMetadata, fetchTransaction } from "../utils/utils";
import { contractForSnapshot } from "../utils/const";
import { contractForSnapshot, nodleContracts } from "../utils/const";
import { TokenSnapshot, TokenSnapshotV2 } from "../types";

const keysMapping = {
Expand Down Expand Up @@ -85,8 +85,9 @@ export async function handleApprovalForAll(event: ApprovalForAllLog) {
}

export async function handleSafeMint(tx: SafeMintTransaction) {
assert(tx.args, "No tx.args");
assert(tx.logs, "No tx.logs");
if (!tx.args || !tx.logs) {
throw new Error("No tx.args or tx.logs");
}

// Call to the contract
const contract = await fetchContract(String(tx.to).toLowerCase());
Expand Down Expand Up @@ -123,12 +124,10 @@ export async function handleSafeMint(tx: SafeMintTransaction) {

token.uri = uri;

if (false) {
if (nodleContracts.includes(contract.id)) {
const metadata = await fetchMetadata(uri, [
"nodle-community-nfts.myfilebase.com",
"pinning.infura-ipfs.io",
"nodle-web-wallet.infura-ipfs.io",
"cloudflare-ipfs.com",
"nodle-community-nfts.myfilebase.com/ipfs",
"storage.googleapis.com/ipfs-backups",
]);

if (metadata) {
Expand Down
19 changes: 17 additions & 2 deletions subquery/src/mappings/grants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export async function handleClaimed(event: ClaimedLog): Promise<void> {
const who = event.args.who?.toString();
const amount = event.args.amount?.toBigInt();
const id = event.transactionHash + "-" + event.logIndex.toString();
const start = event.args.start?.toBigInt();
const end = event.args.end?.toBigInt();

const transaction = await fetchTransaction(
event.transactionHash,
Expand All @@ -31,6 +33,8 @@ export async function handleClaimed(event: ClaimedLog): Promise<void> {
const claimTransaction = new VestingScheduleClaimed(id, who, transaction.id);

claimTransaction.amount = amount;
claimTransaction.start = start;
claimTransaction.end = end;

await claimTransaction.save();
}
Expand All @@ -43,6 +47,8 @@ export async function handleRenounced(event: RenouncedLog): Promise<void> {

const to = event.args.to.toString();
const from = event.args.from.toString();
const start = event.args.start?.toBigInt();
const end = event.args.end?.toBigInt();
const id = event.transactionHash + "-" + event.logIndex.toString();
const transaction = await fetchTransaction(
event.transactionHash,
Expand All @@ -52,6 +58,9 @@ export async function handleRenounced(event: RenouncedLog): Promise<void> {

const action = new VestingScheduleRenounced(id, to, transaction.id);

action.start = start;
action.end = end;

const schedules = await VestingSchedule.getByCancelAuthorityId(from, { limit: 100 });

if (schedules && schedules.length > 0) {
Expand Down Expand Up @@ -82,19 +91,20 @@ export async function handleVestingScheduleAdded(
const id = event.transactionHash + "-" + event.logIndex.toString();
const to = event.args.to.toString();
const schedule = event.args.schedule;
logger.info("schedule: " + JSON.stringify(schedule) + " to: " + to);
const transaction = await fetchTransaction(
event.transactionHash,
event.block.timestamp,
BigInt(event.block.number)
);

const vestingSchedule = new VestingSchedule(id, to, transaction.id);

const total =
BigInt(schedule.periodCount) * schedule.perPeriodAmount.toBigInt();
vestingSchedule.start = schedule.start.toBigInt();
vestingSchedule.period = schedule.period.toBigInt();
vestingSchedule.periodCount = schedule.periodCount;
vestingSchedule.perPeriodAmount = schedule.perPeriodAmount.toBigInt();
vestingSchedule.total = total;

vestingSchedule.cancelAuthorityId = schedule.cancelAuthority?.toString();

Expand All @@ -111,6 +121,8 @@ export async function handleVestingSchedulesCanceled(

const from = event.args.from.toString();
const to = event.args.to.toString();
const start = event.args.start?.toBigInt();
const end = event.args.end?.toBigInt();
const id = event.transactionHash + "-" + event.logIndex.toString();

const transaction = await fetchTransaction(
Expand All @@ -121,6 +133,9 @@ export async function handleVestingSchedulesCanceled(

const action = new VestingScheduleCanceled(id, to, transaction.id);

action.start = start;
action.end = end;

const schedules = await VestingSchedule.getByCancelAuthorityId(from, { limit: 100 });

if (schedules && schedules.length > 0) {
Expand Down
2 changes: 0 additions & 2 deletions subquery/src/mappings/migration-nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export async function handleNFTTransfer(event: TransferLog): Promise<void> {
]).catch((error) => {
return null;
});
logger.info("Token URI: " + String(tokenUri));

if (tokenUri && nodleContracts.includes(contract.id)) {
const metadata = await fetchMetadata(String(tokenUri), [
Expand Down Expand Up @@ -95,7 +94,6 @@ export async function handleApproval(event: ApprovalLog): Promise<void> {
]).catch((error) => {
return null;
});
logger.info("Token URI: " + String(tokenUri));
if (tokenUri && nodleContracts.includes(contract.id)) {
const metadata = await fetchMetadata(String(tokenUri), [
"nodle-community-nfts.myfilebase.com/ipfs",
Expand Down
3 changes: 0 additions & 3 deletions subquery/src/utils/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ export const fetchContract = async (
const contract = await ERC20Contract.get(lowercaseAddress);

if (!contract) {
logger.error(
`Contract not found for lowercaseAddress: ${lowercaseAddress}`
);
const newContract = new ERC20Contract(lowercaseAddress, lowercaseAddress);
newContract.save();

Expand Down
9 changes: 3 additions & 6 deletions subquery/src/utils/erc721.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ export const fetchContract = async (
const contract = await ERC721Contract.get(lowercaseAddress);

if (!contract) {
logger.error(
`Contract not found for lowercaseAddress: ${lowercaseAddress}`
);
const newContract = new ERC721Contract(lowercaseAddress, lowercaseAddress);
newContract.save();

Expand All @@ -33,7 +30,6 @@ export const fetchToken = async (
const token = await ERC721Token.get(id);

if (!token) {
logger.error(`Token not found for id: ${id}`);
const newToken = new ERC721Token(
id,
contractId,
Expand All @@ -54,7 +50,9 @@ export const getApprovalLog = (
address: string
) => {
const targetLog = logs.find((log) => log.args?.to === address);
assert(targetLog, "No target log found");
if (!targetLog) {
throw new Error("Approval log not found");
}

return targetLog.args;
};
Expand All @@ -73,7 +71,6 @@ export const fetchERC721Operator = async (
const op = await ERC721Operator.get(id);

if (!op) {
logger.error(`Operator not found for id: ${id}`);
const newOp = new ERC721Operator(
id,
contract.id,
Expand Down
3 changes: 0 additions & 3 deletions subquery/src/utils/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ export const fetchContract = async (
const contract = await ProposalContract.get(lowercaseAddress);

if (!contract) {
logger.error(
`Contract not found for lowercaseAddress: ${lowercaseAddress}`
);
const newContract = new ProposalContract(
lowercaseAddress,
lowercaseAddress
Expand Down
Loading

0 comments on commit adef145

Please sign in to comment.