From 3ea1c02040b8e04982b5775e5f6fd3454da02b65 Mon Sep 17 00:00:00 2001 From: Fawad Ali Date: Fri, 24 May 2024 13:51:44 +0200 Subject: [PATCH] Add docs to the code --- docs/docs/api/puffer-client-helpers.md | 32 ++++++++++++++++++-------- docs/docs/api/puffer-client.md | 6 ++--- lib/api/puffer-client-helpers.ts | 17 ++++++++++++++ lib/api/puffer-client.ts | 26 +++++++++++++++++++++ 4 files changed, 68 insertions(+), 13 deletions(-) diff --git a/docs/docs/api/puffer-client-helpers.md b/docs/docs/api/puffer-client-helpers.md index 4d35838..b4fb85a 100644 --- a/docs/docs/api/puffer-client-helpers.md +++ b/docs/docs/api/puffer-client-helpers.md @@ -4,6 +4,8 @@ ### PufferClientHelpers +Helper methods for the main `PufferClient`. + #### Constructors ##### new PufferClientHelpers() @@ -20,37 +22,47 @@ > `static` **createPublicClient**(`config`): `object` +Helper method for creating a public client based on the +configuration + ###### Parameters -| Parameter | Type | -| :------ | :------ | -| `config` | [`ClientConfig`](puffer-client-helpers.md#clientconfig) | +| Parameter | Type | Description | +| :------ | :------ | :------ | +| `config` | [`ClientConfig`](puffer-client-helpers.md#clientconfig) | Configuration for the public client. | ###### Returns `object` +The public client created with viem. + ###### Source -[lib/api/puffer-client-helpers.ts:21](https://github.com/PufferFinance/puffer-smart-contract-lib/blob/b42b48e3e859b7356dd285f776ef9f575bf1ffe0/lib/api/puffer-client-helpers.ts#L21) +[lib/api/puffer-client-helpers.ts:31](https://github.com/PufferFinance/puffer-smart-contract-lib/blob/04d3cf08e4a224e4d187c438d5041e962c4cdfb2/lib/api/puffer-client-helpers.ts#L31) ##### createWalletClient() > `static` **createWalletClient**(`config`): `object` +Helper method for creating a wallet client based on the +configuration + ###### Parameters -| Parameter | Type | -| :------ | :------ | -| `config` | [`ClientConfig`](puffer-client-helpers.md#clientconfig) | +| Parameter | Type | Description | +| :------ | :------ | :------ | +| `config` | [`ClientConfig`](puffer-client-helpers.md#clientconfig) | Configuration for the wallet client. | ###### Returns `object` +The wallet client created with viem. + ###### Source -[lib/api/puffer-client-helpers.ts:28](https://github.com/PufferFinance/puffer-smart-contract-lib/blob/b42b48e3e859b7356dd285f776ef9f575bf1ffe0/lib/api/puffer-client-helpers.ts#L28) +[lib/api/puffer-client-helpers.ts:45](https://github.com/PufferFinance/puffer-smart-contract-lib/blob/04d3cf08e4a224e4d187c438d5041e962c4cdfb2/lib/api/puffer-client-helpers.ts#L45) ##### extractTransportConfig() @@ -68,7 +80,7 @@ ###### Source -[lib/api/puffer-client-helpers.ts:35](https://github.com/PufferFinance/puffer-smart-contract-lib/blob/b42b48e3e859b7356dd285f776ef9f575bf1ffe0/lib/api/puffer-client-helpers.ts#L35) +[lib/api/puffer-client-helpers.ts:52](https://github.com/PufferFinance/puffer-smart-contract-lib/blob/04d3cf08e4a224e4d187c438d5041e962c4cdfb2/lib/api/puffer-client-helpers.ts#L52) ## Type Aliases @@ -84,4 +96,4 @@ #### Source -[lib/api/puffer-client-helpers.ts:13](https://github.com/PufferFinance/puffer-smart-contract-lib/blob/b42b48e3e859b7356dd285f776ef9f575bf1ffe0/lib/api/puffer-client-helpers.ts#L13) +[lib/api/puffer-client-helpers.ts:13](https://github.com/PufferFinance/puffer-smart-contract-lib/blob/04d3cf08e4a224e4d187c438d5041e962c4cdfb2/lib/api/puffer-client-helpers.ts#L13) diff --git a/docs/docs/api/puffer-client.md b/docs/docs/api/puffer-client.md index 4d64994..55c7914 100644 --- a/docs/docs/api/puffer-client.md +++ b/docs/docs/api/puffer-client.md @@ -28,7 +28,7 @@ Create the Puffer Client. ###### Source -[lib/api/puffer-client.ts:32](https://github.com/PufferFinance/puffer-smart-contract-lib/blob/b42b48e3e859b7356dd285f776ef9f575bf1ffe0/lib/api/puffer-client.ts#L32) +[lib/api/puffer-client.ts:32](https://github.com/PufferFinance/puffer-smart-contract-lib/blob/04d3cf08e4a224e4d187c438d5041e962c4cdfb2/lib/api/puffer-client.ts#L32) #### Properties @@ -90,7 +90,7 @@ transaction. ###### Source -[lib/api/puffer-client.ts:76](https://github.com/PufferFinance/puffer-smart-contract-lib/blob/b42b48e3e859b7356dd285f776ef9f575bf1ffe0/lib/api/puffer-client.ts#L76) +[lib/api/puffer-client.ts:76](https://github.com/PufferFinance/puffer-smart-contract-lib/blob/04d3cf08e4a224e4d187c438d5041e962c4cdfb2/lib/api/puffer-client.ts#L76) ##### requestAddresses() @@ -106,4 +106,4 @@ An array of wallet addresses. ###### Source -[lib/api/puffer-client.ts:60](https://github.com/PufferFinance/puffer-smart-contract-lib/blob/b42b48e3e859b7356dd285f776ef9f575bf1ffe0/lib/api/puffer-client.ts#L60) +[lib/api/puffer-client.ts:60](https://github.com/PufferFinance/puffer-smart-contract-lib/blob/04d3cf08e4a224e4d187c438d5041e962c4cdfb2/lib/api/puffer-client.ts#L60) diff --git a/lib/api/puffer-client-helpers.ts b/lib/api/puffer-client-helpers.ts index ea06ec8..c753092 100644 --- a/lib/api/puffer-client-helpers.ts +++ b/lib/api/puffer-client-helpers.ts @@ -17,7 +17,17 @@ export type ClientConfig = { | { provider: TransportProvider; config?: CustomTransportConfig } ); +/** + * Helper methods for the main `PufferClient`. + */ export class PufferClientHelpers { + /** + * Helper method for creating a public client based on the + * configuration + * + * @param config Configuration for the public client. + * @returns The public client created with viem. + */ public static createPublicClient(config: ClientConfig) { return createPublicClientViem({ chain: VIEM_CHAINS[config.chain], @@ -25,6 +35,13 @@ export class PufferClientHelpers { }); } + /** + * Helper method for creating a wallet client based on the + * configuration + * + * @param config Configuration for the wallet client. + * @returns The wallet client created with viem. + */ public static createWalletClient(config: ClientConfig) { return createWalletClientViem({ chain: VIEM_CHAINS[config.chain], diff --git a/lib/api/puffer-client.ts b/lib/api/puffer-client.ts index 7704a21..89e2549 100644 --- a/lib/api/puffer-client.ts +++ b/lib/api/puffer-client.ts @@ -12,6 +12,9 @@ import { CHAIN_ADDRESSES } from '../contracts/addresses'; import { ValueOf } from '../utils/types'; import { CHAIN_ABIS } from '../contracts/abis/abis'; +/** + * The core class and the main entry point of the Puffer SDK. + */ export class PufferClient { private chainAddresses: ValueOf; private chainAbis: ValueOf; @@ -20,6 +23,12 @@ export class PufferClient { private walletClient: WalletClient; private publicClient: PublicClient; + /** + * Create the Puffer Client. + * @param chain Chain to use for the client. + * @param walletClient The wallet client to use for wallet interactions. + * @param publicClient The public client to use for public interactions. + */ constructor( chain: Chain, walletClient?: WalletClient, @@ -43,10 +52,27 @@ export class PufferClient { }); } + /** + * Request addresses from the wallet. + * + * @returns An array of wallet addresses. + */ public async requestAddresses() { return await this.walletClient.requestAddresses(); } + /** + * Deposit ETH to the given wallet address. This doesn't make the + * transaction but returns two methods namely `transact` and + * `estimate`. + * + * @param walletAddress Wallet address to get the ETH from. + * @returns `transact: (value: bigint) => Promise
` - Used to + * make the transaction with the given value. + * + * `estimate: () => Promise` - Gas estimate of the + * transaction. + */ public depositETH(walletAddress: Address) { const contract = getContract({ address: this.chainAddresses.PufferVault as Address,