Skip to content

Commit

Permalink
feat: script changes for safe proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
arthcp committed Oct 25, 2024
1 parent 8160668 commit 0e8ee47
Show file tree
Hide file tree
Showing 9 changed files with 2,803 additions and 189 deletions.
10 changes: 5 additions & 5 deletions contracts/socket/SocketBatcher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,11 @@ contract SocketBatcher is AccessControl {
IExecutionManager.setRelativeNativeTokenPrice.selector
) {
IExecutionManager(contractAddress_).setRelativeNativeTokenPrice(
setFeesRequests_[index].nonce,
setFeesRequests_[index].dstChainSlug,
setFeesRequests_[index].fees,
setFeesRequests_[index].signature
);
setFeesRequests_[index].nonce,
setFeesRequests_[index].dstChainSlug,
setFeesRequests_[index].fees,
setFeesRequests_[index].signature
);
} else if (
setFeesRequests_[index].functionSelector ==
IExecutionManager.setMsgValueMaxThreshold.selector
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@nomiclabs/hardhat-ethers": "^2.1.1",
"@nomiclabs/hardhat-etherscan": "^3.1.0",
"@socket.tech/dl-core": "2.17.0-test.3",
"@socket.tech/dl-common": "1.0.4-test.11",
"@socket.tech/dl-common": "1.0.12-test.1",
"@typechain/ethers-v5": "^10.0.0",
"@typechain/hardhat": "^6.0.0",
"@types/node": "^18.11.9",
Expand Down
4 changes: 2 additions & 2 deletions scripts/admin/rescueFunds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ const createContractAddrArray = (
): string[] => {
let addresses: string[] = [];

if (chainAddresses.ExecutionManager)
addresses.push(chainAddresses.ExecutionManager);
if (chainAddresses.ExecutionManagerDF)
addresses.push(chainAddresses.ExecutionManagerDF);
if (chainAddresses.OpenExecutionManager)
addresses.push(chainAddresses.OpenExecutionManager);

Expand Down
6 changes: 4 additions & 2 deletions scripts/admin/rotate-owner/1-nominate-multisig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ export const main = async () => {
filteredChainSlugs.map(async (chainSlug) => {
let chainAddresses: ChainSocketAddresses = addresses[chainSlug];

let newOwner = chainAddresses["SafeL2"];
let newOwner = chainAddresses["SocketSafeProxy"];
if (!newOwner) {
console.log(`❗ ${chainSlug}: SafeL2 address not found`);
console.log(`❗ ${chainSlug}: SocketSafeProxy address not found`);
return;
}

Expand All @@ -95,6 +95,8 @@ export const main = async () => {
"integrations",
"Counter",
"SafeL2",
"SocketSafeProxy",
"SafeProxyFactory",
"MultiSigWrapper",
].includes(key)
);
Expand Down
5 changes: 4 additions & 1 deletion scripts/admin/rotate-owner/2-claim-with-multisig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const main = async () => {
await Promise.all(
filteredChainSlugs.map(async (chainSlug) => {
let chainAddresses: ChainSocketAddresses = addresses[chainSlug];
const signerAddress = chainAddresses["SafeL2"];
const signerAddress = chainAddresses["SocketSafeProxy"];
const signer = await getSocketSigner(
parseInt(chainSlug),
chainAddresses,
Expand All @@ -71,6 +71,8 @@ export const main = async () => {
"integrations",
"Counter",
"SafeL2",
"SocketSafeProxy",
"SafeProxyFactory",
"MultiSigWrapper",
].includes(key)
);
Expand Down Expand Up @@ -155,6 +157,7 @@ const checkAndClaim = async (

const owner = (await contract.owner()).toLowerCase();
const nominee = (await contract.nominee()).toLowerCase();
signerAddress = signerAddress.toLowerCase();

console.log(` - ${label}: Checking: ${owner}, ${nominee}`);

Expand Down
Empty file.
132 changes: 132 additions & 0 deletions scripts/admin/update-safe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import { config as dotenvConfig } from "dotenv";
import {
ChainSocketAddresses,
DeploymentAddresses,
getAllAddresses,
isMainnet,
isTestnet,
} from "../../src";
import { mode, overrides } from "../deploy/config/config";
import MultiSigWrapperArtifact from "../../out/MultiSigWrapper.sol/MultiSigWrapper.json";
import { Signer, ethers } from "ethers";
import { getSocketSigner } from "../deploy/utils/socket-signer";
import { MultiSigWrapper } from "../../typechain-types";

dotenvConfig();

/**
* Usage
*
* --sendtx Send claim tx along with ownership check.
* Default is only check owner, nominee.
* Eg. npx --sendtx ts-node scripts/admin/rotate-owner/claim.ts
*
* --chains Run only for specified chains.
* Default is all chains.
* Eg. npx --chains=10,2999 ts-node scripts/admin/rotate-owner/claim.ts
*
* --testnets Run for testnets.
* Default is false.
*/

const sendTx = process.env.npm_config_sendtx == "true";
const testnets = process.env.npm_config_testnets == "true";
const filterChainsParam = process.env.npm_config_chains
? process.env.npm_config_chains.split(",")
: null;

const addresses: DeploymentAddresses = getAllAddresses(mode);
let allChainSlugs: string[];
if (testnets)
allChainSlugs = Object.keys(addresses).filter((c) => isTestnet(parseInt(c)));
else
allChainSlugs = Object.keys(addresses).filter((c) => isMainnet(parseInt(c)));

const filteredChainSlugs = !filterChainsParam
? allChainSlugs
: allChainSlugs.filter((c) => filterChainsParam.includes(c));

const wrapperABI = MultiSigWrapperArtifact.abi;

export const main = async () => {
await Promise.all(
filteredChainSlugs.map(async (chainSlug) => {
let chainAddresses: ChainSocketAddresses = addresses[chainSlug];
const wrapperAddress = chainAddresses.MultiSigWrapper;
const safeAddress = chainAddresses.SocketSafeProxy;
const signer = await getSocketSigner(
parseInt(chainSlug),
chainAddresses,
false,
true
);
await checkAndUpdate(
wrapperAddress,
safeAddress,
signer,
chainSlug,
`${chainSlug} wrapper`
);
})
);
};

const checkAndUpdate = async (
wrapperAddress: string,
newSafeAddress: string,
signer: Signer,
chainSlug: string,
label: string
) => {
if (!wrapperAddress || !newSafeAddress) {
console.log(`❗ ${label}: Invalid wrapper or safe address`);
return;
}

const signerAddress = (await signer.getAddress()).toLowerCase();
const wrapper = new ethers.Contract(
wrapperAddress,
wrapperABI,
signer
) as MultiSigWrapper;
label = label.padEnd(45);

console.log(
` - ${label}: Checking: signer: ${signerAddress}, wrapper: ${wrapperAddress}`
);

const owner = (await wrapper.owner()).toLowerCase();
const safe = (await wrapper.safe()).toLowerCase();
if (safe === newSafeAddress) {
console.log(` ✔ ${label}: Safe already updated`);
return;
}

if (owner !== signerAddress) {
console.log(`❗ ${label}: Not owner`);
return;
}

if (sendTx) {
console.log(
`✨ ${label}: Updating safe, current safe: ${safe}, new safe: ${newSafeAddress}`
);
const tx = await wrapper.updateSafe(newSafeAddress, {
...(await overrides(parseInt(chainSlug))),
});

const receipt = await tx.wait();
console.log(`🚀 ${label}: Done: ${receipt.transactionHash}`);
} else {
console.log(
`✨ ${label}: Needs updating, current safe: ${safe}, new safe: ${newSafeAddress}`
);
}
};

main()
.then(() => process.exit(0))
.catch((error: Error) => {
console.error(error);
process.exit(1);
});
4 changes: 3 additions & 1 deletion src/socket-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ export interface ChainSocketAddresses {
SocketSimulator?: string;
SimulatorUtils?: string;
SwitchboardSimulator?: string;
Safe?: string;
MultiSigWrapper?: string;
SafeL2?: string;
SafeProxyFactory?: string;
SocketSafeProxy?: string;
}

export type DeploymentAddresses = {
Expand Down
Loading

0 comments on commit 0e8ee47

Please sign in to comment.