From 34054343b381c14c2d822354c63fe6e203f3a6a6 Mon Sep 17 00:00:00 2001 From: lewinskimaciej Date: Tue, 9 Jan 2024 08:57:14 +0100 Subject: [PATCH] feat: update transactions and marketplace with v2 endpoints --- .../assets/managing-profile-assets.mdx | 8 +-- .../service/assets/reading-profile-assets.mdx | 16 ++++-- pages/service/marketplace/buying-assets.mdx | 4 +- pages/service/marketplace/currencies.mdx | 4 +- pages/service/marketplace/listing-assets.mdx | 5 +- pages/service/marketplace/offers.mdx | 51 ++++++++----------- pages/service/transactions/custom-charges.mdx | 11 ++-- .../profile-paid-transactions.mdx | 11 ++-- .../transactions/sponsored-transactions.mdx | 11 ++-- 9 files changed, 64 insertions(+), 57 deletions(-) diff --git a/pages/service/assets/managing-profile-assets.mdx b/pages/service/assets/managing-profile-assets.mdx index 65c92f6..a580897 100644 --- a/pages/service/assets/managing-profile-assets.mdx +++ b/pages/service/assets/managing-profile-assets.mdx @@ -17,7 +17,7 @@ If we registered an ERC20 contract for your game, you are able to manage the ERC Initiating a token transfer would look something like this. In the example below, we are not considering more complicated features like sponsoring transactions just yet - the transaction will be paid for by you - the game developer. ```typescript -const transaction = await beam.assets.transferToken("your-sender-id", { +const transaction = await beam.assetsV2.transferTokenV2("your-sender-id", { receiverEntityId: "your-receiver-id", assetAddress: "your-contract-address", amountToTransfer: "10", // 10 means 10 - we don't expect you to consider any other format like gwei @@ -36,11 +36,11 @@ const transaction = await beam.assets.transferToken("your-sender-id", { Asset transfers work in a similar fashion as ERC20 token transfers, but instead of calling the `transferToken`, you will need to call the `transferAsset` method and pass an `assetId` property for the asset you want to move around. ```typescript -const transaction = await beam.assets.transferAsset("your-sender-id", { +const transaction = await beam.assetsV2.transferAssetV2("your-sender-id", { receiverEntityId: "your-receiver-id", assetAddress: "your-contract-address", assetId: "73", - amountToTransfer: "1", // amountToTransfer is related to 1155, defaults to 1 and doesn't have to be passed for ERC721 contracts. + amountToTransfer: 1, // amountToTransfer is related to 1155, defaults to 1 and doesn't have to be passed for ERC721 contracts. }); // { @@ -56,7 +56,7 @@ const transaction = await beam.assets.transferAsset("your-sender-id", { Lastly - we offer you the possibility to transfer our native token: BEAM. Depending on the context of your game, you might want to be able to transfer our native token around between profiles. ```typescript -const transaction = await beam.assets.transferNativeToken("your-sender-id", { +const transaction = await beam.assetsV2.transferNativeTokenV2("your-sender-id", { receiverEntityId: "your-receiver-id", amountToTransfer: "10", // 10 means 10 - we don't expect you to consider any other format like gwei }); diff --git a/pages/service/assets/reading-profile-assets.mdx b/pages/service/assets/reading-profile-assets.mdx index b4a1029..6bcdddd 100644 --- a/pages/service/assets/reading-profile-assets.mdx +++ b/pages/service/assets/reading-profile-assets.mdx @@ -15,7 +15,14 @@ By running the following method, you will receive all ERC721 and ERC1155 type as Note that at the moment of writing, we do not expose filtering options yet - but they are expected to drop soon in order for you to filter in different ways to get meaningful results. ```typescript -const profileAssets = await beam.assets.getProfileAssets("entity-id"); +const profileAssets = await beam.assetsV2.getProfileAssetsForGamePostV2("entity-id", { + sortDirection: 'desc'; + sortBy: 'acquiredAt'; + contract: "0x..."; // if you want to get assets only from one collection, null/undefined otherwise + includeAttributes: true; // defaults to false + continuation: null; // pagination continuation token + limit: 20; +}); // { // "data": [ @@ -42,7 +49,7 @@ const profileAssets = await beam.assets.getProfileAssets("entity-id"); In order to get all ERC20 token balances for a profile, you can run the `getProfileCurrencies` method. The response model for this enpdoint is not paginated, as we don't expect a single game to have more than a few on-chain currencies to support their in-game economy. ```typescript -const profileTokens = await beam.assets.getProfileCurrencies("entity-id"); +const profileTokens = await beam.assetsV2.getProfileCurrenciesV2("entity-id"); // { // "data": [ @@ -52,6 +59,7 @@ const profileTokens = await beam.assets.getProfileCurrencies("entity-id"); // "symbol": "string", // "decimals": 0, // "logoUri": "string", +// "chainId": 13337; // "balance": "string" // } // ] @@ -63,7 +71,7 @@ const profileTokens = await beam.assets.getProfileCurrencies("entity-id"); If you are interested in validating the native currency of a profile, for example to validate whenever the profile has enough BEAM to run a self-paid transaction, you could fetch the native token balance directly by doing the following: ```typescript -const profileTokens = await beam.assets.getProfileNativeCurrency("entity-id"); +const profileTokens = await beam.assetsV2.getProfileNativeCurrencyV2("entity-id"); // { // "nativeTokenBalance": { @@ -71,7 +79,7 @@ const profileTokens = await beam.assets.getProfileNativeCurrency("entity-id"); // "symbol": "string", // "decimals": 0, // "logoUri": "string", -// "chainId": 0, +// "chainId": 13337, // "balance": "string" // } // } diff --git a/pages/service/marketplace/buying-assets.mdx b/pages/service/marketplace/buying-assets.mdx index 55d271e..a6470ed 100644 --- a/pages/service/marketplace/buying-assets.mdx +++ b/pages/service/marketplace/buying-assets.mdx @@ -3,14 +3,12 @@ If a user shows interest in a listing for sale by another profile, it's possible to buy the listed asset with a profile by simply calling the `buyListedAsset` method. Note that in order to actually buy the asset, the buyer-profile needs to be funded with enough BEAM based on the listing price set by the seller profile. ```typescript -const response = await beam.marketplace.buyListedAsset('buyer-profile-id', { - orderId: '' // data[0].orderId from the getListedAssetsForProfile method, +const response = await beam.marketplaceV2.buyListedAssetV2('buyer-profile-id', 'order-id-to-fulfill' { quantity: 1 // the amount of NFTs to buy, only relevant for ERC-1155 based tokens, defaults to 1 }); // { // "status": "success", -// "type": "custodial", // "transactionHash": '0x71f3f259568e9875c41a4350a3912a3a7650d9321ccd1d57641241128b4e504f', // "explorerUrl": "https://subnets.avax.network/beam/0x71f3f259568e9875c41a4350a3912a3a7650d9321ccd1d57641241128b4e504f" // } diff --git a/pages/service/marketplace/currencies.mdx b/pages/service/marketplace/currencies.mdx index dde0404..7a4149e 100644 --- a/pages/service/marketplace/currencies.mdx +++ b/pages/service/marketplace/currencies.mdx @@ -7,14 +7,14 @@ title: Currencies At the moment of writing the Beam marketplace supports a couple of pre-configured tokens for all marketplace interactions. In order to get the currencies supported for a specific chain, we've added a method. Here's how you can use it: ```typescript -const currencies = await beam.marketplace.getCurrencies(4337); // the chain ID you want to get the supported currencies for +const currencies = await beam.marketplaceV2.getChainCurrenciesV2(4337); // the chain ID you want to get the supported currencies for // { // data: [ // { // currency: 'USDC' // decimals: 18, -// tokenAddress: '0x007Fdc86FD12924C9116025C7F594843087397E3' +// address: '0x007Fdc86FD12924C9116025C7F594843087397E3' // } // ] // } diff --git a/pages/service/marketplace/listing-assets.mdx b/pages/service/marketplace/listing-assets.mdx index a9b9954..6a66139 100644 --- a/pages/service/marketplace/listing-assets.mdx +++ b/pages/service/marketplace/listing-assets.mdx @@ -3,8 +3,9 @@ In order to list an asset on behalf of a profile you need to give us some information about the listing. ```typescript -const transaction = await beam.marketplace.listAsset('profile-seller-id', { - marketplaceId": "64df956525e46b4d63ae37e9, +const transaction = await beam.marketplaceV2.listAssetV2('profile-seller-id', { + assetAddress: '0x...', + assetId: '1', quantity: 1 // You can list multiple 1155 assets from the same token, defaults to 1 price: '1000', // Listing price in BEAM token sellType: 'FixedPrice' // AscendingAuction, DescendingAuction or FixedPrice diff --git a/pages/service/marketplace/offers.mdx b/pages/service/marketplace/offers.mdx index 2df113f..6fb8473 100644 --- a/pages/service/marketplace/offers.mdx +++ b/pages/service/marketplace/offers.mdx @@ -16,11 +16,12 @@ Based on the available currencies, you can create an offer for items which are l ```typescript -const transaction = await beam.marketplace.createAssetOffer('profile-offerer-id', { - marketplaceId: "64df956525e46b4d63ae37e9", +const transaction = await beam.marketplaceV2.createAssetOfferV2('profile-offerer-id', { + assetAddress: '0x...', + assetId: '1', quantity: 1 // You can make an offer for multiple 1155 assets from the same token price: '1000', // Listing price - currency: 'USDC' // Defaults to BEAM. Find all available options through the getCurrencies() method; + currency: 'USDC' // Defaults to WBEAM. Find all available options through the getCurrencies() method; You cannot use native(BEAM) to make offers. }); // { @@ -34,9 +35,9 @@ const transaction = await beam.marketplace.createAssetOffer('profile-offerer-id' If you want to cancel the offer, you can use the following snippet. ```typescript -const transaction = await beam.marketplace.cancelAssetOffer( - "profile-offerer-id", - "651bfbb9b47baf2d2a092c04" +const transaction = await beam.marketplaceV2.cancelAssetOfferV2("profile-offerer-id", { + offerId: 'offer-id-you-created' +} ); // { @@ -51,34 +52,23 @@ const transaction = await beam.marketplace.cancelAssetOffer( If you want to list all the offers made to an NFT, you are able to do so with the following snippets ```typescript -const transaction = await beam.marketplace.getAssetOffers( - "asset-marketplace-id" +// Get all offers for an asset +const transaction = await beam.marketplaceV2.getAssetOffersV2( + "asset-address", + "asset-id" ); -const transaction = await beam.marketplace.getProfileOffers( + +// Get all offers that player created +const transaction = await beam.marketplaceV2.getPlayerOffersV2( "profile-offerer-id" ); -const transaction = await beam.marketplace.getProfileAssetOffers( + +//Get all asset offers that player created +const transaction = await beam.marketplaceV2.getPlayerAssetOffersV2( "profile-offerer-id", - "asset-marketplace-id" + "asset-address", + "asset-id" ); - -// { -// "data": [ -// { -// "orderId": "651578cd46df7c4288b267cc", -// "kind": "SignedSingleOrder", -// "currency": "Wmc", -// "quantity": 1, -// "quantityFilled": 0, -// "quantityAvailable": 1, -// "offerer": "0x106b7272d041727878Aff54514e81DEEF546C64d", -// "tokenAmount": "0x01b4fbd92b5f8000", -// "tokenAmountNumber": 0.123, -// "startTime": "2023-07-08T12:35:00.000Z", -// "endTime": "2023-08-08T12:35:00.000Z" -// } -// ] -// } ``` ### Accepting an offer @@ -86,9 +76,10 @@ const transaction = await beam.marketplace.getProfileAssetOffers( If an item is listed by a profile that is managed by you through the SDK, it's possible to accept an offer through the SDK as well. Keep in mind that not every listing is managed through the SDK: accepting offers to an asset on Sphere only can be done if you manage the profile that listed it in the first place. ```typescript -const transaction = await beam.marketplace.acceptAssetOffer( +const transaction = await beam.marketplaceV2.acceptAssetOfferV2( "profile-seller-id", { + offerId: 'offer-id-you-accept' quantity: 1, // You can accept multiple 1155 assets from the same token } ); diff --git a/pages/service/transactions/custom-charges.mdx b/pages/service/transactions/custom-charges.mdx index 0842a56..17054e8 100644 --- a/pages/service/transactions/custom-charges.mdx +++ b/pages/service/transactions/custom-charges.mdx @@ -15,10 +15,13 @@ You could charge your users an X amount of Gold by simply creating a policy, and Eventually, you as a game developer will be responsible for funding the BEAM for all the transactions that are ran through our service, so if you take away in-game Gold, you have to consider if it is economically viable to make this transaction. Let's assume a single transaction on Beam costs < 0.001 BEAM, and a Gold costs the user $ 0.05 to obtain - this means that the transaction through the policy is now not only economically viable, it also allows you to to sponsor quite some transactions for the user as the single Gold paid for the transaction in tenfold. ```typescript -const transaction = await beam.assets.transferAsset("your-sender-id", { - receiverEntityId: "your-receiver-id", - assetAddress: "your-contract-address", - assetId: "73", +const transaction = await beam.assetsV2.transferAssetV2("your-sender-id", { + assets: [ + receiverEntityId: "your-receiver-id", + assetAddress: "your-contract-address", + assetId: "73", + amountToTransfer: 1, + ] // ... sponsor: false, // 👈 This handles the transaction to be self paid policyId: "cl..", // 👈 This triggers the custom policy to be used diff --git a/pages/service/transactions/profile-paid-transactions.mdx b/pages/service/transactions/profile-paid-transactions.mdx index cedcf47..d158a20 100644 --- a/pages/service/transactions/profile-paid-transactions.mdx +++ b/pages/service/transactions/profile-paid-transactions.mdx @@ -20,10 +20,13 @@ Take into account that if the Profile doesn't actually have the necessary BEAM f Below you will find an example how this would look like when managing assets in a Profile ```typescript -const transaction = await beam.assets.transferAsset("your-sender-id", { - receiverEntityId: "your-receiver-id", - assetAddress: "your-contract-address", - assetId: "73", +const transaction = await beam.assetsV2.transferAssetV2("your-sender-id", { + assets: [ + receiverEntityId: "your-receiver-id", + assetAddress: "your-contract-address", + assetId: "73", + amountToTransfer: 1, + ] // ... sponsor: false, // 👈 This handles the transaction to be self paid }); diff --git a/pages/service/transactions/sponsored-transactions.mdx b/pages/service/transactions/sponsored-transactions.mdx index cd7c532..ebed3bb 100644 --- a/pages/service/transactions/sponsored-transactions.mdx +++ b/pages/service/transactions/sponsored-transactions.mdx @@ -13,10 +13,13 @@ We think this default is sensible, as it's you as the game developer are in cont To paint a clearer picture on how this looks like, below you'll find a transaction which is sponsored ```typescript -const transaction = await beam.assets.transferAsset("your-sender-id", { - receiverEntityId: "your-receiver-id", - assetAddress: "your-contract-address", - assetId: "73", +const transaction = await beam.assetsV2.transferAssetV2("your-sender-id", { + assets: [ + receiverEntityId: "your-receiver-id", + assetAddress: "your-contract-address", + assetId: "73", + amountToTransfer: 1, + ] // ... sponsor: true, // 👈 true is also the default. });