Skip to content

Commit

Permalink
WIP Sugar v3, Core
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Aug 13, 2024
1 parent 64fb1f6 commit d7fe06b
Show file tree
Hide file tree
Showing 52 changed files with 1,757 additions and 2,091 deletions.
10 changes: 6 additions & 4 deletions .autodoc/docs/markdown/src/common.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The code can be divided into three main sections:
The code imports several components from Rust's standard library, such as `HashMap`, `File`, `Path`, `PathBuf`, and `FromStr`. These components are commonly used in various parts of the project for tasks like file handling, path manipulation, and string parsing.

2. External Library Imports:
The code imports components from several external libraries, such as `anchor_client`, `anchor_lang`, `anyhow`, `bs58`, `indexmap`, `mpl_candy_machine_core`, `reqwest`, `serde`, `serde_json`, and `tracing`. These libraries provide additional functionality for the project, such as interacting with the Solana blockchain (`anchor_client`), error handling (`anyhow`), HTTP requests (`reqwest`), and logging (`tracing`).
The code imports components from several external libraries, such as `anchor_client`, `anchor_lang`, `anyhow`, `bs58`, `indexmap`, `mpl_core_candy_machine_core`, `reqwest`, `serde`, `serde_json`, and `tracing`. These libraries provide additional functionality for the project, such as interacting with the Solana blockchain (`anchor_client`), error handling (`anyhow`), HTTP requests (`reqwest`), and logging (`tracing`).

3. Internal Module Imports:
The code imports components from other modules within the Sugar project, such as `cache`, `constants`, `errors`, `parse`, and `setup`. These modules provide project-specific functionality, like caching data, defining constants, handling custom errors, parsing input, and setting up the project environment.
Expand All @@ -20,8 +20,10 @@ let client = setup_client(...);
```

By organizing imports in this manner, the Sugar project can easily manage its dependencies and ensure that all required components are available for use throughout the codebase.
## Questions:
1. **Question:** What is the purpose of the `sugar` project and how does this code fit into the overall project?

## Questions:

1. **Question:** What is the purpose of the `sugar` project and how does this code fit into the overall project?

**Answer:** The purpose of the `sugar` project is not clear from this code snippet alone. This code appears to be a module that imports various external libraries and internal modules for use within the project, but more context is needed to understand the project's overall goal.

Expand All @@ -31,4 +33,4 @@ By organizing imports in this manner, the Sugar project can easily manage its de

3. **Question:** Are there any specific version requirements for the imported libraries, and how can they be managed?

**Answer:** This code snippet does not provide information about specific version requirements for the imported libraries. Version management is typically handled in a separate configuration file, such as a `Cargo.toml` file for Rust projects.
**Answer:** This code snippet does not provide information about specific version requirements for the imported libraries. Version management is typically handled in a separate configuration file, such as a `Cargo.toml` file for Rust projects.
22 changes: 12 additions & 10 deletions .autodoc/docs/markdown/src/config/guard_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

The code defines a set of data structures and methods for managing guards in the Sugar project. Guards are conditions that must be met for certain actions to be allowed, such as minting tokens or accessing specific features. The main data structure is `CandyGuardData`, which contains a default `GuardSet` and an optional list of `Group`s, each with its own `GuardSet`.

The `GuardSet` structure contains various optional guards, such as `BotTax`, `SolPayment`, `TokenPayment`, `StartDate`, `ThirdPartySigner`, `TokenGate`, `Gatekeeper`, `EndDate`, `AllowList`, `MintLimit`, `NftPayment`, `RedeemedAmount`, `AddressGate`, `NftGate`, `NftBurn`, `TokenBurn`, `FreezeSolPayment`, and `FreezeTokenPayment`. Each guard has its own data structure and a method `to_guard_format()` that converts it to the corresponding format used by the `mpl_candy_guard` library.
The `GuardSet` structure contains various optional guards, such as `BotTax`, `SolPayment`, `TokenPayment`, `StartDate`, `ThirdPartySigner`, `TokenGate`, `Gatekeeper`, `EndDate`, `AllowList`, `MintLimit`, `NftPayment`, `RedeemedAmount`, `AddressGate`, `NftGate`, `NftBurn`, `TokenBurn`, `FreezeSolPayment`, and `FreezeTokenPayment`. Each guard has its own data structure and a method `to_guard_format()` that converts it to the corresponding format used by the `mpl_core_candy_guard` library.

For example, the `BotTax` guard has a `value` field representing the penalty for invalid transactions and a `last_instruction` field indicating whether it should be checked as the last instruction. The `to_guard_format()` method converts the `value` to lamports and returns a `mpl_candy_guard::guards::BotTax` object.
For example, the `BotTax` guard has a `value` field representing the penalty for invalid transactions and a `last_instruction` field indicating whether it should be checked as the last instruction. The `to_guard_format()` method converts the `value` to lamports and returns a `mpl_core_candy_guard::guards::BotTax` object.

The `CandyGuardData` and `Group` structures also have `to_guard_format()` methods that convert their respective `GuardSet`s to the `mpl_candy_guard` format.
The `CandyGuardData` and `Group` structures also have `to_guard_format()` methods that convert their respective `GuardSet`s to the `mpl_core_candy_guard` format.

Here's an example of how the code might be used in the larger project:

Expand All @@ -21,19 +21,21 @@ let candy_guard_data = CandyGuardData {
groups: None,
};

let mpl_candy_guard_data = candy_guard_data.to_guard_format()?;
let mpl_core_candy_guard_data = candy_guard_data.to_guard_format()?;
```

