Skip to content

Commit

Permalink
sdk: add getMaxSwapAmount (#488)
Browse files Browse the repository at this point in the history
* temp

* add calculateSpotPositionFreeCollateralContribution

* sdk: do binary search for max token swap

* fix boundary conditions

* fix edge case causing inf loop

* try to add leverage

* remove some console.logs

* make leverage work for reducing position

* make it work w small accounts

* make initial max swap larger

* add accountLeverageAfterSwap

* dont throw error in getSpotTokenAmount

* allow custom calcuateSwap fn and iteration limit

* CHANGELOG
  • Loading branch information
crispheaney committed Jun 22, 2023
1 parent 5090422 commit 950b61c
Show file tree
Hide file tree
Showing 3 changed files with 459 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Features

- ts-sdk: add getMaxSwapAmount (([#488](https://github.com/drift-labs/protocol-v2/pull/488)))
- program: add bulk place orders ix (([#499](https://github.com/drift-labs/protocol-v2/pull/499)))
- ts-sdk: add stakeForMSOL to driftClient (([#500](https://github.com/drift-labs/protocol-v2/pull/500)))
- ts-sdk: driftClient accepts default txParams (([#496](https://github.com/drift-labs/protocol-v2/pull/496)))
Expand Down
4 changes: 4 additions & 0 deletions sdk/src/math/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export const divCeil = (a: BN, b: BN): BN => {
}
};

export const sigNum = (x: BN): BN => {
return x.isNeg() ? new BN(-1) : new BN(1);
};

/**
* calculates the time remaining until the next update based on a rounded, "on-the-hour" update schedule
* this schedule is used for Perpetual Funding Rate and Revenue -> Insurance Updates
Expand Down
Loading

0 comments on commit 950b61c

Please sign in to comment.