unite onchain tx as one function with gas sanitization
Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
This commit is contained in:
parent
37831d1a1c
commit
5dc0bb3a1b
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "ghost-dao-interface",
|
"name": "ghost-dao-interface",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.7.20",
|
"version": "0.7.21",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
@ -1,10 +1,6 @@
|
|||||||
import { useReadContract, useReadContracts } from "wagmi";
|
import { useReadContract, useReadContracts } from "wagmi";
|
||||||
import { simulateContract, writeContract, waitForTransactionReceipt } from "@wagmi/core";
|
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
|
|
||||||
import { isNetworkLegacyType } from "../../constants";
|
|
||||||
import { config } from "../../config";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
BOND_DEPOSITORY_ADDRESSES,
|
BOND_DEPOSITORY_ADDRESSES,
|
||||||
DAO_TREASURY_ADDRESSES,
|
DAO_TREASURY_ADDRESSES,
|
||||||
@ -17,7 +13,14 @@ import { abi as BondingCalculatorAbi } from "../../abi/GhostBondingCalculator.js
|
|||||||
import { useReservePrice, useFtsoPrice } from "../prices";
|
import { useReservePrice, useFtsoPrice } from "../prices";
|
||||||
import { useOrinalCoefficient } from "../treasury";
|
import { useOrinalCoefficient } from "../treasury";
|
||||||
import { useTokenSymbol, useTokenSymbols } from "../tokens";
|
import { useTokenSymbol, useTokenSymbols } from "../tokens";
|
||||||
import { getTokenAddress, getTokenIcons, getBondNameDisplayName, getTokenPurchaseLink } from "../helpers";
|
import {
|
||||||
|
getTokenAddress,
|
||||||
|
getTokenIcons,
|
||||||
|
getBondNameDisplayName,
|
||||||
|
getTokenPurchaseLink,
|
||||||
|
executeOnChainTransaction
|
||||||
|
} from "../helpers";
|
||||||
|
|
||||||
import { DecimalBigNumber } from "../../helpers/DecimalBigNumber";
|
import { DecimalBigNumber } from "../../helpers/DecimalBigNumber";
|
||||||
import { shorten } from "../../helpers";
|
import { shorten } from "../../helpers";
|
||||||
import { tokenNameConverter } from "../../helpers/tokenConverter";
|
import { tokenNameConverter } from "../../helpers/tokenConverter";
|
||||||
@ -267,78 +270,61 @@ export const useNotes = (chainId, address) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const purchaseBond = async ({ chainId, bondId, amount, maxPrice, user, sender, referral, isNative }) => {
|
export const purchaseBond = async ({ chainId, bondId, amount, maxPrice, user, sender, referral, isNative }) => {
|
||||||
const args = [
|
const args = [bondId, amount, maxPrice, user, referral];
|
||||||
bondId,
|
|
||||||
amount,
|
|
||||||
maxPrice,
|
|
||||||
user,
|
|
||||||
referral
|
|
||||||
];
|
|
||||||
const messages = {
|
const messages = {
|
||||||
replacedMsg: "Bond transaction was replaced. Wait for inclusion please.",
|
replacedMsg: "Bond transaction was replaced. Wait for inclusion please.",
|
||||||
successMsg: `Bond successfully purchased for ${shorten(user)}! Wait until it'll mature before claim.`,
|
successMsg: `Bond successfully purchased for ${shorten(user)}! Wait until it'll mature before claim.`,
|
||||||
errorMsg: "Bond transaction failed. Check logs for error detalization.",
|
errorMsg: "Bond transaction failed. Check logs for error detalization.",
|
||||||
};
|
};
|
||||||
await executeOnChainTransaction(
|
|
||||||
|
await executeOnChainTransaction({
|
||||||
chainId,
|
chainId,
|
||||||
"deposit",
|
|
||||||
args,
|
args,
|
||||||
sender,
|
|
||||||
messages,
|
messages,
|
||||||
isNative ? amount : undefined
|
abi: BondAbi,
|
||||||
);
|
address: BOND_DEPOSITORY_ADDRESSES[chainId],
|
||||||
|
functionName: "deposit",
|
||||||
|
account: user,
|
||||||
|
value: isNative ? amount : undefined
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export const redeem = async ({ chainId, user, isGhst, indexes }) => {
|
export const redeem = async ({ chainId, user, isGhst, indexes }) => {
|
||||||
const args = [
|
const args = [user, isGhst, indexes];
|
||||||
user,
|
|
||||||
isGhst,
|
|
||||||
indexes
|
|
||||||
];
|
|
||||||
const messages = {
|
const messages = {
|
||||||
replacedMsg: "Redeem transaction was replaced. Wait for inclusion please.",
|
replacedMsg: "Redeem transaction was replaced. Wait for inclusion please.",
|
||||||
successMsg: `Address ${shorten(user)} redeemed ${indexes.length} bonds in ${isGhst ? "GHST" : "STNK"}!`,
|
successMsg: `Address ${shorten(user)} redeemed ${indexes.length} bonds in ${isGhst ? "GHST" : "STNK"}!`,
|
||||||
errorMsg: `Redeem of ${indexes.length} bonds failed. Check logs for error detalization.`,
|
errorMsg: `Redeem of ${indexes.length} bonds failed. Check logs for error detalization.`,
|
||||||
};
|
};
|
||||||
await executeOnChainTransaction(
|
|
||||||
|
await executeOnChainTransaction({
|
||||||
chainId,
|
chainId,
|
||||||
"redeem",
|
|
||||||
args,
|
args,
|
||||||
user,
|
messages,
|
||||||
messages
|
abi: BondAbi,
|
||||||
);
|
address: BOND_DEPOSITORY_ADDRESSES[chainId],
|
||||||
|
functionName: "redeem",
|
||||||
|
account: user,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const executeOnChainTransaction = async (
|
export const forceRedeem = async ({ chainId, user, receiver, indexes }) => {
|
||||||
chainId,
|
const args = [receiver, indexes];
|
||||||
functionName,
|
const messages = {
|
||||||
args,
|
replacedMsg: "Bond breakout transaction was replaced. Wait for inclusion please.",
|
||||||
account,
|
successMsg: `Address ${shorten(user)} succesfully breakout for ${indexes.length} bonds.`,
|
||||||
messages,
|
errorMsg: `Breakout of ${indexes.length} bonds failed. Check logs for error detalization.`,
|
||||||
value
|
};
|
||||||
) => {
|
|
||||||
try {
|
|
||||||
const { request } = await simulateContract(config, {
|
|
||||||
abi: BondAbi,
|
|
||||||
address: BOND_DEPOSITORY_ADDRESSES[chainId],
|
|
||||||
functionName,
|
|
||||||
args,
|
|
||||||
account,
|
|
||||||
chainId,
|
|
||||||
type: isNetworkLegacyType(chainId) ? 'legacy' : 'eip1559',
|
|
||||||
value: value,
|
|
||||||
});
|
|
||||||
|
|
||||||
const txHash = await writeContract(config, request);
|
const txHash = await executeOnChainTransaction({
|
||||||
await waitForTransactionReceipt(config, {
|
chainId,
|
||||||
hash: txHash,
|
args,
|
||||||
onReplaced: () => toast(messages.replacedMsg),
|
messages,
|
||||||
chainId
|
abi: BondAbi,
|
||||||
});
|
address: BOND_DEPOSITORY_ADDRESSES[chainId],
|
||||||
|
functionName: "forceRedeem",
|
||||||
|
account: user,
|
||||||
|
});
|
||||||
|
|
||||||
toast.success(messages.successMsg);
|
return txHash;
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
toast.error(messages.errorMsg)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,7 @@
|
|||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import { useReadContract, useReadContracts } from "wagmi";
|
import { useReadContract, useReadContracts } from "wagmi";
|
||||||
import { simulateContract, writeContract, waitForTransactionReceipt } from "@wagmi/core";
|
|
||||||
import toast from "react-hot-toast";
|
|
||||||
import { keccak256, stringToBytes } from 'viem'
|
import { keccak256, stringToBytes } from 'viem'
|
||||||
|
import toast from "react-hot-toast";
|
||||||
import { isNetworkLegacyType } from "../../constants";
|
|
||||||
import { config } from "../../config";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
GHOST_GOVERNANCE_ADDRESSES,
|
GHOST_GOVERNANCE_ADDRESSES,
|
||||||
@ -16,7 +12,7 @@ import { abi as GovernorStorageAbi } from "../../abi/GovernorStorage.json";
|
|||||||
import { abi as GovernorVotesQuorumFractionAbi } from "../../abi/GovernorVotesQuorumFraction.json";
|
import { abi as GovernorVotesQuorumFractionAbi } from "../../abi/GovernorVotesQuorumFraction.json";
|
||||||
|
|
||||||
import { DecimalBigNumber } from "../../helpers/DecimalBigNumber";
|
import { DecimalBigNumber } from "../../helpers/DecimalBigNumber";
|
||||||
import { getTokenDecimals, getTokenAbi, getTokenAddress } from "../helpers";
|
import { getTokenDecimals, getTokenAbi, getTokenAddress, executeOnChainTransaction } from "../helpers";
|
||||||
|
|
||||||
export const getVoteValue = (forVotes, totalVotes) => {
|
export const getVoteValue = (forVotes, totalVotes) => {
|
||||||
if (totalVotes == 0n) return 0;
|
if (totalVotes == 0n) return 0;
|
||||||
@ -538,87 +534,57 @@ export const useProposals = (chainId, depth, searchedIndexes) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const releaseLocked = async (chainId, account, proposalId) => {
|
export const releaseLocked = async (chainId, account, proposalId) => {
|
||||||
try {
|
const messages = {
|
||||||
const { request } = await simulateContract(config, {
|
replacedMsg: "Release locked transaction was replaced. Wait for inclusion please.",
|
||||||
abi: GovernorAbi,
|
successMsg: "Successfully release locked funds from the governor.",
|
||||||
address: GHOST_GOVERNANCE_ADDRESSES[chainId],
|
errorMsg: "Release locked funds failed. Check logs for error detalization.",
|
||||||
functionName: 'releaseLocked',
|
};
|
||||||
args: [proposalId],
|
|
||||||
account: account,
|
|
||||||
chainId: chainId,
|
|
||||||
type: isNetworkLegacyType(chainId) ? 'legacy' : 'eip1559',
|
|
||||||
});
|
|
||||||
|
|
||||||
const txHash = await writeContract(config, request);
|
await executeOnChainTransaction({
|
||||||
await waitForTransactionReceipt(config, {
|
chainId,
|
||||||
hash: txHash,
|
args: [proposalId],
|
||||||
onReplaced: () => toast("Release locked transaction was replaced. Wait for inclusion please."),
|
abi: GovernorAbi,
|
||||||
chainId
|
address: GHOST_GOVERNANCE_ADDRESSES[chainId],
|
||||||
});
|
functionName: "releaseLocked",
|
||||||
|
account,
|
||||||
toast.success("Successfully release locked funds from the governor.");
|
messages,
|
||||||
return true;
|
});
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
toast.error("Release locked funds failed. Check logs for error detalization.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const executeProposal = async (chainId, account, proposalId) => {
|
export const executeProposal = async (chainId, account, proposalId) => {
|
||||||
try {
|
const messages = {
|
||||||
const { request } = await simulateContract(config, {
|
replacedMsg: "Proposal execution transaction was replaced. Wait for inclusion please.",
|
||||||
abi: GovernorAbi,
|
successMsg: "Proposal execution was successful, wait for updates.",
|
||||||
address: GHOST_GOVERNANCE_ADDRESSES[chainId],
|
errorMsg: "Proposal execution failed. Check logs for error detalization.",
|
||||||
functionName: 'execute',
|
};
|
||||||
args: [proposalId],
|
|
||||||
account: account,
|
|
||||||
chainId: chainId,
|
|
||||||
type: isNetworkLegacyType(chainId) ? 'legacy' : 'eip1559',
|
|
||||||
});
|
|
||||||
|
|
||||||
const txHash = await writeContract(config, request);
|
await executeOnChainTransaction({
|
||||||
await waitForTransactionReceipt(config, {
|
chainId,
|
||||||
hash: txHash,
|
args: [proposalId],
|
||||||
onReplaced: () => toast("Proposal execution transaction was replaced. Wait for inclusion please."),
|
abi: GovernorAbi,
|
||||||
chainId
|
address: GHOST_GOVERNANCE_ADDRESSES[chainId],
|
||||||
});
|
functionName: "execute",
|
||||||
|
account,
|
||||||
toast.success("Proposal execution was successful, wait for updates.");
|
messages,
|
||||||
return true;
|
});
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
toast.error("Proposal execution failed. Check logs for error detalization.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const castVote = async (chainId, account, proposalId, support) => {
|
export const castVote = async (chainId, account, proposalId, support) => {
|
||||||
try {
|
const messages = {
|
||||||
const { request } = await simulateContract(config, {
|
replacedMsg: "Cast vote transaction was replaced. Wait for inclusion please.",
|
||||||
abi: GovernorAbi,
|
successMsg: "Successfully casted a vote, should be applied the proposal.",
|
||||||
address: GHOST_GOVERNANCE_ADDRESSES[chainId],
|
errorMsg: "Vote cast failed. Check logs for error detalization.",
|
||||||
functionName: 'castVote',
|
};
|
||||||
args: [proposalId, support],
|
|
||||||
account: account,
|
|
||||||
chainId: chainId,
|
|
||||||
type: isNetworkLegacyType(chainId) ? 'legacy' : 'eip1559',
|
|
||||||
});
|
|
||||||
|
|
||||||
const txHash = await writeContract(config, request);
|
await executeOnChainTransaction({
|
||||||
await waitForTransactionReceipt(config, {
|
chainId,
|
||||||
hash: txHash,
|
args: [proposalId, support],
|
||||||
onReplaced: () => toast("Cast vote transaction was replaced. Wait for inclusion please."),
|
abi: GovernorAbi,
|
||||||
chainId
|
address: GHOST_GOVERNANCE_ADDRESSES[chainId],
|
||||||
});
|
functionName: "castVote",
|
||||||
|
account,
|
||||||
toast.success("Successfully casted a vote, should be applied the proposal.");
|
messages,
|
||||||
return true;
|
});
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
toast.error("Vote cast failed. Check logs for error detalization.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const propose = async (chainId, account, functions, description) => {
|
export const propose = async (chainId, account, functions, description) => {
|
||||||
@ -626,29 +592,19 @@ export const propose = async (chainId, account, functions, description) => {
|
|||||||
const values = functions.map(f => f.value);
|
const values = functions.map(f => f.value);
|
||||||
const calldatas = functions.map(f => f.calldata);
|
const calldatas = functions.map(f => f.calldata);
|
||||||
|
|
||||||
try {
|
const messages = {
|
||||||
const { request } = await simulateContract(config, {
|
replacedMsg: "Proposal transaction was replaced. Wait for inclusion please.",
|
||||||
abi: GovernorAbi,
|
successMsg: "Successfully proposed a set of functions to be executed.",
|
||||||
address: GHOST_GOVERNANCE_ADDRESSES[chainId],
|
errorMsg: "Proposal creation failed. Check logs for error detalization.",
|
||||||
functionName: 'propose',
|
};
|
||||||
args: [targets, values, calldatas, description],
|
|
||||||
account: account,
|
|
||||||
chainId: chainId,
|
|
||||||
type: isNetworkLegacyType(chainId) ? 'legacy' : 'eip1559',
|
|
||||||
});
|
|
||||||
|
|
||||||
const txHash = await writeContract(config, request);
|
await executeOnChainTransaction({
|
||||||
await waitForTransactionReceipt(config, {
|
chainId,
|
||||||
hash: txHash,
|
args: [targets, values, calldatas, description],
|
||||||
onReplaced: () => toast("Proposal transaction was replaced. Wait for inclusion please."),
|
abi: GovernorAbi,
|
||||||
chainId
|
address: GHOST_GOVERNANCE_ADDRESSES[chainId],
|
||||||
});
|
functionName: "propose",
|
||||||
|
account,
|
||||||
toast.success("Successfully proposed a set of functions to be executed.");
|
messages,
|
||||||
return true;
|
});
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
toast.error("Proposal creation failed. Check logs for error detalization.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,6 @@
|
|||||||
|
import toast from "react-hot-toast";
|
||||||
|
import { simulateContract, writeContract, waitForTransactionReceipt } from "@wagmi/core";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
RESERVE_ADDRESSES,
|
RESERVE_ADDRESSES,
|
||||||
FTSO_ADDRESSES,
|
FTSO_ADDRESSES,
|
||||||
@ -6,6 +9,8 @@ import {
|
|||||||
FTSO_DAI_LP_ADDRESSES,
|
FTSO_DAI_LP_ADDRESSES,
|
||||||
WETH_ADDRESSES,
|
WETH_ADDRESSES,
|
||||||
} from "../constants/addresses";
|
} from "../constants/addresses";
|
||||||
|
import { isNetworkLegacyType } from "../constants";
|
||||||
|
import { config } from "../config";
|
||||||
|
|
||||||
import { tokenNameConverter } from "../helpers/tokenConverter";
|
import { tokenNameConverter } from "../helpers/tokenConverter";
|
||||||
|
|
||||||
@ -201,3 +206,55 @@ export const getTokenPurchaseLink = (chainId, tokenAddress, chainName) => {
|
|||||||
}
|
}
|
||||||
return purchaseUrl;
|
return purchaseUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sanitizeTransactionRequest = (request, isLegacy) => {
|
||||||
|
const finalRequest = { ...request };
|
||||||
|
if (isLegacy) {
|
||||||
|
delete finalRequest.maxFeePerGas;
|
||||||
|
delete finalRequest.maxPriorityFeePerGas;
|
||||||
|
} else {
|
||||||
|
delete finalRequest.gasPrice;
|
||||||
|
}
|
||||||
|
return finalRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const executeOnChainTransaction = async ({
|
||||||
|
chainId,
|
||||||
|
abi,
|
||||||
|
address,
|
||||||
|
functionName,
|
||||||
|
args,
|
||||||
|
account,
|
||||||
|
messages,
|
||||||
|
value
|
||||||
|
}) => {
|
||||||
|
try {
|
||||||
|
const isLegacy = isNetworkLegacyType(chainId);
|
||||||
|
const { request } = await simulateContract(config, {
|
||||||
|
abi,
|
||||||
|
address,
|
||||||
|
functionName,
|
||||||
|
args,
|
||||||
|
account,
|
||||||
|
chainId,
|
||||||
|
value,
|
||||||
|
type: isLegacy ? 'legacy' : 'eip1559',
|
||||||
|
});
|
||||||
|
|
||||||
|
const finalRequest = sanitizeTransactionRequest(request, isLegacy);
|
||||||
|
const txHash = await writeContract(config, finalRequest);
|
||||||
|
await waitForTransactionReceipt(config, {
|
||||||
|
hash: txHash,
|
||||||
|
onReplaced: () => toast(messages.replacedMsg),
|
||||||
|
chainId
|
||||||
|
});
|
||||||
|
|
||||||
|
toast.success(messages.successMsg);
|
||||||
|
|
||||||
|
return txHash;
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
toast.error(messages.errorMsg)
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,16 +1,13 @@
|
|||||||
import { useReadContract } from "wagmi";
|
import { useReadContract } from "wagmi";
|
||||||
import { simulateContract, writeContract, waitForTransactionReceipt } from "@wagmi/core";
|
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
|
|
||||||
import { config } from "../../config";
|
|
||||||
|
|
||||||
import { isNetworkLegacyType } from "../../constants";
|
|
||||||
import { STAKING_ADDRESSES } from "../../constants/addresses";
|
import { STAKING_ADDRESSES } from "../../constants/addresses";
|
||||||
import { abi as StakingAbi } from "../../abi/GhostStaking.json";
|
import { abi as StakingAbi } from "../../abi/GhostStaking.json";
|
||||||
import { abi as GatekeeperAbi } from "../../abi/GhostGatekeeper.json";
|
import { abi as GatekeeperAbi } from "../../abi/GhostGatekeeper.json";
|
||||||
|
|
||||||
import { shorten } from "../../helpers";
|
import { shorten } from "../../helpers";
|
||||||
import { DecimalBigNumber } from "../../helpers/DecimalBigNumber";
|
import { DecimalBigNumber } from "../../helpers/DecimalBigNumber";
|
||||||
|
import { executeOnChainTransaction } from "../helpers";
|
||||||
|
|
||||||
export const useGatekeeperApy = (chainId) => {
|
export const useGatekeeperApy = (chainId) => {
|
||||||
const { data: gatekeeper, refetch } = useReadContract({
|
const { data: gatekeeper, refetch } = useReadContract({
|
||||||
@ -155,45 +152,39 @@ export const useGhostedSupply = (chainId) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const stake = async (chainId, account, amount, isRebase, isClaim, ftsoSymbol, stnkSymbol, ghstSymbol) => {
|
export const stake = async (chainId, account, amount, isRebase, isClaim, ftsoSymbol, stnkSymbol, ghstSymbol) => {
|
||||||
const args = [
|
const args = [amount, account, isRebase, isClaim];
|
||||||
amount,
|
|
||||||
account,
|
|
||||||
isRebase,
|
|
||||||
isClaim
|
|
||||||
];
|
|
||||||
const messages = {
|
const messages = {
|
||||||
replacedMsg: "Staking transaction was replaced. Wait for inclusion please.",
|
replacedMsg: "Staking transaction was replaced. Wait for inclusion please.",
|
||||||
successMsg: `${ftsoSymbol} tokens staked successfully! Wait for the warmup period to claim your ${isRebase ? stnkSymbol : ghstSymbol}.`,
|
successMsg: `${ftsoSymbol} tokens staked successfully! Wait for the warmup period to claim your ${isRebase ? stnkSymbol : ghstSymbol}.`,
|
||||||
errorMsg: "Staking transaction failed. Check logs for error detalization.",
|
errorMsg: "Staking transaction failed. Check logs for error detalization.",
|
||||||
};
|
};
|
||||||
await executeOnChainTransaction(
|
await executeOnChainTransaction({
|
||||||
chainId,
|
chainId,
|
||||||
"stake",
|
|
||||||
args,
|
args,
|
||||||
|
messages,
|
||||||
account,
|
account,
|
||||||
messages
|
abi: StakingAbi,
|
||||||
);
|
address: STAKING_ADDRESSES[chainId],
|
||||||
|
functionName: "stake",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export const unstake = async (chainId, account, amount, isTrigger, isRebase, ftsoSymbol, stnkSymbol, ghstSymbol) => {
|
export const unstake = async (chainId, account, amount, isTrigger, isRebase, ftsoSymbol, stnkSymbol, ghstSymbol) => {
|
||||||
const args = [
|
const args = [amount, account, isTrigger, isRebase];
|
||||||
amount,
|
|
||||||
account,
|
|
||||||
isTrigger,
|
|
||||||
isRebase
|
|
||||||
];
|
|
||||||
const messages = {
|
const messages = {
|
||||||
replacedMsg: "Unstake transaction was replaced. Wait for inclusion please.",
|
replacedMsg: "Unstake transaction was replaced. Wait for inclusion please.",
|
||||||
successMsg: `${isRebase ? stnkSymbol : ghstSymbol} tokens unstaked successfully! Check your ${ftsoSymbol} balance on ${shorten(account)}.`,
|
successMsg: `${isRebase ? stnkSymbol : ghstSymbol} tokens unstaked successfully! Check your ${ftsoSymbol} balance on ${shorten(account)}.`,
|
||||||
errorMsg: "Unstake transaction failed. Check logs for error detalization.",
|
errorMsg: "Unstake transaction failed. Check logs for error detalization.",
|
||||||
};
|
};
|
||||||
await executeOnChainTransaction(
|
await executeOnChainTransaction({
|
||||||
chainId,
|
chainId,
|
||||||
"unstake",
|
|
||||||
args,
|
args,
|
||||||
|
messages,
|
||||||
account,
|
account,
|
||||||
messages
|
abi: StakingAbi,
|
||||||
);
|
address: STAKING_ADDRESSES[chainId],
|
||||||
|
functionName: "unstake",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export const forfeit = async (chainId, account, ftsoSymbol) => {
|
export const forfeit = async (chainId, account, ftsoSymbol) => {
|
||||||
@ -202,13 +193,15 @@ export const forfeit = async (chainId, account, ftsoSymbol) => {
|
|||||||
successMsg: `Tokens forfeited successfully! Check your ${ftsoSymbol} balance on ${shorten(account)}.`,
|
successMsg: `Tokens forfeited successfully! Check your ${ftsoSymbol} balance on ${shorten(account)}.`,
|
||||||
errorMsg: "Forfeit transaction failed. Check logs for error detalization.",
|
errorMsg: "Forfeit transaction failed. Check logs for error detalization.",
|
||||||
};
|
};
|
||||||
await executeOnChainTransaction(
|
await executeOnChainTransaction({
|
||||||
chainId,
|
chainId,
|
||||||
"forfeit",
|
messages,
|
||||||
[],
|
|
||||||
account,
|
account,
|
||||||
messages
|
args: [],
|
||||||
);
|
abi: StakingAbi,
|
||||||
|
address: STAKING_ADDRESSES[chainId],
|
||||||
|
functionName: "forfeit",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export const claim = async (chainId, account, isStnk, stnkSymbol, ghstSymbol) => {
|
export const claim = async (chainId, account, isStnk, stnkSymbol, ghstSymbol) => {
|
||||||
@ -218,94 +211,89 @@ export const claim = async (chainId, account, isStnk, stnkSymbol, ghstSymbol) =>
|
|||||||
successMsg: `${isStnk ? stnkSymbol : ghstSymbol} tokens claimed successfully to ${shorten(account)}.`,
|
successMsg: `${isStnk ? stnkSymbol : ghstSymbol} tokens claimed successfully to ${shorten(account)}.`,
|
||||||
errorMsg: "Claim transaction failed. Check logs for error detalization.",
|
errorMsg: "Claim transaction failed. Check logs for error detalization.",
|
||||||
};
|
};
|
||||||
await executeOnChainTransaction(
|
await executeOnChainTransaction({
|
||||||
chainId,
|
chainId,
|
||||||
"claim",
|
|
||||||
args,
|
args,
|
||||||
|
messages,
|
||||||
account,
|
account,
|
||||||
messages
|
abi: StakingAbi,
|
||||||
);
|
address: STAKING_ADDRESSES[chainId],
|
||||||
|
functionName: "claim",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export const breakout = async (chainId, account, receiver, amount) => {
|
||||||
|
const args = [receiver, amount];
|
||||||
|
const messages = {
|
||||||
|
replacedMsg: "Breakout transaction was replaced. Wait for inclusion please.",
|
||||||
|
successMsg: `Staking breakout succesfully bridged to ${shorten(receiver)}.`,
|
||||||
|
errorMsg: "Breakout transaction failed. Check logs for error detalization.",
|
||||||
|
};
|
||||||
|
const txHash = await executeOnChainTransaction({
|
||||||
|
chainId,
|
||||||
|
args,
|
||||||
|
messages,
|
||||||
|
account,
|
||||||
|
abi: StakingAbi,
|
||||||
|
address: STAKING_ADDRESSES[chainId],
|
||||||
|
functionName: "breakout",
|
||||||
|
});
|
||||||
|
|
||||||
|
return txHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const unwrap = async (chainId, account, amount, stnkSymbol) => {
|
export const unwrap = async (chainId, account, amount, stnkSymbol) => {
|
||||||
|
const args = [account, amount];
|
||||||
const messages = {
|
const messages = {
|
||||||
replacedMsg: "Unwrap transaction was replaced. Wait for inclusion please.",
|
replacedMsg: "Unwrap transaction was replaced. Wait for inclusion please.",
|
||||||
successMsg: `Tokens unwrapped successfully! Check your ${stnkSymbol} balance on ${shorten(account)}.`,
|
successMsg: `Tokens unwrapped successfully! Check your ${stnkSymbol} balance on ${shorten(account)}.`,
|
||||||
errorMsg: "Unwrap transaction failed. Check logs for error detalization.",
|
errorMsg: "Unwrap transaction failed. Check logs for error detalization.",
|
||||||
};
|
};
|
||||||
await executeOnChainTransaction(
|
const txHash = await executeOnChainTransaction({
|
||||||
chainId,
|
chainId,
|
||||||
"unwrap",
|
args,
|
||||||
[account, amount],
|
messages,
|
||||||
account,
|
account,
|
||||||
messages
|
abi: StakingAbi,
|
||||||
);
|
address: STAKING_ADDRESSES[chainId],
|
||||||
|
functionName: "unwrap",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export const wrap = async (chainId, account, amount, ghstSymbol) => {
|
export const wrap = async (chainId, account, amount, ghstSymbol) => {
|
||||||
|
const args = [account, amount];
|
||||||
const messages = {
|
const messages = {
|
||||||
replacedMsg: "Wrap transaction was replaced. Wait for inclusion please.",
|
replacedMsg: "Wrap transaction was replaced. Wait for inclusion please.",
|
||||||
successMsg: `Tokens wrapped successfully! Check your ${ghstSymbol} balance on ${shorten(account)}.`,
|
successMsg: `Tokens wrapped successfully! Check your ${ghstSymbol} balance on ${shorten(account)}.`,
|
||||||
errorMsg: "Wrap transaction failed. Check logs for error detalization.",
|
errorMsg: "Wrap transaction failed. Check logs for error detalization.",
|
||||||
};
|
};
|
||||||
await executeOnChainTransaction(
|
const txHash = await executeOnChainTransaction({
|
||||||
chainId,
|
chainId,
|
||||||
"wrap",
|
args,
|
||||||
[account, amount],
|
messages,
|
||||||
account,
|
account,
|
||||||
messages
|
abi: StakingAbi,
|
||||||
);
|
address: STAKING_ADDRESSES[chainId],
|
||||||
|
functionName: "wrap",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ghost = async (chainId, account, receiver, amount) => {
|
export const ghost = async (chainId, account, receiver, amount) => {
|
||||||
|
const ars = [receiver, amount];
|
||||||
const messages = {
|
const messages = {
|
||||||
replacedMsg: "Bridge transaction was replaced. Wait for inclusion please.",
|
replacedMsg: "Bridge transaction was replaced. Wait for inclusion please.",
|
||||||
successMsg: `Amount successfully bridged! Check tx hash status or wait for slow clap finalization.`,
|
successMsg: `Amount successfully bridged! Check tx hash status or wait for slow clap finalization.`,
|
||||||
errorMsg: "Bridge transaction failed. Check logs for error detalization.",
|
errorMsg: "Bridge transaction failed. Check logs for error detalization.",
|
||||||
};
|
};
|
||||||
|
const txHash = await executeOnChainTransaction({
|
||||||
const txHash = await executeOnChainTransaction(
|
|
||||||
chainId,
|
chainId,
|
||||||
"ghost",
|
args,
|
||||||
[receiver, amount],
|
messages,
|
||||||
account,
|
account,
|
||||||
messages
|
abi: StakingAbi,
|
||||||
);
|
address: STAKING_ADDRESSES[chainId],
|
||||||
|
functionName: "ghost",
|
||||||
|
});
|
||||||
|
|
||||||
return txHash;
|
return txHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
const executeOnChainTransaction = async (
|
|
||||||
chainId,
|
|
||||||
functionName,
|
|
||||||
args,
|
|
||||||
account,
|
|
||||||
messages
|
|
||||||
) => {
|
|
||||||
try {
|
|
||||||
const { request } = await simulateContract(config, {
|
|
||||||
abi: StakingAbi,
|
|
||||||
address: STAKING_ADDRESSES[chainId],
|
|
||||||
functionName,
|
|
||||||
args,
|
|
||||||
account,
|
|
||||||
chainId,
|
|
||||||
type: isNetworkLegacyType(chainId) ? 'legacy' : 'eip1559',
|
|
||||||
});
|
|
||||||
|
|
||||||
const txHash = await writeContract(config, request);
|
|
||||||
await waitForTransactionReceipt(config, {
|
|
||||||
hash: txHash,
|
|
||||||
onReplaced: () => toast(messages.replacedMsg),
|
|
||||||
chainId
|
|
||||||
});
|
|
||||||
|
|
||||||
toast.success(messages.successMsg);
|
|
||||||
|
|
||||||
return txHash;
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
toast.error(messages.errorMsg)
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,14 +1,16 @@
|
|||||||
import { useReadContract, useReadContracts, useToken, useBalance as useInnerBalance } from "wagmi";
|
import { useReadContract, useReadContracts, useToken, useBalance as useInnerBalance } from "wagmi";
|
||||||
import { simulateContract, writeContract, waitForTransactionReceipt } from "@wagmi/core";
|
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
|
|
||||||
import { getTokenAbi, getTokenAddress, getTokenDecimals } from "../helpers";
|
import {
|
||||||
|
getTokenAbi,
|
||||||
|
getTokenAddress,
|
||||||
|
getTokenDecimals,
|
||||||
|
executeOnChainTransaction
|
||||||
|
} from "../helpers";
|
||||||
|
|
||||||
import { isNetworkLegacyType } from "../../constants";
|
|
||||||
import { DecimalBigNumber } from "../../helpers/DecimalBigNumber";
|
import { DecimalBigNumber } from "../../helpers/DecimalBigNumber";
|
||||||
import { shorten } from "../../helpers";
|
import { shorten } from "../../helpers";
|
||||||
import { tokenNameConverter } from "../../helpers/tokenConverter";
|
import { tokenNameConverter } from "../../helpers/tokenConverter";
|
||||||
import { config } from "../../config";
|
|
||||||
import { WETH_ADDRESSES } from "../../constants/addresses";
|
import { WETH_ADDRESSES } from "../../constants/addresses";
|
||||||
|
|
||||||
export const usePastVotes = (chainId, name, timepoint, address) => {
|
export const usePastVotes = (chainId, name, timepoint, address) => {
|
||||||
@ -204,132 +206,86 @@ export const useBalanceForShares = (chainId, name, amount) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const approveTokens = async (chainId, name, owner, spender, value) => {
|
export const approveTokens = async (chainId, name, owner, spender, value) => {
|
||||||
try {
|
const messages = {
|
||||||
const { request } = await simulateContract(config, {
|
replacedMsg: "Approve transaction was replaced. Wait for inclusion please.",
|
||||||
abi: getTokenAbi(name),
|
successMsg: `${name} tokens successfully approved to ${shorten(spender)}`,
|
||||||
address: getTokenAddress(chainId, name),
|
errorMsg: `${name} tokens approval failed. Check logs for error detalization.`
|
||||||
functionName: 'approve',
|
};
|
||||||
args: [spender, value],
|
await executeOnChainTransaction({
|
||||||
account: owner,
|
chainId,
|
||||||
chainId: chainId,
|
args: [spender, value],
|
||||||
type: isNetworkLegacyType(chainId) ? 'legacy' : 'eip1559',
|
abi: getTokenAbi(name),
|
||||||
});
|
address: getTokenAddress(chainId, name),
|
||||||
|
functionName: "approve",
|
||||||
const txHash = await writeContract(config, request);
|
account: owner,
|
||||||
await waitForTransactionReceipt(config, {
|
messages,
|
||||||
hash: txHash,
|
});
|
||||||
onReplaced: () => toast("Approve transaction was replaced. Wait for inclusion please."),
|
|
||||||
chainId
|
|
||||||
});
|
|
||||||
|
|
||||||
toast.success(name + " tokens successfully approved to " + shorten(spender));
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
toast.error(name + " tokens approval failed. Check logs for error detalization.")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const mintDai = async (chainId, account, value) => {
|
export const mintDai = async (chainId, account, value) => {
|
||||||
try {
|
const messages = {
|
||||||
const { request } = await simulateContract(config, {
|
replacedMsg: "Mint transaction was replaced. Wait for inclusion please.",
|
||||||
abi: getTokenAbi("GDAI"),
|
successMsg: "gDAI successfully minted to your wallet! Funds will be used on Ghost Faucet.",
|
||||||
address: getTokenAddress(chainId, "GDAI"),
|
errorMsg: "Minting gDAI from the faucet failed. Check logs for error detalization."
|
||||||
functionName: 'mint',
|
};
|
||||||
args: [account],
|
await executeOnChainTransaction({
|
||||||
account: account,
|
chainId,
|
||||||
value: value,
|
args: [account],
|
||||||
chainId: chainId,
|
abi: getTokenAbi("GDAI"),
|
||||||
type: isNetworkLegacyType(chainId) ? 'legacy' : 'eip1559',
|
address: getTokenAddress(chainId, "GDAI"),
|
||||||
});
|
functionName: "mint",
|
||||||
|
account,
|
||||||
const txHash = await writeContract(config, request);
|
messages,
|
||||||
await waitForTransactionReceipt(config, {
|
});
|
||||||
hash: txHash,
|
|
||||||
onReplaced: () => toast("Mint transaction was replaced. Wait for inclusion please."),
|
|
||||||
chainId
|
|
||||||
});
|
|
||||||
|
|
||||||
toast.success("gDAI successfully minted to your wallet! Funds will be used on Ghost Faucet.");
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
toast.error("Minting gDAI from the faucet failed. Check logs for error detalization.")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const burnDai = async (chainId, account, value) => {
|
export const burnDai = async (chainId, account, value) => {
|
||||||
try {
|
const messages = {
|
||||||
const { request } = await simulateContract(config, {
|
replacedMsg: "Burn transaction was replaced. Wait for inclusion please.",
|
||||||
abi: getTokenAbi("GDAI"),
|
successMsg: "gDAI successfully burned for native coins! Check your wallet balance.",
|
||||||
address: getTokenAddress(chainId, "GDAI"),
|
errorMsg: "Burning gDAI from the faucet failed. Check logs for error detalization."
|
||||||
functionName: 'burn',
|
};
|
||||||
args: [value],
|
await executeOnChainTransaction({
|
||||||
account: account,
|
chainId,
|
||||||
chainId: chainId,
|
abi: getTokenAbi("GDAI"),
|
||||||
type: isNetworkLegacyType(chainId) ? 'legacy' : 'eip1559',
|
address: getTokenAddress(chainId, "GDAI"),
|
||||||
});
|
functionName: 'burn',
|
||||||
|
args: [value],
|
||||||
const txHash = await writeContract(config, request);
|
account,
|
||||||
await waitForTransactionReceipt(config, {
|
messages,
|
||||||
hash: txHash,
|
});
|
||||||
onReplaced: () => toast("Burn transaction was replaced. Wait for inclusion please."),
|
|
||||||
chainId
|
|
||||||
});
|
|
||||||
|
|
||||||
toast.success("gDAI successfully burned for native coins! Check your wallet balance.");
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
toast.error("Burning gDAI from the faucet failed. Check logs for error detalization.")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const depositNative = async (chainId, account, value) => {
|
export const depositNative = async (chainId, account, value) => {
|
||||||
try {
|
const messages = {
|
||||||
const { request } = await simulateContract(config, {
|
replacedMsg: "WETH9 deposit transaction was replaced. Wait for inclusion please.",
|
||||||
abi: getTokenAbi("WETH"),
|
successMsg: "WETH9 successfully minted to your wallet! Check your wallet balance.",
|
||||||
address: getTokenAddress(chainId, "WETH"),
|
errorMsg: "WETH9 wrapping failed. Check logs for error detalization."
|
||||||
functionName: 'deposit',
|
};
|
||||||
account: account,
|
await executeOnChainTransaction({
|
||||||
chainId: chainId,
|
chainId,
|
||||||
value: value,
|
abi: getTokenAbi("WETH"),
|
||||||
type: isNetworkLegacyType(chainId) ? 'legacy' : 'eip1559',
|
address: getTokenAddress(chainId, "WETH"),
|
||||||
});
|
functionName: 'deposit',
|
||||||
const txHash = await writeContract(config, request);
|
value,
|
||||||
|
account,
|
||||||
await waitForTransactionReceipt(config, {
|
messages,
|
||||||
hash: txHash,
|
});
|
||||||
onReplaced: () => toast("WETH9 deposit transaction was replaced. Wait for inclusion please."),
|
|
||||||
chainId
|
|
||||||
});
|
|
||||||
|
|
||||||
toast.success("WETH9 successfully minted to your wallet! Check your wallet balance.");
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
toast.error("WETH9 wrapping failed. Check logs for error detalization.")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const withdrawWeth = async (chainId, account, value) => {
|
export const withdrawWeth = async (chainId, account, value) => {
|
||||||
try {
|
const messages = {
|
||||||
const { request } = await simulateContract(config, {
|
replacedMsg: "WETH9 withdraw transaction was replaced. Wait for inclusion please.",
|
||||||
abi: getTokenAbi("WETH"),
|
successMsg: "WETH9 successfully burned for native coins! Check your wallet balance.",
|
||||||
address: getTokenAddress(chainId, "WETH"),
|
errorMsg: "WETH9 unwrapping failed. Check logs for error detalization."
|
||||||
functionName: 'withdraw',
|
};
|
||||||
args: [value],
|
await executeOnChainTransaction({
|
||||||
account: account,
|
chainId,
|
||||||
chainId: chainId,
|
abi: getTokenAbi("WETH"),
|
||||||
type: isNetworkLegacyType(chainId) ? 'legacy' : 'eip1559',
|
address: getTokenAddress(chainId, "WETH"),
|
||||||
});
|
functionName: 'withdraw',
|
||||||
|
args: [value],
|
||||||
const txHash = await writeContract(config, request);
|
account,
|
||||||
await waitForTransactionReceipt(config, {
|
messages,
|
||||||
hash: txHash,
|
});
|
||||||
onReplaced: () => toast("WETH9 withdraw transaction was replaced. Wait for inclusion please."),
|
|
||||||
chainId
|
|
||||||
});
|
|
||||||
|
|
||||||
toast.success("WETH9 successfully burned for native coins! Check your wallet balance.");
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
toast.error("WETH9 unwrapping failed. Check logs for error detalization.")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,8 @@
|
|||||||
import { simulateContract, writeContract, waitForTransactionReceipt } from "@wagmi/core";
|
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
|
|
||||||
import { isNetworkLegacyType } from "../../constants";
|
|
||||||
import { UNISWAP_V2_ROUTER, WETH_ADDRESSES } from "../../constants/addresses";
|
import { UNISWAP_V2_ROUTER, WETH_ADDRESSES } from "../../constants/addresses";
|
||||||
import { abi as RouterAbi } from "../../abi/UniswapV2Router.json";
|
import { abi as RouterAbi } from "../../abi/UniswapV2Router.json";
|
||||||
import { getTokenAddress } from "../helpers";
|
import { getTokenAddress, executeOnChainTransaction } from "../helpers";
|
||||||
|
|
||||||
import { config } from "../../config";
|
|
||||||
|
|
||||||
const swapMessages = {
|
const swapMessages = {
|
||||||
replacedMsg: "Swap transaction was replaced. Wait for inclusion please.",
|
replacedMsg: "Swap transaction was replaced. Wait for inclusion please.",
|
||||||
@ -27,6 +23,7 @@ export const swapExactETHForTokens = async ({
|
|||||||
tokenNameTop,
|
tokenNameTop,
|
||||||
tokenNameBottom,
|
tokenNameBottom,
|
||||||
destination,
|
destination,
|
||||||
|
address,
|
||||||
deadline
|
deadline
|
||||||
}) => {
|
}) => {
|
||||||
const args = [
|
const args = [
|
||||||
@ -38,9 +35,11 @@ export const swapExactETHForTokens = async ({
|
|||||||
|
|
||||||
await executeOnChainTransaction({
|
await executeOnChainTransaction({
|
||||||
chainId,
|
chainId,
|
||||||
functionName: "swapExactETHForTokens",
|
|
||||||
args,
|
args,
|
||||||
account: destination,
|
abi: RouterAbi,
|
||||||
|
address: UNISWAP_V2_ROUTER[chainId],
|
||||||
|
functionName: "swapExactETHForTokens",
|
||||||
|
account: address,
|
||||||
messages: swapMessages,
|
messages: swapMessages,
|
||||||
value: amountADesired,
|
value: amountADesired,
|
||||||
});
|
});
|
||||||
@ -66,8 +65,10 @@ export const swapExactTokensForETH = async ({
|
|||||||
|
|
||||||
await executeOnChainTransaction({
|
await executeOnChainTransaction({
|
||||||
chainId,
|
chainId,
|
||||||
functionName: "swapExactTokensForETH",
|
|
||||||
args,
|
args,
|
||||||
|
abi: RouterAbi,
|
||||||
|
address: UNISWAP_V2_ROUTER[chainId],
|
||||||
|
functionName: "swapExactTokensForETH",
|
||||||
account: address,
|
account: address,
|
||||||
messages: swapMessages,
|
messages: swapMessages,
|
||||||
});
|
});
|
||||||
@ -93,10 +94,12 @@ export const swapExactTokensForTokens = async ({
|
|||||||
|
|
||||||
await executeOnChainTransaction({
|
await executeOnChainTransaction({
|
||||||
chainId,
|
chainId,
|
||||||
functionName: "swapExactTokensForTokens",
|
|
||||||
args,
|
args,
|
||||||
|
abi: RouterAbi,
|
||||||
|
address: UNISWAP_V2_ROUTER[chainId],
|
||||||
|
functionName: "swapExactTokensForTokens",
|
||||||
account: address,
|
account: address,
|
||||||
messages: swapMessages
|
messages: swapMessages,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,10 +128,12 @@ export const addLiquidity = async ({
|
|||||||
|
|
||||||
await executeOnChainTransaction({
|
await executeOnChainTransaction({
|
||||||
chainId,
|
chainId,
|
||||||
functionName: "addLiquidity",
|
|
||||||
args,
|
args,
|
||||||
|
abi: RouterAbi,
|
||||||
|
address: UNISWAP_V2_ROUTER[chainId],
|
||||||
|
functionName: "addLiquidity",
|
||||||
account: address,
|
account: address,
|
||||||
messages: addMessages
|
messages: addMessages,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,44 +174,12 @@ export const addLiquidityETH = async ({
|
|||||||
|
|
||||||
await executeOnChainTransaction({
|
await executeOnChainTransaction({
|
||||||
chainId,
|
chainId,
|
||||||
functionName: "addLiquidityETH",
|
|
||||||
args,
|
args,
|
||||||
|
abi: RouterAbi,
|
||||||
|
address: UNISWAP_V2_ROUTER[chainId],
|
||||||
|
functionName: "addLiquidityETH",
|
||||||
account: address,
|
account: address,
|
||||||
messages: addMessages,
|
messages: addMessages,
|
||||||
value: amountETHDesired,
|
value: amountETHDesired,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const executeOnChainTransaction = async ({
|
|
||||||
chainId,
|
|
||||||
functionName,
|
|
||||||
args,
|
|
||||||
account,
|
|
||||||
messages,
|
|
||||||
value,
|
|
||||||
}) => {
|
|
||||||
try {
|
|
||||||
const { request } = await simulateContract(config, {
|
|
||||||
abi: RouterAbi,
|
|
||||||
address: UNISWAP_V2_ROUTER[chainId],
|
|
||||||
functionName,
|
|
||||||
args,
|
|
||||||
account,
|
|
||||||
chainId,
|
|
||||||
type: isNetworkLegacyType(chainId) ? 'legacy' : 'eip1559',
|
|
||||||
value: value ?? 0n,
|
|
||||||
});
|
|
||||||
|
|
||||||
const txHash = await writeContract(config, request);
|
|
||||||
await waitForTransactionReceipt(config, {
|
|
||||||
hash: txHash,
|
|
||||||
onReplaced: () => toast(messages.replacedMsg),
|
|
||||||
chainId
|
|
||||||
});
|
|
||||||
|
|
||||||
toast.success(messages.successMsg);
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
toast.error(messages.errorMsg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user