-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #300 from JoinColony/feat/wormhole-tx-matching
[Proxy colonies] Feat: Get the main-chain transaction hash from a proxy chain
- Loading branch information
Showing
17 changed files
with
606 additions
and
59 deletions.
There are no files selected for viewing
72 changes: 70 additions & 2 deletions
72
apps/main-chain/src/handlers/proxyColonies/proxyColonyRequested.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 |
---|---|---|
@@ -1,7 +1,75 @@ | ||
import { ContractEvent } from '@joincolony/blocks'; | ||
import { | ||
ContractEvent, | ||
ContractEventsSignatures, | ||
ProxyColonyEvents, | ||
} from '@joincolony/blocks'; | ||
import { output } from '@joincolony/utils'; | ||
import { constants, utils } from 'ethers'; | ||
import blockManager from '~blockManager'; | ||
import rpcProvider from '~provider'; | ||
import { writeActionFromEvent } from '~utils/actions/writeAction'; | ||
import { ColonyActionType } from '@joincolony/graphql'; | ||
|
||
export const handleProxyColonyRequested = async ( | ||
event: ContractEvent, | ||
): Promise<void> => { | ||
console.log('proxy colony requested event', event); | ||
const { blockNumber, contractAddress: colonyAddress } = event; | ||
|
||
const { destinationChainId } = event.args; | ||
|
||
const logs = await rpcProvider.getProviderInstance().getLogs({ | ||
fromBlock: blockNumber, | ||
toBlock: blockNumber, | ||
topics: [ | ||
[ | ||
utils.id(ContractEventsSignatures.ProxyColonyRequested), | ||
utils.id(ContractEventsSignatures.LogMessagePublished), | ||
], | ||
], | ||
}); | ||
|
||
const events = await Promise.all( | ||
logs.map((log) => | ||
blockManager.mapLogToContractEvent(log, ProxyColonyEvents), | ||
), | ||
); | ||
|
||
const wormholeEvent = events.find( | ||
(event) => | ||
ContractEventsSignatures.LogMessagePublished === event?.signature, | ||
); | ||
const proxyRequestedEvent = events.find( | ||
(event) => | ||
ContractEventsSignatures.ProxyColonyRequested === event?.signature, | ||
); | ||
|
||
if (!wormholeEvent || !proxyRequestedEvent) { | ||
output( | ||
`ProxyColonyRequested or LogMessagePublished are not present in the same block`, | ||
); | ||
|
||
return; | ||
} | ||
|
||
const { sender, sequence } = wormholeEvent.args; | ||
const emitterAddress = sender.toString(); | ||
const emitterSequence = sequence.toString(); | ||
|
||
if (!emitterAddress || !sequence) { | ||
output('Missing arguments on the LogMessagePublished events'); | ||
return; | ||
} | ||
|
||
await writeActionFromEvent(event, colonyAddress, { | ||
type: ColonyActionType.AddProxyColony, | ||
initiatorAddress: constants.AddressZero, | ||
multiChainInfo: { | ||
completed: false, | ||
targetChainId: destinationChainId.toNumber(), | ||
wormholeInfo: { | ||
sequence: emitterSequence, | ||
emitterAddress, | ||
}, | ||
}, | ||
}); | ||
}; |
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,7 @@ | ||
import { WormholeClient } from "@joincolony/clients"; | ||
|
||
const bridgeEndpoint = process.env.MULTI_CHAIN_BRIDGE_ENDPOINT ?? ''; | ||
|
||
const client = new WormholeClient(bridgeEndpoint); | ||
|
||
export default client; |
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,7 @@ | ||
import { WormholeClient } from "@joincolony/clients"; | ||
|
||
const bridgeEndpoint = process.env.MULTI_CHAIN_BRIDGE_ENDPOINT ?? ''; | ||
|
||
const client = new WormholeClient(bridgeEndpoint); | ||
|
||
export default client; |
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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { RpcProvider } from './rpcProvider'; | ||
export * from './amplifyClient'; | ||
export * from './networkClient'; | ||
export * from './wormholeClient'; | ||
// @TODO rename clients into providers |
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 |
---|---|---|
@@ -1,23 +1,37 @@ | ||
import { ColonyNetworkClient, Network, getColonyNetworkClient } from '@colony/colony-js'; | ||
import { | ||
ColonyNetworkClient, | ||
Network, | ||
NetworkClientOptions, | ||
getColonyNetworkClient, | ||
} from '@colony/colony-js'; | ||
|
||
import { RpcProvider } from './rpcProvider'; | ||
|
||
export class NetworkClient { | ||
private readonly rpcProvider: RpcProvider; | ||
private readonly network: Network; | ||
private readonly networkAddress?: string; | ||
private readonly rpcProvider: RpcProvider; | ||
private readonly network: Network; | ||
private readonly networkAddress?: string; | ||
|
||
constructor(rpcProvider: RpcProvider, network: Network, networkAddress?: string) { | ||
this.rpcProvider = rpcProvider; | ||
this.network = network; | ||
this.networkAddress = networkAddress; | ||
} | ||
constructor( | ||
rpcProvider: RpcProvider, | ||
network: Network, | ||
networkAddress?: string, | ||
) { | ||
this.rpcProvider = rpcProvider; | ||
this.network = network; | ||
this.networkAddress = networkAddress; | ||
} | ||
|
||
// @TODO maybe add here an options object | ||
public getInstance(): ColonyNetworkClient { | ||
return getColonyNetworkClient(this.network, this.rpcProvider.getProviderInstance(), { | ||
networkAddress: this.networkAddress, | ||
disableVersionCheck: true, | ||
}); | ||
} | ||
} | ||
public getInstance( | ||
options: NetworkClientOptions = { disableVersionCheck: true }, | ||
): ColonyNetworkClient { | ||
return getColonyNetworkClient( | ||
this.network, | ||
this.rpcProvider.getProviderInstance(), | ||
{ | ||
...options, | ||
networkAddress: this.networkAddress, | ||
}, | ||
); | ||
} | ||
} |
Oops, something went wrong.