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

[Kiosk SDK] Support kiosk_lock_rule and environments #12287

Merged
merged 12 commits into from Jun 2, 2023

Conversation

manolisliolios
Copy link
Contributor

@manolisliolios manolisliolios commented Jun 1, 2023

Description

In this PR:

  • (breaking) Change signature of purchaseAndResolvePolicies to a) support environments (e.g. mainnet, testnet) and b) accept extraParams (to support kiosk_lock_rule).
  • Support for kiosk_lock_rule, enabling the SDK to fully support strong royalties enforcement.
  • (breaking) Change return of purchaseAndResolvePolicies to include the item + canTransfer flag (whether it can be transferred or not, based on the ruleset).
  • Isolate the Types of the Kiosk SDK and export them all properly (from ./types directory).
  • Reuse types in bcs definitions.
  • Convert functions to plain format (instead of arrow fns) for consistency.
  • Fixes withdrawFromKiosk and withdrawFromPolicy call amount params.

Test Plan

How did you test the new or updated feature?

Right now the changes are tested on the Demo Kiosk dapp that is being developed in parallel. We'll need to start creating a testing suite for the SDK, as we start finalizing our requirements.


If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process.

Type of Change (Check all that apply)

  • protocol change
  • user-visible impact
  • breaking change for a client SDKs
  • breaking change for FNs (FN binary must upgrade)
  • breaking change for validators or node operators (must upgrade binaries)
  • breaking change for on-chain data layout
  • necessitate either a data wipe or data migration

Release notes

Adds support for kiosk_lock_rule and environments (testnet, mainnet, custom) for the purchase flows. Fixes withdrawFromKiosk and withdrawFromPolicy.

@vercel
Copy link

vercel bot commented Jun 1, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
offline-signer-helper ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 2, 2023 4:04pm
4 Ignored Deployments
Name Status Preview Comments Updated (UTC)
explorer ⬜️ Ignored (Inspect) Jun 2, 2023 4:04pm
explorer-storybook ⬜️ Ignored (Inspect) Jun 2, 2023 4:04pm
sui-wallet-kit ⬜️ Ignored (Inspect) Jun 2, 2023 4:04pm
wallet-adapter ⬜️ Ignored (Inspect) Jun 2, 2023 4:04pm

Copy link
Contributor

@damirka damirka left a comment

Choose a reason for hiding this comment

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

Looks good, left some comments. Approving to unblock.

import {
KIOSK_PURCHASE_CAP,
KIOSK_TYPE,
TRANSFER_POLICY_CREATED_EVENT,
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be great if we had a function to create generic events of kind: transferPolicyCreated(type): 0x2:....::Created<${type}>. Wonder what you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@damirka Could you elaborate a bit on that?

policy.bcs.bcsBytes,
'base64',
);
let parsed = bcs.de(TRANSFER_POLICY_TYPE, policy.bcs.bcsBytes, 'base64');

return {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that we could help provide initialSharedVersion for shared transfer policy. That could help build arguments for the purchase flow.

sdk/kiosk/src/tx/kiosk.ts Outdated Show resolved Hide resolved
@@ -200,20 +203,16 @@ export function purchase(
tx: TransactionBlock,
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we call txb to align with other places?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this sdk, we have it defined as tx everywhere!
Does other places refer to the @mysten/sui.js sdk?

@@ -200,20 +203,16 @@ export function purchase(
tx: TransactionBlock,
itemType: string,
Copy link
Contributor

Choose a reason for hiding this comment

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

Some argument grouping / ordering would help. Eg kioskId, itemId, itemType?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was trying to follow the same ordering we had on the other ones. (itemType was always first)

sdk/kiosk/src/tx/kiosk.ts Outdated Show resolved Hide resolved
// if we don't pass the listing or the listing doens't have a price, return.
if (!listing || listing?.price === undefined) return null;
if (!listing || listing?.price === undefined)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's just require price. Perhaps, instead we should require Coin... the reason for it is that developers might choose a custom coin and not use gas for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point for the price!
I like the Coin idea, I think though that this is a nice generic solution for 3-line purchase flows.
Maybe we should support more advanced use-case variations for ideas like this, by possibly extending extraParams in the future to support coin, etc.

sdk/kiosk/src/tx/kiosk.ts Outdated Show resolved Hide resolved
sdk/kiosk/src/types/env.ts Show resolved Hide resolved
sdk/kiosk/src/types/transfer-policy.ts Outdated Show resolved Hide resolved
@manolisliolios manolisliolios merged commit 9683043 into main Jun 2, 2023
36 checks passed
@manolisliolios manolisliolios deleted the ml/kiosk-sdk-enhancements branch June 2, 2023 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants