ecash-agora 0.1.1-rc → 0.2.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/.eslintrc.js +45 -0
- package/README.md +42 -0
- package/agora.py +12 -3
- package/dist/ad.js +18 -14
- package/dist/ad.js.map +1 -1
- package/dist/agora.d.ts +55 -3
- package/dist/agora.d.ts.map +1 -1
- package/dist/agora.js +205 -59
- package/dist/agora.js.map +1 -1
- package/dist/consts.js +6 -3
- package/dist/consts.js.map +1 -1
- package/dist/index.js +21 -5
- package/dist/index.js.map +1 -1
- package/dist/oneshot.js +96 -89
- package/dist/oneshot.js.map +1 -1
- package/dist/partial.d.ts +29 -0
- package/dist/partial.d.ts.map +1 -1
- package/dist/partial.js +344 -274
- package/dist/partial.js.map +1 -1
- package/package.json +4 -4
- package/tests/oneshot.test.ts +139 -2
- package/tests/partial-helper-alp.ts +37 -16
- package/tests/partial-helper-slp.ts +2 -0
- package/tests/partial.alp.bigsats.test.ts +25 -12
- package/tests/partial.alp.test.ts +157 -23
- package/tests/partial.locktime.test.ts +244 -0
- package/tests/partial.slp.bigsats.test.ts +25 -14
- package/tests/partial.slp.test.ts +187 -24
- package/tsconfig.json +1 -2
- package/eslint.config.js +0 -16
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Copyright (c) 2024 The Bitcoin developers
|
|
2
|
+
// Distributed under the MIT software license, see the accompanying
|
|
3
|
+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
4
|
+
|
|
5
|
+
const headerArray = [
|
|
6
|
+
{
|
|
7
|
+
pattern:
|
|
8
|
+
'^ Copyright \\(c\\) 2[0-9]{3}(-2[0-9]{3})? The Bitcoin developers$',
|
|
9
|
+
template: ` Copyright (c) ${new Date().getFullYear()} The Bitcoin developers`,
|
|
10
|
+
},
|
|
11
|
+
' Distributed under the MIT software license, see the accompanying',
|
|
12
|
+
' file COPYING or http://www.opensource.org/licenses/mit-license.php.',
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
module.exports = {
|
|
16
|
+
env: {
|
|
17
|
+
node: true,
|
|
18
|
+
commonjs: true,
|
|
19
|
+
es2021: true,
|
|
20
|
+
mocha: true,
|
|
21
|
+
},
|
|
22
|
+
overrides: [],
|
|
23
|
+
extends: [
|
|
24
|
+
'eslint:recommended',
|
|
25
|
+
'plugin:@typescript-eslint/recommended', // Add TypeScript recommended rules
|
|
26
|
+
],
|
|
27
|
+
parserOptions: {
|
|
28
|
+
ecmaVersion: 'latest',
|
|
29
|
+
sourceType: 'module', // If you're using ES modules
|
|
30
|
+
parser: '@typescript-eslint/parser', // Use the TS parser
|
|
31
|
+
},
|
|
32
|
+
plugins: [
|
|
33
|
+
'header',
|
|
34
|
+
'@typescript-eslint', // Add the TypeScript plugin
|
|
35
|
+
],
|
|
36
|
+
rules: {
|
|
37
|
+
'strict': 'error',
|
|
38
|
+
'header/header': [2, 'line', headerArray, 2],
|
|
39
|
+
'no-unused-vars': 'off',
|
|
40
|
+
'@typescript-eslint/no-unused-vars': [
|
|
41
|
+
'error',
|
|
42
|
+
{ varsIgnorePattern: '^_' },
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
};
|
package/README.md
CHANGED
|
@@ -116,7 +116,49 @@ const acceptTx = txBuilder.sign(ecc);
|
|
|
116
116
|
await chronik.broadcastTx(acceptTx.ser());
|
|
117
117
|
```
|
|
118
118
|
|
|
119
|
+
## Development
|
|
120
|
+
|
|
121
|
+
### Running the integration tests locally
|
|
122
|
+
|
|
123
|
+
1. Build the node software from source with chronik and plugins enabled
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
mkdir build/
|
|
127
|
+
cd build/
|
|
128
|
+
cmake -GNinja .. -DBUILD_BITCOIN_CHRONIK=ON -DBUILD_BITCOIN_CHRONIK_PLUGINS=ON
|
|
129
|
+
ninja
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
2. You may need to [adjust](https://stackoverflow.com/questions/72409563/unsupported-hash-type-ripemd160-with-hashlib-in-python/72508879#72508879) your `openssl` settings
|
|
133
|
+
|
|
134
|
+
3. Specify the location of your built chronik-with-plugins node with the `BUILD_DIR` env variable, e.g.
|
|
135
|
+
|
|
136
|
+
Running from `bitcoin-abc/modules/ecash-agora` if your build dir is `bitcoin-abc/build/`:
|
|
137
|
+
|
|
138
|
+
`BUILD_DIR="${PWD}/../../build" npm run integration-tests`
|
|
139
|
+
|
|
119
140
|
## Changelog
|
|
120
141
|
|
|
121
142
|
- 0.1.0 - MVP [D16087](https://reviews.bitcoinabc.org/D16087) [D16111](https://reviews.bitcoinabc.org/D16111)
|
|
122
143
|
- 0.1.1 - Upgrading dependencies [D16374](https://reviews.bitcoinabc.org/D16374)
|
|
144
|
+
|
|
145
|
+
### 0.2.0
|
|
146
|
+
|
|
147
|
+
- Add agora.py plugin [D16544](https://reviews.bitcoinabc.org/D16544)
|
|
148
|
+
- Plugin support [D16745](https://reviews.bitcoinabc.org/D16745)|[D16753](https://reviews.bitcoinabc.org/D16753)|[D16754](https://reviews.bitcoinabc.org/D16754)|[D16755](https://reviews.bitcoinabc.org/D16755)
|
|
149
|
+
- Improve test framework [D16741](https://reviews.bitcoinabc.org/D16741)
|
|
150
|
+
- Websocket subscriptions [D16845](https://reviews.bitcoinabc.org/D16845)
|
|
151
|
+
- Build script for partial SLP offers [D16743](https://reviews.bitcoinabc.org/D16743)
|
|
152
|
+
- Approximation logic for partial offers [D16735](https://reviews.bitcoinabc.org/D16735)
|
|
153
|
+
- Add `historicOffers` function to `Agora` [D16819](https://reviews.bitcoinabc.org/D16819)
|
|
154
|
+
- Patch burned tokens issue in agora partial scripts [D16821](https://reviews.bitcoinabc.org/D16821)
|
|
155
|
+
- Export partial modules [D16820](https://reviews.bitcoinabc.org/D16820)
|
|
156
|
+
- Syntax linting [D16919](https://reviews.bitcoinabc.org/D16919)|[D16928](https://reviews.bitcoinabc.org/D16928)
|
|
157
|
+
- README patch for local integration testing [D16952](https://reviews.bitcoinabc.org/D16952)
|
|
158
|
+
- Patch minAcceptedTokens() to return true minimum (prepared value) [D16920](https://reviews.bitcoinabc.org/D16920)
|
|
159
|
+
- Add validation to acceptTx method of AgoraPartial to prevent creation of unspendable offers [D16944](https://reviews.bitcoinabc.org/D16944)
|
|
160
|
+
- Export `scriptOps` helper function [D16972](https://reviews.bitcoinabc.org/D16972)
|
|
161
|
+
- Improve approximation for USD-esque tokens [D16995](https://reviews.bitcoinabc.org/D16995)
|
|
162
|
+
- Update tsconfig to support use in nodejs [D17019](https://reviews.bitcoinabc.org/D17019)
|
|
163
|
+
- Monorepo linting [D17072](https://reviews.bitcoinabc.org/D17072)
|
|
164
|
+
- CI publishing [D17243](https://reviews.bitcoinabc.org/D17243)
|
package/agora.py
CHANGED
|
@@ -16,6 +16,7 @@ from dataclasses import dataclass
|
|
|
16
16
|
from io import BytesIO
|
|
17
17
|
from typing import Optional, Union
|
|
18
18
|
|
|
19
|
+
from chronik_plugin.etoken import Token
|
|
19
20
|
from chronik_plugin.plugin import Plugin, PluginOutput
|
|
20
21
|
from chronik_plugin.script import (
|
|
21
22
|
OP_0,
|
|
@@ -70,7 +71,6 @@ from chronik_plugin.script import (
|
|
|
70
71
|
CScript,
|
|
71
72
|
)
|
|
72
73
|
from chronik_plugin.slp import slp_send
|
|
73
|
-
from chronik_plugin.token import Token
|
|
74
74
|
|
|
75
75
|
LOKAD_ID = b"AGR0"
|
|
76
76
|
SLP_INT_SIZE = 8
|
|
@@ -389,6 +389,7 @@ class AgoraPartial:
|
|
|
389
389
|
token_type: int
|
|
390
390
|
token_protocol: str
|
|
391
391
|
script_len: int
|
|
392
|
+
enforced_locktime: int
|
|
392
393
|
dust_amount: int
|
|
393
394
|
|
|
394
395
|
@classmethod
|
|
@@ -424,6 +425,7 @@ class AgoraPartial:
|
|
|
424
425
|
pushdata.extend(self.token_scale_factor.to_bytes(8, "little"))
|
|
425
426
|
pushdata.extend(self.scaled_trunc_tokens_per_trunc_sat.to_bytes(8, "little"))
|
|
426
427
|
pushdata.extend(self.min_accepted_scaled_trunc_tokens.to_bytes(8, "little"))
|
|
428
|
+
pushdata.extend(self.enforced_locktime.to_bytes(4, "little"))
|
|
427
429
|
pushdata.extend(self.maker_pk)
|
|
428
430
|
return bytes(pushdata)
|
|
429
431
|
|
|
@@ -435,6 +437,7 @@ class AgoraPartial:
|
|
|
435
437
|
self.token_scale_factor.to_bytes(8, "little"),
|
|
436
438
|
self.scaled_trunc_tokens_per_trunc_sat.to_bytes(8, "little"),
|
|
437
439
|
self.min_accepted_scaled_trunc_tokens.to_bytes(8, "little"),
|
|
440
|
+
self.enforced_locktime.to_bytes(4, "little"),
|
|
438
441
|
]
|
|
439
442
|
|
|
440
443
|
def script(self) -> CScript:
|
|
@@ -547,7 +550,11 @@ class AgoraPartial:
|
|
|
547
550
|
OP_NIP,
|
|
548
551
|
32,
|
|
549
552
|
OP_SPLIT,
|
|
553
|
+
4,
|
|
554
|
+
OP_SPLIT,
|
|
550
555
|
OP_DROP,
|
|
556
|
+
self.enforced_locktime.to_bytes(4, "little"),
|
|
557
|
+
OP_EQUALVERIFY,
|
|
551
558
|
OP_TOALTSTACK,
|
|
552
559
|
OP_CAT,
|
|
553
560
|
OP_HASH160,
|
|
@@ -715,10 +722,10 @@ def parse_partial(pushdata: bytes, token) -> Optional[AgoraPartial]:
|
|
|
715
722
|
data_reader = BytesIO(pushdata)
|
|
716
723
|
# AGR0 PARTIAL pushdata always has the same length
|
|
717
724
|
if token.token_protocol == "SLP":
|
|
718
|
-
if len(pushdata) !=
|
|
725
|
+
if len(pushdata) != 63:
|
|
719
726
|
return None
|
|
720
727
|
elif token.token_protocol == "ALP":
|
|
721
|
-
if len(pushdata) !=
|
|
728
|
+
if len(pushdata) != 75:
|
|
722
729
|
return None
|
|
723
730
|
if data_reader.read(4) != b"AGR0":
|
|
724
731
|
return None
|
|
@@ -731,6 +738,7 @@ def parse_partial(pushdata: bytes, token) -> Optional[AgoraPartial]:
|
|
|
731
738
|
token_scale_factor = int.from_bytes(data_reader.read(8), "little")
|
|
732
739
|
scaled_trunc_tokens_per_trunc_sat = int.from_bytes(data_reader.read(8), "little")
|
|
733
740
|
min_accepted_scaled_trunc_tokens = int.from_bytes(data_reader.read(8), "little")
|
|
741
|
+
enforced_locktime = int.from_bytes(data_reader.read(4), "little")
|
|
734
742
|
maker_pk = data_reader.read(33)
|
|
735
743
|
|
|
736
744
|
token_trunc_factor = 1 << (8 * num_token_trunc_bytes)
|
|
@@ -751,6 +759,7 @@ def parse_partial(pushdata: bytes, token) -> Optional[AgoraPartial]:
|
|
|
751
759
|
token_type=token.token_type,
|
|
752
760
|
token_protocol=token.token_protocol,
|
|
753
761
|
script_len=0x7F,
|
|
762
|
+
enforced_locktime=enforced_locktime,
|
|
754
763
|
dust_amount=546,
|
|
755
764
|
)
|
|
756
765
|
measured_len = len(cut_out_codesep(partial_alp.script()))
|
package/dist/ad.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
// Copyright (c) 2024 The Bitcoin developers
|
|
2
3
|
// Distributed under the MIT software license, see the accompanying
|
|
3
4
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.parseAgoraTx = void 0;
|
|
7
|
+
const ecash_lib_1 = require("ecash-lib");
|
|
8
|
+
const consts_js_1 = require("./consts.js");
|
|
9
|
+
const oneshot_js_1 = require("./oneshot.js");
|
|
10
|
+
function parseAgoraTx(tx) {
|
|
8
11
|
if (tx.inputs.length === 0) {
|
|
9
12
|
return undefined;
|
|
10
13
|
}
|
|
@@ -23,13 +26,13 @@ export function parseAgoraTx(tx) {
|
|
|
23
26
|
let opreturnScript;
|
|
24
27
|
switch (tokenEntry.tokenType.protocol) {
|
|
25
28
|
case 'SLP':
|
|
26
|
-
opreturnScript = slpSend(tokenEntry.tokenId, tokenEntry.tokenType.number, [0, BigInt(offerOutput.token.amount)]);
|
|
29
|
+
opreturnScript = (0, ecash_lib_1.slpSend)(tokenEntry.tokenId, tokenEntry.tokenType.number, [0, BigInt(offerOutput.token.amount)]);
|
|
27
30
|
break;
|
|
28
31
|
case 'ALP':
|
|
29
32
|
// ALP not implemented yet
|
|
30
33
|
return undefined;
|
|
31
34
|
}
|
|
32
|
-
const scriptSig = new Script(fromHex(adInput.inputScript));
|
|
35
|
+
const scriptSig = new ecash_lib_1.Script((0, ecash_lib_1.fromHex)(adInput.inputScript));
|
|
33
36
|
const parsedAd = parseAdScriptSig(scriptSig);
|
|
34
37
|
if (parsedAd === undefined) {
|
|
35
38
|
return undefined;
|
|
@@ -38,10 +41,10 @@ export function parseAgoraTx(tx) {
|
|
|
38
41
|
let expectedAgoraScript;
|
|
39
42
|
let expectedAgoraP2sh;
|
|
40
43
|
switch (parsedAd.covenantVariant) {
|
|
41
|
-
case AgoraOneshot.COVENANT_VARIANT: {
|
|
44
|
+
case oneshot_js_1.AgoraOneshot.COVENANT_VARIANT: {
|
|
42
45
|
let agoraOneshot;
|
|
43
46
|
try {
|
|
44
|
-
agoraOneshot = AgoraOneshot.fromRedeemScript(parsedAd.redeemScript, opreturnScript);
|
|
47
|
+
agoraOneshot = oneshot_js_1.AgoraOneshot.fromRedeemScript(parsedAd.redeemScript, opreturnScript);
|
|
45
48
|
}
|
|
46
49
|
catch (ex) {
|
|
47
50
|
return undefined;
|
|
@@ -51,13 +54,13 @@ export function parseAgoraTx(tx) {
|
|
|
51
54
|
params: agoraOneshot,
|
|
52
55
|
};
|
|
53
56
|
expectedAgoraScript = agoraOneshot.script();
|
|
54
|
-
expectedAgoraP2sh = Script.p2sh(shaRmd160(expectedAgoraScript.bytecode));
|
|
57
|
+
expectedAgoraP2sh = ecash_lib_1.Script.p2sh((0, ecash_lib_1.shaRmd160)(expectedAgoraScript.bytecode));
|
|
55
58
|
break;
|
|
56
59
|
}
|
|
57
60
|
default:
|
|
58
61
|
return undefined;
|
|
59
62
|
}
|
|
60
|
-
if (offerOutput.outputScript !== toHex(expectedAgoraP2sh.bytecode)) {
|
|
63
|
+
if (offerOutput.outputScript !== (0, ecash_lib_1.toHex)(expectedAgoraP2sh.bytecode)) {
|
|
61
64
|
return undefined;
|
|
62
65
|
}
|
|
63
66
|
const outpoint = {
|
|
@@ -77,6 +80,7 @@ export function parseAgoraTx(tx) {
|
|
|
77
80
|
spentBy: offerOutput.spentBy,
|
|
78
81
|
};
|
|
79
82
|
}
|
|
83
|
+
exports.parseAgoraTx = parseAgoraTx;
|
|
80
84
|
/**
|
|
81
85
|
* How many pushops we expect at least for an advertisement.
|
|
82
86
|
* There has to be at least a LOKAD ID, a covenant variant and a redeemScript.
|
|
@@ -87,7 +91,7 @@ function parseAdScriptSig(scriptSig) {
|
|
|
87
91
|
const pushdata = [];
|
|
88
92
|
let op;
|
|
89
93
|
while ((op = ops.next())) {
|
|
90
|
-
if (!isPushOp(op)) {
|
|
94
|
+
if (!(0, ecash_lib_1.isPushOp)(op)) {
|
|
91
95
|
return undefined;
|
|
92
96
|
}
|
|
93
97
|
pushdata.push(op.data);
|
|
@@ -96,12 +100,12 @@ function parseAdScriptSig(scriptSig) {
|
|
|
96
100
|
return undefined;
|
|
97
101
|
}
|
|
98
102
|
const lokadId = pushdata[0];
|
|
99
|
-
if (bytesToStr(lokadId) != AGORA_LOKAD_ID_STR) {
|
|
103
|
+
if ((0, ecash_lib_1.bytesToStr)(lokadId) != consts_js_1.AGORA_LOKAD_ID_STR) {
|
|
100
104
|
return undefined;
|
|
101
105
|
}
|
|
102
|
-
const covenantVariant = bytesToStr(pushdata[1]);
|
|
106
|
+
const covenantVariant = (0, ecash_lib_1.bytesToStr)(pushdata[1]);
|
|
103
107
|
const parsedPushdata = pushdata.slice(2, -1);
|
|
104
|
-
const redeemScript = new Script(pushdata[pushdata.length - 1]);
|
|
108
|
+
const redeemScript = new ecash_lib_1.Script(pushdata[pushdata.length - 1]);
|
|
105
109
|
return {
|
|
106
110
|
covenantVariant,
|
|
107
111
|
pushdata: parsedPushdata,
|
package/dist/ad.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ad.js","sourceRoot":"","sources":["../src/ad.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,mEAAmE;AACnE,sEAAsE
|
|
1
|
+
{"version":3,"file":"ad.js","sourceRoot":"","sources":["../src/ad.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,mEAAmE;AACnE,sEAAsE;;;AAGtE,yCAWmB;AACnB,2CAAiD;AACjD,6CAA4C;AAa5C,SAAgB,YAAY,CAAC,EAAc;IACvC,IAAI,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,SAAS,CAAC;IACrB,CAAC;IACD,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC;IACrB,CAAC;IACD,IAAI,EAAE,CAAC,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/B,OAAO,SAAS,CAAC;IACrB,CAAC;IACD,MAAM,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC7B,MAAM,WAAW,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAClC,IAAI,WAAW,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QAClC,OAAO,SAAS,CAAC;IACrB,CAAC;IACD,MAAM,UAAU,GAAG,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IACtC,IAAI,cAAsB,CAAC;IAC3B,QAAQ,UAAU,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;QACpC,KAAK,KAAK;YACN,cAAc,GAAG,IAAA,mBAAO,EACpB,UAAU,CAAC,OAAO,EAClB,UAAU,CAAC,SAAS,CAAC,MAAM,EAC3B,CAAC,CAA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QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IAC/D,OAAO;QACH,eAAe;QACf,QAAQ,EAAE,cAAc;QACxB,YAAY;KACf,CAAC;AACN,CAAC"}
|
package/dist/agora.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ChronikClient, Token } from 'chronik-client';
|
|
2
|
-
import { Ecc, OutPoint, Script, Tx, TxBuilderInput, TxInput } from 'ecash-lib';
|
|
1
|
+
import { ChronikClient, Token, WsEndpoint } from 'chronik-client';
|
|
2
|
+
import { Ecc, Op, OutPoint, Script, Tx, TxBuilderInput, TxInput } from 'ecash-lib';
|
|
3
3
|
import { AgoraOneshot } from './oneshot.js';
|
|
4
|
-
import { AgoraPartial } from './partial.js';
|
|
4
|
+
import { AgoraPartial, AgoraPartialParams } from './partial.js';
|
|
5
5
|
/** Offer variant, determines the Script used to enforce the offer */
|
|
6
6
|
export type AgoraOfferVariant = {
|
|
7
7
|
type: 'ONESHOT';
|
|
@@ -10,6 +10,8 @@ export type AgoraOfferVariant = {
|
|
|
10
10
|
type: 'PARTIAL';
|
|
11
11
|
params: AgoraPartial;
|
|
12
12
|
};
|
|
13
|
+
/** Status of the offer, i.e. if it open/taken/canceled */
|
|
14
|
+
export type AgoraOfferStatus = 'OPEN' | 'TAKEN' | 'CANCELED';
|
|
13
15
|
/**
|
|
14
16
|
* Individual token offer on the Agora, i.e. one UTXO offering tokens.
|
|
15
17
|
*
|
|
@@ -20,11 +22,13 @@ export declare class AgoraOffer {
|
|
|
20
22
|
outpoint: OutPoint;
|
|
21
23
|
txBuilderInput: TxInput;
|
|
22
24
|
token: Token;
|
|
25
|
+
status: AgoraOfferStatus;
|
|
23
26
|
constructor(params: {
|
|
24
27
|
variant: AgoraOfferVariant;
|
|
25
28
|
outpoint: OutPoint;
|
|
26
29
|
txBuilderInput: TxInput;
|
|
27
30
|
token: Token;
|
|
31
|
+
status: AgoraOfferStatus;
|
|
28
32
|
});
|
|
29
33
|
/**
|
|
30
34
|
* Build a tx accepting this offer.
|
|
@@ -64,6 +68,8 @@ export declare class AgoraOffer {
|
|
|
64
68
|
dustAmount?: number;
|
|
65
69
|
/** Fee per kB to use when building the tx. */
|
|
66
70
|
feePerKb?: number;
|
|
71
|
+
/** Allow accepting an offer such that the remaining quantity is unacceptable */
|
|
72
|
+
allowUnspendable?: boolean;
|
|
67
73
|
}): Tx;
|
|
68
74
|
/**
|
|
69
75
|
* How many extra satoshis are required to fuel this offer so it can be
|
|
@@ -137,6 +143,30 @@ export declare class AgoraOffer {
|
|
|
137
143
|
**/
|
|
138
144
|
askedSats(acceptedTokens?: bigint): bigint;
|
|
139
145
|
}
|
|
146
|
+
/** Which txs to query (confirmed, unconfirmed, reverse history) */
|
|
147
|
+
export type TxHistoryTable = 'CONFIRMED' | 'UNCONFIRMED' | 'HISTORY';
|
|
148
|
+
export type AgoraQueryParamVariants = {
|
|
149
|
+
type: 'TOKEN_ID';
|
|
150
|
+
tokenId: string;
|
|
151
|
+
} | {
|
|
152
|
+
type: 'GROUP_TOKEN_ID';
|
|
153
|
+
groupTokenId: string;
|
|
154
|
+
} | {
|
|
155
|
+
type: 'PUBKEY';
|
|
156
|
+
pubkeyHex: string;
|
|
157
|
+
};
|
|
158
|
+
/** Params which Agora txs to query */
|
|
159
|
+
export type AgoraHistoryParams = AgoraQueryParamVariants & {
|
|
160
|
+
table: TxHistoryTable;
|
|
161
|
+
page?: number;
|
|
162
|
+
pageSize?: number;
|
|
163
|
+
};
|
|
164
|
+
/** Queried offers from the history */
|
|
165
|
+
export interface AgoraHistoryResult {
|
|
166
|
+
offers: AgoraOffer[];
|
|
167
|
+
numTxs: number;
|
|
168
|
+
numPages: number;
|
|
169
|
+
}
|
|
140
170
|
/**
|
|
141
171
|
* Enables access to Agora, via Chronik instances that have the "agora" plugin
|
|
142
172
|
* loaded.
|
|
@@ -144,6 +174,7 @@ export declare class AgoraOffer {
|
|
|
144
174
|
* See agora.py.
|
|
145
175
|
**/
|
|
146
176
|
export declare class Agora {
|
|
177
|
+
private chronik;
|
|
147
178
|
private plugin;
|
|
148
179
|
private dustAmount;
|
|
149
180
|
/**
|
|
@@ -169,10 +200,31 @@ export declare class Agora {
|
|
|
169
200
|
activeOffersByGroupTokenId(groupTokenId: string): Promise<AgoraOffer[]>;
|
|
170
201
|
/** Query all active offers with the given cancel pubkey. */
|
|
171
202
|
activeOffersByPubKey(pubkeyHex: string): Promise<AgoraOffer[]>;
|
|
203
|
+
/**
|
|
204
|
+
* Query historic offers (paginated)
|
|
205
|
+
*
|
|
206
|
+
* These are basically the "candlesticks" of a specific token (and also the
|
|
207
|
+
* cancelled offers, but those would have to be ignored).
|
|
208
|
+
* Offers can also be queried by pubkey, giving a history of user's offers.
|
|
209
|
+
**/
|
|
210
|
+
historicOffers(params: AgoraHistoryParams): Promise<AgoraHistoryResult>;
|
|
211
|
+
/** Subscribe to updates from the websocket for some params */
|
|
212
|
+
subscribeWs(ws: WsEndpoint, params: AgoraQueryParamVariants): void;
|
|
213
|
+
/** Unsubscribe from updates from the websocket for some params */
|
|
214
|
+
unsubscribeWs(ws: WsEndpoint, params: AgoraQueryParamVariants): void;
|
|
215
|
+
/**
|
|
216
|
+
* Build a safe AgoraPartial for the given parameters.
|
|
217
|
+
*
|
|
218
|
+
* This looks at the blockchain to avoid creating an identical offer, by
|
|
219
|
+
* tweaking the enforcedLockTime.
|
|
220
|
+
*/
|
|
221
|
+
selectParams(params: Omit<AgoraPartialParams, 'enforcedLockTime'> | AgoraPartial): Promise<AgoraPartial>;
|
|
222
|
+
private _groupHex;
|
|
172
223
|
private _allTokenIdsByPrefix;
|
|
173
224
|
private _activeOffersByGroup;
|
|
174
225
|
private _parseOfferUtxo;
|
|
175
226
|
private _parseOneshotOfferUtxo;
|
|
176
227
|
private _parsePartialOfferUtxo;
|
|
177
228
|
}
|
|
229
|
+
export declare function scriptOps(script: Script): Op[];
|
|
178
230
|
//# sourceMappingURL=agora.d.ts.map
|
package/dist/agora.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agora.d.ts","sourceRoot":"","sources":["../src/agora.ts"],"names":[],"mappings":"AAIA,OAAO,EACH,aAAa,EAGb,KAAK,
|
|
1
|
+
{"version":3,"file":"agora.d.ts","sourceRoot":"","sources":["../src/agora.ts"],"names":[],"mappings":"AAIA,OAAO,EACH,aAAa,EAGb,KAAK,EAGL,UAAU,EACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAMH,GAAG,EAIH,EAAE,EAEF,QAAQ,EAER,MAAM,EAMN,EAAE,EAEF,cAAc,EAEd,OAAO,EAEV,MAAM,WAAW,CAAC;AAEnB,OAAO,EACH,YAAY,EAGf,MAAM,cAAc,CAAC;AACtB,OAAO,EACH,YAAY,EAEZ,kBAAkB,EAErB,MAAM,cAAc,CAAC;AAatB,qEAAqE;AACrE,MAAM,MAAM,iBAAiB,GACvB;IACI,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,YAAY,CAAC;CACxB,GACD;IACI,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,YAAY,CAAC;CACxB,CAAC;AAER,0DAA0D;AAC1D,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,CAAC;AAE7D;;;;GAIG;AACH,qBAAa,UAAU;IACZ,OAAO,EAAE,iBAAiB,CAAC;IAC3B,QAAQ,EAAE,QAAQ,CAAC;IACnB,cAAc,EAAE,OAAO,CAAC;IACxB,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,EAAE,gBAAgB,CAAC;gBAEb,MAAM,EAAE;QACvB,OAAO,EAAE,iBAAiB,CAAC;QAC3B,QAAQ,EAAE,QAAQ,CAAC;QACnB,cAAc,EAAE,OAAO,CAAC;QACxB,KAAK,EAAE,KAAK,CAAC;QACb,MAAM,EAAE,gBAAgB,CAAC;KAC5B;IAQD;;;;;;;SAOK;IACE,QAAQ,CAAC,MAAM,EAAE;Q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