Skip to content

Commit 96dbe72

Browse files
committed
solana relayer fixes
1 parent a5c6af2 commit 96dbe72

File tree

6 files changed

+19
-27
lines changed

6 files changed

+19
-27
lines changed

sdk/src/contexts/solana/utils/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ export * from './wormhole/cpi';
2525
* @category Solana
2626
*/
2727
export * from './tokenBridge/cpi';
28+
export * from './computeBudget';

wormhole-connect/src/config/testnet/tokens.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2333,7 +2333,7 @@ export const TESTNET_TOKENS: TokensConfig = {
23332333
// If the transceiver is split into a separate contract, this address
23342334
// and route code should be updated to support the new structure.
23352335
wormholeTransceiver: 'nTTh3bZ5Aer6xboWZe39RDEft4MeVxSQ8D1EYAVLZw9',
2336-
solanaQuoter: '',
2336+
solanaQuoter: 'NqTdGLLL6b6bFo7YESNEezocgF8onH5cst5EdH791en',
23372337
},
23382338
},
23392339
};

wormhole-connect/src/routes/ntt/nttRelay.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class NttRelay extends NttBase {
9797
if (!nttConfig.solanaQuoter) throw new Error('no solana quoter');
9898
const quoter = new NttQuoter(nttConfig.solanaQuoter);
9999
const relayCost = await quoter.calcRelayCost(destChain);
100-
return { fee: BigNumber.from(relayCost), feeToken: 'native' };
100+
return { fee: BigNumber.from(relayCost.toString()), feeToken: 'native' };
101101
}
102102
throw new Error('unsupported chain');
103103
}

wormhole-connect/src/routes/ntt/platforms/solana/nttManager.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import {
2+
addComputeBudget,
23
ChainId,
34
ChainName,
45
TokenId,
56
} from '@wormhole-foundation/wormhole-connect-sdk';
67
import { InboundQueuedTransfer } from '../../types';
7-
import { solanaContext, toChainId } from 'utils/sdk';
8+
import { solanaContext, toChainId, toChainName } from 'utils/sdk';
89
import { TransferWallet, postVaa, signAndSendTransaction } from 'utils/wallet';
910
import {
1011
Connection,
@@ -62,7 +63,7 @@ export class NttManagerSolana {
6263
readonly wormholeId: string;
6364

6465
constructor(readonly nttId: string) {
65-
const connection = solanaContext().connection;
66+
const { connection } = solanaContext();
6667
if (!connection) throw new Error('Connection not found');
6768
this.connection = connection;
6869
this.program = new Program(IDL, nttId, { connection });
@@ -91,7 +92,7 @@ export class NttManagerSolana {
9192
payer,
9293
from: tokenAccount,
9394
amount: new BN(amount.toString()),
94-
recipientChain: CONFIG.wh.toChainName(toChain),
95+
recipientChain: toChainName(toChain),
9596
recipientAddress: destContext.formatAddress(recipient),
9697
fromAuthority: payer,
9798
outboxItem: outboxItem.publicKey,
@@ -141,6 +142,7 @@ export class NttManagerSolana {
141142
tx.feePayer = payer;
142143
const { blockhash } = await this.connection.getLatestBlockhash('finalized');
143144
tx.recentBlockhash = blockhash;
145+
await addComputeBudget(this.connection, tx);
144146
tx.partialSign(outboxItem);
145147
const txId = await signAndSendTransaction(
146148
'solana',
@@ -217,6 +219,7 @@ export class NttManagerSolana {
217219
tx.feePayer = payerPublicKey;
218220
const { blockhash } = await this.connection.getLatestBlockhash('finalized');
219221
tx.recentBlockhash = blockhash;
222+
await addComputeBudget(this.connection, tx);
220223
const txId = await signAndSendTransaction(
221224
'solana',
222225
tx,
@@ -332,6 +335,7 @@ export class NttManagerSolana {
332335
tx.feePayer = payerPublicKey;
333336
const { blockhash } = await this.connection.getLatestBlockhash('finalized');
334337
tx.recentBlockhash = blockhash;
338+
await addComputeBudget(this.connection, tx);
335339
const txId = await signAndSendTransaction(
336340
'solana',
337341
tx,
@@ -434,7 +438,7 @@ export class NttManagerSolana {
434438
}
435439

436440
transceiverPeerAccountAddress(chain: ChainName | ChainId): PublicKey {
437-
const chainId = CONFIG.wh.toChainId(chain);
441+
const chainId = toChainId(chain);
438442
return this.derivePda([
439443
Buffer.from('transceiver_peer'),
440444
new BN(chainId).toBuffer('be', 2),

wormhole-connect/src/routes/ntt/platforms/solana/nttQuoter.ts

+8-11
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import {
88
} from '@solana/web3.js';
99
import { BN, Program } from '@coral-xyz/anchor';
1010
import { NttQuoter as NttQuoterType, IDL } from './types/ntt_quoter';
11-
import { solanaContext } from 'utils/sdk';
12-
import config from 'config';
11+
import { solanaContext, toChainId } from 'utils/sdk';
1312

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

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

7372
const totalNativeGasCostUsd =
7473
chainData.nativePriceUsd *
75-
chainData.gasPriceGwei *
76-
EVM_GAS_COST *
77-
GWEI_PER_ETH;
74+
((chainData.gasPriceGwei * EVM_GAS_COST) / GWEI_PER_ETH);
7875

7976
const totalCostSol =
80-
rentCost +
77+
rentCost / LAMPORTS_PER_SOL +
8178
(chainData.basePriceUsd + totalNativeGasCostUsd) /
8279
instanceData.solPriceUsd;
8380

8481
// Add 5% to account for possible price updates while the tx is in flight
85-
return U64.to(totalCostSol * 1.05, LAMPORTS_PER_SOL);
82+
const cost = U64.to(totalCostSol * 1.05, LAMPORTS_PER_SOL);
83+
return cost;
8684
}
8785

8886
async createRequestRelayInstruction(
@@ -99,8 +97,7 @@ export class NttQuoter {
9997
.accounts({
10098
payer,
10199
instance: this.instance,
102-
feeRecipient: (await this.getInstance()).feeRecipient,
103-
registeredChain: this.registeredChainPda(config.wh.toChainId(chain)),
100+
registeredChain: this.registeredChainPda(toChainId(chain)),
104101
outboxItem,
105102
relayRequest: this.relayRequestPda(outboxItem),
106103
systemProgram: SystemProgram.programId,
@@ -120,7 +117,7 @@ export class NttQuoter {
120117

121118
async getRegisteredChain(chain: ChainName | ChainId) {
122119
const data = await this.program.account.registeredChain.fetch(
123-
this.registeredChainPda(config.wh.toChainId(chain)),
120+
this.registeredChainPda(toChainId(chain)),
124121
);
125122

126123
return {

wormhole-connect/src/routes/ntt/platforms/solana/types/ntt_quoter.ts

-10
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ export type NttQuoter = {
1515
isMut: false;
1616
isSigner: false;
1717
},
18-
{
19-
name: 'feeRecipient';
20-
isMut: true;
21-
isSigner: false;
22-
},
2318
{
2419
name: 'registeredChain';
2520
isMut: false;
@@ -463,11 +458,6 @@ export const IDL: NttQuoter = {
463458
isMut: false,
464459
isSigner: false,
465460
},
466-
{
467-
name: 'feeRecipient',
468-
isMut: true,
469-
isSigner: false,
470-
},
471461
{
472462
name: 'registeredChain',
473463
isMut: false,

0 commit comments

Comments
 (0)