Skip to content

Commit

Permalink
Merge pull request #96 from securesecrets/js002_stkd-messages
Browse files Browse the repository at this point in the history
stkd-scrt messages and services
  • Loading branch information
AustinWoetzel authored Mar 27, 2024
2 parents 82a3421 + 82884da commit 77c7e0f
Show file tree
Hide file tree
Showing 22 changed files with 675 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-apples-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@shadeprotocol/shadejs": patch
---

Added stkd-scrt messages and services, and refactored dSHD names to derivativeShd
1 change: 1 addition & 0 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default defineConfig({
items: [
{ text: 'Swap', link: '/queries/swap' },
{ text: 'Oracle', link: '/queries/oracle' },
{ text: 'stkd-SCRT', link: '/queries/derivativeScrt' },
{ text: 'Batch Query', link: '/queries/batch-query' },
{ text: 'Snip20', link: '/queries/snip20' },
]
Expand Down
2 changes: 2 additions & 0 deletions docs/contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This page contains a list of deployed contracts.
| ShadeSwap Router | secret1pjhdug87nxzv0esxasmeyfsucaj98pw4334wyc | 448e3f6d801e453e838b7a5fbaa4dd93b84d0f1011245f0d5745366dadaf3e85 |
| Batch Query Router | secret17gnlxnwux0szd7qhl90ym8lw22qvedjz4v09dm | 72a09535b77b76862f7b568baf1ddbe158a2e4bbd0f0879c69ada9b398e31c1f |
| Oracle | secret10n2xl5jmez6r9umtdrth78k0vwmce0l5m9f5dm | 32c4710842b97a526c243a68511b15f58d6e72a388af38a7221ff3244c754e91 |
| stkd-scrt | secret1k6u0cy4feepm6pehnz804zmwakuwdapm69tuc4 | f6be719b3c6feb498d3554ca0398eb6b7e7db262acb33f84a8f12106da6bbb09 |

::: tip
The ShadeSwap pairs contracts are accessible via the factory registered pairs query.
Expand All @@ -22,3 +23,4 @@ The ShadeSwap pairs contracts are accessible via the factory registered pairs qu
| ShadeSwap Router | secret137sjm7hgqdp4d0dldqnrxe2ktw02meaygnjd0e | 93dac48bf508eeb4c619fcb8b1cb260f9957e31450740a2b7325440ddf92daa8 |
| Batch Query Router | secret10cxkxmspt44mp2wym6dcguk5wqqkm5a9ydw3du | 72a09535b77b76862f7b568baf1ddbe158a2e4bbd0f0879c69ada9b398e31c1f |
| Oracle | secret17z47r9u4nqytpdgvewxq4jqd965sfj2wpsnlak | 113c47c016667817b315dde03b4ee9774edf1fb293a7ea3f02d983c6b1fa1cf1 |
| stkd-scrt | secret14svk0x3sztxwta9kv9dv6fwzqlc26mmjfyypc2 | 680fbb3c8f8eb1c920da13d857daaedaa46ab8f9a8e26e892bb18a16985ec29e |
56 changes: 56 additions & 0 deletions docs/queries/derivativeScrt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Scrt Derivative Examples

This page demonstrates how to query the stkd Scrt derivative contracts

## Derivative Info

**input**

```ts
/**
* query both the staking info and the fee info
*
* queryTimeSeconds is a paramater to query the contract
* at a specific time in seconds from the UNIX Epoch
* Optional and will default to current time
*/
const queryDerivativeScrtInfo = ({
queryRouterContractAddress,
queryRouterCodeHash,
contractAddress,
codeHash,
lcdEndpoint,
chainId,
queryTimeSeconds,
}: {
queryRouterContractAddress: string,
queryRouterCodeHash?: string,
contractAddress: string,
codeHash: string,
lcdEndpoint?: string,
chainId?: string,
queryTimeSeconds?: number,
}): Promise<DerivativeScrtInfo>
```

**output**

```ts
type DerivativeScrtInfo = {
validators: DerivativeScrtValidator[],
supply: string,
exchangeRate: number,
communityRewards: string,
nextUnboundAmount: string,
nextUnbondingBatchEstimatedTime: number,
depositFee: number,
withdrawFee: number,
}

// type references below

type DerivativeScrtValidator = {
validatorAddress: string,
weight: number;
}
```
79 changes: 79 additions & 0 deletions src/contracts/definitions/derivativeScrt.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import {
test,
expect,
vi,
} from 'vitest';
import {
msgQueryScrtDerivativeStakingInfo,
msgQueryScrtDerivativeFees,
msgQueryScrtDerivativeUserUnbondings,
msgDerivativeScrtStake,
msgDerivativeScrtUnbond,
msgDerivativeScrtClaim,
} from '~/contracts/definitions/derivativeScrt';

vi.mock('~/lib/utils', () => ({
generatePadding: vi.fn(() => 'RANDOM_PADDING'),
}));

test('it tests the form of the query staking info msg', () => {
const time = Math.round(new Date().getTime() / 1000);
const output = {
staking_info: {
time,
},
};
expect(msgQueryScrtDerivativeStakingInfo(time)).toStrictEqual(output);
});

test('it tests the form of the query fee info msg', () => {
const output = {
fee_info: {
},
};
expect(msgQueryScrtDerivativeFees()).toStrictEqual(output);
});

test('it tests the form of the query user unbondings msg', () => {
const output = {
unbondings: {
address: 'USER_ADDR',
key: 'VIEWING_KEY',
},
};
expect(msgQueryScrtDerivativeUserUnbondings('USER_ADDR', 'VIEWING_KEY')).toStrictEqual(output);
});

test('it tests the form of the stake execute msg', () => {
const output = {
msg: {
stake: {
padding: 'RANDOM_PADDING',
},
},
transferAmount: {
amount: '123456789',
denom: 'uscrt',
},
};
expect(msgDerivativeScrtStake(output.transferAmount.amount)).toStrictEqual(output);
});

test('it tests the form of the unbond execute msg', () => {
const output = {
unbond: {
redeem_amount: '12341234',
padding: 'RANDOM_PADDING',
},
};
expect(msgDerivativeScrtUnbond(output.unbond.redeem_amount)).toStrictEqual(output);
});

test('it tests the form of the claim msg', () => {
const output = {
claim: {
padding: 'RANDOM_PADDING',
},
};
expect(msgDerivativeScrtClaim()).toStrictEqual(output);
});
71 changes: 71 additions & 0 deletions src/contracts/definitions/derivativeScrt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { generatePadding } from '~/lib/utils';

/**
* Query the public contract staking info
* ex: time = Math.round(new Date().getTime() / 1000)
*/
const msgQueryScrtDerivativeStakingInfo = (time: number) => ({ staking_info: { time } });

/**
* Query the public contract fee information
*/
const msgQueryScrtDerivativeFees = () => ({ fee_info: {} });

/**
* Query the users private unbondings
*/
const msgQueryScrtDerivativeUserUnbondings = (userAddress: string, viewingKey: string) => ({
unbondings: {
address: userAddress,
key: viewingKey,
},
});

/**
* message to stake scrt to receive stkd-scrt
*/
function msgDerivativeScrtStake(stakeAmount: string) {
return {
msg: {
stake: {
padding: generatePadding(),
},
},
transferAmount: {
amount: stakeAmount,
denom: 'uscrt',
},
};
}

/**
* message to unbond stkd-scrt to eventually receive secret
*/
function msgDerivativeScrtUnbond(unbondAmount: string) {
return {
unbond: {
redeem_amount: unbondAmount,
padding: generatePadding(),
},
};
}

/**
* message to claim unbonded stkd-scrt as secret
*/
function msgDerivativeScrtClaim() {
return {
claim: {
padding: generatePadding(),
},
};
}

export {
msgQueryScrtDerivativeStakingInfo,
msgQueryScrtDerivativeFees,
msgQueryScrtDerivativeUserUnbondings,
msgDerivativeScrtStake,
msgDerivativeScrtUnbond,
msgDerivativeScrtClaim,
};
20 changes: 10 additions & 10 deletions src/contracts/definitions/derivativeShd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import {
vi,
} from 'vitest';
import {
msgQueryStakingInfo,
msgQueryUserHoldingsWithViewingKey,
msgQueryUserUnbondingsWithViewingKey,
msgQueryShdDerivativeStakingInfo,
msgQueryShdDerivativeUserHoldingsWithViewingKey,
msgQueryShdDerivativeUserUnbondingsWithViewingKey,
msgDerivativeShdStake,
msgDerivativeShdUnbond,
msgDerivativeShdTransferStaked,
msgQueryUserHoldingsWithPermit,
msgQueryUserUnbondingsWithPermit,
msgQueryShdDerivativeUserHoldingsWithPermit,
msgQueryShdDerivativeUserUnbondingsWithPermit,
} from '~/contracts/definitions/derivativeShd';
import { StdSignature } from 'secretjs';
import { snip20 } from './snip20';
Expand All @@ -30,7 +30,7 @@ vi.mock('~/lib/utils', () => ({

test('it tests the form of the query staking info msg', () => {
const output = { staking_info: {} };
expect(msgQueryStakingInfo()).toStrictEqual(output);
expect(msgQueryShdDerivativeStakingInfo()).toStrictEqual(output);
});

test('it tests the form of the query user holdings msg', () => {
Expand All @@ -40,7 +40,7 @@ test('it tests the form of the query user holdings msg', () => {
viewing_key: 'VIEWING_KEY',
},
};
expect(msgQueryUserHoldingsWithViewingKey('USER_ADDR', 'VIEWING_KEY')).toStrictEqual(output);
expect(msgQueryShdDerivativeUserHoldingsWithViewingKey('USER_ADDR', 'VIEWING_KEY')).toStrictEqual(output);
});

test('it tests the form of the query user holdings msg with permit', () => {
Expand All @@ -58,7 +58,7 @@ test('it tests the form of the query user holdings msg with permit', () => {
query: { holdings: { } },
},
};
expect(msgQueryUserHoldingsWithPermit(permit)).toStrictEqual(output);
expect(msgQueryShdDerivativeUserHoldingsWithPermit(permit)).toStrictEqual(output);
});

test('it tests the form of the query user unbondings msg', () => {
Expand All @@ -68,7 +68,7 @@ test('it tests the form of the query user unbondings msg', () => {
viewing_key: 'VIEWING_KEY',
},
};
expect(msgQueryUserUnbondingsWithViewingKey('USER_ADDR', 'VIEWING_KEY')).toStrictEqual(output);
expect(msgQueryShdDerivativeUserUnbondingsWithViewingKey('USER_ADDR', 'VIEWING_KEY')).toStrictEqual(output);
});

test('it tests the form of the query user unbondings msg', () => {
Expand All @@ -86,7 +86,7 @@ test('it tests the form of the query user unbondings msg', () => {
query: { unbondings: { } },
},
};
expect(msgQueryUserUnbondingsWithPermit(permit)).toStrictEqual(output);
expect(msgQueryShdDerivativeUserUnbondingsWithPermit(permit)).toStrictEqual(output);
});

test('it tests the form of the stake execute msg', () => {
Expand Down
26 changes: 16 additions & 10 deletions src/contracts/definitions/derivativeShd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import { AccountPermit } from '~/types/permit';
* Query the public contract staking info
* NOT FOR PRODUCTION USE, CONTRACT IS IN DEVELOPMENT ON TESTNET ONLY
*/
const msgQueryStakingInfo = () => ({ staking_info: {} });
const msgQueryShdDerivativeStakingInfo = () => ({ staking_info: {} });

/**
* Query the users private holdings
* NOT FOR PRODUCTION USE, CONTRACT IS IN DEVELOPMENT ON TESTNET ONLY
*/
const msgQueryUserHoldingsWithViewingKey = (userAddress: string, viewingKey: string) => ({
const msgQueryShdDerivativeUserHoldingsWithViewingKey = (
userAddress: string,
viewingKey: string,
) => ({
holdings: {
address: userAddress,
viewing_key: viewingKey,
Expand All @@ -23,7 +26,7 @@ const msgQueryUserHoldingsWithViewingKey = (userAddress: string, viewingKey: str
* Query the users private holdings with a permit
* NOT FOR PRODUCTION USE, CONTRACT IS IN DEVELOPMENT ON TESTNET ONLY
*/
const msgQueryUserHoldingsWithPermit = (permit: AccountPermit) => ({
const msgQueryShdDerivativeUserHoldingsWithPermit = (permit: AccountPermit) => ({
with_permit: {
permit,
query: {
Expand All @@ -36,7 +39,10 @@ const msgQueryUserHoldingsWithPermit = (permit: AccountPermit) => ({
* Query the users private unbondings
* NOT FOR PRODUCTION USE, CONTRACT IS IN DEVELOPMENT ON TESTNET ONLY
*/
const msgQueryUserUnbondingsWithViewingKey = (userAddress: string, viewingKey: string) => ({
const msgQueryShdDerivativeUserUnbondingsWithViewingKey = (
userAddress: string,
viewingKey: string,
) => ({
unbondings: {
address: userAddress,
viewing_key: viewingKey,
Expand All @@ -47,7 +53,7 @@ const msgQueryUserUnbondingsWithViewingKey = (userAddress: string, viewingKey: s
* Query the users private unbondings with a permit
* NOT FOR PRODUCTION USE, CONTRACT IS IN DEVELOPMENT ON TESTNET ONLY
*/
const msgQueryUserUnbondingsWithPermit = (permit: AccountPermit) => ({
const msgQueryShdDerivativeUserUnbondingsWithPermit = (permit: AccountPermit) => ({
with_permit: {
permit,
query: {
Expand Down Expand Up @@ -127,11 +133,11 @@ function msgDerivativeShdTransferStaked({
}

export {
msgQueryStakingInfo,
msgQueryUserHoldingsWithViewingKey,
msgQueryUserUnbondingsWithViewingKey,
msgQueryUserHoldingsWithPermit,
msgQueryUserUnbondingsWithPermit,
msgQueryShdDerivativeStakingInfo,
msgQueryShdDerivativeUserHoldingsWithViewingKey,
msgQueryShdDerivativeUserUnbondingsWithViewingKey,
msgQueryShdDerivativeUserHoldingsWithPermit,
msgQueryShdDerivativeUserUnbondingsWithPermit,
msgDerivativeShdStake,
msgDerivativeShdUnbond,
msgDerivativeShdTransferStaked,
Expand Down
1 change: 1 addition & 0 deletions src/contracts/definitions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './oracle';
export * from './snip20';
export * from './swap';
export * from './derivativeShd';
export * from './derivativeScrt';
Loading

0 comments on commit 77c7e0f

Please sign in to comment.