Skip to content

Commit

Permalink
Merge branch 'release.1.0.2' into stage
Browse files Browse the repository at this point in the history
  • Loading branch information
dsudit01 committed Mar 4, 2024
2 parents 9cf8488 + 3836bb3 commit c4dfa81
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 13 deletions.
6 changes: 6 additions & 0 deletions app/governance/components/ProposalTable/ProposalTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import Container from "@/components/container/container";
import { Pagination } from "@/components/pagination/Pagination";
import Spacer from "@/components/layout/spacer";
import { ProposalRow } from "./ProposalRow";
import Analytics from "@/provider/analytics";
import { getAnalyticsProposalInfo } from "@/utils/analytics";

interface TableProps {
proposals: Proposal[];
Expand All @@ -27,6 +29,9 @@ const ProposalTable = ({ proposals }: TableProps) => {
const router = useRouter();
const handleRowClick = (proposalId: any) => {
// Navigate to the appropriate page
Analytics.actions.events.governance.proposalClicked(
getAnalyticsProposalInfo(proposalId, proposals)
);
router.push(`/governance/proposal?id=${proposalId}`);
};

Expand Down Expand Up @@ -155,6 +160,7 @@ const ProposalTable = ({ proposals }: TableProps) => {
const proposalFilter = Object.values(ProposalFilter).find(
(filter) => filter.split(" ")[0] === value
);
Analytics.actions.events.governance.tabSwitched(value);
setCurrentFilter(proposalFilter || ProposalFilter.ALL);
}}
/>
Expand Down
1 change: 1 addition & 0 deletions app/governance/proposal/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default function Page() {
chainId: chainId,
ethAccount: signer.account.address,
proposalId: proposalId,
proposal: proposals.find((p) => p.proposal_id === Number(proposalId)),
voteOption: voteOption,
});
txStore?.addNewFlow({
Expand Down
12 changes: 12 additions & 0 deletions app/lp/components/ambient/managePosition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ const AddLiquidity = ({
min="0"
max={pool.base.balance ?? "0"}
symbol={pool.base.symbol}
ambientAmountError={
Number(pool.stats.lastPriceSwap) <=
Number(
positionManager.getWeiRangePrice(positionValues.lowerPrice)
) && Number(amountBase) !== 0
}
/>
<Spacer height="10px" />
<Amount
Expand All @@ -173,6 +179,12 @@ const AddLiquidity = ({
max={pool.quote.balance ?? "0"}
min="0"
symbol={pool.quote.symbol}
ambientAmountError={
Number(pool.stats.lastPriceSwap) >=
Number(
positionManager.getWeiRangePrice(positionValues.upperPrice)
) && Number(amountQuote) !== 0
}
/>
<Spacer height="10px" />
<Container className={styles.card}>
Expand Down
18 changes: 18 additions & 0 deletions app/lp/components/ambient/newAmbientPosition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
} from "@/utils/ambient/liquidityControllers";
import { Validation } from "@/config/interfaces";
import Analytics from "@/provider/analytics";
import BigNumber from "bignumber.js";
import useScreenSize from "@/hooks/helpers/useScreenSize";
interface NewPositionModalProps {
pool: AmbientPool;
Expand Down Expand Up @@ -83,6 +84,11 @@ export const NewAmbientPositionModal = ({

const percentDiff = (currentPrice: number, selectedPrice: number) =>
formatPercent(((selectedPrice - currentPrice) / currentPrice).toString());
function getWeiRangePrice(priceFormatted: string): string {
const scale = BigNumber(10).pow(pool.base.decimals - pool.quote.decimals);
const priceWei = scale.multipliedBy(priceFormatted).toString();
return priceWei;
}
const { isMobile } = useScreenSize();
return (
<Container
Expand Down Expand Up @@ -158,6 +164,12 @@ export const NewAmbientPositionModal = ({
max={baseToken.balance ?? "0"}
maxName="LP Modal"
symbol={baseToken.symbol}
ambientAmountError={
Number(pool.stats.lastPriceSwap) <=
Number(
getWeiRangePrice(positionManager.options.minRangePrice)
) && Number(positionManager.options.amountBase) !== 0
}
/>
<Spacer height="12px" />
<Amount
Expand All @@ -172,6 +184,12 @@ export const NewAmbientPositionModal = ({
max={quoteToken.balance ?? "0"}
maxName="LP Modal"
symbol={quoteToken.symbol}
ambientAmountError={
Number(pool.stats.lastPriceSwap) >=
Number(
getWeiRangePrice(positionManager.options.maxRangePrice)
) && Number(positionManager.options.amountQuote) !== 0
}
/>
<Spacer height="20px" />
<Container className={styles.card}>
Expand Down
22 changes: 20 additions & 2 deletions app/lp/components/dexModals/AddLiquidityModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Toggle from "@/components/toggle";
import { areEqualAddresses } from "@/utils/address";
import PopUp from "@/components/popup/popup";
import { CantoDexTxTypes } from "@/transactions/pairs/cantoDex";
import BigNumber from "bignumber.js";

interface AddLiquidityProps {
pair: CantoDexPairWithUserCTokenData;
Expand Down Expand Up @@ -91,6 +92,23 @@ export const AddLiquidityModal = ({
: token.symbol;
};

// function to get max input amount
const tokenBalance = (token: {
chainId: number;
address: string;
balance?: string;
}) => {
const updatedBalance = BigNumber(token.balance ?? "0").minus(
"1000000000000000000"
);
const wcantoAddress = getCantoCoreAddress(Number(token.chainId), "wcanto");
return areEqualAddresses(token.address, wcantoAddress ?? "")
? updatedBalance.isNegative()
? "0"
: updatedBalance.toString()
: token.balance ?? "0";
};

return (
<Container margin="sm">
<div className={styles.iconTitle}>
Expand All @@ -107,7 +125,7 @@ export const AddLiquidityModal = ({
IconUrl={pair.token1.logoURI}
title={tokenSymbol(pair.token1)}
min="1"
max={pair.token1.balance ?? "0"}
max={tokenBalance(pair.token1)}
maxName="LP Modal"
symbol={tokenSymbol(pair.token1)}
/>
Expand All @@ -121,7 +139,7 @@ export const AddLiquidityModal = ({
IconUrl={pair.token2.logoURI}
title={tokenSymbol(pair.token2)}
min="1"
max={pair.token2.balance ?? "0"}
max={tokenBalance(pair.token2)}
maxName="LP Modal"
symbol={tokenSymbol(pair.token2)}
/>
Expand Down
20 changes: 13 additions & 7 deletions components/amount/amount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import clsx from "clsx";
import Spacer from "../layout/spacer";
import { validateNonWeiUserInputTokenAmount } from "@/utils/math";
import Analytics from "@/provider/analytics";
import { TX_PARAM_ERRORS } from "@/config/consts/errors";

interface Props {
IconUrl: string;
title: string;
Expand All @@ -23,6 +25,7 @@ interface Props {
};
extraNode?: React.ReactNode;
maxName?: string;
ambientAmountError?: boolean;
}
const Amount = (props: Props) => {
const [focused, setFocused] = useState(false);
Expand Down Expand Up @@ -74,20 +77,23 @@ const Amount = (props: Props) => {
// deal with error inputs
const inputError = useMemo(
() =>
validateNonWeiUserInputTokenAmount(
props.value,
props.min,
props.limit?.limit ?? props.max,
props.symbol,
props.decimals
),
!props.ambientAmountError
? validateNonWeiUserInputTokenAmount(
props.value,
props.min,
props.limit?.limit ?? props.max,
props.symbol,
props.decimals
)
: { error: true, reason: TX_PARAM_ERRORS.AMBIENT_AMOUNT_ERROR() },
[
props.value,
props.max,
props.min,
props.decimals,
props.symbol,
props.limit?.limit,
props.ambientAmountError,
]
);

Expand Down
1 change: 1 addition & 0 deletions config/consts/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const TX_PARAM_ERRORS = {
`${
min ? "Minimum" : "Maximum"
} execution price must be less than or equal to ${price}`,
AMBIENT_AMOUNT_ERROR: () => "Amount must be 0 in selected price range",
};
export const TX_SIGN_ERRORS = {
INCORRECT_TX_TYPE: (txType: string) => `Incorrect tx type ${txType}`,
Expand Down
20 changes: 19 additions & 1 deletion provider/analytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { CTokenLendingTxTypes } from "@/transactions/lending";
import { CantoDexTxTypes } from "@/transactions/pairs/cantoDex";
import { AmbientTxType } from "@/transactions/pairs/ambient";
import { StakingTxTypes } from "@/transactions/staking";
import { VoteOption } from "@/transactions/gov";
import posthog from "posthog-js";

// (BRIDGE/LP/LENDING/...)
Expand Down Expand Up @@ -93,12 +94,19 @@ export type AnalyticsStakingData = {
stakingNewValidator?: string;
};

export type AnalyticsGovernanceData = {
govProposalId?: Number,
govProposalTitle?: string,
govVoteOption?: VoteOption,
};

export type AnalyticsTransactionFlowData =
| AnalyticsBridgeData
| AnalyticsCantoLPData
| AnalyticsAmbientLPData
| AnalyticsLMData
| AnalyticsStakingData;
| AnalyticsStakingData
| AnalyticsGovernanceData;;

// tx types (approve/mint/swap/...)
type AnalyticsTransactionType = CantoFETxType;
Expand Down Expand Up @@ -239,6 +247,16 @@ class AnalyticsWrapper {
});
},
},
governance: {
proposalClicked: (params: AnalyticsGovernanceData) => {
posthog.capture("Proposal Clicked", params);
},
tabSwitched: (tab: string) => {
posthog.capture("Proposal Tab Switched", {
tab,
});
},
},
transactionFlows: {
started: (params: AnalyticsTransactionFlowParams) => {
posthog.capture("Transaction Flow Started", params);
Expand Down
2 changes: 2 additions & 0 deletions transactions/gov/voteTxParams.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Proposal } from "@/hooks/gov/interfaces/proposal";
import { VoteOption } from "./voteOptions";

export interface ProposalVoteTxParams {
chainId: number;
ethAccount: string;
proposalId: number;
proposal?: Proposal;
voteOption: VoteOption;
}
10 changes: 10 additions & 0 deletions transactions/pairs/ambient/ambientTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ export function validateAmbientLiquidityTxParams(
getPriceFromTick(txParams.lowerTick),
getPriceFromTick(txParams.upperTick)
);

if(Number(currentPrice) <= Number(getPriceFromTick(txParams.lowerTick)) && Number(baseAmount) !== 0){
return {error: true, reason: TX_PARAM_ERRORS.AMBIENT_AMOUNT_ERROR()}
}

const baseCheck = validateWeiUserInputTokenAmount(
baseAmount,
"0",
Expand All @@ -228,6 +233,11 @@ export function validateAmbientLiquidityTxParams(
getPriceFromTick(txParams.upperTick)
)
: txParams.amount;

if(Number(currentPrice) >= Number(getPriceFromTick(txParams.upperTick)) && Number(quoteAmount) !== 0){
return {error: true, reason: TX_PARAM_ERRORS.AMBIENT_AMOUNT_ERROR()}
}

const quoteCheck = validateWeiUserInputTokenAmount(
quoteAmount,
"0",
Expand Down
19 changes: 17 additions & 2 deletions transactions/pairs/cantoDex/cantoDexTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { TransactionFlowType } from "@/transactions/flows";
import { CTokenLendingTxTypes, cTokenLendingTx } from "@/transactions/lending";
import { quoteRemoveLiquidity } from "@/utils/cantoDex";
import { getTokenBalance } from "@/utils/tokens";
import BigNumber from "bignumber.js";

export async function cantoDexLPTx(
txParams: CantoDexTransactionParams
Expand Down Expand Up @@ -93,14 +94,14 @@ export function validateCantoDexLPTxParams(
validateWeiUserInputTokenAmount(
txParams.amounts.amount1,
"1",
token1.balance ?? "0",
tokenBalance(token1),
token1.symbol,
token1.decimals
),
validateWeiUserInputTokenAmount(
txParams.amounts.amount2,
"1",
token2.balance ?? "0",
tokenBalance(token2),
token2.symbol,
token2.decimals
),
Expand Down Expand Up @@ -464,3 +465,17 @@ export async function stakeCantoDexLPTx(
return NEW_ERROR("stakeCantoDexLPTx", err);
}
}


// function to get max input amount
const tokenBalance = (token: {
chainId: number;
address: string;
balance?: string;
}) => {
const updatedBalance = BigNumber(token.balance ?? "0").minus("1000000000000000000");
const wcantoAddress = getCantoCoreAddress(Number(token.chainId), "wcanto");
return areEqualAddresses(token.address, wcantoAddress ?? "")
? updatedBalance.isNegative() ? "0" : updatedBalance.toString()
: token.balance ?? "0"
};
Loading

0 comments on commit c4dfa81

Please sign in to comment.