minor fixes

This commit is contained in:
g1nt0ki
2023-01-11 14:52:46 +01:00
parent 772497da1b
commit 4896e6b9df
5 changed files with 39 additions and 76 deletions

View File

@@ -1,4 +0,0 @@
{
"aelinPool_purchaseToken": "address:purchaseToken",
"aelinPool_aelinRewardsAddress": "address:aelinRewardsAddress"
}

View File

@@ -1,77 +1,50 @@
const sdk = require('@defillama/sdk');
const { request, gql } = require("graphql-request");
const { getBlock } = require('../helper/http');
const { staking } = require('../helper/staking')
const { pool2 } = require('../helper/pool2')
const { unwrapUniswapLPs } = require('../helper/unwrapLPs')
const { unwrapUniswapLPs, sumTokens2, } = require('../helper/unwrapLPs')
const { getLogs } = require('../helper/cache/getLogs')
const { default: BigNumber } = require('bignumber.js')
const abi = require('./abi.json')
const aelin_data = {
'ethereum': {
logConfig: [
{ target: '0x2c0979b0de5f99c2bde1e698aeca13b55695951e', fromBlock: 13996006 },
{ target: '0x5541da82549d732878c4104c9887c408790397af', fromBlock: 13846412 },
],
'graphUrl': 'https://api.thegraph.com/subgraphs/name/aelin-xyz/aelin',
'AELIN_ETH_LP': '0x974d51fafc9013e42cbbb9465ea03fe097824bcc',
'AELIN_ETH_staking': '0x944cb90082fc1416d4b551a21cfe6d7cc5447c80',
'AELIN': '0xa9c125bf4c8bb26f299c00969532b66732b1f758'
},
'optimism': {
'graphUrl': 'https://api.thegraph.com/subgraphs/name/aelin-xyz/optimism',
logConfig: [
{ target: '0x9219f9f65b007fd3ba0b53762861f54062531a31', fromBlock: 2266169 },
{ target: '0x87525307974a312AF13a78041F88B0BAe23ebb10', fromBlock: 1487918 },
{ target: '0x914ffc8dc0678911aae77f51b8489d6e214da20f', fromBlock: 1971285 },
],
'graphUrl': 'https://api.thegraph.com/subgraphs/name/aelin-xyz/optimism',
'AELIN': '0x61BAADcF22d2565B0F471b291C475db5555e0b76',
'AELIN_staking': '0xfe757a40f3eda520845b339c698b321663986a4d',
'AELIN_ETH_LP': '0x665d8D87ac09Bdbc1222B8B9E72Ddcb82f76B54A',
'AELIN_ETH_staking': '0x4aec980a0daef4905520a11b99971c7b9583f4f8',
'vAELIN': '0x780f70882fF4929D1A658a4E8EC8D4316b24748A',
'vAELIN': '0x780f70882fF4929D1A658a4E8EC8D4316b24748A',
},
}
// https://thegraph.com/hosted-service/subgraph/aelin-xyz/optimism
const graphQuery = gql`
query GET_AELIN_POOLS ($minGotchiId: Int, $block: Int) {
poolCreateds(
first: 1000
skip: 0
block: { number: $block }
) {
id
name
}
totalPoolsCreateds(first: 5) {
count
}
}`
function tvl(chain) {
return async (timestamp, ethBlock, chainBlocks) => {
const block = await getBlock(timestamp, chain, chainBlocks, false) - 100; // graph out of sync
const { poolCreateds, totalPoolsCreateds } = await request(
aelin_data[chain]['graphUrl'],
graphQuery,
{block}
);
const n_pools = totalPoolsCreateds[0]['count']
const poolsAddressesCalls = poolCreateds.map(p => ({ target: p.id }))
console.log(`${chain} - ${block}: n_pools: ${poolsAddressesCalls.length} / ${n_pools}`) // , poolsAddressesCalls)
const {output: purchaseTokens} = await sdk.api.abi.multiCall({
calls: poolsAddressesCalls,
abi: abi["aelinPool_purchaseToken"],
chain,
block,
})
const balancesCall = purchaseTokens.map((purchaseToken, i) =>
({ target: purchaseToken.output, params: [poolCreateds[i].id] }))
const tokenBalances = await sdk.api.abi.multiCall({
calls: balancesCall,
abi: "erc20:balanceOf",
chain,
block,
return async (timestamp, ethBlock, chainBlocks, { api }) => {
const { logConfig } = aelin_data[chain]
const logs = (await Promise.all(logConfig.map(({ target, fromBlock }) => getLogs({
api,
target,
topics: ['0x2f9902ccfa1b25adff84fa12ff5b7cbcffcb5578f08631567f5173b39c3004fe'],
fromBlock,
eventAbi: 'event CreatePool(address indexed poolAddress, string name, string symbol, uint256 purchaseTokenCap, address indexed purchaseToken, uint256 duration, uint256 sponsorFee, address indexed sponsor, uint256 purchaseDuration, bool hasAllowList)'
})
))).flat()
// console.log(rewardsBalances.output.map(b => b.input.params + ' aelinRewardsAddress pool has: ' + BigNumber(b.output).div(1e18).toFixed(0) + ' of purchaseToken ' + b.input.target))
const balances = {};
sdk.util.sumMultiBalanceOf(balances, tokenBalances, true, x => `${chain}:${x}`);
return balances
return sumTokens2({ api, tokensAndOwners: logs.map(i => ([i.args.purchaseToken, i.args.poolAddress])) })
}
}
@@ -79,13 +52,13 @@ function stakingTVL(chain) {
return async (timestamp, ethBlock, chainBlocks) => {
if (chain === 'ethereum') {
return {}
}
}
const staked = await staking(
aelin_data[chain]['AELIN_staking'],
aelin_data[chain]['AELIN'],
aelin_data[chain]['AELIN_staking'],
aelin_data[chain]['AELIN'],
chain
) (timestamp, ethBlock, chainBlocks)
)(timestamp, ethBlock, chainBlocks)
return staked
}
}
@@ -97,25 +70,25 @@ function pool2TVL(chain) {
const block = await getBlock(timestamp, chain, chainBlocks, false) - 100; // graph out of sync
if (chain === 'ethereum') {
const staked = await pool2(stakingContract, lpToken, chain) (timestamp, ethBlock, chainBlocks)
const staked = await pool2(stakingContract, lpToken, chain)(timestamp, ethBlock, chainBlocks)
const aelin_addr = `ethereum:${aelin_data[chain]['AELIN']}`
staked['AELIN'] = BigNumber(staked[aelin_addr]).div(1e18).toFixed(0)
staked[aelin_addr] = 0
return staked
}
}
else if (chain === 'optimism') {
const balances = {}
const transformAddress = (addr) => `${chain}:${addr}`;
const {output: heldLPshares} = await sdk.api.abi.call({
abi: 'erc20:balanceOf',
target: lpToken,
params: stakingContract,
chain,
block,
const { output: heldLPshares } = await sdk.api.abi.call({
abi: 'erc20:balanceOf',
target: lpToken,
params: stakingContract,
chain,
block,
})
const lpBalances = [
{
balance: heldLPshares,
balance: heldLPshares,
token: lpToken
}
]

View File

@@ -3,7 +3,4 @@ const { masterChefExports } = require("../helper/masterchef");
const masterchef = "0x24e5C28c060ae0836e6378FfDa3d0846fee0c56E";
const token = "0xbbdaA8700A7caAAf3b4aAc1fA6Fb5fF76Fc14C56";
module.exports = {
misrepresentedTokens: true,
...masterChefExports(masterchef, "bsc", token, false)
}
module.exports = masterChefExports(masterchef, "bsc", token)

View File

@@ -3,7 +3,4 @@ const { masterChefExports } = require("../helper/masterchef");
const masterchef = "0xD35a150Ec317a8a187C52FC1164b4D15C0851b84";
const token = "0x12C415aAFB1A521B42251e972BB7Ce6795F7669b";
module.exports = {
misrepresentedTokens: true,
...masterChefExports(masterchef, "bsc", token, false)
}
module.exports = masterChefExports(masterchef, "bsc", token)

View File

@@ -74,7 +74,7 @@ function transform(obj, file) {
function print() {
let res = data
if (data.type) data = [data]
if (data.name) data = [data]
if (Array.isArray(data)) {
res = {}
data