Page MenuHomePhabricator

D17776.diff
No OneTemporary

D17776.diff

diff --git a/modules/ecash-agora/README.md b/modules/ecash-agora/README.md
--- a/modules/ecash-agora/README.md
+++ b/modules/ecash-agora/README.md
@@ -191,3 +191,7 @@
- Improve types and shapes in line with chronik proto updates [D17650](https://reviews.bitcoinabc.org/D17650)
- 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.
+
+# 2.0.1
+
+- Ensure special case of agora partial offers where `minAcceptedAtoms` should equal `offeredAtoms` will work out this way [D17776](https://reviews.bitcoinabc.org/D17776)
diff --git a/modules/ecash-agora/package-lock.json b/modules/ecash-agora/package-lock.json
--- a/modules/ecash-agora/package-lock.json
+++ b/modules/ecash-agora/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "ecash-agora",
- "version": "2.0.0",
+ "version": "2.0.1",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "ecash-agora",
- "version": "2.0.0",
+ "version": "2.0.1",
"license": "MIT",
"dependencies": {
"chronik-client": "file:../chronik-client",
diff --git a/modules/ecash-agora/package.json b/modules/ecash-agora/package.json
--- a/modules/ecash-agora/package.json
+++ b/modules/ecash-agora/package.json
@@ -1,6 +1,6 @@
{
"name": "ecash-agora",
- "version": "2.0.0",
+ "version": "2.0.1",
"description": "Library for interacting with the eCash Agora protocol",
"main": "./dist/index.js",
"scripts": {
diff --git a/modules/ecash-agora/src/partial.approx.test.ts b/modules/ecash-agora/src/partial.approx.test.ts
--- a/modules/ecash-agora/src/partial.approx.test.ts
+++ b/modules/ecash-agora/src/partial.approx.test.ts
@@ -1074,6 +1074,36 @@
expect(agoraPartial.askedSats(100n)).to.equal(71236327571456n);
});
+ it('AgoraPartial.approximateParams ALP 1:1 priced (e.g. XECX), large quantity, minAcceptedAtoms === offeredAtoms', async () => {
+ // Use a figure where error of "minAcceptedAtoms exceeds offeredAtoms" was seen in real life
+ const attemptedOfferedAtoms = 292_116_503_52n;
+ const agoraPartial = AgoraPartial.approximateParams({
+ offeredAtoms: attemptedOfferedAtoms,
+ priceNanoSatsPerAtom: 1_000_000_000n, // i.e. 1 sat per atom
+ minAcceptedAtoms: attemptedOfferedAtoms,
+ ...BASE_PARAMS_ALP,
+ });
+
+ expect(agoraPartial).to.deep.equal(
+ new AgoraPartial({
+ truncAtoms: 114108009n,
+ numAtomsTruncBytes: 1,
+ atomsScaleFactor: 18n,
+ scaledTruncAtomsPerTruncSat: 18n,
+ numSatsTruncBytes: 1,
+ minAcceptedScaledTruncAtoms: 2053944162n,
+ ...BASE_PARAMS_ALP,
+ scriptLen: agoraPartial.scriptLen,
+ }),
+ );
+ const actualOfferedAtoms = 292_116_503_04n;
+ expect(agoraPartial.offeredAtoms()).to.equal(actualOfferedAtoms);
+ expect(agoraPartial.minAcceptedAtoms()).to.equal(actualOfferedAtoms);
+ expect(agoraPartial.askedSats(actualOfferedAtoms)).to.equal(
+ actualOfferedAtoms,
+ );
+ });
+
it('AgoraPartial.approximateParams failure', () => {
expect(() =>
AgoraPartial.approximateParams({
@@ -1124,7 +1154,9 @@
...BASE_PARAMS_SLP,
tokenProtocol: 'ALP',
}),
- ).to.throw('offeredAtoms must be greater than minAcceptedAtoms');
+ ).to.throw(
+ 'offeredAtoms must be greater than or equal to minAcceptedAtoms',
+ );
expect(() =>
AgoraPartial.approximateParams({
offeredAtoms: 1n,
diff --git a/modules/ecash-agora/src/partial.ts b/modules/ecash-agora/src/partial.ts
--- a/modules/ecash-agora/src/partial.ts
+++ b/modules/ecash-agora/src/partial.ts
@@ -343,7 +343,7 @@
if (params.offeredAtoms < params.minAcceptedAtoms) {
throw new Error(
- 'offeredAtoms must be greater than minAcceptedAtoms',
+ 'offeredAtoms must be greater than or equal to minAcceptedAtoms',
);
}
@@ -443,8 +443,12 @@
// Scale + truncate the minimum accepted tokens
const minAcceptedScaledTruncAtoms =
- (params.minAcceptedAtoms * atomsScaleFactor) >>
- (8n * numAtomsTruncBytes);
+ params.minAcceptedAtoms === params.offeredAtoms
+ ? // If minAcceptedAtoms is intended to be the whole offer, set it this way.
+ // This prevents creating an unacceptable offer (minAcceptedAtoms > offeredAtoms)
+ truncAtoms * atomsScaleFactor
+ : (params.minAcceptedAtoms * atomsScaleFactor) >>
+ (8n * numAtomsTruncBytes);
const dustSats = params.dustSats ?? DEFAULT_DUST_SATS;
const agoraPartial = new AgoraPartial({

File Metadata

Mime Type
text/plain
Expires
Tue, May 20, 20:16 (14 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5865855
Default Alt Text
D17776.diff (4 KB)

Event Timeline