@dynamic-labs/ethereum-core 3.0.0-alpha.49
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/CHANGELOG.md +3894 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/_virtual/_tslib.cjs +49 -0
- package/_virtual/_tslib.js +44 -0
- package/package.json +37 -0
- package/src/index.cjs +34 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +13 -0
- package/src/lib/utils/index.d.ts +2 -0
- package/src/lib/utils/logger.cjs +10 -0
- package/src/lib/utils/logger.d.ts +2 -0
- package/src/lib/utils/logger.js +6 -0
- package/src/lib/utils/validateAddressFormat.cjs +8 -0
- package/src/lib/utils/validateAddressFormat.d.ts +1 -0
- package/src/lib/utils/validateAddressFormat.js +4 -0
- package/src/lib/utils/viem/Eip1559FeeFeed.cjs +51 -0
- package/src/lib/utils/viem/Eip1559FeeFeed.d.ts +20 -0
- package/src/lib/utils/viem/Eip1559FeeFeed.js +47 -0
- package/src/lib/utils/viem/ViemRpcUiTransaction/ViemRpcUiTransaction.cjs +98 -0
- package/src/lib/utils/viem/ViemRpcUiTransaction/ViemRpcUiTransaction.d.ts +37 -0
- package/src/lib/utils/viem/ViemRpcUiTransaction/ViemRpcUiTransaction.js +94 -0
- package/src/lib/utils/viem/ViemRpcUiTransaction/index.d.ts +1 -0
- package/src/lib/utils/viem/ViemUiTransaction/ViemUiTransaction.cjs +121 -0
- package/src/lib/utils/viem/ViemUiTransaction/ViemUiTransaction.d.ts +56 -0
- package/src/lib/utils/viem/ViemUiTransaction/ViemUiTransaction.js +117 -0
- package/src/lib/utils/viem/ViemUiTransaction/index.d.ts +2 -0
- package/src/lib/utils/viem/chainsMap/chainsMap.cjs +31 -0
- package/src/lib/utils/viem/chainsMap/chainsMap.d.ts +2 -0
- package/src/lib/utils/viem/chainsMap/chainsMap.js +7 -0
- package/src/lib/utils/viem/chainsMap/index.d.ts +1 -0
- package/src/lib/utils/viem/confirmationTransport/confirmationTransport.cjs +39 -0
- package/src/lib/utils/viem/confirmationTransport/confirmationTransport.d.ts +11 -0
- package/src/lib/utils/viem/confirmationTransport/confirmationTransport.js +35 -0
- package/src/lib/utils/viem/confirmationTransport/index.d.ts +1 -0
- package/src/lib/utils/viem/createAccountWithUiConfirmation/createAccountWithUiConfirmation.cjs +41 -0
- package/src/lib/utils/viem/createAccountWithUiConfirmation/createAccountWithUiConfirmation.d.ts +12 -0
- package/src/lib/utils/viem/createAccountWithUiConfirmation/createAccountWithUiConfirmation.js +37 -0
- package/src/lib/utils/viem/createAccountWithUiConfirmation/index.d.ts +1 -0
- package/src/lib/utils/viem/createTransportWithUiConfirmation/createTransportWithUiConfirmation.cjs +33 -0
- package/src/lib/utils/viem/createTransportWithUiConfirmation/createTransportWithUiConfirmation.d.ts +25 -0
- package/src/lib/utils/viem/createTransportWithUiConfirmation/createTransportWithUiConfirmation.js +29 -0
- package/src/lib/utils/viem/createTransportWithUiConfirmation/index.d.ts +1 -0
- package/src/lib/utils/viem/createViemUiTransaction/createViemUiTransaction.cjs +40 -0
- package/src/lib/utils/viem/createViemUiTransaction/createViemUiTransaction.d.ts +9 -0
- package/src/lib/utils/viem/createViemUiTransaction/createViemUiTransaction.js +36 -0
- package/src/lib/utils/viem/createViemUiTransaction/index.d.ts +1 -0
- package/src/lib/utils/viem/createWalletClientFromWallet/createWalletClientFromWallet.cjs +70 -0
- package/src/lib/utils/viem/createWalletClientFromWallet/createWalletClientFromWallet.d.ts +19 -0
- package/src/lib/utils/viem/createWalletClientFromWallet/createWalletClientFromWallet.js +46 -0
- package/src/lib/utils/viem/createWalletClientFromWallet/index.d.ts +1 -0
- package/src/lib/utils/viem/createWalletClientWithUiConfirmation/createWalletClientWithUiConfirmation.cjs +73 -0
- package/src/lib/utils/viem/createWalletClientWithUiConfirmation/createWalletClientWithUiConfirmation.d.ts +29 -0
- package/src/lib/utils/viem/createWalletClientWithUiConfirmation/createWalletClientWithUiConfirmation.js +69 -0
- package/src/lib/utils/viem/createWalletClientWithUiConfirmation/index.d.ts +1 -0
- package/src/lib/utils/viem/erc20/abi.cjs +230 -0
- package/src/lib/utils/viem/erc20/abi.d.ts +38 -0
- package/src/lib/utils/viem/erc20/abi.js +226 -0
- package/src/lib/utils/viem/erc20/index.d.ts +1 -0
- package/src/lib/utils/viem/estimateL1Fee/estimateL1Fee.cjs +31 -0
- package/src/lib/utils/viem/estimateL1Fee/estimateL1Fee.d.ts +10 -0
- package/src/lib/utils/viem/estimateL1Fee/estimateL1Fee.js +26 -0
- package/src/lib/utils/viem/estimateL1Fee/index.d.ts +1 -0
- package/src/lib/utils/viem/estimateL1Fee/opStack/abi.cjs +23 -0
- package/src/lib/utils/viem/estimateL1Fee/opStack/abi.d.ts +20 -0
- package/src/lib/utils/viem/estimateL1Fee/opStack/abi.js +18 -0
- package/src/lib/utils/viem/estimateL1Fee/opStack/estimateL1Fee.cjs +30 -0
- package/src/lib/utils/viem/estimateL1Fee/opStack/estimateL1Fee.d.ts +3 -0
- package/src/lib/utils/viem/estimateL1Fee/opStack/estimateL1Fee.js +25 -0
- package/src/lib/utils/viem/estimateL1Fee/opStack/index.d.ts +1 -0
- package/src/lib/utils/viem/formatEther/formatEther.cjs +11 -0
- package/src/lib/utils/viem/formatEther/formatEther.d.ts +2 -0
- package/src/lib/utils/viem/formatEther/formatEther.js +7 -0
- package/src/lib/utils/viem/formatEther/index.d.ts +1 -0
- package/src/lib/utils/viem/getOrMapViemChain/getOrMapViemChain.cjs +77 -0
- package/src/lib/utils/viem/getOrMapViemChain/getOrMapViemChain.d.ts +11 -0
- package/src/lib/utils/viem/getOrMapViemChain/getOrMapViemChain.js +51 -0
- package/src/lib/utils/viem/getOrMapViemChain/index.d.ts +1 -0
- package/src/lib/utils/viem/index.d.ts +11 -0
- package/src/lib/utils/viem/interceptTransport/index.d.ts +1 -0
- package/src/lib/utils/viem/interceptTransport/interceptTransport.cjs +35 -0
- package/src/lib/utils/viem/interceptTransport/interceptTransport.d.ts +29 -0
- package/src/lib/utils/viem/interceptTransport/interceptTransport.js +31 -0
- package/src/lib/utils/viem/parseEther/index.d.ts +1 -0
- package/src/lib/utils/viem/parseEther/parseEther.cjs +10 -0
- package/src/lib/utils/viem/parseEther/parseEther.d.ts +1 -0
- package/src/lib/utils/viem/parseEther/parseEther.js +6 -0
- package/src/lib/utils/viem/unFormatTransaction/index.d.ts +1 -0
- package/src/lib/utils/viem/unFormatTransaction/unFormatTransaction.cjs +30 -0
- package/src/lib/utils/viem/unFormatTransaction/unFormatTransaction.d.ts +8 -0
- package/src/lib/utils/viem/unFormatTransaction/unFormatTransaction.js +26 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../../../_virtual/_tslib.cjs');
|
|
7
|
+
var viem = require('viem');
|
|
8
|
+
var utils = require('@dynamic-labs/utils');
|
|
9
|
+
var Eip1559FeeFeed = require('../Eip1559FeeFeed.cjs');
|
|
10
|
+
var estimateL1Fee = require('../estimateL1Fee/estimateL1Fee.cjs');
|
|
11
|
+
var validateAddressFormat = require('../../validateAddressFormat.cjs');
|
|
12
|
+
var parseEther = require('../parseEther/parseEther.cjs');
|
|
13
|
+
var formatEther = require('../formatEther/formatEther.cjs');
|
|
14
|
+
|
|
15
|
+
class ViemUiTransaction extends Eip1559FeeFeed.Eip1559FeeFeed {
|
|
16
|
+
constructor({ transaction, onSubmit, publicClient, account, }) {
|
|
17
|
+
super({
|
|
18
|
+
initialGasLimit: transaction.gas,
|
|
19
|
+
initialMaxFeePerGas: transaction.maxFeePerGas,
|
|
20
|
+
publicClient,
|
|
21
|
+
});
|
|
22
|
+
this.chain = 'EVM';
|
|
23
|
+
this.validateAddressFormat = validateAddressFormat.validateAddressFormat;
|
|
24
|
+
this.parse = parseEther.parseEther;
|
|
25
|
+
this.parseNonNativeToken = (amount, decimals) => viem.parseUnits(amount, decimals);
|
|
26
|
+
this.format = formatEther.formatEther;
|
|
27
|
+
this.formatNonNativeToken = (value, decimals) => viem.formatUnits(value, decimals);
|
|
28
|
+
this.transaction = transaction;
|
|
29
|
+
this.onSubmit = onSubmit;
|
|
30
|
+
this.publicClient = publicClient;
|
|
31
|
+
this.address = account;
|
|
32
|
+
}
|
|
33
|
+
get to() {
|
|
34
|
+
return this.transaction.to || undefined;
|
|
35
|
+
}
|
|
36
|
+
set to(toAddress) {
|
|
37
|
+
this.transaction.to = toAddress;
|
|
38
|
+
}
|
|
39
|
+
get from() {
|
|
40
|
+
return this.address;
|
|
41
|
+
}
|
|
42
|
+
get value() {
|
|
43
|
+
return this.transaction.value;
|
|
44
|
+
}
|
|
45
|
+
set value(value) {
|
|
46
|
+
this.transaction.value = value;
|
|
47
|
+
}
|
|
48
|
+
get nonNativeValue() {
|
|
49
|
+
return this.transaction.nonNativeValue;
|
|
50
|
+
}
|
|
51
|
+
set nonNativeValue(value) {
|
|
52
|
+
this.transaction.nonNativeValue = value;
|
|
53
|
+
}
|
|
54
|
+
get nonNativeAddress() {
|
|
55
|
+
return this.transaction.nonNativeAddress;
|
|
56
|
+
}
|
|
57
|
+
set nonNativeAddress(value) {
|
|
58
|
+
this.transaction.nonNativeAddress = value;
|
|
59
|
+
}
|
|
60
|
+
get nonNativeDecimal() {
|
|
61
|
+
return this.transaction.nonNativeDecimal;
|
|
62
|
+
}
|
|
63
|
+
set nonNativeDecimal(value) {
|
|
64
|
+
this.transaction.nonNativeDecimal = value;
|
|
65
|
+
}
|
|
66
|
+
get data() {
|
|
67
|
+
return this.transaction.data;
|
|
68
|
+
}
|
|
69
|
+
submit() {
|
|
70
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
return this.onSubmit(this.transaction).catch((error) => {
|
|
72
|
+
if (error instanceof utils.UserRejectedTransactionError) {
|
|
73
|
+
throw new viem.TransactionExecutionError(new viem.BaseError(error.message), this.transaction);
|
|
74
|
+
}
|
|
75
|
+
throw error;
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
getBalance() {
|
|
80
|
+
return this.publicClient.getBalance({ address: this.address });
|
|
81
|
+
}
|
|
82
|
+
estimateGas() {
|
|
83
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
const hexResult = (yield this.publicClient.transport.request({
|
|
85
|
+
method: 'eth_estimateGas',
|
|
86
|
+
params: [
|
|
87
|
+
{
|
|
88
|
+
data: this.data,
|
|
89
|
+
to: this.to,
|
|
90
|
+
value: this.convertBigIntToHex(this.value),
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
}));
|
|
94
|
+
return viem.hexToBigInt(hexResult);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
convertBigIntToHex(value) {
|
|
98
|
+
return value ? viem.toHex(value) : undefined;
|
|
99
|
+
}
|
|
100
|
+
estimateL1Fee() {
|
|
101
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
var _a;
|
|
103
|
+
if (!estimateL1Fee.isL1FeeSupportedByChain(((_a = this.publicClient.chain) === null || _a === void 0 ? void 0 : _a.id) || 0)) {
|
|
104
|
+
return BigInt(0);
|
|
105
|
+
}
|
|
106
|
+
return estimateL1Fee.estimateL1Fee(this.publicClient, {
|
|
107
|
+
data: this.transaction.data,
|
|
108
|
+
to: this.transaction.to,
|
|
109
|
+
value: this.transaction.value,
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
set maxFeePerGas(value) {
|
|
114
|
+
this.transaction.maxFeePerGas = value;
|
|
115
|
+
}
|
|
116
|
+
set maxPriorityFeePerGas(value) {
|
|
117
|
+
this.transaction.maxPriorityFeePerGas = value;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
exports.ViemUiTransaction = ViemUiTransaction;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Address, Chain, PublicClient, TransactionSerializable, Transport } from 'viem';
|
|
2
|
+
import { IUITransaction } from '@dynamic-labs/types';
|
|
3
|
+
import { Eip1559FeeFeed } from '../Eip1559FeeFeed';
|
|
4
|
+
export type NonNativeTransaction = {
|
|
5
|
+
nonNativeValue?: bigint;
|
|
6
|
+
nonNativeAddress?: string;
|
|
7
|
+
nonNativeDecimal?: number;
|
|
8
|
+
};
|
|
9
|
+
type ViemUiTransactionProps = {
|
|
10
|
+
account: Address;
|
|
11
|
+
transaction: TransactionSerializable & NonNativeTransaction;
|
|
12
|
+
onSubmit: (transaction: TransactionSerializable & NonNativeTransaction) => Promise<string>;
|
|
13
|
+
publicClient: PublicClient<Transport, Chain>;
|
|
14
|
+
};
|
|
15
|
+
export interface IUIEvmTransaction {
|
|
16
|
+
nonNativeValue: bigint | undefined;
|
|
17
|
+
nonNativeAddress: string | undefined;
|
|
18
|
+
nonNativeDecimal: number | undefined;
|
|
19
|
+
formatNonNativeToken: (value: bigint, decimals: number) => string;
|
|
20
|
+
parseNonNativeToken: (input: string, decimals: number) => bigint;
|
|
21
|
+
}
|
|
22
|
+
export declare class ViemUiTransaction extends Eip1559FeeFeed implements IUITransaction, IUIEvmTransaction {
|
|
23
|
+
chain: string;
|
|
24
|
+
receipt: string | undefined;
|
|
25
|
+
private transaction;
|
|
26
|
+
private address;
|
|
27
|
+
protected publicClient: PublicClient<Transport, Chain>;
|
|
28
|
+
private onSubmit;
|
|
29
|
+
constructor({ transaction, onSubmit, publicClient, account, }: ViemUiTransactionProps);
|
|
30
|
+
nativePrice?: number | undefined;
|
|
31
|
+
validateAddressFormat: (address: string) => boolean;
|
|
32
|
+
parse: (input: string) => bigint;
|
|
33
|
+
parseNonNativeToken: (amount: string, decimals: number) => bigint;
|
|
34
|
+
format: (value: bigint, { precision }?: import("@dynamic-labs/types").IUITransactionFormatOptions) => string;
|
|
35
|
+
formatNonNativeToken: (value: bigint, decimals: number) => string;
|
|
36
|
+
get to(): Address | undefined;
|
|
37
|
+
set to(toAddress: Address | undefined);
|
|
38
|
+
get from(): `0x${string}`;
|
|
39
|
+
get value(): bigint | undefined;
|
|
40
|
+
set value(value: bigint | undefined);
|
|
41
|
+
get nonNativeValue(): bigint | undefined;
|
|
42
|
+
set nonNativeValue(value: bigint | undefined);
|
|
43
|
+
get nonNativeAddress(): string | undefined;
|
|
44
|
+
set nonNativeAddress(value: string | undefined);
|
|
45
|
+
get nonNativeDecimal(): number | undefined;
|
|
46
|
+
set nonNativeDecimal(value: number | undefined);
|
|
47
|
+
get data(): `0x${string}` | undefined;
|
|
48
|
+
submit(): Promise<string>;
|
|
49
|
+
getBalance(): Promise<bigint>;
|
|
50
|
+
estimateGas(): Promise<bigint>;
|
|
51
|
+
private convertBigIntToHex;
|
|
52
|
+
estimateL1Fee(): Promise<bigint>;
|
|
53
|
+
set maxFeePerGas(value: bigint);
|
|
54
|
+
set maxPriorityFeePerGas(value: bigint);
|
|
55
|
+
}
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
3
|
+
import { parseUnits, formatUnits, toHex, TransactionExecutionError, BaseError, hexToBigInt } from 'viem';
|
|
4
|
+
import { UserRejectedTransactionError } from '@dynamic-labs/utils';
|
|
5
|
+
import { Eip1559FeeFeed } from '../Eip1559FeeFeed.js';
|
|
6
|
+
import { isL1FeeSupportedByChain, estimateL1Fee } from '../estimateL1Fee/estimateL1Fee.js';
|
|
7
|
+
import { validateAddressFormat } from '../../validateAddressFormat.js';
|
|
8
|
+
import { parseEther } from '../parseEther/parseEther.js';
|
|
9
|
+
import { formatEther } from '../formatEther/formatEther.js';
|
|
10
|
+
|
|
11
|
+
class ViemUiTransaction extends Eip1559FeeFeed {
|
|
12
|
+
constructor({ transaction, onSubmit, publicClient, account, }) {
|
|
13
|
+
super({
|
|
14
|
+
initialGasLimit: transaction.gas,
|
|
15
|
+
initialMaxFeePerGas: transaction.maxFeePerGas,
|
|
16
|
+
publicClient,
|
|
17
|
+
});
|
|
18
|
+
this.chain = 'EVM';
|
|
19
|
+
this.validateAddressFormat = validateAddressFormat;
|
|
20
|
+
this.parse = parseEther;
|
|
21
|
+
this.parseNonNativeToken = (amount, decimals) => parseUnits(amount, decimals);
|
|
22
|
+
this.format = formatEther;
|
|
23
|
+
this.formatNonNativeToken = (value, decimals) => formatUnits(value, decimals);
|
|
24
|
+
this.transaction = transaction;
|
|
25
|
+
this.onSubmit = onSubmit;
|
|
26
|
+
this.publicClient = publicClient;
|
|
27
|
+
this.address = account;
|
|
28
|
+
}
|
|
29
|
+
get to() {
|
|
30
|
+
return this.transaction.to || undefined;
|
|
31
|
+
}
|
|
32
|
+
set to(toAddress) {
|
|
33
|
+
this.transaction.to = toAddress;
|
|
34
|
+
}
|
|
35
|
+
get from() {
|
|
36
|
+
return this.address;
|
|
37
|
+
}
|
|
38
|
+
get value() {
|
|
39
|
+
return this.transaction.value;
|
|
40
|
+
}
|
|
41
|
+
set value(value) {
|
|
42
|
+
this.transaction.value = value;
|
|
43
|
+
}
|
|
44
|
+
get nonNativeValue() {
|
|
45
|
+
return this.transaction.nonNativeValue;
|
|
46
|
+
}
|
|
47
|
+
set nonNativeValue(value) {
|
|
48
|
+
this.transaction.nonNativeValue = value;
|
|
49
|
+
}
|
|
50
|
+
get nonNativeAddress() {
|
|
51
|
+
return this.transaction.nonNativeAddress;
|
|
52
|
+
}
|
|
53
|
+
set nonNativeAddress(value) {
|
|
54
|
+
this.transaction.nonNativeAddress = value;
|
|
55
|
+
}
|
|
56
|
+
get nonNativeDecimal() {
|
|
57
|
+
return this.transaction.nonNativeDecimal;
|
|
58
|
+
}
|
|
59
|
+
set nonNativeDecimal(value) {
|
|
60
|
+
this.transaction.nonNativeDecimal = value;
|
|
61
|
+
}
|
|
62
|
+
get data() {
|
|
63
|
+
return this.transaction.data;
|
|
64
|
+
}
|
|
65
|
+
submit() {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
return this.onSubmit(this.transaction).catch((error) => {
|
|
68
|
+
if (error instanceof UserRejectedTransactionError) {
|
|
69
|
+
throw new TransactionExecutionError(new BaseError(error.message), this.transaction);
|
|
70
|
+
}
|
|
71
|
+
throw error;
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
getBalance() {
|
|
76
|
+
return this.publicClient.getBalance({ address: this.address });
|
|
77
|
+
}
|
|
78
|
+
estimateGas() {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
const hexResult = (yield this.publicClient.transport.request({
|
|
81
|
+
method: 'eth_estimateGas',
|
|
82
|
+
params: [
|
|
83
|
+
{
|
|
84
|
+
data: this.data,
|
|
85
|
+
to: this.to,
|
|
86
|
+
value: this.convertBigIntToHex(this.value),
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
}));
|
|
90
|
+
return hexToBigInt(hexResult);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
convertBigIntToHex(value) {
|
|
94
|
+
return value ? toHex(value) : undefined;
|
|
95
|
+
}
|
|
96
|
+
estimateL1Fee() {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
var _a;
|
|
99
|
+
if (!isL1FeeSupportedByChain(((_a = this.publicClient.chain) === null || _a === void 0 ? void 0 : _a.id) || 0)) {
|
|
100
|
+
return BigInt(0);
|
|
101
|
+
}
|
|
102
|
+
return estimateL1Fee(this.publicClient, {
|
|
103
|
+
data: this.transaction.data,
|
|
104
|
+
to: this.transaction.to,
|
|
105
|
+
value: this.transaction.value,
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
set maxFeePerGas(value) {
|
|
110
|
+
this.transaction.maxFeePerGas = value;
|
|
111
|
+
}
|
|
112
|
+
set maxPriorityFeePerGas(value) {
|
|
113
|
+
this.transaction.maxPriorityFeePerGas = value;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export { ViemUiTransaction };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var chains = require('viem/chains');
|
|
7
|
+
|
|
8
|
+
function _interopNamespace(e) {
|
|
9
|
+
if (e && e.__esModule) return e;
|
|
10
|
+
var n = Object.create(null);
|
|
11
|
+
if (e) {
|
|
12
|
+
Object.keys(e).forEach(function (k) {
|
|
13
|
+
if (k !== 'default') {
|
|
14
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return e[k]; }
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
n["default"] = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var chains__namespace = /*#__PURE__*/_interopNamespace(chains);
|
|
27
|
+
|
|
28
|
+
// eslint-disable-next-line import/no-namespace
|
|
29
|
+
const chainsMap = Object.values(chains__namespace).reduce((acc, chain) => (Object.assign(Object.assign({}, acc), { [chain.id]: chain })), {});
|
|
30
|
+
|
|
31
|
+
exports.chainsMap = chainsMap;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './chainsMap';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var viem = require('viem');
|
|
7
|
+
var interceptTransport = require('../interceptTransport/interceptTransport.cjs');
|
|
8
|
+
var ViemRpcUiTransaction = require('../ViemRpcUiTransaction/ViemRpcUiTransaction.cjs');
|
|
9
|
+
|
|
10
|
+
const confirmationTransport = ({ transport, walletUiUtils, getAccounts, onPersonalSign, onSendTransaction, onSignTypedData, walletConnector, provider, }) => interceptTransport.interceptTransport({
|
|
11
|
+
getAccounts,
|
|
12
|
+
onPersonalSign: onPersonalSign
|
|
13
|
+
? (args) => walletUiUtils.signMessage({
|
|
14
|
+
handler: () => onPersonalSign(args),
|
|
15
|
+
message: viem.fromHex(args.message, 'string'),
|
|
16
|
+
walletConnector,
|
|
17
|
+
})
|
|
18
|
+
: undefined,
|
|
19
|
+
onSendTransaction: onSendTransaction
|
|
20
|
+
? (args) => {
|
|
21
|
+
const uiTransaction = new ViemRpcUiTransaction.ViemRpcUiTransaction({
|
|
22
|
+
onSubmit: (transaction) => onSendTransaction(Object.assign(Object.assign({}, args), { transaction })),
|
|
23
|
+
publicClient: provider,
|
|
24
|
+
transaction: args.transaction,
|
|
25
|
+
});
|
|
26
|
+
return walletUiUtils.sendTransaction(walletConnector, uiTransaction);
|
|
27
|
+
}
|
|
28
|
+
: undefined,
|
|
29
|
+
onSignTypedData: onSignTypedData
|
|
30
|
+
? (args) => walletUiUtils.signMessage({
|
|
31
|
+
handler: () => onSignTypedData(args),
|
|
32
|
+
message: args.message,
|
|
33
|
+
walletConnector,
|
|
34
|
+
})
|
|
35
|
+
: undefined,
|
|
36
|
+
transport,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
exports.confirmationTransport = confirmationTransport;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Chain, PublicClient, Transport } from 'viem';
|
|
2
|
+
import { WalletUiUtils } from '@dynamic-labs/types';
|
|
3
|
+
import { WalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
import { type InterceptTransportProps } from '../interceptTransport';
|
|
5
|
+
type ConfirmationTransportProps = {
|
|
6
|
+
provider: PublicClient<Transport, Chain>;
|
|
7
|
+
walletConnector: WalletConnector;
|
|
8
|
+
walletUiUtils: WalletUiUtils<WalletConnector>;
|
|
9
|
+
} & InterceptTransportProps;
|
|
10
|
+
export declare const confirmationTransport: ({ transport, walletUiUtils, getAccounts, onPersonalSign, onSendTransaction, onSignTypedData, walletConnector, provider, }: ConfirmationTransportProps) => import("viem").CustomTransport;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { fromHex } from 'viem';
|
|
3
|
+
import { interceptTransport } from '../interceptTransport/interceptTransport.js';
|
|
4
|
+
import { ViemRpcUiTransaction } from '../ViemRpcUiTransaction/ViemRpcUiTransaction.js';
|
|
5
|
+
|
|
6
|
+
const confirmationTransport = ({ transport, walletUiUtils, getAccounts, onPersonalSign, onSendTransaction, onSignTypedData, walletConnector, provider, }) => interceptTransport({
|
|
7
|
+
getAccounts,
|
|
8
|
+
onPersonalSign: onPersonalSign
|
|
9
|
+
? (args) => walletUiUtils.signMessage({
|
|
10
|
+
handler: () => onPersonalSign(args),
|
|
11
|
+
message: fromHex(args.message, 'string'),
|
|
12
|
+
walletConnector,
|
|
13
|
+
})
|
|
14
|
+
: undefined,
|
|
15
|
+
onSendTransaction: onSendTransaction
|
|
16
|
+
? (args) => {
|
|
17
|
+
const uiTransaction = new ViemRpcUiTransaction({
|
|
18
|
+
onSubmit: (transaction) => onSendTransaction(Object.assign(Object.assign({}, args), { transaction })),
|
|
19
|
+
publicClient: provider,
|
|
20
|
+
transaction: args.transaction,
|
|
21
|
+
});
|
|
22
|
+
return walletUiUtils.sendTransaction(walletConnector, uiTransaction);
|
|
23
|
+
}
|
|
24
|
+
: undefined,
|
|
25
|
+
onSignTypedData: onSignTypedData
|
|
26
|
+
? (args) => walletUiUtils.signMessage({
|
|
27
|
+
handler: () => onSignTypedData(args),
|
|
28
|
+
message: args.message,
|
|
29
|
+
walletConnector,
|
|
30
|
+
})
|
|
31
|
+
: undefined,
|
|
32
|
+
transport,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export { confirmationTransport };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { confirmationTransport } from './confirmationTransport';
|
package/src/lib/utils/viem/createAccountWithUiConfirmation/createAccountWithUiConfirmation.cjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../../../_virtual/_tslib.cjs');
|
|
7
|
+
var accounts = require('viem/accounts');
|
|
8
|
+
var ViemUiTransaction = require('../ViemUiTransaction/ViemUiTransaction.cjs');
|
|
9
|
+
|
|
10
|
+
const createAccountWithUiConfirmation = ({ address, account, provider, walletConnector, walletUiUtils, }) => accounts.toAccount({
|
|
11
|
+
address,
|
|
12
|
+
signMessage: (...args) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
+
return walletUiUtils.signMessage({
|
|
14
|
+
handler: () => _tslib.__awaiter(void 0, void 0, void 0, function* () { return (yield account()).signMessage(...args); }),
|
|
15
|
+
message: (() => {
|
|
16
|
+
var _a;
|
|
17
|
+
const msg = (_a = args[0]) === null || _a === void 0 ? void 0 : _a.message;
|
|
18
|
+
return msg && !(typeof msg === 'string' && Array.isArray(msg))
|
|
19
|
+
? JSON.stringify(msg)
|
|
20
|
+
: msg === null || msg === void 0 ? void 0 : msg.toString();
|
|
21
|
+
})(),
|
|
22
|
+
walletConnector,
|
|
23
|
+
});
|
|
24
|
+
}),
|
|
25
|
+
signTransaction: (...args) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
const uiTransaction = new ViemUiTransaction.ViemUiTransaction({
|
|
27
|
+
account: address,
|
|
28
|
+
onSubmit: (transaction) => _tslib.__awaiter(void 0, void 0, void 0, function* () { return (yield account()).signTransaction(transaction); }),
|
|
29
|
+
publicClient: provider,
|
|
30
|
+
transaction: args[0],
|
|
31
|
+
});
|
|
32
|
+
return walletUiUtils.sendTransaction(walletConnector, uiTransaction);
|
|
33
|
+
}),
|
|
34
|
+
signTypedData: (...args) => walletUiUtils.signMessage({
|
|
35
|
+
handler: () => _tslib.__awaiter(void 0, void 0, void 0, function* () { return (yield account()).signTypedData(...args); }),
|
|
36
|
+
message: JSON.stringify(args[0]),
|
|
37
|
+
walletConnector,
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
exports.createAccountWithUiConfirmation = createAccountWithUiConfirmation;
|
package/src/lib/utils/viem/createAccountWithUiConfirmation/createAccountWithUiConfirmation.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Chain, LocalAccount, PublicClient, Transport } from 'viem';
|
|
2
|
+
import { WalletUiUtils } from '@dynamic-labs/types';
|
|
3
|
+
import { WalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
type Props = {
|
|
5
|
+
address: `0x${string}`;
|
|
6
|
+
account: () => Promise<LocalAccount>;
|
|
7
|
+
walletConnector: WalletConnector;
|
|
8
|
+
walletUiUtils: WalletUiUtils<WalletConnector>;
|
|
9
|
+
provider: PublicClient<Transport, Chain>;
|
|
10
|
+
};
|
|
11
|
+
export declare const createAccountWithUiConfirmation: ({ address, account, provider, walletConnector, walletUiUtils, }: Props) => LocalAccount;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
3
|
+
import { toAccount } from 'viem/accounts';
|
|
4
|
+
import { ViemUiTransaction } from '../ViemUiTransaction/ViemUiTransaction.js';
|
|
5
|
+
|
|
6
|
+
const createAccountWithUiConfirmation = ({ address, account, provider, walletConnector, walletUiUtils, }) => toAccount({
|
|
7
|
+
address,
|
|
8
|
+
signMessage: (...args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
9
|
+
return walletUiUtils.signMessage({
|
|
10
|
+
handler: () => __awaiter(void 0, void 0, void 0, function* () { return (yield account()).signMessage(...args); }),
|
|
11
|
+
message: (() => {
|
|
12
|
+
var _a;
|
|
13
|
+
const msg = (_a = args[0]) === null || _a === void 0 ? void 0 : _a.message;
|
|
14
|
+
return msg && !(typeof msg === 'string' && Array.isArray(msg))
|
|
15
|
+
? JSON.stringify(msg)
|
|
16
|
+
: msg === null || msg === void 0 ? void 0 : msg.toString();
|
|
17
|
+
})(),
|
|
18
|
+
walletConnector,
|
|
19
|
+
});
|
|
20
|
+
}),
|
|
21
|
+
signTransaction: (...args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
const uiTransaction = new ViemUiTransaction({
|
|
23
|
+
account: address,
|
|
24
|
+
onSubmit: (transaction) => __awaiter(void 0, void 0, void 0, function* () { return (yield account()).signTransaction(transaction); }),
|
|
25
|
+
publicClient: provider,
|
|
26
|
+
transaction: args[0],
|
|
27
|
+
});
|
|
28
|
+
return walletUiUtils.sendTransaction(walletConnector, uiTransaction);
|
|
29
|
+
}),
|
|
30
|
+
signTypedData: (...args) => walletUiUtils.signMessage({
|
|
31
|
+
handler: () => __awaiter(void 0, void 0, void 0, function* () { return (yield account()).signTypedData(...args); }),
|
|
32
|
+
message: JSON.stringify(args[0]),
|
|
33
|
+
walletConnector,
|
|
34
|
+
}),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export { createAccountWithUiConfirmation };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createAccountWithUiConfirmation } from './createAccountWithUiConfirmation';
|
package/src/lib/utils/viem/createTransportWithUiConfirmation/createTransportWithUiConfirmation.cjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../../../_virtual/_tslib.cjs');
|
|
7
|
+
var confirmationTransport = require('../confirmationTransport/confirmationTransport.cjs');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates a viem transport with user interface confirmation for Ethereum-related operations.
|
|
11
|
+
*
|
|
12
|
+
* This function wraps a `Transport` object with additional UI confirmation logic for
|
|
13
|
+
* personal sign requests, transaction sending, and signing typed data using the provided
|
|
14
|
+
* `WalletUiUtils`. The function intercepts various Ethereum-related operations to
|
|
15
|
+
* inject custom UI handling logic.
|
|
16
|
+
*
|
|
17
|
+
* @param {Object} props - The properties to configure the transport.
|
|
18
|
+
* @param {WalletUiUtils} props.walletUiUtils - The UI utility functions for wallet operations.
|
|
19
|
+
* @param {PublicClient} props.publicClient - The public client for interacting with Ethereum.
|
|
20
|
+
* @param {Transport} props.transport - The transport layer to be wrapped.
|
|
21
|
+
* @returns {Transport} The transport layer wrapped with UI confirmation logic.
|
|
22
|
+
*/
|
|
23
|
+
const createTransportWithUiConfirmation = ({ walletUiUtils, publicClient, transport, walletConnector, }) => confirmationTransport.confirmationTransport({
|
|
24
|
+
onPersonalSign: (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ args, provider }) { return provider.request(args); }),
|
|
25
|
+
onSendTransaction: (_b) => _tslib.__awaiter(void 0, [_b], void 0, function* ({ args, provider }) { return provider.request(args); }),
|
|
26
|
+
onSignTypedData: (_c) => _tslib.__awaiter(void 0, [_c], void 0, function* ({ args, provider }) { return provider.request(args); }),
|
|
27
|
+
provider: publicClient,
|
|
28
|
+
transport,
|
|
29
|
+
walletConnector,
|
|
30
|
+
walletUiUtils,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
exports.createTransportWithUiConfirmation = createTransportWithUiConfirmation;
|
package/src/lib/utils/viem/createTransportWithUiConfirmation/createTransportWithUiConfirmation.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Chain, PublicClient, Transport } from 'viem';
|
|
2
|
+
import { WalletUiUtils } from '@dynamic-labs/types';
|
|
3
|
+
import { WalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
type Props = {
|
|
5
|
+
walletUiUtils: WalletUiUtils<WalletConnector>;
|
|
6
|
+
walletConnector: WalletConnector;
|
|
7
|
+
publicClient: PublicClient<Transport, Chain>;
|
|
8
|
+
transport: Transport;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Creates a viem transport with user interface confirmation for Ethereum-related operations.
|
|
12
|
+
*
|
|
13
|
+
* This function wraps a `Transport` object with additional UI confirmation logic for
|
|
14
|
+
* personal sign requests, transaction sending, and signing typed data using the provided
|
|
15
|
+
* `WalletUiUtils`. The function intercepts various Ethereum-related operations to
|
|
16
|
+
* inject custom UI handling logic.
|
|
17
|
+
*
|
|
18
|
+
* @param {Object} props - The properties to configure the transport.
|
|
19
|
+
* @param {WalletUiUtils} props.walletUiUtils - The UI utility functions for wallet operations.
|
|
20
|
+
* @param {PublicClient} props.publicClient - The public client for interacting with Ethereum.
|
|
21
|
+
* @param {Transport} props.transport - The transport layer to be wrapped.
|
|
22
|
+
* @returns {Transport} The transport layer wrapped with UI confirmation logic.
|
|
23
|
+
*/
|
|
24
|
+
export declare const createTransportWithUiConfirmation: ({ walletUiUtils, publicClient, transport, walletConnector, }: Props) => import("viem").CustomTransport;
|
|
25
|
+
export {};
|
package/src/lib/utils/viem/createTransportWithUiConfirmation/createTransportWithUiConfirmation.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
3
|
+
import { confirmationTransport } from '../confirmationTransport/confirmationTransport.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a viem transport with user interface confirmation for Ethereum-related operations.
|
|
7
|
+
*
|
|
8
|
+
* This function wraps a `Transport` object with additional UI confirmation logic for
|
|
9
|
+
* personal sign requests, transaction sending, and signing typed data using the provided
|
|
10
|
+
* `WalletUiUtils`. The function intercepts various Ethereum-related operations to
|
|
11
|
+
* inject custom UI handling logic.
|
|
12
|
+
*
|
|
13
|
+
* @param {Object} props - The properties to configure the transport.
|
|
14
|
+
* @param {WalletUiUtils} props.walletUiUtils - The UI utility functions for wallet operations.
|
|
15
|
+
* @param {PublicClient} props.publicClient - The public client for interacting with Ethereum.
|
|
16
|
+
* @param {Transport} props.transport - The transport layer to be wrapped.
|
|
17
|
+
* @returns {Transport} The transport layer wrapped with UI confirmation logic.
|
|
18
|
+
*/
|
|
19
|
+
const createTransportWithUiConfirmation = ({ walletUiUtils, publicClient, transport, walletConnector, }) => confirmationTransport({
|
|
20
|
+
onPersonalSign: (_a) => __awaiter(void 0, [_a], void 0, function* ({ args, provider }) { return provider.request(args); }),
|
|
21
|
+
onSendTransaction: (_b) => __awaiter(void 0, [_b], void 0, function* ({ args, provider }) { return provider.request(args); }),
|
|
22
|
+
onSignTypedData: (_c) => __awaiter(void 0, [_c], void 0, function* ({ args, provider }) { return provider.request(args); }),
|
|
23
|
+
provider: publicClient,
|
|
24
|
+
transport,
|
|
25
|
+
walletConnector,
|
|
26
|
+
walletUiUtils,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export { createTransportWithUiConfirmation };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createTransportWithUiConfirmation } from './createTransportWithUiConfirmation';
|