Skip to content

Commit

Permalink
fix token type to asset id
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel committed Mar 4, 2024
1 parent 155023e commit 274ad14
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const translateActivityType = (policy: LegacyPolicy): PolicyCriterion[] => {
if (chain_id && chain_id !== '*' && assetAddress && assetAddress !== '*') {
intentToken.args = [
...intentToken.args,
toAccountId({ chainId: Number(chain_id), address: assetAddress as Address })
toAssetId({ assetType: AssetType.ERC20, chainId: Number(chain_id), address: assetAddress as Address })
]
}
}
Expand Down Expand Up @@ -267,7 +267,7 @@ const translateActivityType = (policy: LegacyPolicy): PolicyCriterion[] => {
if (assetAddress && assetAddress !== '*') {
intentToken.args = [
...intentToken.args,
toAccountId({ chainId: Number(chain_id), address: assetAddress as Address })
toAssetId({ assetType: AssetType.ERC20, chainId: Number(chain_id), address: assetAddress as Address })
]
}
if (destination_account_type === 'contract' && destination_address && destination_address !== '*') {
Expand Down
14 changes: 7 additions & 7 deletions apps/policy-engine/src/shared/types/policy.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
FiatCurrency,
IdentityOperators,
IsAccountId,
IsAccountOrAssetId,
IsAssetId,
IsHexString,
IsNotEmptyArrayEnum,
IsNotEmptyArrayString,
Expand Down Expand Up @@ -105,7 +105,7 @@ export class AmountCondition {
}

export class ERC1155AmountCondition {
@IsAccountOrAssetId()
@IsAssetId()
@ApiProperty()
tokenId: AssetId

Expand Down Expand Up @@ -211,7 +211,7 @@ export class SpendingLimitTimeWindow {

export class SpendingLimitFilters {
@IsNotEmptyArrayString()
@IsAccountOrAssetId({ each: true })
@IsAssetId({ each: true })
@IsOptional()
@ApiPropertyOptional()
tokens?: AssetId[]
Expand Down Expand Up @@ -411,8 +411,8 @@ export class IntentTokenCriterion extends BaseCriterion {
criterion: typeof Criterion.CHECK_INTENT_TOKEN

@IsNotEmptyArrayString()
@IsAccountOrAssetId({ each: true })
args: Array<AccountId | AssetId>
@IsAssetId({ each: true })
args: AssetId[]
}

export class IntentSpenderCriterion extends BaseCriterion {
Expand Down Expand Up @@ -455,7 +455,7 @@ export class ERC721TokenIdCriterion extends BaseCriterion {
criterion: typeof Criterion.CHECK_ERC721_TOKEN_ID

@IsNotEmptyArrayString()
@IsAccountOrAssetId({ each: true })
@IsAssetId({ each: true })
args: AssetId[]
}

Expand All @@ -464,7 +464,7 @@ export class ERC1155TokenIdCriterion extends BaseCriterion {
criterion: typeof Criterion.CHECK_ERC1155_TOKEN_ID

@IsNotEmptyArrayString()
@IsAccountOrAssetId({ each: true })
@IsAssetId({ each: true })
args: AssetId[]
}

Expand Down
2 changes: 1 addition & 1 deletion packages/policy-engine-shared/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './lib/decorators/is-account-id.decorator'
export * from './lib/decorators/is-account-or-asset-id.decorator'
export * from './lib/decorators/is-asset-id.decorator'
export * from './lib/decorators/is-hex-string.decorator'
export * from './lib/decorators/is-not-empty-array-enum.decorator'
export * from './lib/decorators/is-not-empty-array-string.decorator'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { ValidationOptions, registerDecorator } from 'class-validator'
import { isAccountId, isAssetId } from '../util/caip.util'
import { isAssetId } from '../util/caip.util'

export function IsAccountOrAssetId(validationOptions?: ValidationOptions) {
export function IsAssetId(validationOptions?: ValidationOptions) {
return function (object: object, propertyName: string) {
registerDecorator({
name: 'isAccountOrAssetId',
name: 'isAssetId',
target: object.constructor,
propertyName: propertyName,
options: validationOptions,
validator: {
validate(value: unknown) {
return typeof value === 'string' && (isAccountId(value) || isAssetId(value))
return typeof value === 'string' && isAssetId(value)
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type TransferErc20 = {
type: Intents.TRANSFER_ERC20
to: AccountId
from: AccountId
token: AccountId
token: AssetId
amount: string
}

Expand Down

0 comments on commit 274ad14

Please sign in to comment.