Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions .changeset/fifty-mugs-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@delvtech/hyperdrive-artifacts": patch
---

Added a `name` field for the contract's name.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export function OpenLongForm({
amount: depositAmountAsBigInt,
});

const { maxBaseIn, maxSharesIn, maxBondsOut } = useMaxLong({
const { maxBaseIn, maxSharesIn } = useMaxLong({
hyperdriveAddress: hyperdrive.address,
chainId: hyperdrive.chainId,
});
Expand Down Expand Up @@ -227,25 +227,6 @@ export function OpenLongForm({
minSharePrice: poolInfo?.vaultSharePrice || 0n,
});

const { fiatPrice: baseTokenPrice } = useTokenFiatPrice({
chainId: hyperdrive.chainId,
tokenAddress: baseToken.address,
});
let zapTokenAmountInBase = 0n;
if (
isZapping &&
activeTokenPrice &&
baseTokenPrice &&
depositAmountAsBigInt
) {
const fiatValueOfDepositAmount = fixed(
depositAmountAsBigInt,
activeToken.decimals,
).mul(activeTokenPrice);
const equivalentAmountOfBase = fiatValueOfDepositAmount.div(baseTokenPrice);
zapTokenAmountInBase = equivalentAmountOfBase.bigint;
}

// Plausible event props
const formName = "Open Long";
const chainId = hyperdrive.chainId;
Expand Down
60 changes: 35 additions & 25 deletions crates/ts-type/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,9 @@ impl TsType {
}
// a & b join c | d -> (a & b & c) | d
Self::Union(mut union_types) => {
let first_member = union_types.remove(0);
let intersection = Self::Intersection(types);
let intersected_member = intersection.and(first_member);
union_types.insert(0, intersected_member);
let first_union_member = union_types.remove(0);
let intersection = Self::Intersection(types).and(first_union_member);
union_types.insert(0, intersection);
Ok(Self::Union(union_types))
}
// a & b join _ -> a & b & _
Expand All @@ -258,7 +257,10 @@ impl TsType {
Ok(Self::Tuple(types))
}
// (a | b) join c -> (a | b | c)
Self::Paren(inner) => inner.join(other),
Self::Paren(inner) => {
let joined = inner.join(other)?;
Ok(Self::Paren(Box::new(joined)))
}
_ => Err("Type does not support joining."),
}
}
Expand Down Expand Up @@ -304,22 +306,22 @@ impl TsType {
'|' => {
// push pending as union or an empty union since types can
// start with `|`
let member = match pending_type {
let members = match pending_type {
Some(ty) => vec![ty],
None => vec![],
};
let mut _union = Self::Union(member);
let mut _union = Self::Union(members);
pending_stack.push(_union);
pending_type = None;
}
'&' => {
// push pending as union or an empty union since types can
// start with `&`
let member = match pending_type {
let members = match pending_type {
Some(ty) => vec![ty],
None => vec![],
};
let intersection = Self::Intersection(member);
let intersection = Self::Intersection(members);
pending_stack.push(intersection);
pending_type = None;
}
Expand All @@ -328,8 +330,8 @@ impl TsType {
if pending_type.is_none() {
return Err(type_error_at!(location, "Unexpected `<` found."));
}
let inner = pending_type.unwrap();
let generic = inner.as_generic(vec![]);
let pending = pending_type.unwrap();
let generic = pending.as_generic(vec![]);
pending_stack.push(generic);
pending_type = None;
}
Expand All @@ -339,13 +341,13 @@ impl TsType {
if pending_type.is_none() {
return Err(type_error_at!(location, "Unexpected `,` found."));
}
let mut inner = pending_type.unwrap();
let mut pending = pending_type.unwrap();

loop {
let top = pending_stack.pop().unwrap();
inner = top.join(inner).unwrap();
pending = top.join(pending).unwrap();

match inner {
match pending {
Self::Generic(_, _) => break,
Self::IndexedAccess(_, _) => break,
Self::Tuple(_) => break,
Expand All @@ -356,7 +358,7 @@ impl TsType {
return Err(type_error_at!(location, "Unexpected `,` found."));
}
}
pending_stack.push(inner);
pending_stack.push(pending);
pending_type = None;
}
'>' => {
Expand All @@ -365,20 +367,21 @@ impl TsType {
if pending_type.is_none() {
return Err(type_error_at!(location, "Unexpected `>` found."));
};
let mut ty = pending_type.unwrap();
let mut pending = pending_type.unwrap();

loop {
let top = pending_stack.pop().unwrap();
ty = top.join(ty).unwrap();
pending = top.join(pending).unwrap();

if let Self::Generic(_, _) = ty {
if let Self::Generic(_, _) = pending {
break;
}

if pending_stack.is_empty() {
return Err(type_error_at!(location, "Unexpected `,` found."));
return Err(type_error_at!(location, "Unexpected `>` found."));
}
}
pending_type = Some(ty);
pending_type = Some(pending);
}
'[' => {
if pending_type.is_none() {
Expand All @@ -395,19 +398,19 @@ impl TsType {
if pending_type.is_none() {
return Err(type_error_at!(location, "Unexpected `]` found."));
};
let mut ty = pending_type.unwrap();
let mut pending = pending_type.unwrap();

// If there's an ambiguous bracket, it's an array, otherwise
// it's the end of a bracketed type on the stack.
if ambiguous_bracket {
pending_type = Some(ty.in_array());
pending_type = Some(pending.in_array());
ambiguous_bracket = false;
} else {
loop {
let top = pending_stack.pop().unwrap();
ty = top.join(ty).unwrap();
pending = top.join(pending).unwrap();

match ty {
match pending {
Self::IndexedAccess(_, _) => break,
Self::Tuple(_) => break,
_ => {}
Expand All @@ -417,7 +420,7 @@ impl TsType {
return Err(type_error_at!(location, "Unexpected `]` found."));
}
}
pending_type = Some(ty);
pending_type = Some(pending);
}
}
'(' => {
Expand Down Expand Up @@ -778,6 +781,13 @@ fn match_simple_type(rust_type: &str) -> Option<TsType> {
mod tests {
use super::*;

#[test]
fn test_join_parens() {
let parens = ts_type!((string | number));
let joined = parens.join(ts_type!(boolean)).unwrap();
assert_eq!(joined, ts_type!((string | number | boolean)));
}

#[test]
fn test_formatting() {
let base = ts_type!(string);
Expand Down
4 changes: 2 additions & 2 deletions packages/fixed-point-wasm/fixed_point_wasm.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ class FixedPoint {
mulDown(other, decimals) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.fixedpoint_mul(retptr, this.__wbg_ptr, addHeapObject(other), isLikeNone(decimals) ? 0xFFFFFF : decimals);
wasm.fixedpoint_mulDown(retptr, this.__wbg_ptr, addHeapObject(other), isLikeNone(decimals) ? 0xFFFFFF : decimals);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
Expand Down Expand Up @@ -695,7 +695,7 @@ class FixedPoint {
divDown(other, decimals) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.fixedpoint_div(retptr, this.__wbg_ptr, addHeapObject(other), isLikeNone(decimals) ? 0xFFFFFF : decimals);
wasm.fixedpoint_divDown(retptr, this.__wbg_ptr, addHeapObject(other), isLikeNone(decimals) ? 0xFFFFFF : decimals);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
Expand Down
6 changes: 3 additions & 3 deletions packages/fixed-point-wasm/fixed_point_wasm.js

Large diffs are not rendered by default.

Binary file modified packages/fixed-point-wasm/fixed_point_wasm_bg.wasm
Binary file not shown.
11 changes: 3 additions & 8 deletions packages/hyperdrive-artifacts/.gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
dist
node_modules

# Ignore temporary clones of the hyperdrive repo used by the build script
hyperdrive-temp.*

# Ignore the src directory which is generated by the build script
src

# Don't ignore the dist directory which requires forge to build
!dist
# Ignore temporary clones created by the build script
*_temp
19 changes: 6 additions & 13 deletions packages/hyperdrive-artifacts/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# @delvtech/hyperdrive-artifacts

Build artifacts, including ABIs and Bytecodes, for the [Hyperdrive
AMM](https://github.com/delvtech/hyperdrive) contracts.
Strongly typed build artifacts, including ABIs and Bytecodes, for the
[Hyperdrive AMM](https://github.com/delvtech/hyperdrive) contracts.

## Install

Expand All @@ -22,25 +22,18 @@ const hyperdriveAbi = IHyperdrive.abi;
const hyperdriveBytecode = IHyperdrive.bytecode;
```

## Building
## Generating TypeScript Files

The build script takes the git ref to clone and compile as the first positional
The generate script takes the git ref to clone and compile as the first positional
argument. This means you can change the version of the contract to generate
artifacts for in the `package.json`:

```json
"build:src": "sh scripts/build_src.sh v0.9.0"
"generate": "sh scripts/generate.sh v1.0.20"
```

Then run:

```sh
yarn workspace @delvtech/hyperdrive-artifacts build:src
```

If the `src` directory already exists from a previous build, you can force a new
build by running:

```sh
yarn workspace @delvtech/hyperdrive-artifacts build:new
yarn workspace @delvtech/hyperdrive-artifacts generate
```

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading