Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to FT-141 for BridgeToken #39

Merged
merged 22 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
74 changes: 60 additions & 14 deletions bridge-token-factory/Cargo.lock

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

9 changes: 6 additions & 3 deletions bridge-token-factory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ panic = "abort"
overflow-checks = true

[dependencies]
near-sdk = { git = "https://github.com/near/near-sdk-rs", rev = "af0e826f916f3aa3ea51e8b675ecebdd37176671" }
near-contract-standards = { git = "https://github.com/near/near-sdk-rs", rev = "af0e826f916f3aa3ea51e8b675ecebdd37176671" }
near-sdk = { git = "https://github.com/near/near-sdk-rs", rev = "613adcab6322e4f830efb4d5bde2a810ae642158" }
near-contract-standards = { git = "https://github.com/near/near-sdk-rs", rev = "613adcab6322e4f830efb4d5bde2a810ae642158" }
#near-sdk = { path = "../../near-sdk-rs/near-sdk" }
#near-contract-standards = { path = "../../near-sdk-rs/near-contract-standards" }
serde = { version = "*", features = ["derive"] }
serde_json = "*"
uint = { version = "0.8.3", default-features = false }
Expand All @@ -31,7 +33,8 @@ hex = "0.4.2"
tiny-keccak = "1.4.0"

[dev-dependencies]
near-sdk-sim = { git = "https://github.com/near/near-sdk-rs", rev = "af0e826f916f3aa3ea51e8b675ecebdd37176671" }
near-sdk-sim = { git = "https://github.com/near/near-sdk-rs", rev = "613adcab6322e4f830efb4d5bde2a810ae642158" }
#near-sdk-sim = { path = "../../near-sdk-rs/near-sdk-sim" }
test-token = { git = "https://github.com/mfornet/contracts" }
bridge-token = { path = "../bridge-token" }
mock-prover = { path = "../mock-prover" }
Expand Down
12 changes: 4 additions & 8 deletions bridge-token-factory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,21 +191,18 @@ impl BridgeTokenFactory {
assert_self();
assert!(verification_success, "Failed to verify the proof");

let initial_storage_usage = env::storage_usage();
self.record_proof(&proof);
let storage_used = env::storage_usage() - initial_storage_usage;
let balance_required = storage_used as u128 * STORAGE_PRICE_PER_BYTE;
let required_deposit = self.record_proof(&proof);

assert!(
env::attached_deposit()
>= balance_required + self.bridge_token_storage_deposit_required
>= required_deposit + self.bridge_token_storage_deposit_required
);

ext_bridge_token::mint(
new_owner_id,
amount.into(),
&self.get_bridge_token_account_id(token),
env::attached_deposit() - balance_required,
env::attached_deposit() - required_deposit,
env::prepaid_gas() / 2,
);
}
Expand Down Expand Up @@ -351,10 +348,9 @@ impl BridgeTokenFactory {
);
self.used_events.insert(&key);
let current_storage = env::storage_usage();
let attached_deposit = env::attached_deposit();
let required_deposit =
Balance::from(current_storage - initial_storage) * STORAGE_PRICE_PER_BYTE;
attached_deposit - required_deposit
required_deposit
}
}

Expand Down
Loading