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: use native eth for caching routing lambda token in and token out #983

Merged
merged 2 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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')
})
})