Skip to content

Commit

Permalink
add manta pacific chain
Browse files Browse the repository at this point in the history
  • Loading branch information
anassohail99 committed May 6, 2024
1 parent 02e4f4b commit 06794d6
Showing 1 changed file with 64 additions and 42 deletions.
106 changes: 64 additions & 42 deletions projects/a51-finance-v3/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const { getLogs } = require("../helper/cache/getLogs")
const { sumTokens2 } = require("../helper/unwrapLPs")
const { getLogs } = require("../helper/cache/getLogs");
const { sumTokens2 } = require("../helper/unwrapLPs");
const { staking } = require("../helper/staking");

const A51_STAKING_CONTRACT = "0x10a62e0d8491751c40476d432f9e19ba8f699a61";
const A51 = "0xe9e7c09e82328c3107d367f6c617cf9977e63ed0";


const getStrategiesDetails = "function strategies(bytes32) view returns ( tuple(address pool, int24 tickLower, int24 tickUpper) key, address owner, bytes actions, bytes actionStatus, bool isCompound, bool isPrivate, uint256 managementFee, uint256 performanceFee, tuple(uint256 fee0, uint256 fee1, uint256 balance0, uint256 balance1, uint256 totalShares, uint128 uniswapLiquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128) account)"
const getStrategyReserves = "function getStrategyReserves(address, int24, int24, uint128) returns (uint256 reserves0, uint256 reserves1)"
const getStrategiesDetails =
"function strategies(bytes32) view returns ( tuple(address pool, int24 tickLower, int24 tickUpper) key, address owner, bytes actions, bytes actionStatus, bool isCompound, bool isPrivate, uint256 managementFee, uint256 performanceFee, tuple(uint256 fee0, uint256 fee1, uint256 balance0, uint256 balance1, uint256 totalShares, uint128 uniswapLiquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128) account)";
const getStrategyReserves =
"function getStrategyReserves(address, int24, int24, uint128) returns (uint256 reserves0, uint256 reserves1)";

const ADDRESSES = {
arbitrum: {
Expand Down Expand Up @@ -38,9 +39,13 @@ const ADDRESSES = {
CLTBASE: "0xA8Dc31c8C9F93dB2e42A5472F580689794639576",
HELPER: "0x965356eb2C208Ce4130E267342cA720042Cce7b2",
},
}
mantaPacific: {
CLTBASE: "0x69317029384c3305fC04670c68a2b434e2D8C44C",
HELPER: "0xa1d8180f4482359ceb7eb7437fcf4a2616830f81",
},
};

const DEFAULT_STRATEGY_CREATION_TOPIC = "StrategyCreated(bytes32)"
const DEFAULT_STRATEGY_CREATION_TOPIC = "StrategyCreated(bytes32)";

const START_BLOCKS = {
arbitrum: {
Expand All @@ -64,71 +69,88 @@ const START_BLOCKS = {
scroll: {
CLTBASE: 4846051,
},
}
mantaPacific: {
CLTBASE: 1834975,
},
};

async function getStrategiesLogs(strategies, factoryType, api) {
const chain = api.chain
let topic = DEFAULT_STRATEGY_CREATION_TOPIC
const chain = api.chain;
let topic = DEFAULT_STRATEGY_CREATION_TOPIC;

const strategyLogs = await getLogs({
target: ADDRESSES[chain][factoryType],
topic,
fromBlock: START_BLOCKS[chain][factoryType],
api,
})
});

for (let log of strategyLogs)
strategies.push(log.topics[1])
for (let log of strategyLogs) strategies.push(log.topics[1]);

return strategies
return strategies;
}

async function tvl(api) {
const chain = api.chain
const strategies = []
const pools = []
const reservesCalls = []
const chain = api.chain;
const strategies = [];
const pools = [];
const reservesCalls = [];

for (const label of Object.keys(START_BLOCKS[api.chain]))
await getStrategiesLogs(strategies, label, api)
await getStrategiesLogs(strategies, label, api);

const strategyDetails = await api.multiCall({
abi: getStrategiesDetails,
target: ADDRESSES[chain].CLTBASE,
calls: strategies,
})

strategyDetails.forEach(({ key: { pool, tickLower, tickUpper }, account }) => {
pools.push(pool)

reservesCalls.push({
target: ADDRESSES[chain].HELPER,
params: [pool, Number(tickLower), Number(tickUpper), account.uniswapLiquidity,],
})
})
});

strategyDetails.forEach(
({ key: { pool, tickLower, tickUpper }, account }) => {
pools.push(pool);

reservesCalls.push({
target: ADDRESSES[chain].HELPER,
params: [
pool,
Number(tickLower),
Number(tickUpper),
account.uniswapLiquidity,
],
});
}
);

const [token0s, token1s, reserves] = await Promise.all([
api.multiCall({ abi: 'address:token0', calls: pools, }),
api.multiCall({ abi: 'address:token1', calls: pools, }),
api.multiCall({ abi: getStrategyReserves, calls: reservesCalls, target: ADDRESSES[chain].HELPER, }),
])
api.multiCall({ abi: "address:token0", calls: pools }),
api.multiCall({ abi: "address:token1", calls: pools }),
api.multiCall({
abi: getStrategyReserves,
calls: reservesCalls,
target: ADDRESSES[chain].HELPER,
}),
]);

reserves.forEach((reserve, index) => {
api.add(token0s[index], reserve.reserves0)
api.add(token1s[index], reserve.reserves1)
})
api.add(token0s[index], reserve.reserves0);
api.add(token1s[index], reserve.reserves1);
});

return sumTokens2({ owner: ADDRESSES[chain].CLTBASE, tokens: token0s.concat(token1s), api, })
return sumTokens2({
owner: ADDRESSES[chain].CLTBASE,
tokens: token0s.concat(token1s),
api,
});
}

module.exports = {
doublecounted: true,
}
};

Object.keys(ADDRESSES).forEach((chain) => {
module.exports[chain] = { tvl }
})
module.exports[chain] = { tvl };
});

if (!module.exports.polygon) module.exports.polygon = {}
if (!module.exports.polygon) module.exports.polygon = {};

module.exports.polygon.staking = staking(A51_STAKING_CONTRACT, A51)
module.exports.polygon.staking = staking(A51_STAKING_CONTRACT, A51);

0 comments on commit 06794d6

Please sign in to comment.