From 405ce0afc3780b9a15534b2657d56f5b5699ee03 Mon Sep 17 00:00:00 2001 From: Vitor Date: Thu, 5 Dec 2024 13:25:44 -0300 Subject: [PATCH] chore: remove duplicate abis --- .../src/delegation/constants.ts | 28 + packages/universal-data/src/exports/index.ts | 11 + .../src/abis/delegation-manager-abi.ts | 629 ------------------ .../erc20-transfer-amount-enforcer-abi.ts | 119 ---- .../src/exports/index.ts | 11 +- 5 files changed, 40 insertions(+), 758 deletions(-) create mode 100644 packages/universal-data/src/delegation/constants.ts delete mode 100644 packages/universal-delegations-sdk/src/abis/delegation-manager-abi.ts delete mode 100644 packages/universal-delegations-sdk/src/abis/erc20-transfer-amount-enforcer-abi.ts diff --git a/packages/universal-data/src/delegation/constants.ts b/packages/universal-data/src/delegation/constants.ts new file mode 100644 index 00000000..82447c76 --- /dev/null +++ b/packages/universal-data/src/delegation/constants.ts @@ -0,0 +1,28 @@ +import { type Address, type Hex, keccak256, toHex } from 'viem'; + +// Delegation constants +export const ANY_DELEGATE = + '0x0000000000000000000000000000000000000a11' as Address; +export const ROOT_AUTHORITY = + '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff' as Hex; + +// Execution Modes +export const BATCH_EXECUTION_MODE = [ + '0x0100000000000000000000000000000000000000000000000000000000000000' as Hex, +]; +export const SINGLE_EXECUTION_MODE = [ + '0x0000000000000000000000000000000000000000000000000000000000000000' as Hex, +]; +export const EMPTY_ARGS = '0x'; +export const EMPTY_SIGNATURE = '0x'; +export const SALT = BigInt(0); + +export const CAVEAT_TYPEHASH = keccak256( + toHex('Caveat(address enforcer,bytes terms)'), +); + +export const DELEGATION_TYPEHASH = keccak256( + toHex( + 'Delegation(address delegate,address delegator,bytes32 authority,Caveat[] caveats,uint256 salt)Caveat(address enforcer,bytes terms)', + ), +); diff --git a/packages/universal-data/src/exports/index.ts b/packages/universal-data/src/exports/index.ts index e747ba9f..6324c135 100644 --- a/packages/universal-data/src/exports/index.ts +++ b/packages/universal-data/src/exports/index.ts @@ -36,3 +36,14 @@ export type { } from '../types.js'; export { findTokenBySymbol } from '../utils/find-token-by-symbol.js'; export { findToken } from '../utils/find-token.js'; +export { + ANY_DELEGATE, + BATCH_EXECUTION_MODE, + CAVEAT_TYPEHASH, + DELEGATION_TYPEHASH, + EMPTY_ARGS, + EMPTY_SIGNATURE, + ROOT_AUTHORITY, + SALT, + SINGLE_EXECUTION_MODE, +} from '../delegation/constants.js'; diff --git a/packages/universal-delegations-sdk/src/abis/delegation-manager-abi.ts b/packages/universal-delegations-sdk/src/abis/delegation-manager-abi.ts deleted file mode 100644 index 242fa7da..00000000 --- a/packages/universal-delegations-sdk/src/abis/delegation-manager-abi.ts +++ /dev/null @@ -1,629 +0,0 @@ -export const delegationManagerAbi = [ - { - type: 'constructor', - inputs: [{ name: '_owner', type: 'address', internalType: 'address' }], - stateMutability: 'nonpayable', - }, - { - type: 'function', - name: 'ANY_DELEGATE', - inputs: [], - outputs: [{ name: '', type: 'address', internalType: 'address' }], - stateMutability: 'view', - }, - { - type: 'function', - name: 'DOMAIN_VERSION', - inputs: [], - outputs: [{ name: '', type: 'string', internalType: 'string' }], - stateMutability: 'view', - }, - { - type: 'function', - name: 'NAME', - inputs: [], - outputs: [{ name: '', type: 'string', internalType: 'string' }], - stateMutability: 'view', - }, - { - type: 'function', - name: 'ROOT_AUTHORITY', - inputs: [], - outputs: [{ name: '', type: 'bytes32', internalType: 'bytes32' }], - stateMutability: 'view', - }, - { - type: 'function', - name: 'VERSION', - inputs: [], - outputs: [{ name: '', type: 'string', internalType: 'string' }], - stateMutability: 'view', - }, - { - type: 'function', - name: 'acceptOwnership', - inputs: [], - outputs: [], - stateMutability: 'nonpayable', - }, - { - type: 'function', - name: 'disableDelegation', - inputs: [ - { - name: '_delegation', - type: 'tuple', - internalType: 'struct Delegation', - components: [ - { - name: 'delegate', - type: 'address', - internalType: 'address', - }, - { - name: 'delegator', - type: 'address', - internalType: 'address', - }, - { - name: 'authority', - type: 'bytes32', - internalType: 'bytes32', - }, - { - name: 'caveats', - type: 'tuple[]', - internalType: 'struct Caveat[]', - components: [ - { - name: 'enforcer', - type: 'address', - internalType: 'address', - }, - { name: 'terms', type: 'bytes', internalType: 'bytes' }, - { name: 'args', type: 'bytes', internalType: 'bytes' }, - ], - }, - { name: 'salt', type: 'uint256', internalType: 'uint256' }, - { name: 'signature', type: 'bytes', internalType: 'bytes' }, - ], - }, - ], - outputs: [], - stateMutability: 'nonpayable', - }, - { - type: 'function', - name: 'disabledDelegations', - inputs: [ - { - name: 'delegationHash', - type: 'bytes32', - internalType: 'bytes32', - }, - ], - outputs: [{ name: 'isDisabled', type: 'bool', internalType: 'bool' }], - stateMutability: 'view', - }, - { - type: 'function', - name: 'eip712Domain', - inputs: [], - outputs: [ - { name: 'fields', type: 'bytes1', internalType: 'bytes1' }, - { name: 'name', type: 'string', internalType: 'string' }, - { name: 'version', type: 'string', internalType: 'string' }, - { name: 'chainId', type: 'uint256', internalType: 'uint256' }, - { - name: 'verifyingContract', - type: 'address', - internalType: 'address', - }, - { name: 'salt', type: 'bytes32', internalType: 'bytes32' }, - { - name: 'extensions', - type: 'uint256[]', - internalType: 'uint256[]', - }, - ], - stateMutability: 'view', - }, - { - type: 'function', - name: 'enableDelegation', - inputs: [ - { - name: '_delegation', - type: 'tuple', - internalType: 'struct Delegation', - components: [ - { - name: 'delegate', - type: 'address', - internalType: 'address', - }, - { - name: 'delegator', - type: 'address', - internalType: 'address', - }, - { - name: 'authority', - type: 'bytes32', - internalType: 'bytes32', - }, - { - name: 'caveats', - type: 'tuple[]', - internalType: 'struct Caveat[]', - components: [ - { - name: 'enforcer', - type: 'address', - internalType: 'address', - }, - { name: 'terms', type: 'bytes', internalType: 'bytes' }, - { name: 'args', type: 'bytes', internalType: 'bytes' }, - ], - }, - { name: 'salt', type: 'uint256', internalType: 'uint256' }, - { name: 'signature', type: 'bytes', internalType: 'bytes' }, - ], - }, - ], - outputs: [], - stateMutability: 'nonpayable', - }, - { - type: 'function', - name: 'getDelegationHash', - inputs: [ - { - name: '_input', - type: 'tuple', - internalType: 'struct Delegation', - components: [ - { - name: 'delegate', - type: 'address', - internalType: 'address', - }, - { - name: 'delegator', - type: 'address', - internalType: 'address', - }, - { - name: 'authority', - type: 'bytes32', - internalType: 'bytes32', - }, - { - name: 'caveats', - type: 'tuple[]', - internalType: 'struct Caveat[]', - components: [ - { - name: 'enforcer', - type: 'address', - internalType: 'address', - }, - { name: 'terms', type: 'bytes', internalType: 'bytes' }, - { name: 'args', type: 'bytes', internalType: 'bytes' }, - ], - }, - { name: 'salt', type: 'uint256', internalType: 'uint256' }, - { name: 'signature', type: 'bytes', internalType: 'bytes' }, - ], - }, - ], - outputs: [{ name: '', type: 'bytes32', internalType: 'bytes32' }], - stateMutability: 'pure', - }, - { - type: 'function', - name: 'getDomainHash', - inputs: [], - outputs: [{ name: '', type: 'bytes32', internalType: 'bytes32' }], - stateMutability: 'view', - }, - { - type: 'function', - name: 'owner', - inputs: [], - outputs: [{ name: '', type: 'address', internalType: 'address' }], - stateMutability: 'view', - }, - { - type: 'function', - name: 'pause', - inputs: [], - outputs: [], - stateMutability: 'nonpayable', - }, - { - type: 'function', - name: 'paused', - inputs: [], - outputs: [{ name: '', type: 'bool', internalType: 'bool' }], - stateMutability: 'view', - }, - { - type: 'function', - name: 'pendingOwner', - inputs: [], - outputs: [{ name: '', type: 'address', internalType: 'address' }], - stateMutability: 'view', - }, - { - type: 'function', - name: 'redeemDelegations', - inputs: [ - { - name: '_permissionContexts', - type: 'bytes[]', - internalType: 'bytes[]', - }, - { name: '_modes', type: 'bytes32[]', internalType: 'ModeCode[]' }, - { - name: '_executionCallDatas', - type: 'bytes[]', - internalType: 'bytes[]', - }, - ], - outputs: [], - stateMutability: 'nonpayable', - }, - { - type: 'function', - name: 'renounceOwnership', - inputs: [], - outputs: [], - stateMutability: 'nonpayable', - }, - { - type: 'function', - name: 'transferOwnership', - inputs: [{ name: 'newOwner', type: 'address', internalType: 'address' }], - outputs: [], - stateMutability: 'nonpayable', - }, - { - type: 'function', - name: 'unpause', - inputs: [], - outputs: [], - stateMutability: 'nonpayable', - }, - { - type: 'event', - name: 'DisabledDelegation', - inputs: [ - { - name: 'delegationHash', - type: 'bytes32', - indexed: true, - internalType: 'bytes32', - }, - { - name: 'delegator', - type: 'address', - indexed: true, - internalType: 'address', - }, - { - name: 'delegate', - type: 'address', - indexed: true, - internalType: 'address', - }, - { - name: 'delegation', - type: 'tuple', - indexed: false, - internalType: 'struct Delegation', - components: [ - { - name: 'delegate', - type: 'address', - internalType: 'address', - }, - { - name: 'delegator', - type: 'address', - internalType: 'address', - }, - { - name: 'authority', - type: 'bytes32', - internalType: 'bytes32', - }, - { - name: 'caveats', - type: 'tuple[]', - internalType: 'struct Caveat[]', - components: [ - { - name: 'enforcer', - type: 'address', - internalType: 'address', - }, - { name: 'terms', type: 'bytes', internalType: 'bytes' }, - { name: 'args', type: 'bytes', internalType: 'bytes' }, - ], - }, - { name: 'salt', type: 'uint256', internalType: 'uint256' }, - { name: 'signature', type: 'bytes', internalType: 'bytes' }, - ], - }, - ], - anonymous: false, - }, - { - type: 'event', - name: 'EIP712DomainChanged', - inputs: [], - anonymous: false, - }, - { - type: 'event', - name: 'EnabledDelegation', - inputs: [ - { - name: 'delegationHash', - type: 'bytes32', - indexed: true, - internalType: 'bytes32', - }, - { - name: 'delegator', - type: 'address', - indexed: true, - internalType: 'address', - }, - { - name: 'delegate', - type: 'address', - indexed: true, - internalType: 'address', - }, - { - name: 'delegation', - type: 'tuple', - indexed: false, - internalType: 'struct Delegation', - components: [ - { - name: 'delegate', - type: 'address', - internalType: 'address', - }, - { - name: 'delegator', - type: 'address', - internalType: 'address', - }, - { - name: 'authority', - type: 'bytes32', - internalType: 'bytes32', - }, - { - name: 'caveats', - type: 'tuple[]', - internalType: 'struct Caveat[]', - components: [ - { - name: 'enforcer', - type: 'address', - internalType: 'address', - }, - { name: 'terms', type: 'bytes', internalType: 'bytes' }, - { name: 'args', type: 'bytes', internalType: 'bytes' }, - ], - }, - { name: 'salt', type: 'uint256', internalType: 'uint256' }, - { name: 'signature', type: 'bytes', internalType: 'bytes' }, - ], - }, - ], - anonymous: false, - }, - { - type: 'event', - name: 'OwnershipTransferStarted', - inputs: [ - { - name: 'previousOwner', - type: 'address', - indexed: true, - internalType: 'address', - }, - { - name: 'newOwner', - type: 'address', - indexed: true, - internalType: 'address', - }, - ], - anonymous: false, - }, - { - type: 'event', - name: 'OwnershipTransferred', - inputs: [ - { - name: 'previousOwner', - type: 'address', - indexed: true, - internalType: 'address', - }, - { - name: 'newOwner', - type: 'address', - indexed: true, - internalType: 'address', - }, - ], - anonymous: false, - }, - { - type: 'event', - name: 'Paused', - inputs: [ - { - name: 'account', - type: 'address', - indexed: false, - internalType: 'address', - }, - ], - anonymous: false, - }, - { - type: 'event', - name: 'RedeemedDelegation', - inputs: [ - { - name: 'rootDelegator', - type: 'address', - indexed: true, - internalType: 'address', - }, - { - name: 'redeemer', - type: 'address', - indexed: true, - internalType: 'address', - }, - { - name: 'delegation', - type: 'tuple', - indexed: false, - internalType: 'struct Delegation', - components: [ - { - name: 'delegate', - type: 'address', - internalType: 'address', - }, - { - name: 'delegator', - type: 'address', - internalType: 'address', - }, - { - name: 'authority', - type: 'bytes32', - internalType: 'bytes32', - }, - { - name: 'caveats', - type: 'tuple[]', - internalType: 'struct Caveat[]', - components: [ - { - name: 'enforcer', - type: 'address', - internalType: 'address', - }, - { name: 'terms', type: 'bytes', internalType: 'bytes' }, - { name: 'args', type: 'bytes', internalType: 'bytes' }, - ], - }, - { name: 'salt', type: 'uint256', internalType: 'uint256' }, - { name: 'signature', type: 'bytes', internalType: 'bytes' }, - ], - }, - ], - anonymous: false, - }, - { - type: 'event', - name: 'SetDomain', - inputs: [ - { - name: 'domainHash', - type: 'bytes32', - indexed: true, - internalType: 'bytes32', - }, - { - name: 'name', - type: 'string', - indexed: false, - internalType: 'string', - }, - { - name: 'domainVersion', - type: 'string', - indexed: false, - internalType: 'string', - }, - { - name: 'chainId', - type: 'uint256', - indexed: false, - internalType: 'uint256', - }, - { - name: 'contractAddress', - type: 'address', - indexed: true, - internalType: 'address', - }, - ], - anonymous: false, - }, - { - type: 'event', - name: 'Unpaused', - inputs: [ - { - name: 'account', - type: 'address', - indexed: false, - internalType: 'address', - }, - ], - anonymous: false, - }, - { type: 'error', name: 'AlreadyDisabled', inputs: [] }, - { type: 'error', name: 'AlreadyEnabled', inputs: [] }, - { type: 'error', name: 'BatchDataLengthMismatch', inputs: [] }, - { type: 'error', name: 'CannotUseADisabledDelegation', inputs: [] }, - { type: 'error', name: 'ECDSAInvalidSignature', inputs: [] }, - { - type: 'error', - name: 'ECDSAInvalidSignatureLength', - inputs: [{ name: 'length', type: 'uint256', internalType: 'uint256' }], - }, - { - type: 'error', - name: 'ECDSAInvalidSignatureS', - inputs: [{ name: 's', type: 'bytes32', internalType: 'bytes32' }], - }, - { type: 'error', name: 'EmptySignature', inputs: [] }, - { type: 'error', name: 'EnforcedPause', inputs: [] }, - { type: 'error', name: 'ExpectedPause', inputs: [] }, - { type: 'error', name: 'InvalidAuthority', inputs: [] }, - { type: 'error', name: 'InvalidDelegate', inputs: [] }, - { type: 'error', name: 'InvalidDelegator', inputs: [] }, - { type: 'error', name: 'InvalidShortString', inputs: [] }, - { type: 'error', name: 'InvalidSignature', inputs: [] }, - { - type: 'error', - name: 'OwnableInvalidOwner', - inputs: [{ name: 'owner', type: 'address', internalType: 'address' }], - }, - { - type: 'error', - name: 'OwnableUnauthorizedAccount', - inputs: [{ name: 'account', type: 'address', internalType: 'address' }], - }, - { - type: 'error', - name: 'StringTooLong', - inputs: [{ name: 'str', type: 'string', internalType: 'string' }], - }, -] as const; diff --git a/packages/universal-delegations-sdk/src/abis/erc20-transfer-amount-enforcer-abi.ts b/packages/universal-delegations-sdk/src/abis/erc20-transfer-amount-enforcer-abi.ts deleted file mode 100644 index 00ca32a4..00000000 --- a/packages/universal-delegations-sdk/src/abis/erc20-transfer-amount-enforcer-abi.ts +++ /dev/null @@ -1,119 +0,0 @@ -export const erc20TransferAmountEnforcerAbi = [ - { - type: 'function', - name: 'afterAllHook', - inputs: [ - { name: '', type: 'bytes', internalType: 'bytes' }, - { name: '', type: 'bytes', internalType: 'bytes' }, - { name: '', type: 'bytes32', internalType: 'ModeCode' }, - { name: '', type: 'bytes', internalType: 'bytes' }, - { name: '', type: 'bytes32', internalType: 'bytes32' }, - { name: '', type: 'address', internalType: 'address' }, - { name: '', type: 'address', internalType: 'address' }, - ], - outputs: [], - stateMutability: 'nonpayable', - }, - { - type: 'function', - name: 'afterHook', - inputs: [ - { name: '', type: 'bytes', internalType: 'bytes' }, - { name: '', type: 'bytes', internalType: 'bytes' }, - { name: '', type: 'bytes32', internalType: 'ModeCode' }, - { name: '', type: 'bytes', internalType: 'bytes' }, - { name: '', type: 'bytes32', internalType: 'bytes32' }, - { name: '', type: 'address', internalType: 'address' }, - { name: '', type: 'address', internalType: 'address' }, - ], - outputs: [], - stateMutability: 'nonpayable', - }, - { - type: 'function', - name: 'beforeAllHook', - inputs: [ - { name: '', type: 'bytes', internalType: 'bytes' }, - { name: '', type: 'bytes', internalType: 'bytes' }, - { name: '', type: 'bytes32', internalType: 'ModeCode' }, - { name: '', type: 'bytes', internalType: 'bytes' }, - { name: '', type: 'bytes32', internalType: 'bytes32' }, - { name: '', type: 'address', internalType: 'address' }, - { name: '', type: 'address', internalType: 'address' }, - ], - outputs: [], - stateMutability: 'nonpayable', - }, - { - type: 'function', - name: 'beforeHook', - inputs: [ - { name: '_terms', type: 'bytes', internalType: 'bytes' }, - { name: '', type: 'bytes', internalType: 'bytes' }, - { name: '_mode', type: 'bytes32', internalType: 'ModeCode' }, - { name: '_executionCallData', type: 'bytes', internalType: 'bytes' }, - { name: '_delegationHash', type: 'bytes32', internalType: 'bytes32' }, - { name: '', type: 'address', internalType: 'address' }, - { name: '_redeemer', type: 'address', internalType: 'address' }, - ], - outputs: [], - stateMutability: 'nonpayable', - }, - { - type: 'function', - name: 'getTermsInfo', - inputs: [{ name: '_terms', type: 'bytes', internalType: 'bytes' }], - outputs: [ - { name: 'allowedContract_', type: 'address', internalType: 'address' }, - { name: 'maxTokens_', type: 'uint256', internalType: 'uint256' }, - ], - stateMutability: 'pure', - }, - { - type: 'function', - name: 'spentMap', - inputs: [ - { name: 'delegationManager', type: 'address', internalType: 'address' }, - { name: 'delegationHash', type: 'bytes32', internalType: 'bytes32' }, - ], - outputs: [{ name: 'amount', type: 'uint256', internalType: 'uint256' }], - stateMutability: 'view', - }, - { - type: 'event', - name: 'IncreasedSpentMap', - inputs: [ - { - name: 'sender', - type: 'address', - indexed: true, - internalType: 'address', - }, - { - name: 'redeemer', - type: 'address', - indexed: true, - internalType: 'address', - }, - { - name: 'delegationHash', - type: 'bytes32', - indexed: true, - internalType: 'bytes32', - }, - { - name: 'limit', - type: 'uint256', - indexed: false, - internalType: 'uint256', - }, - { - name: 'spent', - type: 'uint256', - indexed: false, - internalType: 'uint256', - }, - ], - anonymous: false, - }, -] as const; diff --git a/packages/universal-delegations-sdk/src/exports/index.ts b/packages/universal-delegations-sdk/src/exports/index.ts index 61e7bca0..ee93acb7 100644 --- a/packages/universal-delegations-sdk/src/exports/index.ts +++ b/packages/universal-delegations-sdk/src/exports/index.ts @@ -47,13 +47,4 @@ export { SALT, SINGLE_EXECUTION_MODE, } from '../constants.js'; -export type { Delegation, Caveat, Execution } from '../types.js'; -export { delegationManagerAbi } from '../abis/delegation-manager-abi.js'; -export type { - DelegationsApi, - InsertDelegationDb, - SelectDelegationDb, - InsertCaveatDb, - SelectCaveatDb, - DelegationDb, -} from 'api-delegations'; +export type { DelegationsApi } from 'api-delegations';