Skip to content

Add Moar Market adapter #1898

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

Merged
merged 2 commits into from
Jun 4, 2025
Merged
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
82 changes: 82 additions & 0 deletions src/adaptors/moar-market/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
const axios = require('axios');
const sdk = require('@defillama/sdk');

const MOAR_APP_URL = 'https://app.moar.market';
const MOAR_ADDRESS = "0xa3afc59243afb6deeac965d40b25d509bb3aebc12f502b8592c283070abc2e07";
const MOAR_PACKAGE_OWNER_ADDRESS = "0x37e9ce6910ceadd16b0048250a33dac6342549acf31387278ea0f95c9057f110";

async function apy() {
const poolsConfig = await getAptosResource(MOAR_PACKAGE_OWNER_ADDRESS, `${MOAR_ADDRESS}::pool::PoolConfigs`)
const poolAddresses = poolsConfig['data']['all_pools']['inline_vec'].map(x => x['inner'])

const pools = [];
let poolIndex = 0;
for (const poolAddress of poolAddresses) {
const poolData = (await getAptosResource(poolAddress, `${MOAR_ADDRESS}::pool::Pool`)).data
const underlyingAsset = poolData.underlying_asset.inner;

const [faSymbol, interestRateResponse] = await Promise.all([
aptosView({
functionStr: "0x1::fungible_asset::symbol",
type_arguments: ["0x1::fungible_asset::Metadata"],
args: [underlyingAsset]}),
aptosView({
functionStr: `${MOAR_ADDRESS}::pool::get_interest_rate`,
type_arguments: [],
args: [poolIndex.toString()],
})])
const interestRate = interestRateResponse[0];

pools.push({
pool: `${poolAddress}_aptos`,
chain: 'aptos',
project: 'moar-market',
apyBase: (interestRate / 1e8 * (1 - poolData.fee_on_interest_bps / 1e4)) * 100,
apyReward: null,
apyBaseBorrow: interestRate / 1e8 * 100,
apyRewardBorrow: null,
totalSupplyUsd: await getUSDValue(poolData.total_deposited, underlyingAsset),
totalBorrowUsd: await getUSDValue(poolData.total_borrows, underlyingAsset),
rewardTokens: [],
symbol: faSymbol,
tvlUsd: await getUSDValue(poolData.total_deposited - poolData.total_borrows, underlyingAsset),
underlyingTokens: [underlyingAsset],
url: `${MOAR_APP_URL}/lend/${faSymbol.toLowerCase()}`,
})
poolIndex++;
}

return pools;
}

async function getUSDValue(amount, asset) {
const chainApi = new sdk.ChainApi({ chain: 'aptos' })
chainApi.addToken(asset, amount)
const usdValue = await chainApi.getUSDValue()
return usdValue
}

async function getAptosResource(address, resource) {
const response = await axios.get(`https://api.mainnet.aptoslabs.com/v1/accounts/${address}/resource/${resource}`)
return response.data
}

async function aptosView({ functionStr, type_arguments = [], args = [], ledgerVersion = undefined }) {
let path = `https://api.mainnet.aptoslabs.com/v1/view`
if (ledgerVersion !== undefined) path += `?ledger_version=${ledgerVersion}`
const response = await axios.post(path,
{ "function": functionStr, "type_arguments": type_arguments, arguments: args },
{
headers: {
'Content-Type': 'application/json',
},
}
)
return response.data.length === 1 ? response.data[0] : response.data
}

module.exports = {
timetravel: true,
apy: apy,
url: `${MOAR_APP_URL}/lend`,
};
Loading