Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description = "Sway token standard SRC-20 rust sdk"

[dependencies]
dotenv = "0.15.0"
fuels = { version = "0.55.0", features = ["fuel-core-lib"] }
fuels = { version = "0.60.0", features = ["fuel-core-lib"] }
rand = "0.8.5"
serde = "1.0.197"
serde_json = "1.0.114"
Expand Down
38 changes: 16 additions & 22 deletions contract/Forc.lock
Original file line number Diff line number Diff line change
@@ -1,41 +1,35 @@
[[package]]
name = "asset"
source = "git+https://github.com/FuelLabs/sway-libs?tag=v0.19.0#dcbbec000a9051e71c0c21f4b720eebbb55c199a"
dependencies = [
"src7",
"std",
]

[[package]]
name = "core"
source = "path+from-root-566CA1D5F8BEAFBF"
source = "path+from-root-CC7184DF2EE4172B"

[[package]]
name = "src20"
source = "git+https://github.com/FuelLabs/sway-standards?tag=v0.3.3#4198b4b07449ad16104cc8a0501f3013670fdcfd"
name = "standards"
source = "git+https://github.com/FuelLabs/sway-standards?tag=v0.4.1#0a6f3ba0bce036a0ce61f15ed4480c71af32d3aa"
dependencies = ["std"]

[[package]]
name = "src3"
source = "git+https://github.com/FuelLabs/sway-standards?tag=v0.3.3#4198b4b07449ad16104cc8a0501f3013670fdcfd"
dependencies = ["std"]

[[package]]
name = "src7"
source = "git+https://github.com/FuelLabs/sway-standards?tag=v0.3.3#4198b4b07449ad16104cc8a0501f3013670fdcfd"
name = "standards"
source = "git+https://github.com/FuelLabs/sway-standards?tag=v0.4.3#6f63eb7dff2458a7d976184e565b5cbf26f61da2"
dependencies = ["std"]

[[package]]
name = "std"
source = "git+https://github.com/fuellabs/sway?tag=v0.49.3#0dc6570377ee9c4a6359ade597fa27351e02a728"
source = "git+https://github.com/fuellabs/sway?rev#850a2c48ddac019aa04bf7f5c1319381edc53fea"
dependencies = ["core"]

[[package]]
name = "sway_libs"
source = "git+https://github.com/FuelLabs/sway-libs?tag=v0.21.0#6a227ed34c86fe1ebd334dbdfeccf66c43e3915b"
dependencies = [
"standards git+https://github.com/FuelLabs/sway-standards?tag=v0.4.3#6f63eb7dff2458a7d976184e565b5cbf26f61da2",
"std",
]

[[package]]
name = "token"
source = "member"
dependencies = [
"asset",
"src20",
"src3",
"standards git+https://github.com/FuelLabs/sway-standards?tag=v0.4.1#0a6f3ba0bce036a0ce61f15ed4480c71af32d3aa",
"std",
"sway_libs",
]
5 changes: 2 additions & 3 deletions contract/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ license = "Apache-2.0"
name = "token"

