Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/internal/metrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { AxiosInstance } from "axios";

/**
* Tracks a transaction metric specifically for developer-controlled wallets.
* Internal SDK helper used by DCW functions.
*/
export async function trackDeveloperTransaction(
axiosInstance: AxiosInstance,
network: "mainnet" | "testnet",
blockchain: "cardano" | "bitcoin" | "spark",
type: string = "tx-submit"
) {
try {
const yearMonth = new Date().toISOString().slice(0, 7);
await axiosInstance.post("api/metrics/tx", {
walletType: "developer",
blockchain,
network: network,
type,
yearMonth,
});
} catch (error) {
// Silent fail - tracing shouldn't break the SDK
}
}

/**
* Tracks a platform-level metric.
* Internal SDK helper for platform-wide analytics.
*/
export async function trackPlatformMetric(
axiosInstance: AxiosInstance,
metricType:
| "mau"
| "new-wallets"
| "active-projects"
| "new-projects",
count: number = 1
) {
try {
await axiosInstance.post("api/metrics/platform", {
metricType,
count,
});
} catch (error) {
// Silent fail
}
}

13 changes: 13 additions & 0 deletions src/non-custodial/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import {
Web3WalletObject,
Web3AuthProvider,
} from "../";
import axios from "axios";
import { trackPlatformMetric } from "../internal/metrics";


import { getStorage, getLinking, getEncoding } from "../internal/platform-context";

export * from "./utils";

const AUTH_KEY = "mesh-web3-services-auth";
Expand Down Expand Up @@ -359,7 +364,15 @@ export class Web3NonCustodialProvider {
}
const result = (await res.json()) as CreateWalletResponseBody;

try {
const metricsAxios = axios.create({ baseURL: this.appOrigin });
await trackPlatformMetric(metricsAxios, "new-wallets");
await trackPlatformMetric(metricsAxios, "mau");
} catch (e) {}

await this.pushDevice({


deviceId: result.deviceId,
encryptedDeviceShard,
walletId: result.walletId,
Expand Down
5 changes: 5 additions & 0 deletions src/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { Web3Project } from "../types";
import { IFetcher, ISubmitter } from "@meshsdk/common";
import { Sponsorship } from "./sponsorship";
import { Tokenization } from "./tokenization";
import { trackPlatformMetric } from "../internal/metrics";


export const meshUniversalStaticUtxo = {
mainnet: {
Expand Down Expand Up @@ -148,7 +150,10 @@ export class Web3Sdk {

if (status === 200) {
this.project = data as Web3Project;
await trackPlatformMetric(this.axiosInstance, "active-projects");
await trackPlatformMetric(this.axiosInstance, "mau");
return this.project;

}

throw new Error("Failed to get project");
Expand Down
11 changes: 11 additions & 0 deletions src/sdk/sponsorship/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Asset, UTxO } from "@meshsdk/common";
import { MeshTxBuilder } from "@meshsdk/transaction";
import { meshUniversalStaticUtxo } from "../index";
import { SponsorshipTxParserPostRequestBody } from "../../types";
import { trackDeveloperTransaction } from "../../internal/metrics";


type SponsorshipConfig = {
id: string;
Expand Down Expand Up @@ -482,6 +484,15 @@ export class Sponsorship {
const unsignedTx = await txBuilder.complete();
const signedTx = await wallet.signTxReturnFullTx(unsignedTx);
const txHash = await this.sdk.providerSubmitter!.submitTx(signedTx);
if(txHash){
await trackDeveloperTransaction(
this.sdk.axiosInstance,
this.sdk.network,
"cardano",
"tx-submit",
);
}


await this.sdk.axiosInstance.post(
`api/sponsorship/${config.id}/refreshTxHash`,
Expand Down
9 changes: 9 additions & 0 deletions src/sdk/tokenization/cardano.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
ListFrozenAddressesParams,
ListTokenizationPoliciesParams,
} from "../../types/cardano/tokenization";
import { trackDeveloperTransaction } from "../../internal/metrics";


export type {
CreateTokenParams,
Expand Down Expand Up @@ -313,6 +315,13 @@ export class TokenizationCardano {
status: params.status || "success",
metadata: params.metadata,
});
await trackDeveloperTransaction(
this.sdk.axiosInstance,
this.sdk.network,
"cardano",
"tx-submit",
);

} catch (error) {
console.warn(`Failed to log ${params.type} transaction:`, error);
}
Expand Down
9 changes: 9 additions & 0 deletions src/sdk/tokenization/spark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import {
ListFrozenAddressesParams,
ListTokenizationPoliciesParams,
} from "../../types/spark/tokenization";
import { trackDeveloperTransaction } from "../../internal/metrics";


export type {
InitTokenizationParams,
Expand Down Expand Up @@ -671,6 +673,13 @@ export class TokenizationSpark {
toAddress: params.toAddress,
status: params.status || "confirmed",
});
await trackDeveloperTransaction(
this.sdk.axiosInstance,
this.sdk.network,
"spark",
"tx-submit",
);

} catch (error) {
console.warn(`Failed to log ${params.type} transaction:`, error);
}
Expand Down
16 changes: 16 additions & 0 deletions src/sdk/wallet-developer-controlled/cardano.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Web3Sdk } from "..";
import { MeshCardanoHeadlessWallet } from "@meshsdk/wallet";
import { decryptWithPrivateKey } from "../../functions";
import { MultiChainWalletInfo, TokenCreationParams } from "../../types";
import { trackDeveloperTransaction } from "../../internal/metrics";


/**
* CardanoWalletDeveloperControlled - Manages Cardano-specific developer-controlled wallets.
Expand Down Expand Up @@ -103,7 +105,21 @@ export class CardanoWalletDeveloperControlled {
walletAddressType: 1,
});

// Wrap submitTx to track metrics
const originalSubmitTx = wallet.submitTx.bind(wallet);
wallet.submitTx = async (tx: string) => {
const txHash = await originalSubmitTx(tx);
await trackDeveloperTransaction(
this.sdk.axiosInstance,
this.sdk.network,
"cardano",
"tx-submit",
);
return txHash;
};

return { info: web3Wallet, wallet: wallet };

}

throw new Error("Failed to get Cardano wallet");
Expand Down
9 changes: 9 additions & 0 deletions src/sdk/wallet-developer-controlled/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import { IssuerSparkWallet } from "@buildonspark/issuer-sdk";
import { deserializeBech32Address } from "@meshsdk/core-cst";
import { encryptWithPublicKey, decryptWithPrivateKey } from "../../functions";
import { v4 as uuidv4 } from "uuid";
import {
trackPlatformMetric,
} from "../../internal/metrics";



/**
* The `WalletDeveloperControlled` class provides functionality for managing developer-controlled wallets
Expand Down Expand Up @@ -138,7 +143,11 @@ export class WalletDeveloperControlled {
);

if (status === 200) {
await trackPlatformMetric(this.sdk.axiosInstance, "new-wallets");
await trackPlatformMetric(this.sdk.axiosInstance, "mau");
return {


info: walletData,
sparkIssuerWallet: sparkWallet,
cardanoWallet: cardanoWallet,
Expand Down
Loading