Skip to content

Commit df4d784

Browse files
authored
feat: add contract finder to export artifacts and addresses for contracts (#129)
* feat: add contract finder to export artifacts and addresses for contracts Signed-off-by: chrismaree <christopher.maree@gmail.com> * nit Signed-off-by: chrismaree <christopher.maree@gmail.com> * nit Signed-off-by: chrismaree <christopher.maree@gmail.com> * nit Signed-off-by: chrismaree <christopher.maree@gmail.com> * nit Signed-off-by: chrismaree <christopher.maree@gmail.com> * nit Signed-off-by: chrismaree <christopher.maree@gmail.com> * nit Signed-off-by: chrismaree <christopher.maree@gmail.com> * nit Signed-off-by: chrismaree <christopher.maree@gmail.com> * nit Signed-off-by: chrismaree <christopher.maree@gmail.com> * nit Signed-off-by: chrismaree <christopher.maree@gmail.com> * nit Signed-off-by: chrismaree <christopher.maree@gmail.com> * nit Signed-off-by: chrismaree <christopher.maree@gmail.com> * nit Signed-off-by: chrismaree <christopher.maree@gmail.com> * Restore Ethereum_SpokePool.json * Delete 0cbb34d0852dbbdf983e586f15b99b69.json * nit Signed-off-by: chrismaree <christopher.maree@gmail.com> * nit Signed-off-by: chrismaree <christopher.maree@gmail.com> * nit Signed-off-by: chrismaree <christopher.maree@gmail.com> * nit Signed-off-by: chrismaree <christopher.maree@gmail.com> * nit Signed-off-by: chrismaree <christopher.maree@gmail.com> * nit Signed-off-by: chrismaree <christopher.maree@gmail.com> * nit Signed-off-by: chrismaree <christopher.maree@gmail.com> * nit Signed-off-by: chrismaree <christopher.maree@gmail.com> * nit Signed-off-by: chrismaree <christopher.maree@gmail.com> * nit Signed-off-by: chrismaree <christopher.maree@gmail.com>
1 parent 72b796e commit df4d784

File tree

12 files changed

+139
-60
lines changed

12 files changed

+139
-60
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ typechain-types
99
#Hardhat files
1010
cache
1111
artifacts
12-

deployments/deployments.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"4": {
3+
"Arbitrum_Adapter": "0x18F4D98C7CeA6Ab934F2976c2a98009A529d8F49",
4+
"Ethereum_Adapter": "0x682DEa71e7246910A4dec2396a53B24291EB0AD8",
5+
"Ethereum_SpokePool": "0x90743806D7A66b37F31FAfd7b3447210aB55640f",
6+
"HubPool": "0xa1b6DA4AaE90fA16F3A3338c8d1Dc70B4926FCa7",
7+
"LpTokenFactory": "0x0668ab3839346ebf95d969b3e18B2a96b1CC2b02",
8+
"Optimism_Adapter": "0x277C7ecB45851dcB49c494fB4D0d9d8228037f0C",
9+
"PolygonTokenBridger": "0xF92B101f07df74B1f4f3160f9e8a25D48BA5d583",
10+
"Polygon_Adapter": "0xd8176EBf6170513Aa232D065042fa480557232A4"
11+
},
12+
"5": {
13+
"Arbitrum_Adapter": "0xc6aFa90Ebf5F7eC9Ce0409a0B2bF7b0E6E81b5F6",
14+
"Ethereum_Adapter": "0xbe96050668dECb6FA0ef5Af919f37221658cfbEf",
15+
"Ethereum_SpokePool": "0x9a5de999108042946F59848E083e12690ff018C6",
16+
"HubPool": "0xe1fC1EB80db9AD0160AEF6998673625bc2a09d14",
17+
"LpTokenFactory": "0x56f2c8353049270d3553773E680B0d6c632544b6",
18+
"Optimism_Adapter": "0x04Ec0038859943Cf28E49d51821e33c987C4faDD",
19+
"PolygonTokenBridger": "0xe9D669a4A28aBF4C77c1c6f98942638b7A9aEaC9",
20+
"Polygon_Adapter": "0xD732393f8eC57644675c104Ec8A4661db58CCE41"
21+
},
22+
"42": {
23+
"Arbitrum_Adapter": "0xD007aB76E36B03853C1F2fE5980069E7ACd38FF8",
24+
"Ethereum_Adapter": "0x304d7cbD119E356084b6c02542191EA43df5E399",
25+
"Ethereum_SpokePool": "0x73549B5639B04090033c1E77a22eE9Aa44C2eBa0",
26+
"HubPool": "0xD449Af45a032Df413b497A709EeD3E8C112EbcE3",
27+
"LpTokenFactory": "0x2C4f1527Ec183ccD25f65816Cfc3a45b26B626B8",
28+
"Optimism_Adapter": "0x7851603f5d6679FC8fFe76bBCb08a88Db34DB4E2",
29+
"PolygonTokenBridger": "0x6C9cb9a525aED1f6EEbF5321A1f35DF3ec3dfe84",
30+
"Polygon_Adapter": "0x3aa1b039252ee320bd551875213AFA4996c00b85",
31+
"RateModelStore": "0x5923929DF7A2D6E038bb005B167c1E8a86cd13C8"
32+
},
33+
"69": { "Optimism_SpokePool": "0x2b7b7bAE341089103dD22fa4e8D7E4FA63E11084" },
34+
"80001": {
35+
"PolygonTokenBridger": "0xe9D669a4A28aBF4C77c1c6f98942638b7A9aEaC9",
36+
"Polygon_SpokePool": "0xC50c8cEd449321a6c506a5Da409D9eDe7269ac3a"
37+
},
38+
"421611": { "Arbitrum_SpokePool": "0x3BED21dAe767e4Df894B31b14aD32369cE4bad8b" }
39+
}

