@gearbox-protocol/sdk 14.12.0-next.59 → 14.12.0-next.60
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/AccountOpener.js +8 -1
- package/dist/cjs/dev/index.js +2 -0
- package/dist/cjs/dev/kycUtils.js +1 -1
- package/dist/cjs/dev/midasUtils.js +100 -0
- package/dist/cjs/permissionless/bindings/factory/credit-factory.js +1 -1
- package/dist/cjs/plugins/adapters/abi/adapters/iMidasGatewayAdapterV311.js +11 -0
- package/dist/esm/dev/AccountOpener.js +8 -1
- package/dist/esm/dev/index.js +2 -1
- package/dist/esm/dev/kycUtils.js +1 -1
- package/dist/esm/dev/midasUtils.js +99 -0
- package/dist/esm/plugins/adapters/abi/adapters/iMidasGatewayAdapterV311.js +11 -0
- package/dist/types/dev/index.d.ts +2 -1
- package/dist/types/dev/midasUtils.d.ts +39 -0
- package/dist/types/plugins/adapters/abi/adapters/iMidasGatewayAdapterV311.d.ts +10 -0
- package/dist/types/plugins/adapters/contracts/MidasGatewayAdapterContract.d.ts +10 -0
- package/package.json +1 -1
|
@@ -14,6 +14,7 @@ require("../sdk/index.js");
|
|
|
14
14
|
const require_dev_abi = require("./abi.js");
|
|
15
15
|
const require_dev_claimFromFaucet = require("./claimFromFaucet.js");
|
|
16
16
|
const require_dev_createAnvilClient = require("./createAnvilClient.js");
|
|
17
|
+
const require_dev_midasUtils = require("./midasUtils.js");
|
|
17
18
|
const require_dev_mint_factory = require("./mint/factory.js");
|
|
18
19
|
require("./mint/index.js");
|
|
19
20
|
let viem = require("viem");
|
|
@@ -253,6 +254,12 @@ var AccountOpener = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
253
254
|
target
|
|
254
255
|
});
|
|
255
256
|
logger?.debug(strategy, "found open strategy");
|
|
257
|
+
const strategyCalls = await require_dev_midasUtils.prependMidasReceiveGreenlist({
|
|
258
|
+
cm,
|
|
259
|
+
client: this.#anvil,
|
|
260
|
+
calls: strategy.calls,
|
|
261
|
+
logger
|
|
262
|
+
});
|
|
256
263
|
const debt = minDebt * (leverage - require_sdk_constants_math.PERCENTAGE_FACTOR) / require_sdk_constants_math.PERCENTAGE_FACTOR;
|
|
257
264
|
const averageQuota = this.#getCollateralQuota(cm, target, strategy.amount, debt, logger);
|
|
258
265
|
const minQuota = this.#getCollateralQuota(cm, target, strategy.minAmount, debt, logger);
|
|
@@ -279,7 +286,7 @@ var AccountOpener = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
279
286
|
balance: minDebt
|
|
280
287
|
}],
|
|
281
288
|
debt,
|
|
282
|
-
calls:
|
|
289
|
+
calls: strategyCalls,
|
|
283
290
|
ethAmount: 0n,
|
|
284
291
|
permits: {},
|
|
285
292
|
to: borrower.address,
|
package/dist/cjs/dev/index.js
CHANGED
|
@@ -2,6 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_dev_abi = require("./abi.js");
|
|
3
3
|
const require_dev_claimFromFaucet = require("./claimFromFaucet.js");
|
|
4
4
|
const require_dev_createAnvilClient = require("./createAnvilClient.js");
|
|
5
|
+
const require_dev_midasUtils = require("./midasUtils.js");
|
|
5
6
|
const require_dev_mint_factory = require("./mint/factory.js");
|
|
6
7
|
require("./mint/index.js");
|
|
7
8
|
const require_dev_AccountOpener = require("./AccountOpener.js");
|
|
@@ -70,6 +71,7 @@ exports.isTransientError = require_dev_isTransientError.isTransientError;
|
|
|
70
71
|
exports.logSplitterTransport = require_dev_logSplitterTransport.logSplitterTransport;
|
|
71
72
|
exports.makePendingWithdrawalsClaimable = require_dev_withdrawalUtils.makePendingWithdrawalsClaimable;
|
|
72
73
|
exports.migrateFaucet = require_dev_migrateFaucet.migrateFaucet;
|
|
74
|
+
exports.prependMidasReceiveGreenlist = require_dev_midasUtils.prependMidasReceiveGreenlist;
|
|
73
75
|
exports.providerConfigSchema = require_dev_RevolverTransport.providerConfigSchema;
|
|
74
76
|
exports.registerMidasInvestor = require_dev_kycUtils.registerMidasInvestor;
|
|
75
77
|
exports.registerRWAInvestor = require_dev_kycUtils.registerRWAInvestor;
|
package/dist/cjs/dev/kycUtils.js
CHANGED
|
@@ -3,9 +3,9 @@ const require_sdk_utils_AddressSet = require("../sdk/utils/AddressSet.js");
|
|
|
3
3
|
const require_sdk_constants_math = require("../sdk/constants/math.js");
|
|
4
4
|
const require_sdk_OnchainSDK = require("../sdk/OnchainSDK.js");
|
|
5
5
|
require("../sdk/index.js");
|
|
6
|
+
const require_dev_withdrawalAbi = require("./withdrawalAbi.js");
|
|
6
7
|
const require_abi_rwa_iDSToken = require("../abi/rwa/iDSToken.js");
|
|
7
8
|
const require_abi_rwa_iDSRegistryService = require("../abi/rwa/iDSRegistryService.js");
|
|
8
|
-
const require_dev_withdrawalAbi = require("./withdrawalAbi.js");
|
|
9
9
|
let viem = require("viem");
|
|
10
10
|
let viem_accounts = require("viem/accounts");
|
|
11
11
|
//#region src/dev/kycUtils.ts
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_dev_withdrawalAbi = require("./withdrawalAbi.js");
|
|
3
|
+
let viem = require("viem");
|
|
4
|
+
//#region src/dev/midasUtils.ts
|
|
5
|
+
const ADAPTER_MIDAS_GATEWAY = "ADAPTER::MIDAS_GATEWAY";
|
|
6
|
+
const ADAPTER_MIDAS_ISSUANCE_VAULT = "ADAPTER::MIDAS_ISSUANCE_VAULT";
|
|
7
|
+
/**
|
|
8
|
+
* Permissionless gateways have no greenlist and reject `receiveGreenlist`,
|
|
9
|
+
* see MidasMode in integrations-v3
|
|
10
|
+
*/
|
|
11
|
+
const MIDAS_MODE_PERMISSIONLESS = 0;
|
|
12
|
+
/**
|
|
13
|
+
* Gateways and issuance vaults both expose their mToken, but only on-chain:
|
|
14
|
+
* without the adapters plugin the SDK represents adapters as placeholders that
|
|
15
|
+
* expose nothing but their target contract
|
|
16
|
+
*/
|
|
17
|
+
const iMidasMTokenAbi = (0, viem.parseAbi)(["function mToken() external view returns (address)"]);
|
|
18
|
+
const iMidasGatewayAdapterExtAbi = (0, viem.parseAbi)(["function receiveGreenlist() external returns (bool)"]);
|
|
19
|
+
const receiveGreenlistCallData = (0, viem.encodeFunctionData)({
|
|
20
|
+
abi: iMidasGatewayAdapterExtAbi,
|
|
21
|
+
functionName: "receiveGreenlist"
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* Prepends `MidasGatewayAdapter.receiveGreenlist()` to a credit facade
|
|
25
|
+
* multicall that mints an mToken through a Midas issuance vault.
|
|
26
|
+
*
|
|
27
|
+
* Permissioned and restricted-interface mTokens can only be held by greenlisted
|
|
28
|
+
* accounts, and a freshly opened credit account is never greenlisted, so the
|
|
29
|
+
* mint reverts with `WMAC: hasnt role` unless the account asks the gateway for
|
|
30
|
+
* the greenlist first. Greenlisting the borrower (see `registerMidasInvestor`)
|
|
31
|
+
* is not enough — the role is checked on the token holder, which is the credit
|
|
32
|
+
* account.
|
|
33
|
+
*
|
|
34
|
+
* Returns `calls` unchanged when nothing has to be greenlisted: no issuance
|
|
35
|
+
* vault is called, its mToken has no gateway adapter on this credit manager,
|
|
36
|
+
* the gateway is permissionless, or the call is already there.
|
|
37
|
+
*/
|
|
38
|
+
async function prependMidasReceiveGreenlist(props) {
|
|
39
|
+
const { cm, client, calls, logger } = props;
|
|
40
|
+
const gatewayAdapters = [];
|
|
41
|
+
const issuanceAdapters = [];
|
|
42
|
+
for (const adapter of cm.creditManager.adapters.values()) switch (adapter.contractType) {
|
|
43
|
+
case ADAPTER_MIDAS_GATEWAY:
|
|
44
|
+
gatewayAdapters.push(adapter);
|
|
45
|
+
break;
|
|
46
|
+
case ADAPTER_MIDAS_ISSUANCE_VAULT: issuanceAdapters.push(adapter);
|
|
47
|
+
}
|
|
48
|
+
if (gatewayAdapters.length === 0) return calls;
|
|
49
|
+
const calledIssuanceAdapters = issuanceAdapters.filter((adapter) => calls.some((call) => (0, viem.isAddressEqual)(call.target, adapter.address)));
|
|
50
|
+
if (calledIssuanceAdapters.length === 0) return calls;
|
|
51
|
+
const [gatewayMTokens, issuanceMTokens] = await Promise.all([readMTokens(client, gatewayAdapters), readMTokens(client, calledIssuanceAdapters)]);
|
|
52
|
+
const gateways = [];
|
|
53
|
+
for (const [i, mToken] of issuanceMTokens.entries()) {
|
|
54
|
+
const gateway = gatewayAdapters.find((_, j) => (0, viem.isAddressEqual)(gatewayMTokens[j], mToken));
|
|
55
|
+
if (!gateway) {
|
|
56
|
+
logger?.debug(`midas: no gateway adapter for mToken ${mToken} minted by ${calledIssuanceAdapters[i].address} on ${cm.name}, cannot greenlist the credit account`);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (gateways.some((g) => (0, viem.isAddressEqual)(g.address, gateway.address))) continue;
|
|
60
|
+
if (calls.some((call) => (0, viem.isAddressEqual)(call.target, gateway.address) && call.callData === receiveGreenlistCallData)) {
|
|
61
|
+
logger?.debug(`midas: gateway adapter ${gateway.address} already receives the greenlist`);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
gateways.push(gateway);
|
|
65
|
+
}
|
|
66
|
+
if (gateways.length === 0) return calls;
|
|
67
|
+
const modes = await client.multicall({
|
|
68
|
+
allowFailure: false,
|
|
69
|
+
contracts: gateways.map(({ targetContract }) => ({
|
|
70
|
+
address: targetContract,
|
|
71
|
+
abi: require_dev_withdrawalAbi.midasGatewayAbi,
|
|
72
|
+
functionName: "mode"
|
|
73
|
+
}))
|
|
74
|
+
});
|
|
75
|
+
const prepended = [];
|
|
76
|
+
for (const [i, gateway] of gateways.entries()) {
|
|
77
|
+
if (modes[i] === MIDAS_MODE_PERMISSIONLESS) {
|
|
78
|
+
logger?.debug(`midas: gateway ${gateway.targetContract} is permissionless, nothing to greenlist`);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
logger?.debug(`midas: greenlisting the credit account via gateway adapter ${gateway.address}`);
|
|
82
|
+
prepended.push({
|
|
83
|
+
target: gateway.address,
|
|
84
|
+
callData: receiveGreenlistCallData
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return prepended.length > 0 ? [...prepended, ...calls] : calls;
|
|
88
|
+
}
|
|
89
|
+
async function readMTokens(client, adapters) {
|
|
90
|
+
return await client.multicall({
|
|
91
|
+
allowFailure: false,
|
|
92
|
+
contracts: adapters.map(({ targetContract }) => ({
|
|
93
|
+
address: targetContract,
|
|
94
|
+
abi: iMidasMTokenAbi,
|
|
95
|
+
functionName: "mToken"
|
|
96
|
+
}))
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
exports.prependMidasReceiveGreenlist = prependMidasReceiveGreenlist;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_abi_310_configure_iCreditConfigureActions = require("../../../abi/310/configure/iCreditConfigureActions.js");
|
|
2
3
|
const require_plugins_adapters_abi_conctructorAbi = require("../../../plugins/adapters/abi/conctructorAbi.js");
|
|
3
4
|
const require_plugins_adapters_abi_utils = require("../../../plugins/adapters/abi/utils.js");
|
|
4
5
|
require("../../../plugins/adapters/index.js");
|
|
5
|
-
const require_abi_310_configure_iCreditConfigureActions = require("../../../abi/310/configure/iCreditConfigureActions.js");
|
|
6
6
|
const require_permissionless_bindings_factory_abstract_factory = require("./abstract-factory.js");
|
|
7
7
|
let viem = require("viem");
|
|
8
8
|
//#region src/permissionless/bindings/factory/credit-factory.ts
|
|
@@ -132,6 +132,17 @@ const iMidasGatewayAdapterV311Abi = [
|
|
|
132
132
|
}],
|
|
133
133
|
stateMutability: "view"
|
|
134
134
|
},
|
|
135
|
+
{
|
|
136
|
+
type: "function",
|
|
137
|
+
name: "receiveGreenlist",
|
|
138
|
+
inputs: [],
|
|
139
|
+
outputs: [{
|
|
140
|
+
name: "",
|
|
141
|
+
type: "bool",
|
|
142
|
+
internalType: "bool"
|
|
143
|
+
}],
|
|
144
|
+
stateMutability: "nonpayable"
|
|
145
|
+
},
|
|
135
146
|
{
|
|
136
147
|
type: "function",
|
|
137
148
|
name: "redeemInstant",
|
|
@@ -13,6 +13,7 @@ import "../sdk/index.js";
|
|
|
13
13
|
import { iDegenNftv2Abi } from "./abi.js";
|
|
14
14
|
import { claimFromFaucet } from "./claimFromFaucet.js";
|
|
15
15
|
import { extendAnvilClient } from "./createAnvilClient.js";
|
|
16
|
+
import { prependMidasReceiveGreenlist } from "./midasUtils.js";
|
|
16
17
|
import { createMinter } from "./mint/factory.js";
|
|
17
18
|
import "./mint/index.js";
|
|
18
19
|
import { BaseError, erc20Abi, isAddress, parseEther, parseEventLogs } from "viem";
|
|
@@ -252,6 +253,12 @@ var AccountOpener = class extends SDKConstruct {
|
|
|
252
253
|
target
|
|
253
254
|
});
|
|
254
255
|
logger?.debug(strategy, "found open strategy");
|
|
256
|
+
const strategyCalls = await prependMidasReceiveGreenlist({
|
|
257
|
+
cm,
|
|
258
|
+
client: this.#anvil,
|
|
259
|
+
calls: strategy.calls,
|
|
260
|
+
logger
|
|
261
|
+
});
|
|
255
262
|
const debt = minDebt * (leverage - PERCENTAGE_FACTOR) / PERCENTAGE_FACTOR;
|
|
256
263
|
const averageQuota = this.#getCollateralQuota(cm, target, strategy.amount, debt, logger);
|
|
257
264
|
const minQuota = this.#getCollateralQuota(cm, target, strategy.minAmount, debt, logger);
|
|
@@ -278,7 +285,7 @@ var AccountOpener = class extends SDKConstruct {
|
|
|
278
285
|
balance: minDebt
|
|
279
286
|
}],
|
|
280
287
|
debt,
|
|
281
|
-
calls:
|
|
288
|
+
calls: strategyCalls,
|
|
282
289
|
ethAmount: 0n,
|
|
283
290
|
permits: {},
|
|
284
291
|
to: borrower.address,
|
package/dist/esm/dev/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { faucetAbi, iDegenNftv2Abi, iOnchainExecutionIdAbi, iOwnableAbi, iaclTraitAbi } from "./abi.js";
|
|
2
2
|
import { claimFromFaucet } from "./claimFromFaucet.js";
|
|
3
3
|
import { anvilNodeInfo, createAnvilClient, evmMineDetailed, extendAnvilClient, isAnvil } from "./createAnvilClient.js";
|
|
4
|
+
import { prependMidasReceiveGreenlist } from "./midasUtils.js";
|
|
4
5
|
import { createMinter } from "./mint/factory.js";
|
|
5
6
|
import "./mint/index.js";
|
|
6
7
|
import { AccountOpener, OpenTxRevertedError } from "./AccountOpener.js";
|
|
@@ -24,4 +25,4 @@ import { resilientTransport, resilientTransportOptionsSchema } from "./resilient
|
|
|
24
25
|
import "./types.js";
|
|
25
26
|
import { ONCHAIN_EXECUTION_ID_ADDRESS, verifyTestnet } from "./verifyTestnet.js";
|
|
26
27
|
import { makePendingWithdrawalsClaimable } from "./withdrawalUtils.js";
|
|
27
|
-
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, createAnvilClient, createMinter, deployUsingPublicCreate2, detectChain, evmMineDetailed, extendAnvilClient, faucetAbi, getAlchemyUrl, getAnkrUrl, getDrpcUrl, getErpcKey, getPublicCreate2Address, getRpcProviderUrl, getThirdWebUrl, greenlistMidasGateway, httpTransportOptionsSchema, iDegenNftv2Abi, iOnchainExecutionIdAbi, iOwnableAbi, iaclTraitAbi, isAnvil, isDeployedUsingPublicCreate2, isOutOfSyncError, isRangeError, isRateLimitError, isTransientError, logSplitterTransport, makePendingWithdrawalsClaimable, migrateFaucet, providerConfigSchema, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor, replaceStorage, resilientTransport, resilientTransportOptionsSchema, revolverTransportConfigBaseSchema, revolverTransportConfigSchema, rpcProvidersSchema, setLTZero, setLTs, verifyTestnet, writeAndWait };
|
|
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, createAnvilClient, createMinter, deployUsingPublicCreate2, detectChain, evmMineDetailed, extendAnvilClient, faucetAbi, getAlchemyUrl, getAnkrUrl, getDrpcUrl, getErpcKey, getPublicCreate2Address, getRpcProviderUrl, getThirdWebUrl, greenlistMidasGateway, httpTransportOptionsSchema, iDegenNftv2Abi, iOnchainExecutionIdAbi, iOwnableAbi, iaclTraitAbi, isAnvil, isDeployedUsingPublicCreate2, isOutOfSyncError, isRangeError, isRateLimitError, isTransientError, logSplitterTransport, makePendingWithdrawalsClaimable, migrateFaucet, prependMidasReceiveGreenlist, providerConfigSchema, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor, replaceStorage, resilientTransport, resilientTransportOptionsSchema, revolverTransportConfigBaseSchema, revolverTransportConfigSchema, rpcProvidersSchema, setLTZero, setLTs, verifyTestnet, writeAndWait };
|
package/dist/esm/dev/kycUtils.js
CHANGED
|
@@ -2,9 +2,9 @@ import { AddressSet } from "../sdk/utils/AddressSet.js";
|
|
|
2
2
|
import { MAX_UINT256 } from "../sdk/constants/math.js";
|
|
3
3
|
import { OnchainSDK } from "../sdk/OnchainSDK.js";
|
|
4
4
|
import "../sdk/index.js";
|
|
5
|
+
import { midasGatewayAbi } from "./withdrawalAbi.js";
|
|
5
6
|
import { iDSTokenAbi } from "../abi/rwa/iDSToken.js";
|
|
6
7
|
import { iDSRegistryServiceAbi } from "../abi/rwa/iDSRegistryService.js";
|
|
7
|
-
import { midasGatewayAbi } from "./withdrawalAbi.js";
|
|
8
8
|
import { isAddressEqual, parseAbi, parseEther, zeroAddress } from "viem";
|
|
9
9
|
import { privateKeyToAccount } from "viem/accounts";
|
|
10
10
|
//#region src/dev/kycUtils.ts
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { midasGatewayAbi } from "./withdrawalAbi.js";
|
|
2
|
+
import { encodeFunctionData, isAddressEqual, parseAbi } from "viem";
|
|
3
|
+
//#region src/dev/midasUtils.ts
|
|
4
|
+
const ADAPTER_MIDAS_GATEWAY = "ADAPTER::MIDAS_GATEWAY";
|
|
5
|
+
const ADAPTER_MIDAS_ISSUANCE_VAULT = "ADAPTER::MIDAS_ISSUANCE_VAULT";
|
|
6
|
+
/**
|
|
7
|
+
* Permissionless gateways have no greenlist and reject `receiveGreenlist`,
|
|
8
|
+
* see MidasMode in integrations-v3
|
|
9
|
+
*/
|
|
10
|
+
const MIDAS_MODE_PERMISSIONLESS = 0;
|
|
11
|
+
/**
|
|
12
|
+
* Gateways and issuance vaults both expose their mToken, but only on-chain:
|
|
13
|
+
* without the adapters plugin the SDK represents adapters as placeholders that
|
|
14
|
+
* expose nothing but their target contract
|
|
15
|
+
*/
|
|
16
|
+
const iMidasMTokenAbi = parseAbi(["function mToken() external view returns (address)"]);
|
|
17
|
+
const iMidasGatewayAdapterExtAbi = parseAbi(["function receiveGreenlist() external returns (bool)"]);
|
|
18
|
+
const receiveGreenlistCallData = encodeFunctionData({
|
|
19
|
+
abi: iMidasGatewayAdapterExtAbi,
|
|
20
|
+
functionName: "receiveGreenlist"
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* Prepends `MidasGatewayAdapter.receiveGreenlist()` to a credit facade
|
|
24
|
+
* multicall that mints an mToken through a Midas issuance vault.
|
|
25
|
+
*
|
|
26
|
+
* Permissioned and restricted-interface mTokens can only be held by greenlisted
|
|
27
|
+
* accounts, and a freshly opened credit account is never greenlisted, so the
|
|
28
|
+
* mint reverts with `WMAC: hasnt role` unless the account asks the gateway for
|
|
29
|
+
* the greenlist first. Greenlisting the borrower (see `registerMidasInvestor`)
|
|
30
|
+
* is not enough — the role is checked on the token holder, which is the credit
|
|
31
|
+
* account.
|
|
32
|
+
*
|
|
33
|
+
* Returns `calls` unchanged when nothing has to be greenlisted: no issuance
|
|
34
|
+
* vault is called, its mToken has no gateway adapter on this credit manager,
|
|
35
|
+
* the gateway is permissionless, or the call is already there.
|
|
36
|
+
*/
|
|
37
|
+
async function prependMidasReceiveGreenlist(props) {
|
|
38
|
+
const { cm, client, calls, logger } = props;
|
|
39
|
+
const gatewayAdapters = [];
|
|
40
|
+
const issuanceAdapters = [];
|
|
41
|
+
for (const adapter of cm.creditManager.adapters.values()) switch (adapter.contractType) {
|
|
42
|
+
case ADAPTER_MIDAS_GATEWAY:
|
|
43
|
+
gatewayAdapters.push(adapter);
|
|
44
|
+
break;
|
|
45
|
+
case ADAPTER_MIDAS_ISSUANCE_VAULT: issuanceAdapters.push(adapter);
|
|
46
|
+
}
|
|
47
|
+
if (gatewayAdapters.length === 0) return calls;
|
|
48
|
+
const calledIssuanceAdapters = issuanceAdapters.filter((adapter) => calls.some((call) => isAddressEqual(call.target, adapter.address)));
|
|
49
|
+
if (calledIssuanceAdapters.length === 0) return calls;
|
|
50
|
+
const [gatewayMTokens, issuanceMTokens] = await Promise.all([readMTokens(client, gatewayAdapters), readMTokens(client, calledIssuanceAdapters)]);
|
|
51
|
+
const gateways = [];
|
|
52
|
+
for (const [i, mToken] of issuanceMTokens.entries()) {
|
|
53
|
+
const gateway = gatewayAdapters.find((_, j) => isAddressEqual(gatewayMTokens[j], mToken));
|
|
54
|
+
if (!gateway) {
|
|
55
|
+
logger?.debug(`midas: no gateway adapter for mToken ${mToken} minted by ${calledIssuanceAdapters[i].address} on ${cm.name}, cannot greenlist the credit account`);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (gateways.some((g) => isAddressEqual(g.address, gateway.address))) continue;
|
|
59
|
+
if (calls.some((call) => isAddressEqual(call.target, gateway.address) && call.callData === receiveGreenlistCallData)) {
|
|
60
|
+
logger?.debug(`midas: gateway adapter ${gateway.address} already receives the greenlist`);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
gateways.push(gateway);
|
|
64
|
+
}
|
|
65
|
+
if (gateways.length === 0) return calls;
|
|
66
|
+
const modes = await client.multicall({
|
|
67
|
+
allowFailure: false,
|
|
68
|
+
contracts: gateways.map(({ targetContract }) => ({
|
|
69
|
+
address: targetContract,
|
|
70
|
+
abi: midasGatewayAbi,
|
|
71
|
+
functionName: "mode"
|
|
72
|
+
}))
|
|
73
|
+
});
|
|
74
|
+
const prepended = [];
|
|
75
|
+
for (const [i, gateway] of gateways.entries()) {
|
|
76
|
+
if (modes[i] === MIDAS_MODE_PERMISSIONLESS) {
|
|
77
|
+
logger?.debug(`midas: gateway ${gateway.targetContract} is permissionless, nothing to greenlist`);
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
logger?.debug(`midas: greenlisting the credit account via gateway adapter ${gateway.address}`);
|
|
81
|
+
prepended.push({
|
|
82
|
+
target: gateway.address,
|
|
83
|
+
callData: receiveGreenlistCallData
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return prepended.length > 0 ? [...prepended, ...calls] : calls;
|
|
87
|
+
}
|
|
88
|
+
async function readMTokens(client, adapters) {
|
|
89
|
+
return await client.multicall({
|
|
90
|
+
allowFailure: false,
|
|
91
|
+
contracts: adapters.map(({ targetContract }) => ({
|
|
92
|
+
address: targetContract,
|
|
93
|
+
abi: iMidasMTokenAbi,
|
|
94
|
+
functionName: "mToken"
|
|
95
|
+
}))
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
//#endregion
|
|
99
|
+
export { prependMidasReceiveGreenlist };
|
|
@@ -131,6 +131,17 @@ const iMidasGatewayAdapterV311Abi = [
|
|
|
131
131
|
}],
|
|
132
132
|
stateMutability: "view"
|
|
133
133
|
},
|
|
134
|
+
{
|
|
135
|
+
type: "function",
|
|
136
|
+
name: "receiveGreenlist",
|
|
137
|
+
inputs: [],
|
|
138
|
+
outputs: [{
|
|
139
|
+
name: "",
|
|
140
|
+
type: "bool",
|
|
141
|
+
internalType: "bool"
|
|
142
|
+
}],
|
|
143
|
+
stateMutability: "nonpayable"
|
|
144
|
+
},
|
|
134
145
|
{
|
|
135
146
|
type: "function",
|
|
136
147
|
name: "redeemInstant",
|
|
@@ -15,6 +15,7 @@ import { isTransientError } from "./isTransientError.js";
|
|
|
15
15
|
import { GreenlistMidasGatewayProps, RWAKycFailure, RegisterMidasInvestorProps, RegisterRWAInvestorProps, RegisterRWAInvestorResult, RegisterSecuritizeInvestorProps, greenlistMidasGateway, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor, writeAndWait } from "./kycUtils.js";
|
|
16
16
|
import { LogSplitterTransportOptions, isRangeError, logSplitterTransport } from "./logSplitterTransport.js";
|
|
17
17
|
import { setLTZero, setLTs } from "./ltUtils.js";
|
|
18
|
+
import { PrependMidasReceiveGreenlistProps, prependMidasReceiveGreenlist } from "./midasUtils.js";
|
|
18
19
|
import { migrateFaucet } from "./migrateFaucet.js";
|
|
19
20
|
import { IMinter } from "./mint/types.js";
|
|
20
21
|
import { createMinter } from "./mint/factory.js";
|
|
@@ -25,4 +26,4 @@ import { ResilientTransportOptions, resilientTransport, resilientTransportOption
|
|
|
25
26
|
import { httpTransportOptionsSchema } from "./transports.js";
|
|
26
27
|
import { ONCHAIN_EXECUTION_ID_ADDRESS, VerifyTestnetParams, verifyTestnet } from "./verifyTestnet.js";
|
|
27
28
|
import { MakePendingWithdrawalsClaimableOptions, makePendingWithdrawalsClaimable } from "./withdrawalUtils.js";
|
|
28
|
-
export { AccountOpener, AccountOpenerOptions, AnvilActions, AnvilClient, AnvilClientConfig, AnvilDealParameters, AnvilNodeInfo, AnvilRPCSchema, CheckMulticallFn, Create2Deployer, Create2Parameters, DEFAULT_CREATE2_SALT, DetectedCall, 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, RevolverTransport, RevolverTransportConfig, RevolverTransportValue, RpcErrorResult, RpcProvider, RpcResponse, RpcSuccessResult, SUPPORTED_RPC_PROVIDERS, SelectionStrategy, TargetAccount, VerifyTestnetParams, anvilNodeInfo, calcLiquidatableLTs, claimDSToken, claimDSTokens, claimFromFaucet, createAnvilClient, createMinter, deployUsingPublicCreate2, detectChain, evmMineDetailed, extendAnvilClient, faucetAbi, getAlchemyUrl, getAnkrUrl, getDrpcUrl, getErpcKey, getPublicCreate2Address, getRpcProviderUrl, getThirdWebUrl, greenlistMidasGateway, httpTransportOptionsSchema, iDegenNftv2Abi, iOnchainExecutionIdAbi, iOwnableAbi, iaclTraitAbi, isAnvil, isDeployedUsingPublicCreate2, isOutOfSyncError, isRangeError, isRateLimitError, isTransientError, logSplitterTransport, makePendingWithdrawalsClaimable, migrateFaucet, providerConfigSchema, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor, replaceStorage, resilientTransport, resilientTransportOptionsSchema, revolverTransportConfigBaseSchema, revolverTransportConfigSchema, rpcProvidersSchema, setLTZero, setLTs, verifyTestnet, writeAndWait };
|
|
29
|
+
export { AccountOpener, AccountOpenerOptions, AnvilActions, AnvilClient, AnvilClientConfig, AnvilDealParameters, AnvilNodeInfo, AnvilRPCSchema, CheckMulticallFn, Create2Deployer, Create2Parameters, DEFAULT_CREATE2_SALT, DetectedCall, EnsureExistsUsingPublicCreate2ReturnType, EthCallMethod, EthCallRequest, EthCallSpy, GetCreate2AddressParameters, GreenlistMidasGatewayProps, IMinter, type LogSplitterTransportOptions, MakePendingWithdrawalsClaimableOptions, NoAvailableTransportsError, ONCHAIN_EXECUTION_ID_ADDRESS, OpenAccountHumanizedPreview, OpenAccountResult, OpenAccountsResult, OpenTxRevertedError, PUBLIC_CREATE2_FACTORY, PoolDepositResult, PrependMidasReceiveGreenlistProps, ProviderConfig, ProviderStatus, RWAKycFailure, RegisterMidasInvestorProps, RegisterRWAInvestorProps, RegisterRWAInvestorResult, RegisterSecuritizeInvestorProps, ReplaceStorageParams, ResilientTransportOptions, RevolverTransport, RevolverTransportConfig, RevolverTransportValue, RpcErrorResult, RpcProvider, RpcResponse, RpcSuccessResult, SUPPORTED_RPC_PROVIDERS, SelectionStrategy, TargetAccount, VerifyTestnetParams, anvilNodeInfo, calcLiquidatableLTs, claimDSToken, claimDSTokens, claimFromFaucet, createAnvilClient, createMinter, deployUsingPublicCreate2, detectChain, evmMineDetailed, extendAnvilClient, faucetAbi, getAlchemyUrl, getAnkrUrl, getDrpcUrl, getErpcKey, getPublicCreate2Address, getRpcProviderUrl, getThirdWebUrl, greenlistMidasGateway, httpTransportOptionsSchema, iDegenNftv2Abi, iOnchainExecutionIdAbi, iOwnableAbi, iaclTraitAbi, isAnvil, isDeployedUsingPublicCreate2, isOutOfSyncError, isRangeError, isRateLimitError, isTransientError, logSplitterTransport, makePendingWithdrawalsClaimable, migrateFaucet, prependMidasReceiveGreenlist, providerConfigSchema, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor, replaceStorage, resilientTransport, resilientTransportOptionsSchema, revolverTransportConfigBaseSchema, revolverTransportConfigSchema, rpcProvidersSchema, setLTZero, setLTs, verifyTestnet, writeAndWait };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ILogger } from "../sdk/types/logger.js";
|
|
2
|
+
import { CreditSuite } from "../sdk/market/credit/CreditSuite.js";
|
|
3
|
+
import { MultiCall } from "../sdk/types/transactions.js";
|
|
4
|
+
import "../sdk/index.js";
|
|
5
|
+
import { PublicClient } from "viem";
|
|
6
|
+
//#region src/dev/midasUtils.d.ts
|
|
7
|
+
interface PrependMidasReceiveGreenlistProps {
|
|
8
|
+
/**
|
|
9
|
+
* Credit manager the account is opened on
|
|
10
|
+
*/
|
|
11
|
+
cm: CreditSuite;
|
|
12
|
+
/**
|
|
13
|
+
* Client to read gateway state with
|
|
14
|
+
*/
|
|
15
|
+
client: PublicClient;
|
|
16
|
+
/**
|
|
17
|
+
* Calls to run in the credit facade multicall, as produced by the router
|
|
18
|
+
*/
|
|
19
|
+
calls: MultiCall[];
|
|
20
|
+
logger?: ILogger;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Prepends `MidasGatewayAdapter.receiveGreenlist()` to a credit facade
|
|
24
|
+
* multicall that mints an mToken through a Midas issuance vault.
|
|
25
|
+
*
|
|
26
|
+
* Permissioned and restricted-interface mTokens can only be held by greenlisted
|
|
27
|
+
* accounts, and a freshly opened credit account is never greenlisted, so the
|
|
28
|
+
* mint reverts with `WMAC: hasnt role` unless the account asks the gateway for
|
|
29
|
+
* the greenlist first. Greenlisting the borrower (see `registerMidasInvestor`)
|
|
30
|
+
* is not enough — the role is checked on the token holder, which is the credit
|
|
31
|
+
* account.
|
|
32
|
+
*
|
|
33
|
+
* Returns `calls` unchanged when nothing has to be greenlisted: no issuance
|
|
34
|
+
* vault is called, its mToken has no gateway adapter on this credit manager,
|
|
35
|
+
* the gateway is permissionless, or the call is already there.
|
|
36
|
+
*/
|
|
37
|
+
declare function prependMidasReceiveGreenlist(props: PrependMidasReceiveGreenlistProps): Promise<MultiCall[]>;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { PrependMidasReceiveGreenlistProps, prependMidasReceiveGreenlist };
|
|
@@ -117,6 +117,16 @@ declare const iMidasGatewayAdapterV311Abi: readonly [{
|
|
|
117
117
|
readonly internalType: "address";
|
|
118
118
|
}];
|
|
119
119
|
readonly stateMutability: "view";
|
|
120
|
+
}, {
|
|
121
|
+
readonly type: "function";
|
|
122
|
+
readonly name: "receiveGreenlist";
|
|
123
|
+
readonly inputs: readonly [];
|
|
124
|
+
readonly outputs: readonly [{
|
|
125
|
+
readonly name: "";
|
|
126
|
+
readonly type: "bool";
|
|
127
|
+
readonly internalType: "bool";
|
|
128
|
+
}];
|
|
129
|
+
readonly stateMutability: "nonpayable";
|
|
120
130
|
}, {
|
|
121
131
|
readonly type: "function";
|
|
122
132
|
readonly name: "redeemInstant";
|
|
@@ -123,6 +123,16 @@ declare const abi: readonly [{
|
|
|
123
123
|
readonly internalType: "address";
|
|
124
124
|
}];
|
|
125
125
|
readonly stateMutability: "view";
|
|
126
|
+
}, {
|
|
127
|
+
readonly type: "function";
|
|
128
|
+
readonly name: "receiveGreenlist";
|
|
129
|
+
readonly inputs: readonly [];
|
|
130
|
+
readonly outputs: readonly [{
|
|
131
|
+
readonly name: "";
|
|
132
|
+
readonly type: "bool";
|
|
133
|
+
readonly internalType: "bool";
|
|
134
|
+
}];
|
|
135
|
+
readonly stateMutability: "nonpayable";
|
|
126
136
|
}, {
|
|
127
137
|
readonly type: "function";
|
|
128
138
|
readonly name: "redeemInstant";
|