Skip to content

Commit

Permalink
⚡️ Campaign mangment simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
KONFeature committed Jul 1, 2024
1 parent 5953439 commit df4bc81
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 95 deletions.
43 changes: 6 additions & 37 deletions abis/frak-campaign-abis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ export const campaignFactoryAbi = [
{
type: "function",
inputs: [
{ name: "_identifier", internalType: "bytes4", type: "bytes4" },
{ name: "_owner", internalType: "address", type: "address" },
{
name: "_contentInteractionManager",
internalType: "address",
name: "_interaction",
internalType: "contract ContentInteractionDiamond",
type: "address",
},
{ name: "_owner", internalType: "address", type: "address" },
{ name: "_identifier", internalType: "bytes4", type: "bytes4" },
{ name: "_initData", internalType: "bytes", type: "bytes" },
],
name: "createCampaign",
Expand Down Expand Up @@ -62,19 +62,6 @@ export const campaignFactoryAbi = [
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

export const interactionCampaignAbi = [
{
type: "function",
inputs: [
{
name: "_interactionContract",
internalType: "address",
type: "address",
},
],
name: "allowInteractionContract",
outputs: [],
stateMutability: "nonpayable",
},
{
type: "function",
inputs: [],
Expand Down Expand Up @@ -312,11 +299,6 @@ export const referralCampaignAbi = [
type: "tuple",
components: [
{ name: "token", internalType: "address", type: "address" },
{
name: "referralTree",
internalType: "bytes32",
type: "bytes32",
},
{
name: "initialReward",
internalType: "uint256",
Expand Down Expand Up @@ -357,26 +339,13 @@ export const referralCampaignAbi = [
type: "address",
},
{
name: "_contentInterationManager",
internalType: "address",
name: "_interaction",
internalType: "contract ContentInteractionDiamond",
type: "address",
},
],
stateMutability: "nonpayable",
},
{
type: "function",
inputs: [
{
name: "_interactionContract",
internalType: "address",
type: "address",
},
],
name: "allowInteractionContract",
outputs: [],
stateMutability: "nonpayable",
},
{
type: "function",
inputs: [],
Expand Down
14 changes: 0 additions & 14 deletions abis/frak-interaction-abis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,20 +443,6 @@ export const contentInteractionManagerAbi = [
outputs: [],
stateMutability: "nonpayable",
},
{
type: "function",
inputs: [
{ name: "_contentId", internalType: "uint256", type: "uint256" },
{
name: "_campaign",
internalType: "contract InteractionCampaign",
type: "address",
},
],
name: "attachCampaign",
outputs: [],
stateMutability: "nonpayable",
},
{
type: "function",
inputs: [],
Expand Down
12 changes: 6 additions & 6 deletions ponder.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ export default createConfig({
// The interaction manager
ContentInteractionManager: {
abi: contentInteractionManagerAbi,
address: "0x76091A17B9f0C53Ea826E04bD5E586C143AFC30e",
address: "0xC97D72A8a9d1D2Ed326EB04f2d706A21cEe2B94E",
network: {
arbitrumSepolia: {
startBlock: 59205615,
startBlock: 60118981,
},
},
},
Expand All @@ -104,29 +104,29 @@ export default createConfig({
dappInteractionFacetAbi,
]),
factory: {
address: "0x76091A17B9f0C53Ea826E04bD5E586C143AFC30e",
address: "0xC97D72A8a9d1D2Ed326EB04f2d706A21cEe2B94E",
event: parseAbiItem(
"event InteractionContractDeployed(uint256 indexed contentId, address interactionContract)"
),
parameter: "interactionContract",
},
network: {
arbitrumSepolia: {
startBlock: 59205615,
startBlock: 60118981,
},
},
},
// Every campaigns
Campaigns: {
abi: mergeAbis([interactionCampaignAbi, referralCampaignAbi]),
factory: {
address: "0x719C9C48dB1622CF7F196012a269cDB96cBC044f",
address: "0x1f65A60340E4D017DdfeE45aA2905b6D79a55672",
event: parseAbiItem("event CampaignCreated(address campaign)"),
parameter: "campaign",
},
network: {
arbitrumSepolia: {
startBlock: 59205615,
startBlock: 60118981,
},
},
},
Expand Down
13 changes: 3 additions & 10 deletions ponder.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default createSchema((p) => ({

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

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

Expand Down Expand Up @@ -106,22 +106,15 @@ export default createSchema((p) => ({
name: p.string(),
version: p.string(),

attachments: p.many("CampaignToContent.campaignId"),
capResets: p.many("CampaignCapReset.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(),

capResets: p.many("CampaignCapReset.campaignId"),
}),
CampaignCapReset: p.createTable({
id: p.string(), // campaign address + timestamp
Expand Down
44 changes: 16 additions & 28 deletions src/interactionCampaign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { ponder } from "@/generated";
import { interactionCampaignAbi } from "../abis/frak-campaign-abis";

ponder.on("ContentInteraction:CampaignAttached", async ({ event, context }) => {
const { Campaign, CampaignToContent, ContentInteractionContract } =
context.db;
const { Campaign, ContentInteractionContract } = context.db;

// Find the interaction contract
const interactionContract = await ContentInteractionContract.findUnique({
Expand All @@ -15,42 +14,31 @@ ponder.on("ContentInteraction:CampaignAttached", async ({ event, context }) => {
return;
}

// Try to find the campaign
const campaign = await Campaign.findUnique({ id: event.args.campaign });
if (!campaign) {
// If not found, get the metadata and create it
const [name, version] = await context.client.readContract({
abi: interactionCampaignAbi,
address: event.args.campaign,
functionName: "getMetadata",
});
await Campaign.create({
id: event.args.campaign,
data: {
name,
version,
},
});
}

// Insert the content to campaign link
await CampaignToContent.create({
id: `${event.args.campaign}-${event.log.address}`,
data: {
campaignId: event.args.campaign,
// Get the metadata and create it
const [name, version] = await context.client.readContract({
abi: interactionCampaignAbi,
address: event.args.campaign,
functionName: "getMetadata",
});
await Campaign.upsert({
id: event.args.campaign,
create: {
name,
version,
contentId: interactionContract.contentId,
attached: true,
attachTimestamp: event.block.timestamp,
},
update: {},
});
});

ponder.on("ContentInteraction:CampaignDetached", async ({ event, context }) => {
const { CampaignToContent } = context.db;
const { Campaign } = context.db;

// Find the campaign to content and mark it as detached
await CampaignToContent.update({
id: `${event.args.campaign}-${event.log.address}`,
await Campaign.update({
id: event.args.campaign,
data: {
attached: false,
detachTimestamp: event.block.timestamp,
Expand Down

0 comments on commit df4bc81

Please sign in to comment.