Skip to content

Commit

Permalink
Merge pull request #284 from web3wagers/dev
Browse files Browse the repository at this point in the history
merge dev into main
  • Loading branch information
adrianvrj authored Nov 29, 2024
2 parents 7d871b4 + 2b60d05 commit 19aab53
Show file tree
Hide file tree
Showing 22 changed files with 881 additions and 489 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NEXT_PUBLIC_APP_ROOT = "/"
2 changes: 1 addition & 1 deletion contracts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ declare:
starkli declare ./target/dev/gostarkme_FundManager.contract_class.json --keystore ~/.starkli-wallets/deployer/keystore_2.json --account ~/.starkli-wallets/accounts/account_2.json --rpc https://starknet-sepolia.g.alchemy.com/starknet/version/rpc/v0_7/2qi3kpZwfw6DlnjQmzL8vUh5PlqZ0Dpv

deploy:
starkli deploy 0x00a154538458a3aa00c13ff94e30cacf715ee1d43075d74add171d7abcb38d0a --keystore ~/.starkli-wallets/deployer/keystore_2.json --account ~/.starkli-wallets/accounts/account_2.json --rpc https://starknet-sepolia.g.alchemy.com/starknet/version/rpc/v0_7/2qi3kpZwfw6DlnjQmzL8vUh5PlqZ0Dpv
starkli deploy 0x04652dc5b0d79659cfb92c13d3b3bbdbcbd8f480afedbed7d90834e3e14c4260 --keystore ~/.starkli-wallets/deployer/keystore_2.json --account ~/.starkli-wallets/accounts/account_2.json --rpc https://starknet-sepolia.g.alchemy.com/starknet/version/rpc/v0_7/2qi3kpZwfw6DlnjQmzL8vUh5PlqZ0Dpv 0x034773a6a6d5f9ee24c44aa99455e9e8a95d2ff13362e4038f2577c00a7c7ed5

new-fund:
starkli invoke 0x0076d98b43b5ed1092dda81f2d52144e26323110ad87bd6fcf65a621409fcef6 --rpc https://starknet-sepolia.g.alchemy.com/starknet/version/rpc/v0_7/2qi3kpZwfw6DlnjQmzL8vUh5PlqZ0Dpv --keystore ~/.starkli-wallets/deployer/keystore_2.json --account ~/.starkli-wallets/accounts/account_2.json newFund 0x0388012BD4385aDf3b7afDE89774249D5179841cBaB06e9E5b4045F27B327CE8 0x5465737446756e64 0x5465737446756e64 200
Expand Down
77 changes: 53 additions & 24 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,70 @@

2. **Setup your environment**

