-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathRewardToken.cairo
More file actions
74 lines (65 loc) · 2.38 KB
/
RewardToken.cairo
File metadata and controls
74 lines (65 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// SPDX-License-Identifier: MIT
use starknet::ContractAddress;
#[starknet::interface]
pub trait IExternal<ContractState> {
fn mint(ref self: ContractState, recipient: ContractAddress, amount: u256);
}
#[starknet::contract]
pub mod RewardERC20 {
use openzeppelin::access::ownable::OwnableComponent;
use openzeppelin::token::erc20::interface::IERC20Metadata;
use openzeppelin::token::erc20::{ERC20Component, ERC20HooksEmptyImpl};
use starknet::ContractAddress;
use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess};
component!(path: ERC20Component, storage: erc20, event: ERC20Event);
component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);
#[storage]
pub struct Storage {
#[substorage(v0)]
pub erc20: ERC20Component::Storage,
#[substorage(v0)]
pub ownable: OwnableComponent::Storage,
custom_decimals: u8 // Add custom decimals storage
}
#[event]
#[derive(Drop, starknet::Event)]
enum Event {
#[flat]
ERC20Event: ERC20Component::Event,
#[flat]
OwnableEvent: OwnableComponent::Event,
}
#[constructor]
fn constructor(
ref self: ContractState, owner: ContractAddress, name: ByteArray, symbol: ByteArray,
) {
self.erc20.initializer(name, symbol);
self.ownable.initializer(owner);
self.custom_decimals.write(8);
}
#[abi(embed_v0)]
impl CustomERC20MetadataImpl of IERC20Metadata<ContractState> {
fn name(self: @ContractState) -> ByteArray {
self.erc20.name()
}
fn symbol(self: @ContractState) -> ByteArray {
self.erc20.symbol()
}
fn decimals(self: @ContractState) -> u8 {
self.custom_decimals.read() // Return custom value
}
}
// Keep existing implementations
#[abi(embed_v0)]
impl ERC20Impl = ERC20Component::ERC20Impl<ContractState>;
#[abi(embed_v0)]
impl OwnableImpl = OwnableComponent::OwnableImpl<ContractState>;
impl InternalImpl = ERC20Component::InternalImpl<ContractState>;
impl OwnableInternalImpl = OwnableComponent::InternalImpl<ContractState>;
#[abi(embed_v0)]
impl ExternalImpl of super::IExternal<ContractState> {
fn mint(ref self: ContractState, recipient: ContractAddress, amount: u256) {
self.erc20.mint(recipient, amount);
}
}
}