[TESTING] Add alfredpay discounts#1163
Open
gianfra-t wants to merge 11 commits into
Open
Conversation
✅ Deploy Preview for vortex-sandbox ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for vortexfi ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
There was a problem hiding this comment.
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.subsidyamounts and updates finalize logic for Alfredpay-on-Polygon passthrough cases. - Adjusts ramp phase routing/handlers so Alfredpay onramps go through
subsidizePreSwapbefore 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); |
22c530c to
5e536a5
Compare
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.
Partially closes: #1162