Skip to content

Commit

Permalink
#NOISSUE - add support to bid / buy NFT asset from Auction / Marketpl…
Browse files Browse the repository at this point in the history
…ace for ERC20 on behalf of someone else
  • Loading branch information
Samuel Sramko committed Oct 21, 2021
1 parent 6295732 commit baa81d3
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tatumio/tatum",
"version": "1.28.17",
"version": "1.29.0",
"description": "Tatum API client allows browsers and Node.js clients to interact with Tatum API.",
"main": "dist/src/index.js",
"repository": "https://github.com/tatumio/tatum-js",
Expand Down
25 changes: 24 additions & 1 deletion src/contracts/marketplace/auction.ts

Large diffs are not rendered by default.

25 changes: 24 additions & 1 deletion src/contracts/marketplace/listing.ts

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/model/request/InvokeAuctionOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export class InvokeAuctionOperation extends PrivateKeyOrSignatureId {
@Matches(/^[+]?((\d+(\.\d*)?)|(\.\d+))$/)
public bidValue: string;

@IsOptional()
@Length(34, 43)
public bidder?: string;

@IsOptional()
@Min(0)
public nonce?: number;
Expand Down
14 changes: 9 additions & 5 deletions src/model/request/InvokeMarketplaceListingOperation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {Type} from 'class-transformer'
import {IsIn, IsNotEmpty, IsNumberString, IsOptional, Length, Matches, Min} from 'class-validator'
import {Currency} from './Currency'
import {Fee} from './Fee'
import {PrivateKeyOrSignatureId} from './PrivateKeyOrSignatureId'
import {Type} from 'class-transformer';
import {IsIn, IsNotEmpty, IsNumberString, IsOptional, Length, Matches, Min} from 'class-validator';
import {Currency} from './Currency';
import {Fee} from './Fee';
import {PrivateKeyOrSignatureId} from './PrivateKeyOrSignatureId';

export class InvokeMarketplaceListingOperation extends PrivateKeyOrSignatureId {

Expand All @@ -17,6 +17,10 @@ export class InvokeMarketplaceListingOperation extends PrivateKeyOrSignatureId {
@IsNotEmpty()
public listingId: string;

@IsOptional()
@Length(34, 43)
public buyer?: string;

@IsOptional()
@Length(34, 43)
public erc20Address?: string;
Expand Down
11 changes: 10 additions & 1 deletion src/nft/marketplace/auction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,25 @@ export const prepareAuctionBid = async (testnet: boolean, body: InvokeAuctionOpe
// @ts-ignore
const a = await (new web3.eth.Contract(auction.abi, body.contractAddress)).methods.getAuction(body.id).call();
let decimals = 18;
let methodName = 'bid';
const b: any = {...body};
if (a[6] !== '0x0000000000000000000000000000000000000000') {
// @ts-ignore
decimals = await getErc20Decimals(testnet, body.chain, a[6], provider);
if (body.bidder) {
methodName = 'bidForExternalBidder';
}
} else if (body.bidder) {
throw new Error('Bidder could be present only for ERC20 based auctions.');
} else {
b.amount = body.bidValue;
}

const params = [body.id, `0x${new BigNumber(body.bidValue).multipliedBy(new BigNumber(10).pow(decimals)).toString(16)}`,];
return await helperPrepareSCCall(testnet, b, InvokeAuctionOperation, 'bid', params, undefined, provider, auction.abi);
if (body.bidder) {
params.push(body.bidder.trim());
}
return await helperPrepareSCCall(testnet, b, InvokeAuctionOperation, methodName, params, undefined, provider, auction.abi);
};

/**
Expand Down
7 changes: 6 additions & 1 deletion src/nft/marketplace/listing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,13 @@ export const prepareMarketplaceCreateListing = async (testnet: boolean, body: Cr
export const prepareMarketplaceBuyListing = async (testnet: boolean, body: InvokeMarketplaceListingOperation | InvokeTronMarketplaceListingOperation, provider?: string) => {
await validateBody(body, body.chain === Currency.TRON ? InvokeTronMarketplaceListingOperation : InvokeMarketplaceListingOperation);
const params = [body.listingId, body.erc20Address || '0x0000000000000000000000000000000000000000'];
let methodName = 'buyAssetFromListing';
if (body.erc20Address) {
body.amount = undefined;
if (body.buyer) {
params.push(body.buyer.trim());
methodName = 'buyAssetFromListingForExternalBuyer';
}
}
if (body.chain === Currency.TRON) {
throw new Error('Unsupported chain');
Expand All @@ -283,7 +288,7 @@ export const prepareMarketplaceBuyListing = async (testnet: boolean, body: Invok
// {type: 'address', value: convertAddressToHex(params[1])},
// ], 'buyAssetFromListing(string,address)', provider);
} else {
return await helperPrepareSCCall(testnet, body, InvokeMarketplaceListingOperation, 'buyAssetFromListing', params, undefined, provider);
return await helperPrepareSCCall(testnet, body, InvokeMarketplaceListingOperation, methodName, params, undefined, provider);
}
};

Expand Down

0 comments on commit baa81d3

Please sign in to comment.