Skip to content

Commit

Permalink
Remove double royalty counting
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Nov 11, 2024
1 parent 5660514 commit e99b4ba
Showing 1 changed file with 2 additions and 40 deletions.
42 changes: 2 additions & 40 deletions crates/sage-wallet/src/wallet/make_offer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use chia::{
},
};
use chia_wallet_sdk::{
calculate_nft_royalty, calculate_nft_trace_price, Condition, Conditions, HashedPtr, Layer,
NftInfo, Offer, OfferBuilder, SpendContext, StandardLayer, TradePrice,
calculate_nft_trace_price, Condition, Conditions, HashedPtr, Layer, NftInfo, Offer,
OfferBuilder, SpendContext, StandardLayer, TradePrice,
};
use indexmap::IndexMap;

Expand Down Expand Up @@ -119,44 +119,6 @@ impl Wallet {
)?;
}

// Add royalty payments for NFTs you are offering.
if !nfts.is_empty() {
for (asset_id, amount) in [(None, requested.xch)].into_iter().chain(
requested
.cats
.iter()
.map(|(asset_id, amount)| (Some(*asset_id), *amount)),
) {
let trade_price = calculate_nft_trace_price(amount, nfts.len())
.ok_or(WalletError::InvalidTradePrice)?;

for NftOfferSpend { nft, .. } in &nfts {
let royalty =
calculate_nft_royalty(trade_price, nft.info.royalty_ten_thousandths)
.ok_or(WalletError::InvalidRoyaltyAmount)?;

let mut puzzle = settlement;

if let Some(asset_id) = asset_id {
puzzle = ctx.alloc(&CurriedProgram {
program: cat,
args: CatArgs::new(asset_id, puzzle),
})?;
}

builder = builder.request(
&mut ctx,
&puzzle,
vec![Payment::with_memos(
nft.info.royalty_puzzle_hash,
royalty,
vec![nft.info.royalty_puzzle_hash.into()],
)],
)?;
}
}
}

// Add requested CAT payments.
for (asset_id, amount) in requested.cats {
builder = builder.request(
Expand Down

0 comments on commit e99b4ba

Please sign in to comment.