Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
mshrieve committed Oct 26, 2023
1 parent 1dd5d7f commit bda9de0
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 29 deletions.
2 changes: 1 addition & 1 deletion examples/approveAllowances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dotenvConfig({ path: resolve(__dirname, "../.env") });
export function getWallet(mainnetQ: boolean): ethers.Wallet {
const pk = process.env.PK as string;
const rpcToken: string = process.env.RPC_TOKEN as string;
let rpcUrl: string = "";
let rpcUrl = "";
if (mainnetQ) {
rpcUrl = `https://polygon-mainnet.g.alchemy.com/v2/${rpcToken}`;
} else {
Expand Down
2 changes: 1 addition & 1 deletion examples/geoToken.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ethers } from "ethers";
import { config as dotenvConfig } from "dotenv";
import { resolve } from "path";
import { ApiKeyCreds, Chain, ClobClient, PriceHistoryInterval, Side } from "../src";
import { ApiKeyCreds, Chain, ClobClient, Side } from "../src";

dotenvConfig({ path: resolve(__dirname, "../.env") });

Expand Down
22 changes: 18 additions & 4 deletions examples/signatureTypes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ethers } from "ethers";
import { config as dotenvConfig } from "dotenv";
import { resolve } from "path";
import { ApiKeyCreds, Chain, ClobClient, Side } from "../src";
import { ApiKeyCreds, Chain, ClobClient } from "../src";
import { SignatureType } from "@polymarket/order-utils";

dotenvConfig({ path: resolve(__dirname, "../.env") });
Expand All @@ -22,12 +22,26 @@ async function main() {
const clobClient = new ClobClient(host, chainId, wallet, creds);

// Client used with a Polymarket Proxy Wallet: Signature type 1
const proxyWalletAddress = "0x...";
const polyProxyClient = new ClobClient(host, chainId, wallet, creds, SignatureType.POLY_PROXY, proxyWalletAddress);
const proxyWalletAddress = "0x...";
const polyProxyClient = new ClobClient(
host,
chainId,
wallet,
creds,
SignatureType.POLY_PROXY,
proxyWalletAddress,
);

// Client used with a Polymarket Gnosis safe: Signature Type 2
const gnosisSafeAddress = "0x...";
const polyGnosisSafeClient = new ClobClient(host, chainId, wallet, creds, SignatureType.POLY_GNOSIS_SAFE, gnosisSafeAddress)
const polyGnosisSafeClient = new ClobClient(
host,
chainId,
wallet,
creds,
SignatureType.POLY_GNOSIS_SAFE,
gnosisSafeAddress,
);
}

