bridge_ui: solana getSignedVAA

Change-Id: I49e1dff820836db776297eac3ba667070fd3871e
This commit is contained in:
Evan Gray 2021-08-04 19:46:01 -04:00 committed by Hendrik Hofstadt
parent 5187120fa0
commit 8444363ac8
2 changed files with 28 additions and 5 deletions

View File

@ -7,6 +7,7 @@ import {
TextField,
Typography,
} from "@material-ui/core";
import { ethers } from "ethers";
import { useCallback, useState } from "react";
import { useEthereumProvider } from "../contexts/EthereumProviderContext";
import { useSolanaWallet } from "../contexts/SolanaWalletContext";
@ -50,6 +51,7 @@ const useStyles = makeStyles((theme) => ({
},
}));
// TODO: ensure that both wallets are connected to the same known network
// TODO: loaders and such, navigation block?
// TODO: refresh displayed token amount after transfer somehow, could be resolved by having different components appear
// TODO: warn if amount exceeds balance
@ -116,7 +118,7 @@ function Transfer() {
console.log(isCheckingWrapped, wrappedAsset);
// TODO: make a helper function for this
const isWrapped = true;
//wrappedAsset && wrappedAsset !== ethers.constants.AddressZero;
// wrappedAsset && wrappedAsset !== ethers.constants.AddressZero;
// TODO: dynamically get "to" wallet
const handleTransferClick = useCallback(() => {
// TODO: more generic way of calling these

View File

@ -183,9 +183,8 @@ export function transferFromSolana(
});
// TODO: pass in connection
// Add transfer instruction to transaction
const { transfer_native_ix, approval_authority_address } = await import(
"token-bridge"
);
const { transfer_native_ix, approval_authority_address, emitter_address } =
await import("token-bridge");
const approvalIx = Token.createApproveInstruction(
TOKEN_PROGRAM_ID,
new PublicKey(fromAddress),
@ -208,7 +207,6 @@ export function transferFromSolana(
targetChain
)
);
console.log(ix);
const transaction = new Transaction().add(transferIx, approvalIx, ix);
const { blockhash } = await connection.getRecentBlockhash();
transaction.recentBlockhash = blockhash;
@ -220,6 +218,29 @@ export function transferFromSolana(
console.log("SENT", txid);
const conf = await connection.confirmTransaction(txid);
console.log("CONFIRMED", conf);
const info = await connection.getTransaction(txid);
console.log("INFO", info);
// TODO: better parsing, safer
const SEQ_LOG = "Program log: Sequence: ";
const sequence = info?.meta?.logMessages
?.filter((msg) => msg.startsWith(SEQ_LOG))[0]
.replace(SEQ_LOG, "");
if (!sequence) {
throw new Error("sequence not found");
}
console.log("SEQ", sequence);
const emitterAddress = Buffer.from(
zeroPad(
new PublicKey(emitter_address(SOL_TOKEN_BRIDGE_ADDRESS)).toBytes(),
32
)
).toString("hex");
const { vaaBytes } = await getSignedVAA(
CHAIN_ID_SOLANA,
emitterAddress,
sequence
);
console.log("SIGNED VAA:", vaaBytes);
})();
}