Skip to content

Commit 28a15f1

Browse files
authored
Merge pull request #196 from securesecrets/js014_merge-develop
Js014 merge develop
2 parents 3d0ca6b + 0cdfd03 commit 28a15f1

23 files changed

+3626
-2348
lines changed

.changeset/brave-emus-share.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@shadeprotocol/shadejs": patch
3+
---
4+
5+
SecretJs Bump

.changeset/dirty-yaks-think.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@shadeprotocol/shadejs": minor
3+
---
4+
5+
adding decimals as a required arg to queryDerivativeShdStakingInfo

.changeset/large-bananas-speak.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@shadeprotocol/shadejs": minor
3+
---
4+
5+
upgrade secretjs which includes breaking changes for the pre-upgraded version of secret network

.changeset/rotten-paws-judge.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@shadeprotocol/shadejs": patch
3+
---
4+
5+
change from individual validator queries to batch data

.changeset/spicy-badgers-nail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@shadeprotocol/shadejs": patch
3+
---
4+
5+
change secret endpoints to new api after upgrade

.changeset/swift-mirrors-cross.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@shadeprotocol/shadejs": patch
3+
---
4+
5+
add batch query for shade staking

src/client/services/clientServices.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,45 @@ const sendSecretClientContractQuery$ = ({
6464
first(),
6565
);
6666

67+
// This function queries the total supply of the a token
68+
const secretClientTokenSupplyQuery$ = (
69+
client: SecretNetworkClient,
70+
denom: string,
71+
) => createFetchClient(defer(
72+
() => from(client.query.bank.supplyOf({
73+
denom,
74+
})),
75+
));
76+
77+
// This function queries the individual validator data
78+
const secretClientValidatorQuery$ = (
79+
client: SecretNetworkClient,
80+
validatorAddress: string,
81+
) => createFetchClient(defer(
82+
() => from(client.query.staking.validator({ validator_addr: validatorAddress })),
83+
));
84+
85+
// This function queries a single page of multiple validators data
86+
const secretClientValidatorsQuery$ = ({
87+
client,
88+
offset,
89+
limit,
90+
}:{
91+
client: SecretNetworkClient,
92+
offset?: number,
93+
limit?: number,
94+
}) => createFetchClient(defer(
95+
() => from(client.query.staking.validators({
96+
pagination: {
97+
offset: offset ? offset.toString() : undefined,
98+
limit: limit ? limit.toString() : undefined,
99+
},
100+
})),
101+
));
102+
67103
export {
68104
sendSecretClientContractQuery$,
105+
secretClientTokenSupplyQuery$,
106+
secretClientValidatorQuery$,
107+
secretClientValidatorsQuery$,
69108
};

src/contracts/services/derivativeShd.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ beforeAll(() => {
2929
test('it can parse the staking info', () => {
3030
expect(parseDerivativeShdStakingInfo(
3131
stakingInfoResponse as StakingInfoResponse,
32+
8,
3233
)).toStrictEqual(stakingInfoResponseParsed);
3334
});
3435

@@ -41,6 +42,7 @@ test('it can call the query staking info service', async () => {
4142
codeHash: 'CODE_HASH',
4243
lcdEndpoint: 'LCD_ENDPOINT',
4344
chainId: 'CHAIN_ID',
45+
decimals: 8,
4446
};
4547

4648
let output;

src/contracts/services/derivativeShd.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,21 @@ import {
1515
import { convertCoinFromUDenom } from '~/lib/utils';
1616
import { msgQueryShdDerivativeStakingInfo } from '~/contracts/definitions/derivativeShd';
1717

18-
// Contract returns price as a rate of dSHD/SHD with 8 decimals
19-
const DERIVATE_PRICE_DECIMALS = 8;
20-
2118
/**
2219
* Parses the staking info query into a cleaner data model
2320
* NOT FOR PRODUCTION USE, CONTRACT IS IN DEVELOPMENT ON TESTNET ONLY
2421
*/
2522
const parseDerivativeShdStakingInfo = (
2623
response: StakingInfoResponse,
24+
decimals: number,
2725
): ParsedStakingInfoResponse => ({
2826
unbondingTime: response.staking_info.unbonding_time,
2927
bondedShd: response.staking_info.bonded_shd,
3028
rewards: response.staking_info.rewards,
3129
totalDerivativeTokenSupply: response.staking_info.total_derivative_token_supply,
3230
price: convertCoinFromUDenom(
3331
response.staking_info.price,
34-
DERIVATE_PRICE_DECIMALS,
32+
decimals,
3533
).toNumber(),
3634
feeInfo: {
3735
stakingFee: response.staking_info.fee_info.staking.rate / (
@@ -54,19 +52,21 @@ const queryDerivativeShdStakingInfo$ = ({
5452
codeHash,
5553
lcdEndpoint,
5654
chainId,
55+
decimals,
5756
}: {
5857
contractAddress: string,
5958
codeHash?: string,
6059
lcdEndpoint?: string,
6160
chainId?: string,
61+
decimals: number,
6262
}) => getActiveQueryClient$(lcdEndpoint, chainId).pipe(
6363
switchMap(({ client }) => sendSecretClientContractQuery$({
6464
queryMsg: msgQueryShdDerivativeStakingInfo(),
6565
client,
6666
contractAddress,
6767
codeHash,
6868
})),
69-
map((response) => parseDerivativeShdStakingInfo(response as StakingInfoResponse)),
69+
map((response) => parseDerivativeShdStakingInfo(response as StakingInfoResponse, decimals)),
7070
first(),
7171
);
7272

@@ -79,17 +79,20 @@ async function queryDerivativeShdStakingInfo({
7979
codeHash,
8080
lcdEndpoint,
8181
chainId,
82+
decimals,
8283
}: {
8384
contractAddress: string,
8485
codeHash?: string,
8586
lcdEndpoint?: string,
8687
chainId?: string,
88+
decimals: number,
8789
}) {
8890
return lastValueFrom(queryDerivativeShdStakingInfo$({
8991
contractAddress,
9092
codeHash,
9193
lcdEndpoint,
9294
chainId,
95+
decimals,
9396
}));
9497
}
9598

src/contracts/services/shadeStaking.test.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ import { of } from 'rxjs';
88
import stakingOpportunityResponse from '~/test/mocks/shadeStaking/stakingOpportunityResponse.json';
99
import { stakingOpportunityResponseParsed } from '~/test/mocks/shadeStaking/response';
1010
import {
11+
batchQueryShadeStakingOpportunity,
12+
batchQueryShadeStakingOpportunity$,
1113
parseStakingOpportunity,
1214
queryShadeStakingOpportunity,
1315
queryShadeStakingOpportunity$,
1416
} from '~/contracts/services/shadeStaking';
1517
import { StakingInfoServiceResponse } from '~/types/contracts/shadeStaking/index';
18+
import { batchStakingInfoUnparsed } from '~/test/mocks/shadeStaking/batchStakingInfoUnparsed';
19+
import { batchStakingInfoParsed } from '~/test/mocks/shadeStaking/batchStakingInfoParsed';
1620

1721
const sendSecretClientContractQuery$ = vi.hoisted(() => vi.fn());
22+
const batchQuery$ = vi.hoisted(() => vi.fn());
1823

1924
beforeAll(() => {
2025
vi.mock('~/contracts/definitions/shadeStaking', () => ({
@@ -28,6 +33,10 @@ beforeAll(() => {
2833
vi.mock('~/client/services/clientServices', () => ({
2934
sendSecretClientContractQuery$,
3035
}));
36+
37+
vi.mock('~/contracts/services/batchQuery', () => ({
38+
batchQuery$,
39+
}));
3140
});
3241

3342
test('it can parse the shade staking info', () => {
@@ -76,3 +85,60 @@ test('it can call the query shade staking info service', async () => {
7685

7786
expect(output2).toStrictEqual(stakingOpportunityResponseParsed);
7887
});
88+
89+
test('it can call the batch shade staking info query service', async () => {
90+
const input = {
91+
queryRouterContractAddress: 'CONTRACT_ADDRESS',
92+
queryRouterCodeHash: 'CODE_HASH',
93+
lcdEndpoint: 'LCD_ENDPOINT',
94+
chainId: 'CHAIN_ID',
95+
stakingContracts: [{
96+
address: 'STAKING_ADDRESS',
97+
codeHash: 'STAKING_CODE_HASH',
98+
}],
99+
};
100+
// observables function
101+
batchQuery$.mockReturnValueOnce(of(batchStakingInfoUnparsed));
102+
let output;
103+
batchQueryShadeStakingOpportunity$(input).subscribe({
104+
next: (response) => {
105+
output = response;
106+
},
107+
});
108+
109+
expect(batchQuery$).toHaveBeenCalledWith({
110+
contractAddress: input.queryRouterContractAddress,
111+
codeHash: input.queryRouterCodeHash,
112+
lcdEndpoint: input.lcdEndpoint,
113+
chainId: input.chainId,
114+
queries: [{
115+
id: input.stakingContracts[0].address,
116+
contract: {
117+
address: input.stakingContracts[0].address,
118+
codeHash: input.stakingContracts[0].codeHash,
119+
},
120+
queryMsg: 'STAKING_INFO_MSG',
121+
}],
122+
});
123+
124+
expect(output).toStrictEqual(batchStakingInfoParsed);
125+
126+
// async/await function
127+
batchQuery$.mockReturnValueOnce(of(batchStakingInfoUnparsed));
128+
const response = await batchQueryShadeStakingOpportunity(input);
129+
expect(batchQuery$).toHaveBeenCalledWith({
130+
contractAddress: input.queryRouterContractAddress,
131+
codeHash: input.queryRouterCodeHash,
132+
lcdEndpoint: input.lcdEndpoint,
133+
chainId: input.chainId,
134+
queries: [{
135+
id: input.stakingContracts[0].address,
136+
contract: {
137+
address: input.stakingContracts[0].address,
138+
codeHash: input.stakingContracts[0].codeHash,
139+
},
140+
queryMsg: 'STAKING_INFO_MSG',
141+
}],
142+
});
143+
expect(response).toStrictEqual(batchStakingInfoParsed);
144+
});

0 commit comments

Comments
 (0)