Skip to content

Commit 184e42a

Browse files
fix min max
1 parent 995b5cc commit 184e42a

File tree

1 file changed

+26
-40
lines changed

1 file changed

+26
-40
lines changed

src/mapping.ts

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,57 +16,32 @@ import {
1616
} from "../generated/schema"
1717

1818
let NORMAL_SUPPLY = BigInt.fromI32(5000000).times(BigInt.fromI32(10).pow(18)),
19+
MAX_SUPPLY = NORMAL_SUPPLY.plus(NORMAL_SUPPLY),
1920
MIN_SUPPLY_1 = BigInt.fromI32(4500000).times(BigInt.fromI32(10).pow(18)),
2021
MIN_SUPPLY_2 = BigInt.fromI32(4000000).times(BigInt.fromI32(10).pow(18)),
2122
MIN_SUPPLY_3 = BigInt.fromI32(3500000).times(BigInt.fromI32(10).pow(18)),
2223
MIN_SUPPLY_4 = BigInt.fromI32(3000000).times(BigInt.fromI32(10).pow(18)),
2324
MIN_SUPPLY_5 = BigInt.fromI32(2500000).times(BigInt.fromI32(10).pow(18)),
24-
MIN_SUPPLY_6 = BigInt.fromI32(1).times(BigInt.fromI32(10).pow(18)),
25-
MAX_SUPPLY_1 = BigInt.fromI32(5500000).times(BigInt.fromI32(10).pow(18)),
26-
MAX_SUPPLY_2 = BigInt.fromI32(6000000).times(BigInt.fromI32(10).pow(18)),
27-
MAX_SUPPLY_3 = BigInt.fromI32(6500000).times(BigInt.fromI32(10).pow(18)),
28-
MAX_SUPPLY_4 = BigInt.fromI32(7000000).times(BigInt.fromI32(10).pow(18)),
29-
MAX_SUPPLY_5 = BigInt.fromI32(7500000).times(BigInt.fromI32(10).pow(18)),
30-
MAX_SUPPLY_6 = BigInt.fromI32(9999999).times(BigInt.fromI32(10).pow(18))
31-
32-
for (let i = 1; i <= 50; i++) {
33-
let day = new GlobalReservationDay(i.toString())
34-
day.investmentDay = BigInt.fromI32(i)
35-
let min = NORMAL_SUPPLY, max = NORMAL_SUPPLY
36-
switch (i) {
25+
MIN_SUPPLY_6 = BigInt.fromI32(1).times(BigInt.fromI32(10).pow(18))
26+
27+
function getMinSupply (dayStr: string): BigInt {
28+
let dayNum = parseInt(dayStr)
29+
switch (dayNum) {
3730
case 8: case 10:
38-
min = MIN_SUPPLY_1
39-
max = MAX_SUPPLY_1
40-
break
31+
return MIN_SUPPLY_1
4132
case 14: case 16: case 17:
42-
min = MIN_SUPPLY_2
43-
max = MAX_SUPPLY_2
44-
break
33+
return MIN_SUPPLY_2
4534
case 21: case 23: case 25:
46-
min = MIN_SUPPLY_3
47-
max = MAX_SUPPLY_3
48-
break
35+
return MIN_SUPPLY_3
4936
case 29: case 31:
50-
min = MIN_SUPPLY_4
51-
max = MAX_SUPPLY_4
52-
break
37+
return MIN_SUPPLY_4
5338
case 35: case 36: case 38:
54-
min = MIN_SUPPLY_5
55-
max = MAX_SUPPLY_5
56-
break
39+
return MIN_SUPPLY_5
5740
case 12: case 19: case 26: case 33: case 40: case 42: case 44: case 46: case 47: case 48:
58-
min = MIN_SUPPLY_6
59-
max = MAX_SUPPLY_6
60-
break
41+
return MIN_SUPPLY_6
42+
default:
43+
return NORMAL_SUPPLY
6144
}
62-
day.supply = null
63-
day.minSupply = min
64-
day.maxSupply = max
65-
day.totalAmount = BigInt.fromI32(0)
66-
day.totalRealAmount = BigInt.fromI32(0)
67-
day.reservationCount = BigInt.fromI32(0)
68-
day.userCount = BigInt.fromI32(0)
69-
day.save()
7045
}
7146

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

176-
let gResDay = GlobalReservationDay.load(reservation.investmentDay.toString())
151+
let gResDayID = reservation.investmentDay.toString()
152+
let gResDay = GlobalReservationDay.load(gResDayID)
153+
if (gResDay == null) {
154+
gResDay = new GlobalReservationDay(gResDayID)
155+
gResDay.investmentDay = reservation.investmentDay
156+
gResDay.minSupply = getMinSupply(gResDay.investmentDay.toString())
157+
gResDay.maxSupply = MAX_SUPPLY.minus(gResDay.minSupply)
158+
gResDay.totalAmount = BigInt.fromI32(0)
159+
gResDay.totalRealAmount = BigInt.fromI32(0)
160+
gResDay.reservationCount = BigInt.fromI32(0)
161+
gResDay.userCount = BigInt.fromI32(0)
162+
}
177163
gResDay.totalAmount = gResDay.totalAmount.plus(reservation.amount)
178164
gResDay.totalRealAmount = gResDay.totalRealAmount.plus(reservation.amount)
179165
gResDay.reservationCount = gResDay.reservationCount.plus(BigInt.fromI32(1))

0 commit comments

Comments
 (0)