reverse-mirage
Advanced tools
Comparing version 0.1.5 to 0.1.6
@@ -48,9 +48,9 @@ import { Abi, Hash, SimulateContractReturnType, PublicClient, Address as Address$1, WalletClient, Account } from 'viem'; | ||
declare const isAmount: <TAmount extends Amount<Token>>(x: BigIntIsh | TAmount) => x is TAmount; | ||
declare const makeAmountFromString: <TToken extends Token & { | ||
declare const createAmountFromString: <TToken extends Token & { | ||
decimals?: number; | ||
}>(token: TToken, amount: string) => Amount<TToken>; | ||
declare const makeAmountFromFraction: <TToken extends Token & { | ||
declare const createAmountFromFraction: <TToken extends Token & { | ||
decimals?: number; | ||
}>(token: TToken, amount: Fraction) => Amount<TToken>; | ||
declare const makeAmountFromRaw: <TToken extends Token & { | ||
declare const createAmountFromRaw: <TToken extends Token & { | ||
decimals?: number; | ||
@@ -87,3 +87,3 @@ }>(token: TToken, amount: bigint) => Amount<TToken>; | ||
*/ | ||
declare const makeFraction: (numerator: BigIntIsh, denominator?: BigIntIsh) => Fraction; | ||
declare const createFraction: (numerator: BigIntIsh, denominator?: BigIntIsh) => Fraction; | ||
/** | ||
@@ -135,3 +135,3 @@ * Calculate the quotient | ||
}>(x: BigIntIsh | Price<TQuoteCurrency, TBaseCurrency>) => x is Price<TQuoteCurrency, TBaseCurrency>; | ||
declare const makePriceFromFraction: <TQuoteCurrency extends Token & { | ||
declare const createPriceFromFraction: <TQuoteCurrency extends Token & { | ||
decimals?: number; | ||
@@ -141,3 +141,3 @@ }, TBaseCurrency extends Token & { | ||
}>(quote: TQuoteCurrency, base: TBaseCurrency, price: Fraction) => Price<TQuoteCurrency, TBaseCurrency>; | ||
declare const makePriceFromAmounts: <TQuoteCurrency extends Token & { | ||
declare const createPriceFromAmounts: <TQuoteCurrency extends Token & { | ||
decimals?: number; | ||
@@ -147,3 +147,3 @@ }, TBaseCurrency extends Token & { | ||
}>(quote: Amount<TQuoteCurrency>, base: Amount<TBaseCurrency>) => Price<TQuoteCurrency, TBaseCurrency>; | ||
declare const makePrice: <TQuoteCurrency extends Token & { | ||
declare const createPrice: <TQuoteCurrency extends Token & { | ||
decimals?: number; | ||
@@ -215,15 +215,17 @@ }, TBaseCurrency extends Token & { | ||
}; | ||
type ERC20Amount<TERC20 extends ERC20> = TokenData<TERC20, { | ||
amount: bigint; | ||
}>; | ||
type ERC20Permit = ERC20 & { | ||
version: string; | ||
}; | ||
type ERC20Data<TERC20 extends ERC20> = Amount<TERC20>; | ||
type ERC20Amount<TERC20 extends ERC20> = ERC20Data<TERC20>; | ||
declare const erc20BalanceOf: (publicClient: PublicClient, args: { | ||
erc20: ERC20; | ||
declare const erc20BalanceOf: <TERC20 extends ERC20>(publicClient: PublicClient, args: { | ||
erc20: TERC20; | ||
address: Address$1; | ||
}) => { | ||
read: () => Promise<bigint>; | ||
parse: (data: bigint) => Amount<ERC20>; | ||
parse: (data: bigint) => ERC20Amount<TERC20>; | ||
}; | ||
declare const erc20Allowance: (publicClient: PublicClient, args: { | ||
erc20: ERC20; | ||
declare const erc20Allowance: <TERC20 extends ERC20>(publicClient: PublicClient, args: { | ||
erc20: TERC20; | ||
address: Address$1; | ||
@@ -233,9 +235,9 @@ spender: Address$1; | ||
read: () => Promise<bigint>; | ||
parse: (data: bigint) => Amount<ERC20>; | ||
parse: (data: bigint) => ERC20Amount<TERC20>; | ||
}; | ||
declare const erc20TotalSupply: (publicClient: PublicClient, args: { | ||
erc20: ERC20; | ||
declare const erc20TotalSupply: <TERC20 extends ERC20>(publicClient: PublicClient, args: { | ||
erc20: TERC20; | ||
}) => { | ||
read: () => Promise<bigint>; | ||
parse: (data: bigint) => Amount<ERC20>; | ||
parse: (data: bigint) => ERC20Amount<TERC20>; | ||
}; | ||
@@ -260,156 +262,243 @@ declare const erc20Name: (publicClient: PublicClient, args: { | ||
}; | ||
declare const erc20GetToken: (publicClient: PublicClient, args: { | ||
declare const getErc20: (publicClient: PublicClient, args: { | ||
erc20: Pick<ERC20, "address" | "chainID">; | ||
}) => { | ||
read: () => Promise<[string, string, number]>; | ||
parse: (data: [string, string, number]) => { | ||
chainID: number; | ||
address: `0x${string}`; | ||
name: string; | ||
symbol: string; | ||
decimals: number; | ||
}; | ||
parse: (data: [string, string, number]) => ERC20; | ||
}; | ||
declare const getErc20Permit: (publicClient: PublicClient, args: { | ||
erc20: Pick<ERC20Permit, "address" | "chainID"> & Partial<Pick<ERC20Permit, "version">>; | ||
}) => { | ||
read: () => Promise<[string, string, number]>; | ||
parse: (data: [string, string, number]) => ERC20Permit; | ||
}; | ||
declare const createErc20: (address: Address$1, name: string, symbol: string, decimals: number, chainID: number) => ERC20; | ||
declare const erc20ABI: readonly [{ | ||
readonly type: "event"; | ||
readonly name: "Approval"; | ||
readonly anonymous: false; | ||
readonly inputs: readonly [{ | ||
readonly indexed: true; | ||
readonly name: "owner"; | ||
readonly internalType: "address"; | ||
readonly type: "address"; | ||
readonly indexed: true; | ||
}, { | ||
readonly indexed: true; | ||
readonly name: "spender"; | ||
readonly internalType: "address"; | ||
readonly type: "address"; | ||
readonly indexed: true; | ||
}, { | ||
readonly name: "amount"; | ||
readonly internalType: "uint256"; | ||
readonly type: "uint256"; | ||
readonly indexed: false; | ||
readonly name: "value"; | ||
readonly type: "uint256"; | ||
}]; | ||
readonly name: "Approval"; | ||
}, { | ||
readonly type: "event"; | ||
readonly name: "Transfer"; | ||
readonly anonymous: false; | ||
readonly inputs: readonly [{ | ||
readonly indexed: true; | ||
readonly name: "from"; | ||
readonly internalType: "address"; | ||
readonly type: "address"; | ||
readonly indexed: true; | ||
}, { | ||
readonly indexed: true; | ||
readonly name: "to"; | ||
readonly internalType: "address"; | ||
readonly type: "address"; | ||
readonly indexed: true; | ||
}, { | ||
readonly name: "amount"; | ||
readonly internalType: "uint256"; | ||
readonly type: "uint256"; | ||
readonly indexed: false; | ||
readonly name: "value"; | ||
readonly type: "uint256"; | ||
}]; | ||
readonly name: "Transfer"; | ||
}, { | ||
readonly stateMutability: "view"; | ||
readonly type: "function"; | ||
readonly name: "allowance"; | ||
readonly inputs: readonly []; | ||
readonly name: "DOMAIN_SEPARATOR"; | ||
readonly outputs: readonly [{ | ||
readonly name: ""; | ||
readonly internalType: "bytes32"; | ||
readonly type: "bytes32"; | ||
}]; | ||
}, { | ||
readonly stateMutability: "view"; | ||
readonly type: "function"; | ||
readonly inputs: readonly [{ | ||
readonly name: "owner"; | ||
readonly name: ""; | ||
readonly internalType: "address"; | ||
readonly type: "address"; | ||
}, { | ||
readonly name: "spender"; | ||
readonly name: ""; | ||
readonly internalType: "address"; | ||
readonly type: "address"; | ||
}]; | ||
readonly name: "allowance"; | ||
readonly outputs: readonly [{ | ||
readonly name: ""; | ||
readonly internalType: "uint256"; | ||
readonly type: "uint256"; | ||
}]; | ||
}, { | ||
readonly stateMutability: "nonpayable"; | ||
readonly type: "function"; | ||
readonly name: "approve"; | ||
readonly stateMutability: "nonpayable"; | ||
readonly inputs: readonly [{ | ||
readonly name: "spender"; | ||
readonly internalType: "address"; | ||
readonly type: "address"; | ||
}, { | ||
readonly name: "amount"; | ||
readonly internalType: "uint256"; | ||
readonly type: "uint256"; | ||
}]; | ||
readonly name: "approve"; | ||
readonly outputs: readonly [{ | ||
readonly name: ""; | ||
readonly internalType: "bool"; | ||
readonly type: "bool"; | ||
}]; | ||
}, { | ||
readonly stateMutability: "view"; | ||
readonly type: "function"; | ||
readonly name: "balanceOf"; | ||
readonly stateMutability: "view"; | ||
readonly inputs: readonly [{ | ||
readonly name: "account"; | ||
readonly name: ""; | ||
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: "decimals"; | ||
readonly stateMutability: "view"; | ||
readonly inputs: readonly []; | ||
readonly outputs: readonly [{ | ||
readonly name: ""; | ||
readonly internalType: "uint8"; | ||
readonly type: "uint8"; | ||
}]; | ||
}, { | ||
readonly stateMutability: "view"; | ||
readonly type: "function"; | ||
readonly inputs: readonly []; | ||
readonly name: "name"; | ||
readonly stateMutability: "view"; | ||
readonly inputs: readonly []; | ||
readonly outputs: readonly [{ | ||
readonly name: ""; | ||
readonly internalType: "string"; | ||
readonly type: "string"; | ||
}]; | ||
}, { | ||
readonly stateMutability: "view"; | ||
readonly type: "function"; | ||
readonly name: "symbol"; | ||
readonly inputs: readonly [{ | ||
readonly name: ""; | ||
readonly internalType: "address"; | ||
readonly type: "address"; | ||
}]; | ||
readonly name: "nonces"; | ||
readonly outputs: readonly [{ | ||
readonly name: ""; | ||
readonly internalType: "uint256"; | ||
readonly type: "uint256"; | ||
}]; | ||
}, { | ||
readonly stateMutability: "nonpayable"; | ||
readonly type: "function"; | ||
readonly inputs: readonly [{ | ||
readonly name: "owner"; | ||
readonly internalType: "address"; | ||
readonly type: "address"; | ||
}, { | ||
readonly name: "spender"; | ||
readonly internalType: "address"; | ||
readonly type: "address"; | ||
}, { | ||
readonly name: "value"; | ||
readonly internalType: "uint256"; | ||
readonly type: "uint256"; | ||
}, { | ||
readonly name: "deadline"; | ||
readonly internalType: "uint256"; | ||
readonly type: "uint256"; | ||
}, { | ||
readonly name: "v"; | ||
readonly internalType: "uint8"; | ||
readonly type: "uint8"; | ||
}, { | ||
readonly name: "r"; | ||
readonly internalType: "bytes32"; | ||
readonly type: "bytes32"; | ||
}, { | ||
readonly name: "s"; | ||
readonly internalType: "bytes32"; | ||
readonly type: "bytes32"; | ||
}]; | ||
readonly name: "permit"; | ||
readonly outputs: readonly []; | ||
}, { | ||
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: "totalSupply"; | ||
readonly stateMutability: "view"; | ||
readonly inputs: readonly []; | ||
readonly outputs: readonly [{ | ||
readonly name: ""; | ||
readonly internalType: "uint256"; | ||
readonly type: "uint256"; | ||
}]; | ||
}, { | ||
readonly stateMutability: "nonpayable"; | ||
readonly type: "function"; | ||
readonly name: "transfer"; | ||
readonly stateMutability: "nonpayable"; | ||
readonly inputs: readonly [{ | ||
readonly name: "recipient"; | ||
readonly name: "to"; | ||
readonly internalType: "address"; | ||
readonly type: "address"; | ||
}, { | ||
readonly name: "amount"; | ||
readonly internalType: "uint256"; | ||
readonly type: "uint256"; | ||
}]; | ||
readonly name: "transfer"; | ||
readonly outputs: readonly [{ | ||
readonly name: ""; | ||
readonly internalType: "bool"; | ||
readonly type: "bool"; | ||
}]; | ||
}, { | ||
readonly stateMutability: "nonpayable"; | ||
readonly type: "function"; | ||
readonly name: "transferFrom"; | ||
readonly stateMutability: "nonpayable"; | ||
readonly inputs: readonly [{ | ||
readonly name: "sender"; | ||
readonly name: "from"; | ||
readonly internalType: "address"; | ||
readonly type: "address"; | ||
}, { | ||
readonly name: "recipient"; | ||
readonly name: "to"; | ||
readonly internalType: "address"; | ||
readonly type: "address"; | ||
}, { | ||
readonly name: "amount"; | ||
readonly internalType: "uint256"; | ||
readonly type: "uint256"; | ||
}]; | ||
readonly name: "transferFrom"; | ||
readonly outputs: readonly [{ | ||
readonly name: ""; | ||
readonly internalType: "bool"; | ||
readonly type: "bool"; | ||
@@ -440,10 +529,12 @@ }]; | ||
declare const nativeBalance: (publicClient: PublicClient, args: { | ||
nativeCurrency: NativeCurrency; | ||
declare const nativeBalance: <TNativeCurrency extends NativeCurrency>(publicClient: PublicClient, args: { | ||
nativeCurrency: TNativeCurrency; | ||
address: Address$1; | ||
}) => { | ||
read: () => Promise<bigint>; | ||
parse: (data: bigint) => Amount<NativeCurrency>; | ||
parse: (data: bigint) => NativeCurrencyAmount<TNativeCurrency>; | ||
}; | ||
export { 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, erc20Allowance, erc20Approve, erc20BalanceOf, erc20Decimals, erc20GetToken, erc20Name, erc20Symbol, erc20TotalSupply, erc20Transfer, erc20TransferFrom, fractionAdd, fractionDivide, fractionEqualTo, fractionGreaterThan, fractionInvert, fractionLessThan, fractionMultiply, fractionQuotient, fractionRemainder, fractionSubtract, isAmount, isFraction, isPrice, makeAmountFromFraction, makeAmountFromRaw, makeAmountFromString, makeFraction, makePrice, makePriceFromAmounts, makePriceFromFraction, nativeBalance, priceAdd, priceDivide, priceEqualTo, priceGreaterThan, priceInvert, priceLessThan, priceMultiply, priceQuote, priceSubtract, rawPrice, readAndParse }; | ||
declare const createNativeCurrency: (name: string, symbol: string, decimals: number, chainID: number) => NativeCurrency; | ||
export { Amount, BigIntIsh, ERC20, ERC20Amount, Fraction, MaxUint128, MaxUint16, MaxUint256, MaxUint32, MaxUint64, MaxUint8, NativeCurrency, NativeCurrencyAmount, Price, ReverseMirageRead, ReverseMirageWrite, Token, TokenData, adjustedPrice, amountAdd, amountDivide, amountEqualTo, amountGreaterThan, amountLessThan, amountMultiply, amountSubtract, createAmountFromFraction, createAmountFromRaw, createAmountFromString, createErc20, createFraction, createNativeCurrency, createPrice, createPriceFromAmounts, createPriceFromFraction, erc20ABI, erc20Allowance, erc20Approve, erc20BalanceOf, erc20Decimals, erc20Name, erc20Symbol, erc20TotalSupply, erc20Transfer, erc20TransferFrom, fractionAdd, fractionDivide, fractionEqualTo, fractionGreaterThan, fractionInvert, fractionLessThan, fractionMultiply, fractionQuotient, fractionRemainder, fractionSubtract, getErc20, getErc20Permit, isAmount, isFraction, isPrice, nativeBalance, priceAdd, priceDivide, priceEqualTo, priceGreaterThan, priceInvert, priceLessThan, priceMultiply, priceQuote, priceSubtract, rawPrice, readAndParse }; |
@@ -15,3 +15,3 @@ // src/constants.ts | ||
var isAmount = (x) => typeof x === "object" && "amount" in x; | ||
var makeAmountFromString = (token, amount) => ({ | ||
var createAmountFromString = (token, amount) => ({ | ||
type: `${token.type}Amount`, | ||
@@ -21,3 +21,3 @@ token, | ||
}); | ||
var makeAmountFromFraction = (token, amount) => ({ | ||
var createAmountFromFraction = (token, amount) => ({ | ||
type: `${token.type}Amount`, | ||
@@ -27,3 +27,3 @@ token, | ||
}); | ||
var makeAmountFromRaw = (token, amount) => ({ | ||
var createAmountFromRaw = (token, amount) => ({ | ||
type: `${token.type}Amount`, | ||
@@ -37,3 +37,3 @@ token, | ||
} | ||
return isAmount(b) ? makeAmountFromRaw(a.token, a.amount + b.amount) : makeAmountFromRaw(a.token, a.amount + scaleUp(a.token, BigInt(b))); | ||
return isAmount(b) ? createAmountFromRaw(a.token, a.amount + b.amount) : createAmountFromRaw(a.token, a.amount + scaleUp(a.token, BigInt(b))); | ||
}; | ||
@@ -44,3 +44,3 @@ var amountSubtract = (a, b) => { | ||
} | ||
return isAmount(b) ? makeAmountFromRaw(a.token, a.amount - b.amount) : makeAmountFromRaw(a.token, a.amount - scaleUp(a.token, BigInt(b))); | ||
return isAmount(b) ? createAmountFromRaw(a.token, a.amount - b.amount) : createAmountFromRaw(a.token, a.amount - scaleUp(a.token, BigInt(b))); | ||
}; | ||
@@ -51,3 +51,3 @@ var amountMultiply = (a, b) => { | ||
} | ||
return isAmount(b) ? makeAmountFromRaw(a.token, scaleDown(a.token, a.amount * b.amount)) : makeAmountFromRaw(a.token, a.amount * BigInt(b)); | ||
return isAmount(b) ? createAmountFromRaw(a.token, scaleDown(a.token, a.amount * b.amount)) : createAmountFromRaw(a.token, a.amount * BigInt(b)); | ||
}; | ||
@@ -58,3 +58,3 @@ var amountDivide = (a, b) => { | ||
} | ||
return isAmount(b) ? makeAmountFromRaw(a.token, scaleUp(a.token, a.amount) / b.amount) : makeAmountFromRaw(a.token, a.amount / BigInt(b)); | ||
return isAmount(b) ? createAmountFromRaw(a.token, scaleUp(a.token, a.amount) / b.amount) : createAmountFromRaw(a.token, a.amount / BigInt(b)); | ||
}; | ||
@@ -83,3 +83,3 @@ var amountLessThan = (a, b) => { | ||
var isFraction = (x) => typeof x === "object" && "type" in x && x.type === "fraction"; | ||
var makeFraction = (numerator, denominator = 1) => { | ||
var createFraction = (numerator, denominator = 1) => { | ||
const d = BigInt(denominator); | ||
@@ -142,3 +142,3 @@ invariant2(d !== 0n, "Fraction: denominator equal to 0"); | ||
var isPrice = (x) => typeof x === "object" && "type" in x && x.type === "price"; | ||
var makePriceFromFraction = (quote, base, price) => ({ | ||
var createPriceFromFraction = (quote, base, price) => ({ | ||
type: "price", | ||
@@ -150,3 +150,3 @@ quote, | ||
}); | ||
var makePriceFromAmounts = (quote, base) => ({ | ||
var createPriceFromAmounts = (quote, base) => ({ | ||
type: "price", | ||
@@ -158,3 +158,3 @@ quote: quote.token, | ||
}); | ||
var makePrice = (quote, base, numerator, denominator = 1) => ({ | ||
var createPrice = (quote, base, numerator, denominator = 1) => ({ | ||
type: "price", | ||
@@ -180,3 +180,7 @@ quote, | ||
base: a.base | ||
} : makePriceFromFraction(a.quote, a.base, fractionAdd(adjustedPrice(a), b)); | ||
} : createPriceFromFraction( | ||
a.quote, | ||
a.base, | ||
fractionAdd(adjustedPrice(a), b) | ||
); | ||
}; | ||
@@ -191,3 +195,3 @@ var priceSubtract = (a, b) => { | ||
base: a.base | ||
} : makePriceFromFraction( | ||
} : createPriceFromFraction( | ||
a.quote, | ||
@@ -213,3 +217,3 @@ a.base, | ||
) | ||
} : makePriceFromFraction( | ||
} : createPriceFromFraction( | ||
a.quote, | ||
@@ -235,3 +239,3 @@ a.base, | ||
) | ||
} : makePriceFromFraction( | ||
} : createPriceFromFraction( | ||
a.quote, | ||
@@ -259,3 +263,3 @@ a.base, | ||
invariant3(price.base === amount.token); | ||
return makeAmountFromRaw( | ||
return createAmountFromRaw( | ||
price.quote, | ||
@@ -281,198 +285,148 @@ price.numerator * amount.amount / price.denominator | ||
// src/erc20/erc20Abi.ts | ||
// src/generated.ts | ||
var erc20ABI = [ | ||
{ | ||
type: "event", | ||
name: "Approval", | ||
anonymous: false, | ||
inputs: [ | ||
{ | ||
indexed: true, | ||
name: "owner", | ||
type: "address" | ||
internalType: "address", | ||
type: "address", | ||
indexed: true | ||
}, | ||
{ | ||
indexed: true, | ||
name: "spender", | ||
type: "address" | ||
internalType: "address", | ||
type: "address", | ||
indexed: true | ||
}, | ||
{ | ||
indexed: false, | ||
name: "value", | ||
type: "uint256" | ||
name: "amount", | ||
internalType: "uint256", | ||
type: "uint256", | ||
indexed: false | ||
} | ||
] | ||
], | ||
name: "Approval" | ||
}, | ||
{ | ||
type: "event", | ||
name: "Transfer", | ||
anonymous: false, | ||
inputs: [ | ||
{ name: "from", internalType: "address", type: "address", indexed: true }, | ||
{ name: "to", internalType: "address", type: "address", indexed: true }, | ||
{ | ||
indexed: true, | ||
name: "from", | ||
type: "address" | ||
}, | ||
{ | ||
indexed: true, | ||
name: "to", | ||
type: "address" | ||
}, | ||
{ | ||
indexed: false, | ||
name: "value", | ||
type: "uint256" | ||
name: "amount", | ||
internalType: "uint256", | ||
type: "uint256", | ||
indexed: false | ||
} | ||
] | ||
], | ||
name: "Transfer" | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
name: "allowance", | ||
inputs: [], | ||
name: "DOMAIN_SEPARATOR", | ||
outputs: [{ name: "", internalType: "bytes32", type: "bytes32" }] | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [ | ||
{ | ||
name: "owner", | ||
type: "address" | ||
}, | ||
{ | ||
name: "spender", | ||
type: "address" | ||
} | ||
{ name: "", internalType: "address", type: "address" }, | ||
{ name: "", internalType: "address", type: "address" } | ||
], | ||
outputs: [ | ||
{ | ||
name: "", | ||
type: "uint256" | ||
} | ||
] | ||
name: "allowance", | ||
outputs: [{ name: "", internalType: "uint256", type: "uint256" }] | ||
}, | ||
{ | ||
stateMutability: "nonpayable", | ||
type: "function", | ||
name: "approve", | ||
stateMutability: "nonpayable", | ||
inputs: [ | ||
{ | ||
name: "spender", | ||
type: "address" | ||
}, | ||
{ | ||
name: "amount", | ||
type: "uint256" | ||
} | ||
{ name: "spender", internalType: "address", type: "address" }, | ||
{ name: "amount", internalType: "uint256", type: "uint256" } | ||
], | ||
outputs: [ | ||
{ | ||
name: "", | ||
type: "bool" | ||
} | ||
] | ||
name: "approve", | ||
outputs: [{ name: "", internalType: "bool", type: "bool" }] | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [{ name: "", internalType: "address", type: "address" }], | ||
name: "balanceOf", | ||
stateMutability: "view", | ||
inputs: [ | ||
{ | ||
name: "account", | ||
type: "address" | ||
} | ||
], | ||
outputs: [ | ||
{ | ||
name: "", | ||
type: "uint256" | ||
} | ||
] | ||
outputs: [{ name: "", internalType: "uint256", type: "uint256" }] | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [], | ||
name: "decimals", | ||
outputs: [{ name: "", internalType: "uint8", type: "uint8" }] | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [], | ||
outputs: [ | ||
{ | ||
name: "", | ||
type: "uint8" | ||
} | ||
] | ||
name: "name", | ||
outputs: [{ name: "", internalType: "string", type: "string" }] | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
name: "name", | ||
stateMutability: "view", | ||
inputs: [], | ||
outputs: [ | ||
{ | ||
name: "", | ||
type: "string" | ||
} | ||
] | ||
inputs: [{ name: "", internalType: "address", type: "address" }], | ||
name: "nonces", | ||
outputs: [{ name: "", internalType: "uint256", type: "uint256" }] | ||
}, | ||
{ | ||
stateMutability: "nonpayable", | ||
type: "function", | ||
name: "symbol", | ||
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: [], | ||
outputs: [ | ||
{ | ||
name: "", | ||
type: "string" | ||
} | ||
] | ||
name: "symbol", | ||
outputs: [{ name: "", internalType: "string", type: "string" }] | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [], | ||
name: "totalSupply", | ||
stateMutability: "view", | ||
inputs: [], | ||
outputs: [ | ||
{ | ||
name: "", | ||
type: "uint256" | ||
} | ||
] | ||
outputs: [{ name: "", internalType: "uint256", type: "uint256" }] | ||
}, | ||
{ | ||
stateMutability: "nonpayable", | ||
type: "function", | ||
name: "transfer", | ||
stateMutability: "nonpayable", | ||
inputs: [ | ||
{ | ||
name: "recipient", | ||
type: "address" | ||
}, | ||
{ | ||
name: "amount", | ||
type: "uint256" | ||
} | ||
{ name: "to", internalType: "address", type: "address" }, | ||
{ name: "amount", internalType: "uint256", type: "uint256" } | ||
], | ||
outputs: [ | ||
{ | ||
name: "", | ||
type: "bool" | ||
} | ||
] | ||
name: "transfer", | ||
outputs: [{ name: "", internalType: "bool", type: "bool" }] | ||
}, | ||
{ | ||
stateMutability: "nonpayable", | ||
type: "function", | ||
name: "transferFrom", | ||
stateMutability: "nonpayable", | ||
inputs: [ | ||
{ | ||
name: "sender", | ||
type: "address" | ||
}, | ||
{ | ||
name: "recipient", | ||
type: "address" | ||
}, | ||
{ | ||
name: "amount", | ||
type: "uint256" | ||
} | ||
{ name: "from", internalType: "address", type: "address" }, | ||
{ name: "to", internalType: "address", type: "address" }, | ||
{ name: "amount", internalType: "uint256", type: "uint256" } | ||
], | ||
outputs: [ | ||
{ | ||
name: "", | ||
type: "bool" | ||
} | ||
] | ||
name: "transferFrom", | ||
outputs: [{ name: "", internalType: "bool", type: "bool" }] | ||
} | ||
@@ -482,2 +436,3 @@ ]; | ||
// src/erc20/reads.ts | ||
import { getAddress } from "viem"; | ||
var erc20BalanceOf = (publicClient, args) => { | ||
@@ -491,3 +446,3 @@ return { | ||
}), | ||
parse: (data) => makeAmountFromRaw(args.erc20, data) | ||
parse: (data) => createAmountFromRaw(args.erc20, data) | ||
}; | ||
@@ -503,3 +458,3 @@ }; | ||
}), | ||
parse: (data) => makeAmountFromRaw(args.erc20, data) | ||
parse: (data) => createAmountFromRaw(args.erc20, data) | ||
}; | ||
@@ -514,3 +469,3 @@ }; | ||
}), | ||
parse: (data) => makeAmountFromRaw(args.erc20, data) | ||
parse: (data) => createAmountFromRaw(args.erc20, data) | ||
}; | ||
@@ -548,3 +503,3 @@ }; | ||
}; | ||
var erc20GetToken = (publicClient, args) => { | ||
var getErc20 = (publicClient, args) => { | ||
return { | ||
@@ -557,11 +512,43 @@ read: () => Promise.all([ | ||
parse: (data) => ({ | ||
type: "erc20", | ||
name: data[0], | ||
symbol: data[1], | ||
decimals: data[2], | ||
...args.erc20 | ||
address: getAddress(args.erc20.address), | ||
chainID: args.erc20.chainID | ||
}) | ||
}; | ||
}; | ||
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 | ||
}); | ||
// src/erc20/writes.ts | ||
import invariant4 from "tiny-invariant"; | ||
var erc20Transfer = async (publicClient, walletClient, account, args) => { | ||
@@ -605,5 +592,14 @@ const { request, result } = await publicClient.simulateContract({ | ||
read: () => publicClient.getBalance({ address: args.address }), | ||
parse: (data) => makeAmountFromRaw(args.nativeCurrency, data) | ||
parse: (data) => createAmountFromRaw(args.nativeCurrency, data) | ||
}; | ||
}; | ||
// src/native/utils.ts | ||
var createNativeCurrency = (name, symbol, decimals, chainID) => ({ | ||
type: "nativeCurrency", | ||
name, | ||
symbol, | ||
decimals, | ||
chainID | ||
}); | ||
export { | ||
@@ -624,2 +620,12 @@ MaxUint128, | ||
amountSubtract, | ||
createAmountFromFraction, | ||
createAmountFromRaw, | ||
createAmountFromString, | ||
createErc20, | ||
createFraction, | ||
createNativeCurrency, | ||
createPrice, | ||
createPriceFromAmounts, | ||
createPriceFromFraction, | ||
erc20ABI, | ||
erc20Allowance, | ||
@@ -629,3 +635,2 @@ erc20Approve, | ||
erc20Decimals, | ||
erc20GetToken, | ||
erc20Name, | ||
@@ -646,12 +651,7 @@ erc20Symbol, | ||
fractionSubtract, | ||
getErc20, | ||
getErc20Permit, | ||
isAmount, | ||
isFraction, | ||
isPrice, | ||
makeAmountFromFraction, | ||
makeAmountFromRaw, | ||
makeAmountFromString, | ||
makeFraction, | ||
makePrice, | ||
makePriceFromAmounts, | ||
makePriceFromFraction, | ||
nativeBalance, | ||
@@ -658,0 +658,0 @@ priceAdd, |
{ | ||
"name": "reverse-mirage", | ||
"version": "0.1.5", | ||
"description": "", | ||
"version": "0.1.6", | ||
"description": "Application level typescript utilities for Ethereum", | ||
"type": "module", | ||
"sideEffects": false, | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.js", | ||
"types": "./dist/types/index.d.ts", | ||
"typings": "./dist/types/index.d.ts", | ||
"types": "./dist/index.d.ts", | ||
"typings": "./dist/index.d.ts", | ||
"files": [ | ||
@@ -18,11 +19,31 @@ "dist", | ||
], | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"keywords": [ | ||
"eth", | ||
"ethereum", | ||
"dapps", | ||
"web3" | ||
], | ||
"author": "Kyle Scott", | ||
"license": "MIT", | ||
"repository": "kyscott18/reverse-mirage", | ||
"exports": { | ||
".": { | ||
"types": "./dist/types/index.d.ts", | ||
"import": "./dist/index.js" | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.js", | ||
"default": "./dist/cjs/index.js" | ||
} | ||
}, | ||
"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": { | ||
@@ -35,7 +56,4 @@ "tiny-invariant": "^1.3.1" | ||
"devDependencies": { | ||
"@changesets/cli": "^2.26.2", | ||
"@uniswap/sdk-core": "^4.0.6", | ||
"@viem/anvil": "^0.0.6", | ||
"@wagmi/cli": "^1.3.0", | ||
"husky": "^8.0.3", | ||
"rome": "^12.1.3", | ||
@@ -47,2 +65,3 @@ "tsup": "^7.1.0", | ||
}, | ||
"packageManager": "pnpm@8.6.10", | ||
"scripts": { | ||
@@ -56,4 +75,5 @@ "bench": "vitest bench", | ||
"typecheck": "tsc --noEmit", | ||
"test": "vitest" | ||
"test": "vitest", | ||
"test:ci": "CI=true vitest" | ||
} | ||
} |
@@ -20,3 +20,3 @@ import type { BigIntIsh, Fraction, Token, TokenData } from "./types.js"; | ||
export const makeAmountFromString = <TToken extends Amount["token"]>( | ||
export const createAmountFromString = <TToken extends Amount["token"]>( | ||
token: TToken, | ||
@@ -30,3 +30,3 @@ amount: string, | ||
export const makeAmountFromFraction = <TToken extends Amount["token"]>( | ||
export const createAmountFromFraction = <TToken extends Amount["token"]>( | ||
token: TToken, | ||
@@ -40,3 +40,3 @@ amount: Fraction, | ||
export const makeAmountFromRaw = <TToken extends Amount["token"]>( | ||
export const createAmountFromRaw = <TToken extends Amount["token"]>( | ||
token: TToken, | ||
@@ -59,4 +59,4 @@ amount: bigint, | ||
return isAmount(b) | ||
? makeAmountFromRaw(a.token, a.amount + b.amount) | ||
: makeAmountFromRaw(a.token, a.amount + scaleUp(a.token, BigInt(b))); | ||
? createAmountFromRaw(a.token, a.amount + b.amount) | ||
: createAmountFromRaw(a.token, a.amount + scaleUp(a.token, BigInt(b))); | ||
}; | ||
@@ -73,4 +73,4 @@ | ||
return isAmount(b) | ||
? makeAmountFromRaw(a.token, a.amount - b.amount) | ||
: makeAmountFromRaw(a.token, a.amount - scaleUp(a.token, BigInt(b))); | ||
? createAmountFromRaw(a.token, a.amount - b.amount) | ||
: createAmountFromRaw(a.token, a.amount - scaleUp(a.token, BigInt(b))); | ||
}; | ||
@@ -87,4 +87,4 @@ | ||
return isAmount(b) | ||
? makeAmountFromRaw(a.token, scaleDown(a.token, a.amount * b.amount)) | ||
: makeAmountFromRaw(a.token, a.amount * BigInt(b)); | ||
? createAmountFromRaw(a.token, scaleDown(a.token, a.amount * b.amount)) | ||
: createAmountFromRaw(a.token, a.amount * BigInt(b)); | ||
}; | ||
@@ -101,4 +101,4 @@ | ||
return isAmount(b) | ||
? makeAmountFromRaw(a.token, scaleUp(a.token, a.amount) / b.amount) | ||
: makeAmountFromRaw(a.token, a.amount / BigInt(b)); | ||
? createAmountFromRaw(a.token, scaleUp(a.token, a.amount) / b.amount) | ||
: createAmountFromRaw(a.token, a.amount / BigInt(b)); | ||
}; | ||
@@ -105,0 +105,0 @@ |
@@ -1,10 +0,15 @@ | ||
import { makeAmountFromRaw } from "../amountUtils.js"; | ||
import { erc20ABI } from "../erc20/erc20Abi.js"; | ||
import { createAmountFromRaw } from "../amountUtils.js"; | ||
import { erc20ABI } from "../generated.js"; | ||
import type { ReverseMirageRead } from "../types.js"; | ||
import type { ERC20 } from "./types.js"; | ||
import type { Address, PublicClient } from "viem"; | ||
import type { | ||
ERC20, | ||
ERC20Amount, | ||
ERC20Permit, | ||
ERC20PermitData, | ||
} from "./types.js"; | ||
import { type Address, type Hex, type PublicClient, getAddress } from "viem"; | ||
export const erc20BalanceOf = ( | ||
export const erc20BalanceOf = <TERC20 extends ERC20>( | ||
publicClient: PublicClient, | ||
args: { erc20: ERC20; address: Address }, | ||
args: { erc20: TERC20; address: Address }, | ||
) => { | ||
@@ -19,9 +24,9 @@ return { | ||
}), | ||
parse: (data) => makeAmountFromRaw(args.erc20, data), | ||
parse: (data): ERC20Amount<TERC20> => createAmountFromRaw(args.erc20, data), | ||
} satisfies ReverseMirageRead<bigint>; | ||
}; | ||
export const erc20Allowance = ( | ||
export const erc20PermitNonce = ( | ||
publicClient: PublicClient, | ||
args: { erc20: ERC20; address: Address; spender: Address }, | ||
args: { erc20: ERC20; address: Address }, | ||
) => { | ||
@@ -33,12 +38,55 @@ return { | ||
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", | ||
args: [args.address, args.spender], | ||
}), | ||
parse: (data) => makeAmountFromRaw(args.erc20, data), | ||
parse: (data): ERC20Amount<TERC20> => createAmountFromRaw(args.erc20, data), | ||
} satisfies ReverseMirageRead<bigint>; | ||
}; | ||
export const erc20TotalSupply = ( | ||
export const erc20TotalSupply = <TERC20 extends ERC20>( | ||
publicClient: PublicClient, | ||
args: { erc20: ERC20 }, | ||
args: { erc20: TERC20 }, | ||
) => { | ||
@@ -52,3 +100,3 @@ return { | ||
}), | ||
parse: (data) => makeAmountFromRaw(args.erc20, data), | ||
parse: (data): ERC20Amount<TERC20> => createAmountFromRaw(args.erc20, data), | ||
} satisfies ReverseMirageRead<bigint>; | ||
@@ -102,4 +150,19 @@ }; | ||
export const erc20GetToken = ( | ||
export const erc20PermitDomainSeparator = ( | ||
publicClient: PublicClient, | ||
args: { erc20: Pick<ERC20Permit, "address"> }, | ||
) => { | ||
return { | ||
read: () => | ||
publicClient.readContract({ | ||
abi: erc20ABI, | ||
address: args.erc20.address, | ||
functionName: "DOMAIN_SEPARATOR", | ||
}), | ||
parse: (data) => data, | ||
} satisfies ReverseMirageRead<Hex>; | ||
}; | ||
export const getErc20 = ( | ||
publicClient: PublicClient, | ||
args: { erc20: Pick<ERC20, "address" | "chainID"> }, | ||
@@ -114,9 +177,39 @@ ) => { | ||
]), | ||
parse: (data) => ({ | ||
parse: (data): ERC20 => ({ | ||
type: "erc20", | ||
name: data[0], | ||
symbol: data[1], | ||
decimals: data[2], | ||
...args.erc20, | ||
address: getAddress(args.erc20.address), | ||
chainID: args.erc20.chainID, | ||
}), | ||
} satisfies ReverseMirageRead<[string, string, number]>; | ||
}; | ||
export const getErc20Permit = ( | ||
publicClient: PublicClient, | ||
args: { | ||
erc20: Pick<ERC20Permit, "address" | "chainID"> & | ||
Partial<Pick<ERC20Permit, "version">>; | ||
}, | ||
) => { | ||
return { | ||
read: () => | ||
Promise.all([ | ||
erc20Name(publicClient, args).read(), | ||
erc20Symbol(publicClient, args).read(), | ||
erc20Decimals(publicClient, args).read(), | ||
]), | ||
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]>; | ||
}; | ||
export const erc20IsPermit = () => {}; |
@@ -1,2 +0,3 @@ | ||
import type { Token, TokenData } from "../types.js"; | ||
import type { Amount } from "../amountUtils.js"; | ||
import type { Token } from "../types.js"; | ||
import type { Address } from "viem/accounts"; | ||
@@ -9,5 +10,13 @@ | ||
export type ERC20Amount<TERC20 extends ERC20> = TokenData< | ||
TERC20, | ||
{ amount: bigint } | ||
>; | ||
export type ERC20Permit = ERC20 & { version: string }; | ||
export type ERC20Data<TERC20 extends ERC20> = Amount<TERC20>; | ||
export type ERC20Amount<TERC20 extends ERC20> = ERC20Data<TERC20>; | ||
export type ERC20PermitData<TERC20 extends ERC20Permit> = ERC20Data<TERC20> & { | ||
nonce: bigint; | ||
}; | ||
export type ERC20PermitAmount<TERC20 extends ERC20Permit> = | ||
ERC20PermitData<TERC20>; |
@@ -0,5 +1,13 @@ | ||
import { erc20ABI } from "../generated.js"; | ||
import type { ReverseMirageWrite } from "../types.js"; | ||
import { erc20ABI } from "./erc20Abi.js"; | ||
import type { ERC20, ERC20Amount } from "./types.js"; | ||
import type { Account, PublicClient, WalletClient } from "viem"; | ||
import type { | ||
ERC20, | ||
ERC20Amount, | ||
ERC20Permit, | ||
ERC20PermitAmount, | ||
ERC20PermitData, | ||
} from "./types.js"; | ||
import { PermitType } from "./utils.js"; | ||
import invariant from "tiny-invariant"; | ||
import type { Account, Hex, PublicClient, WalletClient } from "viem"; | ||
import type { Address } from "viem/accounts"; | ||
@@ -67,1 +75,70 @@ | ||
}; | ||
export const erc20SignPermit = async ( | ||
walletClient: WalletClient, | ||
account: Account | Address, | ||
permit: { | ||
amount: ERC20PermitData<ERC20Permit>; | ||
owner: Address; | ||
spender: Address; | ||
deadline: bigint; | ||
}, | ||
) => { | ||
const domain = { | ||
name: permit.amount.token.name, | ||
version: permit.amount.token.version, | ||
chainId: permit.amount.token.chainID, | ||
verifyingContract: permit.amount.token.address, | ||
} as const; | ||
return walletClient.signTypedData({ | ||
domain, | ||
account, | ||
types: PermitType, | ||
primaryType: "Permit", | ||
message: { | ||
owner: permit.owner, | ||
spender: permit.spender, | ||
value: permit.amount.amount, | ||
nonce: permit.amount.nonce, | ||
deadline: permit.deadline, | ||
}, | ||
}); | ||
}; | ||
export const erc20Permit = async ( | ||
publicClient: PublicClient, | ||
walletClient: WalletClient, | ||
account: Account | Address, | ||
args: { | ||
owner: Address; | ||
spender: Address; | ||
erc20Permit: ERC20PermitAmount<ERC20Permit>; | ||
deadline: bigint; | ||
signature: Hex; | ||
}, | ||
): Promise<ReverseMirageWrite<typeof erc20ABI, "permit">> => { | ||
invariant(args.signature.length === 67, "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 { request, result } = await publicClient.simulateContract({ | ||
address: args.erc20Permit.token.address, | ||
abi: erc20ABI, | ||
functionName: "permit", | ||
args: [ | ||
args.owner, | ||
args.spender, | ||
args.erc20Permit.amount, | ||
args.deadline, | ||
v, | ||
r, | ||
s, | ||
], | ||
account, | ||
}); | ||
const hash = await walletClient.writeContract(request); | ||
return { hash, result, request }; | ||
}; |
@@ -13,3 +13,3 @@ import type { BigIntIsh, Fraction } from "./types.js"; | ||
*/ | ||
export const makeFraction = ( | ||
export const createFraction = ( | ||
numerator: BigIntIsh, | ||
@@ -16,0 +16,0 @@ denominator: BigIntIsh = 1, |
@@ -11,6 +11,7 @@ export { | ||
export { | ||
type Amount, | ||
isAmount, | ||
makeAmountFromString, | ||
makeAmountFromFraction, | ||
makeAmountFromRaw, | ||
createAmountFromString, | ||
createAmountFromFraction, | ||
createAmountFromRaw, | ||
amountAdd, | ||
@@ -27,3 +28,3 @@ amountSubtract, | ||
isFraction, | ||
makeFraction, | ||
createFraction, | ||
fractionQuotient, | ||
@@ -43,5 +44,5 @@ fractionRemainder, | ||
isPrice, | ||
makePriceFromFraction, | ||
makePriceFromAmounts, | ||
makePrice, | ||
createPriceFromFraction, | ||
createPriceFromAmounts, | ||
createPrice, | ||
priceInvert, | ||
@@ -69,5 +70,8 @@ priceAdd, | ||
erc20Decimals, | ||
erc20GetToken, | ||
getErc20, | ||
getErc20Permit, | ||
} from "./erc20/reads.js"; | ||
export { createErc20 } from "./erc20/utils.js"; | ||
export { | ||
@@ -83,4 +87,8 @@ erc20Transfer, | ||
export { createNativeCurrency } from "./native/utils.js"; | ||
export type { NativeCurrency, NativeCurrencyAmount } from "./native/types.js"; | ||
export { erc20ABI } from "./generated.js"; | ||
export type { | ||
@@ -87,0 +95,0 @@ BigIntIsh, |
@@ -1,14 +0,15 @@ | ||
import { makeAmountFromRaw } from "../amountUtils.js"; | ||
import { createAmountFromRaw } from "../amountUtils.js"; | ||
import type { ReverseMirageRead } from "../types.js"; | ||
import type { NativeCurrency } from "./types.js"; | ||
import type { NativeCurrency, NativeCurrencyAmount } from "./types.js"; | ||
import type { Address, PublicClient } from "viem"; | ||
export const nativeBalance = ( | ||
export const nativeBalance = <TNativeCurrency extends NativeCurrency>( | ||
publicClient: PublicClient, | ||
args: { nativeCurrency: NativeCurrency; address: Address }, | ||
args: { nativeCurrency: TNativeCurrency; address: Address }, | ||
) => { | ||
return { | ||
read: () => publicClient.getBalance({ address: args.address }), | ||
parse: (data) => makeAmountFromRaw(args.nativeCurrency, data), | ||
parse: (data): NativeCurrencyAmount<TNativeCurrency> => | ||
createAmountFromRaw(args.nativeCurrency, data), | ||
} satisfies ReverseMirageRead<bigint>; | ||
}; |
@@ -1,2 +0,2 @@ | ||
import { type Amount, makeAmountFromRaw, scaleUp } from "./amountUtils.js"; | ||
import { type Amount, createAmountFromRaw, scaleUp } from "./amountUtils.js"; | ||
import { | ||
@@ -23,3 +23,3 @@ fractionAdd, | ||
export const makePriceFromFraction = < | ||
export const createPriceFromFraction = < | ||
TQuoteCurrency extends Amount["token"], | ||
@@ -43,3 +43,3 @@ TBaseCurrency extends Amount["token"], | ||
export const makePriceFromAmounts = < | ||
export const createPriceFromAmounts = < | ||
TQuoteCurrency extends Amount["token"], | ||
@@ -58,3 +58,3 @@ TBaseCurrency extends Amount["token"], | ||
export const makePrice = < | ||
export const createPrice = < | ||
TQuoteCurrency extends Amount["token"], | ||
@@ -107,3 +107,7 @@ TBaseCurrency extends Amount["token"], | ||
} | ||
: makePriceFromFraction(a.quote, a.base, fractionAdd(adjustedPrice(a), b)); | ||
: createPriceFromFraction( | ||
a.quote, | ||
a.base, | ||
fractionAdd(adjustedPrice(a), b), | ||
); | ||
}; | ||
@@ -127,3 +131,3 @@ | ||
} | ||
: makePriceFromFraction( | ||
: createPriceFromFraction( | ||
a.quote, | ||
@@ -158,3 +162,3 @@ a.base, | ||
} | ||
: makePriceFromFraction( | ||
: createPriceFromFraction( | ||
a.quote, | ||
@@ -189,3 +193,3 @@ a.base, | ||
} | ||
: makePriceFromFraction( | ||
: createPriceFromFraction( | ||
a.quote, | ||
@@ -248,3 +252,3 @@ a.base, | ||
return makeAmountFromRaw( | ||
return createAmountFromRaw( | ||
price.quote, | ||
@@ -251,0 +255,0 @@ (price.numerator * amount.amount) / price.denominator, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
240177
7
24
3848
1
2
0