Skip to content

support creator fees - #40

Open
ahmxdiqbal wants to merge 3 commits into
mainfrom
feat/creator-fees
Open

support creator fees#40
ahmxdiqbal wants to merge 3 commits into
mainfrom
feat/creator-fees

Conversation

@ahmxdiqbal

Copy link
Copy Markdown
Collaborator

No description provided.

@greptile-apps greptile-apps Bot left a comment

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.

Greptile Overview

Greptile Summary

This PR introduces a new creator fees feature that enables pool creators to collect and withdraw fees separately from pool owners. The implementation adds three new client methods (getCreatorFees(), getPoolCreatorFees(), withdrawCreatorFees()), extends the pool initialization flow to optionally track creator public keys via confirmInitialDeposit(), and adds corresponding API endpoint handlers in typed-endpoints.ts. The feature follows the existing architectural patterns established for host and integrator fees, maintaining consistency with signed intent message generation, acceptance validation, and fee inquiry operations. All changes are additive and backward-compatible, with comprehensive TypeScript type definitions added to support the new functionality across the SDK.

Changed Files
Filename Score Overview
index.ts 5/5 Exports new generateWithdrawCreatorFeesIntentMessage function in alphabetical order alongside existing fee withdrawal exports
src/api/typed-endpoints.ts 2/5 Adds three creator fee endpoints but getCreatorFees and getPoolCreatorFees incorrectly use the same /v1/creators/pool-fees endpoint
src/utils/intents.ts 5/5 Implements creator fee withdrawal intent generation and adds optional poolCreatorPublicKey parameter to pool initialization
src/client/FlashnetClient.ts 4/5 Adds three creator fee methods and enhances confirmInitialDeposit() with conditional creator tracking; note unusual undefined handling for assetBAmount
src/types/index.ts 4/5 Introduces comprehensive type definitions for creator fees including requests, responses, validation data, and fee inquiry types

Confidence score: 2/5

  • This PR has significant issues that must be addressed before merging due to endpoint conflicts that will cause runtime errors.
  • Score lowered primarily due to the critical bug in typed-endpoints.ts where two distinct methods (getCreatorFees and getPoolCreatorFees) point to the same endpoint despite accepting different request types and having different intended behaviors. Secondary concerns include the unique handling of assetBAmount as undefined in withdrawCreatorFees() (differs from host/integrator patterns) and the lack of migration strategy for existing pools to retroactively assign creator public keys.
  • Pay close attention to src/api/typed-endpoints.ts (the endpoint collision must be fixed), src/client/FlashnetClient.ts (verify the undefined assetBAmount behavior is intentional), and consider documenting the behavior for pools initialized without a creator public key.

Sequence Diagram

sequenceDiagram
    participant User
    participant FlashnetClient
    participant TypedAmmApi
    participant ApiClient
    participant Backend

    User->>FlashnetClient: "getCreatorFees(creatorPublicKey?)"
    FlashnetClient->>FlashnetClient: "ensureInitialized()"
    FlashnetClient->>TypedAmmApi: "getCreatorFees(request)"
    TypedAmmApi->>ApiClient: "ammPost('/v1/creators/pool-fees', request)"
    ApiClient->>Backend: "POST /v1/creators/pool-fees"
    Backend-->>ApiClient: "GetCreatorFeesResponse"
    ApiClient-->>TypedAmmApi: "GetCreatorFeesResponse"
    TypedAmmApi-->>FlashnetClient: "GetCreatorFeesResponse"
    FlashnetClient-->>User: "GetCreatorFeesResponse"

    User->>FlashnetClient: "getPoolCreatorFees(poolId)"
    FlashnetClient->>FlashnetClient: "ensureInitialized()"
    FlashnetClient->>FlashnetClient: "ensurePingOk()"
    FlashnetClient->>TypedAmmApi: "getPoolCreatorFees(request)"
    TypedAmmApi->>ApiClient: "ammPost('/v1/creators/pool-fees', request)"
    ApiClient->>Backend: "POST /v1/creators/pool-fees"
    Backend-->>ApiClient: "GetPoolCreatorFeesResponse"
    ApiClient-->>TypedAmmApi: "GetPoolCreatorFeesResponse"
    TypedAmmApi-->>FlashnetClient: "GetPoolCreatorFeesResponse"
    FlashnetClient-->>User: "GetPoolCreatorFeesResponse"

    User->>FlashnetClient: "withdrawCreatorFees(params)"
    FlashnetClient->>FlashnetClient: "ensureInitialized()"
    FlashnetClient->>FlashnetClient: "ensureAmmOperationAllowed('allow_withdraw_fees')"
    FlashnetClient->>FlashnetClient: "generateWithdrawCreatorFeesIntentMessage()"
    FlashnetClient->>FlashnetClient: "signMessageWithIdentityKey()"
    FlashnetClient->>TypedAmmApi: "withdrawCreatorFees(request)"
    TypedAmmApi->>ApiClient: "ammPost('/v1/creators/withdraw-fees', request)"
    ApiClient->>Backend: "POST /v1/creators/withdraw-fees"
    Backend-->>ApiClient: "WithdrawCreatorFeesResponse"
    ApiClient-->>TypedAmmApi: "WithdrawCreatorFeesResponse"
    TypedAmmApi-->>FlashnetClient: "WithdrawCreatorFeesResponse"
    FlashnetClient->>FlashnetClient: "check if accepted"
    FlashnetClient-->>User: "WithdrawCreatorFeesResponse"
Loading

5 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile


/**
* Get creator fees for a specific pool
* @POST /v1/creators/pool-fees

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.

logic: Both getCreatorFees and getPoolCreatorFees use the same endpoint /v1/creators/pool-fees. This seems incorrect - typically different methods should call different endpoints or at minimum have different purposes. Are these methods meant to call different endpoints, or should one of them use a different URL path?

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/api/typed-endpoints.ts
Line: 428:428

Comment:
**logic:** Both `getCreatorFees` and `getPoolCreatorFees` use the same endpoint `/v1/creators/pool-fees`. This seems incorrect - typically different methods should call different endpoints or at minimum have different purposes. Are these methods meant to call different endpoints, or should one of them use a different URL path?

How can I resolve this? If you propose a fix, please make it concise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant