@cowprotocol/hook-dapp-lib 1.0.0-RC1 → 1.1.0

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/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # CoW Protocol hooks
2
+
3
+ >CoW Hooks allow users to call arbitrary Ethereum action before and/or after swap.
4
+ >For example: before swap give a permission to CoW Protocol smart-contract and after swap bridge tokens to another chain.
5
+
6
+ ### Docs: https://docs.cow.fi/cow-protocol/tutorials/hook-dapp
7
+
8
+ ![](./demo.png)
9
+
10
+ ## CoW Hooks Dapp library
11
+
12
+ [CoW Swap](https://swap.cow.fi/) provides an opportunity to use external dapps to build hooks.
13
+ So, you can put a link to some hook-daap and it will be automatically integrate in CoW Swap!
14
+
15
+ This library is for developers who are interested in developing dapps for CoW Hooks.
16
+ It provides:
17
+ - `EIP-1193` provider to interact with a user wallet
18
+ - `HookDappContext` which contains environment parameters (chainId, account, etc.) and current order parameters (sell token, validTo, etc.)
19
+
20
+ And it expects calling two callbacks:
21
+ - `addHook()` when a hook data is ready and can be added to an order
22
+ - `editHook()` when hook parameters were changed
23
+
24
+ ## Quick start
25
+
26
+ ```
27
+ npm install @cowprotocol/hook-dapp-lib --save
28
+ ```
29
+
30
+ ```
31
+ yarn add @cowprotocol/hook-dapp-lib
32
+ ```
33
+
34
+ Let's create a simple hook-dapp that will check the COW token balance of the order creator.
35
+
36
+ ```html
37
+ <html>
38
+ <body>
39
+ <button id="actionButton">Add hook</button>
40
+
41
+ <script>
42
+ import { initCoWHookDapp, HookDappContext } from '@cowprotocol/hook-dapp-lib'
43
+
44
+ const COW_TOKEN_ADDRESS = '0xdef1ca1fb7fbcdc777520aa7f396b4e015f497ab'
45
+ // ERC20.balanceOf(account)
46
+ const CALL_DATA = (account: string) => `0x70a08231000000000000000000000000${account.slice(2)}`
47
+
48
+ let context: HookDappContext | null = null
49
+
50
+ const { actions } = initCoWHookDapp({ onContext: (_context) => context = _context })
51
+
52
+ document.getElementById('actionButton').addEventListener('click', () => {
53
+ if (!context) {
54
+ console.log('App is not loaded yet, please wait a bit.')
55
+ return
56
+ }
57
+
58
+ if (context.hookToEdit) {
59
+ // Implement a logic for editing an existing hook
60
+ // And call actions.editHook() with new parameters
61
+ }
62
+
63
+ actions.addHook({
64
+ hook: {
65
+ target: COW_TOKEN_ADDRESS,
66
+ callData: CALL_DATA(context.account),
67
+ gasLimit: '32000'
68
+ }
69
+ })
70
+ })
71
+ </script>
72
+ </body>
73
+ </html>
74
+ ```
75
+
76
+ ## Developers
77
+
78
+ #### Test
79
+
80
+ ```
81
+ nx test hook-dapp-lib
82
+ ```
83
+
84
+ #### Build the library
85
+
86
+ ```
87
+ nx build hook-dapp-lib
88
+ ```
package/index.iife.js CHANGED
@@ -1 +1 @@
1
- var cowSwapWidget=function(u){"use strict";var $=Object.defineProperty;var Q=(u,_,O)=>_ in u?$(u,_,{enumerable:!0,configurable:!0,writable:!0,value:O}):u[_]=O;var T=(u,_,O)=>(Q(u,typeof _!="symbol"?_+"":_,O),O);class _{constructor(p){this.key=p}postMessageToWindow(p,e,t){const c=typeof t=="object"?t:{},f={key:this.key,method:e,...c};p.postMessage(f,"*")}listenToMessageFromWindow(p,e,t){const c=f=>{!O(f.data)||f.data.key!==this.key||f.data.method!==e||t(f.data)};return p.addEventListener("message",c),c}stopListeningToMessageFromWindow(p,e,t){p.removeEventListener("message",t)}stopListeningWindowListener(p,e){p.removeEventListener("message",e)}}function O(o){return typeof o=="object"&&o!==null&&"key"in o&&"method"in o&&typeof o.key=="string"&&typeof o.method=="string"}var R=(o=>(o.PROVIDER_RPC_REQUEST="PROVIDER_RPC_REQUEST",o.PROVIDER_RPC_RESPONSE="PROVIDER_RPC_RESPONSE",o.PROVIDER_ON_EVENT="PROVIDER_ON_EVENT",o))(R||{});const A=new _("cowSwapIframeRpcProviderTransport");var N={exports:{}};(function(o){var p=Object.prototype.hasOwnProperty,e="~";function t(){}Object.create&&(t.prototype=Object.create(null),new t().__proto__||(e=!1));function c(a,r,s){this.fn=a,this.context=r,this.once=s||!1}function f(a,r,s,i,w){if(typeof s!="function")throw new TypeError("The listener must be a function");var m=new c(s,i||a,w),l=e?e+r:r;return a._events[l]?a._events[l].fn?a._events[l]=[a._events[l],m]:a._events[l].push(m):(a._events[l]=m,a._eventsCount++),a}function g(a,r){--a._eventsCount===0?a._events=new t:delete a._events[r]}function h(){this._events=new t,this._eventsCount=0}h.prototype.eventNames=function(){var r=[],s,i;if(this._eventsCount===0)return r;for(i in s=this._events)p.call(s,i)&&r.push(e?i.slice(1):i);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(s)):r},h.prototype.listeners=function(r){var s=e?e+r:r,i=this._events[s];if(!i)return[];if(i.fn)return[i.fn];for(var w=0,m=i.length,l=new Array(m);w<m;w++)l[w]=i[w].fn;return l},h.prototype.listenerCount=function(r){var s=e?e+r:r,i=this._events[s];return i?i.fn?1:i.length:0},h.prototype.emit=function(r,s,i,w,m,l){var v=e?e+r:r;if(!this._events[v])return!1;var n=this._events[v],y=arguments.length,C,d;if(n.fn){switch(n.once&&this.removeListener(r,n.fn,void 0,!0),y){case 1:return n.fn.call(n.context),!0;case 2:return n.fn.call(n.context,s),!0;case 3:return n.fn.call(n.context,s,i),!0;case 4:return n.fn.call(n.context,s,i,w),!0;case 5:return n.fn.call(n.context,s,i,w,m),!0;case 6:return n.fn.call(n.context,s,i,w,m,l),!0}for(d=1,C=new Array(y-1);d<y;d++)C[d-1]=arguments[d];n.fn.apply(n.context,C)}else{var Y=n.length,k;for(d=0;d<Y;d++)switch(n[d].once&&this.removeListener(r,n[d].fn,void 0,!0),y){case 1:n[d].fn.call(n[d].context);break;case 2:n[d].fn.call(n[d].context,s);break;case 3:n[d].fn.call(n[d].context,s,i);break;case 4:n[d].fn.call(n[d].context,s,i,w);break;default:if(!C)for(k=1,C=new Array(y-1);k<y;k++)C[k-1]=arguments[k];n[d].fn.apply(n[d].context,C)}}return!0},h.prototype.on=function(r,s,i){return f(this,r,s,i,!1)},h.prototype.once=function(r,s,i){return f(this,r,s,i,!0)},h.prototype.removeListener=function(r,s,i,w){var m=e?e+r:r;if(!this._events[m])return this;if(!s)return g(this,m),this;var l=this._events[m];if(l.fn)l.fn===s&&(!w||l.once)&&(!i||l.context===i)&&g(this,m);else{for(var v=0,n=[],y=l.length;v<y;v++)(l[v].fn!==s||w&&!l[v].once||i&&l[v].context!==i)&&n.push(l[v]);n.length?this._events[m]=n.length===1?n[0]:n:g(this,m)}return this},h.prototype.removeAllListeners=function(r){var s;return r?(s=e?e+r:r,this._events[s]&&g(this,s)):(this._events=new t,this._eventsCount=0),this},h.prototype.off=h.prototype.removeListener,h.prototype.addListener=h.prototype.on,h.prefixed=e,h.EventEmitter=h,o.exports=h})(N);var V=N.exports;const U=6e5,x="2.0";function F(){return Math.floor(Math.random()*Number.MAX_SAFE_INTEGER)}class G extends Error{constructor(e,t){super(`${e}: ${t}`);T(this,"isRpcError",!0);T(this,"code");T(this,"reason");this.code=e,this.reason=t}}class B extends V.EventEmitter{constructor({timeoutMilliseconds:e=U,eventSource:t=window,eventTarget:c=window.parent}={}){super();T(this,"enabled",null);T(this,"timeoutMilliseconds");T(this,"eventSource");T(this,"eventTarget");T(this,"completers",{});T(this,"handleRpcRequests",({rpcResponse:e})=>{if(e.id===void 0||e.id===null)return;const t=this.completers[""+e.id];t&&("error"in e||"result"in e?t.resolve(e):t.reject(new Error("Response from provider did not have error or result key")),delete this.completers[e.id])});this.timeoutMilliseconds=e,this.eventSource=t,this.eventTarget=c,A.listenToMessageFromWindow(this.eventSource,R.PROVIDER_RPC_RESPONSE,f=>{this.handleRpcRequests(f)}),A.listenToMessageFromWindow(this.eventSource,R.PROVIDER_ON_EVENT,f=>{this.handleOnEvent(f)})}request({method:e,params:t}){return this.send(e,t)}isConnected(){return!0}get isIFrame(){return!0}get currentProvider(){return this}async execute(e,t){const c=F(),f={jsonrpc:x,id:c,method:e,params:t},g=new Promise((h,a)=>this.completers[c]={resolve:h,reject:a});return A.postMessageToWindow(this.eventTarget,R.PROVIDER_RPC_REQUEST,{rpcRequest:f}),setTimeout(()=>{this.completers[c]&&(this.completers[c].reject(new Error("Request timed out. Please try again and submit it faster.")),delete this.completers[c])},this.timeoutMilliseconds),g}async send(e,t){const{method:c,params:f}=typeof e=="string"?{method:e,params:t}:{method:e.method,params:e.params},g=await this.execute(c,f);if("error"in g)throw new G(g.error.code,g.error.message);return g.result}async enable(){if(this.enabled===null){const e=this.enabled=this.send("enable",[]).catch(t=>{throw this.enabled===e&&(this.enabled=null),t})}return this.enabled}async sendAsync(e,t){try{const c=await this.execute(e.method,e.params);t(null,c)}catch(c){t(c,null)}}handleOnEvent(e){const t=e.params;switch(e.event){case"notification":this.emitNotification(t);break;case"connect":this.emitConnect(t);break;case"disconnect":this.emitDisconnect(t);break;case"chainChanged":this.emitChainChanged(t);break;case"accountsChanged":this.emitAccountsChanged(t);break;case"message":this.emitMessage(t);break;case"networkChanged":this.emitNetworkChanged(t);break;case"close":this.emitClose(t);break;default:console.warn(`[WidgetEthereumProvider] Unknown event type: ${e.event}`);break}}emitNotification(e){this.emit("notification",e)}emitConnect(e){this.enabled===null&&(this.enabled=Promise.resolve([])),this.emit("connect",e)}emitClose(e){Array.isArray(e)&&e.length===2?this.emit("close",e[0],e[1]):this.emit("close")}emitDisconnect(e){this.emit("disconnect",e)}emitChainChanged(e){this.emit("chainChanged",e)}emitNetworkChanged(e){this.emit("networkChanged",e)}emitAccountsChanged(e){this.enabled=Promise.resolve(e),this.emit("accountsChanged",e)}emitMessage(e){this.emit("message",e)}}var E=(o=>(o.ACTIVATE="ACTIVATE",o.CONTEXT_UPDATE="CONTEXT_UPDATE",o.ADD_HOOK="ADD_HOOK",o.EDIT_HOOK="EDIT_HOOK",o.SET_SELL_TOKEN="SET_SELL_TOKEN",o.SET_BUY_TOKEN="SET_BUY_TOKEN",o))(E||{});const b=new _("cowSwapHookDapp");function q({onContext:o}){const p=window.parent,e=new B,t=j();return b.listenToMessageFromWindow(window,E.CONTEXT_UPDATE,o),b.postMessageToWindow(p,E.ACTIVATE,void 0),{actions:t,provider:e}}function j(){return{addHook(o){b.postMessageToWindow(parent,E.ADD_HOOK,o)},editHook(o){b.postMessageToWindow(parent,E.EDIT_HOOK,o)},setSellToken(o){b.postMessageToWindow(parent,E.SET_SELL_TOKEN,o)},setBuyToken(o){b.postMessageToWindow(parent,E.SET_BUY_TOKEN,o)}}}var S=(o=>(o.INTERNAL="INTERNAL",o.IFRAME="IFRAME",o))(S||{}),D=(o=>(o.EOA="EOA",o.SMART_CONTRACT="SMART_CONTRACT",o))(D||{});const I=64,P={id:"c768665aa144bcf18c14eea0249b6322050e5daeba046d7e94df743a2e504586",type:"INTERNAL",name:"Build your own hook",descriptionShort:"Call any smart contract with your own parameters",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.",image:"https://raw.githubusercontent.com/cowprotocol/cowswap/refs/heads/develop/apps/cowswap-frontend/src/modules/hooksStore/dapps/BuildHookApp/build.png",version:"v0.1.0",website:"https://docs.cow.fi/cow-protocol/tutorials/hook-dapp"},L={id:"ee4a6b1065cda592972b9ff7448ec111f29a566f137fef101ead7fbf8b01dd0b",type:"INTERNAL",name:"Claim GNO from validators",descriptionShort:"Withdraw rewards from your Gnosis validators.",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.",image:"https://raw.githubusercontent.com/cowprotocol/cowswap/897ce91ca60a6b2d3823e6a002c3bf64c5384afe/libs/assets/src/cow-swap/network-gnosis-chain-logo.svg",version:"v0.1.1",website:"https://www.gnosis.io",conditions:{supportedNetworks:[100],position:"pre"}},M={id:"1db4bacb661a90fb6b475fd5b585acba9745bc373573c65ecc3e8f5bfd5dee1f",type:"INTERNAL",name:"Permit a token",descriptionShort:"Infinite permit an address to spend one token on your behalf.",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.",image:"https://raw.githubusercontent.com/cowprotocol/cowswap/refs/heads/develop/apps/cowswap-frontend/src/modules/hooksStore/dapps/PermitHookApp/icon.png",version:"v0.1.0",website:"https://docs.cow.fi/cow-protocol/tutorials/hook-dapp",conditions:{walletCompatibility:["EOA"],supportedNetworks:[11155111]}},W={id:"40ed08569519f3b58c410ba35a8e684612663a7c9b58025e0a9c3a54551fb0ff",type:"INTERNAL",name:"Claim COW Airdrop",descriptionShort:"Retrieve COW tokens before or after a swap.",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.",image:"https://raw.githubusercontent.com/cowprotocol/cowswap/897ce91ca60a6b2d3823e6a002c3bf64c5384afe/apps/cowswap-frontend/src/modules/hooksStore/dapps/AirdropHookApp/airdrop.svg",version:"v0.1.0",website:"https://github.com/bleu/cow-airdrop-contract-deployer",conditions:{supportedNetworks:[11155111]}},H=Object.freeze(Object.defineProperty({__proto__:null,BUILD_CUSTOM_HOOK:P,CLAIM_COW_AIRDROP:W,CLAIM_GNO_FROM_VALIDATORS:L,PERMIT_TOKEN:M,default:{BUILD_CUSTOM_HOOK:P,CLAIM_GNO_FROM_VALIDATORS:L,PERMIT_TOKEN:M,CLAIM_COW_AIRDROP:W}},Symbol.toStringTag,{value:"Module"}));function K(o,p){const e=p.reduce((t,c)=>(t[c.id]=c,t),{});return o.map(t=>({hook:t,dapp:e[t.callData.slice(-I)]||null}))}function X(o){return K(o,Object.values(H))}return u.CoWHookDappEvents=E,u.HOOK_DAPP_ID_LENGTH=I,u.HookDappType=S,u.HookDappWalletCompatibility=D,u.hookDappIframeTransport=b,u.hookDappsRegistry=H,u.initCoWHookDapp=q,u.matchHooksToDapps=K,u.matchHooksToDappsRegistry=X,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"}),u}({});
1
+ var cowSwapWidget=function(f){"use strict";var $=Object.defineProperty;var Q=(f,_,O)=>_ in f?$(f,_,{enumerable:!0,configurable:!0,writable:!0,value:O}):f[_]=O;var T=(f,_,O)=>(Q(f,typeof _!="symbol"?_+"":_,O),O);class _{constructor(h){this.key=h}postMessageToWindow(h,e,t){const a=typeof t=="object"?t:{},p={key:this.key,method:e,...a};h.postMessage(p,"*")}listenToMessageFromWindow(h,e,t){const a=p=>{!O(p.data)||p.data.key!==this.key||p.data.method!==e||t(p.data)};return h.addEventListener("message",a),a}stopListeningToMessageFromWindow(h,e,t){h.removeEventListener("message",t)}stopListeningWindowListener(h,e){h.removeEventListener("message",e)}}function O(o){return typeof o=="object"&&o!==null&&"key"in o&&"method"in o&&typeof o.key=="string"&&typeof o.method=="string"}var R=(o=>(o.PROVIDER_RPC_REQUEST="PROVIDER_RPC_REQUEST",o.PROVIDER_RPC_RESPONSE="PROVIDER_RPC_RESPONSE",o.PROVIDER_ON_EVENT="PROVIDER_ON_EVENT",o))(R||{});const A=new _("cowSwapIframeRpcProviderTransport");var N={exports:{}};(function(o){var h=Object.prototype.hasOwnProperty,e="~";function t(){}Object.create&&(t.prototype=Object.create(null),new t().__proto__||(e=!1));function a(c,r,s){this.fn=c,this.context=r,this.once=s||!1}function p(c,r,s,i,w){if(typeof s!="function")throw new TypeError("The listener must be a function");var m=new a(s,i||c,w),l=e?e+r:r;return c._events[l]?c._events[l].fn?c._events[l]=[c._events[l],m]:c._events[l].push(m):(c._events[l]=m,c._eventsCount++),c}function g(c,r){--c._eventsCount===0?c._events=new t:delete c._events[r]}function u(){this._events=new t,this._eventsCount=0}u.prototype.eventNames=function(){var r=[],s,i;if(this._eventsCount===0)return r;for(i in s=this._events)h.call(s,i)&&r.push(e?i.slice(1):i);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(s)):r},u.prototype.listeners=function(r){var s=e?e+r:r,i=this._events[s];if(!i)return[];if(i.fn)return[i.fn];for(var w=0,m=i.length,l=new Array(m);w<m;w++)l[w]=i[w].fn;return l},u.prototype.listenerCount=function(r){var s=e?e+r:r,i=this._events[s];return i?i.fn?1:i.length:0},u.prototype.emit=function(r,s,i,w,m,l){var v=e?e+r:r;if(!this._events[v])return!1;var n=this._events[v],y=arguments.length,C,d;if(n.fn){switch(n.once&&this.removeListener(r,n.fn,void 0,!0),y){case 1:return n.fn.call(n.context),!0;case 2:return n.fn.call(n.context,s),!0;case 3:return n.fn.call(n.context,s,i),!0;case 4:return n.fn.call(n.context,s,i,w),!0;case 5:return n.fn.call(n.context,s,i,w,m),!0;case 6:return n.fn.call(n.context,s,i,w,m,l),!0}for(d=1,C=new Array(y-1);d<y;d++)C[d-1]=arguments[d];n.fn.apply(n.context,C)}else{var Y=n.length,k;for(d=0;d<Y;d++)switch(n[d].once&&this.removeListener(r,n[d].fn,void 0,!0),y){case 1:n[d].fn.call(n[d].context);break;case 2:n[d].fn.call(n[d].context,s);break;case 3:n[d].fn.call(n[d].context,s,i);break;case 4:n[d].fn.call(n[d].context,s,i,w);break;default:if(!C)for(k=1,C=new Array(y-1);k<y;k++)C[k-1]=arguments[k];n[d].fn.apply(n[d].context,C)}}return!0},u.prototype.on=function(r,s,i){return p(this,r,s,i,!1)},u.prototype.once=function(r,s,i){return p(this,r,s,i,!0)},u.prototype.removeListener=function(r,s,i,w){var m=e?e+r:r;if(!this._events[m])return this;if(!s)return g(this,m),this;var l=this._events[m];if(l.fn)l.fn===s&&(!w||l.once)&&(!i||l.context===i)&&g(this,m);else{for(var v=0,n=[],y=l.length;v<y;v++)(l[v].fn!==s||w&&!l[v].once||i&&l[v].context!==i)&&n.push(l[v]);n.length?this._events[m]=n.length===1?n[0]:n:g(this,m)}return this},u.prototype.removeAllListeners=function(r){var s;return r?(s=e?e+r:r,this._events[s]&&g(this,s)):(this._events=new t,this._eventsCount=0),this},u.prototype.off=u.prototype.removeListener,u.prototype.addListener=u.prototype.on,u.prefixed=e,u.EventEmitter=u,o.exports=u})(N);var K=N.exports;const V=6e5,U="2.0";function x(){return Math.floor(Math.random()*Number.MAX_SAFE_INTEGER)}class F extends Error{constructor(e,t){super(`${e}: ${t}`);T(this,"isRpcError",!0);T(this,"code");T(this,"reason");this.code=e,this.reason=t}}class G extends K.EventEmitter{constructor({timeoutMilliseconds:e=V,eventSource:t=window,eventTarget:a=window.parent}={}){super();T(this,"enabled",null);T(this,"timeoutMilliseconds");T(this,"eventSource");T(this,"eventTarget");T(this,"completers",{});T(this,"handleRpcRequests",({rpcResponse:e})=>{if(e.id===void 0||e.id===null)return;const t=this.completers[""+e.id];t&&("error"in e||"result"in e?t.resolve(e):t.reject(new Error("Response from provider did not have error or result key")),delete this.completers[e.id])});this.timeoutMilliseconds=e,this.eventSource=t,this.eventTarget=a,A.listenToMessageFromWindow(this.eventSource,R.PROVIDER_RPC_RESPONSE,p=>{this.handleRpcRequests(p)}),A.listenToMessageFromWindow(this.eventSource,R.PROVIDER_ON_EVENT,p=>{this.handleOnEvent(p)})}request({method:e,params:t}){return this.send(e,t)}isConnected(){return!0}get isIFrame(){return!0}get currentProvider(){return this}async execute(e,t){const a=x(),p={jsonrpc:U,id:a,method:e,params:t},g=new Promise((u,c)=>this.completers[a]={resolve:u,reject:c});return A.postMessageToWindow(this.eventTarget,R.PROVIDER_RPC_REQUEST,{rpcRequest:p}),setTimeout(()=>{this.completers[a]&&(this.completers[a].reject(new Error("Request timed out. Please try again and submit it faster.")),delete this.completers[a])},this.timeoutMilliseconds),g}async send(e,t){const{method:a,params:p}=typeof e=="string"?{method:e,params:t}:{method:e.method,params:e.params},g=await this.execute(a,p);if("error"in g)throw new F(g.error.code,g.error.message);return g.result}async enable(){if(this.enabled===null){const e=this.enabled=this.send("enable",[]).catch(t=>{throw this.enabled===e&&(this.enabled=null),t})}return this.enabled}async sendAsync(e,t){try{const a=await this.execute(e.method,e.params);t(null,a)}catch(a){t(a,null)}}handleOnEvent(e){const t=e.params;switch(e.event){case"notification":this.emitNotification(t);break;case"connect":this.emitConnect(t);break;case"disconnect":this.emitDisconnect(t);break;case"chainChanged":this.emitChainChanged(t);break;case"accountsChanged":this.emitAccountsChanged(t);break;case"message":this.emitMessage(t);break;case"networkChanged":this.emitNetworkChanged(t);break;case"close":this.emitClose(t);break;default:console.warn(`[WidgetEthereumProvider] Unknown event type: ${e.event}`);break}}emitNotification(e){this.emit("notification",e)}emitConnect(e){this.enabled===null&&(this.enabled=Promise.resolve([])),this.emit("connect",e)}emitClose(e){Array.isArray(e)&&e.length===2?this.emit("close",e[0],e[1]):this.emit("close")}emitDisconnect(e){this.emit("disconnect",e)}emitChainChanged(e){this.emit("chainChanged",e)}emitNetworkChanged(e){this.emit("networkChanged",e)}emitAccountsChanged(e){this.enabled=Promise.resolve(e),this.emit("accountsChanged",e)}emitMessage(e){this.emit("message",e)}}var E=(o=>(o.ACTIVATE="ACTIVATE",o.CONTEXT_UPDATE="CONTEXT_UPDATE",o.ADD_HOOK="ADD_HOOK",o.EDIT_HOOK="EDIT_HOOK",o.SET_SELL_TOKEN="SET_SELL_TOKEN",o.SET_BUY_TOKEN="SET_BUY_TOKEN",o))(E||{});const b=new _("cowSwapHookDapp");function B({onContext:o}){const h=window.parent,e=new G,t=q();return b.listenToMessageFromWindow(window,E.CONTEXT_UPDATE,o),b.postMessageToWindow(h,E.ACTIVATE,void 0),{actions:t,provider:e}}function q(){return{addHook(o){b.postMessageToWindow(parent,E.ADD_HOOK,o)},editHook(o){b.postMessageToWindow(parent,E.EDIT_HOOK,o)},setSellToken(o){b.postMessageToWindow(parent,E.SET_SELL_TOKEN,o)},setBuyToken(o){b.postMessageToWindow(parent,E.SET_BUY_TOKEN,o)}}}var S=(o=>(o.INTERNAL="INTERNAL",o.IFRAME="IFRAME",o))(S||{}),I=(o=>(o.EOA="EOA",o.SMART_CONTRACT="SMART_CONTRACT",o))(I||{});const j=64,D={id:"c768665aa144bcf18c14eea0249b6322050e5daeba046d7e94df743a2e504586",type:"INTERNAL",name:"Build your own hook",descriptionShort:"Call any smart contract with your own parameters",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.",image:"https://raw.githubusercontent.com/cowprotocol/cowswap/refs/heads/develop/apps/cowswap-frontend/src/modules/hooksStore/dapps/BuildHookApp/build.png",version:"v0.1.0",website:"https://docs.cow.fi/cow-protocol/tutorials/hook-dapp"},P={id:"ee4a6b1065cda592972b9ff7448ec111f29a566f137fef101ead7fbf8b01dd0b",type:"INTERNAL",name:"Claim GNO from validators",descriptionShort:"Withdraw rewards from your Gnosis validators.",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.",image:"https://raw.githubusercontent.com/cowprotocol/cowswap/897ce91ca60a6b2d3823e6a002c3bf64c5384afe/libs/assets/src/cow-swap/network-gnosis-chain-logo.svg",version:"v0.1.1",website:"https://www.gnosis.io",conditions:{supportedNetworks:[100],position:"pre"}},L={id:"1db4bacb661a90fb6b475fd5b585acba9745bc373573c65ecc3e8f5bfd5dee1f",type:"INTERNAL",name:"Permit a token",descriptionShort:"Infinite permit an address to spend one token on your behalf.",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.",image:"https://raw.githubusercontent.com/cowprotocol/cowswap/refs/heads/develop/apps/cowswap-frontend/src/modules/hooksStore/dapps/PermitHookApp/icon.png",version:"v0.1.0",website:"https://docs.cow.fi/cow-protocol/tutorials/hook-dapp",conditions:{walletCompatibility:["EOA"],supportedNetworks:[11155111]}},M={id:"40ed08569519f3b58c410ba35a8e684612663a7c9b58025e0a9c3a54551fb0ff",type:"INTERNAL",name:"Claim COW Airdrop",descriptionShort:"Retrieve COW tokens before or after a swap.",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.",image:"https://raw.githubusercontent.com/cowprotocol/cowswap/897ce91ca60a6b2d3823e6a002c3bf64c5384afe/apps/cowswap-frontend/src/modules/hooksStore/dapps/AirdropHookApp/airdrop.svg",version:"v0.1.0",website:"https://github.com/bleu/cow-airdrop-contract-deployer",conditions:{supportedNetworks:[11155111]}},W=Object.freeze(Object.defineProperty({__proto__:null,BUILD_CUSTOM_HOOK:D,CLAIM_COW_AIRDROP:M,CLAIM_GNO_FROM_VALIDATORS:P,PERMIT_TOKEN:L,default:{BUILD_CUSTOM_HOOK:D,CLAIM_GNO_FROM_VALIDATORS:P,PERMIT_TOKEN:L,CLAIM_COW_AIRDROP:M}},Symbol.toStringTag,{value:"Module"}));function H(o,h){const e=h.reduce((t,a)=>(t[a.id]=a,t),{});return o.filter(t=>!!t.dappId).map(t=>{const a=t,p=e[a.dappId];return{hook:a,dapp:p||null}})}function X(o,h=[]){return H(o,Object.values(W).concat(h))}return f.CoWHookDappEvents=E,f.HOOK_DAPP_ID_LENGTH=j,f.HookDappType=S,f.HookDappWalletCompatibility=I,f.hookDappIframeTransport=b,f.hookDappsRegistry=W,f.initCoWHookDapp=B,f.matchHooksToDapps=H,f.matchHooksToDappsRegistry=X,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"}),f}({});
package/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var H=Object.defineProperty;var K=(t,a,e)=>a in t?H(t,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[a]=e;var g=(t,a,e)=>(K(t,typeof a!="symbol"?a+"":a,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class k{constructor(a){this.key=a}postMessageToWindow(a,e,o){const l=typeof o=="object"?o:{},u={key:this.key,method:e,...l};a.postMessage(u,"*")}listenToMessageFromWindow(a,e,o){const l=u=>{!V(u.data)||u.data.key!==this.key||u.data.method!==e||o(u.data)};return a.addEventListener("message",l),l}stopListeningToMessageFromWindow(a,e,o){a.removeEventListener("message",o)}stopListeningWindowListener(a,e){a.removeEventListener("message",e)}}function V(t){return typeof t=="object"&&t!==null&&"key"in t&&"method"in t&&typeof t.key=="string"&&typeof t.method=="string"}var b=(t=>(t.PROVIDER_RPC_REQUEST="PROVIDER_RPC_REQUEST",t.PROVIDER_RPC_RESPONSE="PROVIDER_RPC_RESPONSE",t.PROVIDER_ON_EVENT="PROVIDER_ON_EVENT",t))(b||{});const C=new k("cowSwapIframeRpcProviderTransport");var R={exports:{}};(function(t){var a=Object.prototype.hasOwnProperty,e="~";function o(){}Object.create&&(o.prototype=Object.create(null),new o().__proto__||(e=!1));function l(c,n,s){this.fn=c,this.context=n,this.once=s||!1}function u(c,n,s,i,m){if(typeof s!="function")throw new TypeError("The listener must be a function");var f=new l(s,i||c,m),p=e?e+n:n;return c._events[p]?c._events[p].fn?c._events[p]=[c._events[p],f]:c._events[p].push(f):(c._events[p]=f,c._eventsCount++),c}function w(c,n){--c._eventsCount===0?c._events=new o:delete c._events[n]}function h(){this._events=new o,this._eventsCount=0}h.prototype.eventNames=function(){var n=[],s,i;if(this._eventsCount===0)return n;for(i in s=this._events)a.call(s,i)&&n.push(e?i.slice(1):i);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(s)):n},h.prototype.listeners=function(n){var s=e?e+n:n,i=this._events[s];if(!i)return[];if(i.fn)return[i.fn];for(var m=0,f=i.length,p=new Array(f);m<f;m++)p[m]=i[m].fn;return p},h.prototype.listenerCount=function(n){var s=e?e+n:n,i=this._events[s];return i?i.fn?1:i.length:0},h.prototype.emit=function(n,s,i,m,f,p){var _=e?e+n:n;if(!this._events[_])return!1;var r=this._events[_],T=arguments.length,E,d;if(r.fn){switch(r.once&&this.removeListener(n,r.fn,void 0,!0),T){case 1:return r.fn.call(r.context),!0;case 2:return r.fn.call(r.context,s),!0;case 3:return r.fn.call(r.context,s,i),!0;case 4:return r.fn.call(r.context,s,i,m),!0;case 5:return r.fn.call(r.context,s,i,m,f),!0;case 6:return r.fn.call(r.context,s,i,m,f,p),!0}for(d=1,E=new Array(T-1);d<T;d++)E[d-1]=arguments[d];r.fn.apply(r.context,E)}else{var x=r.length,O;for(d=0;d<x;d++)switch(r[d].once&&this.removeListener(n,r[d].fn,void 0,!0),T){case 1:r[d].fn.call(r[d].context);break;case 2:r[d].fn.call(r[d].context,s);break;case 3:r[d].fn.call(r[d].context,s,i);break;case 4:r[d].fn.call(r[d].context,s,i,m);break;default:if(!E)for(O=1,E=new Array(T-1);O<T;O++)E[O-1]=arguments[O];r[d].fn.apply(r[d].context,E)}}return!0},h.prototype.on=function(n,s,i){return u(this,n,s,i,!1)},h.prototype.once=function(n,s,i){return u(this,n,s,i,!0)},h.prototype.removeListener=function(n,s,i,m){var f=e?e+n:n;if(!this._events[f])return this;if(!s)return w(this,f),this;var p=this._events[f];if(p.fn)p.fn===s&&(!m||p.once)&&(!i||p.context===i)&&w(this,f);else{for(var _=0,r=[],T=p.length;_<T;_++)(p[_].fn!==s||m&&!p[_].once||i&&p[_].context!==i)&&r.push(p[_]);r.length?this._events[f]=r.length===1?r[0]:r:w(this,f)}return this},h.prototype.removeAllListeners=function(n){var s;return n?(s=e?e+n:n,this._events[s]&&w(this,s)):(this._events=new o,this._eventsCount=0),this},h.prototype.off=h.prototype.removeListener,h.prototype.addListener=h.prototype.on,h.prefixed=e,h.EventEmitter=h,t.exports=h})(R);var U=R.exports;const F=6e5,G="2.0";function B(){return Math.floor(Math.random()*Number.MAX_SAFE_INTEGER)}class q extends Error{constructor(e,o){super(`${e}: ${o}`);g(this,"isRpcError",!0);g(this,"code");g(this,"reason");this.code=e,this.reason=o}}class j extends U.EventEmitter{constructor({timeoutMilliseconds:e=F,eventSource:o=window,eventTarget:l=window.parent}={}){super();g(this,"enabled",null);g(this,"timeoutMilliseconds");g(this,"eventSource");g(this,"eventTarget");g(this,"completers",{});g(this,"handleRpcRequests",({rpcResponse:e})=>{if(e.id===void 0||e.id===null)return;const o=this.completers[""+e.id];o&&("error"in e||"result"in e?o.resolve(e):o.reject(new Error("Response from provider did not have error or result key")),delete this.completers[e.id])});this.timeoutMilliseconds=e,this.eventSource=o,this.eventTarget=l,C.listenToMessageFromWindow(this.eventSource,b.PROVIDER_RPC_RESPONSE,u=>{this.handleRpcRequests(u)}),C.listenToMessageFromWindow(this.eventSource,b.PROVIDER_ON_EVENT,u=>{this.handleOnEvent(u)})}request({method:e,params:o}){return this.send(e,o)}isConnected(){return!0}get isIFrame(){return!0}get currentProvider(){return this}async execute(e,o){const l=B(),u={jsonrpc:G,id:l,method:e,params:o},w=new Promise((h,c)=>this.completers[l]={resolve:h,reject:c});return C.postMessageToWindow(this.eventTarget,b.PROVIDER_RPC_REQUEST,{rpcRequest:u}),setTimeout(()=>{this.completers[l]&&(this.completers[l].reject(new Error("Request timed out. Please try again and submit it faster.")),delete this.completers[l])},this.timeoutMilliseconds),w}async send(e,o){const{method:l,params:u}=typeof e=="string"?{method:e,params:o}:{method:e.method,params:e.params},w=await this.execute(l,u);if("error"in w)throw new q(w.error.code,w.error.message);return w.result}async enable(){if(this.enabled===null){const e=this.enabled=this.send("enable",[]).catch(o=>{throw this.enabled===e&&(this.enabled=null),o})}return this.enabled}async sendAsync(e,o){try{const l=await this.execute(e.method,e.params);o(null,l)}catch(l){o(l,null)}}handleOnEvent(e){const o=e.params;switch(e.event){case"notification":this.emitNotification(o);break;case"connect":this.emitConnect(o);break;case"disconnect":this.emitDisconnect(o);break;case"chainChanged":this.emitChainChanged(o);break;case"accountsChanged":this.emitAccountsChanged(o);break;case"message":this.emitMessage(o);break;case"networkChanged":this.emitNetworkChanged(o);break;case"close":this.emitClose(o);break;default:console.warn(`[WidgetEthereumProvider] Unknown event type: ${e.event}`);break}}emitNotification(e){this.emit("notification",e)}emitConnect(e){this.enabled===null&&(this.enabled=Promise.resolve([])),this.emit("connect",e)}emitClose(e){Array.isArray(e)&&e.length===2?this.emit("close",e[0],e[1]):this.emit("close")}emitDisconnect(e){this.emit("disconnect",e)}emitChainChanged(e){this.emit("chainChanged",e)}emitNetworkChanged(e){this.emit("networkChanged",e)}emitAccountsChanged(e){this.enabled=Promise.resolve(e),this.emit("accountsChanged",e)}emitMessage(e){this.emit("message",e)}}var v=(t=>(t.ACTIVATE="ACTIVATE",t.CONTEXT_UPDATE="CONTEXT_UPDATE",t.ADD_HOOK="ADD_HOOK",t.EDIT_HOOK="EDIT_HOOK",t.SET_SELL_TOKEN="SET_SELL_TOKEN",t.SET_BUY_TOKEN="SET_BUY_TOKEN",t))(v||{});const y=new k("cowSwapHookDapp");function X({onContext:t}){const a=window.parent,e=new j,o=Y();return y.listenToMessageFromWindow(window,v.CONTEXT_UPDATE,t),y.postMessageToWindow(a,v.ACTIVATE,void 0),{actions:o,provider:e}}function Y(){return{addHook(t){y.postMessageToWindow(parent,v.ADD_HOOK,t)},editHook(t){y.postMessageToWindow(parent,v.EDIT_HOOK,t)},setSellToken(t){y.postMessageToWindow(parent,v.SET_SELL_TOKEN,t)},setBuyToken(t){y.postMessageToWindow(parent,v.SET_BUY_TOKEN,t)}}}var A=(t=>(t.INTERNAL="INTERNAL",t.IFRAME="IFRAME",t))(A||{}),N=(t=>(t.EOA="EOA",t.SMART_CONTRACT="SMART_CONTRACT",t))(N||{});const S=64,D={id:"c768665aa144bcf18c14eea0249b6322050e5daeba046d7e94df743a2e504586",type:"INTERNAL",name:"Build your own hook",descriptionShort:"Call any smart contract with your own parameters",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.",image:"https://raw.githubusercontent.com/cowprotocol/cowswap/refs/heads/develop/apps/cowswap-frontend/src/modules/hooksStore/dapps/BuildHookApp/build.png",version:"v0.1.0",website:"https://docs.cow.fi/cow-protocol/tutorials/hook-dapp"},I={id:"ee4a6b1065cda592972b9ff7448ec111f29a566f137fef101ead7fbf8b01dd0b",type:"INTERNAL",name:"Claim GNO from validators",descriptionShort:"Withdraw rewards from your Gnosis validators.",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.",image:"https://raw.githubusercontent.com/cowprotocol/cowswap/897ce91ca60a6b2d3823e6a002c3bf64c5384afe/libs/assets/src/cow-swap/network-gnosis-chain-logo.svg",version:"v0.1.1",website:"https://www.gnosis.io",conditions:{supportedNetworks:[100],position:"pre"}},P={id:"1db4bacb661a90fb6b475fd5b585acba9745bc373573c65ecc3e8f5bfd5dee1f",type:"INTERNAL",name:"Permit a token",descriptionShort:"Infinite permit an address to spend one token on your behalf.",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.",image:"https://raw.githubusercontent.com/cowprotocol/cowswap/refs/heads/develop/apps/cowswap-frontend/src/modules/hooksStore/dapps/PermitHookApp/icon.png",version:"v0.1.0",website:"https://docs.cow.fi/cow-protocol/tutorials/hook-dapp",conditions:{walletCompatibility:["EOA"],supportedNetworks:[11155111]}},L={id:"40ed08569519f3b58c410ba35a8e684612663a7c9b58025e0a9c3a54551fb0ff",type:"INTERNAL",name:"Claim COW Airdrop",descriptionShort:"Retrieve COW tokens before or after a swap.",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.",image:"https://raw.githubusercontent.com/cowprotocol/cowswap/897ce91ca60a6b2d3823e6a002c3bf64c5384afe/apps/cowswap-frontend/src/modules/hooksStore/dapps/AirdropHookApp/airdrop.svg",version:"v0.1.0",website:"https://github.com/bleu/cow-airdrop-contract-deployer",conditions:{supportedNetworks:[11155111]}},$={BUILD_CUSTOM_HOOK:D,CLAIM_GNO_FROM_VALIDATORS:I,PERMIT_TOKEN:P,CLAIM_COW_AIRDROP:L},M=Object.freeze(Object.defineProperty({__proto__:null,BUILD_CUSTOM_HOOK:D,CLAIM_COW_AIRDROP:L,CLAIM_GNO_FROM_VALIDATORS:I,PERMIT_TOKEN:P,default:$},Symbol.toStringTag,{value:"Module"}));function W(t,a){const e=a.reduce((o,l)=>(o[l.id]=l,o),{});return t.map(o=>({hook:o,dapp:e[o.callData.slice(-S)]||null}))}function Q(t){return W(t,Object.values(M))}exports.CoWHookDappEvents=v;exports.HOOK_DAPP_ID_LENGTH=S;exports.HookDappType=A;exports.HookDappWalletCompatibility=N;exports.hookDappIframeTransport=y;exports.hookDappsRegistry=M;exports.initCoWHookDapp=X;exports.matchHooksToDapps=W;exports.matchHooksToDappsRegistry=Q;
1
+ "use strict";var x=Object.defineProperty;var H=(t,a,e)=>a in t?x(t,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[a]=e;var g=(t,a,e)=>(H(t,typeof a!="symbol"?a+"":a,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class k{constructor(a){this.key=a}postMessageToWindow(a,e,o){const c=typeof o=="object"?o:{},h={key:this.key,method:e,...c};a.postMessage(h,"*")}listenToMessageFromWindow(a,e,o){const c=h=>{!K(h.data)||h.data.key!==this.key||h.data.method!==e||o(h.data)};return a.addEventListener("message",c),c}stopListeningToMessageFromWindow(a,e,o){a.removeEventListener("message",o)}stopListeningWindowListener(a,e){a.removeEventListener("message",e)}}function K(t){return typeof t=="object"&&t!==null&&"key"in t&&"method"in t&&typeof t.key=="string"&&typeof t.method=="string"}var b=(t=>(t.PROVIDER_RPC_REQUEST="PROVIDER_RPC_REQUEST",t.PROVIDER_RPC_RESPONSE="PROVIDER_RPC_RESPONSE",t.PROVIDER_ON_EVENT="PROVIDER_ON_EVENT",t))(b||{});const C=new k("cowSwapIframeRpcProviderTransport");var R={exports:{}};(function(t){var a=Object.prototype.hasOwnProperty,e="~";function o(){}Object.create&&(o.prototype=Object.create(null),new o().__proto__||(e=!1));function c(l,r,s){this.fn=l,this.context=r,this.once=s||!1}function h(l,r,s,i,m){if(typeof s!="function")throw new TypeError("The listener must be a function");var f=new c(s,i||l,m),p=e?e+r:r;return l._events[p]?l._events[p].fn?l._events[p]=[l._events[p],f]:l._events[p].push(f):(l._events[p]=f,l._eventsCount++),l}function w(l,r){--l._eventsCount===0?l._events=new o:delete l._events[r]}function u(){this._events=new o,this._eventsCount=0}u.prototype.eventNames=function(){var r=[],s,i;if(this._eventsCount===0)return r;for(i in s=this._events)a.call(s,i)&&r.push(e?i.slice(1):i);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(s)):r},u.prototype.listeners=function(r){var s=e?e+r:r,i=this._events[s];if(!i)return[];if(i.fn)return[i.fn];for(var m=0,f=i.length,p=new Array(f);m<f;m++)p[m]=i[m].fn;return p},u.prototype.listenerCount=function(r){var s=e?e+r:r,i=this._events[s];return i?i.fn?1:i.length:0},u.prototype.emit=function(r,s,i,m,f,p){var _=e?e+r:r;if(!this._events[_])return!1;var n=this._events[_],T=arguments.length,E,d;if(n.fn){switch(n.once&&this.removeListener(r,n.fn,void 0,!0),T){case 1:return n.fn.call(n.context),!0;case 2:return n.fn.call(n.context,s),!0;case 3:return n.fn.call(n.context,s,i),!0;case 4:return n.fn.call(n.context,s,i,m),!0;case 5:return n.fn.call(n.context,s,i,m,f),!0;case 6:return n.fn.call(n.context,s,i,m,f,p),!0}for(d=1,E=new Array(T-1);d<T;d++)E[d-1]=arguments[d];n.fn.apply(n.context,E)}else{var W=n.length,O;for(d=0;d<W;d++)switch(n[d].once&&this.removeListener(r,n[d].fn,void 0,!0),T){case 1:n[d].fn.call(n[d].context);break;case 2:n[d].fn.call(n[d].context,s);break;case 3:n[d].fn.call(n[d].context,s,i);break;case 4:n[d].fn.call(n[d].context,s,i,m);break;default:if(!E)for(O=1,E=new Array(T-1);O<T;O++)E[O-1]=arguments[O];n[d].fn.apply(n[d].context,E)}}return!0},u.prototype.on=function(r,s,i){return h(this,r,s,i,!1)},u.prototype.once=function(r,s,i){return h(this,r,s,i,!0)},u.prototype.removeListener=function(r,s,i,m){var f=e?e+r:r;if(!this._events[f])return this;if(!s)return w(this,f),this;var p=this._events[f];if(p.fn)p.fn===s&&(!m||p.once)&&(!i||p.context===i)&&w(this,f);else{for(var _=0,n=[],T=p.length;_<T;_++)(p[_].fn!==s||m&&!p[_].once||i&&p[_].context!==i)&&n.push(p[_]);n.length?this._events[f]=n.length===1?n[0]:n:w(this,f)}return this},u.prototype.removeAllListeners=function(r){var s;return r?(s=e?e+r:r,this._events[s]&&w(this,s)):(this._events=new o,this._eventsCount=0),this},u.prototype.off=u.prototype.removeListener,u.prototype.addListener=u.prototype.on,u.prefixed=e,u.EventEmitter=u,t.exports=u})(R);var V=R.exports;const U=6e5,F="2.0";function G(){return Math.floor(Math.random()*Number.MAX_SAFE_INTEGER)}class B extends Error{constructor(e,o){super(`${e}: ${o}`);g(this,"isRpcError",!0);g(this,"code");g(this,"reason");this.code=e,this.reason=o}}class q extends V.EventEmitter{constructor({timeoutMilliseconds:e=U,eventSource:o=window,eventTarget:c=window.parent}={}){super();g(this,"enabled",null);g(this,"timeoutMilliseconds");g(this,"eventSource");g(this,"eventTarget");g(this,"completers",{});g(this,"handleRpcRequests",({rpcResponse:e})=>{if(e.id===void 0||e.id===null)return;const o=this.completers[""+e.id];o&&("error"in e||"result"in e?o.resolve(e):o.reject(new Error("Response from provider did not have error or result key")),delete this.completers[e.id])});this.timeoutMilliseconds=e,this.eventSource=o,this.eventTarget=c,C.listenToMessageFromWindow(this.eventSource,b.PROVIDER_RPC_RESPONSE,h=>{this.handleRpcRequests(h)}),C.listenToMessageFromWindow(this.eventSource,b.PROVIDER_ON_EVENT,h=>{this.handleOnEvent(h)})}request({method:e,params:o}){return this.send(e,o)}isConnected(){return!0}get isIFrame(){return!0}get currentProvider(){return this}async execute(e,o){const c=G(),h={jsonrpc:F,id:c,method:e,params:o},w=new Promise((u,l)=>this.completers[c]={resolve:u,reject:l});return C.postMessageToWindow(this.eventTarget,b.PROVIDER_RPC_REQUEST,{rpcRequest:h}),setTimeout(()=>{this.completers[c]&&(this.completers[c].reject(new Error("Request timed out. Please try again and submit it faster.")),delete this.completers[c])},this.timeoutMilliseconds),w}async send(e,o){const{method:c,params:h}=typeof e=="string"?{method:e,params:o}:{method:e.method,params:e.params},w=await this.execute(c,h);if("error"in w)throw new B(w.error.code,w.error.message);return w.result}async enable(){if(this.enabled===null){const e=this.enabled=this.send("enable",[]).catch(o=>{throw this.enabled===e&&(this.enabled=null),o})}return this.enabled}async sendAsync(e,o){try{const c=await this.execute(e.method,e.params);o(null,c)}catch(c){o(c,null)}}handleOnEvent(e){const o=e.params;switch(e.event){case"notification":this.emitNotification(o);break;case"connect":this.emitConnect(o);break;case"disconnect":this.emitDisconnect(o);break;case"chainChanged":this.emitChainChanged(o);break;case"accountsChanged":this.emitAccountsChanged(o);break;case"message":this.emitMessage(o);break;case"networkChanged":this.emitNetworkChanged(o);break;case"close":this.emitClose(o);break;default:console.warn(`[WidgetEthereumProvider] Unknown event type: ${e.event}`);break}}emitNotification(e){this.emit("notification",e)}emitConnect(e){this.enabled===null&&(this.enabled=Promise.resolve([])),this.emit("connect",e)}emitClose(e){Array.isArray(e)&&e.length===2?this.emit("close",e[0],e[1]):this.emit("close")}emitDisconnect(e){this.emit("disconnect",e)}emitChainChanged(e){this.emit("chainChanged",e)}emitNetworkChanged(e){this.emit("networkChanged",e)}emitAccountsChanged(e){this.enabled=Promise.resolve(e),this.emit("accountsChanged",e)}emitMessage(e){this.emit("message",e)}}var v=(t=>(t.ACTIVATE="ACTIVATE",t.CONTEXT_UPDATE="CONTEXT_UPDATE",t.ADD_HOOK="ADD_HOOK",t.EDIT_HOOK="EDIT_HOOK",t.SET_SELL_TOKEN="SET_SELL_TOKEN",t.SET_BUY_TOKEN="SET_BUY_TOKEN",t))(v||{});const y=new k("cowSwapHookDapp");function j({onContext:t}){const a=window.parent,e=new q,o=X();return y.listenToMessageFromWindow(window,v.CONTEXT_UPDATE,t),y.postMessageToWindow(a,v.ACTIVATE,void 0),{actions:o,provider:e}}function X(){return{addHook(t){y.postMessageToWindow(parent,v.ADD_HOOK,t)},editHook(t){y.postMessageToWindow(parent,v.EDIT_HOOK,t)},setSellToken(t){y.postMessageToWindow(parent,v.SET_SELL_TOKEN,t)},setBuyToken(t){y.postMessageToWindow(parent,v.SET_BUY_TOKEN,t)}}}var A=(t=>(t.INTERNAL="INTERNAL",t.IFRAME="IFRAME",t))(A||{}),N=(t=>(t.EOA="EOA",t.SMART_CONTRACT="SMART_CONTRACT",t))(N||{});const Y=64,S={id:"c768665aa144bcf18c14eea0249b6322050e5daeba046d7e94df743a2e504586",type:"INTERNAL",name:"Build your own hook",descriptionShort:"Call any smart contract with your own parameters",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.",image:"https://raw.githubusercontent.com/cowprotocol/cowswap/refs/heads/develop/apps/cowswap-frontend/src/modules/hooksStore/dapps/BuildHookApp/build.png",version:"v0.1.0",website:"https://docs.cow.fi/cow-protocol/tutorials/hook-dapp"},I={id:"ee4a6b1065cda592972b9ff7448ec111f29a566f137fef101ead7fbf8b01dd0b",type:"INTERNAL",name:"Claim GNO from validators",descriptionShort:"Withdraw rewards from your Gnosis validators.",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.",image:"https://raw.githubusercontent.com/cowprotocol/cowswap/897ce91ca60a6b2d3823e6a002c3bf64c5384afe/libs/assets/src/cow-swap/network-gnosis-chain-logo.svg",version:"v0.1.1",website:"https://www.gnosis.io",conditions:{supportedNetworks:[100],position:"pre"}},D={id:"1db4bacb661a90fb6b475fd5b585acba9745bc373573c65ecc3e8f5bfd5dee1f",type:"INTERNAL",name:"Permit a token",descriptionShort:"Infinite permit an address to spend one token on your behalf.",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.",image:"https://raw.githubusercontent.com/cowprotocol/cowswap/refs/heads/develop/apps/cowswap-frontend/src/modules/hooksStore/dapps/PermitHookApp/icon.png",version:"v0.1.0",website:"https://docs.cow.fi/cow-protocol/tutorials/hook-dapp",conditions:{walletCompatibility:["EOA"],supportedNetworks:[11155111]}},P={id:"40ed08569519f3b58c410ba35a8e684612663a7c9b58025e0a9c3a54551fb0ff",type:"INTERNAL",name:"Claim COW Airdrop",descriptionShort:"Retrieve COW tokens before or after a swap.",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.",image:"https://raw.githubusercontent.com/cowprotocol/cowswap/897ce91ca60a6b2d3823e6a002c3bf64c5384afe/apps/cowswap-frontend/src/modules/hooksStore/dapps/AirdropHookApp/airdrop.svg",version:"v0.1.0",website:"https://github.com/bleu/cow-airdrop-contract-deployer",conditions:{supportedNetworks:[11155111]}},$={BUILD_CUSTOM_HOOK:S,CLAIM_GNO_FROM_VALIDATORS:I,PERMIT_TOKEN:D,CLAIM_COW_AIRDROP:P},L=Object.freeze(Object.defineProperty({__proto__:null,BUILD_CUSTOM_HOOK:S,CLAIM_COW_AIRDROP:P,CLAIM_GNO_FROM_VALIDATORS:I,PERMIT_TOKEN:D,default:$},Symbol.toStringTag,{value:"Module"}));function M(t,a){const e=a.reduce((o,c)=>(o[c.id]=c,o),{});return t.filter(o=>!!o.dappId).map(o=>{const c=o,h=e[c.dappId];return{hook:c,dapp:h||null}})}function Q(t,a=[]){return M(t,Object.values(L).concat(a))}exports.CoWHookDappEvents=v;exports.HOOK_DAPP_ID_LENGTH=Y;exports.HookDappType=A;exports.HookDappWalletCompatibility=N;exports.hookDappIframeTransport=y;exports.hookDappsRegistry=L;exports.initCoWHookDapp=j;exports.matchHooksToDapps=M;exports.matchHooksToDappsRegistry=Q;
package/index.mjs CHANGED
@@ -1,27 +1,27 @@
1
- var D = Object.defineProperty;
2
- var L = (t, a, e) => a in t ? D(t, a, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[a] = e;
3
- var g = (t, a, e) => (L(t, typeof a != "symbol" ? a + "" : a, e), e);
1
+ var L = Object.defineProperty;
2
+ var M = (t, a, e) => a in t ? L(t, a, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[a] = e;
3
+ var g = (t, a, e) => (M(t, typeof a != "symbol" ? a + "" : a, e), e);
4
4
  class R {
5
5
  constructor(a) {
6
6
  this.key = a;
7
7
  }
8
8
  postMessageToWindow(a, e, o) {
9
- const l = typeof o == "object" ? o : {}, p = {
9
+ const c = typeof o == "object" ? o : {}, u = {
10
10
  key: this.key,
11
11
  method: e,
12
- ...l
12
+ ...c
13
13
  };
14
14
  a.postMessage(
15
- p,
15
+ u,
16
16
  "*"
17
17
  // TODO: Change to CoW specific origin in production. https://github.com/cowprotocol/cowswap/issues/3828
18
18
  );
19
19
  }
20
20
  listenToMessageFromWindow(a, e, o) {
21
- const l = (p) => {
22
- !M(p.data) || p.data.key !== this.key || p.data.method !== e || o(p.data);
21
+ const c = (u) => {
22
+ !D(u.data) || u.data.key !== this.key || u.data.method !== e || o(u.data);
23
23
  };
24
- return a.addEventListener("message", l), l;
24
+ return a.addEventListener("message", c), c;
25
25
  }
26
26
  stopListeningToMessageFromWindow(a, e, o) {
27
27
  a.removeEventListener("message", o);
@@ -30,7 +30,7 @@ class R {
30
30
  a.removeEventListener("message", e);
31
31
  }
32
32
  }
33
- function M(t) {
33
+ function D(t) {
34
34
  return typeof t == "object" && t !== null && "key" in t && "method" in t && typeof t.key == "string" && typeof t.method == "string";
35
35
  }
36
36
  var b = /* @__PURE__ */ ((t) => (t.PROVIDER_RPC_REQUEST = "PROVIDER_RPC_REQUEST", t.PROVIDER_RPC_RESPONSE = "PROVIDER_RPC_RESPONSE", t.PROVIDER_ON_EVENT = "PROVIDER_ON_EVENT", t))(b || {});
@@ -43,29 +43,29 @@ var A = { exports: {} };
43
43
  function o() {
44
44
  }
45
45
  Object.create && (o.prototype = /* @__PURE__ */ Object.create(null), new o().__proto__ || (e = !1));
46
- function l(c, r, s) {
47
- this.fn = c, this.context = r, this.once = s || !1;
46
+ function c(l, r, s) {
47
+ this.fn = l, this.context = r, this.once = s || !1;
48
48
  }
49
- function p(c, r, s, i, m) {
49
+ function u(l, r, s, i, m) {
50
50
  if (typeof s != "function")
51
51
  throw new TypeError("The listener must be a function");
52
- var f = new l(s, i || c, m), d = e ? e + r : r;
53
- return c._events[d] ? c._events[d].fn ? c._events[d] = [c._events[d], f] : c._events[d].push(f) : (c._events[d] = f, c._eventsCount++), c;
52
+ var f = new c(s, i || l, m), d = e ? e + r : r;
53
+ return l._events[d] ? l._events[d].fn ? l._events[d] = [l._events[d], f] : l._events[d].push(f) : (l._events[d] = f, l._eventsCount++), l;
54
54
  }
55
- function w(c, r) {
56
- --c._eventsCount === 0 ? c._events = new o() : delete c._events[r];
55
+ function w(l, r) {
56
+ --l._eventsCount === 0 ? l._events = new o() : delete l._events[r];
57
57
  }
58
- function u() {
58
+ function p() {
59
59
  this._events = new o(), this._eventsCount = 0;
60
60
  }
61
- u.prototype.eventNames = function() {
61
+ p.prototype.eventNames = function() {
62
62
  var r = [], s, i;
63
63
  if (this._eventsCount === 0)
64
64
  return r;
65
65
  for (i in s = this._events)
66
66
  a.call(s, i) && r.push(e ? i.slice(1) : i);
67
67
  return Object.getOwnPropertySymbols ? r.concat(Object.getOwnPropertySymbols(s)) : r;
68
- }, u.prototype.listeners = function(r) {
68
+ }, p.prototype.listeners = function(r) {
69
69
  var s = e ? e + r : r, i = this._events[s];
70
70
  if (!i)
71
71
  return [];
@@ -74,10 +74,10 @@ var A = { exports: {} };
74
74
  for (var m = 0, f = i.length, d = new Array(f); m < f; m++)
75
75
  d[m] = i[m].fn;
76
76
  return d;
77
- }, u.prototype.listenerCount = function(r) {
77
+ }, p.prototype.listenerCount = function(r) {
78
78
  var s = e ? e + r : r, i = this._events[s];
79
79
  return i ? i.fn ? 1 : i.length : 0;
80
- }, u.prototype.emit = function(r, s, i, m, f, d) {
80
+ }, p.prototype.emit = function(r, s, i, m, f, d) {
81
81
  var _ = e ? e + r : r;
82
82
  if (!this._events[_])
83
83
  return !1;
@@ -124,11 +124,11 @@ var A = { exports: {} };
124
124
  }
125
125
  }
126
126
  return !0;
127
- }, u.prototype.on = function(r, s, i) {
128
- return p(this, r, s, i, !1);
129
- }, u.prototype.once = function(r, s, i) {
130
- return p(this, r, s, i, !0);
131
- }, u.prototype.removeListener = function(r, s, i, m) {
127
+ }, p.prototype.on = function(r, s, i) {
128
+ return u(this, r, s, i, !1);
129
+ }, p.prototype.once = function(r, s, i) {
130
+ return u(this, r, s, i, !0);
131
+ }, p.prototype.removeListener = function(r, s, i, m) {
132
132
  var f = e ? e + r : r;
133
133
  if (!this._events[f])
134
134
  return this;
@@ -143,10 +143,10 @@ var A = { exports: {} };
143
143
  n.length ? this._events[f] = n.length === 1 ? n[0] : n : w(this, f);
144
144
  }
145
145
  return this;
146
- }, u.prototype.removeAllListeners = function(r) {
146
+ }, p.prototype.removeAllListeners = function(r) {
147
147
  var s;
148
148
  return r ? (s = e ? e + r : r, this._events[s] && w(this, s)) : (this._events = new o(), this._eventsCount = 0), this;
149
- }, u.prototype.off = u.prototype.removeListener, u.prototype.addListener = u.prototype.on, u.prefixed = e, u.EventEmitter = u, t.exports = u;
149
+ }, p.prototype.off = p.prototype.removeListener, p.prototype.addListener = p.prototype.on, p.prefixed = e, p.EventEmitter = p, t.exports = p;
150
150
  })(A);
151
151
  var x = A.exports;
152
152
  const W = 6e5, V = "2.0";
@@ -166,7 +166,7 @@ class H extends x.EventEmitter {
166
166
  constructor({
167
167
  timeoutMilliseconds: e = W,
168
168
  eventSource: o = window,
169
- eventTarget: l = window.parent
169
+ eventTarget: c = window.parent
170
170
  } = {}) {
171
171
  super();
172
172
  g(this, "enabled", null);
@@ -183,17 +183,17 @@ class H extends x.EventEmitter {
183
183
  const o = this.completers["" + e.id];
184
184
  o && ("error" in e || "result" in e ? o.resolve(e) : o.reject(new Error("Response from provider did not have error or result key")), delete this.completers[e.id]);
185
185
  });
186
- this.timeoutMilliseconds = e, this.eventSource = o, this.eventTarget = l, C.listenToMessageFromWindow(
186
+ this.timeoutMilliseconds = e, this.eventSource = o, this.eventTarget = c, C.listenToMessageFromWindow(
187
187
  this.eventSource,
188
188
  b.PROVIDER_RPC_RESPONSE,
189
- (p) => {
190
- this.handleRpcRequests(p);
189
+ (u) => {
190
+ this.handleRpcRequests(u);
191
191
  }
192
192
  ), C.listenToMessageFromWindow(
193
193
  this.eventSource,
194
194
  b.PROVIDER_ON_EVENT,
195
- (p) => {
196
- this.handleOnEvent(p);
195
+ (u) => {
196
+ this.handleOnEvent(u);
197
197
  }
198
198
  );
199
199
  }
@@ -221,22 +221,22 @@ class H extends x.EventEmitter {
221
221
  * @param params params to pass the method
222
222
  */
223
223
  async execute(e, o) {
224
- const l = K(), p = {
224
+ const c = K(), u = {
225
225
  jsonrpc: V,
226
- id: l,
226
+ id: c,
227
227
  method: e,
228
228
  params: o
229
229
  }, w = new Promise(
230
- (u, c) => this.completers[l] = { resolve: u, reject: c }
230
+ (p, l) => this.completers[c] = { resolve: p, reject: l }
231
231
  );
232
232
  return C.postMessageToWindow(this.eventTarget, b.PROVIDER_RPC_REQUEST, {
233
- rpcRequest: p
233
+ rpcRequest: u
234
234
  }), setTimeout(() => {
235
- this.completers[l] && (this.completers[l].reject(new Error("Request timed out. Please try again and submit it faster.")), delete this.completers[l]);
235
+ this.completers[c] && (this.completers[c].reject(new Error("Request timed out. Please try again and submit it faster.")), delete this.completers[c]);
236
236
  }, this.timeoutMilliseconds), w;
237
237
  }
238
238
  async send(e, o) {
239
- const { method: l, params: p } = typeof e == "string" ? { method: e, params: o } : { method: e.method, params: e.params }, w = await this.execute(l, p);
239
+ const { method: c, params: u } = typeof e == "string" ? { method: e, params: o } : { method: e.method, params: e.params }, w = await this.execute(c, u);
240
240
  if ("error" in w)
241
241
  throw new U(w.error.code, w.error.message);
242
242
  return w.result;
@@ -259,10 +259,10 @@ class H extends x.EventEmitter {
259
259
  */
260
260
  async sendAsync(e, o) {
261
261
  try {
262
- const l = await this.execute(e.method, e.params);
263
- o(null, l);
264
- } catch (l) {
265
- o(l, null);
262
+ const c = await this.execute(e.method, e.params);
263
+ o(null, c);
264
+ } catch (c) {
265
+ o(c, null);
266
266
  }
267
267
  }
268
268
  handleOnEvent(e) {
@@ -330,7 +330,7 @@ class H extends x.EventEmitter {
330
330
  }
331
331
  var T = /* @__PURE__ */ ((t) => (t.ACTIVATE = "ACTIVATE", t.CONTEXT_UPDATE = "CONTEXT_UPDATE", t.ADD_HOOK = "ADD_HOOK", t.EDIT_HOOK = "EDIT_HOOK", t.SET_SELL_TOKEN = "SET_SELL_TOKEN", t.SET_BUY_TOKEN = "SET_BUY_TOKEN", t))(T || {});
332
332
  const y = new R("cowSwapHookDapp");
333
- function Q({ onContext: t }) {
333
+ function $({ onContext: t }) {
334
334
  const a = window.parent, e = new H(), o = F();
335
335
  return y.listenToMessageFromWindow(window, T.CONTEXT_UPDATE, t), y.postMessageToWindow(a, T.ACTIVATE, void 0), { actions: o, provider: e };
336
336
  }
@@ -351,7 +351,7 @@ function F() {
351
351
  };
352
352
  }
353
353
  var G = /* @__PURE__ */ ((t) => (t.INTERNAL = "INTERNAL", t.IFRAME = "IFRAME", t))(G || {}), B = /* @__PURE__ */ ((t) => (t.EOA = "EOA", t.SMART_CONTRACT = "SMART_CONTRACT", t))(B || {});
354
- const q = 64, k = {
354
+ const Q = 64, k = {
355
355
  id: "c768665aa144bcf18c14eea0249b6322050e5daeba046d7e94df743a2e504586",
356
356
  type: "INTERNAL",
357
357
  name: "Build your own hook",
@@ -406,40 +406,43 @@ const q = 64, k = {
406
406
  11155111
407
407
  ]
408
408
  }
409
- }, j = {
409
+ }, q = {
410
410
  BUILD_CUSTOM_HOOK: k,
411
411
  CLAIM_GNO_FROM_VALIDATORS: N,
412
412
  PERMIT_TOKEN: S,
413
413
  CLAIM_COW_AIRDROP: I
414
- }, X = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
414
+ }, j = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
415
415
  __proto__: null,
416
416
  BUILD_CUSTOM_HOOK: k,
417
417
  CLAIM_COW_AIRDROP: I,
418
418
  CLAIM_GNO_FROM_VALIDATORS: N,
419
419
  PERMIT_TOKEN: S,
420
- default: j
420
+ default: q
421
421
  }, Symbol.toStringTag, { value: "Module" }));
422
- function Y(t, a) {
422
+ function X(t, a) {
423
423
  const e = a.reduce(
424
- (o, l) => (o[l.id] = l, o),
424
+ (o, c) => (o[c.id] = c, o),
425
425
  {}
426
426
  );
427
- return t.map((o) => ({
428
- hook: o,
429
- dapp: e[o.callData.slice(-q)] || null
430
- }));
427
+ return t.filter((o) => !!o.dappId).map((o) => {
428
+ const c = o, u = e[c.dappId];
429
+ return {
430
+ hook: c,
431
+ dapp: u || null
432
+ };
433
+ });
431
434
  }
432
- function z(t) {
433
- return Y(t, Object.values(X));
435
+ function z(t, a = []) {
436
+ return X(t, Object.values(j).concat(a));
434
437
  }
435
438
  export {
436
439
  T as CoWHookDappEvents,
437
- q as HOOK_DAPP_ID_LENGTH,
440
+ Q as HOOK_DAPP_ID_LENGTH,
438
441
  G as HookDappType,
439
442
  B as HookDappWalletCompatibility,
440
443
  y as hookDappIframeTransport,
441
- X as hookDappsRegistry,
442
- Q as initCoWHookDapp,
443
- Y as matchHooksToDapps,
444
+ j as hookDappsRegistry,
445
+ $ as initCoWHookDapp,
446
+ X as matchHooksToDapps,
444
447
  z as matchHooksToDappsRegistry
445
448
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cowprotocol/hook-dapp-lib",
3
- "version": "1.0.0-RC1",
3
+ "version": "1.1.0",
4
4
  "type": "commonjs",
5
5
  "description": "CoW Swap Hook Dapp Library. Allows you to develop pre/post hooks dapps for CoW Protocol.",
6
6
  "main": "index.js",
package/types.d.ts CHANGED
@@ -4,6 +4,7 @@ export interface CowHook {
4
4
  target: string;
5
5
  callData: string;
6
6
  gasLimit: string;
7
+ dappId: string;
7
8
  }
8
9
  export interface HookDappConditions {
9
10
  position?: 'post' | 'pre';
@@ -11,18 +12,22 @@ export interface HookDappConditions {
11
12
  supportedNetworks?: number[];
12
13
  }
13
14
  export interface CowHookCreation {
14
- hook: CowHook;
15
+ hook: Omit<CowHook, 'dappId'>;
15
16
  recipientOverride?: string;
16
17
  }
17
18
  export interface TokenData {
18
19
  address: string;
19
20
  }
20
21
  export interface CowHookDetails extends CowHookCreation {
22
+ hook: CowHook;
23
+ uuid: string;
24
+ }
25
+ export interface CowHookToEdit extends CowHookCreation {
21
26
  uuid: string;
22
27
  }
23
28
  export interface CoWHookDappActions {
24
29
  addHook(payload: CowHookCreation): void;
25
- editHook(payload: CowHookDetails): void;
30
+ editHook(payload: CowHookToEdit): void;
26
31
  setSellToken(token: TokenData): void;
27
32
  setBuyToken(token: TokenData): void;
28
33
  }
package/utils.d.ts CHANGED
@@ -1,7 +1,11 @@
1
1
  import { CowHook, HookDappBase } from './types';
2
+ type StrictCowHook = Omit<CowHook, 'dappId'> & {
3
+ dappId?: string;
4
+ };
2
5
  export interface HookToDappMatch {
3
6
  dapp: HookDappBase | null;
4
7
  hook: CowHook;
5
8
  }
6
- export declare function matchHooksToDapps(hooks: CowHook[], dapps: HookDappBase[]): HookToDappMatch[];
7
- export declare function matchHooksToDappsRegistry(hooks: CowHook[]): HookToDappMatch[];
9
+ export declare function matchHooksToDapps(hooks: StrictCowHook[], dapps: HookDappBase[]): HookToDappMatch[];
10
+ export declare function matchHooksToDappsRegistry(hooks: StrictCowHook[], additionalHookDapps?: HookDappBase[]): HookToDappMatch[];
11
+ export {};