@chorus-one/polygon 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -3
- package/dist/cjs/staker.d.ts +4 -4
- package/dist/cjs/staker.js +7 -6
- package/dist/mjs/staker.d.ts +4 -4
- package/dist/mjs/staker.js +7 -6
- package/package.json +2 -2
- package/src/staker.ts +7 -6
- package/test/lib/networks.json +1 -1
package/README.md
CHANGED
|
@@ -99,7 +99,9 @@ const { txHash } = await staker.broadcast({ signedTx })
|
|
|
99
99
|
|
|
100
100
|
### Stake (Delegate) to Validator
|
|
101
101
|
|
|
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.
|
|
103
105
|
|
|
104
106
|
```javascript
|
|
105
107
|
const { tx } = await staker.buildStakeTx({
|
|
@@ -121,7 +123,9 @@ const { txHash } = await staker.broadcast({ signedTx })
|
|
|
121
123
|
|
|
122
124
|
### Unstake (Unbond) from Validator
|
|
123
125
|
|
|
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.
|
|
125
129
|
|
|
126
130
|
```javascript
|
|
127
131
|
const { tx } = await staker.buildUnstakeTx({
|
|
@@ -215,7 +219,7 @@ console.log(status) // 'success', 'failure', or 'unknown'
|
|
|
215
219
|
- **Ethereum L1 Based**: Polygon PoS staking operates via ValidatorShare contracts deployed on Ethereum mainnet (or Sepolia for testnet)
|
|
216
220
|
- **POL Token Staking**: Stake the native POL token (formerly MATIC) to validators
|
|
217
221
|
- **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
|
|
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.
|
|
219
223
|
- **Query Methods**: Read stake balances, rewards, allowances, unbond status (with POL amount and withdrawability), and epoch information
|
|
220
224
|
- **Rewards Management**: Claim rewards to wallet or compound them back into your delegation
|
|
221
225
|
|
package/dist/cjs/staker.d.ts
CHANGED
|
@@ -54,8 +54,8 @@ export declare class PolygonStaker {
|
|
|
54
54
|
* @param params.delegatorAddress - The delegator's Ethereum address
|
|
55
55
|
* @param params.validatorShareAddress - The validator's ValidatorShare contract address
|
|
56
56
|
* @param params.amount - The amount to stake in POL
|
|
57
|
-
* @param params.slippageBps -
|
|
58
|
-
* @param params.minSharesToMint -
|
|
57
|
+
* @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).
|
|
58
|
+
* @param params.minSharesToMint - Minimum validator shares to receive. Exactly one of `slippageBps` or `minSharesToMint` must be provided (not both, no default).
|
|
59
59
|
* @param params.referrer - (Optional) Custom referrer string for tracking. If not provided, uses 'sdk-chorusone-staking'.
|
|
60
60
|
*
|
|
61
61
|
* @returns Returns a promise that resolves to a Polygon staking transaction
|
|
@@ -80,8 +80,8 @@ export declare class PolygonStaker {
|
|
|
80
80
|
* @param params.delegatorAddress - The delegator's address
|
|
81
81
|
* @param params.validatorShareAddress - The validator's ValidatorShare contract address
|
|
82
82
|
* @param params.amount - The amount to unstake in POL (will be converted to wei internally)
|
|
83
|
-
* @param params.slippageBps -
|
|
84
|
-
* @param params.maximumSharesToBurn -
|
|
83
|
+
* @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).
|
|
84
|
+
* @param params.maximumSharesToBurn - Maximum validator shares willing to burn. Exactly one of `slippageBps` or `maximumSharesToBurn` must be provided (not both, no default).
|
|
85
85
|
* @param params.referrer - (Optional) Custom referrer string for tracking. If not provided, uses 'sdk-chorusone-staking'.
|
|
86
86
|
*
|
|
87
87
|
* @returns Returns a promise that resolves to a Polygon unstaking transaction
|
package/dist/cjs/staker.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PolygonStaker = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
5
|
const chains_1 = require("viem/chains");
|
|
6
|
-
const
|
|
6
|
+
const secp256k1_1 = require("@noble/curves/secp256k1");
|
|
7
7
|
const referrer_1 = require("./referrer");
|
|
8
8
|
const constants_1 = require("./constants");
|
|
9
9
|
/**
|
|
@@ -46,7 +46,8 @@ class PolygonStaker {
|
|
|
46
46
|
* @returns Returns an array containing the derived address.
|
|
47
47
|
*/
|
|
48
48
|
static getAddressDerivationFn = () => async (publicKey) => {
|
|
49
|
-
const
|
|
49
|
+
const point = secp256k1_1.secp256k1.Point.fromHex(publicKey);
|
|
50
|
+
const pkUncompressed = point.toBytes(false);
|
|
50
51
|
const hash = (0, viem_1.keccak256)(pkUncompressed.subarray(1));
|
|
51
52
|
const ethAddress = hash.slice(-40);
|
|
52
53
|
return [ethAddress];
|
|
@@ -108,8 +109,8 @@ class PolygonStaker {
|
|
|
108
109
|
* @param params.delegatorAddress - The delegator's Ethereum address
|
|
109
110
|
* @param params.validatorShareAddress - The validator's ValidatorShare contract address
|
|
110
111
|
* @param params.amount - The amount to stake in POL
|
|
111
|
-
* @param params.slippageBps -
|
|
112
|
-
* @param params.minSharesToMint -
|
|
112
|
+
* @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).
|
|
113
|
+
* @param params.minSharesToMint - Minimum validator shares to receive. Exactly one of `slippageBps` or `minSharesToMint` must be provided (not both, no default).
|
|
113
114
|
* @param params.referrer - (Optional) Custom referrer string for tracking. If not provided, uses 'sdk-chorusone-staking'.
|
|
114
115
|
*
|
|
115
116
|
* @returns Returns a promise that resolves to a Polygon staking transaction
|
|
@@ -165,8 +166,8 @@ class PolygonStaker {
|
|
|
165
166
|
* @param params.delegatorAddress - The delegator's address
|
|
166
167
|
* @param params.validatorShareAddress - The validator's ValidatorShare contract address
|
|
167
168
|
* @param params.amount - The amount to unstake in POL (will be converted to wei internally)
|
|
168
|
-
* @param params.slippageBps -
|
|
169
|
-
* @param params.maximumSharesToBurn -
|
|
169
|
+
* @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).
|
|
170
|
+
* @param params.maximumSharesToBurn - Maximum validator shares willing to burn. Exactly one of `slippageBps` or `maximumSharesToBurn` must be provided (not both, no default).
|
|
170
171
|
* @param params.referrer - (Optional) Custom referrer string for tracking. If not provided, uses 'sdk-chorusone-staking'.
|
|
171
172
|
*
|
|
172
173
|
* @returns Returns a promise that resolves to a Polygon unstaking transaction
|
package/dist/mjs/staker.d.ts
CHANGED
|
@@ -54,8 +54,8 @@ export declare class PolygonStaker {
|
|
|
54
54
|
* @param params.delegatorAddress - The delegator's Ethereum address
|
|
55
55
|
* @param params.validatorShareAddress - The validator's ValidatorShare contract address
|
|
56
56
|
* @param params.amount - The amount to stake in POL
|
|
57
|
-
* @param params.slippageBps -
|
|
58
|
-
* @param params.minSharesToMint -
|
|
57
|
+
* @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).
|
|
58
|
+
* @param params.minSharesToMint - Minimum validator shares to receive. Exactly one of `slippageBps` or `minSharesToMint` must be provided (not both, no default).
|
|
59
59
|
* @param params.referrer - (Optional) Custom referrer string for tracking. If not provided, uses 'sdk-chorusone-staking'.
|
|
60
60
|
*
|
|
61
61
|
* @returns Returns a promise that resolves to a Polygon staking transaction
|
|
@@ -80,8 +80,8 @@ export declare class PolygonStaker {
|
|
|
80
80
|
* @param params.delegatorAddress - The delegator's address
|
|
81
81
|
* @param params.validatorShareAddress - The validator's ValidatorShare contract address
|
|
82
82
|
* @param params.amount - The amount to unstake in POL (will be converted to wei internally)
|
|
83
|
-
* @param params.slippageBps -
|
|
84
|
-
* @param params.maximumSharesToBurn -
|
|
83
|
+
* @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).
|
|
84
|
+
* @param params.maximumSharesToBurn - Maximum validator shares willing to burn. Exactly one of `slippageBps` or `maximumSharesToBurn` must be provided (not both, no default).
|
|
85
85
|
* @param params.referrer - (Optional) Custom referrer string for tracking. If not provided, uses 'sdk-chorusone-staking'.
|
|
86
86
|
*
|
|
87
87
|
* @returns Returns a promise that resolves to a Polygon unstaking transaction
|
package/dist/mjs/staker.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createPublicClient, http, encodeFunctionData, parseEther, formatEther, isAddress, keccak256, serializeTransaction, createWalletClient, maxUint256, erc20Abi } from 'viem';
|
|
2
2
|
import { mainnet, sepolia } from 'viem/chains';
|
|
3
|
-
import { secp256k1 } from '@noble/curves/secp256k1
|
|
3
|
+
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
4
4
|
import { appendReferrerTracking } from './referrer';
|
|
5
5
|
import { VALIDATOR_SHARE_ABI, STAKE_MANAGER_ABI, NETWORK_CONTRACTS, EXCHANGE_RATE_PRECISION, EXCHANGE_RATE_HIGH_PRECISION } from './constants';
|
|
6
6
|
/**
|
|
@@ -43,7 +43,8 @@ export class PolygonStaker {
|
|
|
43
43
|
* @returns Returns an array containing the derived address.
|
|
44
44
|
*/
|
|
45
45
|
static getAddressDerivationFn = () => async (publicKey) => {
|
|
46
|
-
const
|
|
46
|
+
const point = secp256k1.Point.fromHex(publicKey);
|
|
47
|
+
const pkUncompressed = point.toBytes(false);
|
|
47
48
|
const hash = keccak256(pkUncompressed.subarray(1));
|
|
48
49
|
const ethAddress = hash.slice(-40);
|
|
49
50
|
return [ethAddress];
|
|
@@ -105,8 +106,8 @@ export class PolygonStaker {
|
|
|
105
106
|
* @param params.delegatorAddress - The delegator's Ethereum address
|
|
106
107
|
* @param params.validatorShareAddress - The validator's ValidatorShare contract address
|
|
107
108
|
* @param params.amount - The amount to stake in POL
|
|
108
|
-
* @param params.slippageBps -
|
|
109
|
-
* @param params.minSharesToMint -
|
|
109
|
+
* @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).
|
|
110
|
+
* @param params.minSharesToMint - Minimum validator shares to receive. Exactly one of `slippageBps` or `minSharesToMint` must be provided (not both, no default).
|
|
110
111
|
* @param params.referrer - (Optional) Custom referrer string for tracking. If not provided, uses 'sdk-chorusone-staking'.
|
|
111
112
|
*
|
|
112
113
|
* @returns Returns a promise that resolves to a Polygon staking transaction
|
|
@@ -162,8 +163,8 @@ export class PolygonStaker {
|
|
|
162
163
|
* @param params.delegatorAddress - The delegator's address
|
|
163
164
|
* @param params.validatorShareAddress - The validator's ValidatorShare contract address
|
|
164
165
|
* @param params.amount - The amount to unstake in POL (will be converted to wei internally)
|
|
165
|
-
* @param params.slippageBps -
|
|
166
|
-
* @param params.maximumSharesToBurn -
|
|
166
|
+
* @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).
|
|
167
|
+
* @param params.maximumSharesToBurn - Maximum validator shares willing to burn. Exactly one of `slippageBps` or `maximumSharesToBurn` must be provided (not both, no default).
|
|
167
168
|
* @param params.referrer - (Optional) Custom referrer string for tracking. If not provided, uses 'sdk-chorusone-staking'.
|
|
168
169
|
*
|
|
169
170
|
* @returns Returns a promise that resolves to a Polygon unstaking transaction
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chorus-one/polygon",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "All-in-one toolkit for building staking dApps on Polygon network",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"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",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"type": "module",
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@chorus-one/signer": "^1.0.0",
|
|
41
|
-
"@noble/curves": "^
|
|
41
|
+
"@noble/curves": "^1.9.2",
|
|
42
42
|
"viem": "^2.28.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
package/src/staker.ts
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
type Chain
|
|
17
17
|
} from 'viem'
|
|
18
18
|
import { mainnet, sepolia } from 'viem/chains'
|
|
19
|
-
import { secp256k1 } from '@noble/curves/secp256k1
|
|
19
|
+
import { secp256k1 } from '@noble/curves/secp256k1'
|
|
20
20
|
import type { Signer } from '@chorus-one/signer'
|
|
21
21
|
import type { Transaction, PolygonNetworkConfig, PolygonTxStatus, StakeInfo, UnbondInfo } from './types'
|
|
22
22
|
import { appendReferrerTracking } from './referrer'
|
|
@@ -75,7 +75,8 @@ export class PolygonStaker {
|
|
|
75
75
|
static getAddressDerivationFn =
|
|
76
76
|
() =>
|
|
77
77
|
async (publicKey: Uint8Array): Promise<Array<string>> => {
|
|
78
|
-
const
|
|
78
|
+
const point = secp256k1.Point.fromHex(publicKey)
|
|
79
|
+
const pkUncompressed = point.toBytes(false)
|
|
79
80
|
const hash = keccak256(pkUncompressed.subarray(1))
|
|
80
81
|
const ethAddress = hash.slice(-40)
|
|
81
82
|
return [ethAddress]
|
|
@@ -144,8 +145,8 @@ export class PolygonStaker {
|
|
|
144
145
|
* @param params.delegatorAddress - The delegator's Ethereum address
|
|
145
146
|
* @param params.validatorShareAddress - The validator's ValidatorShare contract address
|
|
146
147
|
* @param params.amount - The amount to stake in POL
|
|
147
|
-
* @param params.slippageBps -
|
|
148
|
-
* @param params.minSharesToMint -
|
|
148
|
+
* @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).
|
|
149
|
+
* @param params.minSharesToMint - Minimum validator shares to receive. Exactly one of `slippageBps` or `minSharesToMint` must be provided (not both, no default).
|
|
149
150
|
* @param params.referrer - (Optional) Custom referrer string for tracking. If not provided, uses 'sdk-chorusone-staking'.
|
|
150
151
|
*
|
|
151
152
|
* @returns Returns a promise that resolves to a Polygon staking transaction
|
|
@@ -218,8 +219,8 @@ export class PolygonStaker {
|
|
|
218
219
|
* @param params.delegatorAddress - The delegator's address
|
|
219
220
|
* @param params.validatorShareAddress - The validator's ValidatorShare contract address
|
|
220
221
|
* @param params.amount - The amount to unstake in POL (will be converted to wei internally)
|
|
221
|
-
* @param params.slippageBps -
|
|
222
|
-
* @param params.maximumSharesToBurn -
|
|
222
|
+
* @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).
|
|
223
|
+
* @param params.maximumSharesToBurn - Maximum validator shares willing to burn. Exactly one of `slippageBps` or `maximumSharesToBurn` must be provided (not both, no default).
|
|
223
224
|
* @param params.referrer - (Optional) Custom referrer string for tracking. If not provided, uses 'sdk-chorusone-staking'.
|
|
224
225
|
*
|
|
225
226
|
* @returns Returns a promise that resolves to a Polygon unstaking transaction
|