-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: deployment scripts for nft-collection
- Loading branch information
Andres Adjimann
committed
Dec 16, 2024
1 parent
251f57e
commit 4291ff9
Showing
6 changed files
with
251 additions
and
5 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
24 changes: 24 additions & 0 deletions
24
packages/deploy/deploy/28_nft_collection/01_deploy_nft_collection_implementation.ts
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,24 @@ | ||
import {DeployFunction} from 'hardhat-deploy/types'; | ||
import {HardhatRuntimeEnvironment} from 'hardhat/types'; | ||
import {DEPLOY_TAGS} from '../../hardhat.config'; | ||
|
||
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { | ||
const {deployments, getNamedAccounts} = hre; | ||
const {deployer} = await getNamedAccounts(); | ||
|
||
await deployments.deploy('NFTCollection_Implementation', { | ||
from: deployer, | ||
contract: 'NFTCollection', | ||
log: true, | ||
skipIfAlreadyDeployed: true, | ||
}); | ||
}; | ||
|
||
export default func; | ||
func.tags = [ | ||
'PolygonNFTCollection', | ||
'PolygonNFTCollectionImplementation_deploy', | ||
DEPLOY_TAGS.L2, | ||
DEPLOY_TAGS.L2_PROD, | ||
DEPLOY_TAGS.L2_TEST, | ||
]; |
88 changes: 88 additions & 0 deletions
88
packages/deploy/deploy/28_nft_collection/02_deploy_nft_collection_beacon.ts
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,88 @@ | ||
import {ZeroAddress} from 'ethers'; | ||
import {DeployFunction} from 'hardhat-deploy/types'; | ||
import {HardhatRuntimeEnvironment} from 'hardhat/types'; | ||
import {DEPLOY_TAGS} from '../../hardhat.config'; | ||
import { | ||
getEventArgsFromReceipt, | ||
saveDeployment, | ||
} from '../../utils/hardhatDeployUtils'; | ||
import {getNamedAccounts} from 'hardhat'; | ||
|
||
// hardhat-deploy don't support factory and beacons the way we use it | ||
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { | ||
const {deployments, ethers} = hre; | ||
const beaconAlias = ethers.encodeBytes32String('nft-collection-v2'); | ||
const implementation = await deployments.get('NFTCollection_Implementation'); | ||
const beaconAddress = await deployments.read( | ||
'CollectionFactory', | ||
'aliasToBeacon', | ||
beaconAlias | ||
); | ||
if (beaconAddress == ZeroAddress) { | ||
await deployments.catchUnknownSigner( | ||
deployBeacon(hre, beaconAlias, implementation) | ||
); | ||
} else { | ||
await performSanityChecks(hre, beaconAddress, implementation); | ||
} | ||
}; | ||
|
||
async function deployBeacon(hre, beaconAlias, implementation) { | ||
const {deployments, ethers} = hre; | ||
const {nftCollectionAdmin} = await getNamedAccounts(); | ||
const receipt = await deployments.execute( | ||
'CollectionFactory', | ||
{from: nftCollectionAdmin, log: true}, | ||
'deployBeacon', | ||
implementation.address, | ||
beaconAlias | ||
); | ||
const eventArgs: {beaconAlias: string; beaconAddress: string} = | ||
getEventArgsFromReceipt( | ||
await ethers.getContract('CollectionFactory'), | ||
receipt, | ||
'BeaconAdded' | ||
); | ||
await saveDeployment( | ||
deployments, | ||
eventArgs.beaconAddress, | ||
'NFTCollection_Beacon', | ||
'UpgradeableBeacon', | ||
receipt | ||
); | ||
} | ||
|
||
async function performSanityChecks(hre, beaconAddress: string, implementation) { | ||
const {deployments, ethers} = hre; | ||
const beaconArtifact = await deployments.getArtifact('UpgradeableBeacon'); | ||
const beacon = await ethers.getContractAt(beaconArtifact.abi, beaconAddress); | ||
|
||
const i = await beacon.implementation(); | ||
if (i != implementation.address) { | ||
throw new Error( | ||
'something went wrong: Beacon already deployed but has wrong implementation address, must call updateBeaconImplementation' | ||
); | ||
} | ||
const factory = await deployments.get('CollectionFactory'); | ||
const o = await beacon.owner(); | ||
if (o != factory.address) { | ||
throw new Error( | ||
'something went wrong: Beacon already deployed but has wrong owner' | ||
); | ||
} | ||
} | ||
|
||
export default func; | ||
func.tags = [ | ||
'PolygonNFTCollection', | ||
'PolygonNFTCollection_Beacon', | ||
'PolygonNFTCollectionBeacon_deploy', | ||
DEPLOY_TAGS.L2, | ||
DEPLOY_TAGS.L2_PROD, | ||
DEPLOY_TAGS.L2_TEST, | ||
]; | ||
func.dependencies = [ | ||
'CollectionFactory_deploy', | ||
'CollectionFactory_change_admin', | ||
'PolygonNFTCollectionImplementation_deploy', | ||
]; |
83 changes: 83 additions & 0 deletions
83
packages/deploy/deploy/28_nft_collection/100_deploy_nft_collection_mock.ts
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,83 @@ | ||
import {DeployFunction} from 'hardhat-deploy/types'; | ||
import {HardhatRuntimeEnvironment} from 'hardhat/types'; | ||
import {DEPLOY_TAGS} from '../../hardhat.config'; | ||
import { | ||
getEventArgsFromReceipt, | ||
saveDeployment, | ||
} from '../../utils/hardhatDeployUtils'; | ||
|
||
// Collections are created via backoffice, this script creates a collection | ||
// for testing (TO BE USED ONLY ON TESTNETS) | ||
// hardhat-deploy don't support factory and beacons the way we use it | ||
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { | ||
const {deployments, getNamedAccounts, ethers} = hre; | ||
|
||
const skipIfAlreadyExists = !!(await deployments.getOrNull( | ||
'NFTCollection_CollectionProxy' | ||
)); | ||
if (skipIfAlreadyExists) { | ||
console.log('skip NFTCollection_CollectionProxy already exist'); | ||
return; | ||
} | ||
const {treasury, raffleSignWallet, nftCollectionAdmin} = | ||
await getNamedAccounts(); | ||
|
||
// TODO: set the right arguments | ||
const metadataUrl = | ||
'https://contracts.sandbox.game/avatarcollection-unrevealed/'; | ||
const collectionName = 'NFTCollectionTest'; | ||
const collectionSymbol = 'TEST'; | ||
const MAX_SUPPLY = 500; | ||
|
||
const TRUSTED_FORWARDER = await deployments.get('TRUSTED_FORWARDER_V2'); | ||
const sandContract = await deployments.get('PolygonSand'); | ||
const implementation = await ethers.getContract( | ||
'NFTCollection_Implementation' | ||
); | ||
|
||
await deployments.catchUnknownSigner(async () => { | ||
const receipt = await deployments.execute( | ||
'CollectionFactory', | ||
{from: nftCollectionAdmin, log: true}, | ||
'deployCollection', | ||
ethers.encodeBytes32String('nft-collection-v2'), | ||
implementation.interface.encodeFunctionData('initialize', [ | ||
nftCollectionAdmin, | ||
metadataUrl, | ||
collectionName, | ||
collectionSymbol, | ||
treasury, | ||
raffleSignWallet, | ||
TRUSTED_FORWARDER.address, | ||
sandContract.address, | ||
MAX_SUPPLY, | ||
]) | ||
); | ||
const eventArgs: {collectionProxy: string; beaconAddress: string} = | ||
getEventArgsFromReceipt( | ||
await ethers.getContract('CollectionFactory'), | ||
receipt, | ||
'CollectionAdded' | ||
); | ||
await saveDeployment( | ||
deployments, | ||
eventArgs.collectionProxy, | ||
'NFTCollectionMat_Proxy', | ||
'CollectionProxy', | ||
receipt, | ||
await implementation.getAddress() | ||
); | ||
}); | ||
}; | ||
|
||
export default func; | ||
func.tags = [ | ||
'PolygonNFTCollectionTest_deploy', | ||
DEPLOY_TAGS.L2, | ||
DEPLOY_TAGS.L2_TEST, | ||
]; | ||
func.dependencies = [ | ||
'PolygonNFTCollectionBeacon_deploy', | ||
'PolygonSand_deploy', | ||
'TRUSTED_FORWARDER_V2', | ||
]; |
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 |
---|---|---|
|
@@ -15,7 +15,13 @@ import { | |
|
||
// Package name : solidity source code path | ||
const importedPackages = { | ||
'@sandbox-smart-contracts/avatar': 'contracts/', | ||
'@sandbox-smart-contracts/avatar': [ | ||
'contracts/nft-collection/NFTCollection.sol', | ||
'contracts/avatar/AvatarCollection.sol', | ||
'contracts/proxy', | ||
'contracts/raffle', | ||
'contracts/raffleold/contracts', | ||
], | ||
'@sandbox-smart-contracts/[email protected]': [ | ||
'contracts/Asset.sol', | ||
'contracts/AssetCreate.sol', | ||
|
@@ -312,6 +318,7 @@ const namedAccounts = { | |
default: 'sandAdmin', | ||
mainnet: null, | ||
polygon: '0xF06dD9b61d480704Cc7bEF717e5Ea6efB6Af75bE', // Final admin should be 0xE79AF6BEb7D31c7faF7a1b891d9684960522D22e | ||
amoy: '0x4BF86138e9DC66Fb65F8b9387C53aB4439FC41FF', | ||
}, | ||
lazyMintingCatSeller: { | ||
default: 4, | ||
|
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,39 @@ | ||
// Hardhat-deploy don't support factory and beacons the way we use it | ||
// We are forced to save the deployment by hand | ||
import { | ||
DeploymentsExtension, | ||
DeploymentSubmission, | ||
Receipt, | ||
} from 'hardhat-deploy/types'; | ||
import {Contract} from 'ethers'; | ||
|
||
export async function saveDeployment( | ||
deployments: DeploymentsExtension, | ||
address: string, | ||
artifactName: string, | ||
contractName: string, | ||
receipt: Receipt, | ||
implementationAddress?: string | ||
) { | ||
const extendedArtifact = await deployments.getExtendedArtifact(contractName); | ||
console.log( | ||
`saving "${artifactName}" (tx: ${receipt.transactionHash})...: deployed at ${address} with ${receipt.gasUsed} gas` | ||
); | ||
await deployments.save(artifactName, { | ||
address, | ||
...extendedArtifact, | ||
receipt, | ||
transactionHash: receipt.transactionHash, | ||
...(implementationAddress ? {implementation: implementationAddress} : {}), | ||
} as DeploymentSubmission); | ||
} | ||
|
||
export function getEventArgsFromReceipt( | ||
contract: Contract, | ||
receipt: Receipt, | ||
eventName: string | ||
) { | ||
const fragment = contract.filters[eventName].fragment; | ||
const ev = receipt.events.find((x) => x.topics[0] == fragment.topicHash); | ||
return ev.args; | ||
} |
4291ff9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage for this commit
Coverage Report