@maxion-platform/ronin-market-sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1141 -0
- package/dist/cjs/actions/approve-token/index.js +64 -0
- package/dist/cjs/actions/approve-token/types.js +9 -0
- package/dist/cjs/actions/bulk-buy-token/index.js +116 -0
- package/dist/cjs/actions/buy-token/index.js +160 -0
- package/dist/cjs/actions/gift-token/index.js +49 -0
- package/dist/cjs/actions/offer/acceptOffer.js +40 -0
- package/dist/cjs/actions/offer/cancelOffer.js +27 -0
- package/dist/cjs/actions/offer/makeOffer.js +92 -0
- package/dist/cjs/actions/order/cancelOrder.js +58 -0
- package/dist/cjs/actions/order/createOrder.js +153 -0
- package/dist/cjs/actions/ron-wrapper/index.js +51 -0
- package/dist/cjs/common/constants.js +147 -0
- package/dist/cjs/configs/index.js +83 -0
- package/dist/cjs/contracts/BaseContract.js +23 -0
- package/dist/cjs/contracts/KatanaContract.js +25 -0
- package/dist/cjs/contracts/abis/collection-offer.json.js +2366 -0
- package/dist/cjs/contracts/abis/erc1155.json.js +823 -0
- package/dist/cjs/contracts/abis/erc20.json.js +232 -0
- package/dist/cjs/contracts/abis/erc721.json.js +825 -0
- package/dist/cjs/contracts/abis/katana.json.js +1034 -0
- package/dist/cjs/contracts/abis/market-gateway-multisend.json.js +394 -0
- package/dist/cjs/contracts/abis/market-gateway.json.js +774 -0
- package/dist/cjs/contracts/abis/multicall.json.js +349 -0
- package/dist/cjs/contracts/abis/royalty-registry.json.js +952 -0
- package/dist/cjs/contracts/abis/types/v5/factories/CollectionOffer__factory.js +2352 -0
- package/dist/cjs/contracts/abis/types/v5/factories/Erc1155OrderExchange__factory.js +876 -0
- package/dist/cjs/contracts/abis/types/v5/factories/Erc1155__factory.js +813 -0
- package/dist/cjs/contracts/abis/types/v5/factories/Erc20__factory.js +240 -0
- package/dist/cjs/contracts/abis/types/v5/factories/Erc721__factory.js +814 -0
- package/dist/cjs/contracts/abis/types/v5/factories/Katana__factory.js +1041 -0
- package/dist/cjs/contracts/abis/types/v5/factories/MarketGatewayMultisend__factory.js +398 -0
- package/dist/cjs/contracts/abis/types/v5/factories/MarketGateway__factory.js +773 -0
- package/dist/cjs/contracts/abis/types/v5/factories/MavisExchange__factory.js +842 -0
- package/dist/cjs/contracts/abis/types/v5/factories/Multicall__factory.js +355 -0
- package/dist/cjs/contracts/abis/types/v5/factories/RoyaltyRegistry__factory.js +949 -0
- package/dist/cjs/contracts/abis/types/v5/factories/Wron__factory.js +476 -0
- package/dist/cjs/contracts/abis/types/v5/factories/index.js +31 -0
- package/dist/cjs/contracts/abis/wron.json.js +478 -0
- package/dist/cjs/contracts/index.js +70 -0
- package/dist/cjs/contracts/market-gateway/Erc1155MarketGatewayContract.js +104 -0
- package/dist/cjs/contracts/market-gateway/MarketGatewayContract.js +102 -0
- package/dist/cjs/contracts/market-gateway/MarketGatewayMultisendContract.js +157 -0
- package/dist/cjs/contracts/market-gateway/factory.js +20 -0
- package/dist/cjs/index.js +278 -0
- package/dist/cjs/queries/collection/index.js +44 -0
- package/dist/cjs/queries/collection/types.js +8 -0
- package/dist/cjs/queries/exchange-rate/index.js +11 -0
- package/dist/cjs/queries/graphql/fragments/asset.js +24 -0
- package/dist/cjs/queries/graphql/fragments/collection.js +32 -0
- package/dist/cjs/queries/graphql/fragments/offer.js +61 -0
- package/dist/cjs/queries/graphql/fragments/order.js +77 -0
- package/dist/cjs/queries/graphql/fragments/profile.js +37 -0
- package/dist/cjs/queries/graphql/fragments/token.js +217 -0
- package/dist/cjs/queries/graphql/index.js +37 -0
- package/dist/cjs/queries/graphql/mutations/metadata.js +11 -0
- package/dist/cjs/queries/graphql/mutations/order.js +15 -0
- package/dist/cjs/queries/graphql/queries/collection.js +80 -0
- package/dist/cjs/queries/graphql/queries/exchange-rate.js +27 -0
- package/dist/cjs/queries/graphql/queries/offer.js +102 -0
- package/dist/cjs/queries/graphql/queries/order.js +105 -0
- package/dist/cjs/queries/graphql/queries/token.js +390 -0
- package/dist/cjs/queries/offer/index.js +92 -0
- package/dist/cjs/queries/offer/types.js +11 -0
- package/dist/cjs/queries/order/index.js +90 -0
- package/dist/cjs/queries/order/types.js +43 -0
- package/dist/cjs/queries/token/index.js +226 -0
- package/dist/cjs/queries/token/types.js +24 -0
- package/dist/cjs/services/balance/checkIsInsufficientBalance.js +16 -0
- package/dist/cjs/services/balance/fetchBalances.js +27 -0
- package/dist/cjs/services/order/bulkSettleOrders.js +26 -0
- package/dist/cjs/services/order/checkIsOrderValid.js +72 -0
- package/dist/cjs/services/order/generateOrderData.js +86 -0
- package/dist/cjs/services/order/getNonce.js +13 -0
- package/dist/cjs/services/order/getOrderSignature.js +18 -0
- package/dist/cjs/services/order/getOrderState.js +39 -0
- package/dist/cjs/services/order/getOrdersByCriteria.js +38 -0
- package/dist/cjs/services/order/getOrdersByQuantity.js +23 -0
- package/dist/cjs/services/order/getOrdersTotalPrice.js +46 -0
- package/dist/cjs/services/order/getSwapTokenData.js +41 -0
- package/dist/cjs/services/order/settleOrder.js +141 -0
- package/dist/cjs/services/tokens/checkIsTokenApproved.js +47 -0
- package/dist/cjs/services/tokens/configs.js +163 -0
- package/dist/cjs/services/tokens/data.js +150 -0
- package/dist/cjs/services/tokens/getPaymentTokens.js +14 -0
- package/dist/cjs/services/tokens/getTokensNeedToApprove.js +26 -0
- package/dist/cjs/services/tokens/getTokensNeedToApproveByOrders.js +31 -0
- package/dist/cjs/types/index.js +23 -0
- package/dist/cjs/types/order.js +13 -0
- package/dist/cjs/utils/convertPrice.js +13 -0
- package/dist/cjs/utils/getSpenderContractAddress.js +17 -0
- package/dist/cjs/utils/mapData.js +65 -0
- package/dist/mjs/actions/approve-token/index.js +47 -0
- package/dist/mjs/actions/approve-token/types.js +7 -0
- package/dist/mjs/actions/bulk-buy-token/index.js +86 -0
- package/dist/mjs/actions/buy-token/index.js +126 -0
- package/dist/mjs/actions/gift-token/index.js +27 -0
- package/dist/mjs/actions/offer/acceptOffer.js +15 -0
- package/dist/mjs/actions/offer/cancelOffer.js +3 -0
- package/dist/mjs/actions/offer/makeOffer.js +63 -0
- package/dist/mjs/actions/order/cancelOrder.js +32 -0
- package/dist/mjs/actions/order/createOrder.js +122 -0
- package/dist/mjs/actions/ron-wrapper/index.js +24 -0
- package/dist/mjs/common/constants.js +139 -0
- package/dist/mjs/configs/index.js +72 -0
- package/dist/mjs/contracts/BaseContract.js +15 -0
- package/dist/mjs/contracts/KatanaContract.js +19 -0
- package/dist/mjs/contracts/abis/collection-offer.json.js +2360 -0
- package/dist/mjs/contracts/abis/erc1155.json.js +817 -0
- package/dist/mjs/contracts/abis/erc20.json.js +226 -0
- package/dist/mjs/contracts/abis/erc721.json.js +819 -0
- package/dist/mjs/contracts/abis/katana.json.js +1028 -0
- package/dist/mjs/contracts/abis/market-gateway-multisend.json.js +388 -0
- package/dist/mjs/contracts/abis/market-gateway.json.js +768 -0
- package/dist/mjs/contracts/abis/multicall.json.js +343 -0
- package/dist/mjs/contracts/abis/royalty-registry.json.js +946 -0
- package/dist/mjs/contracts/abis/types/v5/factories/CollectionOffer__factory.js +2346 -0
- package/dist/mjs/contracts/abis/types/v5/factories/Erc1155OrderExchange__factory.js +870 -0
- package/dist/mjs/contracts/abis/types/v5/factories/Erc1155__factory.js +807 -0
- package/dist/mjs/contracts/abis/types/v5/factories/Erc20__factory.js +234 -0
- package/dist/mjs/contracts/abis/types/v5/factories/Erc721__factory.js +808 -0
- package/dist/mjs/contracts/abis/types/v5/factories/Katana__factory.js +1035 -0
- package/dist/mjs/contracts/abis/types/v5/factories/MarketGatewayMultisend__factory.js +392 -0
- package/dist/mjs/contracts/abis/types/v5/factories/MarketGateway__factory.js +767 -0
- package/dist/mjs/contracts/abis/types/v5/factories/MavisExchange__factory.js +836 -0
- package/dist/mjs/contracts/abis/types/v5/factories/Multicall__factory.js +349 -0
- package/dist/mjs/contracts/abis/types/v5/factories/RoyaltyRegistry__factory.js +943 -0
- package/dist/mjs/contracts/abis/types/v5/factories/Wron__factory.js +470 -0
- package/dist/mjs/contracts/abis/types/v5/factories/index.js +3 -0
- package/dist/mjs/contracts/abis/wron.json.js +472 -0
- package/dist/mjs/contracts/index.js +40 -0
- package/dist/mjs/contracts/market-gateway/Erc1155MarketGatewayContract.js +94 -0
- package/dist/mjs/contracts/market-gateway/MarketGatewayContract.js +91 -0
- package/dist/mjs/contracts/market-gateway/MarketGatewayMultisendContract.js +146 -0
- package/dist/mjs/contracts/market-gateway/factory.js +10 -0
- package/dist/mjs/index.js +1 -0
- package/dist/mjs/queries/collection/index.js +29 -0
- package/dist/mjs/queries/collection/types.js +6 -0
- package/dist/mjs/queries/exchange-rate/index.js +4 -0
- package/dist/mjs/queries/graphql/fragments/asset.js +17 -0
- package/dist/mjs/queries/graphql/fragments/collection.js +25 -0
- package/dist/mjs/queries/graphql/fragments/offer.js +53 -0
- package/dist/mjs/queries/graphql/fragments/order.js +68 -0
- package/dist/mjs/queries/graphql/fragments/profile.js +29 -0
- package/dist/mjs/queries/graphql/fragments/token.js +199 -0
- package/dist/mjs/queries/graphql/index.js +27 -0
- package/dist/mjs/queries/graphql/mutations/metadata.js +5 -0
- package/dist/mjs/queries/graphql/mutations/order.js +8 -0
- package/dist/mjs/queries/graphql/queries/collection.js +69 -0
- package/dist/mjs/queries/graphql/queries/exchange-rate.js +21 -0
- package/dist/mjs/queries/graphql/queries/offer.js +90 -0
- package/dist/mjs/queries/graphql/queries/order.js +94 -0
- package/dist/mjs/queries/graphql/queries/token.js +368 -0
- package/dist/mjs/queries/offer/index.js +75 -0
- package/dist/mjs/queries/offer/types.js +9 -0
- package/dist/mjs/queries/order/index.js +59 -0
- package/dist/mjs/queries/order/types.js +41 -0
- package/dist/mjs/queries/token/index.js +189 -0
- package/dist/mjs/queries/token/types.js +22 -0
- package/dist/mjs/services/balance/checkIsInsufficientBalance.js +8 -0
- package/dist/mjs/services/balance/fetchBalances.js +15 -0
- package/dist/mjs/services/order/bulkSettleOrders.js +17 -0
- package/dist/mjs/services/order/checkIsOrderValid.js +47 -0
- package/dist/mjs/services/order/generateOrderData.js +76 -0
- package/dist/mjs/services/order/getNonce.js +6 -0
- package/dist/mjs/services/order/getOrderSignature.js +10 -0
- package/dist/mjs/services/order/getOrderState.js +28 -0
- package/dist/mjs/services/order/getOrdersByCriteria.js +26 -0
- package/dist/mjs/services/order/getOrdersByQuantity.js +19 -0
- package/dist/mjs/services/order/getOrdersTotalPrice.js +36 -0
- package/dist/mjs/services/order/getSwapTokenData.js +25 -0
- package/dist/mjs/services/order/settleOrder.js +122 -0
- package/dist/mjs/services/tokens/checkIsTokenApproved.js +35 -0
- package/dist/mjs/services/tokens/configs.js +153 -0
- package/dist/mjs/services/tokens/data.js +143 -0
- package/dist/mjs/services/tokens/getPaymentTokens.js +7 -0
- package/dist/mjs/services/tokens/getTokensNeedToApprove.js +18 -0
- package/dist/mjs/services/tokens/getTokensNeedToApproveByOrders.js +22 -0
- package/dist/mjs/types/index.js +10 -0
- package/dist/mjs/types/order.js +11 -0
- package/dist/mjs/utils/convertPrice.js +7 -0
- package/dist/mjs/utils/getSpenderContractAddress.js +10 -0
- package/dist/mjs/utils/mapData.js +43 -0
- package/dist/types/actions/approve-token/index.d.ts +8 -0
- package/dist/types/actions/approve-token/index.d.ts.map +1 -0
- package/dist/types/actions/approve-token/types.d.ts +25 -0
- package/dist/types/actions/approve-token/types.d.ts.map +1 -0
- package/dist/types/actions/bulk-buy-token/index.d.ts +4 -0
- package/dist/types/actions/bulk-buy-token/index.d.ts.map +1 -0
- package/dist/types/actions/bulk-buy-token/types.d.ts +25 -0
- package/dist/types/actions/bulk-buy-token/types.d.ts.map +1 -0
- package/dist/types/actions/buy-token/index.d.ts +8 -0
- package/dist/types/actions/buy-token/index.d.ts.map +1 -0
- package/dist/types/actions/buy-token/types.d.ts +28 -0
- package/dist/types/actions/buy-token/types.d.ts.map +1 -0
- package/dist/types/actions/gift-token/index.d.ts +6 -0
- package/dist/types/actions/gift-token/index.d.ts.map +1 -0
- package/dist/types/actions/gift-token/types.d.ts +16 -0
- package/dist/types/actions/gift-token/types.d.ts.map +1 -0
- package/dist/types/actions/index.d.ts +8 -0
- package/dist/types/actions/index.d.ts.map +1 -0
- package/dist/types/actions/offer/acceptOffer.d.ts +3 -0
- package/dist/types/actions/offer/acceptOffer.d.ts.map +1 -0
- package/dist/types/actions/offer/cancelOffer.d.ts +3 -0
- package/dist/types/actions/offer/cancelOffer.d.ts.map +1 -0
- package/dist/types/actions/offer/index.d.ts +5 -0
- package/dist/types/actions/offer/index.d.ts.map +1 -0
- package/dist/types/actions/offer/makeOffer.d.ts +3 -0
- package/dist/types/actions/offer/makeOffer.d.ts.map +1 -0
- package/dist/types/actions/offer/types.d.ts +21 -0
- package/dist/types/actions/offer/types.d.ts.map +1 -0
- package/dist/types/actions/order/cancelOrder.d.ts +5 -0
- package/dist/types/actions/order/cancelOrder.d.ts.map +1 -0
- package/dist/types/actions/order/createOrder.d.ts +5 -0
- package/dist/types/actions/order/createOrder.d.ts.map +1 -0
- package/dist/types/actions/order/index.d.ts +4 -0
- package/dist/types/actions/order/index.d.ts.map +1 -0
- package/dist/types/actions/order/types.d.ts +30 -0
- package/dist/types/actions/order/types.d.ts.map +1 -0
- package/dist/types/actions/ron-wrapper/index.d.ts +5 -0
- package/dist/types/actions/ron-wrapper/index.d.ts.map +1 -0
- package/dist/types/actions/ron-wrapper/types.d.ts +9 -0
- package/dist/types/actions/ron-wrapper/types.d.ts.map +1 -0
- package/dist/types/common/constants.d.ts +24 -0
- package/dist/types/common/constants.d.ts.map +1 -0
- package/dist/types/common/index.d.ts +2 -0
- package/dist/types/common/index.d.ts.map +1 -0
- package/dist/types/configs/index.d.ts +28 -0
- package/dist/types/configs/index.d.ts.map +1 -0
- package/dist/types/contracts/BaseContract.d.ts +6 -0
- package/dist/types/contracts/BaseContract.d.ts.map +1 -0
- package/dist/types/contracts/KatanaContract.d.ts +9 -0
- package/dist/types/contracts/KatanaContract.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/CollectionOffer.d.ts +871 -0
- package/dist/types/contracts/abis/types/v5/CollectionOffer.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/Erc1155.d.ts +535 -0
- package/dist/types/contracts/abis/types/v5/Erc1155.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/Erc1155OrderExchange.d.ts +522 -0
- package/dist/types/contracts/abis/types/v5/Erc1155OrderExchange.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/Erc20.d.ts +169 -0
- package/dist/types/contracts/abis/types/v5/Erc20.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/Erc721.d.ts +547 -0
- package/dist/types/contracts/abis/types/v5/Erc721.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/Katana.d.ts +548 -0
- package/dist/types/contracts/abis/types/v5/Katana.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/MarketGateway.d.ts +543 -0
- package/dist/types/contracts/abis/types/v5/MarketGateway.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/MarketGatewayMultisend.d.ts +267 -0
- package/dist/types/contracts/abis/types/v5/MarketGatewayMultisend.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/MavisExchange.d.ts +508 -0
- package/dist/types/contracts/abis/types/v5/MavisExchange.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/Multicall.d.ts +219 -0
- package/dist/types/contracts/abis/types/v5/Multicall.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/RoyaltyRegistry.d.ts +497 -0
- package/dist/types/contracts/abis/types/v5/RoyaltyRegistry.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/Wron.d.ts +348 -0
- package/dist/types/contracts/abis/types/v5/Wron.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/common.d.ts +23 -0
- package/dist/types/contracts/abis/types/v5/common.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/factories/CollectionOffer__factory.d.ts +1826 -0
- package/dist/types/contracts/abis/types/v5/factories/CollectionOffer__factory.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/factories/Erc1155OrderExchange__factory.d.ts +672 -0
- package/dist/types/contracts/abis/types/v5/factories/Erc1155OrderExchange__factory.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/factories/Erc1155__factory.d.ts +626 -0
- package/dist/types/contracts/abis/types/v5/factories/Erc1155__factory.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/factories/Erc20__factory.d.ts +176 -0
- package/dist/types/contracts/abis/types/v5/factories/Erc20__factory.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/factories/Erc721__factory.d.ts +620 -0
- package/dist/types/contracts/abis/types/v5/factories/Erc721__factory.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/factories/Katana__factory.d.ts +810 -0
- package/dist/types/contracts/abis/types/v5/factories/Katana__factory.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/factories/MarketGatewayMultisend__factory.d.ts +302 -0
- package/dist/types/contracts/abis/types/v5/factories/MarketGatewayMultisend__factory.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/factories/MarketGateway__factory.d.ts +588 -0
- package/dist/types/contracts/abis/types/v5/factories/MarketGateway__factory.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/factories/MavisExchange__factory.d.ts +646 -0
- package/dist/types/contracts/abis/types/v5/factories/MavisExchange__factory.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/factories/Multicall__factory.d.ts +268 -0
- package/dist/types/contracts/abis/types/v5/factories/Multicall__factory.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/factories/RoyaltyRegistry__factory.d.ts +721 -0
- package/dist/types/contracts/abis/types/v5/factories/RoyaltyRegistry__factory.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/factories/Wron__factory.d.ts +369 -0
- package/dist/types/contracts/abis/types/v5/factories/Wron__factory.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/factories/index.d.ts +13 -0
- package/dist/types/contracts/abis/types/v5/factories/index.d.ts.map +1 -0
- package/dist/types/contracts/abis/types/v5/index.d.ts +26 -0
- package/dist/types/contracts/abis/types/v5/index.d.ts.map +1 -0
- package/dist/types/contracts/index.d.ts +19 -0
- package/dist/types/contracts/index.d.ts.map +1 -0
- package/dist/types/contracts/market-gateway/Erc1155MarketGatewayContract.d.ts +46 -0
- package/dist/types/contracts/market-gateway/Erc1155MarketGatewayContract.d.ts.map +1 -0
- package/dist/types/contracts/market-gateway/MarketGatewayContract.d.ts +43 -0
- package/dist/types/contracts/market-gateway/MarketGatewayContract.d.ts.map +1 -0
- package/dist/types/contracts/market-gateway/MarketGatewayMultisendContract.d.ts +60 -0
- package/dist/types/contracts/market-gateway/MarketGatewayMultisendContract.d.ts.map +1 -0
- package/dist/types/contracts/market-gateway/factory.d.ts +6 -0
- package/dist/types/contracts/market-gateway/factory.d.ts.map +1 -0
- package/dist/types/contracts/market-gateway/index.d.ts +5 -0
- package/dist/types/contracts/market-gateway/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/queries/collection/index.d.ts +11 -0
- package/dist/types/queries/collection/index.d.ts.map +1 -0
- package/dist/types/queries/collection/queryTypes.d.ts +40 -0
- package/dist/types/queries/collection/queryTypes.d.ts.map +1 -0
- package/dist/types/queries/collection/types.d.ts +98 -0
- package/dist/types/queries/collection/types.d.ts.map +1 -0
- package/dist/types/queries/exchange-rate/index.d.ts +5 -0
- package/dist/types/queries/exchange-rate/index.d.ts.map +1 -0
- package/dist/types/queries/exchange-rate/queryTypes.d.ts +9 -0
- package/dist/types/queries/exchange-rate/queryTypes.d.ts.map +1 -0
- package/dist/types/queries/exchange-rate/types.d.ts +11 -0
- package/dist/types/queries/exchange-rate/types.d.ts.map +1 -0
- package/dist/types/queries/graphql/fragments/asset.d.ts +3 -0
- package/dist/types/queries/graphql/fragments/asset.d.ts.map +1 -0
- package/dist/types/queries/graphql/fragments/collection.d.ts +3 -0
- package/dist/types/queries/graphql/fragments/collection.d.ts.map +1 -0
- package/dist/types/queries/graphql/fragments/offer.d.ts +3 -0
- package/dist/types/queries/graphql/fragments/offer.d.ts.map +1 -0
- package/dist/types/queries/graphql/fragments/order.d.ts +3 -0
- package/dist/types/queries/graphql/fragments/order.d.ts.map +1 -0
- package/dist/types/queries/graphql/fragments/profile.d.ts +4 -0
- package/dist/types/queries/graphql/fragments/profile.d.ts.map +1 -0
- package/dist/types/queries/graphql/fragments/token.d.ts +12 -0
- package/dist/types/queries/graphql/fragments/token.d.ts.map +1 -0
- package/dist/types/queries/graphql/index.d.ts +14 -0
- package/dist/types/queries/graphql/index.d.ts.map +1 -0
- package/dist/types/queries/graphql/mutations/metadata.d.ts +2 -0
- package/dist/types/queries/graphql/mutations/metadata.d.ts.map +1 -0
- package/dist/types/queries/graphql/mutations/order.d.ts +2 -0
- package/dist/types/queries/graphql/mutations/order.d.ts.map +1 -0
- package/dist/types/queries/graphql/queries/collection.d.ts +5 -0
- package/dist/types/queries/graphql/queries/collection.d.ts.map +1 -0
- package/dist/types/queries/graphql/queries/exchange-rate.d.ts +2 -0
- package/dist/types/queries/graphql/queries/exchange-rate.d.ts.map +1 -0
- package/dist/types/queries/graphql/queries/offer.d.ts +7 -0
- package/dist/types/queries/graphql/queries/offer.d.ts.map +1 -0
- package/dist/types/queries/graphql/queries/order.d.ts +6 -0
- package/dist/types/queries/graphql/queries/order.d.ts.map +1 -0
- package/dist/types/queries/graphql/queries/token.d.ts +14 -0
- package/dist/types/queries/graphql/queries/token.d.ts.map +1 -0
- package/dist/types/queries/index.d.ts +8 -0
- package/dist/types/queries/index.d.ts.map +1 -0
- package/dist/types/queries/offer/index.d.ts +19 -0
- package/dist/types/queries/offer/index.d.ts.map +1 -0
- package/dist/types/queries/offer/queryTypes.d.ts +89 -0
- package/dist/types/queries/offer/queryTypes.d.ts.map +1 -0
- package/dist/types/queries/offer/types.d.ts +33 -0
- package/dist/types/queries/offer/types.d.ts.map +1 -0
- package/dist/types/queries/order/index.d.ts +14 -0
- package/dist/types/queries/order/index.d.ts.map +1 -0
- package/dist/types/queries/order/queryTypes.d.ts +87 -0
- package/dist/types/queries/order/queryTypes.d.ts.map +1 -0
- package/dist/types/queries/order/types.d.ts +96 -0
- package/dist/types/queries/order/types.d.ts.map +1 -0
- package/dist/types/queries/profile/index.d.ts +2 -0
- package/dist/types/queries/profile/index.d.ts.map +1 -0
- package/dist/types/queries/profile/types.d.ts +11 -0
- package/dist/types/queries/profile/types.d.ts.map +1 -0
- package/dist/types/queries/token/index.d.ts +92 -0
- package/dist/types/queries/token/index.d.ts.map +1 -0
- package/dist/types/queries/token/queryTypes.d.ts +304 -0
- package/dist/types/queries/token/queryTypes.d.ts.map +1 -0
- package/dist/types/queries/token/types.d.ts +103 -0
- package/dist/types/queries/token/types.d.ts.map +1 -0
- package/dist/types/services/balance/checkIsInsufficientBalance.d.ts +4 -0
- package/dist/types/services/balance/checkIsInsufficientBalance.d.ts.map +1 -0
- package/dist/types/services/balance/fetchBalances.d.ts +4 -0
- package/dist/types/services/balance/fetchBalances.d.ts.map +1 -0
- package/dist/types/services/balance/index.d.ts +3 -0
- package/dist/types/services/balance/index.d.ts.map +1 -0
- package/dist/types/services/index.d.ts +4 -0
- package/dist/types/services/index.d.ts.map +1 -0
- package/dist/types/services/order/bulkSettleOrders.d.ts +21 -0
- package/dist/types/services/order/bulkSettleOrders.d.ts.map +1 -0
- package/dist/types/services/order/checkIsOrderValid.d.ts +5 -0
- package/dist/types/services/order/checkIsOrderValid.d.ts.map +1 -0
- package/dist/types/services/order/generateOrderData.d.ts +6 -0
- package/dist/types/services/order/generateOrderData.d.ts.map +1 -0
- package/dist/types/services/order/getNonce.d.ts +3 -0
- package/dist/types/services/order/getNonce.d.ts.map +1 -0
- package/dist/types/services/order/getOrderSignature.d.ts +4 -0
- package/dist/types/services/order/getOrderSignature.d.ts.map +1 -0
- package/dist/types/services/order/getOrderState.d.ts +4 -0
- package/dist/types/services/order/getOrderState.d.ts.map +1 -0
- package/dist/types/services/order/getOrdersByCriteria.d.ts +4 -0
- package/dist/types/services/order/getOrdersByCriteria.d.ts.map +1 -0
- package/dist/types/services/order/getOrdersByQuantity.d.ts +4 -0
- package/dist/types/services/order/getOrdersByQuantity.d.ts.map +1 -0
- package/dist/types/services/order/getOrdersTotalPrice.d.ts +15 -0
- package/dist/types/services/order/getOrdersTotalPrice.d.ts.map +1 -0
- package/dist/types/services/order/getSwapTokenData.d.ts +9 -0
- package/dist/types/services/order/getSwapTokenData.d.ts.map +1 -0
- package/dist/types/services/order/index.d.ts +11 -0
- package/dist/types/services/order/index.d.ts.map +1 -0
- package/dist/types/services/order/settleOrder.d.ts +11 -0
- package/dist/types/services/order/settleOrder.d.ts.map +1 -0
- package/dist/types/services/tokens/checkIsTokenApproved.d.ts +6 -0
- package/dist/types/services/tokens/checkIsTokenApproved.d.ts.map +1 -0
- package/dist/types/services/tokens/configs.d.ts +71 -0
- package/dist/types/services/tokens/configs.d.ts.map +1 -0
- package/dist/types/services/tokens/data.d.ts +45 -0
- package/dist/types/services/tokens/data.d.ts.map +1 -0
- package/dist/types/services/tokens/getPaymentTokens.d.ts +11 -0
- package/dist/types/services/tokens/getPaymentTokens.d.ts.map +1 -0
- package/dist/types/services/tokens/getTokensNeedToApprove.d.ts +4 -0
- package/dist/types/services/tokens/getTokensNeedToApprove.d.ts.map +1 -0
- package/dist/types/services/tokens/getTokensNeedToApproveByOrders.d.ts +4 -0
- package/dist/types/services/tokens/getTokensNeedToApproveByOrders.d.ts.map +1 -0
- package/dist/types/services/tokens/index.d.ts +7 -0
- package/dist/types/services/tokens/index.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +11 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/types/order.d.ts +72 -0
- package/dist/types/types/order.d.ts.map +1 -0
- package/dist/types/types/wallet.d.ts +10 -0
- package/dist/types/types/wallet.d.ts.map +1 -0
- package/dist/types/utils/convertPrice.d.ts +3 -0
- package/dist/types/utils/convertPrice.d.ts.map +1 -0
- package/dist/types/utils/getSpenderContractAddress.d.ts +3 -0
- package/dist/types/utils/getSpenderContractAddress.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +4 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/dist/types/utils/mapData.d.ts +7 -0
- package/dist/types/utils/mapData.d.ts.map +1 -0
- package/package.json +72 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ethers = require('ethers');
|
|
4
|
+
var index = require('../../configs/index.js');
|
|
5
|
+
var index$1 = require('../../contracts/index.js');
|
|
6
|
+
var types = require('./types.js');
|
|
7
|
+
|
|
8
|
+
const approveWRonToken = async (params) => {
|
|
9
|
+
const { chainId, wallet, options } = params;
|
|
10
|
+
const { provider, account } = wallet;
|
|
11
|
+
const approvedValue = ethers.BigNumber.from('1').shl(256).sub(1).toString();
|
|
12
|
+
const config = index.getConfig(chainId);
|
|
13
|
+
const marketGatewayContract = config.contractsAddress.marketGateway;
|
|
14
|
+
const wRonContract = index$1.createWRonContract(chainId, provider);
|
|
15
|
+
return wRonContract.approve(marketGatewayContract, approvedValue, { ...options, from: account });
|
|
16
|
+
};
|
|
17
|
+
const approveErc20Token = async (params) => {
|
|
18
|
+
const { chainId, wallet, address, spenderAddress, options } = params;
|
|
19
|
+
const { provider, account } = wallet;
|
|
20
|
+
const approvedValue = ethers.BigNumber.from('1').shl(256).sub(1).toString();
|
|
21
|
+
const config = index.getConfig(chainId);
|
|
22
|
+
const spender = spenderAddress || config.contractsAddress.marketGateway;
|
|
23
|
+
const erc20Contract = index$1.createErc20Contract(address, provider);
|
|
24
|
+
return erc20Contract.approve(spender, approvedValue, { ...options, from: account });
|
|
25
|
+
};
|
|
26
|
+
const approveErc721Token = async (params) => {
|
|
27
|
+
const { chainId, wallet, address, options } = params;
|
|
28
|
+
const { provider, account } = wallet;
|
|
29
|
+
const config = index.getConfig(chainId);
|
|
30
|
+
const marketGatewayContract = config.contractsAddress.marketGateway;
|
|
31
|
+
const erc721Contract = index$1.createErc721Contract(address, provider);
|
|
32
|
+
return erc721Contract.setApprovalForAll(marketGatewayContract, true, { ...options, from: account });
|
|
33
|
+
};
|
|
34
|
+
const approveErc1155Token = async (params) => {
|
|
35
|
+
const { chainId, wallet, address, options } = params;
|
|
36
|
+
const { provider, account } = wallet;
|
|
37
|
+
const config = index.getConfig(chainId);
|
|
38
|
+
const marketGatewayContract = config.contractsAddress.marketGateway;
|
|
39
|
+
const erc1155Contract = index$1.createErc1155Contract(address, provider);
|
|
40
|
+
return erc1155Contract.setApprovalForAll(marketGatewayContract, true, { ...options, from: account });
|
|
41
|
+
};
|
|
42
|
+
const approveToken = (params) => {
|
|
43
|
+
const { tokenType, ...otherParams } = params;
|
|
44
|
+
if (tokenType === types.ApproveTokenType.Erc20) {
|
|
45
|
+
return approveErc20Token(otherParams);
|
|
46
|
+
}
|
|
47
|
+
if (tokenType === types.ApproveTokenType.Erc721) {
|
|
48
|
+
return approveErc721Token(otherParams);
|
|
49
|
+
}
|
|
50
|
+
if (tokenType === types.ApproveTokenType.Erc1155) {
|
|
51
|
+
return approveErc721Token(otherParams);
|
|
52
|
+
}
|
|
53
|
+
return approveWRonToken(otherParams);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
Object.defineProperty(exports, 'ApproveTokenType', {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
get: function () { return types.ApproveTokenType; }
|
|
59
|
+
});
|
|
60
|
+
exports.approveErc1155Token = approveErc1155Token;
|
|
61
|
+
exports.approveErc20Token = approveErc20Token;
|
|
62
|
+
exports.approveErc721Token = approveErc721Token;
|
|
63
|
+
exports.approveToken = approveToken;
|
|
64
|
+
exports.approveWRonToken = approveWRonToken;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
exports.ApproveTokenType = void 0;
|
|
4
|
+
(function (ApproveTokenType) {
|
|
5
|
+
ApproveTokenType["Erc721"] = "Erc721";
|
|
6
|
+
ApproveTokenType["Erc1155"] = "Erc1155";
|
|
7
|
+
ApproveTokenType["Erc20"] = "Erc20";
|
|
8
|
+
ApproveTokenType["WRon"] = "WRon";
|
|
9
|
+
})(exports.ApproveTokenType || (exports.ApproveTokenType = {}));
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ethers = require('ethers');
|
|
4
|
+
var constants = require('../../common/constants.js');
|
|
5
|
+
require('graphql-request');
|
|
6
|
+
require('../../types/index.js');
|
|
7
|
+
require('../../queries/graphql/queries/collection.js');
|
|
8
|
+
var types = require('../../queries/collection/types.js');
|
|
9
|
+
require('../../queries/graphql/queries/exchange-rate.js');
|
|
10
|
+
require('../../queries/graphql/queries/offer.js');
|
|
11
|
+
require('../../queries/offer/types.js');
|
|
12
|
+
require('../../queries/graphql/mutations/order.js');
|
|
13
|
+
require('../../queries/graphql/queries/order.js');
|
|
14
|
+
require('../../queries/token/types.js');
|
|
15
|
+
require('../../queries/order/types.js');
|
|
16
|
+
require('../../queries/graphql/mutations/metadata.js');
|
|
17
|
+
require('../../queries/graphql/queries/token.js');
|
|
18
|
+
var checkIsInsufficientBalance = require('../../services/balance/checkIsInsufficientBalance.js');
|
|
19
|
+
require('../../configs/index.js');
|
|
20
|
+
require('../../services/tokens/data.js');
|
|
21
|
+
var getPaymentTokens = require('../../services/tokens/getPaymentTokens.js');
|
|
22
|
+
var configs = require('../../services/tokens/configs.js');
|
|
23
|
+
require('lodash');
|
|
24
|
+
var getOrdersTotalPrice = require('../../services/order/getOrdersTotalPrice.js');
|
|
25
|
+
var generateOrderData = require('../../services/order/generateOrderData.js');
|
|
26
|
+
require('ethers/lib/utils');
|
|
27
|
+
var bulkSettleOrders = require('../../services/order/bulkSettleOrders.js');
|
|
28
|
+
|
|
29
|
+
const parseOrder = (params) => {
|
|
30
|
+
const { tokenType, order, totalPrice, quantity, referralAddr = constants.ZERO_ADDRESS } = params;
|
|
31
|
+
const { expectedState, signature } = order;
|
|
32
|
+
if (tokenType === types.Erc.Erc721) {
|
|
33
|
+
const orderData = generateOrderData.generateErc721Order(order);
|
|
34
|
+
return {
|
|
35
|
+
expectedState,
|
|
36
|
+
settlePrice: totalPrice,
|
|
37
|
+
referralAddr,
|
|
38
|
+
signature,
|
|
39
|
+
order: orderData,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const orderData = generateOrderData.generateErc1155Order(order);
|
|
43
|
+
return {
|
|
44
|
+
expectedState,
|
|
45
|
+
settlePrice: totalPrice,
|
|
46
|
+
referralAddr,
|
|
47
|
+
signature,
|
|
48
|
+
order: orderData,
|
|
49
|
+
quantity: quantity.toString(),
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
const swapAndParseOrder = (chainId, order, totalPrice, quantity, selectedToken, deadline, tokenType) => {
|
|
53
|
+
const { paymentToken: listingToken } = order;
|
|
54
|
+
const { address } = selectedToken;
|
|
55
|
+
const swapConfig = configs.getSwapConfig(chainId, listingToken);
|
|
56
|
+
const path = swapConfig[address].path;
|
|
57
|
+
const settlePrice = ethers.BigNumber.from(totalPrice || '0')
|
|
58
|
+
.mul(100 + constants.SWAP_DEFAULT_SLIPPAGE)
|
|
59
|
+
.div(100)
|
|
60
|
+
.toString();
|
|
61
|
+
const parsedOrder = parseOrder({ tokenType, order, totalPrice: settlePrice, quantity });
|
|
62
|
+
return {
|
|
63
|
+
...parsedOrder,
|
|
64
|
+
deadline,
|
|
65
|
+
path,
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
const bulkBuyToken = async (params) => {
|
|
69
|
+
try {
|
|
70
|
+
const { chainId, wallet, data, selectedTokenAddress, deadline, tokenType, requiredAllSuccess = false, options, } = params;
|
|
71
|
+
const selectedToken = getPaymentTokens.getPaymentToken(chainId, selectedTokenAddress);
|
|
72
|
+
const { address: paymentToken } = selectedToken;
|
|
73
|
+
const { account } = wallet;
|
|
74
|
+
const { totalPriceOfEachOrder } = await getOrdersTotalPrice.getOrdersTotalPrice({
|
|
75
|
+
data,
|
|
76
|
+
chainId,
|
|
77
|
+
token: selectedToken,
|
|
78
|
+
wallet,
|
|
79
|
+
});
|
|
80
|
+
let totalSettlePrice = ethers.BigNumber.from('0');
|
|
81
|
+
const bulkBuyData = data.map(({ quantity, order }) => {
|
|
82
|
+
const { paymentToken: listingToken, hash } = order;
|
|
83
|
+
const totalPrice = totalPriceOfEachOrder[hash];
|
|
84
|
+
const isListingWithPaymentToken = listingToken.toLowerCase() === paymentToken.toLowerCase();
|
|
85
|
+
if (isListingWithPaymentToken) {
|
|
86
|
+
totalSettlePrice = totalSettlePrice.add(totalPrice);
|
|
87
|
+
return parseOrder({ tokenType, order, totalPrice, quantity: quantity.toString() });
|
|
88
|
+
}
|
|
89
|
+
const settlePrice = ethers.BigNumber.from(totalPrice || '0')
|
|
90
|
+
.mul(100 + constants.SWAP_DEFAULT_SLIPPAGE)
|
|
91
|
+
.div(100)
|
|
92
|
+
.toString();
|
|
93
|
+
totalSettlePrice = totalSettlePrice.add(settlePrice);
|
|
94
|
+
return swapAndParseOrder(chainId, order, totalPrice, quantity.toString(), selectedToken, deadline, tokenType);
|
|
95
|
+
});
|
|
96
|
+
const isInsufficient = await checkIsInsufficientBalance.checkIsInsufficientBalance(chainId, selectedTokenAddress, account, totalSettlePrice.toString());
|
|
97
|
+
if (isInsufficient) {
|
|
98
|
+
throw new Error('Insufficient balance for transaction.');
|
|
99
|
+
}
|
|
100
|
+
return bulkSettleOrders.bulkSettleOrders({
|
|
101
|
+
chainId,
|
|
102
|
+
wallet,
|
|
103
|
+
bulkBuyData: bulkBuyData,
|
|
104
|
+
paymentToken,
|
|
105
|
+
totalSettlePrice: totalSettlePrice.toString(),
|
|
106
|
+
tokenType,
|
|
107
|
+
requiredAllSuccess,
|
|
108
|
+
options,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
throw new Error(error.message || error);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
exports.bulkBuyToken = bulkBuyToken;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ethers = require('ethers');
|
|
4
|
+
var utils = require('ethers/lib/utils');
|
|
5
|
+
var constants = require('../../common/constants.js');
|
|
6
|
+
require('graphql-request');
|
|
7
|
+
require('../../types/index.js');
|
|
8
|
+
require('../../queries/graphql/queries/collection.js');
|
|
9
|
+
var types = require('../../queries/collection/types.js');
|
|
10
|
+
var index$1 = require('../../queries/exchange-rate/index.js');
|
|
11
|
+
require('../../queries/graphql/queries/offer.js');
|
|
12
|
+
require('../../queries/offer/types.js');
|
|
13
|
+
var index = require('../../queries/order/index.js');
|
|
14
|
+
require('../../queries/graphql/mutations/metadata.js');
|
|
15
|
+
require('../../queries/graphql/queries/token.js');
|
|
16
|
+
require('../../queries/order/types.js');
|
|
17
|
+
require('../../queries/token/types.js');
|
|
18
|
+
var checkIsInsufficientBalance = require('../../services/balance/checkIsInsufficientBalance.js');
|
|
19
|
+
require('../../configs/index.js');
|
|
20
|
+
var data = require('../../services/tokens/data.js');
|
|
21
|
+
var getPaymentTokens = require('../../services/tokens/getPaymentTokens.js');
|
|
22
|
+
var configs = require('../../services/tokens/configs.js');
|
|
23
|
+
var getTokensNeedToApprove = require('../../services/tokens/getTokensNeedToApprove.js');
|
|
24
|
+
require('lodash');
|
|
25
|
+
var checkIsOrderValid = require('../../services/order/checkIsOrderValid.js');
|
|
26
|
+
var convertPrice = require('../../utils/convertPrice.js');
|
|
27
|
+
var getSwapTokenData$1 = require('../../services/order/getSwapTokenData.js');
|
|
28
|
+
var settleOrder = require('../../services/order/settleOrder.js');
|
|
29
|
+
|
|
30
|
+
const buyErc721Token = async (params) => {
|
|
31
|
+
const { order, selectedTokenAddress, chainId, wallet, deadline, refAddress = constants.ZERO_ADDRESS, recipient, options } = params;
|
|
32
|
+
if (!order) {
|
|
33
|
+
throw new Error('Order not found');
|
|
34
|
+
}
|
|
35
|
+
const { paymentToken: listingToken, currentPrice } = order;
|
|
36
|
+
const { account } = wallet;
|
|
37
|
+
const tokens = getPaymentTokens.getPaymentTokens(chainId);
|
|
38
|
+
const isBuyingWithListingToken = selectedTokenAddress.toLowerCase() === listingToken.toLowerCase();
|
|
39
|
+
const isBuyingWithRonToken = selectedTokenAddress.toLowerCase() === tokens[data.Token.RON].address.toLowerCase();
|
|
40
|
+
const settlePrice = await settleOrder.getSettlePrice(chainId, selectedTokenAddress, listingToken, currentPrice);
|
|
41
|
+
if (!settlePrice) {
|
|
42
|
+
throw new Error('Can not get settle price');
|
|
43
|
+
}
|
|
44
|
+
// Check order is valid
|
|
45
|
+
const isOrderValid = await checkIsOrderValid.checkIsErc721OrderValid(chainId, order);
|
|
46
|
+
if (!isOrderValid) {
|
|
47
|
+
throw new Error('Invalid order');
|
|
48
|
+
}
|
|
49
|
+
// Check all tokens is approved
|
|
50
|
+
const tokensNeedToApprove = await getTokensNeedToApprove.getTokensNeedToApprove(chainId, account, selectedTokenAddress, listingToken, settlePrice);
|
|
51
|
+
const isApprovedAllToken = tokensNeedToApprove.length === 0;
|
|
52
|
+
if (!isApprovedAllToken) {
|
|
53
|
+
const tokensNameNeedToApprove = tokensNeedToApprove.map(token => token.name);
|
|
54
|
+
throw new Error(`Tokens need to approve: ${JSON.stringify(tokensNameNeedToApprove)}`);
|
|
55
|
+
}
|
|
56
|
+
// Check insufficient balance
|
|
57
|
+
const isInsufficient = await checkIsInsufficientBalance.checkIsInsufficientBalance(chainId, selectedTokenAddress, account, settlePrice);
|
|
58
|
+
if (isInsufficient) {
|
|
59
|
+
throw new Error('Insufficient balance');
|
|
60
|
+
}
|
|
61
|
+
// Settle order
|
|
62
|
+
if (isBuyingWithListingToken) {
|
|
63
|
+
return settleOrder.settleErc721Order(chainId, wallet, order, settlePrice, refAddress, recipient, options);
|
|
64
|
+
}
|
|
65
|
+
const swapConfig = configs.getSwapConfig(chainId, listingToken);
|
|
66
|
+
const tokenPaths = swapConfig[selectedTokenAddress]?.path;
|
|
67
|
+
if (isBuyingWithRonToken) {
|
|
68
|
+
return settleOrder.swapRONAndSettleErc721Order(chainId, wallet, order, settlePrice, tokenPaths, deadline, refAddress, recipient, options);
|
|
69
|
+
}
|
|
70
|
+
return settleOrder.swapTokensAndSettleErc721Order(chainId, wallet, order, settlePrice, tokenPaths, deadline, refAddress, recipient, options);
|
|
71
|
+
};
|
|
72
|
+
const buyErc1155Token = async (params) => {
|
|
73
|
+
const { order, selectedTokenAddress, chainId, wallet, quantity, deadline, refAddress = constants.ZERO_ADDRESS, recipient, options, } = params;
|
|
74
|
+
if (!order) {
|
|
75
|
+
throw new Error('Order not found');
|
|
76
|
+
}
|
|
77
|
+
const { paymentToken: listingToken, currentPrice } = order;
|
|
78
|
+
const { account } = wallet;
|
|
79
|
+
const totalPrice = ethers.BigNumber.from(currentPrice)
|
|
80
|
+
.mul(Number(quantity || 0))
|
|
81
|
+
.toString();
|
|
82
|
+
const tokens = getPaymentTokens.getPaymentTokens(chainId);
|
|
83
|
+
const isBuyingWithListingToken = selectedTokenAddress.toLowerCase() === listingToken.toLowerCase();
|
|
84
|
+
const isBuyingWithRonToken = selectedTokenAddress.toLowerCase() === tokens[data.Token.RON].address.toLowerCase();
|
|
85
|
+
const settlePrice = await settleOrder.getSettlePrice(chainId, selectedTokenAddress, listingToken, totalPrice);
|
|
86
|
+
if (!settlePrice) {
|
|
87
|
+
throw new Error('Can not get settle price');
|
|
88
|
+
}
|
|
89
|
+
// Check order is valid
|
|
90
|
+
const isOrderValid = await checkIsOrderValid.checkIsErc1155OrderValid(chainId, order);
|
|
91
|
+
if (!isOrderValid) {
|
|
92
|
+
throw new Error('Invalid order');
|
|
93
|
+
}
|
|
94
|
+
// Check all tokens is approved
|
|
95
|
+
const tokensNeedToApprove = await getTokensNeedToApprove.getTokensNeedToApprove(chainId, account, selectedTokenAddress, listingToken, settlePrice);
|
|
96
|
+
const isApprovedAllToken = tokensNeedToApprove.length === 0;
|
|
97
|
+
if (!isApprovedAllToken) {
|
|
98
|
+
const tokensNameNeedToApprove = tokensNeedToApprove.map(token => token.name);
|
|
99
|
+
throw new Error(`Tokens need to approve: ${JSON.stringify(tokensNameNeedToApprove)}`);
|
|
100
|
+
}
|
|
101
|
+
// Check insufficient balance
|
|
102
|
+
const isInsufficient = await checkIsInsufficientBalance.checkIsInsufficientBalance(chainId, selectedTokenAddress, account, settlePrice);
|
|
103
|
+
if (isInsufficient) {
|
|
104
|
+
throw new Error('Insufficient balance');
|
|
105
|
+
}
|
|
106
|
+
// Settle order
|
|
107
|
+
if (isBuyingWithListingToken) {
|
|
108
|
+
return settleOrder.settleErc1155Order(chainId, wallet, order, settlePrice, quantity, refAddress, recipient, options);
|
|
109
|
+
}
|
|
110
|
+
const swapConfig = configs.getSwapConfig(chainId, listingToken);
|
|
111
|
+
const tokenPaths = swapConfig[selectedTokenAddress]?.path;
|
|
112
|
+
if (isBuyingWithRonToken) {
|
|
113
|
+
return settleOrder.swapRONAndSettleErc1155Order(chainId, wallet, order, settlePrice, tokenPaths, quantity, deadline, refAddress, recipient, options);
|
|
114
|
+
}
|
|
115
|
+
return settleOrder.swapTokensAndSettleErc1155Order(chainId, wallet, order, currentPrice, tokenPaths, quantity, deadline, refAddress, recipient, options);
|
|
116
|
+
};
|
|
117
|
+
const buyToken = async (params) => {
|
|
118
|
+
const { hash, ...otherParams } = params;
|
|
119
|
+
const order = await index.getOrderByHash({ hash, chainId: params.chainId });
|
|
120
|
+
if (!order) {
|
|
121
|
+
throw new Error('Order not found');
|
|
122
|
+
}
|
|
123
|
+
const ercType = order.assets?.[0]?.erc;
|
|
124
|
+
if (ercType === types.Erc.Erc721) {
|
|
125
|
+
return buyErc721Token({ ...otherParams, order });
|
|
126
|
+
}
|
|
127
|
+
return buyErc1155Token({ quantity: 1, ...otherParams, order });
|
|
128
|
+
};
|
|
129
|
+
const getSwapTokenData = async (params) => {
|
|
130
|
+
const { chainId, inputTokenAddress, outputTokenAddress, amount } = params;
|
|
131
|
+
const exchangeRate = await index$1.getExchangeRate({ chainId });
|
|
132
|
+
const inputTokenData = getPaymentTokens.getPaymentToken(chainId, inputTokenAddress);
|
|
133
|
+
const outputTokenData = getPaymentTokens.getPaymentToken(chainId, outputTokenAddress);
|
|
134
|
+
if (!inputTokenData) {
|
|
135
|
+
throw new Error('Input token address is invalid');
|
|
136
|
+
}
|
|
137
|
+
if (!outputTokenData) {
|
|
138
|
+
throw new Error('Output token address is invalid');
|
|
139
|
+
}
|
|
140
|
+
const swappedAmount = await getSwapTokenData$1.getSwappedAmount(chainId, inputTokenAddress, outputTokenAddress, amount);
|
|
141
|
+
const fiatValueIn = convertPrice.convertAmountToUsd(Number(utils.formatUnits(ethers.BigNumber.from(amount), inputTokenData.decimals)), inputTokenData.symbol, exchangeRate);
|
|
142
|
+
const fiatValueOut = convertPrice.convertAmountToUsd(Number(utils.formatUnits(ethers.BigNumber.from(swappedAmount), outputTokenData.decimals)), inputTokenData?.symbol, exchangeRate);
|
|
143
|
+
const liquidityProviderFee = getSwapTokenData$1.getLiquidityProviderFee(chainId, inputTokenAddress, outputTokenAddress, amount);
|
|
144
|
+
const liquidityProviderFeePercent = getSwapTokenData$1.getLiquidityProviderFeePercent(chainId, inputTokenAddress, outputTokenAddress);
|
|
145
|
+
const priceImpactPercent = await getSwapTokenData$1.getPriceImpactPercent(chainId, inputTokenAddress, outputTokenAddress, fiatValueIn, fiatValueOut);
|
|
146
|
+
const maximumSent = await settleOrder.getSettlePrice(chainId, inputTokenAddress, outputTokenAddress, amount);
|
|
147
|
+
return {
|
|
148
|
+
swappedAmount: swappedAmount?.toString(),
|
|
149
|
+
maximumSent,
|
|
150
|
+
liquidityProviderFee,
|
|
151
|
+
liquidityProviderFeePercent,
|
|
152
|
+
priceImpactPercent,
|
|
153
|
+
slippageTolerance: constants.SWAP_DEFAULT_SLIPPAGE,
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
exports.buyErc1155Token = buyErc1155Token;
|
|
158
|
+
exports.buyErc721Token = buyErc721Token;
|
|
159
|
+
exports.buyToken = buyToken;
|
|
160
|
+
exports.getSwapTokenData = getSwapTokenData;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ethers = require('ethers');
|
|
4
|
+
var index = require('../../contracts/index.js');
|
|
5
|
+
var index$1 = require('../../queries/collection/index.js');
|
|
6
|
+
require('graphql-request');
|
|
7
|
+
require('../../types/index.js');
|
|
8
|
+
require('../../queries/graphql/queries/exchange-rate.js');
|
|
9
|
+
require('../../queries/graphql/queries/offer.js');
|
|
10
|
+
require('../../queries/offer/types.js');
|
|
11
|
+
require('../../queries/graphql/mutations/order.js');
|
|
12
|
+
require('../../queries/graphql/queries/order.js');
|
|
13
|
+
require('../../queries/token/types.js');
|
|
14
|
+
require('../../queries/order/types.js');
|
|
15
|
+
require('../../queries/graphql/mutations/metadata.js');
|
|
16
|
+
require('../../queries/graphql/queries/token.js');
|
|
17
|
+
var types = require('../../queries/collection/types.js');
|
|
18
|
+
|
|
19
|
+
const giftErc721Token = async (params) => {
|
|
20
|
+
const { tokenId, tokenAddress, receiverAddress, wallet, options } = params;
|
|
21
|
+
const { account, provider } = wallet;
|
|
22
|
+
const erc721Contract = index.createErc721Contract(tokenAddress, provider);
|
|
23
|
+
return erc721Contract?.['safeTransferFrom(address,address,uint256)'](account, receiverAddress, ethers.BigNumber.from(tokenId), { ...options });
|
|
24
|
+
};
|
|
25
|
+
const giftErc1155Token = async (params) => {
|
|
26
|
+
const { tokenId, tokenAddress, receiverAddress, quantity, wallet, options } = params;
|
|
27
|
+
const { account, provider } = wallet;
|
|
28
|
+
const erc1155Contract = index.createErc1155Contract(tokenAddress, provider);
|
|
29
|
+
return erc1155Contract?.safeTransferFrom(account, receiverAddress, ethers.BigNumber.from(tokenId), quantity, [], {
|
|
30
|
+
...options,
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
const giftToken = async (params) => {
|
|
34
|
+
const { chainId, ...otherParams } = params;
|
|
35
|
+
const tokenMetadata = await index$1.getTokenMetadata({
|
|
36
|
+
showAttributes: false,
|
|
37
|
+
chainId,
|
|
38
|
+
tokenAddress: otherParams.tokenAddress,
|
|
39
|
+
});
|
|
40
|
+
const { erc } = tokenMetadata;
|
|
41
|
+
if (erc === types.Erc.Erc721) {
|
|
42
|
+
return giftErc721Token(otherParams);
|
|
43
|
+
}
|
|
44
|
+
return giftErc1155Token({ quantity: 1, ...otherParams });
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
exports.giftErc1155Token = giftErc1155Token;
|
|
48
|
+
exports.giftErc721Token = giftErc721Token;
|
|
49
|
+
exports.giftToken = giftToken;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var constants = require('../../common/constants.js');
|
|
4
|
+
require('graphql-request');
|
|
5
|
+
require('../../types/index.js');
|
|
6
|
+
require('../../queries/graphql/queries/collection.js');
|
|
7
|
+
require('../../queries/collection/types.js');
|
|
8
|
+
require('../../queries/graphql/queries/exchange-rate.js');
|
|
9
|
+
var index = require('../../queries/offer/index.js');
|
|
10
|
+
require('../../queries/graphql/mutations/order.js');
|
|
11
|
+
require('../../queries/graphql/queries/order.js');
|
|
12
|
+
require('../../queries/token/types.js');
|
|
13
|
+
require('../../queries/order/types.js');
|
|
14
|
+
require('../../queries/graphql/mutations/metadata.js');
|
|
15
|
+
require('../../queries/graphql/queries/token.js');
|
|
16
|
+
require('ethers');
|
|
17
|
+
require('../../configs/index.js');
|
|
18
|
+
require('../../services/tokens/data.js');
|
|
19
|
+
var checkIsTokenApproved = require('../../services/tokens/checkIsTokenApproved.js');
|
|
20
|
+
require('lodash');
|
|
21
|
+
require('ethers/lib/utils');
|
|
22
|
+
var settleOrder = require('../../services/order/settleOrder.js');
|
|
23
|
+
|
|
24
|
+
const acceptOffer = async (params) => {
|
|
25
|
+
const { hash, wallet, chainId, refAddress = constants.ZERO_ADDRESS, recipient, options } = params;
|
|
26
|
+
const { account } = wallet;
|
|
27
|
+
const offer = await index.getOffer({ hash, chainId });
|
|
28
|
+
if (!offer) {
|
|
29
|
+
throw new Error('Offer not found');
|
|
30
|
+
}
|
|
31
|
+
const { assets } = offer;
|
|
32
|
+
const tokenAddress = assets?.[0]?.token?.tokenAddress;
|
|
33
|
+
const isApproved = await checkIsTokenApproved.checkIsErc721Approved(chainId, account, tokenAddress);
|
|
34
|
+
if (!isApproved) {
|
|
35
|
+
throw new Error('Token need to be approved');
|
|
36
|
+
}
|
|
37
|
+
return settleOrder.settleErc721Order(chainId, wallet, offer, '0', refAddress, recipient, options);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
exports.acceptOffer = acceptOffer;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var cancelOrder = require('../order/cancelOrder.js');
|
|
4
|
+
require('ethers');
|
|
5
|
+
require('graphql-request');
|
|
6
|
+
require('../../types/index.js');
|
|
7
|
+
require('../../queries/graphql/queries/collection.js');
|
|
8
|
+
require('../../queries/collection/types.js');
|
|
9
|
+
require('../../queries/graphql/queries/exchange-rate.js');
|
|
10
|
+
require('../../queries/graphql/queries/offer.js');
|
|
11
|
+
require('../../queries/offer/types.js');
|
|
12
|
+
require('../../queries/graphql/mutations/order.js');
|
|
13
|
+
require('../../queries/graphql/queries/order.js');
|
|
14
|
+
require('../../queries/token/types.js');
|
|
15
|
+
require('../../queries/order/types.js');
|
|
16
|
+
require('../../queries/graphql/mutations/metadata.js');
|
|
17
|
+
require('../../queries/graphql/queries/token.js');
|
|
18
|
+
require('../../configs/index.js');
|
|
19
|
+
require('../../services/tokens/data.js');
|
|
20
|
+
require('lodash');
|
|
21
|
+
require('ethers/lib/utils');
|
|
22
|
+
|
|
23
|
+
const cancelOffer = (params) => {
|
|
24
|
+
return cancelOrder.cancelOrder(params);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
exports.cancelOffer = cancelOffer;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ethers = require('ethers');
|
|
4
|
+
var constants = require('../../common/constants.js');
|
|
5
|
+
require('graphql-request');
|
|
6
|
+
require('../../types/index.js');
|
|
7
|
+
require('../../queries/graphql/queries/collection.js');
|
|
8
|
+
require('../../queries/collection/types.js');
|
|
9
|
+
require('../../queries/graphql/queries/exchange-rate.js');
|
|
10
|
+
require('../../queries/graphql/queries/offer.js');
|
|
11
|
+
require('../../queries/offer/types.js');
|
|
12
|
+
var index = require('../../queries/order/index.js');
|
|
13
|
+
require('../../queries/graphql/mutations/metadata.js');
|
|
14
|
+
require('../../queries/graphql/queries/token.js');
|
|
15
|
+
var types = require('../../queries/order/types.js');
|
|
16
|
+
require('../../queries/token/types.js');
|
|
17
|
+
var checkIsInsufficientBalance = require('../../services/balance/checkIsInsufficientBalance.js');
|
|
18
|
+
require('../../configs/index.js');
|
|
19
|
+
var data = require('../../services/tokens/data.js');
|
|
20
|
+
var checkIsTokenApproved = require('../../services/tokens/checkIsTokenApproved.js');
|
|
21
|
+
require('lodash');
|
|
22
|
+
var generateOrderData = require('../../services/order/generateOrderData.js');
|
|
23
|
+
var getNonce = require('../../services/order/getNonce.js');
|
|
24
|
+
var getOrderSignature$1 = require('../../services/order/getOrderSignature.js');
|
|
25
|
+
require('ethers/lib/utils');
|
|
26
|
+
var order = require('../../types/order.js');
|
|
27
|
+
|
|
28
|
+
const getInputOrder = async (chainId, account, price, duration, expectedState, assets) => {
|
|
29
|
+
const wRonAddress = data.wRonToken[chainId].address;
|
|
30
|
+
const nonce = await getNonce.getNonce(chainId, account);
|
|
31
|
+
return generateOrderData.generateInputOrder({
|
|
32
|
+
price: ethers.BigNumber.from(price),
|
|
33
|
+
duration,
|
|
34
|
+
paymentToken: wRonAddress,
|
|
35
|
+
orderType: types.OrderType.Offer,
|
|
36
|
+
expectedState,
|
|
37
|
+
nonce,
|
|
38
|
+
maker: account,
|
|
39
|
+
assets,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
const getOrderSignature = (chainId, wallet, price, duration, expectedState, assets) => {
|
|
43
|
+
const { account, signer } = wallet;
|
|
44
|
+
const wRonAddress = data.wRonToken[chainId].address;
|
|
45
|
+
const now = new Date().getTime();
|
|
46
|
+
const startedAt = Math.ceil(now / 1000);
|
|
47
|
+
const expiredAt = startedAt + duration;
|
|
48
|
+
const dataForSigning = {
|
|
49
|
+
maker: account,
|
|
50
|
+
kind: order.OrderKind.Offer,
|
|
51
|
+
assets,
|
|
52
|
+
expiredAt,
|
|
53
|
+
paymentToken: wRonAddress,
|
|
54
|
+
startedAt,
|
|
55
|
+
basePrice: price,
|
|
56
|
+
endedAt: 0,
|
|
57
|
+
endedPrice: '0',
|
|
58
|
+
expectedState,
|
|
59
|
+
nonce: 0,
|
|
60
|
+
marketFeePercentage: constants.MARKET_FEE_PERCENTAGE,
|
|
61
|
+
};
|
|
62
|
+
return getOrderSignature$1.getErc721OrderSignature(chainId, signer, dataForSigning);
|
|
63
|
+
};
|
|
64
|
+
const makeOffer = async (params) => {
|
|
65
|
+
const { tokenId, tokenAddress, price, duration, chainId, wallet } = params;
|
|
66
|
+
const { account } = wallet;
|
|
67
|
+
const assets = [
|
|
68
|
+
{
|
|
69
|
+
id: tokenId,
|
|
70
|
+
addr: tokenAddress,
|
|
71
|
+
erc: order.ErcAssetItem.Erc721,
|
|
72
|
+
quantity: 0,
|
|
73
|
+
},
|
|
74
|
+
];
|
|
75
|
+
const isWRonApproved = checkIsTokenApproved.checkIsWRonTokenApproved(chainId, account, price);
|
|
76
|
+
if (!isWRonApproved) {
|
|
77
|
+
throw new Error('WRon need to be approved');
|
|
78
|
+
}
|
|
79
|
+
const isInsufficient = await checkIsInsufficientBalance.checkIsInsufficientOfferBalance(chainId, account, price);
|
|
80
|
+
if (isInsufficient) {
|
|
81
|
+
throw new Error('Insufficient balance');
|
|
82
|
+
}
|
|
83
|
+
const expectedState = '0';
|
|
84
|
+
const inputOrder = await getInputOrder(chainId, account, price, duration, expectedState, assets);
|
|
85
|
+
const signature = await getOrderSignature(chainId, wallet, price, duration, expectedState, assets);
|
|
86
|
+
if (!signature) {
|
|
87
|
+
throw new Error('Invalid signature');
|
|
88
|
+
}
|
|
89
|
+
return index.requestCreateOrder({ order: inputOrder, account, signature, chainId });
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
exports.makeOffer = makeOffer;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('ethers');
|
|
4
|
+
require('../../configs/index.js');
|
|
5
|
+
require('../../services/tokens/data.js');
|
|
6
|
+
var factory = require('../../contracts/market-gateway/factory.js');
|
|
7
|
+
require('../../types/index.js');
|
|
8
|
+
require('graphql-request');
|
|
9
|
+
require('../../queries/graphql/queries/collection.js');
|
|
10
|
+
var types = require('../../queries/collection/types.js');
|
|
11
|
+
require('../../queries/graphql/queries/exchange-rate.js');
|
|
12
|
+
require('../../queries/graphql/queries/offer.js');
|
|
13
|
+
require('../../queries/offer/types.js');
|
|
14
|
+
var index = require('../../queries/order/index.js');
|
|
15
|
+
require('../../queries/graphql/mutations/metadata.js');
|
|
16
|
+
require('../../queries/graphql/queries/token.js');
|
|
17
|
+
require('../../queries/order/types.js');
|
|
18
|
+
require('../../queries/token/types.js');
|
|
19
|
+
require('lodash');
|
|
20
|
+
var generateOrderData = require('../../services/order/generateOrderData.js');
|
|
21
|
+
require('ethers/lib/utils');
|
|
22
|
+
|
|
23
|
+
const cancelErc721Order = async (params) => {
|
|
24
|
+
const { chainId, wallet, order, options } = params;
|
|
25
|
+
const { provider } = wallet;
|
|
26
|
+
if (!order) {
|
|
27
|
+
throw new Error('Order not found');
|
|
28
|
+
}
|
|
29
|
+
const marketGatewayContract = factory.createMarketGatewayContract(chainId, provider);
|
|
30
|
+
const erc721Order = generateOrderData.generateErc721Order(order);
|
|
31
|
+
return marketGatewayContract.cancelOrder(erc721Order, options);
|
|
32
|
+
};
|
|
33
|
+
const cancelErc1155Order = async (params) => {
|
|
34
|
+
const { chainId, wallet, order, options } = params;
|
|
35
|
+
const { provider } = wallet;
|
|
36
|
+
if (!order) {
|
|
37
|
+
throw new Error('Order not found');
|
|
38
|
+
}
|
|
39
|
+
const erc1155MarketGatewayContract = factory.createErc1155MarketGatewayContract(chainId, provider);
|
|
40
|
+
const erc1155Order = generateOrderData.generateErc1155Order(order);
|
|
41
|
+
return erc1155MarketGatewayContract.cancelErc1155Order(erc1155Order, options);
|
|
42
|
+
};
|
|
43
|
+
const cancelOrder = async (params) => {
|
|
44
|
+
const { hash, ...otherParams } = params;
|
|
45
|
+
const order = await index.getOrderByHash({ hash, chainId: params.chainId });
|
|
46
|
+
if (!order) {
|
|
47
|
+
throw new Error('Order not found');
|
|
48
|
+
}
|
|
49
|
+
const ercType = order.assets?.[0]?.erc;
|
|
50
|
+
if (ercType === types.Erc.Erc721) {
|
|
51
|
+
return cancelErc721Order({ ...otherParams, order });
|
|
52
|
+
}
|
|
53
|
+
return cancelErc1155Order({ ...otherParams, order });
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
exports.cancelErc1155Order = cancelErc1155Order;
|
|
57
|
+
exports.cancelErc721Order = cancelErc721Order;
|
|
58
|
+
exports.cancelOrder = cancelOrder;
|