Skip to content

Commit 7723eaf

Browse files
committed
check indexer neg number and fix + clean
1 parent 7a10808 commit 7723eaf

File tree

5 files changed

+188
-240
lines changed

5 files changed

+188
-240
lines changed

apps/nestjs-indexer/src/services/sell-token/sell-token.service.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,24 @@ export class SellTokenService {
3232
} else {
3333
const newSupply =
3434
Number(tokenLaunchRecord.current_supply ?? 0) + Number(data.amount);
35-
const newLiquidityRaised =
35+
let newLiquidityRaised =
3636
Number(tokenLaunchRecord.liquidity_raised ?? 0) -
3737
Number(data.quoteAmount);
38-
// const newTotalTokenHolded =
39-
// Number(tokenLaunchRecord.total_token_holded ?? 0) -
40-
// Number(data.amount);
4138

42-
const newTotalTokenHolded =
39+
// TODO fix issue negative number
40+
// Check event fees etc
41+
if (newLiquidityRaised < 0) {
42+
newLiquidityRaised = 0;
43+
}
44+
// TODO fix issue negative number
45+
// Check event fees etc
46+
let newTotalTokenHolded =
4347
Number(tokenLaunchRecord.total_token_holded ?? 0) -
4448
Number(data.coinAmount ?? data?.amount);
4549

50+
if (newTotalTokenHolded < 0) {
51+
newTotalTokenHolded = 0;
52+
}
4653
await this.prismaService.token_launch.update({
4754
where: { transaction_hash: tokenLaunchRecord.transaction_hash },
4855
data: {

onchain/cairo/launchpad/src/interfaces/launchpad.cairo

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,8 @@ pub trait ILaunchpadMarketplace<TContractState> {
7676
fn get_share_of_user_by_contract(
7777
self: @TContractState, owner: ContractAddress, key_user: ContractAddress,
7878
) -> SharesTokenUser;
79-
fn get_all_launch(self: @TContractState) -> Span<TokenLaunch>;
80-
81-
fn get_all_coins(self: @TContractState) -> Span<Token>;
79+
// fn get_all_launch(self: @TContractState) -> Span<TokenLaunch>;
80+
// fn get_all_coins(self: @TContractState) -> Span<Token>;
8281

8382
// Admins functions
8483
fn set_token(ref self: TContractState, token_quote: TokenQuoteBuyCoin);

onchain/cairo/launchpad/src/launchpad/launchpad.cairo

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -518,35 +518,35 @@ pub mod LaunchpadMarketplace {
518518
self.shares_by_users.entry(owner).entry(key_user).read()
519519
}
520520

521-
fn get_all_coins(self: @ContractState) -> Span<Token> {
522-
let max_coin_id = self.total_token.read() + 1;
523-
let mut coins: Array<Token> = ArrayTrait::new();
524-
let mut i = 0; //Since the stream id starts from 0
525-
loop {
526-
if i >= max_coin_id {}
527-
let coin = self.array_coins.read(i);
528-
if coin.owner.is_zero() {
529-
break coins.span();
530-
}
531-
coins.append(coin);
532-
i += 1;
533-
}
534-
}
535-
536-
fn get_all_launch(self: @ContractState) -> Span<TokenLaunch> {
537-
let max_key_id = self.total_launch.read() + 1;
538-
let mut launches: Array<TokenLaunch> = ArrayTrait::new();
539-
let mut i = 0; //Since the stream id starts from 0
540-
loop {
541-
if i >= max_key_id {}
542-
let pool = self.array_launched_coins.read(i);
543-
if pool.owner.is_zero() {
544-
break launches.span();
545-
}
546-
launches.append(pool);
547-
i += 1;
548-
}
549-
}
521+
// fn get_all_coins(self: @ContractState) -> Span<Token> {
522+
// let max_coin_id = self.total_token.read() + 1;
523+
// let mut coins: Array<Token> = ArrayTrait::new();
524+
// let mut i = 0; //Since the stream id starts from 0
525+
// loop {
526+
// if i >= max_coin_id {}
527+
// let coin = self.array_coins.read(i);
528+
// if coin.owner.is_zero() {
529+
// break coins.span();
530+
// }
531+
// coins.append(coin);
532+
// i += 1;
533+
// }
534+
// }
535+
536+
// fn get_all_launch(self: @ContractState) -> Span<TokenLaunch> {
537+
// let max_key_id = self.total_launch.read() + 1;
538+
// let mut launches: Array<TokenLaunch> = ArrayTrait::new();
539+
// let mut i = 0; //Since the stream id starts from 0
540+
// loop {
541+
// if i >= max_key_id {}
542+
// let pool = self.array_launched_coins.read(i);
543+
// if pool.owner.is_zero() {
544+
// break launches.span();
545+
// }
546+
// launches.append(pool);
547+
// i += 1;
548+
// }
549+
// }
550550
// User call
551551

552552
// Create token for an user
@@ -780,7 +780,6 @@ pub mod LaunchpadMarketplace {
780780
get_caller_address(), get_contract_address(), remain_quote_to_liquidity
781781
);
782782

783-
// Assertion: Amount Received Validation
784783
// Update the Stats of pool:
785784
// Liquidity raised
786785
// Available supply
@@ -790,8 +789,6 @@ pub mod LaunchpadMarketplace {
790789
// Optionally, re-calculate the quote amount based on the amount to ensure consistency
791790
// println!("total_price {:?}", total_price);
792791
// println!("update pool");
793-
794-
795792
// println!("subtract amount and available supply");
796793
// println!("available supply {:?}", pool_coin.available_supply);
797794
// println!("amount {:?}", amount);
@@ -811,9 +808,6 @@ pub mod LaunchpadMarketplace {
811808
}
812809

813810
// Update share and coin stats for an user
814-
// let mut old_share = self.shares_by_users.read((get_caller_address(), coin_address));
815-
// let mut old_share = self.shares_by_users.entry((get_caller_address(),
816-
// coin_address)).read();
817811
let mut old_share = self
818812
.shares_by_users
819813
.entry(get_caller_address())
@@ -822,7 +816,6 @@ pub mod LaunchpadMarketplace {
822816

823817
let mut share_user = old_share.clone();
824818
// println!("update share");
825-
826819
if share_user.owner.is_zero() {
827820
share_user =
828821
SharesTokenUser {

0 commit comments

Comments
 (0)