Skip to content

Commit

Permalink
Merge pull request #538 from JoinColony/maint/support-v11-colony-client
Browse files Browse the repository at this point in the history
Add support for Colony V12 (for the v4.x.x branch)
  • Loading branch information
rdig authored Apr 24, 2024
2 parents a849fe7 + b3a3506 commit 42b3044
Show file tree
Hide file tree
Showing 59 changed files with 79,223 additions and 6,123 deletions.
2 changes: 1 addition & 1 deletion 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.2.1",
"version": "v4.2.2-rc.3",
"main": "lib/index.js",
"module": "lib-esm/index.js",
"files": [
Expand Down
125 changes: 125 additions & 0 deletions src/clients/Colony/ColonyClientV11.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
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__factory as IColonyFactoryV10 } from '../../contracts/colony/10/factories/IColony__factory';
import { IColony__factory as IColonyFactoryV11 } from '../../contracts/colony/11/factories/IColony__factory';

import { IColony as IColonyV6 } from '../../contracts/colony/6/IColony';
import { IColony as IColonyV7 } from '../../contracts/colony/7/IColony';
import { IColony as IColonyV8 } from '../../contracts/colony/8/IColony';
import { IColony as IColonyV9 } from '../../contracts/colony/9/IColony';
import { IColony as PreviousIColony } from '../../contracts/colony/10/IColony';
import { IColony } from '../../contracts/colony/11/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 { ColonyExtensionsV9 } from './extensions/extensionsV9';
import { ColonyExtensionsV10 } from './extensions/extensionsV10';
import {
addExtensions,
ColonyExtensionsV11,
ExtendedEstimateV11,
} from './extensions/extensionsV11';

import { addEncodeInterfaces } from './interfaces/encodeInterfacesV11';

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<IColonyV8> &
ColonyExtensionsV9<IColonyV9> &
ColonyExtensionsV10<PreviousIColony> &
ColonyExtensionsV11<IColony>;

export type ColonyClientV11 = ColonyExtensions & {
clientVersion: ColonyVersion.GreenLightweightSpaceshipTwo;
estimate: ExtendedIColony<IColony>['estimate'] & ExtendedEstimateV11;
};

