Skip to content

Commit c9e0d36

Browse files
authored
Merge pull request #6338 from BitGo/fguo/SC-1430
feat: add go staking service endpoints to sdk
2 parents 11309a6 + 13c4430 commit c9e0d36

File tree

6 files changed

+383
-45
lines changed

6 files changed

+383
-45
lines changed

modules/bitgo/test/v2/fixtures/staking/goStakingWallet.ts

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { GoStakingRequest, UnsignedGoStakingRequest } from '@bitgo/sdk-core';
1+
import {
2+
GoStakingRequest,
3+
GoStakingRequestResults,
4+
GoStakingWalletObject,
5+
GoStakingWalletResults,
6+
UnsignedGoStakingRequest,
7+
} from '@bitgo/sdk-core';
28

39
export default {
410
previewGoStakingRequest: function (coin: string): UnsignedGoStakingRequest {
@@ -24,4 +30,88 @@ export default {
2430
createdDate: '2025-01-03T22:04:29.264Z',
2531
};
2632
},
33+
getGoStakingRequestsByCoin: function (coin: string): GoStakingRequestResults {
34+
return {
35+
requests: [this.finalizeGoStakingRequest(coin, 'STAKE'), this.finalizeGoStakingRequest(coin, 'UNSTAKE')],
36+
page: 1,
37+
totalPages: 1,
38+
totalElements: 2,
39+
};
40+
},
41+
getGoStakingRequests: function (coins: string[]): GoStakingRequestResults {
42+
return {
43+
requests: coins.map((coin) => this.finalizeGoStakingRequest(coin, 'STAKE')),
44+
page: 1,
45+
totalPages: 1,
46+
totalElements: coins.length,
47+
};
48+
},
49+
getGoStakingWallet: function (coin: string): GoStakingWalletObject {
50+
return {
51+
coin: coin,
52+
activeStake: '1000000',
53+
pendingStake: '500000',
54+
pendingUnstake: '200000',
55+
rewards: '10000',
56+
attributes: {
57+
permissionAttributes: {
58+
staking: {
59+
enabled: true,
60+
allowClientToUseOwnValidator: true,
61+
},
62+
unstaking: {
63+
enabled: true,
64+
},
65+
wallet: {
66+
useValidatorList: true,
67+
allowPartialUnstake: true,
68+
validatorNotNeededForStake: false,
69+
},
70+
},
71+
spendableAttributes: {
72+
staking: {
73+
fee: '1000',
74+
max: '10000000',
75+
min: '1000',
76+
netMax: '9000000',
77+
netMin: '500',
78+
minStakeMore: '1000',
79+
minDuration: '3600',
80+
maxDuration: '86400',
81+
},
82+
unstaking: {
83+
fee: '500',
84+
max: '5000000',
85+
min: '1000',
86+
multipleDelegations: true,
87+
requiresAmount: true,
88+
requiresDelegationId: false,
89+
requiresDelegationIds: false,
90+
},
91+
},
92+
disclaimerAttributes: {
93+
staking: {
94+
info: ['Staking is subject to network conditions and may vary.'],
95+
rewardPercentageRate: '5.0',
96+
stakeWarmupPeriodDesc: 'Staking warmup period is 24 hours.',
97+
},
98+
unstaking: {
99+
info: ['Unstaking may take up to 7 days to complete.'],
100+
unStakeCooldownPeriodDesc: 'Unstaking cooldown period is 7 days.',
101+
},
102+
nextRewards: {
103+
rewardCycle: 30,
104+
},
105+
},
106+
},
107+
};
108+
},
109+
getGoStakingWallets: function (coinList: string[]): GoStakingWalletResults {
110+
return {
111+
coins: coinList.map((coin) => this.getGoStakingWallet(coin)),
112+
page: 1,
113+
totalPages: 1,
114+
totalElements: coinList.length,
115+
};
116+
},
27117
};

