Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for baseswap dex base chain #10164

Closed
wants to merge 1 commit into from
Closed
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
108 changes: 66 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 @@ -42,9 +43,14 @@
CLTBASE: "0x69317029384c3305fC04670c68a2b434e2D8C44C",
HELPER: "0xa1d8180f4482359ceb7eb7437fcf4a2616830f81",
},
}
base: {

Check failure on line 46 in projects/a51-finance-v3/index.js

View workflow job for this annotation

GitHub Actions / test

Duplicate key 'base'
// different dex
CLTBASE: "0xDFb179526ae303Eea49AC99DD360159C39105828",
HELPER: "0x6e7e838E20ED6657Aaf1166f9B7a845565956F51",
},
};

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

const START_BLOCKS = {
arbitrum: {
Expand All @@ -71,71 +77,89 @@
manta: {
CLTBASE: 1834975,
},
}
base: {

Check failure on line 80 in projects/a51-finance-v3/index.js

View workflow job for this annotation

GitHub Actions / test

Duplicate key 'base'
// different dex
CLTBASE: 13890566,
},
};

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);
Loading