-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(cli): move deploy utils to common (#3421)
- Loading branch information
Showing
25 changed files
with
101 additions
and
77 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
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 |
---|---|---|
@@ -1,30 +1,35 @@ | ||
import { DeterministicContract, LibraryPlaceholder, salt } from "./common"; | ||
import { DeterministicContract, LibraryPlaceholder } from "./common"; | ||
import { spliceHex } from "@latticexyz/common"; | ||
import { Hex, getCreate2Address, Address } from "viem"; | ||
import { Hex, Address } from "viem"; | ||
import { LibraryMap } from "./getLibraryMap"; | ||
import { getContractAddress } from "@latticexyz/common/internal"; | ||
|
||
export function createPrepareDeploy( | ||
bytecodeWithPlaceholders: Hex, | ||
placeholders: readonly LibraryPlaceholder[], | ||
): DeterministicContract["prepareDeploy"] { | ||
return function prepareDeploy(deployer: Address, libraryMap?: LibraryMap) { | ||
return function prepareDeploy(deployerAddress: Address, libraryMap?: LibraryMap) { | ||
let bytecode = bytecodeWithPlaceholders; | ||
|
||
if (placeholders.length === 0) { | ||
return { bytecode, address: getCreate2Address({ from: deployer, bytecode, salt }) }; | ||
return { bytecode, address: getContractAddress({ deployerAddress, bytecode }) }; | ||
} | ||
|
||
if (!libraryMap) { | ||
throw new Error("Libraries must be provided if there are placeholders"); | ||
} | ||
|
||
for (const placeholder of placeholders) { | ||
const address = libraryMap.getAddress({ name: placeholder.name, path: placeholder.path, deployer }); | ||
const address = libraryMap.getAddress({ | ||
name: placeholder.name, | ||
path: placeholder.path, | ||
deployer: deployerAddress, | ||
}); | ||
bytecode = spliceHex(bytecode, placeholder.start, placeholder.length, address); | ||
} | ||
return { | ||
bytecode, | ||
address: getCreate2Address({ from: deployer, bytecode, salt }), | ||
address: getContractAddress({ deployerAddress, bytecode }), | ||
}; | ||
}; | ||
} |
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
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
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
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,7 @@ | ||
import { stringToHex } from "viem"; | ||
|
||
// salt for deterministic deploys of singleton contracts | ||
export const singletonSalt = stringToHex("", { size: 32 }); | ||
|
||
// https://eips.ethereum.org/EIPS/eip-170 | ||
export const contractSizeLimit = parseInt("6000", 16); |
File renamed without changes.
File renamed without changes.
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,10 @@ | ||
import { debug as parentDebug } from "../debug"; | ||
|
||
export const debug = parentDebug.extend("deploy"); | ||
export const error = parentDebug.extend("deploy"); | ||
|
||
// Pipe debug output to stdout instead of stderr | ||
debug.log = console.debug.bind(console); | ||
|
||
// Pipe error output to stderr | ||
error.log = console.error.bind(console); |
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
4 changes: 2 additions & 2 deletions
4
...cli/src/deploy/ensureContractsDeployed.ts → ...mon/src/deploy/ensureContractsDeployed.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
File renamed without changes.
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,12 @@ | ||
import { Hex, getCreate2Address } from "viem"; | ||
import { singletonSalt } from "./common"; | ||
|
||
export function getContractAddress({ | ||
deployerAddress, | ||
bytecode, | ||
}: { | ||
readonly deployerAddress: Hex; | ||
readonly bytecode: Hex; | ||
}): Hex { | ||
return getCreate2Address({ from: deployerAddress, bytecode, salt: singletonSalt }); | ||
} |
Oops, something went wrong.