Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ chia-sdk-driver = { version = "0.33.0", path = "./crates/chia-sdk-driver" }
chia-sdk-signer = { version = "0.33.0", path = "./crates/chia-sdk-signer" }
chia-sdk-test = { version = "0.33.0", path = "./crates/chia-sdk-test" }
chia-sdk-types = { version = "0.33.0", path = "./crates/chia-sdk-types" }
chia-sdk-puzzles = { version = "0.33.0", path = "./crates/chia-sdk-puzzles" }
chia-sdk-derive = { version = "0.33.0", path = "./crates/chia-sdk-types/derive" }
chia-sdk-utils = { version = "0.33.0", path = "./crates/chia-sdk-utils" }
chia-sdk-coinset = { version = "0.33.0", path = "./crates/chia-sdk-coinset" }
Expand Down
31 changes: 31 additions & 0 deletions bindings/conditions.json
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,14 @@
"singleton_inner_puzzle_hash": "Option<Bytes32>"
}
},
"SetCatTradeContext": {
"type": "class",
"new": true,
"fields": {
"trade_nonce": "Bytes32",
"trade_prices": "Vec<TransferFeeTradePrice>"
}
},
"RunCatTail": {
"type": "class",
"new": true,
Expand Down Expand Up @@ -302,5 +310,28 @@
"amount": "u64",
"puzzle_hash": "Bytes32"
}
},
"TransferFeeTradePrice": {
"type": "class",
"new": true,
"remote": true,
"fields": {
"amount": "u64",
"asset_id": "Option<Bytes32>",
"quote_hidden_puzzle_hash": "Option<Bytes32>",
"quote_fee_policy": "Option<TransferFeeQuoteFeePolicy>"
}
},
"TransferFeeQuoteFeePolicy": {
"type": "class",
"new": true,
"remote": true,
"fields": {
"issuer_fee_puzzle_hash": "Bytes32",
"fee_basis_points": "u16",
"min_fee": "u64",
"allow_zero_price": "bool",
"allow_revoke_fee_bypass": "bool"
}
}
}
1 change: 1 addition & 0 deletions crates/chia-sdk-bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ chia-sdk-driver = { workspace = true, features = ["offer-compression", "action-l
chia-sdk-coinset = { workspace = true, features = ["native-tls"] }
chia-sdk-test = { workspace = true }
chia-sdk-types = { workspace = true }
chia-sdk-puzzles = { workspace = true }
chia-sdk-client = { workspace = true, optional = true, features = ["native-tls"] }
chia-ssl = { workspace = true, optional = true }
chia-protocol = { workspace = true }
Expand Down
10 changes: 5 additions & 5 deletions crates/chia-sdk-bindings/src/action_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use chia_puzzle_types::{Memos, offer::SettlementPaymentsSolution};
use chia_sdk_driver::{
self as sdk, Cat, Delta, HashedPtr, Layer, Relation, SettlementLayer, SpendContext, SpendKind,
};
use chia_sdk_types::{Condition, conditions::TradePrice};
use chia_sdk_types::{Condition, conditions::TradePrice as NftTradePrice};
use clvm_traits::{FromClvm, ToClvm};
use clvmr::NodePtr;

Expand Down Expand Up @@ -258,8 +258,8 @@ impl PendingSpend {
}

pub fn as_cat(&self) -> Result<Option<Cat>> {
match self.asset {
sdk::SpendableAsset::Cat(cat) => Ok(Some(cat)),
match &self.asset {
sdk::SpendableAsset::Cat(cat) => Ok(Some(*cat)),
_ => Ok(None),
}
}
Expand Down Expand Up @@ -287,7 +287,7 @@ impl PendingSpend {
}

#[derive(Clone)]
pub struct Action(sdk::Action);
pub struct Action(pub(crate) sdk::Action);

impl Action {
pub fn send(id: Id, puzzle_hash: Bytes32, amount: u64, memos: Option<Program>) -> Result<Self> {
Expand Down Expand Up @@ -481,5 +481,5 @@ impl Outputs {
#[derive(Clone)]
pub struct TransferNftById {
pub owner_id: Option<Id>,
pub trade_prices: Vec<TradePrice>,
pub trade_prices: Vec<NftTradePrice>,
}
6 changes: 6 additions & 0 deletions crates/chia-sdk-bindings/src/clvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,12 @@ impl Clvm {
.map(|n| n.as_program(&self.0)))
}

pub fn offer_trade_nonce(&self, offer: SpendBundle) -> Result<Bytes32> {
let mut ctx = self.0.lock().unwrap();
let offer = Offer::from_spend_bundle(&mut ctx, &offer)?;
Ok(offer.trade_nonce()?)
}

pub fn parse_vault_transaction(
&self,
vault: VaultSpendReveal,
Expand Down
14 changes: 13 additions & 1 deletion crates/chia-sdk-bindings/src/conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use bindy::Result;
use chia_bls::PublicKey;
use chia_protocol::{Bytes, Bytes32};
use chia_sdk_driver::SpendContext;
use chia_sdk_types::conditions::{self, Memos, TradePrice};
use chia_sdk_types::{
conditions::{self, Memos, TradePrice},
puzzles::TransferFeeTradePrice,
};
use clvm_traits::{FromClvm, ToClvm};
use clvmr::NodePtr;
use paste::paste;
Expand Down Expand Up @@ -69,6 +72,12 @@ impl Convert<TradePrice> for TradePrice {
}
}

impl Convert<TransferFeeTradePrice> for TransferFeeTradePrice {
fn convert(self, _clvm: &Arc<Mutex<SpendContext>>) -> Result<TransferFeeTradePrice> {
Ok(self)
}
}

impl Convert<Memos<NodePtr>> for Option<Program> {
fn convert(self, _clvm: &Arc<Mutex<SpendContext>>) -> Result<Memos<NodePtr>> {
Ok(self.map_or(Memos::None, |program| Memos::Some(program.1)))
Expand Down Expand Up @@ -252,6 +261,9 @@ conditions!(
TransferNft {
transfer_nft(launcher_id: Option<Bytes32>, trade_prices: Vec<TradePrice>, singleton_inner_puzzle_hash: Option<Bytes32>)
},
SetCatTradeContext {
set_cat_trade_context(trade_nonce: Bytes32, trade_prices: Vec<TransferFeeTradePrice>)
},
RunCatTail<NodePtr, NodePtr> {
run_cat_tail(program: Program, solution: Program)
},
Expand Down
2 changes: 2 additions & 0 deletions crates/chia-sdk-bindings/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use bindy::Result;
use chia_protocol::Program;
use chia_puzzles::*;
use chia_sdk_puzzles::{FEE_LAYER_V1, FEE_LAYER_V1_HASH};
use chia_sdk_types::puzzles::*;
use clvm_utils::TreeHash;
use paste::paste;
Expand Down Expand Up @@ -47,6 +48,7 @@ puzzle_constants! {
augmented_condition => AUGMENTED_CONDITION,
block_program_zero => BLOCK_PROGRAM_ZERO,
cat_puzzle => CAT_PUZZLE,
fee_layer_v1 => FEE_LAYER_V1,
chialisp_deserialisation => CHIALISP_DESERIALISATION,
conditions_w_fee_announce => CONDITIONS_W_FEE_ANNOUNCE,
covenant_layer => COVENANT_LAYER,
Expand Down
6 changes: 4 additions & 2 deletions crates/chia-sdk-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,16 @@ pub use chia_sdk_driver::{
MedievalVaultHint, MedievalVaultInfo, MetadataUpdate, NftState, OptionInfo, OptionMetadata,
OptionType, OptionUnderlying, P2ParentCoin, ParsedNftTransfer, ParsedPayment,
RewardDistributorConstants, RewardDistributorState, RewardDistributorType, RoundRewardInfo,
RoundTimeInfo, StreamedAsset, StreamingPuzzleInfo, TransferType, UriKind, VaultInfo,
VaultTransaction,
RoundTimeInfo, StreamedAsset, StreamingPuzzleInfo, TransferFeeInfo, TransferFeePolicy,
TransferType, UriKind, VaultInfo, VaultTransaction,
};
pub use chia_sdk_types::{
conditions::TradePrice,
puzzles::{
IntermediaryCoinProof, NftLauncherProof, RewardDistributorCommitmentSlotValue,
RewardDistributorEntrySlotValue, RewardDistributorRewardSlotValue,
TRANSFER_FEE_TRADE_PRICE_ASSET_KIND_CAT, TRANSFER_FEE_TRADE_PRICE_ASSET_KIND_XCH,
TransferFeeQuoteFeePolicy, TransferFeeTradePrice,
},
};

Expand Down
1 change: 1 addition & 0 deletions crates/chia-sdk-driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ offer-compression = ["dep:flate2", "dep:chia-sdk-utils"]

[dependencies]
chia-sdk-signer = { workspace = true }
chia-sdk-puzzles = { workspace = true }
chia-bls = { workspace = true }
chia-consensus = { workspace = true }
chia-secp = { workspace = true }
Expand Down
7 changes: 3 additions & 4 deletions crates/chia-sdk-driver/src/action_system/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ use chia_puzzle_types::{
use hex_literal::hex;

use crate::{
CreateDidAction, Delta, Deltas, DriverError, FeeAction, HashedPtr, Id, IssueCatAction,
MeltSingletonAction, MintNftAction, MintOptionAction, OptionType, RunTailAction, SendAction,
SettleAction, Spend, SpendContext, Spends, TailIssuance, TransferNftById, UpdateDidAction,
UpdateNftAction,
CreateDidAction, Delta, Deltas, DriverError, FeeAction, HashedPtr, Id, IssueCatAction, MeltSingletonAction,
MintNftAction, MintOptionAction, OptionType, RunTailAction, SendAction, SettleAction, Spend, SpendContext,
Spends, TailIssuance, TransferNftById, UpdateDidAction, UpdateNftAction,
};

pub const BURN_PUZZLE_HASH: Bytes32 = Bytes32::new(hex!(
Expand Down
10 changes: 5 additions & 5 deletions crates/chia-sdk-driver/src/action_system/fungible_spends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,25 +142,25 @@ where

pub fn intermediate_settlement_source(&mut self) -> Result<Option<usize>, DriverError> {
let Some((index, amount)) = self.items.iter().enumerate().find_map(|(index, item)| {
let settlement_p2_puzzle_hash = SETTLEMENT_PAYMENT_HASH.into();
item.kind
.find_amount(SETTLEMENT_PAYMENT_HASH.into(), &item.asset.constraints())
.find_amount(settlement_p2_puzzle_hash, &item.asset.constraints())
.map(|amount| (index, amount))
}) else {
return Ok(None);
};

let source = &mut self.items[index];
let settlement_p2_puzzle_hash = SETTLEMENT_PAYMENT_HASH.into();

source.kind.create_intermediate_coin(CreateCoin::new(
SETTLEMENT_PAYMENT_HASH.into(),
settlement_p2_puzzle_hash,
amount,
Memos::None,
));

let child = FungibleSpend::new(
source
.asset
.make_child(SETTLEMENT_PAYMENT_HASH.into(), amount),
source.asset.make_child(settlement_p2_puzzle_hash, amount),
true,
);

Expand Down
13 changes: 5 additions & 8 deletions crates/chia-sdk-driver/src/action_system/spends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,10 @@ impl Spends<Unfinished> {
);
}
SpendKind::Settlement(spend) => {
coin_spends.insert(
asset.coin().coin_id(),
SettlementLayer.construct_spend(
ctx,
SettlementPaymentsSolution::new(spend.finish()),
)?,
);
let solution = SettlementPaymentsSolution::new(spend.finish());
let spend = SettlementLayer.construct_spend(ctx, solution)?;

coin_spends.insert(asset.coin().coin_id(), spend);
}
}
}
Expand Down Expand Up @@ -542,7 +539,7 @@ impl Spends<Finished> {
ctx.spend(item.asset, spend)?;
}

for cat in self.cats.into_values() {
for (_, cat) in self.cats {
let mut cat_spends = Vec::new();
for item in cat.items {
let spend = coin_spends
Expand Down
2 changes: 1 addition & 1 deletion crates/chia-sdk-driver/src/actions/mint_option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl MintOptionAction {
.cats
.entry(self.underlying_id)
.or_default()
.push(cat);
.push(cat.clone());

return Ok(cat.coin_id());
} else if let Some(nft) = spends.nfts.get_mut(&self.underlying_id) {
Expand Down
Loading