Closed kevinrodriguez-io closed 3 months ago
How are you planning to implement the deny/allow list structure here? I don't see any struct for it, will it be a PDA point to a re-sizable list of other IDs?
Here is a first take on guard structure to support cpi, amount, and additional field rules. If a guard has multiple rules set then all must pass for the transfer to be allowed.
If the rule is none or vec is empty then the rule is skipped.
// Control which protocols can interact with a mint's tokens. eg only allow royalty respecting protocols to facilitate transfers.
enum CPIRule {
Allow(Vec<Pubkey>)
Deny(Vec<Pubkey>)
}
// Enforce the transfer amount is above, below, equal to, or within a range set my the mint authority.
enum TransferAmountRule {
Above(u64),
Below(u64),
Equal(u64),
Rang(u64, u64)
}
enum MetadataAdditionalFieldRestriction {
Includes(Vec<String>),
Excludes(Vec<String>)
}
// Ensure a field exists and if desired is equal to some value. If multiple rules are set then all must pass.
struct MetadataAdditionalFieldRule {
field: String,
value_restrictions: Option<MetadataAdditionalFieldRestriction>
}
seed: ["wen_token_guard", "guard_v1", {mint}]
struct GuardV1 {
cpi_rule: Option<CPIRule>,
transfer_amount_rule: Option<TransferAmountRule>,
addition_fields_rule: Vec<AdditionalFieldRule>
}
/// Ensure the token has
enum Guard {
V1(GuardV1)
}
Wen Transfer Guard Program
The Wen Transfer Guard Program secures token transfers on the Solana blockchain by enforcing customizable rules using the token_2022 program transfer hook interface.
How It Works
Overview
Create a Transfer Guard Account:
Update the Guard:
Initialize the Guard:
Execute Transfer Rules:
Instructions Summary
create_guard
: Creates a new transfer guard account.update_guard
: Updates the ruleset of a transfer guard account.initialize
: Assigns extra metas to a given mint, linking the guard to it.execute
: Enforces the ruleset during a token transfer.Guard Ruleset Modes
Example Flow (Anchor Based)
Creating a guard
Updating a guard
Initializing (Assign guard to mint)
Executing a transfer