@tradeport/sui-trading-sdk 0.4.62 → 0.4.64
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/dist/index.d.mts +21 -50
- package/dist/index.d.ts +21 -50
- package/dist/index.js +255 -631
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +248 -619
- package/dist/index.mjs.map +1 -1
- package/package.json +59 -61
- package/src/SuiTradingClient.ts +37 -65
- package/src/index.ts +0 -1
- package/src/methods/buyListings/buyListings.ts +4 -11
- package/src/methods/createMultiBid/createMultiBid.ts +3 -4
- package/src/methods/listNfts/listNfts.ts +7 -9
- package/src/methods/placeCollectionBids/placeCollectionBids.ts +14 -13
- package/src/methods/placeNftBids/placeNftBids.ts +6 -12
- package/src/methods/sponsorNftListing/addSponsorNftListingTx.ts +14 -44
- package/src/methods/sponsorNftListing/sponsorNftListing.ts +10 -15
- package/src/methods/updateMultiBid/updateMultiBid.ts +19 -15
- package/src/utils/addLeadingZerosAfter0x.ts +7 -0
- package/.claude/settings.local.json +0 -5
- package/src/helpers/deserializeOrCreateTxBlock.ts +0 -13
- package/src/helpers/extractSwapResultCoin.ts +0 -17
- package/src/methods/swapCoins/swapCoins.ts +0 -400
package/dist/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/index.ts
|
|
@@ -178,16 +168,6 @@ var TRADEPORT_NFT_STRATEGY_PACKAGE_ID = "0xb7386fc8c6e64ea2b0079e293592b57e98498
|
|
|
178
168
|
var TRADEPORT_NFT_STRATEGY_MANAGER_ID = "0xfb58ee62b3a62a8150f871da950dfdf923cd0d97b153caf99b5219cd4ddda5bd";
|
|
179
169
|
var TRADEPORT_POOL_REGISTRY_ID = "0xcd0a614c4cbbf173f59dee2602c43a1717f283215ed7a0bb1d55d786af16fbcd";
|
|
180
170
|
var TRADEPORT_POOL_VERSIONED_ID = "0x0309b66202e9aaf470081fffee7ffc0fbd50e3b7400d4f56fd06502e4dbbd676";
|
|
181
|
-
var DexConstants = {
|
|
182
|
-
commission: "0x24f5f2258ef80c0a3243088199faeb95ad50516ca1517dbd93be398d759057bb",
|
|
183
|
-
commissionManager: "0xd19a03d4ec3d12b0ce407b54eb676cc0f8e1403621deda77d9677bfcb9d738c1",
|
|
184
|
-
poolsToExclude: [
|
|
185
|
-
"0x3addbbc82866c0bbd93e51b6e2d75c0a4faaf270cc0e281d8f4de5df48bebfa4",
|
|
186
|
-
"0x19d614f421046cae90f5a3a976816063478f648087a12adc74e90ebd54dfaf19",
|
|
187
|
-
"0x514c74e28a9720366abc4a65a5688f47c72e784dbf035844d3f59059bfaed056",
|
|
188
|
-
"0x0854de4e9d64716b757b2f6f22258467f59cc1b4bc0cc64c70086549faaddedf"
|
|
189
|
-
]
|
|
190
|
-
};
|
|
191
171
|
var USDC_COIN_TYPE = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
|
|
192
172
|
var COLLECTION_IDS_WITH_ZERO_COMMISSION = [
|
|
193
173
|
""
|
|
@@ -3616,16 +3596,6 @@ var getCollectionChainState = async (collectionId) => {
|
|
|
3616
3596
|
});
|
|
3617
3597
|
return res?.collections?.[0]?.chain_state;
|
|
3618
3598
|
};
|
|
3619
|
-
var getCollectionChainStateByFtType = async (ftType) => {
|
|
3620
|
-
const res = await gqlChainRequest({
|
|
3621
|
-
chain: "sui",
|
|
3622
|
-
query: fetchCollectionChainStateByFtType,
|
|
3623
|
-
variables: {
|
|
3624
|
-
ftType
|
|
3625
|
-
}
|
|
3626
|
-
});
|
|
3627
|
-
return res?.collections_by_ft_type?.[0]?.chain_state;
|
|
3628
|
-
};
|
|
3629
3599
|
|
|
3630
3600
|
// src/methods/applyFtStrategy/applyFtStrategy.ts
|
|
3631
3601
|
async function applyFtStrategy({
|
|
@@ -3660,12 +3630,105 @@ async function applyFtStrategy({
|
|
|
3660
3630
|
return tx;
|
|
3661
3631
|
}
|
|
3662
3632
|
|
|
3633
|
+
// src/methods/applyNftStrategy/applyNftStrategy.ts
|
|
3634
|
+
var import_transactions5 = require("@mysten/sui/transactions");
|
|
3635
|
+
|
|
3636
|
+
// src/graphql/queries/fetchCollectionFloorListingForMarket.ts
|
|
3637
|
+
var import_graphql_request13 = require("graphql-request");
|
|
3638
|
+
var fetchCollectionFloorListingsForMarket = import_graphql_request13.gql`
|
|
3639
|
+
query fetchCollectionFloorListingsForMarket(
|
|
3640
|
+
$collectionId: uuid!
|
|
3641
|
+
$marketAddress: String!
|
|
3642
|
+
$totalPrice: numeric
|
|
3643
|
+
) {
|
|
3644
|
+
listings(
|
|
3645
|
+
where: {
|
|
3646
|
+
collection_id: { _eq: $collectionId }
|
|
3647
|
+
listed: { _eq: true }
|
|
3648
|
+
market_name: { _eq: "tradeport" }
|
|
3649
|
+
seller: { _neq: $marketAddress }
|
|
3650
|
+
nonce: { _like: "1::0x%" }
|
|
3651
|
+
price: { _lte: $totalPrice }
|
|
3652
|
+
}
|
|
3653
|
+
order_by: [{ price: asc_nulls_last }, { block_height: asc }, { tx_index: asc }]
|
|
3654
|
+
) {
|
|
3655
|
+
id
|
|
3656
|
+
price
|
|
3657
|
+
nft {
|
|
3658
|
+
token_id
|
|
3659
|
+
delegated_owner
|
|
3660
|
+
}
|
|
3661
|
+
}
|
|
3662
|
+
}
|
|
3663
|
+
`;
|
|
3664
|
+
|
|
3665
|
+
// src/methods/applyNftStrategy/applyNftStrategy.ts
|
|
3666
|
+
async function applyTradeportNftStrategy({
|
|
3667
|
+
collectionId,
|
|
3668
|
+
strategyFtType,
|
|
3669
|
+
tx: existingTx
|
|
3670
|
+
}) {
|
|
3671
|
+
const tx = existingTx ?? new import_transactions5.Transaction();
|
|
3672
|
+
const chainState = await getCollectionChainState(collectionId);
|
|
3673
|
+
const nftStrategies = chainState?.nft_strategies ?? {};
|
|
3674
|
+
const nftStrategyKeys = Object.keys(nftStrategies);
|
|
3675
|
+
if (nftStrategyKeys.length === 0) {
|
|
3676
|
+
throw new Error("No NFT strategies found for collection");
|
|
3677
|
+
}
|
|
3678
|
+
strategyFtType = strategyFtType ?? nftStrategyKeys[0];
|
|
3679
|
+
if (!nftStrategyKeys.includes(strategyFtType)) {
|
|
3680
|
+
throw new Error(`Specified FT type ${strategyFtType} is not supported for this collection`);
|
|
3681
|
+
}
|
|
3682
|
+
const transferPolicy = getNativeKioskTransferPolicies(chainState?.transfer_policies ?? [])?.at(0);
|
|
3683
|
+
if (!transferPolicy) {
|
|
3684
|
+
throw new Error("No transfer policy found for collection");
|
|
3685
|
+
}
|
|
3686
|
+
const nftType = chainState?.nft_type;
|
|
3687
|
+
let suiBalance = BigInt(
|
|
3688
|
+
nftStrategies[strategyFtType].sui_balance ?? 0n
|
|
3689
|
+
);
|
|
3690
|
+
const result = await gqlChainRequest({
|
|
3691
|
+
chain: "sui",
|
|
3692
|
+
query: fetchCollectionFloorListingsForMarket,
|
|
3693
|
+
variables: {
|
|
3694
|
+
collectionId,
|
|
3695
|
+
marketAddress: TRADEPORT_NFT_STRATEGY_MANAGER_ID,
|
|
3696
|
+
totalPrice: suiBalance.toString()
|
|
3697
|
+
}
|
|
3698
|
+
});
|
|
3699
|
+
if ((result?.listings?.length ?? 0) === 0) {
|
|
3700
|
+
throw new Error(
|
|
3701
|
+
`No floor listing found for collection with price bellow or equal to ${suiBalance} MIST`
|
|
3702
|
+
);
|
|
3703
|
+
}
|
|
3704
|
+
for (const floorListing of result.listings) {
|
|
3705
|
+
suiBalance -= BigInt(floorListing.price);
|
|
3706
|
+
if (suiBalance < 0n) {
|
|
3707
|
+
break;
|
|
3708
|
+
}
|
|
3709
|
+
tx.moveCall({
|
|
3710
|
+
target: `${TRADEPORT_NFT_STRATEGY_PACKAGE_ID}::tradeport_nft_strategy::apply_tradeport_nft_strategy_confirm_request`,
|
|
3711
|
+
typeArguments: [nftType, strategyFtType],
|
|
3712
|
+
arguments: [
|
|
3713
|
+
tx.object(TRADEPORT_NFT_STRATEGY_MANAGER_ID),
|
|
3714
|
+
tx.object(nftStrategies[strategyFtType].kiosk_id),
|
|
3715
|
+
tx.object(TRADEPORT_LISTINGS_STORE),
|
|
3716
|
+
tx.object(TRADEPORT_ORDERBOOK_STORE),
|
|
3717
|
+
tx.object(floorListing.nft.delegated_owner),
|
|
3718
|
+
tx.object(floorListing.nft.token_id),
|
|
3719
|
+
tx.object(transferPolicy.id)
|
|
3720
|
+
]
|
|
3721
|
+
});
|
|
3722
|
+
}
|
|
3723
|
+
return tx;
|
|
3724
|
+
}
|
|
3725
|
+
|
|
3663
3726
|
// src/methods/buyListings/buyListings.ts
|
|
3664
3727
|
var import_transactions7 = require("@mysten/sui/transactions");
|
|
3665
3728
|
|
|
3666
3729
|
// src/graphql/queries/fetchListingsById.ts
|
|
3667
|
-
var
|
|
3668
|
-
var fetchListingsById =
|
|
3730
|
+
var import_graphql_request14 = require("graphql-request");
|
|
3731
|
+
var fetchListingsById = import_graphql_request14.gql`
|
|
3669
3732
|
query fetchListingsById($listingIds: [uuid!]) {
|
|
3670
3733
|
listings(where: { id: { _in: $listingIds } }) {
|
|
3671
3734
|
id
|
|
@@ -3704,29 +3767,6 @@ var addThirdPartyTxFee = async (tx, price) => {
|
|
|
3704
3767
|
);
|
|
3705
3768
|
};
|
|
3706
3769
|
|
|
3707
|
-
// src/helpers/deserializeOrCreateTxBlock.ts
|
|
3708
|
-
var import_transactions5 = require("@mysten/sui/transactions");
|
|
3709
|
-
var deserializeOrCreateTxBlock = ({
|
|
3710
|
-
existingTx
|
|
3711
|
-
}) => {
|
|
3712
|
-
if (typeof existingTx === "string") {
|
|
3713
|
-
return import_transactions5.Transaction.from(existingTx);
|
|
3714
|
-
}
|
|
3715
|
-
return existingTx ?? new import_transactions5.Transaction();
|
|
3716
|
-
};
|
|
3717
|
-
|
|
3718
|
-
// src/helpers/extractSwapResultCoin.ts
|
|
3719
|
-
var extractSwapResultCoinFromTxBlock = (txBlock) => {
|
|
3720
|
-
if (!txBlock) return void 0;
|
|
3721
|
-
const tx = typeof txBlock === "string" ? JSON.parse(txBlock) : txBlock?.getData();
|
|
3722
|
-
const commands = tx.commands ?? [];
|
|
3723
|
-
const index = commands.findIndex(
|
|
3724
|
-
(cmd) => cmd?.MoveCall?.module === "universal_router" && cmd?.MoveCall?.function === "settle"
|
|
3725
|
-
);
|
|
3726
|
-
if (index === -1) return void 0;
|
|
3727
|
-
return { $kind: "Result", Result: index };
|
|
3728
|
-
};
|
|
3729
|
-
|
|
3730
3770
|
// src/helpers/kiosk/preProcessSharedBulkBuyingData.ts
|
|
3731
3771
|
var import_bcs2 = require("@mysten/sui/bcs");
|
|
3732
3772
|
var import_transactions6 = require("@mysten/sui/transactions");
|
|
@@ -3832,8 +3872,8 @@ var preProcessSharedBulkBuyingData = async ({
|
|
|
3832
3872
|
var import_bcs3 = require("@mysten/sui/bcs");
|
|
3833
3873
|
|
|
3834
3874
|
// src/graphql/queries/fetchCommissionByListingId.ts
|
|
3835
|
-
var
|
|
3836
|
-
var fetchCommissionByNftContractId =
|
|
3875
|
+
var import_graphql_request15 = require("graphql-request");
|
|
3876
|
+
var fetchCommissionByNftContractId = import_graphql_request15.gql`
|
|
3837
3877
|
query fetchCommissionByNftContractId($nftContractId: uuid!) {
|
|
3838
3878
|
commissions(where: { contract_id: { _eq: $nftContractId } }) {
|
|
3839
3879
|
is_custodial
|
|
@@ -4583,8 +4623,7 @@ var buyListings = async ({
|
|
|
4583
4623
|
throw new Error("No listings found");
|
|
4584
4624
|
}
|
|
4585
4625
|
const listingsForTracking = [];
|
|
4586
|
-
const tx =
|
|
4587
|
-
const swapResultCoin = extractSwapResultCoinFromTxBlock(tx);
|
|
4626
|
+
const tx = existingTx ?? new import_transactions7.Transaction();
|
|
4588
4627
|
const tocenTokenIds = [];
|
|
4589
4628
|
let tocenNftType = "";
|
|
4590
4629
|
let tocenTotalPrice = 0;
|
|
@@ -4629,7 +4668,7 @@ var buyListings = async ({
|
|
|
4629
4668
|
sellerKiosk: listing.nft?.chain_state?.kiosk_id,
|
|
4630
4669
|
collectionId: listing?.nft?.collection_id,
|
|
4631
4670
|
nftContractId: listing?.nft?.contract_id,
|
|
4632
|
-
coinToSplit
|
|
4671
|
+
coinToSplit,
|
|
4633
4672
|
marketFeeDecimalPercent,
|
|
4634
4673
|
beforeResolveKioskTransferRequest,
|
|
4635
4674
|
sharedKioskState,
|
|
@@ -4678,9 +4717,6 @@ var buyListings = async ({
|
|
|
4678
4717
|
});
|
|
4679
4718
|
}
|
|
4680
4719
|
sharedKioskState?.kioskTx?.finalize();
|
|
4681
|
-
if (swapResultCoin) {
|
|
4682
|
-
tx.transferObjects([swapResultCoin], walletAddress);
|
|
4683
|
-
}
|
|
4684
4720
|
if (tocenTokenIds?.length > 0) {
|
|
4685
4721
|
addTocenBuyTxHandler({
|
|
4686
4722
|
tx,
|
|
@@ -4689,7 +4725,7 @@ var buyListings = async ({
|
|
|
4689
4725
|
price: tocenTotalPrice
|
|
4690
4726
|
});
|
|
4691
4727
|
}
|
|
4692
|
-
return
|
|
4728
|
+
return tx;
|
|
4693
4729
|
};
|
|
4694
4730
|
|
|
4695
4731
|
// src/methods/cancelMultiBid/cancelMultiBid.ts
|
|
@@ -4813,8 +4849,8 @@ async function cancelMultiBid({ multiBidId }) {
|
|
|
4813
4849
|
var import_transactions9 = require("@mysten/sui/transactions");
|
|
4814
4850
|
|
|
4815
4851
|
// src/graphql/queries/fetchAccountKiosks.ts
|
|
4816
|
-
var
|
|
4817
|
-
var fetchAccountKiosks =
|
|
4852
|
+
var import_graphql_request16 = require("graphql-request");
|
|
4853
|
+
var fetchAccountKiosks = import_graphql_request16.gql`
|
|
4818
4854
|
query fetchAccountKiosks($accountAddress: String!) {
|
|
4819
4855
|
kiosks: kiosks_by_owner_address(owner_address: $accountAddress) {
|
|
4820
4856
|
id
|
|
@@ -5283,17 +5319,22 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
|
|
|
5283
5319
|
return import_transactions10.Transaction.from(tx);
|
|
5284
5320
|
};
|
|
5285
5321
|
|
|
5322
|
+
// src/methods/createMultiBid/createMultiBid.ts
|
|
5323
|
+
var import_transactions12 = require("@mysten/sui/transactions");
|
|
5324
|
+
|
|
5286
5325
|
// src/methods/updateMultiBid/updateMultiBid.ts
|
|
5326
|
+
var import_transactions11 = require("@mysten/sui/transactions");
|
|
5287
5327
|
async function updateMultiBid({
|
|
5328
|
+
walletAddress,
|
|
5288
5329
|
multiBidId,
|
|
5289
5330
|
name,
|
|
5290
5331
|
amount,
|
|
5291
5332
|
amountToWithdraw,
|
|
5292
5333
|
tx: existingTx,
|
|
5293
|
-
multiBidChainId
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
const
|
|
5334
|
+
multiBidChainId,
|
|
5335
|
+
coinToSplit
|
|
5336
|
+
}, context) {
|
|
5337
|
+
const tx = existingTx ?? new import_transactions11.Transaction();
|
|
5297
5338
|
if (!multiBidChainId) {
|
|
5298
5339
|
const { chain_id: chainId, cancelled_at } = (await gqlChainRequest({
|
|
5299
5340
|
chain: "sui",
|
|
@@ -5308,7 +5349,7 @@ async function updateMultiBid({
|
|
|
5308
5349
|
}
|
|
5309
5350
|
multiBidChainId = chainId;
|
|
5310
5351
|
}
|
|
5311
|
-
const [coin] = tx.splitCoins(
|
|
5352
|
+
const [coin] = tx.splitCoins(coinToSplit ? coinToSplit : tx.gas, [amount ?? 0n]);
|
|
5312
5353
|
tx.moveCall({
|
|
5313
5354
|
target: `${TRADEPORT_MULTI_BID_PACKAGE}::tradeport_biddings::update_multi_bid`,
|
|
5314
5355
|
arguments: [
|
|
@@ -5329,7 +5370,7 @@ async function createMultiBid({
|
|
|
5329
5370
|
amount,
|
|
5330
5371
|
tx: existingTx
|
|
5331
5372
|
}) {
|
|
5332
|
-
const tx =
|
|
5373
|
+
const tx = existingTx ?? new import_transactions12.Transaction();
|
|
5333
5374
|
const multiBidChainId = tx.moveCall({
|
|
5334
5375
|
target: `${TRADEPORT_MULTI_BID_PACKAGE}::tradeport_biddings::create_multi_bid`,
|
|
5335
5376
|
arguments: [tx.object(TRADEPORT_MULTI_BID_STORE), tx.pure.option("string", name)]
|
|
@@ -5347,7 +5388,11 @@ async function createMultiBid({
|
|
|
5347
5388
|
}
|
|
5348
5389
|
|
|
5349
5390
|
// src/methods/listNfts/listNfts.ts
|
|
5350
|
-
var
|
|
5391
|
+
var import_transactions14 = require("@mysten/sui/transactions");
|
|
5392
|
+
|
|
5393
|
+
// src/helpers/isExpiredListing.ts
|
|
5394
|
+
var import_utils7 = require("@mysten/sui/utils");
|
|
5395
|
+
var isExpiredListing = (listing, walletAddress) => listing.nonce && listing.seller && (0, import_utils7.normalizeSuiAddress)(listing.seller) === (0, import_utils7.normalizeSuiAddress)(walletAddress);
|
|
5351
5396
|
|
|
5352
5397
|
// src/helpers/validateMinFloorPrice.ts
|
|
5353
5398
|
function validateMinFloorPrice({ transferPolicies, listPrice }) {
|
|
@@ -5676,323 +5721,16 @@ async function relistNft({
|
|
|
5676
5721
|
}
|
|
5677
5722
|
}
|
|
5678
5723
|
|
|
5679
|
-
// src/methods/swapCoins/swapCoins.ts
|
|
5680
|
-
var import_sdk = require("@flowx-finance/sdk");
|
|
5681
|
-
var import_transactions11 = require("@mysten/sui/transactions");
|
|
5682
|
-
var import_utils7 = require("@mysten/sui/utils");
|
|
5683
|
-
var import_ms = __toESM(require("ms"));
|
|
5684
|
-
|
|
5685
|
-
// src/utils/pureValues.ts
|
|
5686
|
-
var toDecimalValue = (value, decimals) => {
|
|
5687
|
-
if (!value || decimals === void 0) return new bigNumberConfig_default(0);
|
|
5688
|
-
return new bigNumberConfig_default(value).div(10 ** decimals);
|
|
5689
|
-
};
|
|
5690
|
-
var toPureValue = (value, decimals) => {
|
|
5691
|
-
if (!value || decimals === void 0) return new bigNumberConfig_default(0);
|
|
5692
|
-
return new bigNumberConfig_default(new bigNumberConfig_default(value).multipliedBy(10 ** decimals).toFixed(0));
|
|
5693
|
-
};
|
|
5694
|
-
|
|
5695
|
-
// src/methods/swapCoins/swapCoins.ts
|
|
5696
|
-
async function swapCoins({
|
|
5697
|
-
walletAddress,
|
|
5698
|
-
coinInType,
|
|
5699
|
-
coinInAmount,
|
|
5700
|
-
coinOutType,
|
|
5701
|
-
slippage = 1e3,
|
|
5702
|
-
// 0.1%
|
|
5703
|
-
ttl = "5m",
|
|
5704
|
-
excludeSources = [import_sdk.Protocol.STEAMM, import_sdk.Protocol.BOLT],
|
|
5705
|
-
routes,
|
|
5706
|
-
commission,
|
|
5707
|
-
tx: existingTx
|
|
5708
|
-
}, { suiClient, defiRouterUrl }) {
|
|
5709
|
-
const inAmount = BigInt(coinInAmount);
|
|
5710
|
-
const tx = existingTx ?? new import_transactions11.Transaction();
|
|
5711
|
-
coinInType = (0, import_utils7.normalizeStructTag)(coinInType);
|
|
5712
|
-
coinOutType = (0, import_utils7.normalizeStructTag)(coinOutType);
|
|
5713
|
-
walletAddress = (0, import_utils7.normalizeSuiAddress)(walletAddress);
|
|
5714
|
-
tx.setSenderIfNotSet((0, import_utils7.normalizeSuiAddress)(walletAddress));
|
|
5715
|
-
if (inAmount === 0n) {
|
|
5716
|
-
const zeroCoin = tx.moveCall({
|
|
5717
|
-
target: "0x2::coin::zero",
|
|
5718
|
-
typeArguments: [coinOutType]
|
|
5719
|
-
});
|
|
5720
|
-
return {
|
|
5721
|
-
tx,
|
|
5722
|
-
coinOut: zeroCoin
|
|
5723
|
-
};
|
|
5724
|
-
}
|
|
5725
|
-
if (coinInType === coinOutType) {
|
|
5726
|
-
const getCoin = (0, import_transactions11.coinWithBalance)({
|
|
5727
|
-
type: coinInType,
|
|
5728
|
-
balance: inAmount
|
|
5729
|
-
});
|
|
5730
|
-
return {
|
|
5731
|
-
tx,
|
|
5732
|
-
coinOut: getCoin(tx)
|
|
5733
|
-
};
|
|
5734
|
-
}
|
|
5735
|
-
const types = await getAffectedNftAndFtTypes(coinInType, coinOutType);
|
|
5736
|
-
const { feeAndReward, amountToSwap } = calculateSwapAmounts(types.length, inAmount);
|
|
5737
|
-
if (!routes) {
|
|
5738
|
-
routes = (await buildSwapRoutes(
|
|
5739
|
-
{
|
|
5740
|
-
walletAddress,
|
|
5741
|
-
coinInType,
|
|
5742
|
-
coinOutType,
|
|
5743
|
-
amountToSwap,
|
|
5744
|
-
excludeSources,
|
|
5745
|
-
commission
|
|
5746
|
-
},
|
|
5747
|
-
{ defiRouterUrl }
|
|
5748
|
-
)).routes;
|
|
5749
|
-
}
|
|
5750
|
-
const tradeBuilder = new import_sdk.TradeBuilder("mainnet", routes);
|
|
5751
|
-
if (commission) {
|
|
5752
|
-
tradeBuilder.commission(commission);
|
|
5753
|
-
}
|
|
5754
|
-
const trade = tradeBuilder.sender(walletAddress).slippage(slippage).deadline(Date.now() + (0, import_ms.default)(ttl)).build();
|
|
5755
|
-
const coinOut = await trade.swap({ client: suiClient, tx });
|
|
5756
|
-
let suiFeeAndRewardCoin;
|
|
5757
|
-
if (coinInType === (0, import_utils7.normalizeStructTag)(import_utils7.SUI_TYPE_ARG)) {
|
|
5758
|
-
suiFeeAndRewardCoin = tx.splitCoins(tx.gas, [
|
|
5759
|
-
tx.pure.u64(feeAndReward)
|
|
5760
|
-
])[0];
|
|
5761
|
-
} else {
|
|
5762
|
-
const suiFeeAndRewardRoutes = await buildSwapRoutes(
|
|
5763
|
-
{
|
|
5764
|
-
walletAddress,
|
|
5765
|
-
coinInType,
|
|
5766
|
-
coinOutType: import_utils7.SUI_TYPE_ARG,
|
|
5767
|
-
amountToSwap: feeAndReward,
|
|
5768
|
-
excludeSources
|
|
5769
|
-
},
|
|
5770
|
-
{ defiRouterUrl }
|
|
5771
|
-
);
|
|
5772
|
-
const suiFeeTradeBuilder = new import_sdk.TradeBuilder("mainnet", suiFeeAndRewardRoutes.routes);
|
|
5773
|
-
const suiFeeTrade = suiFeeTradeBuilder.sender(walletAddress).slippage(slippage).deadline(Date.now() + (0, import_ms.default)(ttl)).build();
|
|
5774
|
-
suiFeeAndRewardCoin = await suiFeeTrade.swap({ client: suiClient, tx });
|
|
5775
|
-
}
|
|
5776
|
-
if (types.length > 0) {
|
|
5777
|
-
if (types.length > 2) {
|
|
5778
|
-
throw new Error("Unexpected affected types count greater than 2");
|
|
5779
|
-
}
|
|
5780
|
-
let usedSuiCoin = suiFeeAndRewardCoin;
|
|
5781
|
-
if (types.length === 2) {
|
|
5782
|
-
const suiFeeAndRewardCoinBalance = tx.moveCall({
|
|
5783
|
-
target: "0x2::coin::value",
|
|
5784
|
-
typeArguments: [import_utils7.SUI_TYPE_ARG],
|
|
5785
|
-
arguments: [suiFeeAndRewardCoin]
|
|
5786
|
-
});
|
|
5787
|
-
const halfSuiCoinAmount = tx.moveCall({
|
|
5788
|
-
target: "0x2::math::divide_and_round_up",
|
|
5789
|
-
arguments: [suiFeeAndRewardCoinBalance, tx.pure.u64(2)]
|
|
5790
|
-
});
|
|
5791
|
-
const [coin] = tx.splitCoins(usedSuiCoin, [halfSuiCoinAmount]);
|
|
5792
|
-
usedSuiCoin = coin;
|
|
5793
|
-
}
|
|
5794
|
-
for (const data of types) {
|
|
5795
|
-
const { nftType, ftType, type } = data;
|
|
5796
|
-
switch (type) {
|
|
5797
|
-
case "liquidNft": {
|
|
5798
|
-
tx.moveCall({
|
|
5799
|
-
target: `${DexConstants.commission}::commission::pay`,
|
|
5800
|
-
arguments: [
|
|
5801
|
-
tx.object(DexConstants.commissionManager),
|
|
5802
|
-
tx.pure.string("swap"),
|
|
5803
|
-
usedSuiCoin,
|
|
5804
|
-
tx.pure.option("string", nftType)
|
|
5805
|
-
],
|
|
5806
|
-
typeArguments: [import_utils7.SUI_TYPE_ARG]
|
|
5807
|
-
});
|
|
5808
|
-
break;
|
|
5809
|
-
}
|
|
5810
|
-
case "nftStrategy": {
|
|
5811
|
-
const suiFeeAndRewardCoinBalance = tx.moveCall({
|
|
5812
|
-
target: "0x2::coin::value",
|
|
5813
|
-
typeArguments: [import_utils7.SUI_TYPE_ARG],
|
|
5814
|
-
arguments: [usedSuiCoin]
|
|
5815
|
-
});
|
|
5816
|
-
const feeAmount = tx.moveCall({
|
|
5817
|
-
target: "0x2::math::divide_and_round_up",
|
|
5818
|
-
arguments: [suiFeeAndRewardCoinBalance, tx.pure.u64(4)]
|
|
5819
|
-
});
|
|
5820
|
-
const [feeCoin] = tx.splitCoins(usedSuiCoin, [feeAmount]);
|
|
5821
|
-
tx.moveCall({
|
|
5822
|
-
target: `${DexConstants.commission}::commission::pay`,
|
|
5823
|
-
arguments: [
|
|
5824
|
-
tx.object(DexConstants.commissionManager),
|
|
5825
|
-
tx.pure.string("swap"),
|
|
5826
|
-
feeCoin,
|
|
5827
|
-
tx.pure.option("string", void 0)
|
|
5828
|
-
],
|
|
5829
|
-
typeArguments: [import_utils7.SUI_TYPE_ARG]
|
|
5830
|
-
});
|
|
5831
|
-
tx.moveCall({
|
|
5832
|
-
target: `${TRADEPORT_NFT_STRATEGY_PACKAGE_ID}::tradeport_nft_strategy::reward_strategy`,
|
|
5833
|
-
arguments: [
|
|
5834
|
-
tx.object(TRADEPORT_NFT_STRATEGY_MANAGER_ID),
|
|
5835
|
-
usedSuiCoin
|
|
5836
|
-
// 3/4 retained coin for reward
|
|
5837
|
-
],
|
|
5838
|
-
typeArguments: [nftType, ftType]
|
|
5839
|
-
});
|
|
5840
|
-
break;
|
|
5841
|
-
}
|
|
5842
|
-
default: {
|
|
5843
|
-
throw new Error(`Unexpected type ${type}`);
|
|
5844
|
-
}
|
|
5845
|
-
}
|
|
5846
|
-
usedSuiCoin = suiFeeAndRewardCoin;
|
|
5847
|
-
}
|
|
5848
|
-
} else {
|
|
5849
|
-
tx.moveCall({
|
|
5850
|
-
target: `${DexConstants.commission}::commission::pay`,
|
|
5851
|
-
arguments: [
|
|
5852
|
-
tx.object(DexConstants.commissionManager),
|
|
5853
|
-
tx.pure.string("swap"),
|
|
5854
|
-
suiFeeAndRewardCoin,
|
|
5855
|
-
tx.pure.option("string", void 0)
|
|
5856
|
-
],
|
|
5857
|
-
typeArguments: [import_utils7.SUI_TYPE_ARG]
|
|
5858
|
-
});
|
|
5859
|
-
}
|
|
5860
|
-
return {
|
|
5861
|
-
tx,
|
|
5862
|
-
coinOut
|
|
5863
|
-
};
|
|
5864
|
-
}
|
|
5865
|
-
async function calculateAmountToSwap({
|
|
5866
|
-
coinInType,
|
|
5867
|
-
coinOutType,
|
|
5868
|
-
coinInAmount
|
|
5869
|
-
}) {
|
|
5870
|
-
const types = await getAffectedNftAndFtTypes(coinInType, coinOutType);
|
|
5871
|
-
const { amountToSwap } = calculateSwapAmounts(types.length, BigInt(coinInAmount));
|
|
5872
|
-
return amountToSwap;
|
|
5873
|
-
}
|
|
5874
|
-
async function calculateSwapInputAmountWithSlippage({
|
|
5875
|
-
coinInType,
|
|
5876
|
-
coinOutType,
|
|
5877
|
-
coinOutAmount,
|
|
5878
|
-
slippage = 0
|
|
5879
|
-
}) {
|
|
5880
|
-
if (coinInType === coinOutType) {
|
|
5881
|
-
return new bigNumberConfig_default(coinOutAmount);
|
|
5882
|
-
}
|
|
5883
|
-
const provider = new import_sdk.CoinProvider("mainnet");
|
|
5884
|
-
const coinQueryResult = await provider.getCoins({
|
|
5885
|
-
limit: 2,
|
|
5886
|
-
coinTypes: [coinInType, coinOutType]
|
|
5887
|
-
});
|
|
5888
|
-
const coinIn = coinQueryResult?.find(
|
|
5889
|
-
(coin) => (0, import_utils7.normalizeStructTag)(coin.coinType) === (0, import_utils7.normalizeStructTag)(coinInType)
|
|
5890
|
-
);
|
|
5891
|
-
const coinOut = coinQueryResult?.find(
|
|
5892
|
-
(coin) => (0, import_utils7.normalizeStructTag)(coin.coinType) === (0, import_utils7.normalizeStructTag)(coinOutType)
|
|
5893
|
-
);
|
|
5894
|
-
const exchangeRate = new bigNumberConfig_default(coinOut.derivedPriceInUSD ?? 0)?.gt(0) ? new bigNumberConfig_default(coinIn?.derivedPriceInUSD ?? 1)?.div(coinOut?.derivedPriceInUSD ?? 1) : new bigNumberConfig_default(0);
|
|
5895
|
-
const amountSell = toDecimalValue(coinOutAmount.toString(), coinOut?.decimals).div(exchangeRate);
|
|
5896
|
-
const slippageMultiplier = 1 + parseInt(slippage.toString() || "0", 10) / 1e6;
|
|
5897
|
-
const amountWithSlippage = amountSell.times(slippageMultiplier);
|
|
5898
|
-
const coinInAmount = toPureValue(amountWithSlippage, coinIn?.decimals);
|
|
5899
|
-
return coinInAmount;
|
|
5900
|
-
}
|
|
5901
|
-
async function buildSwapRoutes(options, { defiRouterUrl }) {
|
|
5902
|
-
const aggregatorQuoter = new import_sdk.AggregatorQuoter("mainnet");
|
|
5903
|
-
const routes = await aggregatorQuoter.getRoutes({
|
|
5904
|
-
tokenIn: options.coinInType,
|
|
5905
|
-
tokenOut: options.coinOutType,
|
|
5906
|
-
amountIn: options.amountToSwap.toString(),
|
|
5907
|
-
commission: options.commission,
|
|
5908
|
-
excludeSources: options.excludeSources
|
|
5909
|
-
});
|
|
5910
|
-
if (defiRouterUrl && options.walletAddress) {
|
|
5911
|
-
await makeDefiRouterRequest(`${defiRouterUrl}/start`, {
|
|
5912
|
-
walletId: options.walletAddress,
|
|
5913
|
-
coinTypeIn: options.coinInType,
|
|
5914
|
-
coinTypeOut: options.coinOutType,
|
|
5915
|
-
amountIn: options.amountToSwap.toString()
|
|
5916
|
-
});
|
|
5917
|
-
}
|
|
5918
|
-
return routes;
|
|
5919
|
-
}
|
|
5920
|
-
function calculateSwapAmounts(affectedTypesCount, inAmount) {
|
|
5921
|
-
const feeAndReward = affectedTypesCount > 0 ? BigInt(affectedTypesCount) * inAmount / 25n : inAmount / 100n;
|
|
5922
|
-
const amountToSwap = inAmount - feeAndReward;
|
|
5923
|
-
if (amountToSwap <= 0n) {
|
|
5924
|
-
throw new Error("Amount to swap is too small");
|
|
5925
|
-
}
|
|
5926
|
-
return { feeAndReward, amountToSwap };
|
|
5927
|
-
}
|
|
5928
|
-
async function getAffectedNftAndFtTypes(coinInType, coinOutType) {
|
|
5929
|
-
const normalizedSuiType = (0, import_utils7.normalizeStructTag)(import_utils7.SUI_TYPE_ARG);
|
|
5930
|
-
const coinTypes = [coinInType, coinOutType].filter((type) => type !== normalizedSuiType);
|
|
5931
|
-
const types = await Promise.all(
|
|
5932
|
-
coinTypes.map(async (type) => {
|
|
5933
|
-
const chainState = await getCollectionChainStateByFtType(type);
|
|
5934
|
-
return chainState ? {
|
|
5935
|
-
nftType: chainState.nft_type,
|
|
5936
|
-
ftType: type,
|
|
5937
|
-
type: chainState.ft_type ? "liquidNft" : "nftStrategy"
|
|
5938
|
-
} : void 0;
|
|
5939
|
-
})
|
|
5940
|
-
);
|
|
5941
|
-
return types.filter(Boolean);
|
|
5942
|
-
}
|
|
5943
|
-
async function makeDefiRouterRequest(url, body, defaultResponse = void 0) {
|
|
5944
|
-
try {
|
|
5945
|
-
const response = await fetch(url, {
|
|
5946
|
-
method: "POST",
|
|
5947
|
-
headers: { "Content-Type": "application/json" },
|
|
5948
|
-
body: JSON.stringify(body)
|
|
5949
|
-
});
|
|
5950
|
-
if (!response.ok) {
|
|
5951
|
-
console.warn(`DeFi router request failed with status ${response.status}`);
|
|
5952
|
-
return defaultResponse;
|
|
5953
|
-
}
|
|
5954
|
-
if (response.headers.get("Content-Type")?.includes("application/json")) {
|
|
5955
|
-
return await response.json();
|
|
5956
|
-
}
|
|
5957
|
-
return defaultResponse;
|
|
5958
|
-
} catch (error) {
|
|
5959
|
-
console.warn(`DeFi router request error: ${error.message}`);
|
|
5960
|
-
return defaultResponse;
|
|
5961
|
-
}
|
|
5962
|
-
}
|
|
5963
|
-
|
|
5964
5724
|
// src/methods/sponsorNftListing/addSponsorNftListingTx.ts
|
|
5725
|
+
var import_transactions13 = require("@mysten/sui/transactions");
|
|
5965
5726
|
var addSponsorListingTx = async ({
|
|
5966
5727
|
tx,
|
|
5967
5728
|
nftTokenId,
|
|
5968
5729
|
nftType,
|
|
5969
|
-
|
|
5970
|
-
walletAddress,
|
|
5971
|
-
sponsorOptions,
|
|
5972
|
-
defiRouterUrl
|
|
5730
|
+
sponsorOptions
|
|
5973
5731
|
}) => {
|
|
5974
|
-
const
|
|
5975
|
-
|
|
5976
|
-
coinOutType: USDC_COIN_TYPE,
|
|
5977
|
-
coinOutAmount: new bigNumberConfig_default(sponsorOptions?.usdcFeeAmountPerPeriod)?.times(sponsorOptions?.numOfPeriods).toString(),
|
|
5978
|
-
slippage: sponsorOptions?.slippage
|
|
5979
|
-
});
|
|
5980
|
-
const { coinOut } = await swapCoins(
|
|
5981
|
-
{
|
|
5982
|
-
walletAddress,
|
|
5983
|
-
coinInType: sponsorOptions?.coinInType,
|
|
5984
|
-
coinInAmount: coinInAmount.toString(),
|
|
5985
|
-
coinOutType: USDC_COIN_TYPE,
|
|
5986
|
-
slippage: sponsorOptions?.slippage,
|
|
5987
|
-
tx
|
|
5988
|
-
},
|
|
5989
|
-
{ suiClient, defiRouterUrl }
|
|
5990
|
-
);
|
|
5991
|
-
const [sponsorFeeCoin] = tx.splitCoins(coinOut, [
|
|
5992
|
-
tx.pure.u64(
|
|
5993
|
-
new bigNumberConfig_default(sponsorOptions?.usdcFeeAmountPerPeriod)?.times(sponsorOptions?.numOfPeriods).toString()
|
|
5994
|
-
)
|
|
5995
|
-
]);
|
|
5732
|
+
const totalFee = new bigNumberConfig_default(sponsorOptions?.usdcFeeAmountPerPeriod)?.times(sponsorOptions?.numOfPeriods).toString();
|
|
5733
|
+
const sponsorCoin = sponsorOptions.coinToSplit ? tx.splitCoins(sponsorOptions.coinToSplit, [tx.pure.u64(totalFee)])[0] : (0, import_transactions13.coinWithBalance)({ type: USDC_COIN_TYPE, balance: BigInt(totalFee) });
|
|
5996
5734
|
tx.moveCall({
|
|
5997
5735
|
target: `${TRADEPORT_LISTINGS_PACKAGE}::tradeport_listings::add_sponsored_listing`,
|
|
5998
5736
|
arguments: [
|
|
@@ -6000,19 +5738,14 @@ var addSponsorListingTx = async ({
|
|
|
6000
5738
|
tx.object.clock(),
|
|
6001
5739
|
tx.pure.id(nftTokenId),
|
|
6002
5740
|
tx.pure.u64(sponsorOptions?.numOfPeriods),
|
|
6003
|
-
tx.object(
|
|
5741
|
+
tx.object(sponsorCoin)
|
|
6004
5742
|
],
|
|
6005
5743
|
typeArguments: [nftType]
|
|
6006
5744
|
});
|
|
6007
|
-
tx.transferObjects([coinOut], walletAddress);
|
|
6008
5745
|
};
|
|
6009
5746
|
|
|
6010
|
-
// src/helpers/isExpiredListing.ts
|
|
6011
|
-
var import_utils8 = require("@mysten/sui/utils");
|
|
6012
|
-
var isExpiredListing = (listing, walletAddress) => listing.nonce && listing.seller && (0, import_utils8.normalizeSuiAddress)(listing.seller) === (0, import_utils8.normalizeSuiAddress)(walletAddress);
|
|
6013
|
-
|
|
6014
5747
|
// src/methods/listNfts/listNfts.ts
|
|
6015
|
-
var listNfts = async ({ nfts, walletAddress }, context) => {
|
|
5748
|
+
var listNfts = async ({ nfts, walletAddress, tx: existingTx }, context) => {
|
|
6016
5749
|
const res = await gqlChainRequest({
|
|
6017
5750
|
chain: "sui",
|
|
6018
5751
|
query: fetchNftsWithListingsById,
|
|
@@ -6022,7 +5755,7 @@ var listNfts = async ({ nfts, walletAddress }, context) => {
|
|
|
6022
5755
|
throw new Error("No nfts found");
|
|
6023
5756
|
}
|
|
6024
5757
|
const nftsForTracking = [];
|
|
6025
|
-
const tx = new
|
|
5758
|
+
const tx = existingTx ?? new import_transactions14.Transaction();
|
|
6026
5759
|
const sharedKioskState = {
|
|
6027
5760
|
kioskTx: void 0
|
|
6028
5761
|
};
|
|
@@ -6072,12 +5805,9 @@ var listNfts = async ({ nfts, walletAddress }, context) => {
|
|
|
6072
5805
|
if (inputNft?.sponsorOptions?.shouldSponsor) {
|
|
6073
5806
|
await addSponsorListingTx({
|
|
6074
5807
|
tx,
|
|
6075
|
-
suiClient: context.suiClient,
|
|
6076
5808
|
nftTokenId: nft?.token_id,
|
|
6077
5809
|
nftType,
|
|
6078
|
-
|
|
6079
|
-
sponsorOptions: inputNft?.sponsorOptions,
|
|
6080
|
-
defiRouterUrl: context.defiRouterUrl
|
|
5810
|
+
sponsorOptions: inputNft?.sponsorOptions
|
|
6081
5811
|
});
|
|
6082
5812
|
}
|
|
6083
5813
|
nftsForTracking.push({
|
|
@@ -6090,15 +5820,15 @@ var listNfts = async ({ nfts, walletAddress }, context) => {
|
|
|
6090
5820
|
});
|
|
6091
5821
|
}
|
|
6092
5822
|
sharedKioskState?.kioskTx?.finalize();
|
|
6093
|
-
return tx
|
|
5823
|
+
return tx;
|
|
6094
5824
|
};
|
|
6095
5825
|
|
|
6096
5826
|
// src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts
|
|
6097
|
-
var
|
|
5827
|
+
var import_transactions15 = require("@mysten/sui/transactions");
|
|
6098
5828
|
|
|
6099
5829
|
// src/graphql/queries/fetchNftsByKioskId.ts
|
|
6100
|
-
var
|
|
6101
|
-
var fetchNftsByKioskId =
|
|
5830
|
+
var import_graphql_request17 = require("graphql-request");
|
|
5831
|
+
var fetchNftsByKioskId = import_graphql_request17.gql`
|
|
6102
5832
|
query fetchNftsByKioskId($jsonFilter: jsonb) {
|
|
6103
5833
|
nfts(where: { chain_state: { _contains: $jsonFilter } }) {
|
|
6104
5834
|
id
|
|
@@ -6119,7 +5849,7 @@ var fetchNftsByKioskId = import_graphql_request16.gql`
|
|
|
6119
5849
|
}
|
|
6120
5850
|
}
|
|
6121
5851
|
`;
|
|
6122
|
-
var fetchBulkNftsByKioskId =
|
|
5852
|
+
var fetchBulkNftsByKioskId = import_graphql_request17.gql`
|
|
6123
5853
|
query fetchNftsByKioskId($where: nfts_bool_exp) {
|
|
6124
5854
|
nfts(where: $where) {
|
|
6125
5855
|
id
|
|
@@ -6142,8 +5872,8 @@ var fetchBulkNftsByKioskId = import_graphql_request16.gql`
|
|
|
6142
5872
|
`;
|
|
6143
5873
|
|
|
6144
5874
|
// src/graphql/queries/fetchTransferPoliciesByType.ts
|
|
6145
|
-
var
|
|
6146
|
-
var fetchTransferPoliciesByType =
|
|
5875
|
+
var import_graphql_request18 = require("graphql-request");
|
|
5876
|
+
var fetchTransferPoliciesByType = import_graphql_request18.gql`
|
|
6147
5877
|
query fetchTransferPoliciesByType($type: String!) {
|
|
6148
5878
|
transfer_policies_by_type(type: $type) {
|
|
6149
5879
|
id
|
|
@@ -6302,7 +6032,7 @@ async function getTransferPolicyForDirectTransfer(suiClient, collectionChainStat
|
|
|
6302
6032
|
|
|
6303
6033
|
// src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts
|
|
6304
6034
|
async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 50 }, context) {
|
|
6305
|
-
const tx = new
|
|
6035
|
+
const tx = new import_transactions15.Transaction();
|
|
6306
6036
|
const res = await gqlChainRequest({
|
|
6307
6037
|
chain: "sui",
|
|
6308
6038
|
query: fetchKiosksByOwner,
|
|
@@ -6468,15 +6198,15 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 50 }
|
|
|
6468
6198
|
}
|
|
6469
6199
|
}
|
|
6470
6200
|
sharedKioskState?.kioskTx?.finalize();
|
|
6471
|
-
return
|
|
6201
|
+
return import_transactions15.Transaction.from(tx);
|
|
6472
6202
|
}
|
|
6473
6203
|
|
|
6474
6204
|
// src/methods/placeCollectionBids/placeCollectionBids.ts
|
|
6475
|
-
var
|
|
6205
|
+
var import_transactions16 = require("@mysten/sui/transactions");
|
|
6476
6206
|
|
|
6477
6207
|
// src/graphql/queries/fetchCollectionsById.ts
|
|
6478
|
-
var
|
|
6479
|
-
var fetchCollectionsById =
|
|
6208
|
+
var import_graphql_request19 = require("graphql-request");
|
|
6209
|
+
var fetchCollectionsById = import_graphql_request19.gql`
|
|
6480
6210
|
query fetchCollectionsById($collectionIds: [uuid!]) {
|
|
6481
6211
|
collections(where: { id: { _in: $collectionIds } }) {
|
|
6482
6212
|
id
|
|
@@ -6486,7 +6216,7 @@ var fetchCollectionsById = import_graphql_request18.gql`
|
|
|
6486
6216
|
}
|
|
6487
6217
|
}
|
|
6488
6218
|
`;
|
|
6489
|
-
var fetchCollectionsByIdWithOneNft =
|
|
6219
|
+
var fetchCollectionsByIdWithOneNft = import_graphql_request19.gql`
|
|
6490
6220
|
query fetchCollectionsByIdWithOneNft($collectionIds: [uuid!]) {
|
|
6491
6221
|
collections(where: { id: { _in: $collectionIds } }) {
|
|
6492
6222
|
id
|
|
@@ -6504,7 +6234,7 @@ var fetchCollectionsByIdWithOneNft = import_graphql_request18.gql`
|
|
|
6504
6234
|
}
|
|
6505
6235
|
}
|
|
6506
6236
|
`;
|
|
6507
|
-
var fetchCollectionsBySlug =
|
|
6237
|
+
var fetchCollectionsBySlug = import_graphql_request19.gql`
|
|
6508
6238
|
query fetchCollectionsBySlug($slug: String!) {
|
|
6509
6239
|
collections(where: { slug: { _eq: $slug } }) {
|
|
6510
6240
|
id
|
|
@@ -6513,7 +6243,7 @@ var fetchCollectionsBySlug = import_graphql_request18.gql`
|
|
|
6513
6243
|
`;
|
|
6514
6244
|
|
|
6515
6245
|
// src/methods/placeNftBids/addPlaceNftBidTxs.ts
|
|
6516
|
-
var
|
|
6246
|
+
var import_utils8 = require("@mysten/sui/utils");
|
|
6517
6247
|
async function addTradePortPlaceNftBidTxHandler(txData) {
|
|
6518
6248
|
if (isOriginByteCollection(txData?.transferPolicies) && !ORIGIN_BYTE_NFT_TYPES_MISSING_ORDERBOOK?.includes(normalizedNftType(txData?.nftType))) {
|
|
6519
6249
|
throw new Error("OriginByte bidding not supported currently");
|
|
@@ -6534,7 +6264,7 @@ async function addTradePortPlaceNftBidTxHandler(txData) {
|
|
|
6534
6264
|
if (!bcsHex) {
|
|
6535
6265
|
throw new Error(`No BCS found for token ${nftTokenId}`);
|
|
6536
6266
|
}
|
|
6537
|
-
bcs4 = (0,
|
|
6267
|
+
bcs4 = (0, import_utils8.fromHex)(bcsHex);
|
|
6538
6268
|
}
|
|
6539
6269
|
let multiBidChainId;
|
|
6540
6270
|
let expiredBids;
|
|
@@ -6590,12 +6320,12 @@ async function addTradePortPlaceNftBidTxHandler(txData) {
|
|
|
6590
6320
|
arguments: [
|
|
6591
6321
|
tx.object(TRADEPORT_MULTI_BID_STORE),
|
|
6592
6322
|
tx.pure.u64(nftTokenId ? 1 : 0),
|
|
6593
|
-
multiBidChainId ? typeof multiBidChainId === "string" ? tx.pure.option("id", (0,
|
|
6323
|
+
multiBidChainId ? typeof multiBidChainId === "string" ? tx.pure.option("id", (0, import_utils8.normalizeSuiObjectId)(multiBidChainId)) : tx.moveCall({
|
|
6594
6324
|
target: "0x1::option::some",
|
|
6595
6325
|
typeArguments: ["0x2::object::ID"],
|
|
6596
6326
|
arguments: [multiBidChainId]
|
|
6597
6327
|
}) : void 0,
|
|
6598
|
-
tx.pure.option("id", nftTokenId ? (0,
|
|
6328
|
+
tx.pure.option("id", nftTokenId ? (0, import_utils8.normalizeSuiObjectId)(nftTokenId) : void 0),
|
|
6599
6329
|
tx.pure.option("vector<u8>", bcs4 ? [...bcs4] : void 0),
|
|
6600
6330
|
tx.pure.option("u64", expireAt?.getTime()),
|
|
6601
6331
|
tx.pure.u64(price),
|
|
@@ -6626,8 +6356,8 @@ function isDynamicCollection(collectionId) {
|
|
|
6626
6356
|
}
|
|
6627
6357
|
|
|
6628
6358
|
// src/graphql/queries/fetchCollectionFloorListings.ts
|
|
6629
|
-
var
|
|
6630
|
-
var fetchCollectionFloorListings =
|
|
6359
|
+
var import_graphql_request20 = require("graphql-request");
|
|
6360
|
+
var fetchCollectionFloorListings = import_graphql_request20.gql`
|
|
6631
6361
|
query fetchCollectionFloorListings($collectionId: uuid!) {
|
|
6632
6362
|
listings(
|
|
6633
6363
|
where: { collection_id: { _eq: $collectionId }, listed: { _eq: true }, nft: {} }
|
|
@@ -6686,7 +6416,14 @@ async function addOriginByteCollectionBidTx({
|
|
|
6686
6416
|
}
|
|
6687
6417
|
|
|
6688
6418
|
// src/methods/placeCollectionBids/placeCollectionBids.ts
|
|
6689
|
-
var placeCollectionBids = async ({
|
|
6419
|
+
var placeCollectionBids = async ({
|
|
6420
|
+
collections,
|
|
6421
|
+
walletAddress,
|
|
6422
|
+
multiBidId,
|
|
6423
|
+
multiBidChainId,
|
|
6424
|
+
tx: existingTx,
|
|
6425
|
+
coinToSplit
|
|
6426
|
+
}, context) => {
|
|
6690
6427
|
const res = await gqlChainRequest({
|
|
6691
6428
|
chain: "sui",
|
|
6692
6429
|
query: fetchCollectionsByIdWithOneNft,
|
|
@@ -6696,8 +6433,7 @@ var placeCollectionBids = async ({ collections, walletAddress, multiBidId, multi
|
|
|
6696
6433
|
throw new Error("No collection found");
|
|
6697
6434
|
}
|
|
6698
6435
|
const collectionsForTracking = [];
|
|
6699
|
-
const tx =
|
|
6700
|
-
const swapResultCoin = extractSwapResultCoinFromTxBlock(tx);
|
|
6436
|
+
const tx = existingTx ?? new import_transactions16.Transaction();
|
|
6701
6437
|
for (const collection of res.collections) {
|
|
6702
6438
|
const nftType = getNftType({
|
|
6703
6439
|
collectionId: collection?.id,
|
|
@@ -6717,7 +6453,7 @@ var placeCollectionBids = async ({ collections, walletAddress, multiBidId, multi
|
|
|
6717
6453
|
multiBidId,
|
|
6718
6454
|
multiBidChainId,
|
|
6719
6455
|
expireAt: collections?.find((c) => c.id === collection?.id)?.expireAt,
|
|
6720
|
-
coinToSplit
|
|
6456
|
+
coinToSplit
|
|
6721
6457
|
};
|
|
6722
6458
|
const numOfBids = collections?.find((c) => c.id === collection?.id)?.numOfBids;
|
|
6723
6459
|
if (isOriginByteCollection(txData?.transferPolicies) && !ORIGIN_BYTE_NFT_TYPES_MISSING_ORDERBOOK?.includes(normalizedNftType(txData?.nftType))) {
|
|
@@ -6744,17 +6480,13 @@ var placeCollectionBids = async ({ collections, walletAddress, multiBidId, multi
|
|
|
6744
6480
|
bidder: walletAddress
|
|
6745
6481
|
});
|
|
6746
6482
|
}
|
|
6747
|
-
|
|
6748
|
-
tx.transferObjects([swapResultCoin], walletAddress);
|
|
6749
|
-
}
|
|
6750
|
-
return import_transactions14.Transaction.from(tx);
|
|
6483
|
+
return tx;
|
|
6751
6484
|
};
|
|
6752
6485
|
|
|
6753
6486
|
// src/methods/placeNftBids/placeNftBids.ts
|
|
6754
|
-
var
|
|
6755
|
-
var placeNftBids = async ({ bids, walletAddress, multiBidId, multiBidChainId, tx: existingTx }, context) => {
|
|
6756
|
-
const tx =
|
|
6757
|
-
const swapResultCoin = extractSwapResultCoinFromTxBlock(tx);
|
|
6487
|
+
var import_transactions17 = require("@mysten/sui/transactions");
|
|
6488
|
+
var placeNftBids = async ({ bids, walletAddress, multiBidId, multiBidChainId, tx: existingTx, coinToSplit }, context) => {
|
|
6489
|
+
const tx = existingTx ?? new import_transactions17.Transaction();
|
|
6758
6490
|
const res = await gqlChainRequest({
|
|
6759
6491
|
chain: "sui",
|
|
6760
6492
|
query: fetchNftsById,
|
|
@@ -6788,7 +6520,7 @@ var placeNftBids = async ({ bids, walletAddress, multiBidId, multiBidChainId, tx
|
|
|
6788
6520
|
multiBidId,
|
|
6789
6521
|
multiBidChainId,
|
|
6790
6522
|
expireAt: bid?.expireAt,
|
|
6791
|
-
coinToSplit
|
|
6523
|
+
coinToSplit
|
|
6792
6524
|
};
|
|
6793
6525
|
await addTradePortPlaceNftBidTxHandler(txData);
|
|
6794
6526
|
nftsForTracking.push({
|
|
@@ -6798,17 +6530,14 @@ var placeNftBids = async ({ bids, walletAddress, multiBidId, multiBidChainId, tx
|
|
|
6798
6530
|
bidder: walletAddress
|
|
6799
6531
|
});
|
|
6800
6532
|
}
|
|
6801
|
-
|
|
6802
|
-
tx.transferObjects([swapResultCoin], walletAddress);
|
|
6803
|
-
}
|
|
6804
|
-
return import_transactions15.Transaction.from(tx);
|
|
6533
|
+
return tx;
|
|
6805
6534
|
};
|
|
6806
6535
|
|
|
6807
6536
|
// src/methods/removeCollectionBids/removeCollectionBids.ts
|
|
6808
|
-
var
|
|
6537
|
+
var import_transactions18 = require("@mysten/sui/transactions");
|
|
6809
6538
|
|
|
6810
6539
|
// src/methods/removeCollectionBids/addRemoveCollectionBidsTxs.ts
|
|
6811
|
-
var
|
|
6540
|
+
var import_utils9 = require("@mysten/sui/utils");
|
|
6812
6541
|
function addTradeportRemoveCollectionBidTx({
|
|
6813
6542
|
tx,
|
|
6814
6543
|
nftType,
|
|
@@ -6864,7 +6593,7 @@ function addBluemoveKioskRemoveCollectionBidTx({
|
|
|
6864
6593
|
async function addTradePortRemoveCollectionBidTxHandler(txData) {
|
|
6865
6594
|
const bidType = await getObjectType({
|
|
6866
6595
|
suiClient: txData?.suiClient,
|
|
6867
|
-
objectId: (0,
|
|
6596
|
+
objectId: (0, import_utils9.normalizeSuiObjectId)(txData?.bidNonce)
|
|
6868
6597
|
});
|
|
6869
6598
|
if (isSingleBid(bidType)) {
|
|
6870
6599
|
await addSingleBidRemoveNftBidTx(txData);
|
|
@@ -6884,7 +6613,7 @@ async function addTradePortRemoveCollectionBidTxHandler(txData) {
|
|
|
6884
6613
|
async function addBluemoveRemoveCollectionBidTxHandler(txData) {
|
|
6885
6614
|
const bidType = await getObjectType({
|
|
6886
6615
|
suiClient: txData?.suiClient,
|
|
6887
|
-
objectId: (0,
|
|
6616
|
+
objectId: (0, import_utils9.normalizeSuiObjectId)(txData?.bidNonce)
|
|
6888
6617
|
});
|
|
6889
6618
|
if (isOriginByteBid(bidType)) {
|
|
6890
6619
|
const sharedObjects = await getSharedObjects(txData?.nftType);
|
|
@@ -6913,7 +6642,7 @@ var removeCollectionBids = async ({ bidIds, tx: existingTx }, context) => {
|
|
|
6913
6642
|
throw new Error("No bids found");
|
|
6914
6643
|
}
|
|
6915
6644
|
const bidsForTracking = [];
|
|
6916
|
-
const tx = existingTx ?
|
|
6645
|
+
const tx = existingTx ? import_transactions18.Transaction.from(existingTx) : new import_transactions18.Transaction();
|
|
6917
6646
|
for (const bid of res.bids) {
|
|
6918
6647
|
if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(bid?.nft?.token_id)) {
|
|
6919
6648
|
throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
|
|
@@ -6961,11 +6690,11 @@ var removeCollectionBids = async ({ bidIds, tx: existingTx }, context) => {
|
|
|
6961
6690
|
bidder: bid?.bidder
|
|
6962
6691
|
});
|
|
6963
6692
|
}
|
|
6964
|
-
return
|
|
6693
|
+
return import_transactions18.Transaction.from(tx);
|
|
6965
6694
|
};
|
|
6966
6695
|
|
|
6967
6696
|
// src/methods/removeNftBids/removeNftBids.ts
|
|
6968
|
-
var
|
|
6697
|
+
var import_transactions19 = require("@mysten/sui/transactions");
|
|
6969
6698
|
var removeNftBids = async ({ bidIds, tx: existingTx }, context) => {
|
|
6970
6699
|
const res = await gqlChainRequest({
|
|
6971
6700
|
chain: "sui",
|
|
@@ -6976,7 +6705,7 @@ var removeNftBids = async ({ bidIds, tx: existingTx }, context) => {
|
|
|
6976
6705
|
throw new Error("No bids found");
|
|
6977
6706
|
}
|
|
6978
6707
|
const bidsForTracking = [];
|
|
6979
|
-
const tx = existingTx ?
|
|
6708
|
+
const tx = existingTx ? import_transactions19.Transaction.from(existingTx) : new import_transactions19.Transaction();
|
|
6980
6709
|
for (const bid of res.bids) {
|
|
6981
6710
|
if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(bid?.nft?.token_id)) {
|
|
6982
6711
|
throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
|
|
@@ -7021,11 +6750,61 @@ var removeNftBids = async ({ bidIds, tx: existingTx }, context) => {
|
|
|
7021
6750
|
bidder: bid?.bidder
|
|
7022
6751
|
});
|
|
7023
6752
|
}
|
|
7024
|
-
return
|
|
6753
|
+
return import_transactions19.Transaction.from(tx);
|
|
6754
|
+
};
|
|
6755
|
+
|
|
6756
|
+
// src/methods/sponsorNftListing/sponsorNftListing.ts
|
|
6757
|
+
var import_transactions20 = require("@mysten/sui/transactions");
|
|
6758
|
+
|
|
6759
|
+
// src/graphql/queries/fetchNftCollectionChainState.ts
|
|
6760
|
+
var import_graphql_request21 = require("graphql-request");
|
|
6761
|
+
var fetchNftCollectionChainState = import_graphql_request21.gql`
|
|
6762
|
+
query fetchNftCollectionChainState($nftTokenId: String!) {
|
|
6763
|
+
nfts(where: { token_id: { _eq: $nftTokenId } }) {
|
|
6764
|
+
collection {
|
|
6765
|
+
id
|
|
6766
|
+
chain_state
|
|
6767
|
+
}
|
|
6768
|
+
}
|
|
6769
|
+
}
|
|
6770
|
+
`;
|
|
6771
|
+
|
|
6772
|
+
// src/methods/sponsorNftListing/sponsorNftListing.ts
|
|
6773
|
+
var sponsorNftListing = async ({
|
|
6774
|
+
tx: existingTx,
|
|
6775
|
+
nftTokenId,
|
|
6776
|
+
options
|
|
6777
|
+
}) => {
|
|
6778
|
+
const res = await gqlChainRequest({
|
|
6779
|
+
chain: "sui",
|
|
6780
|
+
query: fetchNftCollectionChainState,
|
|
6781
|
+
variables: { nftTokenId }
|
|
6782
|
+
});
|
|
6783
|
+
if (res?.nfts?.length === 0) {
|
|
6784
|
+
throw new Error(`No nft found with token id ${nftTokenId}`);
|
|
6785
|
+
}
|
|
6786
|
+
const nft = res?.nfts?.[0];
|
|
6787
|
+
const nftType = getNftType({
|
|
6788
|
+
collectionId: nft?.collection?.id,
|
|
6789
|
+
collectionChainState: nft?.collection?.chain_state,
|
|
6790
|
+
nft
|
|
6791
|
+
});
|
|
6792
|
+
const transferPolicies = nft?.collection?.chain_state?.transfer_policies;
|
|
6793
|
+
if (isOriginByteCollection(transferPolicies)) {
|
|
6794
|
+
throw new Error(`You cannot sponsor an Origin Byte NFT. Nft Token Id: ${nftTokenId}`);
|
|
6795
|
+
}
|
|
6796
|
+
const tx = existingTx ?? new import_transactions20.Transaction();
|
|
6797
|
+
await addSponsorListingTx({
|
|
6798
|
+
tx,
|
|
6799
|
+
nftTokenId,
|
|
6800
|
+
nftType,
|
|
6801
|
+
sponsorOptions: options
|
|
6802
|
+
});
|
|
6803
|
+
return tx;
|
|
7025
6804
|
};
|
|
7026
6805
|
|
|
7027
6806
|
// src/methods/transferNfts/transferNfts.ts
|
|
7028
|
-
var
|
|
6807
|
+
var import_transactions21 = require("@mysten/sui/transactions");
|
|
7029
6808
|
var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context) => {
|
|
7030
6809
|
if (addLeadingZerosAfter0x(recipientAddress) === addLeadingZerosAfter0x(walletAddress)) {
|
|
7031
6810
|
throw new Error("Cannot transfer to self");
|
|
@@ -7043,7 +6822,7 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
|
|
|
7043
6822
|
}
|
|
7044
6823
|
const nftsForTracking = [];
|
|
7045
6824
|
const nftsToTransferDirectly = [];
|
|
7046
|
-
const tx = new
|
|
6825
|
+
const tx = new import_transactions21.Transaction();
|
|
7047
6826
|
const sharedKioskState = {
|
|
7048
6827
|
kioskTx: void 0
|
|
7049
6828
|
};
|
|
@@ -7146,11 +6925,11 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
|
|
|
7146
6925
|
context.suiClient
|
|
7147
6926
|
);
|
|
7148
6927
|
sharedKioskState?.kioskTx?.finalize();
|
|
7149
|
-
return
|
|
6928
|
+
return import_transactions21.Transaction.from(tx);
|
|
7150
6929
|
};
|
|
7151
6930
|
|
|
7152
6931
|
// src/methods/unlistListings/unlistListings.ts
|
|
7153
|
-
var
|
|
6932
|
+
var import_transactions22 = require("@mysten/sui/transactions");
|
|
7154
6933
|
var unlistListings = async ({ listingIds, walletAddress }, context) => {
|
|
7155
6934
|
const res = await gqlChainRequest({
|
|
7156
6935
|
chain: "sui",
|
|
@@ -7161,7 +6940,7 @@ var unlistListings = async ({ listingIds, walletAddress }, context) => {
|
|
|
7161
6940
|
throw new Error("No listings found");
|
|
7162
6941
|
}
|
|
7163
6942
|
const listingsForTracking = [];
|
|
7164
|
-
const tx = new
|
|
6943
|
+
const tx = new import_transactions22.Transaction();
|
|
7165
6944
|
const sharedKioskState = {
|
|
7166
6945
|
kioskTx: void 0
|
|
7167
6946
|
};
|
|
@@ -7230,12 +7009,12 @@ var unlistListings = async ({ listingIds, walletAddress }, context) => {
|
|
|
7230
7009
|
});
|
|
7231
7010
|
}
|
|
7232
7011
|
sharedKioskState?.kioskTx?.finalize();
|
|
7233
|
-
return
|
|
7012
|
+
return import_transactions22.Transaction.from(tx);
|
|
7234
7013
|
};
|
|
7235
7014
|
|
|
7236
7015
|
// src/methods/withdrawProfitsFromKiosks/withdrawProfitsFromKiosks.ts
|
|
7237
7016
|
var import_kiosk5 = require("@mysten/kiosk");
|
|
7238
|
-
var
|
|
7017
|
+
var import_transactions23 = require("@mysten/sui/transactions");
|
|
7239
7018
|
async function withdrawProfitsFromKiosks({ walletAddress }, context) {
|
|
7240
7019
|
const res = await gqlChainRequest({
|
|
7241
7020
|
chain: "sui",
|
|
@@ -7255,7 +7034,7 @@ async function withdrawProfitsFromKiosks({ walletAddress }, context) {
|
|
|
7255
7034
|
if (kiosksWithProfit.length === 0) {
|
|
7256
7035
|
throw new Error(`No kiosks with profit to withdraw found for ${walletAddress}`);
|
|
7257
7036
|
}
|
|
7258
|
-
const tx = new
|
|
7037
|
+
const tx = new import_transactions23.Transaction();
|
|
7259
7038
|
try {
|
|
7260
7039
|
for (const kiosk of kiosksWithProfit) {
|
|
7261
7040
|
let kioskTx;
|
|
@@ -7301,149 +7080,7 @@ async function withdrawProfitsFromKiosks({ walletAddress }, context) {
|
|
|
7301
7080
|
} catch (err) {
|
|
7302
7081
|
console.log("err", err);
|
|
7303
7082
|
}
|
|
7304
|
-
return
|
|
7305
|
-
}
|
|
7306
|
-
|
|
7307
|
-
// src/methods/sponsorNftListing/sponsorNftListing.ts
|
|
7308
|
-
var import_transactions21 = require("@mysten/sui/transactions");
|
|
7309
|
-
|
|
7310
|
-
// src/graphql/queries/fetchNftCollectionChainState.ts
|
|
7311
|
-
var import_graphql_request20 = require("graphql-request");
|
|
7312
|
-
var fetchNftCollectionChainState = import_graphql_request20.gql`
|
|
7313
|
-
query fetchNftCollectionChainState($nftTokenId: String!) {
|
|
7314
|
-
nfts(where: { token_id: { _eq: $nftTokenId } }) {
|
|
7315
|
-
collection {
|
|
7316
|
-
id
|
|
7317
|
-
chain_state
|
|
7318
|
-
}
|
|
7319
|
-
}
|
|
7320
|
-
}
|
|
7321
|
-
`;
|
|
7322
|
-
|
|
7323
|
-
// src/methods/sponsorNftListing/sponsorNftListing.ts
|
|
7324
|
-
var sponsorNftListing = async ({ nftTokenId, walletAddress, options }, context) => {
|
|
7325
|
-
const res = await gqlChainRequest({
|
|
7326
|
-
chain: "sui",
|
|
7327
|
-
query: fetchNftCollectionChainState,
|
|
7328
|
-
variables: { nftTokenId }
|
|
7329
|
-
});
|
|
7330
|
-
if (res?.nfts?.length === 0) {
|
|
7331
|
-
throw new Error(`No nft found with token id ${nftTokenId}`);
|
|
7332
|
-
}
|
|
7333
|
-
const nft = res?.nfts?.[0];
|
|
7334
|
-
const nftType = getNftType({
|
|
7335
|
-
collectionId: nft?.collection?.id,
|
|
7336
|
-
collectionChainState: nft?.collection?.chain_state,
|
|
7337
|
-
nft
|
|
7338
|
-
});
|
|
7339
|
-
const transferPolicies = nft?.collection?.chain_state?.transfer_policies;
|
|
7340
|
-
if (isOriginByteCollection(transferPolicies)) {
|
|
7341
|
-
throw new Error(`You cannot sponsor an Origin Byte NFT. Nft Token Id: ${nftTokenId}`);
|
|
7342
|
-
}
|
|
7343
|
-
const tx = new import_transactions21.Transaction();
|
|
7344
|
-
await addSponsorListingTx({
|
|
7345
|
-
tx,
|
|
7346
|
-
suiClient: context.suiClient,
|
|
7347
|
-
nftTokenId,
|
|
7348
|
-
nftType,
|
|
7349
|
-
walletAddress,
|
|
7350
|
-
sponsorOptions: options,
|
|
7351
|
-
defiRouterUrl: context.defiRouterUrl
|
|
7352
|
-
});
|
|
7353
|
-
return tx instanceof import_transactions21.Transaction ? tx : import_transactions21.Transaction.from(tx);
|
|
7354
|
-
};
|
|
7355
|
-
|
|
7356
|
-
// src/methods/applyNftStrategy/applyNftStrategy.ts
|
|
7357
|
-
var import_transactions22 = require("@mysten/sui/transactions");
|
|
7358
|
-
|
|
7359
|
-
// src/graphql/queries/fetchCollectionFloorListingForMarket.ts
|
|
7360
|
-
var import_graphql_request21 = require("graphql-request");
|
|
7361
|
-
var fetchCollectionFloorListingsForMarket = import_graphql_request21.gql`
|
|
7362
|
-
query fetchCollectionFloorListingsForMarket(
|
|
7363
|
-
$collectionId: uuid!
|
|
7364
|
-
$marketAddress: String!
|
|
7365
|
-
$totalPrice: numeric
|
|
7366
|
-
) {
|
|
7367
|
-
listings(
|
|
7368
|
-
where: {
|
|
7369
|
-
collection_id: { _eq: $collectionId }
|
|
7370
|
-
listed: { _eq: true }
|
|
7371
|
-
market_name: { _eq: "tradeport" }
|
|
7372
|
-
seller: { _neq: $marketAddress }
|
|
7373
|
-
nonce: { _like: "1::0x%" }
|
|
7374
|
-
price: { _lte: $totalPrice }
|
|
7375
|
-
}
|
|
7376
|
-
order_by: [{ price: asc_nulls_last }, { block_height: asc }, { tx_index: asc }]
|
|
7377
|
-
) {
|
|
7378
|
-
id
|
|
7379
|
-
price
|
|
7380
|
-
nft {
|
|
7381
|
-
token_id
|
|
7382
|
-
delegated_owner
|
|
7383
|
-
}
|
|
7384
|
-
}
|
|
7385
|
-
}
|
|
7386
|
-
`;
|
|
7387
|
-
|
|
7388
|
-
// src/methods/applyNftStrategy/applyNftStrategy.ts
|
|
7389
|
-
async function applyTradeportNftStrategy({
|
|
7390
|
-
collectionId,
|
|
7391
|
-
strategyFtType,
|
|
7392
|
-
tx: existingTx
|
|
7393
|
-
}) {
|
|
7394
|
-
const tx = existingTx ?? new import_transactions22.Transaction();
|
|
7395
|
-
const chainState = await getCollectionChainState(collectionId);
|
|
7396
|
-
const nftStrategies = chainState?.nft_strategies ?? {};
|
|
7397
|
-
const nftStrategyKeys = Object.keys(nftStrategies);
|
|
7398
|
-
if (nftStrategyKeys.length === 0) {
|
|
7399
|
-
throw new Error("No NFT strategies found for collection");
|
|
7400
|
-
}
|
|
7401
|
-
strategyFtType = strategyFtType ?? nftStrategyKeys[0];
|
|
7402
|
-
if (!nftStrategyKeys.includes(strategyFtType)) {
|
|
7403
|
-
throw new Error(`Specified FT type ${strategyFtType} is not supported for this collection`);
|
|
7404
|
-
}
|
|
7405
|
-
const transferPolicy = getNativeKioskTransferPolicies(chainState?.transfer_policies ?? [])?.at(0);
|
|
7406
|
-
if (!transferPolicy) {
|
|
7407
|
-
throw new Error("No transfer policy found for collection");
|
|
7408
|
-
}
|
|
7409
|
-
const nftType = chainState?.nft_type;
|
|
7410
|
-
let suiBalance = BigInt(
|
|
7411
|
-
nftStrategies[strategyFtType].sui_balance ?? 0n
|
|
7412
|
-
);
|
|
7413
|
-
const result = await gqlChainRequest({
|
|
7414
|
-
chain: "sui",
|
|
7415
|
-
query: fetchCollectionFloorListingsForMarket,
|
|
7416
|
-
variables: {
|
|
7417
|
-
collectionId,
|
|
7418
|
-
marketAddress: TRADEPORT_NFT_STRATEGY_MANAGER_ID,
|
|
7419
|
-
totalPrice: suiBalance.toString()
|
|
7420
|
-
}
|
|
7421
|
-
});
|
|
7422
|
-
if ((result?.listings?.length ?? 0) === 0) {
|
|
7423
|
-
throw new Error(
|
|
7424
|
-
`No floor listing found for collection with price bellow or equal to ${suiBalance} MIST`
|
|
7425
|
-
);
|
|
7426
|
-
}
|
|
7427
|
-
for (const floorListing of result.listings) {
|
|
7428
|
-
suiBalance -= BigInt(floorListing.price);
|
|
7429
|
-
if (suiBalance < 0n) {
|
|
7430
|
-
break;
|
|
7431
|
-
}
|
|
7432
|
-
tx.moveCall({
|
|
7433
|
-
target: `${TRADEPORT_NFT_STRATEGY_PACKAGE_ID}::tradeport_nft_strategy::apply_tradeport_nft_strategy_confirm_request`,
|
|
7434
|
-
typeArguments: [nftType, strategyFtType],
|
|
7435
|
-
arguments: [
|
|
7436
|
-
tx.object(TRADEPORT_NFT_STRATEGY_MANAGER_ID),
|
|
7437
|
-
tx.object(nftStrategies[strategyFtType].kiosk_id),
|
|
7438
|
-
tx.object(TRADEPORT_LISTINGS_STORE),
|
|
7439
|
-
tx.object(TRADEPORT_ORDERBOOK_STORE),
|
|
7440
|
-
tx.object(floorListing.nft.delegated_owner),
|
|
7441
|
-
tx.object(floorListing.nft.token_id),
|
|
7442
|
-
tx.object(transferPolicy.id)
|
|
7443
|
-
]
|
|
7444
|
-
});
|
|
7445
|
-
}
|
|
7446
|
-
return tx;
|
|
7083
|
+
return import_transactions23.Transaction.from(tx);
|
|
7447
7084
|
}
|
|
7448
7085
|
|
|
7449
7086
|
// src/SuiTradingClient.ts
|
|
@@ -7453,14 +7090,14 @@ var SuiTradingClient = class {
|
|
|
7453
7090
|
apiKey,
|
|
7454
7091
|
apiVercelId,
|
|
7455
7092
|
apiUrl,
|
|
7456
|
-
|
|
7093
|
+
tradeportRouterUrl,
|
|
7457
7094
|
suiNodeUrl,
|
|
7458
7095
|
graphQLClient
|
|
7459
7096
|
}) {
|
|
7460
7097
|
this.allowedApiUsersForUnsharedKiosksMigration = ["tradeport.xyz", "mercato.xyz"];
|
|
7461
7098
|
this.apiUser = apiUser;
|
|
7462
7099
|
this.apiKey = apiKey;
|
|
7463
|
-
this.
|
|
7100
|
+
this.tradeportRouterUrl = tradeportRouterUrl;
|
|
7464
7101
|
this.suiClient = createSuiClient_default(suiNodeUrl ?? (0, import_client2.getFullnodeUrl)("mainnet"));
|
|
7465
7102
|
this.kioskClient = createKioskClient_default(this.suiClient);
|
|
7466
7103
|
if (graphQLClient) {
|
|
@@ -7474,31 +7111,31 @@ var SuiTradingClient = class {
|
|
|
7474
7111
|
...apiVercelId && { "x-vercel-id": apiVercelId }
|
|
7475
7112
|
});
|
|
7476
7113
|
}
|
|
7477
|
-
async buyListings(
|
|
7114
|
+
async buyListings(args) {
|
|
7478
7115
|
const context = {
|
|
7479
7116
|
apiUser: this.apiUser,
|
|
7480
7117
|
apiKey: this.apiKey,
|
|
7481
|
-
|
|
7118
|
+
tradeportRouterUrl: this.tradeportRouterUrl,
|
|
7482
7119
|
suiClient: this.suiClient,
|
|
7483
7120
|
kioskClient: this.kioskClient
|
|
7484
7121
|
};
|
|
7485
|
-
return buyListings(
|
|
7122
|
+
return buyListings(args, context);
|
|
7486
7123
|
}
|
|
7487
|
-
async listNfts({ nfts, walletAddress }) {
|
|
7124
|
+
async listNfts({ nfts, walletAddress, tx }) {
|
|
7488
7125
|
const context = {
|
|
7489
7126
|
apiUser: this.apiUser,
|
|
7490
7127
|
apiKey: this.apiKey,
|
|
7491
|
-
|
|
7128
|
+
tradeportRouterUrl: this.tradeportRouterUrl,
|
|
7492
7129
|
suiClient: this.suiClient,
|
|
7493
7130
|
kioskClient: this.kioskClient
|
|
7494
7131
|
};
|
|
7495
|
-
return listNfts({ nfts, walletAddress }, context);
|
|
7132
|
+
return listNfts({ nfts, walletAddress, tx }, context);
|
|
7496
7133
|
}
|
|
7497
7134
|
async unlistListings({ listingIds, walletAddress }) {
|
|
7498
7135
|
const context = {
|
|
7499
7136
|
apiUser: this.apiUser,
|
|
7500
7137
|
apiKey: this.apiKey,
|
|
7501
|
-
|
|
7138
|
+
tradeportRouterUrl: this.tradeportRouterUrl,
|
|
7502
7139
|
suiClient: this.suiClient,
|
|
7503
7140
|
kioskClient: this.kioskClient
|
|
7504
7141
|
};
|
|
@@ -7508,7 +7145,7 @@ var SuiTradingClient = class {
|
|
|
7508
7145
|
const context = {
|
|
7509
7146
|
apiUser: this.apiUser,
|
|
7510
7147
|
apiKey: this.apiKey,
|
|
7511
|
-
|
|
7148
|
+
tradeportRouterUrl: this.tradeportRouterUrl,
|
|
7512
7149
|
suiClient: this.suiClient,
|
|
7513
7150
|
kioskClient: this.kioskClient
|
|
7514
7151
|
};
|
|
@@ -7517,7 +7154,7 @@ var SuiTradingClient = class {
|
|
|
7517
7154
|
async removeNftBids({ bidIds, tx }) {
|
|
7518
7155
|
const context = {
|
|
7519
7156
|
apiUser: this.apiUser,
|
|
7520
|
-
|
|
7157
|
+
tradeportRouterUrl: this.tradeportRouterUrl,
|
|
7521
7158
|
apiKey: this.apiKey,
|
|
7522
7159
|
suiClient: this.suiClient,
|
|
7523
7160
|
kioskClient: this.kioskClient
|
|
@@ -7528,7 +7165,7 @@ var SuiTradingClient = class {
|
|
|
7528
7165
|
const context = {
|
|
7529
7166
|
apiUser: this.apiUser,
|
|
7530
7167
|
apiKey: this.apiKey,
|
|
7531
|
-
|
|
7168
|
+
tradeportRouterUrl: this.tradeportRouterUrl,
|
|
7532
7169
|
suiClient: this.suiClient,
|
|
7533
7170
|
kioskClient: this.kioskClient
|
|
7534
7171
|
};
|
|
@@ -7547,7 +7184,7 @@ var SuiTradingClient = class {
|
|
|
7547
7184
|
const context = {
|
|
7548
7185
|
apiUser: this.apiUser,
|
|
7549
7186
|
apiKey: this.apiKey,
|
|
7550
|
-
|
|
7187
|
+
tradeportRouterUrl: this.tradeportRouterUrl,
|
|
7551
7188
|
suiClient: this.suiClient,
|
|
7552
7189
|
kioskClient: this.kioskClient
|
|
7553
7190
|
};
|
|
@@ -7573,7 +7210,7 @@ var SuiTradingClient = class {
|
|
|
7573
7210
|
const context = {
|
|
7574
7211
|
apiUser: this.apiUser,
|
|
7575
7212
|
apiKey: this.apiKey,
|
|
7576
|
-
|
|
7213
|
+
tradeportRouterUrl: this.tradeportRouterUrl,
|
|
7577
7214
|
suiClient: this.suiClient,
|
|
7578
7215
|
kioskClient: this.kioskClient
|
|
7579
7216
|
};
|
|
@@ -7649,7 +7286,7 @@ var SuiTradingClient = class {
|
|
|
7649
7286
|
const context = {
|
|
7650
7287
|
apiUser: this.apiUser,
|
|
7651
7288
|
apiKey: this.apiKey,
|
|
7652
|
-
|
|
7289
|
+
tradeportRouterUrl: this.tradeportRouterUrl,
|
|
7653
7290
|
suiClient: this.suiClient,
|
|
7654
7291
|
kioskClient: this.kioskClient
|
|
7655
7292
|
};
|
|
@@ -7659,7 +7296,7 @@ var SuiTradingClient = class {
|
|
|
7659
7296
|
const context = {
|
|
7660
7297
|
apiUser: this.apiUser,
|
|
7661
7298
|
apiKey: this.apiKey,
|
|
7662
|
-
|
|
7299
|
+
tradeportRouterUrl: this.tradeportRouterUrl,
|
|
7663
7300
|
suiClient: this.suiClient,
|
|
7664
7301
|
kioskClient: this.kioskClient
|
|
7665
7302
|
};
|
|
@@ -7669,7 +7306,7 @@ var SuiTradingClient = class {
|
|
|
7669
7306
|
const context = {
|
|
7670
7307
|
apiUser: this.apiUser,
|
|
7671
7308
|
apiKey: this.apiKey,
|
|
7672
|
-
|
|
7309
|
+
tradeportRouterUrl: this.tradeportRouterUrl,
|
|
7673
7310
|
suiClient: this.suiClient,
|
|
7674
7311
|
kioskClient: this.kioskClient
|
|
7675
7312
|
};
|
|
@@ -7685,7 +7322,7 @@ var SuiTradingClient = class {
|
|
|
7685
7322
|
const context = {
|
|
7686
7323
|
apiUser: this.apiUser,
|
|
7687
7324
|
apiKey: this.apiKey,
|
|
7688
|
-
|
|
7325
|
+
tradeportRouterUrl: this.tradeportRouterUrl,
|
|
7689
7326
|
suiClient: this.suiClient,
|
|
7690
7327
|
kioskClient: this.kioskClient
|
|
7691
7328
|
};
|
|
@@ -7705,7 +7342,7 @@ var SuiTradingClient = class {
|
|
|
7705
7342
|
const context = {
|
|
7706
7343
|
apiUser: this.apiUser,
|
|
7707
7344
|
apiKey: this.apiKey,
|
|
7708
|
-
|
|
7345
|
+
tradeportRouterUrl: this.tradeportRouterUrl,
|
|
7709
7346
|
suiClient: this.suiClient,
|
|
7710
7347
|
kioskClient: this.kioskClient
|
|
7711
7348
|
};
|
|
@@ -7718,7 +7355,7 @@ var SuiTradingClient = class {
|
|
|
7718
7355
|
const context = {
|
|
7719
7356
|
apiUser: this.apiUser,
|
|
7720
7357
|
apiKey: this.apiKey,
|
|
7721
|
-
|
|
7358
|
+
tradeportRouterUrl: this.tradeportRouterUrl,
|
|
7722
7359
|
suiClient: this.suiClient,
|
|
7723
7360
|
kioskClient: this.kioskClient
|
|
7724
7361
|
};
|
|
@@ -7731,17 +7368,13 @@ var SuiTradingClient = class {
|
|
|
7731
7368
|
return cancelMultiBid(args);
|
|
7732
7369
|
}
|
|
7733
7370
|
async updateMultiBid(args) {
|
|
7734
|
-
return updateMultiBid(args
|
|
7371
|
+
return updateMultiBid(args, {
|
|
7372
|
+
suiClient: this.suiClient,
|
|
7373
|
+
tradeportRouterUrl: this.tradeportRouterUrl
|
|
7374
|
+
});
|
|
7735
7375
|
}
|
|
7736
7376
|
async sponsorNftListing(args) {
|
|
7737
|
-
|
|
7738
|
-
apiUser: this.apiUser,
|
|
7739
|
-
apiKey: this.apiKey,
|
|
7740
|
-
defiRouterUrl: this.defiRouterUrl,
|
|
7741
|
-
suiClient: this.suiClient,
|
|
7742
|
-
kioskClient: this.kioskClient
|
|
7743
|
-
};
|
|
7744
|
-
return sponsorNftListing(args, context);
|
|
7377
|
+
return sponsorNftListing(args);
|
|
7745
7378
|
}
|
|
7746
7379
|
async applyFtStrategy(args) {
|
|
7747
7380
|
return applyFtStrategy(args);
|
|
@@ -7749,15 +7382,6 @@ var SuiTradingClient = class {
|
|
|
7749
7382
|
async applyTradeportNftStrategy(args) {
|
|
7750
7383
|
return applyTradeportNftStrategy(args);
|
|
7751
7384
|
}
|
|
7752
|
-
async swapCoins(args) {
|
|
7753
|
-
return swapCoins(args, { suiClient: this.suiClient, defiRouterUrl: this.defiRouterUrl });
|
|
7754
|
-
}
|
|
7755
|
-
async buildSwapRoutes(args) {
|
|
7756
|
-
return buildSwapRoutes(args, { defiRouterUrl: this.defiRouterUrl });
|
|
7757
|
-
}
|
|
7758
|
-
async calculateAmountToSwap(args) {
|
|
7759
|
-
return calculateAmountToSwap(args);
|
|
7760
|
-
}
|
|
7761
7385
|
};
|
|
7762
7386
|
var SuiTradingClient_default = SuiTradingClient;
|
|
7763
7387
|
// Annotate the CommonJS export names for ESM import in node:
|