Skip to content

Commit 3db2244

Browse files
authored
feat: add near-plugins usage and another refactoring (#10)
1 parent 6ed2eac commit 3db2244

36 files changed

+1060
-966
lines changed

Cargo.lock

Lines changed: 666 additions & 615 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
1+
[workspace.package]
2+
version = "0.1.0"
3+
edition = "2024"
4+
# NEP-0330 is automatically implemented for all contracts built with https://github.com/near/cargo-near.
5+
# Link to the repository will be available via `contract_source_metadata` view-function.
6+
repository = "https://github.com/Near-One/tee-solver"
7+
18
[workspace]
2-
resolver = "2"
9+
resolver = "3"
310
members = [
411
"contracts/intents-vault",
512
"contracts/solver-registry",
613
"contracts/mock-intents",
714
"contracts/mock-ft",
815
]
916

17+
[workspace.lints.clippy]
18+
all = { level = "deny", priority = -1 }
19+
nursery = { level = "deny", priority = -1 }
20+
pedantic = { level = "deny", priority = -1 }
21+
similar_names = "allow"
22+
needless_pass_by_value = "allow"
23+
module_inception = "allow"
24+
1025
[profile.release]
1126
codegen-units = 1
12-
# Tell `rustc` to optimize for small code size.
27+
# Tell `rustc` to optimize compiled code to descrease the code size.
1328
opt-level = "z"
1429
lto = true
1530
debug = false
1631
panic = "abort"
1732
# Opt into extra safety checks on arithmetic operations https://stackoverflow.com/a/64136471/249801
1833
overflow-checks = true
34+
strip = "symbols"

contracts/intents-vault/Cargo.toml

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
[package]
22
name = "intents-vault"
33
description = "NEAR Intents Vault"
4-
version = "0.1.0"
5-
edition = "2021"
6-
# NEP-0330 is automatically implemented for all contracts built with https://github.com/near/cargo-near.
7-
# Link to the repository will be available via `contract_source_metadata` view-function.
8-
repository = "https://github.com/Near-One/tee-solver/tree/main/contracts/intents-vault"
4+
version.workspace = true
5+
edition.workspace = true
6+
repository.workspace = true
97

108
[lib]
119
crate-type = ["cdylib", "rlib"]
1210

13-
# fields to configure build with WASM reproducibility, according to specs
14-
# in https://github.com/near/NEPs/blob/master/neps/nep-0330.md
11+
# fields to configure build with WASM reproducibility, according to specs
12+
# in https://github.com/near/NEPs/blob/master/neps/nep-0330.md
1513
[package.metadata.near.reproducible_build]
1614
# docker image, descriptor of build environment
1715
image = "sourcescan/cargo-near:0.14.1-rust-1.86.0"
@@ -21,7 +19,7 @@ image_digest = "sha256:eaac91be3119cc7c136b6f375f2d3e092001f717ed6151ccc9d5348c2
2119
# in a reproducible manner
2220
# supported by `sourcescan/cargo-near:0.10.1-rust-1.82.0` image or later images
2321
passed_env = []
24-
# build command inside of docker container
22+
# build command inside of docker container
2523
# if docker image from default gallery is used https://hub.docker.com/r/sourcescan/cargo-near/tags,
2624
# the command may be any combination of flags of `cargo-near`,
2725
# supported by respective version of binary inside the container besides `--no-locked` flag
@@ -35,12 +33,7 @@ container_build_command = [
3533

3634
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
3735
[dependencies]
38-
near-sdk = "5.14.0"
39-
serde_json = "1.0.140"
36+
near-sdk = "5"
4037

41-
[dev-dependencies]
42-
near-sdk = { version = "5.14.0", features = ["unit-testing"] }
43-
tokio = "1.44.1"
44-
anyhow = "1.0.97"
45-
near-workspaces = { version = "0.20.1", features = ["unstable"]}
46-
near-gas = "0.3.0"
38+
[lints]
39+
workspace = true
-598 Bytes
Binary file not shown.

contracts/intents-vault/src/lib.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use near_sdk::{
2-
assert_one_yocto, env, ext_contract, near, require, AccountId, NearToken, Promise, PublicKey,
2+
AccountId, NearToken, Promise, PublicKey, assert_one_yocto, env, ext_contract, near, require,
33
};
44

55
#[allow(dead_code)]
@@ -23,7 +23,7 @@ impl Contract {
2323
public_key: PublicKey,
2424
) -> Promise {
2525
assert_one_yocto();
26-
self.require_parent_account();
26+
require_parent_account();
2727

2828
ext_intents::ext(intents_contract_id)
2929
.with_attached_deposit(NearToken::from_yoctonear(1))
@@ -37,21 +37,19 @@ impl Contract {
3737
public_key: PublicKey,
3838
) -> Promise {
3939
assert_one_yocto();
40-
self.require_parent_account();
40+
require_parent_account();
4141

4242
ext_intents::ext(intents_contract_id)
4343
.with_attached_deposit(NearToken::from_yoctonear(1))
4444
.remove_public_key(public_key)
4545
}
4646
}
4747

48-
impl Contract {
49-
fn require_parent_account(&self) {
50-
let contract_id = env::current_account_id().to_string();
51-
let (_, parent_account_id) = contract_id.split_once('.').expect("Invalid contract ID");
52-
require!(
53-
env::predecessor_account_id() == parent_account_id,
54-
"Only parent account can perform this action"
55-
);
56-
}
48+
fn require_parent_account() {
49+
let contract_id = env::current_account_id().to_string();
50+
let (_, parent_account_id) = contract_id.split_once('.').expect("Invalid contract ID");
51+
require!(
52+
env::predecessor_account_id() == parent_account_id,
53+
"Only parent account can perform this action"
54+
);
5755
}

contracts/mock-ft/Cargo.toml

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
[package]
22
name = "mock-ft"
33
description = "Mocked Fungible Token Contract for Testing"
4-
version = "0.1.0"
5-
edition = "2021"
6-
# NEP-0330 is automatically implemented for all contracts built with https://github.com/near/cargo-near.
7-
# Link to the repository will be available via `contract_source_metadata` view-function.
8-
repository = "https://github.com/Near-One/tee-solver/tree/main/contracts/mock-ft"
4+
version.workspace = true
5+
edition.workspace = true
6+
repository.workspace = true
97

108
[lib]
119
crate-type = ["cdylib", "rlib"]
1210

13-
# fields to configure build with WASM reproducibility, according to specs
14-
# in https://github.com/near/NEPs/blob/master/neps/nep-0330.md
11+
# fields to configure build with WASM reproducibility, according to specs
12+
# in https://github.com/near/NEPs/blob/master/neps/nep-0330.md
1513
[package.metadata.near.reproducible_build]
1614
# docker image, descriptor of build environment
1715
image = "sourcescan/cargo-near:0.14.1-rust-1.86.0"
@@ -21,7 +19,7 @@ image_digest = "sha256:eaac91be3119cc7c136b6f375f2d3e092001f717ed6151ccc9d5348c2
2119
# in a reproducible manner
2220
# supported by `sourcescan/cargo-near:0.10.1-rust-1.82.0` image or later images
2321
passed_env = []
24-
# build command inside of docker container
22+
# build command inside of docker container
2523
# if docker image from default gallery is used https://hub.docker.com/r/sourcescan/cargo-near/tags,
2624
# the command may be any combination of flags of `cargo-near`,
2725
# supported by respective version of binary inside the container besides `--no-locked` flag
@@ -35,13 +33,5 @@ container_build_command = [
3533

3634
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
3735
[dependencies]
38-
near-sdk = "5.14.0"
39-
near-contract-standards = "5.14.0"
40-
serde_json = "1.0.140"
41-
42-
[dev-dependencies]
43-
near-sdk = { version = "5.14.0", features = ["unit-testing"] }
44-
tokio = "1.44.1"
45-
anyhow = "1.0.97"
46-
near-workspaces = { version = "0.20.1", features = ["unstable"]}
47-
near-gas = "0.3.0"
36+
near-sdk = "5"
37+
near-contract-standards = "5"

contracts/mock-ft/res/mock_ft.wasm

-926 Bytes
Binary file not shown.

contracts/mock-ft/src/lib.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use near_contract_standards::fungible_token::metadata::{
2-
FungibleTokenMetadata, FungibleTokenMetadataProvider, FT_METADATA_SPEC,
2+
FT_METADATA_SPEC, FungibleTokenMetadata, FungibleTokenMetadataProvider,
33
};
44
use near_contract_standards::fungible_token::{
55
FungibleToken, FungibleTokenCore, FungibleTokenResolver,
@@ -10,7 +10,7 @@ use near_contract_standards::storage_management::{
1010
use near_sdk::borsh::BorshSerialize;
1111
use near_sdk::collections::LazyOption;
1212
use near_sdk::json_types::U128;
13-
use near_sdk::{log, near, AccountId, BorshStorageKey, NearToken, PanicOnDefault, PromiseOrValue};
13+
use near_sdk::{AccountId, BorshStorageKey, NearToken, PanicOnDefault, PromiseOrValue, log, near};
1414

1515
#[derive(PanicOnDefault)]
1616
#[near(contract_state)]
@@ -33,11 +33,13 @@ impl Contract {
3333
/// Initializes the contract with the given total supply owned by the given `owner_id` with
3434
/// default metadata (for example purposes only).
3535
#[init]
36-
pub fn new_default_meta(owner_id: AccountId, total_supply: U128) -> Self {
36+
#[must_use]
37+
#[allow(clippy::use_self)]
38+
pub fn new_default_meta(owner_id: &AccountId, total_supply: U128) -> Self {
3739
Self::new(
3840
owner_id,
3941
total_supply,
40-
FungibleTokenMetadata {
42+
&FungibleTokenMetadata {
4143
spec: FT_METADATA_SPEC.to_string(),
4244
name: "Mocked Fungible Token".to_string(),
4345
symbol: "MOCKED".to_string(),
@@ -52,17 +54,19 @@ impl Contract {
5254
/// Initializes the contract with the given total supply owned by the given `owner_id` with
5355
/// the given fungible token metadata.
5456
#[init]
55-
pub fn new(owner_id: AccountId, total_supply: U128, metadata: FungibleTokenMetadata) -> Self {
57+
#[must_use]
58+
#[allow(clippy::use_self)]
59+
pub fn new(owner_id: &AccountId, total_supply: U128, metadata: &FungibleTokenMetadata) -> Self {
5660
metadata.assert_valid();
5761
let mut this = Self {
5862
token: FungibleToken::new(StorageKey::FungibleToken),
59-
metadata: LazyOption::new(StorageKey::Metadata, Some(&metadata)),
63+
metadata: LazyOption::new(StorageKey::Metadata, Some(metadata)),
6064
};
61-
this.token.internal_register_account(&owner_id);
62-
this.token.internal_deposit(&owner_id, total_supply.into());
65+
this.token.internal_register_account(owner_id);
66+
this.token.internal_deposit(owner_id, total_supply.into());
6367

6468
near_contract_standards::fungible_token::events::FtMint {
65-
owner_id: &owner_id,
69+
owner_id,
6670
amount: total_supply,
6771
memo: Some("new tokens are minted"),
6872
}
@@ -76,7 +80,7 @@ impl Contract {
7680
impl FungibleTokenCore for Contract {
7781
#[payable]
7882
fn ft_transfer(&mut self, receiver_id: AccountId, amount: U128, memo: Option<String>) {
79-
self.token.ft_transfer(receiver_id, amount, memo)
83+
self.token.ft_transfer(receiver_id, amount, memo);
8084
}
8185

8286
#[payable]

contracts/mock-intents/Cargo.toml

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
[package]
22
name = "mock-intents"
33
description = "Mocked Intents Contract for Testing"
4-
version = "0.1.0"
5-
edition = "2021"
6-
# NEP-0330 is automatically implemented for all contracts built with https://github.com/near/cargo-near.
7-
# Link to the repository will be available via `contract_source_metadata` view-function.
8-
repository = "https://github.com/Near-One/tee-solver/tree/main/contracts/mock-intents"
4+
version.workspace = true
5+
edition.workspace = true
6+
repository.workspace = true
97

108
[lib]
119
crate-type = ["cdylib", "rlib"]
1210

13-
# fields to configure build with WASM reproducibility, according to specs
14-
# in https://github.com/near/NEPs/blob/master/neps/nep-0330.md
11+
# fields to configure build with WASM reproducibility, according to specs
12+
# in https://github.com/near/NEPs/blob/master/neps/nep-0330.md
1513
[package.metadata.near.reproducible_build]
1614
# docker image, descriptor of build environment
1715
image = "sourcescan/cargo-near:0.14.1-rust-1.86.0"
@@ -21,7 +19,7 @@ image_digest = "sha256:eaac91be3119cc7c136b6f375f2d3e092001f717ed6151ccc9d5348c2
2119
# in a reproducible manner
2220
# supported by `sourcescan/cargo-near:0.10.1-rust-1.82.0` image or later images
2321
passed_env = []
24-
# build command inside of docker container
22+
# build command inside of docker container
2523
# if docker image from default gallery is used https://hub.docker.com/r/sourcescan/cargo-near/tags,
2624
# the command may be any combination of flags of `cargo-near`,
2725
# supported by respective version of binary inside the container besides `--no-locked` flag
@@ -35,12 +33,7 @@ container_build_command = [
3533

3634
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
3735
[dependencies]
38-
near-sdk = "5.14.0"
39-
serde_json = "1.0.140"
36+
near-sdk = "5"
4037

41-
[dev-dependencies]
42-
near-sdk = { version = "5.14.0", features = ["unit-testing"] }
43-
tokio = "1.44.1"
44-
anyhow = "1.0.97"
45-
near-workspaces = { version = "0.20.1", features = ["unstable"]}
46-
near-gas = "0.3.0"
38+
[lints]
39+
workspace = true
-1.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)