Skip to content

Commit

Permalink
create l2 admin commands
Browse files Browse the repository at this point in the history
  • Loading branch information
augustbleeds committed Jan 8, 2025
1 parent fe0c38b commit 6596131
Show file tree
Hide file tree
Showing 19 changed files with 269 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"files.insertFinalNewline": true
"files.insertFinalNewline": true,
"typescript.tsdk": "node_modules/typescript/lib"
}
21 changes: 21 additions & 0 deletions packages-ts/starknet-gauntlet-bridge/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2022 SmartContract ChainLink, Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
17 changes: 17 additions & 0 deletions packages-ts/starknet-gauntlet-bridge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Gauntlet Starknet Commands for LINK Token

## Bridge

All register/remove admin commands follow the same format

```bash
yarn gauntlet bridge:<REGISTER_OR_REMOVE_COMMAND> --account=<ADMIN_TO_REGISTER_OR_REMOVE> <CONTRACT>
```

Example:
```bash
yarn gauntlet bridge:register_governance_admin --account=<ADMIN_TO_REGISTER> <L2_BRIDGE_CONTRACT>
```



31 changes: 31 additions & 0 deletions packages-ts/starknet-gauntlet-bridge/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@chainlink/starknet-gauntlet-bridge",
"version": "0.0.1",
"description": "Gauntlet Starknet Starkgate Bridge",
"keywords": [
"typescript",
"cli"
],
"main": "./dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist/**/*",
"!dist/**/*.test.js"
],
"scripts": {
"gauntlet": "ts-node ./src/index.ts",
"lint": "tsc",
"format": "yarn prettier --write ./src",
"format:check": "yarn prettier --check ./src",
"clean": "rm -rf ./dist/ ./bin/",
"build": "yarn clean && tsc -b",
"bundle": "yarn build && pkg ."
},
"dependencies": {
"@chainlink/evm-gauntlet": "^0.4.0",
"@chainlink/gauntlet-core": "0.3.1",
"@chainlink/starknet-gauntlet": "*",
"@chainlink/starknet-gauntlet-oz": "*",
"ethers": "^5.6.9"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import RegisterGovernanceAdmin from './registerGovernanceAdmin'
import RemoveGovernanceAdmin from './removeGovernanceAdmin'
import RemoveSecurityAdmin from './removeSecurityAdmin'
import RemoveUpgradeGovernor from './removeUpgradeGovernor'

export default [RegisterGovernanceAdmin, RemoveGovernanceAdmin, RemoveSecurityAdmin, RemoveUpgradeGovernor]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {
makeExecuteCommand,
} from '@chainlink/starknet-gauntlet'
import { createRegisterAdminCommandConfig } from '../../lib/createAdminCommand'

const commandConfig = createRegisterAdminCommandConfig('register_governance_admin')

export default makeExecuteCommand(commandConfig)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {
makeExecuteCommand,
} from '@chainlink/starknet-gauntlet'
import { createRemoveAdminCommandConfig } from '../../lib/createAdminCommand'

const commandConfig = createRemoveAdminCommandConfig('remove_governance_admin')

export default makeExecuteCommand(commandConfig)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {
makeExecuteCommand,
} from '@chainlink/starknet-gauntlet'
import { createRemoveAdminCommandConfig } from '../../lib/createAdminCommand'

const commandConfig = createRemoveAdminCommandConfig('remove_security_admin')

export default makeExecuteCommand(commandConfig)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {
makeExecuteCommand,
} from '@chainlink/starknet-gauntlet'
import { createRemoveAdminCommandConfig } from '../../lib/createAdminCommand'

const commandConfig = createRemoveAdminCommandConfig('remove_upgrade_governor')

export default makeExecuteCommand(commandConfig)
3 changes: 3 additions & 0 deletions packages-ts/starknet-gauntlet-bridge/src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Bridge from './bridge'

export const L2Commands = [...Bridge]
3 changes: 3 additions & 0 deletions packages-ts/starknet-gauntlet-bridge/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { L2Commands } from './commands'

export { L2Commands }
5 changes: 5 additions & 0 deletions packages-ts/starknet-gauntlet-bridge/src/lib/categories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { CONTRACT_LIST } from './contracts'

export const CATEGORIES = {
BRIDGE: CONTRACT_LIST.BRIDGE,
}
11 changes: 11 additions & 0 deletions packages-ts/starknet-gauntlet-bridge/src/lib/contracts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { loadContractByPath } from '@chainlink/starknet-gauntlet'

export enum CONTRACT_LIST {
BRIDGE = 'bridge',
}

export const bridgeContractLoader = () =>
loadContractByPath(
`${__dirname}/../../artifacts/bridge/TokenBridge.contract_class.json`,
`${__dirname}/../../artifacts/bridge/TokenBridge.compiled_contract_class.json`,
)
94 changes: 94 additions & 0 deletions packages-ts/starknet-gauntlet-bridge/src/lib/createAdminCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import {
BeforeExecute,
isValidAddress,
} from '@chainlink/starknet-gauntlet'
import { uint256 } from 'starknet'
import { CATEGORIES } from './categories'
import { bridgeContractLoader, CONTRACT_LIST } from './contracts'

type UserInput = {
account: string
}

type ContractInput = [account: string]

const makeUserInput = async (flags, args): Promise<UserInput> => {
if (flags.input) return flags.input as UserInput

return {
account: flags.account,
}
}

const validateAccount = async (input) => {
if (!isValidAddress(input.account)) throw new Error(`Invalid account address: ${input.account}`)
return true
}

const makeContractInput = async (input: UserInput): Promise<ContractInput> => {
return [input.account]
}

const beforeAdminRemoveExecute: BeforeExecute<UserInput, ContractInput> = (
context,
input,
deps,
) => async () => {

deps.logger.info(
`About to remove admin ${input.user.account} for l2 bridge ${context.contractAddress}`,
)
}

const beforeAdminRegisterExecute: BeforeExecute<UserInput, ContractInput> = (
context,
input,
deps,
) => async () => {

deps.logger.info(
`About to register admin ${input.user.account} for l2 bridge ${context.contractAddress}`,
)
}

export const createRegisterAdminCommandConfig = (action: string) => {
return {
contractId: CONTRACT_LIST.BRIDGE,
category: CATEGORIES.BRIDGE,
action,
ux: {
description: 'Registers admin',
examples: [
`${CATEGORIES.BRIDGE}:${action} --network=<NETWORK> --account=<ADMIN> <CONTRACT_ADDRESS>`,
],
},
makeUserInput,
makeContractInput,
validations: [validateAccount],
loadContract: bridgeContractLoader,
hooks: {
beforeExecute: beforeAdminRegisterExecute,
},
}
}

export const createRemoveAdminCommandConfig = (action: string) => {
return {
contractId: CONTRACT_LIST.BRIDGE,
category: CATEGORIES.BRIDGE,
action,
ux: {
description: 'Removes admin',
examples: [
`${CATEGORIES.BRIDGE}:${action} --network=<NETWORK> --account=<ADMIN> <CONTRACT_ADDRESS>`,
],
},
makeUserInput,
makeContractInput,
validations: [validateAccount],
loadContract: bridgeContractLoader,
hooks: {
beforeExecute: beforeAdminRemoveExecute,
},
}
}
9 changes: 9 additions & 0 deletions packages-ts/starknet-gauntlet-bridge/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
},
"include": ["src/**/*"],
"exclude": ["dist", "**/*.spec.ts", "**/*.test.ts"]
}
3 changes: 2 additions & 1 deletion packages-ts/starknet-gauntlet-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@chainlink/starknet-gauntlet-token": "*",
"@chainlink/starknet-gauntlet-multisig": "*",
"@chainlink/starknet-gauntlet-emergency-protocol": "*",
"@chainlink/starknet-gauntlet-ledger": "*"
"@chainlink/starknet-gauntlet-ledger": "*",
"@chainlink/starknet-gauntlet-bridge": "*"
}
}
40 changes: 22 additions & 18 deletions packages-ts/starknet-gauntlet-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import {
inspectionCommands as MultisigInspectionCommands,
wrapCommand as multisigWrapCommand,
} from '@chainlink/starknet-gauntlet-multisig'
import {
L2Commands as BridgeCommands
} from '@chainlink/starknet-gauntlet-bridge'

