UNPKG

axie-ronin-ethers-js-tools

Version:

A set of functions that make it easier for developers to interact with their Axies on the Ronin network and the maketplace.

179 lines (178 loc) 4.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ORDER_EXPIRATION = void 0; exports.default = createMarketplaceOrder; const contracts_1 = require("@roninbuilders/contracts"); const utils_1 = require("../utils"); exports.ORDER_EXPIRATION = 15634800; // ~ 6 months async function createMarketplaceOrder(orderData, accessToken, signer, skyMavisApiKey) { const { address, axieId, basePrice, endedPrice, startedAt, endedAt, expiredAt, } = orderData; const types = { Asset: [ { name: 'erc', type: 'uint8' }, { name: 'addr', type: 'address' }, { name: 'id', type: 'uint256' }, { name: 'quantity', type: 'uint256' } ], Order: [ { name: 'maker', type: 'address' }, { name: 'kind', type: 'uint8' }, { name: 'assets', type: 'Asset[]' }, { name: 'expiredAt', type: 'uint256' }, { name: 'paymentToken', type: 'address' }, { name: 'startedAt', type: 'uint256' }, { name: 'basePrice', type: 'uint256' }, { name: 'endedAt', type: 'uint256' }, { name: 'endedPrice', type: 'uint256' }, { name: 'expectedState', type: 'uint256' }, { name: 'nonce', type: 'uint256' }, { name: 'marketFeePercentage', type: 'uint256' } ] }; const domain = { name: 'MarketGateway', version: '1', chainId: '2020', verifyingContract: contracts_1.MARKETPLACE_GATEWAY_V2.address }; const order = { maker: address, kind: '1', assets: [ { erc: '1', addr: contracts_1.AXIE_PROXY.address, id: axieId, quantity: '0' // ??? not sure why this is 0, maybbe its for items } ], expiredAt, paymentToken: contracts_1.WRAPPED_ETHER.address, startedAt, basePrice, endedAt, endedPrice, expectedState: '0', nonce: '0', // ?? use nonce from the wallet marketFeePercentage: '425' }; const signature = await signer._signTypedData(domain, types, order); const query = ` mutation CreateOrder($order: InputOrder!, $signature: String!) { createOrder(order: $order, signature: $signature) { ...OrderInfo __typename } } fragment OrderInfo on Order { id maker kind assets { ...AssetInfo __typename } expiredAt paymentToken startedAt basePrice endedAt endedPrice expectedState nonce marketFeePercentage signature hash duration timeLeft currentPrice suggestedPrice currentPriceUsd __typename } fragment AssetInfo on Asset { erc address id quantity orderId __typename } `; const variables = { order: { nonce: 0, assets: [ { id: axieId, address: contracts_1.AXIE_PROXY.address, erc: 'Erc721', quantity: '0' } ], basePrice, endedPrice, startedAt, endedAt, expiredAt }, signature }; const graphqlUrl = skyMavisApiKey ? "https://api-gateway.skymavis.com/graphql/axie-marketplace" : "https://graphql-gateway.axieinfinity.com/graphql"; const headers = { 'authorization': `Bearer ${accessToken}`, ...skyMavisApiKey && { 'x-api-key': skyMavisApiKey } }; const result = await (0, utils_1.apiRequest)(graphqlUrl, JSON.stringify({ query, variables }), headers); return result; }