@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/CHANGELOG.md +23 -0
- package/package.json +27 -3
- package/src/consts.d.ts +10 -0
- package/src/consts.js +16 -0
- package/src/consts.js.map +1 -0
- package/src/hookDappIframeTransport.d.ts +19 -0
- package/src/hookDappIframeTransport.js +15 -0
- package/src/hookDappIframeTransport.js.map +1 -0
- package/src/hookDappsRegistry.d.ts +203 -0
- package/src/hookDappsRegistry.js +208 -0
- package/src/hookDappsRegistry.js.map +1 -0
- package/src/index.d.ts +6 -0
- package/src/index.js +13 -0
- package/src/index.js.map +1 -0
- package/src/initCoWHookDapp.d.ts +11 -0
- package/src/initCoWHookDapp.js +30 -0
- package/src/initCoWHookDapp.js.map +1 -0
- package/src/types.d.ts +120 -0
- package/src/types.js +36 -0
- package/src/types.js.map +1 -0
- package/src/utils.d.ts +14 -0
- package/src/utils.js +48 -0
- package/src/utils.js.map +1 -0
- package/demo.png +0 -0
- package/jest.config.ts +0 -10
- package/project.json +0 -51
- package/src/consts.ts +0 -13
- package/src/hookDappIframeTransport.ts +0 -23
- package/src/hookDappsRegistry.ts +0 -209
- package/src/index.ts +0 -6
- package/src/initCoWHookDapp.ts +0 -42
- package/src/types.ts +0 -141
- package/src/utils.ts +0 -68
- package/tsconfig.json +0 -22
- package/tsconfig.lib.json +0 -10
- package/tsconfig.spec.json +0 -9
package/src/types.d.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { HookDappType, HookDappWalletCompatibility } from './consts';
|
|
2
|
+
export interface CowHook {
|
|
3
|
+
target: string;
|
|
4
|
+
callData: string;
|
|
5
|
+
gasLimit: string;
|
|
6
|
+
dappId: string;
|
|
7
|
+
}
|
|
8
|
+
export interface HookDappConditions {
|
|
9
|
+
position?: 'post' | 'pre';
|
|
10
|
+
walletCompatibility?: HookDappWalletCompatibility[];
|
|
11
|
+
supportedNetworks?: number[];
|
|
12
|
+
}
|
|
13
|
+
export interface CowHookCreation {
|
|
14
|
+
hook: Omit<CowHook, 'dappId'>;
|
|
15
|
+
recipientOverride?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface TokenData {
|
|
18
|
+
address: string;
|
|
19
|
+
}
|
|
20
|
+
export interface CowHookDetails extends CowHookCreation {
|
|
21
|
+
hook: CowHook;
|
|
22
|
+
uuid: string;
|
|
23
|
+
}
|
|
24
|
+
export interface CowHookToEdit extends CowHookCreation {
|
|
25
|
+
uuid: string;
|
|
26
|
+
}
|
|
27
|
+
export interface CoWHookDappActions {
|
|
28
|
+
addHook(payload: CowHookCreation): void;
|
|
29
|
+
editHook(payload: CowHookToEdit): void;
|
|
30
|
+
setSellToken(token: TokenData): void;
|
|
31
|
+
setBuyToken(token: TokenData): void;
|
|
32
|
+
}
|
|
33
|
+
export interface HookDappOrderParams {
|
|
34
|
+
kind: 'buy' | 'sell';
|
|
35
|
+
validTo: number;
|
|
36
|
+
sellTokenAddress: string;
|
|
37
|
+
buyTokenAddress: string;
|
|
38
|
+
receiver: string;
|
|
39
|
+
sellAmount: string;
|
|
40
|
+
buyAmount: string;
|
|
41
|
+
}
|
|
42
|
+
declare enum SimpleTypeType {
|
|
43
|
+
Address = "address",
|
|
44
|
+
Bool = "bool",
|
|
45
|
+
Bytes = "bytes",
|
|
46
|
+
Slice = "slice",
|
|
47
|
+
String = "string",
|
|
48
|
+
Uint = "uint"
|
|
49
|
+
}
|
|
50
|
+
interface Type {
|
|
51
|
+
type: SimpleTypeType;
|
|
52
|
+
}
|
|
53
|
+
declare enum SoltypeType {
|
|
54
|
+
Address = "address",
|
|
55
|
+
Bool = "bool",
|
|
56
|
+
Bytes32 = "bytes32",
|
|
57
|
+
MappingAddressUint256 = "mapping (address => uint256)",
|
|
58
|
+
MappingUint256Uint256 = "mapping (uint256 => uint256)",
|
|
59
|
+
String = "string",
|
|
60
|
+
Tuple = "tuple",
|
|
61
|
+
TypeAddress = "address[]",
|
|
62
|
+
TypeTuple = "tuple[]",
|
|
63
|
+
Uint16 = "uint16",
|
|
64
|
+
Uint256 = "uint256",
|
|
65
|
+
Uint48 = "uint48",
|
|
66
|
+
Uint56 = "uint56",
|
|
67
|
+
Uint8 = "uint8"
|
|
68
|
+
}
|
|
69
|
+
declare enum StorageLocation {
|
|
70
|
+
Calldata = "calldata",
|
|
71
|
+
Default = "default",
|
|
72
|
+
Memory = "memory",
|
|
73
|
+
Storage = "storage"
|
|
74
|
+
}
|
|
75
|
+
interface SoltypeElement {
|
|
76
|
+
name: string;
|
|
77
|
+
type: SoltypeType;
|
|
78
|
+
storage_location: StorageLocation;
|
|
79
|
+
components: SoltypeElement[] | null;
|
|
80
|
+
offset: number;
|
|
81
|
+
index: string;
|
|
82
|
+
indexed: boolean;
|
|
83
|
+
simple_type?: Type;
|
|
84
|
+
}
|
|
85
|
+
interface RawElement {
|
|
86
|
+
address: string;
|
|
87
|
+
key: string;
|
|
88
|
+
original: string;
|
|
89
|
+
dirty: string;
|
|
90
|
+
}
|
|
91
|
+
export interface StateDiff {
|
|
92
|
+
address: string;
|
|
93
|
+
soltype: SoltypeElement | null;
|
|
94
|
+
original: string | Record<string, unknown>;
|
|
95
|
+
dirty: string | Record<string, unknown>;
|
|
96
|
+
raw: RawElement[];
|
|
97
|
+
}
|
|
98
|
+
export interface HookDappContext {
|
|
99
|
+
chainId: number;
|
|
100
|
+
account?: string;
|
|
101
|
+
orderParams: HookDappOrderParams | null;
|
|
102
|
+
hookToEdit?: CowHookDetails;
|
|
103
|
+
isSmartContract: boolean | undefined;
|
|
104
|
+
isPreHook: boolean;
|
|
105
|
+
isDarkMode: boolean;
|
|
106
|
+
balancesDiff: Record<string, Record<string, string>>;
|
|
107
|
+
stateDiff: StateDiff[];
|
|
108
|
+
}
|
|
109
|
+
export interface HookDappBase {
|
|
110
|
+
id: string;
|
|
111
|
+
name: string;
|
|
112
|
+
descriptionShort?: string;
|
|
113
|
+
description?: string;
|
|
114
|
+
type: HookDappType;
|
|
115
|
+
version: string;
|
|
116
|
+
website: string;
|
|
117
|
+
image: string;
|
|
118
|
+
conditions?: HookDappConditions;
|
|
119
|
+
}
|
|
120
|
+
export {};
|
package/src/types.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var SimpleTypeType;
|
|
4
|
+
(function (SimpleTypeType) {
|
|
5
|
+
SimpleTypeType["Address"] = "address";
|
|
6
|
+
SimpleTypeType["Bool"] = "bool";
|
|
7
|
+
SimpleTypeType["Bytes"] = "bytes";
|
|
8
|
+
SimpleTypeType["Slice"] = "slice";
|
|
9
|
+
SimpleTypeType["String"] = "string";
|
|
10
|
+
SimpleTypeType["Uint"] = "uint";
|
|
11
|
+
})(SimpleTypeType || (SimpleTypeType = {}));
|
|
12
|
+
var SoltypeType;
|
|
13
|
+
(function (SoltypeType) {
|
|
14
|
+
SoltypeType["Address"] = "address";
|
|
15
|
+
SoltypeType["Bool"] = "bool";
|
|
16
|
+
SoltypeType["Bytes32"] = "bytes32";
|
|
17
|
+
SoltypeType["MappingAddressUint256"] = "mapping (address => uint256)";
|
|
18
|
+
SoltypeType["MappingUint256Uint256"] = "mapping (uint256 => uint256)";
|
|
19
|
+
SoltypeType["String"] = "string";
|
|
20
|
+
SoltypeType["Tuple"] = "tuple";
|
|
21
|
+
SoltypeType["TypeAddress"] = "address[]";
|
|
22
|
+
SoltypeType["TypeTuple"] = "tuple[]";
|
|
23
|
+
SoltypeType["Uint16"] = "uint16";
|
|
24
|
+
SoltypeType["Uint256"] = "uint256";
|
|
25
|
+
SoltypeType["Uint48"] = "uint48";
|
|
26
|
+
SoltypeType["Uint56"] = "uint56";
|
|
27
|
+
SoltypeType["Uint8"] = "uint8";
|
|
28
|
+
})(SoltypeType || (SoltypeType = {}));
|
|
29
|
+
var StorageLocation;
|
|
30
|
+
(function (StorageLocation) {
|
|
31
|
+
StorageLocation["Calldata"] = "calldata";
|
|
32
|
+
StorageLocation["Default"] = "default";
|
|
33
|
+
StorageLocation["Memory"] = "memory";
|
|
34
|
+
StorageLocation["Storage"] = "storage";
|
|
35
|
+
})(StorageLocation || (StorageLocation = {}));
|
|
36
|
+
//# sourceMappingURL=types.js.map
|
package/src/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../libs/hook-dapp-lib/src/types.ts"],"names":[],"mappings":";;AAqDA,IAAK,cAOJ;AAPD,WAAK,cAAc;IACjB,qCAAmB,CAAA;IACnB,+BAAa,CAAA;IACb,iCAAe,CAAA;IACf,iCAAe,CAAA;IACf,mCAAiB,CAAA;IACjB,+BAAa,CAAA;AACf,CAAC,EAPI,cAAc,KAAd,cAAc,QAOlB;AAMD,IAAK,WAeJ;AAfD,WAAK,WAAW;IACd,kCAAmB,CAAA;IACnB,4BAAa,CAAA;IACb,kCAAmB,CAAA;IACnB,qEAAsD,CAAA;IACtD,qEAAsD,CAAA;IACtD,gCAAiB,CAAA;IACjB,8BAAe,CAAA;IACf,wCAAyB,CAAA;IACzB,oCAAqB,CAAA;IACrB,gCAAiB,CAAA;IACjB,kCAAmB,CAAA;IACnB,gCAAiB,CAAA;IACjB,gCAAiB,CAAA;IACjB,8BAAe,CAAA;AACjB,CAAC,EAfI,WAAW,KAAX,WAAW,QAef;AAED,IAAK,eAKJ;AALD,WAAK,eAAe;IAClB,wCAAqB,CAAA;IACrB,sCAAmB,CAAA;IACnB,oCAAiB,CAAA;IACjB,sCAAmB,CAAA;AACrB,CAAC,EALI,eAAe,KAAf,eAAe,QAKnB"}
|
package/src/utils.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CowHook, HookDappBase } from './types';
|
|
2
|
+
type StrictCowHook = Omit<CowHook, 'dappId'> & {
|
|
3
|
+
dappId?: string;
|
|
4
|
+
};
|
|
5
|
+
export interface HookToDappMatch {
|
|
6
|
+
dapp: HookDappBase | null;
|
|
7
|
+
hook: CowHook;
|
|
8
|
+
}
|
|
9
|
+
export declare function matchHooksToDapps(hooks: StrictCowHook[], dapps: HookDappBase[]): HookToDappMatch[];
|
|
10
|
+
export declare function doesHookHavePermit(hook: {
|
|
11
|
+
callData: string;
|
|
12
|
+
}): boolean;
|
|
13
|
+
export declare function matchHooksToDappsRegistry(hooks: StrictCowHook[], additionalHookDapps?: HookDappBase[]): HookToDappMatch[];
|
|
14
|
+
export {};
|
package/src/utils.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.matchHooksToDapps = matchHooksToDapps;
|
|
4
|
+
exports.doesHookHavePermit = doesHookHavePermit;
|
|
5
|
+
exports.matchHooksToDappsRegistry = matchHooksToDappsRegistry;
|
|
6
|
+
const consts_1 = require("./consts");
|
|
7
|
+
const hookDappsRegistry_1 = require("./hookDappsRegistry");
|
|
8
|
+
const hookDapps = Object.keys(hookDappsRegistry_1.hookDappsRegistry).reduce((acc, id) => {
|
|
9
|
+
const dapp = hookDappsRegistry_1.hookDappsRegistry[id];
|
|
10
|
+
acc.push({ id, ...dapp });
|
|
11
|
+
return acc;
|
|
12
|
+
}, []);
|
|
13
|
+
// permit() function selector
|
|
14
|
+
const EIP_2612_PERMIT_SELECTOR = '0xd505accf';
|
|
15
|
+
const DAI_PERMIT_SELECTOR = '0x8fcbaf0c';
|
|
16
|
+
function matchHooksToDapps(hooks, dapps) {
|
|
17
|
+
const dappsMap = dapps.reduce((acc, dapp) => {
|
|
18
|
+
acc[dapp.id] = dapp;
|
|
19
|
+
return acc;
|
|
20
|
+
}, {});
|
|
21
|
+
return (hooks
|
|
22
|
+
// Skip hooks before the hooks store was introduced
|
|
23
|
+
.filter((hook) => !!hook.dappId)
|
|
24
|
+
.map((_hook) => {
|
|
25
|
+
const hook = _hook;
|
|
26
|
+
const dapp = dappsMap[hook.dappId];
|
|
27
|
+
/**
|
|
28
|
+
* Permit token is a special case, as it's not a dapp, but a hook
|
|
29
|
+
*/
|
|
30
|
+
if (doesHookHavePermit(hook)) {
|
|
31
|
+
return {
|
|
32
|
+
hook,
|
|
33
|
+
dapp: hookDappsRegistry_1.hookDappsRegistry[consts_1.PERMIT_HOOK_DAPP_ID],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
hook,
|
|
38
|
+
dapp: dapp || null,
|
|
39
|
+
};
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
function doesHookHavePermit(hook) {
|
|
43
|
+
return hook.callData.startsWith(EIP_2612_PERMIT_SELECTOR) || hook.callData.startsWith(DAI_PERMIT_SELECTOR);
|
|
44
|
+
}
|
|
45
|
+
function matchHooksToDappsRegistry(hooks, additionalHookDapps = []) {
|
|
46
|
+
return matchHooksToDapps(hooks, hookDapps.concat(additionalHookDapps));
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=utils.js.map
|
package/src/utils.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../libs/hook-dapp-lib/src/utils.ts"],"names":[],"mappings":";;AAuBA,8CAiCC;AAED,gDAEC;AAED,8DAKC;AAnED,qCAA8C;AAC9C,2DAAuD;AAGvD,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,qCAAiB,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE;IAClE,MAAM,IAAI,GAAI,qCAA8D,CAAC,EAAE,CAAC,CAAA;IAEhF,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC,CAAA;IACzB,OAAO,GAAG,CAAA;AACZ,CAAC,EAAE,EAAoB,CAAC,CAAA;AAExB,6BAA6B;AAC7B,MAAM,wBAAwB,GAAG,YAAY,CAAA;AAC7C,MAAM,mBAAmB,GAAG,YAAY,CAAA;AAUxC,SAAgB,iBAAiB,CAAC,KAAsB,EAAE,KAAqB;IAC7E,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAC3B,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;QACZ,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,CAAA;QACnB,OAAO,GAAG,CAAA;IACZ,CAAC,EACD,EAA8C,CAC/C,CAAA;IAED,OAAO,CACL,KAAK;QACH,mDAAmD;SAClD,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;SAC/B,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QACb,MAAM,IAAI,GAAG,KAAgB,CAAA;QAC7B,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAElC;;WAEG;QACH,IAAI,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7B,OAAO;gBACL,IAAI;gBACJ,IAAI,EAAE,qCAAiB,CAAC,4BAAmB,CAAiB;aAC7D,CAAA;QACH,CAAC;QAED,OAAO;YACL,IAAI;YACJ,IAAI,EAAE,IAAI,IAAI,IAAI;SACnB,CAAA;IACH,CAAC,CAAC,CACL,CAAA;AACH,CAAC;AAED,SAAgB,kBAAkB,CAAC,IAA0B;IAC3D,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,wBAAwB,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAA;AAC5G,CAAC;AAED,SAAgB,yBAAyB,CACvC,KAAsB,EACtB,sBAAsC,EAAE;IAExC,OAAO,iBAAiB,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAA;AACxE,CAAC"}
|
package/demo.png
DELETED
|
Binary file
|
package/jest.config.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
displayName: 'hook-dapp-lib',
|
|
3
|
-
preset: '../../jest.preset.js',
|
|
4
|
-
transform: {
|
|
5
|
-
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
|
|
6
|
-
},
|
|
7
|
-
setupFilesAfterEnv: ['../../jest.setup.ts'],
|
|
8
|
-
moduleFileExtensions: ['ts', 'js', 'html'],
|
|
9
|
-
coverageDirectory: '../../../coverage/libs/hook-dapp-lib',
|
|
10
|
-
}
|
package/project.json
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "hook-dapp-lib",
|
|
3
|
-
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
-
"sourceRoot": "libs/hook-dapp-lib/src",
|
|
5
|
-
"projectType": "library",
|
|
6
|
-
"targets": {
|
|
7
|
-
"build": {
|
|
8
|
-
"executor": "@nx/js:tsc",
|
|
9
|
-
"outputs": ["{options.outputPath}"],
|
|
10
|
-
"options": {
|
|
11
|
-
"outputPath": "dist/libs/hook-dapp-lib",
|
|
12
|
-
"main": "libs/hook-dapp-lib/src/index.ts",
|
|
13
|
-
"tsConfig": "libs/hook-dapp-lib/tsconfig.lib.json",
|
|
14
|
-
"assets": ["libs/hook-dapp-lib/*.md"],
|
|
15
|
-
"updateBuildableProjectDepsInPackageJson": true,
|
|
16
|
-
"buildableProjectDepsInPackageJsonType": "dependencies"
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
"serve": {
|
|
20
|
-
"executor": "@nx/vite:dev-server",
|
|
21
|
-
"defaultConfiguration": "development",
|
|
22
|
-
"options": {
|
|
23
|
-
"buildTarget": "hook-dapp-lib:build",
|
|
24
|
-
"port": 3012
|
|
25
|
-
},
|
|
26
|
-
"configurations": {}
|
|
27
|
-
},
|
|
28
|
-
"lint": {
|
|
29
|
-
"executor": "@nx/eslint:lint",
|
|
30
|
-
"outputs": ["{options.outputFile}"],
|
|
31
|
-
"options": {
|
|
32
|
-
"lintFilePatterns": ["libs/hook-dapp-lib/**/*.ts"]
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
"test": {
|
|
36
|
-
"executor": "@nx/jest:jest",
|
|
37
|
-
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
|
38
|
-
"options": {
|
|
39
|
-
"jestConfig": "libs/hook-dapp-lib/jest.config.ts",
|
|
40
|
-
"passWithNoTests": true
|
|
41
|
-
},
|
|
42
|
-
"configurations": {
|
|
43
|
-
"ci": {
|
|
44
|
-
"ci": true,
|
|
45
|
-
"codeCoverage": true
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
"tags": []
|
|
51
|
-
}
|
package/src/consts.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export enum HookDappType {
|
|
2
|
-
INTERNAL = 'INTERNAL',
|
|
3
|
-
IFRAME = 'IFRAME',
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export enum HookDappWalletCompatibility {
|
|
7
|
-
EOA = 'EOA',
|
|
8
|
-
SMART_CONTRACT = 'SMART_CONTRACT',
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const HOOK_DAPP_ID_LENGTH = 64
|
|
12
|
-
|
|
13
|
-
export const PERMIT_HOOK_DAPP_ID = 'cow-swap://libs/hook-dapp-lib/permit'
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { IframeTransport } from '@cowprotocol/iframe-transport'
|
|
2
|
-
|
|
3
|
-
import { CowHookCreation, CowHookDetails, HookDappContext, TokenData } from './types'
|
|
4
|
-
|
|
5
|
-
export enum CoWHookDappEvents {
|
|
6
|
-
ACTIVATE = 'ACTIVATE',
|
|
7
|
-
CONTEXT_UPDATE = 'CONTEXT_UPDATE',
|
|
8
|
-
ADD_HOOK = 'ADD_HOOK',
|
|
9
|
-
EDIT_HOOK = 'EDIT_HOOK',
|
|
10
|
-
SET_SELL_TOKEN = 'SET_SELL_TOKEN',
|
|
11
|
-
SET_BUY_TOKEN = 'SET_BUY_TOKEN',
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface HookDappEventsPayloadMap {
|
|
15
|
-
[CoWHookDappEvents.ACTIVATE]: void
|
|
16
|
-
[CoWHookDappEvents.CONTEXT_UPDATE]: HookDappContext
|
|
17
|
-
[CoWHookDappEvents.ADD_HOOK]: CowHookCreation
|
|
18
|
-
[CoWHookDappEvents.EDIT_HOOK]: CowHookDetails
|
|
19
|
-
[CoWHookDappEvents.SET_SELL_TOKEN]: TokenData
|
|
20
|
-
[CoWHookDappEvents.SET_BUY_TOKEN]: TokenData
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const hookDappIframeTransport = new IframeTransport<HookDappEventsPayloadMap>('cowSwapHookDapp')
|
package/src/hookDappsRegistry.ts
DELETED
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import { PERMIT_HOOK_DAPP_ID } from './consts'
|
|
2
|
-
|
|
3
|
-
export const hookDappsRegistry = {
|
|
4
|
-
BUILD_CUSTOM_HOOK: {
|
|
5
|
-
type: 'INTERNAL',
|
|
6
|
-
name: `Build your own hook`,
|
|
7
|
-
descriptionShort: `Call any smart contract with your own parameters`,
|
|
8
|
-
description: `Didn't find a suitable hook? You can always create your own! To do this, you need to specify which smart contract you want to call, the parameters for the call and the gas limit.`,
|
|
9
|
-
image:
|
|
10
|
-
'https://raw.githubusercontent.com/cowprotocol/cowswap/refs/heads/develop/apps/cowswap-frontend/src/modules/hooksStore/dapps/BuildHookApp/build.png',
|
|
11
|
-
version: 'v0.1.0',
|
|
12
|
-
website: 'https://docs.cow.fi/cow-protocol/tutorials/hook-dapp',
|
|
13
|
-
},
|
|
14
|
-
CLAIM_GNO_FROM_VALIDATORS: {
|
|
15
|
-
type: 'INTERNAL',
|
|
16
|
-
name: `Claim GNO from validators`,
|
|
17
|
-
descriptionShort: `Withdraw rewards from your Gnosis validators.`,
|
|
18
|
-
description: `This hook allows you to withdraw rewards from your Gnosis Chain validators through CoW Swap. It automates the process of interacting with the Gnosis Deposit Contract, enabling you to claim any available rewards directly to your specified withdrawal address. The hook monitors your validator's accrued rewards and triggers the claimWithdrawals function when rewards are ready for withdrawal. This simplifies the management of Gnosis validator earnings without requiring ready for withdrawal. This simplifies the management of Gnosis validator earnings without requiring manual contract interaction, providing a smoother and more efficient experience for users.`,
|
|
19
|
-
image:
|
|
20
|
-
'https://raw.githubusercontent.com/cowprotocol/cowswap/897ce91ca60a6b2d3823e6a002c3bf64c5384afe/libs/assets/src/cow-swap/network-gnosis-chain-logo.svg',
|
|
21
|
-
version: 'v0.1.1',
|
|
22
|
-
website: 'https://www.gnosis.io',
|
|
23
|
-
conditions: {
|
|
24
|
-
supportedNetworks: [100],
|
|
25
|
-
position: 'pre',
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
[PERMIT_HOOK_DAPP_ID]: {
|
|
29
|
-
type: 'INTERNAL',
|
|
30
|
-
name: `Permit a token`,
|
|
31
|
-
descriptionShort: `Permit an address to spend one token on your behalf.`,
|
|
32
|
-
description: `This hook allows you to permit an address to spend your tokens on your behalf. This is useful for allowing a smart contract to spend your tokens without needing to approve each transaction.`,
|
|
33
|
-
image:
|
|
34
|
-
'https://raw.githubusercontent.com/cowprotocol/cowswap/refs/heads/develop/apps/cowswap-frontend/src/modules/hooksStore/dapps/PermitHookApp/icon.png',
|
|
35
|
-
version: 'v0.1.0',
|
|
36
|
-
website: 'https://docs.cow.fi/cow-protocol/tutorials/hook-dapp',
|
|
37
|
-
conditions: {
|
|
38
|
-
walletCompatibility: ['EOA'],
|
|
39
|
-
supportedNetworks: [11155111],
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
CLAIM_COW_AIRDROP: {
|
|
43
|
-
type: 'INTERNAL',
|
|
44
|
-
name: `Claim COW Airdrop`,
|
|
45
|
-
descriptionShort: `Retrieve COW tokens before or after a swap.`,
|
|
46
|
-
description: `Effortless Airdrop Claims! The Claim COW Airdrop feature simplifies the process of collecting free COW tokens before or after your swap, seamlessly integrating into the CoW Swap platform. Whether you're claiming new airdrops or exploring CoW on a new network, this tool ensures you get your rewards quickly and easily.`,
|
|
47
|
-
image:
|
|
48
|
-
'https://raw.githubusercontent.com/cowprotocol/cowswap/897ce91ca60a6b2d3823e6a002c3bf64c5384afe/apps/cowswap-frontend/src/modules/hooksStore/dapps/AirdropHookApp/airdrop.svg',
|
|
49
|
-
version: 'v0.1.0',
|
|
50
|
-
website: 'https://github.com/bleu/cow-airdrop-contract-deployer',
|
|
51
|
-
conditions: {
|
|
52
|
-
supportedNetworks: [11155111],
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
COW_AMM_WITHDRAW: {
|
|
56
|
-
name: `CoW AMM Withdraw Liquidity`,
|
|
57
|
-
type: 'IFRAME',
|
|
58
|
-
descriptionShort: `Remove liquidity from a CoW AMM pool before the swap`,
|
|
59
|
-
description: `Reduce or withdraw liquidity from a pool before a token swap integrating the process directly into the transaction flow. By adjusting your liquidity ahead of time, you gain more control over your assets without any extra steps. Optimize your position in a pool, all in one seamless action — no need for multiple transactions or added complexity.`,
|
|
60
|
-
version: '0.0.1',
|
|
61
|
-
website: 'https://balancer.fi/pools/cow',
|
|
62
|
-
image: 'https://cow-hooks-dapps-withdraw-pool.vercel.app/icon.png',
|
|
63
|
-
url: 'https://cow-hooks-dapps-withdraw-pool.vercel.app/',
|
|
64
|
-
conditions: {
|
|
65
|
-
position: 'pre',
|
|
66
|
-
walletCompatibility: ['EOA'],
|
|
67
|
-
supportedNetworks: [1, 100, 8453, 42161, 11155111],
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
CLAIM_LLAMAPAY_VESTING: {
|
|
71
|
-
type: 'IFRAME',
|
|
72
|
-
name: `Claim LlamaPay Vesting Hook`,
|
|
73
|
-
description: `The Claim LlamaPay Vesting Hook is a powerful and user-friendly feature designed to streamline the process of claiming funds from LlamaPay vesting contracts. This tool empowers users to easily access and manage their vested tokens, ensuring a smooth and efficient experience in handling time-locked assets.`,
|
|
74
|
-
descriptionShort: `Claim your LlamaPay vesting contract funds`,
|
|
75
|
-
image: 'https://cow-hooks-dapps-claim-vesting.vercel.app/llama-pay-icon.png',
|
|
76
|
-
version: '0.1.0',
|
|
77
|
-
website: 'https://github.com/bleu/cow-hooks-dapps',
|
|
78
|
-
url: 'https://cow-hooks-dapps-claim-vesting.vercel.app',
|
|
79
|
-
conditions: {
|
|
80
|
-
supportedNetworks: [1, 100, 42161],
|
|
81
|
-
walletCompatibility: ['EOA'],
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
CREATE_LLAMAPAY_VESTING: {
|
|
85
|
-
type: 'IFRAME',
|
|
86
|
-
name: `Create LlamaPay Vesting`,
|
|
87
|
-
descriptionShort: `Create a LlamaPay vesting contract`,
|
|
88
|
-
description: `This hook allows you to easily set up vesting contracts with LlamaPay. Enter the recipient’s address or ENS name, then choose how much to transfer: the token buy will be automatically detected by the hook and the contracts will be linked to your LlamaPay dashboard for seamless tracking.`,
|
|
89
|
-
version: '0.1.0',
|
|
90
|
-
website: 'https://llamapay.io/vesting',
|
|
91
|
-
image: 'https://cow-hooks-dapps-create-vesting.vercel.app/llama-pay-icon.png',
|
|
92
|
-
url: 'https://cow-hooks-dapps-create-vesting.vercel.app',
|
|
93
|
-
conditions: {
|
|
94
|
-
position: 'post',
|
|
95
|
-
walletCompatibility: ['EOA'],
|
|
96
|
-
supportedNetworks: [1, 100, 42161],
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
UNI_V2_WITHDRAW: {
|
|
100
|
-
type: 'IFRAME',
|
|
101
|
-
name: `Withdraw Uniswap v2 Liquidity`,
|
|
102
|
-
descriptionShort: `Remove liquidity from a Uniswap v2 Weighted pool before the swap`,
|
|
103
|
-
description: `Reduce or withdraw Uniswap v2 from a pool before a token swap integrating the process directly into the transaction flow. By adjusting your liquidity ahead of time, you gain more control over your assets without any extra steps. Optimize your position in a pool, all in one seamless action — no need for multiple transactions or added complexity.`,
|
|
104
|
-
version: '0.0.1',
|
|
105
|
-
website: 'https://app.uniswap.org/pools/v2',
|
|
106
|
-
image: 'https://cow-hooks-dapps-withdraw-uniswap-v2.vercel.app/icon.png',
|
|
107
|
-
url: 'https://cow-hooks-dapps-withdraw-uniswap-v2.vercel.app/',
|
|
108
|
-
conditions: {
|
|
109
|
-
position: 'pre',
|
|
110
|
-
walletCompatibility: ['EOA'],
|
|
111
|
-
supportedNetworks: [1, 42161, 11155111, 8453],
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
COW_AMM_DEPOSIT: {
|
|
115
|
-
name: `CoW AMM Deposit`,
|
|
116
|
-
type: 'IFRAME',
|
|
117
|
-
descriptionShort: `Add liquidity to any of the CoW AMM pools`,
|
|
118
|
-
description: `Easily increase your position in a liquidity pool, adding both tokens in the right ratio.\n\n Whether you're seeking to increase your exposure to specific tokens or maximize the returns from your assets, this tool offers a quick and efficient way to enhance your liquidity position after a token swap, all in a smooth, efficient process.`,
|
|
119
|
-
version: '0.0.1',
|
|
120
|
-
website: 'https://balancer.fi/pools/cow',
|
|
121
|
-
image: 'https://cow-hooks-dapps-cow-amm-deposit.vercel.app/icon.png',
|
|
122
|
-
url: 'https://cow-hooks-dapps-cow-amm-deposit.vercel.app/',
|
|
123
|
-
conditions: {
|
|
124
|
-
position: 'post',
|
|
125
|
-
walletCompatibility: ['EOA'],
|
|
126
|
-
supportedNetworks: [1, 100, 8453, 42161, 11155111],
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
UNI_V2_DEPOSIT: {
|
|
130
|
-
name: `Uniswap v2 Deposit`,
|
|
131
|
-
type: 'IFRAME',
|
|
132
|
-
descriptionShort: `Add liquidity to a Uniswap v2 pool after the swap`,
|
|
133
|
-
description: `Easily increase your position in a liquidity pool, adding both tokens in the right ratio.\n\n Whether you're seeking to increase your exposure to specific tokens or maximize the returns from your assets, this tool offers a quick and efficient way to enhance your liquidity position after a token swap, all in a smooth, efficient process.`,
|
|
134
|
-
version: '0.0.1',
|
|
135
|
-
website: 'https://app.uniswap.org/pools/v2',
|
|
136
|
-
image: 'https://cow-hooks-dapps-9zio.vercel.app/icon.png',
|
|
137
|
-
url: 'https://cow-hooks-dapps-9zio.vercel.app/',
|
|
138
|
-
conditions: {
|
|
139
|
-
position: 'post',
|
|
140
|
-
walletCompatibility: ['EOA'],
|
|
141
|
-
supportedNetworks: [1, 42161, 11155111, 8453],
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
|
-
MORPHO_BORROW: {
|
|
145
|
-
name: `Morpho Borrow`,
|
|
146
|
-
type: 'IFRAME',
|
|
147
|
-
descriptionShort: `Supply collateral, borrow, repay and withdraw collateral on Morpho Protocol.`,
|
|
148
|
-
description: `The Morpho Borrow hook enables users to seamlessly combine swaps with borrow-related actions. Users can enter new positions, leave existing ones, or move between different markets through a unified, streamlined process.`,
|
|
149
|
-
version: '0.0.1',
|
|
150
|
-
website: 'https://app.morpho.org/',
|
|
151
|
-
image: 'https://cow-hooks-dapps-morpho-lending.vercel.app/icon.png',
|
|
152
|
-
url: 'https://cow-hooks-dapps-morpho-lending.vercel.app/',
|
|
153
|
-
conditions: {
|
|
154
|
-
walletCompatibility: ['EOA'],
|
|
155
|
-
supportedNetworks: [1, 137, 8453],
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
'cow-sdk://bridging/providers/bungee': {
|
|
159
|
-
name: `Bungee`,
|
|
160
|
-
type: 'INTERNAL',
|
|
161
|
-
descriptionShort: `Bungee Protocol - Swap tokens across chains`,
|
|
162
|
-
description: `Bungee is a liquidity marketplace that lets you swap into any token on any chain in a fully abstracted manner. Trade any token with the best quotes and a gasless UX!`,
|
|
163
|
-
version: '0.0.1',
|
|
164
|
-
website: 'https://www.bungee.exchange',
|
|
165
|
-
image: 'https://files.cow.fi/cow-sdk/bridging/providers/bungee/bungee-logo.png',
|
|
166
|
-
conditions: {
|
|
167
|
-
walletCompatibility: ['EOA'],
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
'cow-sdk://bridging/providers/across': {
|
|
171
|
-
name: `Across`,
|
|
172
|
-
type: 'INTERNAL',
|
|
173
|
-
descriptionShort: `Across Protocol - Transfer Assets Between Layer 2s and Mainnet`,
|
|
174
|
-
description: `Across is the fastest, cheapest and most secure cross-chain bridge for Ethereum, Arbitrum, Optimism, Polygon and other Layer 1 and Layer 2 networks. Transfer tokens with Across.`,
|
|
175
|
-
version: '0.0.1',
|
|
176
|
-
website: 'https://across.to',
|
|
177
|
-
image: 'https://files.cow.fi/cow-sdk/bridging/providers/across/across-logo.png',
|
|
178
|
-
conditions: {
|
|
179
|
-
walletCompatibility: ['EOA'],
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
'cow-sdk://flashloans/aave/v3/collateral-swap': {
|
|
183
|
-
name: `Aave Collateral Swap`,
|
|
184
|
-
type: 'INTERNAL',
|
|
185
|
-
descriptionShort: `Aave Collateral Swap Flashloan`,
|
|
186
|
-
description: `The swap adapter contracts integrate Aave Flash Loans and CoW Swap to facilitate advanced actions like swapping collateral assets when there are borrow positions. Learn more at https://aave.com/docs/developers/smart-contracts/swap-features.`,
|
|
187
|
-
version: '0.0.1',
|
|
188
|
-
website: 'https://aave.com',
|
|
189
|
-
image: 'https://files.cow.fi/token-lists/images/1/0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9/logo.png',
|
|
190
|
-
},
|
|
191
|
-
'cow-sdk://flashloans/aave/v3/debt-swap': {
|
|
192
|
-
name: `Aave Debt Swap`,
|
|
193
|
-
type: 'INTERNAL',
|
|
194
|
-
descriptionShort: `Aave Debt Swap Flashloan`,
|
|
195
|
-
description: `The swap adapter contracts integrate Aave Flash Loans and CoW Swap to facilitate advanced actions like swapping debt assets. Learn more at https://aave.com/docs/developers/smart-contracts/swap-features.`,
|
|
196
|
-
version: '0.0.1',
|
|
197
|
-
website: 'https://aave.com',
|
|
198
|
-
image: 'https://files.cow.fi/token-lists/images/1/0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9/logo.png',
|
|
199
|
-
},
|
|
200
|
-
'cow-sdk://flashloans/aave/v3/repay-with-collateral': {
|
|
201
|
-
name: `Aave Repay`,
|
|
202
|
-
type: 'INTERNAL',
|
|
203
|
-
descriptionShort: `Aave Repay with Collateral Flashloan`,
|
|
204
|
-
description: `The swap adapter contracts integrate Aave Flash Loans and CoW Swap to facilitate advanced actions like repaying borrow positions using collateral. Learn more at https://aave.com/docs/developers/smart-contracts/swap-features.`,
|
|
205
|
-
version: '0.0.1',
|
|
206
|
-
website: 'https://aave.com',
|
|
207
|
-
image: 'https://files.cow.fi/token-lists/images/1/0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9/logo.png',
|
|
208
|
-
},
|
|
209
|
-
}
|
package/src/index.ts
DELETED
package/src/initCoWHookDapp.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { WidgetEthereumProvider } from '@cowprotocol/iframe-transport'
|
|
2
|
-
|
|
3
|
-
import { CoWHookDappEvents, hookDappIframeTransport } from './hookDappIframeTransport'
|
|
4
|
-
import { CowHookCreation, CoWHookDappActions, CowHookDetails, HookDappContext, TokenData } from './types'
|
|
5
|
-
|
|
6
|
-
interface CoWHookDappInit {
|
|
7
|
-
onContext(context: HookDappContext): void
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface CoWHookDappHandler {
|
|
11
|
-
actions: CoWHookDappActions
|
|
12
|
-
provider: WidgetEthereumProvider
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function initCoWHookDapp({ onContext }: CoWHookDappInit): CoWHookDappHandler {
|
|
16
|
-
const parent = window.parent
|
|
17
|
-
const provider = new WidgetEthereumProvider()
|
|
18
|
-
const actions = getCoWHookDappActions()
|
|
19
|
-
|
|
20
|
-
hookDappIframeTransport.listenToMessageFromWindow(window, CoWHookDappEvents.CONTEXT_UPDATE, onContext)
|
|
21
|
-
|
|
22
|
-
hookDappIframeTransport.postMessageToWindow(parent, CoWHookDappEvents.ACTIVATE, void 0)
|
|
23
|
-
|
|
24
|
-
return { actions, provider }
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function getCoWHookDappActions(): CoWHookDappActions {
|
|
28
|
-
return {
|
|
29
|
-
addHook(payload: CowHookCreation) {
|
|
30
|
-
hookDappIframeTransport.postMessageToWindow(parent, CoWHookDappEvents.ADD_HOOK, payload)
|
|
31
|
-
},
|
|
32
|
-
editHook(payload: CowHookDetails) {
|
|
33
|
-
hookDappIframeTransport.postMessageToWindow(parent, CoWHookDappEvents.EDIT_HOOK, payload)
|
|
34
|
-
},
|
|
35
|
-
setSellToken(token: TokenData) {
|
|
36
|
-
hookDappIframeTransport.postMessageToWindow(parent, CoWHookDappEvents.SET_SELL_TOKEN, token)
|
|
37
|
-
},
|
|
38
|
-
setBuyToken(token: TokenData) {
|
|
39
|
-
hookDappIframeTransport.postMessageToWindow(parent, CoWHookDappEvents.SET_BUY_TOKEN, token)
|
|
40
|
-
},
|
|
41
|
-
}
|
|
42
|
-
}
|