> ## Documentation Index
> Fetch the complete documentation index at: https://docs.oaknetwork.org/llms.txt
> Use this file to discover all available pages before exploring further.

# TreasuryFactory

Deploys treasury contracts for a given CampaignInfo. Manages treasury implementations that platforms can register, approve, and deploy.

```typescript theme={null}
const tf = oak.treasuryFactory('0x...contractAddress');
```

## Methods

### Writes

All write methods return `Promise<Hex>` (transaction hash).

| Method                                                                           | Description                            |
| -------------------------------------------------------------------------------- | -------------------------------------- |
| `deploy(platformHash, infoAddress, implementationId)`                            | Deploy a treasury for a campaign       |
| `registerTreasuryImplementation(platformHash, implementationId, implementation)` | Register a new treasury implementation |
| `approveTreasuryImplementation(platformHash, implementationId)`                  | Approve a registered implementation    |
| `disapproveTreasuryImplementation(implementation)`                               | Disapprove an implementation           |
| `removeTreasuryImplementation(platformHash, implementationId)`                   | Remove an implementation               |

## Usage examples

### Deploy a treasury

```typescript theme={null}
import { keccak256, toHex } from '@oaknetwork/contracts-sdk';

const PLATFORM_HASH = keccak256(toHex('my-platform'));
const campaignInfoAddress = '0x...';
const implementationId = 1n; // ID of the approved implementation

const txHash = await tf.deploy(PLATFORM_HASH, campaignInfoAddress, implementationId);
const receipt = await oak.waitForReceipt(txHash);
console.log('Treasury deployed in block:', receipt.blockNumber);
```

### Register and approve an implementation

```typescript theme={null}
// Register
const regTx = await tf.registerTreasuryImplementation(
  PLATFORM_HASH,
  1n,                      // implementationId
  '0x...implAddress',      // implementation contract address
);
await oak.waitForReceipt(regTx);

// Approve
const approveTx = await tf.approveTreasuryImplementation(PLATFORM_HASH, 1n);
await oak.waitForReceipt(approveTx);
```

### Remove an implementation

```typescript theme={null}
const txHash = await tf.removeTreasuryImplementation(PLATFORM_HASH, 1n);
await oak.waitForReceipt(txHash);
```

## Simulation

```typescript theme={null}
try {
  await tf.simulate.deploy(PLATFORM_HASH, campaignInfoAddress, 1n);
  const txHash = await tf.deploy(PLATFORM_HASH, campaignInfoAddress, 1n);
} catch (err) {
  console.error('Would revert:', err.name);
}
```

## Related

* [CampaignInfo](/contracts-sdk/campaign-info) — the campaign that the treasury serves
* [PaymentTreasury](/contracts-sdk/payment-treasury) — fiat payment treasury type
* [AllOrNothing](/contracts-sdk/all-or-nothing) — all-or-nothing crowdfunding treasury type
* [KeepWhatsRaised](/contracts-sdk/keep-whats-raised) — keep-what's-raised treasury type
