diff --git a/README.md b/README.md index 7ba8d96..f26e820 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # pmarket-cli - +[![npm version](https://img.shields.io/npm/v/pmarket-cli)](https://www.npmjs.com/package/pmarket-cli) Command line interface for Polymarket. --- @@ -26,31 +26,43 @@ npm i pmarket-cli -g ## Setup -After successful installation you need to go through four steps in order +After successful installation you need to go through couple of steps in order to place buy and sell orders with the tool. Setup requires editing config.json file which is located under `~/.pmarket-cli/config.json` where `~` is your home directory. 1. You need to generate api key to access polygon network. I recommend using [infura.io](https://www.infura.io/) but you can use any other provider you like [Steps to generate key](https://docs.infura.io/getting-started). - Once you generate the key set rpcProvider value in config.json file to your rpc provider url. + Once you generate the key set `rpcProvider` value in config.json file to your rpc provider url. Url should look something like this: `https://polygon-mainnet.infura.io/v3/your-api-key` -2. Generate your private key and set it in config.json file (privateKey entry). You can use [metamask](https://metamask.io/) to generate private key. [Steps to generate private key](https://metamask.zendesk.com/hc/en-us/articles/360015289632-How-to-Export-an-Account-Private-Key) +2. Generate your metamask wallet private key and set it in config.json file (`privateKey` entry). [Steps to generate private key](https://support.metamask.io/managing-my-wallet/secret-recovery-phrase-and-private-keys/how-to-export-an-accounts-private-key) + +3. Get your `funderAddress` from polymarket app (The one next to your public profile on polymarket app) -3. You will need to generate an api key for polymarket. You can do this by running the following command: +4. You will need to generate an api key for polymarket. You can do this by running the following command: ```shell pmarket-cli -k ``` -Take values from the response and set them in config.json file (apiKey, apiSecret and passphrase entries). +Take values from the response and set them in config.json file (`apiKey`, `apiSecret` and `passphrase` entries). -4. Set allowance for CTFExchange contract. You can do this by running the following command. This will allow CTFExchange contract to spend your USDC tokens. +5. Set allowance for CTFExchange contract. You can do this by running the following command. This will allow CTFExchange contract to spend your USDC tokens. ```shell pmarket-cli -a 500 ``` -After all 4 steps your config.json file should have all entries filled with values. +After all 5 steps your config.json file should have all entries filled with values. +``` +{ + "apiKey": "apiKey",(step 4) + "apiSecret": "apiSecret",(step 4) + "passphrase": "passphrase",(step 4) + "rpcProvider": "https://polygon-mainnet.infura.io/v3/your-api-key", (step 1) + "privateKey": "your-metamask-wallet-private-key",(step 2) + "funderAddress": "funderAddressFromPolymarketApp" (step 3) +} +``` --- @@ -61,7 +73,7 @@ After all 4 steps your config.json file should have all entries filled with valu Command ```shell -pmarket-cli -l "Will Trump attend the first RNC debate?" +pmarket-cli -l "Oscar" ``` Response @@ -69,15 +81,214 @@ Response ```shell [ { - token_0: { - token_id: '12110463059584809904811790486163860991533989713640269122405796144537637099628', - outcome: 'Yes' + yes: { + token_id: '32690616433410387308307813339600971589831744601462134742731346664328487681674', + outcome: 'Yes', + price: 0.645, + winner: false + }, + no: { + token_id: '93520364131545158991271066783085167796254018656458248205265557269588037162187', + outcome: 'No', + price: 0.355, + winner: false + }, + question: "Will 'Sing Sing' be nominated for Oscar for Best Picture?" + }, + { + yes: { + token_id: '100401097213549719544430330089381355980751133453267218243446808652190404553676', + outcome: 'Yes', + price: 0.625, + winner: false + }, + no: { + token_id: '5399213552646241399758526346963923893707773966118900537360111893113091092777', + outcome: 'No', + price: 0.375, + winner: false + }, + question: "Will 'A Real Pain' be nominated for Oscar for Best Picture?" + }, + { + yes: { + token_id: '96640869691532587244570283302780466327078472971610770069097941773703286390027', + outcome: 'Yes', + price: 0.981, + winner: false + }, + no: { + token_id: '67931077130043942518483022378076251176956266677865613007855881895832314338989', + outcome: 'No', + price: 0.019, + winner: false + }, + question: "Will 'Emilia Perez' be nominated for Oscar for Best Picture?" + }, + { + yes: { + token_id: '71253205524417391866208339119597974189550792786476743396831705495855112450492', + outcome: 'Yes', + price: 0.315, + winner: false + }, + no: { + token_id: '16882157695214605799133873002564430339850918902933529749045793413918741191752', + outcome: 'No', + price: 0.685, + winner: false + }, + question: "Will 'September 5' be nominated for Oscar for Best Picture?" + }, + { + yes: { + token_id: '111738901907809443600037910023684478622915124934957230261829398758881989293766', + outcome: 'Yes', + price: 0.09, + winner: false + }, + no: { + token_id: '33976536607797914371585069047396561557527874165898480435138330747945477786512', + outcome: 'No', + price: 0.91, + winner: false + }, + question: "Will 'Blitz' be nominated for Oscar for Best Picture?" + }, + { + yes: { + token_id: '17141600067691573577485747775118635864925506414161610505761549736848495519363', + outcome: 'Yes', + price: 0.545, + winner: false + }, + no: { + token_id: '101962157253245690493877071168263866510465623662446987356042737166417606798256', + outcome: 'No', + price: 0.455, + winner: false + }, + question: "Will 'A Complete Unknown' be nominated for Oscar for Best Picture?" + }, + { + yes: { + token_id: '90992535272147567931508137629092419903145779789552007385817623243259081817819', + outcome: 'Yes', + price: 0.625, + winner: false }, - token_1: { - token_id: '29339358161683554702930216891507179890535004654000050338417989709558351328832', - outcome: 'No' + no: { + token_id: '112050965724963176646680630632767812634280014319419640668361967417736052131131', + outcome: 'No', + price: 0.375, + winner: false + }, + question: "Will 'The Substance' be nominated for Oscar for Best Picture?" + }, + { + yes: { + token_id: '11401947330912495336075989162259552620335030712684952206022571276421308445194', + outcome: 'Yes', + price: 0.575, + winner: false + }, + no: { + token_id: '71405501953515250392036436688816920605059194883228676237741391871754267694223', + outcome: 'No', + price: 0.425, + winner: false + }, + question: "Will 'Nickel Boys' be nominated for Oscar for Best Picture?" + }, + { + yes: { + token_id: '104687854183071741371695044459492858385023155729056052792472869008359784070851', + outcome: 'Yes', + price: 0.155, + winner: false + }, + no: { + token_id: '95256566383480312433988451491253310710707233915223521570088402500343648576289', + outcome: 'No', + price: 0.845, + winner: false + }, + question: "Will 'The Seed of the Sacred Fig' be nominated for Oscar for Best Picture?" + }, + { + yes: { + token_id: '106124606603253014598710528659186278479494442996460010129243257316537903936557', + outcome: 'Yes', + price: 0.095, + winner: false }, - question: 'Will Trump attend the first RNC debate?' + no: { + token_id: '42392241498764529227049798458044618986039872101558312093943861400630136579252', + outcome: 'No', + price: 0.905, + winner: false + }, + question: "Will 'Challengers' be nominated for Oscar for Best Picture?" + }, + { + yes: { + token_id: '70107851796254851256550131323680162861915303716570160476164262541864168848203', + outcome: 'Yes', + price: 0.175, + winner: false + }, + no: { + token_id: '91129262031415306337846861683941945267499438177680407919369102453214763879537', + outcome: 'No', + price: 0.825, + winner: false + }, + question: "Will 'Nosferatu' be nominated for Oscar for Best Picture?" + }, + { + yes: { + token_id: '24407508819234282464933075570576262820711040241472859810696604181515136132297', + outcome: 'Yes', + price: 0.12, + winner: false + }, + no: { + token_id: '20077393403763790363624979235978091595345440602923095023242303408941046675470', + outcome: 'No', + price: 0.88, + winner: false + }, + question: "Will 'The Piano Lesson' be nominated for Oscar for Best Picture?" + }, + { + yes: { + token_id: '99736097289508014861057174585239840739129795025185531876280544252158499243638', + outcome: 'Yes', + price: 0.06, + winner: false + }, + no: { + token_id: '1880131924389797790288814877967953731284212787573623296031594534223744445027', + outcome: 'No', + price: 0.94, + winner: false + }, + question: "Will 'A Different Man' be nominated for Oscar for Best Picture?" + }, + { + yes: { + token_id: '41194420579853832111792943550797230648479286191062857764566839803695954154898', + outcome: 'Yes', + price: 0.165, + winner: false + }, + no: { + token_id: '6980419307993749449373106703104366839484022772040366571203245278705517294617', + outcome: 'No', + price: 0.835, + winner: false + }, + question: "Will 'Gladiator 2' be nominated for Oscar for Best Picture?" } ] ``` @@ -95,15 +306,98 @@ pmarket-cli -b 12110463059584809904811790486163860991533989713640269122405796144 Response ```shell - { - "success": true, - "errorMsg": "", - "orderID": "0x556d3864c64d851462b2f378f5e6dcec7d31ba1632dfe44bfdcaa3cc685b45cc", - "transactionsHashes": [ - "0x23d3b0f75446128bff33fd750870a1ea03a210de863ed7efd836ab3d18d83609" - ], - "status": "matched" - } +{ + market: '0xe986284ed884732cb82713c2ff601056f092efe785254fa16a4db0abc7e76654', + asset_id: '80686157984042045124111759746605774670542171586147533847217628946080812697410', + timestamp: '1734286970575', + hash: 'bcc5d198def20dcd6d77ac297d362d018afff96b', + bids: [ + { price: '0.014', size: '410.5' }, + { price: '0.015', size: '416.5' }, + { price: '0.022', size: '280' }, + { price: '0.035', size: '300' }, + { price: '0.036', size: '71.57' }, + { price: '0.044', size: '2853.41' }, + { price: '0.051', size: '591.94' }, + { price: '0.058', size: '30' }, + { price: '0.062', size: '85.47' }, + { price: '0.063', size: '146' } + ], + asks: [ + { price: '0.998', size: '8000' }, + { price: '0.987', size: '1500' }, + { price: '0.975', size: '600' }, + { price: '0.97', size: '388' }, + { price: '0.949', size: '300' }, + { price: '0.94', size: '250' }, + { price: '0.93', size: '200' }, + { price: '0.89', size: '125' }, + { price: '0.88', size: '200.44' }, + { price: '0.875', size: '125' }, + { price: '0.87', size: '125' }, + { price: '0.85', size: '100' }, + { price: '0.849', size: '1986' }, + { price: '0.82', size: '120' }, + { price: '0.81', size: '100' }, + { price: '0.8', size: '250' }, + { price: '0.79', size: '254' }, + { price: '0.77', size: '250' }, + { price: '0.76', size: '100' }, + { price: '0.75', size: '100' }, + { price: '0.73', size: '67.25' }, + { price: '0.72', size: '100' }, + { price: '0.7', size: '250.27' }, + { price: '0.69', size: '250.07' }, + { price: '0.68', size: '75' }, + { price: '0.67', size: '100' }, + { price: '0.65', size: '60' }, + { price: '0.64', size: '100' }, + { price: '0.62', size: '147' }, + { price: '0.6', size: '120' }, + { price: '0.59', size: '117.91' }, + { price: '0.58', size: '75' }, + { price: '0.57', size: '192.7' }, + { price: '0.56', size: '250.01' }, + { price: '0.55', size: '50' }, + { price: '0.49', size: '215' }, + { price: '0.48', size: '65' }, + { price: '0.47', size: '107.29' }, + { price: '0.44', size: '45' }, + { price: '0.164', size: '20' }, + { price: '0.115', size: '23' }, + { price: '0.106', size: '91.65' }, + { price: '0.072', size: '210' }, + { price: '0.071', size: '128.2' }, + { price: '0.07', size: '31.47' } + ] +} +BUY +Amount of shares/tokens: 15 +Price0.064 +{ + salt: '881519783809', + maker: '0x74e0D67f659766360E92152ea8c8a935BA89FAbD', + signer: '0x72819b106DBfFD451bbE40ED1e3CE2fBD13CC947', + taker: '0x0000000000000000000000000000000000000000', + tokenId: '80686157984042045124111759746605774670542171586147533847217628946080812697410', + makerAmount: '960000', + takerAmount: '15000000', + expiration: '0', + nonce: '0', + feeRateBps: '0', + side: 0, + signatureType: 2, + signature: '0x4ce2e19f68887725a289be82fc2879dd0e346e1f1d11a8d63579d5ddf236767a08a3f3a0d0da9c831ff98eb0e9e9aaaddbd20f75c4a7e8d7c09dfc9b2eed459c1c' +} +{ + errorMsg: '', + orderID: '0x6f89228a046c2cda1beb604599bda10c6acab735e2d8fdd7208754575f88dae0', + takingAmount: '', + makingAmount: '', + status: 'live', + transactionsHashes: null, + success: true +} ``` diff --git a/dist/main.js b/dist/main.js old mode 100644 new mode 100755 index 72119a2..1f17a72 --- a/dist/main.js +++ b/dist/main.js @@ -1,3 +1,3 @@ #! /usr/bin/env node -(()=>{"use strict";var e={283:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.usdcContractABI=void 0,t.usdcContractABI=[{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"authorizer",type:"address"},{indexed:!0,internalType:"bytes32",name:"nonce",type:"bytes32"}],name:"AuthorizationCanceled",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"authorizer",type:"address"},{indexed:!0,internalType:"bytes32",name:"nonce",type:"bytes32"}],name:"AuthorizationUsed",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"account",type:"address"}],name:"Blacklisted",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"userAddress",type:"address"},{indexed:!1,internalType:"address payable",name:"relayerAddress",type:"address"},{indexed:!1,internalType:"bytes",name:"functionSignature",type:"bytes"}],name:"MetaTransactionExecuted",type:"event"},{anonymous:!1,inputs:[],name:"Pause",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"newRescuer",type:"address"}],name:"RescuerChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"previousAdminRole",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"newAdminRole",type:"bytes32"}],name:"RoleAdminChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"address",name:"account",type:"address"},{indexed:!0,internalType:"address",name:"sender",type:"address"}],name:"RoleGranted",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"address",name:"account",type:"address"},{indexed:!0,internalType:"address",name:"sender",type:"address"}],name:"RoleRevoked",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"account",type:"address"}],name:"UnBlacklisted",type:"event"},{anonymous:!1,inputs:[],name:"Unpause",type:"event"},{inputs:[],name:"APPROVE_WITH_AUTHORIZATION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"BLACKLISTER_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"CANCEL_AUTHORIZATION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"DECREASE_ALLOWANCE_WITH_AUTHORIZATION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"DEFAULT_ADMIN_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"DEPOSITOR_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"DOMAIN_SEPARATOR",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"EIP712_VERSION",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"INCREASE_ALLOWANCE_WITH_AUTHORIZATION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"META_TRANSACTION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"PAUSER_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"PERMIT_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"RESCUER_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"TRANSFER_WITH_AUTHORIZATION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"WITHDRAW_WITH_AUTHORIZATION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"validAfter",type:"uint256"},{internalType:"uint256",name:"validBefore",type:"uint256"},{internalType:"bytes32",name:"nonce",type:"bytes32"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"approveWithAuthorization",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"authorizer",type:"address"},{internalType:"bytes32",name:"nonce",type:"bytes32"}],name:"authorizationState",outputs:[{internalType:"enum GasAbstraction.AuthorizationState",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"blacklist",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"blacklisters",outputs:[{internalType:"address[]",name:"",type:"address[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"authorizer",type:"address"},{internalType:"bytes32",name:"nonce",type:"bytes32"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"cancelAuthorization",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"subtractedValue",type:"uint256"}],name:"decreaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"decrement",type:"uint256"},{internalType:"uint256",name:"validAfter",type:"uint256"},{internalType:"uint256",name:"validBefore",type:"uint256"},{internalType:"bytes32",name:"nonce",type:"bytes32"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"decreaseAllowanceWithAuthorization",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"user",type:"address"},{internalType:"bytes",name:"depositData",type:"bytes"}],name:"deposit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"userAddress",type:"address"},{internalType:"bytes",name:"functionSignature",type:"bytes"},{internalType:"bytes32",name:"sigR",type:"bytes32"},{internalType:"bytes32",name:"sigS",type:"bytes32"},{internalType:"uint8",name:"sigV",type:"uint8"}],name:"executeMetaTransaction",outputs:[{internalType:"bytes",name:"",type:"bytes"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"}],name:"getRoleAdmin",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"uint256",name:"index",type:"uint256"}],name:"getRoleMember",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"}],name:"getRoleMemberCount",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"grantRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"hasRole",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"addedValue",type:"uint256"}],name:"increaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"increment",type:"uint256"},{internalType:"uint256",name:"validAfter",type:"uint256"},{internalType:"uint256",name:"validBefore",type:"uint256"},{internalType:"bytes32",name:"nonce",type:"bytes32"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"increaseAllowanceWithAuthorization",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"string",name:"newName",type:"string"},{internalType:"string",name:"newSymbol",type:"string"},{internalType:"uint8",name:"newDecimals",type:"uint8"},{internalType:"address",name:"childChainManager",type:"address"}],name:"initialize",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"initialized",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"isBlacklisted",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"nonces",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"pause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"paused",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"pausers",outputs:[{internalType:"address[]",name:"",type:"address[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"permit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"renounceRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract IERC20",name:"tokenContract",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"rescueERC20",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"rescuers",outputs:[{internalType:"address[]",name:"",type:"address[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"revokeRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"validAfter",type:"uint256"},{internalType:"uint256",name:"validBefore",type:"uint256"},{internalType:"bytes32",name:"nonce",type:"bytes32"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"transferWithAuthorization",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"unBlacklist",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"unpause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"string",name:"newName",type:"string"},{internalType:"string",name:"newSymbol",type:"string"}],name:"updateMetadata",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"amount",type:"uint256"}],name:"withdraw",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"validAfter",type:"uint256"},{internalType:"uint256",name:"validBefore",type:"uint256"},{internalType:"bytes32",name:"nonce",type:"bytes32"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"withdrawWithAuthorization",outputs:[],stateMutability:"nonpayable",type:"function"}]},858:function(e,t,n){var a=this&&this.__decorate||function(e,t,n,a){var i,s=arguments.length,r=s<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,n):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,a);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r};Object.defineProperty(t,"__esModule",{value:!0}),t.AppModule=void 0;const i=n(481),s=n(498),r=n(255),o=n(442),p=n(235);let y=class AppModule{};y=a([(0,i.Module)({imports:[s.HttpModule],providers:[r.PolymarketService,o.ConfigService,p.ContractService]})],y),t.AppModule=y},974:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getProgram=void 0;const a=n(304),i=n(598);t.getProgram=()=>{const e=new a.Command;return e.version(i.version).description("Command line interface for Polymarket").option("-l, --list ","List available markets with question filter. Usage: pmarket-cli -l ").option("-b, --buy ","Buy token order. Usage: pmarket-cli -b ").option("-s, --sell ","Sell token order. Usage: pmarket-cli -s ").option("-a, --allowance ","Set USDC allowance for CTFExchange contract. Usage: pmarket-cli -a ").option("-o, --orderBook ","Show order book for specific tokenId. Usage: pmarket-cli -o ").option("-c, --cancelAll","Cancel all open orders. Usage: pmarket-cli -c").option("-k, --keys","Get or generate api keys. Usage: pmarket-cli -k"),e}},442:function(e,t,n){var a=this&&this.__decorate||function(e,t,n,a){var i,s=arguments.length,r=s<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,n):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,a);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r},i=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};Object.defineProperty(t,"__esModule",{value:!0}),t.ConfigService=void 0;const s=n(481),r=n(147),o=n(17),p=n(37),y=".pmarket-cli",l="config.json";let u=class ConfigService{constructor(){this.isConfigAvailable()?this.loadConfig():this.createNewConfig()}isConfigAvailable(){const e=(0,p.homedir)()+o.sep+y+o.sep+l;return(0,r.existsSync)(e)}loadConfig(){const e=(0,p.homedir)()+o.sep+y+o.sep+l;this.config=JSON.parse((0,r.readFileSync)(e,"utf8"))}createNewConfig(){const e=(0,p.homedir)()+o.sep+y+o.sep+l;this.config={apiKey:"",apiSecret:"",passphrase:"",rpcProvider:"",privateKey:""},(0,r.existsSync)((0,p.homedir)()+o.sep+y)||(0,r.mkdirSync)((0,p.homedir)()+o.sep+y),(0,r.writeFileSync)(e,JSON.stringify(this.config,null,4))}get(e){return this.config[e]}getCreds(){return{key:this.config.apiKey,secret:this.config.apiSecret,passphrase:this.config.passphrase}}};u=a([(0,s.Injectable)(),i("design:paramtypes",[])],u),t.ConfigService=u},235:function(e,t,n){var a=this&&this.__decorate||function(e,t,n,a){var i,s=arguments.length,r=s<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,n):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,a);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r},i=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};Object.defineProperty(t,"__esModule",{value:!0}),t.ContractService=void 0;const s=n(481),r=n(982),o=n(283),p=n(442);let y=class ContractService{constructor(e){this.configService=e,this.polygonProvider=new r.ethers.providers.JsonRpcProvider(this.configService.get("rpcProvider"));try{this.wallet=new r.ethers.Wallet(this.configService.get("privateKey"),this.polygonProvider)}catch(e){console.log("Please provide valid private key and rpc provider in config.json file")}}async setAllowance(e){const t=await this.getBlockGasLimit(),n=await this.polygonProvider.getGasPrice(),a=new r.ethers.Contract("0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",o.usdcContractABI,this.wallet),i=r.ethers.utils.parseUnits(e.toString(),"6");return await a.approve("0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E",i,{gasLimit:t,gasPrice:n})}async getBlockGasLimit(){const e=await this.polygonProvider.getBlockNumber(),t=(await this.polygonProvider.getBlock(e)).gasLimit;console.log("Block Gas Limit:",t.toString())}};y=a([(0,s.Injectable)(),i("design:paramtypes",[p.ConfigService])],y),t.ContractService=y},255:function(e,t,n){var a=this&&this.__decorate||function(e,t,n,a){var i,s=arguments.length,r=s<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,n):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,a);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r},i=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};Object.defineProperty(t,"__esModule",{value:!0}),t.PolymarketService=void 0;const s=n(481),r=n(204),o=n(509),p=n(167),y=n(982),l=n(442);let u;const c="https://clob.polymarket.com/";let d=class PolymarketService{constructor(e){this.configService=e;const t=new y.ethers.providers.JsonRpcProvider(this.configService.get("rpcProvider")),n=new y.ethers.Wallet(this.configService.get("privateKey"),t);u=this.configService.getCreds(),this.clobClient=new r.ClobClient(c,o.Chain.POLYGON,n,u)}async getMarkets(){return(await p.default.get(`${c}markets`)).data}async getMarketsAcceptingOrders(){return(await this.getMarkets()).filter((e=>e.accepting_orders)).map((e=>({token_0:e.tokens[0],token_1:e.tokens[1],question:e.question})))}async determineMakerOrTakerFee(e,t,n,a,i){const s={side:"taker",fee:0};if(t===o.Side.SELL){if(a.bids.map((e=>({price:parseFloat(e.price),size:parseFloat(e.size)}))).filter((e=>e.price>=i)).reduce(((e,t)=>t.size),0)>=n){const t=await this.getFeeRateBps(e,"taker");return s.side="taker",s.fee=t,s}{const t=await this.getFeeRateBps(e,"maker");return s.side="maker",s.fee=t,s}}if(t===o.Side.BUY){if(a.asks.map((e=>({price:parseFloat(e.price),size:parseFloat(e.size)}))).filter((e=>e.price<=i)).reduce(((e,t)=>e+t.size),0)>=n){const t=await this.getFeeRateBps(e,"taker");return s.side="taker",s.fee=t,s}{const t=await this.getFeeRateBps(e,"maker");return s.side="maker",s.fee=t,s}}}async getFeeRateBps(e,t){const n=(await this.getMarkets()).filter((t=>t.tokens.map((e=>e.token_id)).indexOf(e)>=0))[0];return"taker"===t?n.taker_base_fee:n.maker_base_fee}async marketOrder(e,t,n,a){t===o.Side.BUY&&(n=Math.floor(n/a));const i=await this.clobClient.getOrderBook(e);console.log(i);const s=await this.determineMakerOrTakerFee(e,t,n,i,a);console.log("Fee rate: "+s.fee),console.log(t),console.log("Amount of shares/tokens: "+n),console.log("Price"+a);const r=await this.clobClient.createOrder({tokenID:e,price:a,side:t,size:n,feeRateBps:s.fee,nonce:0,expiration:0});let p;return console.log(r),"taker"===s.side&&t===o.Side.BUY?p=await this.clobClient.postOrder(r,o.OrderType.FOK):("taker"===s.side&&t===o.Side.SELL||"maker"===s.side)&&(p=await this.clobClient.postOrder(r,o.OrderType.GTC)),p}async getOrderBook(e){return this.clobClient.getOrderBook(e)}async cancelAll(){const e=await this.clobClient.cancelAll();return console.log(e),e}async getApiKeys(){const e=await this.clobClient.deriveApiKey();return e.error?this.clobClient.createApiKey():e}};d=a([(0,s.Injectable)(),i("design:paramtypes",[l.ConfigService])],d),t.PolymarketService=d},832:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AllowanceStrategy=void 0;t.AllowanceStrategy=class AllowanceStrategy{constructor(e){this.contractService=e}async execute(e){try{const t=await this.contractService.setAllowance(+e.allowance);console.log(t)}catch(e){console.error(e)}}}},733:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ApiKeysStrategy=void 0;t.ApiKeysStrategy=class ApiKeysStrategy{constructor(e){this.polymarketService=e}async execute(){const e=await this.polymarketService.getApiKeys();console.log(e)}}},719:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BuyStrategy=void 0;const a=n(204);t.BuyStrategy=class BuyStrategy{constructor(e){this.polymarketService=e}async execute(e){const t=e.buy[0],n=+e.buy[1],i=+e.buy[2];try{const e=await this.polymarketService.marketOrder(t,a.Side.BUY,n,i);console.log(e)}catch(e){console.error(e)}}}},943:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CancelAllStrategy=void 0;t.CancelAllStrategy=class CancelAllStrategy{constructor(e){this.polymarketService=e}async execute(){try{await this.polymarketService.cancelAll()}catch(e){console.error(e)}}}},638:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Context=void 0;const a=n(946),i=n(719),s=n(280),r=n(832),o=n(398),p=n(943),y=n(733);t.Context=class Context{constructor(e,t){this.polymarketService=e,this.contractService=t,this.setStrategy=e=>{this.strategy=e},this.executeStrategy=e=>{this.strategy.execute(e)},this.determineStrategy=e=>{let t;return e.list&&(t=new a.ListStrategy(this.polymarketService)),e.buy&&3===e.buy.length&&(t=new i.BuyStrategy(this.polymarketService)),e.sell&&3===e.sell.length&&(t=new s.SellStrategy(this.polymarketService)),e.allowance&&(t=new r.AllowanceStrategy(this.contractService)),e.orderBook&&(t=new o.OrderBookStrategy(this.polymarketService)),e.cancelAll&&(t=new p.CancelAllStrategy(this.polymarketService)),e.keys&&(t=new y.ApiKeysStrategy(this.polymarketService)),t}}}},946:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ListStrategy=void 0;t.ListStrategy=class ListStrategy{constructor(e){this.polymarketService=e}async execute(e){const t=await this.polymarketService.getMarketsAcceptingOrders();console.log(t.filter((t=>t.question.toLowerCase().includes(e.list.toLowerCase()))))}}},398:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.OrderBookStrategy=void 0;t.OrderBookStrategy=class OrderBookStrategy{constructor(e){this.polymarketService=e}async execute(e){try{const t=await this.polymarketService.getOrderBook(e.orderBook);console.log(t)}catch(e){console.error(e)}}}},280:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SellStrategy=void 0;const a=n(204);t.SellStrategy=class SellStrategy{constructor(e){this.polymarketService=e}async execute(e){const t=e.sell[0],n=+e.sell[1],i=+e.sell[2];try{const e=await this.polymarketService.marketOrder(t,a.Side.SELL,n,i);console.log(e)}catch(e){console.error(e)}}}},593:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.setAndExecuteStrategy=void 0;t.setAndExecuteStrategy=(e,t,n)=>{n.setStrategy(e),n.executeStrategy(t)}},498:e=>{e.exports=require("@nestjs/axios")},481:e=>{e.exports=require("@nestjs/common")},143:e=>{e.exports=require("@nestjs/core")},204:e=>{e.exports=require("@polymarket/clob-client")},509:e=>{e.exports=require("@polymarket/clob-client/dist/types")},167:e=>{e.exports=require("axios")},304:e=>{e.exports=require("commander")},982:e=>{e.exports=require("ethers")},116:e=>{e.exports=require("figlet")},147:e=>{e.exports=require("fs")},37:e=>{e.exports=require("os")},17:e=>{e.exports=require("path")},598:e=>{e.exports=JSON.parse('{"name":"pmarket-cli","version":"0.7.3","description":"CLI tool to trade on Polymarket","license":"MIT","author":{"name":"Arkadiusz Gotfryd","email":"arekgotfryd@g.pl"},"keywords":["cli","npmtool","polymarket"],"repository":"https://github.com/arekgotfryd/pmarket-cli","homepage":"https://github.com/arekgotfryd/pmarket-cli/blob/master/README.md","main":"dist/main.js","bin":{"pmarket-cli":"./dist/main.js"},"scripts":{"prebuild":"rimraf dist","build":"nest build --webpack --webpackPath webpack.config.js","format":"prettier --write \\"src/**/*.ts\\" \\"test/**/*.ts\\"","start":"nest start","start:dev":"nest start --watch","start:debug":"nest start --debug --watch","start:prod":"node dist/main","lint":"eslint src/**/*.ts --fix","test":"jest","test:watch":"jest --watch","test:cov":"jest --coverage","test:debug":"node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand","test:e2e":"echo \'No e2e tests implemented yet.\'","build:postinstall":"nest build --webpack --webpackPath webpack.postinstall.config.js","postinstall":"node ./scripts/create-config.js"},"dependencies":{"@nestjs/axios":"^2.0.0","@nestjs/common":"^9.4.2","@nestjs/core":"^9.4.2","@polymarket/clob-client":"^1.4.0","axios":"^1.3.4","commander":"^10.0.1","ethers":"^5.7.1","figlet":"^1.6.0","reflect-metadata":"0.1.13","rimraf":"3.0.2"},"devDependencies":{"@nestjs/cli":"^9.5.0","@nestjs/testing":"^9.4.2","@types/jest":"^29.5.2","@types/node":"18.0.3","@typescript-eslint/eslint-plugin":"5.30.5","@typescript-eslint/parser":"5.30.5","eslint":"8.19.0","eslint-config-prettier":"8.5.0","jest":"28.1.2","prettier":"2.7.1","ts-jest":"28.0.5","ts-loader":"9.3.1","ts-node":"10.8.2","typescript":"4.7.4","webpack-shebang-plugin":"^1.1.8"}}')}},t={};function __webpack_require__(n){var a=t[n];if(void 0!==a)return a.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,__webpack_require__),i.exports}(()=>{const e=__webpack_require__(143),t=__webpack_require__(858),n=__webpack_require__(255),a=__webpack_require__(974),i=__webpack_require__(235),s=__webpack_require__(116),r=__webpack_require__(638),o=__webpack_require__(593),p=__webpack_require__(598);!async function bootstrap(){const y=await e.NestFactory.createApplicationContext(t.AppModule,{logger:!1}),l=y.get(n.PolymarketService),u=y.get(i.ContractService);console.log(s.textSync(p.name));const c=(0,a.getProgram)();process.argv.slice(2).length||c.outputHelp();const d=c.parse(process.argv).opts(),m=new r.Context(l,u),b=m.determineStrategy(d);b&&(0,o.setAndExecuteStrategy)(b,d,m)}()})()})(); \ No newline at end of file +(()=>{"use strict";var e={283:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.usdcContractABI=void 0,t.usdcContractABI=[{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"authorizer",type:"address"},{indexed:!0,internalType:"bytes32",name:"nonce",type:"bytes32"}],name:"AuthorizationCanceled",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"authorizer",type:"address"},{indexed:!0,internalType:"bytes32",name:"nonce",type:"bytes32"}],name:"AuthorizationUsed",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"account",type:"address"}],name:"Blacklisted",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"userAddress",type:"address"},{indexed:!1,internalType:"address payable",name:"relayerAddress",type:"address"},{indexed:!1,internalType:"bytes",name:"functionSignature",type:"bytes"}],name:"MetaTransactionExecuted",type:"event"},{anonymous:!1,inputs:[],name:"Pause",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"newRescuer",type:"address"}],name:"RescuerChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"previousAdminRole",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"newAdminRole",type:"bytes32"}],name:"RoleAdminChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"address",name:"account",type:"address"},{indexed:!0,internalType:"address",name:"sender",type:"address"}],name:"RoleGranted",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"address",name:"account",type:"address"},{indexed:!0,internalType:"address",name:"sender",type:"address"}],name:"RoleRevoked",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"account",type:"address"}],name:"UnBlacklisted",type:"event"},{anonymous:!1,inputs:[],name:"Unpause",type:"event"},{inputs:[],name:"APPROVE_WITH_AUTHORIZATION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"BLACKLISTER_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"CANCEL_AUTHORIZATION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"DECREASE_ALLOWANCE_WITH_AUTHORIZATION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"DEFAULT_ADMIN_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"DEPOSITOR_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"DOMAIN_SEPARATOR",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"EIP712_VERSION",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"INCREASE_ALLOWANCE_WITH_AUTHORIZATION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"META_TRANSACTION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"PAUSER_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"PERMIT_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"RESCUER_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"TRANSFER_WITH_AUTHORIZATION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"WITHDRAW_WITH_AUTHORIZATION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"validAfter",type:"uint256"},{internalType:"uint256",name:"validBefore",type:"uint256"},{internalType:"bytes32",name:"nonce",type:"bytes32"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"approveWithAuthorization",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"authorizer",type:"address"},{internalType:"bytes32",name:"nonce",type:"bytes32"}],name:"authorizationState",outputs:[{internalType:"enum GasAbstraction.AuthorizationState",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"blacklist",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"blacklisters",outputs:[{internalType:"address[]",name:"",type:"address[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"authorizer",type:"address"},{internalType:"bytes32",name:"nonce",type:"bytes32"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"cancelAuthorization",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"subtractedValue",type:"uint256"}],name:"decreaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"decrement",type:"uint256"},{internalType:"uint256",name:"validAfter",type:"uint256"},{internalType:"uint256",name:"validBefore",type:"uint256"},{internalType:"bytes32",name:"nonce",type:"bytes32"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"decreaseAllowanceWithAuthorization",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"user",type:"address"},{internalType:"bytes",name:"depositData",type:"bytes"}],name:"deposit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"userAddress",type:"address"},{internalType:"bytes",name:"functionSignature",type:"bytes"},{internalType:"bytes32",name:"sigR",type:"bytes32"},{internalType:"bytes32",name:"sigS",type:"bytes32"},{internalType:"uint8",name:"sigV",type:"uint8"}],name:"executeMetaTransaction",outputs:[{internalType:"bytes",name:"",type:"bytes"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"}],name:"getRoleAdmin",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"uint256",name:"index",type:"uint256"}],name:"getRoleMember",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"}],name:"getRoleMemberCount",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"grantRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"hasRole",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"addedValue",type:"uint256"}],name:"increaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"increment",type:"uint256"},{internalType:"uint256",name:"validAfter",type:"uint256"},{internalType:"uint256",name:"validBefore",type:"uint256"},{internalType:"bytes32",name:"nonce",type:"bytes32"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"increaseAllowanceWithAuthorization",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"string",name:"newName",type:"string"},{internalType:"string",name:"newSymbol",type:"string"},{internalType:"uint8",name:"newDecimals",type:"uint8"},{internalType:"address",name:"childChainManager",type:"address"}],name:"initialize",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"initialized",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"isBlacklisted",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"nonces",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"pause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"paused",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"pausers",outputs:[{internalType:"address[]",name:"",type:"address[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"permit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"renounceRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract IERC20",name:"tokenContract",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"rescueERC20",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"rescuers",outputs:[{internalType:"address[]",name:"",type:"address[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"revokeRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"validAfter",type:"uint256"},{internalType:"uint256",name:"validBefore",type:"uint256"},{internalType:"bytes32",name:"nonce",type:"bytes32"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"transferWithAuthorization",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"unBlacklist",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"unpause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"string",name:"newName",type:"string"},{internalType:"string",name:"newSymbol",type:"string"}],name:"updateMetadata",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"amount",type:"uint256"}],name:"withdraw",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"validAfter",type:"uint256"},{internalType:"uint256",name:"validBefore",type:"uint256"},{internalType:"bytes32",name:"nonce",type:"bytes32"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"withdrawWithAuthorization",outputs:[],stateMutability:"nonpayable",type:"function"}]},858:function(e,t,n){var a=this&&this.__decorate||function(e,t,n,a){var i,s=arguments.length,r=s<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,n):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,a);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r};Object.defineProperty(t,"__esModule",{value:!0}),t.AppModule=void 0;const i=n(481),s=n(498),r=n(255),o=n(442),p=n(235);let y=class AppModule{};y=a([(0,i.Module)({imports:[s.HttpModule],providers:[r.PolymarketService,o.ConfigService,p.ContractService]})],y),t.AppModule=y},974:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getProgram=void 0;const a=n(304),i=n(598);t.getProgram=()=>{const e=new a.Command;return e.version(i.version).description("Command line interface for Polymarket").option("-l, --list ","List available markets with question filter. Usage: pmarket-cli -l ").option("-b, --buy ","Buy token order. Usage: pmarket-cli -b ").option("-s, --sell ","Sell token order. Usage: pmarket-cli -s ").option("-a, --allowance ","Set USDC allowance for CTFExchange contract. Usage: pmarket-cli -a ").option("-o, --orderBook ","Show order book for specific tokenId. Usage: pmarket-cli -o ").option("-c, --cancelAll","Cancel all open orders. Usage: pmarket-cli -c").option("-k, --keys","Get or generate api keys. Usage: pmarket-cli -k"),e}},442:function(e,t,n){var a=this&&this.__decorate||function(e,t,n,a){var i,s=arguments.length,r=s<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,n):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,a);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r},i=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};Object.defineProperty(t,"__esModule",{value:!0}),t.ConfigService=void 0;const s=n(481),r=n(147),o=n(17),p=n(37),y=".pmarket-cli",l="config.json";let u=class ConfigService{constructor(){this.isConfigAvailable()?this.loadConfig():this.createNewConfig()}isConfigAvailable(){const e=(0,p.homedir)()+o.sep+y+o.sep+l;return(0,r.existsSync)(e)}loadConfig(){const e=(0,p.homedir)()+o.sep+y+o.sep+l;this.config=JSON.parse((0,r.readFileSync)(e,"utf8"))}createNewConfig(){const e=(0,p.homedir)()+o.sep+y+o.sep+l;this.config={apiKey:"",apiSecret:"",passphrase:"",rpcProvider:"",privateKey:"",funderAddress:""},(0,r.existsSync)((0,p.homedir)()+o.sep+y)||(0,r.mkdirSync)((0,p.homedir)()+o.sep+y),(0,r.writeFileSync)(e,JSON.stringify(this.config,null,4))}get(e){return this.config[e]}getCreds(){return{key:this.config.apiKey,secret:this.config.apiSecret,passphrase:this.config.passphrase}}};u=a([(0,s.Injectable)(),i("design:paramtypes",[])],u),t.ConfigService=u},235:function(e,t,n){var a=this&&this.__decorate||function(e,t,n,a){var i,s=arguments.length,r=s<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,n):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,a);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r},i=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};Object.defineProperty(t,"__esModule",{value:!0}),t.ContractService=void 0;const s=n(481),r=n(982),o=n(283),p=n(442);let y=class ContractService{constructor(e){this.configService=e,this.polygonProvider=new r.ethers.providers.JsonRpcProvider(this.configService.get("rpcProvider"));try{this.wallet=new r.ethers.Wallet(this.configService.get("privateKey"),this.polygonProvider)}catch(e){console.log("Please provide valid private key and rpc provider in config.json file")}}async setAllowance(e){const t=await this.getBlockGasLimit(),n=await this.polygonProvider.getGasPrice(),a=new r.ethers.Contract("0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",o.usdcContractABI,this.wallet),i=r.ethers.utils.parseUnits(e.toString(),"6");return await a.approve("0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E",i,{gasLimit:t,gasPrice:n})}async getBlockGasLimit(){const e=await this.polygonProvider.getBlockNumber(),t=(await this.polygonProvider.getBlock(e)).gasLimit;console.log("Block Gas Limit:",t.toString())}};y=a([(0,s.Injectable)(),i("design:paramtypes",[p.ConfigService])],y),t.ContractService=y},255:function(e,t,n){var a=this&&this.__decorate||function(e,t,n,a){var i,s=arguments.length,r=s<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,n):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,a);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r},i=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};Object.defineProperty(t,"__esModule",{value:!0}),t.PolymarketService=void 0;const s=n(481),r=n(204),o=n(509),p=n(982),y=n(442);let l;let u=class PolymarketService{constructor(e){this.configService=e;const t=new p.ethers.providers.JsonRpcProvider(this.configService.get("rpcProvider"));try{this.signer=new p.ethers.Wallet(this.configService.get("privateKey"),t)}catch(e){console.log("Please provide valid private key and rpc provider in config.json file")}l=this.configService.getCreds(),this.clobClient=new r.ClobClient("https://clob.polymarket.com/",o.Chain.POLYGON,this.signer,l,2,this.configService.get("funderAddress"))}async fetchAllMarkets(){let e=[],t="";for(;;){const n=await this.clobClient.getMarkets(t);if(e.push(...n.data),"LTE="===n.next_cursor||!n.next_cursor)break;t=n.next_cursor}return e}async getMarketsAcceptingOrders(){return(await this.fetchAllMarkets()).filter((e=>!e.closed&&e.active)).map((e=>({yes:e.tokens[0],no:e.tokens[1],question:e.question})))}async marketOrder(e,t,n,a){t===o.Side.BUY&&(n=Math.floor(n/a));const i=await this.clobClient.getOrderBook(e);console.log(i),console.log(t),console.log("Amount of shares/tokens: "+n),console.log("Price"+a);const s=await this.clobClient.createOrder({tokenID:e,price:a,side:t,size:n,feeRateBps:0,nonce:0,expiration:0});let r;return console.log(s),(t===o.Side.BUY||t===o.Side.SELL)&&(r=await this.clobClient.postOrder(s,o.OrderType.GTC)),r}async getOrderBook(e){return this.clobClient.getOrderBook(e)}async cancelAll(){const e=await this.clobClient.cancelAll();return console.log(e),e}async getApiKeys(){const e=await this.clobClient.deriveApiKey();return e.error?this.clobClient.createApiKey():e}};u=a([(0,s.Injectable)(),i("design:paramtypes",[y.ConfigService])],u),t.PolymarketService=u},832:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AllowanceStrategy=void 0;t.AllowanceStrategy=class AllowanceStrategy{constructor(e){this.contractService=e}async execute(e){try{const t=await this.contractService.setAllowance(+e.allowance);console.log(t)}catch(e){console.error(e)}}}},733:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ApiKeysStrategy=void 0;t.ApiKeysStrategy=class ApiKeysStrategy{constructor(e){this.polymarketService=e}async execute(){const e=await this.polymarketService.getApiKeys();console.log(e)}}},719:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BuyStrategy=void 0;const a=n(204);t.BuyStrategy=class BuyStrategy{constructor(e){this.polymarketService=e}async execute(e){const t=e.buy[0],n=+e.buy[1],i=+e.buy[2];try{const e=await this.polymarketService.marketOrder(t,a.Side.BUY,n,i);console.log(e)}catch(e){console.error(e)}}}},943:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CancelAllStrategy=void 0;t.CancelAllStrategy=class CancelAllStrategy{constructor(e){this.polymarketService=e}async execute(){try{await this.polymarketService.cancelAll()}catch(e){console.error(e)}}}},638:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Context=void 0;const a=n(946),i=n(719),s=n(280),r=n(832),o=n(398),p=n(943),y=n(733);t.Context=class Context{constructor(e,t){this.polymarketService=e,this.contractService=t,this.setStrategy=e=>{this.strategy=e},this.executeStrategy=e=>{this.strategy.execute(e)},this.determineStrategy=e=>{let t;return e.list&&(t=new a.ListStrategy(this.polymarketService)),e.buy&&3===e.buy.length&&(t=new i.BuyStrategy(this.polymarketService)),e.sell&&3===e.sell.length&&(t=new s.SellStrategy(this.polymarketService)),e.allowance&&(t=new r.AllowanceStrategy(this.contractService)),e.orderBook&&(t=new o.OrderBookStrategy(this.polymarketService)),e.cancelAll&&(t=new p.CancelAllStrategy(this.polymarketService)),e.keys&&(t=new y.ApiKeysStrategy(this.polymarketService)),t}}}},946:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ListStrategy=void 0;t.ListStrategy=class ListStrategy{constructor(e){this.polymarketService=e}async execute(e){const t=await this.polymarketService.getMarketsAcceptingOrders();console.log(t.filter((t=>t.question.toLowerCase().includes(e.list.toLowerCase()))))}}},398:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.OrderBookStrategy=void 0;t.OrderBookStrategy=class OrderBookStrategy{constructor(e){this.polymarketService=e}async execute(e){try{const t=await this.polymarketService.getOrderBook(e.orderBook);console.log(t)}catch(e){console.error(e)}}}},280:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SellStrategy=void 0;const a=n(204);t.SellStrategy=class SellStrategy{constructor(e){this.polymarketService=e}async execute(e){const t=e.sell[0],n=+e.sell[1],i=+e.sell[2];try{const e=await this.polymarketService.marketOrder(t,a.Side.SELL,n,i);console.log(e)}catch(e){console.error(e)}}}},593:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.setAndExecuteStrategy=void 0;t.setAndExecuteStrategy=(e,t,n)=>{n.setStrategy(e),n.executeStrategy(t)}},498:e=>{e.exports=require("@nestjs/axios")},481:e=>{e.exports=require("@nestjs/common")},143:e=>{e.exports=require("@nestjs/core")},204:e=>{e.exports=require("@polymarket/clob-client")},509:e=>{e.exports=require("@polymarket/clob-client/dist/types")},304:e=>{e.exports=require("commander")},982:e=>{e.exports=require("ethers")},116:e=>{e.exports=require("figlet")},147:e=>{e.exports=require("fs")},37:e=>{e.exports=require("os")},17:e=>{e.exports=require("path")},598:e=>{e.exports=JSON.parse('{"name":"pmarket-cli","version":"0.7.5","description":"CLI tool to trade on Polymarket","license":"MIT","author":{"name":"Arkadiusz Gotfryd","email":"arekgotfryd@g.pl"},"keywords":["cli","npmtool","polymarket"],"repository":"https://github.com/arekgotfryd/pmarket-cli","homepage":"https://github.com/arekgotfryd/pmarket-cli/blob/master/README.md","main":"dist/main.js","bin":{"pmarket-cli":"./dist/main.js"},"scripts":{"prebuild":"rimraf dist","build":"nest build --webpack --webpackPath webpack.config.js","format":"prettier --write \\"src/**/*.ts\\" \\"test/**/*.ts\\"","start":"nest start","start:dev":"nest start --watch","start:debug":"nest start --debug --watch","start:prod":"node dist/main","lint":"eslint src/**/*.ts --fix","test":"jest","test:watch":"jest --watch","test:cov":"jest --coverage","test:debug":"node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand","test:e2e":"echo \'No e2e tests implemented yet.\'","build:postinstall":"nest build --webpack --webpackPath webpack.postinstall.config.js","postinstall":"node ./scripts/create-config.js"},"dependencies":{"@nestjs/axios":"^2.0.0","@nestjs/common":"^9.4.2","@nestjs/core":"^9.4.2","@polymarket/clob-client":"^4.12.0","axios":"^1.3.4","commander":"^10.0.1","ethers":"^5.7.1","figlet":"^1.6.0","graphql-request":"^4.3.0","reflect-metadata":"0.1.13","rimraf":"3.0.2"},"devDependencies":{"@nestjs/cli":"^9.5.0","@nestjs/testing":"^9.4.2","@types/jest":"^29.5.2","@types/node":"18.0.3","@typescript-eslint/eslint-plugin":"5.30.5","@typescript-eslint/parser":"5.30.5","eslint":"8.19.0","eslint-config-prettier":"8.5.0","jest":"28.1.2","prettier":"2.7.1","ts-jest":"28.0.5","ts-loader":"9.3.1","ts-node":"10.8.2","typescript":"4.7.4","webpack-shebang-plugin":"^1.1.8"}}')}},t={};function __webpack_require__(n){var a=t[n];if(void 0!==a)return a.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,__webpack_require__),i.exports}(()=>{const e=__webpack_require__(143),t=__webpack_require__(858),n=__webpack_require__(255),a=__webpack_require__(974),i=__webpack_require__(235),s=__webpack_require__(116),r=__webpack_require__(638),o=__webpack_require__(593),p=__webpack_require__(598);!async function bootstrap(){const y=await e.NestFactory.createApplicationContext(t.AppModule,{logger:!1}),l=y.get(n.PolymarketService),u=y.get(i.ContractService);console.log(s.textSync(p.name));const c=(0,a.getProgram)();process.argv.slice(2).length||c.outputHelp();const d=c.parse(process.argv).opts(),m=new r.Context(l,u),b=m.determineStrategy(d);b&&(0,o.setAndExecuteStrategy)(b,d,m)}()})()})(); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index c4809c9..f0f2906 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,23 +1,24 @@ { "name": "pmarket-cli", - "version": "0.7.2", + "version": "0.7.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "pmarket-cli", - "version": "0.7.2", + "version": "0.7.4", "hasInstallScript": true, "license": "MIT", "dependencies": { "@nestjs/axios": "^2.0.0", "@nestjs/common": "^9.4.2", "@nestjs/core": "^9.4.2", - "@polymarket/clob-client": "^1.4.0", + "@polymarket/clob-client": "^4.12.0", "axios": "^1.3.4", "commander": "^10.0.1", "ethers": "^5.7.1", "figlet": "^1.6.0", + "graphql-request": "^4.3.0", "reflect-metadata": "0.1.13", "rimraf": "3.0.2" }, @@ -754,29 +755,6 @@ "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==", "dev": true }, - "node_modules/@chainsafe/as-sha256": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/@chainsafe/as-sha256/-/as-sha256-0.3.1.tgz", - "integrity": "sha512-hldFFYuf49ed7DAakWVXSJODuq3pzJEguD8tQ7h+sGkM18vja+OFoJI9krnGmgzyuZC2ETX0NOIcCTy31v2Mtg==" - }, - "node_modules/@chainsafe/persistent-merkle-tree": { - "version": "0.4.2", - "resolved": "https://registry.npmjs.org/@chainsafe/persistent-merkle-tree/-/persistent-merkle-tree-0.4.2.tgz", - "integrity": "sha512-lLO3ihKPngXLTus/L7WHKaw9PnNJWizlOF1H9NNzHP6Xvh82vzg9F2bzkXhYIFshMZ2gTCEz8tq6STe7r5NDfQ==", - "dependencies": { - "@chainsafe/as-sha256": "^0.3.1" - } - }, - "node_modules/@chainsafe/ssz": { - "version": "0.9.4", - "resolved": "https://registry.npmjs.org/@chainsafe/ssz/-/ssz-0.9.4.tgz", - "integrity": "sha512-77Qtg2N1ayqs4Bg/wvnWfg5Bta7iy7IRh8XqXh7oNMeP2HBbBwx8m6yTpA8p0EHItWPEBkgZd5S5/LSlp3GXuQ==", - "dependencies": { - "@chainsafe/as-sha256": "^0.3.1", - "@chainsafe/persistent-merkle-tree": "^0.4.2", - "case": "^1.6.3" - } - }, "node_modules/@colors/colors": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", @@ -833,6 +811,7 @@ "version": "4.0.1", "resolved": "https://registry.npmjs.org/@ethereumjs/rlp/-/rlp-4.0.1.tgz", "integrity": "sha512-tqsQiBQDQdmPWE1xkkBq4rlSW5QZpLOUJ5RJh2/9fug+q9tnUhuZoVLk7s0scUIKTOzEtR72DFBXI4WiZcMpvw==", + "license": "MPL-2.0", "bin": { "rlp": "bin/rlp" }, @@ -841,13 +820,14 @@ } }, "node_modules/@ethereumjs/util": { - "version": "8.0.5", - "resolved": "https://registry.npmjs.org/@ethereumjs/util/-/util-8.0.5.tgz", - "integrity": "sha512-259rXKK3b3D8HRVdRmlOEi6QFvwxdt304hhrEAmpZhsj7ufXEOTIc9JRZPMnXatKjECokdLNBcDOFBeBSzAIaw==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@ethereumjs/util/-/util-8.1.0.tgz", + "integrity": "sha512-zQ0IqbdX8FZ9aw11vP+dZkKDkS+kgIvQPHnSAXzP9pLu+Rfu3D3XEeLbicvoXJTYnhZiPmsZUxgdzXwNKxRPbA==", + "license": "MPL-2.0", "dependencies": { - "@chainsafe/ssz": "0.9.4", "@ethereumjs/rlp": "^4.0.1", - "ethereum-cryptography": "^1.1.2" + "ethereum-cryptography": "^2.0.0", + "micro-ftch": "^0.3.1" }, "engines": { "node": ">=14" @@ -2073,13 +2053,14 @@ } }, "node_modules/@metamask/eth-sig-util": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/@metamask/eth-sig-util/-/eth-sig-util-5.0.2.tgz", - "integrity": "sha512-RU6fG/H6/UlBol221uBkq5C7w3TwLK611nEZliO2u+kO0vHKGBXnIPlhI0tzKUigjhUeOd9mhCNbNvhh0LKt9Q==", - "dependencies": { - "@ethereumjs/util": "^8.0.0", - "bn.js": "^4.11.8", - "ethereum-cryptography": "^1.1.2", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@metamask/eth-sig-util/-/eth-sig-util-5.1.0.tgz", + "integrity": "sha512-mlgziIHYlA9pi/XZerChqg4NocdOgBPB9NmxgXWQO2U2hH8RGOJQrz6j/AIKkYxgCMIE2PY000+joOwXfzeTDQ==", + "license": "ISC", + "dependencies": { + "@ethereumjs/util": "^8.0.6", + "bn.js": "^4.12.0", + "ethereum-cryptography": "^2.0.0", "ethjs-util": "^0.1.6", "tweetnacl": "^1.0.3", "tweetnacl-util": "^0.15.1" @@ -2451,16 +2432,29 @@ "integrity": "sha512-5svOrSA2w3iGFDs1HibEVBGbDrAY82bFQ3HZ3ixB+88nsbsWQoKqDRb5UBYAUPEzbBn6dAp5gRNXglySbx1MlA==", "dev": true }, - "node_modules/@noble/secp256k1": { - "version": "1.7.1", - "resolved": "https://registry.npmjs.org/@noble/secp256k1/-/secp256k1-1.7.1.tgz", - "integrity": "sha512-hOUk6AyBFmqVrv7k5WAw/LpszxVbj9gGN4JRkIX52fdFAj1UA61KXmZDvqVEm+pOyec3+fIeZB02LYa/pWOArw==", - "funding": [ - { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - ] + "node_modules/@noble/curves": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.4.2.tgz", + "integrity": "sha512-TavHr8qycMChk8UwMld0ZDRvatedkzWfH8IiaeGCfymOP5i0hSCozz9vHOL0nkwk7HRMlFnAiKpS2jrUmSybcw==", + "license": "MIT", + "dependencies": { + "@noble/hashes": "1.4.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@noble/hashes": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.4.0.tgz", + "integrity": "sha512-V1JJ1WTRUqHHrOSh597hURcMqVKVGL/ea3kv0gSnEdsEZ0/+VyPghM1lMNGc00z7CIQorSvbKpuJkxvuHbvdbg==", + "license": "MIT", + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", @@ -2515,12 +2509,14 @@ } }, "node_modules/@polymarket/clob-client": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/@polymarket/clob-client/-/clob-client-1.4.0.tgz", - "integrity": "sha512-nUDUDiuH0VrYPfiy16pj2fdgWYFRwy7ezWArTy8L560N3/T6p7+LpSzL4lcUZTw+V6mOVOZJ8GwqW05Wlh7WJw==", + "version": "4.12.0", + "resolved": "https://registry.npmjs.org/@polymarket/clob-client/-/clob-client-4.12.0.tgz", + "integrity": "sha512-7+8WdbPzMkMVTa2hD2JA7ynAKazrsI37czQVBlZEO9tShzRyCPrJtl89cHebTXOQfP+8V2T3Ny7JkZxAofxpQQ==", + "license": "MIT", "dependencies": { - "@polymarket/order-utils": "^1.3.1", + "@polymarket/order-utils": "^2.1.0", "axios": "^0.27.2", + "browser-or-node": "^2.1.1", "ethers": "^5.7.1" } }, @@ -2581,9 +2577,10 @@ } }, "node_modules/@polymarket/order-utils": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/@polymarket/order-utils/-/order-utils-1.3.1.tgz", - "integrity": "sha512-+ml9tjIYvpEoWO98MAZwlq0V3fHDAW8oXOEJL0oj58CidFDTzgLGflhhzhDOs4DTEbjaUGD8mbFcuIN4OEzBBQ==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@polymarket/order-utils/-/order-utils-2.1.0.tgz", + "integrity": "sha512-vUFj1WiEtm4vB0dxx2NweKKioPu7ehBoJ8fTTaVbR8Dur6AazVWyS+KhgrDE66fKTNneOxxgfdEpbNgxZ4pOIA==", + "license": "MIT", "dependencies": { "@metamask/eth-sig-util": "^5.0.0", "ethers": "^5.7.1" @@ -2593,117 +2590,42 @@ "npm": ">=5" } }, - "node_modules/@polymarket/order-utils/node_modules/ethers": { - "version": "5.7.2", - "resolved": "https://registry.npmjs.org/ethers/-/ethers-5.7.2.tgz", - "integrity": "sha512-wswUsmWo1aOK8rR7DIKiWSw9DbLWe6x98Jrn8wcTflTVvaXhAMaB5zGAXy0GYQEQp9iO1iSHWVyARQm11zUtyg==", - "funding": [ - { - "type": "individual", - "url": "https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2" - }, - { - "type": "individual", - "url": "https://www.buymeacoffee.com/ricmoo" - } - ], - "dependencies": { - "@ethersproject/abi": "5.7.0", - "@ethersproject/abstract-provider": "5.7.0", - "@ethersproject/abstract-signer": "5.7.0", - "@ethersproject/address": "5.7.0", - "@ethersproject/base64": "5.7.0", - "@ethersproject/basex": "5.7.0", - "@ethersproject/bignumber": "5.7.0", - "@ethersproject/bytes": "5.7.0", - "@ethersproject/constants": "5.7.0", - "@ethersproject/contracts": "5.7.0", - "@ethersproject/hash": "5.7.0", - "@ethersproject/hdnode": "5.7.0", - "@ethersproject/json-wallets": "5.7.0", - "@ethersproject/keccak256": "5.7.0", - "@ethersproject/logger": "5.7.0", - "@ethersproject/networks": "5.7.1", - "@ethersproject/pbkdf2": "5.7.0", - "@ethersproject/properties": "5.7.0", - "@ethersproject/providers": "5.7.2", - "@ethersproject/random": "5.7.0", - "@ethersproject/rlp": "5.7.0", - "@ethersproject/sha2": "5.7.0", - "@ethersproject/signing-key": "5.7.0", - "@ethersproject/solidity": "5.7.0", - "@ethersproject/strings": "5.7.0", - "@ethersproject/transactions": "5.7.0", - "@ethersproject/units": "5.7.0", - "@ethersproject/wallet": "5.7.0", - "@ethersproject/web": "5.7.1", - "@ethersproject/wordlists": "5.7.0" - } - }, "node_modules/@scure/base": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@scure/base/-/base-1.1.1.tgz", - "integrity": "sha512-ZxOhsSyxYwLJj3pLZCefNitxsj093tb2vq90mp2txoYeBqbcjDjqFhyM8eUjq/uFm6zJ+mUuqxlS2FkuSY1MTA==", - "funding": [ - { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - ] + "version": "1.1.9", + "resolved": "https://registry.npmjs.org/@scure/base/-/base-1.1.9.tgz", + "integrity": "sha512-8YKhl8GHiNI/pU2VMaofa2Tor7PJRAjwQLBBuilkJ9L5+13yVbC7JO/wS7piioAvPSwR3JKM1IJ/u4xQzbcXKg==", + "license": "MIT", + "funding": { + "url": "https://paulmillr.com/funding/" + } }, "node_modules/@scure/bip32": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/@scure/bip32/-/bip32-1.1.5.tgz", - "integrity": "sha512-XyNh1rB0SkEqd3tXcXMi+Xe1fvg+kUIcoRIEujP1Jgv7DqW2r9lg3Ah0NkFaCs9sTkQAQA8kw7xiRXzENi9Rtw==", - "funding": [ - { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - ], + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@scure/bip32/-/bip32-1.4.0.tgz", + "integrity": "sha512-sVUpc0Vq3tXCkDGYVWGIZTRfnvu8LoTDaev7vbwh0omSvVORONr960MQWdKqJDCReIEmTj3PAr73O3aoxz7OPg==", + "license": "MIT", "dependencies": { - "@noble/hashes": "~1.2.0", - "@noble/secp256k1": "~1.7.0", - "@scure/base": "~1.1.0" + "@noble/curves": "~1.4.0", + "@noble/hashes": "~1.4.0", + "@scure/base": "~1.1.6" + }, + "funding": { + "url": "https://paulmillr.com/funding/" } }, - "node_modules/@scure/bip32/node_modules/@noble/hashes": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.2.0.tgz", - "integrity": "sha512-FZfhjEDbT5GRswV3C6uvLPHMiVD6lQBmpoX5+eSiPaMTXte/IKqI5dykDxzZB/WBeK/CDuQRBWarPdi3FNY2zQ==", - "funding": [ - { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - ] - }, "node_modules/@scure/bip39": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@scure/bip39/-/bip39-1.1.1.tgz", - "integrity": "sha512-t+wDck2rVkh65Hmv280fYdVdY25J9YeEUIgn2LG1WM6gxFkGzcksoDiUkWVpVp3Oex9xGC68JU2dSbUfwZ2jPg==", - "funding": [ - { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - ], + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@scure/bip39/-/bip39-1.3.0.tgz", + "integrity": "sha512-disdg7gHuTDZtY+ZdkmLpPCk7fxZSu3gBiEGuoC1XYxv9cGx3Z6cpTggCgW6odSOOIXCiDjuGejW+aJKCY/pIQ==", + "license": "MIT", "dependencies": { - "@noble/hashes": "~1.2.0", - "@scure/base": "~1.1.0" + "@noble/hashes": "~1.4.0", + "@scure/base": "~1.1.6" + }, + "funding": { + "url": "https://paulmillr.com/funding/" } }, - "node_modules/@scure/bip39/node_modules/@noble/hashes": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.2.0.tgz", - "integrity": "sha512-FZfhjEDbT5GRswV3C6uvLPHMiVD6lQBmpoX5+eSiPaMTXte/IKqI5dykDxzZB/WBeK/CDuQRBWarPdi3FNY2zQ==", - "funding": [ - { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - ] - }, "node_modules/@sinclair/typebox": { "version": "0.23.5", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.23.5.tgz", @@ -3794,6 +3716,12 @@ "resolved": "https://registry.npmjs.org/brorand/-/brorand-1.1.0.tgz", "integrity": "sha512-cKV8tMCEpQs4hK/ik71d6LrPOnpkpGBR0wzxqr68g2m/LB2GxVYQroAjMJZRVM1Y4BCjCKc3vAamxSzOY2RP+w==" }, + "node_modules/browser-or-node": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/browser-or-node/-/browser-or-node-2.1.1.tgz", + "integrity": "sha512-8CVjaLJGuSKMVTxJ2DpBl5XnlNDiT4cQFeuCJJrvJmts9YrTZDizTX7PjC2s6W4x+MBGZeEY6dGMrF04/6Hgqg==", + "license": "MIT" + }, "node_modules/browserslist": { "version": "4.21.1", "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.21.1.tgz", @@ -3907,14 +3835,6 @@ } ] }, - "node_modules/case": { - "version": "1.6.3", - "resolved": "https://registry.npmjs.org/case/-/case-1.6.3.tgz", - "integrity": "sha512-mzDSXIPaFwVDvZAHqZ9VlbyF4yyXRuX6IvB06WvPYkqJVO24kX1PPhv9bfpKNFZyxYFmmgo03HUiD8iklmJYRQ==", - "engines": { - "node": ">= 0.8.0" - } - }, "node_modules/chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", @@ -4153,6 +4073,15 @@ "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", "dev": true }, + "node_modules/cross-fetch": { + "version": "3.1.8", + "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.8.tgz", + "integrity": "sha512-cvA+JwZoU0Xq+h6WkMvAUqPEYy92Obet6UdKLfW60qn99ftItKjB5T+BkyWOFWe2pUyfQ+IJHmpOTznqk1M6Kg==", + "license": "MIT", + "dependencies": { + "node-fetch": "^2.6.12" + } + }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -4619,27 +4548,17 @@ } }, "node_modules/ethereum-cryptography": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/ethereum-cryptography/-/ethereum-cryptography-1.2.0.tgz", - "integrity": "sha512-6yFQC9b5ug6/17CQpCyE3k9eKBMdhyVjzUy1WkiuY/E4vj/SXDBbCw8QEIaXqf0Mf2SnY6RmpDcwlUmBSS0EJw==", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ethereum-cryptography/-/ethereum-cryptography-2.2.1.tgz", + "integrity": "sha512-r/W8lkHSiTLxUxW8Rf3u4HGB0xQweG2RyETjywylKZSzLWoWAijRz8WCuOtJ6wah+avllXBqZuk29HCCvhEIRg==", + "license": "MIT", "dependencies": { - "@noble/hashes": "1.2.0", - "@noble/secp256k1": "1.7.1", - "@scure/bip32": "1.1.5", - "@scure/bip39": "1.1.1" + "@noble/curves": "1.4.2", + "@noble/hashes": "1.4.0", + "@scure/bip32": "1.4.0", + "@scure/bip39": "1.3.0" } }, - "node_modules/ethereum-cryptography/node_modules/@noble/hashes": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.2.0.tgz", - "integrity": "sha512-FZfhjEDbT5GRswV3C6uvLPHMiVD6lQBmpoX5+eSiPaMTXte/IKqI5dykDxzZB/WBeK/CDuQRBWarPdi3FNY2zQ==", - "funding": [ - { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - ] - }, "node_modules/ethers": { "version": "5.7.1", "resolved": "https://registry.npmjs.org/ethers/-/ethers-5.7.1.tgz", @@ -4728,6 +4647,7 @@ "version": "0.1.6", "resolved": "https://registry.npmjs.org/ethjs-util/-/ethjs-util-0.1.6.tgz", "integrity": "sha512-CUnVOQq7gSpDHZVVrQW8ExxUETWrnrvXYvYz55wOU8Uj4VCgw56XC2B/fVqQN+f7gmrnRHSLVnFAwsCuNwji8w==", + "license": "MIT", "dependencies": { "is-hex-prefixed": "1.0.0", "strip-hex-prefix": "1.0.0" @@ -4808,6 +4728,18 @@ "node": ">=4" } }, + "node_modules/extract-files": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/extract-files/-/extract-files-9.0.0.tgz", + "integrity": "sha512-CvdFfHkC95B4bBBk36hcEmvdR2awOdhhVUYH6S/zrVj3477zven/fJMYg7121h4T1xHZC+tetUpubpAhxwI7hQ==", + "license": "MIT", + "engines": { + "node": "^10.17.0 || ^12.0.0 || >= 13.7.0" + }, + "funding": { + "url": "https://github.com/sponsors/jaydenseric" + } + }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -5174,6 +5106,44 @@ "integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==", "dev": true }, + "node_modules/graphql": { + "version": "16.10.0", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.10.0.tgz", + "integrity": "sha512-AjqGKbDGUFRKIRCP9tCKiIGHyriz2oHEbPIbEtcSLSs4YjReZOIPQQWek4+6hjw62H9QShXHyaGivGiYVLeYFQ==", + "license": "MIT", + "peer": true, + "engines": { + "node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0" + } + }, + "node_modules/graphql-request": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/graphql-request/-/graphql-request-4.3.0.tgz", + "integrity": "sha512-2v6hQViJvSsifK606AliqiNiijb1uwWp6Re7o0RTyH+uRTv/u7Uqm2g4Fjq/LgZIzARB38RZEvVBFOQOVdlBow==", + "license": "MIT", + "dependencies": { + "cross-fetch": "^3.1.5", + "extract-files": "^9.0.0", + "form-data": "^3.0.0" + }, + "peerDependencies": { + "graphql": "14 - 16" + } + }, + "node_modules/graphql-request/node_modules/form-data": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.2.tgz", + "integrity": "sha512-sJe+TQb2vIaIyO783qN6BlMYWMw3WBOHA1Ay2qxsnjuafEOQFJ2JakedOQirT6D5XPRxDvS7AHYyem9fTpb4LQ==", + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -5435,6 +5405,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-hex-prefixed/-/is-hex-prefixed-1.0.0.tgz", "integrity": "sha512-WvtOiug1VFrE9v1Cydwm+FnXd3+w9GaeVUss5W4v/SLy3UW00vP+6iNF2SdnfiBoLy4bTqVdkftNGTUeOFVsbA==", + "license": "MIT", "engines": { "node": ">=6.5.0", "npm": ">=3" @@ -6553,6 +6524,12 @@ "node": ">= 8" } }, + "node_modules/micro-ftch": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/micro-ftch/-/micro-ftch-0.3.1.tgz", + "integrity": "sha512-/0LLxhzP0tfiR5hcQebtudP56gUurs2CLkGarnCiB/OqEyUFQ6U3paQi/tgLv0hBJYt2rnr9MNpxz4fiiugstg==", + "license": "MIT" + }, "node_modules/micromatch": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.4.tgz", @@ -6664,9 +6641,10 @@ } }, "node_modules/node-fetch": { - "version": "2.6.11", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.11.tgz", - "integrity": "sha512-4I6pdBY1EthSqDmJkiNk3JIT8cswwR9nfeW/cPdUagJYEQG7R95WRH74wpz7ma8Gh/9dI9FP+OU+0E4FvtA55w==", + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "license": "MIT", "dependencies": { "whatwg-url": "^5.0.0" }, @@ -7610,6 +7588,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/strip-hex-prefix/-/strip-hex-prefix-1.0.0.tgz", "integrity": "sha512-q8d4ue7JGEiVcypji1bALTos+0pWtyGlivAWyPuTkHzuTCJqrK9sWxYQZUq6Nq3cuyv3bm734IhHvHtGGURU6A==", + "license": "MIT", "dependencies": { "is-hex-prefixed": "1.0.0" }, @@ -7996,12 +7975,14 @@ "node_modules/tweetnacl": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", - "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==" + "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==", + "license": "Unlicense" }, "node_modules/tweetnacl-util": { "version": "0.15.1", "resolved": "https://registry.npmjs.org/tweetnacl-util/-/tweetnacl-util-0.15.1.tgz", - "integrity": "sha512-RKJBIj8lySrShN4w6i/BonWp2Z/uxwC3h4y7xsRrpP59ZboCd0GpEVsOnMDYLMmKBpYhb5TgHzZXy7wTfYFBRw==" + "integrity": "sha512-RKJBIj8lySrShN4w6i/BonWp2Z/uxwC3h4y7xsRrpP59ZboCd0GpEVsOnMDYLMmKBpYhb5TgHzZXy7wTfYFBRw==", + "license": "Unlicense" }, "node_modules/type-check": { "version": "0.4.0", @@ -8948,29 +8929,6 @@ "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==", "dev": true }, - "@chainsafe/as-sha256": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/@chainsafe/as-sha256/-/as-sha256-0.3.1.tgz", - "integrity": "sha512-hldFFYuf49ed7DAakWVXSJODuq3pzJEguD8tQ7h+sGkM18vja+OFoJI9krnGmgzyuZC2ETX0NOIcCTy31v2Mtg==" - }, - "@chainsafe/persistent-merkle-tree": { - "version": "0.4.2", - "resolved": "https://registry.npmjs.org/@chainsafe/persistent-merkle-tree/-/persistent-merkle-tree-0.4.2.tgz", - "integrity": "sha512-lLO3ihKPngXLTus/L7WHKaw9PnNJWizlOF1H9NNzHP6Xvh82vzg9F2bzkXhYIFshMZ2gTCEz8tq6STe7r5NDfQ==", - "requires": { - "@chainsafe/as-sha256": "^0.3.1" - } - }, - "@chainsafe/ssz": { - "version": "0.9.4", - "resolved": "https://registry.npmjs.org/@chainsafe/ssz/-/ssz-0.9.4.tgz", - "integrity": "sha512-77Qtg2N1ayqs4Bg/wvnWfg5Bta7iy7IRh8XqXh7oNMeP2HBbBwx8m6yTpA8p0EHItWPEBkgZd5S5/LSlp3GXuQ==", - "requires": { - "@chainsafe/as-sha256": "^0.3.1", - "@chainsafe/persistent-merkle-tree": "^0.4.2", - "case": "^1.6.3" - } - }, "@colors/colors": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", @@ -9022,13 +8980,13 @@ "integrity": "sha512-tqsQiBQDQdmPWE1xkkBq4rlSW5QZpLOUJ5RJh2/9fug+q9tnUhuZoVLk7s0scUIKTOzEtR72DFBXI4WiZcMpvw==" }, "@ethereumjs/util": { - "version": "8.0.5", - "resolved": "https://registry.npmjs.org/@ethereumjs/util/-/util-8.0.5.tgz", - "integrity": "sha512-259rXKK3b3D8HRVdRmlOEi6QFvwxdt304hhrEAmpZhsj7ufXEOTIc9JRZPMnXatKjECokdLNBcDOFBeBSzAIaw==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@ethereumjs/util/-/util-8.1.0.tgz", + "integrity": "sha512-zQ0IqbdX8FZ9aw11vP+dZkKDkS+kgIvQPHnSAXzP9pLu+Rfu3D3XEeLbicvoXJTYnhZiPmsZUxgdzXwNKxRPbA==", "requires": { - "@chainsafe/ssz": "0.9.4", "@ethereumjs/rlp": "^4.0.1", - "ethereum-cryptography": "^1.1.2" + "ethereum-cryptography": "^2.0.0", + "micro-ftch": "^0.3.1" } }, "@ethersproject/abi": { @@ -9845,13 +9803,13 @@ "integrity": "sha512-Z7C/xXCiGWsg0KuKsHTKJxbWhpI3Vs5GwLfOean7MGyVFGqdRgBbAjOCh6u4bbjPc/8MJ2pZmK/0DLdCbivLDA==" }, "@metamask/eth-sig-util": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/@metamask/eth-sig-util/-/eth-sig-util-5.0.2.tgz", - "integrity": "sha512-RU6fG/H6/UlBol221uBkq5C7w3TwLK611nEZliO2u+kO0vHKGBXnIPlhI0tzKUigjhUeOd9mhCNbNvhh0LKt9Q==", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@metamask/eth-sig-util/-/eth-sig-util-5.1.0.tgz", + "integrity": "sha512-mlgziIHYlA9pi/XZerChqg4NocdOgBPB9NmxgXWQO2U2hH8RGOJQrz6j/AIKkYxgCMIE2PY000+joOwXfzeTDQ==", "requires": { - "@ethereumjs/util": "^8.0.0", - "bn.js": "^4.11.8", - "ethereum-cryptography": "^1.1.2", + "@ethereumjs/util": "^8.0.6", + "bn.js": "^4.12.0", + "ethereum-cryptography": "^2.0.0", "ethjs-util": "^0.1.6", "tweetnacl": "^1.0.3", "tweetnacl-util": "^0.15.1" @@ -10088,10 +10046,18 @@ } } }, - "@noble/secp256k1": { - "version": "1.7.1", - "resolved": "https://registry.npmjs.org/@noble/secp256k1/-/secp256k1-1.7.1.tgz", - "integrity": "sha512-hOUk6AyBFmqVrv7k5WAw/LpszxVbj9gGN4JRkIX52fdFAj1UA61KXmZDvqVEm+pOyec3+fIeZB02LYa/pWOArw==" + "@noble/curves": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.4.2.tgz", + "integrity": "sha512-TavHr8qycMChk8UwMld0ZDRvatedkzWfH8IiaeGCfymOP5i0hSCozz9vHOL0nkwk7HRMlFnAiKpS2jrUmSybcw==", + "requires": { + "@noble/hashes": "1.4.0" + } + }, + "@noble/hashes": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.4.0.tgz", + "integrity": "sha512-V1JJ1WTRUqHHrOSh597hURcMqVKVGL/ea3kv0gSnEdsEZ0/+VyPghM1lMNGc00z7CIQorSvbKpuJkxvuHbvdbg==" }, "@nodelib/fs.scandir": { "version": "2.1.5", @@ -10130,12 +10096,13 @@ } }, "@polymarket/clob-client": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/@polymarket/clob-client/-/clob-client-1.4.0.tgz", - "integrity": "sha512-nUDUDiuH0VrYPfiy16pj2fdgWYFRwy7ezWArTy8L560N3/T6p7+LpSzL4lcUZTw+V6mOVOZJ8GwqW05Wlh7WJw==", + "version": "4.12.0", + "resolved": "https://registry.npmjs.org/@polymarket/clob-client/-/clob-client-4.12.0.tgz", + "integrity": "sha512-7+8WdbPzMkMVTa2hD2JA7ynAKazrsI37czQVBlZEO9tShzRyCPrJtl89cHebTXOQfP+8V2T3Ny7JkZxAofxpQQ==", "requires": { - "@polymarket/order-utils": "^1.3.1", + "@polymarket/order-utils": "^2.1.0", "axios": "^0.27.2", + "browser-or-node": "^2.1.1", "ethers": "^5.7.1" }, "dependencies": { @@ -10188,89 +10155,36 @@ } }, "@polymarket/order-utils": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/@polymarket/order-utils/-/order-utils-1.3.1.tgz", - "integrity": "sha512-+ml9tjIYvpEoWO98MAZwlq0V3fHDAW8oXOEJL0oj58CidFDTzgLGflhhzhDOs4DTEbjaUGD8mbFcuIN4OEzBBQ==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@polymarket/order-utils/-/order-utils-2.1.0.tgz", + "integrity": "sha512-vUFj1WiEtm4vB0dxx2NweKKioPu7ehBoJ8fTTaVbR8Dur6AazVWyS+KhgrDE66fKTNneOxxgfdEpbNgxZ4pOIA==", "requires": { "@metamask/eth-sig-util": "^5.0.0", "ethers": "^5.7.1" - }, - "dependencies": { - "ethers": { - "version": "5.7.2", - "resolved": "https://registry.npmjs.org/ethers/-/ethers-5.7.2.tgz", - "integrity": "sha512-wswUsmWo1aOK8rR7DIKiWSw9DbLWe6x98Jrn8wcTflTVvaXhAMaB5zGAXy0GYQEQp9iO1iSHWVyARQm11zUtyg==", - "requires": { - "@ethersproject/abi": "5.7.0", - "@ethersproject/abstract-provider": "5.7.0", - "@ethersproject/abstract-signer": "5.7.0", - "@ethersproject/address": "5.7.0", - "@ethersproject/base64": "5.7.0", - "@ethersproject/basex": "5.7.0", - "@ethersproject/bignumber": "5.7.0", - "@ethersproject/bytes": "5.7.0", - "@ethersproject/constants": "5.7.0", - "@ethersproject/contracts": "5.7.0", - "@ethersproject/hash": "5.7.0", - "@ethersproject/hdnode": "5.7.0", - "@ethersproject/json-wallets": "5.7.0", - "@ethersproject/keccak256": "5.7.0", - "@ethersproject/logger": "5.7.0", - "@ethersproject/networks": "5.7.1", - "@ethersproject/pbkdf2": "5.7.0", - "@ethersproject/properties": "5.7.0", - "@ethersproject/providers": "5.7.2", - "@ethersproject/random": "5.7.0", - "@ethersproject/rlp": "5.7.0", - "@ethersproject/sha2": "5.7.0", - "@ethersproject/signing-key": "5.7.0", - "@ethersproject/solidity": "5.7.0", - "@ethersproject/strings": "5.7.0", - "@ethersproject/transactions": "5.7.0", - "@ethersproject/units": "5.7.0", - "@ethersproject/wallet": "5.7.0", - "@ethersproject/web": "5.7.1", - "@ethersproject/wordlists": "5.7.0" - } - } } }, "@scure/base": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@scure/base/-/base-1.1.1.tgz", - "integrity": "sha512-ZxOhsSyxYwLJj3pLZCefNitxsj093tb2vq90mp2txoYeBqbcjDjqFhyM8eUjq/uFm6zJ+mUuqxlS2FkuSY1MTA==" + "version": "1.1.9", + "resolved": "https://registry.npmjs.org/@scure/base/-/base-1.1.9.tgz", + "integrity": "sha512-8YKhl8GHiNI/pU2VMaofa2Tor7PJRAjwQLBBuilkJ9L5+13yVbC7JO/wS7piioAvPSwR3JKM1IJ/u4xQzbcXKg==" }, "@scure/bip32": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/@scure/bip32/-/bip32-1.1.5.tgz", - "integrity": "sha512-XyNh1rB0SkEqd3tXcXMi+Xe1fvg+kUIcoRIEujP1Jgv7DqW2r9lg3Ah0NkFaCs9sTkQAQA8kw7xiRXzENi9Rtw==", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@scure/bip32/-/bip32-1.4.0.tgz", + "integrity": "sha512-sVUpc0Vq3tXCkDGYVWGIZTRfnvu8LoTDaev7vbwh0omSvVORONr960MQWdKqJDCReIEmTj3PAr73O3aoxz7OPg==", "requires": { - "@noble/hashes": "~1.2.0", - "@noble/secp256k1": "~1.7.0", - "@scure/base": "~1.1.0" - }, - "dependencies": { - "@noble/hashes": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.2.0.tgz", - "integrity": "sha512-FZfhjEDbT5GRswV3C6uvLPHMiVD6lQBmpoX5+eSiPaMTXte/IKqI5dykDxzZB/WBeK/CDuQRBWarPdi3FNY2zQ==" - } + "@noble/curves": "~1.4.0", + "@noble/hashes": "~1.4.0", + "@scure/base": "~1.1.6" } }, "@scure/bip39": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@scure/bip39/-/bip39-1.1.1.tgz", - "integrity": "sha512-t+wDck2rVkh65Hmv280fYdVdY25J9YeEUIgn2LG1WM6gxFkGzcksoDiUkWVpVp3Oex9xGC68JU2dSbUfwZ2jPg==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@scure/bip39/-/bip39-1.3.0.tgz", + "integrity": "sha512-disdg7gHuTDZtY+ZdkmLpPCk7fxZSu3gBiEGuoC1XYxv9cGx3Z6cpTggCgW6odSOOIXCiDjuGejW+aJKCY/pIQ==", "requires": { - "@noble/hashes": "~1.2.0", - "@scure/base": "~1.1.0" - }, - "dependencies": { - "@noble/hashes": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.2.0.tgz", - "integrity": "sha512-FZfhjEDbT5GRswV3C6uvLPHMiVD6lQBmpoX5+eSiPaMTXte/IKqI5dykDxzZB/WBeK/CDuQRBWarPdi3FNY2zQ==" - } + "@noble/hashes": "~1.4.0", + "@scure/base": "~1.1.6" } }, "@sinclair/typebox": { @@ -11143,6 +11057,11 @@ "resolved": "https://registry.npmjs.org/brorand/-/brorand-1.1.0.tgz", "integrity": "sha512-cKV8tMCEpQs4hK/ik71d6LrPOnpkpGBR0wzxqr68g2m/LB2GxVYQroAjMJZRVM1Y4BCjCKc3vAamxSzOY2RP+w==" }, + "browser-or-node": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/browser-or-node/-/browser-or-node-2.1.1.tgz", + "integrity": "sha512-8CVjaLJGuSKMVTxJ2DpBl5XnlNDiT4cQFeuCJJrvJmts9YrTZDizTX7PjC2s6W4x+MBGZeEY6dGMrF04/6Hgqg==" + }, "browserslist": { "version": "4.21.1", "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.21.1.tgz", @@ -11207,11 +11126,6 @@ "integrity": "sha512-HpQhpzTGGPVMnCjIomjt+jvyUu8vNFo3TaDiZ/RcoTrlOq/5+tC8zHdsbgFB6MxmaY+jCpsH09aD80Bb4Ow3Sg==", "dev": true }, - "case": { - "version": "1.6.3", - "resolved": "https://registry.npmjs.org/case/-/case-1.6.3.tgz", - "integrity": "sha512-mzDSXIPaFwVDvZAHqZ9VlbyF4yyXRuX6IvB06WvPYkqJVO24kX1PPhv9bfpKNFZyxYFmmgo03HUiD8iklmJYRQ==" - }, "chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", @@ -11391,6 +11305,14 @@ "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", "dev": true }, + "cross-fetch": { + "version": "3.1.8", + "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.8.tgz", + "integrity": "sha512-cvA+JwZoU0Xq+h6WkMvAUqPEYy92Obet6UdKLfW60qn99ftItKjB5T+BkyWOFWe2pUyfQ+IJHmpOTznqk1M6Kg==", + "requires": { + "node-fetch": "^2.6.12" + } + }, "cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -11745,21 +11667,14 @@ "dev": true }, "ethereum-cryptography": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/ethereum-cryptography/-/ethereum-cryptography-1.2.0.tgz", - "integrity": "sha512-6yFQC9b5ug6/17CQpCyE3k9eKBMdhyVjzUy1WkiuY/E4vj/SXDBbCw8QEIaXqf0Mf2SnY6RmpDcwlUmBSS0EJw==", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ethereum-cryptography/-/ethereum-cryptography-2.2.1.tgz", + "integrity": "sha512-r/W8lkHSiTLxUxW8Rf3u4HGB0xQweG2RyETjywylKZSzLWoWAijRz8WCuOtJ6wah+avllXBqZuk29HCCvhEIRg==", "requires": { - "@noble/hashes": "1.2.0", - "@noble/secp256k1": "1.7.1", - "@scure/bip32": "1.1.5", - "@scure/bip39": "1.1.1" - }, - "dependencies": { - "@noble/hashes": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.2.0.tgz", - "integrity": "sha512-FZfhjEDbT5GRswV3C6uvLPHMiVD6lQBmpoX5+eSiPaMTXte/IKqI5dykDxzZB/WBeK/CDuQRBWarPdi3FNY2zQ==" - } + "@noble/curves": "1.4.2", + "@noble/hashes": "1.4.0", + "@scure/bip32": "1.4.0", + "@scure/bip39": "1.3.0" } }, "ethers": { @@ -11890,6 +11805,11 @@ "tmp": "^0.0.33" } }, + "extract-files": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/extract-files/-/extract-files-9.0.0.tgz", + "integrity": "sha512-CvdFfHkC95B4bBBk36hcEmvdR2awOdhhVUYH6S/zrVj3477zven/fJMYg7121h4T1xHZC+tetUpubpAhxwI7hQ==" + }, "fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -12160,6 +12080,34 @@ "integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==", "dev": true }, + "graphql": { + "version": "16.10.0", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.10.0.tgz", + "integrity": "sha512-AjqGKbDGUFRKIRCP9tCKiIGHyriz2oHEbPIbEtcSLSs4YjReZOIPQQWek4+6hjw62H9QShXHyaGivGiYVLeYFQ==", + "peer": true + }, + "graphql-request": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/graphql-request/-/graphql-request-4.3.0.tgz", + "integrity": "sha512-2v6hQViJvSsifK606AliqiNiijb1uwWp6Re7o0RTyH+uRTv/u7Uqm2g4Fjq/LgZIzARB38RZEvVBFOQOVdlBow==", + "requires": { + "cross-fetch": "^3.1.5", + "extract-files": "^9.0.0", + "form-data": "^3.0.0" + }, + "dependencies": { + "form-data": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.2.tgz", + "integrity": "sha512-sJe+TQb2vIaIyO783qN6BlMYWMw3WBOHA1Ay2qxsnjuafEOQFJ2JakedOQirT6D5XPRxDvS7AHYyem9fTpb4LQ==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + } + } + }, "has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -13197,6 +13145,11 @@ "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", "dev": true }, + "micro-ftch": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/micro-ftch/-/micro-ftch-0.3.1.tgz", + "integrity": "sha512-/0LLxhzP0tfiR5hcQebtudP56gUurs2CLkGarnCiB/OqEyUFQ6U3paQi/tgLv0hBJYt2rnr9MNpxz4fiiugstg==" + }, "micromatch": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.4.tgz", @@ -13290,9 +13243,9 @@ } }, "node-fetch": { - "version": "2.6.11", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.11.tgz", - "integrity": "sha512-4I6pdBY1EthSqDmJkiNk3JIT8cswwR9nfeW/cPdUagJYEQG7R95WRH74wpz7ma8Gh/9dI9FP+OU+0E4FvtA55w==", + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", "requires": { "whatwg-url": "^5.0.0" } diff --git a/package.json b/package.json index 18a1765..d949ccd 100644 --- a/package.json +++ b/package.json @@ -39,11 +39,12 @@ "@nestjs/axios": "^2.0.0", "@nestjs/common": "^9.4.2", "@nestjs/core": "^9.4.2", - "@polymarket/clob-client": "^1.4.0", + "@polymarket/clob-client": "^4.12.0", "axios": "^1.3.4", "commander": "^10.0.1", "ethers": "^5.7.1", "figlet": "^1.6.0", + "graphql-request": "^4.3.0", "reflect-metadata": "0.1.13", "rimraf": "3.0.2" }, diff --git a/src/services/config.service.ts b/src/services/config.service.ts index d75a620..69ae2dc 100644 --- a/src/services/config.service.ts +++ b/src/services/config.service.ts @@ -31,6 +31,7 @@ export class ConfigService { passphrase: '', rpcProvider: '', privateKey: '', + funderAddress: '' }; if(!existsSync(homedir() + sep + polyCliDir)){ mkdirSync(homedir() + sep + polyCliDir); diff --git a/src/services/contract.service.ts b/src/services/contract.service.ts index c233c86..8fa13c5 100644 --- a/src/services/contract.service.ts +++ b/src/services/contract.service.ts @@ -21,7 +21,6 @@ export class ContractService { console.log("Please provide valid private key and rpc provider in config.json file"); } } - async setAllowance(amountOfAllowedUSDC: number): Promise { const currentBlockGasLimit = await this.getBlockGasLimit(); const currentGasPrice = await this.polygonProvider.getGasPrice(); diff --git a/src/services/polymarket.service.spec.ts b/src/services/polymarket.service.spec.ts index 1b6b21f..a675aab 100644 --- a/src/services/polymarket.service.spec.ts +++ b/src/services/polymarket.service.spec.ts @@ -1,238 +1,255 @@ -import { ClobClient, OrderBookSummary, OrderType, Side } from '@polymarket/clob-client'; -import { ConfigService } from './config.service'; -import { PolymarketService } from './polymarket.service'; -import { Test } from '@nestjs/testing'; -import { ethers } from 'ethers'; -import { SignatureType, SignedOrder } from '@polymarket/order-utils'; - -const markets = [{ - "condition_id": "0xa00a22b16d602abf9ed695404df68a71ddd4ef05573bf9590de4f0fccf096c93", - "question_id": "0xaf090077f0db7aa7f97051e04fcd764d86970004a37b3150ae7a681b5b3e495c", - "tokens": [ - { - "token_id": "9629446620718684243744463725282080039675086062123106562256171337393905586388", - "outcome": "No" - }, - { - "token_id": "43232097181918994738032241755006123258571385315939394755006203919277954135565", - "outcome": "Yes" - } +import { + ClobClient, + OrderBookSummary, + OrderType, +} from "@polymarket/clob-client"; +import { ConfigService } from "./config.service"; +import { Market, PolymarketService } from "./polymarket.service"; +import { Test } from "@nestjs/testing"; +import { ethers } from "ethers"; +import { Side, SignatureType, SignedOrder } from "@polymarket/order-utils"; +import { Side as ClobClientSide } from "@polymarket/clob-client"; + +const markets: Market[] = [ + { + condition_id: + "0xa00a22b16d602abf9ed695404df68a71ddd4ef05573bf9590de4f0fccf096c93", + question_id: + "0xaf090077f0db7aa7f97051e04fcd764d86970004a37b3150ae7a681b5b3e495c", + tokens: [ + { + token_id: + "9629446620718684243744463725282080039675086062123106562256171337393905586388", + outcome: "No", + price: 0.56, + winner: false, + }, + { + token_id: + "43232097181918994738032241755006123258571385315939394755006203919277954135565", + outcome: "Yes", + price: 0.56, + winner: false, + }, ], - "rewards": { - "min_size": 0, - "max_spread": 0, - "event_start_date": null, - "event_end_date": null, - "in_game_multiplier": 0, - "reward_epoch": 0 - }, - "description": "This market will resolve to \"Yes\" if the Boston Celtics become the 2022-23 NBA Champion. Otherwise, this market will resolve to \"No\".\n\nIf it is determined at any point that it is impossible for the Celtics to be the 2022-23 NBA Champion based on the rules of the NBA (e.g. they're eliminated in the playoffs), this market will immediately resolve to \"No.\"\n\nIf this team is still in contention to become the champion and the champion still isn't determined by October 24, 2023, 11:59:59 PM ET, this market will resolve 50-50.", - "question": "Will the Celtics be the 2022-23 NBA Champion?", - "active": true, - "closed": true, - "end_date_iso": "2023-06-17", - "game_start_time": null, - "seconds_delay": 0, - "minimum_order_size": "15", - "minimum_tick_size": "0.01", - "market_slug": "will-the-celtics-be-the-2022-23-nba-champion", - "icon": "https://polymarket-upload.s3.us-east-2.amazonaws.com/celtics.png", - "fpmm": "0x34EC3128703f4aC2D990A04776Bd5A0E451f6088", - "accepting_orders": false, - "maker_base_fee": 0, - "taker_base_fee": 0 -}, { - "condition_id": "0x757fe19cced3f2136ef1dc0e0163b9996a68a330a8d2338835e3b81a31fcac91", - "question_id": "0x8c7336ccc387ba779bfa886a638e6d81ecfb315c4ebdd7b099f505a16ce5f860", - "tokens": [ - { - "token_id": "14811968980410449224099097755442778591369245152075435522945362809904270343154", - "outcome": "Yes" - }, - { - "token_id": "57430235197990449398919000106517296481235279294973890917683113058548298509870", - "outcome": "No" - } + rewards: {incentiveProgram: "aadas",totalRewardPool: "sadasdas" }, + description: + 'This market will resolve to "Yes" if the Boston Celtics become the 2022-23 NBA Champion. Otherwise, this market will resolve to "No".\n\nIf it is determined at any point that it is impossible for the Celtics to be the 2022-23 NBA Champion based on the rules of the NBA (e.g. they\'re eliminated in the playoffs), this market will immediately resolve to "No."\n\nIf this team is still in contention to become the champion and the champion still isn\'t determined by October 24, 2023, 11:59:59 PM ET, this market will resolve 50-50.', + question: "Will the Celtics be the 2022-23 NBA Champion?", + active: true, + closed: true, + end_date_iso: "2023-06-17", + game_start_time: null, + seconds_delay: 0, + minimum_order_size: "15", + minimum_tick_size: "0.01", + market_slug: "will-the-celtics-be-the-2022-23-nba-champion", + icon: "https://polymarket-upload.s3.us-east-2.amazonaws.com/celtics.png", + fpmm: "0x34EC3128703f4aC2D990A04776Bd5A0E451f6088", + min_incentive_size: "0", + max_incentive_spread: "0.2", + category: "adsadsa" + }, + { + condition_id: + "0x757fe19cced3f2136ef1dc0e0163b9996a68a330a8d2338835e3b81a31fcac91", + question_id: + "0x8c7336ccc387ba779bfa886a638e6d81ecfb315c4ebdd7b099f505a16ce5f860", + tokens: [ + { + token_id: + "14811968980410449224099097755442778591369245152075435522945362809904270343154", + outcome: "Yes", + price: 0.56, + winner: false, + }, + { + token_id: + "57430235197990449398919000106517296481235279294973890917683113058548298509870", + outcome: "No", + price: 0.56, + winner: false, + }, ], - "rewards": { - "min_size": 0, - "max_spread": 0, - "event_start_date": null, - "event_end_date": null, - "in_game_multiplier": 0, - "reward_epoch": 0 + rewards: {incentiveProgram: "aadas",totalRewardPool: "sadasdas" }, + description: + "This market will resolve to “Yes” if Vivek Ramaswamy wins the 2024 nomination of the Republican Party for U.S. president. Otherwise, this market will resolve to “No”. \n\nThe resolution source for this market will be a consensus of official GOP sources, including https://www.gop.com. Any replacement of the nominee before election day will not change the resolution of the market.", + question: + "Will Vivek Ramaswamy win the U.S. 2024 Republican presidential nomination?", + active: true, + closed: false, + end_date_iso: "2024-09-10", + game_start_time: null, + seconds_delay: 0, + minimum_order_size: "15", + minimum_tick_size: "0.01", + market_slug: + "will-vivek-ramaswamy-win-the-us-2024-republican-presidential-nomination", + icon: "https://polymarket-upload.s3.us-east-2.amazonaws.com/vivek+ramaswamy.png", + fpmm: "0x055e0D264A2f865c7D5c0A58A2229F66135530FD", + min_incentive_size: "0", + max_incentive_spread: "0.2", + category: "adsadsa" + }, +]; + +const orderBook: OrderBookSummary = { + bids: [ + { + price: "0.5", + size: "100", }, - "description": "This market will resolve to “Yes” if Vivek Ramaswamy wins the 2024 nomination of the Republican Party for U.S. president. Otherwise, this market will resolve to “No”. \n\nThe resolution source for this market will be a consensus of official GOP sources, including https://www.gop.com. Any replacement of the nominee before election day will not change the resolution of the market.", - "question": "Will Vivek Ramaswamy win the U.S. 2024 Republican presidential nomination?", - "active": true, - "closed": false, - "end_date_iso": "2024-09-10", - "game_start_time": null, - "seconds_delay": 0, - "minimum_order_size": "15", - "minimum_tick_size": "0.01", - "market_slug": "will-vivek-ramaswamy-win-the-us-2024-republican-presidential-nomination", - "icon": "https://polymarket-upload.s3.us-east-2.amazonaws.com/vivek+ramaswamy.png", - "fpmm": "0x055e0D264A2f865c7D5c0A58A2229F66135530FD", - "accepting_orders": true, - "maker_base_fee": 0, - "taker_base_fee": 0 -}] - -const orderBook:OrderBookSummary = { - bids: [ - { - price: '0.5', - size: '100' - }, - { - price: '0.4', - size: '100' - } - ], - asks: [ - { - price: '0.6', - size: '100' - }, - { - price: '0.7', - size: '100' + { + price: "0.4", + size: "100", + }, + ], + asks: [ + { + price: "0.6", + size: "100", + }, + { + price: "0.7", + size: "100", + }, + ], + market: "marketID", + asset_id: "asset_id", + hash: "hash", + timestamp: 'timestamp' +}; + +describe("PolymarketService", () => { + let polymarketService: PolymarketService; + beforeAll(async () => { + //mock conifg service + const configService = { + get: (key: string) => { + if (key === "privateKey") { + const wallet = ethers.Wallet.createRandom(); + const privateKey = wallet.privateKey; + return privateKey; + } else { + return "something else"; } - ], - market: 'marketID', - asset_id: 'asset_id', - hash: 'hash' -} - -describe('PolymarketService', () => { - let polymarketService: PolymarketService; - beforeAll(async () => { - //mock conifg service - const configService = { - get: (key: string) => { - if (key === "privateKey") { - const wallet = ethers.Wallet.createRandom(); - const privateKey = wallet.privateKey; - return privateKey; - } else { - return "something else" - } - }, - getCreds: () => { - return { - key: 'something', - secret: 'secret', - passphrase: 'passphrase' - } - } + }, + getCreds: () => { + return { + key: "something", + secret: "secret", + passphrase: "passphrase", }; - const moduleRef = await Test.createTestingModule({ - providers: [PolymarketService, ConfigService], - }).overrideProvider(ConfigService) - .useValue(configService).compile(); - - polymarketService = moduleRef.get(PolymarketService); - jest.spyOn(polymarketService, 'getMarkets').mockImplementation(() => Promise.resolve(markets)); + }, + }; + const moduleRef = await Test.createTestingModule({ + providers: [PolymarketService, ConfigService], + }) + .overrideProvider(ConfigService) + .useValue(configService) + .compile(); + + polymarketService = moduleRef.get(PolymarketService); + jest + .spyOn(polymarketService, "fetchAllMarkets") + .mockImplementation(() => Promise.resolve(markets)); + }); + + it("should only return markets accepting orders ", async () => { + const marketsAcceptingOrders = + await polymarketService.getMarketsAcceptingOrders(); + expect(marketsAcceptingOrders.length).toBe(1); + expect(marketsAcceptingOrders[0].yes.token_id).toBe( + "14811968980410449224099097755442778591369245152075435522945362809904270343154" + ); + }); + + it("should call postOrder with BUY OrderType.GTC", async () => { + const signedOrder: SignedOrder = { + signature: "", + salt: "", + maker: "", + signer: "", + taker: "", + tokenId: "", + makerAmount: "", + takerAmount: "", + expiration: "", + nonce: "", + feeRateBps: "", + side: Side.BUY, + signatureType: SignatureType.EOA, + }; + // jest.spyOn(polymarketService, 'determineMakerOrTakerFee').mockImplementation(() => Promise.resolve({ fee: 0, side: 'taker' })); + + const getOrderBookSpy = jest.spyOn(ClobClient.prototype, "getOrderBook"); + getOrderBookSpy.mockImplementation((tokenID): Promise => { + // Mocked implementation + return Promise.resolve(orderBook); }); - it('should only return markets accepting orders ', async () => { - const marketsAcceptingOrders = await polymarketService.getMarketsAcceptingOrders(); - expect(marketsAcceptingOrders.length).toBe(1); - expect(marketsAcceptingOrders[0].token_0.token_id).toBe("14811968980410449224099097755442778591369245152075435522945362809904270343154"); + const createOrderBookSpy = jest.spyOn(ClobClient.prototype, "createOrder"); + createOrderBookSpy.mockImplementation((userOrder): Promise => { + // Mocked implementation + return Promise.resolve(signedOrder); }); - it('should taker fee equal to 200', async () => { - const spy = jest.spyOn(polymarketService, 'getFeeRateBps').mockImplementation(() => Promise.resolve(200)); - const takerFee = await polymarketService.determineMakerOrTakerFee('14811968980410449224099097755442778591369245152075435522945362809904270343154', Side.BUY, 100, orderBook, 0.6); - expect(spy).toHaveBeenCalledWith('14811968980410449224099097755442778591369245152075435522945362809904270343154', 'taker'); - expect(takerFee).toStrictEqual({ fee: 200, side: 'taker' }); + const postOrderSpy = jest.spyOn(ClobClient.prototype, "postOrder"); + postOrderSpy.mockImplementation((order, orderType): Promise => { + // Mocked implementation + return Promise.resolve({}); }); - - it('should return maker fee equal to 0', async () => { - const spy = jest.spyOn(polymarketService, 'getFeeRateBps').mockImplementation(() => Promise.resolve(0)); - const makerFee = await polymarketService.determineMakerOrTakerFee('14811968980410449224099097755442778591369245152075435522945362809904270343154', Side.SELL, 100, orderBook, 0.8); - expect(spy).toHaveBeenCalledWith('14811968980410449224099097755442778591369245152075435522945362809904270343154', 'maker'); - expect(makerFee).toStrictEqual({ fee: 0, side: 'maker' }); + const resp = await polymarketService.marketOrder( + "tokenID", + ClobClientSide.BUY, + 20, + 0.5 + ); + expect(postOrderSpy).toHaveBeenCalledWith(signedOrder, OrderType.GTC); + postOrderSpy.mockRestore(); + createOrderBookSpy.mockRestore(); + }); + + it("should call postOrder with SELL OrderType.GTC", async () => { + const signedOrder: SignedOrder = { + signature: "", + salt: "", + maker: "", + signer: "", + taker: "", + tokenId: "", + makerAmount: "", + takerAmount: "", + expiration: "", + nonce: "", + feeRateBps: "", + side: Side.SELL, + signatureType: SignatureType.EOA, + }; + + const getOrderBookSpy = jest.spyOn(ClobClient.prototype, "getOrderBook"); + getOrderBookSpy.mockImplementation((tokenID): Promise => { + // Mocked implementation + return Promise.resolve(orderBook); }); - it('should call postOrder with BUY OrderType.FOK', async () => { - const signedOrder:SignedOrder = { - signature: '', - salt: '', - maker: '', - signer: '', - taker: '', - tokenId: '', - makerAmount: '', - takerAmount: '', - expiration: '', - nonce: '', - feeRateBps: '', - side: Side.BUY, - signatureType: SignatureType.EOA - }; - jest.spyOn(polymarketService, 'determineMakerOrTakerFee').mockImplementation(() => Promise.resolve({ fee: 0, side: 'taker' })); - - const getOrderBookSpy = jest.spyOn(ClobClient.prototype, 'getOrderBook'); - getOrderBookSpy.mockImplementation((tokenID):Promise => { - // Mocked implementation - return Promise.resolve(orderBook); - }); - - const createOrderBookSpy = jest.spyOn(ClobClient.prototype, 'createOrder'); - createOrderBookSpy.mockImplementation((userOrder):Promise => { - // Mocked implementation - return Promise.resolve(signedOrder); - }); - - const postOrderSpy = jest.spyOn(ClobClient.prototype, 'postOrder'); - postOrderSpy.mockImplementation((order,orderType,optionalParams):Promise => { - // Mocked implementation - return Promise.resolve({}); - }); - const resp = await polymarketService.marketOrder('tokenID', Side.BUY, 20, 0.50,); - expect(postOrderSpy).toHaveBeenCalledWith(signedOrder, OrderType.FOK); - postOrderSpy.mockRestore(); - createOrderBookSpy.mockRestore(); + const createOrderBookSpy = jest.spyOn(ClobClient.prototype, "createOrder"); + createOrderBookSpy.mockImplementation((userOrder): Promise => { + // Mocked implementation + return Promise.resolve(signedOrder); }); - it('should call postOrder with SELL OrderType.GTC', async () => { - const signedOrder:SignedOrder = { - signature: '', - salt: '', - maker: '', - signer: '', - taker: '', - tokenId: '', - makerAmount: '', - takerAmount: '', - expiration: '', - nonce: '', - feeRateBps: '', - side: Side.SELL, - signatureType: SignatureType.EOA - }; - - const getOrderBookSpy = jest.spyOn(ClobClient.prototype, 'getOrderBook'); - getOrderBookSpy.mockImplementation((tokenID):Promise => { - // Mocked implementation - return Promise.resolve(orderBook); - }); - - const createOrderBookSpy = jest.spyOn(ClobClient.prototype, 'createOrder'); - createOrderBookSpy.mockImplementation((userOrder):Promise => { - // Mocked implementation - return Promise.resolve(signedOrder); - }); - - const postOrderSpy = jest.spyOn(ClobClient.prototype, 'postOrder'); - postOrderSpy.mockImplementation((order,orderType,optionalParams):Promise => { - // Mocked implementation - return Promise.resolve({}); - }); - const resp = await polymarketService.marketOrder('tokenID', Side.SELL, 20, 0.50,); - expect(postOrderSpy).toHaveBeenCalledWith(signedOrder, OrderType.GTC); + const postOrderSpy = jest.spyOn(ClobClient.prototype, "postOrder"); + postOrderSpy.mockImplementation((order, orderType): Promise => { + // Mocked implementation + return Promise.resolve({}); }); - -}); \ No newline at end of file + const resp = await polymarketService.marketOrder( + "tokenID", + ClobClientSide.SELL, + 20, + 0.5 + ); + expect(postOrderSpy).toHaveBeenCalledWith(signedOrder, OrderType.GTC); + }); +}); diff --git a/src/services/polymarket.service.ts b/src/services/polymarket.service.ts index b4daef2..ba7c876 100644 --- a/src/services/polymarket.service.ts +++ b/src/services/polymarket.service.ts @@ -6,12 +6,50 @@ import { OrderType, Side, } from "@polymarket/clob-client/dist/types"; -import axios from "axios"; import { ethers } from "ethers"; import { ConfigService } from "./config.service"; let creds: ApiKeyCreds; const CLOB_API_ENDPOINT = "https://clob.polymarket.com/"; -type FeeResponse = { side: 'taker' | 'maker', fee: number }; +const GAMMA_API_ENDPOINT = "https://gamma-api.polymarket.com/"; +interface Token { + token_id: string; + outcome: string; + price: number; + winner: boolean; +} + +interface Rewards { + incentiveProgram: string; + totalRewardPool: string; +} + +export interface Market { + condition_id: string; + question_id: string; + tokens: [Token, Token]; // exactly two tokens + rewards: Rewards; + minimum_order_size: string; + minimum_tick_size: string; + description: string; + category: string; + end_date_iso: string; + game_start_time: string; + question: string; + market_slug: string; + min_incentive_size: string; + max_incentive_spread: string; + active: boolean; + closed: boolean; + seconds_delay: number; + icon: string; + fpmm: string; +} +interface MarketsResponse { + limit: number; + count: number; + next_cursor: string; + data: Market[]; +} @Injectable() export class PolymarketService { clobClient: ClobClient; @@ -37,88 +75,60 @@ export class PolymarketService { CLOB_API_ENDPOINT, Chain.POLYGON, this.signer, - creds + creds, + 2, + this.configService.get("funderAddress") ); } + async fetchAllMarkets(): Promise { + let allMarkets: Market[] = []; + let nextCursor = ""; // start from the beginning - async getMarkets(): Promise { - const response = await axios.get( - `${CLOB_API_ENDPOINT}markets`, - ); - return response.data; - } - - async getMarketsAcceptingOrders(): Promise { - const markets = await this.getMarkets(); - return markets.filter(market => market.accepting_orders).map((market) => { - return { token_0: market.tokens[0], token_1: market.tokens[1], question: market.question }; - }); - } + while (true) { + const response: MarketsResponse = await this.clobClient.getMarkets( + nextCursor + ); - async determineMakerOrTakerFee(tokenId: string, side: Side, size: number, orderBook: any, price: number): Promise<{ side: 'taker' | 'maker', fee: number }> { + // Add the newly fetched markets to the full list + allMarkets.push(...response.data); - const resp: FeeResponse = { - side: 'taker', - fee: 0 - } - if (side === Side.SELL) { - //check bids - const bids = orderBook.bids; - const bidsWithPriceAsNumber = bids.map((bid) => { return { price: parseFloat(bid.price), size: parseFloat(bid.size) } }); - const bidsWithPriceHigherThanPrice = bidsWithPriceAsNumber.filter((bid) => bid.price >= price); - const sumOfSizeOfBidsWithPriceHigherThanPrice = bidsWithPriceHigherThanPrice.reduce((acc, val) => val.size, 0); - if (sumOfSizeOfBidsWithPriceHigherThanPrice >= size) { - //get taker - const takerFee = await this.getFeeRateBps(tokenId, 'taker'); - resp.side = 'taker'; - resp.fee = takerFee; - return resp; - } else { - const makerFee = await this.getFeeRateBps(tokenId, 'maker'); - resp.side = 'maker'; - resp.fee = makerFee; - return resp; - } - } else if (side === Side.BUY) { - //check asks - const asks = orderBook.asks; - const asksWithPriceAsNumber = asks.map((ask) => { return { price: parseFloat(ask.price), size: parseFloat(ask.size) } }); - const asksWithPriceLowerThanPrice = asksWithPriceAsNumber.filter((ask) => ask.price <= price); - const sumOfSizeOfAsksWithPriceLowerThanPrice = asksWithPriceLowerThanPrice.reduce((acc, val) => acc + val.size, 0); - if (sumOfSizeOfAsksWithPriceLowerThanPrice >= size) { - //get taker - const takerFee = await this.getFeeRateBps(tokenId, 'taker'); - resp.side = 'taker'; - resp.fee = takerFee; - return resp; - } else { - const makerFee = await this.getFeeRateBps(tokenId, 'maker'); - resp.side = 'maker'; - resp.fee = makerFee; - return resp; + // Check if we've reached the end + if (response.next_cursor === "LTE=" || !response.next_cursor) { + break; } + // Update nextCursor to fetch the next page + nextCursor = response.next_cursor; } + + return allMarkets; } - async getFeeRateBps(tokenId: string, side: 'taker' | 'maker'): Promise { - const markets = await this.getMarkets(); - const market = markets - .filter(market => { return market.tokens.map(token => { return token.token_id }).indexOf(tokenId) >= 0 })[0]; - return side === 'taker' ? market.taker_base_fee : market.maker_base_fee; + async getMarketsAcceptingOrders(): Promise { + const markets = await this.fetchAllMarkets(); + return markets + .filter((market) => !market.closed && market.active) + .map((market) => { + return { + yes: market.tokens[0], + no: market.tokens[1], + question: market.question, + }; + }); } - async marketOrder(tokenID: string, side: Side, amount: number, price: number,): Promise { + async marketOrder( + tokenID: string, + side: Side, + amount: number, + price: number + ): Promise { //if we buy, we need to convert amount in dollars to amount in tokens if (side === Side.BUY) { amount = Math.floor(amount / price); } - const orderBook = await this.clobClient.getOrderBook( - tokenID, - ); + const orderBook = await this.clobClient.getOrderBook(tokenID); console.log(orderBook); - const feeResponse: FeeResponse = await this.determineMakerOrTakerFee(tokenID, side, amount, orderBook, price) - console.log("Fee rate: " + feeResponse.fee); console.log(side); console.log("Amount of shares/tokens: " + amount); console.log("Price" + price); @@ -127,19 +137,16 @@ export class PolymarketService { price: price, side: side, size: amount, - feeRateBps: feeResponse.fee, + feeRateBps: 0, nonce: 0, expiration: 0, }); console.log(marketOrder); let resp; - if (feeResponse.side === 'taker' && side === Side.BUY) { + if (side === Side.BUY) { //fill or kill - resp = await this.clobClient.postOrder(marketOrder, OrderType.FOK); - } else if (feeResponse.side === 'taker' && side === Side.SELL) { - //good till cancelled resp = await this.clobClient.postOrder(marketOrder, OrderType.GTC); - } else if (feeResponse.side === 'maker') { + } else if (side === Side.SELL) { //good till cancelled resp = await this.clobClient.postOrder(marketOrder, OrderType.GTC); } @@ -158,11 +165,10 @@ export class PolymarketService { async getApiKeys(): Promise { const apiKeys = await this.clobClient.deriveApiKey(); - if (!apiKeys['error']) { + if (!apiKeys["error"]) { return apiKeys; } else { return this.clobClient.createApiKey(); } } - }