Skip to content

Commit

Permalink
renamed loan_request to request_loan
Browse files Browse the repository at this point in the history
  • Loading branch information
1ixi1 committed Jun 9, 2023
1 parent 604ef66 commit a92dc3e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
15 changes: 12 additions & 3 deletions contracts/controller.func
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ int check_new_stake_msg(slice cs);
state = state::REST;
}
} elseif (equal_slice_bits(sender_address, pool)) {
if(op == pool::loan_repayment) {
if(op == pool::repay_loan) {
borrowed_amount += msg_value;
borrowing_time = now();
} elseif (op == pool::request_loan) {
Expand All @@ -131,7 +131,7 @@ int check_new_stake_msg(slice cs);
if(balance >= MIN_TONS_FOR_STORAGE + borrowed_amount) {
send_msg(pool,
borrowed_amount, ;; TODO add fee???
begin_cell().store_body_header(pool::loan_repayment, query_id).end_cell(),
begin_cell().store_body_header(pool::repay_loan, query_id).end_cell(),
msgflag::BOUNCEABLE,
sendmode::PAY_FEES_SEPARETELY); ;; remaining inbound message amount, fee deducted from
borrowed_amount = 0;
Expand Down Expand Up @@ -358,7 +358,7 @@ int check_new_stake_msg(slice cs);
if(balance >= MIN_TONS_FOR_STORAGE + borrowed_amount) {
send_msg(pool,
borrowed_amount, ;; TODO add fee???
begin_cell().store_body_header(pool::loan_repayment, query_id).end_cell(),
begin_cell().store_body_header(pool::repay_loan, query_id).end_cell(),
msgflag::BOUNCEABLE,
sendmode::PAY_FEES_SEPARETELY); ;; remaining inbound message amount, fee deducted from
borrowed_amount = 0;
Expand Down Expand Up @@ -499,3 +499,12 @@ int get_max_punishment(int stake) method_id {
return (MIN_TONS_FOR_STORAGE + overdue_fine + elector_fine + interest_payment,
validator_amount);
}


(int, int) request_window_time() method_id { ;; TODO: put it in recv_internal in request_loan operation
;; get time window (since, until) when controller may request loan
(int elections_start_before, _, int elections_end_before) = get_validator_config();
(int utime_since, int utime_until, _) = get_current_validator_set();
return (utime_until - elections_start_before,
utime_until - elections_end_before);
}
2 changes: 1 addition & 1 deletion contracts/op-codes.func
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const int controller::send_request_loan = 0x452f7112;

{- ======== Validator Pool OPCODES ========== -}
const int pool::request_loan = 0x7ccd46e9;
const int pool::loan_repayment = 0xdfdca27b;
const int pool::repay_loan = 0xdfdca27b;
const int pool::deposit = 0x47d54391;
const int pool::withdraw = 0x319b0cdc; ;;TODO
const int pool::withdrawal = 0x31777cdc; ;;TODO
Expand Down
15 changes: 9 additions & 6 deletions contracts/pool.func
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ int current_round_index();
} else {
update_round();
}
{- ========== Pool operations ========== -}
if (op == pool::request_loan) {

{- =========== Controller operations =========== -}
if (op == pool::request_loan) {
assert_state!(state::NORMAL);

int min_loan = in_msg_body~load_coins();
Expand Down Expand Up @@ -181,8 +181,7 @@ int current_round_index();
msgflag::NON_BOUNCEABLE, sendmode::PAY_FEES_SEPARETELY);

}
if (op == pool::loan_repayment) {

if (op == pool::repay_loan) {
assert_1of2_state!(state::NORMAL, state::REPAYMENT_ONLY);
;; we expect loans from previous round only
;; note, close_loan finalize round if last loan is closed
Expand All @@ -202,10 +201,12 @@ int current_round_index();
update_round();
}
}

{- ========== Validator operations ========== -}
if (op == pool::deploy_controller) {
assert_state!(state::NORMAL);
int controller_id = in_msg_body~load_uint(32);
(slice controller_address, cell init_state ) = build_controller_address(controller_id, sender_address);
(slice controller_address, cell init_state) = build_controller_address(controller_id, sender_address);
builder msg = begin_cell()
.store_msg_flags(msgflag::BOUNCEABLE)
.store_slice(controller_address)
Expand All @@ -214,6 +215,8 @@ int current_round_index();
.store_body_header(controller::top_up, cur_lt());
send_raw_message(msg.end_cell(), sendmode::CARRY_ALL_REMAINING_MESSAGE_VALUE);
}

{- ========== Nominator operations ========== -}
if (op == pool::deposit) {
assert_state!(state::NORMAL);
throw_unless(error::deposits_are_closed, deposits_open?);
Expand Down Expand Up @@ -261,8 +264,8 @@ int current_round_index();
;; TODO send response to response_address
}
}
{- ========== General operations ========== -}

{- ========== Governance operations ========== -}
if (op == sudo::send_message) {
process_sudo_request(sender_address, in_msg_body);
}
Expand Down
22 changes: 22 additions & 0 deletions tests/ControllerPool.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Controller and Pool communication

File `ControllerPool.spec.ts` contains tests for actions where Pool and
Controller are the main participants.

There are only 2 actions like this: `request_loan` and `repay_loan`, which
are both starting as a message from controller to pool.


## Loan request

Pool should accept it only from controllers that were minted by this pool
with exact approver. Tests are need to cover

Selected interest rate should be greater or eqal to pool's interest

Then pool should correctly add the loan to it's list.


## Loan repayment


0 comments on commit a92dc3e

Please sign in to comment.