Skip to content

Commit

Permalink
playbooks added and modified (#86)
Browse files Browse the repository at this point in the history
* playbooks added and modified

* rm commented line
  • Loading branch information
peersky authored Dec 2, 2024
1 parent 9246d9f commit 5a44931
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .changeset/friendly-radios-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'rankify-contracts': minor
---

added playbooks for adding distribution and creating subject, removed old multipass playbook
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
14 changes: 14 additions & 0 deletions playbook/addDistribution.ts
Original file line number Diff line number Diff line change
@@ -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;
});
78 changes: 78 additions & 0 deletions playbook/createSubject.ts
Original file line number Diff line number Diff line change
@@ -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 };
});
3 changes: 3 additions & 0 deletions playbook/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./addDistribution"
export * from "./createGame"
export * from "./createSubject"
2 changes: 1 addition & 1 deletion playbook/utils/deploy-to-local-anvil.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 0 additions & 18 deletions playbook/utils/utils.ts

This file was deleted.

9 changes: 4 additions & 5 deletions scripts/playbooks/addDistribution.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { ethers } from 'hardhat';
import { Signer } from '@ethersproject/abstract-signer';
import { DAODistributor } from '../../types';

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,
) as DAODistributor;
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();
Expand Down

0 comments on commit 5a44931

Please sign in to comment.