Skip to content

Commit

Permalink
Merge branch 'feature/add-contracts-v2'
Browse files Browse the repository at this point in the history
  • Loading branch information
KONFeature committed Jun 13, 2024
2 parents 15f27c6 + 4c94b0a commit 473b7d2
Show file tree
Hide file tree
Showing 10 changed files with 3,017 additions and 149 deletions.
651 changes: 651 additions & 0 deletions abis/frak-campaign-abis.ts

Large diffs are not rendered by default.

1,172 changes: 1,172 additions & 0 deletions abis/frak-interaction-abis.ts

Large diffs are not rendered by default.

850 changes: 850 additions & 0 deletions abis/frak-registry-abis.ts

Large diffs are not rendered by default.

61 changes: 50 additions & 11 deletions ponder.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { createConfig } from "@ponder/core";
import { http } from "viem";
import { erc20ABI } from "./abis/erc20ABI";
import { createConfig, mergeAbis } from "@ponder/core";
import { http, parseAbiItem } from "viem";
import {
contentInteractionDiamondAbi,
contentInteractionManagerAbi,
dappStorageFacetAbi,
pressInteractionFacetAbi,
} from "./abis/frak-interaction-abis";
import { contentRegistryAbi } from "./abis/frak-registry-abis";
import { multiWebAuthNValidatorV2Abi } from "./abis/multiWebAuthNValidatorABI";

