Skip to content

Commit

Permalink
Merge branch 'main' into feat/issues-1097-stardust-output
Browse files Browse the repository at this point in the history
  • Loading branch information
msarcev authored Feb 16, 2024
2 parents 1ec092e + 507b49b commit 45bbf43
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 41 deletions.
6 changes: 3 additions & 3 deletions api/src/services/stardust/influx/influxQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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";
`;

Expand Down
6 changes: 3 additions & 3 deletions client/src/app/routes/stardust/landing/AnalyticStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const AnalyticStats: React.FC<AnalyticStatsProps> = ({ 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 ? (
Expand Down
17 changes: 5 additions & 12 deletions client/src/helpers/stardust/preExpandedConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) => {
Expand Down
19 changes: 19 additions & 0 deletions client/src/helpers/stardust/resolveTransiviteUnlock.ts
Original file line number Diff line number Diff line change
@@ -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;
}
30 changes: 7 additions & 23 deletions client/src/helpers/stardust/transactionsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@ import {
Output,
OutputType,
PayloadType,
ReferenceUnlock,
RegularTransactionEssence,
SignatureUnlock,
StateControllerAddressUnlockCondition,
TagFeature,
TransactionPayload,
TreasuryOutput,
Unlock,
UnlockCondition,
UnlockConditionType,
UnlockType,
Utils,
UTXOInput,
} from "@iota/sdk-wasm/web";
Expand All @@ -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[];
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 45bbf43

Please sign in to comment.