@gearbox-protocol/sdk 18.4.1-aave.3 → 18.4.1-aave.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/abi/rwa/iSecuritizeRWAFactory.js +15 -0
- package/dist/cjs/onchain/accounts/intents/plan.js +1 -0
- package/dist/cjs/onchain/accounts/intents/realize.js +6 -3
- package/dist/cjs/onchain/market/adapters/contracts/AaveHorizonBridgeAdapterContract.js +10 -3
- package/dist/cjs/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +9 -0
- package/dist/cjs/onchain/positions/projectAavePosition.js +1 -1
- package/dist/esm/abi/rwa/iSecuritizeRWAFactory.js +15 -0
- package/dist/esm/onchain/accounts/intents/plan.js +1 -0
- package/dist/esm/onchain/accounts/intents/realize.js +6 -3
- package/dist/esm/onchain/market/adapters/contracts/AaveHorizonBridgeAdapterContract.js +10 -3
- package/dist/esm/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +9 -0
- package/dist/esm/onchain/positions/projectAavePosition.js +1 -1
- package/dist/types/abi/rwa/iSecuritizeRWAFactory.d.ts +14 -0
- package/dist/types/onchain/accounts/intents/plan.d.ts +2 -1
- package/dist/types/onchain/accounts/intents/types.d.ts +2 -1
- package/dist/types/onchain/market/adapters/contracts/AaveHorizonBridgeAdapterContract.d.ts +5 -1
- package/dist/types/onchain/market/rwa/securitize/SecuritizeRWAFactory.d.ts +20 -0
- package/dist/types/onchain/market/rwa/types.d.ts +6 -0
- package/dist/types/sdk/prepare/types.d.ts +6 -2
- package/package.json +1 -1
|
@@ -79,6 +79,21 @@ const iSecuritizeRWAFactoryAbi = [
|
|
|
79
79
|
}],
|
|
80
80
|
stateMutability: "view"
|
|
81
81
|
},
|
|
82
|
+
{
|
|
83
|
+
type: "function",
|
|
84
|
+
name: "isAllowedBot",
|
|
85
|
+
inputs: [{
|
|
86
|
+
name: "bot",
|
|
87
|
+
type: "address",
|
|
88
|
+
internalType: "address"
|
|
89
|
+
}],
|
|
90
|
+
outputs: [{
|
|
91
|
+
name: "",
|
|
92
|
+
type: "bool",
|
|
93
|
+
internalType: "bool"
|
|
94
|
+
}],
|
|
95
|
+
stateMutability: "view"
|
|
96
|
+
},
|
|
82
97
|
{
|
|
83
98
|
type: "function",
|
|
84
99
|
name: "isCreditAccount",
|
|
@@ -371,16 +371,19 @@ async function realize(steps, props) {
|
|
|
371
371
|
const aToken = await aavePoolAdapter(sdk, suite, step.token).aToken(step.token);
|
|
372
372
|
const aTokenAmount = ledger.balanceOf(aToken);
|
|
373
373
|
assertHolds(aToken, aTokenAmount, "aaveOpenPosition");
|
|
374
|
+
const debtToken = rwaAsset ?? underlying;
|
|
375
|
+
const borrowAmount = require_onchain_accounts_intents_utils_common.toTargetDecimals(step.borrow, underlying, debtToken, sdk);
|
|
374
376
|
push(require_onchain_accounts_intents_operations.buildAaveOpenPositionOperation({
|
|
375
377
|
adapter: aaveBridgeAdapter(sdk, suite, step.token, {
|
|
376
378
|
aToken,
|
|
377
|
-
debtToken
|
|
379
|
+
debtToken
|
|
378
380
|
}),
|
|
379
381
|
aToken,
|
|
380
382
|
aTokenAmount,
|
|
381
|
-
debtToken
|
|
382
|
-
borrowAmount
|
|
383
|
+
debtToken,
|
|
384
|
+
borrowAmount
|
|
383
385
|
}));
|
|
386
|
+
raised = borrowAmount;
|
|
384
387
|
break;
|
|
385
388
|
}
|
|
386
389
|
}
|
|
@@ -13,6 +13,7 @@ let viem = require("viem");
|
|
|
13
13
|
const abi = require_onchain_market_adapters_abi_adapters_iAaveHorizonBridgeAdapter.iAaveHorizonBridgeAdapterAbi;
|
|
14
14
|
const protocolAbi = require_onchain_market_adapters_abi_aave_iAaveHorizonBridge.iAaveHorizonBridgeAbi;
|
|
15
15
|
const FINALIZER_BOT_TYPE = (0, viem.stringToHex)("BOT::AAVE_HORIZON_FINALIZER", { size: 32 });
|
|
16
|
+
const SECURITIZE_FINALIZER_BOT_TYPE = (0, viem.stringToHex)("BOT::AAVE_HORIZON_SECURITIZE", { size: 32 });
|
|
16
17
|
/**
|
|
17
18
|
* The bridge a finalizer bot serves, from its `serialize()`:
|
|
18
19
|
* `abi.encode(pool, bridge)`. `undefined` where the bot did not serialize.
|
|
@@ -123,17 +124,23 @@ var AaveHorizonBridgeAdapterContract = class extends require_onchain_market_adap
|
|
|
123
124
|
}
|
|
124
125
|
}
|
|
125
126
|
/**
|
|
126
|
-
* Every account on this credit manager is finished by
|
|
127
|
+
* Every account on this credit manager is finished by a Horizon finalizer
|
|
127
128
|
* bot a block after its own transaction, so opening one grants the bot its
|
|
128
129
|
* permissions. The bot is the one the market configurator lists among its
|
|
129
130
|
* periphery contracts for this adapter's bridge, the latest version where
|
|
130
131
|
* there are several; nothing where it lists none.
|
|
132
|
+
*
|
|
133
|
+
* An account opened through an RWA factory belongs to the factory's wallet,
|
|
134
|
+
* which needs the Securitize finalizer and grants only the bots the factory
|
|
135
|
+
* allows; nothing where it does not allow that bot.
|
|
131
136
|
*/
|
|
132
137
|
async openingCalls() {
|
|
133
138
|
const { configurator } = this.sdk.marketRegister.findByCreditManager(this.creditManager);
|
|
134
|
-
const
|
|
139
|
+
const { creditFacade, rwaFactory } = this.sdk.marketRegister.findCreditManager(this.creditManager);
|
|
140
|
+
const botType = rwaFactory ? SECURITIZE_FINALIZER_BOT_TYPE : FINALIZER_BOT_TYPE;
|
|
141
|
+
const [bot] = (await this.sdk.accounts.bots.getMarketBots(configurator.address)).filter(({ baseParams }) => require_onchain_utils_hex.hexEq(baseParams.contractType, botType) && require_onchain_utils_hex.hexEq(finalizerBridge(baseParams.serializedParams), this.bridge)).sort((a, b) => Number(b.baseParams.version - a.baseParams.version));
|
|
135
142
|
if (!bot) return [];
|
|
136
|
-
|
|
143
|
+
if (rwaFactory && !await rwaFactory.isAllowedBot(bot.baseParams.addr)) return [];
|
|
137
144
|
return [creditFacade.prepareSetBotPermissions(bot.baseParams.addr, bot.requiredPermissions)];
|
|
138
145
|
}
|
|
139
146
|
stateHuman(raw) {
|
|
@@ -167,6 +167,15 @@ var SecuritizeRWAFactory = class extends require_onchain_base_BaseContract.BaseC
|
|
|
167
167
|
return this.contract.read.getWallet([creditAccount]);
|
|
168
168
|
}
|
|
169
169
|
/**
|
|
170
|
+
* {@inheritDoc IRWAFactory.isAllowedBot}
|
|
171
|
+
*
|
|
172
|
+
* Factories below 3.12 keep no allowlist, and their wallets reject every bot.
|
|
173
|
+
*/
|
|
174
|
+
async isAllowedBot(bot) {
|
|
175
|
+
if (this.version < 312) return false;
|
|
176
|
+
return this.contract.read.isAllowedBot([bot]);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
170
179
|
* {@inheritDoc IRWAFactory.multicall}
|
|
171
180
|
*/
|
|
172
181
|
multicall(creditAccount, calls, args) {
|
|
@@ -35,7 +35,7 @@ let viem = require("viem");
|
|
|
35
35
|
async function projectAavePosition(sdk, snapshot, owner) {
|
|
36
36
|
const suite = sdk.marketRegister.findCreditManager(snapshot.creditManager);
|
|
37
37
|
const market = sdk.marketRegister.findByCreditManager(snapshot.creditManager);
|
|
38
|
-
const
|
|
38
|
+
const underlying = market.unwrappedUnderlying;
|
|
39
39
|
const adapters = suite.creditManager.adapters.values();
|
|
40
40
|
const poolAdapters = adapters.filter((p) => p instanceof require_onchain_market_adapters_contracts_AaveV3PoolAdapterContract.AaveV3PoolAdapterContract);
|
|
41
41
|
const compressor = sdk.withdrawalCompressor;
|
|
@@ -78,6 +78,21 @@ const iSecuritizeRWAFactoryAbi = [
|
|
|
78
78
|
}],
|
|
79
79
|
stateMutability: "view"
|
|
80
80
|
},
|
|
81
|
+
{
|
|
82
|
+
type: "function",
|
|
83
|
+
name: "isAllowedBot",
|
|
84
|
+
inputs: [{
|
|
85
|
+
name: "bot",
|
|
86
|
+
type: "address",
|
|
87
|
+
internalType: "address"
|
|
88
|
+
}],
|
|
89
|
+
outputs: [{
|
|
90
|
+
name: "",
|
|
91
|
+
type: "bool",
|
|
92
|
+
internalType: "bool"
|
|
93
|
+
}],
|
|
94
|
+
stateMutability: "view"
|
|
95
|
+
},
|
|
81
96
|
{
|
|
82
97
|
type: "function",
|
|
83
98
|
name: "isCreditAccount",
|
|
@@ -370,16 +370,19 @@ async function realize(steps, props) {
|
|
|
370
370
|
const aToken = await aavePoolAdapter(sdk, suite, step.token).aToken(step.token);
|
|
371
371
|
const aTokenAmount = ledger.balanceOf(aToken);
|
|
372
372
|
assertHolds(aToken, aTokenAmount, "aaveOpenPosition");
|
|
373
|
+
const debtToken = rwaAsset ?? underlying;
|
|
374
|
+
const borrowAmount = toTargetDecimals(step.borrow, underlying, debtToken, sdk);
|
|
373
375
|
push(buildAaveOpenPositionOperation({
|
|
374
376
|
adapter: aaveBridgeAdapter(sdk, suite, step.token, {
|
|
375
377
|
aToken,
|
|
376
|
-
debtToken
|
|
378
|
+
debtToken
|
|
377
379
|
}),
|
|
378
380
|
aToken,
|
|
379
381
|
aTokenAmount,
|
|
380
|
-
debtToken
|
|
381
|
-
borrowAmount
|
|
382
|
+
debtToken,
|
|
383
|
+
borrowAmount
|
|
382
384
|
}));
|
|
385
|
+
raised = borrowAmount;
|
|
383
386
|
break;
|
|
384
387
|
}
|
|
385
388
|
}
|
|
@@ -12,6 +12,7 @@ import { decodeAbiParameters, decodeFunctionData, encodeFunctionData, stringToHe
|
|
|
12
12
|
const abi = iAaveHorizonBridgeAdapterAbi;
|
|
13
13
|
const protocolAbi = iAaveHorizonBridgeAbi;
|
|
14
14
|
const FINALIZER_BOT_TYPE = stringToHex("BOT::AAVE_HORIZON_FINALIZER", { size: 32 });
|
|
15
|
+
const SECURITIZE_FINALIZER_BOT_TYPE = stringToHex("BOT::AAVE_HORIZON_SECURITIZE", { size: 32 });
|
|
15
16
|
/**
|
|
16
17
|
* The bridge a finalizer bot serves, from its `serialize()`:
|
|
17
18
|
* `abi.encode(pool, bridge)`. `undefined` where the bot did not serialize.
|
|
@@ -122,17 +123,23 @@ var AaveHorizonBridgeAdapterContract = class extends AbstractAdapterContract {
|
|
|
122
123
|
}
|
|
123
124
|
}
|
|
124
125
|
/**
|
|
125
|
-
* Every account on this credit manager is finished by
|
|
126
|
+
* Every account on this credit manager is finished by a Horizon finalizer
|
|
126
127
|
* bot a block after its own transaction, so opening one grants the bot its
|
|
127
128
|
* permissions. The bot is the one the market configurator lists among its
|
|
128
129
|
* periphery contracts for this adapter's bridge, the latest version where
|
|
129
130
|
* there are several; nothing where it lists none.
|
|
131
|
+
*
|
|
132
|
+
* An account opened through an RWA factory belongs to the factory's wallet,
|
|
133
|
+
* which needs the Securitize finalizer and grants only the bots the factory
|
|
134
|
+
* allows; nothing where it does not allow that bot.
|
|
130
135
|
*/
|
|
131
136
|
async openingCalls() {
|
|
132
137
|
const { configurator } = this.sdk.marketRegister.findByCreditManager(this.creditManager);
|
|
133
|
-
const
|
|
138
|
+
const { creditFacade, rwaFactory } = this.sdk.marketRegister.findCreditManager(this.creditManager);
|
|
139
|
+
const botType = rwaFactory ? SECURITIZE_FINALIZER_BOT_TYPE : FINALIZER_BOT_TYPE;
|
|
140
|
+
const [bot] = (await this.sdk.accounts.bots.getMarketBots(configurator.address)).filter(({ baseParams }) => hexEq(baseParams.contractType, botType) && hexEq(finalizerBridge(baseParams.serializedParams), this.bridge)).sort((a, b) => Number(b.baseParams.version - a.baseParams.version));
|
|
134
141
|
if (!bot) return [];
|
|
135
|
-
|
|
142
|
+
if (rwaFactory && !await rwaFactory.isAllowedBot(bot.baseParams.addr)) return [];
|
|
136
143
|
return [creditFacade.prepareSetBotPermissions(bot.baseParams.addr, bot.requiredPermissions)];
|
|
137
144
|
}
|
|
138
145
|
stateHuman(raw) {
|
|
@@ -166,6 +166,15 @@ var SecuritizeRWAFactory = class extends BaseContract {
|
|
|
166
166
|
return this.contract.read.getWallet([creditAccount]);
|
|
167
167
|
}
|
|
168
168
|
/**
|
|
169
|
+
* {@inheritDoc IRWAFactory.isAllowedBot}
|
|
170
|
+
*
|
|
171
|
+
* Factories below 3.12 keep no allowlist, and their wallets reject every bot.
|
|
172
|
+
*/
|
|
173
|
+
async isAllowedBot(bot) {
|
|
174
|
+
if (this.version < 312) return false;
|
|
175
|
+
return this.contract.read.isAllowedBot([bot]);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
169
178
|
* {@inheritDoc IRWAFactory.multicall}
|
|
170
179
|
*/
|
|
171
180
|
multicall(creditAccount, calls, args) {
|
|
@@ -34,7 +34,7 @@ import { isAddressEqual } from "viem";
|
|
|
34
34
|
async function projectAavePosition(sdk, snapshot, owner) {
|
|
35
35
|
const suite = sdk.marketRegister.findCreditManager(snapshot.creditManager);
|
|
36
36
|
const market = sdk.marketRegister.findByCreditManager(snapshot.creditManager);
|
|
37
|
-
const
|
|
37
|
+
const underlying = market.unwrappedUnderlying;
|
|
38
38
|
const adapters = suite.creditManager.adapters.values();
|
|
39
39
|
const poolAdapters = adapters.filter((p) => p instanceof AaveV3PoolAdapterContract);
|
|
40
40
|
const compressor = sdk.withdrawalCompressor;
|
|
@@ -71,6 +71,20 @@ export declare const iSecuritizeRWAFactoryAbi: readonly [{
|
|
|
71
71
|
readonly internalType: "address";
|
|
72
72
|
}];
|
|
73
73
|
readonly stateMutability: "view";
|
|
74
|
+
}, {
|
|
75
|
+
readonly type: "function";
|
|
76
|
+
readonly name: "isAllowedBot";
|
|
77
|
+
readonly inputs: readonly [{
|
|
78
|
+
readonly name: "bot";
|
|
79
|
+
readonly type: "address";
|
|
80
|
+
readonly internalType: "address";
|
|
81
|
+
}];
|
|
82
|
+
readonly outputs: readonly [{
|
|
83
|
+
readonly name: "";
|
|
84
|
+
readonly type: "bool";
|
|
85
|
+
readonly internalType: "bool";
|
|
86
|
+
}];
|
|
87
|
+
readonly stateMutability: "view";
|
|
74
88
|
}, {
|
|
75
89
|
readonly type: "function";
|
|
76
90
|
readonly name: "isCreditAccount";
|
|
@@ -117,7 +117,8 @@ export type Step = {
|
|
|
117
117
|
} |
|
|
118
118
|
/**
|
|
119
119
|
* Hands every aToken of `token` the account holds to its owner through the
|
|
120
|
-
* Horizon bridge, which borrows `borrow
|
|
120
|
+
* Horizon bridge, which borrows `borrow`, in underlying units, into the
|
|
121
|
+
* account: of the underlying, or of the asset an RWA underlying wraps.
|
|
121
122
|
*/
|
|
122
123
|
{
|
|
123
124
|
kind: "aaveOpenPosition";
|
|
@@ -450,7 +450,8 @@ export interface RepayStrategyIntent {
|
|
|
450
450
|
* borrows the underlying on the owner's behalf into the account, and the loan
|
|
451
451
|
* is repaid in full with its quotas. The bridge borrows the debt plus a 10bps
|
|
452
452
|
* margin for the interest of the blocks still to come; whatever the facade
|
|
453
|
-
* does not take stays on the account.
|
|
453
|
+
* does not take stays on the account. On an RWA market Aave lends the asset
|
|
454
|
+
* the underlying wraps, which is wrapped before the repayment.
|
|
454
455
|
*
|
|
455
456
|
* The bridge borrows as the owner, so the owner must have delegated credit on
|
|
456
457
|
* the Aave variable debt token to the bridge beforehand.
|
|
@@ -317,11 +317,15 @@ export declare class AaveHorizonBridgeAdapterContract extends AbstractAdapterCon
|
|
|
317
317
|
amount: bigint;
|
|
318
318
|
} | undefined;
|
|
319
319
|
/**
|
|
320
|
-
* Every account on this credit manager is finished by
|
|
320
|
+
* Every account on this credit manager is finished by a Horizon finalizer
|
|
321
321
|
* bot a block after its own transaction, so opening one grants the bot its
|
|
322
322
|
* permissions. The bot is the one the market configurator lists among its
|
|
323
323
|
* periphery contracts for this adapter's bridge, the latest version where
|
|
324
324
|
* there are several; nothing where it lists none.
|
|
325
|
+
*
|
|
326
|
+
* An account opened through an RWA factory belongs to the factory's wallet,
|
|
327
|
+
* which needs the Securitize finalizer and grants only the bots the factory
|
|
328
|
+
* allows; nothing where it does not allow that bot.
|
|
325
329
|
*/
|
|
326
330
|
openingCalls(): Promise<MultiCall[]>;
|
|
327
331
|
stateHuman(raw?: boolean): {
|
|
@@ -82,6 +82,20 @@ declare const abi: readonly [{
|
|
|
82
82
|
readonly internalType: "address";
|
|
83
83
|
}];
|
|
84
84
|
readonly stateMutability: "view";
|
|
85
|
+
}, {
|
|
86
|
+
readonly type: "function";
|
|
87
|
+
readonly name: "isAllowedBot";
|
|
88
|
+
readonly inputs: readonly [{
|
|
89
|
+
readonly name: "bot";
|
|
90
|
+
readonly type: "address";
|
|
91
|
+
readonly internalType: "address";
|
|
92
|
+
}];
|
|
93
|
+
readonly outputs: readonly [{
|
|
94
|
+
readonly name: "";
|
|
95
|
+
readonly type: "bool";
|
|
96
|
+
readonly internalType: "bool";
|
|
97
|
+
}];
|
|
98
|
+
readonly stateMutability: "view";
|
|
85
99
|
}, {
|
|
86
100
|
readonly type: "function";
|
|
87
101
|
readonly name: "isCreditAccount";
|
|
@@ -493,6 +507,12 @@ export declare class SecuritizeRWAFactory extends BaseContract<abi> implements I
|
|
|
493
507
|
* {@inheritDoc IRWAFactory.getWallet}
|
|
494
508
|
*/
|
|
495
509
|
getWallet(creditAccount: Address): Promise<Address>;
|
|
510
|
+
/**
|
|
511
|
+
* {@inheritDoc IRWAFactory.isAllowedBot}
|
|
512
|
+
*
|
|
513
|
+
* Factories below 3.12 keep no allowlist, and their wallets reject every bot.
|
|
514
|
+
*/
|
|
515
|
+
isAllowedBot(bot: Address): Promise<boolean>;
|
|
496
516
|
/**
|
|
497
517
|
* {@inheritDoc IRWAFactory.multicall}
|
|
498
518
|
*/
|
|
@@ -147,6 +147,12 @@ export interface IRWAFactory<T extends RWAFactoryType = RWAFactoryType> extends
|
|
|
147
147
|
* @param creditAccount - credit account address
|
|
148
148
|
**/
|
|
149
149
|
getWallet(creditAccount: Address): Promise<Address>;
|
|
150
|
+
/**
|
|
151
|
+
* Whether the factory's wallets let a multicall grant `bot` permissions;
|
|
152
|
+
* they reject every other `setBotPermissions`.
|
|
153
|
+
* @param bot - bot address
|
|
154
|
+
**/
|
|
155
|
+
isAllowedBot(bot: Address): Promise<boolean>;
|
|
150
156
|
/**
|
|
151
157
|
* Creates a raw transaction to perform operations on a credit account.
|
|
152
158
|
* Similar to {@link CreditFacadeV310Contract.multicall}.
|
|
@@ -684,7 +684,10 @@ export interface IOpportunitiesPrepare {
|
|
|
684
684
|
* every credit manager with a Horizon bridge adapter, whichever of the two
|
|
685
685
|
* methods prepared it; the bot is the one the market configurator lists
|
|
686
686
|
* among its periphery contracts for that bridge, and with none listed the
|
|
687
|
-
* opening grants nothing and the move is left to {@link moveToAave}.
|
|
687
|
+
* opening grants nothing and the move is left to {@link moveToAave}. An
|
|
688
|
+
* account opened through an RWA factory gets the Securitize finalizer
|
|
689
|
+
* instead, and only where the factory allows it: its wallet rejects any
|
|
690
|
+
* other bot.
|
|
688
691
|
*
|
|
689
692
|
* The bot borrows the whole Gearbox debt on Aave or reverts, so an opening
|
|
690
693
|
* whose debt is above what Aave lends against the collateral at its LTV is
|
|
@@ -827,7 +830,8 @@ export interface IOpportunitiesPrepare {
|
|
|
827
830
|
* which borrows the underlying on the owner's behalf into the account, and
|
|
828
831
|
* the Gearbox loan is repaid in full with its quotas. Aave lends the debt
|
|
829
832
|
* plus a 10bps margin for the interest still to come; whatever the facade
|
|
830
|
-
* does not take stays on the account.
|
|
833
|
+
* does not take stays on the account. On an RWA market Aave lends the
|
|
834
|
+
* asset the underlying wraps, and it is wrapped before the repayment. The state answered is the credit
|
|
831
835
|
* account's: owing nothing, holding that remainder.
|
|
832
836
|
*
|
|
833
837
|
* The bridge borrows as the owner, so the transaction reverts unless the
|