You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.3 KiB

2 years ago
import "constants";
import "messages";
fun stakingDepositMessage(value: Int, pool: Address): SendParameters {
return SendParameters{
to: pool,
value: value,
body: beginCell().storeSlice("Deposit".asSlice()).endCell()
};
}
fun stakingWithdrawMessage(value: Int, pool: Address): SendParameters {
return SendParameters{
to: pool,
value: ton("0.05"),
body: beginCell().storeUint(3665837821, 32).storeCoins(value).endCell()
};
}
struct WithdrawalRequests {
addresses: map[Int]Address;
amounts: map[Int]Int;
n_requests: Int = 0;
}
fun withdrawalSum(requests: WithdrawalRequests): Int {
let sum: Int = 0;
let i: Int = 0;
while(i < requests.n_requests) {
sum = sum + requests.amounts.get(i)!!;
i = i + 1;
}
return sum;
2 years ago
}
trait StakingTrait {
staking_pool: Address?;
withdrawal_requests: WithdrawalRequests;
owner: Address;
in_the_pool: Int = 0;
2 years ago
fun sendStake() {
if(self.staking_pool == null) {
return;
}
let value: Int = myBalance() - tonb_floor;
if(value < ton("0.05")) {
return;
}
self.in_the_pool = self.in_the_pool + value;
2 years ago
send(stakingDepositMessage(value, self.staking_pool!!));
}
fun sendWithdrawal() {
if(self.staking_pool == null) {
return;
}
let value: Int = withdrawalSum(self.withdrawal_requests);
send(stakingWithdrawMessage(value, self.staking_pool!!));
}
receive("Withdraw completed") {
let i: Int = 0;
while(i < self.withdrawal_requests.n_requests) {
send(SendParameters{
to: self.withdrawal_requests.addresses.get(i)!!,
value: self.withdrawal_requests.amounts.get(i)!!
});
i = i + 1;
}
// todo: send profit to the foundation (owner)
2 years ago
self.withdrawal_requests = WithdrawalRequests{
addresses: emptyMap(),
amounts: emptyMap()
};
2 years ago
}
fun requestWithdrawal(address: Address, value: Int) {
self.withdrawal_requests.addresses.set(self.withdrawal_requests.n_requests, address);
self.withdrawal_requests.amounts.set(self.withdrawal_requests.n_requests, value);
self.withdrawal_requests.n_requests = self.withdrawal_requests.n_requests + 1;
}
}