Skip to content

Commit

Permalink
update tests, scripts, readme
Browse files Browse the repository at this point in the history
  • Loading branch information
peersky committed Dec 4, 2024
1 parent 4dc5b1a commit d975d9f
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 53 deletions.
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,12 @@ In order to instantiate the MAO distribution, you don't need to deploy a thing.
```ts
import { MAODistribution } from 'rankify-contracts/types';
const distributorArguments: MAODistribution.DistributorArgumentsStruct = {
DAOSEttings: {
daoURI: 'https://example.com/dao',
subdomain: 'example',
metadata: ethers.utils.hexlify(ethers.utils.toUtf8Bytes('metadata')),
tokenSettings: {
tokenName: 'tokenName',
tokenSymbol: 'tokenSymbol',
},
RankifySettings: {
RankTokenContractURI: 'https://example.com/rank',
rankifySettings: {
rankTokenContractURI: 'https://example.com/rank',
principalCost: RInstanceSettings.PRINCIPAL_COST,
principalTimeConstant: RInstanceSettings.PRINCIPAL_TIME_CONSTANT,
metadata: ethers.utils.hexlify(ethers.utils.toUtf8Bytes('metadata')),
Expand All @@ -78,7 +75,7 @@ const distributorArguments: MAODistribution.DistributorArgumentsStruct = {
// Encode the arguments
const data = ethers.utils.defaultAbiCoder.encode(
[
'tuple(tuple(string daoURI, string subdomain, bytes metadata, string tokenName, string tokenSymbol) DAOSEttings, tuple(uint256 principalCost, uint256 principalTimeConstant, string metadata, string rankTokenURI, string RankTokenContractURI) RankifySettings)',
'tuple(tuple(string tokenName, string tokenSymbol) tokenSettings, tuple(uint256 principalCost, uint256 principalTimeConstant, string metadata, string rankTokenURI, string rankTokenContractURI) rankifySettings)',
],
[distributorArguments],
);
Expand Down
2 changes: 1 addition & 1 deletion deploy/mao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const govTokenDeployment = await deploy('DistributableGovernanceERC20', {
from: deployer,
skipIfAlreadyDeployed: true,
args: [ethers.constants.AddressZero, 'TokenName', 'tkn', mintSettings, ethers.constants.AddressZero],
args: ['TokenName', 'tkn', mintSettings, ethers.constants.AddressZero],
});

const govTokenDeploymentCode = await hre.ethers.provider.getCode(govTokenDeployment.address);
Expand Down
13 changes: 6 additions & 7 deletions playbook/createSubject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,12 @@ task('createSubject', 'Creates a new subject with MAO distribution')
newInstanceId: parsedLog.args.newInstanceId,
receipt,
instancesParsed: {
rankToken: parsedLog.args.instances[12],
rankifyInstance: parsedLog.args.instances[3],
daoInstance: parsedLog.args.instances[0],
govToken: parsedLog.args.instances[1],
govTokenAccessManager: parsedLog.args.instances[2],
acidInstance: parsedLog.args.instances[3],
acidAccessManager: parsedLog.args.instances[11],
rankToken: parsedLog.args.instances[11],
rankifyInstance: parsedLog.args.instances[2],
govToken: parsedLog.args.instances[0],
govTokenAccessManager: parsedLog.args.instances[1],
acidInstance: parsedLog.args.instances[2],
acidAccessManager: parsedLog.args.instances[10],
},
};
});
2 changes: 1 addition & 1 deletion scripts/libraries/generateDistributorData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MAODistribution } from '../../types/src/distributions/MAODistribution';
export function generateDistributorData(args: MAODistribution.DistributorArgumentsStruct): string {
const data = ethers.utils.defaultAbiCoder.encode(
[
'tuple(tuple(string daoURI, string subdomain, bytes metadata, string tokenName, string tokenSymbol) DAOSEttings, tuple(uint256 principalCost, uint256 principalTimeConstant, string metadata, string rankTokenURI, string RankTokenContractURI) RankifySettings)',
'tuple(tuple(string tokenName, string tokenSymbol) tokenSettings, tuple(uint256 principalCost, uint256 principalTimeConstant, string metadata, string rankTokenURI, string rankTokenContractURI) rankifySettings)',
],
[args],
);
Expand Down
11 changes: 5 additions & 6 deletions scripts/playbooks/instantiateMAO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ export const instantiateMAO = async ({
const instances = evts[0].args.instances;

return {
daoAddress: instances[0],
govToken: instances[1],
govTokenAccessManager: instances[2],
ACIDInstance: instances[3],
ACIDAccessManager: instances[11],
rankToken: instances[12],
govToken: instances[0],
govTokenAccessManager: instances[1],
ACIDInstance: instances[2],
ACIDAccessManager: instances[10],
rankToken: instances[11],
instanceId: evts[0].args.newInstanceId,
distributorsId: evts[0].args.distributionId,
};
Expand Down
4 changes: 2 additions & 2 deletions src/distributions/MAODistribution.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ contract MAODistribution is IDistribution, CodeIndexer {
uint96 principalTimeConstant;
string metadata;
string rankTokenURI;
string RankTokenContractURI;
string rankTokenContractURI;
}

struct TokenArguments {
Expand Down Expand Up @@ -186,7 +186,7 @@ contract MAODistribution is IDistribution, CodeIndexer {
RankTokenAccessSettings[5].distributionComponentsOnly = true;

rankTokenAccessManager.initialize(RankTokenAccessSettings, rankToken, IDistributor(msg.sender)); // msg.sender must be IDistributor or it will revert
RankToken(rankToken).initialize(args.rankTokenURI, args.RankTokenContractURI, address(rankTokenAccessManager));
RankToken(rankToken).initialize(args.rankTokenURI, args.rankTokenContractURI, address(rankTokenAccessManager));

(
address[] memory RankifyDistrAddresses,
Expand Down
18 changes: 6 additions & 12 deletions test/MAODistribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import { deployments, ethers, getNamedAccounts } from 'hardhat';
import hre from 'hardhat';
import { expect } from 'chai';
import { IDAO, MAODistribution, DAODistributor, Rankify, RankifyDiamondInstance } from '../types';
import utils, { AdrSetupResult, setupTest } from './utils';
import { MAODistribution, DAODistributor, Rankify, RankifyDiamondInstance } from '../types';
import { AdrSetupResult, setupTest } from './utils';
import { getCodeIdFromArtifact } from '../scripts/getCodeId';
import addDistribution from '../scripts/playbooks/addDistribution';
import generateDistributorData from '../scripts/libraries/generateDistributorData';
Expand Down Expand Up @@ -43,22 +43,18 @@ describe('MAODistribution', async function () {
});
it('Can instantiate a distribution', async () => {
const distributorArguments: MAODistribution.DistributorArgumentsStruct = {
DAOSEttings: {
daoURI: 'https://example.com/dao',
subdomain: 'example',
metadata: ethers.utils.hexlify(ethers.utils.toUtf8Bytes('metadata')),
tokenSettings: {
tokenName: 'tokenName',
tokenSymbol: 'tokenSymbol',
},
RankifySettings: {
RankTokenContractURI: 'https://example.com/rank',
rankifySettings: {
rankTokenContractURI: 'https://example.com/rank',
metadata: ethers.utils.hexlify(ethers.utils.toUtf8Bytes('metadata')),
rankTokenURI: 'https://example.com/rank',
principalCost: 1,
principalTimeConstant: 1,
},
};

// Encode the arguments using generateDistributorData
const data = generateDistributorData(distributorArguments);

Expand All @@ -79,12 +75,10 @@ describe('MAODistribution', async function () {
const filter = distributorContract.filters.Instantiated();
const evts = await distributorContract.queryFilter(filter);
expect(evts.length).to.equal(1);
const daoContract = (await ethers.getContractAt('IDAO', evts[0].args.instances[0])) as IDAO;
expect((await daoContract.functions.getTrustedForwarder())[0]).to.equal(ethers.constants.AddressZero);

const ACIDContract = (await ethers.getContractAt(
'RankifyDiamondInstance',
evts[0].args.instances[3],
evts[0].args.instances[2],
)) as RankifyDiamondInstance;
expect((await ACIDContract.functions['getGM(uint256)'](0))[0]).to.equal(ethers.constants.AddressZero);
});
Expand Down
11 changes: 4 additions & 7 deletions test/RankToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,12 @@ describe('Rank Token Test', async function () {

await addDistribution(hre)(await getCodeIdFromArtifact(hre)('MAODistribution'), adr.gameOwner.wallet);
const distributorArguments: MAODistribution.DistributorArgumentsStruct = {
DAOSEttings: {
daoURI: 'https://example.com/dao',
subdomain: 'example',
metadata: ethers.utils.hexlify(ethers.utils.toUtf8Bytes('metadata')),
tokenSettings: {
tokenName: 'tokenName',
tokenSymbol: 'tokenSymbol',
},
RankifySettings: {
RankTokenContractURI: 'https://example.com/rank',
rankifySettings: {
rankTokenContractURI: 'https://example.com/rank',
principalCost: RInstanceSettings.PRINCIPAL_COST,
principalTimeConstant: RInstanceSettings.PRINCIPAL_TIME_CONSTANT,
metadata: ethers.utils.hexlify(ethers.utils.toUtf8Bytes('metadata')),
Expand Down Expand Up @@ -78,7 +75,7 @@ describe('Rank Token Test', async function () {
await env.rankifyToken.connect(adr.player9.wallet).approve(rankifyInstance.address, ethers.constants.MaxUint256);
await env.rankifyToken.connect(adr.player10.wallet).approve(rankifyInstance.address, ethers.constants.MaxUint256);

rankToken = (await ethers.getContractAt('RankToken', evts[0].args.instances[12])) as RankToken;
rankToken = (await ethers.getContractAt('RankToken', evts[0].args.instances[11])) as RankToken;
});
// it('Allows only owner to set rankingInstance', async () => {
// await expect(rankToken.connect(deployer).updateRankingInstance(adr.gameCreator1.wallet.address))
Expand Down
15 changes: 5 additions & 10 deletions test/RankifyInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,12 @@ describe(scriptName, () => {
env = setup.env;
await addDistribution(hre)(await getCodeIdFromArtifact(hre)('MAODistribution'), adr.gameOwner.wallet);
const distributorArguments: MAODistribution.DistributorArgumentsStruct = {
DAOSEttings: {
daoURI: 'https://example.com/dao',
subdomain: 'example',
metadata: ethers.utils.hexlify(ethers.utils.toUtf8Bytes('metadata')),
tokenSettings: {
tokenName: 'tokenName',
tokenSymbol: 'tokenSymbol',
},
RankifySettings: {
RankTokenContractURI: 'https://example.com/rank',
rankifySettings: {
rankTokenContractURI: 'https://example.com/rank',
metadata: ethers.utils.hexlify(ethers.utils.toUtf8Bytes('metadata')),
rankTokenURI: 'https://example.com/rank',
principalCost: RInstanceSettings.PRINCIPAL_COST,
Expand All @@ -274,7 +271,7 @@ describe(scriptName, () => {
const evts = await env.distributor.queryFilter(filter);
rankifyInstance = (await ethers.getContractAt(
'RankifyDiamondInstance',
evts[0].args.instances[3],
evts[0].args.instances[2],
)) as RankifyDiamondInstance;

await env.rankifyToken
Expand All @@ -297,7 +294,7 @@ describe(scriptName, () => {
await env.rankifyToken.connect(adr.player9.wallet).approve(rankifyInstance.address, ethers.constants.MaxUint256);
await env.rankifyToken.connect(adr.player10.wallet).approve(rankifyInstance.address, ethers.constants.MaxUint256);

rankToken = (await ethers.getContractAt('RankToken', evts[0].args.instances[12])) as RankToken;
rankToken = (await ethers.getContractAt('RankToken', evts[0].args.instances[11])) as RankToken;

requirement.contracts = [];
requirement.contracts.push({
Expand Down Expand Up @@ -739,8 +736,6 @@ describe(scriptName, () => {
const { params } = proposalsStruct[i];
if (i !== 0) {
await rankifyInstance.connect(adr.gameMaster1.wallet).submitProposal(params);
} else {
console.log('skipped proposal', i);
}
}

Expand Down

0 comments on commit d975d9f

Please sign in to comment.