Skip to content

Commit

Permalink
solana sdk refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kev1n-peters committed Feb 28, 2024
1 parent 78fb12e commit b0ddb26
Show file tree
Hide file tree
Showing 7 changed files with 512 additions and 913 deletions.
8 changes: 7 additions & 1 deletion wormhole-connect/src/hooks/useDeliveryStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useDispatch, useSelector } from 'react-redux';
import { RootState } from 'store';
import { setRedeemTx, setDeliveryStatus } from 'store/redeem';
import { sleep } from 'utils';
import { isEvmChain } from 'utils/sdk';
import { getEmitterAndSequence } from 'utils/vaa';

const BASE_URL = `https://api.${
Expand All @@ -22,7 +23,12 @@ const useDeliveryStatus = () => {
(state: RootState) => state.redeem.signedMessage,
);
useEffect(() => {
if (!signedMessage || route !== Route.NttRelay) return;
if (
!signedMessage ||
route !== Route.NttRelay ||
!isEvmChain(signedMessage.toChain) // Currently, only EVM chains support standard relayer
)
return;
const { emitterChain, emitterAddress, sequence } =
getEmitterAndSequence(signedMessage);
let active = true;
Expand Down
18 changes: 9 additions & 9 deletions wormhole-connect/src/routes/ntt/payloads/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ export class TransceiverMessage<A> {
constructor(
sourceNttManager: Buffer,
recipientNttManager: Buffer,
ntt_managerPayload: NttManagerMessage<A>,
nttManagerPayload: NttManagerMessage<A>,
transceiverPayload: Buffer,
) {
this.sourceNttManager = sourceNttManager;
this.recipientNttManager = recipientNttManager;
this.nttManagerPayload = ntt_managerPayload;
this.nttManagerPayload = nttManagerPayload;
this.transceiverPayload = transceiverPayload;
}

Expand All @@ -32,19 +32,19 @@ export class TransceiverMessage<A> {
}
const sourceNttManager = data.subarray(4, 36);
const recipientNttManager = data.subarray(36, 68);
const ntt_managerPayloadLen = data.readUInt16BE(68);
const ntt_managerPayload = deserializer(
data.subarray(70, 70 + ntt_managerPayloadLen),
const nttManagerPayloadLen = data.readUInt16BE(68);
const nttManagerPayload = deserializer(
data.subarray(70, 70 + nttManagerPayloadLen),
);
const transceiverPayloadLen = data.readUInt16BE(70 + ntt_managerPayloadLen);
const transceiverPayloadLen = data.readUInt16BE(70 + nttManagerPayloadLen);
const transceiverPayload = data.subarray(
72 + ntt_managerPayloadLen,
72 + ntt_managerPayloadLen + transceiverPayloadLen,
72 + nttManagerPayloadLen,
72 + nttManagerPayloadLen + transceiverPayloadLen,
);
return new TransceiverMessage(
sourceNttManager,
recipientNttManager,
ntt_managerPayload,
nttManagerPayload,
transceiverPayload,
);
}
Expand Down
15 changes: 15 additions & 0 deletions wormhole-connect/src/routes/ntt/platforms/evm/getMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ export const getMessageEvm = async (
const wormholeLog = await getWormholeLogEvm(fromChain, receipt);
const parsedWormholeLog =
Implementation__factory.createInterface().parseLog(wormholeLog);

//const relayingInfoEvent = receipt.logs.find((log) => log.topics[0] === '');
//if (!relayingInfoEvent) {
// throw new Error('RelayingInfo event not found');
//}
//const relayingInfoIface = new ethers.utils.Interface([
// 'event RelayingInfo(uint8 relayingType, uint256 deliveryPayment)',
//]);
//const parsedRelayingInfo = relayingInfoIface.parseLog(relayingInfoEvent);
//const { relayingType, deliveryPayment } = parsedRelayingInfo.args;
//if (relayingType !== RelayingType.Standard {
//} else if (relayingType === relayingType.Manual || relayingType === relayingType.Special) {
//} else {
// throw new Error(`Unexpected relaying type ${relayingType}`);
//}
let payload: Buffer;
let relayerFee = '';
if (parsedWormholeLog.args.sender === token.ntt?.wormholeTransceiver) {
Expand Down
18 changes: 9 additions & 9 deletions wormhole-connect/src/routes/ntt/platforms/evm/nttManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ export class NttManagerEvm {

async getInboundQueuedTransfer(
emitterChain: ChainName | ChainId,
nttManagerMessage: NttManagerMessage<NativeTokenTransfer>,
message: NttManagerMessage<NativeTokenTransfer>,
): Promise<InboundQueuedTransfer | undefined> {
const digest = getNttManagerMessageDigest(emitterChain, nttManagerMessage);
const digest = getNttManagerMessageDigest(emitterChain, message);
const queuedTransfer = await this.nttManager.getInboundQueuedTransfer(
digest,
);
Expand All @@ -162,9 +162,9 @@ export class NttManagerEvm {

async completeInboundQueuedTransfer(
emitterChain: ChainName | ChainId,
nttManagerMessage: NttManagerMessage<NativeTokenTransfer>,
message: NttManagerMessage<NativeTokenTransfer>,
): Promise<string> {
const digest = getNttManagerMessageDigest(emitterChain, nttManagerMessage);
const digest = getNttManagerMessageDigest(emitterChain, message);
try {
const tx =
await this.nttManager.populateTransaction.completeInboundQueuedTransfer(
Expand All @@ -178,9 +178,9 @@ export class NttManagerEvm {

async isMessageExecuted(
emitterChain: ChainName | ChainId,
nttManagerMessage: NttManagerMessage<NativeTokenTransfer>,
message: NttManagerMessage<NativeTokenTransfer>,
): Promise<boolean> {
const digest = getNttManagerMessageDigest(emitterChain, nttManagerMessage);
const digest = getNttManagerMessageDigest(emitterChain, message);
return this.nttManager.isMessageExecuted(digest);
}

Expand All @@ -190,15 +190,15 @@ export class NttManagerEvm {

async fetchRedeemTx(
emitterChain: ChainName | ChainId,
nttManagerMessage: NttManagerMessage<NativeTokenTransfer>,
message: NttManagerMessage<NativeTokenTransfer>,
): Promise<string | undefined> {
const digest = getNttManagerMessageDigest(emitterChain, nttManagerMessage);
const digest = getNttManagerMessageDigest(emitterChain, message);
// @ts-ignore
// TODO: why does the abi expect null for the digest?
const eventFilter = this.nttManager.filters.TransferRedeemed(digest);
const provider = wh.mustGetProvider(this.chain);
const currentBlock = await provider.getBlockNumber();
const chainName = wh.toChainName(nttManagerMessage.payload.recipientChain);
const chainName = wh.toChainName(message.payload.recipientChain);
const chainConfig = CHAINS[chainName]!;
const events = await this.nttManager.queryFilter(
eventFilter,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// NOTE: The generics have been removed from the IDL to prevent
// runtime errors when the IDL is used in the browser.
export type ExampleNativeTokenTransfers = {
version: '0.1.0';
name: 'example_native_token_transfers';
Expand Down
Loading

0 comments on commit b0ddb26

Please sign in to comment.