@cowprotocol/hook-dapp-lib 2.0.7 → 2.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.ts DELETED
@@ -1,141 +0,0 @@
1
- import { HookDappType, HookDappWalletCompatibility } from './consts'
2
-
3
- export interface CowHook {
4
- target: string
5
- callData: string
6
- gasLimit: string
7
- dappId: string
8
- }
9
-
10
- export interface HookDappConditions {
11
- position?: 'post' | 'pre'
12
- walletCompatibility?: HookDappWalletCompatibility[]
13
- supportedNetworks?: number[]
14
- }
15
-
16
- export interface CowHookCreation {
17
- hook: Omit<CowHook, 'dappId'>
18
- recipientOverride?: string
19
- }
20
-
21
- export interface TokenData {
22
- address: string
23
- }
24
-
25
- export interface CowHookDetails extends CowHookCreation {
26
- hook: CowHook
27
- uuid: string
28
- }
29
-
30
- export interface CowHookToEdit extends CowHookCreation {
31
- uuid: string
32
- }
33
-
34
- export interface CoWHookDappActions {
35
- addHook(payload: CowHookCreation): void
36
-
37
- editHook(payload: CowHookToEdit): void
38
-
39
- setSellToken(token: TokenData): void
40
-
41
- setBuyToken(token: TokenData): void
42
- }
43
-
44
- export interface HookDappOrderParams {
45
- kind: 'buy' | 'sell'
46
- validTo: number
47
- sellTokenAddress: string
48
- buyTokenAddress: string
49
- receiver: string
50
- sellAmount: string
51
- buyAmount: string
52
- }
53
-
54
- enum SimpleTypeType {
55
- Address = 'address',
56
- Bool = 'bool',
57
- Bytes = 'bytes',
58
- Slice = 'slice',
59
- String = 'string',
60
- Uint = 'uint',
61
- }
62
-
63
- interface Type {
64
- type: SimpleTypeType
65
- }
66
-
67
- enum SoltypeType {
68
- Address = 'address',
69
- Bool = 'bool',
70
- Bytes32 = 'bytes32',
71
- MappingAddressUint256 = 'mapping (address => uint256)',
72
- MappingUint256Uint256 = 'mapping (uint256 => uint256)',
73
- String = 'string',
74
- Tuple = 'tuple',
75
- TypeAddress = 'address[]',
76
- TypeTuple = 'tuple[]',
77
- Uint16 = 'uint16',
78
- Uint256 = 'uint256',
79
- Uint48 = 'uint48',
80
- Uint56 = 'uint56',
81
- Uint8 = 'uint8',
82
- }
83
-
84
- enum StorageLocation {
85
- Calldata = 'calldata',
86
- Default = 'default',
87
- Memory = 'memory',
88
- Storage = 'storage',
89
- }
90
-
91
- interface SoltypeElement {
92
- name: string
93
- type: SoltypeType
94
- storage_location: StorageLocation
95
- components: SoltypeElement[] | null
96
- offset: number
97
- index: string
98
- indexed: boolean
99
- simple_type?: Type
100
- }
101
-
102
- interface RawElement {
103
- address: string
104
- key: string
105
- original: string
106
- dirty: string
107
- }
108
-
109
- export interface StateDiff {
110
- address: string
111
- soltype: SoltypeElement | null
112
- original: string | Record<string, unknown>
113
- dirty: string | Record<string, unknown>
114
- raw: RawElement[]
115
- }
116
-
117
- export interface HookDappContext {
118
- chainId: number
119
- account?: string
120
- orderParams: HookDappOrderParams | null
121
- hookToEdit?: CowHookDetails
122
- isSmartContract: boolean | undefined
123
- isPreHook: boolean
124
- isDarkMode: boolean
125
- // { [address: string]: { [token: string]: balanceDiff: string } }
126
- // example: { '0x123': { '0x456': '100', '0xabc': '-100' } }
127
- balancesDiff: Record<string, Record<string, string>>
128
- stateDiff: StateDiff[]
129
- }
130
-
131
- export interface HookDappBase {
132
- id: string
133
- name: string
134
- descriptionShort?: string
135
- description?: string
136
- type: HookDappType
137
- version: string
138
- website: string
139
- image: string
140
- conditions?: HookDappConditions
141
- }
package/src/utils.ts DELETED
@@ -1,68 +0,0 @@
1
- import { PERMIT_HOOK_DAPP_ID } from './consts'
2
- import { hookDappsRegistry } from './hookDappsRegistry'
3
- import { CowHook, HookDappBase } from './types'
4
-
5
- const hookDapps = Object.keys(hookDappsRegistry).reduce((acc, id) => {
6
- const dapp = (hookDappsRegistry as Record<string, Omit<HookDappBase, 'id'>>)[id]
7
-
8
- acc.push({ id, ...dapp })
9
- return acc
10
- }, [] as HookDappBase[])
11
-
12
- // permit() function selector
13
- const EIP_2612_PERMIT_SELECTOR = '0xd505accf'
14
- const DAI_PERMIT_SELECTOR = '0x8fcbaf0c'
15
-
16
- // Before the hooks store the dappId wasn't included in the hook object
17
- type StrictCowHook = Omit<CowHook, 'dappId'> & { dappId?: string }
18
-
19
- export interface HookToDappMatch {
20
- dapp: HookDappBase | null
21
- hook: CowHook
22
- }
23
-
24
- export function matchHooksToDapps(hooks: StrictCowHook[], dapps: HookDappBase[]): HookToDappMatch[] {
25
- const dappsMap = dapps.reduce(
26
- (acc, dapp) => {
27
- acc[dapp.id] = dapp
28
- return acc
29
- },
30
- {} as Record<string, HookDappBase | undefined>,
31
- )
32
-
33
- return (
34
- hooks
35
- // Skip hooks before the hooks store was introduced
36
- .filter((hook) => !!hook.dappId)
37
- .map((_hook) => {
38
- const hook = _hook as CowHook
39
- const dapp = dappsMap[hook.dappId]
40
-
41
- /**
42
- * Permit token is a special case, as it's not a dapp, but a hook
43
- */
44
- if (doesHookHavePermit(hook)) {
45
- return {
46
- hook,
47
- dapp: hookDappsRegistry[PERMIT_HOOK_DAPP_ID] as HookDappBase,
48
- }
49
- }
50
-
51
- return {
52
- hook,
53
- dapp: dapp || null,
54
- }
55
- })
56
- )
57
- }
58
-
59
- export function doesHookHavePermit(hook: { callData: string }): boolean {
60
- return hook.callData.startsWith(EIP_2612_PERMIT_SELECTOR) || hook.callData.startsWith(DAI_PERMIT_SELECTOR)
61
- }
62
-
63
- export function matchHooksToDappsRegistry(
64
- hooks: StrictCowHook[],
65
- additionalHookDapps: HookDappBase[] = [],
66
- ): HookToDappMatch[] {
67
- return matchHooksToDapps(hooks, hookDapps.concat(additionalHookDapps))
68
- }
package/tsconfig.json DELETED
@@ -1,22 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "module": "commonjs",
5
- "forceConsistentCasingInFileNames": true,
6
- "strict": true,
7
- "noImplicitOverride": true,
8
- "noPropertyAccessFromIndexSignature": true,
9
- "noImplicitReturns": true,
10
- "noFallthroughCasesInSwitch": true
11
- },
12
- "files": [],
13
- "include": [],
14
- "references": [
15
- {
16
- "path": "./tsconfig.lib.json"
17
- },
18
- {
19
- "path": "./tsconfig.spec.json"
20
- }
21
- ]
22
- }
package/tsconfig.lib.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
- "declaration": true,
6
- "types": ["node"]
7
- },
8
- "include": ["src/**/*.ts"],
9
- "exclude": ["src/**/*.spec.ts", "src/**/*.test.ts"]
10
- }
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../../dist/out-tsc",
5
- "module": "commonjs",
6
- "types": ["jest", "node"]
7
- },
8
- "include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts", "src/lib/widget.ts"]
9
- }