@swapper-finance/deposit-sdk 0.2.0 → 0.2.1

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.
@@ -1 +1,233 @@
1
- import{SwapperWalletProvider}from"./SwapperWalletProvider";import{createSwapperSigner}from"./adapters";const DEFAULT_IFRAME_URL="https://deposit.swapper.finance/";export class SwapperIframe{constructor(e){if(this.eventHandlers=new Map,this.validateConfig(e),this.config={integratorId:e.integratorId,dstChainId:e.dstChainId,dstTokenAddr:e.dstTokenAddr,depositWalletAddress:e.depositWalletAddress,styles:e.styles,customContractCalls:e.customContractCalls,supportedDepositOptions:e.supportedDepositOptions,webhookUrl:e.webhookUrl},this.iframeUrl=e.iframeUrl||DEFAULT_IFRAME_URL,this.iframe=this.createIframe(e),this.setupMessageListener(),e.container&&this.mount(e.container),e.wallet){const t=new URL(this.iframeUrl).origin;if("signer"in e.wallet){const s=createSwapperSigner(e.wallet.signer),i=e=>s.sendTransaction(e),r=e=>s.switchChain(e);Promise.all([s.getAddress(),s.getChainId()]).then(([e,s])=>{this.walletProvider=new SwapperWalletProvider({iframe:this.iframe,iframeOrigin:t,onTransactionRequest:i,onChainSwitchRequest:r,autoConnect:{address:e,chainId:s}})}).catch(e=>{console.error("[SwapperIframe] Failed to initialize wallet provider:",e)})}else this.walletProvider=new SwapperWalletProvider({iframe:this.iframe,iframeOrigin:t,onTransactionRequest:e.wallet.onTransactionRequest,onChainSwitchRequest:e.wallet.onChainSwitchRequest,autoConnect:e.wallet.autoConnect})}}validateConfig(e){const t=["integratorId","dstChainId","dstTokenAddr","depositWalletAddress"];for(const s of t)if(!e[s])throw new Error(`Missing required parameter: ${s}`)}createIframe(e){const t=document.createElement("iframe"),s=new URL(this.iframeUrl);s.searchParams.set("integratorId",this.config.integratorId),s.searchParams.set("dstChainId",this.config.dstChainId),s.searchParams.set("dstTokenAddr",this.config.dstTokenAddr),s.searchParams.set("depositWalletAddress",this.config.depositWalletAddress),this.config.styles&&s.searchParams.set("styles",JSON.stringify(this.config.styles)),this.config.customContractCalls&&s.searchParams.set("customContractCalls",JSON.stringify(this.config.customContractCalls)),this.config.supportedDepositOptions&&s.searchParams.set("supportedDepositOptions",JSON.stringify(this.config.supportedDepositOptions)),this.config.webhookUrl&&s.searchParams.set("webhookUrl",this.config.webhookUrl),s.searchParams.set("t",Date.now().toString()),t.src=s.toString(),t.style.border="none",t.style.width=e.iframeAttributes?.width||"100%",t.style.height=e.iframeAttributes?.height||"560px",t.title=e.iframeAttributes?.title||"Swapper Deposit Widget";const i=`camera; clipboard-write self ${new URL(this.iframeUrl).origin}`,r=e.iframeAttributes?.allow||"",a=r?`${i} ${r}`:i;t.setAttribute("allow",a);const o="allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts",n=e.iframeAttributes?.sandbox||"",d=n?`${o} ${n}`:o;return t.setAttribute("sandbox",d),e.iframeAttributes&&Object.entries(e.iframeAttributes).forEach(([e,s])=>{s&&"width"!==e&&"height"!==e&&"title"!==e&&"allow"!==e&&"sandbox"!==e&&t.setAttribute(e,s)}),t}setupMessageListener(){this.messageListener=e=>{const t=new URL(this.iframeUrl).origin;if(e.origin===t&&e.data&&"object"==typeof e.data){const t={type:e.data.type,data:e.data.data},s=this.eventHandlers.get(t.type);s&&s.forEach(e=>e(t));const i=this.eventHandlers.get("*");i&&i.forEach(e=>e(t))}},window.addEventListener("message",this.messageListener)}mount(e){const t="string"==typeof e?document.querySelector(e):e;if(!t)throw new Error(`Container not found: ${"string"==typeof e?e:"provided element"}`);t.appendChild(this.iframe)}updateConfig(e){this.config={...this.config,...e},this.sendMessage({type:"SWAPPER_CONFIG",config:e})}updateStyles(e){this.updateConfig({styles:e})}updateCustomContractCalls(e){this.updateConfig({customContractCalls:e})}updateSupportedDepositOptions(e){this.updateConfig({supportedDepositOptions:e})}updateWebhookUrl(e){this.updateConfig({webhookUrl:e})}sendMessage(e){const t=new URL(this.iframeUrl).origin;this.iframe.contentWindow?.postMessage(e,t)}on(e,t){this.eventHandlers.has(e)||this.eventHandlers.set(e,new Set),this.eventHandlers.get(e).add(t)}off(e,t){const s=this.eventHandlers.get(e);s&&(s.delete(t),0===s.size&&this.eventHandlers.delete(e))}getIframe(){return this.iframe}getConfig(){return{...this.config}}updateSigner(e){const t=createSwapperSigner(e);this.walletProvider&&(this.walletProvider.destroy(),this.walletProvider=void 0);const s=new URL(this.iframeUrl).origin,i=e=>t.sendTransaction(e),r=e=>t.switchChain(e);Promise.all([t.getAddress(),t.getChainId()]).then(([e,t])=>{this.walletProvider=new SwapperWalletProvider({iframe:this.iframe,iframeOrigin:s,onTransactionRequest:i,onChainSwitchRequest:r,autoConnect:{address:e,chainId:t}})}).catch(e=>{console.error("[SwapperIframe] Failed to update wallet provider:",e)})}destroy(){this.walletProvider&&(this.walletProvider.destroy(),this.walletProvider=void 0),this.messageListener&&window.removeEventListener("message",this.messageListener),this.eventHandlers.clear(),this.iframe.parentNode&&this.iframe.parentNode.removeChild(this.iframe)}}
1
+ import { SwapperWalletProvider } from "./SwapperWalletProvider";
2
+ import { createSwapperSigner } from "./adapters";
3
+ const DEFAULT_IFRAME_URL = "https://deposit.swapper.finance/";
4
+ export class SwapperIframe {
5
+ constructor(options) {
6
+ this.eventHandlers = new Map();
7
+ this.validateConfig(options);
8
+ this.config = {
9
+ integratorId: options.integratorId,
10
+ dstChainId: options.dstChainId,
11
+ dstTokenAddr: options.dstTokenAddr,
12
+ depositWalletAddress: options.depositWalletAddress,
13
+ styles: options.styles,
14
+ customContractCalls: options.customContractCalls,
15
+ supportedDepositOptions: options.supportedDepositOptions,
16
+ webhookUrl: options.webhookUrl,
17
+ };
18
+ this.iframeUrl = options.iframeUrl || DEFAULT_IFRAME_URL;
19
+ this.iframe = this.createIframe(options);
20
+ this.setupMessageListener();
21
+ if (options.container) {
22
+ this.mount(options.container);
23
+ }
24
+ if (!!options.wallet) {
25
+ const iframeOrigin = new URL(this.iframeUrl).origin;
26
+ if ("signer" in options.wallet) {
27
+ const signer = createSwapperSigner(options.wallet.signer);
28
+ const onTransactionRequest = (tx) => signer.sendTransaction(tx);
29
+ const onChainSwitchRequest = (chainId) => signer.switchChain(chainId);
30
+ Promise.all([signer.getAddress(), signer.getChainId()])
31
+ .then(([address, chainId]) => {
32
+ this.walletProvider = new SwapperWalletProvider({
33
+ iframe: this.iframe,
34
+ iframeOrigin,
35
+ onTransactionRequest,
36
+ onChainSwitchRequest,
37
+ autoConnect: { address, chainId },
38
+ });
39
+ })
40
+ .catch((err) => {
41
+ console.error("[SwapperIframe] Failed to initialize wallet provider:", err);
42
+ });
43
+ }
44
+ else {
45
+ this.walletProvider = new SwapperWalletProvider({
46
+ iframe: this.iframe,
47
+ iframeOrigin,
48
+ onTransactionRequest: options.wallet.onTransactionRequest,
49
+ onChainSwitchRequest: options.wallet.onChainSwitchRequest,
50
+ autoConnect: options.wallet.autoConnect,
51
+ });
52
+ }
53
+ }
54
+ }
55
+ validateConfig(config) {
56
+ const required = [
57
+ "integratorId",
58
+ "dstChainId",
59
+ "dstTokenAddr",
60
+ "depositWalletAddress",
61
+ ];
62
+ for (const field of required) {
63
+ if (!config[field]) {
64
+ throw new Error(`Missing required parameter: ${field}`);
65
+ }
66
+ }
67
+ }
68
+ createIframe(options) {
69
+ const iframe = document.createElement("iframe");
70
+ const url = new URL(this.iframeUrl);
71
+ url.searchParams.set("integratorId", this.config.integratorId);
72
+ url.searchParams.set("dstChainId", this.config.dstChainId);
73
+ url.searchParams.set("dstTokenAddr", this.config.dstTokenAddr);
74
+ url.searchParams.set("depositWalletAddress", this.config.depositWalletAddress);
75
+ if (this.config.styles) {
76
+ url.searchParams.set("styles", JSON.stringify(this.config.styles));
77
+ }
78
+ if (this.config.customContractCalls) {
79
+ url.searchParams.set("customContractCalls", JSON.stringify(this.config.customContractCalls));
80
+ }
81
+ if (this.config.supportedDepositOptions) {
82
+ url.searchParams.set("supportedDepositOptions", JSON.stringify(this.config.supportedDepositOptions));
83
+ }
84
+ if (this.config.webhookUrl) {
85
+ url.searchParams.set("webhookUrl", this.config.webhookUrl);
86
+ }
87
+ url.searchParams.set("t", Date.now().toString());
88
+ iframe.src = url.toString();
89
+ iframe.style.border = "none";
90
+ iframe.style.width = options.iframeAttributes?.width || "100%";
91
+ iframe.style.height = options.iframeAttributes?.height || "560px";
92
+ iframe.title = options.iframeAttributes?.title || "Swapper Deposit Widget";
93
+ const iframeOrigin = new URL(this.iframeUrl).origin;
94
+ const defaultAllow = `camera; clipboard-write self ${iframeOrigin}`;
95
+ const additionalAllow = options.iframeAttributes?.allow || "";
96
+ const allowPermissions = additionalAllow
97
+ ? `${defaultAllow} ${additionalAllow}`
98
+ : defaultAllow;
99
+ iframe.setAttribute("allow", allowPermissions);
100
+ const defaultSandbox = "allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts";
101
+ const additionalSandbox = options.iframeAttributes?.sandbox || "";
102
+ const sandboxPermissions = additionalSandbox
103
+ ? `${defaultSandbox} ${additionalSandbox}`
104
+ : defaultSandbox;
105
+ iframe.setAttribute("sandbox", sandboxPermissions);
106
+ if (options.iframeAttributes) {
107
+ Object.entries(options.iframeAttributes).forEach(([key, value]) => {
108
+ if (value &&
109
+ key !== "width" &&
110
+ key !== "height" &&
111
+ key !== "title" &&
112
+ key !== "allow" &&
113
+ key !== "sandbox") {
114
+ iframe.setAttribute(key, value);
115
+ }
116
+ });
117
+ }
118
+ return iframe;
119
+ }
120
+ setupMessageListener() {
121
+ this.messageListener = (event) => {
122
+ const iframeOrigin = new URL(this.iframeUrl).origin;
123
+ if (event.origin !== iframeOrigin) {
124
+ return;
125
+ }
126
+ if (event.data && typeof event.data === "object") {
127
+ const swapperEvent = {
128
+ type: event.data.type,
129
+ data: event.data.data,
130
+ };
131
+ const handlers = this.eventHandlers.get(swapperEvent.type);
132
+ if (handlers) {
133
+ handlers.forEach((handler) => handler(swapperEvent));
134
+ }
135
+ const wildcardHandlers = this.eventHandlers.get("*");
136
+ if (wildcardHandlers) {
137
+ wildcardHandlers.forEach((handler) => handler(swapperEvent));
138
+ }
139
+ }
140
+ };
141
+ window.addEventListener("message", this.messageListener);
142
+ }
143
+ mount(container) {
144
+ const containerElement = typeof container === "string"
145
+ ? document.querySelector(container)
146
+ : container;
147
+ if (!containerElement) {
148
+ throw new Error(`Container not found: ${typeof container === "string" ? container : "provided element"}`);
149
+ }
150
+ containerElement.appendChild(this.iframe);
151
+ }
152
+ updateConfig(config) {
153
+ this.config = { ...this.config, ...config };
154
+ this.sendMessage({
155
+ type: "SWAPPER_CONFIG",
156
+ config: config,
157
+ });
158
+ }
159
+ updateStyles(styles) {
160
+ this.updateConfig({ styles });
161
+ }
162
+ updateCustomContractCalls(customContractCalls) {
163
+ this.updateConfig({ customContractCalls });
164
+ }
165
+ updateSupportedDepositOptions(supportedDepositOptions) {
166
+ this.updateConfig({ supportedDepositOptions });
167
+ }
168
+ updateWebhookUrl(webhookUrl) {
169
+ this.updateConfig({ webhookUrl });
170
+ }
171
+ sendMessage(message) {
172
+ const iframeOrigin = new URL(this.iframeUrl).origin;
173
+ this.iframe.contentWindow?.postMessage(message, iframeOrigin);
174
+ }
175
+ on(eventType, handler) {
176
+ if (!this.eventHandlers.has(eventType)) {
177
+ this.eventHandlers.set(eventType, new Set());
178
+ }
179
+ this.eventHandlers.get(eventType).add(handler);
180
+ }
181
+ off(eventType, handler) {
182
+ const handlers = this.eventHandlers.get(eventType);
183
+ if (handlers) {
184
+ handlers.delete(handler);
185
+ if (handlers.size === 0) {
186
+ this.eventHandlers.delete(eventType);
187
+ }
188
+ }
189
+ }
190
+ getIframe() {
191
+ return this.iframe;
192
+ }
193
+ getConfig() {
194
+ return { ...this.config };
195
+ }
196
+ updateSigner(rawSigner) {
197
+ const signer = createSwapperSigner(rawSigner);
198
+ if (this.walletProvider) {
199
+ this.walletProvider.destroy();
200
+ this.walletProvider = undefined;
201
+ }
202
+ const iframeOrigin = new URL(this.iframeUrl).origin;
203
+ const onTransactionRequest = (tx) => signer.sendTransaction(tx);
204
+ const onChainSwitchRequest = (chainId) => signer.switchChain(chainId);
205
+ Promise.all([signer.getAddress(), signer.getChainId()])
206
+ .then(([address, chainId]) => {
207
+ this.walletProvider = new SwapperWalletProvider({
208
+ iframe: this.iframe,
209
+ iframeOrigin,
210
+ onTransactionRequest,
211
+ onChainSwitchRequest,
212
+ autoConnect: { address, chainId },
213
+ });
214
+ })
215
+ .catch((err) => {
216
+ console.error("[SwapperIframe] Failed to update wallet provider:", err);
217
+ });
218
+ }
219
+ destroy() {
220
+ if (this.walletProvider) {
221
+ this.walletProvider.destroy();
222
+ this.walletProvider = undefined;
223
+ }
224
+ if (this.messageListener) {
225
+ window.removeEventListener("message", this.messageListener);
226
+ }
227
+ this.eventHandlers.clear();
228
+ if (this.iframe.parentNode) {
229
+ this.iframe.parentNode.removeChild(this.iframe);
230
+ }
231
+ }
232
+ }
233
+ //# sourceMappingURL=SwapperIframe.js.map
@@ -1 +1,175 @@
1
- import{SwapperIframe}from"./SwapperIframe";export class SwapperModal{constructor(e){this.iframe=null,this.overlay=null,this.modalContainer=null,this.iframeContainer=null,this.isOpen=!1,this.options=e}open(){this.isOpen||(this.createModal(),this.isOpen=!0)}close(){this.isOpen&&(this.destroyModal(),this.isOpen=!1,this.options.onClose&&this.options.onClose())}isModalOpen(){return this.isOpen}getIframe(){return this.iframe}createModal(){const e=this.options.modalStyle||{},t=this.options.styles||{};if(this.overlay=document.createElement("div"),this.overlay.style.cssText=`\n position: fixed;\n top: 0;\n left: 0;\n width: 100vw;\n height: 100vh;\n background: ${e.overlayColor||"rgba(0, 0, 0, 0.7)"};\n z-index: ${e.zIndex||1e4};\n display: flex;\n align-items: center;\n justify-content: center;\n animation: swapper-fade-in 0.2s ease-out;\n `,!document.getElementById("swapper-modal-styles")){const e=document.createElement("style");e.id="swapper-modal-styles",e.textContent="\n @keyframes swapper-fade-in {\n from { opacity: 0; }\n to { opacity: 1; }\n }\n @keyframes swapper-scale-in {\n from {\n transform: scale(0.95);\n opacity: 0;\n }\n to {\n transform: scale(1);\n opacity: 1;\n }\n }\n ",document.head.appendChild(e)}this.overlay.addEventListener("click",e=>{e.target===this.overlay&&this.close()});const n=e=>{"Escape"===e.key&&(this.close(),document.removeEventListener("keydown",n))};if(document.addEventListener("keydown",n),this.modalContainer=document.createElement("div"),this.modalContainer.style.cssText=`\n position: relative;\n width: ${e.width||"450px"};\n height: ${e.height||"560px"};\n background: ${"light"===t.themeMode?"#ffffff":"#111111"};\n border-radius: 30px;\n overflow: hidden;\n animation: swapper-scale-in 0.3s ease-out;\n `,!0===e.showCloseButton){const t=document.createElement("button");t.innerHTML="×",t.style.cssText=`\n position: absolute;\n top: 12px;\n right: 12px;\n width: 32px;\n height: 32px;\n border: none;\n background: rgba(0, 0, 0, 0.5);\n color: white;\n font-size: 24px;\n line-height: 1;\n border-radius: 50%;\n cursor: pointer;\n z-index: ${(e.zIndex||1e4)+1};\n display: flex;\n align-items: center;\n justify-content: center;\n transition: background 0.2s ease;\n `,t.onmouseover=()=>{t.style.background="rgba(0, 0, 0, 0.7)"},t.onmouseout=()=>{t.style.background="rgba(0, 0, 0, 0.5)"},t.onclick=()=>this.close(),this.modalContainer.appendChild(t)}this.iframeContainer=document.createElement("div"),this.iframeContainer.style.cssText="\n width: 100%;\n height: 100%;\n ",this.modalContainer.appendChild(this.iframeContainer),this.overlay.appendChild(this.modalContainer),document.body.appendChild(this.overlay),document.body.style.overflow="hidden",this.iframe=new SwapperIframe({container:this.iframeContainer,integratorId:this.options.integratorId,dstChainId:this.options.dstChainId,dstTokenAddr:this.options.dstTokenAddr,depositWalletAddress:this.options.depositWalletAddress,styles:this.options.styles,customContractCalls:this.options.customContractCalls,supportedDepositOptions:this.options.supportedDepositOptions,webhookUrl:this.options.webhookUrl,wallet:this.options.wallet,iframeUrl:this.options.iframeUrl,iframeAttributes:{...this.options.iframeAttributes,width:"100%",height:"100%"}})}destroyModal(){this.iframe&&(this.iframe.destroy(),this.iframe=null),this.overlay&&this.overlay.parentNode&&this.overlay.parentNode.removeChild(this.overlay),document.body.style.overflow="",this.overlay=null,this.modalContainer=null,this.iframeContainer=null}destroy(){this.close()}}export function openSwapperModal(e){const t=new SwapperModal(e);return t.open(),t}
1
+ import { SwapperIframe } from "./SwapperIframe";
2
+ export class SwapperModal {
3
+ constructor(options) {
4
+ this.iframe = null;
5
+ this.overlay = null;
6
+ this.modalContainer = null;
7
+ this.iframeContainer = null;
8
+ this.isOpen = false;
9
+ this.options = options;
10
+ }
11
+ open() {
12
+ if (this.isOpen) {
13
+ return;
14
+ }
15
+ this.createModal();
16
+ this.isOpen = true;
17
+ }
18
+ close() {
19
+ if (!this.isOpen) {
20
+ return;
21
+ }
22
+ this.destroyModal();
23
+ this.isOpen = false;
24
+ if (this.options.onClose) {
25
+ this.options.onClose();
26
+ }
27
+ }
28
+ isModalOpen() {
29
+ return this.isOpen;
30
+ }
31
+ getIframe() {
32
+ return this.iframe;
33
+ }
34
+ createModal() {
35
+ const style = this.options.modalStyle || {};
36
+ const iframeStyles = this.options.styles || {};
37
+ this.overlay = document.createElement("div");
38
+ this.overlay.style.cssText = `
39
+ position: fixed;
40
+ top: 0;
41
+ left: 0;
42
+ width: 100vw;
43
+ height: 100vh;
44
+ background: ${style.overlayColor || "rgba(0, 0, 0, 0.7)"};
45
+ z-index: ${style.zIndex || 10000};
46
+ display: flex;
47
+ align-items: center;
48
+ justify-content: center;
49
+ animation: swapper-fade-in 0.2s ease-out;
50
+ `;
51
+ if (!document.getElementById("swapper-modal-styles")) {
52
+ const styleSheet = document.createElement("style");
53
+ styleSheet.id = "swapper-modal-styles";
54
+ styleSheet.textContent = `
55
+ @keyframes swapper-fade-in {
56
+ from { opacity: 0; }
57
+ to { opacity: 1; }
58
+ }
59
+ @keyframes swapper-scale-in {
60
+ from {
61
+ transform: scale(0.95);
62
+ opacity: 0;
63
+ }
64
+ to {
65
+ transform: scale(1);
66
+ opacity: 1;
67
+ }
68
+ }
69
+ `;
70
+ document.head.appendChild(styleSheet);
71
+ }
72
+ this.overlay.addEventListener("click", (e) => {
73
+ if (e.target === this.overlay) {
74
+ this.close();
75
+ }
76
+ });
77
+ const escapeHandler = (e) => {
78
+ if (e.key === "Escape") {
79
+ this.close();
80
+ document.removeEventListener("keydown", escapeHandler);
81
+ }
82
+ };
83
+ document.addEventListener("keydown", escapeHandler);
84
+ this.modalContainer = document.createElement("div");
85
+ this.modalContainer.style.cssText = `
86
+ position: relative;
87
+ width: ${style.width || "450px"};
88
+ height: ${style.height || "560px"};
89
+ background: ${iframeStyles.themeMode === "light" ? "#ffffff" : "#111111"};
90
+ border-radius: 30px;
91
+ overflow: hidden;
92
+ animation: swapper-scale-in 0.3s ease-out;
93
+ `;
94
+ if (style.showCloseButton === true) {
95
+ const closeButton = document.createElement("button");
96
+ closeButton.innerHTML = "×";
97
+ closeButton.style.cssText = `
98
+ position: absolute;
99
+ top: 12px;
100
+ right: 12px;
101
+ width: 32px;
102
+ height: 32px;
103
+ border: none;
104
+ background: rgba(0, 0, 0, 0.5);
105
+ color: white;
106
+ font-size: 24px;
107
+ line-height: 1;
108
+ border-radius: 50%;
109
+ cursor: pointer;
110
+ z-index: ${(style.zIndex || 10000) + 1};
111
+ display: flex;
112
+ align-items: center;
113
+ justify-content: center;
114
+ transition: background 0.2s ease;
115
+ `;
116
+ closeButton.onmouseover = () => {
117
+ closeButton.style.background = "rgba(0, 0, 0, 0.7)";
118
+ };
119
+ closeButton.onmouseout = () => {
120
+ closeButton.style.background = "rgba(0, 0, 0, 0.5)";
121
+ };
122
+ closeButton.onclick = () => this.close();
123
+ this.modalContainer.appendChild(closeButton);
124
+ }
125
+ this.iframeContainer = document.createElement("div");
126
+ this.iframeContainer.style.cssText = `
127
+ width: 100%;
128
+ height: 100%;
129
+ `;
130
+ this.modalContainer.appendChild(this.iframeContainer);
131
+ this.overlay.appendChild(this.modalContainer);
132
+ document.body.appendChild(this.overlay);
133
+ document.body.style.overflow = "hidden";
134
+ this.iframe = new SwapperIframe({
135
+ container: this.iframeContainer,
136
+ integratorId: this.options.integratorId,
137
+ dstChainId: this.options.dstChainId,
138
+ dstTokenAddr: this.options.dstTokenAddr,
139
+ depositWalletAddress: this.options.depositWalletAddress,
140
+ styles: this.options.styles,
141
+ customContractCalls: this.options.customContractCalls,
142
+ supportedDepositOptions: this.options.supportedDepositOptions,
143
+ webhookUrl: this.options.webhookUrl,
144
+ wallet: this.options.wallet,
145
+ iframeUrl: this.options.iframeUrl,
146
+ iframeAttributes: {
147
+ ...this.options.iframeAttributes,
148
+ width: "100%",
149
+ height: "100%",
150
+ },
151
+ });
152
+ }
153
+ destroyModal() {
154
+ if (this.iframe) {
155
+ this.iframe.destroy();
156
+ this.iframe = null;
157
+ }
158
+ if (this.overlay && this.overlay.parentNode) {
159
+ this.overlay.parentNode.removeChild(this.overlay);
160
+ }
161
+ document.body.style.overflow = "";
162
+ this.overlay = null;
163
+ this.modalContainer = null;
164
+ this.iframeContainer = null;
165
+ }
166
+ destroy() {
167
+ this.close();
168
+ }
169
+ }
170
+ export function openSwapperModal(options) {
171
+ const modal = new SwapperModal(options);
172
+ modal.open();
173
+ return modal;
174
+ }
175
+ //# sourceMappingURL=SwapperModal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SwapperWalletProvider.d.ts","sourceRoot":"","sources":["../src/SwapperWalletProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,4BAA4B,EAK7B,MAAM,SAAS,CAAC;AAajB,qBAAa,qBAAqB;IAChC,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,oBAAoB,CAA4B;IACxD,OAAO,CAAC,oBAAoB,CAA4B;IACxD,OAAO,CAAC,iBAAiB,CAAC,CAAuC;IACjE,OAAO,CAAC,eAAe,CAAgC;IAEvD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC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AgB,IAAI,IAAI;IASxB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAQzC,cAAc,CACnB,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,GACvD,IAAI;IAOA,UAAU,IAAI,OAAO;IAIrB,cAAc,IAAI,OAAO;IAIzB,UAAU,IAAI,MAAM,GAAG,SAAS;IAIhC,UAAU,IAAI,MAAM,GAAG,SAAS;IAIhC,OAAO,IAAI,IAAI;CAQvB"}
@@ -1 +1,139 @@
1
- import{SWAPPER_WALLET_MSGS}from"./types";const DEFAULT_ORIGIN="https://deposit.swapper.finance";function resolveOrigin(e,t){if(t)return t;try{return new URL(e.src).origin}catch{return DEFAULT_ORIGIN}}export class SwapperWalletProvider{constructor(e){this.isReady=!1,this.isConnected=!1,this.iframe=e.iframe,this.iframeOrigin=resolveOrigin(e.iframe,e.iframeOrigin),this.onTransactionRequest=e.onTransactionRequest,this.onChainSwitchRequest=e.onChainSwitchRequest,this.autoConnectConfig=e.autoConnect,this.messageListener=this.handleMessage.bind(this),window.addEventListener("message",this.messageListener)}handleMessage(e){if(e.origin!==this.iframeOrigin)return;if(!e.data||"object"!=typeof e.data)return;const{type:t}=e.data;switch(t){case SWAPPER_WALLET_MSGS.WALLET_READY:this.isReady=!0,this.autoConnectConfig&&this.connectWallet(this.autoConnectConfig.address,this.autoConnectConfig.chainId);break;case SWAPPER_WALLET_MSGS.TX_REQUEST:this.handleTxRequest(e.data);break;case SWAPPER_WALLET_MSGS.CHAIN_SWITCH_REQUEST:this.handleChainSwitchRequest(e.data)}}async handleTxRequest(e){try{const t=await this.onTransactionRequest(e.transaction);this.postMessage({type:SWAPPER_WALLET_MSGS.TX_RESPONSE,requestId:e.requestId,hash:t.hash})}catch(t){this.postMessage({type:SWAPPER_WALLET_MSGS.TX_RESPONSE,requestId:e.requestId,error:t instanceof Error?t.message:String(t)})}}async handleChainSwitchRequest(e){try{await this.onChainSwitchRequest(Number(e.chainId)),this.chainId=Number(e.chainId),this.postMessage({type:SWAPPER_WALLET_MSGS.CHAIN_SWITCH_RESPONSE,requestId:e.requestId}),this.postMessage({type:SWAPPER_WALLET_MSGS.WALLET_CHAIN_CHANGED,chainId:e.chainId})}catch(t){this.postMessage({type:SWAPPER_WALLET_MSGS.CHAIN_SWITCH_RESPONSE,requestId:e.requestId,error:t instanceof Error?t.message:String(t)})}}postMessage(e){this.iframe.contentWindow?.postMessage(e,this.iframeOrigin)}connectWallet(e,t){this.isConnected=!0,this.address=e,this.chainId=t,this.postMessage({type:SWAPPER_WALLET_MSGS.WALLET_CONNECT,address:e,chainId:String(t)})}disconnectWallet(){this.isConnected=!1,this.address=void 0,this.chainId=void 0,this.postMessage({type:SWAPPER_WALLET_MSGS.WALLET_DISCONNECT})}notifyChainChanged(e){this.chainId=e,this.postMessage({type:SWAPPER_WALLET_MSGS.WALLET_CHAIN_CHANGED,chainId:String(e)})}setAutoConnect(e){this.autoConnectConfig=e,e&&this.isReady&&this.connectWallet(e.address,e.chainId)}getIsReady(){return this.isReady}getIsConnected(){return this.isConnected}getAddress(){return this.address}getChainId(){return this.chainId}destroy(){window.removeEventListener("message",this.messageListener),this.isReady=!1,this.isConnected=!1,this.address=void 0,this.chainId=void 0,this.autoConnectConfig=void 0}}
1
+ import { SWAPPER_WALLET_MSGS, } from "./types";
2
+ const DEFAULT_ORIGIN = "https://deposit.swapper.finance";
3
+ function resolveOrigin(iframe, explicit) {
4
+ if (explicit)
5
+ return explicit;
6
+ try {
7
+ return new URL(iframe.src).origin;
8
+ }
9
+ catch {
10
+ return DEFAULT_ORIGIN;
11
+ }
12
+ }
13
+ export class SwapperWalletProvider {
14
+ constructor(options) {
15
+ this.isReady = false;
16
+ this.isConnected = false;
17
+ this.iframe = options.iframe;
18
+ this.iframeOrigin = resolveOrigin(options.iframe, options.iframeOrigin);
19
+ this.onTransactionRequest = options.onTransactionRequest;
20
+ this.onChainSwitchRequest = options.onChainSwitchRequest;
21
+ this.autoConnectConfig = options.autoConnect;
22
+ this.messageListener = this.handleMessage.bind(this);
23
+ window.addEventListener("message", this.messageListener);
24
+ }
25
+ handleMessage(event) {
26
+ if (event.origin !== this.iframeOrigin)
27
+ return;
28
+ if (!event.data || typeof event.data !== "object")
29
+ return;
30
+ const { type } = event.data;
31
+ switch (type) {
32
+ case SWAPPER_WALLET_MSGS.WALLET_READY:
33
+ this.isReady = true;
34
+ if (this.autoConnectConfig) {
35
+ this.connectWallet(this.autoConnectConfig.address, this.autoConnectConfig.chainId);
36
+ }
37
+ break;
38
+ case SWAPPER_WALLET_MSGS.TX_REQUEST:
39
+ this.handleTxRequest(event.data);
40
+ break;
41
+ case SWAPPER_WALLET_MSGS.CHAIN_SWITCH_REQUEST:
42
+ this.handleChainSwitchRequest(event.data);
43
+ break;
44
+ }
45
+ }
46
+ async handleTxRequest(msg) {
47
+ try {
48
+ const result = await this.onTransactionRequest(msg.transaction);
49
+ this.postMessage({
50
+ type: SWAPPER_WALLET_MSGS.TX_RESPONSE,
51
+ requestId: msg.requestId,
52
+ hash: result.hash,
53
+ });
54
+ }
55
+ catch (err) {
56
+ this.postMessage({
57
+ type: SWAPPER_WALLET_MSGS.TX_RESPONSE,
58
+ requestId: msg.requestId,
59
+ error: err instanceof Error ? err.message : String(err),
60
+ });
61
+ }
62
+ }
63
+ async handleChainSwitchRequest(msg) {
64
+ try {
65
+ await this.onChainSwitchRequest(Number(msg.chainId));
66
+ this.chainId = Number(msg.chainId);
67
+ this.postMessage({
68
+ type: SWAPPER_WALLET_MSGS.CHAIN_SWITCH_RESPONSE,
69
+ requestId: msg.requestId,
70
+ });
71
+ this.postMessage({
72
+ type: SWAPPER_WALLET_MSGS.WALLET_CHAIN_CHANGED,
73
+ chainId: msg.chainId,
74
+ });
75
+ }
76
+ catch (err) {
77
+ this.postMessage({
78
+ type: SWAPPER_WALLET_MSGS.CHAIN_SWITCH_RESPONSE,
79
+ requestId: msg.requestId,
80
+ error: err instanceof Error ? err.message : String(err),
81
+ });
82
+ }
83
+ }
84
+ postMessage(message) {
85
+ this.iframe.contentWindow?.postMessage(message, this.iframeOrigin);
86
+ }
87
+ connectWallet(address, chainId) {
88
+ this.isConnected = true;
89
+ this.address = address;
90
+ this.chainId = chainId;
91
+ this.postMessage({
92
+ type: SWAPPER_WALLET_MSGS.WALLET_CONNECT,
93
+ address,
94
+ chainId: String(chainId),
95
+ });
96
+ }
97
+ disconnectWallet() {
98
+ this.isConnected = false;
99
+ this.address = undefined;
100
+ this.chainId = undefined;
101
+ this.postMessage({
102
+ type: SWAPPER_WALLET_MSGS.WALLET_DISCONNECT,
103
+ });
104
+ }
105
+ notifyChainChanged(chainId) {
106
+ this.chainId = chainId;
107
+ this.postMessage({
108
+ type: SWAPPER_WALLET_MSGS.WALLET_CHAIN_CHANGED,
109
+ chainId: String(chainId),
110
+ });
111
+ }
112
+ setAutoConnect(config) {
113
+ this.autoConnectConfig = config;
114
+ if (config && this.isReady) {
115
+ this.connectWallet(config.address, config.chainId);
116
+ }
117
+ }
118
+ getIsReady() {
119
+ return this.isReady;
120
+ }
121
+ getIsConnected() {
122
+ return this.isConnected;
123
+ }
124
+ getAddress() {
125
+ return this.address;
126
+ }
127
+ getChainId() {
128
+ return this.chainId;
129
+ }
130
+ destroy() {
131
+ window.removeEventListener("message", this.messageListener);
132
+ this.isReady = false;
133
+ this.isConnected = false;
134
+ this.address = undefined;
135
+ this.chainId = undefined;
136
+ this.autoConnectConfig = undefined;
137
+ }
138
+ }
139
+ //# sourceMappingURL=SwapperWalletProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SwapperWalletProvider.js","sourceRoot":"","sources":["../src/SwapperWalletProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,GAMpB,MAAM,SAAS,CAAC;AAEjB,MAAM,cAAc,GAAG,iCAAiC,CAAC;AAEzD,SAAS,aAAa,CAAC,MAAyB,EAAE,QAAiB;IACjE,IAAI,QAAQ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W,CAAC;YACf,IAAI,EAAE,mBAAmB,CAAC,oBAAoB;YAC9C,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC;SACzB,CAAC,CAAC;IACL,CAAC;IAEM,cAAc,CACnB,MAAwD;QAExD,IAAI,CAAC,iBAAiB,GAAG,MAAM,CAAC;QAChC,IAAI,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAC3B,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;IAEM,UAAU;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAEM,cAAc;QACnB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAEM,UAAU;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAEM,UAAU;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAEM,OAAO;QACZ,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QAC5D,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;QACzB,IAAI,CAAC,iBAAiB,GAAG,SAAS,CAAC;IACrC,CAAC;CACF"}
package/dist/adapters.js CHANGED
@@ -1 +1,136 @@
1
- export class EthersV5SignerAdapter{constructor(t){this.signer=t}async getAddress(){return this.signer.getAddress()}async getChainId(){return this.signer.getChainId()}async sendTransaction(t){return{hash:(await this.signer.sendTransaction({to:t.to,data:t.data,value:t.value,gasLimit:t.gasLimit})).hash}}async switchChain(t){const e="0x"+Number(t).toString(16);if(!this.signer.provider||!("send"in this.signer.provider))throw new Error("Provider does not support wallet_switchEthereumChain");await this.signer.provider.send("wallet_switchEthereumChain",[{chainId:e}])}}export class EthersV6SignerAdapter{constructor(t){this.signer=t}async getAddress(){return this.signer.getAddress()}async getChainId(){const t=await this.signer.provider.getNetwork();return Number(t.chainId)}async sendTransaction(t){return{hash:(await this.signer.sendTransaction({to:t.to,data:t.data,value:t.value,gasLimit:t.gasLimit})).hash}}async switchChain(t){const e="0x"+Number(t).toString(16);await this.signer.provider.send("wallet_switchEthereumChain",[{chainId:e}])}}export class ViemSignerAdapter{constructor(t){this.client=t}async getAddress(){const[t]=await this.client.getAddresses();if(!t)throw new Error("No account found in WalletClient");return t}async getChainId(){return this.client.getChainId()}async sendTransaction(t){const[e]=await this.client.getAddresses();if(!e)throw new Error("No account found");return{hash:await this.client.sendTransaction({account:e,to:t.to,data:t.data,value:t.value?BigInt(t.value):void 0,gas:t.gasLimit?BigInt(t.gasLimit):void 0,chain:void 0})}}async switchChain(t){await this.client.switchChain({id:t})}}function isViemWalletClient(t){return"object"==typeof t&&null!==t&&"function"==typeof t.getAddresses}function isEthersV6Signer(t){return"object"==typeof t&&null!==t&&"function"==typeof t.getAddress&&"function"==typeof t.sendTransaction&&null!=t.provider&&"function"==typeof t.provider.getNetwork&&!("getChainId"in t)}function isEthersV5Signer(t){return"object"==typeof t&&null!==t&&"function"==typeof t.getAddress&&"function"==typeof t.getChainId&&"function"==typeof t.sendTransaction&&!("getAddresses"in t)}function isSwapperSigner(t){return"object"==typeof t&&null!==t&&"function"==typeof t.getAddress&&"function"==typeof t.getChainId&&"function"==typeof t.sendTransaction&&"function"==typeof t.switchChain}export function createSwapperSigner(t){if(isViemWalletClient(t))return new ViemSignerAdapter(t);if(isEthersV6Signer(t))return new EthersV6SignerAdapter(t);if(isEthersV5Signer(t))return new EthersV5SignerAdapter(t);if(isSwapperSigner(t))return t;throw new Error("Unsupported signer type. Expected an ethers v5 Signer, ethers v6 Signer, viem WalletClient, or an object implementing the SwapperSigner interface.")}
1
+ export class EthersV5SignerAdapter {
2
+ constructor(signer) {
3
+ this.signer = signer;
4
+ }
5
+ async getAddress() {
6
+ return this.signer.getAddress();
7
+ }
8
+ async getChainId() {
9
+ return this.signer.getChainId();
10
+ }
11
+ async sendTransaction(transaction) {
12
+ const txResponse = await this.signer.sendTransaction({
13
+ to: transaction.to,
14
+ data: transaction.data,
15
+ value: transaction.value,
16
+ gasLimit: transaction.gasLimit,
17
+ });
18
+ return { hash: txResponse.hash };
19
+ }
20
+ async switchChain(chainId) {
21
+ const hexChainId = "0x" + Number(chainId).toString(16);
22
+ if (this.signer.provider && "send" in this.signer.provider) {
23
+ await this.signer.provider.send("wallet_switchEthereumChain", [
24
+ { chainId: hexChainId },
25
+ ]);
26
+ }
27
+ else {
28
+ throw new Error("Provider does not support wallet_switchEthereumChain");
29
+ }
30
+ }
31
+ }
32
+ export class EthersV6SignerAdapter {
33
+ constructor(signer) {
34
+ this.signer = signer;
35
+ }
36
+ async getAddress() {
37
+ return this.signer.getAddress();
38
+ }
39
+ async getChainId() {
40
+ const network = await this.signer.provider.getNetwork();
41
+ return Number(network.chainId);
42
+ }
43
+ async sendTransaction(transaction) {
44
+ const txResponse = await this.signer.sendTransaction({
45
+ to: transaction.to,
46
+ data: transaction.data,
47
+ value: transaction.value,
48
+ gasLimit: transaction.gasLimit,
49
+ });
50
+ return { hash: txResponse.hash };
51
+ }
52
+ async switchChain(chainId) {
53
+ const hexChainId = "0x" + Number(chainId).toString(16);
54
+ await this.signer.provider.send("wallet_switchEthereumChain", [
55
+ { chainId: hexChainId },
56
+ ]);
57
+ }
58
+ }
59
+ export class ViemSignerAdapter {
60
+ constructor(client) {
61
+ this.client = client;
62
+ }
63
+ async getAddress() {
64
+ const [address] = await this.client.getAddresses();
65
+ if (!address)
66
+ throw new Error("No account found in WalletClient");
67
+ return address;
68
+ }
69
+ async getChainId() {
70
+ return this.client.getChainId();
71
+ }
72
+ async sendTransaction(transaction) {
73
+ const [account] = await this.client.getAddresses();
74
+ if (!account)
75
+ throw new Error("No account found");
76
+ const hash = await this.client.sendTransaction({
77
+ account,
78
+ to: transaction.to,
79
+ data: transaction.data,
80
+ value: transaction.value ? BigInt(transaction.value) : undefined,
81
+ gas: transaction.gasLimit ? BigInt(transaction.gasLimit) : undefined,
82
+ chain: undefined,
83
+ });
84
+ return { hash };
85
+ }
86
+ async switchChain(chainId) {
87
+ await this.client.switchChain({ id: chainId });
88
+ }
89
+ }
90
+ function isViemWalletClient(signer) {
91
+ return (typeof signer === "object" &&
92
+ signer !== null &&
93
+ typeof signer.getAddresses === "function");
94
+ }
95
+ function isEthersV6Signer(signer) {
96
+ return (typeof signer === "object" &&
97
+ signer !== null &&
98
+ typeof signer.getAddress === "function" &&
99
+ typeof signer.sendTransaction === "function" &&
100
+ signer.provider != null &&
101
+ typeof signer.provider.getNetwork === "function" &&
102
+ !("getChainId" in signer));
103
+ }
104
+ function isEthersV5Signer(signer) {
105
+ return (typeof signer === "object" &&
106
+ signer !== null &&
107
+ typeof signer.getAddress === "function" &&
108
+ typeof signer.getChainId === "function" &&
109
+ typeof signer.sendTransaction === "function" &&
110
+ !("getAddresses" in signer));
111
+ }
112
+ function isSwapperSigner(signer) {
113
+ return (typeof signer === "object" &&
114
+ signer !== null &&
115
+ typeof signer.getAddress === "function" &&
116
+ typeof signer.getChainId === "function" &&
117
+ typeof signer.sendTransaction === "function" &&
118
+ typeof signer.switchChain === "function");
119
+ }
120
+ export function createSwapperSigner(signer) {
121
+ if (isViemWalletClient(signer)) {
122
+ return new ViemSignerAdapter(signer);
123
+ }
124
+ if (isEthersV6Signer(signer)) {
125
+ return new EthersV6SignerAdapter(signer);
126
+ }
127
+ if (isEthersV5Signer(signer)) {
128
+ return new EthersV5SignerAdapter(signer);
129
+ }
130
+ if (isSwapperSigner(signer)) {
131
+ return signer;
132
+ }
133
+ throw new Error("Unsupported signer type. Expected an ethers v5 Signer, ethers v6 Signer, " +
134
+ "viem WalletClient, or an object implementing the SwapperSigner interface.");
135
+ }
136
+ //# sourceMappingURL=adapters.js.map
package/dist/helpers.js CHANGED
@@ -1 +1,74 @@
1
- import{ContractCallType}from"./types";class ABICoder{encodeApprove(a,e){return"0x095ea7b3"+a.slice(2).padStart(64,"0")+BigInt(e).toString(16).padStart(64,"0")}encodeTransfer(a,e){return"0xa9059cbb"+a.slice(2).padStart(64,"0")+BigInt(e).toString(16).padStart(64,"0")}encodeTransferFrom(a,e,r){return"0x23b872dd"+a.slice(2).padStart(64,"0")+e.slice(2).padStart(64,"0")+BigInt(r).toString(16).padStart(64,"0")}encodeBalancePayload(a,e){return"0x"+a.slice(2).padStart(64,"0")+BigInt(e).toString(16).padStart(64,"0")}}const abiCoder=new ABICoder;export function approve(a,e,r){return{callType:ContractCallType.DEFAULT,target:a,value:"0",callData:abiCoder.encodeApprove(e,r),payload:"0x"}}export function transfer(a,e,r){return{callType:ContractCallType.DEFAULT,target:a,value:"0",callData:abiCoder.encodeTransfer(e,r),payload:"0x"}}export function transferFrom(a,e,r,t){return{callType:ContractCallType.DEFAULT,target:a,value:"0",callData:abiCoder.encodeTransferFrom(e,r,t),payload:"0x"}}export function approveBalance(a,e){return{callType:ContractCallType.FULL_TOKEN_BALANCE,target:a,value:"0",callData:abiCoder.encodeApprove(e,"0"),payload:abiCoder.encodeBalancePayload(a,"1")}}export function transferBalance(a,e){return{callType:ContractCallType.FULL_TOKEN_BALANCE,target:a,value:"0",callData:abiCoder.encodeTransfer(e,"0"),payload:abiCoder.encodeBalancePayload(a,"1")}}
1
+ import { ContractCallType } from "./types";
2
+ class ABICoder {
3
+ encodeApprove(spender, amount) {
4
+ const selector = "0x095ea7b3";
5
+ const paddedSpender = spender.slice(2).padStart(64, "0");
6
+ const paddedAmount = BigInt(amount).toString(16).padStart(64, "0");
7
+ return selector + paddedSpender + paddedAmount;
8
+ }
9
+ encodeTransfer(recipient, amount) {
10
+ const selector = "0xa9059cbb";
11
+ const paddedRecipient = recipient.slice(2).padStart(64, "0");
12
+ const paddedAmount = BigInt(amount).toString(16).padStart(64, "0");
13
+ return selector + paddedRecipient + paddedAmount;
14
+ }
15
+ encodeTransferFrom(from, to, amount) {
16
+ const selector = "0x23b872dd";
17
+ const paddedFrom = from.slice(2).padStart(64, "0");
18
+ const paddedTo = to.slice(2).padStart(64, "0");
19
+ const paddedAmount = BigInt(amount).toString(16).padStart(64, "0");
20
+ return selector + paddedFrom + paddedTo + paddedAmount;
21
+ }
22
+ encodeBalancePayload(tokenAddress, balanceSlot) {
23
+ const paddedAddress = tokenAddress.slice(2).padStart(64, "0");
24
+ const paddedSlot = BigInt(balanceSlot).toString(16).padStart(64, "0");
25
+ return "0x" + paddedAddress + paddedSlot;
26
+ }
27
+ }
28
+ const abiCoder = new ABICoder();
29
+ export function approve(tokenAddress, spender, amount) {
30
+ return {
31
+ callType: ContractCallType.DEFAULT,
32
+ target: tokenAddress,
33
+ value: "0",
34
+ callData: abiCoder.encodeApprove(spender, amount),
35
+ payload: "0x",
36
+ };
37
+ }
38
+ export function transfer(tokenAddress, recipient, amount) {
39
+ return {
40
+ callType: ContractCallType.DEFAULT,
41
+ target: tokenAddress,
42
+ value: "0",
43
+ callData: abiCoder.encodeTransfer(recipient, amount),
44
+ payload: "0x",
45
+ };
46
+ }
47
+ export function transferFrom(tokenAddress, from, to, amount) {
48
+ return {
49
+ callType: ContractCallType.DEFAULT,
50
+ target: tokenAddress,
51
+ value: "0",
52
+ callData: abiCoder.encodeTransferFrom(from, to, amount),
53
+ payload: "0x",
54
+ };
55
+ }
56
+ export function approveBalance(tokenAddress, spender) {
57
+ return {
58
+ callType: ContractCallType.FULL_TOKEN_BALANCE,
59
+ target: tokenAddress,
60
+ value: "0",
61
+ callData: abiCoder.encodeApprove(spender, "0"),
62
+ payload: abiCoder.encodeBalancePayload(tokenAddress, "1"),
63
+ };
64
+ }
65
+ export function transferBalance(tokenAddress, recipient) {
66
+ return {
67
+ callType: ContractCallType.FULL_TOKEN_BALANCE,
68
+ target: tokenAddress,
69
+ value: "0",
70
+ callData: abiCoder.encodeTransfer(recipient, "0"),
71
+ payload: abiCoder.encodeBalancePayload(tokenAddress, "1"),
72
+ };
73
+ }
74
+ //# sourceMappingURL=helpers.js.map
package/dist/index.js CHANGED
@@ -1 +1,7 @@
1
- export{SwapperIframe}from"./SwapperIframe";export{SwapperModal,openSwapperModal}from"./SwapperModal";export{SwapperWalletProvider}from"./SwapperWalletProvider";export{ContractCallType,SWAPPER_WALLET_MSGS}from"./types";export{approve,transfer,transferFrom,approveBalance,transferBalance}from"./helpers";export{createSwapperSigner,EthersV5SignerAdapter,EthersV6SignerAdapter,ViemSignerAdapter}from"./adapters";
1
+ export { SwapperIframe } from "./SwapperIframe";
2
+ export { SwapperModal, openSwapperModal } from "./SwapperModal";
3
+ export { SwapperWalletProvider } from "./SwapperWalletProvider";
4
+ export { ContractCallType, SWAPPER_WALLET_MSGS, } from "./types";
5
+ export { approve, transfer, transferFrom, approveBalance, transferBalance, } from "./helpers";
6
+ export { createSwapperSigner, EthersV5SignerAdapter, EthersV6SignerAdapter, ViemSignerAdapter, } from "./adapters";
7
+ //# sourceMappingURL=index.js.map
@@ -1 +1,8 @@
1
- export var ContractCallType;!function(L){L[L.DEFAULT=0]="DEFAULT",L[L.FULL_TOKEN_BALANCE=1]="FULL_TOKEN_BALANCE",L[L.FULL_NATIVE_BALANCE=2]="FULL_NATIVE_BALANCE",L[L.COLLECT_TOKEN_BALANCE=3]="COLLECT_TOKEN_BALANCE"}(ContractCallType||(ContractCallType={}));
1
+ export var ContractCallType;
2
+ (function (ContractCallType) {
3
+ ContractCallType[ContractCallType["DEFAULT"] = 0] = "DEFAULT";
4
+ ContractCallType[ContractCallType["FULL_TOKEN_BALANCE"] = 1] = "FULL_TOKEN_BALANCE";
5
+ ContractCallType[ContractCallType["FULL_NATIVE_BALANCE"] = 2] = "FULL_NATIVE_BALANCE";
6
+ ContractCallType[ContractCallType["COLLECT_TOKEN_BALANCE"] = 3] = "COLLECT_TOKEN_BALANCE";
7
+ })(ContractCallType || (ContractCallType = {}));
8
+ //# sourceMappingURL=config.js.map
@@ -1 +1,2 @@
1
- export{};
1
+ export {};
2
+ //# sourceMappingURL=events.js.map
@@ -1 +1,5 @@
1
- export*from"./styles";export*from"./config";export*from"./events";export*from"./wallet";
1
+ export * from "./styles";
2
+ export * from "./config";
3
+ export * from "./events";
4
+ export * from "./wallet";
5
+ //# sourceMappingURL=index.js.map
@@ -1 +1,2 @@
1
- export{};
1
+ export {};
2
+ //# sourceMappingURL=styles.js.map
@@ -1 +1,11 @@
1
- export const SWAPPER_WALLET_MSGS={WALLET_READY:"SWAPPER_WALLET_READY",WALLET_CONNECT:"SWAPPER_WALLET_CONNECT",WALLET_DISCONNECT:"SWAPPER_WALLET_DISCONNECT",WALLET_CHAIN_CHANGED:"SWAPPER_WALLET_CHAIN_CHANGED",TX_REQUEST:"SWAPPER_TX_REQUEST",TX_RESPONSE:"SWAPPER_TX_RESPONSE",CHAIN_SWITCH_REQUEST:"SWAPPER_CHAIN_SWITCH_REQUEST",CHAIN_SWITCH_RESPONSE:"SWAPPER_CHAIN_SWITCH_RESPONSE"};
1
+ export const SWAPPER_WALLET_MSGS = {
2
+ WALLET_READY: "SWAPPER_WALLET_READY",
3
+ WALLET_CONNECT: "SWAPPER_WALLET_CONNECT",
4
+ WALLET_DISCONNECT: "SWAPPER_WALLET_DISCONNECT",
5
+ WALLET_CHAIN_CHANGED: "SWAPPER_WALLET_CHAIN_CHANGED",
6
+ TX_REQUEST: "SWAPPER_TX_REQUEST",
7
+ TX_RESPONSE: "SWAPPER_TX_RESPONSE",
8
+ CHAIN_SWITCH_REQUEST: "SWAPPER_CHAIN_SWITCH_REQUEST",
9
+ CHAIN_SWITCH_RESPONSE: "SWAPPER_CHAIN_SWITCH_RESPONSE",
10
+ };
11
+ //# sourceMappingURL=wallet.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swapper-finance/deposit-sdk",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Easy iframe embedding for Swapper deposit widget with full TypeScript support",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -12,8 +12,7 @@
12
12
  "LICENSE"
13
13
  ],
14
14
  "scripts": {
15
- "build": "tsc && npm run minify",
16
- "minify": "find dist -name '*.js' -exec terser {} -o {} --compress --mangle \\;",
15
+ "build": "tsc",
17
16
  "prepare": "npm run build",
18
17
  "clean": "rm -rf dist",
19
18
  "watch": "tsc --watch",
package/dist/types.d.ts DELETED
@@ -1,53 +0,0 @@
1
- export type ThemeMode = "light" | "dark";
2
- export interface ComponentStyles {
3
- primaryColor?: string;
4
- primaryBorderColor?: string;
5
- accentColor?: string;
6
- primaryTextColor?: string;
7
- }
8
- export interface SwapperStyles {
9
- themeMode?: ThemeMode;
10
- componentStyles?: ComponentStyles;
11
- }
12
- export type SupportedDepositOption = "transferCrypto" | "depositWithCash" | "walletDeposit";
13
- export declare enum ContractCallType {
14
- DEFAULT = 0,
15
- FULL_TOKEN_BALANCE = 1,
16
- FULL_NATIVE_BALANCE = 2,
17
- COLLECT_TOKEN_BALANCE = 3
18
- }
19
- export interface ContractCall {
20
- callType: ContractCallType;
21
- target: string;
22
- value: string;
23
- callData: string;
24
- payload: string;
25
- }
26
- export interface SwapperConfig {
27
- integratorId: string;
28
- dstChainId: string;
29
- dstTokenAddr: string;
30
- depositWalletAddress: string;
31
- styles?: SwapperStyles;
32
- customContractCalls?: ContractCall[];
33
- supportedDepositOptions?: SupportedDepositOption[];
34
- webhookUrl?: string;
35
- }
36
- export interface SwapperIframeOptions extends SwapperConfig {
37
- container?: HTMLElement | string;
38
- iframeUrl?: string;
39
- iframeAttributes?: {
40
- width?: string;
41
- height?: string;
42
- title?: string;
43
- allow?: string;
44
- sandbox?: string;
45
- [key: string]: string | undefined;
46
- };
47
- }
48
- export interface SwapperEvent {
49
- type: string;
50
- data?: unknown;
51
- }
52
- export type SwapperEventHandler = (event: SwapperEvent) => void;
53
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.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EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;KACnC,CAAC;CACH;AAKD,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAKD,MAAM,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC"}
package/dist/types.js DELETED
@@ -1 +0,0 @@
1
- export var ContractCallType;!function(L){L[L.DEFAULT=0]="DEFAULT",L[L.FULL_TOKEN_BALANCE=1]="FULL_TOKEN_BALANCE",L[L.FULL_NATIVE_BALANCE=2]="FULL_NATIVE_BALANCE",L[L.COLLECT_TOKEN_BALANCE=3]="COLLECT_TOKEN_BALANCE"}(ContractCallType||(ContractCallType={}));
package/dist/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAyCA,MAAM,CAAN,IAAY,gBAKX;AALD,WAAY,gBAAgB;IAC1B,6DAAW,CAAA;IACX,mFAAsB,CAAA;IACtB,qFAAuB,CAAA;IACvB,yFAAyB,CAAA;AAC3B,CAAC,EALW,gBAAgB,KAAhB,gBAAgB,QAK3B"}