reverse-mirage
Advanced tools
Comparing version 0.1.6 to 0.1.7
@@ -78,2 +78,3 @@ import { Abi, Hash, SimulateContractReturnType, PublicClient, Address as Address$1, WalletClient, Account } from 'viem'; | ||
}>(a: Amount<TToken>, b: BigIntIsh | Amount<TToken>) => boolean; | ||
declare const amountToNumber: (amount: Amount) => number; | ||
@@ -128,2 +129,3 @@ /** | ||
declare const fractionEqualTo: (a: Fraction, b: Fraction | BigIntIsh) => boolean; | ||
declare const fractionToNumber: (fraction: Fraction) => number; | ||
@@ -195,12 +197,5 @@ declare const isPrice: <TQuoteCurrency extends Token & { | ||
}>(price: Price<TQuoteCurrency, TBaseCurrency>, amount: Amount<TBaseCurrency>) => Amount<TQuoteCurrency>; | ||
declare const rawPrice: <TQuoteCurrency extends Token & { | ||
decimals?: number; | ||
}, TBaseCurrency extends Token & { | ||
decimals?: number; | ||
}>(price: Price<TQuoteCurrency, TBaseCurrency>) => Fraction; | ||
declare const adjustedPrice: <TQuoteCurrency extends Token & { | ||
decimals?: number; | ||
}, TBaseCurrency extends Token & { | ||
decimals?: number; | ||
}>(price: Price<TQuoteCurrency, TBaseCurrency>) => Fraction; | ||
declare const rawPrice: (price: Price<Amount["token"], Amount["token"]>) => Fraction; | ||
declare const adjustedPrice: (price: Price<Amount["token"], Amount["token"]>) => Fraction; | ||
declare const priceToNumber: (price: Price<Amount["token"], Amount["token"]>) => number; | ||
@@ -534,2 +529,2 @@ declare const readAndParse: <TRet, TParse>(reverseMirageRead: ReverseMirageRead<TRet, TParse>) => Promise<TParse>; | ||
export { Amount, BigIntIsh, ERC20, ERC20Amount, Fraction, MaxUint128, MaxUint16, MaxUint256, MaxUint32, MaxUint64, MaxUint8, NativeCurrency, NativeCurrencyAmount, Price, ReverseMirageRead, ReverseMirageWrite, Token, TokenData, adjustedPrice, amountAdd, amountDivide, amountEqualTo, amountGreaterThan, amountLessThan, amountMultiply, amountSubtract, createAmountFromFraction, createAmountFromRaw, createAmountFromString, createErc20, createFraction, createNativeCurrency, createPrice, createPriceFromAmounts, createPriceFromFraction, erc20ABI, erc20Allowance, erc20Approve, erc20BalanceOf, erc20Decimals, erc20Name, erc20Symbol, erc20TotalSupply, erc20Transfer, erc20TransferFrom, fractionAdd, fractionDivide, fractionEqualTo, fractionGreaterThan, fractionInvert, fractionLessThan, fractionMultiply, fractionQuotient, fractionRemainder, fractionSubtract, getErc20, getErc20Permit, isAmount, isFraction, isPrice, nativeBalance, priceAdd, priceDivide, priceEqualTo, priceGreaterThan, priceInvert, priceLessThan, priceMultiply, priceQuote, priceSubtract, rawPrice, readAndParse }; | ||
export { Amount, BigIntIsh, ERC20, ERC20Amount, Fraction, MaxUint128, MaxUint16, MaxUint256, MaxUint32, MaxUint64, MaxUint8, NativeCurrency, NativeCurrencyAmount, Price, ReverseMirageRead, ReverseMirageWrite, Token, TokenData, adjustedPrice, amountAdd, amountDivide, amountEqualTo, amountGreaterThan, amountLessThan, amountMultiply, amountSubtract, amountToNumber, createAmountFromFraction, createAmountFromRaw, createAmountFromString, createErc20, createFraction, createNativeCurrency, createPrice, createPriceFromAmounts, createPriceFromFraction, erc20ABI, erc20Allowance, erc20Approve, erc20BalanceOf, erc20Decimals, erc20Name, erc20Symbol, erc20TotalSupply, erc20Transfer, erc20TransferFrom, fractionAdd, fractionDivide, fractionEqualTo, fractionGreaterThan, fractionInvert, fractionLessThan, fractionMultiply, fractionQuotient, fractionRemainder, fractionSubtract, fractionToNumber, getErc20, getErc20Permit, isAmount, isFraction, isPrice, nativeBalance, priceAdd, priceDivide, priceEqualTo, priceGreaterThan, priceInvert, priceLessThan, priceMultiply, priceQuote, priceSubtract, priceToNumber, rawPrice, readAndParse }; |
@@ -72,2 +72,3 @@ // src/constants.ts | ||
}; | ||
var amountToNumber = (amount) => Number(amount.amount) / 10 ** (amount.token.decimals ?? 0); | ||
@@ -131,2 +132,3 @@ // src/fractionUtils.ts | ||
var fractionEqualTo = (a, b) => isFraction(b) ? a.numerator * b.denominator === a.denominator * b.numerator : a.numerator === a.denominator * BigInt(b); | ||
var fractionToNumber = (fraction) => Number(fraction.numerator) / Number(fraction.denominator); | ||
@@ -265,2 +267,3 @@ // src/priceUtils.ts | ||
}); | ||
var priceToNumber = (price) => fractionToNumber(adjustedPrice(price)); | ||
@@ -599,2 +602,3 @@ // src/readUtils.ts | ||
amountSubtract, | ||
amountToNumber, | ||
createAmountFromFraction, | ||
@@ -629,2 +633,3 @@ createAmountFromRaw, | ||
fractionSubtract, | ||
fractionToNumber, | ||
getErc20, | ||
@@ -645,2 +650,3 @@ getErc20Permit, | ||
priceSubtract, | ||
priceToNumber, | ||
rawPrice, | ||
@@ -647,0 +653,0 @@ readAndParse |
{ | ||
"name": "reverse-mirage", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "Application level typescript utilities for Ethereum", | ||
@@ -58,6 +58,6 @@ "type": "module", | ||
"rome": "^12.1.3", | ||
"tsup": "^7.1.0", | ||
"tsup": "^7.2.0", | ||
"typescript": "^5.1.6", | ||
"viem": "^1.4.1", | ||
"vitest": "^0.33.0" | ||
"viem": "^1.5.2", | ||
"vitest": "^0.34.1" | ||
}, | ||
@@ -64,0 +64,0 @@ "packageManager": "pnpm@8.6.10", |
@@ -138,4 +138,3 @@ import type { BigIntIsh, Fraction, Token, TokenData } from "./types.js"; | ||
// toSignificant | ||
// toFixed | ||
export const amountToNumber = (amount: Amount): number => | ||
Number(amount.amount) / 10 ** (amount.token.decimals ?? 0); |
@@ -153,4 +153,3 @@ import type { BigIntIsh, Fraction } from "./types.js"; | ||
// toSignificant | ||
// toFixed | ||
export const fractionToNumber = (fraction: Fraction): number => | ||
Number(fraction.numerator) / Number(fraction.denominator); |
@@ -1,4 +0,185 @@ | ||
// Generated by @wagmi/cli@1.3.0 on 7/30/2023 at 11:53:24 AM | ||
// Generated by @wagmi/cli@1.3.0 on 8/1/2023 at 10:40:22 AM | ||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
// MockERC20 | ||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
export const mockErc20ABI = [ | ||
{ | ||
stateMutability: 'nonpayable', | ||
type: 'constructor', | ||
inputs: [ | ||
{ name: '_name', internalType: 'string', type: 'string' }, | ||
{ name: '_symbol', internalType: 'string', type: 'string' }, | ||
{ name: '_decimals', internalType: 'uint8', type: 'uint8' }, | ||
], | ||
}, | ||
{ | ||
type: 'event', | ||
anonymous: false, | ||
inputs: [ | ||
{ | ||
name: 'owner', | ||
internalType: 'address', | ||
type: 'address', | ||
indexed: true, | ||
}, | ||
{ | ||
name: 'spender', | ||
internalType: 'address', | ||
type: 'address', | ||
indexed: true, | ||
}, | ||
{ | ||
name: 'amount', | ||
internalType: 'uint256', | ||
type: 'uint256', | ||
indexed: false, | ||
}, | ||
], | ||
name: 'Approval', | ||
}, | ||
{ | ||
type: 'event', | ||
anonymous: false, | ||
inputs: [ | ||
{ name: 'from', internalType: 'address', type: 'address', indexed: true }, | ||
{ name: 'to', internalType: 'address', type: 'address', indexed: true }, | ||
{ | ||
name: 'amount', | ||
internalType: 'uint256', | ||
type: 'uint256', | ||
indexed: false, | ||
}, | ||
], | ||
name: 'Transfer', | ||
}, | ||
{ | ||
stateMutability: 'view', | ||
type: 'function', | ||
inputs: [], | ||
name: 'DOMAIN_SEPARATOR', | ||
outputs: [{ name: '', internalType: 'bytes32', type: 'bytes32' }], | ||
}, | ||
{ | ||
stateMutability: 'view', | ||
type: 'function', | ||
inputs: [ | ||
{ name: '', internalType: 'address', type: 'address' }, | ||
{ name: '', internalType: 'address', type: 'address' }, | ||
], | ||
name: 'allowance', | ||
outputs: [{ name: '', internalType: 'uint256', type: 'uint256' }], | ||
}, | ||
{ | ||
stateMutability: 'nonpayable', | ||
type: 'function', | ||
inputs: [ | ||
{ name: 'spender', internalType: 'address', type: 'address' }, | ||
{ name: 'amount', internalType: 'uint256', type: 'uint256' }, | ||
], | ||
name: 'approve', | ||
outputs: [{ name: '', internalType: 'bool', type: 'bool' }], | ||
}, | ||
{ | ||
stateMutability: 'view', | ||
type: 'function', | ||
inputs: [{ name: '', internalType: 'address', type: 'address' }], | ||
name: 'balanceOf', | ||
outputs: [{ name: '', internalType: 'uint256', type: 'uint256' }], | ||
}, | ||
{ | ||
stateMutability: 'nonpayable', | ||
type: 'function', | ||
inputs: [ | ||
{ name: 'from', internalType: 'address', type: 'address' }, | ||
{ name: 'value', internalType: 'uint256', type: 'uint256' }, | ||
], | ||
name: 'burn', | ||
outputs: [], | ||
}, | ||
{ | ||
stateMutability: 'view', | ||
type: 'function', | ||
inputs: [], | ||
name: 'decimals', | ||
outputs: [{ name: '', internalType: 'uint8', type: 'uint8' }], | ||
}, | ||
{ | ||
stateMutability: 'nonpayable', | ||
type: 'function', | ||
inputs: [ | ||
{ name: 'to', internalType: 'address', type: 'address' }, | ||
{ name: 'value', internalType: 'uint256', type: 'uint256' }, | ||
], | ||
name: 'mint', | ||
outputs: [], | ||
}, | ||
{ | ||
stateMutability: 'view', | ||
type: 'function', | ||
inputs: [], | ||
name: 'name', | ||
outputs: [{ name: '', internalType: 'string', type: 'string' }], | ||
}, | ||
{ | ||
stateMutability: 'view', | ||
type: 'function', | ||
inputs: [{ name: '', internalType: 'address', type: 'address' }], | ||
name: 'nonces', | ||
outputs: [{ name: '', internalType: 'uint256', type: 'uint256' }], | ||
}, | ||
{ | ||
stateMutability: 'nonpayable', | ||
type: 'function', | ||
inputs: [ | ||
{ name: 'owner', internalType: 'address', type: 'address' }, | ||
{ name: 'spender', internalType: 'address', type: 'address' }, | ||
{ name: 'value', internalType: 'uint256', type: 'uint256' }, | ||
{ name: 'deadline', internalType: 'uint256', type: 'uint256' }, | ||
{ name: 'v', internalType: 'uint8', type: 'uint8' }, | ||
{ name: 'r', internalType: 'bytes32', type: 'bytes32' }, | ||
{ name: 's', internalType: 'bytes32', type: 'bytes32' }, | ||
], | ||
name: 'permit', | ||
outputs: [], | ||
}, | ||
{ | ||
stateMutability: 'view', | ||
type: 'function', | ||
inputs: [], | ||
name: 'symbol', | ||
outputs: [{ name: '', internalType: 'string', type: 'string' }], | ||
}, | ||
{ | ||
stateMutability: 'view', | ||
type: 'function', | ||
inputs: [], | ||
name: 'totalSupply', | ||
outputs: [{ name: '', internalType: 'uint256', type: 'uint256' }], | ||
}, | ||
{ | ||
stateMutability: 'nonpayable', | ||
type: 'function', | ||
inputs: [ | ||
{ name: 'to', internalType: 'address', type: 'address' }, | ||
{ name: 'amount', internalType: 'uint256', type: 'uint256' }, | ||
], | ||
name: 'transfer', | ||
outputs: [{ name: '', internalType: 'bool', type: 'bool' }], | ||
}, | ||
{ | ||
stateMutability: 'nonpayable', | ||
type: 'function', | ||
inputs: [ | ||
{ name: 'from', internalType: 'address', type: 'address' }, | ||
{ name: 'to', internalType: 'address', type: 'address' }, | ||
{ name: 'amount', internalType: 'uint256', type: 'uint256' }, | ||
], | ||
name: 'transferFrom', | ||
outputs: [{ name: '', internalType: 'bool', type: 'bool' }], | ||
}, | ||
] as const | ||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
// ERC20 | ||
@@ -5,0 +186,0 @@ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
@@ -23,2 +23,3 @@ export { | ||
amountGreaterThan, | ||
amountToNumber, | ||
} from "./amountUtils.js"; | ||
@@ -39,2 +40,3 @@ | ||
fractionGreaterThan, | ||
fractionToNumber, | ||
} from "./fractionUtils.js"; | ||
@@ -58,2 +60,3 @@ | ||
adjustedPrice, | ||
priceToNumber, | ||
} from "./priceUtils.js"; | ||
@@ -60,0 +63,0 @@ |
@@ -11,2 +11,3 @@ import { type Amount, createAmountFromRaw, scaleUp } from "./amountUtils.js"; | ||
fractionSubtract, | ||
fractionToNumber, | ||
} from "./fractionUtils.js"; | ||
@@ -252,7 +253,4 @@ import type { BigIntIsh, Fraction, Price } from "./types.js"; | ||
export const rawPrice = < | ||
TQuoteCurrency extends Amount["token"], | ||
TBaseCurrency extends Amount["token"], | ||
>( | ||
price: Price<TQuoteCurrency, TBaseCurrency>, | ||
export const rawPrice = ( | ||
price: Price<Amount["token"], Amount["token"]>, | ||
): Fraction => ({ | ||
@@ -264,7 +262,4 @@ type: "fraction", | ||
export const adjustedPrice = < | ||
TQuoteCurrency extends Amount["token"], | ||
TBaseCurrency extends Amount["token"], | ||
>( | ||
price: Price<TQuoteCurrency, TBaseCurrency>, | ||
export const adjustedPrice = ( | ||
price: Price<Amount["token"], Amount["token"]>, | ||
): Fraction => ({ | ||
@@ -280,4 +275,4 @@ type: "fraction", | ||
// to fixed | ||
// to significant | ||
export const priceToNumber = ( | ||
price: Price<Amount["token"], Amount["token"]>, | ||
): number => fractionToNumber(adjustedPrice(price)); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
258262
4046