From 6b914d80e4a59f07a63d5d80df1a50bcbcb3c3f5 Mon Sep 17 00:00:00 2001 From: kevandee Date: Tue, 24 Oct 2023 11:46:20 +0300 Subject: [PATCH] added TokenSaleTierBuyHistory --- .../src/entities/global/globals.ts | 2 +- AllInteractions/subgraph.yaml | 8 +-- DaoPools/schema.graphql | 18 +++++++ .../src/entities/TokenSaleTierBuyHistory.ts | 29 +++++++++++ DaoPools/src/entities/global/globals.ts | 2 +- DaoPools/src/mappings/TokenSale.ts | 9 ++-- DaoPools/subgraph.yaml | 8 +-- DaoPools/tests/TokenSale.test.ts | 50 +++++++++++++++++++ DaoValidators/src/entities/global/globals.ts | 2 +- DaoValidators/subgraph.yaml | 4 +- 10 files changed, 116 insertions(+), 16 deletions(-) create mode 100644 DaoPools/src/entities/TokenSaleTierBuyHistory.ts diff --git a/AllInteractions/src/entities/global/globals.ts b/AllInteractions/src/entities/global/globals.ts index 848bfb1..621ea99 100644 --- a/AllInteractions/src/entities/global/globals.ts +++ b/AllInteractions/src/entities/global/globals.ts @@ -1 +1 @@ -export const PRICE_FEED_ADDRESS = "0x7Bc604663D1cedB045d746fF3BE50d0380E1a69c"; +export const PRICE_FEED_ADDRESS = "0x80852Edd95423C3BD37F94EF795e7Da8E1ED465e"; diff --git a/AllInteractions/subgraph.yaml b/AllInteractions/subgraph.yaml index 209bf5a..26bde3d 100644 --- a/AllInteractions/subgraph.yaml +++ b/AllInteractions/subgraph.yaml @@ -6,9 +6,9 @@ dataSources: name: PoolFactory network: chapel source: - address: "0x433F3d397055503fB2320584b9F027931ECba762" + address: "0xc5A750E8e3361D186236D7f708Cb1C92b944Ce48" abi: PoolFactory - startBlock: 32954665 + startBlock: 34202816 mapping: kind: ethereum/events apiVersion: 0.0.6 @@ -27,9 +27,9 @@ dataSources: name: UserRegistry network: chapel source: - address: "0x4748e4e294c6e11D7Ff0062290628Caa56bACaB1" + address: "0x7d090C1a5A5f8f1742F32C15BeB03980B3bfb1Dc" abi: UserRegistry - startBlock: 32954665 + startBlock: 34202816 mapping: kind: ethereum/events apiVersion: 0.0.6 diff --git a/DaoPools/schema.graphql b/DaoPools/schema.graphql index 2484eaa..9274c4e 100644 --- a/DaoPools/schema.graphql +++ b/DaoPools/schema.graphql @@ -473,6 +473,24 @@ type TokenSaleTier @entity { tokenSale: TokenSaleContract! } +""" +The entity holds information about token buying +""" +type TokenSaleTierBuyHistory @entity { + "id forms from tx hash + interactionCount" + id: Bytes! + + "tx hash" + hash: Bytes! + "timestamp of token buying" + timestamp: BigInt! + + "The buyer VoterInPool entity id" + buyer: VoterInPool! + "The TokenSaleTier id" + tier: TokenSaleTier! +} + """ The entity counts interactions in single tx """ diff --git a/DaoPools/src/entities/TokenSaleTierBuyHistory.ts b/DaoPools/src/entities/TokenSaleTierBuyHistory.ts new file mode 100644 index 0000000..4b1c5fe --- /dev/null +++ b/DaoPools/src/entities/TokenSaleTierBuyHistory.ts @@ -0,0 +1,29 @@ +import { BigInt, Bytes } from "@graphprotocol/graph-ts"; +import { TokenSaleTierBuyHistory, TokenSaleTier, VoterInPool } from "../../generated/schema"; +import { increaseCounter } from "../helpers/IncreaseCounter"; +import { getInteractionCount } from "./global/InteractionCount"; + +export function getTokenSaleTierBuyHistory( + hash: Bytes, + timestamp: BigInt, + tokenSaleTier: TokenSaleTier, + buyer: VoterInPool +): TokenSaleTierBuyHistory { + let counter = getInteractionCount(hash); + let id = hash.concatI32(counter.count.toI32()); + + let history = TokenSaleTierBuyHistory.load(id); + + if (history == null) { + history = new TokenSaleTierBuyHistory(id); + + history.hash = hash; + history.timestamp = timestamp; + + history.buyer = buyer.id; + history.tier = tokenSaleTier.id; + increaseCounter(counter); + } + + return history; +} diff --git a/DaoPools/src/entities/global/globals.ts b/DaoPools/src/entities/global/globals.ts index a9275a4..33df940 100644 --- a/DaoPools/src/entities/global/globals.ts +++ b/DaoPools/src/entities/global/globals.ts @@ -1,6 +1,6 @@ import { BigInt } from "@graphprotocol/graph-ts"; -export const PRICE_FEED_ADDRESS = "0x7Bc604663D1cedB045d746fF3BE50d0380E1a69c"; +export const PRICE_FEED_ADDRESS = "0x80852Edd95423C3BD37F94EF795e7Da8E1ED465e"; export const BNB_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; export const WBNB_ADDRESS = "0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd"; export const DAY = 86400; diff --git a/DaoPools/src/mappings/TokenSale.ts b/DaoPools/src/mappings/TokenSale.ts index 70af7aa..99ad88f 100644 --- a/DaoPools/src/mappings/TokenSale.ts +++ b/DaoPools/src/mappings/TokenSale.ts @@ -7,6 +7,7 @@ import { getTokenSaleTier } from "../entities/TokenSaleTier"; import { getVoter } from "../entities/Voters/Voter"; import { getVoterInPool } from "../entities/Voters/VoterInPool"; import { push } from "../helpers/ArrayHelper"; +import { getTokenSaleTierBuyHistory } from "../entities/TokenSaleTierBuyHistory"; export function onTierCreated(event: TierCreated): void { let tokenSale = getTokenSale(event.address); @@ -28,15 +29,17 @@ export function onBought(event: Bought): void { let tokenSale = getTokenSale(event.address); let tier = getTokenSaleTier(tokenSale, event.params.tierId); let pool = getDaoPool(Address.fromBytes(tokenSale.daoPool)); + let buyer = getVoterInPool(pool, getVoter(event.params.buyer), event.block.timestamp); - tier.buyers = pushUnique(tier.buyers, [ - getVoterInPool(pool, getVoter(event.params.buyer), event.block.timestamp).id, - ]); + tier.buyers = pushUnique(tier.buyers, [buyer.id]); if (tier.buyers.length > tier.totalBuyersCount.toI32()) { tier.totalBuyersCount = tier.totalBuyersCount.plus(BigInt.fromI32(tier.buyers.length).minus(tier.totalBuyersCount)); } + getTokenSaleTierBuyHistory(event.transaction.hash, event.block.timestamp, tier, buyer).save(); + + buyer.save(); tokenSale.save(); tier.save(); pool.save(); diff --git a/DaoPools/subgraph.yaml b/DaoPools/subgraph.yaml index 40d911b..3432f5b 100644 --- a/DaoPools/subgraph.yaml +++ b/DaoPools/subgraph.yaml @@ -6,9 +6,9 @@ dataSources: name: PoolFactory network: chapel source: - address: "0x433F3d397055503fB2320584b9F027931ECba762" + address: "0xc5A750E8e3361D186236D7f708Cb1C92b944Ce48" abi: PoolFactory - startBlock: 32954665 + startBlock: 34202816 mapping: kind: ethereum/events apiVersion: 0.0.6 @@ -26,9 +26,9 @@ dataSources: name: ERC721Expert network: chapel source: - address: "0xBd5fd8866588FA0da3331Ab1587D39bBC0e89a8a" + address: "0x36841F49C19B08795f4d3CDd9AB722Be8A8843C9" abi: ERC721Expert - startBlock: 32954665 + startBlock: 34202816 mapping: kind: ethereum/events apiVersion: 0.0.6 diff --git a/DaoPools/tests/TokenSale.test.ts b/DaoPools/tests/TokenSale.test.ts index 5c72f04..e77d730 100644 --- a/DaoPools/tests/TokenSale.test.ts +++ b/DaoPools/tests/TokenSale.test.ts @@ -167,6 +167,31 @@ describe("TokenSale", () => { `[${user1.concat(poolAddress).toHexString()}]` ); + assert.fieldEquals( + "TokenSaleTierBuyHistory", + event.transaction.hash.concatI32(0).toHexString(), + "hash", + event.transaction.hash.toHexString() + ); + assert.fieldEquals( + "TokenSaleTierBuyHistory", + event.transaction.hash.concatI32(0).toHexString(), + "timestamp", + event.block.timestamp.toString() + ); + assert.fieldEquals( + "TokenSaleTierBuyHistory", + event.transaction.hash.concatI32(0).toHexString(), + "buyer", + user1.concat(poolAddress).toHexString() + ); + assert.fieldEquals( + "TokenSaleTierBuyHistory", + event.transaction.hash.concatI32(0).toHexString(), + "tier", + contractSender.concatI32(tierId.toI32()).toHexString() + ); + let user2 = Address.fromString("0xfF42F3B569cdB6dF9dC260473Ec2ef63Ca971d63"); event = createBought(tierId, user2, contractSender, block, tx); @@ -190,6 +215,31 @@ describe("TokenSale", () => { "buyers", `[${user1.concat(poolAddress).toHexString()}, ${user2.concat(poolAddress).toHexString()}]` ); + + assert.fieldEquals( + "TokenSaleTierBuyHistory", + event.transaction.hash.concatI32(1).toHexString(), + "hash", + event.transaction.hash.toHexString() + ); + assert.fieldEquals( + "TokenSaleTierBuyHistory", + event.transaction.hash.concatI32(1).toHexString(), + "timestamp", + event.block.timestamp.toString() + ); + assert.fieldEquals( + "TokenSaleTierBuyHistory", + event.transaction.hash.concatI32(1).toHexString(), + "buyer", + user2.concat(poolAddress).toHexString() + ); + assert.fieldEquals( + "TokenSaleTierBuyHistory", + event.transaction.hash.concatI32(1).toHexString(), + "tier", + contractSender.concatI32(tierId.toI32()).toHexString() + ); }); test("should add user to whitelist", () => { diff --git a/DaoValidators/src/entities/global/globals.ts b/DaoValidators/src/entities/global/globals.ts index 848bfb1..621ea99 100644 --- a/DaoValidators/src/entities/global/globals.ts +++ b/DaoValidators/src/entities/global/globals.ts @@ -1 +1 @@ -export const PRICE_FEED_ADDRESS = "0x7Bc604663D1cedB045d746fF3BE50d0380E1a69c"; +export const PRICE_FEED_ADDRESS = "0x80852Edd95423C3BD37F94EF795e7Da8E1ED465e"; diff --git a/DaoValidators/subgraph.yaml b/DaoValidators/subgraph.yaml index 75497b2..c3892eb 100644 --- a/DaoValidators/subgraph.yaml +++ b/DaoValidators/subgraph.yaml @@ -6,9 +6,9 @@ dataSources: name: PoolFactory network: chapel source: - address: "0x433F3d397055503fB2320584b9F027931ECba762" + address: "0xc5A750E8e3361D186236D7f708Cb1C92b944Ce48" abi: PoolFactory - startBlock: 32954665 + startBlock: 34202816 mapping: kind: ethereum/events apiVersion: 0.0.6