Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@refinableco/refinable-sdk

Package Overview
Dependencies
Maintainers
2
Versions
191
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@refinableco/refinable-sdk - npm Package Compare versions

Comparing version 5.0.0-next.6 to 5.0.0-next.7

lib/errors/InsufficientBalanceError.d.ts

19

lib/nft/AbstractEvmNFT.d.ts

@@ -1,2 +0,2 @@

import { MarketConfig, TokenType, Platform, SaleOffer as SaleOfferType } from "../@types/graphql";
import { MarketConfig, TokenType, Platform, SaleOffer as SaleOfferType, LaunchpadDetailsInput } from "../@types/graphql";
import { AuctionOffer } from "../offer/AuctionOffer";

@@ -96,2 +96,19 @@ import { SaleOffer } from "../offer/SaleOffer";

*/
protected _putForSale(params: {
price: IPrice;
startTime?: Date;
endTime?: Date;
supply: number;
launchpadDetails?: LaunchpadDetailsInput;
platforms?: Platform[];
onInitialize?: (steps: {
step: LIST_STATUS_STEP;
platform: Platform;
}[]) => void;
onProgress?: <T extends ListStatus>(status: T) => void;
onError?: ({ step, platform }: {
step: LIST_STATUS_STEP;
platform: Platform;
}, error: any) => void;
}): Promise<SaleOffer>;
getSaleId(): Promise<any>;