index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
export * from "./typechain";
2+
export * from "./src/ContractFinder";
3+
export * from "./utils/MerkleTree";

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@across-protocol/contracts-v2",
3-
"version": "0.0.33",
3+
"version": "0.0.38",
44
"author": "UMA Team",
55
"license": "AGPL-3.0",
66
"repository": {
@@ -24,7 +24,7 @@
2424
"test:report-gas": "REPORT_GAS=true hardhat test",
2525
"test:gas-analytics": "GAS_TEST_ENABLED=true hardhat test ./test/gas-analytics/*",
2626
"test:all": "GAS_TEST_ENABLED=true REPORT_GAS=true yarn hardhat test",
27-
"prepublish": "yarn build"
27+
"prepublish": "yarn build && hardhat export --export-all ./cache/massExport.json && ts-node ./scripts/processHardhatExport.ts && prettier --write ./deployments/deployments.json"
2828
},
2929
"dependencies": {
3030
"@defi-wonderland/smock": "^2.0.7",

scripts/buildSampleTree.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ async function main() {
126126
depositor: SLOW_RELAY_RECIPIENT_ADDRESS,
127127
recipient: SLOW_RELAY_RECIPIENT_ADDRESS,
128128
destinationToken: L2_TOKEN,
129-
amount: toBNWeiWithDecimals(SLOW_RELAY_AMOUNT, DECIMALS).toString(),
129+
amount: toBNWeiWithDecimals(SLOW_RELAY_AMOUNT, DECIMALS),
130130
originChainId: SPOKE_POOL_CHAIN_ID.toString(),
131131
destinationChainId: SPOKE_POOL_CHAIN_ID.toString(),
132-
realizedLpFeePct: "0",
133-
relayerFeePct: "0",
132+
realizedLpFeePct: toBN(0),
133+
relayerFeePct: toBN(0),
134134
depositId: i.toString(),
135135
});
136136
console.group();

scripts/processHardhatExport.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import fs from "fs";
2+
import path from "path";
3+
4+
// Prunes the hardhat export file sent to the cache directory to only contain the deployment addresses of each contract
5+
// over the network of chains the Across v2 contracts are deployed on. Meant to be run as part of a publish process.
6+
export async function run(): Promise<void> {
7+
try {
8+
const deploymentExport = require("../cache/massExport.json");
9+
const castExport = deploymentExport as any;
10+
console.log("Generating exports on the following networks(if they have deployments)", Object.keys(castExport));
11+
const processedOutput: { [chainid: string]: { [contractName: string]: string } } = {};
12+
Object.keys(castExport).forEach((chainId) => {
13+
if (castExport[chainId][0])
14+
Object.keys(castExport[chainId][0].contracts).forEach((contractName) => {
15+
if (!processedOutput[chainId]) processedOutput[chainId] = {};
16+
processedOutput[chainId][contractName] = castExport[chainId][0]?.contracts[contractName].address;
17+
});
18+
});
19+
console.log("Constructed the following address export for release:\n", processedOutput);
20+
21+
fs.writeFileSync(`${path.resolve(__dirname)}/../deployments/deployments.json`, JSON.stringify(processedOutput));
22+
} catch (error) {}
23+
}
24+
25+
if (require.main === module) {
26+
run().then(() => {
27+
process.exit(0);
28+
});
29+
}

