@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,387 @@
|
|
|
1
|
+
import { SDKConstruct } from "../../base/SDKConstruct.js";
|
|
2
|
+
import { assembleOperationCalls } from "./utils/assemble-operation-calls.js";
|
|
3
|
+
import { simulateState } from "./utils/simulate-adjust-state.js";
|
|
4
|
+
import { getOperationsWithQuotaUpdate } from "./utils/with-quota-update.js";
|
|
5
|
+
import "./utils/index.js";
|
|
6
|
+
import { buildResumeAddCollateralOperations } from "./intents/resume/add-collateral/add-collateral.js";
|
|
7
|
+
import { buildResumeCloseOperations } from "./intents/resume/close/close.js";
|
|
8
|
+
import { buildResumeDecreaseLeverageOperations } from "./intents/resume/decrease-leverage/decrease-leverage.js";
|
|
9
|
+
import { buildResumeDepositOperations } from "./intents/resume/deposit/deposit.js";
|
|
10
|
+
import { buildResumeIncreaseLeverageOperations } from "./intents/resume/increase-leverage/increase-leverage.js";
|
|
11
|
+
import { buildResumeWithdrawOperations } from "./intents/resume/withdraw/withdraw.js";
|
|
12
|
+
import "./intents/resume/index.js";
|
|
13
|
+
import { createCloseOracleQuoter, createRouterCloseQuoter } from "./quoters/close.js";
|
|
14
|
+
import { createOracleSwapQuoter, createRouterSwapQuoter } from "./quoters/swap.js";
|
|
15
|
+
import "./quoters/index.js";
|
|
16
|
+
//#region src/sdk/accounts/intents/index.ts
|
|
17
|
+
var CreditAccountOperationsService = class extends SDKConstruct {
|
|
18
|
+
async finishIntent(props) {
|
|
19
|
+
const intent = props.intent;
|
|
20
|
+
switch (intent.type) {
|
|
21
|
+
case "ADD_COLLATERAL": return this.#finishAddCollateralIntent({
|
|
22
|
+
...props,
|
|
23
|
+
intent
|
|
24
|
+
});
|
|
25
|
+
case "INCREASE_LEVERAGE": return this.#finishIncreaseLeverageIntent({
|
|
26
|
+
...props,
|
|
27
|
+
intent
|
|
28
|
+
});
|
|
29
|
+
case "DEPOSIT": return this.#finishDepositIntent({
|
|
30
|
+
...props,
|
|
31
|
+
intent
|
|
32
|
+
});
|
|
33
|
+
case "DEPOSIT_AND_INCREASE_LEVERAGE": return this.#finishDepositAndIncreaseLeverageIntent({
|
|
34
|
+
...props,
|
|
35
|
+
intent
|
|
36
|
+
});
|
|
37
|
+
case "CLOSE_ACCOUNT": return this.#finishCloseAccountIntent({
|
|
38
|
+
...props,
|
|
39
|
+
intent
|
|
40
|
+
});
|
|
41
|
+
case "WITHDRAW_COLLATERAL": return this.#finishWithdrawCollateralIntent({
|
|
42
|
+
...props,
|
|
43
|
+
intent
|
|
44
|
+
});
|
|
45
|
+
case "DECREASE_LEVERAGE": return this.#finishDecreaseLeverageIntent({
|
|
46
|
+
...props,
|
|
47
|
+
intent
|
|
48
|
+
});
|
|
49
|
+
default: throw new Error(`${props.intent.type} - not implemented`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Shared resume flow for claim-only intents (add collateral, increase
|
|
54
|
+
* leverage, deposit, deposit+increase): claim op + trailing changeQuota.
|
|
55
|
+
* If any implementations change, respective handler should be implemented separately
|
|
56
|
+
*/
|
|
57
|
+
#finishClaimOnlyIntent = (buildOperations) => async (props) => {
|
|
58
|
+
switch (props.options.kind) {
|
|
59
|
+
case "offchain": return this.#finishClaimOnlyIntentOffchain(props, props.options, buildOperations);
|
|
60
|
+
default: return this.#finishClaimOnlyIntentOnchain(props, props.options, buildOperations);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
#finishClaimOnlyIntentOffchain(props, options, buildOperations) {
|
|
64
|
+
const baseOperations = buildOperations(props.creditAccount, options, this.sdk);
|
|
65
|
+
const state = simulateState({
|
|
66
|
+
...props,
|
|
67
|
+
operations: baseOperations
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
ok: true,
|
|
71
|
+
instant: {
|
|
72
|
+
operations: getOperationsWithQuotaUpdate({
|
|
73
|
+
operations: baseOperations,
|
|
74
|
+
state,
|
|
75
|
+
creditAccount: props.creditAccount,
|
|
76
|
+
sdk: this.sdk,
|
|
77
|
+
options
|
|
78
|
+
}),
|
|
79
|
+
preview: { min: state.state },
|
|
80
|
+
calls: []
|
|
81
|
+
},
|
|
82
|
+
instantError: void 0,
|
|
83
|
+
delayedBranch: void 0,
|
|
84
|
+
delayedError: void 0
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
async #finishClaimOnlyIntentOnchain(props, options, buildOperations) {
|
|
88
|
+
const baseOperations = buildOperations(props.creditAccount, options, this.sdk);
|
|
89
|
+
const state = simulateState({
|
|
90
|
+
...props,
|
|
91
|
+
operations: baseOperations
|
|
92
|
+
});
|
|
93
|
+
const operations = getOperationsWithQuotaUpdate({
|
|
94
|
+
operations: baseOperations,
|
|
95
|
+
state,
|
|
96
|
+
creditAccount: props.creditAccount,
|
|
97
|
+
sdk: this.sdk,
|
|
98
|
+
options
|
|
99
|
+
});
|
|
100
|
+
const calls = await assembleOperationCalls({
|
|
101
|
+
...props,
|
|
102
|
+
operations
|
|
103
|
+
});
|
|
104
|
+
return {
|
|
105
|
+
ok: true,
|
|
106
|
+
instant: {
|
|
107
|
+
operations,
|
|
108
|
+
preview: { min: state.state },
|
|
109
|
+
calls
|
|
110
|
+
},
|
|
111
|
+
instantError: void 0,
|
|
112
|
+
delayedBranch: void 0,
|
|
113
|
+
delayedError: void 0
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
#finishAddCollateralIntent = this.#finishClaimOnlyIntent(buildResumeAddCollateralOperations);
|
|
117
|
+
#finishIncreaseLeverageIntent = this.#finishClaimOnlyIntent(buildResumeIncreaseLeverageOperations);
|
|
118
|
+
#finishDepositIntent = this.#finishClaimOnlyIntent(buildResumeDepositOperations);
|
|
119
|
+
#finishDepositAndIncreaseLeverageIntent = this.#finishClaimOnlyIntent(buildResumeDepositOperations);
|
|
120
|
+
/**
|
|
121
|
+
* Resume close: claim, then close against quoted post-claim balances.
|
|
122
|
+
* Offchain quotes equity by oracle prices, onchain — router close path.
|
|
123
|
+
* Router miss soft-fails to the oracle quote with `calls: []` (legacy parity).
|
|
124
|
+
*/
|
|
125
|
+
async #finishCloseAccountIntent({ options, ...props }) {
|
|
126
|
+
switch (options.kind) {
|
|
127
|
+
case "offchain": return this.#finishCloseAccountIntentOffchain({
|
|
128
|
+
...props,
|
|
129
|
+
options
|
|
130
|
+
});
|
|
131
|
+
default: try {
|
|
132
|
+
return await this.#finishCloseAccountIntentOnchain({
|
|
133
|
+
...props,
|
|
134
|
+
options
|
|
135
|
+
});
|
|
136
|
+
} catch {
|
|
137
|
+
return this.#finishCloseAccountIntentOffchain({
|
|
138
|
+
...props,
|
|
139
|
+
options
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
async #finishCloseAccountIntentOffchain({ options, ...props }) {
|
|
145
|
+
const quoter = createCloseOracleQuoter({
|
|
146
|
+
sdk: this.sdk,
|
|
147
|
+
creditAccount: props.creditAccount
|
|
148
|
+
});
|
|
149
|
+
const { operations, quote } = await buildResumeCloseOperations({
|
|
150
|
+
...props,
|
|
151
|
+
options
|
|
152
|
+
}, quoter);
|
|
153
|
+
return {
|
|
154
|
+
ok: true,
|
|
155
|
+
instant: {
|
|
156
|
+
operations,
|
|
157
|
+
preview: { min: {
|
|
158
|
+
kind: "close",
|
|
159
|
+
amount: quote.amount,
|
|
160
|
+
minAmount: quote.minAmount,
|
|
161
|
+
underlyingBalance: quote.underlyingBalance
|
|
162
|
+
} },
|
|
163
|
+
calls: []
|
|
164
|
+
},
|
|
165
|
+
instantError: void 0,
|
|
166
|
+
delayedBranch: void 0,
|
|
167
|
+
delayedError: void 0
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
async #finishCloseAccountIntentOnchain({ options, slippage = 0, ...props }) {
|
|
171
|
+
const quoter = createRouterCloseQuoter({
|
|
172
|
+
sdk: this.sdk,
|
|
173
|
+
creditAccount: props.creditAccount,
|
|
174
|
+
slippage
|
|
175
|
+
});
|
|
176
|
+
const { operations, quote } = await buildResumeCloseOperations({
|
|
177
|
+
...props,
|
|
178
|
+
options
|
|
179
|
+
}, quoter);
|
|
180
|
+
const calls = await assembleOperationCalls({
|
|
181
|
+
...props,
|
|
182
|
+
operations
|
|
183
|
+
});
|
|
184
|
+
return {
|
|
185
|
+
ok: true,
|
|
186
|
+
instant: {
|
|
187
|
+
operations,
|
|
188
|
+
preview: { min: {
|
|
189
|
+
kind: "close",
|
|
190
|
+
amount: quote.amount,
|
|
191
|
+
minAmount: quote.minAmount,
|
|
192
|
+
underlyingBalance: quote.underlyingBalance
|
|
193
|
+
} },
|
|
194
|
+
calls
|
|
195
|
+
},
|
|
196
|
+
instantError: void 0,
|
|
197
|
+
delayedBranch: void 0,
|
|
198
|
+
delayedError: void 0
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Resume withdraw: claim → (swap?) → decreaseDebt? → (unwrapRwa?) →
|
|
203
|
+
* withdrawCollateral + trailing changeQuota. Offchain prices swaps by
|
|
204
|
+
* oracle, onchain — router swap paths (leftover-aware).
|
|
205
|
+
*/
|
|
206
|
+
async #finishWithdrawCollateralIntent({ options, ...props }) {
|
|
207
|
+
switch (options.kind) {
|
|
208
|
+
case "offchain": return this.#finishWithdrawCollateralIntentOffchain({
|
|
209
|
+
...props,
|
|
210
|
+
options
|
|
211
|
+
});
|
|
212
|
+
default: try {
|
|
213
|
+
return await this.#finishWithdrawCollateralIntentOnchain({
|
|
214
|
+
...props,
|
|
215
|
+
options
|
|
216
|
+
});
|
|
217
|
+
} catch {
|
|
218
|
+
return this.#finishWithdrawCollateralIntentOffchain({
|
|
219
|
+
...props,
|
|
220
|
+
options
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
async #finishWithdrawCollateralIntentOffchain({ options, ...props }) {
|
|
226
|
+
const quoter = createOracleSwapQuoter({
|
|
227
|
+
sdk: this.sdk,
|
|
228
|
+
creditAccount: props.creditAccount
|
|
229
|
+
});
|
|
230
|
+
const baseOperations = await buildResumeWithdrawOperations({
|
|
231
|
+
...props,
|
|
232
|
+
options
|
|
233
|
+
}, quoter);
|
|
234
|
+
const state = simulateState({
|
|
235
|
+
...props,
|
|
236
|
+
operations: baseOperations
|
|
237
|
+
});
|
|
238
|
+
return {
|
|
239
|
+
ok: true,
|
|
240
|
+
instant: {
|
|
241
|
+
operations: getOperationsWithQuotaUpdate({
|
|
242
|
+
operations: baseOperations,
|
|
243
|
+
state,
|
|
244
|
+
creditAccount: props.creditAccount,
|
|
245
|
+
sdk: this.sdk,
|
|
246
|
+
options
|
|
247
|
+
}),
|
|
248
|
+
preview: { min: state.state },
|
|
249
|
+
calls: []
|
|
250
|
+
},
|
|
251
|
+
instantError: void 0,
|
|
252
|
+
delayedBranch: void 0,
|
|
253
|
+
delayedError: void 0
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
async #finishWithdrawCollateralIntentOnchain({ options, slippage = 0, ...props }) {
|
|
257
|
+
const quoter = createRouterSwapQuoter({
|
|
258
|
+
sdk: this.sdk,
|
|
259
|
+
creditAccount: props.creditAccount,
|
|
260
|
+
slippage
|
|
261
|
+
});
|
|
262
|
+
const baseOperations = await buildResumeWithdrawOperations({
|
|
263
|
+
...props,
|
|
264
|
+
options
|
|
265
|
+
}, quoter);
|
|
266
|
+
const state = simulateState({
|
|
267
|
+
...props,
|
|
268
|
+
operations: baseOperations
|
|
269
|
+
});
|
|
270
|
+
const operations = getOperationsWithQuotaUpdate({
|
|
271
|
+
operations: baseOperations,
|
|
272
|
+
state,
|
|
273
|
+
creditAccount: props.creditAccount,
|
|
274
|
+
sdk: this.sdk,
|
|
275
|
+
options
|
|
276
|
+
});
|
|
277
|
+
const calls = await assembleOperationCalls({
|
|
278
|
+
...props,
|
|
279
|
+
operations
|
|
280
|
+
});
|
|
281
|
+
return {
|
|
282
|
+
ok: true,
|
|
283
|
+
instant: {
|
|
284
|
+
operations,
|
|
285
|
+
preview: { min: state.state },
|
|
286
|
+
calls
|
|
287
|
+
},
|
|
288
|
+
instantError: void 0,
|
|
289
|
+
delayedBranch: void 0,
|
|
290
|
+
delayedError: void 0
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Resume decrease leverage: claim → (wrapRwa | swap)? → decreaseDebt +
|
|
295
|
+
* trailing changeQuota. Offchain prices swaps by oracle, onchain — router
|
|
296
|
+
* swap paths. Router miss soft-fails to the oracle quote (legacy parity).
|
|
297
|
+
*/
|
|
298
|
+
async #finishDecreaseLeverageIntent({ options, ...props }) {
|
|
299
|
+
switch (options.kind) {
|
|
300
|
+
case "offchain": return this.#finishDecreaseLeverageIntentOffchain({
|
|
301
|
+
...props,
|
|
302
|
+
options
|
|
303
|
+
});
|
|
304
|
+
default: try {
|
|
305
|
+
return await this.#finishDecreaseLeverageIntentOnchain({
|
|
306
|
+
...props,
|
|
307
|
+
options
|
|
308
|
+
});
|
|
309
|
+
} catch {
|
|
310
|
+
return this.#finishDecreaseLeverageIntentOffchain({
|
|
311
|
+
...props,
|
|
312
|
+
options
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
async #finishDecreaseLeverageIntentOffchain({ options, ...props }) {
|
|
318
|
+
const quoter = createOracleSwapQuoter({
|
|
319
|
+
sdk: this.sdk,
|
|
320
|
+
creditAccount: props.creditAccount
|
|
321
|
+
});
|
|
322
|
+
const baseOperations = await buildResumeDecreaseLeverageOperations({
|
|
323
|
+
...props,
|
|
324
|
+
options
|
|
325
|
+
}, quoter);
|
|
326
|
+
const state = simulateState({
|
|
327
|
+
...props,
|
|
328
|
+
operations: baseOperations
|
|
329
|
+
});
|
|
330
|
+
return {
|
|
331
|
+
ok: true,
|
|
332
|
+
instant: {
|
|
333
|
+
operations: getOperationsWithQuotaUpdate({
|
|
334
|
+
operations: baseOperations,
|
|
335
|
+
state,
|
|
336
|
+
creditAccount: props.creditAccount,
|
|
337
|
+
sdk: this.sdk,
|
|
338
|
+
options
|
|
339
|
+
}),
|
|
340
|
+
preview: { min: state.state },
|
|
341
|
+
calls: []
|
|
342
|
+
},
|
|
343
|
+
instantError: void 0,
|
|
344
|
+
delayedBranch: void 0,
|
|
345
|
+
delayedError: void 0
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
async #finishDecreaseLeverageIntentOnchain({ options, slippage = 0, ...props }) {
|
|
349
|
+
const quoter = createRouterSwapQuoter({
|
|
350
|
+
sdk: this.sdk,
|
|
351
|
+
creditAccount: props.creditAccount,
|
|
352
|
+
slippage
|
|
353
|
+
});
|
|
354
|
+
const baseOperations = await buildResumeDecreaseLeverageOperations({
|
|
355
|
+
...props,
|
|
356
|
+
options
|
|
357
|
+
}, quoter);
|
|
358
|
+
const state = simulateState({
|
|
359
|
+
...props,
|
|
360
|
+
operations: baseOperations
|
|
361
|
+
});
|
|
362
|
+
const operations = getOperationsWithQuotaUpdate({
|
|
363
|
+
operations: baseOperations,
|
|
364
|
+
state,
|
|
365
|
+
creditAccount: props.creditAccount,
|
|
366
|
+
sdk: this.sdk,
|
|
367
|
+
options
|
|
368
|
+
});
|
|
369
|
+
const calls = await assembleOperationCalls({
|
|
370
|
+
...props,
|
|
371
|
+
operations
|
|
372
|
+
});
|
|
373
|
+
return {
|
|
374
|
+
ok: true,
|
|
375
|
+
instant: {
|
|
376
|
+
operations,
|
|
377
|
+
preview: { min: state.state },
|
|
378
|
+
calls
|
|
379
|
+
},
|
|
380
|
+
instantError: void 0,
|
|
381
|
+
delayedBranch: void 0,
|
|
382
|
+
delayedError: void 0
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
//#endregion
|
|
387
|
+
export { CreditAccountOperationsService };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { buildResumeAddCollateralOperations } from "./resume/add-collateral/add-collateral.js";
|
|
2
|
+
import { buildResumeCloseOperations } from "./resume/close/close.js";
|
|
3
|
+
import { buildResumeDecreaseLeverageOperations } from "./resume/decrease-leverage/decrease-leverage.js";
|
|
4
|
+
import { buildResumeDepositOperations } from "./resume/deposit/deposit.js";
|
|
5
|
+
import { buildResumeIncreaseLeverageOperations } from "./resume/increase-leverage/increase-leverage.js";
|
|
6
|
+
import { buildResumeWithdrawOperations } from "./resume/withdraw/withdraw.js";
|
|
7
|
+
import "./resume/index.js";
|
|
8
|
+
export { buildResumeAddCollateralOperations, buildResumeCloseOperations, buildResumeDecreaseLeverageOperations, buildResumeDepositOperations, buildResumeIncreaseLeverageOperations, buildResumeWithdrawOperations };
|
package/dist/esm/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { ANY, RESUME_FIXTURE_PHANTOM, RWA_ASSET, UND, buildClaimResumeProps, buildOffchainOptions, buildOnchainOptions, buildResumeSdk } from "../../../testing/resume.js";
|
|
2
|
+
//#region src/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.ts
|
|
3
|
+
const ADD_UND = 100000000000n;
|
|
4
|
+
const ANY_CLAIMED = 2000000000000000000000n;
|
|
5
|
+
const RWA_CLAIMED = 100000000000n;
|
|
6
|
+
const QUOTA_INCREASE = 92000000000n;
|
|
7
|
+
/** Post-claim metrics after add und-worth collateral (fixed debt). */
|
|
8
|
+
const ADD_T1 = 5100000000000n;
|
|
9
|
+
const ADD_D1 = 4000000000000n;
|
|
10
|
+
/**
|
|
11
|
+
* Flow 1.2 — C=und, T=any (swap then quota).
|
|
12
|
+
* Resume: changeQuota(ANY) only.
|
|
13
|
+
*/
|
|
14
|
+
const case_1_2_und_any = {
|
|
15
|
+
claimedToken: ANY,
|
|
16
|
+
claimedAmount: ANY_CLAIMED,
|
|
17
|
+
postClaimTotalValue: ADD_T1,
|
|
18
|
+
postClaimDebt: ADD_D1,
|
|
19
|
+
resumeOps: [{
|
|
20
|
+
type: "claimDelayedWithdrawal",
|
|
21
|
+
token: ANY,
|
|
22
|
+
withdrawalPhantomToken: RESUME_FIXTURE_PHANTOM,
|
|
23
|
+
withdrawalTokenSpent: ANY_CLAIMED,
|
|
24
|
+
outputs: [{
|
|
25
|
+
token: ANY,
|
|
26
|
+
amount: ANY_CLAIMED,
|
|
27
|
+
isDelayed: false
|
|
28
|
+
}],
|
|
29
|
+
calls: []
|
|
30
|
+
}, {
|
|
31
|
+
type: "changeQuota",
|
|
32
|
+
quotaIncrease: [{
|
|
33
|
+
token: ANY,
|
|
34
|
+
balance: QUOTA_INCREASE
|
|
35
|
+
}],
|
|
36
|
+
quotaDecrease: [],
|
|
37
|
+
desiredQuota: {}
|
|
38
|
+
}],
|
|
39
|
+
expectedQuotaBalance: QUOTA_INCREASE
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Flow 1.7 — C=any, T=asset (swap then quota).
|
|
43
|
+
* Resume: changeQuota(RWA) only.
|
|
44
|
+
*/
|
|
45
|
+
const case_1_7_any_rwa = {
|
|
46
|
+
claimedToken: RWA_ASSET,
|
|
47
|
+
claimedAmount: RWA_CLAIMED,
|
|
48
|
+
postClaimTotalValue: ADD_T1,
|
|
49
|
+
postClaimDebt: ADD_D1,
|
|
50
|
+
resumeOps: [{
|
|
51
|
+
type: "claimDelayedWithdrawal",
|
|
52
|
+
token: RWA_ASSET,
|
|
53
|
+
withdrawalPhantomToken: RESUME_FIXTURE_PHANTOM,
|
|
54
|
+
withdrawalTokenSpent: RWA_CLAIMED,
|
|
55
|
+
outputs: [{
|
|
56
|
+
token: RWA_ASSET,
|
|
57
|
+
amount: RWA_CLAIMED,
|
|
58
|
+
isDelayed: false
|
|
59
|
+
}],
|
|
60
|
+
calls: []
|
|
61
|
+
}, {
|
|
62
|
+
type: "changeQuota",
|
|
63
|
+
quotaIncrease: [{
|
|
64
|
+
token: RWA_ASSET,
|
|
65
|
+
balance: QUOTA_INCREASE
|
|
66
|
+
}],
|
|
67
|
+
quotaDecrease: [],
|
|
68
|
+
desiredQuota: {}
|
|
69
|
+
}],
|
|
70
|
+
expectedQuotaBalance: QUOTA_INCREASE
|
|
71
|
+
};
|
|
72
|
+
/** Claimed und — no active quota-buy path. */
|
|
73
|
+
const case_claimed_und = {
|
|
74
|
+
claimedToken: UND,
|
|
75
|
+
claimedAmount: ADD_UND,
|
|
76
|
+
postClaimTotalValue: 5000000000000n,
|
|
77
|
+
postClaimDebt: 4000000000000n,
|
|
78
|
+
baseAssets: [{
|
|
79
|
+
token: ANY,
|
|
80
|
+
balance: 98000000000000000000000n,
|
|
81
|
+
quota: 0n,
|
|
82
|
+
mask: 0n,
|
|
83
|
+
success: true
|
|
84
|
+
}],
|
|
85
|
+
resumeOps: [{
|
|
86
|
+
type: "claimDelayedWithdrawal",
|
|
87
|
+
token: UND,
|
|
88
|
+
withdrawalPhantomToken: RESUME_FIXTURE_PHANTOM,
|
|
89
|
+
withdrawalTokenSpent: ADD_UND,
|
|
90
|
+
outputs: [{
|
|
91
|
+
token: UND,
|
|
92
|
+
amount: ADD_UND,
|
|
93
|
+
isDelayed: false
|
|
94
|
+
}],
|
|
95
|
+
calls: []
|
|
96
|
+
}]
|
|
97
|
+
};
|
|
98
|
+
function buildResumeAddCollateralProps(args) {
|
|
99
|
+
return buildClaimResumeProps({
|
|
100
|
+
intent: { type: "ADD_COLLATERAL" },
|
|
101
|
+
case: args.case,
|
|
102
|
+
sdk: args.sdk,
|
|
103
|
+
options: args.options
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
export { ADD_UND, ANY, ANY_CLAIMED, QUOTA_INCREASE, RWA_ASSET, RWA_CLAIMED, UND, buildOffchainOptions, buildOnchainOptions, buildResumeAddCollateralProps, buildResumeSdk, case_1_2_und_any, case_1_7_any_rwa, case_claimed_und };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { buildClaimDelayedWithdrawalOperation } from "../../../operations/claim-delayed/index.js";
|
|
2
|
+
import "../../../operations/index.js";
|
|
3
|
+
//#region src/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.ts
|
|
4
|
+
/**
|
|
5
|
+
* Resume add-collateral: claim only
|
|
6
|
+
*/
|
|
7
|
+
function buildResumeAddCollateralOperations(creditAccount, options, sdk) {
|
|
8
|
+
return [buildClaimDelayedWithdrawalOperation({
|
|
9
|
+
creditAccount,
|
|
10
|
+
sdk
|
|
11
|
+
}, options)];
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { buildResumeAddCollateralOperations };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { toBN } from "../../../../../utils/formatter.js";
|
|
2
|
+
import "../../../../../index.js";
|
|
3
|
+
import { CREDIT_ACCOUNT, CREDIT_FACADE, CREDIT_MANAGER, RESUME_FIXTURE_PHANTOM, RWA_ASSET, UND, buildOffchainOptions, buildOnchainOptions, buildResumeSdk, claimedValueInUnd } from "../../../testing/resume.js";
|
|
4
|
+
//#region src/sdk/accounts/intents/intents/resume/close/close.fixtures.ts
|
|
5
|
+
/**
|
|
6
|
+
* Resume close fixtures, ported from intent-calculator
|
|
7
|
+
* `closeAccount.flowFixtures.ts` (resume cases only).
|
|
8
|
+
*
|
|
9
|
+
* The oracle quoter repays debt from NON-underlying value
|
|
10
|
+
* (`amount = Σ convert(non-underlying) − debt`), so the base balance is held
|
|
11
|
+
* in TOK worth `CLOSE_T0` (minus the claimed token's value when the claim
|
|
12
|
+
* adds convertible value) and the derived amount matches `CLOSE_EQUITY`.
|
|
13
|
+
*/
|
|
14
|
+
const CLOSE_T0 = 5000000000000n;
|
|
15
|
+
const CLOSE_D0 = 4000000000000n;
|
|
16
|
+
const CLOSE_EQUITY = 1000000000000n;
|
|
17
|
+
const CLAIMED = 1000000n;
|
|
18
|
+
const A0_TOK = toBN("100000", 18);
|
|
19
|
+
/** TOK worth CLOSE_T0 (TOK $1 vs UND $2, 18→8 decimals). */
|
|
20
|
+
const BASE_TOK = toBN("100000", 18);
|
|
21
|
+
/** Wallet recipient of the close withdraw (legacy `mockAccount`). */
|
|
22
|
+
const CLOSE_TO = "0x1234567890123456789012345678901234567890";
|
|
23
|
+
const rwaUnderlyingMeta = { asset: RWA_ASSET };
|
|
24
|
+
/** Resume: claim first, then same close op as full flow. */
|
|
25
|
+
const closeResumeOps = [{
|
|
26
|
+
type: "claimDelayedWithdrawal",
|
|
27
|
+
token: UND,
|
|
28
|
+
withdrawalPhantomToken: RESUME_FIXTURE_PHANTOM,
|
|
29
|
+
withdrawalTokenSpent: 0n,
|
|
30
|
+
outputs: [{
|
|
31
|
+
token: UND,
|
|
32
|
+
amount: 0n,
|
|
33
|
+
isDelayed: false
|
|
34
|
+
}],
|
|
35
|
+
calls: []
|
|
36
|
+
}, {
|
|
37
|
+
type: "closeCreditAccount",
|
|
38
|
+
amount: CLOSE_EQUITY,
|
|
39
|
+
minAmount: CLOSE_EQUITY,
|
|
40
|
+
underlyingBalance: CLOSE_EQUITY,
|
|
41
|
+
calls: []
|
|
42
|
+
}];
|
|
43
|
+
const closePreviewState = {
|
|
44
|
+
kind: "close",
|
|
45
|
+
amount: CLOSE_EQUITY,
|
|
46
|
+
minAmount: CLOSE_EQUITY,
|
|
47
|
+
underlyingBalance: CLOSE_EQUITY
|
|
48
|
+
};
|
|
49
|
+
function buildCloseSdk(args) {
|
|
50
|
+
return buildResumeSdk({ claimedToken: args.claimedToken }, {
|
|
51
|
+
closePath: args.closePath,
|
|
52
|
+
rwaAssets: args.rwaAssets
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/** Pre-claim CA for resume: phantom balance; claim op credits claimed token then close. */
|
|
56
|
+
function buildCloseResumeProps(args) {
|
|
57
|
+
const claimedToken = args.claimedToken ?? "0x3333333333333333333333333333333333333333";
|
|
58
|
+
const claimedAmount = args.claimedAmount ?? 0n;
|
|
59
|
+
const creditAccount = {
|
|
60
|
+
creditAccount: CREDIT_ACCOUNT,
|
|
61
|
+
creditManager: CREDIT_MANAGER,
|
|
62
|
+
creditFacade: CREDIT_FACADE,
|
|
63
|
+
underlying: UND,
|
|
64
|
+
enabledTokensMask: 0n,
|
|
65
|
+
totalDebtUSD: 0n,
|
|
66
|
+
accountDebt: CLOSE_D0,
|
|
67
|
+
tokens: args.tokens ?? [{
|
|
68
|
+
token: "0xcccccccccccccccccccccccccccccccccccccccc",
|
|
69
|
+
balance: claimedAmount,
|
|
70
|
+
quota: 0n,
|
|
71
|
+
mask: 0n,
|
|
72
|
+
success: true
|
|
73
|
+
}, {
|
|
74
|
+
token: "0x1111111111111111111111111111111111111111",
|
|
75
|
+
balance: claimedToken === "0x3333333333333333333333333333333333333333" ? BASE_TOK : BASE_TOK - claimedValueInUnd(claimedAmount, claimedToken) * 20000000000n,
|
|
76
|
+
quota: 0n,
|
|
77
|
+
mask: 0n,
|
|
78
|
+
success: true
|
|
79
|
+
}]
|
|
80
|
+
};
|
|
81
|
+
return {
|
|
82
|
+
intent: {
|
|
83
|
+
type: "CLOSE_ACCOUNT",
|
|
84
|
+
to: CLOSE_TO
|
|
85
|
+
},
|
|
86
|
+
creditAccount,
|
|
87
|
+
sdk: args.sdk,
|
|
88
|
+
quotaReserve: void 0,
|
|
89
|
+
options: args.options,
|
|
90
|
+
slippage: args.slippage ?? 50
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
export { A0_TOK, CLAIMED, CLOSE_D0, CLOSE_EQUITY, CLOSE_T0, CLOSE_TO, CREDIT_ACCOUNT, buildCloseResumeProps, buildCloseSdk, buildOffchainOptions, buildOnchainOptions, closePreviewState, closeResumeOps, rwaUnderlyingMeta };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { toRouterCaSlice } from "../../../utils/common.js";
|
|
2
|
+
import { convertAmount } from "../../../utils/convert-amount.js";
|
|
3
|
+
import { simulateOperationAssets } from "../../../utils/simulate-assets.js";
|
|
4
|
+
import "../../../utils/index.js";
|
|
5
|
+
import { buildClaimDelayedWithdrawalOperation } from "../../../operations/claim-delayed/index.js";
|
|
6
|
+
import { buildCloseCreditAccountOperation } from "../../../operations/close-credit-account/index.js";
|
|
7
|
+
import "../../../operations/index.js";
|
|
8
|
+
//#region src/sdk/accounts/intents/intents/resume/close/close.ts
|
|
9
|
+
/**
|
|
10
|
+
* Resume close — linear op chain: claim, then close against the quoted
|
|
11
|
+
* post-claim balances. Quota zeroing and debt/withdraw live inside
|
|
12
|
+
* assembleCloseCreditAccountCalls — no separate changeQuota / wrap ops.
|
|
13
|
+
*/
|
|
14
|
+
async function buildResumeCloseOperations(props, quoter) {
|
|
15
|
+
const { options, creditAccount, sdk, intent } = props;
|
|
16
|
+
const operations = [buildClaimDelayedWithdrawalOperation({
|
|
17
|
+
creditAccount,
|
|
18
|
+
sdk
|
|
19
|
+
}, options)];
|
|
20
|
+
const convert = convertAmount(sdk, creditAccount.creditManager);
|
|
21
|
+
const { assets: assetsAfterClaim, debt } = simulateOperationAssets({
|
|
22
|
+
initialAssets: creditAccount.tokens,
|
|
23
|
+
operations,
|
|
24
|
+
underlyingToken: creditAccount.underlying,
|
|
25
|
+
debt: creditAccount.accountDebt,
|
|
26
|
+
convert
|
|
27
|
+
});
|
|
28
|
+
const quote = await quoter({
|
|
29
|
+
assets: assetsAfterClaim,
|
|
30
|
+
debt
|
|
31
|
+
});
|
|
32
|
+
if (options.kind === "onchain") operations.push(await buildCloseCreditAccountOperation({
|
|
33
|
+
quote,
|
|
34
|
+
sdk
|
|
35
|
+
}, {
|
|
36
|
+
...options,
|
|
37
|
+
to: intent.to,
|
|
38
|
+
creditAccount: toRouterCaSlice(creditAccount, assetsAfterClaim)
|
|
39
|
+
}));
|
|
40
|
+
else operations.push(await buildCloseCreditAccountOperation({
|
|
41
|
+
quote,
|
|
42
|
+
sdk
|
|
43
|
+
}, options));
|
|
44
|
+
return {
|
|
45
|
+
operations,
|
|
46
|
+
quote
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { buildResumeCloseOperations };
|