There is could be a case when Delegation with given ID is in DB, and then there are multiple ClearDelegate followed by SetDelegate with the same ID.
let isExistOnDB = await ctx.store.get(Delegation, id);
// let isExistOnMap = delegations.get(id);
if (isExistOnDB) {
clearDelegations.set(id, id);
...
await ctx.store.upsert([...delegations.values()]);
await ctx.store.upsert([...sigs.values()]);
if (clearDelegations.size != 0) {
await ctx.store.remove(Delegation, [...clearDelegations.values()]);
}
});
There is could be a case when Delegation with given ID is in DB, and then there are multiple ClearDelegate followed by SetDelegate with the same ID.
Example:
https://etherscan.io/txs?a=0xef8305e140ac520225daf050e2f71d5fbcc543e7&p=9
(around tx https://etherscan.io/tx/0xcc8525f8b227674e5216ce2fd7c4fc3f63c7cd62b0f3912e9c09054a6e358978#eventlog)
In such case Delegation will be deleted by code below: