-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ECO-2489] Arena Move implementation #408
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
||
struct Nil has store {} | ||
|
||
struct MeleeEscrow<phantom Emojicoin0, phantom EmojicoinLP0, phantom Emojicoin1, phantom EmojicoinLP1> has key { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a field like octa_holdings_upon_entry
could enable instantaneous profit and loss calculations, however it would need to be reset any time someone decided to deposit more. Otherwise there would need to be a sequence of _growth_q64
values to determine PnL between successive entry/exit operations
let match_amount = | ||
if (lock_in) { | ||
let escrow_ref_mut = | ||
&mut MeleeEscrow<Emojicoin0, EmojicoinLP0, Emojicoin1, EmojicoinLP1>[entrant_address]; | ||
let current_tap_out_fee = escrow_ref_mut.tap_out_fee; | ||
let lock_in_period_end_time = | ||
current_melee_ref.start_time + current_melee_ref.lock_in_period; | ||
let lock_ins_still_allowed = | ||
timestamp::now_microseconds() < lock_in_period_end_time; | ||
if (current_tap_out_fee < MAX_MATCH_AMOUNT && lock_ins_still_allowed) { | ||
let eligible_match_amount = MAX_MATCH_AMOUNT - current_tap_out_fee; | ||
eligible_match_amount = if (eligible_match_amount | ||
< current_melee_ref.available_rewards) { | ||
eligible_match_amount | ||
} else { | ||
current_melee_ref.available_rewards | ||
}; | ||
let vault_balance = | ||
coin::balance<AptosCoin>( | ||
account::get_signer_capability_address( | ||
&Registry[@rewards].signer_capability | ||
) | ||
); | ||
eligible_match_amount = if (eligible_match_amount < vault_balance) { | ||
eligible_match_amount | ||
} else { | ||
vault_balance | ||
}; | ||
let requested_match_amount = | ||
( | ||
((input_amount as u128) * (MATCH_PERCENTAGE as u128) | ||
/ (MAX_PERCENTAGE as u128)) as u64 | ||
); | ||
let actual_match_amount = | ||
if (eligible_match_amount < requested_match_amount) { | ||
eligible_match_amount | ||
} else { | ||
requested_match_amount | ||
}; | ||
if (actual_match_amount > 0) { | ||
escrow_ref_mut.tap_out_fee = escrow_ref_mut.tap_out_fee | ||
+ actual_match_amount; | ||
let registry_ref_mut = &mut Registry[@rewards]; | ||
let available_rewards_ref_mut = | ||
&mut registry_ref_mut.melees_by_id.borrow_mut(melee_id).available_rewards; | ||
*available_rewards_ref_mut = *available_rewards_ref_mut | ||
- actual_match_amount; | ||
let vault_signer = | ||
account::create_signer_with_capability( | ||
®istry_ref_mut.signer_capability | ||
); | ||
aptos_account::transfer( | ||
&vault_signer, entrant_address, actual_match_amount | ||
); | ||
}; | ||
actual_match_amount | ||
} else { 0 } | ||
} else { 0 }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could probably be simplified/abstracted out for readability.
participant: &signer, melee_id: u64, may_have_to_pay_tap_out_fee: bool | ||
) acquires Registry { | ||
let participant_address = signer::address_of(participant); | ||
// Only allow exit if user has corresponding melee resourcce and melee ID matches. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Only allow exit if user has corresponding melee resourcce and melee ID matches. | |
// Only allow exit if user has corresponding melee resource and melee ID matches. |
} | ||
|
||
fun init_module(rewards: &signer) { | ||
// Get first melee market addresses, without using randomness APIs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to use randomness APIs during the init_module
function? If not, it might be simplest to just init without any active melee, and have the publisher send the first crank txn, which could be done randomly
/// Set of serial IDs of all melees the user has entered. | ||
melee_ids: SmartTable<u64, Nil> | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useful view functions:
- User's balance in an escrow
- User's PnL in an escrow
- Current melee information
- Economic parameters
- Vault state
start_time: u64, | ||
lock_in_period: u64, | ||
duration: u64 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aggregators might be useful to determine:
- Amount of TVL in the melee, e.g. updated upon entry/exit to an escrow
- Amount of volume driven by melee-only APIs
- Total number of melee-only swaps
- Total number of traders locked in
melees_by_market_combo_sorted_market_ids: SmartTable<vector<u64>, u64>, | ||
/// Approves transfers from the vault. | ||
signer_capability: SignerCapability | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might consider using aggregators to track all-time stats, effectively summing the stats per each melee but across all melees and all time
if (buy_emojicoin_0) { | ||
let swap = | ||
emojicoin_dot_fun::simulate_swap<Emojicoin0, EmojicoinLP0>( | ||
entrant_address, | ||
market_address_0, | ||
input_amount_after_matching, | ||
false, | ||
@integrator, | ||
INTEGRATOR_FEE_RATE_BPS | ||
); | ||
let (_, _, _, _, _, _, _, _, net_proceeds, _, _, _, _, _, _, _, _, _) = | ||
emojicoin_dot_fun::unpack_swap(swap); | ||
emojicoin_dot_fun::swap<Emojicoin0, EmojicoinLP0>( | ||
entrant, | ||
market_address_0, | ||
input_amount_after_matching, | ||
false, | ||
@integrator, | ||
INTEGRATOR_FEE_RATE_BPS, | ||
1 | ||
); | ||
coin::merge( | ||
&mut escrow_ref_mut.emojicoin_0, coin::withdraw(entrant, net_proceeds) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The simulate then swap flow could probably be abstracted out to an inline func
No description provided.