howardpen9 / staking-in-tact

Staking Jetton token(ERC20 in TON) implement in Tact-lang
20 stars 10 forks source link

How to transfer Jetton Token to Staking Contract? #5

Open immujahidkhan opened 1 month ago

immujahidkhan commented 1 month ago

Where are you receive jetton token from a sender ? also have you check sender balance is he has enough Jetton in his wallet? you are checking ton but we need to check Token .

  //where are you receive jetton token from a sender ?
    receive(stake: TokenNotification){
    require(context().value >= ton("0.1"), "not enough value");
    // Check the sender is from the Jetton Wallet
    require(context().sender == self.this_contract_jettonWallet, "not from one of any jetton wallet");

    // Manipulating the score you want to give, no matter based on time or amount
    let score: Int = self.score_function(stake.amount);

    // Update the stake record
    self.stake_record.set(self.index,
        StakeRecord{
            stake_address: stake.from, 
            jettonStakeAmount: stake.amount, 
            score: score
        }
    );

    // Update the weight of the user, if the user is in the list, then add it
    let previous_score: Int = self.score_list.get(stake.from)!!;
    if (previous_score == null) {
        self.score_list.set(stake.from, score);
    } else if (previous_score >= 0) {
        previous_score = (previous_score + score);
        self.score_list.set(stake.from, previous_score);
    }
    self.total_score = (self.total_score + score);
    self.index = (self.index + 1);

    // Submit the Log Event
    emit(TransferEvent{sender_address: stake.from, jetton_amount: stake.amount, score: score}.toCell());
}
tanevanwifferen commented 1 month ago

thanks for that comment, was going to deploy lol. Just learning about TON development, so I'm trying to understand contracts. Would be worthwhile if there'd be an openzeppelin for tact