Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ScreamingHawk committed Oct 30, 2023
1 parent 08878dd commit 0708f1a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
6 changes: 4 additions & 2 deletions packages/account/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -758,8 +758,10 @@ export class Account {
pstatus?: AccountStatus,
callback?: (bundle: commons.transaction.IntendedTransactionBundle) => void
): Promise<ethers.providers.TransactionResponse> {
const firstChainId = Array.isArray(signedBundle) ? signedBundle[0].chainId : signedBundle.chainId
const status = pstatus || (await this.status(firstChainId))
if (!Array.isArray(signedBundle)) {
return this.sendSignedTransactions([signedBundle], chainId, quote, pstatus, callback)
}
const status = pstatus || (await this.status(signedBundle[0].chainId))
this.mustBeFullyMigrated(status)

const decoratedBundle = await this.decorateTransactions(signedBundle, status)
Expand Down
16 changes: 7 additions & 9 deletions packages/account/src/orchestrator/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,26 @@ import { signers, Status } from '@0xsequence/signhub'
import { ethers } from 'ethers'
import { Account } from '../account'

export type AccountWrapperDecorateMetadata = {
chainId?: ethers.BigNumberish
export type MetadataWithChainId = {
chainId: ethers.BigNumberish
}

// Implements a wrapper for using Sequence accounts as nested signers
// in the signhub orchestrator. It only works for nested signatures.
// Implements a wrapper for using Sequence accounts as nested signers in the signhub orchestrator.
export class AccountOrchestratorWrapper implements signers.SapientSigner {
constructor(public account: Account) {}

async getAddress(): Promise<string> {
return this.account.address
}

getChainIdFromMetadata(metadata: Object): ethers.BigNumberish {
let { chainId } = metadata as AccountWrapperDecorateMetadata
getChainIdFromMetadata(metadata: Object): ethers.BigNumber {
try {
chainId = ethers.BigNumber.from(chainId)
const { chainId } = metadata as MetadataWithChainId
return ethers.BigNumber.from(chainId)
} catch (err) {
// Invalid metadata object
throw new Error('AccountOrchestratorWrapper only supports account status callbacks')
throw new Error('AccountOrchestratorWrapper only supports metadata with chain id')
}
return chainId
}

async buildDeployTransaction(metadata: Object): Promise<commons.transaction.TransactionBundle | undefined> {
Expand Down
2 changes: 2 additions & 0 deletions packages/signhub/src/signers/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export interface SapientSigner {

export function isSapientSigner(signer: ethers.Signer | SapientSigner): signer is SapientSigner {
return (
(signer as SapientSigner).getAddress !== undefined &&
(signer as SapientSigner).buildDeployTransaction !== undefined &&
(signer as SapientSigner).predecorateSignedTransactions !== undefined &&
(signer as SapientSigner).decorateTransactions !== undefined &&
(signer as SapientSigner).requestSignature !== undefined &&
(signer as SapientSigner).notifyStatusChange !== undefined
Expand Down

0 comments on commit 0708f1a

Please sign in to comment.