@4mica/sdk 1.0.1 → 1.0.2
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/contract.js +26 -10
- package/package.json +4 -2
- package/dist/abi/core4mica.json +0 -1605
- package/dist/abi/erc20.json +0 -187
- package/dist/client.d.ts +0 -56
- package/dist/client.js +0 -258
- package/dist/src/abi/core4mica.json +0 -1605
- package/dist/src/abi/erc20.json +0 -187
- package/dist/src/bls.d.ts +0 -5
- package/dist/src/bls.js +0 -45
- package/dist/src/client.d.ts +0 -55
- package/dist/src/client.js +0 -214
- package/dist/src/config.d.ts +0 -21
- package/dist/src/config.js +0 -76
- package/dist/src/contract.d.ts +0 -33
- package/dist/src/contract.js +0 -121
- package/dist/src/errors.d.ts +0 -17
- package/dist/src/errors.js +0 -31
- package/dist/src/guarantee.d.ts +0 -3
- package/dist/src/guarantee.js +0 -66
- package/dist/src/index.d.ts +0 -11
- package/dist/src/index.js +0 -27
- package/dist/src/models.d.ts +0 -119
- package/dist/src/models.js +0 -132
- package/dist/src/rpc.d.ts +0 -30
- package/dist/src/rpc.js +0 -122
- package/dist/src/signing.d.ts +0 -16
- package/dist/src/signing.js +0 -102
- package/dist/src/utils.d.ts +0 -8
- package/dist/src/utils.js +0 -78
- package/dist/src/x402.d.ts +0 -77
- package/dist/src/x402.js +0 -214
- package/dist/tests/config.test.d.ts +0 -1
- package/dist/tests/config.test.js +0 -26
- package/dist/tests/guarantee.test.d.ts +0 -1
- package/dist/tests/guarantee.test.js +0 -26
- package/dist/tests/rpc.test.d.ts +0 -1
- package/dist/tests/rpc.test.js +0 -44
- package/dist/tests/signing.test.d.ts +0 -1
- package/dist/tests/signing.test.js +0 -25
- package/dist/tests/utils.test.d.ts +0 -1
- package/dist/tests/utils.test.js +0 -25
- package/dist/tests/x402.test.d.ts +0 -1
- package/dist/tests/x402.test.js +0 -65
- package/dist/x402.d.ts +0 -78
- package/dist/x402.js +0 -231
package/dist/contract.js
CHANGED
|
@@ -7,6 +7,7 @@ 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_PAY_TAB_ERC20_GAS_LIMIT = 300000n;
|
|
10
11
|
const DEFAULT_MAX_FEE_PER_GAS = (0, viem_1.parseGwei)('0.1');
|
|
11
12
|
const DEFAULT_MAX_PRIORITY_FEE_PER_GAS = (0, viem_1.parseGwei)('0.1');
|
|
12
13
|
class ContractGateway {
|
|
@@ -89,10 +90,27 @@ class ContractGateway {
|
|
|
89
90
|
async approveErc20(token, amount, waitOptions) {
|
|
90
91
|
const { receipt } = this.splitWaitOptions(waitOptions);
|
|
91
92
|
const erc20 = this.erc20(token);
|
|
92
|
-
// spender address logic
|
|
93
93
|
const spender = this.contract.address;
|
|
94
|
-
const
|
|
95
|
-
|
|
94
|
+
const targetAllowance = (0, utils_1.parseU256)(amount);
|
|
95
|
+
const sendApprove = async (value) => {
|
|
96
|
+
const hash = await this.enqueueTx(() => erc20.write.approve([spender, value], this.defaultFeeParams()));
|
|
97
|
+
const txReceipt = await this.publicClient.waitForTransactionReceipt({ hash, ...receipt });
|
|
98
|
+
if (txReceipt.status !== 'success') {
|
|
99
|
+
throw new errors_1.ContractError(`approve transaction reverted: ${hash}`);
|
|
100
|
+
}
|
|
101
|
+
return txReceipt;
|
|
102
|
+
};
|
|
103
|
+
try {
|
|
104
|
+
return await sendApprove(targetAllowance);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
// Some ERC20s require resetting allowance to zero before setting a new value.
|
|
108
|
+
if (targetAllowance === 0n) {
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
await sendApprove(0n);
|
|
112
|
+
return sendApprove(targetAllowance);
|
|
113
|
+
}
|
|
96
114
|
}
|
|
97
115
|
async deposit(amount, erc20Token, waitOptions) {
|
|
98
116
|
const { receipt } = this.splitWaitOptions(waitOptions);
|
|
@@ -141,13 +159,11 @@ class ContractGateway {
|
|
|
141
159
|
return this.publicClient.waitForTransactionReceipt({ hash, ...receipt });
|
|
142
160
|
}
|
|
143
161
|
async payTabErc20(tabId, amount, erc20Token, recipient, waitOptions) {
|
|
144
|
-
const { receipt } = this.splitWaitOptions(waitOptions);
|
|
145
|
-
const hash = await this.enqueueTx(() => this.contract.write.payTabInERC20Token([
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
recipient,
|
|
150
|
-
], this.defaultFeeParams()));
|
|
162
|
+
const { gas, receipt } = this.splitWaitOptions(waitOptions);
|
|
163
|
+
const hash = await this.enqueueTx(() => this.contract.write.payTabInERC20Token([(0, utils_1.parseU256)(tabId), erc20Token, (0, utils_1.parseU256)(amount), recipient], {
|
|
164
|
+
gas: gas ?? DEFAULT_PAY_TAB_ERC20_GAS_LIMIT,
|
|
165
|
+
...this.defaultFeeParams(),
|
|
166
|
+
}));
|
|
151
167
|
return this.publicClient.waitForTransactionReceipt({ hash, ...receipt });
|
|
152
168
|
}
|
|
153
169
|
async requestWithdrawal(amount, erc20Token, waitOptions) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@4mica/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "TypeScript SDK for interacting with the 4Mica payment network",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -39,10 +39,12 @@
|
|
|
39
39
|
"ethers"
|
|
40
40
|
],
|
|
41
41
|
"scripts": {
|
|
42
|
-
"
|
|
42
|
+
"clean": "node -e \"require('node:fs').rmSync('dist',{ recursive: true, force: true })\"",
|
|
43
|
+
"build": "npm run clean && tsc -p tsconfig.build.json",
|
|
43
44
|
"test": "vitest run",
|
|
44
45
|
"test:e2e": "vitest run --config vitest.e2e.config.ts",
|
|
45
46
|
"example:base-sepolia:x402-v2": "node_modules/.bin/tsx examples/base-sepolia-x402-facilitator-e2e.ts",
|
|
47
|
+
"example:manual:agents": "node_modules/.bin/tsx examples/manual-agents/demo.ts",
|
|
46
48
|
"lint": "eslint . --ext .ts",
|
|
47
49
|
"fmt": "prettier --check \"{src,tests}/**/*.{ts,js,json}\""
|
|
48
50
|
},
|