Skip to content

Commit

Permalink
Add docs to the code
Browse files Browse the repository at this point in the history
  • Loading branch information
9inpachi committed May 27, 2024
1 parent ee9d7e6 commit 3ea1c02
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 13 deletions.
32 changes: 22 additions & 10 deletions docs/docs/api/puffer-client-helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### PufferClientHelpers

Helper methods for the main `PufferClient`.

#### Constructors

##### new PufferClientHelpers()
Expand All @@ -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()

Expand All @@ -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

Expand All @@ -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)
6 changes: 3 additions & 3 deletions docs/docs/api/puffer-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()

Expand All @@ -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)
17 changes: 17 additions & 0 deletions lib/api/puffer-client-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,31 @@ 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],
transport: PufferClientHelpers.extractTransportConfig(config),
});
}

/**
* 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],
Expand Down
26 changes: 26 additions & 0 deletions lib/api/puffer-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof CHAIN_ADDRESSES>;
private chainAbis: ValueOf<typeof CHAIN_ABIS>;
Expand All @@ -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,
Expand All @@ -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<Address>` - Used to
* make the transaction with the given value.
*
* `estimate: () => Promise<bigint>` - Gas estimate of the
* transaction.
*/
public depositETH(walletAddress: Address) {
const contract = getContract({
address: this.chainAddresses.PufferVault as Address,
Expand Down

0 comments on commit 3ea1c02

Please sign in to comment.