Skip to content

Commit

Permalink
feat: add method to get a CustomContract in ColonyManager
Browse files Browse the repository at this point in the history
  • Loading branch information
chmanie committed Oct 30, 2024
1 parent a4be8f4 commit 6c2ab06
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 48 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ cypress/screenshots
/playwright-report/
/blob-report/
/playwright/.cache/
/network-files

.vscode
.DS_Store
Expand Down
8 changes: 1 addition & 7 deletions docker/colony-cdapp-dev-env-orchestration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ services:
- 'amplify-mock-data:/mock-data'
- '../amplify/backend/:/backend-repo'
command: '/bin/bash -c "rm -rf /backend/* && rm -rf /mock-data/* && touch /backend/.initialized && touch /mock-data/.initialized && cp -r /backend-repo/* /backend/ && chown -R $(id -u node):$(id -g node) /backend && chown -R $(id -u node):$(id -g node) /mock-data"'

network-contracts:
container_name: 'network'
image: colony-cdapp-dev-env/network:latest
volumes:
- 'amplify-mock-data:/colonyCDapp/amplify/mock-data'
- '../network-files/:/colonyCDappBackend/colonyNetwork/artifacts'
ports:
- '8545:8545'
- '3002:3002'
Expand All @@ -25,7 +25,6 @@ services:
depends_on:
amplify-setup:
condition: service_completed_successfully

reputation-monitor:
container_name: 'monitor'
image: colony-cdapp-dev-env/reputation-monitor:latest
Expand All @@ -36,7 +35,6 @@ services:
depends_on:
network-contracts:
condition: service_healthy

block-ingestor:
container_name: 'ingestor'
image: colony-cdapp-dev-env/block-ingestor:latest
Expand All @@ -49,7 +47,6 @@ services:
condition: service_healthy
amplify:
condition: service_healthy

amplify:
container_name: 'amplify'
image: colony-cdapp-dev-env/amplify:latest
Expand All @@ -73,7 +70,6 @@ services:
test: ['CMD', 'curl', '-f', 'http://localhost:9200']
interval: 5s
retries: 1000

auth-proxy:
container_name: 'auth'
image: colony-cdapp-dev-env/auth-proxy:latest
Expand All @@ -82,7 +78,6 @@ services:
depends_on:
amplify:
condition: service_healthy

network-files:
container_name: 'network-files'
image: colony-cdapp-dev-env/base:latest
Expand All @@ -94,7 +89,6 @@ services:
depends_on:
network-contracts:
condition: service_healthy

volumes:
amplify-backend:
amplify-mock-data:
104 changes: 67 additions & 37 deletions package-lock.json

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

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"postinstall": "if [ -z \"$SKIP_HOOKS\" ]; then ./scripts/lambda-functions-dependencies.sh && scripts/generate-amplify-local-config.sh; fi",
"watch-amplify": "node scripts/watchAmplifyFiles",
"forward-time": "node scripts/forward-time",
"playwright:install": "npx playwright install --with-deps",
"playwright:install": "npx playwright install --with-deps",
"playwright:run": "playwright test",
"playwright:watch": "playwright test --ui"
},
Expand Down Expand Up @@ -149,10 +149,11 @@
},
"dependencies": {
"@apollo/client": "3.7.14",
"@colony/abis": "1.5.0",
"@colony/colony-js": "^7.2.0",
"@colony/events": "3.0.0",
"@colony/abis": "^1.6.0",
"@colony/colony-js": "^8.0.0-next.0",
"@colony/events": "^4.0.0-next.0",
"@colony/redux-promise-listener": "^1.2.0",
"@colony/sdk": "^3.0.0-next.0",
"@colony/unicode-confusables-noascii": "^0.1.2",
"@hookform/resolvers": "^2.9.10",
"@phosphor-icons/react": "^2.1.5",
Expand Down
37 changes: 37 additions & 0 deletions src/context/ColonyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,22 @@ import {
type AnyColonyClient,
type AnyMultisigPermissionsClient,
} from '@colony/colony-js';
import { type Abi, CustomContract } from '@colony/sdk';
import { ContractConfig } from '@colony/sdk/dist/types/ContractConfig';
import { type Signer, type providers } from 'ethers';

import { DEFAULT_NETWORK } from '~constants/index.ts';
import { type Address } from '~types/index.ts';
import { ColonyJSNetworkMapping } from '~types/network.ts';
import { isAddress } from '~utils/web3/index.ts';

export default class ColonyManager {
private metaColonyClient?: any;

colonyClients: Map<Address, Promise<any>>;

customContracts: Map<Address, CustomContract<any>>;

extensionClients: Map<string, Promise<ExtensionClient>>;

tokenClients: Map<Address, Promise<TokenClient>>;
Expand All @@ -38,6 +44,7 @@ export default class ColonyManager {
this.extensionClients = new Map();
this.tokenClients = new Map();
this.tokenLockingClients = new Map();
this.customContracts = new Map();
this.networkClient = networkClient;
this.provider = networkClient.provider;
this.signer = networkClient.signer;
Expand Down Expand Up @@ -252,4 +259,34 @@ export default class ColonyManager {
}
return clientPromise;
}

/*
* Get a custom colony contract by address and ABI (using Colony SDK)
*
* @example
* ```ts
* import { abi as colonyNetworkAbi } from '../../network-files/contracts/colonyNetwork/ColonyNetwork.sol/ColonyNetwork.json';
* const networkAddress = import.meta.env.NETWORK_CONTRACT_ADDRESS || ColonyNetworkAddress[DEFAULT_NETWORK];
* const customColonyNetwork = colonyManager.getCustomContract(networkAddress, colonyNetworkAbi);
* ```
*/
getCustomContract<A extends Abi>(address: string, abi: A): CustomContract<A> {
const reputationOracleEndpoint = import.meta.env.REPUTATION_ORACLE_ENDPOINT
? new URL(import.meta.env.REPUTATION_ORACLE_ENDPOINT)
: new URL(`/reputation`, window.location.origin);

const metaTxBroadcasterEndpoint = `${import.meta.env.METATX_BROADCASTER_ENDPOINT}/broadcast`;

const config = new ContractConfig(this.signer || this.provider, {
metaTxBroadcasterEndpoint,
network: ColonyJSNetworkMapping[DEFAULT_NETWORK],
reputationOracleEndpoint: reputationOracleEndpoint.toString(),
});

if (this.customContracts.has(address)) {
return this.customContracts.get(address) as CustomContract<A>;
}

return new CustomContract(address as `0x${string}`, abi, config);
}
}
2 changes: 2 additions & 0 deletions src/redux/sagas/utils/getNetworkClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const getNetworkClient = async (signerOrProvider?: SignerOrProvider) => {
return getColonyNetworkClient(ColonyJSNetwork.Custom, signer, {
networkAddress,
reputationOracleEndpoint: reputationOracleUrl.href,
disableVersionCheck: true,
});
}

Expand All @@ -58,6 +59,7 @@ const getNetworkClient = async (signerOrProvider?: SignerOrProvider) => {
import.meta.env.NETWORK_CONTRACT_ADDRESS ||
ColonyNetworkAddress[network],
reputationOracleEndpoint: reputationOracleUrl.href,
disableVersionCheck: true,
},
);
};
Expand Down

0 comments on commit 6c2ab06

Please sign in to comment.