From 25d3794d1bddbfcc54681e43d03a0c8504017bb1 Mon Sep 17 00:00:00 2001 From: Marton Lederer Date: Fri, 29 Aug 2025 16:34:33 +0200 Subject: [PATCH 1/4] fix: use config in getData() --- src/ao/messaging/getData.ts | 5 +++-- src/ao/utils/connect.ts | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ao/messaging/getData.ts b/src/ao/messaging/getData.ts index 425281ba..62dae323 100644 --- a/src/ao/messaging/getData.ts +++ b/src/ao/messaging/getData.ts @@ -1,5 +1,5 @@ -import { dryrun } from "@permaweb/aoconnect"; import { DryRunResult } from "@permaweb/aoconnect/dist/lib/dryrun"; +import { connectToAO, Services } from "../utils/connect"; interface MessageTags { Target: string; @@ -19,7 +19,7 @@ interface MessageTags { type GetDataRes = DryRunResult; -export async function getData(messageTags: MessageTags): Promise { +export async function getData(messageTags: MessageTags, config?: Services): Promise { const convertedMessageTags = Object.entries(messageTags) .map(([name, value]) => ({ name, @@ -31,6 +31,7 @@ export async function getData(messageTags: MessageTags): Promise { const targetProcessID = messageTags["Target"]; try { + const { dryrun } = connectToAO(config); const { Messages, Spawns, Output, Error } = await dryrun({ process: targetProcessID, data: "", diff --git a/src/ao/utils/connect.ts b/src/ao/utils/connect.ts index 370bd05a..8555438d 100644 --- a/src/ao/utils/connect.ts +++ b/src/ao/utils/connect.ts @@ -57,10 +57,10 @@ export function connectToAO(services?: Partial) { CU_URL, }; - const { spawn, message, result } = connect({ + const { spawn, message, result, dryrun } = connect({ MODE: "legacy", ...configs, }) as LegacyConnectResult; - return { spawn, message, result, configs }; + return { spawn, message, result, configs, dryrun }; } From 1b21ab8579b8c29261b19435beab79e6ea275414 Mon Sep 17 00:00:00 2001 From: Marton Lederer Date: Fri, 29 Aug 2025 17:06:45 +0200 Subject: [PATCH 2/4] feat: update codebase to use config defined --- src/functions/liquidations/getLiquidations.ts | 6 +++-- .../liquidations/getLiquidationsMap.ts | 5 ++-- src/functions/oTokenData/getBalances.ts | 5 ++-- src/functions/oTokenData/getBorrowAPR.ts | 5 ++-- src/functions/oTokenData/getCooldown.ts | 5 ++-- src/functions/oTokenData/getExchangeRate.ts | 5 ++-- src/functions/oTokenData/getGlobalPosition.ts | 7 ++--- src/functions/oTokenData/getInfo.ts | 5 ++-- src/functions/oTokenData/getPosition.ts | 5 ++-- src/functions/oTokenData/getSupplyAPR.ts | 7 ++--- src/functions/protocolData/getAllPositions.ts | 5 ++-- .../protocolData/getHistoricalAPR.ts | 5 ++-- src/functions/utils/getBalance.ts | 1 + src/functions/utils/getPrice.ts | 5 ++-- src/index.ts | 26 +++++++++---------- 15 files changed, 56 insertions(+), 41 deletions(-) diff --git a/src/functions/liquidations/getLiquidations.ts b/src/functions/liquidations/getLiquidations.ts index eb07d3b6..e33f3562 100644 --- a/src/functions/liquidations/getLiquidations.ts +++ b/src/functions/liquidations/getLiquidations.ts @@ -15,6 +15,7 @@ import { calculateGlobalPositions, TokenPosition, } from "../../ao/sharedLogic/globalPositionUtils"; +import { Services } from "../../ao/utils/connect"; export interface GetLiquidationsRes { liquidations: Map; @@ -49,6 +50,7 @@ interface Tag { export async function getLiquidations( precisionFactor: number, + config?: Services, ): Promise { try { if (!Number.isInteger(precisionFactor)) { @@ -64,7 +66,7 @@ export async function getLiquidations( Target: redstoneOracleAddress, Action: "v2.Request-Latest-Data", Tickers: JSON.stringify(collateralEnabledTickers.map(convertTicker)), - }); + }, config); // add dry run await to not get rate limited await dryRunAwait(1); @@ -115,7 +117,7 @@ export async function getLiquidations( const auctionsRes = await getData({ Target: controllerAddress, Action: "Get-Auctions", - }); + }, config); // add dry run await to not get rate limited await dryRunAwait(1); diff --git a/src/functions/liquidations/getLiquidationsMap.ts b/src/functions/liquidations/getLiquidationsMap.ts index a6cc1f91..7676205d 100644 --- a/src/functions/liquidations/getLiquidationsMap.ts +++ b/src/functions/liquidations/getLiquidationsMap.ts @@ -16,6 +16,7 @@ import { TokenPosition, } from "../../ao/sharedLogic/globalPositionUtils"; import { RedstonePrices } from "./getLiquidations"; +import { Services } from "../../ao/utils/connect"; export interface GetLiquidationsMapRes { /** The wallet/user address that owns this position */ @@ -34,7 +35,7 @@ export interface GetLiquidationsMapRes { remainingCapacity: number; } -export async function getLiquidationsMap(): Promise { +export async function getLiquidationsMap(config?: Services): Promise { try { // Get list of tokens to process const tokensList = Object.keys(tokens); @@ -45,7 +46,7 @@ export async function getLiquidationsMap(): Promise { Target: redstoneOracleAddress, Action: "v2.Request-Latest-Data", Tickers: JSON.stringify(collateralEnabledTickers.map(convertTicker)), - }); + }, config); // add dry run await to not get rate limited await dryRunAwait(1); diff --git a/src/functions/oTokenData/getBalances.ts b/src/functions/oTokenData/getBalances.ts index c765ba9e..408798df 100644 --- a/src/functions/oTokenData/getBalances.ts +++ b/src/functions/oTokenData/getBalances.ts @@ -1,4 +1,5 @@ import { getData } from "../../ao/messaging/getData"; +import { Services } from "../../ao/utils/connect"; import { TokenInput, tokenInput } from "../../ao/utils/tokenInput"; export interface GetBalances { @@ -9,7 +10,7 @@ export type GetBalancesRes = Record; export async function getBalances({ token, -}: GetBalances): Promise { +}: GetBalances, config?: Services): Promise { try { if (!token) { throw new Error("Please specify a token."); @@ -20,7 +21,7 @@ export async function getBalances({ const res = await getData({ Target: oTokenAddress, Action: "Balances", - }); + }, config); if (!res.Messages || !res.Messages[0] || !res.Messages[0].Data) { throw new Error("Invalid response format from getData"); diff --git a/src/functions/oTokenData/getBorrowAPR.ts b/src/functions/oTokenData/getBorrowAPR.ts index 70e6ee2f..a72c076f 100644 --- a/src/functions/oTokenData/getBorrowAPR.ts +++ b/src/functions/oTokenData/getBorrowAPR.ts @@ -1,4 +1,5 @@ import { getData } from "../../ao/messaging/getData"; +import { Services } from "../../ao/utils/connect"; import { TokenInput, tokenInput } from "../../ao/utils/tokenInput"; export interface GetBorrowAPR { @@ -9,7 +10,7 @@ export type GetBorrowAPRRes = number; export async function getBorrowAPR({ token, -}: GetBorrowAPR): Promise { +}: GetBorrowAPR, config?: Services): Promise { try { if (!token) { throw new Error("Please specify a token."); @@ -20,7 +21,7 @@ export async function getBorrowAPR({ const checkDataRes = await getData({ Target: oTokenAddress, Action: "Get-APR", - }); + }, config); const tags = checkDataRes.Messages[0].Tags; const aprResponse: { diff --git a/src/functions/oTokenData/getCooldown.ts b/src/functions/oTokenData/getCooldown.ts index 372b4931..4e24f18e 100644 --- a/src/functions/oTokenData/getCooldown.ts +++ b/src/functions/oTokenData/getCooldown.ts @@ -1,4 +1,5 @@ import { getData } from "../../ao/messaging/getData"; +import { Services } from "../../ao/utils/connect"; import { tokenInput } from "../../ao/utils/tokenInput"; export interface GetCooldown { @@ -17,7 +18,7 @@ export type GetCooldownRes = export async function getCooldown({ recipient, token, -}: GetCooldown): Promise { +}: GetCooldown, config?: Services): Promise { if (!recipient) throw new Error("Please specify a recipient"); if (!token) throw new Error("Please specify a token address"); @@ -27,7 +28,7 @@ export async function getCooldown({ Target: oTokenAddress, Owner: recipient, Action: "Is-Cooldown", - }); + }, config); if (!cooldownRes?.Messages?.[0]?.Tags) { return { onCooldown: false }; diff --git a/src/functions/oTokenData/getExchangeRate.ts b/src/functions/oTokenData/getExchangeRate.ts index 5660f0c7..50f74d0e 100644 --- a/src/functions/oTokenData/getExchangeRate.ts +++ b/src/functions/oTokenData/getExchangeRate.ts @@ -1,4 +1,5 @@ import { getData } from "../../ao/messaging/getData"; +import { Services } from "../../ao/utils/connect"; import { TokenInput, tokenInput } from "../../ao/utils/tokenInput"; export interface GetExchangeRate { @@ -11,7 +12,7 @@ export type GetExchangeRateRes = BigInt; export async function getExchangeRate({ token, quantity, -}: GetExchangeRate): Promise { +}: GetExchangeRate, config?: Services): Promise { try { if (!token || !quantity) { throw new Error("Please specify a token and quantity."); @@ -23,7 +24,7 @@ export async function getExchangeRate({ Target: oTokenAddress, Action: "Exchange-Rate-Current", ...(quantity && { Quantity: quantity.toString() }), - }); + }, config); const valueTag = message.Messages[0].Tags.find( (tag: { name: string; value: string }) => tag.name === "Value", diff --git a/src/functions/oTokenData/getGlobalPosition.ts b/src/functions/oTokenData/getGlobalPosition.ts index a9dfca39..57cb6829 100644 --- a/src/functions/oTokenData/getGlobalPosition.ts +++ b/src/functions/oTokenData/getGlobalPosition.ts @@ -13,6 +13,7 @@ import { TokenPosition, GlobalPosition, } from "../../ao/sharedLogic/globalPositionUtils"; +import { Services } from "../../ao/utils/connect"; type RedstonePrices = Record; @@ -27,7 +28,7 @@ export interface GetGlobalPosition { export async function getGlobalPosition({ walletAddress, -}: GetGlobalPosition): Promise { +}: GetGlobalPosition, config?: Services): Promise { try { if (!walletAddress) { throw new Error("Please specify a wallet address."); @@ -42,7 +43,7 @@ export async function getGlobalPosition({ Target: redstoneOracleAddress, Action: "v2.Request-Latest-Data", Tickers: JSON.stringify(collateralEnabledTickers.map(convertTicker)), - }); + }, config); // add dry run await to not get rate limited await dryRunAwait(1); @@ -61,7 +62,7 @@ export async function getGlobalPosition({ const position = await getPosition({ token, recipient: walletAddress, - }); + }, config); // add dry run await to not get rate limited await dryRunAwait(1); diff --git a/src/functions/oTokenData/getInfo.ts b/src/functions/oTokenData/getInfo.ts index ef25906b..f5d84ef5 100644 --- a/src/functions/oTokenData/getInfo.ts +++ b/src/functions/oTokenData/getInfo.ts @@ -1,4 +1,5 @@ import { getData } from "../../ao/messaging/getData"; +import { Services } from "../../ao/utils/connect"; import { TokenInput, tokenInput } from "../../ao/utils/tokenInput"; export interface GetInfo { @@ -34,7 +35,7 @@ interface Tag { value: string; } -export async function getInfo({ token }: GetInfo): Promise { +export async function getInfo({ token }: GetInfo, config?: Services): Promise { try { if (!token) { throw new Error("Please specify a token."); @@ -45,7 +46,7 @@ export async function getInfo({ token }: GetInfo): Promise { const res = await getData({ Target: oTokenAddress, Action: "Info", - }); + }, config); const tagsObject = Object.fromEntries( res.Messages[0].Tags.map((tag: Tag) => [ diff --git a/src/functions/oTokenData/getPosition.ts b/src/functions/oTokenData/getPosition.ts index c2a8cc99..1130ed7c 100644 --- a/src/functions/oTokenData/getPosition.ts +++ b/src/functions/oTokenData/getPosition.ts @@ -1,6 +1,7 @@ import { getData } from "../../ao/messaging/getData"; import { TokenInput, tokenInput } from "../../ao/utils/tokenInput"; import { convertTicker } from "../../ao/utils/tokenAddressData"; +import { Services } from "../../ao/utils/connect"; export interface GetPosition { token: TokenInput; @@ -24,7 +25,7 @@ interface Tag { export async function getPosition({ token, recipient, -}: GetPosition): Promise { +}: GetPosition, config?: Services): Promise { try { if (!token || !recipient) { throw new Error("Please specify a token and recipient."); @@ -36,7 +37,7 @@ export async function getPosition({ Target: oTokenAddress, Action: "Position", ...(recipient && { Recipient: recipient }), - }); + }, config); const tagsObject = Object.fromEntries( res.Messages[0].Tags.map((tag: Tag) => [tag.name, tag.value]), diff --git a/src/functions/oTokenData/getSupplyAPR.ts b/src/functions/oTokenData/getSupplyAPR.ts index f5ff4dd8..92572a92 100644 --- a/src/functions/oTokenData/getSupplyAPR.ts +++ b/src/functions/oTokenData/getSupplyAPR.ts @@ -3,6 +3,7 @@ import { TokenInput, tokenInput } from "../../ao/utils/tokenInput"; import { getBorrowAPR, GetBorrowAPRRes } from "./getBorrowAPR"; import { getInfo, GetInfoRes } from "./getInfo"; import { dryRunAwait } from "../../ao/utils/dryRunAwait"; +import { Services } from "../../ao/utils/connect"; export interface GetSupplyAPR { token: TokenInput; @@ -16,14 +17,14 @@ export async function getSupplyAPR({ token, getInfoRes, getBorrowAPRRes, -}: GetSupplyAPR): Promise { +}: GetSupplyAPR, config?: Services): Promise { try { if (!token) { throw new Error("Please specify a token."); } if (!getBorrowAPRRes) { - getBorrowAPRRes = await getBorrowAPR({ token }); + getBorrowAPRRes = await getBorrowAPR({ token }, config); // add await for 1 second due to double dry run request await dryRunAwait(1); } @@ -35,7 +36,7 @@ export async function getSupplyAPR({ throw new Error("getInfoRes supplied does not match token supplied."); } if (!getInfoRes) { - getInfoRes = await getInfo({ token }); + getInfoRes = await getInfo({ token }, config); } const { totalBorrows, collateralDenomination, reserveFactor, totalSupply } = diff --git a/src/functions/protocolData/getAllPositions.ts b/src/functions/protocolData/getAllPositions.ts index aaceb246..77cfa907 100644 --- a/src/functions/protocolData/getAllPositions.ts +++ b/src/functions/protocolData/getAllPositions.ts @@ -1,4 +1,5 @@ import { getData } from "../../ao/messaging/getData"; +import { Services } from "../../ao/utils/connect"; import { TokenInput, tokenInput } from "../../ao/utils/tokenInput"; export interface GetAllPositions { @@ -16,7 +17,7 @@ export interface GetAllPositionsRes { export async function getAllPositions({ token, -}: GetAllPositions): Promise { +}: GetAllPositions, config?: Services): Promise { try { if (!token) { throw new Error("Please specify a token."); @@ -27,7 +28,7 @@ export async function getAllPositions({ const res = await getData({ Target: oTokenAddress, Action: "Positions", - }); + }, config); const allPositions = JSON.parse(res.Messages[0].Data); diff --git a/src/functions/protocolData/getHistoricalAPR.ts b/src/functions/protocolData/getHistoricalAPR.ts index 670a26a3..b85f2bce 100644 --- a/src/functions/protocolData/getHistoricalAPR.ts +++ b/src/functions/protocolData/getHistoricalAPR.ts @@ -1,6 +1,7 @@ import { getData } from "../../ao/messaging/getData"; import { TokenInput, tokenInput } from "../../ao/utils/tokenInput"; import { APRAgentAddress } from "../../ao/utils/tokenAddressData"; +import { Services } from "../../ao/utils/connect"; export interface GetHistoricalAPR { token: TokenInput; @@ -17,7 +18,7 @@ interface APR { export async function getHistoricalAPR({ token, fillGaps = true, -}: GetHistoricalAPR): Promise { +}: GetHistoricalAPR, config?: Services): Promise { try { if (!token) { throw new Error("Please specify a token."); @@ -30,7 +31,7 @@ export async function getHistoricalAPR({ Action: "Get-Data", Token: oTokenAddress, "Fill-Gaps": fillGaps.toString(), - }); + }, config); if (!response.Messages?.[0]?.Data) { const errorTag = response.Messages[0].Tags.find( diff --git a/src/functions/utils/getBalance.ts b/src/functions/utils/getBalance.ts index 117832bf..d8f3016f 100644 --- a/src/functions/utils/getBalance.ts +++ b/src/functions/utils/getBalance.ts @@ -1,4 +1,5 @@ import { Token, Quantity } from "ao-tokens"; +import { getInfo } from "../oTokenData/getInfo"; export interface GetBalance { tokenAddress: string; diff --git a/src/functions/utils/getPrice.ts b/src/functions/utils/getPrice.ts index 49ef7f92..4748c7d2 100644 --- a/src/functions/utils/getPrice.ts +++ b/src/functions/utils/getPrice.ts @@ -6,6 +6,7 @@ import { } from "../../ao/utils/tokenAddressData"; import { redstoneOracleAddress } from "../../ao/utils/tokenAddressData"; import { RedstonePrices } from "../liquidations/getLiquidations"; +import { Services } from "../../ao/utils/connect"; export interface GetPrice { token: TokenInput | string; @@ -13,7 +14,7 @@ export interface GetPrice { export type GetPriceRes = number; -export async function getPrice({ token }: GetPrice): Promise { +export async function getPrice({ token }: GetPrice, config?: Services): Promise { if (!token) { throw new Error("Please specify a token."); } @@ -24,7 +25,7 @@ export async function getPrice({ token }: GetPrice): Promise { Target: redstoneOracleAddress, Action: "v2.Request-Latest-Data", Tickers: JSON.stringify([convertTicker(token)]), - }); + }, config); const prices: RedstonePrices = JSON.parse( redstonePriceFeedRes.Messages[0].Data, diff --git a/src/index.ts b/src/index.ts index 4ed0beb2..ca02d403 100644 --- a/src/index.ts +++ b/src/index.ts @@ -189,11 +189,11 @@ class LiquidOps { } async getLiquidationsMap(): Promise { - return getLiquidationsMap(); + return getLiquidationsMap(this.configs); } async getLiquidations(): Promise { - return getLiquidations(LiquidOps.liquidationPrecisionFactor); + return getLiquidations(LiquidOps.liquidationPrecisionFactor, this.configs); } async liquidate(params: Liquidate): Promise { @@ -202,49 +202,49 @@ class LiquidOps { //--------------------------------------------------------------------------------------------------------------- oTokenData async getBalances(params: GetBalances): Promise { - return getBalances(params); + return getBalances(params, this.configs); } async getBorrowAPR(params: GetBorrowAPR): Promise { - return getBorrowAPR(params); + return getBorrowAPR(params, this.configs); } async getCooldown(params: GetCooldown): Promise { - return getCooldown(params); + return getCooldown(params, this.configs); } async getExchangeRate(params: GetExchangeRate): Promise { - return getExchangeRate(params); + return getExchangeRate(params, this.configs); } async getGlobalPosition( params: GetGlobalPosition, ): Promise { - return getGlobalPosition(params); + return getGlobalPosition(params, this.configs); } async getInfo(params: GetInfo): Promise { - return getInfo(params); + return getInfo(params, this.configs); } async getPosition(params: GetPosition): Promise { - return getPosition(params); + return getPosition(params, this.configs); } async getSupplyAPR(params: GetSupplyAPR): Promise { - return getSupplyAPR(params); + return getSupplyAPR(params, this.configs); } //--------------------------------------------------------------------------------------------------------------- protocolData async getAllPositions(params: GetAllPositions): Promise { - return getAllPositions(params); + return getAllPositions(params, this.configs); } async getHistoricalAPR( params: GetHistoricalAPR, ): Promise { - return getHistoricalAPR(params); + return getHistoricalAPR(params, this.configs); } //--------------------------------------------------------------------------------------------------------------- utils @@ -254,7 +254,7 @@ class LiquidOps { } async getPrice(params: GetPrice): Promise { - return getPrice(params); + return getPrice(params, this.configs); } async getResult(params: GetResult): Promise { From c325d1e1dec22d9628d9909b618b286c44d1801a Mon Sep 17 00:00:00 2001 From: Marton Lederer Date: Fri, 29 Aug 2025 17:07:33 +0200 Subject: [PATCH 3/4] chore: version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 97a3cf27..7c7f0c40 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "liquidops", - "version": "1.2.20", + "version": "1.2.21", "author": "Lorimer Jenkins , Marton Lederer ", "repository": { "type": "git", From 569f41cffaf50cdb327945e068e2d95d8d604778 Mon Sep 17 00:00:00 2001 From: Marton Lederer Date: Fri, 29 Aug 2025 17:09:23 +0200 Subject: [PATCH 4/4] fix: config --- src/functions/liquidations/getLiquidations.ts | 2 +- src/functions/liquidations/getLiquidationsMap.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/functions/liquidations/getLiquidations.ts b/src/functions/liquidations/getLiquidations.ts index e33f3562..c4bcade3 100644 --- a/src/functions/liquidations/getLiquidations.ts +++ b/src/functions/liquidations/getLiquidations.ts @@ -80,7 +80,7 @@ export async function getLiquidations( let positions: GetAllPositionsRes | null = null; for (let attempt = 1; attempt <= maxRetries; attempt++) { try { - positions = await getAllPositions({ token }); + positions = await getAllPositions({ token }, config); // add dry run await to not get rate limited await dryRunAwait(1); break; // Success, exit retry loop diff --git a/src/functions/liquidations/getLiquidationsMap.ts b/src/functions/liquidations/getLiquidationsMap.ts index 7676205d..5825772a 100644 --- a/src/functions/liquidations/getLiquidationsMap.ts +++ b/src/functions/liquidations/getLiquidationsMap.ts @@ -60,7 +60,7 @@ export async function getLiquidationsMap(config?: Services): Promise