@gearbox-protocol/sdk 18.6.0-next.1 → 18.6.0-next.3
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/abi/signatureDegenNFT.js +14 -0
- package/dist/cjs/model/index.js +5 -2
- package/dist/cjs/model/openingApproval.js +1 -0
- package/dist/cjs/model/openingApproval.schema.js +17 -0
- package/dist/cjs/offchain/AbstractOffchainNamespace.js +6 -16
- package/dist/cjs/offchain/errors/OpeningSignerConfigurationError.js +7 -0
- package/dist/cjs/offchain/errors/OpeningSignerError.js +39 -0
- package/dist/cjs/offchain/errors/OpeningSignerQuorumError.js +12 -0
- package/dist/cjs/offchain/errors/OpeningSignerVerificationError.js +18 -0
- package/dist/cjs/offchain/errors/index.js +12 -0
- package/dist/cjs/offchain/index.js +16 -0
- package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +9 -0
- package/dist/cjs/offchain/opportunities/index.js +4 -0
- package/dist/cjs/offchain/opportunities/openingApproval.js +141 -0
- package/dist/cjs/offchain/opportunities/openingSignerRegistries.js +12 -0
- package/dist/cjs/offchain/transport.js +21 -0
- package/dist/cjs/onchain/accounts/CreditAccountsServiceV310.js +20 -3
- package/dist/cjs/onchain/accounts/openingApproval.js +72 -0
- package/dist/cjs/onchain/index.js +3 -0
- package/dist/cjs/onchain/market/credit/CreditFacadeV310BaseContract.js +6 -2
- package/dist/cjs/onchain/market/credit/CreditFacadeV310Contract.js +14 -1
- package/dist/cjs/onchain/market/credit/CreditSuite.js +4 -2
- package/dist/cjs/onchain/market/credit/errors.js +18 -0
- package/dist/cjs/onchain/market/credit/index.js +3 -0
- package/dist/cjs/onchain/market/index.js +3 -0
- package/dist/cjs/onchain/preview/parse/parseFacadeOperationCalldata.js +1 -0
- package/dist/cjs/permissionless/api/GearboxPermissionless.js +3 -2
- package/dist/cjs/permissionless/api/analytics/PermissionlessAnalytics.js +20 -0
- package/dist/cjs/permissionless/api/analytics/schemas.js +3 -0
- package/dist/cjs/permissionless/api/transactions/InstanceOwnerTransactions.js +71 -17
- package/dist/cjs/permissionless/api/transactions/fixedRateWindowFeeds.js +134 -0
- package/dist/cjs/permissionless/api/transactions/lp-price-feeds.js +10 -35
- package/dist/cjs/permissionless/api/transactions/nextLowerBound.js +18 -0
- package/dist/cjs/sdk/execute/ExecuteApi.js +20 -3
- package/dist/cjs/sdk/opportunities/OpportunitiesNamespace.js +1 -1
- package/dist/esm/abi/signatureDegenNFT.js +11 -0
- package/dist/esm/dev/RevolverTransport.js +1 -1
- package/dist/esm/dev/resilientTransport.js +1 -1
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/model/analytics.schema.js +1 -1
- package/dist/esm/model/index.js +6 -4
- package/dist/esm/model/openingApproval.js +1 -0
- package/dist/esm/model/openingApproval.schema.js +16 -0
- package/dist/esm/offchain/AbstractOffchainNamespace.js +6 -16
- package/dist/esm/offchain/errors/OffchainValidationError.js +1 -1
- package/dist/esm/offchain/errors/OpeningSignerConfigurationError.js +6 -0
- package/dist/esm/offchain/errors/OpeningSignerError.js +34 -0
- package/dist/esm/offchain/errors/OpeningSignerQuorumError.js +11 -0
- package/dist/esm/offchain/errors/OpeningSignerVerificationError.js +17 -0
- package/dist/esm/offchain/errors/index.js +5 -1
- package/dist/esm/offchain/index.js +7 -1
- package/dist/esm/offchain/opportunities/OffchainOpportunities.js +9 -0
- package/dist/esm/offchain/opportunities/index.js +4 -1
- package/dist/esm/offchain/opportunities/openingApproval.js +140 -0
- package/dist/esm/offchain/opportunities/openingSignerRegistries.js +11 -0
- package/dist/esm/offchain/transport.js +19 -0
- package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +24 -7
- package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +6 -6
- package/dist/esm/onchain/accounts/openingApproval.js +71 -0
- package/dist/esm/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +2 -2
- package/dist/esm/onchain/base/TokensMeta.js +4 -4
- package/dist/esm/onchain/chain/chains.js +1 -1
- package/dist/esm/onchain/core/createAddressProvider.js +1 -1
- package/dist/esm/onchain/index.js +3 -2
- package/dist/esm/onchain/market/MarketSuite.js +1 -1
- package/dist/esm/onchain/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
- package/dist/esm/onchain/market/credit/CreditFacadeV310BaseContract.js +7 -3
- package/dist/esm/onchain/market/credit/CreditFacadeV310Contract.js +14 -1
- package/dist/esm/onchain/market/credit/CreditSuite.js +4 -2
- package/dist/esm/onchain/market/credit/errors.js +16 -0
- package/dist/esm/onchain/market/credit/index.js +2 -1
- package/dist/esm/onchain/market/index.js +2 -1
- package/dist/esm/onchain/market/pool/PoolV310Contract.js +3 -3
- package/dist/esm/onchain/market/rwa/RWARegistry.js +1 -1
- package/dist/esm/onchain/market/rwa/createDegenNFT.js +1 -1
- package/dist/esm/onchain/market/rwa/midas/MidasDegenNFT.js +1 -1
- package/dist/esm/onchain/market/rwa/securitize/SecuritizeDegenNFT.js +1 -1
- package/dist/esm/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +1 -1
- package/dist/esm/onchain/market/zapper/ZapperContract.js +2 -2
- package/dist/esm/onchain/positions/PositionsService.js +1 -1
- package/dist/esm/onchain/preview/parse/parseFacadeOperationCalldata.js +1 -0
- package/dist/esm/onchain/preview/parse/parseRWAFactoryOperationCalldata.js +1 -1
- package/dist/esm/onchain/preview/preview/previewPoolPositionOperation.js +1 -1
- package/dist/esm/onchain/utils/zod.js +1 -1
- package/dist/esm/permissionless/api/GearboxPermissionless.js +3 -2
- package/dist/esm/permissionless/api/analytics/PermissionlessAnalytics.js +21 -1
- package/dist/esm/permissionless/api/analytics/schemas.js +3 -1
- package/dist/esm/permissionless/api/configurators/schemas.js +1 -1
- package/dist/esm/permissionless/api/oracles/PermissionlessOracles.js +2 -2
- package/dist/esm/permissionless/api/schemas.js +1 -1
- package/dist/esm/permissionless/api/transactions/InstanceOwnerTransactions.js +71 -17
- package/dist/esm/permissionless/api/transactions/fixedRateWindowFeeds.js +131 -0
- package/dist/esm/permissionless/api/transactions/lp-price-feeds.js +10 -34
- package/dist/esm/permissionless/api/transactions/nextLowerBound.js +17 -0
- package/dist/esm/permissionless/curator/actions/addAssetActionData.js +1 -1
- package/dist/esm/permissionless/curator/actions/addCollateralTokenActionData.js +1 -1
- package/dist/esm/permissionless/curator/actions/addPeripheryContractActionData.js +1 -1
- package/dist/esm/permissionless/curator/actions/createCreditSuiteActionData.js +1 -1
- package/dist/esm/permissionless/curator/actions/createMarketActionData.js +1 -1
- package/dist/esm/permissionless/curator/actions/creditManagerTargets.js +1 -1
- package/dist/esm/permissionless/curator/actions/deployContractActionData.js +1 -1
- package/dist/esm/permissionless/curator/actions/setPriceFeedActionData.js +1 -1
- package/dist/esm/permissionless/curator/actions/utils/rawAmounts.js +1 -1
- package/dist/esm/permissionless/curator/configurator-actions/setDefaultSplitActionData.js +1 -1
- package/dist/esm/permissionless/curator/plugins/adapters/adapterPluginHelpers.js +1 -1
- package/dist/esm/permissionless/curator/plugins/adapters/curve-v1/getCurveV1Plugin.js +1 -1
- package/dist/esm/permissionless/curator/plugins/adapters/curve-v1-steth/curveV1StETHPlugin.js +1 -1
- package/dist/esm/permissionless/curator/plugins/adapters/erc4626/erc4626AdapterPlugin.js +1 -1
- package/dist/esm/permissionless/curator/plugins/adapters/erc4626-referral/erc4626ReferralAdapterPlugin.js +1 -1
- package/dist/esm/permissionless/curator/plugins/adapters/mellow-erc4626/mellowErc4626AdapterPlugin.js +1 -1
- package/dist/esm/permissionless/curator/plugins/adapters/mellow-wrapper/mellowWrapperAdapterPlugin.js +1 -1
- package/dist/esm/permissionless/curator/plugins/adapters/midas-gateway/midasGatewayAdapterPlugin.js +1 -1
- package/dist/esm/permissionless/curator/plugins/adapters/midas-issuance/midasIssuanceAdapterPlugin.js +1 -1
- package/dist/esm/permissionless/curator/plugins/adapters/midas-redemption/midasRedemptionAdapterPlugin.js +1 -1
- package/dist/esm/permissionless/curator/plugins/adapters/securitize-redemption/securitizeRedemptionAdapterPlugin.js +1 -1
- package/dist/esm/permissionless/curator/plugins/adapters/staking-rewards/stakingRewardsPlugin.js +1 -1
- package/dist/esm/permissionless/curator/plugins/irm/linear/linearPlugin.js +1 -1
- package/dist/esm/permissionless/curator/plugins/loss-policies/alias/actions/setAliasActionData.js +1 -1
- package/dist/esm/permissionless/curator/plugins/loss-policies/alias/aliasedLossPolicyPlugin.js +1 -1
- package/dist/esm/permissionless/curator/plugins/rate-keepers/gauge/gaugePlugin.js +1 -1
- package/dist/esm/permissionless/curator/plugins/rate-keepers/tumbler/tumblerPlugin.js +1 -1
- package/dist/esm/permissionless/curator/rwaPeripherySetup.js +1 -1
- package/dist/esm/permissionless/curator/state/configurator/types.js +1 -1
- package/dist/esm/permissionless/curator/validationSchemas.js +1 -1
- package/dist/esm/sdk/GearboxSDK.js +2 -2
- package/dist/esm/sdk/execute/ExecuteApi.js +21 -4
- package/dist/esm/sdk/opportunities/OpportunitiesNamespace.js +1 -1
- package/dist/types/abi/signatureDegenNFT.d.ts +91 -0
- package/dist/types/model/index.d.ts +3 -1
- package/dist/types/model/openingApproval.d.ts +33 -0
- package/dist/types/model/openingApproval.schema.d.ts +11 -0
- package/dist/types/offchain/errors/OpeningSignerConfigurationError.d.ts +4 -0
- package/dist/types/offchain/errors/OpeningSignerError.d.ts +24 -0
- package/dist/types/offchain/errors/OpeningSignerQuorumError.d.ts +6 -0
- package/dist/types/offchain/errors/OpeningSignerVerificationError.d.ts +8 -0
- package/dist/types/offchain/errors/index.d.ts +5 -1
- package/dist/types/offchain/index.d.ts +8 -2
- package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +2 -0
- package/dist/types/offchain/opportunities/index.d.ts +3 -1
- package/dist/types/offchain/opportunities/openingApproval.d.ts +3 -0
- package/dist/types/offchain/opportunities/openingSignerRegistries.d.ts +3 -0
- package/dist/types/offchain/opportunities/types.d.ts +2 -0
- package/dist/types/offchain/transport.d.ts +2 -0
- package/dist/types/offchain/types.d.ts +12 -0
- package/dist/types/onchain/accounts/CreditAccountsServiceV310.d.ts +4 -1
- package/dist/types/onchain/accounts/liquidations/types.d.ts +3 -3
- package/dist/types/onchain/accounts/openingApproval.d.ts +4 -0
- package/dist/types/onchain/accounts/types.d.ts +4 -0
- package/dist/types/onchain/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.d.ts +2 -2
- package/dist/types/onchain/index.d.ts +2 -1
- package/dist/types/onchain/market/credit/CreditFacadeV310BaseContract.d.ts +28 -0
- package/dist/types/onchain/market/credit/CreditFacadeV310Contract.d.ts +1 -1
- package/dist/types/onchain/market/credit/CreditSuite.d.ts +2 -2
- package/dist/types/onchain/market/credit/errors.d.ts +11 -0
- package/dist/types/onchain/market/credit/index.d.ts +2 -1
- package/dist/types/onchain/market/credit/types.d.ts +1 -1
- package/dist/types/onchain/market/index.d.ts +2 -1
- package/dist/types/onchain/preview/parse/types-facades.d.ts +1 -0
- package/dist/types/permissionless/api/GearboxPermissionless.d.ts +2 -1
- package/dist/types/permissionless/api/analytics/PermissionlessAnalytics.d.ts +12 -1
- package/dist/types/permissionless/api/analytics/index.d.ts +2 -2
- package/dist/types/permissionless/api/analytics/schemas.d.ts +4 -0
- package/dist/types/permissionless/api/analytics/types.d.ts +29 -0
- package/dist/types/permissionless/api/index.d.ts +2 -2
- package/dist/types/permissionless/api/transactions/InstanceOwnerTransactions.d.ts +16 -9
- package/dist/types/permissionless/api/transactions/fixedRateWindowFeeds.d.ts +38 -0
- package/dist/types/permissionless/api/transactions/lp-price-feeds.d.ts +4 -6
- package/dist/types/permissionless/api/transactions/nextLowerBound.d.ts +15 -0
- package/dist/types/permissionless/index.d.ts +2 -2
- package/dist/types/sdk/execute/ExecuteApi.d.ts +2 -1
- package/dist/types/sdk/execute/types.d.ts +8 -1
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ require("../../model/rwa.js");
|
|
|
4
4
|
require("../../model/index.js");
|
|
5
5
|
const require_onchain_market_rwa_securitize_SecuritizeRWAFactory = require("../../onchain/market/rwa/securitize/SecuritizeRWAFactory.js");
|
|
6
6
|
const require_onchain_market_rwa_types = require("../../onchain/market/rwa/types.js");
|
|
7
|
+
const require_offchain_opportunities_openingApproval = require("../../offchain/opportunities/openingApproval.js");
|
|
7
8
|
require("../../onchain/index.js");
|
|
8
9
|
let viem = require("viem");
|
|
9
10
|
// src/sdk/execute/ExecuteApi.ts
|
|
@@ -12,7 +13,9 @@ let viem = require("viem");
|
|
|
12
13
|
**/
|
|
13
14
|
var ExecuteApi = class {
|
|
14
15
|
#chainOf;
|
|
15
|
-
|
|
16
|
+
#signer;
|
|
17
|
+
constructor(chainOf, signer = { requestOpeningApproval: require_offchain_opportunities_openingApproval.collectOpeningApproval }) {
|
|
18
|
+
this.#signer = signer;
|
|
16
19
|
this.#chainOf = chainOf;
|
|
17
20
|
}
|
|
18
21
|
/** {@inheritDoc IOpportunitiesExecute.withSecuritizeSignatures} */
|
|
@@ -55,14 +58,25 @@ var ExecuteApi = class {
|
|
|
55
58
|
async buildTx(request) {
|
|
56
59
|
if (!request.sim.ok) throw new Error(`cannot build a transaction from a failed ${request.kind} preparation`);
|
|
57
60
|
const sdk = this.#chainOf(request.chainId);
|
|
61
|
+
if (request.kind === "pool") return poolTx(sdk, request);
|
|
62
|
+
if (request.kind === "account") return accountTx(sdk, request);
|
|
63
|
+
const openingApproval = await this.#openingApproval(sdk, request);
|
|
64
|
+
if (openingApproval) request = {
|
|
65
|
+
...request,
|
|
66
|
+
openingApproval
|
|
67
|
+
};
|
|
58
68
|
switch (request.kind) {
|
|
59
|
-
case "pool": return poolTx(sdk, request);
|
|
60
69
|
case "open": return openTx(sdk, request);
|
|
61
70
|
case "openEmpty": return openEmptyTx(sdk, request);
|
|
62
71
|
case "borrow": return borrowTx(sdk, request);
|
|
63
|
-
case "account": return accountTx(sdk, request);
|
|
64
72
|
}
|
|
65
73
|
}
|
|
74
|
+
async #openingApproval(sdk, request) {
|
|
75
|
+
if (request.openingApproval || request.kind !== "openEmpty" && request.sim.data.state.creditAccount) return;
|
|
76
|
+
const requirement = await sdk.accounts.getOpeningApprovalRequirement(request.creditManager, request.wallet);
|
|
77
|
+
if (requirement.status !== "signaturesRequired") return;
|
|
78
|
+
return this.#signer.requestOpeningApproval(requirement);
|
|
79
|
+
}
|
|
66
80
|
};
|
|
67
81
|
function poolTx(sdk, request) {
|
|
68
82
|
const { pool, wallet, sim } = request;
|
|
@@ -95,6 +109,7 @@ async function openTx(sdk, request) {
|
|
|
95
109
|
const { creditManager, wallet, collateral, ethAmount, sim } = request;
|
|
96
110
|
const { state } = sim.data;
|
|
97
111
|
return sdk.accounts.openCA({
|
|
112
|
+
...request.openingApproval && { openingApproval: request.openingApproval },
|
|
98
113
|
creditManager,
|
|
99
114
|
to: wallet,
|
|
100
115
|
collateral,
|
|
@@ -119,6 +134,7 @@ async function openTx(sdk, request) {
|
|
|
119
134
|
**/
|
|
120
135
|
function openEmptyTx(sdk, request) {
|
|
121
136
|
return sdk.accounts.openCA({
|
|
137
|
+
...request.openingApproval && { openingApproval: request.openingApproval },
|
|
122
138
|
creditManager: request.creditManager,
|
|
123
139
|
to: request.wallet,
|
|
124
140
|
collateral: [],
|
|
@@ -149,6 +165,7 @@ async function borrowTx(sdk, request) {
|
|
|
149
165
|
balance: state.collateral.value
|
|
150
166
|
};
|
|
151
167
|
return sdk.accounts.openCA({
|
|
168
|
+
...request.openingApproval && { openingApproval: request.openingApproval },
|
|
152
169
|
creditManager,
|
|
153
170
|
to: wallet,
|
|
154
171
|
collateral: [collateral],
|
|
@@ -30,7 +30,7 @@ var OpportunitiesNamespace = class extends require_sdk_AbstractNamespace.Abstrac
|
|
|
30
30
|
constructor(onchain, offchain, options) {
|
|
31
31
|
super("Opportunities", onchain?.opportunities, offchain?.opportunities, options);
|
|
32
32
|
this.#prepare = onchain && new require_sdk_prepare_PrepareApi.PrepareApi(onchain, options.ensureFresh);
|
|
33
|
-
this.#execute = onchain && new require_sdk_execute_ExecuteApi.ExecuteApi((chainId) => onchain.chain(chainId));
|
|
33
|
+
this.#execute = onchain && new require_sdk_execute_ExecuteApi.ExecuteApi((chainId) => onchain.chain(chainId), offchain?.opportunities);
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
36
|
* {@inheritDoc IOpportunitiesOnchainOnly.prepare}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { parseAbi, parseAbiParameters } from "viem";
|
|
2
|
+
// src/abi/signatureDegenNFT.ts
|
|
3
|
+
const openingSignatureParams = parseAbiParameters("(address creditManager,address accountOwner,uint32 deadline,uint32 nonce,bytes signature)[]");
|
|
4
|
+
const signatureDegenNFTAbi = parseAbi([
|
|
5
|
+
"function marketConfigurator() view returns (address)",
|
|
6
|
+
"function acl() view returns (address)",
|
|
7
|
+
"function minSignaturesRequired() view returns (uint16)",
|
|
8
|
+
"function openingDeadlines(address accountOwner,address creditManager) view returns (uint32 deadline,uint32 nonce)"
|
|
9
|
+
]);
|
|
10
|
+
const openWithDataAbi = parseAbi(["function openCreditAccount(address onBehalfOf,(address target,bytes callData)[] calls,uint256 referralCode,bytes degenNFTData) payable returns (address creditAccount)"]);
|
|
11
|
+
export { openWithDataAbi, openingSignatureParams, signatureDegenNFTAbi };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { httpTransportOptionsSchema } from "./transports.js";
|
|
2
|
-
import { z } from "zod/v4";
|
|
3
2
|
import { BaseError, HttpRequestError, InvalidInputRpcError, InvalidParamsRpcError, InvalidRequestRpcError, ResourceNotFoundRpcError, ResourceUnavailableRpcError, RpcError, http, withRetry } from "viem";
|
|
4
3
|
import { mainnet } from "viem/chains";
|
|
4
|
+
import { z } from "zod/v4";
|
|
5
5
|
// src/dev/RevolverTransport.ts
|
|
6
6
|
const providerConfigSchema = z.object({
|
|
7
7
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { isOutOfSyncError } from "./isOutOfSyncError.js";
|
|
2
2
|
import { isRateLimitError } from "./isRateLimitError.js";
|
|
3
3
|
import { isTransientError } from "./isTransientError.js";
|
|
4
|
-
import { z } from "zod/v4";
|
|
5
4
|
import { withRetry } from "viem";
|
|
5
|
+
import { z } from "zod/v4";
|
|
6
6
|
// src/dev/resilientTransport.ts
|
|
7
7
|
/** Schema for {@link RateLimitOptions}. */
|
|
8
8
|
const rateLimitOptionsSchema = z.object({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { iWithdrawalCompressorV313Abi } from "../abi/IWithdrawalCompressorV313.js";
|
|
2
1
|
import { getNetworkType } from "../onchain/chain/chains.js";
|
|
3
2
|
import { getWithdrawalCompressorAddress } from "../onchain/accounts/withdrawal-compressor/addresses.js";
|
|
3
|
+
import { iWithdrawalCompressorV313Abi } from "../abi/IWithdrawalCompressorV313.js";
|
|
4
4
|
import "../onchain/index.js";
|
|
5
5
|
import { iMidasDataFeedAbi, iMidasRedemptionVaultAbi, midasGatewayAbi, midasRedeemerAbi, midasRedemptionVaultPhantomTokenAbi, securitizeRedeemerAbi, securitizeRedemptionGatewayAbi, securitizeRedemptionPhantomTokenAbi } from "./withdrawalAbi.js";
|
|
6
6
|
import { erc20Abi, hexToString, parseAbi, parseEther } from "viem";
|
|
@@ -6,8 +6,8 @@ import { encodeFlag, filterable } from "./filters.schema.js";
|
|
|
6
6
|
import { liquidationPositionSchema } from "./liquidations.schema.js";
|
|
7
7
|
import { poolPositionSchema, positionKindSchema, strategyPositionSchema } from "./positions.schema.js";
|
|
8
8
|
import { assetTypeSchema, chainIdSchema, tokenSchema, underlyingTokenSchema } from "./primitives.schema.js";
|
|
9
|
-
import { z } from "zod/v4";
|
|
10
9
|
import { isAddress } from "viem";
|
|
10
|
+
import { z } from "zod/v4";
|
|
11
11
|
// src/model/analytics.schema.ts
|
|
12
12
|
/** Default page size of the protocol-wide positions list. */
|
|
13
13
|
const ANALYTICS_POSITIONS_DEFAULT_LIMIT = 25;
|
package/dist/esm/model/index.js
CHANGED
|
@@ -11,15 +11,17 @@ import { FILTER_ALL, isFilterSet } from "./filters.js";
|
|
|
11
11
|
import { booleanParamSchema, encodeFlag, filterAllSchema, filterable } from "./filters.schema.js";
|
|
12
12
|
import { matchesLiquidatableAccountFilter } from "./liquidations.js";
|
|
13
13
|
import { delayedReceivedAssetSchema, instantReceivedAssetSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionSchema, receivedAssetSchema } from "./liquidations.schema.js";
|
|
14
|
+
import "./openingApproval.js";
|
|
15
|
+
import { openingSignerResponseSchema } from "./openingApproval.schema.js";
|
|
14
16
|
import { matchesOpportunityFilter, opportunityId, poolOpportunityId, strategyOpportunityId } from "./opportunities.js";
|
|
15
|
-
import { apyBreakdownSchema, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityKeySchema, opportunityKindSchema, opportunitySchema, opportunityTotalsSchema, pointRewardsSchema, pointsProgramSchema, poolOpportunityDetailSchema, poolOpportunityKeySchema, poolOpportunitySchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, rewardsSchema, strategyOpportunityDetailSchema, strategyOpportunityKeySchema, strategyOpportunitySchema, tokenRewardsSchema } from "./opportunities.schema.js";
|
|
16
|
-
import { STRATEGY_POSITION_COLLATERAL_ERROR, liquidationPositionId, matchesPositionFilter, poolPositionId, positionId, strategyPositionId } from "./positions.js";
|
|
17
|
-
import { borrowRateBreakdownSchema, pnlBreakdownSchema, pointsProgramPnLSchema, pointsRewardsPnLSchema, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionKeySchema, positionKindSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionsTotalsSchema, rewardsPnLSchema, strategyPositionKeySchema, strategyPositionSchema, tokenQuotaRateSchema, tokenRewardsPnLSchema } from "./positions.schema.js";
|
|
18
17
|
import { creditAccountFrozen, liquidatorNotEligible, notEmergencyLiquidator, partialLiquidationImpossible } from "./errors/liquidation-errors.js";
|
|
19
18
|
import { accountNotMidasGreenlisted, creditManagerPaused, debtOutOfRange, forbiddenToken, insufficientAllowance, insufficientBalance, insufficientCollateral, insufficientPoolLiquidity, leverageOutOfRange, marketExpired, poolPaused, poolSunset, quotaAboveMax, quotaCountExceeded, quotaInactive, quotaLimitReached, quotaUnchanged, reservePriceLimited, rwaOpenRequirementsNotMet } from "./errors/operation-errors.js";
|
|
20
19
|
import { unpriceableTokenError } from "./errors/oracle-errors.js";
|
|
21
20
|
import { creditAccountNotEmpty, creditAccountNotFound, multipleDelayedWithdrawals, noDelayedRoute, noRecordedIntent, noStrategyTargetCollateral, unexpectedFailure, unsupportedCollateralToken, unsupportedTokenPair, withdrawalInProgress } from "./errors/prepare-errors.js";
|
|
22
21
|
import { malformedTransaction } from "./errors/preview-errors.js";
|
|
22
|
+
import { apyBreakdownSchema, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityKeySchema, opportunityKindSchema, opportunitySchema, opportunityTotalsSchema, pointRewardsSchema, pointsProgramSchema, poolOpportunityDetailSchema, poolOpportunityKeySchema, poolOpportunitySchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, rewardsSchema, strategyOpportunityDetailSchema, strategyOpportunityKeySchema, strategyOpportunitySchema, tokenRewardsSchema } from "./opportunities.schema.js";
|
|
23
|
+
import { STRATEGY_POSITION_COLLATERAL_ERROR, liquidationPositionId, matchesPositionFilter, poolPositionId, positionId, strategyPositionId } from "./positions.js";
|
|
24
|
+
import { borrowRateBreakdownSchema, pnlBreakdownSchema, pointsProgramPnLSchema, pointsRewardsPnLSchema, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionKeySchema, positionKindSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionsTotalsSchema, rewardsPnLSchema, strategyPositionKeySchema, strategyPositionSchema, tokenQuotaRateSchema, tokenRewardsPnLSchema } from "./positions.schema.js";
|
|
23
25
|
import { asEstimated } from "./previews.js";
|
|
24
26
|
import "./primitives.js";
|
|
25
27
|
import { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema, underlyingTokenSchema } from "./primitives.schema.js";
|
|
@@ -31,4 +33,4 @@ import { KYC_REGISTRATION_LINKS, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_
|
|
|
31
33
|
import { kycRequirementSchema, rwaProtocolSchema } from "./rwa.schema.js";
|
|
32
34
|
import "./withdrawals.js";
|
|
33
35
|
import { positionClaimableWithdrawalSchema, positionPendingWithdrawalSchema, positionWithdrawalsSchema, withdrawalOutputAmountSchema } from "./withdrawals.schema.js";
|
|
34
|
-
export { ANALYTICS_POSITIONS_DEFAULT_LIMIT, ANALYTICS_POSITIONS_MAX_LIMIT, CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, FILTER_ALL, KYC_REGISTRATION_LINKS, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, PROTOCOL_CHART_METRICS, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_PROTOCOLS, SECURITIZE_REGISTER_VAULT_TYPES, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS, STRATEGY_POSITION_COLLATERAL_ERROR, accountNotMidasGreenlisted, amountSchema, analyticsChartQueryOptionsSchema, analyticsChartQueryParamsSchema, analyticsChartQuerySchema, analyticsContractOptionSchema, analyticsContractRefSchema, analyticsCuratorOptionSchema, analyticsPositionFilterOptionsQuerySchema, analyticsPositionFilterOptionsSchema, analyticsPositionListOptionsSchema, analyticsPositionListQueryParamsSchema, analyticsPositionListQuerySchema, analyticsPositionPageSchema, analyticsPositionSchema, analyticsPositionSortFieldSchema, analyticsSortDirectionSchema, apyBreakdownSchema, asEstimated, assetTypeSchema, backendPreferred, booleanParamSchema, borrowRateBreakdownSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, compareTagOf, creditAccountFrozen, creditAccountNotEmpty, creditAccountNotFound, creditManagerPaused, curatorNameSchema, curatorSchema, dataSourceSchema, debtOutOfRange, delayedReceivedAssetSchema, encodeFlag, filterAllSchema, filterable, forbiddenToken, instantReceivedAssetSchema, insufficientAllowance, insufficientBalance, insufficientCollateral, insufficientPoolLiquidity, isFilterSet, kycRequirementSchema, leverageOutOfRange, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, liquidatorNotEligible, malformedTransaction, marketExpired, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, multipleDelayedWithdrawals, noDelayedRoute, noRecordedIntent, noStrategyTargetCollateral, notEmergencyLiquidator, offchainOnly, onchainOnly, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, opportunityTotalsSchema, partialLiquidationImpossible, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolOpportunityChartMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPaused, poolPositionChartMetricSchema, poolPositionId, poolPositionKeySchema, poolPositionSchema, poolSunset, positionClaimableWithdrawalSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionId, positionKeySchema, positionKindSchema, positionPendingWithdrawalSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionWithdrawalsSchema, positionsTotalsSchema, priceFeedDataSchema, priceFeedSummarySchema, protocolChartMetricSchema, quotaAboveMax, quotaAssetSchema, quotaCountExceeded, quotaInactive, quotaLimitReached, quotaUnchanged, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, reservePriceLimited, responseMetadataSchema, responseSchema, rewardsPnLSchema, rewardsSchema, rwaOpenRequirementsNotMet, rwaProtocolSchema, safeValue, sdkErr, sdkOk, strategyOpportunityChartMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionChartMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenQuotaRateSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, tolerance, txCallSchema, underlyingTokenSchema, unexpectedFailure, unpriceableTokenError, unsupportedCollateralToken, unsupportedTokenPair, withdrawalInProgress, withdrawalOutputAmountSchema };
|
|
36
|
+
export { ANALYTICS_POSITIONS_DEFAULT_LIMIT, ANALYTICS_POSITIONS_MAX_LIMIT, CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, FILTER_ALL, KYC_REGISTRATION_LINKS, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, PROTOCOL_CHART_METRICS, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_PROTOCOLS, SECURITIZE_REGISTER_VAULT_TYPES, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS, STRATEGY_POSITION_COLLATERAL_ERROR, accountNotMidasGreenlisted, amountSchema, analyticsChartQueryOptionsSchema, analyticsChartQueryParamsSchema, analyticsChartQuerySchema, analyticsContractOptionSchema, analyticsContractRefSchema, analyticsCuratorOptionSchema, analyticsPositionFilterOptionsQuerySchema, analyticsPositionFilterOptionsSchema, analyticsPositionListOptionsSchema, analyticsPositionListQueryParamsSchema, analyticsPositionListQuerySchema, analyticsPositionPageSchema, analyticsPositionSchema, analyticsPositionSortFieldSchema, analyticsSortDirectionSchema, apyBreakdownSchema, asEstimated, assetTypeSchema, backendPreferred, booleanParamSchema, borrowRateBreakdownSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, compareTagOf, creditAccountFrozen, creditAccountNotEmpty, creditAccountNotFound, creditManagerPaused, curatorNameSchema, curatorSchema, dataSourceSchema, debtOutOfRange, delayedReceivedAssetSchema, encodeFlag, filterAllSchema, filterable, forbiddenToken, instantReceivedAssetSchema, insufficientAllowance, insufficientBalance, insufficientCollateral, insufficientPoolLiquidity, isFilterSet, kycRequirementSchema, leverageOutOfRange, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, liquidatorNotEligible, malformedTransaction, marketExpired, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, multipleDelayedWithdrawals, noDelayedRoute, noRecordedIntent, noStrategyTargetCollateral, notEmergencyLiquidator, offchainOnly, onchainOnly, openingSignerResponseSchema, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, opportunityTotalsSchema, partialLiquidationImpossible, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolOpportunityChartMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPaused, poolPositionChartMetricSchema, poolPositionId, poolPositionKeySchema, poolPositionSchema, poolSunset, positionClaimableWithdrawalSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionId, positionKeySchema, positionKindSchema, positionPendingWithdrawalSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionWithdrawalsSchema, positionsTotalsSchema, priceFeedDataSchema, priceFeedSummarySchema, protocolChartMetricSchema, quotaAboveMax, quotaAssetSchema, quotaCountExceeded, quotaInactive, quotaLimitReached, quotaUnchanged, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, reservePriceLimited, responseMetadataSchema, responseSchema, rewardsPnLSchema, rewardsSchema, rwaOpenRequirementsNotMet, rwaProtocolSchema, safeValue, sdkErr, sdkOk, strategyOpportunityChartMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionChartMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenQuotaRateSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, tolerance, txCallSchema, underlyingTokenSchema, unexpectedFailure, unpriceableTokenError, unsupportedCollateralToken, unsupportedTokenPair, withdrawalInProgress, withdrawalOutputAmountSchema };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isAddress } from "viem";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
|
+
// src/model/openingApproval.schema.ts
|
|
4
|
+
const address = z.custom((v) => typeof v === "string" && isAddress(v));
|
|
5
|
+
const uint32 = z.number().int().min(0).max(4294967295);
|
|
6
|
+
const openingSignerResponseSchema = z.object({
|
|
7
|
+
signer: address,
|
|
8
|
+
degenNFT: address,
|
|
9
|
+
digest: z.custom((v) => typeof v === "string" && /^0x[0-9a-f]{64}$/i.test(v)),
|
|
10
|
+
creditManager: address,
|
|
11
|
+
accountOwner: address,
|
|
12
|
+
deadline: uint32,
|
|
13
|
+
nonce: uint32,
|
|
14
|
+
signature: z.custom((v) => typeof v === "string" && /^0x[0-9a-f]{130}$/i.test(v))
|
|
15
|
+
});
|
|
16
|
+
export { openingSignerResponseSchema };
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { chartBundleSchemaFor, chartQueryCodec } from "../model/charts.schema.js";
|
|
2
2
|
import { responseSchema } from "../model/response.schema.js";
|
|
3
|
-
import { OffchainInvalidJsonError } from "./errors/OffchainInvalidJsonError.js";
|
|
4
3
|
import { OffchainNotConfiguredError } from "./errors/OffchainNotConfiguredError.js";
|
|
5
|
-
import { OffchainRequestFailedError } from "./errors/OffchainRequestFailedError.js";
|
|
6
4
|
import { OffchainStatusError } from "./errors/OffchainStatusError.js";
|
|
7
5
|
import { OffchainValidationError } from "./errors/OffchainValidationError.js";
|
|
8
6
|
import { readResponseBody } from "./errors/readResponseBody.js";
|
|
9
7
|
import "./errors/index.js";
|
|
8
|
+
import { fetchOffchainResponse, readOffchainJson } from "./transport.js";
|
|
10
9
|
import { z } from "zod/v4";
|
|
11
10
|
// src/offchain/AbstractOffchainNamespace.ts
|
|
12
11
|
const DEFAULT_TIMEOUT = 3e4;
|
|
@@ -113,21 +112,12 @@ var AbstractOffchainNamespace = class {
|
|
|
113
112
|
* Body of a successful read, still undecoded.
|
|
114
113
|
**/
|
|
115
114
|
async #fetchJson(url) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
signal: AbortSignal.timeout(this.#timeout)
|
|
121
|
-
});
|
|
122
|
-
} catch (error) {
|
|
123
|
-
throw new OffchainRequestFailedError(url, error);
|
|
124
|
-
}
|
|
115
|
+
const response = await fetchOffchainResponse(url, {
|
|
116
|
+
headers: { accept: "application/json" },
|
|
117
|
+
signal: AbortSignal.timeout(this.#timeout)
|
|
118
|
+
});
|
|
125
119
|
if (!response.ok) throw new OffchainStatusError(url, response.status, await readResponseBody(response));
|
|
126
|
-
|
|
127
|
-
return await response.json();
|
|
128
|
-
} catch (error) {
|
|
129
|
-
throw new OffchainInvalidJsonError(url, response.status, error);
|
|
130
|
-
}
|
|
120
|
+
return readOffchainJson(url, response);
|
|
131
121
|
}
|
|
132
122
|
};
|
|
133
123
|
export { AbstractOffchainNamespace };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { OffchainStatusError } from "./OffchainStatusError.js";
|
|
2
|
+
// src/offchain/errors/OpeningSignerError.ts
|
|
3
|
+
/** A signer refused the HTTP request. Retry-After is measured in seconds. */
|
|
4
|
+
var OpeningSignerError = class extends OffchainStatusError {
|
|
5
|
+
retryAfterSeconds;
|
|
6
|
+
name = "OpeningSignerError";
|
|
7
|
+
static fromStatus(url, status, body, retryAfterSeconds) {
|
|
8
|
+
if (status === 451) return new OpeningSignerDeniedError(url, status, body, retryAfterSeconds);
|
|
9
|
+
if (status === 429 || status === 503) return new OpeningSignerRetryableError(url, status, body, retryAfterSeconds);
|
|
10
|
+
if (status >= 400 && status < 500) return new OpeningSignerRequestError(url, status, body, retryAfterSeconds);
|
|
11
|
+
return new OpeningSignerServiceError(url, status, body, retryAfterSeconds);
|
|
12
|
+
}
|
|
13
|
+
constructor(url, status, body, retryAfterSeconds) {
|
|
14
|
+
super(url, status, body);
|
|
15
|
+
this.retryAfterSeconds = retryAfterSeconds;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
/** The signer denied the owner during screening (451). */
|
|
19
|
+
var OpeningSignerDeniedError = class extends OpeningSignerError {
|
|
20
|
+
name = "OpeningSignerDeniedError";
|
|
21
|
+
};
|
|
22
|
+
/** Rate limiting (429) or temporary unavailability (503). */
|
|
23
|
+
var OpeningSignerRetryableError = class extends OpeningSignerError {
|
|
24
|
+
name = "OpeningSignerRetryableError";
|
|
25
|
+
};
|
|
26
|
+
/** The endpoint rejected the request, for example malformed input or an unsupported market. */
|
|
27
|
+
var OpeningSignerRequestError = class extends OpeningSignerError {
|
|
28
|
+
name = "OpeningSignerRequestError";
|
|
29
|
+
};
|
|
30
|
+
/** An unexpected HTTP response from the signer or its gateway. */
|
|
31
|
+
var OpeningSignerServiceError = class extends OpeningSignerError {
|
|
32
|
+
name = "OpeningSignerServiceError";
|
|
33
|
+
};
|
|
34
|
+
export { OpeningSignerDeniedError, OpeningSignerError, OpeningSignerRequestError, OpeningSignerRetryableError, OpeningSignerServiceError };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/offchain/errors/OpeningSignerQuorumError.ts
|
|
2
|
+
/** Distinct signers did not supply enough approvals for any single digest. */
|
|
3
|
+
var OpeningSignerQuorumError = class extends AggregateError {
|
|
4
|
+
required;
|
|
5
|
+
name = "OpeningSignerQuorumError";
|
|
6
|
+
constructor(causes, required) {
|
|
7
|
+
super(causes, `Opening signers did not return ${required} approvals for the same digest.`);
|
|
8
|
+
this.required = required;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
export { OpeningSignerQuorumError };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseError } from "viem";
|
|
2
|
+
// src/offchain/errors/OpeningSignerVerificationError.ts
|
|
3
|
+
/** A well-formed signer response failed EIP-712 verification or request matching. */
|
|
4
|
+
var OpeningSignerVerificationError = class extends BaseError {
|
|
5
|
+
url;
|
|
6
|
+
signer;
|
|
7
|
+
name = "OpeningSignerVerificationError";
|
|
8
|
+
constructor(url, signer, cause) {
|
|
9
|
+
super("Opening signer response does not match the requested approval.", {
|
|
10
|
+
cause,
|
|
11
|
+
metaMessages: [`URL: ${url}`, `Expected signer: ${signer}`]
|
|
12
|
+
});
|
|
13
|
+
this.url = url;
|
|
14
|
+
this.signer = signer;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export { OpeningSignerVerificationError };
|
|
@@ -7,5 +7,9 @@ import { OffchainRequestFailedError } from "./OffchainRequestFailedError.js";
|
|
|
7
7
|
import { OffchainStatusError } from "./OffchainStatusError.js";
|
|
8
8
|
import { OffchainTransportError } from "./OffchainTransportError.js";
|
|
9
9
|
import { OffchainValidationError } from "./OffchainValidationError.js";
|
|
10
|
+
import { OpeningSignerConfigurationError } from "./OpeningSignerConfigurationError.js";
|
|
11
|
+
import { OpeningSignerDeniedError, OpeningSignerError, OpeningSignerRequestError, OpeningSignerRetryableError, OpeningSignerServiceError } from "./OpeningSignerError.js";
|
|
12
|
+
import { OpeningSignerQuorumError } from "./OpeningSignerQuorumError.js";
|
|
13
|
+
import { OpeningSignerVerificationError } from "./OpeningSignerVerificationError.js";
|
|
10
14
|
import { readResponseBody } from "./readResponseBody.js";
|
|
11
|
-
export { OffchainInvalidJsonError, OffchainNotConfiguredError, OffchainNotImplementedError, OffchainRequestFailedError, OffchainStatusError, OffchainTransportError, OffchainValidationError, backendMessage, errorCause, readResponseBody };
|
|
15
|
+
export { OffchainInvalidJsonError, OffchainNotConfiguredError, OffchainNotImplementedError, OffchainRequestFailedError, OffchainStatusError, OffchainTransportError, OffchainValidationError, OpeningSignerConfigurationError, OpeningSignerDeniedError, OpeningSignerError, OpeningSignerQuorumError, OpeningSignerRequestError, OpeningSignerRetryableError, OpeningSignerServiceError, OpeningSignerVerificationError, backendMessage, errorCause, readResponseBody };
|
|
@@ -7,16 +7,22 @@ import { OffchainNotImplementedError } from "./errors/OffchainNotImplementedErro
|
|
|
7
7
|
import { OffchainRequestFailedError } from "./errors/OffchainRequestFailedError.js";
|
|
8
8
|
import { OffchainStatusError } from "./errors/OffchainStatusError.js";
|
|
9
9
|
import { OffchainValidationError } from "./errors/OffchainValidationError.js";
|
|
10
|
+
import { OpeningSignerConfigurationError } from "./errors/OpeningSignerConfigurationError.js";
|
|
11
|
+
import { OpeningSignerDeniedError, OpeningSignerError, OpeningSignerRequestError, OpeningSignerRetryableError, OpeningSignerServiceError } from "./errors/OpeningSignerError.js";
|
|
12
|
+
import { OpeningSignerQuorumError } from "./errors/OpeningSignerQuorumError.js";
|
|
13
|
+
import { OpeningSignerVerificationError } from "./errors/OpeningSignerVerificationError.js";
|
|
10
14
|
import { readResponseBody } from "./errors/readResponseBody.js";
|
|
11
15
|
import { AbstractOffchainNamespace } from "./AbstractOffchainNamespace.js";
|
|
12
16
|
import "./analytics/index.js";
|
|
13
17
|
import { OffchainAnalyticsPositions } from "./analytics/OffchainAnalyticsPositions.js";
|
|
14
18
|
import { OffchainAnalytics } from "./analytics/OffchainAnalytics.js";
|
|
15
19
|
import "./errors/index.js";
|
|
20
|
+
import { defaultOpeningSignerRegistries } from "./opportunities/openingSignerRegistries.js";
|
|
21
|
+
import { collectOpeningApproval } from "./opportunities/openingApproval.js";
|
|
16
22
|
import { OffchainOpportunities } from "./opportunities/OffchainOpportunities.js";
|
|
17
23
|
import { GearboxAPI } from "./GearboxAPI.js";
|
|
18
24
|
import { OffchainPositions } from "./positions/OffchainPositions.js";
|
|
19
25
|
import "./opportunities/index.js";
|
|
20
26
|
import "./positions/index.js";
|
|
21
27
|
import "./types.js";
|
|
22
|
-
export { AbstractOffchainNamespace, GearboxAPI, OffchainAnalytics, OffchainAnalyticsPositions, OffchainInvalidJsonError, OffchainNotConfiguredError, OffchainNotImplementedError, OffchainOpportunities, OffchainPositions, OffchainRequestFailedError, OffchainStatusError, OffchainTransportError, OffchainValidationError, backendMessage, errorCause, readResponseBody };
|
|
28
|
+
export { AbstractOffchainNamespace, GearboxAPI, OffchainAnalytics, OffchainAnalyticsPositions, OffchainInvalidJsonError, OffchainNotConfiguredError, OffchainNotImplementedError, OffchainOpportunities, OffchainPositions, OffchainRequestFailedError, OffchainStatusError, OffchainTransportError, OffchainValidationError, OpeningSignerConfigurationError, OpeningSignerDeniedError, OpeningSignerError, OpeningSignerQuorumError, OpeningSignerRequestError, OpeningSignerRetryableError, OpeningSignerServiceError, OpeningSignerVerificationError, backendMessage, collectOpeningApproval, defaultOpeningSignerRegistries, errorCause, readResponseBody };
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { opportunityFilterQuerySchema, opportunitySchema, opportunityTotalsSchema, poolOpportunityDetailSchema, strategyOpportunityDetailSchema } from "../../model/opportunities.schema.js";
|
|
2
|
+
import { OpeningSignerConfigurationError } from "../errors/OpeningSignerConfigurationError.js";
|
|
2
3
|
import { AbstractOffchainNamespace } from "../AbstractOffchainNamespace.js";
|
|
4
|
+
import "../errors/index.js";
|
|
5
|
+
import { collectOpeningApproval } from "./openingApproval.js";
|
|
3
6
|
import { z } from "zod/v4";
|
|
4
7
|
// src/offchain/opportunities/OffchainOpportunities.ts
|
|
5
8
|
/**
|
|
@@ -7,8 +10,14 @@ import { z } from "zod/v4";
|
|
|
7
10
|
**/
|
|
8
11
|
var OffchainOpportunities = class extends AbstractOffchainNamespace {
|
|
9
12
|
#root = "/v2/opportunities";
|
|
13
|
+
#options;
|
|
14
|
+
async requestOpeningApproval(requirement) {
|
|
15
|
+
if (!this.#options.chainIds.some((id) => id === requirement.chainId)) throw new OpeningSignerConfigurationError("Opening signer chain is not configured");
|
|
16
|
+
return collectOpeningApproval(requirement, this.#options.openingSignerRegistries, this.#options.timeout);
|
|
17
|
+
}
|
|
10
18
|
constructor(options) {
|
|
11
19
|
super("OffchainOpportunities", options);
|
|
20
|
+
this.#options = options;
|
|
12
21
|
}
|
|
13
22
|
/**
|
|
14
23
|
* {@inheritDoc IOffchainOpportunities.list}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { OffchainOpportunities } from "./OffchainOpportunities.js";
|
|
2
|
+
import { collectOpeningApproval } from "./openingApproval.js";
|
|
3
|
+
import { defaultOpeningSignerRegistries } from "./openingSignerRegistries.js";
|
|
2
4
|
import "./types.js";
|
|
5
|
+
export { OffchainOpportunities, collectOpeningApproval, defaultOpeningSignerRegistries };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { openingSignerResponseSchema } from "../../model/openingApproval.schema.js";
|
|
2
|
+
import { OffchainValidationError } from "../errors/OffchainValidationError.js";
|
|
3
|
+
import { OpeningSignerConfigurationError } from "../errors/OpeningSignerConfigurationError.js";
|
|
4
|
+
import { OpeningSignerError } from "../errors/OpeningSignerError.js";
|
|
5
|
+
import { OpeningSignerQuorumError } from "../errors/OpeningSignerQuorumError.js";
|
|
6
|
+
import { OpeningSignerVerificationError } from "../errors/OpeningSignerVerificationError.js";
|
|
7
|
+
import { readResponseBody } from "../errors/readResponseBody.js";
|
|
8
|
+
import "../errors/index.js";
|
|
9
|
+
import { fetchOffchainResponse, readOffchainJson } from "../transport.js";
|
|
10
|
+
import { defaultOpeningSignerRegistries } from "./openingSignerRegistries.js";
|
|
11
|
+
import { getAddress, hashTypedData, isAddressEqual, recoverAddress } from "viem";
|
|
12
|
+
// src/offchain/opportunities/openingApproval.ts
|
|
13
|
+
const types = { Mint: [
|
|
14
|
+
{
|
|
15
|
+
name: "creditManager",
|
|
16
|
+
type: "address"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: "accountOwner",
|
|
20
|
+
type: "address"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: "deadline",
|
|
24
|
+
type: "uint32"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: "nonce",
|
|
28
|
+
type: "uint32"
|
|
29
|
+
}
|
|
30
|
+
] };
|
|
31
|
+
function wait(ms, signal) {
|
|
32
|
+
signal.throwIfAborted();
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
const abort = () => {
|
|
35
|
+
clearTimeout(timer);
|
|
36
|
+
reject(signal.reason);
|
|
37
|
+
};
|
|
38
|
+
const timer = setTimeout(() => {
|
|
39
|
+
signal.removeEventListener("abort", abort);
|
|
40
|
+
resolve();
|
|
41
|
+
}, ms);
|
|
42
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
async function sign(url, expected, req, signal, timeout) {
|
|
46
|
+
const { chainId, creditManager, accountOwner } = req;
|
|
47
|
+
for (let attempt = 0;; attempt++) {
|
|
48
|
+
const res = await fetchOffchainResponse(url, {
|
|
49
|
+
method: "POST",
|
|
50
|
+
headers: { "Content-Type": "application/json" },
|
|
51
|
+
body: JSON.stringify({
|
|
52
|
+
chainId,
|
|
53
|
+
creditManager: getAddress(creditManager),
|
|
54
|
+
accountOwner: getAddress(accountOwner)
|
|
55
|
+
}),
|
|
56
|
+
signal: AbortSignal.any([signal, AbortSignal.timeout(timeout)])
|
|
57
|
+
});
|
|
58
|
+
if (!res.ok) {
|
|
59
|
+
const raw = res.headers.get("retry-after");
|
|
60
|
+
const seconds = raw !== null && /^\d+$/.test(raw) ? Number(raw) : void 0;
|
|
61
|
+
const error = OpeningSignerError.fromStatus(url, res.status, await readResponseBody(res), seconds);
|
|
62
|
+
const delay = seconds ?? 1;
|
|
63
|
+
if (res.status !== 503 || attempt === 1 || delay > 300) throw error;
|
|
64
|
+
await wait(delay * 1e3, signal);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const parsed = openingSignerResponseSchema.safeParse(await readOffchainJson(url, res));
|
|
68
|
+
if (!parsed.success) throw new OffchainValidationError(url, parsed.error);
|
|
69
|
+
await verifyResponse(url, parsed.data, expected, req);
|
|
70
|
+
return parsed.data;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async function verifyResponse(url, response, expected, req) {
|
|
74
|
+
const { creditManager, accountOwner, chainId } = req;
|
|
75
|
+
const message = {
|
|
76
|
+
creditManager,
|
|
77
|
+
accountOwner,
|
|
78
|
+
nonce: response.nonce,
|
|
79
|
+
deadline: response.deadline
|
|
80
|
+
};
|
|
81
|
+
const digest = hashTypedData({
|
|
82
|
+
domain: {
|
|
83
|
+
name: "SignatureDegenNFT",
|
|
84
|
+
version: "3_10",
|
|
85
|
+
chainId,
|
|
86
|
+
verifyingContract: req.degenNFT
|
|
87
|
+
},
|
|
88
|
+
primaryType: "Mint",
|
|
89
|
+
types,
|
|
90
|
+
message
|
|
91
|
+
});
|
|
92
|
+
if (!isAddressEqual(response.creditManager, creditManager) || !isAddressEqual(response.accountOwner, accountOwner) || !isAddressEqual(response.degenNFT, req.degenNFT) || !isAddressEqual(response.signer, expected) || response.nonce !== req.nonce || response.deadline < Math.floor(Date.now() / 1e3) || digest !== response.digest.toLowerCase()) throw new OpeningSignerVerificationError(url, expected);
|
|
93
|
+
let recovered;
|
|
94
|
+
try {
|
|
95
|
+
recovered = await recoverAddress({
|
|
96
|
+
hash: digest,
|
|
97
|
+
signature: response.signature
|
|
98
|
+
});
|
|
99
|
+
} catch (cause) {
|
|
100
|
+
throw new OpeningSignerVerificationError(url, expected, cause instanceof Error ? cause : void 0);
|
|
101
|
+
}
|
|
102
|
+
if (!isAddressEqual(recovered, expected)) throw new OpeningSignerVerificationError(url, expected);
|
|
103
|
+
}
|
|
104
|
+
async function collectOpeningApproval(req, registries = defaultOpeningSignerRegistries, timeout = 3e4) {
|
|
105
|
+
const eligible = /* @__PURE__ */ new Map();
|
|
106
|
+
for (const registry of registries) {
|
|
107
|
+
if (registry.chainId !== req.chainId || !isAddressEqual(registry.marketConfigurator, req.marketConfigurator)) continue;
|
|
108
|
+
for (const signer of registry.signers) if (req.authorizedSigners.some((a) => isAddressEqual(a, signer.address))) eligible.set(getAddress(signer.address), signer.url);
|
|
109
|
+
}
|
|
110
|
+
if (req.minSignaturesRequired < 1 || eligible.size < req.minSignaturesRequired) throw new OpeningSignerConfigurationError("Insufficient configured authorized opening signers");
|
|
111
|
+
const controller = new AbortController();
|
|
112
|
+
const groups = /* @__PURE__ */ new Map();
|
|
113
|
+
try {
|
|
114
|
+
return await new Promise((resolve, reject) => {
|
|
115
|
+
let pending = eligible.size;
|
|
116
|
+
const failures = [];
|
|
117
|
+
for (const [expected, url] of eligible) sign(url, expected, req, controller.signal, timeout).then(({ digest, signer, degenNFT: _degenNFT, ...entry }) => {
|
|
118
|
+
const key = digest.toLowerCase();
|
|
119
|
+
const group = groups.get(key) ?? /* @__PURE__ */ new Map();
|
|
120
|
+
group.set(signer, entry);
|
|
121
|
+
groups.set(key, group);
|
|
122
|
+
if (group.size === req.minSignaturesRequired) {
|
|
123
|
+
const signatures = [...group].sort(([a], [b]) => BigInt(a) < BigInt(b) ? -1 : 1).map(([, e]) => e);
|
|
124
|
+
resolve({
|
|
125
|
+
chainId: req.chainId,
|
|
126
|
+
degenNFT: req.degenNFT,
|
|
127
|
+
signatures
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}).catch((error) => {
|
|
131
|
+
failures.push(error);
|
|
132
|
+
}).finally(() => {
|
|
133
|
+
if (--pending === 0) reject(failures.length === 1 && eligible.size === 1 ? failures[0] : new OpeningSignerQuorumError(failures, req.minSignaturesRequired));
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
} finally {
|
|
137
|
+
controller.abort();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
export { collectOpeningApproval };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/offchain/opportunities/openingSignerRegistries.ts
|
|
2
|
+
/** Default endpoints for ACL-authorized opening signers, grouped by market configurator. */
|
|
3
|
+
const defaultOpeningSignerRegistries = [{
|
|
4
|
+
chainId: 1,
|
|
5
|
+
marketConfigurator: "0x1b265b97eb169fb6668e3258007c3b0242c7bdbe",
|
|
6
|
+
signers: [{
|
|
7
|
+
address: "0x25a116142fE62a9aCE9AeeF09AF1857de44DCd29",
|
|
8
|
+
url: "https://signer.gear-dev.dev/sign"
|
|
9
|
+
}]
|
|
10
|
+
}];
|
|
11
|
+
export { defaultOpeningSignerRegistries };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { OffchainInvalidJsonError } from "./errors/OffchainInvalidJsonError.js";
|
|
2
|
+
import { OffchainRequestFailedError } from "./errors/OffchainRequestFailedError.js";
|
|
3
|
+
import "./errors/index.js";
|
|
4
|
+
// src/offchain/transport.ts
|
|
5
|
+
async function fetchOffchainResponse(url, init) {
|
|
6
|
+
try {
|
|
7
|
+
return await fetch(url, init);
|
|
8
|
+
} catch (cause) {
|
|
9
|
+
throw new OffchainRequestFailedError(url, cause);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
async function readOffchainJson(url, response) {
|
|
13
|
+
try {
|
|
14
|
+
return await response.json();
|
|
15
|
+
} catch (cause) {
|
|
16
|
+
throw new OffchainInvalidJsonError(url, response.status, cause);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export { fetchOffchainResponse, readOffchainJson };
|