@@ -98,0 +115,0 @@ protected _buy(params: {

@@ -31,2 +31,3 @@ "use strict";

const SaleInfo_1 = require("./interfaces/SaleInfo");
const SaleStatusStep_1 = require("./interfaces/SaleStatusStep");
class AbstractEvmNFT extends AbstractNFT_1.AbstractNFT {

@@ -165,2 +166,156 @@ constructor(type, refinable, item) {

*/
_putForSale(params) {
return __awaiter(this, void 0, void 0, function* () {
const { price, startTime, endTime, launchpadDetails, platforms = [], onInitialize = () => true, onProgress = () => true, onError = () => true, supply = 1 } = params;
// calculate steps
const steps = [
{
step: SaleStatusStep_1.LIST_STATUS_STEP.APPROVE,
platform: graphql_1.Platform.Refinable,
},
{
step: SaleStatusStep_1.LIST_STATUS_STEP.SIGN,
platform: graphql_1.Platform.Refinable,
},
{
step: SaleStatusStep_1.LIST_STATUS_STEP.CREATE,
platform: graphql_1.Platform.Refinable,
},
];
if (Array.isArray(platforms)) {
for (const platform of platforms) {
steps.push({
step: SaleStatusStep_1.LIST_STATUS_STEP.APPROVE,
platform,
}, {
step: SaleStatusStep_1.LIST_STATUS_STEP.SIGN,
platform,
}, {
step: SaleStatusStep_1.LIST_STATUS_STEP.CREATE,
platform,
});
}
}
onInitialize(steps);
this.verifyItem();
// validate launchpad
if (startTime && (launchpadDetails === null || launchpadDetails === void 0 ? void 0 : launchpadDetails.stages)) {
for (let i = 0; i < launchpadDetails.stages.length; i++) {
const stage = launchpadDetails.stages[i];
if (stage.startTime >= startTime) {
throw new Error(`The start time of the ${stage.stage} stage (index: ${i}) is after the start time of the public sale, this whitelist won't have any effect. Please remove this stage or adjust its startTime`);
}
}
}
let saleParamsHash;
try {
yield this.approveIfNeeded(this.transferProxyContract.address, () => {
onProgress({
step: SaleStatusStep_1.LIST_STATUS_STEP.APPROVE,
platform: graphql_1.Platform.Refinable,
data: {
addressToApprove: this.transferProxyContract.address,
},
});
});
saleParamsHash = yield this.getSaleParamsHash({
price,
ethAddress: this.refinable.accountAddress,
startTime,
endTime,
isV2: true,
supply
});
}
catch (ex) {
onError({
step: SaleStatusStep_1.LIST_STATUS_STEP.APPROVE,
platform: graphql_1.Platform.Refinable,
}, ex);
throw ex;
}
onProgress({
step: SaleStatusStep_1.LIST_STATUS_STEP.SIGN,
platform: graphql_1.Platform.Refinable,
data: {
what: "Sale Parameters",
hash: saleParamsHash,
},
});
let signedHash, saleId, blockchainId;
try {
signedHash = yield this.refinable.account.sign(saleParamsHash);
saleId = yield this.getSaleId();
blockchainId = new ERCSaleId_1.ERCSaleID(saleId, SaleInfo_1.SaleVersion.V2).toBlockchainId();
}
catch (ex) {
onError({
step: SaleStatusStep_1.LIST_STATUS_STEP.SIGN,
platform: graphql_1.Platform.Refinable,
}, ex);
throw ex;
}
onProgress({
step: SaleStatusStep_1.LIST_STATUS_STEP.CREATE,
platform: graphql_1.Platform.Refinable,
data: {
chainId: this.item.chainId,
tokenId: this.item.tokenId,
signature: signedHash,
type: graphql_1.OfferType.Sale,
contractAddress: this.item.contractAddress,
price: Object.assign(Object.assign({}, price), { amount: parseFloat(price.amount.toString()) }),
startTime,
endTime,
supply,
launchpadDetails,
blockchainId,
},
});
let result;
try {
result = yield this.refinable.graphqlClient.request(sale_1.CREATE_OFFER, {
input: {
chainId: this.item.chainId,
tokenId: this.item.tokenId,
signature: signedHash,
type: graphql_1.OfferType.Sale,
contractAddress: this.item.contractAddress,
price: {
payToken: price.address,
amount: parseFloat(price.amount.toString()),
},
startTime,
endTime,
supply,
launchpadDetails,
blockchainId,
},
});
}
catch (ex) {
onError({
step: SaleStatusStep_1.LIST_STATUS_STEP.CREATE,
platform: graphql_1.Platform.Refinable,
}, ex);
throw ex;
}
onProgress({
step: SaleStatusStep_1.LIST_STATUS_STEP.DONE,
platform: graphql_1.Platform.Refinable,
data: result,
});
// third party platforms
if (Array.isArray(platforms)) {
const platformFactory = new platform_1.PlatformFactory(this.refinable);
for (const platform of platforms) {
const platformInstance = platformFactory.createPlatform(platform);
yield platformInstance.listForSale(this, price, {
onProgress,
});
}
}
return this.refinable.offer.createOffer(result.createOfferForItems, this);
});
}
getSaleId() {

@@ -167,0 +322,0 @@ return __awaiter(this, void 0, void 0, function* () {

@@ -1,2 +0,2 @@

import { LaunchpadDetailsInput, MarketConfig } from "../@types/graphql";
import { LaunchpadDetailsInput, MarketConfig, Platform } from "../@types/graphql";
import { SaleOffer } from "../offer/SaleOffer";

@@ -8,5 +8,7 @@ import { Refinable } from "../refinable/Refinable";

import { IPrice } from "./interfaces/Price";
import { ListStatus, LIST_STATUS_STEP } from "./interfaces/SaleStatusStep";
import { WhitelistVoucherParams } from "./interfaces/Voucher";
export declare class ERC1155NFT extends AbstractEvmNFT {
constructor(refinable: Refinable, item: PartialNFTItem);
getBalance(ownerAddress?: string): Promise<number>;
approve(operatorAddress: string): Promise<EvmTransaction>;

@@ -39,7 +41,16 @@ isApproved(operatorAddress: string): Promise<boolean>;

putForSale(params: {
supply?: number;
price: IPrice;
startTime?: Date;
endTime?: Date;
supply?: number;
launchpadDetails?: LaunchpadDetailsInput;
onInitialize?: (steps: {
step: LIST_STATUS_STEP;
platform: Platform;
}[]) => void;
onProgress?: <T extends ListStatus>(status: T) => void;
onError?: ({ step, platform }: {
step: LIST_STATUS_STEP;
platform: Platform;
}, error: any) => void;
}): Promise<SaleOffer>;

@@ -46,0 +57,0 @@ transfer(ownerEthAddress: string, recipientEthAddress: string, amount?: number): Promise<EvmTransaction>;

67

lib/nft/ERC1155NFT.js

@@ -15,6 +15,4 @@ "use strict";

const graphql_1 = require("../@types/graphql");
const sale_1 = require("../graphql/sale");
const InsufficientBalanceError_1 = require("../errors/InsufficientBalanceError");
const AbstractEvmNFT_1 = require("./AbstractEvmNFT");
const ERCSaleId_1 = require("./ERCSaleId");
const SaleInfo_1 = require("./interfaces/SaleInfo");
class ERC1155NFT extends AbstractEvmNFT_1.AbstractEvmNFT {

@@ -24,2 +22,9 @@ constructor(refinable, item) {

}
getBalance(ownerAddress) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const nftTokenContract = yield this.getTokenContractWrapper();
return (_a = (yield nftTokenContract.read.balanceOf(ownerAddress !== null && ownerAddress !== void 0 ? ownerAddress : this.refinable.accountAddress, this.item.tokenId))) === null || _a === void 0 ? void 0 : _a.toNumber();
});
}
approve(operatorAddress) {

@@ -73,45 +78,17 @@ return __awaiter(this, void 0, void 0, function* () {

return __awaiter(this, void 0, void 0, function* () {
const { price, startTime, endTime, launchpadDetails, supply = 1 } = params;
this.verifyItem();
// validate launchpad
if (startTime && (launchpadDetails === null || launchpadDetails === void 0 ? void 0 : launchpadDetails.stages)) {
for (let i = 0; i < launchpadDetails.stages.length; i++) {
const stage = launchpadDetails.stages[i];
if (stage.startTime >= startTime) {
throw new Error(`The start time of the ${stage.stage} stage (index: ${i}) is after the start time of the public sale, this whitelist won't have any effect. Please remove this stage or adjust its startTime`);
}
}
}
const addressForApproval = this.transferProxyContract.address;
yield this.approveIfNeeded(addressForApproval);
const saleParamHash = yield this.getSaleParamsHash({
price,
ethAddress: this.refinable.accountAddress,
supply,
startTime,
endTime,
isV2: true,
// Check if current user has sufficient balance to put for sale
const currentUserBalance = yield this.getBalance();
if (currentUserBalance < params.supply)
throw new InsufficientBalanceError_1.InsufficientBalanceError(currentUserBalance);
return this._putForSale({
price: params.price,
startTime: params.startTime,
endTime: params.endTime,
launchpadDetails: params.launchpadDetails,
onError: params.onError,
onInitialize: params.onInitialize,
onProgress: params.onProgress,
platforms: [],
supply: params.supply,
});
const signedHash = yield this.refinable.account.sign(saleParamHash);
const saleId = yield this.getSaleId();
const blockchainId = new ERCSaleId_1.ERCSaleID(saleId, SaleInfo_1.SaleVersion.V2).toBlockchainId();
const result = yield this.refinable.graphqlClient.request(sale_1.CREATE_OFFER, {
input: {
chainId: this.item.chainId,
tokenId: this.item.tokenId,
signature: signedHash,
type: graphql_1.OfferType.Sale,
contractAddress: this.item.contractAddress,
price: {
payToken: price.address,
amount: parseFloat(price.amount.toString()),
},
supply,
startTime,
endTime,
launchpadDetails,
blockchainId,
},
});
return this.refinable.offer.createOffer(result.createOfferForItems, this);
});

@@ -118,0 +95,0 @@ }

@@ -11,2 +11,3 @@ import { LaunchpadDetailsInput, MarketConfig, Platform } from "../@types/graphql";

constructor(refinable: Refinable, item: PartialNFTItem);
getOwner(): Promise<string>;
approve(operatorAddress: string): Promise<EvmTransaction>;

@@ -13,0 +14,0 @@ isApproved(operatorAddress: string): Promise<boolean>;

@@ -17,9 +17,5 @@ "use strict";

const graphql_1 = require("../@types/graphql");
const sale_1 = require("../graphql/sale");
const platform_1 = require("../platform");
const InsufficientBalanceError_1 = require("../errors/InsufficientBalanceError");
const EvmTransaction_1 = __importDefault(require("../transaction/EvmTransaction"));
const AbstractEvmNFT_1 = require("./AbstractEvmNFT");
const ERCSaleId_1 = require("./ERCSaleId");
const SaleInfo_1 = require("./interfaces/SaleInfo");
const SaleStatusStep_1 = require("./interfaces/SaleStatusStep");
class ERC721NFT extends AbstractEvmNFT_1.AbstractEvmNFT {

@@ -29,2 +25,8 @@ constructor(refinable, item) {

}
getOwner() {
return __awaiter(this, void 0, void 0, function* () {
const nftTokenContract = yield this.getTokenContractWrapper();
return nftTokenContract.read.ownerOf(this._item.tokenId);
});
}
approve(operatorAddress) {

@@ -99,151 +101,18 @@ return __awaiter(this, void 0, void 0, function* () {

return __awaiter(this, void 0, void 0, function* () {
const { price, startTime, endTime, launchpadDetails, platforms = [], onInitialize = () => true, onProgress = () => true, onError = () => true, } = params;
// calculate steps
const steps = [
{
step: SaleStatusStep_1.LIST_STATUS_STEP.APPROVE,
platform: graphql_1.Platform.Refinable,
},
{
step: SaleStatusStep_1.LIST_STATUS_STEP.SIGN,
platform: graphql_1.Platform.Refinable,
},
{
step: SaleStatusStep_1.LIST_STATUS_STEP.CREATE,
platform: graphql_1.Platform.Refinable,
},
];
if (Array.isArray(platforms)) {
for (const platform of platforms) {
steps.push({
step: SaleStatusStep_1.LIST_STATUS_STEP.APPROVE,
platform,
}, {
step: SaleStatusStep_1.LIST_STATUS_STEP.SIGN,
platform,
}, {
step: SaleStatusStep_1.LIST_STATUS_STEP.CREATE,
platform,
});
}
}
onInitialize(steps);
this.verifyItem();
// validate launchpad
if (startTime && (launchpadDetails === null || launchpadDetails === void 0 ? void 0 : launchpadDetails.stages)) {
for (let i = 0; i < launchpadDetails.stages.length; i++) {
const stage = launchpadDetails.stages[i];
if (stage.startTime >= startTime) {
throw new Error(`The start time of the ${stage.stage} stage (index: ${i}) is after the start time of the public sale, this whitelist won't have any effect. Please remove this stage or adjust its startTime`);
}
}
}
let saleParamsHash;
try {
yield this.approveIfNeeded(this.transferProxyContract.address, () => {
onProgress({
step: SaleStatusStep_1.LIST_STATUS_STEP.APPROVE,
platform: graphql_1.Platform.Refinable,
data: {
addressToApprove: this.transferProxyContract.address,
},
});
});
saleParamsHash = yield this.getSaleParamsHash({
price,
ethAddress: this.refinable.accountAddress,
startTime,
endTime,
isV2: true,
});
}
catch (ex) {
onError({
step: SaleStatusStep_1.LIST_STATUS_STEP.APPROVE,
platform: graphql_1.Platform.Refinable,
}, ex);
throw ex;
}
onProgress({
step: SaleStatusStep_1.LIST_STATUS_STEP.SIGN,
platform: graphql_1.Platform.Refinable,
data: {
what: "Sale Parameters",
hash: saleParamsHash,
},
// Check if current user has sufficient balance to put for sale
const ownerEthAddress = yield this.getOwner();
if (ownerEthAddress.toLowerCase() !==
this.refinable.accountAddress.toLowerCase())
throw new InsufficientBalanceError_1.InsufficientBalanceError();
return this._putForSale({
price: params.price,
startTime: params.startTime,
endTime: params.endTime,
launchpadDetails: params.launchpadDetails,
onError: params.onError,
onInitialize: params.onInitialize,
onProgress: params.onProgress,
platforms: params.platforms,
supply: 1,
});
let signedHash, saleId, blockchainId;
try {
signedHash = yield this.refinable.account.sign(saleParamsHash);
saleId = yield this.getSaleId();
blockchainId = new ERCSaleId_1.ERCSaleID(saleId, SaleInfo_1.SaleVersion.V2).toBlockchainId();
}
catch (ex) {
onError({
step: SaleStatusStep_1.LIST_STATUS_STEP.SIGN,
platform: graphql_1.Platform.Refinable,
}, ex);
throw ex;
}
onProgress({
step: SaleStatusStep_1.LIST_STATUS_STEP.CREATE,
platform: graphql_1.Platform.Refinable,
data: {
chainId: this.item.chainId,
tokenId: this.item.tokenId,
signature: signedHash,
type: graphql_1.OfferType.Sale,
contractAddress: this.item.contractAddress,
price: Object.assign(Object.assign({}, price), { amount: parseFloat(price.amount.toString()) }),
startTime,
endTime,
supply: 1,
launchpadDetails,
blockchainId,
},
});
let result;
try {
result = yield this.refinable.graphqlClient.request(sale_1.CREATE_OFFER, {
input: {
chainId: this.item.chainId,
tokenId: this.item.tokenId,
signature: signedHash,
type: graphql_1.OfferType.Sale,
contractAddress: this.item.contractAddress,
price: {
payToken: price.address,
amount: parseFloat(price.amount.toString()),
},
startTime,
endTime,
supply: 1,
launchpadDetails,
blockchainId,
},
});
}
catch (ex) {
onError({
step: SaleStatusStep_1.LIST_STATUS_STEP.CREATE,
platform: graphql_1.Platform.Refinable,
}, ex);
throw ex;
}
onProgress({
step: SaleStatusStep_1.LIST_STATUS_STEP.DONE,
platform: graphql_1.Platform.Refinable,
data: result,
});
// third party platforms
if (Array.isArray(platforms)) {
const platformFactory = new platform_1.PlatformFactory(this.refinable);
for (const platform of platforms) {
const platformInstance = platformFactory.createPlatform(platform);
yield platformInstance.listForSale(this, price, {
onProgress,
});
}
}
return this.refinable.offer.createOffer(result.createOfferForItems, this);
});

@@ -250,0 +119,0 @@ }

@@ -42,3 +42,3 @@ "use strict";

const parseMetaMaskError = (metaMaskError) => {
var _a, _b, _c, _d, _e;
var _a, _b, _c, _d, _e, _f;
const error = JSON.parse(JSON.stringify(metaMaskError));

@@ -57,3 +57,3 @@ const errorData = error["data"];

}
const msg = (_e = (_c = (_b = (_a = data === null || data === void 0 ? void 0 : data.reason) !== null && _a !== void 0 ? _a : data === null || data === void 0 ? void 0 : data.message) !== null && _b !== void 0 ? _b : error === null || error === void 0 ? void 0 : error.message) !== null && _c !== void 0 ? _c : (_d = error === null || error === void 0 ? void 0 : error.error) === null || _d === void 0 ? void 0 : _d.message) !== null && _e !== void 0 ? _e : "Something went wrong. Please try again later.";
const msg = (_f = (_e = (_c = (_b = (_a = data === null || data === void 0 ? void 0 : data.reason) !== null && _a !== void 0 ? _a : data === null || data === void 0 ? void 0 : data.message) !== null && _b !== void 0 ? _b : error === null || error === void 0 ? void 0 : error.message) !== null && _c !== void 0 ? _c : (_d = error === null || error === void 0 ? void 0 : error.error) === null || _d === void 0 ? void 0 : _d.message) !== null && _e !== void 0 ? _e : metaMaskError === null || metaMaskError === void 0 ? void 0 : metaMaskError.message) !== null && _f !== void 0 ? _f : "Something went wrong. Please try again later.";
// rpc errors are special as they're wrapped, extract the value and handle that

@@ -60,0 +60,0 @@ const rpcError = msg.match(/\[ethjs-query\] while formatting outputs from RPC '(.*)'/);

{
"name": "@refinableco/refinable-sdk",
"version": "5.0.0-next.6",
"version": "5.0.0-next.7",
"description": "The Refinable SDK allows you to easily interact with the Refinable Marketplace to mint, sell and buy NFTs",

@@ -25,3 +25,3 @@ "main": "./lib/index.js",

"eth-rpc-errors": "^4.0.3",
"ethers": "^5.7.0",
"ethers": "^5.7.2",
"eventemitter3": "^4.0.7",

@@ -28,0 +28,0 @@ "form-data": "^4.0.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc