UNPKG

@sx-bet/sportx-js

Version:

Provides an easy to use API to interact with the SportX relayer.

231 lines 8.82 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCancelOrderEIP712Payload = exports.getCancelAllOrdersEIP712Payload = exports.getCancelOrderEventsEIP712Payload = exports.getMaticEip712Payload = exports.getFillOrderEIP712Payload = exports.getOrderHash = exports.getOrderSignature = void 0; const bytes_1 = require("@ethersproject/bytes"); const solidity_1 = require("@ethersproject/solidity"); const convert_1 = require("./convert"); function getOrderSignature(order, wallet) { return __awaiter(this, void 0, void 0, function* () { const contractOrder = convert_1.convertToContractOrder(order); return getContractOrderSignature(contractOrder, wallet); }); } exports.getOrderSignature = getOrderSignature; function getOrderHash(order) { return solidity_1.keccak256([ "bytes32", "address", "uint256", "uint256", "uint256", "uint256", "address", "address", "bool", ], [ order.marketHash, order.baseToken, order.totalBetSize, order.percentageOdds, order.expiry, order.salt, order.maker, order.executor, order.isMakerBettingOutcomeOne, ]); } exports.getOrderHash = getOrderHash; function getContractOrderSignature(order, signer) { return __awaiter(this, void 0, void 0, function* () { const hash = bytes_1.arrayify(getOrderHash(order)); return signer.signMessage(hash); }); } function getFillOrderEIP712Payload(fillDetails, chainId, version, verifyingContract) { const payload = { types: { EIP712Domain: [ { name: "name", type: "string" }, { name: "version", type: "string" }, { name: "chainId", type: "uint256" }, { name: "verifyingContract", type: "address" }, ], Details: [ { name: "action", type: "string" }, { name: "market", type: "string" }, { name: "betting", type: "string" }, { name: "stake", type: "string" }, { name: "odds", type: "string" }, { name: "returning", type: "string" }, { name: "fills", type: "FillObject" }, ], FillObject: [ { name: "orders", type: "Order[]" }, { name: "makerSigs", type: "bytes[]" }, { name: "takerAmounts", type: "uint256[]" }, { name: "fillSalt", type: "uint256" }, { name: "beneficiary", type: "address" }, ], Order: [ { name: "marketHash", type: "bytes32" }, { name: "baseToken", type: "address" }, { name: "totalBetSize", type: "uint256" }, { name: "percentageOdds", type: "uint256" }, { name: "expiry", type: "uint256" }, { name: "salt", type: "uint256" }, { name: "maker", type: "address" }, { name: "executor", type: "address" }, { name: "isMakerBettingOutcomeOne", type: "bool" }, ], }, primaryType: "Details", domain: { name: "SportX", version, chainId, verifyingContract, }, message: { action: fillDetails.action, market: fillDetails.market, betting: fillDetails.betting, stake: fillDetails.stake, odds: fillDetails.odds, returning: fillDetails.returning, fills: { makerSigs: fillDetails.fills.makerSigs, orders: fillDetails.fills.orders.map((order) => ({ marketHash: order.marketHash, baseToken: order.baseToken, totalBetSize: order.totalBetSize.toString(), percentageOdds: order.percentageOdds.toString(), expiry: order.expiry.toString(), salt: order.salt.toString(), maker: order.maker, executor: order.executor, isMakerBettingOutcomeOne: order.isMakerBettingOutcomeOne, })), takerAmounts: fillDetails.fills.takerAmounts.map((takerAmount) => takerAmount.toString()), fillSalt: fillDetails.fills.fillSalt.toString(), beneficiary: fillDetails.fills.beneficiary, }, }, }; return payload; } exports.getFillOrderEIP712Payload = getFillOrderEIP712Payload; function getMaticEip712Payload(abiEncodedFunctionSig, nonce, from, chainId, verifyingContract, domainName) { return { types: { EIP712Domain: [ { name: "name", type: "string" }, { name: "version", type: "string" }, { name: "verifyingContract", type: "address" }, { name: "salt", type: "bytes32" }, ], MetaTransaction: [ { name: "nonce", type: "uint256" }, { name: "from", type: "address" }, { name: "functionSignature", type: "bytes" }, ], }, domain: { name: domainName, version: "1", salt: bytes_1.hexZeroPad(bytes_1.hexlify(chainId), 32), verifyingContract, }, message: { nonce, from, functionSignature: abiEncodedFunctionSig, }, primaryType: "MetaTransaction", }; } exports.getMaticEip712Payload = getMaticEip712Payload; function getCancelOrderEventsEIP712Payload(sportXeventId, salt, timestamp, chainId) { const payload = { types: { EIP712Domain: [ { name: "name", type: "string" }, { name: "version", type: "string" }, { name: "chainId", type: "uint256" }, { name: "salt", type: "bytes32" }, ], Details: [ { name: "sportXeventId", type: "string" }, { name: "timestamp", type: "uint256" }, ], }, primaryType: "Details", domain: { name: "CancelOrderEventsSportX", version: "1.0", chainId, salt, }, message: { sportXeventId, timestamp }, }; return payload; } exports.getCancelOrderEventsEIP712Payload = getCancelOrderEventsEIP712Payload; function getCancelAllOrdersEIP712Payload(salt, timestamp, chainId) { const payload = { types: { EIP712Domain: [ { name: "name", type: "string" }, { name: "version", type: "string" }, { name: "chainId", type: "uint256" }, { name: "salt", type: "bytes32" }, ], Details: [{ name: "timestamp", type: "uint256" }], }, primaryType: "Details", domain: { name: "CancelAllOrdersSportX", version: "1.0", chainId, salt, }, message: { timestamp }, }; return payload; } exports.getCancelAllOrdersEIP712Payload = getCancelAllOrdersEIP712Payload; function getCancelOrderEIP712Payload(orderHashes, salt, timestamp, chainId) { const payload = { types: { EIP712Domain: [ { name: "name", type: "string" }, { name: "version", type: "string" }, { name: "chainId", type: "uint256" }, { name: "salt", type: "bytes32" }, ], Details: [ { name: "orderHashes", type: "string[]" }, { name: "timestamp", type: "uint256" }, ], }, primaryType: "Details", domain: { name: "CancelOrderV2SportX", version: "1.0", chainId, salt, }, message: { orderHashes, timestamp }, }; return payload; } exports.getCancelOrderEIP712Payload = getCancelOrderEIP712Payload; //# sourceMappingURL=signing.js.map