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

fix sell coin issue #50

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions onchain/cairo/src/launchpad/launchpad.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -588,13 +588,14 @@ mod LaunchpadMarketplace {
let token_quote = old_pool.token_quote.clone();
let quote_token_address = token_quote.token_address.clone();

// let mut amount = self
// ._get_amount_by_type_of_coin_or_quote(coin_address, quote_amount, false, true);
// let mut amount = self._get_amount_by_type_of_coin_or_quote(coin_address, quote_amount, false, true);

// TODO fix this function
let mut amount = self
._get_coin_amount_by_quote_amount(coin_address, quote_amount, true);

assert!(old_share.amount_buy >= amount, "Trying to sell more than bought");

let mut total_price = quote_amount.clone();
// println!("amount {:?}", amount);
// println!("quote_amount {:?}", quote_amount);
Expand Down Expand Up @@ -1060,6 +1061,15 @@ mod LaunchpadMarketplace {
let pool_coin = self.launched_coins.read(coin_address);
let total_supply = pool_coin.total_supply.clone();
let current_supply = pool_coin.token_holded.clone();
if is_decreased == true {
let k = current_supply * pool_coin.liquidity_raised;
// println!("k {:?}", k);
// let q_out = total_supply - (k / (quote_amount));
let liquidity_ratio = total_supply / LIQUIDITY_RATIO;
let q_out = (total_supply + liquidity_ratio) + (k / (quote_amount));
// println!("q_out {:?}", q_out);
return q_out;
}
// let mut current_price = self
// ._get_linear_price(pool_coin.initial_key_price, pool_coin.slope, current_supply);
// println!("current_price {:?}", current_price);
Expand Down Expand Up @@ -1191,7 +1201,10 @@ mod LaunchpadMarketplace {
match x {
BondingType::Linear => {
if is_quote_amount == true {
self._get_coin_amount_by_quote_amount(coin_address, amount, is_decreased)
self
._get_coin_amount_by_quote_amount(
coin_address, amount, is_decreased
)
} else {
self._get_quote_paid_by_amount_coin(coin_address, amount, false)
}
Expand Down
Loading