Skip to content

Make AlfredPay sell discounts executable - #1327

Open
ebma wants to merge 10 commits into
stagingfrom
codex/alfredpay-effective-target-discount
Open

Make AlfredPay sell discounts executable#1327
ebma wants to merge 10 commits into
stagingfrom
codex/alfredpay-effective-target-discount

Conversation

@ebma

@ebma ebma commented Aug 11, 2026

Copy link
Copy Markdown
Member

Summary

  • reconcile positive AlfredPay SELL target discounts against the exact Vortex reference while accounting for provider spread, provider fees, and the platform fee reserve
  • return the best executable lower quote with a structured warning when partner, runtime, or provider caps bind instead of rejecting with 503
  • preserve provider upside and keep zero or negative targets subsidy-free
  • size cross-chain settlement from the guaranteed Squid minimum and bind provider orders to the promised payout

Simplification

  • removed the recovery-only flow-v3 implementation, legacy context type, dual transaction preparer, metadata-shape adoption, and legacy settlement-evidence branches
  • flow v4 and context schema 3 are now the only supported AlfredPay SELL pricing program
  • rollout must be timed for a window with no pending AlfredPay flow-v3 quotes or ramps
  • retained treasury acquisition and provider-order replay safeguards because they are required for new capped quotes to remain executable and recoverable

Commit structure

  1. shared AlfredPay and Squid wire-contract validation
  2. AlfredPay SELL quote target reconciliation
  3. settlement and provider-order execution hardening
  4. end-to-end pricing, cap, and recovery regressions
  5. security and architecture documentation

Validation

  • full repository typecheck
  • repository lint
  • 32 shared AlfredPay and Squid schema tests
  • 27 focused API flow, registration, and settlement tests
  • 5 hermetic AlfredPay provider-contract tests
  • 14 DB-backed financial-operation tests
  • all 36 DB-backed MXN AlfredPay offramp scenarios

Notes

  • no database migration or public API wire-version change is required
  • deployment requires confirming that no AlfredPay SELL flow-v3 quotes or ramps are pending

@netlify

netlify Bot commented Aug 11, 2026

Copy link
Copy Markdown

Deploy Preview for vortexfi ready!

Name Link
🔨 Latest commit 07c0b55
🔍 Latest deploy log https://app.netlify.com/projects/vortexfi/deploys/6a82c30ca7da4400082b37aa
😎 Deploy Preview https://deploy-preview-1327--vortexfi.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 11, 2026

Copy link
Copy Markdown

Deploy Preview for vortex-sandbox failed. Why did it fail? →

Name Link
🔨 Latest commit 07c0b55
🔍 Latest deploy log https://app.netlify.com/projects/vortex-sandbox/deploys/6a82c30c84a64b0008e54a5e

@netlify

netlify Bot commented Aug 11, 2026

Copy link
Copy Markdown

Deploy Preview for vrtx-dashboard failed. Why did it fail? →

Name Link
🔨 Latest commit 07c0b55
🔍 Latest deploy log https://app.netlify.com/projects/vrtx-dashboard/deploys/6a82c30c0ade700008e8b9b4

@ebma
ebma force-pushed the codex/alfredpay-effective-target-discount branch from e1ba562 to d5dcf5f Compare August 11, 2026 18:14
@ebma
ebma requested a balanced review from Copilot August 11, 2026 19:13

Copilot AI 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.

Pull request overview

Makes AlfredPay SELL discounts executable while enforcing provider, partner, bridge, and settlement limits.

Changes:

  • Reconciles quotes against AlfredPay and Squid guaranteed terms.
  • Hardens settlement, recovery, and residual cleanup.
  • Expands contract, corridor, recovery, and security documentation coverage.

Reviewed changes

