Skip to content

Commit

Permalink
feat: properly added json/borsh schemas for abi generation
Browse files Browse the repository at this point in the history
  • Loading branch information
frolvanya committed Jan 16, 2025
1 parent 9bd4358 commit 9c5916d
Show file tree
Hide file tree
Showing 20 changed files with 139 additions and 177 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ clippy-omni-relayer:
cargo clippy --manifest-path $(OMNI_RELAYER_MANIFEST) -- $(LINT_OPTIONS)

rust-build-omni-bridge:
cargo near build non-reproducible-wasm --manifest-path $(OMNI_BRIDGE_MANIFEST) --no-abi
cargo near build non-reproducible-wasm --manifest-path $(OMNI_BRIDGE_MANIFEST)

rust-build-omni-token:
cargo near build non-reproducible-wasm --manifest-path $(OMNI_TOKEN_MANIFEST) --no-abi
cargo near build non-reproducible-wasm --manifest-path $(OMNI_TOKEN_MANIFEST)

rust-build-token-deployer:
cargo near build non-reproducible-wasm --manifest-path $(TOKEN_DEPLOYER) --no-abi
cargo near build non-reproducible-wasm --manifest-path $(TOKEN_DEPLOYER)

rust-build-mock-prover:
cargo near build non-reproducible-wasm --manifest-path $(MOCK_PROVER_MANIFEST) --no-abi
cargo near build non-reproducible-wasm --manifest-path $(MOCK_PROVER_MANIFEST)

rust-build-mock-token:
cargo near build non-reproducible-wasm --manifest-path $(MOCK_TOKEN_MANIFEST) --no-abi
cargo near build non-reproducible-wasm --manifest-path $(MOCK_TOKEN_MANIFEST)

rust-build-near: rust-build-omni-bridge rust-build-omni-token rust-build-token-deployer rust-build-mock-prover rust-build-mock-token

Expand Down
47 changes: 20 additions & 27 deletions near/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion near/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ panic = "abort"
overflow-checks = true

[workspace.dependencies]
cargo-near-build = "0.4.2"
cargo-near-build = "0.3.0"
near-sdk = "5.7.0"
near-contract-standards = "5.7.0"
hex = "0.4.2"
Expand Down
2 changes: 1 addition & 1 deletion near/mock/mock-token/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use near_sdk::{
env, log, near, require, AccountId, BorshStorageKey, NearToken, PanicOnDefault, PromiseOrValue,
};

#[derive(PanicOnDefault)]
#[near(contract_state)]
#[derive(PanicOnDefault)]
pub struct Contract {
token: FungibleToken,
metadata: LazyOption<FungibleTokenMetadata>,
Expand Down
1 change: 0 additions & 1 deletion near/omni-bridge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ hex.workspace = true
borsh.workspace = true
serde.workspace = true
near-plugins.workspace = true
schemars.workspace = true
omni-types.workspace = true

[dev-dependencies]
Expand Down
16 changes: 9 additions & 7 deletions near/omni-bridge/src/storage.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
use near_contract_standards::storage_management::{StorageBalance, StorageBalanceBounds};
use near_sdk::{assert_one_yocto, borsh};
use near_sdk::{assert_one_yocto, borsh, near};
use near_sdk::{env, near_bindgen, AccountId, NearToken};
use omni_types::TransferId;
use schemars::JsonSchema;

use crate::{
require, BorshDeserialize, BorshSerialize, ChainKind, Contract, ContractExt, Deserialize, Fee,
OmniAddress, Promise, SdkExpect, Serialize, TransferMessage, U128,
require, ChainKind, Contract, ContractExt, Fee, OmniAddress, Promise, SdkExpect,
TransferMessage, U128,
};

pub const BRIDGE_TOKEN_INIT_BALANCE: NearToken = NearToken::from_near(3);
pub const NEP141_DEPOSIT: NearToken = NearToken::from_yoctonear(1_250_000_000_000_000_000_000);

#[derive(JsonSchema, BorshDeserialize, BorshSerialize, Serialize, Deserialize, Debug, Clone)]
#[near(serializers=[borsh, json])]
#[derive(Debug, Clone)]
pub struct TransferMessageStorageValue {
pub message: TransferMessage,
pub owner: AccountId,
}

#[derive(BorshDeserialize, BorshSerialize, Serialize, Deserialize, Debug, Clone)]
#[near(serializers=[borsh, json])]
#[derive(Debug, Clone)]
pub enum TransferMessageStorage {
V0(TransferMessageStorageValue),
}
Expand All @@ -41,7 +42,8 @@ impl TransferMessageStorage {
}
}

