-
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.
Merge pull request #96 from securesecrets/js002_stkd-messages
stkd-scrt messages and services
- Loading branch information
Showing
22 changed files
with
675 additions
and
23 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,5 @@ | ||
--- | ||
"@shadeprotocol/shadejs": patch | ||
--- | ||
|
||
Added stkd-scrt messages and services, and refactored dSHD names to derivativeShd |
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,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; | ||
} | ||
``` |
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, | ||
} 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); | ||
}); |
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,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, | ||
}; |
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
Oops, something went wrong.