ecash-agora 1.0.1 → 2.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/README.md +13 -8
- package/agora.py +3 -3
- package/dist/ad.js +2 -2
- package/dist/ad.js.map +1 -1
- package/dist/agora.d.ts +16 -18
- package/dist/agora.d.ts.map +1 -1
- package/dist/agora.js +68 -69
- package/dist/agora.js.map +1 -1
- package/dist/inputs.d.ts +4 -4
- package/dist/inputs.d.ts.map +1 -1
- package/dist/inputs.js +11 -11
- package/dist/inputs.js.map +1 -1
- package/dist/oneshot.js +2 -2
- package/dist/oneshot.js.map +1 -1
- package/dist/partial.d.ts +49 -49
- package/dist/partial.d.ts.map +1 -1
- package/dist/partial.js +206 -208
- package/dist/partial.js.map +1 -1
- package/package.json +3 -3
- package/tests/oneshot.test.ts +46 -46
- package/tests/partial-helper-alp.ts +12 -14
- package/tests/partial-helper-slp.ts +14 -14
- package/tests/partial.alp.bigsats.test.ts +144 -151
- package/tests/partial.alp.test.ts +252 -259
- package/tests/partial.locktime.test.ts +27 -27
- package/tests/partial.slp.bigsats.test.ts +150 -158
- package/tests/partial.slp.test.ts +282 -290
package/README.md
CHANGED
|
@@ -55,8 +55,8 @@ You can create a "one shot" offer (one that offers all or nothing) using `AgoraO
|
|
|
55
55
|
|
|
56
56
|
```ts
|
|
57
57
|
const enforcedOutputs: TxOutput[] = [
|
|
58
|
-
{
|
|
59
|
-
{
|
|
58
|
+
{ sats: 0n, script: slpSend(tokenId, SLP_NFT1_CHILD, [0n, 1n]) },
|
|
59
|
+
{ sats: 80000n, script: sellerP2pkh },
|
|
60
60
|
];
|
|
61
61
|
const agoraOneshot = new AgoraOneshot({
|
|
62
62
|
enforcedOutputs,
|
|
@@ -79,7 +79,7 @@ const txBuilder = new TxBuilder({
|
|
|
79
79
|
outIdx: 1,
|
|
80
80
|
},
|
|
81
81
|
signData: {
|
|
82
|
-
|
|
82
|
+
sats: 546n,
|
|
83
83
|
redeemScript: agoraScript,
|
|
84
84
|
},
|
|
85
85
|
},
|
|
@@ -96,7 +96,7 @@ const txBuilder = new TxBuilder({
|
|
|
96
96
|
outIdx: 0,
|
|
97
97
|
},
|
|
98
98
|
signData: {
|
|
99
|
-
|
|
99
|
+
sats: 90000n,
|
|
100
100
|
outputScript: buyerP2pkh,
|
|
101
101
|
},
|
|
102
102
|
},
|
|
@@ -105,11 +105,11 @@ const txBuilder = new TxBuilder({
|
|
|
105
105
|
],
|
|
106
106
|
outputs: [
|
|
107
107
|
{
|
|
108
|
-
|
|
109
|
-
script: slpSend(tokenId, SLP_NFT1_CHILD, [
|
|
108
|
+
sats: 0n,
|
|
109
|
+
script: slpSend(tokenId, SLP_NFT1_CHILD, [0n, 1n]),
|
|
110
110
|
},
|
|
111
|
-
{
|
|
112
|
-
{
|
|
111
|
+
{ sats: 80000n, script: sellerP2pkh },
|
|
112
|
+
{ sats: 546n, script: buyerP2pkh },
|
|
113
113
|
],
|
|
114
114
|
});
|
|
115
115
|
const acceptTx = txBuilder.sign();
|
|
@@ -186,3 +186,8 @@ Running from `bitcoin-abc/modules/ecash-agora` if your build dir is `bitcoin-abc
|
|
|
186
186
|
### 1.0.1
|
|
187
187
|
|
|
188
188
|
- Do not validate for unspendable offer creation when we calculate fee in `acceptFeeSats()` [D17648](https://reviews.bitcoinabc.org/D17648)
|
|
189
|
+
|
|
190
|
+
### 2.0.0
|
|
191
|
+
|
|
192
|
+
- Improve types and shapes in line with chronik proto updates [D17650](https://reviews.bitcoinabc.org/D17650)
|
|
193
|
+
- Introduce 'atoms' as term for base unit of tokens. Implement in lib. The term "token" is ambiguous as it is not clear that we are talking about base tokens.
|
package/agora.py
CHANGED
|
@@ -321,7 +321,7 @@ class AgoraOneshot:
|
|
|
321
321
|
op_return_script = slp_send(
|
|
322
322
|
token_type=self.token.token_type,
|
|
323
323
|
token_id=self.token.token_id,
|
|
324
|
-
amounts=[0, self.token.
|
|
324
|
+
amounts=[0, self.token.atoms],
|
|
325
325
|
)
|
|
326
326
|
return (
|
|
327
327
|
bytes(8)
|
|
@@ -744,11 +744,11 @@ def parse_partial(pushdata: bytes, token) -> Optional[AgoraPartial]:
|
|
|
744
744
|
token_trunc_factor = 1 << (8 * num_token_trunc_bytes)
|
|
745
745
|
|
|
746
746
|
# Offers must have a losslessly truncatable token amount
|
|
747
|
-
if token.
|
|
747
|
+
if token.atoms % token_trunc_factor != 0:
|
|
748
748
|
return None
|
|
749
749
|
|
|
750
750
|
partial_alp = AgoraPartial(
|
|
751
|
-
trunc_tokens=token.
|
|
751
|
+
trunc_tokens=token.atoms // token_trunc_factor,
|
|
752
752
|
num_token_trunc_bytes=num_token_trunc_bytes,
|
|
753
753
|
token_scale_factor=token_scale_factor,
|
|
754
754
|
scaled_trunc_tokens_per_trunc_sat=scaled_trunc_tokens_per_trunc_sat,
|
package/dist/ad.js
CHANGED
|
@@ -26,7 +26,7 @@ function parseAgoraTx(tx) {
|
|
|
26
26
|
let opreturnScript;
|
|
27
27
|
switch (tokenEntry.tokenType.protocol) {
|
|
28
28
|
case 'SLP':
|
|
29
|
-
opreturnScript = (0, ecash_lib_1.slpSend)(tokenEntry.tokenId, tokenEntry.tokenType.number, [
|
|
29
|
+
opreturnScript = (0, ecash_lib_1.slpSend)(tokenEntry.tokenId, tokenEntry.tokenType.number, [0n, offerOutput.token.atoms]);
|
|
30
30
|
break;
|
|
31
31
|
case 'ALP':
|
|
32
32
|
// ALP not implemented yet
|
|
@@ -73,7 +73,7 @@ function parseAgoraTx(tx) {
|
|
|
73
73
|
txBuilderInput: {
|
|
74
74
|
prevOut: outpoint,
|
|
75
75
|
signData: {
|
|
76
|
-
|
|
76
|
+
sats: offerOutput.sats,
|
|
77
77
|
redeemScript: expectedAgoraScript,
|
|
78
78
|
},
|
|
79
79
|
},
|
package/dist/ad.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ad.js","sourceRoot":"","sources":["../src/ad.ts"],"names":[],"mappings":";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,IAAI,EAAE,CAAC,EAAE,CAAC;QACvB,IAAI,CAAC,IAAA,oBAAQ,EAAC,EAAE,CAAC,EAAE,CAAC;YAChB,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IACD,IAAI,QAAQ,CAAC,MAAM,GAAG,yBAAyB,EAAE,CAAC;QAC9C,OAAO,SAAS,CAAC;IACrB,CAAC;IACD,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC5B,IAAI,IAAA,sBAAU,EAAC,OAAO,CAAC,IAAI,8BAAkB,EAAE,CAAC;QAC5C,OAAO,SAAS,CAAC;IACrB,CAAC;IACD,MAAM,eAAe,GAAG,IAAA,sBAAU,EAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IAChD,MAAM,cAAc,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC7C,MAAM,YAAY,GAAG,IAAI,kBAAM,CAAC,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
|
@@ -15,13 +15,11 @@ export type AgoraOfferStatus = 'OPEN' | 'TAKEN' | 'CANCELED';
|
|
|
15
15
|
/** If an offer is TAKEN */
|
|
16
16
|
export interface TakenInfo {
|
|
17
17
|
/** satoshis paid in taking an offer */
|
|
18
|
-
|
|
18
|
+
sats: bigint;
|
|
19
19
|
/**
|
|
20
|
-
* amount of token purchased in base tokens
|
|
21
|
-
* (aka token satoshis, the token qty without
|
|
22
|
-
* decimals applied)
|
|
20
|
+
* amount of token purchased in atoms aka base tokens
|
|
23
21
|
*/
|
|
24
|
-
|
|
22
|
+
atoms: bigint;
|
|
25
23
|
/** taker outputScript as a hex string*/
|
|
26
24
|
takerScriptHex: string;
|
|
27
25
|
}
|
|
@@ -75,13 +73,13 @@ export declare class AgoraOffer {
|
|
|
75
73
|
fuelInputs: TxBuilderInput[];
|
|
76
74
|
/** Script to send the tokens and the leftover sats (if any) to. */
|
|
77
75
|
recipientScript: Script;
|
|
78
|
-
/** For partial offers: Number of accepted tokens */
|
|
79
|
-
|
|
76
|
+
/** For partial offers: Number of accepted atoms (base tokens) */
|
|
77
|
+
acceptedAtoms?: bigint;
|
|
80
78
|
/** Dust amount to use for the token output. */
|
|
81
|
-
|
|
79
|
+
dustSats?: bigint;
|
|
82
80
|
/** Fee per kB to use when building the tx. */
|
|
83
|
-
feePerKb?:
|
|
84
|
-
/**
|
|
81
|
+
feePerKb?: bigint;
|
|
82
|
+
/** Allow accepting an offer such that the remaining quantity is unacceptable */
|
|
85
83
|
allowUnspendable?: boolean;
|
|
86
84
|
}): Tx;
|
|
87
85
|
/**
|
|
@@ -96,8 +94,8 @@ export declare class AgoraOffer {
|
|
|
96
94
|
/** Extra inputs */
|
|
97
95
|
extraInputs?: TxBuilderInput[];
|
|
98
96
|
/** Fee per kB to use when building the tx. */
|
|
99
|
-
feePerKb?:
|
|
100
|
-
|
|
97
|
+
feePerKb?: bigint;
|
|
98
|
+
acceptedAtoms?: bigint;
|
|
101
99
|
}): bigint;
|
|
102
100
|
private _acceptTxBuilder;
|
|
103
101
|
/**
|
|
@@ -124,9 +122,9 @@ export declare class AgoraOffer {
|
|
|
124
122
|
/** Script to send canceled tokens and the leftover sats (if any) to. */
|
|
125
123
|
recipientScript: Script;
|
|
126
124
|
/** Dust amount to use for the token output. */
|
|
127
|
-
|
|
125
|
+
dustSats?: bigint;
|
|
128
126
|
/** Fee per kB to use when building the tx. */
|
|
129
|
-
feePerKb?:
|
|
127
|
+
feePerKb?: bigint;
|
|
130
128
|
}): Tx;
|
|
131
129
|
/**
|
|
132
130
|
* How many extra satoshis are required to fuel cancelling this offer,
|
|
@@ -145,14 +143,14 @@ export declare class AgoraOffer {
|
|
|
145
143
|
/** Extra inputs */
|
|
146
144
|
extraInputs?: TxBuilderInput[];
|
|
147
145
|
/** Fee per kB to use when building the tx. */
|
|
148
|
-
feePerKb?:
|
|
146
|
+
feePerKb?: bigint;
|
|
149
147
|
}): bigint;
|
|
150
148
|
private _cancelTxBuilder;
|
|
151
149
|
/**
|
|
152
150
|
* How many satoshis are asked to accept this offer, excluding tx fees.
|
|
153
151
|
* This is what should be displayed to the user as the price.
|
|
154
152
|
**/
|
|
155
|
-
askedSats(
|
|
153
|
+
askedSats(acceptedAtoms?: bigint): bigint;
|
|
156
154
|
}
|
|
157
155
|
/** Which txs to query (confirmed, unconfirmed, reverse history) */
|
|
158
156
|
export type TxHistoryTable = 'CONFIRMED' | 'UNCONFIRMED' | 'HISTORY';
|
|
@@ -187,12 +185,12 @@ export interface AgoraHistoryResult {
|
|
|
187
185
|
export declare class Agora {
|
|
188
186
|
private chronik;
|
|
189
187
|
private plugin;
|
|
190
|
-
private
|
|
188
|
+
private dustSats;
|
|
191
189
|
/**
|
|
192
190
|
* Create an Agora instance. The provided Chronik instance must have the
|
|
193
191
|
* "agora" plugin loaded.
|
|
194
192
|
**/
|
|
195
|
-
constructor(chronik: ChronikClient,
|
|
193
|
+
constructor(chronik: ChronikClient, dustSats?: bigint);
|
|
196
194
|
/**
|
|
197
195
|
* Query all the token IDs, fungible and non-fungible ones, that have active
|
|
198
196
|
* Agora offers.
|
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,EAGL,UAAU,EACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,
|
|
1
|
+
{"version":3,"file":"agora.d.ts","sourceRoot":"","sources":["../src/agora.ts"],"names":[],"mappings":"AAIA,OAAO,EACH,aAAa,EAGb,KAAK,EAGL,UAAU,EAC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0B,CACnC,YAAY,EAAE,MAAM,GACrB,OAAO,CAAC,UAAU,EAAE,CAAC;IAMxB,4DAA4D;IAC/C,oBAAoB,CAC7B,SAAS,EAAE,MAAM,GAClB,OAAO,CAAC,UAAU,EAAE,CAAC;IAIxB;;;;;;QAMI;IACS,cAAc,CACvB,MAAM,EAAE,kBAAkB,GAC3B,OAAO,CAAC,kBAAkB,CAAC;IAyI9B,8DAA8D;IACvD,WAAW,CAAC,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,uBAAuB;IAKlE,kEAAkE;IAC3D,aAAa,CAAC,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,uBAAuB;IAKpE;;;;;OAKG;IACU,YAAY,CACrB,MAAM,EAAE,IAAI,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,GAAG,YAAY,GACpE,OAAO,CAAC,YAAY,CAAC;IAkCxB,OAAO,CAAC,SAAS;YAaH,oBAAoB;YAmBpB,oBAAoB;IAUlC,OAAO,CAAC,eAAe;IAsBvB,OAAO,CAAC,sBAAsB;IAuD9B,OAAO,CAAC,sBAAsB;CAkFjC;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,EAAE,EAAE,CAQ9C"}
|
package/dist/agora.js
CHANGED
|
@@ -40,8 +40,8 @@ class AgoraOffer {
|
|
|
40
40
|
* `fuelInputs` has to provide enough sats for this offer to cover ask + tx fee.
|
|
41
41
|
* */
|
|
42
42
|
acceptTx(params) {
|
|
43
|
-
const
|
|
44
|
-
const feePerKb = params.feePerKb ?? ecash_lib_1.
|
|
43
|
+
const dustSats = params.dustSats ?? ecash_lib_1.DEFAULT_DUST_SATS;
|
|
44
|
+
const feePerKb = params.feePerKb ?? ecash_lib_1.DEFAULT_FEE_SATS_PER_KB;
|
|
45
45
|
const allowUnspendable = params.allowUnspendable ?? false;
|
|
46
46
|
const txBuild = this._acceptTxBuilder({
|
|
47
47
|
covenantSk: params.covenantSk,
|
|
@@ -49,15 +49,15 @@ class AgoraOffer {
|
|
|
49
49
|
fuelInputs: params.fuelInputs,
|
|
50
50
|
extraOutputs: [
|
|
51
51
|
{
|
|
52
|
-
|
|
52
|
+
sats: dustSats,
|
|
53
53
|
script: params.recipientScript,
|
|
54
54
|
},
|
|
55
55
|
params.recipientScript,
|
|
56
56
|
],
|
|
57
|
-
|
|
57
|
+
acceptedAtoms: params.acceptedAtoms,
|
|
58
58
|
allowUnspendable,
|
|
59
59
|
});
|
|
60
|
-
return txBuild.sign({ feePerKb,
|
|
60
|
+
return txBuild.sign({ feePerKb, dustSats });
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
63
|
* How many extra satoshis are required to fuel this offer so it can be
|
|
@@ -66,23 +66,23 @@ class AgoraOffer {
|
|
|
66
66
|
* The total required input amount is askedSats + acceptFeeSats.
|
|
67
67
|
**/
|
|
68
68
|
acceptFeeSats(params) {
|
|
69
|
-
const feePerKb = params.feePerKb ?? ecash_lib_1.
|
|
69
|
+
const feePerKb = params.feePerKb ?? ecash_lib_1.DEFAULT_FEE_SATS_PER_KB;
|
|
70
70
|
const txBuild = this._acceptTxBuilder({
|
|
71
71
|
covenantSk: new Uint8Array(32),
|
|
72
72
|
covenantPk: new Uint8Array(33),
|
|
73
73
|
fuelInputs: params.extraInputs ?? [],
|
|
74
74
|
extraOutputs: [
|
|
75
75
|
{
|
|
76
|
-
|
|
76
|
+
sats: 0n,
|
|
77
77
|
script: params.recipientScript,
|
|
78
78
|
},
|
|
79
79
|
],
|
|
80
|
-
|
|
80
|
+
acceptedAtoms: params.acceptedAtoms,
|
|
81
81
|
/** We do not need to validate for this condition when we get the fee */
|
|
82
82
|
allowUnspendable: true,
|
|
83
83
|
});
|
|
84
84
|
const measureTx = txBuild.sign({ ecc: new ecash_lib_1.EccDummy() });
|
|
85
|
-
return BigInt(Math.ceil((measureTx.serSize() * feePerKb) / 1000));
|
|
85
|
+
return BigInt(Math.ceil((measureTx.serSize() * Number(feePerKb)) / 1000));
|
|
86
86
|
}
|
|
87
87
|
_acceptTxBuilder(params) {
|
|
88
88
|
switch (this.variant.type) {
|
|
@@ -101,43 +101,43 @@ class AgoraOffer {
|
|
|
101
101
|
],
|
|
102
102
|
});
|
|
103
103
|
case 'PARTIAL': {
|
|
104
|
-
if (params.
|
|
105
|
-
throw new Error('Must set
|
|
104
|
+
if (params.acceptedAtoms === undefined) {
|
|
105
|
+
throw new Error('Must set acceptedAtoms for partial offers');
|
|
106
106
|
}
|
|
107
107
|
const txBuild = new ecash_lib_1.TxBuilder();
|
|
108
108
|
const agoraPartial = this.variant.params;
|
|
109
|
-
const truncFactor = 1n << BigInt(8 * agoraPartial.
|
|
110
|
-
if (params.
|
|
111
|
-
throw new Error(`Must
|
|
109
|
+
const truncFactor = 1n << BigInt(8 * agoraPartial.numAtomsTruncBytes);
|
|
110
|
+
if (params.acceptedAtoms % truncFactor != 0n) {
|
|
111
|
+
throw new Error(`Must acceptedAtoms must be a multiple of ${truncFactor}`);
|
|
112
112
|
}
|
|
113
113
|
if (params.allowUnspendable === false ||
|
|
114
114
|
typeof params.allowUnspendable === 'undefined') {
|
|
115
115
|
// Prevent creation of unacceptable offer
|
|
116
|
-
agoraPartial.preventUnacceptableRemainder(params.
|
|
116
|
+
agoraPartial.preventUnacceptableRemainder(params.acceptedAtoms);
|
|
117
117
|
}
|
|
118
118
|
txBuild.inputs.push({
|
|
119
119
|
input: this.txBuilderInput,
|
|
120
|
-
signatory: (0, partial_js_1.AgoraPartialSignatory)(agoraPartial, params.
|
|
120
|
+
signatory: (0, partial_js_1.AgoraPartialSignatory)(agoraPartial, params.acceptedAtoms / truncFactor, params.covenantSk, params.covenantPk),
|
|
121
121
|
});
|
|
122
122
|
txBuild.inputs.push(...params.fuelInputs);
|
|
123
|
-
const
|
|
124
|
-
const
|
|
125
|
-
if (
|
|
126
|
-
|
|
123
|
+
const sendAtomsArray = [0n];
|
|
124
|
+
const offeredAtoms = this.token.atoms;
|
|
125
|
+
if (offeredAtoms > params.acceptedAtoms) {
|
|
126
|
+
sendAtomsArray.push(offeredAtoms - params.acceptedAtoms);
|
|
127
127
|
}
|
|
128
|
-
|
|
128
|
+
sendAtomsArray.push(params.acceptedAtoms);
|
|
129
129
|
if (agoraPartial.tokenProtocol === 'SLP') {
|
|
130
130
|
txBuild.outputs.push({
|
|
131
|
-
|
|
132
|
-
script: (0, ecash_lib_1.slpSend)(this.token.tokenId, this.token.tokenType.number,
|
|
131
|
+
sats: 0n,
|
|
132
|
+
script: (0, ecash_lib_1.slpSend)(this.token.tokenId, this.token.tokenType.number, sendAtomsArray),
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
135
|
else if (agoraPartial.tokenProtocol === 'ALP') {
|
|
136
136
|
txBuild.outputs.push({
|
|
137
|
-
|
|
137
|
+
sats: 0n,
|
|
138
138
|
script: (0, ecash_lib_1.emppScript)([
|
|
139
139
|
agoraPartial.adPushdata(),
|
|
140
|
-
(0, ecash_lib_1.alpSend)(this.token.tokenId, this.token.tokenType.number,
|
|
140
|
+
(0, ecash_lib_1.alpSend)(this.token.tokenId, this.token.tokenType.number, sendAtomsArray),
|
|
141
141
|
]),
|
|
142
142
|
});
|
|
143
143
|
}
|
|
@@ -145,17 +145,16 @@ class AgoraOffer {
|
|
|
145
145
|
throw new Error('Not implemented');
|
|
146
146
|
}
|
|
147
147
|
txBuild.outputs.push({
|
|
148
|
-
|
|
148
|
+
sats: agoraPartial.askedSats(params.acceptedAtoms),
|
|
149
149
|
script: ecash_lib_1.Script.p2pkh((0, ecash_lib_1.shaRmd160)(agoraPartial.makerPk)),
|
|
150
150
|
});
|
|
151
|
-
if (
|
|
151
|
+
if (offeredAtoms > params.acceptedAtoms) {
|
|
152
152
|
const newAgoraPartial = new partial_js_1.AgoraPartial({
|
|
153
153
|
...agoraPartial,
|
|
154
|
-
|
|
155
|
-
truncFactor,
|
|
154
|
+
truncAtoms: (offeredAtoms - params.acceptedAtoms) / truncFactor,
|
|
156
155
|
});
|
|
157
156
|
txBuild.outputs.push({
|
|
158
|
-
|
|
157
|
+
sats: agoraPartial.dustSats,
|
|
159
158
|
script: ecash_lib_1.Script.p2sh((0, ecash_lib_1.shaRmd160)(newAgoraPartial.script().bytecode)),
|
|
160
159
|
});
|
|
161
160
|
}
|
|
@@ -175,20 +174,20 @@ class AgoraOffer {
|
|
|
175
174
|
* `fuelInputs` must cover the tx fee, you can calculate it with cancelFeeSats.
|
|
176
175
|
**/
|
|
177
176
|
cancelTx(params) {
|
|
178
|
-
const
|
|
179
|
-
const feePerKb = params.feePerKb ?? ecash_lib_1.
|
|
177
|
+
const dustSats = params.dustSats ?? ecash_lib_1.DEFAULT_DUST_SATS;
|
|
178
|
+
const feePerKb = params.feePerKb ?? ecash_lib_1.DEFAULT_FEE_SATS_PER_KB;
|
|
180
179
|
const txBuild = this._cancelTxBuilder({
|
|
181
180
|
cancelSk: params.cancelSk,
|
|
182
181
|
fuelInputs: params.fuelInputs,
|
|
183
182
|
extraOutputs: [
|
|
184
183
|
{
|
|
185
|
-
|
|
184
|
+
sats: dustSats,
|
|
186
185
|
script: params.recipientScript,
|
|
187
186
|
},
|
|
188
187
|
params.recipientScript,
|
|
189
188
|
],
|
|
190
189
|
});
|
|
191
|
-
return txBuild.sign({ feePerKb,
|
|
190
|
+
return txBuild.sign({ feePerKb, dustSats });
|
|
192
191
|
}
|
|
193
192
|
/**
|
|
194
193
|
* How many extra satoshis are required to fuel cancelling this offer,
|
|
@@ -202,19 +201,19 @@ class AgoraOffer {
|
|
|
202
201
|
* The total required sats input amount is returned by this function.
|
|
203
202
|
**/
|
|
204
203
|
cancelFeeSats(params) {
|
|
205
|
-
const feePerKb = params.feePerKb ?? ecash_lib_1.
|
|
204
|
+
const feePerKb = params.feePerKb ?? ecash_lib_1.DEFAULT_FEE_SATS_PER_KB;
|
|
206
205
|
const txBuild = this._cancelTxBuilder({
|
|
207
206
|
cancelSk: new Uint8Array(32),
|
|
208
207
|
fuelInputs: params.extraInputs ?? [],
|
|
209
208
|
extraOutputs: [
|
|
210
209
|
{
|
|
211
|
-
|
|
210
|
+
sats: 0n,
|
|
212
211
|
script: params.recipientScript,
|
|
213
212
|
},
|
|
214
213
|
],
|
|
215
214
|
});
|
|
216
215
|
const measureTx = txBuild.sign({ ecc: new ecash_lib_1.EccDummy() });
|
|
217
|
-
return BigInt(Math.ceil((measureTx.serSize() * feePerKb) / 1000));
|
|
216
|
+
return BigInt(Math.ceil((measureTx.serSize() * Number(feePerKb)) / 1000));
|
|
218
217
|
}
|
|
219
218
|
_cancelTxBuilder(params) {
|
|
220
219
|
let signatory;
|
|
@@ -235,15 +234,15 @@ class AgoraOffer {
|
|
|
235
234
|
switch (tokenProtocol) {
|
|
236
235
|
case 'SLP':
|
|
237
236
|
outputs.push({
|
|
238
|
-
|
|
239
|
-
script: (0, ecash_lib_1.slpSend)(this.token.tokenId, this.token.tokenType.number, [
|
|
237
|
+
sats: 0n,
|
|
238
|
+
script: (0, ecash_lib_1.slpSend)(this.token.tokenId, this.token.tokenType.number, [this.token.atoms]),
|
|
240
239
|
});
|
|
241
240
|
break;
|
|
242
241
|
case 'ALP':
|
|
243
242
|
outputs.push({
|
|
244
|
-
|
|
243
|
+
sats: 0n,
|
|
245
244
|
script: (0, ecash_lib_1.emppScript)([
|
|
246
|
-
(0, ecash_lib_1.alpSend)(this.token.tokenId, this.token.tokenType.number, [
|
|
245
|
+
(0, ecash_lib_1.alpSend)(this.token.tokenId, this.token.tokenType.number, [this.token.atoms]),
|
|
247
246
|
]),
|
|
248
247
|
});
|
|
249
248
|
break;
|
|
@@ -264,15 +263,15 @@ class AgoraOffer {
|
|
|
264
263
|
* How many satoshis are asked to accept this offer, excluding tx fees.
|
|
265
264
|
* This is what should be displayed to the user as the price.
|
|
266
265
|
**/
|
|
267
|
-
askedSats(
|
|
266
|
+
askedSats(acceptedAtoms) {
|
|
268
267
|
switch (this.variant.type) {
|
|
269
268
|
case 'ONESHOT':
|
|
270
269
|
return this.variant.params.askedSats();
|
|
271
270
|
case 'PARTIAL':
|
|
272
|
-
if (
|
|
273
|
-
throw new Error('Must provide
|
|
271
|
+
if (acceptedAtoms === undefined) {
|
|
272
|
+
throw new Error('Must provide acceptedAtoms for PARTIAL offers');
|
|
274
273
|
}
|
|
275
|
-
return this.variant.params.askedSats(
|
|
274
|
+
return this.variant.params.askedSats(acceptedAtoms);
|
|
276
275
|
default:
|
|
277
276
|
throw new Error('Not implemented');
|
|
278
277
|
}
|
|
@@ -290,10 +289,10 @@ class Agora {
|
|
|
290
289
|
* Create an Agora instance. The provided Chronik instance must have the
|
|
291
290
|
* "agora" plugin loaded.
|
|
292
291
|
**/
|
|
293
|
-
constructor(chronik,
|
|
292
|
+
constructor(chronik, dustSats) {
|
|
294
293
|
this.chronik = chronik;
|
|
295
294
|
this.plugin = chronik.plugin(PLUGIN_NAME);
|
|
296
|
-
this.
|
|
295
|
+
this.dustSats = dustSats ?? ecash_lib_1.DEFAULT_DUST_SATS;
|
|
297
296
|
}
|
|
298
297
|
/**
|
|
299
298
|
* Query all the token IDs, fungible and non-fungible ones, that have active
|
|
@@ -358,7 +357,7 @@ class Agora {
|
|
|
358
357
|
// isCanceled is always the last pushop (before redeemScript)
|
|
359
358
|
const opIsCanceled = ops[ops.length - 2];
|
|
360
359
|
const isCanceled = opIsCanceled === ecash_lib_1.OP_0;
|
|
361
|
-
// If isCanceled, then offer.token.
|
|
360
|
+
// If isCanceled, then offer.token.atoms is the canceled amount
|
|
362
361
|
let takenInfo;
|
|
363
362
|
if (!isCanceled) {
|
|
364
363
|
// If this tx is not canceling an agora offer
|
|
@@ -391,7 +390,7 @@ class Agora {
|
|
|
391
390
|
// Note we may see AgoraOffer change in the future and need to update this parsing
|
|
392
391
|
// The purchase price is satoshis that go to the offer creator
|
|
393
392
|
// Index 1 output
|
|
394
|
-
const
|
|
393
|
+
const sats = tx.outputs[1].sats;
|
|
395
394
|
// The taker receives the purchased tokens at a p2pkh address
|
|
396
395
|
// This is at index 2 for a buy of the full offer and index 3 for a partial buy
|
|
397
396
|
// If tx.outputs[2].outputScript is p2sh, that means partialbuy and takerBuyIndex is 3
|
|
@@ -399,14 +398,14 @@ class Agora {
|
|
|
399
398
|
? 2
|
|
400
399
|
: 3;
|
|
401
400
|
const takerScriptHex = tx.outputs[takerBuyIndex].outputScript;
|
|
402
|
-
const
|
|
403
|
-
if (typeof
|
|
401
|
+
const atoms = tx.outputs[takerBuyIndex].token?.atoms;
|
|
402
|
+
if (typeof atoms === 'bigint') {
|
|
404
403
|
// Should always be true but we may have different kinds of agora
|
|
405
404
|
// offers in the future
|
|
406
405
|
// So, we only set if we have the info we expect
|
|
407
406
|
takenInfo = {
|
|
408
|
-
|
|
409
|
-
|
|
407
|
+
sats,
|
|
408
|
+
atoms,
|
|
410
409
|
takerScriptHex,
|
|
411
410
|
};
|
|
412
411
|
}
|
|
@@ -416,7 +415,7 @@ class Agora {
|
|
|
416
415
|
outpoint: input.prevOut,
|
|
417
416
|
blockHeight: tx.block?.height ?? -1,
|
|
418
417
|
isCoinbase: tx.isCoinbase,
|
|
419
|
-
|
|
418
|
+
sats: input.sats,
|
|
420
419
|
script: input.outputScript,
|
|
421
420
|
isFinal: false,
|
|
422
421
|
plugins: input.plugins,
|
|
@@ -539,8 +538,8 @@ class Agora {
|
|
|
539
538
|
const outputsSerBytes = new ecash_lib_1.Bytes((0, ecash_lib_1.fromHex)(outputsSerHex));
|
|
540
539
|
const enforcedOutputs = [
|
|
541
540
|
{
|
|
542
|
-
|
|
543
|
-
script: (0, ecash_lib_1.slpSend)(utxo.token.tokenId, utxo.token.tokenType.number, [
|
|
541
|
+
sats: 0n,
|
|
542
|
+
script: (0, ecash_lib_1.slpSend)(utxo.token.tokenId, utxo.token.tokenType.number, [0n, utxo.token.atoms]),
|
|
544
543
|
},
|
|
545
544
|
];
|
|
546
545
|
while (outputsSerBytes.data.length > outputsSerBytes.idx) {
|
|
@@ -564,7 +563,7 @@ class Agora {
|
|
|
564
563
|
txBuilderInput: {
|
|
565
564
|
prevOut: utxo.outpoint,
|
|
566
565
|
signData: {
|
|
567
|
-
|
|
566
|
+
sats: utxo.sats,
|
|
568
567
|
redeemScript: agoraOneshot.script(),
|
|
569
568
|
},
|
|
570
569
|
},
|
|
@@ -577,15 +576,15 @@ class Agora {
|
|
|
577
576
|
return undefined;
|
|
578
577
|
}
|
|
579
578
|
// Plugin gives us the offer data in this form
|
|
580
|
-
const [_,
|
|
579
|
+
const [_, numAtomsTruncBytesHex, numSatsTruncBytesHex, atomsScaleFactorHex, scaledTruncAtomsPerTruncSatHex, minAcceptedScaledTruncAtomsHex, enforcedLockTimeHex,] = plugin.data;
|
|
581
580
|
if (enforcedLockTimeHex === undefined) {
|
|
582
581
|
throw new Error('Outdated plugin');
|
|
583
582
|
}
|
|
584
|
-
const
|
|
583
|
+
const numAtomsTruncBytes = (0, ecash_lib_1.fromHex)(numAtomsTruncBytesHex)[0];
|
|
585
584
|
const numSatsTruncBytes = (0, ecash_lib_1.fromHex)(numSatsTruncBytesHex)[0];
|
|
586
|
-
const
|
|
587
|
-
const
|
|
588
|
-
const
|
|
585
|
+
const atomsScaleFactor = new ecash_lib_1.Bytes((0, ecash_lib_1.fromHex)(atomsScaleFactorHex)).readU64();
|
|
586
|
+
const scaledTruncAtomsPerTruncSat = new ecash_lib_1.Bytes((0, ecash_lib_1.fromHex)(scaledTruncAtomsPerTruncSatHex)).readU64();
|
|
587
|
+
const minAcceptedScaledTruncAtoms = new ecash_lib_1.Bytes((0, ecash_lib_1.fromHex)(minAcceptedScaledTruncAtomsHex)).readU64();
|
|
589
588
|
const enforcedLockTime = new ecash_lib_1.Bytes((0, ecash_lib_1.fromHex)(enforcedLockTimeHex)).readU32();
|
|
590
589
|
const makerPkGroupHex = plugin.groups.find(group => group.startsWith(PUBKEY_PREFIX));
|
|
591
590
|
if (makerPkGroupHex === undefined) {
|
|
@@ -593,19 +592,19 @@ class Agora {
|
|
|
593
592
|
}
|
|
594
593
|
const makerPk = (0, ecash_lib_1.fromHex)(makerPkGroupHex.substring(PUBKEY_PREFIX.length));
|
|
595
594
|
const agoraPartial = new partial_js_1.AgoraPartial({
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
595
|
+
truncAtoms: utxo.token.atoms >> (8n * BigInt(numAtomsTruncBytes)),
|
|
596
|
+
numAtomsTruncBytes,
|
|
597
|
+
atomsScaleFactor,
|
|
598
|
+
scaledTruncAtomsPerTruncSat,
|
|
600
599
|
numSatsTruncBytes,
|
|
601
600
|
makerPk,
|
|
602
|
-
|
|
601
|
+
minAcceptedScaledTruncAtoms,
|
|
603
602
|
tokenId: utxo.token.tokenId,
|
|
604
603
|
tokenType: utxo.token.tokenType.number,
|
|
605
604
|
tokenProtocol: utxo.token.tokenType.protocol,
|
|
606
605
|
scriptLen: 0x7f,
|
|
607
606
|
enforcedLockTime,
|
|
608
|
-
|
|
607
|
+
dustSats: this.dustSats,
|
|
609
608
|
});
|
|
610
609
|
agoraPartial.updateScriptLen();
|
|
611
610
|
return new AgoraOffer({
|
|
@@ -617,7 +616,7 @@ class Agora {
|
|
|
617
616
|
txBuilderInput: {
|
|
618
617
|
prevOut: utxo.outpoint,
|
|
619
618
|
signData: {
|
|
620
|
-
|
|
619
|
+
sats: utxo.sats,
|
|
621
620
|
redeemScript: agoraPartial.script(),
|
|
622
621
|
},
|
|
623
622
|
},
|