main();
14 changes: 7 additions & 7 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {
ApiKeyCreds,
ApiKeysResponse,
Chain,
CreateOrderOptions,
MarketPrice,
OpenOrderParams,
OpenOrdersResponse,
OrderMarketCancelParams,
OrderBookSummary,
OrderOptions,
OrderPayload,
OrderType,
Side,
Expand Down Expand Up @@ -419,14 +419,14 @@ export class ClobClient {

public async createOrder(
userOrder: UserOrder,
orderOptions?: Partial<OrderOptions>,
options?: Partial<CreateOrderOptions>,
): Promise<SignedOrder> {
this.canL1Auth();

const { tokenID } = userOrder;

const tickSize = await this._resolveTickSize(tokenID, orderOptions?.tickSize);
const negRisk = orderOptions?.negRisk ?? false;
const tickSize = await this._resolveTickSize(tokenID, options?.tickSize);
const negRisk = options?.negRisk ?? false;

return this.orderBuilder.buildOrder(userOrder, {
tickSize,
Expand All @@ -436,14 +436,14 @@ export class ClobClient {

public async createMarketBuyOrder(
userMarketOrder: UserMarketOrder,
orderOptions?: OrderOptions,
options?: CreateOrderOptions,
): Promise<SignedOrder> {
this.canL1Auth();

const { tokenID } = userMarketOrder;

const tickSize = await this._resolveTickSize(tokenID, orderOptions?.tickSize);
const negRisk = orderOptions?.negRisk ?? false;
const tickSize = await this._resolveTickSize(tokenID, options?.tickSize);
const negRisk = options?.negRisk ?? false;

if (!userMarketOrder.price) {
const marketPrice = await this.getPrice(tokenID, Side.BUY);
Expand Down
10 changes: 5 additions & 5 deletions src/order-builder/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Wallet } from "@ethersproject/wallet";
import { JsonRpcSigner } from "@ethersproject/providers";
import { SignedOrder, SignatureType } from "@polymarket/order-utils";
import { createMarketBuyOrder, createOrder } from "./helpers";
import { Chain, OrderOptions, UserMarketOrder, UserOrder } from "../types";
import { Chain, CreateOrderOptions, UserMarketOrder, UserOrder } from "../types";

export class OrderBuilder {
readonly signer: Wallet | JsonRpcSigner;
Expand Down Expand Up @@ -34,15 +34,15 @@ export class OrderBuilder {
*/
public async buildOrder(
userOrder: UserOrder,
orderOptions: OrderOptions,
options: CreateOrderOptions,
): Promise<SignedOrder> {
return createOrder(
this.signer,
this.chainId,
this.signatureType,
this.funderAddress,
userOrder,
orderOptions,
options,
);
}

Expand All @@ -51,15 +51,15 @@ export class OrderBuilder {
*/
public async buildMarketOrder(
userMarketOrder: UserMarketOrder,
orderOptions: OrderOptions,
options: CreateOrderOptions,
): Promise<SignedOrder> {
return createMarketBuyOrder(
this.signer,
this.chainId,
this.signatureType,
this.funderAddress,
userMarketOrder,
orderOptions,
options,
);
}
}
18 changes: 9 additions & 9 deletions src/order-builder/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import {
UserMarketOrder,
TickSize,
RoundConfig,
OrderOptions,
} from "../types";
import { decimalPlaces, roundDown, roundNormal, roundUp } from "../utilities";
CreateOrderOptions,
} from "src/types";
import { decimalPlaces, roundDown, roundNormal, roundUp } from "src/utilities";
import {
COLLATERAL_TOKEN_DECIMALS,
CONDITIONAL_TOKEN_DECIMALS,
Expand Down Expand Up @@ -172,20 +172,20 @@ export const createOrder = async (
signatureType: SignatureType,
funderAddress: string | undefined,
userOrder: UserOrder,
orderOptions: OrderOptions,
options: CreateOrderOptions,
): Promise<SignedOrder> => {
const eoaSignerAddress = await eoaSigner.getAddress();

// If funder address is not given, use the signer address
const maker = funderAddress === undefined ? eoaSignerAddress : funderAddress;
const contractConfig = getContractConfig(chainId, orderOptions.negRisk);
const contractConfig = getContractConfig(chainId, options.negRisk);

const orderData = await buildOrderCreationArgs(
eoaSignerAddress,
maker,
signatureType,
userOrder,
ROUNDING_CONFIG[orderOptions.tickSize],
ROUNDING_CONFIG[options.tickSize],
);
return buildOrder(eoaSigner, contractConfig.exchange, chainId, orderData);
};
Expand Down Expand Up @@ -274,20 +274,20 @@ export const createMarketBuyOrder = async (
signatureType: SignatureType,
funderAddress: string | undefined,
userMarketOrder: UserMarketOrder,
orderOptions: OrderOptions,
options: CreateOrderOptions,
): Promise<SignedOrder> => {
const eoaSignerAddress = await eoaSigner.getAddress();

// If funder address is not given, use the signer address
const maker = funderAddress === undefined ? eoaSignerAddress : funderAddress;
const contractConfig = getContractConfig(chainId, orderOptions.negRisk);
const contractConfig = getContractConfig(chainId, options.negRisk);

const orderData = await buildMarketBuyOrderCreationArgs(
eoaSignerAddress,
maker,
signatureType,
userMarketOrder,
ROUNDING_CONFIG[orderOptions.tickSize],
ROUNDING_CONFIG[options.tickSize],
);
return buildOrder(eoaSigner, contractConfig.exchange, chainId, orderData);
};
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export interface OrdersScoringParams {

export type OrdersScoring = { [orderId in string]: boolean };

export type OrderOptions = {
export type CreateOrderOptions = {
tickSize: TickSize;
negRisk?: boolean;
};
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "./node_modules", "./node_modules/*"],
"include": ["src/**/*", "tests/**/*.ts"]
"include": ["src/**/*", "tests/**/*.ts", "examples/**/*.ts"]
}

0 comments on commit bda9de0

Please sign in to comment.