Skip to content
Open
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
28 changes: 14 additions & 14 deletions docs/precompiles/precompiles/staking.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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

);
```
</Accordion>
Expand All @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -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,
Expand All @@ -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)

Choose a reason for hiding this comment

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

18 decimals truncated to 6 decimals

});

return await publicClient.waitForTransactionReceipt({ hash });
Expand Down Expand Up @@ -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 });
Expand All @@ -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 });
Expand Down Expand Up @@ -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)

Choose a reason for hiding this comment

The 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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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)

const delegationPromises = validatorAddresses.map(validator =>
delegateToValidator(validator, formatEther(amountPerValidator))
delegateToValidator(validator, amountPerValidator)
);

return await Promise.all(delegationPromises);
}
```
Expand Down