Skip to content
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

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft

[ECO-2489] Arena Move implementation #408

wants to merge 9 commits into from

Conversation

alnoki
Copy link
Member

@alnoki alnoki commented Nov 22, 2024

No description provided.

Copy link

vercel bot commented Nov 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
emojicoin-dot-fun ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 23, 2024 1:50am
emojicoin-dot-fun-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 23, 2024 1:50am

@alnoki alnoki changed the title [ECO-2489] Refactor tiered rewards for swap escrow [ECO-2489] Arena Move implementation Nov 23, 2024
Copy link


struct Nil has store {}

struct MeleeEscrow<phantom Emojicoin0, phantom EmojicoinLP0, phantom Emojicoin1, phantom EmojicoinLP1> has key {
Copy link
Member Author

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

Comment on lines +132 to +189
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(
&registry_ref_mut.signer_capability
);
aptos_account::transfer(
&vault_signer, entrant_address, actual_match_amount
);
};
actual_match_amount
} else { 0 }
} else { 0 };
Copy link
Member Author

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.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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.
Copy link
Member Author

@alnoki alnoki Nov 26, 2024

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>
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useful view functions:

  1. User's balance in an escrow
  2. User's PnL in an escrow
  3. Current melee information
  4. Economic parameters
  5. Vault state

start_time: u64,
lock_in_period: u64,
duration: u64
}
Copy link
Member Author

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:

  1. Amount of TVL in the melee, e.g. updated upon entry/exit to an escrow
  2. Amount of volume driven by melee-only APIs
  3. Total number of melee-only swaps
  4. 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
}
Copy link
Member Author

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

Comment on lines +195 to +218
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)
);
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant