Skip to content
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

feat(move/examples): implementation of kiosk marketplace extension using kiosk rules #4156

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from

Conversation

Dkwcs
Copy link
Contributor

@Dkwcs Dkwcs commented Nov 20, 2024

Description of change

New Kiosk extensions have been added in order to demonstrate practical usage of some Kiosk features(extensions, rules, transfer policies).

Links to any relevant issues

Fix #3997 .

Type of change

  • Enhancement (a non-breaking change which adds functionality)

How the change has been tested

Read https://github.com/iotaledger/iota/pull/4156/files#diff-ed4b688332b92ef7cc237545e28cac0a73f64d2e509737d8e95cc72a6b82831d

@Dkwcs Dkwcs added the team-vm-language Issues related to the VM & Language Team label Nov 20, 2024
@Dkwcs Dkwcs self-assigned this Nov 20, 2024
Copy link
Contributor

@miker83z miker83z left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good example! What do you think about creating a documentation page with the text of the README?

docs/examples/move/nft_marketplace/README.md Show resolved Hide resolved
docs/examples/move/nft_marketplace/README.md Show resolved Hide resolved
docs/examples/move/nft_marketplace/README.md Show resolved Hide resolved
docs/examples/move/nft_marketplace/README.md Outdated Show resolved Hide resolved
docs/examples/move/nft_marketplace/README.md Show resolved Hide resolved
@Dkwcs Dkwcs marked this pull request as ready for review November 26, 2024 13:14
@Dkwcs Dkwcs requested a review from a team as a code owner November 26, 2024 13:14
@Dkwcs Dkwcs requested review from valeriyr, nonast and a team November 26, 2024 13:14
Copy link

✅ Vercel Preview Deployment is ready!

View Preview

Copy link

✅ Vercel Preview Deployment is ready!

View Preview

Copy link

✅ Vercel Preview Deployment is ready!

View Preview

Copy link

✅ Vercel Preview Deployment is ready!

View Preview

@Dkwcs Dkwcs changed the title feat(move/examples): draft of kiosk nft marketplace using kiosk rules feat(move/examples): implementation of kiosk marketplace extension using kiosk rules Nov 27, 2024
Comment on lines +63 to +77
assert!(kiosk_extension::is_installed<Marketplace>(kiosk), EExtensionNotInstalled);
let ItemPrice { price } = take_from_bag<T, Listed>(kiosk, Listed { id: item_id });

let payment_amount_value = payment.value();
let coin_price = payment.split(price, ctx);

let (item, mut transfer_request) = purchase(kiosk, item_id, coin_price);
if (policy.has_rule<T, RoyaltyRule>()) {
let royalties_value = royalty_rule::fee_amount(policy, price);
assert!(payment_amount_value == price + royalties_value, EWrongPaymentRoyalties);
royalty_rule::pay(policy, &mut transfer_request, payment);
} else {
payment.destroy_zero();
};
transfer_policy::confirm_request(policy, transfer_request);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert!(kiosk_extension::is_installed<Marketplace>(kiosk), EExtensionNotInstalled);
let ItemPrice { price } = take_from_bag<T, Listed>(kiosk, Listed { id: item_id });
let payment_amount_value = payment.value();
let coin_price = payment.split(price, ctx);
let (item, mut transfer_request) = purchase(kiosk, item_id, coin_price);
if (policy.has_rule<T, RoyaltyRule>()) {
let royalties_value = royalty_rule::fee_amount(policy, price);
assert!(payment_amount_value == price + royalties_value, EWrongPaymentRoyalties);
royalty_rule::pay(policy, &mut transfer_request, payment);
} else {
payment.destroy_zero();
};
transfer_policy::confirm_request(policy, transfer_request);
assert!(kiosk_extension::is_installed<Marketplace>(kiosk), EExtensionNotInstalled);
// Get item price
let ItemPrice { price } = take_from_bag<T, Listed>(kiosk, Listed { id: item_id });
// Compute the value of the coin in input
let payment_amount_value = payment.value();
// Prepare the payment coin for the purchase (if no royalties are present then the
// remaining balance will be 0 after this operation)
let coin_price = payment.split(price, ctx);
// Purchase and create the transfer request
let (item, mut transfer_request) = purchase(kiosk, item_id, coin_price);
// If the royalty is present, then update the request with a royalty payment
if (policy.has_rule<T, RoyaltyRule>()) {
let royalties_value = royalty_rule::fee_amount(policy, price);
assert!(payment_amount_value == price + royalties_value, EWrongPaymentRoyalties);
royalty_rule::pay(policy, &mut transfer_request, payment);
} else {
// Else clean the input coin (if the input payment amount is not exact, this will fail)
payment.destroy_zero();
};
// Confirm the request
transfer_policy::confirm_request(policy, transfer_request);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-vm-language Issues related to the VM & Language Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[kiosk] Create an example NFT marketplace using the Kiosk framework, document it and suggest improvements
2 participants