Skip to content

Commit

Permalink
Set share to be 24bit number
Browse files Browse the repository at this point in the history
  • Loading branch information
EmelyanenkoK committed Jun 30, 2023
1 parent 80b6080 commit 15a36fb
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions contracts/types.func
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ builder store_body_header(builder b, int op, int query_id) inline {

;; Pool types

(slice, (int)) ~load_share(slice s) inline { return s.load_uint(16); }
builder store_share(builder b, int share) inline { return b.store_uint(share, 16); }
const int SHARE_BASIS = 65536;
(slice, (int)) ~load_share(slice s) inline { return s.load_uint(24); }
builder store_share(builder b, int share) inline { return b.store_uint(share, 24); }
const int SHARE_BASIS = 256 * 256 * 256; ;; 24 bit


(slice, (int)) ~load_controller_id(slice s) inline { return s.load_uint(32); }
Expand Down
4 changes: 2 additions & 2 deletions fift-scripts/generate-loan-request.fif
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{ ."usage: " @' $0 type ." min_loan max_loan max_interest [<savefile>]" cr
."Creates msg body for send_request_loan request to validator-controller " cr
."min_loan and max_loan are in TON" cr
."max_interest is maximal interest is share of loan, controller ready to pay per round as 65536 based rational" cr 1 halt
."max_interest is maximal interest is share of loan, controller ready to pay per round as 16777216 based rational" cr 1 halt
} : usage
$# dup 3 < swap 4 > or ' usage if

Expand All @@ -14,5 +14,5 @@ $2 $>GR =: max_loan
$3 parse-int =: max_interest
$4 "loan_request.boc" replace-if-null =: file-base

<b 0x6335b11a 32 u, now 64 u, min_loan Gram, max_loan Gram, max_interest 16 u, b> 2 boc+>B
<b 0x6335b11a 32 u, now 64 u, min_loan Gram, max_loan Gram, max_interest 24 u, b> 2 boc+>B
file-base B>file
2 changes: 1 addition & 1 deletion tests/ControllerPool.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ describe('Controller & Pool', () => {
});
const loan = await pool.getLoan(0, deployer.address);
const { interestRate } = await pool.getFinanceData()
const expectedInterest = loanRequestParams[1] * BigInt(interestRate) / 65536n;
const expectedInterest = loanRequestParams[1] * BigInt(interestRate) / (256n * 256n * 256n);
expect(loan.borrowed).toEqual(loanRequestParams[1]);
expect(loan.interestAmount).toEqual(expectedInterest);
});
Expand Down
2 changes: 1 addition & 1 deletion wrappers/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class Controller implements Contract {
.storeUint(query_id, 64)
.storeCoins(min_loan)
.storeCoins(max_loan)
.storeUint(max_interest, 16)
.storeUint(max_interest, 24)
.endCell();
}
async sendRequestLoan(provider: ContractProvider,
Expand Down
8 changes: 4 additions & 4 deletions wrappers/Pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function poolConfigToCell(config: PoolConfig): Cell {
.storeInt(0n, 1) // halted?
.storeCoins(0) // total_balance
.storeRef(mintersData)
.storeUint(100, 16) // minimal interest_rate
.storeUint(100, 24) // minimal interest_rate
.storeInt(config.optimistic_deposit_withdrawals, 1) // optimistic_deposit_withdrawals
.storeInt(-1n, 1) // deposits_open?
.storeUint(0, 256) // saved_validator_set_hash
Expand All @@ -118,7 +118,7 @@ export function poolConfigToCell(config: PoolConfig): Cell {
)
.storeCoins(100 * 1000000000) // min_loan_per_validator
.storeCoins(1000000 * 1000000000) // max_loan_per_validator
.storeUint(155, 16) // governance fee
.storeUint(155, 24) // governance fee
.storeRef(roles)
.storeRef(codes)
.endCell();
Expand Down Expand Up @@ -219,7 +219,7 @@ export function poolFullConfigToCell(config: PoolFullConfig): Cell {
.storeBit(config.halted) // halted?
.storeCoins(config.totalBalance) // total_balance
.storeRef(minters)
.storeUint(config.interestRate, 16) // minimal interest_rate
.storeUint(config.interestRate, 24) // minimal interest_rate
.storeBit(config.optimisticDepositWithdrawals) // optimistic_deposit_withdrawals
.storeBit(config.depositsOpen) // deposits_open?
.storeUint(config.savedValidatorSetHash, 256) // saved_validator_set_hash
Expand All @@ -231,7 +231,7 @@ export function poolFullConfigToCell(config: PoolFullConfig): Cell {
)
.storeCoins(config.minLoanPerValidator) // min_loan_per_validator
.storeCoins(config.maxLoanPerValidator) // max_loan_per_validator
.storeUint(config.governanceFee, 16) // governance fee
.storeUint(config.governanceFee, 24) // governance fee
.storeRef(roles)
.storeRef(codes)
.endCell();
Expand Down

0 comments on commit 15a36fb

Please sign in to comment.