Skip to content

Commit

Permalink
New scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lima committed Apr 30, 2024
1 parent 1f4c768 commit 7f3ab81
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 15 deletions.
21 changes: 21 additions & 0 deletions scripts/orium-marketplace-royalties/08-set-trusted-tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { print, colors } from '../../utils/misc'
import { callContractFunction } from '../../utils/write-contract'

const TOKEN_ADDRESSES = ['0x8fbe243d898e7c88a6724bb9eb13d746614d23d6'] // GLMRApes address moonbeam
const FEE_TOKEN_ADDRESSES = ['0xd10078fdbc835726c79533a4a19db40cfad69d7f'] // GLMB address moonbeam
const IS_TRUSTED = [true]
const CONTRACT_NAME = 'OriumMarketplaceRoyalties'
const CONTRACT_FUNCTION = 'setTrustedFeeTokenForToken'
const CONTRACT_ARGUMENTS = [TOKEN_ADDRESSES, FEE_TOKEN_ADDRESSES, IS_TRUSTED]
async function main() {
await callContractFunction(CONTRACT_NAME, CONTRACT_FUNCTION, CONTRACT_ARGUMENTS)
}

main()
.then(() => {
print(colors.bigSuccess, 'All done!')
})
.catch(error => {
console.error(error)
process.exitCode = 1
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ZeroAddress } from 'ethers'
import { print, colors } from '../../utils/misc'
import { callContractFunction } from '../../utils/write-contract'

const CONTRACT_NAME = 'OriumMarketplaceRoyalties'
const CONTRACT_FUNCTION = 'setDefaultNftRolesRegistry'
const CONTRACT_ARGUMENTS = [ZeroAddress]
async function main() {
await callContractFunction(CONTRACT_NAME, CONTRACT_FUNCTION, CONTRACT_ARGUMENTS)
}

main()
.then(() => {
print(colors.bigSuccess, 'All done!')
})
.catch(error => {
console.error(error)
process.exitCode = 1
})
30 changes: 15 additions & 15 deletions utils/deploy-upgradeable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import hre, { ethers, network, upgrades } from 'hardhat'
import { print, confirmOrDie, colors } from './misc'
import { Network } from '../addresses'
import { updateJsonFile } from './json'
import { AwsKmsSigner } from './ethers-aws-kms-signer'
import { kmsDeployer, kmsProvider } from './deployer'

const kmsCredentials = {
accessKeyId: process.env.AWS_ACCESS_KEY_ID || 'AKIAxxxxxxxxxxxxxxxx', // credentials for your IAM user with KMS access
secretAccessKey: process.env.AWS_ACCESS_KEY_SECRET || 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // credentials for your IAM user with KMS access
region: 'us-east-1', // region of your KMS key
keyId: process.env.AWS_KMS_KEY_ID || 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', // KMS key id
}
const NETWORK = network.name as Network
const networkConfig: any = network.config
const provider = new ethers.JsonRpcProvider(networkConfig.url || '')
const deployer = new AwsKmsSigner(kmsCredentials).connect(provider)

/**
* @notice Deploy an upgradeable contract
* @dev The contract must existis in a solidity file in the contracts folder with the same name
* @param PROXY_CONTRACT_NAME The name of the contract
* @param OPERATOR_ADDRESS The address of the operator
* @param INITIALIZER_ARGUMENTS The arguments to pass to the function
* @param LIBRARIES_CONTRACT_NAME The name of the libraries
* @param CUSTOM_FEE_DATA The custom fee data
*/
export async function deployUpgradeableContract(
PROXY_CONTRACT_NAME: string,
OPERATOR_ADDRESS: string,
Expand All @@ -24,9 +24,9 @@ export async function deployUpgradeableContract(
) {
if (CUSTOM_FEE_DATA !== undefined) {
const FEE_DATA: any = CUSTOM_FEE_DATA
provider.getFeeData = async () => FEE_DATA
kmsProvider.getFeeData = async () => FEE_DATA
}
const deployerAddress = await deployer.getAddress()
const deployerAddress = await kmsDeployer.getAddress()
const libraries: { [key: string]: string } = {}

await confirmOrDie(
Expand All @@ -37,7 +37,7 @@ export async function deployUpgradeableContract(
print(colors.highlight, 'Deploying libraries...')

for (const LIBRARY_CONTRACT_NAME of LIBRARIES_CONTRACT_NAME) {
const LibraryFactory = await ethers.getContractFactory(LIBRARY_CONTRACT_NAME, deployer)
const LibraryFactory = await ethers.getContractFactory(LIBRARY_CONTRACT_NAME, kmsDeployer)
const library = await LibraryFactory.deploy()
await library.waitForDeployment()
libraries[LIBRARY_CONTRACT_NAME] = await library.getAddress()
Expand All @@ -50,7 +50,7 @@ export async function deployUpgradeableContract(
console.log('INITIALIZER_ARGUMENTS', INITIALIZER_ARGUMENTS)
const ContractFactory = await ethers.getContractFactory(PROXY_CONTRACT_NAME, {
libraries,
signer: deployer,
signer: kmsDeployer,
})
const contract = await upgrades.deployProxy(ContractFactory, INITIALIZER_ARGUMENTS, {
unsafeAllowLinkedLibraries: true,
Expand Down Expand Up @@ -93,7 +93,7 @@ export async function deployUpgradeableContract(
type: 'function',
},
]
const proxyAdminContract = new ethers.Contract(deploymentInfo[PROXY_CONTRACT_NAME].proxyAdmin, abi, deployer)
const proxyAdminContract = new ethers.Contract(deploymentInfo[PROXY_CONTRACT_NAME].proxyAdmin, abi, kmsDeployer)
await proxyAdminContract.transferOwnership(OPERATOR_ADDRESS)
print(colors.success, `Proxy admin ownership transferred to: ${OPERATOR_ADDRESS}`)
} catch (e) {
Expand Down
12 changes: 12 additions & 0 deletions utils/deployer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ethers, network } from 'hardhat'
import { AwsKmsSigner } from './ethers-aws-kms-signer'

const kmsCredentials = {
accessKeyId: process.env.AWS_ACCESS_KEY_ID || 'AKIAxxxxxxxxxxxxxxxx', // credentials for your IAM user with KMS access
secretAccessKey: process.env.AWS_ACCESS_KEY_SECRET || 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // credentials for your IAM user with KMS access
region: 'us-east-1', // region of your KMS key
keyId: process.env.AWS_KMS_KEY_ID || 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', // KMS key id
}
const networkConfig: any = network.config
export const kmsProvider = new ethers.JsonRpcProvider(networkConfig.url || '')
export const kmsDeployer = new AwsKmsSigner(kmsCredentials).connect(kmsProvider)
37 changes: 37 additions & 0 deletions utils/write-contract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { ethers, network } from 'hardhat'
import config, { Network } from '../addresses'
import { print, colors, confirmOrDie } from '../utils/misc'
import { kmsDeployer, kmsProvider } from './deployer'

const NETWORK = network.name as Network

/**
* @notice Send a transaction to a contract
* @dev The contract must be deployed on the network and the solidity file in the contracts folder
* @param CONTRACT_NAME The name of the contract
* @param FUNCTION_NAME The function to call
* @param FUNCTION_ARGUMENTS The arguments to pass to the function
* @param CUSTOM_FEE_DATA The custom fee data (optional)
*/
export async function callContractFunction(
CONTRACT_NAME: keyof (typeof config)[Network],
FUNCTION_NAME: string,
FUNCTION_ARGUMENTS: any,
CUSTOM_FEE_DATA?: { maxFeePerGas: bigint; maxPriorityFeePerGas: bigint },
) {
console.log('CONTRACT_NAME', CONTRACT_NAME)
await confirmOrDie(
`Are you sure you want to call ${FUNCTION_NAME} in ${CONTRACT_NAME} contract on ${NETWORK} network?`,
)
if (CUSTOM_FEE_DATA !== undefined) {
const FEE_DATA: any = CUSTOM_FEE_DATA
kmsProvider.getFeeData = async () => FEE_DATA
}
print(colors.warn, `Arguments: ${FUNCTION_ARGUMENTS}`)
const contract = await ethers.getContractAt(CONTRACT_NAME, config[NETWORK][CONTRACT_NAME].address, kmsDeployer)
print(colors.highlight, `Sending Transaction...`)
const response = await contract[FUNCTION_NAME](...FUNCTION_ARGUMENTS)
print(colors.highlight, `Waiting for transaction to be mined...`)
const transaction = await response.wait()
print(colors.bigSuccess, `Transaction sent! txHash: ${transaction?.hash}`)
}

0 comments on commit 7f3ab81

Please sign in to comment.