Skip to content

Commit

Permalink
Merge branch 'master' into pxrl/undefinedToken
Browse files Browse the repository at this point in the history
  • Loading branch information
bmzig committed Sep 3, 2024
2 parents 0a21246 + 1058a22 commit c23eb42
Show file tree
Hide file tree
Showing 107 changed files with 4,889 additions and 995 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
- run: yarn install
- run: yarn build

2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
- run: yarn install
- run: yarn lint-check
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v3
with:
node-version: "16.x"
node-version: "18.x"
always-auth: true
registry-url: "https://registry.npmjs.org"

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Across SDK V2
# Across SDK

Across is a system that uses UMA contracts to quickly move tokens across chains. This repository contains shareable code and libraries for Across V2.
Across is a system that quickly moves tokens across chains. This repository contains shareable code and libraries for Across.

## Modules
| Name | Description | README | Source Code |
Expand Down Expand Up @@ -111,6 +111,6 @@ There are many ways to ship styles, including with CSS-in-JS. TSDX has no opinio
For vanilla CSS, you can include it at the root directory and add it to the `files` section in your `package.json`, so that it can be imported separately by your users and run through their bundler's loader.

## Publishing a new version
1. Bump version in package.json and merge to master. Example: https://github.com/across-protocol/sdk-v2/pull/67
2. Create a new release with a new tag (version number should be incremented): https://github.com/across-protocol/sdk-v2/releases
3. Update any upstream repos/binaries that depend on sdk-v2 such as https://github.com/across-protocol/frontend-v2. Example: https://github.com/across-protocol/frontend-v2/pull/202
1. Bump version in package.json and merge to master. Example: https://github.com/across-protocol/sdk/pull/67
2. Create a new release with a new tag (version number should be incremented): https://github.com/across-protocol/sdk/releases
3. Update any upstream repos/binaries that depend on the sdk such as https://github.com/across-protocol/frontend. Example: https://github.com/across-protocol/frontend/pull/202
2 changes: 1 addition & 1 deletion contracts/MockAcrossMessageContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.0;

