Skip to content

Commit

Permalink
Wallet -> Account in armory and engine (#356)
Browse files Browse the repository at this point in the history
* renamed wallet entities into accounts

* removed console statement

* renamed fixtures and WALLET classification into VAULT

* renamed fixtures in vault and devtool

* vault format

* rego permissions on wallet not account

* fix viem link in comments
  • Loading branch information
Ptroger authored Jun 21, 2024
1 parent 56caa6f commit 8bdd845
Show file tree
Hide file tree
Showing 39 changed files with 336 additions and 336 deletions.
8 changes: 4 additions & 4 deletions apps/devtool/src/app/_lib/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { getTime } from 'date-fns'
import { v4 as uuid } from 'uuid'

export const erc20 = async () => {
const from = FIXTURE.WALLET.Engineering
const to = FIXTURE.WALLET.Operation
const from = FIXTURE.ACCOUNT.Engineering
const to = FIXTURE.ACCOUNT.Operation

const request = {
resourceId: from.id,
Expand Down Expand Up @@ -46,8 +46,8 @@ export const erc20 = async () => {
}

export const spendingLimits = async () => {
const from = FIXTURE.WALLET.Engineering
const to = FIXTURE.WALLET.Operation
const from = FIXTURE.ACCOUNT.Engineering
const to = FIXTURE.ACCOUNT.Operation

const transferOneMatic = {
from: from.address,
Expand Down
10 changes: 5 additions & 5 deletions apps/devtool/src/app/api/data-store/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
"tokens": [],
"userGroupMembers": [],
"userGroups": [],
"userWallets": [
"userAccounts": [
{
"userId": "61e775a9-5f68-41ab-a775-5806845e6e72",
"walletId": "eip155:eoa:0x494042504a8148a6d00ab10ed26043f5579ce00f"
"accountId": "eip155:eoa:0x494042504a8148a6d00ab10ed26043f5579ce00f"
}
],
"users": [
Expand All @@ -61,9 +61,9 @@
"role": "admin"
}
],
"walletGroupMembers": [],
"walletGroups": [],
"wallets": [
"accountGroupMembers": [],
"accountGroups": [],
"accounts": [
{
"id": "eip155:eoa:0x494042504a8148a6d00ab10ed26043f5579ce00f",
"address": "0x494042504a8148a6d00ab10ed26043f5579ce00f",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ describe(DataStoreService.name, () => {
credentials: [],
tokens: [],
userGroupMembers: [],
userWallets: [],
userAccounts: [],
users: [],
walletGroupMembers: [],
walletGroups: [],
wallets: []
accountGroupMembers: [],
accountGroups: [],
accounts: []
}

await testThrowDataStoreException({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ describe('OpenPolicyAgentEngine', () => {
tokens: [],
userGroupMembers: [],
userGroups: [],
userWallets: [],
userAccounts: [],
users: [],
walletGroupMembers: [],
walletGroups: [],
wallets: []
accountGroupMembers: [],
accountGroups: [],
accounts: []
})
})
})
Expand Down Expand Up @@ -145,12 +145,12 @@ describe('OpenPolicyAgentEngine', () => {
action: Action.SIGN_TRANSACTION,
nonce: 'test-nonce',
transactionRequest: {
from: FIXTURE.WALLET.Engineering.address,
to: FIXTURE.WALLET.Testing.address,
from: FIXTURE.ACCOUNT.Engineering.address,
to: FIXTURE.ACCOUNT.Testing.address,
value: ONE_ETH,
chainId: 1
},
resourceId: FIXTURE.WALLET.Engineering.id
resourceId: FIXTURE.ACCOUNT.Engineering.id
}

const evaluation: EvaluationRequest = {
Expand Down Expand Up @@ -195,12 +195,12 @@ describe('OpenPolicyAgentEngine', () => {
action: Action.SIGN_TRANSACTION,
nonce: 'test-nonce',
transactionRequest: {
from: FIXTURE.WALLET.Engineering.address,
to: FIXTURE.WALLET.Testing.address,
from: FIXTURE.ACCOUNT.Engineering.address,
to: FIXTURE.ACCOUNT.Testing.address,
value: ONE_ETH,
chainId: 1
},
resourceId: FIXTURE.WALLET.Engineering.id
resourceId: FIXTURE.ACCOUNT.Engineering.id
}

const evaluation: EvaluationRequest = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ export type UserGroup = {
users: string[] // userIds
}

type Wallet = {
type Account = {
id: string
address: Address
accountType: AccountType
chainId?: number
assignees?: string[] // userIds
}

export type WalletGroup = {
export type AccountGroup = {
id: string
wallets: string[] // walletIds
accounts: string[] // accountIds
}

type AddressBookAccount = {
Expand All @@ -72,9 +72,9 @@ type Token = {
export type Data = {
entities: {
users: Record<string, User>
wallets: Record<string, Wallet>
accounts: Record<string, Account>
userGroups: Record<string, UserGroup>
walletGroups: Record<string, WalletGroup>
accountGroups: Record<string, AccountGroup>
addressBook: Record<string, AddressBookAccount>
tokens: Record<string, Token>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,11 @@ describe('toData', () => {
expect(entities.users[alice.id]).toEqual(alice)
})

it('indexes wallets by id', () => {
it('indexes accounts by id', () => {
const { entities } = toData(FIXTURE.ENTITIES)
const wallet = FIXTURE.WALLET.Testing
const account = FIXTURE.ACCOUNT.Testing

expect(entities.wallets[wallet.id]).toEqual(wallet)
expect(entities.accounts[account.id]).toEqual(account)
})

it('indexes user groups with members by id', () => {
Expand All @@ -285,14 +285,14 @@ describe('toData', () => {
})
})

it('indexes wallet groups with members by id', () => {
it('indexes account groups with members by id', () => {
const { entities } = toData(FIXTURE.ENTITIES)
const group = FIXTURE.WALLET_GROUP.Treasury
const group = FIXTURE.ACCOUNT_GROUP.Treasury

expect(entities.walletGroups[group.id]).toEqual({
expect(entities.accountGroups[group.id]).toEqual({
id: group.id,
wallets: FIXTURE.WALLET_GROUP_MEMBER.filter(({ groupId }) => groupId === group.id).map(
({ walletId }) => walletId
accounts: FIXTURE.ACCOUNT_GROUP_MEMBER.filter(({ groupId }) => groupId === group.id).map(
({ accountId }) => accountId
)
})
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ConfigModule, ConfigService } from '@narval/config-module'
import {
AccountAddressCriterion,
ApprovalsCriterion,
Criterion,
ERC1155TransfersCriterion,
Expand All @@ -8,8 +9,7 @@ import {
IntentAmountCriterion,
NonceRequiredCriterion,
Then,
ValueOperators,
WalletAddressCriterion
ValueOperators
} from '@narval/policy-engine-shared'
import { Path, PathValue } from '@nestjs/config'
import { Test, TestingModule } from '@nestjs/testing'
Expand Down Expand Up @@ -46,12 +46,12 @@ describe('transpileCriterion', () => {
})

it('returns criterion if args is an array of strings', () => {
const item: WalletAddressCriterion = {
criterion: Criterion.CHECK_WALLET_ADDRESS,
const item: AccountAddressCriterion = {
criterion: Criterion.CHECK_ACCOUNT_ADDRESS,
args: ['0x123', '0x456']
}

expect(transpileCriterion(item)).toEqual(`${Criterion.CHECK_WALLET_ADDRESS}({"0x123", "0x456"})`)
expect(transpileCriterion(item)).toEqual(`${Criterion.CHECK_ACCOUNT_ADDRESS}({"0x123", "0x456"})`)
})

it('returns criterion if args is an array of objects', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { InputType, safeDecode } from '@narval/transaction-request-intent'
import { HttpStatus } from '@nestjs/common'
import { indexBy } from 'lodash/fp'
import { OpenPolicyAgentException } from '../exception/open-policy-agent.exception'
import { Data, Input, UserGroup, WalletGroup } from '../type/open-policy-agent.type'
import { AccountGroup, Data, Input, UserGroup } from '../type/open-policy-agent.type'

type Mapping<R extends Request> = (
request: R,
Expand Down Expand Up @@ -150,27 +150,27 @@ export const toData = (entities: Entities): Data => {
}
}, new Map<string, UserGroup>())

const walletGroups = entities.walletGroupMembers.reduce((groups, { walletId, groupId }) => {
const accountGroups = entities.accountGroupMembers.reduce((groups, { accountId, groupId }) => {
const group = groups.get(groupId)

if (group) {
return groups.set(groupId, {
id: groupId,
wallets: group.wallets.concat(walletId)
accounts: group.accounts.concat(accountId)
})
} else {
return groups.set(groupId, { id: groupId, wallets: [walletId] })
return groups.set(groupId, { id: groupId, accounts: [accountId] })
}
}, new Map<string, WalletGroup>())
}, new Map<string, AccountGroup>())

return {
entities: {
addressBook: indexBy('id', entities.addressBook),
tokens: indexBy('id', entities.tokens),
users: indexBy('id', entities.users),
userGroups: Object.fromEntries(userGroups),
wallets: indexBy('id', entities.wallets),
walletGroups: Object.fromEntries(walletGroups)
accounts: indexBy('id', entities.accounts),
accountGroups: Object.fromEntries(accountGroups)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ test_checkApprovalWithoutCountingDuplicates {
"userId": "test-bar-uid",
"alg": "ES256K",
"pubKey": "test-bar-pub-key",
"sig": "test-bar-wallet-sig",
"sig": "test-bar-account-sig",
},
{
"userId": "test-bar-uid",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test_contractCall {
checkIntentType({"contractCall"}) with input as contractCallRequest
with data.entities as entities

checkWalletId({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as contractCallRequest
checkAccountId({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as contractCallRequest
with data.entities as entities

checkDestinationId({"eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3"}) with input as contractCallRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ test_contractDeploy {
},
}

checkIntentType({"deployContract", "deployErc4337Wallet", "deploySafeWallet"}) with input as contractDeployRequest
checkIntentType({"deployContract", "deployErc4337Account", "deploySafeAccount"}) with input as contractDeployRequest
with data.entities as entities

checkWalletId({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as contractDeployRequest
checkAccountId({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as contractDeployRequest
with data.entities as entities

checkIntentChainId({"137"}) with input as contractDeployRequest with data.entities as entities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test_permit {
checkIntentType({"permit", "permit2"}) with input as permitRequest
with data.entities as entities

checkWalletId({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as permitRequest
checkAccountId({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as permitRequest
with data.entities as entities

checkIntentSpender({"eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3"}) with input as permitRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test_checkSignMessage {
checkIntentType({"signMessage", "signRawMessage"}) with input as signMessageRequest
with data.entities as entities

checkWalletId({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as signMessageRequest
checkAccountId({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as signMessageRequest
with data.entities as entities

checkIntentMessage({"operator": operators.equal, "value": "Hello world!"}) with input as signMessageRequest
Expand All @@ -43,7 +43,7 @@ test_checkSignRawPayload {
checkIntentType({"signRawPayload"}) with input as signRawPayloadRequest
with data.entities as entities

checkWalletId({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as signRawPayloadRequest
checkAccountId({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as signRawPayloadRequest
with data.entities as entities

checkIntentPayload({"operator": operators.equal, "value": "Hello world!"}) with input as signRawPayloadRequest
Expand Down Expand Up @@ -76,7 +76,7 @@ test_checkSignTypedData {
checkIntentType({"signTypedData"}) with input as signTypedDataRequest
with data.entities as entities

checkWalletId({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as signTypedDataRequest
checkAccountId({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as signTypedDataRequest
with data.entities as entities

checkIntentDomain({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test_tokenAllowance {
checkIntentType({"approveTokenAllowance"}) with input as tokenAllowanceRequest
with data.entities as entities

checkWalletId({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as tokenAllowanceRequest
checkAccountId({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as tokenAllowanceRequest
with data.entities as entities

checkIntentSpender({"eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3"}) with input as tokenAllowanceRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test_transferERC721 {
checkIntentType({"transferERC721"}) with input as erc721Request
with data.entities as entities

checkWalletId({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as erc721Request
checkAccountId({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as erc721Request
with data.entities as entities

checkDestinationId({"eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3"}) with input as erc721Request
Expand Down Expand Up @@ -58,7 +58,7 @@ test_transferERC1155 {
checkIntentType({"transferERC1155"}) with input as erc1155Request
with data.entities as entities

checkWalletId({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as erc1155Request
checkAccountId({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as erc1155Request
with data.entities as entities

checkDestinationId({"eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3"}) with input as erc1155Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test_transferNative {
checkIntentType({"transferNative"}) with input as nativeRequest
with data.entities as entities

checkWalletId({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as nativeRequest
checkAccountId({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as nativeRequest
with data.entities as entities

checkDestinationId({"eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3"}) with input as nativeRequest
Expand Down Expand Up @@ -45,7 +45,7 @@ test_transferERC20 {
checkIntentType({"transferERC20"}) with input as erc20Request
with data.entities as entities

checkWalletId({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as erc20Request
checkAccountId({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as erc20Request
with data.entities as entities

checkDestinationId({"eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3"}) with input as erc20Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test_principal {
isPrincipalRootUser with input as request
with data.entities as entities

isPrincipalAssignedToWallet with input as request
isPrincipalAssignedToAccount with input as request
with data.entities as entities

checkPrincipalId({"test-bob-uid", "test-alice-uid"}) with input as request
Expand Down
Loading

0 comments on commit 8bdd845

Please sign in to comment.