Skip to content

Commit 1958d8a

Browse files
authored
Misc polish (#1838)
* Remove unused variable * Remove more unused variables * Cleanup artifacts package * Patch parenthesis parsing in `TsType`
1 parent 39be4d9 commit 1958d8a

File tree

1,922 files changed

+301014
-535321
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,922 files changed

+301014
-535321
lines changed

.changeset/fifty-mugs-reply.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@delvtech/hyperdrive-artifacts": patch
3+
---
4+
5+
Added a `name` field for the contract's name.

apps/hyperdrive-trading/src/ui/hyperdrive/longs/OpenLongForm/OpenLongForm.tsx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export function OpenLongForm({
146146
amount: depositAmountAsBigInt,
147147
});
148148

149-
const { maxBaseIn, maxSharesIn, maxBondsOut } = useMaxLong({
149+
const { maxBaseIn, maxSharesIn } = useMaxLong({
150150
hyperdriveAddress: hyperdrive.address,
151151
chainId: hyperdrive.chainId,
152152
});
@@ -227,25 +227,6 @@ export function OpenLongForm({
227227
minSharePrice: poolInfo?.vaultSharePrice || 0n,
228228
});
229229

230-
const { fiatPrice: baseTokenPrice } = useTokenFiatPrice({
231-
chainId: hyperdrive.chainId,
232-
tokenAddress: baseToken.address,
233-
});
234-
let zapTokenAmountInBase = 0n;
235-
if (
236-
isZapping &&
237-
activeTokenPrice &&
238-
baseTokenPrice &&
239-
depositAmountAsBigInt
240-
) {
241-
const fiatValueOfDepositAmount = fixed(
242-
depositAmountAsBigInt,
243-
activeToken.decimals,
244-
).mul(activeTokenPrice);
245-
const equivalentAmountOfBase = fiatValueOfDepositAmount.div(baseTokenPrice);
246-
zapTokenAmountInBase = equivalentAmountOfBase.bigint;
247-
}
248-
249230
// Plausible event props
250231
const formName = "Open Long";
251232
const chainId = hyperdrive.chainId;

crates/ts-type/src/lib.rs

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,9 @@ impl TsType {
239239
}
240240
// a & b join c | d -> (a & b & c) | d
241241
Self::Union(mut union_types) => {
242-
let first_member = union_types.remove(0);
243-
let intersection = Self::Intersection(types);
244-
let intersected_member = intersection.and(first_member);
245-
union_types.insert(0, intersected_member);
242+
let first_union_member = union_types.remove(0);
243+
let intersection = Self::Intersection(types).and(first_union_member);
244+
union_types.insert(0, intersection);
246245
Ok(Self::Union(union_types))
247246
}
248247
// a & b join _ -> a & b & _
@@ -258,7 +257,10 @@ impl TsType {
258257
Ok(Self::Tuple(types))
259258
}
260259
// (a | b) join c -> (a | b | c)
261-
Self::Paren(inner) => inner.join(other),
260+
Self::Paren(inner) => {
261+
let joined = inner.join(other)?;
262+
Ok(Self::Paren(Box::new(joined)))
263+
}
262264
_ => Err("Type does not support joining."),
263265
}
264266
}
@@ -304,22 +306,22 @@ impl TsType {
304306
'|' => {
305307
// push pending as union or an empty union since types can
306308
// start with `|`
307-
let member = match pending_type {
309+
let members = match pending_type {
308310
Some(ty) => vec![ty],
309311
None => vec![],
310312
};
311-
let mut _union = Self::Union(member);
313+
let mut _union = Self::Union(members);
312314
pending_stack.push(_union);
313315
pending_type = None;
314316
}
315317
'&' => {
316318
// push pending as union or an empty union since types can
317319
// start with `&`
318-
let member = match pending_type {
320+
let members = match pending_type {
319321
Some(ty) => vec![ty],
320322
None => vec![],
321323
};
322-
let intersection = Self::Intersection(member);
324+
let intersection = Self::Intersection(members);
323325
pending_stack.push(intersection);
324326
pending_type = None;
325327
}
@@ -328,8 +330,8 @@ impl TsType {
328330
if pending_type.is_none() {
329331
return Err(type_error_at!(location, "Unexpected `<` found."));
330332
}
331-
let inner = pending_type.unwrap();
332-
let generic = inner.as_generic(vec![]);
333+
let pending = pending_type.unwrap();
334+
let generic = pending.as_generic(vec![]);
333335
pending_stack.push(generic);
334336
pending_type = None;
335337
}
@@ -339,13 +341,13 @@ impl TsType {
339341
if pending_type.is_none() {
340342
return Err(type_error_at!(location, "Unexpected `,` found."));
341343
}
342-
let mut inner = pending_type.unwrap();
344+
let mut pending = pending_type.unwrap();
343345

344346
loop {
345347
let top = pending_stack.pop().unwrap();
346-
inner = top.join(inner).unwrap();
348+
pending = top.join(pending).unwrap();
347349

348-
match inner {
350+
match pending {
349351
Self::Generic(_, _) => break,
350352
Self::IndexedAccess(_, _) => break,
351353
Self::Tuple(_) => break,
@@ -356,7 +358,7 @@ impl TsType {
356358
return Err(type_error_at!(location, "Unexpected `,` found."));
357359
}
358360
}
359-
pending_stack.push(inner);
361+
pending_stack.push(pending);
360362
pending_type = None;
361363
}
362364
'>' => {
@@ -365,20 +367,21 @@ impl TsType {
365367
if pending_type.is_none() {
366368
return Err(type_error_at!(location, "Unexpected `>` found."));
367369
};
368-
let mut ty = pending_type.unwrap();
370+
let mut pending = pending_type.unwrap();
371+
369372
loop {
370373
let top = pending_stack.pop().unwrap();
371-
ty = top.join(ty).unwrap();
374+
pending = top.join(pending).unwrap();
372375

373-
if let Self::Generic(_, _) = ty {
376+
if let Self::Generic(_, _) = pending {
374377
break;
375378
}
376379

377380
if pending_stack.is_empty() {
378-
return Err(type_error_at!(location, "Unexpected `,` found."));
381+
return Err(type_error_at!(location, "Unexpected `>` found."));
379382
}
380383
}
381-
pending_type = Some(ty);
384+
pending_type = Some(pending);
382385
}
383386
'[' => {
384387
if pending_type.is_none() {
@@ -395,19 +398,19 @@ impl TsType {
395398
if pending_type.is_none() {
396399
return Err(type_error_at!(location, "Unexpected `]` found."));
397400
};
398-
let mut ty = pending_type.unwrap();
401+
let mut pending = pending_type.unwrap();
399402

400403
// If there's an ambiguous bracket, it's an array, otherwise
401404
// it's the end of a bracketed type on the stack.
402405
if ambiguous_bracket {
403-
pending_type = Some(ty.in_array());
406+
pending_type = Some(pending.in_array());
404407
ambiguous_bracket = false;
405408
} else {
406409
loop {
407410
let top = pending_stack.pop().unwrap();
408-
ty = top.join(ty).unwrap();
411+
pending = top.join(pending).unwrap();
409412

410-
match ty {
413+
match pending {
411414
Self::IndexedAccess(_, _) => break,
412415
Self::Tuple(_) => break,
413416
_ => {}
@@ -417,7 +420,7 @@ impl TsType {
417420
return Err(type_error_at!(location, "Unexpected `]` found."));
418421
}
419422
}
420-
pending_type = Some(ty);
423+
pending_type = Some(pending);
421424
}
422425
}
423426
'(' => {
@@ -778,6 +781,13 @@ fn match_simple_type(rust_type: &str) -> Option<TsType> {
778781
mod tests {
779782
use super::*;
780783

784+
#[test]
785+
fn test_join_parens() {
786+
let parens = ts_type!((string | number));
787+
let joined = parens.join(ts_type!(boolean)).unwrap();
788+
assert_eq!(joined, ts_type!((string | number | boolean)));
789+
}
790+
781791
#[test]
782792
fn test_formatting() {
783793
let base = ts_type!(string);

packages/fixed-point-wasm/fixed_point_wasm.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ class FixedPoint {
641641
mulDown(other, decimals) {
642642
try {
643643
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
644-
wasm.fixedpoint_mul(retptr, this.__wbg_ptr, addHeapObject(other), isLikeNone(decimals) ? 0xFFFFFF : decimals);
644+
wasm.fixedpoint_mulDown(retptr, this.__wbg_ptr, addHeapObject(other), isLikeNone(decimals) ? 0xFFFFFF : decimals);
645645
var r0 = getInt32Memory0()[retptr / 4 + 0];
646646
var r1 = getInt32Memory0()[retptr / 4 + 1];
647647
var r2 = getInt32Memory0()[retptr / 4 + 2];
@@ -695,7 +695,7 @@ class FixedPoint {
695695
divDown(other, decimals) {
696696
try {
697697
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
698-
wasm.fixedpoint_div(retptr, this.__wbg_ptr, addHeapObject(other), isLikeNone(decimals) ? 0xFFFFFF : decimals);
698+
wasm.fixedpoint_divDown(retptr, this.__wbg_ptr, addHeapObject(other), isLikeNone(decimals) ? 0xFFFFFF : decimals);
699699
var r0 = getInt32Memory0()[retptr / 4 + 0];
700700
var r1 = getInt32Memory0()[retptr / 4 + 1];
701701
var r2 = getInt32Memory0()[retptr / 4 + 2];

packages/fixed-point-wasm/fixed_point_wasm.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
3.21 KB
Binary file not shown.
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1+
dist
12
node_modules
23

3-
# Ignore temporary clones of the hyperdrive repo used by the build script
4-
hyperdrive-temp.*
5-
6-
# Ignore the src directory which is generated by the build script
7-
src
8-
9-
# Don't ignore the dist directory which requires forge to build
10-
!dist
4+
# Ignore temporary clones created by the build script
5+
*_temp
Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# @delvtech/hyperdrive-artifacts
22

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

66
## Install
77

@@ -22,25 +22,18 @@ const hyperdriveAbi = IHyperdrive.abi;
2222
const hyperdriveBytecode = IHyperdrive.bytecode;
2323
```
2424

25-
## Building
25+
## Generating TypeScript Files
2626

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

3131
```json
32-
"build:src": "sh scripts/build_src.sh v0.9.0"
32+
"generate": "sh scripts/generate.sh v1.0.20"
3333
```
3434

3535
Then run:
3636

3737
```sh
38-
yarn workspace @delvtech/hyperdrive-artifacts build:src
39-
```
40-
41-
If the `src` directory already exists from a previous build, you can force a new
42-
build by running:
43-
44-
```sh
45-
yarn workspace @delvtech/hyperdrive-artifacts build:new
38+
yarn workspace @delvtech/hyperdrive-artifacts generate
4639
```

packages/hyperdrive-artifacts/dist/83e70ca879a76f0c763a400659cff4f0.d.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

packages/hyperdrive-artifacts/dist/83e70ca879a76f0c763a400659cff4f0.d.ts.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)