Skip to content

Commit 88a85dd

Browse files
committed
[REF] Changelly: using stablecoin_api for stablecoin swaps
1 parent cfd14a2 commit 88a85dd

3 files changed

Lines changed: 45 additions & 4 deletions

File tree

packages/bitcore-wallet-service/src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ const Config = (): any => {
456456
// },
457457
// v2: {
458458
// secret: 'changelly_secret_v2',
459+
// secret_stablecoin: 'changelly_secret_stablecoin_v2'
459460
// api: 'https://api.changelly.com/v2'
460461
// }
461462
// },

packages/bitcore-wallet-service/src/externalservices/changelly.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ import { checkRequired } from '../lib/server';
99
export class ChangellyService {
1010
request: any = request;
1111

12-
private changellyGetKeysV2(_req) {
12+
changellyGetKeysV2(req) {
13+
14+
const stablecoins = [
15+
'usdt20', 'usdtarb', 'usdtop', 'usdtpolygon', 'usdtsol',
16+
'usdcmatic', 'usdcarb', 'usdcbase', 'usdcop', 'usdcsol',
17+
'daipolygon'
18+
];
19+
1320
if (!config.changelly) {
1421
logger.warn('Changelly missing credentials');
1522
throw new Error('ClientError: Service not configured.');
@@ -18,9 +25,15 @@ export class ChangellyService {
1825
throw new Error('ClientError: Service v2 not configured.');
1926
}
2027

28+
const { api, secret, secret_stablecoin } = config.changelly.v2;
29+
30+
const apiKey = stablecoins.includes(req.body.coinFrom)
31+
? (secret_stablecoin ?? secret)
32+
: secret;
33+
2134
const keys = {
22-
API: config.changelly.v2.api,
23-
SECRET: config.changelly.v2.secret
35+
API: api,
36+
SECRET: apiKey
2437
};
2538

2639
return keys;

packages/bitcore-wallet-service/test/integration/externalservices/changelly.test.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ describe('Changelly integration', () => {
4343
},
4444
v2: {
4545
secret: privateKey.toString('hex'),
46-
api: 'apiV2'
46+
secret_stablecoin: 'changelly_secret_stablecoin_v2',
47+
api: 'apiV2',
4748
}
4849
};
4950

@@ -70,6 +71,32 @@ describe('Changelly integration', () => {
7071
await helpers.after();
7172
});
7273

74+
describe('#Changelly API key selection', () => {
75+
it('should use stablecoin API key for stablecoin swaps', () => {
76+
const stablecoins = [
77+
'usdt20', 'usdtarb', 'usdtop', 'usdtpolygon', 'usdtsol',
78+
'usdcmatic', 'usdcarb', 'usdcbase', 'usdcop', 'usdcsol',
79+
'daipolygon'
80+
];
81+
82+
for (const coin of stablecoins) {
83+
const req = {
84+
body: { coinFrom: coin }
85+
};
86+
const keys = server.externalServices.changelly.changellyGetKeysV2(req);
87+
keys.SECRET.should.equal(config.changelly.v2.secret_stablecoin);
88+
keys.API.should.equal(config.changelly.v2.api);
89+
}
90+
91+
const req = {
92+
body: { coinFrom: 'xxx' }
93+
};
94+
const keys = server.externalServices.changelly.changellyGetKeysV2(req);
95+
keys.SECRET.should.equal(config.changelly.v2.secret);
96+
keys.API.should.equal(config.changelly.v2.api);
97+
});
98+
});
99+
73100
describe('#changellyGetCurrencies', () => {
74101
beforeEach(() => {
75102
req = {

0 commit comments

Comments
 (0)