Comparing version 1.4.27-dev.8 to 1.4.27-dev.9
@@ -74,3 +74,3 @@ "use strict"; | ||
// const protocolPackage = getPackageCache(); | ||
const protocolPackage = '0xacc64a324fc6f68b47fefd484419dedc4d620630665ead67f393c90d11b387b9'; | ||
const protocolPackage = '0x8200ce83e1bc0894b641f0a466694b4f6e25d3f9cc3093915a887ec9e7f3395e'; | ||
return { | ||
@@ -99,3 +99,3 @@ ProtocolPackage: protocolPackage, | ||
supplyBalanceParentId: "0x0864aabbdcab5da56964b70fe6ad8fc592b01dfbb6254cb9bc2a965e517c1029", | ||
rewardFundId: "", | ||
rewardFundId: "0x5fdbd4ae16b58784bc898d81c732815c46f92b915ba3a188a520424482b6bdd9", | ||
}, | ||
@@ -102,0 +102,0 @@ wUSDC: { |
@@ -119,2 +119,1 @@ import { Pool, CoinInfo } from './types'; | ||
}; | ||
export declare const noDepositCoinType: never[]; |
@@ -12,3 +12,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.noDepositCoinType = exports.ProFundsPoolInfo = exports.OracleProConfig = exports.PriceFeedConfig = exports.vSuiConfig = exports.suiBTC = exports.stSUI = exports.suiUSDT = exports.BUCK = exports.BLUE = exports.FDUSD = exports.DEEP = exports.LorenzoBTC = exports.NS = exports.USDY = exports.ETH = exports.nUSDC = exports.wUSDC = exports.AUSD = exports.WBTC = exports.haSui = exports.CETUS = exports.WETH = exports.USDT = exports.vSui = exports.Sui = exports.NAVX = exports.flashloanConfig = exports.pool = exports.getConfig = exports.AddressMap = void 0; | ||
exports.ProFundsPoolInfo = exports.OracleProConfig = exports.PriceFeedConfig = exports.vSuiConfig = exports.suiBTC = exports.stSUI = exports.suiUSDT = exports.BUCK = exports.BLUE = exports.FDUSD = exports.DEEP = exports.LorenzoBTC = exports.NS = exports.USDY = exports.ETH = exports.nUSDC = exports.wUSDC = exports.AUSD = exports.WBTC = exports.haSui = exports.CETUS = exports.WETH = exports.USDT = exports.vSui = exports.Sui = exports.NAVX = exports.flashloanConfig = exports.pool = exports.getConfig = exports.AddressMap = void 0; | ||
exports.getPackageCache = getPackageCache; | ||
@@ -894,2 +894,1 @@ exports.setPackageCache = setPackageCache; | ||
}; | ||
exports.noDepositCoinType = []; |
import { Transaction } from "@mysten/sui/transactions"; | ||
import { CoinInfo, PoolConfig } from '../../types'; | ||
import { CoinInfo, PoolConfig, OptionType } from '../../types'; | ||
import { SuiClient } from "@mysten/sui/client"; | ||
@@ -165,4 +165,4 @@ /** | ||
* @param contractOptionTypes - Array of contract option types to filter rewards (e.g., [1], [3], or [1,3]). | ||
* When passing [1], only option 1 rewards will be returned. | ||
* When passing [3], only option 3 rewards will be returned. | ||
* When passing [1], only supply rewards will be returned. | ||
* When passing [3], only borrow rewards will be returned. | ||
* When passing [1,3], rewards for both options will be returned. | ||
@@ -173,3 +173,3 @@ * @param prettyPrint - Flag to determine if the result should be pretty printed. | ||
*/ | ||
export declare function getAvailableRewards(client: SuiClient, checkAddress: string, contractOptionTypes: number[], // Use ContractOptionType[] if you have a dedicated type | ||
export declare function getAvailableRewards(client: SuiClient, checkAddress: string, contractOptionTypes: OptionType[], // Use ContractOptionType[] if you have a dedicated type | ||
prettyPrint?: boolean, includeV2?: boolean): Promise<PoolRewards[]>; | ||
@@ -176,0 +176,0 @@ /** |
@@ -88,3 +88,3 @@ "use strict"; | ||
txb.object(config.IncentiveV2), | ||
txb.object(config.IncentiveV3), // The incentive object v2 | ||
txb.object(config.IncentiveV3), // The incentive object v3 | ||
], | ||
@@ -116,3 +116,3 @@ typeArguments: [_pool.type] | ||
txb.object(config.IncentiveV2), | ||
txb.object(config.IncentiveV3), // The incentive object v2 | ||
txb.object(config.IncentiveV3), // The incentive object v3 | ||
txb.object(account) | ||
@@ -146,3 +146,3 @@ ], | ||
txb.object(config.IncentiveV2), | ||
txb.object(config.IncentiveV3), // The incentive object v2 | ||
txb.object(config.IncentiveV3), // The incentive object v3 | ||
], | ||
@@ -185,3 +185,3 @@ typeArguments: [_pool.type] | ||
txb.object(config.IncentiveV2), | ||
txb.object(config.IncentiveV3), // The incentive object v2 | ||
txb.object(config.IncentiveV3), // The incentive object v3 | ||
txb.object(account) | ||
@@ -220,3 +220,3 @@ ], | ||
txb.object(config.IncentiveV2), // The incentive object v2 | ||
txb.object(config.IncentiveV3), // The incentive object v2 | ||
txb.object(config.IncentiveV3), // The incentive object v3 | ||
], | ||
@@ -262,3 +262,3 @@ typeArguments: [_pool.type] | ||
txb.object(config.IncentiveV2), // The incentive object v2 | ||
txb.object(config.IncentiveV3), // The incentive object v2 | ||
txb.object(config.IncentiveV3), // The incentive object v3 | ||
], | ||
@@ -458,4 +458,4 @@ typeArguments: [_pool.type] | ||
* @param contractOptionTypes - Array of contract option types to filter rewards (e.g., [1], [3], or [1,3]). | ||
* When passing [1], only option 1 rewards will be returned. | ||
* When passing [3], only option 3 rewards will be returned. | ||
* When passing [1], only supply rewards will be returned. | ||
* When passing [3], only borrow rewards will be returned. | ||
* When passing [1,3], rewards for both options will be returned. | ||
@@ -520,3 +520,3 @@ * @param prettyPrint - Flag to determine if the result should be pretty printed. | ||
continue; | ||
const assetId = parseInt(entry.assert_id, 10); | ||
const assetId = parseInt(entry.asset_id, 10); | ||
const rewardType = entry.option; | ||
@@ -523,0 +523,0 @@ const key = `${assetId}-${rewardType}-${entry.reward_coin_type}`; |
@@ -67,3 +67,3 @@ "use strict"; | ||
const activePools = allPools.filter((pool) => pool.available.trim() !== "0"); | ||
const fundIds = activePools.map((item) => item.funds); | ||
const fundIds = [...new Set(activePools.map((item) => item.funds))]; | ||
// Fetch fund details | ||
@@ -70,0 +70,0 @@ const funds = yield client.multiGetObjects({ |
@@ -109,3 +109,3 @@ "use strict"; | ||
for (const reward of rewardsList) { | ||
const { asset_coin_type, reward_coin_type, option, rule_ids, user_claimable_reward } = reward; | ||
const { asset_coin_type, reward_coin_type, option, rule_ids, user_claimable_reward, } = reward; | ||
// Retrieve configuration keys for asset and reward coin types. | ||
@@ -117,3 +117,6 @@ const assetPriceFeedKey = getPriceFeedKey(asset_coin_type); | ||
// Skip reward if any necessary configuration is missing. | ||
if (!assetPriceFeedKey || !rewardPriceFeedKey || !assetPoolKey || !rewardPoolKey) { | ||
if (!assetPriceFeedKey || | ||
!rewardPriceFeedKey || | ||
!assetPoolKey || | ||
!rewardPoolKey) { | ||
continue; | ||
@@ -129,3 +132,3 @@ } | ||
groupedRewards[asset_coin_type].push({ | ||
assert_id: address_1.pool[assetPoolKey].assetId.toString(), | ||
asset_id: address_1.pool[assetPoolKey].assetId.toString(), | ||
reward_id: address_1.pool[rewardPoolKey].assetId.toString(), | ||
@@ -148,4 +151,3 @@ reward_coin_type, | ||
const rewardKey = (_a = getPriceFeedKey(reward.reward_coin_type)) !== null && _a !== void 0 ? _a : reward.reward_coin_type; | ||
console.log(` ${idx + 1}. Reward Coin: ${rewardKey}, Option: ${reward.option}, ` + | ||
`Claimable: ${reward.user_claimable_reward}`); | ||
console.log(` ${idx + 1}. Reward Coin: ${rewardKey}, Option: ${reward.option}, ` + `Claimable: ${reward.user_claimable_reward}`); | ||
}); | ||
@@ -226,3 +228,3 @@ } | ||
acc[asset_coin_type].push({ | ||
assert_id: address_1.pool[assetPoolKey].assetId.toString(), | ||
asset_id: address_1.pool[assetPoolKey].assetId.toString(), | ||
reward_id: address_1.pool[rewardPoolKey].assetId.toString(), | ||
@@ -279,17 +281,19 @@ reward_coin_type, | ||
if (!matchedRewardFund) { | ||
throw new Error(`No matching rewardFund found for reward_coin_type: ${rewardInfo.reward_coin_type}`); | ||
console.log(`No matching rewardFund found for reward_coin_type: ${rewardInfo.reward_coin_type}`); | ||
return; | ||
} | ||
// Construct the Move call | ||
tx.moveCall({ | ||
target: `${config.ProtocolPackage}::incentive_v3::claim_reward_entry`, | ||
arguments: [ | ||
tx.object("0x06"), | ||
tx.object(config.IncentiveV3), | ||
tx.object(config.StorageId), | ||
tx.object(matchedRewardFund), | ||
tx.pure.vector("string", rewardInfo.asset_vector), | ||
tx.pure.vector("address", rewardInfo.rules_vector), | ||
], | ||
typeArguments: [rewardInfo.reward_coin_type], | ||
}); | ||
else { | ||
tx.moveCall({ | ||
target: `${config.ProtocolPackage}::incentive_v3::claim_reward_entry`, | ||
arguments: [ | ||
tx.object("0x06"), | ||
tx.object(config.IncentiveV3), | ||
tx.object(config.StorageId), | ||
tx.object(matchedRewardFund), | ||
tx.pure.vector("string", rewardInfo.asset_vector), | ||
tx.pure.vector("address", rewardInfo.rules_vector), | ||
], | ||
typeArguments: [rewardInfo.reward_coin_type], | ||
}); | ||
} | ||
}); | ||
@@ -465,6 +469,13 @@ } | ||
return rules.reduce((acc, rule) => { | ||
var _a, _b, _c; | ||
const ruleRate = Number(rule.rate) / 1e27; // Convert from large integer representation | ||
const rewardPrice = coinPriceMap[formatCoinType(rule.reward_coin_type)].value || 0; | ||
const rewardDecimal = Number(coinPriceMap[formatCoinType(rule.reward_coin_type)].decimals) || | ||
0; | ||
const formattedRewardCoinType = formatCoinType(rule.reward_coin_type); | ||
const rewardPrice = ((_a = coinPriceMap[formattedRewardCoinType]) === null || _a === void 0 ? void 0 : _a.value) || 0; | ||
const rewardDecimal = Number((_b = coinPriceMap[formattedRewardCoinType]) === null || _b === void 0 ? void 0 : _b.decimals) || 9; | ||
if (rewardPrice === 0) { | ||
console.log(`No price data found for reward coin type: ${rule.reward_coin_type} (${formattedRewardCoinType})`); | ||
} | ||
if (!((_c = coinPriceMap[formattedRewardCoinType]) === null || _c === void 0 ? void 0 : _c.decimals)) { | ||
console.log(`No decimal data found for reward coin type: ${rule.reward_coin_type} (${formattedRewardCoinType})`); | ||
} | ||
acc.rateSum += (ruleRate * rewardPrice) / Math.pow(10, rewardDecimal); | ||
@@ -586,6 +597,5 @@ acc.rewardCoins.push(rule.reward_coin_type); | ||
const config = yield (0, address_1.getConfig)(); | ||
const userAddress = '0xcda879cde94eeeae2dd6df58c9ededc60bcf2f7aedb79777e47d95b2cfb016c2'; | ||
// 2. Get ReserveData (this replaces the previous poolsInfo) | ||
// 3. Get on-chain incentive data | ||
const [reserves, rawData] = yield Promise.all([ | ||
const userAddress = "0xcda879cde94eeeae2dd6df58c9ededc60bcf2f7aedb79777e47d95b2cfb016c2"; | ||
// 2. Fetch ReserveData, IncentiveV3 data, and APY calculations in parallel | ||
const [reserves, rawData, v2SupplyApy, v2BorrowApy] = yield Promise.all([ | ||
(0, CallFunctions_1.getReserveData)(config.StorageId, client), | ||
@@ -596,8 +606,9 @@ client.getObject({ | ||
}), | ||
(0, CallFunctions_1.getIncentiveAPY)(userAddress, client, 1), | ||
(0, CallFunctions_1.getIncentiveAPY)(userAddress, client, 3), | ||
]); | ||
// 3. Process incentive data | ||
const incentiveData = rawData; | ||
// 4. Group incentive data by asset coin type | ||
const groupedPools = groupByAssetCoinType(incentiveData); | ||
// 5. Build a set of all coin types needed for price lookup. | ||
// This includes coin types from reserves, asset coin types, and reward coin types. | ||
// 4. Build a set of all coin types needed for price lookup | ||
const coinTypeSet = new Set(); | ||
@@ -614,3 +625,3 @@ reserves.forEach((r) => { | ||
const coinTypes = Array.from(coinTypeSet); | ||
// 6. Fetch coin price data | ||
// 5. Fetch coin price data | ||
const coinPrices = yield (0, PoolInfo_1.fetchCoinPrices)(coinTypes); | ||
@@ -624,8 +635,5 @@ const coinPriceMap = (coinPrices === null || coinPrices === void 0 ? void 0 : coinPrices.reduce((map, price) => { | ||
}, {})) || {}; | ||
// 7. Calculate APY using grouped incentive data and reserve data with price info | ||
// 6. Calculate APY using grouped incentive data and reserve data with price info | ||
const v3Apy = yield calculateApy(groupedPools, reserves, coinPriceMap); | ||
const [v2SupplyApy, v2BorrowApy] = yield Promise.all([ | ||
(0, CallFunctions_1.getIncentiveAPY)(userAddress, client, 1), | ||
(0, CallFunctions_1.getIncentiveAPY)(userAddress, client, 3), | ||
]); | ||
// 7. Merge the APY results | ||
return mergeApyResults(v3Apy, v2SupplyApy, v2BorrowApy); | ||
@@ -650,3 +658,5 @@ }); | ||
return ""; | ||
return poolEntry.type.startsWith("0x") ? poolEntry.type.slice(2) : poolEntry.type; | ||
return poolEntry.type.startsWith("0x") | ||
? poolEntry.type.slice(2) | ||
: poolEntry.type; | ||
}; | ||
@@ -653,0 +663,0 @@ // Map to store merged V2 supply and borrow data by asset ID |
@@ -24,3 +24,3 @@ interface BaseRewardFields { | ||
export interface ProcessedReward { | ||
assert_id: string; | ||
asset_id: string; | ||
reward_id: string; | ||
@@ -27,0 +27,0 @@ reward_coin_type: string; |
{ | ||
"name": "navi-sdk", | ||
"version": "1.4.27-dev.8", | ||
"version": "1.4.27-dev.9", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -90,3 +90,3 @@ import { Pool, CoinInfo,PoolConfig } from './types'; | ||
// const protocolPackage = getPackageCache(); | ||
const protocolPackage = '0xacc64a324fc6f68b47fefd484419dedc4d620630665ead67f393c90d11b387b9'; | ||
const protocolPackage = '0x8200ce83e1bc0894b641f0a466694b4f6e25d3f9cc3093915a887ec9e7f3395e'; | ||
return { | ||
@@ -129,3 +129,3 @@ ProtocolPackage: protocolPackage, | ||
"0x0864aabbdcab5da56964b70fe6ad8fc592b01dfbb6254cb9bc2a965e517c1029", | ||
rewardFundId: "", | ||
rewardFundId: "0x5fdbd4ae16b58784bc898d81c732815c46f92b915ba3a188a520424482b6bdd9", | ||
}, | ||
@@ -132,0 +132,0 @@ wUSDC: { |
@@ -39,3 +39,3 @@ import { Transaction } from "@mysten/sui/transactions"; | ||
txb.object(config.IncentiveV2), | ||
txb.object(config.IncentiveV3), // The incentive object v2 | ||
txb.object(config.IncentiveV3), // The incentive object v3 | ||
], | ||
@@ -67,3 +67,3 @@ typeArguments: [_pool.type] | ||
txb.object(config.IncentiveV2), | ||
txb.object(config.IncentiveV3), // The incentive object v2 | ||
txb.object(config.IncentiveV3), // The incentive object v3 | ||
txb.object(account) | ||
@@ -97,3 +97,3 @@ ], | ||
txb.object(config.IncentiveV2), | ||
txb.object(config.IncentiveV3), // The incentive object v2 | ||
txb.object(config.IncentiveV3), // The incentive object v3 | ||
], | ||
@@ -138,3 +138,3 @@ typeArguments: [_pool.type] | ||
txb.object(config.IncentiveV2), | ||
txb.object(config.IncentiveV3), // The incentive object v2 | ||
txb.object(config.IncentiveV3), // The incentive object v3 | ||
txb.object(account) | ||
@@ -175,3 +175,3 @@ ], | ||
txb.object(config.IncentiveV2), // The incentive object v2 | ||
txb.object(config.IncentiveV3), // The incentive object v2 | ||
txb.object(config.IncentiveV3), // The incentive object v3 | ||
], | ||
@@ -220,3 +220,3 @@ typeArguments: [_pool.type] | ||
txb.object(config.IncentiveV2), // The incentive object v2 | ||
txb.object(config.IncentiveV3), // The incentive object v2 | ||
txb.object(config.IncentiveV3), // The incentive object v3 | ||
], | ||
@@ -432,4 +432,4 @@ typeArguments: [_pool.type] | ||
* @param contractOptionTypes - Array of contract option types to filter rewards (e.g., [1], [3], or [1,3]). | ||
* When passing [1], only option 1 rewards will be returned. | ||
* When passing [3], only option 3 rewards will be returned. | ||
* When passing [1], only supply rewards will be returned. | ||
* When passing [3], only borrow rewards will be returned. | ||
* When passing [1,3], rewards for both options will be returned. | ||
@@ -443,3 +443,3 @@ * @param prettyPrint - Flag to determine if the result should be pretty printed. | ||
checkAddress: string, | ||
contractOptionTypes: number[], // Use ContractOptionType[] if you have a dedicated type | ||
contractOptionTypes: OptionType[], // Use ContractOptionType[] if you have a dedicated type | ||
prettyPrint = true, | ||
@@ -483,4 +483,3 @@ includeV2: boolean = true // Feature flag to enable/disable V2 logic | ||
type V3Entry = { | ||
// "assert_id" represents the asset id. | ||
assert_id: string; | ||
asset_id: string; | ||
reward_id: string; | ||
@@ -518,3 +517,3 @@ reward_coin_type: string; | ||
if (!contractOptionTypes.includes(entry.option)) continue; | ||
const assetId = parseInt(entry.assert_id, 10); | ||
const assetId = parseInt(entry.asset_id, 10); | ||
const rewardType = entry.option; | ||
@@ -521,0 +520,0 @@ const key = `${assetId}-${rewardType}-${entry.reward_coin_type}`; |
@@ -102,3 +102,3 @@ import { Transaction } from "@mysten/sui/transactions"; | ||
); | ||
const fundIds = activePools.map((item) => item.funds); | ||
const fundIds = [...new Set(activePools.map((item) => item.funds))]; | ||
@@ -105,0 +105,0 @@ // Fetch fund details |
@@ -120,3 +120,9 @@ import { Transaction } from "@mysten/sui/transactions"; | ||
for (const reward of rewardsList) { | ||
const { asset_coin_type, reward_coin_type, option, rule_ids, user_claimable_reward } = reward; | ||
const { | ||
asset_coin_type, | ||
reward_coin_type, | ||
option, | ||
rule_ids, | ||
user_claimable_reward, | ||
} = reward; | ||
@@ -130,3 +136,8 @@ // Retrieve configuration keys for asset and reward coin types. | ||
// Skip reward if any necessary configuration is missing. | ||
if (!assetPriceFeedKey || !rewardPriceFeedKey || !assetPoolKey || !rewardPoolKey) { | ||
if ( | ||
!assetPriceFeedKey || | ||
!rewardPriceFeedKey || | ||
!assetPoolKey || | ||
!rewardPoolKey | ||
) { | ||
continue; | ||
@@ -146,3 +157,3 @@ } | ||
groupedRewards[asset_coin_type].push({ | ||
assert_id: pool[assetPoolKey].assetId.toString(), | ||
asset_id: pool[assetPoolKey].assetId.toString(), | ||
reward_id: pool[rewardPoolKey].assetId.toString(), | ||
@@ -167,4 +178,5 @@ reward_coin_type, | ||
console.log( | ||
` ${idx + 1}. Reward Coin: ${rewardKey}, Option: ${reward.option}, ` + | ||
`Claimable: ${reward.user_claimable_reward}` | ||
` ${idx + 1}. Reward Coin: ${rewardKey}, Option: ${ | ||
reward.option | ||
}, ` + `Claimable: ${reward.user_claimable_reward}` | ||
); | ||
@@ -178,3 +190,2 @@ }); | ||
/** | ||
@@ -290,3 +301,3 @@ * Retrieves the available rewards for a specific user in the protocol. | ||
acc[asset_coin_type].push({ | ||
assert_id: pool[assetPoolKey].assetId.toString(), | ||
asset_id: pool[assetPoolKey].assetId.toString(), | ||
reward_id: pool[rewardPoolKey].assetId.toString(), | ||
@@ -360,20 +371,20 @@ reward_coin_type, | ||
if (!matchedRewardFund) { | ||
throw new Error( | ||
console.log( | ||
`No matching rewardFund found for reward_coin_type: ${rewardInfo.reward_coin_type}` | ||
); | ||
return; | ||
} else { | ||
tx.moveCall({ | ||
target: `${config.ProtocolPackage}::incentive_v3::claim_reward_entry`, | ||
arguments: [ | ||
tx.object("0x06"), | ||
tx.object(config.IncentiveV3), | ||
tx.object(config.StorageId), | ||
tx.object(matchedRewardFund), | ||
tx.pure.vector("string", rewardInfo.asset_vector), | ||
tx.pure.vector("address", rewardInfo.rules_vector), | ||
], | ||
typeArguments: [rewardInfo.reward_coin_type], | ||
}); | ||
} | ||
// Construct the Move call | ||
tx.moveCall({ | ||
target: `${config.ProtocolPackage}::incentive_v3::claim_reward_entry`, | ||
arguments: [ | ||
tx.object("0x06"), | ||
tx.object(config.IncentiveV3), | ||
tx.object(config.StorageId), | ||
tx.object(matchedRewardFund), | ||
tx.pure.vector("string", rewardInfo.asset_vector), | ||
tx.pure.vector("address", rewardInfo.rules_vector), | ||
], | ||
typeArguments: [rewardInfo.reward_coin_type], | ||
}); | ||
} | ||
@@ -602,7 +613,14 @@ | ||
const ruleRate = Number(rule.rate) / 1e27; // Convert from large integer representation | ||
const rewardPrice = | ||
coinPriceMap[formatCoinType(rule.reward_coin_type)].value || 0; | ||
const formattedRewardCoinType = formatCoinType(rule.reward_coin_type); | ||
const rewardPrice = coinPriceMap[formattedRewardCoinType]?.value || 0; | ||
const rewardDecimal = | ||
Number(coinPriceMap[formatCoinType(rule.reward_coin_type)].decimals) || | ||
0; | ||
Number(coinPriceMap[formattedRewardCoinType]?.decimals) || 9; | ||
if (rewardPrice === 0) { | ||
console.log( | ||
`No price data found for reward coin type: ${rule.reward_coin_type} (${formattedRewardCoinType})` | ||
); | ||
} | ||
if (!coinPriceMap[formattedRewardCoinType]?.decimals) { | ||
console.log(`No decimal data found for reward coin type: ${rule.reward_coin_type} (${formattedRewardCoinType})`); | ||
} | ||
acc.rateSum += (ruleRate * rewardPrice) / Math.pow(10, rewardDecimal); | ||
@@ -756,7 +774,7 @@ acc.rewardCoins.push(rule.reward_coin_type); | ||
const config = await getConfig(); | ||
const userAddress = '0xcda879cde94eeeae2dd6df58c9ededc60bcf2f7aedb79777e47d95b2cfb016c2' | ||
const userAddress = | ||
"0xcda879cde94eeeae2dd6df58c9ededc60bcf2f7aedb79777e47d95b2cfb016c2"; | ||
// 2. Get ReserveData (this replaces the previous poolsInfo) | ||
// 3. Get on-chain incentive data | ||
const [reserves, rawData] = await Promise.all([ | ||
// 2. Fetch ReserveData, IncentiveV3 data, and APY calculations in parallel | ||
const [reserves, rawData, v2SupplyApy, v2BorrowApy] = await Promise.all([ | ||
getReserveData(config.StorageId, client), | ||
@@ -767,10 +785,11 @@ client.getObject({ | ||
}), | ||
getIncentiveAPY(userAddress, client, 1), | ||
getIncentiveAPY(userAddress, client, 3), | ||
]); | ||
// 3. Process incentive data | ||
const incentiveData = rawData as unknown as V3Type.IncentiveData; | ||
// 4. Group incentive data by asset coin type | ||
const groupedPools = groupByAssetCoinType(incentiveData); | ||
// 5. Build a set of all coin types needed for price lookup. | ||
// This includes coin types from reserves, asset coin types, and reward coin types. | ||
// 4. Build a set of all coin types needed for price lookup | ||
const coinTypeSet = new Set<string>(); | ||
@@ -787,3 +806,4 @@ reserves.forEach((r: V3Type.ReserveData) => { | ||
const coinTypes = Array.from(coinTypeSet); | ||
// 6. Fetch coin price data | ||
// 5. Fetch coin price data | ||
const coinPrices = await fetchCoinPrices(coinTypes); | ||
@@ -798,8 +818,7 @@ const coinPriceMap: Record<string, { value: number; decimals: string }> = | ||
}, {} as Record<string, { value: number; decimals: string }>) || {}; | ||
// 7. Calculate APY using grouped incentive data and reserve data with price info | ||
// 6. Calculate APY using grouped incentive data and reserve data with price info | ||
const v3Apy = await calculateApy(groupedPools, reserves, coinPriceMap); | ||
const [v2SupplyApy, v2BorrowApy] = await Promise.all([ | ||
getIncentiveAPY(userAddress, client, 1), | ||
getIncentiveAPY(userAddress, client, 3), | ||
]); | ||
// 7. Merge the APY results | ||
return mergeApyResults(v3Apy, v2SupplyApy, v2BorrowApy); | ||
@@ -821,7 +840,6 @@ } | ||
async function mergeApyResults( | ||
v3ApyResults: V3Type.ApyResult[], // V3 APY results | ||
v2SupplyApy: V2Apy[], // V2 supply APY data | ||
v2BorrowApy: V2Apy[] // V2 borrow APY data | ||
v3ApyResults: V3Type.ApyResult[], // V3 APY results | ||
v2SupplyApy: V2Apy[], // V2 supply APY data | ||
v2BorrowApy: V2Apy[] // V2 borrow APY data | ||
): Promise<V3Type.ApyResult[]> { | ||
// Helper function to calculate APY as a percentage | ||
@@ -836,3 +854,5 @@ const calculateApyPercentage = (apyStr: string): number => | ||
if (!poolEntry) return ""; | ||
return poolEntry.type.startsWith("0x") ? poolEntry.type.slice(2) : poolEntry.type; | ||
return poolEntry.type.startsWith("0x") | ||
? poolEntry.type.slice(2) | ||
: poolEntry.type; | ||
}; | ||
@@ -881,5 +901,6 @@ | ||
v3ApyResults.forEach((v3Data) => { | ||
finalApyResultsMap.set(v3Data.asset, { | ||
finalApyResultsMap.set(v3Data.asset, { | ||
...v3Data, | ||
asset_coin_type: getFormattedCoinType(v3Data.asset) }); | ||
asset_coin_type: getFormattedCoinType(v3Data.asset), | ||
}); | ||
}); | ||
@@ -905,3 +926,3 @@ | ||
// Ensure coin type is formatted correctly, regardless of whether it's a new asset or not | ||
asset_coin_type: getFormattedCoinType(assetId), | ||
asset_coin_type: getFormattedCoinType(assetId), | ||
supplyIncentiveApyInfo: { ...v2Data.supply }, | ||
@@ -908,0 +929,0 @@ borrowIncentiveApyInfo: { ...v2Data.borrow }, |
@@ -35,3 +35,3 @@ // 1) This part is to enable reuse for Reward and ClaimRewardInput interfaces. | ||
export interface ProcessedReward { | ||
assert_id: string; | ||
asset_id: string; | ||
reward_id: string; | ||
@@ -38,0 +38,0 @@ reward_coin_type: string; // The coin type used for the reward. |
@@ -74,8 +74,8 @@ import { | ||
txb.setGasBudget(300_000_000); | ||
const poolConfig: PoolConfig = pool["haSui" as keyof Pool]; | ||
const poolConfig: PoolConfig = pool["FDUSD" as keyof Pool]; | ||
const hasuiObj = | ||
txb.object("0xc13c5f026b7b78aa17da377d39c6f749d9625bdf87a3a3aa5b53d65edadf37b0"); | ||
txb.object("0x57c1d71495095908d733703045351861dffb5f21709408362335db8fa324acef"); | ||
// const [toDeposit] = txb.splitCoins(txb.gas, [1e9]); | ||
await V.depositCoin(txb, poolConfig, hasuiObj, txb.pure.u64(1e8)); | ||
await V.depositCoin(txb, poolConfig, hasuiObj, txb.pure.u64(1e6)); | ||
@@ -181,3 +181,3 @@ // const result = await account.client.devInspectTransactionBlock({ | ||
account.client, | ||
"0x3be8db6ca4adf33387f16c86c443737e78fd14db85a4e1c68cc8f256ac68549c", | ||
"0x400a533a4801f3905a25bd7edab4be6b54aeef41fe44971bd1e519d4f363d6b9", | ||
[3,1] | ||
@@ -287,3 +287,3 @@ ); | ||
it("should success cal apy V3", async () => { | ||
it.skip("should success cal apy V3", async () => { | ||
const txRes = await getPoolApy(account.client); | ||
@@ -444,4 +444,25 @@ console.log(JSON.stringify(txRes, null, 2)); | ||
it.skip('should success withdraw Sui to NAVI protocol', async () => { | ||
let txb = new Transaction(); | ||
txb.setSender(account.address); | ||
const poolConfig: PoolConfig = pool["Sui" as keyof Pool]; | ||
// const [toDeposit] = txb.splitCoins(txb.gas, [1e9]); | ||
// await depositCoin(txb, poolConfig, toDeposit, 1e9); | ||
// const [withdrawCoind] = await V.withdrawCoin(txb, poolConfig, 1e9); | ||
const [borrowCoind] = await V.borrowCoin(txb, poolConfig, 1e6); | ||
// borrowCoind | ||
txb.transferObjects([borrowCoind as any], account.address); | ||
const txRes = await V.SignAndSubmitTXB( | ||
txb, | ||
account.client, | ||
account.keypair | ||
); | ||
if (txRes.effects.status.status === "failure") { | ||
throw new Error(txRes.effects.status.error) | ||
} | ||
expect(txRes.effects.status.status).toEqual("success"); | ||
}); | ||
}); |
716569
14979