Copilot reviewed 35 out of 35 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/shared/src/services/squidrouter/schemas.ts Validates guaranteed route output.
packages/shared/src/services/squidrouter/schemas.test.ts Tests minimum-output validation.
packages/shared/src/services/squidrouter/offramp.ts Returns the selected Squid route.
packages/shared/src/services/alfredpay/schemas.ts Expands quote and order schemas.
packages/shared/src/services/alfredpay/schemas.test.ts Tests expanded AlfredPay contracts.
docs/security-spec/06-cross-chain/fund-routing.md Documents settlement guarantees and caps.
docs/security-spec/05-integrations/alfredpay.md Documents SELL pricing and recovery.
docs/security-spec/03-ramp-engine/ramp-phase-flows.md Documents flow v4 behavior.
docs/security-spec/03-ramp-engine/quote-lifecycle.md Documents quote selection and replacement.
docs/security-spec/03-ramp-engine/fee-integrity.md Documents reserve and subsidy accounting.
docs/security-spec/03-ramp-engine/ephemeral-accounts.md Documents user-directed cleanup.
docs/security-spec/03-ramp-engine/discount-mechanism.md Documents executable discount reconciliation.
apps/api/src/tests/sdk-contract.alfredpay-offramp.test.ts Updates provider lifecycle simulation.
apps/api/src/tests/corridors/mxn-offramp.scenario.test.ts Adds pricing and recovery scenarios.
apps/api/src/tests/corridors/alfredpay-currencies.scenario.test.ts Updates multi-currency lifecycle behavior.
apps/api/src/tests/contracts/alfredpay.contract.test.ts Expands provider contract coverage.
apps/api/src/test-utils/fake-world/fake-squidrouter.ts Models guaranteed route output.
apps/api/src/test-utils/fake-world/fake-evm.ts Models ERC-20 cleanup transfers.
apps/api/src/test-utils/fake-world/fake-anchors.ts Models AlfredPay limits and orders.
apps/api/src/api/services/phases/post-process/polygon-post-process-handler.ts Returns SELL residuals to users.
apps/api/src/api/services/phases/blocks/README.md Documents block ownership.
apps/api/src/api/services/phases/blocks/phases/final-settlement-subsidy/execution.ts Hardens capped settlement acquisition.
apps/api/src/api/services/phases/blocks/phases/alfredpay-offramp/transactions.ts Binds preparation to guaranteed output.
apps/api/src/api/services/phases/blocks/phases/alfredpay-offramp/simulation.ts Implements executable SELL pricing.
apps/api/src/api/services/phases/blocks/phases/alfredpay-offramp/registration.ts Validates refreshed provider orders.
apps/api/src/api/services/phases/blocks/phases/alfredpay-offramp/lifecycle.ts Preserves generic metadata typing.
apps/api/src/api/services/phases/blocks/phases/alfredpay-offramp/execution.ts Hardens transfer and order recovery.
apps/api/src/api/services/phases/blocks/flows/catalog.ts Simplifies persisted-flow resolution.
apps/api/src/api/services/phases/blocks/flows/alfredpay-offramp.ts Advances AlfredPay SELL to flow v4.
apps/api/src/api/services/phases/blocks/core/squidrouter.ts Exposes guaranteed route amounts.
apps/api/src/api/services/phases/blocks/core/financial-operation.ts Adds request-shape recovery support.
apps/api/src/api/services/phases/blocks/core/financial-operation.test.ts Tests durable-operation compatibility.
apps/api/src/api/services/phases/blocks/__tests__/evm-executor-regressions.test.ts Tests acquisition and subsidy safeguards.
apps/api/src/api/services/phases/blocks/__tests__/alfredpay-offramp.registration.test.ts Tests strict registration binding.
apps/api/src/api/services/phases/blocks/__tests__/alfredpay-offramp.flow.test.ts Pins flow v4/schema 3.
Suppressed comments (1)

packages/shared/src/services/alfredpay/schemas.ts:155

  • The production createOfframp and getOfframpTransaction methods still raw-cast JSON and never invoke this expanded schema. As a result, the recovery executor binds transfers and lifecycle decisions to unvalidated order identity, amounts, status, address, and expiry despite these fields now being security-critical. Apply this schema in both service methods before returning provider transactions.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +28 to +32
const squidrouterRouteEstimateSchema = z
.looseObject({
aggregateSlippage: z.number().optional(),
toAmount: z.string().regex(RAW_UNITS),
toAmountMin: z.string().regex(RAW_UNITS),
Comment on lines 106 to +107
export const alfredpayQuoteResponseSchema = z.looseObject({
chain: z.enum(AlfredpayChain).optional(),
Comment on lines +123 to +127
if (operation.status === "not_started") {
// No financial side effect has been claimed yet. Refreshing a preflight's
// request is safe and lets legacy/live observations converge on the stable
// authorization used by the current executor.
await operation.update({ requestHash });
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.

2 participants