- Scarb v2.6.5 : [here](https://docs.swmansion.com/scarb/download.html#install-via-asdf).
```bash
asdf install scarb 2.6.5
```
```bash
asdf global scarb 2.6.5
```
- Starknet Foundry v0.27.0: [here](https://foundry-rs.github.io/starknet-foundry/getting-started/installation.html).
```bash
asdf install starknet-foundry 0.27.0
```
```bash
asdf global starknet-foundry 0.27.0
```
**Setup your environment(Different option for macOS)**

- Option #1: Install Scarb and Starknet Foundry using asdf (Only macOS)
- Scarb v2.6.5 : [here](https://docs.swmansion.com/scarb/download.html#install-via-asdf).
```bash
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -v 2.6.5
asdf install scarb 2.6.5
```
Place it in the path:
```bash
export PATH="$HOME/.local/bin:$PATH"
asdf global scarb 2.6.5
```
It is recommended to restart the terminal.
- Starknet Foundry v0.27.0: [here](https://foundry-rs.github.io/starknet-foundry/getting-started/installation.html).
```bash
curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh -s -- -v 0.27.0
asdf install starknet-foundry 0.27.0
```
Place it in the path:
```bash
echo 'export PATH="$HOME/.asdf/shims:$HOME/.asdf/bin:$PATH"' >> ~/.zshrc
asdf global starknet-foundry 0.27.0
```
- Option #2: Install Scarb and Starknet Foundry using curl (Only macOS)
- Scarb v2.6.5 : [here](https://docs.swmansion.com/scarb/download.html#install-via-asdf).
```bash
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -v 2.6.5
```
Place it in the path:
```bash
echo 'export PATH="$HOME/.foundry/bin:$PATH"' >> ~/.zshrc
export PATH="$HOME/.local/bin:$PATH"
```
It is recommended to restart the terminal.

- Option #3: Install Scarb and Starknet Foundry (Only Ubuntu)
- Scarb v2.6.5
```bash
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -v 2.6.5
```
Run at terminal:
```bash
code ~ /.bashrc
```
Place it at the end of the path/code:
```bash
export PATH="$HOME/.local/bin:$PATH"
```
It is recommended to restart the terminal.

- Starknet Foundry v0.27.0: [here](https://foundry-rs.github.io/starknet-foundry/getting-started/installation.html).
```bash
curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh -s -- -v 0.27.0
```
**Place it in the path (Option for macOS):**
```bash
echo 'export PATH="$HOME/.asdf/shims:$HOME/.asdf/bin:$PATH"' >> ~/.zshrc
```
```bash
echo 'export PATH="$HOME/.foundry/bin:$PATH"' >> ~/.zshrc
```
**Place it in the path (Option for Ubuntu):**
```bash
In the terminal: code ~ /.bashrc
```
Place it at the end of the path/code:
```bash
export PATH="$HOME/.asdf/shims:$HOME/.asdf/bin:$PATH"
```
```bash
export PATH="$HOME/.foundry/bin:$PATH"
```

3. **Compile Go Stark Me Backend 🛠️**

To build the contracts, run the command:
Expand Down
20 changes: 10 additions & 10 deletions contracts/src/donator.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use starknet::ContractAddress;

#[starknet::interface]
pub trait IDonator<TContractState> {
fn getOwner(self: @TContractState) -> ContractAddress;
fn getLevel(self: @TContractState) -> u32;
fn getTotalStarkDonations(self: @TContractState) -> u256;
fn getMaxStarkDonationsToNextLevel(self: @TContractState) -> u256;
fn updateDonatorValues(ref self: TContractState, donated_starks: u256);
fn get_owner(self: @TContractState) -> ContractAddress;
fn get_level(self: @TContractState) -> u32;
fn get_total_stark_donations(self: @TContractState) -> u256;
fn get_max_stark_donations_to_next_level(self: @TContractState) -> u256;
fn update_donator_values(ref self: TContractState, donated_starks: u256);
}

#[starknet::contract]
Expand Down Expand Up @@ -46,19 +46,19 @@ mod Donator {
// *************************************************************************
#[abi(embed_v0)]
impl DonatorImpl of super::IDonator<ContractState> {
fn getOwner(self: @ContractState) -> ContractAddress {
fn get_owner(self: @ContractState) -> ContractAddress {
return self.owner.read();
}
fn getLevel(self: @ContractState) -> u32 {
fn get_level(self: @ContractState) -> u32 {
return self.level.read();
}
fn getTotalStarkDonations(self: @ContractState) -> u256 {
fn get_total_stark_donations(self: @ContractState) -> u256 {
return self.total_stark_donations.read();
}
fn getMaxStarkDonationsToNextLevel(self: @ContractState) -> u256 {
fn get_max_stark_donations_to_next_level(self: @ContractState) -> u256 {
return self.max_stark_donations_to_next_level.read();
}
fn updateDonatorValues(ref self: ContractState, donated_starks: u256) {
fn update_donator_values(ref self: ContractState, donated_starks: u256) {
let total_donator_pod = self.total_stark_donations.read() + donated_starks;
self.total_stark_donations.write(total_donator_pod);
if (total_donator_pod > self.max_stark_donations_to_next_level.read()) {
Expand Down
22 changes: 11 additions & 11 deletions contracts/src/donatorManager.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use starknet::class_hash::ClassHash;

#[starknet::interface]
pub trait IDonatorManager<TContractState> {
fn newDonator(ref self: TContractState);
fn getOwner(self: @TContractState) -> ContractAddress;
fn getDonatorClassHash(self: @TContractState) -> ClassHash;
fn getDonatorByAddress(self: @TContractState, owner: ContractAddress) -> ContractAddress;
fn new_donator(ref self: TContractState);
fn get_owner(self: @TContractState) -> ContractAddress;
fn get_donator_class_hash(self: @TContractState) -> ClassHash;
fn get_donator_by_address(self: @TContractState, owner: ContractAddress) -> ContractAddress;
}

#[starknet::contract]
Expand Down Expand Up @@ -60,12 +60,12 @@ pub mod DonatorManager {
// *************************************************************************
#[abi(embed_v0)]
impl DonatorManagerImpl of super::IDonatorManager<ContractState> {
fn newDonator(ref self: ContractState) {
let mut calldata = ArrayTrait::<felt252>::new();
calldata.append(get_caller_address().try_into().unwrap());
fn new_donator(ref self: ContractState) {
let mut call_data = ArrayTrait::<felt252>::new();
call_data.append(get_caller_address().try_into().unwrap());

let (new_donator_address, _) = deploy_syscall(
self.donator_class_hash.read(), 12345, calldata.span(), false
self.donator_class_hash.read(), 12345, call_data.span(), false
)
.unwrap();
self.donators.write(get_caller_address().try_into().unwrap(), new_donator_address);
Expand All @@ -76,13 +76,13 @@ pub mod DonatorManager {
}
)
}
fn getOwner(self: @ContractState) -> ContractAddress {
fn get_owner(self: @ContractState) -> ContractAddress {
return self.owner.read();
}
fn getDonatorClassHash(self: @ContractState) -> ClassHash {
fn get_donator_class_hash(self: @ContractState) -> ClassHash {
return self.donator_class_hash.read();
}
fn getDonatorByAddress(self: @ContractState, owner: ContractAddress) -> ContractAddress {
fn get_donator_by_address(self: @ContractState, owner: ContractAddress) -> ContractAddress {
return self.donators.read(owner);
}
}
Expand Down
114 changes: 73 additions & 41 deletions contracts/src/fund.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ use starknet::ContractAddress;

#[starknet::interface]
pub trait IFund<TContractState> {
fn getId(self: @TContractState) -> u128;
fn getOwner(self: @TContractState) -> ContractAddress;
fn setName(ref self: TContractState, name: ByteArray);
fn getName(self: @TContractState) -> ByteArray;
fn setReason(ref self: TContractState, reason: ByteArray);
fn getReason(self: @TContractState) -> ByteArray;
fn receiveVote(ref self: TContractState);
fn getUpVotes(self: @TContractState) -> u32;
fn setGoal(ref self: TContractState, goal: u256);
fn getGoal(self: @TContractState) -> u256;
fn get_id(self: @TContractState) -> u128;
fn get_owner(self: @TContractState) -> ContractAddress;
fn set_name(ref self: TContractState, name: ByteArray);
fn get_name(self: @TContractState) -> ByteArray;
fn set_reason(ref self: TContractState, reason: ByteArray);
fn get_reason(self: @TContractState) -> ByteArray;
fn receive_vote(ref self: TContractState);
fn get_up_votes(self: @TContractState) -> u32;
fn set_goal(ref self: TContractState, goal: u256);
fn get_goal(self: @TContractState) -> u256;
fn update_receive_donation(ref self: TContractState, strks: u256);
fn get_current_goal_state(self: @TContractState) -> u256;
fn setState(ref self: TContractState, state: u8);
fn getState(self: @TContractState) -> u8;
fn getVoter(self: @TContractState) -> u32;
fn set_state(ref self: TContractState, state: u8);
fn get_state(self: @TContractState) -> u8;
fn get_voter(self: @TContractState) -> u32;
fn withdraw(ref self: TContractState);
fn set_evidence_link(ref self: TContractState, evidence: ByteArray);
fn get_evidence_link(self: @TContractState) -> ByteArray;
Expand Down Expand Up @@ -122,29 +122,45 @@ pub mod Fund {
// *************************************************************************
#[abi(embed_v0)]
impl FundImpl of super::IFund<ContractState> {
fn getId(self: @ContractState) -> u128 {
fn get_id(self: @ContractState) -> u128 {
return self.id.read();
}
fn getOwner(self: @ContractState) -> ContractAddress {
fn get_owner(self: @ContractState) -> ContractAddress {
return self.owner.read();
}
fn setName(ref self: ContractState, name: ByteArray) {
fn set_name(ref self: ContractState, name: ByteArray) {
let caller = get_caller_address();
assert!(self.owner.read() == caller, "You are not the owner");
let valid_address_1 = contract_address_const::<FundManagerConstants::VALID_ADDRESS_1>();
let valid_address_2 = contract_address_const::<FundManagerConstants::VALID_ADDRESS_2>();
assert!(
self.owner.read() == caller
|| valid_address_1 == caller
|| valid_address_2 == caller,
"You must be an owner or admin to perform this action"
);
self.name.write(name);
}
fn getName(self: @ContractState) -> ByteArray {
fn get_name(self: @ContractState) -> ByteArray {
return self.name.read();
}
fn setReason(ref self: ContractState, reason: ByteArray) {
fn set_reason(ref self: ContractState, reason: ByteArray) {
let caller = get_caller_address();
assert!(self.owner.read() == caller, "You are not the owner");
let valid_address_1 = contract_address_const::<FundManagerConstants::VALID_ADDRESS_1>();
let valid_address_2 = contract_address_const::<FundManagerConstants::VALID_ADDRESS_2>();

assert!(
self.owner.read() == caller
|| valid_address_1 == caller
|| valid_address_2 == caller,
"You must be an owner or admin to perform this action"
);

self.reason.write(reason);
}
fn getReason(self: @ContractState) -> ByteArray {
fn get_reason(self: @ContractState) -> ByteArray {
return self.reason.read();
}
fn receiveVote(ref self: ContractState) {
fn receive_vote(ref self: ContractState) {
assert(self.voters.read(get_caller_address()) == 0, 'User already voted!');
assert(
self.state.read() == FundStates::RECOLLECTING_VOTES, 'Fund not recollecting votes!'
Expand All @@ -164,18 +180,19 @@ pub mod Fund {
}
);
}
fn getUpVotes(self: @ContractState) -> u32 {
fn get_up_votes(self: @ContractState) -> u32 {
return self.up_votes.read();
}
fn setGoal(ref self: ContractState, goal: u256) {
fn set_goal(ref self: ContractState, goal: u256) {
let caller = get_caller_address();
let fund_manager_address = contract_address_const::<
FundManagerConstants::FUND_MANAGER_ADDRESS
>();
assert!(fund_manager_address == caller, "You are not the fund manager");
let valid_address_1 = contract_address_const::<FundManagerConstants::VALID_ADDRESS_1>();
let valid_address_2 = contract_address_const::<FundManagerConstants::VALID_ADDRESS_2>();
assert!(
valid_address_1 == caller || valid_address_2 == caller, "Only Admins can set goal"
);
self.goal.write(goal);
}
fn getGoal(self: @ContractState) -> u256 {
fn get_goal(self: @ContractState) -> u256 {
return self.goal.read();
}
fn update_receive_donation(ref self: ContractState, strks: u256) {
Expand All @@ -196,39 +213,47 @@ pub mod Fund {
fn get_current_goal_state(self: @ContractState) -> u256 {
self.token_dispatcher().balance_of(get_contract_address())
}
fn setState(ref self: ContractState, state: u8) {
fn set_state(ref self: ContractState, state: u8) {
let caller = get_caller_address();
let valid_address_1 = contract_address_const::<FundManagerConstants::VALID_ADDRESS_1>();
let valid_address_2 = contract_address_const::<FundManagerConstants::VALID_ADDRESS_2>();
assert!(valid_address_1 == caller || valid_address_2 == caller, "Only Admins can change the fund state.");
assert!(
valid_address_1 == caller || valid_address_2 == caller,
"Only Admins can change the fund state."
);
self.state.write(state);
}
fn getState(self: @ContractState) -> u8 {
fn get_state(self: @ContractState) -> u8 {
return self.state.read();
}
fn getVoter(self: @ContractState) -> u32 {
fn get_voter(self: @ContractState) -> u32 {
return self.voters.read(get_caller_address());
}
fn withdraw(ref self: ContractState) {
let caller = get_caller_address();
assert!(self.owner.read() == caller, "You are not the owner");
assert(self.state.read() == FundStates::CLOSED, 'Fund not close goal yet.');
assert(
self.get_current_goal_state() >= self.getGoal(), 'Fund hasnt reached its goal yet'
self.get_current_goal_state() >= self.get_goal(), 'Fund hasnt reached its goal yet'
);

let valid_address = contract_address_const::<FundManagerConstants::VALID_ADDRESS_1>();
let withdrawn_amount = self.get_current_goal_state() * 95 / 100;
let fund_manager_amount = self.get_current_goal_state() * 5 / 100;
self.token_dispatcher().approve(self.getOwner(), withdrawn_amount);
self.token_dispatcher().transfer(self.getOwner(), withdrawn_amount);
let withdrawn_amount = (self.get_current_goal_state() * 95) / 100;
let fund_manager_amount = (self.get_current_goal_state() * 5) / 100;

self.token_dispatcher().approve(self.get_owner(), withdrawn_amount);
self.token_dispatcher().transfer(self.get_owner(), withdrawn_amount);

self.token_dispatcher().approve(valid_address, fund_manager_amount);
self.token_dispatcher().transfer(valid_address, fund_manager_amount);

assert(self.get_current_goal_state() == 0, 'Pending stks to withdraw');
self.setState(4);
self.state.write(FundStates::WITHDRAW);

self
.emit(
DonationWithdraw {
owner_address: self.getOwner(),
owner_address: self.get_owner(),
fund_contract_address: get_contract_address(),
withdrawn_amount
}
Expand All @@ -244,7 +269,14 @@ pub mod Fund {
}
fn set_contact_handle(ref self: ContractState, contact_handle: ByteArray) {
let caller = get_caller_address();
assert!(self.owner.read() == caller, "You are not the owner");
let valid_address_1 = contract_address_const::<FundManagerConstants::VALID_ADDRESS_1>();
let valid_address_2 = contract_address_const::<FundManagerConstants::VALID_ADDRESS_2>();
assert!(
self.owner.read() == caller
|| valid_address_1 == caller
|| valid_address_2 == caller,
"You must be an owner or admin to perform this action"
);
self.contact_handle.write(contact_handle);
}
fn get_contact_handle(self: @ContractState) -> ByteArray {
Expand Down
Loading

0 comments on commit 19aab53

Please sign in to comment.