Skip to content

Commit

Permalink
check indexer neg number and fix + clean
Browse files Browse the repository at this point in the history
  • Loading branch information
MSghais committed Jan 26, 2025
1 parent 7a10808 commit 7723eaf
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 240 deletions.
17 changes: 12 additions & 5 deletions apps/nestjs-indexer/src/services/sell-token/sell-token.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,24 @@ export class SellTokenService {
} else {
const newSupply =
Number(tokenLaunchRecord.current_supply ?? 0) + Number(data.amount);
const newLiquidityRaised =
let newLiquidityRaised =
Number(tokenLaunchRecord.liquidity_raised ?? 0) -
Number(data.quoteAmount);
// const newTotalTokenHolded =
// Number(tokenLaunchRecord.total_token_holded ?? 0) -
// Number(data.amount);

const newTotalTokenHolded =
// TODO fix issue negative number
// Check event fees etc
if (newLiquidityRaised < 0) {
newLiquidityRaised = 0;
}
// TODO fix issue negative number
// Check event fees etc
let newTotalTokenHolded =
Number(tokenLaunchRecord.total_token_holded ?? 0) -
Number(data.coinAmount ?? data?.amount);

if (newTotalTokenHolded < 0) {
newTotalTokenHolded = 0;
}
await this.prismaService.token_launch.update({
where: { transaction_hash: tokenLaunchRecord.transaction_hash },
data: {
Expand Down
5 changes: 2 additions & 3 deletions onchain/cairo/launchpad/src/interfaces/launchpad.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ pub trait ILaunchpadMarketplace<TContractState> {
fn get_share_of_user_by_contract(
self: @TContractState, owner: ContractAddress, key_user: ContractAddress,
) -> SharesTokenUser;
fn get_all_launch(self: @TContractState) -> Span<TokenLaunch>;

fn get_all_coins(self: @TContractState) -> Span<Token>;
// fn get_all_launch(self: @TContractState) -> Span<TokenLaunch>;
// fn get_all_coins(self: @TContractState) -> Span<Token>;

// Admins functions
fn set_token(ref self: TContractState, token_quote: TokenQuoteBuyCoin);
Expand Down
65 changes: 29 additions & 36 deletions onchain/cairo/launchpad/src/launchpad/launchpad.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -518,35 +518,35 @@ pub mod LaunchpadMarketplace {
self.shares_by_users.entry(owner).entry(key_user).read()
}

fn get_all_coins(self: @ContractState) -> Span<Token> {
let max_coin_id = self.total_token.read() + 1;
let mut coins: Array<Token> = ArrayTrait::new();
let mut i = 0; //Since the stream id starts from 0
loop {
if i >= max_coin_id {}
let coin = self.array_coins.read(i);
if coin.owner.is_zero() {
break coins.span();
}
coins.append(coin);
i += 1;
}
}

fn get_all_launch(self: @ContractState) -> Span<TokenLaunch> {
let max_key_id = self.total_launch.read() + 1;
let mut launches: Array<TokenLaunch> = ArrayTrait::new();
let mut i = 0; //Since the stream id starts from 0
loop {
if i >= max_key_id {}
let pool = self.array_launched_coins.read(i);
if pool.owner.is_zero() {
break launches.span();
}
launches.append(pool);
i += 1;
}
}
// fn get_all_coins(self: @ContractState) -> Span<Token> {
// let max_coin_id = self.total_token.read() + 1;
// let mut coins: Array<Token> = ArrayTrait::new();
// let mut i = 0; //Since the stream id starts from 0
// loop {
// if i >= max_coin_id {}
// let coin = self.array_coins.read(i);
// if coin.owner.is_zero() {
// break coins.span();
// }
// coins.append(coin);
// i += 1;
// }
// }

// fn get_all_launch(self: @ContractState) -> Span<TokenLaunch> {
// let max_key_id = self.total_launch.read() + 1;
// let mut launches: Array<TokenLaunch> = ArrayTrait::new();
// let mut i = 0; //Since the stream id starts from 0
// loop {
// if i >= max_key_id {}
// let pool = self.array_launched_coins.read(i);
// if pool.owner.is_zero() {
// break launches.span();
// }
// launches.append(pool);
// i += 1;
// }
// }
// User call

// Create token for an user
Expand Down Expand Up @@ -780,7 +780,6 @@ pub mod LaunchpadMarketplace {
get_caller_address(), get_contract_address(), remain_quote_to_liquidity
);

// Assertion: Amount Received Validation
// Update the Stats of pool:
// Liquidity raised
// Available supply
Expand All @@ -790,8 +789,6 @@ pub mod LaunchpadMarketplace {
// Optionally, re-calculate the quote amount based on the amount to ensure consistency
// println!("total_price {:?}", total_price);
// println!("update pool");


// println!("subtract amount and available supply");
// println!("available supply {:?}", pool_coin.available_supply);
// println!("amount {:?}", amount);
Expand All @@ -811,9 +808,6 @@ pub mod LaunchpadMarketplace {
}

// Update share and coin stats for an user
// let mut old_share = self.shares_by_users.read((get_caller_address(), coin_address));
// let mut old_share = self.shares_by_users.entry((get_caller_address(),
// coin_address)).read();
let mut old_share = self
.shares_by_users
.entry(get_caller_address())
Expand All @@ -822,7 +816,6 @@ pub mod LaunchpadMarketplace {

let mut share_user = old_share.clone();
// println!("update share");

if share_user.owner.is_zero() {
share_user =
SharesTokenUser {
Expand Down
Loading

0 comments on commit 7723eaf

Please sign in to comment.