Skip to content

Commit

Permalink
feat: use the colony creation salt instead of calling the network to …
Browse files Browse the repository at this point in the history
…get the salt
  • Loading branch information
bassgeta committed Dec 19, 2024
1 parent e981891 commit 3f616d8
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 53 deletions.
4 changes: 2 additions & 2 deletions amplify/backend/api/colonycdapp/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1539,9 +1539,9 @@ type ColonyCreateEvent {
"""
blockNumber: Int!
"""
The address that signed the transaction
The salt used during creation
"""
signerAddress: String!
creationSalt: String!
}

"""
Expand Down
2 changes: 1 addition & 1 deletion docker/colony-cdapp-dev-env-block-ingestor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM colony-cdapp-dev-env/base:latest

ENV BLOCK_INGESTOR_HASH=9f9904afa30c7401f365e9e8e972d18d93e68cd4
ENV BLOCK_INGESTOR_HASH=93f5d6c2636b2cea91287da15f9d55a00cf2ea5a

# Declare volumes to set up metadata
VOLUME [ "/colonyCDapp/amplify/mock-data" ]
Expand Down
4 changes: 2 additions & 2 deletions docker/colony-cdapp-dev-env-proxy-block-ingestor
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM colony-cdapp-dev-env/base:latest

# @TODO maybe add a PROXY_BLOCK_INGESTOR_HASH and fallback to BLOCK_INGESTOR_HASH
ENV BLOCK_INGESTOR_HASH=9f9904afa30c7401f365e9e8e972d18d93e68cd4
ENV BLOCK_INGESTOR_HASH=93f5d6c2636b2cea91287da15f9d55a00cf2ea5a
# @TODO do we need here a contract to be in the format:
# {
# name: 'ColonyNetwork',
Expand Down Expand Up @@ -49,7 +49,7 @@ RUN npm i -g [email protected]
RUN pnpm install --frozen-lockfile

# Compile JS files
RUN pnpm --filter @joincolony/proxy-chain run build
RUN pnpm --filter @joincolony/proxy-chain run build

WORKDIR /colonyCDappBackend

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ export const TmpProxyColonyDeploy = () => {

await createProxyColony({
colonyAddress: colony.colonyAddress,
signerAddress: colony.colonyCreateEvent.signerAddress,
blockNumber: colony.colonyCreateEvent.blockNumber,
creationSalt: colony.colonyCreateEvent.creationSalt,
foreignChainId: chainId,
});
};
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/fragments/colony.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fragment Colony on Colony {
name
colonyCreateEvent {
blockNumber
signerAddress
creationSalt
}
nativeToken {
...Token
Expand Down
28 changes: 14 additions & 14 deletions src/graphql/generated.ts

Large diffs are not rendered by default.

35 changes: 6 additions & 29 deletions src/redux/sagas/proxyColonies/createProxyColony.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { ClientType } from '@colony/colony-js';
import { type CustomContract } from '@colony/sdk';
import { utils, providers } from 'ethers';
import { call, put, takeEvery } from 'redux-saga/effects';
import { utils } from 'ethers';
import { put, takeEvery } from 'redux-saga/effects';

import { GANACHE_LOCAL_RPC_URL, isDev } from '~constants';
import { colonyAbi } from '~constants/abis.ts';
import { ContextModule, getContext } from '~context/index.ts';
import { type Action, ActionTypes, type AllActions } from '~redux';
Expand All @@ -17,18 +16,14 @@ import { addTransactionToDb } from '~state/transactionState.ts';
import { TransactionStatus } from '~types/graphql.ts';
import { TRANSACTION_METHODS } from '~types/transactions.ts';

import {
getColonyManager,
getNetworkClient,
putError,
} from '../utils/index.ts';
import { getColonyManager, putError } from '../utils/index.ts';

export type CreateProxyColonyPayload =
Action<ActionTypes.PROXY_COLONY_CREATE>['payload'];

// @TODO if metatx are enabled sent a metaTx instead of tx
function* createProxyColony({
payload: { colonyAddress, signerAddress, blockNumber, foreignChainId },
payload: { colonyAddress, creationSalt, foreignChainId },
meta,
}: Action<ActionTypes.PROXY_COLONY_CREATE>) {
const batchKey = TRANSACTION_METHODS.CreateProxyColony;
Expand All @@ -38,28 +33,10 @@ function* createProxyColony({

const walletAddress = utils.getAddress(address);

const provider = (() => {
if (isDev) {
return new providers.StaticJsonRpcProvider(GANACHE_LOCAL_RPC_URL);
}
return new providers.Web3Provider(window.ethereum!);
})();

/**
* For the networkClient.getColonyCreationSalt to properly work when passing the `from` value
* We need to instantiate the ColonyNetworkClient using a provider
*/
const networkClient = yield call(getNetworkClient, provider);

try {
const generatedColonySalt = yield networkClient.getColonyCreationSalt({
blockTag: blockNumber,
from: signerAddress,
});

const proxyColonyContract: CustomContract<typeof colonyAbi> =
colonyManager.getCustomContract(colonyAddress, colonyAbi);
const params = [foreignChainId, generatedColonySalt];
const params = [foreignChainId, creationSalt];

yield addTransactionToDb(meta.id, {
context: ClientType.ColonyClient, // @NOTE we want to add a new context type
Expand All @@ -78,7 +55,7 @@ function* createProxyColony({
const [transaction, waitForMined] = yield proxyColonyContract
.createTxCreator('createProxyColony', [
BigInt(foreignChainId),
generatedColonySalt,
creationSalt,
{
gasLimit: BigInt(10_000_000),
},
Expand Down
3 changes: 1 addition & 2 deletions src/redux/types/actions/proxyColonies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ export type ProxyColoniesActionTypes =
ActionTypes.PROXY_COLONY_CREATE,
{
colonyAddress: Address;
signerAddress: Address;
blockNumber: number;
foreignChainId: number;
creationSalt: string;
},
object
>
Expand Down

0 comments on commit 3f616d8

Please sign in to comment.