Skip to content

Commit

Permalink
repeat requests until completed
Browse files Browse the repository at this point in the history
  • Loading branch information
ewansheldon committed Sep 18, 2023
1 parent 375fa1e commit 12c6745
Showing 1 changed file with 75 additions and 27 deletions.
102 changes: 75 additions & 27 deletions src/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,29 @@ const getERC20DepositsForVaults = async (vaults, tokens, wallet, provider) => {
let deposits = [];
for (let i = 0; i < tokens.length; i++) {
const token = tokens[i];
console.log(token.addr);
const tokenContract = new ethers.Contract(token.addr, contracts.ERC20, wallet);
const filter = withBlockLimits(tokenContract.filters.Transfer(null, vaults));
// try {
const tokenDepositEvents = await tokenContract.queryFilter(filter, startBlock, endBlock);
for (let j = 0; j < tokenDepositEvents.length; j++) {
const tokenDepositEvent = tokenDepositEvents[j];
deposits.push({
type: 'deposit',
txHash: tokenDepositEvent.transactionHash.toLowerCase(),
blockNumber: tokenDepositEvent.blockNumber,
asset: ethers.utils.parseBytes32String(token.symbol),
vaultAddress: tokenDepositEvent.args.to.toLowerCase(),
amount: tokenDepositEvent.args.value.toString(),
amountDec: token.dec,
timestamp: (await provider.getBlock(tokenDepositEvent.blockNumber)).timestamp
})
let tokenDepositEvents;
while (!tokenDepositEvents) {
try {
tokenDepositEvents = await tokenContract.queryFilter(filter, startBlock, endBlock);
} catch(e) {
break;
}
console.log(deposits)
// } catch (e) {
// console.log(e)
// await getAcceptedERC20s(vaults, tokens, wallet, provider)
// }
}
for (let j = 0; j < tokenDepositEvents.length; j++) {
const tokenDepositEvent = tokenDepositEvents[j];
deposits.push({
type: 'deposit',
txHash: tokenDepositEvent.transactionHash.toLowerCase(),
blockNumber: tokenDepositEvent.blockNumber,
asset: ethers.utils.parseBytes32String(token.symbol),
vaultAddress: tokenDepositEvent.args.to.toLowerCase(),
amount: tokenDepositEvent.args.value.toString(),
amountDec: token.dec,
timestamp: (await provider.getBlock(tokenDepositEvent.blockNumber)).timestamp
})
}
}

return deposits;
Expand Down Expand Up @@ -133,7 +133,14 @@ const getWithdrawals = async (vaults, wallet, provider) => {
const vault = vaults[i]
const vaultContract = new ethers.Contract(vault, contracts.SmartVault, wallet);
const filter = withBlockLimits(vaultContract.filters.CollateralRemoved());
const vaultWithdrawals = await vaultContract.queryFilter(filter, startBlock, endBlock);
let vaultWithdrawals;
while (!vaultWithdrawals) {
try {
vaultWithdrawals = await vaultContract.queryFilter(filter, startBlock, endBlock);
} catch(e) {
break;
}
}
for (let j = 0; j < vaultWithdrawals.length; j++) {
const vaultWithdrawal = vaultWithdrawals[j];
withdrawals.push({
Expand All @@ -157,8 +164,14 @@ const getBorrows = async (vaults, wallet, provider) => {
const vault = vaults[i]
const vaultContract = new ethers.Contract(vault, contracts.SmartVault, wallet);
const filter = withBlockLimits(vaultContract.filters.EUROsMinted());

const vaultBorrows = await vaultContract.queryFilter(filter, startBlock, endBlock);
let vaultBorrows;
while (!vaultBorrows) {
try {
vaultBorrows = await vaultContract.queryFilter(filter, startBlock, endBlock);
} catch(e) {
break;
}
}
for (let j = 0; j < vaultBorrows.length; j++) {
const vaultBorrow = vaultBorrows[j];
borrows.push({
Expand All @@ -182,8 +195,14 @@ const getRepays = async (vaults, wallet, provider) => {
const vault = vaults[i]
const vaultContract = new ethers.Contract(vault, contracts.SmartVault, wallet);
const filter = withBlockLimits(vaultContract.filters.EUROsBurned());

const vaultRepays = await vaultContract.queryFilter(filter, startBlock, endBlock);
let vaultRepays;
while (!vaultRepays) {
try {
vaultRepays = await vaultContract.queryFilter(filter, startBlock, endBlock);
} catch(e) {
break;
}
}
for (let j = 0; j < vaultRepays.length; j++) {
const vaultRepay = vaultRepays[j];
repays.push({
Expand All @@ -205,7 +224,14 @@ const getLiquidations = async (smartVaultManagerContract, provider) => {
const liquidations = [];
const filter = withBlockLimits(smartVaultManagerContract.filters.VaultLiquidated());

const liquidationEvents = await smartVaultManagerContract.queryFilter(filter, startBlock, endBlock);
let liquidationEvents;
while (!liquidationEvents) {
try {
liquidationEvents = await smartVaultManagerContract.queryFilter(filter, startBlock, endBlock);
} catch(e) {
break;
}
}
for (let i = 0; i < liquidationEvents.length; i++) {
const event = liquidationEvents[i];
liquidations.push({
Expand Down Expand Up @@ -234,6 +260,27 @@ const getLiquidations = async (smartVaultManagerContract, provider) => {
return liquidations;
}

// const getCreations = async (smartVaultManagerContract, provider) => {
// const creations = [];
// const filter = withBlockLimits(smartVaultManagerContract.filters.VaultDeployed());

// const creationEvents = await smartVaultManagerContract.queryFilter(filter, startBlock, endBlock);
// for (let i = 0; i < creationEvents.length; i++) {
// const event = creationEvents[i];
// creations.push({
// type: 'liquidation',
// txHash: event.transactionHash.toLowerCase(),
// blockNumber: event.blockNumber,
// asset: 'n/a',
// vaultAddress: event.args.vaultAddress.toLowerCase(),
// amount: '0',
// amountDec: 0,
// timestamp: (await provider.getBlock(event.blockNumber)).timestamp
// });
// }
// return creations;
// }

const getTs = _ => {
return Math.floor(new Date() / 1000);
}
Expand Down Expand Up @@ -302,7 +349,8 @@ const indexVaultTransactions = async _ => {
getWithdrawals(vaults, wallet, provider),
getBorrows(vaults, wallet, provider),
getRepays(vaults, wallet, provider),
getLiquidations(smartVaultManagerContract, provider)
getLiquidations(smartVaultManagerContract, provider),
getCreations(smartVaultManagerContract, provider)
])).flat());
await saveToRedis(transactions);
const endTs = getTs();
Expand Down

0 comments on commit 12c6745

Please sign in to comment.