Skip to content
Open
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
12 changes: 11 additions & 1 deletion components/nav_bar/navBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,22 @@ const NavBar = () => {
const [isMoreModalOpen, setIsMoreModalOpen] = useState(false);

useEffect(() => {
const connectWalletEvent = async () => {
try {
const chainId = await signer?.getChainId();
Analytics.actions.events.connections.walletConnect(true, chainId);
} catch (error) {
Analytics.actions.events.connections.walletConnect(true);
console.error(error);
}
};

if (signer?.account.address) {
Analytics.actions.people.registerWallet(signer.account.address);
Analytics.actions.identify(signer.account.address, {
account: signer.account.address,
});
Analytics.actions.events.connections.walletConnect(true);
connectWalletEvent();
}
}, [signer]);

Expand Down
7 changes: 5 additions & 2 deletions provider/analytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export type AnalyticsAmbientLPData = {
ambientLp?: string;
ambientLpBaseToken?: string;
ambientLpQuoteToken?: string;
ambientIsAmountBase?: boolean;
ambientLpBaseAmount?: string;
ambientLpQuoteAmount?: string;
ambientLpBaseBalance?: string;
Expand Down Expand Up @@ -162,9 +163,11 @@ class AnalyticsWrapper {
});
},
connections: {
walletConnect: (connected: boolean) => {
walletConnect: (connected: boolean, chainId?: number) => {
if (connected) {
posthog.capture("Wallet Connected");
posthog.capture("Wallet Connected", {
chainId,
});
} else {
posthog.capture("Wallet Disconnected");
}
Expand Down
16 changes: 8 additions & 8 deletions transactions/pairs/ambient/ambientTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ async function addConLiquidity(
quoteAmount = getConcQuoteTokensFromBaseTokens(
txParams.amount,
txParams.pool.stats.lastPriceSwap,
getPriceFromTick(txParams.lowerTick),
getPriceFromTick(txParams.upperTick)
txParams.lowerTick,
txParams.upperTick
);
} else {
quoteAmount = txParams.amount;
baseAmount = getConcBaseTokensFromQuoteTokens(
txParams.amount,
txParams.pool.stats.lastPriceSwap,
getPriceFromTick(txParams.lowerTick),
getPriceFromTick(txParams.upperTick)
txParams.lowerTick,
txParams.upperTick
);
}

Expand Down Expand Up @@ -207,8 +207,8 @@ export function validateAmbientLiquidityTxParams(
: getConcBaseTokensFromQuoteTokens(
txParams.amount,
currentPrice,
getPriceFromTick(txParams.lowerTick),
getPriceFromTick(txParams.upperTick)
txParams.lowerTick,
txParams.upperTick
);

if(Number(currentPrice) <= Number(getPriceFromTick(txParams.lowerTick)) && Number(baseAmount) !== 0){
Expand All @@ -229,8 +229,8 @@ export function validateAmbientLiquidityTxParams(
? getConcQuoteTokensFromBaseTokens(
txParams.amount,
currentPrice,
getPriceFromTick(txParams.lowerTick),
getPriceFromTick(txParams.upperTick)
txParams.lowerTick,
txParams.upperTick
)
: txParams.amount;

Expand Down
30 changes: 17 additions & 13 deletions utils/ambient/liquidity.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
convertTokenAmountToNote,
percentOfAmount,
} from "../math";
import { getPriceFromTick } from "./ambientMath.utils";
import { getPriceFromTick, getTickFromPrice } from "./ambientMath.utils";
import { AmbientPool } from "@/hooks/pairs/newAmbient/interfaces/ambientPools";
import { convertToBigNumber, formatBalance } from "../formatting";

Expand All @@ -27,9 +27,11 @@ import { convertToBigNumber, formatBalance } from "../formatting";
export function getConcQuoteTokensFromBaseTokens(
amount: string,
currentPrice: string,
minPrice: string,
maxPrice: string
lowerTick: number,
upperTick: number
): string {
const minPrice = getPriceFromTick(lowerTick)
const maxPrice = getPriceFromTick(upperTick)
// check if zero or current price is below min price
if (
!amount ||
Expand All @@ -51,8 +53,8 @@ export function getConcQuoteTokensFromBaseTokens(
Number(minPrice),
Number(maxPrice)
);
// overestimate amount by 1%
const quoteEstimate = percentOfAmount(quoteTokens.toString(), 101);
// overestimate amount by 3%
const quoteEstimate = percentOfAmount(quoteTokens.toString(), 103);
if (quoteEstimate.error) {
return "0";
}
Expand All @@ -71,9 +73,11 @@ export function getConcQuoteTokensFromBaseTokens(
export function getConcBaseTokensFromQuoteTokens(
amount: string,
currentPrice: string,
minPrice: string,
maxPrice: string
lowerTick: number,
upperTick: number
): string {
const minPrice = getPriceFromTick(lowerTick)
const maxPrice = getPriceFromTick(upperTick)
// check if zero or over max price
if (
!amount ||
Expand All @@ -95,8 +99,8 @@ export function getConcBaseTokensFromQuoteTokens(
Number(minPrice),
Number(maxPrice)
);
// overestimate amount by 1%
const baseEstimate = percentOfAmount(baseTokens.toString(), 101);
// overestimate amount by 3%
const baseEstimate = percentOfAmount(baseTokens.toString(), 103);
if (baseEstimate.error) {
return "0";
}
Expand Down Expand Up @@ -250,8 +254,8 @@ export function getDisplayTokenAmountFromRange(
const quoteEstimateWei = getConcQuoteTokensFromBaseTokens(
weiAmount,
pool.stats.lastPriceSwap,
minPriceWei,
maxPriceWei
getTickFromPrice(minPriceWei),
getTickFromPrice(maxPriceWei)
);
return formatBalance(quoteEstimateWei, pool.quote.decimals, {
precision: pool.quote.decimals,
Expand All @@ -261,8 +265,8 @@ export function getDisplayTokenAmountFromRange(
const baseEstimateWei = getConcBaseTokensFromQuoteTokens(
weiAmount,
pool.stats.lastPriceSwap,
minPriceWei,
maxPriceWei
getTickFromPrice(minPriceWei),
getTickFromPrice(maxPriceWei)
);
return formatBalance(baseEstimateWei, pool.base.decimals, {
precision: pool.base.decimals,
Expand Down
1 change: 1 addition & 0 deletions utils/analytics/analytics.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ function getAmbientLiquidityTransactionFlowData(
return {
...poolData,
ambientLpIsAdvanced: ambientLiquidityTxParams.isAdvanced ?? false,
ambientIsAmountBase: ambientLiquidityTxParams.isAmountBase,
ambientLpBaseAmount: baseAmount,
ambientLpQuoteAmount: quoteAmount,
ambientLpBaseBalance: baseBalance,
Expand Down