dexbot 1.4.8 → 1.4.10
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 +4 -7
- package/dist/dexbot.d.ts +3 -0
- package/dist/dexbot.d.ts.map +1 -1
- package/dist/dexbot.js +21 -2
- package/dist/dexbot.js.map +1 -1
- package/dist/modules/broadcast_failure.d.ts +0 -1
- package/dist/modules/broadcast_failure.d.ts.map +1 -1
- package/dist/modules/broadcast_failure.js +0 -1
- package/dist/modules/broadcast_failure.js.map +1 -1
- package/dist/modules/chain_keys.d.ts.map +1 -1
- package/dist/modules/chain_keys.js +19 -1
- package/dist/modules/chain_keys.js.map +1 -1
- package/dist/modules/credential_policy.d.ts.map +1 -1
- package/dist/modules/credential_policy.js +135 -364
- package/dist/modules/credential_policy.js.map +1 -1
- package/dist/modules/credit_runtime.d.ts.map +1 -1
- package/dist/modules/credit_runtime.js +26 -0
- package/dist/modules/credit_runtime.js.map +1 -1
- package/dist/modules/daemon_node_health.d.ts +0 -1
- package/dist/modules/daemon_node_health.d.ts.map +1 -1
- package/dist/modules/daemon_node_health.js +0 -1
- package/dist/modules/daemon_node_health.js.map +1 -1
- package/dist/modules/dexbot_cow_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_cow_runtime.js +7 -1
- package/dist/modules/dexbot_cow_runtime.js.map +1 -1
- package/dist/modules/dexbot_fill_runtime.d.ts +14 -5
- package/dist/modules/dexbot_fill_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_fill_runtime.js +27 -27
- package/dist/modules/dexbot_fill_runtime.js.map +1 -1
- package/dist/modules/dexbot_maintenance_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_maintenance_runtime.js +32 -14
- package/dist/modules/dexbot_maintenance_runtime.js.map +1 -1
- package/dist/modules/dexbot_startup_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_startup_runtime.js +4 -11
- package/dist/modules/dexbot_startup_runtime.js.map +1 -1
- package/dist/modules/dexbot_state_recovery.d.ts.map +1 -1
- package/dist/modules/dexbot_state_recovery.js +7 -7
- package/dist/modules/dexbot_state_recovery.js.map +1 -1
- package/dist/modules/key_store.d.ts.map +1 -1
- package/dist/modules/key_store.js +42 -60
- package/dist/modules/key_store.js.map +1 -1
- package/dist/modules/launcher/bot_supervisor.d.ts +2 -2
- package/dist/modules/launcher/bot_supervisor.d.ts.map +1 -1
- package/dist/modules/launcher/bot_supervisor.js +6 -26
- package/dist/modules/launcher/bot_supervisor.js.map +1 -1
- package/dist/modules/launcher/foreign_cred_daemon.d.ts +17 -0
- package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +1 -1
- package/dist/modules/launcher/foreign_cred_daemon.js +5 -14
- package/dist/modules/launcher/foreign_cred_daemon.js.map +1 -1
- package/dist/modules/launcher/monolithic_runtime.d.ts.map +1 -1
- package/dist/modules/launcher/monolithic_runtime.js +4 -16
- package/dist/modules/launcher/monolithic_runtime.js.map +1 -1
- package/dist/modules/launcher/status_reporting.d.ts.map +1 -1
- package/dist/modules/launcher/status_reporting.js +1 -11
- package/dist/modules/launcher/status_reporting.js.map +1 -1
- package/dist/modules/node_failure_ledger.d.ts +0 -1
- package/dist/modules/node_failure_ledger.d.ts.map +1 -1
- package/dist/modules/node_failure_ledger.js +0 -1
- package/dist/modules/node_failure_ledger.js.map +1 -1
- package/dist/modules/order/accounting.d.ts.map +1 -1
- package/dist/modules/order/accounting.js +5 -1
- package/dist/modules/order/accounting.js.map +1 -1
- package/dist/modules/order/grid.d.ts.map +1 -1
- package/dist/modules/order/grid.js +187 -22
- package/dist/modules/order/grid.js.map +1 -1
- package/dist/modules/order/grid_reconcile_internal.d.ts.map +1 -1
- package/dist/modules/order/grid_reconcile_internal.js +147 -35
- package/dist/modules/order/grid_reconcile_internal.js.map +1 -1
- package/dist/modules/order/logger.js +1 -1
- package/dist/modules/order/logger.js.map +1 -1
- package/dist/modules/order/manager.d.ts +1 -1
- package/dist/modules/order/manager.d.ts.map +1 -1
- package/dist/modules/order/manager.js +3 -20
- package/dist/modules/order/manager.js.map +1 -1
- package/dist/modules/order/strategy.js +2 -2
- package/dist/modules/order/strategy.js.map +1 -1
- package/dist/modules/order/sync_engine.js +4 -4
- package/dist/modules/order/sync_engine.js.map +1 -1
- package/dist/modules/order/utils/math.d.ts +38 -1
- package/dist/modules/order/utils/math.d.ts.map +1 -1
- package/dist/modules/order/utils/math.js +60 -0
- package/dist/modules/order/utils/math.js.map +1 -1
- package/dist/modules/order/utils/order.d.ts +45 -1
- package/dist/modules/order/utils/order.d.ts.map +1 -1
- package/dist/modules/order/utils/order.js +84 -0
- package/dist/modules/order/utils/order.js.map +1 -1
- package/dist/modules/order/utils/system.d.ts.map +1 -1
- package/dist/modules/order/utils/system.js +5 -2
- package/dist/modules/order/utils/system.js.map +1 -1
- package/dist/modules/process_discovery.d.ts +1 -1
- package/dist/modules/process_discovery.d.ts.map +1 -1
- package/dist/modules/process_discovery.js +15 -14
- package/dist/modules/process_discovery.js.map +1 -1
- package/dist/modules/socket_json_client.d.ts +0 -1
- package/dist/modules/socket_json_client.d.ts.map +1 -1
- package/dist/modules/socket_json_client.js +0 -1
- package/dist/modules/socket_json_client.js.map +1 -1
- package/dist/modules/types.d.ts +0 -600
- package/dist/modules/types.d.ts.map +1 -1
- package/dist/modules/types.js +15 -0
- package/dist/modules/types.js.map +1 -1
- package/dist/scripts/run-tests.js +185 -18
- package/dist/scripts/run-tests.js.map +1 -1
- package/dist/unlock.d.ts +4 -4
- package/dist/unlock.js +8 -8
- package/dist/unlock.js.map +1 -1
- package/package.json +1 -1
|
@@ -694,411 +694,182 @@ function buildPolicyContext(request) {
|
|
|
694
694
|
* Evaluate per-operation parameter constraints.
|
|
695
695
|
* Returns { allow: boolean, reason: string|null, policyId: string }
|
|
696
696
|
*/
|
|
697
|
+
function asDeny(reason) {
|
|
698
|
+
return { allow: false, reason, policyId: 'opParams' };
|
|
699
|
+
}
|
|
700
|
+
function denyNotInList(opName, word, id, listName, list, requirePresent) {
|
|
701
|
+
if (!Array.isArray(list) || list.length === 0)
|
|
702
|
+
return null;
|
|
703
|
+
if (requirePresent) {
|
|
704
|
+
if (!list.includes(String(id))) {
|
|
705
|
+
return asDeny(`${opName}: ${word} "${id}" not in ${listName}`);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
else if (id != null && !list.includes(String(id))) {
|
|
709
|
+
return asDeny(`${opName}: ${word} "${id}" not in ${listName}`);
|
|
710
|
+
}
|
|
711
|
+
return null;
|
|
712
|
+
}
|
|
713
|
+
function denyBoundExceeded(opName, label, compareValue, shownValue, boundLabel, bound, opts = {}) {
|
|
714
|
+
if (bound == null)
|
|
715
|
+
return null;
|
|
716
|
+
if (compareValue == null || !Number.isFinite(compareValue))
|
|
717
|
+
return null;
|
|
718
|
+
const over = opts.lower ? compareValue < bound : compareValue > bound;
|
|
719
|
+
if (!over)
|
|
720
|
+
return null;
|
|
721
|
+
const verb = opts.verb ?? (opts.lower ? 'below' : 'exceeds');
|
|
722
|
+
return asDeny(`${opName}: ${label} ${shownValue} ${verb} ${boundLabel} ${bound}`);
|
|
723
|
+
}
|
|
724
|
+
async function denyAssetRefMismatch(opName, word, assetId, refs, refLabel, opts = {}) {
|
|
725
|
+
if (!opts.active)
|
|
726
|
+
return null;
|
|
727
|
+
const resolved = await resolveConfiguredAssetRefs(refs, refLabel);
|
|
728
|
+
if (!resolved.ok)
|
|
729
|
+
return asDeny(`${opName}: ${resolved.reason}`);
|
|
730
|
+
if (assetId && resolved.values && !resolved.values.includes(String(assetId))) {
|
|
731
|
+
const phrase = opts.matchOnly ? 'does not match' : 'not in';
|
|
732
|
+
return asDeny(`${opName}: ${word} "${assetId}" ${phrase} ${refLabel}`);
|
|
733
|
+
}
|
|
734
|
+
return null;
|
|
735
|
+
}
|
|
697
736
|
async function evaluateOpConstraints(opName, opData, constraints) {
|
|
698
737
|
if (!constraints)
|
|
699
738
|
return { allow: true, reason: null, policyId: null };
|
|
700
739
|
const d = opData || {};
|
|
701
740
|
if (opName === 'transfer') {
|
|
702
741
|
// allowedToAccounts
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
allow: false,
|
|
707
|
-
reason: `transfer: recipient "${d.to}" not in allowedToAccounts`,
|
|
708
|
-
policyId: 'opParams',
|
|
709
|
-
};
|
|
710
|
-
}
|
|
711
|
-
}
|
|
742
|
+
const recipientDenied = denyNotInList('transfer', 'recipient', d.to, 'allowedToAccounts', constraints.allowedToAccounts, true);
|
|
743
|
+
if (recipientDenied)
|
|
744
|
+
return recipientDenied;
|
|
712
745
|
// allowedAssets
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
return {
|
|
717
|
-
allow: false,
|
|
718
|
-
reason: `transfer: asset "${id}" not in allowedAssets`,
|
|
719
|
-
policyId: 'opParams',
|
|
720
|
-
};
|
|
721
|
-
}
|
|
722
|
-
}
|
|
746
|
+
const assetDenied = denyNotInList('transfer', 'asset', d.amount && d.amount.asset_id, 'allowedAssets', constraints.allowedAssets);
|
|
747
|
+
if (assetDenied)
|
|
748
|
+
return assetDenied;
|
|
723
749
|
// maxAmount
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
return {
|
|
728
|
-
allow: false,
|
|
729
|
-
reason: `transfer: amount ${amt} exceeds maxAmount ${constraints.maxAmount}`,
|
|
730
|
-
policyId: 'opParams',
|
|
731
|
-
};
|
|
732
|
-
}
|
|
733
|
-
}
|
|
750
|
+
const maxAmountDenied = denyBoundExceeded('transfer', 'amount', d.amount && d.amount.amount, d.amount && d.amount.amount, 'maxAmount', constraints.maxAmount);
|
|
751
|
+
if (maxAmountDenied)
|
|
752
|
+
return maxAmountDenied;
|
|
734
753
|
}
|
|
735
754
|
if (opName === 'limit_order_create') {
|
|
736
755
|
// allowedSellAssets
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
return {
|
|
741
|
-
allow: false,
|
|
742
|
-
reason: `limit_order_create: sell asset "${id}" not in allowedSellAssets`,
|
|
743
|
-
policyId: 'opParams',
|
|
744
|
-
};
|
|
745
|
-
}
|
|
746
|
-
}
|
|
756
|
+
const sellDenied = denyNotInList('limit_order_create', 'sell asset', d.amount_to_sell && d.amount_to_sell.asset_id, 'allowedSellAssets', constraints.allowedSellAssets);
|
|
757
|
+
if (sellDenied)
|
|
758
|
+
return sellDenied;
|
|
747
759
|
// allowedReceiveAssets
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
return {
|
|
752
|
-
allow: false,
|
|
753
|
-
reason: `limit_order_create: receive asset "${id}" not in allowedReceiveAssets`,
|
|
754
|
-
policyId: 'opParams',
|
|
755
|
-
};
|
|
756
|
-
}
|
|
757
|
-
}
|
|
760
|
+
const receiveDenied = denyNotInList('limit_order_create', 'receive asset', d.min_to_receive && d.min_to_receive.asset_id, 'allowedReceiveAssets', constraints.allowedReceiveAssets);
|
|
761
|
+
if (receiveDenied)
|
|
762
|
+
return receiveDenied;
|
|
758
763
|
// maxSellAmount
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
return {
|
|
763
|
-
allow: false,
|
|
764
|
-
reason: `limit_order_create: sell amount ${amt} exceeds maxSellAmount ${constraints.maxSellAmount}`,
|
|
765
|
-
policyId: 'opParams',
|
|
766
|
-
};
|
|
767
|
-
}
|
|
768
|
-
}
|
|
764
|
+
const maxSellDenied = denyBoundExceeded('limit_order_create', 'sell amount', d.amount_to_sell && d.amount_to_sell.amount, d.amount_to_sell && d.amount_to_sell.amount, 'maxSellAmount', constraints.maxSellAmount);
|
|
765
|
+
if (maxSellDenied)
|
|
766
|
+
return maxSellDenied;
|
|
769
767
|
// maxReceiveAmount
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
return {
|
|
774
|
-
allow: false,
|
|
775
|
-
reason: `limit_order_create: receive amount ${amt} exceeds maxReceiveAmount ${constraints.maxReceiveAmount}`,
|
|
776
|
-
policyId: 'opParams',
|
|
777
|
-
};
|
|
778
|
-
}
|
|
779
|
-
}
|
|
768
|
+
const maxReceiveDenied = denyBoundExceeded('limit_order_create', 'receive amount', d.min_to_receive && d.min_to_receive.amount, d.min_to_receive && d.min_to_receive.amount, 'maxReceiveAmount', constraints.maxReceiveAmount);
|
|
769
|
+
if (maxReceiveDenied)
|
|
770
|
+
return maxReceiveDenied;
|
|
780
771
|
// allowFillOrKill
|
|
781
772
|
if (constraints.allowFillOrKill === false && d.fill_or_kill === true) {
|
|
782
|
-
return
|
|
783
|
-
allow: false,
|
|
784
|
-
reason: 'limit_order_create: fill_or_kill=true not permitted',
|
|
785
|
-
policyId: 'opParams',
|
|
786
|
-
};
|
|
773
|
+
return asDeny('limit_order_create: fill_or_kill=true not permitted');
|
|
787
774
|
}
|
|
788
775
|
}
|
|
789
776
|
if (opName === 'limit_order_update') {
|
|
790
777
|
// allowedSellAssets via new_price.base
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
return {
|
|
795
|
-
allow: false,
|
|
796
|
-
reason: `limit_order_update: base asset "${id}" not in allowedSellAssets`,
|
|
797
|
-
policyId: 'opParams',
|
|
798
|
-
};
|
|
799
|
-
}
|
|
800
|
-
}
|
|
778
|
+
const sellDenied = denyNotInList('limit_order_update', 'base asset', d.new_price && d.new_price.base && d.new_price.base.asset_id, 'allowedSellAssets', constraints.allowedSellAssets);
|
|
779
|
+
if (sellDenied)
|
|
780
|
+
return sellDenied;
|
|
801
781
|
// allowedReceiveAssets via new_price.quote
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
return {
|
|
806
|
-
allow: false,
|
|
807
|
-
reason: `limit_order_update: quote asset "${id}" not in allowedReceiveAssets`,
|
|
808
|
-
policyId: 'opParams',
|
|
809
|
-
};
|
|
810
|
-
}
|
|
811
|
-
}
|
|
782
|
+
const receiveDenied = denyNotInList('limit_order_update', 'quote asset', d.new_price && d.new_price.quote && d.new_price.quote.asset_id, 'allowedReceiveAssets', constraints.allowedReceiveAssets);
|
|
783
|
+
if (receiveDenied)
|
|
784
|
+
return receiveDenied;
|
|
812
785
|
// maxDeltaSellAmount (abs value)
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
return {
|
|
817
|
-
allow: false,
|
|
818
|
-
reason: `limit_order_update: |delta| ${Math.abs(delta)} exceeds maxDeltaSellAmount ${constraints.maxDeltaSellAmount}`,
|
|
819
|
-
policyId: 'opParams',
|
|
820
|
-
};
|
|
821
|
-
}
|
|
822
|
-
}
|
|
786
|
+
const maxDeltaSellDenied = denyBoundExceeded('limit_order_update', '|delta|', Math.abs(d.delta_amount_to_sell && d.delta_amount_to_sell.amount), Math.abs(d.delta_amount_to_sell && d.delta_amount_to_sell.amount), 'maxDeltaSellAmount', constraints.maxDeltaSellAmount);
|
|
787
|
+
if (maxDeltaSellDenied)
|
|
788
|
+
return maxDeltaSellDenied;
|
|
823
789
|
}
|
|
824
790
|
if (opName === 'call_order_update') {
|
|
825
791
|
// allowedAssets
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
allow: false,
|
|
839
|
-
reason: `call_order_update: debt asset "${debtId}" not in allowedAssets`,
|
|
840
|
-
policyId: 'opParams',
|
|
841
|
-
};
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
if (constraints.collateralAsset) {
|
|
845
|
-
const collId = d.delta_collateral && d.delta_collateral.asset_id;
|
|
846
|
-
const resolved = await resolveConfiguredAssetRefs([constraints.collateralAsset], 'collateralAsset');
|
|
847
|
-
if (!resolved.ok) {
|
|
848
|
-
return {
|
|
849
|
-
allow: false,
|
|
850
|
-
reason: `call_order_update: ${resolved.reason}`,
|
|
851
|
-
policyId: 'opParams',
|
|
852
|
-
};
|
|
853
|
-
}
|
|
854
|
-
if (collId && resolved.values && !resolved.values.includes(String(collId))) {
|
|
855
|
-
return {
|
|
856
|
-
allow: false,
|
|
857
|
-
reason: `call_order_update: collateral asset "${collId}" does not match collateralAsset`,
|
|
858
|
-
policyId: 'opParams',
|
|
859
|
-
};
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
if (Array.isArray(constraints.allowedCollateralAssets) && constraints.allowedCollateralAssets.length > 0) {
|
|
863
|
-
const collId = d.delta_collateral && d.delta_collateral.asset_id;
|
|
864
|
-
const resolved = await resolveConfiguredAssetRefs(constraints.allowedCollateralAssets, 'allowedCollateralAssets');
|
|
865
|
-
if (!resolved.ok) {
|
|
866
|
-
return {
|
|
867
|
-
allow: false,
|
|
868
|
-
reason: `call_order_update: ${resolved.reason}`,
|
|
869
|
-
policyId: 'opParams',
|
|
870
|
-
};
|
|
871
|
-
}
|
|
872
|
-
if (collId && resolved.values && !resolved.values.includes(String(collId))) {
|
|
873
|
-
return {
|
|
874
|
-
allow: false,
|
|
875
|
-
reason: `call_order_update: collateral asset "${collId}" not in allowedCollateralAssets`,
|
|
876
|
-
policyId: 'opParams',
|
|
877
|
-
};
|
|
878
|
-
}
|
|
879
|
-
}
|
|
792
|
+
const collDenied = denyNotInList('call_order_update', 'collateral asset', d.delta_collateral && d.delta_collateral.asset_id, 'allowedAssets', constraints.allowedAssets);
|
|
793
|
+
if (collDenied)
|
|
794
|
+
return collDenied;
|
|
795
|
+
const debtDenied = denyNotInList('call_order_update', 'debt asset', d.delta_debt && d.delta_debt.asset_id, 'allowedAssets', constraints.allowedAssets);
|
|
796
|
+
if (debtDenied)
|
|
797
|
+
return debtDenied;
|
|
798
|
+
const collateralMatchDenied = await denyAssetRefMismatch('call_order_update', 'collateral asset', d.delta_collateral && d.delta_collateral.asset_id, [constraints.collateralAsset], 'collateralAsset', { active: !!constraints.collateralAsset, matchOnly: true });
|
|
799
|
+
if (collateralMatchDenied)
|
|
800
|
+
return collateralMatchDenied;
|
|
801
|
+
const allowedCollateralDenied = await denyAssetRefMismatch('call_order_update', 'collateral asset', d.delta_collateral && d.delta_collateral.asset_id, constraints.allowedCollateralAssets, 'allowedCollateralAssets', { active: Array.isArray(constraints.allowedCollateralAssets) && constraints.allowedCollateralAssets.length > 0 });
|
|
802
|
+
if (allowedCollateralDenied)
|
|
803
|
+
return allowedCollateralDenied;
|
|
880
804
|
// maxDeltaCollateral
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
return {
|
|
885
|
-
allow: false,
|
|
886
|
-
reason: `call_order_update: |delta_collateral| ${Math.abs(amt)} exceeds maxDeltaCollateral ${constraints.maxDeltaCollateral}`,
|
|
887
|
-
policyId: 'opParams',
|
|
888
|
-
};
|
|
889
|
-
}
|
|
890
|
-
}
|
|
805
|
+
const maxDeltaCollateralDenied = denyBoundExceeded('call_order_update', '|delta_collateral|', Math.abs(d.delta_collateral && d.delta_collateral.amount), Math.abs(d.delta_collateral && d.delta_collateral.amount), 'maxDeltaCollateral', constraints.maxDeltaCollateral);
|
|
806
|
+
if (maxDeltaCollateralDenied)
|
|
807
|
+
return maxDeltaCollateralDenied;
|
|
891
808
|
// maxDeltaDebt
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
if (constraints.minCollateralRatio != null && d.extensions && d.extensions.target_collateral_ratio != null) {
|
|
903
|
-
const target = normalizeGrapheneCollateralRatio(d.extensions.target_collateral_ratio);
|
|
904
|
-
if (Number.isFinite(target) && target != null && target < constraints.minCollateralRatio) {
|
|
905
|
-
return {
|
|
906
|
-
allow: false,
|
|
907
|
-
reason: `call_order_update: target_collateral_ratio ${target} below minCollateralRatio ${constraints.minCollateralRatio}`,
|
|
908
|
-
policyId: 'opParams',
|
|
909
|
-
};
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
if (constraints.maxCollateralRatio != null && d.extensions && d.extensions.target_collateral_ratio != null) {
|
|
913
|
-
const target = normalizeGrapheneCollateralRatio(d.extensions.target_collateral_ratio);
|
|
914
|
-
if (Number.isFinite(target) && target != null && target > constraints.maxCollateralRatio) {
|
|
915
|
-
return {
|
|
916
|
-
allow: false,
|
|
917
|
-
reason: `call_order_update: target_collateral_ratio ${target} above maxCollateralRatio ${constraints.maxCollateralRatio}`,
|
|
918
|
-
policyId: 'opParams',
|
|
919
|
-
};
|
|
920
|
-
}
|
|
921
|
-
}
|
|
809
|
+
const maxDeltaDebtDenied = denyBoundExceeded('call_order_update', '|delta_debt|', Math.abs(d.delta_debt && d.delta_debt.amount), Math.abs(d.delta_debt && d.delta_debt.amount), 'maxDeltaDebt', constraints.maxDeltaDebt);
|
|
810
|
+
if (maxDeltaDebtDenied)
|
|
811
|
+
return maxDeltaDebtDenied;
|
|
812
|
+
const targetCollateralRatio = d.extensions && d.extensions.target_collateral_ratio != null ? normalizeGrapheneCollateralRatio(d.extensions.target_collateral_ratio) : NaN;
|
|
813
|
+
const minRatioDenied = denyBoundExceeded('call_order_update', 'target_collateral_ratio', targetCollateralRatio, targetCollateralRatio, 'minCollateralRatio', constraints.minCollateralRatio, { lower: true });
|
|
814
|
+
if (minRatioDenied)
|
|
815
|
+
return minRatioDenied;
|
|
816
|
+
const maxRatioDenied = denyBoundExceeded('call_order_update', 'target_collateral_ratio', targetCollateralRatio, targetCollateralRatio, 'maxCollateralRatio', constraints.maxCollateralRatio, { verb: 'above' });
|
|
817
|
+
if (maxRatioDenied)
|
|
818
|
+
return maxRatioDenied;
|
|
922
819
|
}
|
|
923
820
|
if (opName === 'credit_offer_accept') {
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
}
|
|
934
|
-
if (
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
};
|
|
943
|
-
}
|
|
944
|
-
if (assetId && resolved.values && !resolved.values.includes(String(assetId))) {
|
|
945
|
-
return {
|
|
946
|
-
allow: false,
|
|
947
|
-
reason: `credit_offer_accept: collateral asset "${assetId}" does not match collateralAsset`,
|
|
948
|
-
policyId: 'opParams',
|
|
949
|
-
};
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
if (Array.isArray(constraints.allowedCollateralAssets) && constraints.allowedCollateralAssets.length > 0) {
|
|
953
|
-
const assetId = d.collateral && d.collateral.asset_id;
|
|
954
|
-
const resolved = await resolveConfiguredAssetRefs(constraints.allowedCollateralAssets, 'allowedCollateralAssets');
|
|
955
|
-
if (!resolved.ok) {
|
|
956
|
-
return {
|
|
957
|
-
allow: false,
|
|
958
|
-
reason: `credit_offer_accept: ${resolved.reason}`,
|
|
959
|
-
policyId: 'opParams',
|
|
960
|
-
};
|
|
961
|
-
}
|
|
962
|
-
if (assetId && resolved.values && !resolved.values.includes(String(assetId))) {
|
|
963
|
-
return {
|
|
964
|
-
allow: false,
|
|
965
|
-
reason: `credit_offer_accept: collateral asset "${assetId}" not in allowedCollateralAssets`,
|
|
966
|
-
policyId: 'opParams',
|
|
967
|
-
};
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
if (Array.isArray(constraints.allowedDebtAssets) && constraints.allowedDebtAssets.length > 0) {
|
|
971
|
-
const assetId = d.borrow_amount && d.borrow_amount.asset_id;
|
|
972
|
-
const resolved = await resolveConfiguredAssetRefs(constraints.allowedDebtAssets, 'allowedDebtAssets');
|
|
973
|
-
if (!resolved.ok) {
|
|
974
|
-
return {
|
|
975
|
-
allow: false,
|
|
976
|
-
reason: `credit_offer_accept: ${resolved.reason}`,
|
|
977
|
-
policyId: 'opParams',
|
|
978
|
-
};
|
|
979
|
-
}
|
|
980
|
-
if (assetId && resolved.values && !resolved.values.includes(String(assetId))) {
|
|
981
|
-
return {
|
|
982
|
-
allow: false,
|
|
983
|
-
reason: `credit_offer_accept: debt asset "${assetId}" not in allowedDebtAssets`,
|
|
984
|
-
policyId: 'opParams',
|
|
985
|
-
};
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
if (constraints.maxFeeRate != null) {
|
|
989
|
-
const maxFeeRate = Number(d.max_fee_rate);
|
|
990
|
-
if (Number.isFinite(maxFeeRate) && maxFeeRate > constraints.maxFeeRate) {
|
|
991
|
-
return {
|
|
992
|
-
allow: false,
|
|
993
|
-
reason: `credit_offer_accept: max_fee_rate ${maxFeeRate} exceeds maxFeeRate ${constraints.maxFeeRate}`,
|
|
994
|
-
policyId: 'opParams',
|
|
995
|
-
};
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
if (constraints.minDurationSeconds != null) {
|
|
999
|
-
const minDurationSeconds = Number(d.min_duration_seconds);
|
|
1000
|
-
if (Number.isFinite(minDurationSeconds) && minDurationSeconds < constraints.minDurationSeconds) {
|
|
1001
|
-
return {
|
|
1002
|
-
allow: false,
|
|
1003
|
-
reason: `credit_offer_accept: min_duration_seconds ${minDurationSeconds} below minDurationSeconds ${constraints.minDurationSeconds}`,
|
|
1004
|
-
policyId: 'opParams',
|
|
1005
|
-
};
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
821
|
+
const offerDenied = denyNotInList('credit_offer_accept', 'offer', d.offer_id, 'allowedOfferIds', constraints.allowedOfferIds);
|
|
822
|
+
if (offerDenied)
|
|
823
|
+
return offerDenied;
|
|
824
|
+
const collateralMatchDenied = await denyAssetRefMismatch('credit_offer_accept', 'collateral asset', d.collateral && d.collateral.asset_id, [constraints.collateralAsset], 'collateralAsset', { active: !!constraints.collateralAsset, matchOnly: true });
|
|
825
|
+
if (collateralMatchDenied)
|
|
826
|
+
return collateralMatchDenied;
|
|
827
|
+
const allowedCollateralDenied = await denyAssetRefMismatch('credit_offer_accept', 'collateral asset', d.collateral && d.collateral.asset_id, constraints.allowedCollateralAssets, 'allowedCollateralAssets', { active: Array.isArray(constraints.allowedCollateralAssets) && constraints.allowedCollateralAssets.length > 0 });
|
|
828
|
+
if (allowedCollateralDenied)
|
|
829
|
+
return allowedCollateralDenied;
|
|
830
|
+
const allowedDebtDenied = await denyAssetRefMismatch('credit_offer_accept', 'debt asset', d.borrow_amount && d.borrow_amount.asset_id, constraints.allowedDebtAssets, 'allowedDebtAssets', { active: Array.isArray(constraints.allowedDebtAssets) && constraints.allowedDebtAssets.length > 0 });
|
|
831
|
+
if (allowedDebtDenied)
|
|
832
|
+
return allowedDebtDenied;
|
|
833
|
+
const maxFeeDenied = denyBoundExceeded('credit_offer_accept', 'max_fee_rate', Number(d.max_fee_rate), Number(d.max_fee_rate), 'maxFeeRate', constraints.maxFeeRate);
|
|
834
|
+
if (maxFeeDenied)
|
|
835
|
+
return maxFeeDenied;
|
|
836
|
+
const minDurationDenied = denyBoundExceeded('credit_offer_accept', 'min_duration_seconds', Number(d.min_duration_seconds), Number(d.min_duration_seconds), 'minDurationSeconds', constraints.minDurationSeconds, { lower: true });
|
|
837
|
+
if (minDurationDenied)
|
|
838
|
+
return minDurationDenied;
|
|
1008
839
|
}
|
|
1009
840
|
if (opName === 'credit_deal_repay') {
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
}
|
|
1020
|
-
if (assetId && resolved.values && !resolved.values.includes(String(assetId))) {
|
|
1021
|
-
return {
|
|
1022
|
-
allow: false,
|
|
1023
|
-
reason: `credit_deal_repay: debt asset "${assetId}" not in allowedDebtAssets`,
|
|
1024
|
-
policyId: 'opParams',
|
|
1025
|
-
};
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
if (constraints.maxRepayAmount != null) {
|
|
1029
|
-
const amt = d.repay_amount && d.repay_amount.amount;
|
|
1030
|
-
if (typeof amt === 'number' && amt > constraints.maxRepayAmount) {
|
|
1031
|
-
return {
|
|
1032
|
-
allow: false,
|
|
1033
|
-
reason: `credit_deal_repay: repay amount ${amt} exceeds maxRepayAmount ${constraints.maxRepayAmount}`,
|
|
1034
|
-
policyId: 'opParams',
|
|
1035
|
-
};
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
if (constraints.maxCreditFee != null) {
|
|
1039
|
-
const fee = d.credit_fee && d.credit_fee.amount;
|
|
1040
|
-
if (typeof fee === 'number' && fee > constraints.maxCreditFee) {
|
|
1041
|
-
return {
|
|
1042
|
-
allow: false,
|
|
1043
|
-
reason: `credit_deal_repay: credit fee ${fee} exceeds maxCreditFee ${constraints.maxCreditFee}`,
|
|
1044
|
-
policyId: 'opParams',
|
|
1045
|
-
};
|
|
1046
|
-
}
|
|
1047
|
-
}
|
|
841
|
+
const allowedDebtDenied = await denyAssetRefMismatch('credit_deal_repay', 'debt asset', d.repay_amount && d.repay_amount.asset_id, constraints.allowedDebtAssets, 'allowedDebtAssets', { active: Array.isArray(constraints.allowedDebtAssets) && constraints.allowedDebtAssets.length > 0 });
|
|
842
|
+
if (allowedDebtDenied)
|
|
843
|
+
return allowedDebtDenied;
|
|
844
|
+
const maxRepayDenied = denyBoundExceeded('credit_deal_repay', 'repay amount', d.repay_amount && d.repay_amount.amount, d.repay_amount && d.repay_amount.amount, 'maxRepayAmount', constraints.maxRepayAmount);
|
|
845
|
+
if (maxRepayDenied)
|
|
846
|
+
return maxRepayDenied;
|
|
847
|
+
const maxCreditFeeDenied = denyBoundExceeded('credit_deal_repay', 'credit fee', d.credit_fee && d.credit_fee.amount, d.credit_fee && d.credit_fee.amount, 'maxCreditFee', constraints.maxCreditFee);
|
|
848
|
+
if (maxCreditFeeDenied)
|
|
849
|
+
return maxCreditFeeDenied;
|
|
1048
850
|
}
|
|
1049
851
|
if (opName === 'credit_deal_update') {
|
|
1050
852
|
if (constraints.allowAutoRepay === false && d.auto_repay) {
|
|
1051
|
-
return
|
|
1052
|
-
allow: false,
|
|
1053
|
-
reason: 'credit_deal_update: auto_repay change not permitted',
|
|
1054
|
-
policyId: 'opParams',
|
|
1055
|
-
};
|
|
853
|
+
return asDeny('credit_deal_update: auto_repay change not permitted');
|
|
1056
854
|
}
|
|
1057
855
|
}
|
|
1058
856
|
if (opName === 'liquidity_pool_exchange') {
|
|
1059
857
|
// allowedPools
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
allow: false,
|
|
1064
|
-
reason: `liquidity_pool_exchange: pool "${d.pool}" not in allowedPools`,
|
|
1065
|
-
policyId: 'opParams',
|
|
1066
|
-
};
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
858
|
+
const poolDenied = denyNotInList('liquidity_pool_exchange', 'pool', d.pool, 'allowedPools', constraints.allowedPools, true);
|
|
859
|
+
if (poolDenied)
|
|
860
|
+
return poolDenied;
|
|
1069
861
|
// allowedSellAssets
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
return {
|
|
1074
|
-
allow: false,
|
|
1075
|
-
reason: `liquidity_pool_exchange: sell asset "${id}" not in allowedSellAssets`,
|
|
1076
|
-
policyId: 'opParams',
|
|
1077
|
-
};
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
862
|
+
const sellDenied = denyNotInList('liquidity_pool_exchange', 'sell asset', d.amount_to_sell && d.amount_to_sell.asset_id, 'allowedSellAssets', constraints.allowedSellAssets);
|
|
863
|
+
if (sellDenied)
|
|
864
|
+
return sellDenied;
|
|
1080
865
|
// allowedReceiveAssets
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
return {
|
|
1085
|
-
allow: false,
|
|
1086
|
-
reason: `liquidity_pool_exchange: receive asset "${id}" not in allowedReceiveAssets`,
|
|
1087
|
-
policyId: 'opParams',
|
|
1088
|
-
};
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
866
|
+
const receiveDenied = denyNotInList('liquidity_pool_exchange', 'receive asset', d.min_to_receive && d.min_to_receive.asset_id, 'allowedReceiveAssets', constraints.allowedReceiveAssets);
|
|
867
|
+
if (receiveDenied)
|
|
868
|
+
return receiveDenied;
|
|
1091
869
|
// maxSellAmount
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
return {
|
|
1096
|
-
allow: false,
|
|
1097
|
-
reason: `liquidity_pool_exchange: sell amount ${amt} exceeds maxSellAmount ${constraints.maxSellAmount}`,
|
|
1098
|
-
policyId: 'opParams',
|
|
1099
|
-
};
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
870
|
+
const maxSellDenied = denyBoundExceeded('liquidity_pool_exchange', 'sell amount', d.amount_to_sell && d.amount_to_sell.amount, d.amount_to_sell && d.amount_to_sell.amount, 'maxSellAmount', constraints.maxSellAmount);
|
|
871
|
+
if (maxSellDenied)
|
|
872
|
+
return maxSellDenied;
|
|
1102
873
|
}
|
|
1103
874
|
// limit_order_cancel — no constraints
|
|
1104
875
|
return { allow: true, reason: null, policyId: null };
|