Skip to content

Commit

Permalink
feat: factor out ContractConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
chmanie committed Oct 24, 2024
1 parent 176b095 commit dcb1d3f
Show file tree
Hide file tree
Showing 22 changed files with 181 additions and 234 deletions.
2 changes: 1 addition & 1 deletion packages/sdk/examples/node/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ const provider = new providers.JsonRpcProvider(ColonyRpcEndpoint.ArbitrumOne);
const start = async () => {
const colonyNetwork = new ColonyNetwork(provider);
const usdc = new CustomContract(
colonyNetwork,
'0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
erc20Abi,
colonyNetwork.config,
);
const metaColonyAddress = await colonyNetwork
.getInternalNetworkContract()
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@
"@colony/core": "^2.3.0",
"@colony/events": "^3.0.0",
"@colony/tokens": "^0.3.0",
"@ethersproject/abstract-provider": "^5.7.0",
"abitype": "^1.0.6"
},
"devDependencies": {
"@colony/contractor": "^2.2.0",
"@ethersproject/abi": "^5.7.0",
"@ethersproject/abstract-provider": "^5.7.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@picocss/pico": "^1.5.7",
Expand Down
23 changes: 15 additions & 8 deletions packages/sdk/src/ColonyNetwork/Colony.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import { type ColonyNetwork } from './ColonyNetwork.js';
import { OneTxPayment } from './OneTxPayment.js';
import { ERC20Token, type Token, getToken } from './tokens/index.js';
import { VotingReputation } from './VotingReputation.js';
import { type ContractConfig } from '../ContractConfig.js';

export type SupportedColonyContract =
| ColonyContract11
Expand Down Expand Up @@ -108,7 +109,7 @@ export class Colony {
static async connect(colonyNetwork: ColonyNetwork, address: string) {
const version = (await getContractVersion(
address,
colonyNetwork.signerOrProvider,
colonyNetwork.config.signerOrProvider,
)) as ColonyVersion;

const Factory = Colony.supportedVersions.find(
Expand All @@ -123,7 +124,7 @@ export class Colony {

const colonyContract = Factory.connect(
address,
colonyNetwork.signerOrProvider,
colonyNetwork.config.signerOrProvider,
);

const tokenAddress = await colonyContract.getToken();
Expand Down Expand Up @@ -152,6 +153,11 @@ export class Colony {
*/
address: string;

/**
* The colony's contract config (taken from ColonyNetwork)
*/
config: ContractConfig;

/**
* A shortcut to the {@link ColonyNetwork} instance
*/
Expand Down Expand Up @@ -212,6 +218,7 @@ export class Colony {
) {
this.colony = colony;
this.colonyNetwork = colonyNetwork;
this.config = colonyNetwork.config;
this.address = colony.address;
this.ext = {};
this.reputation = new ReputationClient(
Expand Down Expand Up @@ -252,7 +259,7 @@ export class Colony {
) {
return new ColonyTxCreator({
colony: this,
colonyNetwork: this.colonyNetwork,
config: this.colonyNetwork.config,
contract,
method,
args,
Expand Down Expand Up @@ -292,7 +299,7 @@ export class Colony {
) {
return new ColonyTxCreator({
colony: this,
colonyNetwork: this.colonyNetwork,
config: this.colonyNetwork.config,
contract,
method,
args,
Expand Down Expand Up @@ -428,7 +435,7 @@ export class Colony {
if (typeof metadata == 'string') {
cid = metadata;
} else {
cid = await this.colonyNetwork.ipfs.uploadMetadata(
cid = await this.config.ipfs.uploadMetadata(
MetadataType.Colony,
metadata,
);
Expand Down Expand Up @@ -569,7 +576,7 @@ export class Colony {
if (typeof metadata == 'string') {
cid = metadata;
} else {
cid = await this.colonyNetwork.ipfs.uploadMetadata(
cid = await this.config.ipfs.uploadMetadata(
MetadataType.Domain,
metadata,
);
Expand Down Expand Up @@ -654,7 +661,7 @@ export class Colony {
if (typeof metadata == 'string') {
cid = metadata;
} else {
cid = await this.colonyNetwork.ipfs.uploadMetadata(
cid = await this.config.ipfs.uploadMetadata(
MetadataType.Domain,
metadata,
);
Expand Down Expand Up @@ -1056,7 +1063,7 @@ export class Colony {
if (typeof metadata == 'string') {
cid = metadata;
} else {
cid = await this.colonyNetwork.ipfs.uploadMetadata(
cid = await this.config.ipfs.uploadMetadata(
MetadataType.Annotation,
metadata,
);
Expand Down
Loading

0 comments on commit dcb1d3f

Please sign in to comment.