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 pump state and transfer + fix pixel backend #94

Merged
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions apps/mobile/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ EXPO_NODE_ENV="development"
EXPO_PUBLIC_INDEXER_BACKEND_URL=""
EXPO_PUBLIC_PIXEL_URL="http://localhost:3000/pixel"


# Website Pixel UI package
REACT_APP_BACKEND_URL=
REACT_APP_USERNAME_STORE_CONTRACT_ADDRESS=
REACT_APP_CANVAS_NFT_CONTRACT_ADDRESS=
REACT_APP_USERNAME_STORE_CONTRACT_ADDRESS=
REACT_APP_NODE_ENV=

8 changes: 7 additions & 1 deletion apps/website/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ NETWORK_NAME="SN_SEPOLIA" # SN_SEPOLIA, SN_MAIN

PINATA_API_KEY="YOUR_PINATA_API_KEY"
PINATA_SECRET_API_KEY="YOUR_PINATA_SECRET_API_KEY"
IPFS_GATEWAT="https://your.ipfs.gateway.url/ipfs"
IPFS_GATEWAY="https://ipfs.io/"

REACT_APP_BACKEND_URL=
REACT_APP_USERNAME_STORE_CONTRACT_ADDRESS=
REACT_APP_CANVAS_NFT_CONTRACT_ADDRESS=
REACT_APP_USERNAME_STORE_CONTRACT_ADDRESS=
REACT_APP_NODE_ENV=
80 changes: 45 additions & 35 deletions onchain/cairo/src/launchpad/launchpad.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -396,17 +396,6 @@ mod LaunchpadMarketplace {
self._launch_token(coin_address, caller);
}

// Launch liquidity if threshold ok
fn launch_liquidity(ref self: ContractState, coin_address: ContractAddress) {

let pool = self.launched_coins.read(coin_address);

assert!(pool.liquidity_raised >= pool.threshold_liquidity, "no threshold raised");
assert!(pool.is_liquidity_launch == false, "liquidity already launch");

self._add_liquidity(coin_address, SupportedExchanges::Jediswap);

}


