@rhinestone/deposit-modal 0.2.3 → 0.2.5-alpha.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/dist/{DepositModalReown-SJHEU6RQ.mjs → DepositModalReown-GIODYNOK.mjs} +5 -3
- package/dist/{DepositModalReown-QPJ5TT57.cjs → DepositModalReown-SVVA3OZ6.cjs} +6 -4
- package/dist/{WithdrawModalReown-RUJZCQ4C.mjs → WithdrawModalReown-HTEB4XGU.mjs} +4 -3
- package/dist/{WithdrawModalReown-KGKKBTC7.cjs → WithdrawModalReown-VNTKGALT.cjs} +5 -4
- package/dist/{chunk-5EU7N73M.cjs → chunk-4S262VLP.cjs} +83 -367
- package/dist/{chunk-TYJEZX6S.cjs → chunk-AHQY2O3U.cjs} +595 -323
- package/dist/{chunk-JRNGXHWQ.mjs → chunk-DUGDAMAF.mjs} +135 -133
- package/dist/chunk-J2SWZSXL.mjs +295 -0
- package/dist/{chunk-T2KOQH57.cjs → chunk-KE6CJVOV.cjs} +109 -107
- package/dist/chunk-LHOHM67Z.mjs +234 -0
- package/dist/{chunk-MUWVDVY4.cjs → chunk-R2HP743T.cjs} +14 -1
- package/dist/{chunk-DGT2DZXN.mjs → chunk-RQ2VCKLS.mjs} +452 -180
- package/dist/{chunk-MKO5TNVQ.mjs → chunk-WA4RA4HB.mjs} +15 -299
- package/dist/{chunk-SDZKKUCJ.mjs → chunk-WHW3ZMOT.mjs} +14 -1
- package/dist/chunk-YKGL66EF.cjs +295 -0
- package/dist/chunk-ZHLQMSQM.cjs +234 -0
- package/dist/constants.cjs +2 -2
- package/dist/constants.mjs +1 -1
- package/dist/deposit.cjs +6 -4
- package/dist/deposit.d.cts +3 -3
- package/dist/deposit.d.ts +3 -3
- package/dist/deposit.mjs +5 -3
- package/dist/index.cjs +7 -5
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +6 -4
- package/dist/reown.cjs +7 -5
- package/dist/reown.d.cts +2 -2
- package/dist/reown.d.ts +2 -2
- package/dist/reown.mjs +6 -4
- package/dist/safe-CB7TvRCc.d.cts +62 -0
- package/dist/safe-CB7TvRCc.d.ts +62 -0
- package/dist/safe.cjs +22 -1
- package/dist/safe.d.cts +11 -59
- package/dist/safe.d.ts +11 -59
- package/dist/safe.mjs +22 -0
- package/dist/{types-DGQzvl6v.d.ts → types-CeFbJ-MW.d.ts} +8 -1
- package/dist/{types-DJ1fzNC7.d.cts → types-D0NawmZ8.d.cts} +8 -1
- package/dist/withdraw.cjs +5 -4
- package/dist/withdraw.d.cts +3 -3
- package/dist/withdraw.d.ts +3 -3
- package/dist/withdraw.mjs +4 -3
- package/package.json +1 -1
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getChainName
|
|
3
|
+
} from "./chunk-WHW3ZMOT.mjs";
|
|
4
|
+
|
|
5
|
+
// src/core/safe.ts
|
|
6
|
+
import {
|
|
7
|
+
concat,
|
|
8
|
+
encodeFunctionData,
|
|
9
|
+
erc20Abi,
|
|
10
|
+
hashTypedData,
|
|
11
|
+
pad,
|
|
12
|
+
parseEventLogs,
|
|
13
|
+
toHex,
|
|
14
|
+
zeroAddress
|
|
15
|
+
} from "viem";
|
|
16
|
+
var SAFE_ABI = [
|
|
17
|
+
{
|
|
18
|
+
type: "function",
|
|
19
|
+
name: "isOwner",
|
|
20
|
+
stateMutability: "view",
|
|
21
|
+
inputs: [{ name: "owner", type: "address" }],
|
|
22
|
+
outputs: [{ name: "", type: "bool" }]
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
type: "function",
|
|
26
|
+
name: "nonce",
|
|
27
|
+
stateMutability: "view",
|
|
28
|
+
inputs: [],
|
|
29
|
+
outputs: [{ type: "uint256" }]
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
type: "function",
|
|
33
|
+
name: "execTransaction",
|
|
34
|
+
stateMutability: "payable",
|
|
35
|
+
inputs: [
|
|
36
|
+
{ name: "to", type: "address" },
|
|
37
|
+
{ name: "value", type: "uint256" },
|
|
38
|
+
{ name: "data", type: "bytes" },
|
|
39
|
+
{ name: "operation", type: "uint8" },
|
|
40
|
+
{ name: "safeTxGas", type: "uint256" },
|
|
41
|
+
{ name: "baseGas", type: "uint256" },
|
|
42
|
+
{ name: "gasPrice", type: "uint256" },
|
|
43
|
+
{ name: "gasToken", type: "address" },
|
|
44
|
+
{ name: "refundReceiver", type: "address" },
|
|
45
|
+
{ name: "signatures", type: "bytes" }
|
|
46
|
+
],
|
|
47
|
+
outputs: [{ name: "success", type: "bool" }]
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
type: "event",
|
|
51
|
+
name: "ExecutionSuccess",
|
|
52
|
+
inputs: [
|
|
53
|
+
{ name: "txHash", type: "bytes32", indexed: true },
|
|
54
|
+
{ name: "payment", type: "uint256", indexed: false }
|
|
55
|
+
],
|
|
56
|
+
anonymous: false
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
type: "event",
|
|
60
|
+
name: "ExecutionFailure",
|
|
61
|
+
inputs: [
|
|
62
|
+
{ name: "txHash", type: "bytes32", indexed: true },
|
|
63
|
+
{ name: "payment", type: "uint256", indexed: false }
|
|
64
|
+
],
|
|
65
|
+
anonymous: false
|
|
66
|
+
}
|
|
67
|
+
];
|
|
68
|
+
async function executeSafeEthTransfer(params) {
|
|
69
|
+
const {
|
|
70
|
+
walletClient,
|
|
71
|
+
publicClient,
|
|
72
|
+
safeAddress,
|
|
73
|
+
recipient,
|
|
74
|
+
amount,
|
|
75
|
+
chainId
|
|
76
|
+
} = params;
|
|
77
|
+
const account = walletClient.account;
|
|
78
|
+
const chain = walletClient.chain;
|
|
79
|
+
if (!account || !chain) {
|
|
80
|
+
throw new Error("Wallet not connected");
|
|
81
|
+
}
|
|
82
|
+
if (chain.id !== chainId) {
|
|
83
|
+
throw new Error(`Switch to ${getChainName(chainId)} to sign`);
|
|
84
|
+
}
|
|
85
|
+
const isOwner = await publicClient.readContract({
|
|
86
|
+
address: safeAddress,
|
|
87
|
+
abi: SAFE_ABI,
|
|
88
|
+
functionName: "isOwner",
|
|
89
|
+
args: [account.address]
|
|
90
|
+
});
|
|
91
|
+
if (!isOwner) {
|
|
92
|
+
throw new Error("Connected wallet is not a Safe owner");
|
|
93
|
+
}
|
|
94
|
+
const safeTx = {
|
|
95
|
+
to: recipient,
|
|
96
|
+
value: amount,
|
|
97
|
+
data: "0x",
|
|
98
|
+
operation: 0,
|
|
99
|
+
safeTxGas: 0n,
|
|
100
|
+
baseGas: 0n,
|
|
101
|
+
gasPrice: 0n,
|
|
102
|
+
gasToken: zeroAddress,
|
|
103
|
+
refundReceiver: zeroAddress
|
|
104
|
+
};
|
|
105
|
+
const signature = concat([
|
|
106
|
+
pad(account.address, { size: 32 }),
|
|
107
|
+
pad(toHex(0), { size: 32 }),
|
|
108
|
+
toHex(1, { size: 1 })
|
|
109
|
+
]);
|
|
110
|
+
const txHash = await walletClient.writeContract({
|
|
111
|
+
account,
|
|
112
|
+
chain,
|
|
113
|
+
address: safeAddress,
|
|
114
|
+
abi: SAFE_ABI,
|
|
115
|
+
functionName: "execTransaction",
|
|
116
|
+
args: [
|
|
117
|
+
safeTx.to,
|
|
118
|
+
safeTx.value,
|
|
119
|
+
safeTx.data,
|
|
120
|
+
safeTx.operation,
|
|
121
|
+
safeTx.safeTxGas,
|
|
122
|
+
safeTx.baseGas,
|
|
123
|
+
safeTx.gasPrice,
|
|
124
|
+
safeTx.gasToken,
|
|
125
|
+
safeTx.refundReceiver,
|
|
126
|
+
signature
|
|
127
|
+
]
|
|
128
|
+
});
|
|
129
|
+
const receipt = await publicClient.waitForTransactionReceipt({
|
|
130
|
+
hash: txHash
|
|
131
|
+
});
|
|
132
|
+
const safeLogs = receipt.logs.filter(
|
|
133
|
+
(log) => log.address.toLowerCase() === safeAddress.toLowerCase()
|
|
134
|
+
);
|
|
135
|
+
const parsed = parseEventLogs({
|
|
136
|
+
abi: SAFE_ABI,
|
|
137
|
+
logs: safeLogs,
|
|
138
|
+
strict: false
|
|
139
|
+
});
|
|
140
|
+
const failed = parsed.find((log) => log.eventName === "ExecutionFailure");
|
|
141
|
+
if (failed) {
|
|
142
|
+
throw new Error("Safe transaction failed");
|
|
143
|
+
}
|
|
144
|
+
const succeeded = parsed.find((log) => log.eventName === "ExecutionSuccess");
|
|
145
|
+
if (!succeeded) {
|
|
146
|
+
throw new Error("Safe transaction status unavailable");
|
|
147
|
+
}
|
|
148
|
+
return { txHash };
|
|
149
|
+
}
|
|
150
|
+
async function executeSafeErc20Transfer(params) {
|
|
151
|
+
const {
|
|
152
|
+
walletClient,
|
|
153
|
+
publicClient,
|
|
154
|
+
safeAddress,
|
|
155
|
+
tokenAddress,
|
|
156
|
+
recipient,
|
|
157
|
+
amount,
|
|
158
|
+
chainId
|
|
159
|
+
} = params;
|
|
160
|
+
const account = walletClient.account;
|
|
161
|
+
const chain = walletClient.chain;
|
|
162
|
+
if (!account || !chain) {
|
|
163
|
+
throw new Error("Wallet not connected");
|
|
164
|
+
}
|
|
165
|
+
if (chain.id !== chainId) {
|
|
166
|
+
throw new Error(`Switch to ${getChainName(chainId)} to sign`);
|
|
167
|
+
}
|
|
168
|
+
const isOwner = await publicClient.readContract({
|
|
169
|
+
address: safeAddress,
|
|
170
|
+
abi: SAFE_ABI,
|
|
171
|
+
functionName: "isOwner",
|
|
172
|
+
args: [account.address]
|
|
173
|
+
});
|
|
174
|
+
if (!isOwner) {
|
|
175
|
+
throw new Error("Connected wallet is not a Safe owner");
|
|
176
|
+
}
|
|
177
|
+
const data = encodeFunctionData({
|
|
178
|
+
abi: erc20Abi,
|
|
179
|
+
functionName: "transfer",
|
|
180
|
+
args: [recipient, amount]
|
|
181
|
+
});
|
|
182
|
+
const safeTx = {
|
|
183
|
+
to: tokenAddress,
|
|
184
|
+
value: 0n,
|
|
185
|
+
data,
|
|
186
|
+
operation: 0,
|
|
187
|
+
safeTxGas: 0n,
|
|
188
|
+
baseGas: 0n,
|
|
189
|
+
gasPrice: 0n,
|
|
190
|
+
gasToken: zeroAddress,
|
|
191
|
+
refundReceiver: zeroAddress
|
|
192
|
+
};
|
|
193
|
+
const signature = concat([
|
|
194
|
+
pad(account.address, { size: 32 }),
|
|
195
|
+
pad(toHex(0), { size: 32 }),
|
|
196
|
+
toHex(1, { size: 1 })
|
|
197
|
+
]);
|
|
198
|
+
const txHash = await walletClient.writeContract({
|
|
199
|
+
account,
|
|
200
|
+
chain,
|
|
201
|
+
address: safeAddress,
|
|
202
|
+
abi: SAFE_ABI,
|
|
203
|
+
functionName: "execTransaction",
|
|
204
|
+
args: [
|
|
205
|
+
safeTx.to,
|
|
206
|
+
safeTx.value,
|
|
207
|
+
safeTx.data,
|
|
208
|
+
safeTx.operation,
|
|
209
|
+
safeTx.safeTxGas,
|
|
210
|
+
safeTx.baseGas,
|
|
211
|
+
safeTx.gasPrice,
|
|
212
|
+
safeTx.gasToken,
|
|
213
|
+
safeTx.refundReceiver,
|
|
214
|
+
signature
|
|
215
|
+
]
|
|
216
|
+
});
|
|
217
|
+
const receipt = await publicClient.waitForTransactionReceipt({
|
|
218
|
+
hash: txHash
|
|
219
|
+
});
|
|
220
|
+
const safeLogs = receipt.logs.filter(
|
|
221
|
+
(log) => log.address.toLowerCase() === safeAddress.toLowerCase()
|
|
222
|
+
);
|
|
223
|
+
const parsed = parseEventLogs({
|
|
224
|
+
abi: SAFE_ABI,
|
|
225
|
+
logs: safeLogs,
|
|
226
|
+
strict: false
|
|
227
|
+
});
|
|
228
|
+
const failed = parsed.find((log) => log.eventName === "ExecutionFailure");
|
|
229
|
+
if (failed) {
|
|
230
|
+
throw new Error("Safe transaction failed");
|
|
231
|
+
}
|
|
232
|
+
const succeeded = parsed.find((log) => log.eventName === "ExecutionSuccess");
|
|
233
|
+
if (!succeeded) {
|
|
234
|
+
throw new Error("Safe transaction status unavailable");
|
|
235
|
+
}
|
|
236
|
+
return { txHash };
|
|
237
|
+
}
|
|
238
|
+
var SAFE_TX_TYPES = {
|
|
239
|
+
SafeTx: [
|
|
240
|
+
{ name: "to", type: "address" },
|
|
241
|
+
{ name: "value", type: "uint256" },
|
|
242
|
+
{ name: "data", type: "bytes" },
|
|
243
|
+
{ name: "operation", type: "uint8" },
|
|
244
|
+
{ name: "safeTxGas", type: "uint256" },
|
|
245
|
+
{ name: "baseGas", type: "uint256" },
|
|
246
|
+
{ name: "gasPrice", type: "uint256" },
|
|
247
|
+
{ name: "gasToken", type: "address" },
|
|
248
|
+
{ name: "refundReceiver", type: "address" },
|
|
249
|
+
{ name: "nonce", type: "uint256" }
|
|
250
|
+
]
|
|
251
|
+
};
|
|
252
|
+
async function buildSafeTransaction(params) {
|
|
253
|
+
const { publicClient, safeAddress, to, value, data, chainId } = params;
|
|
254
|
+
const nonce = await publicClient.readContract({
|
|
255
|
+
address: safeAddress,
|
|
256
|
+
abi: SAFE_ABI,
|
|
257
|
+
functionName: "nonce"
|
|
258
|
+
});
|
|
259
|
+
const message = {
|
|
260
|
+
to,
|
|
261
|
+
value,
|
|
262
|
+
data,
|
|
263
|
+
operation: 0,
|
|
264
|
+
safeTxGas: 0n,
|
|
265
|
+
baseGas: 0n,
|
|
266
|
+
gasPrice: 0n,
|
|
267
|
+
gasToken: zeroAddress,
|
|
268
|
+
refundReceiver: zeroAddress,
|
|
269
|
+
nonce
|
|
270
|
+
};
|
|
271
|
+
const safeTxHash = hashTypedData({
|
|
272
|
+
domain: { chainId, verifyingContract: safeAddress },
|
|
273
|
+
types: SAFE_TX_TYPES,
|
|
274
|
+
primaryType: "SafeTx",
|
|
275
|
+
message
|
|
276
|
+
});
|
|
277
|
+
return {
|
|
278
|
+
chainId,
|
|
279
|
+
safeAddress,
|
|
280
|
+
safeTxHash,
|
|
281
|
+
typedData: {
|
|
282
|
+
domain: { chainId, verifyingContract: safeAddress },
|
|
283
|
+
types: SAFE_TX_TYPES,
|
|
284
|
+
primaryType: "SafeTx",
|
|
285
|
+
message
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export {
|
|
291
|
+
SAFE_ABI,
|
|
292
|
+
executeSafeEthTransfer,
|
|
293
|
+
executeSafeErc20Transfer,
|
|
294
|
+
buildSafeTransaction
|
|
295
|
+
};
|