Skip to content

Commit

Permalink
🧹 Solana: Move common signer functionality into devtools (#724)
Browse files Browse the repository at this point in the history
  • Loading branch information
janjakubnanista authored Jul 18, 2024
1 parent 1bc24e2 commit 7716a76
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .changeset/fuzzy-fans-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@layerzerolabs/devtools-evm": patch
"@layerzerolabs/devtools": patch
---

Move common signer functionality into devtools
21 changes: 5 additions & 16 deletions packages/devtools-evm/src/signer/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<string>
abstract signAndSend(transaction: OmniTransaction): Promise<OmniTransactionResponse>
}

/**
Expand Down
27 changes: 27 additions & 0 deletions packages/devtools/src/transactions/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,40 @@ import type {
OmniSigner,
OmniSignerFactory,
OmniTransaction,
OmniTransactionResponse,
OmniTransactionWithError,
OmniTransactionWithReceipt,
OmniTransactionWithResponse,
} from './types'
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<string>

abstract signAndSend(transaction: OmniTransaction): Promise<OmniTransactionResponse>

/**
* 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
Expand Down
3 changes: 3 additions & 0 deletions packages/devtools/src/transactions/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { OmniPoint } from '@/omnigraph/types'
import { EndpointBasedFactory } from '@/types'
import { EndpointId } from '@layerzerolabs/lz-definitions'

export interface OmniTransaction {
point: OmniPoint
Expand Down Expand Up @@ -34,6 +35,8 @@ export interface OmniTransactionReceipt {
}

export interface OmniSigner<TResponse extends OmniTransactionResponse = OmniTransactionResponse> {
eid: EndpointId

sign: (transaction: OmniTransaction) => Promise<string>
signAndSend: (transaction: OmniTransaction) => Promise<TResponse>

Expand Down

0 comments on commit 7716a76

Please sign in to comment.