src/ContractFinder.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as deployments from "../deployments/deployments.json";
2+
3+
// Returns the deployed address of any contract on any network. Uses the pruned network file in the deployments directory.
4+
// Note that we dont export the contract ABI or bytecode. Implementors are expected to use the typechain artifacts.
5+
export function getDeployedAddress(contractName: string, networkId: number): string {
6+
try {
7+
return (deployments as any)[networkId.toString()][contractName];
8+
} catch (_) {
9+
throw new Error(`Contract ${contractName} not found on ${networkId} in export.json`);
10+
}
11+
}

test/SpokePool.Relay.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ describe("SpokePool Relayer Logic", async function () {
105105
consts.originChainId,
106106
consts.destinationChainId,
107107
destErc20.address,
108-
consts.amountToDeposit.toString(),
109-
toWei("0.5").toString(),
110-
consts.depositRelayerFeePct.toString()
108+
consts.amountToDeposit,
109+
toWei("0.5"),
110+
consts.depositRelayerFeePct
111111
).relayData,
112112
consts.amountToRelay,
113113
consts.repaymentChainId
@@ -126,9 +126,9 @@ describe("SpokePool Relayer Logic", async function () {
126126
consts.originChainId,
127127
consts.destinationChainId,
128128
destErc20.address,
129-
consts.amountToDeposit.toString(),
130-
consts.realizedLpFeePct.toString(),
131-
toWei("0.5").toString()
129+
consts.amountToDeposit,
130+
consts.realizedLpFeePct,
131+
toWei("0.5")
132132
).relayData,
133133
consts.amountToRelay,
134134
consts.repaymentChainId

test/SpokePool.SlowRelay.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ describe("SpokePool Slow Relay Logic", async function () {
4747
depositor: randomAddress(),
4848
recipient: randomAddress(),
4949
destinationToken: randomAddress(),
50-
amount: randomBigNumber().toString(),
50+
amount: randomBigNumber(),
5151
originChainId: randomBigNumber(2).toString(),
5252
destinationChainId: OTHER_DESTINATION_CHAIN_ID,
53-
realizedLpFeePct: randomBigNumber(8).toString(),
54-
relayerFeePct: randomBigNumber(8).toString(),
53+
realizedLpFeePct: randomBigNumber(8),
54+
relayerFeePct: randomBigNumber(8),
5555
depositId: randomBigNumber(2).toString(),
5656
});
5757
}
@@ -61,11 +61,11 @@ describe("SpokePool Slow Relay Logic", async function () {
6161
depositor: depositor.address,
6262
recipient: recipient.address,
6363
destinationToken: destErc20.address,
64-
amount: consts.amountToRelay.toString(),
64+
amount: consts.amountToRelay,
6565
originChainId: consts.originChainId.toString(),
6666
destinationChainId: consts.destinationChainId.toString(),
67-
realizedLpFeePct: consts.realizedLpFeePct.toString(),
68-
relayerFeePct: consts.depositRelayerFeePct.toString(),
67+
realizedLpFeePct: consts.realizedLpFeePct,
68+
relayerFeePct: consts.depositRelayerFeePct,
6969
depositId: consts.firstDepositId.toString(),
7070
});
7171

@@ -74,11 +74,11 @@ describe("SpokePool Slow Relay Logic", async function () {
7474
depositor: depositor.address,
7575
recipient: recipient.address,
7676
destinationToken: weth.address,
77-
amount: consts.amountToRelay.toString(),
77+
amount: consts.amountToRelay,
7878
originChainId: consts.originChainId.toString(),
7979
destinationChainId: consts.destinationChainId.toString(),
80-
realizedLpFeePct: consts.realizedLpFeePct.toString(),
81-
relayerFeePct: consts.depositRelayerFeePct.toString(),
80+
realizedLpFeePct: consts.realizedLpFeePct,
81+
relayerFeePct: consts.depositRelayerFeePct,
8282
depositId: consts.firstDepositId.toString(),
8383
});
8484

@@ -213,7 +213,7 @@ describe("SpokePool Slow Relay Logic", async function () {
213213
consts.originChainId,
214214
consts.destinationChainId,
215215
destErc20.address,
216-
consts.amountToRelay.toString()
216+
consts.amountToRelay
217217
).relayData,
218218
partialAmountPostFees
219219
)
@@ -255,7 +255,7 @@ describe("SpokePool Slow Relay Logic", async function () {
255255
consts.originChainId,
256256
consts.destinationChainId,
257257
weth.address,
258-
consts.amountToRelay.toString()
258+
consts.amountToRelay
259259
).relayData,
260260
partialAmountPostFees
261261
)
@@ -298,7 +298,7 @@ describe("SpokePool Slow Relay Logic", async function () {
298298
consts.originChainId,
299299
consts.destinationChainId,
300300
weth.address,
301-
consts.amountToRelay.toString()
301+
consts.amountToRelay
302302
).relayData,
303303
partialAmountPostFees
304304
)

test/fixtures/SpokePool.Fixture.ts

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export async function deposit(
101101

102102
export async function fillRelay(
103103
spokePool: Contract,
104-
destErc20: Contract,
104+
destErc20: Contract | string,
105105
recipient: SignerWithAddress,
106106
depositor: SignerWithAddress,
107107
relayer: SignerWithAddress,
@@ -117,15 +117,15 @@ export async function fillRelay(
117117
.fillRelay(
118118
...getFillRelayParams(
119119
getRelayHash(
120-
depositor.address ?? depositor,
121-
recipient.address ?? recipient,
120+
depositor.address,
121+
recipient.address,
122122
depositId,
123123
originChainId,
124124
consts.destinationChainId,
125-
destErc20.address ?? destErc20,
126-
depositAmount.toString(),
127-
realizedLpFeePct.toString(),
128-
relayerFeePct.toString()
125+
(destErc20 as Contract).address ?? (destErc20 as string),
126+
depositAmount,
127+
realizedLpFeePct,
128+
relayerFeePct
129129
).relayData,
130130
amountToRelay,
131131
consts.repaymentChainId
@@ -161,9 +161,9 @@ export interface RelayData {
161161
depositor: string;
162162
recipient: string;
163163
destinationToken: string;
164-
amount: string;
165-
realizedLpFeePct: string;
166-
relayerFeePct: string;
164+
amount: BigNumber;
165+
realizedLpFeePct: BigNumber;
166+
relayerFeePct: BigNumber;
167167
depositId: string;
168168
originChainId: string;
169169
destinationChainId: string;
@@ -175,19 +175,19 @@ export function getRelayHash(
175175
_originChainId: number,
176176
_destinationChainId: number,
177177
_destinationToken: string,
178-
_amount?: string,
179-
_realizedLpFeePct?: string,
180-
_relayerFeePct?: string
178+
_amount?: BigNumber,
179+
_realizedLpFeePct?: BigNumber,
180+
_relayerFeePct?: BigNumber
181181
): { relayHash: string; relayData: RelayData } {
182182
const relayData = {
183183
depositor: _depositor,
184184
recipient: _recipient,
185185
destinationToken: _destinationToken,
186-
amount: _amount || consts.amountToDeposit.toString(),
186+
amount: _amount || consts.amountToDeposit,
187187
originChainId: _originChainId.toString(),
188188
destinationChainId: _destinationChainId.toString(),
189-
realizedLpFeePct: _realizedLpFeePct || consts.realizedLpFeePct.toString(),
190-
relayerFeePct: _relayerFeePct || consts.depositRelayerFeePct.toString(),
189+
realizedLpFeePct: _realizedLpFeePct || consts.realizedLpFeePct,
190+
relayerFeePct: _relayerFeePct || consts.depositRelayerFeePct,
191191
depositId: _depositId.toString(),
192192
};
193193
const relayHash = ethers.utils.keccak256(
@@ -196,10 +196,7 @@ export function getRelayHash(
196196
Object.values(relayData)
197197
)
198198
);
199-
return {
200-
relayHash,
201-
relayData,
202-
};
199+
return { relayHash, relayData };
203200
}
204201

205202
export function getDepositParams(
@@ -229,12 +226,12 @@ export function getFillRelayParams(
229226
_relayData.depositor,
230227
_relayData.recipient,
231228
_relayData.destinationToken,
232-
_relayData.amount,
229+
_relayData.amount.toString(),
233230
_maxTokensToSend.toString(),
234231
_repaymentChain ? _repaymentChain.toString() : consts.repaymentChainId.toString(),
235232
_relayData.originChainId,
236-
_relayData.realizedLpFeePct,
237-
_relayData.relayerFeePct,
233+
_relayData.realizedLpFeePct.toString(),
234+
_relayData.relayerFeePct.toString(),
238235
_relayData.depositId,
239236
];
240237
}
@@ -250,12 +247,12 @@ export function getFillRelayUpdatedFeeParams(
250247
_relayData.depositor,
251248
_relayData.recipient,
252249
_relayData.destinationToken,
253-
_relayData.amount,
250+
_relayData.amount.toString(),
254251
_maxTokensToSend.toString(),
255252
_repaymentChain ? _repaymentChain.toString() : consts.repaymentChainId.toString(),
256253
_relayData.originChainId,
257-
_relayData.realizedLpFeePct,
258-
_relayData.relayerFeePct,
254+
_relayData.realizedLpFeePct.toString(),
255+
_relayData.relayerFeePct.toString(),
259256
_updatedFee.toString(),
260257
_relayData.depositId,
261258
_signature,

0 commit comments

Comments
 (0)