Skip to content

Commit

Permalink
solana relayer fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kev1n-peters committed Mar 21, 2024
1 parent a5c6af2 commit 96dbe72
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 27 deletions.
1 change: 1 addition & 0 deletions sdk/src/contexts/solana/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ export * from './wormhole/cpi';
* @category Solana
*/
export * from './tokenBridge/cpi';
export * from './computeBudget';
2 changes: 1 addition & 1 deletion wormhole-connect/src/config/testnet/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2333,7 +2333,7 @@ export const TESTNET_TOKENS: TokensConfig = {
// If the transceiver is split into a separate contract, this address
// and route code should be updated to support the new structure.
wormholeTransceiver: 'nTTh3bZ5Aer6xboWZe39RDEft4MeVxSQ8D1EYAVLZw9',
solanaQuoter: '',
solanaQuoter: 'NqTdGLLL6b6bFo7YESNEezocgF8onH5cst5EdH791en',
},
},
};
2 changes: 1 addition & 1 deletion wormhole-connect/src/routes/ntt/nttRelay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class NttRelay extends NttBase {
if (!nttConfig.solanaQuoter) throw new Error('no solana quoter');
const quoter = new NttQuoter(nttConfig.solanaQuoter);
const relayCost = await quoter.calcRelayCost(destChain);
return { fee: BigNumber.from(relayCost), feeToken: 'native' };
return { fee: BigNumber.from(relayCost.toString()), feeToken: 'native' };
}
throw new Error('unsupported chain');
}
Expand Down
12 changes: 8 additions & 4 deletions wormhole-connect/src/routes/ntt/platforms/solana/nttManager.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {
addComputeBudget,
ChainId,
ChainName,
TokenId,
} from '@wormhole-foundation/wormhole-connect-sdk';
import { InboundQueuedTransfer } from '../../types';
import { solanaContext, toChainId } from 'utils/sdk';
import { solanaContext, toChainId, toChainName } from 'utils/sdk';
import { TransferWallet, postVaa, signAndSendTransaction } from 'utils/wallet';
import {
Connection,
Expand Down Expand Up @@ -62,7 +63,7 @@ export class NttManagerSolana {
readonly wormholeId: string;

constructor(readonly nttId: string) {
const connection = solanaContext().connection;
const { connection } = solanaContext();
if (!connection) throw new Error('Connection not found');
this.connection = connection;
this.program = new Program(IDL, nttId, { connection });
Expand Down Expand Up @@ -91,7 +92,7 @@ export class NttManagerSolana {
payer,
from: tokenAccount,
amount: new BN(amount.toString()),
recipientChain: CONFIG.wh.toChainName(toChain),
recipientChain: toChainName(toChain),
recipientAddress: destContext.formatAddress(recipient),
fromAuthority: payer,
outboxItem: outboxItem.publicKey,
Expand Down Expand Up @@ -141,6 +142,7 @@ export class NttManagerSolana {
tx.feePayer = payer;
const { blockhash } = await this.connection.getLatestBlockhash('finalized');
tx.recentBlockhash = blockhash;
await addComputeBudget(this.connection, tx);
tx.partialSign(outboxItem);
const txId = await signAndSendTransaction(
'solana',
Expand Down Expand Up @@ -217,6 +219,7 @@ export class NttManagerSolana {
tx.feePayer = payerPublicKey;
const { blockhash } = await this.connection.getLatestBlockhash('finalized');
tx.recentBlockhash = blockhash;
await addComputeBudget(this.connection, tx);
const txId = await signAndSendTransaction(
'solana',
tx,
Expand Down Expand Up @@ -332,6 +335,7 @@ export class NttManagerSolana {
tx.feePayer = payerPublicKey;
const { blockhash } = await this.connection.getLatestBlockhash('finalized');
tx.recentBlockhash = blockhash;
await addComputeBudget(this.connection, tx);
const txId = await signAndSendTransaction(
'solana',
tx,
Expand Down Expand Up @@ -434,7 +438,7 @@ export class NttManagerSolana {
}

transceiverPeerAccountAddress(chain: ChainName | ChainId): PublicKey {
const chainId = CONFIG.wh.toChainId(chain);
const chainId = toChainId(chain);
return this.derivePda([
Buffer.from('transceiver_peer'),
new BN(chainId).toBuffer('be', 2),
Expand Down
19 changes: 8 additions & 11 deletions wormhole-connect/src/routes/ntt/platforms/solana/nttQuoter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import {
} from '@solana/web3.js';
import { BN, Program } from '@coral-xyz/anchor';
import { NttQuoter as NttQuoterType, IDL } from './types/ntt_quoter';
import { solanaContext } from 'utils/sdk';
import config from 'config';
import { solanaContext, toChainId } from 'utils/sdk';

//constants that must match ntt-quoter lib.rs / implementation:
const EVM_GAS_COST = 250_000; // TODO: make sure this is right
Expand Down Expand Up @@ -40,7 +39,7 @@ export class NttQuoter {
readonly instance: PublicKey;

constructor(programId: PublicKeyInitData) {
const connection = solanaContext().connection;
const { connection } = solanaContext();
if (!connection) throw new Error('Connection not found');
this.connection = connection;
this.program = new Program<NttQuoterType>(IDL, new PublicKey(programId), {
Expand Down Expand Up @@ -72,17 +71,16 @@ export class NttQuoter {

const totalNativeGasCostUsd =
chainData.nativePriceUsd *
chainData.gasPriceGwei *
EVM_GAS_COST *
GWEI_PER_ETH;
((chainData.gasPriceGwei * EVM_GAS_COST) / GWEI_PER_ETH);

const totalCostSol =
rentCost +
rentCost / LAMPORTS_PER_SOL +
(chainData.basePriceUsd + totalNativeGasCostUsd) /
instanceData.solPriceUsd;

// Add 5% to account for possible price updates while the tx is in flight
return U64.to(totalCostSol * 1.05, LAMPORTS_PER_SOL);
const cost = U64.to(totalCostSol * 1.05, LAMPORTS_PER_SOL);
return cost;
}

async createRequestRelayInstruction(
Expand All @@ -99,8 +97,7 @@ export class NttQuoter {
.accounts({
payer,
instance: this.instance,
feeRecipient: (await this.getInstance()).feeRecipient,
registeredChain: this.registeredChainPda(config.wh.toChainId(chain)),
registeredChain: this.registeredChainPda(toChainId(chain)),
outboxItem,
relayRequest: this.relayRequestPda(outboxItem),
systemProgram: SystemProgram.programId,
Expand All @@ -120,7 +117,7 @@ export class NttQuoter {

async getRegisteredChain(chain: ChainName | ChainId) {
const data = await this.program.account.registeredChain.fetch(
this.registeredChainPda(config.wh.toChainId(chain)),
this.registeredChainPda(toChainId(chain)),
);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ export type NttQuoter = {
isMut: false;
isSigner: false;
},
{
name: 'feeRecipient';
isMut: true;
isSigner: false;
},
{
name: 'registeredChain';
isMut: false;
Expand Down Expand Up @@ -463,11 +458,6 @@ export const IDL: NttQuoter = {
isMut: false,
isSigner: false,
},
{
name: 'feeRecipient',
isMut: true,
isSigner: false,
},
{
name: 'registeredChain',
isMut: false,
Expand Down

0 comments on commit 96dbe72

Please sign in to comment.