Skip to content

feat: relay swapper quotes evm sign and status#9188

Merged
NeOMakinG merged 39 commits intodevelopfrom
relay-quotes
Apr 9, 2025
Merged

feat: relay swapper quotes evm sign and status#9188
NeOMakinG merged 39 commits intodevelopfrom
relay-quotes

Conversation

@NeOMakinG
Copy link
Copy Markdown
Collaborator

@NeOMakinG NeOMakinG commented Mar 28, 2025

Description

Implements Relay EVM quotes:

  • Add feature flag
  • Swapper boilerplate
  • getQuote and rate functions with proper types narrowing
  • EVM signing TXs
  • TX Status
  • Native asset address mapping (like lifi)
  • Chain mapping (because their chainId differs sometime for BTC and solana for example)

Issue (if applicable)

closes #9160
closes #9161

Risk

Medium (new swapper)

High Risk PRs Require 2 approvals

What protocols, transaction types, wallets or contract interactions might be affected by this PR?

Testing

  • You can swap ERC20 to ETH on any EVM chain, and ETH to ERC20
  • You don't need to send approval if you already have some approval spending
  • You can bridge from any ERC20 asset to any ERC20 asset between different EVM chains
  • TX status works as expected
  • Also test slippage tolerance
  • Feature flag is disabling relay in production (should be testable with yarn preview:prod)

Engineering

n/a

Operations

n/a

  • 🏁 My feature is behind a flag and doesn't require operations testing (yet)

Screenshots (if applicable)

https://jam.dev/c/e8cdc489-a802-4ad1-af66-2491c8e20a42

Swap fees amount test FOX => AVAX

image
(0.03 USD (0.002 AVAX))

Swap fees amount test AVAX => FOX on Arb

image
(1.1 FOX (0.026 USDC)), according to the USDC amount of the quote it should be 0.025937 USD), maths seems good

Swap fees amount test ETH on Arb => FOX on Arb

image

0 fees from relayer

Full retest

https://jam.dev/c/cda7820f-9589-4871-b64c-b906f3d9683a

@NeOMakinG NeOMakinG marked this pull request as ready for review April 1, 2025 09:38
@NeOMakinG NeOMakinG requested a review from a team as a code owner April 1, 2025 09:38
@NeOMakinG NeOMakinG changed the title feat: relay swapper and quotes feat: relay swapper quotes evm sign and status Apr 1, 2025
@gomesalexandre gomesalexandre self-requested a review April 1, 2025 17:17
Copy link
Copy Markdown
Contributor

@gomesalexandre gomesalexandre left a comment

Choose a reason for hiding this comment

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

See review comments for code pass.

Runtime test

  • Unable to test locally without explicitly enabling the flag - flag needs to be enabled in devish envs 🚫
  • Able to do a same-chain EVM swap e2e ✅

https://jam.dev/c/59b8d6aa-5ef3-4605-b626-3d1dedf13e0b

Comment thread packages/swapper/src/constants.ts
Comment thread packages/swapper/src/constants.ts Outdated
Comment thread packages/swapper/src/swappers/RelaySwapper/RelaySwapper.ts Outdated
Comment thread packages/swapper/src/swappers/RelaySwapper/RelaySwapper.ts Outdated
Comment thread headers/csps/relay.ts
Comment thread packages/swapper/src/swappers/RelaySwapper/getTradeQuote/getTradeQuote.ts Outdated
Comment thread packages/swapper/src/swappers/RelaySwapper/getTradeQuote/getTradeQuote.ts Outdated
Comment thread packages/swapper/src/swappers/RelaySwapper/getTradeQuote/getTradeQuote.ts Outdated
Comment thread yarn.lock Outdated
Comment thread packages/swapper/src/swappers/RelaySwapper/getTradeQuote/getTradeQuote.ts Outdated
Comment thread packages/swapper/src/swappers/RelaySwapper/RelaySwapper.ts
Comment thread packages/swapper/src/types.ts Outdated
Comment thread packages/swapper/src/swappers/RelaySwapper/endpoints.ts Outdated
Comment thread packages/swapper/src/swappers/RelaySwapper/utils/getTrade.ts Outdated
Comment thread packages/swapper/src/swappers/RelaySwapper/utils/getTrade.ts Outdated
Copy link
Copy Markdown
Contributor

@gomesalexandre gomesalexandre left a comment

Choose a reason for hiding this comment

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

See comments

  • getEvmTransactionFees() is unimplemented - fees estimation are broken at confirm time
  • getUnsignedEvmTransaction() is using quote fee estimate for fees
  • SDK is imported but unused

Comment thread packages/swapper/src/swappers/RelaySwapper/constant.ts
Comment thread packages/swapper/src/swappers/RelaySwapper/endpoints.ts Outdated
Comment thread packages/swapper/src/swappers/RelaySwapper/endpoints.ts Outdated
Comment thread package.json Outdated
Comment thread packages/swapper/src/swappers/RelaySwapper/utils/getTrade.ts Outdated
Comment thread packages/swapper/src/swappers/RelaySwapper/utils/getTrade.ts Outdated
@NeOMakinG NeOMakinG marked this pull request as draft April 7, 2025 06:31
@NeOMakinG NeOMakinG marked this pull request as ready for review April 7, 2025 09:35
Copy link
Copy Markdown
Contributor

