[Khensu] Including the contract for the Khensu Platform#9
Open
BlueJaySamurai wants to merge 2 commits into
Open
[Khensu] Including the contract for the Khensu Platform#9BlueJaySamurai wants to merge 2 commits into
BlueJaySamurai wants to merge 2 commits into
Conversation
glevco
requested changes
Jun 1, 2026
| """Create a new token with the manager.""" | ||
| initial_token_reserve = self.default_token_total_supply | ||
|
|
||
| token_uid = self.syscall.create_fee_token( |
Contributor
There was a problem hiding this comment.
We must wait fee tokens activation on mainnet before this is deployed.
Comment on lines
+1249
to
+1251
| for i in range(-1 - offset, -1 - offset - number, -1): | ||
| if -n <= i < 0: | ||
| newest_tokens.append(self.all_tokens[i].hex()) |
Contributor
There was a problem hiding this comment.
This loop is unbounded. Please add a limit to it.
Comment on lines
+1276
to
+1278
| for i in range(-1 - offset, -1 - offset - number, -1): | ||
| if -n <= i < 0: | ||
| recent_graduated_tokens.append(self.graduated_tokens[i].hex()) |
Contributor
There was a problem hiding this comment.
This loop is unbounded. Please add a limit to it.
Comment on lines
+1295
to
+1297
| for i in range(-1 - offset, -1 - offset - number, -1): | ||
| if -n <= i < 0: | ||
| newest_tokens.append(token_list[i].hex()) |
Contributor
There was a problem hiding this comment.
This loop is unbounded. Please add a limit to it.
Comment on lines
+1263
to
+1264
| for i in range(offset, min(offset + number, n)): | ||
| oldest_tokens.append(self.all_tokens[i].hex()) |
Contributor
There was a problem hiding this comment.
This loop is unbounded. Please add a limit to it.
Comment on lines
+1230
to
+1237
| for _ in range(min(number, self.lru_cache_size)): | ||
| if current == self.lru_null_token: | ||
| break | ||
| last_tokens.append(current.hex()) | ||
| if current in self.lru_next: | ||
| current = self.lru_next[current] | ||
| else: | ||
| current = self.lru_null_token |
Contributor
There was a problem hiding this comment.
This loop is unbounded. Please add a limit to it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Khensu Manager Blueprint - Token Fair-Launch Platform with Bonding Curves
This blueprint implements Khensu Manager, a contract that manages a token launchpad with bonding curve pricing for the Hathor network. Tokens are created, traded on a bonding curve, and automatically graduated to a Dozer DEX pool when they reach a target market cap.
What it does
Khensu Manager enables a pump.fun-style token launchpad where anyone can create a new token, trade it on a bonding curve with built-in price discovery, and have the token automatically migrate its liquidity to a full DEX (Dozer Pool Manager) once the bonding curve reaches its target market cap.
Main Workflow
1. Token Creation (
khensu_manager.py:774-854)https://prefix; image links must be ≥ 32 characters2. Token Trading via Bonding Curve
Buy Tokens (
khensu_manager.py:856-948)T = H × (a - c×Ts)² / (a×b + H×c×(a - c×Ts))T= tokens out,H= HTR in,Ts= tokens already soldSell Tokens (
khensu_manager.py:950-1001)H = a×b×T / ((a - c×Ts) × (a - c×Ts + c×T))3. Automatic Migration to DEX (
khensu_manager.py:716-772)buy_tokenswhen the bonding curve reaches 80% tokens sold from the total supply4. User Balance System (
khensu_manager.py:613-629, 1048-1069)Internal Balance Tracking
withdraw_from_balancemethodWithdraw from Balance (
khensu_manager.py:1048-1069)5. Platform Fee Management (
khensu_manager.py:1003-1046)6. Administrative Controls
Fee Configuration
khensu_manager.py:1071-1077) — max 10%khensu_manager.py:1079-1085) — max 10%khensu_manager.py:1087-1093) — max 10%khensu_manager.py:1095-1101) — max 10%Bonding Curve Reconfiguration (
khensu_manager.py:1103-1137)3 × target_market_cap > 5 × graduation_feeAdmin Management (
khensu_manager.py:1139-1153)add_adminremove_admin(cannot remove the original contract creator)Contract Upgrade (
khensu_manager.py:1565-1601)7. Query/View Methods
Token Information
get_token_info(khensu_manager.py:1214-1217) — Full token data including computed market cap and progressget_pool(khensu_manager.py:1441-1449) — Get Dozer pool key for migrated tokenssearch(khensu_manager.py:1168-1212) — Search by symbol or name with paginationToken Listings
get_last_n_tokens(khensu_manager.py:1219-1239) — Most recently active tokens via LRU cache, with cursor-based paginationget_newest_n_tokens(khensu_manager.py:1241-1253) — Newest created tokens (reverse chronological), offset-based paginationget_oldest_n_tokens(khensu_manager.py:1255-1266) — Oldest created tokens (chronological), offset-based paginationget_recently_graduated_tokens(khensu_manager.py:1268-1280) — Recently migrated tokens (reverse chronological)get_tokens_created_by_user(khensu_manager.py:1282-1299) — Tokens created by a specific userUser Data
get_user_balance(khensu_manager.py:1301-1320) — All token balances for a user (formatted astoken_hex_amountspace-separated)get_user_token_balance(khensu_manager.py:1322-1334) — Balance for a specific tokenPrice Quotes
quote_buy(khensu_manager.py:1336-1381) — Quote buying tokens with HTR (includes recommended amount for graduation edge case)quote_sell(khensu_manager.py:1383-1408) — Quote selling tokens for HTRfront_quote_exact_tokens_for_tokens(khensu_manager.py:1451-1506) — Post-migration quote via Dozer reserves (exact input)front_quote_tokens_for_exact_tokens(khensu_manager.py:1508-1563) — Post-migration quote via Dozer reserves (exact output)Platform Data
get_platform_stats(khensu_manager.py:1410-1419) — Total tokens created/migrated and fees collectedget_platform_info(khensu_manager.py:1421-1439) — Full admin configuration and fee stateget_contract_version(khensu_manager.py:1641-1648) — Current contract versionKey Features
Technical Highlights
a = 16 × total_supply × target_market_capb = (target_market_cap + 5 × graduation_fee)²c = 5 × (3 × target_market_cap − 5 × graduation_fee)MarketCap = a × b × S / (a − c × Ts)²Progress = 5 × b × Ts × 10000 / ((target + 5 × grad_fee) × (a − c × Ts))fee = (amount × rate + rate + BASIS_POINTS − 1) / (rate + BASIS_POINTS)lru_prev/lru_nextdicts and head/tail pointers_replace()for partial updatesTokenData) and API (TokenInfo) representations — API includes computed fields likemarket_capandprogressContract Structure
State Variables (Core)
tokens: Main token data dict mappingTokenUid → TokenData(reserves, supply, volume, curve constants, migration state)user_balances: Internal balances per user per token (slippage returns + creator fees)user_balance_tokens: List of tokens with balance per user (for iteration)State Variables (Registry)
all_tokens: Ordered list of all token UIDs (creation order)symbol_dict: Symbol → list of TokenUids mapping for searchname_dict: Name → list of TokenUids mapping for searchuser_creations: Creator address → list of created TokenUidsgraduated_tokens: List of migrated token UIDsState Variables (LRU Cache)
lru_prev/lru_next: Doubly-linked list pointers for O(1) cache operationslru_head/lru_tail: Most/least recently used token pointerslru_cache_capacity/lru_cache_size: Cache boundslru_null_token: Sentinel value (HATHOR_TOKEN_UID) representing null pointersState Variables (Platform)
admin_address: Original contract creator (cannot be removed)admin_set: Set of authorized admin addressescollected_buy_fees/collected_sell_fees/collected_operation_fees: Accumulated platform feestotal_tokens_created/total_tokens_migrated: Platform-wide counterscontract_version: Semantic version string for upgrade control