diff --git a/src/custom/api/coingecko/index.ts b/src/custom/api/coingecko/index.ts index 7de810c0dd..5e1a34ddbf 100644 --- a/src/custom/api/coingecko/index.ts +++ b/src/custom/api/coingecko/index.ts @@ -99,5 +99,5 @@ export function toPriceInformation(priceRaw: CoinGeckoUsdQuote | null): PriceInf } const { usd } = priceRaw[token] - return { amount: usd.toString(), token } + return { amount: usd.toString(), token, oppositeAmount: '1' } } diff --git a/src/custom/api/gnosisProtocol/api.ts b/src/custom/api/gnosisProtocol/api.ts index 04cef488e4..040e289277 100644 --- a/src/custom/api/gnosisProtocol/api.ts +++ b/src/custom/api/gnosisProtocol/api.ts @@ -353,7 +353,12 @@ async function _handleQuoteResponse & { buyAmount: string validTo: string feeAmount: string + // quoteId?: string // TODO: not yet coming from the API, tracked on https://github.com/cowprotocol/services/issues/170 } expiration: string } @@ -110,13 +113,22 @@ function _filterWinningPrice(params: FilterWinningPriceParams) { const amount = BigNumberJs[aggregationFunction](...params.amounts).toString(10) const token = params.priceQuotes[0].token - const winningPrices = params.priceQuotes - .filter((quote) => quote.amount === amount) - .map((p) => p.source) - .join(', ') - console.debug('[util::filterWinningPrice] Winning price: ' + winningPrices + ' for token ' + token + ' @', amount) + const winningPrices = params.priceQuotes.filter((quote) => quote.amount === amount) + const oppositeAmount = winningPrices[0]?.oppositeAmount + + console.debug( + '[util::filterWinningPrice] Winning price: ' + + winningPrices.map((p) => p.source).join(', ') + + ' for token ' + + token + + ' @ ' + + amount + + ' & oppositeAmount ' + + oppositeAmount, + winningPrices + ) - return { token, amount } + return { token, amount, oppositeAmount } } export type QuoteResult = [PromiseSettledResult, PromiseSettledResult] @@ -260,10 +272,13 @@ export async function getBestPrice(params: PriceQuoteParams, options?: GetBestPr export async function getFullQuote({ quoteParams }: { quoteParams: FeeQuoteParams }): Promise { const { kind } = quoteParams const { quote, expiration: expirationDate } = await getQuote(quoteParams) + // TODO: store/pass down as response the buyAmount, sellAmount and quoteId from quote obj const price = { amount: kind === OrderKind.SELL ? quote.buyAmount : quote.sellAmount, + oppositeAmount: kind === OrderKind.SELL ? quote.sellAmount : quote.buyAmount, token: kind === OrderKind.SELL ? quote.buyToken : quote.sellToken, + // quoteId: quote.quoteId, } const fee = { amount: quote.feeAmount,