[dependencies]
asset = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.19.0" }
src20 = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.3.3" }
src3 = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.3.3"}
sway_libs = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.21.0" }
standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.4.1" }
19 changes: 16 additions & 3 deletions contract/out/debug/token-abi.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"encoding": "1",
"types": [
{
"typeId": 0,
Expand Down Expand Up @@ -77,7 +78,7 @@
"type": "struct Address",
"components": [
{
"name": "value",
"name": "bits",
"type": 1,
"typeArguments": null
}
Expand All @@ -89,7 +90,7 @@
"type": "struct AssetId",
"components": [
{
"name": "value",
"name": "bits",
"type": 1,
"typeArguments": null
}
Expand Down Expand Up @@ -118,7 +119,7 @@
"type": "struct ContractId",
"components": [
{
"name": "value",
"name": "bits",
"type": 1,
"typeArguments": null
}
Expand Down Expand Up @@ -321,6 +322,10 @@
"typeArguments": null
},
"attributes": [
{
"name": "payable",
"arguments": []
},
{
"name": "storage",
"arguments": [
Expand Down Expand Up @@ -373,6 +378,14 @@
"type": 2,
"typeArguments": []
}
},
{
"logId": 1,
"loggedType": {
"name": "",
"type": 2,
"typeArguments": []
}
}
],
"messagesTypes": [],
Expand Down
Binary file modified contract/out/debug/token.bin
Binary file not shown.
9 changes: 5 additions & 4 deletions contract/src/main.sw
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
contract;

use asset::base::{
use sway_libs::asset::base::{
_total_assets,
_total_supply,
_name,
_symbol,
_decimals
};
use asset::mint::{_mint, _burn};
use src20::SRC20;
use src3::SRC3;
use sway_libs::asset::supply::{_mint, _burn};
use standards::src20::SRC20;
use standards::src3::SRC3;
use std::{hash::{Hash, sha256}, string::String, storage::storage_string::*};
storage {
total_assets: u64 = 0,
Expand Down Expand Up @@ -52,6 +52,7 @@ impl SRC3 for Contract {
let _asset_id = _mint(storage.total_assets, storage.total_supply, recipient, sub_id, amount);
}

#[payable]
#[storage(read, write)]
fn burn(sub_id: SubId, amount: u64) {
_burn(storage.total_supply, sub_id, amount);
Expand Down
2 changes: 1 addition & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub const RPC: &str = "beta-5.fuel.network";
pub const RPC: &str = "devnet.fuel.network";

pub const TOKEN_CONTRACT_ID: &str =
"0x6bd9643c9279204b474a778dea7f923226060cb94a4c61c5aae015cf96b5aad2";
12 changes: 5 additions & 7 deletions src/token_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct Asset {
pub asset_id: AssetId,
pub decimals: u64,
pub symbol: String,
pub token_contract_instance: Option<TokenContract<WalletUnlocked>>,
pub token_contract: TokenContract<WalletUnlocked>,
}

impl Asset {
Expand All @@ -36,13 +36,11 @@ impl Asset {
amount: u64,
) -> Result<FuelCallResponse<()>, fuels::types::errors::Error> {
let symbol_hash = get_symbol_hash(&self.symbol);
self.token_contract_instance
.as_ref()
.unwrap()
self.token_contract
.methods()
.mint(Identity::Address(recipient), symbol_hash, amount)
.append_variable_outputs(1)
.with_tx_policies(TxPolicies::default().with_gas_price(1))
.with_tx_policies(TxPolicies::default().with_tip(1))
.call()
.await
}
Expand All @@ -69,7 +67,7 @@ impl Asset {
asset_id,
decimals: config.decimals,
symbol: config.symbol,
token_contract_instance: Option::Some(instance),
token_contract: instance,
}
}
}
Expand All @@ -83,7 +81,7 @@ pub async fn deploy_token_contract(wallet: &WalletUnlocked) -> TokenContract<Wal
let id = Contract::load_from(bin_path, config)
.unwrap()
.with_salt(salt)
.deploy(wallet, TxPolicies::default().with_gas_price(1))
.deploy(wallet, TxPolicies::default().with_tip(1))
.await
.unwrap();
let instance = TokenContract::new(id.clone(), wallet.clone());
Expand Down
4 changes: 2 additions & 2 deletions tests/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ async fn main_test() {
let admin = &wallets[0];
let alice = &wallets[1];

let token_contarct = deploy_token_contract(&admin).await;
let usdc = Asset::new(admin.clone(), token_contarct.contract_id().into(), "USDC");
let token_contract = deploy_token_contract(&admin).await;
let usdc = Asset::new(admin.clone(), token_contract.contract_id().into(), "USDC");

usdc.mint(alice.address().into(), usdc.parse_units(1000.0) as u64)
.await
Expand Down