Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Commit

Permalink
[hyperdrive-wasm] Return ether, update to 0.5.0 (#56)
Browse files Browse the repository at this point in the history
- Reorganized the hyperdrive-wasm package and simplified type conversion
from JS values to a `State` instance.
- Modified return values to return ether strings (no decimals) rather
than Wei floating point string.
- Updated to hyperderive 0.5.0
  • Loading branch information
ryangoree authored Jan 17, 2024
1 parent 44d57a3 commit 43c24b1
Show file tree
Hide file tree
Showing 15 changed files with 3,039 additions and 356 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build_wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ jobs:
uses: actions/checkout@master
with:
repository: delvtech/hyperdrive
ref: 'v0.4.0'
ref: 'v0.5.0'
path: './hyperdrive'
ssh-key: ${{ secrets.HYPERDRIVE_ACCESS_KEY }}

- name: build hyperdrive-wasm
working-directory: crates/hyperdrive-wasm
run: sh build.sh
run: sh scripts/build.sh

- name: publish hyperdrive-wasm
if: github.event_name == 'release'
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/hyperdrive-wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hyperdrive-wasm"
version = "0.4.0"
version = "0.5.0"
edition = "2021"

[lib]
Expand Down
6 changes: 0 additions & 6 deletions crates/hyperdrive-wasm/build_and_install.sh

This file was deleted.

39 changes: 27 additions & 12 deletions crates/hyperdrive-wasm/example/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import * as hyperdriveWasm from '@delvtech/hyperdrive-wasm';

const ZERO_ADDRESS = '0x'.padEnd(42, '0');
// const MAX_U256 = '0x'.padEnd(66, 'F');
const MAX_U256 = '0x'.padEnd(66, 'F');
const MAX_BUDGET = BigInt(MAX_U256).toString();

// const MAX_BUDGET = BigInt(MAX_U256).toString();
const mockPoolInfo = {
const examplePoolInfo = {
shareReserves: '10000000000000000000000000',
shareAdjustment: '0',
zombieBaseProceeds: '0',
zombieShareReserves: '0',
bondReserves: '10217899519533796120000000',
lpTotalSupply: '9999990000000000000000000',
Expand All @@ -20,7 +21,7 @@ const mockPoolInfo = {
lpSharePrice: '1000000000000000000',
longExposure: '0',
};
const mockPoolConfig = {
const examplePoolConfig = {
baseToken: ZERO_ADDRESS,
governance: ZERO_ADDRESS,
feeCollector: ZERO_ADDRESS,
Expand All @@ -43,18 +44,32 @@ const mockPoolConfig = {
async function main() {
hyperdriveWasm.initSync(hyperdriveWasm.wasmBuffer);

const spotRate = hyperdriveWasm.getSpotRate(mockPoolInfo, mockPoolConfig);
const spotRate = hyperdriveWasm.getSpotRate(
examplePoolInfo,
examplePoolConfig
);
console.log('spotRate:', spotRate);

const spotPrice = hyperdriveWasm.getSpotPrice(mockPoolInfo, mockPoolConfig);
console.log('spotPrice:', spotPrice);
const maxLong = hyperdriveWasm.getMaxLong(
examplePoolInfo,
examplePoolConfig,
MAX_BUDGET,
'90844806244066488'
);
console.log('maxLong:', maxLong);

const baseAmountRequired = hyperdriveWasm.calcOpenShort(
mockPoolInfo,
mockPoolConfig,
(10e18).toString()
const baseForMaxLong = hyperdriveWasm.calcOpenLong(
examplePoolInfo,
examplePoolConfig,
maxLong
);
console.log('baseAmountRequired:', baseAmountRequired);
console.log('baseForMaxLong:', baseForMaxLong);

const spotPrice = hyperdriveWasm.getSpotPrice(
examplePoolInfo,
examplePoolConfig
);
console.log('spotPrice:', spotPrice);
}

main();
8 changes: 4 additions & 4 deletions crates/hyperdrive-wasm/example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/hyperdrive-wasm/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"webpack-dev-server": "^4.15.1"
},
"dependencies": {
"@delvtech/hyperdrive-wasm": "file:delvtech-hyperdrive-wasm-0.4.0.tgz"
"@delvtech/hyperdrive-wasm": "file:delvtech-hyperdrive-wasm-0.5.0.tgz"
}
}
Loading

0 comments on commit 43c24b1

Please sign in to comment.