-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
brings devnets to multisig-wallet example
- Loading branch information
1 parent
aea5c9d
commit 656d43c
Showing
15 changed files
with
22,312 additions
and
4,870 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,3 +79,4 @@ typings/ | |
|
||
# macOS | ||
.DS_Store | ||
.devnet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"latest": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { replaceExistingForkwWith } from "../tenderly-infra"; | ||
import { aTenderlyFork, removeFork } from "./tenderly-api"; | ||
|
||
export const deleteAndCreateFork = async () => { | ||
const forkUrl = | ||
process.env.FORK_MODE === "TEST" | ||
? process.env.TENDERLY_TEST_FORK_URL | ||
: process.env.TENDERLY_FORK_URL; | ||
|
||
if (!!forkUrl) { | ||
const forkId = forkUrl.split("/").reverse()[0]; | ||
console.log("Removing fork", forkId); | ||
await removeFork(forkId).catch((err) => { | ||
// console.error(err); | ||
}); | ||
} | ||
console.log("Creating a fork"); | ||
console.time("fork"); | ||
const fork = await aTenderlyFork({ | ||
network_id: process.env.TENDERLY_FORK_NETWORK || "5", | ||
chain_config: { | ||
chain_id: Number.parseInt(process.env.TENDERLY_FORK_CHAINID || "55"), | ||
}, | ||
alias: "UI Fork", | ||
description: "", | ||
}); | ||
console.timeEnd("fork"); | ||
|
||
console.log("Created the fork", fork.id); | ||
replaceExistingForkwWith(fork); | ||
}; |
31 changes: 31 additions & 0 deletions
31
multisig-wallet/lib-tenderly/api/t-forks-clean-recreate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { readFileSync, writeFileSync } from "fs"; | ||
import { loadInfra, replaceExistingForkwWith } from "../tenderly-infra"; | ||
import { aTenderlyFork, removeFork } from "./tenderly-api"; | ||
|
||
(async () => { | ||
const forkUrl = | ||
process.env.FORK_MODE === "TEST" | ||
? process.env.TENDERLY_TEST_FORK_URL | ||
: process.env.TENDERLY_FORK_URL; | ||
|
||
if (!!forkUrl) { | ||
const forkId = forkUrl.split("/").reverse()[0]; | ||
console.log("Removing fork", forkId); | ||
await removeFork(forkId).catch((err) => { | ||
// console.error(err); | ||
}); | ||
} | ||
console.log("Creating a fork"); | ||
console.time("fork"); | ||
const fork = await aTenderlyFork({ | ||
network_id: process.env.TENDERLY_FORK_NETWORK || "5", | ||
chain_config: { | ||
chain_id: Number.parseInt(process.env.TENDERLY_FORK_CHAINID || "55"), | ||
}, | ||
alias: "UI Fork", | ||
}); | ||
console.timeEnd("fork"); | ||
|
||
console.log("Created the fork", fork.id); | ||
replaceExistingForkwWith(fork); | ||
})().catch(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { JsonRpcProvider } from "@ethersproject/providers"; | ||
import axios, { AxiosResponse } from "axios"; | ||
import * as dotenv from "dotenv"; | ||
|
||
dotenv.config(); | ||
|
||
type TenderlyForkRequest = { | ||
block_number?: number; | ||
network_id: string; | ||
transaction_index?: number; | ||
initial_balance?: number; | ||
alias?: string; | ||
description?: string; | ||
chain_config?: { | ||
chain_id?: number; | ||
homestead_block?: number; | ||
dao_fork_support?: boolean; | ||
eip_150_block?: number; | ||
eip_150_hash?: string; | ||
eip_155_block?: number; | ||
eip_158_block?: number; | ||
byzantium_block?: number; | ||
constantinople_block?: number; | ||
petersburg_block?: number; | ||
istanbul_block?: number; | ||
berlin_block?: number; | ||
}; | ||
}; | ||
|
||
export type TenderlyForkProvider = { | ||
provider: JsonRpcProvider; | ||
id: number; | ||
blockNumber: number; | ||
chainId: number; | ||
networkId: number; | ||
/** | ||
* map from address to given address' balance | ||
*/ | ||
removeFork: () => Promise<AxiosResponse<any, any>>; | ||
}; | ||
|
||
const somewhereInTenderly = ( | ||
where: string = process.env.TENDERLY_PROJECT_SLUG || "" | ||
) => | ||
axios.create({ | ||
baseURL: `https://api.tenderly.co/api/v1/${where}`, | ||
headers: { | ||
"X-Access-Key": process.env.TENDERLY_ACCESS_KEY || "", | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
|
||
export const inProject = (...path: any[]) => | ||
[ | ||
`account/${process.env.TENDERLY_USERNAME}/project/${process.env.TENDERLY_PROJECT_SLUG}`, | ||
...path, | ||
] | ||
.join("/") | ||
.replace("//", ""); | ||
|
||
export const anAxiosOnTenderly = () => somewhereInTenderly(""); | ||
const axiosOnTenderly = anAxiosOnTenderly(); | ||
|
||
// todo: cache these poor axioses | ||
const axiosInProject = somewhereInTenderly(inProject()); | ||
|
||
export const removeFork = async (forkId: string) => { | ||
console.log("Removing test fork", forkId); | ||
return await axiosOnTenderly.delete(inProject(`fork/${forkId}`)); | ||
}; | ||
|
||
export async function aTenderlyFork( | ||
fork: TenderlyForkRequest | ||
): Promise<TenderlyForkProvider> { | ||
const forkResponse = await axiosInProject.post(`/fork`, fork); | ||
const forkId = forkResponse.data.root_transaction.fork_id; | ||
|
||
const forkRpc = `https://rpc.tenderly.co/fork/${forkId}`; | ||
const forkProvider = new JsonRpcProvider(forkRpc); | ||
|
||
const blockNumberStr = ( | ||
forkResponse.data.root_transaction.receipt.blockNumber as string | ||
).replace("0x", ""); | ||
const blockNumber: number = Number.parseInt(blockNumberStr, 16); | ||
|
||
console.info( | ||
`\nForked with fork id ${forkId} at block number ${blockNumber}` | ||
); | ||
|
||
console.info(`https://dashboard.tenderly.co/${inProject("fork", forkId)}`); | ||
console.info("JSON-RPC:", forkRpc); | ||
|
||
return { | ||
provider: forkProvider, | ||
blockNumber, | ||
id: forkId, | ||
removeFork: () => removeFork(forkId), | ||
networkId: fork.network_id as any, | ||
chainId: forkResponse.data.simulation_fork.chain_config.chain_id, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Contract } from "ethers"; | ||
import { existsSync, readFileSync, writeFileSync } from "fs"; | ||
import { network } from "hardhat"; | ||
|
||
export type DeploymentRecord = { | ||
name: string; | ||
address: string; | ||
network: string; | ||
timestamp?: Date; | ||
}; | ||
|
||
function readDeployments() { | ||
type Deployments = Record<string, DeploymentRecord[]>; | ||
if (!existsSync(".tenderly/deployments.json")) { | ||
return {} as Deployments; | ||
} | ||
const deployments = JSON.parse( | ||
readFileSync(".tenderly/deployments.json", "utf8").toString() | ||
) as unknown as Deployments; | ||
return deployments; | ||
} | ||
|
||
export function deployed(deployment: DeploymentRecord, tag: string = "latest") { | ||
if (findDeployment(deployment.name, deployment.network, tag)) { | ||
return; | ||
} | ||
deployment.timestamp = new Date(); | ||
|
||
const deploymentsOn = findDeployment(deployment.name, tag); | ||
const deployments = readDeployments(); | ||
if (!deployments[tag]) { | ||
deployments[tag] = [deployment]; | ||
} else { | ||
const idx = deployments[tag].findIndex( | ||
(d) => d.network == deployment.network && d.name == deployment.name | ||
); | ||
deployments[tag][idx] = { ...deployments[tag][idx], ...deployment }; | ||
} | ||
|
||
writeFileSync( | ||
".tenderly/deployments.json", | ||
JSON.stringify(deployments, null, 2) | ||
); | ||
} | ||
|
||
export function findDeployment(name: string, network: string, tag = "latest") { | ||
const deployments = readDeployments()[tag]; | ||
if (!deployments) { | ||
return undefined; | ||
} | ||
return deployments.filter((d) => d.name === name && d.network == network)[0]; | ||
} |
Oops, something went wrong.