-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into entrykit
- Loading branch information
Showing
49 changed files
with
1,080 additions
and
503 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@latticexyz/entrykit": patch | ||
--- | ||
|
||
Initial, experimental release of EntryKit. |
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,9 @@ | ||
--- | ||
"@latticexyz/cli": patch | ||
--- | ||
|
||
In addition to a hex `--salt`, deploy commands now accept a string salt for world deployment, which will get converted to a hex. | ||
|
||
``` | ||
pnpm mud deploy --salt hello | ||
``` |
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 @@ | ||
#!/usr/bin/env node | ||
// workaround for https://github.com/pnpm/pnpm/issues/1801 | ||
import "../dist/tsup/bin/deploy-local-prereqs.js"; |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,135 @@ | ||
import "dotenv/config"; | ||
import { | ||
Hex, | ||
concatHex, | ||
createWalletClient, | ||
http, | ||
isHex, | ||
parseAbiParameters, | ||
encodeAbiParameters, | ||
size, | ||
parseEther, | ||
} from "viem"; | ||
import { privateKeyToAccount } from "viem/accounts"; | ||
import { getRpcUrl } from "@latticexyz/common/foundry"; | ||
import { | ||
ensureContractsDeployed, | ||
ensureDeployer, | ||
getContractAddress, | ||
waitForTransactions, | ||
} from "@latticexyz/common/internal"; | ||
import entryPointArtifact from "@account-abstraction/contracts/artifacts/EntryPoint.json" assert { type: "json" }; | ||
import simpleAccountFactoryArtifact from "@account-abstraction/contracts/artifacts/SimpleAccountFactory.json" assert { type: "json" }; | ||
import paymasterArtifact from "@latticexyz/paymaster/out/GenerousPaymaster.sol/GenerousPaymaster.json" assert { type: "json" }; | ||
import { getChainId } from "viem/actions"; | ||
import { writeContract } from "@latticexyz/common"; | ||
|
||
// TODO: parse env with arktype (to avoid zod dep) and throw when absent | ||
|
||
const privateKey = process.env.PRIVATE_KEY; | ||
if (!isHex(privateKey)) { | ||
// TODO: detect anvil and automatically put this env var where it needs to go? | ||
throw new Error( | ||
`Missing \`PRIVATE_KEY\` environment variable. If you're using Anvil, run | ||
echo "PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" > .env | ||
to use a prefunded Anvil account.`, | ||
); | ||
} | ||
const account = privateKeyToAccount(privateKey); | ||
|
||
// TODO: rpc url flag/env var? | ||
// TODO: foundry profile flag/env var? | ||
const rpc = await getRpcUrl(); | ||
|
||
const client = createWalletClient({ | ||
transport: http(rpc), | ||
account, | ||
}); | ||
|
||
const chainId = await getChainId(client); | ||
|
||
// TODO: deployer address flag/env var? | ||
const deployerAddress = await ensureDeployer(client); | ||
|
||
// https://github.com/eth-infinitism/account-abstraction/blob/b3bae63bd9bc0ed394dfca8668008213127adb62/hardhat.config.ts#L11 | ||
const entryPointSalt = "0x90d8084deab30c2a37c45e8d47f49f2f7965183cb6990a98943ef94940681de3"; | ||
const entryPointAddress = getContractAddress({ | ||
deployerAddress, | ||
bytecode: entryPointArtifact.bytecode as Hex, | ||
salt: entryPointSalt, | ||
}); | ||
// TODO: assert that this matches Viem's entryPoint07Address | ||
|
||
// Deploy entrypoint first, because following deploys need to be able to call it. | ||
await ensureContractsDeployed({ | ||
client, | ||
deployerAddress, | ||
contracts: [ | ||
{ | ||
bytecode: entryPointArtifact.bytecode as Hex, | ||
salt: entryPointSalt, | ||
deployedBytecodeSize: size(entryPointArtifact.deployedBytecode as Hex), | ||
debugLabel: "EntryPoint v0.7", | ||
}, | ||
], | ||
}); | ||
|
||
const paymasterBytecode = concatHex([ | ||
paymasterArtifact.bytecode.object as Hex, | ||
encodeAbiParameters(parseAbiParameters("address"), [entryPointAddress]), | ||
]); | ||
const paymasterAddress = getContractAddress({ deployerAddress, bytecode: paymasterBytecode }); | ||
|
||
await ensureContractsDeployed({ | ||
client, | ||
deployerAddress, | ||
contracts: [ | ||
{ | ||
bytecode: concatHex([ | ||
simpleAccountFactoryArtifact.bytecode as Hex, | ||
encodeAbiParameters(parseAbiParameters("address"), [entryPointAddress]), | ||
]), | ||
deployedBytecodeSize: size(simpleAccountFactoryArtifact.deployedBytecode as Hex), | ||
debugLabel: "SimpleAccountFactory", | ||
}, | ||
{ | ||
bytecode: paymasterBytecode, | ||
deployedBytecodeSize: size(paymasterArtifact.deployedBytecode.object as Hex), | ||
debugLabel: "GenerousPaymaster", | ||
}, | ||
], | ||
}); | ||
|
||
console.log("\nContracts deployed!\n"); | ||
|
||
if (chainId === 31337) { | ||
const tx = await writeContract(client, { | ||
chain: null, | ||
address: entryPointAddress, | ||
abi: [ | ||
{ | ||
inputs: [{ name: "account", type: "address" }], | ||
name: "depositTo", | ||
outputs: [], | ||
stateMutability: "payable", | ||
type: "function", | ||
}, | ||
], | ||
functionName: "depositTo", | ||
args: [paymasterAddress], | ||
value: parseEther("100"), | ||
}); | ||
await waitForTransactions({ client, hashes: [tx] }); | ||
console.log("\nFunded paymaster at:", paymasterAddress, "\n"); | ||
} else { | ||
console.log(` | ||
Be sure to fund the paymaster by making a deposit in the entrypoint contract. For example: | ||
cast send ${entryPointAddress} "depositTo(address)" ${paymasterAddress} --value 1ether | ||
`); | ||
} | ||
|
||
console.log("\nEntryKit prerequisites complete!\n"); | ||
process.exit(0); |
Oops, something went wrong.