Skip to content

Commit

Permalink
tmp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianscatularo committed Sep 19, 2023
1 parent 190e076 commit 409857b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 19 deletions.
7 changes: 3 additions & 4 deletions src/hooks/useHandleAttest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ import {
} from "@certusone/wormhole-sdk/lib/cjs/sui";
import { useSuiWallet } from "../contexts/SuiWalletContext";
import { useSeiWallet } from "../contexts/SeiWalletContext";
import { SeiWallet } from "@xlabs-libs/wallet-aggregator-sei";
import { SeiWallet, buildExecuteMessage } from "@xlabs-libs/wallet-aggregator-sei";
import { parseSequenceFromLogSei } from "../utils/sei";
import { calculateFee } from "@cosmjs/stargate";
import { SuiTransactionBlockResponse } from "@mysten/sui.js";
Expand Down Expand Up @@ -606,7 +606,6 @@ async function sei(
dispatch: any,
enqueueSnackbar: any,
wallet: SeiWallet,
walletAddress: string,
asset: string
) {
dispatch(setIsSending(true));
Expand All @@ -625,7 +624,7 @@ async function sei(
},
};

const fee = calculateFee(750000, "0.1usei");
const fee = calculateFee(10000000, "0.1usei");
const tx = await wallet.executeMultiple({
instructions: [{ contractAddress: tokenBridgeAddress, msg }],
fee,
Expand Down Expand Up @@ -716,7 +715,7 @@ export function useHandleAttest() {
} else if (sourceChain === CHAIN_ID_INJECTIVE && injWallet && injAddress) {
injective(dispatch, enqueueSnackbar, injWallet, injAddress, sourceAsset);
} else if (sourceChain === CHAIN_ID_SEI && seiWallet && seiAddress) {
sei(dispatch, enqueueSnackbar, seiWallet, seiAddress, sourceAsset);
sei(dispatch, enqueueSnackbar, seiWallet, sourceAsset);
} else if (
sourceChain === CHAIN_ID_SUI &&
suiWallet?.isConnected() &&
Expand Down
17 changes: 12 additions & 5 deletions src/hooks/useHandleCreateWrapped.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ import { createWrappedOnSuiPrepare } from "../utils/suiPublishHotfix";
import { calculateFee } from "@cosmjs/stargate";
import { createWrappedOnSei, updateWrappedOnSei } from "../utils/sei";
import { useSeiWallet } from "../contexts/SeiWalletContext";
import { SeiWallet } from "@xlabs-libs/wallet-aggregator-sei";
import { SeiWallet, buildExecuteMessage } from "@xlabs-libs/wallet-aggregator-sei";

// TODO: replace with SDK method -
export async function updateWrappedOnSui(
Expand Down Expand Up @@ -374,20 +374,27 @@ async function sei(
signedVAA: Uint8Array,
shouldUpdate: boolean
) {
console.log("inside SEI method pa!");
dispatch(setIsCreating(true));
const tokenBridgeAddress = getTokenBridgeAddressForChain(CHAIN_ID_SEI);
try {
const msg = shouldUpdate
? await updateWrappedOnSei(signedVAA)
: await createWrappedOnSei(signedVAA);

const fee = calculateFee(100000000, "0.1usei");
const currentFee = await wallet.calculateFee({
msgs: [buildExecuteMessage(
wallet.getAddress()!,
tokenBridgeAddress,
[msg]
)],
fee,
memo: "Wormhole - Create Wrapped",
})
// TODO: is this right?
const fee = calculateFee(750000, "0.1usei");

const tx = await wallet.executeMultiple({
instructions: [{ msg: msg, contractAddress: tokenBridgeAddress }],
fee,
fee: calculateFee(parseInt(currentFee), "0.1usei"),
memo: "Wormhole - Create Wrapped",
});

Expand Down
28 changes: 22 additions & 6 deletions src/hooks/useHandleRedeem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ import { newThresholdWormholeGateway } from "../assets/providers/tbtc/solana/Wor
import { calculateFee } from "@cosmjs/stargate";
import { fromUint8Array } from "js-base64";
import { useSeiWallet } from "../contexts/SeiWalletContext";
import { SeiWallet } from "@xlabs-libs/wallet-aggregator-sei";
import {
SeiWallet,
buildExecuteMessage,
} from "@xlabs-libs/wallet-aggregator-sei";

async function algo(
dispatch: any,
Expand Down Expand Up @@ -322,17 +325,22 @@ async function sei(
dispatch(setIsRedeeming(true));
try {
// TODO: is this right?
const fee = calculateFee(800000, "0.1usei");

const fee = calculateFee(100000000, "0.1usei");

const vaa = parseVaa(signedVAA);
const transfer = parseTokenTransferPayload(vaa.payload);
const receiver = cosmos.humanAddress("sei", transfer.to);
const contractAddress =
receiver === SEI_TRANSLATOR
? SEI_TRANSLATOR
: getTokenBridgeAddressForChain(CHAIN_ID_SEI);

const instructions =
receiver === SEI_TRANSLATOR
? [
{
contractAddress: SEI_TRANSLATOR,
contractAddress,
msg: {
complete_transfer_and_convert: {
vaa: fromUint8Array(signedVAA),
Expand All @@ -342,18 +350,26 @@ async function sei(
]
: [
{
contractAddress: getTokenBridgeAddressForChain(CHAIN_ID_SEI),
contractAddress,
msg: {
submit_vaa: {
data: fromUint8Array(signedVAA),
},
},
},
];

const simulatedFee = await wallet.calculateFee({
msgs: [
buildExecuteMessage(wallet.getAddress()!, contractAddress, [
instructions.map((i) => i.msg),
]),
],
fee,
memo: "Wormhole - Create Wrapped",
});
const tx = await wallet.executeMultiple({
instructions,
fee,
fee: calculateFee(parseInt(simulatedFee), "0.1usei"),
memo: "Wormhole - Complete Transfer",
});

Expand Down
21 changes: 17 additions & 4 deletions src/hooks/useHandleTransfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ import { newThresholdWormholeGateway } from "../assets/providers/tbtc/solana/Wor
import { calculateFee } from "@cosmjs/stargate";
import { parseSequenceFromLogSei } from "../utils/sei";
import { useSeiWallet } from "../contexts/SeiWalletContext";
import { SeiWallet } from "@xlabs-libs/wallet-aggregator-sei";
import {
SeiWallet,
buildExecuteMessage,
} from "@xlabs-libs/wallet-aggregator-sei";
import { SuiTransactionBlockResponse } from "@mysten/sui.js";

type AdditionalPayloadOverride = {
Expand Down Expand Up @@ -845,8 +848,7 @@ async function sei(
const tokenBridgeAddress = getTokenBridgeAddressForChain(CHAIN_ID_SEI);

const encodedRecipient = Buffer.from(targetAddress).toString("base64");

const fee = calculateFee(750000, "0.1usei");
const fee = calculateFee(100000000, "0.1usei");

// NOTE: this only supports transferring out via the Sei CW20 <> Bank translator
// or the usei native denomination
Expand Down Expand Up @@ -891,10 +893,21 @@ async function sei(
],
},
];
const simulatedFee = await wallet.calculateFee({
msgs: [
buildExecuteMessage(
wallet.getAddress()!,
tokenBridgeAddress,
instructions.map((i) => i.msg)
),
],
fee,
memo: "Wormhole - Create Wrapped",
});

const tx = await wallet.executeMultiple({
instructions,
fee,
fee: calculateFee(parseInt(simulatedFee), "0.1usei"),
memo: "Wormhole - Initiate Transfer",
});

Expand Down

0 comments on commit 409857b

Please sign in to comment.