Skip to content

Commit

Permalink
Merge pull request #18 from SoarinSkySagar/lint
Browse files Browse the repository at this point in the history
fix: linted all cairo code
  • Loading branch information
machuwey authored Dec 2, 2024
2 parents de8373d + fa30689 commit 7dc4853
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 15 deletions.
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,22 @@ For more detailed guidelines, please refer to the [Git Style Guide](https://udac
<table>
<tbody>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/machuwey"><img src="https://avatars.githubusercontent.com/u/56169780?v=4&s=100" width="100px;" alt="Machuwey"/><br /><sub><b>Machuwey</b></sub></a><br /><a href="https://github.com/The Starknet Community/The Starknet Book/commits?author=omarespejel" title="Code">💻</a> <a href="https://github.com/The Starknet Community/The Starknet Book/commits?author=omarespejel" title="Documentation">📖</a></td>
<tr>
</tbody>
<td align="center" valign="top" width="14.28%">
<a href="https://github.com/machuwey">
<img src="https://avatars.githubusercontent.com/u/56169780?v=4&s=100" width="100px;" alt="Machuwey"/><br />
<sub><b>Machuwey</b></sub>
</a><br />
<a href="https://github.com/The Starknet Community/The Starknet Book/commits?author=omarespejel" title="Code">💻</a>
<a href="https://github.com/The Starknet Community/The Starknet Book/commits?author=omarespejel" title="Documentation">📖</a>
</td>
<td align="center" valign="top" width="14.28%">
<a href="https://github.com/SoarinSkySagar">
<img src="https://avatars.githubusercontent.com/u/117727361?v=4&s=100" width="100px;" alt="SoarinSkySagar"/><br />
<sub><b>SoarinSkySagar</b></sub>
</a><br />
<a href="https://github.com/The Starknet Community/The Starknet Book/commits?author=omarespejel" title="Code">💻</a>
<a href="https://github.com/The Starknet Community/The Starknet Book/commits?author=omarespejel" title="Documentation">📖</a>
</td>
</tr>
</tbody>
</table>
14 changes: 14 additions & 0 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ This guide will walk you through the deployment process for the `Strapex` contra
- **Factory Contract Address**: `0x03e171d9c4b93dde9a2b2c6658b56dc2b1bf43aad105e7685cb9974f01e13117`
- **Starkli Wallet Path**: `~/.starkli-wallets/deployer/`

## Linting
Make sure to use the following command to lint all Cairo files before raising a PR

#### Lint all Cairo files
```bash
scarb fmt
```

To check if all files are linted, run the following command. If there are any linting errors, it will be displayed in the terminal.

#### Check for linting errors
```bash
scarb fmt --check
```

### 0. Set your wallet locally
Please refer to the [Starknet documentation](https://docs.starknet.io/quick-start/set-up-an-account/#creating_a_keystore_file) to create a keystore file.
Expand Down
13 changes: 9 additions & 4 deletions contracts/src/ownership_component.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ trait IOwnable<TContractState> {

#[starknet::component]
mod ownable_component {
use starknet::{get_caller_address, ContractAddress, get_contract_address, Zeroable, get_block_timestamp};
use starknet::{
get_caller_address, ContractAddress, get_contract_address, Zeroable, get_block_timestamp
};
use super::Errors;

#[storage]
Expand All @@ -30,7 +32,8 @@ mod ownable_component {

#[embeddable_as(Ownable)]
impl OwnableImpl<
TContractState, +HasComponent<TContractState>> of super::IOwnable<ComponentState<TContractState>> {
TContractState, +HasComponent<TContractState>
> of super::IOwnable<ComponentState<TContractState>> {
fn owner(self: @ComponentState<TContractState>) -> ContractAddress {
self.owner.read()
}
Expand All @@ -50,7 +53,9 @@ mod ownable_component {
}

#[generate_trait]
impl InternalImpl<TContractState, +HasComponent<TContractState>> of InternalTrait<TContractState> {
impl InternalImpl<
TContractState, +HasComponent<TContractState>
> of InternalTrait<TContractState> {
fn initializer(ref self: ComponentState<TContractState>, owner: ContractAddress) {
self._transfer_ownership(owner);
}
Expand Down Expand Up @@ -79,4 +84,4 @@ mod Errors {
const NOT_OWNER: felt252 = 'Caller is not the owner';
const ZERO_ADDRESS_CALLER: felt252 = 'Caller is the zero address';
const ZERO_ADDRESS_OWNER: felt252 = 'New owner is the zero address';
}
}
20 changes: 13 additions & 7 deletions contracts/src/strapex_contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ pub mod StrapexContract {
#[storage]
struct Storage {
token: IERC20Dispatcher,

balance: u256,
fee_percentage: u256,
fees_collected: u256,
Expand Down Expand Up @@ -174,7 +173,7 @@ pub mod StrapexContract {
let owner = self.ownable.owner();
assert(caller == owner, Errors::UnAuthorized_Caller);

let taxable_amount: u256 = self.taxable_amount.read();
let taxable_amount: u256 = self.taxable_amount.read();
let fee_percentage = self.fee_percentage.read();
let fee_amount = taxable_amount * fee_percentage / 100;
let withdrawal_amount = self.balance.read() - fee_amount;
Expand Down Expand Up @@ -258,7 +257,7 @@ pub mod StrapexContract {
// Optionally update fees collected
let updated_fees_collected = self.fees_collected.read() + fee_amount;
self.fees_collected.write(updated_fees_collected);
// Emit an event if necessary
// Emit an event if necessary
}

fn refund(ref self: ContractState, tx_hash: felt252) {
Expand All @@ -267,7 +266,7 @@ pub mod StrapexContract {
assert(caller == owner, Errors::UnAuthorized_Caller);

let (_, _, _) = self.getImportantAddresses();
let Payment{buyer, amount, token, id, refunded } = self.payments.read(tx_hash);
let Payment { buyer, amount, token, id, refunded } = self.payments.read(tx_hash);
assert(refunded == 0.into(), Errors::Already_Refunded);

// Generalized for future support of multi tokens
Expand All @@ -283,14 +282,21 @@ pub mod StrapexContract {
assert(caller == owner, Errors::UnAuthorized_Caller);

let (_, _, _) = self.getImportantAddresses();
let Payment{buyer, amount: total_amount, token, id, refunded } = self.payments.read(tx_hash);
let Payment { buyer, amount: total_amount, token, id, refunded } = self
.payments
.read(tx_hash);
assert(refunded + amount <= total_amount, Errors::Refund_Exceeds_Amount);

// Generalized for future support of multi tokens
let tokenDispatch = super::IERC20Dispatcher { contract_address: token };
tokenDispatch.transfer(buyer, amount.into());

self.payments.write(tx_hash, Payment { buyer, amount: total_amount, token, id, refunded: refunded + amount });
self
.payments
.write(
tx_hash,
Payment { buyer, amount: total_amount, token, id, refunded: refunded + amount }
);
}

fn get_fee_percentage(self: @ContractState) -> u256 {
Expand Down Expand Up @@ -322,4 +328,4 @@ pub mod StrapexContract {
(caller, this, currentBalance)
}
}
}
}
2 changes: 1 addition & 1 deletion contracts/src/strapex_factory.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,4 @@ mod StrapexFactory {
currentHash
}
}
}
}

0 comments on commit 7dc4853

Please sign in to comment.