Skip to content

Commit

Permalink
feat(limit-order-rfq): util for create,fill,cancel limit order RFQ
Browse files Browse the repository at this point in the history
npm run rfq-utils
  • Loading branch information
shoom3301 committed Jun 8, 2021
1 parent b4a670e commit aa61ed2
Show file tree
Hide file tree
Showing 8 changed files with 432 additions and 5 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@
"prettier": "prettier --write .",
"make-badges": "istanbul-badges-readme",
"ci-pipeline": "yarn run lint && yarn run test && yarn run typecheck",
"set-npm-auth": "echo \"//npm.pkg.github.com/:_authToken=${NPM_AUTH_TOKEN}\" >> .npmrc"
"set-npm-auth": "echo \"//npm.pkg.github.com/:_authToken=${NPM_AUTH_TOKEN}\" >> .npmrc",
"rfq-utils": "ts-node --project tsconfig.scripts.json ./src/utils/limit-order-rfq.utils.ts"
},
"dependencies": {
"@ethersproject/bignumber": "^5.1.1",
"eth-sig-util": "^3.0.1",
"prompts": "^2.4.1",
"web3": "^2.0.0-alpha.1"
},
"devDependencies": {
"@babel/core": "^7.13.16",
"@babel/preset-env": "^7.13.15",
"@babel/preset-typescript": "^7.13.0",
"@types/jest": "^26.0.22",
"@types/prompts": "^2.0.12",
"@typescript-eslint/eslint-plugin": "4",
"babel-jest": "^26.6.3",
"eslint": "7",
Expand Down
1 change: 1 addition & 0 deletions src/model/limit-order-protocol.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {LimitOrderPredicateCallData} from '../limit-order-predicate.builder';
export enum ChainId {
etherumMainnet = 1,
binanceMainnet = 56,
polygonMainnet = 137,
}

export type LimitOrderSignature = string;
Expand Down
133 changes: 133 additions & 0 deletions src/utils/limit-order-rfq.const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import {PromptObject} from 'prompts';
import {ChainId} from '../model/limit-order-protocol.model';

const commonProperties: PromptObject[] = [
{
type: 'select',
name: 'chainId',
message: 'Select network',
choices: [
{title: 'Ethereum', value: ChainId.etherumMainnet},
{title: 'BSC', value: ChainId.binanceMainnet},
{title: 'Polygon', value: ChainId.polygonMainnet},
],
},
{
type: 'password',
name: 'privateKey',
message: 'Enter your private key',
},
];

export const operationSchema: PromptObject[] = [
{
type: 'select',
name: 'operation',
choices: [
{title: 'create', value: 'create'},
{title: 'fill', value: 'fill'},
{title: 'cancel', value: 'cancel'},
],
message: 'Choose operation for limit order RFQ: create, fill, cancel',
},
];

export const createOrderSchema: PromptObject[] = [
...commonProperties,
{
type: 'number',
name: 'orderId',
message: 'Limit order RFQ id',
},
{
type: 'number',
name: 'expiresIn',
message:
'Expires in (seconds, for example: 300 - order will expired in 5 mins)',
initial: 300,
},
{
type: 'text',
name: 'makerAssetAddress',
message: 'Maker asset address',
},
{
type: 'text',
name: 'takerAssetAddress',
message: 'Taker asset address',
},
{
type: 'text',
name: 'makerAmount',
message: 'Maker asset amount',
},
{
type: 'text',
name: 'takerAmount',
message: 'Taker asset amount',
},
{
type: 'text',
name: 'takerAddress',
message: 'Taker address (optional)',
},
];

export const fillOrderSchema: PromptObject[] = [
...commonProperties,
{
type: 'number',
name: 'gasPrice',
message: 'Gas price (GWEI)',
initial: 10,
},
{
type: 'text',
name: 'order',
message: 'Limit order RFQ json',
},
{
type: 'text',
name: 'makerAmount',
message:
'Maker asset fill amount (set 0 if you will use taker asset amount)',
},
{
type: 'text',
name: 'takerAmount',
message: 'Taker asset amount (set 0 if has set maker asset amount)',
},
];

export const cancelOrderSchema: PromptObject[] = [
...commonProperties,
{
type: 'number',
name: 'gasPrice',
message: 'Gas price (GWEI)',
initial: 10,
},
{
type: 'text',
name: 'orderInfo',
message: 'Order info',
},
];

export const rpcUrls: {[key: number]: string} = {
[ChainId.etherumMainnet]: 'https://web3-node.1inch.exchange',
[ChainId.binanceMainnet]: 'https://bsc-dataseed.binance.org',
[ChainId.polygonMainnet]: 'https://bor-nodes.1inch.exchange',
};

export const contractAddresses: {[key: number]: string} = {
[ChainId.etherumMainnet]: '0x3ef51736315f52d568d6d2cf289419b9cfffe782',
[ChainId.binanceMainnet]: '0xe3456f4ee65e745a44ec3bcb83d0f2529d1b84eb',
[ChainId.polygonMainnet]: '0xb707d89d29c189421163515c59e42147371d6857',
};

export const explorersUrls: {[key: number]: string} = {
[ChainId.etherumMainnet]: 'https://etherscan.io',
[ChainId.binanceMainnet]: 'https://bscscan.com',
[ChainId.polygonMainnet]: 'https://explorer-mainnet.maticvigil.com',
};
31 changes: 31 additions & 0 deletions src/utils/limit-order-rfq.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export interface CreatingParams {
chainId: number;
privateKey: string;
orderId: number;
expiresIn: number;
makerAssetAddress: string;
takerAssetAddress: string;
makerAmount: string;
takerAmount: string;
takerAddress: string;
}

export interface FillingParams {
chainId: number;
privateKey: string;
gasPrice: number;
order: string;
makerAmount: string;
takerAmount: string;
}

export interface CancelingParams {
chainId: number;
privateKey: string;
gasPrice: number;
orderInfo: string;
}

export interface OperationParams {
operation: string;
}
Loading

0 comments on commit aa61ed2

Please sign in to comment.