Skip to content

Commit 6b0cedb

Browse files
committed
Add details on how to use slippage on Polygon docs
1 parent 30c877f commit 6b0cedb

File tree

6 files changed

+39
-17
lines changed

6 files changed

+39
-17
lines changed

book/build-your-staking-dapp/polygon/methods.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,11 @@ To build a staking transaction, you will need to specify:
5050
- **delegatorAddress**: The delegator's Ethereum address
5151
- **validatorShareAddress**: The validator's ValidatorShare contract address
5252
- **amount**: The amount to stake in POL
53-
- **slippageBps**: (Optional) Slippage tolerance in basis points (e.g., 50 = 0.5%). Used to calculate minSharesToMint automatically.
54-
- **minSharesToMint**: (Optional) Minimum validator shares to receive for slippage protection. Use this OR slippageBps, not both.
53+
- **slippageBps**: Slippage tolerance in basis points (e.g., 50 = 0.5%). Used to calculate minSharesToMint automatically. Exactly one of `slippageBps` or `minSharesToMint` must be provided (not both, no default).
54+
- **minSharesToMint**: Minimum validator shares to receive for slippage protection. Exactly one of `slippageBps` or `minSharesToMint` must be provided (not both, no default).
55+
56+
> **Why is slippage required?** Polygon uses a share-based delegation model where the exchange rate between POL and validator shares fluctuates. The slippage parameter protects against unfavorable rate changes between transaction submission and execution. This is a requirement of the ValidatorShare contract itself.
57+
5558
- **referrer**: (Optional) Custom referrer string for tracking. Defaults to `'sdk-chorusone-staking'`.
5659

5760
### Example
@@ -99,8 +102,11 @@ To build an unstaking transaction, you need to specify:
99102
- **delegatorAddress**: The address of the delegator
100103
- **validatorShareAddress**: The validator's ValidatorShare contract address
101104
- **amount**: The amount of POL to unstake
102-
- **slippageBps**: (Optional) Slippage tolerance in basis points (e.g., 50 = 0.5%). Used to calculate maximumSharesToBurn automatically.
103-
- **maximumSharesToBurn**: (Optional) Maximum validator shares willing to burn for slippage protection. Use this OR slippageBps, not both.
105+
- **slippageBps**: Slippage tolerance in basis points (e.g., 50 = 0.5%). Used to calculate maximumSharesToBurn automatically. Exactly one of `slippageBps` or `maximumSharesToBurn` must be provided (not both, no default).
106+
- **maximumSharesToBurn**: Maximum validator shares willing to burn for slippage protection. Exactly one of `slippageBps` or `maximumSharesToBurn` must be provided (not both, no default).
107+
108+
> **Why is slippage required?** Polygon uses a share-based delegation model where the exchange rate between POL and validator shares fluctuates. The slippage parameter protects against unfavorable rate changes between transaction submission and execution. This is a requirement of the ValidatorShare contract itself.
109+
104110
- **referrer**: (Optional) Custom referrer string for tracking. Defaults to `'sdk-chorusone-staking'`.
105111

106112
### Example

book/docs/classes/polygon_src.PolygonStaker.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ Builds a staking (delegation) transaction
124124
Delegates POL tokens to a validator via their ValidatorShare contract.
125125
Requires prior token approval to the StakeManager contract.
126126

127+
**Slippage requirement:** Exactly one of `slippageBps` or `minSharesToMint` must be provided.
128+
There is no default value. Providing neither or both will throw an error.
129+
127130
### Parameters
128131

