Compare commits

..

No commits in common. "175d964b9fed45524cecfd63654d79ee19bc3d4a" and "bc5f88d57255773178f3134dc5a74f1927bbb639" have entirely different histories.

9 changed files with 84 additions and 103 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "ghost-dao-interface", "name": "ghost-dao-interface",
"private": true, "private": true,
"version": "0.2.4", "version": "0.2.0",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",

View File

@ -220,11 +220,7 @@ const Bridge = ({ chainId, address, config, connect }) => {
const preparedAmount = useMemo(() => { const preparedAmount = useMemo(() => {
try { try {
const result = BigInt(parseFloat(amount) * Math.pow(10, 18)); return BigInt(parseFloat(amount) * Math.pow(10, 18));
if (result > ghstBalance._value) {
return ghstBalance._value;
}
return result;
} catch { } catch {
return 0n; return 0n;
} }
@ -252,8 +248,8 @@ const Bridge = ({ chainId, address, config, connect }) => {
setIsPending(true); setIsPending(true);
const txHash = await ghost(chainId, address, convertedReceiver, preparedAmount); const txHash = await ghost(chainId, address, convertedReceiver, preparedAmount);
await ghstBalanceRefetch();
await ghstBalanceRefetch();
setReceiver(""); setReceiver("");
setAmount(""); setAmount("");
setIsPending(false); setIsPending(false);

View File

@ -12,41 +12,53 @@ import GhostStyledIcon from "../../components/Icon/GhostIcon";
import Modal from "../../components/Modal/Modal"; import Modal from "../../components/Modal/Modal";
import Paper from "../../components/Paper/Paper"; import Paper from "../../components/Paper/Paper";
import TokenStack from "../../components/TokenStack/TokenStack"; import TokenStack from "../../components/TokenStack/TokenStack";
import { useTokenSymbol } from "../../hooks/tokens";
const Stake = ({ chainId, address, isOpened, closeModal, connect }) => { const Stake = ({ chainId, address, isOpened, closeModal, connect }) => {
const [action, setAction] = useState("STAKE"); const [action, setAction] = useState("STAKE");
const [upperToken, setUpperToken] = useState("FTSO");
const [bottomToken, setBottomToken] = useState("GHST");
const [settingsModalOpen, setSettingsModalOpen] = useState(false); const [settingsModalOpen, setSettingsModalOpen] = useState(false);
const { symbol: ftsoSymbol } = useTokenSymbol(chainId, "FTSO");
const { symbol: stnkSymbol } = useTokenSymbol(chainId, "STNK");
const { symbol: ghstSymbol } = useTokenSymbol(chainId, "GHST");
const [upperToken, setUpperToken] = useState(ftsoSymbol);
const [bottomToken, setBottomToken] = useState(ghstSymbol);
const setSettingsModalOpenInner = (value) => { const setSettingsModalOpenInner = (value) => {
setSettingsModalOpen(value); setSettingsModalOpen(value);
} }
useEffect(() => { useEffect(() => {
switch (true) { switch (true) {
case (upperToken === ftsoSymbol && bottomToken === stnkSymbol): case (upperToken === "FTSO" && bottomToken === "STNK"):
setAction("STAKE") setAction("STAKE")
break; break;
case (upperToken === ftsoSymbol && bottomToken === ghstSymbol): case (upperToken === "eCSPR" && bottomToken === "sCSPR"):
setAction("STAKE") setAction("STAKE")
break; break;
case (upperToken === stnkSymbol && bottomToken === ftsoSymbol): case (upperToken === "FTSO" && bottomToken === "GHST"):
setAction("STAKE")
break;
case (upperToken === "eCSPR" && bottomToken === "CSPR"):
setAction("STAKE")
break;
case (upperToken === "STNK" && bottomToken === "FTSO"):
setAction("UNSTAKE") setAction("UNSTAKE")
break; break;
case (upperToken === ghstSymbol && bottomToken === ftsoSymbol): case (upperToken === "sCSPR" && bottomToken === "eCSPR"):
setAction("UNSTAKE") setAction("UNSTAKE")
break; break;
case (upperToken === stnkSymbol && bottomToken === ghstSymbol): case (upperToken === "GHST" && bottomToken === "FTSO"):
setAction("UNSTAKE")
break;
case (upperToken === "CSPR" && bottomToken === "eCSPR"):
setAction("UNSTAKE")
break;
case (upperToken === "STNK" && bottomToken === "GHST"):
setAction("WRAP") setAction("WRAP")
break; break;
case (upperToken === ghstSymbol && bottomToken === stnkSymbol): case (upperToken === "sCSPR" && bottomToken === "CSPR"):
setAction("WRAP")
break;
case (upperToken === "GHST" && bottomToken === "STNK"):
setAction("UNWRAP")
break;
case (upperToken === "CSPR" && bottomToken === "sCSPR"):
setAction("UNWRAP") setAction("UNWRAP")
break; break;
default: default:

View File

@ -19,16 +19,10 @@ const ClaimConfirmationModal = (props) => {
switch (props.action.toUpperCase()) { switch (props.action.toUpperCase()) {
case "FORFEIT": case "FORFEIT":
await forfeit(props.chainId, props.receiver, props.ftsoSymbol); await forfeit(props.chainId, props.receiver);
break; break;
case "CLAIM": case "CLAIM":
await claim( await claim(props.chainId, props.receiver, props.outputToken === "STNK" || props.outputToken === "sCSPR");
props.chainId,
props.receiver,
props.outputToken === props.stnkSymbol,
props.stnkSymbol,
props.ghstSymbol
);
break; break;
default: default:
console.log("Unknown action") console.log("Unknown action")
@ -61,7 +55,7 @@ const ClaimConfirmationModal = (props) => {
/> />
<Box display="flex" flexDirection="row" justifyContent="center"> <Box display="flex" flexDirection="row" justifyContent="center">
<Typography> <Typography>
{props.outputToken} {props.outputTokenName}
</Typography> </Typography>
</Box> </Box>
</Box> </Box>

View File

@ -88,10 +88,8 @@ export const ClaimsArea = ({ chainId, address, epoch }) => {
chainid={chainId} chainid={chainId}
receiver={address} receiver={address}
receiveAmount={claim.expiry > epoch.number ? claim.deposit : isPayoutGhst ? balanceForShares.div(currentIndex) : balanceForShares} receiveAmount={claim.expiry > epoch.number ? claim.deposit : isPayoutGhst ? balanceForShares.div(currentIndex) : balanceForShares}
outputToken={claim.expiry > epoch.number ? ftsoSymbol : isPayoutGhst ? ghstSymbol : stnkSymbol} outputToken={claim.expiry > epoch.number ? "FTSO" : isPayoutGhst ? "GHST" : "STNK"}
stnkSymbol={stnkSymbol} outputTokenName={claim.expiry > epoch.number ? ftsoSymbol : isPayoutGhst ? ghstSymbol : stnkSymbol}
ghstSymbol={ghstSymbol}
ftsoSymbol={ftsoSymbol}
action={claim.expiry > epoch.number ? "forfeit" : "claim"} action={claim.expiry > epoch.number ? "forfeit" : "claim"}
chainId={chainId} chainId={chainId}
/> />

View File

@ -71,46 +71,18 @@ const StakeConfirmationModal = (props) => {
switch (props.action) { switch (props.action) {
case "STAKE": case "STAKE":
isRebase = props.bottomToken === props.stnkSymbol; isRebase = props.bottomToken.toUpperCase() === "STNK";
await stake( await stake(props.chainId, props.address, actionAmount._value.toBigInt(), isRebase, props.isClaim);
props.chainId,
props.address,
actionAmount._value.toBigInt(),
isRebase,
props.isClaim,
props.ftsoSymbol,
props.stnkSymbol,
props.ghstSymbol
);
break; break;
case "UNSTAKE": case "UNSTAKE":
isRebase = props.upperToken === stnkSymbol; isRebase = props.upperToken.toUpperCase() === "STNK";
await unstake( await unstake(props.chainId, props.address, actionAmount._value.toBigInt(), props.isTrigger, isRebase);
props.chainId,
props.address,
actionAmount._value.toBigInt(),
props.isTrigger,
isRebase,
props.ftsoSymbol,
props.stnkSymbol,
props.ghstSymbol
);
break; break;
case "WRAP": case "WRAP":
await wrap( await wrap(props.chainId, props.address, actionAmount._value.toBigInt());
props.chainId,
props.address,
actionAmount._value.toBigInt(),
props.ghstSymbol
);
break; break;
case "UNWRAP": case "UNWRAP":
await unwrap( await unwrap(props.chainId, props.address, actionAmount._value.toBigInt());
props.chainId,
props.address,
actionAmount._value.toBigInt(),
props.stnkSymbol
);
break; break;
default: default:
console.log("Wrong action to be executed!"); console.log("Wrong action to be executed!");
@ -143,7 +115,7 @@ const StakeConfirmationModal = (props) => {
/> />
<Box display="flex" flexDirection="row" justifyContent="center"> <Box display="flex" flexDirection="row" justifyContent="center">
<Typography> <Typography>
{props.upperToken} {props.upperToken === "FTSO" ? props.ftsoSymbol : props.upperToken === "STNK" ? props.stnkSymbol : props.ghstSymbol}
</Typography> </Typography>
</Box> </Box>
</Box> </Box>
@ -155,7 +127,7 @@ const StakeConfirmationModal = (props) => {
/> />
<Box display="flex" flexDirection="row" justifyContent="center"> <Box display="flex" flexDirection="row" justifyContent="center">
<Typography> <Typography>
{props.bottomToken} {props.bottomToken === "FTSO" ? props.ftsoSymbol : props.bottomToken === "STNK" ? props.stnkSymbol : props.ghstSymbol}
</Typography> </Typography>
</Box> </Box>
</Box> </Box>
@ -169,7 +141,7 @@ const StakeConfirmationModal = (props) => {
owner={props.address} owner={props.address}
spender={STAKING_ADDRESSES[props.chainId]} spender={STAKING_ADDRESSES[props.chainId]}
decimals={props.spendDecimals} decimals={props.spendDecimals}
approvalText={`Approve ${props.upperToken}`} approvalText={"Approve " + props.upperToken === "FTSO" ? props.ftsoSymbol : props.upperToken === "STNK" ? props.stnkSymbol : props.ghstSymbol}
approvalPendingText={"Approving..."} approvalPendingText={"Approving..."}
connect={props.connect} connect={props.connect}
isVertical isVertical

View File

@ -129,33 +129,33 @@ export const StakeInputArea = ({
} }
useEffect(() => { useEffect(() => {
const innerBalance = upperToken === ghstSymbol ? const innerBalance = upperToken === "GHST" ?
ghstBalance ghstBalance
: :
upperToken === stnkSymbol ? upperToken === "STNK" ?
stnkBalance stnkBalance
: :
ftsoBalance; ftsoBalance;
if ( if (
(upperToken === ftsoSymbol && bottomToken === stnkSymbol) || (upperToken === "FTSO" && bottomToken === "STNK") ||
(upperToken === stnkSymbol && bottomToken === ftsoSymbol) (upperToken === "STNK" && bottomToken === "FTSO")
) { ) {
setReceiveAmount(amount); setReceiveAmount(amount);
setExceedsAmount(new DecimalBigNumber(amount, 9).gt(innerBalance)) setExceedsAmount(new DecimalBigNumber(amount, 9).gt(innerBalance))
} else { } else {
const decimals = upperToken === ghstSymbol ? 18 : 9; const decimals = upperToken === "GHST" ? 18 : 9;
const raw = new DecimalBigNumber(amount, decimals); const raw = new DecimalBigNumber(amount, decimals);
const amountIn = new DecimalBigNumber(raw._value.toBigInt(), decimals); const amountIn = new DecimalBigNumber(raw._value.toBigInt(), decimals);
const result = upperToken === ghstSymbol ? const result = upperToken === "GHST" ?
currentIndex.mul(amountIn).toString() currentIndex.mul(amountIn).toString()
: :
currentIndex._value > 0n ? amountIn.div(currentIndex).toString() : "0"; currentIndex._value > 0n ? amountIn.div(currentIndex).toString() : "0";
const innerBalance = upperToken === ghstSymbol ? const innerBalance = upperToken === "GHST" ?
ghstBalance ghstBalance
: :
upperToken === stnkSymbol ? upperToken === "STNK" ?
stnkBalance stnkBalance
: :
ftsoBalance; ftsoBalance;
@ -168,7 +168,7 @@ export const StakeInputArea = ({
const handleTokenModalInput = (value, isUpper) => { const handleTokenModalInput = (value, isUpper) => {
if (isUpper) { if (isUpper) {
if (value === bottomToken) { if (value === bottomToken) {
const newValue = value === ghstSymbol ? stnkSymbol : ghstSymbol; const newValue = value === "GHST" ? "STNK" : "GHST";
setBottomToken(newValue) setBottomToken(newValue)
} }
setUpperToken(value); setUpperToken(value);
@ -185,19 +185,28 @@ export const StakeInputArea = ({
} }
const SwapCardTemplate = (tokenName, tokenAmount, isUpper, handleModal) => { const SwapCardTemplate = (tokenName, tokenAmount, isUpper, handleModal) => {
const balance = tokenName === stnkSymbol const balance = tokenName === "STNK" || tokenName === "sCSPR" ?
? stnkBalance stnkBalance : tokenName === "FTSO" || tokenName === "eCSPR" ?
: tokenName === ftsoSymbol ? ftsoBalance : ghstBalance; ftsoBalance : ghstBalance;
let realTokenName = ""; let realTokenName = "";
switch (tokenName.toUpperCase()) { switch (tokenName.toUpperCase()) {
case ftsoSymbol: case "FTSO":
realTokenName = ftsoSymbol; realTokenName = ftsoSymbol;
break; break;
case stnkSymbol: case "ECSPR":
realTokenName = ftsoSymbol;
break;
case "STNK":
realTokenName = stnkSymbol; realTokenName = stnkSymbol;
break; break;
case ghstSymbol: case "SCSPR":
realTokenName = stnkSymbol;
break;
case "GHST":
realTokenName = ghstSymbol;
break;
case "CSPR":
realTokenName = ghstSymbol; realTokenName = ghstSymbol;
break; break;
} }
@ -311,8 +320,8 @@ export const StakeInputArea = ({
receiveAmount={receiveAmount} receiveAmount={receiveAmount}
amountExceedsBalance={exceedsAmount} amountExceedsBalance={exceedsAmount}
connect={connect} connect={connect}
spendDecimals={upperToken === ghstSymbol ? 18 : 9} spendDecimals={upperToken === "GHST" ? 18 : 9}
receiveDecimals={bottomToken === ghstSymbol ? 18 : 9} receiveDecimals={bottomToken === "GHST" ? 18 : 9}
isClaim={isClaim} isClaim={isClaim}
isTrigger={isTrigger} isTrigger={isTrigger}
ftsoSymbol={ftsoSymbol} ftsoSymbol={ftsoSymbol}

View File

@ -69,9 +69,9 @@ const TokenModal = ({
</Link> </Link>
</Box> </Box>
<List> <List>
{<TokenItem isUpper={isUpper} exclude={tokenToExclude} token={ftsoSymbol} name={ftsoSymbol} balance={ftsoBalance} />} {<TokenItem isUpper={isUpper} exclude={tokenToExclude} token="FTSO" name={ftsoSymbol} balance={ftsoBalance} />}
{<TokenItem isUpper={isUpper} exclude={tokenToExclude} token={stnkSymbol} name={stnkSymbol} balance={stnkBalance} />} {<TokenItem isUpper={isUpper} exclude={tokenToExclude} token="STNK" name={stnkSymbol} balance={stnkBalance} />}
{<TokenItem isUpper={isUpper} exclude={tokenToExclude} token={ghstSymbol} name={ghstSymbol} balance={ghstBalance} />} {<TokenItem isUpper={isUpper} exclude={tokenToExclude} token="GHST" name={ghstSymbol} balance={ghstBalance} />}
</List> </List>
</Box> </Box>
</Dialog> </Dialog>

View File

@ -113,7 +113,7 @@ export const useGhostedSupply = (chainId) => {
return ghostedSupply; return ghostedSupply;
} }
export const stake = async (chainId, account, amount, isRebase, isClaim, ftsoSymbol, stnkSymbol, ghstSymbol) => { export const stake = async (chainId, account, amount, isRebase, isClaim) => {
const args = [ const args = [
amount, amount,
account, account,
@ -122,7 +122,7 @@ export const stake = async (chainId, account, amount, isRebase, isClaim, ftsoSym
]; ];
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: `FTSO tokens staked successfully! Wait for the warmup period to claim your ${isRebase ? "STNK" : "GHST"}.`,
errorMsg: "Staking transaction failed. Check logs for error detalization.", errorMsg: "Staking transaction failed. Check logs for error detalization.",
}; };
await executeOnChainTransaction( await executeOnChainTransaction(
@ -134,7 +134,7 @@ export const stake = async (chainId, account, amount, isRebase, isClaim, ftsoSym
); );
} }
export const unstake = async (chainId, account, amount, isTrigger, isRebase, ftsoSymbol, stnkSymbol, ghstSymbol) => { export const unstake = async (chainId, account, amount, isTrigger, isRebase) => {
const args = [ const args = [
amount, amount,
account, account,
@ -143,7 +143,7 @@ export const unstake = async (chainId, account, amount, isTrigger, isRebase, fts
]; ];
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 ? "STNK" : "GHST"} tokens unstaked successfully! Check your FTSO 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(
@ -155,10 +155,10 @@ export const unstake = async (chainId, account, amount, isTrigger, isRebase, fts
); );
} }
export const forfeit = async (chainId, account, ftsoSymbol) => { export const forfeit = async (chainId, account) => {
const messages = { const messages = {
replacedMsg: "Forfeit transaction was replaced. Wait for inclusion please.", replacedMsg: "Forfeit transaction was replaced. Wait for inclusion please.",
successMsg: `Tokens forfeited successfully! Check your ${ftsoSymbol} balance on ${shorten(account)}.`, successMsg: `Tokens forfeited successfully! Check your FTSO 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(
@ -170,11 +170,11 @@ export const forfeit = async (chainId, account, ftsoSymbol) => {
); );
} }
export const claim = async (chainId, account, isStnk, stnkSymbol, ghstSymbol) => { export const claim = async (chainId, account, isStnk) => {
const args = [account, isStnk]; const args = [account, isStnk];
const messages = { const messages = {
replacedMsg: "Claim transaction was replaced. Wait for inclusion please.", replacedMsg: "Claim transaction was replaced. Wait for inclusion please.",
successMsg: `${isStnk ? stnkSymbol : ghstSymbol} tokens claimed successfully to ${shorten(account)}.`, successMsg: `${isStnk ? "STNK" : "GHST"} 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(
@ -186,10 +186,10 @@ export const claim = async (chainId, account, isStnk, stnkSymbol, ghstSymbol) =>
); );
} }
export const unwrap = async (chainId, account, amount, stnkSymbol) => { export const unwrap = async (chainId, 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 STNK balance on ${shorten(account)}.`,
errorMsg: "Unwrap transaction failed. Check logs for error detalization.", errorMsg: "Unwrap transaction failed. Check logs for error detalization.",
}; };
await executeOnChainTransaction( await executeOnChainTransaction(
@ -201,10 +201,10 @@ export const unwrap = async (chainId, account, amount, stnkSymbol) => {
); );
} }
export const wrap = async (chainId, account, amount, ghstSymbol) => { export const wrap = async (chainId, 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 GHST balance on ${shorten(account)}.`,
errorMsg: "Wrap transaction failed. Check logs for error detalization.", errorMsg: "Wrap transaction failed. Check logs for error detalization.",
}; };
await executeOnChainTransaction( await executeOnChainTransaction(