Skip to content
Open
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
12 changes: 7 additions & 5 deletions src/totle.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async function fetchTotle (swapFuncParams: SwapFuncParams) {
const { contracts } = await fetch('https://api.totle.com/contracts').then((res) => res.json())
const primaries = contracts.filter(({ type }) => type === 1)

for (const { address: primaryAddress } of primaries) {
await Promise.all(primaries.map(async ({ address: primaryAddress }) => {
const primary = new web3.eth.Contract(PRIMARY_ABI, primaryAddress)
const swapCollectionEvents = await primary.getPastEvents('LogSwapCollection', {
filter: { partnerContract: partnerContractAddress },
Expand All @@ -61,7 +61,7 @@ async function fetchTotle (swapFuncParams: SwapFuncParams) {
fromBlock: offset,
toBlock: 'latest'
})
for (const swapEvent of swapEvents) {
await Promise.all(swapEvents.map(async (swapEvent) => {
const { sourceAsset, destinationAsset, sourceAmount, destinationAmount } = swapEvent.returnValues

const {timestamp} = await web3.eth.getBlock(swapEvent.blockNumber)
Expand All @@ -72,7 +72,7 @@ async function fetchTotle (swapFuncParams: SwapFuncParams) {
const destinationToken = tokens.find((t) => t.address.toLowerCase() === destinationAsset.toLowerCase())

// Cannot find token
if (!sourceToken || !destinationToken) continue
if (!sourceToken || !destinationToken) return
const ssTx: StandardTx = {
status: 'complete',
inputTXID: receipt.transactionHash,
Expand All @@ -86,16 +86,18 @@ async function fetchTotle (swapFuncParams: SwapFuncParams) {
}
// console.log(ssTx)
ssFormatTxs.push(ssTx)
}
}))
}

// console.log(ssFormatTxs.length)
// console.log('done....')
}
}))
} catch (err) {
console.log(err)
}

ssFormatTxs.sort((tx1, tx2) => tx1.timestamp - tx2.timestamp)

diskCache.offset = currentBlockNumber
const out = {
diskCache,
Expand Down