Skip to content

Commit

Permalink
ntt/solana: relayer fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kev1n-peters committed Apr 15, 2024
1 parent 8cc7677 commit d214507
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 4 additions & 1 deletion wormhole-connect/src/routes/ntt/chains/solana/nttManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,13 @@ export class NttManagerSolana {
);
if (!nttConfig || !nttConfig.solanaQuoter) throw new Error('no quoter');
const quoter = new NttQuoter(nttConfig.solanaQuoter);
const fee = await quoter.calcRelayCost(toChain);
const fee = await quoter.calcRelayCost(toChain, nttConfig.address);
const relayIx = await quoter.createRequestRelayInstruction(
payer,
outboxItem.publicKey,
toChain,
fee,
nttConfig.address,
);
tx.add(relayIx);
}
Expand All @@ -160,6 +161,7 @@ export class NttManagerSolana {
}

async receiveMessage(vaa: string, payer: string): Promise<string> {
await this.checkAbi(payer);
const core = CONFIG.wh.mustGetContracts('solana').core;
if (!core) throw new Error('Core not found');
const config = await this.getConfig();
Expand Down Expand Up @@ -313,6 +315,7 @@ export class NttManagerSolana {
recipientAddress: string,
payer: string,
): Promise<string> {
await this.checkAbi(payer);
const payerPublicKey = new PublicKey(payer);
const releaseArgs = {
payer: payerPublicKey,
Expand Down
10 changes: 8 additions & 2 deletions wormhole-connect/src/routes/ntt/chains/solana/nttQuoter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,14 @@ export class NttQuoter {
}

// calculates the relay cost in lamports
async calcRelayCost(chain: ChainName | ChainId, requestedGasDropoffEth = 0) {
async calcRelayCost(
chain: ChainName | ChainId,
nttProgramId: string,
requestedGasDropoffEth = 0,
) {
const [chainData, nttData, instanceData, rentCost] = await Promise.all([
this.getRegisteredChain(chain),
this.getRegisteredNtt(this.program.programId),
this.getRegisteredNtt(new PublicKey(nttProgramId)),
this.getInstance(),
this.program.provider.connection.getMinimumBalanceForRentExemption(
this.program.account.relayRequest.size,
Expand Down Expand Up @@ -96,6 +100,7 @@ export class NttQuoter {
outboxItem: PublicKey,
chain: ChainName | ChainId,
maxFee: BN,
nttProgramId: string,
) {
return this.program.methods
.requestRelay({
Expand All @@ -106,6 +111,7 @@ export class NttQuoter {
payer,
instance: this.instance,
registeredChain: this.registeredChainPda(toChainId(chain)),
registeredNtt: this.registeredNttPda(new PublicKey(nttProgramId)),
outboxItem,
relayRequest: this.relayRequestPda(outboxItem),
systemProgram: SystemProgram.programId,
Expand Down
5 changes: 4 additions & 1 deletion wormhole-connect/src/routes/ntt/nttRelay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ export class NttRelay extends NttBase {
if (toChainName(sourceChain) === 'solana') {
if (!nttConfig.solanaQuoter) throw new Error('no solana quoter');
const quoter = new NttQuoter(nttConfig.solanaQuoter);
const relayCost = await quoter.calcRelayCost(destChain);
const relayCost = await quoter.calcRelayCost(
destChain,
nttConfig.address,
);
return { fee: BigNumber.from(relayCost.toString()), feeToken: 'native' };
}
throw new Error('unsupported chain');
Expand Down

0 comments on commit d214507

Please sign in to comment.