-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
275 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# APY Calculations | ||
|
||
This page demonstrates how to calculate outputs the shade derivative contracts | ||
|
||
### stkd-SCRT APY | ||
Calculates the apy expected for the stkd-SCRT token | ||
```ts | ||
/** | ||
* Will calculate APY for the stkd secret derivative contract | ||
* | ||
* returns a number that is the decimal form of the percent APY | ||
*/ | ||
function calculateDerivativeScrtApy({ | ||
queryRouterContractAddress, | ||
queryRouterCodeHash, | ||
contractAddress, | ||
codeHash, | ||
lcdEndpoint, | ||
chainId, | ||
}: { | ||
queryRouterContractAddress: string, | ||
queryRouterCodeHash?: string, | ||
contractAddress: string, | ||
codeHash: string, | ||
lcdEndpoint: string, | ||
chainId?: string, | ||
}): Promise<number> | ||
``` | ||
|
||
### dSHD APY | ||
Calculates the apy expected for the stkd-SCRT token | ||
```ts | ||
/** | ||
* Calculates the dSHD expected APY by querying the staking contract | ||
* TESTNET ONLY NOT READY FOR PRODUCTION | ||
* | ||
* returns a number that is the decimal form of the percent APY | ||
*/ | ||
async function calculateDerivativeShdApy({ | ||
shadeTokenContractAddress, | ||
shadeStakingContractAddress, | ||
shadeStakingCodeHash, | ||
decimals, | ||
price, | ||
lcdEndpoint, | ||
chainId, | ||
}:{ | ||
shadeTokenContractAddress: string, | ||
shadeStakingContractAddress: string, | ||
shadeStakingCodeHash?: string, | ||
decimals: number, | ||
price: string, | ||
lcdEndpoint?: string, | ||
chainId?: string, | ||
}): Promise<number> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Shade Staking Examples | ||
|
||
This page demonstrates how to query the shade staking contracts | ||
|
||
## Staking Info | ||
|
||
**input** | ||
|
||
```ts | ||
/** | ||
* query the staking info from the shade staking contract | ||
*/ | ||
async function queryShadeStakingOpportunity({ | ||
shadeStakingContractAddress, | ||
shadeStakingCodeHash, | ||
lcdEndpoint, | ||
chainId, | ||
}: { | ||
shadeStakingContractAddress: string, | ||
shadeStakingCodeHash?: string, | ||
lcdEndpoint?: string, | ||
chainId?: string, | ||
}): Promise<StakingInfoServiceModel> | ||
``` | ||
|
||
**output** | ||
|
||
```ts | ||
type StakingInfoServiceModel = { | ||
stakeTokenAddress: string, | ||
totalStakedRaw: string, | ||
unbondingPeriod: number, | ||
rewardPools: StakingRewardPoolServiceModel[], | ||
} | ||
// type references below | ||
type StakingRewardPoolServiceModel = { | ||
id: string, | ||
amountRaw: string, | ||
startDate: Date, | ||
endDate: Date, | ||
tokenAddress: string, | ||
rateRaw: string, | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { | ||
test, | ||
expect, | ||
} from 'vitest'; | ||
import { msgQueryShadeStakingOpportunity } from './shadeStaking'; | ||
|
||
test('it tests the form of the query staking info msg', () => { | ||
const output = { staking_info: {} }; | ||
expect(msgQueryShadeStakingOpportunity()).toStrictEqual(output); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { | ||
test, | ||
expect, | ||
vi, | ||
beforeAll, | ||
} from 'vitest'; | ||
import { | ||
SecretQueryOptions, | ||
} from '~/types/apy'; | ||
import { of } from 'rxjs'; | ||
import { | ||
secretChainQuery$, | ||
secretChainQuery, | ||
secretChainQueries$, | ||
secretChainQueries, | ||
parseSecretQueryResponse, | ||
} from './secretQueries'; | ||
|
||
beforeAll(async () => { | ||
vi.mock('~/client/services/createFetch', () => ({ | ||
createFetch: vi.fn(() => of({ response: 'MOCK_API_RESPONSE' })), | ||
})); | ||
}); | ||
|
||
test('it can parse chain queries', () => { | ||
expect(parseSecretQueryResponse( | ||
{ result: 10 }, | ||
SecretQueryOptions.INFLATION, | ||
)).toStrictEqual({ secretInflationPercent: 10 }); | ||
|
||
expect(parseSecretQueryResponse( | ||
{ amount: { amount: 10 } }, | ||
SecretQueryOptions.TOTAL_SUPPLY, | ||
)).toStrictEqual({ secretTotalSupplyRaw: 10 }); | ||
|
||
expect(parseSecretQueryResponse( | ||
{ result: { bonded_tokens: 10 } }, | ||
SecretQueryOptions.TOTAL_STAKED, | ||
)).toStrictEqual({ secretTotalStakedRaw: 10 }); | ||
|
||
expect(parseSecretQueryResponse( | ||
{ result: { community_tax: '10', secret_foundation_tax: '11' } }, | ||
SecretQueryOptions.TAXES, | ||
)).toStrictEqual({ secretTaxes: { foundationTaxPercent: 11, communityTaxPercent: 10 } }); | ||
|
||
expect(parseSecretQueryResponse( | ||
{ result: [{ commission: { commission_rates: { rate: '10' } }, operator_address: 'MOCK_ADDRESS' }] }, | ||
SecretQueryOptions.VALIDATORS, | ||
)).toStrictEqual({ secretValidators: [{ ratePercent: 10, validatorAddress: 'MOCK_ADDRESS' }] }); | ||
|
||
expect(parseSecretQueryResponse( | ||
'nonsence', | ||
'/nonsence/api', | ||
)).toStrictEqual('nonsence'); | ||
}); | ||
|
||
test('it can do a single chain query', async () => { | ||
let output; | ||
secretChainQuery$('MOCK_URL', 'MOCK_ENDPOINT').subscribe({ | ||
next: (response) => { | ||
output = response; | ||
}, | ||
}); | ||
expect(output).toStrictEqual({ response: 'MOCK_API_RESPONSE' }); | ||
const output2 = await secretChainQuery('MOCK_URL', 'MOCK_ENDPOINT'); | ||
expect(output2).toStrictEqual({ response: 'MOCK_API_RESPONSE' }); | ||
}); | ||
|
||
test('it can do many chain queries', async () => { | ||
let output; | ||
secretChainQueries$('MOCK_URL', ['MOCK_ENDPOINT']).subscribe({ | ||
next: (response) => { | ||
output = response; | ||
}, | ||
}); | ||
expect(output).toStrictEqual({ response: 'MOCK_API_RESPONSE' }); | ||
const output2 = await secretChainQueries('MOCK_URL', ['MOCK_ENDPOINT']); | ||
expect(output2).toStrictEqual({ response: 'MOCK_API_RESPONSE' }); | ||
}); |
Oops, something went wrong.