|
|
|
@ -2,11 +2,11 @@ import { BigNumber } from '@ethersproject/bignumber'; |
|
|
|
|
import { arrayify, hexlify } from '@ethersproject/bytes'; |
|
|
|
|
import { TransactionReceipt } from '@ethersproject/abstract-provider'; |
|
|
|
|
import { ethers } from 'ethers'; |
|
|
|
|
import { xapps } from 'optics-ts-interface'; |
|
|
|
|
import { BridgeContracts, OpticsContext } from '..'; |
|
|
|
|
import { xapps } from '@abacus-network/ts-interface'; |
|
|
|
|
import { BridgeContracts, AbacusContext } from '..'; |
|
|
|
|
import { ResolvedTokenInfo, TokenIdentifier } from '../tokens'; |
|
|
|
|
import { OpticsMessage } from './OpticsMessage'; |
|
|
|
|
import { AnnotatedDispatch } from '../events/opticsEvents'; |
|
|
|
|
import { AbacusMessage } from './AbacusMessage'; |
|
|
|
|
import { AnnotatedDispatch } from '../events/abacusEvents'; |
|
|
|
|
|
|
|
|
|
const ACTION_LEN = { |
|
|
|
|
identifier: 1, |
|
|
|
@ -106,10 +106,10 @@ function parseBody( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* The BridgeMessage extends {@link OpticsMessage} with Bridge-specific |
|
|
|
|
* The BridgeMessage extends {@link AbacusMessage} with Bridge-specific |
|
|
|
|
* functionality. |
|
|
|
|
*/ |
|
|
|
|
class BridgeMessage extends OpticsMessage { |
|
|
|
|
class BridgeMessage extends AbacusMessage { |
|
|
|
|
readonly token: TokenIdentifier; |
|
|
|
|
readonly fromBridge: BridgeContracts; |
|
|
|
|
readonly toBridge: BridgeContracts; |
|
|
|
@ -118,7 +118,7 @@ class BridgeMessage extends OpticsMessage { |
|
|
|
|
* @hideconstructor |
|
|
|
|
*/ |
|
|
|
|
constructor( |
|
|
|
|
context: OpticsContext, |
|
|
|
|
context: AbacusContext, |
|
|
|
|
event: AnnotatedDispatch, |
|
|
|
|
token: TokenIdentifier, |
|
|
|
|
callerKnowsWhatTheyAreDoing: boolean, |
|
|
|
@ -138,36 +138,36 @@ class BridgeMessage extends OpticsMessage { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Attempt to instantiate a BridgeMessage from an existing |
|
|
|
|
* {@link OpticsMessage} |
|
|
|
|
* {@link AbacusMessage} |
|
|
|
|
* |
|
|
|
|
* @param context The {@link OpticsContext} to use. |
|
|
|
|
* @param opticsMessage The existing OpticsMessage |
|
|
|
|
* @param context The {@link AbacusContext} to use. |
|
|
|
|
* @param abacusMessage The existing AbacusMessage |
|
|
|
|
* @returns A Bridge message |
|
|
|
|
* @throws if the message cannot be parsed as a bridge message |
|
|
|
|
*/ |
|
|
|
|
static fromOpticsMessage( |
|
|
|
|
context: OpticsContext, |
|
|
|
|
opticsMessage: OpticsMessage, |
|
|
|
|
static fromAbacusMessage( |
|
|
|
|
context: AbacusContext, |
|
|
|
|
abacusMessage: AbacusMessage, |
|
|
|
|
): AnyBridgeMessage { |
|
|
|
|
const parsedMessageBody = parseBody(opticsMessage.message.body); |
|
|
|
|
const parsedMessageBody = parseBody(abacusMessage.message.body); |
|
|
|
|
|
|
|
|
|
switch (parsedMessageBody.action.type) { |
|
|
|
|
case 'transfer': |
|
|
|
|
return new TransferMessage( |
|
|
|
|
context, |
|
|
|
|
opticsMessage.dispatch, |
|
|
|
|
abacusMessage.dispatch, |
|
|
|
|
parsedMessageBody as ParsedTransferMessage, |
|
|
|
|
); |
|
|
|
|
case 'details': |
|
|
|
|
return new DetailsMessage( |
|
|
|
|
context, |
|
|
|
|
opticsMessage.dispatch, |
|
|
|
|
abacusMessage.dispatch, |
|
|
|
|
parsedMessageBody as ParsedDetailsMessage, |
|
|
|
|
); |
|
|
|
|
case 'requestDetails': |
|
|
|
|
return new RequestDetailsMessage( |
|
|
|
|
context, |
|
|
|
|
opticsMessage.dispatch, |
|
|
|
|
abacusMessage.dispatch, |
|
|
|
|
parsedMessageBody as ParsedRequestDetailsMesasage, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
@ -176,32 +176,32 @@ class BridgeMessage extends OpticsMessage { |
|
|
|
|
/** |
|
|
|
|
* Attempt to instantiate some BridgeMessages from a transaction receipt |
|
|
|
|
* |
|
|
|
|
* @param context The {@link OpticsContext} to use. |
|
|
|
|
* @param context The {@link AbacusContext} to use. |
|
|
|
|
* @param nameOrDomain the domain on which the receipt was logged |
|
|
|
|
* @param receipt The receipt |
|
|
|
|
* @returns an array of {@link BridgeMessage} objects |
|
|
|
|
* @throws if any message cannot be parsed as a bridge message |
|
|
|
|
*/ |
|
|
|
|
static fromReceipt( |
|
|
|
|
context: OpticsContext, |
|
|
|
|
context: AbacusContext, |
|
|
|
|
nameOrDomain: string | number, |
|
|
|
|
receipt: TransactionReceipt, |
|
|
|
|
): AnyBridgeMessage[] { |
|
|
|
|
const opticsMessages: OpticsMessage[] = OpticsMessage.fromReceipt( |
|
|
|
|
const abacusMessages: AbacusMessage[] = AbacusMessage.fromReceipt( |
|
|
|
|
context, |
|
|
|
|
nameOrDomain, |
|
|
|
|
receipt, |
|
|
|
|
); |
|
|
|
|
const bridgeMessages: AnyBridgeMessage[] = []; |
|
|
|
|
for (const opticsMessage of opticsMessages) { |
|
|
|
|
for (const abacusMessage of abacusMessages) { |
|
|
|
|
try { |
|
|
|
|
const bridgeMessage = BridgeMessage.fromOpticsMessage( |
|
|
|
|
const bridgeMessage = BridgeMessage.fromAbacusMessage( |
|
|
|
|
context, |
|
|
|
|
opticsMessage, |
|
|
|
|
abacusMessage, |
|
|
|
|
); |
|
|
|
|
bridgeMessages.push(bridgeMessage); |
|
|
|
|
} catch (e) { |
|
|
|
|
// catch error if OpticsMessage isn't a BridgeMessage
|
|
|
|
|
// catch error if AbacusMessage isn't a BridgeMessage
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return bridgeMessages; |
|
|
|
@ -210,7 +210,7 @@ class BridgeMessage extends OpticsMessage { |
|
|
|
|
/** |
|
|
|
|
* Attempt to instantiate EXACTLY one BridgeMessage from a transaction receipt |
|
|
|
|
* |
|
|
|
|
* @param context The {@link OpticsContext} to use. |
|
|
|
|
* @param context The {@link AbacusContext} to use. |
|
|
|
|
* @param nameOrDomain the domain on which the receipt was logged |
|
|
|
|
* @param receipt The receipt |
|
|
|
|
* @returns an array of {@link BridgeMessage} objects |
|
|
|
@ -218,7 +218,7 @@ class BridgeMessage extends OpticsMessage { |
|
|
|
|
* is not EXACTLY 1 BridgeMessage in the receipt |
|
|
|
|
*/ |
|
|
|
|
static singleFromReceipt( |
|
|
|
|
context: OpticsContext, |
|
|
|
|
context: AbacusContext, |
|
|
|
|
nameOrDomain: string | number, |
|
|
|
|
receipt: TransactionReceipt, |
|
|
|
|
): AnyBridgeMessage { |
|
|
|
@ -237,14 +237,14 @@ class BridgeMessage extends OpticsMessage { |
|
|
|
|
* Attempt to instantiate some BridgeMessages from a transaction hash by |
|
|
|
|
* retrieving and parsing the receipt. |
|
|
|
|
* |
|
|
|
|
* @param context The {@link OpticsContext} to use. |
|
|
|
|
* @param context The {@link AbacusContext} to use. |
|
|
|
|
* @param nameOrDomain the domain on which the receipt was logged |
|
|
|
|
* @param transactionHash The transaction hash |
|
|
|
|
* @returns an array of {@link BridgeMessage} objects |
|
|
|
|
* @throws if any message cannot be parsed as a bridge message |
|
|
|
|
*/ |
|
|
|
|
static async fromTransactionHash( |
|
|
|
|
context: OpticsContext, |
|
|
|
|
context: AbacusContext, |
|
|
|
|
nameOrDomain: string | number, |
|
|
|
|
transactionHash: string, |
|
|
|
|
): Promise<AnyBridgeMessage[]> { |
|
|
|
@ -260,7 +260,7 @@ class BridgeMessage extends OpticsMessage { |
|
|
|
|
* Attempt to instantiate EXACTLY one BridgeMessages from a transaction hash |
|
|
|
|
* by retrieving and parsing the receipt. |
|
|
|
|
* |
|
|
|
|
* @param context The {@link OpticsContext} to use. |
|
|
|
|
* @param context The {@link AbacusContext} to use. |
|
|
|
|
* @param nameOrDomain the domain on which the receipt was logged |
|
|
|
|
* @param transactionHash The transaction hash |
|
|
|
|
* @returns an array of {@link BridgeMessage} objects |
|
|
|
@ -268,7 +268,7 @@ class BridgeMessage extends OpticsMessage { |
|
|
|
|
* not EXACTLY one such message |
|
|
|
|
*/ |
|
|
|
|
static async singleFromTransactionHash( |
|
|
|
|
context: OpticsContext, |
|
|
|
|
context: AbacusContext, |
|
|
|
|
nameOrDomain: string | number, |
|
|
|
|
transactionHash: string, |
|
|
|
|
): Promise<AnyBridgeMessage> { |
|
|
|
@ -327,7 +327,7 @@ export class TransferMessage extends BridgeMessage { |
|
|
|
|
action: Transfer; |
|
|
|
|
|
|
|
|
|
constructor( |
|
|
|
|
context: OpticsContext, |
|
|
|
|
context: AbacusContext, |
|
|
|
|
event: AnnotatedDispatch, |
|
|
|
|
parsed: ParsedTransferMessage, |
|
|
|
|
) { |
|
|
|
@ -381,7 +381,7 @@ export class DetailsMessage extends BridgeMessage { |
|
|
|
|
action: Details; |
|
|
|
|
|
|
|
|
|
constructor( |
|
|
|
|
context: OpticsContext, |
|
|
|
|
context: AbacusContext, |
|
|
|
|
event: AnnotatedDispatch, |
|
|
|
|
parsed: ParsedDetailsMessage, |
|
|
|
|
) { |
|
|
|
@ -419,7 +419,7 @@ export class RequestDetailsMessage extends BridgeMessage { |
|
|
|
|
action: RequestDetails; |
|
|
|
|
|
|
|
|
|
constructor( |
|
|
|
|
context: OpticsContext, |
|
|
|
|
context: AbacusContext, |
|
|
|
|
event: AnnotatedDispatch, |
|
|
|
|
parsed: ParsedRequestDetailsMesasage, |
|
|
|
|
) { |