-
Notifications
You must be signed in to change notification settings - Fork 5
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
} | ||
|
||
inline fun getShardFromAddress(addr: Slice): Int { | 8000||
addr.skipBits(11); |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this 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"; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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
Closes #150