Skip to content

Commit

Permalink
[PLAT-308] Fix wormhole on identity (#3742)
Browse files Browse the repository at this point in the history
* [PLAT-308] Fix wormhole on identity

* Address comments
  • Loading branch information
raymondjacobson authored Aug 24, 2022
1 parent 4d94f7c commit 879b906
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
2 changes: 0 additions & 2 deletions libs/src/AudiusLibs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,11 +565,9 @@ export class AudiusLibs {
}
await Promise.all(contractsToInit)
if (
this.hedgehog &&
this.wormholeConfig &&
this.ethWeb3Manager &&
this.ethContracts &&
this.identityService &&
this.solanaWeb3Manager
) {
this.wormholeClient = new Wormhole(
Expand Down
28 changes: 23 additions & 5 deletions libs/src/services/wormhole/Wormhole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { providers } from 'ethers/lib/index'
import wormholeSDK, { ChainId } from '@certusone/wormhole-sdk'

import { SolanaUtils, wAudioFromWeiAudio } from '../solana'
import { Utils, sign, getTransferTokensDigest } from '../../utils'
import { Utils, sign, getTransferTokensDigest, Nullable } from '../../utils'
import type {
RpcResponseAndContext,
SignatureResult,
Expand All @@ -30,10 +30,10 @@ export type WormholeConfig = {

/** Singleton state-manager for Audius Eth Contracts */
export class Wormhole {
hedgehog: Hedgehog
hedgehog: Nullable<Hedgehog>
ethWeb3Manager: EthWeb3Manager
ethContracts: EthContracts
identityService: IdentityService
identityService: Nullable<IdentityService>
solanaWeb3Manager: SolanaWeb3Manager
rpcHosts: string[]
solBridgeAddress: string
Expand All @@ -43,10 +43,10 @@ export class Wormhole {
wormholeSDK: typeof wormholeSDK

constructor(
hedgehog: Hedgehog,
hedgehog: Hedgehog | null,
ethWeb3Manager: EthWeb3Manager,
ethContracts: EthContracts,
identityService: IdentityService,
identityService: IdentityService | null,
solanaWeb3Manager: SolanaWeb3Manager,
rpcHosts: string[],
solBridgeAddress: string,
Expand Down Expand Up @@ -146,6 +146,9 @@ export class Wormhole {
if (customSignTransaction) {
signTransaction = customSignTransaction
} else {
if (!this.identityService) {
throw new Error('Identity service required to relay raw transaction')
}
signTransaction = async (transaction: Transaction) => {
const { blockhash } = await connection.getLatestBlockhash()
// Must call serialize message to set the correct signatures on the transaction
Expand Down Expand Up @@ -205,6 +208,10 @@ export class Wormhole {

await connection.confirmTransaction(txid)
} else {
if (!this.identityService) {
throw new Error('Identity service required to relay raw transaction')
}

transaction.serializeMessage()

const { blockhash } = await connection.getLatestBlockhash()
Expand Down Expand Up @@ -247,6 +254,12 @@ export class Wormhole {
ethTargetAddress: string,
options = {}
) {
if (!this.hedgehog) {
throw new Error('Hedgehog required for sendTokensFromSolToEthViaWormhole')
}
if (!this.identityService) {
throw new Error('Identity service required to relay raw transaction')
}
const phases = {
GENERATE_SOL_ROOT_ACCT: 'GENERATE_SOL_ROOT_ACCT',
TRANSFER_WAUDIO_TO_ROOT: 'TRANSFER_WAUDIO_TO_ROOT',
Expand Down Expand Up @@ -397,6 +410,11 @@ export class Wormhole {
amount: BN,
solanaAccount: string
) {
if (!this.hedgehog) {
throw new Error(
'Hedgehog required for _getTransferTokensToEthWormholeParams'
)
}
const web3 = this.ethWeb3Manager.getWeb3()
const wormholeClientAddress =
this.ethContracts.WormholeClient.contractAddress
Expand Down

0 comments on commit 879b906

Please sign in to comment.