-
Notifications
You must be signed in to change notification settings - Fork 4
Add getShortBondsGivenDeposit to sdk, absDiff to fixed point
#1549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8385f96
14cd3e0
0838bd5
c0e8c30
9389f84
cc2cff8
df65382
297e9fd
574b53f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@delvtech/hyperdrive-js-core": minor | ||
| --- | ||
|
|
||
| Add `getShortBondsGivenDeposit` method to `ReadHyperdrive` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@delvtech/hyperdrive-wasm": patch | ||
| --- | ||
|
|
||
| Add `shortBondsGivenDeposit` function |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@delvtech/fixed-point-wasm": patch | ||
| --- | ||
|
|
||
| Add `absDiff` method |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,4 +16,4 @@ thiserror = "1.0" | |
| wasm-bindgen = "0.2.92" | ||
|
|
||
| # internal | ||
| fixedpointmath = "0.17.1" | ||
| fixedpointmath = "0.18.1" | ||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1663,6 +1663,55 @@ export class ReadHyperdrive extends ReadModel { | |
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Predicts the amount of bonds that can be shorted given a target deposit | ||
| * amount in either base or shares. | ||
| */ | ||
| async getShortBondsGivenDeposit({ | ||
| amountIn, | ||
| asBase, | ||
| tolerance, | ||
| options, | ||
| }: { | ||
| amountIn: bigint; | ||
| asBase: boolean; | ||
| /** | ||
| * The maximum difference between the target and actual base amount. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1e9 is decent for 18 decimal numbers, but for usdc (6 decimals) we'll definitely want to set a smaller tolerance. Should we capture this in the TokenConfig, HyperdriveConfig, or just inline a bit of logic in our hook to look at the token decimals and map that to a known good tolerance?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could also just make the default tolerance in ReadHyperdrive dynamic based on
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question. I'd confirm with @dpaiton on how far this tolerance can go before it stops working, but if the tolerance a pool uses is data based on other data (e.g., the token's decimals) then I'd inline it to keep the config data more normalized. |
||
| * | ||
| * @default 1e9 | ||
| */ | ||
| tolerance?: bigint; | ||
| options?: ContractReadOptions; | ||
| }): Promise<bigint> { | ||
| const poolConfig = await this.getPoolConfig(options); | ||
| const poolInfo = await this.getPoolInfo(options); | ||
| const latestCheckpoint = await this.getCheckpoint({ options }); | ||
| const checkpointExposure = await this.getCheckpointExposure({ options }); | ||
|
|
||
| let targetBaseAmount = amountIn; | ||
| if (!asBase) { | ||
| targetBaseAmount = await this.convertToBase({ | ||
| sharesAmount: amountIn, | ||
| options, | ||
| }); | ||
| } | ||
|
|
||
| const absoluteMaxBondAmount = hyperwasm.absoluteMaxShort({ | ||
| poolInfo, | ||
| poolConfig, | ||
| checkpointExposure, | ||
| }); | ||
|
|
||
| return hyperwasm.shortBondsGivenDeposit({ | ||
| poolInfo, | ||
| poolConfig, | ||
| targetBaseAmount, | ||
| absoluteMaxBondAmount, | ||
| openVaultSharePrice: latestCheckpoint.vaultSharePrice, | ||
| maybeTolerance: tolerance, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Predicts the amount of base asset a user will receive when closing a long. | ||
| */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