@gearbox-protocol/sdk 16.6.0-next.5 → 16.6.0-next.7
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/dev/index.js +4 -2
- package/dist/cjs/dev/kycUtils.js +15 -17
- package/dist/cjs/dev/midasUtils.js +41 -14
- package/dist/cjs/onchain/accounts/intents/operations.js +0 -1
- package/dist/cjs/onchain/accounts/intents/utils/router-path.js +4 -5
- package/dist/esm/dev/index.js +3 -3
- package/dist/esm/dev/kycUtils.js +16 -19
- package/dist/esm/dev/midasUtils.js +39 -13
- package/dist/esm/onchain/accounts/intents/operations.js +0 -1
- package/dist/esm/onchain/accounts/intents/utils/router-path.js +4 -5
- package/dist/types/dev/index.d.ts +3 -3
- package/dist/types/dev/kycUtils.d.ts +8 -2
- package/dist/types/dev/midasUtils.d.ts +21 -5
- package/dist/types/onchain/accounts/intents/utils/router-path.d.ts +2 -5
- package/package.json +1 -1
package/dist/cjs/dev/index.js
CHANGED
|
@@ -29,6 +29,7 @@ const require_dev_withdrawalUtils = require("./withdrawalUtils.js");
|
|
|
29
29
|
exports.AccountOpener = require_dev_AccountOpener.AccountOpener;
|
|
30
30
|
exports.Create2Deployer = require_dev_create2.Create2Deployer;
|
|
31
31
|
exports.DEFAULT_CREATE2_SALT = require_dev_create2.DEFAULT_CREATE2_SALT;
|
|
32
|
+
exports.DEFAULT_MIDAS_ADMIN = require_dev_kycUtils.DEFAULT_MIDAS_ADMIN;
|
|
32
33
|
exports.EthCallSpy = require_dev_EthCallSpy.EthCallSpy;
|
|
33
34
|
exports.NoAvailableTransportsError = require_dev_RevolverTransport.NoAvailableTransportsError;
|
|
34
35
|
exports.ONCHAIN_EXECUTION_ID_ADDRESS = require_dev_verifyTestnet.ONCHAIN_EXECUTION_ID_ADDRESS;
|
|
@@ -42,12 +43,13 @@ exports.calcLiquidatableLTs = require_dev_calcLiquidatableLTs.calcLiquidatableLT
|
|
|
42
43
|
exports.claimDSToken = require_dev_securitizeUtils.claimDSToken;
|
|
43
44
|
exports.claimDSTokens = require_dev_securitizeUtils.claimDSTokens;
|
|
44
45
|
exports.claimFromFaucet = require_dev_claimFromFaucet.claimFromFaucet;
|
|
45
|
-
exports.collectMidasGateways = require_dev_midasUtils.collectMidasGateways;
|
|
46
|
-
exports.collectMidasMTokens = require_dev_midasUtils.collectMidasMTokens;
|
|
47
46
|
exports.createAnvilClient = require_dev_createAnvilClient.createAnvilClient;
|
|
48
47
|
exports.createMinter = require_dev_mint_factory.createMinter;
|
|
49
48
|
exports.deployUsingPublicCreate2 = require_dev_create2.deployUsingPublicCreate2;
|
|
50
49
|
exports.detectChain = require_dev_detectChain.detectChain;
|
|
50
|
+
exports.discoverMidasCreditSuites = require_dev_midasUtils.discoverMidasCreditSuites;
|
|
51
|
+
exports.discoverMidasGateways = require_dev_midasUtils.discoverMidasGateways;
|
|
52
|
+
exports.discoverMidasMTokens = require_dev_midasUtils.discoverMidasMTokens;
|
|
51
53
|
exports.enableDSTokenBackDating = require_dev_securitizeUtils.enableDSTokenBackDating;
|
|
52
54
|
exports.evmMineDetailed = require_dev_createAnvilClient.evmMineDetailed;
|
|
53
55
|
exports.extendAnvilClient = require_dev_createAnvilClient.extendAnvilClient;
|
package/dist/cjs/dev/kycUtils.js
CHANGED
|
@@ -290,8 +290,7 @@ async function greenlistMidasGateway(props) {
|
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
/**
|
|
293
|
-
* Finds the Midas gateway that issues `token`
|
|
294
|
-
* adapters of all loaded credit managers and the gateways of Midas degen NFTs
|
|
293
|
+
* Finds the Midas gateway that issues `token` among the loaded credit managers.
|
|
295
294
|
*/
|
|
296
295
|
async function findMidasGateway(props) {
|
|
297
296
|
const { anvil, token, marketConfigurators, logger } = props;
|
|
@@ -303,21 +302,19 @@ async function findMidasGateway(props) {
|
|
|
303
302
|
});
|
|
304
303
|
await sdk.attach({ marketConfigurators });
|
|
305
304
|
}
|
|
306
|
-
const
|
|
307
|
-
if (
|
|
308
|
-
const
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
abi: require_dev_withdrawalAbi.midasGatewayAbi,
|
|
313
|
-
functionName: "mToken"
|
|
314
|
-
}))
|
|
315
|
-
})).findIndex((mToken) => (0, viem.isAddressEqual)(mToken, token));
|
|
316
|
-
if (index === -1) throw new Error(`no midas gateway found for token ${token}`);
|
|
317
|
-
logger?.debug(`midas: gateway for ${token} is ${candidates[index]}`);
|
|
318
|
-
return candidates[index];
|
|
305
|
+
const suites = await require_dev_midasUtils.discoverMidasCreditSuites(sdk);
|
|
306
|
+
if (suites.length === 0) throw new Error("no midas gateway adapters or midas degen NFTs found in loaded markets");
|
|
307
|
+
const suite = suites.find(({ mToken }) => (0, viem.isAddressEqual)(mToken, token));
|
|
308
|
+
if (!suite) throw new Error(`no midas gateway found for token ${token}`);
|
|
309
|
+
logger?.debug(`midas: gateway for ${token} is ${suite.gateway}`);
|
|
310
|
+
return suite.gateway;
|
|
319
311
|
}
|
|
320
312
|
/**
|
|
313
|
+
* Midas access control admin on mainnet. Holds the admin role of the greenlist
|
|
314
|
+
* operator role.
|
|
315
|
+
*/
|
|
316
|
+
const DEFAULT_MIDAS_ADMIN = "0xd4195CF4df289a4748C1A7B6dDBE770e27bA1227";
|
|
317
|
+
/**
|
|
321
318
|
* Registers a wallet as an investor (fake KYC) in every Securitize DSToken and
|
|
322
319
|
* every Midas gateway of the markets loaded by `sdk`.
|
|
323
320
|
*
|
|
@@ -325,7 +322,7 @@ async function findMidasGateway(props) {
|
|
|
325
322
|
* result instead of aborting the whole run.
|
|
326
323
|
*/
|
|
327
324
|
async function registerRWAInvestor(props) {
|
|
328
|
-
const { anvil, sdk, investor, midasAdmin =
|
|
325
|
+
const { anvil, sdk, investor, midasAdmin = DEFAULT_MIDAS_ADMIN, logger } = props;
|
|
329
326
|
const securitizeTokens = [];
|
|
330
327
|
const midasGateways = [];
|
|
331
328
|
const failed = [];
|
|
@@ -346,7 +343,7 @@ async function registerRWAInvestor(props) {
|
|
|
346
343
|
error: e
|
|
347
344
|
});
|
|
348
345
|
}
|
|
349
|
-
const gateways = await require_dev_midasUtils.
|
|
346
|
+
const gateways = await require_dev_midasUtils.discoverMidasGateways(sdk);
|
|
350
347
|
for (const gateway of gateways) try {
|
|
351
348
|
await greenlistMidasGateway({
|
|
352
349
|
anvil,
|
|
@@ -372,6 +369,7 @@ async function registerRWAInvestor(props) {
|
|
|
372
369
|
};
|
|
373
370
|
}
|
|
374
371
|
//#endregion
|
|
372
|
+
exports.DEFAULT_MIDAS_ADMIN = DEFAULT_MIDAS_ADMIN;
|
|
375
373
|
exports.getSecuritizeAdmin = getSecuritizeAdmin;
|
|
376
374
|
exports.greenlistMidasGateway = greenlistMidasGateway;
|
|
377
375
|
exports.registerMidasInvestor = registerMidasInvestor;
|
|
@@ -147,29 +147,56 @@ async function unpauseMidasIssuanceVault(props) {
|
|
|
147
147
|
}
|
|
148
148
|
};
|
|
149
149
|
}
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
/**
|
|
151
|
+
* Midas credit suites of the loaded credit managers.
|
|
152
|
+
*
|
|
153
|
+
* A manager with a gateway adapter is a suite on its own, so its degen NFT
|
|
154
|
+
* is not consulted. Suites that only have a Midas degen NFT read `mToken`
|
|
155
|
+
* from the gateway.
|
|
156
|
+
*/
|
|
157
|
+
async function discoverMidasCreditSuites(sdk) {
|
|
158
|
+
const suites = [];
|
|
159
|
+
for (const cm of sdk.marketRegister.creditManagers) {
|
|
160
|
+
const creditManager = cm.creditManager.address;
|
|
161
|
+
let hasAdapter = false;
|
|
162
|
+
for (const adapter of cm.creditManager.adapters.values()) if (adapter instanceof require_onchain_market_adapters_contracts_MidasGatewayAdapterContract.MidasGatewayAdapterContract) {
|
|
163
|
+
hasAdapter = true;
|
|
164
|
+
suites.push({
|
|
165
|
+
creditManager,
|
|
166
|
+
gateway: adapter.gateway,
|
|
167
|
+
mToken: adapter.mToken
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
if (hasAdapter) continue;
|
|
171
|
+
const nft = await cm.degenNFT();
|
|
172
|
+
if (nft instanceof require_onchain_market_rwa_midas_MidasDegenNFT.MidasDegenNFT) {
|
|
173
|
+
const [mToken] = await nft.getTokens();
|
|
174
|
+
suites.push({
|
|
175
|
+
creditManager,
|
|
176
|
+
gateway: nft.gateway,
|
|
177
|
+
mToken
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return suites;
|
|
152
182
|
}
|
|
153
183
|
/**
|
|
154
|
-
*
|
|
155
|
-
* plus gateways of Midas degen NFTs (permissioned-mode suites with no gateway adapter).
|
|
184
|
+
* Gateways of the Midas credit suites of the loaded credit managers.
|
|
156
185
|
*/
|
|
157
|
-
async function
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
const nfts = await Promise.all(sdk.marketRegister.creditManagers.map((cm) => cm.degenNFT()));
|
|
161
|
-
for (const nft of nfts) if (nft instanceof require_onchain_market_rwa_midas_MidasDegenNFT.MidasDegenNFT) gateways.add(nft.gateway);
|
|
162
|
-
return gateways.asArray();
|
|
186
|
+
async function discoverMidasGateways(sdk) {
|
|
187
|
+
const suites = await discoverMidasCreditSuites(sdk);
|
|
188
|
+
return new require_onchain_utils_AddressSet.AddressSet(suites.map((suite) => suite.gateway)).asArray();
|
|
163
189
|
}
|
|
164
190
|
/**
|
|
165
191
|
* mTokens of all Midas gateway adapters of the loaded credit managers
|
|
166
192
|
*/
|
|
167
|
-
function
|
|
193
|
+
function discoverMidasMTokens(sdk) {
|
|
168
194
|
const mTokens = new require_onchain_utils_AddressSet.AddressSet();
|
|
169
|
-
for (const adapter of
|
|
195
|
+
for (const cm of sdk.marketRegister.creditManagers) for (const adapter of cm.creditManager.adapters.values()) if (adapter instanceof require_onchain_market_adapters_contracts_MidasGatewayAdapterContract.MidasGatewayAdapterContract) mTokens.add(adapter.mToken);
|
|
170
196
|
return mTokens.asArray();
|
|
171
197
|
}
|
|
172
198
|
//#endregion
|
|
173
|
-
exports.
|
|
174
|
-
exports.
|
|
199
|
+
exports.discoverMidasCreditSuites = discoverMidasCreditSuites;
|
|
200
|
+
exports.discoverMidasGateways = discoverMidasGateways;
|
|
201
|
+
exports.discoverMidasMTokens = discoverMidasMTokens;
|
|
175
202
|
exports.unpauseMidasIssuanceVault = unpauseMidasIssuanceVault;
|
|
@@ -3,11 +3,8 @@ const require_onchain_accounts_intents_utils_common = require("./common.js");
|
|
|
3
3
|
const require_onchain_accounts_intents_utils_price_impact = require("./price-impact.js");
|
|
4
4
|
//#region src/onchain/accounts/intents/utils/router-path.ts
|
|
5
5
|
/**
|
|
6
|
-
* The engine's only door to the pathfinder
|
|
7
|
-
*
|
|
8
|
-
* Deliberately not a quoter abstraction with an oracle-priced twin: paths are
|
|
9
|
-
* always resolved on-chain, because a preview whose swap amounts came from
|
|
10
|
-
* oracle prices could not produce the calldata that realises them.
|
|
6
|
+
* The engine's only door to the pathfinder, and the only quoter whose legs can
|
|
7
|
+
* be sent. {@link createOraclePaths} is the twin for a walk that only projects.
|
|
11
8
|
*/
|
|
12
9
|
function createRouterPaths(args) {
|
|
13
10
|
const { sdk, creditAccount, slippage } = args;
|
|
@@ -92,6 +89,7 @@ function createRouterPaths(args) {
|
|
|
92
89
|
amount,
|
|
93
90
|
keep
|
|
94
91
|
});
|
|
92
|
+
if (leg.calls.length === 0) throw new Error("swap: missing router calls");
|
|
95
93
|
return {
|
|
96
94
|
...leg,
|
|
97
95
|
probe: probe && {
|
|
@@ -108,6 +106,7 @@ function createRouterPaths(args) {
|
|
|
108
106
|
route: async (quoted) => (await quoteClose(quoted)).amount
|
|
109
107
|
});
|
|
110
108
|
const { amount, minAmount, calls } = await quoteClose(balances);
|
|
109
|
+
if (calls.length === 0 && minAmount > 0n) throw new Error("closeAll: missing router calls");
|
|
111
110
|
const leg = {
|
|
112
111
|
amount,
|
|
113
112
|
minAmount,
|
package/dist/esm/dev/index.js
CHANGED
|
@@ -13,8 +13,8 @@ import { detectChain } from "./detectChain.js";
|
|
|
13
13
|
import { isOutOfSyncError } from "./isOutOfSyncError.js";
|
|
14
14
|
import { isRateLimitError } from "./isRateLimitError.js";
|
|
15
15
|
import { isTransientError } from "./isTransientError.js";
|
|
16
|
-
import {
|
|
17
|
-
import { getSecuritizeAdmin, greenlistMidasGateway, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor } from "./kycUtils.js";
|
|
16
|
+
import { discoverMidasCreditSuites, discoverMidasGateways, discoverMidasMTokens, unpauseMidasIssuanceVault } from "./midasUtils.js";
|
|
17
|
+
import { DEFAULT_MIDAS_ADMIN, getSecuritizeAdmin, greenlistMidasGateway, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor } from "./kycUtils.js";
|
|
18
18
|
import { isRangeError, logSplitterTransport } from "./logSplitterTransport.js";
|
|
19
19
|
import { setLTZero, setLTs } from "./ltUtils.js";
|
|
20
20
|
import { migrateFaucet } from "./migrateFaucet.js";
|
|
@@ -25,4 +25,4 @@ import { claimDSToken, claimDSTokens, enableDSTokenBackDating } from "./securiti
|
|
|
25
25
|
import "./types.js";
|
|
26
26
|
import { ONCHAIN_EXECUTION_ID_ADDRESS, verifyTestnet } from "./verifyTestnet.js";
|
|
27
27
|
import { makePendingWithdrawalsClaimable } from "./withdrawalUtils.js";
|
|
28
|
-
export { AccountOpener, Create2Deployer, DEFAULT_CREATE2_SALT, EthCallSpy, NoAvailableTransportsError, ONCHAIN_EXECUTION_ID_ADDRESS, OpenTxRevertedError, PUBLIC_CREATE2_FACTORY, RevolverTransport, SUPPORTED_RPC_PROVIDERS, SelectionStrategy, anvilNodeInfo, calcLiquidatableLTs, claimDSToken, claimDSTokens, claimFromFaucet,
|
|
28
|
+
export { AccountOpener, Create2Deployer, DEFAULT_CREATE2_SALT, DEFAULT_MIDAS_ADMIN, EthCallSpy, NoAvailableTransportsError, ONCHAIN_EXECUTION_ID_ADDRESS, OpenTxRevertedError, PUBLIC_CREATE2_FACTORY, RevolverTransport, SUPPORTED_RPC_PROVIDERS, SelectionStrategy, anvilNodeInfo, calcLiquidatableLTs, claimDSToken, claimDSTokens, claimFromFaucet, createAnvilClient, createMinter, deployUsingPublicCreate2, detectChain, discoverMidasCreditSuites, discoverMidasGateways, discoverMidasMTokens, enableDSTokenBackDating, evmMineDetailed, extendAnvilClient, getAlchemyUrl, getAnkrUrl, getDrpcUrl, getErpcKey, getPublicCreate2Address, getRpcProviderUrl, getSecuritizeAdmin, getThirdWebUrl, greenlistMidasGateway, httpTransportOptionsSchema, iDegenNftv2Abi, iFaucetAbi, iOnchainExecutionIdAbi, iOwnableAbi, iaclTraitAbi, isAnvil, isDeployedUsingPublicCreate2, isOutOfSyncError, isRangeError, isRateLimitError, isTransientError, logSplitterTransport, makePendingWithdrawalsClaimable, migrateFaucet, providerConfigSchema, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor, replaceStorage, resilientTransport, resilientTransportOptionsSchema, revolverTransportConfigBaseSchema, revolverTransportConfigSchema, rpcProvidersSchema, setLTZero, setLTs, unpauseMidasIssuanceVault, verifyTestnet, writeContractSync };
|
package/dist/esm/dev/kycUtils.js
CHANGED
|
@@ -4,7 +4,7 @@ import { OnchainSDK } from "../onchain/OnchainSDK.js";
|
|
|
4
4
|
import "../onchain/index.js";
|
|
5
5
|
import { iDSRegistryServiceAbi } from "../abi/rwa/iDSRegistryService.js";
|
|
6
6
|
import { iDSTokenAbi } from "../abi/rwa/iDSToken.js";
|
|
7
|
-
import {
|
|
7
|
+
import { discoverMidasCreditSuites, discoverMidasGateways } from "./midasUtils.js";
|
|
8
8
|
import { midasGatewayAbi } from "./withdrawalAbi.js";
|
|
9
9
|
import { getAddress, isAddressEqual, parseAbi, parseEther, slice, toHex, zeroAddress } from "viem";
|
|
10
10
|
//#region src/dev/kycUtils.ts
|
|
@@ -289,8 +289,7 @@ async function greenlistMidasGateway(props) {
|
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
291
|
/**
|
|
292
|
-
* Finds the Midas gateway that issues `token`
|
|
293
|
-
* adapters of all loaded credit managers and the gateways of Midas degen NFTs
|
|
292
|
+
* Finds the Midas gateway that issues `token` among the loaded credit managers.
|
|
294
293
|
*/
|
|
295
294
|
async function findMidasGateway(props) {
|
|
296
295
|
const { anvil, token, marketConfigurators, logger } = props;
|
|
@@ -302,21 +301,19 @@ async function findMidasGateway(props) {
|
|
|
302
301
|
});
|
|
303
302
|
await sdk.attach({ marketConfigurators });
|
|
304
303
|
}
|
|
305
|
-
const
|
|
306
|
-
if (
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
abi: midasGatewayAbi,
|
|
312
|
-
functionName: "mToken"
|
|
313
|
-
}))
|
|
314
|
-
})).findIndex((mToken) => isAddressEqual(mToken, token));
|
|
315
|
-
if (index === -1) throw new Error(`no midas gateway found for token ${token}`);
|
|
316
|
-
logger?.debug(`midas: gateway for ${token} is ${candidates[index]}`);
|
|
317
|
-
return candidates[index];
|
|
304
|
+
const suites = await discoverMidasCreditSuites(sdk);
|
|
305
|
+
if (suites.length === 0) throw new Error("no midas gateway adapters or midas degen NFTs found in loaded markets");
|
|
306
|
+
const suite = suites.find(({ mToken }) => isAddressEqual(mToken, token));
|
|
307
|
+
if (!suite) throw new Error(`no midas gateway found for token ${token}`);
|
|
308
|
+
logger?.debug(`midas: gateway for ${token} is ${suite.gateway}`);
|
|
309
|
+
return suite.gateway;
|
|
318
310
|
}
|
|
319
311
|
/**
|
|
312
|
+
* Midas access control admin on mainnet. Holds the admin role of the greenlist
|
|
313
|
+
* operator role.
|
|
314
|
+
*/
|
|
315
|
+
const DEFAULT_MIDAS_ADMIN = "0xd4195CF4df289a4748C1A7B6dDBE770e27bA1227";
|
|
316
|
+
/**
|
|
320
317
|
* Registers a wallet as an investor (fake KYC) in every Securitize DSToken and
|
|
321
318
|
* every Midas gateway of the markets loaded by `sdk`.
|
|
322
319
|
*
|
|
@@ -324,7 +321,7 @@ async function findMidasGateway(props) {
|
|
|
324
321
|
* result instead of aborting the whole run.
|
|
325
322
|
*/
|
|
326
323
|
async function registerRWAInvestor(props) {
|
|
327
|
-
const { anvil, sdk, investor, midasAdmin =
|
|
324
|
+
const { anvil, sdk, investor, midasAdmin = DEFAULT_MIDAS_ADMIN, logger } = props;
|
|
328
325
|
const securitizeTokens = [];
|
|
329
326
|
const midasGateways = [];
|
|
330
327
|
const failed = [];
|
|
@@ -345,7 +342,7 @@ async function registerRWAInvestor(props) {
|
|
|
345
342
|
error: e
|
|
346
343
|
});
|
|
347
344
|
}
|
|
348
|
-
const gateways = await
|
|
345
|
+
const gateways = await discoverMidasGateways(sdk);
|
|
349
346
|
for (const gateway of gateways) try {
|
|
350
347
|
await greenlistMidasGateway({
|
|
351
348
|
anvil,
|
|
@@ -371,4 +368,4 @@ async function registerRWAInvestor(props) {
|
|
|
371
368
|
};
|
|
372
369
|
}
|
|
373
370
|
//#endregion
|
|
374
|
-
export { getSecuritizeAdmin, greenlistMidasGateway, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor };
|
|
371
|
+
export { DEFAULT_MIDAS_ADMIN, getSecuritizeAdmin, greenlistMidasGateway, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor };
|
|
@@ -146,27 +146,53 @@ async function unpauseMidasIssuanceVault(props) {
|
|
|
146
146
|
}
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
/**
|
|
150
|
+
* Midas credit suites of the loaded credit managers.
|
|
151
|
+
*
|
|
152
|
+
* A manager with a gateway adapter is a suite on its own, so its degen NFT
|
|
153
|
+
* is not consulted. Suites that only have a Midas degen NFT read `mToken`
|
|
154
|
+
* from the gateway.
|
|
155
|
+
*/
|
|
156
|
+
async function discoverMidasCreditSuites(sdk) {
|
|
157
|
+
const suites = [];
|
|
158
|
+
for (const cm of sdk.marketRegister.creditManagers) {
|
|
159
|
+
const creditManager = cm.creditManager.address;
|
|
160
|
+
let hasAdapter = false;
|
|
161
|
+
for (const adapter of cm.creditManager.adapters.values()) if (adapter instanceof MidasGatewayAdapterContract) {
|
|
162
|
+
hasAdapter = true;
|
|
163
|
+
suites.push({
|
|
164
|
+
creditManager,
|
|
165
|
+
gateway: adapter.gateway,
|
|
166
|
+
mToken: adapter.mToken
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
if (hasAdapter) continue;
|
|
170
|
+
const nft = await cm.degenNFT();
|
|
171
|
+
if (nft instanceof MidasDegenNFT) {
|
|
172
|
+
const [mToken] = await nft.getTokens();
|
|
173
|
+
suites.push({
|
|
174
|
+
creditManager,
|
|
175
|
+
gateway: nft.gateway,
|
|
176
|
+
mToken
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return suites;
|
|
151
181
|
}
|
|
152
182
|
/**
|
|
153
|
-
*
|
|
154
|
-
* plus gateways of Midas degen NFTs (permissioned-mode suites with no gateway adapter).
|
|
183
|
+
* Gateways of the Midas credit suites of the loaded credit managers.
|
|
155
184
|
*/
|
|
156
|
-
async function
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
const nfts = await Promise.all(sdk.marketRegister.creditManagers.map((cm) => cm.degenNFT()));
|
|
160
|
-
for (const nft of nfts) if (nft instanceof MidasDegenNFT) gateways.add(nft.gateway);
|
|
161
|
-
return gateways.asArray();
|
|
185
|
+
async function discoverMidasGateways(sdk) {
|
|
186
|
+
const suites = await discoverMidasCreditSuites(sdk);
|
|
187
|
+
return new AddressSet(suites.map((suite) => suite.gateway)).asArray();
|
|
162
188
|
}
|
|
163
189
|
/**
|
|
164
190
|
* mTokens of all Midas gateway adapters of the loaded credit managers
|
|
165
191
|
*/
|
|
166
|
-
function
|
|
192
|
+
function discoverMidasMTokens(sdk) {
|
|
167
193
|
const mTokens = new AddressSet();
|
|
168
|
-
for (const adapter of
|
|
194
|
+
for (const cm of sdk.marketRegister.creditManagers) for (const adapter of cm.creditManager.adapters.values()) if (adapter instanceof MidasGatewayAdapterContract) mTokens.add(adapter.mToken);
|
|
169
195
|
return mTokens.asArray();
|
|
170
196
|
}
|
|
171
197
|
//#endregion
|
|
172
|
-
export {
|
|
198
|
+
export { discoverMidasCreditSuites, discoverMidasGateways, discoverMidasMTokens, unpauseMidasIssuanceVault };
|
|
@@ -2,11 +2,8 @@ import { toRouterCaSlice } from "./common.js";
|
|
|
2
2
|
import { startProbe } from "./price-impact.js";
|
|
3
3
|
//#region src/onchain/accounts/intents/utils/router-path.ts
|
|
4
4
|
/**
|
|
5
|
-
* The engine's only door to the pathfinder
|
|
6
|
-
*
|
|
7
|
-
* Deliberately not a quoter abstraction with an oracle-priced twin: paths are
|
|
8
|
-
* always resolved on-chain, because a preview whose swap amounts came from
|
|
9
|
-
* oracle prices could not produce the calldata that realises them.
|
|
5
|
+
* The engine's only door to the pathfinder, and the only quoter whose legs can
|
|
6
|
+
* be sent. {@link createOraclePaths} is the twin for a walk that only projects.
|
|
10
7
|
*/
|
|
11
8
|
function createRouterPaths(args) {
|
|
12
9
|
const { sdk, creditAccount, slippage } = args;
|
|
@@ -91,6 +88,7 @@ function createRouterPaths(args) {
|
|
|
91
88
|
amount,
|
|
92
89
|
keep
|
|
93
90
|
});
|
|
91
|
+
if (leg.calls.length === 0) throw new Error("swap: missing router calls");
|
|
94
92
|
return {
|
|
95
93
|
...leg,
|
|
96
94
|
probe: probe && {
|
|
@@ -107,6 +105,7 @@ function createRouterPaths(args) {
|
|
|
107
105
|
route: async (quoted) => (await quoteClose(quoted)).amount
|
|
108
106
|
});
|
|
109
107
|
const { amount, minAmount, calls } = await quoteClose(balances);
|
|
108
|
+
if (calls.length === 0 && minAmount > 0n) throw new Error("closeAll: missing router calls");
|
|
110
109
|
const leg = {
|
|
111
110
|
amount,
|
|
112
111
|
minAmount,
|
|
@@ -11,10 +11,10 @@ import { detectChain } from "./detectChain.js";
|
|
|
11
11
|
import { isOutOfSyncError } from "./isOutOfSyncError.js";
|
|
12
12
|
import { isRateLimitError } from "./isRateLimitError.js";
|
|
13
13
|
import { isTransientError } from "./isTransientError.js";
|
|
14
|
-
import { GreenlistMidasGatewayProps, RWAKycFailure, RegisterMidasInvestorProps, RegisterRWAInvestorProps, RegisterRWAInvestorResult, RegisterSecuritizeInvestorProps, getSecuritizeAdmin, greenlistMidasGateway, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor } from "./kycUtils.js";
|
|
14
|
+
import { DEFAULT_MIDAS_ADMIN, GreenlistMidasGatewayProps, RWAKycFailure, RegisterMidasInvestorProps, RegisterRWAInvestorProps, RegisterRWAInvestorResult, RegisterSecuritizeInvestorProps, getSecuritizeAdmin, greenlistMidasGateway, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor } from "./kycUtils.js";
|
|
15
15
|
import { LogSplitterTransportOptions, isRangeError, logSplitterTransport } from "./logSplitterTransport.js";
|
|
16
16
|
import { setLTZero, setLTs } from "./ltUtils.js";
|
|
17
|
-
import { RestoreMidasIssuanceVaultPause, UnpauseMidasIssuanceVaultProps,
|
|
17
|
+
import { MidasCreditSuite, RestoreMidasIssuanceVaultPause, UnpauseMidasIssuanceVaultProps, discoverMidasCreditSuites, discoverMidasGateways, discoverMidasMTokens, unpauseMidasIssuanceVault } from "./midasUtils.js";
|
|
18
18
|
import { migrateFaucet } from "./migrateFaucet.js";
|
|
19
19
|
import { IMinter } from "./mint/types.js";
|
|
20
20
|
import { createMinter } from "./mint/factory.js";
|
|
@@ -26,4 +26,4 @@ import { EnableDSTokenBackDatingProps, RestoreDSTokenBackDating, claimDSToken, c
|
|
|
26
26
|
import { httpTransportOptionsSchema } from "./transports.js";
|
|
27
27
|
import { ONCHAIN_EXECUTION_ID_ADDRESS, VerifyTestnetParams, verifyTestnet } from "./verifyTestnet.js";
|
|
28
28
|
import { MakePendingWithdrawalsClaimableOptions, makePendingWithdrawalsClaimable } from "./withdrawalUtils.js";
|
|
29
|
-
export { AccountOpener, AccountOpenerOptions, AnvilActions, AnvilClient, AnvilClientConfig, AnvilDealParameters, AnvilNodeInfo, AnvilRPCSchema, CheckMulticallFn, Create2Deployer, Create2Parameters, DEFAULT_CREATE2_SALT, DetectedCall, EnableDSTokenBackDatingProps, EnsureExistsUsingPublicCreate2ReturnType, EthCallMethod, EthCallRequest, EthCallSpy, GetCreate2AddressParameters, GreenlistMidasGatewayProps, IMinter, type LogSplitterTransportOptions, MakePendingWithdrawalsClaimableOptions, NoAvailableTransportsError, ONCHAIN_EXECUTION_ID_ADDRESS, OpenAccountHumanizedPreview, OpenAccountResult, OpenAccountsResult, OpenTxRevertedError, PUBLIC_CREATE2_FACTORY, PoolDepositResult, ProviderConfig, ProviderStatus, RWAKycFailure, RegisterMidasInvestorProps, RegisterRWAInvestorProps, RegisterRWAInvestorResult, RegisterSecuritizeInvestorProps, ReplaceStorageParams, ResilientTransportOptions, RestoreDSTokenBackDating, RestoreMidasIssuanceVaultPause, RevolverTransport, RevolverTransportConfig, RevolverTransportValue, RpcErrorResult, RpcProvider, RpcResponse, RpcSuccessResult, SUPPORTED_RPC_PROVIDERS, SelectionStrategy, TargetAccount, UnpauseMidasIssuanceVaultProps, VerifyTestnetParams, anvilNodeInfo, calcLiquidatableLTs, claimDSToken, claimDSTokens, claimFromFaucet,
|
|
29
|
+
export { AccountOpener, AccountOpenerOptions, AnvilActions, AnvilClient, AnvilClientConfig, AnvilDealParameters, AnvilNodeInfo, AnvilRPCSchema, CheckMulticallFn, Create2Deployer, Create2Parameters, DEFAULT_CREATE2_SALT, DEFAULT_MIDAS_ADMIN, DetectedCall, EnableDSTokenBackDatingProps, EnsureExistsUsingPublicCreate2ReturnType, EthCallMethod, EthCallRequest, EthCallSpy, GetCreate2AddressParameters, GreenlistMidasGatewayProps, IMinter, type LogSplitterTransportOptions, MakePendingWithdrawalsClaimableOptions, MidasCreditSuite, NoAvailableTransportsError, ONCHAIN_EXECUTION_ID_ADDRESS, OpenAccountHumanizedPreview, OpenAccountResult, OpenAccountsResult, OpenTxRevertedError, PUBLIC_CREATE2_FACTORY, PoolDepositResult, ProviderConfig, ProviderStatus, RWAKycFailure, RegisterMidasInvestorProps, RegisterRWAInvestorProps, RegisterRWAInvestorResult, RegisterSecuritizeInvestorProps, ReplaceStorageParams, ResilientTransportOptions, RestoreDSTokenBackDating, RestoreMidasIssuanceVaultPause, RevolverTransport, RevolverTransportConfig, RevolverTransportValue, RpcErrorResult, RpcProvider, RpcResponse, RpcSuccessResult, SUPPORTED_RPC_PROVIDERS, SelectionStrategy, TargetAccount, UnpauseMidasIssuanceVaultProps, VerifyTestnetParams, anvilNodeInfo, calcLiquidatableLTs, claimDSToken, claimDSTokens, claimFromFaucet, createAnvilClient, createMinter, deployUsingPublicCreate2, detectChain, discoverMidasCreditSuites, discoverMidasGateways, discoverMidasMTokens, enableDSTokenBackDating, evmMineDetailed, extendAnvilClient, getAlchemyUrl, getAnkrUrl, getDrpcUrl, getErpcKey, getPublicCreate2Address, getRpcProviderUrl, getSecuritizeAdmin, getThirdWebUrl, greenlistMidasGateway, httpTransportOptionsSchema, iDegenNftv2Abi, iFaucetAbi, iOnchainExecutionIdAbi, iOwnableAbi, iaclTraitAbi, isAnvil, isDeployedUsingPublicCreate2, isOutOfSyncError, isRangeError, isRateLimitError, isTransientError, logSplitterTransport, makePendingWithdrawalsClaimable, migrateFaucet, providerConfigSchema, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor, replaceStorage, resilientTransport, resilientTransportOptionsSchema, revolverTransportConfigBaseSchema, revolverTransportConfigSchema, rpcProvidersSchema, setLTZero, setLTs, unpauseMidasIssuanceVault, verifyTestnet, writeContractSync };
|
|
@@ -80,6 +80,11 @@ interface GreenlistMidasGatewayProps {
|
|
|
80
80
|
* Greenlists an investor in the access control of a single Midas gateway
|
|
81
81
|
*/
|
|
82
82
|
declare function greenlistMidasGateway(props: GreenlistMidasGatewayProps): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Midas access control admin on mainnet. Holds the admin role of the greenlist
|
|
85
|
+
* operator role.
|
|
86
|
+
*/
|
|
87
|
+
declare const DEFAULT_MIDAS_ADMIN: Address;
|
|
83
88
|
interface RegisterRWAInvestorProps {
|
|
84
89
|
anvil: AnvilClient;
|
|
85
90
|
/**
|
|
@@ -91,7 +96,8 @@ interface RegisterRWAInvestorProps {
|
|
|
91
96
|
*/
|
|
92
97
|
investor: Address;
|
|
93
98
|
/**
|
|
94
|
-
*
|
|
99
|
+
* Midas access control admin, impersonated on the fork.
|
|
100
|
+
* Defaults to {@link DEFAULT_MIDAS_ADMIN}.
|
|
95
101
|
*/
|
|
96
102
|
midasAdmin?: Address;
|
|
97
103
|
logger?: ILogger;
|
|
@@ -123,4 +129,4 @@ interface RegisterRWAInvestorResult {
|
|
|
123
129
|
*/
|
|
124
130
|
declare function registerRWAInvestor(props: RegisterRWAInvestorProps): Promise<RegisterRWAInvestorResult>;
|
|
125
131
|
//#endregion
|
|
126
|
-
export { GreenlistMidasGatewayProps, RWAKycFailure, RegisterMidasInvestorProps, RegisterRWAInvestorProps, RegisterRWAInvestorResult, RegisterSecuritizeInvestorProps, getSecuritizeAdmin, greenlistMidasGateway, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor };
|
|
132
|
+
export { DEFAULT_MIDAS_ADMIN, GreenlistMidasGatewayProps, RWAKycFailure, RegisterMidasInvestorProps, RegisterRWAInvestorProps, RegisterRWAInvestorResult, RegisterSecuritizeInvestorProps, getSecuritizeAdmin, greenlistMidasGateway, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor };
|
|
@@ -34,13 +34,29 @@ type RestoreMidasIssuanceVaultPause = () => Promise<void>;
|
|
|
34
34
|
*/
|
|
35
35
|
declare function unpauseMidasIssuanceVault(props: UnpauseMidasIssuanceVaultProps): Promise<RestoreMidasIssuanceVaultPause>;
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
37
|
+
* One Midas credit suite: a credit manager with a Midas gateway adapter,
|
|
38
|
+
* or with a Midas degen NFT when it has no such adapter.
|
|
39
39
|
*/
|
|
40
|
-
|
|
40
|
+
interface MidasCreditSuite {
|
|
41
|
+
creditManager: Address;
|
|
42
|
+
gateway: Address;
|
|
43
|
+
mToken: Address;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Midas credit suites of the loaded credit managers.
|
|
47
|
+
*
|
|
48
|
+
* A manager with a gateway adapter is a suite on its own, so its degen NFT
|
|
49
|
+
* is not consulted. Suites that only have a Midas degen NFT read `mToken`
|
|
50
|
+
* from the gateway.
|
|
51
|
+
*/
|
|
52
|
+
declare function discoverMidasCreditSuites(sdk: OnchainSDK): Promise<MidasCreditSuite[]>;
|
|
53
|
+
/**
|
|
54
|
+
* Gateways of the Midas credit suites of the loaded credit managers.
|
|
55
|
+
*/
|
|
56
|
+
declare function discoverMidasGateways(sdk: OnchainSDK): Promise<Address[]>;
|
|
41
57
|
/**
|
|
42
58
|
* mTokens of all Midas gateway adapters of the loaded credit managers
|
|
43
59
|
*/
|
|
44
|
-
declare function
|
|
60
|
+
declare function discoverMidasMTokens(sdk: OnchainSDK): Address[];
|
|
45
61
|
//#endregion
|
|
46
|
-
export { RestoreMidasIssuanceVaultPause, UnpauseMidasIssuanceVaultProps,
|
|
62
|
+
export { MidasCreditSuite, RestoreMidasIssuanceVaultPause, UnpauseMidasIssuanceVaultProps, discoverMidasCreditSuites, discoverMidasGateways, discoverMidasMTokens, unpauseMidasIssuanceVault };
|
|
@@ -64,11 +64,8 @@ interface RouterPaths {
|
|
|
64
64
|
}): Promise<OpenStrategyLeg>;
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
|
-
* The engine's only door to the pathfinder
|
|
68
|
-
*
|
|
69
|
-
* Deliberately not a quoter abstraction with an oracle-priced twin: paths are
|
|
70
|
-
* always resolved on-chain, because a preview whose swap amounts came from
|
|
71
|
-
* oracle prices could not produce the calldata that realises them.
|
|
67
|
+
* The engine's only door to the pathfinder, and the only quoter whose legs can
|
|
68
|
+
* be sent. {@link createOraclePaths} is the twin for a walk that only projects.
|
|
72
69
|
*/
|
|
73
70
|
declare function createRouterPaths(args: {
|
|
74
71
|
sdk: OnchainSDK;
|