@rhinestone/deposit-modal 0.2.4 → 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-CY5MSQGK.mjs → DepositModalReown-GIODYNOK.mjs} +4 -2
- package/dist/{DepositModalReown-2UMPITRN.cjs → DepositModalReown-SVVA3OZ6.cjs} +5 -3
- package/dist/{WithdrawModalReown-YSRO5ZTA.mjs → WithdrawModalReown-HTEB4XGU.mjs} +3 -2
- package/dist/{WithdrawModalReown-Z5BUZQ4Z.cjs → WithdrawModalReown-VNTKGALT.cjs} +4 -3
- package/dist/{chunk-QUOP5C6V.cjs → chunk-4S262VLP.cjs} +54 -338
- package/dist/{chunk-ARGMXV6E.cjs → chunk-AHQY2O3U.cjs} +507 -235
- package/dist/{chunk-WNFGZS56.mjs → chunk-DUGDAMAF.mjs} +134 -132
- package/dist/chunk-J2SWZSXL.mjs +295 -0
- package/dist/{chunk-NFXJEOE6.cjs → chunk-KE6CJVOV.cjs} +88 -86
- package/dist/chunk-LHOHM67Z.mjs +234 -0
- package/dist/{chunk-HFQV7EHS.mjs → chunk-RQ2VCKLS.mjs} +451 -179
- package/dist/{chunk-KJEHVIPZ.mjs → chunk-WA4RA4HB.mjs} +14 -298
- package/dist/chunk-YKGL66EF.cjs +295 -0
- package/dist/chunk-ZHLQMSQM.cjs +234 -0
- package/dist/deposit.cjs +5 -3
- package/dist/deposit.d.cts +3 -3
- package/dist/deposit.d.ts +3 -3
- package/dist/deposit.mjs +4 -2
- package/dist/index.cjs +6 -4
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +5 -3
- package/dist/reown.cjs +6 -4
- package/dist/reown.d.cts +2 -2
- package/dist/reown.d.ts +2 -2
- package/dist/reown.mjs +5 -3
- 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 +4 -3
- package/dist/withdraw.d.cts +3 -3
- package/dist/withdraw.d.ts +3 -3
- package/dist/withdraw.mjs +3 -2
- package/package.json +1 -1
|
@@ -21,7 +21,12 @@ import {
|
|
|
21
21
|
saveSessionOwnerToStorage,
|
|
22
22
|
toEvmCaip2,
|
|
23
23
|
useLatestRef
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-DUGDAMAF.mjs";
|
|
25
|
+
import {
|
|
26
|
+
buildSafeTransaction,
|
|
27
|
+
executeSafeErc20Transfer,
|
|
28
|
+
executeSafeEthTransfer
|
|
29
|
+
} from "./chunk-J2SWZSXL.mjs";
|
|
25
30
|
import {
|
|
26
31
|
DEFAULT_BACKEND_URL,
|
|
27
32
|
DEFAULT_SIGNER_ADDRESS,
|
|
@@ -569,293 +574,8 @@ function WithdrawFormStep({
|
|
|
569
574
|
}
|
|
570
575
|
WithdrawFormStep.displayName = "WithdrawFormStep";
|
|
571
576
|
|
|
572
|
-
// src/core/safe.ts
|
|
573
|
-
import {
|
|
574
|
-
concat,
|
|
575
|
-
encodeFunctionData,
|
|
576
|
-
erc20Abi as erc20Abi2,
|
|
577
|
-
hashTypedData,
|
|
578
|
-
pad,
|
|
579
|
-
parseEventLogs,
|
|
580
|
-
toHex,
|
|
581
|
-
zeroAddress
|
|
582
|
-
} from "viem";
|
|
583
|
-
var SAFE_ABI = [
|
|
584
|
-
{
|
|
585
|
-
type: "function",
|
|
586
|
-
name: "isOwner",
|
|
587
|
-
stateMutability: "view",
|
|
588
|
-
inputs: [{ name: "owner", type: "address" }],
|
|
589
|
-
outputs: [{ name: "", type: "bool" }]
|
|
590
|
-
},
|
|
591
|
-
{
|
|
592
|
-
type: "function",
|
|
593
|
-
name: "nonce",
|
|
594
|
-
stateMutability: "view",
|
|
595
|
-
inputs: [],
|
|
596
|
-
outputs: [{ type: "uint256" }]
|
|
597
|
-
},
|
|
598
|
-
{
|
|
599
|
-
type: "function",
|
|
600
|
-
name: "execTransaction",
|
|
601
|
-
stateMutability: "payable",
|
|
602
|
-
inputs: [
|
|
603
|
-
{ name: "to", type: "address" },
|
|
604
|
-
{ name: "value", type: "uint256" },
|
|
605
|
-
{ name: "data", type: "bytes" },
|
|
606
|
-
{ name: "operation", type: "uint8" },
|
|
607
|
-
{ name: "safeTxGas", type: "uint256" },
|
|
608
|
-
{ name: "baseGas", type: "uint256" },
|
|
609
|
-
{ name: "gasPrice", type: "uint256" },
|
|
610
|
-
{ name: "gasToken", type: "address" },
|
|
611
|
-
{ name: "refundReceiver", type: "address" },
|
|
612
|
-
{ name: "signatures", type: "bytes" }
|
|
613
|
-
],
|
|
614
|
-
outputs: [{ name: "success", type: "bool" }]
|
|
615
|
-
},
|
|
616
|
-
{
|
|
617
|
-
type: "event",
|
|
618
|
-
name: "ExecutionSuccess",
|
|
619
|
-
inputs: [
|
|
620
|
-
{ name: "txHash", type: "bytes32", indexed: true },
|
|
621
|
-
{ name: "payment", type: "uint256", indexed: false }
|
|
622
|
-
],
|
|
623
|
-
anonymous: false
|
|
624
|
-
},
|
|
625
|
-
{
|
|
626
|
-
type: "event",
|
|
627
|
-
name: "ExecutionFailure",
|
|
628
|
-
inputs: [
|
|
629
|
-
{ name: "txHash", type: "bytes32", indexed: true },
|
|
630
|
-
{ name: "payment", type: "uint256", indexed: false }
|
|
631
|
-
],
|
|
632
|
-
anonymous: false
|
|
633
|
-
}
|
|
634
|
-
];
|
|
635
|
-
async function executeSafeEthTransfer(params) {
|
|
636
|
-
const {
|
|
637
|
-
walletClient,
|
|
638
|
-
publicClient,
|
|
639
|
-
safeAddress,
|
|
640
|
-
recipient,
|
|
641
|
-
amount,
|
|
642
|
-
chainId
|
|
643
|
-
} = params;
|
|
644
|
-
const account = walletClient.account;
|
|
645
|
-
const chain = walletClient.chain;
|
|
646
|
-
if (!account || !chain) {
|
|
647
|
-
throw new Error("Wallet not connected");
|
|
648
|
-
}
|
|
649
|
-
if (chain.id !== chainId) {
|
|
650
|
-
throw new Error(`Switch to ${getChainName(chainId)} to sign`);
|
|
651
|
-
}
|
|
652
|
-
const isOwner = await publicClient.readContract({
|
|
653
|
-
address: safeAddress,
|
|
654
|
-
abi: SAFE_ABI,
|
|
655
|
-
functionName: "isOwner",
|
|
656
|
-
args: [account.address]
|
|
657
|
-
});
|
|
658
|
-
if (!isOwner) {
|
|
659
|
-
throw new Error("Connected wallet is not a Safe owner");
|
|
660
|
-
}
|
|
661
|
-
const safeTx = {
|
|
662
|
-
to: recipient,
|
|
663
|
-
value: amount,
|
|
664
|
-
data: "0x",
|
|
665
|
-
operation: 0,
|
|
666
|
-
safeTxGas: 0n,
|
|
667
|
-
baseGas: 0n,
|
|
668
|
-
gasPrice: 0n,
|
|
669
|
-
gasToken: zeroAddress,
|
|
670
|
-
refundReceiver: zeroAddress
|
|
671
|
-
};
|
|
672
|
-
const signature = concat([
|
|
673
|
-
pad(account.address, { size: 32 }),
|
|
674
|
-
pad(toHex(0), { size: 32 }),
|
|
675
|
-
toHex(1, { size: 1 })
|
|
676
|
-
]);
|
|
677
|
-
const txHash = await walletClient.writeContract({
|
|
678
|
-
account,
|
|
679
|
-
chain,
|
|
680
|
-
address: safeAddress,
|
|
681
|
-
abi: SAFE_ABI,
|
|
682
|
-
functionName: "execTransaction",
|
|
683
|
-
args: [
|
|
684
|
-
safeTx.to,
|
|
685
|
-
safeTx.value,
|
|
686
|
-
safeTx.data,
|
|
687
|
-
safeTx.operation,
|
|
688
|
-
safeTx.safeTxGas,
|
|
689
|
-
safeTx.baseGas,
|
|
690
|
-
safeTx.gasPrice,
|
|
691
|
-
safeTx.gasToken,
|
|
692
|
-
safeTx.refundReceiver,
|
|
693
|
-
signature
|
|
694
|
-
]
|
|
695
|
-
});
|
|
696
|
-
const receipt = await publicClient.waitForTransactionReceipt({
|
|
697
|
-
hash: txHash
|
|
698
|
-
});
|
|
699
|
-
const safeLogs = receipt.logs.filter(
|
|
700
|
-
(log) => log.address.toLowerCase() === safeAddress.toLowerCase()
|
|
701
|
-
);
|
|
702
|
-
const parsed = parseEventLogs({
|
|
703
|
-
abi: SAFE_ABI,
|
|
704
|
-
logs: safeLogs,
|
|
705
|
-
strict: false
|
|
706
|
-
});
|
|
707
|
-
const failed = parsed.find((log) => log.eventName === "ExecutionFailure");
|
|
708
|
-
if (failed) {
|
|
709
|
-
throw new Error("Safe transaction failed");
|
|
710
|
-
}
|
|
711
|
-
const succeeded = parsed.find((log) => log.eventName === "ExecutionSuccess");
|
|
712
|
-
if (!succeeded) {
|
|
713
|
-
throw new Error("Safe transaction status unavailable");
|
|
714
|
-
}
|
|
715
|
-
return { txHash };
|
|
716
|
-
}
|
|
717
|
-
async function executeSafeErc20Transfer(params) {
|
|
718
|
-
const {
|
|
719
|
-
walletClient,
|
|
720
|
-
publicClient,
|
|
721
|
-
safeAddress,
|
|
722
|
-
tokenAddress,
|
|
723
|
-
recipient,
|
|
724
|
-
amount,
|
|
725
|
-
chainId
|
|
726
|
-
} = params;
|
|
727
|
-
const account = walletClient.account;
|
|
728
|
-
const chain = walletClient.chain;
|
|
729
|
-
if (!account || !chain) {
|
|
730
|
-
throw new Error("Wallet not connected");
|
|
731
|
-
}
|
|
732
|
-
if (chain.id !== chainId) {
|
|
733
|
-
throw new Error(`Switch to ${getChainName(chainId)} to sign`);
|
|
734
|
-
}
|
|
735
|
-
const isOwner = await publicClient.readContract({
|
|
736
|
-
address: safeAddress,
|
|
737
|
-
abi: SAFE_ABI,
|
|
738
|
-
functionName: "isOwner",
|
|
739
|
-
args: [account.address]
|
|
740
|
-
});
|
|
741
|
-
if (!isOwner) {
|
|
742
|
-
throw new Error("Connected wallet is not a Safe owner");
|
|
743
|
-
}
|
|
744
|
-
const data = encodeFunctionData({
|
|
745
|
-
abi: erc20Abi2,
|
|
746
|
-
functionName: "transfer",
|
|
747
|
-
args: [recipient, amount]
|
|
748
|
-
});
|
|
749
|
-
const safeTx = {
|
|
750
|
-
to: tokenAddress,
|
|
751
|
-
value: 0n,
|
|
752
|
-
data,
|
|
753
|
-
operation: 0,
|
|
754
|
-
safeTxGas: 0n,
|
|
755
|
-
baseGas: 0n,
|
|
756
|
-
gasPrice: 0n,
|
|
757
|
-
gasToken: zeroAddress,
|
|
758
|
-
refundReceiver: zeroAddress
|
|
759
|
-
};
|
|
760
|
-
const signature = concat([
|
|
761
|
-
pad(account.address, { size: 32 }),
|
|
762
|
-
pad(toHex(0), { size: 32 }),
|
|
763
|
-
toHex(1, { size: 1 })
|
|
764
|
-
]);
|
|
765
|
-
const txHash = await walletClient.writeContract({
|
|
766
|
-
account,
|
|
767
|
-
chain,
|
|
768
|
-
address: safeAddress,
|
|
769
|
-
abi: SAFE_ABI,
|
|
770
|
-
functionName: "execTransaction",
|
|
771
|
-
args: [
|
|
772
|
-
safeTx.to,
|
|
773
|
-
safeTx.value,
|
|
774
|
-
safeTx.data,
|
|
775
|
-
safeTx.operation,
|
|
776
|
-
safeTx.safeTxGas,
|
|
777
|
-
safeTx.baseGas,
|
|
778
|
-
safeTx.gasPrice,
|
|
779
|
-
safeTx.gasToken,
|
|
780
|
-
safeTx.refundReceiver,
|
|
781
|
-
signature
|
|
782
|
-
]
|
|
783
|
-
});
|
|
784
|
-
const receipt = await publicClient.waitForTransactionReceipt({
|
|
785
|
-
hash: txHash
|
|
786
|
-
});
|
|
787
|
-
const safeLogs = receipt.logs.filter(
|
|
788
|
-
(log) => log.address.toLowerCase() === safeAddress.toLowerCase()
|
|
789
|
-
);
|
|
790
|
-
const parsed = parseEventLogs({
|
|
791
|
-
abi: SAFE_ABI,
|
|
792
|
-
logs: safeLogs,
|
|
793
|
-
strict: false
|
|
794
|
-
});
|
|
795
|
-
const failed = parsed.find((log) => log.eventName === "ExecutionFailure");
|
|
796
|
-
if (failed) {
|
|
797
|
-
throw new Error("Safe transaction failed");
|
|
798
|
-
}
|
|
799
|
-
const succeeded = parsed.find((log) => log.eventName === "ExecutionSuccess");
|
|
800
|
-
if (!succeeded) {
|
|
801
|
-
throw new Error("Safe transaction status unavailable");
|
|
802
|
-
}
|
|
803
|
-
return { txHash };
|
|
804
|
-
}
|
|
805
|
-
var SAFE_TX_TYPES = {
|
|
806
|
-
SafeTx: [
|
|
807
|
-
{ name: "to", type: "address" },
|
|
808
|
-
{ name: "value", type: "uint256" },
|
|
809
|
-
{ name: "data", type: "bytes" },
|
|
810
|
-
{ name: "operation", type: "uint8" },
|
|
811
|
-
{ name: "safeTxGas", type: "uint256" },
|
|
812
|
-
{ name: "baseGas", type: "uint256" },
|
|
813
|
-
{ name: "gasPrice", type: "uint256" },
|
|
814
|
-
{ name: "gasToken", type: "address" },
|
|
815
|
-
{ name: "refundReceiver", type: "address" },
|
|
816
|
-
{ name: "nonce", type: "uint256" }
|
|
817
|
-
]
|
|
818
|
-
};
|
|
819
|
-
async function buildSafeTransaction(params) {
|
|
820
|
-
const { publicClient, safeAddress, to, value, data, chainId } = params;
|
|
821
|
-
const nonce = await publicClient.readContract({
|
|
822
|
-
address: safeAddress,
|
|
823
|
-
abi: SAFE_ABI,
|
|
824
|
-
functionName: "nonce"
|
|
825
|
-
});
|
|
826
|
-
const message = {
|
|
827
|
-
to,
|
|
828
|
-
value,
|
|
829
|
-
data,
|
|
830
|
-
operation: 0,
|
|
831
|
-
safeTxGas: 0n,
|
|
832
|
-
baseGas: 0n,
|
|
833
|
-
gasPrice: 0n,
|
|
834
|
-
gasToken: zeroAddress,
|
|
835
|
-
refundReceiver: zeroAddress,
|
|
836
|
-
nonce
|
|
837
|
-
};
|
|
838
|
-
const safeTxHash = hashTypedData({
|
|
839
|
-
domain: { chainId, verifyingContract: safeAddress },
|
|
840
|
-
types: SAFE_TX_TYPES,
|
|
841
|
-
primaryType: "SafeTx",
|
|
842
|
-
message
|
|
843
|
-
});
|
|
844
|
-
return {
|
|
845
|
-
chainId,
|
|
846
|
-
safeAddress,
|
|
847
|
-
safeTxHash,
|
|
848
|
-
typedData: {
|
|
849
|
-
domain: { chainId, verifyingContract: safeAddress },
|
|
850
|
-
types: SAFE_TX_TYPES,
|
|
851
|
-
primaryType: "SafeTx",
|
|
852
|
-
message
|
|
853
|
-
}
|
|
854
|
-
};
|
|
855
|
-
}
|
|
856
|
-
|
|
857
577
|
// src/WithdrawFlow.tsx
|
|
858
|
-
import { encodeFunctionData
|
|
578
|
+
import { encodeFunctionData, erc20Abi as erc20Abi2, parseUnits as parseUnits2 } from "viem";
|
|
859
579
|
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
860
580
|
function WithdrawFlow({
|
|
861
581
|
dappWalletClient,
|
|
@@ -1196,8 +916,8 @@ function WithdrawFlow({
|
|
|
1196
916
|
const transferData = isSourceNative ? { to: transferTarget, value: amountUnits, data: "0x" } : {
|
|
1197
917
|
to: sourceToken,
|
|
1198
918
|
value: 0n,
|
|
1199
|
-
data:
|
|
1200
|
-
abi:
|
|
919
|
+
data: encodeFunctionData({
|
|
920
|
+
abi: erc20Abi2,
|
|
1201
921
|
functionName: "transfer",
|
|
1202
922
|
args: [transferTarget, amountUnits]
|
|
1203
923
|
})
|
|
@@ -1414,17 +1134,13 @@ function WithdrawFlow({
|
|
|
1414
1134
|
ConnectStep,
|
|
1415
1135
|
{
|
|
1416
1136
|
walletOptions,
|
|
1417
|
-
|
|
1418
|
-
|
|
1137
|
+
onSelectWallet: (walletId) => {
|
|
1138
|
+
setSelectedWalletId(walletId);
|
|
1139
|
+
setIsConnectSelectionConfirmed(true);
|
|
1140
|
+
},
|
|
1419
1141
|
onRequestConnect,
|
|
1420
1142
|
onConnect,
|
|
1421
1143
|
onDisconnect,
|
|
1422
|
-
onContinue: () => {
|
|
1423
|
-
if (selectedWalletIdEffective) {
|
|
1424
|
-
setSelectedWalletId(selectedWalletIdEffective);
|
|
1425
|
-
}
|
|
1426
|
-
setIsConnectSelectionConfirmed(true);
|
|
1427
|
-
},
|
|
1428
1144
|
connectButtonLabel
|
|
1429
1145
|
}
|
|
1430
1146
|
) });
|
|
@@ -1485,7 +1201,7 @@ function WithdrawFlow({
|
|
|
1485
1201
|
// src/WithdrawModal.tsx
|
|
1486
1202
|
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1487
1203
|
var ReownWithdrawInner = lazy(
|
|
1488
|
-
() => import("./WithdrawModalReown-
|
|
1204
|
+
() => import("./WithdrawModalReown-HTEB4XGU.mjs").then((m) => ({
|
|
1489
1205
|
default: m.WithdrawModalReown
|
|
1490
1206
|
}))
|
|
1491
1207
|
);
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkR2HP743Tcjs = require('./chunk-R2HP743T.cjs');
|
|
4
|
+
|
|
5
|
+
// src/core/safe.ts
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
var _viem = require('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 ${_chunkR2HP743Tcjs.getChainName.call(void 0, 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: _viem.zeroAddress,
|
|
103
|
+
refundReceiver: _viem.zeroAddress
|
|
104
|
+
};
|
|
105
|
+
const signature = _viem.concat.call(void 0, [
|
|
106
|
+
_viem.pad.call(void 0, account.address, { size: 32 }),
|
|
107
|
+
_viem.pad.call(void 0, _viem.toHex.call(void 0, 0), { size: 32 }),
|
|
108
|
+
_viem.toHex.call(void 0, 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 = _viem.parseEventLogs.call(void 0, {
|
|
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 ${_chunkR2HP743Tcjs.getChainName.call(void 0, 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 = _viem.encodeFunctionData.call(void 0, {
|
|
178
|
+
abi: _viem.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: _viem.zeroAddress,
|
|
191
|
+
refundReceiver: _viem.zeroAddress
|
|
192
|
+
};
|
|
193
|
+
const signature = _viem.concat.call(void 0, [
|
|
194
|
+
_viem.pad.call(void 0, account.address, { size: 32 }),
|
|
195
|
+
_viem.pad.call(void 0, _viem.toHex.call(void 0, 0), { size: 32 }),
|
|
196
|
+
_viem.toHex.call(void 0, 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 = _viem.parseEventLogs.call(void 0, {
|
|
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: _viem.zeroAddress,
|
|
268
|
+
refundReceiver: _viem.zeroAddress,
|
|
269
|
+
nonce
|
|
270
|
+
};
|
|
271
|
+
const safeTxHash = _viem.hashTypedData.call(void 0, {
|
|
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
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
exports.SAFE_ABI = SAFE_ABI; exports.executeSafeEthTransfer = executeSafeEthTransfer; exports.executeSafeErc20Transfer = executeSafeErc20Transfer; exports.buildSafeTransaction = buildSafeTransaction;
|