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