Skip to content

Commit

Permalink
enhance getBlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
g1nt0ki committed Dec 6, 2022
1 parent c14da86 commit 3bf0358
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
7 changes: 4 additions & 3 deletions projects/arbor-finance/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ const { getLogs } = require('../helper/utils')

const bondFactory = '0x1533eb8c6cc510863b496d182596ab0e9e77a00c'

async function tvl(timestamp, block) {
async function tvl(timestamp, block, chainBlocks) {

const logs = await getLogs({
fromBlock: 15785514,
toBlock: block,
timestamp,
chainBlocks,
topic: 'BondCreated(address,string,string,address,uint256,address,address,uint256,uint256,uint256)',
interface: 'event BondCreated (address newBond, string name, string symbol, address owner, uint256 maturity, address paymentToken, address collateralToken, uint256 collateralTokenAmount, uint256 convertibleTokenAmount, uint256 bonds)',
eventInterface: 'event BondCreated (address newBond, string name, string symbol, address owner, uint256 maturity, address paymentToken, address collateralToken, uint256 collateralTokenAmount, uint256 convertibleTokenAmount, uint256 bonds)',
target: bondFactory,
})
const toa = logs.map(i => ([i.topics[3], i.newBond]))
Expand Down
13 changes: 9 additions & 4 deletions projects/helper/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,17 +328,22 @@ async function fetchItemList({ chain, block, lengthAbi, itemAbi, target }) {
return data
}

async function getLogs({ chain = 'ethereum', fromBlock, toBlock, topic, topics, keys = [], target, interface, }) {
async function getLogs({ chain = 'ethereum', fromBlock, toBlock, topic, topics, keys = [], target, eventInterface, chainBlocks, timestamp }) {
if (!toBlock)
toBlock = await http.getBlock(timestamp, chain, chainBlocks)

const { output: logs} = await sdk.api.util.getLogs({
chain, topics, target, topic, keys, fromBlock, toBlock,
});
if (!interface) return logs

let iface = new ethers.utils.Interface([interface])
const getAddress = i => `0x${i.substr(-40)}`.toLowerCase()
if (!eventInterface) return logs.map(log => log.topics.map(getAddress))

let iface = new ethers.utils.Interface([eventInterface])
return logs.map((log) => {
const res = {...iface.parseLog(log).args}
if (!res.topics )
res.topics = log.topics.map(j => `0x${j.substr(-40)}`.toLowerCase())
res.topics = log.topics.map(getAddress)
return res
})
}
Expand Down
6 changes: 3 additions & 3 deletions projects/metalswap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const { sumTokens2, nullAddress } = require('../helper/unwrapLPs');
const config = {
ethereum: {
toa: [
[nullAddress, '0xaAA50f60a256b74D1C71ED4AD739836b50059201','0x9494c9FfE0735832885269a10c910CDb227a7B0F'], // ETH pool
['0xdac17f958d2ee523a2206206994597c13d831ec7', '0x51bb873D5b68309cf645e84234bC290b7D991D2C','0x2535D0578562C88c1c875075A1085a4AD3117b20'], // USDT pool
['0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', '0xdCE224F9299CDd66e4D01D196d4cabce35a2F478','0x725fbd08e4c5d4b5978E48667d96D03F9B1C4d3A'], // WBTC pool
[nullAddress, '0xaAA50f60a256b74D1C71ED4AD739836b50059201'], // ETH pool
['0xdac17f958d2ee523a2206206994597c13d831ec7', '0x51bb873D5b68309cf645e84234bC290b7D991D2C'], // USDT pool
['0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', '0xdCE224F9299CDd66e4D01D196d4cabce35a2F478'], // WBTC pool
],
token: '0x3E5D9D8a63CC8a88748f229999CF59487e90721e',
staking: [
Expand Down

0 comments on commit 3bf0358

Please sign in to comment.