67 lines
1.8 KiB
TypeScript
67 lines
1.8 KiB
TypeScript
import { Connection, PublicKey, Transaction } from "@solana/web3.js";
|
|
import { ethers } from "ethers";
|
|
import { Bridge__factory } from "../ethers-contracts";
|
|
import { ConnectedWallet as TerraConnectedWallet } from "@terra-money/wallet-provider";
|
|
import { MsgExecuteContract } from "@terra-money/terra.js";
|
|
import { ixFromRust } from "../solana";
|
|
import { fromUint8Array } from "js-base64";
|
|
|
|
export async function createWrappedOnEth(
|
|
tokenBridgeAddress: string,
|
|
signer: ethers.Signer,
|
|
signedVAA: Uint8Array
|
|
) {
|
|
const bridge = Bridge__factory.connect(tokenBridgeAddress, signer);
|
|
const v = await bridge.createWrapped(signedVAA);
|
|
const receipt = await v.wait();
|
|
return receipt;
|
|
}
|
|
|
|
export async function createWrappedOnTerra(
|
|
tokenBridgeAddress: string,
|
|
wallet: TerraConnectedWallet,
|
|
signedVAA: Uint8Array,
|
|
) {
|
|
console.log(tokenBridgeAddress);
|
|
console.log(wallet.terraAddress);
|
|
console.log(signedVAA);
|
|
await wallet.post({
|
|
msgs: [
|
|
new MsgExecuteContract(
|
|
wallet.terraAddress,
|
|
tokenBridgeAddress,
|
|
{
|
|
submit_vaa: {
|
|
data: fromUint8Array(signedVAA),
|
|
},
|
|
},
|
|
{ uluna: 1000 }
|
|
),
|
|
],
|
|
memo: "Create Wrapped",
|
|
});
|
|
}
|
|
|
|
export async function createWrappedOnSolana(
|
|
connection: Connection,
|
|
bridgeAddress: string,
|
|
tokenBridgeAddress: string,
|
|
payerAddress: string,
|
|
signedVAA: Uint8Array
|
|
) {
|
|
const { create_wrapped_ix } = await import("../solana/token/token_bridge");
|
|
const ix = ixFromRust(
|
|
create_wrapped_ix(
|
|
tokenBridgeAddress,
|
|
bridgeAddress,
|
|
payerAddress,
|
|
signedVAA
|
|
)
|
|
);
|
|
const transaction = new Transaction().add(ix);
|
|
const { blockhash } = await connection.getRecentBlockhash();
|
|
transaction.recentBlockhash = blockhash;
|
|
transaction.feePayer = new PublicKey(payerAddress);
|
|
return transaction;
|
|
}
|