@chorus-one/polygon 1.0.0

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.
Files changed (43) hide show
  1. package/.mocharc.json +6 -0
  2. package/LICENSE +13 -0
  3. package/README.md +233 -0
  4. package/dist/cjs/constants.d.ts +187 -0
  5. package/dist/cjs/constants.js +141 -0
  6. package/dist/cjs/index.d.ts +4 -0
  7. package/dist/cjs/index.js +12 -0
  8. package/dist/cjs/package.json +3 -0
  9. package/dist/cjs/referrer.d.ts +2 -0
  10. package/dist/cjs/referrer.js +15 -0
  11. package/dist/cjs/staker.d.ts +335 -0
  12. package/dist/cjs/staker.js +716 -0
  13. package/dist/cjs/types.d.ts +40 -0
  14. package/dist/cjs/types.js +2 -0
  15. package/dist/mjs/constants.d.ts +187 -0
  16. package/dist/mjs/constants.js +138 -0
  17. package/dist/mjs/index.d.ts +4 -0
  18. package/dist/mjs/index.js +2 -0
  19. package/dist/mjs/package.json +3 -0
  20. package/dist/mjs/referrer.d.ts +2 -0
  21. package/dist/mjs/referrer.js +11 -0
  22. package/dist/mjs/staker.d.ts +335 -0
  23. package/dist/mjs/staker.js +712 -0
  24. package/dist/mjs/types.d.ts +40 -0
  25. package/dist/mjs/types.js +1 -0
  26. package/hardhat.config.ts +27 -0
  27. package/package.json +50 -0
  28. package/src/constants.ts +151 -0
  29. package/src/index.ts +14 -0
  30. package/src/referrer.ts +15 -0
  31. package/src/staker.ts +878 -0
  32. package/src/types.ts +45 -0
  33. package/test/fixtures/expected-data.ts +17 -0
  34. package/test/integration/localSigner.spec.ts +128 -0
  35. package/test/integration/setup.ts +41 -0
  36. package/test/integration/staker.spec.ts +587 -0
  37. package/test/integration/testStaker.ts +130 -0
  38. package/test/integration/utils.ts +263 -0
  39. package/test/lib/networks.json +14 -0
  40. package/test/staker.spec.ts +154 -0
  41. package/tsconfig.cjs.json +9 -0
  42. package/tsconfig.json +13 -0
  43. package/tsconfig.mjs.json +9 -0
