Skip to content

Commit c17b76d

Browse files
committed
wip
1 parent 4eb159f commit c17b76d

File tree

5 files changed

+112
-1
lines changed

5 files changed

+112
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
members = [
44
"fvm_dispatch",
55
"fil_token",
6+
"testing/actors/fil_token_actor",
67
]

fil_token/Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,11 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
fvm_shared = { version = "0.8.0" }
9+
anyhow = "1.0.56"
10+
cid = { version = "0.8.3", default-features = false, features = ["serde-codec"] }
11+
fvm_ipld_blockstore = "0.1.1"
12+
fvm_ipld_hamt = "0.5.1"
13+
fvm_ipld_amt = { version = "0.4.2", features = ["go-interop"] }
14+
fvm_ipld_encoding = "0.2.2"
15+
fvm_shared = { version = "0.8.0" }
16+
serde = { version = "1.0.136", features = ["derive"] }

fil_token/src/token/mod.rs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
pub mod receiver;
22

3+
use anyhow::anyhow;
4+
use cid::Cid;
5+
6+
use fvm_ipld_blockstore::Blockstore;
7+
use fvm_ipld_encoding::tuple::*;
8+
use fvm_ipld_encoding::Cbor;
9+
use fvm_ipld_hamt::Hamt;
10+
311
use fvm_shared::address::Address;
12+
use fvm_shared::bigint::bigint_ser;
413
pub use fvm_shared::econ::TokenAmount;
14+
use fvm_shared::HAMT_BIT_WIDTH;
515

616
pub type Result<T> = std::result::Result<T, TokenError>;
717
pub enum TokenError {}
@@ -28,3 +38,82 @@ pub trait Token {
2838

2939
fn burn_from(from: Address, amount: TokenAmount, data: &[u8]) -> Result<TokenAmount>;
3040
}
41+
42+
/// Token actor state
43+
#[derive(Serialize_tuple, Deserialize_tuple, Clone)]
44+
pub struct DefaultToken {
45+
#[serde(with = "bigint_ser")]
46+
supply: TokenAmount,
47+
name: String,
48+
symbol: String,
49+
50+
balances: Cid,
51+
allowances: Cid,
52+
}
53+
54+
/// Default token implementation
55+
impl DefaultToken {
56+
pub fn new<BS>(name: &str, symbol: &str, store: &BS) -> anyhow::Result<Self>
57+
where
58+
BS: Blockstore,
59+
{
60+
let empty_balance_map = Hamt::<_, ()>::new_with_bit_width(store, HAMT_BIT_WIDTH)
61+
.flush()
62+
.map_err(|e| anyhow!("Failed to create empty balances map state {}", e))?;
63+
let empty_allowances_map = Hamt::<_, ()>::new_with_bit_width(store, HAMT_BIT_WIDTH)
64+
.flush()
65+
.map_err(|e| anyhow!("Failed to create empty balances map state {}", e))?;
66+
67+
Ok(Self {
68+
supply: Default::default(),
69+
name: name.to_string(),
70+
symbol: symbol.to_string(),
71+
balances: empty_balance_map,
72+
allowances: empty_allowances_map,
73+
})
74+
}
75+
}
76+
77+
impl Cbor for DefaultToken {}
78+
79+
impl Token for DefaultToken {
80+
fn name() -> String {
81+
todo!()
82+
}
83+
84+
fn symbol() -> String {
85+
todo!()
86+
}
87+
88+
fn total_supply() -> TokenAmount {
89+
todo!()
90+
}
91+
92+
fn balance_of(holder: Address) -> Result<TokenAmount> {
93+
todo!()
94+
}
95+
96+
fn increase_allowance(spender: Address, value: TokenAmount) -> Result<TokenAmount> {
97+
todo!()
98+
}
99+
100+
fn decrease_allowance(spender: Address, value: TokenAmount) -> Result<TokenAmount> {
101+
todo!()
102+
}
103+
104+
fn revoke_allowance(spender: Address) -> Result<()> {
105+
todo!()
106+
}
107+
108+
fn allowance(owner: Address, spender: Address) -> Result<TokenAmount> {
109+
todo!()
110+
}
111+
112+
fn burn(amount: TokenAmount, data: &[u8]) -> Result<TokenAmount> {
113+
todo!()
114+
}
115+
116+
fn burn_from(from: Address, amount: TokenAmount, data: &[u8]) -> Result<TokenAmount> {
117+
todo!()
118+
}
119+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "fil_token_actor"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
fil_token = { version = "0.1.0", path = "../../../fil_token" }
10+
11+
[dev-dependencies]
12+
fvm_integration_tests = {version = "0.1.0", git = "https://github.com/filecoin-project/ref-fvm" }
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#[cfg(test)]
2+
mod tests {}

0 commit comments

Comments
 (0)