Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PFT-848] Replace FS functions with sdk config for private key #49

Merged
merged 2 commits into from
Apr 25, 2024
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@parifi/sdk",
"version": "0.1.16",
"version": "0.1.18",
"description": "Parifi SDK with common utility functions",
"files": [
"dist",
Expand Down
14 changes: 12 additions & 2 deletions src/relayers/pimlico/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import 'dotenv/config';
import { RelayerConfig, RpcConfig, SubgraphConfig } from '../../interfaces';
import { executeTxUsingPimlico, getPimlicoSmartAccountClient } from './utils';
import { SmartAccount } from 'permissionless/accounts';
import { Chain, Transport } from 'viem';
import { Chain, Hex, Transport } from 'viem';
import { EntryPoint } from 'permissionless/types/entrypoint';
import { SmartAccountClient } from 'permissionless';
import { getBatchLiquidateTxData, getBatchSettleTxData, getParifiUtilsInstance } from '../../core/parifi-utils';
import { getPublicSubgraphEndpoint } from '../../subgraph';
import { getPythClient } from '../../pyth/pyth';
import { generatePrivateKey } from 'viem/accounts';

import { contracts as parifiContracts } from '@parifi/references';

Expand Down Expand Up @@ -39,7 +40,16 @@ export class Pimlico {
return;
}

this.smartAccountClient = await getPimlicoSmartAccountClient(this.pimlicoConfig, this.rpcConfig);
/// Create Smart account for user address EOA
const privateKey =
((process.env.PRIVATE_KEY as Hex) || this.pimlicoConfig.password) ??
(() => {
const pk = generatePrivateKey();
this.pimlicoConfig.password = pk;
return pk;
})();

this.smartAccountClient = await getPimlicoSmartAccountClient(this.pimlicoConfig, this.rpcConfig, privateKey);

// Set the Pimlico Relayer as initialized
this.isInitialized = true;
Expand Down
12 changes: 1 addition & 11 deletions src/relayers/pimlico/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import { Chain, Hex, Transport, createPublicClient, http } from 'viem';

import { createPimlicoBundlerClient, createPimlicoPaymasterClient } from 'permissionless/clients/pimlico';

import { generatePrivateKey } from 'viem/accounts';

import { EntryPoint } from 'permissionless/types/entrypoint';
import { FACTORY_ADDRESS_SIMPLE_ACCOUNT } from '../../common';

export const getPimlicoSmartAccountClient = async (
pimlicoConfig: RelayerI,
rpcConfig: RpcConfig,
privateKey: `0x${string}`,
): Promise<SmartAccountClient<EntryPoint, Transport, Chain, SmartAccount<EntryPoint>>> => {
const apiKey = pimlicoConfig.apiKey ?? '';
const viemChain = getViemChainById(rpcConfig.chainId as number);
Expand All @@ -32,15 +31,6 @@ export const getPimlicoSmartAccountClient = async (
entryPoint: ENTRYPOINT_ADDRESS_V07,
});

/// Create Smart account for user address EOA
const privateKey =
(process.env.PRIVATE_KEY as Hex) ??
(() => {
const pk = generatePrivateKey();
appendFileSync('.env', `PRIVATE_KEY=${pk}`);
return pk;
})();

const account = await privateKeyToSimpleSmartAccount(publicClient, {
privateKey,
entryPoint: ENTRYPOINT_ADDRESS_V07,
Expand Down
Loading