diff --git a/packages/protocol-kit/src/Safe.ts b/packages/protocol-kit/src/Safe.ts index 20a34a9bd..2a1c78d38 100644 --- a/packages/protocol-kit/src/Safe.ts +++ b/packages/protocol-kit/src/Safe.ts @@ -88,6 +88,7 @@ import { Hash, Hex, SendTransactionParameters } from 'viem' import getPasskeyOwnerAddress from './utils/passkeys/getPasskeyOwnerAddress' import createPasskeyDeploymentTransaction from './utils/passkeys/createPasskeyDeploymentTransaction' import generateOnChainIdentifier from './utils/on-chain-tracking/generateOnChainIdentifier' +import getProtocolKitVersion from './utils/getProtocolKitVersion' const EQ_OR_GT_1_4_1 = '>=1.4.1' const EQ_OR_GT_1_3_0 = '>=1.3.0' @@ -134,12 +135,13 @@ class Safe { const { provider, signer, isL1SafeSingleton, contractNetworks, onchainAnalitics } = config if (onchainAnalitics?.project) { - this.#onchainIdentifier = generateOnChainIdentifier( - onchainAnalitics.project, - onchainAnalitics.platform, - 'protocol-kit', - '5.0.4' - ) + const { project, platform } = onchainAnalitics + this.#onchainIdentifier = generateOnChainIdentifier({ + project, + platform, + tool: 'protocol-kit', + toolVersion: getProtocolKitVersion() + }) } this.#safeProvider = await SafeProvider.init({ diff --git a/packages/protocol-kit/src/utils/getProtocolKitVersion.ts b/packages/protocol-kit/src/utils/getProtocolKitVersion.ts new file mode 100644 index 000000000..3abd3bdb4 --- /dev/null +++ b/packages/protocol-kit/src/utils/getProtocolKitVersion.ts @@ -0,0 +1,7 @@ +import packageJson from '../../package.json' + +function getProtocolKitVersion(): string { + return packageJson.version +} + +export default getProtocolKitVersion diff --git a/packages/protocol-kit/src/utils/on-chain-tracking/generateOnChainIdentifier.ts b/packages/protocol-kit/src/utils/on-chain-tracking/generateOnChainIdentifier.ts index b5f87cfbe..aee82d29f 100644 --- a/packages/protocol-kit/src/utils/on-chain-tracking/generateOnChainIdentifier.ts +++ b/packages/protocol-kit/src/utils/on-chain-tracking/generateOnChainIdentifier.ts @@ -12,22 +12,38 @@ export function generateHash(input: string, size: number): string { return toHex(fullHash.slice(-size)).replace('0x', '') // Take the last X bytes } +export type OnChainIdentifierParamsType = { + project: string + platform?: string + tool: string + toolVersion: string +} + /** * Generates an on-chain identifier for tracking transactions on the blockchain. - * This identifier includes hased metadata such as the project name, platform, tool, and tool version. + * This identifier includes hashed metadata such as the project name, platform, tool, and tool version. * - * @param {string} project - The name of the project initiating the transaction. - * @param {string} [platform='Web'] - The platform from which the transaction originates (e.g., "Web", "Mobile", "Safe App", "Widget"...). - * @param {string} tool - The tool used to generate the transaction (e.g., "protocol-kit"). - * @param {string} toolVersion - The version of the tool used to generate the transaction. + * @param {Object} params - An object containing the metadata for generating the on-chain identifier. + * @param {string} params.project - The name of the project initiating the transaction. + * @param {string} [params.platform='Web'] - The platform from which the transaction originates (e.g., "Web", "Mobile", "Safe App", "Widget"...). + * @param {string} params.tool - The tool used to generate the transaction (e.g., "protocol-kit"). + * @param {string} params.toolVersion - The version of the tool used to generate the transaction. * @returns {string} A string representing the on-chain identifier, composed of multiple hashed segments. + * + * @example + * const identifier = generateOnChainIdentifier({ + * project: 'MyProject', + * platform: 'Mobile', + * tool: 'protocol-kit', + * toolVersion: '4.0.0' + * }) */ -function generateOnChainIdentifier( - project: string, - platform: string = 'Web', - tool: string, - toolVersion: string -): string { +function generateOnChainIdentifier({ + project, + platform = 'Web', + tool, + toolVersion +}: OnChainIdentifierParamsType): string { const identifierPrefix = '5afe' const identifierVersion = '00' // first version const projectHash = generateHash(project, 20) // Take the last 20 bytes diff --git a/packages/protocol-kit/tests/e2e/onChainIdentifier.test.ts b/packages/protocol-kit/tests/e2e/onChainIdentifier.test.ts index cf7e8784d..a4d0eadda 100644 --- a/packages/protocol-kit/tests/e2e/onChainIdentifier.test.ts +++ b/packages/protocol-kit/tests/e2e/onChainIdentifier.test.ts @@ -24,7 +24,7 @@ describe('On-chain analytics', () => { const tool = 'protocol-kit' const toolVersion = '1.0.0' - const onChainIdentifier = generateOnChainIdentifier(project, platform, tool, toolVersion) + const onChainIdentifier = generateOnChainIdentifier({ project, platform, tool, toolVersion }) const identifierPrefix = '5afe' const identifierVersion = '00' diff --git a/packages/protocol-kit/tsconfig.build.json b/packages/protocol-kit/tsconfig.build.json index c05e497c4..51551a680 100644 --- a/packages/protocol-kit/tsconfig.build.json +++ b/packages/protocol-kit/tsconfig.build.json @@ -4,5 +4,5 @@ "composite": true, "outDir": "dist" }, - "include": ["src/**/*"] + "include": ["src/**/*", "package.json"] } diff --git a/packages/protocol-kit/tsconfig.json b/packages/protocol-kit/tsconfig.json index 5f6bc90a7..fc2fc6868 100644 --- a/packages/protocol-kit/tsconfig.json +++ b/packages/protocol-kit/tsconfig.json @@ -4,5 +4,5 @@ "composite": true, "outDir": "dist" }, - "include": ["src/**/*", "tests/**/*", "hardhat/**/*", "hardhat.config.ts"] + "include": ["package.json", "src/**/*", "tests/**/*", "hardhat/**/*", "hardhat.config.ts"] } diff --git a/packages/relay-kit/src/packs/safe-4337/Safe4337Pack.ts b/packages/relay-kit/src/packs/safe-4337/Safe4337Pack.ts index effeb4d62..df55fd2ac 100644 --- a/packages/relay-kit/src/packs/safe-4337/Safe4337Pack.ts +++ b/packages/relay-kit/src/packs/safe-4337/Safe4337Pack.ts @@ -53,6 +53,7 @@ import { } from './utils' import { entryPointToSafeModules, EQ_OR_GT_0_3_0 } from './utils/entrypoint' import { PimlicoFeeEstimator } from './estimators/PimlicoFeeEstimator' +import getRelayKitVersion from './utils/getRelayKitVersion' const MAX_ERC20_AMOUNT_TO_APPROVE = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn @@ -117,12 +118,13 @@ export class Safe4337Pack extends RelayKitBasePack<{ this.#SAFE_WEBAUTHN_SHARED_SIGNER_ADDRESS = safeWebAuthnSharedSignerAddress || '0x' if (onchainAnalitics?.project) { - this.#onchainIdentifier = generateOnChainIdentifier( - onchainAnalitics.project, - onchainAnalitics.platform, - 'relay-kit', - '3.2.4' - ) + const { project, platform } = onchainAnalitics + this.#onchainIdentifier = generateOnChainIdentifier({ + project, + platform, + tool: 'relay-kit', + toolVersion: getRelayKitVersion() + }) } } diff --git a/packages/relay-kit/src/packs/safe-4337/types.ts b/packages/relay-kit/src/packs/safe-4337/types.ts index 99a944703..ea555e17f 100644 --- a/packages/relay-kit/src/packs/safe-4337/types.ts +++ b/packages/relay-kit/src/packs/safe-4337/types.ts @@ -54,7 +54,6 @@ export type Safe4337InitOptions = { } options: ExistingSafeOptions | PredictedSafeOptions paymasterOptions?: PaymasterOptions - // on-chain analitics onchainAnalitics?: OnchainAnaliticsProps } @@ -67,7 +66,6 @@ export type Safe4337Options = { entryPointAddress: string safe4337ModuleAddress: string safeWebAuthnSharedSignerAddress?: string - // on-chain analitics onchainAnalitics?: OnchainAnaliticsProps } diff --git a/packages/relay-kit/src/packs/safe-4337/utils/getRelayKitVersion.ts b/packages/relay-kit/src/packs/safe-4337/utils/getRelayKitVersion.ts new file mode 100644 index 000000000..8f90e8f67 --- /dev/null +++ b/packages/relay-kit/src/packs/safe-4337/utils/getRelayKitVersion.ts @@ -0,0 +1,7 @@ +import packageJson from '../../../../package.json' + +function getRelayKitVersion(): string { + return packageJson.version +} + +export default getRelayKitVersion diff --git a/packages/relay-kit/tsconfig.build.json b/packages/relay-kit/tsconfig.build.json index cc22498f1..0dbe71055 100644 --- a/packages/relay-kit/tsconfig.build.json +++ b/packages/relay-kit/tsconfig.build.json @@ -4,6 +4,6 @@ "composite": true, "outDir": "dist" }, - "include": ["src/**/*"], + "include": ["src/**/*", "package.json"], "exclude": ["src/**/*.test.ts", "src/**/*.test-d.ts"] } diff --git a/packages/relay-kit/tsconfig.json b/packages/relay-kit/tsconfig.json index c05e497c4..51551a680 100644 --- a/packages/relay-kit/tsconfig.json +++ b/packages/relay-kit/tsconfig.json @@ -4,5 +4,5 @@ "composite": true, "outDir": "dist" }, - "include": ["src/**/*"] + "include": ["src/**/*", "package.json"] } diff --git a/playground/protocol-kit/deploy-safe.ts b/playground/protocol-kit/deploy-safe.ts index 4db8f9427..eadbf568b 100644 --- a/playground/protocol-kit/deploy-safe.ts +++ b/playground/protocol-kit/deploy-safe.ts @@ -1,4 +1,3 @@ -import * as dotenv from 'dotenv' import Safe, { SafeAccountConfig, getSafeAddressFromDeploymentTx } from '@safe-global/protocol-kit' import { SafeVersion } from '@safe-global/types-kit' @@ -8,10 +7,6 @@ import { sepolia } from 'viem/chains' import { waitForTransactionReceipt } from 'viem/actions' import semverSatisfies from 'semver/functions/satisfies' -dotenv.config() - -const { SIGNER_ADDRESS_PRIVATE_KEY } = process.env - // This file can be used to play around with the Safe Core SDK interface Config { @@ -27,7 +22,7 @@ interface Config { const config: Config = { RPC_URL: sepolia.rpcUrls.default.http[0], - DEPLOYER_ADDRESS_PRIVATE_KEY: SIGNER_ADDRESS_PRIVATE_KEY!, + DEPLOYER_ADDRESS_PRIVATE_KEY: '', DEPLOY_SAFE: { OWNERS: ['OWNER_ADDRESS'], THRESHOLD: 1, //