// Buy coin by quote amount
Expand Down Expand Up @@ -507,7 +496,22 @@ mod LaunchpadMarketplace {
// println!("amount to buy {:?}", amount);
// println!("total_price {:?}", total_price);

// Update share and key stats
// Change the Stats of pool:
// Liquidity raised
// Available supply
// Token holded
pool_coin.liquidity_raised = pool_coin.liquidity_raised + total_price;
// pool_coin.total_supply += amount;
pool_coin.token_holded += amount;
pool_coin.price = total_price;

if amount > pool_coin.available_supply {
pool_coin.available_supply = 0;
} else {
pool_coin.available_supply -= amount;
}

// Update share and coin stats for an user
let mut old_share = self.shares_by_users.read((get_caller_address(), coin_address));
// println!("old_share {:?}", old_share.owner);

Expand All @@ -532,14 +536,7 @@ mod LaunchpadMarketplace {
}
// pool_coin.price = total_price;
// pool_coin.price = total_price / amount;
pool_coin.liquidity_raised = pool_coin.liquidity_raised + total_price;
// pool_coin.total_supply += amount;
pool_coin.token_holded += amount;
if amount > pool_coin.available_supply {
pool_coin.available_supply = 0;
} else {
pool_coin.available_supply -= amount;
}

// pool_coin.available_supply-=amount;

// TODO // ENABLE if direct launch coin
Expand Down Expand Up @@ -639,18 +636,16 @@ mod LaunchpadMarketplace {
assert!(old_pool.total_supply >= quote_amount, "above supply");

// TODO erc20 token transfer
// let token = old_pool.token_quote.clone();
let total_supply = old_pool.total_supply;
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);

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

assert!(share_user.amount_owned >= amount, "above supply");

let mut total_price = quote_amount.clone();
// println!("amount {:?}", amount);
// println!("quote_amount {:?}", quote_amount);
Expand Down Expand Up @@ -678,32 +673,31 @@ mod LaunchpadMarketplace {
assert!( old_pool.liquidity_raised >= remain_liquidity, "pool_update.liquidity_raised <= remain_liquidity");

// TODO fix amount owned and sellable.
// Update share user key
// share_user.amount_owned -= amount;
// share_user.amount_sell += amount;
// Update share user coin
share_user.amount_owned -= amount;
share_user.amount_sell += amount;

// Transfer to Liquidity, Creator and Protocol
// println!("contract_balance {}", contract_balance);
// println!("transfer creator fee {}", amount_creator_fee.clone());
// println!("transfer liquidity {}", remain_liquidity.clone());
// erc20.transfer(get_caller_address(), remain_liquidity);
erc20.transfer(get_caller_address(), remain_liquidity);
// // println!("transfer protocol fee {}", amount_protocol_fee.clone());
// erc20.transfer(self.protocol_fee_destination.read(), amount_protocol_fee);
erc20.transfer(self.protocol_fee_destination.read(), amount_protocol_fee);

// TODO sell coin if it's already sendable and transferable
// ENABLE if direct launch coin
// let memecoin = IERC20Dispatcher { contract_address: coin_address };
// memecoin.transfer_from(get_caller_address(), get_contract_address(), amount);

// pool_update.price = total_price;

// key.total_supply -= amount;
// TODO check reetrancy guard

// TODO finish update state
// pool_update.price = total_price;
// pool_update.total_supply = pool_update.total_supply - amount;
// pool_update.liquidity_raised = pool_update.liquidity_raised - remain_liquidity;
pool_update.price = total_price;
pool_update.liquidity_raised = pool_update.liquidity_raised - total_price;
pool_update.token_holded -= amount;
pool_update.available_supply += amount;

self
.shares_by_users
.write((get_caller_address(), coin_address.clone()), share_user.clone());
Expand All @@ -724,7 +718,23 @@ mod LaunchpadMarketplace {
);
}


// TODO finish check
// Launch liquidity if threshold ok
fn launch_liquidity(ref self: ContractState, coin_address: ContractAddress) {

let pool = self.launched_coins.read(coin_address);

assert!(pool.liquidity_raised >= pool.threshold_liquidity, "no threshold raised");
assert!(pool.is_liquidity_launch == false, "liquidity already launch");

self._add_liquidity(coin_address, SupportedExchanges::Jediswap);

}

// TODO Finish this function
// Claim coin if liquidity is sent
// Check and modify the share of user
fn claim_coin_buy(ref self: ContractState, coin_address: ContractAddress, amount: u256) {}


Expand Down
6 changes: 3 additions & 3 deletions packages/pixel_ui/src/configs/backend.config.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"host_local": "localhost",
"host_p": "https://backend-pixel.onrender.com/",
"host": "http://localhost:8081",
"host": "backend-pixel.onrender.com/",
"host_p": "localhost",
"port": 8082,
"scripts": {
"place_pixel_devnet": "../tests/integration/local/place_pixel.sh",
"place_extra_pixels_devnet": "../tests/integration/local/place_extra_pixels.sh",
"add_template_devnet": "../tests/integration/local/add_template.sh",
"mint_nft_devnet": "../tests/integration/local/mint_nft.sh"
},
"production": true,
"production": false,
"websocket": {
"read_buffer_size": 1024,
"write_buffer_size": 1024
Expand Down
49 changes: 37 additions & 12 deletions packages/pixel_ui/src/utils/Consts.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,52 @@
import backendConfig from '../configs/backend.config.json';

/** TODO add ENV and config for prod and test */
/** TODO fix url */
// TODO used REACT_APP_NODE_ENV

// const isProduction = process.env.REACT_APP_NODE_ENV == "true" ? true : false
const isProduction = true
// export const backendUrl = 'https://' + backendConfig.host;
export const backendUrl = backendConfig.host;
// export const backendUrl = 'https://' + backendConfig.host + ':' + backendConfig.port;
console.log("isProduction", isProduction)
console.log("REACT_APP_BACKEND_URL", process.env.REACT_APP_BACKEND_URL)
// export const backendUrl = process.env.REACT_APP_BACKEND_URL ?? backendConfig.host;

// export const backendUrl = process.env.REACT_APP_BACKEND_URL ? 'https://' + process.env.REACT_APP_BACKEND_URL : 'https://' + backendConfig.host + ':' + backendConfig.port;
// console.log("backendUrl", backendUrl)

// export const backendUrl = backendConfig.production
// ? 'https://' + backendConfig.host
// : 'http://' + backendConfig.host + ':' + backendConfig.port;
export const backendUrl = isProduction
? 'https://' + typeof process.env.REACT_APP_BACKEND_URL !== "undefined" ? process.env.REACT_APP_BACKEND_URL : backendConfig.host
: 'http://' + backendConfig.host + ':' + backendConfig.port;
console.log("backendUrl", backendUrl)

export const wsUrl = backendConfig.production
export const wsUrl = isProduction
? 'wss://' + backendConfig.host + '/ws'
: 'ws://' + backendConfig.host + ':' + backendConfig.consumer_port + '/ws';
console.log("wsUrl", wsUrl)

export const nftUrl = backendConfig.production
? 'https://' + backendConfig.host
export const nftUrl = isProduction
? 'https://' + typeof process.env.REACT_APP_BACKEND_URL !== "undefined" ? process.env.REACT_APP_BACKEND_URL : backendConfig.host
: 'http://' + backendConfig.host + ':' + backendConfig.consumer_port;

export const templateUrl = backendConfig.production
? 'https://' + backendConfig.host
: 'http://' + backendConfig.host + ':' + backendConfig.port;

export const templateUrl = isProduction
? 'https://' + typeof process.env.REACT_APP_BACKEND_URL !== "undefined" ? process.env.REACT_APP_BACKEND_URL : backendConfig.host
: 'http://' + typeof process.env.REACT_APP_BACKEND_URL !== "undefined" ? process.env.REACT_APP_BACKEND_URL : backendConfig.host + ':' + backendConfig.port;


// export const wsUrl = backendConfig.production
// ? 'wss://' + backendConfig.host + '/ws'
// : 'ws://' + backendConfig.host + ':' + backendConfig.consumer_port + '/ws';
// console.log("wsUrl", wsUrl)

// export const nftUrl = backendConfig.production
// ? 'https://' + typeof process.env.REACT_APP_BACKEND_URL !== "undefined" ? process.env.REACT_APP_BACKEND_URL : backendConfig.host
// : 'http://' + backendConfig.host + ':' + backendConfig.consumer_port;

console.log("nftUrl", nftUrl)

// export const templateUrl = backendConfig.production
// ? 'https://' + typeof process.env.REACT_APP_BACKEND_URL !== "undefined" ? process.env.REACT_APP_BACKEND_URL : backendConfig.host
// : 'http://' + typeof process.env.REACT_APP_BACKEND_URL !== "undefined" ? process.env.REACT_APP_BACKEND_URL : backendConfig.host + ':' + backendConfig.port;

// TODO used REACT_APP_NODE_ENV
export const devnetMode = backendConfig.production === false;
Expand Down
12 changes: 9 additions & 3 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"TELEGRAM_WEB_APP",
"TG_ADMIN_CHAT_ID",
"TELEGRAM_MOBILE_APP",
"EXPO_PUBLIC_PIXEL_URL"
"EXPO_PUBLIC_PIXEL_URL",
"REACT_APP_BACKEND_URL",
"REACT_APP_NODE_ENV"
],
"pipeline": {
"build": {
Expand All @@ -44,7 +46,9 @@
"TELEGRAM_WEB_APP",
"INDEXER_DATABASE_URL",
"TELEGRAM_MOBILE_APP",
"EXPO_PUBLIC_PIXEL_URL"
"EXPO_PUBLIC_PIXEL_URL",
"REACT_APP_BACKEND_URL",
"REACT_APP_NODE_ENV"
]
},
"run": {
Expand All @@ -58,7 +62,9 @@
"NEXT_PUBLIC_PINATA_JWT",
"APP_URL",
"NEXT_PUBLIC_WALLET_CONNECT_ID",
"EXPO_PUBLIC_PIXEL_URL"
"EXPO_PUBLIC_PIXEL_URL",
"REACT_APP_BACKEND_URL",
"REACT_APP_NODE_ENV"
]
},
"deploy": {
Expand Down
Loading