import { executeCLI } from '@chainlink/gauntlet-core'
import { existsSync } from 'fs'
Expand All @@ -45,7 +48,7 @@ import {
} from '@chainlink/evm-gauntlet'
import { makeWallet as makeLedgerWallet } from '@chainlink/starknet-gauntlet-ledger'

export const noopPrompt: typeof prompt = async () => {}
export const noopPrompt: typeof prompt = async () => { }

const registerExecuteCommand = <UI, CI>(
registerCommand: (deps: Dependencies) => CommandCtor<ExecuteCommandInstance<UI, CI>>,
Expand Down Expand Up @@ -129,6 +132,7 @@ const L2ExecuteCommands = [
...ArgentCommands,
...MultisigExecuteCommands,
...L2EmergencyProtocolCommands,
...BridgeCommands,
]

const msigCommands = L2ExecuteCommands.map((c) => registerExecuteCommand(c, true)).map(
Expand All @@ -155,21 +159,21 @@ const commands = {
makeCommand: () => undefined,
},
}
;(async () => {
try {
const networkPossiblePaths = [
path.join(process.cwd(), 'networks'),
path.join(__dirname, '../networks'),
]
const networkPath = networkPossiblePaths.filter((networkPath) => existsSync(networkPath))[0]
const result = await executeCLI(commands, networkPath)
if (result) {
io.saveJSON(result, process.env['REPORT_NAME'] ? process.env['REPORT_NAME'] : 'report')
; (async () => {
try {
const networkPossiblePaths = [
path.join(process.cwd(), 'networks'),
path.join(__dirname, '../networks'),
]
const networkPath = networkPossiblePaths.filter((networkPath) => existsSync(networkPath))[0]
const result = await executeCLI(commands, networkPath)
if (result) {
io.saveJSON(result, process.env['REPORT_NAME'] ? process.env['REPORT_NAME'] : 'report')
}
process.exit(0)
} catch (e) {
console.log(e)
console.log('Starknet Command execution error', e.message)
process.exitCode = 1
}
process.exit(0)
} catch (e) {
console.log(e)
console.log('Starknet Command execution error', e.message)
process.exitCode = 1
}
})()
})()
7 changes: 7 additions & 0 deletions packages-ts/starknet-gauntlet/src/contract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ export const loadContract = (name: string): LoadContractResult => {
),
}
}

export const loadContractByPath = (contractPath: string, casmPath: string): LoadContractResult => {
return {
contract: json.parse(fs.readFileSync(contractPath, 'utf-8')),
casm: json.parse(fs.readFileSync(casmPath, 'utf-8')),
}
}
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
"path": "./packages-ts/starknet-gauntlet-ledger"
},
{
"path": "./packages-ts/starknet-gauntlet-cli"
"path": "./packages-ts/starknet-gauntlet-bridge"
},
{
"path": "./packages-ts/starknet-gauntlet-cli"
}
]
}

0 comments on commit 6596131

Please sign in to comment.