mirror of
https://github.com/alexgo-io/DefiLlama-Adapters.git
synced 2026-04-29 13:25:30 +08:00
Use limiter directly in algorand helper
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
const { RateLimiter } = require("limiter");
|
||||
|
||||
const pools = [
|
||||
{
|
||||
// Algo
|
||||
@@ -82,8 +80,6 @@ const oracleAdapterAppId = 751277258;
|
||||
const oracleDecimals = 14;
|
||||
const tinymanValidatorAppId = 552635992;
|
||||
|
||||
const limiter = new RateLimiter({ tokensPerInterval: 10, interval: "second" });
|
||||
|
||||
module.exports = {
|
||||
pools,
|
||||
liquidGovernanceAppId,
|
||||
@@ -91,5 +87,4 @@ module.exports = {
|
||||
oracleAdapterAppId,
|
||||
oracleDecimals,
|
||||
tinymanValidatorAppId,
|
||||
limiter,
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const { toUSDTBalances } = require("../helper/balances");
|
||||
|
||||
const { pools, liquidGovernanceAppId, limiter } = require("./constants");
|
||||
const { pools, liquidGovernanceAppId } = require("./constants");
|
||||
const {
|
||||
lookupApplications,
|
||||
lookupAccountByID,
|
||||
@@ -10,7 +10,6 @@ const { getAppState, getParsedValueFromState } = require("./utils");
|
||||
const { getPrices } = require("./prices");
|
||||
|
||||
async function getAlgoLiquidGovernanceDepositUsd(prices) {
|
||||
await limiter.removeTokens(2);
|
||||
const [app, acc] = await Promise.all([
|
||||
lookupApplications(liquidGovernanceAppId),
|
||||
lookupAccountByID(getApplicationAddress(liquidGovernanceAppId)),
|
||||
|
||||
@@ -5,7 +5,6 @@ const {
|
||||
pools,
|
||||
tinymanValidatorAppId,
|
||||
oracleDecimals,
|
||||
limiter,
|
||||
} = require("./constants");
|
||||
const {
|
||||
getAppState,
|
||||
@@ -17,7 +16,6 @@ const {
|
||||
} = require("./utils");
|
||||
|
||||
async function getTinymanLPPrice(validatorAppId, poolAddress, p0, p1) {
|
||||
await limiter.removeTokens(1);
|
||||
const res = await lookupAccountByID(poolAddress);
|
||||
const { account } = res;
|
||||
|
||||
@@ -36,7 +34,6 @@ async function getTinymanLPPrice(validatorAppId, poolAddress, p0, p1) {
|
||||
}
|
||||
|
||||
async function getPactLPPrice(poolAppId, p0, p1) {
|
||||
await limiter.removeTokens(1);
|
||||
const res = await lookupApplications(poolAppId);
|
||||
const state = res.application.params["global-state"];
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
const { lookupApplications } = require("../helper/algorand");
|
||||
const { encodeAddress } = require("../helper/algorandUtils/address");
|
||||
const { limiter } = require("./constants");
|
||||
|
||||
function fromIntToBytes8Hex(num) {
|
||||
return num.toString(16).padStart(16, "0");
|
||||
@@ -49,7 +48,6 @@ function getParsedValueFromState(state, key, encoding = "utf8") {
|
||||
}
|
||||
|
||||
async function getAppState(appId) {
|
||||
await limiter.removeTokens(1);
|
||||
const res = await lookupApplications(appId);
|
||||
return res.application.params["global-state"];
|
||||
}
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
|
||||
const axios = require('axios')
|
||||
const { getApplicationAddress } = require('./algorandUtils/address')
|
||||
const { RateLimiter } = require("limiter");
|
||||
|
||||
const axiosObj = axios.create({
|
||||
baseURL: 'https://algoindexer.algoexplorerapi.io',
|
||||
timeout: 300000,
|
||||
})
|
||||
|
||||
const indexerLimiter = new RateLimiter({ tokensPerInterval: 10, interval: "second" });
|
||||
|
||||
async function lookupApplications(appId) {
|
||||
return (await axiosObj.get(`/v2/applications/${appId}`)).data
|
||||
}
|
||||
@@ -15,6 +18,7 @@ async function lookupApplications(appId) {
|
||||
async function lookupAccountByID(appId) {
|
||||
return (await axiosObj.get(`/v2/accounts/${appId}`)).data
|
||||
}
|
||||
|
||||
async function searchAccounts({ appId, limit = 1000, nexttoken, }) {
|
||||
const response = (await axiosObj.get('/v2/accounts', {
|
||||
params: {
|
||||
@@ -26,11 +30,15 @@ async function searchAccounts({ appId, limit = 1000, nexttoken, }) {
|
||||
return response.data
|
||||
}
|
||||
|
||||
|
||||
const withLimiter = (fn, tokensToRemove = 1) => async (...args) => {
|
||||
await indexerLimiter.removeTokens(tokensToRemove);
|
||||
return fn(...args);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
lookupApplications,
|
||||
lookupAccountByID,
|
||||
getApplicationAddress,
|
||||
searchAccounts,
|
||||
lookupApplications: withLimiter(lookupApplications),
|
||||
lookupAccountByID: withLimiter(lookupAccountByID),
|
||||
searchAccounts: withLimiter(searchAccounts),
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user