|
| 1 | +import { Contract, Signer } from 'ethers'; |
| 2 | +import { Provider } from 'ethers/providers'; |
| 3 | + |
| 4 | +import { IColonyFactory as IColonyFactoryV3 } from '../../contracts/3/IColonyFactory'; |
| 5 | +import { IColonyFactory as IColonyFactoryV4 } from '../../contracts/4/IColonyFactory'; |
| 6 | +import { IColony__factory as IColonyFactoryV5 } from '../../contracts/5/factories/IColony__factory'; |
| 7 | +import { IColony__factory as IColonyFactoryV6 } from '../../contracts/colony/6/factories/IColony__factory'; |
| 8 | +import { IColony__factory as IColonyFactoryV7 } from '../../contracts/colony/7/factories/IColony__factory'; |
| 9 | +import { IColony__factory as IColonyFactoryV8 } from '../../contracts/colony/8/factories/IColony__factory'; |
| 10 | +import { IColony__factory as IColonyFactoryV9 } from '../../contracts/colony/9/factories/IColony__factory'; |
| 11 | +import { IColony__factory as IColonyFactoryV10 } from '../../contracts/colony/10/factories/IColony__factory'; |
| 12 | +import { IColony__factory as IColonyFactoryV11 } from '../../contracts/colony/11/factories/IColony__factory'; |
| 13 | +import { IColony__factory as IColonyFactoryV12 } from '../../contracts/colony/12/factories/IColony__factory'; |
| 14 | +import { IColony__factory as IColonyFactoryV13 } from '../../contracts/colony/13/factories/IColony__factory'; |
| 15 | + |
| 16 | +import { IColony as IColonyV6 } from '../../contracts/colony/6/IColony'; |
| 17 | +import { IColony as IColonyV7 } from '../../contracts/colony/7/IColony'; |
| 18 | +import { IColony as IColonyV8 } from '../../contracts/colony/8/IColony'; |
| 19 | +import { IColony as IColonyV9 } from '../../contracts/colony/9/IColony'; |
| 20 | +import { IColony as IColonyV10 } from '../../contracts/colony/10/IColony'; |
| 21 | +import { IColony as IColonyV11 } from '../../contracts/colony/11/IColony'; |
| 22 | +import { IColony as PreviousIColony } from '../../contracts/colony/12/IColony'; |
| 23 | +import { IColony } from '../../contracts/colony/13/IColony'; |
| 24 | + |
| 25 | +import { ColonyNetworkClient } from '../ColonyNetworkClient'; |
| 26 | +import { ExtendedIColony } from './extensions/commonExtensions'; |
| 27 | +import { ColonyExtensionsV3 } from './extensions/extensionsV3'; |
| 28 | +import { ColonyExtensionsV4 } from './extensions/extensionsV4'; |
| 29 | +import { ColonyExtensionsV5 } from './extensions/extensionsV5'; |
| 30 | +import { ColonyExtensionsV6 } from './extensions/extensionsV6'; |
| 31 | +import { ColonyExtensionsV7 } from './extensions/extensionsV7'; |
| 32 | +import { ColonyExtensionsV8 } from './extensions/extensionsV8'; |
| 33 | +import { ColonyExtensionsV9 } from './extensions/extensionsV9'; |
| 34 | +import { ColonyExtensionsV10 } from './extensions/extensionsV10'; |
| 35 | +import { ColonyExtensionsV11 } from './extensions/extensionsV11'; |
| 36 | +import { ColonyExtensionsV12 } from './extensions/extensionsV12'; |
| 37 | + |
| 38 | +import { |
| 39 | + addExtensions, |
| 40 | + ColonyExtensionsV13, |
| 41 | + ExtendedEstimateV13, |
| 42 | +} from './extensions/extensionsV13'; |
| 43 | + |
| 44 | +import { addEncodeInterfaces } from './interfaces/encodeInterfacesV13'; |
| 45 | + |
| 46 | +import { getAllAbiEvents, getAbiFunctions } from '../../utils'; |
| 47 | +import { ColonyVersion } from '../../versions'; |
| 48 | + |
| 49 | +type ColonyExtensions = Omit< |
| 50 | + ExtendedIColony<IColony>, |
| 51 | + 'moveFundsBetweenPotsWithProofs' |
| 52 | +> & |
| 53 | + ColonyExtensionsV3<IColonyV6> & |
| 54 | + ColonyExtensionsV4<IColonyV6> & |
| 55 | + ColonyExtensionsV5<IColonyV6> & |
| 56 | + ColonyExtensionsV6<IColonyV6> & |
| 57 | + ColonyExtensionsV7<IColonyV7> & |
| 58 | + ColonyExtensionsV8<IColonyV8> & |
| 59 | + ColonyExtensionsV9<IColonyV9> & |
| 60 | + ColonyExtensionsV10<IColonyV10> & |
| 61 | + ColonyExtensionsV11<IColonyV11> & |
| 62 | + ColonyExtensionsV12<PreviousIColony> & |
| 63 | + ColonyExtensionsV13<IColony>; |
| 64 | + |
| 65 | +export type ColonyClientV13 = ColonyExtensions & { |
| 66 | + clientVersion: ColonyVersion.GreenLightweightSpaceshipThree; |
| 67 | + estimate: ExtendedIColony<IColony>['estimate'] & ExtendedEstimateV13; |
| 68 | +}; |
| 69 | + |
| 70 | +export default function getColonyClient( |
| 71 | + this: ColonyNetworkClient, |
| 72 | + address: string, |
| 73 | + signerOrProvider: Signer | Provider, |
| 74 | +): ColonyClientV13 { |
| 75 | + const abiFunctions = getAbiFunctions( |
| 76 | + IColonyFactoryV13, |
| 77 | + address, |
| 78 | + signerOrProvider, |
| 79 | + ); |
| 80 | + /* |
| 81 | + * Get all events, including the ones from v3, as well as the current ones |
| 82 | + */ |
| 83 | + const abiEvents = getAllAbiEvents( |
| 84 | + [ |
| 85 | + IColonyFactoryV13, |
| 86 | + IColonyFactoryV12, |
| 87 | + IColonyFactoryV11, |
| 88 | + IColonyFactoryV10, |
| 89 | + IColonyFactoryV9, |
| 90 | + IColonyFactoryV8, |
| 91 | + IColonyFactoryV7, |
| 92 | + IColonyFactoryV6, |
| 93 | + IColonyFactoryV5, |
| 94 | + IColonyFactoryV4, |
| 95 | + IColonyFactoryV3, |
| 96 | + ], |
| 97 | + address, |
| 98 | + signerOrProvider, |
| 99 | + ); |
| 100 | + |
| 101 | + /* |
| 102 | + * For this to work we have to create our own instance of the contract, so |
| 103 | + * that we can pass in the merged abi events |
| 104 | + */ |
| 105 | + const customEthersContractInstace = (new Contract( |
| 106 | + address, |
| 107 | + [...abiFunctions, ...abiEvents], |
| 108 | + signerOrProvider, |
| 109 | + ) as unknown) as ColonyClientV13; |
| 110 | + |
| 111 | + /* |
| 112 | + * We need to clone the Ethers intance otherwise props, which we may |
| 113 | + * want appent or overwrite, won't work since Ethers marks their props |
| 114 | + * as read-only and non-configurable by default |
| 115 | + * |
| 116 | + * @TODO All of this should be extracted as an util to remove code repetition |
| 117 | + * when creating new Colony version clients |
| 118 | + */ |
| 119 | + const colonyClientV13 = { |
| 120 | + // eslint-disable-next-line @typescript-eslint/ban-ts-ignore |
| 121 | + // @ts-ignore |
| 122 | + ...customEthersContractInstace, |
| 123 | + interface: { |
| 124 | + ...customEthersContractInstace.interface, |
| 125 | + /* |
| 126 | + * Manually assign non-enumerable props |
| 127 | + */ |
| 128 | + parseLog: customEthersContractInstace.interface.parseLog, |
| 129 | + parseTransaction: customEthersContractInstace.interface.parseTransaction, |
| 130 | + }, |
| 131 | + } as ColonyClientV13; |
| 132 | + colonyClientV13.clientVersion = ColonyVersion.GreenLightweightSpaceshipThree; |
| 133 | + |
| 134 | + addExtensions(colonyClientV13, this); |
| 135 | + addEncodeInterfaces(colonyClientV13); |
| 136 | + |
| 137 | + return colonyClientV13; |
| 138 | +} |
0 commit comments