@gearbox-protocol/sdk 14.12.0-next.69 → 14.12.0-next.70
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/dist/cjs/common-utils/charts/credit-session.js +0 -1
- package/dist/cjs/common-utils/index.js +1 -1
- package/dist/cjs/common-utils/utils/creditAccount/index.js +1 -1
- package/dist/cjs/common-utils/utils/creditAccount/quota-utils.js +0 -1
- package/dist/cjs/common-utils/utils/index.js +1 -1
- package/dist/cjs/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.js +1 -1
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +81 -66
- package/dist/cjs/sdk/accounts/index.js +2 -0
- package/dist/cjs/sdk/accounts/intents/index.js +388 -0
- package/dist/cjs/sdk/accounts/intents/intents/index.js +14 -0
- package/dist/cjs/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.js +121 -0
- package/dist/cjs/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.js +15 -0
- package/dist/cjs/sdk/accounts/intents/intents/resume/close/close.fixtures.js +108 -0
- package/dist/cjs/sdk/accounts/intents/intents/resume/close/close.js +51 -0
- package/dist/cjs/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.js +130 -0
- package/dist/cjs/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.js +83 -0
- package/dist/cjs/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.js +117 -0
- package/dist/cjs/sdk/accounts/intents/intents/resume/deposit/deposit.js +15 -0
- package/dist/cjs/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.js +95 -0
- package/dist/cjs/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.js +15 -0
- package/dist/cjs/sdk/accounts/intents/intents/resume/index.js +13 -0
- package/dist/cjs/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.js +138 -0
- package/dist/cjs/sdk/accounts/intents/intents/resume/withdraw/withdraw.js +161 -0
- package/dist/cjs/sdk/accounts/intents/operations/add-collateral/index.js +17 -0
- package/dist/cjs/sdk/accounts/intents/operations/claim-delayed/index.js +54 -0
- package/dist/cjs/sdk/accounts/intents/operations/close-credit-account/index.js +26 -0
- package/dist/cjs/sdk/accounts/intents/operations/decrease-debt/index.js +12 -0
- package/dist/cjs/sdk/accounts/intents/operations/increase-debt/index.js +12 -0
- package/dist/cjs/sdk/accounts/intents/operations/index.js +27 -0
- package/dist/cjs/sdk/accounts/intents/operations/quota-update/index.js +22 -0
- package/dist/cjs/sdk/accounts/intents/operations/repay-credit-account/index.js +22 -0
- package/dist/cjs/sdk/accounts/intents/operations/start-delayed-withdrawal/index.js +18 -0
- package/dist/cjs/sdk/accounts/intents/operations/swap/index.js +18 -0
- package/dist/cjs/sdk/accounts/intents/operations/types.js +1 -0
- package/dist/cjs/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.js +27 -0
- package/dist/cjs/sdk/accounts/intents/operations/withdraw-collateral/index.js +43 -0
- package/dist/cjs/sdk/accounts/intents/operations/wrap-rwa-collateral/index.js +27 -0
- package/dist/cjs/sdk/accounts/intents/quoters/close.js +58 -0
- package/dist/cjs/sdk/accounts/intents/quoters/index.js +7 -0
- package/dist/cjs/sdk/accounts/intents/quoters/swap.js +79 -0
- package/dist/cjs/sdk/accounts/intents/testing/expect.js +167 -0
- package/dist/cjs/sdk/accounts/intents/testing/resume.js +172 -0
- package/dist/cjs/sdk/accounts/intents/testing/sdk-mock.js +179 -0
- package/dist/cjs/sdk/accounts/intents/types.js +1 -0
- package/dist/cjs/sdk/accounts/intents/utils/assemble-operation-calls.js +7 -0
- package/dist/cjs/sdk/accounts/intents/utils/borrowed-amount-plus-interest-and-fees.js +13 -0
- package/dist/cjs/sdk/accounts/intents/utils/common.js +43 -0
- package/dist/cjs/sdk/accounts/intents/utils/convert-amount.js +37 -0
- package/dist/cjs/sdk/accounts/intents/utils/index.js +19 -0
- package/dist/cjs/sdk/accounts/intents/utils/quotas-for-update.js +122 -0
- package/dist/cjs/sdk/accounts/intents/utils/simulate-adjust-state.js +39 -0
- package/dist/cjs/sdk/accounts/intents/utils/simulate-assets.js +69 -0
- package/dist/cjs/sdk/accounts/intents/utils/with-quota-update.js +13 -0
- package/dist/cjs/sdk/index.js +2 -0
- package/dist/esm/common-utils/charts/credit-session.js +0 -1
- package/dist/esm/common-utils/index.js +1 -1
- package/dist/esm/common-utils/utils/creditAccount/index.js +1 -1
- package/dist/esm/common-utils/utils/creditAccount/quota-utils.js +0 -1
- package/dist/esm/common-utils/utils/index.js +1 -1
- package/dist/esm/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.js +1 -1
- package/dist/esm/dev/AccountOpener.js +1 -1
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
- package/dist/esm/preview/trace/extractTransfers.js +1 -1
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +83 -68
- package/dist/esm/sdk/accounts/index.js +2 -1
- package/dist/esm/sdk/accounts/intents/index.js +387 -0
- package/dist/esm/sdk/accounts/intents/intents/index.js +8 -0
- package/dist/esm/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.js +107 -0
- package/dist/esm/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.js +14 -0
- package/dist/esm/sdk/accounts/intents/intents/resume/close/close.fixtures.js +94 -0
- package/dist/esm/sdk/accounts/intents/intents/resume/close/close.js +50 -0
- package/dist/esm/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.js +114 -0
- package/dist/esm/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.js +82 -0
- package/dist/esm/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.js +110 -0
- package/dist/esm/sdk/accounts/intents/intents/resume/deposit/deposit.js +14 -0
- package/dist/esm/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.js +88 -0
- package/dist/esm/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.js +14 -0
- package/dist/esm/sdk/accounts/intents/intents/resume/index.js +7 -0
- package/dist/esm/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.js +121 -0
- package/dist/esm/sdk/accounts/intents/intents/resume/withdraw/withdraw.js +160 -0
- package/dist/esm/sdk/accounts/intents/operations/add-collateral/index.js +16 -0
- package/dist/esm/sdk/accounts/intents/operations/claim-delayed/index.js +52 -0
- package/dist/esm/sdk/accounts/intents/operations/close-credit-account/index.js +25 -0
- package/dist/esm/sdk/accounts/intents/operations/decrease-debt/index.js +11 -0
- package/dist/esm/sdk/accounts/intents/operations/increase-debt/index.js +11 -0
- package/dist/esm/sdk/accounts/intents/operations/index.js +14 -0
- package/dist/esm/sdk/accounts/intents/operations/quota-update/index.js +21 -0
- package/dist/esm/sdk/accounts/intents/operations/repay-credit-account/index.js +21 -0
- package/dist/esm/sdk/accounts/intents/operations/start-delayed-withdrawal/index.js +17 -0
- package/dist/esm/sdk/accounts/intents/operations/swap/index.js +17 -0
- package/dist/esm/sdk/accounts/intents/operations/types.js +1 -0
- package/dist/esm/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.js +26 -0
- package/dist/esm/sdk/accounts/intents/operations/withdraw-collateral/index.js +42 -0
- package/dist/esm/sdk/accounts/intents/operations/wrap-rwa-collateral/index.js +26 -0
- package/dist/esm/sdk/accounts/intents/quoters/close.js +56 -0
- package/dist/esm/sdk/accounts/intents/quoters/index.js +3 -0
- package/dist/esm/sdk/accounts/intents/quoters/swap.js +77 -0
- package/dist/esm/sdk/accounts/intents/testing/expect.js +162 -0
- package/dist/esm/sdk/accounts/intents/testing/resume.js +157 -0
- package/dist/esm/sdk/accounts/intents/testing/sdk-mock.js +172 -0
- package/dist/esm/sdk/accounts/intents/types.js +1 -0
- package/dist/esm/sdk/accounts/intents/utils/assemble-operation-calls.js +6 -0
- package/dist/esm/sdk/accounts/intents/utils/borrowed-amount-plus-interest-and-fees.js +12 -0
- package/dist/esm/sdk/accounts/intents/utils/common.js +40 -0
- package/dist/esm/sdk/accounts/intents/utils/convert-amount.js +36 -0
- package/dist/esm/sdk/accounts/intents/utils/index.js +9 -0
- package/dist/esm/sdk/accounts/intents/utils/quotas-for-update.js +121 -0
- package/dist/esm/sdk/accounts/intents/utils/simulate-adjust-state.js +38 -0
- package/dist/esm/sdk/accounts/intents/utils/simulate-assets.js +68 -0
- package/dist/esm/sdk/accounts/intents/utils/with-quota-update.js +12 -0
- package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
- package/dist/esm/sdk/base/TokensMeta.js +2 -2
- package/dist/esm/sdk/chain/detectNetwork.js +1 -1
- package/dist/esm/sdk/core/createAddressProvider.js +1 -1
- package/dist/esm/sdk/index.js +2 -1
- package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
- package/dist/esm/sdk/market/pool/PoolV310Contract.js +1 -1
- package/dist/esm/sdk/market/zapper/IETHZapperContract.js +1 -1
- package/dist/esm/sdk/market/zapper/ZapperContract.js +1 -1
- package/dist/esm/sdk/pools/PoolService.js +1 -1
- package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
- package/dist/types/common-utils/index.d.ts +19 -19
- package/dist/types/common-utils/static/index.d.ts +1 -1
- package/dist/types/common-utils/utils/apy/index.d.ts +1 -1
- package/dist/types/common-utils/utils/creditAccount/calc-health-factor.d.ts +1 -1
- package/dist/types/common-utils/utils/creditAccount/calc-overall-apy.d.ts +1 -1
- package/dist/types/common-utils/utils/creditAccount/calc-quota-borrow-rate.d.ts +1 -1
- package/dist/types/common-utils/utils/creditAccount/debt.d.ts +1 -1
- package/dist/types/common-utils/utils/creditAccount/index.d.ts +1 -1
- package/dist/types/common-utils/utils/creditAccount/liquidation-price.d.ts +1 -1
- package/dist/types/common-utils/utils/creditAccount/quota-utils.d.ts +0 -1
- package/dist/types/common-utils/utils/creditAccount/sort.d.ts +1 -1
- package/dist/types/common-utils/utils/index.d.ts +3 -3
- package/dist/types/common-utils/utils/strategies/credit-managers/get-wallet-balances-allowed-on-cm.d.ts +1 -1
- package/dist/types/common-utils/utils/strategies/strategy-info/calculate-total-apy.d.ts +1 -1
- package/dist/types/common-utils/utils/strategies/strategy-info/calculate-total-points.d.ts +1 -1
- package/dist/types/common-utils/utils/strategies/strategy-info/types.d.ts +1 -1
- package/dist/types/common-utils/utils/strategies/tokens/add-amount-in-target.d.ts +1 -1
- package/dist/types/common-utils/utils/strategies/tokens/get-list-with-amount-in-target.d.ts +1 -1
- package/dist/types/common-utils/utils/strategies/types/credit-manager-data-legacy.d.ts +1 -1
- package/dist/types/common-utils/utils/strategies/types/strategies-cm-list.d.ts +1 -1
- package/dist/types/common-utils/utils/strategies/types/strategy-earnings.d.ts +1 -1
- package/dist/types/common-utils/utils/strategies/types/strategy.d.ts +1 -1
- package/dist/types/common-utils/utils/validation/validate-open-account.d.ts +1 -1
- package/dist/types/common-utils/utils/validation/validate-quota.d.ts +1 -1
- package/dist/types/plugins/apy/ApyPlugin.d.ts +1 -1
- package/dist/types/plugins/apy/pool-apy-utils.d.ts +1 -1
- package/dist/types/plugins/apy/strategy-data-source.d.ts +1 -1
- package/dist/types/plugins/apy/types.d.ts +1 -1
- package/dist/types/plugins/remote-configs/CustomConfigSource.d.ts +1 -1
- package/dist/types/plugins/remote-configs/RemoteConfigSource.d.ts +1 -1
- package/dist/types/plugins/remote-configs/RemoteConfigsPlugin.d.ts +1 -1
- package/dist/types/plugins/remote-configs/index.d.ts +1 -1
- package/dist/types/plugins/remote-configs/types.d.ts +1 -1
- package/dist/types/rewards/rewards/extra-apy.d.ts +1 -1
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +30 -10
- package/dist/types/sdk/accounts/index.d.ts +2 -1
- package/dist/types/sdk/accounts/intents/index.d.ts +22 -0
- package/dist/types/sdk/accounts/intents/intents/index.d.ts +8 -0
- package/dist/types/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.d.ts +13 -0
- package/dist/types/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.d.ts +38 -0
- package/dist/types/sdk/accounts/intents/intents/resume/close/close.d.ts +26 -0
- package/dist/types/sdk/accounts/intents/intents/resume/close/close.fixtures.d.ts +63 -0
- package/dist/types/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.d.ts +26 -0
- package/dist/types/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.d.ts +86 -0
- package/dist/types/sdk/accounts/intents/intents/resume/deposit/deposit.d.ts +13 -0
- package/dist/types/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.d.ts +48 -0
- package/dist/types/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.d.ts +13 -0
- package/dist/types/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.d.ts +46 -0
- package/dist/types/sdk/accounts/intents/intents/resume/index.d.ts +7 -0
- package/dist/types/sdk/accounts/intents/intents/resume/withdraw/withdraw.d.ts +33 -0
- package/dist/types/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.d.ts +68 -0
- package/dist/types/sdk/accounts/intents/operations/add-collateral/index.d.ts +23 -0
- package/dist/types/sdk/accounts/intents/operations/claim-delayed/index.d.ts +55 -0
- package/dist/types/sdk/accounts/intents/operations/close-credit-account/index.d.ts +22 -0
- package/dist/types/sdk/accounts/intents/operations/decrease-debt/index.d.ts +18 -0
- package/dist/types/sdk/accounts/intents/operations/increase-debt/index.d.ts +18 -0
- package/dist/types/sdk/accounts/intents/operations/index.d.ts +14 -0
- package/dist/types/sdk/accounts/intents/operations/quota-update/index.d.ts +24 -0
- package/dist/types/sdk/accounts/intents/operations/repay-credit-account/index.d.ts +32 -0
- package/dist/types/sdk/accounts/intents/operations/start-delayed-withdrawal/index.d.ts +23 -0
- package/dist/types/sdk/accounts/intents/operations/swap/index.d.ts +28 -0
- package/dist/types/sdk/accounts/intents/operations/types.d.ts +21 -0
- package/dist/types/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.d.ts +30 -0
- package/dist/types/sdk/accounts/intents/operations/withdraw-collateral/index.d.ts +36 -0
- package/dist/types/sdk/accounts/intents/operations/wrap-rwa-collateral/index.d.ts +30 -0
- package/dist/types/sdk/accounts/intents/quoters/close.d.ts +43 -0
- package/dist/types/sdk/accounts/intents/quoters/index.d.ts +3 -0
- package/dist/types/sdk/accounts/intents/quoters/swap.d.ts +43 -0
- package/dist/types/sdk/accounts/intents/testing/expect.d.ts +52 -0
- package/dist/types/sdk/accounts/intents/testing/resume.d.ts +84 -0
- package/dist/types/sdk/accounts/intents/testing/sdk-mock.d.ts +90 -0
- package/dist/types/sdk/accounts/intents/types.d.ts +75 -0
- package/dist/types/sdk/accounts/intents/utils/assemble-operation-calls.d.ts +10 -0
- package/dist/types/sdk/accounts/intents/utils/borrowed-amount-plus-interest-and-fees.d.ts +17 -0
- package/dist/types/sdk/accounts/intents/utils/common.d.ts +19 -0
- package/dist/types/sdk/accounts/intents/utils/convert-amount.d.ts +13 -0
- package/dist/types/sdk/accounts/intents/utils/index.d.ts +9 -0
- package/dist/types/sdk/accounts/intents/utils/quotas-for-update.d.ts +35 -0
- package/dist/types/sdk/accounts/intents/utils/simulate-adjust-state.d.ts +19 -0
- package/dist/types/sdk/accounts/intents/utils/simulate-assets.d.ts +21 -0
- package/dist/types/sdk/accounts/intents/utils/with-quota-update.d.ts +16 -0
- package/dist/types/sdk/accounts/types.d.ts +20 -0
- package/dist/types/sdk/index.d.ts +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_accounts_intents_testing_sdk_mock = require("./sdk-mock.js");
|
|
3
|
+
let vitest = require("vitest");
|
|
4
|
+
//#region src/sdk/accounts/intents/testing/expect.ts
|
|
5
|
+
function expectedCalls(expected) {
|
|
6
|
+
return expected.calls ?? [];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Fills sentinel `calls` for onchain resume expectations. Shared fixtures keep
|
|
10
|
+
* `calls: []` for offchain; onchain tests map through this helper.
|
|
11
|
+
*/
|
|
12
|
+
function withOnchainOpCalls(ops) {
|
|
13
|
+
return ops.map((op) => {
|
|
14
|
+
switch (op.type) {
|
|
15
|
+
case "claimDelayedWithdrawal": return {
|
|
16
|
+
...op,
|
|
17
|
+
calls: [require_sdk_accounts_intents_testing_sdk_mock.MOCK_CLAIM_CALL]
|
|
18
|
+
};
|
|
19
|
+
case "changeQuota": return {
|
|
20
|
+
...op,
|
|
21
|
+
calls: [require_sdk_accounts_intents_testing_sdk_mock.CA_OP_CALLS.changeQuota]
|
|
22
|
+
};
|
|
23
|
+
case "decreaseDebt": return {
|
|
24
|
+
...op,
|
|
25
|
+
calls: [require_sdk_accounts_intents_testing_sdk_mock.CA_OP_CALLS.decreaseDebt]
|
|
26
|
+
};
|
|
27
|
+
case "withdrawCollateral": return {
|
|
28
|
+
...op,
|
|
29
|
+
calls: [require_sdk_accounts_intents_testing_sdk_mock.CA_OP_CALLS.withdrawCollateral]
|
|
30
|
+
};
|
|
31
|
+
case "swap": return {
|
|
32
|
+
...op,
|
|
33
|
+
calls: op.calls?.length ? op.calls : [require_sdk_accounts_intents_testing_sdk_mock.MOCK_ROUTER_CALL]
|
|
34
|
+
};
|
|
35
|
+
case "wrapRwaCollateral": return {
|
|
36
|
+
...op,
|
|
37
|
+
calls: op.calls?.length ? op.calls : [require_sdk_accounts_intents_testing_sdk_mock.MOCK_RWA_WRAP_CALL]
|
|
38
|
+
};
|
|
39
|
+
case "unwrapRwaCollateral": return {
|
|
40
|
+
...op,
|
|
41
|
+
calls: op.calls?.length ? op.calls : [require_sdk_accounts_intents_testing_sdk_mock.MOCK_RWA_UNWRAP_CALL]
|
|
42
|
+
};
|
|
43
|
+
case "closeCreditAccount": return {
|
|
44
|
+
...op,
|
|
45
|
+
calls: op.calls?.length ? op.calls : [require_sdk_accounts_intents_testing_sdk_mock.MOCK_CLOSE_CALL]
|
|
46
|
+
};
|
|
47
|
+
default: return op;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function matchOp(actual, expected, index) {
|
|
52
|
+
(0, vitest.expect)(actual.type, `op[${index}].type`).toBe(expected.type);
|
|
53
|
+
switch (expected.type) {
|
|
54
|
+
case "claimDelayedWithdrawal":
|
|
55
|
+
if (actual.type !== "claimDelayedWithdrawal") return;
|
|
56
|
+
(0, vitest.expect)(actual.token, `op[${index}].token`).toBe(expected.token);
|
|
57
|
+
(0, vitest.expect)(actual.withdrawalPhantomToken, `op[${index}].withdrawalPhantomToken`).toBe(expected.withdrawalPhantomToken);
|
|
58
|
+
(0, vitest.expect)(actual.withdrawalTokenSpent, `op[${index}].withdrawalTokenSpent`).toBe(expected.withdrawalTokenSpent);
|
|
59
|
+
(0, vitest.expect)(actual.outputs, `op[${index}].outputs`).toEqual(expected.outputs);
|
|
60
|
+
(0, vitest.expect)(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
|
|
61
|
+
break;
|
|
62
|
+
case "changeQuota":
|
|
63
|
+
if (actual.type !== "changeQuota") return;
|
|
64
|
+
(0, vitest.expect)(actual.quotaIncrease, `op[${index}].quotaIncrease`).toEqual(expected.quotaIncrease);
|
|
65
|
+
(0, vitest.expect)(actual.quotaDecrease, `op[${index}].quotaDecrease`).toEqual(expected.quotaDecrease);
|
|
66
|
+
(0, vitest.expect)(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
|
|
67
|
+
break;
|
|
68
|
+
case "closeCreditAccount":
|
|
69
|
+
if (actual.type !== "closeCreditAccount") return;
|
|
70
|
+
(0, vitest.expect)(actual.amount, `op[${index}].amount`).toBe(expected.amount);
|
|
71
|
+
(0, vitest.expect)(actual.minAmount, `op[${index}].minAmount`).toBe(expected.minAmount);
|
|
72
|
+
(0, vitest.expect)(actual.underlyingBalance, `op[${index}].underlyingBalance`).toBe(expected.underlyingBalance);
|
|
73
|
+
(0, vitest.expect)(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
|
|
74
|
+
break;
|
|
75
|
+
case "swap":
|
|
76
|
+
if (actual.type !== "swap") return;
|
|
77
|
+
(0, vitest.expect)(actual.from, `op[${index}].from`).toEqual(expected.from);
|
|
78
|
+
(0, vitest.expect)(actual.tokenOut, `op[${index}].tokenOut`).toBe(expected.tokenOut);
|
|
79
|
+
(0, vitest.expect)(actual.amountOut, `op[${index}].amountOut`).toBe(expected.amountOut);
|
|
80
|
+
(0, vitest.expect)(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
|
|
81
|
+
break;
|
|
82
|
+
case "decreaseDebt":
|
|
83
|
+
if (actual.type !== "decreaseDebt") return;
|
|
84
|
+
(0, vitest.expect)(actual.amount, `op[${index}].amount`).toBe(expected.amount);
|
|
85
|
+
(0, vitest.expect)(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
|
|
86
|
+
break;
|
|
87
|
+
case "withdrawCollateral":
|
|
88
|
+
if (actual.type !== "withdrawCollateral") return;
|
|
89
|
+
(0, vitest.expect)(actual.token, `op[${index}].token`).toBe(expected.token);
|
|
90
|
+
(0, vitest.expect)(actual.amount, `op[${index}].amount`).toBe(expected.amount);
|
|
91
|
+
(0, vitest.expect)(actual.to, `op[${index}].to`).toBe(expected.to);
|
|
92
|
+
(0, vitest.expect)(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
|
|
93
|
+
break;
|
|
94
|
+
case "unwrapRwaCollateral":
|
|
95
|
+
if (actual.type !== "unwrapRwaCollateral") return;
|
|
96
|
+
(0, vitest.expect)(actual.tokenIn, `op[${index}].tokenIn`).toBe(expected.tokenIn);
|
|
97
|
+
(0, vitest.expect)(actual.tokenOut, `op[${index}].tokenOut`).toBe(expected.tokenOut);
|
|
98
|
+
(0, vitest.expect)(actual.amount, `op[${index}].amount`).toBe(expected.amount);
|
|
99
|
+
(0, vitest.expect)(actual.amountOut, `op[${index}].amountOut`).toBe(expected.amountOut);
|
|
100
|
+
(0, vitest.expect)(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
|
|
101
|
+
break;
|
|
102
|
+
case "wrapRwaCollateral":
|
|
103
|
+
if (actual.type !== "wrapRwaCollateral") return;
|
|
104
|
+
(0, vitest.expect)(actual.tokenIn, `op[${index}].tokenIn`).toBe(expected.tokenIn);
|
|
105
|
+
(0, vitest.expect)(actual.tokenOut, `op[${index}].tokenOut`).toBe(expected.tokenOut);
|
|
106
|
+
(0, vitest.expect)(actual.amount, `op[${index}].amount`).toBe(expected.amount);
|
|
107
|
+
(0, vitest.expect)(actual.amountOut, `op[${index}].amountOut`).toBe(expected.amountOut);
|
|
108
|
+
(0, vitest.expect)(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** Asserts exact operations on a raw op array (type + tokens + amounts). */
|
|
112
|
+
function expectOpsArrayExact(ops, expected) {
|
|
113
|
+
(0, vitest.expect)(ops.length, "operations.length").toBe(expected.length);
|
|
114
|
+
for (let i = 0; i < expected.length; i++) {
|
|
115
|
+
const actual = ops[i];
|
|
116
|
+
const exp = expected[i];
|
|
117
|
+
if (actual === void 0 || exp === void 0) {
|
|
118
|
+
vitest.expect.fail(`missing op at index ${i}`);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
matchOp(actual, exp, i);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/** Asserts exact calls on a raw MultiCall array (target + callData). */
|
|
125
|
+
function expectCallsArrayExact(calls, expected, label = "calls") {
|
|
126
|
+
(0, vitest.expect)(calls.length, `${label}.length`).toBe(expected.length);
|
|
127
|
+
for (let i = 0; i < expected.length; i++) {
|
|
128
|
+
const actual = calls[i];
|
|
129
|
+
const exp = expected[i];
|
|
130
|
+
if (actual === void 0 || exp === void 0) {
|
|
131
|
+
vitest.expect.fail(`missing call at index ${i}`);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
(0, vitest.expect)(actual.target, `${label}[${i}].target`).toBe(exp.target);
|
|
135
|
+
(0, vitest.expect)(actual.callData, `${label}[${i}].callData`).toBe(exp.callData);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Asserts a successful adjust-style resume preview: ok, instant branch present,
|
|
140
|
+
* exact calls (empty unless `expectedCalls` is provided), metrics from the
|
|
141
|
+
* post-claim CA, and exact operations (incl. changeQuota).
|
|
142
|
+
* Returns the adjust preview state for further asset/quota assertions.
|
|
143
|
+
*/
|
|
144
|
+
function expectAdjustResumePreview(result, args) {
|
|
145
|
+
(0, vitest.expect)(result.ok).toBe(true);
|
|
146
|
+
if (!result.ok) throw new Error("expected ok resume preview");
|
|
147
|
+
(0, vitest.expect)(result.instant, "instant branch").toBeDefined();
|
|
148
|
+
if (!result.instant) throw new Error("expected instant branch");
|
|
149
|
+
if (args.expectedCalls) expectCallsArrayExact(result.instant.calls, args.expectedCalls);
|
|
150
|
+
else (0, vitest.expect)(result.instant.calls).toEqual([]);
|
|
151
|
+
const state = result.instant.preview.min;
|
|
152
|
+
(0, vitest.expect)(state.kind).toBe("adjust");
|
|
153
|
+
if (state.kind !== "adjust") throw new Error("expected adjust preview state");
|
|
154
|
+
(0, vitest.expect)(state.totalValue).toBe(args.totalValue);
|
|
155
|
+
(0, vitest.expect)(state.accountDebt).toBe(args.accountDebt);
|
|
156
|
+
expectOpsArrayExact(result.instant.operations, args.expectedOps);
|
|
157
|
+
return state;
|
|
158
|
+
}
|
|
159
|
+
function assetBalance(assets, token) {
|
|
160
|
+
return assets.find((a) => a.token === token)?.balance ?? 0n;
|
|
161
|
+
}
|
|
162
|
+
//#endregion
|
|
163
|
+
exports.assetBalance = assetBalance;
|
|
164
|
+
exports.expectAdjustResumePreview = expectAdjustResumePreview;
|
|
165
|
+
exports.expectCallsArrayExact = expectCallsArrayExact;
|
|
166
|
+
exports.expectOpsArrayExact = expectOpsArrayExact;
|
|
167
|
+
exports.withOnchainOpCalls = withOnchainOpCalls;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_utils_formatter = require("../../../utils/formatter.js");
|
|
3
|
+
require("../../../index.js");
|
|
4
|
+
const require_sdk_accounts_intents_testing_sdk_mock = require("./sdk-mock.js");
|
|
5
|
+
//#region src/sdk/accounts/intents/testing/resume.ts
|
|
6
|
+
/**
|
|
7
|
+
* Shared kit for claim-only resume fixtures (add collateral, increase
|
|
8
|
+
* leverage, deposit, deposit+increase).
|
|
9
|
+
*
|
|
10
|
+
* Unlike the legacy props (which echoed `creditAccount.totalValue`), the
|
|
11
|
+
* service computes totalValue from CA token balances via the price oracle.
|
|
12
|
+
* Each case's base balance is therefore `postClaimTotalValue − claimed value
|
|
13
|
+
* in UND`, so the derived totalValue matches the legacy expectation exactly.
|
|
14
|
+
*/
|
|
15
|
+
const UND_DECIMALS = 8;
|
|
16
|
+
const TOK_DECIMALS = 18;
|
|
17
|
+
const UND = "0x3333333333333333333333333333333333333333";
|
|
18
|
+
const ANY = "0x1111111111111111111111111111111111111111";
|
|
19
|
+
const ANY2 = "0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
|
|
20
|
+
const RWA_ASSET = "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
|
21
|
+
const RESUME_FIXTURE_PHANTOM = "0xcccccccccccccccccccccccccccccccccccccccc";
|
|
22
|
+
const CREDIT_MANAGER = "0xdddddddddddddddddddddddddddddddddddddddd";
|
|
23
|
+
const CREDIT_FACADE = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
24
|
+
const CREDIT_ACCOUNT = "0xacacacacacacacacacacacacacacacacacacacac";
|
|
25
|
+
const PRICES = {
|
|
26
|
+
[UND]: require_sdk_utils_formatter.toBN("2", 8),
|
|
27
|
+
[ANY]: require_sdk_utils_formatter.toBN("1", 8),
|
|
28
|
+
[ANY2]: require_sdk_utils_formatter.toBN("1", 8),
|
|
29
|
+
[RWA_ASSET]: require_sdk_utils_formatter.toBN("2", 8)
|
|
30
|
+
};
|
|
31
|
+
const DECIMALS = {
|
|
32
|
+
[UND]: 8,
|
|
33
|
+
[ANY]: 18,
|
|
34
|
+
[ANY2]: 18,
|
|
35
|
+
[RWA_ASSET]: 8
|
|
36
|
+
};
|
|
37
|
+
const QUOTAS = {
|
|
38
|
+
[ANY]: {
|
|
39
|
+
token: ANY,
|
|
40
|
+
rate: 500n,
|
|
41
|
+
limit: require_sdk_utils_formatter.toBN("999999999999999", 18),
|
|
42
|
+
isActive: true
|
|
43
|
+
},
|
|
44
|
+
[ANY2]: {
|
|
45
|
+
token: ANY2,
|
|
46
|
+
rate: 500n,
|
|
47
|
+
limit: require_sdk_utils_formatter.toBN("999999999999999", 18),
|
|
48
|
+
isActive: true
|
|
49
|
+
},
|
|
50
|
+
[RWA_ASSET]: {
|
|
51
|
+
token: RWA_ASSET,
|
|
52
|
+
rate: 500n,
|
|
53
|
+
limit: require_sdk_utils_formatter.toBN("999999999999999", 8),
|
|
54
|
+
isActive: true
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const LIQUIDATION_THRESHOLDS = {
|
|
58
|
+
[UND]: 9800,
|
|
59
|
+
[ANY]: 9200,
|
|
60
|
+
[ANY2]: 9200,
|
|
61
|
+
[RWA_ASSET]: 9200
|
|
62
|
+
};
|
|
63
|
+
const MAX_DEBT = require_sdk_utils_formatter.toBN("200000", 8);
|
|
64
|
+
/** Claimed proceeds converted to UND (mirrors the mock price oracle). */
|
|
65
|
+
function claimedValueInUnd(amount, token) {
|
|
66
|
+
return amount * PRICES[token] * 10n ** BigInt(8) / (PRICES[UND] * 10n ** BigInt(DECIMALS[token]));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Mock sdk for a resume case. The fixture phantom token gets the claimed
|
|
70
|
+
* token's decimals so the offchain `toTargetDecimals` rescale stays identity
|
|
71
|
+
* (its `10n * decimals` factor is only correct for equal decimals).
|
|
72
|
+
* `closePath` configures the router `findBestClosePath` result (close resume).
|
|
73
|
+
*/
|
|
74
|
+
function buildResumeSdk(c, extras) {
|
|
75
|
+
const phantom = extras?.phantom ?? "0xcccccccccccccccccccccccccccccccccccccccc";
|
|
76
|
+
return require_sdk_accounts_intents_testing_sdk_mock.buildMockSdk({
|
|
77
|
+
prices: {
|
|
78
|
+
...PRICES,
|
|
79
|
+
...extras?.extraPrices
|
|
80
|
+
},
|
|
81
|
+
decimals: {
|
|
82
|
+
...DECIMALS,
|
|
83
|
+
...extras?.extraDecimals,
|
|
84
|
+
[phantom]: extras?.extraDecimals?.[c.claimedToken] ?? DECIMALS[c.claimedToken]
|
|
85
|
+
},
|
|
86
|
+
quotas: QUOTAS,
|
|
87
|
+
liquidationThresholds: LIQUIDATION_THRESHOLDS,
|
|
88
|
+
maxDebt: MAX_DEBT,
|
|
89
|
+
creditManager: CREDIT_MANAGER,
|
|
90
|
+
creditFacade: CREDIT_FACADE,
|
|
91
|
+
underlying: UND,
|
|
92
|
+
closePath: extras?.closePath,
|
|
93
|
+
rwaAssets: extras?.rwaAssets
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function buildOffchainOptions(c) {
|
|
97
|
+
return {
|
|
98
|
+
kind: "offchain",
|
|
99
|
+
phantomSpent: c.claimedAmount,
|
|
100
|
+
withdrawalConfig: {
|
|
101
|
+
creditManager: CREDIT_MANAGER,
|
|
102
|
+
token: c.claimedToken,
|
|
103
|
+
withdrawalPhantomToken: RESUME_FIXTURE_PHANTOM,
|
|
104
|
+
underlying: c.claimedToken,
|
|
105
|
+
withdrawalLength: 0n
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function buildOnchainOptions(c) {
|
|
110
|
+
return {
|
|
111
|
+
kind: "onchain",
|
|
112
|
+
claimableWithdrawal: {
|
|
113
|
+
token: c.claimedToken,
|
|
114
|
+
withdrawalPhantomToken: RESUME_FIXTURE_PHANTOM,
|
|
115
|
+
withdrawalTokenSpent: c.claimedAmount,
|
|
116
|
+
outputs: [{
|
|
117
|
+
token: c.claimedToken,
|
|
118
|
+
amount: c.claimedAmount,
|
|
119
|
+
isDelayed: false
|
|
120
|
+
}],
|
|
121
|
+
claimCalls: [require_sdk_accounts_intents_testing_sdk_mock.MOCK_CLAIM_CALL]
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function buildClaimResumeProps(args) {
|
|
126
|
+
const { intent, case: c, sdk, options } = args;
|
|
127
|
+
return {
|
|
128
|
+
intent,
|
|
129
|
+
creditAccount: {
|
|
130
|
+
creditAccount: CREDIT_ACCOUNT,
|
|
131
|
+
creditManager: CREDIT_MANAGER,
|
|
132
|
+
creditFacade: CREDIT_FACADE,
|
|
133
|
+
underlying: UND,
|
|
134
|
+
enabledTokensMask: 0n,
|
|
135
|
+
totalDebtUSD: 0n,
|
|
136
|
+
accountDebt: c.postClaimDebt,
|
|
137
|
+
tokens: [{
|
|
138
|
+
token: RESUME_FIXTURE_PHANTOM,
|
|
139
|
+
balance: c.claimedAmount,
|
|
140
|
+
quota: 0n,
|
|
141
|
+
mask: 0n,
|
|
142
|
+
success: true
|
|
143
|
+
}, ...c.baseAssets ?? [{
|
|
144
|
+
token: "0x3333333333333333333333333333333333333333",
|
|
145
|
+
balance: c.postClaimTotalValue - claimedValueInUnd(c.claimedAmount, c.claimedToken),
|
|
146
|
+
quota: 0n,
|
|
147
|
+
mask: 0n,
|
|
148
|
+
success: true
|
|
149
|
+
}]]
|
|
150
|
+
},
|
|
151
|
+
sdk,
|
|
152
|
+
quotaReserve: void 0,
|
|
153
|
+
options,
|
|
154
|
+
slippage: void 0
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
//#endregion
|
|
158
|
+
exports.ANY = ANY;
|
|
159
|
+
exports.ANY2 = ANY2;
|
|
160
|
+
exports.CREDIT_ACCOUNT = CREDIT_ACCOUNT;
|
|
161
|
+
exports.CREDIT_FACADE = CREDIT_FACADE;
|
|
162
|
+
exports.CREDIT_MANAGER = CREDIT_MANAGER;
|
|
163
|
+
exports.RESUME_FIXTURE_PHANTOM = RESUME_FIXTURE_PHANTOM;
|
|
164
|
+
exports.RWA_ASSET = RWA_ASSET;
|
|
165
|
+
exports.TOK_DECIMALS = TOK_DECIMALS;
|
|
166
|
+
exports.UND = UND;
|
|
167
|
+
exports.UND_DECIMALS = UND_DECIMALS;
|
|
168
|
+
exports.buildClaimResumeProps = buildClaimResumeProps;
|
|
169
|
+
exports.buildOffchainOptions = buildOffchainOptions;
|
|
170
|
+
exports.buildOnchainOptions = buildOnchainOptions;
|
|
171
|
+
exports.buildResumeSdk = buildResumeSdk;
|
|
172
|
+
exports.claimedValueInUnd = claimedValueInUnd;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let vitest = require("vitest");
|
|
3
|
+
//#region src/sdk/accounts/intents/testing/sdk-mock.ts
|
|
4
|
+
/**
|
|
5
|
+
* Test kit for intent-service specs.
|
|
6
|
+
*
|
|
7
|
+
* The service resolves all market data through `OnchainSDK`
|
|
8
|
+
* (`marketRegister`, `tokensMeta`, `accounts`). `buildMockSdk` builds a mock
|
|
9
|
+
* from plain records; assemble mocks ECHO recognizable sentinel calls derived
|
|
10
|
+
* from their inputs, so `result.instant.calls` pins down which ops reached the
|
|
11
|
+
* assembler and in which order.
|
|
12
|
+
*/
|
|
13
|
+
/** Fixture `claimableWithdrawal.claimCalls` content; echoes through claim ops. */
|
|
14
|
+
const MOCK_CLAIM_CALL = {
|
|
15
|
+
target: "0x1111111111111111111111111111111111111111",
|
|
16
|
+
callData: "0x"
|
|
17
|
+
};
|
|
18
|
+
/** Recognizable router call embedded in close path results. */
|
|
19
|
+
const MOCK_ROUTER_CALL = {
|
|
20
|
+
target: "0x9999999999999999999999999999999999999999",
|
|
21
|
+
callData: "0x"
|
|
22
|
+
};
|
|
23
|
+
/** Returned by the `getRWAWrapCalls` mock; passes through per wrap op. */
|
|
24
|
+
const MOCK_RWA_WRAP_CALL = {
|
|
25
|
+
target: "0x8888888888888888888888888888888888888888",
|
|
26
|
+
callData: "0x"
|
|
27
|
+
};
|
|
28
|
+
/** Router-produced call for an RWA underlying → asset unwrap leg. */
|
|
29
|
+
const MOCK_RWA_UNWRAP_CALL = {
|
|
30
|
+
target: "0x7777777777777777777777777777777777777777",
|
|
31
|
+
callData: "0x"
|
|
32
|
+
};
|
|
33
|
+
/** Returned by the `assembleCloseCreditAccountCalls` mock. */
|
|
34
|
+
const MOCK_CLOSE_CALL = {
|
|
35
|
+
target: "0x5555555555555555555555555555555555555555",
|
|
36
|
+
callData: "0x"
|
|
37
|
+
};
|
|
38
|
+
/** One sentinel call per plain encodable op type. */
|
|
39
|
+
const CA_OP_CALLS = {
|
|
40
|
+
addCollateral: {
|
|
41
|
+
target: "0xa1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1",
|
|
42
|
+
callData: "0x"
|
|
43
|
+
},
|
|
44
|
+
increaseDebt: {
|
|
45
|
+
target: "0xd1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1",
|
|
46
|
+
callData: "0x"
|
|
47
|
+
},
|
|
48
|
+
decreaseDebt: {
|
|
49
|
+
target: "0xd2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2",
|
|
50
|
+
callData: "0x"
|
|
51
|
+
},
|
|
52
|
+
withdrawCollateral: {
|
|
53
|
+
target: "0xc1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1",
|
|
54
|
+
callData: "0x"
|
|
55
|
+
},
|
|
56
|
+
changeQuota: {
|
|
57
|
+
target: "0xc2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2",
|
|
58
|
+
callData: "0x"
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
function echoEncodableOpCalls(op) {
|
|
62
|
+
if ("calls" in op) return [...op.calls];
|
|
63
|
+
return [CA_OP_CALLS[op.type]];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Mock `OnchainSDK` covering exactly what the intent-service touches:
|
|
67
|
+
* price conversion, quota params, CM/facade lookup and call assembly.
|
|
68
|
+
* Conversion mirrors the legacy price-based math:
|
|
69
|
+
* `amount * price[from] * 10^dec(to) / (price[to] * 10^dec(from))`.
|
|
70
|
+
*/
|
|
71
|
+
function buildMockSdk(args) {
|
|
72
|
+
const decimalsOf = (token) => args.decimals[token.toLowerCase()] ?? 18;
|
|
73
|
+
const convert = (token, to, amount) => {
|
|
74
|
+
const from = token.toLowerCase();
|
|
75
|
+
const target = to.toLowerCase();
|
|
76
|
+
const fromPrice = args.prices[from];
|
|
77
|
+
const toPrice = args.prices[target];
|
|
78
|
+
if (fromPrice === void 0 || toPrice === void 0) throw new Error(`mock priceOracle: missing price for ${from} or ${target}`);
|
|
79
|
+
return amount * fromPrice * 10n ** BigInt(decimalsOf(target)) / (toPrice * 10n ** BigInt(decimalsOf(from)));
|
|
80
|
+
};
|
|
81
|
+
const quotas = { values: () => Object.values(args.quotas).map((q) => ({
|
|
82
|
+
cumulativeIndexLU: 0n,
|
|
83
|
+
totalQuoted: 0n,
|
|
84
|
+
quotaIncreaseFee: 0n,
|
|
85
|
+
...q
|
|
86
|
+
})) };
|
|
87
|
+
const liquidationThresholds = { entries: () => Object.entries(args.liquidationThresholds) };
|
|
88
|
+
const market = {
|
|
89
|
+
priceOracle: { convert },
|
|
90
|
+
pool: {
|
|
91
|
+
pqk: { quotas },
|
|
92
|
+
underlying: args.underlying
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const creditManagerSuite = {
|
|
96
|
+
creditManager: {
|
|
97
|
+
address: args.creditManager,
|
|
98
|
+
liquidationThresholds,
|
|
99
|
+
collateralTokens: []
|
|
100
|
+
},
|
|
101
|
+
creditFacade: {
|
|
102
|
+
address: args.creditFacade,
|
|
103
|
+
maxDebt: args.maxDebt
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const routeCalls = (tokenIn, tokenOut) => {
|
|
107
|
+
const underlying = args.underlying.toLowerCase();
|
|
108
|
+
const asset = args.rwaAssets?.[args.underlying.toLowerCase()]?.toLowerCase();
|
|
109
|
+
const from = tokenIn.toLowerCase();
|
|
110
|
+
const to = tokenOut.toLowerCase();
|
|
111
|
+
if (asset && from === asset && to === underlying) return [MOCK_RWA_WRAP_CALL];
|
|
112
|
+
if (asset && from === underlying && to === asset) return [MOCK_RWA_UNWRAP_CALL];
|
|
113
|
+
return [MOCK_ROUTER_CALL];
|
|
114
|
+
};
|
|
115
|
+
const router = {
|
|
116
|
+
findBestClosePath: vitest.vi.fn(async () => {
|
|
117
|
+
if (!args.closePath) throw new Error("mock router: closePath not configured");
|
|
118
|
+
return args.closePath;
|
|
119
|
+
}),
|
|
120
|
+
findOneTokenPath: vitest.vi.fn(async ({ amount, tokenIn, tokenOut }) => ({
|
|
121
|
+
amount,
|
|
122
|
+
minAmount: amount,
|
|
123
|
+
calls: routeCalls(tokenIn, tokenOut)
|
|
124
|
+
})),
|
|
125
|
+
findManyToOnePath: vitest.vi.fn(async ({ expectedBalances, leftoverBalances, target }) => {
|
|
126
|
+
const spent = expectedBalances.reduce((acc, a) => acc + a.balance, 0n) - leftoverBalances.reduce((acc, a) => acc + a.balance, 0n);
|
|
127
|
+
const tokenIn = expectedBalances[0]?.token ?? target;
|
|
128
|
+
return {
|
|
129
|
+
amount: spent,
|
|
130
|
+
minAmount: spent,
|
|
131
|
+
calls: routeCalls(tokenIn, target)
|
|
132
|
+
};
|
|
133
|
+
}),
|
|
134
|
+
findOpenStrategyPath: vitest.vi.fn(async ({ expectedBalances, leftoverBalances }) => {
|
|
135
|
+
const spent = expectedBalances.reduce((acc, a) => acc + a.balance, 0n) - leftoverBalances.reduce((acc, a) => acc + a.balance, 0n);
|
|
136
|
+
return {
|
|
137
|
+
amount: spent,
|
|
138
|
+
minAmount: spent,
|
|
139
|
+
calls: [MOCK_ROUTER_CALL],
|
|
140
|
+
minAssets: [],
|
|
141
|
+
averageAssets: []
|
|
142
|
+
};
|
|
143
|
+
})
|
|
144
|
+
};
|
|
145
|
+
return {
|
|
146
|
+
tokensMeta: {
|
|
147
|
+
get: (token) => ({ decimals: decimalsOf(token) }),
|
|
148
|
+
rwaUnderlyings: { get: (token) => {
|
|
149
|
+
const asset = args.rwaAssets?.[token.toLowerCase()];
|
|
150
|
+
return asset ? { asset } : void 0;
|
|
151
|
+
} }
|
|
152
|
+
},
|
|
153
|
+
marketRegister: {
|
|
154
|
+
findByCreditManager: vitest.vi.fn(() => market),
|
|
155
|
+
findCreditManager: vitest.vi.fn(() => creditManagerSuite)
|
|
156
|
+
},
|
|
157
|
+
routerFor: vitest.vi.fn(() => router),
|
|
158
|
+
accounts: {
|
|
159
|
+
assembleCaOperations: vitest.vi.fn(({ operations }) => operations.flatMap(echoEncodableOpCalls)),
|
|
160
|
+
prepareIncreaseDebt: vitest.vi.fn(() => CA_OP_CALLS.increaseDebt),
|
|
161
|
+
prepareChangeDebt: vitest.vi.fn(() => CA_OP_CALLS.decreaseDebt),
|
|
162
|
+
prepareAddCollateral: vitest.vi.fn(() => [CA_OP_CALLS.addCollateral]),
|
|
163
|
+
prepareWithdrawToken: vitest.vi.fn(() => CA_OP_CALLS.withdrawCollateral),
|
|
164
|
+
prepareUpdateQuotas: vitest.vi.fn(() => [CA_OP_CALLS.changeQuota]),
|
|
165
|
+
assembleClaimDelayedCalls: vitest.vi.fn(({ claimableNow }) => [...claimableNow.claimCalls]),
|
|
166
|
+
assembleCloseCreditAccountCalls: vitest.vi.fn(async () => [MOCK_CLOSE_CALL]),
|
|
167
|
+
getRWAWrapCalls: vitest.vi.fn(async () => [MOCK_RWA_WRAP_CALL]),
|
|
168
|
+
getRWAUnwrapCalls: vitest.vi.fn(async () => [MOCK_RWA_UNWRAP_CALL])
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
exports.CA_OP_CALLS = CA_OP_CALLS;
|
|
174
|
+
exports.MOCK_CLAIM_CALL = MOCK_CLAIM_CALL;
|
|
175
|
+
exports.MOCK_CLOSE_CALL = MOCK_CLOSE_CALL;
|
|
176
|
+
exports.MOCK_ROUTER_CALL = MOCK_ROUTER_CALL;
|
|
177
|
+
exports.MOCK_RWA_UNWRAP_CALL = MOCK_RWA_UNWRAP_CALL;
|
|
178
|
+
exports.MOCK_RWA_WRAP_CALL = MOCK_RWA_WRAP_CALL;
|
|
179
|
+
exports.buildMockSdk = buildMockSdk;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/sdk/accounts/intents/utils/assemble-operation-calls.ts
|
|
3
|
+
function assembleOperationCalls({ operations }) {
|
|
4
|
+
return operations.flatMap((operation) => operation.calls);
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
exports.assembleOperationCalls = assembleOperationCalls;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/sdk/accounts/intents/utils/borrowed-amount-plus-interest-and-fees.ts
|
|
3
|
+
/**
|
|
4
|
+
* Total debt of a credit account: principal + accrued interest + accrued fees.
|
|
5
|
+
*
|
|
6
|
+
* On the v3 SDK `CreditAccountData` the parts
|
|
7
|
+
* come as separate `debt` / `accruedInterest` / `accruedFees` fields.
|
|
8
|
+
*/
|
|
9
|
+
function calcBorrowedAmountPlusInterestAndFees(ca) {
|
|
10
|
+
return ca.debt + ca.accruedInterest + ca.accruedFees;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
exports.calcBorrowedAmountPlusInterestAndFees = calcBorrowedAmountPlusInterestAndFees;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_utils_AddressMap = require("../../../utils/AddressMap.js");
|
|
3
|
+
//#region src/sdk/accounts/intents/utils/common.ts
|
|
4
|
+
/** Case-insensitive address equality. */
|
|
5
|
+
const eq = (a, b) => a.toLowerCase() === b.toLowerCase();
|
|
6
|
+
function toTargetDecimals(fromAmount, fromToken, toToken, sdk) {
|
|
7
|
+
const fromDecimals = sdk.tokensMeta.get(fromToken)?.decimals ?? 18;
|
|
8
|
+
const toDecimals = sdk.tokensMeta.get(toToken)?.decimals ?? 18;
|
|
9
|
+
return fromAmount * 10n ** BigInt(toDecimals) / 10n ** BigInt(fromDecimals);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Router CA slice from the account slice. RouterV310 reads `ca.tokens` for
|
|
13
|
+
* underlyingBalance, so balances are overlaid with the post-claim projection
|
|
14
|
+
* (legacy `overlayExpectedBalancesOntoCaTokens`): existing tokens keep quota
|
|
15
|
+
* with balance from the projection (0n when absent), new tokens get quota 0n.
|
|
16
|
+
*/
|
|
17
|
+
function toRouterCaSlice(creditAccount, expectedBalances = []) {
|
|
18
|
+
const { accountDebt, underlying, creditFacade, creditManager, creditAccount: creditAccountAddress, tokens: _, ...restCA } = creditAccount;
|
|
19
|
+
const expected = new require_sdk_utils_AddressMap.AddressMap([]);
|
|
20
|
+
for (const asset of expectedBalances ?? []) expected.upsert(asset.token, (expected.get(asset.token) ?? 0n) + asset.balance);
|
|
21
|
+
const tokens = creditAccount.tokens.map((t) => {
|
|
22
|
+
const token = t.token.toLowerCase();
|
|
23
|
+
const balance = expected.get(token) ?? t.balance;
|
|
24
|
+
return {
|
|
25
|
+
...t,
|
|
26
|
+
token,
|
|
27
|
+
balance
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
...restCA,
|
|
32
|
+
underlying: underlying.toLowerCase(),
|
|
33
|
+
creditAccount: creditAccountAddress.toLowerCase(),
|
|
34
|
+
creditFacade: creditFacade.toLowerCase(),
|
|
35
|
+
creditManager: creditManager.toLowerCase(),
|
|
36
|
+
debt: creditAccount.accountDebt,
|
|
37
|
+
tokens
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
exports.eq = eq;
|
|
42
|
+
exports.toRouterCaSlice = toRouterCaSlice;
|
|
43
|
+
exports.toTargetDecimals = toTargetDecimals;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_accounts_intents_utils_common = require("./common.js");
|
|
3
|
+
//#region src/sdk/accounts/intents/utils/convert-amount.ts
|
|
4
|
+
/**
|
|
5
|
+
* Converts an amount from one token to another using oracle prices of the
|
|
6
|
+
* given credit manager's market. When the direct oracle path is missing
|
|
7
|
+
* (e.g. `rwa.asset` has no pool price), bridges via the wrapped underlying
|
|
8
|
+
* (1:1 wrap + decimals rescale) — mirrors legacy `convertAmountWithRwaBridge`.
|
|
9
|
+
*/
|
|
10
|
+
const convertAmount = (sdk, creditManager) => (fromTokenRaw, toTokenRaw, amount) => {
|
|
11
|
+
const fromToken = fromTokenRaw.toLowerCase();
|
|
12
|
+
const toToken = toTokenRaw.toLowerCase();
|
|
13
|
+
if (amount === 0n || fromToken === toToken) return amount;
|
|
14
|
+
const market = sdk.marketRegister.findByCreditManager(creditManager);
|
|
15
|
+
const underlying = market.pool.underlying.toLowerCase();
|
|
16
|
+
let direct = 0n;
|
|
17
|
+
try {
|
|
18
|
+
direct = market.priceOracle.convert(fromToken, toToken, amount);
|
|
19
|
+
} catch {}
|
|
20
|
+
if (direct > 0n) return direct;
|
|
21
|
+
const rwa = sdk.tokensMeta.rwaUnderlyings.get(underlying);
|
|
22
|
+
if (!rwa) return 0n;
|
|
23
|
+
const asset = rwa.asset.toLowerCase();
|
|
24
|
+
if (fromToken === asset && toToken === underlying) return require_sdk_accounts_intents_utils_common.toTargetDecimals(amount, fromToken, toToken, sdk);
|
|
25
|
+
if (fromToken === underlying && toToken === asset) return require_sdk_accounts_intents_utils_common.toTargetDecimals(amount, fromToken, toToken, sdk);
|
|
26
|
+
if (fromToken === asset) {
|
|
27
|
+
const asUnd = require_sdk_accounts_intents_utils_common.toTargetDecimals(amount, fromToken, underlying, sdk);
|
|
28
|
+
return convertAmount(sdk, creditManager)(underlying, toTokenRaw, asUnd);
|
|
29
|
+
}
|
|
30
|
+
if (toToken === asset) {
|
|
31
|
+
const asUnd = convertAmount(sdk, creditManager)(fromToken, underlying, amount);
|
|
32
|
+
return asUnd === 0n ? 0n : require_sdk_accounts_intents_utils_common.toTargetDecimals(asUnd, underlying, toToken, sdk);
|
|
33
|
+
}
|
|
34
|
+
return 0n;
|
|
35
|
+
};
|
|
36
|
+
//#endregion
|
|
37
|
+
exports.convertAmount = convertAmount;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_accounts_intents_utils_assemble_operation_calls = require("./assemble-operation-calls.js");
|
|
3
|
+
const require_sdk_accounts_intents_utils_borrowed_amount_plus_interest_and_fees = require("./borrowed-amount-plus-interest-and-fees.js");
|
|
4
|
+
const require_sdk_accounts_intents_utils_common = require("./common.js");
|
|
5
|
+
const require_sdk_accounts_intents_utils_convert_amount = require("./convert-amount.js");
|
|
6
|
+
const require_sdk_accounts_intents_utils_quotas_for_update = require("./quotas-for-update.js");
|
|
7
|
+
const require_sdk_accounts_intents_utils_simulate_assets = require("./simulate-assets.js");
|
|
8
|
+
const require_sdk_accounts_intents_utils_simulate_adjust_state = require("./simulate-adjust-state.js");
|
|
9
|
+
const require_sdk_accounts_intents_utils_with_quota_update = require("./with-quota-update.js");
|
|
10
|
+
exports.assembleOperationCalls = require_sdk_accounts_intents_utils_assemble_operation_calls.assembleOperationCalls;
|
|
11
|
+
exports.calcBorrowedAmountPlusInterestAndFees = require_sdk_accounts_intents_utils_borrowed_amount_plus_interest_and_fees.calcBorrowedAmountPlusInterestAndFees;
|
|
12
|
+
exports.convertAmount = require_sdk_accounts_intents_utils_convert_amount.convertAmount;
|
|
13
|
+
exports.eq = require_sdk_accounts_intents_utils_common.eq;
|
|
14
|
+
exports.getOperationsWithQuotaUpdate = require_sdk_accounts_intents_utils_with_quota_update.getOperationsWithQuotaUpdate;
|
|
15
|
+
exports.getQuotasForUpdate = require_sdk_accounts_intents_utils_quotas_for_update.getQuotasForUpdate;
|
|
16
|
+
exports.simulateOperationAssets = require_sdk_accounts_intents_utils_simulate_assets.simulateOperationAssets;
|
|
17
|
+
exports.simulateState = require_sdk_accounts_intents_utils_simulate_adjust_state.simulateState;
|
|
18
|
+
exports.toRouterCaSlice = require_sdk_accounts_intents_utils_common.toRouterCaSlice;
|
|
19
|
+
exports.toTargetDecimals = require_sdk_accounts_intents_utils_common.toTargetDecimals;
|