Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #143 from statechannels/scroll
Browse files Browse the repository at this point in the history
Scroll deploy
  • Loading branch information
lalexgap authored Oct 19, 2023
2 parents 127180d + 7467fc6 commit 989b4df
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 18 deletions.
7 changes: 3 additions & 4 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ VITE_BOB_CHAIN_URL=http://localhost:8546
VITE_IRENE_SK=0xfebb3b74b0b52d0976f6571d555f4ac8b91c308dfa25c7b58d1e6a7c3f50c781
VITE_IRENE_ADDRESS=0x111A00868581f73AB42FEEF67D235Ca09ca1E8db

# The string to convert to bytes32 and use as the salt for deployment
VITE_DEPLOY_SALT_STRING="State channels are cool!"
# If Alice and Bob are on seperate chains they could use seperate entrypoints
VITE_ALICE_ENTRYPOINT_ADDRESS=0x5FbDB2315678afecb367f032d93F642f64180aa3
VITE_BOB_ENTRYPOINT_ADDRESS=0x5FbDB2315678afecb367f032d93F642f64180aa3

# These are the expected adresses when deploying to a local hardhat node using the above salt
VITE_ENTRYPOINT_ADDRESS=0x5FbDB2315678afecb367f032d93F642f64180aa3
VITE_ALICE_SCW_ADDRESS=0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
VITE_BOB_SCW_ADDRESS=0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0

Expand Down
12 changes: 7 additions & 5 deletions clients/OwnerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { IAccount } from "./utils";
import { hashState } from "./State";