package/.mocharc.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "require": ["tsx"],
3
+ "extensions": ["ts"],
4
+ "timeout": 10000,
5
+ "reporter": "spec"
6
+ }
package/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2024 Chorus One AG
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,233 @@
1
+ # Chorus One SDK: Polygon
2
+
3
+ All-in-one toolkit for building staking dApps on Polygon PoS network.
4
+
5
+ ## Documentation
6
+
7
+ For detailed instructions on how to set up and use the Chorus One SDK for Polygon staking, please visit our [main documentation](https://chorus-one.gitbook.io/sdk/build-your-staking-dapp/polygon/overview).
8
+
9
+ ## Installation
10
+
11
+ In the project's root directory, run the following command:
12
+
13
+ ```bash
14
+ npm install @chorus-one/polygon
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ Here is a basic example of how to use the Chorus One SDK to build, sign, and broadcast staking transactions on Polygon PoS.
20
+
21
+ ### Configuration
22
+
23
+ ```javascript
24
+ import { PolygonStaker } from '@chorus-one/polygon'
25
+
26
+ const staker = new PolygonStaker({
27
+ network: 'mainnet', // 'mainnet' (Ethereum L1) or 'testnet' (Sepolia L1)
28
+ rpcUrl: 'https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY' // Optional: uses viem's default if not provided
29
+ })
30
+ ```
31
+
32
+ ### Querying Staking Information
33
+
34
+ ```javascript
35
+ const delegatorAddress = '0xYourAddress'
36
+ const validatorShareAddress = '0xValidatorShareContract'
37
+
38
+ // Get staking info (balance, shares, exchange rate)
39
+ const stake = await staker.getStake({ delegatorAddress, validatorShareAddress })
40
+ console.log('Staked Balance:', stake.balance, 'POL')
41
+ console.log('Shares:', stake.shares)
42
+ console.log('Exchange Rate:', stake.exchangeRate)
43
+
44
+ // Get pending rewards
45
+ const rewards = await staker.getLiquidRewards({ delegatorAddress, validatorShareAddress })
46
+ console.log('Pending Rewards:', rewards, 'POL')
47
+
48
+ // Get POL allowance for StakeManager
49
+ const allowance = await staker.getAllowance(delegatorAddress)
50
+ console.log('Current Allowance:', allowance, 'POL')
51
+
52
+ // Get unbond info (for pending unstakes)
53
+ const unbondNonce = await staker.getUnbondNonce({ delegatorAddress, validatorShareAddress })
54
+ if (unbondNonce > 0n) {
55
+ const unbond = await staker.getUnbond({ delegatorAddress, validatorShareAddress, unbondNonce })
56
+ console.log('Amount:', unbond.amount, 'POL')
57
+ console.log('Withdrawable:', unbond.isWithdrawable)
58
+ console.log('Shares:', unbond.shares)
59
+ console.log('Withdraw Epoch:', unbond.withdrawEpoch)
60
+
61
+ // Or fetch multiple unbonds efficiently in a single RPC call
62
+ const unbonds = await staker.getUnbonds({
63
+ delegatorAddress,
64
+ validatorShareAddress,
65
+ unbondNonces: [1n, 2n, 3n]
66
+ })
67
+ unbonds.forEach((u, i) => console.log(`Unbond ${i + 1}: ${u.amount} POL, withdrawable: ${u.isWithdrawable}`))
68
+ }
69
+
70
+ // Get current epoch and withdrawal delay
71
+ const epoch = await staker.getEpoch()
72
+ const withdrawalDelay = await staker.getWithdrawalDelay()
73
+ console.log('Current Epoch:', epoch)
74
+ console.log('Withdrawal Delay:', withdrawalDelay, 'epochs')
75
+ ```
76
+
77
+ ### Approve POL Tokens
78
+
79
+ Before staking, you must approve the StakeManager contract to spend your POL tokens:
80
+
81
+ ```javascript
82
+ import { FireblocksSigner } from '@chorus-one/signer-fireblocks'
83
+
84
+ const signer = new FireblocksSigner({...})
85
+ await signer.init()
86
+
87
+ const { tx: approveTx } = await staker.buildApproveTx({
88
+ amount: '1000' // Amount in POL, or 'max' for unlimited approval
89
+ })
90
+
91
+ const { signedTx } = await staker.sign({
92
+ signer,
93
+ signerAddress: delegatorAddress,
94
+ tx: approveTx
95
+ })
96
+
97
+ const { txHash } = await staker.broadcast({ signedTx })
98
+ ```
99
+
100
+ ### Stake (Delegate) to Validator
101
+
102
+ Delegate POL tokens to a validator via their ValidatorShare contract:
103
+
104
+ ```javascript
105
+ const { tx } = await staker.buildStakeTx({
106
+ delegatorAddress,
107
+ validatorShareAddress,
108
+ amount: '1000', // Amount in POL
109
+ slippageBps: 50 // 0.5% slippage tolerance (auto-calculates minSharesToMint)
110
+ // Or use minSharesToMint directly: minSharesToMint: 999n * 10n ** 18n
111
+ })
112
+
113
+ const { signedTx } = await staker.sign({
114
+ signer,
115
+ signerAddress: delegatorAddress,
116
+ tx
117
+ })
118
+
119
+ const { txHash } = await staker.broadcast({ signedTx })
120
+ ```
121
+
122
+ ### Unstake (Unbond) from Validator
123
+
124
+ Create an unbond request to unstake POL tokens. After the unbonding period (~80 epochs, approximately 3-4 days), call withdraw to claim funds:
125
+
126
+ ```javascript
127
+ const { tx } = await staker.buildUnstakeTx({
128
+ delegatorAddress,
129
+ validatorShareAddress,
130
+ amount: '500', // Amount in POL
131
+ slippageBps: 50 // 0.5% slippage tolerance (auto-calculates maximumSharesToBurn)
132
+ // Or use maximumSharesToBurn directly: maximumSharesToBurn: 501n * 10n ** 18n
133
+ })
134
+
135
+ const { signedTx } = await staker.sign({
136
+ signer,
137
+ signerAddress: delegatorAddress,
138
+ tx
139
+ })
140
+
141
+ const { txHash } = await staker.broadcast({ signedTx })
142
+ ```
143
+
144
+ ### Withdraw Unstaked Tokens
145
+
146
+ Claim unstaked POL tokens after the unbonding period has elapsed. Each unstake creates a separate unbond with its own nonce:
147
+
148
+ ```javascript
149
+ // Get the unbond nonce for the unstake you want to withdraw
150
+ const unbondNonce = await staker.getUnbondNonce({ delegatorAddress, validatorShareAddress })
151
+
152
+ const { tx } = await staker.buildWithdrawTx({
153
+ delegatorAddress,
154
+ validatorShareAddress,
155
+ unbondNonce
156
+ })
157
+
158
+ const { signedTx } = await staker.sign({
159
+ signer,
160
+ signerAddress: delegatorAddress,
161
+ tx
162
+ })
163
+
164
+ const { txHash } = await staker.broadcast({ signedTx })
165
+ ```
166
+
167
+ ### Claim Rewards
168
+
169
+ Claim accumulated delegation rewards and send them to your wallet:
170
+
171
+ ```javascript
172
+ const { tx } = await staker.buildClaimRewardsTx({
173
+ delegatorAddress,
174
+ validatorShareAddress
175
+ })
176
+
177
+ const { signedTx } = await staker.sign({
178
+ signer,
179
+ signerAddress: delegatorAddress,
180
+ tx
181
+ })
182
+
183
+ const { txHash } = await staker.broadcast({ signedTx })
184
+ ```
185
+
186
+ ### Compound (Restake) Rewards
187
+
188
+ Restake accumulated rewards back into the validator, increasing your delegation without new tokens:
189
+
190
+ ```javascript
191
+ const { tx } = await staker.buildCompoundTx({
192
+ delegatorAddress,
193
+ validatorShareAddress
194
+ })
195
+
196
+ const { signedTx } = await staker.sign({
197
+ signer,
198
+ signerAddress: delegatorAddress,
199
+ tx
200
+ })
201
+
202
+ const { txHash } = await staker.broadcast({ signedTx })
203
+ ```
204
+
205
+ ### Tracking Transaction Status
206
+
207
+ ```javascript
208
+ const { status, receipt } = await staker.getTxStatus({ txHash })
209
+
210
+ console.log(status) // 'success', 'failure', or 'unknown'
211
+ ```
212
+
213
+ ## Key Features
214
+
215
+ - **Ethereum L1 Based**: Polygon PoS staking operates via ValidatorShare contracts deployed on Ethereum mainnet (or Sepolia for testnet)
216
+ - **POL Token Staking**: Stake the native POL token (formerly MATIC) to validators
217
+ - **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
219
+ - **Query Methods**: Read stake balances, rewards, allowances, unbond status (with POL amount and withdrawability), and epoch information
220
+ - **Rewards Management**: Claim rewards to wallet or compound them back into your delegation
221
+
222
+ ## Important Notes
223
+
224
+ - **Token Approval**: You must approve the StakeManager contract to spend POL tokens before staking. Use `buildApproveTx()` to create the approval transaction.
225
+ - **Unbonding Period**: After unstaking, there is an unbonding period of ~80 epochs (approximately 3-4 days) before tokens can be withdrawn.
226
+ - **Unbond Nonces**: Each unstake operation creates a separate unbond request with an incrementing nonce. Withdrawals must be done per-nonce. Claimed unbonds are deleted, but the nonce counter never decrements. Use `getUnbonds()` to efficiently fetch multiple unbond requests in a single RPC call.
227
+ - **Referrer Tracking**: Transaction builders that support referrer tracking (stake, unstake, claim rewards, compound) append a tracking marker to the transaction calldata. By default, `sdk-chorusone-staking` is used as the referrer. You can provide a custom referrer via the `referrer` parameter.
228
+ - **Exchange Rate**: The exchange rate between shares and POL may fluctuate. Use `slippageBps` for automatic slippage protection, or specify `minSharesToMint`/`maximumSharesToBurn` directly. Foundation validators (ID < 8) use different precision than others.
229
+ - **Validator Share Contracts**: Each validator has their own ValidatorShare contract address. You must specify the correct contract address for the validator you want to delegate to.
230
+
231
+ ## License
232
+
233
+ The Chorus One SDK is licensed under the Apache 2.0 License. For more detailed information, please refer to the [LICENSE](./LICENSE) file in the repository.
@@ -0,0 +1,187 @@
1
+ import type { Address } from 'viem';
2
+ export type PolygonNetworks = 'mainnet' | 'testnet';
3
+ export interface NetworkContracts {
4
+ stakeManagerAddress: Address;
5
+ stakingTokenAddress: Address;
6
+ }
7
+ /** Contract addresses per network (mainnet = Ethereum L1, testnet = Sepolia L1) */
8
+ export declare const NETWORK_CONTRACTS: Record<PolygonNetworks, NetworkContracts>;
9
+ /** Chorus One Polygon ValidatorShare contract addresses */
10
+ export declare const CHORUS_ONE_POLYGON_VALIDATORS: {
11
+ readonly mainnet: `0x${string}`;
12
+ readonly testnet: `0x${string}`;
13
+ };
14
+ export declare const VALIDATOR_SHARE_ABI: readonly [{
15
+ readonly type: "function";
16
+ readonly name: "buyVoucherPOL";
17
+ readonly inputs: readonly [{
18
+ readonly name: "_amount";
19
+ readonly type: "uint256";
20
+ readonly internalType: "uint256";
21
+ }, {
22
+ readonly name: "_minSharesToMint";
23
+ readonly type: "uint256";
24
+ readonly internalType: "uint256";
25
+ }];
26
+ readonly outputs: readonly [{
27
+ readonly name: "amountToDeposit";
28
+ readonly type: "uint256";
29
+ readonly internalType: "uint256";
30
+ }];
31
+ readonly stateMutability: "nonpayable";
32
+ }, {
33
+ readonly type: "function";
34
+ readonly name: "sellVoucher_newPOL";
35
+ readonly inputs: readonly [{
36
+ readonly name: "claimAmount";
37
+ readonly type: "uint256";
38
+ readonly internalType: "uint256";
39
+ }, {
40
+ readonly name: "maximumSharesToBurn";
41
+ readonly type: "uint256";
42
+ readonly internalType: "uint256";
43
+ }];
44
+ readonly outputs: readonly [];
45
+ readonly stateMutability: "nonpayable";
46
+ }, {
47
+ readonly type: "function";
48
+ readonly name: "unstakeClaimTokens_newPOL";
49
+ readonly inputs: readonly [{
50
+ readonly name: "unbondNonce";
51
+ readonly type: "uint256";
52
+ readonly internalType: "uint256";
53
+ }];
54
+ readonly outputs: readonly [];
55
+ readonly stateMutability: "nonpayable";
56
+ }, {
57
+ readonly type: "function";
58
+ readonly name: "withdrawRewardsPOL";
59
+ readonly inputs: readonly [];
60
+ readonly outputs: readonly [];
61
+ readonly stateMutability: "nonpayable";
62
+ }, {
63
+ readonly type: "function";
64
+ readonly name: "restakePOL";
65
+ readonly inputs: readonly [];
66
+ readonly outputs: readonly [{
67
+ readonly name: "amountRestaked";
68
+ readonly type: "uint256";
69
+ readonly internalType: "uint256";
70
+ }, {
71
+ readonly name: "liquidReward";
72
+ readonly type: "uint256";
73
+ readonly internalType: "uint256";
74
+ }];
75
+ readonly stateMutability: "nonpayable";
76
+ }, {
77
+ readonly type: "function";
78
+ readonly name: "getTotalStake";
79
+ readonly inputs: readonly [{
80
+ readonly name: "user";
81
+ readonly type: "address";
82
+ readonly internalType: "address";
83
+ }];
84
+ readonly outputs: readonly [{
85
+ readonly name: "";
86
+ readonly type: "uint256";
87
+ readonly internalType: "uint256";
88
+ }, {
89
+ readonly name: "";
90
+ readonly type: "uint256";
91
+ readonly internalType: "uint256";
92
+ }];
93
+ readonly stateMutability: "view";
94
+ }, {
95
+ readonly type: "function";
96
+ readonly name: "unbondNonces";
97
+ readonly inputs: readonly [{
98
+ readonly name: "";
99
+ readonly type: "address";
100
+ readonly internalType: "address";
101
+ }];
102
+ readonly outputs: readonly [{
103
+ readonly name: "";
104
+ readonly type: "uint256";
105
+ readonly internalType: "uint256";
106
+ }];
107
+ readonly stateMutability: "view";
108
+ }, {
109
+ readonly type: "function";
110
+ readonly name: "unbonds_new";
111
+ readonly inputs: readonly [{
112
+ readonly name: "";
113
+ readonly type: "address";
114
+ readonly internalType: "address";
115
+ }, {
116
+ readonly name: "";
117
+ readonly type: "uint256";
118
+ readonly internalType: "uint256";
119
+ }];
120
+ readonly outputs: readonly [{
121
+ readonly name: "shares";
122
+ readonly type: "uint256";
123
+ readonly internalType: "uint256";
124
+ }, {
125
+ readonly name: "withdrawEpoch";
126
+ readonly type: "uint256";
127
+ readonly internalType: "uint256";
128
+ }];
129
+ readonly stateMutability: "view";
130
+ }, {
131
+ readonly type: "function";
132
+ readonly name: "getLiquidRewards";
133
+ readonly inputs: readonly [{
134
+ readonly name: "user";
135
+ readonly type: "address";
136
+ readonly internalType: "address";
137
+ }];
138
+ readonly outputs: readonly [{
139
+ readonly name: "";
140
+ readonly type: "uint256";
141
+ readonly internalType: "uint256";
142
+ }];
143
+ readonly stateMutability: "view";
144
+ }, {
145
+ readonly type: "function";
146
+ readonly name: "validatorId";
147
+ readonly inputs: readonly [];
148
+ readonly outputs: readonly [{
149
+ readonly name: "";
150
+ readonly type: "uint256";
151
+ readonly internalType: "uint256";
152
+ }];
153
+ readonly stateMutability: "view";
154
+ }, {
155
+ readonly type: "function";
156
+ readonly name: "withdrawExchangeRate";
157
+ readonly inputs: readonly [];
158
+ readonly outputs: readonly [{
159
+ readonly name: "";
160
+ readonly type: "uint256";
161
+ readonly internalType: "uint256";
162
+ }];
163
+ readonly stateMutability: "view";
164
+ }];
165
+ export declare const EXCHANGE_RATE_PRECISION = 100n;
166
+ export declare const EXCHANGE_RATE_HIGH_PRECISION: bigint;
167
+ export declare const STAKE_MANAGER_ABI: readonly [{
168
+ readonly type: "function";
169
+ readonly name: "epoch";
170
+ readonly inputs: readonly [];
171
+ readonly outputs: readonly [{
172
+ readonly name: "";
173
+ readonly type: "uint256";
174
+ readonly internalType: "uint256";
175
+ }];
176
+ readonly stateMutability: "view";
177
+ }, {
178
+ readonly type: "function";
179
+ readonly name: "withdrawalDelay";
180
+ readonly inputs: readonly [];
181
+ readonly outputs: readonly [{
182
+ readonly name: "";
183
+ readonly type: "uint256";
184
+ readonly internalType: "uint256";
185
+ }];
186
+ readonly stateMutability: "view";
187
+ }];
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.STAKE_MANAGER_ABI = exports.EXCHANGE_RATE_HIGH_PRECISION = exports.EXCHANGE_RATE_PRECISION = exports.VALIDATOR_SHARE_ABI = exports.CHORUS_ONE_POLYGON_VALIDATORS = exports.NETWORK_CONTRACTS = void 0;
4
+ /** Contract addresses per network (mainnet = Ethereum L1, testnet = Sepolia L1) */
5
+ // Reference: https://docs.polygon.technology/pos/reference/rpc-endpoints/
6
+ exports.NETWORK_CONTRACTS = {
7
+ mainnet: {
8
+ stakeManagerAddress: '0x5e3Ef299fDDf15eAa0432E6e66473ace8c13D908',
9
+ stakingTokenAddress: '0x455e53CBB86018Ac2B8092FdCd39d8444aFFC3F6'
10
+ },
11
+ testnet: {
12
+ stakeManagerAddress: '0x4AE8f648B1Ec892B6cc68C89cc088583964d08bE',
13
+ stakingTokenAddress: '0x44499312f493F62f2DFd3C6435Ca3603EbFCeeBa'
14
+ }
15
+ };
16
+ /** Chorus One Polygon ValidatorShare contract addresses */
17
+ // Reference mainnet: https://staking.polygon.technology/validators/106
18
+ // Reference testnet (Random Validator): https://staking.polygon.technology/validators/31
19
+ exports.CHORUS_ONE_POLYGON_VALIDATORS = {
20
+ mainnet: '0xD9E6987D77bf2c6d0647b8181fd68A259f838C36',
21
+ testnet: '0x91344055cb0511b3aa36c561d741ee356b95f1c9'
22
+ };
23
+ // Reference: https://github.com/0xPolygon/pos-contracts/blob/main/contracts/staking/validatorShare/ValidatorShare.sol
24
+ exports.VALIDATOR_SHARE_ABI = [
25
+ {
26
+ type: 'function',
27
+ name: 'buyVoucherPOL',
28
+ inputs: [
29
+ { name: '_amount', type: 'uint256', internalType: 'uint256' },
30
+ { name: '_minSharesToMint', type: 'uint256', internalType: 'uint256' }
31
+ ],
32
+ outputs: [{ name: 'amountToDeposit', type: 'uint256', internalType: 'uint256' }],
33
+ stateMutability: 'nonpayable'
34
+ },
35
+ {
36
+ type: 'function',
37
+ name: 'sellVoucher_newPOL',
38
+ inputs: [
39
+ { name: 'claimAmount', type: 'uint256', internalType: 'uint256' },
40
+ { name: 'maximumSharesToBurn', type: 'uint256', internalType: 'uint256' }
41
+ ],
42
+ outputs: [],
43
+ stateMutability: 'nonpayable'
44
+ },
45
+ {
46
+ type: 'function',
47
+ name: 'unstakeClaimTokens_newPOL',
48
+ inputs: [{ name: 'unbondNonce', type: 'uint256', internalType: 'uint256' }],
49
+ outputs: [],
50
+ stateMutability: 'nonpayable'
51
+ },
52
+ {
53
+ type: 'function',
54
+ name: 'withdrawRewardsPOL',
55
+ inputs: [],
56
+ outputs: [],
57
+ stateMutability: 'nonpayable'
58
+ },
59
+ {
60
+ type: 'function',
61
+ name: 'restakePOL',
62
+ inputs: [],
63
+ outputs: [
64
+ { name: 'amountRestaked', type: 'uint256', internalType: 'uint256' },
65
+ { name: 'liquidReward', type: 'uint256', internalType: 'uint256' }
66
+ ],
67
+ stateMutability: 'nonpayable'
68
+ },
69
+ {
70
+ type: 'function',
71
+ name: 'getTotalStake',
72
+ inputs: [{ name: 'user', type: 'address', internalType: 'address' }],
73
+ outputs: [
74
+ { name: '', type: 'uint256', internalType: 'uint256' },
75
+ { name: '', type: 'uint256', internalType: 'uint256' }
76
+ ],
77
+ stateMutability: 'view'
78
+ },
79
+ {
80
+ type: 'function',
81
+ name: 'unbondNonces',
82
+ inputs: [{ name: '', type: 'address', internalType: 'address' }],
83
+ outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
84
+ stateMutability: 'view'
85
+ },
86
+ {
87
+ type: 'function',
88
+ name: 'unbonds_new',
89
+ inputs: [
90
+ { name: '', type: 'address', internalType: 'address' },
91
+ { name: '', type: 'uint256', internalType: 'uint256' }
92
+ ],
93
+ outputs: [
94
+ { name: 'shares', type: 'uint256', internalType: 'uint256' },
95
+ { name: 'withdrawEpoch', type: 'uint256', internalType: 'uint256' }
96
+ ],
97
+ stateMutability: 'view'
98
+ },
99
+ {
100
+ type: 'function',
101
+ name: 'getLiquidRewards',
102
+ inputs: [{ name: 'user', type: 'address', internalType: 'address' }],
103
+ outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
104
+ stateMutability: 'view'
105
+ },
106
+ {
107
+ type: 'function',
108
+ name: 'validatorId',
109
+ inputs: [],
110
+ outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
111
+ stateMutability: 'view'
112
+ },
113
+ {
114
+ type: 'function',
115
+ name: 'withdrawExchangeRate',
116
+ inputs: [],
117
+ outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
118
+ stateMutability: 'view'
119
+ }
120
+ ];
121
+ // Exchange rate precision constants from the ValidatorShare contract
122
+ // Reference: https://github.com/0xPolygon/pos-contracts/blob/main/contracts/staking/validatorShare/ValidatorShare.sol
123
+ exports.EXCHANGE_RATE_PRECISION = 100n;
124
+ exports.EXCHANGE_RATE_HIGH_PRECISION = 10n ** 29n;
125
+ // Reference: https://github.com/0xPolygon/pos-contracts/blob/main/contracts/staking/stakeManager/StakeManager.sol
126
+ exports.STAKE_MANAGER_ABI = [
127
+ {
128
+ type: 'function',
129
+ name: 'epoch',
130
+ inputs: [],
131
+ outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
132
+ stateMutability: 'view'
133
+ },
134
+ {
135
+ type: 'function',
136
+ name: 'withdrawalDelay',
137
+ inputs: [],
138
+ outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
139
+ stateMutability: 'view'
140
+ }
141
+ ];
@@ -0,0 +1,4 @@
1
+ export { PolygonStaker } from './staker';
2
+ export { PolygonNetworkConfig, Transaction, PolygonTxStatus, StakeInfo, UnbondInfo } from './types';
3
+ export { NETWORK_CONTRACTS, CHORUS_ONE_POLYGON_VALIDATORS, VALIDATOR_SHARE_ABI, STAKE_MANAGER_ABI, EXCHANGE_RATE_PRECISION, EXCHANGE_RATE_HIGH_PRECISION } from './constants';
4
+ export type { PolygonNetworks, NetworkContracts } from './constants';
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EXCHANGE_RATE_HIGH_PRECISION = exports.EXCHANGE_RATE_PRECISION = exports.STAKE_MANAGER_ABI = exports.VALIDATOR_SHARE_ABI = exports.CHORUS_ONE_POLYGON_VALIDATORS = exports.NETWORK_CONTRACTS = exports.PolygonStaker = void 0;
4
+ var staker_1 = require("./staker");
5
+ Object.defineProperty(exports, "PolygonStaker", { enumerable: true, get: function () { return staker_1.PolygonStaker; } });
6
+ var constants_1 = require("./constants");
7
+ Object.defineProperty(exports, "NETWORK_CONTRACTS", { enumerable: true, get: function () { return constants_1.NETWORK_CONTRACTS; } });
8
+ Object.defineProperty(exports, "CHORUS_ONE_POLYGON_VALIDATORS", { enumerable: true, get: function () { return constants_1.CHORUS_ONE_POLYGON_VALIDATORS; } });
9
+ Object.defineProperty(exports, "VALIDATOR_SHARE_ABI", { enumerable: true, get: function () { return constants_1.VALIDATOR_SHARE_ABI; } });
10
+ Object.defineProperty(exports, "STAKE_MANAGER_ABI", { enumerable: true, get: function () { return constants_1.STAKE_MANAGER_ABI; } });
11
+ Object.defineProperty(exports, "EXCHANGE_RATE_PRECISION", { enumerable: true, get: function () { return constants_1.EXCHANGE_RATE_PRECISION; } });
12
+ Object.defineProperty(exports, "EXCHANGE_RATE_HIGH_PRECISION", { enumerable: true, get: function () { return constants_1.EXCHANGE_RATE_HIGH_PRECISION; } });
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,2 @@
1
+ import type { Hex } from 'viem';
2
+ export declare const appendReferrerTracking: (data: Hex, referrer?: string) => Hex;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.appendReferrerTracking = void 0;
4
+ const viem_1 = require("viem");
5
+ const DEFAULT_REFERRER = 'sdk-chorusone-staking';
6
+ const REFERRER_MARKER = 'c1c1';
7
+ const encodeReferrer = (referrer) => {
8
+ const hash = (0, viem_1.keccak256)((0, viem_1.toHex)(referrer));
9
+ return `0x${REFERRER_MARKER}${hash.slice(2, 8)}`;
10
+ };
11
+ const appendReferrerTracking = (data, referrer) => {
12
+ const encoded = encodeReferrer(referrer ?? DEFAULT_REFERRER);
13
+ return `${data}${encoded.slice(2)}`;
14
+ };
15
+ exports.appendReferrerTracking = appendReferrerTracking;