Skip to content

Commit

Permalink
Merge branch 'develop' into fee-info
Browse files Browse the repository at this point in the history
  • Loading branch information
cwlittle committed Dec 21, 2023
2 parents 9877aae + d8eb41d commit f333986
Show file tree
Hide file tree
Showing 14 changed files with 162 additions and 210 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "nomic"
version = "6.6.0"
authors = ["The Nomic Team <hello@nomic.io>"]
version = "7.0.0"
authors = ["The Turbofish Team <hello@turbofish.org>"]
edition = "2021"
default-run = "nomic"

[dependencies]
bitcoin = { version = "0.29.2", features = ["serde", "rand"] }
orga = { git = "https://github.com/nomic-io/orga.git", rev = "3d422b1702841b9ebb76878d7336d6fa68729c91", features = [
orga = { git = "https://github.com/nomic-io/orga.git", rev = "eef75df69fcb8ee0eb788feae376d7edec36ac6f", features = [
"merk-verify",
] }
thiserror = "1.0.30"
Expand Down Expand Up @@ -66,7 +66,7 @@ toml = { version = "0.7.2", features = ["parse"] }
semver = "1.0.18"

[features]
default = ["full", "feat-ibc", "testnet", "legacy-bin"]
default = ["full", "feat-ibc", "legacy-bin"]
full = [
"bitcoincore-rpc-async",
"clap",
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn main() {
#[cfg(feature = "testnet")]
let default_features = "full,feat-ibc,testnet";
#[cfg(not(feature = "testnet"))]
let default_features = "full";
let default_features = "full,feat-ibc";

let cargo_features =
std::env::var("NOMIC_LEGACY_FEATURES").unwrap_or(default_features.to_string());
Expand Down
3 changes: 1 addition & 2 deletions networks/stakenet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ btc_relayer = [
"https://relayer.nomic.mappum.io:8443"
]

upgrade_height = 9357000
legacy_version = "3.0.2"
legacy_version = "6.0.x"

genesis = """
{
Expand Down
6 changes: 3 additions & 3 deletions rest/Cargo.lock

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

163 changes: 56 additions & 107 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ const STRATEGIC_RESERVE_ADDRESS: &str = "nomic1d5n325zrf4elfu0heqd59gna5j6xyunhe
#[cfg(feature = "full")]
const VALIDATOR_BOOTSTRAP_ADDRESS: &str = "nomic1fd9mxxt84lw3jdcsmjh6jy8m6luafhqd8dcqeq";

#[cfg(feature = "testnet")]
const IBC_FEE_USATS: u64 = 1_000_000;
const DECLARE_FEE_USATS: u64 = 100_000_000;

Expand Down Expand Up @@ -93,14 +92,20 @@ pub struct InnerApp {
#[cfg(feature = "testnet")]
#[call]
pub ibc: Ibc,
#[cfg(not(feature = "testnet"))]
#[orga(version(V4))]
#[call]
pub ibc: Ibc,

pub upgrade: Upgrade,

#[call]
pub incentives: Incentives,

#[cfg(feature = "testnet")]
#[orga(version(V3, V4))]
pub cosmos: Cosmos,
#[cfg(not(feature = "testnet"))]
#[orga(version(V4))]
pub cosmos: Cosmos,
}

Expand Down Expand Up @@ -163,61 +168,43 @@ impl InnerApp {

#[call]
pub fn ibc_transfer_nbtc(&mut self, dest: IbcDest, amount: Amount) -> Result<()> {
#[cfg(feature = "testnet")]
{
crate::bitcoin::exempt_from_fee()?;
crate::bitcoin::exempt_from_fee()?;

dest.source_port()?;
dest.source_channel()?;
dest.sender_address()?;
dest.source_port()?;
dest.source_channel()?;
dest.sender_address()?;

let signer = self.signer()?;
let mut coins = self.bitcoin.accounts.withdraw(signer, amount)?;
let signer = self.signer()?;
let mut coins = self.bitcoin.accounts.withdraw(signer, amount)?;

let fee = ibc_fee(amount)?;
let fee = coins.take(fee)?;
self.bitcoin.reward_pool.give(fee)?;
let fee = ibc_fee(amount)?;
let fee = coins.take(fee)?;
self.bitcoin.reward_pool.give(fee)?;

let building = &mut self.bitcoin.checkpoints.building_mut()?;
let dest = Dest::Ibc(dest);
building.insert_pending(dest, coins)?;
let building = &mut self.bitcoin.checkpoints.building_mut()?;
let dest = Dest::Ibc(dest);
building.insert_pending(dest, coins)?;

Ok(())
}

#[cfg(not(feature = "testnet"))]
Err(orga::Error::Unknown)
Ok(())
}

#[call]
pub fn ibc_withdraw_nbtc(&mut self, amount: Amount) -> Result<()> {
#[cfg(feature = "testnet")]
{
crate::bitcoin::exempt_from_fee()?;

let signer = self.signer()?;
let coins: Coin<Nbtc> = amount.into();
self.ibc
.transfer_mut()
.burn_coins_execute(&signer, &coins.into())?;
self.bitcoin.accounts.deposit(signer, amount.into())?;
crate::bitcoin::exempt_from_fee()?;

Ok(())
}
let signer = self.signer()?;
let coins: Coin<Nbtc> = amount.into();
self.ibc
.transfer_mut()
.burn_coins_execute(&signer, &coins.into())?;
self.bitcoin.accounts.deposit(signer, amount.into())?;

#[cfg(not(feature = "testnet"))]
Err(orga::Error::Unknown)
Ok(())
}

#[query]
pub fn escrowed_nbtc(&self, address: Address) -> Result<Amount> {
#[cfg(feature = "testnet")]
{
self.ibc.transfer().symbol_balance::<Nbtc>(address)
}

#[cfg(not(feature = "testnet"))]
Err(orga::Error::Unknown)
self.ibc.transfer().symbol_balance::<Nbtc>(address)
}

#[call]
Expand Down Expand Up @@ -262,24 +249,16 @@ impl InnerApp {
op_addr: Proof,
acc: Proof,
) -> Result<()> {
#[cfg(feature = "testnet")]
{
self.deduct_nbtc_fee(IBC_FEE_USATS.into())?;
self.deduct_nbtc_fee(IBC_FEE_USATS.into())?;

Ok(self
.cosmos
.relay_op_key(&self.ibc, client_id, height, cons_key, op_addr, acc)?)
}
#[cfg(not(feature = "testnet"))]
Err(orga::Error::Unknown)
Ok(self
.cosmos
.relay_op_key(&self.ibc, client_id, height, cons_key, op_addr, acc)?)
}

pub fn credit_transfer(&mut self, dest: Dest, nbtc: Coin<Nbtc>) -> Result<()> {
match dest {
Dest::Address(addr) => self.bitcoin.accounts.deposit(addr, nbtc),
#[cfg(not(feature = "testnet"))]
Dest::Ibc(dest) => Err(Error::Unknown),
#[cfg(feature = "testnet")]
Dest::Ibc(dest) => dest.transfer(nbtc, &mut self.bitcoin, &mut self.ibc),
}
}
Expand Down Expand Up @@ -317,39 +296,34 @@ impl InnerApp {

#[call]
pub fn ibc_deliver(&mut self, messages: RawIbcTx) -> Result<()> {
#[cfg(feature = "testnet")]
{
self.deduct_nbtc_fee(IBC_FEE_USATS.into())?;
let incoming_transfers = self.ibc.deliver(messages)?;
self.deduct_nbtc_fee(IBC_FEE_USATS.into())?;
let incoming_transfers = self.ibc.deliver(messages)?;

for transfer in incoming_transfers {
if transfer.denom.to_string() != "usat" {
continue;
}
let memo: NbtcMemo = transfer.memo.parse().unwrap_or_default();
if let NbtcMemo::Withdraw(script) = memo {
let amount = transfer.amount;
let receiver: Address = transfer
.receiver
.parse()
.map_err(|_| Error::Coins("Invalid address".to_string()))?;
for transfer in incoming_transfers {
if transfer.denom.to_string() != "usat" {
continue;
}
let memo: NbtcMemo = transfer.memo.parse().unwrap_or_default();
if let NbtcMemo::Withdraw(script) = memo {
let amount = transfer.amount;
let receiver: Address = transfer
.receiver
.parse()
.map_err(|_| Error::Coins("Invalid address".to_string()))?;
let coins = Coin::<Nbtc>::mint(amount);
self.ibc
.transfer_mut()
.burn_coins_execute(&receiver, &coins.into())?;
if self.bitcoin.add_withdrawal(script, amount.into()).is_err() {
let coins = Coin::<Nbtc>::mint(amount);
self.ibc
.transfer_mut()
.burn_coins_execute(&receiver, &coins.into())?;
if self.bitcoin.add_withdrawal(script, amount.into()).is_err() {
let coins = Coin::<Nbtc>::mint(amount);
self.ibc
.transfer_mut()
.mint_coins_execute(&receiver, &coins.into())?;
}
.mint_coins_execute(&receiver, &coins.into())?;
}
}

Ok(())
}
#[cfg(not(feature = "testnet"))]
Err(orga::Error::Unknown)

Ok(())
}

#[call]
Expand Down Expand Up @@ -458,7 +432,6 @@ mod abci {
)?;
self.staking.begin_block(ctx)?;

#[cfg(feature = "testnet")]
self.ibc.begin_block(ctx)?;

let has_stake = self.staking.staked()? > 0;
Expand All @@ -483,13 +456,8 @@ mod abci {
}

let external_outputs = if self.bitcoin.should_push_checkpoint()? {
#[cfg(feature = "testnet")]
{
self.cosmos
.build_outputs(&self.ibc, self.bitcoin.checkpoints.index)?
}
#[cfg(not(feature = "testnet"))]
vec![]
self.cosmos
.build_outputs(&self.ibc, self.bitcoin.checkpoints.index)?
} else {
vec![]
};
Expand Down Expand Up @@ -519,7 +487,6 @@ mod abci {
}
}

#[cfg(feature = "testnet")]
impl AbciQuery for InnerApp {
fn abci_query(&self, request: &messages::RequestQuery) -> Result<messages::ResponseQuery> {
self.ibc.abci_query(request)
Expand All @@ -534,7 +501,6 @@ impl ConvertSdkTx for InnerApp {
let sender_address = sdk_tx.sender_address()?;
match sdk_tx {
SdkTx::Protobuf(tx) => {
#[cfg(feature = "testnet")]
if IbcTx::try_from(tx.clone()).is_ok() {
let raw_ibc_tx = RawIbcTx(tx.clone());
let payer = build_call!(self.ibc_deliver(raw_ibc_tx));
Expand Down Expand Up @@ -815,22 +781,6 @@ impl ConvertSdkTx for InnerApp {
Ok(PaidCall { payer, paid })
}

#[cfg(feature = "stakenet")]
"nomic/MsgClaimTestnetParticipationAirdrop" => {
let msg = msg
.value
.as_object()
.ok_or_else(|| Error::App("Invalid message value".to_string()))?;
if !msg.is_empty() {
return Err(Error::App("Message should be empty".to_string()));
}

let payer = build_call!(self.airdrop.claim_testnet_participation());
let paid = build_call!(self.accounts.give_from_funding_all());

Ok(PaidCall { payer, paid })
}

"nomic/MsgWithdraw" => {
let msg: MsgWithdraw = serde_json::value::from_value(msg.value.clone())
.map_err(|e| Error::App(e.to_string()))?;
Expand Down Expand Up @@ -867,7 +817,6 @@ impl ConvertSdkTx for InnerApp {
Ok(PaidCall { payer, paid })
}

#[cfg(feature = "testnet")]
"nomic/MsgIbcTransferOut" => {
let msg: MsgIbcTransfer = serde_json::value::from_value(msg.value.clone())
.map_err(|e| Error::App(e.to_string()))?;
Expand Down
Loading

0 comments on commit f333986

Please sign in to comment.