From 3309fa65453015245c1b5df849715d886024e994 Mon Sep 17 00:00:00 2001 From: Andrii Ublinskykh Date: Thu, 20 Feb 2025 12:15:34 +0200 Subject: [PATCH 1/5] commented console logs --- src/ciphex-presale.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/ciphex-presale.ts b/src/ciphex-presale.ts index a115da1..26f850a 100644 --- a/src/ciphex-presale.ts +++ b/src/ciphex-presale.ts @@ -3,6 +3,7 @@ import { bigDecimal, BigDecimal, BigInt, + log, } from "@graphprotocol/graph-ts"; import { Bought as BoughtEvent, @@ -24,8 +25,6 @@ import { TotalContributions, UserContribution, } from "../generated/schema"; -import {} from "./ranks"; -import { log } from "@graphprotocol/graph-ts"; import { calculateReferralRewards, tokenDecimals, @@ -75,7 +74,7 @@ export function handleBought(event: BoughtEvent): void { ); user.save(); - log.info("Before handling ReferralContribution:{}", []); + // log.info("Before handling ReferralContribution:{}", []); // handling ReferralContribution if (event.params.referral.notEqual(zeroAddress)) { const referralId = event.params.referral; @@ -87,20 +86,20 @@ export function handleBought(event: BoughtEvent): void { referral.totalUsdRewards = BigInt.fromI32(0); referral.totalCiphexRewards = BigInt.fromI32(0); } - log.info("Usercpmtribution usd: {}", [usd.toString()]); - log.info("Usercpmtribution cpx: {}", [entity.ciphexAmount.toString()]); + // log.info("Usercpmtribution usd: {}", [usd.toString()]); + // log.info("Usercpmtribution cpx: {}", [entity.ciphexAmount.toString()]); referral.totalUsdContribution = referral.totalUsdContribution.plus(usd); referral.totalCiphexContribution = referral.totalCiphexContribution.plus( entity.ciphexAmount ); - log.info("Before calculateReferralRewards execution {}", []); + // log.info("Before calculateReferralRewards execution {}", []); // handling Referral rewards let rewRes: AffiliateResult = calculateReferralRewards( referral.totalUsdContribution, referral.totalCiphexContribution ); - log.info("calculateReferralRewards {}", [rewRes.getResString()]); + // log.info("calculateReferralRewards {}", [rewRes.getResString()]); let usdRewDelta: BigInt = BigInt.fromString(rewRes.usdt.toString()) .times(usdDecimals) .minus(referral.totalUsdRewards); @@ -123,7 +122,7 @@ export function handleBought(event: BoughtEvent): void { referral.save(); totalAffiliateRewards.save(); } - log.info("Before handling TotalContributions", []); + // log.info("Before handling TotalContributions", []); // handling TotalContributions let totalContributions = TotalContributions.load(zeroAddress); From 4c43561af940bb2dcef488511084723148b7e4bc Mon Sep 17 00:00:00 2001 From: Andrii Ublinskykh Date: Fri, 21 Feb 2025 00:16:43 +0200 Subject: [PATCH 2/5] deployed v0.0.6.13 --- src/affiliateRewards.ts | 12 ++++++------ src/ranks.ts | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/affiliateRewards.ts b/src/affiliateRewards.ts index c04d792..c2963aa 100644 --- a/src/affiliateRewards.ts +++ b/src/affiliateRewards.ts @@ -18,9 +18,9 @@ export class AffiliateResult { this.usdt = usdt; this.cpx = cpx; } - getResString(): string { - return `usdt = ${this.usdt.toString()}; cpx = ${this.cpx.toString()}`; - } + // getResString(): string { + // return `usdt = ${this.usdt.toString()}; cpx = ${this.cpx.toString()}`; + // } } export function calculateReferralRewards( usdcAmount: BigInt, @@ -35,12 +35,12 @@ export function calculateReferralRewards( let total: BigDecimal = new BigDecimal(usdcAmount.div(usdDecimals)); let usdRewards: BigDecimal = BigDecimal.fromString("0"); let percentages: Percentage[] = []; - log.info(`getRanksLengh: {}`, [getRanksLengh().toString()]); - for (let i = getRanksLengh() - 1; i >= 0; i++) { + // log.info(`getRanksLengh: {}`, [getRanksLengh().toString()]); + for (let i = getRanksLengh() - 1; i >= 0; i--) { if (total == zeroBd) break; const rank: Rank | null = getRank(i); if (!rank) break; - log.info(`getRank: data {}, index {}`, [rank.getResString(), i.toString()]); + // log.info(`getRank: data {}, index {}`, [rank.getResString(), i.toString()]); // Calculate the maximum amount that can be attributed to this rank let bracketMax: BigDecimal; // same as const bracketMax = Math.min(rank.max - rank.min + 1, total); diff --git a/src/ranks.ts b/src/ranks.ts index 7391521..4527ae9 100644 --- a/src/ranks.ts +++ b/src/ranks.ts @@ -9,9 +9,9 @@ export class Rank { this.max = BigDecimal.fromString(max); this.rate = BigDecimal.fromString(rate); } - getResString(): string { - return `min = ${this.min.toString()}; max = ${this.max.toString()}; rate = ${this.rate.toString()}`; - } + // getResString(): string { + // return `min = ${this.min.toString()}; max = ${this.max.toString()}; rate = ${this.rate.toString()}`; + // } } export let ranks: Rank[] = []; From 0606319b5ec8fabc2c58165d34656030f483a174 Mon Sep 17 00:00:00 2001 From: Andrii Ublinskykh Date: Fri, 21 Feb 2025 00:48:35 +0200 Subject: [PATCH 3/5] added handler for 0 rank lengh, start use truncate function --- src/affiliateRewards.ts | 8 ++++---- src/ciphex-presale.ts | 22 ++++++++++++---------- src/ranks.ts | 3 --- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/affiliateRewards.ts b/src/affiliateRewards.ts index c2963aa..2314e57 100644 --- a/src/affiliateRewards.ts +++ b/src/affiliateRewards.ts @@ -1,6 +1,5 @@ import { BigDecimal, BigInt } from "@graphprotocol/graph-ts"; import { getRanksLengh, getRank, Rank } from "./ranks"; -import { log } from "@graphprotocol/graph-ts"; export const usdDecimals = new BigInt(1000000); export const tokenDecimals = new BigInt(1 * 10 ** 18); export class Percentage { @@ -35,12 +34,13 @@ export function calculateReferralRewards( let total: BigDecimal = new BigDecimal(usdcAmount.div(usdDecimals)); let usdRewards: BigDecimal = BigDecimal.fromString("0"); let percentages: Percentage[] = []; - // log.info(`getRanksLengh: {}`, [getRanksLengh().toString()]); - for (let i = getRanksLengh() - 1; i >= 0; i--) { + let ranksLength = getRanksLengh(); + if (ranksLength == 0) + return new AffiliateResult(BigDecimal.zero(), BigDecimal.zero()); + for (let i = ranksLength - 1; i >= 0; i--) { if (total == zeroBd) break; const rank: Rank | null = getRank(i); if (!rank) break; - // log.info(`getRank: data {}, index {}`, [rank.getResString(), i.toString()]); // Calculate the maximum amount that can be attributed to this rank let bracketMax: BigDecimal; // same as const bracketMax = Math.min(rank.max - rank.min + 1, total); diff --git a/src/ciphex-presale.ts b/src/ciphex-presale.ts index 26f850a..0e36904 100644 --- a/src/ciphex-presale.ts +++ b/src/ciphex-presale.ts @@ -74,7 +74,6 @@ export function handleBought(event: BoughtEvent): void { ); user.save(); - // log.info("Before handling ReferralContribution:{}", []); // handling ReferralContribution if (event.params.referral.notEqual(zeroAddress)) { const referralId = event.params.referral; @@ -86,29 +85,33 @@ export function handleBought(event: BoughtEvent): void { referral.totalUsdRewards = BigInt.fromI32(0); referral.totalCiphexRewards = BigInt.fromI32(0); } - // log.info("Usercpmtribution usd: {}", [usd.toString()]); - // log.info("Usercpmtribution cpx: {}", [entity.ciphexAmount.toString()]); referral.totalUsdContribution = referral.totalUsdContribution.plus(usd); referral.totalCiphexContribution = referral.totalCiphexContribution.plus( entity.ciphexAmount ); - // log.info("Before calculateReferralRewards execution {}", []); // handling Referral rewards let rewRes: AffiliateResult = calculateReferralRewards( referral.totalUsdContribution, referral.totalCiphexContribution ); - // log.info("calculateReferralRewards {}", [rewRes.getResString()]); - let usdRewDelta: BigInt = BigInt.fromString(rewRes.usdt.toString()) + let usdRewDelta: BigInt = BigInt.fromString( + rewRes.usdt.truncate(0).toString() + ) .times(usdDecimals) .minus(referral.totalUsdRewards); - let cpxRewDelta: BigInt = BigInt.fromString(rewRes.cpx.toString()) + let cpxRewDelta: BigInt = BigInt.fromString( + rewRes.cpx.truncate(0).toString() + ) .times(tokenDecimals) .minus(referral.totalCiphexRewards); - referral.totalUsdRewards = BigInt.fromString(rewRes.usdt.toString()); - referral.totalCiphexRewards = BigInt.fromString(rewRes.cpx.toString()); + referral.totalUsdRewards = BigInt.fromString( + rewRes.usdt.truncate(0).toString() + ); + referral.totalCiphexRewards = BigInt.fromString( + rewRes.cpx.truncate(0).toString() + ); let totalAffiliateRewards = new TotalAffiliateRewards(zeroAddress); if (!totalAffiliateRewards) { totalAffiliateRewards = new TotalAffiliateRewards(zeroAddress); @@ -122,7 +125,6 @@ export function handleBought(event: BoughtEvent): void { referral.save(); totalAffiliateRewards.save(); } - // log.info("Before handling TotalContributions", []); // handling TotalContributions let totalContributions = TotalContributions.load(zeroAddress); diff --git a/src/ranks.ts b/src/ranks.ts index 4527ae9..215284f 100644 --- a/src/ranks.ts +++ b/src/ranks.ts @@ -9,9 +9,6 @@ export class Rank { this.max = BigDecimal.fromString(max); this.rate = BigDecimal.fromString(rate); } - // getResString(): string { - // return `min = ${this.min.toString()}; max = ${this.max.toString()}; rate = ${this.rate.toString()}`; - // } } export let ranks: Rank[] = []; From 0157b79141888f0267a5d7d3ca8650fe1e27fa04 Mon Sep 17 00:00:00 2001 From: Andrii Ublinskykh Date: Fri, 21 Feb 2025 00:55:45 +0200 Subject: [PATCH 4/5] added logs v0.0.6.15 --- src/ciphex-presale.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ciphex-presale.ts b/src/ciphex-presale.ts index 0e36904..2aea9a2 100644 --- a/src/ciphex-presale.ts +++ b/src/ciphex-presale.ts @@ -74,6 +74,7 @@ export function handleBought(event: BoughtEvent): void { ); user.save(); + log.info("Before referral check", []); // handling ReferralContribution if (event.params.referral.notEqual(zeroAddress)) { const referralId = event.params.referral; @@ -90,11 +91,13 @@ export function handleBought(event: BoughtEvent): void { entity.ciphexAmount ); + log.info("Before calculateReferralRewards", []); // handling Referral rewards let rewRes: AffiliateResult = calculateReferralRewards( referral.totalUsdContribution, referral.totalCiphexContribution ); + log.info("After calculateReferralRewards", []); let usdRewDelta: BigInt = BigInt.fromString( rewRes.usdt.truncate(0).toString() ) @@ -105,13 +108,14 @@ export function handleBought(event: BoughtEvent): void { ) .times(tokenDecimals) .minus(referral.totalCiphexRewards); - + log.info("After converting res from BigDecimal to BigInt", []); referral.totalUsdRewards = BigInt.fromString( rewRes.usdt.truncate(0).toString() ); referral.totalCiphexRewards = BigInt.fromString( rewRes.cpx.truncate(0).toString() ); + log.info("After updating total rewards", []); let totalAffiliateRewards = new TotalAffiliateRewards(zeroAddress); if (!totalAffiliateRewards) { totalAffiliateRewards = new TotalAffiliateRewards(zeroAddress); From 264178cca266c2079defcb830efad635a0615960 Mon Sep 17 00:00:00 2001 From: Andrii Ublinskykh Date: Fri, 21 Feb 2025 01:06:15 +0200 Subject: [PATCH 5/5] updated rank array v0.0.3 for ciphexSubgraphBase3 --- src/ciphex-presale.ts | 12 ++++++------ src/ranks.ts | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/ciphex-presale.ts b/src/ciphex-presale.ts index 2aea9a2..9f643a1 100644 --- a/src/ciphex-presale.ts +++ b/src/ciphex-presale.ts @@ -91,7 +91,7 @@ export function handleBought(event: BoughtEvent): void { entity.ciphexAmount ); - log.info("Before calculateReferralRewards", []); + /* log.info("Before calculateReferralRewards", []); // handling Referral rewards let rewRes: AffiliateResult = calculateReferralRewards( referral.totalUsdContribution, @@ -114,7 +114,7 @@ export function handleBought(event: BoughtEvent): void { ); referral.totalCiphexRewards = BigInt.fromString( rewRes.cpx.truncate(0).toString() - ); + ); */ log.info("After updating total rewards", []); let totalAffiliateRewards = new TotalAffiliateRewards(zeroAddress); if (!totalAffiliateRewards) { @@ -122,10 +122,10 @@ export function handleBought(event: BoughtEvent): void { totalAffiliateRewards.totalUsdRewards = BigInt.fromI32(0); totalAffiliateRewards.totalCiphexRewards = BigInt.fromI32(0); } - totalAffiliateRewards.totalUsdRewards = - totalAffiliateRewards.totalUsdRewards.plus(usdRewDelta); - totalAffiliateRewards.totalCiphexRewards = - totalAffiliateRewards.totalCiphexRewards.plus(cpxRewDelta); + // totalAffiliateRewards.totalUsdRewards = + // totalAffiliateRewards.totalUsdRewards.plus(usdRewDelta); + // totalAffiliateRewards.totalCiphexRewards = + // totalAffiliateRewards.totalCiphexRewards.plus(cpxRewDelta); referral.save(); totalAffiliateRewards.save(); } diff --git a/src/ranks.ts b/src/ranks.ts index 215284f..fb055bf 100644 --- a/src/ranks.ts +++ b/src/ranks.ts @@ -13,25 +13,25 @@ export class Rank { export let ranks: Rank[] = []; // rank 1, zero means Infinity -ranks.push(new Rank("650000", "0", "0.3")); +ranks.push(new Rank("650000", "0", "300")); // rank 2 -ranks.push(new Rank("490000", "650000", "0.26")); +ranks.push(new Rank("490000", "650000", "260")); // rank 3 -ranks.push(new Rank("350000", "490000", "0.24")); +ranks.push(new Rank("350000", "490000", "240")); // rank 4 -ranks.push(new Rank("250000", "350000", "0.22")); +ranks.push(new Rank("250000", "350000", "220")); // rank 5 -ranks.push(new Rank("175000", "250000", "0.2")); +ranks.push(new Rank("175000", "250000", "200")); // rank 6 -ranks.push(new Rank("115000", "175000", "0.18")); +ranks.push(new Rank("115000", "175000", "180")); // rank 7 -ranks.push(new Rank("75000", "115000", "0.16")); +ranks.push(new Rank("75000", "115000", "160")); // rank 8 -ranks.push(new Rank("45000", "75000", "0.14")); +ranks.push(new Rank("45000", "75000", "140")); // rank 9 -ranks.push(new Rank("24000", "45000", "0.12")); +ranks.push(new Rank("24000", "45000", "120")); // rank 10 -ranks.push(new Rank("0", "24000", "0.1")); +ranks.push(new Rank("0", "24000", "100")); export function getRanksLengh(): i32 { return ranks.length;