Skip to content

Commit

Permalink
feat: non forked near sdk and new nitka
Browse files Browse the repository at this point in the history
  • Loading branch information
VladasZ committed Apr 17, 2024
1 parent 8f42aa6 commit dc7628c
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 513 deletions.
563 changes: 110 additions & 453 deletions Cargo.lock

Large diffs are not rendered by default.

13 changes: 5 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ rand = "0.8.5"
anyhow = "1.0.79"
tokio = "1.36"

nitka = "0.1.1"
nitka-proc = "0.1.1"
nitka = "0.3.0"
nitka-proc = "0.3.0"

claim-model = { path = "model" }
sweat-model = { git = "https://github.com/sweatco/sweat-near", rev = "1fee5d917dc1f2eeb91ba4ac65eef35f173e9a47" }
sweat-model = { git = "https://github.com/sweatco/sweat-near", rev = "eb9947f95359df8f007575e16636705f79edb01d" }

near-workspaces = "0.10.0"
near-sdk = { git = "https://github.com/sweatco/near-sdk-rs", rev = "8c48b26cc48d969c1e5f3162141fe9c824fccecd" }
near-contract-standards = { git = "https://github.com/sweatco/near-sdk-rs", rev = "8c48b26cc48d969c1e5f3162141fe9c824fccecd" }

