Skip to content

Commit

Permalink
Simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Dec 27, 2024
1 parent aff8e25 commit a4eadeb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 43 deletions.
26 changes: 13 additions & 13 deletions crates/sage-wallet/src/wallet/offer/lock_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,18 @@ impl Wallet {
outputs.push(royalty_coin);
}

// TODO: This is a hack to make the puzzle non-conflicting, maybe there's a better amount or method
let non_conflicting_amount =
outputs.iter().map(|output| output.amount).sum::<u64>() + 1;
let remaining_amount = remaining_royalties
.iter()
.map(|royalty| royalty.amount)
.sum::<u64>();

if !remaining_royalties.is_empty() {
notarized_payments.push(NotarizedPayment {
// TODO: Make nonce nil as an optimization
nonce: Bytes32::default(),
payments: vec![Payment::new(
SETTLEMENT_PAYMENTS_PUZZLE_HASH.into(),
non_conflicting_amount,
remaining_amount,
)],
});
}
Expand All @@ -161,7 +162,7 @@ impl Wallet {
parent_royalty_coin = Coin::new(
parent_royalty_coin.coin_id(),
SETTLEMENT_PAYMENTS_PUZZLE_HASH.into(),
non_conflicting_amount,
remaining_amount,
);
}
}
Expand Down Expand Up @@ -257,17 +258,18 @@ impl Wallet {
outputs.push(royalty_cat.coin);
}

// TODO: This is a hack to make the puzzle non-conflicting, maybe there's a better amount or method
let non_conflicting_amount =
outputs.iter().map(|output| output.amount).sum::<u64>() + 1;
let remaining_amount = remaining_royalties
.iter()
.map(|royalty| royalty.amount)
.sum::<u64>();

if !remaining_royalties.is_empty() {
notarized_payments.push(NotarizedPayment {
// TODO: Make nonce nil as an optimization
nonce: Bytes32::default(),
payments: vec![Payment::new(
SETTLEMENT_PAYMENTS_PUZZLE_HASH.into(),
non_conflicting_amount,
remaining_amount,
)],
});
}
Expand All @@ -277,10 +279,8 @@ impl Wallet {

cat_spends.push(CatSpend::new(parent_royalty_cat, inner_spend));

parent_royalty_cat = parent_royalty_cat.wrapped_child(
SETTLEMENT_PAYMENTS_PUZZLE_HASH.into(),
non_conflicting_amount,
);
parent_royalty_cat = parent_royalty_cat
.wrapped_child(SETTLEMENT_PAYMENTS_PUZZLE_HASH.into(), remaining_amount);
}

Cat::spend_all(ctx, &cat_spends)?;
Expand Down
16 changes: 1 addition & 15 deletions crates/sage-wallet/src/wallet/offer/make_offer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,24 +155,10 @@ impl Wallet {
.count(),
)?;

let taker_royalties = calculate_royalties(
&taker_amounts,
&maker_coins
.nfts
.values()
.map(|nft| NftRoyaltyInfo {
launcher_id: nft.info.launcher_id,
royalty_puzzle_hash: nft.info.royalty_puzzle_hash,
royalty_ten_thousandths: nft.info.royalty_ten_thousandths,
})
.collect::<Vec<_>>(),
)?;

let (assertions, builder) = builder.finish();
let mut extra_conditions = Conditions::new()
.extend(assertions)
.extend(maker_royalties.assertions())
.extend(taker_royalties.assertions());
.extend(maker_royalties.assertions());

if let Some(expires_at) = expires_at {
extra_conditions = extra_conditions.assert_before_seconds_absolute(expires_at);
Expand Down
16 changes: 1 addition & 15 deletions crates/sage-wallet/src/wallet/offer/take_offer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,6 @@ impl Wallet {
let requested_payments = parse_offer_payments(&mut ctx, &mut builder)?;
let taker_amounts = requested_payments.amounts();

let maker_royalties = calculate_royalties(
&maker_amounts,
&requested_payments
.nfts
.values()
.map(|(nft, _)| NftRoyaltyInfo {
launcher_id: nft.launcher_id,
royalty_puzzle_hash: nft.royalty_puzzle_hash,
royalty_ten_thousandths: nft.royalty_ten_thousandths,
})
.collect::<Vec<_>>(),
)?;

let taker_royalties = calculate_royalties(
&taker_amounts,
&locked_coins
Expand Down Expand Up @@ -86,8 +73,7 @@ impl Wallet {

let extra_conditions = Conditions::new()
.extend(assertions)
.extend(taker_royalties.assertions())
.extend(maker_royalties.assertions());
.extend(taker_royalties.assertions());

// Spend the assets.
let payment_coins = self
Expand Down

0 comments on commit a4eadeb

Please sign in to comment.