Skip to content

Commit

Permalink
Merge pull request #494 from JoinColony/feature/whitelist-extension
Browse files Browse the repository at this point in the history
Introduce Whitelist Extension
  • Loading branch information
rdig committed Nov 18, 2021
2 parents 06a5366 + ab5065b commit 45d5dcb
Show file tree
Hide file tree
Showing 59 changed files with 62,880 additions and 162 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.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@colony/colony-js",
"version": "v4.0.2",
"version": "v4.1.0-beta.8",
"main": "lib/index.js",
"module": "lib-esm/index.js",
"files": [
Expand All @@ -19,13 +19,16 @@
},
"scripts": {
"clean": "rimraf ./lib && rimraf ./lib-esm",
"build": "npm run clean && npm run compile && npm run compile-esm && npm run copy-declarations && npm run build-docs",
"build": "npm run clean && npm run compile && npm run compile-esm && OUT=lib npm run copy-declarations && OUT=lib-esm npm run copy-declarations && npm run build-docs",
"test": "npm run lint && npm run typecheck && jest",
"lint": "eslint src/**/*.ts scripts/**/*.ts",
"typecheck": "tsc --noEmit",
"compile": "tsc -p tsconfig.build.json",
"compile-esm": "tsc -p tsconfig.build.json -m es6 --outDir lib-esm",
"copy-declarations": "copyfiles -u 1 src/contracts/**/*.d.ts lib && copyfiles -u 1 src/contracts/**/*.d.ts lib-esm",
"copy-declarations": "OUT=lib npm run copy-declarations:colony && npm run copy-declarations:extensions",
"copy-declarations:colony": "copyfiles -u 1 src/contracts/colony/**/*.d.ts $OUT",
"copy-declarations:extensions": "copyfiles -u 1 src/contracts/extensions/**/*.d.ts $OUT",
"copy-declarations:legacy": "copyfiles -u 1 src/contracts/**/*.d.ts $OUT",
"build-docs": "typedoc --out docs src/index.ts",
"build-contracts": "DISABLE_DOCKER=true npm run build-contracts:docker",
"build-contracts:docker": "ts-node -P scripts/tsconfig-scripts.json scripts/build-contracts.ts",
Expand Down
3 changes: 3 additions & 0 deletions scripts/build-clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
CurrentCoinMachineVersion,
CurrentOneTxPaymentVersion,
CurrentVotingReputationVersion,
CurrentWhitelistVersion,
} from '../src/versions';
import getClientTemplate from './client-templates/extension-client-generator';
import getClientAddonTemplate from './client-templates/extension-client-addons-generator';
Expand All @@ -19,12 +20,14 @@ const extensionContracts = [
Extension.OneTxPayment,
Extension.CoinMachine,
Extension.VotingReputation,
Extension.Whitelist,
];

const currentExtensionsVersions = {
[Extension.OneTxPayment]: CurrentOneTxPaymentVersion,
[Extension.CoinMachine]: CurrentCoinMachineVersion,
[Extension.VotingReputation]: CurrentVotingReputationVersion,
[Extension.Whitelist]: CurrentWhitelistVersion,
};