const pollingConfig = {
Expand Down Expand Up @@ -43,16 +49,10 @@ export default createConfig({
},
},
contracts: {
// The erc20 tokens to index
ERC20: {
abi: erc20ABI,
network: "arbitrumSepolia",
address: "0x9584A61F70cC4BEF5b8B5f588A1d35740f0C7ae2",
startBlock: 29562417,
},
// The WebAuthN validator to index
WebAuthNValidator: {
abi: multiWebAuthNValidatorV2Abi,
address: "0xD546c4Ba2e8e5e5c961C36e6Db0460Be03425808",
network: {
arbitrumSepolia: {
startBlock: 35765963,
Expand All @@ -70,7 +70,46 @@ export default createConfig({
startBlock: 56157675,
},*/
},
address: "0xD546c4Ba2e8e5e5c961C36e6Db0460Be03425808",
},
// The content registry
ContentRegistry: {
abi: contentRegistryAbi,
address: "0xC110ecb55EbAa4Ea9eFC361C4bBB224A6664Ea45",
network: {
arbitrumSepolia: {
startBlock: 54321880,
},
},
},
// The interaction manager
ContentInteractionManager: {
abi: contentInteractionManagerAbi,
address: "0x603674006fE11c38449C22bA56c40444C8e4CC5C",
network: {
arbitrumSepolia: {
startBlock: 54321880,
},
},
},
// Every content interactions
ContentInteraction: {
abi: mergeAbis([
contentInteractionDiamondAbi,
pressInteractionFacetAbi,
dappStorageFacetAbi,
]),
factory: {
address: "0x603674006fE11c38449C22bA56c40444C8e4CC5C",
event: parseAbiItem(
"event InteractionContractDeployed(uint256 indexed contentId, address interactionContract)"
),
parameter: "interactionContract",
},
network: {
arbitrumSepolia: {
startBlock: 54321880,
},
},
},
},
});
150 changes: 82 additions & 68 deletions ponder.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,9 @@ export default createSchema((p) => ({
// Id the wallet address
id: p.hex(),

// The linked token Balance
balances: p.many("TokenBalance.accountId"),

// The linked transfer events
transferFromEvents: p.many("TransferEvent.fromId"),
transferToEvents: p.many("TransferEvent.toId"),

// The linked webauthn validators
validators: p.many("MultiWebAuthNValidator.accountId"),
}),
// Token we are tracking
Token: p.createTable(
{
// Id the token address + chain id
id: p.hex(),
address: p.hex(),
chain: p.int(),
},
{
// Indexes
chainIndex: p.index("chain"),
// Address index
addressIndex: p.index("address"),
}
),
// Token balance for each users
TokenBalance: p.createTable(
{
// Id the token address + user address + chain id
id: p.hex(),

balance: p.bigint(),

// The account this balance is linked to
accountId: p.hex().references("Account.id"),
account: p.one("accountId"),

// The token this balance is linked to
tokenId: p.hex().references("Token.id"),
token: p.one("tokenId"),
},
{
accountIndex: p.index("accountId"),
tokenIndex: p.index("tokenId"),
}
),
// Validator we are tracking
MultiWebAuthNValidator: p.createTable({
// Id is a concatenation of chain + account address
Expand Down Expand Up @@ -79,31 +36,6 @@ export default createSchema((p) => ({
changeLogEvents: p.many("PasskeyChangeLogEvent.passkeyId"),
}),

// Erc20 Transfer events
TransferEvent: p.createTable(
{
id: p.string(),
amount: p.bigint(),

tokenId: p.hex().references("Token.id"),
token: p.one("tokenId"),

timestamp: p.int(),

fromId: p.hex().references("Account.id"),
toId: p.hex().references("Account.id"),

from: p.one("fromId"),
to: p.one("toId"),
},
{
// From and to indexes
fromIndex: p.index("fromId"),
toIndex: p.index("toId"),
// Search indexes
tokenIndex: p.index("tokenId"),
}
),
// WebAuthN Validator related events
PrimaryPasskeyChangedEvent: p.createTable({
id: p.string(),
Expand All @@ -124,4 +56,86 @@ export default createSchema((p) => ({
timestamp: p.int(),
chain: p.int(),
}),

// Content related stuff
Content: p.createTable({
id: p.bigint(),

domain: p.string(),
contentTypes: p.bigint(),
name: p.string(),

createTimestamp: p.bigint(),
lastUpdateTimestamp: p.bigint().optional(),

interactionContracts: p.many("ContentInteractionContract.contentId"),

campaignsLink: p.many("CampaignToContent.contentId"),
administrators: p.many("ContentAdministrator.contentId"),
}),

// Content related stuff
ContentAdministrator: p.createTable({
id: p.hex(),

contentId: p.bigint().references("Content.id"),
content: p.one("contentId"),

isOwner: p.boolean(),
user: p.hex(),

createdTimestamp: p.bigint(),
}),

// Interaction related
ContentInteractionContract: p.createTable({
id: p.hex(), // address

contentId: p.bigint().references("Content.id"),
content: p.one("contentId"),

createdTimestamp: p.bigint(),
lastUpdateTimestamp: p.bigint().optional(),
removedTimestamp: p.bigint().optional(),
}),

// Campaign related
Campaign: p.createTable({
id: p.hex(),

name: p.string(),
version: p.string(),

attachments: p.many("CampaignToContent.campaignId"),
}),
CampaignToContent: p.createTable({
id: p.string(), // address

campaignId: p.hex().references("Campaign.id"),
campaign: p.one("campaignId"),

contentId: p.bigint().references("Content.id"),
content: p.one("contentId"),

attached: p.boolean(),

attachTimestamp: p.bigint(),
detachTimestamp: p.bigint().optional(),
}),

// Press events
PressEvent: p.createTable({
id: p.string(),

interactionId: p.hex().references("ContentInteractionContract.id"),
interaction: p.one("interactionId"),

user: p.hex(),
type: p.enum("PressEventType"),
data: p.json(),

timestamp: p.bigint(),
}),

PressEventType: p.createEnum(["OPEN_ARTICLE", "READ_ARTICLE", "REFERRED"]),
}));
65 changes: 65 additions & 0 deletions src/content.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { ponder } from "@/generated";
import {
type Address,
type Hex,
isAddressEqual,
keccak256,
toHex,
zeroAddress,
} from "viem";

ponder.on("ContentRegistry:ContentMinted", async ({ event, context }) => {
const { Content } = context.db;

// Create the content
await Content.create({
id: event.args.contentId,
data: {
name: event.args.name,
domain: event.args.domain,
contentTypes: event.args.contentTypes,
createTimestamp: event.block.timestamp,
},
});
});

ponder.on("ContentRegistry:ContentUpdated", async ({ event, context }) => {
const { Content } = context.db;

// Update the content
await Content.update({
id: event.args.contentId,
data: {
name: event.args.name,
contentTypes: event.args.contentTypes,
lastUpdateTimestamp: event.block.timestamp,
},
});
});

ponder.on("ContentRegistry:Transfer", async ({ event, context }) => {
const { ContentAdministrator } = context.db;

// Delete the previous administrator
if (!isAddressEqual(event.args.from, zeroAddress)) {
await ContentAdministrator.delete({
id: contentAdministratorId(event.args.id, event.args.from),
});
}

// Create the new administrator
await ContentAdministrator.create({
id: contentAdministratorId(event.args.id, event.args.to),
data: {
isOwner: true,
contentId: event.args.id,
user: event.args.to,
createdTimestamp: event.block.timestamp,
},
});
});

// todo: manage approval
function contentAdministratorId(contentId: bigint, user: Address): Hex {
return keccak256(`${toHex(contentId)}-${user}`);
}
70 changes: 0 additions & 70 deletions src/erc20.ts

This file was deleted.

Loading

0 comments on commit 473b7d2

Please sign in to comment.