Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #26 from ZkPad-Labs/filip/new_investment_strategies
Browse files Browse the repository at this point in the history
Add Staking Vault w/ full testing coverage
  • Loading branch information
EvolveArt authored May 31, 2022
2 parents 7031910 + 7b2e248 commit 6a1c198
Show file tree
Hide file tree
Showing 24 changed files with 3,538 additions and 876 deletions.
4 changes: 3 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
repos:
- repo: https://github.com/franalgaba/pre-commit-cairo
rev: main # Use the ref you want to point at
rev: 170457cda19bad99676876b82f139b437c5e84fa # Use the ref you want to point at
hooks:
- id: cairo-lint
- id: cairo-format
118 changes: 118 additions & 0 deletions InterfaceAll.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
%lang starknet
from starkware.cairo.common.uint256 import Uint256

struct UserInfo:
member amount : Uint256
member reward_debt : Uint256
end

struct Purchase_Round:
member time_starts : felt
member time_ends : felt
Expand Down Expand Up @@ -43,6 +48,12 @@ namespace IZkPadIDOContract:
end
end

@contract_interface
namespace IAccount:
func is_valid_signature(hash : felt, sig_len : felt, sig : felt*) -> ():
end
end

@contract_interface
namespace IZKPadIDOFactory:
func get_ido_launch_date(id : felt) -> (res : felt):
Expand Down Expand Up @@ -190,6 +201,9 @@ namespace IERC20:

func approve(spender : felt, amount : Uint256) -> (success : felt):
end

func mint(to : felt, amount : Uint256):
end
end

const XOROSHIRO_ADDR = 0x0236b6c5722c5b5e78c215d72306f642de0424a6b56f699d43c98683bea7460d
Expand Down Expand Up @@ -217,3 +231,107 @@ namespace ITask:
func setIDOContractAddress(address : felt) -> ():
end
end

@contract_interface
namespace IVault:
func feePercent() -> (fee_percent : felt):
end

func lockedProfit() -> (res : Uint256):
end

func harvestDelay() -> (harvest_delay : felt):
end

func harvestWindow() -> (harvest_window : felt):
end

func targetFloatPercent() -> (float_percent : felt):
end

func canHarvest() -> (yes_no : felt):
end

func lastHarvestWindowStart() -> (last_harvest_window_start : felt):
end

func getWithdrawalStack() -> (strategies_len : felt, strategies : felt*):
end

func rewardPerBlock() -> (reward : Uint256):
end

func startBlock() -> (block : felt):
end

func endBlock() -> (block : felt):
end

func lastRewardBlock() -> (block : felt):
end

func accTokenPerShare() -> (res : Uint256):
end

func getMultiplier(_from : felt, _to : felt) -> (multiplier : felt):
end

func userInfo(user : felt) -> (info : UserInfo):
end

func totalFloat() -> (float : Uint256):
end

func harvest(strategies_len : felt, strategies : felt*):
end

func setFeePercent(new_fee_percent : felt):
end

func setHarvestDelay(new_harvest_delay : felt):
end

func setHarvestWindow(new_harvest_window : felt):
end

func setTargetFloatPercent(float_percent : felt):
end

func setHarvestTaskContract(address : felt):
end

func updateRewardPerBlockAndEndBlock(_reward_per_block : Uint256, new_end_block : felt):
end

func initializer(
name : felt,
symbol : felt,
asset_addr : felt,
owner : felt,
reward_per_block : Uint256,
start_reward_block : felt,
end_reward_block : felt,
):
end

func harvestRewards():
end

func calculatePendingRewards(user : felt) -> (rewards : Uint256):
end

func pushToWithdrawalStack(strategy : felt):
end

func popFromWithdrawalStack():
end

func setWithdrawalStack(stack_len : felt, stack : felt*):
end

func replaceWithdrawalStackIndex(index : felt, address : felt):
end

func swapWithdrawalStackIndexes(index1 : felt, index2 : felt):
end
end
22 changes: 19 additions & 3 deletions contracts/ZkPadLotteryToken.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%lang starknet

from starkware.cairo.common.cairo_builtins import HashBuiltin
from starkware.cairo.common.cairo_builtins import HashBuiltin, SignatureBuiltin
from starkware.cairo.common.uint256 import (
Uint256,
uint256_add,
Expand All @@ -17,7 +17,7 @@ from starkware.starknet.common.syscalls import (
)
from starkware.cairo.common.alloc import alloc

from openzeppelin.access.ownable import Ownable_initializer, Ownable_only_owner
from openzeppelin.access.ownable import Ownable_initializer, Ownable_only_owner, Ownable_get_owner
from openzeppelin.utils.constants import TRUE, FALSE

from contracts.erc1155.ERC1155_struct import TokenUri
Expand Down Expand Up @@ -51,7 +51,7 @@ from contracts.utils.Math64x61 import (

from contracts.utils.Uint256_felt_conv import _felt_to_uint, _uint_to_felt

from InterfaceAll import IZkPadIDOContract, IERC20, IERC4626, IZKPadIDOFactory
from InterfaceAll import IZkPadIDOContract, IERC20, IERC4626, IZKPadIDOFactory, IAccount

from starkware.cairo.common.hash import hash2

Expand Down Expand Up @@ -487,3 +487,19 @@ func _balance_to_tickets{pedersen_ptr : HashBuiltin*, syscall_ptr : felt*, range

return (nb_tickets)
end

@view
func checkKYCSignature{
syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr, ecdsa_ptr : SignatureBuiltin*
}(sig_len : felt, sig : felt*):
alloc_locals
let (caller) = get_caller_address()
let (admin_address) = Ownable_get_owner()

let (user_hash) = hash2{hash_ptr=pedersen_ptr}(caller, 0)

# Verify the user's signature.
IAccount.is_valid_signature(admin_address, user_hash, sig_len, sig)

return ()
end
Loading

0 comments on commit 6a1c198

Please sign in to comment.