@zoralabs/protocol-sdk 0.11.7-COMMENTS.0 → 0.11.8
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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +8 -8
- package/dist/anvil.d.ts +1 -0
- package/dist/anvil.d.ts.map +1 -1
- package/dist/create/mint-from-create.d.ts +1 -2
- package/dist/create/mint-from-create.d.ts.map +1 -1
- package/dist/fixtures/rewards-query-results.d.ts +4 -1
- package/dist/fixtures/rewards-query-results.d.ts.map +1 -1
- package/dist/index.cjs +66 -207
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +68 -213
- package/dist/index.js.map +1 -1
- package/dist/mint/mint-client.d.ts +1 -3
- package/dist/mint/mint-client.d.ts.map +1 -1
- package/dist/mint/mint-queries.d.ts +3 -5
- package/dist/mint/mint-queries.d.ts.map +1 -1
- package/dist/mint/mint-transactions.d.ts +2 -4
- package/dist/mint/mint-transactions.d.ts.map +1 -1
- package/dist/rewards/rewards-queries.d.ts.map +1 -1
- package/dist/rewards/subgraph-queries.d.ts +2 -1
- package/dist/rewards/subgraph-queries.d.ts.map +1 -1
- package/dist/rewards/subgraph-rewards-getter.d.ts +9 -3
- package/dist/rewards/subgraph-rewards-getter.d.ts.map +1 -1
- package/dist/sdk.d.ts.map +1 -1
- package/dist/secondary/secondary-client.d.ts +1 -2
- package/dist/secondary/secondary-client.d.ts.map +1 -1
- package/dist/secondary/types.d.ts +0 -1
- package/dist/secondary/types.d.ts.map +1 -1
- package/dist/test-utils.d.ts +1 -5
- package/dist/test-utils.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/create/1155-create-helper.test.ts +12 -2
- package/src/create/1155-create-helper.ts +0 -2
- package/src/create/mint-from-create.ts +0 -3
- package/src/fixtures/rewards-query-results.ts +9 -2
- package/src/mint/mint-client.test.ts +30 -67
- package/src/mint/mint-client.ts +1 -10
- package/src/mint/mint-queries.ts +5 -16
- package/src/mint/mint-transactions.ts +16 -80
- package/src/rewards/rewards-client.test.ts +41 -9
- package/src/rewards/rewards-queries.ts +15 -5
- package/src/rewards/subgraph-queries.ts +4 -2
- package/src/rewards/subgraph-rewards-getter.ts +24 -10
- package/src/sdk.ts +0 -1
- package/src/secondary/secondary-client.test.ts +2 -248
- package/src/secondary/secondary-client.ts +6 -136
- package/src/secondary/types.ts +0 -2
- package/src/sparks/sparks-sponsored-sparks-spender.test.ts +1 -2
- package/src/test-utils.ts +0 -19
- package/src/comments/comments.test.ts +0 -338
package/dist/index.js
CHANGED
|
@@ -3717,9 +3717,7 @@ import {
|
|
|
3717
3717
|
import {
|
|
3718
3718
|
erc20MinterABI,
|
|
3719
3719
|
zoraCreator1155ImplABI as zoraCreator1155ImplABI2,
|
|
3720
|
-
zoraTimedSaleStrategyABI
|
|
3721
|
-
callerAndCommenterABI,
|
|
3722
|
-
callerAndCommenterAddress
|
|
3720
|
+
zoraTimedSaleStrategyABI
|
|
3723
3721
|
} from "@zoralabs/protocol-deployments";
|
|
3724
3722
|
|
|
3725
3723
|
// src/mint/utils.ts
|
|
@@ -3737,8 +3735,7 @@ var contractSupportsNewMintFunction = (contractVersion) => {
|
|
|
3737
3735
|
// src/mint/mint-transactions.ts
|
|
3738
3736
|
function makeOnchainMintCall({
|
|
3739
3737
|
token,
|
|
3740
|
-
mintParams
|
|
3741
|
-
chainId
|
|
3738
|
+
mintParams
|
|
3742
3739
|
}) {
|
|
3743
3740
|
if (token.mintType === "721") {
|
|
3744
3741
|
return makePrepareMint721TokenParams({
|
|
@@ -3751,55 +3748,9 @@ function makeOnchainMintCall({
|
|
|
3751
3748
|
salesConfigAndTokenInfo: token,
|
|
3752
3749
|
tokenContract: token.contract.address,
|
|
3753
3750
|
tokenId: token.tokenId,
|
|
3754
|
-
chainId,
|
|
3755
3751
|
...mintParams
|
|
3756
3752
|
});
|
|
3757
3753
|
}
|
|
3758
|
-
function makeZoraTimedSaleStrategyMintCall({
|
|
3759
|
-
minterAccount,
|
|
3760
|
-
salesConfigAndTokenInfo,
|
|
3761
|
-
mintQuantity,
|
|
3762
|
-
mintTo,
|
|
3763
|
-
tokenContract,
|
|
3764
|
-
tokenId,
|
|
3765
|
-
mintReferral,
|
|
3766
|
-
mintComment,
|
|
3767
|
-
chainId
|
|
3768
|
-
}) {
|
|
3769
|
-
if (mintComment && mintComment !== "") {
|
|
3770
|
-
return makeContractParameters({
|
|
3771
|
-
abi: callerAndCommenterABI,
|
|
3772
|
-
address: callerAndCommenterAddress[chainId],
|
|
3773
|
-
functionName: "timedSaleMintAndComment",
|
|
3774
|
-
account: minterAccount,
|
|
3775
|
-
value: salesConfigAndTokenInfo.salesConfig.mintFeePerQuantity * mintQuantity,
|
|
3776
|
-
args: [
|
|
3777
|
-
mintTo,
|
|
3778
|
-
mintQuantity,
|
|
3779
|
-
tokenContract,
|
|
3780
|
-
tokenId,
|
|
3781
|
-
mintReferral || zeroAddress3,
|
|
3782
|
-
mintComment
|
|
3783
|
-
]
|
|
3784
|
-
});
|
|
3785
|
-
}
|
|
3786
|
-
return makeContractParameters({
|
|
3787
|
-
abi: zoraTimedSaleStrategyABI,
|
|
3788
|
-
functionName: "mint",
|
|
3789
|
-
account: minterAccount,
|
|
3790
|
-
address: salesConfigAndTokenInfo.salesConfig.address,
|
|
3791
|
-
value: salesConfigAndTokenInfo.salesConfig.mintFeePerQuantity * mintQuantity,
|
|
3792
|
-
/* args: mintTo, quantity, collection, tokenId, mintReferral, comment */
|
|
3793
|
-
args: [
|
|
3794
|
-
mintTo,
|
|
3795
|
-
mintQuantity,
|
|
3796
|
-
tokenContract,
|
|
3797
|
-
BigInt(tokenId),
|
|
3798
|
-
mintReferral || zeroAddress3,
|
|
3799
|
-
""
|
|
3800
|
-
]
|
|
3801
|
-
});
|
|
3802
|
-
}
|
|
3803
3754
|
function makePrepareMint1155TokenParams({
|
|
3804
3755
|
tokenContract,
|
|
3805
3756
|
tokenId,
|
|
@@ -3809,8 +3760,7 @@ function makePrepareMint1155TokenParams({
|
|
|
3809
3760
|
mintReferral,
|
|
3810
3761
|
mintRecipient,
|
|
3811
3762
|
quantityToMint,
|
|
3812
|
-
allowListEntry
|
|
3813
|
-
chainId
|
|
3763
|
+
allowListEntry
|
|
3814
3764
|
}) {
|
|
3815
3765
|
const mintQuantity = BigInt(quantityToMint || 1);
|
|
3816
3766
|
const mintTo = mintRecipientOrAccount({ mintRecipient, minterAccount });
|
|
@@ -3829,16 +3779,21 @@ function makePrepareMint1155TokenParams({
|
|
|
3829
3779
|
});
|
|
3830
3780
|
}
|
|
3831
3781
|
if (saleType === "timed") {
|
|
3832
|
-
return
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
tokenId,
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3782
|
+
return makeContractParameters({
|
|
3783
|
+
abi: zoraTimedSaleStrategyABI,
|
|
3784
|
+
functionName: "mint",
|
|
3785
|
+
account: minterAccount,
|
|
3786
|
+
address: salesConfigAndTokenInfo.salesConfig.address,
|
|
3787
|
+
value: salesConfigAndTokenInfo.salesConfig.mintFeePerQuantity * mintQuantity,
|
|
3788
|
+
/* args: mintTo, quantity, collection, tokenId, mintReferral, comment */
|
|
3789
|
+
args: [
|
|
3790
|
+
mintTo,
|
|
3791
|
+
mintQuantity,
|
|
3792
|
+
tokenContract,
|
|
3793
|
+
BigInt(tokenId),
|
|
3794
|
+
mintReferral || zeroAddress3,
|
|
3795
|
+
mintComment || ""
|
|
3796
|
+
]
|
|
3842
3797
|
});
|
|
3843
3798
|
}
|
|
3844
3799
|
if (saleType === "erc20") {
|
|
@@ -4003,8 +3958,7 @@ async function getMint({
|
|
|
4003
3958
|
params,
|
|
4004
3959
|
mintGetter,
|
|
4005
3960
|
premintGetter,
|
|
4006
|
-
publicClient
|
|
4007
|
-
chainId
|
|
3961
|
+
publicClient
|
|
4008
3962
|
}) {
|
|
4009
3963
|
const { tokenContract } = params;
|
|
4010
3964
|
if (isOnChainMint(params)) {
|
|
@@ -4016,7 +3970,7 @@ async function getMint({
|
|
|
4016
3970
|
preferredSaleType: params.preferredSaleType,
|
|
4017
3971
|
blockTime
|
|
4018
3972
|
});
|
|
4019
|
-
return toMintableReturn(result
|
|
3973
|
+
return toMintableReturn(result);
|
|
4020
3974
|
}
|
|
4021
3975
|
const premint = await premintGetter.get({
|
|
4022
3976
|
collectionAddress: tokenContract,
|
|
@@ -4054,12 +4008,11 @@ async function getMintsOfContract({
|
|
|
4054
4008
|
params,
|
|
4055
4009
|
mintGetter,
|
|
4056
4010
|
premintGetter,
|
|
4057
|
-
publicClient
|
|
4058
|
-
chainId
|
|
4011
|
+
publicClient
|
|
4059
4012
|
}) {
|
|
4060
4013
|
const onchainMints = (await mintGetter.getContractMintable({
|
|
4061
4014
|
tokenAddress: params.tokenContract
|
|
4062
|
-
})).map(
|
|
4015
|
+
})).map(toMintableReturn);
|
|
4063
4016
|
const offchainMints = await getPremintsOfContractMintable({
|
|
4064
4017
|
mintGetter,
|
|
4065
4018
|
premintGetter,
|
|
@@ -4176,15 +4129,14 @@ function parsePremint({
|
|
|
4176
4129
|
}
|
|
4177
4130
|
throw new Error("Invalid premint config version");
|
|
4178
4131
|
}
|
|
4179
|
-
var makeOnchainPrepareMint = (result
|
|
4132
|
+
var makeOnchainPrepareMint = (result) => (params) => {
|
|
4180
4133
|
if (!result.salesConfig) {
|
|
4181
4134
|
throw new Error("No valid sales config found for token");
|
|
4182
4135
|
}
|
|
4183
4136
|
return {
|
|
4184
4137
|
parameters: makeOnchainMintCall({
|
|
4185
4138
|
token: result,
|
|
4186
|
-
mintParams: params
|
|
4187
|
-
chainId
|
|
4139
|
+
mintParams: params
|
|
4188
4140
|
}),
|
|
4189
4141
|
erc20Approval: getRequiredErc20Approvals(params, result.salesConfig),
|
|
4190
4142
|
costs: parseMintCosts({
|
|
@@ -4194,7 +4146,7 @@ var makeOnchainPrepareMint = (result, chainId) => (params) => {
|
|
|
4194
4146
|
})
|
|
4195
4147
|
};
|
|
4196
4148
|
};
|
|
4197
|
-
function toMintableReturn(result
|
|
4149
|
+
function toMintableReturn(result) {
|
|
4198
4150
|
const primaryMintActive = result.primaryMintActive;
|
|
4199
4151
|
if (!primaryMintActive) {
|
|
4200
4152
|
return {
|
|
@@ -4210,10 +4162,7 @@ function toMintableReturn(result, chainId) {
|
|
|
4210
4162
|
primaryMintActive,
|
|
4211
4163
|
primaryMintEnd: result.primaryMintEnd,
|
|
4212
4164
|
secondaryMarketActive: result.secondaryMarketActive,
|
|
4213
|
-
prepareMint: makeOnchainPrepareMint(
|
|
4214
|
-
result.salesConfigAndTokenInfo,
|
|
4215
|
-
chainId
|
|
4216
|
-
)
|
|
4165
|
+
prepareMint: makeOnchainPrepareMint(result.salesConfigAndTokenInfo)
|
|
4217
4166
|
};
|
|
4218
4167
|
}
|
|
4219
4168
|
var makePremintPrepareMint = (mintable, mintFee, premint) => {
|
|
@@ -4276,13 +4225,11 @@ var MintClient = class {
|
|
|
4276
4225
|
constructor({
|
|
4277
4226
|
publicClient,
|
|
4278
4227
|
premintGetter,
|
|
4279
|
-
mintGetter
|
|
4280
|
-
chainId
|
|
4228
|
+
mintGetter
|
|
4281
4229
|
}) {
|
|
4282
4230
|
this.publicClient = publicClient;
|
|
4283
4231
|
this.mintGetter = mintGetter;
|
|
4284
4232
|
this.premintGetter = premintGetter;
|
|
4285
|
-
this.chainId = chainId;
|
|
4286
4233
|
}
|
|
4287
4234
|
/**
|
|
4288
4235
|
* Returns the parameters needed to prepare a transaction mint a token.
|
|
@@ -4296,8 +4243,7 @@ var MintClient = class {
|
|
|
4296
4243
|
parameters,
|
|
4297
4244
|
publicClient: this.publicClient,
|
|
4298
4245
|
mintGetter: this.mintGetter,
|
|
4299
|
-
premintGetter: this.premintGetter
|
|
4300
|
-
chainId: this.chainId
|
|
4246
|
+
premintGetter: this.premintGetter
|
|
4301
4247
|
});
|
|
4302
4248
|
}
|
|
4303
4249
|
/**
|
|
@@ -4311,8 +4257,7 @@ var MintClient = class {
|
|
|
4311
4257
|
params: parameters,
|
|
4312
4258
|
mintGetter: this.mintGetter,
|
|
4313
4259
|
premintGetter: this.premintGetter,
|
|
4314
|
-
publicClient: this.publicClient
|
|
4315
|
-
chainId: this.chainId
|
|
4260
|
+
publicClient: this.publicClient
|
|
4316
4261
|
});
|
|
4317
4262
|
}
|
|
4318
4263
|
/**
|
|
@@ -4326,8 +4271,7 @@ var MintClient = class {
|
|
|
4326
4271
|
params,
|
|
4327
4272
|
mintGetter: this.mintGetter,
|
|
4328
4273
|
premintGetter: this.premintGetter,
|
|
4329
|
-
publicClient: this.publicClient
|
|
4330
|
-
chainId: this.chainId
|
|
4274
|
+
publicClient: this.publicClient
|
|
4331
4275
|
});
|
|
4332
4276
|
}
|
|
4333
4277
|
/**
|
|
@@ -4348,15 +4292,13 @@ async function mint({
|
|
|
4348
4292
|
parameters,
|
|
4349
4293
|
publicClient,
|
|
4350
4294
|
mintGetter,
|
|
4351
|
-
premintGetter
|
|
4352
|
-
chainId
|
|
4295
|
+
premintGetter
|
|
4353
4296
|
}) {
|
|
4354
4297
|
const { prepareMint, primaryMintActive } = await getMint({
|
|
4355
4298
|
params: parameters,
|
|
4356
4299
|
mintGetter,
|
|
4357
4300
|
premintGetter,
|
|
4358
|
-
publicClient
|
|
4359
|
-
chainId
|
|
4301
|
+
publicClient
|
|
4360
4302
|
});
|
|
4361
4303
|
if (!primaryMintActive) {
|
|
4362
4304
|
throw new Error("Primary mint is not active");
|
|
@@ -4918,8 +4860,7 @@ function makeOnchainPrepareMintFromCreate({
|
|
|
4918
4860
|
result,
|
|
4919
4861
|
minter,
|
|
4920
4862
|
getContractMintFee,
|
|
4921
|
-
contractVersion
|
|
4922
|
-
chainId
|
|
4863
|
+
contractVersion
|
|
4923
4864
|
}) {
|
|
4924
4865
|
return async (params) => {
|
|
4925
4866
|
const subgraphSalesConfig = await toSalesStrategyFromSubgraph({
|
|
@@ -4935,8 +4876,7 @@ function makeOnchainPrepareMintFromCreate({
|
|
|
4935
4876
|
},
|
|
4936
4877
|
...params,
|
|
4937
4878
|
tokenContract: contractAddress,
|
|
4938
|
-
tokenId
|
|
4939
|
-
chainId
|
|
4879
|
+
tokenId
|
|
4940
4880
|
}),
|
|
4941
4881
|
costs: parseMintCosts({
|
|
4942
4882
|
allowListEntry: params.allowListEntry,
|
|
@@ -5109,8 +5049,7 @@ async function createNew1155ContractAndToken({
|
|
|
5109
5049
|
getContractMintFee: async () => getNewContractMintFee({
|
|
5110
5050
|
publicClient,
|
|
5111
5051
|
chainId
|
|
5112
|
-
})
|
|
5113
|
-
chainId
|
|
5052
|
+
})
|
|
5114
5053
|
});
|
|
5115
5054
|
return {
|
|
5116
5055
|
parameters: request,
|
|
@@ -5156,8 +5095,7 @@ async function createNew1155Token({
|
|
|
5156
5095
|
minter,
|
|
5157
5096
|
result: newToken.salesConfig,
|
|
5158
5097
|
tokenId: nextTokenId,
|
|
5159
|
-
getContractMintFee: async () => mintFee
|
|
5160
|
-
chainId
|
|
5098
|
+
getContractMintFee: async () => mintFee
|
|
5161
5099
|
});
|
|
5162
5100
|
return {
|
|
5163
5101
|
parameters: request,
|
|
@@ -5616,7 +5554,10 @@ var getRewardsBalance = async ({
|
|
|
5616
5554
|
// Interface for getting ERC20Z tokens for a creator
|
|
5617
5555
|
}) => {
|
|
5618
5556
|
const address = typeof account === "string" ? account : account.address;
|
|
5619
|
-
const
|
|
5557
|
+
const erc20ZsAndSecondaryActivated = await rewardsGetter.getErc20ZzForCreator(
|
|
5558
|
+
{ address }
|
|
5559
|
+
);
|
|
5560
|
+
const validErc20Zs = erc20ZsAndSecondaryActivated.filter(({ secondaryActivated }) => secondaryActivated).map(({ erc20z }) => erc20z);
|
|
5620
5561
|
const result = await publicClient.multicall({
|
|
5621
5562
|
contracts: [
|
|
5622
5563
|
{
|
|
@@ -5629,7 +5570,7 @@ var getRewardsBalance = async ({
|
|
|
5629
5570
|
address: erc20ZRoyaltiesAddress[chainId],
|
|
5630
5571
|
abi: erc20ZRoyaltiesABI,
|
|
5631
5572
|
functionName: "getUnclaimedFeesBatch",
|
|
5632
|
-
args: [
|
|
5573
|
+
args: [validErc20Zs]
|
|
5633
5574
|
}
|
|
5634
5575
|
],
|
|
5635
5576
|
multicallAddress: multicall3Address,
|
|
@@ -5662,9 +5603,10 @@ var makeClaimSecondaryRoyaltiesCalls = async ({
|
|
|
5662
5603
|
chainId,
|
|
5663
5604
|
rewardsGetter
|
|
5664
5605
|
}) => {
|
|
5665
|
-
const
|
|
5666
|
-
address: claimFor
|
|
5667
|
-
|
|
5606
|
+
const erc20ZsAndSecondaryActivated = await rewardsGetter.getErc20ZzForCreator(
|
|
5607
|
+
{ address: claimFor }
|
|
5608
|
+
);
|
|
5609
|
+
const erc20z = erc20ZsAndSecondaryActivated.filter(({ secondaryActivated }) => secondaryActivated).map(({ erc20z: erc20z2 }) => erc20z2);
|
|
5668
5610
|
const royaltiesAddress = erc20ZRoyaltiesAddress[chainId];
|
|
5669
5611
|
if (erc20z.length === 0) {
|
|
5670
5612
|
return [];
|
|
@@ -5764,13 +5706,14 @@ function buildCreatorERC20zs({
|
|
|
5764
5706
|
query: `
|
|
5765
5707
|
query ($address: Bytes!) {
|
|
5766
5708
|
zoraCreateTokens(
|
|
5767
|
-
where: { royalties_: {
|
|
5709
|
+
where: { royalties_: { royaltyRecipient: $address }, salesStrategies_: { type: "ZORA_TIMED" } }
|
|
5768
5710
|
) {
|
|
5769
5711
|
royalties {
|
|
5770
5712
|
user
|
|
5771
5713
|
}
|
|
5772
5714
|
salesStrategies {
|
|
5773
5715
|
zoraTimedMinter {
|
|
5716
|
+
secondaryActivated
|
|
5774
5717
|
erc20Z {
|
|
5775
5718
|
id
|
|
5776
5719
|
}
|
|
@@ -5791,15 +5734,23 @@ var SubgraphRewardsGetter = class extends SubgraphGetter {
|
|
|
5791
5734
|
constructor(chainId, subgraphQuerier) {
|
|
5792
5735
|
super(chainId, subgraphQuerier);
|
|
5793
5736
|
}
|
|
5794
|
-
async getErc20ZzForCreator({
|
|
5795
|
-
address
|
|
5796
|
-
}) {
|
|
5737
|
+
async getErc20ZzForCreator({ address }) {
|
|
5797
5738
|
const queryResults = await this.querySubgraphWithRetries(
|
|
5798
5739
|
buildCreatorERC20zs({ address })
|
|
5799
5740
|
);
|
|
5800
|
-
|
|
5801
|
-
|
|
5802
|
-
|
|
5741
|
+
const results = (queryResults?.map((result) => {
|
|
5742
|
+
const timedMinter = result.salesStrategies[0].zoraTimedMinter;
|
|
5743
|
+
if (!timedMinter) {
|
|
5744
|
+
return null;
|
|
5745
|
+
}
|
|
5746
|
+
return {
|
|
5747
|
+
secondaryActivated: timedMinter.secondaryActivated,
|
|
5748
|
+
erc20z: timedMinter.erc20Z.id
|
|
5749
|
+
};
|
|
5750
|
+
}) || []).filter(
|
|
5751
|
+
(idAndActivated) => !!idAndActivated
|
|
5752
|
+
);
|
|
5753
|
+
return results;
|
|
5803
5754
|
}
|
|
5804
5755
|
};
|
|
5805
5756
|
|
|
@@ -5809,9 +5760,7 @@ import {
|
|
|
5809
5760
|
secondarySwapAddress,
|
|
5810
5761
|
zoraCreator1155ImplABI as zoraCreator1155ImplABI7,
|
|
5811
5762
|
safeTransferSwapAbiParameters,
|
|
5812
|
-
secondarySwapABI
|
|
5813
|
-
callerAndCommenterABI as callerAndCommenterABI2,
|
|
5814
|
-
callerAndCommenterAddress as callerAndCommenterAddress2
|
|
5763
|
+
secondarySwapABI
|
|
5815
5764
|
} from "@zoralabs/protocol-deployments";
|
|
5816
5765
|
|
|
5817
5766
|
// src/secondary/uniswap/uniswapQuote.ts
|
|
@@ -6099,13 +6048,10 @@ var ERROR_INSUFFICIENT_WALLET_FUNDS = "Insufficient wallet funds";
|
|
|
6099
6048
|
var ERROR_INSUFFICIENT_POOL_SUPPLY = "Insufficient pool supply";
|
|
6100
6049
|
var ERROR_SECONDARY_NOT_CONFIGURED = "Secondary not configured for given contract and token";
|
|
6101
6050
|
var ERROR_SECONDARY_NOT_STARTED = "Secondary market has not started";
|
|
6102
|
-
var ERROR_RECIPIENT_MISMATCH = "Recipient must be the same as the caller if there is a comment";
|
|
6103
6051
|
function makeError(errorMessage) {
|
|
6104
6052
|
return { error: errorMessage };
|
|
6105
6053
|
}
|
|
6106
6054
|
async function makeBuy({
|
|
6107
|
-
contract,
|
|
6108
|
-
tokenId,
|
|
6109
6055
|
erc20z,
|
|
6110
6056
|
poolBalance,
|
|
6111
6057
|
amount,
|
|
@@ -6114,106 +6060,20 @@ async function makeBuy({
|
|
|
6114
6060
|
recipient,
|
|
6115
6061
|
chainId,
|
|
6116
6062
|
slippage,
|
|
6117
|
-
publicClient,
|
|
6118
|
-
comment
|
|
6119
|
-
}) {
|
|
6120
|
-
const costWithSlippage = calculateSlippageUp(amount, slippage);
|
|
6121
|
-
const accountAddress = addressOrAccountAddress(account);
|
|
6122
|
-
const validationResult = await validateBuyConditions({
|
|
6123
|
-
poolBalance,
|
|
6124
|
-
quantity,
|
|
6125
|
-
costWithSlippage,
|
|
6126
|
-
accountAddress,
|
|
6127
|
-
publicClient
|
|
6128
|
-
});
|
|
6129
|
-
if (validationResult.error) {
|
|
6130
|
-
return makeError(validationResult.error);
|
|
6131
|
-
}
|
|
6132
|
-
if (comment && comment !== "") {
|
|
6133
|
-
return handleBuyWithComment({
|
|
6134
|
-
accountAddress,
|
|
6135
|
-
recipient,
|
|
6136
|
-
chainId,
|
|
6137
|
-
quantity,
|
|
6138
|
-
contract,
|
|
6139
|
-
tokenId,
|
|
6140
|
-
costWithSlippage,
|
|
6141
|
-
comment,
|
|
6142
|
-
account
|
|
6143
|
-
});
|
|
6144
|
-
}
|
|
6145
|
-
return handleBuyWithoutComment({
|
|
6146
|
-
erc20z,
|
|
6147
|
-
quantity,
|
|
6148
|
-
recipient,
|
|
6149
|
-
accountAddress,
|
|
6150
|
-
costWithSlippage,
|
|
6151
|
-
chainId,
|
|
6152
|
-
account
|
|
6153
|
-
});
|
|
6154
|
-
}
|
|
6155
|
-
async function validateBuyConditions({
|
|
6156
|
-
poolBalance,
|
|
6157
|
-
quantity,
|
|
6158
|
-
costWithSlippage,
|
|
6159
|
-
accountAddress,
|
|
6160
6063
|
publicClient
|
|
6161
6064
|
}) {
|
|
6065
|
+
const costWithSlippage = calculateSlippageUp(amount, slippage);
|
|
6162
6066
|
const availableToBuy = poolBalance.erc20z / BigInt(1e18) - 1n;
|
|
6067
|
+
const accountAddress = addressOrAccountAddress(account);
|
|
6163
6068
|
const availableToSpend = await publicClient.getBalance({
|
|
6164
6069
|
address: accountAddress
|
|
6165
6070
|
});
|
|
6166
6071
|
if (costWithSlippage > availableToSpend) {
|
|
6167
|
-
return
|
|
6072
|
+
return makeError(ERROR_INSUFFICIENT_WALLET_FUNDS);
|
|
6168
6073
|
}
|
|
6169
6074
|
if (availableToBuy < BigInt(quantity)) {
|
|
6170
|
-
return
|
|
6171
|
-
}
|
|
6172
|
-
return {};
|
|
6173
|
-
}
|
|
6174
|
-
function handleBuyWithComment({
|
|
6175
|
-
accountAddress,
|
|
6176
|
-
recipient,
|
|
6177
|
-
chainId,
|
|
6178
|
-
quantity,
|
|
6179
|
-
contract,
|
|
6180
|
-
tokenId,
|
|
6181
|
-
costWithSlippage,
|
|
6182
|
-
comment,
|
|
6183
|
-
account
|
|
6184
|
-
}) {
|
|
6185
|
-
if (recipient && recipient !== accountAddress) {
|
|
6186
|
-
return makeError(ERROR_RECIPIENT_MISMATCH);
|
|
6075
|
+
return makeError(ERROR_INSUFFICIENT_POOL_SUPPLY);
|
|
6187
6076
|
}
|
|
6188
|
-
return {
|
|
6189
|
-
parameters: makeContractParameters({
|
|
6190
|
-
abi: callerAndCommenterABI2,
|
|
6191
|
-
address: callerAndCommenterAddress2[chainId],
|
|
6192
|
-
functionName: "buyOnSecondaryAndComment",
|
|
6193
|
-
args: [
|
|
6194
|
-
accountAddress,
|
|
6195
|
-
quantity,
|
|
6196
|
-
contract,
|
|
6197
|
-
tokenId,
|
|
6198
|
-
accountAddress,
|
|
6199
|
-
costWithSlippage,
|
|
6200
|
-
0n,
|
|
6201
|
-
comment
|
|
6202
|
-
],
|
|
6203
|
-
account,
|
|
6204
|
-
value: costWithSlippage
|
|
6205
|
-
})
|
|
6206
|
-
};
|
|
6207
|
-
}
|
|
6208
|
-
function handleBuyWithoutComment({
|
|
6209
|
-
erc20z,
|
|
6210
|
-
quantity,
|
|
6211
|
-
recipient,
|
|
6212
|
-
accountAddress,
|
|
6213
|
-
costWithSlippage,
|
|
6214
|
-
chainId,
|
|
6215
|
-
account
|
|
6216
|
-
}) {
|
|
6217
6077
|
return {
|
|
6218
6078
|
parameters: makeContractParameters({
|
|
6219
6079
|
abi: secondarySwapABI,
|
|
@@ -6240,8 +6100,7 @@ async function buyWithSlippage({
|
|
|
6240
6100
|
chainId,
|
|
6241
6101
|
account,
|
|
6242
6102
|
slippage = UNISWAP_SLIPPAGE,
|
|
6243
|
-
recipient
|
|
6244
|
-
comment
|
|
6103
|
+
recipient
|
|
6245
6104
|
}) {
|
|
6246
6105
|
const secondaryInfo = await getSecondaryInfo({
|
|
6247
6106
|
contract,
|
|
@@ -6268,8 +6127,6 @@ async function buyWithSlippage({
|
|
|
6268
6127
|
);
|
|
6269
6128
|
const call = await makeBuy({
|
|
6270
6129
|
erc20z,
|
|
6271
|
-
contract,
|
|
6272
|
-
tokenId,
|
|
6273
6130
|
poolBalance,
|
|
6274
6131
|
amount,
|
|
6275
6132
|
quantity,
|
|
@@ -6277,7 +6134,6 @@ async function buyWithSlippage({
|
|
|
6277
6134
|
recipient,
|
|
6278
6135
|
chainId,
|
|
6279
6136
|
slippage,
|
|
6280
|
-
comment,
|
|
6281
6137
|
publicClient
|
|
6282
6138
|
});
|
|
6283
6139
|
return {
|
|
@@ -6467,8 +6323,7 @@ function createCollectorClient(params) {
|
|
|
6467
6323
|
const mintClient = new MintClient({
|
|
6468
6324
|
publicClient: params.publicClient,
|
|
6469
6325
|
premintGetter: premintGetterToUse,
|
|
6470
|
-
mintGetter: mintGetterToUse
|
|
6471
|
-
chainId: params.chainId
|
|
6326
|
+
mintGetter: mintGetterToUse
|
|
6472
6327
|
});
|
|
6473
6328
|
const secondaryClient = new SecondaryClient({
|
|
6474
6329
|
publicClient: params.publicClient,
|