@gearbox-protocol/sdk 16.0.0-next.56 → 16.0.0-next.58
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/abi.js +99 -16
- package/dist/cjs/dev/claimFromFaucet.js +3 -3
- package/dist/cjs/dev/index.js +1 -1
- package/dist/cjs/onchain/accounts/CreditAccountsServiceV310.js +2 -2
- package/dist/cjs/onchain/accounts/intents/open-strategy.js +38 -4
- package/dist/cjs/onchain/base/TokensMeta.js +3 -3
- package/dist/cjs/onchain/chain/chains.js +7 -0
- package/dist/cjs/onchain/market/strategyName.js +1 -1
- package/dist/cjs/sdk/execute/ExecuteApi.js +1 -0
- package/dist/cjs/sdk/index.js +2 -0
- package/dist/cjs/sdk/prepare/PrepareApi.js +18 -1
- package/dist/cjs/sdk/prepare/errors.js +21 -0
- package/dist/cjs/sdk/prepare/index.js +2 -0
- package/dist/esm/dev/AccountOpener.js +1 -1
- package/dist/esm/dev/abi.js +99 -16
- package/dist/esm/dev/claimFromFaucet.js +4 -4
- package/dist/esm/dev/index.js +2 -2
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +4 -4
- package/dist/esm/onchain/accounts/intents/open-strategy.js +38 -4
- package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
- package/dist/esm/onchain/base/TokensMeta.js +6 -6
- package/dist/esm/onchain/chain/chains.js +7 -0
- package/dist/esm/onchain/core/createAddressProvider.js +1 -1
- package/dist/esm/onchain/market/adapters/contracts/AccountMigratorAdapterContract.js +1 -1
- package/dist/esm/onchain/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
- package/dist/esm/onchain/market/credit/CreditFacadeV310BaseContract.js +1 -1
- package/dist/esm/onchain/market/pool/PoolV310Contract.js +1 -1
- package/dist/esm/onchain/market/strategyName.js +1 -1
- package/dist/esm/onchain/market/zapper/IETHZapperContract.js +1 -1
- package/dist/esm/onchain/market/zapper/ZapperContract.js +1 -1
- package/dist/esm/onchain/utils/viem/simulateWithPriceUpdates.js +1 -1
- package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
- package/dist/esm/preview/trace/extractTransfers.js +1 -1
- package/dist/esm/sdk/execute/ExecuteApi.js +1 -0
- package/dist/esm/sdk/index.js +2 -2
- package/dist/esm/sdk/prepare/PrepareApi.js +19 -2
- package/dist/esm/sdk/prepare/errors.js +20 -1
- package/dist/esm/sdk/prepare/index.js +2 -2
- package/dist/types/dev/abi.d.ts +91 -15
- package/dist/types/dev/index.d.ts +2 -2
- package/dist/types/model/primitives.d.ts +1 -1
- package/dist/types/onchain/accounts/intents/open-strategy.d.ts +34 -3
- package/dist/types/onchain/accounts/intents/tests/open-strategy.fixtures.d.ts +2 -2
- package/dist/types/onchain/accounts/types.d.ts +2 -1
- package/dist/types/onchain/base/TokensMeta.d.ts +3 -3
- package/dist/types/onchain/base/token-types.d.ts +1 -1
- package/dist/types/onchain/market/strategyName.d.ts +1 -1
- package/dist/types/sdk/index.d.ts +2 -2
- package/dist/types/sdk/prepare/PrepareApi.d.ts +2 -2
- package/dist/types/sdk/prepare/errors.d.ts +25 -1
- package/dist/types/sdk/prepare/index.d.ts +2 -2
- package/dist/types/sdk/prepare/types.d.ts +25 -2
- package/package.json +1 -1
package/dist/cjs/dev/abi.js
CHANGED
|
@@ -4,12 +4,12 @@ let viem = require("viem");
|
|
|
4
4
|
const iaclTraitAbi = (0, viem.parseAbi)(["function acl() external view returns (address)"]);
|
|
5
5
|
const iOwnableAbi = (0, viem.parseAbi)(["function owner() external view returns (address)"]);
|
|
6
6
|
const iDegenNftv2Abi = (0, viem.parseAbi)(["function minter() external view returns (address)", "function mint(address to, uint256 amount) external"]);
|
|
7
|
-
const
|
|
7
|
+
const iFaucetAbi = [
|
|
8
8
|
{
|
|
9
9
|
type: "function",
|
|
10
10
|
name: "assets",
|
|
11
11
|
inputs: [{
|
|
12
|
-
name: "",
|
|
12
|
+
name: "index",
|
|
13
13
|
type: "uint256",
|
|
14
14
|
internalType: "uint256"
|
|
15
15
|
}],
|
|
@@ -58,6 +58,100 @@ const faucetAbi = [
|
|
|
58
58
|
outputs: [],
|
|
59
59
|
stateMutability: "nonpayable"
|
|
60
60
|
},
|
|
61
|
+
{
|
|
62
|
+
type: "function",
|
|
63
|
+
name: "claimOnBehalfOf",
|
|
64
|
+
inputs: [{
|
|
65
|
+
name: "receiver",
|
|
66
|
+
type: "address",
|
|
67
|
+
internalType: "address"
|
|
68
|
+
}, {
|
|
69
|
+
name: "claims",
|
|
70
|
+
type: "tuple[]",
|
|
71
|
+
internalType: "struct TokenClaim[]",
|
|
72
|
+
components: [{
|
|
73
|
+
name: "token",
|
|
74
|
+
type: "address",
|
|
75
|
+
internalType: "address"
|
|
76
|
+
}, {
|
|
77
|
+
name: "amount",
|
|
78
|
+
type: "uint256",
|
|
79
|
+
internalType: "uint256"
|
|
80
|
+
}]
|
|
81
|
+
}],
|
|
82
|
+
outputs: [{
|
|
83
|
+
name: "",
|
|
84
|
+
type: "bool",
|
|
85
|
+
internalType: "bool"
|
|
86
|
+
}],
|
|
87
|
+
stateMutability: "nonpayable"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
type: "function",
|
|
91
|
+
name: "claimOnBehalfOf",
|
|
92
|
+
inputs: [{
|
|
93
|
+
name: "receiver",
|
|
94
|
+
type: "address",
|
|
95
|
+
internalType: "address"
|
|
96
|
+
}, {
|
|
97
|
+
name: "amountUSD",
|
|
98
|
+
type: "uint256",
|
|
99
|
+
internalType: "uint256"
|
|
100
|
+
}],
|
|
101
|
+
outputs: [{
|
|
102
|
+
name: "",
|
|
103
|
+
type: "bool",
|
|
104
|
+
internalType: "bool"
|
|
105
|
+
}],
|
|
106
|
+
stateMutability: "nonpayable"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
type: "function",
|
|
110
|
+
name: "claimOnBehalfOf",
|
|
111
|
+
inputs: [{
|
|
112
|
+
name: "receiver",
|
|
113
|
+
type: "address",
|
|
114
|
+
internalType: "address"
|
|
115
|
+
}],
|
|
116
|
+
outputs: [{
|
|
117
|
+
name: "",
|
|
118
|
+
type: "bool",
|
|
119
|
+
internalType: "bool"
|
|
120
|
+
}],
|
|
121
|
+
stateMutability: "nonpayable"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
type: "function",
|
|
125
|
+
name: "configure",
|
|
126
|
+
inputs: [{
|
|
127
|
+
name: "minAmountUSD",
|
|
128
|
+
type: "uint256",
|
|
129
|
+
internalType: "uint256"
|
|
130
|
+
}, {
|
|
131
|
+
name: "tokens",
|
|
132
|
+
type: "tuple[]",
|
|
133
|
+
internalType: "struct FaucetToken[]",
|
|
134
|
+
components: [
|
|
135
|
+
{
|
|
136
|
+
name: "token",
|
|
137
|
+
type: "address",
|
|
138
|
+
internalType: "address"
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
name: "price",
|
|
142
|
+
type: "uint256",
|
|
143
|
+
internalType: "uint256"
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
name: "decimals",
|
|
147
|
+
type: "uint8",
|
|
148
|
+
internalType: "uint8"
|
|
149
|
+
}
|
|
150
|
+
]
|
|
151
|
+
}],
|
|
152
|
+
outputs: [],
|
|
153
|
+
stateMutability: "nonpayable"
|
|
154
|
+
},
|
|
61
155
|
{
|
|
62
156
|
type: "function",
|
|
63
157
|
name: "getAssets",
|
|
@@ -95,22 +189,11 @@ const faucetAbi = [
|
|
|
95
189
|
}],
|
|
96
190
|
stateMutability: "view"
|
|
97
191
|
},
|
|
98
|
-
{
|
|
99
|
-
type: "function",
|
|
100
|
-
name: "owner",
|
|
101
|
-
inputs: [],
|
|
102
|
-
outputs: [{
|
|
103
|
-
name: "",
|
|
104
|
-
type: "address",
|
|
105
|
-
internalType: "address"
|
|
106
|
-
}],
|
|
107
|
-
stateMutability: "view"
|
|
108
|
-
},
|
|
109
192
|
{
|
|
110
193
|
type: "function",
|
|
111
194
|
name: "prices",
|
|
112
195
|
inputs: [{
|
|
113
|
-
name: "",
|
|
196
|
+
name: "token",
|
|
114
197
|
type: "address",
|
|
115
198
|
internalType: "address"
|
|
116
199
|
}],
|
|
@@ -125,7 +208,7 @@ const faucetAbi = [
|
|
|
125
208
|
type: "function",
|
|
126
209
|
name: "scales",
|
|
127
210
|
inputs: [{
|
|
128
|
-
name: "",
|
|
211
|
+
name: "token",
|
|
129
212
|
type: "address",
|
|
130
213
|
internalType: "address"
|
|
131
214
|
}],
|
|
@@ -204,8 +287,8 @@ const iOnchainExecutionIdAbi = [
|
|
|
204
287
|
}
|
|
205
288
|
];
|
|
206
289
|
//#endregion
|
|
207
|
-
exports.faucetAbi = faucetAbi;
|
|
208
290
|
exports.iDegenNftv2Abi = iDegenNftv2Abi;
|
|
291
|
+
exports.iFaucetAbi = iFaucetAbi;
|
|
209
292
|
exports.iOnchainExecutionIdAbi = iOnchainExecutionIdAbi;
|
|
210
293
|
exports.iOwnableAbi = iOwnableAbi;
|
|
211
294
|
exports.iaclTraitAbi = iaclTraitAbi;
|
|
@@ -23,7 +23,7 @@ async function claimFromFaucet(opts) {
|
|
|
23
23
|
} else if (typeof amount === "function") {
|
|
24
24
|
const minAmountUSD = await (0, viem_actions.readContract)(publicClient, {
|
|
25
25
|
address: faucet,
|
|
26
|
-
abi: require_dev_abi.
|
|
26
|
+
abi: require_dev_abi.iFaucetAbi,
|
|
27
27
|
functionName: "minAmountUSD"
|
|
28
28
|
});
|
|
29
29
|
logger?.debug(`faucet min amount USD: ${minAmountUSD}`);
|
|
@@ -39,7 +39,7 @@ async function claimFromFaucet(opts) {
|
|
|
39
39
|
const gas = await publicClient.estimateContractGas({
|
|
40
40
|
account: claimer,
|
|
41
41
|
address: faucet,
|
|
42
|
-
abi: require_dev_abi.
|
|
42
|
+
abi: require_dev_abi.iFaucetAbi,
|
|
43
43
|
functionName: "claim",
|
|
44
44
|
args
|
|
45
45
|
});
|
|
@@ -47,7 +47,7 @@ async function claimFromFaucet(opts) {
|
|
|
47
47
|
const { request } = await publicClient.simulateContract({
|
|
48
48
|
account: claimer,
|
|
49
49
|
address: faucet,
|
|
50
|
-
abi: require_dev_abi.
|
|
50
|
+
abi: require_dev_abi.iFaucetAbi,
|
|
51
51
|
functionName: "claim",
|
|
52
52
|
args,
|
|
53
53
|
chain: wallet.chain,
|
package/dist/cjs/dev/index.js
CHANGED
|
@@ -49,7 +49,6 @@ exports.detectChain = require_dev_detectChain.detectChain;
|
|
|
49
49
|
exports.enableDSTokenBackDating = require_dev_securitizeUtils.enableDSTokenBackDating;
|
|
50
50
|
exports.evmMineDetailed = require_dev_createAnvilClient.evmMineDetailed;
|
|
51
51
|
exports.extendAnvilClient = require_dev_createAnvilClient.extendAnvilClient;
|
|
52
|
-
exports.faucetAbi = require_dev_abi.faucetAbi;
|
|
53
52
|
exports.getAlchemyUrl = require_dev_providers.getAlchemyUrl;
|
|
54
53
|
exports.getAnkrUrl = require_dev_providers.getAnkrUrl;
|
|
55
54
|
exports.getDrpcUrl = require_dev_providers.getDrpcUrl;
|
|
@@ -60,6 +59,7 @@ exports.getThirdWebUrl = require_dev_providers.getThirdWebUrl;
|
|
|
60
59
|
exports.greenlistMidasGateway = require_dev_kycUtils.greenlistMidasGateway;
|
|
61
60
|
exports.httpTransportOptionsSchema = require_dev_transports.httpTransportOptionsSchema;
|
|
62
61
|
exports.iDegenNftv2Abi = require_dev_abi.iDegenNftv2Abi;
|
|
62
|
+
exports.iFaucetAbi = require_dev_abi.iFaucetAbi;
|
|
63
63
|
exports.iOnchainExecutionIdAbi = require_dev_abi.iOnchainExecutionIdAbi;
|
|
64
64
|
exports.iOwnableAbi = require_dev_abi.iOwnableAbi;
|
|
65
65
|
exports.iaclTraitAbi = require_dev_abi.iaclTraitAbi;
|
|
@@ -205,7 +205,7 @@ var CreditAccountsServiceV310 = class extends require_onchain_base_SDKConstruct.
|
|
|
205
205
|
else if (typeof withdrawToken === "string") tokenToWithdraw = withdrawToken;
|
|
206
206
|
const { creditFacade } = cmSuite;
|
|
207
207
|
let calls = [
|
|
208
|
-
creditFacade.prepareIncreaseDebt(debt),
|
|
208
|
+
...debt > 0n ? [creditFacade.prepareIncreaseDebt(debt)] : [],
|
|
209
209
|
...creditFacade.prepareAddCollateral(collateral, permits),
|
|
210
210
|
...openPathCalls,
|
|
211
211
|
...tokenToWithdraw ? [creditFacade.prepareWithdrawCollateral(tokenToWithdraw, require_onchain_constants_math.MAX_UINT256, to)] : [],
|
|
@@ -217,7 +217,7 @@ var CreditAccountsServiceV310 = class extends require_onchain_base_SDKConstruct.
|
|
|
217
217
|
];
|
|
218
218
|
calls = await this.#prependMidasReceiveGreenlist(cm.address, calls);
|
|
219
219
|
calls = await this.prependPriceUpdates(cm.address, calls);
|
|
220
|
-
const tx = reopenCreditAccount ? cmSuite.multicallTx(reopenCreditAccount, calls) : cmSuite.openCreditAccountTx(to, calls, referralCode, rwaOptions);
|
|
220
|
+
const tx = reopenCreditAccount ? cmSuite.multicallTx(reopenCreditAccount, calls, rwaOptions) : cmSuite.openCreditAccountTx(to, calls, referralCode, rwaOptions);
|
|
221
221
|
tx.value = ethAmount.toString(10);
|
|
222
222
|
return tx;
|
|
223
223
|
}
|
|
@@ -7,7 +7,10 @@ const require_onchain_accounts_intents_utils_quotas_for_update = require("./util
|
|
|
7
7
|
const require_onchain_accounts_intents_utils_router_path = require("./utils/router-path.js");
|
|
8
8
|
require("./utils/index.js");
|
|
9
9
|
//#region src/onchain/accounts/intents/open-strategy.ts
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Stand-in account address, used when the opening creates its own account:
|
|
12
|
+
* nothing exists on chain until the tx lands.
|
|
13
|
+
*/
|
|
11
14
|
const NO_ACCOUNT = "0x0000000000000000000000000000000000000000";
|
|
12
15
|
/**
|
|
13
16
|
* Builds the state opening a leveraged position out of wallet collateral would
|
|
@@ -22,7 +25,8 @@ const NO_ACCOUNT = "0x0000000000000000000000000000000000000000";
|
|
|
22
25
|
* `sdk.accounts.openCA`.
|
|
23
26
|
*/
|
|
24
27
|
async function buildOpenStrategyState(props) {
|
|
25
|
-
|
|
28
|
+
if (props.empty) return emptyOpenState(props);
|
|
29
|
+
const { sdk, creditManager, collateral, targetToken, leverage, slippage = 0, quotaReserve, leftoverBalances = [], creditAccount: existing } = props;
|
|
26
30
|
require_onchain_accounts_intents_math.assertLeverageAtLeastOne(leverage);
|
|
27
31
|
const suite = sdk.marketRegister.findCreditManager(creditManager);
|
|
28
32
|
const market = sdk.marketRegister.findByCreditManager(creditManager);
|
|
@@ -32,7 +36,7 @@ async function buildOpenStrategyState(props) {
|
|
|
32
36
|
const margin = collateral.reduce((acc, a) => acc + convert(a.token, underlying, a.balance), 0n);
|
|
33
37
|
if (margin <= 0n) throw new require_onchain_validation_refusal.IntentPreviewError("insufficientSourceBalance", void 0, "openStrategy: collateral is worth nothing in underlying");
|
|
34
38
|
const debt = require_onchain_accounts_intents_math.debtForLeverage(margin, leverage);
|
|
35
|
-
const account = {
|
|
39
|
+
const account = existing ?? {
|
|
36
40
|
creditAccount: NO_ACCOUNT,
|
|
37
41
|
creditManager: creditManager.toLowerCase(),
|
|
38
42
|
creditFacade: suite.creditFacade.address.toLowerCase(),
|
|
@@ -101,7 +105,37 @@ async function buildOpenStrategyState(props) {
|
|
|
101
105
|
minAssets: minAssets.map(priced),
|
|
102
106
|
averageQuota,
|
|
103
107
|
minQuota,
|
|
104
|
-
calls: [...leg.calls]
|
|
108
|
+
calls: [...leg.calls],
|
|
109
|
+
creditAccount: existing?.creditAccount
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The opening that holds an account and nothing else.
|
|
114
|
+
*
|
|
115
|
+
* Taken before the walk rather than threaded through it: the router has no
|
|
116
|
+
* guard for an empty basket and would still make its `eth_call`, and every
|
|
117
|
+
* assertion below reads amounts that are not there.
|
|
118
|
+
*/
|
|
119
|
+
async function emptyOpenState(props) {
|
|
120
|
+
const { sdk, creditManager } = props;
|
|
121
|
+
require_onchain_accounts_intents_guards.assertMarketOperable(sdk.marketRegister.findCreditManager(creditManager));
|
|
122
|
+
const snapshot = {
|
|
123
|
+
creditManager,
|
|
124
|
+
assets: [],
|
|
125
|
+
quotas: [],
|
|
126
|
+
totalDebt: 0n,
|
|
127
|
+
totalValue: 0n
|
|
128
|
+
};
|
|
129
|
+
const { assets: _assets, quotas: _quotas, ...projection } = sdk.positions.projection(snapshot, { availableLiquidityChange: 0n });
|
|
130
|
+
return {
|
|
131
|
+
...projection,
|
|
132
|
+
currentPrice: sdk.positions.currentPrice(snapshot),
|
|
133
|
+
priceImpact: void 0,
|
|
134
|
+
averageAssets: [],
|
|
135
|
+
minAssets: [],
|
|
136
|
+
averageQuota: [],
|
|
137
|
+
minQuota: [],
|
|
138
|
+
calls: []
|
|
105
139
|
};
|
|
106
140
|
}
|
|
107
141
|
/** Collateral plus the borrowed underlying, folded into one balance per token. */
|
|
@@ -55,7 +55,7 @@ var TokensMeta = class extends require_onchain_utils_AddressMap.AddressMap {
|
|
|
55
55
|
* Returns the display symbol for a token.
|
|
56
56
|
*
|
|
57
57
|
* This is not always the on-chain ERC-20 `symbol()`: curated pretty names
|
|
58
|
-
* and redemption phantom tokens (`"
|
|
58
|
+
* and redemption phantom tokens (`"target redemption from source"`) replace it.
|
|
59
59
|
*
|
|
60
60
|
* @param token - Token address.
|
|
61
61
|
* @throws If the token is not in the registry.
|
|
@@ -154,7 +154,7 @@ var TokensMeta = class extends require_onchain_utils_AddressMap.AddressMap {
|
|
|
154
154
|
}
|
|
155
155
|
/**
|
|
156
156
|
* Rewrites display symbols of redemption phantom tokens to
|
|
157
|
-
* `"${
|
|
157
|
+
* `"${target} redemption from ${source}"`.
|
|
158
158
|
*
|
|
159
159
|
* @param renames - Phantom / source / target address triples.
|
|
160
160
|
**/
|
|
@@ -164,7 +164,7 @@ var TokensMeta = class extends require_onchain_utils_AddressMap.AddressMap {
|
|
|
164
164
|
if (!meta || !this.has(source) || !this.has(target)) continue;
|
|
165
165
|
this.upsert(phantom, {
|
|
166
166
|
...meta,
|
|
167
|
-
symbol: `${this.symbol(
|
|
167
|
+
symbol: `${this.symbol(target)} redemption from ${this.symbol(source)}`
|
|
168
168
|
});
|
|
169
169
|
}
|
|
170
170
|
}
|
|
@@ -126,6 +126,13 @@ const chains = {
|
|
|
126
126
|
symbol: "USDC"
|
|
127
127
|
},
|
|
128
128
|
tokenPrettyNames: require_onchain_utils_AddressMap.AddressMap.fromRecord({
|
|
129
|
+
"0xab7d50fc2486a1ac06516e2ece9dadc95ba8cd20": "wstETH redemption from cp0xLRT",
|
|
130
|
+
"0x6252467c2fefb61cb55180282943139baeea36c5": "wstETH redemption from rstETH",
|
|
131
|
+
"0xd412ca00d177eba2843348f9c50dd17bfce32c40": "wstETH redemption from pzETH",
|
|
132
|
+
"0x26c98674e623647f11909791593fa3b6e9406c67": "wstETH redemption from steak7LRT",
|
|
133
|
+
"0x9fb930eacadad079683a4758424a53b9b3692775": "wstETH redemption from Re7LRT",
|
|
134
|
+
"0xd7f1a4e3aba92a9d20987c752bd4a6cc759d7738": "rsETH redemption from hgETH",
|
|
135
|
+
"0xc71219dca5a671aa6268ab8fb35e570bd72f372b": "iUSD redemption from liUSD-1w",
|
|
129
136
|
"0x924d24c238db7ecae2aa3a19430239ed684bde4a": "Beefy WBTC/cbBTC/hemiBTC",
|
|
130
137
|
"0x403cc0d2694ec2639101f32b146b90d766461ce9": "Beefy wstETH/tETH",
|
|
131
138
|
"0x02a4cceed3c400b5ba9fd22ad6ec18d8f7a3d48e": "Beefy ETH+/WETH",
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
5
5
|
* borrowed underlying, e.g. `"wstETH / WETH"`.
|
|
6
6
|
*
|
|
7
7
|
* Uses each token's display {@link Token.symbol}, which may already be a
|
|
8
|
-
* curated pretty name or a `"
|
|
8
|
+
* curated pretty name or a `"target redemption from source"` redemption rewrite.
|
|
9
9
|
*
|
|
10
10
|
* @param target - Collateral the position is built around.
|
|
11
11
|
* @param underlying - Token the position borrows.
|
package/dist/cjs/sdk/index.js
CHANGED
|
@@ -47,7 +47,9 @@ exports.PreviewNamespace = require_sdk_preview_PreviewNamespace.PreviewNamespace
|
|
|
47
47
|
exports.SourceChainMismatchError = require_sdk_errors_SourceChainMismatchError.SourceChainMismatchError;
|
|
48
48
|
exports.SourceUnavailableError = require_sdk_errors_SourceUnavailableError.SourceUnavailableError;
|
|
49
49
|
exports.assertSameChains = require_sdk_errors_assertSameChains.assertSameChains;
|
|
50
|
+
exports.creditAccountNotEmpty = require_sdk_prepare_errors.creditAccountNotEmpty;
|
|
50
51
|
exports.creditAccountNotFound = require_sdk_prepare_errors.creditAccountNotFound;
|
|
52
|
+
exports.emptyOpenTakesNothing = require_sdk_prepare_errors.emptyOpenTakesNothing;
|
|
51
53
|
exports.everyChainFailed = require_sdk_errors_everyChainFailed.everyChainFailed;
|
|
52
54
|
exports.filterResponse = require_sdk_utils_filterResponse.filterResponse;
|
|
53
55
|
exports.mergeChainList = require_sdk_utils_mergeChains.mergeChainList;
|
|
@@ -9,6 +9,7 @@ const require_onchain_accounts_intents_index = require("../../onchain/accounts/i
|
|
|
9
9
|
require("../../onchain/index.js");
|
|
10
10
|
const require_sdk_prepare_errors = require("./errors.js");
|
|
11
11
|
const require_sdk_prepare_withdrawable_collaterals = require("./withdrawable-collaterals.js");
|
|
12
|
+
let viem = require("viem");
|
|
12
13
|
//#region src/sdk/prepare/PrepareApi.ts
|
|
13
14
|
/**
|
|
14
15
|
* {@inheritDoc IOpportunitiesPrepare}
|
|
@@ -182,8 +183,23 @@ var PrepareApi = class extends require_onchain_base_MultichainConstruct.Multicha
|
|
|
182
183
|
try {
|
|
183
184
|
const sdk = await this.#chain(strategy.chainId);
|
|
184
185
|
const at = stateBlock(sdk);
|
|
186
|
+
if (params.empty) {
|
|
187
|
+
if (params.collateral.length > 0 || params.creditAccount || params.leverage !== 0n) return require_model_result.sdkErr(require_sdk_prepare_errors.emptyOpenTakesNothing());
|
|
188
|
+
return opened(await service(sdk).openStrategyIntent({
|
|
189
|
+
sdk,
|
|
190
|
+
creditManager: strategy.creditManager,
|
|
191
|
+
empty: true
|
|
192
|
+
}), at);
|
|
193
|
+
}
|
|
185
194
|
const targetToken = params.targetToken ?? sdk.marketRegister.findCreditManager(strategy.creditManager).strategyTargetCollateral;
|
|
186
195
|
if (!targetToken) return require_model_result.sdkErr(require_sdk_prepare_errors.noStrategyTargetCollateral(strategy.creditManager));
|
|
196
|
+
let creditAccount;
|
|
197
|
+
if (params.creditAccount) {
|
|
198
|
+
const reused = await slice(sdk, params.creditAccount);
|
|
199
|
+
if (!reused || !(0, viem.isAddressEqual)(reused.creditManager, strategy.creditManager)) return require_model_result.sdkErr(require_sdk_prepare_errors.creditAccountNotFound(params.creditAccount));
|
|
200
|
+
if (reused.totalDebt > 0n || reused.tokens.some((t) => t.quota > 0n)) return require_model_result.sdkErr(require_sdk_prepare_errors.creditAccountNotEmpty(params.creditAccount));
|
|
201
|
+
creditAccount = reused;
|
|
202
|
+
}
|
|
187
203
|
return opened(await service(sdk).openStrategyIntent({
|
|
188
204
|
sdk,
|
|
189
205
|
creditManager: strategy.creditManager,
|
|
@@ -192,7 +208,8 @@ var PrepareApi = class extends require_onchain_base_MultichainConstruct.Multicha
|
|
|
192
208
|
leverage: params.leverage,
|
|
193
209
|
leftoverBalances: params.leftoverBalances,
|
|
194
210
|
slippage: params.slippage,
|
|
195
|
-
quotaReserve: params.quotaReserve
|
|
211
|
+
quotaReserve: params.quotaReserve,
|
|
212
|
+
creditAccount
|
|
196
213
|
}), at);
|
|
197
214
|
} catch (e) {
|
|
198
215
|
return require_model_result.sdkErr(require_sdk_prepare_errors.unexpectedFailure(e));
|
|
@@ -63,6 +63,16 @@ function noStrategyTargetCollateral(creditManager) {
|
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
|
+
* {@inheritDoc CreditAccountNotEmptyError}
|
|
67
|
+
**/
|
|
68
|
+
function creditAccountNotEmpty(creditAccount) {
|
|
69
|
+
return {
|
|
70
|
+
code: "creditAccountNotEmpty",
|
|
71
|
+
message: `Credit account ${creditAccount} carries debt or quotas.`,
|
|
72
|
+
creditAccount
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
66
76
|
* {@inheritDoc CreditAccountNotFoundError}
|
|
67
77
|
**/
|
|
68
78
|
function creditAccountNotFound(creditAccount) {
|
|
@@ -73,6 +83,15 @@ function creditAccountNotFound(creditAccount) {
|
|
|
73
83
|
};
|
|
74
84
|
}
|
|
75
85
|
/**
|
|
86
|
+
* {@inheritDoc EmptyOpenTakesNothingError}
|
|
87
|
+
**/
|
|
88
|
+
function emptyOpenTakesNothing() {
|
|
89
|
+
return {
|
|
90
|
+
code: "emptyOpenTakesNothing",
|
|
91
|
+
message: "An empty opening takes no collateral, no account to reuse and no leverage."
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
76
95
|
* {@inheritDoc UnexpectedFailureError}
|
|
77
96
|
*
|
|
78
97
|
* Takes what was thrown, whatever that is: a `throw` is not obliged to raise an
|
|
@@ -87,7 +106,9 @@ function unexpectedFailure(thrown) {
|
|
|
87
106
|
};
|
|
88
107
|
}
|
|
89
108
|
//#endregion
|
|
109
|
+
exports.creditAccountNotEmpty = creditAccountNotEmpty;
|
|
90
110
|
exports.creditAccountNotFound = creditAccountNotFound;
|
|
111
|
+
exports.emptyOpenTakesNothing = emptyOpenTakesNothing;
|
|
91
112
|
exports.noStrategyTargetCollateral = noStrategyTargetCollateral;
|
|
92
113
|
exports.toRefusalError = toRefusalError;
|
|
93
114
|
exports.unexpectedFailure = unexpectedFailure;
|
|
@@ -5,7 +5,9 @@ const require_sdk_prepare_PrepareApi = require("./PrepareApi.js");
|
|
|
5
5
|
require("./types.js");
|
|
6
6
|
exports.IntentPreviewError = require_onchain_validation_refusal.IntentPreviewError;
|
|
7
7
|
exports.PrepareApi = require_sdk_prepare_PrepareApi.PrepareApi;
|
|
8
|
+
exports.creditAccountNotEmpty = require_sdk_prepare_errors.creditAccountNotEmpty;
|
|
8
9
|
exports.creditAccountNotFound = require_sdk_prepare_errors.creditAccountNotFound;
|
|
10
|
+
exports.emptyOpenTakesNothing = require_sdk_prepare_errors.emptyOpenTakesNothing;
|
|
9
11
|
exports.noStrategyTargetCollateral = require_sdk_prepare_errors.noStrategyTargetCollateral;
|
|
10
12
|
exports.raise = require_onchain_validation_refusal.raise;
|
|
11
13
|
exports.refuse = require_onchain_validation_refusal.refuse;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { iCreditFacadeV310Abi } from "../abi/310/generated.js";
|
|
2
1
|
import { ierc20Abi } from "../abi/iERC20.js";
|
|
2
|
+
import { iCreditFacadeV310Abi } from "../abi/310/generated.js";
|
|
3
3
|
import { AddressMap } from "../onchain/utils/AddressMap.js";
|
|
4
4
|
import { AddressSet } from "../onchain/utils/AddressSet.js";
|
|
5
5
|
import { AssetsMap } from "../onchain/utils/AssetsMap.js";
|
package/dist/esm/dev/abi.js
CHANGED
|
@@ -3,12 +3,12 @@ import { parseAbi } from "viem";
|
|
|
3
3
|
const iaclTraitAbi = parseAbi(["function acl() external view returns (address)"]);
|
|
4
4
|
const iOwnableAbi = parseAbi(["function owner() external view returns (address)"]);
|
|
5
5
|
const iDegenNftv2Abi = parseAbi(["function minter() external view returns (address)", "function mint(address to, uint256 amount) external"]);
|
|
6
|
-
const
|
|
6
|
+
const iFaucetAbi = [
|
|
7
7
|
{
|
|
8
8
|
type: "function",
|
|
9
9
|
name: "assets",
|
|
10
10
|
inputs: [{
|
|
11
|
-
name: "",
|
|
11
|
+
name: "index",
|
|
12
12
|
type: "uint256",
|
|
13
13
|
internalType: "uint256"
|
|
14
14
|
}],
|
|
@@ -57,6 +57,100 @@ const faucetAbi = [
|
|
|
57
57
|
outputs: [],
|
|
58
58
|
stateMutability: "nonpayable"
|
|
59
59
|
},
|
|
60
|
+
{
|
|
61
|
+
type: "function",
|
|
62
|
+
name: "claimOnBehalfOf",
|
|
63
|
+
inputs: [{
|
|
64
|
+
name: "receiver",
|
|
65
|
+
type: "address",
|
|
66
|
+
internalType: "address"
|
|
67
|
+
}, {
|
|
68
|
+
name: "claims",
|
|
69
|
+
type: "tuple[]",
|
|
70
|
+
internalType: "struct TokenClaim[]",
|
|
71
|
+
components: [{
|
|
72
|
+
name: "token",
|
|
73
|
+
type: "address",
|
|
74
|
+
internalType: "address"
|
|
75
|
+
}, {
|
|
76
|
+
name: "amount",
|
|
77
|
+
type: "uint256",
|
|
78
|
+
internalType: "uint256"
|
|
79
|
+
}]
|
|
80
|
+
}],
|
|
81
|
+
outputs: [{
|
|
82
|
+
name: "",
|
|
83
|
+
type: "bool",
|
|
84
|
+
internalType: "bool"
|
|
85
|
+
}],
|
|
86
|
+
stateMutability: "nonpayable"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
type: "function",
|
|
90
|
+
name: "claimOnBehalfOf",
|
|
91
|
+
inputs: [{
|
|
92
|
+
name: "receiver",
|
|
93
|
+
type: "address",
|
|
94
|
+
internalType: "address"
|
|
95
|
+
}, {
|
|
96
|
+
name: "amountUSD",
|
|
97
|
+
type: "uint256",
|
|
98
|
+
internalType: "uint256"
|
|
99
|
+
}],
|
|
100
|
+
outputs: [{
|
|
101
|
+
name: "",
|
|
102
|
+
type: "bool",
|
|
103
|
+
internalType: "bool"
|
|
104
|
+
}],
|
|
105
|
+
stateMutability: "nonpayable"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
type: "function",
|
|
109
|
+
name: "claimOnBehalfOf",
|
|
110
|
+
inputs: [{
|
|
111
|
+
name: "receiver",
|
|
112
|
+
type: "address",
|
|
113
|
+
internalType: "address"
|
|
114
|
+
}],
|
|
115
|
+
outputs: [{
|
|
116
|
+
name: "",
|
|
117
|
+
type: "bool",
|
|
118
|
+
internalType: "bool"
|
|
119
|
+
}],
|
|
120
|
+
stateMutability: "nonpayable"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
type: "function",
|
|
124
|
+
name: "configure",
|
|
125
|
+
inputs: [{
|
|
126
|
+
name: "minAmountUSD",
|
|
127
|
+
type: "uint256",
|
|
128
|
+
internalType: "uint256"
|
|
129
|
+
}, {
|
|
130
|
+
name: "tokens",
|
|
131
|
+
type: "tuple[]",
|
|
132
|
+
internalType: "struct FaucetToken[]",
|
|
133
|
+
components: [
|
|
134
|
+
{
|
|
135
|
+
name: "token",
|
|
136
|
+
type: "address",
|
|
137
|
+
internalType: "address"
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
name: "price",
|
|
141
|
+
type: "uint256",
|
|
142
|
+
internalType: "uint256"
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
name: "decimals",
|
|
146
|
+
type: "uint8",
|
|
147
|
+
internalType: "uint8"
|
|
148
|
+
}
|
|
149
|
+
]
|
|
150
|
+
}],
|
|
151
|
+
outputs: [],
|
|
152
|
+
stateMutability: "nonpayable"
|
|
153
|
+
},
|
|
60
154
|
{
|
|
61
155
|
type: "function",
|
|
62
156
|
name: "getAssets",
|
|
@@ -94,22 +188,11 @@ const faucetAbi = [
|
|
|
94
188
|
}],
|
|
95
189
|
stateMutability: "view"
|
|
96
190
|
},
|
|
97
|
-
{
|
|
98
|
-
type: "function",
|
|
99
|
-
name: "owner",
|
|
100
|
-
inputs: [],
|
|
101
|
-
outputs: [{
|
|
102
|
-
name: "",
|
|
103
|
-
type: "address",
|
|
104
|
-
internalType: "address"
|
|
105
|
-
}],
|
|
106
|
-
stateMutability: "view"
|
|
107
|
-
},
|
|
108
191
|
{
|
|
109
192
|
type: "function",
|
|
110
193
|
name: "prices",
|
|
111
194
|
inputs: [{
|
|
112
|
-
name: "",
|
|
195
|
+
name: "token",
|
|
113
196
|
type: "address",
|
|
114
197
|
internalType: "address"
|
|
115
198
|
}],
|
|
@@ -124,7 +207,7 @@ const faucetAbi = [
|
|
|
124
207
|
type: "function",
|
|
125
208
|
name: "scales",
|
|
126
209
|
inputs: [{
|
|
127
|
-
name: "",
|
|
210
|
+
name: "token",
|
|
128
211
|
type: "address",
|
|
129
212
|
internalType: "address"
|
|
130
213
|
}],
|
|
@@ -203,4 +286,4 @@ const iOnchainExecutionIdAbi = [
|
|
|
203
286
|
}
|
|
204
287
|
];
|
|
205
288
|
//#endregion
|
|
206
|
-
export {
|
|
289
|
+
export { iDegenNftv2Abi, iFaucetAbi, iOnchainExecutionIdAbi, iOwnableAbi, iaclTraitAbi };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { formatBN } from "../onchain/utils/formatter.js";
|
|
2
2
|
import "../onchain/index.js";
|
|
3
|
-
import {
|
|
3
|
+
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) {
|
|
@@ -22,7 +22,7 @@ async function claimFromFaucet(opts) {
|
|
|
22
22
|
} else if (typeof amount === "function") {
|
|
23
23
|
const minAmountUSD = await readContract(publicClient, {
|
|
24
24
|
address: faucet,
|
|
25
|
-
abi:
|
|
25
|
+
abi: iFaucetAbi,
|
|
26
26
|
functionName: "minAmountUSD"
|
|
27
27
|
});
|
|
28
28
|
logger?.debug(`faucet min amount USD: ${minAmountUSD}`);
|
|
@@ -38,7 +38,7 @@ async function claimFromFaucet(opts) {
|
|
|
38
38
|
const gas = await publicClient.estimateContractGas({
|
|
39
39
|
account: claimer,
|
|
40
40
|
address: faucet,
|
|
41
|
-
abi:
|
|
41
|
+
abi: iFaucetAbi,
|
|
42
42
|
functionName: "claim",
|
|
43
43
|
args
|
|
44
44
|
});
|
|
@@ -46,7 +46,7 @@ async function claimFromFaucet(opts) {
|
|
|
46
46
|
const { request } = await publicClient.simulateContract({
|
|
47
47
|
account: claimer,
|
|
48
48
|
address: faucet,
|
|
49
|
-
abi:
|
|
49
|
+
abi: iFaucetAbi,
|
|
50
50
|
functionName: "claim",
|
|
51
51
|
args,
|
|
52
52
|
chain: wallet.chain,
|
package/dist/esm/dev/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { iDegenNftv2Abi, iFaucetAbi, 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
4
|
import { createMinter } from "./mint/factory.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, createAnvilClient, createMinter, deployUsingPublicCreate2, detectChain, enableDSTokenBackDating, evmMineDetailed, extendAnvilClient,
|
|
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, 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, writeAndWait };
|