Skip to content

Commit

Permalink
resolved 'assetType' conflict and started testing contract deployment…
Browse files Browse the repository at this point in the history
… intents
  • Loading branch information
Ptroger committed Jan 25, 2024
1 parent 1125233 commit 52dee90
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions packages/transaction-request-intent/src/lib/domain.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, Alg, AssetType as AssetTypeEnum, Caip10Id, Hex, TransactionRequest } from '@narval/authz-shared'
import { Address, Alg, AssetType, Caip10Id, Hex, TransactionRequest } from '@narval/authz-shared'
import { TypedDataDomain, TypedData as TypedDataParams } from 'viem'
import { Intent } from './intent.types'

Expand Down Expand Up @@ -39,11 +39,11 @@ export type TypedDataInput = {

export type ContractInformation = {
contractAddress: string
assetType: AssetTypeEnum
assetType: AssetType
}
export type ContractRegistryInput = {
contract: Caip10Id | { address: Address; chainId: number }
assetType?: AssetTypeEnum
assetType?: AssetType
walletType?: WalletType
}[]
export type ContractRegistry = Map<Caip10Id, ContractInformation>
Expand Down Expand Up @@ -154,7 +154,7 @@ export enum Misc {
UNKNOWN = 'unknown'
}

export type AssetType = AssetTypeEnum | Misc
export type AssetTypeAndUnknown = AssetType | Misc

export enum SupportedChains {
ETHEREUM = 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AssetType as AssetTypeEnum } from '@narval/authz-shared'
import { AbiParameter } from 'viem'
import { AssetType, Intents, Misc } from './domain'
import { AssetTypeAndUnknown, Intents, Misc } from './domain'
import {
ApproveAllowanceParamsTransform,
Erc1155SafeTransferFromParamsTransform,
Expand Down Expand Up @@ -166,7 +166,7 @@ export type MethodsMapping = {
name: string
abi: AbiParameter[]
transformer: (params: unknown[]) => StandardMethodsParams[K]
assetType: AssetType
assetType: AssetTypeAndUnknown
intent: Intents
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/transaction-request-intent/src/lib/typeguards.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AssetType as AssetTypeEnum, Hex } from '@narval/authz-shared'
import { AssetType, Misc } from './domain'
import { AssetType, Hex } from '@narval/authz-shared'
import { SupportedMethodId } from './supported-methods'
import { AssetTypeAndUnknown, Misc } from './domain'

export const isString = (value: unknown): value is string => {
return typeof value === 'string'
Expand Down Expand Up @@ -75,7 +75,7 @@ export const isSupportedMethodId = (value: Hex): value is SupportedMethodId => {
type AssertType = 'string' | 'bigint' | 'number' | 'boolean' | 'hex'

export const isAssetType = (value: unknown): value is AssetType => {
const types: AssetType[] = Object.values(AssetTypeEnum)
const types: AssetTypeAndUnknown[] = Object.values(AssetType)
types.push(Misc.UNKNOWN)

return types.includes(value as AssetType)
Expand Down
14 changes: 7 additions & 7 deletions packages/transaction-request-intent/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
AssetType as AssetTypeEnum,
AssetType,
Caip10Id,
Hex,
Namespace,
Expand All @@ -9,7 +9,7 @@ import {
} from '@narval/authz-shared'
import { isAddress } from 'viem'
import {
AssetType,
AssetTypeAndUnknown,
ContractCallInput,
ContractInformation,
ContractRegistry,
Expand Down Expand Up @@ -48,8 +48,8 @@ export const buildContractRegistryEntry = ({
chainId: number
contractAddress: string
assetType: string
}): { [key: Caip10Id]: AssetType } => {
const registry: { [key: Caip10Id]: AssetType } = {}
}): { [key: Caip10Id]: AssetTypeAndUnknown } => {
const registry: { [key: Caip10Id]: AssetTypeAndUnknown } = {}
if (!isAddress(contractAddress) || !isAssetType(assetType)) {
throw new Error('Invalid contract registry entry')
}
Expand Down Expand Up @@ -162,9 +162,9 @@ export const getTransactionIntentType = ({
{
condition: () =>
methodId === SupportedMethodId.TRANSFER_FROM &&
((contractType && contractType.assetType === AssetTypeEnum.ERC20) ||
(contractType && contractType.assetType === AssetTypeEnum.ERC721)),
intent: contractType?.assetType === AssetTypeEnum.ERC721 ? Intents.TRANSFER_ERC721 : Intents.TRANSFER_ERC20
((contractType && contractType.assetType === AssetType.ERC20) ||
(contractType && contractType.assetType === AssetType.ERC721)),
intent: contractType?.assetType === AssetType.ERC721 ? Intents.TRANSFER_ERC721 : Intents.TRANSFER_ERC20
},
// Cancel condition
{
Expand Down

0 comments on commit 52dee90

Please sign in to comment.