export default function getColonyClient(
this: ColonyNetworkClient,
address: string,
signerOrProvider: Signer | Provider,
): ColonyClientV11 {
const abiFunctions = getAbiFunctions(
IColonyFactoryV11,
address,
signerOrProvider,
);
/*
* Get all events, including the ones from v3, as well as the current ones
*/
const abiEvents = getAllAbiEvents(
[
IColonyFactoryV11,
IColonyFactoryV10,
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 customEthersContractInstace = (new Contract(
address,
[...abiFunctions, ...abiEvents],
signerOrProvider,
) as unknown) as ColonyClientV11;

/*
* We need to clone the Ethers intance otherwise props, which we may
* want appent or overwrite, won't work since Ethers marks their props
* as read-only and non-configurable by default
*
* @TODO All of this should be extracted as an util to remove code repetition
* when creating new Colony version clients
*/
const colonyClientV11 = {
...customEthersContractInstace,
interface: {
...customEthersContractInstace.interface,
/*
* Manually assign non-enumerable props
*/
parseLog: customEthersContractInstace.interface.parseLog,
parseTransaction: customEthersContractInstace.interface.parseTransaction,
},
} as ColonyClientV11;
colonyClientV11.clientVersion = ColonyVersion.GreenLightweightSpaceshipTwo;

addExtensions(colonyClientV11, this);
addEncodeInterfaces(colonyClientV11);

return colonyClientV11;
}
134 changes: 134 additions & 0 deletions src/clients/Colony/ColonyClientV12.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
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__factory as IColonyFactoryV10 } from '../../contracts/colony/10/factories/IColony__factory';
import { IColony__factory as IColonyFactoryV11 } from '../../contracts/colony/11/factories/IColony__factory';
import { IColony__factory as IColonyFactoryV12 } from '../../contracts/colony/12/factories/IColony__factory';

import { IColony as IColonyV6 } from '../../contracts/colony/6/IColony';
import { IColony as IColonyV7 } from '../../contracts/colony/7/IColony';
import { IColony as IColonyV8 } from '../../contracts/colony/8/IColony';
import { IColony as IColonyV9 } from '../../contracts/colony/9/IColony';
import { IColony as IColonyV10 } from '../../contracts/colony/10/IColony';
import { IColony as PreviousIColony } from '../../contracts/colony/11/IColony';
import { IColony } from '../../contracts/colony/12/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 { ColonyExtensionsV9 } from './extensions/extensionsV9';
import { ColonyExtensionsV10 } from './extensions/extensionsV10';
import { ColonyExtensionsV11 } from './extensions/extensionsV11';
import {
addExtensions,
ColonyExtensionsV12,
ExtendedEstimateV12,
} from './extensions/extensionsV12';

import { addEncodeInterfaces } from './interfaces/encodeInterfacesV12';

import { getAllAbiEvents, getAbiFunctions } from '../../utils';
import { ColonyVersion } from '../../versions';

// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
type ColonyExtensions = Omit<
ExtendedIColony<IColony>,
'moveFundsBetweenPotsWithProofs'
> &
ColonyExtensionsV3<IColonyV6> &
ColonyExtensionsV4<IColonyV6> &
ColonyExtensionsV5<IColonyV6> &
ColonyExtensionsV6<IColonyV6> &
ColonyExtensionsV7<IColonyV7> &
ColonyExtensionsV8<IColonyV8> &
ColonyExtensionsV9<IColonyV9> &
ColonyExtensionsV10<IColonyV10> &
ColonyExtensionsV11<PreviousIColony> &
ColonyExtensionsV12<IColony>;

// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
export type ColonyClientV12 = ColonyExtensions & {
clientVersion: ColonyVersion.GreenLightweightSpaceshipThree;
estimate: ExtendedIColony<IColony>['estimate'] & ExtendedEstimateV12;
};

export default function getColonyClient(
this: ColonyNetworkClient,
address: string,
signerOrProvider: Signer | Provider,
): ColonyClientV12 {
const abiFunctions = getAbiFunctions(
IColonyFactoryV12,
address,
signerOrProvider,
);
/*
* Get all events, including the ones from v3, as well as the current ones
*/
const abiEvents = getAllAbiEvents(
[
IColonyFactoryV12,
IColonyFactoryV11,
IColonyFactoryV10,
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 customEthersContractInstace = (new Contract(
address,
[...abiFunctions, ...abiEvents],
signerOrProvider,
) as unknown) as ColonyClientV12;

/*
* We need to clone the Ethers intance otherwise props, which we may
* want appent or overwrite, won't work since Ethers marks their props
* as read-only and non-configurable by default
*
* @TODO All of this should be extracted as an util to remove code repetition
* when creating new Colony version clients
*/
const colonyClientV12 = {
...customEthersContractInstace,
interface: {
...customEthersContractInstace.interface,
/*
* Manually assign non-enumerable props
*/
parseLog: customEthersContractInstace.interface.parseLog,
parseTransaction: customEthersContractInstace.interface.parseTransaction,
},
} as ColonyClientV12;
colonyClientV12.clientVersion = ColonyVersion.GreenLightweightSpaceshipThree;

addExtensions(colonyClientV12, this);
addEncodeInterfaces(colonyClientV12);

return colonyClientV12;
}
6 changes: 5 additions & 1 deletion src/clients/Colony/extensions/commonExtensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { IColony as IColonyV7 } from '../../../contracts/colony/7/IColony';
import { IColony as IColonyV8 } from '../../../contracts/colony/8/IColony';
import { IColony as IColonyV9 } from '../../../contracts/colony/9/IColony';
import { IColony as IColonyV10 } from '../../../contracts/colony/10/IColony';
import { IColony as IColonyV11 } from '../../../contracts/colony/11/IColony';
import { IColony as IColonyV12 } from '../../../contracts/colony/12/IColony';
import { TransactionOverrides } from '../../../contracts/6';
import { IColonyFactory } from '../../../contracts/4/IColonyFactory';

Expand Down Expand Up @@ -49,7 +51,9 @@ type AnyIColony =
| IColonyV7
| IColonyV8
| IColonyV9
| IColonyV10;
| IColonyV10
| IColonyV11
| IColonyV12;

// This is exposed to type the awkward recovery event client which is basically
// just an IColonyV4
Expand Down
59 changes: 59 additions & 0 deletions src/clients/Colony/extensions/extensionsV11.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { IColony as IColonyV6 } from '../../../contracts/colony/6/IColony';
import { IColony as IColonyV7 } from '../../../contracts/colony/7/IColony';
import { IColony as IColonyV8 } from '../../../contracts/colony/8/IColony';
import { IColony as IColonyV9 } from '../../../contracts/colony/9/IColony';
import { IColony as PreviousIColony } from '../../../contracts/colony/10/IColony';
import { IColony as IColonyV11 } from '../../../contracts/colony/11/IColony';
import { ColonyNetworkClient } from '../../ColonyNetworkClient';
import { ExtendedIColony } from './commonExtensions';
import { ColonyExtensionsV3 } from './extensionsV3';
import { ColonyExtensionsV4 } from './extensionsV4';
import { ColonyExtensionsV5 } from './extensionsV5';
import { ColonyExtensionsV6 } from './extensionsV6';
import { ColonyExtensionsV7 } from './extensionsV7';
import { ColonyExtensionsV8 } from './extensionsV8';
import { ColonyExtensionsV9 } from './extensionsV9';
import {
addExtensions as addExtensionsV10,
ColonyExtensionsV10,
ExtendedEstimateV10,
} from './extensionsV10';

type ValidColony = IColonyV11;

type PreviousVersionsExtensions = ExtendedIColony<ValidColony> &
ColonyExtensionsV3<IColonyV6> &
ColonyExtensionsV4<IColonyV6> &
ColonyExtensionsV5<IColonyV6> &
ColonyExtensionsV6<IColonyV6> &
ColonyExtensionsV7<IColonyV7> &
ColonyExtensionsV8<IColonyV8> &
ColonyExtensionsV9<IColonyV9> &
ColonyExtensionsV10<PreviousIColony>;

/*
* Estimates
*/
export type ExtendedEstimateV11 = ExtendedEstimateV10;

/*
* Extension Methods
*/
export type ColonyExtensionsV11<
T extends ValidColony
> = {} & PreviousVersionsExtensions;

/*
* Bindings
*/
export const addExtensions = (
instance: ExtendedIColony<ValidColony>,
networkClient: ColonyNetworkClient,
): ColonyExtensionsV11<ValidColony> => {
// Add all extensions from v7, because these are also still valid
const extendedInstance = addExtensionsV10(
instance as PreviousVersionsExtensions,
networkClient,
) as ColonyExtensionsV11<ValidColony>;
return extendedInstance;
};
Loading

0 comments on commit 42b3044

Please sign in to comment.