Skip to content

Commit

Permalink
added TokenSaleTierBuyHistory
Browse files Browse the repository at this point in the history
  • Loading branch information
kevandee committed Oct 24, 2023
1 parent 350ceea commit 6b914d8
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 16 deletions.
2 changes: 1 addition & 1 deletion AllInteractions/src/entities/global/globals.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const PRICE_FEED_ADDRESS = "0x7Bc604663D1cedB045d746fF3BE50d0380E1a69c";
export const PRICE_FEED_ADDRESS = "0x80852Edd95423C3BD37F94EF795e7Da8E1ED465e";
8 changes: 4 additions & 4 deletions AllInteractions/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 18 additions & 0 deletions DaoPools/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
29 changes: 29 additions & 0 deletions DaoPools/src/entities/TokenSaleTierBuyHistory.ts
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion DaoPools/src/entities/global/globals.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
9 changes: 6 additions & 3 deletions DaoPools/src/mappings/TokenSale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<Bytes>(tier.buyers, [
getVoterInPool(pool, getVoter(event.params.buyer), event.block.timestamp).id,
]);
tier.buyers = pushUnique<Bytes>(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();
Expand Down
8 changes: 4 additions & 4 deletions DaoPools/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
50 changes: 50 additions & 0 deletions DaoPools/tests/TokenSale.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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", () => {
Expand Down
2 changes: 1 addition & 1 deletion DaoValidators/src/entities/global/globals.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const PRICE_FEED_ADDRESS = "0x7Bc604663D1cedB045d746fF3BE50d0380E1a69c";
export const PRICE_FEED_ADDRESS = "0x80852Edd95423C3BD37F94EF795e7Da8E1ED465e";
4 changes: 2 additions & 2 deletions DaoValidators/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6b914d8

Please sign in to comment.