Skip to content
Open
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
23 changes: 11 additions & 12 deletions lib/moment/collectMoment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CHAIN_ID, IS_TESTNET, USDC_ADDRESS } from "@/lib/consts";
import { sendUserOperation } from "@/lib/coinbase/sendUserOperation";
import { getOrCreateSmartWallet } from "../coinbase/getOrCreateSmartWallet";
import { collectSchema } from "../schema/collectSchema";
import { distributeSplitFunds } from "../splits/distributeSplitFunds";
import { distributeCall } from "../splits/distributeCall";
import isSplitContract from "../splits/isSplitContract";
import { MomentType } from "@/types/moment";
import getCollectCall from "../viem/getCollectCall";
Expand Down Expand Up @@ -53,28 +53,27 @@ export async function collectMoment({
amount
);

const calls = [...approveCall, collectCall] as readonly OneOf<
Call<unknown, { [key: string]: unknown }>
>[];
// Send the transaction and wait for receipt using the helper
const transaction = await sendUserOperation({
smartAccount,
network: IS_TESTNET ? "base-sepolia" : "base",
calls,
});
const calls = [...approveCall, collectCall] as OneOf<Call<unknown, { [key: string]: unknown }>>[];

// Distribute funds from split contract if fundsRecipient is a split
if (saleConfig.fundsRecipient) {
const isSplit = await isSplitContract(saleConfig.fundsRecipient as Address, CHAIN_ID);
if (isSplit) {
await distributeSplitFunds({
const splitCall = await distributeCall({
splitAddress: saleConfig.fundsRecipient,
tokenAddress: saleConfig.type === MomentType.Erc20Mint ? USDC_ADDRESS : zeroAddress, // zeroAddress for native ETH
smartAccount,
});
calls.push(splitCall);
}
}

// Send the transaction and wait for receipt using the helper
const transaction = await sendUserOperation({
smartAccount,
network: IS_TESTNET ? "base-sepolia" : "base",
calls,
});

return {
hash: transaction.transactionHash as Hash,
chainId: CHAIN_ID,
Expand Down
38 changes: 38 additions & 0 deletions lib/splits/distributeCall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Address, Hash } from "viem";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Remove unused import.

The Hash type is imported but never used in this file.

🔎 Proposed fix
-import { Address, Hash } from "viem";
+import { Address } from "viem";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { Address, Hash } from "viem";
import { Address } from "viem";
🤖 Prompt for AI Agents
In lib/splits/distributeCall.ts around line 1, the import statement brings in
both Address and Hash from "viem" but the Hash type is never used; remove the
unused Hash identifier from the import so it reads only import { Address } from
"viem" (or re-add usage if Hash is actually required), then run linter/tsc to
confirm no unused-import warnings remain.

import { CHAIN_ID, USDC_ADDRESS } from "@/lib/consts";
import { getSplitsClient } from "./getSplitsClient";
import { getPublicClient } from "@/lib/viem/publicClient";
import { EvmSmartAccount } from "@coinbase/cdp-sdk";
import { Call } from "@coinbase/coinbase-sdk/dist/types/calls";

/**
* Generates call data to distribute funds from a split contract to its recipients.
* Uses 0xSplits SDK to generate the distribution call data.
* Returns a Call object that can be executed via smart wallet.
*/
export async function distributeCall({
splitAddress,
tokenAddress = USDC_ADDRESS,
smartAccount,
}: {
splitAddress: Address;
tokenAddress?: Address;
smartAccount: EvmSmartAccount;
}): Promise<Call<unknown, { [key: string]: unknown }>> {
const publicClient = getPublicClient(CHAIN_ID);
const splitsClient = getSplitsClient({
chainId: CHAIN_ID,
publicClient,
});

const distributeCallData = await splitsClient.callData.distribute({
splitAddress,
tokenAddress,
distributorAddress: smartAccount.address,
});

return {
to: distributeCallData.address as Address,
data: distributeCallData.data,
};
}
45 changes: 0 additions & 45 deletions lib/splits/distributeSplitFunds.ts

This file was deleted.