Skip to content

Commit

Permalink
Merge pull request #65 from Giveth/feat/op_givpower_upgrade
Browse files Browse the repository at this point in the history
Update token locks after optimism givpower upgrade
  • Loading branch information
aminlatifi authored Sep 21, 2023
2 parents 0c56165 + fa20bc9 commit 3c0115c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
33 changes: 30 additions & 3 deletions src/utils/misc.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { Address, BigInt, ethereum } from '@graphprotocol/graph-ts';
import { Address, BigInt, dataSource, ethereum } from '@graphprotocol/graph-ts';
import {
GIVPower,
TokenBalance,
User,
Unipool,
UnipoolBalance,
BalanceChange,
TokenLock,
} from '../types/schema';
import { GIVPower as GIVPowerContract } from '../types/GIVPower/GIVPower';
import { UnipoolTokenDistributor as UnipoolContract } from '../types/Unipool/UnipoolTokenDistributor';
import { TO_UPDATE_GIV_POWER_LOCKS_IDS } from '../utils/optimismGivPowerLocks';

export function getUserEntity(userAddress: Address): User {
let user = User.load(userAddress.toHex());
Expand Down Expand Up @@ -45,20 +47,45 @@ export function getGIVPower(givPowerAddress: Address): GIVPower {
return givpower;
}

export function updateGivPowerLocks(givPowerAddress: Address): void {
const network = dataSource.network();
if (network == 'optimism') {
const givPowerContract = GIVPowerContract.bind(givPowerAddress);
const dateCall = givPowerContract.try_INITIAL_DATE();
const durationCall = givPowerContract.try_ROUND_DURATION();

const initialDate = dateCall.reverted ? BigInt.zero() : dateCall.value;
const roundDuration = durationCall.reverted
? 0
: durationCall.value.toI32();

for (let i = 0; i < TO_UPDATE_GIV_POWER_LOCKS_IDS.length; i += 1) {
const lock = TokenLock.load(TO_UPDATE_GIV_POWER_LOCKS_IDS[i]);
if (!lock) continue;
lock.unlockableAt = initialDate.plus(
BigInt.fromI64((lock.untilRound + 1) * roundDuration),
);
lock.save();
}
}
}

export function updateGivPower(givPowerAddress: Address): void {
const givPower = getGIVPower(givPowerAddress);

const givPowerContract = GIVPowerContract.bind(givPowerAddress);
const dateCall = givPowerContract.try_INITIAL_DATE();
const durationCall = givPowerContract.try_ROUND_DURATION();

let initialDate = dateCall.reverted ? BigInt.zero() : dateCall.value;
let roundDuration = durationCall.reverted ? 0 : durationCall.value.toI32();
const initialDate = dateCall.reverted ? BigInt.zero() : dateCall.value;
const roundDuration = durationCall.reverted ? 0 : durationCall.value.toI32();

givPower.initialDate = initialDate;
givPower.roundDuration = roundDuration;

givPower.save();

updateGivPowerLocks(givPowerAddress);
}

export function getTokenLockId(
Expand Down
33 changes: 33 additions & 0 deletions src/utils/optimismGivPowerLocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export const TO_UPDATE_GIV_POWER_LOCKS_IDS = [
'0x0f46540678c7e6d2ef983b382cc07fa815ab148c-26-58',
'0x10a84b835c5df26f2a380b3e00bcc84a66cd2d34-6-39',
'0x1b3fd358c66974572cd7c77b5be7759c67c178b1-26-59',
'0x1ccd9f598a51ce30a912c0b1713dec9478762deb-26-58',
'0x2a8fe25896fcce82c49c2db923abfa4198ad3394-26-58',
'0x2a8fe25896fcce82c49c2db923abfa4198ad3394-26-59',
'0x2a8fe25896fcce82c49c2db923abfa4198ad3394-3-35',
'0x302e2a0d4291ac14aa1160504ca45a0a1f2e7a5c-26-58',
'0x33878e070db7f70d2953fe0278cd32adf8104572-26-58',
'0x33878e070db7f70d2953fe0278cd32adf8104572-26-59',
'0x5a7c338fce14bef491590e13d03a221af1be80ab-7-40',
'0x5ffd23b1b0350debb17a2cb668929ac5f76d0e18-6-38',
'0x6433a7994681f87e717dc761490be9553713546f-26-58',
'0x7587cfbd20e5a970209526b4d1f69dbaae8bed37-26-58',
'0x7587cfbd20e5a970209526b4d1f69dbaae8bed37-26-59',
'0x826976d7c600d45fb8287ca1d7c76fc8eb732030-5-37',
'0x8e4bdd156e4dd802dd919f4fd2645681ce99a538-6-38',
'0xa4d506434445bb7303ea34a07bc38484cdc64a95-1-33',
'0xa64f2228ccec96076c82abb903021c33859082f8-26-58',
'0xa64f2228ccec96076c82abb903021c33859082f8-26-59',
'0xad62d4fdd2d071536dbcb72202f1ef51b17ece30-4-37',
'0xad7575aefd4d64520c3269fd24eae1b0e13dbe7b-26-58',
'0xc46c67bb7e84490d7ebdd0b8ecdaca68cf3823f4-26-58',
'0xcd192b61a8dd586a97592555c1f5709e032f2505-1-33',
'0xcd192b61a8dd586a97592555c1f5709e032f2505-3-35',
'0xcd192b61a8dd586a97592555c1f5709e032f2505-3-36',
'0xcd192b61a8dd586a97592555c1f5709e032f2505-4-37',
'0xe564ef4523cb7931bafd6ecb36814b2b3691e1a4-26-59',
'0xed8db37778804a913670d9367aaf4f043aad938b-26-59',
'0xfe229fc3c1982d8eaaf12ada33e57ee2f99efaf4-26-58',
'0xff75e131c711e4310c045317779d39b3b4f718c4-26-58',
];

0 comments on commit 3c0115c

Please sign in to comment.