Skip to content

feat: mod/client referrals #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/late-timers-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@mod-protocol/react": minor
"@mod-protocol/core": minor
---

feat: client and mod attribution in transactions
18 changes: 18 additions & 0 deletions .changeset/slow-goats-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
"@mods/infura-ipfs-upload": patch
"@mods/chatgpt-shorten": patch
"@mods/zora-nft-minter": patch
"@mods/livepeer-video": patch
"@mods/giphy-picker": patch
"@mods/image-render": patch
"@mods/imgur-upload": patch
"@mods/video-render": patch
"@mods/zora-create": patch
"@mods/nft-minter": patch
"@mods/url-render": patch
"@mods/chatgpt": patch
"@mods/dall-e": patch
"@mod-protocol/core": minor
---

fix: deprecate ENS support for `ModManifest` `custodyAddress` field
3 changes: 2 additions & 1 deletion examples/nextjs-shadcn/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ NEXT_PUBLIC_API_URL="http://localhost:3001/api"
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=""
NEXT_PUBLIC_URL="http://localhost:3000"
NEXT_PUBLIC_HOST="localhost:3000"
NEXT_PUBLIC_EXPERIMENTAL_MODS="false"
NEXT_PUBLIC_EXPERIMENTAL_MODS="false"
NEXT_PUBLIC_CLIENT_REFERRAL_ADDRESS=
3 changes: 3 additions & 0 deletions examples/nextjs-shadcn/src/app/editor-example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ import { useExperimentalMods } from "./use-experimental-mods";
// Optionally replace with your API_URL here
const API_URL =
process.env.NEXT_PUBLIC_API_URL ?? "https://api.modprotocol.org/api";
const CLIENT_REFERRAL_ADDRESS = process.env
.NEXT_PUBLIC_CLIENT_REFERRAL_ADDRESS as `0x${string}` | undefined;

const getMentions = getFarcasterMentions(API_URL);
const getChannels = getFarcasterChannels(API_URL);
Expand Down Expand Up @@ -217,6 +219,7 @@ export default function EditorExample() {
input={getText()}
embeds={getEmbeds()}
api={API_URL}
clientReferralAddress={CLIENT_REFERRAL_ADDRESS}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs to be changed in the docs as well

user={user}
variant="creation"
manifest={currentMod}
Expand Down
3 changes: 3 additions & 0 deletions examples/nextjs-shadcn/src/app/embeds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ export function Embeds(props: { embeds: Array<Embed> }) {
address,
},
},
clientReferralAddress: process.env.NEXT_PUBLIC_CLIENT_REFERRAL_ADDRESS as
| `0x${string}`
| undefined,
};
}, [address]);

