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

docs: add section for withdrawing cycles from cycles ledger #38

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Changes from 1 commit
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
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,10 @@ fund_manager.register(

### Obtaining Cycles

`canfund` can also be configured to obtain cycles from an ICP account balance if your canister requires more cycles than it currently holds. This is achieved by interacting with the ICP Ledger and the Cycles Minting Canister (CMC).
`canfund` can be configured to obtain cycles if your canister requires more cycles than it currently holds. This is achieved by interacting with the ICP Ledger and the Cycles Minting Canister (CMC) or by withdrawing cycles from the cycles ledger. Only one strategy can be set at a time.

To enable this feature, you must provide the necessary configuration to allow `canfund` to mint cycles. This configuration can also be set for each registered canister to override the global configuration.
#### Minting Cycles
To enable minting cycles, you must provide the necessary configuration to allow `canfund` to mint cycles. This configuration can also be set for each registered canister to override the global configuration.

```rust,ignore
let obtain_cycles_config = ObtainCyclesOptions {
Expand All @@ -167,6 +168,25 @@ funding_options.with_obtain_cycles_options(Some(obtain_cycles_config));

With this configuration, `canfund` will periodically check the ICP balance and mint new cycles as needed to ensure that your canisters remain adequately funded.

#### Withdrawing Cycles

Alternatively, `canfund` can be configured to withdraw cycles from the cycles ledger. This is achieved by interacting with the Cycles Ledger using the `WithdrawFromCyclesLedger` struct.

To enable this feature, you must provide the necessary configuration to allow `canfund` to withdraw cycles. This configuration can also be set for each registered canister to override the global configuration.

```rust,ignore
let obtain_cycles_config = ObtainCyclesOptions {
obtain_cycles: Arc::new(WithdrawFromCyclesLedger {
ledger: Arc::new(CyclesLedgerCanister::new(MAINNET_CYCLES_LEDGER_CANISTER_ID)),
from_subaccount: None,
}),
};

funding_options.with_obtain_cycles_options(Some(obtain_cycles_config));
```

With this configuration, canfund will periodically check the cycles balance and withdraw cycles as needed to ensure that your canisters remain adequately funded.

### Funding Callback

`canfund` also supports registering a callback function that will be triggered after a funding round is completed. This feature is useful for monitoring and logging purposes, allowing you to capture and read data such as the remaining cycle balances and total cycles deposited per canister.
Expand Down
Loading