From 43e9bed1095df271f03cc20d850fd3ad7468f454 Mon Sep 17 00:00:00 2001 From: Eugene P Date: Fri, 16 Feb 2024 13:10:20 +0200 Subject: [PATCH 1/3] fix: "Rewards claimed" stats for Shimmer (#1122) Signed-off-by: Eugene Panteleymonchuk --- client/src/app/routes/stardust/landing/AnalyticStats.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/src/app/routes/stardust/landing/AnalyticStats.tsx b/client/src/app/routes/stardust/landing/AnalyticStats.tsx index 0b22b5567..8fdedeb08 100644 --- a/client/src/app/routes/stardust/landing/AnalyticStats.tsx +++ b/client/src/app/routes/stardust/landing/AnalyticStats.tsx @@ -19,9 +19,9 @@ const AnalyticStats: React.FC = ({ analytics, circulatingSup let claimedAndPercentLabels: [string, string] | undefined; if (analytics?.unclaimedShimmer && circulatingSupply) { - // magic number since influx doesn't account for the unclaimable portion of 20% - const shimmerClaimed = circulatingSupply - (Number.parseInt(analytics.unclaimedShimmer, 10) - 362724101812273); - claimedAndPercentLabels = buildShimmerClaimedStats(shimmerClaimed.toString(), String(circulatingSupply), tokenInfo); + const totalSupplyBigInt = (BigInt(circulatingSupply) * BigInt(100)) / BigInt(80); // https://github.com/iotaledger/explorer/issues/584 + const shimmerClaimedBigInt = totalSupplyBigInt - BigInt(analytics.unclaimedShimmer); + claimedAndPercentLabels = buildShimmerClaimedStats(shimmerClaimedBigInt.toString(), totalSupplyBigInt.toString(), tokenInfo); } return analytics && !analytics.error ? ( From 79bfabff6e6ae0c340cccfef333a2845a4b15817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bego=C3=B1a=20=C3=81lvarez=20de=20la=20Cruz?= Date: Fri, 16 Feb 2024 12:23:18 +0100 Subject: [PATCH 2/3] fix: lockedStorageDeposit multiplied by 100 (#1108) * fix: lockedStorageDeposit multiplied by 100 * fix: lockedStorageDeposit multiplied by 100 --------- Co-authored-by: Mario --- api/src/services/stardust/influx/influxQueries.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/src/services/stardust/influx/influxQueries.ts b/api/src/services/stardust/influx/influxQueries.ts index 6ae4ffde5..ac7ba6f2a 100644 --- a/api/src/services/stardust/influx/influxQueries.ts +++ b/api/src/services/stardust/influx/influxQueries.ts @@ -279,14 +279,14 @@ export const LEDGER_SIZE_DAILY_QUERY = { export const STORAGE_DEPOSIT_DAILY_QUERY = { full: ` SELECT - last("total_storage_deposit_amount") * 100 / 1000000 AS "storageDeposit" + last("total_storage_deposit_amount") / 1000000 AS "storageDeposit" FROM "stardust_ledger_size" WHERE time < $to GROUP BY time(1d) fill(null) `, partial: ` SELECT - last("total_storage_deposit_amount") * 100 / 1000000 AS "storageDeposit" + last("total_storage_deposit_amount") / 1000000 AS "storageDeposit" FROM "stardust_ledger_size" WHERE time >= $from and time <= $to GROUP BY time(1d) fill(null) @@ -315,7 +315,7 @@ export const NFT_STAT_TOTAL_QUERY = ` export const STORAGE_DEPOSIT_TOTAL_QUERY = ` SELECT - last("total_storage_deposit_amount") * 100 AS "lockedStorageDeposit" + last("total_storage_deposit_amount") AS "lockedStorageDeposit" FROM "stardust_ledger_size"; `; From 507b49b21db24a93b68cc61dd4a4e0f32f1faa1c Mon Sep 17 00:00:00 2001 From: JCNoguera <88061365+VmMad@users.noreply.github.com> Date: Fri, 16 Feb 2024 12:32:53 +0100 Subject: [PATCH 3/3] refactor: handle multiple unlock types in `getInputsPreExpandedConfig` (#1113) * refactor: handle multiple unlock types in getInputsPreExpandedConfig * feat: handle transitive unlocks * refactor: create util `resolveTransitiveUnlock` --------- Co-authored-by: Mario --- .../src/helpers/stardust/preExpandedConfig.ts | 17 ++++------- .../stardust/resolveTransiviteUnlock.ts | 19 ++++++++++++ .../helpers/stardust/transactionsHelper.ts | 30 +++++-------------- 3 files changed, 31 insertions(+), 35 deletions(-) create mode 100644 client/src/helpers/stardust/resolveTransiviteUnlock.ts diff --git a/client/src/helpers/stardust/preExpandedConfig.ts b/client/src/helpers/stardust/preExpandedConfig.ts index a1badc321..c52a0d669 100644 --- a/client/src/helpers/stardust/preExpandedConfig.ts +++ b/client/src/helpers/stardust/preExpandedConfig.ts @@ -3,18 +3,16 @@ import { CommonOutput, ExpirationUnlockCondition, GovernorAddressUnlockCondition, - ReferenceUnlock, - SignatureUnlock, StateControllerAddressUnlockCondition, Unlock, UnlockConditionType, - UnlockType, Utils, } from "@iota/sdk-wasm/web"; import { Bech32AddressHelper } from "~/helpers/stardust/bech32AddressHelper"; import { IInput } from "~models/api/stardust/IInput"; import { IOutput } from "~models/api/stardust/IOutput"; import { IPreExpandedConfig } from "~models/components"; +import { resolveTransitiveUnlock } from "./resolveTransiviteUnlock"; const OUTPUT_EXPAND_CONDITIONS: UnlockConditionType[] = [ UnlockConditionType.Address, @@ -44,15 +42,10 @@ export function getInputsPreExpandedConfig(inputs: IInput[], unlocks: Unlock[], }; if (input?.output?.output && "unlockConditions" in input.output.output) { const commmonOutput = input.output.output as unknown as CommonOutput; - let unlock = unlocks[idx]; - if (unlock.type === UnlockType.Reference) { - const referenceUnlock = unlock as ReferenceUnlock; - unlock = unlocks[referenceUnlock.reference]; - } - const unlockSignatureAddress = Utils.hexPublicKeyToBech32Address( - (unlock as SignatureUnlock).signature.publicKey, - bech32Hrp, - ); + + const signatureUnlock = resolveTransitiveUnlock(unlocks, idx); + const unlockSignatureAddress = Utils.hexPublicKeyToBech32Address(signatureUnlock.signature.publicKey, bech32Hrp); + preExpandedConfig = { ...preExpandedConfig, unlockConditions: commmonOutput.unlockConditions?.map((unlockCondition) => { diff --git a/client/src/helpers/stardust/resolveTransiviteUnlock.ts b/client/src/helpers/stardust/resolveTransiviteUnlock.ts new file mode 100644 index 000000000..2e7f8d206 --- /dev/null +++ b/client/src/helpers/stardust/resolveTransiviteUnlock.ts @@ -0,0 +1,19 @@ +import { ReferenceUnlock, SignatureUnlock, Unlock, UnlockType } from "@iota/sdk-wasm/web"; + +export function resolveTransitiveUnlock(unlocks: Unlock[], unlockIndex: number): SignatureUnlock { + const unlock = unlocks[unlockIndex]; + let signatureUnlock: SignatureUnlock; + if (unlock.type === UnlockType.Signature) { + signatureUnlock = unlock as SignatureUnlock; + } else { + let refUnlockIdx = unlockIndex; + // unlock references can be transitive, + // so we need to follow the path until we find the signature + do { + const referenceUnlock = unlocks[refUnlockIdx] as ReferenceUnlock; + signatureUnlock = unlocks[referenceUnlock.reference] as SignatureUnlock; + refUnlockIdx = referenceUnlock.reference; + } while (!signatureUnlock.signature); + } + return signatureUnlock; +} diff --git a/client/src/helpers/stardust/transactionsHelper.ts b/client/src/helpers/stardust/transactionsHelper.ts index 1a04615db..c3dc20a19 100644 --- a/client/src/helpers/stardust/transactionsHelper.ts +++ b/client/src/helpers/stardust/transactionsHelper.ts @@ -13,9 +13,7 @@ import { Output, OutputType, PayloadType, - ReferenceUnlock, RegularTransactionEssence, - SignatureUnlock, StateControllerAddressUnlockCondition, TagFeature, TransactionPayload, @@ -23,7 +21,6 @@ import { Unlock, UnlockCondition, UnlockConditionType, - UnlockType, Utils, UTXOInput, } from "@iota/sdk-wasm/web"; @@ -36,6 +33,7 @@ import { IOutput } from "~models/api/stardust/IOutput"; import { MAINNET } from "~models/config/networkType"; import { StardustApiClient } from "~services/stardust/stardustApiClient"; import { Bech32AddressHelper } from "../stardust/bech32AddressHelper"; +import { resolveTransitiveUnlock } from "./resolveTransiviteUnlock"; interface TransactionInputsAndOutputsResponse { inputs: IInput[]; @@ -82,28 +80,14 @@ export class TransactionsHelper { // unlock Addresses computed from public keys in unlocks for (let i = 0; i < unlocks.length; i++) { - const unlock = payload.unlocks[i]; - let signatureUnlock: SignatureUnlock; + const signatureUnlock = resolveTransitiveUnlock(unlocks, i); - if (unlock.type === UnlockType.Signature) { - signatureUnlock = unlock as SignatureUnlock; - } else { - let refUnlockIdx = i; - // unlock references can be transitive, - // so we need to follow the path until we find the signature - do { - const referenceUnlock = payload.unlocks[refUnlockIdx] as ReferenceUnlock; - signatureUnlock = payload.unlocks[referenceUnlock.reference] as SignatureUnlock; - refUnlockIdx = referenceUnlock.reference; - } while (!signatureUnlock.signature); - } - - unlockAddresses.push( - Bech32AddressHelper.buildAddress( - _bechHrp, - Utils.hexPublicKeyToBech32Address(signatureUnlock.signature.publicKey, _bechHrp), - ), + const address = Bech32AddressHelper.buildAddress( + _bechHrp, + Utils.hexPublicKeyToBech32Address(signatureUnlock.signature.publicKey, _bechHrp), ); + + unlockAddresses.push(address); } const payloadEssence = payload.essence as RegularTransactionEssence;