@gearbox-protocol/sdk 16.5.1 → 16.6.0-next.1
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/claimFromFaucet.js +4 -8
- package/dist/cjs/dev/createAnvilClient.js +35 -17
- package/dist/cjs/dev/index.js +1 -0
- package/dist/cjs/onchain/accounts/CreditAccountsServiceV310.js +1 -14
- package/dist/cjs/onchain/market/adapters/contracts/AbstractAdapter.js +6 -0
- package/dist/cjs/onchain/market/adapters/contracts/MidasGatewayAdapterContract.js +41 -5
- package/dist/cjs/onchain/market/credit/CreditSuite.js +7 -0
- package/dist/esm/dev/claimFromFaucet.js +4 -8
- package/dist/esm/dev/createAnvilClient.js +36 -19
- package/dist/esm/dev/index.js +2 -2
- package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +1 -14
- package/dist/esm/onchain/market/adapters/contracts/AbstractAdapter.js +6 -0
- package/dist/esm/onchain/market/adapters/contracts/MidasGatewayAdapterContract.js +42 -6
- package/dist/esm/onchain/market/credit/CreditSuite.js +7 -0
- package/dist/types/dev/claimFromFaucet.d.ts +0 -1
- package/dist/types/dev/createAnvilClient.d.ts +10 -3
- package/dist/types/dev/index.d.ts +2 -2
- package/dist/types/onchain/market/adapters/contracts/AbstractAdapter.d.ts +6 -0
- package/dist/types/onchain/market/adapters/contracts/MidasGatewayAdapterContract.d.ts +15 -5
- package/dist/types/onchain/market/adapters/types.d.ts +8 -0
- package/dist/types/onchain/market/credit/CreditSuite.d.ts +5 -0
- package/package.json +1 -1
- package/dist/cjs/onchain/accounts/utils/midasUtils.js +0 -76
- package/dist/esm/onchain/accounts/utils/midasUtils.js +0 -75
- package/dist/types/onchain/accounts/utils/midasUtils.d.ts +0 -39
|
@@ -5,7 +5,7 @@ const require_dev_abi = require("./abi.js");
|
|
|
5
5
|
let viem_actions = require("viem/actions");
|
|
6
6
|
//#region src/dev/claimFromFaucet.ts
|
|
7
7
|
async function claimFromFaucet(opts) {
|
|
8
|
-
const { sdk, publicClient, wallet, faucet, claimer, role, amount, logger, gasMultiplier = 10n
|
|
8
|
+
const { sdk, publicClient, wallet, faucet, claimer, role, amount, logger, gasMultiplier = 10n } = opts;
|
|
9
9
|
let amnt = "default amount";
|
|
10
10
|
let args;
|
|
11
11
|
if (Array.isArray(amount)) {
|
|
@@ -54,13 +54,9 @@ async function claimFromFaucet(opts) {
|
|
|
54
54
|
gas: gas * gasMultiplier
|
|
55
55
|
});
|
|
56
56
|
logger?.debug({ request }, "simulated claim tx request");
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const hash = await wallet.writeContract(request);
|
|
61
|
-
logger?.debug({ hash }, "claim tx hash");
|
|
62
|
-
receipt = await publicClient.waitForTransactionReceipt({ hash });
|
|
63
|
-
}
|
|
57
|
+
const hash = await wallet.writeContract(request);
|
|
58
|
+
logger?.debug({ hash }, "claim tx hash");
|
|
59
|
+
const receipt = await publicClient.waitForTransactionReceipt({ hash });
|
|
64
60
|
if (receipt.status === "reverted") throw new Error(`${usr} failed to claimed ${amnt} from faucet, tx: ${receipt.transactionHash}`);
|
|
65
61
|
logger?.debug(`${usr} claimed ${amnt} from faucet, tx: ${receipt.transactionHash}`);
|
|
66
62
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
let viem = require("viem");
|
|
3
|
+
let viem_utils = require("viem/utils");
|
|
4
|
+
let viem_actions = require("viem/actions");
|
|
3
5
|
//#region src/dev/createAnvilClient.ts
|
|
4
6
|
let dealModulePromise;
|
|
5
7
|
async function loadDeal() {
|
|
@@ -8,23 +10,27 @@ async function loadDeal() {
|
|
|
8
10
|
if (!mod) throw new Error("createAnvilClient: deal action requires the 'viem-deal' package; install it as a dependency");
|
|
9
11
|
return mod.deal;
|
|
10
12
|
}
|
|
13
|
+
function anvilActions(client) {
|
|
14
|
+
return {
|
|
15
|
+
anvilNodeInfo: () => anvilNodeInfo(client),
|
|
16
|
+
isAnvil: () => isAnvil(client),
|
|
17
|
+
evmMineDetailed: (timestamp) => evmMineDetailed(client, timestamp),
|
|
18
|
+
deal: async (params) => {
|
|
19
|
+
await (await loadDeal())(client, params);
|
|
20
|
+
},
|
|
21
|
+
writeContractSync: (parameters) => writeContractSync(client, parameters)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
11
24
|
/**
|
|
12
25
|
* Extends an arbitrary viem `PublicClient` with anvil + wallet actions plus
|
|
13
26
|
* the SDK's bonus actions (`anvilNodeInfo`, `isAnvil`, `evmMineDetailed`,
|
|
14
|
-
* `deal`).
|
|
27
|
+
* `deal`, `writeContractSync`).
|
|
15
28
|
*
|
|
16
29
|
* Used to lift `sdk.client` into an `AnvilClient` shape on the fly when test
|
|
17
30
|
* RPCs (impersonateAccount, setBalance, setStorageAt, ...) are needed.
|
|
18
31
|
*/
|
|
19
32
|
function extendAnvilClient(client) {
|
|
20
|
-
return client.extend(() => ({ mode: "anvil" })).extend((0, viem.testActions)({ mode: "anvil" })).extend(viem.walletActions).extend((c) => (
|
|
21
|
-
anvilNodeInfo: () => anvilNodeInfo(c),
|
|
22
|
-
isAnvil: () => isAnvil(c),
|
|
23
|
-
evmMineDetailed: (timestamp) => evmMineDetailed(c, timestamp),
|
|
24
|
-
deal: async (params) => {
|
|
25
|
-
await (await loadDeal())(c, params);
|
|
26
|
-
}
|
|
27
|
-
}));
|
|
33
|
+
return client.extend(() => ({ mode: "anvil" })).extend((0, viem.testActions)({ mode: "anvil" })).extend(viem.walletActions).extend((c) => anvilActions(c));
|
|
28
34
|
}
|
|
29
35
|
function createAnvilClient({ chain, transport, cacheTime = 0, pollingInterval = 50 }) {
|
|
30
36
|
return (0, viem.createTestClient)({
|
|
@@ -33,14 +39,7 @@ function createAnvilClient({ chain, transport, cacheTime = 0, pollingInterval =
|
|
|
33
39
|
transport,
|
|
34
40
|
cacheTime,
|
|
35
41
|
pollingInterval
|
|
36
|
-
}).extend(viem.publicActions).extend(viem.walletActions).extend((c) => (
|
|
37
|
-
anvilNodeInfo: () => anvilNodeInfo(c),
|
|
38
|
-
isAnvil: () => isAnvil(c),
|
|
39
|
-
evmMineDetailed: (timestamp) => evmMineDetailed(c, timestamp),
|
|
40
|
-
deal: async (params) => {
|
|
41
|
-
await (await loadDeal())(c, params);
|
|
42
|
-
}
|
|
43
|
-
}));
|
|
42
|
+
}).extend(viem.publicActions).extend(viem.walletActions).extend((c) => anvilActions(c));
|
|
44
43
|
}
|
|
45
44
|
/**
|
|
46
45
|
* View action to detect if client is an anvil client
|
|
@@ -85,9 +84,28 @@ async function evmMineDetailed(client, timestamp) {
|
|
|
85
84
|
return;
|
|
86
85
|
}
|
|
87
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Anvil-compatible `writeContractSync`: send via `writeContract` (Anvil
|
|
89
|
+
* supports `eth_sendTransaction` / `eth_sendRawTransaction`) then wait for
|
|
90
|
+
* the receipt. Viem's own action uses `eth_sendRawTransactionSync`, which
|
|
91
|
+
* Anvil does not implement.
|
|
92
|
+
*/
|
|
93
|
+
async function writeContractSync(client, parameters) {
|
|
94
|
+
const { throwOnReceiptRevert, pollingInterval, timeout, ...writeParams } = parameters;
|
|
95
|
+
const hash = await (0, viem_utils.getAction)(client, viem_actions.writeContract, "writeContract")(writeParams);
|
|
96
|
+
const receipt = await (0, viem_utils.getAction)(client, viem_actions.waitForTransactionReceipt, "waitForTransactionReceipt")({
|
|
97
|
+
checkReplacement: false,
|
|
98
|
+
hash,
|
|
99
|
+
pollingInterval,
|
|
100
|
+
timeout
|
|
101
|
+
});
|
|
102
|
+
if (throwOnReceiptRevert && receipt.status === "reverted") throw new viem.BaseError(`Transaction with hash "${receipt.transactionHash}" reverted.`, { name: "TransactionReceiptRevertedError" });
|
|
103
|
+
return receipt;
|
|
104
|
+
}
|
|
88
105
|
//#endregion
|
|
89
106
|
exports.anvilNodeInfo = anvilNodeInfo;
|
|
90
107
|
exports.createAnvilClient = createAnvilClient;
|
|
91
108
|
exports.evmMineDetailed = evmMineDetailed;
|
|
92
109
|
exports.extendAnvilClient = extendAnvilClient;
|
|
93
110
|
exports.isAnvil = isAnvil;
|
|
111
|
+
exports.writeContractSync = writeContractSync;
|
package/dist/cjs/dev/index.js
CHANGED
|
@@ -88,3 +88,4 @@ exports.setLTZero = require_dev_ltUtils.setLTZero;
|
|
|
88
88
|
exports.setLTs = require_dev_ltUtils.setLTs;
|
|
89
89
|
exports.unpauseMidasIssuanceVault = require_dev_midasUtils.unpauseMidasIssuanceVault;
|
|
90
90
|
exports.verifyTestnet = require_dev_verifyTestnet.verifyTestnet;
|
|
91
|
+
exports.writeContractSync = require_dev_createAnvilClient.writeContractSync;
|
|
@@ -16,7 +16,6 @@ require("../market/index.js");
|
|
|
16
16
|
const require_onchain_accounts_credit_account_compressor_CreditAccountCompressor = require("./credit-account-compressor/CreditAccountCompressor.js");
|
|
17
17
|
require("./credit-account-compressor/index.js");
|
|
18
18
|
const require_onchain_accounts_multicall_utils = require("./multicall-utils.js");
|
|
19
|
-
const require_onchain_accounts_utils_midasUtils = require("./utils/midasUtils.js");
|
|
20
19
|
let viem = require("viem");
|
|
21
20
|
//#region src/onchain/accounts/CreditAccountsServiceV310.ts
|
|
22
21
|
/**
|
|
@@ -213,7 +212,7 @@ var CreditAccountsServiceV310 = class extends require_onchain_base_SDKConstruct.
|
|
|
213
212
|
}),
|
|
214
213
|
...callsAfter ?? []
|
|
215
214
|
];
|
|
216
|
-
calls = await
|
|
215
|
+
calls = [...await cmSuite.openingCalls(), ...calls];
|
|
217
216
|
calls = await this.prependPriceUpdates(cm.address, calls);
|
|
218
217
|
const tx = reopenCreditAccount ? cmSuite.multicallTx(reopenCreditAccount, calls, rwaOptions) : cmSuite.openCreditAccountTx(to, calls, referralCode, rwaOptions);
|
|
219
218
|
tx.value = ethAmount.toString(10);
|
|
@@ -440,18 +439,6 @@ var CreditAccountsServiceV310 = class extends require_onchain_base_SDKConstruct.
|
|
|
440
439
|
return this.sdk.addressProvider.mustGetLatest(require_onchain_constants_address_provider.AP_REWARDS_COMPRESSOR, require_onchain_constants_versions.VERSION_RANGE_310)[0];
|
|
441
440
|
}
|
|
442
441
|
/**
|
|
443
|
-
* {@inheritDoc ICreditAccountsService.prependMidasReceiveGreenlist}
|
|
444
|
-
*/
|
|
445
|
-
async #prependMidasReceiveGreenlist(creditManager, calls) {
|
|
446
|
-
const cm = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
447
|
-
return require_onchain_accounts_utils_midasUtils.prependMidasReceiveGreenlist({
|
|
448
|
-
cm,
|
|
449
|
-
client: this.client,
|
|
450
|
-
calls,
|
|
451
|
-
logger: this.logger
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
/**
|
|
455
442
|
* Withdrawal compressor of the current chain.
|
|
456
443
|
* @throws If no withdrawal compressor is supported on the current chain.
|
|
457
444
|
**/
|
|
@@ -129,6 +129,12 @@ var AbstractAdapterContract = class extends require_onchain_base_BaseContract.Ba
|
|
|
129
129
|
return false;
|
|
130
130
|
}
|
|
131
131
|
/**
|
|
132
|
+
* {@inheritDoc IAdapterContract.openingCalls}
|
|
133
|
+
*/
|
|
134
|
+
async openingCalls() {
|
|
135
|
+
return [];
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
132
138
|
* Applies the balance changes of a decoded adapter call to the running
|
|
133
139
|
* balances, mutating them in place. Overrides should express changes via
|
|
134
140
|
* {@link setLeftover} (diff-style calls) and {@link spendExact}
|
|
@@ -14,6 +14,12 @@ const receiveGreenlistCalldata = (0, viem.encodeFunctionData)({
|
|
|
14
14
|
abi,
|
|
15
15
|
functionName: "receiveGreenlist"
|
|
16
16
|
});
|
|
17
|
+
const MGLOBAL_MTOKEN = (0, viem.getAddress)("0x7433806912Eae67919e66aea853d46Fa0aef98A8");
|
|
18
|
+
/**
|
|
19
|
+
* Permissionless gateways have no greenlist and reject `receiveGreenlist`,
|
|
20
|
+
* see MidasMode in integrations-v3
|
|
21
|
+
*/
|
|
22
|
+
const MIDAS_MODE_PERMISSIONLESS = 0;
|
|
17
23
|
var MidasGatewayAdapterContract = class extends require_onchain_market_adapters_contracts_AbstractAdapter.AbstractAdapterContract {
|
|
18
24
|
#version;
|
|
19
25
|
#gateway;
|
|
@@ -21,6 +27,7 @@ var MidasGatewayAdapterContract = class extends require_onchain_market_adapters_
|
|
|
21
27
|
#quoteToken;
|
|
22
28
|
#phantomToken;
|
|
23
29
|
#referrerId;
|
|
30
|
+
#mode;
|
|
24
31
|
constructor(sdk, args) {
|
|
25
32
|
super(sdk, {
|
|
26
33
|
...args,
|
|
@@ -126,6 +133,35 @@ var MidasGatewayAdapterContract = class extends require_onchain_market_adapters_
|
|
|
126
133
|
if (this.#referrerId === void 0) throw new require_onchain_base_errors.MissingSerializedParamsError("referrerId");
|
|
127
134
|
return this.#referrerId;
|
|
128
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Gateway `mode` is immutable on-chain, so the first read is reused.
|
|
138
|
+
*/
|
|
139
|
+
async mode() {
|
|
140
|
+
if (!this.#mode) this.#mode = this.client.readContract({
|
|
141
|
+
address: this.targetContract,
|
|
142
|
+
abi: this.protocolAbi,
|
|
143
|
+
functionName: "mode"
|
|
144
|
+
});
|
|
145
|
+
return this.#mode;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* {@inheritDoc IAdapterContract.openingCalls}
|
|
149
|
+
*/
|
|
150
|
+
async openingCalls() {
|
|
151
|
+
if ((0, viem.isAddressEqual)(this.mToken, MGLOBAL_MTOKEN)) {
|
|
152
|
+
this.logger?.debug(`midas: skipping receiveGreenlist for mGLOBAL ${this.mToken}`);
|
|
153
|
+
return [];
|
|
154
|
+
}
|
|
155
|
+
if (await this.mode() === MIDAS_MODE_PERMISSIONLESS) {
|
|
156
|
+
this.logger?.debug(`midas: gateway ${this.targetContract} is permissionless, nothing to greenlist`);
|
|
157
|
+
return [];
|
|
158
|
+
}
|
|
159
|
+
this.logger?.debug(`midas: greenlisting the credit account via gateway adapter ${this.address}`);
|
|
160
|
+
return [{
|
|
161
|
+
target: this.address,
|
|
162
|
+
callData: receiveGreenlistCalldata
|
|
163
|
+
}];
|
|
164
|
+
}
|
|
129
165
|
stateHuman(raw) {
|
|
130
166
|
return {
|
|
131
167
|
...super.stateHuman(raw),
|
|
@@ -177,11 +213,11 @@ var MidasGatewayAdapterContract = class extends require_onchain_market_adapters_
|
|
|
177
213
|
return calldata === receiveGreenlistCalldata;
|
|
178
214
|
}
|
|
179
215
|
/**
|
|
180
|
-
* `receiveGreenlist()` is prepended by
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
216
|
+
* `receiveGreenlist()` is prepended by {@link openingCalls} before the
|
|
217
|
+
* balance bracket when a permissioned mToken is minted: it only grants
|
|
218
|
+
* the Midas greenlisted role to the credit account and is
|
|
219
|
+
* balance-neutral, so it is legal outside a bracket and leaves balances
|
|
220
|
+
* untouched.
|
|
185
221
|
*/
|
|
186
222
|
replayOutOfBracketCall(_balances, calldata) {
|
|
187
223
|
return this.isReceiveGreenlist(calldata);
|
|
@@ -179,6 +179,13 @@ var CreditSuite = class extends require_onchain_base_SDKConstruct.SDKConstruct {
|
|
|
179
179
|
return rwaFactory ? rwaFactory.openCreditAccount(this.creditManager.address, calls, rwaOptions) : this.creditFacade.openCreditAccount(to, calls, referralCode ?? 0n);
|
|
180
180
|
}
|
|
181
181
|
/**
|
|
182
|
+
* Calls to run first in the multicall of a freshly opened account on this
|
|
183
|
+
* suite; use before {@link openCreditAccountTx}.
|
|
184
|
+
*/
|
|
185
|
+
async openingCalls() {
|
|
186
|
+
return (await Promise.all(this.creditManager.adapters.values().map((a) => a.openingCalls()))).flat();
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
182
189
|
* Router configured for this credit suite.
|
|
183
190
|
*/
|
|
184
191
|
get router() {
|
|
@@ -4,7 +4,7 @@ import { iFaucetAbi } from "./abi.js";
|
|
|
4
4
|
import { readContract } from "viem/actions";
|
|
5
5
|
//#region src/dev/claimFromFaucet.ts
|
|
6
6
|
async function claimFromFaucet(opts) {
|
|
7
|
-
const { sdk, publicClient, wallet, faucet, claimer, role, amount, logger, gasMultiplier = 10n
|
|
7
|
+
const { sdk, publicClient, wallet, faucet, claimer, role, amount, logger, gasMultiplier = 10n } = opts;
|
|
8
8
|
let amnt = "default amount";
|
|
9
9
|
let args;
|
|
10
10
|
if (Array.isArray(amount)) {
|
|
@@ -53,13 +53,9 @@ async function claimFromFaucet(opts) {
|
|
|
53
53
|
gas: gas * gasMultiplier
|
|
54
54
|
});
|
|
55
55
|
logger?.debug({ request }, "simulated claim tx request");
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const hash = await wallet.writeContract(request);
|
|
60
|
-
logger?.debug({ hash }, "claim tx hash");
|
|
61
|
-
receipt = await publicClient.waitForTransactionReceipt({ hash });
|
|
62
|
-
}
|
|
56
|
+
const hash = await wallet.writeContract(request);
|
|
57
|
+
logger?.debug({ hash }, "claim tx hash");
|
|
58
|
+
const receipt = await publicClient.waitForTransactionReceipt({ hash });
|
|
63
59
|
if (receipt.status === "reverted") throw new Error(`${usr} failed to claimed ${amnt} from faucet, tx: ${receipt.transactionHash}`);
|
|
64
60
|
logger?.debug(`${usr} claimed ${amnt} from faucet, tx: ${receipt.transactionHash}`);
|
|
65
61
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { createTestClient, publicActions, testActions, toHex, walletActions } from "viem";
|
|
1
|
+
import { BaseError, createTestClient, publicActions, testActions, toHex, walletActions } from "viem";
|
|
2
|
+
import { getAction } from "viem/utils";
|
|
3
|
+
import { waitForTransactionReceipt, writeContract } from "viem/actions";
|
|
2
4
|
//#region src/dev/createAnvilClient.ts
|
|
3
5
|
let dealModulePromise;
|
|
4
6
|
async function loadDeal() {
|
|
@@ -7,23 +9,27 @@ async function loadDeal() {
|
|
|
7
9
|
if (!mod) throw new Error("createAnvilClient: deal action requires the 'viem-deal' package; install it as a dependency");
|
|
8
10
|
return mod.deal;
|
|
9
11
|
}
|
|
12
|
+
function anvilActions(client) {
|
|
13
|
+
return {
|
|
14
|
+
anvilNodeInfo: () => anvilNodeInfo(client),
|
|
15
|
+
isAnvil: () => isAnvil(client),
|
|
16
|
+
evmMineDetailed: (timestamp) => evmMineDetailed(client, timestamp),
|
|
17
|
+
deal: async (params) => {
|
|
18
|
+
await (await loadDeal())(client, params);
|
|
19
|
+
},
|
|
20
|
+
writeContractSync: (parameters) => writeContractSync(client, parameters)
|
|
21
|
+
};
|
|
22
|
+
}
|
|
10
23
|
/**
|
|
11
24
|
* Extends an arbitrary viem `PublicClient` with anvil + wallet actions plus
|
|
12
25
|
* the SDK's bonus actions (`anvilNodeInfo`, `isAnvil`, `evmMineDetailed`,
|
|
13
|
-
* `deal`).
|
|
26
|
+
* `deal`, `writeContractSync`).
|
|
14
27
|
*
|
|
15
28
|
* Used to lift `sdk.client` into an `AnvilClient` shape on the fly when test
|
|
16
29
|
* RPCs (impersonateAccount, setBalance, setStorageAt, ...) are needed.
|
|
17
30
|
*/
|
|
18
31
|
function extendAnvilClient(client) {
|
|
19
|
-
return client.extend(() => ({ mode: "anvil" })).extend(testActions({ mode: "anvil" })).extend(walletActions).extend((c) => (
|
|
20
|
-
anvilNodeInfo: () => anvilNodeInfo(c),
|
|
21
|
-
isAnvil: () => isAnvil(c),
|
|
22
|
-
evmMineDetailed: (timestamp) => evmMineDetailed(c, timestamp),
|
|
23
|
-
deal: async (params) => {
|
|
24
|
-
await (await loadDeal())(c, params);
|
|
25
|
-
}
|
|
26
|
-
}));
|
|
32
|
+
return client.extend(() => ({ mode: "anvil" })).extend(testActions({ mode: "anvil" })).extend(walletActions).extend((c) => anvilActions(c));
|
|
27
33
|
}
|
|
28
34
|
function createAnvilClient({ chain, transport, cacheTime = 0, pollingInterval = 50 }) {
|
|
29
35
|
return createTestClient({
|
|
@@ -32,14 +38,7 @@ function createAnvilClient({ chain, transport, cacheTime = 0, pollingInterval =
|
|
|
32
38
|
transport,
|
|
33
39
|
cacheTime,
|
|
34
40
|
pollingInterval
|
|
35
|
-
}).extend(publicActions).extend(walletActions).extend((c) => (
|
|
36
|
-
anvilNodeInfo: () => anvilNodeInfo(c),
|
|
37
|
-
isAnvil: () => isAnvil(c),
|
|
38
|
-
evmMineDetailed: (timestamp) => evmMineDetailed(c, timestamp),
|
|
39
|
-
deal: async (params) => {
|
|
40
|
-
await (await loadDeal())(c, params);
|
|
41
|
-
}
|
|
42
|
-
}));
|
|
41
|
+
}).extend(publicActions).extend(walletActions).extend((c) => anvilActions(c));
|
|
43
42
|
}
|
|
44
43
|
/**
|
|
45
44
|
* View action to detect if client is an anvil client
|
|
@@ -84,5 +83,23 @@ async function evmMineDetailed(client, timestamp) {
|
|
|
84
83
|
return;
|
|
85
84
|
}
|
|
86
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Anvil-compatible `writeContractSync`: send via `writeContract` (Anvil
|
|
88
|
+
* supports `eth_sendTransaction` / `eth_sendRawTransaction`) then wait for
|
|
89
|
+
* the receipt. Viem's own action uses `eth_sendRawTransactionSync`, which
|
|
90
|
+
* Anvil does not implement.
|
|
91
|
+
*/
|
|
92
|
+
async function writeContractSync(client, parameters) {
|
|
93
|
+
const { throwOnReceiptRevert, pollingInterval, timeout, ...writeParams } = parameters;
|
|
94
|
+
const hash = await getAction(client, writeContract, "writeContract")(writeParams);
|
|
95
|
+
const receipt = await getAction(client, waitForTransactionReceipt, "waitForTransactionReceipt")({
|
|
96
|
+
checkReplacement: false,
|
|
97
|
+
hash,
|
|
98
|
+
pollingInterval,
|
|
99
|
+
timeout
|
|
100
|
+
});
|
|
101
|
+
if (throwOnReceiptRevert && receipt.status === "reverted") throw new BaseError(`Transaction with hash "${receipt.transactionHash}" reverted.`, { name: "TransactionReceiptRevertedError" });
|
|
102
|
+
return receipt;
|
|
103
|
+
}
|
|
87
104
|
//#endregion
|
|
88
|
-
export { anvilNodeInfo, createAnvilClient, evmMineDetailed, extendAnvilClient, isAnvil };
|
|
105
|
+
export { anvilNodeInfo, createAnvilClient, evmMineDetailed, extendAnvilClient, isAnvil, writeContractSync };
|
package/dist/esm/dev/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { iDegenNftv2Abi, iFaucetAbi, iOnchainExecutionIdAbi, iOwnableAbi, iaclTraitAbi } from "./abi.js";
|
|
2
2
|
import { claimFromFaucet } from "./claimFromFaucet.js";
|
|
3
|
-
import { anvilNodeInfo, createAnvilClient, evmMineDetailed, extendAnvilClient, isAnvil } from "./createAnvilClient.js";
|
|
3
|
+
import { anvilNodeInfo, createAnvilClient, evmMineDetailed, extendAnvilClient, isAnvil, writeContractSync } from "./createAnvilClient.js";
|
|
4
4
|
import { createMinter } from "./mint/factory.js";
|
|
5
5
|
import "./mint/index.js";
|
|
6
6
|
import { AccountOpener, OpenTxRevertedError } from "./AccountOpener.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, collectMidasGateways, collectMidasMTokens, createAnvilClient, createMinter, deployUsingPublicCreate2, detectChain, enableDSTokenBackDating, evmMineDetailed, extendAnvilClient, getAlchemyUrl, getAnkrUrl, getDrpcUrl, getErpcKey, getPublicCreate2Address, getRpcProviderUrl, 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 };
|
|
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, collectMidasGateways, collectMidasMTokens, createAnvilClient, createMinter, deployUsingPublicCreate2, detectChain, enableDSTokenBackDating, evmMineDetailed, extendAnvilClient, getAlchemyUrl, getAnkrUrl, getDrpcUrl, getErpcKey, getPublicCreate2Address, getRpcProviderUrl, 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 };
|
|
@@ -15,7 +15,6 @@ import "../market/index.js";
|
|
|
15
15
|
import { CreditAccountCompressor } from "./credit-account-compressor/CreditAccountCompressor.js";
|
|
16
16
|
import "./credit-account-compressor/index.js";
|
|
17
17
|
import { extractPriceUpdates, extractQuotaTokens, mergePriceUpdates } from "./multicall-utils.js";
|
|
18
|
-
import { prependMidasReceiveGreenlist } from "./utils/midasUtils.js";
|
|
19
18
|
import { encodeFunctionData } from "viem";
|
|
20
19
|
//#region src/onchain/accounts/CreditAccountsServiceV310.ts
|
|
21
20
|
/**
|
|
@@ -212,7 +211,7 @@ var CreditAccountsServiceV310 = class extends SDKConstruct {
|
|
|
212
211
|
}),
|
|
213
212
|
...callsAfter ?? []
|
|
214
213
|
];
|
|
215
|
-
calls = await
|
|
214
|
+
calls = [...await cmSuite.openingCalls(), ...calls];
|
|
216
215
|
calls = await this.prependPriceUpdates(cm.address, calls);
|
|
217
216
|
const tx = reopenCreditAccount ? cmSuite.multicallTx(reopenCreditAccount, calls, rwaOptions) : cmSuite.openCreditAccountTx(to, calls, referralCode, rwaOptions);
|
|
218
217
|
tx.value = ethAmount.toString(10);
|
|
@@ -439,18 +438,6 @@ var CreditAccountsServiceV310 = class extends SDKConstruct {
|
|
|
439
438
|
return this.sdk.addressProvider.mustGetLatest(AP_REWARDS_COMPRESSOR, VERSION_RANGE_310)[0];
|
|
440
439
|
}
|
|
441
440
|
/**
|
|
442
|
-
* {@inheritDoc ICreditAccountsService.prependMidasReceiveGreenlist}
|
|
443
|
-
*/
|
|
444
|
-
async #prependMidasReceiveGreenlist(creditManager, calls) {
|
|
445
|
-
const cm = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
446
|
-
return prependMidasReceiveGreenlist({
|
|
447
|
-
cm,
|
|
448
|
-
client: this.client,
|
|
449
|
-
calls,
|
|
450
|
-
logger: this.logger
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
/**
|
|
454
441
|
* Withdrawal compressor of the current chain.
|
|
455
442
|
* @throws If no withdrawal compressor is supported on the current chain.
|
|
456
443
|
**/
|
|
@@ -128,6 +128,12 @@ var AbstractAdapterContract = class extends BaseContract {
|
|
|
128
128
|
return false;
|
|
129
129
|
}
|
|
130
130
|
/**
|
|
131
|
+
* {@inheritDoc IAdapterContract.openingCalls}
|
|
132
|
+
*/
|
|
133
|
+
async openingCalls() {
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
131
137
|
* Applies the balance changes of a decoded adapter call to the running
|
|
132
138
|
* balances, mutating them in place. Overrides should express changes via
|
|
133
139
|
* {@link setLeftover} (diff-style calls) and {@link spendExact}
|
|
@@ -5,7 +5,7 @@ import "../abi/adapters/index.js";
|
|
|
5
5
|
import { iMidasGatewayV311Abi } from "../abi/midas/iMidasGatewayV311.js";
|
|
6
6
|
import "../abi/index.js";
|
|
7
7
|
import { AbstractAdapterContract } from "./AbstractAdapter.js";
|
|
8
|
-
import { decodeAbiParameters, decodeFunctionData, encodeFunctionData, isAddressEqual, zeroAddress } from "viem";
|
|
8
|
+
import { decodeAbiParameters, decodeFunctionData, encodeFunctionData, getAddress, isAddressEqual, zeroAddress } from "viem";
|
|
9
9
|
//#region src/onchain/market/adapters/contracts/MidasGatewayAdapterContract.ts
|
|
10
10
|
const abi = iMidasGatewayAdapterV311Abi;
|
|
11
11
|
const protocolAbi = iMidasGatewayV311Abi;
|
|
@@ -13,6 +13,12 @@ const receiveGreenlistCalldata = encodeFunctionData({
|
|
|
13
13
|
abi,
|
|
14
14
|
functionName: "receiveGreenlist"
|
|
15
15
|
});
|
|
16
|
+
const MGLOBAL_MTOKEN = getAddress("0x7433806912Eae67919e66aea853d46Fa0aef98A8");
|
|
17
|
+
/**
|
|
18
|
+
* Permissionless gateways have no greenlist and reject `receiveGreenlist`,
|
|
19
|
+
* see MidasMode in integrations-v3
|
|
20
|
+
*/
|
|
21
|
+
const MIDAS_MODE_PERMISSIONLESS = 0;
|
|
16
22
|
var MidasGatewayAdapterContract = class extends AbstractAdapterContract {
|
|
17
23
|
#version;
|
|
18
24
|
#gateway;
|
|
@@ -20,6 +26,7 @@ var MidasGatewayAdapterContract = class extends AbstractAdapterContract {
|
|
|
20
26
|
#quoteToken;
|
|
21
27
|
#phantomToken;
|
|
22
28
|
#referrerId;
|
|
29
|
+
#mode;
|
|
23
30
|
constructor(sdk, args) {
|
|
24
31
|
super(sdk, {
|
|
25
32
|
...args,
|
|
@@ -125,6 +132,35 @@ var MidasGatewayAdapterContract = class extends AbstractAdapterContract {
|
|
|
125
132
|
if (this.#referrerId === void 0) throw new MissingSerializedParamsError("referrerId");
|
|
126
133
|
return this.#referrerId;
|
|
127
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Gateway `mode` is immutable on-chain, so the first read is reused.
|
|
137
|
+
*/
|
|
138
|
+
async mode() {
|
|
139
|
+
if (!this.#mode) this.#mode = this.client.readContract({
|
|
140
|
+
address: this.targetContract,
|
|
141
|
+
abi: this.protocolAbi,
|
|
142
|
+
functionName: "mode"
|
|
143
|
+
});
|
|
144
|
+
return this.#mode;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* {@inheritDoc IAdapterContract.openingCalls}
|
|
148
|
+
*/
|
|
149
|
+
async openingCalls() {
|
|
150
|
+
if (isAddressEqual(this.mToken, MGLOBAL_MTOKEN)) {
|
|
151
|
+
this.logger?.debug(`midas: skipping receiveGreenlist for mGLOBAL ${this.mToken}`);
|
|
152
|
+
return [];
|
|
153
|
+
}
|
|
154
|
+
if (await this.mode() === MIDAS_MODE_PERMISSIONLESS) {
|
|
155
|
+
this.logger?.debug(`midas: gateway ${this.targetContract} is permissionless, nothing to greenlist`);
|
|
156
|
+
return [];
|
|
157
|
+
}
|
|
158
|
+
this.logger?.debug(`midas: greenlisting the credit account via gateway adapter ${this.address}`);
|
|
159
|
+
return [{
|
|
160
|
+
target: this.address,
|
|
161
|
+
callData: receiveGreenlistCalldata
|
|
162
|
+
}];
|
|
163
|
+
}
|
|
128
164
|
stateHuman(raw) {
|
|
129
165
|
return {
|
|
130
166
|
...super.stateHuman(raw),
|
|
@@ -176,11 +212,11 @@ var MidasGatewayAdapterContract = class extends AbstractAdapterContract {
|
|
|
176
212
|
return calldata === receiveGreenlistCalldata;
|
|
177
213
|
}
|
|
178
214
|
/**
|
|
179
|
-
* `receiveGreenlist()` is prepended by
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
215
|
+
* `receiveGreenlist()` is prepended by {@link openingCalls} before the
|
|
216
|
+
* balance bracket when a permissioned mToken is minted: it only grants
|
|
217
|
+
* the Midas greenlisted role to the credit account and is
|
|
218
|
+
* balance-neutral, so it is legal outside a bracket and leaves balances
|
|
219
|
+
* untouched.
|
|
184
220
|
*/
|
|
185
221
|
replayOutOfBracketCall(_balances, calldata) {
|
|
186
222
|
return this.isReceiveGreenlist(calldata);
|
|
@@ -178,6 +178,13 @@ var CreditSuite = class extends SDKConstruct {
|
|
|
178
178
|
return rwaFactory ? rwaFactory.openCreditAccount(this.creditManager.address, calls, rwaOptions) : this.creditFacade.openCreditAccount(to, calls, referralCode ?? 0n);
|
|
179
179
|
}
|
|
180
180
|
/**
|
|
181
|
+
* Calls to run first in the multicall of a freshly opened account on this
|
|
182
|
+
* suite; use before {@link openCreditAccountTx}.
|
|
183
|
+
*/
|
|
184
|
+
async openingCalls() {
|
|
185
|
+
return (await Promise.all(this.creditManager.adapters.values().map((a) => a.openingCalls()))).flat();
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
181
188
|
* Router configured for this credit suite.
|
|
182
189
|
*/
|
|
183
190
|
get router() {
|
|
@@ -24,7 +24,6 @@ interface ClaimFromFaucetOptions {
|
|
|
24
24
|
amount?: TokenClaim[] | bigint | ((minAmountUSD: bigint) => bigint);
|
|
25
25
|
gasMultiplier?: bigint;
|
|
26
26
|
logger?: ILogger;
|
|
27
|
-
sync?: boolean;
|
|
28
27
|
}
|
|
29
28
|
declare function claimFromFaucet(opts: ClaimFromFaucetOptions): Promise<void>;
|
|
30
29
|
//#endregion
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Account, Address, Block, Chain, Client, Hex, Prettify, PublicClient, TestActions, TestRpcSchema, Transport, WalletClient } from "viem";
|
|
1
|
+
import { Abi, Account, Address, Block, Chain, Client, ContractFunctionArgs, ContractFunctionName, Hex, Prettify, PublicClient, TestActions, TestRpcSchema, Transport, WalletClient, WriteContractSyncParameters, WriteContractSyncReturnType } from "viem";
|
|
2
2
|
//#region src/dev/createAnvilClient.d.ts
|
|
3
3
|
interface AnvilNodeInfo {
|
|
4
4
|
currentBlockNumber: string;
|
|
@@ -67,7 +67,7 @@ interface AnvilClientConfig<transport extends Transport = Transport, chain exten
|
|
|
67
67
|
/**
|
|
68
68
|
* Extends an arbitrary viem `PublicClient` with anvil + wallet actions plus
|
|
69
69
|
* the SDK's bonus actions (`anvilNodeInfo`, `isAnvil`, `evmMineDetailed`,
|
|
70
|
-
* `deal`).
|
|
70
|
+
* `deal`, `writeContractSync`).
|
|
71
71
|
*
|
|
72
72
|
* Used to lift `sdk.client` into an `AnvilClient` shape on the fly when test
|
|
73
73
|
* RPCs (impersonateAccount, setBalance, setStorageAt, ...) are needed.
|
|
@@ -93,5 +93,12 @@ declare function anvilNodeInfo(client: Client<any, any, any, AnvilRPCSchema, any
|
|
|
93
93
|
* @returns
|
|
94
94
|
*/
|
|
95
95
|
declare function evmMineDetailed(client: Client<any, any, any, AnvilRPCSchema, any>, timestamp: bigint | number): Promise<Block<Hex> | undefined>;
|
|
96
|
+
/**
|
|
97
|
+
* Anvil-compatible `writeContractSync`: send via `writeContract` (Anvil
|
|
98
|
+
* supports `eth_sendTransaction` / `eth_sendRawTransaction`) then wait for
|
|
99
|
+
* the receipt. Viem's own action uses `eth_sendRawTransactionSync`, which
|
|
100
|
+
* Anvil does not implement.
|
|
101
|
+
*/
|
|
102
|
+
declare function writeContractSync<chain extends Chain | undefined, account extends Account | undefined, const abi extends Abi | readonly unknown[], functionName extends ContractFunctionName<abi, "nonpayable" | "payable">, args extends ContractFunctionArgs<abi, "nonpayable" | "payable", functionName>, chainOverride extends Chain | undefined>(client: Client<Transport, chain, account>, parameters: WriteContractSyncParameters<abi, functionName, args, chain, account, chainOverride>): Promise<WriteContractSyncReturnType<chain>>;
|
|
96
103
|
//#endregion
|
|
97
|
-
export { AnvilActions, AnvilClient, AnvilClientConfig, AnvilDealParameters, AnvilNodeInfo, AnvilRPCSchema, anvilNodeInfo, createAnvilClient, evmMineDetailed, extendAnvilClient, isAnvil };
|
|
104
|
+
export { AnvilActions, AnvilClient, AnvilClientConfig, AnvilDealParameters, AnvilNodeInfo, AnvilRPCSchema, anvilNodeInfo, createAnvilClient, evmMineDetailed, extendAnvilClient, isAnvil, writeContractSync };
|
|
@@ -6,7 +6,7 @@ import { iDegenNftv2Abi, iFaucetAbi, iOnchainExecutionIdAbi, iOwnableAbi, iaclTr
|
|
|
6
6
|
import { calcLiquidatableLTs } from "./calcLiquidatableLTs.js";
|
|
7
7
|
import { claimFromFaucet } from "./claimFromFaucet.js";
|
|
8
8
|
import { Create2Deployer, Create2Parameters, DEFAULT_CREATE2_SALT, EnsureExistsUsingPublicCreate2ReturnType, GetCreate2AddressParameters, PUBLIC_CREATE2_FACTORY, deployUsingPublicCreate2, getPublicCreate2Address, isDeployedUsingPublicCreate2 } from "./create2.js";
|
|
9
|
-
import { AnvilActions, AnvilClient, AnvilClientConfig, AnvilDealParameters, AnvilNodeInfo, AnvilRPCSchema, anvilNodeInfo, createAnvilClient, evmMineDetailed, extendAnvilClient, isAnvil } from "./createAnvilClient.js";
|
|
9
|
+
import { AnvilActions, AnvilClient, AnvilClientConfig, AnvilDealParameters, AnvilNodeInfo, AnvilRPCSchema, anvilNodeInfo, createAnvilClient, evmMineDetailed, extendAnvilClient, isAnvil, writeContractSync } from "./createAnvilClient.js";
|
|
10
10
|
import { detectChain } from "./detectChain.js";
|
|
11
11
|
import { isOutOfSyncError } from "./isOutOfSyncError.js";
|
|
12
12
|
import { isRateLimitError } from "./isRateLimitError.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, collectMidasGateways, collectMidasMTokens, createAnvilClient, createMinter, deployUsingPublicCreate2, detectChain, enableDSTokenBackDating, evmMineDetailed, extendAnvilClient, getAlchemyUrl, getAnkrUrl, getDrpcUrl, getErpcKey, getPublicCreate2Address, getRpcProviderUrl, 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 };
|
|
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, collectMidasGateways, collectMidasMTokens, createAnvilClient, createMinter, deployUsingPublicCreate2, detectChain, enableDSTokenBackDating, evmMineDetailed, extendAnvilClient, getAlchemyUrl, getAnkrUrl, getDrpcUrl, getErpcKey, getPublicCreate2Address, getRpcProviderUrl, 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 };
|
|
@@ -3,8 +3,10 @@ import { AssetsMap } from "../../../utils/AssetsMap.js";
|
|
|
3
3
|
import { AdapterContractStateHuman, AdapterContractType, AdapterProtocolOperation, DelayedWithdrawalClaim, DelayedWithdrawalRequest, IAdapterContract } from "../types.js";
|
|
4
4
|
import { CallTrace } from "../../../utils/trace.js";
|
|
5
5
|
import { LegacyAdapterOperation, Transfers } from "../legacyAdapterOperations.js";
|
|
6
|
+
import { MultiCall } from "../../../types/transactions.js";
|
|
6
7
|
import { OnchainSDK } from "../../../OnchainSDK.js";
|
|
7
8
|
import "../../../utils/index.js";
|
|
9
|
+
import "../../../types/index.js";
|
|
8
10
|
import { BaseContract } from "../../../base/BaseContract.js";
|
|
9
11
|
import "../../../base/index.js";
|
|
10
12
|
import { Abi, Address, DecodeFunctionDataReturnType, Hex } from "viem";
|
|
@@ -69,6 +71,10 @@ declare class AbstractAdapterContract<const abi extends Abi | readonly unknown[]
|
|
|
69
71
|
* cannot be decoded
|
|
70
72
|
*/
|
|
71
73
|
replayOutOfBracketCall(_balances: AssetsMap, _calldata: Hex): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* {@inheritDoc IAdapterContract.openingCalls}
|
|
76
|
+
*/
|
|
77
|
+
openingCalls(): Promise<MultiCall[]>;
|
|
72
78
|
/**
|
|
73
79
|
* Applies the balance changes of a decoded adapter call to the running
|
|
74
80
|
* balances, mutating them in place. Overrides should express changes via
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { AssetsMap } from "../../../utils/AssetsMap.js";
|
|
2
2
|
import { DelayedWithdrawalClaim, DelayedWithdrawalRequest } from "../types.js";
|
|
3
3
|
import { AbstractAdapterContract, ConcreteAdapterContractOptions } from "./AbstractAdapter.js";
|
|
4
|
+
import { MultiCall } from "../../../types/transactions.js";
|
|
4
5
|
import { OnchainSDK } from "../../../OnchainSDK.js";
|
|
5
6
|
import "../../../utils/index.js";
|
|
7
|
+
import "../../../types/index.js";
|
|
6
8
|
import { Address, DecodeFunctionDataReturnType, Hex } from "viem";
|
|
7
9
|
//#region src/onchain/market/adapters/contracts/MidasGatewayAdapterContract.d.ts
|
|
8
10
|
declare const abi: readonly [{
|
|
@@ -625,6 +627,14 @@ declare class MidasGatewayAdapterContract extends AbstractAdapterContract<abi, p
|
|
|
625
627
|
*/
|
|
626
628
|
get phantomToken(): Address;
|
|
627
629
|
get referrerId(): string | undefined;
|
|
630
|
+
/**
|
|
631
|
+
* Gateway `mode` is immutable on-chain, so the first read is reused.
|
|
632
|
+
*/
|
|
633
|
+
mode(): Promise<number>;
|
|
634
|
+
/**
|
|
635
|
+
* {@inheritDoc IAdapterContract.openingCalls}
|
|
636
|
+
*/
|
|
637
|
+
openingCalls(): Promise<MultiCall[]>;
|
|
628
638
|
stateHuman(raw?: boolean): {
|
|
629
639
|
address: string;
|
|
630
640
|
version: number;
|
|
@@ -655,11 +665,11 @@ declare class MidasGatewayAdapterContract extends AbstractAdapterContract<abi, p
|
|
|
655
665
|
*/
|
|
656
666
|
isReceiveGreenlist(calldata: Hex): boolean;
|
|
657
667
|
/**
|
|
658
|
-
* `receiveGreenlist()` is prepended by
|
|
659
|
-
*
|
|
660
|
-
*
|
|
661
|
-
*
|
|
662
|
-
*
|
|
668
|
+
* `receiveGreenlist()` is prepended by {@link openingCalls} before the
|
|
669
|
+
* balance bracket when a permissioned mToken is minted: it only grants
|
|
670
|
+
* the Midas greenlisted role to the credit account and is
|
|
671
|
+
* balance-neutral, so it is legal outside a bracket and leaves balances
|
|
672
|
+
* untouched.
|
|
663
673
|
*/
|
|
664
674
|
replayOutOfBracketCall(_balances: AssetsMap, calldata: Hex): boolean;
|
|
665
675
|
protected applyBalanceChanges(balances: AssetsMap, decoded: DecodeFunctionDataReturnType<abi>): void;
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { IBaseContract } from "../../base/types.js";
|
|
2
2
|
import { BaseContractStateHuman } from "../../types/state-human.js";
|
|
3
|
+
import { MultiCall } from "../../types/transactions.js";
|
|
4
|
+
import "../../types/index.js";
|
|
3
5
|
import "../../base/index.js";
|
|
4
6
|
import { AbiParameter, Address, Hex } from "viem";
|
|
5
7
|
//#region src/onchain/market/adapters/types.d.ts
|
|
6
8
|
interface IAdapterContract extends IBaseContract {
|
|
7
9
|
targetContract: Address;
|
|
10
|
+
/**
|
|
11
|
+
* Multicall entries a freshly opened credit account on this adapter's
|
|
12
|
+
* credit manager must run first. Decided from adapter state alone, not
|
|
13
|
+
* from the rest of the multicall.
|
|
14
|
+
*/
|
|
15
|
+
openingCalls(): Promise<MultiCall[]>;
|
|
8
16
|
}
|
|
9
17
|
type VersionedAbi = Record<number, readonly AbiParameter[]>;
|
|
10
18
|
type AdapterContractType = "ADAPTER::ACCOUNT_MIGRATOR" | "ADAPTER::BALANCER_V3_ROUTER" | "ADAPTER::BALANCER_V3_WRAPPER" | "ADAPTER::CAMELOT_V3_ROUTER" | "ADAPTER::CURVE_STABLE_NG" | "ADAPTER::CURVE_V1_2ASSETS" | "ADAPTER::CURVE_V1_3ASSETS" | "ADAPTER::CURVE_V1_4ASSETS" | "ADAPTER::CURVE_V1_STECRV_POOL" | "ADAPTER::CVX_V1_BASE_REWARD_POOL" | "ADAPTER::CVX_V1_BOOSTER" | "ADAPTER::DAI_USDS_EXCHANGE" | "ADAPTER::ERC4626_VAULT" | "ADAPTER::ERC4626_VAULT_REFERRAL" | "ADAPTER::FLUID_DEX" | "ADAPTER::INFINIFI_GATEWAY" | "ADAPTER::INFINIFI_UNWINDING" | "ADAPTER::KELP_DEPOSIT_POOL" | "ADAPTER::KELP_WITHDRAWAL" | "ADAPTER::LIDO_V1" | "ADAPTER::LIDO_WSTETH_V1" | "ADAPTER::MELLOW_CLAIMER" | "ADAPTER::MELLOW_DVV" | "ADAPTER::MELLOW_ERC4626_VAULT" | "ADAPTER::MELLOW_WRAPPER" | "ADAPTER::MIDAS_GATEWAY" | "ADAPTER::MIDAS_ISSUANCE_VAULT" | "ADAPTER::MIDAS_REDEMPTION_VAULT" | "ADAPTER::PENDLE_ROUTER" | "ADAPTER::SECURITIZE_ONRAMP" | "ADAPTER::SECURITIZE_REDEMPTION" | "ADAPTER::STAKING_REWARDS" | "ADAPTER::TRADERJOE_ROUTER" | "ADAPTER::UNISWAP_V2_ROUTER" | "ADAPTER::UNISWAP_V3_ROUTER" | "ADAPTER::UNISWAP_V4_GATEWAY" | "ADAPTER::UPSHIFT_VAULT" | "ADAPTER::VELODROME_V2_ROUTER";
|
|
@@ -127,6 +127,11 @@ declare class CreditSuite extends SDKConstruct {
|
|
|
127
127
|
* @param rwaOptions - Factory-specific args, ignored on non-RWA markets.
|
|
128
128
|
*/
|
|
129
129
|
openCreditAccountTx(to: Address, calls: MultiCall[], referralCode?: bigint, rwaOptions?: RWAOperationArgs): RawTx;
|
|
130
|
+
/**
|
|
131
|
+
* Calls to run first in the multicall of a freshly opened account on this
|
|
132
|
+
* suite; use before {@link openCreditAccountTx}.
|
|
133
|
+
*/
|
|
134
|
+
openingCalls(): Promise<MultiCall[]>;
|
|
130
135
|
/**
|
|
131
136
|
* Router configured for this credit suite.
|
|
132
137
|
*/
|
package/package.json
CHANGED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_onchain_utils_AddressMap = require("../../utils/AddressMap.js");
|
|
3
|
-
let viem = require("viem");
|
|
4
|
-
//#region src/onchain/accounts/utils/midasUtils.ts
|
|
5
|
-
const ADAPTER_MIDAS_GATEWAY = "ADAPTER::MIDAS_GATEWAY";
|
|
6
|
-
const ADAPTER_MIDAS_ISSUANCE_VAULT = "ADAPTER::MIDAS_ISSUANCE_VAULT";
|
|
7
|
-
const MGLOBAL_MTOKEN = (0, viem.getAddress)("0x7433806912Eae67919e66aea853d46Fa0aef98A8");
|
|
8
|
-
/**
|
|
9
|
-
* Permissionless gateways have no greenlist and reject `receiveGreenlist`,
|
|
10
|
-
* see MidasMode in integrations-v3
|
|
11
|
-
*/
|
|
12
|
-
const MIDAS_MODE_PERMISSIONLESS = 0;
|
|
13
|
-
const iMidasGatewayAdapterExtAbi = (0, viem.parseAbi)(["function receiveGreenlist() external returns (bool)"]);
|
|
14
|
-
const iMidasGatewayModeAbi = (0, viem.parseAbi)(["function mode() external view returns (uint8)"]);
|
|
15
|
-
const receiveGreenlistCallData = (0, viem.encodeFunctionData)({
|
|
16
|
-
abi: iMidasGatewayAdapterExtAbi,
|
|
17
|
-
functionName: "receiveGreenlist"
|
|
18
|
-
});
|
|
19
|
-
/**
|
|
20
|
-
* Prepends `MidasGatewayAdapter.receiveGreenlist()` to a credit facade
|
|
21
|
-
* multicall that mints an mToken through a Midas issuance vault.
|
|
22
|
-
*
|
|
23
|
-
* Permissioned and restricted-interface mTokens can only be held by greenlisted
|
|
24
|
-
* accounts, and a freshly opened credit account is never greenlisted, so the
|
|
25
|
-
* mint reverts with `WMAC: hasnt role` unless the account asks the gateway for
|
|
26
|
-
* the greenlist first. Greenlisting the borrower is not enough — the role is
|
|
27
|
-
* checked on the token holder, which is the credit account.
|
|
28
|
-
*
|
|
29
|
-
* Returns `calls` unchanged when nothing has to be greenlisted: no issuance
|
|
30
|
-
* vault is called, its mToken has no gateway adapter on this credit manager,
|
|
31
|
-
* the gateway is permissionless, the call is already there, or the mToken is
|
|
32
|
-
* mGLOBAL (temporary: its gateway cannot grant the greenlist).
|
|
33
|
-
*/
|
|
34
|
-
async function prependMidasReceiveGreenlist(props) {
|
|
35
|
-
const { cm, client, calls, logger } = props;
|
|
36
|
-
const adapters = Array.from(cm.creditManager.adapters.values());
|
|
37
|
-
const gatewayByMToken = require_onchain_utils_AddressMap.AddressMap.fromMappedArray(adapters.filter((a) => a.contractType === ADAPTER_MIDAS_GATEWAY), (a) => a.mToken);
|
|
38
|
-
const calledVaults = adapters.filter((a) => a.contractType === ADAPTER_MIDAS_ISSUANCE_VAULT).filter((vault) => calls.some((call) => (0, viem.isAddressEqual)(call.target, vault.address)));
|
|
39
|
-
if (gatewayByMToken.size === 0 || calledVaults.length === 0) return calls;
|
|
40
|
-
const gateways = new require_onchain_utils_AddressMap.AddressMap();
|
|
41
|
-
for (const vault of calledVaults) {
|
|
42
|
-
if ((0, viem.isAddressEqual)(vault.mToken, MGLOBAL_MTOKEN)) {
|
|
43
|
-
logger?.debug(`midas: skipping receiveGreenlist for mGLOBAL ${vault.mToken}`);
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
const gateway = gatewayByMToken.get(vault.mToken);
|
|
47
|
-
if (!gateway) logger?.debug(`midas: no gateway adapter for mToken ${vault.mToken} minted by ${vault.address} on ${cm.name}, cannot greenlist the credit account`);
|
|
48
|
-
else if (calls.some((call) => (0, viem.isAddressEqual)(call.target, gateway.address) && call.callData === receiveGreenlistCallData)) logger?.debug(`midas: gateway adapter ${gateway.address} already receives the greenlist`);
|
|
49
|
-
else gateways.upsert(gateway.address, gateway);
|
|
50
|
-
}
|
|
51
|
-
if (gateways.size === 0) return calls;
|
|
52
|
-
const uniqueGateways = gateways.values();
|
|
53
|
-
const modes = await client.multicall({
|
|
54
|
-
allowFailure: false,
|
|
55
|
-
contracts: uniqueGateways.map(({ targetContract }) => ({
|
|
56
|
-
address: targetContract,
|
|
57
|
-
abi: iMidasGatewayModeAbi,
|
|
58
|
-
functionName: "mode"
|
|
59
|
-
}))
|
|
60
|
-
});
|
|
61
|
-
const prepended = [];
|
|
62
|
-
for (const [i, gateway] of uniqueGateways.entries()) {
|
|
63
|
-
if (modes[i] === MIDAS_MODE_PERMISSIONLESS) {
|
|
64
|
-
logger?.debug(`midas: gateway ${gateway.targetContract} is permissionless, nothing to greenlist`);
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
logger?.debug(`midas: greenlisting the credit account via gateway adapter ${gateway.address}`);
|
|
68
|
-
prepended.push({
|
|
69
|
-
target: gateway.address,
|
|
70
|
-
callData: receiveGreenlistCallData
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
return prepended.length > 0 ? [...prepended, ...calls] : calls;
|
|
74
|
-
}
|
|
75
|
-
//#endregion
|
|
76
|
-
exports.prependMidasReceiveGreenlist = prependMidasReceiveGreenlist;
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { AddressMap } from "../../utils/AddressMap.js";
|
|
2
|
-
import { encodeFunctionData, getAddress, isAddressEqual, parseAbi } from "viem";
|
|
3
|
-
//#region src/onchain/accounts/utils/midasUtils.ts
|
|
4
|
-
const ADAPTER_MIDAS_GATEWAY = "ADAPTER::MIDAS_GATEWAY";
|
|
5
|
-
const ADAPTER_MIDAS_ISSUANCE_VAULT = "ADAPTER::MIDAS_ISSUANCE_VAULT";
|
|
6
|
-
const MGLOBAL_MTOKEN = getAddress("0x7433806912Eae67919e66aea853d46Fa0aef98A8");
|
|
7
|
-
/**
|
|
8
|
-
* Permissionless gateways have no greenlist and reject `receiveGreenlist`,
|
|
9
|
-
* see MidasMode in integrations-v3
|
|
10
|
-
*/
|
|
11
|
-
const MIDAS_MODE_PERMISSIONLESS = 0;
|
|
12
|
-
const iMidasGatewayAdapterExtAbi = parseAbi(["function receiveGreenlist() external returns (bool)"]);
|
|
13
|
-
const iMidasGatewayModeAbi = parseAbi(["function mode() external view returns (uint8)"]);
|
|
14
|
-
const receiveGreenlistCallData = encodeFunctionData({
|
|
15
|
-
abi: iMidasGatewayAdapterExtAbi,
|
|
16
|
-
functionName: "receiveGreenlist"
|
|
17
|
-
});
|
|
18
|
-
/**
|
|
19
|
-
* Prepends `MidasGatewayAdapter.receiveGreenlist()` to a credit facade
|
|
20
|
-
* multicall that mints an mToken through a Midas issuance vault.
|
|
21
|
-
*
|
|
22
|
-
* Permissioned and restricted-interface mTokens can only be held by greenlisted
|
|
23
|
-
* accounts, and a freshly opened credit account is never greenlisted, so the
|
|
24
|
-
* mint reverts with `WMAC: hasnt role` unless the account asks the gateway for
|
|
25
|
-
* the greenlist first. Greenlisting the borrower is not enough — the role is
|
|
26
|
-
* checked on the token holder, which is the credit account.
|
|
27
|
-
*
|
|
28
|
-
* Returns `calls` unchanged when nothing has to be greenlisted: no issuance
|
|
29
|
-
* vault is called, its mToken has no gateway adapter on this credit manager,
|
|
30
|
-
* the gateway is permissionless, the call is already there, or the mToken is
|
|
31
|
-
* mGLOBAL (temporary: its gateway cannot grant the greenlist).
|
|
32
|
-
*/
|
|
33
|
-
async function prependMidasReceiveGreenlist(props) {
|
|
34
|
-
const { cm, client, calls, logger } = props;
|
|
35
|
-
const adapters = Array.from(cm.creditManager.adapters.values());
|
|
36
|
-
const gatewayByMToken = AddressMap.fromMappedArray(adapters.filter((a) => a.contractType === ADAPTER_MIDAS_GATEWAY), (a) => a.mToken);
|
|
37
|
-
const calledVaults = adapters.filter((a) => a.contractType === ADAPTER_MIDAS_ISSUANCE_VAULT).filter((vault) => calls.some((call) => isAddressEqual(call.target, vault.address)));
|
|
38
|
-
if (gatewayByMToken.size === 0 || calledVaults.length === 0) return calls;
|
|
39
|
-
const gateways = new AddressMap();
|
|
40
|
-
for (const vault of calledVaults) {
|
|
41
|
-
if (isAddressEqual(vault.mToken, MGLOBAL_MTOKEN)) {
|
|
42
|
-
logger?.debug(`midas: skipping receiveGreenlist for mGLOBAL ${vault.mToken}`);
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
const gateway = gatewayByMToken.get(vault.mToken);
|
|
46
|
-
if (!gateway) logger?.debug(`midas: no gateway adapter for mToken ${vault.mToken} minted by ${vault.address} on ${cm.name}, cannot greenlist the credit account`);
|
|
47
|
-
else if (calls.some((call) => isAddressEqual(call.target, gateway.address) && call.callData === receiveGreenlistCallData)) logger?.debug(`midas: gateway adapter ${gateway.address} already receives the greenlist`);
|
|
48
|
-
else gateways.upsert(gateway.address, gateway);
|
|
49
|
-
}
|
|
50
|
-
if (gateways.size === 0) return calls;
|
|
51
|
-
const uniqueGateways = gateways.values();
|
|
52
|
-
const modes = await client.multicall({
|
|
53
|
-
allowFailure: false,
|
|
54
|
-
contracts: uniqueGateways.map(({ targetContract }) => ({
|
|
55
|
-
address: targetContract,
|
|
56
|
-
abi: iMidasGatewayModeAbi,
|
|
57
|
-
functionName: "mode"
|
|
58
|
-
}))
|
|
59
|
-
});
|
|
60
|
-
const prepended = [];
|
|
61
|
-
for (const [i, gateway] of uniqueGateways.entries()) {
|
|
62
|
-
if (modes[i] === MIDAS_MODE_PERMISSIONLESS) {
|
|
63
|
-
logger?.debug(`midas: gateway ${gateway.targetContract} is permissionless, nothing to greenlist`);
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
logger?.debug(`midas: greenlisting the credit account via gateway adapter ${gateway.address}`);
|
|
67
|
-
prepended.push({
|
|
68
|
-
target: gateway.address,
|
|
69
|
-
callData: receiveGreenlistCallData
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
return prepended.length > 0 ? [...prepended, ...calls] : calls;
|
|
73
|
-
}
|
|
74
|
-
//#endregion
|
|
75
|
-
export { prependMidasReceiveGreenlist };
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { ILogger } from "../../types/logger.js";
|
|
2
|
-
import { CreditSuite } from "../../market/credit/CreditSuite.js";
|
|
3
|
-
import { MultiCall } from "../../types/transactions.js";
|
|
4
|
-
import "../../types/index.js";
|
|
5
|
-
import { PublicClient } from "viem";
|
|
6
|
-
//#region src/onchain/accounts/utils/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 `mode` 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 is not enough — the role is
|
|
30
|
-
* checked on the token holder, which is the credit account.
|
|
31
|
-
*
|
|
32
|
-
* Returns `calls` unchanged when nothing has to be greenlisted: no issuance
|
|
33
|
-
* vault is called, its mToken has no gateway adapter on this credit manager,
|
|
34
|
-
* the gateway is permissionless, the call is already there, or the mToken is
|
|
35
|
-
* mGLOBAL (temporary: its gateway cannot grant the greenlist).
|
|
36
|
-
*/
|
|
37
|
-
declare function prependMidasReceiveGreenlist(props: PrependMidasReceiveGreenlistProps): Promise<MultiCall[]>;
|
|
38
|
-
//#endregion
|
|
39
|
-
export { PrependMidasReceiveGreenlistProps, prependMidasReceiveGreenlist };
|