@pioneer-platform/pioneer-coins 9.2.25 → 9.3.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/lib/paths.js +2 -72
- package/lib/thorchain.d.ts +1 -0
- package/lib/thorchain.js +68 -100
- package/package.json +9 -9
package/lib/paths.js
CHANGED
|
@@ -72,7 +72,7 @@ function getPaths(blockchains, isTestnet) {
|
|
|
72
72
|
else {
|
|
73
73
|
//legacy bip44
|
|
74
74
|
output.push({
|
|
75
|
-
note: "Bitcoin
|
|
75
|
+
note: "Bitcoin account 0",
|
|
76
76
|
networks: ['bip122:000000000019d6689c085ae165831e93'],
|
|
77
77
|
script_type: "p2pkh",
|
|
78
78
|
available_scripts_types: ['p2pkh', 'p2sh', 'p2wpkh', 'p2sh-p2wpkh'],
|
|
@@ -82,6 +82,7 @@ function getPaths(blockchains, isTestnet) {
|
|
|
82
82
|
curve: 'secp256k1',
|
|
83
83
|
showDisplay: false // Not supported by TrezorConnect or Ledger, but KeepKey should do it
|
|
84
84
|
});
|
|
85
|
+
//TODO non-native segwit wraped p2sh
|
|
85
86
|
output.push({
|
|
86
87
|
note: "Bitcoin account 0 Segwit (p2sh-p2wpkh) (ypub) (bip49)",
|
|
87
88
|
networks: ['bip122:000000000019d6689c085ae165831e93'],
|
|
@@ -105,77 +106,6 @@ function getPaths(blockchains, isTestnet) {
|
|
|
105
106
|
curve: 'secp256k1',
|
|
106
107
|
showDisplay: false // Not supported by TrezorConnect or Ledger, but KeepKey should do it
|
|
107
108
|
});
|
|
108
|
-
//account 1
|
|
109
|
-
output.push({
|
|
110
|
-
note: "Bitcoin legacy account 1",
|
|
111
|
-
networks: ['bip122:000000000019d6689c085ae165831e93'],
|
|
112
|
-
script_type: "p2pkh",
|
|
113
|
-
available_scripts_types: ['p2pkh', 'p2sh', 'p2wpkh', 'p2sh-p2wpkh'],
|
|
114
|
-
type: "xpub",
|
|
115
|
-
addressNList: [0x80000000 + 44, 0x80000000 + 0, 0x80000000 + 1],
|
|
116
|
-
addressNListMaster: [0x80000000 + 44, 0x80000000 + 0, 0x80000000 + 1, 0, 0],
|
|
117
|
-
curve: 'secp256k1',
|
|
118
|
-
showDisplay: false // Not supported by TrezorConnect or Ledger, but KeepKey should do it
|
|
119
|
-
});
|
|
120
|
-
output.push({
|
|
121
|
-
note: "Bitcoin account 1 Segwit (p2sh-p2wpkh) (ypub) (bip49)",
|
|
122
|
-
networks: ['bip122:000000000019d6689c085ae165831e93'],
|
|
123
|
-
script_type: "p2sh-p2wpkh",
|
|
124
|
-
available_scripts_types: ['p2pkh', 'p2sh', 'p2wpkh', 'p2sh-p2wpkh'],
|
|
125
|
-
type: "ypub",
|
|
126
|
-
addressNList: [0x80000000 + 49, 0x80000000 + 0, 0x80000000 + 1],
|
|
127
|
-
addressNListMaster: [0x80000000 + 49, 0x80000000 + 0, 0x80000000 + 1, 0, 0],
|
|
128
|
-
curve: 'secp256k1',
|
|
129
|
-
showDisplay: false // Not supported by TrezorConnect or Ledger, but KeepKey should do it
|
|
130
|
-
});
|
|
131
|
-
//bech32 bip84
|
|
132
|
-
output.push({
|
|
133
|
-
note: "Bitcoin account 1Native Segwit (Bech32)",
|
|
134
|
-
networks: ['bip122:000000000019d6689c085ae165831e93'],
|
|
135
|
-
script_type: "p2wpkh", //bech32
|
|
136
|
-
available_scripts_types: ['p2pkh', 'p2sh', 'p2wpkh', 'p2sh-p2wpkh'],
|
|
137
|
-
type: "zpub",
|
|
138
|
-
addressNList: [0x80000000 + 84, 0x80000000 + 0, 0x80000000 + 1],
|
|
139
|
-
addressNListMaster: [0x80000000 + 84, 0x80000000 + 0, 0x80000000 + 1, 0, 0],
|
|
140
|
-
curve: 'secp256k1',
|
|
141
|
-
showDisplay: false // Not supported by TrezorConnect or Ledger, but KeepKey should do it
|
|
142
|
-
});
|
|
143
|
-
//account 2
|
|
144
|
-
output.push({
|
|
145
|
-
note: "Bitcoin legacy account 2",
|
|
146
|
-
networks: ['bip122:000000000019d6689c085ae165831e93'],
|
|
147
|
-
script_type: "p2pkh",
|
|
148
|
-
available_scripts_types: ['p2pkh', 'p2sh', 'p2wpkh', 'p2sh-p2wpkh'],
|
|
149
|
-
type: "xpub",
|
|
150
|
-
addressNList: [0x80000000 + 44, 0x80000000 + 0, 0x80000000 + 2],
|
|
151
|
-
addressNListMaster: [0x80000000 + 44, 0x80000000 + 0, 0x80000000 + 2, 0, 0],
|
|
152
|
-
curve: 'secp256k1',
|
|
153
|
-
showDisplay: false // Not supported by TrezorConnect or Ledger, but KeepKey should do it
|
|
154
|
-
});
|
|
155
|
-
output.push({
|
|
156
|
-
note: "Bitcoin account 1 Segwit (p2sh-p2wpkh) (ypub) (bip49)",
|
|
157
|
-
networks: ['bip122:000000000019d6689c085ae165831e93'],
|
|
158
|
-
script_type: "p2sh-p2wpkh",
|
|
159
|
-
available_scripts_types: ['p2pkh', 'p2sh', 'p2wpkh', 'p2sh-p2wpkh'],
|
|
160
|
-
type: "ypub",
|
|
161
|
-
addressNList: [0x80000000 + 49, 0x80000000 + 0, 0x80000000 + 2],
|
|
162
|
-
addressNListMaster: [0x80000000 + 49, 0x80000000 + 0, 0x80000000 + 2, 0, 0],
|
|
163
|
-
curve: 'secp256k1',
|
|
164
|
-
showDisplay: false // Not supported by TrezorConnect or Ledger, but KeepKey should do it
|
|
165
|
-
});
|
|
166
|
-
//bech32 bip84
|
|
167
|
-
output.push({
|
|
168
|
-
note: "Bitcoin account 1Native Segwit (Bech32)",
|
|
169
|
-
networks: ['bip122:000000000019d6689c085ae165831e93'],
|
|
170
|
-
script_type: "p2wpkh", //bech32
|
|
171
|
-
available_scripts_types: ['p2pkh', 'p2sh', 'p2wpkh', 'p2sh-p2wpkh'],
|
|
172
|
-
type: "zpub",
|
|
173
|
-
addressNList: [0x80000000 + 84, 0x80000000 + 0, 0x80000000 + 2],
|
|
174
|
-
addressNListMaster: [0x80000000 + 84, 0x80000000 + 0, 0x80000000 + 2, 0, 0],
|
|
175
|
-
curve: 'secp256k1',
|
|
176
|
-
showDisplay: false // Not supported by TrezorConnect or Ledger, but KeepKey should do it
|
|
177
|
-
});
|
|
178
|
-
//account 0-2 parity with ShapeShift legacy
|
|
179
109
|
}
|
|
180
110
|
}
|
|
181
111
|
if (blockchains.some(function (blockchain) { return blockchain.includes('eip155:'); })) {
|
package/lib/thorchain.d.ts
CHANGED
package/lib/thorchain.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
----------------------
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.normalizeSwapMemo = normalizeSwapMemo;
|
|
7
8
|
exports.createMemo = createMemo;
|
|
8
9
|
exports.parseMemo = parseMemo;
|
|
9
10
|
var assetShortCodeMap = {
|
|
@@ -35,28 +36,24 @@ var assetShortCodeMap = {
|
|
|
35
36
|
function interpretAssetShortCode(shortCode) {
|
|
36
37
|
return assetShortCodeMap[shortCode] || shortCode;
|
|
37
38
|
}
|
|
38
|
-
// Utility function to interpret
|
|
39
|
+
// Utility function to interpret shortened parts (parsing only, no sci notation)
|
|
39
40
|
function interpretShortenedPart(part) {
|
|
40
|
-
|
|
41
|
-
var _a = part.split('e').map(Number), base = _a[0], exponent = _a[1];
|
|
42
|
-
return base * Math.pow(10, exponent);
|
|
43
|
-
}
|
|
41
|
+
// No scientific notation in THORChain memos - keep as is
|
|
44
42
|
return part;
|
|
45
43
|
}
|
|
46
44
|
// Function to build an Aggregate Swap transaction memo
|
|
47
45
|
function buildAggregateSwapMemo(tx) {
|
|
48
|
-
var
|
|
49
|
-
var limIntervalQuantity = "".concat(tx.lim || '', "/").concat(tx.interval || '', "/").concat(tx.quantity || '');
|
|
46
|
+
var limInterval = "".concat(tx.lim || '', "/").concat(tx.interval || '');
|
|
50
47
|
var parts = [
|
|
51
48
|
'SWAP',
|
|
52
49
|
tx.asset,
|
|
53
50
|
tx.destAddr,
|
|
54
|
-
|
|
51
|
+
limInterval,
|
|
55
52
|
tx.affiliate || '',
|
|
56
|
-
|
|
53
|
+
tx.fee || '',
|
|
57
54
|
tx.dexAggregatorAddr,
|
|
58
55
|
tx.finalAssetAddr,
|
|
59
|
-
tx.minAmountOut
|
|
56
|
+
tx.minAmountOut || ''
|
|
60
57
|
];
|
|
61
58
|
return truncateMemo(parts.join(':'));
|
|
62
59
|
}
|
|
@@ -70,43 +67,29 @@ function truncateMemo(memo, limit) {
|
|
|
70
67
|
}
|
|
71
68
|
return memo;
|
|
72
69
|
}
|
|
73
|
-
//
|
|
74
|
-
function toScientificNotation(number) {
|
|
75
|
-
if (number > 1000000) { // Adjust the threshold as needed
|
|
76
|
-
var exponent = Math.floor(Math.log10(number));
|
|
77
|
-
var base = number / Math.pow(10, exponent);
|
|
78
|
-
return "".concat(base.toFixed(1), "e").concat(exponent);
|
|
79
|
-
}
|
|
80
|
-
return number.toString();
|
|
81
|
-
}
|
|
70
|
+
// Removed toScientificNotation - THORChain requires plain integers
|
|
82
71
|
// Function to build a Swap transaction memo
|
|
83
72
|
function buildSwapMemo(tx) {
|
|
84
|
-
|
|
85
|
-
var
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
var interval = tx.interval ? toScientificNotation(tx.interval) : '';
|
|
94
|
-
var quantity = tx.quantity ? toScientificNotation(tx.quantity) : '';
|
|
95
|
-
parts.push("".concat(lim, "/").concat(interval, "/").concat(quantity));
|
|
73
|
+
// Always emit fully-qualified CHAIN.SYMBOL - never shorthand
|
|
74
|
+
var assetFQ = tx.asset; // e.g. 'BTC.BTC', 'ETH.ETH'
|
|
75
|
+
var parts = ['=', assetFQ, tx.destAddr];
|
|
76
|
+
// Handle lim and interval (no quantity in standard swap)
|
|
77
|
+
if (tx.lim !== undefined || tx.interval !== undefined) {
|
|
78
|
+
// Integers only, no sci-notation
|
|
79
|
+
var lim = tx.lim !== undefined ? String(tx.lim) : '';
|
|
80
|
+
var interval = tx.interval !== undefined ? String(tx.interval) : '';
|
|
81
|
+
parts.push("".concat(lim).concat(interval ? '/' + interval : ''));
|
|
96
82
|
}
|
|
97
83
|
else {
|
|
98
|
-
parts.push(''); // Add
|
|
84
|
+
parts.push(''); // Add empty string for missing lim/interval
|
|
99
85
|
}
|
|
100
|
-
//
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
parts.push(tx.minAmountOut ? toScientificNotation(tx.minAmountOut) : '');
|
|
106
|
-
// Join parts with ':' and correctly handle empty fields
|
|
86
|
+
// Base swap supports optional affiliate tag + bp (basis points 0..1000)
|
|
87
|
+
if (tx.affiliate !== undefined)
|
|
88
|
+
parts.push(tx.affiliate);
|
|
89
|
+
if (tx.fee !== undefined)
|
|
90
|
+
parts.push(String(tx.fee)); // basis points
|
|
107
91
|
var memo = parts.join(':');
|
|
108
|
-
memo = memo.replace(/:{2,}/g, '::');
|
|
109
|
-
memo = memo.replace(/:+$/, ''); // Remove trailing colons
|
|
92
|
+
memo = memo.replace(/:{2,}/g, '::').replace(/:+$/, '');
|
|
110
93
|
return truncateMemo(memo);
|
|
111
94
|
}
|
|
112
95
|
// Function to build a Deposit transaction memo
|
|
@@ -216,6 +199,32 @@ function buildNoOpMemo(tx) {
|
|
|
216
199
|
return truncateMemo(parts.filter(function (part) { return part; }).join(':'));
|
|
217
200
|
}
|
|
218
201
|
// Main function to create a memo from any transaction type
|
|
202
|
+
// Normalize and validate swap memo
|
|
203
|
+
function normalizeSwapMemo(memo) {
|
|
204
|
+
// Ensure "=:" prefix and fully qualified asset
|
|
205
|
+
if (!memo.startsWith('=:')) {
|
|
206
|
+
if (memo.startsWith('='))
|
|
207
|
+
memo = memo.replace(/^=/, '=:');
|
|
208
|
+
else if (memo.startsWith('SWAP:'))
|
|
209
|
+
memo = memo.replace(/^SWAP:/, '=:');
|
|
210
|
+
}
|
|
211
|
+
var parts = memo.slice(2).split(':');
|
|
212
|
+
if (parts.length < 2)
|
|
213
|
+
throw new Error('Memo missing asset/destination');
|
|
214
|
+
// Expand single-letter shorthand if present (parse-time convenience only)
|
|
215
|
+
var cs = parts[0];
|
|
216
|
+
var fix = assetShortCodeMap[cs] || assetShortCodeMap[cs.toUpperCase()];
|
|
217
|
+
if (fix)
|
|
218
|
+
parts[0] = fix;
|
|
219
|
+
// Enforce UPPERCASE CHAIN.SYMBOL
|
|
220
|
+
var _a = parts[0].split('.'), chain = _a[0], symbol = _a[1];
|
|
221
|
+
if (!chain || !symbol)
|
|
222
|
+
throw new Error('Asset must be CHAIN.SYMBOL');
|
|
223
|
+
parts[0] = "".concat(chain.toUpperCase(), ".").concat(symbol.toUpperCase());
|
|
224
|
+
var normalized = "=:" + parts.join(':');
|
|
225
|
+
// guard length
|
|
226
|
+
return truncateMemo(normalized, 250);
|
|
227
|
+
}
|
|
219
228
|
function createMemo(tx) {
|
|
220
229
|
switch (tx.type) {
|
|
221
230
|
case 'SWAP':
|
|
@@ -264,19 +273,15 @@ function parseMemo(memo) {
|
|
|
264
273
|
case 'SWAP': {
|
|
265
274
|
var asset_1 = parts[1];
|
|
266
275
|
var destAddr_1 = parts[2];
|
|
267
|
-
var _a = parts[3].split('/'), lim = _a[0], interval = _a[1]
|
|
276
|
+
var _a = (parts[3] || '').split('/'), lim = _a[0], interval = _a[1];
|
|
268
277
|
return {
|
|
269
|
-
type: 'SWAP',
|
|
270
|
-
asset: asset_1,
|
|
271
|
-
destAddr: destAddr_1,
|
|
272
|
-
lim: lim
|
|
273
|
-
interval: interval
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
fee: parts[5] ? parseFloat(parts[5]) : null, // Fee (optional)
|
|
277
|
-
dexAggregatorAddr: parts[6] || null, // DEX aggregator address (optional)
|
|
278
|
-
finalAssetAddr: parts[7] || null, // Final asset address (optional)
|
|
279
|
-
minAmountOut: parts[8] ? parseInt(parts[8]) : null, // Minimum amount out (optional)
|
|
278
|
+
type: 'SWAP',
|
|
279
|
+
asset: asset_1,
|
|
280
|
+
destAddr: destAddr_1,
|
|
281
|
+
lim: lim || undefined, // keep as string
|
|
282
|
+
interval: interval || undefined, // keep as string
|
|
283
|
+
affiliate: parts[4] || undefined,
|
|
284
|
+
fee: parts[5] || undefined, // keep as string (bp)
|
|
280
285
|
};
|
|
281
286
|
}
|
|
282
287
|
case 'DEPOSIT':
|
|
@@ -355,58 +360,21 @@ function parseMemo(memo) {
|
|
|
355
360
|
noVault: parts[1] === 'NOVAULT',
|
|
356
361
|
};
|
|
357
362
|
case 'AGGREGATE_SWAP': {
|
|
358
|
-
var _b = parts[3].split('/'), lim = _b[0], interval = _b[1]
|
|
359
|
-
return {
|
|
360
|
-
type: 'SWAP', // Using 'SWAP' as the type for consistency
|
|
361
|
-
asset: asset,
|
|
362
|
-
destAddr: destAddr,
|
|
363
|
-
lim: lim ? parseInt(lim) : null,
|
|
364
|
-
interval: interval ? parseInt(interval) : null,
|
|
365
|
-
quantity: quantity ? parseInt(quantity) : null,
|
|
366
|
-
affiliate: parts[4] || null,
|
|
367
|
-
fee: parts[5] ? parseFloat(parts[5]) : null,
|
|
368
|
-
dexAggregatorAddr: parts[6],
|
|
369
|
-
finalAssetAddr: parts[7],
|
|
370
|
-
minAmountOut: parts[8] ? parseInt(parts[8]) : null,
|
|
371
|
-
};
|
|
372
|
-
}
|
|
373
|
-
case 'LOAN+': {
|
|
374
|
-
var minOut = parts[3] ? parseInt(parts[3]) : null;
|
|
363
|
+
var _b = (parts[3] || '').split('/'), lim = _b[0], interval = _b[1];
|
|
375
364
|
return {
|
|
376
|
-
type:
|
|
365
|
+
type: 'AGGREGATE_SWAP',
|
|
377
366
|
asset: asset,
|
|
378
367
|
destAddr: destAddr,
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
return {
|
|
387
|
-
type: type,
|
|
388
|
-
asset: asset,
|
|
389
|
-
destAddr: destAddr,
|
|
390
|
-
minOut: minOut,
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
case 'ADD': {
|
|
394
|
-
return {
|
|
395
|
-
type: type,
|
|
396
|
-
asset: asset,
|
|
397
|
-
pairedAddr: parts[3] || null,
|
|
398
|
-
affiliate: parts[4] || null,
|
|
399
|
-
fee: parts[5] ? parseFloat(parts[5]) : null,
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
case 'WD': {
|
|
403
|
-
return {
|
|
404
|
-
type: type,
|
|
405
|
-
asset: asset,
|
|
406
|
-
basisPoints: parseInt(parts[3]),
|
|
407
|
-
singleAsset: parts[4] || null,
|
|
368
|
+
lim: lim || undefined,
|
|
369
|
+
interval: interval || undefined,
|
|
370
|
+
affiliate: parts[4] || undefined,
|
|
371
|
+
fee: parts[5] || undefined,
|
|
372
|
+
dexAggregatorAddr: parts[6] || '',
|
|
373
|
+
finalAssetAddr: parts[7] || '',
|
|
374
|
+
minAmountOut: parts[8] || undefined,
|
|
408
375
|
};
|
|
409
376
|
}
|
|
377
|
+
// Removed duplicate cases - already handled above
|
|
410
378
|
default:
|
|
411
379
|
throw new Error("Unsupported memo type: ".concat(type));
|
|
412
380
|
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pioneer-platform/pioneer-coins",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.3.0",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"_moduleAliases": {
|
|
7
7
|
"@coins": "lib/coins"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
-
"npm": "
|
|
10
|
+
"npm": "pnpm i",
|
|
11
11
|
"build": "tsc -p .",
|
|
12
|
-
"test": "
|
|
13
|
-
"test-suite": "
|
|
14
|
-
"build:watch": "
|
|
15
|
-
"prepublish": "
|
|
12
|
+
"test": "pnpm run build && node __tests__/test-module.js",
|
|
13
|
+
"test-suite": "pnpm run build && node __tests__/tests-common.js",
|
|
14
|
+
"build:watch": "pnpm run build && onchange 'src/**/*.ts' -- pnpm run build",
|
|
15
|
+
"prepublish": "pnpm run build"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@pioneer-platform/loggerdog": "^8.3.1",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/express": "^4.17.6",
|
|
24
|
-
"@types/node": "18.
|
|
24
|
+
"@types/node": "^18.16.0",
|
|
25
25
|
"nodemon": "^2.0.3",
|
|
26
|
-
"typescript": "^5.0.
|
|
26
|
+
"typescript": "^5.0.4"
|
|
27
27
|
},
|
|
28
28
|
"gitHead": "a76012f6693a12181c4744e53e977a9eaeef0ed3"
|
|
29
|
-
}
|
|
29
|
+
}
|