Using #import produce contract that doesn't typecheck
This contract typechecks in ligo but not in michelson. May be either a typechecking bugs or a Module access bugs.
module auditFarm/contract/main/../partials/FarmMethods.mligo = const only_admin = "Only the contract admin can change the contract administrator or increase reward"
const unknown_lp_contract = "This farm works with a different LP token"
const unknown_smak_contract = "Cannot connect to the SMAK contract"
const unknown_user_claim = "You do not have any reward to claim"
const unknown_user_unstake = "You do not have any LP token to unstake"
const farm_empty_week = "Farm has no cumulated stake for one week"
const amount_is_null = "The staking amount must be greater than zero"
const amount_must_be_zero_tez = "You must not send Tezos to the smart contract"
const time_too_early = "Please try again in few seconds"
const no_stakes = "You did not stake any token yet"
const unstake_more_than_stake = "You cannot unstake more than your staking"
const user_no_points = "You do not have or no longer have any rewards"
const rewards_sent_but_missing_points = "You do not have any reward to claim"
const no_week_left = "There are no more weeks left for staking"
type week = nat
type storage_farm =
record[admin -> address , creation_time -> timestamp , farm_points -> map (nat , nat) , lp_token_address -> address , rate -> nat , reserve_address -> address , reward_at_week -> map (nat , nat) , smak_address -> address , total_reward -> nat , user_points -> big_map (address , map (nat , nat)) , user_stakes -> big_map (address , nat) , weeks -> nat]
const noOperations = LIST_EMPTY()
type return =
( list (operation) * record[admin -> address , creation_time -> timestamp , farm_points -> map (nat , nat) , lp_token_address -> address , rate -> nat , reserve_address -> address , reward_at_week -> map (nat , nat) , smak_address -> address , total_reward -> nat , user_points -> big_map (address , map (nat , nat)) , user_stakes -> big_map (address , nat) , weeks -> nat] )
const week_in_seconds = +604800
type smak_transfer =
( address * ( address * nat ) )
type stake_param = nat
type reward_param = nat
type entrypoint =
sum[ClaimAll -> unit , IncreaseReward -> nat , SetAdmin -> address , Stake -> nat , Unstake -> nat]
type transfer =
record[address_from -> address , address_to -> address , value -> nat]
type approve =
record[spender -> address , value -> nat]
type mintOrBurn =
record[quantity -> int , target -> address]
type allowance_key =
record[owner -> address , spender -> address]
type getAllowance =
record[callback -> contract (nat) , request -> record[owner -> address , spender -> address]]
type getBalance =
record[callback -> contract (nat) , owner -> address]
type getTotalSupply =
record[callback -> contract (nat) , request -> unit]
type tokens = big_map (address ,
nat)
type allowances = big_map (
record[owner -> address , spender -> address] ,
nat)
type token_metadata_entry =
record[token_id -> nat , token_info -> map (string , bytes)]
type storage =
record[admin -> address , allowances -> big_map (record[owner -> address , spender -> address] , nat) , metadata -> big_map (string , bytes) , token_metadata -> big_map (nat , record[token_id -> nat , token_info -> map (string , bytes)]) , tokens -> big_map (address , nat) , total_supply -> nat]
type parameter =
sum[Approve -> record[spender -> address , value -> nat] , GetAllowance -> record[callback -> contract (nat) , request -> record[owner -> address , spender -> address]] , GetBalance -> record[callback -> contract (nat) , owner -> address] , GetTotalSupply -> record[callback -> contract (nat) , request -> unit] , MintOrBurn -> record[quantity -> int , target -> address] , Transfer -> record[address_from -> address , address_to -> address , value -> nat]]
type result =
( list (operation) * record[admin -> address , allowances -> big_map (record[owner -> address , spender -> address] , nat) , metadata -> big_map (string , bytes) , token_metadata -> big_map (nat , record[token_id -> nat , token_info -> map (string , bytes)]) , tokens -> big_map (address , nat) , total_supply -> nat] )
const maybe = lambda (n) return let #331 = EQ(n ,
+0) in
match
#331 with
| False unit_proj#332 ->
SOME(n)
| True unit_proj#333 ->
NONE()[@inline]
const transfer = lambda (param) return lambda (storage) return let allowances = storage.allowances in let tokens = storage.tokens in let allowances = let #334 = EQ(SENDER() ,
param.address_from) in
match
#334 with
| False unit_proj#335 ->
let allowance_key =
record[owner -> param.address_from , spender -> SENDER()] in let authorized_value = let #336 = MAP_FIND_OPT(allowance_key ,
allowances) in
match
#336 with
| Some value ->
value
| None unit_proj#337 ->
+0 in let authorized_value = let #338 = IS_NAT(SUB(authorized_value ,
param.value)) in
match
#338 with
| Some authorized_value ->
authorized_value
| None unit_proj#339 ->
FAILWITH("NotEnoughAllowance") in MAP_UPDATE(allowance_key ,
(maybe)@(authorized_value) ,
allowances)
| True unit_proj#340 ->
allowances in let tokens = let from_balance = let #341 = MAP_FIND_OPT(param.address_from ,
tokens) in
match
#341 with
| Some value ->
value
| None unit_proj#342 ->
+0 in let from_balance = let #343 = IS_NAT(SUB(from_balance ,
param.value)) in
match
#343 with
| Some from_balance ->
from_balance
| None unit_proj#344 ->
FAILWITH("NotEnoughBalance") in MAP_UPDATE(param.address_from ,
(maybe)@(from_balance) ,
tokens) in let tokens = let to_balance = let #345 = MAP_FIND_OPT(param.address_to ,
tokens) in
match
#345 with
| Some value ->
value
| None unit_proj#346 ->
+0 in let to_balance = ADD(to_balance ,
param.value) in MAP_UPDATE(param.address_to ,
(maybe)@(to_balance) ,
tokens) in
( LIST_EMPTY() , { { storage with { tokens = tokens } } with { allowances = allowances } } )
const approve = lambda (param) return lambda (storage) return let allowances = storage.allowances in let allowance_key =
record[owner -> SENDER() , spender -> param.spender] in let previous_value = let #347 = MAP_FIND_OPT(allowance_key ,
allowances) in
match
#347 with
| Some value ->
value
| None unit_proj#348 ->
+0 in let _ = let #349 = AND(GT(previous_value ,
+0) ,
GT(param.value ,
+0)) in
match
#349 with
| False unit_proj#350 ->
unit
| True unit_proj#351 ->
FAILWITH("UnsafeAllowanceChange") in let allowances = MAP_UPDATE(allowance_key ,
(maybe)@(param.value) ,
allowances) in
( LIST_EMPTY() , { storage with { allowances = allowances } } )
const mintOrBurn = lambda (param) return lambda (storage) return let _ = let #352 = NEQ(SENDER() ,
storage.admin) in
match
#352 with
| False unit_proj#353 ->
unit
| True unit_proj#354 ->
FAILWITH("OnlyAdmin") in let tokens = storage.tokens in let old_balance = let #355 = MAP_FIND_OPT(param.target ,
tokens) in
match
#355 with
| Some bal ->
bal
| None unit_proj#356 ->
+0 in let new_balance = let #357 = IS_NAT(ADD(old_balance ,
param.quantity)) in
match
#357 with
| Some bal ->
bal
| None unit_proj#358 ->
FAILWITH("Cannot burn more than the target's balance.") in let tokens = MAP_UPDATE(param.target ,
(maybe)@(new_balance) ,
storage.tokens) in let total_supply = ABS(ADD(storage.total_supply ,
param.quantity)) in
( LIST_EMPTY() , { { storage with { tokens = tokens } } with { total_supply = total_supply } } )
const getAllowance = lambda (param) return lambda (storage) return let value = let #359 = MAP_FIND_OPT(param.request ,
storage.allowances) in
match
#359 with
| Some value ->
value
| None unit_proj#360 ->
+0 in CONS(CALL(value ,
0mutez ,
param.callback) ,
LIST_EMPTY())
const getBalance = lambda (param) return lambda (storage) return let value = let #361 = MAP_FIND_OPT(param.owner ,
storage.tokens) in
match
#361 with
| Some value ->
value
| None unit_proj#362 ->
+0 in CONS(CALL(value ,
0mutez ,
param.callback) ,
LIST_EMPTY())
const getTotalSupply = lambda (param) return lambda (storage) return let total = storage.total_supply in CONS(CALL(total ,
0mutez ,
param.callback) ,
LIST_EMPTY())
const main = lambda (#191) return let #363 = #191 in
match
#363 with
| ( param , storage ) ->
let _ = let #365 = NEQ(AMOUNT() ,
0mutez) in
match
#365 with
| False unit_proj#366 ->
unit
| True unit_proj#367 ->
FAILWITH("DontSendTez") in let #368 = param in
match
#368 with
| Approve param ->
((approve)@(param))@(storage)
| GetAllowance param ->
( ((getAllowance)@(param))@(storage) , storage )
| GetBalance param ->
( ((getBalance)@(param))@(storage) , storage )
| GetTotalSupply param ->
( ((getTotalSupply)@(param))@(storage) , storage )
| MintOrBurn param ->
((mintOrBurn)@(param))@(storage)
| Transfer param ->
((transfer)@(param))@(storage)
const setAdmin = lambda (#192) return let #369 = #192 in
match
#369 with
| ( admin , s ) ->
let _check_if_no_tez = let #371 = EQ(AMOUNT() ,
0mutez) in
match
#371 with
| False unit_proj#372 ->
FAILWITH(amount_must_be_zero_tez)
| True unit_proj#373 ->
TRUE() in let new_admin = let #374 = EQ(SENDER() ,
s.admin) in
match
#374 with
| False unit_proj#375 ->
FAILWITH(only_admin)
| True unit_proj#376 ->
admin in
( noOperations , { s with { admin = new_admin } } )
const get_current_week = lambda (s) return let delay = ABS(SUB(NOW() ,
s.creation_time)) in ADD(DIV(delay ,
week_in_seconds) ,
+1)
const get_weeks_indices = lambda (#194) return let #377 = #194 in
match
#377 with
| ( first , last ) ->
let append = rec (append:
( list (nat) * nat * nat ) -> list (nat) => lambda (#193) return let #379 = #193 in
match
#379 with
|
( acc , elt , last ) ->
let #381 = LE(elt ,
last) in
match
#381 with
| False unit_proj#382 ->
acc
| True unit_proj#383 ->
(append)@(
( CONS(elt , acc) , ADD(elt , +1) , last )) ) in (append)@(
( LIST_EMPTY() , first , last ))
const get_weeks_indices_as_set = lambda (#196) return let #384 = #196 in
match
#384 with
| ( first , last ) ->
let append = rec (append:
( set (nat) * nat * nat ) -> set (nat) => lambda (#195) return let #386 = #195 in
match
#386 with
|
( acc , elt , last ) ->
let #388 = LE(elt ,
last) in
match
#388 with
| False unit_proj#389 ->
acc
| True unit_proj#390 ->
(append)@(
( SET_ADD(elt , acc) , ADD(elt , +1) , last )) ) in (append)@(
( SET_EMPTY() , first , last ))
const stakeSome = lambda (#201) return let #391 = #201 in
match
#391 with
| ( lp_amount , s ) ->
let _check_if_no_tez = let #393 = EQ(AMOUNT() ,
0mutez) in
match
#393 with
| False unit_proj#394 ->
FAILWITH(amount_must_be_zero_tez)
| True unit_proj#395 ->
TRUE() in let _check_amount_positive = let #396 = GT(lp_amount ,
+0) in
match
#396 with
| False unit_proj#397 ->
FAILWITH(amount_is_null)
| True unit_proj#398 ->
TRUE() in let _check_current_week = let #399 = LT(NOW() ,
ADD(s.creation_time ,
INT(MUL(s.weeks ,
week_in_seconds)))) in
match
#399 with
| False unit_proj#400 ->
FAILWITH(no_week_left)
| True unit_proj#401 ->
TRUE() in let lp_contract_opt = CONTRACT_OPT(s.lp_token_address) in let lp_contract = let #402 = lp_contract_opt in
match
#402 with
| Some x ->
x
| None unit_proj#403 ->
FAILWITH(unknown_lp_contract) in let transfer_param =
record[address_from -> SENDER() , address_to -> SELF_ADDRESS() , value -> lp_amount] in let op = CALL(Transfer(transfer_param) ,
0mutez ,
lp_contract) in let ops = CONS(op ,
LIST_EMPTY()) in let existing_bal_opt = MAP_FIND_OPT(SENDER() ,
s.user_stakes) in let new_user_stakes = let #404 = existing_bal_opt in
match
#404 with
| Some v ->
MAP_UPDATE(SENDER() ,
SOME(ADD(lp_amount ,
v)) ,
s.user_stakes)
| None unit_proj#405 ->
MAP_ADD(SENDER() ,
lp_amount ,
s.user_stakes) in let current_week = (get_current_week)@(s) in let endofweek_in_seconds = ADD(s.creation_time ,
INT(MUL(current_week ,
week_in_seconds))) in let _check_negative = let #406 = LT(SUB(NOW() ,
endofweek_in_seconds) ,
0) in
match
#406 with
| False unit_proj#407 ->
FAILWITH(time_too_early)
| True unit_proj#408 ->
TRUE() in let before_end_week = ABS(SUB(NOW() ,
endofweek_in_seconds)) in let points_current_week = MUL(before_end_week ,
lp_amount) in let points_next_weeks = MUL(week_in_seconds ,
lp_amount) in let user_weeks_opt = MAP_FIND_OPT(SENDER() ,
s.user_points) in let new_user_points = let #409 = user_weeks_opt in
match
#409 with
| Some m ->
let modified_current_week = let #410 = MAP_FIND_OPT(current_week ,
m) in
match
#410 with
| Some wpts ->
MAP_UPDATE(current_week ,
SOME(ADD(points_current_week ,
wpts)) ,
m)
| None unit_proj#411 ->
MAP_ADD(current_week ,
points_current_week ,
MAP_EMPTY()) in MAP_UPDATE(SENDER() ,
SOME(modified_current_week) ,
s.user_points)
| None unit_proj#412 ->
MAP_ADD(SENDER() ,
MAP_ADD(current_week ,
points_current_week ,
MAP_EMPTY()) ,
s.user_points) in let new_farm_points = let #413 = MAP_FIND_OPT(current_week ,
s.farm_points) in
match
#413 with
| Some val_ ->
MAP_UPDATE(current_week ,
SOME(ADD(val_ ,
points_current_week)) ,
s.farm_points)
| None unit_proj#414 ->
MAP_ADD(current_week ,
points_current_week ,
s.farm_points) in let future_weeks = (get_weeks_indices)@(
( ADD(current_week , +1) , s.weeks )) in let update_user_points_func = lambda (#200) return let #415 = #200 in
match
#415 with
|
( a , v , i , m ) ->
let #417 = MAP_FIND_OPT(a ,
m) in
match
#417 with
| Some weeks_map ->
let new_weeks_map = let #418 = MAP_FIND_OPT(i ,
weeks_map) in
match
#418 with
| Some value ->
MAP_UPDATE(i ,
SOME(ADD(value ,
v)) ,
weeks_map)
| None unit_proj#419 ->
MAP_ADD(i ,
v ,
weeks_map) in MAP_UPDATE(a ,
SOME(new_weeks_map) ,
m)
| None unit_proj#420 ->
MAP_ADD(SENDER() ,
MAP_ADD(i ,
v ,
MAP_EMPTY()) ,
m) in let modify_user_points_func = rec (modify_user_points_func:
( big_map (address , map (nat , nat)) * nat * list (nat) ) -> big_map (address ,
map (nat ,
nat)) => lambda (#199) return let #421 = #199 in
match
#421 with
|
( resulting_acc , modificateur , weeks_indices ) ->
let week_indice_opt = LIST_HEAD_OPT(weeks_indices) in let #423 = week_indice_opt in
match
#423 with
| Some week_indice ->
let modified = (update_user_points_func)@(
( SENDER() , modificateur , week_indice , resulting_acc )) in let remaining_weeks_opt = LIST_TAIL_OPT(weeks_indices) in let remaining_weeks = let #424 = remaining_weeks_opt in
match
#424 with
| Some l ->
l
| None unit_proj#425 ->
LIST_EMPTY() in (modify_user_points_func)@(
( modified , modificateur , remaining_weeks ))
| None unit_proj#426 ->
resulting_acc ) in let final_user_points = (modify_user_points_func)@(
( new_user_points , points_next_weeks , future_weeks )) in let update_farm_points_func = lambda (#198) return let #427 = #198 in
match
#427 with
|
( v , i , m ) ->
let #429 = MAP_FIND_OPT(i ,
m) in
match
#429 with
| Some entry ->
MAP_UPDATE(i ,
SOME(ADD(entry ,
v)) ,
m)
| None unit_proj#430 ->
MAP_ADD(i ,
v ,
m) in let modify_farm_points_func = rec (modify_farm_points_func:
( map (nat , nat) * nat * list (nat) ) -> map (nat ,
nat) => lambda (#197) return let #431 = #197 in
match
#431 with
|
( farm_result , delta , weeks_indices ) ->
let week_indice_opt = LIST_HEAD_OPT(weeks_indices) in let #433 = week_indice_opt in
match
#433 with
| Some week_indice ->
let modified = (update_farm_points_func)@(
( delta , week_indice , farm_result )) in let remaining_weeks_opt = LIST_TAIL_OPT(weeks_indices) in let remaining_weeks = let #434 = remaining_weeks_opt in
match
#434 with
| Some l ->
l
| None unit_proj#435 ->
LIST_EMPTY() in (modify_farm_points_func)@(
( modified , delta , remaining_weeks ))
| None unit_proj#436 ->
farm_result ) in let final_farm_points = (modify_farm_points_func)@(
( new_farm_points , points_next_weeks , future_weeks )) in
( ops , { { { s with { user_stakes = new_user_stakes } } with { user_points = final_user_points } } with { farm_points = final_farm_points } } )
const unstakeSome = lambda (#206) return let #437 = #206 in
match
#437 with
| ( lp_amount , s ) ->
let _check_if_no_tez = let #439 = EQ(AMOUNT() ,
0mutez) in
match
#439 with
| False unit_proj#440 ->
FAILWITH(amount_must_be_zero_tez)
| True unit_proj#441 ->
TRUE() in let existing_bal_opt = MAP_FIND_OPT(SENDER() ,
s.user_stakes) in let new_user_stakes = let #442 = existing_bal_opt in
match
#442 with
| Some v ->
let #443 = GE(v ,
lp_amount) in
match
#443 with
| False unit_proj#444 ->
FAILWITH(unstake_more_than_stake)
| True unit_proj#445 ->
MAP_UPDATE(SENDER() ,
SOME(ABS(SUB(v ,
lp_amount))) ,
s.user_stakes)
| None unit_proj#446 ->
FAILWITH(no_stakes) in let lp_contract_opt = CONTRACT_OPT(s.lp_token_address) in let lp_contract = let #447 = lp_contract_opt in
match
#447 with
| Some x ->
x
| None unit_proj#448 ->
FAILWITH(unknown_lp_contract) in let transfer_param =
record[address_from -> SELF_ADDRESS() , address_to -> SENDER() , value -> lp_amount] in let op = CALL(Transfer(transfer_param) ,
0mutez ,
lp_contract) in let ops = CONS(op ,
LIST_EMPTY()) in let #449 = LT(SUB(SUB(NOW() ,
s.creation_time) ,
MUL(s.weeks ,
week_in_seconds)) ,
0) in
match
#449 with
| False unit_proj#450 ->
( ops , { s with { user_stakes = new_user_stakes } } )
| True unit_proj#451 ->
let current_week = (get_current_week)@(s) in let endofweek_in_seconds = ADD(s.creation_time ,
INT(MUL(current_week ,
week_in_seconds))) in let _check_negative = let #452 = LT(SUB(NOW() ,
endofweek_in_seconds) ,
0) in
match
#452 with
| False unit_proj#453 ->
FAILWITH(time_too_early)
| True unit_proj#454 ->
TRUE() in let before_end_week = ABS(SUB(NOW() ,
endofweek_in_seconds)) in let points_current_week = MUL(before_end_week ,
lp_amount) in let points_next_weeks = MUL(week_in_seconds ,
lp_amount) in let user_weeks_opt = MAP_FIND_OPT(SENDER() ,
s.user_points) in let new_user_points = let #455 = user_weeks_opt in
match
#455 with
| Some m ->
let modified_current_week = let #456 = MAP_FIND_OPT(current_week ,
m) in
match
#456 with
| Some wpts ->
MAP_UPDATE(current_week ,
SOME(ABS(SUB(wpts ,
points_current_week))) ,
m)
| None unit_proj#457 ->
FAILWITH(user_no_points) in MAP_UPDATE(SENDER() ,
SOME(modified_current_week) ,
s.user_points)
| None unit_proj#458 ->
FAILWITH(user_no_points) in let new_farm_points = let #459 = MAP_FIND_OPT(current_week ,
s.farm_points) in
match
#459 with
| Some val_ ->
MAP_UPDATE(current_week ,
SOME(ABS(SUB(val_ ,
points_current_week))) ,
s.farm_points)
| None unit_proj#460 ->
FAILWITH(user_no_points) in let future_weeks = (get_weeks_indices)@(
( ADD(current_week , +1) , s.weeks )) in let update_user_points_func = lambda (#205) return let #461 = #205 in
match
#461 with
| ( a , v , i , m ) ->
let #463 = MAP_FIND_OPT(a ,
m) in
match
#463 with
| Some weeks_map ->
let new_weeks_map = let #464 = MAP_FIND_OPT(i ,
weeks_map) in
match
#464 with
| Some value ->
MAP_UPDATE(i ,
SOME(ABS(SUB(value ,
v))) ,
weeks_map)
| None unit_proj#465 ->
FAILWITH(unknown_user_unstake) in MAP_UPDATE(a ,
SOME(new_weeks_map) ,
m)
| None unit_proj#466 ->
FAILWITH(unknown_user_unstake) in let modify_user_points_func = rec (modify_user_points_func:
( big_map (address , map (nat , nat)) * nat * list (nat) ) -> big_map (address ,
map (nat ,
nat)) => lambda (#204) return let #467 = #204 in
match
#467 with
| ( resulting_acc , modificateur , weeks_indices ) ->
let week_indice_opt = LIST_HEAD_OPT(weeks_indices) in let #469 = week_indice_opt in
match
#469 with
| Some week_indice ->
let modified = (update_user_points_func)@(
( SENDER() , modificateur , week_indice , resulting_acc )) in let remaining_weeks_opt = LIST_TAIL_OPT(weeks_indices) in let remaining_weeks = let #470 = remaining_weeks_opt in
match
#470 with
| Some l ->
l
| None unit_proj#471 ->
LIST_EMPTY() in (modify_user_points_func)@(
( modified , modificateur , remaining_weeks ))
| None unit_proj#472 ->
resulting_acc ) in let final_user_points = (modify_user_points_func)@(
( new_user_points , points_next_weeks , future_weeks )) in let update_farm_points_func = lambda (#203) return let #473 = #203 in
match
#473 with
| ( v , i , m ) ->
let #475 = MAP_FIND_OPT(i ,
m) in
match
#475 with
| Some entry ->
MAP_UPDATE(i ,
SOME(ABS(SUB(entry ,
v))) ,
m)
| None unit_proj#476 ->
FAILWITH(user_no_points) in let modify_farm_points_func = rec (modify_farm_points_func:
( map (nat , nat) * nat * list (nat) ) -> map (nat ,
nat) => lambda (#202) return let #477 = #202 in
match
#477 with
| ( farm_result , delta , weeks_indices ) ->
let week_indice_opt = LIST_HEAD_OPT(weeks_indices) in let #479 = week_indice_opt in
match
#479 with
| Some week_indice ->
let modified = (update_farm_points_func)@(
( delta , week_indice , farm_result )) in let remaining_weeks_opt = LIST_TAIL_OPT(weeks_indices) in let remaining_weeks = let #480 = remaining_weeks_opt in
match
#480 with
| Some l ->
l
| None unit_proj#481 ->
LIST_EMPTY() in (modify_farm_points_func)@(
( modified , delta , remaining_weeks ))
| None unit_proj#482 ->
farm_result ) in let final_farm_points = (modify_farm_points_func)@(
( new_farm_points , points_next_weeks , future_weeks )) in
( ops , { { { s with { user_stakes = new_user_stakes } } with { user_points = final_user_points } } with { farm_points = final_farm_points } } )
const sendReward = lambda (#207) return let #483 = #207 in
match
#483 with
| ( token_amount , user_address , s ) ->
let smak_contract_otp = CONTRACT_ENTRYPOINT_OPT("%transfer" ,
s.smak_address) in let transfer_smak = let #485 = smak_contract_otp in
match
#485 with
| Some c ->
c
| None unit_proj#486 ->
FAILWITH(unknown_smak_contract) in let transfer_param =
( s.reserve_address , ( user_address , token_amount ) ) in let op = CALL(transfer_param ,
0mutez ,
transfer_smak) in op
const power = lambda (#209) return let #487 = #209 in
match
#487 with
| ( x , y ) ->
let multiply = rec (multiply:
( nat * nat * nat ) -> nat => lambda (#208) return let #489 = #208 in
match
#489 with
|
( acc , elt , last ) ->
let #491 = EQ(last ,
+0) in
match
#491 with
| False unit_proj#492 ->
(multiply)@(
( MUL(acc , elt) , elt , ABS(SUB(last , +1)) ))
| True unit_proj#493 ->
acc ) in (multiply)@(
( +1 , x , y ))
const computeReward = lambda (#212) return let #494 = #212 in
match
#494 with
| ( offset , s ) ->
let weeks = (get_weeks_indices)@(
( +1 , s.weeks )) in let update_reward_per_week_func = lambda (#211) return let #496 = #211 in
match
#496 with
|
( week_indice , rate , weeks_max , reward_total , map_accumulator ) ->
let t_before = (power)@(
( rate , ABS(SUB(week_indice , +1)) )) in let t_before_divisor = (power)@(
( +10000 , ABS(SUB(week_indice , +1)) )) in let un_moins_rate = ABS(SUB(+10000 ,
rate)) in let m_10000_4 = (power)@(
( +10000 , ABS(SUB(weeks_max , +1)) )) in let numerator = MUL(un_moins_rate ,
m_10000_4) in let t_I_max = (power)@(
( rate , weeks_max )) in let m_10000_5 = (power)@(
( +10000 , weeks_max )) in let denominator = ABS(SUB(m_10000_5 ,
t_I_max)) in let final_denominator = MUL(t_before_divisor ,
denominator) in let final_numerator = MUL(MUL(numerator ,
reward_total) ,
t_before) in let result = DIV(final_numerator ,
final_denominator) in let value_opt = MAP_FIND_OPT(ADD(week_indice ,
offset) ,
map_accumulator) in let new_map = let #498 = value_opt in
match
#498 with
| Some _v ->
MAP_UPDATE(ADD(week_indice ,
offset) ,
SOME(result) ,
map_accumulator)
| None unit_proj#499 ->
MAP_ADD(ADD(week_indice ,
offset) ,
result ,
map_accumulator) in new_map in let modify_rewards_func = rec (modify_rewards_func:
( map (nat , nat) * list (nat) ) -> map (nat ,
nat) => lambda (#210) return let #500 = #210 in
match
#500 with
|
( resulting_acc , weeks_indices ) ->
let week_indice_opt = LIST_HEAD_OPT(weeks_indices) in let #502 = week_indice_opt in
match
#502 with
| Some week_indice ->
let modified = (update_reward_per_week_func)@(
( week_indice , s.rate , s.weeks , s.total_reward , resulting_acc )) in let remaining_weeks_opt = LIST_TAIL_OPT(weeks_indices) in let remaining_weeks = let #503 = remaining_weeks_opt in
match
#503 with
| Some l ->
l
| None unit_proj#504 ->
LIST_EMPTY() in (modify_rewards_func)@(
( modified , remaining_weeks ))
| None unit_proj#505 ->
resulting_acc ) in let final_rewards = (modify_rewards_func)@(
( s.reward_at_week , weeks )) in { s with { reward_at_week = final_rewards } }
const increaseReward = lambda (#214) return let #506 = #214 in
match
#506 with
| ( value , s ) ->
let _check_if_admin = let #508 = EQ(SENDER() ,
s.admin) in
match
#508 with
| False unit_proj#509 ->
FAILWITH(only_admin)
| True unit_proj#510 ->
TRUE() in let _check_if_no_tez = let #511 = EQ(AMOUNT() ,
0mutez) in
match
#511 with
| False unit_proj#512 ->
FAILWITH(amount_must_be_zero_tez)
| True unit_proj#513 ->
TRUE() in let current_week = (get_current_week)@(s) in let _check_current_week = let #514 = LT(NOW() ,
ADD(s.creation_time ,
INT(MUL(s.weeks ,
week_in_seconds)))) in
match
#514 with
| False unit_proj#515 ->
FAILWITH(no_week_left)
| True unit_proj#516 ->
TRUE() in let delta = value in let weeks_set = (get_weeks_indices_as_set)@(
( current_week , s.weeks )) in let initialized_creation_time = let #517 = EQ(delta ,
+0) in
match
#517 with
| False unit_proj#518 ->
s.creation_time
| True unit_proj#519 ->
NOW() in let folded = lambda (#213) return let #520 = #213 in
match
#520 with
|
( acc , elt ) ->
let #522 = SET_MEM(elt.0 ,
weeks_set) in
match
#522 with
| False unit_proj#523 ->
ADD(acc ,
elt.1)
| True unit_proj#524 ->
acc in let sum_R = MAP_FOLD(folded ,
s.reward_at_week ,
+0) in let new_r_total = ADD(delta ,
ABS(SUB(s.total_reward ,
sum_R))) in let new_i_max = ABS(ADD(SUB(s.weeks ,
current_week) ,
+1)) in let new_storage = { { { s with { weeks = new_i_max } } with { total_reward = new_r_total } } with { creation_time = initialized_creation_time } } in let new_reward_storage = (computeReward)@(
( ABS(SUB(current_week , +1)) , new_storage )) in let final_reward = ADD(s.total_reward ,
value) in let final_weeks = s.weeks in
( noOperations , { { new_reward_storage with { total_reward = final_reward } } with { weeks = final_weeks } } )
const claimAll = lambda (s) return let _check_if_no_tez = let #525 = EQ(AMOUNT() ,
0mutez) in
match
#525 with
| False unit_proj#526 ->
FAILWITH(amount_must_be_zero_tez)
| True unit_proj#527 ->
TRUE() in let current_week = (get_current_week)@(s) in let precision = +100000000 in let weeks = let #528 = GT(current_week ,
s.weeks) in
match
#528 with
| False unit_proj#529 ->
(get_weeks_indices)@(
( +1 , ABS(SUB(current_week , +1)) ))
| True unit_proj#530 ->
(get_weeks_indices)@(
( +1 , s.weeks )) in let compute_percentage_func = lambda (#220) return let #531 = #220 in
match
#531 with
| ( week_indice , map_accumulator ) ->
let points = let #533 = MAP_FIND_OPT(SENDER() ,
s.user_points) in
match
#533 with
| Some week_points_map ->
let val_opt = MAP_FIND_OPT(week_indice ,
week_points_map) in let computed_value = let #534 = val_opt in
match
#534 with
| Some v ->
v
| None unit_proj#535 ->
+0 in computed_value
| None unit_proj#536 ->
FAILWITH(unknown_user_claim) in let farm_points = let #537 = MAP_FIND_OPT(week_indice ,
s.farm_points) in
match
#537 with
| Some val_ ->
val_
| None unit_proj#538 ->
+0 in let #539 = EQ(farm_points ,
+0) in
match
#539 with
| False unit_proj#540 ->
let perc = let #541 = EQ(points ,
+0) in
match
#541 with
| False unit_proj#542 ->
DIV(MUL(points ,
precision) ,
farm_points)
| True unit_proj#543 ->
+0 in let #544 = EQ(perc ,
+0) in
match
#544 with
| False unit_proj#545 ->
let #546 = MAP_FIND_OPT(SENDER() ,
map_accumulator) in
match
#546 with
| Some wks ->
let modified_wks = MAP_ADD(week_indice ,
perc ,
wks) in MAP_UPDATE(SENDER() ,
SOME(modified_wks) ,
map_accumulator)
| None unit_proj#547 ->
let modified_wks = MAP_ADD(week_indice ,
perc ,
MAP_EMPTY()) in MAP_ADD(SENDER() ,
modified_wks ,
map_accumulator)
| True unit_proj#548 ->
map_accumulator
| True unit_proj#549 ->
map_accumulator in let compute_func = rec (compute_func:
( map (address , map (nat , nat)) * list (nat) ) -> map (address ,
map (nat ,
nat)) => lambda (#219) return let #550 = #219 in
match
#550 with
| ( acc , indices ) ->
let indice_opt = LIST_HEAD_OPT(indices) in let #552 = indice_opt in
match
#552 with
| Some week_indice ->
let modified_acc = (compute_percentage_func)@(
( week_indice , acc )) in let remaining_indices_opt = LIST_TAIL_OPT(indices) in let remaining_indices = let #553 = remaining_indices_opt in
match
#553 with
| Some l ->
l
| None unit_proj#554 ->
LIST_EMPTY() in (compute_func)@(
( modified_acc , remaining_indices ))
| None unit_proj#555 ->
acc ) in let percentages = (compute_func)@(
( MAP_EMPTY() , weeks )) in let compute_and_send_func = lambda (#218) return let #556 = #218 in
match
#556 with
| ( ops , i ) ->
let send_reward_func = lambda (#217) return let #558 = #217 in
match
#558 with
|
( acc , elt ) ->
let #560 = elt in
match
#560 with
|
( week_indice , percent ) ->
let reward_for_week = let #562 = MAP_FIND_OPT(week_indice ,
s.reward_at_week) in
match
#562 with
| Some rwwk ->
rwwk
| None unit_proj#563 ->
+0 in let amount_to_send = DIV(MUL(reward_for_week ,
percent) ,
precision) in CONS((sendReward)@(
( amount_to_send , SENDER() , s )) ,
acc) in MAP_FOLD(send_reward_func ,
i.1 , ops) in let operations = MAP_FOLD(compute_and_send_func ,
percentages ,
LIST_EMPTY()) in let remove_points = lambda (#216) return let #564 = #216 in
match
#564 with
| ( acc , percentages_i ) ->
let user = percentages_i.0 in let percs = percentages_i.1 in let rem = lambda (#215) return let #566 = #215 in
match
#566 with
|
( week_points , j ) ->
let week_indice = j.0 in let #568 = MAP_FIND_OPT(week_indice ,
week_points) in
match
#568 with
| Some _pts ->
MAP_UPDATE(week_indice ,
SOME(+0) ,
week_points)
| None unit_proj#569 ->
week_points in let week_points_for_user = let #570 = MAP_FIND_OPT(user ,
acc) in
match
#570 with
| Some wk_pts ->
wk_pts
| None unit_proj#571 ->
FAILWITH(rewards_sent_but_missing_points) in let new_week_points = MAP_FOLD(rem ,
percs ,
week_points_for_user) in let modified_map = MAP_UPDATE(user ,
SOME(new_week_points) ,
acc) in modified_map in let remove_points_map = MAP_FOLD(remove_points ,
percentages ,
s.user_points) in
( operations , { s with { user_points = remove_points_map } } )
module Farm = auditFarm/contract/main/../partials/FarmMethods.mligo
const main = lambda (#328) return let #572 = #328 in match #572 with
| ( action , s ) ->
let #574 = action in
match #574 with
| ClaimAll unit_proj#575 ->
(Farm.claimAll)@(s)
| IncreaseReward value ->
(Farm.increaseReward)@(
( value , s ))
| SetAdmin admin ->
(Farm.setAdmin)@(
( admin , s ))
| Stake value ->
(Farm.stakeSome)@(
( value , s ))
| Unstake value ->
(Farm.unstakeSome)@(
( value , s ))
Edited by Pierre-Emmanuel Wulfman