8000 feat: add sharded jetton by skywardboundd · Pull Request #154 · tact-lang/jetton · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add sharded jetton #154

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 17 commits into
base: main
Choose a base branch
from
Open

feat: add sharded jetton #154

wants to merge 17 commits into from

Conversation

skywardboundd
Copy link
Contributor
@skywardboundd skywardboundd commented May 12, 2025

Closes #150

  • Add Shard folder
  • Add Shard tests
  • Add shard contracts to base tests
  • Add shard scripts
  • Add shard ExtensionWrappers
  • Update Sandbox to latest version

@skywardboundd skywardboundd linked an issue May 12, 2025 that may be closed by this pull request
@skywardboundd skywardboundd changed the title first version feat: add shard jetton May 13, 2025
@skywardboundd skywardboundd marked this pull request as ready for review May 13, 2025 11:09
@skywardboundd skywardboundd requested review from Kaladin13 and Shvandre and removed request for Kaladin13 May 13, 2025 11:22
@anton-trunov anton-trunov changed the title feat: add shard jetton feat: add sharded jetton May 13, 2025
Copy link
Contributor
@Shvandre Shvandre left a comment

Choose a reason for hiding this comment

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

Huge work done here, I've added some comments but also two main one.

If we want to then copy that into stdlib we should refactor a lot of magic nubers here, they are literally in each function in shard-utils.tact.

And also I think we need to be consistent about new message/send/deploy style. Using two styles in the same time looks bad IMHO.

@@ -25,3 +25,4 @@ tonweb
utime
workchain
yada
Toncoins
Copy link
Contributor

Choose a reason for hiding this comment

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

not sorted lines

? BasechainAddress { hash: changeAddressHashShard(getJettonWalletInit(msg.ownerAddress).hash(), ownerShard) }
: emptyBasechainAddress();

message(MessageParameters {
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 change this to MessageParameters.send() to be consistent

self.totalSupply -= msg.amount;

if (msg.responseDestination != null) {
message(MessageParameters {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same refactor here

nativeReserve(minTonsForStorage, ReserveExact | ReserveBounceIfActionFail);

// we allow bounce here and don't handle it, if claim fails we just accept the TONs back
message(MessageParameters {
Copy link
Contributor

Choose a reason for hiding this comment

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

And here

return beginCell().storeUint(sl.loadUint(11), 11).storeUint(changeAddressHashShard(sl.loadUint(256), shard), 256).asSlice().loadAddress();
}

inline fun getShardFromAddress(addr: Slice): Int {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it's better to accept Address as a parameter and transform it into a Slice internally

8000
}

inline fun getShardFromAddress(addr: Slice): Int {
addr.skipBits(11);
Copy link
Contributor

Choose a reason for hiding this comment

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

please add a comment here, why it is 11

inline extends fun hasSameBasechainAddressShard(self: StateInit, sender: Address): Bool {
let senderAddress = parseStdAddress(sender.asSlice()).address;
let baseAddress = contractBasechainAddressShard(self);
return (baseAddress.hash!! & ((1 << (256 - prefixLength)) - 1)) == (senderAddress & ((1 << (256 - prefixLength)) - 1));
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you check LSHIFT group of instructions? Maybe some of them allows logical overflow

return addr.loadUint(prefixLength);
}

extends inline fun toShardCell(self: StateInit): Cell {
Copy link
Contributor

Choose a reason for hiding this comment

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

idk what is the prorer naming here, but toShardCell is confusing

Copy link
Contributor
@Kaladin13 Kaladin13 left a comment

Choose a reason for hiding this comment

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

Good job, but I am strongly against yet another separate folder for this impl. We need to add it to all current implementations as default functionality

Can you please describe what is pros/cons in this +1 folder approach?

@@ -0,0 +1,223 @@
import "./shard-utils";
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 group this to separate folder and add comments why we need it, or link the issue with tact-lang PR

SENDRAWMSG
}

extends inline fun send(self: ShardDeployParameters) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Definitely need comments here)

};
}

inline fun changeAddressHashShard(addr_hash: Int, shard: Int): Int {
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
inline fun changeAddressHashShard(addr_hash: Int, shard: Int): Int {
inline fun changeAddressHashShard(addrHash: Int, shard: Int): Int {

@@ -0,0 +1,70 @@
const prefixLength: Int = 8;

struct ShardDeployParameters {
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 add something like getShardNumber(addr: Address): Int as uint8;

return newStateInit;
}

inline fun contractBasechainAddressShard(s: StateInit): BasechainAddress {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't get what this function does from the name


extends inline fun toShardCell(self: StateInit): Cell {
let newStateInit = beginCell()
.storeUint(32 + prefixLength, 6)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why 6?

await blockchain.loadFrom(snapshot)
})

it("should deploy in the same shard", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

We need a lot more tests for this: failed deploy, different shards collision, different blockchain configs

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.

Add shard jetton
3 participants
0