-
Notifications
You must be signed in to change notification settings - Fork 49
Adjusted precompiles docs to use 6 decimal places instead of 18 #294
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
codebycarson
wants to merge
2
commits into
main
Choose a base branch
from
fix/precompiles-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,7 @@ The Staking precompile provides access to Sei's native staking functionality, al | |
| ```typescript | ||
| const success = await stakingContract.delegate( | ||
| "seivaloper1...", | ||
| { value: parseEther("100") } // Delegate 100 SEI | ||
| { value: 100000000 } // Delegate 100 SEI (6 decimals) | ||
| ); | ||
| ``` | ||
| </Accordion> | ||
|
|
@@ -54,7 +54,7 @@ The Staking precompile provides access to Sei's native staking functionality, al | |
| const success = await stakingContract.redelegate( | ||
| "seivaloper1source...", | ||
| "seivaloper1destination...", | ||
| parseEther("50") // Redelegate 50 SEI | ||
| 50000000 // Redelegate 50 SEI (6 decimals) | ||
| ); | ||
| ``` | ||
| </Accordion> | ||
|
|
@@ -73,7 +73,7 @@ The Staking precompile provides access to Sei's native staking functionality, al | |
| ```typescript | ||
| const success = await stakingContract.undelegate( | ||
| "seivaloper1...", | ||
| parseEther("25") // Undelegate 25 SEI | ||
| 25000000 // Undelegate 25 SEI (6 decimals) | ||
| ); | ||
| ``` | ||
| </Accordion> | ||
|
|
@@ -124,7 +124,7 @@ The Staking precompile provides access to Sei's native staking functionality, al | |
| <Tabs> | ||
| <Tab title="Viem"> | ||
| ```typescript | ||
| import { createPublicClient, createWalletClient, http, parseEther, formatEther } from 'viem'; | ||
| import { createPublicClient, createWalletClient, http, formatEther } from 'viem'; | ||
| import { privateKeyToAccount } from 'viem/accounts'; | ||
| import { | ||
| seiTestnet, | ||
|
|
@@ -151,7 +151,7 @@ The Staking precompile provides access to Sei's native staking functionality, al | |
| abi: STAKING_PRECOMPILE_ABI, | ||
| functionName: 'delegate', | ||
| args: [validatorAddress], | ||
| value: parseEther(amount) | ||
| value: amount // (6 decimals) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 18 decimals truncated to 6 decimals |
||
| }); | ||
|
|
||
| return await publicClient.waitForTransactionReceipt({ hash }); | ||
|
|
@@ -184,7 +184,7 @@ The Staking precompile provides access to Sei's native staking functionality, al | |
| address: STAKING_PRECOMPILE_ADDRESS, | ||
| abi: STAKING_PRECOMPILE_ABI, | ||
| functionName: 'redelegate', | ||
| args: [fromValidator, toValidator, parseEther(amount)] | ||
| args: [fromValidator, toValidator, amount] // Amount (6 decimals) | ||
| }); | ||
|
|
||
| return await publicClient.waitForTransactionReceipt({ hash }); | ||
|
|
@@ -196,7 +196,7 @@ The Staking precompile provides access to Sei's native staking functionality, al | |
| address: STAKING_PRECOMPILE_ADDRESS, | ||
| abi: STAKING_PRECOMPILE_ABI, | ||
| functionName: 'undelegate', | ||
| args: [validatorAddress, parseEther(amount)] | ||
| args: [validatorAddress, amount] // Amount (6 decimals) | ||
| }); | ||
|
|
||
| return await publicClient.waitForTransactionReceipt({ hash }); | ||
|
|
@@ -232,7 +232,7 @@ The Staking precompile provides access to Sei's native staking functionality, al | |
| const stakingWithSigner = stakingContract.connect(signer); | ||
|
|
||
| const tx = await stakingWithSigner.delegate(validatorAddress, { | ||
| value: ethers.parseEther(amount) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. parseEther was correct as its delegate function but have a amount.toFixed(6) |
||
| value: amount // Amount (6 decimals) | ||
| }); | ||
|
|
||
| return await tx.wait(); | ||
|
|
@@ -261,7 +261,7 @@ The Staking precompile provides access to Sei's native staking functionality, al | |
| const tx = await stakingWithSigner.redelegate( | ||
| fromValidator, | ||
| toValidator, | ||
| ethers.parseEther(amount) | ||
| amount // Amount (6 decimals) | ||
| ); | ||
|
|
||
| return await tx.wait(); | ||
|
|
@@ -273,7 +273,7 @@ The Staking precompile provides access to Sei's native staking functionality, al | |
|
|
||
| const tx = await stakingWithSigner.undelegate( | ||
| validatorAddress, | ||
| ethers.parseEther(amount) | ||
| amount // Amount (6 decimals) | ||
| ); | ||
|
|
||
| return await tx.wait(); | ||
|
|
@@ -392,12 +392,12 @@ async function diversifyDelegations( | |
| totalAmount: string, | ||
| validatorAddresses: string[] | ||
| ) { | ||
| const amountPerValidator = parseEther(totalAmount) / BigInt(validatorAddresses.length); | ||
| const amountPerValidator = BigInt(totalAmount) / BigInt(validatorAddresses.length); // Amount (6 decimals) | ||
codebycarson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const delegationPromises = validatorAddresses.map(validator => | ||
| delegateToValidator(validator, formatEther(amountPerValidator)) | ||
| delegateToValidator(validator, amountPerValidator) | ||
codebycarson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ); | ||
|
|
||
codebycarson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return await Promise.all(delegationPromises); | ||
| } | ||
| ``` | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
While using
delegate, specifically this one function uses 18 decimals inputs truncated to 6 decimals. Basically, you do something like:10.123456789 -> 10.123456 -> parseEther(10.123456)
Best practice would be to always have amount.toFixed(6) -> parseEther(fixedAmount)
We need to change from having 6 decimals in delegate function to 18 decimals which is truncated to 6 decimals