@4mica/sdk 1.0.0 → 1.0.1
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 +17 -0
- package/dist/contract.d.ts +1 -0
- package/dist/contract.js +20 -10
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -144,6 +144,23 @@ The SDK exposes three main entry points:
|
|
|
144
144
|
- `client.recipient`: recipient-side operations (tabs, guarantees, remuneration)
|
|
145
145
|
- `X402Flow`: helper for 402-protected HTTP resources
|
|
146
146
|
|
|
147
|
+
### End-to-end Example (Base Sepolia + x402 v2)
|
|
148
|
+
|
|
149
|
+
See `examples/base-sepolia-x402-facilitator-e2e.ts` for a full flow in the `examples` folder:
|
|
150
|
+
- deposit collateral
|
|
151
|
+
- create/get a tab via facilitator
|
|
152
|
+
- issue and verify V1 + V2 guarantees
|
|
153
|
+
- `payTab` in ERC20 for V1
|
|
154
|
+
- remunerate V2 only after `wachai-validation-sdk` returns a passing ERC-8004 validation
|
|
155
|
+
- submit + finalize withdrawal
|
|
156
|
+
|
|
157
|
+
Run it with:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
cp examples/.env.x402-facilitator-e2e.example examples/.env.x402-facilitator-e2e
|
|
161
|
+
npx dotenv-cli -e examples/.env.x402-facilitator-e2e -- npm run example:base-sepolia:x402-v2
|
|
162
|
+
```
|
|
163
|
+
|
|
147
164
|
### X402 flow (HTTP 402)
|
|
148
165
|
|
|
149
166
|
The X402 helper turns `paymentRequirements` from a `402 Payment Required` response into an
|
package/dist/contract.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export declare class ContractGateway {
|
|
|
21
21
|
static create(rpcUrl: string, signer: Account, contractAddress: Hex, chainId: number): Promise<ContractGateway>;
|
|
22
22
|
private erc20;
|
|
23
23
|
private enqueueTx;
|
|
24
|
+
private defaultFeeParams;
|
|
24
25
|
private splitWaitOptions;
|
|
25
26
|
getGuaranteeDomain(): Promise<string>;
|
|
26
27
|
getGuaranteeVersionConfig(version: number): Promise<{
|
package/dist/contract.js
CHANGED
|
@@ -7,6 +7,8 @@ const chain_1 = require("./chain");
|
|
|
7
7
|
const errors_1 = require("./errors");
|
|
8
8
|
const utils_1 = require("./utils");
|
|
9
9
|
const DEFAULT_REMUNERATE_GAS_LIMIT = 8000000n;
|
|
10
|
+
const DEFAULT_MAX_FEE_PER_GAS = (0, viem_1.parseGwei)('0.1');
|
|
11
|
+
const DEFAULT_MAX_PRIORITY_FEE_PER_GAS = (0, viem_1.parseGwei)('0.1');
|
|
10
12
|
class ContractGateway {
|
|
11
13
|
publicClient;
|
|
12
14
|
walletClient;
|
|
@@ -58,6 +60,12 @@ class ContractGateway {
|
|
|
58
60
|
this.txQueue = run.then(() => undefined, () => undefined);
|
|
59
61
|
return run;
|
|
60
62
|
}
|
|
63
|
+
defaultFeeParams() {
|
|
64
|
+
return {
|
|
65
|
+
maxFeePerGas: DEFAULT_MAX_FEE_PER_GAS,
|
|
66
|
+
maxPriorityFeePerGas: DEFAULT_MAX_PRIORITY_FEE_PER_GAS,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
61
69
|
splitWaitOptions(waitOptions) {
|
|
62
70
|
if (!waitOptions) {
|
|
63
71
|
return { receipt: {} };
|
|
@@ -83,17 +91,17 @@ class ContractGateway {
|
|
|
83
91
|
const erc20 = this.erc20(token);
|
|
84
92
|
// spender address logic
|
|
85
93
|
const spender = this.contract.address;
|
|
86
|
-
const hash = await this.enqueueTx(() => erc20.write.approve([spender, (0, utils_1.parseU256)(amount)]));
|
|
94
|
+
const hash = await this.enqueueTx(() => erc20.write.approve([spender, (0, utils_1.parseU256)(amount)], this.defaultFeeParams()));
|
|
87
95
|
return this.publicClient.waitForTransactionReceipt({ hash, ...receipt });
|
|
88
96
|
}
|
|
89
97
|
async deposit(amount, erc20Token, waitOptions) {
|
|
90
98
|
const { receipt } = this.splitWaitOptions(waitOptions);
|
|
91
99
|
let hash;
|
|
92
100
|
if (erc20Token) {
|
|
93
|
-
hash = await this.enqueueTx(() => this.contract.write.depositStablecoin([erc20Token, (0, utils_1.parseU256)(amount)]));
|
|
101
|
+
hash = await this.enqueueTx(() => this.contract.write.depositStablecoin([erc20Token, (0, utils_1.parseU256)(amount)], this.defaultFeeParams()));
|
|
94
102
|
}
|
|
95
103
|
else {
|
|
96
|
-
hash = await this.enqueueTx(() => this.contract.write.deposit({ value: (0, utils_1.parseU256)(amount) }));
|
|
104
|
+
hash = await this.enqueueTx(() => this.contract.write.deposit({ value: (0, utils_1.parseU256)(amount), ...this.defaultFeeParams() }));
|
|
97
105
|
}
|
|
98
106
|
return this.publicClient.waitForTransactionReceipt({ hash, ...receipt });
|
|
99
107
|
}
|
|
@@ -128,6 +136,7 @@ class ContractGateway {
|
|
|
128
136
|
to: recipient,
|
|
129
137
|
value: (0, utils_1.parseU256)(amount),
|
|
130
138
|
data: (0, utils_1.hexFromBytes)(data),
|
|
139
|
+
...this.defaultFeeParams(),
|
|
131
140
|
}));
|
|
132
141
|
return this.publicClient.waitForTransactionReceipt({ hash, ...receipt });
|
|
133
142
|
}
|
|
@@ -138,7 +147,7 @@ class ContractGateway {
|
|
|
138
147
|
erc20Token,
|
|
139
148
|
(0, utils_1.parseU256)(amount),
|
|
140
149
|
recipient,
|
|
141
|
-
]));
|
|
150
|
+
], this.defaultFeeParams()));
|
|
142
151
|
return this.publicClient.waitForTransactionReceipt({ hash, ...receipt });
|
|
143
152
|
}
|
|
144
153
|
async requestWithdrawal(amount, erc20Token, waitOptions) {
|
|
@@ -146,10 +155,10 @@ class ContractGateway {
|
|
|
146
155
|
const value = (0, utils_1.parseU256)(amount);
|
|
147
156
|
let hash;
|
|
148
157
|
if (erc20Token) {
|
|
149
|
-
hash = await this.enqueueTx(() => this.contract.write.requestWithdrawal([erc20Token, value]));
|
|
158
|
+
hash = await this.enqueueTx(() => this.contract.write.requestWithdrawal([erc20Token, value], this.defaultFeeParams()));
|
|
150
159
|
}
|
|
151
160
|
else {
|
|
152
|
-
hash = await this.enqueueTx(() => this.contract.write.requestWithdrawal([value]));
|
|
161
|
+
hash = await this.enqueueTx(() => this.contract.write.requestWithdrawal([value], this.defaultFeeParams()));
|
|
153
162
|
}
|
|
154
163
|
return this.publicClient.waitForTransactionReceipt({ hash, ...receipt });
|
|
155
164
|
}
|
|
@@ -157,10 +166,10 @@ class ContractGateway {
|
|
|
157
166
|
const { receipt } = this.splitWaitOptions(waitOptions);
|
|
158
167
|
let hash;
|
|
159
168
|
if (erc20Token) {
|
|
160
|
-
hash = await this.enqueueTx(() => this.contract.write.cancelWithdrawal([erc20Token]));
|
|
169
|
+
hash = await this.enqueueTx(() => this.contract.write.cancelWithdrawal([erc20Token], this.defaultFeeParams()));
|
|
161
170
|
}
|
|
162
171
|
else {
|
|
163
|
-
hash = await this.enqueueTx(() => this.contract.write.cancelWithdrawal());
|
|
172
|
+
hash = await this.enqueueTx(() => this.contract.write.cancelWithdrawal(this.defaultFeeParams()));
|
|
164
173
|
}
|
|
165
174
|
return this.publicClient.waitForTransactionReceipt({ hash, ...receipt });
|
|
166
175
|
}
|
|
@@ -168,10 +177,10 @@ class ContractGateway {
|
|
|
168
177
|
const { receipt } = this.splitWaitOptions(waitOptions);
|
|
169
178
|
let hash;
|
|
170
179
|
if (erc20Token) {
|
|
171
|
-
hash = await this.enqueueTx(() => this.contract.write.finalizeWithdrawal([erc20Token]));
|
|
180
|
+
hash = await this.enqueueTx(() => this.contract.write.finalizeWithdrawal([erc20Token], this.defaultFeeParams()));
|
|
172
181
|
}
|
|
173
182
|
else {
|
|
174
|
-
hash = await this.enqueueTx(() => this.contract.write.finalizeWithdrawal());
|
|
183
|
+
hash = await this.enqueueTx(() => this.contract.write.finalizeWithdrawal(this.defaultFeeParams()));
|
|
175
184
|
}
|
|
176
185
|
return this.publicClient.waitForTransactionReceipt({ hash, ...receipt });
|
|
177
186
|
}
|
|
@@ -189,6 +198,7 @@ class ContractGateway {
|
|
|
189
198
|
};
|
|
190
199
|
const hash = await this.enqueueTx(() => this.contract.write.remunerate([(0, utils_1.hexFromBytes)(claimsBlob), sigStruct], {
|
|
191
200
|
gas: gas ?? DEFAULT_REMUNERATE_GAS_LIMIT,
|
|
201
|
+
...this.defaultFeeParams(),
|
|
192
202
|
}));
|
|
193
203
|
return this.publicClient.waitForTransactionReceipt({ hash, ...receipt });
|
|
194
204
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@4mica/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "TypeScript SDK for interacting with the 4Mica payment network",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -42,11 +42,14 @@
|
|
|
42
42
|
"build": "tsc -p tsconfig.build.json",
|
|
43
43
|
"test": "vitest run",
|
|
44
44
|
"test:e2e": "vitest run --config vitest.e2e.config.ts",
|
|
45
|
+
"example:base-sepolia:x402-v2": "node_modules/.bin/tsx examples/base-sepolia-x402-facilitator-e2e.ts",
|
|
45
46
|
"lint": "eslint . --ext .ts",
|
|
46
47
|
"fmt": "prettier --check \"{src,tests}/**/*.{ts,js,json}\""
|
|
47
48
|
},
|
|
48
49
|
"dependencies": {
|
|
50
|
+
"@4mica/x402": "file:../x402-4mica/packages/typescript/x402",
|
|
49
51
|
"@noble/curves": "^2.0.1",
|
|
52
|
+
"@quillai-network/wachai-validation-sdk": "^0.1.0",
|
|
50
53
|
"viem": "^2.45.1"
|
|
51
54
|
},
|
|
52
55
|
"devDependencies": {
|