modules/bitgo/test/v2/unit/staking/goStakingWalletCommon.ts

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ describe('Go Staking Wallet Common', function () {
148148
});
149149

150150
describe('getGoStakingRequest', function () {
151-
it('should call gostaking-service to get go staking request', async function () {
151+
it('should call go-staking-service to get go staking request', async function () {
152152
const stakingRequestId = '8638284a-dab2-46b9-b07f-21109a6e7220';
153153
const expected = fixtures.finalizeGoStakingRequest(coin, 'STAKE');
154154
const msScope = nock(microservicesUri)
@@ -163,4 +163,68 @@ describe('Go Staking Wallet Common', function () {
163163
msScope.isDone().should.be.True();
164164
});
165165
});
166+
167+
describe('getGoStakingRequestsByCoin', function () {
168+
it('should call go-staking-service to get go staking requests by coin', async function () {
169+
const expected = fixtures.getGoStakingRequestsByCoin(ofcCoin);
170+
const msScope = nock(microservicesUri)
171+
.get(`/api/go-staking/v1/${ofcCoin}/accounts/${stakingWallet.accountId}/requests`)
172+
.reply(200, expected);
173+
174+
const stakingRequests = await stakingWallet.getGoStakingRequestsByWalletCoin();
175+
176+
should.exist(stakingRequests);
177+
178+
stakingRequests.should.deepEqual(expected);
179+
msScope.isDone().should.be.True();
180+
});
181+
});
182+
183+
describe('getGoStakingRequests', function () {
184+
it('should call go-staking-service to get go staking requests', async function () {
185+
const expected = fixtures.getGoStakingRequests([ofcCoin]);
186+
const msScope = nock(microservicesUri)
187+
.get(`/api/go-staking/v1/accounts/${stakingWallet.accountId}/requests`)
188+
.reply(200, expected);
189+
190+
const stakingRequests = await stakingWallet.getGoStakingRequests();
191+
192+
should.exist(stakingRequests);
193+
194+
stakingRequests.should.deepEqual(expected);
195+
msScope.isDone().should.be.True();
196+
});
197+
});
198+
199+
describe('getGoStakingWallets', function () {
200+
it('should call go-staking-service to get go staking wallets', async function () {
201+
const expected = fixtures.getGoStakingWallets([ofcCoin]);
202+
const msScope = nock(microservicesUri)
203+
.get(`/api/go-staking/v1/accounts/${stakingWallet.accountId}/coins`)
204+
.reply(200, expected);
205+
206+
const goStakingWallets = await stakingWallet.getGoStakingWallets();
207+
208+
should.exist(goStakingWallets);
209+
210+
goStakingWallets.should.deepEqual(expected);
211+
msScope.isDone().should.be.True();
212+
});
213+
});
214+
215+
describe('getGoStakingWallet', function () {
216+
it('should call go-staking-service to get go staking wallet', async function () {
217+
const expected = fixtures.getGoStakingWallet(ofcCoin);
218+
const msScope = nock(microservicesUri)
219+
.get(`/api/go-staking/v1/${ofcCoin}/accounts/${stakingWallet.accountId}/coins`)
220+
.reply(200, expected);
221+
222+
const goStakingWallet = await stakingWallet.getGoStakingWallet();
223+
224+
should.exist(goStakingWallet);
225+
226+
goStakingWallet.should.deepEqual(expected);
227+
msScope.isDone().should.be.True();
228+
});
229+
});
166230
});
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
import { FrontTransferSendRequest } from './iGoStakingWallet';
2+
3+
export interface UnsignedGoStakingRequest {
4+
payload: string;
5+
coin: string;
6+
token: string;
7+
feeInfo: FeeInfo;
8+
}
9+
10+
interface FeeInfo {
11+
feeString: string;
12+
}
13+
14+
export interface GoStakingRequest {
15+
id: string;
16+
amount: string;
17+
clientId?: string;
18+
type: 'STAKE' | 'UNSTAKE';
19+
coin: string;
20+
status: string;
21+
goSpecificStatus: string;
22+
error?: string;
23+
rawError?: string;
24+
statusModifiedDate: string;
25+
createdDate: string;
26+
}
27+
28+
export interface GoStakeOptions {
29+
amount: string;
30+
clientId?: string;
31+
walletPassphrase: string;
32+
}
33+
34+
export interface BaseGoStakeOptions {
35+
amount: string;
36+
clientId?: string;
37+
}
38+
39+
export interface GoStakeFinalizeOptions extends BaseGoStakeOptions {
40+
frontTransferSendRequest: FrontTransferSendRequest;
41+
}
42+
43+
export interface GoStakingRequestOptions {
44+
status?: string;
45+
page?: number;
46+
pageSize?: number;
47+
createdDateGte?: string;
48+
createdDateLt?: string;
49+
sortBy?: string;
50+
}
51+
52+
export interface GoStakingRequestResults {
53+
requests: GoStakingRequest[];
54+
page: number;
55+
totalPages: number;
56+
totalElements: number;
57+
}
58+
59+
export interface GoStakingWalletResults {
60+
coins: GoStakingWalletObject[];
61+
page: number;
62+
totalPages: number;
63+
totalElements: number;
64+
}
65+
66+
export interface StakingPermissionAttributes {
67+
enabled: boolean;
68+
disabledReason?: string;
69+
allowClientToUseOwnValidator: boolean;
70+
}
71+
72+
export interface UnstakingPermissionAttributes {
73+
enabled: boolean;
74+
disabledReason?: string;
75+
}
76+
77+
export interface WalletPermissionAttributes {
78+
useValidatorList: boolean;
79+
allowPartialUnstake: boolean;
80+
validatorNotNeededForStake: boolean;
81+
}
82+
83+
export interface PermissionAttributes {
84+
staking: StakingPermissionAttributes;
85+
unstaking: UnstakingPermissionAttributes;
86+
wallet: WalletPermissionAttributes;
87+
}
88+
89+
export interface StakingSpendableAttributes {
90+
fee: string;
91+
max: string;
92+
min: string;
93+
netMax: string;
94+
netMin: string;
95+
minStakeMore: string;
96+
minDuration?: string;
97+
maxDuration?: string;
98+
}
99+
100+
export interface UnstakingSpendableAttributes {
101+
fee?: string;
102+
max?: string;
103+
min?: string;
104+
multipleDelegations: boolean;
105+
requiresAmount: boolean;
106+
requiresDelegationId: boolean;
107+
requiresDelegationIds: boolean;
108+
}
109+
110+
export interface SpendableAttributes {
111+
staking: StakingSpendableAttributes;
112+
unstaking: UnstakingSpendableAttributes;
113+
}
114+
115+
export interface StakingDisclaimer {
116+
info: string[];
117+
rewardPercentageRate?: string;
118+
stakeWarmupPeriodDesc?: string;
119+
}
120+
121+
export interface UnstakingDisclaimer {
122+
info: string[];
123+
unStakeCooldownPeriodDesc?: string;
124+
}
125+
126+
export interface NextRewardsDisclaimer {
127+
rewardCycle: number;
128+
}
129+
130+
export interface DisclaimerAttributes {
131+
staking: StakingDisclaimer;
132+
unstaking: UnstakingDisclaimer;
133+
nextRewards?: NextRewardsDisclaimer;
134+
}
135+
136+
export interface GoStakingAttributes {
137+
permissionAttributes: PermissionAttributes;
138+
spendableAttributes: SpendableAttributes;
139+
disclaimerAttributes: DisclaimerAttributes;
140+
}
141+
142+
export interface GoStakingWalletObject {
143+
coin: string;
144+
activeStake: string;
145+
pendingStake: string;
146+
pendingUnstake: string;
147+
rewards: string;
148+
attributes: GoStakingAttributes;
149+
}

0 commit comments

Comments
 (0)