Skip to content

Commit

Permalink
fix(blue-sdk): make domain name possibly undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax committed Oct 21, 2024
1 parent 0107f6e commit e0cc8ee
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/blue-sdk-viem/src/signatures/permit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import type { TypedDataDefinition } from "viem";

export interface PermitArgs {
name: string;
name?: string;
address: Address;
owner: Address;
spender: Address;
Expand Down Expand Up @@ -36,7 +36,7 @@ export const getPermitTypedData = (
const { usdc } = getChainAddresses(chainId);

const domain = {
name: name,
name,
version: address === usdc ? "2" : "1",
chainId,
verifyingContract: address,
Expand Down
7 changes: 4 additions & 3 deletions packages/blue-sdk/src/token/Token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@ export class Token implements InputToken {
*/
public price?: bigint;

constructor({ address, decimals = 0, symbol, name, price }: InputToken) {
constructor({ address, name, symbol, decimals = 0, price }: InputToken) {
this.address = address;
this.name = name;
this.symbol = symbol;
this.decimals = Number(decimals);

if (price != null) this.price = BigInt(price);
}

/**
* Quotes an amount in USD (scaled by WAD) in this token.
* Returns undefined iff the token's price is undefined.
* Returns `undefined` iff the token's price is undefined.
* @param amount The amount of USD to quote.
*/
fromUsd(amount: bigint, rounding: RoundingDirection = "Down") {
Expand All @@ -69,7 +70,7 @@ export class Token implements InputToken {

/**
* Quotes an amount of tokens in USD (scaled by WAD).
* Returns undefined iff the token's price is undefined.
* Returns `undefined` iff the token's price is undefined.
* @param amount The amount of tokens to quote.
*/
toUsd(amount: bigint, rounding: RoundingDirection = "Down") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ export const check = async <
return console.warn(`Unknown oracle price for market "${market.id}"`);

try {
const collateralToken = converter.getTokenWithPrice(
const collateralToken = converter.getToken(
position.market.collateralAsset,
wethPriceUsd,
);
if (collateralToken.price == null)
throw new UnknownTokenPriceError(collateralToken.address);

const loanToken = converter.getTokenWithPrice(
const loanToken = converter.getToken(
position.market.loanAsset,
wethPriceUsd,
);
Expand Down

0 comments on commit e0cc8ee

Please sign in to comment.