@quantabit/staking-sdk 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.
- package/LICENSE +21 -0
- package/README.md +39 -0
- package/dist/index.cjs +174 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.esm.js +161 -0
- package/dist/index.esm.js.map +1 -0
- package/package.json +71 -0
- package/types/index.d.ts +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 QuantaBit Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @quantabit/staking-sdk
|
|
2
|
+
|
|
3
|
+
QuantaBit Staking SDK provides comprehensive tools for participating in Proof-of-Stake validator operations, reward monitoring, unbonding scheduling, and native yield simulation in the QuantaBit network.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Validator Delegation**: Delegate and stake native QBT tokens with verified validator nodes.
|
|
8
|
+
- **Yield Calculation**: Simulate APY / APR rewards over custom lockup periods.
|
|
9
|
+
- **Reward Claiming**: Redeem accumulated node staking rewards in a single step.
|
|
10
|
+
- **Staking hooks**: React hooks to monitor real-time node stakes and user deposits.
|
|
11
|
+
- **Multilingual Support**: Fully localized dictionary support for EN, ZH, JA, and KO.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @quantabit/staking-sdk @quantabit/sdk-config
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
import { stakeTokens, claimStakingRewards, calculateStakingYield } from '@quantabit/staking-sdk';
|
|
23
|
+
|
|
24
|
+
// Calculate estimated yield
|
|
25
|
+
const estimatedInterest = calculateStakingYield(5000, 180, 0.082); // stake 5000 QBT for 180 days at 8.2% APR
|
|
26
|
+
|
|
27
|
+
// Stake tokens
|
|
28
|
+
const record = await stakeTokens('val_node_1', 1000);
|
|
29
|
+
|
|
30
|
+
// Claim rewards
|
|
31
|
+
await claimStakingRewards('val_node_1');
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Brand & Links
|
|
35
|
+
|
|
36
|
+
- **Official Website**: [https://quantabit.io](https://quantabit.io)
|
|
37
|
+
- **Documentation**: [https://docs.quantabit.io](https://docs.quantabit.io)
|
|
38
|
+
- **Explorer**: [https://explorer.mg.qbitchain.io](https://explorer.mg.qbitchain.io)
|
|
39
|
+
- **Source Code**: [https://github.com/quantabit-chain/qbit-sdk](https://github.com/quantabit-chain/qbit-sdk)
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var sdkConfig = require('@quantabit/sdk-config');
|
|
5
|
+
|
|
6
|
+
const messages = {
|
|
7
|
+
en: {
|
|
8
|
+
stake_success: "Staking successful",
|
|
9
|
+
unstake_success: "Unstaking request submitted successfully",
|
|
10
|
+
claim_success: "Rewards claimed successfully",
|
|
11
|
+
insufficient_balance: "Insufficient balance for staking",
|
|
12
|
+
invalid_validator: "Invalid validator address"
|
|
13
|
+
},
|
|
14
|
+
zh: {
|
|
15
|
+
stake_success: "质押成功",
|
|
16
|
+
unstake_success: "解质押请求已成功提交",
|
|
17
|
+
claim_success: "收益领取成功",
|
|
18
|
+
insufficient_balance: "余额不足,无法进行质押",
|
|
19
|
+
invalid_validator: "无效的验证节点地址"
|
|
20
|
+
},
|
|
21
|
+
ja: {
|
|
22
|
+
stake_success: "ステーキングに成功しました",
|
|
23
|
+
unstake_success: "ステーキング解除リクエストが正常に送信されました",
|
|
24
|
+
claim_success: "報酬の請求に成功しました",
|
|
25
|
+
insufficient_balance: "ステーキングに必要な残高が不足しています",
|
|
26
|
+
invalid_validator: "無効なバリデータアドレス"
|
|
27
|
+
},
|
|
28
|
+
ko: {
|
|
29
|
+
stake_success: "스테이킹 성공",
|
|
30
|
+
unstake_success: "스테이킹 해제 요청이 성공적으로 제출되었습니다",
|
|
31
|
+
claim_success: "보상 수령 완료",
|
|
32
|
+
insufficient_balance: "스테이킹할 잔액이 부족합니다",
|
|
33
|
+
invalid_validator: "유효하지 않은 검증인 주소"
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
let currentLang = null;
|
|
37
|
+
function getLanguage() {
|
|
38
|
+
return currentLang || sdkConfig.getLanguage() || 'en';
|
|
39
|
+
}
|
|
40
|
+
function setLanguage(lang) {
|
|
41
|
+
if (messages[lang]) {
|
|
42
|
+
currentLang = lang;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function t(key) {
|
|
46
|
+
const lang = getLanguage();
|
|
47
|
+
return messages[lang]?.[key] || messages['en']?.[key] || key;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 模拟验证节点数据
|
|
51
|
+
const VALIDATORS = {
|
|
52
|
+
"val_node_1": {
|
|
53
|
+
address: "val_node_1",
|
|
54
|
+
name: "QuantaBit Core Validator",
|
|
55
|
+
apr: 0.082,
|
|
56
|
+
totalStaked: 15000000
|
|
57
|
+
},
|
|
58
|
+
"val_node_2": {
|
|
59
|
+
address: "val_node_2",
|
|
60
|
+
name: "Genesis Community Validator",
|
|
61
|
+
apr: 0.095,
|
|
62
|
+
totalStaked: 8000000
|
|
63
|
+
},
|
|
64
|
+
"val_node_3": {
|
|
65
|
+
address: "val_node_3",
|
|
66
|
+
name: "Antigravity Power Node",
|
|
67
|
+
apr: 0.114,
|
|
68
|
+
totalStaked: 3500000
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
async function stakeTokens(validatorAddress, amount) {
|
|
72
|
+
const validator = VALIDATORS[validatorAddress];
|
|
73
|
+
if (!validator) {
|
|
74
|
+
throw new Error(t('invalid_validator'));
|
|
75
|
+
}
|
|
76
|
+
if (amount <= 0) {
|
|
77
|
+
throw new Error("Staking amount must be positive");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// 模拟扣除余额和创建质押记录
|
|
81
|
+
return {
|
|
82
|
+
txHash: `stake_tx_${Math.random().toString(36).substr(2, 9)}`,
|
|
83
|
+
validatorAddress,
|
|
84
|
+
amount,
|
|
85
|
+
apr: validator.apr,
|
|
86
|
+
status: "confirmed",
|
|
87
|
+
message: t('stake_success')
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
async function unstakeTokens(validatorAddress, amount) {
|
|
91
|
+
const validator = VALIDATORS[validatorAddress];
|
|
92
|
+
if (!validator) {
|
|
93
|
+
throw new Error(t('invalid_validator'));
|
|
94
|
+
}
|
|
95
|
+
if (amount <= 0) {
|
|
96
|
+
throw new Error("Unstaking amount must be positive");
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
txHash: `unstake_tx_${Math.random().toString(36).substr(2, 9)}`,
|
|
100
|
+
validatorAddress,
|
|
101
|
+
amount,
|
|
102
|
+
status: "pending_unbonding",
|
|
103
|
+
message: t('unstake_success')
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
async function claimStakingRewards(validatorAddress) {
|
|
107
|
+
const validator = VALIDATORS[validatorAddress];
|
|
108
|
+
if (!validator) {
|
|
109
|
+
throw new Error(t('invalid_validator'));
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
txHash: `claim_tx_${Math.random().toString(36).substr(2, 9)}`,
|
|
113
|
+
validatorAddress,
|
|
114
|
+
amountClaimed: parseFloat((Math.random() * 100).toFixed(4)),
|
|
115
|
+
status: "confirmed",
|
|
116
|
+
message: t('claim_success')
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
async function getValidatorInfo(validatorAddress) {
|
|
120
|
+
const validator = VALIDATORS[validatorAddress];
|
|
121
|
+
if (!validator) {
|
|
122
|
+
throw new Error(t('invalid_validator'));
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
...validator
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function calculateStakingYield(amount, durationDays, apr) {
|
|
129
|
+
const dailyRate = apr / 365;
|
|
130
|
+
const yieldEarned = amount * dailyRate * durationDays;
|
|
131
|
+
return parseFloat(yieldEarned.toFixed(4));
|
|
132
|
+
}
|
|
133
|
+
function useStakingInfo(userAddress) {
|
|
134
|
+
const [stakingData, setStakingData] = react.useState([]);
|
|
135
|
+
const [loading, setLoading] = react.useState(true);
|
|
136
|
+
react.useEffect(() => {
|
|
137
|
+
if (!userAddress) return;
|
|
138
|
+
setLoading(true);
|
|
139
|
+
|
|
140
|
+
// 模拟异步拉取用户质押账户状态
|
|
141
|
+
const timer = setTimeout(() => {
|
|
142
|
+
setStakingData([{
|
|
143
|
+
validatorAddress: "val_node_1",
|
|
144
|
+
stakedAmount: 1000,
|
|
145
|
+
pendingRewards: 5.42
|
|
146
|
+
}, {
|
|
147
|
+
validatorAddress: "val_node_3",
|
|
148
|
+
stakedAmount: 500,
|
|
149
|
+
pendingRewards: 12.18
|
|
150
|
+
}]);
|
|
151
|
+
setLoading(false);
|
|
152
|
+
}, 400);
|
|
153
|
+
return () => clearTimeout(timer);
|
|
154
|
+
}, [userAddress]);
|
|
155
|
+
return {
|
|
156
|
+
stakingData,
|
|
157
|
+
loading
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
const SUPPORTED_LANGUAGES = ['en', 'zh', 'ja', 'ko'];
|
|
161
|
+
|
|
162
|
+
exports.SUPPORTED_LANGUAGES = SUPPORTED_LANGUAGES;
|
|
163
|
+
exports.VALIDATORS = VALIDATORS;
|
|
164
|
+
exports.calculateStakingYield = calculateStakingYield;
|
|
165
|
+
exports.claimStakingRewards = claimStakingRewards;
|
|
166
|
+
exports.getLanguage = getLanguage;
|
|
167
|
+
exports.getValidatorInfo = getValidatorInfo;
|
|
168
|
+
exports.messages = messages;
|
|
169
|
+
exports.setLanguage = setLanguage;
|
|
170
|
+
exports.stakeTokens = stakeTokens;
|
|
171
|
+
exports.t = t;
|
|
172
|
+
exports.unstakeTokens = unstakeTokens;
|
|
173
|
+
exports.useStakingInfo = useStakingInfo;
|
|
174
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/i18n/index.js","../src/index.js"],"sourcesContent":["import { getLanguage as getGlobalLang } from '@quantabit/sdk-config';\n\nexport const messages = {\n en: {\n stake_success: \"Staking successful\",\n unstake_success: \"Unstaking request submitted successfully\",\n claim_success: \"Rewards claimed successfully\",\n insufficient_balance: \"Insufficient balance for staking\",\n invalid_validator: \"Invalid validator address\"\n },\n zh: {\n stake_success: \"质押成功\",\n unstake_success: \"解质押请求已成功提交\",\n claim_success: \"收益领取成功\",\n insufficient_balance: \"余额不足,无法进行质押\",\n invalid_validator: \"无效的验证节点地址\"\n },\n ja: {\n stake_success: \"ステーキングに成功しました\",\n unstake_success: \"ステーキング解除リクエストが正常に送信されました\",\n claim_success: \"報酬の請求に成功しました\",\n insufficient_balance: \"ステーキングに必要な残高が不足しています\",\n invalid_validator: \"無効なバリデータアドレス\"\n },\n ko: {\n stake_success: \"스테이킹 성공\",\n unstake_success: \"스테이킹 해제 요청이 성공적으로 제출되었습니다\",\n claim_success: \"보상 수령 완료\",\n insufficient_balance: \"스테이킹할 잔액이 부족합니다\",\n invalid_validator: \"유효하지 않은 검증인 주소\"\n }\n};\n\nlet currentLang = null;\n\nexport function getLanguage() {\n return currentLang || getGlobalLang() || 'en';\n}\n\nexport function setLanguage(lang) {\n if (messages[lang]) {\n currentLang = lang;\n }\n}\n\nexport function t(key) {\n const lang = getLanguage();\n return messages[lang]?.[key] || messages['en']?.[key] || key;\n}\n","import { useState, useEffect } from 'react';\nimport { getConfig } from '@quantabit/sdk-config';\nimport { t, setLanguage, getLanguage, messages } from './i18n/index.js';\n\n// 模拟验证节点数据\nconst VALIDATORS = {\n \"val_node_1\": { address: \"val_node_1\", name: \"QuantaBit Core Validator\", apr: 0.082, totalStaked: 15000000 },\n \"val_node_2\": { address: \"val_node_2\", name: \"Genesis Community Validator\", apr: 0.095, totalStaked: 8000000 },\n \"val_node_3\": { address: \"val_node_3\", name: \"Antigravity Power Node\", apr: 0.114, totalStaked: 3500000 }\n};\n\nexport async function stakeTokens(validatorAddress, amount) {\n const validator = VALIDATORS[validatorAddress];\n if (!validator) {\n throw new Error(t('invalid_validator'));\n }\n if (amount <= 0) {\n throw new Error(\"Staking amount must be positive\");\n }\n \n // 模拟扣除余额和创建质押记录\n return {\n txHash: `stake_tx_${Math.random().toString(36).substr(2, 9)}`,\n validatorAddress,\n amount,\n apr: validator.apr,\n status: \"confirmed\",\n message: t('stake_success')\n };\n}\n\nexport async function unstakeTokens(validatorAddress, amount) {\n const validator = VALIDATORS[validatorAddress];\n if (!validator) {\n throw new Error(t('invalid_validator'));\n }\n if (amount <= 0) {\n throw new Error(\"Unstaking amount must be positive\");\n }\n \n return {\n txHash: `unstake_tx_${Math.random().toString(36).substr(2, 9)}`,\n validatorAddress,\n amount,\n status: \"pending_unbonding\",\n message: t('unstake_success')\n };\n}\n\nexport async function claimStakingRewards(validatorAddress) {\n const validator = VALIDATORS[validatorAddress];\n if (!validator) {\n throw new Error(t('invalid_validator'));\n }\n \n return {\n txHash: `claim_tx_${Math.random().toString(36).substr(2, 9)}`,\n validatorAddress,\n amountClaimed: parseFloat((Math.random() * 100).toFixed(4)),\n status: \"confirmed\",\n message: t('claim_success')\n };\n}\n\nexport async function getValidatorInfo(validatorAddress) {\n const validator = VALIDATORS[validatorAddress];\n if (!validator) {\n throw new Error(t('invalid_validator'));\n }\n return { ...validator };\n}\n\nexport function calculateStakingYield(amount, durationDays, apr) {\n const dailyRate = apr / 365;\n const yieldEarned = amount * dailyRate * durationDays;\n return parseFloat(yieldEarned.toFixed(4));\n}\n\nexport function useStakingInfo(userAddress) {\n const [stakingData, setStakingData] = useState([]);\n const [loading, setLoading] = useState(true);\n\n useEffect(() => {\n if (!userAddress) return;\n setLoading(true);\n \n // 模拟异步拉取用户质押账户状态\n const timer = setTimeout(() => {\n setStakingData([\n { validatorAddress: \"val_node_1\", stakedAmount: 1000, pendingRewards: 5.42 },\n { validatorAddress: \"val_node_3\", stakedAmount: 500, pendingRewards: 12.18 }\n ]);\n setLoading(false);\n }, 400);\n\n return () => clearTimeout(timer);\n }, [userAddress]);\n\n return { stakingData, loading };\n}\n\nexport { t, setLanguage, getLanguage, messages };\nexport const SUPPORTED_LANGUAGES = ['en', 'zh', 'ja', 'ko'];\nexport { VALIDATORS };\n"],"names":["messages","en","stake_success","unstake_success","claim_success","insufficient_balance","invalid_validator","zh","ja","ko","currentLang","getLanguage","getGlobalLang","setLanguage","lang","t","key","VALIDATORS","address","name","apr","totalStaked","stakeTokens","validatorAddress","amount","validator","Error","txHash","Math","random","toString","substr","status","message","unstakeTokens","claimStakingRewards","amountClaimed","parseFloat","toFixed","getValidatorInfo","calculateStakingYield","durationDays","dailyRate","yieldEarned","useStakingInfo","userAddress","stakingData","setStakingData","useState","loading","setLoading","useEffect","timer","setTimeout","stakedAmount","pendingRewards","clearTimeout","SUPPORTED_LANGUAGES"],"mappings":";;;;;AAEO,MAAMA,QAAQ,GAAG;AACtBC,EAAAA,EAAE,EAAE;AACFC,IAAAA,aAAa,EAAE,oBAAoB;AACnCC,IAAAA,eAAe,EAAE,0CAA0C;AAC3DC,IAAAA,aAAa,EAAE,8BAA8B;AAC7CC,IAAAA,oBAAoB,EAAE,kCAAkC;AACxDC,IAAAA,iBAAiB,EAAE;GACpB;AACDC,EAAAA,EAAE,EAAE;AACFL,IAAAA,aAAa,EAAE,MAAM;AACrBC,IAAAA,eAAe,EAAE,YAAY;AAC7BC,IAAAA,aAAa,EAAE,QAAQ;AACvBC,IAAAA,oBAAoB,EAAE,aAAa;AACnCC,IAAAA,iBAAiB,EAAE;GACpB;AACDE,EAAAA,EAAE,EAAE;AACFN,IAAAA,aAAa,EAAE,eAAe;AAC9BC,IAAAA,eAAe,EAAE,0BAA0B;AAC3CC,IAAAA,aAAa,EAAE,cAAc;AAC7BC,IAAAA,oBAAoB,EAAE,sBAAsB;AAC5CC,IAAAA,iBAAiB,EAAE;GACpB;AACDG,EAAAA,EAAE,EAAE;AACFP,IAAAA,aAAa,EAAE,SAAS;AACxBC,IAAAA,eAAe,EAAE,2BAA2B;AAC5CC,IAAAA,aAAa,EAAE,UAAU;AACzBC,IAAAA,oBAAoB,EAAE,iBAAiB;AACvCC,IAAAA,iBAAiB,EAAE;AACrB;AACF;AAEA,IAAII,WAAW,GAAG,IAAI;AAEf,SAASC,WAAWA,GAAG;AAC5B,EAAA,OAAOD,WAAW,IAAIE,qBAAa,EAAE,IAAI,IAAI;AAC/C;AAEO,SAASC,WAAWA,CA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AAAK,OAAC,EAC5E;AAAEhC,QAAAA,gBAAgB,EAAE,YAAY;AAAE+B,QAAAA,YAAY,EAAE,GAAG;AAAEC,QAAAA,cAAc,EAAE;AAAM,OAAC,CAC7E,CAAC;MACFL,UAAU,CAAC,KAAK,CAAC;IACnB,CAAC,EAAE,GAAG,CAAC;AAEP,IAAA,OAAO,MAAMM,YAAY,CAACJ,KAAK,CAAC;AAClC,EAAA,CAAC,EAAE,CAACP,WAAW,CAAC,CAAC;EAEjB,OAAO;IAAEC,WAAW;AAAEG,IAAAA;GAAS;AACjC;AAGO,MAAMQ,mBAAmB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import { getLanguage as getLanguage$1 } from '@quantabit/sdk-config';
|
|
3
|
+
|
|
4
|
+
const messages = {
|
|
5
|
+
en: {
|
|
6
|
+
stake_success: "Staking successful",
|
|
7
|
+
unstake_success: "Unstaking request submitted successfully",
|
|
8
|
+
claim_success: "Rewards claimed successfully",
|
|
9
|
+
insufficient_balance: "Insufficient balance for staking",
|
|
10
|
+
invalid_validator: "Invalid validator address"
|
|
11
|
+
},
|
|
12
|
+
zh: {
|
|
13
|
+
stake_success: "质押成功",
|
|
14
|
+
unstake_success: "解质押请求已成功提交",
|
|
15
|
+
claim_success: "收益领取成功",
|
|
16
|
+
insufficient_balance: "余额不足,无法进行质押",
|
|
17
|
+
invalid_validator: "无效的验证节点地址"
|
|
18
|
+
},
|
|
19
|
+
ja: {
|
|
20
|
+
stake_success: "ステーキングに成功しました",
|
|
21
|
+
unstake_success: "ステーキング解除リクエストが正常に送信されました",
|
|
22
|
+
claim_success: "報酬の請求に成功しました",
|
|
23
|
+
insufficient_balance: "ステーキングに必要な残高が不足しています",
|
|
24
|
+
invalid_validator: "無効なバリデータアドレス"
|
|
25
|
+
},
|
|
26
|
+
ko: {
|
|
27
|
+
stake_success: "스테이킹 성공",
|
|
28
|
+
unstake_success: "스테이킹 해제 요청이 성공적으로 제출되었습니다",
|
|
29
|
+
claim_success: "보상 수령 완료",
|
|
30
|
+
insufficient_balance: "스테이킹할 잔액이 부족합니다",
|
|
31
|
+
invalid_validator: "유효하지 않은 검증인 주소"
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
let currentLang = null;
|
|
35
|
+
function getLanguage() {
|
|
36
|
+
return currentLang || getLanguage$1() || 'en';
|
|
37
|
+
}
|
|
38
|
+
function setLanguage(lang) {
|
|
39
|
+
if (messages[lang]) {
|
|
40
|
+
currentLang = lang;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function t(key) {
|
|
44
|
+
const lang = getLanguage();
|
|
45
|
+
return messages[lang]?.[key] || messages['en']?.[key] || key;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 模拟验证节点数据
|
|
49
|
+
const VALIDATORS = {
|
|
50
|
+
"val_node_1": {
|
|
51
|
+
address: "val_node_1",
|
|
52
|
+
name: "QuantaBit Core Validator",
|
|
53
|
+
apr: 0.082,
|
|
54
|
+
totalStaked: 15000000
|
|
55
|
+
},
|
|
56
|
+
"val_node_2": {
|
|
57
|
+
address: "val_node_2",
|
|
58
|
+
name: "Genesis Community Validator",
|
|
59
|
+
apr: 0.095,
|
|
60
|
+
totalStaked: 8000000
|
|
61
|
+
},
|
|
62
|
+
"val_node_3": {
|
|
63
|
+
address: "val_node_3",
|
|
64
|
+
name: "Antigravity Power Node",
|
|
65
|
+
apr: 0.114,
|
|
66
|
+
totalStaked: 3500000
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
async function stakeTokens(validatorAddress, amount) {
|
|
70
|
+
const validator = VALIDATORS[validatorAddress];
|
|
71
|
+
if (!validator) {
|
|
72
|
+
throw new Error(t('invalid_validator'));
|
|
73
|
+
}
|
|
74
|
+
if (amount <= 0) {
|
|
75
|
+
throw new Error("Staking amount must be positive");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 模拟扣除余额和创建质押记录
|
|
79
|
+
return {
|
|
80
|
+
txHash: `stake_tx_${Math.random().toString(36).substr(2, 9)}`,
|
|
81
|
+
validatorAddress,
|
|
82
|
+
amount,
|
|
83
|
+
apr: validator.apr,
|
|
84
|
+
status: "confirmed",
|
|
85
|
+
message: t('stake_success')
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
async function unstakeTokens(validatorAddress, amount) {
|
|
89
|
+
const validator = VALIDATORS[validatorAddress];
|
|
90
|
+
if (!validator) {
|
|
91
|
+
throw new Error(t('invalid_validator'));
|
|
92
|
+
}
|
|
93
|
+
if (amount <= 0) {
|
|
94
|
+
throw new Error("Unstaking amount must be positive");
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
txHash: `unstake_tx_${Math.random().toString(36).substr(2, 9)}`,
|
|
98
|
+
validatorAddress,
|
|
99
|
+
amount,
|
|
100
|
+
status: "pending_unbonding",
|
|
101
|
+
message: t('unstake_success')
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
async function claimStakingRewards(validatorAddress) {
|
|
105
|
+
const validator = VALIDATORS[validatorAddress];
|
|
106
|
+
if (!validator) {
|
|
107
|
+
throw new Error(t('invalid_validator'));
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
txHash: `claim_tx_${Math.random().toString(36).substr(2, 9)}`,
|
|
111
|
+
validatorAddress,
|
|
112
|
+
amountClaimed: parseFloat((Math.random() * 100).toFixed(4)),
|
|
113
|
+
status: "confirmed",
|
|
114
|
+
message: t('claim_success')
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
async function getValidatorInfo(validatorAddress) {
|
|
118
|
+
const validator = VALIDATORS[validatorAddress];
|
|
119
|
+
if (!validator) {
|
|
120
|
+
throw new Error(t('invalid_validator'));
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
...validator
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function calculateStakingYield(amount, durationDays, apr) {
|
|
127
|
+
const dailyRate = apr / 365;
|
|
128
|
+
const yieldEarned = amount * dailyRate * durationDays;
|
|
129
|
+
return parseFloat(yieldEarned.toFixed(4));
|
|
130
|
+
}
|
|
131
|
+
function useStakingInfo(userAddress) {
|
|
132
|
+
const [stakingData, setStakingData] = useState([]);
|
|
133
|
+
const [loading, setLoading] = useState(true);
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
if (!userAddress) return;
|
|
136
|
+
setLoading(true);
|
|
137
|
+
|
|
138
|
+
// 模拟异步拉取用户质押账户状态
|
|
139
|
+
const timer = setTimeout(() => {
|
|
140
|
+
setStakingData([{
|
|
141
|
+
validatorAddress: "val_node_1",
|
|
142
|
+
stakedAmount: 1000,
|
|
143
|
+
pendingRewards: 5.42
|
|
144
|
+
}, {
|
|
145
|
+
validatorAddress: "val_node_3",
|
|
146
|
+
stakedAmount: 500,
|
|
147
|
+
pendingRewards: 12.18
|
|
148
|
+
}]);
|
|
149
|
+
setLoading(false);
|
|
150
|
+
}, 400);
|
|
151
|
+
return () => clearTimeout(timer);
|
|
152
|
+
}, [userAddress]);
|
|
153
|
+
return {
|
|
154
|
+
stakingData,
|
|
155
|
+
loading
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
const SUPPORTED_LANGUAGES = ['en', 'zh', 'ja', 'ko'];
|
|
159
|
+
|
|
160
|
+
export { SUPPORTED_LANGUAGES, VALIDATORS, calculateStakingYield, claimStakingRewards, getLanguage, getValidatorInfo, messages, setLanguage, stakeTokens, t, unstakeTokens, useStakingInfo };
|
|
161
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/i18n/index.js","../src/index.js"],"sourcesContent":["import { getLanguage as getGlobalLang } from '@quantabit/sdk-config';\n\nexport const messages = {\n en: {\n stake_success: \"Staking successful\",\n unstake_success: \"Unstaking request submitted successfully\",\n claim_success: \"Rewards claimed successfully\",\n insufficient_balance: \"Insufficient balance for staking\",\n invalid_validator: \"Invalid validator address\"\n },\n zh: {\n stake_success: \"质押成功\",\n unstake_success: \"解质押请求已成功提交\",\n claim_success: \"收益领取成功\",\n insufficient_balance: \"余额不足,无法进行质押\",\n invalid_validator: \"无效的验证节点地址\"\n },\n ja: {\n stake_success: \"ステーキングに成功しました\",\n unstake_success: \"ステーキング解除リクエストが正常に送信されました\",\n claim_success: \"報酬の請求に成功しました\",\n insufficient_balance: \"ステーキングに必要な残高が不足しています\",\n invalid_validator: \"無効なバリデータアドレス\"\n },\n ko: {\n stake_success: \"스테이킹 성공\",\n unstake_success: \"스테이킹 해제 요청이 성공적으로 제출되었습니다\",\n claim_success: \"보상 수령 완료\",\n insufficient_balance: \"스테이킹할 잔액이 부족합니다\",\n invalid_validator: \"유효하지 않은 검증인 주소\"\n }\n};\n\nlet currentLang = null;\n\nexport function getLanguage() {\n return currentLang || getGlobalLang() || 'en';\n}\n\nexport function setLanguage(lang) {\n if (messages[lang]) {\n currentLang = lang;\n }\n}\n\nexport function t(key) {\n const lang = getLanguage();\n return messages[lang]?.[key] || messages['en']?.[key] || key;\n}\n","import { useState, useEffect } from 'react';\nimport { getConfig } from '@quantabit/sdk-config';\nimport { t, setLanguage, getLanguage, messages } from './i18n/index.js';\n\n// 模拟验证节点数据\nconst VALIDATORS = {\n \"val_node_1\": { address: \"val_node_1\", name: \"QuantaBit Core Validator\", apr: 0.082, totalStaked: 15000000 },\n \"val_node_2\": { address: \"val_node_2\", name: \"Genesis Community Validator\", apr: 0.095, totalStaked: 8000000 },\n \"val_node_3\": { address: \"val_node_3\", name: \"Antigravity Power Node\", apr: 0.114, totalStaked: 3500000 }\n};\n\nexport async function stakeTokens(validatorAddress, amount) {\n const validator = VALIDATORS[validatorAddress];\n if (!validator) {\n throw new Error(t('invalid_validator'));\n }\n if (amount <= 0) {\n throw new Error(\"Staking amount must be positive\");\n }\n \n // 模拟扣除余额和创建质押记录\n return {\n txHash: `stake_tx_${Math.random().toString(36).substr(2, 9)}`,\n validatorAddress,\n amount,\n apr: validator.apr,\n status: \"confirmed\",\n message: t('stake_success')\n };\n}\n\nexport async function unstakeTokens(validatorAddress, amount) {\n const validator = VALIDATORS[validatorAddress];\n if (!validator) {\n throw new Error(t('invalid_validator'));\n }\n if (amount <= 0) {\n throw new Error(\"Unstaking amount must be positive\");\n }\n \n return {\n txHash: `unstake_tx_${Math.random().toString(36).substr(2, 9)}`,\n validatorAddress,\n amount,\n status: \"pending_unbonding\",\n message: t('unstake_success')\n };\n}\n\nexport async function claimStakingRewards(validatorAddress) {\n const validator = VALIDATORS[validatorAddress];\n if (!validator) {\n throw new Error(t('invalid_validator'));\n }\n \n return {\n txHash: `claim_tx_${Math.random().toString(36).substr(2, 9)}`,\n validatorAddress,\n amountClaimed: parseFloat((Math.random() * 100).toFixed(4)),\n status: \"confirmed\",\n message: t('claim_success')\n };\n}\n\nexport async function getValidatorInfo(validatorAddress) {\n const validator = VALIDATORS[validatorAddress];\n if (!validator) {\n throw new Error(t('invalid_validator'));\n }\n return { ...validator };\n}\n\nexport function calculateStakingYield(amount, durationDays, apr) {\n const dailyRate = apr / 365;\n const yieldEarned = amount * dailyRate * durationDays;\n return parseFloat(yieldEarned.toFixed(4));\n}\n\nexport function useStakingInfo(userAddress) {\n const [stakingData, setStakingData] = useState([]);\n const [loading, setLoading] = useState(true);\n\n useEffect(() => {\n if (!userAddress) return;\n setLoading(true);\n \n // 模拟异步拉取用户质押账户状态\n const timer = setTimeout(() => {\n setStakingData([\n { validatorAddress: \"val_node_1\", stakedAmount: 1000, pendingRewards: 5.42 },\n { validatorAddress: \"val_node_3\", stakedAmount: 500, pendingRewards: 12.18 }\n ]);\n setLoading(false);\n }, 400);\n\n return () => clearTimeout(timer);\n }, [userAddress]);\n\n return { stakingData, loading };\n}\n\nexport { t, setLanguage, getLanguage, messages };\nexport const SUPPORTED_LANGUAGES = ['en', 'zh', 'ja', 'ko'];\nexport { VALIDATORS };\n"],"names":["messages","en","stake_success","unstake_success","claim_success","insufficient_balance","invalid_validator","zh","ja","ko","currentLang","getLanguage","getGlobalLang","setLanguage","lang","t","key","VALIDATORS","address","name","apr","totalStaked","stakeTokens","validatorAddress","amount","validator","Error","txHash","Math","random","toString","substr","status","message","unstakeTokens","claimStakingRewards","amountClaimed","parseFloat","toFixed","getValidatorInfo","calculateStakingYield","durationDays","dailyRate","yieldEarned","useStakingInfo","userAddress","stakingData","setStakingData","useState","loading","setLoading","useEffect","timer","setTimeout","stakedAmount","pendingRewards","clearTimeout","SUPPORTED_LANGUAGES"],"mappings":";;;AAEO,MAAMA,QAAQ,GAAG;AACtBC,EAAAA,EAAE,EAAE;AACFC,IAAAA,aAAa,EAAE,oBAAoB;AACnCC,IAAAA,eAAe,EAAE,0CAA0C;AAC3DC,IAAAA,aAAa,EAAE,8BAA8B;AAC7CC,IAAAA,oBAAoB,EAAE,kCAAkC;AACxDC,IAAAA,iBAAiB,EAAE;GACpB;AACDC,EAAAA,EAAE,EAAE;AACFL,IAAAA,aAAa,EAAE,MAAM;AACrBC,IAAAA,eAAe,EAAE,YAAY;AAC7BC,IAAAA,aAAa,EAAE,QAAQ;AACvBC,IAAAA,oBAAoB,EAAE,aAAa;AACnCC,IAAAA,iBAAiB,EAAE;GACpB;AACDE,EAAAA,EAAE,EAAE;AACFN,IAAAA,aAAa,EAAE,eAAe;AAC9BC,IAAAA,eAAe,EAAE,0BAA0B;AAC3CC,IAAAA,aAAa,EAAE,cAAc;AAC7BC,IAAAA,oBAAoB,EAAE,sBAAsB;AAC5CC,IAAAA,iBAAiB,EAAE;GACpB;AACDG,EAAAA,EAAE,EAAE;AACFP,IAAAA,aAAa,EAAE,SAAS;AACxBC,IAAAA,eAAe,EAAE,2BAA2B;AAC5CC,IAAAA,aAAa,EAAE,UAAU;AACzBC,IAAAA,oBAAoB,EAAE,iBAAiB;AACvCC,IAAAA,iBAAiB,EAAE;AACrB;AACF;AAEA,IAAII,WA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AAC7BN,MAAAA,cAAc,CAAC,CACb;AAAExB,QAAAA,gBAAgB,EAAE,YAAY;AAAE+B,QAAAA,YAAY,EAAE,IAAI;AAAEC,QAAAA,cAAc,EAAE;AAAK,OAAC,EAC5E;AAAEhC,QAAAA,gBAAgB,EAAE,YAAY;AAAE+B,QAAAA,YAAY,EAAE,GAAG;AAAEC,QAAAA,cAAc,EAAE;AAAM,OAAC,CAC7E,CAAC;MACFL,UAAU,CAAC,KAAK,CAAC;IACnB,CAAC,EAAE,GAAG,CAAC;AAEP,IAAA,OAAO,MAAMM,YAAY,CAACJ,KAAK,CAAC;AAClC,EAAA,CAAC,EAAE,CAACP,WAAW,CAAC,CAAC;EAEjB,OAAO;IAAEC,WAAW;AAAEG,IAAAA;GAAS;AACjC;AAGO,MAAMQ,mBAAmB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@quantabit/staking-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "QuantaBit Staking SDK - Native token staking, reward calculations and validator interactions",
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.esm.js",
|
|
8
|
+
"types": "types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./types/index.d.ts",
|
|
12
|
+
"import": "./dist/index.esm.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"sideEffects": [
|
|
17
|
+
"*.css"
|
|
18
|
+
],
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"types",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "rollup -c",
|
|
27
|
+
"dev": "rollup -c -w",
|
|
28
|
+
"test": "jest --passWithNoTests",
|
|
29
|
+
"prepublishOnly": "npm run build"
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/quantabit-chain/qbit-sdk.git",
|
|
34
|
+
"directory": "packages/staking-sdk"
|
|
35
|
+
},
|
|
36
|
+
"keywords": [
|
|
37
|
+
"staking",
|
|
38
|
+
"delegate",
|
|
39
|
+
"apr",
|
|
40
|
+
"web3",
|
|
41
|
+
"react",
|
|
42
|
+
"quantabit"
|
|
43
|
+
],
|
|
44
|
+
"author": "QuantaBit Team",
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=18.0.0"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"react": ">=17.0.0",
|
|
51
|
+
"react-dom": ">=17.0.0"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@quantabit/sdk-config": "^1.0.10"
|
|
55
|
+
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public"
|
|
58
|
+
},
|
|
59
|
+
"qbit": {
|
|
60
|
+
"privacy": {
|
|
61
|
+
"level": "functional",
|
|
62
|
+
"dataCollection": "Queries staking node performance. No personal details processed.",
|
|
63
|
+
"gdprCompliant": true,
|
|
64
|
+
"ccpaCompliant": true
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"homepage": "https://github.com/quantabit-chain/qbit-sdk/tree/main/packages/staking-sdk#readme",
|
|
68
|
+
"bugs": {
|
|
69
|
+
"url": "https://github.com/quantabit-chain/qbit-sdk/issues"
|
|
70
|
+
}
|
|
71
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export interface Validator {
|
|
2
|
+
address: string;
|
|
3
|
+
name: string;
|
|
4
|
+
apr: number;
|
|
5
|
+
totalStaked: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface StakingRecord {
|
|
9
|
+
txHash: string;
|
|
10
|
+
validatorAddress: string;
|
|
11
|
+
amount: number;
|
|
12
|
+
apr?: number;
|
|
13
|
+
status: string;
|
|
14
|
+
message: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ClaimResult {
|
|
18
|
+
txHash: string;
|
|
19
|
+
validatorAddress: string;
|
|
20
|
+
amountClaimed: number;
|
|
21
|
+
status: string;
|
|
22
|
+
message: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function stakeTokens(validatorAddress: string, amount: number): Promise<StakingRecord>;
|
|
26
|
+
export function unstakeTokens(validatorAddress: string, amount: number): Promise<StakingRecord>;
|
|
27
|
+
export function claimStakingRewards(validatorAddress: string): Promise<ClaimResult>;
|
|
28
|
+
export function getValidatorInfo(validatorAddress: string): Promise<Validator>;
|
|
29
|
+
export function calculateStakingYield(amount: number, durationDays: number, apr: number): number;
|
|
30
|
+
|
|
31
|
+
export function useStakingInfo(userAddress: string): {
|
|
32
|
+
stakingData: Array<{
|
|
33
|
+
validatorAddress: string;
|
|
34
|
+
stakedAmount: number;
|
|
35
|
+
pendingRewards: number;
|
|
36
|
+
}>;
|
|
37
|
+
loading: boolean;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export function getLanguage(): string;
|
|
41
|
+
export function setLanguage(lang: string): void;
|
|
42
|
+
export function t(key: string): string;
|
|
43
|
+
export const SUPPORTED_LANGUAGES: string[];
|
|
44
|
+
export const messages: Record<string, Record<string, string>>;
|