@gomesalexandre gomesalexandre left a comment

Choose a reason for hiding this comment

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

  • Types are wrong and need to be accomodated vs. simply copied and pasted
  • getEvmTransactionFees is still wrong and polling is still borked - will always return hardcoded networkFeeCryptoBaseunit from quote at the moment final quote was fetched, i.e static, stale fees when we got the final quote vs. polling node as it should

Comment thread packages/swapper/src/swappers/RelaySwapper/endpoints.ts Outdated
Comment thread packages/swapper/src/swappers/RelaySwapper/utils/getTrade.ts Outdated
Comment thread packages/swapper/src/swappers/RelaySwapper/endpoints.ts Outdated
Comment thread packages/swapper/src/swappers/RelaySwapper/endpoints.ts Outdated
Comment thread packages/swapper/src/swappers/RelaySwapper/endpoints.ts Outdated
Comment thread packages/swapper/src/swappers/RelaySwapper/utils/types.ts Outdated
Comment thread packages/swapper/src/swappers/RelaySwapper/utils/types.ts Outdated
Comment thread packages/swapper/src/swappers/RelaySwapper/utils/types.ts Outdated
Comment thread packages/swapper/src/swappers/RelaySwapper/utils/getTrade.ts Outdated
Comment thread packages/swapper/src/swappers/RelaySwapper/utils/getTrade.ts Outdated
@NeOMakinG NeOMakinG marked this pull request as draft April 7, 2025 14:35
@NeOMakinG NeOMakinG marked this pull request as ready for review April 8, 2025 13:56
Copy link
Copy Markdown
Contributor

@gomesalexandre gomesalexandre left a comment

Choose a reason for hiding this comment

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

Code-wise pass looking good now, runtime pass to follow soon

Comment thread packages/swapper/src/swappers/RelaySwapper/utils/getTrade.ts
Comment thread packages/swapper/src/swappers/RelaySwapper/utils/getTrade.ts Outdated
Copy link
Copy Markdown
Contributor

@gomesalexandre gomesalexandre left a comment

Choose a reason for hiding this comment

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

Tested locally, happy with this one

Two main things I spotted for follow-ups:

  • Actual amount out doesn't consistently update. Seemingly, same-chain Txs aren't parsed properly
  • We'll want to revisit the buy amount to both be as close as possible to the one that's guaranteed, i.e optimistic but never under (except for slippage obviously), probably worth spending a few hours while we're done with the meat of Relay to see how they do it in their UI

Rabby same-chain ✅

https://jam.dev/c/863dc93b-855f-406f-8c5c-af2721a7d930

Note: non-blocking, but we don't seem to introspect transfers properly in <SpotTradeSuccess /> - may or may not be related to this PR but would be nice to tackle as a follow-up as users don't see the receive amount being greater than it really is

Would also be nice to tweak things a notch here so that the amount we display is as optimistic as possible without lying, though as previously discussed, it may or may not be possible to achieve this without giving false guarantees.

Rabby cross-chain ✅

https://jam.dev/c/c236bdf9-1634-406a-ab2c-f106924dc1a0

Ledger (EIP-1559) cross-chain ✅

https://jam.dev/c/33a4a0f1-1cb6-47c5-be3e-ba6a5ddfa81d

Ledger (EIP-1559) same-chain ✅

https://jam.dev/c/242ca953-b8ca-40af-8afe-29b8630f8a10

Same thing here, actual amount out never updated, hinting at deciphering transfers

@NeOMakinG
Copy link
Copy Markdown
Collaborator Author

  • Actual amount out doesn't consistently update. Seemingly, same-chain Txs aren't parsed properly

That's a nice catch, creating an issue for tracking purposes #9304

  • We'll want to revisit the buy amount to both be as close as possible to the one that's guaranteed, i.e optimistic but never under (except for slippage obviously), probably worth spending a few hours while we're done with the meat of Relay to see how they do it in their UI

This is what I was saying in the minimumAmount vs amount comments, their UI is using amount, we are using minimumAmount, that's the reason why I was asking if we should do Relay a special case for our swapper by using the amount as it's way closer than the real amount received

@NeOMakinG NeOMakinG enabled auto-merge (squash) April 9, 2025 07:20
@NeOMakinG NeOMakinG merged commit 1d98b38 into develop Apr 9, 2025
3 checks passed
@NeOMakinG NeOMakinG deleted the relay-quotes branch April 9, 2025 07:28
NeOMakinG added a commit that referenced this pull request Apr 11, 2025
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.

[RELAY] EVM Transactions handlers and trade status [RELAY] Implement quotes

2 participants