-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: script to configure new chain from socket admin
- Loading branch information
1 parent
8bc379f
commit ebdf913
Showing
1 changed file
with
163 additions
and
0 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,163 @@ | ||
import { Wallet } from "ethers"; | ||
import fs from "fs"; | ||
|
||
import { | ||
CORE_CONTRACTS, | ||
ChainSlug, | ||
DeploymentAddresses, | ||
IntegrationTypes, | ||
ROLES, | ||
} from "../../src"; | ||
import { checkAndUpdateRoles } from "../deploy/checkRoles"; | ||
import { | ||
chains, | ||
executionManagerVersion, | ||
executorAddresses, | ||
filterSiblingChains, | ||
mode, | ||
newRoleStatus, | ||
sendTransaction, | ||
socketOwner, | ||
transmitterAddresses, | ||
watcherAddresses, | ||
} from "../deploy/config"; | ||
import { | ||
configureExecutionManager, | ||
registerSwitchboards, | ||
} from "../deploy/configure"; | ||
import { getProviderFromChainSlug } from "../constants"; | ||
import { deployedAddressPath, storeAllAddresses } from "../deploy/utils"; | ||
|
||
export const main = async () => { | ||
const addresses: DeploymentAddresses = JSON.parse( | ||
fs.readFileSync(deployedAddressPath(mode), "utf-8") | ||
); | ||
|
||
let addr; | ||
for (let c = 0; c < chains.length; c++) { | ||
const providerInstance = getProviderFromChainSlug(c as any as ChainSlug); | ||
const socketSigner: Wallet = new Wallet( | ||
process.env.SOCKET_SIGNER_KEY as string, | ||
providerInstance | ||
); | ||
|
||
// grant all roles for new chain | ||
await grantRoles(); | ||
|
||
// general configs for socket | ||
await configureExecutionManager( | ||
executionManagerVersion, | ||
addresses[c].ExecutionManager!, | ||
addresses[c].SocketBatcher, | ||
c, | ||
filterSiblingChains, | ||
socketSigner | ||
); | ||
|
||
addr = await registerSwitchboards( | ||
c, | ||
filterSiblingChains, | ||
CORE_CONTRACTS.FastSwitchboard2, | ||
IntegrationTypes.fast2, | ||
addresses[c], | ||
addresses, | ||
socketSigner | ||
); | ||
} | ||
await storeAllAddresses(addresses, mode); | ||
}; | ||
|
||
const grantRoles = async () => { | ||
// Grant rescue,withdraw and governance role for Execution Manager to owner | ||
await checkAndUpdateRoles({ | ||
userSpecificRoles: [ | ||
{ | ||
userAddress: socketOwner, | ||
filterRoles: [ROLES.FEES_UPDATER_ROLE], | ||
}, | ||
{ | ||
userAddress: transmitterAddresses[mode], | ||
filterRoles: [ROLES.FEES_UPDATER_ROLE], | ||
}, | ||
{ | ||
userAddress: executorAddresses[mode], | ||
filterRoles: [ROLES.EXECUTOR_ROLE], | ||
}, | ||
], | ||
contractName: executionManagerVersion, | ||
filterChains: chains, | ||
filterSiblingChains, | ||
sendTransaction, | ||
newRoleStatus, | ||
}); | ||
|
||
// Grant owner roles for TransmitManager | ||
await checkAndUpdateRoles({ | ||
userSpecificRoles: [ | ||
{ | ||
userAddress: socketOwner, | ||
filterRoles: [ROLES.FEES_UPDATER_ROLE], | ||
}, | ||
{ | ||
userAddress: transmitterAddresses[mode], | ||
filterRoles: [ROLES.TRANSMITTER_ROLE], | ||
}, | ||
{ | ||
userAddress: transmitterAddresses[mode], | ||
filterRoles: [ROLES.FEES_UPDATER_ROLE], | ||
}, | ||
], | ||
contractName: CORE_CONTRACTS.TransmitManager, | ||
filterChains: chains, | ||
filterSiblingChains, | ||
sendTransaction, | ||
newRoleStatus, | ||
}); | ||
|
||
// Setup Fast Switchboard2 roles | ||
await checkAndUpdateRoles({ | ||
userSpecificRoles: [ | ||
{ | ||
userAddress: socketOwner, | ||
filterRoles: [ROLES.FEES_UPDATER_ROLE], | ||
}, | ||
{ | ||
userAddress: transmitterAddresses[mode], | ||
filterRoles: [ROLES.FEES_UPDATER_ROLE], | ||
}, | ||
{ | ||
userAddress: watcherAddresses[mode], | ||
filterRoles: [ROLES.WATCHER_ROLE], | ||
}, | ||
], | ||
|
||
contractName: CORE_CONTRACTS.FastSwitchboard2, | ||
filterChains: chains, | ||
filterSiblingChains, | ||
sendTransaction, | ||
newRoleStatus, | ||
}); | ||
|
||
// Grant watcher role to watcher for OptimisticSwitchboard | ||
await checkAndUpdateRoles({ | ||
userSpecificRoles: [ | ||
{ | ||
userAddress: socketOwner, | ||
filterRoles: [ROLES.FEES_UPDATER_ROLE], | ||
}, | ||
{ | ||
userAddress: transmitterAddresses[mode], | ||
filterRoles: [ROLES.FEES_UPDATER_ROLE], // all roles | ||
}, | ||
{ | ||
userAddress: watcherAddresses[mode], | ||
filterRoles: [ROLES.WATCHER_ROLE], | ||
}, | ||
], | ||
contractName: CORE_CONTRACTS.OptimisticSwitchboard, | ||
filterChains: chains, | ||
filterSiblingChains, | ||
sendTransaction, | ||
newRoleStatus, | ||
}); | ||
}; |