CHAN¶
Overview¶
CHAN is the player channel manager that coordinates YUE (player banks) and handles opt-in mechanics for game contracts. It provides controlled access to player funds through the whitelist system.
- Inherits: DYSNOMIA V2
- License: Sharia
- Solidity: ^0.8.21
What This Means For Players¶
Plain English Summary: CHAN is the player manager - it controls access to your bank (YUE). Before any game contract can touch your funds, you must explicitly opt-in through CHAN. This gives you granular control over which game features can access your tokens.
Real-World Analogy: Think of CHAN like the security settings on your bank account. You can authorize specific apps to access your account (opt-in) and revoke that access anytime (opt-out). No one can move your money without your explicit permission.
How It Affects Your Gameplay: - Opt-in control - You decide which contracts can access your YUE - YUE management - CHAN links your wallet address to your YUE bank - Transfer safety - Withdrawals and transfers only work with opted-in contracts - Account portability - You can transfer your YUE to a new wallet through CHAN
State Variables¶
| Variable | Type | Visibility | Description |
|---|---|---|---|
| Type | string | public constant | "CHAN" |
| Xie | XIE | public | Reference to XIE power contract |
| Yan | mapping(address => address) | public | Origin → YUE mapping |
| _optInList | mapping(address => mapping(address => bool)) | private | YUE → Contract opt-in |
Read Functions¶
Yan¶
- Returns: YUE address for origin - In Plain English: Look up any player's bank (YUE) address using their wallet address. This is how the game finds your personal bank.OptedIn¶
- Returns: True if YUE has opted into contract - In Plain English: Check if a player has authorized a specific contract to access their bank. Returns true if they've granted permission.Write Functions¶
AddYue¶
- Access:onlyOwners
- Parameters:
- Origin (address): Player's wallet address
- Yue (address): YUE bank contract address to associate
- Description: Registers a YUE bank for a player's wallet address. Prevents duplicate associations.
- Logic Flow:
1. Check not already registered: if(Yan[Origin] != address(0x0)) revert AlreadyAdded
2. Store mapping: Yan[Origin] = Yue
3. Mint to capacity: mintToCap()
- Side Effects: Updates Yan mapping; mints CHAN tokens
- In Plain English: Link a new player's wallet to their bank account. This is done during player setup to register their YUE. Each wallet can only have one YUE.
TransferYue¶
- Access:public
- Parameters:
- Yue (address): YUE bank contract to transfer
- NewOrigin (address): New wallet address to own the YUE
- Description: Transfers YUE ownership to a new wallet. Caller must be current origin.
- Logic Flow:
1. Check new origin is available: if(Yan[NewOrigin] != address(0x0)) revert AlreadyAdded
2. Verify caller owns YUE: if(_chi.Origin() != tx.origin) revert NotOrigin
3. Clear old mapping: Yan[_chi.Origin()] = address(0x0)
4. Execute origin change on YUE: _chi.ChangeOrigin(NewOrigin)
5. Set new mapping: Yan[NewOrigin] = Yue
6. Mint to capacity
- Side Effects: Updates Yan mappings; modifies YUE contract origin; mints CHAN tokens
- In Plain English: Move your bank account to a new wallet address. Only the current owner can do this - useful if you need to change wallets but keep your game progress.
ReactYue¶
- Access:onlyOwners
- Parameters:
- Yue (YUEINTERFACE): Player's YUE bank
- Qing (address): Venue (QING) to react against
- Returns:
- Charge (uint256): Reaction charge value from YUE.React
- Description: Makes a player's YUE bank react with a venue, generating charge value.
- Logic Flow:
1. Call YUE reaction: Charge = Yue.React(Qing)
2. Return charge value
- Side Effects: Triggers YUE reaction which may update internal state; mints tokens
- In Plain English: Make a player's bank interact with a venue. This builds up their activity score at that venue and returns a charge value used for calculating rewards.
OptIn¶
- Access:public
- Parameters:
- Contract (address): Contract to grant/revoke access for
- Allow (bool): True to authorize, false to revoke
- Description: Player sets opt-in permission for a contract to access their YUE.
- Logic Flow:
1. Get player's YUE: look up via origin
2. Set permission: _optInList[address(Yue)][Contract] = Allow
3. Emit event: NewSpenderContractOptIn(tx.origin, Yue, Contract, Allow)
4. Mint to capacity
- Side Effects: Updates _optInList mapping; emits event; mints CHAN tokens
- In Plain English: Grant or revoke permission for a contract to access your bank. Set Allow=true to authorize, false to block. You control who can touch your funds.
YueWithdraw¶
- Access:onlyOwners
- Parameters:
- Yue (YUEINTERFACE): Player's YUE bank
- Asset (address): Token to withdraw
- To (address): Destination address
- Amount (uint256): Amount to transfer
- Description: Withdraws tokens from a YUE if caller has opt-in permission.
- Logic Flow:
1. Check opt-in: if(!_optInList[address(Yue)][msg.sender]) revert PlayerMustOptIn
2. Execute withdrawal: Yue.Withdraw(Asset, To, Amount)
3. Mint to capacity
- Side Effects: Transfers tokens from YUE; mints CHAN tokens
- In Plain English: Take tokens from a player's bank and send them somewhere. Only works if the player has opted in - this protects against unauthorized withdrawals.
YueMintToOrigin¶
- Access:onlyOwners
- Parameters:
- Yue (YUEINTERFACE): Player's YUE bank
- Description: Triggers YUE's internal mint-to-origin function.
- Logic Flow:
1. Call YUE mint: Yue.MintToOrigin()
2. Mint to capacity
- Side Effects: Mints YUE tokens to player; mints CHAN tokens
- In Plain English: Create a new YUE token and send it to the player's wallet. Used during setup and as part of reward distribution.
YueForceTransfer¶
function YueForceTransfer(YUEINTERFACE Yue, address From, address To, uint256 Amount) public onlyOwners
onlyOwners
- Parameters:
- Yue (YUEINTERFACE): Player's YUE bank
- From (address): Source address
- To (address): Destination address
- Amount (uint256): Amount to transfer
- Description: Forces a token transfer via YUE if caller has opt-in permission.
- Logic Flow:
1. Check opt-in: if(!_optInList[address(Yue)][msg.sender]) revert PlayerMustOptIn
2. Execute force transfer: Yue.ForceTransfer(From, To, Amount)
3. Mint to capacity
- Side Effects: Transfers tokens; mints CHAN tokens
- In Plain English: Move tokens between addresses using the player's bank. Requires player opt-in consent - this enables game mechanics that need to move tokens for gameplay.
Events¶
| Event | Parameters | Description |
|---|---|---|
| NewSpenderContractOptIn | Origin, Yue, Contract, Allow | Opt-in state change |
Errors¶
| Error | Parameters | Description |
|---|---|---|
| AlreadyAdded | Origin, Yue, New | Origin already has YUE |
| NotOrigin | YueOrigin, Requestor | Not YUE origin |
| PlayerMustOptIn | Player, Yue, Contract | Opt-in required |
Contract Interactions¶
Depends On¶
- DYSNOMIA V2 - Base functionality
- XIE - Power calculations
Depended On By¶
Special Mechanisms¶
Opt-In Security¶
function YueWithdraw(YUEINTERFACE Yue, address Asset, address To, uint256 Amount) public onlyOwners {
if(!_optInList[address(Yue)][msg.sender])
revert PlayerMustOptIn(Yue.Origin(), address(Yue), msg.sender);
Yue.Withdraw(Asset, To, Amount);
}
YUE Transfer¶
function TransferYue(address Yue, address NewOrigin) public {
// Check no conflict
if(Yan[NewOrigin] != address(0x0)) revert AlreadyAdded(...);
// Verify caller is origin
YUEINTERFACE _chi = YUEINTERFACE(Yue);
if(_chi.Origin() != tx.origin) revert NotOrigin(...);
// Update mappings
Yan[_chi.Origin()] = address(0x0);
_chi.ChangeOrigin(NewOrigin);
Yan[NewOrigin] = Yue;
}
Contract Verification¶
| Property | Value |
|---|---|
| Keccak256 Hash | 0xb5795a39986847f3f24ca4cf07279bfcf4a723f9b255e73f5a37673990261da0 |
| Source URL | https://raw.githubusercontent.com/busytoby/atropa_pulsechain/main/solidity/dysnomia/domain/sky/01_chan.sol |
| Hash Generated | 2026-02-08T00:29:08Z |