Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass full request to reads #54

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions packages/core/src/erc1155/publicActions/getERC1155.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,40 @@ export const getERC1155 = <
T extends "select" | undefined,
>(
client: Client<Transport, TChain>,
args: GetERC1155Parameters,
{ erc1155, ...request }: GetERC1155Parameters,
type?: T,
): ReverseMirage<string, GetERC1155ReturnType, T> =>
(type === undefined
? readContract(client, {
abi: solmateERC1155ABI,
address: args.erc1155.address,
address: erc1155.address,
functionName: "uri",
args: [args.erc1155.id],
args: [erc1155.id],
...request,
}).then((data) =>
createERC1155(
args.erc1155.address,
args.erc1155.id,
erc1155.address,
erc1155.id,
data,
args.erc1155.chainID,
args.blockNumber,
erc1155.chainID,
erc1155.blockCreated,
),
)
: {
read: () =>
readContract(client, {
abi: solmateERC1155ABI,
address: args.erc1155.address,
address: erc1155.address,
functionName: "uri",
args: [args.erc1155.id],
args: [erc1155.id],
...request,
}),
parse: (data) =>
createERC1155(
args.erc1155.address,
args.erc1155.id,
erc1155.address,
erc1155.id,
data,
args.erc1155.chainID,
args.blockNumber,
erc1155.chainID,
erc1155.blockCreated,
),
}) as ReverseMirage<string, GetERC1155ReturnType, T>;
16 changes: 9 additions & 7 deletions packages/core/src/erc1155/publicActions/getERC1155BalanceOf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,25 @@ export const getERC1155BalanceOf = <
T extends "select" | undefined,
>(
client: Client<Transport, TChain>,
args: GetERC1155BalanceOfParameters<TERC1155>,
{ erc1155, address, ...request }: GetERC1155BalanceOfParameters<TERC1155>,
type?: T,
): ReverseMirage<bigint, GetERC1155BalanceOfReturnType<TERC1155>, T> =>
(type === undefined
? readContract(client, {
abi: solmateERC1155ABI,
address: args.erc1155.address,
address: erc1155.address,
functionName: "balanceOf",
args: [args.address, args.erc1155.id],
}).then((data) => createERC1155Data(args.erc1155, data))
args: [address, erc1155.id],
...request,
}).then((data) => createERC1155Data(erc1155, data))
: {
read: () =>
readContract(client, {
abi: solmateERC1155ABI,
address: args.erc1155.address,
address: erc1155.address,
functionName: "balanceOf",
args: [args.address, args.erc1155.id],
args: [address, erc1155.id],
...request,
}),
parse: (data) => createERC1155Data(args.erc1155, data),
parse: (data) => createERC1155Data(erc1155, data),
}) as ReverseMirage<bigint, GetERC1155BalanceOfReturnType<TERC1155>, T>;
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,25 @@ export const getERC1155IsApprovedForAll = <
T extends "select" | undefined,
>(
client: Client<Transport, TChain>,
args: GetERC1155IsApprovedForAllParameters,
{ erc1155, owner, spender, ...request }: GetERC1155IsApprovedForAllParameters,
type?: T,
): ReverseMirage<boolean, GetERC1155IsApprovedForAllReturnType, T> =>
(type === undefined
? readContract(client, {
abi: solmateERC1155ABI,
address: args.erc1155.address,
address: erc1155.address,
functionName: "isApprovedForAll",
args: [args.owner, args.spender],
args: [owner, spender],
...request,
})
: {
read: () =>
readContract(client, {
abi: solmateERC1155ABI,
address: args.erc1155.address,
address: erc1155.address,
functionName: "isApprovedForAll",
args: [args.owner, args.spender],
args: [owner, spender],
...request,
}),
parse: (data) => data,
}) as ReverseMirage<boolean, GetERC1155IsApprovedForAllReturnType, T>;
12 changes: 7 additions & 5 deletions packages/core/src/erc1155/publicActions/getERC1155URI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,25 @@ export const getERC1155URI = <
T extends "select" | undefined,
>(
client: Client<Transport, TChain>,
args: GetERC1155URIParameters,
{ erc1155, ...request }: GetERC1155URIParameters,
type?: T,
): ReverseMirage<string, GetERC1155URIReturnType, T> =>
(type === undefined
? readContract(client, {
abi: solmateERC1155ABI,
address: args.erc1155.address,
address: erc1155.address,
functionName: "uri",
args: [args.erc1155.id],
args: [erc1155.id],
...request,
})
: {
read: () =>
readContract(client, {
abi: solmateERC1155ABI,
address: args.erc1155.address,
address: erc1155.address,
functionName: "uri",
args: [args.erc1155.id],
args: [erc1155.id],
...request,
}),
parse: (data) => data,
}) as ReverseMirage<string, GetERC1155URIReturnType, T>;
26 changes: 13 additions & 13 deletions packages/core/src/erc20/publicActions/getERC20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,38 @@ export const getERC20 = <
T extends "select" | undefined,
>(
client: Client<Transport, TChain>,
args: GetERC20Parameters,
{ erc20, ...request }: GetERC20Parameters,
type?: T,
): ReverseMirage<[string, string, number], GetERC20NameReturnType, T> =>
(type === undefined
? Promise.all([
getERC20Name(client, args),
getERC20Symbol(client, args),
getERC20Decimals(client, args),
getERC20Name(client, { erc20, ...request }),
getERC20Symbol(client, { erc20, ...request }),
getERC20Decimals(client, { erc20, ...request }),
]).then(([name, symbol, decimals]) =>
createERC20(
args.erc20.address,
erc20.address,
name,
symbol,
decimals,
args.erc20.chainID,
args.erc20.blockCreated,
erc20.chainID,
erc20.blockCreated,
),
)
: {
read: () =>
Promise.all([
getERC20Name(client, args, "select").read(),
getERC20Symbol(client, args, "select").read(),
getERC20Decimals(client, args, "select").read(),
getERC20Name(client, { erc20, ...request }, "select").read(),
getERC20Symbol(client, { erc20, ...request }, "select").read(),
getERC20Decimals(client, { erc20, ...request }, "select").read(),
]),
parse: ([name, symbol, decimals]) =>
createERC20(
args.erc20.address,
erc20.address,
name,
symbol,
decimals,
args.erc20.chainID,
args.erc20.blockCreated,
erc20.chainID,
erc20.blockCreated,
),
}) as ReverseMirage<[string, string, number], GetERC20NameReturnType, T>;
16 changes: 9 additions & 7 deletions packages/core/src/erc20/publicActions/getERC20Allowance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,25 @@ export const getERC20Allowance = <
T extends "select" | undefined,
>(
client: Client<Transport, TChain>,
args: GetERC20AllowanceParameters<TERC20>,
{ erc20, owner, spender, ...request }: GetERC20AllowanceParameters<TERC20>,
type?: T,
): ReverseMirage<bigint, GetERC20AllowanceReturnType<TERC20>, T> =>
(type === undefined
? readContract(client, {
abi: solmateERC20ABI,
address: args.erc20.address,
address: erc20.address,
functionName: "allowance",
args: [args.owner, args.spender],
}).then((data) => createAmountFromRaw(args.erc20, data))
args: [owner, spender],
...request,
}).then((data) => createAmountFromRaw(erc20, data))
: {
read: () =>
readContract(client, {
abi: solmateERC20ABI,
address: args.erc20.address,
address: erc20.address,
functionName: "allowance",
args: [args.owner, args.spender],
args: [owner, spender],
...request,
}),
parse: (data) => createAmountFromRaw(args.erc20, data),
parse: (data) => createAmountFromRaw(erc20, data),
}) as ReverseMirage<bigint, GetERC20AllowanceReturnType<TERC20>, T>;
16 changes: 9 additions & 7 deletions packages/core/src/erc20/publicActions/getERC20BalanceOf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,25 @@ export const getERC20BalanceOf = <
T extends "select" | undefined,
>(
client: Client<Transport, TChain>,
args: GetERC20BalanceOfParameters<TERC20>,
{ erc20, address, ...request }: GetERC20BalanceOfParameters<TERC20>,
type?: T,
): ReverseMirage<bigint, GetERC20BalanceOfReturnType<TERC20>, T> =>
(type === undefined
? readContract(client, {
abi: solmateERC20ABI,
address: args.erc20.address,
address: erc20.address,
functionName: "balanceOf",
args: [args.address],
}).then((data) => createAmountFromRaw(args.erc20, data))
args: [address],
...request,
}).then((data) => createAmountFromRaw(erc20, data))
: {
read: () =>
readContract(client, {
abi: solmateERC20ABI,
address: args.erc20.address,
address: erc20.address,
functionName: "balanceOf",
args: [args.address],
args: [address],
...request,
}),
parse: (data) => createAmountFromRaw(args.erc20, data),
parse: (data) => createAmountFromRaw(erc20, data),
}) as ReverseMirage<bigint, GetERC20BalanceOfReturnType<TERC20>, T>;
8 changes: 5 additions & 3 deletions packages/core/src/erc20/publicActions/getERC20Decimals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,23 @@ export const getERC20Decimals = <
T extends "select" | undefined,
>(
client: Client<Transport, TChain>,
args: GetERC20DecimalsParameters,
{ erc20, ...request }: GetERC20DecimalsParameters,
type?: T,
): ReverseMirage<number, GetERC20DecimalsReturnType, T> =>
(type === undefined
? readContract(client, {
abi: solmateERC20ABI,
address: args.erc20.address,
address: erc20.address,
functionName: "decimals",
...request,
})
: {
read: () =>
readContract(client, {
abi: solmateERC20ABI,
address: args.erc20.address,
address: erc20.address,
functionName: "decimals",
...request,
}),
parse: (data) => data,
}) as ReverseMirage<number, GetERC20DecimalsReturnType, T>;
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,23 @@ export const getERC20DomainSeparator = <
T extends "select" | undefined,
>(
client: Client<Transport, TChain>,
args: GetERC20DomainSeparatorParameters,
{ erc20, ...request }: GetERC20DomainSeparatorParameters,
type?: T,
): ReverseMirage<Hex, GetERC20DomainSeparatorReturnType, T> =>
(type === undefined
? readContract(client, {
abi: solmateERC20ABI,
address: args.erc20.address,
address: erc20.address,
functionName: "DOMAIN_SEPARATOR",
...request,
})
: {
read: () =>
readContract(client, {
abi: solmateERC20ABI,
address: args.erc20.address,
address: erc20.address,
functionName: "DOMAIN_SEPARATOR",
...request,
}),
parse: (data) => data,
}) as ReverseMirage<Hex, GetERC20DomainSeparatorReturnType, T>;
8 changes: 5 additions & 3 deletions packages/core/src/erc20/publicActions/getERC20Name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,23 @@ export const getERC20Name = <
T extends "select" | undefined,
>(
client: Client<Transport, TChain>,
args: GetERC20NameParameters,
{ erc20, ...request }: GetERC20NameParameters,
type?: T,
): ReverseMirage<string, GetERC20NameReturnType, T> =>
(type === undefined
? readContract(client, {
abi: solmateERC20ABI,
address: args.erc20.address,
address: erc20.address,
functionName: "name",
...request,
})
: {
read: () =>
readContract(client, {
abi: solmateERC20ABI,
address: args.erc20.address,
address: erc20.address,
functionName: "name",
...request,
}),
parse: (data) => data,
}) as ReverseMirage<string, GetERC20NameReturnType, T>;
Loading