// This interface is expected to be implemented by any contract
// that expects to receive messages from the SpokePool.
// Retrieved from https://github.com/across-protocol/contracts-v2/blob/master/contracts/SpokePool.sol
// Retrieved from https://github.com/across-protocol/contracts/blob/master/contracts/SpokePool.sol
interface AcrossMessageHandler {
function handleV3AcrossMessage(address, uint256, address, bytes memory message) external;
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/MockSpokePool.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;

import "@across-protocol/contracts-v2/contracts/test/MockSpokePool.sol";
import "@across-protocol/contracts/contracts/test/MockSpokePool.sol";

/**
* @title MockSpokePool
Expand Down
3 changes: 2 additions & 1 deletion e2e/oracle.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@ const networks: { [chainId: number]: string } = {
324: "https://mainnet.era.zksync.io",
8453: "https://mainnet.base.org",
42161: "https://rpc.ankr.com/arbitrum",
534352: "https://rpc.scroll.io",
};

const stdGasPrice = ethersUtils.parseUnits("10", 9);
const stdMaxPriorityFeePerGas = ethersUtils.parseUnits("1.5", 9); // EIP-1559 chains only
const stdLastBaseFeePerGas = stdGasPrice.sub(stdMaxPriorityFeePerGas);
const stdMaxFeePerGas = stdGasPrice;
const eip1559Chains = [1, 10, 137, 8453, 42161];
const legacyChains = [288, 324];
const legacyChains = [288, 324, 534352];

let providerInstances: { [chainId: number]: MockedProvider } = {};

Expand Down
5 changes: 5 additions & 0 deletions funding.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"opRetro": {
"projectId": "0x72723e07fe409557489a6643b43d9493a94c10ba68230b0527f01834cb6a550f"
}
}
29 changes: 15 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@across-protocol/sdk-v2",
"name": "@across-protocol/sdk",
"author": "UMA Team",
"version": "0.23.10",
"version": "3.1.29",
"license": "AGPL-3.0",
"homepage": "https://docs.across.to/reference/sdk",
"files": [
Expand All @@ -13,13 +13,10 @@
},
"scripts": {
"start": "nodemon -e ts,tsx,json,js,jsx --watch ./src --ignore ./dist --exec 'yarn build'",
"build": "yarn run clean && yarn run build:cjs & yarn run build:esm & yarn run build:types; wait",
"build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir ./dist/cjs --removeComments --verbatimModuleSyntax false && echo > ./dist/cjs/package.json '{\"type\":\"commonjs\"}' && yarn copy-abi:cjs",
"build:esm": "tsc --project tsconfig.build.json --module es2015 --outDir ./dist/esm && echo > ./dist/esm/package.json '{\"type\":\"module\",\"sideEffects\":false}' && yarn copy-abi:esm",
"build": "yarn run clean && yarn typechain && yarn run build:cjs & yarn run build:esm & yarn run build:types; wait",
"build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir ./dist/cjs --removeComments --verbatimModuleSyntax false && echo > ./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
"build:esm": "tsc --project tsconfig.build.json --module es2015 --outDir ./dist/esm && echo > ./dist/esm/package.json '{\"type\":\"module\",\"sideEffects\":false}'",
"build:types": "tsc --project tsconfig.build.json --module esnext --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap",
"copy-abi:cjs": "DIR=cjs yarn copy-abi",
"copy-abi:esm": "DIR=esm yarn copy-abi",
"copy-abi": "abi=utils/abi/contracts; dstdir=\"./dist/${DIR}/${abi}\"; mkdir -p \"${dstdir}\"; cp ./src/${abi}/*.json \"${dstdir}\"",
"test": "hardhat test",
"test:watch": "hardhat watch test",
"test:run:arweave": "npx -y arlocal",
Expand All @@ -31,7 +28,8 @@
"clean": "rm -rf ./dist",
"bump-version:major": "yarn version --major --no-git-tag-version --no-commit-hooks && git commit -m 'chore: bump version' ./package.json --no-verify",
"bump-version:minor": "yarn version --minor --no-git-tag-version --no-commit-hooks && git commit -m 'chore: bump version' ./package.json --no-verify",
"bump-version:patch": "yarn version --patch --no-git-tag-version --no-commit-hooks && git commit -m 'chore: bump version' ./package.json --no-verify"
"bump-version:patch": "yarn version --patch --no-git-tag-version --no-commit-hooks && git commit -m 'chore: bump version' ./package.json --no-verify",
"typechain": "typechain --target ethers-v5 --out-dir src/utils/abi/typechain 'src/utils/abi/contracts/*.json' && eslint --fix src/utils/abi/typechain && yarn prettier --write \"src/utils/abi/typechain/**/*.ts\""
},
"lint-staged": {
"*.ts": "yarn lint"
Expand All @@ -40,11 +38,11 @@
"sideEffects": false,
"size-limit": [
{
"path": "dist/sdk-v2.cjs.production.min.js",
"path": "dist/sdk.cjs.production.min.js",
"limit": "10 KB"
},
{
"path": "dist/sdk-v2.esm.js",
"path": "dist/sdk.esm.js",
"limit": "10 KB"
}
],
Expand All @@ -58,6 +56,7 @@
"@size-limit/preset-small-lib": "^7.0.8",
"@typechain/ethers-v5": "^11.1.1",
"@typechain/hardhat": "^6.1.6",
"@types/async": "^3.2.24",
"@types/chai": "^4.3.6",
"@types/dotenv": "^8.2.0",
"@types/lodash": "^4.14.199",
Expand Down Expand Up @@ -99,17 +98,19 @@
},
"dependencies": {
"@across-protocol/across-token": "^1.0.0",
"@across-protocol/constants-v2": "^1.0.20",
"@across-protocol/contracts-v2": "2.5.6",
"@eth-optimism/sdk": "^3.2.2",
"@across-protocol/constants": "^3.1.14",
"@across-protocol/contracts": "^3.0.10",
"@eth-optimism/sdk": "^3.3.1",
"@pinata/sdk": "^2.1.0",
"@types/mocha": "^10.0.1",
"@uma/sdk": "^0.34.1",
"arweave": "^1.14.4",
"async": "^3.2.5",
"axios": "^0.27.2",
"big-number": "^2.0.0",
"decimal.js": "^10.3.1",
"ethers": "^5.7.2",
"lodash": "^4.17.21",
"lodash.get": "^4.4.2",
"superstruct": "^0.15.4",
"tslib": "^2.6.2"
Expand Down
8 changes: 4 additions & 4 deletions src/caching/Arweave/ArweaveClient.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Arweave from "arweave";
import { JWKInterface } from "arweave/node/lib/wallet";
import axios from "axios";
import { ethers } from "ethers";
import { BigNumber, ethers } from "ethers";
import { Struct, create } from "superstruct";
import winston from "winston";
import { ARWEAVE_TAG_APP_NAME, ARWEAVE_TAG_APP_VERSION, DEFAULT_ARWEAVE_STORAGE_ADDRESS } from "../../constants";
import { isDefined, jsonReplacerWithBigNumbers, parseWinston, toBN } from "../../utils";
import { isDefined, jsonReplacerWithBigNumbers, toBN } from "../../utils";

export class ArweaveClient {
private client: Arweave;
Expand Down Expand Up @@ -230,9 +230,9 @@ export class ArweaveClient {
if (balanceInFloat.includes("e")) {
const [balance, exponent] = balanceInFloat.split("e");
const resultingBN = ethers.BigNumber.from(balance).mul(toBN(10).pow(exponent.replace("+", "")));
return parseWinston(resultingBN.toString());
return BigNumber.from(resultingBN.toString());
} else {
return parseWinston(balanceInFloat);
return BigNumber.from(balanceInFloat);
}
}
}
67 changes: 67 additions & 0 deletions src/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
ConfigStoreVersionUpdate,
DisabledChainsUpdate,
GlobalConfigUpdate,
LiteChainsIdListUpdate,
ParsedTokenConfig,
RouteRateModelUpdate,
SpokePoolTargetBalance,
Expand Down Expand Up @@ -58,6 +59,7 @@ export enum GLOBAL_CONFIG_STORE_KEYS {
VERSION = "VERSION",
DISABLED_CHAINS = "DISABLED_CHAINS",
CHAIN_ID_INDICES = "CHAIN_ID_INDICES",
LITE_CHAIN_ID_INDICES = "LITE_CHAIN_ID_INDICES",
}

export class AcrossConfigStoreClient extends BaseAbstractClient {
Expand All @@ -67,6 +69,7 @@ export class AcrossConfigStoreClient extends BaseAbstractClient {
public cumulativeMaxRefundCountUpdates: GlobalConfigUpdate[] = [];
public cumulativeMaxL1TokenCountUpdates: GlobalConfigUpdate[] = [];
public chainIdIndicesUpdates: GlobalConfigUpdate<number[]>[] = [];
public liteChainIndicesUpdates: LiteChainsIdListUpdate[] = [];
public cumulativeSpokeTargetBalanceUpdates: SpokeTargetBalanceUpdate[] = [];
public cumulativeConfigStoreVersionUpdates: ConfigStoreVersionUpdate[] = [];
public cumulativeDisabledChainUpdates: DisabledChainsUpdate[] = [];
Expand Down Expand Up @@ -153,6 +156,38 @@ export class AcrossConfigStoreClient extends BaseAbstractClient {
return chainIdIndices ?? this.implicitChainIdIndices(this.chainId);
}

/**
* Resolves the lite chain ids that were available to the protocol at a given block range.
* @param blockNumber Block number to search for. Defaults to latest block.
* @returns List of lite chain IDs that were available to the protocol at the given block number.
* @note This dynamic functionality has been added after the launch of Across.
*/
getLiteChainIdIndicesForBlock(blockNumber: number = Number.MAX_SAFE_INTEGER): number[] {
const liteChainIdList = sortEventsDescending(this.liteChainIndicesUpdates);
return liteChainIdList.find((update) => update.blockNumber <= blockNumber)?.value ?? [];
}

/**
* Resolves the lite chain ids that were available to the protocol at a given timestamp.
* @param timestamp Timestamp to search for. Defaults to latest time - in seconds.
* @returns List of lite chain IDs that were available to the protocol at the given timestamp.
* @note This dynamic functionality has been added after the launch of Across.
*/
getLiteChainIdIndicesForTimestamp(timestamp: number = Number.MAX_SAFE_INTEGER): number[] {
const liteChainIdList = sortEventsDescending(this.liteChainIndicesUpdates);
return liteChainIdList.find((update) => update.timestamp <= timestamp)?.value ?? [];
}

/**
* Checks if a chain ID was a lite chain at a given timestamp.
* @param chainId The chain ID to check.
* @param timestamp The timestamp to check. Defaults to latest time - in seconds.
* @returns True if the chain ID was a lite chain at the given timestamp. False otherwise.
*/
isChainLiteChainAtTimestamp(chainId: number, timestamp: number = Number.MAX_SAFE_INTEGER): boolean {
return this.getLiteChainIdIndicesForTimestamp(timestamp).includes(chainId);
}

getSpokeTargetBalancesForBlock(
l1Token: string,
chainId: number,
Expand Down Expand Up @@ -407,6 +442,38 @@ export class AcrossConfigStoreClient extends BaseAbstractClient {
if (!isNaN(args.value)) {
this.cumulativeMaxRefundCountUpdates.push(args);
}
} else if (args.key === utf8ToHex(GLOBAL_CONFIG_STORE_KEYS.LITE_CHAIN_ID_INDICES)) {
// We need to parse the chain ID indices array from the stringified JSON. However,
// the on-chain string has quotes around the array, which will parse our JSON as a
// string instead of an array. We need to remove these quotes before parsing.
// To be sure, we can check for single quotes, double quotes, and spaces.

// Use a regular expression to check if the string is a valid array. We need to check for
// leading and trailing quotes, as well as leading and trailing whitespace. We also need to
// check for commas between the numbers. Alternatively, this can be an empty array.
if (!/^\s*["']?\[(\d+(,\d+)*)?\]["']?\s*$/.test(args.value)) {
this.logger.warn({ at: "ConfigStore", message: `The lite chain indices array ${args.value} is invalid.` });
// If not a valid array, skip.
continue;
}
const chainIndices = JSON.parse(args.value.replace(/['"\s]/g, ""));
// Check that the array is valid and that every element is a number.
if (!isArrayOf<number>(chainIndices, isPositiveInteger)) {
this.logger.warn({ at: "ConfigStore", message: `The array ${chainIndices} is invalid.` });
// If not a valid array, skip.
continue;
}
// Let's also check that the array doesn't contain any duplicates.
if (new Set(chainIndices).size !== chainIndices.length) {
this.logger.warn({
at: "ConfigStore",
message: `The array ${chainIndices} contains duplicates making it invalid.`,
});
// If not a valid array, skip.
continue;
}
// If all else passes, we can add this update.
this.liteChainIndicesUpdates.push({ ...args, value: chainIndices, timestamp: globalConfigUpdateTimes[i] });
} else if (args.key === utf8ToHex(GLOBAL_CONFIG_STORE_KEYS.CHAIN_ID_INDICES)) {
try {
// We need to parse the chain ID indices array from the stringified JSON. However,
Expand Down
Loading

0 comments on commit c23eb42

Please sign in to comment.