Skip to content

Commit

Permalink
refactor: Drop v2 types (#1360)
Browse files Browse the repository at this point in the history
A follow-up change would drop all references to V3 types in favour of
the vanilla variants. That hasn't been done here to keep this change on
the smaller side.
  • Loading branch information
pxrl authored Mar 28, 2024
1 parent 2dc7049 commit efc3869
Show file tree
Hide file tree
Showing 17 changed files with 94 additions and 147 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"@across-protocol/constants-v2": "1.0.14",
"@across-protocol/contracts-v2": "2.5.4",
"@across-protocol/sdk-v2": "0.22.19",
"@across-protocol/sdk-v2": "0.23.1",
"@arbitrum/sdk": "^3.1.3",
"@consensys/linea-sdk": "^0.2.1",
"@defi-wonderland/smock": "^2.3.5",
Expand Down
19 changes: 7 additions & 12 deletions src/clients/BundleDataClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {
V3FillWithBlock,
FillType,
FillStatus,
V2DepositWithBlock,
V2FillWithBlock,
} from "../interfaces";
import { SpokePoolClient } from "../clients";
import {
Expand Down Expand Up @@ -497,9 +495,8 @@ export class BundleDataClient {
originClient
.getDepositsForDestinationChain(destinationChainId)
.filter((deposit) => deposit.blockNumber <= originChainBlockRange[1])
.filter(utils.isV3Deposit<V3DepositWithBlock, V2DepositWithBlock>)
.forEach((deposit) => {
const relayDataHash = utils.getV3RelayHashFromEvent(deposit);
const relayDataHash = utils.getRelayHashFromEvent(deposit);
if (v3RelayHashes[relayDataHash]) {
// If we've seen this deposit before, then skip this deposit. This can happen if our RPC provider
// gives us bad data.
Expand Down Expand Up @@ -554,10 +551,9 @@ export class BundleDataClient {
await utils.forEachAsync(
destinationClient
.getFillsForOriginChain(originChainId)
.filter((fill) => fill.blockNumber <= destinationChainBlockRange[1])
.filter(utils.isV3Fill<V3FillWithBlock, V2FillWithBlock>),
.filter((fill) => fill.blockNumber <= destinationChainBlockRange[1]),
async (fill) => {
const relayDataHash = utils.getV3RelayHashFromEvent(fill);
const relayDataHash = utils.getRelayHashFromEvent(fill);

if (v3RelayHashes[relayDataHash]) {
if (!v3RelayHashes[relayDataHash].fill) {
Expand Down Expand Up @@ -600,13 +596,12 @@ export class BundleDataClient {
if (!historicalDeposit.found) {
bundleInvalidFillsV3.push(fill);
} else {
assert(utils.isV3Deposit(historicalDeposit.deposit));
const matchedDeposit = historicalDeposit.deposit;
// @dev Since queryHistoricalDepositForFill validates the fill by checking individual
// object property values against the deposit's, we
// sanity check it here by comparing the full relay hashes. If there's an error here then the
// historical deposit query is not working as expected.
assert(utils.getV3RelayHashFromEvent(matchedDeposit) === relayDataHash);
assert(utils.getRelayHashFromEvent(matchedDeposit) === relayDataHash);
validatedBundleV3Fills.push({
...fill,
quoteTimestamp: matchedDeposit.quoteTimestamp,
Expand All @@ -625,7 +620,7 @@ export class BundleDataClient {
.getSlowFillRequestsForOriginChain(originChainId)
.filter((request) => request.blockNumber <= destinationChainBlockRange[1]),
async (slowFillRequest: SlowFillRequestWithBlock) => {
const relayDataHash = utils.getV3RelayHashFromEvent(slowFillRequest);
const relayDataHash = utils.getRelayHashFromEvent(slowFillRequest);

if (v3RelayHashes[relayDataHash]) {
if (!v3RelayHashes[relayDataHash].slowFillRequest) {
Expand Down Expand Up @@ -684,7 +679,7 @@ export class BundleDataClient {
// older deposit in case the spoke pool client's lookback isn't old enough to find the matching deposit.
if (slowFillRequest.blockNumber >= destinationChainBlockRange[0]) {
const historicalDeposit = await queryHistoricalDepositForFill(originClient, slowFillRequest);
if (!historicalDeposit.found || !utils.isV3Deposit(historicalDeposit.deposit)) {
if (!historicalDeposit.found) {
// TODO: Invalid slow fill request. Maybe worth logging.
return;
}
Expand All @@ -693,7 +688,7 @@ export class BundleDataClient {
// object property values against the deposit's, we
// sanity check it here by comparing the full relay hashes. If there's an error here then the
// historical deposit query is not working as expected.
assert(utils.getV3RelayHashFromEvent(matchedDeposit) === relayDataHash);
assert(utils.getRelayHashFromEvent(matchedDeposit) === relayDataHash);
v3RelayHashes[relayDataHash].deposit = matchedDeposit;

// Note: we don't need to query for a historical fill at this point because a fill
Expand Down
6 changes: 3 additions & 3 deletions src/clients/ProfitClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export class ProfitClient {

async getTotalGasCost(deposit: V3Deposit, fillAmount?: BigNumber): Promise<TransactionCostEstimate> {
const { destinationChainId: chainId } = deposit;
fillAmount ??= sdkUtils.getDepositOutputAmount(deposit);
fillAmount ??= deposit.outputAmount;

// If there's no attached message, gas consumption from previous fills can be used in most cases.
// @todo: Simulate this per-token in future, because some ERC20s consume more gas.
Expand Down Expand Up @@ -257,7 +257,7 @@ export class ProfitClient {
fillAmount?: BigNumber
): Promise<Pick<FillProfit, "nativeGasCost" | "tokenGasCost" | "gasTokenPriceUsd" | "gasCostUsd">> {
const { destinationChainId: chainId } = deposit;
fillAmount ??= sdkUtils.getDepositOutputAmount(deposit);
fillAmount ??= deposit.outputAmount;

const gasToken = this.resolveGasToken(chainId);
const gasTokenPriceUsd = this.getPriceOfToken(gasToken.symbol);
Expand Down Expand Up @@ -404,7 +404,7 @@ export class ProfitClient {
getFillAmountInUsd(deposit: Deposit, fillAmount: BigNumber): BigNumber {
const l1TokenInfo = this.hubPoolClient.getTokenInfoForDeposit(deposit);
if (!l1TokenInfo) {
const inputToken = sdkUtils.getDepositInputToken(deposit);
const { inputToken } = deposit;
throw new Error(
`ProfitClient#getFillAmountInUsd missing l1TokenInfo for deposit with origin token: ${inputToken}`
);
Expand Down
20 changes: 9 additions & 11 deletions src/dataworker/Dataworker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import {
PoolRebalanceLeaf,
RelayerRefundLeaf,
V3SlowFillLeaf,
V2FillWithBlock,
V3FillWithBlock,
} from "../interfaces";
import { DataworkerClients } from "./DataworkerClientHelper";
import { SpokePoolClient, BalanceAllocator } from "../clients";
Expand Down Expand Up @@ -127,9 +125,9 @@ export class Dataworker {
}
}

isV3(blockNumber: number): boolean {
const versionAtBlock = this.clients.configStoreClient.getConfigStoreVersionForBlock(blockNumber);
return sdk.utils.isV3(versionAtBlock);
isV3(_blockNumber: number): boolean {
_blockNumber; // lint
return true;
}

// This should be called whenever it's possible that the loadData information for a block range could have changed.
Expand Down Expand Up @@ -1058,7 +1056,7 @@ export class Dataworker {
continue;
}

const leavesForChain = leaves.filter((leaf) => sdkUtils.getSlowFillLeafChainId(leaf) === chainId);
const leavesForChain = leaves.filter((leaf) => leaf.chainId === chainId);
const unexecutedLeaves = leavesForChain.filter((leaf) => {
const executedLeaf = slowFillsForChain.find(
(event) =>
Expand Down Expand Up @@ -1137,7 +1135,7 @@ export class Dataworker {

const chainId = client.chainId;

const sortedFills = client.getFills().filter(sdkUtils.isV3Fill<V3FillWithBlock, V2FillWithBlock>);
const sortedFills = client.getFills();
const latestFills = leaves.map((slowFill) => {
const { relayData, chainId: slowFillChainId } = slowFill;

Expand All @@ -1147,7 +1145,7 @@ export class Dataworker {
!(
fill.depositId === relayData.depositId &&
fill.originChainId === relayData.originChainId &&
sdkUtils.getV3RelayHash(fill, chainId) === sdkUtils.getV3RelayHash(relayData, slowFillChainId)
sdkUtils.getRelayDataHash(fill, chainId) === sdkUtils.getRelayDataHash(relayData, slowFillChainId)
)
) {
return false;
Expand All @@ -1162,7 +1160,7 @@ export class Dataworker {
const fundedLeaves = (
await Promise.all(
leaves.map(async (slowFill, idx) => {
const destinationChainId = sdkUtils.getSlowFillLeafChainId(slowFill);
const destinationChainId = slowFill.chainId;
if (destinationChainId !== chainId) {
throw new Error(`Leaf chainId does not match input chainId (${destinationChainId} != ${chainId})`);
}
Expand Down Expand Up @@ -1207,7 +1205,7 @@ export class Dataworker {

const hubChainId = this.clients.hubPoolClient.chainId;
fundedLeaves.forEach((leaf) => {
assert(sdkUtils.getSlowFillLeafChainId(leaf) === chainId);
assert(leaf.chainId === chainId);

const { relayData } = leaf;
const { outputAmount } = relayData;
Expand Down Expand Up @@ -1396,7 +1394,7 @@ export class Dataworker {
// Now, execute refund and slow fill leaves for Mainnet using new funds. These methods will return early if there
// are no relevant leaves to execute.
await this._executeSlowFillLeaf(
expectedTrees.slowRelayTree.leaves.filter((leaf) => sdkUtils.getSlowFillLeafChainId(leaf) === hubPoolChainId),
expectedTrees.slowRelayTree.leaves.filter((leaf) => leaf.chainId === hubPoolChainId),
balanceAllocator,
spokePoolClients[hubPoolChainId],
expectedTrees.slowRelayTree.tree,
Expand Down
2 changes: 1 addition & 1 deletion src/dataworker/DataworkerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export function _buildSlowRelayRoot(bundleSlowFillsV3: BundleSlowFills): {
};
}

function buildV3SlowFillLeaf(deposit: interfaces.V3Deposit): V3SlowFillLeaf {
function buildV3SlowFillLeaf(deposit: interfaces.Deposit): V3SlowFillLeaf {
const lpFee = deposit.inputAmount.mul(deposit.realizedLpFeePct).div(fixedPointAdjustment);

return {
Expand Down
4 changes: 2 additions & 2 deletions src/dataworker/PoolRebalanceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ export function generateMarkdownForRootBundle(

let slowRelayLeavesPretty = "";
slowRelayLeaves.forEach((leaf, index) => {
const outputToken = sdkUtils.getRelayDataOutputToken(leaf.relayData);
const destinationChainId = sdkUtils.getSlowFillLeafChainId(leaf);
const { outputToken } = leaf.relayData;
const destinationChainId = leaf.chainId;
const outputTokenDecimals = hubPoolClient.getTokenInfo(destinationChainId, outputToken).decimals;
const lpFeePct = sdkUtils.getSlowFillLeafLpFeePct(leaf);

Expand Down
10 changes: 5 additions & 5 deletions src/interfaces/BundleData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import { interfaces } from "@across-protocol/sdk-v2";
import { BigNumber } from "../utils";
export type ExpiredDepositsToRefundV3 = {
[originChainId: number]: {
[originToken: string]: interfaces.V3DepositWithBlock[];
[originToken: string]: interfaces.DepositWithBlock[];
};
};

export type BundleDepositsV3 = {
[originChainId: number]: {
[originToken: string]: interfaces.V3DepositWithBlock[];
[originToken: string]: interfaces.DepositWithBlock[];
};
};

export interface BundleFillV3 extends interfaces.V3FillWithBlock {
export interface BundleFillV3 extends interfaces.FillWithBlock {
lpFeePct: BigNumber;
}

Expand All @@ -29,12 +29,12 @@ export type BundleFillsV3 = {

export type BundleExcessSlowFills = {
[destinationChainId: number]: {
[destinationToken: string]: interfaces.V3DepositWithBlock[];
[destinationToken: string]: interfaces.DepositWithBlock[];
};
};
export type BundleSlowFills = {
[destinationChainId: number]: {
[destinationToken: string]: interfaces.V3DepositWithBlock[];
[destinationToken: string]: interfaces.DepositWithBlock[];
};
};

Expand Down
22 changes: 8 additions & 14 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,11 @@ export const { FillType, FillStatus } = interfaces;

export type CachingMechanismInterface = interfaces.CachingMechanismInterface;

// V2 / V3 interfaces
export type V2RelayData = interfaces.V2RelayData;
export type V3RelayData = interfaces.V3RelayData;
export type V2Deposit = interfaces.V2Deposit;
export type V3Deposit = interfaces.V3Deposit;
export type V2DepositWithBlock = interfaces.V2DepositWithBlock;
export type V3DepositWithBlock = interfaces.V3DepositWithBlock;
export type V2SpeedUp = interfaces.V2SpeedUp;
export type V3SpeedUp = interfaces.V3SpeedUp;
export type V2Fill = interfaces.V2Fill;
export type V3Fill = interfaces.V3Fill;
export type V2FillWithBlock = interfaces.V2FillWithBlock;
export type V3FillWithBlock = interfaces.V3FillWithBlock;
export type V3SlowFillLeaf = interfaces.V3SlowFillLeaf;
// V3 shims (to be removed later)
export type V3RelayData = interfaces.RelayData;
export type V3Deposit = interfaces.Deposit;
export type V3DepositWithBlock = interfaces.DepositWithBlock;
export type V3SpeedUp = interfaces.SpeedUp;
export type V3Fill = interfaces.Fill;
export type V3FillWithBlock = interfaces.FillWithBlock;
export type V3SlowFillLeaf = interfaces.SlowFillLeaf;
3 changes: 1 addition & 2 deletions src/scripts/validateRunningBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// which also indicates an amount of tokens that need to be taken out of the spoke pool to execute those refunds
// - excess_t_c_{i,i+1,i+2,...} should therefore be consistent unless tokens are dropped onto the spoke pool.

import { utils as sdkUtils } from "@across-protocol/sdk-v2";
import {
bnZero,
winston,
Expand Down Expand Up @@ -257,7 +256,7 @@ export async function runScript(_logger: winston.Logger, baseSigner: Signer): Pr

if (slowFillsForPoolRebalanceLeaf.length > 0) {
for (const slowFillForChain of slowFillsForPoolRebalanceLeaf) {
const destinationChainId = sdkUtils.getSlowFillLeafChainId(slowFillForChain);
const destinationChainId = slowFillForChain.chainId;
const fillsForSameDeposit = bundleSpokePoolClients[destinationChainId]
.getFillsForOriginChain(slowFillForChain.relayData.originChainId)
.filter(
Expand Down
26 changes: 9 additions & 17 deletions src/utils/FillUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from "assert";
import { utils as sdkUtils } from "@across-protocol/sdk-v2";
import { HubPoolClient, SpokePoolClient } from "../clients";
import { Fill, FillStatus, SpokePoolClientsByChain, V2DepositWithBlock, V3DepositWithBlock } from "../interfaces";
import { Fill, FillStatus, SpokePoolClientsByChain, V3DepositWithBlock } from "../interfaces";
import { getBlockForTimestamp, getRedisCache } from "../utils";
import { isDefined } from "./";
import { getBlockRangeForChain } from "../dataworker/DataworkerUtils";
Expand All @@ -25,20 +25,13 @@ export function getRefundInformationFromFill(
hubPoolClient.chainId,
chainIdListForBundleEvaluationBlockNumbers
)[1];
let l1TokenCounterpart: string;
if (sdkUtils.isV3Fill(fill)) {
l1TokenCounterpart = hubPoolClient.getL1TokenForL2TokenAtBlock(
fill.inputToken,
fill.originChainId,
endBlockForMainnet
);
} else {
l1TokenCounterpart = hubPoolClient.getL1TokenForL2TokenAtBlock(
sdkUtils.getFillOutputToken(fill),
fill.destinationChainId,
endBlockForMainnet
);
}

const l1TokenCounterpart = hubPoolClient.getL1TokenForL2TokenAtBlock(
fill.inputToken,
fill.originChainId,
endBlockForMainnet
);

const repaymentToken = hubPoolClient.getL2TokenForL1TokenAtBlock(
l1TokenCounterpart,
chainToSendRefundTo,
Expand Down Expand Up @@ -102,8 +95,7 @@ export async function getUnfilledDeposits(
// Find all unfilled deposits for the current loops originChain -> destinationChain.
return originClient
.getDepositsForDestinationChain(destinationChainId)
.filter((deposit) => deposit.blockNumber >= earliestBlockNumber)
.filter(sdkUtils.isV3Deposit<V3DepositWithBlock, V2DepositWithBlock>); // @todo: Remove after v2 deprecated.
.filter((deposit) => deposit.blockNumber >= earliestBlockNumber);
})
.flat();

Expand Down
Loading

0 comments on commit efc3869

Please sign in to comment.