@4mica/sdk 1.2.3 → 1.2.5
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 +6 -5
- package/dist/abi/core4mica.d.ts +492 -9
- package/dist/abi/core4mica.js +649 -19
- package/dist/client/user.d.ts +3 -1
- package/dist/client/user.js +2 -2
- package/dist/config.d.ts +4 -4
- package/dist/config.js +6 -6
- package/dist/contract.d.ts +3 -1
- package/dist/contract.js +7 -3
- package/dist/networks.d.ts +4 -4
- package/dist/networks.js +8 -4
- package/package.json +4 -1
package/dist/client/user.d.ts
CHANGED
|
@@ -32,7 +32,9 @@ export declare class UserClient {
|
|
|
32
32
|
* locked collateral and any pending withdrawal.
|
|
33
33
|
* @throws {@link ContractError} if the contract call fails.
|
|
34
34
|
*/
|
|
35
|
-
getUser(
|
|
35
|
+
getUser(opts?: {
|
|
36
|
+
blockNumber?: bigint;
|
|
37
|
+
}): Promise<UserInfo[]>;
|
|
36
38
|
/**
|
|
37
39
|
* Query the on-chain payment status of a tab.
|
|
38
40
|
*
|
package/dist/client/user.js
CHANGED
|
@@ -43,8 +43,8 @@ class UserClient {
|
|
|
43
43
|
* locked collateral and any pending withdrawal.
|
|
44
44
|
* @throws {@link ContractError} if the contract call fails.
|
|
45
45
|
*/
|
|
46
|
-
async getUser() {
|
|
47
|
-
const assets = await this.client.gateway.getUserAssets();
|
|
46
|
+
async getUser(opts) {
|
|
47
|
+
const assets = await this.client.gateway.getUserAssets(opts);
|
|
48
48
|
return assets.map((a) => ({
|
|
49
49
|
asset: a.asset,
|
|
50
50
|
collateral: (0, utils_1.parseU256)(a.collateral),
|
package/dist/config.d.ts
CHANGED
|
@@ -48,15 +48,15 @@ export declare class ConfigBuilder {
|
|
|
48
48
|
* Resolves to the corresponding core API URL.
|
|
49
49
|
* Mutually exclusive with {@link rpcUrl} — last call wins.
|
|
50
50
|
*
|
|
51
|
-
* Supported values: `"base-sepolia"` / `"eip155:84532"`,
|
|
51
|
+
* Supported values: `"base"` / `"eip155:8453"`, `"base-sepolia"` / `"eip155:84532"`,
|
|
52
52
|
* `"ethereum-sepolia"` / `"eip155:11155111"`.
|
|
53
53
|
*
|
|
54
54
|
* @throws {@link ConfigError} if the network is not recognised.
|
|
55
55
|
*
|
|
56
56
|
* @example
|
|
57
57
|
* ```ts
|
|
58
|
-
* new ConfigBuilder().network("base
|
|
59
|
-
* new ConfigBuilder().network("eip155:
|
|
58
|
+
* new ConfigBuilder().network("base").walletPrivateKey("0x...").build();
|
|
59
|
+
* new ConfigBuilder().network("eip155:8453").walletPrivateKey("0x...").build();
|
|
60
60
|
* ```
|
|
61
61
|
*/
|
|
62
62
|
network(value: string): ConfigBuilder;
|
|
@@ -82,7 +82,7 @@ export declare class ConfigBuilder {
|
|
|
82
82
|
* Load configuration from environment variables.
|
|
83
83
|
*
|
|
84
84
|
* Recognised variables:
|
|
85
|
-
* - `4MICA_NETWORK` — shorthand or CAIP-2 id (e.g. `base
|
|
85
|
+
* - `4MICA_NETWORK` — shorthand or CAIP-2 id (e.g. `base`); takes precedence over `4MICA_RPC_URL`
|
|
86
86
|
* - `4MICA_RPC_URL`
|
|
87
87
|
* - `4MICA_WALLET_PRIVATE_KEY`
|
|
88
88
|
* - `4MICA_ETHEREUM_HTTP_RPC_URL`
|
package/dist/config.js
CHANGED
|
@@ -38,21 +38,21 @@ class ConfigBuilder {
|
|
|
38
38
|
* Resolves to the corresponding core API URL.
|
|
39
39
|
* Mutually exclusive with {@link rpcUrl} — last call wins.
|
|
40
40
|
*
|
|
41
|
-
* Supported values: `"base-sepolia"` / `"eip155:84532"`,
|
|
41
|
+
* Supported values: `"base"` / `"eip155:8453"`, `"base-sepolia"` / `"eip155:84532"`,
|
|
42
42
|
* `"ethereum-sepolia"` / `"eip155:11155111"`.
|
|
43
43
|
*
|
|
44
44
|
* @throws {@link ConfigError} if the network is not recognised.
|
|
45
45
|
*
|
|
46
46
|
* @example
|
|
47
47
|
* ```ts
|
|
48
|
-
* new ConfigBuilder().network("base
|
|
49
|
-
* new ConfigBuilder().network("eip155:
|
|
48
|
+
* new ConfigBuilder().network("base").walletPrivateKey("0x...").build();
|
|
49
|
+
* new ConfigBuilder().network("eip155:8453").walletPrivateKey("0x...").build();
|
|
50
50
|
* ```
|
|
51
51
|
*/
|
|
52
52
|
network(value) {
|
|
53
53
|
const url = (0, networks_1.resolveNetworkRpcUrl)(value);
|
|
54
54
|
if (!url) {
|
|
55
|
-
throw new errors_1.ConfigError(`unknown network "${value}". Use a known shorthand (e.g. "base
|
|
55
|
+
throw new errors_1.ConfigError(`unknown network "${value}". Use a known shorthand (e.g. "base") or CAIP-2 id, or call rpcUrl() directly.`);
|
|
56
56
|
}
|
|
57
57
|
this._rpcUrl = url;
|
|
58
58
|
return this;
|
|
@@ -108,7 +108,7 @@ class ConfigBuilder {
|
|
|
108
108
|
* Load configuration from environment variables.
|
|
109
109
|
*
|
|
110
110
|
* Recognised variables:
|
|
111
|
-
* - `4MICA_NETWORK` — shorthand or CAIP-2 id (e.g. `base
|
|
111
|
+
* - `4MICA_NETWORK` — shorthand or CAIP-2 id (e.g. `base`); takes precedence over `4MICA_RPC_URL`
|
|
112
112
|
* - `4MICA_RPC_URL`
|
|
113
113
|
* - `4MICA_WALLET_PRIVATE_KEY`
|
|
114
114
|
* - `4MICA_ETHEREUM_HTTP_RPC_URL`
|
|
@@ -122,7 +122,7 @@ class ConfigBuilder {
|
|
|
122
122
|
const env = process.env;
|
|
123
123
|
if (env['4MICA_NETWORK'])
|
|
124
124
|
this.network(env['4MICA_NETWORK']);
|
|
125
|
-
if (env['4MICA_RPC_URL'])
|
|
125
|
+
else if (env['4MICA_RPC_URL'])
|
|
126
126
|
this._rpcUrl = env['4MICA_RPC_URL'];
|
|
127
127
|
if (env['4MICA_WALLET_PRIVATE_KEY'])
|
|
128
128
|
this._walletPrivateKey = env['4MICA_WALLET_PRIVATE_KEY'];
|
package/dist/contract.d.ts
CHANGED
|
@@ -31,7 +31,9 @@ export declare class ContractGateway {
|
|
|
31
31
|
}>;
|
|
32
32
|
approveErc20(token: string, amount: number | bigint | string, waitOptions?: TxReceiptWaitOptions): Promise<import("viem").TransactionReceipt>;
|
|
33
33
|
deposit(amount: number | bigint | string, erc20Token?: string, waitOptions?: TxReceiptWaitOptions): Promise<import("viem").TransactionReceipt>;
|
|
34
|
-
getUserAssets(
|
|
34
|
+
getUserAssets(opts?: {
|
|
35
|
+
blockNumber?: bigint;
|
|
36
|
+
}): Promise<{
|
|
35
37
|
asset: `0x${string}`;
|
|
36
38
|
collateral: bigint;
|
|
37
39
|
withdrawalRequestTimestamp: bigint;
|
package/dist/contract.js
CHANGED
|
@@ -136,9 +136,13 @@ class ContractGateway {
|
|
|
136
136
|
}
|
|
137
137
|
// Verify the allowance was actually set on-chain. The catch path above can
|
|
138
138
|
// leave allowance at 0 if the re-approve transaction fails silently.
|
|
139
|
+
// Read at the confirmed block number so the result is consistent regardless
|
|
140
|
+
// of RPC node propagation lag.
|
|
139
141
|
const account = this.walletClient.account;
|
|
140
142
|
if (account) {
|
|
141
|
-
const actual = await erc20.read.allowance([account.address, spender]
|
|
143
|
+
const actual = (await erc20.read.allowance([account.address, spender], {
|
|
144
|
+
blockNumber: txReceipt.blockNumber,
|
|
145
|
+
}));
|
|
142
146
|
if (actual < targetAllowance) {
|
|
143
147
|
throw new errors_1.ContractError(`ERC20 allowance verification failed: on-chain allowance is ${actual} but expected ${targetAllowance}. ` +
|
|
144
148
|
`Try calling approveErc20 again.`);
|
|
@@ -181,13 +185,13 @@ class ContractGateway {
|
|
|
181
185
|
}
|
|
182
186
|
return this.publicClient.waitForTransactionReceipt({ hash, ...receipt });
|
|
183
187
|
}
|
|
184
|
-
async getUserAssets() {
|
|
188
|
+
async getUserAssets(opts) {
|
|
185
189
|
const account = this.walletClient.account;
|
|
186
190
|
if (!account) {
|
|
187
191
|
throw new errors_1.ContractError('wallet client has no account configured');
|
|
188
192
|
}
|
|
189
193
|
const addr = account.address;
|
|
190
|
-
const result = await this.contract.read.getUserAllAssets([addr]);
|
|
194
|
+
const result = await this.contract.read.getUserAllAssets([addr], opts);
|
|
191
195
|
return result.map((a) => ({
|
|
192
196
|
asset: a.asset,
|
|
193
197
|
collateral: a.collateral,
|
package/dist/networks.d.ts
CHANGED
|
@@ -17,12 +17,12 @@ export interface NetworkInfo {
|
|
|
17
17
|
*
|
|
18
18
|
* // By shorthand
|
|
19
19
|
* const cfg = new ConfigBuilder()
|
|
20
|
-
* .network("base
|
|
20
|
+
* .network("base")
|
|
21
21
|
* .walletPrivateKey("0x...")
|
|
22
22
|
* .build();
|
|
23
23
|
*
|
|
24
24
|
* // Inspect available networks
|
|
25
|
-
* console.log(NETWORKS["base
|
|
25
|
+
* console.log(NETWORKS["base"].caip2); // "eip155:8453"
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
28
|
export declare const NETWORKS: Record<string, NetworkInfo>;
|
|
@@ -32,8 +32,8 @@ export declare const NETWORKS: Record<string, NetworkInfo>;
|
|
|
32
32
|
*
|
|
33
33
|
* @example
|
|
34
34
|
* ```ts
|
|
35
|
-
* resolveNetworkRpcUrl("base
|
|
36
|
-
* resolveNetworkRpcUrl("eip155:
|
|
35
|
+
* resolveNetworkRpcUrl("base"); // "https://base.api.4mica.xyz/"
|
|
36
|
+
* resolveNetworkRpcUrl("eip155:8453"); // "https://base.api.4mica.xyz/"
|
|
37
37
|
* resolveNetworkRpcUrl("eip155:1"); // undefined
|
|
38
38
|
* ```
|
|
39
39
|
*/
|
package/dist/networks.js
CHANGED
|
@@ -14,15 +14,19 @@ exports.resolveNetworkRpcUrl = resolveNetworkRpcUrl;
|
|
|
14
14
|
*
|
|
15
15
|
* // By shorthand
|
|
16
16
|
* const cfg = new ConfigBuilder()
|
|
17
|
-
* .network("base
|
|
17
|
+
* .network("base")
|
|
18
18
|
* .walletPrivateKey("0x...")
|
|
19
19
|
* .build();
|
|
20
20
|
*
|
|
21
21
|
* // Inspect available networks
|
|
22
|
-
* console.log(NETWORKS["base
|
|
22
|
+
* console.log(NETWORKS["base"].caip2); // "eip155:8453"
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
25
|
exports.NETWORKS = {
|
|
26
|
+
base: {
|
|
27
|
+
caip2: 'eip155:8453',
|
|
28
|
+
rpcUrl: 'https://base.api.4mica.xyz/',
|
|
29
|
+
},
|
|
26
30
|
'base-sepolia': {
|
|
27
31
|
caip2: 'eip155:84532',
|
|
28
32
|
rpcUrl: 'https://base.sepolia.api.4mica.xyz/',
|
|
@@ -39,8 +43,8 @@ const NETWORKS_BY_CAIP2 = Object.fromEntries(Object.values(exports.NETWORKS).map
|
|
|
39
43
|
*
|
|
40
44
|
* @example
|
|
41
45
|
* ```ts
|
|
42
|
-
* resolveNetworkRpcUrl("base
|
|
43
|
-
* resolveNetworkRpcUrl("eip155:
|
|
46
|
+
* resolveNetworkRpcUrl("base"); // "https://base.api.4mica.xyz/"
|
|
47
|
+
* resolveNetworkRpcUrl("eip155:8453"); // "https://base.api.4mica.xyz/"
|
|
44
48
|
* resolveNetworkRpcUrl("eip155:1"); // undefined
|
|
45
49
|
* ```
|
|
46
50
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@4mica/sdk",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"description": "TypeScript SDK for interacting with the 4Mica payment network",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -45,6 +45,9 @@
|
|
|
45
45
|
"test:e2e": "vitest run --config vitest.e2e.config.ts",
|
|
46
46
|
"example:base-sepolia:x402-v2": "node_modules/.bin/tsx examples/base-sepolia-x402-facilitator-e2e.ts",
|
|
47
47
|
"example:manual:agents": "node_modules/.bin/tsx examples/manual-agents/demo.ts",
|
|
48
|
+
"example:wachai:v2": "node_modules/.bin/tsx examples/wachai-v2-demo/demo.ts",
|
|
49
|
+
"example:deposit": "node_modules/.bin/tsx examples/deposit.ts",
|
|
50
|
+
"example:yield": "node_modules/.bin/tsx examples/yield.ts",
|
|
48
51
|
"lint": "eslint . --ext .ts",
|
|
49
52
|
"fmt": "prettier --check \"{src,tests}/**/*.{ts,js,json}\""
|
|
50
53
|
},
|