diff --git a/.gitignore b/.gitignore index 3a8f634e6..c230c00f6 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,3 @@ typechain-types #Hardhat files cache artifacts - diff --git a/deployments/deployments.json b/deployments/deployments.json new file mode 100644 index 000000000..0e1a2a2a9 --- /dev/null +++ b/deployments/deployments.json @@ -0,0 +1,39 @@ +{ + "4": { + "Arbitrum_Adapter": "0x18F4D98C7CeA6Ab934F2976c2a98009A529d8F49", + "Ethereum_Adapter": "0x682DEa71e7246910A4dec2396a53B24291EB0AD8", + "Ethereum_SpokePool": "0x90743806D7A66b37F31FAfd7b3447210aB55640f", + "HubPool": "0xa1b6DA4AaE90fA16F3A3338c8d1Dc70B4926FCa7", + "LpTokenFactory": "0x0668ab3839346ebf95d969b3e18B2a96b1CC2b02", + "Optimism_Adapter": "0x277C7ecB45851dcB49c494fB4D0d9d8228037f0C", + "PolygonTokenBridger": "0xF92B101f07df74B1f4f3160f9e8a25D48BA5d583", + "Polygon_Adapter": "0xd8176EBf6170513Aa232D065042fa480557232A4" + }, + "5": { + "Arbitrum_Adapter": "0xc6aFa90Ebf5F7eC9Ce0409a0B2bF7b0E6E81b5F6", + "Ethereum_Adapter": "0xbe96050668dECb6FA0ef5Af919f37221658cfbEf", + "Ethereum_SpokePool": "0x9a5de999108042946F59848E083e12690ff018C6", + "HubPool": "0xe1fC1EB80db9AD0160AEF6998673625bc2a09d14", + "LpTokenFactory": "0x56f2c8353049270d3553773E680B0d6c632544b6", + "Optimism_Adapter": "0x04Ec0038859943Cf28E49d51821e33c987C4faDD", + "PolygonTokenBridger": "0xe9D669a4A28aBF4C77c1c6f98942638b7A9aEaC9", + "Polygon_Adapter": "0xD732393f8eC57644675c104Ec8A4661db58CCE41" + }, + "42": { + "Arbitrum_Adapter": "0xD007aB76E36B03853C1F2fE5980069E7ACd38FF8", + "Ethereum_Adapter": "0x304d7cbD119E356084b6c02542191EA43df5E399", + "Ethereum_SpokePool": "0x73549B5639B04090033c1E77a22eE9Aa44C2eBa0", + "HubPool": "0xD449Af45a032Df413b497A709EeD3E8C112EbcE3", + "LpTokenFactory": "0x2C4f1527Ec183ccD25f65816Cfc3a45b26B626B8", + "Optimism_Adapter": "0x7851603f5d6679FC8fFe76bBCb08a88Db34DB4E2", + "PolygonTokenBridger": "0x6C9cb9a525aED1f6EEbF5321A1f35DF3ec3dfe84", + "Polygon_Adapter": "0x3aa1b039252ee320bd551875213AFA4996c00b85", + "RateModelStore": "0x5923929DF7A2D6E038bb005B167c1E8a86cd13C8" + }, + "69": { "Optimism_SpokePool": "0x2b7b7bAE341089103dD22fa4e8D7E4FA63E11084" }, + "80001": { + "PolygonTokenBridger": "0xe9D669a4A28aBF4C77c1c6f98942638b7A9aEaC9", + "Polygon_SpokePool": "0xC50c8cEd449321a6c506a5Da409D9eDe7269ac3a" + }, + "421611": { "Arbitrum_SpokePool": "0x3BED21dAe767e4Df894B31b14aD32369cE4bad8b" } +} diff --git a/index.ts b/index.ts index 515806496..b53e01cc9 100644 --- a/index.ts +++ b/index.ts @@ -1 +1,3 @@ export * from "./typechain"; +export * from "./src/ContractFinder"; +export * from "./utils/MerkleTree"; diff --git a/package.json b/package.json index 4f8235d78..c26309cbb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@across-protocol/contracts-v2", - "version": "0.0.33", + "version": "0.0.38", "author": "UMA Team", "license": "AGPL-3.0", "repository": { @@ -24,7 +24,7 @@ "test:report-gas": "REPORT_GAS=true hardhat test", "test:gas-analytics": "GAS_TEST_ENABLED=true hardhat test ./test/gas-analytics/*", "test:all": "GAS_TEST_ENABLED=true REPORT_GAS=true yarn hardhat test", - "prepublish": "yarn build" + "prepublish": "yarn build && hardhat export --export-all ./cache/massExport.json && ts-node ./scripts/processHardhatExport.ts && prettier --write ./deployments/deployments.json" }, "dependencies": { "@defi-wonderland/smock": "^2.0.7", diff --git a/scripts/buildSampleTree.ts b/scripts/buildSampleTree.ts index de7bca7aa..451b1d4aa 100644 --- a/scripts/buildSampleTree.ts +++ b/scripts/buildSampleTree.ts @@ -126,11 +126,11 @@ async function main() { depositor: SLOW_RELAY_RECIPIENT_ADDRESS, recipient: SLOW_RELAY_RECIPIENT_ADDRESS, destinationToken: L2_TOKEN, - amount: toBNWeiWithDecimals(SLOW_RELAY_AMOUNT, DECIMALS).toString(), + amount: toBNWeiWithDecimals(SLOW_RELAY_AMOUNT, DECIMALS), originChainId: SPOKE_POOL_CHAIN_ID.toString(), destinationChainId: SPOKE_POOL_CHAIN_ID.toString(), - realizedLpFeePct: "0", - relayerFeePct: "0", + realizedLpFeePct: toBN(0), + relayerFeePct: toBN(0), depositId: i.toString(), }); console.group(); diff --git a/scripts/processHardhatExport.ts b/scripts/processHardhatExport.ts new file mode 100644 index 000000000..c7276d8e5 --- /dev/null +++ b/scripts/processHardhatExport.ts @@ -0,0 +1,29 @@ +import fs from "fs"; +import path from "path"; + +// Prunes the hardhat export file sent to the cache directory to only contain the deployment addresses of each contract +// over the network of chains the Across v2 contracts are deployed on. Meant to be run as part of a publish process. +export async function run(): Promise { + try { + const deploymentExport = require("../cache/massExport.json"); + const castExport = deploymentExport as any; + console.log("Generating exports on the following networks(if they have deployments)", Object.keys(castExport)); + const processedOutput: { [chainid: string]: { [contractName: string]: string } } = {}; + Object.keys(castExport).forEach((chainId) => { + if (castExport[chainId][0]) + Object.keys(castExport[chainId][0].contracts).forEach((contractName) => { + if (!processedOutput[chainId]) processedOutput[chainId] = {}; + processedOutput[chainId][contractName] = castExport[chainId][0]?.contracts[contractName].address; + }); + }); + console.log("Constructed the following address export for release:\n", processedOutput); + + fs.writeFileSync(`${path.resolve(__dirname)}/../deployments/deployments.json`, JSON.stringify(processedOutput)); + } catch (error) {} +} + +if (require.main === module) { + run().then(() => { + process.exit(0); + }); +} diff --git a/src/ContractFinder.ts b/src/ContractFinder.ts new file mode 100644 index 000000000..dbfd3153b --- /dev/null +++ b/src/ContractFinder.ts @@ -0,0 +1,11 @@ +import * as deployments from "../deployments/deployments.json"; + +// Returns the deployed address of any contract on any network. Uses the pruned network file in the deployments directory. +// Note that we dont export the contract ABI or bytecode. Implementors are expected to use the typechain artifacts. +export function getDeployedAddress(contractName: string, networkId: number): string { + try { + return (deployments as any)[networkId.toString()][contractName]; + } catch (_) { + throw new Error(`Contract ${contractName} not found on ${networkId} in export.json`); + } +} diff --git a/test/SpokePool.Relay.ts b/test/SpokePool.Relay.ts index 7f4f21cc6..28da44e5a 100644 --- a/test/SpokePool.Relay.ts +++ b/test/SpokePool.Relay.ts @@ -105,9 +105,9 @@ describe("SpokePool Relayer Logic", async function () { consts.originChainId, consts.destinationChainId, destErc20.address, - consts.amountToDeposit.toString(), - toWei("0.5").toString(), - consts.depositRelayerFeePct.toString() + consts.amountToDeposit, + toWei("0.5"), + consts.depositRelayerFeePct ).relayData, consts.amountToRelay, consts.repaymentChainId @@ -126,9 +126,9 @@ describe("SpokePool Relayer Logic", async function () { consts.originChainId, consts.destinationChainId, destErc20.address, - consts.amountToDeposit.toString(), - consts.realizedLpFeePct.toString(), - toWei("0.5").toString() + consts.amountToDeposit, + consts.realizedLpFeePct, + toWei("0.5") ).relayData, consts.amountToRelay, consts.repaymentChainId diff --git a/test/SpokePool.SlowRelay.ts b/test/SpokePool.SlowRelay.ts index b4dd8ff0d..5e67273bc 100644 --- a/test/SpokePool.SlowRelay.ts +++ b/test/SpokePool.SlowRelay.ts @@ -47,11 +47,11 @@ describe("SpokePool Slow Relay Logic", async function () { depositor: randomAddress(), recipient: randomAddress(), destinationToken: randomAddress(), - amount: randomBigNumber().toString(), + amount: randomBigNumber(), originChainId: randomBigNumber(2).toString(), destinationChainId: OTHER_DESTINATION_CHAIN_ID, - realizedLpFeePct: randomBigNumber(8).toString(), - relayerFeePct: randomBigNumber(8).toString(), + realizedLpFeePct: randomBigNumber(8), + relayerFeePct: randomBigNumber(8), depositId: randomBigNumber(2).toString(), }); } @@ -61,11 +61,11 @@ describe("SpokePool Slow Relay Logic", async function () { depositor: depositor.address, recipient: recipient.address, destinationToken: destErc20.address, - amount: consts.amountToRelay.toString(), + amount: consts.amountToRelay, originChainId: consts.originChainId.toString(), destinationChainId: consts.destinationChainId.toString(), - realizedLpFeePct: consts.realizedLpFeePct.toString(), - relayerFeePct: consts.depositRelayerFeePct.toString(), + realizedLpFeePct: consts.realizedLpFeePct, + relayerFeePct: consts.depositRelayerFeePct, depositId: consts.firstDepositId.toString(), }); @@ -74,11 +74,11 @@ describe("SpokePool Slow Relay Logic", async function () { depositor: depositor.address, recipient: recipient.address, destinationToken: weth.address, - amount: consts.amountToRelay.toString(), + amount: consts.amountToRelay, originChainId: consts.originChainId.toString(), destinationChainId: consts.destinationChainId.toString(), - realizedLpFeePct: consts.realizedLpFeePct.toString(), - relayerFeePct: consts.depositRelayerFeePct.toString(), + realizedLpFeePct: consts.realizedLpFeePct, + relayerFeePct: consts.depositRelayerFeePct, depositId: consts.firstDepositId.toString(), }); @@ -213,7 +213,7 @@ describe("SpokePool Slow Relay Logic", async function () { consts.originChainId, consts.destinationChainId, destErc20.address, - consts.amountToRelay.toString() + consts.amountToRelay ).relayData, partialAmountPostFees ) @@ -255,7 +255,7 @@ describe("SpokePool Slow Relay Logic", async function () { consts.originChainId, consts.destinationChainId, weth.address, - consts.amountToRelay.toString() + consts.amountToRelay ).relayData, partialAmountPostFees ) @@ -298,7 +298,7 @@ describe("SpokePool Slow Relay Logic", async function () { consts.originChainId, consts.destinationChainId, weth.address, - consts.amountToRelay.toString() + consts.amountToRelay ).relayData, partialAmountPostFees ) diff --git a/test/fixtures/SpokePool.Fixture.ts b/test/fixtures/SpokePool.Fixture.ts index 0856486c1..4fbbadd77 100644 --- a/test/fixtures/SpokePool.Fixture.ts +++ b/test/fixtures/SpokePool.Fixture.ts @@ -101,7 +101,7 @@ export async function deposit( export async function fillRelay( spokePool: Contract, - destErc20: Contract, + destErc20: Contract | string, recipient: SignerWithAddress, depositor: SignerWithAddress, relayer: SignerWithAddress, @@ -117,15 +117,15 @@ export async function fillRelay( .fillRelay( ...getFillRelayParams( getRelayHash( - depositor.address ?? depositor, - recipient.address ?? recipient, + depositor.address, + recipient.address, depositId, originChainId, consts.destinationChainId, - destErc20.address ?? destErc20, - depositAmount.toString(), - realizedLpFeePct.toString(), - relayerFeePct.toString() + (destErc20 as Contract).address ?? (destErc20 as string), + depositAmount, + realizedLpFeePct, + relayerFeePct ).relayData, amountToRelay, consts.repaymentChainId @@ -161,9 +161,9 @@ export interface RelayData { depositor: string; recipient: string; destinationToken: string; - amount: string; - realizedLpFeePct: string; - relayerFeePct: string; + amount: BigNumber; + realizedLpFeePct: BigNumber; + relayerFeePct: BigNumber; depositId: string; originChainId: string; destinationChainId: string; @@ -175,19 +175,19 @@ export function getRelayHash( _originChainId: number, _destinationChainId: number, _destinationToken: string, - _amount?: string, - _realizedLpFeePct?: string, - _relayerFeePct?: string + _amount?: BigNumber, + _realizedLpFeePct?: BigNumber, + _relayerFeePct?: BigNumber ): { relayHash: string; relayData: RelayData } { const relayData = { depositor: _depositor, recipient: _recipient, destinationToken: _destinationToken, - amount: _amount || consts.amountToDeposit.toString(), + amount: _amount || consts.amountToDeposit, originChainId: _originChainId.toString(), destinationChainId: _destinationChainId.toString(), - realizedLpFeePct: _realizedLpFeePct || consts.realizedLpFeePct.toString(), - relayerFeePct: _relayerFeePct || consts.depositRelayerFeePct.toString(), + realizedLpFeePct: _realizedLpFeePct || consts.realizedLpFeePct, + relayerFeePct: _relayerFeePct || consts.depositRelayerFeePct, depositId: _depositId.toString(), }; const relayHash = ethers.utils.keccak256( @@ -196,10 +196,7 @@ export function getRelayHash( Object.values(relayData) ) ); - return { - relayHash, - relayData, - }; + return { relayHash, relayData }; } export function getDepositParams( @@ -229,12 +226,12 @@ export function getFillRelayParams( _relayData.depositor, _relayData.recipient, _relayData.destinationToken, - _relayData.amount, + _relayData.amount.toString(), _maxTokensToSend.toString(), _repaymentChain ? _repaymentChain.toString() : consts.repaymentChainId.toString(), _relayData.originChainId, - _relayData.realizedLpFeePct, - _relayData.relayerFeePct, + _relayData.realizedLpFeePct.toString(), + _relayData.relayerFeePct.toString(), _relayData.depositId, ]; } @@ -250,12 +247,12 @@ export function getFillRelayUpdatedFeeParams( _relayData.depositor, _relayData.recipient, _relayData.destinationToken, - _relayData.amount, + _relayData.amount.toString(), _maxTokensToSend.toString(), _repaymentChain ? _repaymentChain.toString() : consts.repaymentChainId.toString(), _relayData.originChainId, - _relayData.realizedLpFeePct, - _relayData.relayerFeePct, + _relayData.realizedLpFeePct.toString(), + _relayData.relayerFeePct.toString(), _updatedFee.toString(), _relayData.depositId, _signature, diff --git a/test/gas-analytics/SpokePool.SlowRelayLeafExecution.ts b/test/gas-analytics/SpokePool.SlowRelayLeafExecution.ts index 664b353bf..5cc97e7bc 100644 --- a/test/gas-analytics/SpokePool.SlowRelayLeafExecution.ts +++ b/test/gas-analytics/SpokePool.SlowRelayLeafExecution.ts @@ -1,4 +1,5 @@ -import { toBNWei, SignerWithAddress, Contract, ethers, toBN, expect, seedContract, seedWallet } from "../utils"; +import { toBNWei, SignerWithAddress, Contract, ethers, toBN, expect } from "../utils"; +import { seedContract, seedWallet, BigNumber } from "../utils"; import { deployErc20, warmSpokePool } from "./utils"; import * as consts from "../constants"; import { spokePoolFixture, RelayData } from "../fixtures/SpokePool.Fixture"; @@ -28,7 +29,7 @@ async function constructSimpleTree( depositor: string, recipient: string, destinationTokens: string[], - universalRelayAmount: string + universalRelayAmount: BigNumber ) { // Each refund amount mapped to one refund address. expect(destinationTokens.length).to.equal(LEAF_COUNT); @@ -39,11 +40,11 @@ async function constructSimpleTree( depositor, recipient, destinationToken: destinationTokens[i], - amount: universalRelayAmount, + amount: toBN(universalRelayAmount), originChainId: ORIGIN_CHAIN_ID, destinationChainId: consts.destinationChainId.toString(), - realizedLpFeePct: FEE_PCT, - relayerFeePct: FEE_PCT, + realizedLpFeePct: toBN(FEE_PCT), + relayerFeePct: toBN(FEE_PCT), depositId: i.toString(), }); } @@ -88,7 +89,7 @@ describe("Gas Analytics: SpokePool Slow Relay Root Execution", function () { owner.address, recipient.address, l2Tokens.map((token) => token.address), - "1" + toBN(1) ); // Store new tree. @@ -114,7 +115,7 @@ describe("Gas Analytics: SpokePool Slow Relay Root Execution", function () { owner.address, recipient.address, l2Tokens.map((token) => token.address), - RELAY_AMOUNT.toString() + RELAY_AMOUNT ); leaves = simpleTree.leaves; tree = simpleTree.tree; @@ -206,7 +207,7 @@ describe("Gas Analytics: SpokePool Slow Relay Root Execution", function () { owner.address, recipient.address, Array(LEAF_COUNT).fill(weth.address), - "1" + toBN(1) ); // Store new tree. @@ -232,7 +233,7 @@ describe("Gas Analytics: SpokePool Slow Relay Root Execution", function () { owner.address, recipient.address, Array(LEAF_COUNT).fill(weth.address), - RELAY_AMOUNT.toString() + RELAY_AMOUNT ); leaves = simpleTree.leaves; tree = simpleTree.tree; diff --git a/tsconfig.json b/tsconfig.json index c4b670412..4cbb79dfa 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,8 @@ "esModuleInterop": true, "outDir": "./dist", "declaration": true, - "skipLibCheck": true + "skipLibCheck": true, + "resolveJsonModule": true }, "include": ["./scripts", "./test", "./typechain", "./index.ts", "./test-utils.ts"], "files": ["./hardhat.config.ts"]