Skip to content

Commit 86f44eb

Browse files
feat(abstract-cosmos): add non-bitgo token recovery support on wrw
TICKET: COIN-5413
1 parent 62ef360 commit 86f44eb

File tree

15 files changed

+644
-123
lines changed

15 files changed

+644
-123
lines changed

modules/abstract-cosmos/src/cosmosCoin.ts

Lines changed: 268 additions & 84 deletions
Large diffs are not rendered by default.

modules/abstract-cosmos/src/lib/iface.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { TransactionExplanation as BaseTransactionExplanation, TransactionType } from '@bitgo/sdk-core';
22
import { Coin } from '@cosmjs/stargate';
3+
import { BigNumber } from 'bignumber.js';
34

45
/**
56
* Defines the protobuf typeUrl for the public key
@@ -109,3 +110,24 @@ export interface CosmosLikeTransaction<CustomMessage = never> {
109110
readonly hash?: string;
110111
readonly memo?: string;
111112
}
113+
114+
export interface KeyShares {
115+
userKeyShare: Buffer;
116+
backupKeyShare: Buffer;
117+
commonKeyChain: string;
118+
}
119+
120+
export interface TransactionBuildParams {
121+
messages: SendMessage[];
122+
chainId: string;
123+
accountDetails: string[];
124+
publicKey: string;
125+
isUnsignedSweep: boolean;
126+
keyShares?: KeyShares;
127+
}
128+
129+
export interface BalanceResult {
130+
nativeBalance: BigNumber;
131+
remainingBalances: Coin[];
132+
actualBalance: BigNumber;
133+
}

modules/sdk-coin-atom/test/unit/atom.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,21 @@ describe('ATOM', function () {
390390
const sandBox = sinon.createSandbox();
391391
const destinationAddress = wrwUser.destinationAddress;
392392
const coin = coins.get('tatom');
393-
const testBalance = '150000';
393+
const testBalance = [
394+
{
395+
denom: 'uatom',
396+
amount: '150000',
397+
},
398+
];
394399
const testAccountNumber = '725163';
395400
const testSequenceNumber = '8';
396401

397-
const testBalanceDkls = '150000';
402+
const testBalanceDkls = [
403+
{
404+
denom: 'uatom',
405+
amount: '150000',
406+
},
407+
];
398408
const testAccountNumberDkls = '755440';
399409
const testSequenceNumberDkls = '2';
400410

@@ -439,10 +449,11 @@ describe('ATOM', function () {
439449
atomTxn.enrichTransactionDetailsFromRawTransaction(res.serializedTx);
440450
const atomTxnJson = atomTxn.toJson();
441451
const sendMessage = atomTxnJson.sendMessages[0].value as SendMessage;
442-
const balance = new BigNumber(testBalance);
452+
const balance = new BigNumber(testBalance[0].amount);
443453
const gasAmount = new BigNumber(GAS_AMOUNT);
444454
const actualBalance = balance.minus(gasAmount);
445455
should.equal(sendMessage.amount[0].amount, actualBalance.toFixed());
456+
should.equal(sendMessage.amount[0].denom, testBalance[0].denom);
446457
});
447458

448459
it('should recover funds for non-bitgo recoveries - DKLS type', async function () {
@@ -463,7 +474,7 @@ describe('ATOM', function () {
463474
atomTxn.enrichTransactionDetailsFromRawTransaction(res.serializedTx);
464475
const atomTxnJson = atomTxn.toJson();
465476
const sendMessage = atomTxnJson.sendMessages[0].value as SendMessage;
466-
const balance = new BigNumber(testBalanceDkls);
477+
const balance = new BigNumber(testBalanceDkls[0].amount);
467478
const gasAmount = new BigNumber(GAS_AMOUNT);
468479
const actualBalance = balance.minus(gasAmount);
469480
should.equal(sendMessage.amount[0].amount, actualBalance.toFixed());
@@ -487,7 +498,7 @@ describe('ATOM', function () {
487498
unsignedSweepTxnDeserialize.enrichTransactionDetailsFromRawTransaction(res.serializedTx);
488499
const unsignedSweepTxnJson = unsignedSweepTxnDeserialize.toJson();
489500
const sendMessage = unsignedSweepTxnJson.sendMessages[0].value as SendMessage;
490-
const balance = new BigNumber(testBalance);
501+
const balance = new BigNumber(testBalance[0].amount);
491502
const gasAmount = new BigNumber(GAS_AMOUNT);
492503
const actualBalance = balance.minus(gasAmount);
493504
should.equal(sendMessage.amount[0].amount, actualBalance.toFixed());
@@ -521,7 +532,12 @@ describe('ATOM', function () {
521532
describe('Recover transactions: failure path', () => {
522533
const sandBox = sinon.createSandbox();
523534
const destinationAddress = wrwUser.destinationAddress;
524-
const testZeroBalance = '0';
535+
const testZeroBalance = [
536+
{
537+
denom: 'uatom',
538+
amount: '0',
539+
},
540+
];
525541
const testAccountNumber = '1234';
526542
const testSequenceNumber = '0';
527543
const testChainId = 'test-chain';

modules/sdk-coin-bld/test/unit/bld.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,12 @@ describe('BLD', function () {
342342
const sandBox = sinon.createSandbox();
343343
const destinationAddress = wrwUser.destinationAddress;
344344
const coin = coins.get('tbld');
345-
const testBalance = '1500000';
345+
const testBalance = [
346+
{
347+
denom: 'ubld',
348+
amount: '150000',
349+
},
350+
];
346351
const testAccountNumber = '123';
347352
const testSequenceNumber = '0';
348353
const testChainId = 'test-chain';
@@ -384,11 +389,12 @@ describe('BLD', function () {
384389
txn.enrichTransactionDetailsFromRawTransaction(res.serializedTx);
385390
const txnJson = txn.toJson();
386391
const sendMessage = txnJson.sendMessages[0].value as SendMessage;
387-
const balance = new BigNumber(testBalance);
392+
const balance = new BigNumber(testBalance[0].amount);
388393
const gasAmount = new BigNumber(7000);
389394
const actualBalance = balance.minus(gasAmount);
390395
should.equal(sendMessage.toAddress, destinationAddress);
391396
should.equal(sendMessage.amount[0].amount, actualBalance.toFixed());
397+
should.equal(sendMessage.amount[0].denom, testBalance[0].denom);
392398
});
393399

394400
it('should redelegate funds to new validator', async function () {
@@ -419,7 +425,12 @@ describe('BLD', function () {
419425
describe('Recover transaction: failure path', () => {
420426
const sandBox = sinon.createSandbox();
421427
const destinationAddress = wrwUser.destinationAddress;
422-
const testZeroBalance = '0';
428+
const testZeroBalance = [
429+
{
430+
denom: 'ubld',
431+
amount: '0',
432+
},
433+
];
423434
const testAccountNumber = '123';
424435
const testSequenceNumber = '0';
425436
const testChainId = 'test-chain';

modules/sdk-coin-coreum/test/unit/coreum.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,12 @@ describe('Coreum', function () {
387387
const sandBox = sinon.createSandbox();
388388
const destinationAddress = wrwUser.destinationAddress;
389389
const coin = coins.get('tcoreum');
390-
const testBalance = '1500000';
390+
const testBalance = [
391+
{
392+
denom: 'utestcore',
393+
amount: '150000000000',
394+
},
395+
];
391396
const testAccountNumber = '123';
392397
const testSequenceNumber = '0';
393398
const testChainId = 'test-chain';
@@ -429,16 +434,22 @@ describe('Coreum', function () {
429434
tcoreumTxn.enrichTransactionDetailsFromRawTransaction(res.serializedTx);
430435
const tcoreumTxnJson = tcoreumTxn.toJson();
431436
const sendMessage = tcoreumTxnJson.sendMessages[0].value as SendMessage;
432-
const balance = new BigNumber(testBalance);
437+
const balance = new BigNumber(testBalance[0].amount);
433438
const actualBalance = balance.minus(new BigNumber(GAS_AMOUNT));
434439
should.equal(sendMessage.amount[0].amount, actualBalance.toFixed());
440+
should.equal(sendMessage.amount[0].denom, testBalance[0].denom);
435441
});
436442
});
437443

438444
describe('Recover transaction: failure path', () => {
439445
const sandBox = sinon.createSandbox();
440446
const destinationAddress = wrwUser.destinationAddress;
441-
const testZeroBalance = '0';
447+
const testZeroBalance = [
448+
{
449+
denom: 'utestcore',
450+
amount: '0',
451+
},
452+
];
442453
const testAccountNumber = '123';
443454
const testSequenceNumber = '0';
444455
const testChainId = 'test-chain';

modules/sdk-coin-hash/src/hashToken.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { BitGoBase, CoinConstructor, NamedCoinConstructor } from '@bitgo/sdk-core';
1+
import { AddressFormat, BitGoBase, CoinConstructor, NamedCoinConstructor } from '@bitgo/sdk-core';
22
import { CosmosTokenConfig, coins, tokens } from '@bitgo/statics';
33
import { Hash } from './hash';
44
import { HashUtils } from './lib/utils';
5+
import { KeyPair } from './lib';
56

67
export class HashToken extends Hash {
78
public readonly tokenConfig: CosmosTokenConfig;
@@ -66,4 +67,9 @@ export class HashToken extends Hash {
6667
getBaseFactor(): number {
6768
return Math.pow(10, this.tokenConfig.decimalPlaces);
6869
}
70+
71+
getAddressFromPublicKey(publicKey: string): string {
72+
const networkType = this.network === 'Mainnet' ? AddressFormat.mainnet : AddressFormat.testnet;
73+
return new KeyPair({ pub: publicKey }).getAddress(networkType);
74+
}
6975
}

modules/sdk-coin-hash/test/unit/hash.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,12 @@ describe('HASH', function () {
378378
const sandBox = sinon.createSandbox();
379379
const destinationAddress = wrwUser.destinationAddress;
380380
const coin = coins.get('thash');
381-
const testBalance = '150000000000';
381+
const testBalance = [
382+
{
383+
denom: 'nhash',
384+
amount: '150000000000',
385+
},
386+
];
382387
const testAccountNumber = '123';
383388
const testSequenceNumber = '0';
384389
const testChainId = 'test-chain';
@@ -420,18 +425,24 @@ describe('HASH', function () {
420425
txn.enrichTransactionDetailsFromRawTransaction(res.serializedTx);
421426
const txnJson = txn.toJson();
422427
const sendMessage = txnJson.sendMessages[0].value as SendMessage;
423-
const balance = new BigNumber(testBalance);
428+
const balance = new BigNumber(testBalance[0].amount);
424429
const gasAmount = new BigNumber(5000000000);
425430
const actualBalance = balance.minus(gasAmount);
426431
should.equal(sendMessage.toAddress, destinationAddress);
427432
should.equal(sendMessage.amount[0].amount, actualBalance.toFixed());
433+
should.equal(sendMessage.amount[0].denom, testBalance[0].denom);
428434
});
429435
});
430436

431437
describe('Recover transaction: failure path', () => {
432438
const sandBox = sinon.createSandbox();
433439
const destinationAddress = wrwUser.destinationAddress;
434-
const testZeroBalance = '0';
440+
const testZeroBalance = [
441+
{
442+
denom: 'nhash',
443+
amount: '0',
444+
},
445+
];
435446
const testAccountNumber = '123';
436447
const testSequenceNumber = '0';
437448
const testChainId = 'test-chain';

0 commit comments

Comments
 (0)