This example creates a `CandyGuardData` object with a default `GuardSet` containing a `BotTax`, `SolPayment`, and `StartDate` guard. It then converts the `CandyGuardData` object to the `mpl_candy_guard` format.
## Questions:
1. **What is the purpose of the `CandyGuardData` struct and its `to_guard_format` method?**
This example creates a `CandyGuardData` object with a default `GuardSet` containing a `BotTax`, `SolPayment`, and `StartDate` guard. It then converts the `CandyGuardData` object to the `mpl_core_candy_guard` format.

The `CandyGuardData` struct represents the data structure for a candy guard, which includes a default `GuardSet` and an optional vector of `Group` structs. The `to_guard_format` method converts the `CandyGuardData` into the format used by the `mpl_candy_guard::state::CandyGuardData` struct.
## Questions:

1. **What is the purpose of the `CandyGuardData` struct and its `to_guard_format` method?**

The `CandyGuardData` struct represents the data structure for a candy guard, which includes a default `GuardSet` and an optional vector of `Group` structs. The `to_guard_format` method converts the `CandyGuardData` into the format used by the `mpl_core_candy_guard::state::CandyGuardData` struct.

2. **What are the different types of guards available in the `GuardSet` struct?**

The `GuardSet` struct contains various types of guards, such as `BotTax`, `SolPayment`, `TokenPayment`, `StartDate`, `ThirdPartySigner`, `TokenGate`, `Gatekeeper`, `EndDate`, `AllowList`, `MintLimit`, `NftPayment`, `RedeemedAmount`, `AddressGate`, `NftGate`, `NftBurn`, `TokenBurn`, `FreezeSolPayment`, and `FreezeTokenPayment`.

3. **How are the different guard structs converted to their corresponding `mpl_candy_guard::guards` format?**
3. **How are the different guard structs converted to their corresponding `mpl_core_candy_guard::guards` format?**

Each guard struct has a `to_guard_format` method that converts the struct into its corresponding `mpl_candy_guard::guards` format. For example, the `BotTax` struct's `to_guard_format` method returns a `mpl_candy_guard::guards::BotTax` struct with the same data.
Each guard struct has a `to_guard_format` method that converts the struct into its corresponding `mpl_core_candy_guard::guards` format. For example, the `BotTax` struct's `to_guard_format` method returns a `mpl_core_candy_guard::guards::BotTax` struct with the same data.
2 changes: 1 addition & 1 deletion .autodoc/docs/markdown/src/config/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The `data.rs` file defines the main `ConfigData` structure, along with several o

The `errors.rs` file defines a custom error type called `ConfigError` for handling configuration-related issues. It has seven variants, each representing a specific configuration error, such as `ParseError`, `MissingFileError`, `InvalidPathError`, and `PermissionError`.

The `guard_data.rs` file manages guards in the project, which are conditions that must be met for certain actions to be allowed. It defines the `CandyGuardData` structure, which contains a default `GuardSet` and an optional list of `Group`s, each with its own `GuardSet`. Each guard has its own data structure and a method `to_guard_format()` that converts it to the corresponding format used by the `mpl_candy_guard` library.
The `guard_data.rs` file manages guards in the project, which are conditions that must be met for certain actions to be allowed. It defines the `CandyGuardData` structure, which contains a default `GuardSet` and an optional list of `Group`s, each with its own `GuardSet`. Each guard has its own data structure and a method `to_guard_format()` that converts it to the corresponding format used by the `mpl_core_candy_guard` library.

The `mod.rs` file imports and re-exports the contents of the `data`, `errors`, `guard_data`, and `parser` submodules, making them available for use in other parts of the project. It also defines three utility functions: `price_as_lamports`, `to_string`, and `to_pubkey`.

