-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Proxy colonies] Feat: Add create event details to colony model #303
Merged
bassgeta
merged 2 commits into
feat/proxy-colonies-dev-env
from
feat/colony-added-event
Jan 16, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
apps/main-chain/src/handlers/colonies/helpers/validateCreationSalt.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { verbose } from '@joincolony/utils'; | ||
import { utils } from 'ethers'; | ||
import rpcProvider from '~provider'; | ||
import networkClient from '~networkClient'; | ||
import { getTransactionSignerAddress } from '~utils/transactions'; | ||
|
||
const ContractCreationEvents = { | ||
Create3ProxyContractCreation: 'Create3ProxyContractCreation(address,bytes32)', | ||
}; | ||
|
||
export const getColonyCreationSalt = async ( | ||
blockNumber: number, | ||
transactionHash: string, | ||
): Promise<string | null> => { | ||
const create3ProxyLogs = await rpcProvider.getProviderInstance().getLogs({ | ||
fromBlock: blockNumber, | ||
toBlock: blockNumber, | ||
topics: [utils.id(ContractCreationEvents.Create3ProxyContractCreation)], | ||
}); | ||
|
||
if (create3ProxyLogs.length === 0) { | ||
verbose(`Couldn't fetch colony proxy contract creation events`); | ||
return null; | ||
} | ||
|
||
const create3ProxySalt = create3ProxyLogs[0].topics[2]; | ||
|
||
if (!create3ProxySalt) { | ||
verbose( | ||
`The Create3ProxyContractCreation log doesn't have the salt data: ${JSON.stringify(create3ProxyLogs[0], null, 2)}`, | ||
); | ||
return null; | ||
} | ||
|
||
const transaction = await rpcProvider | ||
.getProviderInstance() | ||
.getTransaction(transactionHash); | ||
|
||
const signerAddress = getTransactionSignerAddress(transaction); | ||
|
||
if (!signerAddress) { | ||
verbose( | ||
`Couldn't find the signer for transaction with txHash: ${transactionHash}`, | ||
); | ||
return null; | ||
} | ||
|
||
const generatedColonySalt = await networkClient.getColonyCreationSalt({ | ||
blockTag: blockNumber, | ||
from: signerAddress, | ||
}); | ||
|
||
const guardedSalt = utils.keccak256( | ||
utils.defaultAbiCoder.encode( | ||
['bytes32', 'bytes32'], | ||
[ | ||
utils.hexZeroPad(networkClient.address, 32), | ||
generatedColonySalt, // Actual salt | ||
], | ||
), | ||
); | ||
|
||
if (guardedSalt !== create3ProxySalt) { | ||
verbose( | ||
`The network salt doesn't match the salt used when creating the colony!`, | ||
); | ||
return null; | ||
} | ||
|
||
return generatedColonySalt; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { utils, Transaction } from 'ethers'; | ||
|
||
const MetatransactionInterface = new utils.Interface([ | ||
'function executeMetaTransaction(address userAddress, bytes memory payload, bytes32 sigR, bytes32 sigS, uint8 sigV) external payable returns (bytes memory)', | ||
]); | ||
|
||
export const getTransactionSignerAddress = ( | ||
transaction: Transaction, | ||
): string | undefined => { | ||
let signerAddress = transaction.from; | ||
|
||
try { | ||
const metaTx = MetatransactionInterface.parseTransaction({ | ||
data: transaction.data, | ||
value: transaction.value, | ||
}); | ||
signerAddress = metaTx.args[0]; | ||
} catch (error) { | ||
// if it's an error, it just means it's not a metatransaction | ||
} | ||
|
||
return signerAddress; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to bail out of the whole handler if this fails? Or at least log an error or something? I guess it's not critical to the colony creation process (only proxy colonies later down the line) so maybe bailing out is too severe? 🤷