Stores or replaces an Entry by id and appends the id to the global
index. Only callable by Admin.
fn set_entry(env: soroban_sdk::Env, entry: Entry)
Removes an Entry by id and updates the global index. Only callable
by Admin. Panics if the entry does not exist.
fn remove_entry(env: soroban_sdk::Env, id: soroban_sdk::String)
Returns an Entry by id. Panics if the entry does not exist.
fn get_entry(env: soroban_sdk::Env, id: soroban_sdk::String) -> Entry
Bumps when contract logic changes in a way that clients may care about.
fn version(env: soroban_sdk::Env) -> u32
One-time initialization of admin, network, and optional entry ids.
admin: Address with privileged rights (set/remove/upgrade).network: Must be "public" or "testnet".ids: Optional seed list of entry ids to create with zeroed values.Panics if called more than once or if network is invalid.
fn init(
env: soroban_sdk::Env,
admin: soroban_sdk::Address,
network: soroban_sdk::String,
ids: soroban_sdk::Vec,
)
Upgrades the contract code. Only callable by Admin.
fn upgrade(env: soroban_sdk::Env, new_wasm_hash: soroban_sdk::BytesN<32>)
Invest tokens into an entry.
Behavior:
amount from user to the contract.escrow by amount.amount > download_amount threshold, increases user equity
shares and tvl by amount.fn invest(
env: soroban_sdk::Env,
user: soroban_sdk::Address,
id: soroban_sdk::String,
amount: i128,
)
Claim the caller's proportional earnings for an entry.
Earnings are defined as escrow - tvl when positive. The user's
proportional share is (user_shares / tvl) * total_earnings, adjusted
by previously withdrawn amounts. Transfers the claimable amount to the
user and persists updated accounting. Returns the claimed amount.
fn claim_earnings(
env: soroban_sdk::Env,
user: soroban_sdk::Address,
id: soroban_sdk::String,
) -> i128
Sell a portion of the caller's equity shares for an entry.
Behavior:
amount shares.tvl by amount.escrow.escrow (entries with tvl > 0), proportionally to their tvl.fn sell_shares(
env: soroban_sdk::Env,
user: soroban_sdk::Address,
id: soroban_sdk::String,
amount: i128,
) -> i128
Merge one entry into another. Admin-only.
Behavior:
tvl and escrow from from_id into to_id.shares and withdrawn_earnings maps by summing per-user values.fn merge_entries(
env: soroban_sdk::Env,
from_id: soroban_sdk::String,
to_id: soroban_sdk::String,
)
Remove legacy entries that have both tvl = 0 and escrow = 0.
Admin-only. Cleans Index and EligibleIndex accordingly.
fn clean_empty_entries(env: soroban_sdk::Env) -> u32
Batched variant: remove up to limit legacy entries with tvl=0 and escrow=0.
Returns the number of entries removed in this batch.
fn clean_empty_entries_batch(env: soroban_sdk::Env, limit: u32) -> u32
Paged cleanup: scans only the [start, start+limit) window of Index, removing entries with tvl=0 and escrow=0 inside that window. Rebuilds Index while only decoding entries in the specified window to avoid heavy host map unpacking.
fn clean_empty_entries_page(env: soroban_sdk::Env, start: u32, limit: u32) -> u32
Admin-only: remove specific entries by id without decoding their contents. Returns count removed. Safe to use after off-chain verification.
fn remove_entries(
env: soroban_sdk::Env,
ids: soroban_sdk::Vec,
) -> u32