Skip to content

Commit

Permalink
fix min max
Browse files Browse the repository at this point in the history
  • Loading branch information
coffee-converter committed Dec 5, 2020
1 parent 995b5cc commit 184e42a
Showing 1 changed file with 26 additions and 40 deletions.
66 changes: 26 additions & 40 deletions src/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,57 +16,32 @@ import {
} from "../generated/schema"

let NORMAL_SUPPLY = BigInt.fromI32(5000000).times(BigInt.fromI32(10).pow(18)),
MAX_SUPPLY = NORMAL_SUPPLY.plus(NORMAL_SUPPLY),
MIN_SUPPLY_1 = BigInt.fromI32(4500000).times(BigInt.fromI32(10).pow(18)),
MIN_SUPPLY_2 = BigInt.fromI32(4000000).times(BigInt.fromI32(10).pow(18)),
MIN_SUPPLY_3 = BigInt.fromI32(3500000).times(BigInt.fromI32(10).pow(18)),
MIN_SUPPLY_4 = BigInt.fromI32(3000000).times(BigInt.fromI32(10).pow(18)),
MIN_SUPPLY_5 = BigInt.fromI32(2500000).times(BigInt.fromI32(10).pow(18)),
MIN_SUPPLY_6 = BigInt.fromI32(1).times(BigInt.fromI32(10).pow(18)),
MAX_SUPPLY_1 = BigInt.fromI32(5500000).times(BigInt.fromI32(10).pow(18)),
MAX_SUPPLY_2 = BigInt.fromI32(6000000).times(BigInt.fromI32(10).pow(18)),
MAX_SUPPLY_3 = BigInt.fromI32(6500000).times(BigInt.fromI32(10).pow(18)),
MAX_SUPPLY_4 = BigInt.fromI32(7000000).times(BigInt.fromI32(10).pow(18)),
MAX_SUPPLY_5 = BigInt.fromI32(7500000).times(BigInt.fromI32(10).pow(18)),
MAX_SUPPLY_6 = BigInt.fromI32(9999999).times(BigInt.fromI32(10).pow(18))

for (let i = 1; i <= 50; i++) {
let day = new GlobalReservationDay(i.toString())
day.investmentDay = BigInt.fromI32(i)
let min = NORMAL_SUPPLY, max = NORMAL_SUPPLY
switch (i) {
MIN_SUPPLY_6 = BigInt.fromI32(1).times(BigInt.fromI32(10).pow(18))

function getMinSupply (dayStr: string): BigInt {
let dayNum = parseInt(dayStr)
switch (dayNum) {
case 8: case 10:
min = MIN_SUPPLY_1
max = MAX_SUPPLY_1
break
return MIN_SUPPLY_1
case 14: case 16: case 17:
min = MIN_SUPPLY_2
max = MAX_SUPPLY_2
break
return MIN_SUPPLY_2
case 21: case 23: case 25:
min = MIN_SUPPLY_3
max = MAX_SUPPLY_3
break
return MIN_SUPPLY_3
case 29: case 31:
min = MIN_SUPPLY_4
max = MAX_SUPPLY_4
break
return MIN_SUPPLY_4
case 35: case 36: case 38:
min = MIN_SUPPLY_5
max = MAX_SUPPLY_5
break
return MIN_SUPPLY_5
case 12: case 19: case 26: case 33: case 40: case 42: case 44: case 46: case 47: case 48:
min = MIN_SUPPLY_6
max = MAX_SUPPLY_6
break
return MIN_SUPPLY_6
default:
return NORMAL_SUPPLY
}
day.supply = null
day.minSupply = min
day.maxSupply = max
day.totalAmount = BigInt.fromI32(0)
day.totalRealAmount = BigInt.fromI32(0)
day.reservationCount = BigInt.fromI32(0)
day.userCount = BigInt.fromI32(0)
day.save()
}

function getOrCreateUser(id: string): User | null {
Expand Down Expand Up @@ -173,7 +148,18 @@ export function handleWiseReservation(event: WiseReservation): void {
user.reservedEth = user.reservedEth.plus(reservation.amount)
user.save()

let gResDay = GlobalReservationDay.load(reservation.investmentDay.toString())
let gResDayID = reservation.investmentDay.toString()
let gResDay = GlobalReservationDay.load(gResDayID)
if (gResDay == null) {
gResDay = new GlobalReservationDay(gResDayID)
gResDay.investmentDay = reservation.investmentDay
gResDay.minSupply = getMinSupply(gResDay.investmentDay.toString())
gResDay.maxSupply = MAX_SUPPLY.minus(gResDay.minSupply)
gResDay.totalAmount = BigInt.fromI32(0)
gResDay.totalRealAmount = 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.reservationCount = gResDay.reservationCount.plus(BigInt.fromI32(1))
Expand Down

0 comments on commit 184e42a

Please sign in to comment.