Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync with staging #189

Merged
merged 4 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 4 additions & 21 deletions transactions/bridge/layerZero/layerZeroTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import { getMessagesBySrcTxHash } from "@layerzerolabs/scan-client";
import Web3 from "web3";
import { checkUseAdapterParams, estimateOFTSendGasFee } from "./helpers";
import { createApprovalTxs } from "@/transactions/erc20";
import BigNumber from "bignumber.js";
import { _oftDepositOrWithdrawTx, _oftTransferTx } from "./txCreators";
import { _oftTransferTx } from "./txCreators";
import { displayAmount } from "@/utils/formatting";
import { BridgingMethod, getBridgeMethodInfo } from "..";

Expand Down Expand Up @@ -71,7 +70,7 @@ export async function bridgeLayerZeroTx(
);

/** estimate gas */
const { data: gas, error: gasError } = await estimateOFTSendGasFee(
let { data: gas, error: gasError } = await estimateOFTSendGasFee(
txParams.token.chainId,
toLZChainId,
txParams.token.address,
Expand Down Expand Up @@ -111,25 +110,9 @@ export async function bridgeLayerZeroTx(
);
if (oftBalanceError) throw oftBalanceError;
// if OFT balance is less than amount, then user needs to deposit
// Native OFT contract will handle the deposit (just send extra gas to cover deposit amount)
if (oftBalance.lt(txParams.amount)) {
const amountToDeposit = new BigNumber(txParams.amount)
.minus(oftBalance)
.toString();
// push tx
txList.push(
_oftDepositOrWithdrawTx(
txParams.token.chainId,
txParams.ethSender,
true,
txParams.token.address,
amountToDeposit,
TX_DESCRIPTIONS.OFT_DEPOSIT_OR_WITHDRAW(
txParams.token.symbol,
displayAmount(amountToDeposit, txParams.token.decimals),
true
)
)
);
gas = gas.plus(txParams.amount).minus(oftBalance);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions utils/tokens/tokenTypes.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ERC20Token, IBCToken, OFTToken } from "@/config/interfaces";
* @see ERC20Token
*/
export function isERC20Token(object: any): object is ERC20Token {
if (object === null || object === undefined) return false;
return (
typeof object === "object" &&
"id" in object &&
Expand All @@ -30,6 +31,7 @@ export function isERC20Token(object: any): object is ERC20Token {
* @see ERC20Token
*/
export function isERC20TokenList(array: Array<object>): array is ERC20Token[] {
if (array === null || array === undefined) return false;
return array.every(isERC20Token);
}

Expand All @@ -40,6 +42,7 @@ export function isERC20TokenList(array: Array<object>): array is ERC20Token[] {
* @see IBCToken
*/
export function isIBCToken(object: any): object is IBCToken {
if (object === null || object === undefined) return false;
return (
typeof object === "object" &&
"id" in object &&
Expand All @@ -54,6 +57,7 @@ export function isIBCToken(object: any): object is IBCToken {
}

export function isOFTToken(object: any): object is OFTToken {
if (object === null || object === undefined) return false;
return (
isERC20Token(object) &&
"isOFTProxy" in object &&
Expand Down
Loading