From 550380d7838586a407bfb805d2ac7e99c6cf1cec Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 15 Nov 2023 16:23:43 -0700 Subject: [PATCH] feat: deprecate old settlement code * Old code API unusable. No need for breaking change since it is impossible to use with BitGo products PX-262 TICKET: BG-71442 --- modules/bitgo/package.json | 1 - .../test/v2/fixtures/trading/affirmation.ts | 142 ------ .../bitgo/test/v2/fixtures/trading/payload.ts | 66 --- .../test/v2/fixtures/trading/settlement.ts | 441 ------------------ .../v2/fixtures/trading/tradingPartner.ts | 40 -- .../bitgo/test/v2/unit/trading/affirmation.ts | 139 ------ modules/bitgo/test/v2/unit/trading/payload.ts | 166 ------- .../bitgo/test/v2/unit/trading/settlement.ts | 248 ---------- .../test/v2/unit/trading/tradingAccount.ts | 62 --- .../test/v2/unit/trading/tradingPartner.ts | 109 ----- .../src/bitgo/enterprise/enterprise.ts | 15 - .../src/bitgo/enterprise/iEnterprise.ts | 4 - .../sdk-core/src/bitgo/trading/affirmation.ts | 74 --- .../src/bitgo/trading/affirmations.ts | 57 --- .../src/bitgo/trading/iAffirmation.ts | 16 - .../src/bitgo/trading/iAffirmations.ts | 11 - .../sdk-core/src/bitgo/trading/iSettlement.ts | 27 -- .../src/bitgo/trading/iSettlements.ts | 21 - .../src/bitgo/trading/iTradingAccount.ts | 37 -- .../src/bitgo/trading/iTradingPartner.ts | 16 - .../src/bitgo/trading/iTradingPartners.ts | 17 - modules/sdk-core/src/bitgo/trading/index.ts | 15 - modules/sdk-core/src/bitgo/trading/lock.ts | 16 - modules/sdk-core/src/bitgo/trading/payload.ts | 23 - .../sdk-core/src/bitgo/trading/settlement.ts | 37 -- .../sdk-core/src/bitgo/trading/settlements.ts | 80 ---- modules/sdk-core/src/bitgo/trading/trade.ts | 29 -- .../src/bitgo/trading/tradingAccount.ts | 136 +----- .../src/bitgo/trading/tradingPartner.ts | 52 --- .../src/bitgo/trading/tradingPartners.ts | 46 -- 30 files changed, 2 insertions(+), 2141 deletions(-) delete mode 100644 modules/bitgo/test/v2/fixtures/trading/affirmation.ts delete mode 100644 modules/bitgo/test/v2/fixtures/trading/payload.ts delete mode 100644 modules/bitgo/test/v2/fixtures/trading/settlement.ts delete mode 100644 modules/bitgo/test/v2/fixtures/trading/tradingPartner.ts delete mode 100644 modules/bitgo/test/v2/unit/trading/affirmation.ts delete mode 100644 modules/bitgo/test/v2/unit/trading/payload.ts delete mode 100644 modules/bitgo/test/v2/unit/trading/settlement.ts delete mode 100644 modules/bitgo/test/v2/unit/trading/tradingAccount.ts delete mode 100644 modules/bitgo/test/v2/unit/trading/tradingPartner.ts delete mode 100644 modules/sdk-core/src/bitgo/trading/affirmation.ts delete mode 100644 modules/sdk-core/src/bitgo/trading/affirmations.ts delete mode 100644 modules/sdk-core/src/bitgo/trading/iAffirmation.ts delete mode 100644 modules/sdk-core/src/bitgo/trading/iAffirmations.ts delete mode 100644 modules/sdk-core/src/bitgo/trading/iSettlement.ts delete mode 100644 modules/sdk-core/src/bitgo/trading/iSettlements.ts delete mode 100644 modules/sdk-core/src/bitgo/trading/iTradingPartner.ts delete mode 100644 modules/sdk-core/src/bitgo/trading/iTradingPartners.ts delete mode 100644 modules/sdk-core/src/bitgo/trading/lock.ts delete mode 100644 modules/sdk-core/src/bitgo/trading/payload.ts delete mode 100644 modules/sdk-core/src/bitgo/trading/settlement.ts delete mode 100644 modules/sdk-core/src/bitgo/trading/settlements.ts delete mode 100644 modules/sdk-core/src/bitgo/trading/trade.ts delete mode 100644 modules/sdk-core/src/bitgo/trading/tradingPartner.ts delete mode 100644 modules/sdk-core/src/bitgo/trading/tradingPartners.ts diff --git a/modules/bitgo/package.json b/modules/bitgo/package.json index 7510a587e6..d0436fd1c7 100644 --- a/modules/bitgo/package.json +++ b/modules/bitgo/package.json @@ -104,7 +104,6 @@ "@types/bluebird": "^3.5.25", "@types/superagent": "^4.1.3", "bignumber.js": "^9.1.1", - "bitcoinjs-message": "npm:@bitgo-forks/bitcoinjs-message@1.0.0-master.2", "bluebird": "^3.5.3", "fs-extra": "^9.1.0", "lodash": "^4.17.14", diff --git a/modules/bitgo/test/v2/fixtures/trading/affirmation.ts b/modules/bitgo/test/v2/fixtures/trading/affirmation.ts deleted file mode 100644 index 9d300f0672..0000000000 --- a/modules/bitgo/test/v2/fixtures/trading/affirmation.ts +++ /dev/null @@ -1,142 +0,0 @@ -import { AffirmationStatus } from '@bitgo/sdk-core'; - -export default { - listAffirmations: { - affirmations: [ - { - id: '8c25d5e9-ec3e-41d4-9c5e-b517f9e6c2a9', - partyAccountId: '5cf940969449412d00f53b4c55fc2139', - status: 'affirmed', - settlement: 'e19f3371-46dd-4e0a-9817-253060c1f610', - lock: { - id: '07eb3e5c-453f-4d4b-bff0-7defb1a7fa25', - accountId: '5cf940969449412d00f53b4c55fc2139', - status: 'settled', - amount: '43144', - currency: 'ofctbtc', - createdAt: '2019-06-06T22:45:09.988Z', - }, - payload: - '{"walletId":"5cf940969449412d00f53b4c55fc2139","currency":"ofctbtc","amount":"43144","nonceHold":"AVGynQTfZb8V4WlK7RRqaQ==","nonceSettle":"QlOA+ob2U5JFsV27pNVYDg==","otherParties":["5cf9976f6280263a00fe911648fc2d6d"]}', - signature: - '203075f08e6295853cf2c40974f0d813b19abd1eff65a4c77950dea50f2dbaf5904baacd1e97b42f4f4d4621cc1034198a34ee903e4e00c6ae5899a51f3a1f7a33', - createdAt: '2019-06-06T22:45:10.114Z', - expireAt: '2019-06-07T22:45:10.105Z', - }, - { - id: 'c22bfbed-9a16-4319-b26c-f15caaf80cc2', - partyAccountId: '5cf940969449412d00f53b4c55fc2139', - status: 'rejected', - settlement: '6804c586-d65a-40b9-a2b3-66352ec4b964', - lock: { - id: '68c1d408-87cf-4c30-91cb-a9271c9526d7', - accountId: '5cf940969449412d00f53b4c55fc2139', - status: 'released', - amount: '62369', - currency: 'ofctbtc', - createdAt: '2019-06-06T22:45:20.352Z', - }, - payload: - '{"walletId":"5cf940969449412d00f53b4c55fc2139","currency":"ofctbtc","amount":"62369","nonceHold":"7D5LPdn2/dW6hVXCtQKjiw==","nonceSettle":"DZX72/xWxjloNmGjies4tw==","otherParties":["5cf9976f6280263a00fe911648fc2d6d"]}', - createdAt: '2019-06-06T22:45:20.433Z', - expireAt: '2019-06-07T22:45:20.426Z', - }, - { - id: 'a89bb2f8-a927-4fea-aa1c-cf2846765bec', - partyAccountId: '5cf9976f6280263a00fe911648fc2d6d', - status: 'canceled', - settlement: 'abc84f76-4b6e-4a1b-9867-e213de2c2b45', - lock: { - id: '0e1f2742-e446-4572-ac7d-8b0a3b16169b', - accountId: '5cf9976f6280263a00fe911648fc2d6d', - status: 'released', - amount: '94386', - currency: 'ofctusd', - createdAt: '2019-06-06T22:45:28.794Z', - }, - payload: - '{"walletId":"5cf9976f6280263a00fe911648fc2d6d","currency":"ofctusd","amount":"94386","nonceHold":"Y/MzgFBTR5jw3qIKj9kpHw==","nonceSettle":"L6U3HmJQhvdHeyheramwiw==","otherParties":["5cf940969449412d00f53b4c55fc2139"]}', - signature: - '1f6489c0443bf28094b960f20ab44cfcd8b30df3211c9b958cd0a6c9ddd9eb2e9d7b32d3c12f13a9ea51f277db9f9fd5d719fd219e09c5de34fc4d5de098948ae9', - createdAt: '2019-06-06T22:45:28.864Z', - expireAt: '2019-06-07T22:45:28.860Z', - }, - ], - }, - listOverdueAffirmations: { - affirmations: [ - { - id: 'c22bfbed-9a16-4319-b26c-f15caaf80cc2', - partyAccountId: '5cf940969449412d00f53b4c55fc2139', - status: 'overdue', - settlement: '6804c586-d65a-40b9-a2b3-66352ec4b964', - lock: { - id: '68c1d408-87cf-4c30-91cb-a9271c9526d7', - accountId: '5cf940969449412d00f53b4c55fc2139', - status: 'released', - amount: '62369', - currency: 'ofctbtc', - createdAt: '2019-06-06T22:45:20.352Z', - }, - payload: - '{"walletId":"5cf940969449412d00f53b4c55fc2139","currency":"ofctbtc","amount":"62369","nonceHold":"7D5LPdn2/dW6hVXCtQKjiw==","nonceSettle":"DZX72/xWxjloNmGjies4tw==","otherParties":["5cf9976f6280263a00fe911648fc2d6d"]}', - createdAt: '2019-06-06T22:45:20.433Z', - expireAt: '2019-06-07T22:45:20.426Z', - }, - ], - }, - singleAffirmation: { - id: '8c25d5e9-ec3e-41d4-9c5e-b517f9e6c2a9', - partyAccountId: '5cf940969449412d00f53b4c55fc2139', - status: 'affirmed', - settlement: 'e19f3371-46dd-4e0a-9817-253060c1f610', - lock: { - id: '07eb3e5c-453f-4d4b-bff0-7defb1a7fa25', - accountId: '5cf940969449412d00f53b4c55fc2139', - status: 'settled', - amount: '43144', - currency: 'ofctbtc', - createdAt: '2019-06-06T22:45:09.988Z', - }, - payload: - '{"walletId":"5cf940969449412d00f53b4c55fc2139","currency":"ofctbtc","amount":"43144","nonceHold":"AVGynQTfZb8V4WlK7RRqaQ==","nonceSettle":"QlOA+ob2U5JFsV27pNVYDg==","otherParties":["5cf9976f6280263a00fe911648fc2d6d"]}', - signature: - '203075f08e6295853cf2c40974f0d813b19abd1eff65a4c77950dea50f2dbaf5904baacd1e97b42f4f4d4621cc1034198a34ee903e4e00c6ae5899a51f3a1f7a33', - createdAt: '2019-06-06T22:45:10.114Z', - expireAt: '2019-06-07T22:45:10.105Z', - }, - affirmAffirmationPayloadRequest: { - version: '1.2.0', - amounts: [ - { - accountId: '5cf940a49449412d00f53b8f7392f7c0', - sendAmount: '500', - sendCurrency: 'ofctbtc', - receiveAmount: '555', - receiveCurrency: 'ofctusd', - }, - { - accountId: '5cf940969449412d00f53b4c55fc2139', - sendAmount: '555', - sendCurrency: 'ofctusd', - receiveAmount: '500', - receiveCurrency: 'ofctbtc', - }, - ], - }, - affirmAffirmationPayloadResponse: { - payload: - '{"version":"1.1.1","accountId":"5cf940969449412d00f53b4c55fc2139","nonceHold":"djTPc0eRtQixTviodw1iJQ==","nonceSettle":"Wemw9X+iFcwsRFV3nJebxA==","amounts":[{"accountId":"5cf940a49449412d00f53b8f7392f7c0","sendCurrency":"ofctbtc","sendSubtotal":"500","sendAmount":"500","receiveCurrency":"ofctusd","receiveAmount":"555"},{"accountId":"5cf940969449412d00f53b4c55fc2139","sendCurrency":"ofctusd","sendSubtotal":"555","sendAmount":"555","receiveCurrency":"ofctbtc","receiveAmount":"500"}]}', - }, - updateAffirmation: function (status) { - // @ts-expect-error - 'status' is specified more than once, so this usage will be overwritten. - const affirmation = { status, ...this.singleAffirmation }; - if (status !== AffirmationStatus.AFFIRMED) { - // @ts-expect-error - The operand of a 'delete' operator must be optional. - delete affirmation.payload; - // @ts-expect-error - The operand of a 'delete' operator must be optional. - delete affirmation.signature; - } - return affirmation; - }, -}; diff --git a/modules/bitgo/test/v2/fixtures/trading/payload.ts b/modules/bitgo/test/v2/fixtures/trading/payload.ts deleted file mode 100644 index eff6c799b0..0000000000 --- a/modules/bitgo/test/v2/fixtures/trading/payload.ts +++ /dev/null @@ -1,66 +0,0 @@ -export default { - validPayloadWithFees: { - payload: JSON.stringify({ - version: '1.2.0', - accountId: 'walletId', - nonceHold: 'bfrE8itPwYZB+ofDhblE6g==', - nonceSettle: 'EymF2LXnRzn8acbcCFwgUA==', - amounts: [ - { - accountId: 'walletId', - sendCurrency: 'ofctbtc', - sendSubtotal: '100000000', - sendAmount: '100500000', - receiveCurrency: 'ofctusd', - receiveAmount: '90000', - fees: [ - { - feeType: 'SETTLEMENT_FEE', - feeAmount: '500000', - }, - ], - }, - { - accountId: 'counterparty_account_id', - sendCurrency: 'ofctusd', - sendSubtotal: '90000', - sendAmount: '90000', - receiveCurrency: 'ofctbtc', - receiveAmount: '100000000', - }, - ], - }), - }, - invalidPayload: { - payload: JSON.stringify({ - version: '1.2.0', - accountId: 'walletId', - nonceHold: 'bfrE8itPwYZB+ofDhblE6g==', - nonceSettle: 'EymF2LXnRzn8acbcCFwgUA==', - amounts: [ - { - accountId: 'walletId', - sendCurrency: 'ofctbtc', - sendSubtotal: '100000010', - fees: [ - { - feeType: 'SETTLEMENT_FEE', - feeAmount: '500000', - }, - ], - sendAmount: '100000000', - receiveCurrency: 'ofctusd', - receiveAmount: '90000', - }, - { - accountId: 'counterparty_account_id', - sendCurrency: 'ofctusd', - sendSubtotal: '90000', - sendAmount: '90000', - receiveCurrency: 'ofctbtc', - receiveAmount: '100000000', - }, - ], - }), - }, -}; diff --git a/modules/bitgo/test/v2/fixtures/trading/settlement.ts b/modules/bitgo/test/v2/fixtures/trading/settlement.ts deleted file mode 100644 index 89d4e57213..0000000000 --- a/modules/bitgo/test/v2/fixtures/trading/settlement.ts +++ /dev/null @@ -1,441 +0,0 @@ -export default { - listSettlements: { - settlements: [ - { - id: 'fbbb8da8-e7a3-4d9e-82a3-fc396abf9890', - requesterAccountId: '5cf940969449412d00f53b4c55fc2139', - status: 'pending', - type: 'direct', - affirmations: [ - { - id: 'f8259b32-6407-4c42-a48d-7519e7d1905f', - partyAccountId: '5cf940969449412d00f53b4c55fc2139', - status: 'affirmed', - settlement: 'fbbb8da8-e7a3-4d9e-82a3-fc396abf9890', - lock: { - id: '82d2c6f7-5e09-4dc6-8847-cf862f519590', - accountId: '5cf940969449412d00f53b4c55fc2139', - status: 'active', - amount: '555', - currency: 'ofctusd', - createdAt: '2019-06-06T16:36:21.985Z', - }, - payload: - '{"version":"1.2.0","accountId":"5cf940969449412d00f53b4c55fc2139","amounts":[{"accountId":"5df03e088b4eb3470019a88734b69f7a","sendSubtotal":"500","sendAmount":"500","sendCurrency":"ofctbtc","receiveAmount":"555","receiveCurrency":"ofctusd"},{"accountId":"5cf940969449412d00f53b4c55fc2139","sendSubtotal":"555","sendAmount":"555","sendCurrency":"ofctusd","receiveAmount":"500","receiveCurrency":"ofctbtc"}],"nonceHold":"brJ/Ufv/v4Fg8Emap4vnIA==","nonceSettle":"fMOE8AEEGJVdXZ7143B+qQ=="}', - signature: - '2049b6cd2e2693f26415987cb14a9e14be81ddf1e3e370fe19477e7da5237835f9467e5846a4d12a7fd23e860153083938080fe1d8f78f673851e470a9e45f7e3d', - createdAt: '2019-06-06T16:36:22.062Z', - expireAt: '2019-06-07T16:36:22.057Z', - }, - { - id: 'c412e732-c4ea-4ff2-b157-403893cee47b', - partyAccountId: '5cf940a49449412d00f53b8f7392f7c0', - status: 'pending', - settlement: 'fbbb8da8-e7a3-4d9e-82a3-fc396abf9890', - lock: { - id: 'f95c2d97-3841-4aa7-b80c-1d7b31f5503c', - accountId: '5cf940a49449412d00f53b8f7392f7c0', - status: 'active', - amount: '500', - currency: 'ofctbtc', - createdAt: '2019-06-06T16:36:21.980Z', - }, - payload: - '{"version":"1.2.0","accountId":"5cf940a49449412d00f53b8f7392f7c0","amounts":[{"accountId":"5df03e088b4eb3470019a88734b69f7a","sendSubtotal":"500","sendAmount":"500","sendCurrency":"ofctbtc","receiveAmount":"555","receiveCurrency":"ofctusd"},{"accountId":"5cf940969449412d00f53b4c55fc2139","sendSubtotal":"555","sendAmount":"555","sendCurrency":"ofctusd","receiveAmount":"500","receiveCurrency":"ofctbtc"}],"nonceHold":"brJ/Ufv/v4Fg8Emap4vnIA==","nonceSettle":"fMOE8AEEGJVdXZ7143B+qQ=="}', - createdAt: '2019-06-06T16:36:22.066Z', - expireAt: '2019-06-07T16:36:22.057Z', - }, - ], - expireAt: '2019-06-07T16:36:22.057Z', - createdAt: '2019-06-06T16:36:22.058Z', - trades: [ - { - id: '027f0ff0-4e34-4824-899c-4fd33d46abc4', - externalId: 'a4o3ah601etw676okvkvsmizciorxc8v', - baseAccountId: '5cf940a49449412d00f53b8f7392f7c0', - quoteAccountId: '5cf940969449412d00f53b4c55fc2139', - timestamp: '2019-06-06T16:36:20.810Z', - status: 'executed', - baseAmount: '500', - quoteAmount: '555', - baseCurrency: 'ofctbtc', - quoteCurrency: 'ofctusd', - costBasis: '12345', - costBasisCurrency: 'USD', - }, - ], - }, - { - id: 'ff5a8c54-fb0e-481b-900c-abfaa7958a5c', - requesterAccountId: '5cf940969449412d00f53b4c55fc2139', - requesterAccountName: 'Test Enterprise', - status: 'pending', - type: 'agency', - affirmations: [ - { - id: '6f3ff2ed-a40e-4ad7-935b-eea36ec16fce', - partyAccountId: '5cf940969449412d00f53b4c55fc2139', - partyAccountName: 'Test Enterprise', - status: 'affirmed', - settlement: '', - lock: null, - payload: - '{"version":"1.2.0","accountId":"5cf940969449412d00f53b4c55fc2139","amounts":[{"accountId":"5df03e088b4eb3470019a89e37864bed","sendSubtotal":"942777","sendFee":"0","sendAmount":"942777","sendCurrency":"ofctusd","receiveAmount":"115087","receiveCurrency":"ofctbtc"},{"accountId":"5df03e088b4eb3470019a88734b69f7a","sendSubtotal":"115087","sendFee":"0","sendAmount":"115087","sendCurrency":"ofctbtc","receiveAmount":"941966","receiveCurrency":"ofctusd"}],"nonceHold":"+8ZMkylYWnLH7P6t7HvjEQ==","nonceSettle":"yZbXXOR7zkbBWSh+gS4ghA=="}', - signature: - '1f2d7c206a7ed7c345f5b2ab1446b11f9fec234ae9e93285abc20e9cdd327479f74e1e93dfdc073f0350c8e79f2e33f62ac3570c1fb423d254bf761cf5c0550271', - createdAt: '2019-12-11T00:53:52.982Z', - expireAt: '2019-12-11T02:53:52.978Z', - }, - { - id: '489c56f6-3ec2-49fe-87eb-95c8f66a3ad5', - counterpartyAccountId: '5cf940969449412d00f53b4c55fc2139', - counterpartyName: 'Test Enterprise', - partyAccountId: '5df03e088b4eb3470019a88734b69f7a', - partyAccountName: 'TESTINGE2E 5wbdfxt0a3j1t569baiw3ou2ukby1aug', - status: 'pending', - settlement: '', - lock: null, - payload: - '{"version":"1.2.0","accountId":"5df03e088b4eb3470019a88734b69f7a","amounts":[{"accountId":"5df03e088b4eb3470019a88734b69f7a","sendSubtotal":"115087","sendAmount":"115087","sendCurrency":"ofctbtc","receiveAmount":"941966","receiveCurrency":"ofctusd"},{"accountId":"5cf940969449412d00f53b4c55fc2139","sendSubtotal":"941966","sendAmount":"941966","sendCurrency":"ofctusd","receiveAmount":"115087","receiveCurrency":"ofctbtc"}],"nonceHold":"14qL7T1aLkaRDBSrgMNtbg==","nonceSettle":"RGPKwiin9rO1iISJG8AqvQ=="}', - signature: '', - createdAt: '2019-12-11T00:53:52.988Z', - expireAt: '2019-12-11T02:53:52.978Z', - }, - { - id: '7c8c3f11-9b52-4f64-9d55-98c5add9972c', - counterpartyAccountId: '5cf940969449412d00f53b4c55fc2139', - counterpartyName: 'Test Enterprise', - partyAccountId: '5df03e088b4eb3470019a89e37864bed', - partyAccountName: 'TESTINGE2E qlzyrvn6hjum72ovetm9ahd069gt7wi8', - status: 'pending', - settlement: '', - lock: null, - payload: - '{"version":"1.2.0","accountId":"5df03e088b4eb3470019a89e37864bed","amounts":[{"accountId":"5df03e088b4eb3470019a89e37864bed","sendSubtotal":"942777","sendFee":"0","sendAmount":"942777","sendCurrency":"ofctusd","receiveAmount":"115087","receiveCurrency":"ofctbtc"},{"accountId":"5cf940969449412d00f53b4c55fc2139","sendSubtotal":"115087","sendFee":"0","sendAmount":"115087","sendCurrency":"ofctbtc","receiveAmount":"942777","receiveCurrency":"ofctusd"}],"nonceHold":"Tz4pGR5beaUKI1/qNsEuHw==","nonceSettle":"XFWVbytujspmE6CiEBbnTA=="}', - signature: '', - createdAt: '2019-12-11T00:53:52.992Z', - expireAt: '2019-12-11T02:53:52.978Z', - }, - ], - expireAt: '2019-12-11T02:53:52.978Z', - createdAt: '2019-12-11T00:53:52.979Z', - trades: [ - { - id: 'a37c5c9a-efc0-4b2c-89e0-39538de86b29', - baseAccountId: '5df03e088b4eb3470019a88734b69f7a', - quoteAccountId: '5df03e088b4eb3470019a89e37864bed', - status: 'executed', - timestamp: '2019-12-11T00:53:52.814Z', - baseAmount: '115087', - quoteAmount: '942777', - baseCurrency: 'ofctbtc', - quoteCurrency: 'ofctusd', - baseReceiveAmount: '941966', - quoteReceiveAmount: '115087', - baseReceiveCurrency: 'ofctusd', - quoteReceiveCurrency: 'ofctbtc', - costBasis: '', - costBasisCurrency: '', - externalId: 'xff7vln0eh9hh3rp0derlbunlo1sw6k6', - }, - ], - }, - ], - }, - singleSettlementId: 'fbbb8da8-e7a3-4d9e-82a3-fc396abf9890', - getSingleSettlement: { - id: 'fbbb8da8-e7a3-4d9e-82a3-fc396abf9890', - requesterAccountId: '5cf940969449412d00f53b4c55fc2139', - status: 'pending', - type: 'direct', - affirmations: [ - { - id: 'f8259b32-6407-4c42-a48d-7519e7d1905f', - partyAccountId: '5cf940969449412d00f53b4c55fc2139', - status: 'affirmed', - settlement: 'fbbb8da8-e7a3-4d9e-82a3-fc396abf9890', - lock: { - id: '82d2c6f7-5e09-4dc6-8847-cf862f519590', - accountId: '5cf940969449412d00f53b4c55fc2139', - status: 'active', - amount: '555', - currency: 'ofctusd', - createdAt: '2019-06-06T16:36:21.985Z', - }, - payload: - '{"version":"1.2.0","accountId":"5cf940969449412d00f53b4c55fc2139","amounts":[{"accountId":"5df03e088b4eb3470019a88734b69f7a","sendSubtotal":"500","sendAmount":"500","sendCurrency":"ofctbtc","receiveAmount":"555","receiveCurrency":"ofctusd"},{"accountId":"5cf940969449412d00f53b4c55fc2139","sendSubtotal":"555","sendAmount":"555","sendCurrency":"ofctusd","receiveAmount":"500","receiveCurrency":"ofctbtc"}],"nonceHold":"brJ/Ufv/v4Fg8Emap4vnIA==","nonceSettle":"fMOE8AEEGJVdXZ7143B+qQ=="}', - signature: - '2049b6cd2e2693f26415987cb14a9e14be81ddf1e3e370fe19477e7da5237835f9467e5846a4d12a7fd23e860153083938080fe1d8f78f673851e470a9e45f7e3d', - createdAt: '2019-06-06T16:36:22.062Z', - expireAt: '2019-06-07T16:36:22.057Z', - }, - { - id: 'c412e732-c4ea-4ff2-b157-403893cee47b', - partyAccountId: '5cf940a49449412d00f53b8f7392f7c0', - status: 'pending', - settlement: 'fbbb8da8-e7a3-4d9e-82a3-fc396abf9890', - lock: { - id: 'f95c2d97-3841-4aa7-b80c-1d7b31f5503c', - accountId: '5cf940a49449412d00f53b8f7392f7c0', - status: 'active', - amount: '500', - currency: 'ofctbtc', - createdAt: '2019-06-06T16:36:21.980Z', - }, - payload: - '{"version":"1.2.0","accountId":"5cf940a49449412d00f53b8f7392f7c0","amounts":[{"accountId":"5df03e088b4eb3470019a88734b69f7a","sendSubtotal":"500","sendAmount":"500","sendCurrency":"ofctbtc","receiveAmount":"555","receiveCurrency":"ofctusd"},{"accountId":"5cf940969449412d00f53b4c55fc2139","sendSubtotal":"555","sendAmount":"555","sendCurrency":"ofctusd","receiveAmount":"500","receiveCurrency":"ofctbtc"}],"nonceHold":"brJ/Ufv/v4Fg8Emap4vnIA==","nonceSettle":"fMOE8AEEGJVdXZ7143B+qQ=="}', - createdAt: '2019-06-06T16:36:22.066Z', - expireAt: '2019-06-07T16:36:22.057Z', - }, - ], - expireAt: '2019-06-07T16:36:22.057Z', - createdAt: '2019-06-06T16:36:22.058Z', - trades: [ - { - id: '027f0ff0-4e34-4824-899c-4fd33d46abc4', - externalId: 'a4o3ah601etw676okvkvsmizciorxc8v', - baseAccountId: '5cf940a49449412d00f53b8f7392f7c0', - quoteAccountId: '5cf940969449412d00f53b4c55fc2139', - timestamp: '2019-06-06T16:36:20.810Z', - status: 'executed', - baseAmount: '500', - quoteAmount: '555', - baseCurrency: 'ofctbtc', - quoteCurrency: 'ofctusd', - costBasis: '12345', - costBasisCurrency: 'USD', - }, - ], - }, - createDirectSettlementPayloadRequest: { - version: '1.2.0', - amounts: [ - { - accountId: '5cf940a49449412d00f53b8f7392f7c0', - sendAmount: '500', - sendCurrency: 'ofctbtc', - receiveAmount: '555', - receiveCurrency: 'ofctusd', - }, - { - accountId: '5cf940969449412d00f53b4c55fc2139', - sendAmount: '555', - sendCurrency: 'ofctusd', - receiveAmount: '500', - receiveCurrency: 'ofctbtc', - }, - ], - }, - createDirectSettlementPayloadResponse: { - payload: - '{"version":"1.2.0","accountId":"5cf940969449412d00f53b4c55fc2139","nonceHold":"djTPc0eRtQixTviodw1iJQ==","nonceSettle":"Wemw9X+iFcwsRFV3nJebxA==","amounts":[{"accountId":"5cf940a49449412d00f53b8f7392f7c0","sendCurrency":"ofctbtc","sendSubtotal":"500","sendAmount":"500","receiveCurrency":"ofctusd","receiveAmount":"555"},{"accountId":"5cf940969449412d00f53b4c55fc2139","sendCurrency":"ofctusd","sendSubtotal":"555","sendAmount":"555","receiveCurrency":"ofctbtc","receiveAmount":"500"}]}', - }, - createDirectSettlementRequest: { - requesterAccountId: '5cf940969449412d00f53b4c55fc2139', - payload: /{.*}/, - signature: /[0-9a-fA-F]*/, - trades: [ - { - baseAccountId: '5cf940a49449412d00f53b8f7392f7c0', - quoteAccountId: '5cf940969449412d00f53b4c55fc2139', - status: 'executed', - timestamp: '2019-06-06T16:36:20.810Z', - baseAmount: '500', - baseCurrency: 'ofctbtc', - quoteAmount: '555', - quoteCurrency: 'ofctusd', - costBasis: '12345', - costBasisCurrency: 'USD', - externalId: 'a4o3ah601etw676okvkvsmizciorxc8v', - }, - ], - }, - createDirectSettlementResponse: { - id: 'fbbb8da8-e7a3-4d9e-82a3-fc396abf9890', - requesterAccountId: '5cf940969449412d00f53b4c55fc2139', - status: 'pending', - type: 'direct', - affirmations: [ - { - id: 'c412e732-c4ea-4ff2-b157-403893cee47b', - partyAccountId: '5cf940a49449412d00f53b8f7392f7c0', - status: 'pending', - settlement: 'fbbb8da8-e7a3-4d9e-82a3-fc396abf9890', - lock: { - id: 'f95c2d97-3841-4aa7-b80c-1d7b31f5503c', - accountId: '5cf940a49449412d00f53b8f7392f7c0', - status: 'active', - amount: '500', - currency: 'ofctbtc', - createdAt: '2019-06-06T16:36:21.980Z', - }, - payload: - '{"version":"1.2.0","accountId":"5cf940a49449412d00f53b8f7392f7c0","amounts":[{"accountId":"5df03e088b4eb3470019a88734b69f7a","sendSubtotal":"500","sendAmount":"500","sendCurrency":"ofctbtc","receiveAmount":"555","receiveCurrency":"ofctusd"},{"accountId":"5cf940969449412d00f53b4c55fc2139","sendSubtotal":"555","sendAmount":"555","sendCurrency":"ofctusd","receiveAmount":"500","receiveCurrency":"ofctbtc"}],"nonceHold":"brJ/Ufv/v4Fg8Emap4vnIA==","nonceSettle":"fMOE8AEEGJVdXZ7143B+qQ=="}', - createdAt: '2019-06-06T16:36:22.066Z', - expireAt: '2019-06-07T16:36:22.057Z', - }, - { - id: 'f8259b32-6407-4c42-a48d-7519e7d1905f', - partyAccountId: '5cf940969449412d00f53b4c55fc2139', - status: 'affirmed', - settlement: 'fbbb8da8-e7a3-4d9e-82a3-fc396abf9890', - lock: { - id: '82d2c6f7-5e09-4dc6-8847-cf862f519590', - accountId: '5cf940969449412d00f53b4c55fc2139', - status: 'active', - amount: '555', - currency: 'ofctusd', - createdAt: '2019-06-06T16:36:21.985Z', - }, - payload: - '{"version":"1.2.0","accountId":"5cf940969449412d00f53b4c55fc2139","amounts":[{"accountId":"5df03e088b4eb3470019a88734b69f7a","sendSubtotal":"500","sendAmount":"500","sendCurrency":"ofctbtc","receiveAmount":"555","receiveCurrency":"ofctusd"},{"accountId":"5cf940969449412d00f53b4c55fc2139","sendSubtotal":"555","sendAmount":"555","sendCurrency":"ofctusd","receiveAmount":"500","receiveCurrency":"ofctbtc"}],"nonceHold":"brJ/Ufv/v4Fg8Emap4vnIA==","nonceSettle":"fMOE8AEEGJVdXZ7143B+qQ=="}', - signature: - '2049b6cd2e2693f26415987cb14a9e14be81ddf1e3e370fe19477e7da5237835f9467e5846a4d12a7fd23e860153083938080fe1d8f78f673851e470a9e45f7e3d', - createdAt: '2019-06-06T16:36:22.062Z', - expireAt: '2019-06-07T16:36:22.057Z', - }, - ], - expireAt: '2019-06-07T16:36:22.057Z', - createdAt: '2019-06-06T16:36:22.058Z', - trades: [ - { - id: '027f0ff0-4e34-4824-899c-4fd33d46abc4', - externalId: 'a4o3ah601etw676okvkvsmizciorxc8v', - baseAccountId: '5cf940a49449412d00f53b8f7392f7c0', - quoteAccountId: '5cf940969449412d00f53b4c55fc2139', - timestamp: '2019-06-06T16:36:20.810Z', - status: 'executed', - baseAmount: '500', - quoteAmount: '555', - baseCurrency: 'ofctbtc', - quoteCurrency: 'ofctusd', - costBasis: '12345', - costBasisCurrency: 'USD', - }, - ], - }, - - createAgencySettlementPayloadRequest: { - version: '1.2.0', - amounts: [ - { - accountId: '5df03e088b4eb3470019a89e37864bed', - sendAmount: '942777', - sendCurrency: 'ofctusd', - receiveAmount: '115087', - receiveCurrency: 'ofctbtc', - }, - { - accountId: '5df03e088b4eb3470019a88734b69f7a', - sendAmount: '115087', - sendCurrency: 'ofctbtc', - receiveAmount: '941966', - receiveCurrency: 'ofctusd', - }, - ], - }, - createAgencySettlementPayloadResponse: { - payload: - '{"version":"1.2.0","accountId":"5cf940969449412d00f53b4c55fc2139","amounts":[{"accountId":"5df03e088b4eb3470019a89e37864bed","sendSubtotal":"942777","sendFee":"0","sendAmount":"942777","sendCurrency":"ofctusd","receiveAmount":"115087","receiveCurrency":"ofctbtc"},{"accountId":"5df03e088b4eb3470019a88734b69f7a","sendSubtotal":"115087","sendFee":"0","sendAmount":"115087","sendCurrency":"ofctbtc","receiveAmount":"941966","receiveCurrency":"ofctusd"}],"nonceHold":"+8ZMkylYWnLH7P6t7HvjEQ==","nonceSettle":"yZbXXOR7zkbBWSh+gS4ghA=="}', - }, - createAgencySettlementRequest: { - requesterAccountId: '5cf940969449412d00f53b4c55fc2139', - payload: /{.*}/, - signature: /[0-9a-fA-F]*/, - trades: [ - { - id: 'a37c5c9a-efc0-4b2c-89e0-39538de86b29', - baseAccountId: '5df03e088b4eb3470019a88734b69f7a', - quoteAccountId: '5df03e088b4eb3470019a89e37864bed', - status: 'executed', - timestamp: '2019-12-11T00:53:52.814Z', - baseAmount: '115087', - quoteAmount: '942777', - baseCurrency: 'ofctbtc', - quoteCurrency: 'ofctusd', - baseReceiveAmount: '941966', - quoteReceiveAmount: '115087', - baseReceiveCurrency: 'ofctusd', - quoteReceiveCurrency: 'ofctbtc', - costBasis: '', - costBasisCurrency: '', - externalId: 'xff7vln0eh9hh3rp0derlbunlo1sw6k6', - }, - ], - }, - createAgencySettlementResponse: { - id: 'ff5a8c54-fb0e-481b-900c-abfaa7958a5c', - requesterAccountId: '5cf940969449412d00f53b4c55fc2139', - requesterAccountName: 'Test Enterprise', - status: 'pending', - type: 'agency', - affirmations: [ - { - id: '6f3ff2ed-a40e-4ad7-935b-eea36ec16fce', - partyAccountId: '5cf940969449412d00f53b4c55fc2139', - partyAccountName: 'Test Enterprise', - status: 'affirmed', - settlement: '', - lock: null, - payload: - '{"version":"1.2.0","accountId":"5cf940969449412d00f53b4c55fc2139","amounts":[{"accountId":"5df03e088b4eb3470019a89e37864bed","sendSubtotal":"942777","sendFee":"0","sendAmount":"942777","sendCurrency":"ofctusd","receiveAmount":"115087","receiveCurrency":"ofctbtc"},{"accountId":"5df03e088b4eb3470019a88734b69f7a","sendSubtotal":"115087","sendFee":"0","sendAmount":"115087","sendCurrency":"ofctbtc","receiveAmount":"941966","receiveCurrency":"ofctusd"}],"nonceHold":"+8ZMkylYWnLH7P6t7HvjEQ==","nonceSettle":"yZbXXOR7zkbBWSh+gS4ghA=="}', - signature: - '1f2d7c206a7ed7c345f5b2ab1446b11f9fec234ae9e93285abc20e9cdd327479f74e1e93dfdc073f0350c8e79f2e33f62ac3570c1fb423d254bf761cf5c0550271', - createdAt: '2019-12-11T00:53:52.982Z', - expireAt: '2019-12-11T02:53:52.978Z', - }, - { - id: '489c56f6-3ec2-49fe-87eb-95c8f66a3ad5', - counterpartyAccountId: '5cf940969449412d00f53b4c55fc2139', - counterpartyName: 'Test Enterprise', - partyAccountId: '5df03e088b4eb3470019a88734b69f7a', - partyAccountName: 'TESTINGE2E 5wbdfxt0a3j1t569baiw3ou2ukby1aug', - status: 'pending', - settlement: '', - lock: null, - payload: - '{"version":"1.2.0","accountId":"5df03e088b4eb3470019a88734b69f7a","amounts":[{"accountId":"5df03e088b4eb3470019a88734b69f7a","sendSubtotal":"115087","sendAmount":"115087","sendCurrency":"ofctbtc","receiveAmount":"941966","receiveCurrency":"ofctusd"},{"accountId":"5cf940969449412d00f53b4c55fc2139","sendSubtotal":"941966","sendAmount":"941966","sendCurrency":"ofctusd","receiveAmount":"115087","receiveCurrency":"ofctbtc"}],"nonceHold":"14qL7T1aLkaRDBSrgMNtbg==","nonceSettle":"RGPKwiin9rO1iISJG8AqvQ=="}', - signature: '', - createdAt: '2019-12-11T00:53:52.988Z', - expireAt: '2019-12-11T02:53:52.978Z', - }, - { - id: '7c8c3f11-9b52-4f64-9d55-98c5add9972c', - counterpartyAccountId: '5cf940969449412d00f53b4c55fc2139', - counterpartyName: 'Test Enterprise', - partyAccountId: '5df03e088b4eb3470019a89e37864bed', - partyAccountName: 'TESTINGE2E qlzyrvn6hjum72ovetm9ahd069gt7wi8', - status: 'pending', - settlement: '', - lock: null, - payload: - '{"version":"1.2.0","accountId":"5df03e088b4eb3470019a89e37864bed","amounts":[{"accountId":"5df03e088b4eb3470019a89e37864bed","sendSubtotal":"942777","sendFee":"0","sendAmount":"942777","sendCurrency":"ofctusd","receiveAmount":"115087","receiveCurrency":"ofctbtc"},{"accountId":"5cf940969449412d00f53b4c55fc2139","sendSubtotal":"115087","sendFee":"0","sendAmount":"115087","sendCurrency":"ofctbtc","receiveAmount":"942777","receiveCurrency":"ofctusd"}],"nonceHold":"Tz4pGR5beaUKI1/qNsEuHw==","nonceSettle":"XFWVbytujspmE6CiEBbnTA=="}', - signature: '', - createdAt: '2019-12-11T00:53:52.992Z', - expireAt: '2019-12-11T02:53:52.978Z', - }, - ], - expireAt: '2019-12-11T02:53:52.978Z', - createdAt: '2019-12-11T00:53:52.979Z', - trades: [ - { - id: 'a37c5c9a-efc0-4b2c-89e0-39538de86b29', - baseAccountId: '5df03e088b4eb3470019a88734b69f7a', - quoteAccountId: '5df03e088b4eb3470019a89e37864bed', - status: 'executed', - timestamp: '2019-12-11T00:53:52.814Z', - baseAmount: '115087', - quoteAmount: '942777', - baseCurrency: 'ofctbtc', - quoteCurrency: 'ofctusd', - baseReceiveAmount: '941966', - quoteReceiveAmount: '115087', - baseReceiveCurrency: 'ofctusd', - quoteReceiveCurrency: 'ofctbtc', - costBasis: '', - costBasisCurrency: '', - externalId: 'xff7vln0eh9hh3rp0derlbunlo1sw6k6', - }, - ], - }, -}; diff --git a/modules/bitgo/test/v2/fixtures/trading/tradingPartner.ts b/modules/bitgo/test/v2/fixtures/trading/tradingPartner.ts deleted file mode 100644 index 71a514e5b9..0000000000 --- a/modules/bitgo/test/v2/fixtures/trading/tradingPartner.ts +++ /dev/null @@ -1,40 +0,0 @@ -export default { - listTradingPartners: { - tradingPartners: [ - { - id: '6e30a6e7-c073-46fb-a03f-ca8578688d1d', - primaryEnterpriseName: 'Test Enterprise', - primaryAccountId: '5cf940969449412d00f53b4c55fc2139', - secondaryEnterpriseName: 'ja65mcgekmm5111mem6z9g9kwdp58pbw', - secondaryAccountId: '5cfa13da09357e3a00320cecaa119b26', - requesterAccountId: '5cf940969449412d00f53b4c55fc2139', - type: 'direct', - status: 'accepted', - }, - { - id: '07d06a32-d33f-458a-b5de-3dfb2df0efba', - primaryEnterpriseName: 'cugl1je9iem91gogv8h1fbqd1gau3fhk', - primaryAccountId: '5cfa13db09357e3a00320d0b75900419', - secondaryEnterpriseName: 'Test Enterprise', - secondaryAccountId: '5cf940969449412d00f53b4c55fc2139', - requesterAccountId: '5cf940969449412d00f53b4c55fc2139', - type: 'agency', - status: 'accepted', - }, - ], - }, - addByCodeResponse: { - id: '01889e6c-d12a-423a-af8d-649b63e2f7a5', - primaryEnterpriseName: 'Test Enterprise', - primaryAccountId: '5cf940969449412d00f53b4c55fc2139', - secondaryEnterpriseName: 'ja65mcgekmm5111mem6z9g9kwdp58pbw', - secondaryAccountId: '5cfa13da09357e3a00320cecaa119b26', - requesterAccountId: '5cf940969449412d00f53b4c55fc2139', - type: 'agency', - status: 'pending', - }, - balanceCheckTrueRequest: { - amount: '24128', - currency: 'ofctbtc', - }, -}; diff --git a/modules/bitgo/test/v2/unit/trading/affirmation.ts b/modules/bitgo/test/v2/unit/trading/affirmation.ts deleted file mode 100644 index 28bf029401..0000000000 --- a/modules/bitgo/test/v2/unit/trading/affirmation.ts +++ /dev/null @@ -1,139 +0,0 @@ -import * as should from 'should'; -import * as nock from 'nock'; - -import fixtures from '../../fixtures/trading/affirmation'; - -import { TestBitGo } from '@bitgo/sdk-test'; -import { BitGo } from '../../../../src/bitgo'; -import { AffirmationStatus, common, Enterprise, Wallet } from '@bitgo/sdk-core'; -import { Environments } from '../../../../src'; - -describe('Affirmations', function () { - const microservicesUri = Environments['mock'].uri; - let bitgo; - let basecoin; - let enterprise; - let tradingAccount; - let bgUrl; - - let affirmation; - - before(function () { - bitgo = TestBitGo.decorate(BitGo, { env: 'mock', microservicesUri } as any); - bitgo.initializeTestVars(); - basecoin = bitgo.coin('ofc'); - basecoin.keychains(); - - enterprise = new Enterprise(bitgo, basecoin, { id: '5cf940949449412d00f53b3d92dbcaa3', name: 'Test Enterprise' }); - - const walletData = { - id: '5cf940969449412d00f53b4c55fc2139', - coin: 'tofc', - enterprise: enterprise.id, - keys: ['keyid'], - }; - - const wallet = new Wallet(bitgo, basecoin, walletData); - tradingAccount = wallet.toTradingAccount(); - bgUrl = common.Environments[bitgo.getEnv()].uri; - }); - - it('should list all affirmations', async function () { - const scope = nock(microservicesUri) - .get(`/api/trade/v1/enterprise/${enterprise.id}/affirmations`) - .reply(200, fixtures.listAffirmations); - - const affirmations = await enterprise.affirmations().list(); - - should.exist(affirmations); - affirmations.should.have.length(3); - - scope.isDone().should.be.true(); - }); - - it('should list all affirmations filtered by status', async function () { - const scope = nock(microservicesUri) - .get(`/api/trade/v1/enterprise/${enterprise.id}/affirmations?status=overdue`) - .reply(200, fixtures.listOverdueAffirmations); - - const affirmations = await enterprise.affirmations().list(AffirmationStatus.OVERDUE); - - should.exist(affirmations); - affirmations.should.have.length(1); - affirmations[0].status.should.eql(AffirmationStatus.OVERDUE); - - scope.isDone().should.be.true(); - }); - - it('should get a single affirmation', async function () { - const scope = nock(microservicesUri) - .get( - `/api/trade/v1/enterprise/${enterprise.id}/account/${tradingAccount.id}/affirmations/8c25d5e9-ec3e-41d4-9c5e-b517f9e6c2a9` - ) - .reply(200, fixtures.singleAffirmation); - - affirmation = await tradingAccount.affirmations().get({ id: '8c25d5e9-ec3e-41d4-9c5e-b517f9e6c2a9' }); - should.exist(affirmation); - - scope.isDone().should.be.true(); - }); - - it('should affirm an affirmation', async function () { - const scope = nock(microservicesUri) - .post( - `/api/trade/v1/enterprise/${enterprise.id}/account/${tradingAccount.id}/payload`, - fixtures.affirmAffirmationPayloadRequest - ) - .reply(200, fixtures.affirmAffirmationPayloadResponse) - .put( - `/api/trade/v1/enterprise/${enterprise.id}/account/${tradingAccount.id}/affirmations/${affirmation.id}`, - (body) => body.status === AffirmationStatus.AFFIRMED - ) - .reply(200, fixtures.updateAffirmation('affirmed')); - - const xprv = - 'xprv9s21ZrQH143K2MUz7uPUBVzdmvJQE6fPEQCkR3mypPbZgijPqfmGH7pjijdjeJx3oCoxPWVbjC4VYHzgN6wqEfYnnbNjK7jm2CkrvWrvkbR'; - const xpub = - 'xpub661MyMwAqRbcEqZTDvvUYdwNKx8tdZPEbd8MDSBbNj8YZX4YPD5Wpv9Da2YzLC8ZNRhundXP7mVhhu9WdJChzZJFGLQD7tyY1KGfmjuBvcX'; - const platformScope = nock(bgUrl) - .get('/api/v2/ofc/key/keyid') - .reply(200, { - pub: xpub, - encryptedPrv: bitgo.encrypt({ input: xprv, password: TestBitGo.OFC_TEST_PASSWORD }), - }); - - const payload = await tradingAccount.buildPayload(fixtures.affirmAffirmationPayloadRequest); - const signature = await tradingAccount.signPayload({ payload, walletPassphrase: TestBitGo.OFC_TEST_PASSWORD }); - - await affirmation.affirm(payload, signature); - - scope.isDone().should.be.true(); - platformScope.isDone().should.be.true(); - }); - - it('should reject an affirmation', async function () { - const scope = nock(microservicesUri) - .put( - `/api/trade/v1/enterprise/${enterprise.id}/account/${tradingAccount.id}/affirmations/${affirmation.id}`, - (body) => body.status === AffirmationStatus.REJECTED - ) - .reply(200, fixtures.updateAffirmation('rejected')); - - await affirmation.reject(); - - scope.isDone().should.be.true(); - }); - - it('should cancel an affirmation', async function () { - const scope = nock(microservicesUri) - .put( - `/api/trade/v1/enterprise/${enterprise.id}/account/${tradingAccount.id}/affirmations/${affirmation.id}`, - (body) => body.status === AffirmationStatus.CANCELED - ) - .reply(200, fixtures.updateAffirmation('canceled')); - - await affirmation.cancel(); - - scope.isDone().should.be.true(); - }); -}); diff --git a/modules/bitgo/test/v2/unit/trading/payload.ts b/modules/bitgo/test/v2/unit/trading/payload.ts deleted file mode 100644 index 9a257a58c9..0000000000 --- a/modules/bitgo/test/v2/unit/trading/payload.ts +++ /dev/null @@ -1,166 +0,0 @@ -/** - * @prettier - */ - -import { bip32 } from '@bitgo/utxo-lib'; -import * as should from 'should'; -import * as nock from 'nock'; -import * as bitcoinMessage from 'bitcoinjs-message'; - -import fixtures from '../../fixtures/trading/payload'; - -import { TestBitGo } from '@bitgo/sdk-test'; -import { BitGo } from '../../../../src/bitgo'; -import { common, Enterprise, getAddressP2PKH, Wallet } from '@bitgo/sdk-core'; - -describe('Trade Payloads', function () { - const microservicesUri = common.Environments['mock'].uri; - let bitgo; - let basecoin; - let enterprise; - let tradingAccount; - let bgUrl; - - before(function () { - bitgo = TestBitGo.decorate(BitGo, { env: 'mock', microservicesUri } as any); - bitgo.initializeTestVars(); - basecoin = bitgo.coin('ofc'); - basecoin.keychains(); - - enterprise = new Enterprise(bitgo, basecoin, { id: '5cf940949449412d00f53b3d92dbcaa3', name: 'Test Enterprise' }); - - const walletData = { - id: 'walletId', - coin: 'tofc', - enterprise: enterprise.id, - keys: ['keyid'], - }; - - const wallet = new Wallet(bitgo, basecoin, walletData); - tradingAccount = wallet.toTradingAccount(); - bgUrl = common.Environments[bitgo.getEnv()].uri; - }); - - it('should create and sign a trade payload with fees', async function () { - const xprv = - 'xprv9s21ZrQH143K2MUz7uPUBVzdmvJQE6fPEQCkR3mypPbZgijPqfmGH7pjijdjeJx3oCoxPWVbjC4VYHzgN6wqEfYnnbNjK7jm2CkrvWrvkbR'; - const xpub = - 'xpub661MyMwAqRbcEqZTDvvUYdwNKx8tdZPEbd8MDSBbNj8YZX4YPD5Wpv9Da2YzLC8ZNRhundXP7mVhhu9WdJChzZJFGLQD7tyY1KGfmjuBvcX'; - - const platformScope = nock(bgUrl) - .get('/api/v2/ofc/key/keyid') - .reply(200, { - pub: xpub, - encryptedPrv: bitgo.encrypt({ input: xprv, password: TestBitGo.OFC_TEST_PASSWORD }), - }); - - const msScope = nock(microservicesUri) - .post(`/api/trade/v1/enterprise/${enterprise.id}/account/${tradingAccount.id}/payload`) - .reply(200, fixtures.validPayloadWithFees); - - const payload = await tradingAccount.buildPayload({ - amounts: [ - { - accountId: 'walletId', - sendCurrency: 'ofctbtc', - sendAmount: '100000000', - receiveCurrency: 'ofctusd', - receiveAmount: '90000', - }, - { - accountId: 'counterparty_account_id', - sendCurrency: 'ofctusd', - sendAmount: '90000', - receiveCurrency: 'ofctbtc', - receiveAmount: '100000000', - }, - ], - }); - - should.exist(payload); - payload.should.have.property('version', '1.2.0'); - payload.should.have.property('accountId'); - payload.should.have.property('nonceHold'); - payload.should.have.property('nonceSettle'); - payload.should.have.property('amounts').with.length(2); - for (const amount of payload.amounts) { - amount.should.have.property('accountId'); - amount.should.have.property('sendCurrency'); - amount.should.have.property('sendAmount'); - amount.should.have.property('sendSubtotal'); - amount.should.have.property('receiveCurrency'); - amount.should.have.property('receiveAmount'); - if (amount.accountId === payload.accountId) { - amount.should.have.property('fees').with.length(1); - } - } - - const signature = await tradingAccount.signPayload({ - payload, - walletPassphrase: TestBitGo.OFC_TEST_PASSWORD, - }); - - // signature should be a hex string - signature.should.match(/^[0-9a-f]+$/); - - const address = getAddressP2PKH(bip32.fromBase58(xpub)); - - bitcoinMessage.verify(JSON.stringify(payload), address, Buffer.from(signature, 'hex')).should.be.True(); - - platformScope.isDone().should.be.True(); - msScope.isDone().should.be.True(); - }); - - it('should throw if the payload does not match the build parameters', async function () { - const msScope = nock(microservicesUri) - .post(`/api/trade/v1/enterprise/${enterprise.id}/account/${tradingAccount.id}/payload`) - .twice() - .reply(200, fixtures.invalidPayload); - - // no matching amount found between payload and parameters - await tradingAccount - .buildPayload({ - amounts: [ - { - accountId: 'walletId', - sendCurrency: 'ofctbtc', - sendAmount: '10000000', - receiveCurrency: 'ofctusd', - receiveAmount: '90000', - }, - { - accountId: 'counterparty_account_id', - sendCurrency: 'ofctusd', - sendAmount: '90000', - receiveCurrency: 'ofctbtc', - receiveAmount: '10000000', - }, - ], - }) - .should.be.rejected(); - - // incorrect calculation of subtotal to amount given a fee - await tradingAccount - .buildPayload({ - amounts: [ - { - accountId: 'walletId', - sendCurrency: 'ofctbtc', - sendAmount: '100000000', - receiveCurrency: 'ofctusd', - receiveAmount: '90000', - }, - { - accountId: 'counterparty_account_id', - sendCurrency: 'ofctusd', - sendAmount: '90000', - receiveCurrency: 'ofctbtc', - receiveAmount: '100000000', - }, - ], - }) - .should.be.rejected(); - - msScope.isDone().should.be.True(); - }); -}); diff --git a/modules/bitgo/test/v2/unit/trading/settlement.ts b/modules/bitgo/test/v2/unit/trading/settlement.ts deleted file mode 100644 index 00c762e206..0000000000 --- a/modules/bitgo/test/v2/unit/trading/settlement.ts +++ /dev/null @@ -1,248 +0,0 @@ -import * as should from 'should'; -import * as nock from 'nock'; - -import fixtures from '../../fixtures/trading/settlement'; - -import { TestBitGo } from '@bitgo/sdk-test'; -import { BitGo } from '../../../../src/bitgo'; -import { - AffirmationStatus, - common, - Enterprise, - Settlement, - SettlementStatus, - SettlementType, - TradeStatus, - Wallet, -} from '@bitgo/sdk-core'; - -describe('Settlements', function () { - const microservicesUri = common.Environments['mock'].uri; - let bitgo; - let basecoin; - let enterprise; - let tradingAccount; - let bgUrl; - - before(function () { - bitgo = TestBitGo.decorate(BitGo, { env: 'mock', microservicesUri } as any); - bitgo.initializeTestVars(); - basecoin = bitgo.coin('ofc'); - basecoin.keychains(); - - enterprise = new Enterprise(bitgo, basecoin, { id: '5cf940949449412d00f53b3d92dbcaa3', name: 'Test Enterprise' }); - - const walletData = { - id: '5cf940969449412d00f53b4c55fc2139', - coin: 'tofc', - enterprise: enterprise.id, - keys: ['keyid'], - }; - - const wallet = new Wallet(bitgo, basecoin, walletData); - tradingAccount = wallet.toTradingAccount(); - bgUrl = common.Environments[bitgo.getEnv()].uri; - }); - - it('should list all settlements', async function () { - const scope = nock(microservicesUri) - .get(`/api/trade/v1/enterprise/${enterprise.id}/settlements`) - .reply(200, fixtures.listSettlements); - - const settlements = await enterprise.settlements().list(); - should.exist(settlements); - settlements.should.have.length(2); - - for (const settlement of settlements) { - settlement.should.have.property('type'); - if (settlement.type === SettlementType.DIRECT) { - validateDirectSettlement(settlement); - } else { - validateAgencySettlement(settlement); - } - } - - scope.isDone().should.be.true(); - }); - - it('should get a single settlement', async function () { - const scope = nock(microservicesUri) - .get( - `/api/trade/v1/enterprise/${enterprise.id}/account/${tradingAccount.id}/settlements/${fixtures.singleSettlementId}` - ) - .reply(200, fixtures.getSingleSettlement); - - const settlement = await tradingAccount.settlements().get({ id: fixtures.singleSettlementId }); - - should.exist(settlement); - validateDirectSettlement(settlement); - scope.isDone().should.be.true(); - }); - - it('should create a new direct settlement', async function () { - const msScope = nock(microservicesUri) - .post( - `/api/trade/v1/enterprise/${enterprise.id}/account/${tradingAccount.id}/payload`, - fixtures.createDirectSettlementPayloadRequest - ) - .reply(200, fixtures.createDirectSettlementPayloadResponse) - .post( - `/api/trade/v1/enterprise/${enterprise.id}/account/${tradingAccount.id}/settlements`, - fixtures.createDirectSettlementRequest - ) - .reply(200, fixtures.createDirectSettlementResponse); - - const xprv = - 'xprv9s21ZrQH143K2MUz7uPUBVzdmvJQE6fPEQCkR3mypPbZgijPqfmGH7pjijdjeJx3oCoxPWVbjC4VYHzgN6wqEfYnnbNjK7jm2CkrvWrvkbR'; - const xpub = - 'xpub661MyMwAqRbcEqZTDvvUYdwNKx8tdZPEbd8MDSBbNj8YZX4YPD5Wpv9Da2YzLC8ZNRhundXP7mVhhu9WdJChzZJFGLQD7tyY1KGfmjuBvcX'; - const platformScope = nock(bgUrl) - .get('/api/v2/ofc/key/keyid') - .reply(200, { - pub: xpub, - encryptedPrv: bitgo.encrypt({ input: xprv, password: TestBitGo.OFC_TEST_PASSWORD }), - }); - - const payload = await tradingAccount.buildPayload(fixtures.createDirectSettlementPayloadRequest); - - const signature = await tradingAccount.signPayload({ payload, walletPassphrase: TestBitGo.OFC_TEST_PASSWORD }); - - const settlement = await tradingAccount.settlements().create({ - requesterAccountId: tradingAccount.id, - payload: payload, - signature: signature, - trades: [ - { - baseAccountId: '5cf940a49449412d00f53b8f7392f7c0', - quoteAccountId: '5cf940969449412d00f53b4c55fc2139', - status: TradeStatus.EXECUTED, - timestamp: new Date('2019-06-06T16:36:20.810Z'), - baseAmount: '500', - baseCurrency: 'ofctbtc', - quoteAmount: '555', - quoteCurrency: 'ofctusd', - costBasis: '12345', - costBasisCurrency: 'USD', - externalId: 'a4o3ah601etw676okvkvsmizciorxc8v', - }, - ], - }); - - should.exist(settlement); - validateDirectSettlement(settlement); - - msScope.isDone().should.be.true(); - platformScope.isDone().should.be.true(); - }); - - it('should create a new agency settlement', async function () { - const msScope = nock(microservicesUri) - .post( - `/api/trade/v1/enterprise/${enterprise.id}/account/${tradingAccount.id}/payload`, - fixtures.createAgencySettlementPayloadRequest - ) - .reply(200, fixtures.createAgencySettlementPayloadResponse) - .post( - `/api/trade/v1/enterprise/${enterprise.id}/account/${tradingAccount.id}/settlements`, - fixtures.createAgencySettlementRequest - ) - .reply(200, fixtures.createAgencySettlementResponse); - - const xprv = - 'xprv9s21ZrQH143K2MUz7uPUBVzdmvJQE6fPEQCkR3mypPbZgijPqfmGH7pjijdjeJx3oCoxPWVbjC4VYHzgN6wqEfYnnbNjK7jm2CkrvWrvkbR'; - const xpub = - 'xpub661MyMwAqRbcEqZTDvvUYdwNKx8tdZPEbd8MDSBbNj8YZX4YPD5Wpv9Da2YzLC8ZNRhundXP7mVhhu9WdJChzZJFGLQD7tyY1KGfmjuBvcX'; - const platformScope = nock(bgUrl) - .get('/api/v2/ofc/key/keyid') - .reply(200, { - pub: xpub, - encryptedPrv: bitgo.encrypt({ input: xprv, password: TestBitGo.OFC_TEST_PASSWORD }), - }); - - const payload = await tradingAccount.buildPayload(fixtures.createAgencySettlementPayloadRequest); - - const signature = await tradingAccount.signPayload({ payload, walletPassphrase: TestBitGo.OFC_TEST_PASSWORD }); - - const settlement = await tradingAccount.settlements().create({ - requesterAccountId: tradingAccount.id, - payload: payload, - signature: signature, - trades: [ - { - id: 'a37c5c9a-efc0-4b2c-89e0-39538de86b29', - baseAccountId: '5df03e088b4eb3470019a88734b69f7a', - quoteAccountId: '5df03e088b4eb3470019a89e37864bed', - status: TradeStatus.EXECUTED, - timestamp: new Date('2019-12-11T00:53:52.814Z'), - baseAmount: '115087', - quoteAmount: '942777', - baseCurrency: 'ofctbtc', - quoteCurrency: 'ofctusd', - baseReceiveAmount: '941966', - quoteReceiveAmount: '115087', - baseReceiveCurrency: 'ofctusd', - quoteReceiveCurrency: 'ofctbtc', - costBasis: '', - costBasisCurrency: '', - externalId: 'xff7vln0eh9hh3rp0derlbunlo1sw6k6', - }, - ], - }); - - should.exist(settlement); - validateAgencySettlement(settlement); - - msScope.isDone().should.be.true(); - platformScope.isDone().should.be.true(); - }); - - function validateDirectSettlement(settlement: Settlement): void { - settlement.should.have.property('id'); - settlement.should.have.property('requesterAccountId'); - settlement.should.have.property('status'); - settlement.should.have.property('type'); - - settlement.requesterAccountId.should.eql(tradingAccount.id); - settlement.status.should.eql(SettlementStatus.PENDING); - settlement.type.should.eql(SettlementType.DIRECT); - - // one affirmation should be for this account, one should be for the counterparty - // furthermore, the one for this account should already be affirmed - settlement.should.have.property('affirmations'); - settlement.affirmations.should.have.length(2); - settlement.affirmations - .filter( - (affirmation) => - affirmation.partyAccountId === tradingAccount.id && affirmation.status === AffirmationStatus.AFFIRMED - ) - .should.have.length(1); - settlement.affirmations - .filter((affirmation) => affirmation.partyAccountId !== tradingAccount.id) - .should.have.length(1); - } - - function validateAgencySettlement(settlement: Settlement): void { - settlement.should.have.property('id'); - settlement.should.have.property('requesterAccountId'); - settlement.should.have.property('status'); - settlement.should.have.property('type'); - - settlement.requesterAccountId.should.eql(tradingAccount.id); - settlement.status.should.eql(SettlementStatus.PENDING); - settlement.type.should.eql(SettlementType.AGENCY); - - // one affirmation should be for this account, one should be for the counterparty - // furthermore, the one for this account should already be affirmed - settlement.should.have.property('affirmations'); - settlement.affirmations.should.have.length(3); - settlement.affirmations - .filter( - (affirmation) => - affirmation.partyAccountId === tradingAccount.id && affirmation.status === AffirmationStatus.AFFIRMED - ) - .should.have.length(1); - settlement.affirmations - .filter((affirmation) => affirmation.partyAccountId !== tradingAccount.id) - .should.have.length(2); - } -}); diff --git a/modules/bitgo/test/v2/unit/trading/tradingAccount.ts b/modules/bitgo/test/v2/unit/trading/tradingAccount.ts deleted file mode 100644 index c3936c4cec..0000000000 --- a/modules/bitgo/test/v2/unit/trading/tradingAccount.ts +++ /dev/null @@ -1,62 +0,0 @@ -import * as should from 'should'; -import * as nock from 'nock'; - -import { Enterprise, Environments, Wallet } from '@bitgo/sdk-core'; -import { TestBitGo } from '@bitgo/sdk-test'; -import { BitGo } from '../../../../src/bitgo'; - -describe('Trading Accounts', function () { - const microservicesUri = Environments['mock'].uri; - let bitgo; - let basecoin; - let enterprise; - let tradingAccount; - - before(function () { - bitgo = TestBitGo.decorate(BitGo, { env: 'mock', microservicesUri } as any); - bitgo.initializeTestVars(); - basecoin = bitgo.coin('ofc'); - - enterprise = new Enterprise(bitgo, basecoin, { id: '5cf940949449412d00f53b3d92dbcaa3', name: 'Test Enterprise' }); - - const walletData = { - id: 'walletId', - coin: 'tofc', - enterprise: enterprise.id, - }; - - const wallet = new Wallet(bitgo, basecoin, walletData); - tradingAccount = wallet.toTradingAccount(); - }); - - it('should calculate settlement fees', async function () { - const msScope = nock(microservicesUri) - .post(`/api/trade/v1/enterprise/${enterprise.id}/account/${tradingAccount.id}/calculatefees`, { - counterpartyAccountId: 'counterpartyId', - receiveAmount: '100000000', - receiveCurrency: 'ofctbtc', - sendAmount: '1000000', - sendCurrency: 'ofctusd', - }) - .reply(200, { - feeRate: '1', - feeAmount: '100', - feeCurrency: 'ofctusd', - }); - - const settlementFees = await tradingAccount.calculateSettlementFees({ - counterpartyAccountId: 'counterpartyId', - receiveAmount: '100000000', - receiveCurrency: 'ofctbtc', - sendAmount: '1000000', - sendCurrency: 'ofctusd', - }); - - should.exist(settlementFees); - settlementFees.should.have.property('feeRate', '1'); - settlementFees.should.have.property('feeAmount', '100'); - settlementFees.should.have.property('feeCurrency', 'ofctusd'); - - msScope.isDone().should.be.True(); - }); -}); diff --git a/modules/bitgo/test/v2/unit/trading/tradingPartner.ts b/modules/bitgo/test/v2/unit/trading/tradingPartner.ts deleted file mode 100644 index 315d50a97d..0000000000 --- a/modules/bitgo/test/v2/unit/trading/tradingPartner.ts +++ /dev/null @@ -1,109 +0,0 @@ -import * as nock from 'nock'; -import * as should from 'should'; - -import fixtures from '../../fixtures/trading/tradingPartner'; - -import { TestBitGo } from '@bitgo/sdk-test'; -import { BitGo } from '../../../../src/bitgo'; -import { - Enterprise, - Environments, - TradingPartnerStatus, - TradingPartnerType, - TradingReferralRequesterSide, - Wallet, -} from '@bitgo/sdk-core'; - -describe('Trading Partners', function () { - const microservicesUri = Environments['mock'].uri; - let bitgo; - let basecoin; - let enterprise; - let tradingAccount; - - before(function () { - bitgo = TestBitGo.decorate(BitGo, { env: 'mock', microservicesUri } as any); - bitgo.initializeTestVars(); - basecoin = bitgo.coin('ofc'); - basecoin.keychains(); - - enterprise = new Enterprise(bitgo, basecoin, { id: '5cf940949449412d00f53b3d92dbcaa3', name: 'Test Enterprise' }); - - const walletData = { - id: '5cf940969449412d00f53b4c55fc2139', - coin: 'tofc', - enterprise: enterprise.id, - keys: ['keyid'], - }; - - const wallet = new Wallet(bitgo, basecoin, walletData); - tradingAccount = wallet.toTradingAccount(); - }); - - it('should refer check trading partner by code', async function () { - const scope = nock(microservicesUri) - .post(`/api/trade/v1/enterprise/${enterprise.id}/account/${tradingAccount.id}/tradingpartners`) - .reply(200, fixtures.addByCodeResponse); - - const addByCodeResponse = await tradingAccount.partners().addByCode({ - referralCode: 'TEST', - type: TradingPartnerType.AGENCY, - requesterSide: TradingReferralRequesterSide.PRIMARY, - }); - - addByCodeResponse.should.have.property('id'); - addByCodeResponse.should.have.property('primaryAccountId'); - addByCodeResponse.should.have.property('primaryEnterpriseName'); - addByCodeResponse.should.have.property('secondaryAccountId'); - addByCodeResponse.should.have.property('secondaryEnterpriseName'); - addByCodeResponse.should.have.property('requesterAccountId', tradingAccount.id); - addByCodeResponse.status.should.eql(TradingPartnerStatus.PENDING); - addByCodeResponse.type.should.eql(TradingPartnerType.AGENCY); - - scope.isDone().should.be.true(); - }); - - it('should list all trading partners', async function () { - const scope = nock(microservicesUri) - .get(`/api/trade/v1/enterprise/${enterprise.id}/account/${tradingAccount.id}/tradingpartners`) - .reply(200, fixtures.listTradingPartners); - - const partners = await tradingAccount.partners().list(); - - should.exist(partners); - partners.should.have.length(2); - - for (const partner of partners) { - partner.should.have.property('id'); - partner.should.have.property('primaryAccountId'); - partner.should.have.property('primaryEnterpriseName'); - partner.should.have.property('secondaryAccountId'); - partner.should.have.property('secondaryEnterpriseName'); - partner.should.have.property('requesterAccountId'); - partner.status.should.eql(TradingPartnerStatus.ACCEPTED); - [TradingPartnerType.DIRECT, TradingPartnerType.AGENCY].includes(partner.type); - } - - scope.isDone().should.be.true(); - }); - - it('should balance check trading partners', async function () { - const scope = nock(microservicesUri) - .get(`/api/trade/v1/enterprise/${enterprise.id}/account/${tradingAccount.id}/tradingpartners`) - .reply(200, fixtures.listTradingPartners) - .get( - `/api/trade/v1/enterprise/${enterprise.id}/account/${tradingAccount.id}/tradingpartners/${fixtures.listTradingPartners.tradingPartners[0].secondaryAccountId}/balance` - ) - .query(fixtures.balanceCheckTrueRequest) - .reply(200, { check: true }); - - const partners = await tradingAccount.partners().list(); - should.exist(partners); - partners.should.have.length(2); - - const balanceCheck = await partners[0].checkBalance('ofctbtc', '24128'); - balanceCheck.should.be.true(); - - scope.isDone().should.be.true(); - }); -}); diff --git a/modules/sdk-core/src/bitgo/enterprise/enterprise.ts b/modules/sdk-core/src/bitgo/enterprise/enterprise.ts index 2ae957c1f6..785f3e90ca 100644 --- a/modules/sdk-core/src/bitgo/enterprise/enterprise.ts +++ b/modules/sdk-core/src/bitgo/enterprise/enterprise.ts @@ -6,7 +6,6 @@ import { IBaseCoin } from '../baseCoin'; import { BitGoBase } from '../bitgoBase'; import { EnterpriseData, EnterpriseFeatureFlag, IEnterprise } from '../enterprise'; import { getFirstPendingTransaction } from '../internal'; -import { Affirmations, Settlements } from '../trading'; import { Wallet } from '../wallet'; import { BitGoProofSignatures, EcdsaUtils, SerializedNtildeWithVerifiers } from '../utils/tss/ecdsa'; import { EcdsaTypes } from '@bitgo/sdk-lib-mpc'; @@ -106,20 +105,6 @@ export class Enterprise implements IEnterprise { return getFirstPendingTransaction({ enterpriseId: this.id }, this.baseCoin, this.bitgo); } - /** - * Manage settlements for an enterprise - */ - settlements(): Settlements { - return new Settlements(this.bitgo, this.id); - } - - /** - * Manage affirmations for an enterprise - */ - affirmations(): Affirmations { - return new Affirmations(this.bitgo, this.id); - } - /** * Verifies and signs bitgo proofs for the enterprise * @param userPassword - enterprise admin's login password diff --git a/modules/sdk-core/src/bitgo/enterprise/iEnterprise.ts b/modules/sdk-core/src/bitgo/enterprise/iEnterprise.ts index c0eaf20876..00f51b6f70 100644 --- a/modules/sdk-core/src/bitgo/enterprise/iEnterprise.ts +++ b/modules/sdk-core/src/bitgo/enterprise/iEnterprise.ts @@ -1,6 +1,4 @@ import { EcdsaTypes } from '@bitgo/sdk-lib-mpc'; - -import { ISettlements, IAffirmations } from '../trading'; import { IWallet } from '../wallet'; import { Buffer } from 'buffer'; import { BitGoProofSignatures, SerializedNtildeWithVerifiers } from '../utils/tss/ecdsa'; @@ -24,8 +22,6 @@ export interface IEnterprise { addUser(params?: any): Promise; removeUser(params?: any): Promise; getFirstPendingTransaction(params?: Record): Promise; - settlements(): ISettlements; - affirmations(): IAffirmations; verifyEcdsaBitGoChallengeProofs(userPassword: string): Promise; uploadAndEnableTssEcdsaSigning( userPassword: string, diff --git a/modules/sdk-core/src/bitgo/trading/affirmation.ts b/modules/sdk-core/src/bitgo/trading/affirmation.ts deleted file mode 100644 index a9898246f5..0000000000 --- a/modules/sdk-core/src/bitgo/trading/affirmation.ts +++ /dev/null @@ -1,74 +0,0 @@ -/** - * @prettier - */ -import { BitGoBase } from '../bitgoBase'; -import { AffirmationStatus, IAffirmation, Lock, Payload } from '../trading'; - -export class Affirmation implements IAffirmation { - private bitgo: BitGoBase; - private enterpriseId: string; - - public id?: string; - public partyAccountId?: string; - public status?: AffirmationStatus; - public settlement?: string; - public lock?: Lock; - public payload?: string; - public createdAt?: Date; - public expireAt?: Date; - - constructor(affirmationData: any, bitgo: BitGoBase, enterpriseId: string) { - this.bitgo = bitgo; - this.enterpriseId = enterpriseId; - - this.updateAffirmationData(affirmationData); - } - - /** - * Affirms a pending affirmation, authorizing the settlement - * @param payload payload authorizing the movement of funds from a trading account - * @param signature signature of the payload with the user key of the trading account - */ - async affirm(payload: Payload, signature: string): Promise { - const body = { - payload: JSON.stringify(payload), - signature: signature, - }; - - return await this.updateStatus(AffirmationStatus.AFFIRMED, body); - } - - /** - * Rejects a pending affirmation, cancelling the settlement - */ - async reject(): Promise { - return this.updateStatus(AffirmationStatus.REJECTED, null); - } - - /** - * Cancels a pending affirmation, cancelling the settlement - */ - async cancel(): Promise { - return this.updateStatus(AffirmationStatus.CANCELED, null); - } - - private async updateStatus(status: AffirmationStatus, body?: any): Promise { - const bodyWithStatus = { status, ...body }; - const url = this.bitgo.microservicesUrl( - `/api/trade/v1/enterprise/${this.enterpriseId}/account/${this.partyAccountId}/affirmations/${this.id}` - ); - const response = await this.bitgo.put(url).send(bodyWithStatus).result(); - this.updateAffirmationData(response); - } - - private updateAffirmationData(affirmationData: any) { - this.id = affirmationData.id; - this.partyAccountId = affirmationData.partyAccountId; - this.status = affirmationData.status; - this.settlement = affirmationData.settlement; - this.lock = affirmationData.lock as Lock; - this.payload = affirmationData.payload; - this.createdAt = new Date(affirmationData.createdAt); - this.expireAt = new Date(affirmationData.expireAt); - } -} diff --git a/modules/sdk-core/src/bitgo/trading/affirmations.ts b/modules/sdk-core/src/bitgo/trading/affirmations.ts deleted file mode 100644 index 5e4a3d348d..0000000000 --- a/modules/sdk-core/src/bitgo/trading/affirmations.ts +++ /dev/null @@ -1,57 +0,0 @@ -/** - * @prettier - */ -import { BitGoBase } from '../bitgoBase'; -import { Affirmation, AffirmationStatus, GetAffirmationParameters, IAffirmations, ITradingAccount } from '../trading'; - -export class Affirmations implements IAffirmations { - private bitgo: BitGoBase; - private enterpriseId: string; - private account?: ITradingAccount; - - constructor(bitgo: BitGoBase, enterpriseId: string, account?: ITradingAccount) { - this.bitgo = bitgo; - this.enterpriseId = enterpriseId; - this.account = account; - } - - /** - * Lists all affirmations for an enterprise - * @param status optional status to filter affirmations by - */ - async list(status?: AffirmationStatus): Promise { - let url; - if (this.account) { - url = this.bitgo.microservicesUrl( - `/api/trade/v1/enterprise/${this.enterpriseId}/account/${this.account.id}/affirmations` - ); - } else { - url = this.bitgo.microservicesUrl(`/api/trade/v1/enterprise/${this.enterpriseId}/affirmations`); - } - if (status) { - url = `${url}?status=${status}`; - } - - const response = (await this.bitgo.get(url).result()) as any; - - return response.affirmations.map((affirmation) => new Affirmation(affirmation, this.bitgo, this.enterpriseId)); - } - - /** - * Retrieves a single affirmation by its ID - * @param id ID of the affirmation to retrieve - * @param accountId ID of the trading account that the affirmation belongs to - */ - async get({ id, accountId }: GetAffirmationParameters): Promise { - const account = (this.account && this.account.id) || accountId; - if (!account) { - throw new Error('accountId must be provided in parameters for an enterprise context'); - } - - const url = this.bitgo.microservicesUrl( - `/api/trade/v1/enterprise/${this.enterpriseId}/account/${account}/affirmations/${id}` - ); - const response = await this.bitgo.get(url).result(); - return new Affirmation(response, this.bitgo, this.enterpriseId); - } -} diff --git a/modules/sdk-core/src/bitgo/trading/iAffirmation.ts b/modules/sdk-core/src/bitgo/trading/iAffirmation.ts deleted file mode 100644 index ade767bab8..0000000000 --- a/modules/sdk-core/src/bitgo/trading/iAffirmation.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { Payload } from './payload'; - -export enum AffirmationStatus { - PENDING = 'pending', - OVERDUE = 'overdue', - REJECTED = 'rejected', - AFFIRMED = 'affirmed', - FAILED = 'failed', - CANCELED = 'canceled', -} - -export interface IAffirmation { - affirm(payload: Payload, signature: string): Promise; - reject(): Promise; - cancel(): Promise; -} diff --git a/modules/sdk-core/src/bitgo/trading/iAffirmations.ts b/modules/sdk-core/src/bitgo/trading/iAffirmations.ts deleted file mode 100644 index a622a409a1..0000000000 --- a/modules/sdk-core/src/bitgo/trading/iAffirmations.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { AffirmationStatus, IAffirmation } from './iAffirmation'; - -export interface GetAffirmationParameters { - id: string; - accountId?: string; -} - -export interface IAffirmations { - list(status?: AffirmationStatus): Promise; - get(options: GetAffirmationParameters): Promise; -} diff --git a/modules/sdk-core/src/bitgo/trading/iSettlement.ts b/modules/sdk-core/src/bitgo/trading/iSettlement.ts deleted file mode 100644 index ce059351b2..0000000000 --- a/modules/sdk-core/src/bitgo/trading/iSettlement.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { IAffirmation } from './iAffirmation'; -import { Trade } from './trade'; - -export enum SettlementStatus { - CANCELED = 'canceled', - PENDING = 'pending', - REJECTED = 'rejected', - SETTLED = 'settled', - FAILED = 'failed', -} - -export enum SettlementType { - DIRECT = 'direct', - AGENCY = 'agency', -} - -export interface ISettlement { - id: string; - requesterAccountId: string; - status: SettlementStatus; - type: SettlementType; - affirmations: IAffirmation[]; - createdAt: Date; - expireAt: Date; - settledAt: Date; - trades: Trade[]; -} diff --git a/modules/sdk-core/src/bitgo/trading/iSettlements.ts b/modules/sdk-core/src/bitgo/trading/iSettlements.ts deleted file mode 100644 index feca95a9db..0000000000 --- a/modules/sdk-core/src/bitgo/trading/iSettlements.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { ISettlement } from './iSettlement'; -import { Payload } from './payload'; -import { Trade } from './trade'; - -export interface CreateSettlementParams { - requesterAccountId: string; - payload: Payload; - signature: string; - trades: Trade[]; -} - -export interface GetOptions { - id: string; - accountId: string; -} - -export interface ISettlements { - list(): Promise; - get(options: GetOptions): Promise; - create(params: CreateSettlementParams): Promise; -} diff --git a/modules/sdk-core/src/bitgo/trading/iTradingAccount.ts b/modules/sdk-core/src/bitgo/trading/iTradingAccount.ts index 74aac5e336..8dd2612c79 100644 --- a/modules/sdk-core/src/bitgo/trading/iTradingAccount.ts +++ b/modules/sdk-core/src/bitgo/trading/iTradingAccount.ts @@ -1,46 +1,9 @@ -import { IAffirmations } from './iAffirmations'; -import { ISettlements } from './iSettlements'; -import { ITradingPartners } from './iTradingPartners'; -import { Payload } from './payload'; - -export interface BuildPayloadParameters { - amounts: BuildPayloadAmounts[]; -} - -export interface BuildPayloadAmounts { - accountId: string; - sendAmount: string; - sendCurrency: string; - receiveAmount: string; - receiveCurrency: string; -} - export interface SignPayloadParameters { payload: string | Record; walletPassphrase: string; } -export interface SettlementFees { - feeRate: string; - feeAmount: string; - feeCurrency: string; -} - -export interface CalculateSettlementFeesParams { - counterpartyAccountId: string; - sendCurrency: string; - sendAmount: string; - receiveCurrency: string; - receiveAmount: string; -} - export interface ITradingAccount { readonly id: string; - buildPayload(params: BuildPayloadParameters): Promise; - verifyPayload(params: BuildPayloadParameters, payload: string): boolean; - calculateSettlementFees(params: CalculateSettlementFeesParams): Promise; signPayload(params: SignPayloadParameters): Promise; - affirmations(): IAffirmations; - settlements(): ISettlements; - partners(): ITradingPartners; } diff --git a/modules/sdk-core/src/bitgo/trading/iTradingPartner.ts b/modules/sdk-core/src/bitgo/trading/iTradingPartner.ts deleted file mode 100644 index 0cc5aa4509..0000000000 --- a/modules/sdk-core/src/bitgo/trading/iTradingPartner.ts +++ /dev/null @@ -1,16 +0,0 @@ -export enum TradingPartnerStatus { - ACCEPTED = 'accepted', - REJECTED = 'rejected', - CANCELED = 'canceled', - PENDING = 'pending', -} - -// Type of partnership used for settlements -export enum TradingPartnerType { - DIRECT = 'direct', // direct settlement between requester and counterparty - AGENCY = 'agency', // agent settlement between two counterparties of the agent -} - -export interface ITradingPartner { - checkBalance(currency: string, amount: string): Promise; -} diff --git a/modules/sdk-core/src/bitgo/trading/iTradingPartners.ts b/modules/sdk-core/src/bitgo/trading/iTradingPartners.ts deleted file mode 100644 index f3f7d259d9..0000000000 --- a/modules/sdk-core/src/bitgo/trading/iTradingPartners.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { ITradingPartner, TradingPartnerType } from './iTradingPartner'; - -export enum TradingReferralRequesterSide { - PRIMARY = 'primary', // if partnership is of type agency, primary is the agent - SECONDARY = 'secondary', -} - -export interface TradingPartnerAddByCodeParameters { - referralCode: string; - type: TradingPartnerType; - requesterSide: TradingReferralRequesterSide; -} - -export interface ITradingPartners { - list(): Promise; - addByCode(params: TradingPartnerAddByCodeParameters): Promise; -} diff --git a/modules/sdk-core/src/bitgo/trading/index.ts b/modules/sdk-core/src/bitgo/trading/index.ts index 53c05c2a80..ee412f95fb 100644 --- a/modules/sdk-core/src/bitgo/trading/index.ts +++ b/modules/sdk-core/src/bitgo/trading/index.ts @@ -1,17 +1,2 @@ -export * from './affirmation'; -export * from './affirmations'; -export * from './iAffirmation'; -export * from './iAffirmations'; -export * from './iSettlement'; -export * from './iSettlements'; export * from './iTradingAccount'; -export * from './iTradingPartner'; -export * from './iTradingPartners'; -export * from './lock'; -export * from './payload'; -export * from './settlement'; -export * from './settlements'; -export * from './trade'; export * from './tradingAccount'; -export * from './tradingPartner'; -export * from './tradingPartners'; diff --git a/modules/sdk-core/src/bitgo/trading/lock.ts b/modules/sdk-core/src/bitgo/trading/lock.ts deleted file mode 100644 index 89a41841ee..0000000000 --- a/modules/sdk-core/src/bitgo/trading/lock.ts +++ /dev/null @@ -1,16 +0,0 @@ -export interface Lock { - id: string; - accountId: string; - status: LockStatus; - amount: string; - currency: string; - createdAt: Date; -} - -export enum LockStatus { - ACTIVE = 'active', - SETTLED = 'settled', - FAILED = 'failed', - REQUESTED = 'requested', - RELEASED = 'released', -} diff --git a/modules/sdk-core/src/bitgo/trading/payload.ts b/modules/sdk-core/src/bitgo/trading/payload.ts deleted file mode 100644 index 554ddabaf5..0000000000 --- a/modules/sdk-core/src/bitgo/trading/payload.ts +++ /dev/null @@ -1,23 +0,0 @@ -type CURRENT_PAYLOAD_VERSION = '1.2.0'; - -export interface Payload { - version: CURRENT_PAYLOAD_VERSION; - accountId: string; - amounts: PayloadAmounts[]; - nonceHold: string; - nonceSettle: string; -} - -export interface PayloadAmounts { - accountId: string; - sendAmount: string; - sendCurrency: string; - receiveAmount: string; - receiveCurrency: string; - sendSubtotal: string; // sendAmount - fees[].feeAmount - fees?: { - // will only show up if the accountId is the signing accountId - feeType: string; - feeAmount: string; - }[]; -} diff --git a/modules/sdk-core/src/bitgo/trading/settlement.ts b/modules/sdk-core/src/bitgo/trading/settlement.ts deleted file mode 100644 index 40503e0b95..0000000000 --- a/modules/sdk-core/src/bitgo/trading/settlement.ts +++ /dev/null @@ -1,37 +0,0 @@ -/** - * @prettier - */ -import { BitGoBase } from '../bitgoBase'; -import { Affirmation, ISettlement, SettlementStatus, SettlementType, Trade } from '../trading'; - -export class Settlement implements ISettlement { - private readonly bitgo: BitGoBase; - private readonly enterpriseId: string; - - public id: string; - public requesterAccountId: string; - public status: SettlementStatus; - public type: SettlementType; - public affirmations: Affirmation[]; - public createdAt: Date; - public expireAt: Date; - public settledAt: Date; - public trades: Trade[]; - - constructor(settlementData, bitgo, enterpriseId: string) { - this.bitgo = bitgo; - this.enterpriseId = enterpriseId; - - this.id = settlementData.id; - this.requesterAccountId = settlementData.requesterAccountId; - this.status = settlementData.status; - this.type = settlementData.type; - this.affirmations = settlementData.affirmations.map( - (affirmation) => new Affirmation(affirmation, this.bitgo, this.enterpriseId) - ); - this.createdAt = new Date(settlementData.createdAt); - this.expireAt = new Date(settlementData.expireAt); - this.settledAt = new Date(settlementData.settledAt); - this.trades = settlementData.trades as Trade[]; - } -} diff --git a/modules/sdk-core/src/bitgo/trading/settlements.ts b/modules/sdk-core/src/bitgo/trading/settlements.ts deleted file mode 100644 index a9bc24e0d6..0000000000 --- a/modules/sdk-core/src/bitgo/trading/settlements.ts +++ /dev/null @@ -1,80 +0,0 @@ -/** - * @prettier - */ -import { BitGoBase } from '../bitgoBase'; -import { CreateSettlementParams, GetOptions, ISettlement, ISettlements, Settlement, TradingAccount } from '../trading'; - -export class Settlements implements ISettlements { - private bitgo: BitGoBase; - private enterpriseId: string; - private account?: TradingAccount; - - constructor(bitgo: BitGoBase, enterpriseId: string, account?: TradingAccount) { - this.bitgo = bitgo; - this.enterpriseId = enterpriseId; - this.account = account; - } - - /** - * Retrieves all settlements for an enterprise - */ - async list(): Promise { - let url; - if (this.account) { - url = this.bitgo.microservicesUrl( - `/api/trade/v1/enterprise/${this.enterpriseId}/account/${this.account.id}/settlements` - ); - } else { - url = this.bitgo.microservicesUrl(`/api/trade/v1/enterprise/${this.enterpriseId}/settlements`); - } - const response = (await this.bitgo.get(url).result()) as any; - - return response.settlements.map((settlement) => new Settlement(settlement, this.bitgo, this.enterpriseId)); - } - - /** - * Retrieves a single settlement by its ID. - * @param id ID of the settlement - * @param accountId ID of the trading account that the affirmation belongs to - */ - async get({ id, accountId }: GetOptions): Promise { - const account = accountId || (this.account && this.account.id); - if (!account) { - throw new Error('accountId must be provided in parameters for an enterprise context'); - } - - const url = this.bitgo.microservicesUrl( - `/api/trade/v1/enterprise/${this.enterpriseId}/account/${account}/settlements/${id}` - ); - const response = await this.bitgo.get(url).result(); - return new Settlement(response, this.bitgo, this.enterpriseId); - } - - /** - * Submits a new settlement for a set of trades. - * NOTE: This function must be called as tradingAccount.settlements().create(), enterprise.settlements().create() is not a valid call. - * @param params - * @param params.requesterAccountId trading account ID that is creating this settlement - * @param params.payload payload authorizing the movement of funds for the included trades - * @param params.signature hex-encoded signature of the payload - * @param params.trades list of trades to settle as part of this settlement - */ - async create(params: CreateSettlementParams): Promise { - if (!this.account) { - throw new Error( - 'Must select a trading account before creating a settlement. Try tradingAccount.settlements().create()' - ); - } - - // payload must be stringified before being passed to API - const body = Object.assign({}, params as any); - body.payload = JSON.stringify(body.payload); - - const url = this.bitgo.microservicesUrl( - `/api/trade/v1/enterprise/${this.enterpriseId}/account/${this.account.id}/settlements` - ); - const response = await this.bitgo.post(url).send(body).result(); - - return new Settlement(response, this.bitgo, this.enterpriseId); - } -} diff --git a/modules/sdk-core/src/bitgo/trading/trade.ts b/modules/sdk-core/src/bitgo/trading/trade.ts deleted file mode 100644 index 43250c7248..0000000000 --- a/modules/sdk-core/src/bitgo/trading/trade.ts +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Represents a single trade to be settled as part of a settlement. Only off-chain (OFC) currencies are supported, and - * all amounts must be represented in base units (such as cents, satoshi, or wei) - */ -export interface Trade { - id?: string; - externalId: string; - baseAccountId: string; - quoteAccountId: string; - timestamp: Date; - status: TradeStatus; - baseAmount: string; - quoteAmount: string; - baseCurrency: string; - quoteCurrency: string; - baseReceiveAmount?: string; - quoteReceiveAmount?: string; - baseReceiveCurrency?: string; - quoteReceiveCurrency?: string; - costBasis: string; - costBasisCurrency: string; -} - -export enum TradeStatus { - CANCELED = 'canceled', - EXECUTED = 'executed', - PENDING = 'pending', - FAILED = 'failed', -} diff --git a/modules/sdk-core/src/bitgo/trading/tradingAccount.ts b/modules/sdk-core/src/bitgo/trading/tradingAccount.ts index e5476575c0..330fec51e8 100644 --- a/modules/sdk-core/src/bitgo/trading/tradingAccount.ts +++ b/modules/sdk-core/src/bitgo/trading/tradingAccount.ts @@ -1,26 +1,10 @@ /** * @prettier */ -import { BigNumber } from 'bignumber.js'; import { BitGoBase } from '../bitgoBase'; -import { - Affirmations, - BuildPayloadParameters, - CalculateSettlementFeesParams, - IAffirmations, - ISettlements, - ITradingAccount, - ITradingPartners, - Payload, - SettlementFees, - Settlements, - SignPayloadParameters, - TradingPartners, -} from '../trading'; +import { ITradingAccount, SignPayloadParameters } from '../trading'; import { IWallet } from '../wallet'; -const TRADE_PAYLOAD_VERSION = '1.2.0'; - export class TradingAccount implements ITradingAccount { private readonly bitgo: BitGoBase; private readonly enterpriseId: string; @@ -33,114 +17,10 @@ export class TradingAccount implements ITradingAccount { this.bitgo = bitgo; } - get id() { + get id(): string { return this.wallet.id(); } - /** - * Builds a payload authorizing trade from this trading account. - * @param params - * @param params.amounts[] array of amounts that will be traded as part of the settlement - * @param params.amounts[].accountId the accountId corresponding with the sending and receiving amounts for the settlement - * @param params.amounts[].sendAmount amount of currency sent by trading account of given accountId - * @param params.amounts[].sendCurrency currency of amount sent by trading account of given accountId - * @param params.amounts[].receiveAmount amount of currency received by trading account of given accountId - * @param params.amounts[].receiveCurrency currency of amount received by trading account of given accountId - * @returns unsigned trade payload for the given parameters. This object should be stringified with JSON.stringify() before being submitted - */ - async buildPayload(params: BuildPayloadParameters): Promise { - const url = this.bitgo.microservicesUrl(`/api/trade/v1/enterprise/${this.enterpriseId}/account/${this.id}/payload`); - - const body = { - version: TRADE_PAYLOAD_VERSION, - amounts: params.amounts, - }; - - const response = (await this.bitgo.post(url).send(body).result()) as any; - - if (!this.verifyPayload(params, response.payload)) { - throw new Error( - 'Unable to verify trade payload. You may need to update the BitGo SDK, or the payload may have been tampered with.' - ); - } - - return JSON.parse(response.payload) as Payload; - } - - /** - * Verifies that a payload received from BitGo sufficiently matches the expected parameters. This is used to prevent - * man-in-the-middle attacks which could maliciously alter the contents of a payload. - * @param params parameters used to build the payload - * @param payload payload received from the BitGo API - * @returns true if the payload's sensitive fields match, false if the payload may have been tampered with - */ - verifyPayload(params: BuildPayloadParameters, payload: string): boolean { - const payloadObj = JSON.parse(payload); - const paramsCopy = JSON.parse(JSON.stringify(params)); // needs to be a deep copy - - // Verifies that for each party in the payload, we requested a matching party, only checking sensitive fields - let validAmounts = 0; - for (const amount of payloadObj.amounts) { - const matchingExpectedParty = paramsCopy.amounts.findIndex( - (expectedAmount) => - amount.accountId === expectedAmount.accountId && - amount.sendCurrency === expectedAmount.sendCurrency && - amount.sendSubtotal === expectedAmount.sendAmount && - amount.receiveAmount === expectedAmount.receiveAmount && - amount.receiveCurrency === expectedAmount.receiveCurrency - ); - - if (matchingExpectedParty === -1) { - // matchingExpectedParty not found to the payloadObject - // payload is not valid - break; - } - - if (amount.fees && amount.fees.length > 0) { - let feeTotal = new BigNumber(0); - for (const fee of amount.fees) { - feeTotal = feeTotal.plus(new BigNumber(fee.feeAmount)); - } - - const expectedTotalAmount = new BigNumber(paramsCopy.amounts[matchingExpectedParty].sendAmount).plus(feeTotal); - if (expectedTotalAmount.toString() !== amount.sendAmount) { - // expected total does not match the sendAmount of the payload - // payload is not valid - break; - } - } - - // matching party found, and fee found - validAmounts = validAmounts + 1; - // delete so we ensure no duplicates - paramsCopy.amounts.splice(matchingExpectedParty, 1); - } - - return ( - payloadObj.accountId === this.id && - payloadObj.amounts.length === params.amounts.length && - validAmounts === payloadObj.amounts.length - ); - } - - /** - * Calculates the necessary fees to complete a settlement between two parties, based on the amounts and currencies of the settlement. - * @param params - * @param params.counterpartyAccountId Account ID of the counterparty of the settlement - * @param params.sendCurrency Currency to be sent as part of the settlement - * @param params.sendAmount Amount of currency (in base units such as cents, satoshis, or wei) to be sent - * @param params.receiveCurrency Currency to be received as part of the settlement - * @param params.receiveAmount Amount of currency (in base units such as cents, satoshis, or wei) to be received - * @returns Fee rate, currency, and total amount of the described settlement - */ - async calculateSettlementFees(params: CalculateSettlementFeesParams): Promise { - const url = this.bitgo.microservicesUrl( - `/api/trade/v1/enterprise/${this.enterpriseId}/account/${this.id}/calculatefees` - ); - - return await this.bitgo.post(url).send(params).result(); - } - /** * Signs an arbitrary payload with the user key on this trading account * @param params @@ -157,16 +37,4 @@ export class TradingAccount implements ITradingAccount { const payload = typeof params.payload === 'string' ? params.payload : JSON.stringify(params.payload); return ((await this.wallet.baseCoin.signMessage({ prv }, payload)) as any).toString('hex'); } - - affirmations(): IAffirmations { - return new Affirmations(this.bitgo, this.enterpriseId, this); - } - - settlements(): ISettlements { - return new Settlements(this.bitgo, this.enterpriseId, this); - } - - partners(): ITradingPartners { - return new TradingPartners(this.bitgo, this.enterpriseId, this); - } } diff --git a/modules/sdk-core/src/bitgo/trading/tradingPartner.ts b/modules/sdk-core/src/bitgo/trading/tradingPartner.ts deleted file mode 100644 index 89ecd60b42..0000000000 --- a/modules/sdk-core/src/bitgo/trading/tradingPartner.ts +++ /dev/null @@ -1,52 +0,0 @@ -/** - * @prettier - */ -import { BitGoBase } from '../bitgoBase'; -import { ITradingPartner, TradingAccount, TradingPartnerStatus, TradingPartnerType } from '../trading'; - -export class TradingPartner implements ITradingPartner { - private bitgo: BitGoBase; - private enterpriseId: string; - private currentAccount: TradingAccount; // account of the user using the SDK, needed to construct balance check URL - - public id: string; - public primaryEnterpriseName: string; - public primaryAccountId: string; - public secondaryEnterpriseName: string; - public secondaryAccountId: string; - public requesterAccountId: string; - public status: TradingPartnerStatus; - public type: TradingPartnerType; - - constructor(tradingPartnerData: any, bitgo: BitGoBase, enterpriseId: string, currentAccount: TradingAccount) { - this.id = tradingPartnerData.id; - this.primaryEnterpriseName = tradingPartnerData.primaryEnterpriseName; - this.primaryAccountId = tradingPartnerData.primaryAccountId; - this.secondaryEnterpriseName = tradingPartnerData.secondaryEnterpriseName; - this.secondaryAccountId = tradingPartnerData.secondaryAccountId; - this.requesterAccountId = tradingPartnerData.requesterAccountId; - this.status = tradingPartnerData.status; - this.type = tradingPartnerData.type; - - this.bitgo = bitgo; - this.enterpriseId = enterpriseId; - this.currentAccount = currentAccount; - } - - /** - * Check if a trading partner has enough funds to cover the cost of a trade. - * @param currency the currency to check - * @param amount the amount of currency to check, represented in base units (such as cents, satoshi, or wei) - */ - async checkBalance(currency: string, amount: string): Promise { - const partnerAccountId = - this.primaryAccountId === this.currentAccount.id ? this.secondaryAccountId : this.primaryAccountId; - const url = this.bitgo.microservicesUrl( - `/api/trade/v1/enterprise/${this.enterpriseId}/account/${this.currentAccount.id}/tradingpartners/${partnerAccountId}/balance` - ); - - const response = (await this.bitgo.get(url).query({ currency, amount }).result()) as any; - - return response.check; - } -} diff --git a/modules/sdk-core/src/bitgo/trading/tradingPartners.ts b/modules/sdk-core/src/bitgo/trading/tradingPartners.ts deleted file mode 100644 index 06ec2bd068..0000000000 --- a/modules/sdk-core/src/bitgo/trading/tradingPartners.ts +++ /dev/null @@ -1,46 +0,0 @@ -/** - * @prettier - */ -import { BitGoBase } from '../bitgoBase'; -import { ITradingPartners, TradingAccount, TradingPartner, TradingPartnerAddByCodeParameters } from '../trading'; - -export class TradingPartners implements ITradingPartners { - private bitgo: BitGoBase; - - private enterpriseId: string; - private account: TradingAccount; - - constructor(bitgo: BitGoBase, enterpriseId: string, account: TradingAccount) { - this.bitgo = bitgo; - this.enterpriseId = enterpriseId; - this.account = account; - } - - /** - * List all trading partners of your trading account. Your trading partners are the accounts you are allowed to settle with. - */ - async list(): Promise { - const url = this.bitgo.microservicesUrl( - `/api/trade/v1/enterprise/${this.enterpriseId}/account/${this.account.id}/tradingpartners` - ); - const response = (await this.bitgo.get(url).result()) as any; - - return response.tradingPartners.map( - (partner) => new TradingPartner(partner, this.bitgo, this.enterpriseId, this.account) - ); - } - - /** - * Add trading partner given the unique referralCode provided by trading partner. - * @param params - * @param params.referralCode unique referral code provided by counterparty - * @param params.type type of trading partnership - * @param params.requesterSide side of the requester (primary or secondary) important for agency relationships - */ - async addByCode(params: TradingPartnerAddByCodeParameters): Promise { - const url = this.bitgo.microservicesUrl( - `/api/trade/v1/enterprise/${this.enterpriseId}/account/${this.account.id}/tradingpartners` - ); - return await this.bitgo.post(url).send(params).result(); - } -}