diff --git a/schema.graphql b/schema.graphql index a6bad6f..abbe282 100644 --- a/schema.graphql +++ b/schema.graphql @@ -13,9 +13,9 @@ type User @entity { reservations: [Reservation!]! @derivedFrom(field: "user") reservationDays: [UserReservationDay!]! @derivedFrom(field: "user") referrals: [Referral!]! @derivedFrom(field: "referrer") - reservedEth: BigInt! - reservedRealEth: BigInt! - referredEth: BigInt! + reservationEffectiveWei: BigInt! + reservationActualWei: BigInt! + referralActualWei: BigInt! reservationCount: BigInt! reservationDayCount: BigInt! referralCount: BigInt! @@ -28,8 +28,8 @@ type Reservation @entity { timestamp: BigInt! user: User! investmentDay: BigInt! - amount: BigInt! - realAmount: BigInt! + effectiveWei: BigInt! + actualWei: BigInt! referral: Referral } @@ -39,15 +39,15 @@ type Referral @entity { timestamp: BigInt! referrer: User! referee: User! - amount: BigInt! + actualWei: BigInt! } type UserReservationDay @entity { id: ID! user: User! investmentDay: BigInt! - totalAmount: BigInt! - totalRealAmount: BigInt! + effectiveWei: BigInt! + actualWei: BigInt! reservationCount: BigInt! } @@ -57,8 +57,8 @@ type GlobalReservationDay @entity { supply: BigInt minSupply: BigInt! maxSupply: BigInt! - totalAmount: BigInt! - totalRealAmount: BigInt! + effectiveWei: BigInt! + actualWei: BigInt! reservationCount: BigInt! userCount: BigInt! } @@ -67,8 +67,8 @@ type GlobalReservationDaySnapshot @entity { id: ID! timestamp: BigInt! investmentDay: BigInt! - totalAmount: BigInt! - totalRealAmount: BigInt! + effectiveWei: BigInt! + actualWei: BigInt! reservationCount: BigInt! userCount: BigInt! } @@ -82,6 +82,8 @@ type Global @entity { reservationCount: BigInt! stakeCount: BigInt! stakerCount: BigInt! + reservationEffectiveWei: BigInt! + reservationActualWei: BigInt! } type Stake @entity { diff --git a/src/mapping-liquidityTransformer.ts b/src/mapping-liquidityTransformer.ts index 71a283a..9dafec4 100644 --- a/src/mapping-liquidityTransformer.ts +++ b/src/mapping-liquidityTransformer.ts @@ -85,7 +85,8 @@ export function handleReferralAdded(event: ReferralAdded): void { global.userCount = global.userCount.plus(BigInt.fromI32(1)) } let reservedEffectiveEth = event.params.amount.times(BigInt.fromI32(11)).div(BigInt.fromI32(10)) - referee.reservedRealEth = referee.reservedRealEth.plus(event.params.amount).minus(reservedEffectiveEth) + referee.reservationActualWei = referee.reservationActualWei.plus(event.params.amount).minus(reservedEffectiveEth) + global.reservationActualWei = global.reservationActualWei.plus(event.params.amount).minus(reservedEffectiveEth) referee.save() let referralID = event.transaction.hash.toHexString() @@ -94,14 +95,14 @@ export function handleReferralAdded(event: ReferralAdded): void { referral.timestamp = transaction.timestamp referral.referrer = referrer.id referral.referee = referee.id - referral.amount = event.params.amount + referral.actualWei = event.params.amount referral.save() - let wasBelowCm = referrer.referredEth < CM_REFERRER_THRESHOLD; - referrer.referredEth = referrer.referredEth.plus(referral.amount) + let wasBelowCm = referrer.referralActualWei < CM_REFERRER_THRESHOLD; + referrer.referralActualWei = referrer.referralActualWei.plus(referral.actualWei) referrer.referralCount = referrer.referralCount.plus(BigInt.fromI32(1)) referrer.save() - if (wasBelowCm && referrer.referredEth >= CM_REFERRER_THRESHOLD) { + if (wasBelowCm && referrer.referralActualWei >= CM_REFERRER_THRESHOLD) { global.cmReferrerCount = global.cmReferrerCount.plus(BigInt.fromI32(1)) } global.save() @@ -120,27 +121,27 @@ export function handleReferralAdded(event: ReferralAdded): void { } let nRes = BigInt.fromI32(resList.length) - let dayRealAmount = referral.amount.div(nRes) - let remainder = referral.amount.mod(nRes) + let dayActualWei = referral.actualWei.div(nRes) + let remainder = referral.actualWei.mod(nRes) for (let i = 0; i < resList.length; i++) { - let realAmount = i === 0 - ? dayRealAmount.plus(remainder) - : dayRealAmount + let actualWei = i === 0 + ? dayActualWei.plus(remainder) + : dayActualWei let res = resList[i] - res.realAmount = realAmount + res.actualWei = actualWei res.save() let uResDay = UserReservationDay.load(res.user + "-" + res.investmentDay.toString()) - uResDay.totalRealAmount = uResDay.totalRealAmount.plus(realAmount).minus(res.amount) + uResDay.actualWei = uResDay.actualWei.plus(res.actualWei).minus(res.effectiveWei) uResDay.save() let gResDay = GlobalReservationDay.load(res.investmentDay.toString()) - gResDay.totalRealAmount = gResDay.totalRealAmount.plus(realAmount).minus(res.amount) + gResDay.actualWei = gResDay.actualWei.plus(res.actualWei).minus(res.effectiveWei) gResDay.save() let gResDaySnapshot = new GlobalReservationDaySnapshot(res.investmentDay.toString() + "-" + event.block.timestamp.toString()) - gResDaySnapshot.totalRealAmount = gResDay.totalRealAmount + gResDaySnapshot.actualWei = gResDay.actualWei gResDaySnapshot.save() } } @@ -160,7 +161,6 @@ export function handleWiseReservation(event: WiseReservation): void { if (user.reservationCount == BigInt.fromI32(0)) { global.reserverCount = global.reserverCount.plus(BigInt.fromI32(1)) } - global.save() let reservationID = event.transaction.hash.toHexString() + "-" + event.params.investmentDay.toString() let reservation = new Reservation(reservationID) @@ -168,14 +168,17 @@ export function handleWiseReservation(event: WiseReservation): void { reservation.timestamp = transaction.timestamp reservation.user = user.id reservation.investmentDay = event.params.investmentDay - reservation.amount = event.params.amount - reservation.realAmount = event.params.amount + reservation.effectiveWei = event.params.amount + reservation.actualWei = event.params.amount reservation.referral = null reservation.save() user.reservationCount = user.reservationCount.plus(BigInt.fromI32(1)) - user.reservedEth = user.reservedEth.plus(reservation.amount) - user.reservedRealEth = user.reservedRealEth.plus(reservation.amount) + user.reservationEffectiveWei = user.reservationEffectiveWei.plus(reservation.effectiveWei) + user.reservationActualWei = user.reservationActualWei.plus(reservation.effectiveWei) + global.reservationEffectiveWei = global.reservationEffectiveWei.plus(reservation.effectiveWei) + global.reservationActualWei = global.reservationActualWei.plus(reservation.effectiveWei) + global.save() let gResDayID = reservation.investmentDay.toString() let gResDay = GlobalReservationDay.load(gResDayID) @@ -184,21 +187,21 @@ export function handleWiseReservation(event: WiseReservation): void { gResDay.investmentDay = reservation.investmentDay gResDay.minSupply = getMinSupply(gResDay.investmentDay) gResDay.maxSupply = MAX_SUPPLY.minus(gResDay.minSupply) - gResDay.totalAmount = BigInt.fromI32(0) - gResDay.totalRealAmount = BigInt.fromI32(0) + gResDay.effectiveWei = BigInt.fromI32(0) + gResDay.actualWei = BigInt.fromI32(0) gResDay.reservationCount = BigInt.fromI32(0) gResDay.userCount = BigInt.fromI32(0) } - gResDay.totalAmount = gResDay.totalAmount.plus(reservation.amount) - gResDay.totalRealAmount = gResDay.totalRealAmount.plus(reservation.amount) + gResDay.effectiveWei = gResDay.effectiveWei.plus(reservation.effectiveWei) + gResDay.actualWei = gResDay.actualWei.plus(reservation.effectiveWei) gResDay.reservationCount = gResDay.reservationCount.plus(BigInt.fromI32(1)) let gResDaySnapshotID = reservation.investmentDay.toString() + "-" + event.block.timestamp.toString() let gResDaySnapshot = new GlobalReservationDaySnapshot(gResDaySnapshotID) gResDaySnapshot.timestamp = event.block.timestamp gResDaySnapshot.investmentDay = gResDay.investmentDay - gResDaySnapshot.totalAmount = gResDay.totalAmount - gResDaySnapshot.totalRealAmount = gResDay.totalRealAmount + gResDaySnapshot.effectiveWei = gResDay.effectiveWei + gResDaySnapshot.actualWei = gResDay.actualWei gResDaySnapshot.reservationCount = gResDay.reservationCount let uResDayID = userID + "-" + reservation.investmentDay.toString() @@ -207,14 +210,14 @@ export function handleWiseReservation(event: WiseReservation): void { uResDay = new UserReservationDay(uResDayID) uResDay.user = user.id uResDay.investmentDay = reservation.investmentDay - uResDay.totalAmount = BigInt.fromI32(0) - uResDay.totalRealAmount = BigInt.fromI32(0) + uResDay.effectiveWei = BigInt.fromI32(0) + uResDay.actualWei = BigInt.fromI32(0) uResDay.reservationCount = BigInt.fromI32(0) gResDay.userCount = gResDay.userCount.plus(BigInt.fromI32(1)) user.reservationDayCount = user.reservationDayCount.plus(BigInt.fromI32(1)) } - uResDay.totalAmount = uResDay.totalAmount.plus(reservation.amount) - uResDay.totalRealAmount = uResDay.totalRealAmount.plus(reservation.amount) + uResDay.effectiveWei = uResDay.effectiveWei.plus(reservation.effectiveWei) + uResDay.actualWei = uResDay.actualWei.plus(reservation.effectiveWei) uResDay.reservationCount = uResDay.reservationCount.plus(BigInt.fromI32(1)) uResDay.save() diff --git a/src/shared.ts b/src/shared.ts index ade30fa..6595a80 100644 --- a/src/shared.ts +++ b/src/shared.ts @@ -12,6 +12,8 @@ export function getOrCreateGlobal(): Global | null { global.reservationCount = BigInt.fromI32(0) global.stakeCount = BigInt.fromI32(0) global.stakerCount = BigInt.fromI32(0) + global.reservationEffectiveWei = BigInt.fromI32(0) + global.reservationActualWei = BigInt.fromI32(0) global.save() } return global @@ -19,9 +21,9 @@ export function getOrCreateGlobal(): Global | null { export function createUser(id: string): User | null { let user = new User(id) - user.reservedEth = BigInt.fromI32(0) - user.reservedRealEth = BigInt.fromI32(0) - user.referredEth = BigInt.fromI32(0) + user.reservationEffectiveWei = BigInt.fromI32(0) + user.reservationActualWei = BigInt.fromI32(0) + user.referralActualWei = BigInt.fromI32(0) user.reservationCount = BigInt.fromI32(0) user.reservationDayCount = BigInt.fromI32(0) user.referralCount = BigInt.fromI32(0)