Skip to content

Commit c74e5d4

Browse files
adding details
1 parent eba166e commit c74e5d4

10 files changed

Lines changed: 173 additions & 15590 deletions

File tree

.husky/pre-commit

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#!/bin/sh
2-
. "$(dirname "$0")/_/husky.sh"
1+
# #!/bin/sh
2+
# . "$(dirname "$0")/_/husky.sh"
33

4-
yarn format
4+
# yarn format
55
npm run format:check

.yarn/patches/usehooks-ts-npm-2.7.2-fceffe0e43.patch

Lines changed: 0 additions & 13 deletions
This file was deleted.

.yarn/plugins/@yarnpkg/plugin-typescript.cjs

Lines changed: 0 additions & 9 deletions
This file was deleted.

.yarn/releases/yarn-3.2.3.cjs

Lines changed: 0 additions & 783 deletions
This file was deleted.

package.json

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,23 @@
1111
]
1212
},
1313
"scripts": {
14-
"chain": "yarn workspace @ss-2/snfoundry chain",
15-
"deploy": "yarn workspace @ss-2/snfoundry deploy",
16-
"deploy:clear": "yarn workspace @ss-2/snfoundry deploy:clear",
17-
"deploy:no-reset": "yarn workspace @ss-2/snfoundry deploy --no-reset",
18-
"test": "yarn workspace @ss-2/snfoundry test",
19-
"compile": "yarn workspace @ss-2/snfoundry compile",
20-
"start": "yarn workspace @ss-2/nextjs dev",
21-
"next:lint": "yarn workspace @ss-2/nextjs lint",
22-
"next:check-types": "yarn workspace @ss-2/nextjs check-types",
23-
"vercel": "yarn workspace @ss-2/nextjs vercel",
24-
"vercel:yolo": "yarn workspace @ss-2/nextjs vercel:yolo",
25-
"test:nextjs": "yarn workspace @ss-2/nextjs test",
26-
"format": "yarn workspace @ss-2/nextjs format && yarn workspace @ss-2/snfoundry format",
27-
"format:check": "yarn workspace @ss-2/nextjs format:check && yarn workspace @ss-2/snfoundry format:check",
14+
"chain": "npm run chain -w @ss-2/snfoundry",
15+
"deploy": "npm run deploy -w @ss-2/snfoundry",
16+
"deploy:clear": "npm run deploy:clear -w @ss-2/snfoundry",
17+
"deploy:no-reset": "npm run deploy -w @ss-2/snfoundry -- --no-reset",
18+
"test": "npm run test -w @ss-2/snfoundry",
19+
"compile": "npm run compile -w @ss-2/snfoundry",
20+
"start": "npm run dev -w @ss-2/nextjs",
21+
"next:lint": "npm run lint -w @ss-2/nextjs",
22+
"next:check-types": "npm run check-types -w @ss-2/nextjs",
23+
"vercel": "npm run vercel -w @ss-2/nextjs",
24+
"vercel:yolo": "npm run vercel:yolo -w @ss-2/nextjs",
25+
"test:nextjs": "npm run test -w @ss-2/nextjs",
26+
"format": "npm run format -w @ss-2/nextjs && npm run format -w @ss-2/snfoundry",
27+
"format:check": "npm run format:check -w @ss-2/nextjs && npm run format:check -w @ss-2/snfoundry",
2828
"prepare": "husky",
29-
"verify": "yarn workspace @ss-2/snfoundry verify"
29+
"verify": "npm run verify -w @ss-2/snfoundry"
3030
},
31-
"packageManager": "yarn@3.2.3",
3231
"devDependencies": {
3332
"daisyui": "^4.7.3",
3433
"husky": "^9.0.11",

packages/nextjs/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
"prettier": "^3.4.2",
4444
"prettier-standalone": "^1.3.1-0",
4545
"qrcode.react": "^3.1.0",
46-
"react": "19.0.0",
46+
"react": "^18.0.0 || ^19.0.0",
4747
"react-copy-to-clipboard": "^5.1.0",
48-
"react-dom": "19.0.0",
48+
"react-dom": "^18.0.0 || ^19.0.0",
4949
"react-hot-toast": "^2.4.1",
5050
"starknet": "^7.5.0",
5151
"type-fest": "^4.6.0",
@@ -73,7 +73,7 @@
7373
"shx": "^0.4.0",
7474
"tailwindcss": "^3.3.0",
7575
"typescript": "^5",
76-
"vercel": "^33.7.1",
76+
"vercel": "^32.0.1",
7777
"vite": "^6.2.3",
7878
"vitest": "^3.0.9",
7979
"webpack": "^5.97.1",
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#[starknet::interface]
2+
pub trait IBuyMeACoffee<TContractState> {
3+
/// Allows a user to send a tip to the contract owner.
4+
/// # Arguments
5+
/// * `amount` - The amount of the tip token to send.
6+
/// * `message` - A message to accompany the tip.
7+
fn buy_coffee(ref self: TContractState, amount: u256, message: ByteArray);
8+
/// Allows the owner to withdraw the entire balance of the tip token from the contract.
9+
fn withdraw(ref self: TContractState);
10+
/// Returns an array of all tips received.
11+
fn get_tips(self: @TContractState) -> Array<Tip>;
12+
/// Returns the owner of the contract.
13+
fn get_owner(self: @TContractState) -> starknet::ContractAddress;
14+
}
15+
16+
#[starknet::contract]
17+
mod BuyMeACoffee {
18+
use openzeppelin::access::ownable::OwnableComponent;
19+
use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait};
20+
use starknet::{ContractAddress, get_caller_address, get_contract_address};
21+
use super::Tip;
22+
23+
component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);
24+
25+
#[abi(embed_v0)]
26+
impl OwnableImpl = OwnableComponent::OwnableImpl<ContractState>;
27+
impl OwnableInternalImpl = OwnableComponent::InternalImpl<ContractState>;
28+
29+
#[storage]
30+
struct Storage {
31+
tip_token_address: ContractAddress,
32+
tips: LegacyMap<u32, Tip>,
33+
tips_count: u32,
34+
#[substorage(v0)]
35+
ownable: OwnableComponent::Storage,
36+
}
37+
38+
#[event]
39+
#[derive(Drop, starknet::Event)]
40+
enum Event {
41+
#[flat]
42+
OwnableEvent: OwnableComponent::Event,
43+
TipReceived: TipReceived,
44+
}
45+
46+
#[derive(Drop, starknet::Event)]
47+
struct TipReceived {
48+
#[key]
49+
tipper: ContractAddress,
50+
amount: u256,
51+
message: ByteArray,
52+
}
53+
54+
#[constructor]
55+
fn constructor(
56+
ref self: ContractState, owner_address: ContractAddress, tip_token: ContractAddress,
57+
) {
58+
self.ownable.initializer(owner_address);
59+
self.tip_token_address.write(tip_token);
60+
}
61+
62+
#[abi(embed_v0)]
63+
impl IBuyMeACoffeeImpl of super::IBuyMeACoffee<ContractState> {
64+
fn buy_coffee(ref self: ContractState, amount: u256, message: ByteArray) {
65+
assert(amount > 0, 'Tip amount must be > 0');
66+
let tipper = get_caller_address();
67+
let contract_address = get_contract_address();
68+
let token_dispatcher = IERC20Dispatcher {
69+
contract_address: self.tip_token_address.read(),
70+
};
71+
token_dispatcher.transfer_from(tipper, contract_address, amount);
72+
let tip_id = self.tips_count.read();
73+
self.tips.write(tip_id, Tip { tipper, amount, message: message.clone() });
74+
self.tips_count.write(tip_id + 1);
75+
self.emit(TipReceived { tipper, amount, message });
76+
}
77+
78+
fn withdraw(ref self: ContractState) {
79+
self.ownable.assert_only_owner();
80+
let owner_address = self.ownable.owner();
81+
let contract_address = get_contract_address();
82+
let token_dispatcher = IERC20Dispatcher {
83+
contract_address: self.tip_token_address.read(),
84+
};
85+
let balance = token_dispatcher.balance_of(contract_address);
86+
if balance > 0 {
87+
token_dispatcher.transfer(owner_address, balance);
88+
}
89+
}
90+
91+
fn get_tips(self: @ContractState) -> Array<Tip> {
92+
let mut all_tips = array![];
93+
let count = self.tips_count.read();
94+
let mut i = 0_u32;
95+
loop {
96+
if i >= count {
97+
break;
98+
}
99+
all_tips.append(self.tips.read(i));
100+
i += 1;
101+
}
102+
all_tips
103+
}
104+
105+
fn get_owner(self: @ContractState) -> starknet::ContractAddress {
106+
self.ownable.owner()
107+
}
108+
}
109+
}
110+
111+
#[derive(Drop, starknet::Store, Serde)]
112+
pub struct Tip {
113+
tipper: starknet::ContractAddress,
114+
amount: u256,
115+
message: ByteArray,
116+
}
117+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#[starknet::contract]
2+
mod MockERC20 {
3+
use openzeppelin::token::erc20::ERC20Component;
4+
use starknet::ContractAddress;
5+
6+
component!(path: ERC20Component, storage: erc20, event: ERC20Event);
7+
8+
#[abi(embed_v0)]
9+
impl ERC20Impl = ERC20Component::ERC20Impl<ContractState>;
10+
#[abi(embed_v0)]
11+
impl ERC20CamelOnlyImpl = ERC20Component::ERC20CamelOnlyImpl<ContractState>;
12+
13+
impl ERC20InternalImpl = ERC20Component::InternalImpl<ContractState>;
14+
15+
#[storage]
16+
struct Storage {
17+
#[substorage(v0)]
18+
erc20: ERC20Component::Storage,
19+
}
20+
21+
#[event]
22+
#[derive(Drop, starknet::Event)]
23+
enum Event {
24+
#[flat]
25+
ERC20Event: ERC20Component::Event,
26+
}
27+
28+
#[constructor]
29+
fn constructor(ref self: ContractState, initial_supply: u256, recipient: ContractAddress) {
30+
let name = 'MockERC20';
31+
let symbol = 'MOCK';
32+
self.erc20.initializer(name, symbol);
33+
self.erc20._mint(recipient, initial_supply);
34+
}
35+
}

packages/snfoundry/contracts/tests/TestContract.cairo

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)