fixed getAmountAt

This commit is contained in:
Kirill Litvinov
2024-03-12 15:18:48 +03:00
parent c814d41dc1
commit daf45567c8
3 changed files with 21 additions and 11 deletions

View File

@@ -9,7 +9,7 @@ import {
PoolV2InfoResponseSchema,
testIncrementorSchema,
veORNInfoResponseSchema,
votingInfoResponseSchema
votingInfoResponseSchema,
} from './schemas';
import { fetchWithValidation } from 'simple-typed-fetch';
import { BigNumber } from 'bignumber.js';
@@ -118,16 +118,23 @@ class IndexerService {
});
};
readonly getAmountAt = (amount: number, timestamp?: number): BigNumber => {
const finalTimestamp = timestamp !== undefined ? timestamp / 1000 : Date.now() / 1000;
/**
* @param {number} amount - amount
* @param {number} [timestamp = Date.now()] - timestamp, defaults to current time
*/
readonly getAmountAt = (
amount: number,
timestamp = Date.now()
): BigNumber => {
const finalTimestamp = timestamp / 1000;
// sqrt
return BigNumber(amount).dividedBy(this.getK(finalTimestamp));
};
/**
* @deprecated In favor of getAmountAt
*/
* @deprecated since version 69 in favor of getAmountAt
*/
readonly getAmountAtCurrent = (amount: number): BigNumber => {
const timestamp = Date.now() / 1000;
@@ -145,8 +152,7 @@ class IndexerService {
const multSQRT = deltaDaysBN.dividedBy(WEEK_DAYS).sqrt();
const multCUBE = deltaDaysBN.dividedBy(alpha).pow(3);
return BigNumber(amountToken)
.multipliedBy(multSQRT.plus(multCUBE));
return BigNumber(amountToken).multipliedBy(multSQRT.plus(multCUBE));
};
readonly getVotingInfo = (userAddress?: string) => {
@@ -219,7 +225,11 @@ class IndexerService {
});
};
readonly poolV2Info = (token0: string, token1: string, address: string | undefined) => {
readonly poolV2Info = (
token0: string,
token1: string,
address: string | undefined
) => {
return fetchWithValidation(this.apiUrl, PoolV2InfoResponseSchema, {
method: 'POST',
body: this.makeRPCPayload({