Skip to content

Global Record && SBT Record #4

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
64 changes: 64 additions & 0 deletions src/global-record.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Global Record

|||
|-|-|
| **Name** | Global Record |
| **Origin** | [Pika](https://github.com/RandyPen) |
| **Example** | [Movescriptions](https://github.com/movescriptions/movescriptions/blob/main/sui/sources/movescription.move#L233) / [Pika](https://github.com/RandyPen) |
| **Depends on** | None |
| **Known to work on** | Move |

## Summary

In many fully on-chain applications, users continuously creating new activities. The web frontend needs to promptly fetch and present these activities to all users. Relying on Event log searches for this data can be time-intensive and detract from the user experience.

Implementing a shared Object to track these new activities can significantly expedite the frontend's retrieval speed, enhancing the overall user experience.

If the activity records are only continually expanding, the **Global Record** structure should be designed to accommodate this growth.
```move
public struct Deployer has key {
id: UID,
record: TableVec<ID>,
}
```

When launching new activities, include the Deployer as a parameter within the function call.
```move
public fun new_game(deployer: &mut Deployer, ..., ctx: &mut TxContext) {
let game = { id: object::new(ctx), ... };
table_vec::push_back<ID>(&mut deployer.record, object::id(&game));
transfer::share_object(game);
}
```

If activities are both initiated and eventually completed, the **Global Record** structure should be defined to encompass both the initiation and conclusion of these activities.
```move
public struct Deployer has key {
id: UID,
open: Table<ID, bool>,
closed: TableVec<ID>,
}
```

In initiating new activities

```move
public fun new_game(deployer: &mut Deployer, ..., ctx: &mut TxContext) {
let game = { id: object::new(ctx), ... };
table::add<ID, bool>(&mut deployer.open, object::id(&game), true);
transfer::share_object(game);
}
```

When terminating an activity
```move
public fun close_game(deployer: &mut Deployer, game: &mut Game, ..., ctx: &mut TxContext) {
...
let _ = table::remove<ID, bool>(&mut deployer.open, object::id(game));
table_vec::push_back<ID>(&mut deployer.closed, object::id(game));
...
}
```


## Examples
40 changes: 40 additions & 0 deletions src/sbt-record.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# SBT Record

|||
|-|-|
| **Name** | SBT Record |
| **Origin** | [Pika](https://github.com/RandyPen) |
| **Example** | |
| **Depends on** | None |
| **Known to work on** | Move |

## Summary

In many fully on-chain applications, it is necessary to record the activities that users have participated in, to help them remember which activities they have engaged in and to allow them to check results or claim rewards.

Soulbound Tokens (SBTs) can be distributed to users, encapsulating a record of their engagement with various activities.

Define SBT.
```move
public struct Ticket has key {
id: UID,
record: Table<ID, bool>,
}
```

When users participate in activities.

```move
public fun participant_activity(ticket: &mut Ticket, game: &mut Game, ...) {
...
if (!table::contains(&ticket.record, object::id(&game))) {
table::add<ID, bool>(&mut ticket.record, object::id(&game), true);
};
...
}
```

Upon users redeeming their rewards for an activity, the participation record should be archived or removed.

## Examples

Loading