Socket
Socket
Sign inDemoInstall

reverse-mirage

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reverse-mirage - npm Package Compare versions

Comparing version 0.1.9 to 0.1.11

src/_test/constants.ts

1605

dist/index.d.ts

@@ -1,11 +0,4 @@

import { Abi, Hash, SimulateContractReturnType, PublicClient, Address as Address$1, WalletClient, Account } from 'viem';
import { PublicClient, Abi, Hash, SimulateContractReturnType, Address as Address$1, WalletClient, Account, Hex } from 'viem';
import { Address } from 'viem/accounts';
declare const MaxUint256: bigint;
declare const MaxUint128: bigint;
declare const MaxUint64: bigint;
declare const MaxUint32: bigint;
declare const MaxUint16: bigint;
declare const MaxUint8: bigint;
type BigIntIsh = bigint | string | number;

@@ -19,8 +12,6 @@ type Fraction = {

type: TType;
name: string;
symbol: string;
chainID: number;
};
type TokenData<TToken extends Token, TData extends object> = {
type: `${TToken["type"]}${string}`;
type TokenData<TToken extends Token = Token, TType extends `${TToken["type"]}${string}` = `${TToken["type"]}${string}`, TData extends object = object> = {
type: TType;
token: TToken;

@@ -34,3 +25,3 @@ } & TData;

type ReverseMirageRead<TRet = unknown, TParse = unknown> = {
read: () => TRet | Promise<TRet>;
read: (publicClient: PublicClient) => TRet | Promise<TRet>;
parse: (data: TRet) => TParse;

@@ -43,180 +34,173 @@ };

}>;
/**
* A tuple of length `N` with elements of type `T`.
* @see https://github.com/saber-hq/saber-common/blob/master/packages/tuple-utils/src/tuple.ts
*/
type Tuple<T, N extends number> = N extends N ? number extends N ? T[] : _TupleOf<T, N, []> : never;
type _TupleOf<T, N extends number, R extends T[]> = R["length"] extends N ? R : _TupleOf<T, N, [T, ...R]>;
type Amount<TToken extends Token = Token> = TokenData<TToken & {
type Amount<TToken extends Token & {
decimals?: number;
}, {
} = Token & {
decimals?: number;
}, TType extends `${TToken["type"]}${string}` = `${TToken["type"]}${string}`, TData extends {
amount: bigint;
}>;
declare const isAmount: <TAmount extends Amount<Token>>(x: BigIntIsh | TAmount) => x is TAmount;
declare const createAmountFromString: <TToken extends Token & {
decimals?: number;
}>(token: TToken, amount: string) => Amount<TToken>;
declare const createAmountFromFraction: <TToken extends Token & {
decimals?: number;
}>(token: TToken, amount: Fraction) => Amount<TToken>;
declare const createAmountFromRaw: <TToken extends Token & {
decimals?: number;
}>(token: TToken, amount: bigint) => Amount<TToken>;
declare const amountAdd: <TToken extends Token & {
decimals?: number;
}>(a: Amount<TToken>, b: BigIntIsh | Amount<TToken>) => Amount<TToken>;
declare const amountSubtract: <TToken extends Token & {
decimals?: number;
}>(a: Amount<TToken>, b: BigIntIsh | Amount<TToken>) => Amount<TToken>;
declare const amountMultiply: <TToken extends Token & {
decimals?: number;
}>(a: Amount<TToken>, b: BigIntIsh | Amount<TToken>) => Amount<TToken>;
declare const amountDivide: <TToken extends Token & {
decimals?: number;
}>(a: Amount<TToken>, b: BigIntIsh | Amount<TToken>) => Amount<TToken>;
declare const amountLessThan: <TToken extends Token & {
decimals?: number;
}>(a: Amount<TToken>, b: BigIntIsh | Amount<TToken>) => boolean;
declare const amountEqualTo: <TToken extends Token & {
decimals?: number;
}>(a: Amount<TToken>, b: BigIntIsh | Amount<TToken>) => boolean;
declare const amountGreaterThan: <TToken extends Token & {
decimals?: number;
}>(a: Amount<TToken>, b: BigIntIsh | Amount<TToken>) => boolean;
declare const amountToNumber: (amount: Amount) => number;
} = {
amount: bigint;
}> = TokenData<TToken, TType, TData>;
/**
* Determines if x is a fraction type
* Returns true if {@link x} is of type {@link Amount}
*/
declare const isFraction: (x: Fraction | BigIntIsh) => x is Fraction;
declare const isAmount: <TAmount extends Amount<Token & {
decimals?: number;
}, string, {
amount: bigint;
}>>(x: BigIntIsh | TAmount) => x is TAmount;
/**
* Create a fraction
* Creates a {@link Amount} from a {@link token} and a string
*/
declare const createFraction: (numerator: BigIntIsh, denominator?: BigIntIsh) => Fraction;
declare const createAmountFromString: <TToken extends Token & {
decimals?: number;
}>(token: TToken, amount: string) => Amount<TToken, `${TToken["type"]}Amount`, {
amount: bigint;
}>;
/**
* Calculate the quotient
* Creates a {@link Amount} from a {@link token} and a {@link Fraction}
*/
declare const fractionQuotient: (fraction: Fraction) => bigint;
declare const createAmountFromFraction: <TToken extends Token & {
decimals?: number;
}>(token: TToken, amount: Fraction) => Amount<TToken, `${TToken["type"]}Amount`, {
amount: bigint;
}>;
/**
* Calculate the remainder
* Creates a {@link Amount} from a {@link token} and a {@link amount}
*/
declare const fractionRemainder: (fraction: Fraction) => bigint;
declare const createAmountFromRaw: <TToken extends Token & {
decimals?: number;
}>(token: TToken, amount: bigint) => Amount<TToken, `${TToken["type"]}Amount`, {
amount: bigint;
}>;
/**
* Calculate the inverse
* Adds {@link a} with {@link b}
*/
declare const fractionInvert: (fraction: Fraction) => Fraction;
declare const amountAdd: <TAmount extends Amount<Token & {
decimals?: number;
}, string, {
amount: bigint;
}>>(a: TAmount, b: TAmount extends Amount<TAmount["token"], infer TType extends `${TAmount["token"]["type"]}${string}`, {
amount: bigint;
}> ? BigIntIsh | Amount<TAmount["token"], TType, {
amount: bigint;
}> : never) => Omit<TAmount, "amount"> & {
amount: bigint;
};
/**
* Add two fractions
* Subtracts {@link a} by {@link b}
*/
declare const fractionAdd: (a: Fraction, b: Fraction | BigIntIsh) => Fraction;
declare const amountSubtract: <TAmount extends Amount<Token & {
decimals?: number;
}, string, {
amount: bigint;
}>>(a: TAmount, b: TAmount extends Amount<TAmount["token"], infer TType extends `${TAmount["token"]["type"]}${string}`, {
amount: bigint;
}> ? BigIntIsh | Amount<TAmount["token"], TType, {
amount: bigint;
}> : never) => Omit<TAmount, "amount"> & {
amount: bigint;
};
/**
* Subtract the second fraction from the first
* Multiplies {@link a} with {@link b}
*/
declare const fractionSubtract: (a: Fraction, b: Fraction | BigIntIsh) => Fraction;
declare const amountMultiply: <TAmount extends Amount<Token & {
decimals?: number;
}, string, {
amount: bigint;
}>>(a: TAmount, b: TAmount extends Amount<TAmount["token"], infer TType extends `${TAmount["token"]["type"]}${string}`, {
amount: bigint;
}> ? BigIntIsh | Amount<TAmount["token"], TType, {
amount: bigint;
}> : never) => Omit<TAmount, "amount"> & {
amount: bigint;
};
/**
* Multiply two fractions
* Divides {@link a} by {@link b}
*/
declare const fractionMultiply: (a: Fraction, b: Fraction | BigIntIsh) => Fraction;
declare const amountDivide: <TAmount extends Amount<Token & {
decimals?: number;
}, string, {
amount: bigint;
}>>(a: TAmount, b: TAmount extends Amount<TAmount["token"], infer TType extends `${TAmount["token"]["type"]}${string}`, {
amount: bigint;
}> ? BigIntIsh | Amount<TAmount["token"], TType, {
amount: bigint;
}> : never) => Omit<TAmount, "amount"> & {
amount: bigint;
};
/**
* Divide the first fraction by the second
* Returns true if {@link a} is less than {@link b}
*/
declare const fractionDivide: (a: Fraction, b: Fraction | BigIntIsh) => Fraction;
declare const amountLessThan: <TAmount extends Amount<Token & {
decimals?: number;
}, string, {
amount: bigint;
}>>(a: TAmount, b: TAmount extends Amount<TAmount["token"], infer TType extends `${TAmount["token"]["type"]}${string}`, {
amount: bigint;
}> ? BigIntIsh | Amount<TAmount["token"], TType, {
amount: bigint;
}> : never) => boolean;
/**
* Return true if the first fraction is less than the second
* Returns true if {@link a} is equal to {@link b}
*/
declare const fractionLessThan: (a: Fraction, b: Fraction | BigIntIsh) => boolean;
declare const amountEqualTo: <TAmount extends Amount<Token & {
decimals?: number;
}, string, {
amount: bigint;
}>>(a: TAmount, b: TAmount extends Amount<TAmount["token"], infer TType extends `${TAmount["token"]["type"]}${string}`, {
amount: bigint;
}> ? BigIntIsh | Amount<TAmount["token"], TType, {
amount: bigint;
}> : never) => boolean;
/**
* Return true if the first fraction is greater than the second
* Returns true if {@link a} is greater than {@link b}
*/
declare const fractionGreaterThan: (a: Fraction, b: Fraction | BigIntIsh) => boolean;
declare const amountGreaterThan: <TAmount extends Amount<Token & {
decimals?: number;
}, string, {
amount: bigint;
}>>(a: TAmount, b: TAmount extends Amount<TAmount["token"], infer TType extends `${TAmount["token"]["type"]}${string}`, {
amount: bigint;
}> ? BigIntIsh | Amount<TAmount["token"], TType, {
amount: bigint;
}> : never) => boolean;
/**
* Return true if the first fraction is equal to the second
* Returns the {@link amount} as a number with an adjustment for decimals
*/
declare const fractionEqualTo: (a: Fraction, b: Fraction | BigIntIsh) => boolean;
declare const fractionToNumber: (fraction: Fraction) => number;
declare const amountToNumber: (amount: Amount) => number;
declare const isPrice: <TQuoteCurrency extends Token & {
decimals?: number;
}, TBaseCurrency extends Token & {
decimals?: number;
}>(x: BigIntIsh | Price<TQuoteCurrency, TBaseCurrency>) => x is Price<TQuoteCurrency, TBaseCurrency>;
declare const createPriceFromFraction: <TQuoteCurrency extends Token & {
decimals?: number;
}, TBaseCurrency extends Token & {
decimals?: number;
}>(quote: TQuoteCurrency, base: TBaseCurrency, price: Fraction) => Price<TQuoteCurrency, TBaseCurrency>;
declare const createPriceFromAmounts: <TQuoteCurrency extends Token & {
decimals?: number;
}, TBaseCurrency extends Token & {
decimals?: number;
}>(quote: Amount<TQuoteCurrency>, base: Amount<TBaseCurrency>) => Price<TQuoteCurrency, TBaseCurrency>;
declare const createPrice: <TQuoteCurrency extends Token & {
decimals?: number;
}, TBaseCurrency extends Token & {
decimals?: number;
}>(quote: TQuoteCurrency, base: TBaseCurrency, numerator: BigIntIsh, denominator?: BigIntIsh) => Price<TQuoteCurrency, TBaseCurrency>;
declare const priceInvert: <TQuoteCurrency extends Token & {
decimals?: number;
}, TBaseCurrency extends Token & {
decimals?: number;
}>(price: Price<TQuoteCurrency, TBaseCurrency>) => Price<TBaseCurrency, TQuoteCurrency>;
declare const priceAdd: <TBaseCurrency extends Token & {
decimals?: number;
}, TQuoteCurrency extends Token & {
decimals?: number;
}>(a: Price<TQuoteCurrency, TBaseCurrency>, b: BigIntIsh | Price<TQuoteCurrency, TBaseCurrency>) => Price<TQuoteCurrency, TBaseCurrency>;
declare const priceSubtract: <TQuoteCurrency extends Token & {
decimals?: number;
}, TBaseCurrency extends Token & {
decimals?: number;
}>(a: Price<TQuoteCurrency, TBaseCurrency>, b: BigIntIsh | Price<TQuoteCurrency, TBaseCurrency>) => Price<TQuoteCurrency, TBaseCurrency>;
declare const priceMultiply: <TQuoteCurrency extends Token & {
decimals?: number;
}, TBaseCurrency extends Token & {
decimals?: number;
}>(a: Price<TQuoteCurrency, TBaseCurrency>, b: BigIntIsh | Price<TQuoteCurrency, TBaseCurrency>) => Price<TQuoteCurrency, TBaseCurrency>;
declare const priceDivide: <TQuoteCurrency extends Token & {
decimals?: number;
}, TBaseCurrency extends Token & {
decimals?: number;
}>(a: Price<TQuoteCurrency, TBaseCurrency>, b: BigIntIsh | Price<TQuoteCurrency, TBaseCurrency>) => Price<TQuoteCurrency, TBaseCurrency>;
declare const priceLessThan: <TQuoteCurrency extends Token & {
decimals?: number;
}, TBaseCurrency extends Token & {
decimals?: number;
}>(a: Price<TQuoteCurrency, TBaseCurrency>, b: BigIntIsh | Price<TQuoteCurrency, TBaseCurrency>) => boolean;
declare const priceEqualTo: <TQuoteCurrency extends Token & {
decimals?: number;
}, TBaseCurrency extends Token & {
decimals?: number;
}>(a: Price<TQuoteCurrency, TBaseCurrency>, b: BigIntIsh | Price<TQuoteCurrency, TBaseCurrency>) => boolean;
declare const priceGreaterThan: <TQuoteCurrency extends Token & {
decimals?: number;
}, TBaseCurrency extends Token & {
decimals?: number;
}>(a: Price<TQuoteCurrency, TBaseCurrency>, b: BigIntIsh | Price<TQuoteCurrency, TBaseCurrency>) => boolean;
declare const priceQuote: <TQuoteCurrency extends Token & {
decimals?: number;
}, TBaseCurrency extends Token & {
decimals?: number;
}>(price: Price<TQuoteCurrency, TBaseCurrency>, amount: Amount<TBaseCurrency>) => Amount<TQuoteCurrency>;
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;
declare const readAndParse: <TRet, TParse>(reverseMirageRead: ReverseMirageRead<TRet, TParse>) => Promise<TParse>;
type ERC20 = Token<"erc20"> & {
type BaseERC20<TType extends string = string> = Token<TType> & {
address: Address;
name: string;
symbol: string;
decimals: number;
blockCreated: bigint;
};
type ERC20Permit = ERC20 & {
type ERC20 = BaseERC20<"erc20">;
type ERC20Permit = BaseERC20<"erc20Permit"> & {
version: string;
};
type ERC20Data<TERC20 extends ERC20> = Amount<TERC20>;
type ERC20Amount<TERC20 extends ERC20> = ERC20Data<TERC20>;
type ERC20Data<TERC20 extends BaseERC20> = Amount<TERC20, `${TERC20["type"]}Amount`>;
type ERC20Amount<TERC20 extends BaseERC20> = Amount<TERC20, `${TERC20["type"]}Amount`>;
type ERC20PermitData<TERC20 extends ERC20Permit> = TokenData<TERC20, `${TERC20["type"]}Data`, {
amount: bigint;
nonce: bigint;
}>;
declare const erc20BalanceOf: <TERC20 extends ERC20>(publicClient: PublicClient, args: {
declare const erc20BalanceOf: <TERC20 extends BaseERC20>(args: {
erc20: TERC20;
address: Address$1;
}) => {
read: () => Promise<bigint>;
parse: (data: bigint) => ERC20Amount<TERC20>;
readonly read: (publicClient: PublicClient) => Promise<bigint>;
readonly parse: (data: bigint) => ERC20Amount<TERC20>;
};
declare const erc20Allowance: <TERC20 extends ERC20>(publicClient: PublicClient, args: {
declare const erc20Allowance: <TERC20 extends BaseERC20>(args: {
erc20: TERC20;

@@ -226,48 +210,341 @@ address: Address$1;

}) => {
read: () => Promise<bigint>;
parse: (data: bigint) => ERC20Amount<TERC20>;
readonly read: (publicClient: PublicClient) => Promise<bigint>;
readonly parse: (data: bigint) => ERC20Amount<TERC20>;
};
declare const erc20TotalSupply: <TERC20 extends ERC20>(publicClient: PublicClient, args: {
declare const erc20TotalSupply: <TERC20 extends BaseERC20>(args: {
erc20: TERC20;
}) => {
read: () => Promise<bigint>;
parse: (data: bigint) => ERC20Amount<TERC20>;
readonly read: (publicClient: PublicClient) => Promise<bigint>;
readonly parse: (data: bigint) => ERC20Amount<TERC20>;
};
declare const erc20Name: (publicClient: PublicClient, args: {
erc20: Pick<ERC20, "address">;
declare const erc20Name: (args: {
erc20: Pick<BaseERC20, "address">;
}) => {
read: () => Promise<string>;
parse: (data: string) => string;
readonly read: (publicClient: PublicClient) => Promise<string>;
readonly parse: (data: string) => string;
};
declare const erc20Symbol: (publicClient: PublicClient, args: {
erc20: Pick<ERC20, "address">;
declare const erc20Symbol: (args: {
erc20: Pick<BaseERC20, "address">;
}) => {
read: () => Promise<string>;
parse: (data: string) => string;
readonly read: (publicClient: PublicClient) => Promise<string>;
readonly parse: (data: string) => string;
};
declare const erc20Decimals: (publicClient: PublicClient, args: {
erc20: Pick<ERC20, "address">;
declare const erc20Decimals: (args: {
erc20: Pick<BaseERC20, "address">;
}) => {
read: () => Promise<number>;
parse: (data: number) => number;
readonly read: (publicClient: PublicClient) => Promise<number>;
readonly parse: (data: number) => number;
};
declare const getErc20: (publicClient: PublicClient, args: {
erc20: Pick<ERC20, "address" | "chainID">;
declare const erc20PermitNonce: (args: {
erc20: ERC20Permit;
address: Address$1;
}) => {
read: () => Promise<[string, string, number]>;
parse: (data: [string, string, number]) => ERC20;
readonly read: (publicClient: PublicClient) => Promise<bigint>;
readonly parse: (data: bigint) => bigint;
};
declare const getErc20Permit: (publicClient: PublicClient, args: {
erc20: Pick<ERC20Permit, "address" | "chainID"> & Partial<Pick<ERC20Permit, "version">>;
declare const erc20PermitData: <TERC20 extends ERC20Permit>(args: {
erc20: TERC20;
address: Address$1;
}) => {
read: () => Promise<[string, string, number]>;
parse: (data: [string, string, number]) => ERC20Permit;
readonly read: (publicClient: PublicClient) => Promise<[bigint, bigint]>;
readonly parse: (data: [bigint, bigint]) => ERC20PermitData<TERC20>;
};
declare const erc20PermitDomainSeparator: (args: {
erc20: Pick<ERC20Permit, "address">;
}) => {
readonly read: (publicClient: PublicClient) => Promise<`0x${string}`>;
readonly parse: (data: `0x${string}`) => `0x${string}`;
};
declare const getERC20: (args: {
erc20: Pick<BaseERC20, "address" | "chainID"> & Partial<Pick<BaseERC20, "blockCreated">>;
}) => {
readonly read: (publicClient: PublicClient) => Promise<[string, string, number]>;
readonly parse: (data: [string, string, number]) => ERC20;
};
declare const getERC20Permit: (args: {
erc20: Pick<ERC20Permit, "address" | "chainID"> & Partial<Pick<ERC20Permit, "version" | "blockCreated">>;
}) => {
readonly read: (publicClient: PublicClient) => Promise<[string, string, number]>;
readonly parse: (data: [string, string, number]) => ERC20Permit;
};
/**
* Returns either a {@link ERC20} or {@link ERC20Permit} depending on whether the specified token implements EIP 2616\
*
* Implementation is determined by checking if calling `DOMAIN_SEPARATOR()` reverts
*/
declare const erc20IsPermit: (args: {
erc20: Pick<BaseERC20, "address" | "chainID"> & Partial<Pick<BaseERC20, "blockCreated">> & Partial<Pick<ERC20Permit, "version">>;
}) => {
readonly read: (publicClient: PublicClient) => Promise<[[string, string, number], `0x${string}`] | [[string, string, number]]>;
readonly parse: (data: [[string, string, number], `0x${string}`] | [[string, string, number]]) => ERC20 | ERC20Permit;
};
declare const createErc20: (address: Address$1, name: string, symbol: string, decimals: number, chainID: number) => ERC20;
/**
* Creates an {@link ERC20}
*/
declare const createERC20: (address: Address$1, name: string, symbol: string, decimals: number, chainID: number, blockCreated?: bigint) => ERC20;
/**
* Creates an {@link ERC20Permit}
*/
declare const createERC20Permit: (address: Address$1, name: string, symbol: string, decimals: number, version: string, chainID: number, blockCreated?: bigint) => ERC20Permit;
/**
* Creates a {@link ERC20PermitData} from a {@link erc20Permit}, a string, and a {@link nonce}
*/
declare const createERC20PermitDataFromString: <TERC20 extends ERC20Permit>(erc20Permit: TERC20, amount: string, nonce: bigint) => ERC20PermitData<TERC20>;
/**
* Creates a {@link ERC20PermitData} from a {@link erc20Permit}, a {@link Fraction}, and a {@link nonce}
*/
declare const createERC20PermitDataFromFraction: <TERC20 extends ERC20Permit>(erc20Permit: TERC20, amount: Fraction, nonce: bigint) => ERC20PermitData<TERC20>;
/**
* Creates a {@link ERC20PermitData} from a {@link erc20Permit}, a {@link Fraction}, and a {@link nonce}
*/
declare const createERC20PermitDataFromRaw: <TERC20 extends ERC20Permit>(erc20Permit: TERC20, amount: bigint, nonce: bigint) => ERC20PermitData<TERC20>;
/**
* EIP 712 Type for Permit
*/
declare const PermitType: {
readonly Permit: readonly [{
readonly name: "owner";
readonly type: "address";
}, {
readonly name: "spender";
readonly type: "address";
}, {
readonly name: "value";
readonly type: "uint256";
}, {
readonly name: "nonce";
readonly type: "uint256";
}, {
readonly name: "deadline";
readonly type: "uint256";
}];
};
/**
* Returns the EIP 712 typed data hash of type {@link PermitType}
*/
declare const erc20PermitTypedDataHash: (permit: {
amount: ERC20PermitData<ERC20Permit>;
owner: Address$1;
spender: Address$1;
deadline: bigint;
}) => `0x${string}`;
declare const erc20ABI: readonly [{
declare const weth9ABI: readonly [{
readonly constant: true;
readonly payable: false;
readonly stateMutability: "view";
readonly type: "function";
readonly inputs: readonly [];
readonly name: "name";
readonly outputs: readonly [{
readonly name: "";
readonly type: "string";
}];
}, {
readonly constant: false;
readonly payable: false;
readonly stateMutability: "nonpayable";
readonly type: "function";
readonly inputs: readonly [{
readonly name: "guy";
readonly type: "address";
}, {
readonly name: "wad";
readonly type: "uint256";
}];
readonly name: "approve";
readonly outputs: readonly [{
readonly name: "";
readonly type: "bool";
}];
}, {
readonly constant: true;
readonly payable: false;
readonly stateMutability: "view";
readonly type: "function";
readonly inputs: readonly [];
readonly name: "totalSupply";
readonly outputs: readonly [{
readonly name: "";
readonly type: "uint256";
}];
}, {
readonly constant: false;
readonly payable: false;
readonly stateMutability: "nonpayable";
readonly type: "function";
readonly inputs: readonly [{
readonly name: "src";
readonly type: "address";
}, {
readonly name: "dst";
readonly type: "address";
}, {
readonly name: "wad";
readonly type: "uint256";
}];
readonly name: "transferFrom";
readonly outputs: readonly [{
readonly name: "";
readonly type: "bool";
}];
}, {
readonly constant: false;
readonly payable: false;
readonly stateMutability: "nonpayable";
readonly type: "function";
readonly inputs: readonly [{
readonly name: "wad";
readonly type: "uint256";
}];
readonly name: "withdraw";
readonly outputs: readonly [];
}, {
readonly constant: true;
readonly payable: false;
readonly stateMutability: "view";
readonly type: "function";
readonly inputs: readonly [];
readonly name: "decimals";
readonly outputs: readonly [{
readonly name: "";
readonly type: "uint8";
}];
}, {
readonly constant: true;
readonly payable: false;
readonly stateMutability: "view";
readonly type: "function";
readonly inputs: readonly [{
readonly name: "";
readonly type: "address";
}];
readonly name: "balanceOf";
readonly outputs: readonly [{
readonly name: "";
readonly type: "uint256";
}];
}, {
readonly constant: true;
readonly payable: false;
readonly stateMutability: "view";
readonly type: "function";
readonly inputs: readonly [];
readonly name: "symbol";
readonly outputs: readonly [{
readonly name: "";
readonly type: "string";
}];
}, {
readonly constant: false;
readonly payable: false;
readonly stateMutability: "nonpayable";
readonly type: "function";
readonly inputs: readonly [{
readonly name: "dst";
readonly type: "address";
}, {
readonly name: "wad";
readonly type: "uint256";
}];
readonly name: "transfer";
readonly outputs: readonly [{
readonly name: "";
readonly type: "bool";
}];
}, {
readonly constant: false;
readonly payable: true;
readonly stateMutability: "payable";
readonly type: "function";
readonly inputs: readonly [];
readonly name: "deposit";
readonly outputs: readonly [];
}, {
readonly constant: true;
readonly payable: false;
readonly stateMutability: "view";
readonly type: "function";
readonly inputs: readonly [{
readonly name: "";
readonly type: "address";
}, {
readonly name: "";
readonly type: "address";
}];
readonly name: "allowance";
readonly outputs: readonly [{
readonly name: "";
readonly type: "uint256";
}];
}, {
readonly payable: true;
readonly stateMutability: "payable";
readonly type: "fallback";
}, {
readonly type: "event";
readonly anonymous: false;
readonly inputs: readonly [{
readonly name: "src";
readonly type: "address";
readonly indexed: true;
}, {
readonly name: "guy";
readonly type: "address";
readonly indexed: true;
}, {
readonly name: "wad";
readonly type: "uint256";
readonly indexed: false;
}];
readonly name: "Approval";
}, {
readonly type: "event";
readonly anonymous: false;
readonly inputs: readonly [{
readonly name: "src";
readonly type: "address";
readonly indexed: true;
}, {
readonly name: "dst";
readonly type: "address";
readonly indexed: true;
}, {
readonly name: "wad";
readonly type: "uint256";
readonly indexed: false;
}];
readonly name: "Transfer";
}, {
readonly type: "event";
readonly anonymous: false;
readonly inputs: readonly [{
readonly name: "dst";
readonly type: "address";
readonly indexed: true;
}, {
readonly name: "wad";
readonly type: "uint256";
readonly indexed: false;
}];
readonly name: "Deposit";
}, {
readonly type: "event";
readonly anonymous: false;
readonly inputs: readonly [{
readonly name: "src";
readonly type: "address";
readonly indexed: true;
}, {
readonly name: "wad";
readonly type: "uint256";
readonly indexed: false;
}];
readonly name: "Withdrawal";
}];
declare const solmateErc1155ABI: readonly [{
readonly type: "event";
readonly anonymous: false;
readonly inputs: readonly [{
readonly name: "owner";

@@ -278,2 +555,246 @@ readonly internalType: "address";

}, {
readonly name: "operator";
readonly internalType: "address";
readonly type: "address";
readonly indexed: true;
}, {
readonly name: "approved";
readonly internalType: "bool";
readonly type: "bool";
readonly indexed: false;
}];
readonly name: "ApprovalForAll";
}, {
readonly type: "event";
readonly anonymous: false;
readonly inputs: readonly [{
readonly name: "operator";
readonly internalType: "address";
readonly type: "address";
readonly indexed: true;
}, {
readonly name: "from";
readonly internalType: "address";
readonly type: "address";
readonly indexed: true;
}, {
readonly name: "to";
readonly internalType: "address";
readonly type: "address";
readonly indexed: true;
}, {
readonly name: "ids";
readonly internalType: "uint256[]";
readonly type: "uint256[]";
readonly indexed: false;
}, {
readonly name: "amounts";
readonly internalType: "uint256[]";
readonly type: "uint256[]";
readonly indexed: false;
}];
readonly name: "TransferBatch";
}, {
readonly type: "event";
readonly anonymous: false;
readonly inputs: readonly [{
readonly name: "operator";
readonly internalType: "address";
readonly type: "address";
readonly indexed: true;
}, {
readonly name: "from";
readonly internalType: "address";
readonly type: "address";
readonly indexed: true;
}, {
readonly name: "to";
readonly internalType: "address";
readonly type: "address";
readonly indexed: true;
}, {
readonly name: "id";
readonly internalType: "uint256";
readonly type: "uint256";
readonly indexed: false;
}, {
readonly name: "amount";
readonly internalType: "uint256";
readonly type: "uint256";
readonly indexed: false;
}];
readonly name: "TransferSingle";
}, {
readonly type: "event";
readonly anonymous: false;
readonly inputs: readonly [{
readonly name: "value";
readonly internalType: "string";
readonly type: "string";
readonly indexed: false;
}, {
readonly name: "id";
readonly internalType: "uint256";
readonly type: "uint256";
readonly indexed: true;
}];
readonly name: "URI";
}, {
readonly stateMutability: "view";
readonly type: "function";
readonly inputs: readonly [{
readonly name: "";
readonly internalType: "address";
readonly type: "address";
}, {
readonly name: "";
readonly internalType: "uint256";
readonly type: "uint256";
}];
readonly name: "balanceOf";
readonly outputs: readonly [{
readonly name: "";
readonly internalType: "uint256";
readonly type: "uint256";
}];
}, {
readonly stateMutability: "view";
readonly type: "function";
readonly inputs: readonly [{
readonly name: "owners";
readonly internalType: "address[]";
readonly type: "address[]";
}, {
readonly name: "ids";
readonly internalType: "uint256[]";
readonly type: "uint256[]";
}];
readonly name: "balanceOfBatch";
readonly outputs: readonly [{
readonly name: "balances";
readonly internalType: "uint256[]";
readonly type: "uint256[]";
}];
}, {
readonly stateMutability: "view";
readonly type: "function";
readonly inputs: readonly [{
readonly name: "";
readonly internalType: "address";
readonly type: "address";
}, {
readonly name: "";
readonly internalType: "address";
readonly type: "address";
}];
readonly name: "isApprovedForAll";
readonly outputs: readonly [{
readonly name: "";
readonly internalType: "bool";
readonly type: "bool";
}];
}, {
readonly stateMutability: "nonpayable";
readonly type: "function";
readonly inputs: readonly [{
readonly name: "from";
readonly internalType: "address";
readonly type: "address";
}, {
readonly name: "to";
readonly internalType: "address";
readonly type: "address";
}, {
readonly name: "ids";
readonly internalType: "uint256[]";
readonly type: "uint256[]";
}, {
readonly name: "amounts";
readonly internalType: "uint256[]";
readonly type: "uint256[]";
}, {
readonly name: "data";
readonly internalType: "bytes";
readonly type: "bytes";
}];
readonly name: "safeBatchTransferFrom";
readonly outputs: readonly [];
}, {
readonly stateMutability: "nonpayable";
readonly type: "function";
readonly inputs: readonly [{
readonly name: "from";
readonly internalType: "address";
readonly type: "address";
}, {
readonly name: "to";
readonly internalType: "address";
readonly type: "address";
}, {
readonly name: "id";
readonly internalType: "uint256";
readonly type: "uint256";
}, {
readonly name: "amount";
readonly internalType: "uint256";
readonly type: "uint256";
}, {
readonly name: "data";
readonly internalType: "bytes";
readonly type: "bytes";
}];
readonly name: "safeTransferFrom";
readonly outputs: readonly [];
}, {
readonly stateMutability: "nonpayable";
readonly type: "function";
readonly inputs: readonly [{
readonly name: "operator";
readonly internalType: "address";
readonly type: "address";
}, {
readonly name: "approved";
readonly internalType: "bool";
readonly type: "bool";
}];
readonly name: "setApprovalForAll";
readonly outputs: readonly [];
}, {
readonly stateMutability: "view";
readonly type: "function";
readonly inputs: readonly [{
readonly name: "interfaceId";
readonly internalType: "bytes4";
readonly type: "bytes4";
}];
readonly name: "supportsInterface";
readonly outputs: readonly [{
readonly name: "";
readonly internalType: "bool";
readonly type: "bool";
}];
}, {
readonly stateMutability: "view";
readonly type: "function";
readonly inputs: readonly [{
readonly name: "id";
readonly internalType: "uint256";
readonly type: "uint256";
}];
readonly name: "uri";
readonly outputs: readonly [{
readonly name: "";
readonly internalType: "string";
readonly type: "string";
}];
}];
declare const solmateErc20ABI: readonly [{
readonly type: "event";
readonly anonymous: false;
readonly inputs: readonly [{
readonly name: "owner";
readonly internalType: "address";
readonly type: "address";
readonly indexed: true;
}, {
readonly name: "spender";

@@ -499,30 +1020,489 @@ readonly internalType: "address";

}];
declare const solmateErc721ABI: readonly [{
readonly type: "event";
readonly anonymous: false;
readonly inputs: readonly [{
readonly name: "owner";
readonly internalType: "address";
readonly type: "address";
readonly indexed: true;
}, {
readonly name: "spender";
readonly internalType: "address";
readonly type: "address";
readonly indexed: true;
}, {
readonly name: "id";
readonly internalType: "uint256";
readonly type: "uint256";
readonly indexed: true;
}];
readonly name: "Approval";
}, {
readonly type: "event";
readonly anonymous: false;
readonly inputs: readonly [{
readonly name: "owner";
readonly internalType: "address";
readonly type: "address";
readonly indexed: true;
}, {
readonly name: "operator";
readonly internalType: "address";
readonly type: "address";
readonly indexed: true;
}, {
readonly name: "approved";
readonly internalType: "bool";
readonly type: "bool";
readonly indexed: false;
}];
readonly name: "ApprovalForAll";
}, {
readonly type: "event";
readonly anonymous: false;
readonly inputs: readonly [{
readonly name: "from";
readonly internalType: "address";
readonly type: "address";
readonly indexed: true;
}, {
readonly name: "to";
readonly internalType: "address";
readonly type: "address";
readonly indexed: true;
}, {
readonly name: "id";
readonly internalType: "uint256";
readonly type: "uint256";
readonly indexed: true;
}];
readonly name: "Transfer";
}, {
readonly stateMutability: "nonpayable";
readonly type: "function";
readonly inputs: readonly [{
readonly name: "spender";
readonly internalType: "address";
readonly type: "address";
}, {
readonly name: "id";
readonly internalType: "uint256";
readonly type: "uint256";
}];
readonly name: "approve";
readonly outputs: readonly [];
}, {
readonly stateMutability: "view";
readonly type: "function";
readonly inputs: readonly [{
readonly name: "owner";
readonly internalType: "address";
readonly type: "address";
}];
readonly name: "balanceOf";
readonly outputs: readonly [{
readonly name: "";
readonly internalType: "uint256";
readonly type: "uint256";
}];
}, {
readonly stateMutability: "view";
readonly type: "function";
readonly inputs: readonly [{
readonly name: "";
readonly internalType: "uint256";
readonly type: "uint256";
}];
readonly name: "getApproved";
readonly outputs: readonly [{
readonly name: "";
readonly internalType: "address";
readonly type: "address";
}];
}, {
readonly stateMutability: "view";
readonly type: "function";
readonly inputs: readonly [{
readonly name: "";
readonly internalType: "address";
readonly type: "address";
}, {
readonly name: "";
readonly internalType: "address";
readonly type: "address";
}];
readonly name: "isApprovedForAll";
readonly outputs: readonly [{
readonly name: "";
readonly internalType: "bool";
readonly type: "bool";
}];
}, {
readonly stateMutability: "view";
readonly type: "function";
readonly inputs: readonly [];
readonly name: "name";
readonly outputs: readonly [{
readonly name: "";
readonly internalType: "string";
readonly type: "string";
}];
}, {
readonly stateMutability: "view";
readonly type: "function";
readonly inputs: readonly [{
readonly name: "id";
readonly internalType: "uint256";
readonly type: "uint256";
}];
readonly name: "ownerOf";
readonly outputs: readonly [{
readonly name: "owner";
readonly internalType: "address";
readonly type: "address";
}];
}, {
readonly stateMutability: "nonpayable";
readonly type: "function";
readonly inputs: readonly [{
readonly name: "from";
readonly internalType: "address";
readonly type: "address";
}, {
readonly name: "to";
readonly internalType: "address";
readonly type: "address";
}, {
readonly name: "id";
readonly internalType: "uint256";
readonly type: "uint256";
}];
readonly name: "safeTransferFrom";
readonly outputs: readonly [];
}, {
readonly stateMutability: "nonpayable";
readonly type: "function";
readonly inputs: readonly [{
readonly name: "from";
readonly internalType: "address";
readonly type: "address";
}, {
readonly name: "to";
readonly internalType: "address";
readonly type: "address";
}, {
readonly name: "id";
readonly internalType: "uint256";
readonly type: "uint256";
}, {
readonly name: "data";
readonly internalType: "bytes";
readonly type: "bytes";
}];
readonly name: "safeTransferFrom";
readonly outputs: readonly [];
}, {
readonly stateMutability: "nonpayable";
readonly type: "function";
readonly inputs: readonly [{
readonly name: "operator";
readonly internalType: "address";
readonly type: "address";
}, {
readonly name: "approved";
readonly internalType: "bool";
readonly type: "bool";
}];
readonly name: "setApprovalForAll";
readonly outputs: readonly [];
}, {
readonly stateMutability: "view";
readonly type: "function";
readonly inputs: readonly [{
readonly name: "interfaceId";
readonly internalType: "bytes4";
readonly type: "bytes4";
}];
readonly name: "supportsInterface";
readonly outputs: readonly [{
readonly name: "";
readonly internalType: "bool";
readonly type: "bool";
}];
}, {
readonly stateMutability: "view";
readonly type: "function";
readonly inputs: readonly [];
readonly name: "symbol";
readonly outputs: readonly [{
readonly name: "";
readonly internalType: "string";
readonly type: "string";
}];
}, {
readonly stateMutability: "view";
readonly type: "function";
readonly inputs: readonly [{
readonly name: "id";
readonly internalType: "uint256";
readonly type: "uint256";
}];
readonly name: "tokenURI";
readonly outputs: readonly [{
readonly name: "";
readonly internalType: "string";
readonly type: "string";
}];
}, {
readonly stateMutability: "nonpayable";
readonly type: "function";
readonly inputs: readonly [{
readonly name: "from";
readonly internalType: "address";
readonly type: "address";
}, {
readonly name: "to";
readonly internalType: "address";
readonly type: "address";
}, {
readonly name: "id";
readonly internalType: "uint256";
readonly type: "uint256";
}];
readonly name: "transferFrom";
readonly outputs: readonly [];
}];
declare const erc20Transfer: (publicClient: PublicClient, walletClient: WalletClient, account: Account | Address, args: {
to: Address;
amount: ERC20Amount<ERC20>;
}) => Promise<ReverseMirageWrite<typeof erc20ABI, "transfer">>;
amount: ERC20Amount<ERC20 | ERC20Permit>;
}) => Promise<ReverseMirageWrite<typeof solmateErc20ABI, "transfer">>;
declare const erc20Approve: (publicClient: PublicClient, walletClient: WalletClient, account: Account | Address, args: {
spender: Address;
amount: ERC20Amount<ERC20>;
}) => Promise<ReverseMirageWrite<typeof erc20ABI, "approve">>;
amount: ERC20Amount<ERC20 | ERC20Permit>;
}) => Promise<ReverseMirageWrite<typeof solmateErc20ABI, "approve">>;
declare const erc20TransferFrom: (publicClient: PublicClient, walletClient: WalletClient, account: Account | Address, args: {
from: Address;
to: Address;
amount: ERC20Amount<ERC20>;
}) => Promise<ReverseMirageWrite<typeof erc20ABI, "transferFrom">>;
amount: ERC20Amount<ERC20 | ERC20Permit>;
}) => Promise<ReverseMirageWrite<typeof solmateErc20ABI, "transferFrom">>;
declare const erc20SignPermit: (walletClient: WalletClient, account: Account | Address, permit: {
permitData: ERC20PermitData<ERC20Permit>;
owner: Address;
spender: Address;
deadline: bigint;
}) => Promise<`0x${string}`>;
declare const erc20Permit: (publicClient: PublicClient, walletClient: WalletClient, account: Account | Address, args: {
owner: Address;
spender: Address;
permitData: ERC20PermitData<ERC20Permit>;
deadline: bigint;
signature: Hex;
}) => Promise<ReverseMirageWrite<typeof solmateErc20ABI, "permit">>;
type ERC721 = Token<"erc721"> & {
address: Address$1;
name: string;
symbol: string;
id: bigint;
tokenURI: string;
blockCreated: bigint;
};
type ERC721IDData<TERC721 extends ERC721> = TokenData<TERC721, `${TERC721["type"]}IDData`, {
owned: boolean;
}>;
type ERC721Data<TERC721 extends ERC721, TBalance extends number = number> = TokenData<TERC721, `${TERC721["type"]}Data`, {
balance: TBalance;
ids: Tuple<bigint, TBalance> | undefined;
}>;
declare const erc721Name: (args: {
erc721: Pick<ERC721, "address">;
}) => {
readonly read: (publicClient: PublicClient) => Promise<string>;
readonly parse: (data: string) => string;
};
declare const erc721Symbol: (args: {
erc721: Pick<ERC721, "address">;
}) => {
readonly read: (publicClient: PublicClient) => Promise<string>;
readonly parse: (data: string) => string;
};
declare const erc721TokenURI: (args: {
erc721: Pick<ERC721, "address" | "id">;
}) => {
readonly read: (publicClient: PublicClient) => Promise<string>;
readonly parse: (data: string) => string;
};
declare const erc721OwnerOf: (args: {
erc721: Pick<ERC721, "address" | "id">;
}) => {
readonly read: (publicClient: PublicClient) => Promise<`0x${string}`>;
readonly parse: (data: `0x${string}`) => `0x${string}`;
};
declare const erc721BalanceOf: (args: {
erc721: Pick<ERC721, "address">;
owner: Address$1;
}) => {
readonly read: (publicClient: PublicClient) => Promise<bigint>;
readonly parse: (data: bigint) => bigint;
};
declare const erc721GetApproved: (args: {
erc721: Pick<ERC721, "address" | "id">;
}) => {
readonly read: (publicClient: PublicClient) => Promise<`0x${string}`>;
readonly parse: (data: `0x${string}`) => `0x${string}`;
};
declare const erc721IsApprovedForAll: (args: {
erc721: Pick<ERC721, "address">;
owner: Address$1;
spender: Address$1;
}) => {
readonly read: (publicClient: PublicClient) => Promise<boolean>;
readonly parse: (data: boolean) => boolean;
};
declare const erc721SupportsInterface: (args: {
erc721: Pick<ERC721, "address">;
interfaceID: Hex;
}) => {
readonly read: (publicClient: PublicClient) => Promise<boolean>;
readonly parse: (data: boolean) => boolean;
};
declare const getERC721: (args: {
erc721: Pick<ERC721, "address" | "id" | "chainID"> & Partial<Pick<ERC721, "blockCreated">>;
}) => {
readonly read: (publicClient: PublicClient) => Promise<[string, string, string]>;
readonly parse: (data: [string, string, string]) => ERC721;
};
declare const erc721IDData: <TERC721 extends ERC721>(args: {
erc721: TERC721;
owner: Address$1;
}) => {
readonly read: (publicClient: PublicClient) => Promise<`0x${string}`>;
readonly parse: (data: `0x${string}`) => ERC721IDData<TERC721>;
};
declare const erc721Data: <TERC721 extends ERC721>(args: {
erc721: TERC721;
owner: Address$1;
}) => {
readonly read: (publicClient: PublicClient) => Promise<bigint>;
readonly parse: (data: bigint) => ERC721Data<TERC721>;
};
/**
* Creates an {@link ERC721}
*/
declare const createERC721: (address: Address$1, name: string, symbol: string, id: bigint, tokenURI: string, chainID: number, blockCreated?: bigint) => ERC721;
/**
* Creates an {@link ERC721IDData}
*/
declare const createERC721IDData: <TERC721 extends ERC721>(erc721: TERC721, owned: boolean) => ERC721IDData<TERC721>;
/**
* Creates an {@link ERC721Data}
*/
declare const createERC721Data: <TERC721 extends ERC721, TBalance extends number>(erc721: TERC721, balance: TBalance, ids?: Tuple<bigint, TBalance> | undefined) => ERC721Data<TERC721, TBalance>;
/**
* Transfer an {@link ERC721}
*
* Depending on `data` passed in, use one of three transfer methods
*/
declare const erc721Transfer: (publicClient: PublicClient, walletClient: WalletClient, account: Account | Address$1, args: {
from: Address$1;
to: Address$1;
erc721: Pick<ERC721, "address" | "id">;
data?: "safe" | Hex;
}) => Promise<ReverseMirageWrite<typeof solmateErc721ABI, "transferFrom" | "safeTransferFrom">>;
declare const erc721Approve: (publicClient: PublicClient, walletClient: WalletClient, account: Account | Address$1, args: {
erc721: Pick<ERC721, "address" | "id">;
spender: Address$1;
}) => Promise<ReverseMirageWrite<typeof solmateErc721ABI, "approve">>;
declare const erc721SetApprovalForAll: (publicClient: PublicClient, walletClient: WalletClient, account: Account | Address$1, args: {
erc721: Pick<ERC721, "address">;
spender: Address$1;
approved: boolean;
}) => Promise<ReverseMirageWrite<typeof solmateErc721ABI, "setApprovalForAll">>;
type ERC1155 = Token<"erc1155"> & {
address: Address$1;
id: bigint;
uri: string;
blockCreated: bigint;
};
type ERC1155Data<TERC1155 extends ERC1155> = Amount<TERC1155, `${TERC1155["type"]}Data`>;
declare const erc1155IsApprovedForAll: (args: {
erc1155: Pick<ERC1155, "address">;
owner: Address$1;
spender: Address$1;
}) => {
readonly read: (publicClient: PublicClient) => Promise<boolean>;
readonly parse: (data: boolean) => boolean;
};
declare const erc1155URI: (args: {
erc1155: Pick<ERC1155, "address" | "id">;
}) => {
readonly read: (publicClient: PublicClient) => Promise<string>;
readonly parse: (data: string) => string;
};
declare const erc1155BalanceOf: <TERC1155 extends ERC1155>(args: {
erc1155: TERC1155;
owner: Address$1;
}) => {
readonly read: (publicClient: PublicClient) => Promise<bigint>;
readonly parse: (data: bigint) => ERC1155Data<TERC1155>;
};
declare const getERC1155: (args: {
erc1155: Pick<ERC1155, "address" | "id" | "chainID"> & Partial<Pick<ERC1155, "blockCreated">>;
}) => {
readonly read: (publicClient: PublicClient) => Promise<string>;
readonly parse: (data: string) => ERC1155;
};
/**
* Creates an {@link ERC1155}
*/
declare const createERC1155: (address: Address$1, id: bigint, uri: string, chainID: number, blockCreated?: bigint) => ERC1155;
/**
* Creates an {@link ERC1155Data}
*/
declare const createERC1155Data: <TERC1155 extends ERC1155>(erc1155: TERC1155, amount: bigint) => ERC1155Data<TERC1155>;
declare const erc1155SetApprovalForAll: (publicClient: PublicClient, walletClient: WalletClient, account: Account | Address$1, args: {
erc1155: Pick<ERC1155, "address">;
spender: Address$1;
approved: boolean;
}) => Promise<ReverseMirageWrite<typeof solmateErc1155ABI, "setApprovalForAll">>;
declare const erc1155Transfer: (publicClient: PublicClient, walletClient: WalletClient, account: Account | Address$1, args: {
erc1155: ERC1155Data<ERC1155>;
from: Address$1;
to: Address$1;
data?: Hex;
}) => Promise<ReverseMirageWrite<typeof solmateErc1155ABI, "safeTransferFrom">>;
declare const erc1155TransferBatch: (publicClient: PublicClient, walletClient: WalletClient, account: Account | Address$1, args: {
erc1155: ERC1155Data<ERC1155>[];
from: Address$1;
to: Address$1;
data?: Hex;
}) => Promise<ReverseMirageWrite<typeof solmateErc1155ABI, "safeBatchTransferFrom">>;
type NativeCurrency = Token<"nativeCurrency"> & {
name: string;
symbol: string;
decimals: number;
};
type NativeCurrencyAmount<TNativeCurrency extends NativeCurrency> = TokenData<TNativeCurrency, {
type NativeCurrencyData<TNativeCurrency extends NativeCurrency> = TokenData<TNativeCurrency, `${TNativeCurrency["type"]}Amount`, {
amount: bigint;
}>;
type NativeCurrencyAmount<TNativeCurrency extends NativeCurrency> = TokenData<TNativeCurrency, `${TNativeCurrency["type"]}Amount`, {
amount: bigint;
}>;
declare const nativeBalance: <TNativeCurrency extends NativeCurrency>(publicClient: PublicClient, args: {
declare const nativeBalance: <TNativeCurrency extends NativeCurrency>(args: {
nativeCurrency: TNativeCurrency;
address: Address$1;
}) => {
read: () => Promise<bigint>;
parse: (data: bigint) => NativeCurrencyAmount<TNativeCurrency>;
readonly read: (publicClient: PublicClient) => Promise<bigint>;
readonly parse: (data: bigint) => NativeCurrencyAmount<TNativeCurrency>;
};

@@ -532,2 +1512,245 @@

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 };
type WETH = BaseERC20<"weth">;
/**
* Creates an {@link WETH}
*/
declare const createWETH: (address: Address$1, name: string, symbol: string, decimals: number, chainID: number, blockCreated?: bigint) => WETH;
declare const wethDeposit: (publicClient: PublicClient, walletClient: WalletClient, account: Account | Address$1, args: {
amount: ERC20Amount<WETH>;
}) => Promise<ReverseMirageWrite<typeof weth9ABI, "deposit">>;
declare const wethWithdraw: (publicClient: PublicClient, walletClient: WalletClient, account: Account | Address$1, args: {
amount: ERC20Amount<WETH>;
}) => Promise<ReverseMirageWrite<typeof weth9ABI, "withdraw">>;
/**
* Read data using a json-rpc request and parse the returned data
*/
declare const readAndParse: <TRet, TParse>(publicClient: PublicClient, reverseMirageRead: ReverseMirageRead<TRet, TParse>) => Promise<TParse>;
/**
* Returns true if {@link x } is of type {@link Fraction}
*/
declare const isFraction: (x: Fraction | BigIntIsh) => x is Fraction;
/**
* Creates a {@link Fraction} from a {@link numerator} and {@link denominator}
*/
declare const createFraction: (numerator: BigIntIsh, denominator?: BigIntIsh) => Fraction;
/**
* Calculates the quotient
*/
declare const fractionQuotient: (fraction: Fraction) => bigint;
/**
* Calculate the remainder
*/
declare const fractionRemainder: (fraction: Fraction) => bigint;
/**
* Calculate the inverse
*/
declare const fractionInvert: (fraction: Fraction) => Fraction;
/**
* Adds {@link a} with {@link b}
*/
declare const fractionAdd: (a: Fraction, b: Fraction | BigIntIsh) => Fraction;
/**
* Subtracts {@link a} by {@link b}
*/
declare const fractionSubtract: (a: Fraction, b: Fraction | BigIntIsh) => Fraction;
/**
* Multiplies {@link a} with {@link b}
*/
declare const fractionMultiply: (a: Fraction, b: Fraction | BigIntIsh) => Fraction;
/**
* Divides {@link a} by {@link b}
*/
declare const fractionDivide: (a: Fraction, b: Fraction | BigIntIsh) => Fraction;
/**
* Returns true if {@link a} is less than {@link b}
*/
declare const fractionLessThan: (a: Fraction, b: Fraction | BigIntIsh) => boolean;
/**
* Returns true if {@link a} is greater than {@link b}
*/
declare const fractionGreaterThan: (a: Fraction, b: Fraction | BigIntIsh) => boolean;
/**
* Returns true if {@link a} is equal to {@link b}
*/
declare const fractionEqualTo: (a: Fraction, b: Fraction | BigIntIsh) => boolean;
declare const fractionToNumber: (fraction: Fraction) => number;
/**
* Returns true if {@link x} is of type {@link Price}
*/
declare const isPrice: <TQuoteCurrency extends Token & {
decimals?: number;
}, TBaseCurrency extends Token & {
decimals?: number;
}>(x: BigIntIsh | Price<TQuoteCurrency, TBaseCurrency>) => x is Price<TQuoteCurrency, TBaseCurrency>;
/**
* Creates a {@link Price} from two {@link Token}s and a {@link Fraction}
* @param quote The quote asset in the price (i.e. USD in traditional equites markets)
* @param base The base asset in the price
* @param price The exchange rate in units of {@link base} per {@link quote} as a {@link Fraction}
*/
declare const createPriceFromFraction: <TQuoteCurrency extends Token & {
decimals?: number;
}, TBaseCurrency extends Token & {
decimals?: number;
}>(quote: TQuoteCurrency, base: TBaseCurrency, price: Fraction) => Price<TQuoteCurrency, TBaseCurrency>;
/**
* Creates a {@link Price} from two {@link Amount}s
* @param quote The quote amount in the price (i.e. USD in traditional equites markets)
* @param base The base amount in the price
*/
declare const createPriceFromAmounts: <TQuoteCurrency extends Token & {
decimals?: number;
}, TBaseCurrency extends Token & {
decimals?: number;
}>(quote: Amount<TQuoteCurrency>, base: Amount<TBaseCurrency>) => Price<TQuoteCurrency, TBaseCurrency>;
/**
* Creates a {@link Price} from two {@link Token}s and a {@link numerator} and {@link denominator}
* @param quote The quote asset in the price (i.e. USD in traditional equites markets)
* @param base The base asset in the price
* @param numerator The numerator in the price
* @param denominator The denominator in the price
*/
declare const createPrice: <TQuoteCurrency extends Token & {
decimals?: number;
}, TBaseCurrency extends Token & {
decimals?: number;
}>(quote: TQuoteCurrency, base: TBaseCurrency, numerator: BigIntIsh, denominator?: BigIntIsh) => Price<TQuoteCurrency, TBaseCurrency>;
/**
* Calculates the inverse
*/
declare const priceInvert: <TQuoteCurrency extends Token & {
decimals?: number;
}, TBaseCurrency extends Token & {
decimals?: number;
}>(price: Price<TQuoteCurrency, TBaseCurrency>) => Price<TBaseCurrency, TQuoteCurrency>;
/**
* Adds {@link a} with {@link b}
*/
declare const priceAdd: <TBaseCurrency extends Token & {
decimals?: number;
}, TQuoteCurrency extends Token & {
decimals?: number;
}>(a: Price<TQuoteCurrency, TBaseCurrency>, b: BigIntIsh | Price<TQuoteCurrency, TBaseCurrency>) => Price<TQuoteCurrency, TBaseCurrency>;
/**
* Subtracts {@link a} by {@link b}
*/
declare const priceSubtract: <TQuoteCurrency extends Token & {
decimals?: number;
}, TBaseCurrency extends Token & {
decimals?: number;
}>(a: Price<TQuoteCurrency, TBaseCurrency>, b: BigIntIsh | Price<TQuoteCurrency, TBaseCurrency>) => Price<TQuoteCurrency, TBaseCurrency>;
/**
* Multiplies {@link a} with {@link b}
*/
declare const priceMultiply: <TQuoteCurrency extends Token & {
decimals?: number;
}, TBaseCurrency extends Token & {
decimals?: number;
}>(a: Price<TQuoteCurrency, TBaseCurrency>, b: BigIntIsh | Price<TQuoteCurrency, TBaseCurrency>) => Price<TQuoteCurrency, TBaseCurrency>;
/**
* Divides {@link a} by {@link b}
*/
declare const priceDivide: <TQuoteCurrency extends Token & {
decimals?: number;
}, TBaseCurrency extends Token & {
decimals?: number;
}>(a: Price<TQuoteCurrency, TBaseCurrency>, b: BigIntIsh | Price<TQuoteCurrency, TBaseCurrency>) => Price<TQuoteCurrency, TBaseCurrency>;
/**
* Returns true if {@link a} is less than {@link b}
*/
declare const priceLessThan: <TQuoteCurrency extends Token & {
decimals?: number;
}, TBaseCurrency extends Token & {
decimals?: number;
}>(a: Price<TQuoteCurrency, TBaseCurrency>, b: BigIntIsh | Price<TQuoteCurrency, TBaseCurrency>) => boolean;
/**
* Returns true if {@link a} is equal to {@link b}
*/
declare const priceEqualTo: <TQuoteCurrency extends Token & {
decimals?: number;
}, TBaseCurrency extends Token & {
decimals?: number;
}>(a: Price<TQuoteCurrency, TBaseCurrency>, b: BigIntIsh | Price<TQuoteCurrency, TBaseCurrency>) => boolean;
/**
* Returns true if {@link a} is greater than {@link b}
*/
declare const priceGreaterThan: <TQuoteCurrency extends Token & {
decimals?: number;
}, TBaseCurrency extends Token & {
decimals?: number;
}>(a: Price<TQuoteCurrency, TBaseCurrency>, b: BigIntIsh | Price<TQuoteCurrency, TBaseCurrency>) => boolean;
/**
* Returns the amount of quote currency corresponding to the {@link amount} of base currency at a given {@link price}
*/
declare const priceQuote: <TQuoteCurrency extends Token & {
decimals?: number;
}, TBaseCurrency extends Token & {
decimals?: number;
}>(price: Price<TQuoteCurrency, TBaseCurrency>, amount: Amount<TBaseCurrency>) => Amount<TQuoteCurrency>;
/**
* Returns the price as a {@link Fraction} without adjusting for decimals
*/
declare const rawPrice: (price: Price<Amount["token"], Amount["token"]>) => Fraction;
/**
* Returns the price as a {@link Fraction} with adjusting for decimals
*/
declare const adjustedPrice: (price: Price<Amount["token"], Amount["token"]>) => Fraction;
/**
* Returns the {@link price} as a number with an adjustment for decimals
*/
declare const priceToNumber: (price: Price<Amount["token"], Amount["token"]>) => number;
type ChainTokens = {
native: NativeCurrency;
weth?: WETH;
};
declare const mainnetTokens: {
readonly native: NativeCurrency;
readonly weth: WETH;
};
declare const sepoliaTokens: {
readonly native: NativeCurrency;
};
declare const goerliTokens: {
readonly native: NativeCurrency;
readonly weth: WETH;
};
declare const optimismTokens: {
readonly native: NativeCurrency;
readonly weth: WETH;
};
declare const optimismGoerliTokens: {
readonly native: NativeCurrency;
};
declare const arbitrumTokens: {
readonly native: NativeCurrency;
readonly weth: WETH;
};
declare const arbitrumGoerliTokens: {
readonly native: NativeCurrency;
};
declare const baseTokens: {
readonly native: NativeCurrency;
readonly weth: WETH;
};
declare const baseGoerliTokens: {
readonly native: NativeCurrency;
};
declare const celoTokens: {
readonly native: NativeCurrency;
readonly weth: WETH;
};
declare const celoAlfajoresTokens: {
readonly native: NativeCurrency;
readonly weth: WETH;
};
declare const foundryTokens: {
readonly native: NativeCurrency;
};
export { Amount, BaseERC20, BigIntIsh, ChainTokens, ERC1155, ERC1155Data, ERC20, ERC20Amount, ERC20Data, ERC20Permit, ERC20PermitData, ERC721, ERC721Data, ERC721IDData, Fraction, NativeCurrency, NativeCurrencyAmount, NativeCurrencyData, PermitType, Price, ReverseMirageRead, ReverseMirageWrite, Token, TokenData, Tuple, WETH, adjustedPrice, amountAdd, amountDivide, amountEqualTo, amountGreaterThan, amountLessThan, amountMultiply, amountSubtract, amountToNumber, arbitrumGoerliTokens, arbitrumTokens, baseGoerliTokens, baseTokens, celoAlfajoresTokens, celoTokens, createAmountFromFraction, createAmountFromRaw, createAmountFromString, createERC1155, createERC1155Data, createERC20, createERC20Permit, createERC20PermitDataFromFraction, createERC20PermitDataFromRaw, createERC20PermitDataFromString, createERC721, createERC721Data, createERC721IDData, createFraction, createNativeCurrency, createPrice, createPriceFromAmounts, createPriceFromFraction, createWETH, solmateErc1155ABI as erc1155ABI, erc1155BalanceOf, erc1155IsApprovedForAll, erc1155SetApprovalForAll, erc1155Transfer, erc1155TransferBatch, erc1155URI, solmateErc20ABI as erc20ABI, erc20Allowance, erc20Approve, erc20BalanceOf, erc20Decimals, erc20IsPermit, erc20Name, erc20Permit, erc20PermitData, erc20PermitDomainSeparator, erc20PermitNonce, erc20PermitTypedDataHash, erc20SignPermit, erc20Symbol, erc20TotalSupply, erc20Transfer, erc20TransferFrom, solmateErc721ABI as erc721ABI, erc721Approve, erc721BalanceOf, erc721Data, erc721GetApproved, erc721IDData, erc721IsApprovedForAll, erc721Name, erc721OwnerOf, erc721SetApprovalForAll, erc721SupportsInterface, erc721Symbol, erc721TokenURI, erc721Transfer, foundryTokens, fractionAdd, fractionDivide, fractionEqualTo, fractionGreaterThan, fractionInvert, fractionLessThan, fractionMultiply, fractionQuotient, fractionRemainder, fractionSubtract, fractionToNumber, getERC1155, getERC20, getERC20Permit, getERC721, goerliTokens, isAmount, isFraction, isPrice, mainnetTokens, nativeBalance, optimismGoerliTokens, optimismTokens, priceAdd, priceDivide, priceEqualTo, priceGreaterThan, priceInvert, priceLessThan, priceMultiply, priceQuote, priceSubtract, priceToNumber, rawPrice, readAndParse, sepoliaTokens, weth9ABI, wethDeposit, wethWithdraw };

@@ -1,8 +0,3 @@

// src/constants.ts
var MaxUint256 = 2n ** 256n - 1n;
var MaxUint128 = 2n ** 128n - 1n;
var MaxUint64 = 2n ** 64n - 1n;
var MaxUint32 = 2n ** 32n - 1n;
var MaxUint16 = 2n ** 16n - 1n;
var MaxUint8 = 2n ** 8n - 1n;
// src/erc20/reads.ts
import "viem";

@@ -34,3 +29,3 @@ // src/amountUtils.ts

}
return isAmount(b) ? createAmountFromRaw(a.token, a.amount + b.amount) : createAmountFromRaw(a.token, a.amount + scaleUp(a.token, BigInt(b)));
return isAmount(b) ? { ...a, amount: a.amount + b.amount } : { ...a, amount: a.amount + scaleUp(a.token, BigInt(b)) };
};

@@ -41,3 +36,3 @@ var amountSubtract = (a, b) => {

}
return isAmount(b) ? createAmountFromRaw(a.token, a.amount - b.amount) : createAmountFromRaw(a.token, a.amount - scaleUp(a.token, BigInt(b)));
return isAmount(b) ? { ...a, amount: a.amount - b.amount } : { ...a, amount: a.amount - scaleUp(a.token, BigInt(b)) };
};

@@ -48,3 +43,3 @@ var amountMultiply = (a, b) => {

}
return isAmount(b) ? createAmountFromRaw(a.token, scaleDown(a.token, a.amount * b.amount)) : createAmountFromRaw(a.token, a.amount * BigInt(b));
return isAmount(b) ? { ...a, amount: scaleDown(a.token, a.amount * b.amount) } : { ...a, amount: a.amount * BigInt(b) };
};

@@ -55,3 +50,3 @@ var amountDivide = (a, b) => {

}
return isAmount(b) ? createAmountFromRaw(a.token, scaleUp(a.token, a.amount) / b.amount) : createAmountFromRaw(a.token, a.amount / BigInt(b));
return isAmount(b) ? { ...a, amount: scaleUp(a.token, a.amount) / b.amount } : { ...a, amount: a.amount / BigInt(b) };
};

@@ -78,209 +73,161 @@ var amountLessThan = (a, b) => {

// src/fractionUtils.ts
import invariant2 from "tiny-invariant";
var isFraction = (x) => typeof x === "object";
var createFraction = (numerator, denominator = 1) => {
const d = BigInt(denominator);
invariant2(d !== 0n, "Fraction: denominator equal to 0");
return { type: "fraction", numerator: BigInt(numerator), denominator: d };
};
var fractionQuotient = (fraction) => fraction.numerator / fraction.denominator;
var fractionRemainder = (fraction) => fraction.numerator % fraction.denominator;
var fractionInvert = (fraction) => {
invariant2(fraction.numerator !== 0n, "Fraction: denominator equal to 0");
return {
type: "fraction",
numerator: fraction.denominator,
denominator: fraction.numerator
};
};
var fractionAdd = (a, b) => isFraction(b) ? {
type: "fraction",
numerator: a.numerator * b.denominator + b.numerator * a.denominator,
denominator: a.denominator * b.denominator
} : {
type: "fraction",
numerator: a.numerator + a.denominator * BigInt(b),
denominator: a.denominator
};
var fractionSubtract = (a, b) => isFraction(b) ? {
type: "fraction",
numerator: a.numerator * b.denominator - b.numerator * a.denominator,
denominator: a.denominator * b.denominator
} : {
type: "fraction",
numerator: a.numerator - a.denominator * BigInt(b),
denominator: a.denominator
};
var fractionMultiply = (a, b) => isFraction(b) ? {
type: "fraction",
numerator: a.numerator * b.numerator,
denominator: a.denominator * b.denominator
} : {
type: "fraction",
numerator: a.numerator * BigInt(b),
denominator: a.denominator
};
var fractionDivide = (a, b) => isFraction(b) ? {
type: "fraction",
numerator: a.numerator * b.denominator,
denominator: a.denominator * b.numerator
} : {
type: "fraction",
numerator: a.numerator,
denominator: a.denominator * BigInt(b)
};
var fractionLessThan = (a, b) => isFraction(b) ? a.numerator * b.denominator < a.denominator * b.numerator : a.numerator < a.denominator * BigInt(b);
var fractionGreaterThan = (a, b) => isFraction(b) ? a.numerator * b.denominator > a.denominator * b.numerator : a.numerator > a.denominator * BigInt(b);
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);
// src/priceUtils.ts
import invariant3 from "tiny-invariant";
var isPrice = (x) => typeof x === "object";
var createPriceFromFraction = (quote, base, price) => ({
type: "price",
quote,
base,
numerator: quote.decimals ? price.numerator * 10n ** BigInt(quote.decimals) : price.numerator,
denominator: base.decimals ? price.denominator * 10n ** BigInt(base.decimals) : price.denominator
});
var createPriceFromAmounts = (quote, base) => ({
type: "price",
quote: quote.token,
base: base.token,
numerator: base.amount,
denominator: quote.amount
});
var createPrice = (quote, base, numerator, denominator = 1) => ({
type: "price",
quote,
base,
numerator: quote.decimals ? BigInt(numerator) * 10n ** BigInt(quote.decimals) : BigInt(numerator),
denominator: base.decimals ? BigInt(denominator) * 10n ** BigInt(base.decimals) : BigInt(denominator)
});
var priceInvert = (price) => ({
...fractionInvert(rawPrice(price)),
type: "price",
quote: price.base,
base: price.quote
});
var priceAdd = (a, b) => {
if (isPrice(b))
invariant3(a.base === b.base && a.quote === b.quote);
return isPrice(b) ? {
...fractionAdd(rawPrice(a), rawPrice(b)),
type: "price",
quote: a.quote,
base: a.base
} : createPriceFromFraction(
a.quote,
a.base,
fractionAdd(adjustedPrice(a), b)
);
};
var priceSubtract = (a, b) => {
if (isPrice(b))
invariant3(a.base === b.base && a.quote === b.quote);
return isPrice(b) ? {
...fractionSubtract(rawPrice(a), rawPrice(b)),
type: "price",
quote: a.quote,
base: a.base
} : createPriceFromFraction(
a.quote,
a.base,
fractionSubtract(adjustedPrice(a), b)
);
};
var priceMultiply = (a, b) => {
if (isPrice(b))
invariant3(a.base === b.base && a.quote === b.quote);
return isPrice(b) ? {
type: "price",
quote: a.quote,
base: a.base,
numerator: scaleUp(
a.base,
fractionMultiply(rawPrice(a), rawPrice(b)).numerator
),
denominator: scaleUp(
a.quote,
fractionMultiply(rawPrice(a), rawPrice(b)).denominator
)
} : createPriceFromFraction(
a.quote,
a.base,
fractionMultiply(adjustedPrice(a), b)
);
};
var priceDivide = (a, b) => {
if (isPrice(b))
invariant3(a.base === b.base && a.quote === b.quote);
return isPrice(b) ? {
type: "price",
quote: a.quote,
base: a.base,
numerator: scaleUp(
a.quote,
fractionDivide(rawPrice(a), rawPrice(b)).numerator
),
denominator: scaleUp(
a.base,
fractionDivide(rawPrice(a), rawPrice(b)).denominator
)
} : createPriceFromFraction(
a.quote,
a.base,
fractionDivide(adjustedPrice(a), b)
);
};
var priceLessThan = (a, b) => {
if (isPrice(b))
invariant3(a.base === b.base && a.quote === b.quote);
return isPrice(b) ? fractionLessThan(rawPrice(a), rawPrice(b)) : fractionLessThan(adjustedPrice(a), b);
};
var priceEqualTo = (a, b) => {
if (isPrice(b))
invariant3(a.base === b.base && a.quote === b.quote);
return isPrice(b) ? fractionEqualTo(rawPrice(a), rawPrice(b)) : fractionEqualTo(adjustedPrice(a), b);
};
var priceGreaterThan = (a, b) => {
if (isPrice(b))
invariant3(a.base === b.base && a.quote === b.quote);
return isPrice(b) ? fractionGreaterThan(rawPrice(a), rawPrice(b)) : fractionGreaterThan(adjustedPrice(a), b);
};
var priceQuote = (price, amount) => {
invariant3(price.base === amount.token);
return createAmountFromRaw(
price.quote,
price.numerator * amount.amount / price.denominator
);
};
var rawPrice = (price) => ({
type: "fraction",
numerator: price.numerator,
denominator: price.denominator
});
var adjustedPrice = (price) => ({
type: "fraction",
numerator: price.base.decimals ? price.numerator * 10n ** BigInt(price.base.decimals) : price.numerator,
denominator: price.quote.decimals ? price.denominator * 10n ** BigInt(price.quote.decimals) : price.denominator
});
var priceToNumber = (price) => fractionToNumber(adjustedPrice(price));
// src/readUtils.ts
var readAndParse = async (reverseMirageRead) => {
return reverseMirageRead.parse(await reverseMirageRead.read());
};
// src/erc20/reads.ts
import { getAddress } from "viem";
// src/generated.ts
var erc20ABI = [
var weth9ABI = [
{
constant: true,
payable: false,
stateMutability: "view",
type: "function",
inputs: [],
name: "name",
outputs: [{ name: "", type: "string" }]
},
{
constant: false,
payable: false,
stateMutability: "nonpayable",
type: "function",
inputs: [
{ name: "guy", type: "address" },
{ name: "wad", type: "uint256" }
],
name: "approve",
outputs: [{ name: "", type: "bool" }]
},
{
constant: true,
payable: false,
stateMutability: "view",
type: "function",
inputs: [],
name: "totalSupply",
outputs: [{ name: "", type: "uint256" }]
},
{
constant: false,
payable: false,
stateMutability: "nonpayable",
type: "function",
inputs: [
{ name: "src", type: "address" },
{ name: "dst", type: "address" },
{ name: "wad", type: "uint256" }
],
name: "transferFrom",
outputs: [{ name: "", type: "bool" }]
},
{
constant: false,
payable: false,
stateMutability: "nonpayable",
type: "function",
inputs: [{ name: "wad", type: "uint256" }],
name: "withdraw",
outputs: []
},
{
constant: true,
payable: false,
stateMutability: "view",
type: "function",
inputs: [],
name: "decimals",
outputs: [{ name: "", type: "uint8" }]
},
{
constant: true,
payable: false,
stateMutability: "view",
type: "function",
inputs: [{ name: "", type: "address" }],
name: "balanceOf",
outputs: [{ name: "", type: "uint256" }]
},
{
constant: true,
payable: false,
stateMutability: "view",
type: "function",
inputs: [],
name: "symbol",
outputs: [{ name: "", type: "string" }]
},
{
constant: false,
payable: false,
stateMutability: "nonpayable",
type: "function",
inputs: [
{ name: "dst", type: "address" },
{ name: "wad", type: "uint256" }
],
name: "transfer",
outputs: [{ name: "", type: "bool" }]
},
{
constant: false,
payable: true,
stateMutability: "payable",
type: "function",
inputs: [],
name: "deposit",
outputs: []
},
{
constant: true,
payable: false,
stateMutability: "view",
type: "function",
inputs: [
{ name: "", type: "address" },
{ name: "", type: "address" }
],
name: "allowance",
outputs: [{ name: "", type: "uint256" }]
},
{ payable: true, stateMutability: "payable", type: "fallback" },
{
type: "event",
anonymous: false,
inputs: [
{ name: "src", type: "address", indexed: true },
{ name: "guy", type: "address", indexed: true },
{ name: "wad", type: "uint256", indexed: false }
],
name: "Approval"
},
{
type: "event",
anonymous: false,
inputs: [
{ name: "src", type: "address", indexed: true },
{ name: "dst", type: "address", indexed: true },
{ name: "wad", type: "uint256", indexed: false }
],
name: "Transfer"
},
{
type: "event",
anonymous: false,
inputs: [
{ name: "dst", type: "address", indexed: true },
{ name: "wad", type: "uint256", indexed: false }
],
name: "Deposit"
},
{
type: "event",
anonymous: false,
inputs: [
{ name: "src", type: "address", indexed: true },
{ name: "wad", type: "uint256", indexed: false }
],
name: "Withdrawal"
}
];
var solmateErc1155ABI = [
{
type: "event",
anonymous: false,
inputs: [
{

@@ -293,2 +240,164 @@ name: "owner",

{
name: "operator",
internalType: "address",
type: "address",
indexed: true
},
{ name: "approved", internalType: "bool", type: "bool", indexed: false }
],
name: "ApprovalForAll"
},
{
type: "event",
anonymous: false,
inputs: [
{
name: "operator",
internalType: "address",
type: "address",
indexed: true
},
{ name: "from", internalType: "address", type: "address", indexed: true },
{ name: "to", internalType: "address", type: "address", indexed: true },
{
name: "ids",
internalType: "uint256[]",
type: "uint256[]",
indexed: false
},
{
name: "amounts",
internalType: "uint256[]",
type: "uint256[]",
indexed: false
}
],
name: "TransferBatch"
},
{
type: "event",
anonymous: false,
inputs: [
{
name: "operator",
internalType: "address",
type: "address",
indexed: true
},
{ name: "from", internalType: "address", type: "address", indexed: true },
{ name: "to", internalType: "address", type: "address", indexed: true },
{ name: "id", internalType: "uint256", type: "uint256", indexed: false },
{
name: "amount",
internalType: "uint256",
type: "uint256",
indexed: false
}
],
name: "TransferSingle"
},
{
type: "event",
anonymous: false,
inputs: [
{ name: "value", internalType: "string", type: "string", indexed: false },
{ name: "id", internalType: "uint256", type: "uint256", indexed: true }
],
name: "URI"
},
{
stateMutability: "view",
type: "function",
inputs: [
{ name: "", internalType: "address", type: "address" },
{ name: "", internalType: "uint256", type: "uint256" }
],
name: "balanceOf",
outputs: [{ name: "", internalType: "uint256", type: "uint256" }]
},
{
stateMutability: "view",
type: "function",
inputs: [
{ name: "owners", internalType: "address[]", type: "address[]" },
{ name: "ids", internalType: "uint256[]", type: "uint256[]" }
],
name: "balanceOfBatch",
outputs: [
{ name: "balances", internalType: "uint256[]", type: "uint256[]" }
]
},
{
stateMutability: "view",
type: "function",
inputs: [
{ name: "", internalType: "address", type: "address" },
{ name: "", internalType: "address", type: "address" }
],
name: "isApprovedForAll",
outputs: [{ name: "", internalType: "bool", type: "bool" }]
},
{
stateMutability: "nonpayable",
type: "function",
inputs: [
{ name: "from", internalType: "address", type: "address" },
{ name: "to", internalType: "address", type: "address" },
{ name: "ids", internalType: "uint256[]", type: "uint256[]" },
{ name: "amounts", internalType: "uint256[]", type: "uint256[]" },
{ name: "data", internalType: "bytes", type: "bytes" }
],
name: "safeBatchTransferFrom",
outputs: []
},
{
stateMutability: "nonpayable",
type: "function",
inputs: [
{ name: "from", internalType: "address", type: "address" },
{ name: "to", internalType: "address", type: "address" },
{ name: "id", internalType: "uint256", type: "uint256" },
{ name: "amount", internalType: "uint256", type: "uint256" },
{ name: "data", internalType: "bytes", type: "bytes" }
],
name: "safeTransferFrom",
outputs: []
},
{
stateMutability: "nonpayable",
type: "function",
inputs: [
{ name: "operator", internalType: "address", type: "address" },
{ name: "approved", internalType: "bool", type: "bool" }
],
name: "setApprovalForAll",
outputs: []
},
{
stateMutability: "view",
type: "function",
inputs: [{ name: "interfaceId", internalType: "bytes4", type: "bytes4" }],
name: "supportsInterface",
outputs: [{ name: "", internalType: "bool", type: "bool" }]
},
{
stateMutability: "view",
type: "function",
inputs: [{ name: "id", internalType: "uint256", type: "uint256" }],
name: "uri",
outputs: [{ name: "", internalType: "string", type: "string" }]
}
];
var solmateErc20ABI = [
{
type: "event",
anonymous: false,
inputs: [
{
name: "owner",
internalType: "address",
type: "address",
indexed: true
},
{
name: "spender",

@@ -429,8 +538,301 @@ internalType: "address",

];
var solmateErc721ABI = [
{
type: "event",
anonymous: false,
inputs: [
{
name: "owner",
internalType: "address",
type: "address",
indexed: true
},
{
name: "spender",
internalType: "address",
type: "address",
indexed: true
},
{ name: "id", internalType: "uint256", type: "uint256", indexed: true }
],
name: "Approval"
},
{
type: "event",
anonymous: false,
inputs: [
{
name: "owner",
internalType: "address",
type: "address",
indexed: true
},
{
name: "operator",
internalType: "address",
type: "address",
indexed: true
},
{ name: "approved", internalType: "bool", type: "bool", indexed: false }
],
name: "ApprovalForAll"
},
{
type: "event",
anonymous: false,
inputs: [
{ name: "from", internalType: "address", type: "address", indexed: true },
{ name: "to", internalType: "address", type: "address", indexed: true },
{ name: "id", internalType: "uint256", type: "uint256", indexed: true }
],
name: "Transfer"
},
{
stateMutability: "nonpayable",
type: "function",
inputs: [
{ name: "spender", internalType: "address", type: "address" },
{ name: "id", internalType: "uint256", type: "uint256" }
],
name: "approve",
outputs: []
},
{
stateMutability: "view",
type: "function",
inputs: [{ name: "owner", internalType: "address", type: "address" }],
name: "balanceOf",
outputs: [{ name: "", internalType: "uint256", type: "uint256" }]
},
{
stateMutability: "view",
type: "function",
inputs: [{ name: "", internalType: "uint256", type: "uint256" }],
name: "getApproved",
outputs: [{ name: "", internalType: "address", type: "address" }]
},
{
stateMutability: "view",
type: "function",
inputs: [
{ name: "", internalType: "address", type: "address" },
{ name: "", internalType: "address", type: "address" }
],
name: "isApprovedForAll",
outputs: [{ name: "", internalType: "bool", type: "bool" }]
},
{
stateMutability: "view",
type: "function",
inputs: [],
name: "name",
outputs: [{ name: "", internalType: "string", type: "string" }]
},
{
stateMutability: "view",
type: "function",
inputs: [{ name: "id", internalType: "uint256", type: "uint256" }],
name: "ownerOf",
outputs: [{ name: "owner", internalType: "address", type: "address" }]
},
{
stateMutability: "nonpayable",
type: "function",
inputs: [
{ name: "from", internalType: "address", type: "address" },
{ name: "to", internalType: "address", type: "address" },
{ name: "id", internalType: "uint256", type: "uint256" }
],
name: "safeTransferFrom",
outputs: []
},
{
stateMutability: "nonpayable",
type: "function",
inputs: [
{ name: "from", internalType: "address", type: "address" },
{ name: "to", internalType: "address", type: "address" },
{ name: "id", internalType: "uint256", type: "uint256" },
{ name: "data", internalType: "bytes", type: "bytes" }
],
name: "safeTransferFrom",
outputs: []
},
{
stateMutability: "nonpayable",
type: "function",
inputs: [
{ name: "operator", internalType: "address", type: "address" },
{ name: "approved", internalType: "bool", type: "bool" }
],
name: "setApprovalForAll",
outputs: []
},
{
stateMutability: "view",
type: "function",
inputs: [{ name: "interfaceId", internalType: "bytes4", type: "bytes4" }],
name: "supportsInterface",
outputs: [{ name: "", internalType: "bool", type: "bool" }]
},
{
stateMutability: "view",
type: "function",
inputs: [],
name: "symbol",
outputs: [{ name: "", internalType: "string", type: "string" }]
},
{
stateMutability: "view",
type: "function",
inputs: [{ name: "id", internalType: "uint256", type: "uint256" }],
name: "tokenURI",
outputs: [{ name: "", internalType: "string", type: "string" }]
},
{
stateMutability: "nonpayable",
type: "function",
inputs: [
{ name: "from", internalType: "address", type: "address" },
{ name: "to", internalType: "address", type: "address" },
{ name: "id", internalType: "uint256", type: "uint256" }
],
name: "transferFrom",
outputs: []
}
];
// src/erc20/utils.ts
import { getAddress, hashTypedData } from "viem";
var createERC20 = (address, name, symbol, decimals, chainID, blockCreated = 0n) => ({
type: "erc20",
address: getAddress(address),
name,
symbol,
decimals,
chainID,
blockCreated
});
var createERC20Permit = (address, name, symbol, decimals, version, chainID, blockCreated = 0n) => ({
type: "erc20Permit",
address: getAddress(address),
name,
symbol,
decimals,
version,
chainID,
blockCreated
});
var createERC20PermitDataFromString = (erc20Permit2, amount, nonce) => ({
...createAmountFromString(erc20Permit2, amount),
type: `${erc20Permit2.type}Data`,
nonce
});
var createERC20PermitDataFromFraction = (erc20Permit2, amount, nonce) => ({
...createAmountFromFraction(erc20Permit2, amount),
type: `${erc20Permit2.type}Data`,
nonce
});
var createERC20PermitDataFromRaw = (erc20Permit2, amount, nonce) => ({
...createAmountFromRaw(erc20Permit2, amount),
type: `${erc20Permit2.type}Data`,
nonce
});
var PermitType = {
Permit: [
{
name: "owner",
type: "address"
},
{ name: "spender", type: "address" },
{ name: "value", type: "uint256" },
{ name: "nonce", type: "uint256" },
{ name: "deadline", type: "uint256" }
]
};
var erc20PermitTypedDataHash = (permit) => {
const domain = {
name: permit.amount.token.name,
version: permit.amount.token.version,
chainId: permit.amount.token.chainID,
verifyingContract: permit.amount.token.address
};
return hashTypedData({
domain,
types: PermitType,
primaryType: "Permit",
message: {
owner: permit.owner,
spender: permit.spender,
value: permit.amount.amount,
nonce: permit.amount.nonce,
deadline: permit.deadline
}
});
};
// src/erc20/reads.ts
var erc20BalanceOf = (publicClient, args) => {
return {
read: () => publicClient.readContract({
abi: erc20ABI,
var erc20BalanceOf = (args) => ({
read: (publicClient) => publicClient.readContract({
abi: solmateErc20ABI,
address: args.erc20.address,
functionName: "balanceOf",
args: [args.address]
}),
parse: (data) => createAmountFromRaw(args.erc20, data)
});
var erc20Allowance = (args) => ({
read: (publicClient) => publicClient.readContract({
abi: solmateErc20ABI,
address: args.erc20.address,
functionName: "allowance",
args: [args.address, args.spender]
}),
parse: (data) => createAmountFromRaw(args.erc20, data)
});
var erc20TotalSupply = (args) => ({
read: (publicClient) => publicClient.readContract({
abi: solmateErc20ABI,
address: args.erc20.address,
functionName: "totalSupply"
}),
parse: (data) => createAmountFromRaw(args.erc20, data)
});
var erc20Name = (args) => ({
read: (publicClient) => publicClient.readContract({
abi: solmateErc20ABI,
address: args.erc20.address,
functionName: "name"
}),
parse: (data) => data
});
var erc20Symbol = (args) => ({
read: (publicClient) => publicClient.readContract({
abi: solmateErc20ABI,
address: args.erc20.address,
functionName: "symbol"
}),
parse: (data) => data
});
var erc20Decimals = (args) => ({
read: (publicClient) => publicClient.readContract({
abi: solmateErc20ABI,
address: args.erc20.address,
functionName: "decimals"
}),
parse: (data) => data
});
var erc20PermitNonce = (args) => ({
read: (publicClient) => publicClient.readContract({
abi: solmateErc20ABI,
address: args.erc20.address,
functionName: "nonces",
args: [args.address]
}),
parse: (data) => data
});
var erc20PermitData = (args) => ({
read: (publicClient) => Promise.all([
publicClient.readContract({
abi: solmateErc20ABI,
address: args.erc20.address,

@@ -440,109 +842,88 @@ functionName: "balanceOf",

}),
parse: (data) => createAmountFromRaw(args.erc20, data)
};
};
var erc20Allowance = (publicClient, args) => {
return {
read: () => publicClient.readContract({
abi: erc20ABI,
publicClient.readContract({
abi: solmateErc20ABI,
address: args.erc20.address,
functionName: "allowance",
args: [args.address, args.spender]
}),
parse: (data) => createAmountFromRaw(args.erc20, data)
};
};
var erc20TotalSupply = (publicClient, args) => {
return {
read: () => publicClient.readContract({
abi: erc20ABI,
address: args.erc20.address,
functionName: "totalSupply"
}),
parse: (data) => createAmountFromRaw(args.erc20, data)
};
};
var erc20Name = (publicClient, args) => {
return {
read: () => publicClient.readContract({
abi: erc20ABI,
address: args.erc20.address,
functionName: "name"
}),
parse: (data) => data
};
};
var erc20Symbol = (publicClient, args) => {
return {
read: () => publicClient.readContract({
abi: erc20ABI,
address: args.erc20.address,
functionName: "symbol"
}),
parse: (data) => data
};
};
var erc20Decimals = (publicClient, args) => {
return {
read: () => publicClient.readContract({
abi: erc20ABI,
address: args.erc20.address,
functionName: "decimals"
}),
parse: (data) => data
};
};
var getErc20 = (publicClient, args) => {
return {
read: () => Promise.all([
erc20Name(publicClient, args).read(),
erc20Symbol(publicClient, args).read(),
erc20Decimals(publicClient, args).read()
]),
parse: (data) => ({
type: "erc20",
name: data[0],
symbol: data[1],
decimals: data[2],
address: getAddress(args.erc20.address),
chainID: args.erc20.chainID
functionName: "nonces",
args: [args.address]
})
};
};
var getErc20Permit = (publicClient, args) => {
return {
read: () => Promise.all([
erc20Name(publicClient, args).read(),
erc20Symbol(publicClient, args).read(),
erc20Decimals(publicClient, args).read()
]),
parse: (data) => ({
type: "erc20",
name: data[0],
symbol: data[1],
decimals: data[2],
address: getAddress(args.erc20.address),
chainID: args.erc20.chainID,
version: args.erc20.version ?? "1"
})
};
};
// src/erc20/utils.ts
import { getAddress as getAddress2, hashTypedData } from "viem";
var createErc20 = (address, name, symbol, decimals, chainID) => ({
type: "erc20",
address: getAddress2(address),
name,
symbol,
decimals,
chainID
]),
parse: (data) => createERC20PermitDataFromRaw(args.erc20, data[0], data[1])
});
var erc20PermitDomainSeparator = (args) => ({
read: (publicClient) => publicClient.readContract({
abi: solmateErc20ABI,
address: args.erc20.address,
functionName: "DOMAIN_SEPARATOR"
}),
parse: (data) => data
});
var getERC20 = (args) => ({
read: (publicClient) => Promise.all([
erc20Name(args).read(publicClient),
erc20Symbol(args).read(publicClient),
erc20Decimals(args).read(publicClient)
]),
parse: (data) => createERC20(
args.erc20.address,
data[0],
data[1],
data[2],
args.erc20.chainID,
args.erc20.blockCreated
)
});
var getERC20Permit = (args) => ({
read: (publicClient) => Promise.all([
erc20Name(args).read(publicClient),
erc20Symbol(args).read(publicClient),
erc20Decimals(args).read(publicClient)
]),
parse: (data) => createERC20Permit(
args.erc20.address,
data[0],
data[1],
data[2],
args.erc20.version ?? "1",
args.erc20.chainID,
args.erc20.blockCreated
)
});
var erc20IsPermit = (args) => ({
read: async (publicClient) => {
try {
return await Promise.all([
getERC20(args).read(publicClient),
erc20PermitDomainSeparator(args).read(publicClient)
]);
} catch {
return await Promise.all([getERC20(args).read(publicClient)]);
}
},
parse: (data) => data.length === 1 ? createERC20(
args.erc20.address,
data[0][0],
data[0][1],
data[0][2],
args.erc20.chainID,
args.erc20.blockCreated
) : createERC20Permit(
args.erc20.address,
data[0][0],
data[0][1],
data[0][2],
args.erc20.version ?? "1",
args.erc20.chainID,
args.erc20.blockCreated
)
});
// src/erc20/writes.ts
import invariant4 from "tiny-invariant";
import invariant2 from "tiny-invariant";
import {
getAddress as getAddress2
} from "viem";
var erc20Transfer = async (publicClient, walletClient, account, args) => {
const { request, result } = await publicClient.simulateContract({
address: args.amount.token.address,
abi: erc20ABI,
abi: solmateErc20ABI,
functionName: "transfer",

@@ -558,3 +939,3 @@ args: [args.to, args.amount.amount],

address: args.amount.token.address,
abi: erc20ABI,
abi: solmateErc20ABI,
functionName: "approve",

@@ -570,5 +951,5 @@ args: [args.spender, args.amount.amount],

address: args.amount.token.address,
abi: erc20ABI,
abi: solmateErc20ABI,
functionName: "transferFrom",
args: [args.to, args.from, args.amount.amount],
args: [args.from, args.to, args.amount.amount],
account

@@ -579,11 +960,360 @@ });

};
// src/native/reads.ts
var nativeBalance = (publicClient, args) => {
return {
read: () => publicClient.getBalance({ address: args.address }),
parse: (data) => createAmountFromRaw(args.nativeCurrency, data)
var erc20SignPermit = async (walletClient, account, permit) => {
const domain = {
name: permit.permitData.token.name,
version: permit.permitData.token.version,
chainId: permit.permitData.token.chainID,
verifyingContract: getAddress2(permit.permitData.token.address)
};
return walletClient.signTypedData({
domain,
account,
types: PermitType,
primaryType: "Permit",
message: {
owner: permit.owner,
spender: permit.spender,
value: permit.permitData.amount,
deadline: permit.deadline,
nonce: permit.permitData.nonce
}
});
};
var erc20Permit = async (publicClient, walletClient, account, args) => {
invariant2(args.signature.length === 132, "Invalid signature length");
const r = `0x${args.signature.substring(2, 2 + 64)}`;
const s = `0x${args.signature.substring(2 + 64, 2 + 64 + 64)}`;
const v = Number(`0x${args.signature.substring(2 + 64 + 64)}`);
const { request, result } = await publicClient.simulateContract({
address: args.permitData.token.address,
abi: solmateErc20ABI,
functionName: "permit",
args: [
args.owner,
args.spender,
args.permitData.amount,
args.deadline,
v,
r,
s
],
account
});
const hash = await walletClient.writeContract(request);
return { hash, result, request };
};
// src/erc721/reads.ts
import { getAddress as getAddress4 } from "viem";
// src/erc721/utils.ts
import { getAddress as getAddress3 } from "viem";
var createERC721 = (address, name, symbol, id, tokenURI, chainID, blockCreated = 0n) => ({
type: "erc721",
address: getAddress3(address),
name,
symbol,
id,
tokenURI,
chainID,
blockCreated
});
var createERC721IDData = (erc721, owned) => ({
type: `${erc721.type}IDData`,
token: erc721,
owned
});
var createERC721Data = (erc721, balance, ids) => ({
type: `${erc721.type}Data`,
token: erc721,
balance,
ids
});
// src/erc721/reads.ts
var erc721Name = (args) => ({
read: (publicClient) => publicClient.readContract({
abi: solmateErc721ABI,
address: args.erc721.address,
functionName: "name"
}),
parse: (data) => data
});
var erc721Symbol = (args) => ({
read: (publicClient) => publicClient.readContract({
abi: solmateErc721ABI,
address: args.erc721.address,
functionName: "symbol"
}),
parse: (data) => data
});
var erc721TokenURI = (args) => ({
read: (publicClient) => publicClient.readContract({
abi: solmateErc721ABI,
address: args.erc721.address,
functionName: "tokenURI",
args: [args.erc721.id]
}),
parse: (data) => data
});
var erc721OwnerOf = (args) => ({
read: (publicClient) => publicClient.readContract({
abi: solmateErc721ABI,
address: args.erc721.address,
functionName: "ownerOf",
args: [args.erc721.id]
}),
parse: (data) => data
});
var erc721BalanceOf = (args) => ({
read: (publicClient) => publicClient.readContract({
abi: solmateErc721ABI,
address: args.erc721.address,
functionName: "balanceOf",
args: [args.owner]
}),
parse: (data) => data
});
var erc721GetApproved = (args) => ({
read: (publicClient) => publicClient.readContract({
abi: solmateErc721ABI,
address: args.erc721.address,
functionName: "getApproved",
args: [args.erc721.id]
}),
parse: (data) => data
});
var erc721IsApprovedForAll = (args) => ({
read: (publicClient) => publicClient.readContract({
abi: solmateErc721ABI,
address: args.erc721.address,
functionName: "isApprovedForAll",
args: [args.owner, args.spender]
}),
parse: (data) => data
});
var erc721SupportsInterface = (args) => ({
read: (publicClient) => publicClient.readContract({
abi: solmateErc721ABI,
address: args.erc721.address,
functionName: "supportsInterface",
args: [args.interfaceID]
}),
parse: (data) => data
});
var getERC721 = (args) => ({
read: (publicClient) => Promise.all([
erc721Name(args).read(publicClient),
erc721Symbol(args).read(publicClient),
erc721TokenURI(args).read(publicClient)
]),
parse: (data) => createERC721(
args.erc721.address,
data[0],
data[1],
args.erc721.id,
data[2],
args.erc721.chainID,
args.erc721.blockCreated
)
});
var erc721IDData = (args) => ({
read: (publicClient) => erc721OwnerOf({ erc721: args.erc721 }).read(publicClient),
parse: (data) => createERC721IDData(
args.erc721,
getAddress4(data) === getAddress4(args.owner)
)
});
var erc721Data = (args) => ({
read: (publicClient) => erc721BalanceOf(args).read(publicClient),
parse: (data) => {
if (data > Number.MAX_SAFE_INTEGER)
throw Error("balance exceeds maximum representable number");
return createERC721Data(args.erc721, Number(data));
}
});
// src/erc721/writes.ts
var erc721Transfer = async (publicClient, walletClient, account, args) => {
if (args.data === void 0) {
const { request, result } = await publicClient.simulateContract({
address: args.erc721.address,
abi: solmateErc721ABI,
functionName: "transferFrom",
args: [args.from, args.to, args.erc721.id],
account
});
const hash = await walletClient.writeContract(request);
return { hash, result, request };
} else if (args.data === "safe") {
const { request, result } = await publicClient.simulateContract({
address: args.erc721.address,
abi: solmateErc721ABI,
functionName: "safeTransferFrom",
args: [args.from, args.to, args.erc721.id],
account
});
const hash = await walletClient.writeContract(request);
return { hash, result, request };
} else {
const { request, result } = await publicClient.simulateContract({
address: args.erc721.address,
abi: solmateErc721ABI,
functionName: "safeTransferFrom",
args: [args.from, args.to, args.erc721.id, args.data],
account
});
const hash = await walletClient.writeContract(request);
return { hash, result, request };
}
};
var erc721Approve = async (publicClient, walletClient, account, args) => {
const { request, result } = await publicClient.simulateContract({
address: args.erc721.address,
abi: solmateErc721ABI,
functionName: "approve",
args: [args.spender, args.erc721.id],
account
});
const hash = await walletClient.writeContract(request);
return { hash, result, request };
};
var erc721SetApprovalForAll = async (publicClient, walletClient, account, args) => {
const { request, result } = await publicClient.simulateContract({
address: args.erc721.address,
abi: solmateErc721ABI,
functionName: "setApprovalForAll",
args: [args.spender, args.approved],
account
});
const hash = await walletClient.writeContract(request);
return { hash, result, request };
};
// src/erc1155/utils.ts
import { getAddress as getAddress5 } from "viem";
var createERC1155 = (address, id, uri, chainID, blockCreated = 0n) => ({
type: "erc1155",
address: getAddress5(address),
id,
uri,
chainID,
blockCreated
});
var createERC1155Data = (erc1155, amount) => ({
type: `${erc1155.type}Data`,
token: erc1155,
amount
});
// src/erc1155/reads.ts
var erc1155IsApprovedForAll = (args) => ({
read: (publicClient) => publicClient.readContract({
abi: solmateErc1155ABI,
address: args.erc1155.address,
functionName: "isApprovedForAll",
args: [args.owner, args.spender]
}),
parse: (data) => data
});
var erc1155URI = (args) => ({
read: (publicClient) => publicClient.readContract({
abi: solmateErc1155ABI,
address: args.erc1155.address,
functionName: "uri",
args: [args.erc1155.id]
}),
parse: (data) => data
});
var erc1155BalanceOf = (args) => ({
read: (publicClient) => publicClient.readContract({
abi: solmateErc1155ABI,
address: args.erc1155.address,
functionName: "balanceOf",
args: [args.owner, args.erc1155.id]
}),
parse: (data) => createERC1155Data(args.erc1155, data)
});
var getERC1155 = (args) => ({
read: (publicClient) => publicClient.readContract({
abi: solmateErc1155ABI,
address: args.erc1155.address,
functionName: "uri",
args: [args.erc1155.id]
}),
parse: (data) => createERC1155(
args.erc1155.address,
args.erc1155.id,
data,
args.erc1155.chainID,
args.erc1155.blockCreated
)
});
// src/erc1155/writes.ts
import {
getAddress as getAddress6
} from "viem";
var erc1155SetApprovalForAll = async (publicClient, walletClient, account, args) => {
const { request, result } = await publicClient.simulateContract({
address: args.erc1155.address,
abi: solmateErc1155ABI,
functionName: "setApprovalForAll",
args: [args.spender, args.approved],
account
});
const hash = await walletClient.writeContract(request);
return { hash, result, request };
};
var erc1155Transfer = async (publicClient, walletClient, account, args) => {
const { request, result } = await publicClient.simulateContract({
address: args.erc1155.token.address,
abi: solmateErc1155ABI,
functionName: "safeTransferFrom",
args: [
args.from,
args.to,
args.erc1155.token.id,
args.erc1155.amount,
args.data ?? "0x"
],
account
});
const hash = await walletClient.writeContract(request);
return { hash, result, request };
};
var erc1155TransferBatch = async (publicClient, walletClient, account, args) => {
const address = args.erc1155.reduce((addr, cur) => {
if (addr === void 0)
return getAddress6(cur.token.address);
else if (addr !== getAddress6(cur.token.address))
throw Error("Tokens refering to different addresses");
else
return addr;
}, void 0);
if (address === void 0)
throw Error("No tokens passed to transfer");
const { request, result } = await publicClient.simulateContract({
address,
abi: solmateErc1155ABI,
functionName: "safeBatchTransferFrom",
args: [
args.from,
args.to,
args.erc1155.map((t) => t.token.id),
args.erc1155.map((t) => t.amount),
args.data ?? "0x"
],
account
});
const hash = await walletClient.writeContract(request);
return { hash, result, request };
};
// src/native/reads.ts
var nativeBalance = (args) => ({
read: (publicClient) => publicClient.getBalance({ address: args.address }),
parse: (data) => createAmountFromRaw(args.nativeCurrency, data)
});
// src/native/utils.ts

@@ -597,9 +1327,329 @@ var createNativeCurrency = (name, symbol, decimals, chainID) => ({

});
// src/weth/utils.ts
import { getAddress as getAddress7 } from "viem";
var createWETH = (address, name, symbol, decimals, chainID, blockCreated = 0n) => ({
type: "weth",
address: getAddress7(address),
name,
symbol,
decimals,
chainID,
blockCreated
});
// src/weth/writes.ts
var wethDeposit = async (publicClient, walletClient, account, args) => {
const { request, result } = await publicClient.simulateContract({
address: args.amount.token.address,
abi: weth9ABI,
functionName: "deposit",
account,
value: args.amount.amount
});
const hash = await walletClient.writeContract(request);
return { hash, result, request };
};
var wethWithdraw = async (publicClient, walletClient, account, args) => {
const { request, result } = await publicClient.simulateContract({
address: args.amount.token.address,
abi: weth9ABI,
functionName: "withdraw",
account,
args: [args.amount.amount]
});
const hash = await walletClient.writeContract(request);
return { hash, result, request };
};
// src/readUtils.ts
var readAndParse = async (publicClient, reverseMirageRead) => {
return reverseMirageRead.parse(await reverseMirageRead.read(publicClient));
};
// src/fractionUtils.ts
import invariant3 from "tiny-invariant";
var isFraction = (x) => typeof x === "object";
var createFraction = (numerator, denominator = 1) => {
const d = BigInt(denominator);
invariant3(d !== 0n, "Fraction: denominator equal to 0");
return { type: "fraction", numerator: BigInt(numerator), denominator: d };
};
var fractionQuotient = (fraction) => fraction.numerator / fraction.denominator;
var fractionRemainder = (fraction) => fraction.numerator % fraction.denominator;
var fractionInvert = (fraction) => {
invariant3(fraction.numerator !== 0n, "Fraction: denominator equal to 0");
return {
type: "fraction",
numerator: fraction.denominator,
denominator: fraction.numerator
};
};
var fractionAdd = (a, b) => isFraction(b) ? {
type: "fraction",
numerator: a.numerator * b.denominator + b.numerator * a.denominator,
denominator: a.denominator * b.denominator
} : {
type: "fraction",
numerator: a.numerator + a.denominator * BigInt(b),
denominator: a.denominator
};
var fractionSubtract = (a, b) => isFraction(b) ? {
type: "fraction",
numerator: a.numerator * b.denominator - b.numerator * a.denominator,
denominator: a.denominator * b.denominator
} : {
type: "fraction",
numerator: a.numerator - a.denominator * BigInt(b),
denominator: a.denominator
};
var fractionMultiply = (a, b) => isFraction(b) ? {
type: "fraction",
numerator: a.numerator * b.numerator,
denominator: a.denominator * b.denominator
} : {
type: "fraction",
numerator: a.numerator * BigInt(b),
denominator: a.denominator
};
var fractionDivide = (a, b) => isFraction(b) ? {
type: "fraction",
numerator: a.numerator * b.denominator,
denominator: a.denominator * b.numerator
} : {
type: "fraction",
numerator: a.numerator,
denominator: a.denominator * BigInt(b)
};
var fractionLessThan = (a, b) => isFraction(b) ? a.numerator * b.denominator < a.denominator * b.numerator : a.numerator < a.denominator * BigInt(b);
var fractionGreaterThan = (a, b) => isFraction(b) ? a.numerator * b.denominator > a.denominator * b.numerator : a.numerator > a.denominator * BigInt(b);
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);
// src/priceUtils.ts
import invariant4 from "tiny-invariant";
var isPrice = (x) => typeof x === "object";
var createPriceFromFraction = (quote, base, price) => ({
type: "price",
quote,
base,
numerator: quote.decimals ? price.numerator * 10n ** BigInt(quote.decimals) : price.numerator,
denominator: base.decimals ? price.denominator * 10n ** BigInt(base.decimals) : price.denominator
});
var createPriceFromAmounts = (quote, base) => ({
type: "price",
quote: quote.token,
base: base.token,
numerator: base.amount,
denominator: quote.amount
});
var createPrice = (quote, base, numerator, denominator = 1) => ({
type: "price",
quote,
base,
numerator: quote.decimals ? BigInt(numerator) * 10n ** BigInt(quote.decimals) : BigInt(numerator),
denominator: base.decimals ? BigInt(denominator) * 10n ** BigInt(base.decimals) : BigInt(denominator)
});
var priceInvert = (price) => ({
...fractionInvert(rawPrice(price)),
type: "price",
quote: price.base,
base: price.quote
});
var priceAdd = (a, b) => {
if (isPrice(b))
invariant4(a.base === b.base && a.quote === b.quote);
return isPrice(b) ? {
...fractionAdd(rawPrice(a), rawPrice(b)),
type: "price",
quote: a.quote,
base: a.base
} : createPriceFromFraction(
a.quote,
a.base,
fractionAdd(adjustedPrice(a), b)
);
};
var priceSubtract = (a, b) => {
if (isPrice(b))
invariant4(a.base === b.base && a.quote === b.quote);
return isPrice(b) ? {
...fractionSubtract(rawPrice(a), rawPrice(b)),
type: "price",
quote: a.quote,
base: a.base
} : createPriceFromFraction(
a.quote,
a.base,
fractionSubtract(adjustedPrice(a), b)
);
};
var priceMultiply = (a, b) => {
if (isPrice(b))
invariant4(a.base === b.base && a.quote === b.quote);
return isPrice(b) ? {
type: "price",
quote: a.quote,
base: a.base,
numerator: scaleUp(
a.base,
fractionMultiply(rawPrice(a), rawPrice(b)).numerator
),
denominator: scaleUp(
a.quote,
fractionMultiply(rawPrice(a), rawPrice(b)).denominator
)
} : createPriceFromFraction(
a.quote,
a.base,
fractionMultiply(adjustedPrice(a), b)
);
};
var priceDivide = (a, b) => {
if (isPrice(b))
invariant4(a.base === b.base && a.quote === b.quote);
return isPrice(b) ? {
type: "price",
quote: a.quote,
base: a.base,
numerator: scaleUp(
a.quote,
fractionDivide(rawPrice(a), rawPrice(b)).numerator
),
denominator: scaleUp(
a.base,
fractionDivide(rawPrice(a), rawPrice(b)).denominator
)
} : createPriceFromFraction(
a.quote,
a.base,
fractionDivide(adjustedPrice(a), b)
);
};
var priceLessThan = (a, b) => {
if (isPrice(b))
invariant4(a.base === b.base && a.quote === b.quote);
return isPrice(b) ? fractionLessThan(rawPrice(a), rawPrice(b)) : fractionLessThan(adjustedPrice(a), b);
};
var priceEqualTo = (a, b) => {
if (isPrice(b))
invariant4(a.base === b.base && a.quote === b.quote);
return isPrice(b) ? fractionEqualTo(rawPrice(a), rawPrice(b)) : fractionEqualTo(adjustedPrice(a), b);
};
var priceGreaterThan = (a, b) => {
if (isPrice(b))
invariant4(a.base === b.base && a.quote === b.quote);
return isPrice(b) ? fractionGreaterThan(rawPrice(a), rawPrice(b)) : fractionGreaterThan(adjustedPrice(a), b);
};
var priceQuote = (price, amount) => {
invariant4(price.base === amount.token);
return createAmountFromRaw(
price.quote,
price.numerator * amount.amount / price.denominator
);
};
var rawPrice = (price) => ({
type: "fraction",
numerator: price.numerator,
denominator: price.denominator
});
var adjustedPrice = (price) => ({
type: "fraction",
numerator: price.base.decimals ? price.numerator * 10n ** BigInt(price.base.decimals) : price.numerator,
denominator: price.quote.decimals ? price.denominator * 10n ** BigInt(price.quote.decimals) : price.denominator
});
var priceToNumber = (price) => fractionToNumber(adjustedPrice(price));
// src/constants.ts
var mainnetTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 1),
weth: createWETH(
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"Wrapped Ether",
"WETH",
18,
1,
4719568n
)
};
var sepoliaTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 11155111)
};
var goerliTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 5),
weth: createWETH(
"0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6",
"Wrapped Ether",
"WETH",
18,
5,
1036651n
)
};
var optimismTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 10),
weth: createWETH(
"0x4200000000000000000000000000000000000006",
"Wrapped Ether",
"WETH",
18,
10
)
};
var optimismGoerliTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 420)
};
var arbitrumTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 42161),
weth: createWETH(
"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
"Wrapped Ether",
"WETH",
18,
42161,
55n
)
};
var arbitrumGoerliTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 421613)
};
var baseTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 8453),
weth: createWETH(
"0x4200000000000000000000000000000000000006",
"Wrapped Ether",
"WETH",
18,
8453
)
};
var baseGoerliTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 84531)
};
var celoTokens = {
native: createNativeCurrency("Celo Native Asset", "CELO", 18, 42220),
weth: createWETH(
"0x471EcE3750Da237f93B8E339c536989b8978a438",
"Celo Native Asset",
"CELO",
18,
42220,
2919n
)
};
var celoAlfajoresTokens = {
native: createNativeCurrency("Celo Native Asset", "CELO", 18, 44787),
weth: createWETH(
"0xF194afDf50B03e69Bd7D057c1Aa9e10c9954E4C9",
"Celo Native Asset",
"CELO",
18,
44787
)
};
var foundryTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 31337)
};
export {
MaxUint128,
MaxUint16,
MaxUint256,
MaxUint32,
MaxUint64,
MaxUint8,
PermitType,
adjustedPrice,

@@ -614,6 +1664,21 @@ amountAdd,

amountToNumber,
arbitrumGoerliTokens,
arbitrumTokens,
baseGoerliTokens,
baseTokens,
celoAlfajoresTokens,
celoTokens,
createAmountFromFraction,
createAmountFromRaw,
createAmountFromString,
createErc20,
createERC1155,
createERC1155Data,
createERC20,
createERC20Permit,
createERC20PermitDataFromFraction,
createERC20PermitDataFromRaw,
createERC20PermitDataFromString,
createERC721,
createERC721Data,
createERC721IDData,
createFraction,

@@ -624,3 +1689,11 @@ createNativeCurrency,

createPriceFromFraction,
erc20ABI,
createWETH,
solmateErc1155ABI as erc1155ABI,
erc1155BalanceOf,
erc1155IsApprovedForAll,
erc1155SetApprovalForAll,
erc1155Transfer,
erc1155TransferBatch,
erc1155URI,
solmateErc20ABI as erc20ABI,
erc20Allowance,

@@ -630,3 +1703,10 @@ erc20Approve,

erc20Decimals,
erc20IsPermit,
erc20Name,
erc20Permit,
erc20PermitData,
erc20PermitDomainSeparator,
erc20PermitNonce,
erc20PermitTypedDataHash,
erc20SignPermit,
erc20Symbol,

@@ -636,2 +1716,17 @@ erc20TotalSupply,

erc20TransferFrom,
solmateErc721ABI as erc721ABI,
erc721Approve,
erc721BalanceOf,
erc721Data,
erc721GetApproved,
erc721IDData,
erc721IsApprovedForAll,
erc721Name,
erc721OwnerOf,
erc721SetApprovalForAll,
erc721SupportsInterface,
erc721Symbol,
erc721TokenURI,
erc721Transfer,
foundryTokens,
fractionAdd,

@@ -648,8 +1743,14 @@ fractionDivide,

fractionToNumber,
getErc20,
getErc20Permit,
getERC1155,
getERC20,
getERC20Permit,
getERC721,
goerliTokens,
isAmount,
isFraction,
isPrice,
mainnetTokens,
nativeBalance,
optimismGoerliTokens,
optimismTokens,
priceAdd,

@@ -666,4 +1767,8 @@ priceDivide,

rawPrice,
readAndParse
readAndParse,
sepoliaTokens,
weth9ABI,
wethDeposit,
wethWithdraw
};
//# sourceMappingURL=index.js.map

21

package.json
{
"name": "reverse-mirage",
"version": "0.1.9",
"version": "0.1.11",
"description": "Application level typescript utilities for Ethereum",

@@ -35,15 +35,2 @@ "type": "module",

},
"size-limit": [
{
"name": "reverse-mirage (cjs)",
"path": "./dist/index.cjs",
"limit": "25 kB"
},
{
"name": "reverse-mirage",
"path": "./dist/index.js",
"limit": "20 kB",
"import": "*"
}
],
"dependencies": {

@@ -59,2 +46,3 @@ "tiny-invariant": "^1.3.1"

"@viem/anvil": "^0.0.6",
"@vitest/coverage-v8": "^0.34.4",
"bun": "^1.0.0",

@@ -64,3 +52,3 @@ "mitata": "^0.1.6",

"typescript": "^5.2.2",
"viem": "^1.10.8",
"viem": "^1.10.9",
"vitest": "^0.34.4"

@@ -76,4 +64,5 @@ },

"test": "vitest",
"test:ci": "CI=true vitest"
"test:ci": "CI=true vitest --coverage",
"test:cov": "vitest --coverage"
}
}

@@ -5,6 +5,7 @@ import invariant from "tiny-invariant";

export type Amount<TToken extends Token = Token> = TokenData<
TToken & { decimals?: number },
{ amount: bigint }
>;
export type Amount<
TToken extends Token & { decimals?: number } = Token & { decimals?: number },
TType extends `${TToken["type"]}${string}` = `${TToken["type"]}${string}`,
TData extends { amount: bigint } = { amount: bigint },
> = TokenData<TToken, TType, TData>;

@@ -17,2 +18,5 @@ export const scaleUp = (token: Amount["token"], amount: bigint) =>

/**
* Returns true if {@link x} is of type {@link Amount}
*/
export const isAmount = <TAmount extends Amount>(

@@ -22,6 +26,9 @@ x: TAmount | BigIntIsh,

/**
* Creates a {@link Amount} from a {@link token} and a string
*/
export const createAmountFromString = <TToken extends Amount["token"]>(
token: TToken,
amount: string,
): Amount<TToken> => ({
): Amount<TToken, `${TToken["type"]}Amount`> => ({
type: `${token.type}Amount`,

@@ -32,6 +39,9 @@ token,

/**
* Creates a {@link Amount} from a {@link token} and a {@link Fraction}
*/
export const createAmountFromFraction = <TToken extends Amount["token"]>(
token: TToken,
amount: Fraction,
): Amount<TToken> => ({
): Amount<TToken, `${TToken["type"]}Amount`> => ({
type: `${token.type}Amount`,

@@ -42,6 +52,9 @@ token,

/**
* Creates a {@link Amount} from a {@link token} and a {@link amount}
*/
export const createAmountFromRaw = <TToken extends Amount["token"]>(
token: TToken,
amount: bigint,
): Amount<TToken> => ({
): Amount<TToken, `${TToken["type"]}Amount`> => ({
type: `${token.type}Amount`,

@@ -52,6 +65,11 @@ token,

export const amountAdd = <TToken extends Amount["token"]>(
a: Amount<TToken>,
b: Amount<TToken> | BigIntIsh,
): Amount<TToken> => {
/**
* Adds {@link a} with {@link b}
*/
export const amountAdd = <TAmount extends Amount>(
a: TAmount,
b: TAmount extends Amount<TAmount["token"], infer TType>
? Amount<TAmount["token"], TType> | BigIntIsh
: never,
): Omit<TAmount, "amount"> & { amount: bigint } => {
if (isAmount(b)) {

@@ -62,10 +80,15 @@ invariant(a.token === b.token);

return isAmount(b)
? createAmountFromRaw(a.token, a.amount + b.amount)
: createAmountFromRaw(a.token, a.amount + scaleUp(a.token, BigInt(b)));
? { ...a, amount: a.amount + b.amount }
: { ...a, amount: a.amount + scaleUp(a.token, BigInt(b)) };
};
export const amountSubtract = <TToken extends Amount["token"]>(
a: Amount<TToken>,
b: Amount<TToken> | BigIntIsh,
): Amount<TToken> => {
/**
* Subtracts {@link a} by {@link b}
*/
export const amountSubtract = <TAmount extends Amount>(
a: TAmount,
b: TAmount extends Amount<TAmount["token"], infer TType>
? Amount<TAmount["token"], TType> | BigIntIsh
: never,
): Omit<TAmount, "amount"> & { amount: bigint } => {
if (isAmount(b)) {

@@ -76,10 +99,15 @@ invariant(a.token === b.token);

return isAmount(b)
? createAmountFromRaw(a.token, a.amount - b.amount)
: createAmountFromRaw(a.token, a.amount - scaleUp(a.token, BigInt(b)));
? { ...a, amount: a.amount - b.amount }
: { ...a, amount: a.amount - scaleUp(a.token, BigInt(b)) };
};
export const amountMultiply = <TToken extends Amount["token"]>(
a: Amount<TToken>,
b: Amount<TToken> | BigIntIsh,
): Amount<TToken> => {
/**
* Multiplies {@link a} with {@link b}
*/
export const amountMultiply = <TAmount extends Amount>(
a: TAmount,
b: TAmount extends Amount<TAmount["token"], infer TType>
? Amount<TAmount["token"], TType> | BigIntIsh
: never,
): Omit<TAmount, "amount"> & { amount: bigint } => {
if (isAmount(b)) {

@@ -90,10 +118,15 @@ invariant(a.token === b.token);

return isAmount(b)
? createAmountFromRaw(a.token, scaleDown(a.token, a.amount * b.amount))
: createAmountFromRaw(a.token, a.amount * BigInt(b));
? { ...a, amount: scaleDown(a.token, a.amount * b.amount) }
: { ...a, amount: a.amount * BigInt(b) };
};
export const amountDivide = <TToken extends Amount["token"]>(
a: Amount<TToken>,
b: Amount<TToken> | BigIntIsh,
): Amount<TToken> => {
/**
* Divides {@link a} by {@link b}
*/
export const amountDivide = <TAmount extends Amount>(
a: TAmount,
b: TAmount extends Amount<TAmount["token"], infer TType>
? Amount<TAmount["token"], TType> | BigIntIsh
: never,
): Omit<TAmount, "amount"> & { amount: bigint } => {
if (isAmount(b)) {

@@ -104,9 +137,14 @@ invariant(a.token === b.token);

return isAmount(b)
? createAmountFromRaw(a.token, scaleUp(a.token, a.amount) / b.amount)
: createAmountFromRaw(a.token, a.amount / BigInt(b));
? { ...a, amount: scaleUp(a.token, a.amount) / b.amount }
: { ...a, amount: a.amount / BigInt(b) };
};
export const amountLessThan = <TToken extends Amount["token"]>(
a: Amount<TToken>,
b: Amount<TToken> | BigIntIsh,
/**
* Returns true if {@link a} is less than {@link b}
*/
export const amountLessThan = <TAmount extends Amount>(
a: TAmount,
b: TAmount extends Amount<TAmount["token"], infer TType>
? Amount<TAmount["token"], TType> | BigIntIsh
: never,
): boolean => {

@@ -122,5 +160,10 @@ if (isAmount(b)) {

export const amountEqualTo = <TToken extends Amount["token"]>(
a: Amount<TToken>,
b: Amount<TToken> | BigIntIsh,
/**
* Returns true if {@link a} is equal to {@link b}
*/
export const amountEqualTo = <TAmount extends Amount>(
a: TAmount,
b: TAmount extends Amount<TAmount["token"], infer TType>
? Amount<TAmount["token"], TType> | BigIntIsh
: never,
): boolean => {

@@ -136,5 +179,10 @@ if (isAmount(b)) {

export const amountGreaterThan = <TToken extends Amount["token"]>(
a: Amount<TToken>,
b: Amount<TToken> | BigIntIsh,
/**
* Returns true if {@link a} is greater than {@link b}
*/
export const amountGreaterThan = <TAmount extends Amount>(
a: TAmount,
b: TAmount extends Amount<TAmount["token"], infer TType>
? Amount<TAmount["token"], TType> | BigIntIsh
: never,
): boolean => {

@@ -150,3 +198,6 @@ if (isAmount(b)) {

/**
* Returns the {@link amount} as a number with an adjustment for decimals
*/
export const amountToNumber = (amount: Amount): number =>
Number(amount.amount) / 10 ** (amount.token.decimals ?? 0);

@@ -1,6 +0,107 @@

export const MaxUint256 = 2n ** 256n - 1n;
export const MaxUint128 = 2n ** 128n - 1n;
export const MaxUint64 = 2n ** 64n - 1n;
export const MaxUint32 = 2n ** 32n - 1n;
export const MaxUint16 = 2n ** 16n - 1n;
export const MaxUint8 = 2n ** 8n - 1n;
import type { NativeCurrency } from "./native/types.js";
import { createNativeCurrency } from "./native/utils.js";
import type { WETH } from "./weth/types.js";
import { createWETH } from "./weth/utils.js";
export type ChainTokens = { native: NativeCurrency; weth?: WETH };
export const mainnetTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 1),
weth: createWETH(
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"Wrapped Ether",
"WETH",
18,
1,
4719568n,
),
} as const satisfies ChainTokens;
export const sepoliaTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 11155111),
} as const satisfies ChainTokens;
export const goerliTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 5),
weth: createWETH(
"0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6",
"Wrapped Ether",
"WETH",
18,
5,
1036651n,
),
} as const satisfies ChainTokens;
export const optimismTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 10),
weth: createWETH(
"0x4200000000000000000000000000000000000006",
"Wrapped Ether",
"WETH",
18,
10,
),
} as const satisfies ChainTokens;
export const optimismGoerliTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 420),
} as const satisfies ChainTokens;
export const arbitrumTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 42161),
weth: createWETH(
"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
"Wrapped Ether",
"WETH",
18,
42161,
55n,
),
} as const satisfies ChainTokens;
export const arbitrumGoerliTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 421_613),
} as const satisfies ChainTokens;
export const baseTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 8453),
weth: createWETH(
"0x4200000000000000000000000000000000000006",
"Wrapped Ether",
"WETH",
18,
8453,
),
} as const satisfies ChainTokens;
export const baseGoerliTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 84531),
} as const satisfies ChainTokens;
export const celoTokens = {
native: createNativeCurrency("Celo Native Asset", "CELO", 18, 42_220),
weth: createWETH(
"0x471EcE3750Da237f93B8E339c536989b8978a438",
"Celo Native Asset",
"CELO",
18,
42_220,
2919n,
),
} as const satisfies ChainTokens;
export const celoAlfajoresTokens = {
native: createNativeCurrency("Celo Native Asset", "CELO", 18, 44_787),
weth: createWETH(
"0xF194afDf50B03e69Bd7D057c1Aa9e10c9954E4C9",
"Celo Native Asset",
"CELO",
18,
44_787,
),
} as const satisfies ChainTokens;
export const foundryTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 31_337),
} as const satisfies ChainTokens;

@@ -1,6 +0,7 @@

import { type Address, type Hex, type PublicClient, getAddress } from "viem";
import { type Address, type Hex, type PublicClient } from "viem";
import { createAmountFromRaw } from "../amountUtils.js";
import { erc20ABI } from "../generated.js";
import { solmateErc20ABI as solmateERC20ABI } from "../generated.js";
import type { ReverseMirageRead } from "../types.js";
import type {
BaseERC20,
ERC20,

@@ -11,11 +12,16 @@ ERC20Amount,

} from "./types.js";
import {
createERC20,
createERC20Permit,
createERC20PermitDataFromRaw,
} from "./utils.js";
export const erc20BalanceOf = <TERC20 extends ERC20>(
publicClient: PublicClient,
args: { erc20: TERC20; address: Address },
) => {
return {
read: () =>
export const erc20BalanceOf = <TERC20 extends BaseERC20>(args: {
erc20: TERC20;
address: Address;
}) =>
({
read: (publicClient: PublicClient) =>
publicClient.readContract({
abi: erc20ABI,
abi: solmateERC20ABI,
address: args.erc20.address,

@@ -26,57 +32,14 @@ functionName: "balanceOf",

parse: (data): ERC20Amount<TERC20> => createAmountFromRaw(args.erc20, data),
} satisfies ReverseMirageRead<bigint>;
};
}) as const satisfies ReverseMirageRead<bigint>;
export const erc20PermitNonce = (
publicClient: PublicClient,
args: { erc20: ERC20; address: Address },
) => {
return {
read: () =>
export const erc20Allowance = <TERC20 extends BaseERC20>(args: {
erc20: TERC20;
address: Address;
spender: Address;
}) =>
({
read: (publicClient: PublicClient) =>
publicClient.readContract({
abi: erc20ABI,
abi: solmateERC20ABI,
address: args.erc20.address,
functionName: "nonces",
args: [args.address],
}),
parse: (data): bigint => data,
} satisfies ReverseMirageRead<bigint>;
};
export const erc20PermitData = <TERC20 extends ERC20Permit>(
publicClient: PublicClient,
args: { erc20: TERC20; address: Address },
) => {
return {
read: () =>
Promise.all([
publicClient.readContract({
abi: erc20ABI,
address: args.erc20.address,
functionName: "balanceOf",
args: [args.address],
}),
publicClient.readContract({
abi: erc20ABI,
address: args.erc20.address,
functionName: "nonces",
args: [args.address],
}),
]),
parse: (data): ERC20PermitData<TERC20> => ({
...createAmountFromRaw(args.erc20, data[0]),
nonce: data[1],
}),
} satisfies ReverseMirageRead<[bigint, bigint]>;
};
export const erc20Allowance = <TERC20 extends ERC20>(
publicClient: PublicClient,
args: { erc20: TERC20; address: Address; spender: Address },
) => {
return {
read: () =>
publicClient.readContract({
abi: erc20ABI,
address: args.erc20.address,
functionName: "allowance",

@@ -86,13 +49,11 @@ args: [args.address, args.spender],

parse: (data): ERC20Amount<TERC20> => createAmountFromRaw(args.erc20, data),
} satisfies ReverseMirageRead<bigint>;
};
}) as const satisfies ReverseMirageRead<bigint>;
export const erc20TotalSupply = <TERC20 extends ERC20>(
publicClient: PublicClient,
args: { erc20: TERC20 },
) => {
return {
read: () =>
export const erc20TotalSupply = <TERC20 extends BaseERC20>(args: {
erc20: TERC20;
}) =>
({
read: (publicClient: PublicClient) =>
publicClient.readContract({
abi: erc20ABI,
abi: solmateERC20ABI,
address: args.erc20.address,

@@ -102,13 +63,11 @@ functionName: "totalSupply",

parse: (data): ERC20Amount<TERC20> => createAmountFromRaw(args.erc20, data),
} satisfies ReverseMirageRead<bigint>;
};
}) as const satisfies ReverseMirageRead<bigint>;
export const erc20Name = (
publicClient: PublicClient,
args: { erc20: Pick<ERC20, "address"> },
) => {
return {
read: () =>
export const erc20Name = (args: {
erc20: Pick<BaseERC20, "address">;
}) =>
({
read: (publicClient: PublicClient) =>
publicClient.readContract({
abi: erc20ABI,
abi: solmateERC20ABI,
address: args.erc20.address,

@@ -118,13 +77,11 @@ functionName: "name",

parse: (data) => data,
} satisfies ReverseMirageRead<string>;
};
}) as const satisfies ReverseMirageRead<string>;
export const erc20Symbol = (
publicClient: PublicClient,
args: { erc20: Pick<ERC20, "address"> },
) => {
return {
read: () =>
export const erc20Symbol = (args: {
erc20: Pick<BaseERC20, "address">;
}) =>
({
read: (publicClient: PublicClient) =>
publicClient.readContract({
abi: erc20ABI,
abi: solmateERC20ABI,
address: args.erc20.address,

@@ -134,13 +91,11 @@ functionName: "symbol",

parse: (data: string) => data,
} satisfies ReverseMirageRead<string>;
};
}) as const satisfies ReverseMirageRead<string>;
export const erc20Decimals = (
publicClient: PublicClient,
args: { erc20: Pick<ERC20, "address"> },
) => {
return {
read: () =>
export const erc20Decimals = (args: {
erc20: Pick<BaseERC20, "address">;
}) =>
({
read: (publicClient: PublicClient) =>
publicClient.readContract({
abi: erc20ABI,
abi: solmateERC20ABI,
address: args.erc20.address,

@@ -150,68 +105,143 @@ functionName: "decimals",

parse: (data) => data,
} satisfies ReverseMirageRead<number>;
};
}) as const satisfies ReverseMirageRead<number>;
export const erc20PermitDomainSeparator = (
publicClient: PublicClient,
args: { erc20: Pick<ERC20Permit, "address"> },
) => {
return {
read: () =>
export const erc20PermitNonce = (args: {
erc20: ERC20Permit;
address: Address;
}) =>
({
read: (publicClient: PublicClient) =>
publicClient.readContract({
abi: erc20ABI,
abi: solmateERC20ABI,
address: args.erc20.address,
functionName: "nonces",
args: [args.address],
}),
parse: (data): bigint => data,
}) as const satisfies ReverseMirageRead<bigint>;
export const erc20PermitData = <TERC20 extends ERC20Permit>(args: {
erc20: TERC20;
address: Address;
}) =>
({
read: (publicClient: PublicClient) =>
Promise.all([
publicClient.readContract({
abi: solmateERC20ABI,
address: args.erc20.address,
functionName: "balanceOf",
args: [args.address],
}),
publicClient.readContract({
abi: solmateERC20ABI,
address: args.erc20.address,
functionName: "nonces",
args: [args.address],
}),
]),
parse: (data): ERC20PermitData<TERC20> =>
createERC20PermitDataFromRaw(args.erc20, data[0], data[1]),
}) as const satisfies ReverseMirageRead<[bigint, bigint]>;
export const erc20PermitDomainSeparator = (args: {
erc20: Pick<ERC20Permit, "address">;
}) =>
({
read: (publicClient: PublicClient) =>
publicClient.readContract({
abi: solmateERC20ABI,
address: args.erc20.address,
functionName: "DOMAIN_SEPARATOR",
}),
parse: (data) => data,
} satisfies ReverseMirageRead<Hex>;
};
}) as const satisfies ReverseMirageRead<Hex>;
export const getErc20 = (
publicClient: PublicClient,
args: { erc20: Pick<ERC20, "address" | "chainID"> },
) => {
return {
read: () =>
export const getERC20 = (args: {
erc20: Pick<BaseERC20, "address" | "chainID"> &
Partial<Pick<BaseERC20, "blockCreated">>;
}) =>
({
read: (publicClient: PublicClient) =>
Promise.all([
erc20Name(publicClient, args).read(),
erc20Symbol(publicClient, args).read(),
erc20Decimals(publicClient, args).read(),
erc20Name(args).read(publicClient),
erc20Symbol(args).read(publicClient),
erc20Decimals(args).read(publicClient),
]),
parse: (data): ERC20 => ({
type: "erc20",
name: data[0],
symbol: data[1],
decimals: data[2],
address: getAddress(args.erc20.address),
chainID: args.erc20.chainID,
}),
} satisfies ReverseMirageRead<[string, string, number]>;
};
parse: (data): ERC20 =>
createERC20(
args.erc20.address,
data[0],
data[1],
data[2],
args.erc20.chainID,
args.erc20.blockCreated,
),
}) as const satisfies ReverseMirageRead<[string, string, number]>;
export const getErc20Permit = (
publicClient: PublicClient,
args: {
erc20: Pick<ERC20Permit, "address" | "chainID"> &
Partial<Pick<ERC20Permit, "version">>;
},
) => {
return {
read: () =>
export const getERC20Permit = (args: {
erc20: Pick<ERC20Permit, "address" | "chainID"> &
Partial<Pick<ERC20Permit, "version" | "blockCreated">>;
}) =>
({
read: (publicClient: PublicClient) =>
Promise.all([
erc20Name(publicClient, args).read(),
erc20Symbol(publicClient, args).read(),
erc20Decimals(publicClient, args).read(),
erc20Name(args).read(publicClient),
erc20Symbol(args).read(publicClient),
erc20Decimals(args).read(publicClient),
]),
parse: (data): ERC20Permit => ({
type: "erc20",
name: data[0],
symbol: data[1],
decimals: data[2],
address: getAddress(args.erc20.address),
chainID: args.erc20.chainID,
version: args.erc20.version ?? "1",
}),
} satisfies ReverseMirageRead<[string, string, number]>;
};
parse: (data): ERC20Permit =>
createERC20Permit(
args.erc20.address,
data[0],
data[1],
data[2],
args.erc20.version ?? "1",
args.erc20.chainID,
args.erc20.blockCreated,
),
}) as const satisfies ReverseMirageRead<[string, string, number]>;
export const erc20IsPermit = () => {};
/**
* Returns either a {@link ERC20} or {@link ERC20Permit} depending on whether the specified token implements EIP 2616\
*
* Implementation is determined by checking if calling `DOMAIN_SEPARATOR()` reverts
*/
export const erc20IsPermit = (args: {
erc20: Pick<BaseERC20, "address" | "chainID"> &
Partial<Pick<BaseERC20, "blockCreated">> &
Partial<Pick<ERC20Permit, "version">>;
}) =>
({
read: async (publicClient: PublicClient) => {
try {
return await Promise.all([
getERC20(args).read(publicClient),
erc20PermitDomainSeparator(args).read(publicClient),
]);
} catch {
return await Promise.all([getERC20(args).read(publicClient)]);
}
},
parse: (data): ERC20 | ERC20Permit =>
data.length === 1
? createERC20(
args.erc20.address,
data[0][0],
data[0][1],
data[0][2],
args.erc20.chainID,
args.erc20.blockCreated,
)
: createERC20Permit(
args.erc20.address,
data[0][0],
data[0][1],
data[0][2],
args.erc20.version ?? "1",
args.erc20.chainID,
args.erc20.blockCreated,
),
}) as const satisfies ReverseMirageRead<
[[string, string, number], Hex] | [[string, string, number]]
>;
import type { Address } from "viem/accounts";
import type { Amount } from "../amountUtils.js";
import type { Token } from "../types.js";
import type { Token, TokenData } from "../types.js";
export type ERC20 = Token<"erc20"> & {
export type BaseERC20<TType extends string = string> = Token<TType> & {
address: Address;
name: string;
symbol: string;
decimals: number;
blockCreated: bigint;
};
export type ERC20Permit = ERC20 & { version: string };
export type ERC20 = BaseERC20<"erc20">;
export type ERC20Data<TERC20 extends ERC20> = Amount<TERC20>;
export type ERC20Permit = BaseERC20<"erc20Permit"> & {
version: string;
};
export type ERC20Amount<TERC20 extends ERC20> = ERC20Data<TERC20>;
export type ERC20Data<TERC20 extends BaseERC20> = Amount<
TERC20,
`${TERC20["type"]}Amount`
>;
export type ERC20PermitData<TERC20 extends ERC20Permit> = ERC20Data<TERC20> & {
nonce: bigint;
};
export type ERC20Amount<TERC20 extends BaseERC20> = Amount<
TERC20,
`${TERC20["type"]}Amount`
>;
export type ERC20PermitAmount<TERC20 extends ERC20Permit> =
ERC20PermitData<TERC20>;
export type ERC20PermitData<TERC20 extends ERC20Permit> = TokenData<
TERC20,
`${TERC20["type"]}Data`,
{ amount: bigint; nonce: bigint }
>;
import { type Address, getAddress, hashTypedData } from "viem";
import {
createAmountFromFraction,
createAmountFromRaw,
createAmountFromString,
} from "../amountUtils.js";
import type { Fraction } from "../types.js";
import type { ERC20, ERC20Permit, ERC20PermitData } from "./types.js";
export const createErc20 = (
/**
* Creates an {@link ERC20}
*/
export const createERC20 = (
address: Address,

@@ -10,2 +19,3 @@ name: string,

chainID: number,
blockCreated = 0n,
): ERC20 => ({

@@ -18,5 +28,9 @@ type: "erc20",

chainID,
blockCreated,
});
export const createErc20Permit = (
/**
* Creates an {@link ERC20Permit}
*/
export const createERC20Permit = (
address: Address,

@@ -28,4 +42,5 @@ name: string,

chainID: number,
blockCreated = 0n,
): ERC20Permit => ({
type: "erc20",
type: "erc20Permit",
address: getAddress(address),

@@ -37,4 +52,48 @@ name,

chainID,
blockCreated,
});
/**
* Creates a {@link ERC20PermitData} from a {@link erc20Permit}, a string, and a {@link nonce}
*/
export const createERC20PermitDataFromString = <TERC20 extends ERC20Permit>(
erc20Permit: TERC20,
amount: string,
nonce: bigint,
): ERC20PermitData<TERC20> => ({
...createAmountFromString(erc20Permit, amount),
type: `${erc20Permit.type as TERC20["type"]}Data`,
nonce,
});
/**
* Creates a {@link ERC20PermitData} from a {@link erc20Permit}, a {@link Fraction}, and a {@link nonce}
*/
export const createERC20PermitDataFromFraction = <TERC20 extends ERC20Permit>(
erc20Permit: TERC20,
amount: Fraction,
nonce: bigint,
): ERC20PermitData<TERC20> => ({
...createAmountFromFraction(erc20Permit, amount),
type: `${erc20Permit.type as TERC20["type"]}Data`,
nonce,
});
/**
* Creates a {@link ERC20PermitData} from a {@link erc20Permit}, a {@link Fraction}, and a {@link nonce}
*/
export const createERC20PermitDataFromRaw = <TERC20 extends ERC20Permit>(
erc20Permit: TERC20,
amount: bigint,
nonce: bigint,
): ERC20PermitData<TERC20> => ({
...createAmountFromRaw(erc20Permit, amount),
type: `${erc20Permit.type as TERC20["type"]}Data`,
nonce,
});
/**
* EIP 712 Type for Permit
*/
export const PermitType = {

@@ -53,2 +112,5 @@ Permit: [

/**
* Returns the EIP 712 typed data hash of type {@link PermitType}
*/
export const erc20PermitTypedDataHash = (permit: {

@@ -55,0 +117,0 @@ amount: ERC20PermitData<ERC20Permit>;

import invariant from "tiny-invariant";
import type { Account, Hex, PublicClient, WalletClient } from "viem";
import {
type Account,
type Hex,
type PublicClient,
type WalletClient,
getAddress,
} from "viem";
import type { Address } from "viem/accounts";
import { erc20ABI } from "../generated.js";
import { solmateErc20ABI as solmateERC20ABI } from "../generated.js";
import type { ReverseMirageWrite } from "../types.js";

@@ -10,3 +16,2 @@ import type {

ERC20Permit,
ERC20PermitAmount,
ERC20PermitData,

@@ -22,8 +27,8 @@ } from "./types.js";

to: Address;
amount: ERC20Amount<ERC20>;
amount: ERC20Amount<ERC20 | ERC20Permit>;
},
): Promise<ReverseMirageWrite<typeof erc20ABI, "transfer">> => {
): Promise<ReverseMirageWrite<typeof solmateERC20ABI, "transfer">> => {
const { request, result } = await publicClient.simulateContract({
address: args.amount.token.address,
abi: erc20ABI,
abi: solmateERC20ABI,
functionName: "transfer",

@@ -43,8 +48,8 @@ args: [args.to, args.amount.amount],

spender: Address;
amount: ERC20Amount<ERC20>;
amount: ERC20Amount<ERC20 | ERC20Permit>;
},
): Promise<ReverseMirageWrite<typeof erc20ABI, "approve">> => {
): Promise<ReverseMirageWrite<typeof solmateERC20ABI, "approve">> => {
const { request, result } = await publicClient.simulateContract({
address: args.amount.token.address,
abi: erc20ABI,
abi: solmateERC20ABI,
functionName: "approve",

@@ -65,10 +70,10 @@ args: [args.spender, args.amount.amount],

to: Address;
amount: ERC20Amount<ERC20>;
amount: ERC20Amount<ERC20 | ERC20Permit>;
},
): Promise<ReverseMirageWrite<typeof erc20ABI, "transferFrom">> => {
): Promise<ReverseMirageWrite<typeof solmateERC20ABI, "transferFrom">> => {
const { request, result } = await publicClient.simulateContract({
address: args.amount.token.address,
abi: erc20ABI,
abi: solmateERC20ABI,
functionName: "transferFrom",
args: [args.to, args.from, args.amount.amount],
args: [args.from, args.to, args.amount.amount],
account,

@@ -80,2 +85,3 @@ });

// TODO: owner is an unnecessary parameter
export const erc20SignPermit = async (

@@ -85,3 +91,3 @@ walletClient: WalletClient,

permit: {
amount: ERC20PermitData<ERC20Permit>;
permitData: ERC20PermitData<ERC20Permit>;
owner: Address;

@@ -93,6 +99,6 @@ spender: Address;

const domain = {
name: permit.amount.token.name,
version: permit.amount.token.version,
chainId: permit.amount.token.chainID,
verifyingContract: permit.amount.token.address,
name: permit.permitData.token.name,
version: permit.permitData.token.version,
chainId: permit.permitData.token.chainID,
verifyingContract: getAddress(permit.permitData.token.address),
} as const;

@@ -108,5 +114,5 @@

spender: permit.spender,
value: permit.amount.amount,
nonce: permit.amount.nonce,
value: permit.permitData.amount,
deadline: permit.deadline,
nonce: permit.permitData.nonce,
},

@@ -123,16 +129,16 @@ });

spender: Address;
erc20Permit: ERC20PermitAmount<ERC20Permit>;
permitData: ERC20PermitData<ERC20Permit>;
deadline: bigint;
signature: Hex;
},
): Promise<ReverseMirageWrite<typeof erc20ABI, "permit">> => {
invariant(args.signature.length === 67, "invalid signature length");
): Promise<ReverseMirageWrite<typeof solmateERC20ABI, "permit">> => {
invariant(args.signature.length === 132, "Invalid signature length");
const r = `0x${args.signature.substring(2, 2 + 32)}` as const;
const s = `0x${args.signature.substring(34, 34 + 32)}` as const;
const v = Number(args.signature.substring(66));
const r = `0x${args.signature.substring(2, 2 + 64)}` as const;
const s = `0x${args.signature.substring(2 + 64, 2 + 64 + 64)}` as const;
const v = Number(`0x${args.signature.substring(2 + 64 + 64)}`);
const { request, result } = await publicClient.simulateContract({
address: args.erc20Permit.token.address,
abi: erc20ABI,
address: args.permitData.token.address,
abi: solmateERC20ABI,
functionName: "permit",

@@ -142,3 +148,3 @@ args: [

args.spender,
args.erc20Permit.amount,
args.permitData.amount,
args.deadline,

@@ -145,0 +151,0 @@ v,

@@ -5,3 +5,3 @@ import invariant from "tiny-invariant";

/**
* Determines if x is a fraction type
* Returns true if {@link x } is of type {@link Fraction}
*/

@@ -12,3 +12,3 @@ export const isFraction = (x: Fraction | BigIntIsh): x is Fraction =>

/**
* Create a fraction
* Creates a {@link Fraction} from a {@link numerator} and {@link denominator}
*/

@@ -25,3 +25,3 @@ export const createFraction = (

/**
* Calculate the quotient
* Calculates the quotient
*/

@@ -51,3 +51,3 @@ export const fractionQuotient = (fraction: Fraction): bigint =>

/**
* Add two fractions
* Adds {@link a} with {@link b}
*/

@@ -68,3 +68,3 @@ export const fractionAdd = (a: Fraction, b: Fraction | BigIntIsh): Fraction =>

/**
* Subtract the second fraction from the first
* Subtracts {@link a} by {@link b}
*/

@@ -88,3 +88,3 @@ export const fractionSubtract = (

/**
* Multiply two fractions
* Multiplies {@link a} with {@link b}
*/

@@ -108,3 +108,3 @@ export const fractionMultiply = (

/**
* Divide the first fraction by the second
* Divides {@link a} by {@link b}
*/

@@ -128,3 +128,3 @@ export const fractionDivide = (

/**
* Return true if the first fraction is less than the second
* Returns true if {@link a} is less than {@link b}
*/

@@ -140,3 +140,3 @@ export const fractionLessThan = (

/**
* Return true if the first fraction is greater than the second
* Returns true if {@link a} is greater than {@link b}
*/

@@ -152,3 +152,3 @@ export const fractionGreaterThan = (

/**
* Return true if the first fraction is equal to the second
* Returns true if {@link a} is equal to {@link b}
*/

@@ -155,0 +155,0 @@ export const fractionEqualTo = (

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ERC1155
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
export const erc1155ABI = [
{
stateMutability: 'nonpayable',
type: 'constructor',
inputs: [{ name: '_baseURI', internalType: 'string', type: 'string' }],
},
{
type: 'event',
anonymous: false,
inputs: [
{
name: 'owner',
internalType: 'address',
type: 'address',
indexed: true,
},
{
name: 'operator',
internalType: 'address',
type: 'address',
indexed: true,
},
{ name: 'approved', internalType: 'bool', type: 'bool', indexed: false },
],
name: 'ApprovalForAll',
},
{
type: 'event',
anonymous: false,
inputs: [
{
name: 'operator',
internalType: 'address',
type: 'address',
indexed: true,
},
{ name: 'from', internalType: 'address', type: 'address', indexed: true },
{ name: 'to', internalType: 'address', type: 'address', indexed: true },
{
name: 'ids',
internalType: 'uint256[]',
type: 'uint256[]',
indexed: false,
},
{
name: 'amounts',
internalType: 'uint256[]',
type: 'uint256[]',
indexed: false,
},
],
name: 'TransferBatch',
},
{
type: 'event',
anonymous: false,
inputs: [
{
name: 'operator',
internalType: 'address',
type: 'address',
indexed: true,
},
{ name: 'from', internalType: 'address', type: 'address', indexed: true },
{ name: 'to', internalType: 'address', type: 'address', indexed: true },
{ name: 'id', internalType: 'uint256', type: 'uint256', indexed: false },
{
name: 'amount',
internalType: 'uint256',
type: 'uint256',
indexed: false,
},
],
name: 'TransferSingle',
},
{
type: 'event',
anonymous: false,
inputs: [
{ name: 'value', internalType: 'string', type: 'string', indexed: false },
{ name: 'id', internalType: 'uint256', type: 'uint256', indexed: true },
],
name: 'URI',
},
{
stateMutability: 'view',
type: 'function',
inputs: [
{ name: '', internalType: 'address', type: 'address' },
{ name: '', internalType: 'uint256', type: 'uint256' },
],
name: 'balanceOf',
outputs: [{ name: '', internalType: 'uint256', type: 'uint256' }],
},
{
stateMutability: 'view',
type: 'function',
inputs: [
{ name: 'owners', internalType: 'address[]', type: 'address[]' },
{ name: 'ids', internalType: 'uint256[]', type: 'uint256[]' },
],
name: 'balanceOfBatch',
outputs: [
{ name: 'balances', internalType: 'uint256[]', type: 'uint256[]' },
],
},
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'from', internalType: 'address', type: 'address' },
{ name: 'id', internalType: 'uint256', type: 'uint256' },
{ name: 'amount', internalType: 'uint256', type: 'uint256' },
],
name: 'burn',
outputs: [],
},
{
stateMutability: 'view',
type: 'function',
inputs: [
{ name: '', internalType: 'address', type: 'address' },
{ name: '', internalType: 'address', type: 'address' },
],
name: 'isApprovedForAll',
outputs: [{ name: '', internalType: 'bool', type: 'bool' }],
},
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'to', internalType: 'address', type: 'address' },
{ name: 'id', internalType: 'uint256', type: 'uint256' },
{ name: 'amount', internalType: 'uint256', type: 'uint256' },
{ name: 'data', internalType: 'bytes', type: 'bytes' },
],
name: 'mint',
outputs: [],
},
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'from', internalType: 'address', type: 'address' },
{ name: 'to', internalType: 'address', type: 'address' },
{ name: 'ids', internalType: 'uint256[]', type: 'uint256[]' },
{ name: 'amounts', internalType: 'uint256[]', type: 'uint256[]' },
{ name: 'data', internalType: 'bytes', type: 'bytes' },
],
name: 'safeBatchTransferFrom',
outputs: [],
},
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'from', internalType: 'address', type: 'address' },
{ name: 'to', internalType: 'address', type: 'address' },
{ name: 'id', internalType: 'uint256', type: 'uint256' },
{ name: 'amount', internalType: 'uint256', type: 'uint256' },
{ name: 'data', internalType: 'bytes', type: 'bytes' },
],
name: 'safeTransferFrom',
outputs: [],
},
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'operator', internalType: 'address', type: 'address' },
{ name: 'approved', internalType: 'bool', type: 'bool' },
],
name: 'setApprovalForAll',
outputs: [],
},
{
stateMutability: 'view',
type: 'function',
inputs: [{ name: 'interfaceId', internalType: 'bytes4', type: 'bytes4' }],
name: 'supportsInterface',
outputs: [{ name: '', internalType: 'bool', type: 'bool' }],
},
{
stateMutability: 'view',
type: 'function',
inputs: [{ name: '', internalType: 'uint256', type: 'uint256' }],
name: 'uri',
outputs: [{ name: '', internalType: 'string', type: 'string' }],
},
] as const
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ERC1155TokenReceiver
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
export const erc1155TokenReceiverABI = [
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: '', internalType: 'address', type: 'address' },
{ name: '', internalType: 'address', type: 'address' },
{ name: '', internalType: 'uint256[]', type: 'uint256[]' },
{ name: '', internalType: 'uint256[]', type: 'uint256[]' },
{ name: '', internalType: 'bytes', type: 'bytes' },
],
name: 'onERC1155BatchReceived',
outputs: [{ name: '', internalType: 'bytes4', type: 'bytes4' }],
},
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: '', internalType: 'address', type: 'address' },
{ name: '', internalType: 'address', type: 'address' },
{ name: '', internalType: 'uint256', type: 'uint256' },
{ name: '', internalType: 'uint256', type: 'uint256' },
{ name: '', internalType: 'bytes', type: 'bytes' },
],
name: 'onERC1155Received',
outputs: [{ name: '', internalType: 'bytes4', type: 'bytes4' }],
},
] as const
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ERC20

@@ -7,2 +235,11 @@ //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

{
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',

@@ -50,3 +287,155 @@ anonymous: false,

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: 'amount', 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: 'amount', 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: '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
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ERC20Permit
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
export const erc20PermitABI = [
{
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',

@@ -83,2 +472,12 @@ outputs: [{ name: '', internalType: 'bytes32', type: 'bytes32' }],

{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'from', internalType: 'address', type: 'address' },
{ name: 'amount', internalType: 'uint256', type: 'uint256' },
],
name: 'burn',
outputs: [],
},
{
stateMutability: 'view',

@@ -91,2 +490,12 @@ type: 'function',

{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'to', internalType: 'address', type: 'address' },
{ name: 'amount', internalType: 'uint256', type: 'uint256' },
],
name: 'mint',
outputs: [],
},
{
stateMutability: 'view',

@@ -158,6 +567,6 @@ type: 'function',

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// MockERC20
// ERC20PermitHashTypedData
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
export const mockErc20ABI = [
export const erc20PermitHashTypedDataABI = [
{

@@ -251,3 +660,3 @@ stateMutability: 'nonpayable',

{ name: 'from', internalType: 'address', type: 'address' },
{ name: 'value', internalType: 'uint256', type: 'uint256' },
{ name: 'amount', internalType: 'uint256', type: 'uint256' },
],

@@ -265,2 +674,14 @@ name: 'burn',

{
stateMutability: 'view',
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: 'hashTypedData',
outputs: [{ name: '', internalType: 'bytes32', type: 'bytes32' }],
},
{
stateMutability: 'nonpayable',

@@ -270,4 +691,185 @@ type: 'function',

{ name: 'to', internalType: 'address', type: 'address' },
{ name: 'amount', 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
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ERC721
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
export const erc721ABI = [
{
stateMutability: 'nonpayable',
type: 'constructor',
inputs: [
{ name: '_name', internalType: 'string', type: 'string' },
{ name: '_symbol', internalType: 'string', type: 'string' },
{ name: '_baseTokenURI', internalType: 'string', type: 'string' },
],
},
{
type: 'event',
anonymous: false,
inputs: [
{
name: 'owner',
internalType: 'address',
type: 'address',
indexed: true,
},
{
name: 'spender',
internalType: 'address',
type: 'address',
indexed: true,
},
{ name: 'id', internalType: 'uint256', type: 'uint256', indexed: true },
],
name: 'Approval',
},
{
type: 'event',
anonymous: false,
inputs: [
{
name: 'owner',
internalType: 'address',
type: 'address',
indexed: true,
},
{
name: 'operator',
internalType: 'address',
type: 'address',
indexed: true,
},
{ name: 'approved', internalType: 'bool', type: 'bool', indexed: false },
],
name: 'ApprovalForAll',
},
{
type: 'event',
anonymous: false,
inputs: [
{ name: 'from', internalType: 'address', type: 'address', indexed: true },
{ name: 'to', internalType: 'address', type: 'address', indexed: true },
{ name: 'id', internalType: 'uint256', type: 'uint256', indexed: true },
],
name: 'Transfer',
},
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'spender', internalType: 'address', type: 'address' },
{ name: 'id', internalType: 'uint256', type: 'uint256' },
],
name: 'approve',
outputs: [],
},
{
stateMutability: 'view',
type: 'function',
inputs: [{ name: 'owner', internalType: 'address', type: 'address' }],
name: 'balanceOf',
outputs: [{ name: '', internalType: 'uint256', type: 'uint256' }],
},
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [{ name: 'id', internalType: 'uint256', type: 'uint256' }],
name: 'burn',
outputs: [],
},
{
stateMutability: 'view',
type: 'function',
inputs: [{ name: '', internalType: 'uint256', type: 'uint256' }],
name: 'getApproved',
outputs: [{ name: '', internalType: 'address', type: 'address' }],
},
{
stateMutability: 'view',
type: 'function',
inputs: [
{ name: '', internalType: 'address', type: 'address' },
{ name: '', internalType: 'address', type: 'address' },
],
name: 'isApprovedForAll',
outputs: [{ name: '', internalType: 'bool', type: 'bool' }],
},
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'to', internalType: 'address', type: 'address' },
{ name: 'id', internalType: 'uint256', type: 'uint256' },
],
name: 'mint',

@@ -286,3 +888,693 @@ outputs: [],

type: 'function',
inputs: [{ name: 'id', internalType: 'uint256', type: 'uint256' }],
name: 'ownerOf',
outputs: [{ name: 'owner', internalType: 'address', type: 'address' }],
},
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'from', internalType: 'address', type: 'address' },
{ name: 'to', internalType: 'address', type: 'address' },
{ name: 'id', internalType: 'uint256', type: 'uint256' },
],
name: 'safeTransferFrom',
outputs: [],
},
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'from', internalType: 'address', type: 'address' },
{ name: 'to', internalType: 'address', type: 'address' },
{ name: 'id', internalType: 'uint256', type: 'uint256' },
{ name: 'data', internalType: 'bytes', type: 'bytes' },
],
name: 'safeTransferFrom',
outputs: [],
},
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'operator', internalType: 'address', type: 'address' },
{ name: 'approved', internalType: 'bool', type: 'bool' },
],
name: 'setApprovalForAll',
outputs: [],
},
{
stateMutability: 'view',
type: 'function',
inputs: [{ name: 'interfaceId', internalType: 'bytes4', type: 'bytes4' }],
name: 'supportsInterface',
outputs: [{ name: '', internalType: 'bool', type: 'bool' }],
},
{
stateMutability: 'view',
type: 'function',
inputs: [],
name: 'symbol',
outputs: [{ name: '', internalType: 'string', type: 'string' }],
},
{
stateMutability: 'view',
type: 'function',
inputs: [{ name: '', internalType: 'uint256', type: 'uint256' }],
name: 'tokenURI',
outputs: [{ name: '', internalType: 'string', type: 'string' }],
},
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'from', internalType: 'address', type: 'address' },
{ name: 'to', internalType: 'address', type: 'address' },
{ name: 'id', internalType: 'uint256', type: 'uint256' },
],
name: 'transferFrom',
outputs: [],
},
] as const
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ERC721MaxBalance
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
export const erc721MaxBalanceABI = [
{
stateMutability: 'nonpayable',
type: 'constructor',
inputs: [
{ name: '_name', internalType: 'string', type: 'string' },
{ name: '_symbol', internalType: 'string', type: 'string' },
{ name: '_baseTokenURI', internalType: 'string', type: 'string' },
],
},
{
type: 'event',
anonymous: false,
inputs: [
{
name: 'owner',
internalType: 'address',
type: 'address',
indexed: true,
},
{
name: 'spender',
internalType: 'address',
type: 'address',
indexed: true,
},
{ name: 'id', internalType: 'uint256', type: 'uint256', indexed: true },
],
name: 'Approval',
},
{
type: 'event',
anonymous: false,
inputs: [
{
name: 'owner',
internalType: 'address',
type: 'address',
indexed: true,
},
{
name: 'operator',
internalType: 'address',
type: 'address',
indexed: true,
},
{ name: 'approved', internalType: 'bool', type: 'bool', indexed: false },
],
name: 'ApprovalForAll',
},
{
type: 'event',
anonymous: false,
inputs: [
{ name: 'from', internalType: 'address', type: 'address', indexed: true },
{ name: 'to', internalType: 'address', type: 'address', indexed: true },
{ name: 'id', internalType: 'uint256', type: 'uint256', indexed: true },
],
name: 'Transfer',
},
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'spender', internalType: 'address', type: 'address' },
{ name: 'id', internalType: 'uint256', type: 'uint256' },
],
name: 'approve',
outputs: [],
},
{
stateMutability: 'view',
type: 'function',
inputs: [{ name: '', internalType: 'address', type: 'address' }],
name: 'balanceOf',
outputs: [{ name: '', internalType: 'uint256', type: 'uint256' }],
},
{
stateMutability: 'view',
type: 'function',
inputs: [{ name: '', internalType: 'uint256', type: 'uint256' }],
name: 'getApproved',
outputs: [{ name: '', internalType: 'address', type: 'address' }],
},
{
stateMutability: 'view',
type: 'function',
inputs: [
{ name: '', internalType: 'address', type: 'address' },
{ name: '', internalType: 'address', type: 'address' },
],
name: 'isApprovedForAll',
outputs: [{ name: '', internalType: 'bool', type: 'bool' }],
},
{
stateMutability: 'view',
type: 'function',
inputs: [],
name: 'name',
outputs: [{ name: '', internalType: 'string', type: 'string' }],
},
{
stateMutability: 'view',
type: 'function',
inputs: [{ name: 'id', internalType: 'uint256', type: 'uint256' }],
name: 'ownerOf',
outputs: [{ name: 'owner', internalType: 'address', type: 'address' }],
},
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'from', internalType: 'address', type: 'address' },
{ name: 'to', internalType: 'address', type: 'address' },
{ name: 'id', internalType: 'uint256', type: 'uint256' },
],
name: 'safeTransferFrom',
outputs: [],
},
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'from', internalType: 'address', type: 'address' },
{ name: 'to', internalType: 'address', type: 'address' },
{ name: 'id', internalType: 'uint256', type: 'uint256' },
{ name: 'data', internalType: 'bytes', type: 'bytes' },
],
name: 'safeTransferFrom',
outputs: [],
},
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'operator', internalType: 'address', type: 'address' },
{ name: 'approved', internalType: 'bool', type: 'bool' },
],
name: 'setApprovalForAll',
outputs: [],
},
{
stateMutability: 'view',
type: 'function',
inputs: [{ name: 'interfaceId', internalType: 'bytes4', type: 'bytes4' }],
name: 'supportsInterface',
outputs: [{ name: '', internalType: 'bool', type: 'bool' }],
},
{
stateMutability: 'view',
type: 'function',
inputs: [],
name: 'symbol',
outputs: [{ name: '', internalType: 'string', type: 'string' }],
},
{
stateMutability: 'view',
type: 'function',
inputs: [{ name: '', internalType: 'uint256', type: 'uint256' }],
name: 'tokenURI',
outputs: [{ name: '', internalType: 'string', type: 'string' }],
},
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'from', internalType: 'address', type: 'address' },
{ name: 'to', internalType: 'address', type: 'address' },
{ name: 'id', internalType: 'uint256', type: 'uint256' },
],
name: 'transferFrom',
outputs: [],
},
] as const
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ERC721TokenReceiver
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
export const erc721TokenReceiverABI = [
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: '', internalType: 'address', type: 'address' },
{ name: '', internalType: 'address', type: 'address' },
{ name: '', internalType: 'uint256', type: 'uint256' },
{ name: '', internalType: 'bytes', type: 'bytes' },
],
name: 'onERC721Received',
outputs: [{ name: '', internalType: 'bytes4', type: 'bytes4' }],
},
] as const
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// WETH9
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
export const weth9ABI = [
{
constant: true,
payable: false,
stateMutability: 'view',
type: 'function',
inputs: [],
name: 'name',
outputs: [{ name: '', type: 'string' }],
},
{
constant: false,
payable: false,
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'guy', type: 'address' },
{ name: 'wad', type: 'uint256' },
],
name: 'approve',
outputs: [{ name: '', type: 'bool' }],
},
{
constant: true,
payable: false,
stateMutability: 'view',
type: 'function',
inputs: [],
name: 'totalSupply',
outputs: [{ name: '', type: 'uint256' }],
},
{
constant: false,
payable: false,
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'src', type: 'address' },
{ name: 'dst', type: 'address' },
{ name: 'wad', type: 'uint256' },
],
name: 'transferFrom',
outputs: [{ name: '', type: 'bool' }],
},
{
constant: false,
payable: false,
stateMutability: 'nonpayable',
type: 'function',
inputs: [{ name: 'wad', type: 'uint256' }],
name: 'withdraw',
outputs: [],
},
{
constant: true,
payable: false,
stateMutability: 'view',
type: 'function',
inputs: [],
name: 'decimals',
outputs: [{ name: '', type: 'uint8' }],
},
{
constant: true,
payable: false,
stateMutability: 'view',
type: 'function',
inputs: [{ name: '', type: 'address' }],
name: 'balanceOf',
outputs: [{ name: '', type: 'uint256' }],
},
{
constant: true,
payable: false,
stateMutability: 'view',
type: 'function',
inputs: [],
name: 'symbol',
outputs: [{ name: '', type: 'string' }],
},
{
constant: false,
payable: false,
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'dst', type: 'address' },
{ name: 'wad', type: 'uint256' },
],
name: 'transfer',
outputs: [{ name: '', type: 'bool' }],
},
{
constant: false,
payable: true,
stateMutability: 'payable',
type: 'function',
inputs: [],
name: 'deposit',
outputs: [],
},
{
constant: true,
payable: false,
stateMutability: 'view',
type: 'function',
inputs: [
{ name: '', type: 'address' },
{ name: '', type: 'address' },
],
name: 'allowance',
outputs: [{ name: '', type: 'uint256' }],
},
{ payable: true, stateMutability: 'payable', type: 'fallback' },
{
type: 'event',
anonymous: false,
inputs: [
{ name: 'src', type: 'address', indexed: true },
{ name: 'guy', type: 'address', indexed: true },
{ name: 'wad', type: 'uint256', indexed: false },
],
name: 'Approval',
},
{
type: 'event',
anonymous: false,
inputs: [
{ name: 'src', type: 'address', indexed: true },
{ name: 'dst', type: 'address', indexed: true },
{ name: 'wad', type: 'uint256', indexed: false },
],
name: 'Transfer',
},
{
type: 'event',
anonymous: false,
inputs: [
{ name: 'dst', type: 'address', indexed: true },
{ name: 'wad', type: 'uint256', indexed: false },
],
name: 'Deposit',
},
{
type: 'event',
anonymous: false,
inputs: [
{ name: 'src', type: 'address', indexed: true },
{ name: 'wad', type: 'uint256', indexed: false },
],
name: 'Withdrawal',
},
] as const
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// solmateERC1155
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
export const solmateErc1155ABI = [
{
type: 'event',
anonymous: false,
inputs: [
{
name: 'owner',
internalType: 'address',
type: 'address',
indexed: true,
},
{
name: 'operator',
internalType: 'address',
type: 'address',
indexed: true,
},
{ name: 'approved', internalType: 'bool', type: 'bool', indexed: false },
],
name: 'ApprovalForAll',
},
{
type: 'event',
anonymous: false,
inputs: [
{
name: 'operator',
internalType: 'address',
type: 'address',
indexed: true,
},
{ name: 'from', internalType: 'address', type: 'address', indexed: true },
{ name: 'to', internalType: 'address', type: 'address', indexed: true },
{
name: 'ids',
internalType: 'uint256[]',
type: 'uint256[]',
indexed: false,
},
{
name: 'amounts',
internalType: 'uint256[]',
type: 'uint256[]',
indexed: false,
},
],
name: 'TransferBatch',
},
{
type: 'event',
anonymous: false,
inputs: [
{
name: 'operator',
internalType: 'address',
type: 'address',
indexed: true,
},
{ name: 'from', internalType: 'address', type: 'address', indexed: true },
{ name: 'to', internalType: 'address', type: 'address', indexed: true },
{ name: 'id', internalType: 'uint256', type: 'uint256', indexed: false },
{
name: 'amount',
internalType: 'uint256',
type: 'uint256',
indexed: false,
},
],
name: 'TransferSingle',
},
{
type: 'event',
anonymous: false,
inputs: [
{ name: 'value', internalType: 'string', type: 'string', indexed: false },
{ name: 'id', internalType: 'uint256', type: 'uint256', indexed: true },
],
name: 'URI',
},
{
stateMutability: 'view',
type: 'function',
inputs: [
{ name: '', internalType: 'address', type: 'address' },
{ name: '', internalType: 'uint256', type: 'uint256' },
],
name: 'balanceOf',
outputs: [{ name: '', internalType: 'uint256', type: 'uint256' }],
},
{
stateMutability: 'view',
type: 'function',
inputs: [
{ name: 'owners', internalType: 'address[]', type: 'address[]' },
{ name: 'ids', internalType: 'uint256[]', type: 'uint256[]' },
],
name: 'balanceOfBatch',
outputs: [
{ name: 'balances', internalType: 'uint256[]', type: 'uint256[]' },
],
},
{
stateMutability: 'view',
type: 'function',
inputs: [
{ name: '', internalType: 'address', type: 'address' },
{ name: '', internalType: 'address', type: 'address' },
],
name: 'isApprovedForAll',
outputs: [{ name: '', internalType: 'bool', type: 'bool' }],
},
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'from', internalType: 'address', type: 'address' },
{ name: 'to', internalType: 'address', type: 'address' },
{ name: 'ids', internalType: 'uint256[]', type: 'uint256[]' },
{ name: 'amounts', internalType: 'uint256[]', type: 'uint256[]' },
{ name: 'data', internalType: 'bytes', type: 'bytes' },
],
name: 'safeBatchTransferFrom',
outputs: [],
},
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'from', internalType: 'address', type: 'address' },
{ name: 'to', internalType: 'address', type: 'address' },
{ name: 'id', internalType: 'uint256', type: 'uint256' },
{ name: 'amount', internalType: 'uint256', type: 'uint256' },
{ name: 'data', internalType: 'bytes', type: 'bytes' },
],
name: 'safeTransferFrom',
outputs: [],
},
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'operator', internalType: 'address', type: 'address' },
{ name: 'approved', internalType: 'bool', type: 'bool' },
],
name: 'setApprovalForAll',
outputs: [],
},
{
stateMutability: 'view',
type: 'function',
inputs: [{ name: 'interfaceId', internalType: 'bytes4', type: 'bytes4' }],
name: 'supportsInterface',
outputs: [{ name: '', internalType: 'bool', type: 'bool' }],
},
{
stateMutability: 'view',
type: 'function',
inputs: [{ name: 'id', internalType: 'uint256', type: 'uint256' }],
name: 'uri',
outputs: [{ name: '', internalType: 'string', type: 'string' }],
},
] as const
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// solmateERC20
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
export const solmateErc20ABI = [
{
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: 'view',
type: 'function',
inputs: [],
name: 'decimals',
outputs: [{ name: '', internalType: 'uint8', type: 'uint8' }],
},
{
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',

@@ -342,1 +1634,171 @@ outputs: [{ name: '', internalType: 'uint256', type: 'uint256' }],

] as const
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// solmateERC721
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
export const solmateErc721ABI = [
{
type: 'event',
anonymous: false,
inputs: [
{
name: 'owner',
internalType: 'address',
type: 'address',
indexed: true,
},
{
name: 'spender',
internalType: 'address',
type: 'address',
indexed: true,
},
{ name: 'id', internalType: 'uint256', type: 'uint256', indexed: true },
],
name: 'Approval',
},
{
type: 'event',
anonymous: false,
inputs: [
{
name: 'owner',
internalType: 'address',
type: 'address',
indexed: true,
},
{
name: 'operator',
internalType: 'address',
type: 'address',
indexed: true,
},
{ name: 'approved', internalType: 'bool', type: 'bool', indexed: false },
],
name: 'ApprovalForAll',
},
{
type: 'event',
anonymous: false,
inputs: [
{ name: 'from', internalType: 'address', type: 'address', indexed: true },
{ name: 'to', internalType: 'address', type: 'address', indexed: true },
{ name: 'id', internalType: 'uint256', type: 'uint256', indexed: true },
],
name: 'Transfer',
},
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'spender', internalType: 'address', type: 'address' },
{ name: 'id', internalType: 'uint256', type: 'uint256' },
],
name: 'approve',
outputs: [],
},
{
stateMutability: 'view',
type: 'function',
inputs: [{ name: 'owner', internalType: 'address', type: 'address' }],
name: 'balanceOf',
outputs: [{ name: '', internalType: 'uint256', type: 'uint256' }],
},
{
stateMutability: 'view',
type: 'function',
inputs: [{ name: '', internalType: 'uint256', type: 'uint256' }],
name: 'getApproved',
outputs: [{ name: '', internalType: 'address', type: 'address' }],
},
{
stateMutability: 'view',
type: 'function',
inputs: [
{ name: '', internalType: 'address', type: 'address' },
{ name: '', internalType: 'address', type: 'address' },
],
name: 'isApprovedForAll',
outputs: [{ name: '', internalType: 'bool', type: 'bool' }],
},
{
stateMutability: 'view',
type: 'function',
inputs: [],
name: 'name',
outputs: [{ name: '', internalType: 'string', type: 'string' }],
},
{
stateMutability: 'view',
type: 'function',
inputs: [{ name: 'id', internalType: 'uint256', type: 'uint256' }],
name: 'ownerOf',
outputs: [{ name: 'owner', internalType: 'address', type: 'address' }],
},
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'from', internalType: 'address', type: 'address' },
{ name: 'to', internalType: 'address', type: 'address' },
{ name: 'id', internalType: 'uint256', type: 'uint256' },
],
name: 'safeTransferFrom',
outputs: [],
},
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'from', internalType: 'address', type: 'address' },
{ name: 'to', internalType: 'address', type: 'address' },
{ name: 'id', internalType: 'uint256', type: 'uint256' },
{ name: 'data', internalType: 'bytes', type: 'bytes' },
],
name: 'safeTransferFrom',
outputs: [],
},
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'operator', internalType: 'address', type: 'address' },
{ name: 'approved', internalType: 'bool', type: 'bool' },
],
name: 'setApprovalForAll',
outputs: [],
},
{
stateMutability: 'view',
type: 'function',
inputs: [{ name: 'interfaceId', internalType: 'bytes4', type: 'bytes4' }],
name: 'supportsInterface',
outputs: [{ name: '', internalType: 'bool', type: 'bool' }],
},
{
stateMutability: 'view',
type: 'function',
inputs: [],
name: 'symbol',
outputs: [{ name: '', internalType: 'string', type: 'string' }],
},
{
stateMutability: 'view',
type: 'function',
inputs: [{ name: 'id', internalType: 'uint256', type: 'uint256' }],
name: 'tokenURI',
outputs: [{ name: '', internalType: 'string', type: 'string' }],
},
{
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{ name: 'from', internalType: 'address', type: 'address' },
{ name: 'to', internalType: 'address', type: 'address' },
{ name: 'id', internalType: 'uint256', type: 'uint256' },
],
name: 'transferFrom',
outputs: [],
},
] as const

