diff --git a/README.md b/README.md index 994e0f20..d66413f0 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ The Aave Protocol is a decentralized non-custodial liquidity protocol where users can participate as suppliers or borrowers. The protocol is a set of -open source smart contracts which facilitate the logic of user interactions. +open source smart contracts which facilitate the logic of user interactions. These contracts, and all user transactions/balances are stored on a public ledger called a blockchain, making them accessible to anyone @@ -16,11 +16,11 @@ The `@aave/math-utils` package contains methods for formatting raw ([ethers.js](#ethers.js)) or indexed ([subgraph](#subgraph), [caching server](#caching-server)) contract data for usage on a frontend -The `@aave/contract-helpers` package contains methods for generating trancations -based on method and parameter inputs. Can be used to read and write data on the -protocol contracts. +The `@aave/contract-helpers` package contains methods for generating transactions +based on method and parameter inputs. It can be used to read and write data to the +on-chain protocol contracts. -
+  ## Installation @@ -41,65 +41,60 @@ yarn add --dev ethers reflect-metadata yarn add @aave/contract-helpers @aave/math-utils ``` -
+  ## Features -1. [Data Formatting Methods](#data-formatting-methods) - - a. [Fetching Protocol Data](#fetching-protocol-data) - - [ethers](#ethersjs) - - [Subgraph](#subgraph) - - [Caching Server](#caching-server) - - b. [Format Reserve Data](#reserve-data) - - [formatReserves](#formatReserves) - - [formatReservesAndIncentives](#formatReservesAndIncentives) - - c. [Format User Data](#user-data) - - [formatUserSummary](#formatUserSummary) - - [formatUserSummaryAndIncentives](#formatUserSummaryAndIncentives) -2. [Transaction Methods](#transaction-methods) - - a. [Submitting Transactions](#submitting-transactions) - - b. [Pool V3](#pool-v3) - - [supply](#supply) - - [signERC20Approval](#signERC20Approval) - - [supplyWithPermit](#supply-with-permit) - - [borrow](<#borrow-(v3)>) - - [repay](<#repay-(v3)>) - - [repayWithPermit](#repayWithPermit) - - [repayWithATokens](#repayWithATokens) - - [withdraw](<#withdraw-(v3)>) - - [swapBorrowRateMode](<#swapBorrowRateMode-(v3)>) - - [setUsageAsCollateral](<#setUsageAsCollateral-(v3)>) - - [liquidationCall](<#liquidationCall-(v3)>) - - [swapCollateral](<#swapCollateral-(v3)>) - - [repayWithCollateral](<#repayWithCollateral-(v3)>) - - [setUserEMode](#setUserEMode) - - c. [Lending Pool V2](#lending-pool-v2) - - [deposit](#deposit) - - [borrow](#borrow) - - [repay](#repay) - - [withdraw](#withdraw) - - [swapBorrowRateMode](#swapBorrowRateMode) - - [setUsageAsCollateral](#setUsageAsCollateral) - - [liquidationCall](#liquidationCall) - - [swapCollateral](#swapCollateral) - - [repayWithCollateral](#repayWithCollateral) - - d. [Staking](#staking) - - [stake](#stake) - - [redeem](#redeem) - - [cooldown](#cooldown) - - [claimRewards](#claimRewards) - - e. [Governance V2](#governancev2) - - [create](#create) - - [cancel](#cancel) - - [queue](#queue) - - [execute](#execute) - - [submitVote](#submitVote) - - [delegate](#delegate) - - [delegateByType](#delegateByType) - - f. [Faucets](#faucets) - - [mint](#mint) - - g. [Credit Delegation](#credit-delegation) - - [approveDelegation](#approveDelegation) +- [Data Formatting Methods](#data-formatting-methods) + - [Fetching Protocol Data](#fetching-protocol-data) + - [ethers.js](#ethersjs) + - [Subgraph](#subgraph) + - [Caching Server](#caching-server) + - [Reserve Data](#reserve-data) + - [formatReserves](#formatreserves) + - [formatReservesAndIncentives](#formatreservesandincentives) + - [User Data](#user-data) + - [formatUserSummary](#formatusersummary) + - [formatUserSummaryAndIncentives](#formatusersummaryandincentives) +- [Transaction Methods](#transaction-methods) + - [Submitting Transactions](#submitting-transactions) + - [Pool V3](#pool-v3) + - [supply](#supply) + - [signERC20Approval](#signerc20approval) + - [supplyWithPermit](#supplywithpermit) + - [borrow (V3)](#borrow-v3) + - [repay (V3)](#repay-v3) + - [repayWithPermit](#repaywithpermit) + - [repayWithATokens](#repaywithatokens) + - [withdraw (V3)](#withdraw-v3) + - [swapBorrowRateMode (V3)](#swapborrowratemode-v3) + - [setUsageAsCollateral (V3)](#setusageascollateral-v3) + - [liquidationCall (V3)](#liquidationcall-v3) + - [swapCollateral (V3)](#swapcollateral-v3) + - [repayWithCollateral (V3)](#repaywithcollateral-v3) + - [setUserEMode](#setuseremode) + - [Lending Pool V2](#lending-pool-v2) + - [deposit](#deposit) + - [borrow](#borrow) + - [repay](#repay) + - [withdraw](#withdraw) + - [swapBorrowRateMode](#swapborrowratemode) + - [setUsageAsCollateral](#setusageascollateral) + - [liquidationCall](#liquidationcall) + - [swapCollateral](#swapcollateral) + - [repayWithCollateral](#repaywithcollateral) + - [Governance V2](#governance-v2) + - [create](#create) + - [cancel](#cancel) + - [queue](#queue) + - [execute](#execute) + - [submitVote](#submitvote) + - [delegate](#delegate) + - [delegateByType](#delegatebytype) + - [Faucets](#faucets) + - [mint](#mint) + - [Credit Delegation](#credit-delegation) + - [approveDelegation](#approvedelegation)
@@ -136,7 +131,7 @@ it query the helper contract data which can be passed directly into data formatting methods.
- Sample Code + Sample Code ```ts import { ethers } from 'ethers'; @@ -239,7 +234,7 @@ different. Queries will depend on two parameters: - `user` : user to fetch account data for
- V2 + V2
Reserves @@ -354,7 +349,7 @@ For ETH-based markets (all V2 markets except Avalanche): - `marketReferenceCurrencyDecimals` = 18 For USD-based markets (Avalanche and all v3 markets): - + - `marketReferencePriceInUsd` = "100000000" - `marketReferenceCurrencyDecimals` = 8 @@ -372,7 +367,7 @@ maps incentives to reserves and userReserves.
- V3 + V3
Reserves @@ -480,7 +475,7 @@ and will input to the user formatters separately.
Base Currency Data - + All V3 market use USD based oracles, so baseCurrencyData can be hardcoded: - `marketReferencePriceInUsd` = "100000000" @@ -786,9 +781,9 @@ const pool = new Pool(provider, { }); /* -- @param `user` The ethereum address that will make the deposit -- @param `reserve` The ethereum address of the reserve -- @param `amount` The amount to be deposited +- @param `user` The ethereum address that will make the deposit +- @param `reserve` The ethereum address of the reserve +- @param `amount` The amount to be deposited - @param @optional `onBehalfOf` The ethereum address for which user is depositing. It will default to the user address */ const txs: EthereumTransactionTypeExtended[] = await pool.supply({ @@ -833,9 +828,9 @@ const pool = new Pool(provider, { }); /* -- @param `user` The ethereum address that will make the deposit -- @param `reserve` The ethereum address of the reserve -- @param `amount` The amount to be deposited +- @param `user` The ethereum address that will make the deposit +- @param `reserve` The ethereum address of the reserve +- @param `amount` The amount to be deposited - @param `deadline` Expiration of signature in seconds, for example, 1 hour = Math.floor(Date.now() / 1000 + 3600).toString() */ const dataToSign: string = await pool.signERC20Approval({ @@ -874,9 +869,9 @@ const pool = new Pool(provider, { }); /* -- @param `user` The ethereum address that will make the deposit -- @param `reserve` The ethereum address of the reserve -- @param `amount` The amount to be deposited +- @param `user` The ethereum address that will make the deposit +- @param `reserve` The ethereum address of the reserve +- @param `amount` The amount to be deposited - @param `signature` Signature approving Pool to spend user funds, received from signing output data of signERC20Approval() - @param @optional `onBehalfOf` The ethereum address for which user is depositing. It will default to the user address */ @@ -913,9 +908,9 @@ const pool = new Pool(provider, { }); /* -- @param `user` The ethereum address that repays -- @param `reserve` The ethereum address of the reserve on which the user borrowed -- @param `amount` The amount to repay, or (-1) if the user wants to repay everything +- @param `user` The ethereum address that repays +- @param `reserve` The ethereum address of the reserve on which the user borrowed +- @param `amount` The amount to repay, or (-1) if the user wants to repay everything - @param `interestRateMode` // Whether the borrow will incur a stable (InterestRate.Stable) or variable (InterestRate.Variable) interest rate - @param @optional `onBehalfOf` The ethereum address for which user is repaying. It will default to the user address */ @@ -956,9 +951,9 @@ const pool = new Pool(provider, { }); /* -- @param `user` The ethereum address that will make the deposit -- @param `reserve` The ethereum address of the reserve -- @param `amount` The amount to be deposited +- @param `user` The ethereum address that will make the deposit +- @param `reserve` The ethereum address of the reserve +- @param `amount` The amount to be deposited - @param `interestRateMode` // Whether stable (InterestRate.Stable) or variable (InterestRate.Variable) debt will be repaid - @param @optional `onBehalfOf` The ethereum address for which user is depositing. It will default to the user address */ @@ -998,9 +993,9 @@ const pool = new Pool(provider, { }); /* -- @param `user` The ethereum address that will make the deposit -- @param `reserve` The ethereum address of the reserve -- @param `amount` The amount to be deposited +- @param `user` The ethereum address that will make the deposit +- @param `reserve` The ethereum address of the reserve +- @param `amount` The amount to be deposited - @param `signature` Signature approving Pool to spend user funds, from signERC20Approval() - @param @optional `onBehalfOf` The ethereum address for which user is depositing. It will default to the user address */ @@ -1040,9 +1035,9 @@ const pool = new Pool(provider, { }); /* -- @param `user` The ethereum address that will make the deposit +- @param `user` The ethereum address that will make the deposit - @param `amount` The amount to be deposited, -1 to repay max aToken balance or max debt balance without dust (whichever is lowest) -- @param `reserve` The ethereum address of the reserve +- @param `reserve` The ethereum address of the reserve - @param `rateMode` The debt type to repay, stable (InterestRate.Stable) or variable (InterestRate.Variable) */ const txs: EthereumTransactionTypeExtended[] = await pool.repayWithATokens({ @@ -1075,9 +1070,9 @@ const pool = new Pool(provider, { }); /* -- @param `user` The ethereum address that will make the deposit -- @param `reserve` The ethereum address of the reserve -- @param `amount` The amount to be deposited +- @param `user` The ethereum address that will make the deposit +- @param `reserve` The ethereum address of the reserve +- @param `amount` The amount to be deposited - @param `aTokenAddress` The aToken to redeem for underlying asset - @param @optional `onBehalfOf` The ethereum address for which user is depositing. It will default to the user address */ @@ -1113,9 +1108,9 @@ const pool = new Pool(provider, { }); /* -- @param `user` The ethereum address that will make the deposit -- @param `reserve` The ethereum address of the reserve -- @param `interestRateMode` The rate mode to swap to, stable (InterestRate.Stable) or variable (InterestRate.Variable) +- @param `user` The ethereum address that will make the deposit +- @param `reserve` The ethereum address of the reserve +- @param `interestRateMode` The rate mode to swap to, stable (InterestRate.Stable) or variable (InterestRate.Variable) */ const txs: EthereumTransactionTypeExtended[] = await pool.swapBorrowRateMode({ user, @@ -1147,8 +1142,8 @@ const pool = new Pool(provider, { }); /* -- @param `user` The ethereum address that will make the deposit -- @param `reserve` The ethereum address of the reserve +- @param `user` The ethereum address that will make the deposit +- @param `reserve` The ethereum address of the reserve - @param `usageAsCollateral` Boolean, true if the user wants to use the deposit as collateral, false otherwise */ const txs: EthereumTransactionTypeExtended[] = await pool.setUsageAsCollateral({ @@ -1180,11 +1175,11 @@ const pool = new Pool(provider, { }); /* -- @param `liquidator` The ethereum address that will liquidate the position -- @param `liquidatedUser` The address of the borrower -- @param `debtReserve` The ethereum address of the principal reserve -- @param `collateralReserve` The address of the collateral to liquidated -- @param `purchaseAmount` The amount of principal that the liquidator wants to repay +- @param `liquidator` The ethereum address that will liquidate the position +- @param `liquidatedUser` The address of the borrower +- @param `debtReserve` The ethereum address of the principal reserve +- @param `collateralReserve` The address of the collateral to liquidated +- @param `purchaseAmount` The amount of principal that the liquidator wants to repay - @param @optional `getAToken` Boolean to indicate if the user wants to receive the aToken instead of the asset. Defaults to false */ const txs: EthereumTransactionTypeExtended[] = lendingPool.liquidationCall({ @@ -1220,18 +1215,18 @@ const pool = new Pool(provider, { }); /* -- @param `user` The ethereum address that will liquidate the position -- @param @optional `flash` If the transaction will be executed through a flasloan(true) or will be done directly through the adapters(false). Defaults to false -- @param `fromAsset` The ethereum address of the asset you want to swap -- @param `fromAToken` The ethereum address of the aToken of the asset you want to swap -- @param `toAsset` The ethereum address of the asset you want to swap to (get) -- @param `fromAmount` The amount you want to swap -- @param `toAmount` The amount you want to get after the swap -- @param `maxSlippage` The max slippage that the user accepts in the swap -- @param @optional `permitSignature` A permit signature of the tx. Only needed when previously signed (Not needed at the moment). -- @param `swapAll` Bool indicating if the user wants to swap all the current collateral -- @param @optional `onBehalfOf` The ethereum address for which user is swaping. It will default to the user address -- @param @optional `referralCode` Integrators are assigned a referral code and can potentially receive rewards. It defaults to 0 (no referrer) +- @param `user` The ethereum address that will liquidate the position +- @param @optional `flash` If the transaction will be executed through a flasloan(true) or will be done directly through the adapters(false). Defaults to false +- @param `fromAsset` The ethereum address of the asset you want to swap +- @param `fromAToken` The ethereum address of the aToken of the asset you want to swap +- @param `toAsset` The ethereum address of the asset you want to swap to (get) +- @param `fromAmount` The amount you want to swap +- @param `toAmount` The amount you want to get after the swap +- @param `maxSlippage` The max slippage that the user accepts in the swap +- @param @optional `permitSignature` A permit signature of the tx. Only needed when previously signed (Not needed at the moment). +- @param `swapAll` Bool indicating if the user wants to swap all the current collateral +- @param @optional `onBehalfOf` The ethereum address for which user is swaping. It will default to the user address +- @param @optional `referralCode` Integrators are assigned a referral code and can potentially receive rewards. It defaults to 0 (no referrer) - @param @optional `useEthPath` Boolean to indicate if the swap will use an ETH path. Defaults to false */ const txs: EthereumTransactionTypeExtended[] = await lendingPool.swapCollateral( @@ -1276,18 +1271,18 @@ const pool = new Pool(provider, { }); /* -- @param `user` The ethereum address that will liquidate the position -- @param `fromAsset` The ethereum address of the asset you want to repay with (collateral) -- @param `fromAToken` The ethereum address of the aToken of the asset you want to repay with (collateral) -- @param `assetToRepay` The ethereum address of the asset you want to repay -- @param `repayWithAmount` The amount of collateral you want to repay the debt with -- @param `repayAmount` The amount of debt you want to repay +- @param `user` The ethereum address that will liquidate the position +- @param `fromAsset` The ethereum address of the asset you want to repay with (collateral) +- @param `fromAToken` The ethereum address of the aToken of the asset you want to repay with (collateral) +- @param `assetToRepay` The ethereum address of the asset you want to repay +- @param `repayWithAmount` The amount of collateral you want to repay the debt with +- @param `repayAmount` The amount of debt you want to repay - @param `permitSignature` A permit signature of the tx. Optional -- @param @optional `repayAllDebt` Bool indicating if the user wants to repay all current debt. Defaults to false +- @param @optional `repayAllDebt` Bool indicating if the user wants to repay all current debt. Defaults to false - @param `rateMode` //Enum indicating the type of the interest rate of the collateral -- @param @optional `onBehalfOf` The ethereum address for which user is swaping. It will default to the user address -- @param @optional `referralCode` Integrators are assigned a referral code and can potentially receive rewards. It defaults to 0 (no referrer) -- @param @optional `flash` If the transaction will be executed through a flasloan(true) or will be done directly through the adapters(false). Defaults to false +- @param @optional `onBehalfOf` The ethereum address for which user is swaping. It will default to the user address +- @param @optional `referralCode` Integrators are assigned a referral code and can potentially receive rewards. It defaults to 0 (no referrer) +- @param @optional `flash` If the transaction will be executed through a flasloan(true) or will be done directly through the adapters(false). Defaults to false - @param @optional `useEthPath` Boolean to indicate if the swap will use an ETH path. Defaults to false */ const txs: EthereumTransactionTypeExtended[] = @@ -1335,7 +1330,7 @@ const pool = new Pool(provider, { }); /* -- @param `user` The ethereum address that will make the deposit +- @param `user` The ethereum address that will make the deposit - @param `categoryId` number representing the eMode to switch to, 0 = disable, 1 = stablecoins */ const txs: EthereumTransactionTypeExtended[] = await pool.setUserEMode({ @@ -1372,9 +1367,9 @@ const lendingPool = new LendingPool(provider, { }); /* -- @param `user` The ethereum address that will make the deposit -- @param `reserve` The ethereum address of the reserve -- @param `amount` The amount to be deposited +- @param `user` The ethereum address that will make the deposit +- @param `reserve` The ethereum address of the reserve +- @param `amount` The amount to be deposited - @param @optional `onBehalfOf` The ethereum address for which user is depositing. It will default to the user address */ const txs: EthereumTransactionTypeExtended[] = await lendingPool.deposit({ @@ -1411,12 +1406,12 @@ const lendingPool = new LendingPool(provider, { }); /* -- @param `user` The ethereum address that will receive the borrowed amount -- @param `reserve` The ethereum address of the reserve asset -- @param `amount` The amount to be borrowed, in human readable units (e.g. 2.5 ETH) +- @param `user` The ethereum address that will receive the borrowed amount +- @param `reserve` The ethereum address of the reserve asset +- @param `amount` The amount to be borrowed, in human readable units (e.g. 2.5 ETH) - @param `interestRateMode`//Whether the borrow will incur a stable (InterestRate.Stable) or variable (InterestRate.Variable) interest rate -- @param @optional `debtTokenAddress` The ethereum address of the debt token of the asset you want to borrow. Only needed if the reserve is ETH mock address -- @param @optional `onBehalfOf` The ethereum address for which user is borrowing. It will default to the user address +- @param @optional `debtTokenAddress` The ethereum address of the debt token of the asset you want to borrow. Only needed if the reserve is ETH mock address +- @param @optional `onBehalfOf` The ethereum address for which user is borrowing. It will default to the user address */ const txs: EthereumTransactionTypeExtended[] = await lendingPool.borrow({ user, @@ -1456,9 +1451,9 @@ const lendingPool = new LendingPool(provider, { }); /* -- @param `user` The ethereum address that repays -- @param `reserve` The ethereum address of the reserve on which the user borrowed -- @param `amount` The amount to repay, or (-1) if the user wants to repay everything +- @param `user` The ethereum address that repays +- @param `reserve` The ethereum address of the reserve on which the user borrowed +- @param `amount` The amount to repay, or (-1) if the user wants to repay everything - @param `interestRateMode` // Whether stable (InterestRate.Stable) or variable (InterestRate.Variable) debt will be repaid - @param @optional `onBehalfOf` The ethereum address for which user is repaying. It will default to the user address */ @@ -1493,10 +1488,10 @@ const lendingPool = new LendingPool(provider, { }); /* -- @param `user` The ethereum address that will receive the aTokens -- @param `reserve` The ethereum address of the reserve asset -- @param `amount` The amount of aToken being redeemed -- @param @optional `aTokenAddress` The ethereum address of the aToken. Only needed if the reserve is ETH mock address +- @param `user` The ethereum address that will receive the aTokens +- @param `reserve` The ethereum address of the reserve asset +- @param `amount` The amount of aToken being redeemed +- @param @optional `aTokenAddress` The ethereum address of the aToken. Only needed if the reserve is ETH mock address - @param @optional `onBehalfOf` The amount of aToken being redeemed. It will default to the user address */ const txs: EthereumTransactionTypeExtended[] = lendingPool.withdraw({ @@ -1530,8 +1525,8 @@ const lendingPool = new LendingPool(provider, { }); /* -- @param `user` The ethereum address that wants to swap rate modes -- @param `reserve` The address of the reserve on which the user borrowed +- @param `user` The ethereum address that wants to swap rate modes +- @param `reserve` The address of the reserve on which the user borrowed - @param `interestRateMode` //Whether the borrow will incur a stable (InterestRate.Stable) or variable (InterestRate.Variable) interest rate */ const txs: EthereumTransactionTypeExtended[] = lendingPool.swapBorrowRateMode({ @@ -1562,8 +1557,8 @@ const lendingPool = new LendingPool(provider, { }); /* -- @param `user` The ethereum address that enables or disables the deposit as collateral -- @param `reserve` The ethereum address of the reserve +- @param `user` The ethereum address that enables or disables the deposit as collateral +- @param `reserve` The ethereum address of the reserve - @param `useAsCollateral` Boolean, true if the user wants to use the deposit as collateral, false otherwise */ const txs: EthereumTransactionTypeExtended[] = lendingPool.setUsageAsCollateral( @@ -1599,11 +1594,11 @@ const lendingPool = new LendingPool(provider, { }); /* -- @param `liquidator` The ethereum address that will liquidate the position -- @param `liquidatedUser` The address of the borrower -- @param `debtReserve` The ethereum address of the principal reserve -- @param `collateralReserve` The address of the collateral to liquidated -- @param `purchaseAmount` The amount of principal that the liquidator wants to repay +- @param `liquidator` The ethereum address that will liquidate the position +- @param `liquidatedUser` The address of the borrower +- @param `debtReserve` The ethereum address of the principal reserve +- @param `collateralReserve` The address of the collateral to liquidated +- @param `purchaseAmount` The amount of principal that the liquidator wants to repay - @param @optional `getAToken` Boolean to indicate if the user wants to receive the aToken instead of the asset. Defaults to false */ const txs: EthereumTransactionTypeExtended[] = lendingPool.liquidationCall({ @@ -1643,18 +1638,18 @@ const lendingPool = new LendingPool(provider, { }); /* -- @param `user` The ethereum address that will liquidate the position -- @param @optional `flash` If the transaction will be executed through a flasloan(true) or will be done directly through the adapters(false). Defaults to false -- @param `fromAsset` The ethereum address of the asset you want to swap -- @param `fromAToken` The ethereum address of the aToken of the asset you want to swap -- @param `toAsset` The ethereum address of the asset you want to swap to (get) -- @param `fromAmount` The amount you want to swap -- @param `toAmount` The amount you want to get after the swap -- @param `maxSlippage` The max slippage that the user accepts in the swap -- @param @optional `permitSignature` A permit signature of the tx. Only needed when previously signed (Not needed at the moment). -- @param `swapAll` Bool indicating if the user wants to swap all the current collateral -- @param @optional `onBehalfOf` The ethereum address for which user is swaping. It will default to the user address -- @param @optional `referralCode` Integrators are assigned a referral code and can potentially receive rewards. It defaults to 0 (no referrer) +- @param `user` The ethereum address that will liquidate the position +- @param @optional `flash` If the transaction will be executed through a flasloan(true) or will be done directly through the adapters(false). Defaults to false +- @param `fromAsset` The ethereum address of the asset you want to swap +- @param `fromAToken` The ethereum address of the aToken of the asset you want to swap +- @param `toAsset` The ethereum address of the asset you want to swap to (get) +- @param `fromAmount` The amount you want to swap +- @param `toAmount` The amount you want to get after the swap +- @param `maxSlippage` The max slippage that the user accepts in the swap +- @param @optional `permitSignature` A permit signature of the tx. Only needed when previously signed (Not needed at the moment). +- @param `swapAll` Bool indicating if the user wants to swap all the current collateral +- @param @optional `onBehalfOf` The ethereum address for which user is swaping. It will default to the user address +- @param @optional `referralCode` Integrators are assigned a referral code and can potentially receive rewards. It defaults to 0 (no referrer) - @param @optional `useEthPath` Boolean to indicate if the swap will use an ETH path. Defaults to false */ const txs: EthereumTransactionTypeExtended[] = await lendingPool.swapCollateral( @@ -1703,18 +1698,18 @@ const lendingPool = new LendingPool(provider, { }); /* -- @param `user` The ethereum address that will liquidate the position -- @param `fromAsset` The ethereum address of the asset you want to repay with (collateral) -- @param `fromAToken` The ethereum address of the aToken of the asset you want to repay with (collateral) -- @param `assetToRepay` The ethereum address of the asset you want to repay -- @param `repayWithAmount` The amount of collateral you want to repay the debt with -- @param `repayAmount` The amount of debt you want to repay +- @param `user` The ethereum address that will liquidate the position +- @param `fromAsset` The ethereum address of the asset you want to repay with (collateral) +- @param `fromAToken` The ethereum address of the aToken of the asset you want to repay with (collateral) +- @param `assetToRepay` The ethereum address of the asset you want to repay +- @param `repayWithAmount` The amount of collateral you want to repay the debt with +- @param `repayAmount` The amount of debt you want to repay - @param `permitSignature` A permit signature of the tx. Optional -- @param @optional `repayAllDebt` Bool indicating if the user wants to repay all current debt. Defaults to false +- @param @optional `repayAllDebt` Bool indicating if the user wants to repay all current debt. Defaults to false - @param `rateMode` //Enum indicating the type of the interest rate of the collateral -- @param @optional `onBehalfOf` The ethereum address for which user is swaping. It will default to the user address -- @param @optional `referralCode` Integrators are assigned a referral code and can potentially receive rewards. It defaults to 0 (no referrer) -- @param @optional `flash` If the transaction will be executed through a flasloan(true) or will be done directly through the adapters(false). Defaults to false +- @param @optional `onBehalfOf` The ethereum address for which user is swaping. It will default to the user address +- @param @optional `referralCode` Integrators are assigned a referral code and can potentially receive rewards. It defaults to 0 (no referrer) +- @param @optional `flash` If the transaction will be executed through a flasloan(true) or will be done directly through the adapters(false). Defaults to false - @param @optional `useEthPath` Boolean to indicate if the swap will use an ETH path. Defaults to false */ const txs: EthereumTransactionTypeExtended[] = @@ -1907,8 +1902,8 @@ const governanceService = new AaveGovernanceService(rpcProvider, { }); /* -- @param `user` The ethereum address that will create the proposal -- @param `proposalId` Id of the proposal we want to vote +- @param `user` The ethereum address that will create the proposal +- @param `proposalId` Id of the proposal we want to vote - @param `support` Bool indicating if you are voting in favor (true) or against (false) */ const tx = governanceService.submitVote({ user, proposalId, support }); @@ -1934,8 +1929,8 @@ import { GovernancePowerDelegationTokenService } from '@aave/contract-helpers'; const powerDelegation = new GovernancePowerDelegationTokenService(rpcProvider); /* -- @param `user` The ethereum address that will create the proposal -- @param `delegatee` The ethereum address to which the user wants to delegate proposition power and voting power +- @param `user` The ethereum address that will create the proposal +- @param `delegatee` The ethereum address to which the user wants to delegate proposition power and voting power - @param `governanceToken` The ethereum address of the governance token */ const tx = powerDelegation.delegate({ user, delegatee, governanceToken }); @@ -1961,9 +1956,9 @@ import { GovernancePowerDelegationTokenService } from '@aave/contract-helpers'; const powerDelegation = new GovernancePowerDelegationTokenService(rpcProvider); /* -- @param `user` The ethereum address that will create the proposal -- @param `delegatee` The ethereum address to which the user wants to delegate proposition power and voting power -- @param `delegationType` The type of the delegation the user wants to do: voting power ('0') or proposition power ('1') +- @param `user` The ethereum address that will create the proposal +- @param `delegatee` The ethereum address to which the user wants to delegate proposition power and voting power +- @param `delegationType` The type of the delegation the user wants to do: voting power ('0') or proposition power ('1') - @param `governanceToken` The ethereum address of the governance token */ const tx = powerDelegation.delegateByType({ @@ -1998,8 +1993,8 @@ import { FaucetService } from '@aave/contract-helpers'; const faucetService = new FaucetService(provider, faucetAddress); /* -- @param `userAddress` The ethereum address of the wallet the minted tokens will go -- @param `reserve` The ethereum address of the token you want to mint +- @param `userAddress` The ethereum address of the wallet the minted tokens will go +- @param `reserve` The ethereum address of the token you want to mint - @param `tokenSymbol` The symbol of the token you want to mint */ const tx = faucet.mint({ userAddress, reserve, tokenSymbol }); @@ -2009,7 +2004,6 @@ Submit transaction as shown [here](#submitting-transactions)
-
## Credit Delegation @@ -2020,7 +2014,6 @@ Accessing delegated credit is done by passing the delegator address as the `onBe ### approveDelegation -
Sample Code @@ -2048,4 +2041,4 @@ const approveDelegation = delegationServicePolygonV2USDC.approveDelegation({ Submit transaction as shown [here](#submitting-transactions) -
\ No newline at end of file +
diff --git a/jest.config.js b/jest.config.js index 9f2549f3..10af533b 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,6 +1,6 @@ module.exports = { preset: 'ts-jest', - collectCoverageFrom: ['packages/*/src/**/*.ts'], + collectCoverageFrom: ['packages/*/src/**(!typechain)/*.ts'], coverageDirectory: 'coverage', coverageReporters: ['lcov', 'text'], coverageThreshold: { @@ -43,7 +43,6 @@ module.exports = { 'packages/math-utils/src/formatters/reserve/index.ts', // TODO: remove ], modulePathIgnorePatterns: ['node_modules'], - preset: 'ts-jest', testEnvironment: 'node', verbose: true, watchPlugins: [ diff --git a/packages/contract-helpers/src/commons/BaseService.test.ts b/packages/contract-helpers/src/commons/BaseService.test.ts index 6eb0c61f..a04a5ecb 100644 --- a/packages/contract-helpers/src/commons/BaseService.test.ts +++ b/packages/contract-helpers/src/commons/BaseService.test.ts @@ -197,7 +197,7 @@ describe('BaseService', () => { expect(gas?.gasLimit).toEqual('1'); expect(gas?.gasPrice).toEqual('2'); }); - xit('Expects null when no gas limit', async () => { + it.skip('Expects null when no gas limit', async () => { const txCallback = async () => ({}); const txs = [ { diff --git a/packages/contract-helpers/src/gho/GhoDiscountRateStrategyService.test.ts b/packages/contract-helpers/src/gho/GhoDiscountRateStrategyService.test.ts new file mode 100644 index 00000000..159cbeb0 --- /dev/null +++ b/packages/contract-helpers/src/gho/GhoDiscountRateStrategyService.test.ts @@ -0,0 +1,181 @@ +import { constants, BigNumber, BigNumberish, providers } from 'ethers'; +import { valueToWei } from '../commons/utils'; +import { GhoDiscountRateStrategyService } from './GhoDiscountRateStrategyService'; +import { GhoDiscountRateStrategy } from './typechain/GhoDiscountRateStrategy'; +import { GhoDiscountRateStrategy__factory } from './typechain/GhoDiscountRateStrategy__factory'; + +jest.mock('../commons/gasStation', () => { + return { + __esModule: true, + estimateGasByNetwork: jest + .fn() + .mockImplementation(async () => Promise.resolve(BigNumber.from(1))), + estimateGas: jest.fn(async () => Promise.resolve(BigNumber.from(1))), + }; +}); + +// Helper for contract call arguments +const convertToBN = (n: string) => valueToWei(n, 18); + +describe('GhoDiscountRateStrategyService', () => { + const DISCOUNT_RATE_STRATEGY_ADDRESS = constants.AddressZero; + const correctProvider: providers.Provider = new providers.JsonRpcProvider(); + + // Mocking + jest + .spyOn(correctProvider, 'getGasPrice') + .mockImplementation(async () => Promise.resolve(BigNumber.from(1))); + + afterEach(() => jest.clearAllMocks()); + + describe('Create new GhoDiscountRateStrategyService', () => { + it('Expects to be initialized correctly', () => { + const instance = new GhoDiscountRateStrategyService( + correctProvider, + DISCOUNT_RATE_STRATEGY_ADDRESS, + ); + expect(instance).toBeInstanceOf(GhoDiscountRateStrategyService); + }); + }); + + describe('calculateDiscountRate', () => { + it('should return zero discount if discount token balance does not meet minimum requirements to gain a discount', async () => { + // Create instance + const contract = new GhoDiscountRateStrategyService( + correctProvider, + DISCOUNT_RATE_STRATEGY_ADDRESS, + ); + + // Use case - borrowing 100 GHO owning 0 skAAVE + const ghoDebtTokenBalance: BigNumberish = convertToBN('100'); + const stakedAaveBalance: BigNumberish = convertToBN('0'); + const expected = BigNumber.from('0'); // 0% + + // Mock it + const spy = jest + .spyOn(GhoDiscountRateStrategy__factory, 'connect') + .mockReturnValue({ + calculateDiscountRate: async () => Promise.resolve(expected), + } as unknown as GhoDiscountRateStrategy); + + // Call it + const result = await contract.calculateDiscountRate( + ghoDebtTokenBalance, + stakedAaveBalance, + ); + + // Assert it + expect(spy).toHaveBeenCalled(); + expect(spy).toBeCalledTimes(1); + expect(result).toEqual(expected); + }); + + it('should return zero discount if GHO variable debt token balance does not meet minimum requirements to gain a discount', async () => { + // Create instance + const contract = new GhoDiscountRateStrategyService( + correctProvider, + DISCOUNT_RATE_STRATEGY_ADDRESS, + ); + + // Use case - borrowing 0 GHO owning 1 skAAVE + const ghoDebtTokenBalance: BigNumberish = convertToBN('0'); + const stakedAaveBalance: BigNumberish = convertToBN('1'); + const expected = BigNumber.from('0'); // 0% + + // Mock it + const spy = jest + .spyOn(GhoDiscountRateStrategy__factory, 'connect') + .mockReturnValue({ + calculateDiscountRate: async () => Promise.resolve(expected), + } as unknown as GhoDiscountRateStrategy); + + // Call it + const result = await contract.calculateDiscountRate( + ghoDebtTokenBalance, + stakedAaveBalance, + ); + + // Assert it + expect(spy).toHaveBeenCalled(); + expect(spy).toBeCalledTimes(1); + expect(result).toEqual(expected); + }); + + // Discounted balance = discount token * 100 + it('should return the maximum discount rate of 20% if the calculated total discounted balance is greater or equal to the debt token balance', async () => { + // Create instance + const contract = new GhoDiscountRateStrategyService( + correctProvider, + DISCOUNT_RATE_STRATEGY_ADDRESS, + ); + + // Use case #1 - borrowing 100 GHO owning 1 stkAAVE + const ghoDebtTokenBalance: BigNumberish = convertToBN('100'); + let stakedAaveBalance: BigNumberish = convertToBN('1'); + const expected = BigNumber.from('2000'); // 20.00% discount + + // Mock it + const spy = jest + .spyOn(GhoDiscountRateStrategy__factory, 'connect') + .mockReturnValue({ + calculateDiscountRate: async () => Promise.resolve(expected), + } as unknown as GhoDiscountRateStrategy); + + // Call it + let result = await contract.calculateDiscountRate( + ghoDebtTokenBalance, + stakedAaveBalance, + ); + + // Assert it + expect(spy).toHaveBeenCalled(); + expect(spy).toBeCalledTimes(1); + expect(result).toEqual(expected); + + // Use case #2 - borrowing 100 GHO owning 5 stkAAVE + stakedAaveBalance = convertToBN('5'); + + // Call it + result = await contract.calculateDiscountRate( + ghoDebtTokenBalance, + stakedAaveBalance, + ); + + // Assert it + expect(spy).toHaveBeenCalled(); + expect(spy).toBeCalledTimes(1); + expect(result).toEqual(expected); + }); + + it('should return a sub-maximum discount if user borrows more GHO than can be discounted based off of the discount token balance', async () => { + // Create instance + const contract = new GhoDiscountRateStrategyService( + correctProvider, + DISCOUNT_RATE_STRATEGY_ADDRESS, + ); + + // Use case - borrowing 150 GHO owning 1 skAAVE + const ghoDebtTokenBalance: BigNumberish = convertToBN('150'); + const stakedAaveBalance: BigNumberish = convertToBN('1'); + const expected = BigNumber.from('1333'); // 13.33% discount + + // Mock it + const spy = jest + .spyOn(GhoDiscountRateStrategy__factory, 'connect') + .mockReturnValue({ + calculateDiscountRate: async () => Promise.resolve(expected), + } as unknown as GhoDiscountRateStrategy); + + // Call it + const result = await contract.calculateDiscountRate( + ghoDebtTokenBalance, + stakedAaveBalance, + ); + + // Assert it + expect(spy).toHaveBeenCalled(); + expect(spy).toBeCalledTimes(1); + expect(result).toEqual(expected); + }); + }); +}); diff --git a/packages/contract-helpers/src/gho/GhoDiscountRateStrategyService.ts b/packages/contract-helpers/src/gho/GhoDiscountRateStrategyService.ts new file mode 100644 index 00000000..b4113ef7 --- /dev/null +++ b/packages/contract-helpers/src/gho/GhoDiscountRateStrategyService.ts @@ -0,0 +1,51 @@ +import { BigNumber, BigNumberish, providers } from 'ethers'; +import BaseService from '../commons/BaseService'; +import { GhoDiscountRateStrategy__factory } from './typechain/GhoDiscountRateStrategy__factory'; +import type { IGhoDiscountRateStrategy } from './typechain/IGhoDiscountRateStrategy'; + +export interface GhoDiscountRateServiceInterface { + calculateDiscountRate: ( + ghoDebtTokenBalance: BigNumberish, + skAaveBalance: BigNumberish, + ) => Promise; +} + +/** + * The service for interacting with the GhoDiscountRateStrategy.sol smart contract + * https://github.com/aave/gho/blob/main/src/contracts/facilitators/aave/interestStrategy/GhoDiscountRateStrategy.sol + */ +export class GhoDiscountRateStrategyService + extends BaseService + implements GhoDiscountRateServiceInterface +{ + readonly ghoDiscountRateStrategyAddress: string; + + constructor( + provider: providers.Provider, + discountRateStrategyAddress: string, + ) { + super(provider, GhoDiscountRateStrategy__factory); + this.ghoDiscountRateStrategyAddress = discountRateStrategyAddress; + } + + /** + * Calculates the discounted interest rate charged on the borrowed native GHO token from the Aave Protocol. Currently this is set to be 20% on 100 GHO borrowed per stkAAVE held. Additionally, a user's discount rate is + * updated anytime they send or receive the discount token (stkAAVE). Users are entitled to this discount for a given amount of time without needing to perform any additional actions (i.e. the discount lock period). + * @param ghoDebtTokenBalance - The balance for the user's GhoVariableDebtToken, i.e. the amount they currently have borrowed from the protocol + * @param stakedAaveBalance - The balance of the user's stkAAVE token balance + * @returns - The discounted interest rate charged on the borrowed native GHO token. + */ + public async calculateDiscountRate( + ghoDebtTokenBalance: BigNumberish, + stakedAaveBalance: BigNumberish, + ) { + const contract = this.getContractInstance( + this.ghoDiscountRateStrategyAddress, + ); + const result = await contract.calculateDiscountRate( + ghoDebtTokenBalance, + stakedAaveBalance, + ); + return result; + } +} diff --git a/packages/contract-helpers/src/gho/index.test.ts b/packages/contract-helpers/src/gho/index.test.ts new file mode 100644 index 00000000..aebd28ae --- /dev/null +++ b/packages/contract-helpers/src/gho/index.test.ts @@ -0,0 +1,7 @@ +import { GhoDiscountRateStrategyService } from './index'; + +describe('gho contract helpers', () => { + it('exports out the GhoDiscountRateStrategyService', () => { + expect(GhoDiscountRateStrategyService).toBeTruthy(); + }); +}); diff --git a/packages/contract-helpers/src/gho/index.ts b/packages/contract-helpers/src/gho/index.ts new file mode 100644 index 00000000..83d25738 --- /dev/null +++ b/packages/contract-helpers/src/gho/index.ts @@ -0,0 +1,3 @@ +import { GhoDiscountRateStrategyService } from './GhoDiscountRateStrategyService'; + +export { GhoDiscountRateStrategyService }; diff --git a/packages/contract-helpers/src/gho/typechain/GhoDiscountRateStrategy.d.ts b/packages/contract-helpers/src/gho/typechain/GhoDiscountRateStrategy.d.ts new file mode 100644 index 00000000..2c31e633 --- /dev/null +++ b/packages/contract-helpers/src/gho/typechain/GhoDiscountRateStrategy.d.ts @@ -0,0 +1,224 @@ +/* Autogenerated file. Do not edit manually. */ +/* eslint-disable */ +import type { + BaseContract, + BigNumber, + BigNumberish, + BytesLike, + CallOverrides, + PopulatedTransaction, + Signer, + utils, +} from 'ethers'; +import type { FunctionFragment, Result } from '@ethersproject/abi'; +import type { Listener, Provider } from '@ethersproject/providers'; +import type { + TypedEventFilter, + TypedEvent, + TypedListener, + OnEvent, +} from '../../../../../common'; + +export interface GhoDiscountRateStrategyInterface extends utils.Interface { + functions: { + 'DISCOUNT_RATE()': FunctionFragment; + 'DISCOUNT_TOKEN()': FunctionFragment; + 'GHO_DISCOUNTED_PER_DISCOUNT_TOKEN()': FunctionFragment; + 'MIN_DEBT_TOKEN_BALANCE()': FunctionFragment; + 'MIN_DISCOUNT_TOKEN_BALANCE()': FunctionFragment; + 'calculateDiscountRate(uint256,uint256)': FunctionFragment; + }; + + getFunction( + nameOrSignatureOrTopic: + | 'DISCOUNT_RATE' + | 'DISCOUNT_TOKEN' + | 'GHO_DISCOUNTED_PER_DISCOUNT_TOKEN' + | 'MIN_DEBT_TOKEN_BALANCE' + | 'MIN_DISCOUNT_TOKEN_BALANCE' + | 'calculateDiscountRate', + ): FunctionFragment; + + encodeFunctionData( + functionFragment: 'DISCOUNT_RATE', + values?: undefined, + ): string; + encodeFunctionData( + functionFragment: 'DISCOUNT_TOKEN', + values?: undefined, + ): string; + encodeFunctionData( + functionFragment: 'GHO_DISCOUNTED_PER_DISCOUNT_TOKEN', + values?: undefined, + ): string; + encodeFunctionData( + functionFragment: 'MIN_DEBT_TOKEN_BALANCE', + values?: undefined, + ): string; + encodeFunctionData( + functionFragment: 'MIN_DISCOUNT_TOKEN_BALANCE', + values?: undefined, + ): string; + encodeFunctionData( + functionFragment: 'calculateDiscountRate', + values: [BigNumberish, BigNumberish], + ): string; + + decodeFunctionResult( + functionFragment: 'DISCOUNT_RATE', + data: BytesLike, + ): Result; + decodeFunctionResult( + functionFragment: 'DISCOUNT_TOKEN', + data: BytesLike, + ): Result; + decodeFunctionResult( + functionFragment: 'GHO_DISCOUNTED_PER_DISCOUNT_TOKEN', + data: BytesLike, + ): Result; + decodeFunctionResult( + functionFragment: 'MIN_DEBT_TOKEN_BALANCE', + data: BytesLike, + ): Result; + decodeFunctionResult( + functionFragment: 'MIN_DISCOUNT_TOKEN_BALANCE', + data: BytesLike, + ): Result; + decodeFunctionResult( + functionFragment: 'calculateDiscountRate', + data: BytesLike, + ): Result; + + events: {}; +} + +export interface GhoDiscountRateStrategy extends BaseContract { + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + interface: GhoDiscountRateStrategyInterface; + + queryFilter( + event: TypedEventFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined, + ): Promise>; + + listeners( + eventFilter?: TypedEventFilter, + ): Array>; + listeners(eventName?: string): Array; + removeAllListeners( + eventFilter: TypedEventFilter, + ): this; + removeAllListeners(eventName?: string): this; + off: OnEvent; + on: OnEvent; + once: OnEvent; + removeListener: OnEvent; + + functions: { + DISCOUNT_RATE(overrides?: CallOverrides): Promise<[BigNumber]>; + + DISCOUNT_TOKEN(overrides?: CallOverrides): Promise<[string]>; + + GHO_DISCOUNTED_PER_DISCOUNT_TOKEN( + overrides?: CallOverrides, + ): Promise<[BigNumber]>; + + MIN_DEBT_TOKEN_BALANCE(overrides?: CallOverrides): Promise<[BigNumber]>; + + MIN_DISCOUNT_TOKEN_BALANCE(overrides?: CallOverrides): Promise<[BigNumber]>; + + calculateDiscountRate( + debtBalance: BigNumberish, + discountTokenBalance: BigNumberish, + overrides?: CallOverrides, + ): Promise<[BigNumber]>; + }; + + DISCOUNT_RATE(overrides?: CallOverrides): Promise; + + DISCOUNT_TOKEN(overrides?: CallOverrides): Promise; + + GHO_DISCOUNTED_PER_DISCOUNT_TOKEN( + overrides?: CallOverrides, + ): Promise; + + MIN_DEBT_TOKEN_BALANCE(overrides?: CallOverrides): Promise; + + MIN_DISCOUNT_TOKEN_BALANCE(overrides?: CallOverrides): Promise; + + calculateDiscountRate( + debtBalance: BigNumberish, + discountTokenBalance: BigNumberish, + overrides?: CallOverrides, + ): Promise; + + callStatic: { + DISCOUNT_RATE(overrides?: CallOverrides): Promise; + + DISCOUNT_TOKEN(overrides?: CallOverrides): Promise; + + GHO_DISCOUNTED_PER_DISCOUNT_TOKEN( + overrides?: CallOverrides, + ): Promise; + + MIN_DEBT_TOKEN_BALANCE(overrides?: CallOverrides): Promise; + + MIN_DISCOUNT_TOKEN_BALANCE(overrides?: CallOverrides): Promise; + + calculateDiscountRate( + debtBalance: BigNumberish, + discountTokenBalance: BigNumberish, + overrides?: CallOverrides, + ): Promise; + }; + + filters: {}; + + estimateGas: { + DISCOUNT_RATE(overrides?: CallOverrides): Promise; + + DISCOUNT_TOKEN(overrides?: CallOverrides): Promise; + + GHO_DISCOUNTED_PER_DISCOUNT_TOKEN( + overrides?: CallOverrides, + ): Promise; + + MIN_DEBT_TOKEN_BALANCE(overrides?: CallOverrides): Promise; + + MIN_DISCOUNT_TOKEN_BALANCE(overrides?: CallOverrides): Promise; + + calculateDiscountRate( + debtBalance: BigNumberish, + discountTokenBalance: BigNumberish, + overrides?: CallOverrides, + ): Promise; + }; + + populateTransaction: { + DISCOUNT_RATE(overrides?: CallOverrides): Promise; + + DISCOUNT_TOKEN(overrides?: CallOverrides): Promise; + + GHO_DISCOUNTED_PER_DISCOUNT_TOKEN( + overrides?: CallOverrides, + ): Promise; + + MIN_DEBT_TOKEN_BALANCE( + overrides?: CallOverrides, + ): Promise; + + MIN_DISCOUNT_TOKEN_BALANCE( + overrides?: CallOverrides, + ): Promise; + + calculateDiscountRate( + debtBalance: BigNumberish, + discountTokenBalance: BigNumberish, + overrides?: CallOverrides, + ): Promise; + }; +} diff --git a/packages/contract-helpers/src/gho/typechain/GhoDiscountRateStrategy__factory.ts b/packages/contract-helpers/src/gho/typechain/GhoDiscountRateStrategy__factory.ts new file mode 100644 index 00000000..d3f358ad --- /dev/null +++ b/packages/contract-helpers/src/gho/typechain/GhoDiscountRateStrategy__factory.ts @@ -0,0 +1,155 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import { Signer, utils, Contract, ContractFactory, Overrides } from "ethers"; +import type { Provider, TransactionRequest } from "@ethersproject/providers"; +import type { + GhoDiscountRateStrategy, + GhoDiscountRateStrategyInterface, +} from "./GhoDiscountRateStrategy"; + +const _abi = [ + { + inputs: [], + name: "DISCOUNT_RATE", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "DISCOUNT_TOKEN", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "GHO_DISCOUNTED_PER_DISCOUNT_TOKEN", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "MIN_DEBT_TOKEN_BALANCE", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "MIN_DISCOUNT_TOKEN_BALANCE", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "debtBalance", + type: "uint256", + }, + { + internalType: "uint256", + name: "discountTokenBalance", + type: "uint256", + }, + ], + name: "calculateDiscountRate", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "pure", + type: "function", + }, +]; + +const _bytecode = + "0x608060405234801561001057600080fd5b506102c1806100206000396000f3fe608060405234801561001057600080fd5b50600436106100725760003560e01c806393adbec51161005057806393adbec5146100e957806398c4f438146100bc578063b510c589146100fc57600080fd5b80631fd5c9e9146100775780633454274e146100bc578063771a73af146100d9575b600080fd5b610092734da27a545c0c5b758a6ba100e3a049001de870f581565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020015b60405180910390f35b6100cb670de0b6b3a764000081565b6040519081526020016100b3565b6100cb68056bc75e2d6310000081565b6100cb6100f73660046101ca565b610105565b6100cb6107d081565b6000670de0b6b3a76400008210806101245750670de0b6b3a764000083105b1561013157506000610175565b60006101468368056bc75e2d6310000061017b565b905083811061015a576107d0915050610175565b836101676107d0836101ec565b6101719190610250565b9150505b92915050565b600081157ffffffffffffffffffffffffffffffffffffffffffffffffff90fa4a62c4dffff839004841115176101b057600080fd5b50670de0b6b3a764000091026706f05b59d3b20000010490565b600080604083850312156101dd57600080fd5b50508035926020909101359150565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561024b577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b500290565b600082610286577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b50049056fea26469706673582212206bbf29bf6be38a8be7683b6b85fad0e89ba775122d079836285e8ed847f2d92564736f6c634300080a0033"; + +type GhoDiscountRateStrategyConstructorParams = + | [signer?: Signer] + | ConstructorParameters; + +const isSuperArgs = ( + xs: GhoDiscountRateStrategyConstructorParams +): xs is ConstructorParameters => xs.length > 1; + +export class GhoDiscountRateStrategy__factory extends ContractFactory { + constructor(...args: GhoDiscountRateStrategyConstructorParams) { + if (isSuperArgs(args)) { + super(...args); + } else { + super(_abi, _bytecode, args[0]); + } + } + + override deploy( + overrides?: Overrides & { from?: string | Promise } + ): Promise { + return super.deploy(overrides || {}) as Promise; + } + override getDeployTransaction( + overrides?: Overrides & { from?: string | Promise } + ): TransactionRequest { + return super.getDeployTransaction(overrides || {}); + } + override attach(address: string): GhoDiscountRateStrategy { + return super.attach(address) as GhoDiscountRateStrategy; + } + override connect(signer: Signer): GhoDiscountRateStrategy__factory { + return super.connect(signer) as GhoDiscountRateStrategy__factory; + } + + static readonly bytecode = _bytecode; + static readonly abi = _abi; + static createInterface(): GhoDiscountRateStrategyInterface { + return new utils.Interface(_abi) as GhoDiscountRateStrategyInterface; + } + static connect( + address: string, + signerOrProvider: Signer | Provider + ): GhoDiscountRateStrategy { + return new Contract( + address, + _abi, + signerOrProvider + ) as GhoDiscountRateStrategy; + } +} diff --git a/packages/contract-helpers/src/gho/typechain/IGhoDiscountRateStrategy.d.ts b/packages/contract-helpers/src/gho/typechain/IGhoDiscountRateStrategy.d.ts new file mode 100644 index 00000000..9065ff97 --- /dev/null +++ b/packages/contract-helpers/src/gho/typechain/IGhoDiscountRateStrategy.d.ts @@ -0,0 +1,109 @@ +/* Autogenerated file. Do not edit manually. */ +/* eslint-disable */ +import type { + BaseContract, + BigNumber, + BigNumberish, + BytesLike, + CallOverrides, + PopulatedTransaction, + Signer, + utils, +} from 'ethers'; +import type { FunctionFragment, Result } from '@ethersproject/abi'; +import type { Listener, Provider } from '@ethersproject/providers'; +import type { + TypedEventFilter, + TypedEvent, + TypedListener, + OnEvent, +} from '../../../../../../common'; + +export interface IGhoDiscountRateStrategyInterface extends utils.Interface { + functions: { + 'calculateDiscountRate(uint256,uint256)': FunctionFragment; + }; + + getFunction( + nameOrSignatureOrTopic: 'calculateDiscountRate', + ): FunctionFragment; + + encodeFunctionData( + functionFragment: 'calculateDiscountRate', + values: [BigNumberish, BigNumberish], + ): string; + + decodeFunctionResult( + functionFragment: 'calculateDiscountRate', + data: BytesLike, + ): Result; + + events: {}; +} + +export interface IGhoDiscountRateStrategy extends BaseContract { + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + interface: IGhoDiscountRateStrategyInterface; + + queryFilter( + event: TypedEventFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined, + ): Promise>; + + listeners( + eventFilter?: TypedEventFilter, + ): Array>; + listeners(eventName?: string): Array; + removeAllListeners( + eventFilter: TypedEventFilter, + ): this; + removeAllListeners(eventName?: string): this; + off: OnEvent; + on: OnEvent; + once: OnEvent; + removeListener: OnEvent; + + functions: { + calculateDiscountRate( + debtBalance: BigNumberish, + discountTokenBalance: BigNumberish, + overrides?: CallOverrides, + ): Promise<[BigNumber]>; + }; + + calculateDiscountRate( + debtBalance: BigNumberish, + discountTokenBalance: BigNumberish, + overrides?: CallOverrides, + ): Promise; + + callStatic: { + calculateDiscountRate( + debtBalance: BigNumberish, + discountTokenBalance: BigNumberish, + overrides?: CallOverrides, + ): Promise; + }; + + filters: {}; + + estimateGas: { + calculateDiscountRate( + debtBalance: BigNumberish, + discountTokenBalance: BigNumberish, + overrides?: CallOverrides, + ): Promise; + }; + + populateTransaction: { + calculateDiscountRate( + debtBalance: BigNumberish, + discountTokenBalance: BigNumberish, + overrides?: CallOverrides, + ): Promise; + }; +} diff --git a/packages/contract-helpers/src/index.ts b/packages/contract-helpers/src/index.ts index a322e538..260306b7 100644 --- a/packages/contract-helpers/src/index.ts +++ b/packages/contract-helpers/src/index.ts @@ -24,6 +24,7 @@ export * from './synthetix-contract'; export * from './baseDebtToken-contract'; export * from './v3-migration-contract'; export * from './erc20-2612'; +export * from './gho'; // commons export * from './commons/types';