Skip to content

Commit

Permalink
Merge branch 'main' into feat/sdk-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaquinBattilana committed Jan 6, 2025
2 parents 664c462 + ee4de8e commit 79f8c23
Show file tree
Hide file tree
Showing 8 changed files with 576 additions and 483 deletions.
Original file line number Diff line number Diff line change
@@ -1,43 +1,37 @@
import dotenv from "dotenv";
import { Account, Ed25519PrivateKey } from "@aptos-labs/ts-sdk";
import { OracleClient, PoolClient } from "../../src/clients";
import { priceFeeds } from "../../src/helpers/priceFeeds";
import { AptosProvider } from "../../src/clients/aptosProvider";
import { DEFAULT_TESTNET_CONFIG } from "../../src/configs/testnet";

dotenv.config();

const priceMapper = {
DAI: 100000000,
USDC: 100000000,
WETH: 300000000000,
AAVE: 10000000000,
};

(async () => {
// global aptos provider
const aptosProvider = AptosProvider.fromConfig(DEFAULT_TESTNET_CONFIG);

if (!process.env.AAVE_MOCK_ORACLE_PRIVATE_KEY) {
throw new Error(`AAVE_MOCK_ORACLE_PRIVATE_KEY env was not found`);
if (!process.env.AAVE_ORACLE_PRIVATE_KEY) {
throw new Error(`AAVE_ORACLE_PRIVATE_KEY env was not found`);
}

const oracleManageAccount = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey(process.env.AAVE_MOCK_ORACLE_PRIVATE_KEY),
privateKey: new Ed25519PrivateKey(process.env.AAVE_ORACLE_PRIVATE_KEY),
});

const oracleClient = new OracleClient(aptosProvider, oracleManageAccount);
const poolClient = new PoolClient(aptosProvider);

const assets = await poolClient.getAllReservesTokens();
for (const asset of assets) {
const price = priceMapper[asset.symbol];
if (price) {
const txReceipt = await oracleClient.setAssetPrice(
const priceFeedId = priceFeeds.get(asset.symbol);
if (priceFeedId) {
const txReceipt = await oracleClient.setAssetFeedId(
asset.tokenAddress,
BigInt(price),
priceFeedId,
);
console.log(
`Asset ${asset.symbol} price set to ${price} with tx hash ${txReceipt.hash}`,
`Asset ${asset.symbol} price set to ${priceFeedId} with tx hash ${txReceipt.hash}`,
);
}
}
Expand Down
68 changes: 24 additions & 44 deletions examples/admin/setupTestnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ const reserves: ReserveConfig[] = [
projectUri: "https://app.aave.com/",
treasury: AccountAddress.ZERO,
aTokenName: "Aave USDC",
aTokenSymbol: "aUSDC",
aTokenSymbol: "AUSDC",
variableDebtTokenName: "Aave Variable Debt USDC",
variableDebtTokenSymbol: "vUSDC",
variableDebtTokenSymbol: "VUSDC",
optimalUsageRatio: 920000000000000000000000000n,
baseVariableBorrowRate: 0n,
variableRateSlope1: 65000000000000000000000000n,
Expand All @@ -93,9 +93,9 @@ const reserves: ReserveConfig[] = [
projectUri: "https://app.aave.com/",
treasury: AccountAddress.ZERO,
aTokenName: "Aave USDT",
aTokenSymbol: "aUSDT",
aTokenSymbol: "AUSDT",
variableDebtTokenName: "Aave Variable Debt USDT",
variableDebtTokenSymbol: "vUSDT",
variableDebtTokenSymbol: "VUSDT",
optimalUsageRatio: 920000000000000000000000000n,
baseVariableBorrowRate: 0n,
variableRateSlope1: 65000000000000000000000000n,
Expand Down Expand Up @@ -176,7 +176,6 @@ const poolSigner = Account.fromPrivateKey({
}

// configure eModes

for (const eMode of eModes) {
await poolClient.setEmodeCategory(
eMode.categoryId,
Expand All @@ -189,7 +188,6 @@ const poolSigner = Account.fromPrivateKey({
}

// create rate strategies

for (const reserve of reservesWithAsset) {
await poolClient.setReserveInterestRateStrategy(
reserve.underlyingAsset,
Expand All @@ -201,7 +199,6 @@ const poolSigner = Account.fromPrivateKey({
}

// init reserves that dont exist

const reservesToInit = {
assets: [] as Array<AccountAddress>,
decimals: [] as Array<number>,
Expand Down Expand Up @@ -231,7 +228,6 @@ const poolSigner = Account.fromPrivateKey({
if (reservesToInit.assets.length > 0) {
await poolClient.initReserves(
reservesToInit.assets,
reservesToInit.decimals,
reservesToInit.treasury,
reservesToInit.aTokenName,
reservesToInit.aTokenSymbol,
Expand All @@ -240,43 +236,27 @@ const poolSigner = Account.fromPrivateKey({
);
}

const reservesToConfigure = {
asset: [] as Array<AccountAddress>,
ltv: [] as Array<bigint>,
liquidationThreshold: [] as Array<bigint>,
liquidationBonus: [] as Array<bigint>,
reserveFactor: [] as Array<bigint>,
borrowCap: [] as Array<bigint>,
supplyCap: [] as Array<bigint>,
borrowingEnabled: [] as Array<boolean>,
flashloanEnabled: [] as Array<boolean>,
};

for (const reserve of reservesWithAsset) {
reservesToConfigure.asset.push(reserve.underlyingAsset);
reservesToConfigure.ltv.push(reserve.ltv);
reservesToConfigure.liquidationThreshold.push(reserve.liquidationThreshold);
reservesToConfigure.liquidationBonus.push(reserve.liquidationBonus);
reservesToConfigure.reserveFactor.push(reserve.reserveFactor);
reservesToConfigure.borrowCap.push(reserve.borrowCap);
reservesToConfigure.supplyCap.push(reserve.supplyCap);
reservesToConfigure.borrowingEnabled.push(reserve.borrowingEnabled);
reservesToConfigure.flashloanEnabled.push(reserve.flashloanEnabled);
}

await poolClient.configureReserves(
reservesToConfigure.asset,
reservesToConfigure.ltv,
reservesToConfigure.liquidationThreshold,
reservesToConfigure.liquidationBonus,
reservesToConfigure.reserveFactor,
reservesToConfigure.borrowCap,
reservesToConfigure.supplyCap,
reservesToConfigure.borrowingEnabled,
reservesToConfigure.flashloanEnabled,
);

for (const reserve of reservesWithAsset) {
await poolClient.configureReserveAsCollateral(
reserve.underlyingAsset,
reserve.ltv,
reserve.liquidationThreshold,
reserve.liquidationBonus,
);
await poolClient.setReserveFactor(
reserve.underlyingAsset,
reserve.reserveFactor,
);
await poolClient.setBorrowCap(reserve.underlyingAsset, reserve.borrowCap);
await poolClient.setSupplyCap(reserve.underlyingAsset, reserve.supplyCap);
await poolClient.setReserveBorrowing(
reserve.underlyingAsset,
reserve.borrowingEnabled,
);
await poolClient.setReserveFlashLoaning(
reserve.underlyingAsset,
reserve.flashloanEnabled,
);
await poolClient.setAssetEmodeCategory(
reserve.underlyingAsset,
reserve.eModeCategoryId,
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aave/aave-v3-aptos-ts-sdk",
"version": "0.0.27",
"version": "0.0.28",
"description": "Aave's typescript sdk for Aptos",
"main": "dist/cmd/index.js",
"module": "dist/esm/index.js",
Expand Down Expand Up @@ -74,21 +74,21 @@
"buffer": "^6.0.3",
"crypto-js": "^4.2.0",
"dotenv": "^16.4.7",
"ethers": "^6.13.4",
"ethers": "^6.13.5",
"events": "^3.3.0",
"jest-environment-jsdom": "^29.7.0",
"tslib": "^2.8.1",
"tsx": "^4.19.2",
"util": "^0.12.5",
"yaml": "^2.6.1"
"yaml": "^2.7.0"
},
"devDependencies": {
"@types/bn.js": "^5.1.6",
"@types/jest": "^29.5.14",
"@types/node": "^22.10.2",
"@typescript-eslint/eslint-plugin": "^8.18.1",
"@typescript-eslint/parser": "^8.18.1",
"chalk": "^5.4.0",
"@types/node": "^22.10.5",
"@typescript-eslint/eslint-plugin": "^8.19.0",
"@typescript-eslint/parser": "^8.19.0",
"chalk": "^5.4.1",
"eslint": "^9.17.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^18.0.0",
Expand All @@ -111,14 +111,14 @@
"rimraf": "^6.0.1",
"ts-jest": "^29.2.5",
"ts-loader": "^9.5.1",
"typedoc": "^0.27.5",
"typedoc": "^0.27.6",
"typescript": "^5.7.2",
"typescript-eslint": "^8.18.1",
"typescript-eslint": "^8.19.0",
"webpack": "^5.97.1",
"webpack-cli": "^5.1.4"
"webpack-cli": "^6.0.1"
},
"optionalDependencies": {
"bufferutil": "^4.0.8",
"bufferutil": "^4.0.9",
"utf-8-validate": "^6.0.5"
},
"pnpm": {
Expand Down
Loading

0 comments on commit 79f8c23

Please sign in to comment.