From 9842f76f122aeca1d5388a3bc8839be97ce6e000 Mon Sep 17 00:00:00 2001 From: Wagalidoom Date: Tue, 10 Sep 2024 09:27:24 +0200 Subject: [PATCH] fix: cleaning osgno and deposit from files --- schema.graphql | 14 -------- src/constants.ts | 2 -- src/deposit.ts | 21 ------------ src/gno.ts | 25 +------------- src/helpers/osgnoVault.ts | 17 ---------- src/helpers/user.ts | 3 -- src/osgno.ts | 65 ------------------------------------ src/osgnoVault.ts | 53 ----------------------------- subgraph-gnosis-chain.yaml | 68 -------------------------------------- 9 files changed, 1 insertion(+), 267 deletions(-) delete mode 100644 src/deposit.ts delete mode 100644 src/helpers/osgnoVault.ts delete mode 100644 src/osgno.ts delete mode 100644 src/osgnoVault.ts diff --git a/schema.graphql b/schema.graphql index fbaca41..dcaa598 100644 --- a/schema.graphql +++ b/schema.graphql @@ -3,19 +3,5 @@ type User @entity { voteWeight: BigInt! gno: BigInt! lgno: BigInt! - deposit: BigInt! sgno: BigInt! - osgnoShare: BigInt! - osgnoAsset: BigInt! - -} - -type VaultState @entity { - id: ID! - profitAccrued: BigInt! - _totalShares: BigInt! - _totalAssets: BigInt! - lastUpdatedTimeStamp: BigInt! - avgRewardPerSecond: BigInt! - feePercent: Int! } diff --git a/src/constants.ts b/src/constants.ts index 6ee7c46..9a6b31f 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -24,8 +24,6 @@ export const ONE_BI = BigInt.fromI32(1); export const ZERO_BD = BigDecimal.fromString("0"); export const ONE_BD = BigDecimal.fromString("1"); export const BI_18 = BigInt.fromI32(18); -export const WAD = BigInt.fromString("1000000000000000000"); -export const OSGNO_MAX_FEE_PERCENT = BigInt.fromI32(10000); export function arrayRemove( array: string[], diff --git a/src/deposit.ts b/src/deposit.ts deleted file mode 100644 index 7ba6438..0000000 --- a/src/deposit.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { DepositEvent } from "../generated-gc/ds-deposit/SBCDepositContract"; -import { loadOrCreate as loadOrCreateUser } from "./helpers/user"; -import { ONE_GNO } from "./constants"; -import { Address, Bytes } from "@graphprotocol/graph-ts"; - -// HANDLE FOR DEPOSIT, NEED FURTHER TESTS -export function handleDeposit(event: DepositEvent): void { - // const withdrawalCredentials = event.params.withdrawal_credentials; - - // if (withdrawalCredentials.length != 32) { - // return; - // } - - // const addressBytes = withdrawalCredentials.subarray(12, 32); - // const userAddress = Address.fromBytes(Bytes.fromUint8Array(addressBytes)); - - // const entry = loadOrCreateUser(userAddress); - // entry.deposit = entry.deposit.plus(ONE_GNO); - // entry.voteWeight = entry.voteWeight.plus(ONE_GNO); - // entry.save(); -} diff --git a/src/gno.ts b/src/gno.ts index 6ce0d7f..2774a61 100644 --- a/src/gno.ts +++ b/src/gno.ts @@ -4,7 +4,7 @@ import { saveOrRemove as saveOrRemoveUser, } from "./helpers/user"; -import { ADDRESS_ZERO, DEPOSIT_ADDRESS, ZERO_BI } from "./constants"; +import { ADDRESS_ZERO } from "./constants"; export function handleTransfer(event: Transfer): void { const to = event.params.to; @@ -17,29 +17,6 @@ export function handleTransfer(event: Transfer): void { saveOrRemoveUser(userFrom); } - // HANDLE FOR DEPOSIT WITHDRAWAL CLAIM, NEED FURTHER TESTS - - // Decreasing deposit balance to prevent untracked withdrawal from deposit contract - // Temporary solution as this approach does not fully account for rewards generated by the validator - // if (from.toHexString() == DEPOSIT_ADDRESS.toHexString()) { - // const userTo = loadOrCreateUser(to); - - // if (userTo.deposit > ZERO_BI) { - // // To avoid a negative result that could throw an error - // if (userTo.deposit <= event.params.value) { - // userTo.voteWeight = userTo.voteWeight.minus(userTo.deposit); - // userTo.voteWeight = userTo.voteWeight.plus(event.params.value); - // userTo.deposit = ZERO_BI; - // } else { - // userTo.voteWeight = userTo.voteWeight.minus(event.params.value); - // userTo.deposit = userTo.deposit.minus(event.params.value); - // } - // userTo.gno = userTo.gno.plus(event.params.value); - // saveOrRemoveUser(userTo); - // } - // } - - if (to.toHexString() != ADDRESS_ZERO.toHexString()) { const userTo = loadOrCreateUser(to); userTo.gno = userTo.gno.plus(event.params.value); diff --git a/src/helpers/osgnoVault.ts b/src/helpers/osgnoVault.ts deleted file mode 100644 index aa434e5..0000000 --- a/src/helpers/osgnoVault.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { BigInt, } from "@graphprotocol/graph-ts"; -import { VaultState } from "../../generated/schema"; - -export function loadOrCreateVault(): VaultState { - let vaultState = VaultState.load("VAULT_STATE"); - if (vaultState == null) { - vaultState = new VaultState("VAULT_STATE"); - vaultState.profitAccrued = BigInt.fromI32(0); - vaultState._totalShares = BigInt.fromI32(0); - vaultState._totalAssets = BigInt.fromI32(0); - vaultState.lastUpdatedTimeStamp = BigInt.fromString("55776895775"); - vaultState.avgRewardPerSecond = BigInt.fromI32(0); - vaultState.feePercent = 0; - vaultState.save(); - } - return vaultState; -} diff --git a/src/helpers/user.ts b/src/helpers/user.ts index bfb0b4e..60c5c45 100644 --- a/src/helpers/user.ts +++ b/src/helpers/user.ts @@ -11,9 +11,6 @@ export function loadOrCreate(address: Address): User { user.gno = BigInt.fromI32(0); user.lgno = BigInt.fromI32(0); user.sgno = BigInt.fromI32(0); - user.osgnoShare = BigInt.fromI32(0); - user.osgnoAsset = BigInt.fromI32(0); - user.deposit = BigInt.fromI32(0); if (id != ADDRESS_ZERO.toHexString()) { user.save(); log.info("created user {}", [id]); diff --git a/src/osgno.ts b/src/osgno.ts deleted file mode 100644 index 21210d5..0000000 --- a/src/osgno.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { Transfer } from "../generated-gc/ds-osgno/ERC20"; -import { - loadOrCreate as loadOrCreateUser, - saveOrRemove as saveOrRemoveUser, -} from "./helpers/user"; - -import { ADDRESS_ZERO, OSGNO_MAX_FEE_PERCENT, WAD, ZERO_BI } from "./constants"; -import { VaultState } from "../generated/schema"; -import { BigInt } from "@graphprotocol/graph-ts"; -import { loadOrCreateVault } from "./helpers/osgnoVault"; - -// HANDLE FOR OSGNO, NEED FURTHER TESTS -export function handleTransfer(event: Transfer): void { - // const to = event.params.to; - // const from = event.params.from; - - // if (from.toHexString() != ADDRESS_ZERO.toHexString()) { - // const userFrom = loadOrCreateUser(from); - // userFrom.osgnoShare = userFrom.osgnoShare.minus(event.params.value); - // const newAsset = convertToAssets(userFrom.osgnoShare, event.block.timestamp); - // userFrom.voteWeight = userFrom.voteWeight.plus(userFrom.osgnoAsset); - // userFrom.osgnoAsset = newAsset; - // userFrom.voteWeight = userFrom.voteWeight.minus(userFrom.osgnoAsset); - // saveOrRemoveUser(userFrom); - // } - - // if (to.toHexString() != ADDRESS_ZERO.toHexString()) { - // const userTo = loadOrCreateUser(to); - // userTo.osgnoShare = userTo.osgnoShare.plus(event.params.value); - // const newAsset = convertToAssets(userTo.osgnoShare, event.block.timestamp); - // userTo.voteWeight = userTo.voteWeight.minus(userTo.osgnoAsset); - // userTo.osgnoAsset = newAsset; - // userTo.voteWeight = userTo.voteWeight.plus(userTo.osgnoAsset); - // userTo.save(); - // } -} - -function convertToAssets(shares: BigInt, timestamp: BigInt): BigInt { - const vaultState = loadOrCreateVault(); - const _totalShares = vaultState._totalShares; - return _convertToAssets(shares, _totalShares, totalAssets(timestamp, vaultState.lastUpdatedTimeStamp, vaultState.avgRewardPerSecond, vaultState._totalAssets, BigInt.fromI32(vaultState.feePercent))); -} - -function _convertToAssets(shares: BigInt, totalShares_: BigInt, totalAssets_: BigInt): BigInt { - return (totalShares_ == ZERO_BI) ? shares : shares.times(totalAssets_).div(totalShares_); -} - -function totalAssets(timestamp: BigInt, _lastUpdateTimestamp: BigInt, avgRewardPerSecond: BigInt, _totalAssets: BigInt, feePercent: BigInt): BigInt { - let profitAccrued = _unclaimedAssets(timestamp, _lastUpdateTimestamp, avgRewardPerSecond, _totalAssets); - if (profitAccrued == ZERO_BI) return _totalAssets; - - let treasuryAssets = profitAccrued.times(feePercent).div(OSGNO_MAX_FEE_PERCENT); - return _totalAssets.plus(profitAccrued).minus(treasuryAssets); -} - - -function _unclaimedAssets(timestamp: BigInt, _lastUpdateTimestamp: BigInt, avgRewardPerSecond: BigInt, _totalAssets: BigInt): BigInt { - // calculate time passed since the last update - // cannot realistically underflow - let timeElapsed = timestamp.minus(_lastUpdateTimestamp); - - if (timeElapsed == ZERO_BI) return ZERO_BI; - let reward = avgRewardPerSecond.times(_totalAssets).times(timeElapsed); - return reward.div(WAD); -} \ No newline at end of file diff --git a/src/osgnoVault.ts b/src/osgnoVault.ts deleted file mode 100644 index 02834b3..0000000 --- a/src/osgnoVault.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { AvgRewardPerSecondUpdated, Burn, FeePercentUpdated, Mint, StateUpdated } from "../generated-gc/ds-osgno-vault/OsTokenVaultController"; -import { - loadOrCreate as loadOrCreateUser, - saveOrRemove as saveOrRemoveUser, -} from "./helpers/user"; -import { loadOrCreateVault } from "./helpers/osgnoVault"; - -// HANDLE FOR OSGNO VAULT, NEED FURTHER TESTS -export function handleBurn(event: Burn): void { - // const owner = loadOrCreateUser(event.params.owner); - // owner.osgnoShare = owner.osgnoShare.minus(event.params.shares); - // owner.osgnoAsset = owner.osgnoAsset.minus(event.params.assets); - // owner.voteWeight = owner.voteWeight.minus(event.params.assets); - // saveOrRemoveUser(owner); -} - -export function handleMint(event: Mint): void { - // const receiver = loadOrCreateUser(event.params.receiver); - // receiver.osgnoShare = receiver.osgnoShare.plus(event.params.shares); - // receiver.osgnoAsset = receiver.osgnoAsset.plus(event.params.assets); - // receiver.voteWeight = receiver.voteWeight.plus(event.params.assets); - // saveOrRemoveUser(receiver); -} - -export function handleStateUpdated(event: StateUpdated): void { - // let vaultState = loadOrCreateVault(); - - // const profitAccrued = event.params.profitAccrued; - // const treasuryShares = event.params.treasuryShares; - // const treasuryAssets = event.params.treasuryAssets; - - // const newTotalAssets = vaultState._totalAssets.plus(profitAccrued); - - // vaultState.profitAccrued = profitAccrued; - // vaultState._totalAssets = newTotalAssets; - // vaultState._totalShares = vaultState._totalShares.plus(treasuryShares); - // vaultState.lastUpdatedTimeStamp = event.block.timestamp; - - // vaultState.save(); - } - - -export function handleAvgRewardPerSecondUpdated(event: AvgRewardPerSecondUpdated): void { - // let vaultState = loadOrCreateVault(); - // vaultState.avgRewardPerSecond = event.params.avgRewardPerSecond; - // vaultState.save(); -} - -export function handleFeePercentUpdated(event: FeePercentUpdated): void { - // let vaultState = loadOrCreateVault(); - // vaultState.feePercent = event.params.feePercent; - // vaultState.save(); -} diff --git a/subgraph-gnosis-chain.yaml b/subgraph-gnosis-chain.yaml index 84acb66..e1cb186 100644 --- a/subgraph-gnosis-chain.yaml +++ b/subgraph-gnosis-chain.yaml @@ -42,26 +42,6 @@ dataSources: - event: Transfer(indexed address,indexed address,uint256) handler: handleTransfer file: ./src/lgno.ts - - kind: ethereum - name: ds-deposit - network: gnosis - source: - address: "0x0B98057eA310F4d31F2a452B414647007d1645d9" - abi: SBCDepositContract - startBlock: 19469077 - mapping: - kind: ethereum/events - apiVersion: 0.0.6 - language: wasm/assemblyscript - entities: - - User - abis: - - name: SBCDepositContract - file: ./abis/SBCDepositContract.json - eventHandlers: - - event: DepositEvent(bytes,bytes,bytes,bytes,bytes) - handler: handleDeposit - file: ./src/deposit.ts - kind: ethereum name: ds-sgno network: gnosis @@ -82,54 +62,6 @@ dataSources: - event: Transfer(indexed address,indexed address,uint256) handler: handleTransfer file: ./src/sgno.ts - - kind: ethereum - name: ds-osgno - network: gnosis - source: - address: "0xF490c80aAE5f2616d3e3BDa2483E30C4CB21d1A0" - abi: ERC20 - startBlock: 34778547 - mapping: - kind: ethereum/events - apiVersion: 0.0.6 - language: wasm/assemblyscript - entities: - - User - abis: - - name: ERC20 - file: ./abis/ERC20.json - eventHandlers: - - event: Transfer(indexed address,indexed address,uint256) - handler: handleTransfer - file: ./src/osgno.ts - - kind: ethereum - name: ds-osgno-vault - network: gnosis - source: - address: "0x60B2053d7f2a0bBa70fe6CDd88FB47b579B9179a" - abi: OsTokenVaultController - startBlock: 34778543 - mapping: - kind: ethereum/events - apiVersion: 0.0.6 - language: wasm/assemblyscript - entities: - - User - abis: - - name: OsTokenVaultController - file: ./abis/OsTokenVaultController.json - eventHandlers: - - event: Burn(indexed address,indexed address,uint256,uint256) - handler: handleBurn - - event: Mint(indexed address,indexed address,uint256,uint256) - handler: handleMint - - event: StateUpdated(uint256,uint256,uint256) - handler: handleStateUpdated - - event: AvgRewardPerSecondUpdated(uint256) - handler: handleAvgRewardPerSecondUpdated - - event: FeePercentUpdated(uint16) - handler: handleFeePercentUpdated - file: ./src/osgnoVault.ts # Balancer # - kind: ethereum/contract