ox 0.14.26 → 0.14.27
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/CHANGELOG.md +6 -0
- package/_cjs/tempo/ReceivePolicyReceipt.js +80 -0
- package/_cjs/tempo/ReceivePolicyReceipt.js.map +1 -0
- package/_cjs/tempo/index.js +2 -1
- package/_cjs/tempo/index.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/tempo/ReceivePolicyReceipt.js +176 -0
- package/_esm/tempo/ReceivePolicyReceipt.js.map +1 -0
- package/_esm/tempo/index.js +22 -0
- package/_esm/tempo/index.js.map +1 -1
- package/_esm/version.js +1 -1
- package/_types/tempo/ReceivePolicyReceipt.d.ts +168 -0
- package/_types/tempo/ReceivePolicyReceipt.d.ts.map +1 -0
- package/_types/tempo/index.d.ts +22 -0
- package/_types/tempo/index.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/package.json +6 -1
- package/tempo/ReceivePolicyReceipt/package.json +6 -0
- package/tempo/ReceivePolicyReceipt.test.ts +198 -0
- package/tempo/ReceivePolicyReceipt.ts +263 -0
- package/tempo/index.ts +22 -0
- package/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# ox
|
|
2
2
|
|
|
3
|
+
## 0.14.27
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#263](https://github.com/wevm/ox/pull/263) [`451a442`](https://github.com/wevm/ox/commit/451a442f7c3ba0d415ce4c212bc9b6bc7fd0034e) Thanks [@jxom](https://github.com/jxom)! - `ox/tempo`: Added the `ReceivePolicyReceipt` module for encoding/decoding TIP-1028 receive-policy claim receipts (`ClaimReceiptV1` witnesses) with `decode`, `encode`, `from`, `fromLog`, and `fromTransactionReceipt` (returns one receipt per `TransferBlocked` log).
|
|
8
|
+
|
|
3
9
|
## 0.14.26
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decode = decode;
|
|
4
|
+
exports.encode = encode;
|
|
5
|
+
exports.from = from;
|
|
6
|
+
exports.fromLog = fromLog;
|
|
7
|
+
exports.fromTransactionReceipt = fromTransactionReceipt;
|
|
8
|
+
const AbiEvent = require("../core/AbiEvent.js");
|
|
9
|
+
const AbiParameters = require("../core/AbiParameters.js");
|
|
10
|
+
const blockedReasons = ['none', 'tokenFilter', 'receivePolicy'];
|
|
11
|
+
const kinds = ['transfer', 'mint'];
|
|
12
|
+
const parameters = [
|
|
13
|
+
{
|
|
14
|
+
type: 'tuple',
|
|
15
|
+
components: [
|
|
16
|
+
{ name: 'version', type: 'uint8' },
|
|
17
|
+
{ name: 'token', type: 'address' },
|
|
18
|
+
{ name: 'recoveryAuthority', type: 'address' },
|
|
19
|
+
{ name: 'originator', type: 'address' },
|
|
20
|
+
{ name: 'recipient', type: 'address' },
|
|
21
|
+
{ name: 'blockedAt', type: 'uint64' },
|
|
22
|
+
{ name: 'blockedNonce', type: 'uint64' },
|
|
23
|
+
{ name: 'blockedReason', type: 'uint8' },
|
|
24
|
+
{ name: 'kind', type: 'uint8' },
|
|
25
|
+
{ name: 'memo', type: 'bytes32' },
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
const transferBlocked = AbiEvent.from('event TransferBlocked(address indexed token, address indexed receiver, uint64 indexed blockedNonce, uint256 amount, uint8 receiptVersion, bytes receipt)');
|
|
30
|
+
function decode(receipt) {
|
|
31
|
+
const [decoded] = AbiParameters.decode(parameters, receipt);
|
|
32
|
+
return {
|
|
33
|
+
version: decoded.version,
|
|
34
|
+
token: decoded.token,
|
|
35
|
+
recoveryAuthority: decoded.recoveryAuthority,
|
|
36
|
+
originator: decoded.originator,
|
|
37
|
+
recipient: decoded.recipient,
|
|
38
|
+
blockedAt: decoded.blockedAt,
|
|
39
|
+
blockedNonce: decoded.blockedNonce,
|
|
40
|
+
blockedReason: blockedReasons[decoded.blockedReason] ?? 'none',
|
|
41
|
+
kind: kinds[decoded.kind] ?? 'transfer',
|
|
42
|
+
memo: decoded.memo,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function encode(decoded) {
|
|
46
|
+
return AbiParameters.encode(parameters, [
|
|
47
|
+
{
|
|
48
|
+
version: decoded.version,
|
|
49
|
+
token: decoded.token,
|
|
50
|
+
recoveryAuthority: decoded.recoveryAuthority,
|
|
51
|
+
originator: decoded.originator,
|
|
52
|
+
recipient: decoded.recipient,
|
|
53
|
+
blockedAt: decoded.blockedAt,
|
|
54
|
+
blockedNonce: decoded.blockedNonce,
|
|
55
|
+
blockedReason: blockedReasons.indexOf(decoded.blockedReason),
|
|
56
|
+
kind: kinds.indexOf(decoded.kind),
|
|
57
|
+
memo: decoded.memo,
|
|
58
|
+
},
|
|
59
|
+
]);
|
|
60
|
+
}
|
|
61
|
+
function from(value) {
|
|
62
|
+
if (typeof value === 'string')
|
|
63
|
+
return value;
|
|
64
|
+
return encode(value);
|
|
65
|
+
}
|
|
66
|
+
function fromLog(log) {
|
|
67
|
+
const { receipt } = AbiEvent.decode(transferBlocked, log);
|
|
68
|
+
return receipt;
|
|
69
|
+
}
|
|
70
|
+
function fromTransactionReceipt(receipt) {
|
|
71
|
+
const selector = AbiEvent.getSelector(transferBlocked);
|
|
72
|
+
const receipts = [];
|
|
73
|
+
for (const log of receipt.logs ?? []) {
|
|
74
|
+
if (log.topics[0] !== selector)
|
|
75
|
+
continue;
|
|
76
|
+
receipts.push(fromLog(log));
|
|
77
|
+
}
|
|
78
|
+
return receipts;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=ReceivePolicyReceipt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReceivePolicyReceipt.js","sourceRoot":"","sources":["../../tempo/ReceivePolicyReceipt.ts"],"names":[],"mappings":";;A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;AA+BD,SAAgB,sBAAsB,CACpC,OAAuC;IAEvC,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,CAAC,eAAe,CAAC,CAAA;IACtD,MAAM,QAAQ,GAA2B,EAAE,CAAA;IAC3C,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;QACrC,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,QAAQ;YAAE,SAAQ;QACxC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAA;IAC7B,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC"}
|
package/_cjs/tempo/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ZoneRpcAuthentication = exports.ZoneId = exports.VirtualMaster = exports.VirtualAddress = exports.TxEnvelopeTempo = exports.TransactionRequest = exports.TransactionReceipt = exports.Transaction = exports.TokenRole = exports.TokenId = exports.Tick = exports.TempoAddress = exports.SignatureEnvelope = exports.RpcSchemaTempo = exports.PoolId = exports.Period = exports.KeyAuthorization = exports.Channel = exports.AuthorizationTempo = void 0;
|
|
3
|
+
exports.ZoneRpcAuthentication = exports.ZoneId = exports.VirtualMaster = exports.VirtualAddress = exports.TxEnvelopeTempo = exports.TransactionRequest = exports.TransactionReceipt = exports.Transaction = exports.TokenRole = exports.TokenId = exports.Tick = exports.TempoAddress = exports.SignatureEnvelope = exports.RpcSchemaTempo = exports.ReceivePolicyReceipt = exports.PoolId = exports.Period = exports.KeyAuthorization = exports.Channel = exports.AuthorizationTempo = void 0;
|
|
4
4
|
exports.AuthorizationTempo = require("./AuthorizationTempo.js");
|
|
5
5
|
exports.Channel = require("./Channel.js");
|
|
6
6
|
exports.KeyAuthorization = require("./KeyAuthorization.js");
|
|
7
7
|
exports.Period = require("./Period.js");
|
|
8
8
|
exports.PoolId = require("./PoolId.js");
|
|
9
|
+
exports.ReceivePolicyReceipt = require("./ReceivePolicyReceipt.js");
|
|
9
10
|
exports.RpcSchemaTempo = require("./RpcSchemaTempo.js");
|
|
10
11
|
exports.SignatureEnvelope = require("./SignatureEnvelope.js");
|
|
11
12
|
exports.TempoAddress = require("./TempoAddress.js");
|
package/_cjs/tempo/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../tempo/index.ts"],"names":[],"mappings":";;;AAoCA,gEAA6D;AA2B7D,0CAAuC;AAwCvC,4DAAyD;AA6BzD,wCAAqC;AAsBrC,wCAAqC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../tempo/index.ts"],"names":[],"mappings":";;;AAoCA,gEAA6D;AA2B7D,0CAAuC;AAwCvC,4DAAyD;AA6BzD,wCAAqC;AAsBrC,wCAAqC;AAsBrC,oEAAiE;AAoBjE,wDAAqD;AAuBrD,8DAA2D;AAmB3D,oDAAiD;AAoBjD,oCAAiC;AAqBjC,0CAAuC;AAkBvC,8CAA2C;AAkD3C,kDAA+C;AAuB/C,gEAA6D;AAqB7D,gEAA6D;AA6B7D,0DAAuD;AA4BvD,wDAAqD;AAyBrD,sDAAmD;AAqBnD,wCAAqC;AAmCrC,sEAAmE"}
|
package/_cjs/version.js
CHANGED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import * as AbiEvent from '../core/AbiEvent.js';
|
|
2
|
+
import * as AbiParameters from '../core/AbiParameters.js';
|
|
3
|
+
/** @internal */
|
|
4
|
+
const blockedReasons = ['none', 'tokenFilter', 'receivePolicy'];
|
|
5
|
+
/** @internal */
|
|
6
|
+
const kinds = ['transfer', 'mint'];
|
|
7
|
+
/** @internal ABI parameters for the `ClaimReceiptV1` witness. */
|
|
8
|
+
const parameters = [
|
|
9
|
+
{
|
|
10
|
+
type: 'tuple',
|
|
11
|
+
components: [
|
|
12
|
+
{ name: 'version', type: 'uint8' },
|
|
13
|
+
{ name: 'token', type: 'address' },
|
|
14
|
+
{ name: 'recoveryAuthority', type: 'address' },
|
|
15
|
+
{ name: 'originator', type: 'address' },
|
|
16
|
+
{ name: 'recipient', type: 'address' },
|
|
17
|
+
{ name: 'blockedAt', type: 'uint64' },
|
|
18
|
+
{ name: 'blockedNonce', type: 'uint64' },
|
|
19
|
+
{ name: 'blockedReason', type: 'uint8' },
|
|
20
|
+
{ name: 'kind', type: 'uint8' },
|
|
21
|
+
{ name: 'memo', type: 'bytes32' },
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
];
|
|
25
|
+
/** @internal `TransferBlocked` event emitted by the `ReceivePolicyGuard`. */
|
|
26
|
+
const transferBlocked = AbiEvent.from('event TransferBlocked(address indexed token, address indexed receiver, uint64 indexed blockedNonce, uint256 amount, uint8 receiptVersion, bytes receipt)');
|
|
27
|
+
/**
|
|
28
|
+
* Decodes a {@link ox#ReceivePolicyReceipt.ReceivePolicyReceipt} (ABI-encoded
|
|
29
|
+
* `ClaimReceiptV1` witness) into its fields.
|
|
30
|
+
*
|
|
31
|
+
* [TIP-1028](https://docs.tempo.xyz/protocol/tips/tip-1028)
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts twoslash
|
|
35
|
+
* import { ReceivePolicyReceipt } from 'ox/tempo'
|
|
36
|
+
*
|
|
37
|
+
* const decoded = ReceivePolicyReceipt.decode('0x...')
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @param receipt - The receive-policy receipt.
|
|
41
|
+
* @returns The decoded fields.
|
|
42
|
+
*/
|
|
43
|
+
export function decode(receipt) {
|
|
44
|
+
const [decoded] = AbiParameters.decode(parameters, receipt);
|
|
45
|
+
return {
|
|
46
|
+
version: decoded.version,
|
|
47
|
+
token: decoded.token,
|
|
48
|
+
recoveryAuthority: decoded.recoveryAuthority,
|
|
49
|
+
originator: decoded.originator,
|
|
50
|
+
recipient: decoded.recipient,
|
|
51
|
+
blockedAt: decoded.blockedAt,
|
|
52
|
+
blockedNonce: decoded.blockedNonce,
|
|
53
|
+
blockedReason: blockedReasons[decoded.blockedReason] ?? 'none',
|
|
54
|
+
kind: kinds[decoded.kind] ?? 'transfer',
|
|
55
|
+
memo: decoded.memo,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Encodes decoded fields into a
|
|
60
|
+
* {@link ox#ReceivePolicyReceipt.ReceivePolicyReceipt}. Inverse of `decode`.
|
|
61
|
+
*
|
|
62
|
+
* [TIP-1028](https://docs.tempo.xyz/protocol/tips/tip-1028)
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts twoslash
|
|
66
|
+
* // @noErrors
|
|
67
|
+
* import { ReceivePolicyReceipt } from 'ox/tempo'
|
|
68
|
+
*
|
|
69
|
+
* const decoded = ReceivePolicyReceipt.decode('0x...')
|
|
70
|
+
* const receipt = ReceivePolicyReceipt.encode(decoded)
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @param decoded - The decoded fields.
|
|
74
|
+
* @returns The receive-policy receipt.
|
|
75
|
+
*/
|
|
76
|
+
export function encode(decoded) {
|
|
77
|
+
return AbiParameters.encode(parameters, [
|
|
78
|
+
{
|
|
79
|
+
version: decoded.version,
|
|
80
|
+
token: decoded.token,
|
|
81
|
+
recoveryAuthority: decoded.recoveryAuthority,
|
|
82
|
+
originator: decoded.originator,
|
|
83
|
+
recipient: decoded.recipient,
|
|
84
|
+
blockedAt: decoded.blockedAt,
|
|
85
|
+
blockedNonce: decoded.blockedNonce,
|
|
86
|
+
blockedReason: blockedReasons.indexOf(decoded.blockedReason),
|
|
87
|
+
kind: kinds.indexOf(decoded.kind),
|
|
88
|
+
memo: decoded.memo,
|
|
89
|
+
},
|
|
90
|
+
]);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Normalizes a {@link ox#ReceivePolicyReceipt.ReceivePolicyReceipt} from either
|
|
94
|
+
* an encoded receipt (passthrough) or decoded fields.
|
|
95
|
+
*
|
|
96
|
+
* [TIP-1028](https://docs.tempo.xyz/protocol/tips/tip-1028)
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts twoslash
|
|
100
|
+
* // @noErrors
|
|
101
|
+
* import { ReceivePolicyReceipt } from 'ox/tempo'
|
|
102
|
+
*
|
|
103
|
+
* // From an encoded receipt (passthrough).
|
|
104
|
+
* const a = ReceivePolicyReceipt.from('0x...')
|
|
105
|
+
*
|
|
106
|
+
* // From decoded fields.
|
|
107
|
+
* const b = ReceivePolicyReceipt.from(ReceivePolicyReceipt.decode('0x...'))
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @param value - An encoded receipt or decoded fields.
|
|
111
|
+
* @returns The receive-policy receipt.
|
|
112
|
+
*/
|
|
113
|
+
export function from(value) {
|
|
114
|
+
if (typeof value === 'string')
|
|
115
|
+
return value;
|
|
116
|
+
return encode(value);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Extracts the {@link ox#ReceivePolicyReceipt.ReceivePolicyReceipt} from a
|
|
120
|
+
* `ReceivePolicyGuard` `TransferBlocked` log.
|
|
121
|
+
*
|
|
122
|
+
* Throws if the log is not a `TransferBlocked` event. Use
|
|
123
|
+
* `fromTransactionReceipt` to extract every blocked transfer in a transaction
|
|
124
|
+
* (which skips unrelated logs).
|
|
125
|
+
*
|
|
126
|
+
* [TIP-1028](https://docs.tempo.xyz/protocol/tips/tip-1028)
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts twoslash
|
|
130
|
+
* // @noErrors
|
|
131
|
+
* import { ReceivePolicyReceipt } from 'ox/tempo'
|
|
132
|
+
*
|
|
133
|
+
* const receipt = ReceivePolicyReceipt.fromLog(log)
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* @param log - A `TransferBlocked` log (`data` & `topics`).
|
|
137
|
+
* @returns The receive-policy receipt.
|
|
138
|
+
*/
|
|
139
|
+
export function fromLog(log) {
|
|
140
|
+
const { receipt } = AbiEvent.decode(transferBlocked, log);
|
|
141
|
+
return receipt;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Extracts every {@link ox#ReceivePolicyReceipt.ReceivePolicyReceipt} from a
|
|
145
|
+
* transaction receipt's logs.
|
|
146
|
+
*
|
|
147
|
+
* A single transaction may block multiple inbound transfers (e.g. a batched
|
|
148
|
+
* transfer to several recipients), so this returns an array – one entry per
|
|
149
|
+
* `TransferBlocked` log, in log order. Returns an empty array when no transfers
|
|
150
|
+
* were blocked.
|
|
151
|
+
*
|
|
152
|
+
* [TIP-1028](https://docs.tempo.xyz/protocol/tips/tip-1028)
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts twoslash
|
|
156
|
+
* // @noErrors
|
|
157
|
+
* import { ReceivePolicyReceipt } from 'ox/tempo'
|
|
158
|
+
*
|
|
159
|
+
* const receipts = ReceivePolicyReceipt.fromTransactionReceipt(receipt)
|
|
160
|
+
* // @log: ['0x...'] (pass each to `claim` / `burn`)
|
|
161
|
+
* ```
|
|
162
|
+
*
|
|
163
|
+
* @param receipt - The transaction receipt (or any object with `logs`).
|
|
164
|
+
* @returns The receive-policy receipts, one per blocked transfer.
|
|
165
|
+
*/
|
|
166
|
+
export function fromTransactionReceipt(receipt) {
|
|
167
|
+
const selector = AbiEvent.getSelector(transferBlocked);
|
|
168
|
+
const receipts = [];
|
|
169
|
+
for (const log of receipt.logs ?? []) {
|
|
170
|
+
if (log.topics[0] !== selector)
|
|
171
|
+
continue;
|
|
172
|
+
receipts.push(fromLog(log));
|
|
173
|
+
}
|
|
174
|
+
return receipts;
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=ReceivePolicyReceipt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReceivePolicyReceipt.js","sourceRoot":"","sources":["../../tempo/ReceivePolicyReceipt.ts"],"names":[],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MD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,OAAO,CAAC,GAAgB;IACtC,MAAM,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,GAAG,CAAC,CAAA;IACzD,OAAO,OAAO,CAAA;AAChB,CAAC;AAQD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,sBAAsB,CACpC,OAAuC;IAEvC,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,CAAC,eAAe,CAAC,CAAA;IACtD,MAAM,QAAQ,GAA2B,EAAE,CAAA;IAC3C,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;QACrC,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,QAAQ;YAAE,SAAQ;QACxC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAA;IAC7B,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC"}
|
package/_esm/tempo/index.js
CHANGED
|
@@ -148,6 +148,28 @@ export * as Period from './Period.js';
|
|
|
148
148
|
* @category Reference
|
|
149
149
|
*/
|
|
150
150
|
export * as PoolId from './PoolId.js';
|
|
151
|
+
/**
|
|
152
|
+
* TIP-1028 receive-policy claim receipt utilities.
|
|
153
|
+
*
|
|
154
|
+
* When an inbound transfer or mint violates the recipient's receive policy, the
|
|
155
|
+
* funds are redirected to the `ReceivePolicyGuard` and a `ClaimReceiptV1`
|
|
156
|
+
* witness is emitted. This module decodes those witnesses (required to later
|
|
157
|
+
* `claim` or `burn` the blocked funds) from raw bytes or transaction receipts.
|
|
158
|
+
*
|
|
159
|
+
* [TIP-1028](https://docs.tempo.xyz/protocol/tips/tip-1028)
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts twoslash
|
|
163
|
+
* // @noErrors
|
|
164
|
+
* import { ReceivePolicyReceipt } from 'ox/tempo'
|
|
165
|
+
*
|
|
166
|
+
* const receipts = ReceivePolicyReceipt.fromTransactionReceipt(receipt)
|
|
167
|
+
* const decoded = ReceivePolicyReceipt.decode('0x...')
|
|
168
|
+
* ```
|
|
169
|
+
*
|
|
170
|
+
* @category Reference
|
|
171
|
+
*/
|
|
172
|
+
export * as ReceivePolicyReceipt from './ReceivePolicyReceipt.js';
|
|
151
173
|
/**
|
|
152
174
|
* Union of all JSON-RPC Methods for the `tempo_` namespace.
|
|
153
175
|
*
|
package/_esm/tempo/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../tempo/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAA;AAC7D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,OAAO,KAAK,gBAAgB,MAAM,uBAAuB,CAAA;AACzD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AAErD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,iBAAiB,MAAM,wBAAwB,CAAA;AAC3D;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AACjD;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,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AAK,MAAM,MAAM,aAAa,CAAA;AACrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,OAAO,KAAK,qBAAqB,MAAM,4BAA4B,CAAA"}
|
package/_esm/version.js
CHANGED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import * as AbiEvent from '../core/AbiEvent.js';
|
|
2
|
+
import * as AbiParameters from '../core/AbiParameters.js';
|
|
3
|
+
import type * as Address from '../core/Address.js';
|
|
4
|
+
import type * as Errors from '../core/Errors.js';
|
|
5
|
+
import type * as Hex from '../core/Hex.js';
|
|
6
|
+
import type { Compute } from '../core/internal/types.js';
|
|
7
|
+
/**
|
|
8
|
+
* A TIP-1028 receive-policy claim receipt: the ABI-encoded `ClaimReceiptV1`
|
|
9
|
+
* witness emitted when an inbound transfer or mint violates the recipient's
|
|
10
|
+
* receive policy.
|
|
11
|
+
*
|
|
12
|
+
* This is the canonical, on-chain representation – the value passed to the
|
|
13
|
+
* `ReceivePolicyGuard`'s `claim` and `burn` functions. Use `decode` to read its
|
|
14
|
+
* fields.
|
|
15
|
+
*/
|
|
16
|
+
export type ReceivePolicyReceipt = Hex.Hex;
|
|
17
|
+
/** Reason an inbound transfer or mint was blocked by a receive policy. */
|
|
18
|
+
export type BlockedReason = 'none' | 'tokenFilter' | 'receivePolicy';
|
|
19
|
+
/** Kind of inbound operation that was blocked. */
|
|
20
|
+
export type Kind = 'transfer' | 'mint';
|
|
21
|
+
/** A decoded {@link ox#ReceivePolicyReceipt.ReceivePolicyReceipt}. */
|
|
22
|
+
export type Decoded = Compute<{
|
|
23
|
+
/** Receipt layout version. */
|
|
24
|
+
version: number;
|
|
25
|
+
/** TIP-20 token holding the blocked funds. */
|
|
26
|
+
token: Address.Address;
|
|
27
|
+
/** Recovery authority captured when the operation was blocked. */
|
|
28
|
+
recoveryAuthority: Address.Address;
|
|
29
|
+
/** Original sender (transfer) or issuer (mint). */
|
|
30
|
+
originator: Address.Address;
|
|
31
|
+
/** Addressed recipient (may be a virtual address). */
|
|
32
|
+
recipient: Address.Address;
|
|
33
|
+
/** Block timestamp when the operation was blocked. */
|
|
34
|
+
blockedAt: bigint;
|
|
35
|
+
/** Guard nonce assigned when the operation was blocked. */
|
|
36
|
+
blockedNonce: bigint;
|
|
37
|
+
/** Reason the operation was blocked. */
|
|
38
|
+
blockedReason: BlockedReason;
|
|
39
|
+
/** Whether the blocked operation was a transfer or mint. */
|
|
40
|
+
kind: Kind;
|
|
41
|
+
/** Application memo. */
|
|
42
|
+
memo: Hex.Hex;
|
|
43
|
+
}>;
|
|
44
|
+
/**
|
|
45
|
+
* Decodes a {@link ox#ReceivePolicyReceipt.ReceivePolicyReceipt} (ABI-encoded
|
|
46
|
+
* `ClaimReceiptV1` witness) into its fields.
|
|
47
|
+
*
|
|
48
|
+
* [TIP-1028](https://docs.tempo.xyz/protocol/tips/tip-1028)
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts twoslash
|
|
52
|
+
* import { ReceivePolicyReceipt } from 'ox/tempo'
|
|
53
|
+
*
|
|
54
|
+
* const decoded = ReceivePolicyReceipt.decode('0x...')
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @param receipt - The receive-policy receipt.
|
|
58
|
+
* @returns The decoded fields.
|
|
59
|
+
*/
|
|
60
|
+
export declare function decode(receipt: ReceivePolicyReceipt): Decoded;
|
|
61
|
+
export declare namespace decode {
|
|
62
|
+
type ErrorType = AbiParameters.decode.ErrorType | Errors.GlobalErrorType;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Encodes decoded fields into a
|
|
66
|
+
* {@link ox#ReceivePolicyReceipt.ReceivePolicyReceipt}. Inverse of `decode`.
|
|
67
|
+
*
|
|
68
|
+
* [TIP-1028](https://docs.tempo.xyz/protocol/tips/tip-1028)
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts twoslash
|
|
72
|
+
* // @noErrors
|
|
73
|
+
* import { ReceivePolicyReceipt } from 'ox/tempo'
|
|
74
|
+
*
|
|
75
|
+
* const decoded = ReceivePolicyReceipt.decode('0x...')
|
|
76
|
+
* const receipt = ReceivePolicyReceipt.encode(decoded)
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* @param decoded - The decoded fields.
|
|
80
|
+
* @returns The receive-policy receipt.
|
|
81
|
+
*/
|
|
82
|
+
export declare function encode(decoded: Decoded): ReceivePolicyReceipt;
|
|
83
|
+
export declare namespace encode {
|
|
84
|
+
type ErrorType = AbiParameters.encode.ErrorType | Errors.GlobalErrorType;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Normalizes a {@link ox#ReceivePolicyReceipt.ReceivePolicyReceipt} from either
|
|
88
|
+
* an encoded receipt (passthrough) or decoded fields.
|
|
89
|
+
*
|
|
90
|
+
* [TIP-1028](https://docs.tempo.xyz/protocol/tips/tip-1028)
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts twoslash
|
|
94
|
+
* // @noErrors
|
|
95
|
+
* import { ReceivePolicyReceipt } from 'ox/tempo'
|
|
96
|
+
*
|
|
97
|
+
* // From an encoded receipt (passthrough).
|
|
98
|
+
* const a = ReceivePolicyReceipt.from('0x...')
|
|
99
|
+
*
|
|
100
|
+
* // From decoded fields.
|
|
101
|
+
* const b = ReceivePolicyReceipt.from(ReceivePolicyReceipt.decode('0x...'))
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @param value - An encoded receipt or decoded fields.
|
|
105
|
+
* @returns The receive-policy receipt.
|
|
106
|
+
*/
|
|
107
|
+
export declare function from(value: ReceivePolicyReceipt | Decoded): ReceivePolicyReceipt;
|
|
108
|
+
export declare namespace from {
|
|
109
|
+
type ErrorType = encode.ErrorType | Errors.GlobalErrorType;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Extracts the {@link ox#ReceivePolicyReceipt.ReceivePolicyReceipt} from a
|
|
113
|
+
* `ReceivePolicyGuard` `TransferBlocked` log.
|
|
114
|
+
*
|
|
115
|
+
* Throws if the log is not a `TransferBlocked` event. Use
|
|
116
|
+
* `fromTransactionReceipt` to extract every blocked transfer in a transaction
|
|
117
|
+
* (which skips unrelated logs).
|
|
118
|
+
*
|
|
119
|
+
* [TIP-1028](https://docs.tempo.xyz/protocol/tips/tip-1028)
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts twoslash
|
|
123
|
+
* // @noErrors
|
|
124
|
+
* import { ReceivePolicyReceipt } from 'ox/tempo'
|
|
125
|
+
*
|
|
126
|
+
* const receipt = ReceivePolicyReceipt.fromLog(log)
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* @param log - A `TransferBlocked` log (`data` & `topics`).
|
|
130
|
+
* @returns The receive-policy receipt.
|
|
131
|
+
*/
|
|
132
|
+
export declare function fromLog(log: fromLog.Log): ReceivePolicyReceipt;
|
|
133
|
+
export declare namespace fromLog {
|
|
134
|
+
type Log = AbiEvent.decode.Log;
|
|
135
|
+
type ErrorType = AbiEvent.decode.ErrorType | Errors.GlobalErrorType;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Extracts every {@link ox#ReceivePolicyReceipt.ReceivePolicyReceipt} from a
|
|
139
|
+
* transaction receipt's logs.
|
|
140
|
+
*
|
|
141
|
+
* A single transaction may block multiple inbound transfers (e.g. a batched
|
|
142
|
+
* transfer to several recipients), so this returns an array – one entry per
|
|
143
|
+
* `TransferBlocked` log, in log order. Returns an empty array when no transfers
|
|
144
|
+
* were blocked.
|
|
145
|
+
*
|
|
146
|
+
* [TIP-1028](https://docs.tempo.xyz/protocol/tips/tip-1028)
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts twoslash
|
|
150
|
+
* // @noErrors
|
|
151
|
+
* import { ReceivePolicyReceipt } from 'ox/tempo'
|
|
152
|
+
*
|
|
153
|
+
* const receipts = ReceivePolicyReceipt.fromTransactionReceipt(receipt)
|
|
154
|
+
* // @log: ['0x...'] (pass each to `claim` / `burn`)
|
|
155
|
+
* ```
|
|
156
|
+
*
|
|
157
|
+
* @param receipt - The transaction receipt (or any object with `logs`).
|
|
158
|
+
* @returns The receive-policy receipts, one per blocked transfer.
|
|
159
|
+
*/
|
|
160
|
+
export declare function fromTransactionReceipt(receipt: fromTransactionReceipt.Receipt): readonly ReceivePolicyReceipt[];
|
|
161
|
+
export declare namespace fromTransactionReceipt {
|
|
162
|
+
type Receipt = {
|
|
163
|
+
/** Logs emitted by the transaction. */
|
|
164
|
+
logs?: readonly AbiEvent.decode.Log[] | undefined;
|
|
165
|
+
};
|
|
166
|
+
type ErrorType = AbiEvent.getSelector.ErrorType | fromLog.ErrorType | Errors.GlobalErrorType;
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=ReceivePolicyReceipt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReceivePolicyReceipt.d.ts","sourceRoot":"","sources":["../../tempo/ReceivePolicyReceipt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAC/C,OAAO,KAAK,aAAa,MAAM,0BAA0B,CAAA;AACzD,OAAO,KAAK,KAAK,OAAO,MAAM,oBAAoB,CAAA;AAClD,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,KAAK,GAAG,MAAM,gBAAgB,CAAA;AAC1C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AAExD;;;;;;;;GAQG;AACH,MAAM,MAAM,oBAAoB,GAAG,GAAG,CAAC,GAAG,CAAA;AAE1C,0EAA0E;AAC1E,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,aAAa,GAAG,eAAe,CAAA;AAEpE,kDAAkD;AAClD,MAAM,MAAM,IAAI,GAAG,UAAU,GAAG,MAAM,CAAA;AAEtC,sEAAsE;AACtE,MAAM,MAAM,OAAO,GAAG,O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D;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,GAAG,oBAAoB,CAG9D;AAED,MAAM,CAAC,OAAO,WAAW,OAAO,CAAC;IAC/B,KAAK,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAA;IAE9B,KAAK,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,eAAe,CAAA;CACpE;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,sBAAsB,CAAC,OAAO,GACtC,SAAS,oBAAoB,EAAE,CAQjC;AAED,MAAM,CAAC,OAAO,WAAW,sBAAsB,CAAC;IAC9C,KAAK,OAAO,GAAG;QACb,uCAAuC;QACvC,IAAI,CAAC,EAAE,SAAS,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,SAAS,CAAA;KAClD,CAAA;IAED,KAAK,SAAS,GACV,QAAQ,CAAC,WAAW,CAAC,SAAS,GAC9B,OAAO,CAAC,SAAS,GACjB,MAAM,CAAC,eAAe,CAAA;CAC3B"}
|
package/_types/tempo/index.d.ts
CHANGED
|
@@ -150,6 +150,28 @@ export * as Period from './Period.js';
|
|
|
150
150
|
* @category Reference
|
|
151
151
|
*/
|
|
152
152
|
export * as PoolId from './PoolId.js';
|
|
153
|
+
/**
|
|
154
|
+
* TIP-1028 receive-policy claim receipt utilities.
|
|
155
|
+
*
|
|
156
|
+
* When an inbound transfer or mint violates the recipient's receive policy, the
|
|
157
|
+
* funds are redirected to the `ReceivePolicyGuard` and a `ClaimReceiptV1`
|
|
158
|
+
* witness is emitted. This module decodes those witnesses (required to later
|
|
159
|
+
* `claim` or `burn` the blocked funds) from raw bytes or transaction receipts.
|
|
160
|
+
*
|
|
161
|
+
* [TIP-1028](https://docs.tempo.xyz/protocol/tips/tip-1028)
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts twoslash
|
|
165
|
+
* // @noErrors
|
|
166
|
+
* import { ReceivePolicyReceipt } from 'ox/tempo'
|
|
167
|
+
*
|
|
168
|
+
* const receipts = ReceivePolicyReceipt.fromTransactionReceipt(receipt)
|
|
169
|
+
* const decoded = ReceivePolicyReceipt.decode('0x...')
|
|
170
|
+
* ```
|
|
171
|
+
*
|
|
172
|
+
* @category Reference
|
|
173
|
+
*/
|
|
174
|
+
export * as ReceivePolicyReceipt from './ReceivePolicyReceipt.js';
|
|
153
175
|
/**
|
|
154
176
|
* Union of all JSON-RPC Methods for the `tempo_` namespace.
|
|
155
177
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../tempo/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAEhC,YAAY,EAAE,CAAA;AAEd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAA;AAC7D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,OAAO,KAAK,gBAAgB,MAAM,uBAAuB,CAAA;AACzD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AAErD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,iBAAiB,MAAM,wBAAwB,CAAA;AAC3D;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AACjD;;;;;;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,MAAM,qBAAqB,CAAA;AACrD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AAEnD;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,OAAO,KAAK,qBAAqB,MAAM,4BAA4B,CAAA"}
|
package/_types/version.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ox",
|
|
3
3
|
"description": "Ethereum Standard Library",
|
|
4
|
-
"version": "0.14.
|
|
4
|
+
"version": "0.14.27",
|
|
5
5
|
"main": "./_cjs/index.js",
|
|
6
6
|
"module": "./_esm/index.js",
|
|
7
7
|
"types": "./_types/index.d.ts",
|
|
@@ -523,6 +523,11 @@
|
|
|
523
523
|
"import": "./_esm/tempo/PoolId.js",
|
|
524
524
|
"default": "./_cjs/tempo/PoolId.js"
|
|
525
525
|
},
|
|
526
|
+
"./tempo/ReceivePolicyReceipt": {
|
|
527
|
+
"types": "./_types/tempo/ReceivePolicyReceipt.d.ts",
|
|
528
|
+
"import": "./_esm/tempo/ReceivePolicyReceipt.js",
|
|
529
|
+
"default": "./_cjs/tempo/ReceivePolicyReceipt.js"
|
|
530
|
+
},
|
|
526
531
|
"./tempo/RpcSchemaTempo": {
|
|
527
532
|
"types": "./_types/tempo/RpcSchemaTempo.d.ts",
|
|
528
533
|
"import": "./_esm/tempo/RpcSchemaTempo.js",
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { AbiEvent, AbiParameters } from 'ox'
|
|
2
|
+
import { ReceivePolicyReceipt } from 'ox/tempo'
|
|
3
|
+
import { describe, expect, test } from 'vitest'
|
|
4
|
+
|
|
5
|
+
const token = '0x20c0000000000000000000000000000000000001'
|
|
6
|
+
const originator = '0x0000000000000000000000000000000000000aaa'
|
|
7
|
+
const recipient = '0x0000000000000000000000000000000000000bbb'
|
|
8
|
+
const zeroAddress = '0x0000000000000000000000000000000000000000'
|
|
9
|
+
const zeroHash =
|
|
10
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000'
|
|
11
|
+
|
|
12
|
+
const witnessParameters = [
|
|
13
|
+
{
|
|
14
|
+
type: 'tuple',
|
|
15
|
+
components: [
|
|
16
|
+
{ name: 'version', type: 'uint8' },
|
|
17
|
+
{ name: 'token', type: 'address' },
|
|
18
|
+
{ name: 'recoveryAuthority', type: 'address' },
|
|
19
|
+
{ name: 'originator', type: 'address' },
|
|
20
|
+
{ name: 'recipient', type: 'address' },
|
|
21
|
+
{ name: 'blockedAt', type: 'uint64' },
|
|
22
|
+
{ name: 'blockedNonce', type: 'uint64' },
|
|
23
|
+
{ name: 'blockedReason', type: 'uint8' },
|
|
24
|
+
{ name: 'kind', type: 'uint8' },
|
|
25
|
+
{ name: 'memo', type: 'bytes32' },
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
] as const
|
|
29
|
+
|
|
30
|
+
function encodeWitness(
|
|
31
|
+
overrides: Partial<{
|
|
32
|
+
blockedReason: number
|
|
33
|
+
kind: number
|
|
34
|
+
}> = {},
|
|
35
|
+
) {
|
|
36
|
+
return AbiParameters.encode(witnessParameters, [
|
|
37
|
+
{
|
|
38
|
+
version: 1,
|
|
39
|
+
token,
|
|
40
|
+
recoveryAuthority: zeroAddress,
|
|
41
|
+
originator,
|
|
42
|
+
recipient,
|
|
43
|
+
blockedAt: 1234n,
|
|
44
|
+
blockedNonce: 5n,
|
|
45
|
+
blockedReason: overrides.blockedReason ?? 2,
|
|
46
|
+
kind: overrides.kind ?? 0,
|
|
47
|
+
memo: zeroHash,
|
|
48
|
+
},
|
|
49
|
+
])
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const transferBlocked = AbiEvent.from(
|
|
53
|
+
'event TransferBlocked(address indexed token, address indexed receiver, uint64 indexed blockedNonce, uint256 amount, uint8 receiptVersion, bytes receipt)',
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
function blockedLog(witness: `0x${string}`) {
|
|
57
|
+
const { topics } = AbiEvent.encode(transferBlocked, {
|
|
58
|
+
token,
|
|
59
|
+
receiver: recipient,
|
|
60
|
+
blockedNonce: 5n,
|
|
61
|
+
})
|
|
62
|
+
const data = AbiParameters.encode(
|
|
63
|
+
[{ type: 'uint256' }, { type: 'uint8' }, { type: 'bytes' }],
|
|
64
|
+
[10_000_000n, 1, witness],
|
|
65
|
+
)
|
|
66
|
+
return { data, topics: topics as readonly `0x${string}`[] }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
describe('decode', () => {
|
|
70
|
+
test('default', () => {
|
|
71
|
+
expect(ReceivePolicyReceipt.decode(encodeWitness())).toMatchInlineSnapshot(`
|
|
72
|
+
{
|
|
73
|
+
"blockedAt": 1234n,
|
|
74
|
+
"blockedNonce": 5n,
|
|
75
|
+
"blockedReason": "receivePolicy",
|
|
76
|
+
"kind": "transfer",
|
|
77
|
+
"memo": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
78
|
+
"originator": "0x0000000000000000000000000000000000000aaa",
|
|
79
|
+
"recipient": "0x0000000000000000000000000000000000000bbb",
|
|
80
|
+
"recoveryAuthority": "0x0000000000000000000000000000000000000000",
|
|
81
|
+
"token": "0x20c0000000000000000000000000000000000001",
|
|
82
|
+
"version": 1,
|
|
83
|
+
}
|
|
84
|
+
`)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test('behavior: kind mint', () => {
|
|
88
|
+
expect(ReceivePolicyReceipt.decode(encodeWitness({ kind: 1 })).kind).toBe(
|
|
89
|
+
'mint',
|
|
90
|
+
)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
test('behavior: blocked reason token filter', () => {
|
|
94
|
+
expect(
|
|
95
|
+
ReceivePolicyReceipt.decode(encodeWitness({ blockedReason: 1 }))
|
|
96
|
+
.blockedReason,
|
|
97
|
+
).toBe('tokenFilter')
|
|
98
|
+
})
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
describe('encode', () => {
|
|
102
|
+
test('round-trips with decode', () => {
|
|
103
|
+
const witness = encodeWitness()
|
|
104
|
+
expect(
|
|
105
|
+
ReceivePolicyReceipt.encode(ReceivePolicyReceipt.decode(witness)),
|
|
106
|
+
).toBe(witness)
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
test('behavior: maps enum strings back to indices', () => {
|
|
110
|
+
const receipt = ReceivePolicyReceipt.decode(
|
|
111
|
+
encodeWitness({ blockedReason: 1, kind: 1 }),
|
|
112
|
+
)
|
|
113
|
+
const reencoded = ReceivePolicyReceipt.encode(receipt)
|
|
114
|
+
expect(ReceivePolicyReceipt.decode(reencoded)).toEqual(receipt)
|
|
115
|
+
})
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
describe('fromLog', () => {
|
|
119
|
+
test('default', () => {
|
|
120
|
+
const witness = encodeWitness()
|
|
121
|
+
expect(ReceivePolicyReceipt.fromLog(blockedLog(witness))).toBe(witness)
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
test('error: non-matching log', () => {
|
|
125
|
+
expect(() =>
|
|
126
|
+
ReceivePolicyReceipt.fromLog({ data: '0x', topics: [zeroHash] }),
|
|
127
|
+
).toThrow()
|
|
128
|
+
})
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
describe('from', () => {
|
|
132
|
+
test('passthrough encoded receipt', () => {
|
|
133
|
+
const witness = encodeWitness()
|
|
134
|
+
expect(ReceivePolicyReceipt.from(witness)).toBe(witness)
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
test('from decoded fields', () => {
|
|
138
|
+
const witness = encodeWitness()
|
|
139
|
+
expect(
|
|
140
|
+
ReceivePolicyReceipt.from(ReceivePolicyReceipt.decode(witness)),
|
|
141
|
+
).toBe(witness)
|
|
142
|
+
})
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
describe('fromTransactionReceipt', () => {
|
|
146
|
+
test('single blocked transfer', () => {
|
|
147
|
+
const witness = encodeWitness()
|
|
148
|
+
const receipts = ReceivePolicyReceipt.fromTransactionReceipt({
|
|
149
|
+
logs: [blockedLog(witness)],
|
|
150
|
+
})
|
|
151
|
+
expect(receipts).toHaveLength(1)
|
|
152
|
+
expect(receipts[0]).toBe(witness)
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
test('multiple blocked transfers', () => {
|
|
156
|
+
const receipts = ReceivePolicyReceipt.fromTransactionReceipt({
|
|
157
|
+
logs: [
|
|
158
|
+
blockedLog(encodeWitness()),
|
|
159
|
+
blockedLog(encodeWitness({ kind: 1 })),
|
|
160
|
+
],
|
|
161
|
+
})
|
|
162
|
+
expect(receipts).toHaveLength(2)
|
|
163
|
+
expect(ReceivePolicyReceipt.decode(receipts[0]!).kind).toBe('transfer')
|
|
164
|
+
expect(ReceivePolicyReceipt.decode(receipts[1]!).kind).toBe('mint')
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
test('ignores unrelated logs', () => {
|
|
168
|
+
const receipts = ReceivePolicyReceipt.fromTransactionReceipt({
|
|
169
|
+
logs: [
|
|
170
|
+
{
|
|
171
|
+
data: '0x',
|
|
172
|
+
topics: [zeroHash],
|
|
173
|
+
},
|
|
174
|
+
blockedLog(encodeWitness()),
|
|
175
|
+
],
|
|
176
|
+
})
|
|
177
|
+
expect(receipts).toHaveLength(1)
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
test('behavior: no logs', () => {
|
|
181
|
+
expect(ReceivePolicyReceipt.fromTransactionReceipt({})).toEqual([])
|
|
182
|
+
expect(ReceivePolicyReceipt.fromTransactionReceipt({ logs: [] })).toEqual(
|
|
183
|
+
[],
|
|
184
|
+
)
|
|
185
|
+
})
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
test('exports', () => {
|
|
189
|
+
expect(Object.keys(ReceivePolicyReceipt)).toMatchInlineSnapshot(`
|
|
190
|
+
[
|
|
191
|
+
"decode",
|
|
192
|
+
"encode",
|
|
193
|
+
"from",
|
|
194
|
+
"fromLog",
|
|
195
|
+
"fromTransactionReceipt",
|
|
196
|
+
]
|
|
197
|
+
`)
|
|
198
|
+
})
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import * as AbiEvent from '../core/AbiEvent.js'
|
|
2
|
+
import * as AbiParameters from '../core/AbiParameters.js'
|
|
3
|
+
import type * as Address from '../core/Address.js'
|
|
4
|
+
import type * as Errors from '../core/Errors.js'
|
|
5
|
+
import type * as Hex from '../core/Hex.js'
|
|
6
|
+
import type { Compute } from '../core/internal/types.js'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A TIP-1028 receive-policy claim receipt: the ABI-encoded `ClaimReceiptV1`
|
|
10
|
+
* witness emitted when an inbound transfer or mint violates the recipient's
|
|
11
|
+
* receive policy.
|
|
12
|
+
*
|
|
13
|
+
* This is the canonical, on-chain representation – the value passed to the
|
|
14
|
+
* `ReceivePolicyGuard`'s `claim` and `burn` functions. Use `decode` to read its
|
|
15
|
+
* fields.
|
|
16
|
+
*/
|
|
17
|
+
export type ReceivePolicyReceipt = Hex.Hex
|
|
18
|
+
|
|
19
|
+
/** Reason an inbound transfer or mint was blocked by a receive policy. */
|
|
20
|
+
export type BlockedReason = 'none' | 'tokenFilter' | 'receivePolicy'
|
|
21
|
+
|
|
22
|
+
/** Kind of inbound operation that was blocked. */
|
|
23
|
+
export type Kind = 'transfer' | 'mint'
|
|
24
|
+
|
|
25
|
+
/** A decoded {@link ox#ReceivePolicyReceipt.ReceivePolicyReceipt}. */
|
|
26
|
+
export type Decoded = Compute<{
|
|
27
|
+
/** Receipt layout version. */
|
|
28
|
+
version: number
|
|
29
|
+
/** TIP-20 token holding the blocked funds. */
|
|
30
|
+
token: Address.Address
|
|
31
|
+
/** Recovery authority captured when the operation was blocked. */
|
|
32
|
+
recoveryAuthority: Address.Address
|
|
33
|
+
/** Original sender (transfer) or issuer (mint). */
|
|
34
|
+
originator: Address.Address
|
|
35
|
+
/** Addressed recipient (may be a virtual address). */
|
|
36
|
+
recipient: Address.Address
|
|
37
|
+
/** Block timestamp when the operation was blocked. */
|
|
38
|
+
blockedAt: bigint
|
|
39
|
+
/** Guard nonce assigned when the operation was blocked. */
|
|
40
|
+
blockedNonce: bigint
|
|
41
|
+
/** Reason the operation was blocked. */
|
|
42
|
+
blockedReason: BlockedReason
|
|
43
|
+
/** Whether the blocked operation was a transfer or mint. */
|
|
44
|
+
kind: Kind
|
|
45
|
+
/** Application memo. */
|
|
46
|
+
memo: Hex.Hex
|
|
47
|
+
}>
|
|
48
|
+
|
|
49
|
+
/** @internal */
|
|
50
|
+
const blockedReasons = ['none', 'tokenFilter', 'receivePolicy'] as const
|
|
51
|
+
|
|
52
|
+
/** @internal */
|
|
53
|
+
const kinds = ['transfer', 'mint'] as const
|
|
54
|
+
|
|
55
|
+
/** @internal ABI parameters for the `ClaimReceiptV1` witness. */
|
|
56
|
+
const parameters = [
|
|
57
|
+
{
|
|
58
|
+
type: 'tuple',
|
|
59
|
+
components: [
|
|
60
|
+
{ name: 'version', type: 'uint8' },
|
|
61
|
+
{ name: 'token', type: 'address' },
|
|
62
|
+
{ name: 'recoveryAuthority', type: 'address' },
|
|
63
|
+
{ name: 'originator', type: 'address' },
|
|
64
|
+
{ name: 'recipient', type: 'address' },
|
|
65
|
+
{ name: 'blockedAt', type: 'uint64' },
|
|
66
|
+
{ name: 'blockedNonce', type: 'uint64' },
|
|
67
|
+
{ name: 'blockedReason', type: 'uint8' },
|
|
68
|
+
{ name: 'kind', type: 'uint8' },
|
|
69
|
+
{ name: 'memo', type: 'bytes32' },
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
] as const
|
|
73
|
+
|
|
74
|
+
/** @internal `TransferBlocked` event emitted by the `ReceivePolicyGuard`. */
|
|
75
|
+
const transferBlocked = AbiEvent.from(
|
|
76
|
+
'event TransferBlocked(address indexed token, address indexed receiver, uint64 indexed blockedNonce, uint256 amount, uint8 receiptVersion, bytes receipt)',
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Decodes a {@link ox#ReceivePolicyReceipt.ReceivePolicyReceipt} (ABI-encoded
|
|
81
|
+
* `ClaimReceiptV1` witness) into its fields.
|
|
82
|
+
*
|
|
83
|
+
* [TIP-1028](https://docs.tempo.xyz/protocol/tips/tip-1028)
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts twoslash
|
|
87
|
+
* import { ReceivePolicyReceipt } from 'ox/tempo'
|
|
88
|
+
*
|
|
89
|
+
* const decoded = ReceivePolicyReceipt.decode('0x...')
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @param receipt - The receive-policy receipt.
|
|
93
|
+
* @returns The decoded fields.
|
|
94
|
+
*/
|
|
95
|
+
export function decode(receipt: ReceivePolicyReceipt): Decoded {
|
|
96
|
+
const [decoded] = AbiParameters.decode(parameters, receipt)
|
|
97
|
+
return {
|
|
98
|
+
version: decoded.version,
|
|
99
|
+
token: decoded.token,
|
|
100
|
+
recoveryAuthority: decoded.recoveryAuthority,
|
|
101
|
+
originator: decoded.originator,
|
|
102
|
+
recipient: decoded.recipient,
|
|
103
|
+
blockedAt: decoded.blockedAt,
|
|
104
|
+
blockedNonce: decoded.blockedNonce,
|
|
105
|
+
blockedReason: blockedReasons[decoded.blockedReason] ?? 'none',
|
|
106
|
+
kind: kinds[decoded.kind] ?? 'transfer',
|
|
107
|
+
memo: decoded.memo,
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export declare namespace decode {
|
|
112
|
+
type ErrorType = AbiParameters.decode.ErrorType | Errors.GlobalErrorType
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Encodes decoded fields into a
|
|
117
|
+
* {@link ox#ReceivePolicyReceipt.ReceivePolicyReceipt}. Inverse of `decode`.
|
|
118
|
+
*
|
|
119
|
+
* [TIP-1028](https://docs.tempo.xyz/protocol/tips/tip-1028)
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts twoslash
|
|
123
|
+
* // @noErrors
|
|
124
|
+
* import { ReceivePolicyReceipt } from 'ox/tempo'
|
|
125
|
+
*
|
|
126
|
+
* const decoded = ReceivePolicyReceipt.decode('0x...')
|
|
127
|
+
* const receipt = ReceivePolicyReceipt.encode(decoded)
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* @param decoded - The decoded fields.
|
|
131
|
+
* @returns The receive-policy receipt.
|
|
132
|
+
*/
|
|
133
|
+
export function encode(decoded: Decoded): ReceivePolicyReceipt {
|
|
134
|
+
return AbiParameters.encode(parameters, [
|
|
135
|
+
{
|
|
136
|
+
version: decoded.version,
|
|
137
|
+
token: decoded.token,
|
|
138
|
+
recoveryAuthority: decoded.recoveryAuthority,
|
|
139
|
+
originator: decoded.originator,
|
|
140
|
+
recipient: decoded.recipient,
|
|
141
|
+
blockedAt: decoded.blockedAt,
|
|
142
|
+
blockedNonce: decoded.blockedNonce,
|
|
143
|
+
blockedReason: blockedReasons.indexOf(decoded.blockedReason),
|
|
144
|
+
kind: kinds.indexOf(decoded.kind),
|
|
145
|
+
memo: decoded.memo,
|
|
146
|
+
},
|
|
147
|
+
])
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export declare namespace encode {
|
|
151
|
+
type ErrorType = AbiParameters.encode.ErrorType | Errors.GlobalErrorType
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Normalizes a {@link ox#ReceivePolicyReceipt.ReceivePolicyReceipt} from either
|
|
156
|
+
* an encoded receipt (passthrough) or decoded fields.
|
|
157
|
+
*
|
|
158
|
+
* [TIP-1028](https://docs.tempo.xyz/protocol/tips/tip-1028)
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```ts twoslash
|
|
162
|
+
* // @noErrors
|
|
163
|
+
* import { ReceivePolicyReceipt } from 'ox/tempo'
|
|
164
|
+
*
|
|
165
|
+
* // From an encoded receipt (passthrough).
|
|
166
|
+
* const a = ReceivePolicyReceipt.from('0x...')
|
|
167
|
+
*
|
|
168
|
+
* // From decoded fields.
|
|
169
|
+
* const b = ReceivePolicyReceipt.from(ReceivePolicyReceipt.decode('0x...'))
|
|
170
|
+
* ```
|
|
171
|
+
*
|
|
172
|
+
* @param value - An encoded receipt or decoded fields.
|
|
173
|
+
* @returns The receive-policy receipt.
|
|
174
|
+
*/
|
|
175
|
+
export function from(
|
|
176
|
+
value: ReceivePolicyReceipt | Decoded,
|
|
177
|
+
): ReceivePolicyReceipt {
|
|
178
|
+
if (typeof value === 'string') return value
|
|
179
|
+
return encode(value)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export declare namespace from {
|
|
183
|
+
type ErrorType = encode.ErrorType | Errors.GlobalErrorType
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Extracts the {@link ox#ReceivePolicyReceipt.ReceivePolicyReceipt} from a
|
|
188
|
+
* `ReceivePolicyGuard` `TransferBlocked` log.
|
|
189
|
+
*
|
|
190
|
+
* Throws if the log is not a `TransferBlocked` event. Use
|
|
191
|
+
* `fromTransactionReceipt` to extract every blocked transfer in a transaction
|
|
192
|
+
* (which skips unrelated logs).
|
|
193
|
+
*
|
|
194
|
+
* [TIP-1028](https://docs.tempo.xyz/protocol/tips/tip-1028)
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```ts twoslash
|
|
198
|
+
* // @noErrors
|
|
199
|
+
* import { ReceivePolicyReceipt } from 'ox/tempo'
|
|
200
|
+
*
|
|
201
|
+
* const receipt = ReceivePolicyReceipt.fromLog(log)
|
|
202
|
+
* ```
|
|
203
|
+
*
|
|
204
|
+
* @param log - A `TransferBlocked` log (`data` & `topics`).
|
|
205
|
+
* @returns The receive-policy receipt.
|
|
206
|
+
*/
|
|
207
|
+
export function fromLog(log: fromLog.Log): ReceivePolicyReceipt {
|
|
208
|
+
const { receipt } = AbiEvent.decode(transferBlocked, log)
|
|
209
|
+
return receipt
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export declare namespace fromLog {
|
|
213
|
+
type Log = AbiEvent.decode.Log
|
|
214
|
+
|
|
215
|
+
type ErrorType = AbiEvent.decode.ErrorType | Errors.GlobalErrorType
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Extracts every {@link ox#ReceivePolicyReceipt.ReceivePolicyReceipt} from a
|
|
220
|
+
* transaction receipt's logs.
|
|
221
|
+
*
|
|
222
|
+
* A single transaction may block multiple inbound transfers (e.g. a batched
|
|
223
|
+
* transfer to several recipients), so this returns an array – one entry per
|
|
224
|
+
* `TransferBlocked` log, in log order. Returns an empty array when no transfers
|
|
225
|
+
* were blocked.
|
|
226
|
+
*
|
|
227
|
+
* [TIP-1028](https://docs.tempo.xyz/protocol/tips/tip-1028)
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```ts twoslash
|
|
231
|
+
* // @noErrors
|
|
232
|
+
* import { ReceivePolicyReceipt } from 'ox/tempo'
|
|
233
|
+
*
|
|
234
|
+
* const receipts = ReceivePolicyReceipt.fromTransactionReceipt(receipt)
|
|
235
|
+
* // @log: ['0x...'] (pass each to `claim` / `burn`)
|
|
236
|
+
* ```
|
|
237
|
+
*
|
|
238
|
+
* @param receipt - The transaction receipt (or any object with `logs`).
|
|
239
|
+
* @returns The receive-policy receipts, one per blocked transfer.
|
|
240
|
+
*/
|
|
241
|
+
export function fromTransactionReceipt(
|
|
242
|
+
receipt: fromTransactionReceipt.Receipt,
|
|
243
|
+
): readonly ReceivePolicyReceipt[] {
|
|
244
|
+
const selector = AbiEvent.getSelector(transferBlocked)
|
|
245
|
+
const receipts: ReceivePolicyReceipt[] = []
|
|
246
|
+
for (const log of receipt.logs ?? []) {
|
|
247
|
+
if (log.topics[0] !== selector) continue
|
|
248
|
+
receipts.push(fromLog(log))
|
|
249
|
+
}
|
|
250
|
+
return receipts
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export declare namespace fromTransactionReceipt {
|
|
254
|
+
type Receipt = {
|
|
255
|
+
/** Logs emitted by the transaction. */
|
|
256
|
+
logs?: readonly AbiEvent.decode.Log[] | undefined
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
type ErrorType =
|
|
260
|
+
| AbiEvent.getSelector.ErrorType
|
|
261
|
+
| fromLog.ErrorType
|
|
262
|
+
| Errors.GlobalErrorType
|
|
263
|
+
}
|
package/tempo/index.ts
CHANGED
|
@@ -153,6 +153,28 @@ export * as Period from './Period.js'
|
|
|
153
153
|
* @category Reference
|
|
154
154
|
*/
|
|
155
155
|
export * as PoolId from './PoolId.js'
|
|
156
|
+
/**
|
|
157
|
+
* TIP-1028 receive-policy claim receipt utilities.
|
|
158
|
+
*
|
|
159
|
+
* When an inbound transfer or mint violates the recipient's receive policy, the
|
|
160
|
+
* funds are redirected to the `ReceivePolicyGuard` and a `ClaimReceiptV1`
|
|
161
|
+
* witness is emitted. This module decodes those witnesses (required to later
|
|
162
|
+
* `claim` or `burn` the blocked funds) from raw bytes or transaction receipts.
|
|
163
|
+
*
|
|
164
|
+
* [TIP-1028](https://docs.tempo.xyz/protocol/tips/tip-1028)
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```ts twoslash
|
|
168
|
+
* // @noErrors
|
|
169
|
+
* import { ReceivePolicyReceipt } from 'ox/tempo'
|
|
170
|
+
*
|
|
171
|
+
* const receipts = ReceivePolicyReceipt.fromTransactionReceipt(receipt)
|
|
172
|
+
* const decoded = ReceivePolicyReceipt.decode('0x...')
|
|
173
|
+
* ```
|
|
174
|
+
*
|
|
175
|
+
* @category Reference
|
|
176
|
+
*/
|
|
177
|
+
export * as ReceivePolicyReceipt from './ReceivePolicyReceipt.js'
|
|
156
178
|
/**
|
|
157
179
|
* Union of all JSON-RPC Methods for the `tempo_` namespace.
|
|
158
180
|
*
|
package/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** @internal */
|
|
2
|
-
export const version = '0.14.
|
|
2
|
+
export const version = '0.14.27'
|