-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathlib.rs
64 lines (57 loc) · 1.35 KB
/
lib.rs
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
#![cfg_attr(not(test), no_main)]
extern crate alloc;
use alloc::vec::Vec;
use alloy_primitives::{Address, B256, U256};
use openzeppelin_stylus::{
token::erc20::{extensions::Erc20Permit, Erc20},
utils::{cryptography::eip712::IEip712, nonces::Nonces},
};
use stylus_sdk::prelude::*;
#[entrypoint]
#[storage]
struct Erc20PermitExample {
#[borrow]
pub erc20: Erc20,
#[borrow]
pub nonces: Nonces,
#[borrow]
pub erc20_permit: Erc20Permit<Eip712>,
}
#[storage]
struct Eip712 {}
impl IEip712 for Eip712 {
const NAME: &'static str = "ERC-20 Permit Example";
const VERSION: &'static str = "1";
}
#[public]
#[inherit(Erc20, Nonces, Erc20Permit<Eip712>)]
impl Erc20PermitExample {
// Add token minting feature.
fn mint(&mut self, account: Address, value: U256) -> Result<(), Vec<u8>> {
self.erc20._mint(account, value)?;
Ok(())
}
#[allow(clippy::too_many_arguments)]
fn permit(
&mut self,
owner: Address,
spender: Address,
value: U256,
deadline: U256,
v: u8,
r: B256,
s: B256,
) -> Result<(), Vec<u8>> {
Ok(self.erc20_permit.permit(
owner,
spender,
value,
deadline,
v,
r,
s,
&mut self.erc20,
&mut self.nonces,
)?)
}
}