@owneraio/finp2p-sdk-js 0.28.26 → 0.28.41
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 +71 -1
- 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/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__/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/certificates.js +15 -6
- package/lib/OwneraAPI/finp2p-node-api/certificates.js.map +1 -1
- 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 +2 -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__/getAllExecutionPlans.test.js +52 -0
- package/lib/OwneraAPI/oss-api/__tests__/getAllExecutionPlans.test.js.map +1 -1
- 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 +155 -75
- 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 +125 -73
- 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/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 +21 -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/Oss.d.ts +18 -1
- package/lib/types/Oss/OssSchemas.d.ts +50 -0
- package/lib/types/Oss/OssSchemas.js.map +1 -1
- package/lib/types/Oss/utils.d.ts +32 -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 +1 -0
- package/lib/types/index.js +1 -0
- package/lib/types/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -13,6 +13,7 @@ exports.executeIntent = void 0;
|
|
|
13
13
|
const utils_1 = require("../utils");
|
|
14
14
|
const utils_2 = require("./utils");
|
|
15
15
|
const tokens_1 = require("../tokens");
|
|
16
|
+
const custodian_1 = require("../custodian");
|
|
16
17
|
const helpers_1 = require("./createIntent/helpers");
|
|
17
18
|
/**
|
|
18
19
|
* Build a CAIP-19 asset identifier from ledger info
|
|
@@ -36,7 +37,7 @@ const buildCaip19Identifier = (ledgerIdentifier, resourceId) => ({
|
|
|
36
37
|
*
|
|
37
38
|
*/
|
|
38
39
|
const executeIntent = (req) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
40
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
40
41
|
const { owneraAPI, data, userId, userPublicKey, idempotency, logger } = req;
|
|
41
42
|
const ossAsset = (yield owneraAPI.query.getAssets({ filter: { assetIds: [data.assetId] } })).data[0];
|
|
42
43
|
const intent = (0, utils_2.getAssetIntentOrThrowError)(ossAsset, data.intentId);
|
|
@@ -49,21 +50,33 @@ const executeIntent = (req) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
49
50
|
if (isFreeOfPayment && intent.type !== 'primarySale') {
|
|
50
51
|
throw new Error(`Free-of-Payment execution is only supported for primarySale intents (got ${intent.type} ${data.intentId})`);
|
|
51
52
|
}
|
|
52
|
-
// Get CAIP-19 ledger identifier for
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
filter: { assetIds: [
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
53
|
+
// Get CAIP-19 ledger identifier for a settlement asset (skip when FoP)
|
|
54
|
+
const resolveSettlementAssetIdentifier = (resourceId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
let ledgerIdentifier;
|
|
57
|
+
if (resourceId) {
|
|
58
|
+
try {
|
|
59
|
+
const settlementAssetsData = yield owneraAPI.query.getAssets({ filter: { assetIds: [resourceId] } });
|
|
60
|
+
ledgerIdentifier = (_b = (_a = settlementAssetsData.data[0]) === null || _a === void 0 ? void 0 : _a.ledgerAssetInfo) === null || _b === void 0 ? void 0 : _b.ledgerIdentifier;
|
|
61
|
+
}
|
|
62
|
+
catch (_c) {
|
|
63
|
+
logger.debug('Failed to get CAIP-19 for settlement asset, using defaults', {
|
|
64
|
+
settlementAssetResourceId: resourceId,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
64
67
|
}
|
|
65
|
-
|
|
66
|
-
|
|
68
|
+
return buildCaip19Identifier(ledgerIdentifier, resourceId || '');
|
|
69
|
+
});
|
|
70
|
+
// Each settlement side is built on its own asset: the payer pays from the source account's asset and the
|
|
71
|
+
// payee is credited on the destination account's asset. They differ when the payee takes the cash on another
|
|
72
|
+
// asset (e.g. its own bank's USD bound to the same shared-ledger token). A destination without an asset (a
|
|
73
|
+
// placeholder `{ asset: {} }`) settles on the source asset.
|
|
74
|
+
const settlementAssetResourceId = isFreeOfPayment ? undefined : (_c = (_b = data.sourceAccount) === null || _b === void 0 ? void 0 : _b.asset) === null || _c === void 0 ? void 0 : _c.resourceId;
|
|
75
|
+
const settlementAssetIdentifier = yield resolveSettlementAssetIdentifier(settlementAssetResourceId);
|
|
76
|
+
const destinationSettlementAssetResourceId = isFreeOfPayment ? undefined : (_e = (_d = data.destinationAccount) === null || _d === void 0 ? void 0 : _d.asset) === null || _e === void 0 ? void 0 : _e.resourceId;
|
|
77
|
+
const destinationSettlementAssetIdentifier = destinationSettlementAssetResourceId && destinationSettlementAssetResourceId !== settlementAssetResourceId
|
|
78
|
+
? yield resolveSettlementAssetIdentifier(destinationSettlementAssetResourceId)
|
|
79
|
+
: settlementAssetIdentifier;
|
|
67
80
|
// Extract account info from the intent based on type
|
|
68
81
|
const getIntentAccount = () => {
|
|
69
82
|
if ('source' in intentDetails && intentDetails.source) {
|
|
@@ -77,46 +90,84 @@ const executeIntent = (req) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
77
90
|
const intentAccount = getIntentAccount();
|
|
78
91
|
const dstAccountPK = intent.type === 'buyingIntent' ? ((_f = intentAccount === null || intentAccount === void 0 ? void 0 : intentAccount.finId) !== null && _f !== void 0 ? _f : userPublicKey) : userPublicKey;
|
|
79
92
|
const custodianOrgIdFromIntent = (_h = (_g = intentAccount === null || intentAccount === void 0 ? void 0 : intentAccount.custodian) === null || _g === void 0 ? void 0 : _g.orgId) !== null && _h !== void 0 ? _h : '';
|
|
93
|
+
// Validate the settlement inputs BEFORE any custodian resolution: resolution can throw, and a
|
|
94
|
+
// caller who simply forgot the accounts should be told that, not handed a custodian error.
|
|
95
|
+
if (!isFreeOfPayment && (!data.sourceAccount || !data.destinationAccount)) {
|
|
96
|
+
throw new Error(`Intent ${data.intentId} requires settlement (non Free-of-Payment) but execution data is missing sourceAccount/destinationAccount`);
|
|
97
|
+
}
|
|
98
|
+
if (intent.type === 'buyingIntent' && data.destinationCustodianOrgId) {
|
|
99
|
+
logger.debug(`executeIntent: per-call destinationCustodianOrgId "${data.destinationCustodianOrgId}" is not applied to the ASSET destination on a buyingIntent — that account is the intent owner's, whose own custodian is authoritative.`);
|
|
100
|
+
}
|
|
101
|
+
// Whose account the ASSET destination is decides where its custodian may come from:
|
|
102
|
+
// • primarySale / sellingIntent — the destination is the EXECUTOR's own account
|
|
103
|
+
// (finId = userPublicKey), so a custodian passed with the call wins; the intent value is the
|
|
104
|
+
// COUNTERPARTY's (issuer's / seller's) and is only a fallback for callers that pass nothing.
|
|
105
|
+
// • buyingIntent — the destination is the INTENT OWNER's account (finId from the intent), so
|
|
106
|
+
// the intent's own custodian is authoritative and a caller-passed value must NOT override it.
|
|
107
|
+
// Either way the Sdk default is the terminal step, so an intent whose account carries no
|
|
108
|
+
// custodian never stamps '' — it resolves to the default, or fails loudly when there is none.
|
|
109
|
+
const destinationCustodianOrgId = intent.type === 'buyingIntent'
|
|
110
|
+
? custodianOrgIdFromIntent ||
|
|
111
|
+
(0, custodian_1.defaultCustodianOrgId)(req.custodianOrgId, 'executeIntent.destinationAssetAccount(buyingIntent)', logger)
|
|
112
|
+
: data.destinationCustodianOrgId ||
|
|
113
|
+
custodianOrgIdFromIntent ||
|
|
114
|
+
(0, custodian_1.defaultCustodianOrgId)(req.custodianOrgId, 'executeIntent.destinationAssetAccount', logger);
|
|
80
115
|
// Build destination asset account (primary asset, buyer's account)
|
|
81
116
|
const destinationAssetAccount = (0, helpers_1.buildFinp2pAssetAccount)({
|
|
82
117
|
finId: dstAccountPK,
|
|
83
118
|
orgId: (0, utils_1.getOrgFromResourceId)(data.assetId),
|
|
84
|
-
custodian: { orgId:
|
|
119
|
+
custodian: { orgId: destinationCustodianOrgId },
|
|
85
120
|
}, primaryAssetIdentifier);
|
|
86
121
|
// Build settlement instruction accounts with CAIP-19 (skip when FoP — no settlement leg).
|
|
87
122
|
// `instruction` accounts carry a CAIP-19 asset identifier that doesn't match the strict
|
|
88
123
|
// SettlementInstruction*Account.asset (FinP2PAsset) shape — same `as any` bridge used elsewhere.
|
|
89
124
|
let settlement;
|
|
90
125
|
if (!isFreeOfPayment) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
126
|
+
// Settlement accounts resolve: the account's own value, then — ONLY on the leg the executor
|
|
127
|
+
// owns — the per-call side value, then the Sdk default. The per-call fields describe the
|
|
128
|
+
// EXECUTOR's custodian, and each settlement instruction has one executor-owned leg and one
|
|
129
|
+
// counterparty-owned leg: on primarySale/sellingIntent the executor (buyer) pays, so they own
|
|
130
|
+
// the source; on buyingIntent the executor (seller) is paid, so they own the destination.
|
|
131
|
+
// The counterparty's leg must never borrow the executor's custodian — with no value of its
|
|
132
|
+
// own it falls to the default or fails loudly, rather than signing a plausible-but-wrong
|
|
133
|
+
// organization into the instruction.
|
|
134
|
+
const rawSettlementSource = data.sourceAccount.account;
|
|
135
|
+
const rawSettlementDest = data.destinationAccount.account;
|
|
136
|
+
const settlementSourceAccount = (0, helpers_1.buildFinp2pAssetAccount)(Object.assign(Object.assign({}, rawSettlementSource), { custodian: {
|
|
137
|
+
orgId: ((_j = rawSettlementSource.custodian) === null || _j === void 0 ? void 0 : _j.orgId) ||
|
|
138
|
+
(intent.type !== 'buyingIntent' ? data.sourceCustodianOrgId : undefined) ||
|
|
139
|
+
(0, custodian_1.defaultCustodianOrgId)(req.custodianOrgId, 'executeIntent.settlementSourceAccount', logger),
|
|
140
|
+
} }), settlementAssetIdentifier);
|
|
141
|
+
const settlementDestAccount = (0, helpers_1.buildFinp2pAssetAccount)(Object.assign(Object.assign({}, rawSettlementDest), { custodian: {
|
|
142
|
+
orgId: ((_k = rawSettlementDest.custodian) === null || _k === void 0 ? void 0 : _k.orgId) ||
|
|
143
|
+
(intent.type === 'buyingIntent' ? data.destinationCustodianOrgId : undefined) ||
|
|
144
|
+
(0, custodian_1.defaultCustodianOrgId)(req.custodianOrgId, 'executeIntent.settlementDestinationAccount', logger),
|
|
145
|
+
} }), destinationSettlementAssetIdentifier);
|
|
96
146
|
// For buying intents, override the settlement source with the buying intent's settlement account
|
|
97
147
|
if (intent.type === 'buyingIntent') {
|
|
98
148
|
const buyingIntent = intent.intent;
|
|
99
|
-
const buyingSettlementAccount = (
|
|
149
|
+
const buyingSettlementAccount = (_l = buyingIntent.settlementInstruction.account) === null || _l === void 0 ? void 0 : _l.account;
|
|
100
150
|
if (buyingSettlementAccount) {
|
|
101
151
|
settlementSourceAccount.account = {
|
|
102
152
|
type: 'finId',
|
|
103
|
-
finId: (
|
|
104
|
-
orgId: (
|
|
105
|
-
custodian: {
|
|
153
|
+
finId: (_m = buyingSettlementAccount.finId) !== null && _m !== void 0 ? _m : '',
|
|
154
|
+
orgId: (_o = buyingSettlementAccount.orgId) !== null && _o !== void 0 ? _o : '',
|
|
155
|
+
custodian: {
|
|
156
|
+
// On a settlement leg the settlement account's OWN values outrank anything imported
|
|
157
|
+
// from the asset leg: the intent's stored settlement account first, then the
|
|
158
|
+
// caller-passed settlement source (it describes the same account), then the intent's
|
|
159
|
+
// asset-leg custodian as a legacy fallback, then the Sdk default.
|
|
160
|
+
orgId: ((_p = buyingSettlementAccount.custodian) === null || _p === void 0 ? void 0 : _p.orgId) ||
|
|
161
|
+
((_q = rawSettlementSource.custodian) === null || _q === void 0 ? void 0 : _q.orgId) ||
|
|
162
|
+
custodianOrgIdFromIntent ||
|
|
163
|
+
(0, custodian_1.defaultCustodianOrgId)(req.custodianOrgId, 'executeIntent.settlementSourceAccount(buyingIntent)', logger),
|
|
164
|
+
},
|
|
106
165
|
};
|
|
107
166
|
}
|
|
108
167
|
}
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if ('amount' in settlementDetails) {
|
|
113
|
-
amount = settlementDetails.amount;
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
if (settlementTermAmount === undefined) {
|
|
117
|
-
throw new Error(`Intent has no settlementTerm; cannot derive amount. Raw intent: ${JSON.stringify(intentDetails).slice(0, 500)}`);
|
|
118
|
-
}
|
|
119
|
-
amount = (0, utils_2.validateSettlementTermAmount)(settlementTermAmount, data.amount);
|
|
168
|
+
const amount = (0, utils_2.getSettlementExecutionAmount)(intentDetails.settlementTerm, data.amount);
|
|
169
|
+
if (amount === undefined) {
|
|
170
|
+
throw new Error(`Intent settlementTerm has no amount or unitValue; cannot derive amount. Raw intent: ${JSON.stringify(intentDetails).slice(0, 500)}`);
|
|
120
171
|
}
|
|
121
172
|
settlement = {
|
|
122
173
|
term: { amount },
|
|
@@ -147,11 +198,18 @@ const executeIntent = (req) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
147
198
|
if (!data.sourceAccount || !data.destinationAccount) {
|
|
148
199
|
throw new Error(`buyingIntent ${data.intentId} execution requires sourceAccount and destinationAccount (Free-of-Payment is only supported for primarySale)`);
|
|
149
200
|
}
|
|
150
|
-
// Source asset account (seller transferring the asset)
|
|
201
|
+
// Source asset account (seller transferring the asset). This is the EXECUTOR's own account —
|
|
202
|
+
// a custodian passed with the call wins. The old derivation copied
|
|
203
|
+
// `data.sourceAccount.account.custodian` (the SETTLEMENT source, which on this path carries the
|
|
204
|
+
// app's configured-value exception), piping a payment-leg value onto the seller's asset leg.
|
|
205
|
+
// Falling to the Sdk default keeps today's behavior for callers that pass nothing.
|
|
151
206
|
const sourceAssetAccount = (0, helpers_1.buildFinp2pAssetAccount)({
|
|
152
207
|
finId: userPublicKey,
|
|
153
208
|
orgId: (0, utils_1.getOrgFromResourceId)(data.assetId),
|
|
154
|
-
custodian: {
|
|
209
|
+
custodian: {
|
|
210
|
+
orgId: data.sourceCustodianOrgId ||
|
|
211
|
+
(0, custodian_1.defaultCustodianOrgId)(req.custodianOrgId, 'executeIntent.sourceAssetAccount(buyingIntent)', logger),
|
|
212
|
+
},
|
|
155
213
|
}, primaryAssetIdentifier);
|
|
156
214
|
// buyingIntentExecution uses sourceDestinationIntentAsset: { term, instruction }
|
|
157
215
|
executionIntent = Object.assign({ type: 'buyingIntentExecution', nonce, seller: userId, asset: {
|
|
@@ -167,9 +225,12 @@ const executeIntent = (req) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
167
225
|
if (intent.type === 'sellingIntent') {
|
|
168
226
|
// Source asset account (asset being transferred from the seller)
|
|
169
227
|
const sourceAssetAccount = (0, helpers_1.buildFinp2pAssetAccount)({
|
|
170
|
-
finId: (
|
|
228
|
+
finId: (_r = intentAccount === null || intentAccount === void 0 ? void 0 : intentAccount.finId) !== null && _r !== void 0 ? _r : userPublicKey,
|
|
171
229
|
orgId: (0, utils_1.getOrgFromResourceId)(data.assetId),
|
|
172
|
-
custodian: {
|
|
230
|
+
custodian: {
|
|
231
|
+
orgId: custodianOrgIdFromIntent ||
|
|
232
|
+
(0, custodian_1.defaultCustodianOrgId)(req.custodianOrgId, 'executeIntent.sourceAssetAccount(sellingIntent)', logger),
|
|
233
|
+
},
|
|
173
234
|
}, primaryAssetIdentifier);
|
|
174
235
|
// sellingIntentExecution uses sourceDestinationIntentAsset: { term, instruction }
|
|
175
236
|
executionIntent = Object.assign({ type: 'sellingIntentExecution', nonce, buyer: userId, asset: {
|
|
@@ -182,7 +243,7 @@ const executeIntent = (req) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
182
243
|
},
|
|
183
244
|
} }, (settlement ? { settlement } : {}));
|
|
184
245
|
}
|
|
185
|
-
const request = Object.assign({ intentId: data.intentId, user: userId, intent: executionIntent, executionId: data.executionId }, (((
|
|
246
|
+
const request = Object.assign({ intentId: data.intentId, user: userId, intent: executionIntent, executionId: data.executionId }, (((_s = data.observers) === null || _s === void 0 ? void 0 : _s.length) ? { observers: data.observers } : {}));
|
|
186
247
|
const execution = yield (0, tokens_1.executeTokenIntent)({
|
|
187
248
|
owneraAPI,
|
|
188
249
|
logger,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executeIntent.js","sourceRoot":"","sources":["../../../src/core/intents/executeIntent.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
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,wBAAwB;oBACxB,IAAA,iCAAqB,EAAC,GAAG,CAAC,cAAc,EAAE,iDAAiD,EAAE,MAAM,CAAC;aACvG;SACF,EACD,sBAAsB,CACvB,CAAC;QAEF,kFAAkF;QAClF,eAAe,mBACb,IAAI,EAAE,wBAAwB,EAC9B,KAAK,EACL,KAAK,EAAE,MAAM,EACb,KAAK,EAAE;gBACL,IAAI,EAAE;oBACJ,MAAM,EAAE,IAAI,CAAC,MAAM;iBACpB;gBACD,WAAW,EAAE;oBACX,aAAa,EAAE,kBAAkB;oBACjC,kBAAkB,EAAE,uBAAuB;iBAC5C;aACF,IACE,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CACtC,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,mBACX,QAAQ,EAAE,IAAI,CAAC,QAAQ,EACvB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,eAAgB,EACxB,WAAW,EAAE,IAAI,CAAC,WAAW,IAC1B,CAAC,CAAA,MAAA,IAAI,CAAC,SAAS,0CAAE,MAAM,EAAC,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CACjE,CAAC;IAEF,MAAM,SAAS,GAAG,MAAM,IAAA,2BAAkB,EACxC;QACE,SAAS;QACT,MAAM;QACN,IAAI,EAAE,OAAO;KACd,EACD,EAAE,cAAc,EAAE,WAAW,EAAE,CAChC,CAAC;IAEF,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AACpC,CAAC,CAAA,CAAC;AArUW,QAAA,aAAa,iBAqUxB"}
|
|
@@ -14,6 +14,7 @@ const utils_1 = require("../utils");
|
|
|
14
14
|
const utils_2 = require("./utils");
|
|
15
15
|
const tokens_1 = require("../tokens");
|
|
16
16
|
const helpers_1 = require("./createIntent/helpers");
|
|
17
|
+
const custodian_1 = require("../custodian");
|
|
17
18
|
/**
|
|
18
19
|
* Execute loan intent
|
|
19
20
|
*
|
|
@@ -23,23 +24,26 @@ const helpers_1 = require("./createIntent/helpers");
|
|
|
23
24
|
*
|
|
24
25
|
*/
|
|
25
26
|
const executeLoanIntent = (req) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34;
|
|
27
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42;
|
|
27
28
|
const { owneraAPI, data, custodianOrgId, userId, idempotency, logger } = req;
|
|
28
29
|
const intent = yield owneraAPI.query.getLoanIntent({ assetId: data.assetId, intentId: data.intentId });
|
|
29
30
|
const intentDetails = intent.intent.intent;
|
|
30
31
|
const { assetTerm } = intentDetails;
|
|
31
32
|
const loanIntent = intentDetails;
|
|
32
33
|
const nonce = (0, utils_1.generateNonce)();
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
// The execute settlement total, matched by the router against the stored term as an exact
|
|
35
|
+
// decimal value (7305 on any drift). Precedence: the caller's total (sent as is), then the
|
|
36
|
+
// caller's per-unit value x the loan quantity, then the stored term — a fullSettlement total
|
|
37
|
+
// as is, a partialSettlement unitValue x the loan quantity. OSS release/v0.28 reads
|
|
38
|
+
// settlementTerm and loanSettlementInstruction back from the first stored settlement[] entry,
|
|
39
|
+
// which is also the entry the router validates against; the overrides cover older OSS that
|
|
40
|
+
// reads them back as null.
|
|
41
|
+
const settlementAmount = (_a = data.settlementTotalAmount) !== null && _a !== void 0 ? _a : (data.settlementTermAmount !== undefined
|
|
42
|
+
? (0, utils_2.validateSettlementTermAmount)(data.settlementTermAmount, assetTerm.amount)
|
|
43
|
+
: (0, utils_2.getSettlementExecutionAmount)(intentDetails.settlementTerm, assetTerm.amount));
|
|
40
44
|
const settlementResourceId = (_b = data.settlementAssetId) !== null && _b !== void 0 ? _b : (_e = (_d = (_c = loanIntent.loanSettlementInstruction) === null || _c === void 0 ? void 0 : _c.lenderAccount) === null || _d === void 0 ? void 0 : _d.asset) === null || _e === void 0 ? void 0 : _e.resourceId;
|
|
41
|
-
if (
|
|
42
|
-
throw new Error('Settlement data missing on stored loan intent; pass
|
|
45
|
+
if (settlementAmount === undefined || !settlementResourceId) {
|
|
46
|
+
throw new Error('Settlement data missing on stored loan intent; pass settlementAssetId plus either settlementTotalAmount or settlementTermAmount in execution data.');
|
|
43
47
|
}
|
|
44
48
|
// Per-side settlement overrides — required for multi-bank settlement
|
|
45
49
|
// (matching what was passed on createLoanIntent). When absent, both
|
|
@@ -56,7 +60,7 @@ const executeLoanIntent = (req) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
56
60
|
}
|
|
57
61
|
}
|
|
58
62
|
}
|
|
59
|
-
catch (
|
|
63
|
+
catch (_43) {
|
|
60
64
|
logger.debug('Failed to get CAIP-19 for loan intent assets', { assetIdsToFetch });
|
|
61
65
|
}
|
|
62
66
|
const assetIdentifier = (0, helpers_1.buildCaip19Identifier)(caip19Map[data.assetId], data.assetId);
|
|
@@ -76,12 +80,17 @@ const executeLoanIntent = (req) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
76
80
|
borrowerAccount: (0, helpers_1.buildFinp2pAssetAccount)({
|
|
77
81
|
finId: (_o = (_m = (_l = loanIntent.borrowerAccount) === null || _l === void 0 ? void 0 : _l.account) === null || _m === void 0 ? void 0 : _m.finId) !== null && _o !== void 0 ? _o : '',
|
|
78
82
|
orgId: (_r = (_q = (_p = loanIntent.borrowerAccount) === null || _p === void 0 ? void 0 : _p.account) === null || _q === void 0 ? void 0 : _q.orgId) !== null && _r !== void 0 ? _r : (0, utils_1.getOrgFromResourceId)(data.assetId),
|
|
79
|
-
custodian: {
|
|
83
|
+
custodian: {
|
|
84
|
+
orgId: data.sourceCustodianOrgId || (0, custodian_1.defaultCustodianOrgId)(custodianOrgId, 'executeLoanIntent.source', logger),
|
|
85
|
+
},
|
|
80
86
|
}, assetIdentifier),
|
|
81
87
|
lenderAccount: (0, helpers_1.buildFinp2pAssetAccount)({
|
|
82
|
-
finId: (
|
|
83
|
-
orgId: (
|
|
84
|
-
custodian: {
|
|
88
|
+
finId: (_u = (_t = (_s = loanIntent.lenderAccount) === null || _s === void 0 ? void 0 : _s.account) === null || _t === void 0 ? void 0 : _t.finId) !== null && _u !== void 0 ? _u : '',
|
|
89
|
+
orgId: (_x = (_w = (_v = loanIntent.lenderAccount) === null || _v === void 0 ? void 0 : _v.account) === null || _w === void 0 ? void 0 : _w.orgId) !== null && _x !== void 0 ? _x : (0, utils_1.getOrgFromResourceId)(data.assetId),
|
|
90
|
+
custodian: {
|
|
91
|
+
orgId: data.destinationCustodianOrgId ||
|
|
92
|
+
(0, custodian_1.defaultCustodianOrgId)(custodianOrgId, 'executeLoanIntent.destination', logger),
|
|
93
|
+
},
|
|
85
94
|
}, assetIdentifier),
|
|
86
95
|
},
|
|
87
96
|
},
|
|
@@ -98,16 +107,27 @@ const executeLoanIntent = (req) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
98
107
|
nonce: nonce.toString('hex'),
|
|
99
108
|
settlement: {
|
|
100
109
|
assetTerm: {
|
|
101
|
-
amount:
|
|
110
|
+
amount: settlementAmount,
|
|
102
111
|
},
|
|
103
112
|
assetInstruction: {
|
|
104
113
|
lenderAccount: {
|
|
105
114
|
account: {
|
|
106
115
|
type: 'finId',
|
|
107
|
-
finId: (
|
|
108
|
-
orgId: (
|
|
116
|
+
finId: (_4 = (_1 = (_0 = (_z = (_y = loanIntent.loanSettlementInstruction) === null || _y === void 0 ? void 0 : _y.lenderAccount) === null || _z === void 0 ? void 0 : _z.account) === null || _0 === void 0 ? void 0 : _0.finId) !== null && _1 !== void 0 ? _1 : (_3 = (_2 = loanIntent.lenderAccount) === null || _2 === void 0 ? void 0 : _2.account) === null || _3 === void 0 ? void 0 : _3.finId) !== null && _4 !== void 0 ? _4 : '',
|
|
117
|
+
orgId: (_13 = (_10 = (_6 = (_5 = data.settlementLenderAccount) === null || _5 === void 0 ? void 0 : _5.orgId) !== null && _6 !== void 0 ? _6 : (_9 = (_8 = (_7 = loanIntent.loanSettlementInstruction) === null || _7 === void 0 ? void 0 : _7.lenderAccount) === null || _8 === void 0 ? void 0 : _8.account) === null || _9 === void 0 ? void 0 : _9.orgId) !== null && _10 !== void 0 ? _10 : (_12 = (_11 = loanIntent.lenderAccount) === null || _11 === void 0 ? void 0 : _11.account) === null || _12 === void 0 ? void 0 : _12.orgId) !== null && _13 !== void 0 ? _13 : '',
|
|
109
118
|
custodian: {
|
|
110
|
-
|
|
119
|
+
// The LENDER's settlement account takes the LENDER's custodian (destination side).
|
|
120
|
+
// Verified against createLoanIntent, which maps borrower<-source / lender<-destination
|
|
121
|
+
// on BOTH the asset and settlement instructions; the older mapping here was swapped.
|
|
122
|
+
//
|
|
123
|
+
// Precedence is most-specific-first. `settlementLenderAccount` is supplied per call
|
|
124
|
+
// AND is specific to the settlement leg, so it outranks the stored account; the
|
|
125
|
+
// stored account outranks `destinationCustodianOrgId`, which is a per-call value
|
|
126
|
+
// shared with the asset leg and so cannot express a cross-org loan on its own.
|
|
127
|
+
orgId: ((_15 = (_14 = data.settlementLenderAccount) === null || _14 === void 0 ? void 0 : _14.custodian) === null || _15 === void 0 ? void 0 : _15.orgId) ||
|
|
128
|
+
((_19 = (_18 = (_17 = (_16 = loanIntent.loanSettlementInstruction) === null || _16 === void 0 ? void 0 : _16.lenderAccount) === null || _17 === void 0 ? void 0 : _17.account) === null || _18 === void 0 ? void 0 : _18.custodian) === null || _19 === void 0 ? void 0 : _19.orgId) ||
|
|
129
|
+
data.destinationCustodianOrgId ||
|
|
130
|
+
(0, custodian_1.defaultCustodianOrgId)(custodianOrgId, 'executeLoanIntent.destination', logger),
|
|
111
131
|
},
|
|
112
132
|
},
|
|
113
133
|
asset: lenderSettlementAssetIdentifier,
|
|
@@ -115,10 +135,15 @@ const executeLoanIntent = (req) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
115
135
|
borrowerAccount: {
|
|
116
136
|
account: {
|
|
117
137
|
type: 'finId',
|
|
118
|
-
finId: (
|
|
119
|
-
orgId: (
|
|
138
|
+
finId: (_26 = (_23 = (_22 = (_21 = (_20 = loanIntent.loanSettlementInstruction) === null || _20 === void 0 ? void 0 : _20.borrowerAccount) === null || _21 === void 0 ? void 0 : _21.account) === null || _22 === void 0 ? void 0 : _22.finId) !== null && _23 !== void 0 ? _23 : (_25 = (_24 = loanIntent.borrowerAccount) === null || _24 === void 0 ? void 0 : _24.account) === null || _25 === void 0 ? void 0 : _25.finId) !== null && _26 !== void 0 ? _26 : '',
|
|
139
|
+
orgId: (_35 = (_32 = (_28 = (_27 = data.settlementBorrowerAccount) === null || _27 === void 0 ? void 0 : _27.orgId) !== null && _28 !== void 0 ? _28 : (_31 = (_30 = (_29 = loanIntent.loanSettlementInstruction) === null || _29 === void 0 ? void 0 : _29.borrowerAccount) === null || _30 === void 0 ? void 0 : _30.account) === null || _31 === void 0 ? void 0 : _31.orgId) !== null && _32 !== void 0 ? _32 : (_34 = (_33 = loanIntent.borrowerAccount) === null || _33 === void 0 ? void 0 : _33.account) === null || _34 === void 0 ? void 0 : _34.orgId) !== null && _35 !== void 0 ? _35 : '',
|
|
120
140
|
custodian: {
|
|
121
|
-
|
|
141
|
+
// The BORROWER's settlement account takes the BORROWER's custodian (source side) —
|
|
142
|
+
// see the lender leg above for the swap this corrects and for the precedence order.
|
|
143
|
+
orgId: ((_37 = (_36 = data.settlementBorrowerAccount) === null || _36 === void 0 ? void 0 : _36.custodian) === null || _37 === void 0 ? void 0 : _37.orgId) ||
|
|
144
|
+
((_41 = (_40 = (_39 = (_38 = loanIntent.loanSettlementInstruction) === null || _38 === void 0 ? void 0 : _38.borrowerAccount) === null || _39 === void 0 ? void 0 : _39.account) === null || _40 === void 0 ? void 0 : _40.custodian) === null || _41 === void 0 ? void 0 : _41.orgId) ||
|
|
145
|
+
data.sourceCustodianOrgId ||
|
|
146
|
+
(0, custodian_1.defaultCustodianOrgId)(custodianOrgId, 'executeLoanIntent.source', logger),
|
|
122
147
|
},
|
|
123
148
|
},
|
|
124
149
|
asset: borrowerSettlementAssetIdentifier,
|
|
@@ -127,7 +152,7 @@ const executeLoanIntent = (req) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
127
152
|
},
|
|
128
153
|
type: 'loanIntentExecution',
|
|
129
154
|
};
|
|
130
|
-
const request = Object.assign({ intentId: data.intentId, user: userId, intent: execIntent, executionId: data.executionId }, (((
|
|
155
|
+
const request = Object.assign({ intentId: data.intentId, user: userId, intent: execIntent, executionId: data.executionId }, (((_42 = data.observers) === null || _42 === void 0 ? void 0 : _42.length) ? { observers: data.observers } : {}));
|
|
131
156
|
const execution = yield (0, tokens_1.executeTokenIntent)({
|
|
132
157
|
owneraAPI,
|
|
133
158
|
logger,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executeLoanIntent.js","sourceRoot":"","sources":["../../../src/core/intents/executeLoanIntent.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,oCAA+D;AAE/D,
|
|
1
|
+
{"version":3,"file":"executeLoanIntent.js","sourceRoot":"","sources":["../../../src/core/intents/executeLoanIntent.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,oCAA+D;AAE/D,mCAAqF;AACrF,sCAA+C;AAC/C,oDAAwF;AACxF,4C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O,4CAAE,SAAS,4CAAE,KAAK,CAAA;gCAChF,IAAI,CAAC,oBAAoB;gCACzB,IAAA,iCAAqB,EAAC,cAAc,EAAE,0BAA0B,EAAE,MAAM,CAAC;yBAC5E;qBACF;oBACD,KAAK,EAAE,iCAAwC;iBAChD;aACF;SACF;QACD,IAAI,EAAE,qBAAqB;KAC5B,CAAC;IAEF,MAAM,OAAO,mBACX,QAAQ,EAAE,IAAI,CAAC,QAAQ,EACvB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,UAAU,EAClB,WAAW,EAAE,IAAI,CAAC,WAAW,IAC1B,CAAC,CAAA,OAAA,IAAI,CAAC,SAAS,4CAAE,MAAM,EAAC,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CACjE,CAAC;IAEF,MAAM,SAAS,GAAG,MAAM,IAAA,2BAAkB,EACxC;QACE,SAAS;QACT,MAAM;QACN,IAAI,EAAE,OAAO;KACd,EACD,EAAE,cAAc,EAAE,WAAW,EAAE,CAChC,CAAC;IAEF,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AACpC,CAAC,CAAA,CAAC;AA1MW,QAAA,iBAAiB,qBA0M5B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executeMoveIntent.js","sourceRoot":"","sources":["../../../src/core/intents/executeMoveIntent.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"executeMoveIntent.js","sourceRoot":"","sources":["../../../src/core/intents/executeMoveIntent.ts"],"names":[],"mappings":";;;;;;;;;;;;AASA,oCAA+D;AAC/D,mCAAqD;AACrD,sCAA+C;AAC/C,oDAAoH;AAEpH;;;;;;;;GAQG;AACI,MAAM,iBAAiB,GAAG,CAAO,GAQvC,EAA4B,EAAE;;IAC7B,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE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F,MAAM,OAAO,iCACX,QAAQ,EACR,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,eAAe,EACvB,WAAW,EAAE,IAAI,CAAC,WAAW,IAC1B,CAAC,CAAA,MAAA,IAAI,CAAC,SAAS,0CAAE,MAAM,EAAC,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,GAC7D,CAAC,IAAI,CAAC,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAC3F,CAAC;IAEF,OAAO,MAAM,IAAA,2BAAkB,EAC7B;QACE,SAAS;QACT,MAAM;QACN,IAAI,EAAE,OAAO;KACd,EACD,EAAE,cAAc,EAAE,WAAW,EAAE,CAChC,CAAC;AACJ,CAAC,CAAA,CAAC;AAvJW,QAAA,iBAAiB,qBAuJ5B"}
|
|
@@ -14,6 +14,7 @@ const utils_1 = require("../utils");
|
|
|
14
14
|
const utils_2 = require("./utils");
|
|
15
15
|
const tokens_1 = require("../tokens");
|
|
16
16
|
const helpers_1 = require("./createIntent/helpers");
|
|
17
|
+
const custodian_1 = require("../custodian");
|
|
17
18
|
/**
|
|
18
19
|
* Execute private intent
|
|
19
20
|
*
|
|
@@ -31,8 +32,13 @@ const executePrivateIntent = (req) => __awaiter(void 0, void 0, void 0, function
|
|
|
31
32
|
const nonce = (0, utils_1.generateNonce)().toString('hex');
|
|
32
33
|
// currently handle selling flow only
|
|
33
34
|
const dstAccountPK = userPublicKey;
|
|
34
|
-
//
|
|
35
|
-
|
|
35
|
+
// Custodian precedence differs per side — see each site:
|
|
36
|
+
// • source (the OFFEROR's account): intent → per-call → default, resolved inside the
|
|
37
|
+
// non-issuance branch below — issuance builds a sourceAccount with no account at all, so
|
|
38
|
+
// resolving (and possibly throwing) here would fail calls that never use the value;
|
|
39
|
+
// • destination (the TAKER's own account): per-call → intent → default, and the intent step
|
|
40
|
+
// is skipped entirely on the DvD (asset-settlement) branch.
|
|
41
|
+
const custodianOrgIdFromIntent = (_c = (_b = (_a = intentDetails.source) === null || _a === void 0 ? void 0 : _a.account) === null || _b === void 0 ? void 0 : _b.custodian) === null || _c === void 0 ? void 0 : _c.orgId;
|
|
36
42
|
// Detect issuance: the seller is the asset issuer (minting new tokens).
|
|
37
43
|
// Note: cannot rely on source.account.finId being absent — the platform populates it after creation.
|
|
38
44
|
const isIssuance = intentDetails.seller === ossAsset.issuerId;
|
|
@@ -45,12 +51,22 @@ const executePrivateIntent = (req) => __awaiter(void 0, void 0, void 0, function
|
|
|
45
51
|
(((_f = (_e = (_d = intentDetails === null || intentDetails === void 0 ? void 0 : intentDetails.sellingSettlementInstruction) === null || _d === void 0 ? void 0 : _d.accounts) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.asset) || {});
|
|
46
52
|
// Build CAIP-19 asset identifier for main asset
|
|
47
53
|
const assetIdentifier = (0, helpers_1.buildCaip19Identifier)((_g = ossAsset.ledgerAssetInfo) === null || _g === void 0 ? void 0 : _g.ledgerIdentifier, data.assetId);
|
|
54
|
+
// The destination asset account belongs to the EXECUTING taker (finId = userPublicKey), so a
|
|
55
|
+
// per-call value naming the taker's own custodian wins on BOTH branches. The intent's custodian
|
|
56
|
+
// is the OFFEROR's — it stays only as a fallback for callers that pass nothing (previous
|
|
57
|
+
// precedence put it first, stamping the offeror's custodian onto the taker's account).
|
|
58
|
+
const destinationCustodianOrgId = isAssetSettlement
|
|
59
|
+
? data.destinationCustodianOrgId ||
|
|
60
|
+
(0, custodian_1.defaultCustodianOrgId)(custodianOrgId, 'executePrivateIntent.destinationAccount(assetSettlement)', logger)
|
|
61
|
+
: data.destinationCustodianOrgId ||
|
|
62
|
+
custodianOrgIdFromIntent ||
|
|
63
|
+
(0, custodian_1.defaultCustodianOrgId)(custodianOrgId, 'executePrivateIntent.destinationAccount', logger);
|
|
48
64
|
const instructionDestAccount = {
|
|
49
65
|
type: 'finId',
|
|
50
66
|
finId: dstAccountPK,
|
|
51
67
|
orgId: (0, utils_1.getOrgFromResourceId)(data.assetId),
|
|
52
68
|
custodian: {
|
|
53
|
-
orgId:
|
|
69
|
+
orgId: destinationCustodianOrgId,
|
|
54
70
|
},
|
|
55
71
|
};
|
|
56
72
|
logger.debug(`🔵 [executePrivateIntent] isIssuance=${isIssuance} (seller=${intentDetails.seller}, issuerId=${ossAsset.issuerId}), isFreeOfPayment=${isFreeOfPayment}, settlementTerm=${JSON.stringify(settlementTerm)}`);
|
|
@@ -68,12 +84,15 @@ const executePrivateIntent = (req) => __awaiter(void 0, void 0, void 0, function
|
|
|
68
84
|
else {
|
|
69
85
|
// Non-issuance (trade): sourceAccount with full account + asset
|
|
70
86
|
const srcFinId = ((_j = (_h = intentDetails.source) === null || _h === void 0 ? void 0 : _h.account) === null || _j === void 0 ? void 0 : _j.finId) || dstAccountPK;
|
|
87
|
+
const sourceCustodianOrgId = custodianOrgIdFromIntent ||
|
|
88
|
+
data.sourceCustodianOrgId ||
|
|
89
|
+
(0, custodian_1.defaultCustodianOrgId)(custodianOrgId, 'executePrivateIntent.sourceAccount', logger);
|
|
71
90
|
assetInstruction.sourceAccount = (0, helpers_1.buildFinp2pAssetAccount)({
|
|
72
91
|
type: 'finId',
|
|
73
92
|
orgId: (0, utils_1.getOrgFromResourceId)(data.assetId),
|
|
74
93
|
finId: srcFinId,
|
|
75
94
|
custodian: {
|
|
76
|
-
orgId:
|
|
95
|
+
orgId: sourceCustodianOrgId,
|
|
77
96
|
},
|
|
78
97
|
}, assetIdentifier);
|
|
79
98
|
}
|
|
@@ -124,9 +143,24 @@ const executePrivateIntent = (req) => __awaiter(void 0, void 0, void 0, function
|
|
|
124
143
|
if (!data.sourceAccount || !data.destinationAccount) {
|
|
125
144
|
throw new Error(`privateOfferIntent ${data.intentId} requires sourceAccount and destinationAccount when settlementTerm is present`);
|
|
126
145
|
}
|
|
146
|
+
// Settlement finId accounts resolve: the account's own value, then — only on the leg the
|
|
147
|
+
// executor owns — the per-call value, then the Sdk default, so an account passed with an
|
|
148
|
+
// empty custodian.orgId never reaches the Router. The executing taker PAYS, so they own the
|
|
149
|
+
// settlement source; the destination is the OFFEROR's receiving account, which must never
|
|
150
|
+
// borrow the executor's per-call custodian — with no value of its own it falls to the default
|
|
151
|
+
// or fails loudly. Non-finId (fiat/crypto) accounts carry no custodian and pass through
|
|
152
|
+
// untouched.
|
|
153
|
+
const resolveSettlementCustodian = (account, perCallCustodianOrgId, site) => {
|
|
154
|
+
var _a;
|
|
155
|
+
if ((account === null || account === void 0 ? void 0 : account.type) !== 'finId')
|
|
156
|
+
return account;
|
|
157
|
+
return Object.assign(Object.assign({}, account), { custodian: {
|
|
158
|
+
orgId: ((_a = account.custodian) === null || _a === void 0 ? void 0 : _a.orgId) || perCallCustodianOrgId || (0, custodian_1.defaultCustodianOrgId)(custodianOrgId, site, logger),
|
|
159
|
+
} });
|
|
160
|
+
};
|
|
127
161
|
const settlementInstruction = {
|
|
128
|
-
destinationAccount: Object.assign(Object.assign({}, data.destinationAccount), { asset: settlementAssetIdentifier }),
|
|
129
|
-
sourceAccount: Object.assign(Object.assign({}, data.sourceAccount), { asset: settlementAssetIdentifier }),
|
|
162
|
+
destinationAccount: Object.assign(Object.assign({}, data.destinationAccount), { account: resolveSettlementCustodian(data.destinationAccount.account, undefined, 'executePrivateIntent.settlementDestinationAccount'), asset: settlementAssetIdentifier }),
|
|
163
|
+
sourceAccount: Object.assign(Object.assign({}, data.sourceAccount), { account: resolveSettlementCustodian(data.sourceAccount.account, data.sourceCustodianOrgId, 'executePrivateIntent.settlementSourceAccount'), asset: settlementAssetIdentifier }),
|
|
130
164
|
};
|
|
131
165
|
// if DvD private offer, align orgId to the org where the asset exists in the settlement accounts
|
|
132
166
|
if (isAssetSettlement && settlementAccountAsset) {
|
|
@@ -134,14 +168,13 @@ const executePrivateIntent = (req) => __awaiter(void 0, void 0, void 0, function
|
|
|
134
168
|
settlementInstruction.destinationAccount.account.orgId = settlementAssetOrgId;
|
|
135
169
|
settlementInstruction.sourceAccount.account.orgId = settlementAssetOrgId;
|
|
136
170
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
else if (isFullSettlement) {
|
|
142
|
-
const amount = settlementTermDetails.amount;
|
|
143
|
-
settlement = { term: { type: 'fullSettlement', amount }, instruction: settlementInstruction };
|
|
171
|
+
const amount = (0, utils_2.getSettlementExecutionAmount)(intentDetails.settlementTerm, data.amount);
|
|
172
|
+
if (amount === undefined) {
|
|
173
|
+
throw new Error(`privateOfferIntent ${data.intentId} has no settlement amount (unitValue or amount) on its stored term`);
|
|
144
174
|
}
|
|
175
|
+
settlement = isFullSettlement
|
|
176
|
+
? { term: { type: 'fullSettlement', amount }, instruction: settlementInstruction }
|
|
177
|
+
: { term: { amount }, instruction: settlementInstruction };
|
|
145
178
|
}
|
|
146
179
|
const privateIntent = Object.assign(Object.assign({ asset: {
|
|
147
180
|
instruction: assetInstruction,
|