Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ typechain-types
#Hardhat files
cache
artifacts

39 changes: 39 additions & 0 deletions deployments/deployments.json
Original file line number Diff line number Diff line change
@@ -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" }
}
2 changes: 2 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from "./typechain";
export * from "./src/ContractFinder";
export * from "./utils/MerkleTree";
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more involved now.

},
"dependencies": {
"@defi-wonderland/smock": "^2.0.7",
Expand Down
6 changes: 3 additions & 3 deletions scripts/buildSampleTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
29 changes: 29 additions & 0 deletions scripts/processHardhatExport.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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);
});
}
11 changes: 11 additions & 0 deletions src/ContractFinder.ts
Original file line number Diff line number Diff line change
@@ -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`);
}
}
12 changes: 6 additions & 6 deletions test/SpokePool.Relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
24 changes: 12 additions & 12 deletions test/SpokePool.SlowRelay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});
}
Expand All @@ -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(),
});

Expand All @@ -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(),
});

Expand Down Expand Up @@ -213,7 +213,7 @@ describe("SpokePool Slow Relay Logic", async function () {
consts.originChainId,
consts.destinationChainId,
destErc20.address,
consts.amountToRelay.toString()
consts.amountToRelay
).relayData,
partialAmountPostFees
)
Expand Down Expand Up @@ -255,7 +255,7 @@ describe("SpokePool Slow Relay Logic", async function () {
consts.originChainId,
consts.destinationChainId,
weth.address,
consts.amountToRelay.toString()
consts.amountToRelay
).relayData,
partialAmountPostFees
)
Expand Down Expand Up @@ -298,7 +298,7 @@ describe("SpokePool Slow Relay Logic", async function () {
consts.originChainId,
consts.destinationChainId,
weth.address,
consts.amountToRelay.toString()
consts.amountToRelay
).relayData,
partialAmountPostFees
)
Expand Down
49 changes: 23 additions & 26 deletions test/fixtures/SpokePool.Fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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
Comment on lines -178 to +180
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the reason all the other .toStrings() were removed: we now use the correct types.

): { 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(
Expand All @@ -196,10 +196,7 @@ export function getRelayHash(
Object.values(relayData)
)
);
return {
relayHash,
relayData,
};
return { relayHash, relayData };
}

export function getDepositParams(
Expand Down Expand Up @@ -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,
];
}
Expand All @@ -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,
Expand Down
Loading