-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Comment nits * Change `raw` to `bigint` in fixed-point-wasm * Use string template in fixed-point example * Convert wasm errors to JS `error` objects * Add missing `track_caller` attribute * Accept bigints in fixed point methods * Replace `convertSharesToBase` in SDK w/ inline fixed-point math * Use `bigint` property in fixed-point example * Use `HyperdriveSdkError` in place of `Error` * Fix conversion macro imports * Make fixed-point arguments more flexible * Add `toNumber` method to fixed-point * Update example * Build * Delete previous fixedpoint file * Update fixed-point usage in SDK * Update example and README * Adjust tests for new math lib * nit * Make `fixed` function arg required
- Loading branch information
Showing
21 changed files
with
552 additions
and
406 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 |
---|---|---|
@@ -1,27 +1,22 @@ | ||
import { | ||
fixed, | ||
initSync, | ||
parseFixed, | ||
wasmBuffer, | ||
} from "@delvtech/fixed-point-wasm"; | ||
import { fixed, initSync, wasmBuffer } from "@delvtech/fixed-point-wasm"; | ||
|
||
// Initialize the WASM module | ||
initSync(wasmBuffer); | ||
|
||
// BigInt | ||
// bigints | ||
|
||
const totalSupply = fixed(22950342684077248430458n); | ||
const sharePrice = fixed(1094205545459194143n); | ||
const totalSupplyInBase = totalSupply.mulDown(sharePrice); | ||
const totalSupply = 22950342684077248430458n; | ||
const sharePrice = 1094205545459194143n; | ||
const totalSupplyInBase = fixed(totalSupply).mulDown(sharePrice); | ||
|
||
console.log("Total supply in base:", totalSupplyInBase.toString()); | ||
// => 25112.392235106171381320 | ||
console.log(`Total supply in base: ${totalSupplyInBase.bigint}`); | ||
// => 25112392235106171381320 | ||
|
||
// String | ||
// strings and numbers | ||
|
||
const amount = parseFixed("1_000.123456789012345678e18"); | ||
const fee = parseFixed("0.025e18"); | ||
const amount = fixed("1_000.123456789012345678e18"); | ||
const fee = fixed(0.025e18); | ||
const feeAmount = amount.mulUp(fee); | ||
|
||
console.log("Fee amount:", feeAmount.toString()); | ||
console.log(`Fee amount: ${feeAmount}`); | ||
// => 25.003086419725308642 |
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
Oops, something went wrong.