export class OwnerClient extends StateChannelWallet {
private nonce = 0;
constructor(params: StateChannelWalletParams) {
super(params);
if (this.myRole() !== Participant.Owner) {
Expand Down Expand Up @@ -182,10 +181,16 @@ export class OwnerClient extends StateChannelWallet {
amount,
"0x", // specifying no data makes sure the call is interpreted as a basic eth transfer
]);

// Fetch the latest nonce from the entrypointract
const nonce = await this.entrypointContract
.getFunction("getNonce")
.staticCall(this.scBridgeWalletAddress, 0);

const partialUserOp: Partial<UserOperationStruct> = {
sender: this.scBridgeWalletAddress,
callData,
nonce: this.nonce,
nonce,
// TODO: Clean up these defaults
callGasLimit: 40_000,
verificationGasLimit: 150000,
Expand All @@ -211,9 +216,6 @@ export class OwnerClient extends StateChannelWallet {
)} ETH to ${payee} (userOpHash: ${hash})`,
);

// Increment nonce for next transfer
this.nonce++;

return hash;
}
}
5 changes: 5 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ const config: HardhatUserConfig = {
url: "http://127.0.0.1:8546",
chainId: 31338,
},
scroll: {
url: "https://sepolia-rpc.scroll.io",
accounts:
process.env.DEPLOY_KEY !== undefined ? [process.env.DEPLOY_KEY] : [],
},
// Used for testing
hardhat: {
chainId:
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"chain:a": "yarn hardhat node",
"chain:b": "IS_DESTINATION=true yarn hardhat node --port 8546",
"deploy:b": "npx hardhat run --network b scripts/deploy.ts",
"deploy-and-start": "yarn deploy:a && yarn deploy:b && yarn start"
"deploy-and-start": "yarn deploy:a && yarn deploy:b && yarn start",
"deploy:scroll": "npx hardhat run --network scroll scripts/deploy.ts"
},
"packageManager": "[email protected]",
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const deployFunc = async function (): Promise<void> {

const entryPointDeployer = await ethers.getContractFactory("EntryPoint");
const entrypoint = await entryPointDeployer.deploy();
await entrypoint.waitForDeployment();

const walletDeployer = await ethers.getContractFactory("SCBridgeWallet");
console.log("EntryPoint deployed to:", await entrypoint.getAddress());

Expand Down
8 changes: 4 additions & 4 deletions src/Intermediary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ export const Coordinator: React.FunctionComponent = () => {
// @ts-expect-error
const myKey = import.meta.env.VITE_IRENE_SK;
// @ts-expect-error
const entrypointAddress = import.meta.env.VITE_ENTRYPOINT_ADDRESS;
// @ts-expect-error
const aliceScwAddress = import.meta.env.VITE_ALICE_SCW_ADDRESS;
// @ts-expect-error
const bobScwAddress = import.meta.env.VITE_BOB_SCW_ADDRESS;
Expand All @@ -42,7 +40,8 @@ export const Coordinator: React.FunctionComponent = () => {
intermediaryAddress: myAddress,
// @ts-expect-error
chainRpcUrl: import.meta.env.VITE_ALICE_CHAIN_URL,
entrypointAddress,
// @ts-expect-error
entrypointAddress: import.meta.env.VITE_ALICE_ENTRYPOINT_ADDRESS,
scwAddress: aliceScwAddress,
startingIntermediaryBalance,
}),
Expand All @@ -56,7 +55,8 @@ export const Coordinator: React.FunctionComponent = () => {
intermediaryAddress: myAddress,
// @ts-expect-error
chainRpcUrl: import.meta.env.VITE_BOB_CHAIN_URL,
entrypointAddress,
// @ts-expect-error
entrypointAddress: import.meta.env.VITE_BOB_ENTRYPOINT_ADDRESS,
scwAddress: bobScwAddress,
startingIntermediaryBalance,
}),
Expand Down
8 changes: 5 additions & 3 deletions src/Wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ import { chains, type ChainData } from "./chains";
let myAddress: string = "placholder";
let mySigningKey: string;
let myPeer: string; // If I'm Alice, this is Bob. If I'm Bob, this is Alice.
// @ts-expect-error
const entrypointAddress = import.meta.env.VITE_ENTRYPOINT_ADDRESS;
let entrypointAddress: string;
let myScwAddress: string;
let myPeerSCWAddress: string;
let myChainUrl: string;
Expand Down Expand Up @@ -69,6 +68,8 @@ const Wallet: React.FunctionComponent<{ role: Role }> = (props: {
// @ts-expect-error
(c) => c.url === import.meta.env.VITE_ALICE_CHAIN_URL,
)!;
// @ts-expect-error
entrypointAddress = import.meta.env.VITE_ALICE_ENTRYPOINT_ADDRESS;

break;
case "bob":
Expand All @@ -89,7 +90,8 @@ const Wallet: React.FunctionComponent<{ role: Role }> = (props: {
// @ts-expect-error
(c) => c.url === import.meta.env.VITE_BOB_CHAIN_URL,
)!;

// @ts-expect-error
entrypointAddress = import.meta.env.VITE_BOB_ENTRYPOINT_ADDRESS;
break;
}

Expand Down
8 changes: 8 additions & 0 deletions src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,12 @@ export const chains: ChainData[] = [
explorer: "",
exchangeRate: 2,
},
{
chainID: 534351n,
url: "https://sepolia-rpc.scroll.io",
name: "scroll",
symbol: "ETH",
explorer: "",
exchangeRate: 1,
},
];
3 changes: 2 additions & 1 deletion src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ interface ImportMetaEnv {
readonly VITE_IRENE_SK: string;
readonly VITE_IRENE_ADDRESS: string;
readonly VITE_DEPLOY_SALT_STRING: string;
readonly VITE_ENTRYPOINT_ADDRESS: string;
readonly VITE_ALICE_ENTRYPOINT_ADDRESS: string;
readonly VITE_BOB_ENTRYPOINT_ADDRESS: string;
readonly VITE_ALICE_SCW_ADDRESS: string;
readonly VITE_BOB_SCW_ADDRESS: string;
readonly VITE_ALICE_CHAIN_URL: string;
Expand Down

0 comments on commit 989b4df

Please sign in to comment.