Skip to content

Commit

Permalink
Merge pull request #3966 from JoinColony/feat/3875-improve-arbitrary-…
Browse files Browse the repository at this point in the history
…txs-decoding

[Arbitrary txs] Improve function data decoding
  • Loading branch information
jakubcolony authored Dec 19, 2024
2 parents 76570c4 + 589f154 commit 592933d
Show file tree
Hide file tree
Showing 35 changed files with 188 additions and 87 deletions.
18 changes: 9 additions & 9 deletions amplify/backend/api/colonycdapp/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3544,6 +3544,15 @@ type ExpenditureSlotChanges {
type ColonyActionMetadata @model {
id: ID!
customTitle: String!
"""
In case of arbitrary transaction actions, stores the array of ABIs used to encode the transactions
"""
arbitraryTxAbis: [ArbitraryTxAbi!]
}

type ArbitraryTxAbi {
contractAddress: String!
jsonAbi: String!
}

type ColonyDecision @model {
Expand Down Expand Up @@ -3595,20 +3604,11 @@ type ColonyActionRoles {
role_6: Boolean
}

type ArbitraryTransactionMethodArg {
value: String!
name: String
type: String!
}

"""
Colony Arbitrary transaction that can be involved in an action
"""
type ColonyActionArbitraryTransaction {
contractAddress: String!
method: String
methodSignature: String
args: [ArbitraryTransactionMethodArg!]
encodedFunction: 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=64e20a1a16df48a72bb5d65924495aa82ef4622e
ENV BLOCK_INGESTOR_HASH=8b3c23b0154ef1487c3b13df5b2f2d0d5a093f39

# Declare volumes to set up metadata
VOLUME [ "/colonyCDapp/amplify/mock-data" ]
Expand Down
2 changes: 0 additions & 2 deletions docker/files/block-ingestor/env.base
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@ AWS_APPSYNC_ENDPOINT=http://amplify:20002/graphql
AWS_APPSYNC_KEY=da2-fakeApiId123456

NODE_ENV=development

FOUR_BYTE_API_URL=https://www.4byte.directory/api/v1
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { type FC } from 'react';

import MaskedAddress from '~shared/MaskedAddress/MaskedAddress.tsx';
import { type ColonyAction } from '~types/graphql.ts';
import { decodeArbitraryTransaction } from '~utils/arbitraryTxs.ts';

interface ArbitraryTransactionProps {
action: ColonyAction;
Expand All @@ -9,7 +11,46 @@ interface ArbitraryTransactionProps {
const ArbitraryTransaction: FC<ArbitraryTransactionProps> = ({ action }) => {
// eslint-disable-next-line no-console
console.log('action:', action);
return <div>in progress</div>;

return (
<div className="flex flex-col gap-4">
{action.arbitraryTransactions?.map((transaction) => {
const abi = action.metadata?.arbitraryTxAbis?.find(
(abiItem) => abiItem.contractAddress === transaction.contractAddress,
);

if (!abi) {
return <div>No ABI found</div>;
}

const decodedTx = decodeArbitraryTransaction(
abi.jsonAbi,
transaction.encodedFunction,
);

if (!decodedTx) {
return <div>Failed to decode transaction</div>;
}

return (
<div className="flex flex-col gap-2 border-b-2">
<div>
Contract address:
<MaskedAddress address={transaction.contractAddress} />
</div>
Method: {decodedTx.method}
{decodedTx.args?.map((arg) => {
return (
<div key={arg.name}>
{arg.name} ({arg.type}): {arg.value}
</div>
);
})}
</div>
);
})}
</div>
);
};

export default ArbitraryTransaction;
11 changes: 4 additions & 7 deletions src/graphql/fragments/actions.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ fragment ColonyAction on ColonyAction {
}
metadata {
customTitle
arbitraryTxAbis {
contractAddress
jsonAbi
}
}
members
rootHash
Expand All @@ -141,14 +145,7 @@ fragment ColonyAction on ColonyAction {
}
arbitraryTransactions {
contractAddress
method
methodSignature
encodedFunction
args {
value
name
type
}
}
}

Expand Down
49 changes: 21 additions & 28 deletions src/graphql/generated.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/redux/sagas/actions/createDomain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function* createDomainAction({
const { domainId } = eventData?.DomainAdded || {};
const nativeDomainId = toNumber(domainId);

yield createActionMetadataInDB(txHash, customActionTitle);
yield createActionMetadataInDB(txHash, { customTitle: customActionTitle });

if (annotationMessage) {
yield uploadAnnotation({
Expand Down
2 changes: 1 addition & 1 deletion src/redux/sagas/actions/editColony.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function* editColonyAction({
},
} = yield waitForTxResult(editColony.channel);

yield createActionMetadataInDB(txHash, customActionTitle);
yield createActionMetadataInDB(txHash, { customTitle: customActionTitle });

if (annotationMessage) {
yield uploadAnnotation({
Expand Down
2 changes: 1 addition & 1 deletion src/redux/sagas/actions/editDomain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function* editDomainAction({
},
} = yield waitForTxResult(editDomain.channel);

yield createActionMetadataInDB(txHash, customActionTitle);
yield createActionMetadataInDB(txHash, { customTitle: customActionTitle });

if (annotationMessage) {
yield uploadAnnotation({
Expand Down
2 changes: 1 addition & 1 deletion src/redux/sagas/actions/initiateSafeTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function* initiateSafeTransactionAction({
);
}

yield createActionMetadataInDB(txHash, customActionTitle);
yield createActionMetadataInDB(txHash, { customTitle: customActionTitle });

if (annotationMessage) {
yield uploadAnnotation({
Expand Down
2 changes: 1 addition & 1 deletion src/redux/sagas/actions/manageExistingSafes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function* manageExistingSafesAction({
},
} = yield waitForTxResult(manageExistingSafes.channel);

yield createActionMetadataInDB(txHash, customActionTitle);
yield createActionMetadataInDB(txHash, { customTitle: customActionTitle });

if (annotationMessage) {
yield uploadAnnotation({
Expand Down
2 changes: 1 addition & 1 deletion src/redux/sagas/actions/managePermissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function* managePermissionsAction({
},
} = yield waitForTxResult(setUserRoles.channel);

yield createActionMetadataInDB(txHash, customActionTitle);
yield createActionMetadataInDB(txHash, { customTitle: customActionTitle });

if (annotationMessage) {
yield uploadAnnotation({
Expand Down
2 changes: 1 addition & 1 deletion src/redux/sagas/actions/manageReputation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function* manageReputationAction({
},
} = yield waitForTxResult(manageReputation.channel);

yield createActionMetadataInDB(txHash, customActionTitle);
yield createActionMetadataInDB(txHash, { customTitle: customActionTitle });

if (annotationMessage) {
yield uploadAnnotation({
Expand Down
2 changes: 1 addition & 1 deletion src/redux/sagas/actions/manageTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function* manageTokensAction({
},
} = yield waitForTxResult(manageTokens.channel);

yield createActionMetadataInDB(txHash, customActionTitle);
yield createActionMetadataInDB(txHash, { customTitle: customActionTitle });

if (annotationMessage) {
yield uploadAnnotation({
Expand Down
2 changes: 1 addition & 1 deletion src/redux/sagas/actions/manageVerifiedMembers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function* manageVerifiedMembersAction({
},
} = yield waitForTxResult(manageVerifiedMembers.channel);

yield createActionMetadataInDB(txHash, customActionTitle);
yield createActionMetadataInDB(txHash, { customTitle: customActionTitle });

if (annotationMessage) {
yield uploadAnnotation({
Expand Down
2 changes: 1 addition & 1 deletion src/redux/sagas/actions/mintTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function* createMintTokensAction({

yield waitForTxResult(claimColonyFunds.channel);

yield createActionMetadataInDB(txHash, customActionTitle);
yield createActionMetadataInDB(txHash, { customTitle: customActionTitle });

if (annotationMessage) {
yield uploadAnnotation({
Expand Down
2 changes: 1 addition & 1 deletion src/redux/sagas/actions/moveFunds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function* createMoveFundsAction({
},
} = yield waitForTxResult(moveFunds.channel);

yield createActionMetadataInDB(txHash, customActionTitle);
yield createActionMetadataInDB(txHash, { customTitle: customActionTitle });

if (annotationMessage) {
yield uploadAnnotation({
Expand Down
2 changes: 1 addition & 1 deletion src/redux/sagas/actions/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function* createPaymentAction({
},
} = yield waitForTxResult(paymentAction.channel);

yield createActionMetadataInDB(txHash, customActionTitle);
yield createActionMetadataInDB(txHash, { customTitle: customActionTitle });

if (annotationMessage) {
yield uploadAnnotation({
Expand Down
2 changes: 1 addition & 1 deletion src/redux/sagas/actions/unlockToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function* tokenUnlockAction({
},
} = yield waitForTxResult(tokenUnlock.channel);

yield createActionMetadataInDB(txHash, customActionTitle);
yield createActionMetadataInDB(txHash, { customTitle: customActionTitle });

if (annotationMessage) {
yield uploadAnnotation({
Expand Down
2 changes: 1 addition & 1 deletion src/redux/sagas/actions/versionUpgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function* createVersionUpgradeAction({
},
} = yield waitForTxResult(upgrade.channel);

yield createActionMetadataInDB(txHash, customActionTitle);
yield createActionMetadataInDB(txHash, { customTitle: customActionTitle });

if (supportAnnotation) {
yield uploadAnnotation({
Expand Down
39 changes: 28 additions & 11 deletions src/redux/sagas/arbitraryTxs/arbitraryTx.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ClientType } from '@colony/colony-js';
import { utils } from 'ethers';
import { Interface } from 'ethers/lib/utils';
import { call, put, takeEvery } from 'redux-saga/effects';

Expand Down Expand Up @@ -37,16 +38,12 @@ function* arbitraryTxSaga({
const methodsBytes: string[] = [];

transactions.forEach(({ contractAddress, ...item }) => {
try {
const encodedFunction = new Interface(item.jsonAbi).encodeFunctionData(
item.method,
item.args?.map((arg) => arg.value),
);
contractAddresses.push(contractAddress);
methodsBytes.push(encodedFunction);
} catch (e) {
console.error(e);
}
const encodedFunction = new Interface(item.jsonAbi).encodeFunctionData(
item.method,
item.args?.map((arg) => arg.value),
);
contractAddresses.push(contractAddress);
methodsBytes.push(encodedFunction);
});

// setup batch ids and channels
Expand Down Expand Up @@ -106,7 +103,27 @@ function* arbitraryTxSaga({
},
} = yield waitForTxResult(makeArbitraryTransactions.channel);

yield createActionMetadataInDB(txHash, customActionTitle);
const abisByAddress = transactions.reduce<Record<string, string>>(
(acc, transaction) => {
const checksummedAddress = utils.getAddress(
transaction.contractAddress,
);
acc[checksummedAddress] = transaction.jsonAbi;
return acc;
},
{},
);
const arbitraryTxAbis = Object.entries(abisByAddress).map(
([contractAddress, jsonAbi]) => ({
contractAddress,
jsonAbi,
}),
);

yield createActionMetadataInDB(txHash, {
customTitle: customActionTitle,
arbitraryTxAbis,
});

if (annotationMessage) {
yield uploadAnnotation({
Expand Down
4 changes: 3 additions & 1 deletion src/redux/sagas/expenditures/createExpenditure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ function* createExpenditure({
});

if (customActionTitle) {
yield createActionMetadataInDB(txHash, customActionTitle);
yield createActionMetadataInDB(txHash, {
customTitle: customActionTitle,
});
}

if (isStaged) {
Expand Down
4 changes: 3 additions & 1 deletion src/redux/sagas/expenditures/createStakedExpenditure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ function* createStakedExpenditure({
});

if (customActionTitle) {
yield createActionMetadataInDB(txHash, customActionTitle);
yield createActionMetadataInDB(txHash, {
customTitle: customActionTitle,
});
}

if (isStaged) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ export function* handleDomainMetadata({
);
}

yield createActionMetadataInDB(txHash, customActionTitle);
yield createActionMetadataInDB(txHash, { customTitle: customActionTitle });
}
2 changes: 1 addition & 1 deletion src/redux/sagas/motions/editColonyMotion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ function* editColonyMotion({
);
}

yield createActionMetadataInDB(txHash, customActionTitle);
yield createActionMetadataInDB(txHash, { customTitle: customActionTitle });

if (annotationMessage) {
yield uploadAnnotation({
Expand Down
2 changes: 1 addition & 1 deletion src/redux/sagas/motions/initiateSafeTransactionMotion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ function* initiateSafeTransactionMotion({
meta,
});

yield createActionMetadataInDB(txHash, customActionTitle);
yield createActionMetadataInDB(txHash, { customTitle: customActionTitle });

if (annotationMessage) {
yield uploadAnnotation({
Expand Down
2 changes: 1 addition & 1 deletion src/redux/sagas/motions/managePermissionsMotion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ function* managePermissionsMotion({
},
} = yield waitForTxResult(createMotion.channel);

yield createActionMetadataInDB(txHash, customActionTitle);
yield createActionMetadataInDB(txHash, { customTitle: customActionTitle });

if (annotationMessage) {
yield uploadAnnotation({
Expand Down
2 changes: 1 addition & 1 deletion src/redux/sagas/motions/manageReputationMotion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ function* manageReputationMotion({
},
} = yield waitForTxResult(createMotion.channel);

yield createActionMetadataInDB(txHash, customActionTitle);
yield createActionMetadataInDB(txHash, { customTitle: customActionTitle });

if (annotationMessage) {
yield uploadAnnotation({
Expand Down
2 changes: 1 addition & 1 deletion src/redux/sagas/motions/manageTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function* manageTokensMotion({
},
} = yield waitForTxResult(createMotion.channel);

yield createActionMetadataInDB(txHash, customActionTitle);
yield createActionMetadataInDB(txHash, { customTitle: customActionTitle });

if (annotationMessage) {
yield uploadAnnotation({
Expand Down
Loading

0 comments on commit 592933d

Please sign in to comment.