Skip to content

Commit

Permalink
Merge pull request #500 from JoinColony/experimental/meta-transactions
Browse files Browse the repository at this point in the history
Support for Metatransactions
  • Loading branch information
rdig committed Jul 11, 2022
2 parents 4eee2bf + 002d99f commit 022bc50
Show file tree
Hide file tree
Showing 14 changed files with 2,661 additions and 68 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@colony/colony-js",
"version": "v4.1.3-rc.0",
"version": "v4.2.0-rc.0",
"main": "lib/index.js",
"module": "lib-esm/index.js",
"files": [
Expand Down
3 changes: 2 additions & 1 deletion scripts/build-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const tokenContracts = [
'Token',
'TokenERC20',
'TokenSAI',
'MetaTxToken',
];
const version = CurrentColonyVersion;
const outRoot = resolvePath(__dirname, '../src/contracts');
Expand All @@ -73,7 +74,7 @@ const provisionNetworkVendor = async (tag: string): Promise<void> => {
if (gitSubmodule.stdout) gitSubmodule.stdout.pipe(process.stdout);
await gitSubmodule;

const yarn = execute('yarn', ['install'], {
const yarn = execute('yarn', ['install', '--pure-lockfile'], {
cwd: networkDir,
});
if (yarn.stdout) yarn.stdout.pipe(process.stdout);
Expand Down
14 changes: 13 additions & 1 deletion src/clients/Colony/ColonyClientV9.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
ColonyExtensionsV9,
ExtendedEstimateV9,
} from './extensions/extensionsV9';
import { addEncodeInterfaces } from './interfaces/encodeInterfacesV9';
import { getAllAbiEvents, getAbiFunctions } from '../../utils';
import { ColonyVersion } from '../../versions';

Expand Down Expand Up @@ -85,5 +86,16 @@ export default function getColonyClient(
colonyClientV9.clientVersion = ColonyVersion.FuchsiaLightweightSpaceship;
addExtensions(colonyClientV9, this);

return colonyClientV9 as ColonyClientV9;
/*
* @NOTE We need to reassign the whole instance since we can't just modify
* the passed in client (like `addExtensions` does).
*
* This is because we're adding to both `interfaces` and `functions` props
* of the class, and those are set by default as non-writtable
* (and non-cofigurable)
*
* Because of that, we clone instance of the client, which, after we change it,
* needs to be re-assigned in order to reflect the new changes.
*/
return (addEncodeInterfaces(colonyClientV9) as unknown) as ColonyClientV9;
}
67 changes: 33 additions & 34 deletions src/clients/Colony/extensions/commonExtensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,25 +448,38 @@ async function getExtensionClient(
return getVersionedExtensionClient(extensionAddress, this);
}

async function setArchitectureRoleWithProofs(
this: ExtendedIColony,
export const getRoleSettingProofs = async (
colonyClient: ExtendedIColony,
_user: string,
_domainId: BigNumberish,
_setTo: boolean,
overrides?: TransactionOverrides,
): Promise<ContractTransaction> {
requiredRole = ColonyRole.Architecture,
): Promise<[BigNumberish, BigNumberish]> => {
let proofs: [BigNumberish, BigNumberish];
// This method has two potential permissions, so we try both of them
try {
proofs = await getPermissionProofs(colonyClient, _domainId, requiredRole);
} catch (err) {
proofs = await getPermissionProofs(
this,
colonyClient,
_domainId,
ColonyRole.Architecture,
ColonyRole.Root,
);
} catch (err) {
proofs = await getPermissionProofs(this, _domainId, ColonyRole.Root);
}
const [permissionDomainId, childSkillIndex] = proofs;
return proofs;
};

async function setArchitectureRoleWithProofs(
this: ExtendedIColony,
_user: string,
_domainId: BigNumberish,
_setTo: boolean,
overrides?: TransactionOverrides,
): Promise<ContractTransaction> {
const [permissionDomainId, childSkillIndex] = await getRoleSettingProofs(
this,
_user,
_domainId,
);
return this.setArchitectureRole(
permissionDomainId,
childSkillIndex,
Expand All @@ -484,18 +497,11 @@ async function setFundingRoleWithProofs(
_setTo: boolean,
overrides?: TransactionOverrides,
): Promise<ContractTransaction> {
let proofs: [BigNumberish, BigNumberish];
// This method has two potential permissions, so we try both of them
try {
proofs = await getPermissionProofs(
this,
_domainId,
ColonyRole.Architecture,
);
} catch (err) {
proofs = await getPermissionProofs(this, _domainId, ColonyRole.Root);
}
const [permissionDomainId, childSkillIndex] = proofs;
const [permissionDomainId, childSkillIndex] = await getRoleSettingProofs(
this,
_user,
_domainId,
);
return this.setFundingRole(
permissionDomainId,
childSkillIndex,
Expand All @@ -513,18 +519,11 @@ async function setAdministrationRoleWithProofs(
_setTo: boolean,
overrides?: TransactionOverrides,
): Promise<ContractTransaction> {
let proofs: [BigNumberish, BigNumberish];
// This method has two potential permissions, so we try both of them
try {
proofs = await getPermissionProofs(
this,
_domainId,
ColonyRole.Architecture,
);
} catch (err) {
proofs = await getPermissionProofs(this, _domainId, ColonyRole.Root);
}
const [permissionDomainId, childSkillIndex] = proofs;
const [permissionDomainId, childSkillIndex] = await getRoleSettingProofs(
this,
_user,
_domainId,
);
return this.setAdministrationRole(
permissionDomainId,
childSkillIndex,
Expand Down
11 changes: 7 additions & 4 deletions src/clients/Colony/extensions/extensionsV5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,21 @@ async function transferStakeWithProofs(
);
}

export const getMethodDomainProofs = async (
colonyClient: ColonyExtensionsV5<ValidColony>,
_parentDomainId: BigNumberish,
): Promise<[BigNumber, BigNumber]> =>
getPermissionProofs(colonyClient, _parentDomainId, ColonyRole.Architecture);
async function addDomainWithProofs(
this: ColonyExtensionsV5<ValidColony>,
_parentDomainId: BigNumberish,
_metadata: string,
overrides?: TransactionOverrides,
): Promise<ContractTransaction> {
let overrideOverload = overrides;
const [permissionDomainId, childSkillIndex] = await getPermissionProofs(
const [permissionDomainId, childSkillIndex] = await getMethodDomainProofs(
this,
_parentDomainId,
ColonyRole.Architecture,
);
/*
* Otherwise, because of the positioning of `overrides`, it might get confused
Expand Down Expand Up @@ -247,10 +251,9 @@ async function editDomainWithProofs(
_metadata: string,
overrides?: TransactionOverrides,
): Promise<ContractTransaction> {
const [permissionDomainId, childSkillIndex] = await getPermissionProofs(
const [permissionDomainId, childSkillIndex] = await getMethodDomainProofs(
this,
_domainId,
ColonyRole.Architecture,
);
return this.editDomain(
permissionDomainId,
Expand Down
Loading

0 comments on commit 022bc50

Please sign in to comment.