Expand Down
10 changes: 7 additions & 3 deletions .autodoc/docs/markdown/src/guard/remove.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
The `sugar` project contains a file that defines the functionality for removing a candy guard from a candy machine. The candy guard acts as a mint authority, controlling the creation of new tokens in the candy machine. This file provides a function `process_guard_remove` that takes a `GuardRemoveArgs` struct as an argument and returns a `Result<()>`.

The `GuardRemoveArgs` struct contains the following fields:

- `keypair`: An optional string representing the user's keypair.
- `rpc_url`: An optional string representing the RPC URL for the Solana network.
- `cache`: A string representing the cache file path.
- `candy_machine`: An optional string representing the candy machine ID.
- `candy_guard`: An optional string representing the candy guard ID.

The `process_guard_remove` function performs the following steps:

1. It prints a message indicating the unwrapping process has started.
2. It retrieves the candy machine ID and candy guard ID from the provided arguments or from the cache file.
3. It validates and converts the candy machine ID and candy guard ID into `Pubkey` objects.
Expand All @@ -33,12 +35,14 @@ process_guard_remove(args)?;
```

This code would remove the specified candy guard as the mint authority of the specified candy machine, transferring the mint authority to the user's keypair.
## Questions:
1. **Question:** What is the purpose of the `GuardRemoveArgs` struct and its fields?

## Questions:

1. **Question:** What is the purpose of the `GuardRemoveArgs` struct and its fields?
**Answer:** The `GuardRemoveArgs` struct is used to store the arguments required for the `process_guard_remove` function. It contains fields for keypair, rpc_url, cache, candy_machine, and candy_guard, which are all optional strings.

2. **Question:** How does the code handle the precedence of candy machine and candy guard IDs specified in the arguments over the ones from the cache?
**Answer:** The code checks if the candy machine or candy guard ID is provided in the arguments. If it is, the provided ID is used; otherwise, the ID is loaded from the cache.

3. **Question:** How does the code remove the candy guard as the mint authority?
**Answer:** The code sets up a client and a program with the `mpl_candy_guard::ID`. It then creates a transaction with the `UnwrapAccount` struct, which contains the necessary account information, and sends the transaction using `tx.send()`. This effectively removes the candy guard as the mint authority.
**Answer:** The code sets up a client and a program with the `mpl_core_candy_guard::ID`. It then creates a transaction with the `UnwrapAccount` struct, which contains the necessary account information, and sends the transaction using `tx.send()`. This effectively removes the candy guard as the mint authority.
10 changes: 6 additions & 4 deletions .autodoc/docs/markdown/src/guard/withdraw.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The `process_guard_withdraw` function performs the following steps:

3. Retrieve the candy guard account information: The function connects to the Solana network and retrieves the account information for the candy guard ID.

4. Withdraw funds from the candy guard account: The function creates a transaction to withdraw funds from the candy guard account using the `Withdraw` instruction from the `mpl_candy_guard` crate. The transaction is signed by the payer's keypair and sent to the network.
4. Withdraw funds from the candy guard account: The function creates a transaction to withdraw funds from the candy guard account using the `Withdraw` instruction from the `mpl_core_candy_guard` crate. The transaction is signed by the payer's keypair and sent to the network.

5. Update the cache: If the candy guard account was closed and its reference was stored in the cache, the function removes the reference from the cache and syncs the cache file.

Expand All @@ -28,12 +28,14 @@ process_guard_withdraw(args)?;
```

This code snippet initializes a `GuardWithdrawArgs` struct with the necessary information and calls the `process_guard_withdraw` function to withdraw funds from the candy guard account.
## Questions:
1. **Question:** What is the purpose of the `GuardWithdrawArgs` struct and what are its fields used for?

## Questions:

1. **Question:** What is the purpose of the `GuardWithdrawArgs` struct and what are its fields used for?
**Answer:** The `GuardWithdrawArgs` struct is used to store the arguments required for the `process_guard_withdraw` function. It has fields for keypair, rpc_url, cache, and candy_guard, which store the user's keypair, the RPC URL for the Solana network, the cache file path, and the optional candy guard ID, respectively.

2. **Question:** How does the code handle the case when both `args.candy_guard` and the candy guard ID from the cache are provided?
**Answer:** If both `args.candy_guard` and the candy guard ID from the cache are provided, the code prioritizes the `args.candy_guard` value and uses it for the withdrawal process, ignoring the one from the cache.

3. **Question:** What happens if the candy guard ID is not provided in the arguments or the cache?
**Answer:** If the candy guard ID is not provided in the arguments or the cache, the code returns an error with the message "Missing candy guard id." and the withdrawal process is not executed.
**Answer:** If the candy guard ID is not provided in the arguments or the cache, the code returns an error with the message "Missing candy guard id." and the withdrawal process is not executed.
Loading

0 comments on commit d7fe06b

Please sign in to comment.