@pushchain/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +241 -0
- package/package.json +30 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +5 -0
- package/src/index.js.map +1 -0
- package/src/lib/constants/abi/factoryV1.d.ts +81 -0
- package/src/lib/constants/abi/factoryV1.js +255 -0
- package/src/lib/constants/abi/factoryV1.js.map +1 -0
- package/src/lib/constants/abi/feeLocker.evm.d.ts +39 -0
- package/src/lib/constants/abi/feeLocker.evm.js +319 -0
- package/src/lib/constants/abi/feeLocker.evm.js.map +1 -0
- package/src/lib/constants/abi/feeLocker.json +230 -0
- package/src/lib/constants/abi/index.d.ts +5 -0
- package/src/lib/constants/abi/index.js +15 -0
- package/src/lib/constants/abi/index.js.map +1 -0
- package/src/lib/constants/abi/smartAccount.evm.d.ts +110 -0
- package/src/lib/constants/abi/smartAccount.evm.js +212 -0
- package/src/lib/constants/abi/smartAccount.evm.js.map +1 -0
- package/src/lib/constants/abi/smartAccount.svm.d.ts +106 -0
- package/src/lib/constants/abi/smartAccount.svm.js +209 -0
- package/src/lib/constants/abi/smartAccount.svm.js.map +1 -0
- package/src/lib/constants/chain.d.ts +32 -0
- package/src/lib/constants/chain.js +79 -0
- package/src/lib/constants/chain.js.map +1 -0
- package/src/lib/constants/enums.d.ts +30 -0
- package/src/lib/constants/enums.js +40 -0
- package/src/lib/constants/enums.js.map +1 -0
- package/src/lib/constants/index.d.ts +5 -0
- package/src/lib/constants/index.js +10 -0
- package/src/lib/constants/index.js.map +1 -0
- package/src/lib/generated/v1/tx.d.ts +83 -0
- package/src/lib/generated/v1/tx.js +616 -0
- package/src/lib/generated/v1/tx.js.map +1 -0
- package/src/lib/index.d.ts +3 -0
- package/src/lib/index.js +8 -0
- package/src/lib/index.js.map +1 -0
- package/src/lib/orchestrator/orchestrator.d.ts +63 -0
- package/src/lib/orchestrator/orchestrator.js +475 -0
- package/src/lib/orchestrator/orchestrator.js.map +1 -0
- package/src/lib/orchestrator/orchestrator.types.d.ts +44 -0
- package/src/lib/orchestrator/orchestrator.types.js +3 -0
- package/src/lib/orchestrator/orchestrator.types.js.map +1 -0
- package/src/lib/price-fetch/price-fetch.d.ts +13 -0
- package/src/lib/price-fetch/price-fetch.js +115 -0
- package/src/lib/price-fetch/price-fetch.js.map +1 -0
- package/src/lib/push-client/push-client.d.ts +47 -0
- package/src/lib/push-client/push-client.js +132 -0
- package/src/lib/push-client/push-client.js.map +1 -0
- package/src/lib/push-client/push-client.types.d.ts +5 -0
- package/src/lib/push-client/push-client.types.js +3 -0
- package/src/lib/push-client/push-client.types.js.map +1 -0
- package/src/lib/pushChain.d.ts +50 -0
- package/src/lib/pushChain.js +57 -0
- package/src/lib/pushChain.js.map +1 -0
- package/src/lib/universal/account/account.d.ts +51 -0
- package/src/lib/universal/account/account.js +114 -0
- package/src/lib/universal/account/account.js.map +1 -0
- package/src/lib/universal/account/index.d.ts +1 -0
- package/src/lib/universal/account/index.js +5 -0
- package/src/lib/universal/account/index.js.map +1 -0
- package/src/lib/universal/signer/index.d.ts +1 -0
- package/src/lib/universal/signer/index.js +5 -0
- package/src/lib/universal/signer/index.js.map +1 -0
- package/src/lib/universal/signer/signer.d.ts +40 -0
- package/src/lib/universal/signer/signer.js +138 -0
- package/src/lib/universal/signer/signer.js.map +1 -0
- package/src/lib/universal/universal.types.d.ts +52 -0
- package/src/lib/universal/universal.types.js +3 -0
- package/src/lib/universal/universal.types.js.map +1 -0
- package/src/lib/utils.d.ts +53 -0
- package/src/lib/utils.js +58 -0
- package/src/lib/utils.js.map +1 -0
- package/src/lib/vm-client/evm-client.d.ts +173 -0
- package/src/lib/vm-client/evm-client.js +244 -0
- package/src/lib/vm-client/evm-client.js.map +1 -0
- package/src/lib/vm-client/svm-client.d.ts +42 -0
- package/src/lib/vm-client/svm-client.js +136 -0
- package/src/lib/vm-client/svm-client.js.map +1 -0
- package/src/lib/vm-client/vm-client.types.d.ts +49 -0
- package/src/lib/vm-client/vm-client.types.js +3 -0
- package/src/lib/vm-client/vm-client.types.js.map +1 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { WalletClient, Account } from 'viem';
|
|
2
|
+
import { UniversalSigner } from '../universal.types';
|
|
3
|
+
import { CHAIN } from '../../constants/enums';
|
|
4
|
+
import { Keypair } from '@solana/web3.js';
|
|
5
|
+
/**
|
|
6
|
+
* Creates a `UniversalSigner` object for signing messages and transactions
|
|
7
|
+
* on any supported chain.
|
|
8
|
+
*
|
|
9
|
+
* @param {Object} params - The signer configuration object.
|
|
10
|
+
* @param {string} params.address - The signer's address.
|
|
11
|
+
* @param {(data: Uint8Array) => Promise<Uint8Array>} params.signMessage - Required function to sign messages.
|
|
12
|
+
* @param {(data: Uint8Array) => Promise<Uint8Array>} [params.signTransaction] - Required function to sign transactions.
|
|
13
|
+
* @param {CHAIN} params.chain - The chain the signer will operate on.
|
|
14
|
+
* @returns {UniversalSigner} A signer object with chain metadata.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const signer = createUniversalSigner({
|
|
18
|
+
* chain: CHAIN.ETHEREUM_SEPOLIA
|
|
19
|
+
* address: "0xabc...",
|
|
20
|
+
* signMessage: async (data) => sign(data),
|
|
21
|
+
* signTransaction: async (data) => signRawTx(data),
|
|
22
|
+
* });
|
|
23
|
+
*/
|
|
24
|
+
export declare function createUniversalSigner({ chain, address, signMessage, signTransaction, signTypedData, }: UniversalSigner): UniversalSigner;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a UniversalSigner from either a viem WalletClient or Account instance.
|
|
27
|
+
*
|
|
28
|
+
* @param {WalletClient | Account} clientOrAccount - The viem WalletClient or Account instance
|
|
29
|
+
* @param {CHAIN} chain - The chain the signer will operate on
|
|
30
|
+
* @returns {Promise<UniversalSigner>} A signer object configured for the specified chain
|
|
31
|
+
*/
|
|
32
|
+
export declare function toUniversalFromViem(clientOrAccount: WalletClient | Account, chain: CHAIN): Promise<UniversalSigner>;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a UniversalSigner from a Solana Keypair.
|
|
35
|
+
*
|
|
36
|
+
* @param {Keypair} keypair - The Solana Keypair to create the signer from
|
|
37
|
+
* @param {CHAIN} chain - The chain the signer will operate on (should be a Solana chain)
|
|
38
|
+
* @returns {UniversalSigner} A signer object configured for Solana operations
|
|
39
|
+
*/
|
|
40
|
+
export declare function toUniversalFromSolanaKeypair(keypair: Keypair, chain: CHAIN): UniversalSigner;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createUniversalSigner = createUniversalSigner;
|
|
4
|
+
exports.toUniversalFromViem = toUniversalFromViem;
|
|
5
|
+
exports.toUniversalFromSolanaKeypair = toUniversalFromSolanaKeypair;
|
|
6
|
+
const tslib_1 = require("tslib");
|
|
7
|
+
const viem_1 = require("viem");
|
|
8
|
+
const account_1 = require("../account/account");
|
|
9
|
+
const enums_1 = require("../../constants/enums");
|
|
10
|
+
const nacl = tslib_1.__importStar(require("tweetnacl"));
|
|
11
|
+
/**
|
|
12
|
+
* Creates a `UniversalSigner` object for signing messages and transactions
|
|
13
|
+
* on any supported chain.
|
|
14
|
+
*
|
|
15
|
+
* @param {Object} params - The signer configuration object.
|
|
16
|
+
* @param {string} params.address - The signer's address.
|
|
17
|
+
* @param {(data: Uint8Array) => Promise<Uint8Array>} params.signMessage - Required function to sign messages.
|
|
18
|
+
* @param {(data: Uint8Array) => Promise<Uint8Array>} [params.signTransaction] - Required function to sign transactions.
|
|
19
|
+
* @param {CHAIN} params.chain - The chain the signer will operate on.
|
|
20
|
+
* @returns {UniversalSigner} A signer object with chain metadata.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const signer = createUniversalSigner({
|
|
24
|
+
* chain: CHAIN.ETHEREUM_SEPOLIA
|
|
25
|
+
* address: "0xabc...",
|
|
26
|
+
* signMessage: async (data) => sign(data),
|
|
27
|
+
* signTransaction: async (data) => signRawTx(data),
|
|
28
|
+
* });
|
|
29
|
+
*/
|
|
30
|
+
function createUniversalSigner({ chain, address, signMessage, signTransaction, signTypedData, }) {
|
|
31
|
+
return Object.assign(Object.assign({}, (0, account_1.createUniversalAccount)({ chain, address })), { signMessage,
|
|
32
|
+
signTransaction,
|
|
33
|
+
signTypedData });
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates a UniversalSigner from either a viem WalletClient or Account instance.
|
|
37
|
+
*
|
|
38
|
+
* @param {WalletClient | Account} clientOrAccount - The viem WalletClient or Account instance
|
|
39
|
+
* @param {CHAIN} chain - The chain the signer will operate on
|
|
40
|
+
* @returns {Promise<UniversalSigner>} A signer object configured for the specified chain
|
|
41
|
+
*/
|
|
42
|
+
function toUniversalFromViem(clientOrAccount, chain) {
|
|
43
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
let address;
|
|
45
|
+
let signMessage;
|
|
46
|
+
let signTransaction;
|
|
47
|
+
let signTypedData;
|
|
48
|
+
if ('getAddresses' in clientOrAccount) {
|
|
49
|
+
// It's a WalletClient
|
|
50
|
+
address = (yield clientOrAccount.getAddresses())[0];
|
|
51
|
+
signMessage = (data) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
const hexSig = yield clientOrAccount.signMessage({
|
|
53
|
+
account: clientOrAccount.account || address,
|
|
54
|
+
message: { raw: data },
|
|
55
|
+
});
|
|
56
|
+
return (0, viem_1.hexToBytes)(hexSig);
|
|
57
|
+
});
|
|
58
|
+
signTransaction = (unsignedTx) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const tx = (0, viem_1.parseTransaction)((0, viem_1.bytesToHex)(unsignedTx));
|
|
60
|
+
const txHash = yield clientOrAccount.signTransaction(tx);
|
|
61
|
+
return (0, viem_1.hexToBytes)(txHash);
|
|
62
|
+
});
|
|
63
|
+
signTypedData = (_a) => tslib_1.__awaiter(this, [_a], void 0, function* ({ domain, types, primaryType, message, }) {
|
|
64
|
+
const hexSig = yield clientOrAccount.signTypedData({
|
|
65
|
+
domain,
|
|
66
|
+
types,
|
|
67
|
+
primaryType,
|
|
68
|
+
message,
|
|
69
|
+
account: clientOrAccount.account || address,
|
|
70
|
+
});
|
|
71
|
+
return (0, viem_1.hexToBytes)(hexSig);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
// It's an Account
|
|
76
|
+
if (!clientOrAccount.address ||
|
|
77
|
+
!clientOrAccount.signMessage ||
|
|
78
|
+
!clientOrAccount.signTransaction) {
|
|
79
|
+
throw new Error('Invalid Account instance: missing required properties');
|
|
80
|
+
}
|
|
81
|
+
address = clientOrAccount.address;
|
|
82
|
+
signMessage = (data) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
const hexSig = yield clientOrAccount.signMessage({
|
|
84
|
+
message: { raw: data },
|
|
85
|
+
});
|
|
86
|
+
return (0, viem_1.hexToBytes)(hexSig);
|
|
87
|
+
});
|
|
88
|
+
signTransaction = (unsignedTx) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
const tx = (0, viem_1.parseTransaction)((0, viem_1.bytesToHex)(unsignedTx));
|
|
90
|
+
const hexSig = yield clientOrAccount.signTransaction(tx);
|
|
91
|
+
return (0, viem_1.hexToBytes)(hexSig);
|
|
92
|
+
});
|
|
93
|
+
signTypedData = (_a) => tslib_1.__awaiter(this, [_a], void 0, function* ({ domain, types, primaryType, message, }) {
|
|
94
|
+
const hexSig = yield clientOrAccount.signTypedData({
|
|
95
|
+
domain,
|
|
96
|
+
types,
|
|
97
|
+
primaryType,
|
|
98
|
+
message,
|
|
99
|
+
});
|
|
100
|
+
return (0, viem_1.hexToBytes)(hexSig);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
const universalSigner = {
|
|
104
|
+
address,
|
|
105
|
+
chain,
|
|
106
|
+
signMessage,
|
|
107
|
+
signTransaction,
|
|
108
|
+
signTypedData,
|
|
109
|
+
};
|
|
110
|
+
return createUniversalSigner(universalSigner);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Creates a UniversalSigner from a Solana Keypair.
|
|
115
|
+
*
|
|
116
|
+
* @param {Keypair} keypair - The Solana Keypair to create the signer from
|
|
117
|
+
* @param {CHAIN} chain - The chain the signer will operate on (should be a Solana chain)
|
|
118
|
+
* @returns {UniversalSigner} A signer object configured for Solana operations
|
|
119
|
+
*/
|
|
120
|
+
function toUniversalFromSolanaKeypair(keypair, chain) {
|
|
121
|
+
if (chain !== enums_1.CHAIN.SOLANA_MAINNET &&
|
|
122
|
+
chain !== enums_1.CHAIN.SOLANA_TESTNET &&
|
|
123
|
+
chain !== enums_1.CHAIN.SOLANA_DEVNET) {
|
|
124
|
+
throw new Error('Invalid chain for Solana Keypair');
|
|
125
|
+
}
|
|
126
|
+
const universalSigner = {
|
|
127
|
+
address: keypair.publicKey.toBase58(),
|
|
128
|
+
chain,
|
|
129
|
+
signMessage: (data) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
return nacl.sign.detached(data, keypair.secretKey);
|
|
131
|
+
}),
|
|
132
|
+
signTransaction: (unsignedTx) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
return nacl.sign.detached(unsignedTx, keypair.secretKey);
|
|
134
|
+
}),
|
|
135
|
+
};
|
|
136
|
+
return createUniversalSigner(universalSigner);
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=signer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../../../../../../../packages/core/src/lib/universal/signer/signer.ts"],"names":[],"mappings":";;AAkCA,sDAaC;AASD,kDAwGC;AASD,oEAsBC;;AA/LD,+BAQc;AACd,gDAA4D;AAE5D,iDAA8C;AAC9C,wDAAkC;AAGlC;;;;;;;;;;;;;;;;;;G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C;YAC5B,CAAC,CAAA,CAAC;QACJ,CAAC;QAED,MAAM,eAAe,GAAoB;YACvC,OAAO;YACP,KAAK;YACL,WAAW;YACX,eAAe;YACf,aAAa;SACd,CAAC;QACF,OAAO,qBAAqB,CAAC,eAAe,CAAC,CAAC;IAChD,CAAC;CAAA;AAED;;;;;;GAMG;AACH,SAAgB,4BAA4B,CAC1C,OAAgB,EAChB,KAAY;IAEZ,IACE,KAAK,KAAK,aAAK,CAAC,cAAc;QAC9B,KAAK,KAAK,aAAK,CAAC,cAAc;QAC9B,KAAK,KAAK,aAAK,CAAC,aAAa,EAC7B,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACtD,CAAC;IACD,MAAM,eAAe,GAAoB;QACvC,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,QAAQ,EAAE;QACrC,KAAK;QACL,WAAW,EAAE,CAAO,IAAgB,EAAE,EAAE;YACtC,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QACrD,CAAC,CAAA;QACD,eAAe,EAAE,CAAO,UAAsB,EAAE,EAAE;YAChD,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QAC3D,CAAC,CAAA;KACF,CAAC;IACF,OAAO,qBAAqB,CAAC,eAAe,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { TypedData, TypedDataDomain } from 'viem';
|
|
2
|
+
import { CHAIN } from '../constants/enums';
|
|
3
|
+
/**
|
|
4
|
+
* A chain-agnostic account representation.
|
|
5
|
+
* Used to represent a wallet address along with its chain context.
|
|
6
|
+
*/
|
|
7
|
+
export interface UniversalAccount {
|
|
8
|
+
/**
|
|
9
|
+
* Fully qualified chain (e.g., CHAIN.ETHEREUM_SEPOLIA, CHAIN.SOLANA_DEVNET)
|
|
10
|
+
*/
|
|
11
|
+
chain: CHAIN;
|
|
12
|
+
/**
|
|
13
|
+
* The address on the respective chain (EVM: checksummed, Solana: base58, etc.)
|
|
14
|
+
*/
|
|
15
|
+
address: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A signer capable of signing messages for a specific chain.
|
|
19
|
+
* Used to abstract away signing across multiple VM types.
|
|
20
|
+
*/
|
|
21
|
+
export interface UniversalSigner extends UniversalAccount {
|
|
22
|
+
/**
|
|
23
|
+
* Signs an arbitrary data, provided as binary data.
|
|
24
|
+
*
|
|
25
|
+
* If data is a **string**, you MUST UTF-8 encode it before calling this method.
|
|
26
|
+
* @param data - The message to sign, as a Uint8Array.
|
|
27
|
+
* @returns A Promise that resolves to the signature (as a Uint8Array).
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const encoded = new TextEncoder().encode("hello world");
|
|
31
|
+
* const signature = await signer.signMessage(encoded);
|
|
32
|
+
*/
|
|
33
|
+
signMessage: (data: Uint8Array) => Promise<Uint8Array>;
|
|
34
|
+
/**
|
|
35
|
+
* Signs an typed data, provided as binary data.
|
|
36
|
+
* @dev !! Only Required for Evm Signers !!
|
|
37
|
+
*
|
|
38
|
+
* @param data - The message to sign, as a Uint8Array.
|
|
39
|
+
* @returns A Promise that resolves to the signature (as a Uint8Array).
|
|
40
|
+
*/
|
|
41
|
+
signTypedData?: ({ domain, types, primaryType, message, }: {
|
|
42
|
+
domain: TypedDataDomain;
|
|
43
|
+
types: TypedData;
|
|
44
|
+
primaryType: string;
|
|
45
|
+
message: Record<string, any>;
|
|
46
|
+
}) => Promise<Uint8Array>;
|
|
47
|
+
/**
|
|
48
|
+
* Signs a transaction (unsigned tx bytes).
|
|
49
|
+
* Used for sending on-chain transactions.
|
|
50
|
+
*/
|
|
51
|
+
signTransaction: (unsignedTx: Uint8Array) => Promise<Uint8Array>;
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"universal.types.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/universal/universal.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { toChainAgnostic, toUniversal as toUniversalAccount } from './universal/account';
|
|
2
|
+
import { toUniversalFromSolanaKeypair, toUniversalFromViem } from './universal/signer';
|
|
3
|
+
/**
|
|
4
|
+
* @dev - THESE UTILS ARE EXPORTED TO SDK CONSUMER
|
|
5
|
+
* @dev - Make sure each exported fn has good comments to help out sdk consumer
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Utility class for handling CAIP-10 chain-agnostic address formatting
|
|
9
|
+
* and universal account conversions.
|
|
10
|
+
*/
|
|
11
|
+
export declare class Utils {
|
|
12
|
+
static account: {
|
|
13
|
+
/**
|
|
14
|
+
* Converts a UniversalAccount into a CAIP-10 style address string.
|
|
15
|
+
*
|
|
16
|
+
* Format: `namespace:chainId:address`
|
|
17
|
+
* Namespace is derived from the chain's VM type using VM_NAMESPACE.
|
|
18
|
+
*
|
|
19
|
+
* @param {UniversalAccount} account - The account to convert.
|
|
20
|
+
* @returns {string} A CAIP-10 formatted string.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* Utils.account.toChainAgnostic({
|
|
24
|
+
* chain: CHAIN.ETHEREUM_SEPOLIA,
|
|
25
|
+
* address: '0xabc'
|
|
26
|
+
* })
|
|
27
|
+
* // → 'eip155:11155111:0xabc'
|
|
28
|
+
*/
|
|
29
|
+
toChainAgnostic: typeof toChainAgnostic;
|
|
30
|
+
/**
|
|
31
|
+
* Converts a CAIP-10 formatted string into a UniversalAccount.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} caip - A CAIP-10 address string (e.g., 'eip155:1:0xabc...').
|
|
34
|
+
* @returns {UniversalAccount} The resolved account.
|
|
35
|
+
* @throws {Error} If the CAIP string is invalid or unsupported.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* Utils.account.toUniversal('eip155:11155111:0xabc...')
|
|
39
|
+
* // → { chain: CHAIN.ETHEREUM_SEPOLIA, address: '0xabc...' }
|
|
40
|
+
*/
|
|
41
|
+
toUniversal: typeof toUniversalAccount;
|
|
42
|
+
};
|
|
43
|
+
static signer: {
|
|
44
|
+
/**
|
|
45
|
+
* Wraps a viem WalletClient into a UniversalSigner.
|
|
46
|
+
*/
|
|
47
|
+
toUniversalFromViem: typeof toUniversalFromViem;
|
|
48
|
+
/**
|
|
49
|
+
* Wraps a Solana Keypair into a UniversalSigner.
|
|
50
|
+
*/
|
|
51
|
+
toUniversalFromSolanaKeypair: typeof toUniversalFromSolanaKeypair;
|
|
52
|
+
};
|
|
53
|
+
}
|
package/src/lib/utils.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Utils = void 0;
|
|
4
|
+
const account_1 = require("./universal/account");
|
|
5
|
+
const signer_1 = require("./universal/signer");
|
|
6
|
+
/**
|
|
7
|
+
* @dev - THESE UTILS ARE EXPORTED TO SDK CONSUMER
|
|
8
|
+
* @dev - Make sure each exported fn has good comments to help out sdk consumer
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Utility class for handling CAIP-10 chain-agnostic address formatting
|
|
12
|
+
* and universal account conversions.
|
|
13
|
+
*/
|
|
14
|
+
class Utils {
|
|
15
|
+
}
|
|
16
|
+
exports.Utils = Utils;
|
|
17
|
+
Utils.account = {
|
|
18
|
+
/**
|
|
19
|
+
* Converts a UniversalAccount into a CAIP-10 style address string.
|
|
20
|
+
*
|
|
21
|
+
* Format: `namespace:chainId:address`
|
|
22
|
+
* Namespace is derived from the chain's VM type using VM_NAMESPACE.
|
|
23
|
+
*
|
|
24
|
+
* @param {UniversalAccount} account - The account to convert.
|
|
25
|
+
* @returns {string} A CAIP-10 formatted string.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* Utils.account.toChainAgnostic({
|
|
29
|
+
* chain: CHAIN.ETHEREUM_SEPOLIA,
|
|
30
|
+
* address: '0xabc'
|
|
31
|
+
* })
|
|
32
|
+
* // → 'eip155:11155111:0xabc'
|
|
33
|
+
*/
|
|
34
|
+
toChainAgnostic: account_1.toChainAgnostic,
|
|
35
|
+
/**
|
|
36
|
+
* Converts a CAIP-10 formatted string into a UniversalAccount.
|
|
37
|
+
*
|
|
38
|
+
* @param {string} caip - A CAIP-10 address string (e.g., 'eip155:1:0xabc...').
|
|
39
|
+
* @returns {UniversalAccount} The resolved account.
|
|
40
|
+
* @throws {Error} If the CAIP string is invalid or unsupported.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* Utils.account.toUniversal('eip155:11155111:0xabc...')
|
|
44
|
+
* // → { chain: CHAIN.ETHEREUM_SEPOLIA, address: '0xabc...' }
|
|
45
|
+
*/
|
|
46
|
+
toUniversal: account_1.toUniversal,
|
|
47
|
+
};
|
|
48
|
+
Utils.signer = {
|
|
49
|
+
/**
|
|
50
|
+
* Wraps a viem WalletClient into a UniversalSigner.
|
|
51
|
+
*/
|
|
52
|
+
toUniversalFromViem: signer_1.toUniversalFromViem,
|
|
53
|
+
/**
|
|
54
|
+
* Wraps a Solana Keypair into a UniversalSigner.
|
|
55
|
+
*/
|
|
56
|
+
toUniversalFromSolanaKeypair: signer_1.toUniversalFromSolanaKeypair,
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../packages/core/src/lib/utils.ts"],"names":[],"mappings":";;;AAAA,iDAG6B;AAC7B,+CAG4B;AAE5B;;;GAGG;AAEH;;;GAGG;AACH,MAAa,KAAK;;AAAlB,sBA6CC;AA5CQ,aAAO,GAAG;IACf;;;;;;;;;;;;;;;OAeG;IACH,eAAe,EAAf,yBAAe;IAEf;;;;;;;;;;OAUG;IACH,WAAW,EAAE,qBAAkB;CAChC,CAAC;AAEK,YAAM,GAAG;IACd;;OAEG;IACH,mBAAmB,EAAnB,4BAAmB;IAEnB;;OAEG;IACH,4BAA4B,EAA5B,qCAA4B;CAC7B,CAAC"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { UniversalSigner } from '../universal/universal.types';
|
|
2
|
+
import { ClientOptions, ReadContractParams, WriteContractParams } from './vm-client.types';
|
|
3
|
+
import { PublicClient, Hex } from 'viem';
|
|
4
|
+
/**
|
|
5
|
+
* EVM client for reading and writing to Ethereum-compatible chains
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* // Initialize with an RPC URL
|
|
9
|
+
* const evmClient = new EvmClient({
|
|
10
|
+
* rpcUrl: 'https://eth-sepolia.g.alchemy.com/v2/your-api-key'
|
|
11
|
+
* });
|
|
12
|
+
*/
|
|
13
|
+
export declare class EvmClient {
|
|
14
|
+
publicClient: PublicClient;
|
|
15
|
+
constructor({ rpcUrl }: ClientOptions);
|
|
16
|
+
/**
|
|
17
|
+
* Returns the balance (in wei) of an EVM address.
|
|
18
|
+
*
|
|
19
|
+
* @param address - The EVM address to check balance for
|
|
20
|
+
* @returns Balance as a bigint in wei
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // Get balance of an address
|
|
24
|
+
* const balance = await evmClient.getBalance('0x123...');
|
|
25
|
+
* console.log(`Balance: ${balance} wei`);
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* // Check if an address has zero balance
|
|
29
|
+
* const newAddress = privateKeyToAccount(generatePrivateKey()).address;
|
|
30
|
+
* const balance = await evmClient.getBalance(newAddress);
|
|
31
|
+
* if (balance === BigInt(0)) {
|
|
32
|
+
* console.log('Address has no funds');
|
|
33
|
+
* }
|
|
34
|
+
*/
|
|
35
|
+
getBalance(address: `0x${string}`): Promise<bigint>;
|
|
36
|
+
/**
|
|
37
|
+
* Performs a read-only call to a smart contract.
|
|
38
|
+
*
|
|
39
|
+
* @param params - Parameters including ABI, contract address, function name, and args
|
|
40
|
+
* @returns The result of the contract call with the specified type
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* // Read a greeting value from a contract
|
|
44
|
+
* const greeting = await evmClient.readContract<string>({
|
|
45
|
+
* abi: parseAbi(['function greet() view returns (string)']),
|
|
46
|
+
* address: '0x2ba5873eF818BEE57645B7d674149041C44F42c6',
|
|
47
|
+
* functionName: 'greet',
|
|
48
|
+
* });
|
|
49
|
+
* console.log(`Current greeting: ${greeting}`);
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* // Reading with arguments
|
|
53
|
+
* const balance = await evmClient.readContract<bigint>({
|
|
54
|
+
* abi: parseAbi(['function balanceOf(address) view returns (uint256)']),
|
|
55
|
+
* address: '0xTokenAddress',
|
|
56
|
+
* functionName: 'balanceOf',
|
|
57
|
+
* args: ['0xUserAddress'],
|
|
58
|
+
* });
|
|
59
|
+
*/
|
|
60
|
+
readContract<T = unknown>({ abi, address, functionName, args, }: ReadContractParams): Promise<T>;
|
|
61
|
+
/**
|
|
62
|
+
* Writes a transaction to a smart contract using a UniversalSigner.
|
|
63
|
+
* This function handles contract interaction by encoding function data
|
|
64
|
+
* and sending the transaction through sendTransaction.
|
|
65
|
+
*
|
|
66
|
+
* @param params - Parameters including ABI, contract address, function name, args, value and signer
|
|
67
|
+
* @returns Transaction hash as a hex string
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* // Set a new greeting on a contract
|
|
71
|
+
* const txHash = await evmClient.writeContract({
|
|
72
|
+
* abi: parseAbi(['function setGreeting(string _greeting)']),
|
|
73
|
+
* address: '0x2ba5873eF818BEE57645B7d674149041C44F42c6',
|
|
74
|
+
* functionName: 'setGreeting',
|
|
75
|
+
* args: ['Hello from Push SDK!'],
|
|
76
|
+
* signer: universalSigner,
|
|
77
|
+
* });
|
|
78
|
+
* console.log(`Transaction sent: ${txHash}`);
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* // Sending ether with a contract interaction
|
|
82
|
+
* const txHash = await evmClient.writeContract({
|
|
83
|
+
* abi: parseAbi(['function deposit() payable']),
|
|
84
|
+
* address: '0xContractAddress',
|
|
85
|
+
* functionName: 'deposit',
|
|
86
|
+
* value: parseEther('0.1'), // Send 0.1 ETH
|
|
87
|
+
* signer: universalSigner,
|
|
88
|
+
* });
|
|
89
|
+
*/
|
|
90
|
+
writeContract({ abi, address, functionName, args, value, signer, }: WriteContractParams): Promise<Hex>;
|
|
91
|
+
/**
|
|
92
|
+
* Sends a raw EVM transaction using a UniversalSigner.
|
|
93
|
+
* This handles the full transaction flow:
|
|
94
|
+
* 1. Gets nonce, estimates gas, and gets current fee data
|
|
95
|
+
* 2. Serializes and signs the transaction
|
|
96
|
+
* 3. Broadcasts the signed transaction to the network
|
|
97
|
+
*
|
|
98
|
+
* @param params - Transaction parameters including destination, data, value and signer
|
|
99
|
+
* @returns Transaction hash as a hex string
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* // Send a simple ETH transfer
|
|
103
|
+
* const txHash = await evmClient.sendTransaction({
|
|
104
|
+
* to: '0xRecipientAddress',
|
|
105
|
+
* data: '0x', // empty data for a simple transfer
|
|
106
|
+
* value: parseEther('0.01'),
|
|
107
|
+
* signer: universalSigner,
|
|
108
|
+
* });
|
|
109
|
+
* console.log(`ETH transfer sent: ${txHash}`);
|
|
110
|
+
*/
|
|
111
|
+
sendTransaction({ to, data, value, signer, }: {
|
|
112
|
+
to: `0x${string}`;
|
|
113
|
+
data: Hex;
|
|
114
|
+
value?: bigint;
|
|
115
|
+
signer: UniversalSigner;
|
|
116
|
+
}): Promise<Hex>;
|
|
117
|
+
/**
|
|
118
|
+
* Estimates the gas required for a transaction.
|
|
119
|
+
*
|
|
120
|
+
* @param params - Parameters including from/to addresses, value and optional data
|
|
121
|
+
* @returns Estimated gas as a bigint
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* // Estimate gas for a simple transfer
|
|
125
|
+
* const gasEstimate = await evmClient.estimateGas({
|
|
126
|
+
* from: '0xSenderAddress',
|
|
127
|
+
* to: '0xRecipientAddress',
|
|
128
|
+
* value: parseEther('0.01'),
|
|
129
|
+
* });
|
|
130
|
+
* console.log(`Estimated gas: ${gasEstimate}`);
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* // Estimate gas for a contract interaction
|
|
134
|
+
* const data = encodeFunctionData({
|
|
135
|
+
* abi: parseAbi(['function setGreeting(string)']),
|
|
136
|
+
* functionName: 'setGreeting',
|
|
137
|
+
* args: ['New greeting'],
|
|
138
|
+
* });
|
|
139
|
+
*
|
|
140
|
+
* const gasEstimate = await evmClient.estimateGas({
|
|
141
|
+
* from: universalSigner.address as `0x${string}`,
|
|
142
|
+
* to: '0xContractAddress',
|
|
143
|
+
* data,
|
|
144
|
+
* value: BigInt(0),
|
|
145
|
+
* });
|
|
146
|
+
*/
|
|
147
|
+
estimateGas({ from, to, value, data, }: {
|
|
148
|
+
from?: `0x${string}`;
|
|
149
|
+
to: `0x${string}`;
|
|
150
|
+
value?: bigint;
|
|
151
|
+
data?: `0x${string}`;
|
|
152
|
+
}): Promise<bigint>;
|
|
153
|
+
/**
|
|
154
|
+
* Gets the current gas price on the network.
|
|
155
|
+
* This is primarily used for legacy transactions, but can be useful
|
|
156
|
+
* for gas cost estimation in EIP-1559 transactions as well.
|
|
157
|
+
*
|
|
158
|
+
* @returns Current gas price in wei as a bigint
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* // Get current gas price for cost estimation
|
|
162
|
+
* const gasPrice = await evmClient.getGasPrice();
|
|
163
|
+
* console.log(`Current gas price: ${gasPrice} wei`);
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* // Calculate total cost of a transaction
|
|
167
|
+
* const gasPrice = await evmClient.getGasPrice();
|
|
168
|
+
* const gasEstimate = await evmClient.estimateGas({...});
|
|
169
|
+
* const totalCost = gasPrice * gasEstimate;
|
|
170
|
+
* console.log(`Estimated transaction cost: ${totalCost} wei`);
|
|
171
|
+
*/
|
|
172
|
+
getGasPrice(): Promise<bigint>;
|
|
173
|
+
}
|