#[derive(BorshDeserialize, BorshSerialize, Debug, Clone, Copy, PartialEq, Eq)]
#[near(serializers=[borsh, json])]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Decimals {
pub decimals: u8,
pub origin_decimals: u8,
Expand Down
10 changes: 6 additions & 4 deletions near/omni-prover/evm-prover/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
use near_sdk::{env, ext_contract, near_bindgen, require, AccountId, Gas, PanicOnDefault, Promise};
use borsh::BorshDeserialize;
use near_sdk::{
env, ext_contract, near, near_bindgen, require, AccountId, Gas, PanicOnDefault, Promise,
};
use omni_types::evm::events::parse_evm_event;
use omni_types::evm::header::BlockHeader;
use omni_types::evm::receipt::{LogEntry, Receipt};
Expand All @@ -23,8 +25,8 @@ pub trait EvmClient {
fn block_hash_safe(&self, #[serializer(borsh)] index: u64) -> Option<H256>;
}

#[near_bindgen]
#[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)]
#[near(contract_state)]
#[derive(PanicOnDefault)]
pub struct EvmProver {
pub light_client: AccountId,
pub chain_kind: ChainKind,
Expand Down
4 changes: 2 additions & 2 deletions near/omni-prover/omni-prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ enum StorageKey {
RegisteredProvers,
}

#[near_bindgen]
#[derive(BorshDeserialize, BorshSerialize, PanicOnDefault, Pausable, Upgradable)]
#[near(contract_state)]
#[derive(PanicOnDefault, Pausable, Upgradable)]
#[access_control(role_type(Role))]
#[pausable(manager_roles(Role::PauseManager, Role::DAO))]
#[upgradable(access_control_roles(
Expand Down
9 changes: 5 additions & 4 deletions near/omni-prover/wormhole-omni-prover-proxy/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
use near_sdk::borsh::BorshDeserialize;
use near_sdk::{
env, ext_contract, near_bindgen, require, AccountId, Gas, PanicOnDefault, Promise, PromiseError,
env, ext_contract, near, near_bindgen, require, AccountId, Gas, PanicOnDefault, Promise,
PromiseError,
};
use omni_types::prover_args::WormholeVerifyProofArgs;
use omni_types::prover_result::{ProofKind, ProverResult};
Expand All @@ -16,8 +17,8 @@ pub trait Prover {
fn verify_vaa(&self, vaa: &str) -> u32;
}

#[near_bindgen]
#[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)]
#[near(contract_state)]
#[derive(PanicOnDefault)]
pub struct WormholeOmniProverProxy {
pub prover_account: AccountId,
}
Expand Down
4 changes: 0 additions & 4 deletions near/omni-tests/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub mod tests {
cargo_near_build::camino::Utf8PathBuf::from_str("../mock/mock-token/Cargo.toml")
.expect("camino PathBuf from str"),
),
no_abi: true,
..Default::default()
})
.expect("building `mock-token` contract for tests");
Expand All @@ -31,7 +30,6 @@ pub mod tests {
cargo_near_build::camino::Utf8PathBuf::from_str("../mock/mock-prover/Cargo.toml")
.expect("camino PathBuf from str"),
),
no_abi: true,
..Default::default()
})
.expect("building `mock-prover` contract for tests");
Expand All @@ -44,7 +42,6 @@ pub mod tests {
cargo_near_build::camino::Utf8PathBuf::from_str("../omni-bridge/Cargo.toml")
.expect("camino PathBuf from str"),
),
no_abi: true,
..Default::default()
})
.expect("building `omni-bridge` contract for tests");
Expand All @@ -57,7 +54,6 @@ pub mod tests {
cargo_near_build::camino::Utf8PathBuf::from_str("../token-deployer/Cargo.toml")
.expect("camino PathBuf from str"),
),
no_abi: true,
..Default::default()
})
.expect("building `token-deployer` contract for tests");
Expand Down
2 changes: 1 addition & 1 deletion near/omni-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["Near Inc <[email protected]>"]
edition = "2021"

[dependencies]
near-sdk = { workspace = true, features = ["abi"] }
near-sdk.workspace = true
near-contract-standards.workspace = true
hex.workspace = true
borsh.workspace = true
Expand Down
Loading

0 comments on commit 9c5916d

Please sign in to comment.