Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: trade impact is including protocol fees for chainflip #8556

Merged
merged 5 commits into from
Jan 14, 2025
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { AssetId } from '@shapeshiftoss/caip'
import { CHAIN_NAMESPACE, fromAssetId, solAssetId } from '@shapeshiftoss/caip'
import type { GetFeeDataInput } from '@shapeshiftoss/chain-adapters'
import type { KnownChainIds } from '@shapeshiftoss/types'
import { assertUnreachable } from '@shapeshiftoss/utils'
import { assertUnreachable, bnOrZero, toBaseUnit } from '@shapeshiftoss/utils'
import type { Result } from '@sniptt/monads'
import { Err, Ok } from '@sniptt/monads'
import type { AxiosError } from 'axios'
Expand Down Expand Up @@ -297,6 +297,15 @@ export const getQuoteOrRate = async (
singleQuoteResponse.boostQuote.egressAmountNative!,
)

// This is not really a buyAmount before fees but rather an input/output calculation to get the sell amount
// prorated to the buy asset price to determine price impact
NeOMakinG marked this conversation as resolved.
Show resolved Hide resolved
const buyAmountBeforeFeesCryptoBaseUnit = toBaseUnit(
gomesalexandre marked this conversation as resolved.
Show resolved Hide resolved
bnOrZero(singleQuoteResponse.boostQuote.ingressAmount!).times(
NeOMakinG marked this conversation as resolved.
Show resolved Hide resolved
singleQuoteResponse.estimatedPrice!,
),
buyAsset.precision,
)

const boostTradeRateOrQuote = {
id: uuid(),
rate: boostRate,
Expand All @@ -310,7 +319,7 @@ export const getQuoteOrRate = async (
getDefaultSlippageDecimalPercentageForSwapper(SwapperName.Chainflip),
steps: [
{
buyAmountBeforeFeesCryptoBaseUnit: singleQuoteResponse.boostQuote.egressAmountNative!,
buyAmountBeforeFeesCryptoBaseUnit,
buyAmountAfterFeesCryptoBaseUnit: singleQuoteResponse.boostQuote.egressAmountNative!,
sellAmountIncludingProtocolFeesCryptoBaseUnit:
singleQuoteResponse.boostQuote.ingressAmountNative!,
Expand Down Expand Up @@ -349,6 +358,13 @@ export const getQuoteOrRate = async (
singleQuoteResponse.egressAmountNative!,
)

// This is not really a buyAmount before fees but rather an input/output calculation to get the sell amount
// prorated to the buy asset price to determine price impact
const buyAmountBeforeFeesCryptoBaseUnit = toBaseUnit(
bnOrZero(singleQuoteResponse.ingressAmount!).times(singleQuoteResponse.estimatedPrice!),
gomesalexandre marked this conversation as resolved.
Show resolved Hide resolved
buyAsset.precision,
)

const tradeRateOrQuote = {
id: uuid(),
rate,
Expand All @@ -362,7 +378,7 @@ export const getQuoteOrRate = async (
getDefaultSlippageDecimalPercentageForSwapper(SwapperName.Chainflip),
steps: [
{
buyAmountBeforeFeesCryptoBaseUnit: singleQuoteResponse.egressAmountNative!,
buyAmountBeforeFeesCryptoBaseUnit,
buyAmountAfterFeesCryptoBaseUnit: singleQuoteResponse.egressAmountNative!,
sellAmountIncludingProtocolFeesCryptoBaseUnit: singleQuoteResponse.ingressAmountNative!,
feeData: {
Expand Down