Skip to content
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

mod: erc-20 #147

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2ee074a
mod: erc-20
stephancill Jan 11, 2024
8141c10
feat(core): add setstate action
stephancill Jan 15, 2024
3ef9a8e
fix: use larger logo image
stephancill Jan 15, 2024
327e50a
chore: refactor util functions
stephancill Jan 15, 2024
1fcd9dc
feat: buy tokens
stephancill Jan 15, 2024
f8b2bbe
feat(core+react-ui-shadcn): add padding element
stephancill Jan 15, 2024
4f635f4
fix: add env vars to turbo.json
stephancill Jan 15, 2024
d191362
feat: add second token to demo
stephancill Jan 15, 2024
545be98
feat(core): support multiple async actions
stephancill Jan 18, 2024
56fb344
feat(erc-20): separate and cache initial load
stephancill Jan 18, 2024
ef6e228
fix(nextjs-shadcn): check network before switching
stephancill Jan 18, 2024
5d4939d
feat(mod/erc-20): add tx states, clean up
stephancill Jan 19, 2024
8b339ac
fix: yarn.lock
stephancill Jan 19, 2024
61988f6
feat(core+react+react-ui-shadcn): add skeleton loading state
stephancill Jan 22, 2024
940e8d2
fix(react-ui-shadcn): padding on link element
stephancill Jan 22, 2024
5c1fade
fix(react-ui-shadcn): padding element width
stephancill Jan 22, 2024
f7417fc
fix(nextjs-shadcn): text element width
stephancill Jan 22, 2024
d0201c3
fix(erc-20): uppercase $symbol instead of token name
stephancill Jan 22, 2024
12a4c30
fix(erc-20): pr feedback
stephancill Jan 22, 2024
6aeaa27
chore: add changesets
stephancill Jan 22, 2024
7c5ee47
fix: refactor info endpoint
stephancill Jan 23, 2024
de7c32c
fix(mod/zora-nft-minter): fix button layout
stephancill Jan 24, 2024
a19f7af
feat(mod/erc-20): add uniswap fee
stephancill Jan 25, 2024
2d8a4b0
feat(core+react+react-ui-shadcn): add href to avatar element
stephancill Jan 26, 2024
e2fb675
fix(mod/erc-20): token logo links to token url
stephancill Jan 26, 2024
869c9d0
chore(mod/erc-20): update custody address
stephancill Jan 26, 2024
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
5 changes: 5 additions & 0 deletions .changeset/eleven-phones-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@mods/zora-nft-minter": minor
---

fix: button layout
7 changes: 7 additions & 0 deletions .changeset/lemon-spoons-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@mod-protocol/react-ui-shadcn": patch
"@mod-protocol/react": patch
"@mod-protocol/core": patch
---

feat: add optional `href` to avatar component
5 changes: 5 additions & 0 deletions .changeset/orange-spies-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@mod-protocol/core": patch
---

feat: add `SETSTATE` action
7 changes: 7 additions & 0 deletions .changeset/purple-zebras-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@mod-protocol/react-ui-shadcn": patch
"@mod-protocol/react": patch
"@mod-protocol/core": patch
---

feat: skeleton loading state on layouts
5 changes: 5 additions & 0 deletions .changeset/silly-students-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@mod-protocol/core": patch
---

feat: support multiple async actions
6 changes: 6 additions & 0 deletions .changeset/slimy-starfishes-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@mod-protocol/react-ui-shadcn": patch
"@mod-protocol/core": patch
---

feat: add `Padding` element
5 changes: 5 additions & 0 deletions .changeset/wicked-rabbits-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@mod-protocol/react-ui-shadcn": patch
---

