forked from broxus/nekoton
-
Notifications
You must be signed in to change notification settings - Fork 5
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
[pull] master from broxus:master #14
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d4716e5
Split wallet-core from nekoton
0xdeafbeef 08068f6
Merge remote-tracking branch 'github/push-ypsuoxkxvqvz'
Rexagon 0f1a118
Move token wallet stuff into `nekoton-contracts`
Rexagon 0e51815
Bump chacha20poly1305 version to 0.10.1
pashinov f8c669b
Fix warnings
pashinov 7c04f5c
chore: replace lru with quick cache
0xdeafbeef 82e682e
Fix clippy warnings
pashinov 9b4d401
fix(utils): fix total fees computation
Rexagon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use nekoton_abi::num_bigint::BigUint; | ||
use nekoton_utils::*; | ||
use serde::{Deserialize, Serialize}; | ||
use ton_block::MsgAddressInt; | ||
|
||
pub use self::root_token_contract::RootTokenContractState; | ||
pub use self::token_wallet_contract::TokenWalletContractState; | ||
|
||
mod root_token_contract; | ||
mod token_wallet_contract; | ||
|
||
define_string_enum!( | ||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)] | ||
pub enum TokenWalletVersion { | ||
/// Third iteration of token wallets, but with fixed bugs | ||
/// [implementation](https://github.com/broxus/ton-eth-bridge-token-contracts/tree/74905260499d79cf7cb0d89a6eb572176fc1fcd5) | ||
OldTip3v4, | ||
/// Latest iteration with completely new standard | ||
/// [implementation](https://github.com/broxus/ton-eth-bridge-token-contracts/tree/9168190f218fd05a64269f5f24295c69c4840d94) | ||
Tip3, | ||
} | ||
); | ||
|
||
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] | ||
pub struct RootTokenContractDetails { | ||
/// Token ecosystem version | ||
pub version: TokenWalletVersion, | ||
/// Full currency name | ||
pub name: String, | ||
/// Short currency name | ||
pub symbol: String, | ||
/// Decimals | ||
pub decimals: u8, | ||
/// Root owner contract address. Used as proxy address in Tip3v1 | ||
#[serde(with = "serde_address")] | ||
pub owner_address: MsgAddressInt, | ||
#[serde(with = "serde_string")] | ||
pub total_supply: BigUint, | ||
} | ||
|
||
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct TokenWalletDetails { | ||
/// Linked root token contract address | ||
#[serde(with = "serde_address")] | ||
pub root_address: MsgAddressInt, | ||
|
||
/// Owner wallet address | ||
#[serde(with = "serde_address")] | ||
pub owner_address: MsgAddressInt, | ||
|
||
#[serde(with = "serde_string")] | ||
pub balance: BigUint, | ||
} | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum Tip3Error { | ||
#[error("Unknown version")] | ||
UnknownVersion, | ||
#[error("Wallet not deployed")] | ||
WalletNotDeployed, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use nekoton_abi::ExecutionContext; | ||
use ton_block::MsgAddressInt; | ||
|
||
use super::{RootTokenContractDetails, Tip3Error, TokenWalletVersion}; | ||
use crate::{old_tip3, tip3, tip3_1, tip6}; | ||
|
||
pub struct RootTokenContractState<'a>(pub ExecutionContext<'a>); | ||
|
||
impl RootTokenContractState<'_> { | ||
/// Calculates token wallet address | ||
pub fn get_wallet_address( | ||
&self, | ||
version: TokenWalletVersion, | ||
owner: &MsgAddressInt, | ||
) -> anyhow::Result<MsgAddressInt> { | ||
match version { | ||
TokenWalletVersion::OldTip3v4 => { | ||
old_tip3::RootTokenContract(self.0).get_wallet_address(owner.clone()) | ||
} | ||
TokenWalletVersion::Tip3 => tip3_1::RootTokenContract(self.0).wallet_of(owner.clone()), | ||
} | ||
} | ||
|
||
/// Tries to guess version and retrieve details | ||
pub fn guess_details(&self) -> anyhow::Result<RootTokenContractDetails> { | ||
if let Ok(true) = tip6::SidContract(self.0).supports_interfaces(&[ | ||
tip3::root_token_contract::INTERFACE_ID, | ||
tip3_1::root_token_contract::INTERFACE_ID, | ||
]) { | ||
return self.get_details(TokenWalletVersion::Tip3); | ||
} | ||
|
||
let version = match old_tip3::RootTokenContract(self.0).get_version()? { | ||
4 => TokenWalletVersion::OldTip3v4, | ||
_ => anyhow::bail!(Tip3Error::UnknownVersion), | ||
}; | ||
|
||
self.get_details(version) | ||
} | ||
|
||
/// Retrieve details using specified version | ||
pub fn get_details( | ||
&self, | ||
version: TokenWalletVersion, | ||
) -> anyhow::Result<RootTokenContractDetails> { | ||
Ok(match version { | ||
TokenWalletVersion::OldTip3v4 => { | ||
let details = old_tip3::RootTokenContract(self.0).get_details()?; | ||
|
||
RootTokenContractDetails { | ||
version, | ||
name: details.name, | ||
symbol: details.symbol, | ||
decimals: details.decimals, | ||
owner_address: details.root_owner_address, | ||
total_supply: details.total_supply, | ||
} | ||
} | ||
TokenWalletVersion::Tip3 => { | ||
let root_contract = tip3::RootTokenContract(self.0); | ||
let name = root_contract.name()?; | ||
let symbol = root_contract.symbol()?; | ||
let decimals = root_contract.decimals()?; | ||
let total_supply = root_contract.total_supply()?; | ||
|
||
let root_contract = tip3_1::RootTokenContract(self.0); | ||
let owner_address = root_contract.root_owner()?; | ||
|
||
RootTokenContractDetails { | ||
version, | ||
name, | ||
symbol, | ||
decimals, | ||
owner_address, | ||
total_supply, | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use nekoton_abi::num_bigint::BigUint; | ||
use nekoton_abi::ExecutionContext; | ||
|
||
use super::{Tip3Error, TokenWalletDetails, TokenWalletVersion}; | ||
use crate::{old_tip3, tip3, tip3_1, tip6}; | ||
|
||
pub struct TokenWalletContractState<'a>(pub ExecutionContext<'a>); | ||
|
||
impl<'a> TokenWalletContractState<'a> { | ||
pub fn get_code_hash(&self) -> anyhow::Result<ton_types::UInt256> { | ||
match &self.0.account_stuff.storage.state { | ||
ton_block::AccountState::AccountActive { state_init, .. } => { | ||
let code = state_init | ||
.code | ||
.as_ref() | ||
.ok_or(Tip3Error::WalletNotDeployed)?; | ||
Ok(code.repr_hash()) | ||
} | ||
_ => Err(Tip3Error::WalletNotDeployed.into()), | ||
} | ||
} | ||
|
||
pub fn get_balance(&self, version: TokenWalletVersion) -> anyhow::Result<BigUint> { | ||
match version { | ||
TokenWalletVersion::OldTip3v4 => old_tip3::TokenWalletContract(self.0).balance(), | ||
TokenWalletVersion::Tip3 => tip3::TokenWalletContract(self.0).balance(), | ||
} | ||
} | ||
|
||
pub fn get_details(&self, version: TokenWalletVersion) -> anyhow::Result<TokenWalletDetails> { | ||
Ok(match version { | ||
TokenWalletVersion::OldTip3v4 => { | ||
let details = old_tip3::TokenWalletContract(self.0).get_details()?; | ||
|
||
TokenWalletDetails { | ||
root_address: details.root_address, | ||
owner_address: details.owner_address, | ||
balance: details.balance, | ||
} | ||
} | ||
TokenWalletVersion::Tip3 => { | ||
let token_wallet = tip3::TokenWalletContract(self.0); | ||
let root_address = token_wallet.root()?; | ||
let balance = token_wallet.balance()?; | ||
|
||
let token_wallet = tip3_1::TokenWalletContract(self.0); | ||
let owner_address = token_wallet.owner()?; | ||
|
||
TokenWalletDetails { | ||
root_address, | ||
owner_address, | ||
balance, | ||
} | ||
} | ||
}) | ||
} | ||
|
||
pub fn get_version(&self) -> anyhow::Result<TokenWalletVersion> { | ||
if let Ok(true) = tip6::SidContract(self.0).supports_interfaces(&[ | ||
tip3::token_wallet_contract::INTERFACE_ID, | ||
tip3_1::token_wallet_contract::INTERFACE_ID, | ||
]) { | ||
return Ok(TokenWalletVersion::Tip3); | ||
} | ||
|
||
match old_tip3::TokenWalletContract(self.0).get_version()? { | ||
4 => Ok(TokenWalletVersion::OldTip3v4), | ||
_ => Err(Tip3Error::UnknownVersion.into()), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bitcoin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To whom it may concern please I need a full details