Skip to content

[TESTING] Add alfredpay discounts#1163

Open
gianfra-t wants to merge 11 commits into
stagingfrom
add-alfredpay-discounts
Open

[TESTING] Add alfredpay discounts#1163
gianfra-t wants to merge 11 commits into
stagingfrom
add-alfredpay-discounts

Conversation

@gianfra-t
Copy link
Copy Markdown
Contributor

@gianfra-t gianfra-t commented May 22, 2026

Partially closes: #1162

@netlify
Copy link
Copy Markdown

netlify Bot commented May 22, 2026

Deploy Preview for vortex-sandbox ready!

Name Link
🔨 Latest commit 88af81a
🔍 Latest deploy log https://app.netlify.com/projects/vortex-sandbox/deploys/6a1601c5bfa66500085e04e9
😎 Deploy Preview https://deploy-preview-1163--vortex-sandbox.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@netlify
Copy link
Copy Markdown

netlify Bot commented May 22, 2026

Deploy Preview for vortexfi ready!

Name Link
🔨 Latest commit 88af81a
🔍 Latest deploy log https://app.netlify.com/projects/vortexfi/deploys/6a1601c5d5c6d7000836115f
😎 Deploy Preview https://deploy-preview-1163--vortexfi.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces Alfredpay-specific discount handling into the quote pipeline so discounts/subsidies can be computed and propagated correctly for Alfredpay onramp/offramp flows (Issue #1162).

Changes:

  • Adds new Discount-stage engines for Alfredpay onramp and offramp and wires them into the relevant route strategies.
  • Updates Alfredpay onramp SquidRouter computation to consume ctx.subsidy amounts and updates finalize logic for Alfredpay-on-Polygon passthrough cases.
  • Adjusts ramp phase routing/handlers so Alfredpay onramps go through subsidizePreSwap before executing SquidRouter swap/passthrough.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
apps/api/src/api/services/quote/routes/strategies/onramp-alfredpay-to-evm.strategy.ts Inserts Discount stage into Alfredpay onramp strategy order.
apps/api/src/api/services/quote/routes/strategies/offramp-evm-to-alfredpay.strategy.ts Inserts Discount stage into Alfredpay offramp strategy order.
apps/api/src/api/services/quote/engines/squidrouter/onramp-polygon-to-evm-alfredpay.ts Makes SquidRouter use ctx.subsidy amounts for Alfredpay onramp bridging/passthrough.
apps/api/src/api/services/quote/engines/partners/offramp-alfredpay.ts Uses ctx.subsidy and oracle rate to back-solve the USD input needed for a subsidized fiat payout.
apps/api/src/api/services/quote/engines/finalize/onramp.ts Adjusts onramp final output calculation for Alfredpay cases where SquidRouter is skipped.
apps/api/src/api/services/quote/engines/discount/onramp-alfredpay.ts New Alfredpay onramp discount engine computing subsidy from Alfredpay mint rate and fees.
apps/api/src/api/services/quote/engines/discount/offramp-alfredpay.ts New Alfredpay offramp discount engine computing fiat-side subsidy using oracle conversion.
apps/api/src/api/services/phases/handlers/subsidize-pre-swap-handler.ts Extends pre-swap subsidy logic to handle Alfredpay onramp quotes on Polygon.
apps/api/src/api/services/phases/handlers/fund-ephemeral-handler.ts Routes Alfredpay onramps to subsidizePreSwap after ephemeral funding.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +45 to +49
amountRaw: subsidy.actualOutputAmountRaw,
fromNetwork: Networks.Polygon,
fromToken: ALFREDPAY_ERC20_TOKEN,
inputAmountDecimal: subsidy.actualOutputAmountDecimal,
inputAmountRaw: subsidy.actualOutputAmountRaw,
Comment on lines +19 to +22
if (!ctx.request.inputAmount) {
throw new Error("OnRampAlfredpayDiscountEngine requires request.inputAmount to be defined");
}
}
Comment on lines +40 to +42
console.log(
`[OnRampAlfredpayDiscountEngine] input=${inputAmount} ${ctx.request.outputCurrency}, alfredpayMintIn=${alfredpayMint.inputAmountDecimal.toString()} ${alfredpayMint.currency}, alfredpayMintOut=${alfredpayMint.outputAmountDecimal.toString()} ${ctx.request.outputCurrency}, effectiveRate=${effectiveRate.toString()}, finalOutput=${finalOutput.toString()}`
);
Comment on lines +57 to +61
const {
expectedOutput: expectedOutputDecimal,
adjustedDifference,
adjustedTargetDiscount
} = calculateExpectedOutput(inputAmount, effectiveRate, targetDiscount, this.config.isOfframp, partner);
@gianfra-t gianfra-t force-pushed the add-alfredpay-discounts branch from 22c530c to 5e536a5 Compare May 26, 2026 14:25
@@ -0,0 +1,76 @@
import { ALFREDPAY_ERC20_DECIMALS, ALFREDPAY_ERC20_TOKEN, multiplyByPowerOfTen, RampDirection } from "@vortexfi/shared";
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.

Add the discount feature

2 participants