[patch.crates-io]
near-sdk = { git = "https://github.com/sweatco/near-sdk-rs", rev = "8c48b26cc48d969c1e5f3162141fe9c824fccecd" }
near-sdk = "5.1.0"
near-contract-standards = "5.1.0"
2 changes: 1 addition & 1 deletion contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ integration-test = ["claim-model/release-api", "claim-model/integration-methods"
integration-api = ["claim-model/integration-api"]

[dependencies]
near-sdk = { workspace = true }
near-sdk = { workspace = true, features = ["unit-testing"] }

claim-model = { workspace = true }
13 changes: 9 additions & 4 deletions contract/src/burn/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ impl Contract {
pub(crate) mod prod {
use claim_model::{TokensAmount, UnixTimestamp};
use near_sdk::{
env, ext_contract, is_promise_success, json_types::U128, near_bindgen, serde_json::json, Gas, Promise,
PromiseOrValue,
env, ext_contract, is_promise_success, json_types::U128, near_bindgen, serde_json::json, Gas, NearToken,
Promise, PromiseOrValue,
};

use crate::{Contract, ContractExt};
Expand Down Expand Up @@ -123,10 +123,15 @@ pub(crate) mod prod {
.to_vec();

Promise::new(self.token_account_id.clone())
.function_call("burn".to_string(), args, 0, Gas(5 * Gas::ONE_TERA.0))
.function_call(
"burn".to_string(),
args,
NearToken::from_yoctonear(0),
Gas::from_tgas(5),
)
.then(
ext_self::ext(env::current_account_id())
.with_static_gas(Gas(5 * Gas::ONE_TERA.0))
.with_static_gas(Gas::from_tgas(5))
.on_burn(total_to_burn, keys_to_remove),
)
.into()
Expand Down
12 changes: 9 additions & 3 deletions contract/src/claim/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ impl Contract {
mod prod {
use claim_model::{ClaimResultView, TokensAmount, UnixTimestamp};
use near_sdk::{
env, ext_contract, is_promise_success, near_bindgen, serde_json::json, AccountId, Gas, Promise, PromiseOrValue,
env, ext_contract, is_promise_success, near_bindgen, serde_json::json, AccountId, Gas, NearToken, Promise,
PromiseOrValue,
};

use crate::{Contract, ContractExt};
Expand Down Expand Up @@ -206,10 +207,15 @@ mod prod {
.to_vec();

Promise::new(self.token_account_id.clone())
.function_call("ft_transfer".to_string(), args, 1, Gas(5 * Gas::ONE_TERA.0))
.function_call(
"ft_transfer".to_string(),
args,
NearToken::from_yoctonear(1),
Gas::from_tgas(5),
)
.then(
ext_self::ext(env::current_account_id())
.with_static_gas(Gas(5 * Gas::ONE_TERA.0))
.with_static_gas(Gas::from_tgas(5))
.on_transfer(now, account_id, total_accrual, details),
)
.into()
Expand Down
10 changes: 5 additions & 5 deletions contract/src/common/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ pub(crate) struct TestAccounts {
impl Default for TestAccounts {
fn default() -> Self {
Self {
alice: AccountId::new_unchecked("alice".to_string()),
bob: AccountId::new_unchecked("bob".to_string()),
oracle: AccountId::new_unchecked("oracle".to_string()),
token: AccountId::new_unchecked("token".to_string()),
owner: AccountId::new_unchecked("owner".to_string()),
alice: "alice".to_string().try_into().unwrap(),
bob: "bob".to_string().try_into().unwrap(),
oracle: "oracle".to_string().try_into().unwrap(),
token: "token".to_string().try_into().unwrap(),
owner: "owner".to_string().try_into().unwrap(),
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions contract/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use claim_model::{account_record::AccountRecord, api::InitApi, Duration, TokensAmount, UnixTimestamp};
use near_sdk::{
borsh::{self, BorshDeserialize, BorshSerialize},
near_bindgen,
near, near_bindgen,
store::{LookupMap, UnorderedMap, UnorderedSet, Vector},
AccountId, BorshStorageKey, PanicOnDefault,
};
Expand All @@ -18,8 +17,8 @@ const INITIAL_CLAIM_PERIOD_MS: u32 = 24 * 60 * 60;
const INITIAL_BURN_PERIOD_MS: u32 = 30 * 24 * 60 * 60;

/// The main structure representing a smart contract for managing fungible tokens.
#[near_bindgen]
#[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)]
#[near(contract_state)]
#[derive(PanicOnDefault)]
pub struct Contract {
/// The account ID of the fungible token contract serviced by this smart contract.
///
Expand Down Expand Up @@ -82,7 +81,8 @@ pub struct Contract {
is_service_call_running: bool,
}

#[derive(BorshStorageKey, BorshSerialize)]
#[near]
#[derive(BorshStorageKey)]
enum StorageKey {
Accounts,
Accruals,
Expand Down
10 changes: 6 additions & 4 deletions integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ use claim_model::{
api::{BurnApiIntegration, ClaimApiIntegration},
ClaimAvailabilityView,
};
use near_sdk::{
json_types::{U128, U64},
serde_json::json,
use nitka::{
misc::ToNear,
near_sdk::{
json_types::{U128, U64},
serde_json::json,
},
};
use nitka::misc::ToNear;
use sweat_model::{FungibleTokenCoreIntegration, Payout, SweatApiIntegration, SweatContract, SweatDeferIntegration};

use crate::{
Expand Down
31 changes: 14 additions & 17 deletions integration-tests/src/measure/record_batch_for_hold.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#![cfg(test)]

use std::future::IntoFuture;

use anyhow::Result;
use claim_model::api::RecordApiIntegration;
use near_sdk::json_types::U128;
use near_workspaces::types::Gas;
use nitka::measure::{
measure::scoped_command_measure,
outcome_storage::OutcomeStorage,
utils::{pretty_gas_string, values_diff},
use nitka::{
measure::{
measure::scoped_command_measure,
utils::{pretty_gas_string, values_diff},
},
near_sdk::{json_types::U128, AccountId},
};

use crate::{prepare::IntegrationContext, prepare_contract};
Expand Down Expand Up @@ -63,7 +62,7 @@ async fn measure_record_batch_for_hold(count: usize) -> Result<Gas> {

let oracle = context.manager().await?;

let records: Vec<_> = (0..count)
let records: Vec<(AccountId, U128)> = (0..count)
.map(|i| {
(
format!("acc_{i}sdasaddsaadsdasdsadsa").try_into().unwrap(),
Expand All @@ -72,15 +71,13 @@ async fn measure_record_batch_for_hold(count: usize) -> Result<Gas> {
})
.collect();

let (gas, _) = OutcomeStorage::measure_total(
&oracle,
context
.sweat_claim()
.record_batch_for_hold(records)
.with_user(&oracle)
.into_future(),
)
.await?;
let gas = context
.sweat_claim()
.record_batch_for_hold(records)
.with_user(&oracle)
.result()
.await?
.total_gas_burnt;

Ok(gas)
}
3 changes: 1 addition & 2 deletions integration-tests/src/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use claim_model::{
api::{AuthApiIntegration, ClaimContract, ConfigApiIntegration, InitApiIntegration},
Duration,
};
use near_sdk::json_types::U128;
use near_workspaces::Account;
use nitka::misc::ToNear;
use nitka::{misc::ToNear, near_sdk::json_types::U128};
use sweat_model::{StorageManagementIntegration, SweatApiIntegration, SweatContract};

const FT_CONTRACT: &str = "sweat";
Expand Down
7 changes: 2 additions & 5 deletions model/src/account_record.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use near_sdk::{
borsh,
borsh::{BorshDeserialize, BorshSerialize},
};
use near_sdk::near;

use crate::{AccrualIndex, UnixTimestamp};

Expand All @@ -10,7 +7,7 @@ use crate::{AccrualIndex, UnixTimestamp};
/// `AccountRecord` maintains the status and history of an individual user's account within
/// the smart contract. It tracks various aspects of the account, such as accrual references,
/// claim history, and operational states.
#[derive(BorshDeserialize, BorshSerialize)]
#[near]
pub struct AccountRecord {
/// A list of references to accrual entries in `Contract.accruals`.
///
Expand Down
11 changes: 5 additions & 6 deletions model/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#[cfg(feature = "release-api")]
use near_sdk::AccountId;
use near_sdk::{json_types::U128, PromiseOrValue};
// #[cfg(feature = "integration-api")]
use near_sdk::{json_types::U128, AccountId};
#[cfg(feature = "integration-api")]
use nitka::near_sdk;
use nitka_proc::make_integration_version;

use crate::{BurnStatus, ClaimAvailabilityView, ClaimResultView, Duration};
Expand Down Expand Up @@ -136,7 +135,7 @@ pub trait BurnApi {
/// authority to initiate the burn process.
///
/// Panics if another service call is running.
fn burn(&mut self) -> PromiseOrValue<U128>;
fn burn(&mut self) -> ::near_sdk::PromiseOrValue<U128>;

fn get_burn_status(&self, account_id: AccountId) -> BurnStatus;
}
Expand Down Expand Up @@ -211,5 +210,5 @@ pub trait ClaimApi {
///
/// Panics if the claim is unavailable at the moment of calling. Users should ensure that
/// their claim is available using the `is_claim_available` method prior to calling this.
fn claim(&mut self) -> PromiseOrValue<ClaimResultView>;
fn claim(&mut self) -> ::near_sdk::PromiseOrValue<ClaimResultView>;
}
Binary file modified res/sweat_claim.wasm
Binary file not shown.

0 comments on commit dc7628c

Please sign in to comment.