@@ -0,11 +1,100 @@

// ERC20
export {
MaxUint256,
MaxUint128,
MaxUint64,
MaxUint32,
MaxUint16,
MaxUint8,
} from "./constants.js";
erc20BalanceOf,
erc20Allowance,
erc20TotalSupply,
erc20Name,
erc20Symbol,
erc20Decimals,
erc20PermitNonce,
erc20PermitData,
erc20PermitDomainSeparator,
getERC20,
getERC20Permit,
erc20IsPermit,
} from "./erc20/reads.js";
export {
createERC20,
createERC20Permit,
createERC20PermitDataFromString,
createERC20PermitDataFromRaw,
createERC20PermitDataFromFraction,
PermitType,
erc20PermitTypedDataHash,
} from "./erc20/utils.js";
export {
erc20Transfer,
erc20Approve,
erc20TransferFrom,
erc20Permit,
erc20SignPermit,
} from "./erc20/writes.js";
// ERC721
export {
erc721Name,
erc721Symbol,
erc721TokenURI,
erc721GetApproved,
erc721IsApprovedForAll,
erc721OwnerOf,
erc721BalanceOf,
erc721SupportsInterface,
getERC721,
erc721Data,
erc721IDData,
} from "./erc721/reads.js";
export {
createERC721,
createERC721Data,
createERC721IDData,
} from "./erc721/utils.js";
export {
erc721Transfer,
erc721Approve,
erc721SetApprovalForAll,
} from "./erc721/writes.js";
// ERC1155
export {
erc1155IsApprovedForAll,
erc1155URI,
erc1155BalanceOf,
getERC1155,
} from "./erc1155/reads.js";
export { createERC1155, createERC1155Data } from "./erc1155/utils.js";
export {
erc1155SetApprovalForAll,
erc1155Transfer,
erc1155TransferBatch,
} from "./erc1155/writes.js";
// NATIVE
export { nativeBalance } from "./native/reads.js";
export { createNativeCurrency } from "./native/utils.js";
// WETH
export { createWETH } from "./weth/utils.js";
export { wethDeposit, wethWithdraw } from "./weth/writes.js";
// UTILS
export { readAndParse } from "./readUtils.js";
// AMOUNT
export {
type Amount,

@@ -26,2 +115,4 @@ isAmount,

// FRACTION
export {

@@ -43,2 +134,4 @@ isFraction,

// PRICE
export {

@@ -63,33 +156,34 @@ isPrice,

export { readAndParse } from "./readUtils.js";
// ABI
export {
erc20BalanceOf,
erc20Allowance,
erc20TotalSupply,
erc20Name,
erc20Symbol,
erc20Decimals,
getErc20,
getErc20Permit,
} from "./erc20/reads.js";
solmateErc20ABI as erc20ABI,
solmateErc721ABI as erc721ABI,
solmateErc1155ABI as erc1155ABI,
weth9ABI,
} from "./generated.js";
export { createErc20 } from "./erc20/utils.js";
// TYPES
export {
erc20Transfer,
erc20Approve,
erc20TransferFrom,
} from "./erc20/writes.js";
export type {
BaseERC20,
ERC20,
ERC20Permit,
ERC20Data,
ERC20Amount,
ERC20PermitData,
} from "./erc20/types.js";
export type { ERC20, ERC20Amount } from "./erc20/types.js";
export type { ERC721, ERC721IDData, ERC721Data } from "./erc721/types.js";
export { nativeBalance } from "./native/reads.js";
export type { ERC1155, ERC1155Data } from "./erc1155/types.js";
export { createNativeCurrency } from "./native/utils.js";
export type {
NativeCurrency,
NativeCurrencyAmount,
NativeCurrencyData,
} from "./native/types.js";
export type { NativeCurrency, NativeCurrencyAmount } from "./native/types.js";
export type { WETH } from "./weth/types.js";
export { erc20ABI } from "./generated.js";
export type {

@@ -103,2 +197,21 @@ BigIntIsh,

ReverseMirageWrite,
Tuple,
} from "./types.js";
// CONSTANTS
export {
type ChainTokens,
mainnetTokens,
sepoliaTokens,
goerliTokens,
optimismTokens,
optimismGoerliTokens,
arbitrumTokens,
arbitrumGoerliTokens,
baseTokens,
baseGoerliTokens,
celoTokens,
celoAlfajoresTokens,
foundryTokens,
} from "./constants.js";

@@ -6,11 +6,11 @@ import type { Address, PublicClient } from "viem";

export const nativeBalance = <TNativeCurrency extends NativeCurrency>(
publicClient: PublicClient,
args: { nativeCurrency: TNativeCurrency; address: Address },
) => {
return {
read: () => publicClient.getBalance({ address: args.address }),
export const nativeBalance = <TNativeCurrency extends NativeCurrency>(args: {
nativeCurrency: TNativeCurrency;
address: Address;
}) =>
({
read: (publicClient: PublicClient) =>
publicClient.getBalance({ address: args.address }),
parse: (data): NativeCurrencyAmount<TNativeCurrency> =>
createAmountFromRaw(args.nativeCurrency, data),
} satisfies ReverseMirageRead<bigint>;
};
}) as const satisfies ReverseMirageRead<bigint>;
import type { Token, TokenData } from "../types.js";
export type NativeCurrency = Token<"nativeCurrency"> & {
name: string;
symbol: string;
decimals: number;
};
export type NativeCurrencyData<TNativeCurrency extends NativeCurrency> =
TokenData<
TNativeCurrency,
`${TNativeCurrency["type"]}Amount`,
{ amount: bigint }
>;
export type NativeCurrencyAmount<TNativeCurrency extends NativeCurrency> =
TokenData<TNativeCurrency, { amount: bigint }>;
TokenData<
TNativeCurrency,
`${TNativeCurrency["type"]}Amount`,
{ amount: bigint }
>;

@@ -14,4 +14,7 @@ import invariant from "tiny-invariant";

} from "./fractionUtils.js";
import type { BigIntIsh, Fraction, Price } from "./types.js";
import type { BigIntIsh, Fraction, Price, Token } from "./types.js";
/**
* Returns true if {@link x} is of type {@link Price}
*/
export const isPrice = <

@@ -24,2 +27,8 @@ TQuoteCurrency extends Amount["token"],

/**
* Creates a {@link Price} from two {@link Token}s and a {@link Fraction}
* @param quote The quote asset in the price (i.e. USD in traditional equites markets)
* @param base The base asset in the price
* @param price The exchange rate in units of {@link base} per {@link quote} as a {@link Fraction}
*/
export const createPriceFromFraction = <

@@ -44,2 +53,7 @@ TQuoteCurrency extends Amount["token"],

/**
* Creates a {@link Price} from two {@link Amount}s
* @param quote The quote amount in the price (i.e. USD in traditional equites markets)
* @param base The base amount in the price
*/
export const createPriceFromAmounts = <

@@ -59,2 +73,9 @@ TQuoteCurrency extends Amount["token"],

/**
* Creates a {@link Price} from two {@link Token}s and a {@link numerator} and {@link denominator}
* @param quote The quote asset in the price (i.e. USD in traditional equites markets)
* @param base The base asset in the price
* @param numerator The numerator in the price
* @param denominator The denominator in the price
*/
export const createPrice = <

@@ -80,2 +101,5 @@ TQuoteCurrency extends Amount["token"],

/**
* Calculates the inverse
*/
export const priceInvert = <

@@ -93,2 +117,5 @@ TQuoteCurrency extends Amount["token"],

/**
* Adds {@link a} with {@link b}
*/
export const priceAdd = <

@@ -117,2 +144,5 @@ TBaseCurrency extends Amount["token"],

/**
* Subtracts {@link a} by {@link b}
*/
export const priceSubtract = <

@@ -141,2 +171,5 @@ TQuoteCurrency extends Amount["token"],

/**
* Multiplies {@link a} with {@link b}
*/
export const priceMultiply = <

@@ -172,2 +205,5 @@ TQuoteCurrency extends Amount["token"],

/**
* Divides {@link a} by {@link b}
*/
export const priceDivide = <

@@ -203,2 +239,5 @@ TQuoteCurrency extends Amount["token"],

/**
* Returns true if {@link a} is less than {@link b}
*/
export const priceLessThan = <

@@ -218,2 +257,5 @@ TQuoteCurrency extends Amount["token"],

/**
* Returns true if {@link a} is equal to {@link b}
*/
export const priceEqualTo = <

@@ -233,2 +275,5 @@ TQuoteCurrency extends Amount["token"],

/**
* Returns true if {@link a} is greater than {@link b}
*/
export const priceGreaterThan = <

@@ -248,2 +293,5 @@ TQuoteCurrency extends Amount["token"],

/**
* Returns the amount of quote currency corresponding to the {@link amount} of base currency at a given {@link price}
*/
export const priceQuote = <

@@ -264,2 +312,5 @@ TQuoteCurrency extends Amount["token"],

/**
* Returns the price as a {@link Fraction} without adjusting for decimals
*/
export const rawPrice = (

@@ -273,2 +324,5 @@ price: Price<Amount["token"], Amount["token"]>,

/**
* Returns the price as a {@link Fraction} with adjusting for decimals
*/
export const adjustedPrice = (

@@ -286,4 +340,7 @@ price: Price<Amount["token"], Amount["token"]>,

/**
* Returns the {@link price} as a number with an adjustment for decimals
*/
export const priceToNumber = (
price: Price<Amount["token"], Amount["token"]>,
): number => fractionToNumber(adjustedPrice(price));

@@ -0,7 +1,12 @@

import type { PublicClient } from "viem";
import type { ReverseMirageRead } from "./types.js";
/**
* Read data using a json-rpc request and parse the returned data
*/
export const readAndParse = async <TRet, TParse>(
publicClient: PublicClient,
reverseMirageRead: ReverseMirageRead<TRet, TParse>,
) => {
return reverseMirageRead.parse(await reverseMirageRead.read());
return reverseMirageRead.parse(await reverseMirageRead.read(publicClient));
};

@@ -1,2 +0,2 @@

import type { Abi, Hash, SimulateContractReturnType } from "viem";
import type { Abi, Hash, PublicClient, SimulateContractReturnType } from "viem";

@@ -13,9 +13,11 @@ export type BigIntIsh = bigint | string | number;

type: TType;
name: string;
symbol: string;
chainID: number;
};
export type TokenData<TToken extends Token, TData extends object> = {
type: `${TToken["type"]}${string}`;
export type TokenData<
TToken extends Token = Token,
TType extends `${TToken["type"]}${string}` = `${TToken["type"]}${string}`,
TData extends object = object,
> = {
type: TType;
token: TToken;

@@ -34,3 +36,3 @@ } & TData;

export type ReverseMirageRead<TRet = unknown, TParse = unknown> = {
read: () => TRet | Promise<TRet>;
read: (publicClient: PublicClient) => TRet | Promise<TRet>;
parse: (data: TRet) => TParse;

@@ -47,1 +49,14 @@ };

}>;
/**
* A tuple of length `N` with elements of type `T`.
* @see https://github.com/saber-hq/saber-common/blob/master/packages/tuple-utils/src/tuple.ts
*/
export type Tuple<T, N extends number> = N extends N
? number extends N
? T[]
: _TupleOf<T, N, []>
: never;
type _TupleOf<T, N extends number, R extends T[]> = R["length"] extends N
? R
: _TupleOf<T, N, [T, ...R]>;

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc