Skip to content

Commit

Permalink
Merge pull request #50 from OriumNetwork/feature--ON-847
Browse files Browse the repository at this point in the history
ON-847: defender scripts
  • Loading branch information
karacurt authored May 10, 2024
2 parents cbdc763 + 0730803 commit d01a77f
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import config from '../../addresses'
import { createDefenderProposal } from '../../utils/defender-proposal'
import { print, colors } from '../../utils/misc'

const CONTRACT_NAME = 'OriumMarketplaceRoyalties'
const FUNCTION_NAME = 'transferOwnership'
const FUNCTION_INPUTS_TYPE = [{ type: 'address', name: '_newOwner' }]
const FUNCTION_INPUTS = [config.polygon.KMSDeployer.address]

async function main() {
await createDefenderProposal(CONTRACT_NAME, FUNCTION_NAME, FUNCTION_INPUTS_TYPE, FUNCTION_INPUTS)
}

main()
.then(() => {
print(colors.bigSuccess, 'All done!')
})
.catch(error => {
console.error(error)
process.exitCode = 1
})
54 changes: 54 additions & 0 deletions utils/defender-proposal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { network as hardhatNetwork } from 'hardhat'
import config, { Network } from '../addresses'
import { print, colors, confirmOrDie } from '../utils/misc'
import { AdminClient } from 'defender-admin-client'

const NETWORK: Network = hardhatNetwork.name as Network
const DEFENDER_API_KEY = process.env.DEFENDER_TEAM_API_KEY
const DEFENDER_API_SECRET = process.env.DEFENDER_TEAM_API_SECRET_KEY

/**
* @notice Create Defender Proposal
* @dev This function creates a Defender Proposal
* @param CONTRACT_NAME The contract name from the config file
* @param FUNCTION_NAME The function name to be called
* @param FUNCTION_INPUTS_TYPE The function inputs type
* @param FUNCTION_INPUTS The function inputs
*/
export async function createDefenderProposal(
CONTRACT_NAME: keyof (typeof config)[Network],
FUNCTION_NAME: string,
FUNCTION_INPUTS_TYPE: { type: string; name: string }[],
FUNCTION_INPUTS: any[],
) {
console.log(FUNCTION_INPUTS_TYPE)
console.log(FUNCTION_INPUTS)
await confirmOrDie(`Are you sure you want to create Defender Proposal to ${FUNCTION_NAME} on ${NETWORK} network?`)

print(colors.highlight, `Create Defender Upgrade Proposal...`)
if (!DEFENDER_API_KEY || !DEFENDER_API_SECRET) return print(colors.error, 'Missing Defender API Key or Secret')
const adminClient = new AdminClient({
apiKey: DEFENDER_API_KEY,
apiSecret: DEFENDER_API_SECRET,
})

const customNetwork = NETWORK === 'polygon' ? 'matic' : NETWORK
if (customNetwork === 'cronosTestnet' || customNetwork === 'cronos')
return print(colors.error, 'Cronos not supported')

const proposal = await adminClient.createProposal({
contract: { address: config[NETWORK][CONTRACT_NAME].address, network: customNetwork },
title: `Proposal to ${FUNCTION_NAME} on ${CONTRACT_NAME}`,
description: '',
type: 'custom',
functionInterface: {
name: FUNCTION_NAME,
inputs: FUNCTION_INPUTS_TYPE,
},
functionInputs: FUNCTION_INPUTS,
via: config[NETWORK].Multisig.address,
viaType: 'Gnosis Safe',
})

print(colors.bigSuccess, `Upgrade proposal created at: ${proposal.url}`)
}

0 comments on commit d01a77f

Please sign in to comment.