Expand Down
2 changes: 1 addition & 1 deletion mods/chatgpt-shorten/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import loading from "./loading";
const manifest: ModManifest = {
slug: "chatgpt-shorten",
name: "Shorten text using AI",
custodyAddress: "furlong.eth",
custodyAddress: "0xdcC59cF0Adf4175973D4abc8c0715f83f90d2f1d",
logo: "https://i.imgur.com/hV566qC.png",
custodyGithubUsername: "davidfurlong",
version: "0.0.1",
Expand Down
2 changes: 1 addition & 1 deletion mods/chatgpt/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import loading from "./loading";
const manifest: ModManifest = {
slug: "chatgpt",
name: "Prompt ChatGPT",
custodyAddress: "furlong.eth",
custodyAddress: "0xdcC59cF0Adf4175973D4abc8c0715f83f90d2f1d",
logo: "https://i.imgur.com/YayIWi1.png",
custodyGithubUsername: "davidfurlong",
version: "0.0.1",
Expand Down
2 changes: 1 addition & 1 deletion mods/dall-e/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import loading from "./loading";
const manifest: ModManifest = {
slug: "dall-e",
name: "Use AI to make an image",
custodyAddress: "furlong.eth",
custodyAddress: "0xdcC59cF0Adf4175973D4abc8c0715f83f90d2f1d",
logo: "https://i.imgur.com/zKiFDal.png",
custodyGithubUsername: "davidfurlong",
version: "0.0.1",
Expand Down
2 changes: 1 addition & 1 deletion mods/giphy-picker/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import loading from "./loading";
const manifest: ModManifest = {
slug: "giphy-picker",
name: "Add GIF/Sticker",
custodyAddress: "furlong.eth",
custodyAddress: "0xdcC59cF0Adf4175973D4abc8c0715f83f90d2f1d",
custodyGithubUsername: "davidfurlong",
logo: "https://i.imgur.com/vccxL2r.png",
version: "0.0.1",
Expand Down
2 changes: 1 addition & 1 deletion mods/image-render/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import view from "./view";
const manifest: ModManifest = {
slug: "image-render",
name: "View Images",
custodyAddress: "furlong.eth",
custodyAddress: "0xdcC59cF0Adf4175973D4abc8c0715f83f90d2f1d",
version: "0.0.1",
logo: "https://i.imgur.com/75cFuT9.png",
custodyGithubUsername: "davidfurlong",
Expand Down
2 changes: 1 addition & 1 deletion mods/imgur-upload/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import upload from "./upload";
const manifest: ModManifest = {
slug: "imgur-upload",
name: "Upload image to Imgur",
custodyAddress: "stephancill.eth",
custodyAddress: "0xdcC59cF0Adf4175973D4abc8c0715f83f90d2f1d",
logo: "https://imgur.com/favicon.ico",
custodyGithubUsername: "stephancill",
version: "0.0.1",
Expand Down
2 changes: 1 addition & 1 deletion mods/infura-ipfs-upload/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import upload from "./upload";
const manifest: ModManifest = {
slug: "infura-ipfs-upload",
name: "Add image",
custodyAddress: "furlong.eth",
custodyAddress: "0xdcC59cF0Adf4175973D4abc8c0715f83f90d2f1d",
logo: "https://i.imgur.com/FxgecX7.png",
custodyGithubUsername: "davidfurlong",
version: "0.0.1",
Expand Down
2 changes: 1 addition & 1 deletion mods/livepeer-video/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import upload from "./upload";
const manifest: ModManifest = {
slug: "livepeer-video",
name: "Add video",
custodyAddress: "furlong.eth",
custodyAddress: "0xdcC59cF0Adf4175973D4abc8c0715f83f90d2f1d",
logo: "https://i.imgur.com/89epIn5.png",
custodyGithubUsername: "davidfurlong",
version: "0.0.1",
Expand Down
2 changes: 1 addition & 1 deletion mods/nft-minter/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import view from "./view";
const manifest: ModManifest = {
slug: "nft-minter",
name: "Preview and mint NFTs",
custodyAddress: "furlong.eth",
custodyAddress: "0xdcC59cF0Adf4175973D4abc8c0715f83f90d2f1d",
version: "0.0.1",
logo: "https://i.imgur.com/fuSkgoJ.png",
custodyGithubUsername: "davidfurlong",
Expand Down
2 changes: 1 addition & 1 deletion mods/url-render/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fullimage from "./fullimage";
const manifest: ModManifest = {
slug: "url-render",
name: "View urls",
custodyAddress: "furlong.eth",
custodyAddress: "0xdcC59cF0Adf4175973D4abc8c0715f83f90d2f1d",
version: "0.0.1",
logo: "https://i.imgur.com/E7PAMHH.png",
custodyGithubUsername: "davidfurlong",
Expand Down
2 changes: 1 addition & 1 deletion mods/video-render/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import view from "./view";
const manifest: ModManifest = {
slug: "video-render",
name: "View Videos",
custodyAddress: "furlong.eth",
custodyAddress: "0xdcC59cF0Adf4175973D4abc8c0715f83f90d2f1d",
version: "0.0.1",
logo: "https://i.imgur.com/RITeKTW.png",
custodyGithubUsername: "davidfurlong",
Expand Down
2 changes: 1 addition & 1 deletion mods/zora-create/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import loading from "./loading";
const manifest: ModManifest = {
slug: "zora-create",
name: "Add NFT via Zora Premint",
custodyAddress: "stephancill.eth",
custodyAddress: "0xdcC59cF0Adf4175973D4abc8c0715f83f90d2f1d",
logo: "https://i.imgur.com/rsfLOfD.png",
custodyGithubUsername: "stephancill",
version: "0.0.1",
Expand Down
2 changes: 1 addition & 1 deletion mods/zora-nft-minter/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import view from "./view";
const manifest: ModManifest = {
slug: "zora-nft-minter",
name: "Preview and mint Zora NFTs",
custodyAddress: "stephancill.eth",
custodyAddress: "0xdcC59cF0Adf4175973D4abc8c0715f83f90d2f1d",
version: "0.0.1",
logo: "https://i.imgur.com/fuSkgoJ.png",
custodyGithubUsername: "stephancill",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export type ModManifest = {
name: string;
/** A (temporary) github username to define as the owner */
custodyGithubUsername: string;
/** An ethereum address or ENS address to define as the owner */
custodyAddress: string;
/** An ethereum address to define as the owner */
custodyAddress: `0x${string}`;
/** A valid url pointing to an image file, it should be a square */
logo: string;
/** should be the same as the package version */
Expand Down
21 changes: 19 additions & 2 deletions packages/core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,13 @@ export type ModElementRef<T> =
export type BaseContext = {
user?: {
wallet?: {
address?: string;
address?: `0x${string}`;
};
farcaster?: {
fid?: string;
};
};
clientReferralAddress?: `0x${string}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should have a comment above describing it further; on which chain? EOA required?

I think we should also call it appEthRewardsAddress or something instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add a comment. I'm not too attached to the name, but I do prefer referring to the party implementing Mod as the client since app could be ambiguous

};

export type CreationContext = BaseContext & {
Expand Down Expand Up @@ -933,13 +934,29 @@ export class Renderer {
case "SENDETHTRANSACTION": {
const promise = new Promise<void>((resolve) => {
setTimeout(() => {
/* Populate attribution tags */
const zeroAddress = "0000000000000000000000000000000000000000";
const modTag =
this.manifest.custodyAddress.startsWith("0x") &&
this.manifest.custodyAddress.length === 42
? this.manifest.custodyAddress.slice(2)
: zeroAddress;
const clientTag =
this.context.clientReferralAddress?.slice(2) || zeroAddress;
let txData = this.replaceInlineContext(action.txData.data || "");
// Check if data is hex and contains at least a function signature
// 4 hex bytes (8 chars) + '0x' = 10 chars
if (txData.startsWith("0x") && txData.length >= 10) {
txData = txData + modTag + clientTag;
}

this.onSendEthTransactionAction(
{
data: {
from: this.replaceInlineContext(action.txData.from),
to: this.replaceInlineContext(action.txData.to),
value: this.replaceInlineContext(action.txData.value || "0"),
data: this.replaceInlineContext(action.txData.data || ""),
data: txData,
},
chainId: this.replaceInlineContext(action.chainId),
},
Expand Down
19 changes: 15 additions & 4 deletions packages/react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,14 @@ export const CreationMod = (

const input = variant === "creation" ? props.input : "";
const context = React.useMemo<CreationContext>(
() => ({ input, embeds: props.embeds, api: props.api, user: props.user }),
[input, props.api, props.embeds, props.user]
() => ({
input,
embeds: props.embeds,
api: props.api,
user: props.user,
clientReferralAddress: props.clientReferralAddress,
}),
[input, props.api, props.embeds, props.user, props.clientReferralAddress]
);

const [renderer] = React.useState<Renderer>(
Expand Down Expand Up @@ -501,8 +507,13 @@ export const RenderMod = (
const forceRerender = useForceRerender();

const context = React.useMemo<RichEmbedContext>(
() => ({ embed: props.embed, api: props.api, user: props.user }),
[props.embed, props.api, props.user]
() => ({
embed: props.embed,
api: props.api,
user: props.user,
clientReferralAddress: props.clientReferralAddress,
}),
[props.embed, props.api, props.user, props.clientReferralAddress]
);

const [renderer] = React.useState<Renderer>(
Expand Down
3 changes: 2 additions & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"IMGUR_CLIENT_ID",
"NEXT_PUBLIC_EXPERIMENTAL_MODS",
"ZORA_ADMIN_PRIVATE_KEY",
"NFT_STORAGE_API_KEY"
"NFT_STORAGE_API_KEY",
"NEXT_PUBLIC_CLIENT_REFERRAL_ADDRESS"
]
}