-
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
Add support for MoveFunds action #22
Merged
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
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,58 @@ | ||
import { | ||
AnyColonyClient, | ||
ColonyClientV1, | ||
ColonyClientV2, | ||
ColonyClientV3, | ||
ColonyClientV4, | ||
} from '@colony/colony-js'; | ||
import { BigNumber } from 'ethers'; | ||
import networkClient from '~/networkClient'; | ||
import { ColonyActionType, ContractEvent } from '~/types'; | ||
import { toNumber, writeActionFromEvent } from '~/utils'; | ||
import { getDatabaseDomainId } from '~/utils/domains'; | ||
|
||
/** | ||
* The handler makes use of colonyClient getDomainFromFundingPot method which is only | ||
* available on ColonyClientV5 and above. The following type predicate allows to check | ||
* we're dealing with a client that supports this method | ||
*/ | ||
type SupportedColonyClient = Exclude< | ||
AnyColonyClient, | ||
ColonyClientV1 | ColonyClientV2 | ColonyClientV3 | ColonyClientV4 | ||
>; | ||
const isSupportedColonyClient = ( | ||
colonyClient: AnyColonyClient, | ||
): colonyClient is SupportedColonyClient => | ||
(colonyClient as SupportedColonyClient).getDomainFromFundingPot !== undefined; | ||
|
||
export default async (event: ContractEvent): Promise<void> => { | ||
const { contractAddress: colonyAddress } = event; | ||
const { | ||
agent: initiatorAddress, | ||
token: tokenAddress, | ||
amount, | ||
fromPot, | ||
toPot, | ||
} = event.args; | ||
|
||
const colonyClient = await networkClient.getColonyClient(colonyAddress); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we could optimize the ingestor somewhat if we were to store all known instances of the colony client. I see us re-instantiating the client for a lot of tracked events. But I actually don't know what this impact would be real-life. |
||
let fromDomainId: BigNumber | undefined; | ||
let toDomainId: BigNumber | undefined; | ||
if (isSupportedColonyClient(colonyClient)) { | ||
fromDomainId = await colonyClient.getDomainFromFundingPot(fromPot); | ||
toDomainId = await colonyClient.getDomainFromFundingPot(toPot); | ||
} | ||
|
||
await writeActionFromEvent(event, colonyAddress, { | ||
type: ColonyActionType.MoveFunds, | ||
initiatorAddress, | ||
tokenAddress, | ||
amount: amount.toString(), | ||
fromDomainId: fromDomainId | ||
? getDatabaseDomainId(colonyAddress, toNumber(fromDomainId)) | ||
: undefined, | ||
toDomainId: toDomainId | ||
? getDatabaseDomainId(colonyAddress, toNumber(toDomainId)) | ||
: undefined, | ||
}); | ||
}; |
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
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.
alternatively:
Then you don't need to cast
colonyClient
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.
I think explicit casting might be better here since it will alert you if the property you're checking against doesn't exist/got removed
https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates