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(repo): Added coin migrator client #4

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,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 @@ -108,14 +108,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
Loading