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

Auction RPC's #306

Merged
merged 3 commits into from
Jul 17, 2024
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
6 changes: 6 additions & 0 deletions .changeset/brave-masks-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@polkadex/polkadex-api": minor
"@polkadex/types": minor
---

Added RPC for placing a bid and fetching auction info
5 changes: 5 additions & 0 deletions packages/polkadex-api/src/modules/ocex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,9 @@ describe("OCEX modules testing", () => {
expect(res.meta.name.toJSON()).toBe("remove_proxy_account");
}
);

test("Get Auction Info", { timeout: 100000 }, async () => {
const res = await ocex.auctionInfo();
expectTypeOf(res.highestBid).toBeNumber();
});
});
42 changes: 40 additions & 2 deletions packages/polkadex-api/src/modules/ocex.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { SubmittableExtrinsic } from "@polkadot/api/promise/types";
import { PolkadexPrimitivesOcexAccountInfo } from "@polkadex/types";
import { toPlanck } from "@polkadex/numericals";
import {
PolkadexPrimitivesOcexAccountInfo,
PolkadexPrimitivesAuctionAuctionInfo,
} from "@polkadex/types";
import { toPlanck, toUnit } from "@polkadex/numericals";

import { AuctionInfo } from "../types";

import { BalancesApi } from "./balances";

Expand Down Expand Up @@ -48,4 +53,37 @@ export class OcexApi extends BalancesApi {
const amt = toPlanck(amount, decimals);
return this.api.tx.ocex.deposit(asset, amt.toFixed(0));
}

// TODO: Need to test this when backend is upgraded
// Place an anuction bid
public async placeAuctionBid(amount: number): Promise<SubmittableExtrinsic> {
await this.initApi();
// transform amount decimals into usable form
const decimals = this.chainDecimals;
const amt = toPlanck(amount, decimals);
return this.api.tx.ocex.placeBid(amt.toFixed(0));
}

// Fetch current auction info
public async auctionInfo(): Promise<AuctionInfo> {
await this.initApi();

const decimals = this.chainDecimals;
const auctionInfo = (
await this.api.query?.ocex?.auction()
)?.toJSON() as unknown as PolkadexPrimitivesAuctionAuctionInfo;

if (!auctionInfo) return {} as AuctionInfo;

const feeInfo: AuctionInfo["feeInfo"] = {};
for (const itr of Object.entries(auctionInfo.feeInfo)) {
const amt = toUnit(itr[1], decimals);
feeInfo[itr[0]] = amt.toNumber();
}
return {
feeInfo,
highestBid: auctionInfo.highestBid,
highestBidder: auctionInfo.highestBidder,
};
}
}
7 changes: 7 additions & 0 deletions packages/polkadex-api/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AccountId } from "@polkadot/types/interfaces";
import { DefinitionsCall } from "@polkadot/types/types";

export enum AssetType {
Expand All @@ -12,6 +13,12 @@ export type Asset = {
network: AssetType;
};

export type AuctionInfo = {
feeInfo: { [key: string]: number };
highestBidder: AccountId | null;
highestBid: number;
};

export const runtimeTypes = {
AssetId: {
_enum: {
Expand Down
6 changes: 6 additions & 0 deletions packages/types/src/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,9 @@ export interface LMPEpochConfig extends Struct {
maxAccountsRewarded: u16;
claimSafetyPeriod: u16;
}

export interface PolkadexPrimitivesAuctionAuctionInfo extends Struct {
feeInfo: { [key: string]: string };
highestBidder: AccountId | null;
highestBid: number;
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16045,10 +16045,10 @@ vary@~1.1.2:
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
integrity sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==

vaul@^0.8.0:
version "0.8.9"
resolved "https://registry.yarnpkg.com/vaul/-/vaul-0.8.9.tgz#0b6e4771dbd0e8e330b3c4b0415d4fd15cd47e9b"
integrity sha512-gpmtmZRWDPP6niQh14JfRIFUYZVyfvAWyA/7rUINOfNlO/2K7uEvI5rLXEXkxZIRFyUZj+TPHLFMirkegPHjrw==
vaul@^0.9.1:
version "0.9.1"
resolved "https://registry.yarnpkg.com/vaul/-/vaul-0.9.1.tgz#3640198e04636b209b1f907fcf3079bec6ecc66b"
integrity sha512-fAhd7i4RNMinx+WEm6pF3nOl78DFkAazcN04ElLPFF9BMCNGbY/kou8UMhIcicm0rJCNePJP0Yyza60gGOD0Jw==
dependencies:
"@radix-ui/react-dialog" "^1.0.4"

Expand Down
Loading