feat(juicer): /v1/campaigns/juicer/progress + /spend endpoints#256
Open
joshuakrueger-dfx wants to merge 1 commit into
Open
feat(juicer): /v1/campaigns/juicer/progress + /spend endpoints#256joshuakrueger-dfx wants to merge 1 commit into
joshuakrueger-dfx wants to merge 1 commit into
Conversation
JP-trade flow for the Juicer NFT loyalty drop. The wallet trades
JUICER_JP_COST (=5000) Juice Points for a backend signature, then
mints with that signature.
What ships
- src/endpoints/juicerCampaign.ts
* GET /v1/campaigns/juicer/progress - returns { availableJp,
totalEarnedJp, spentJp, cost, isEligibleForNFT, nftMinted, ... }.
Reads totalEarnedJp from ponder /points/{address}, spent from the
new juicer_spend table, and best-effort hasClaimed from the NFT
contract.
* POST /v1/campaigns/juicer/spend - idempotent: if a spend row
already exists for (wallet, chain) the stored signature is
returned, otherwise validates JP balance, generates the
claim signature, INSERTs the row, returns 201.
- prisma/schema.prisma: new JuicerSpend model (table juicer_spend)
with unique (wallet_address, chain_id) constraint as the source of
truth for spent JP.
- src/lib/constants/campaigns.ts: JUICER_NFT_CONTRACT (env-driven so
it stays empty until smart-contracts#56 is deployed) +
JUICER_JP_COST = 5000.
- src/server.ts: mount the two new routes under generalLimiter.
Fail-closed properties
- /spend returns 503 if JUICER_NFT_CONTRACT env var is empty (contract
not deployed yet) so the frontend renders a "not yet live" state
rather than minting against a placeholder address.
- /spend returns 503 if ponder is unreachable, never silently lets a
wallet spend against a stale or missing balance.
- The unique (walletAddress, chainId) constraint plus the contract's
hasClaimed mapping form a defence-in-depth pair against double-claim.
Hard dependencies before this can serve real data
- JuiceSwapxyz/ponder#138 (fixes /points 500s)
- JuiceSwapxyz/smart-contracts#56 (deploys JuicerNFT, populates
JUICER_NFT_CONTRACT env var)
- JuiceSwapxyz/bapp#741 (consumer)
Migration
- Apply prisma migrate to provision juicer_spend before deploy.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Backend for the Juicer NFT post-launch loyalty drop. Wallets trade `JUICER_JP_COST = 5000` Juice Points for a backend signature, then mint with that signature on Citrea Mainnet.
Endpoints
```http
GET /v1/campaigns/juicer/progress?walletAddress={addr}&chainId={4114|5115}
POST /v1/campaigns/juicer/spend { walletAddress, chainId }
```
`/progress` returns:
```json
{
"walletAddress": "0x...",
"chainId": 4114,
"availableJp": 5230,
"totalEarnedJp": 5230,
"spentJp": 0,
"cost": 5000,
"isEligibleForNFT": true,
"nftMinted": false
}
```
`/spend` is idempotent: a retried POST returns the stored signature instead of issuing a new one or deducting JP twice. Signatures are deterministic from `(contract, chainId, wallet)` so re-issuance is safe.
Source of truth
Fail-closed properties
DB migration
`prisma/schema.prisma` adds the `JuicerSpend` model. Apply with `yarn prisma migrate dev --name juicer_spend` before deploying.
Env vars
```bash
JUICER_NFT_CONTRACT=0x... # populate after smart-contracts#56 deploys
CAMPAIGN_SIGNER_PRIVATE_KEY=0x... # already used by First Squeezer; reuse
CITREA_4114_RPC_URL=https://... # already set
```
Companion PRs (hard dependencies)
Test plan