Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/repay bundle #557

Merged
merged 12 commits into from
Nov 20, 2023
133 changes: 33 additions & 100 deletions packages/contract-helpers/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,184 +1,121 @@
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
All notable changes to this project will be documented in this file. See
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# 1.20.0 (2023-08-22)


### Features

* withdraw and swap ([#555](https://github.com/aave/aave-utilities/issues/555)) ([ca6c230](https://github.com/aave/aave-utilities/commit/ca6c230f39536ba34313ba5ec8295267742216a3))




- withdraw and swap ([#555](https://github.com/aave/aave-utilities/issues/555))
([ca6c230](https://github.com/aave/aave-utilities/commit/ca6c230f39536ba34313ba5ec8295267742216a3))

# 1.19.0 (2023-08-21)


### Features

* add Scroll Sepolia and Scroll chainIds ([#554](https://github.com/aave/aave-utilities/issues/554)) ([7510d22](https://github.com/aave/aave-utilities/commit/7510d227dd358f3420d7788a9feaaa72f09e8e9e))




- add Scroll Sepolia and Scroll chainIds
([#554](https://github.com/aave/aave-utilities/issues/554))
([7510d22](https://github.com/aave/aave-utilities/commit/7510d227dd358f3420d7788a9feaaa72f09e8e9e))

## 1.18.3 (2023-08-18)

**Note:** Version bump only for package @aave/contract-helpers





## 1.18.2 (2023-07-14)


### Bug Fixes

* remove commented imports ([#552](https://github.com/aave/aave-utilities/issues/552)) ([91a2772](https://github.com/aave/aave-utilities/commit/91a2772477ce2d9a809114dcbe2535c234603c38))




- remove commented imports
([#552](https://github.com/aave/aave-utilities/issues/552))
([91a2772](https://github.com/aave/aave-utilities/commit/91a2772477ce2d9a809114dcbe2535c234603c38))

## 1.18.1 (2023-07-12)

**Note:** Version bump only for package @aave/contract-helpers





# 1.18.0 (2023-07-12)


### Features

* debt switch ([#548](https://github.com/aave/aave-utilities/issues/548)) ([8c943d7](https://github.com/aave/aave-utilities/commit/8c943d78eda94f6e330e343d3cded9286ac2079c))




- debt switch ([#548](https://github.com/aave/aave-utilities/issues/548))
([8c943d7](https://github.com/aave/aave-utilities/commit/8c943d78eda94f6e330e343d3cded9286ac2079c))

## 1.17.8 (2023-06-22)

**Note:** Version bump only for package @aave/contract-helpers





## 1.17.7 (2023-06-16)

**Note:** Version bump only for package @aave/contract-helpers





## 1.17.6 (2023-06-01)


### Bug Fixes

* gas limits ([#543](https://github.com/aave/aave-utilities/issues/543)) ([cd4e533](https://github.com/aave/aave-utilities/commit/cd4e533c8c469306abaf4a9c1b0a1066b59cf875))




- gas limits ([#543](https://github.com/aave/aave-utilities/issues/543))
([cd4e533](https://github.com/aave/aave-utilities/commit/cd4e533c8c469306abaf4a9c1b0a1066b59cf875))

## 1.17.5 (2023-05-23)

**Note:** Version bump only for package @aave/contract-helpers





## 1.17.4 (2023-05-05)

**Note:** Version bump only for package @aave/contract-helpers





## 1.17.3 (2023-05-02)


### Bug Fixes

* decimal formatting in credit delegation approval checks ([#538](https://github.com/aave/aave-utilities/issues/538)) ([27eef6b](https://github.com/aave/aave-utilities/commit/27eef6b182f671fc9b4eb13cbd3712be17949c5c))




- decimal formatting in credit delegation approval checks
([#538](https://github.com/aave/aave-utilities/issues/538))
([27eef6b](https://github.com/aave/aave-utilities/commit/27eef6b182f671fc9b4eb13cbd3712be17949c5c))

## 1.17.2 (2023-05-01)


### Bug Fixes

* integer rounding for migration credit delegation approval buffer ([#537](https://github.com/aave/aave-utilities/issues/537)) ([3eef29e](https://github.com/aave/aave-utilities/commit/3eef29eb2e79bce2e1289c951fa00628bc5d4868))




- integer rounding for migration credit delegation approval buffer
([#537](https://github.com/aave/aave-utilities/issues/537))
([3eef29e](https://github.com/aave/aave-utilities/commit/3eef29eb2e79bce2e1289c951fa00628bc5d4868))

## 1.17.1 (2023-05-01)

**Note:** Version bump only for package @aave/contract-helpers





# 1.17.0 (2023-04-27)


### Features

* fixed available debt in isolated reserve in case that debt > ma… ([#532](https://github.com/aave/aave-utilities/issues/532)) ([7a2ea1e](https://github.com/aave/aave-utilities/commit/7a2ea1e94a26008247b4c4c045641291ff20261b))




- fixed available debt in isolated reserve in case that debt > ma…
([#532](https://github.com/aave/aave-utilities/issues/532))
([7a2ea1e](https://github.com/aave/aave-utilities/commit/7a2ea1e94a26008247b4c4c045641291ff20261b))

# 1.16.0 (2023-04-17)


### Features

* update borrow methods SDK ([#527](https://github.com/aave/aave-utilities/issues/527)) ([da31b83](https://github.com/aave/aave-utilities/commit/da31b836dd7a85da0dbfe664b67612b1f261c7a7))




- update borrow methods SDK
([#527](https://github.com/aave/aave-utilities/issues/527))
([da31b83](https://github.com/aave/aave-utilities/commit/da31b836dd7a85da0dbfe664b67612b1f261c7a7))

# 1.15.0 (2023-04-12)


### Features

* add Scroll Alpha chainId ([#528](https://github.com/aave/aave-utilities/issues/528)) ([3418c70](https://github.com/aave/aave-utilities/commit/3418c7087796397ed535fc7a3522445fb44f94c5))




- add Scroll Alpha chainId
([#528](https://github.com/aave/aave-utilities/issues/528))
([3418c70](https://github.com/aave/aave-utilities/commit/3418c7087796397ed535fc7a3522445fb44f94c5))

# 1.14.0 (2023-04-05)


### Features

* tx bundle refactor ([#514](https://github.com/aave/aave-utilities/issues/514)) ([fc5c937](https://github.com/aave/aave-utilities/commit/fc5c9378b48a14a31df9fdbe435095a3e81390a2)), closes [#524](https://github.com/aave/aave-utilities/issues/524) [#504](https://github.com/aave/aave-utilities/issues/504)




- tx bundle refactor ([#514](https://github.com/aave/aave-utilities/issues/514))
([fc5c937](https://github.com/aave/aave-utilities/commit/fc5c9378b48a14a31df9fdbe435095a3e81390a2)),
closes [#524](https://github.com/aave/aave-utilities/issues/524)
[#504](https://github.com/aave/aave-utilities/issues/504)

# Change Log

Expand All @@ -189,10 +126,6 @@ All notable changes to this project will be documented in this file. See

**Note:** Version bump only for package @aave/contract-helpers





## 1.13.6 (2023-03-03)

**Note:** Version bump only for package @aave/contract-helpers
Expand Down
20 changes: 19 additions & 1 deletion packages/contract-helpers/src/commons/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { BigNumber, BytesLike, PopulatedTransaction } from 'ethers';
import { LPBorrowParamsType } from '../v3-pool-contract/lendingPoolTypes';
import {
LPBorrowParamsType,
LPRepayParamsType,
LPRepayWithATokensType,
LPRepayWithPermitParamsType,
} from '../v3-pool-contract/lendingPoolTypes';

export type tEthereumAddress = string;
export type ENS = string; // something.eth
Expand Down Expand Up @@ -115,6 +120,8 @@ export enum ProtocolAction {
liquidationCall = 'liquidationCall',
liquidationFlash = 'liquidationFlash',
repay = 'repay',
repayETH = 'repayETH',
repayWithATokens = 'repayWithATokens',
swapCollateral = 'swapCollateral',
repayCollateral = 'repayCollateral',
withdrawETH = 'withdrawETH',
Expand Down Expand Up @@ -345,3 +352,14 @@ export type BorrowTxBuilder = {
encodedTxData,
}: LPBorrowParamsType) => PopulatedTransaction;
};

export type RepayTxBuilder = {
generateTxData: (params: LPRepayParamsType) => PopulatedTransaction;
generateSignedTxData: (
params: LPRepayWithPermitParamsType,
) => PopulatedTransaction;
};

export type RepayWithATokensTxBuilder = {
generateTxData: (params: LPRepayWithATokensType) => PopulatedTransaction;
};
16 changes: 12 additions & 4 deletions packages/contract-helpers/src/commons/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export const gasLimitRecommendations: GasRecommendationType = {
limit: '300000',
recommended: '300000',
},
[ProtocolAction.repayETH]: {
limit: '350000',
recommended: '300000',
},
[ProtocolAction.borrowETH]: {
limit: '450000',
recommended: '450000',
Expand Down Expand Up @@ -106,6 +110,10 @@ export const gasLimitRecommendations: GasRecommendationType = {
limit: '350000',
recommended: '350000',
},
[ProtocolAction.stake]: {
limit: '350000',
recommended: '350000',
},
[ProtocolAction.stakeWithPermit]: {
limit: '400000',
recommended: '400000',
Expand All @@ -114,10 +122,6 @@ export const gasLimitRecommendations: GasRecommendationType = {
limit: '125000',
recommended: '125000',
},
[ProtocolAction.stake]: {
limit: '395000',
recommended: '395000',
},
[ProtocolAction.claimRewards]: {
limit: '275000',
recommended: '275000',
Expand All @@ -126,6 +130,10 @@ export const gasLimitRecommendations: GasRecommendationType = {
limit: '138000',
recommended: '138000',
},
[ProtocolAction.repayWithATokens]: {
limit: '300000',
recommended: '300000',
},
[ProtocolAction.withdrawAndSwitch]: {
limit: '1000000',
recommended: '1000000',
Expand Down
42 changes: 42 additions & 0 deletions packages/contract-helpers/src/lendingPool-contract-bundle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import {
LPBorrowParamsType,
LPDepositParamsType,
LPRepayParamsType,
} from '../lendingPool-contract/lendingPoolTypes';
import {
ILendingPool,
Expand All @@ -43,6 +44,10 @@ export type DepositTxBuilder = {
getApprovedAmount: ({ user, token }: TokenOwner) => Promise<ApproveType>;
};

export type LPRepayTxBuilder = {
generateTxData: (args: LPRepayParamsType) => PopulatedTransaction;
};

export interface LendingPoolBundleInterface {
depositTxBuilder: DepositTxBuilder;
}
Expand All @@ -65,6 +70,7 @@ export class LendingPoolBundle

depositTxBuilder: DepositTxBuilder;
borrowTxBuilder: Omit<BorrowTxBuilder, 'useOptimizedPath' | 'encodedTxData'>;
repayTxBuilder: LPRepayTxBuilder;

constructor(
provider: providers.Provider,
Expand Down Expand Up @@ -191,5 +197,41 @@ export class LendingPoolBundle
return actionTx;
},
};
this.repayTxBuilder = {
grothem marked this conversation as resolved.
Show resolved Hide resolved
generateTxData: ({
user,
reserve,
onBehalfOf,
interestRateMode,
amount,
}) => {
const actionTx: PopulatedTransaction = {};
if (reserve.toLowerCase() === API_ETH_MOCK_ADDRESS.toLowerCase()) {
return this.wethGatewayService.generateRepayEthTxData({
lendingPool: this.lendingPoolAddress,
user,
amount,
interestRateMode,
onBehalfOf,
});
}

const numericRateMode =
interestRateMode === InterestRate.Variable ? 2 : 1;
const txData = this.contractInterface.encodeFunctionData('repay', [
reserve,
amount,
numericRateMode,
onBehalfOf ?? user,
]);
actionTx.to = this.lendingPoolAddress;
actionTx.from = user;
actionTx.data = txData;
actionTx.gasLimit = BigNumber.from(
gasLimitRecommendations[ProtocolAction.repay].recommended,
);
return actionTx;
},
};
}
}
Loading
Loading