From fa20bc91bf8c9c2778337030f43798578d6ee26a Mon Sep 17 00:00:00 2001 From: Amin Latifi Date: Wed, 20 Sep 2023 19:13:26 +0330 Subject: [PATCH] Update token locks after optimism givpower upgrade --- src/utils/misc.ts | 33 +++++++++++++++++++++++++++--- src/utils/optimismGivPowerLocks.ts | 33 ++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 src/utils/optimismGivPowerLocks.ts diff --git a/src/utils/misc.ts b/src/utils/misc.ts index bdc2283..281d053 100644 --- a/src/utils/misc.ts +++ b/src/utils/misc.ts @@ -1,4 +1,4 @@ -import { Address, BigInt, ethereum } from '@graphprotocol/graph-ts'; +import { Address, BigInt, dataSource, ethereum } from '@graphprotocol/graph-ts'; import { GIVPower, TokenBalance, @@ -6,9 +6,11 @@ import { 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()); @@ -45,6 +47,29 @@ 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); @@ -52,13 +77,15 @@ export function updateGivPower(givPowerAddress: Address): void { 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( diff --git a/src/utils/optimismGivPowerLocks.ts b/src/utils/optimismGivPowerLocks.ts new file mode 100644 index 0000000..4da76cc --- /dev/null +++ b/src/utils/optimismGivPowerLocks.ts @@ -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', +];