Skip to content

Commit

Permalink
fix: use native eth for caching routing lambda token in and token out (
Browse files Browse the repository at this point in the history
…#983)

* fix: use native eth for caching routing lambda token in and token out

* add unit test
  • Loading branch information
jsy1218 authored Jan 28, 2025
1 parent 4413319 commit 572d0a9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { PairTradeTypeChainId } from './model/pair-trade-type-chain-id'
import { CachedRoutesMarshaller } from '../../marshalling/cached-routes-marshaller'
import { PromiseResult } from 'aws-sdk/lib/request'
import { DEFAULT_BLOCKS_TO_LIVE_ROUTES_DB } from '../../../util/defaultBlocksToLiveRoutesDB'
import { getSymbolOrAddress } from '../../../util/getSymbolOrAddress'

interface ConstructorParams {
/**
Expand Down Expand Up @@ -354,9 +355,9 @@ export class DynamoRouteCachingProvider extends IRouteCachingProvider {
): void {
const payload = {
queryStringParameters: {
tokenInAddress: partitionKey.currencyIn,
tokenInAddress: getSymbolOrAddress(partitionKey.currencyIn, partitionKey.chainId),
tokenInChainId: partitionKey.chainId.toString(),
tokenOutAddress: partitionKey.currencyOut,
tokenOutAddress: getSymbolOrAddress(partitionKey.currencyOut, partitionKey.chainId),
tokenOutChainId: partitionKey.chainId.toString(),
amount: amount.quotient.toString(),
type: partitionKey.tradeType === 0 ? 'exactIn' : 'exactOut',
Expand Down
10 changes: 10 additions & 0 deletions lib/util/getSymbolOrAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ChainId } from '@uniswap/sdk-core'
import { ADDRESS_ZERO } from '@uniswap/router-sdk'
import { nativeOnChain } from '@uniswap/smart-order-router/build/main/util/chains'
export function getSymbolOrAddress(address: string, chainId: ChainId): string {
if (address === ADDRESS_ZERO) {
return nativeOnChain(chainId)?.symbol ?? 'ETH'
} else {
return address
}
}
14 changes: 14 additions & 0 deletions test/mocha/unit/util/getSymbolOrAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { getSymbolOrAddress } from '../../../../lib/util/getSymbolOrAddress'
import { ADDRESS_ZERO } from '@uniswap/router-sdk'
import { ChainId } from '@uniswap/sdk-core'
import { expect } from 'chai'

describe('get symbol or address', () => {
it('should get symbol or address on L1', async () => {
expect(getSymbolOrAddress(ADDRESS_ZERO, ChainId.MAINNET)).to.eq('ETH')
})

it('should get symbol or address on Polygon', async () => {
expect(getSymbolOrAddress(ADDRESS_ZERO, ChainId.POLYGON)).to.eq('MATIC')
})
})

0 comments on commit 572d0a9

Please sign in to comment.