diff --git a/PoolConstants.ts b/PoolConstants.ts index ee264d5..448d39e 100644 --- a/PoolConstants.ts +++ b/PoolConstants.ts @@ -35,7 +35,7 @@ export abstract class Op { } static readonly pool = { request_loan : 0x7ccd46e9, - repay_loan : 0xdfdca27b, + loan_repayment : 0xdfdca27b, deposit : 0x47d54391, withdraw : 0x319b0cdc, //TODO withdrawal : 0x31777cdc, //TODO diff --git a/contracts/controller.func b/contracts/controller.func index 492fc19..b093db8 100644 --- a/contracts/controller.func +++ b/contracts/controller.func @@ -108,7 +108,7 @@ int check_new_stake_msg(slice cs); state = state::REST; } } elseif (equal_slice_bits(sender_address, pool)) { - if(op == pool::repay_loan) { + if(op == pool::loan_repayment) { borrowed_amount += msg_value; borrowing_time = now(); } elseif (op == pool::request_loan) { @@ -135,7 +135,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::repay_loan, query_id).end_cell(), + begin_cell().store_body_header(pool::loan_repayment, query_id).end_cell(), msgflag::BOUNCEABLE, sendmode::PAY_FEES_SEPARETELY); ;; remaining inbound message amount, fee deducted from borrowed_amount = 0; @@ -203,7 +203,7 @@ int check_new_stake_msg(slice cs); available_funds = min( available_funds, borrowed_amount); send_msg(pool, available_funds, - begin_cell().store_body_header(pool::repay_loan, query_id).end_cell(), + begin_cell().store_body_header(pool::loan_repayment, query_id).end_cell(), msgflag::BOUNCEABLE, sendmode::PAY_FEES_SEPARETELY); ;; remaining inbound message amount, fee deducted from borrowed_amount -= available_funds; @@ -391,7 +391,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::repay_loan, query_id).end_cell(), + begin_cell().store_body_header(pool::loan_repayment, query_id).end_cell(), msgflag::BOUNCEABLE, sendmode::PAY_FEES_SEPARETELY); ;; remaining inbound message amount, fee deducted from borrowed_amount = 0; diff --git a/contracts/op-codes.func b/contracts/op-codes.func index b3e2f0c..a035626 100644 --- a/contracts/op-codes.func +++ b/contracts/op-codes.func @@ -37,7 +37,7 @@ const int controller::send_request_loan = 0x452f7112; {- ======== Validator Pool OPCODES ========== -} const int pool::request_loan = 0x7ccd46e9; -const int pool::repay_loan = 0xdfdca27b; +const int pool::loan_repayment = 0xdfdca27b; const int pool::deposit = 0x47d54391; const int pool::withdraw = 0x319b0cdc; ;;TODO const int pool::withdrawal = 0x31777cdc; ;;TODO diff --git a/contracts/pool.func b/contracts/pool.func index 6a9d8e3..1dee905 100644 --- a/contracts/pool.func +++ b/contracts/pool.func @@ -205,7 +205,7 @@ int current_round_index(); } else { assert_not_halted!(); update_round(); - ;; it is ok, controller knew how to process repay_loan/request_loan bounces + ;; it is ok, controller knew how to process loan_repayment/request_loan bounces {- ========== Pool operations ========== -} if (op == pool::request_loan) { @@ -260,7 +260,7 @@ int current_round_index(); .store_uint(max_interest, 16), msgflag::NON_BOUNCEABLE, sendmode::PAY_FEES_SEPARETELY); - } elseif (op == pool::repay_loan) { + } elseif (op == pool::loan_repayment) { ;; we expect loans from previous round only ;; note, close_loan finalize round if last loan is closed (int closed, int last_one) = prev_round_borrowers~close_loan(sender_address, msg_value); diff --git a/jest.config.ts b/jest.config.ts index 69ed60a..e9810b4 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -3,6 +3,7 @@ import type { Config } from 'jest'; const config: Config = { preset: 'ts-jest', testEnvironment: 'node', + testTimeout: 150000 }; export default config; diff --git a/tests/Controller.spec.ts b/tests/Controller.spec.ts index 77857ac..d72ff61 100644 --- a/tests/Controller.spec.ts +++ b/tests/Controller.spec.ts @@ -861,7 +861,7 @@ describe('Cotroller mock', () => { expect(res.transactions).toHaveTransaction({ from: controller.address, to: poolAddress, - op: Op.pool.repay_loan, + op: Op.pool.loan_repayment, value: dataBefore.borrowedAmount /*- fwdFees.fees - fwdFees.remaining*/ }); expect(res.transactions).toHaveTransaction({ @@ -894,7 +894,7 @@ describe('Cotroller mock', () => { expect(res.transactions).toHaveTransaction({ from: controller.address, to: poolAddress, - op: Op.pool.repay_loan, + op: Op.pool.loan_repayment, value: dataBefore.borrowedAmount }); @@ -920,7 +920,7 @@ describe('Cotroller mock', () => { expect(res.transactions).toHaveTransaction({ from: controller.address, to: poolAddress, - op: Op.pool.repay_loan, + op: Op.pool.loan_repayment, value: dataBefore.borrowedAmount }); // No reward message @@ -1425,7 +1425,7 @@ describe('Cotroller mock', () => { expect(repayMsg.info.dest).toEqualAddress(poolAddress); expect(repayMsg.info.value.coins).toEqual(stateBefore.borrowedAmount); - expect(repayMsg.body.beginParse().preloadUint(32)).toEqual(Op.pool.repay_loan); + expect(repayMsg.body.beginParse().preloadUint(32)).toEqual(Op.pool.loan_repayment); // Should revert to rest state const dataAfter = await controller.getControllerData(); diff --git a/tests/ControllerPool.spec.ts b/tests/ControllerPool.spec.ts index 4b41d95..8cdbaea 100644 --- a/tests/ControllerPool.spec.ts +++ b/tests/ControllerPool.spec.ts @@ -56,8 +56,6 @@ describe('Controller & Pool', () => { let poolConfig: PoolConfig; let controllerConfig: ControllerConfig; - jest.setTimeout(60000); - const readState = async (addr: Address) => { const cSmc = await blockchain.getContract(addr); let state = -1; // no account diff --git a/tests/Smoke.spec.ts b/tests/Smoke.spec.ts index 8ff0eb1..5f49ad5 100644 --- a/tests/Smoke.spec.ts +++ b/tests/Smoke.spec.ts @@ -303,7 +303,7 @@ describe('Pool', () => { //await blockchain.setVerbosityForAddress(pool.address, {blockchainLogs:true, vmLogs: 'vm_logs'}); const secondDeposit = await pool.sendDeposit(deployer.getSender(), toNano('1000000')); - const controllerDeployResult = await controller.sendLoanRequest(deployer.getSender(), toNano('1000'), toNano('10000'), 1000n); + const controllerDeployResult = await controller.sendRequestLoan(deployer.getSender(), toNano('1000'), toNano('10000'), 1000); expect(controllerDeployResult.transactions).toHaveTransaction({ from: deployer.address, to: controller.address, diff --git a/wrappers/ValidatorUtils.ts b/wrappers/ValidatorUtils.ts index eb3c8f6..67b6716 100644 --- a/wrappers/ValidatorUtils.ts +++ b/wrappers/ValidatorUtils.ts @@ -315,8 +315,7 @@ export const calcMaxPunishment = (stake: bigint, config: Cell | ConfigDict) => { fine = fine * medium_flat_mult; fine >>= 8; fine_part = fine_part * rec.medium_proportional_mult; fine_part >>= 8; */ - - fine = fine + (stake * fine_part / BigInt(1 << 32)); + fine = fine + (stake * fine_part / (1n << 32n)); // console.log(stake); if(fine > stake) return stake;