fix: padding on link element
6 changes: 5 additions & 1 deletion examples/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,24 @@
"@lit-protocol/types": "^2.2.61",
"@mod-protocol/core": "^0.1.1",
"@reservoir0x/reservoir-sdk": "^1.8.4",
"@uniswap/smart-order-router": "^3.20.1",
"@vercel/postgres-kysely": "^0.6.0",
"@zoralabs/protocol-sdk": "^0.5.0",
"chatgpt": "^5.2.5",
"cheerio": "^1.0.0-rc.12",
"ethers": "^5.7.2",
"kysely": "^0.26.3",
"next": "^13.5.6",
"nft.storage": "^7.1.1",
"open-graph-scraper": "^6.3.2",
"pg": "^8.11.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"reverse-mirage": "^1.0.3",
"siwe": "^1.1.6",
"uint8arrays": "^3.0.0",
"viem": "1.20.1"
"viem": "1.20.1",
"viem2": "npm:viem@^2.0.6"
},
"devDependencies": {
"@types/node": "^17.0.12",
Expand Down
54 changes: 54 additions & 0 deletions examples/api/src/app/api/erc-20/balances/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { NextRequest, NextResponse } from "next/server";
import { createPublicClient, formatEther, http } from "viem2";
import {
chainByName,
getEthUsdPrice,
numberWithCommas,
parseInfoRequestParams,
} from "../lib/utils";

export async function GET(request: NextRequest) {
const { blockchain, tokenAddress } = parseInfoRequestParams(request);
const userAddress = request.nextUrl.searchParams
.get("walletAddress")
?.toLowerCase();
const buyOptionsUsd = request.nextUrl.searchParams
.get("buyOptionsUsd")
.split(",")
.map((x) => parseFloat(x));

if (!tokenAddress || !blockchain) {
return new Response("Missing tokenAddress or blockchain", {
status: 400,
});
}

// Get eth balance on blockchain
const chain = chainByName[blockchain];
const client = createPublicClient({
transport: http(),
chain,
});

const [balance, ethPriceUsd] = await Promise.all([
client.getBalance({
address: userAddress as `0x${string}`,
}),
getEthUsdPrice(),
]);

const ethBalanceUsd = parseFloat(formatEther(balance)) * Number(ethPriceUsd);

return NextResponse.json({
ethBalance: numberWithCommas(
parseFloat(formatEther(balance)).toPrecision(4)
),
ethPriceUsd,
ethBalanceUsd: numberWithCommas(ethBalanceUsd.toFixed(2)),
chain: {
id: chain.id,
name: chain.name,
},
buyOptionsUsd: buyOptionsUsd.map((x) => ethBalanceUsd > x),
});
}
53 changes: 53 additions & 0 deletions examples/api/src/app/api/erc-20/buy/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { NextRequest, NextResponse } from "next/server";
import { fromHex } from "viem2";
import {
chainByName,
getEthUsdPrice,
getSwapTransaction,
parseInfoRequestParams,
} from "../lib/utils";

export async function POST(request: NextRequest) {
const { blockchain, tokenAddress } = parseInfoRequestParams(request);

const userAddress = request.nextUrl.searchParams
.get("walletAddress")
?.toLowerCase();
const buyAmountUsd = parseFloat(
request.nextUrl.searchParams.get("buyAmountUsd")
);

if (!tokenAddress || !blockchain) {
return new Response("Missing tokenAddress or blockchain", {
status: 400,
});
}

const chain = chainByName[blockchain];

const ethPriceUsd = await getEthUsdPrice();
const ethInputAmount = (buyAmountUsd / ethPriceUsd).toString();

const swapRoute = await getSwapTransaction({
blockchain,
ethInputAmountFormatted: ethInputAmount,
outTokenAddress: tokenAddress,
recipientAddress: userAddress,
feePercentageInt: 5,
feeRecipientAddress: process.env.ERC_20_FEE_RECIPIENT,
});

const tx = swapRoute.methodParameters;

return NextResponse.json({
transaction: {
from: userAddress,
to: tx.to,
value: fromHex(tx.value as `0x${string}`, {
to: "bigint",
}).toString(),
data: tx.calldata,
},
explorer: chain.blockExplorers.default,
});
}
27 changes: 27 additions & 0 deletions examples/api/src/app/api/erc-20/info/holders/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { NextRequest } from "next/server";
import {
getFollowingHolderInfo,
parseInfoRequestParams,
} from "../../lib/utils";

export async function GET(request: NextRequest) {
const { fid, tokenAddress, blockchain } = parseInfoRequestParams(request);
const result = await getFollowingHolderInfo({
fid,
blockchain,
tokenAddress,
});

if (!tokenAddress || !blockchain) {
return new Response("Missing tokenAddress or blockchain", {
status: 400,
});
}

return Response.json(result, {
headers: new Headers({
// Cache for 1 day
"Cache-Control": "public, max-age=86400, immutable",
}),
});
}
23 changes: 23 additions & 0 deletions examples/api/src/app/api/erc-20/info/price/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { NextRequest } from "next/server";
import { getPriceData, parseInfoRequestParams } from "../../lib/utils";

export async function GET(request: NextRequest) {
const { tokenAddress, blockchain } = parseInfoRequestParams(request);
const result = await getPriceData({
blockchain,
tokenAddress,
});

if (!tokenAddress || !blockchain) {
return new Response("Missing tokenAddress or blockchain", {
status: 400,
});
}

return Response.json(result, {
headers: new Headers({
// Cache for 1 hour
"Cache-Control": "public, max-age=3600, immutable",
}),
});
}
23 changes: 23 additions & 0 deletions examples/api/src/app/api/erc-20/info/token/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { NextRequest } from "next/server";
import { getTokenInfo, parseInfoRequestParams } from "../../lib/utils";

export async function GET(request: NextRequest) {
const { tokenAddress, blockchain } = parseInfoRequestParams(request);
const result = await getTokenInfo({
blockchain,
tokenAddress,
});

if (!tokenAddress || !blockchain) {
return new Response("Missing tokenAddress or blockchain", {
status: 400,
});
}

return Response.json(result, {
headers: new Headers({
// Cache for 1 month
"Cache-Control": "public, max-age=2592000, immutable",
}),
});
}
Loading