Skip to content

Commit

Permalink
feat: add initialized field and descrease the price
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptowen committed Jan 19, 2024
1 parent 753b045 commit 3a9717b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion sources/SocialCoin.move
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ module socialcoin::socialcoin {
holders: Table<address, u64>,
// total supply
supply: u64,
// whether the social coin is initialized
initialized: bool,
// subject => balance
holding: Table<address, u64>,
}
Expand Down Expand Up @@ -100,7 +102,7 @@ module socialcoin::socialcoin {
let sum1 = if (supply == 0) { 0 } else { (supply - 1) * (supply) * (2 * (supply - 1) + 1) / 6 };
let sum2 = if (supply == 0 && amount == 1) { 0 } else { (supply - 1 + amount) * (supply + amount) * (2 * (supply - 1 + amount) + 1) / 6 };
let summation = sum2 - sum1;
summation * 100000000
summation * 10000000
}

public fun get_buy_price(global: &Global, subject: address, amount: u64): u64 {
Expand Down Expand Up @@ -141,6 +143,7 @@ module socialcoin::socialcoin {
let shares = Shares {
holders: table::new(ctx),
supply: 0,
initialized: false,
holding: table::new(ctx),
};
table::add(&mut global.shares, subject, shares);
Expand Down Expand Up @@ -179,6 +182,9 @@ module socialcoin::socialcoin {
let subject_share = table::borrow_mut(&mut global.shares, subject);
let supply = subject_share.supply;
assert!(supply > 0 || trader == subject, ERR_ONLY_SHARES_SUBJECT_CAN_BUY_FIRST_SHARE);
if(supply == 0) {
subject_share.initialized = true;
};
let price = get_price(supply, amount);
let protocol_fee = price * global.config.protocol_fee_percent / 1000000000;
let subject_fee = price * global.config.subject_fee_percent / 1000000000;
Expand Down

0 comments on commit 3a9717b

Please sign in to comment.