Skip to content

Commit

Permalink
resolve jobs restart issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ewansheldon committed Jan 20, 2025
1 parent f250b96 commit 141227f
Showing 1 changed file with 40 additions and 40 deletions.
80 changes: 40 additions & 40 deletions src/redemption.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,47 +94,47 @@ const saveRedemptionData = async data => {
}

const scheduleRedemptionData = async _ => {
schedule.scheduleJob('22,52 * * * *', async _ => {
console.log('indexing redemption data')
const { manager, wallet } = await getVaultManager();
const supply = Number((await getVaultSupply(wallet, manager)).toString());
let candidate = {
minted: BigNumber.from(0)
}
for (let tokenID = 1; tokenID <= supply; tokenID++) {
const { minted, vaultAddress, collateral, totalCollateralValue } = (await manager.connect(wallet).vaultData(tokenID)).status;
if (minted.gt(candidate.minted)) {
const simpleCollateralSorted = collateral.filter(c => c.token.addr.toLowerCase() !== PAXG).map(c => {
return {
address: c.token.addr.toLowerCase(),
value: c.collateralValue
}
}).sort(byValue)
// schedule.scheduleJob('22,52 * * * *', async _ => {
// console.log('indexing redemption data')
// const { manager, wallet } = await getVaultManager();
// const supply = Number((await getVaultSupply(wallet, manager)).toString());
// let candidate = {
// minted: BigNumber.from(0)
// }
// for (let tokenID = 1; tokenID <= supply; tokenID++) {
// const { minted, vaultAddress, collateral, totalCollateralValue } = (await manager.connect(wallet).vaultData(tokenID)).status;
// if (minted.gt(candidate.minted)) {
// const simpleCollateralSorted = collateral.filter(c => c.token.addr.toLowerCase() !== PAXG).map(c => {
// return {
// address: c.token.addr.toLowerCase(),
// value: c.collateralValue
// }
// }).sort(byValue)

const lockedCollateralSorted = tokenID > 107 ? (await getLockedCollateral(vaultAddress)).sort(byValue) : [];
const potentialCandidate = {
tokenID,
minted
};
if (lockedCollateralSorted.length > 0 && simpleCollateralSorted[0].value.lt(lockedCollateralSorted[0].value)) {
potentialCandidate.mainValue = lockedCollateralSorted[0].value;
potentialCandidate.hypervisor = lockedCollateralSorted[0].address;
potentialCandidate.collateral = optimalCollateralFor(potentialCandidate.hypervisor, simpleCollateralSorted);
} else {
potentialCandidate.mainValue = simpleCollateralSorted[0].value;
potentialCandidate.collateral = simpleCollateralSorted[0].address;
potentialCandidate.hypervisor = hypervisorOrAddress0For(potentialCandidate.collateral, lockedCollateralSorted);
}
// check that main part of redeemable value is at least 10% of whole vault value
// we don't want a case of a vault with $1 eth and $100000 paxg being used to redeem 1 USDs of its debt
if (potentialCandidate.mainValue.mul(10).div(totalCollateralValue).gt(0)) {
candidate = potentialCandidate;
}
}
}
if (candidate.tokenID) await saveRedemptionData(candidate);
console.log('indexed redemption data')
});
// const lockedCollateralSorted = tokenID > 107 ? (await getLockedCollateral(vaultAddress)).sort(byValue) : [];
// const potentialCandidate = {
// tokenID,
// minted
// };
// if (lockedCollateralSorted.length > 0 && simpleCollateralSorted[0].value.lt(lockedCollateralSorted[0].value)) {
// potentialCandidate.mainValue = lockedCollateralSorted[0].value;
// potentialCandidate.hypervisor = lockedCollateralSorted[0].address;
// potentialCandidate.collateral = optimalCollateralFor(potentialCandidate.hypervisor, simpleCollateralSorted);
// } else {
// potentialCandidate.mainValue = simpleCollateralSorted[0].value;
// potentialCandidate.collateral = simpleCollateralSorted[0].address;
// potentialCandidate.hypervisor = hypervisorOrAddress0For(potentialCandidate.collateral, lockedCollateralSorted);
// }
// // check that main part of redeemable value is at least 10% of whole vault value
// // we don't want a case of a vault with $1 eth and $100000 paxg being used to redeem 1 USDs of its debt
// if (potentialCandidate.mainValue.mul(10).div(totalCollateralValue).gt(0)) {
// candidate = potentialCandidate;
// }
// }
// }
// if (candidate.tokenID) await saveRedemptionData(candidate);
// console.log('indexed redemption data')
// });
};


Expand Down

0 comments on commit 141227f

Please sign in to comment.