Repository navigation
feat: default to OUSD - #95
Conversation
Co-authored-by: Derek Cofausper <256792747+decofe@users.noreply.github.com>
|
No dependency changes detected. Learn more about Socket for GitHub. 👍 No dependency changes detected in pull request |
Co-authored-by: Derek Cofausper <256792747+decofe@users.noreply.github.com>
Co-authored-by: Derek Cofausper <256792747+decofe@users.noreply.github.com>
|
The latest Tipbot preview deployment for 13ce444
|
There was a problem hiding this comment.
The latest commits fix both of my earlier inline points. getTokenAddress now resolves 'usd' to the workspace's stored default_token_address and falls back to the chain default only when that is null, and both callers (chat.ts, twitter.ts) pass the stored value. I found no new bugs. I'd still suggest a human look, because this changes payment defaults for existing workspaces.
What was reviewed:
- The
?? pathUsdtogetDefaultTokenAddress(chain_id)replacements in api.ts, chat.ts and tip.ts. Each one now uses the row's ownchain_id. - The
isAllowedTokensplit. Localnet drops OUSD, which matchesgetDefaultTokenAddressreturning pathUSD there. - Migration 0026. It only touches one workspace, filtered by provider, provider_id and chain 4217.
- One open product question. Mainnet and testnet workspaces with a null default move from PathUSD to OUSD, so access keys already authorized for PathUSD no longer match the default token. Those users get a re-authorization or confirmation prompt instead of a direct tip.
Extended reasoning...
The change touches the tip, batch-tip, access-key and link flows in src/api.ts, src/lib/tip.ts and src/chat.ts, plus token resolution in src/lib/tempo.ts and a one-row data migration. These are payment paths. There's no injection or auth-check change, but the token used for spending and key scoping now differs for workspaces whose default is null. Both of my earlier findings about the 'usd' alias are addressed in the current code. I deferred instead of approving because silently moving existing workspaces' default token, and the effect that has on already-authorized PathUSD access keys, is a product decision a maintainer should confirm.
… CLOUDFLARE_API_TOKEN (#111) **Merge after** tempoxyz/cloudflare-deploy-policies#293 has merged and its **Publish policies** run has succeeded. See "Merge after" below. **Draft on purpose.** A ready pull request gets a preview: `preview.yml` on `main` runs this branch's code with the `preview` environment's token. `main`'s `preview_deploy.yml` does not yet replace this branch's new `tipbot-preview-name` placeholder, so that preview would create a D1 database, Queues and a Slack app and then fail at **Run migrations**. Mark it ready just before merging. Previews of pull requests opened after it merges work. ## Summary A push to `main` now deploys the `tipbot` Worker (https://tip.bot) through the [Cloudflare Deploy Broker](https://github.com/tempoxyz/cloudflare-deploy-broker). No job of `production.yml` holds a Cloudflare credential any more, so the `production` environment's `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID` become unused. The Worker keeps its name, D1 database, Durable Objects, Queue, AI binding, cron, custom domain and secrets. Previews are unchanged and still use the `preview` environment's token; see "Previews" below. ## Why production.yml has been failing Every Production run since 2026-11-04 (#95's merge) fails at **Run migrations**, so nothing after #107 has deployed. `tipbot` still serves version `54437c81`, which run 41477298036 deployed on 2026-11-02 with this workflow (author `tom@tempo.xyz`, the owner of the API token). - The step is `wrangler d1 migrations apply tipbot --env production --remote`. Wrangler reads the ledger and lists `0026_tempo_workspace_ousd.sql`, #95's one `UPDATE`, as pending. Then D1 refuses to run it: `You do not have permission to perform this operation. [code: 7500]` (runs 41924847485 and 42512225697). - So the token can read the database but not write it. 0026 is the first migration since 0025 on 2026-06-05, and the 11-02 run had none to apply, so this is the first D1 write the token has attempted in five months. - Someone replaced `CLOUDFLARE_API_TOKEN` in both environments on 2026-11-17 22:23 UTC and re-ran 42512225697 a minute later. It failed the same way, so the new token cannot write D1 either. It is probably a user token whose owner's tempo-prd role lacks D1 write, or a token without D1 Edit. I could not check which, because I can't read either. The broker applies 0026 with its own credential, so this PR also fixes the failure, provided the database accepts the statement. ## Before / after | Area | Before | After | | --- | --- | --- | | D1 migrations | `wrangler d1 migrations apply` with the static token | The broker applies pending migrations from the attested `db/migrations` before it uploads, and stops before promotion if one fails | | Build | `pnpm build` in the deploy job, with the token in the job | The trusted `cloudflare-deploy-broker-build.yml` (gh-actions `1a535d66`) runs `pnpm build:broker` and attests the Worker, its 48 chunks, `dist/server/wrangler.json`, `dist/client` and the migrations. No credential | | Deploy | Vendored wrangler-action, `deploy --env production`, plus `wrangler secret bulk` of 15 secrets | `cloudflare-deploy-broker` with deployment ID `tipbot`, then a check that `https://tip.bot/api/health` (which queries D1) returns 200 | | Secrets | Re-uploaded from the `production` environment on every deploy | Kept on the Worker. Change them in the broker dashboard (https://cf.tehq.net/, Workers tab) | | Slack app ID | `vars.SLACK_APP_ID` in the deploy job | A `Settings` job in the `production` environment reads it and passes it to the build. It is public: tip.bot serves it in a meta tag | | Concurrency | None | One Production run at a time, never cancelled | | Slack app update | After deploy | Unchanged | ## Changes needed for the broker build - **Wrangler 4.91.0 → 4.151.0.** The builder rejects Durable Object `migrations` and needs `exports`, which Wrangler 4.91 does not understand. 4.151.0 is already in the lockfile through `@cloudflare/vitest-plugin`, so the lockfile only switches the importer; no new package is added. `@cloudflare/vite-plugin` 1.37.0 accepts it (`^4.91.0`). - **`src/worker-configuration.d.ts`** is regenerated by `pnpm gen:types`. Wrangler now declares `Env` and `Cloudflare.Env` as extensions of a generated `__BaseEnv_Env`, so `src/env.d.ts` adds its stronger types to both. - **The preview Worker name placeholder** is `tipbot-preview-name` instead of `__PREVIEW_NAME__`, because Wrangler 4.151's `wrangler types` rejects a Worker name with capitals or underscores. `preview_deploy.yml` replaces both, so branches from before this PR still preview. - **`scripts/broker-build.ts`** (`pnpm build:broker`) runs `pnpm build` for production, then adjusts the generated `dist/server/wrangler.json`: - It declares the live Durable Object classes as exports, derived from `wrangler.jsonc`'s migrations: `TipbotChatStateDO` as SQLite (created as `ChatStateDO`, renamed in `tipbot_chat_state_v2`) and `NonceStorage` as `legacy-kv`. The broker never replays migrations. `wrangler.jsonc` keeps them for previews and local development. - It makes `migrations_dir` relative to the generated file, adds the `ASSETS` binding the broker requires (nothing reads it), and deletes the Vite plugin's `.assetsignore`, which the broker rejects and which lists only files the client build does not write. - **`wrangler.jsonc`** sets `account_id` (tempo-prd) in `env.production`, which the builder requires. - **`db/migrations/0020_telegram_provider.sql`** is a no-op placeholder. Production run 26782816327 applied an earlier file of that name (327ef06) before 954bf9b reverted it, so the production ledger still records it. Wrangler ignores applied names it has no file for; the broker requires every recorded name to be one of the attested manifest's first ones, and otherwise fails with `d1_migration_history_mismatch`. On a fresh database (local, tests, previews) the placeholder runs one `UPDATE … WHERE 0`. It sorts before `0020_tip_ask.sql`, after 0019. ## Also: `pnpm audit` c34b6d2 is separate from the migration. `main`'s Verify job now fails `pnpm audit` on seven advisories published since #109: hono below 4.13.16 (GHSA-4m76-xfj5-7975, GHSA-h7mg-cq63-vhpq and five others) and `@hono/node-server` below 2.1.6 (GHSA-qv5m-9pm6-hqp3, GHSA-jpvv-r467-5p4w). This PR fails the same way without a fix, so it pins hono 4.13.19 and overrides `@hono/node-server` to 2.1.9 (both older than the one-day release-age policy). These are patch releases. ## Secrets The broker keeps the live Worker's secrets. `wrangler secret list --name tipbot` (names only) shows all 14 that `wrangler.jsonc` requires (`FEE_PAYER_PRIVATE_KEY_MAINNET`, `FEE_PAYER_PRIVATE_KEY_TESTNET`, `SECRET_KEY`, `SLACK_CLIENT_ID`, `SLACK_CLIENT_SECRET`, `SLACK_SIGNING_SECRET`, `TEMPO_API_KEY`, and the seven `TWITTER_*`), plus `RPC_CREDENTIALS`, which `src/lib/tempo.ts` reads, and `TELEGRAM_BOT_TOKEN` and `TELEGRAM_WEBHOOK_SECRET_TOKEN`, which nothing reads since the Telegram revert. > [!IMPORTANT] > The `production` environment's `RPC_CREDENTIALS` was updated on 2026-11-12, after the last successful deploy (11-02). Every deploy since has failed, so the Worker still has the earlier value, and this workflow no longer uploads secrets. If the new value should be live, set `RPC_CREDENTIALS` in the broker dashboard. No other production secret changed after 11-02. ## Behavior to review - **Source maps.** `upload_source_maps` stays in `wrangler.jsonc`, but the broker never uploads source maps, so production stack traces will not be source-mapped. - **New binding.** The first broker deploy adds `ASSETS`. Assets are still served directly, before the Worker, as now. - **The first deploy applies 0026** (sets OUSD as the default token for Tempo's own Slack workspace), which has been pending since 11-04. - **Changing bindings needs a policy change.** After the first deploy, the broker's remembered grant authorizes code, vars, assets and new D1 migrations. A new binding, Durable Object class or resource ID needs a policy entry in tempoxyz/cloudflare-deploy-policies first. - **The `Settings` job records a deployment** to the `production` environment before the build, because it reads that environment's `SLACK_APP_ID`. - **This PR's CI does not run the broker build**, which runs only on push to `main`. I replayed it (see Validation). ## Previews PR code runs while the `preview` environment's token is in the job. `preview.yml` loads from `main`, but `preview_deploy.yml`'s deploy job checks out the pull request's commit and then runs its code in the same job as the token: its `setup-pnpm` composite action and lockfile, `src/lib/*.ts`, `scripts/slack.ts`, its `wrangler` for `queues create`, `d1 migrations apply` and `deploy`, `vite.config.ts` during the build, and `scripts/preview-seed.ts` with `CLOUDFLARE_API_TOKEN` in its environment. The token can edit every Worker and every D1 database in tempo-prd. `preview-seed.ts` also reads the production `tipbot` database. Both environments' tokens were replaced in the same second on 11-17, so they are probably the same token. The broker's isolated previews cannot do this: each preview creates its own Worker, D1 database and Queues, attaches `pr<n>.tip.bot`, and binds secrets. Moving previews to STS safely means splitting `preview_deploy.yml` so the pull request's code only builds, without credentials, and code from `main` does every privileged step. That is a larger change of the Slack and seeding steps too, and it cannot run before it merges, so this PR leaves previews as they are. It is listed as a decision for the owner. ## Validation - `pnpm audit` reports no known vulnerabilities, and `pnpm check`, `pnpm check:types` and `pnpm test --project unit` pass locally. `pnpm db:migrate` and `pnpm db:codegen` on a fresh local database apply all 30 migrations and leave `db/types.gen.ts` and `db/schemas.gen.ts` unchanged. - actionlint passes. zizmor 1.30.1 (offline) reports no findings, as on `main`. - I replayed the pinned builder on this branch: its install, its `pnpm build:broker` build command and every packaging step, on macOS and in a `node:24.22.1` Linux container. Every builder check passes. It attests `index.js` plus 48 `esm` modules (6.9 MB), 32 assets (6.3 MB, all with known media types) and 30 migrations. - tempoxyz/cloudflare-deploy-policies#293's policy accepts that configuration and module manifest at the publisher's `BROKER_REF` and at broker `main`, and rejects drifted ones (preview URLs on, another D1 database, another Worker, an extra route, a KV namespace, `NonceStorage` as SQLite). ## Merge after 1. tempoxyz/cloudflare-deploy-policies#293 merges and **Publish policies** succeeds. Before that, the broker refuses the existing Worker name ("an explicit policy is required") and the current version keeps serving. 2. Before merging, optionally confirm the ledger row: `wrangler d1 execute tipbot --remote --env production --command "SELECT name FROM d1_migrations ORDER BY id"` should list `0020_telegram_provider.sql`. If it does not, delete `db/migrations/0020_telegram_provider.sql` from this PR. ## After merge 1. Confirm the merge push's **Production** run succeeds (the bootstrap deploy), the deploy step reports a promoted version, and https://tip.bot/api/health returns 200. The broker dashboard (https://cf.tehq.net/) should show `tipbot` promoted. 2. Remove the bootstrap entry `policies/tempoxyz/tip.bot.yaml` from tempoxyz/cloudflare-deploy-policies. Later deploys use the remembered grant. 3. Set `RPC_CREDENTIALS` in the broker dashboard if the 11-12 value should be live (see Secrets). 4. Delete the `production` environment's `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID`. Nothing reads them after this PR. The environment's Worker secrets (`FEE_PAYER_*`, `RPC_CREDENTIALS`, `SECRET_KEY`, `SLACK_CLIENT_*`, `SLACK_SIGNING_SECRET`, `TEMPO_API_KEY`, `TWITTER_*`, `TELEGRAM_*`) are unread too; delete them only if no one needs them as the copy of record. Keep `vars.SLACK_APP_ID`. 5. Do not revoke the Cloudflare token yet. The `preview` environment's `CLOUDFLARE_API_TOKEN` is probably the same token, and previews still use it. If the bootstrap deploy fails before promotion, the current version keeps serving. Reverting this PR restores the Wrangler workflow, which still fails at the D1 migration.
Workspaces without an explicit
default_token_addressfell back to PathUSD on every chain. This makes OUSD (0x20c0000000000000000000006a37DA5C996874BE) the fallback default on Tempo mainnet and Moderato testnet. OUSD uses the same address on both chains, and the Moderato faucet (tempo_fundAddress) mints it.Tempo.addressLookup.ousdandTempo.getDefaultTokenAddress(chainId): OUSD on mainnet and testnet, PathUSD on localnet.?? Tempo.addressLookup.pathUsdfallbacks in tips, raffles, asks, airdrops, account links and config views withgetDefaultTokenAddress(chain_id).ousd/openusdaliases.Workspaces with an explicit
default_token_address, including the X workspace (USDC.e), keep that setting.The address is hardcoded because the
viem/tokensousddefinition ships in viem 2.56+, and those versions drop theviem/tempo/zonesexport that the pinned@wagmi/core3.4.11 imports. Only@wagmi/core3.6.5+ avoids that, which also requiresaccounts~0.18. That upgrade is left for a separate PR.Validation: CI Unit, Workers and E2E pass. Checked onchain that
symbol()returnsOUSDon Moderato, and thattempo_fundAddressmints 1,000,000 OUSD to a fresh address.Check / Verifyfails onpnpm auditadvisories (undici, brace-expansion, ip-address, fast-uri), which also fail on main.Prompted by: @tmm