Skip to content

Commit

Permalink
Merge pull request #333 from Uniswap/v2-addr
Browse files Browse the repository at this point in the history
fix(cbv2): checksum address
  • Loading branch information
ConjunctiveNormalForm authored Jun 5, 2024
2 parents 52e4173 + 6c27d7b commit 06e186b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
8 changes: 6 additions & 2 deletions lib/cron/fade-rate-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ScheduledHandler } from 'aws-lambda/trigger/cloudwatch-events';
import { EventBridgeEvent } from 'aws-lambda/trigger/eventbridge';
import Logger from 'bunyan';

import { ethers } from 'ethers';
import { BETA_S3_KEY, PRODUCTION_S3_KEY, WEBHOOK_CONFIG_BUCKET } from '../constants';
import { CircuitBreakerMetricDimension } from '../entities';
import { checkDefined } from '../preconditions/preconditions';
Expand Down Expand Up @@ -67,7 +68,10 @@ async function main(metrics: MetricsLogger) {
if (result) {
const fillerEndpoints = webhookProvider.fillerEndpoints();
const addressToFillerMap = await fillerAddressRepo.getAddressToFillerMap(fillerEndpoints);
log.info({ addressToFillerMap }, 'address to filler map from dynamo');
log.info(
{ map: addressToFillerMap.forEach((filler, addr) => [addr, filler]) },
'address to filler map from dynamo'
);
const fillerTimestamps = await timestampDB.getFillerTimestampsMap(fillerEndpoints);

// get fillers new fades from last checked timestamp:
Expand Down Expand Up @@ -134,7 +138,7 @@ export function getFillersNewFades(
): FillerFades {
const newFadesMap: FillerFades = {}; // filler hash -> # of new fades
rows.forEach((row) => {
const fillerAddr = row.fillerAddress.toLowerCase();
const fillerAddr = ethers.utils.getAddress(row.fillerAddress);
const fillerHash = addressToFillerMap.get(fillerAddr);
if (!fillerHash) {
log?.info({ fillerAddr }, 'filler address not found dynamo mapping');
Expand Down
34 changes: 17 additions & 17 deletions test/crons/fade-rate-v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@ const now = Math.floor(Date.now() / 1000);

const FADES_ROWS: V2FadesRowType[] = [
// filler1
{ fillerAddress: '0x1', faded: 1, postTimestamp: now - 100 },
{ fillerAddress: '0x1', faded: 0, postTimestamp: now - 90 },
{ fillerAddress: '0x1', faded: 1, postTimestamp: now - 80 },
{ fillerAddress: '0x2', faded: 1, postTimestamp: now - 80 },
{ fillerAddress: '0x0000000000000000000000000000000000000001', faded: 1, postTimestamp: now - 100 },
{ fillerAddress: '0x0000000000000000000000000000000000000001', faded: 0, postTimestamp: now - 90 },
{ fillerAddress: '0x0000000000000000000000000000000000000001', faded: 1, postTimestamp: now - 80 },
{ fillerAddress: '0x0000000000000000000000000000000000000002', faded: 1, postTimestamp: now - 80 },
// filler2
{ fillerAddress: '0x3', faded: 1, postTimestamp: now - 70 },
{ fillerAddress: '0x3', faded: 1, postTimestamp: now - 100 },
{ fillerAddress: '0x0000000000000000000000000000000000000003', faded: 1, postTimestamp: now - 70 },
{ fillerAddress: '0x0000000000000000000000000000000000000003', faded: 1, postTimestamp: now - 100 },
// filler3
{ fillerAddress: '0x4', faded: 1, postTimestamp: now - 100 },
{ fillerAddress: '0x0000000000000000000000000000000000000004', faded: 1, postTimestamp: now - 100 },
// filler4
{ fillerAddress: '0x5', faded: 0, postTimestamp: now - 100 },
{ fillerAddress: '0x0000000000000000000000000000000000000005', faded: 0, postTimestamp: now - 100 },
// filler5
{ fillerAddress: '0x6', faded: 0, postTimestamp: now - 100 },
{ fillerAddress: '0x0000000000000000000000000000000000000006', faded: 0, postTimestamp: now - 100 },
// filler6
{ fillerAddress: '0x7', faded: 1, postTimestamp: now - 100 },
{ fillerAddress: '0x0000000000000000000000000000000000000007', faded: 1, postTimestamp: now - 100 },
];

const ADDRESS_TO_FILLER = new Map<string, string>([
['0x1', 'filler1'],
['0x2', 'filler1'],
['0x3', 'filler2'],
['0x4', 'filler3'],
['0x5', 'filler4'],
['0x6', 'filler5'],
['0x7', 'filler6'],
['0x0000000000000000000000000000000000000001', 'filler1'],
['0x0000000000000000000000000000000000000002', 'filler1'],
['0x0000000000000000000000000000000000000003', 'filler2'],
['0x0000000000000000000000000000000000000004', 'filler3'],
['0x0000000000000000000000000000000000000005', 'filler4'],
['0x0000000000000000000000000000000000000006', 'filler5'],
['0x0000000000000000000000000000000000000007', 'filler6'],
]);

const FILLER_TIMESTAMPS: FillerTimestamps = new Map([
Expand Down
12 changes: 6 additions & 6 deletions test/crons/fade-rate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { calculateFillerFadeRates } from '../../lib/cron/fade-rate';
import { FadesRowType } from '../../lib/repositories';

const FADES_ROWS: FadesRowType[] = [
{ fillerAddress: '0x1', totalQuotes: 50, fadedQuotes: 10 },
{ fillerAddress: '0x2', totalQuotes: 50, fadedQuotes: 20 },
{ fillerAddress: '0x3', totalQuotes: 100, fadedQuotes: 5 },
{ fillerAddress: '0x0000000000000000000000000000000000000001', totalQuotes: 50, fadedQuotes: 10 },
{ fillerAddress: '0x0000000000000000000000000000000000000002', totalQuotes: 50, fadedQuotes: 20 },
{ fillerAddress: '0x0000000000000000000000000000000000000003', totalQuotes: 100, fadedQuotes: 5 },
];

const ADDRESS_TO_FILLER = new Map<string, string>([
['0x1', 'filler1'],
['0x2', 'filler1'],
['0x3', 'filler2'],
['0x0000000000000000000000000000000000000001', 'filler1'],
['0x0000000000000000000000000000000000000002', 'filler1'],
['0x0000000000000000000000000000000000000003', 'filler2'],
]);

// silent logger in tests
Expand Down

0 comments on commit 06e186b

Please sign in to comment.