@cgentai/cgent-contracts 1.0.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/LICENSE +21 -0
- package/README.md +312 -0
- package/dist/src/browser.d.ts +36 -0
- package/dist/src/browser.d.ts.map +1 -0
- package/dist/src/browser.js +36 -0
- package/dist/src/browser.js.map +1 -0
- package/dist/src/constants.d.ts +5 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +8 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/contracts/p2pEscrowClient.d.ts +70 -0
- package/dist/src/contracts/p2pEscrowClient.d.ts.map +1 -0
- package/dist/src/contracts/p2pEscrowClient.js +160 -0
- package/dist/src/contracts/p2pEscrowClient.js.map +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +21 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/types.d.ts +70 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +16 -0
- package/dist/src/types.js.map +1 -0
- package/dist/typechain-types/common.d.ts +51 -0
- package/dist/typechain-types/common.d.ts.map +1 -0
- package/dist/typechain-types/common.js +3 -0
- package/dist/typechain-types/common.js.map +1 -0
- package/dist/typechain-types/contracts/P2PEscrow.d.ts +555 -0
- package/dist/typechain-types/contracts/P2PEscrow.d.ts.map +1 -0
- package/dist/typechain-types/contracts/P2PEscrow.js +3 -0
- package/dist/typechain-types/contracts/P2PEscrow.js.map +1 -0
- package/dist/typechain-types/factories/contracts/P2PEscrow__factory.d.ts +671 -0
- package/dist/typechain-types/factories/contracts/P2PEscrow__factory.d.ts.map +1 -0
- package/dist/typechain-types/factories/contracts/P2PEscrow__factory.js +874 -0
- package/dist/typechain-types/factories/contracts/P2PEscrow__factory.js.map +1 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Cgent.AI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
## P2P Escrow SDK 文档
|
|
2
|
+
|
|
3
|
+
本仓库提供一个用于点对点电商场景的资金托管合约 `P2PEscrow.sol` 以及与之配套的 TypeScript SDK,帮助买卖双方在交易过程中安全地锁定和释放资金。本文档覆盖以下内容:
|
|
4
|
+
|
|
5
|
+
- 合约设计概览与角色职责
|
|
6
|
+
- 订单生命周期及状态机
|
|
7
|
+
- 合约公开方法与事件说明
|
|
8
|
+
- 常量、费用与错误类型
|
|
9
|
+
- SDK 安装、初始化及常用调用示例
|
|
10
|
+
- 浏览器环境辅助方法
|
|
11
|
+
|
|
12
|
+
> 合约源码位置:`contracts/P2PEscrow.sol`
|
|
13
|
+
>
|
|
14
|
+
> SDK 入口:`src/index.ts`(导出常量、类型与 `P2PEscrowClient`)
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
### 1. 合约概览
|
|
19
|
+
|
|
20
|
+
`P2PEscrow` 合约主要面向买家(buyer)、卖家(seller)与仲裁者(arbitrator)三个角色:
|
|
21
|
+
|
|
22
|
+
- **买家**:发起订单并预付代币;在没有争议时可以确认收货或撤回资金。
|
|
23
|
+
- **卖家**:在确认收到款项后锁定订单;可在必要时退款或在锁定期后请求释放资金。
|
|
24
|
+
- **仲裁者**:当订单进入争议流程时,负责裁定资金归属。
|
|
25
|
+
- **合约拥有者(owner)**:配置手续费接收地址、仲裁者和可用代币列表。
|
|
26
|
+
|
|
27
|
+
资金在订单创建时从买家转入合约,直至订单根据流程释放或退款。合约支持多个 ERC-20 代币,通过白名单管理支持的代币地址。
|
|
28
|
+
|
|
29
|
+
手续费设定为 **1%**(`FEE_BPS = 100`,基础为 `10_000`)。手续费统一转入 `feeRecipient` 地址,其余金额发放给卖家。
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
### 2. 订单状态机
|
|
34
|
+
|
|
35
|
+
合约使用 `OrderStatus` 枚举区分订单生命周期:
|
|
36
|
+
|
|
37
|
+
| 数值 | 状态名 | 说明 |
|
|
38
|
+
| --- | --- | --- |
|
|
39
|
+
| 0 | `None` | 默认状态(订单不存在)。 |
|
|
40
|
+
| 1 | `BuyerPaid` | 买家支付成功,订单已在合约中锁仓。 |
|
|
41
|
+
| 2 | `SellerLocked` | 卖家确认并锁定订单,开始计算锁定期(30 天)。 |
|
|
42
|
+
| 3 | `SellerRefunded` | 卖家将资金原路退回买家。 |
|
|
43
|
+
| 4 | `SellerReleased` | 订单释放给卖家(扣除手续费)。 |
|
|
44
|
+
| 5 | `BuyerWithdrawn` | 买家在卖家锁定前撤回资金。 |
|
|
45
|
+
| 6 | `ArbitrationPending` | 仲裁者介入,等待裁决。 |
|
|
46
|
+
| 7 | `ArbitrationBuyer` | 仲裁判定资金退回买家。 |
|
|
47
|
+
| 8 | `ArbitrationSeller` | 仲裁判定资金释放给卖家(扣除手续费)。 |
|
|
48
|
+
|
|
49
|
+
锁定期(`LOCK_DURATION = 30 days`)从卖家调用 `lockOrder` 时开始计算。锁定期届满后,卖家可调用 `sellerRelease` 将资金解锁给自己。
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
### 3. 合约方法
|
|
54
|
+
|
|
55
|
+
#### 3.1 配置与查看
|
|
56
|
+
|
|
57
|
+
- `feeRecipient() -> address`:查看手续费接收地址。
|
|
58
|
+
- `arbitrator() -> address`:查看当前仲裁者地址。
|
|
59
|
+
- `owner() -> address`:查看合约拥有者。
|
|
60
|
+
- `supportedTokens(address token) -> bool`:查询代币是否在支持列表。
|
|
61
|
+
- `getOrderId(address buyer, address seller, uint256 orderId) -> bytes32`:计算订单唯一 key。
|
|
62
|
+
- `getOrder(address buyer, address seller, uint256 orderId) -> Order`:获取订单结构体。
|
|
63
|
+
- `orders(bytes32 orderKey) -> Order`:通过订单 key 读取原始存储。
|
|
64
|
+
|
|
65
|
+
#### 3.2 订单生命周期
|
|
66
|
+
|
|
67
|
+
- `createOrder(address buyer, address seller, uint256 orderId, uint256 amount, address token)`
|
|
68
|
+
- 仅买家调用;检查代币是否支持、金额>0、卖家非零地址;将 `amount` 转入合约并创建订单。
|
|
69
|
+
|
|
70
|
+
- `lockOrder(address buyer, uint256 orderId)`
|
|
71
|
+
- 仅卖家调用;要求状态为 `BuyerPaid`;锁定期开始计时,状态改为 `SellerLocked`。
|
|
72
|
+
|
|
73
|
+
- `buyerWithdraw(address seller, uint256 orderId)`
|
|
74
|
+
- 买家在卖家锁定前随时撤回资金,状态变为 `BuyerWithdrawn`。
|
|
75
|
+
|
|
76
|
+
- `sellerRefund(address buyer, uint256 orderId)`
|
|
77
|
+
- 卖家在 `BuyerPaid` 或 `SellerLocked` 状态下可主动退款给买家,状态为 `SellerRefunded`。
|
|
78
|
+
|
|
79
|
+
- `buyerConfirmReceipt(address seller, uint256 orderId)`
|
|
80
|
+
- 买家在订单锁定后确认收货,触发 `_releaseToSeller`,将金额按费率拆分给卖家和手续费地址,状态变为 `SellerReleased`。
|
|
81
|
+
|
|
82
|
+
- `sellerRelease(address buyer, uint256 orderId)`
|
|
83
|
+
- 卖家在锁定期已结束后自助释放资金给自己;状态要求 `SellerLocked` 且当前时间超过 `lockedUntil`。
|
|
84
|
+
|
|
85
|
+
#### 3.3 仲裁流程
|
|
86
|
+
|
|
87
|
+
- `setArbitrationPending(address buyer, address seller, uint256 orderId)`
|
|
88
|
+
- 仅仲裁者调用;在 `BuyerPaid` 或 `SellerLocked` 状态下进入仲裁,记录上一个状态。
|
|
89
|
+
|
|
90
|
+
- `cancelArbitration(address buyer, address seller, uint256 orderId)`
|
|
91
|
+
- 仲裁者撤消仲裁,将状态还原至进入仲裁前的状态。
|
|
92
|
+
|
|
93
|
+
- `arbitrate(address buyer, address seller, uint256 orderId, bool releaseToSeller)`
|
|
94
|
+
- 仲裁者最终裁决。`releaseToSeller = true` 时拆分手续费后转给卖家;否则原额退回买家。状态分别变更为 `ArbitrationSeller` 或 `ArbitrationBuyer`。
|
|
95
|
+
|
|
96
|
+
#### 3.4 管理员操作
|
|
97
|
+
|
|
98
|
+
- `setFeeRecipient(address newRecipient)`:合约拥有者更新手续费地址。
|
|
99
|
+
- `setArbitrator(address newArbitrator)`:合约拥有者更新仲裁者。
|
|
100
|
+
- `addSupportedToken(address token)` / `removeSupportedToken(address token)`:增删支持代币。
|
|
101
|
+
- `transferOwnership(address newOwner)` / `renounceOwnership()`:标准 Ownable 权限管理。
|
|
102
|
+
|
|
103
|
+
#### 3.5 内部逻辑
|
|
104
|
+
|
|
105
|
+
- `_releaseToSeller(Order storage order, bytes32 orderKey)`:私有函数,用于统一执行释放逻辑,计算手续费并发放资金。
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
### 4. 事件
|
|
110
|
+
|
|
111
|
+
合约定义的主要事件如下:
|
|
112
|
+
|
|
113
|
+
- `OrderCreated(orderKey, buyer, seller, orderId, token, amount)`
|
|
114
|
+
- `OrderLocked(orderKey, lockedUntil)`
|
|
115
|
+
- `BuyerWithdrawn(orderKey)`
|
|
116
|
+
- `SellerRefunded(orderKey)`
|
|
117
|
+
- `SellerReleased(orderKey, sellerAmount, feeAmount)`
|
|
118
|
+
- `ArbitrationPendingSet(orderKey)`
|
|
119
|
+
- `ArbitrationResolved(orderKey, releasedToSeller, amount, feeAmount)`
|
|
120
|
+
- `ArbitrationCancelled(orderKey, restoredStatus)`
|
|
121
|
+
- `FeeRecipientUpdated(newRecipient)`
|
|
122
|
+
- `ArbitratorUpdated(newArbitrator)`
|
|
123
|
+
- `SupportedTokenAdded(token)` / `SupportedTokenRemoved(token)`
|
|
124
|
+
|
|
125
|
+
SDK 提供的 `P2PEscrowClient` 支持通过 `on/once/off/removeAllListeners` 订阅这些事件。
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
### 5. 常量与错误
|
|
130
|
+
|
|
131
|
+
- `LOCK_DURATION_SECONDS = 30 * 24 * 60 * 60`:卖家锁定后需等待的秒数。
|
|
132
|
+
- `FEE_BPS = 100 (1%)`,`BPS_DENOMINATOR = 10_000`:手续费计算使用 `amount * FEE_BPS / BPS_DENOMINATOR`。
|
|
133
|
+
- 关键错误:
|
|
134
|
+
- `InvalidToken(address)`:代币或地址无效。
|
|
135
|
+
- `InvalidAmount()`:金额为零。
|
|
136
|
+
- `OrderAlreadyExists()`:同一订单重复创建。
|
|
137
|
+
- `Unauthorized()`:调用方角色不匹配。
|
|
138
|
+
- `InvalidStatus()`:当前订单状态不允许执行操作。
|
|
139
|
+
- `LockPeriodActive(uint256)`:卖家释放时锁定期尚未到期。
|
|
140
|
+
- `NothingToRelease()`:订单金额为零。
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
### 6. SDK 使用指南
|
|
145
|
+
|
|
146
|
+
SDK 基于 `ethers@^6`,在 Node.js、浏览器或任意支持 ESM/CJS 的环境中均可使用。
|
|
147
|
+
|
|
148
|
+
#### 6.1 安装
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
npm install @cgentai/cgent-contracts ethers
|
|
152
|
+
# 或者使用 pnpm / yarn
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
#### 6.2 初始化客户端
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
import { JsonRpcProvider } from "ethers";
|
|
159
|
+
import { P2PEscrowClient } from "@cgentai/cgent-contracts";
|
|
160
|
+
|
|
161
|
+
const provider = new JsonRpcProvider("https://rpc.sepolia.linea.build");
|
|
162
|
+
const signer = await provider.getSigner(); // 也可以用 wallet.connect(provider)
|
|
163
|
+
|
|
164
|
+
const escrow = new P2PEscrowClient({
|
|
165
|
+
address: "0xEscrowAddress",
|
|
166
|
+
runner: signer,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
console.log(await escrow.getFeeRecipient());
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
`P2PEscrowClient.connect(address, runner)` 提供了便捷的静态初始化方法。
|
|
173
|
+
|
|
174
|
+
#### 6.3 浏览器环境
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
import { createP2PEscrowClientFromBrowser } from "@cgentai/cgent-contracts";
|
|
178
|
+
|
|
179
|
+
const escrow = await createP2PEscrowClientFromBrowser({
|
|
180
|
+
provider: window.ethereum,
|
|
181
|
+
address: "0xEscrowAddress",
|
|
182
|
+
accountIndex: 0, // 可选,默认 0
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const account = await escrow.getRunnerAddress();
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
#### 6.4 创建订单
|
|
189
|
+
|
|
190
|
+
```ts
|
|
191
|
+
const buyerAddress = await escrow.getRunnerAddress();
|
|
192
|
+
|
|
193
|
+
await escrow.createOrder({
|
|
194
|
+
buyer: buyerAddress!,
|
|
195
|
+
seller: "0xSellerAddress",
|
|
196
|
+
orderId: 1n,
|
|
197
|
+
amount: 1000n * 10n ** 6n, // 以最小单位传值
|
|
198
|
+
token: "0xUSDC",
|
|
199
|
+
});
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
在调用前确保买家钱包已对合约执行 `ERC20.approve` 授权。
|
|
203
|
+
|
|
204
|
+
#### 6.5 卖家操作
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
// 卖家确认锁定
|
|
208
|
+
await escrow.withRunner(sellerSigner).lockOrder({
|
|
209
|
+
buyer: buyerAddress!,
|
|
210
|
+
orderId: 1n,
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// 卖家等待锁定期结束后释放
|
|
214
|
+
await escrow.withRunner(sellerSigner).sellerRelease({
|
|
215
|
+
buyer: buyerAddress!,
|
|
216
|
+
orderId: 1n,
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// 或者在需要时退款
|
|
220
|
+
await escrow.withRunner(sellerSigner).sellerRefund({
|
|
221
|
+
buyer: buyerAddress!,
|
|
222
|
+
orderId: 1n,
|
|
223
|
+
});
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
#### 6.6 买家确认或撤回
|
|
227
|
+
|
|
228
|
+
```ts
|
|
229
|
+
// 买家确认收货
|
|
230
|
+
await escrow.withRunner(buyerSigner).buyerConfirmReceipt({
|
|
231
|
+
seller: "0xSellerAddress",
|
|
232
|
+
orderId: 1n,
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
// 买家在卖家锁定前撤回
|
|
236
|
+
await escrow.withRunner(buyerSigner).buyerWithdraw({
|
|
237
|
+
seller: "0xSellerAddress",
|
|
238
|
+
orderId: 1n,
|
|
239
|
+
});
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
#### 6.7 仲裁流程
|
|
243
|
+
|
|
244
|
+
```ts
|
|
245
|
+
// 仲裁者设置仲裁中
|
|
246
|
+
await escrow.withRunner(arbitratorSigner).setArbitrationPending({
|
|
247
|
+
buyer: buyerAddress!,
|
|
248
|
+
seller: "0xSellerAddress",
|
|
249
|
+
orderId: 1n,
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
// 最终裁决:true 释放给卖家(扣除手续费),false 退给买家
|
|
253
|
+
await escrow.withRunner(arbitratorSigner).arbitrate({
|
|
254
|
+
buyer: buyerAddress!,
|
|
255
|
+
seller: "0xSellerAddress",
|
|
256
|
+
orderId: 1n,
|
|
257
|
+
releaseToSeller: true,
|
|
258
|
+
});
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
#### 6.8 查询订单与辅助函数
|
|
262
|
+
|
|
263
|
+
```ts
|
|
264
|
+
const order = await escrow.getOrder({
|
|
265
|
+
buyer: buyerAddress!,
|
|
266
|
+
seller: "0xSellerAddress",
|
|
267
|
+
orderId: 1n,
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
console.log(order.status); // OrderStatus 枚举值
|
|
271
|
+
|
|
272
|
+
const { feeAmount, sellerAmount } = P2PEscrowClient.calculateFee(order.amount);
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
SDK 返回的 `ResolvedOrder` 将合约中的 `uint256` 转换为 `bigint`,可直接参与 JS/TS 计算。
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
### 7. 事件监听
|
|
280
|
+
|
|
281
|
+
`P2PEscrowClient` 继承了 TypeChain 的事件类型,可在 TypeScript 中获得强类型支持:
|
|
282
|
+
|
|
283
|
+
```ts
|
|
284
|
+
import type { P2PEscrow } from "@cgentai/cgent-contracts/typechain-types";
|
|
285
|
+
|
|
286
|
+
escrow.on(escrow.contract.filters.OrderCreated(), (orderKey, buyer, seller, orderId) => {
|
|
287
|
+
console.log("New order", { orderKey, buyer, seller, orderId: orderId.toString() });
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
// 取消监听
|
|
291
|
+
escrow.removeAllListeners(escrow.contract.filters.OrderCreated());
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
---
|
|
295
|
+
|
|
296
|
+
### 8. 部署与网络
|
|
297
|
+
|
|
298
|
+
`deployments/` 目录中存放了示例部署信息(例如 `P2PEscrow-84532.json` 对应于 Linea Sepolia 测试网)。使用 SDK 时请根据实际网络配置合约地址与 RPC 节点。
|
|
299
|
+
|
|
300
|
+
---
|
|
301
|
+
|
|
302
|
+
### 9. 开发与测试
|
|
303
|
+
|
|
304
|
+
- 本仓库基于 Hardhat,测试脚本位于 `test/` 目录,可运行 `pnpm test` 或 `npx hardhat test`。
|
|
305
|
+
- 若需自建环境,可使用 `pnpm deploy`(具体脚本请参考 `package.json`)。
|
|
306
|
+
- 修改合约或 SDK 后,请重新编译生成 TypeChain 类型:`pnpm build`。
|
|
307
|
+
|
|
308
|
+
---
|
|
309
|
+
|
|
310
|
+
如需更多帮助或功能扩展,欢迎提交 Issue 或 PR。
|
|
311
|
+
|
|
312
|
+
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { P2PEscrowClientConfig } from "./types";
|
|
2
|
+
export interface Eip1193Provider {
|
|
3
|
+
request(args: {
|
|
4
|
+
method: string;
|
|
5
|
+
params?: unknown[] | object;
|
|
6
|
+
}): Promise<unknown>;
|
|
7
|
+
on?(event: string, listener: (...args: unknown[]) => void): void;
|
|
8
|
+
removeListener?(event: string, listener: (...args: unknown[]) => void): void;
|
|
9
|
+
}
|
|
10
|
+
export interface BrowserWalletClientConfig extends Omit<P2PEscrowClientConfig, "runner"> {
|
|
11
|
+
provider: Eip1193Provider;
|
|
12
|
+
accountIndex?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Convenience helper for browser apps where the wallet (EIP-1193 provider)
|
|
16
|
+
* is injected by the host environment (e.g. MetaMask, Coinbase Wallet).
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { createP2PEscrowClientFromBrowser } from "@cgent/contracts";
|
|
20
|
+
*
|
|
21
|
+
* const client = await createP2PEscrowClientFromBrowser({
|
|
22
|
+
* provider: window.ethereum,
|
|
23
|
+
* address: "0xEscrowAddress",
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* await client.createOrder({
|
|
27
|
+
* buyer: await client.getRunnerAddress(),
|
|
28
|
+
* seller: "0xSeller",
|
|
29
|
+
* orderId: 1n,
|
|
30
|
+
* amount: 100n * 10n ** 6n,
|
|
31
|
+
* token: "0xUSDC",
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const createP2PEscrowClientFromBrowser: (config: BrowserWalletClientConfig) => Promise<import("./contracts/p2pEscrowClient").P2PEscrowClient>;
|
|
36
|
+
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/browser.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAGrD,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACjF,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,GAAG,IAAI,CAAC;IACjE,cAAc,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,GAAG,IAAI,CAAC;CAC9E;AAED,MAAM,WAAW,yBAA0B,SAAQ,IAAI,CAAC,qBAAqB,EAAE,QAAQ,CAAC;IACtF,QAAQ,EAAE,eAAe,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,gCAAgC,GAC3C,QAAQ,yBAAyB,mEASlC,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createP2PEscrowClientFromBrowser = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const p2pEscrowClient_1 = require("./contracts/p2pEscrowClient");
|
|
6
|
+
/**
|
|
7
|
+
* Convenience helper for browser apps where the wallet (EIP-1193 provider)
|
|
8
|
+
* is injected by the host environment (e.g. MetaMask, Coinbase Wallet).
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { createP2PEscrowClientFromBrowser } from "@cgent/contracts";
|
|
12
|
+
*
|
|
13
|
+
* const client = await createP2PEscrowClientFromBrowser({
|
|
14
|
+
* provider: window.ethereum,
|
|
15
|
+
* address: "0xEscrowAddress",
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* await client.createOrder({
|
|
19
|
+
* buyer: await client.getRunnerAddress(),
|
|
20
|
+
* seller: "0xSeller",
|
|
21
|
+
* orderId: 1n,
|
|
22
|
+
* amount: 100n * 10n ** 6n,
|
|
23
|
+
* token: "0xUSDC",
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
const createP2PEscrowClientFromBrowser = async (config) => {
|
|
28
|
+
const browserProvider = new ethers_1.BrowserProvider(config.provider);
|
|
29
|
+
const signer = await browserProvider.getSigner(config.accountIndex ?? 0);
|
|
30
|
+
return (0, p2pEscrowClient_1.createP2PEscrowClient)({
|
|
31
|
+
address: config.address,
|
|
32
|
+
runner: signer,
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
exports.createP2PEscrowClientFromBrowser = createP2PEscrowClientFromBrowser;
|
|
36
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/browser.ts"],"names":[],"mappings":";;;AAAA,mCAAyC;AAGzC,iEAAoE;AAapE;;;;;;;;;;;;;;;;;;;;GAoBG;AACI,MAAM,gCAAgC,GAAG,KAAK,EACnD,MAAiC,EACjC,EAAE;IACF,MAAM,eAAe,GAAG,IAAI,wBAAe,CAAC,MAAM,CAAC,QAAe,CAAC,CAAC;IACpE,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,SAAS,CAAC,MAAM,CAAC,YAAY,IAAI,CAAC,CAAC,CAAC;IAEzE,OAAO,IAAA,uCAAqB,EAAC;QAC3B,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,MAAM,EAAE,MAAM;KACf,CAAC,CAAC;AACL,CAAC,CAAC;AAVW,QAAA,gCAAgC,oCAU3C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,QAAoB,CAAC;AACvD,eAAO,MAAM,OAAO,OAAO,CAAC;AAC5B,eAAO,MAAM,eAAe,SAAU,CAAC;AAEvC,eAAO,MAAM,YAAY,+CAA+C,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ZERO_ADDRESS = exports.BPS_DENOMINATOR = exports.FEE_BPS = exports.LOCK_DURATION_SECONDS = void 0;
|
|
4
|
+
exports.LOCK_DURATION_SECONDS = 30 * 24 * 60 * 60; // 30 days
|
|
5
|
+
exports.FEE_BPS = 100n; // 1%
|
|
6
|
+
exports.BPS_DENOMINATOR = 10000n;
|
|
7
|
+
exports.ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
8
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,qBAAqB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,UAAU;AACrD,QAAA,OAAO,GAAG,IAAI,CAAC,CAAC,KAAK;AACrB,QAAA,eAAe,GAAG,MAAO,CAAC;AAE1B,QAAA,YAAY,GAAG,4CAA4C,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { AddressLike, ContractRunner, ContractTransactionResponse } from "ethers";
|
|
2
|
+
import { type ArbitratorActionParams, type CreateOrderParams, type OrderIdentifier, type SellerActionParams, type BuyerWithdrawParams, type BuyerConfirmReceiptParams, type P2PEscrowClientConfig, type ResolvedOrder } from "../types";
|
|
3
|
+
import type { TypedContractEvent, TypedDeferredTopicFilter, TypedListener } from "../../typechain-types/common";
|
|
4
|
+
import type { P2PEscrow } from "../../typechain-types/contracts/P2PEscrow";
|
|
5
|
+
/**
|
|
6
|
+
* High-level TypeScript wrapper around the `P2PEscrow` smart contract.
|
|
7
|
+
*
|
|
8
|
+
* Works with any ethers.js v6 `ContractRunner` (Signer, Provider or JsonRpcProvider).
|
|
9
|
+
* Designed to be framework-agnostic so it can run in browser or server runtimes.
|
|
10
|
+
*/
|
|
11
|
+
export declare class P2PEscrowClient {
|
|
12
|
+
private _contract;
|
|
13
|
+
constructor({ address, runner }: P2PEscrowClientConfig);
|
|
14
|
+
static connect(address: string, runner: ContractRunner): P2PEscrowClient;
|
|
15
|
+
get address(): string;
|
|
16
|
+
get runner(): ContractRunner | null;
|
|
17
|
+
get contract(): P2PEscrow;
|
|
18
|
+
getRunnerAddress(): Promise<string | null>;
|
|
19
|
+
withRunner(runner: ContractRunner): P2PEscrowClient;
|
|
20
|
+
/**
|
|
21
|
+
* Helpers
|
|
22
|
+
*/
|
|
23
|
+
static calculateFee(amount: bigint): {
|
|
24
|
+
feeAmount: bigint;
|
|
25
|
+
sellerAmount: bigint;
|
|
26
|
+
};
|
|
27
|
+
static lockDurationSeconds(): number;
|
|
28
|
+
/**
|
|
29
|
+
* Reads
|
|
30
|
+
*/
|
|
31
|
+
getFeeRecipient(): Promise<string>;
|
|
32
|
+
getArbitrator(): Promise<string>;
|
|
33
|
+
getOwner(): Promise<string>;
|
|
34
|
+
isSupportedToken(token: AddressLike): Promise<boolean>;
|
|
35
|
+
getOrderId(params: OrderIdentifier): Promise<string>;
|
|
36
|
+
getOrder(params: OrderIdentifier): Promise<ResolvedOrder>;
|
|
37
|
+
getRawOrder(params: OrderIdentifier): Promise<Awaited<ReturnType<P2PEscrow["orders"]>>>;
|
|
38
|
+
/**
|
|
39
|
+
* Transactions
|
|
40
|
+
*/
|
|
41
|
+
createOrder(params: CreateOrderParams): Promise<ContractTransactionResponse>;
|
|
42
|
+
lockOrder(params: SellerActionParams): Promise<ContractTransactionResponse>;
|
|
43
|
+
buyerWithdraw(params: BuyerWithdrawParams): Promise<ContractTransactionResponse>;
|
|
44
|
+
buyerConfirmReceipt(params: BuyerConfirmReceiptParams): Promise<ContractTransactionResponse>;
|
|
45
|
+
sellerRefund(params: SellerActionParams): Promise<ContractTransactionResponse>;
|
|
46
|
+
sellerRelease(params: SellerActionParams): Promise<ContractTransactionResponse>;
|
|
47
|
+
setArbitrationPending(params: OrderIdentifier): Promise<ContractTransactionResponse>;
|
|
48
|
+
cancelArbitration(params: OrderIdentifier): Promise<ContractTransactionResponse>;
|
|
49
|
+
arbitrate(params: ArbitratorActionParams): Promise<ContractTransactionResponse>;
|
|
50
|
+
setFeeRecipient(newRecipient: AddressLike): Promise<ContractTransactionResponse>;
|
|
51
|
+
setArbitrator(newArbitrator: AddressLike): Promise<ContractTransactionResponse>;
|
|
52
|
+
addSupportedToken(token: AddressLike): Promise<ContractTransactionResponse>;
|
|
53
|
+
removeSupportedToken(token: AddressLike): Promise<ContractTransactionResponse>;
|
|
54
|
+
transferOwnership(newOwner: AddressLike): Promise<ContractTransactionResponse>;
|
|
55
|
+
renounceOwnership(): Promise<ContractTransactionResponse>;
|
|
56
|
+
/**
|
|
57
|
+
* Events
|
|
58
|
+
*/
|
|
59
|
+
on<Event extends TypedContractEvent>(event: Event, listener: TypedListener<Event>): void;
|
|
60
|
+
on<Event extends TypedContractEvent>(filter: TypedDeferredTopicFilter<Event>, listener: TypedListener<Event>): void;
|
|
61
|
+
once<Event extends TypedContractEvent>(event: Event, listener: TypedListener<Event>): void;
|
|
62
|
+
once<Event extends TypedContractEvent>(filter: TypedDeferredTopicFilter<Event>, listener: TypedListener<Event>): void;
|
|
63
|
+
off<Event extends TypedContractEvent>(event: Event, listener: TypedListener<Event>): void;
|
|
64
|
+
off<Event extends TypedContractEvent>(filter: TypedDeferredTopicFilter<Event>, listener: TypedListener<Event>): void;
|
|
65
|
+
removeAllListeners<Event extends TypedContractEvent>(event?: Event): void;
|
|
66
|
+
private mapOrder;
|
|
67
|
+
}
|
|
68
|
+
export type { P2PEscrow };
|
|
69
|
+
export declare const createP2PEscrowClient: (config: P2PEscrowClientConfig) => P2PEscrowClient;
|
|
70
|
+
//# sourceMappingURL=p2pEscrowClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"p2pEscrowClient.d.ts","sourceRoot":"","sources":["../../../src/contracts/p2pEscrowClient.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createP2PEscrowClient = exports.P2PEscrowClient = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const P2PEscrow__factory_1 = require("../../typechain-types/factories/contracts/P2PEscrow__factory");
|
|
6
|
+
/**
|
|
7
|
+
* High-level TypeScript wrapper around the `P2PEscrow` smart contract.
|
|
8
|
+
*
|
|
9
|
+
* Works with any ethers.js v6 `ContractRunner` (Signer, Provider or JsonRpcProvider).
|
|
10
|
+
* Designed to be framework-agnostic so it can run in browser or server runtimes.
|
|
11
|
+
*/
|
|
12
|
+
class P2PEscrowClient {
|
|
13
|
+
_contract;
|
|
14
|
+
constructor({ address, runner }) {
|
|
15
|
+
if (!address) {
|
|
16
|
+
throw new Error("P2PEscrowClient: contract address is required");
|
|
17
|
+
}
|
|
18
|
+
if (!runner) {
|
|
19
|
+
throw new Error("P2PEscrowClient: runner (signer or provider) is required");
|
|
20
|
+
}
|
|
21
|
+
this._contract = P2PEscrow__factory_1.P2PEscrow__factory.connect(address, runner);
|
|
22
|
+
}
|
|
23
|
+
static connect(address, runner) {
|
|
24
|
+
return new P2PEscrowClient({ address, runner });
|
|
25
|
+
}
|
|
26
|
+
get address() {
|
|
27
|
+
return this._contract.target.toString();
|
|
28
|
+
}
|
|
29
|
+
get runner() {
|
|
30
|
+
return this._contract.runner ?? null;
|
|
31
|
+
}
|
|
32
|
+
get contract() {
|
|
33
|
+
return this._contract;
|
|
34
|
+
}
|
|
35
|
+
async getRunnerAddress() {
|
|
36
|
+
const currentRunner = this._contract.runner;
|
|
37
|
+
if (currentRunner?.getAddress) {
|
|
38
|
+
return currentRunner.getAddress();
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
withRunner(runner) {
|
|
43
|
+
this._contract = this._contract.connect(runner);
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Helpers
|
|
48
|
+
*/
|
|
49
|
+
static calculateFee(amount) {
|
|
50
|
+
const feeAmount = (amount * constants_1.FEE_BPS) / constants_1.BPS_DENOMINATOR;
|
|
51
|
+
return {
|
|
52
|
+
feeAmount,
|
|
53
|
+
sellerAmount: amount - feeAmount,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
static lockDurationSeconds() {
|
|
57
|
+
return constants_1.LOCK_DURATION_SECONDS;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Reads
|
|
61
|
+
*/
|
|
62
|
+
async getFeeRecipient() {
|
|
63
|
+
return this._contract.feeRecipient();
|
|
64
|
+
}
|
|
65
|
+
async getArbitrator() {
|
|
66
|
+
return this._contract.arbitrator();
|
|
67
|
+
}
|
|
68
|
+
async getOwner() {
|
|
69
|
+
return this._contract.owner();
|
|
70
|
+
}
|
|
71
|
+
async isSupportedToken(token) {
|
|
72
|
+
return this._contract.supportedTokens(token);
|
|
73
|
+
}
|
|
74
|
+
async getOrderId(params) {
|
|
75
|
+
return this._contract.getOrderId(params.buyer, params.seller, params.orderId);
|
|
76
|
+
}
|
|
77
|
+
async getOrder(params) {
|
|
78
|
+
const order = await this._contract.getOrder(params.buyer, params.seller, params.orderId);
|
|
79
|
+
return this.mapOrder(order);
|
|
80
|
+
}
|
|
81
|
+
async getRawOrder(params) {
|
|
82
|
+
const orderKey = await this.getOrderId(params);
|
|
83
|
+
return this._contract.orders(orderKey);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Transactions
|
|
87
|
+
*/
|
|
88
|
+
async createOrder(params) {
|
|
89
|
+
return this._contract.createOrder(params.buyer, params.seller, params.orderId, params.amount, params.token);
|
|
90
|
+
}
|
|
91
|
+
async lockOrder(params) {
|
|
92
|
+
return this._contract.lockOrder(params.buyer, params.orderId);
|
|
93
|
+
}
|
|
94
|
+
async buyerWithdraw(params) {
|
|
95
|
+
return this._contract.buyerWithdraw(params.seller, params.orderId);
|
|
96
|
+
}
|
|
97
|
+
async buyerConfirmReceipt(params) {
|
|
98
|
+
return this._contract.buyerConfirmReceipt(params.seller, params.orderId);
|
|
99
|
+
}
|
|
100
|
+
async sellerRefund(params) {
|
|
101
|
+
return this._contract.sellerRefund(params.buyer, params.orderId);
|
|
102
|
+
}
|
|
103
|
+
async sellerRelease(params) {
|
|
104
|
+
return this._contract.sellerRelease(params.buyer, params.orderId);
|
|
105
|
+
}
|
|
106
|
+
async setArbitrationPending(params) {
|
|
107
|
+
return this._contract.setArbitrationPending(params.buyer, params.seller, params.orderId);
|
|
108
|
+
}
|
|
109
|
+
async cancelArbitration(params) {
|
|
110
|
+
return this._contract.cancelArbitration(params.buyer, params.seller, params.orderId);
|
|
111
|
+
}
|
|
112
|
+
async arbitrate(params) {
|
|
113
|
+
return this._contract.arbitrate(params.buyer, params.seller, params.orderId, params.releaseToSeller ?? false);
|
|
114
|
+
}
|
|
115
|
+
async setFeeRecipient(newRecipient) {
|
|
116
|
+
return this._contract.setFeeRecipient(newRecipient);
|
|
117
|
+
}
|
|
118
|
+
async setArbitrator(newArbitrator) {
|
|
119
|
+
return this._contract.setArbitrator(newArbitrator);
|
|
120
|
+
}
|
|
121
|
+
async addSupportedToken(token) {
|
|
122
|
+
return this._contract.addSupportedToken(token);
|
|
123
|
+
}
|
|
124
|
+
async removeSupportedToken(token) {
|
|
125
|
+
return this._contract.removeSupportedToken(token);
|
|
126
|
+
}
|
|
127
|
+
async transferOwnership(newOwner) {
|
|
128
|
+
return this._contract.transferOwnership(newOwner);
|
|
129
|
+
}
|
|
130
|
+
async renounceOwnership() {
|
|
131
|
+
return this._contract.renounceOwnership();
|
|
132
|
+
}
|
|
133
|
+
on(eventOrFilter, listener) {
|
|
134
|
+
void this._contract.on(eventOrFilter, listener);
|
|
135
|
+
}
|
|
136
|
+
once(eventOrFilter, listener) {
|
|
137
|
+
void this._contract.once(eventOrFilter, listener);
|
|
138
|
+
}
|
|
139
|
+
off(eventOrFilter, listener) {
|
|
140
|
+
void this._contract.off(eventOrFilter, listener);
|
|
141
|
+
}
|
|
142
|
+
removeAllListeners(event) {
|
|
143
|
+
void this._contract.removeAllListeners(event);
|
|
144
|
+
}
|
|
145
|
+
mapOrder(order) {
|
|
146
|
+
return {
|
|
147
|
+
buyer: order.buyer,
|
|
148
|
+
seller: order.seller,
|
|
149
|
+
amount: order.amount,
|
|
150
|
+
lockedUntil: order.lockedUntil,
|
|
151
|
+
token: order.token,
|
|
152
|
+
status: Number(order.status),
|
|
153
|
+
previousStatus: Number(order.previousStatus),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
exports.P2PEscrowClient = P2PEscrowClient;
|
|
158
|
+
const createP2PEscrowClient = (config) => new P2PEscrowClient(config);
|
|
159
|
+
exports.createP2PEscrowClient = createP2PEscrowClient;
|
|
160
|
+
//# sourceMappingURL=p2pEscrowClient.js.map
|