@owneraio/finp2p-sdk-js 0.28.26 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +93 -2
- package/lib/OwneraAPI/__tests__/apiErrorShape.test.d.ts +1 -0
- package/lib/OwneraAPI/__tests__/apiErrorShape.test.js +264 -0
- package/lib/OwneraAPI/__tests__/apiErrorShape.test.js.map +1 -0
- package/lib/OwneraAPI/__tests__/utils.test.d.ts +1 -0
- package/lib/OwneraAPI/__tests__/utils.test.js +82 -0
- package/lib/OwneraAPI/__tests__/utils.test.js.map +1 -0
- package/lib/OwneraAPI/finp2p-node-api/__tests__/agreements.test.d.ts +1 -0
- package/lib/OwneraAPI/finp2p-node-api/__tests__/agreements.test.js +149 -0
- package/lib/OwneraAPI/finp2p-node-api/__tests__/agreements.test.js.map +1 -0
- package/lib/OwneraAPI/finp2p-node-api/__tests__/approvalsConfig.test.js +5 -12
- package/lib/OwneraAPI/finp2p-node-api/__tests__/approvalsConfig.test.js.map +1 -1
- package/lib/OwneraAPI/finp2p-node-api/__tests__/collateral.test.d.ts +1 -0
- package/lib/OwneraAPI/finp2p-node-api/__tests__/collateral.test.js +502 -0
- package/lib/OwneraAPI/finp2p-node-api/__tests__/collateral.test.js.map +1 -0
- package/lib/OwneraAPI/finp2p-node-api/__tests__/createIntentMetadata.test.d.ts +1 -0
- package/lib/OwneraAPI/finp2p-node-api/__tests__/createIntentMetadata.test.js +56 -0
- package/lib/OwneraAPI/finp2p-node-api/__tests__/createIntentMetadata.test.js.map +1 -0
- package/lib/OwneraAPI/finp2p-node-api/__tests__/dryRunExecute.test.d.ts +1 -0
- package/lib/OwneraAPI/finp2p-node-api/__tests__/dryRunExecute.test.js +75 -0
- package/lib/OwneraAPI/finp2p-node-api/__tests__/dryRunExecute.test.js.map +1 -0
- package/lib/OwneraAPI/finp2p-node-api/__tests__/pathEncoding.test.d.ts +1 -0
- package/lib/OwneraAPI/finp2p-node-api/__tests__/pathEncoding.test.js +348 -0
- package/lib/OwneraAPI/finp2p-node-api/__tests__/pathEncoding.test.js.map +1 -0
- package/lib/OwneraAPI/finp2p-node-api/__tests__/rejectIntent.test.d.ts +1 -0
- package/lib/OwneraAPI/finp2p-node-api/__tests__/rejectIntent.test.js +97 -0
- package/lib/OwneraAPI/finp2p-node-api/__tests__/rejectIntent.test.js.map +1 -0
- package/lib/OwneraAPI/finp2p-node-api/agreements.d.ts +8 -0
- package/lib/OwneraAPI/finp2p-node-api/agreements.js +31 -0
- package/lib/OwneraAPI/finp2p-node-api/agreements.js.map +1 -0
- package/lib/OwneraAPI/finp2p-node-api/certificates.js +15 -6
- package/lib/OwneraAPI/finp2p-node-api/certificates.js.map +1 -1
- package/lib/OwneraAPI/finp2p-node-api/collateral.d.ts +16 -0
- package/lib/OwneraAPI/finp2p-node-api/collateral.js +131 -0
- package/lib/OwneraAPI/finp2p-node-api/collateral.js.map +1 -0
- package/lib/OwneraAPI/finp2p-node-api/custodies.js +13 -2
- package/lib/OwneraAPI/finp2p-node-api/custodies.js.map +1 -1
- package/lib/OwneraAPI/finp2p-node-api/documents.js +22 -9
- package/lib/OwneraAPI/finp2p-node-api/documents.js.map +1 -1
- package/lib/OwneraAPI/finp2p-node-api/investorAccounts.d.ts +13 -0
- package/lib/OwneraAPI/finp2p-node-api/investorAccounts.js +71 -0
- package/lib/OwneraAPI/finp2p-node-api/investorAccounts.js.map +1 -0
- package/lib/OwneraAPI/finp2p-node-api/ledgers.js +13 -2
- package/lib/OwneraAPI/finp2p-node-api/ledgers.js.map +1 -1
- package/lib/OwneraAPI/finp2p-node-api/messages.js +12 -3
- package/lib/OwneraAPI/finp2p-node-api/messages.js.map +1 -1
- package/lib/OwneraAPI/finp2p-node-api/operations.js +37 -15
- package/lib/OwneraAPI/finp2p-node-api/operations.js.map +1 -1
- package/lib/OwneraAPI/finp2p-node-api/policies.js +14 -5
- package/lib/OwneraAPI/finp2p-node-api/policies.js.map +1 -1
- package/lib/OwneraAPI/finp2p-node-api/profiles.js +82 -45
- package/lib/OwneraAPI/finp2p-node-api/profiles.js.map +1 -1
- package/lib/OwneraAPI/finp2p-node-api/tokens.js +20 -0
- package/lib/OwneraAPI/finp2p-node-api/tokens.js.map +1 -1
- package/lib/OwneraAPI/index.js +6 -0
- package/lib/OwneraAPI/index.js.map +1 -1
- package/lib/OwneraAPI/oss-api/__tests__/buildGraphQLQuery.test.d.ts +1 -0
- package/lib/OwneraAPI/oss-api/__tests__/buildGraphQLQuery.test.js +253 -0
- package/lib/OwneraAPI/oss-api/__tests__/buildGraphQLQuery.test.js.map +1 -0
- package/lib/OwneraAPI/oss-api/__tests__/filterUtils.test.d.ts +1 -0
- package/lib/OwneraAPI/oss-api/__tests__/filterUtils.test.js +15 -0
- package/lib/OwneraAPI/oss-api/__tests__/filterUtils.test.js.map +1 -0
- package/lib/OwneraAPI/oss-api/__tests__/getAgreements.test.d.ts +1 -0
- package/lib/OwneraAPI/oss-api/__tests__/getAgreements.test.js +175 -0
- package/lib/OwneraAPI/oss-api/__tests__/getAgreements.test.js.map +1 -0
- package/lib/OwneraAPI/oss-api/__tests__/getAllExecutionPlans.test.js +52 -0
- package/lib/OwneraAPI/oss-api/__tests__/getAllExecutionPlans.test.js.map +1 -1
- package/lib/OwneraAPI/oss-api/__tests__/getCollateralAgreements.test.d.ts +1 -0
- package/lib/OwneraAPI/oss-api/__tests__/getCollateralAgreements.test.js +321 -0
- package/lib/OwneraAPI/oss-api/__tests__/getCollateralAgreements.test.js.map +1 -0
- package/lib/OwneraAPI/oss-api/__tests__/getCollateralReports.test.d.ts +1 -0
- package/lib/OwneraAPI/oss-api/__tests__/getCollateralReports.test.js +152 -0
- package/lib/OwneraAPI/oss-api/__tests__/getCollateralReports.test.js.map +1 -0
- package/lib/OwneraAPI/oss-api/__tests__/ossQueryEscaping.test.d.ts +1 -0
- package/lib/OwneraAPI/oss-api/__tests__/ossQueryEscaping.test.js +347 -0
- package/lib/OwneraAPI/oss-api/__tests__/ossQueryEscaping.test.js.map +1 -0
- package/lib/OwneraAPI/oss-api/filterUtils.d.ts +20 -0
- package/lib/OwneraAPI/oss-api/filterUtils.js +57 -5
- package/lib/OwneraAPI/oss-api/filterUtils.js.map +1 -1
- package/lib/OwneraAPI/oss-api/oss.js +730 -74
- package/lib/OwneraAPI/oss-api/oss.js.map +1 -1
- package/lib/OwneraAPI/oss-api/queryUtils.d.ts +1 -0
- package/lib/OwneraAPI/oss-api/queryUtils.js +6 -5
- package/lib/OwneraAPI/oss-api/queryUtils.js.map +1 -1
- package/lib/OwneraAPI/oss-api/queryValidation.d.ts +3 -1
- package/lib/OwneraAPI/oss-api/queryValidation.js +21 -2
- package/lib/OwneraAPI/oss-api/queryValidation.js.map +1 -1
- package/lib/OwneraAPI/payment-adapter-api/__tests__/updateBalance.test.d.ts +1 -0
- package/lib/OwneraAPI/payment-adapter-api/__tests__/updateBalance.test.js +42 -0
- package/lib/OwneraAPI/payment-adapter-api/__tests__/updateBalance.test.js.map +1 -0
- package/lib/OwneraAPI/payment-adapter-api/vanilla/__tests__/payouts.test.d.ts +1 -0
- package/lib/OwneraAPI/payment-adapter-api/vanilla/__tests__/payouts.test.js +73 -0
- package/lib/OwneraAPI/payment-adapter-api/vanilla/__tests__/payouts.test.js.map +1 -0
- package/lib/OwneraAPI/payment-adapter-api/vanilla/payouts.js +23 -11
- package/lib/OwneraAPI/payment-adapter-api/vanilla/payouts.js.map +1 -1
- package/lib/OwneraAPI/payment-adapter-api/vanilla/update-balance.d.ts +1 -1
- package/lib/OwneraAPI/payment-adapter-api/vanilla/update-balance.js +3 -1
- package/lib/OwneraAPI/payment-adapter-api/vanilla/update-balance.js.map +1 -1
- package/lib/OwneraAPI/utils.d.ts +39 -0
- package/lib/OwneraAPI/utils.js +176 -82
- package/lib/OwneraAPI/utils.js.map +1 -1
- package/lib/core/__tests__/consoleLogger.test.d.ts +1 -0
- package/lib/core/__tests__/consoleLogger.test.js +269 -0
- package/lib/core/__tests__/consoleLogger.test.js.map +1 -0
- package/lib/core/__tests__/createAssetNameUniqueness.test.d.ts +1 -0
- package/lib/core/__tests__/createAssetNameUniqueness.test.js +95 -0
- package/lib/core/__tests__/createAssetNameUniqueness.test.js.map +1 -0
- package/lib/core/__tests__/custodianPrecedence.test.d.ts +1 -0
- package/lib/core/__tests__/custodianPrecedence.test.js +683 -0
- package/lib/core/__tests__/custodianPrecedence.test.js.map +1 -0
- package/lib/core/__tests__/executeIntentSettlementAssets.test.d.ts +1 -0
- package/lib/core/__tests__/executeIntentSettlementAssets.test.js +128 -0
- package/lib/core/__tests__/executeIntentSettlementAssets.test.js.map +1 -0
- package/lib/core/__tests__/logException.test.d.ts +1 -0
- package/lib/core/__tests__/logException.test.js +49 -0
- package/lib/core/__tests__/logException.test.js.map +1 -0
- package/lib/core/__tests__/multiplyDecimalStrings.test.d.ts +1 -0
- package/lib/core/__tests__/multiplyDecimalStrings.test.js +37 -0
- package/lib/core/__tests__/multiplyDecimalStrings.test.js.map +1 -0
- package/lib/core/__tests__/settlementExecutionAmount.test.d.ts +1 -0
- package/lib/core/__tests__/settlementExecutionAmount.test.js +300 -0
- package/lib/core/__tests__/settlementExecutionAmount.test.js.map +1 -0
- package/lib/core/asset.js +21 -27
- package/lib/core/asset.js.map +1 -1
- package/lib/core/custodian.d.ts +30 -0
- package/lib/core/custodian.js +49 -0
- package/lib/core/custodian.js.map +1 -0
- package/lib/core/index.d.ts +1 -0
- package/lib/core/index.js +3 -1
- package/lib/core/index.js.map +1 -1
- package/lib/core/intents/__tests__/intentErrorCode.test.d.ts +1 -0
- package/lib/core/intents/__tests__/intentErrorCode.test.js +111 -0
- package/lib/core/intents/__tests__/intentErrorCode.test.js.map +1 -0
- package/lib/core/intents/__tests__/intentHandleReject.test.d.ts +1 -0
- package/lib/core/intents/__tests__/intentHandleReject.test.js +50 -0
- package/lib/core/intents/__tests__/intentHandleReject.test.js.map +1 -0
- package/lib/core/intents/__tests__/loanIntentAdditionalAccounts.test.d.ts +1 -0
- package/lib/core/intents/__tests__/loanIntentAdditionalAccounts.test.js +185 -0
- package/lib/core/intents/__tests__/loanIntentAdditionalAccounts.test.js.map +1 -0
- package/lib/core/intents/__tests__/loanIntentCustodianPrecedence.test.d.ts +1 -0
- package/lib/core/intents/__tests__/loanIntentCustodianPrecedence.test.js +85 -0
- package/lib/core/intents/__tests__/loanIntentCustodianPrecedence.test.js.map +1 -0
- package/lib/core/intents/__tests__/loanIntentMetadata.test.d.ts +1 -0
- package/lib/core/intents/__tests__/loanIntentMetadata.test.js +81 -0
- package/lib/core/intents/__tests__/loanIntentMetadata.test.js.map +1 -0
- package/lib/core/intents/__tests__/moveIntentSegregatedAccounts.test.d.ts +1 -0
- package/lib/core/intents/__tests__/moveIntentSegregatedAccounts.test.js +203 -0
- package/lib/core/intents/__tests__/moveIntentSegregatedAccounts.test.js.map +1 -0
- package/lib/core/intents/createIntent/createIntent.js +4 -3
- package/lib/core/intents/createIntent/createIntent.js.map +1 -1
- package/lib/core/intents/createIntent/createMoveIntentReq.d.ts +0 -1
- package/lib/core/intents/createIntent/createMoveIntentReq.js +15 -8
- package/lib/core/intents/createIntent/createMoveIntentReq.js.map +1 -1
- package/lib/core/intents/createIntent/helpers.d.ts +6 -2
- package/lib/core/intents/createIntent/helpers.js +27 -17
- package/lib/core/intents/createIntent/helpers.js.map +1 -1
- package/lib/core/intents/createLoanIntent.js +64 -19
- package/lib/core/intents/createLoanIntent.js.map +1 -1
- package/lib/core/intents/executeIntent.js +102 -41
- package/lib/core/intents/executeIntent.js.map +1 -1
- package/lib/core/intents/executeLoanIntent.js +48 -23
- package/lib/core/intents/executeLoanIntent.js.map +1 -1
- package/lib/core/intents/executeMoveIntent.js.map +1 -1
- package/lib/core/intents/executePrivateIntent.js +46 -13
- package/lib/core/intents/executePrivateIntent.js.map +1 -1
- package/lib/core/intents/executeRedemptionIntent.d.ts +1 -0
- package/lib/core/intents/executeRedemptionIntent.js +23 -9
- package/lib/core/intents/executeRedemptionIntent.js.map +1 -1
- package/lib/core/intents/executeTransferRequest.d.ts +5 -0
- package/lib/core/intents/executeTransferRequest.js +14 -3
- package/lib/core/intents/executeTransferRequest.js.map +1 -1
- package/lib/core/intents/getIntent.js +9 -0
- package/lib/core/intents/getIntent.js.map +1 -1
- package/lib/core/intents/transfer.js +7 -2
- package/lib/core/intents/transfer.js.map +1 -1
- package/lib/core/intents/updateMoveIntentReq.d.ts +4 -3
- package/lib/core/intents/updateMoveIntentReq.js +14 -12
- package/lib/core/intents/updateMoveIntentReq.js.map +1 -1
- package/lib/core/intents/utils.d.ts +15 -7
- package/lib/core/intents/utils.js +35 -26
- package/lib/core/intents/utils.js.map +1 -1
- package/lib/core/logger.js +128 -22
- package/lib/core/logger.js.map +1 -1
- package/lib/core/normalizers/__tests__/normalizeOperationResponse.test.d.ts +1 -0
- package/lib/core/normalizers/__tests__/normalizeOperationResponse.test.js +60 -0
- package/lib/core/normalizers/__tests__/normalizeOperationResponse.test.js.map +1 -0
- package/lib/core/normalizers/normalizeOperationResponse.d.ts +6 -0
- package/lib/core/normalizers/normalizeOperationResponse.js +4 -5
- package/lib/core/normalizers/normalizeOperationResponse.js.map +1 -1
- package/lib/core/sdk.d.ts +4 -0
- package/lib/core/sdk.js +2 -2
- package/lib/core/sdk.js.map +1 -1
- package/lib/core/user.d.ts +2 -2
- package/lib/core/user.js +6 -3
- package/lib/core/user.js.map +1 -1
- package/lib/core/utils.d.ts +17 -1
- package/lib/core/utils.js +75 -16
- package/lib/core/utils.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/types/Agreements/Agreements.d.ts +355 -0
- package/lib/types/Agreements/Agreements.js +3 -0
- package/lib/types/Agreements/Agreements.js.map +1 -0
- package/lib/types/Agreements/index.d.ts +1 -0
- package/lib/types/Agreements/index.js +18 -0
- package/lib/types/Agreements/index.js.map +1 -0
- package/lib/types/Collateral/Collateral.d.ts +564 -0
- package/lib/types/Collateral/Collateral.js +3 -0
- package/lib/types/Collateral/Collateral.js.map +1 -0
- package/lib/types/Collateral/index.d.ts +1 -0
- package/lib/types/Collateral/index.js +18 -0
- package/lib/types/Collateral/index.js.map +1 -0
- package/lib/types/Core/Intents.d.ts +115 -3
- package/lib/types/Core/Intents.js +9 -0
- package/lib/types/Core/Intents.js.map +1 -1
- package/lib/types/Core/OwneraAPI.d.ts +25 -1
- package/lib/types/Core/User.d.ts +28 -3
- package/lib/types/InvestorAccounts/InvestorAccounts.d.ts +171 -0
- package/lib/types/InvestorAccounts/InvestorAccounts.js +35 -0
- package/lib/types/InvestorAccounts/InvestorAccounts.js.map +1 -0
- package/lib/types/InvestorAccounts/index.d.ts +1 -0
- package/lib/types/InvestorAccounts/index.js +18 -0
- package/lib/types/InvestorAccounts/index.js.map +1 -0
- package/lib/types/Operations/Operations.d.ts +11 -0
- package/lib/types/Oss/Agreements.d.ts +671 -0
- package/lib/types/Oss/Agreements.js +3 -0
- package/lib/types/Oss/Agreements.js.map +1 -0
- package/lib/types/Oss/Oss.d.ts +81 -1
- package/lib/types/Oss/OssSchemas.d.ts +50 -0
- package/lib/types/Oss/OssSchemas.js.map +1 -1
- package/lib/types/Oss/index.d.ts +1 -0
- package/lib/types/Oss/index.js +1 -0
- package/lib/types/Oss/index.js.map +1 -1
- package/lib/types/Oss/utils.d.ts +39 -0
- package/lib/types/PaymentAdapter/PaymentAdapter.d.ts +7 -0
- package/lib/types/PaymentAdapter/index.d.ts +33 -1
- package/lib/types/Profiles/Intents.d.ts +24 -12
- package/lib/types/Profiles/Profiles.d.ts +46 -1
- package/lib/types/Tokens/Tokens.d.ts +109 -1
- package/lib/types/index.d.ts +3 -0
- package/lib/types/index.js +3 -0
- package/lib/types/index.js.map +1 -1
- package/lib/types/utils.d.ts +5 -0
- package/lib/types/utils.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,683 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const user_1 = require("../user");
|
|
13
|
+
const transfer_1 = require("../intents/transfer");
|
|
14
|
+
const executeIntent_1 = require("../intents/executeIntent");
|
|
15
|
+
const executeLoanIntent_1 = require("../intents/executeLoanIntent");
|
|
16
|
+
const executePrivateIntent_1 = require("../intents/executePrivateIntent");
|
|
17
|
+
const custodian_1 = require("../custodian");
|
|
18
|
+
const DEFAULT_CUSTODIAN = 'default-custodian';
|
|
19
|
+
const makeLogger = () => ({
|
|
20
|
+
debug: jest.fn(),
|
|
21
|
+
info: jest.fn(),
|
|
22
|
+
warning: jest.fn(),
|
|
23
|
+
error: jest.fn(),
|
|
24
|
+
});
|
|
25
|
+
describe('defaultCustodianOrgId', () => {
|
|
26
|
+
it('returns the default unchanged and logs it at debug with the site name', () => {
|
|
27
|
+
const logger = makeLogger();
|
|
28
|
+
expect((0, custodian_1.defaultCustodianOrgId)(DEFAULT_CUSTODIAN, 'some.site', logger)).toBe(DEFAULT_CUSTODIAN);
|
|
29
|
+
expect(logger.warning).not.toHaveBeenCalled();
|
|
30
|
+
expect(logger.debug).toHaveBeenCalledTimes(1);
|
|
31
|
+
expect(logger.debug.mock.calls[0][0]).toContain('some.site');
|
|
32
|
+
expect(logger.debug.mock.calls[0][0]).toContain(DEFAULT_CUSTODIAN);
|
|
33
|
+
});
|
|
34
|
+
it('throws a named error when no default is configured', () => {
|
|
35
|
+
const logger = makeLogger();
|
|
36
|
+
expect(() => (0, custodian_1.defaultCustodianOrgId)('', 'some.site', logger)).toThrow(expect.objectContaining({
|
|
37
|
+
code: 400,
|
|
38
|
+
name: custodian_1.CUSTODIAN_ORG_ID_ERROR,
|
|
39
|
+
data: { site: 'some.site' },
|
|
40
|
+
}));
|
|
41
|
+
expect(logger.error).toHaveBeenCalledTimes(1);
|
|
42
|
+
});
|
|
43
|
+
it('names the site and both remedies in the error message', () => {
|
|
44
|
+
const logger = makeLogger();
|
|
45
|
+
try {
|
|
46
|
+
(0, custodian_1.defaultCustodianOrgId)('', 'user.addAccount', logger);
|
|
47
|
+
throw new Error('expected defaultCustodianOrgId to throw');
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
const { message } = e;
|
|
51
|
+
expect(message).toContain('user.addAccount');
|
|
52
|
+
expect(message).toContain('Pass a custodian with the call');
|
|
53
|
+
expect(message).toContain("set a default 'custodianOrgId'");
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
describe('addAccount custodian precedence', () => {
|
|
58
|
+
const makeOwneraAPI = (addAccountMock) => ({ profiles: { addAccount: addAccountMock } });
|
|
59
|
+
it('prefers the per-call custodianOrgId over the default', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
+
const profilesAddAccount = jest.fn().mockResolvedValue({});
|
|
61
|
+
const logger = makeLogger();
|
|
62
|
+
yield (0, user_1.addAccount)({ owneraAPI: makeOwneraAPI(profilesAddAccount), logger, custodianOrgId: DEFAULT_CUSTODIAN, userId: 'user-1' }, { custodianOrgId: 'bank-uk' });
|
|
63
|
+
expect(profilesAddAccount).toHaveBeenCalledWith({ orgId: 'bank-uk', ownerId: 'user-1' }, { idempotency: undefined });
|
|
64
|
+
expect(logger.warning).not.toHaveBeenCalled();
|
|
65
|
+
}));
|
|
66
|
+
it('falls back to the Sdk default when no per-call value is given', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
+
const profilesAddAccount = jest.fn().mockResolvedValue({});
|
|
68
|
+
const logger = makeLogger();
|
|
69
|
+
yield (0, user_1.addAccount)({
|
|
70
|
+
owneraAPI: makeOwneraAPI(profilesAddAccount),
|
|
71
|
+
logger,
|
|
72
|
+
custodianOrgId: DEFAULT_CUSTODIAN,
|
|
73
|
+
userId: 'user-1',
|
|
74
|
+
});
|
|
75
|
+
expect(profilesAddAccount).toHaveBeenCalledWith({ orgId: DEFAULT_CUSTODIAN, ownerId: 'user-1' }, { idempotency: undefined });
|
|
76
|
+
expect(logger.warning).not.toHaveBeenCalled();
|
|
77
|
+
}));
|
|
78
|
+
it('passes the per-call value through alongside the idempotency key', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
79
|
+
const profilesAddAccount = jest.fn().mockResolvedValue({});
|
|
80
|
+
const logger = makeLogger();
|
|
81
|
+
yield (0, user_1.addAccount)({ owneraAPI: makeOwneraAPI(profilesAddAccount), logger, custodianOrgId: DEFAULT_CUSTODIAN, userId: 'user-1' }, { custodianOrgId: 'bank-uk', idempotencyKey: 'key-1' });
|
|
82
|
+
expect(profilesAddAccount).toHaveBeenCalledWith({ orgId: 'bank-uk', ownerId: 'user-1' }, { idempotency: 'key-1' });
|
|
83
|
+
}));
|
|
84
|
+
it('fails without calling the Router when neither a per-call custodian nor a default is set', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
85
|
+
const profilesAddAccount = jest.fn().mockResolvedValue({});
|
|
86
|
+
const logger = makeLogger();
|
|
87
|
+
yield expect((0, user_1.addAccount)({ owneraAPI: makeOwneraAPI(profilesAddAccount), logger, custodianOrgId: '', userId: 'user-1' })).rejects.toEqual(expect.objectContaining({ name: custodian_1.CUSTODIAN_ORG_ID_ERROR, data: { site: 'user.addAccount' } }));
|
|
88
|
+
expect(profilesAddAccount).not.toHaveBeenCalled();
|
|
89
|
+
}));
|
|
90
|
+
it('treats an explicit empty-string per-call custodian as absent and uses the default', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
91
|
+
const profilesAddAccount = jest.fn().mockResolvedValue({});
|
|
92
|
+
const logger = makeLogger();
|
|
93
|
+
yield (0, user_1.addAccount)({ owneraAPI: makeOwneraAPI(profilesAddAccount), logger, custodianOrgId: DEFAULT_CUSTODIAN, userId: 'user-1' }, { custodianOrgId: '' });
|
|
94
|
+
expect(profilesAddAccount).toHaveBeenCalledWith({ orgId: DEFAULT_CUSTODIAN, ownerId: 'user-1' }, { idempotency: undefined });
|
|
95
|
+
}));
|
|
96
|
+
it('fails when the per-call custodian is an empty string and no default is set — never ships ""', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
|
+
const profilesAddAccount = jest.fn().mockResolvedValue({});
|
|
98
|
+
const logger = makeLogger();
|
|
99
|
+
yield expect((0, user_1.addAccount)({ owneraAPI: makeOwneraAPI(profilesAddAccount), logger, custodianOrgId: '', userId: 'user-1' }, { custodianOrgId: '' })).rejects.toEqual(expect.objectContaining({ name: custodian_1.CUSTODIAN_ORG_ID_ERROR, data: { site: 'user.addAccount' } }));
|
|
100
|
+
expect(profilesAddAccount).not.toHaveBeenCalled();
|
|
101
|
+
}));
|
|
102
|
+
});
|
|
103
|
+
describe('transfer custodian precedence', () => {
|
|
104
|
+
const account = (finId, custodianOrgId) => ({
|
|
105
|
+
asset: { resourceId: 'org:102:asset-1' },
|
|
106
|
+
account: Object.assign({ finId, orgId: 'org' }, (custodianOrgId === undefined ? {} : { custodian: { orgId: custodianOrgId } })),
|
|
107
|
+
});
|
|
108
|
+
const runTransfer = (overrides) => __awaiter(void 0, void 0, void 0, function* () {
|
|
109
|
+
const executeTransfer = jest.fn().mockResolvedValue({ executionPlanId: 'plan-1' });
|
|
110
|
+
const logger = makeLogger();
|
|
111
|
+
const owneraAPI = {
|
|
112
|
+
query: { getAssets: jest.fn().mockResolvedValue({ data: [{ ledgerAssetInfo: {} }] }) },
|
|
113
|
+
tokens: { transfer: executeTransfer },
|
|
114
|
+
};
|
|
115
|
+
yield (0, transfer_1.transfer)({
|
|
116
|
+
owneraAPI,
|
|
117
|
+
logger,
|
|
118
|
+
custodianOrgId: DEFAULT_CUSTODIAN,
|
|
119
|
+
userId: 'user-1',
|
|
120
|
+
userPublicKey: 'pk',
|
|
121
|
+
data: {
|
|
122
|
+
source: 'src',
|
|
123
|
+
destination: 'dst',
|
|
124
|
+
amount: '1',
|
|
125
|
+
asset: {},
|
|
126
|
+
sourceAccount: account('src-fin', overrides.sourceCustodian),
|
|
127
|
+
destinationAccount: account('dst-fin', overrides.destCustodian),
|
|
128
|
+
sourceFallbackCustodianOrgId: overrides.sourceFallbackCustodianOrgId,
|
|
129
|
+
destinationFallbackCustodianOrgId: overrides.destinationFallbackCustodianOrgId,
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
const request = executeTransfer.mock.calls[0][0];
|
|
133
|
+
return {
|
|
134
|
+
logger,
|
|
135
|
+
source: request.asset.instruction.sourceAccount.account.custodian.orgId,
|
|
136
|
+
destination: request.asset.instruction.destinationAccount.account.custodian.orgId,
|
|
137
|
+
};
|
|
138
|
+
});
|
|
139
|
+
it("prefers each account's own custodian over everything else", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
140
|
+
const { source, destination, logger } = yield runTransfer({
|
|
141
|
+
sourceCustodian: 'bank-us',
|
|
142
|
+
destCustodian: 'bank-uk',
|
|
143
|
+
sourceFallbackCustodianOrgId: 'bank-repo',
|
|
144
|
+
destinationFallbackCustodianOrgId: 'bank-repo',
|
|
145
|
+
});
|
|
146
|
+
expect(source).toBe('bank-us');
|
|
147
|
+
expect(destination).toBe('bank-uk');
|
|
148
|
+
expect(logger.warning).not.toHaveBeenCalled();
|
|
149
|
+
}));
|
|
150
|
+
it('applies each per-call fallback to its own side only — the two sides are different owners', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
151
|
+
const { source, destination, logger } = yield runTransfer({
|
|
152
|
+
sourceFallbackCustodianOrgId: 'bank-us',
|
|
153
|
+
destinationFallbackCustodianOrgId: 'bank-uk',
|
|
154
|
+
});
|
|
155
|
+
expect(source).toBe('bank-us');
|
|
156
|
+
expect(destination).toBe('bank-uk');
|
|
157
|
+
expect(logger.warning).not.toHaveBeenCalled();
|
|
158
|
+
}));
|
|
159
|
+
it('falls back to the Sdk default per side when nothing else is supplied', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
160
|
+
const { source, destination, logger } = yield runTransfer({});
|
|
161
|
+
expect(source).toBe(DEFAULT_CUSTODIAN);
|
|
162
|
+
expect(destination).toBe(DEFAULT_CUSTODIAN);
|
|
163
|
+
expect(logger.warning).not.toHaveBeenCalled();
|
|
164
|
+
}));
|
|
165
|
+
it('mixes sources: account custodian on one side, per-call value on the other', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
166
|
+
const { source, destination, logger } = yield runTransfer({
|
|
167
|
+
sourceCustodian: 'bank-us',
|
|
168
|
+
destinationFallbackCustodianOrgId: 'bank-repo',
|
|
169
|
+
});
|
|
170
|
+
expect(source).toBe('bank-us');
|
|
171
|
+
expect(destination).toBe('bank-repo');
|
|
172
|
+
expect(logger.warning).not.toHaveBeenCalled();
|
|
173
|
+
}));
|
|
174
|
+
it('resolves each side independently: per-call fallback on one, default on the other', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
175
|
+
const { source, destination, logger } = yield runTransfer({ sourceFallbackCustodianOrgId: 'bank-us' });
|
|
176
|
+
expect(source).toBe('bank-us');
|
|
177
|
+
expect(destination).toBe(DEFAULT_CUSTODIAN);
|
|
178
|
+
expect(logger.warning).not.toHaveBeenCalled();
|
|
179
|
+
}));
|
|
180
|
+
});
|
|
181
|
+
describe('executeIntent custodian guards', () => {
|
|
182
|
+
const makeOwneraAPI = (ossAsset, executeTokenIntentMock) => ({
|
|
183
|
+
query: { getAssets: jest.fn().mockResolvedValue({ data: [ossAsset] }) },
|
|
184
|
+
tokens: { executeTokenIntent: executeTokenIntentMock },
|
|
185
|
+
});
|
|
186
|
+
const completedResponse = { cid: 'cid-1', isCompleted: true, response: { id: 'exec-1' } };
|
|
187
|
+
it('primarySale: stamps the Sdk default when the intent carries no custodian and no per-call value is given', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
188
|
+
const executeTokenIntentMock = jest.fn().mockResolvedValue(completedResponse);
|
|
189
|
+
const ossAsset = {
|
|
190
|
+
issuerId: 'issuer-1',
|
|
191
|
+
ledgerAssetInfo: {},
|
|
192
|
+
intents: [
|
|
193
|
+
{
|
|
194
|
+
id: 'intent-1',
|
|
195
|
+
type: 'primarySale',
|
|
196
|
+
intent: { destination: { account: { finId: 'issuer-fin' } }, settlementTerm: null },
|
|
197
|
+
},
|
|
198
|
+
],
|
|
199
|
+
};
|
|
200
|
+
const logger = makeLogger();
|
|
201
|
+
yield (0, executeIntent_1.executeIntent)({
|
|
202
|
+
owneraAPI: makeOwneraAPI(ossAsset, executeTokenIntentMock),
|
|
203
|
+
logger,
|
|
204
|
+
custodianOrgId: DEFAULT_CUSTODIAN,
|
|
205
|
+
userId: 'user-1',
|
|
206
|
+
userPublicKey: 'pk',
|
|
207
|
+
data: { assetId: 'org:102:asset-1', intentId: 'intent-1', amount: '1' },
|
|
208
|
+
});
|
|
209
|
+
const request = executeTokenIntentMock.mock.calls[0][0];
|
|
210
|
+
expect(request.intent.asset.assetInstruction.destinationAccount.account.custodian.orgId).toBe(DEFAULT_CUSTODIAN);
|
|
211
|
+
}));
|
|
212
|
+
it('buyingIntent: fails loudly instead of stamping "" when the intent carries no custodian and no default is set', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
213
|
+
const executeTokenIntentMock = jest.fn().mockResolvedValue(completedResponse);
|
|
214
|
+
const ossAsset = {
|
|
215
|
+
issuerId: 'issuer-1',
|
|
216
|
+
ledgerAssetInfo: {},
|
|
217
|
+
intents: [
|
|
218
|
+
{
|
|
219
|
+
id: 'intent-1',
|
|
220
|
+
type: 'buyingIntent',
|
|
221
|
+
intent: {
|
|
222
|
+
source: { account: { finId: 'owner-fin' } },
|
|
223
|
+
settlementTerm: { details: { amount: '10' } },
|
|
224
|
+
settlementInstruction: {},
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
],
|
|
228
|
+
};
|
|
229
|
+
const logger = makeLogger();
|
|
230
|
+
yield expect((0, executeIntent_1.executeIntent)({
|
|
231
|
+
owneraAPI: makeOwneraAPI(ossAsset, executeTokenIntentMock),
|
|
232
|
+
logger,
|
|
233
|
+
custodianOrgId: '',
|
|
234
|
+
userId: 'user-1',
|
|
235
|
+
userPublicKey: 'pk',
|
|
236
|
+
data: {
|
|
237
|
+
assetId: 'org:102:asset-1',
|
|
238
|
+
intentId: 'intent-1',
|
|
239
|
+
amount: '1',
|
|
240
|
+
sourceAccount: { account: { type: 'finId', finId: 'buyer-pay-fin', orgId: 'org' } },
|
|
241
|
+
destinationAccount: { account: { type: 'finId', finId: 'owner-pay-fin', orgId: 'org' } },
|
|
242
|
+
},
|
|
243
|
+
})).rejects.toEqual(expect.objectContaining({
|
|
244
|
+
name: custodian_1.CUSTODIAN_ORG_ID_ERROR,
|
|
245
|
+
data: { site: 'executeIntent.destinationAssetAccount(buyingIntent)' },
|
|
246
|
+
}));
|
|
247
|
+
expect(executeTokenIntentMock).not.toHaveBeenCalled();
|
|
248
|
+
}));
|
|
249
|
+
it('reports missing settlement accounts as such, not as a custodian resolution failure', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
250
|
+
const executeTokenIntentMock = jest.fn().mockResolvedValue(completedResponse);
|
|
251
|
+
const ossAsset = {
|
|
252
|
+
issuerId: 'issuer-1',
|
|
253
|
+
ledgerAssetInfo: {},
|
|
254
|
+
intents: [
|
|
255
|
+
{
|
|
256
|
+
id: 'intent-1',
|
|
257
|
+
type: 'buyingIntent',
|
|
258
|
+
intent: {
|
|
259
|
+
source: { account: { finId: 'owner-fin' } },
|
|
260
|
+
settlementTerm: { details: { amount: '10' } },
|
|
261
|
+
settlementInstruction: {},
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
],
|
|
265
|
+
};
|
|
266
|
+
const logger = makeLogger();
|
|
267
|
+
yield expect((0, executeIntent_1.executeIntent)({
|
|
268
|
+
owneraAPI: makeOwneraAPI(ossAsset, executeTokenIntentMock),
|
|
269
|
+
logger,
|
|
270
|
+
custodianOrgId: '',
|
|
271
|
+
userId: 'user-1',
|
|
272
|
+
userPublicKey: 'pk',
|
|
273
|
+
data: { assetId: 'org:102:asset-1', intentId: 'intent-1', amount: '1' },
|
|
274
|
+
})).rejects.toThrow(/missing sourceAccount\/destinationAccount/);
|
|
275
|
+
expect(executeTokenIntentMock).not.toHaveBeenCalled();
|
|
276
|
+
}));
|
|
277
|
+
it("buyingIntent: the intent's own custodian stays authoritative — a per-call value does not override it", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
278
|
+
const executeTokenIntentMock = jest.fn().mockResolvedValue(completedResponse);
|
|
279
|
+
const ossAsset = {
|
|
280
|
+
issuerId: 'issuer-1',
|
|
281
|
+
ledgerAssetInfo: {},
|
|
282
|
+
intents: [
|
|
283
|
+
{
|
|
284
|
+
id: 'intent-1',
|
|
285
|
+
type: 'buyingIntent',
|
|
286
|
+
intent: {
|
|
287
|
+
source: { account: { finId: 'owner-fin', custodian: { orgId: 'bank-owner' } } },
|
|
288
|
+
settlementTerm: { details: { amount: '10' } },
|
|
289
|
+
settlementInstruction: {},
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
],
|
|
293
|
+
};
|
|
294
|
+
const logger = makeLogger();
|
|
295
|
+
yield (0, executeIntent_1.executeIntent)({
|
|
296
|
+
owneraAPI: makeOwneraAPI(ossAsset, executeTokenIntentMock),
|
|
297
|
+
logger,
|
|
298
|
+
custodianOrgId: DEFAULT_CUSTODIAN,
|
|
299
|
+
userId: 'user-1',
|
|
300
|
+
userPublicKey: 'pk',
|
|
301
|
+
data: {
|
|
302
|
+
assetId: 'org:102:asset-1',
|
|
303
|
+
intentId: 'intent-1',
|
|
304
|
+
amount: '1',
|
|
305
|
+
destinationCustodianOrgId: 'bank-other',
|
|
306
|
+
sourceAccount: { account: { finId: 'buyer-pay-fin', orgId: 'org' } },
|
|
307
|
+
destinationAccount: { account: { finId: 'owner-pay-fin', orgId: 'org' } },
|
|
308
|
+
},
|
|
309
|
+
});
|
|
310
|
+
const request = executeTokenIntentMock.mock.calls[0][0];
|
|
311
|
+
expect(request.intent.asset.instruction.destinationAccount.account.custodian.orgId).toBe('bank-owner');
|
|
312
|
+
// The ignored per-call value is surfaced at debug, not dropped silently.
|
|
313
|
+
const debugMessages = logger.debug.mock.calls.map((c) => String(c[0]));
|
|
314
|
+
expect(debugMessages.some((m) => m.includes('not applied to the ASSET destination'))).toBe(true);
|
|
315
|
+
// Settlement accounts passed without a custodian resolve through the chain (here: the default)
|
|
316
|
+
// instead of shipping ''.
|
|
317
|
+
expect(request.intent.settlement.instruction.sourceAccount.account.custodian.orgId).toBe(DEFAULT_CUSTODIAN);
|
|
318
|
+
expect(request.intent.settlement.instruction.destinationAccount.account.custodian.orgId).toBe('bank-other');
|
|
319
|
+
}));
|
|
320
|
+
it("buyingIntent settlement source: falls to the caller's settlement account custodian before the default", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
321
|
+
const executeTokenIntentMock = jest.fn().mockResolvedValue(completedResponse);
|
|
322
|
+
const ossAsset = {
|
|
323
|
+
issuerId: 'issuer-1',
|
|
324
|
+
ledgerAssetInfo: {},
|
|
325
|
+
intents: [
|
|
326
|
+
{
|
|
327
|
+
id: 'intent-1',
|
|
328
|
+
type: 'buyingIntent',
|
|
329
|
+
intent: {
|
|
330
|
+
// The intent's asset account carries NO custodian, but its settlement instruction
|
|
331
|
+
// names an account — the override path.
|
|
332
|
+
source: { account: { finId: 'owner-fin' } },
|
|
333
|
+
settlementTerm: { details: { amount: '10' } },
|
|
334
|
+
settlementInstruction: { account: { account: { finId: 'owner-pay-fin', orgId: 'org' } } },
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
],
|
|
338
|
+
};
|
|
339
|
+
const logger = makeLogger();
|
|
340
|
+
yield (0, executeIntent_1.executeIntent)({
|
|
341
|
+
owneraAPI: makeOwneraAPI(ossAsset, executeTokenIntentMock),
|
|
342
|
+
logger,
|
|
343
|
+
custodianOrgId: DEFAULT_CUSTODIAN,
|
|
344
|
+
userId: 'user-1',
|
|
345
|
+
userPublicKey: 'pk',
|
|
346
|
+
data: {
|
|
347
|
+
assetId: 'org:102:asset-1',
|
|
348
|
+
intentId: 'intent-1',
|
|
349
|
+
amount: '1',
|
|
350
|
+
sourceAccount: {
|
|
351
|
+
account: { type: 'finId', finId: 'buyer-pay-fin', orgId: 'org', custodian: { orgId: 'bank-payer' } },
|
|
352
|
+
},
|
|
353
|
+
destinationAccount: { account: { type: 'finId', finId: 'owner-pay-fin', orgId: 'org' } },
|
|
354
|
+
},
|
|
355
|
+
});
|
|
356
|
+
const request = executeTokenIntentMock.mock.calls[0][0];
|
|
357
|
+
// The in-hand caller value wins over the Sdk default when the intent carries no custodian.
|
|
358
|
+
expect(request.intent.settlement.instruction.sourceAccount.account.custodian.orgId).toBe('bank-payer');
|
|
359
|
+
}));
|
|
360
|
+
it("buyingIntent settlement source: the intent's stored settlement account outranks every other value", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
361
|
+
const executeTokenIntentMock = jest.fn().mockResolvedValue(completedResponse);
|
|
362
|
+
const ossAsset = {
|
|
363
|
+
issuerId: 'issuer-1',
|
|
364
|
+
ledgerAssetInfo: {},
|
|
365
|
+
intents: [
|
|
366
|
+
{
|
|
367
|
+
id: 'intent-1',
|
|
368
|
+
type: 'buyingIntent',
|
|
369
|
+
intent: {
|
|
370
|
+
source: { account: { finId: 'owner-fin', custodian: { orgId: 'bank-owner-asset' } } },
|
|
371
|
+
settlementTerm: { details: { amount: '10' } },
|
|
372
|
+
settlementInstruction: {
|
|
373
|
+
account: {
|
|
374
|
+
account: { finId: 'owner-pay-fin', orgId: 'org', custodian: { orgId: 'bank-owner-pay' } },
|
|
375
|
+
},
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
},
|
|
379
|
+
],
|
|
380
|
+
};
|
|
381
|
+
const logger = makeLogger();
|
|
382
|
+
yield (0, executeIntent_1.executeIntent)({
|
|
383
|
+
owneraAPI: makeOwneraAPI(ossAsset, executeTokenIntentMock),
|
|
384
|
+
logger,
|
|
385
|
+
custodianOrgId: DEFAULT_CUSTODIAN,
|
|
386
|
+
userId: 'user-1',
|
|
387
|
+
userPublicKey: 'pk',
|
|
388
|
+
data: {
|
|
389
|
+
assetId: 'org:102:asset-1',
|
|
390
|
+
intentId: 'intent-1',
|
|
391
|
+
amount: '1',
|
|
392
|
+
sourceAccount: {
|
|
393
|
+
account: { type: 'finId', finId: 'buyer-pay-fin', orgId: 'org', custodian: { orgId: 'bank-payer' } },
|
|
394
|
+
},
|
|
395
|
+
destinationAccount: { account: { type: 'finId', finId: 'owner-pay-fin', orgId: 'org' } },
|
|
396
|
+
},
|
|
397
|
+
});
|
|
398
|
+
const request = executeTokenIntentMock.mock.calls[0][0];
|
|
399
|
+
// Settlement leg: the stored settlement account's own custodian, not the caller's value and
|
|
400
|
+
// not the intent's ASSET-leg custodian.
|
|
401
|
+
expect(request.intent.settlement.instruction.sourceAccount.account.custodian.orgId).toBe('bank-owner-pay');
|
|
402
|
+
}));
|
|
403
|
+
it("sellingIntent: the executor's per-call value never leaks onto the counterparty's settlement destination", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
404
|
+
const executeTokenIntentMock = jest.fn().mockResolvedValue(completedResponse);
|
|
405
|
+
const ossAsset = {
|
|
406
|
+
issuerId: 'issuer-1',
|
|
407
|
+
ledgerAssetInfo: {},
|
|
408
|
+
intents: [
|
|
409
|
+
{
|
|
410
|
+
id: 'intent-1',
|
|
411
|
+
type: 'sellingIntent',
|
|
412
|
+
intent: {
|
|
413
|
+
seller: 'seller-1',
|
|
414
|
+
source: { account: { finId: 'seller-fin', custodian: { orgId: 'bank-seller' } } },
|
|
415
|
+
settlementTerm: { details: { amount: '10' } },
|
|
416
|
+
},
|
|
417
|
+
},
|
|
418
|
+
],
|
|
419
|
+
};
|
|
420
|
+
const logger = makeLogger();
|
|
421
|
+
yield (0, executeIntent_1.executeIntent)({
|
|
422
|
+
owneraAPI: makeOwneraAPI(ossAsset, executeTokenIntentMock),
|
|
423
|
+
logger,
|
|
424
|
+
custodianOrgId: DEFAULT_CUSTODIAN,
|
|
425
|
+
userId: 'user-1',
|
|
426
|
+
userPublicKey: 'pk',
|
|
427
|
+
data: {
|
|
428
|
+
assetId: 'org:102:asset-1',
|
|
429
|
+
intentId: 'intent-1',
|
|
430
|
+
amount: '1',
|
|
431
|
+
sourceCustodianOrgId: 'bank-buyer-pay',
|
|
432
|
+
destinationCustodianOrgId: 'bank-buyer',
|
|
433
|
+
sourceAccount: { account: { type: 'finId', finId: 'buyer-pay-fin', orgId: 'org' } },
|
|
434
|
+
destinationAccount: { account: { type: 'finId', finId: 'seller-pay-fin', orgId: 'org' } },
|
|
435
|
+
},
|
|
436
|
+
});
|
|
437
|
+
const request = executeTokenIntentMock.mock.calls[0][0];
|
|
438
|
+
// The executor (buyer) owns the settlement SOURCE — per-call applies there…
|
|
439
|
+
expect(request.intent.settlement.instruction.sourceAccount.account.custodian.orgId).toBe('bank-buyer-pay');
|
|
440
|
+
// …but the settlement DESTINATION is the seller's account: the executor's per-call value is
|
|
441
|
+
// skipped and the account falls to the Sdk default.
|
|
442
|
+
expect(request.intent.settlement.instruction.destinationAccount.account.custodian.orgId).toBe(DEFAULT_CUSTODIAN);
|
|
443
|
+
// The per-call destination value still applies to the executor's own ASSET destination.
|
|
444
|
+
expect(request.intent.asset.instruction.destinationAccount.account.custodian.orgId).toBe('bank-buyer');
|
|
445
|
+
}));
|
|
446
|
+
it("sellingIntent: a counterparty settlement destination with no custodian fails loudly when there is no default — it never borrows the executor's value", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
447
|
+
const executeTokenIntentMock = jest.fn().mockResolvedValue(completedResponse);
|
|
448
|
+
const ossAsset = {
|
|
449
|
+
issuerId: 'issuer-1',
|
|
450
|
+
ledgerAssetInfo: {},
|
|
451
|
+
intents: [
|
|
452
|
+
{
|
|
453
|
+
id: 'intent-1',
|
|
454
|
+
type: 'sellingIntent',
|
|
455
|
+
intent: {
|
|
456
|
+
seller: 'seller-1',
|
|
457
|
+
source: { account: { finId: 'seller-fin', custodian: { orgId: 'bank-seller' } } },
|
|
458
|
+
settlementTerm: { details: { amount: '10' } },
|
|
459
|
+
},
|
|
460
|
+
},
|
|
461
|
+
],
|
|
462
|
+
};
|
|
463
|
+
const logger = makeLogger();
|
|
464
|
+
yield expect((0, executeIntent_1.executeIntent)({
|
|
465
|
+
owneraAPI: makeOwneraAPI(ossAsset, executeTokenIntentMock),
|
|
466
|
+
logger,
|
|
467
|
+
custodianOrgId: '',
|
|
468
|
+
userId: 'user-1',
|
|
469
|
+
userPublicKey: 'pk',
|
|
470
|
+
data: {
|
|
471
|
+
assetId: 'org:102:asset-1',
|
|
472
|
+
intentId: 'intent-1',
|
|
473
|
+
amount: '1',
|
|
474
|
+
destinationCustodianOrgId: 'bank-buyer',
|
|
475
|
+
sourceAccount: {
|
|
476
|
+
account: { type: 'finId', finId: 'buyer-pay-fin', orgId: 'org', custodian: { orgId: 'bank-buyer-pay' } },
|
|
477
|
+
},
|
|
478
|
+
destinationAccount: { account: { type: 'finId', finId: 'seller-pay-fin', orgId: 'org' } },
|
|
479
|
+
},
|
|
480
|
+
})).rejects.toEqual(expect.objectContaining({
|
|
481
|
+
name: custodian_1.CUSTODIAN_ORG_ID_ERROR,
|
|
482
|
+
data: { site: 'executeIntent.settlementDestinationAccount' },
|
|
483
|
+
}));
|
|
484
|
+
expect(executeTokenIntentMock).not.toHaveBeenCalled();
|
|
485
|
+
}));
|
|
486
|
+
it("buyingIntent: the executor's per-call source value never leaks onto the intent owner's settlement source", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
487
|
+
const executeTokenIntentMock = jest.fn().mockResolvedValue(completedResponse);
|
|
488
|
+
const ossAsset = {
|
|
489
|
+
issuerId: 'issuer-1',
|
|
490
|
+
ledgerAssetInfo: {},
|
|
491
|
+
intents: [
|
|
492
|
+
{
|
|
493
|
+
id: 'intent-1',
|
|
494
|
+
type: 'buyingIntent',
|
|
495
|
+
intent: {
|
|
496
|
+
source: { account: { finId: 'owner-fin', custodian: { orgId: 'bank-owner' } } },
|
|
497
|
+
settlementTerm: { details: { amount: '10' } },
|
|
498
|
+
settlementInstruction: {},
|
|
499
|
+
},
|
|
500
|
+
},
|
|
501
|
+
],
|
|
502
|
+
};
|
|
503
|
+
const logger = makeLogger();
|
|
504
|
+
yield (0, executeIntent_1.executeIntent)({
|
|
505
|
+
owneraAPI: makeOwneraAPI(ossAsset, executeTokenIntentMock),
|
|
506
|
+
logger,
|
|
507
|
+
custodianOrgId: DEFAULT_CUSTODIAN,
|
|
508
|
+
userId: 'user-1',
|
|
509
|
+
userPublicKey: 'pk',
|
|
510
|
+
data: {
|
|
511
|
+
assetId: 'org:102:asset-1',
|
|
512
|
+
intentId: 'intent-1',
|
|
513
|
+
amount: '1',
|
|
514
|
+
sourceCustodianOrgId: 'bank-seller-exec',
|
|
515
|
+
sourceAccount: { account: { type: 'finId', finId: 'buyer-pay-fin', orgId: 'org' } },
|
|
516
|
+
destinationAccount: { account: { type: 'finId', finId: 'seller-pay-fin', orgId: 'org' } },
|
|
517
|
+
},
|
|
518
|
+
});
|
|
519
|
+
const request = executeTokenIntentMock.mock.calls[0][0];
|
|
520
|
+
// The settlement SOURCE is the intent owner's (buyer's) paying account: with no stored intent
|
|
521
|
+
// settlement account and no custodian of its own, it falls to the default — never to the
|
|
522
|
+
// executor's per-call source value.
|
|
523
|
+
expect(request.intent.settlement.instruction.sourceAccount.account.custodian.orgId).toBe(DEFAULT_CUSTODIAN);
|
|
524
|
+
// The per-call source value still applies to the executor's own ASSET source.
|
|
525
|
+
expect(request.intent.asset.instruction.sourceAccount.account.custodian.orgId).toBe('bank-seller-exec');
|
|
526
|
+
}));
|
|
527
|
+
});
|
|
528
|
+
describe('executeLoanIntent settlement custodian alignment', () => {
|
|
529
|
+
const completedResponse = { cid: 'cid-1', isCompleted: true, response: { id: 'exec-1' } };
|
|
530
|
+
it("stored settlement accounts' own custodians outrank the per-call values shared with the asset leg", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
531
|
+
const executeTokenIntentMock = jest.fn().mockResolvedValue(completedResponse);
|
|
532
|
+
const loanDetails = {
|
|
533
|
+
borrower: 'borrower-1',
|
|
534
|
+
lender: 'lender-1',
|
|
535
|
+
assetTerm: { amount: '5' },
|
|
536
|
+
borrowerAccount: { account: { finId: 'borrower-fin', orgId: 'org' } },
|
|
537
|
+
lenderAccount: { account: { finId: 'lender-fin', orgId: 'org' } },
|
|
538
|
+
loanSettlementInstruction: {
|
|
539
|
+
borrowerAccount: {
|
|
540
|
+
account: { finId: 'borrower-pay-fin', orgId: 'org', custodian: { orgId: 'bank-borrower-pay' } },
|
|
541
|
+
},
|
|
542
|
+
lenderAccount: {
|
|
543
|
+
account: { finId: 'lender-pay-fin', orgId: 'org', custodian: { orgId: 'bank-lender-pay' } },
|
|
544
|
+
},
|
|
545
|
+
},
|
|
546
|
+
loanInstruction: { openDate: 1, closeDate: 2, loanConditions: { repaymentVolume: '6' } },
|
|
547
|
+
};
|
|
548
|
+
const owneraAPI = {
|
|
549
|
+
query: {
|
|
550
|
+
getLoanIntent: jest.fn().mockResolvedValue({ intent: { intent: loanDetails } }),
|
|
551
|
+
getAssets: jest.fn().mockResolvedValue({ data: [] }),
|
|
552
|
+
},
|
|
553
|
+
tokens: { executeTokenIntent: executeTokenIntentMock },
|
|
554
|
+
};
|
|
555
|
+
const logger = makeLogger();
|
|
556
|
+
yield (0, executeLoanIntent_1.executeLoanIntent)({
|
|
557
|
+
owneraAPI,
|
|
558
|
+
logger,
|
|
559
|
+
custodianOrgId: DEFAULT_CUSTODIAN,
|
|
560
|
+
userId: 'user-1',
|
|
561
|
+
data: {
|
|
562
|
+
assetId: 'org:102:asset-1',
|
|
563
|
+
assetName: 'asset-1',
|
|
564
|
+
executorType: 'borrower',
|
|
565
|
+
intentId: 'intent-1',
|
|
566
|
+
settlementAssetId: 'org:102:cash-1',
|
|
567
|
+
settlementTermAmount: '2',
|
|
568
|
+
sourceCustodianOrgId: 'bank-borrower-asset',
|
|
569
|
+
destinationCustodianOrgId: 'bank-lender-asset',
|
|
570
|
+
},
|
|
571
|
+
});
|
|
572
|
+
const request = executeTokenIntentMock.mock.calls[0][0];
|
|
573
|
+
// Asset legs keep the per-call values…
|
|
574
|
+
expect(request.intent.asset.assetInstruction.borrowerAccount.account.custodian.orgId).toBe('bank-borrower-asset');
|
|
575
|
+
expect(request.intent.asset.assetInstruction.lenderAccount.account.custodian.orgId).toBe('bank-lender-asset');
|
|
576
|
+
// …but the settlement legs prefer the stored settlement accounts' own custodians.
|
|
577
|
+
expect(request.intent.settlement.assetInstruction.borrowerAccount.account.custodian.orgId).toBe('bank-borrower-pay');
|
|
578
|
+
expect(request.intent.settlement.assetInstruction.lenderAccount.account.custodian.orgId).toBe('bank-lender-pay');
|
|
579
|
+
}));
|
|
580
|
+
});
|
|
581
|
+
describe('executePrivateIntent custodian resolution', () => {
|
|
582
|
+
const makeOwneraAPI = (ossAsset, executeTokenIntentMock) => ({
|
|
583
|
+
query: { getAssets: jest.fn().mockResolvedValue({ data: [ossAsset] }) },
|
|
584
|
+
tokens: { executeTokenIntent: executeTokenIntentMock },
|
|
585
|
+
});
|
|
586
|
+
const completedResponse = { cid: 'cid-1', isCompleted: true, response: { id: 'exec-1' } };
|
|
587
|
+
const issuanceAsset = (seller) => ({
|
|
588
|
+
issuerId: 'issuer-1',
|
|
589
|
+
ledgerAssetInfo: {},
|
|
590
|
+
intents: [{ id: 'intent-1', type: 'privateOfferIntent', intent: { seller, settlementTerm: null } }],
|
|
591
|
+
});
|
|
592
|
+
it('issuance: does not resolve (or throw for) a source custodian the minting branch never uses', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
593
|
+
const executeTokenIntentMock = jest.fn().mockResolvedValue(completedResponse);
|
|
594
|
+
const logger = makeLogger();
|
|
595
|
+
// No Sdk default and no per-call source custodian: must still succeed, because
|
|
596
|
+
// the issuance sourceAccount is { asset } only and carries no custodian at all.
|
|
597
|
+
yield (0, executePrivateIntent_1.executePrivateIntent)({
|
|
598
|
+
owneraAPI: makeOwneraAPI(issuanceAsset('issuer-1'), executeTokenIntentMock),
|
|
599
|
+
logger,
|
|
600
|
+
custodianOrgId: '',
|
|
601
|
+
userId: 'user-1',
|
|
602
|
+
userPublicKey: 'pk',
|
|
603
|
+
data: {
|
|
604
|
+
assetId: 'org:102:asset-1',
|
|
605
|
+
intentId: 'intent-1',
|
|
606
|
+
amount: '1',
|
|
607
|
+
destinationCustodianOrgId: 'bank-taker',
|
|
608
|
+
},
|
|
609
|
+
});
|
|
610
|
+
const request = executeTokenIntentMock.mock.calls[0][0];
|
|
611
|
+
expect(request.intent.asset.instruction.sourceAccount).toEqual({
|
|
612
|
+
asset: expect.anything(),
|
|
613
|
+
});
|
|
614
|
+
expect(request.intent.asset.instruction.destinationAccount.account.custodian.orgId).toBe('bank-taker');
|
|
615
|
+
}));
|
|
616
|
+
it('non-issuance: still fails loudly when no source custodian can be resolved', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
617
|
+
const executeTokenIntentMock = jest.fn().mockResolvedValue(completedResponse);
|
|
618
|
+
const logger = makeLogger();
|
|
619
|
+
yield expect((0, executePrivateIntent_1.executePrivateIntent)({
|
|
620
|
+
owneraAPI: makeOwneraAPI(issuanceAsset('someone-else'), executeTokenIntentMock),
|
|
621
|
+
logger,
|
|
622
|
+
custodianOrgId: '',
|
|
623
|
+
userId: 'user-1',
|
|
624
|
+
userPublicKey: 'pk',
|
|
625
|
+
data: {
|
|
626
|
+
assetId: 'org:102:asset-1',
|
|
627
|
+
intentId: 'intent-1',
|
|
628
|
+
amount: '1',
|
|
629
|
+
destinationCustodianOrgId: 'bank-taker',
|
|
630
|
+
},
|
|
631
|
+
})).rejects.toEqual(expect.objectContaining({
|
|
632
|
+
name: custodian_1.CUSTODIAN_ORG_ID_ERROR,
|
|
633
|
+
data: { site: 'executePrivateIntent.sourceAccount' },
|
|
634
|
+
}));
|
|
635
|
+
expect(executeTokenIntentMock).not.toHaveBeenCalled();
|
|
636
|
+
}));
|
|
637
|
+
it('settlement finId accounts resolve through the chain instead of shipping an empty custodian', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
638
|
+
const executeTokenIntentMock = jest.fn().mockResolvedValue(completedResponse);
|
|
639
|
+
const ossAsset = {
|
|
640
|
+
issuerId: 'issuer-1',
|
|
641
|
+
ledgerAssetInfo: {},
|
|
642
|
+
intents: [
|
|
643
|
+
{
|
|
644
|
+
id: 'intent-1',
|
|
645
|
+
type: 'privateOfferIntent',
|
|
646
|
+
intent: {
|
|
647
|
+
seller: 'someone-else',
|
|
648
|
+
source: { account: { finId: 'offeror-fin', custodian: { orgId: 'bank-offeror' } } },
|
|
649
|
+
settlementTerm: { details: { amount: '10' } },
|
|
650
|
+
},
|
|
651
|
+
},
|
|
652
|
+
],
|
|
653
|
+
};
|
|
654
|
+
const logger = makeLogger();
|
|
655
|
+
yield (0, executePrivateIntent_1.executePrivateIntent)({
|
|
656
|
+
owneraAPI: makeOwneraAPI(ossAsset, executeTokenIntentMock),
|
|
657
|
+
logger,
|
|
658
|
+
custodianOrgId: DEFAULT_CUSTODIAN,
|
|
659
|
+
userId: 'user-1',
|
|
660
|
+
userPublicKey: 'pk',
|
|
661
|
+
data: {
|
|
662
|
+
assetId: 'org:102:asset-1',
|
|
663
|
+
intentId: 'intent-1',
|
|
664
|
+
amount: '1',
|
|
665
|
+
destinationCustodianOrgId: 'bank-taker',
|
|
666
|
+
sourceAccount: {
|
|
667
|
+
account: { type: 'finId', finId: 'taker-pay-fin', orgId: 'org' },
|
|
668
|
+
asset: { resourceId: 'org:102:cash-1' },
|
|
669
|
+
},
|
|
670
|
+
destinationAccount: { account: { type: 'finId', finId: 'offeror-pay-fin', orgId: 'org' } },
|
|
671
|
+
},
|
|
672
|
+
});
|
|
673
|
+
const request = executeTokenIntentMock.mock.calls[0][0];
|
|
674
|
+
// Source side (executor's paying account) has no account custodian and no per-call value →
|
|
675
|
+
// the Sdk default. Destination side is the OFFEROR's account: the executor's per-call
|
|
676
|
+
// destinationCustodianOrgId must NOT leak onto it → the Sdk default as well.
|
|
677
|
+
expect(request.intent.settlement.instruction.sourceAccount.account.custodian.orgId).toBe(DEFAULT_CUSTODIAN);
|
|
678
|
+
expect(request.intent.settlement.instruction.destinationAccount.account.custodian.orgId).toBe(DEFAULT_CUSTODIAN);
|
|
679
|
+
// The per-call value still applies to the executor's own ASSET destination.
|
|
680
|
+
expect(request.intent.asset.instruction.destinationAccount.account.custodian.orgId).toBe('bank-taker');
|
|
681
|
+
}));
|
|
682
|
+
});
|
|
683
|
+
//# sourceMappingURL=custodianPrecedence.test.js.map
|