diff --git a/.changeset/friendly-radios-pump.md b/.changeset/friendly-radios-pump.md new file mode 100644 index 0000000..55daf78 --- /dev/null +++ b/.changeset/friendly-radios-pump.md @@ -0,0 +1,5 @@ +--- +'rankify-contracts': minor +--- + +added playbooks for adding distribution and creating subject, removed old multipass playbook diff --git a/hardhat.config.ts b/hardhat.config.ts index 63b9413..d226ba6 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -12,7 +12,7 @@ import 'hardhat-contract-sizer'; import 'hardhat-deploy'; import 'hardhat-tracer'; import 'solidity-docgen'; -import './playbook/createGame'; +import './playbook'; import getSuperInterface from './scripts/getSuperInterface'; import { ErrorFragment, EventFragment, FunctionFragment } from '@ethersproject/abi'; import './scripts/generateSelectorDocs'; diff --git a/playbook/addDistribution.ts b/playbook/addDistribution.ts new file mode 100644 index 0000000..ea3a0e8 --- /dev/null +++ b/playbook/addDistribution.ts @@ -0,0 +1,14 @@ +import { task } from 'hardhat/config'; + +import addDistribution from '../scripts/playbooks/addDistribution'; +import { getCodeIdFromArtifact } from '../scripts/getCodeId'; + +task('addDistribution', 'Adds new distribution').setAction(async (_, hre) => { + const { getNamedAccounts } = hre; + const { DAO } = await getNamedAccounts(); + + const oSigner = await hre.ethers.getSigner(DAO); + const result = await addDistribution(hre)(await getCodeIdFromArtifact(hre)('MAODistribution'), oSigner); + console.log('Distribution added, Distributors Id:', result.distributorsId); + return result; +}); diff --git a/playbook/createSubject.ts b/playbook/createSubject.ts new file mode 100644 index 0000000..f248726 --- /dev/null +++ b/playbook/createSubject.ts @@ -0,0 +1,78 @@ +import { task } from 'hardhat/config'; + +import { getCodeIdFromArtifact } from '../scripts/getCodeId'; +import { DAODistributor, MAODistribution, Rankify } from '../types'; +import generateDistributorData from '../scripts/libraries/generateDistributorData'; +import { InstantiatedEvent } from '../types/src/distributors/DAODistributor'; + +task('createSubject', 'Creates a new subject with MAO distribution') + .addOptionalParam('daoUri', 'URI for the DAO metadata', 'https://example.com/dao') + .addOptionalParam('subdomain', 'Subdomain for the DAO. NB: Must be unique', 'example') + .addOptionalParam('metadata', 'Metadata for the DAO', 'metadata') + .addOptionalParam('tokenName', 'Name of the token', 'tokenName') + .addOptionalParam('tokenSymbol', 'Symbol of the token', 'tokenSymbol') + .addOptionalParam('rankTokenUri', 'URI for the rank token', 'https://example.com/rank') + .addOptionalParam('rankTokenContractUri', 'URI for the rank token contract', 'https://example.com/rank') + .addOptionalParam('principalCost', 'Principal cost for ranking', '1') + .addOptionalParam('principalTimeConstant', 'Time constant for principal', '3600') + .setAction(async (taskArgs, hre) => { + const { getNamedAccounts } = hre; + const distributorDeployment = await hre.deployments.get('DAODistributor'); + + const distributorArguments: MAODistribution.DistributorArgumentsStruct = { + DAOSEttings: { + daoURI: taskArgs.daoUri, + subdomain: taskArgs.subdomain, + metadata: hre.ethers.utils.hexlify(hre.ethers.utils.toUtf8Bytes(taskArgs.metadata)), + tokenName: taskArgs.tokenName, + tokenSymbol: taskArgs.tokenSymbol, + }, + RankifySettings: { + RankTokenContractURI: taskArgs.rankTokenContractUri, + metadata: hre.ethers.utils.hexlify(hre.ethers.utils.toUtf8Bytes(taskArgs.metadata)), + rankTokenURI: taskArgs.rankTokenUri, + principalCost: taskArgs.principalCost, + principalTimeConstant: taskArgs.principalTimeConstant, + }, + }; + + const { DAO } = await getNamedAccounts(); + + const distributorContract = new hre.ethers.Contract( + distributorDeployment.address, + distributorDeployment.abi, + await hre.ethers.getSigner(DAO), + ) as DAODistributor; + + const data = generateDistributorData(distributorArguments); + + const maoId = await getCodeIdFromArtifact(hre)('MAODistribution'); + const distributorsDistId = await distributorContract['calculateDistributorId(bytes32,address)']( + maoId, + hre.ethers.constants.AddressZero, + ); + + const token = await hre.deployments.get('Rankify'); + const { DAO: owner } = await hre.getNamedAccounts(); + const oSigner = await hre.ethers.getSigner(owner); + const tokenContract = new hre.ethers.Contract(token.address, token.abi, oSigner) as Rankify; + await tokenContract.mint(oSigner.address, hre.ethers.utils.parseEther('100')); + await tokenContract.approve(distributorContract.address, hre.ethers.constants.MaxUint256); + const instances = await distributorContract.numInstances(); + const tx = await distributorContract.connect(oSigner).instantiate(distributorsDistId, data); + const receipt = await tx.wait(); + const filter = distributorContract.filters.Instantiated(distributorsDistId); + const t = filter.topics && filter.topics[0]; + if (!t) throw new Error('Filter not found'); + const logs = receipt.logs.filter(log => log.topics[0] === t); + const parsedLog = distributorContract.interface.parseLog(logs[0]); + + console.log('Subject created successfully!'); + console.log('Transaction hash:', tx.hash); + console.log('DAO URI:', taskArgs.daoUri); + console.log('Token Name:', taskArgs.tokenName); + console.log('Token Symbol:', taskArgs.tokenSymbol); + console.log('instances created', parsedLog.args.instances); + console.log('instance id', parsedLog.args.newInstanceId); + return { instances, newInstanceId: parsedLog.args.newInstanceId, receipt }; + }); diff --git a/playbook/index.ts b/playbook/index.ts new file mode 100644 index 0000000..501ec77 --- /dev/null +++ b/playbook/index.ts @@ -0,0 +1,3 @@ +export * from "./addDistribution" +export * from "./createGame" +export * from "./createSubject" \ No newline at end of file diff --git a/playbook/utils/deploy-to-local-anvil.sh b/playbook/utils/deploy-to-local-anvil.sh index f43f5ed..4421efb 100755 --- a/playbook/utils/deploy-to-local-anvil.sh +++ b/playbook/utils/deploy-to-local-anvil.sh @@ -2,4 +2,4 @@ rm -rf ./deployments/localhost export NODE_ENV=TEST -pnpm hardhat deploy --tags multipass,rankify --network localhost +pnpm hardhat deploy --tags MAO,rankify --network localhost diff --git a/playbook/utils/utils.ts b/playbook/utils/utils.ts deleted file mode 100644 index f5c32c5..0000000 --- a/playbook/utils/utils.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; -import { RegisterMessage, MultipassJs } from '../..//utils/multipass'; - -export const signRegistrarMessage = async ( - message: RegisterMessage, - verifierAddress: string, - signer: SignerWithAddress, - hre: any - ) => { - let { chainId } = await hre.ethers.provider.getNetwork(); - const multipassJs = new MultipassJs({ - chainId: chainId, - contractName: 'MultipassDNS', - version: '0.0.1', - ...hre.network, - }); - return await multipassJs.signRegistrarMessage(message, verifierAddress, signer); - }; \ No newline at end of file diff --git a/scripts/playbooks/addDistribution.ts b/scripts/playbooks/addDistribution.ts index 6ff57b4..ee1cc65 100644 --- a/scripts/playbooks/addDistribution.ts +++ b/scripts/playbooks/addDistribution.ts @@ -1,5 +1,4 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; -import { ethers } from 'hardhat'; import { Signer } from '@ethersproject/abstract-signer'; import { DAODistributor } from '../../types'; @@ -7,15 +6,15 @@ export const addDistributionNoChecks = (hre: HardhatRuntimeEnvironment) => async (distrId: string, signer: Signer, initializer?: string) => { const { deployments } = hre; const DAODistributor = await deployments.get('DAODistributor'); - const distributorContract = new ethers.Contract(DAODistributor.address, DAODistributor.abi, signer); - return distributorContract.addDistribution(distrId, initializer ?? ethers.constants.AddressZero); + const distributorContract = new hre.ethers.Contract(DAODistributor.address, DAODistributor.abi, signer); + return distributorContract.addDistribution(distrId, initializer ?? hre.ethers.constants.AddressZero); }; export const addDistribution = (hre: HardhatRuntimeEnvironment) => async (distrId: string, signer: Signer, initializer?: string) => { const { deployments } = hre; const DAODistributor = await deployments.get('DAODistributor'); - const distributorContract = new ethers.Contract( + const distributorContract = new hre.ethers.Contract( DAODistributor.address, DAODistributor.abi, signer, @@ -23,7 +22,7 @@ export const addDistribution = const distributionsLengthBefore = (await distributorContract.getDistributions()).length; const receipt = await distributorContract['addDistribution(bytes32,address)']( distrId, - initializer ?? ethers.constants.AddressZero, + initializer ?? hre.ethers.constants.AddressZero, ); const distributorsId = await distributorContract.getDistributions();