const getExtensionVersionedPath = (
Expand Down
6 changes: 3 additions & 3 deletions scripts/build-contracts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { resolve as resolvePath } from 'path';
import { copyFileSync } from 'fs';
import { promisify } from 'util';
import * as camelcase from 'camelcase';
import * as execute from 'execa';
Expand All @@ -11,6 +10,7 @@ import {
CurrentCoinMachineVersion,
CurrentOneTxPaymentVersion,
CurrentVotingReputationVersion,
CurrentWhitelistVersion,
} from '../src/versions';
import { Extension } from '../src/clients/Extensions/colonyContractExtensions';

Expand All @@ -25,7 +25,6 @@ const networkDir = resolvePath(__dirname, '../vendor/colonyNetwork');
const relativeBuildDir = 'build/contracts';
const relativeTokenDir = 'lib/colonyToken/build/contracts';
const buildDir = resolvePath(networkDir, relativeBuildDir);
const tokenBuildDir = resolvePath(networkDir, relativeTokenDir);
const vendorTokenDir = resolvePath(__dirname, '../vendor/tokens');

const contractsToBuild = ['IColony', 'IColonyNetwork', 'TokenLocking'];
Expand All @@ -34,12 +33,14 @@ const extensionContracts = [
Extension.OneTxPayment,
Extension.CoinMachine,
Extension.VotingReputation,
Extension.Whitelist,
];

const currentExtensionsVersions = {
[Extension.OneTxPayment]: CurrentOneTxPaymentVersion,
[Extension.CoinMachine]: CurrentCoinMachineVersion,
[Extension.VotingReputation]: CurrentVotingReputationVersion,
[Extension.Whitelist]: CurrentWhitelistVersion,
};

const tokenContracts = [
Expand All @@ -51,7 +52,6 @@ const tokenContracts = [
const version = CurrentColonyVersion;
const outRoot = resolvePath(__dirname, '../src/contracts');
const colonyContractsOutDir = `${outRoot}/colony/${version}`;
const deployDir = `${outRoot}/deploy`;

const provisionNetworkVendor = async (tag: string): Promise<void> => {
if (!tag) {
Expand Down
84 changes: 84 additions & 0 deletions src/clients/Colony/ColonyClientV8.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { Contract, Signer } from 'ethers';
import { Provider } from 'ethers/providers';

import { IColonyFactory as IColonyFactoryV3 } from '../../contracts/3/IColonyFactory';
import { IColonyFactory as IColonyFactoryV4 } from '../../contracts/4/IColonyFactory';
import { IColony__factory as IColonyFactoryV5 } from '../../contracts/5/factories/IColony__factory';
import { IColony__factory as IColonyFactoryV6 } from '../../contracts/colony/6/factories/IColony__factory';
import { IColony__factory as IColonyFactoryV7 } from '../../contracts/colony/7/factories/IColony__factory';
import { IColony__factory as IColonyFactoryV8 } from '../../contracts/colony/8/factories/IColony__factory';
import { IColony } from '../../contracts/colony/8/IColony';
import { IColony as IColonyV6 } from '../../contracts/colony/6/IColony';
import { IColony as PreviousIColony } from '../../contracts/colony/7/IColony';
import { ColonyNetworkClient } from '../ColonyNetworkClient';
import { ExtendedIColony } from './extensions/commonExtensions';
import { ColonyExtensionsV3 } from './extensions/extensionsV3';
import { ColonyExtensionsV4 } from './extensions/extensionsV4';
import { ColonyExtensionsV5 } from './extensions/extensionsV5';
import { ColonyExtensionsV6 } from './extensions/extensionsV6';
import { ColonyExtensionsV7 } from './extensions/extensionsV7';
import {
addExtensions,
ColonyExtensionsV8,
ExtendedEstimateV8,
} from './extensions/extensionsV8';
import { getAllAbiEvents, getAbiFunctions } from '../../utils';
import { ColonyVersion } from '../../versions';

type ColonyExtensions = Omit<
ExtendedIColony<IColony>,
'moveFundsBetweenPotsWithProofs'
> &
ColonyExtensionsV3<IColonyV6> &
ColonyExtensionsV4<IColonyV6> &
ColonyExtensionsV5<IColonyV6> &
ColonyExtensionsV6<IColonyV6> &
ColonyExtensionsV7<PreviousIColony> &
ColonyExtensionsV8<IColony>;

export type ColonyClientV8 = ColonyExtensions & {
clientVersion: ColonyVersion.EbonyLightweightSpaceship;
estimate: ExtendedIColony<IColony>['estimate'] & ExtendedEstimateV8;
};

export default function getColonyClient(
this: ColonyNetworkClient,
address: string,
signerOrProvider: Signer | Provider,
): ColonyClientV8 {
const abiFunctions = getAbiFunctions(
IColonyFactoryV8,
address,
signerOrProvider,
);
/*
* Get all events, including the ones from v3, as well as the current ones
*/
const abiEvents = getAllAbiEvents(
[
IColonyFactoryV8,
IColonyFactoryV7,
IColonyFactoryV6,
IColonyFactoryV5,
IColonyFactoryV4,
IColonyFactoryV3,
],
address,
signerOrProvider,
);

/*
* For this to work we have to create our own instance of the contract, so
* that we can pass in the merged abi events
*/
const colonyClientV8 = (new Contract(
address,
[...abiFunctions, ...abiEvents],
signerOrProvider,
) as unknown) as ColonyClientV8;

colonyClientV8.clientVersion = ColonyVersion.EbonyLightweightSpaceship;
addExtensions(colonyClientV8, this);

return colonyClientV8 as ColonyClientV8;
}
89 changes: 89 additions & 0 deletions src/clients/Colony/ColonyClientV9.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { Contract, Signer } from 'ethers';
import { Provider } from 'ethers/providers';

import { IColonyFactory as IColonyFactoryV3 } from '../../contracts/3/IColonyFactory';
import { IColonyFactory as IColonyFactoryV4 } from '../../contracts/4/IColonyFactory';
import { IColony__factory as IColonyFactoryV5 } from '../../contracts/5/factories/IColony__factory';
import { IColony__factory as IColonyFactoryV6 } from '../../contracts/colony/6/factories/IColony__factory';
import { IColony__factory as IColonyFactoryV7 } from '../../contracts/colony/7/factories/IColony__factory';
import { IColony__factory as IColonyFactoryV8 } from '../../contracts/colony/8/factories/IColony__factory';
import { IColony__factory as IColonyFactoryV9 } from '../../contracts/colony/9/factories/IColony__factory';
import { IColony } from '../../contracts/colony/9/IColony';
import { IColony as IColonyV6 } from '../../contracts/colony/6/IColony';
import { IColony as IColonyV7 } from '../../contracts/colony/7/IColony';
import { IColony as PreviousIColony } from '../../contracts/colony/8/IColony';
import { ColonyNetworkClient } from '../ColonyNetworkClient';
import { ExtendedIColony } from './extensions/commonExtensions';
import { ColonyExtensionsV3 } from './extensions/extensionsV3';
import { ColonyExtensionsV4 } from './extensions/extensionsV4';
import { ColonyExtensionsV5 } from './extensions/extensionsV5';
import { ColonyExtensionsV6 } from './extensions/extensionsV6';
import { ColonyExtensionsV7 } from './extensions/extensionsV7';
import { ColonyExtensionsV8 } from './extensions/extensionsV8';
import {
addExtensions,
ColonyExtensionsV9,
ExtendedEstimateV9,
} from './extensions/extensionsV9';
import { getAllAbiEvents, getAbiFunctions } from '../../utils';
import { ColonyVersion } from '../../versions';

type ColonyExtensions = Omit<
ExtendedIColony<IColony>,
'moveFundsBetweenPotsWithProofs'
> &
ColonyExtensionsV3<IColonyV6> &
ColonyExtensionsV4<IColonyV6> &
ColonyExtensionsV5<IColonyV6> &
ColonyExtensionsV6<IColonyV6> &
ColonyExtensionsV7<IColonyV7> &
ColonyExtensionsV8<PreviousIColony> &
ColonyExtensionsV9<IColony>;

export type ColonyClientV9 = ColonyExtensions & {
clientVersion: ColonyVersion.UnnamedLightweightSpaceship;
estimate: ExtendedIColony<IColony>['estimate'] & ExtendedEstimateV9;
};

export default function getColonyClient(
this: ColonyNetworkClient,
address: string,
signerOrProvider: Signer | Provider,
): ColonyClientV9 {
const abiFunctions = getAbiFunctions(
IColonyFactoryV9,
address,
signerOrProvider,
);
/*
* Get all events, including the ones from v3, as well as the current ones
*/
const abiEvents = getAllAbiEvents(
[
IColonyFactoryV9,
IColonyFactoryV8,
IColonyFactoryV7,
IColonyFactoryV6,
IColonyFactoryV5,
IColonyFactoryV4,
IColonyFactoryV3,
],
address,
signerOrProvider,
);

/*
* For this to work we have to create our own instance of the contract, so
* that we can pass in the merged abi events
*/
const colonyClientV9 = (new Contract(
address,
[...abiFunctions, ...abiEvents],
signerOrProvider,
) as unknown) as ColonyClientV9;

colonyClientV9.clientVersion = ColonyVersion.UnnamedLightweightSpaceship;
addExtensions(colonyClientV9, this);

return colonyClientV9 as ColonyClientV9;
}
Loading

0 comments on commit 45d5dcb

Please sign in to comment.