UNPKG

@abstract-foundation/agw-client

Version:
42 lines 1.71 kB
import { BaseError, getAddress, InvalidAddressError, isAddress, } from "viem"; import { readContract } from "viem/actions"; import { getAction, parseAccount } from "viem/utils"; import { ExclusiveDelegateResolverAbi } from "../abis/ExclusiveDelegateResolver.js"; import { AGW_LINK_DELEGATION_RIGHTS, CANONICAL_EXCLUSIVE_DELEGATE_RESOLVER_ADDRESS, } from "../constants.js"; import { AccountNotFoundError } from "../errors/account.js"; export async function getLinkedAgw(client, parameters) { const { address = client.account?.address } = (parameters ?? {}); if (address === undefined) { throw new BaseError("No address provided"); } if (!isAddress(address, { strict: false })) { throw new InvalidAddressError({ address }); } const checksummedAddress = getAddress(address); const result = await getAction(client, readContract, "readContract")({ abi: ExclusiveDelegateResolverAbi, address: CANONICAL_EXCLUSIVE_DELEGATE_RESOLVER_ADDRESS, functionName: "exclusiveWalletByRights", args: [checksummedAddress, AGW_LINK_DELEGATION_RIGHTS], }); if (result === checksummedAddress) { return { agw: undefined, }; } return { agw: result, }; } export async function isLinkedAccount(client, parameters) { const { address } = parameters; if (client.account === undefined) { throw new AccountNotFoundError({ docsPath: "/docs/contract/readContract", }); } const clientAccount = parseAccount(client.account); const { agw } = await getLinkedAgw(client, { address }); return agw === clientAccount.address; } //# sourceMappingURL=getLinkedAgw.js.map