Anchor-Protocol / anchor.js

The JavaScript SDK for Anchor Protocol

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect return annotation on `queryLiquidationQueueBidPoolsByCollateral`

davidvuong opened this issue · comments

Currently:

interface Option {
    lcd: LCDClient;
    collateral_token: string;
    start_after: number | undefined;
    limit: number | undefined;
}
export interface BidPoolResponse {
    sum_snapshot: string;
    product_snapshot: string;
    total_bid_amount: string;
    premium_rate: string;
    current_epoch: string;
    current_scale: string;
}
export declare const queryLiquidationQueueBidPoolsByCollateral: ({ lcd, collateral_token, start_after, limit }: Option) => (addressProvider: AddressProvider) => Promise<BidPoolResponse[]>;

The return type of queryLiquidationQueueBidPoolsByCollateral should be:

export interface BidPoolsByCollateralResponse {
  bid_pools: BidPoolResponse[]
}

Version:

"@anchor-protocol/anchor.js": "^5.0.2"

Documentation: https://docs.anchorprotocol.com/smart-contracts/liquidations/liquidation-queue-contract#bidpoolsbycollateralresponse

Example response in documentation:

{
  "bid_pools": [
    {
      "sum_snapshot": "1.0",
      "product_snapshot": "1.0",
      "total_bid_amount": "1000000",
      "premium_rate": "0.1",
      "current_epoch": "0",
      "current_scale": "0"
    }, 
    {
      "sum_snapshot": "1.0",
      "product_snapshot": "1.0",
      "total_bid_amount": "2000000",
      "premium_rate": "0.2",
      "current_epoch": "0",
      "current_scale": "0"
    }
  ]
}

Similarly, the same problem exists for queryLiquidationQueueBidByUser.

export interface QueueBidResponse {
    idx: string;
    collateral_token: string;
    premium_slot: number;
    bidder: string;
    amount: string;
    product_snapshot: string;
    sum_snapshot: string;
    pending_liquidated_collateral: string;
    wait_end: number | undefined;
    epoch_snapshot: string;
    scale_snapshot: string;
}

export declare const queryLiquidationQueueBidByUser: ({ lcd, collateral_token, bidder, start_after, limit }: Option) => (addressProvider: AddressProvider) => Promise<QueueBidResponse[]>;

When the actual response is:

{
  bids: [
    {
      idx: '1694',
      collateral_token: 'terra...',
      premium_slot: 30,
      bidder: 'terra...',
      amount: '24771388',
      product_snapshot: '1',
      sum_snapshot: '0',
      pending_liquidated_collateral: '0',
      wait_end: 1649910621,
      epoch_snapshot: '0',
      scale_snapshot: '0'
    }
  ]
}

So the response type should be wrapped. A temporary solution is:

const { bids } = (await queryLiquidationQueueBidByUser({
  lcd: this.lcd,
  collateral_token: collateral,
  bidder: wallet.key.accAddress,
  start_after: undefined,
  limit: PAGINATION_LIMIT,
})(this.addressProvider)) as unknown as { bids: QueueBidResponse[] };