From 7716a765ac3f156064aa8f8c775cce91b998e4eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Jakub=20Nani=C5=A1ta?= Date: Thu, 18 Jul 2024 14:01:07 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Solana:=20Move=20common=20signer?= =?UTF-8?q?=20functionality=20into=20devtools=20(#724)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/fuzzy-fans-give.md | 6 +++++ packages/devtools-evm/src/signer/sdk.ts | 21 ++++----------- packages/devtools/src/transactions/signer.ts | 27 ++++++++++++++++++++ packages/devtools/src/transactions/types.ts | 3 +++ 4 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 .changeset/fuzzy-fans-give.md diff --git a/.changeset/fuzzy-fans-give.md b/.changeset/fuzzy-fans-give.md new file mode 100644 index 000000000..ef45077be --- /dev/null +++ b/.changeset/fuzzy-fans-give.md @@ -0,0 +1,6 @@ +--- +"@layerzerolabs/devtools-evm": patch +"@layerzerolabs/devtools": patch +--- + +Move common signer functionality into devtools diff --git a/packages/devtools-evm/src/signer/sdk.ts b/packages/devtools-evm/src/signer/sdk.ts index 26f50d604..d78d336f4 100644 --- a/packages/devtools-evm/src/signer/sdk.ts +++ b/packages/devtools-evm/src/signer/sdk.ts @@ -5,8 +5,7 @@ import SafeApiKit from '@safe-global/api-kit' import { MetaTransactionData, OperationType, SafeTransaction } from '@safe-global/safe-core-sdk-types' import type { EndpointId } from '@layerzerolabs/lz-definitions' import { - formatEid, - formatOmniPoint, + OmniSignerBase, type OmniTransactionResponse, type OmniSigner, type OmniTransaction, @@ -15,23 +14,13 @@ import assert from 'assert' import { ethers } from 'ethers' -export abstract class OmniSignerEVMBase implements OmniSigner { +export abstract class OmniSignerEVMBase extends OmniSignerBase implements OmniSigner { protected constructor( - public readonly eid: EndpointId, + eid: EndpointId, public readonly signer: Signer - ) {} - - protected assertTransaction(transaction: OmniTransaction) { - assert( - transaction.point.eid === this.eid, - `Could not use signer for ${formatEid(this.eid)} to sign a transaction for ${formatOmniPoint( - transaction.point - )}` - ) + ) { + super(eid) } - - abstract sign(transaction: OmniTransaction): Promise - abstract signAndSend(transaction: OmniTransaction): Promise } /** diff --git a/packages/devtools/src/transactions/signer.ts b/packages/devtools/src/transactions/signer.ts index 19a16ad38..f8c299826 100644 --- a/packages/devtools/src/transactions/signer.ts +++ b/packages/devtools/src/transactions/signer.ts @@ -3,6 +3,7 @@ import type { OmniSigner, OmniSignerFactory, OmniTransaction, + OmniTransactionResponse, OmniTransactionWithError, OmniTransactionWithReceipt, OmniTransactionWithResponse, @@ -10,6 +11,32 @@ import type { import { formatEid, formatOmniPoint } from '@/omnigraph/format' import { groupTransactionsByEid } from './utils' import { EndpointId } from '@layerzerolabs/lz-definitions' +import assert from 'assert' + +/** + * Base class for all signers containing common functionality + */ +export abstract class OmniSignerBase implements OmniSigner { + protected constructor(public readonly eid: EndpointId) {} + + abstract sign(transaction: OmniTransaction): Promise + + abstract signAndSend(transaction: OmniTransaction): Promise + + /** + * helper method to ensure that the transaction we are trying to sign is on a correct network + * + * @param {OmniTransaction} transaction + */ + protected assertTransaction(transaction: OmniTransaction) { + assert( + transaction.point.eid === this.eid, + `Could not use signer for ${formatEid(this.eid)} to sign a transaction for ${formatOmniPoint( + transaction.point + )}` + ) + } +} export type SignAndSendResult = [ // All the successful transactions diff --git a/packages/devtools/src/transactions/types.ts b/packages/devtools/src/transactions/types.ts index 259a181b2..87f484b1d 100644 --- a/packages/devtools/src/transactions/types.ts +++ b/packages/devtools/src/transactions/types.ts @@ -1,5 +1,6 @@ import { OmniPoint } from '@/omnigraph/types' import { EndpointBasedFactory } from '@/types' +import { EndpointId } from '@layerzerolabs/lz-definitions' export interface OmniTransaction { point: OmniPoint @@ -34,6 +35,8 @@ export interface OmniTransactionReceipt { } export interface OmniSigner { + eid: EndpointId + sign: (transaction: OmniTransaction) => Promise signAndSend: (transaction: OmniTransaction) => Promise