Skip to content

Commit 766b83c

Browse files
authored
Merge pull request #169 from defisaver/feat/aave-v4
feat: aave v4
2 parents 056f5b9 + ffc654a commit 766b83c

21 files changed

Lines changed: 549 additions & 2 deletions

‎src/Strategy.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ export class Strategy {
3636
this.actions.push(newAction);
3737
}
3838

39+
addActions(newActions: Array<Action>) {
40+
this.actions.push(...newActions);
41+
}
42+
3943
print() {
4044
console.log(`Name: ${this.name}`);
4145
console.log(`Slots: ${this.subSlots}`);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Action } from '../../Action';
2+
import { getAddr } from '../../addresses';
3+
import { EthAddress, uint256 } from '../../types';
4+
5+
/**
6+
* AaveV4BorrowAction
7+
*
8+
* @category AaveV4
9+
*/
10+
export class AaveV4BorrowAction extends Action {
11+
/**
12+
* @param spoke Address of the spoke.
13+
* @param onBehalf Address to borrow tokens on behalf of. Defaults to the user's wallet if not provided.
14+
* @param to Address that will receive the borrowed tokens.
15+
* @param reserveId Reserve id.
16+
* @param amount Amount of tokens to borrow.
17+
*/
18+
constructor(
19+
spoke: EthAddress,
20+
onBehalf: EthAddress,
21+
to: EthAddress,
22+
reserveId: uint256,
23+
amount: uint256,
24+
) {
25+
super(
26+
'AaveV4Borrow',
27+
getAddr('AaveV4Borrow'),
28+
['address', 'address', 'address', 'uint256', 'uint256'],
29+
[spoke, onBehalf, to, reserveId, amount],
30+
);
31+
this.mappableArgs = [
32+
this.args[0],
33+
this.args[1],
34+
this.args[2],
35+
this.args[3],
36+
this.args[4],
37+
];
38+
}
39+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Action } from '../../Action';
2+
import { getAddr } from '../../addresses';
3+
import { EthAddress, uint256 } from '../../types';
4+
5+
/**
6+
* AaveV4CollateralSwitchAction
7+
*
8+
* @category AaveV4
9+
*/
10+
export class AaveV4CollateralSwitchAction extends Action {
11+
/**
12+
* @param spoke Address of the spoke.
13+
* @param onBehalf Address to switch collateral on behalf of. Defaults to the user's wallet if not provided.
14+
* @param reserveId Reserve id.
15+
* @param useAsCollateral Whether to use the tokens as collateral.
16+
*/
17+
constructor(
18+
spoke: EthAddress,
19+
onBehalf: EthAddress,
20+
reserveId: uint256,
21+
useAsCollateral: boolean,
22+
) {
23+
super(
24+
'AaveV4CollateralSwitch',
25+
getAddr('AaveV4CollateralSwitch'),
26+
['address', 'address', 'uint256', 'bool'],
27+
[spoke, onBehalf, reserveId, useAsCollateral],
28+
);
29+
this.mappableArgs = [
30+
this.args[0],
31+
this.args[1],
32+
this.args[2],
33+
this.args[3],
34+
];
35+
}
36+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Action } from '../../Action';
2+
import { getAddr } from '../../addresses';
3+
import { bytes } from '../../types';
4+
5+
/**
6+
* AaveV4DelegateBorrowWithSigAction -Approves a spender to borrow from the specified reserve using an EIP712-typed intent.
7+
*
8+
* @category AaveV4
9+
*/
10+
export class AaveV4DelegateBorrowWithSigAction extends Action {
11+
/**
12+
* @param permit EIP712-typed intent.
13+
* @param signature The EIP712-compliant signature bytes.
14+
*/
15+
constructor(
16+
permit: Array<any>,
17+
signature: bytes,
18+
) {
19+
super(
20+
'AaveV4DelegateBorrowWithSig',
21+
getAddr('AaveV4DelegateBorrowWithSig'),
22+
[
23+
['address', 'uint256', 'address', 'address', 'uint256', 'uint256', 'uint256'],
24+
'bytes',
25+
],
26+
[permit, signature],
27+
);
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Action } from '../../Action';
2+
import { getAddr } from '../../addresses';
3+
import { bytes } from '../../types';
4+
5+
/**
6+
* AaveV4DelegateSetUsingAsCollateralWithSigAction - Approves a delegatee to set using as collateral on behalf of delegator using an EIP712-typed intent.
7+
*
8+
* @category AaveV4
9+
*/
10+
export class AaveV4DelegateSetUsingAsCollateralWithSigAction extends Action {
11+
/**
12+
* @param permit EIP712-typed intent.
13+
* @param signature The EIP712-compliant signature bytes.
14+
*/
15+
constructor(
16+
permit: Array<any>,
17+
signature: bytes,
18+
) {
19+
super(
20+
'AaveV4DelegateSetUsingAsCollateralWithSig',
21+
getAddr('AaveV4DelegateSetUsingAsCollateralWithSig'),
22+
[
23+
['address', 'address', 'address', 'bool', 'uint256', 'uint256'],
24+
'bytes',
25+
],
26+
[permit, signature],
27+
);
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Action } from '../../Action';
2+
import { getAddr } from '../../addresses';
3+
import { bytes } from '../../types';
4+
5+
/**
6+
* AaveV4DelegateWithdrawWithSigAction - Approves a spender to withdraw from the specified reserve using an EIP712-typed intent.
7+
*
8+
* @category AaveV4
9+
*/
10+
export class AaveV4DelegateWithdrawWithSigAction extends Action {
11+
/**
12+
* @param permit EIP712-typed intent.
13+
* @param signature The EIP712-compliant signature bytes.
14+
*/
15+
constructor(
16+
permit: Array<any>,
17+
signature: bytes,
18+
) {
19+
super(
20+
'AaveV4DelegateWithdrawWithSig',
21+
getAddr('AaveV4DelegateWithdrawWithSig'),
22+
[
23+
['address', 'uint256', 'address', 'address', 'uint256', 'uint256', 'uint256'],
24+
'bytes',
25+
],
26+
[permit, signature],
27+
);
28+
}
29+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { getAssetInfoByAddress } from '@defisaver/tokens';
2+
import { Action } from '../../Action';
3+
import { getAddr } from '../../addresses';
4+
import { EthAddress, uint256 } from '../../types';
5+
6+
/**
7+
* AaveV4PaybackAction
8+
*
9+
* @category AaveV4
10+
*/
11+
export class AaveV4PaybackAction extends Action {
12+
tokenForApproval: EthAddress;
13+
14+
/**
15+
* @param spoke Address of the spoke.
16+
* @param onBehalf Address to payback tokens on behalf of. Defaults to the user's wallet if not provided.
17+
* @param from Address from which to pull the payback tokens.
18+
* @param reserveId Reserve id.
19+
* @param amount Amount of tokens to payback. Send type(uint).max to payback whole amount.
20+
* @param tokenAddress Address of the token to approve. Optional, as it is only used for token approval, not part of encoding.
21+
*/
22+
constructor(
23+
spoke: EthAddress,
24+
onBehalf: EthAddress,
25+
from: EthAddress,
26+
reserveId: uint256,
27+
amount: uint256,
28+
tokenAddress: EthAddress = getAddr('Empty'),
29+
) {
30+
super(
31+
'AaveV4Payback',
32+
getAddr('AaveV4Payback'),
33+
['address', 'address', 'address', 'uint256', 'uint256'],
34+
[spoke, onBehalf, from, reserveId, amount],
35+
);
36+
this.mappableArgs = [
37+
this.args[0],
38+
this.args[1],
39+
this.args[2],
40+
this.args[3],
41+
this.args[4],
42+
];
43+
this.tokenForApproval = tokenAddress;
44+
}
45+
46+
async getAssetsToApprove() {
47+
const asset = getAssetInfoByAddress(this.tokenForApproval);
48+
if (asset.symbol !== 'ETH') return [{ asset: this.tokenForApproval, owner: this.args[2] }];
49+
return [];
50+
}
51+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Action } from '../../Action';
2+
import { getAddr } from '../../addresses';
3+
import { EthAddress } from '../../types';
4+
5+
/**
6+
* AaveV4RefreshPremiumAction - Refresh the risk premium for user's position
7+
*
8+
* @category AaveV4RefreshPremium
9+
*/
10+
export class AaveV4RefreshPremiumAction extends Action {
11+
/**
12+
* @param spoke Address of the spoke.
13+
* @param onBehalf Address to refresh the config on behalf of. Defaults to the user's wallet if not provided.
14+
* @param refreshDynamicReserveConfig Whether to also refresh the dynamic reserve config for all collateral reserves.
15+
*/
16+
constructor(
17+
spoke: EthAddress,
18+
onBehalf: EthAddress,
19+
refreshDynamicReserveConfig: boolean,
20+
) {
21+
super(
22+
'AaveV4RefreshPremium',
23+
getAddr('AaveV4RefreshPremium'),
24+
['address', 'address', 'bool'],
25+
[spoke, onBehalf, refreshDynamicReserveConfig],
26+
);
27+
this.mappableArgs = [
28+
this.args[0],
29+
this.args[1],
30+
this.args[2],
31+
];
32+
}
33+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Action } from '../../Action';
2+
import { getAddr } from '../../addresses';
3+
import { EthAddress, bytes, uint256 } from '../../types';
4+
5+
/**
6+
* AaveV4SetUserManagersWithSigAction - Sets user position managers with EIP712-typed signature.
7+
*
8+
* @category AaveV4
9+
*/
10+
export class AaveV4SetUserManagersWithSigAction extends Action {
11+
/**
12+
* @param spoke Address of the spoke.
13+
* @param onBehalf The address of the user on whose behalf position manager can act.
14+
* @param nonce The nonce for the signature.
15+
* @param deadline The deadline for the signature.
16+
* @param signature The signature bytes.
17+
* @param updates The array of position manager updates.
18+
*/
19+
constructor(
20+
spoke: EthAddress,
21+
onBehalf: EthAddress,
22+
nonce: uint256,
23+
deadline: uint256,
24+
signature: bytes,
25+
updates: Array<[EthAddress, boolean]>,
26+
) {
27+
super(
28+
'AaveV4SetUserManagersWithSig',
29+
getAddr('AaveV4SetUserManagersWithSig'),
30+
['address', 'address', 'uint256', 'uint256', 'bytes', 'tuple(address,bool)[]'],
31+
[spoke, onBehalf, nonce, deadline, signature, updates],
32+
);
33+
}
34+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Action } from '../../Action';
2+
import { getAddr } from '../../addresses';
3+
import { EthAddress } from '../../types';
4+
5+
/**
6+
* AaveV4StoreRatioAction - Stores the ratio for a user in transient storage so it can be checked later after strategy execution.
7+
*
8+
* @category AaveV4
9+
*/
10+
export class AaveV4StoreRatioAction extends Action {
11+
/**
12+
* @param spoke Address of the spoke.
13+
* @param user Address of the user to store the ratio for.
14+
*/
15+
constructor(
16+
spoke: EthAddress,
17+
user: EthAddress,
18+
) {
19+
super(
20+
'AaveV4StoreRatio',
21+
getAddr('Empty'),
22+
['address', 'address'],
23+
[spoke, user],
24+
);
25+
this.mappableArgs = [
26+
this.args[0],
27+
this.args[1],
28+
];
29+
}
30+
}

0 commit comments

Comments
 (0)