@pioneer-platform/changelly-client 8.5.0 → 8.7.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/.turbo/turbo-build.log +1 -0
- package/CHANGELOG.md +24 -0
- package/build.sh +22 -0
- package/lib/index.d.ts +15 -0
- package/lib/index.js +307 -0
- package/lib/index.js.map +129 -0
- package/package.json +3 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
$ tsc -p .
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @pioneer-platform/changelly-client
|
|
2
2
|
|
|
3
|
+
## 8.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Automated minor version bump for all packages
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
- @pioneer-platform/loggerdog@8.7.0
|
|
13
|
+
- @pioneer-platform/pioneer-caip@9.6.0
|
|
14
|
+
|
|
15
|
+
## 8.6.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- Automated minor version bump for all packages
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- Updated dependencies
|
|
24
|
+
- @pioneer-platform/loggerdog@8.6.0
|
|
25
|
+
- @pioneer-platform/pioneer-caip@9.5.0
|
|
26
|
+
|
|
3
27
|
## 8.5.0
|
|
4
28
|
|
|
5
29
|
### Minor Changes
|
package/build.sh
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Fast Bun build (replaces slow tsc)
|
|
3
|
+
|
|
4
|
+
OUTDIR="${1:-lib}"
|
|
5
|
+
ENTRY="${2:-src/index.ts}"
|
|
6
|
+
|
|
7
|
+
# Clean output
|
|
8
|
+
rm -rf "$OUTDIR"
|
|
9
|
+
mkdir -p "$OUTDIR"
|
|
10
|
+
|
|
11
|
+
# Build with Bun (10x faster than tsc)
|
|
12
|
+
bun build "$ENTRY" \
|
|
13
|
+
--outdir "$OUTDIR" \
|
|
14
|
+
--target node \
|
|
15
|
+
--format cjs \
|
|
16
|
+
--sourcemap \
|
|
17
|
+
--minify
|
|
18
|
+
|
|
19
|
+
# Generate TypeScript declarations
|
|
20
|
+
bunx tsc --emitDeclarationOnly --outDir "$OUTDIR" --project .
|
|
21
|
+
|
|
22
|
+
echo "✅ Built $OUTDIR"
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare let Changelly: any;
|
|
2
|
+
declare const TAG = " | Changelly | ";
|
|
3
|
+
declare const CHANGELLY_API_KEY: string | undefined;
|
|
4
|
+
declare const CHANGELLY_API_SECRET: string | undefined;
|
|
5
|
+
declare let changelly: any;
|
|
6
|
+
declare let ChainToNetworkId: any, caipToNetworkId: any, shortListSymbolToCaip: any;
|
|
7
|
+
declare let networkSupport: any[];
|
|
8
|
+
declare let assetSupport: any[];
|
|
9
|
+
declare function get_currencies(): Promise<any>;
|
|
10
|
+
declare function create_transaction(from: string, to: string, address: string, amount: number, extraId?: string): Promise<any>;
|
|
11
|
+
declare function get_min_amount(from: string, to: string): Promise<any>;
|
|
12
|
+
declare function get_exchange_amount(from: string, to: string, amount: number): Promise<any>;
|
|
13
|
+
declare function get_transaction(orderId?: string): Promise<any>;
|
|
14
|
+
declare function get_transactions(limit: number, offset: number, currency?: string, address?: string, extraId?: string): Promise<any>;
|
|
15
|
+
declare function get_status(id: string): Promise<any>;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
This is v1, need to migrate to v2
|
|
4
|
+
*/
|
|
5
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
15
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
16
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
17
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
18
|
+
function step(op) {
|
|
19
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
20
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
21
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
22
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
23
|
+
switch (op[0]) {
|
|
24
|
+
case 0: case 1: t = op; break;
|
|
25
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
26
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
27
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
28
|
+
default:
|
|
29
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
30
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
31
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
32
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
33
|
+
if (t[2]) _.ops.pop();
|
|
34
|
+
_.trys.pop(); continue;
|
|
35
|
+
}
|
|
36
|
+
op = body.call(thisArg, _);
|
|
37
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
38
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var Changelly = require('@bithighlander/changelly');
|
|
42
|
+
var TAG = " | Changelly | ";
|
|
43
|
+
var CHANGELLY_API_KEY = process.env['CHANGELLY_API_KEY'];
|
|
44
|
+
var CHANGELLY_API_SECRET = process.env['CHANGELLY_API_SECRET'];
|
|
45
|
+
if (!CHANGELLY_API_KEY)
|
|
46
|
+
throw new Error('CHANGELLY_API_KEY not set');
|
|
47
|
+
if (!CHANGELLY_API_SECRET)
|
|
48
|
+
throw new Error('CHANGELLY_API_SECRET not set');
|
|
49
|
+
var changelly;
|
|
50
|
+
var _a = require("@pioneer-platform/pioneer-caip"), ChainToNetworkId = _a.ChainToNetworkId, caipToNetworkId = _a.caipToNetworkId, shortListSymbolToCaip = _a.shortListSymbolToCaip;
|
|
51
|
+
var networkSupport = [
|
|
52
|
+
ChainToNetworkId["XRP"],
|
|
53
|
+
ChainToNetworkId["DASH"],
|
|
54
|
+
ChainToNetworkId["ZEC"],
|
|
55
|
+
// shortListSymbolToCaip["BSV"], //TODO
|
|
56
|
+
// shortListSymbolToCaip["ADA"], //TODO
|
|
57
|
+
// shortListSymbolToCaip["EOS"], //TODO
|
|
58
|
+
ChainToNetworkId["GAIA"],
|
|
59
|
+
ChainToNetworkId["BNB"],
|
|
60
|
+
ChainToNetworkId["DOGE"],
|
|
61
|
+
ChainToNetworkId["BTC"],
|
|
62
|
+
ChainToNetworkId["ETH"],
|
|
63
|
+
ChainToNetworkId["BASE"],
|
|
64
|
+
ChainToNetworkId["LTC"],
|
|
65
|
+
ChainToNetworkId["THOR"],
|
|
66
|
+
ChainToNetworkId["BCH"],
|
|
67
|
+
ChainToNetworkId["GNO"],
|
|
68
|
+
ChainToNetworkId["MATIC"],
|
|
69
|
+
ChainToNetworkId["AVAX"],
|
|
70
|
+
];
|
|
71
|
+
var assetSupport = [
|
|
72
|
+
shortListSymbolToCaip["BTC"],
|
|
73
|
+
shortListSymbolToCaip["ETH"],
|
|
74
|
+
shortListSymbolToCaip["XRP"],
|
|
75
|
+
shortListSymbolToCaip["DASH"],
|
|
76
|
+
shortListSymbolToCaip["ZEC"],
|
|
77
|
+
shortListSymbolToCaip["DOGE"],
|
|
78
|
+
shortListSymbolToCaip["BASE"],
|
|
79
|
+
shortListSymbolToCaip["LTC"],
|
|
80
|
+
shortListSymbolToCaip["BCH"],
|
|
81
|
+
shortListSymbolToCaip["MATIC"],
|
|
82
|
+
shortListSymbolToCaip["AVAX"],
|
|
83
|
+
shortListSymbolToCaip["BSV"], //TODO
|
|
84
|
+
shortListSymbolToCaip["ADA"], //TODO
|
|
85
|
+
shortListSymbolToCaip["EOS"], //TODO
|
|
86
|
+
];
|
|
87
|
+
module.exports = {
|
|
88
|
+
init: function (settings) {
|
|
89
|
+
changelly = new Changelly(CHANGELLY_API_KEY, CHANGELLY_API_SECRET);
|
|
90
|
+
},
|
|
91
|
+
networkSupport: function () {
|
|
92
|
+
return networkSupport;
|
|
93
|
+
},
|
|
94
|
+
assetSupport: function () {
|
|
95
|
+
return assetSupport;
|
|
96
|
+
},
|
|
97
|
+
getCurrenciesAsync: function () {
|
|
98
|
+
return get_currencies();
|
|
99
|
+
},
|
|
100
|
+
getQuote: function (from, to, address, amount, extraId) {
|
|
101
|
+
return create_transaction(from, to, address, amount, extraId);
|
|
102
|
+
},
|
|
103
|
+
// createTransactionAsync: function(from: string, to: string, address: string, amount: number, extraId?: string): Promise<any> {
|
|
104
|
+
// return create_transaction(from, to, address, amount, extraId);
|
|
105
|
+
// },
|
|
106
|
+
getMinAmountAsync: function (from, to) {
|
|
107
|
+
return get_min_amount(from, to);
|
|
108
|
+
},
|
|
109
|
+
getExchangeAmountAsync: function (from, to, amount) {
|
|
110
|
+
return get_exchange_amount(from, to, amount);
|
|
111
|
+
},
|
|
112
|
+
getTransactionAsync: function (id) {
|
|
113
|
+
return get_transaction(id);
|
|
114
|
+
},
|
|
115
|
+
getTransactionsAsync: function (limit, offset, currency, address, extraId) {
|
|
116
|
+
return get_transactions(limit, offset, currency, address, extraId);
|
|
117
|
+
},
|
|
118
|
+
getStatusAsync: function (id) {
|
|
119
|
+
return get_status(id);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
function get_currencies() {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
124
|
+
return __generator(this, function (_a) {
|
|
125
|
+
try {
|
|
126
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
127
|
+
changelly.getCurrencies(function (err, data) {
|
|
128
|
+
if (err)
|
|
129
|
+
reject(err);
|
|
130
|
+
else
|
|
131
|
+
resolve(data);
|
|
132
|
+
});
|
|
133
|
+
})];
|
|
134
|
+
}
|
|
135
|
+
catch (e) {
|
|
136
|
+
console.error(TAG, "get_currencies error:", e);
|
|
137
|
+
throw e;
|
|
138
|
+
}
|
|
139
|
+
return [2 /*return*/];
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function create_transaction(from, to, address, amount, extraId) {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
145
|
+
var output, data, tx, e_1;
|
|
146
|
+
return __generator(this, function (_a) {
|
|
147
|
+
switch (_a.label) {
|
|
148
|
+
case 0:
|
|
149
|
+
_a.trys.push([0, 2, , 3]);
|
|
150
|
+
output = {};
|
|
151
|
+
output.steps = 1;
|
|
152
|
+
output.complete = true;
|
|
153
|
+
output.source = 'changelly';
|
|
154
|
+
output.meta = {
|
|
155
|
+
quoteMode: "CHANGELLY"
|
|
156
|
+
};
|
|
157
|
+
output.complete = true;
|
|
158
|
+
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
159
|
+
changelly.createTransaction(from, to, address, amount, extraId, function (err, data) {
|
|
160
|
+
if (err) {
|
|
161
|
+
reject(err);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
resolve(data);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
})];
|
|
168
|
+
case 1:
|
|
169
|
+
data = _a.sent();
|
|
170
|
+
console.log("data:", data);
|
|
171
|
+
data = data.result;
|
|
172
|
+
output.id = data.id;
|
|
173
|
+
output.amountOut = data.amountExpectedTo;
|
|
174
|
+
output.inboundAddress = data.payinAddress;
|
|
175
|
+
if (!data)
|
|
176
|
+
throw Error("Failed to create quote@changelly");
|
|
177
|
+
if (!data.payinAddress)
|
|
178
|
+
throw Error("Failed to create quote@changelly");
|
|
179
|
+
if (!data.id)
|
|
180
|
+
throw Error("Failed to create quote@changelly");
|
|
181
|
+
output.id = data.id;
|
|
182
|
+
tx = {
|
|
183
|
+
type: "transfer",
|
|
184
|
+
chain: caipToNetworkId(shortListSymbolToCaip[from]),
|
|
185
|
+
txParams: {
|
|
186
|
+
address: data.payinAddress,
|
|
187
|
+
amount: amount,
|
|
188
|
+
memo: data.payinExtraId,
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
output.txs = [tx];
|
|
192
|
+
output.raw = data;
|
|
193
|
+
return [2 /*return*/, output];
|
|
194
|
+
case 2:
|
|
195
|
+
e_1 = _a.sent();
|
|
196
|
+
console.error(TAG, "create_transaction error:", e_1);
|
|
197
|
+
throw e_1;
|
|
198
|
+
case 3: return [2 /*return*/];
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
function get_min_amount(from, to) {
|
|
204
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
205
|
+
return __generator(this, function (_a) {
|
|
206
|
+
try {
|
|
207
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
208
|
+
changelly.getMinAmount(from, to, function (err, data) {
|
|
209
|
+
if (err)
|
|
210
|
+
reject(err);
|
|
211
|
+
else
|
|
212
|
+
resolve(data);
|
|
213
|
+
});
|
|
214
|
+
})];
|
|
215
|
+
}
|
|
216
|
+
catch (e) {
|
|
217
|
+
console.error(TAG, "get_min_amount error:", e);
|
|
218
|
+
throw e;
|
|
219
|
+
}
|
|
220
|
+
return [2 /*return*/];
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
function get_exchange_amount(from, to, amount) {
|
|
225
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
226
|
+
return __generator(this, function (_a) {
|
|
227
|
+
try {
|
|
228
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
229
|
+
changelly.getExchangeAmount(from, to, amount, function (err, data) {
|
|
230
|
+
if (err)
|
|
231
|
+
reject(err);
|
|
232
|
+
else
|
|
233
|
+
resolve(data);
|
|
234
|
+
});
|
|
235
|
+
})];
|
|
236
|
+
}
|
|
237
|
+
catch (e) {
|
|
238
|
+
console.error(TAG, "get_exchange_amount error:", e);
|
|
239
|
+
throw e;
|
|
240
|
+
}
|
|
241
|
+
return [2 /*return*/];
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
function get_transaction(orderId) {
|
|
246
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
247
|
+
return __generator(this, function (_a) {
|
|
248
|
+
try {
|
|
249
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
250
|
+
changelly.getTransaction(orderId, function (err, data) {
|
|
251
|
+
if (err)
|
|
252
|
+
reject(err);
|
|
253
|
+
else
|
|
254
|
+
resolve(data);
|
|
255
|
+
});
|
|
256
|
+
})];
|
|
257
|
+
}
|
|
258
|
+
catch (e) {
|
|
259
|
+
console.error(TAG, "get_transactions error:", e);
|
|
260
|
+
throw e;
|
|
261
|
+
}
|
|
262
|
+
return [2 /*return*/];
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
function get_transactions(limit, offset, currency, address, extraId) {
|
|
267
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
268
|
+
return __generator(this, function (_a) {
|
|
269
|
+
try {
|
|
270
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
271
|
+
changelly.getTransactions(limit, offset, currency, address, extraId, function (err, data) {
|
|
272
|
+
if (err)
|
|
273
|
+
reject(err);
|
|
274
|
+
else
|
|
275
|
+
resolve(data);
|
|
276
|
+
});
|
|
277
|
+
})];
|
|
278
|
+
}
|
|
279
|
+
catch (e) {
|
|
280
|
+
console.error(TAG, "get_transactions error:", e);
|
|
281
|
+
throw e;
|
|
282
|
+
}
|
|
283
|
+
return [2 /*return*/];
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
function get_status(id) {
|
|
288
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
289
|
+
return __generator(this, function (_a) {
|
|
290
|
+
try {
|
|
291
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
292
|
+
changelly.getStatus(id, function (err, data) {
|
|
293
|
+
if (err)
|
|
294
|
+
reject(err);
|
|
295
|
+
else
|
|
296
|
+
resolve(data);
|
|
297
|
+
});
|
|
298
|
+
})];
|
|
299
|
+
}
|
|
300
|
+
catch (e) {
|
|
301
|
+
console.error(TAG, "get_status error:", e);
|
|
302
|
+
throw e;
|
|
303
|
+
}
|
|
304
|
+
return [2 /*return*/];
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
}
|