Skip to content

Commit

Permalink
Merge branch 'master' into james/acx-1507-add-ability-to-mock-block-r…
Browse files Browse the repository at this point in the history
…anges-in-disputer-local-runs
  • Loading branch information
pxrl authored Sep 4, 2023
2 parents e5ef9f2 + da9af52 commit 4884031
Show file tree
Hide file tree
Showing 60 changed files with 802 additions and 557 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module.exports = {
// Disable warnings for { a, b, ...rest } variables, since this is typically used to remove variables.
"@typescript-eslint/no-unused-vars": ["error", { ignoreRestSiblings: true }],
"chai-expect/missing-assertion": 2,
"no-duplicate-imports": "error",
},
settings: {
node: {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"dependencies": {
"@across-protocol/contracts-v2": "2.4.3",
"@across-protocol/sdk-v2": "0.15.18",
"@across-protocol/sdk-v2": "0.15.20",
"@arbitrum/sdk": "^3.1.3",
"@defi-wonderland/smock": "^2.3.5",
"@eth-optimism/sdk": "^3.1.0",
Expand All @@ -26,7 +26,7 @@
"@uma/common": "2.33.0",
"@uma/contracts-node": "^0.4.16",
"@uma/financial-templates-lib": "^2.32.11",
"@uma/sdk": "^0.34.0",
"@uma/sdk": "^0.34.2",
"async": "^3.2.4",
"axios": "^1.4.0",
"dotenv": "^16.3.1",
Expand Down
22 changes: 10 additions & 12 deletions src/clients/BundleDataClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { winston, BigNumber, toBN } from "../utils";
import * as _ from "lodash";
import {
DepositWithBlock,
Expand All @@ -11,12 +10,13 @@ import {
} from "../interfaces";
import { SpokePoolClient } from "../clients";
import {
winston,
BigNumber,
toBN,
assignValidFillToFillsToRefund,
getRefundInformationFromFill,
updateTotalRefundAmount,
updateTotalRealizedLpFeePct,
} from "../utils";
import {
flattenAndFilterUnfilledDepositsByOriginChain,
updateUnfilledDepositsWithMatchedDeposit,
getUniqueDepositsInRange,
Expand Down Expand Up @@ -371,16 +371,14 @@ export class BundleDataClient {
const fillsForOriginChain = destinationClient
.getFillsForOriginChain(Number(originChainId))
.filter((fillWithBlock) => fillWithBlock.blockNumber <= blockRangeForChain[1]);
// In the UBA model, fills that request repayment on another chain must send a separate refund request
// in order to mark their place in the outflow queue for that chain. This is because the UBA determines
// fees based on sequencing of events. Pre-UBA, the fee model treats each fill independently so there
// is no need to mark a fill's place in line on the repayment chain.
await Promise.all(
fillsForOriginChain.map(async (fill) => {
// In the UBA model, fills that request repayment on another chain must send a separate refund request
// in order to mark their place in the outflow queue for that chain. This is because the UBA determines
// fees based on sequencing of events. Pre-UBA, the fee model treats each fill independently so there
// is no need to mark a fill's place in line on the repayment chain.
if (!isUBA || fill.destinationChainId === fill.repaymentChainId) {
validateFillAndSaveData(fill, blockRangeForChain);
}
})
fillsForOriginChain
.filter((fill) => !isUBA || fill.destinationChainId === fill.repaymentChainId)
.map((fill) => validateFillAndSaveData(fill, blockRangeForChain))
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/clients/InventoryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
toBN,
getNetworkName,
createFormatFunction,
etherscanLink,
blockExplorerLink,
Contract,
runTransaction,
isDefined,
Expand Down Expand Up @@ -362,7 +362,7 @@ export class InventoryClient {
cumulativeBalance.toString()
)} ${symbol} over all chains (ignoring hubpool repayments). This chain has a shortfall of ` +
`${formatter(this.getTokenShortFall(l1Token, chainId).toString())} ${symbol} ` +
`tx: ${etherscanLink(hash, this.hubPoolClient.chainId)}\n`;
`tx: ${blockExplorerLink(hash, this.hubPoolClient.chainId)}\n`;
}
}

Expand Down Expand Up @@ -502,7 +502,7 @@ export class InventoryClient {
`${this.formatWei(unwrapWethTarget.toString())} (trigger of ` +
`${this.formatWei(unwrapWethThreshold.toString())} ETH), ` +
`current balance of ${this.formatWei(balance.toString())} ` +
`tx: ${etherscanLink(hash, chainId)}\n`;
`tx: ${blockExplorerLink(hash, chainId)}\n`;
}

for (const { chainInfo, amount } of unexecutedUnwraps) {
Expand Down
27 changes: 19 additions & 8 deletions src/clients/TokenClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { BigNumber, winston, assign, ERC20, Contract, toBN, MAX_SAFE_ALLOWANCE } from "../utils";
import { runTransaction, getNetworkName, etherscanLink, MAX_UINT_VAL } from "../utils";
import { HubPoolClient, SpokePoolClient } from ".";
import { Deposit } from "../interfaces";
import {
BigNumber,
Contract,
ERC20,
MAX_SAFE_ALLOWANCE,
MAX_UINT_VAL,
assign,
blockExplorerLink,
getNetworkName,
runTransaction,
toBN,
winston,
} from "../utils";

type TokenDataType = { [chainId: number]: { [token: string]: { balance: BigNumber; allowance: BigNumber } } };
type TokenShortfallType = {
Expand Down Expand Up @@ -133,9 +144,9 @@ export class TokenClient {
const contract = new Contract(token, ERC20.abi, targetSpokePool.signer);
const tx = await runTransaction(this.logger, contract, "approve", [targetSpokePool.address, MAX_UINT_VAL]);
mrkdwn +=
` - Approved SpokePool ${etherscanLink(targetSpokePool.address, chainId)} ` +
`to spend ${await contract.symbol()} ${etherscanLink(token, chainId)} on ${getNetworkName(chainId)}. ` +
`tx: ${etherscanLink(tx.hash, chainId)}\n`;
` - Approved SpokePool ${blockExplorerLink(targetSpokePool.address, chainId)} ` +
`to spend ${await contract.symbol()} ${blockExplorerLink(token, chainId)} on ${getNetworkName(chainId)}. ` +
`tx: ${blockExplorerLink(tx.hash, chainId)}\n`;
}
this.logger.info({ at: "TokenBalanceClient", message: "Approved whitelisted tokens! 💰", mrkdwn });
}
Expand All @@ -155,9 +166,9 @@ export class TokenClient {
MAX_UINT_VAL,
]);
const mrkdwn =
` - Approved HubPool ${etherscanLink(this.hubPoolClient.hubPool.address, 1)} ` +
`to spend ${await this.bondToken.symbol()} ${etherscanLink(this.bondToken.address, 1)}. ` +
`tx ${etherscanLink(tx.hash, 1)}\n`;
` - Approved HubPool ${blockExplorerLink(this.hubPoolClient.hubPool.address, 1)} ` +
`to spend ${await this.bondToken.symbol()} ${blockExplorerLink(this.bondToken.address, 1)}. ` +
`tx ${blockExplorerLink(tx.hash, 1)}\n`;
this.logger.info({ at: "hubPoolClient", message: "Approved bond tokens! 💰", mrkdwn });
} else {
this.logger.debug({ at: "hubPoolClient", message: "Bond token approval set" });
Expand Down
9 changes: 6 additions & 3 deletions src/clients/TransactionClient.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { utils as sdkUtils } from "@across-protocol/sdk-v2";
import { utils as sdkUtils, typeguards } from "@across-protocol/sdk-v2";
import {
winston,
getNetworkName,
Contract,
runTransaction,
BigNumber,
etherscanLink,
blockExplorerLink,
toBNWei,
TransactionResponse,
TransactionSimulationResult,
Expand All @@ -29,6 +29,7 @@ export interface AugmentedTransaction {
}

const { fixedPointAdjustment: fixedPoint } = sdkUtils;
const { isError } = typeguards;

const DEFAULT_GASLIMIT_MULTIPLIER = 1.0;

Expand Down Expand Up @@ -95,14 +96,16 @@ export class TransactionClient {
at: "TransactionClient#submit",
message: `Transaction ${idx + 1} submission on ${networkName} failed or timed out.`,
mrkdwn,
// @dev `error` _sometimes_ doesn't decode correctly (especially on Polygon), so fish for the reason.
errorMessage: isError(error) ? (error as Error).message : undefined,
error,
notificationPath: "across-error",
});
return txnResponses;
}

nonce = response.nonce + 1;
const blockExplorer = etherscanLink(response.hash, txn.chainId);
const blockExplorer = blockExplorerLink(response.hash, txn.chainId);
mrkdwn += ` ${idx + 1}. ${txn.message || "No message"} (${blockExplorer}): ${txn.mrkdwn || "No markdown"}\n`;
txnResponses.push(response);
}
Expand Down
8 changes: 5 additions & 3 deletions src/clients/bridges/ArbitrumAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import {
isDefined,
TransactionResponse,
resolveTokenSymbols,
toBN,
toWei,
paginatedEventQuery,
Event,
} from "../../utils";
import { toBN, toWei, paginatedEventQuery, Event } from "../../utils";
import { SpokePoolClient } from "../../clients";
import { BaseAdapter } from "./BaseAdapter";
import { SortableEvent } from "../../interfaces";
import { SortableEvent, OutstandingTransfers } from "../../interfaces";
import { constants } from "@across-protocol/sdk-v2";
import { OutstandingTransfers } from "../../interfaces";
import { CONTRACT_ADDRESSES } from "../../common";
const { TOKEN_SYMBOLS_MAP, CHAIN_IDs } = constants;

Expand Down
34 changes: 19 additions & 15 deletions src/clients/bridges/BaseAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
/* eslint-disable @typescript-eslint/ban-types */
import { constants as sdkConstants } from "@across-protocol/sdk-v2";
import { Provider } from "@ethersproject/abstract-provider";
import { Signer } from "@ethersproject/abstract-signer";
import { constants as sdkConstants } from "@across-protocol/sdk-v2";
import { AugmentedTransaction, SpokePoolClient, TransactionClient } from "../../clients";
import {
toBN,
MAX_SAFE_ALLOWANCE,
AnyObject,
BigNumber,
Contract,
DefaultLogLevels,
ERC20,
winston,
EventSearchConfig,
DefaultLogLevels,
MAX_SAFE_ALLOWANCE,
MAX_UINT_VAL,
MakeOptional,
AnyObject,
BigNumber,
matchTokenSymbol,
TransactionResponse,
ZERO_ADDRESS,
assert,
blockExplorerLink,
compareAddressesSimple,
formatUnitsForToken,
getNetworkName,
matchTokenSymbol,
runTransaction,
toBN,
winston,
createFormatFunction,
BigNumberish,
} from "../../utils";
import { etherscanLink, getNetworkName, MAX_UINT_VAL, runTransaction } from "../../utils";

import { OutstandingTransfers, SortableEvent } from "../../interfaces";
import { TransactionResponse } from "../../utils";
import { CONTRACT_ADDRESSES } from "../../common";
import { BigNumberish, createFormatFunction } from "../../utils/FormattingUtils";
import { OutstandingTransfers, SortableEvent } from "../../interfaces";
interface DepositEvent extends SortableEvent {
amount: BigNumber;
to: string;
Expand Down Expand Up @@ -149,9 +153,9 @@ export abstract class BaseAdapter {
const hubNetwork = getNetworkName(hubChainId);
const spokeNetwork = getNetworkName(this.chainId);
mrkdwn +=
` - Approved canonical ${spokeNetwork} token bridge ${etherscanLink(targetContract, hubChainId)} ` +
`to spend ${await l1Token.symbol()} ${etherscanLink(l1Token.address, hubChainId)} on ${hubNetwork}.` +
`tx: ${etherscanLink(receipt.transactionHash, hubChainId)}\n`;
` - Approved canonical ${spokeNetwork} token bridge ${blockExplorerLink(targetContract, hubChainId)} ` +
`to spend ${await l1Token.symbol()} ${blockExplorerLink(l1Token.address, hubChainId)} on ${hubNetwork}.` +
`tx: ${blockExplorerLink(receipt.transactionHash, hubChainId)}\n`;
}
this.log("Approved whitelisted tokens! 💰", { mrkdwn }, "info");
}
Expand Down
7 changes: 4 additions & 3 deletions src/clients/bridges/PolygonAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import {
BigNumberish,
TransactionResponse,
resolveTokenSymbols,
ZERO_ADDRESS,
spreadEventWithBlockNumber,
paginatedEventQuery,
} from "../../utils";
import { ZERO_ADDRESS, spreadEventWithBlockNumber, paginatedEventQuery } from "../../utils";
import { SpokePoolClient } from "../../clients";
import { BaseAdapter } from "./";
import { SortableEvent } from "../../interfaces";
import { SortableEvent, OutstandingTransfers } from "../../interfaces";
import { constants } from "@across-protocol/sdk-v2";
import { OutstandingTransfers } from "../../interfaces";
import { CONTRACT_ADDRESSES } from "../../common";
const { TOKEN_SYMBOLS_MAP, CHAIN_IDs } = constants;

Expand Down
3 changes: 1 addition & 2 deletions src/clients/bridges/ZKSyncAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigNumber, Contract } from "ethers";
import { BigNumber, BigNumberish, Contract } from "ethers";
import { BaseAdapter } from "./BaseAdapter";
import { OutstandingTransfers, SortableEvent } from "../../interfaces";
import {
Expand All @@ -19,7 +19,6 @@ import { TOKEN_SYMBOLS_MAP } from "@across-protocol/contracts-v2";
import { isDefined } from "../../utils/TypeGuards";
import { gasPriceOracle, utils } from "@across-protocol/sdk-v2";
import { zkSync as zkSyncUtils } from "../../utils/chains";
import { BigNumberish } from "../../utils/FormattingUtils";

/**
* Responsible for providing a common interface for interacting with the ZKSync Era
Expand Down
7 changes: 4 additions & 3 deletions src/clients/bridges/op-stack/OpStackAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import {
Event,
checkAddressChecksum,
ethers,
spreadEventWithBlockNumber,
assign,
winston,
} from "../../../utils";
import { spreadEventWithBlockNumber, assign, winston } from "../../../utils";
import { SpokePoolClient } from "../..";
import { BaseAdapter } from "..";
import { SortableEvent } from "../../../interfaces";
import { OutstandingTransfers } from "../../../interfaces";
import { SortableEvent, OutstandingTransfers } from "../../../interfaces";
import { CONTRACT_ADDRESSES } from "../../../common";
import { constants } from "@across-protocol/sdk-v2";
import { OpStackBridge } from "./OpStackBridgeInterface";
Expand Down
9 changes: 4 additions & 5 deletions src/dataworker/Dataworker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import {
isDefined,
buildPoolRebalanceLeafTree,
updateTotalRefundAmountRaw,
toBNWei,
getFillsInRange,
ZERO_ADDRESS,
} from "../utils";
import { toBNWei, getFillsInRange, ZERO_ADDRESS } from "../utils";
import {
DepositWithBlock,
FillsToRefund,
Expand All @@ -22,16 +24,14 @@ import {
SlowFillLeaf,
SpokePoolClientsByChain,
UnfilledDeposit,
} from "../interfaces";
import {
PendingRootBundle,
RunningBalances,
PoolRebalanceLeaf,
RelayerRefundLeaf,
BigNumberForToken,
} from "../interfaces";
import { DataworkerClients } from "./DataworkerClientHelper";
import { SpokePoolClient, UBAClient } from "../clients";
import { SpokePoolClient, UBAClient, BalanceAllocator } from "../clients";
import * as PoolRebalanceUtils from "./PoolRebalanceUtils";
import {
blockRangesAreInvalidForSpokeClients,
Expand All @@ -45,7 +45,6 @@ import {
_buildRelayerRefundRoot,
_buildSlowRelayRoot,
} from "./DataworkerUtils";
import { BalanceAllocator } from "../clients";
import _ from "lodash";
import { spokePoolClientsToProviders } from "../common";
import * as sdk from "@across-protocol/sdk-v2";
Expand Down
Loading

0 comments on commit 4884031

Please sign in to comment.