@pufferfinance/puffer-sdk 1.0.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.
Files changed (36) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +81 -0
  3. package/dist/ccip-Bv7jv7p7.cjs +2 -0
  4. package/dist/ccip-Bv7jv7p7.cjs.map +1 -0
  5. package/dist/ccip-n5cHM2-q.js +165 -0
  6. package/dist/ccip-n5cHM2-q.js.map +1 -0
  7. package/dist/lib/api/puffer-client-helpers.d.ts +6218 -0
  8. package/dist/lib/api/puffer-client-helpers.test.d.ts +1 -0
  9. package/dist/lib/api/puffer-client.d.ts +28 -0
  10. package/dist/lib/api/puffer-client.test.d.ts +1 -0
  11. package/dist/lib/chains/constants.d.ts +11 -0
  12. package/dist/lib/contracts/abis/abis.d.ts +4151 -0
  13. package/dist/lib/contracts/abis/anvil/PufferVaultV2.d.ts +1361 -0
  14. package/dist/lib/contracts/abis/holesky/PufferVaultV2.d.ts +1361 -0
  15. package/dist/lib/contracts/abis/mainnet/PufferVaultV2.d.ts +1421 -0
  16. package/dist/lib/contracts/addresses.d.ts +11 -0
  17. package/dist/lib/contracts/handlers/puffer-vault-handler.d.ts +79 -0
  18. package/dist/lib/contracts/handlers/puffer-vault-handler.test.d.ts +1 -0
  19. package/dist/lib/errors/base-error.d.ts +8 -0
  20. package/dist/lib/errors/types.d.ts +4 -0
  21. package/dist/lib/errors/validation-errors.d.ts +4 -0
  22. package/dist/lib/errors/validation-errors.test.d.ts +1 -0
  23. package/dist/lib/main.d.ts +3 -0
  24. package/dist/lib/utils/types.d.ts +4 -0
  25. package/dist/lib/utils/version.d.ts +1 -0
  26. package/dist/main-CiwlneBr.js +13444 -0
  27. package/dist/main-CiwlneBr.js.map +1 -0
  28. package/dist/main-DY0whdxp.cjs +39 -0
  29. package/dist/main-DY0whdxp.cjs.map +1 -0
  30. package/dist/main.cjs +2 -0
  31. package/dist/main.cjs.map +1 -0
  32. package/dist/main.js +8 -0
  33. package/dist/main.js.map +1 -0
  34. package/dist/test/mocks/mock-request.d.ts +5 -0
  35. package/dist/test/mocks/setup-mock-clients.d.ts +6455 -0
  36. package/package.json +60 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Puffer Finance
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,81 @@
1
+ <div align="center">
2
+ <h1>Puffer SDK</h1>
3
+
4
+ <img alt="build" src="https://github.com/pufferfinance/puffer-sdk/actions/workflows/build-and-test.yml/badge.svg?branch=main" />
5
+ <img alt="license" src="https://img.shields.io/github/license/pufferfinance/puffer-sdk?color=limegreen" />
6
+ <img alt="npm downloads" src="https://img.shields.io/npm/dm/@pufferfinance/puffer-sdk?color=limegreen&logo=npm" />
7
+ <img alt="npm version" src="https://img.shields.io/npm/v/@pufferfinance/puffer-sdk?label=version&logo=npm" />
8
+ <!-- TODO: ADD COVERAGE BADGE -->
9
+
10
+ <p>SDK to seamlessly interact with puffer smart contracts<p>
11
+ </div>
12
+
13
+ ## Usage
14
+
15
+ Install the package.
16
+
17
+ ```sh
18
+ npm install @pufferfinance/puffer-sdk
19
+ ```
20
+
21
+ Example code to check pufETH balance.
22
+
23
+ ```ts
24
+ import {
25
+ PufferClientHelpers,
26
+ PufferClient,
27
+ Chain,
28
+ } from '@pufferfinance/puffer-sdk';
29
+
30
+ const walletClient = PufferClientHelpers.createWalletClient({
31
+ chain: Chain.Holesky,
32
+ provider: window.ethereum,
33
+ });
34
+ const pufferClient = new PufferClient(Chain.Holesky, walletClient);
35
+ const [walletAddress] = await pufferClient.requestAddresses();
36
+
37
+ const balance = await pufferClient.vault.balanceOf(walletAddress);
38
+ ```
39
+
40
+ ## Features
41
+
42
+ - Interact with puffer smart contracts.
43
+ - Deposit ETH to mint pufETH.
44
+ - Deposit stETH to mint pufETH.
45
+ - Check pufETH balance.
46
+ - Get latest rate of pufETH compared to ETH.
47
+ - and much more.
48
+
49
+ ## Documentation
50
+
51
+ Check the [documentation website](https://pufferfinance.github.io/puffer-sdk/) for detailed documentation and guides.
52
+
53
+ ## Development
54
+
55
+ Install dependencies.
56
+
57
+ ```sh
58
+ pnpm install
59
+ ```
60
+
61
+ Start the package in watch mode.
62
+
63
+ ```sh
64
+ pnpm dev
65
+ ```
66
+
67
+ Setup linking so the package can be linked to other projects locally.
68
+
69
+ ```sh
70
+ pnpm link --global
71
+ ```
72
+
73
+ To link the package to a local project, run the following command.
74
+
75
+ ```sh
76
+ pnpm link --global @pufferfinance/puffer-sdk
77
+ ```
78
+
79
+ ## Release
80
+
81
+ The release is automated using [release-it](https://github.com/release-it/release-it) and the [publish.yml](./.github/workflows/publish.yml) GitHub action. The action can be [dispatched manually](https://github.com/PufferFinance/puffer-sdk/actions/workflows/publish.yml) to make the release.
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./main-DY0whdxp.cjs");class b extends e.BaseError{constructor({callbackSelector:r,cause:t,data:c,extraData:i,sender:d,urls:a}){var u;super(t.shortMessage||"An error occurred while fetching for an offchain result.",{cause:t,metaMessages:[...t.metaMessages||[],(u=t.metaMessages)!=null&&u.length?"":[],"Offchain Gateway Call:",a&&[" Gateway URL(s):",...a.map(f=>` ${e.getUrl(f)}`)],` Sender: ${d}`,` Data: ${c}`,` Callback selector: ${r}`,` Extra data: ${i}`].flat()}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"OffchainLookupError"})}}class g extends e.BaseError{constructor({result:r,url:t}){super("Offchain gateway response is malformed. Response data must be a hex value.",{metaMessages:[`Gateway URL: ${e.getUrl(t)}`,`Response: ${e.stringify(r)}`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"OffchainLookupResponseMalformedError"})}}class k extends e.BaseError{constructor({sender:r,to:t}){super("Reverted sender address does not match target contract address (`to`).",{metaMessages:[`Contract address: ${t}`,`OffchainLookup sender address: ${r}`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"OffchainLookupSenderMismatchError"})}}function E(s,r){if(!e.isAddress(s,{strict:!1}))throw new e.InvalidAddressError({address:s});if(!e.isAddress(r,{strict:!1}))throw new e.InvalidAddressError({address:r});return s.toLowerCase()===r.toLowerCase()}const L="0x556f1830",h={name:"OffchainLookup",type:"error",inputs:[{name:"sender",type:"address"},{name:"urls",type:"string[]"},{name:"callData",type:"bytes"},{name:"callbackFunction",type:"bytes4"},{name:"extraData",type:"bytes"}]};async function O(s,{blockNumber:r,blockTag:t,data:c,to:i}){const{args:d}=e.decodeErrorResult({data:c,abi:[h]}),[a,u,f,o,n]=d,{ccipRead:l}=s,y=l&&typeof(l==null?void 0:l.request)=="function"?l.request:m;try{if(!E(i,a))throw new k({sender:a,to:i});const p=await y({data:f,sender:a,urls:u}),{data:w}=await e.call(s,{blockNumber:r,blockTag:t,data:e.concat([o,e.encodeAbiParameters([{type:"bytes"},{type:"bytes"}],[p,n])]),to:i});return w}catch(p){throw new b({callbackSelector:o,cause:p,data:c,extraData:n,sender:a,urls:u})}}async function m({data:s,sender:r,urls:t}){var i;let c=new Error("An unknown error occurred.");for(let d=0;d<t.length;d++){const a=t[d],u=a.includes("{data}")?"GET":"POST",f=u==="POST"?{data:s,sender:r}:void 0;try{const o=await fetch(a.replace("{sender}",r).replace("{data}",s),{body:JSON.stringify(f),method:u});let n;if((i=o.headers.get("Content-Type"))!=null&&i.startsWith("application/json")?n=(await o.json()).data:n=await o.text(),!o.ok){c=new e.HttpRequestError({body:f,details:n!=null&&n.error?e.stringify(n.error):o.statusText,headers:o.headers,status:o.status,url:a});continue}if(!e.isHex(n)){c=new g({result:n,url:a});continue}return n}catch(o){c=new e.HttpRequestError({body:f,details:o.message,url:a})}}throw c}exports.ccipRequest=m;exports.offchainLookup=O;exports.offchainLookupAbiItem=h;exports.offchainLookupSignature=L;
2
+ //# sourceMappingURL=ccip-Bv7jv7p7.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ccip-Bv7jv7p7.cjs","sources":["../node_modules/.pnpm/viem@2.10.8_typescript@5.4.5_zod@3.23.8/node_modules/viem/_esm/errors/ccip.js","../node_modules/.pnpm/viem@2.10.8_typescript@5.4.5_zod@3.23.8/node_modules/viem/_esm/utils/address/isAddressEqual.js","../node_modules/.pnpm/viem@2.10.8_typescript@5.4.5_zod@3.23.8/node_modules/viem/_esm/utils/ccip.js"],"sourcesContent":["import { stringify } from '../utils/stringify.js';\nimport { BaseError } from './base.js';\nimport { getUrl } from './utils.js';\nexport class OffchainLookupError extends BaseError {\n constructor({ callbackSelector, cause, data, extraData, sender, urls, }) {\n super(cause.shortMessage ||\n 'An error occurred while fetching for an offchain result.', {\n cause,\n metaMessages: [\n ...(cause.metaMessages || []),\n cause.metaMessages?.length ? '' : [],\n 'Offchain Gateway Call:',\n urls && [\n ' Gateway URL(s):',\n ...urls.map((url) => ` ${getUrl(url)}`),\n ],\n ` Sender: ${sender}`,\n ` Data: ${data}`,\n ` Callback selector: ${callbackSelector}`,\n ` Extra data: ${extraData}`,\n ].flat(),\n });\n Object.defineProperty(this, \"name\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: 'OffchainLookupError'\n });\n }\n}\nexport class OffchainLookupResponseMalformedError extends BaseError {\n constructor({ result, url }) {\n super('Offchain gateway response is malformed. Response data must be a hex value.', {\n metaMessages: [\n `Gateway URL: ${getUrl(url)}`,\n `Response: ${stringify(result)}`,\n ],\n });\n Object.defineProperty(this, \"name\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: 'OffchainLookupResponseMalformedError'\n });\n }\n}\nexport class OffchainLookupSenderMismatchError extends BaseError {\n constructor({ sender, to }) {\n super('Reverted sender address does not match target contract address (`to`).', {\n metaMessages: [\n `Contract address: ${to}`,\n `OffchainLookup sender address: ${sender}`,\n ],\n });\n Object.defineProperty(this, \"name\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: 'OffchainLookupSenderMismatchError'\n });\n }\n}\n//# sourceMappingURL=ccip.js.map","import { InvalidAddressError, } from '../../errors/address.js';\nimport { isAddress } from './isAddress.js';\nexport function isAddressEqual(a, b) {\n if (!isAddress(a, { strict: false }))\n throw new InvalidAddressError({ address: a });\n if (!isAddress(b, { strict: false }))\n throw new InvalidAddressError({ address: b });\n return a.toLowerCase() === b.toLowerCase();\n}\n//# sourceMappingURL=isAddressEqual.js.map","import { call } from '../actions/public/call.js';\nimport { OffchainLookupError, OffchainLookupResponseMalformedError, OffchainLookupSenderMismatchError, } from '../errors/ccip.js';\nimport { HttpRequestError } from '../errors/request.js';\nimport { decodeErrorResult } from './abi/decodeErrorResult.js';\nimport { encodeAbiParameters } from './abi/encodeAbiParameters.js';\nimport { isAddressEqual } from './address/isAddressEqual.js';\nimport { concat } from './data/concat.js';\nimport { isHex } from './data/isHex.js';\nimport { stringify } from './stringify.js';\nexport const offchainLookupSignature = '0x556f1830';\nexport const offchainLookupAbiItem = {\n name: 'OffchainLookup',\n type: 'error',\n inputs: [\n {\n name: 'sender',\n type: 'address',\n },\n {\n name: 'urls',\n type: 'string[]',\n },\n {\n name: 'callData',\n type: 'bytes',\n },\n {\n name: 'callbackFunction',\n type: 'bytes4',\n },\n {\n name: 'extraData',\n type: 'bytes',\n },\n ],\n};\nexport async function offchainLookup(client, { blockNumber, blockTag, data, to, }) {\n const { args } = decodeErrorResult({\n data,\n abi: [offchainLookupAbiItem],\n });\n const [sender, urls, callData, callbackSelector, extraData] = args;\n const { ccipRead } = client;\n const ccipRequest_ = ccipRead && typeof ccipRead?.request === 'function'\n ? ccipRead.request\n : ccipRequest;\n try {\n if (!isAddressEqual(to, sender))\n throw new OffchainLookupSenderMismatchError({ sender, to });\n const result = await ccipRequest_({ data: callData, sender, urls });\n const { data: data_ } = await call(client, {\n blockNumber,\n blockTag,\n data: concat([\n callbackSelector,\n encodeAbiParameters([{ type: 'bytes' }, { type: 'bytes' }], [result, extraData]),\n ]),\n to,\n });\n return data_;\n }\n catch (err) {\n throw new OffchainLookupError({\n callbackSelector,\n cause: err,\n data,\n extraData,\n sender,\n urls,\n });\n }\n}\nexport async function ccipRequest({ data, sender, urls, }) {\n let error = new Error('An unknown error occurred.');\n for (let i = 0; i < urls.length; i++) {\n const url = urls[i];\n const method = url.includes('{data}') ? 'GET' : 'POST';\n const body = method === 'POST' ? { data, sender } : undefined;\n try {\n const response = await fetch(url.replace('{sender}', sender).replace('{data}', data), {\n body: JSON.stringify(body),\n method,\n });\n let result;\n if (response.headers.get('Content-Type')?.startsWith('application/json')) {\n result = (await response.json()).data;\n }\n else {\n result = (await response.text());\n }\n if (!response.ok) {\n error = new HttpRequestError({\n body,\n details: result?.error\n ? stringify(result.error)\n : response.statusText,\n headers: response.headers,\n status: response.status,\n url,\n });\n continue;\n }\n if (!isHex(result)) {\n error = new OffchainLookupResponseMalformedError({\n result,\n url,\n });\n continue;\n }\n return result;\n }\n catch (err) {\n error = new HttpRequestError({\n body,\n details: err.message,\n url,\n });\n }\n }\n throw error;\n}\n//# sourceMappingURL=ccip.js.map"],"names":["OffchainLookupError","BaseError","callbackSelector","cause","data","extraData","sender","urls","_a","url","getUrl","OffchainLookupResponseMalformedError","result","stringify","OffchainLookupSenderMismatchError","to","isAddressEqual","a","b","isAddress","InvalidAddressError","offchainLookupSignature","offchainLookupAbiItem","offchainLookup","client","blockNumber","blockTag","args","decodeErrorResult","callData","ccipRead","ccipRequest_","ccipRequest","data_","call","concat","encodeAbiParameters","err","error","i","method","body","response","HttpRequestError","isHex"],"mappings":"uHAGO,MAAMA,UAA4BC,EAAAA,SAAU,CAC/C,YAAY,CAAE,iBAAAC,EAAkB,MAAAC,EAAO,KAAAC,EAAM,UAAAC,EAAW,OAAAC,EAAQ,KAAAC,GAAS,OACrE,MAAMJ,EAAM,cACR,2DAA4D,CAC5D,MAAAA,EACA,aAAc,CACV,GAAIA,EAAM,cAAgB,CAAE,GAC5BK,EAAAL,EAAM,eAAN,MAAAK,EAAoB,OAAS,GAAK,CAAE,EACpC,yBACAD,GAAQ,CACJ,oBACA,GAAGA,EAAK,IAAKE,GAAQ,OAAOC,EAAM,OAACD,CAAG,CAAC,EAAE,CAC5C,EACD,aAAaH,CAAM,GACnB,WAAWF,CAAI,GACf,wBAAwBF,CAAgB,GACxC,iBAAiBG,CAAS,EAC7B,EAAC,KAAM,CACpB,CAAS,EACD,OAAO,eAAe,KAAM,OAAQ,CAChC,WAAY,GACZ,aAAc,GACd,SAAU,GACV,MAAO,qBACnB,CAAS,CACJ,CACL,CACO,MAAMM,UAA6CV,EAAAA,SAAU,CAChE,YAAY,CAAE,OAAAW,EAAQ,IAAAH,GAAO,CACzB,MAAM,6EAA8E,CAChF,aAAc,CACV,gBAAgBC,EAAAA,OAAOD,CAAG,CAAC,GAC3B,aAAaI,EAAAA,UAAUD,CAAM,CAAC,EACjC,CACb,CAAS,EACD,OAAO,eAAe,KAAM,OAAQ,CAChC,WAAY,GACZ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8B,EAAS,KAAI,GAAI,KAGjC9B,EAAU,MAAM8B,EAAS,KAAI,EAE7B,CAACA,EAAS,GAAI,CACdJ,EAAQ,IAAIK,EAAAA,iBAAiB,CACzB,KAAAF,EACA,QAAS7B,GAAA,MAAAA,EAAQ,MACXC,EAAS,UAACD,EAAO,KAAK,EACtB8B,EAAS,WACf,QAASA,EAAS,QAClB,OAAQA,EAAS,OACjB,IAAAjC,CACpB,CAAiB,EACD,QACH,CACD,GAAI,CAACmC,EAAAA,MAAMhC,CAAM,EAAG,CAChB0B,EAAQ,IAAI3B,EAAqC,CAC7C,OAAAC,EACA,IAAAH,CACpB,CAAiB,EACD,QACH,CACD,OAAOG,CACV,OACMyB,EAAK,CACRC,EAAQ,IAAIK,EAAAA,iBAAiB,CACzB,KAAAF,EACA,QAASJ,EAAI,QACb,IAAA5B,CAChB,CAAa,CACJ,CACJ,CACD,MAAM6B,CACV","x_google_ignoreList":[0,1,2]}
@@ -0,0 +1,165 @@
1
+ import { B as p, g as w, s as b, i as h, I as m, d as O, c as L, a as E, e as x, H as y, b as M } from "./main-CiwlneBr.js";
2
+ class R extends p {
3
+ constructor({ callbackSelector: e, cause: t, data: n, extraData: c, sender: u, urls: r }) {
4
+ var i;
5
+ super(t.shortMessage || "An error occurred while fetching for an offchain result.", {
6
+ cause: t,
7
+ metaMessages: [
8
+ ...t.metaMessages || [],
9
+ (i = t.metaMessages) != null && i.length ? "" : [],
10
+ "Offchain Gateway Call:",
11
+ r && [
12
+ " Gateway URL(s):",
13
+ ...r.map((d) => ` ${w(d)}`)
14
+ ],
15
+ ` Sender: ${u}`,
16
+ ` Data: ${n}`,
17
+ ` Callback selector: ${e}`,
18
+ ` Extra data: ${c}`
19
+ ].flat()
20
+ }), Object.defineProperty(this, "name", {
21
+ enumerable: !0,
22
+ configurable: !0,
23
+ writable: !0,
24
+ value: "OffchainLookupError"
25
+ });
26
+ }
27
+ }
28
+ class $ extends p {
29
+ constructor({ result: e, url: t }) {
30
+ super("Offchain gateway response is malformed. Response data must be a hex value.", {
31
+ metaMessages: [
32
+ `Gateway URL: ${w(t)}`,
33
+ `Response: ${b(e)}`
34
+ ]
35
+ }), Object.defineProperty(this, "name", {
36
+ enumerable: !0,
37
+ configurable: !0,
38
+ writable: !0,
39
+ value: "OffchainLookupResponseMalformedError"
40
+ });
41
+ }
42
+ }
43
+ class S extends p {
44
+ constructor({ sender: e, to: t }) {
45
+ super("Reverted sender address does not match target contract address (`to`).", {
46
+ metaMessages: [
47
+ `Contract address: ${t}`,
48
+ `OffchainLookup sender address: ${e}`
49
+ ]
50
+ }), Object.defineProperty(this, "name", {
51
+ enumerable: !0,
52
+ configurable: !0,
53
+ writable: !0,
54
+ value: "OffchainLookupSenderMismatchError"
55
+ });
56
+ }
57
+ }
58
+ function A(a, e) {
59
+ if (!h(a, { strict: !1 }))
60
+ throw new m({ address: a });
61
+ if (!h(e, { strict: !1 }))
62
+ throw new m({ address: e });
63
+ return a.toLowerCase() === e.toLowerCase();
64
+ }
65
+ const P = "0x556f1830", q = {
66
+ name: "OffchainLookup",
67
+ type: "error",
68
+ inputs: [
69
+ {
70
+ name: "sender",
71
+ type: "address"
72
+ },
73
+ {
74
+ name: "urls",
75
+ type: "string[]"
76
+ },
77
+ {
78
+ name: "callData",
79
+ type: "bytes"
80
+ },
81
+ {
82
+ name: "callbackFunction",
83
+ type: "bytes4"
84
+ },
85
+ {
86
+ name: "extraData",
87
+ type: "bytes"
88
+ }
89
+ ]
90
+ };
91
+ async function j(a, { blockNumber: e, blockTag: t, data: n, to: c }) {
92
+ const { args: u } = O({
93
+ data: n,
94
+ abi: [q]
95
+ }), [r, i, d, s, o] = u, { ccipRead: f } = a, g = f && typeof (f == null ? void 0 : f.request) == "function" ? f.request : v;
96
+ try {
97
+ if (!A(c, r))
98
+ throw new S({ sender: r, to: c });
99
+ const l = await g({ data: d, sender: r, urls: i }), { data: k } = await L(a, {
100
+ blockNumber: e,
101
+ blockTag: t,
102
+ data: E([
103
+ s,
104
+ x([{ type: "bytes" }, { type: "bytes" }], [l, o])
105
+ ]),
106
+ to: c
107
+ });
108
+ return k;
109
+ } catch (l) {
110
+ throw new R({
111
+ callbackSelector: s,
112
+ cause: l,
113
+ data: n,
114
+ extraData: o,
115
+ sender: r,
116
+ urls: i
117
+ });
118
+ }
119
+ }
120
+ async function v({ data: a, sender: e, urls: t }) {
121
+ var c;
122
+ let n = new Error("An unknown error occurred.");
123
+ for (let u = 0; u < t.length; u++) {
124
+ const r = t[u], i = r.includes("{data}") ? "GET" : "POST", d = i === "POST" ? { data: a, sender: e } : void 0;
125
+ try {
126
+ const s = await fetch(r.replace("{sender}", e).replace("{data}", a), {
127
+ body: JSON.stringify(d),
128
+ method: i
129
+ });
130
+ let o;
131
+ if ((c = s.headers.get("Content-Type")) != null && c.startsWith("application/json") ? o = (await s.json()).data : o = await s.text(), !s.ok) {
132
+ n = new y({
133
+ body: d,
134
+ details: o != null && o.error ? b(o.error) : s.statusText,
135
+ headers: s.headers,
136
+ status: s.status,
137
+ url: r
138
+ });
139
+ continue;
140
+ }
141
+ if (!M(o)) {
142
+ n = new $({
143
+ result: o,
144
+ url: r
145
+ });
146
+ continue;
147
+ }
148
+ return o;
149
+ } catch (s) {
150
+ n = new y({
151
+ body: d,
152
+ details: s.message,
153
+ url: r
154
+ });
155
+ }
156
+ }
157
+ throw n;
158
+ }
159
+ export {
160
+ v as ccipRequest,
161
+ j as offchainLookup,
162
+ q as offchainLookupAbiItem,
163
+ P as offchainLookupSignature
164
+ };
165
+ //# sourceMappingURL=ccip-n5cHM2-q.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ccip-n5cHM2-q.js","sources":["../node_modules/.pnpm/viem@2.10.8_typescript@5.4.5_zod@3.23.8/node_modules/viem/_esm/errors/ccip.js","../node_modules/.pnpm/viem@2.10.8_typescript@5.4.5_zod@3.23.8/node_modules/viem/_esm/utils/address/isAddressEqual.js","../node_modules/.pnpm/viem@2.10.8_typescript@5.4.5_zod@3.23.8/node_modules/viem/_esm/utils/ccip.js"],"sourcesContent":["import { stringify } from '../utils/stringify.js';\nimport { BaseError } from './base.js';\nimport { getUrl } from './utils.js';\nexport class OffchainLookupError extends BaseError {\n constructor({ callbackSelector, cause, data, extraData, sender, urls, }) {\n super(cause.shortMessage ||\n 'An error occurred while fetching for an offchain result.', {\n cause,\n metaMessages: [\n ...(cause.metaMessages || []),\n cause.metaMessages?.length ? '' : [],\n 'Offchain Gateway Call:',\n urls && [\n ' Gateway URL(s):',\n ...urls.map((url) => ` ${getUrl(url)}`),\n ],\n ` Sender: ${sender}`,\n ` Data: ${data}`,\n ` Callback selector: ${callbackSelector}`,\n ` Extra data: ${extraData}`,\n ].flat(),\n });\n Object.defineProperty(this, \"name\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: 'OffchainLookupError'\n });\n }\n}\nexport class OffchainLookupResponseMalformedError extends BaseError {\n constructor({ result, url }) {\n super('Offchain gateway response is malformed. Response data must be a hex value.', {\n metaMessages: [\n `Gateway URL: ${getUrl(url)}`,\n `Response: ${stringify(result)}`,\n ],\n });\n Object.defineProperty(this, \"name\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: 'OffchainLookupResponseMalformedError'\n });\n }\n}\nexport class OffchainLookupSenderMismatchError extends BaseError {\n constructor({ sender, to }) {\n super('Reverted sender address does not match target contract address (`to`).', {\n metaMessages: [\n `Contract address: ${to}`,\n `OffchainLookup sender address: ${sender}`,\n ],\n });\n Object.defineProperty(this, \"name\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: 'OffchainLookupSenderMismatchError'\n });\n }\n}\n//# sourceMappingURL=ccip.js.map","import { InvalidAddressError, } from '../../errors/address.js';\nimport { isAddress } from './isAddress.js';\nexport function isAddressEqual(a, b) {\n if (!isAddress(a, { strict: false }))\n throw new InvalidAddressError({ address: a });\n if (!isAddress(b, { strict: false }))\n throw new InvalidAddressError({ address: b });\n return a.toLowerCase() === b.toLowerCase();\n}\n//# sourceMappingURL=isAddressEqual.js.map","import { call } from '../actions/public/call.js';\nimport { OffchainLookupError, OffchainLookupResponseMalformedError, OffchainLookupSenderMismatchError, } from '../errors/ccip.js';\nimport { HttpRequestError } from '../errors/request.js';\nimport { decodeErrorResult } from './abi/decodeErrorResult.js';\nimport { encodeAbiParameters } from './abi/encodeAbiParameters.js';\nimport { isAddressEqual } from './address/isAddressEqual.js';\nimport { concat } from './data/concat.js';\nimport { isHex } from './data/isHex.js';\nimport { stringify } from './stringify.js';\nexport const offchainLookupSignature = '0x556f1830';\nexport const offchainLookupAbiItem = {\n name: 'OffchainLookup',\n type: 'error',\n inputs: [\n {\n name: 'sender',\n type: 'address',\n },\n {\n name: 'urls',\n type: 'string[]',\n },\n {\n name: 'callData',\n type: 'bytes',\n },\n {\n name: 'callbackFunction',\n type: 'bytes4',\n },\n {\n name: 'extraData',\n type: 'bytes',\n },\n ],\n};\nexport async function offchainLookup(client, { blockNumber, blockTag, data, to, }) {\n const { args } = decodeErrorResult({\n data,\n abi: [offchainLookupAbiItem],\n });\n const [sender, urls, callData, callbackSelector, extraData] = args;\n const { ccipRead } = client;\n const ccipRequest_ = ccipRead && typeof ccipRead?.request === 'function'\n ? ccipRead.request\n : ccipRequest;\n try {\n if (!isAddressEqual(to, sender))\n throw new OffchainLookupSenderMismatchError({ sender, to });\n const result = await ccipRequest_({ data: callData, sender, urls });\n const { data: data_ } = await call(client, {\n blockNumber,\n blockTag,\n data: concat([\n callbackSelector,\n encodeAbiParameters([{ type: 'bytes' }, { type: 'bytes' }], [result, extraData]),\n ]),\n to,\n });\n return data_;\n }\n catch (err) {\n throw new OffchainLookupError({\n callbackSelector,\n cause: err,\n data,\n extraData,\n sender,\n urls,\n });\n }\n}\nexport async function ccipRequest({ data, sender, urls, }) {\n let error = new Error('An unknown error occurred.');\n for (let i = 0; i < urls.length; i++) {\n const url = urls[i];\n const method = url.includes('{data}') ? 'GET' : 'POST';\n const body = method === 'POST' ? { data, sender } : undefined;\n try {\n const response = await fetch(url.replace('{sender}', sender).replace('{data}', data), {\n body: JSON.stringify(body),\n method,\n });\n let result;\n if (response.headers.get('Content-Type')?.startsWith('application/json')) {\n result = (await response.json()).data;\n }\n else {\n result = (await response.text());\n }\n if (!response.ok) {\n error = new HttpRequestError({\n body,\n details: result?.error\n ? stringify(result.error)\n : response.statusText,\n headers: response.headers,\n status: response.status,\n url,\n });\n continue;\n }\n if (!isHex(result)) {\n error = new OffchainLookupResponseMalformedError({\n result,\n url,\n });\n continue;\n }\n return result;\n }\n catch (err) {\n error = new HttpRequestError({\n body,\n details: err.message,\n url,\n });\n }\n }\n throw error;\n}\n//# sourceMappingURL=ccip.js.map"],"names":["OffchainLookupError","BaseError","callbackSelector","cause","data","extraData","sender","urls","_a","url","getUrl","OffchainLookupResponseMalformedError","result","stringify","OffchainLookupSenderMismatchError","to","isAddressEqual","b","isAddress","InvalidAddressError","offchainLookupSignature","offchainLookupAbiItem","offchainLookup","client","blockNumber","blockTag","args","decodeErrorResult","callData","ccipRead","ccipRequest_","ccipRequest","data_","call","concat","encodeAbiParameters","err","error","i","method","body","response","HttpRequestError","isHex"],"mappings":";AAGO,MAAMA,UAA4BC,EAAU;AAAA,EAC/C,YAAY,EAAE,kBAAAC,GAAkB,OAAAC,GAAO,MAAAC,GAAM,WAAAC,GAAW,QAAAC,GAAQ,MAAAC,KAAS;;AACrE,UAAMJ,EAAM,gBACR,4DAA4D;AAAA,MAC5D,OAAAA;AAAA,MACA,cAAc;AAAA,QACV,GAAIA,EAAM,gBAAgB,CAAE;AAAA,SAC5BK,IAAAL,EAAM,iBAAN,QAAAK,EAAoB,SAAS,KAAK,CAAE;AAAA,QACpC;AAAA,QACAD,KAAQ;AAAA,UACJ;AAAA,UACA,GAAGA,EAAK,IAAI,CAACE,MAAQ,OAAOC,EAAOD,CAAG,CAAC,EAAE;AAAA,QAC5C;AAAA,QACD,aAAaH,CAAM;AAAA,QACnB,WAAWF,CAAI;AAAA,QACf,wBAAwBF,CAAgB;AAAA,QACxC,iBAAiBG,CA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