129132
| Name | Type | Description |
@@ -132,8 +135,8 @@ Requires prior token approval to the StakeManager contract.
132135
| `params.delegatorAddress` | \`0x$\{string}\` | The delegator's Ethereum address |
133136
| `params.validatorShareAddress` | \`0x$\{string}\` | The validator's ValidatorShare contract address |
134137
| `params.amount` | `string` | The amount to stake in POL |
135-
| `params.slippageBps?` | `number` | (Optional) Slippage tolerance in basis points (e.g., 50 = 0.5%). Used to calculate minSharesToMint. |
136-
| `params.minSharesToMint?` | `bigint` | (Optional) Minimum validator shares to receive. Use this OR slippageBps, not both. |
138+
| `params.slippageBps?` | `number` | Slippage tolerance in basis points (e.g., 50 = 0.5%). Used to calculate minSharesToMint. Exactly one of `slippageBps` or `minSharesToMint` must be provided (not both, no default). |
139+
| `params.minSharesToMint?` | `bigint` | Minimum validator shares to receive. Exactly one of `slippageBps` or `minSharesToMint` must be provided (not both, no default). |
137140
| `params.referrer?` | `string` | (Optional) Custom referrer string for tracking. If not provided, uses 'sdk-chorusone-staking'. |
138141

139142
### Returns
@@ -153,6 +156,9 @@ Builds an unstaking transaction
153156
Creates an unbond request to unstake POL tokens from a validator.
154157
After the unbonding period (~80 checkpoints, approximately 3-4 days), call buildWithdrawTx() to claim funds.
155158

159+
**Slippage requirement:** Exactly one of `slippageBps` or `maximumSharesToBurn` must be provided.
160+
There is no default value. Providing neither or both will throw an error.
161+
156162
### Parameters
157163

158164
| Name | Type | Description |
@@ -161,8 +167,8 @@ After the unbonding period (~80 checkpoints, approximately 3-4 days), call build
161167
| `params.delegatorAddress` | \`0x$\{string}\` | The delegator's address |
162168
| `params.validatorShareAddress` | \`0x$\{string}\` | The validator's ValidatorShare contract address |
163169
| `params.amount` | `string` | The amount to unstake in POL (will be converted to wei internally) |
164-
| `params.slippageBps?` | `number` | (Optional) Slippage tolerance in basis points (e.g., 50 = 0.5%). Used to calculate maximumSharesToBurn. |
165-
| `params.maximumSharesToBurn?` | `bigint` | (Optional) Maximum validator shares willing to burn. Use this OR slippageBps, not both. |
170+
| `params.slippageBps?` | `number` | Slippage tolerance in basis points (e.g., 50 = 0.5%). Used to calculate maximumSharesToBurn. Exactly one of `slippageBps` or `maximumSharesToBurn` must be provided (not both, no default). |
171+
| `params.maximumSharesToBurn?` | `bigint` | Maximum validator shares willing to burn. Exactly one of `slippageBps` or `maximumSharesToBurn` must be provided (not both, no default). |
166172
| `params.referrer?` | `string` | (Optional) Custom referrer string for tracking. If not provided, uses 'sdk-chorusone-staking'. |
167173

168174
### Returns

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/polygon/README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ const { txHash } = await staker.broadcast({ signedTx })
9999

100100
### Stake (Delegate) to Validator
101101

102-
Delegate POL tokens to a validator via their ValidatorShare contract:
102+
Delegate POL tokens to a validator via their ValidatorShare contract.
103+
104+
You must provide exactly one of `slippageBps` or `minSharesToMint` (not both). There is no default — omitting both will throw an error.
103105

104106
```javascript
105107
const { tx } = await staker.buildStakeTx({
@@ -121,7 +123,9 @@ const { txHash } = await staker.broadcast({ signedTx })
121123

122124
### Unstake (Unbond) from Validator
123125

124-
Create an unbond request to unstake POL tokens. After the unbonding period (~80 epochs, approximately 3-4 days), call withdraw to claim funds:
126+
Create an unbond request to unstake POL tokens. After the unbonding period (~80 epochs, approximately 3-4 days), call withdraw to claim funds.
127+
128+
You must provide exactly one of `slippageBps` or `maximumSharesToBurn` (not both). There is no default — omitting both will throw an error.
125129

126130
```javascript
127131
const { tx } = await staker.buildUnstakeTx({
@@ -215,7 +219,7 @@ console.log(status) // 'success', 'failure', or 'unknown'
215219
- **Ethereum L1 Based**: Polygon PoS staking operates via ValidatorShare contracts deployed on Ethereum mainnet (or Sepolia for testnet)
216220
- **POL Token Staking**: Stake the native POL token (formerly MATIC) to validators
217221
- **Human-Readable Amounts**: Pass token amounts as strings (e.g., '1.5'), conversion to wei is handled automatically
218-
- **Slippage Protection**: Stake and unstake operations support `slippageBps` (basis points) for automatic slippage calculation, or manual `minSharesToMint`/`maximumSharesToBurn` parameters
222+
- **Slippage Protection**: Stake and unstake operations require either `slippageBps` (basis points) for automatic slippage calculation, or manual `minSharesToMint`/`maximumSharesToBurn` parameters. Exactly one must be provided — there is no default.
219223
- **Query Methods**: Read stake balances, rewards, allowances, unbond status (with POL amount and withdrawability), and epoch information
220224
- **Rewards Management**: Claim rewards to wallet or compound them back into your delegation
221225

packages/polygon/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@chorus-one/polygon",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "All-in-one toolkit for building staking dApps on Polygon network",
55
"scripts": {
66
"build": "rm -fr dist/* && tsc -p tsconfig.mjs.json --outDir dist/mjs && tsc -p tsconfig.cjs.json --outDir dist/cjs && bash ../../scripts/fix-package-json",

packages/polygon/src/staker.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,15 @@ export class PolygonStaker {
140140
* Delegates POL tokens to a validator via their ValidatorShare contract.
141141
* Requires prior token approval to the StakeManager contract.
142142
*
143+
* **Slippage requirement:** Exactly one of `slippageBps` or `minSharesToMint` must be provided.
144+
* There is no default value. Providing neither or both will throw an error.
145+
*
143146
* @param params - Parameters for building the transaction
144147
* @param params.delegatorAddress - The delegator's Ethereum address
145148
* @param params.validatorShareAddress - The validator's ValidatorShare contract address
146149
* @param params.amount - The amount to stake in POL
147-
* @param params.slippageBps - (Optional) Slippage tolerance in basis points (e.g., 50 = 0.5%). Used to calculate minSharesToMint.
148-
* @param params.minSharesToMint - (Optional) Minimum validator shares to receive. Use this OR slippageBps, not both.
150+
* @param params.slippageBps - Slippage tolerance in basis points (e.g., 50 = 0.5%). Used to calculate minSharesToMint. Exactly one of `slippageBps` or `minSharesToMint` must be provided (not both, no default).
151+
* @param params.minSharesToMint - Minimum validator shares to receive. Exactly one of `slippageBps` or `minSharesToMint` must be provided (not both, no default).
149152
* @param params.referrer - (Optional) Custom referrer string for tracking. If not provided, uses 'sdk-chorusone-staking'.
150153
*
151154
* @returns Returns a promise that resolves to a Polygon staking transaction
@@ -214,12 +217,15 @@ export class PolygonStaker {
214217
* Creates an unbond request to unstake POL tokens from a validator.
215218
* After the unbonding period (~80 checkpoints, approximately 3-4 days), call buildWithdrawTx() to claim funds.
216219
*
220+
* **Slippage requirement:** Exactly one of `slippageBps` or `maximumSharesToBurn` must be provided.
221+
* There is no default value. Providing neither or both will throw an error.
222+
*
217223
* @param params - Parameters for building the transaction
218224
* @param params.delegatorAddress - The delegator's address
219225
* @param params.validatorShareAddress - The validator's ValidatorShare contract address
220226
* @param params.amount - The amount to unstake in POL (will be converted to wei internally)
221-
* @param params.slippageBps - (Optional) Slippage tolerance in basis points (e.g., 50 = 0.5%). Used to calculate maximumSharesToBurn.
222-
* @param params.maximumSharesToBurn - (Optional) Maximum validator shares willing to burn. Use this OR slippageBps, not both.
227+
* @param params.slippageBps - Slippage tolerance in basis points (e.g., 50 = 0.5%). Used to calculate maximumSharesToBurn. Exactly one of `slippageBps` or `maximumSharesToBurn` must be provided (not both, no default).
228+
* @param params.maximumSharesToBurn - Maximum validator shares willing to burn. Exactly one of `slippageBps` or `maximumSharesToBurn` must be provided (not both, no default).
223229
* @param params.referrer - (Optional) Custom referrer string for tracking. If not provided, uses 'sdk-chorusone-staking'.
224230
*
225231
* @returns Returns a promise that resolves to a Polygon unstaking transaction

0 commit comments

Comments
 (0)