@zoralabs/protocol-sdk 0.11.7 → 0.11.9
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 +15 -0
- package/dist/anvil.d.ts +1 -0
- package/dist/anvil.d.ts.map +1 -1
- package/dist/create/mint-from-create.d.ts +2 -1
- 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 +219 -52
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +225 -54
- package/dist/index.js.map +1 -1
- package/dist/mint/mint-client.d.ts +3 -1
- package/dist/mint/mint-client.d.ts.map +1 -1
- package/dist/mint/mint-queries.d.ts +5 -3
- package/dist/mint/mint-queries.d.ts.map +1 -1
- package/dist/mint/mint-transactions.d.ts +4 -2
- 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 +2 -1
- package/dist/secondary/secondary-client.d.ts.map +1 -1
- package/dist/secondary/types.d.ts +1 -0
- package/dist/secondary/types.d.ts.map +1 -1
- package/dist/test-utils.d.ts +5 -1
- package/dist/test-utils.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/comments/comments.test.ts +338 -0
- package/src/create/1155-create-helper.test.ts +2 -12
- package/src/create/1155-create-helper.ts +2 -0
- package/src/create/mint-from-create.ts +3 -0
- package/src/fixtures/rewards-query-results.ts +9 -2
- package/src/mint/mint-client.test.ts +67 -30
- package/src/mint/mint-client.ts +10 -1
- package/src/mint/mint-queries.ts +16 -5
- package/src/mint/mint-transactions.ts +80 -16
- package/src/rewards/rewards-client.test.ts +41 -9
- package/src/rewards/rewards-queries.ts +15 -5
- package/src/rewards/subgraph-queries.ts +3 -1
- package/src/rewards/subgraph-rewards-getter.ts +24 -10
- package/src/sdk.ts +1 -0
- package/src/secondary/secondary-client.test.ts +248 -2
- package/src/secondary/secondary-client.ts +136 -6
- package/src/secondary/types.ts +2 -0
- package/src/sparks/sparks-sponsored-sparks-spender.test.ts +1 -0
- package/src/test-utils.ts +19 -0
package/dist/index.js
CHANGED
|
@@ -3717,7 +3717,9 @@ import {
|
|
|
3717
3717
|
import {
|
|
3718
3718
|
erc20MinterABI,
|
|
3719
3719
|
zoraCreator1155ImplABI as zoraCreator1155ImplABI2,
|
|
3720
|
-
zoraTimedSaleStrategyABI
|
|
3720
|
+
zoraTimedSaleStrategyABI,
|
|
3721
|
+
callerAndCommenterABI,
|
|
3722
|
+
callerAndCommenterAddress
|
|
3721
3723
|
} from "@zoralabs/protocol-deployments";
|
|
3722
3724
|
|
|
3723
3725
|
// src/mint/utils.ts
|
|
@@ -3735,7 +3737,8 @@ var contractSupportsNewMintFunction = (contractVersion) => {
|
|
|
3735
3737
|
// src/mint/mint-transactions.ts
|
|
3736
3738
|
function makeOnchainMintCall({
|
|
3737
3739
|
token,
|
|
3738
|
-
mintParams
|
|
3740
|
+
mintParams,
|
|
3741
|
+
chainId
|
|
3739
3742
|
}) {
|
|
3740
3743
|
if (token.mintType === "721") {
|
|
3741
3744
|
return makePrepareMint721TokenParams({
|
|
@@ -3748,9 +3751,55 @@ function makeOnchainMintCall({
|
|
|
3748
3751
|
salesConfigAndTokenInfo: token,
|
|
3749
3752
|
tokenContract: token.contract.address,
|
|
3750
3753
|
tokenId: token.tokenId,
|
|
3754
|
+
chainId,
|
|
3751
3755
|
...mintParams
|
|
3752
3756
|
});
|
|
3753
3757
|
}
|
|
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
|
+
}
|
|
3754
3803
|
function makePrepareMint1155TokenParams({
|
|
3755
3804
|
tokenContract,
|
|
3756
3805
|
tokenId,
|
|
@@ -3760,7 +3809,8 @@ function makePrepareMint1155TokenParams({
|
|
|
3760
3809
|
mintReferral,
|
|
3761
3810
|
mintRecipient,
|
|
3762
3811
|
quantityToMint,
|
|
3763
|
-
allowListEntry
|
|
3812
|
+
allowListEntry,
|
|
3813
|
+
chainId
|
|
3764
3814
|
}) {
|
|
3765
3815
|
const mintQuantity = BigInt(quantityToMint || 1);
|
|
3766
3816
|
const mintTo = mintRecipientOrAccount({ mintRecipient, minterAccount });
|
|
@@ -3779,21 +3829,16 @@ function makePrepareMint1155TokenParams({
|
|
|
3779
3829
|
});
|
|
3780
3830
|
}
|
|
3781
3831
|
if (saleType === "timed") {
|
|
3782
|
-
return
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
tokenContract,
|
|
3793
|
-
BigInt(tokenId),
|
|
3794
|
-
mintReferral || zeroAddress3,
|
|
3795
|
-
mintComment || ""
|
|
3796
|
-
]
|
|
3832
|
+
return makeZoraTimedSaleStrategyMintCall({
|
|
3833
|
+
minterAccount,
|
|
3834
|
+
salesConfigAndTokenInfo,
|
|
3835
|
+
mintQuantity,
|
|
3836
|
+
mintTo,
|
|
3837
|
+
tokenContract,
|
|
3838
|
+
tokenId,
|
|
3839
|
+
mintReferral,
|
|
3840
|
+
mintComment,
|
|
3841
|
+
chainId
|
|
3797
3842
|
});
|
|
3798
3843
|
}
|
|
3799
3844
|
if (saleType === "erc20") {
|
|
@@ -3958,7 +4003,8 @@ async function getMint({
|
|
|
3958
4003
|
params,
|
|
3959
4004
|
mintGetter,
|
|
3960
4005
|
premintGetter,
|
|
3961
|
-
publicClient
|
|
4006
|
+
publicClient,
|
|
4007
|
+
chainId
|
|
3962
4008
|
}) {
|
|
3963
4009
|
const { tokenContract } = params;
|
|
3964
4010
|
if (isOnChainMint(params)) {
|
|
@@ -3970,7 +4016,7 @@ async function getMint({
|
|
|
3970
4016
|
preferredSaleType: params.preferredSaleType,
|
|
3971
4017
|
blockTime
|
|
3972
4018
|
});
|
|
3973
|
-
return toMintableReturn(result);
|
|
4019
|
+
return toMintableReturn(result, chainId);
|
|
3974
4020
|
}
|
|
3975
4021
|
const premint = await premintGetter.get({
|
|
3976
4022
|
collectionAddress: tokenContract,
|
|
@@ -4008,11 +4054,12 @@ async function getMintsOfContract({
|
|
|
4008
4054
|
params,
|
|
4009
4055
|
mintGetter,
|
|
4010
4056
|
premintGetter,
|
|
4011
|
-
publicClient
|
|
4057
|
+
publicClient,
|
|
4058
|
+
chainId
|
|
4012
4059
|
}) {
|
|
4013
4060
|
const onchainMints = (await mintGetter.getContractMintable({
|
|
4014
4061
|
tokenAddress: params.tokenContract
|
|
4015
|
-
})).map(toMintableReturn);
|
|
4062
|
+
})).map((result) => toMintableReturn(result, chainId));
|
|
4016
4063
|
const offchainMints = await getPremintsOfContractMintable({
|
|
4017
4064
|
mintGetter,
|
|
4018
4065
|
premintGetter,
|
|
@@ -4129,14 +4176,15 @@ function parsePremint({
|
|
|
4129
4176
|
}
|
|
4130
4177
|
throw new Error("Invalid premint config version");
|
|
4131
4178
|
}
|
|
4132
|
-
var makeOnchainPrepareMint = (result) => (params) => {
|
|
4179
|
+
var makeOnchainPrepareMint = (result, chainId) => (params) => {
|
|
4133
4180
|
if (!result.salesConfig) {
|
|
4134
4181
|
throw new Error("No valid sales config found for token");
|
|
4135
4182
|
}
|
|
4136
4183
|
return {
|
|
4137
4184
|
parameters: makeOnchainMintCall({
|
|
4138
4185
|
token: result,
|
|
4139
|
-
mintParams: params
|
|
4186
|
+
mintParams: params,
|
|
4187
|
+
chainId
|
|
4140
4188
|
}),
|
|
4141
4189
|
erc20Approval: getRequiredErc20Approvals(params, result.salesConfig),
|
|
4142
4190
|
costs: parseMintCosts({
|
|
@@ -4146,7 +4194,7 @@ var makeOnchainPrepareMint = (result) => (params) => {
|
|
|
4146
4194
|
})
|
|
4147
4195
|
};
|
|
4148
4196
|
};
|
|
4149
|
-
function toMintableReturn(result) {
|
|
4197
|
+
function toMintableReturn(result, chainId) {
|
|
4150
4198
|
const primaryMintActive = result.primaryMintActive;
|
|
4151
4199
|
if (!primaryMintActive) {
|
|
4152
4200
|
return {
|
|
@@ -4162,7 +4210,10 @@ function toMintableReturn(result) {
|
|
|
4162
4210
|
primaryMintActive,
|
|
4163
4211
|
primaryMintEnd: result.primaryMintEnd,
|
|
4164
4212
|
secondaryMarketActive: result.secondaryMarketActive,
|
|
4165
|
-
prepareMint: makeOnchainPrepareMint(
|
|
4213
|
+
prepareMint: makeOnchainPrepareMint(
|
|
4214
|
+
result.salesConfigAndTokenInfo,
|
|
4215
|
+
chainId
|
|
4216
|
+
)
|
|
4166
4217
|
};
|
|
4167
4218
|
}
|
|
4168
4219
|
var makePremintPrepareMint = (mintable, mintFee, premint) => {
|
|
@@ -4225,11 +4276,13 @@ var MintClient = class {
|
|
|
4225
4276
|
constructor({
|
|
4226
4277
|
publicClient,
|
|
4227
4278
|
premintGetter,
|
|
4228
|
-
mintGetter
|
|
4279
|
+
mintGetter,
|
|
4280
|
+
chainId
|
|
4229
4281
|
}) {
|
|
4230
4282
|
this.publicClient = publicClient;
|
|
4231
4283
|
this.mintGetter = mintGetter;
|
|
4232
4284
|
this.premintGetter = premintGetter;
|
|
4285
|
+
this.chainId = chainId;
|
|
4233
4286
|
}
|
|
4234
4287
|
/**
|
|
4235
4288
|
* Returns the parameters needed to prepare a transaction mint a token.
|
|
@@ -4243,7 +4296,8 @@ var MintClient = class {
|
|
|
4243
4296
|
parameters,
|
|
4244
4297
|
publicClient: this.publicClient,
|
|
4245
4298
|
mintGetter: this.mintGetter,
|
|
4246
|
-
premintGetter: this.premintGetter
|
|
4299
|
+
premintGetter: this.premintGetter,
|
|
4300
|
+
chainId: this.chainId
|
|
4247
4301
|
});
|
|
4248
4302
|
}
|
|
4249
4303
|
/**
|
|
@@ -4257,7 +4311,8 @@ var MintClient = class {
|
|
|
4257
4311
|
params: parameters,
|
|
4258
4312
|
mintGetter: this.mintGetter,
|
|
4259
4313
|
premintGetter: this.premintGetter,
|
|
4260
|
-
publicClient: this.publicClient
|
|
4314
|
+
publicClient: this.publicClient,
|
|
4315
|
+
chainId: this.chainId
|
|
4261
4316
|
});
|
|
4262
4317
|
}
|
|
4263
4318
|
/**
|
|
@@ -4271,7 +4326,8 @@ var MintClient = class {
|
|
|
4271
4326
|
params,
|
|
4272
4327
|
mintGetter: this.mintGetter,
|
|
4273
4328
|
premintGetter: this.premintGetter,
|
|
4274
|
-
publicClient: this.publicClient
|
|
4329
|
+
publicClient: this.publicClient,
|
|
4330
|
+
chainId: this.chainId
|
|
4275
4331
|
});
|
|
4276
4332
|
}
|
|
4277
4333
|
/**
|
|
@@ -4292,13 +4348,15 @@ async function mint({
|
|
|
4292
4348
|
parameters,
|
|
4293
4349
|
publicClient,
|
|
4294
4350
|
mintGetter,
|
|
4295
|
-
premintGetter
|
|
4351
|
+
premintGetter,
|
|
4352
|
+
chainId
|
|
4296
4353
|
}) {
|
|
4297
4354
|
const { prepareMint, primaryMintActive } = await getMint({
|
|
4298
4355
|
params: parameters,
|
|
4299
4356
|
mintGetter,
|
|
4300
4357
|
premintGetter,
|
|
4301
|
-
publicClient
|
|
4358
|
+
publicClient,
|
|
4359
|
+
chainId
|
|
4302
4360
|
});
|
|
4303
4361
|
if (!primaryMintActive) {
|
|
4304
4362
|
throw new Error("Primary mint is not active");
|
|
@@ -4860,7 +4918,8 @@ function makeOnchainPrepareMintFromCreate({
|
|
|
4860
4918
|
result,
|
|
4861
4919
|
minter,
|
|
4862
4920
|
getContractMintFee,
|
|
4863
|
-
contractVersion
|
|
4921
|
+
contractVersion,
|
|
4922
|
+
chainId
|
|
4864
4923
|
}) {
|
|
4865
4924
|
return async (params) => {
|
|
4866
4925
|
const subgraphSalesConfig = await toSalesStrategyFromSubgraph({
|
|
@@ -4876,7 +4935,8 @@ function makeOnchainPrepareMintFromCreate({
|
|
|
4876
4935
|
},
|
|
4877
4936
|
...params,
|
|
4878
4937
|
tokenContract: contractAddress,
|
|
4879
|
-
tokenId
|
|
4938
|
+
tokenId,
|
|
4939
|
+
chainId
|
|
4880
4940
|
}),
|
|
4881
4941
|
costs: parseMintCosts({
|
|
4882
4942
|
allowListEntry: params.allowListEntry,
|
|
@@ -5049,7 +5109,8 @@ async function createNew1155ContractAndToken({
|
|
|
5049
5109
|
getContractMintFee: async () => getNewContractMintFee({
|
|
5050
5110
|
publicClient,
|
|
5051
5111
|
chainId
|
|
5052
|
-
})
|
|
5112
|
+
}),
|
|
5113
|
+
chainId
|
|
5053
5114
|
});
|
|
5054
5115
|
return {
|
|
5055
5116
|
parameters: request,
|
|
@@ -5095,7 +5156,8 @@ async function createNew1155Token({
|
|
|
5095
5156
|
minter,
|
|
5096
5157
|
result: newToken.salesConfig,
|
|
5097
5158
|
tokenId: nextTokenId,
|
|
5098
|
-
getContractMintFee: async () => mintFee
|
|
5159
|
+
getContractMintFee: async () => mintFee,
|
|
5160
|
+
chainId
|
|
5099
5161
|
});
|
|
5100
5162
|
return {
|
|
5101
5163
|
parameters: request,
|
|
@@ -5554,7 +5616,10 @@ var getRewardsBalance = async ({
|
|
|
5554
5616
|
// Interface for getting ERC20Z tokens for a creator
|
|
5555
5617
|
}) => {
|
|
5556
5618
|
const address = typeof account === "string" ? account : account.address;
|
|
5557
|
-
const
|
|
5619
|
+
const erc20ZsAndSecondaryActivated = await rewardsGetter.getErc20ZzForCreator(
|
|
5620
|
+
{ address }
|
|
5621
|
+
);
|
|
5622
|
+
const validErc20Zs = erc20ZsAndSecondaryActivated.filter(({ secondaryActivated }) => secondaryActivated).map(({ erc20z }) => erc20z);
|
|
5558
5623
|
const result = await publicClient.multicall({
|
|
5559
5624
|
contracts: [
|
|
5560
5625
|
{
|
|
@@ -5567,7 +5632,7 @@ var getRewardsBalance = async ({
|
|
|
5567
5632
|
address: erc20ZRoyaltiesAddress[chainId],
|
|
5568
5633
|
abi: erc20ZRoyaltiesABI,
|
|
5569
5634
|
functionName: "getUnclaimedFeesBatch",
|
|
5570
|
-
args: [
|
|
5635
|
+
args: [validErc20Zs]
|
|
5571
5636
|
}
|
|
5572
5637
|
],
|
|
5573
5638
|
multicallAddress: multicall3Address,
|
|
@@ -5600,9 +5665,10 @@ var makeClaimSecondaryRoyaltiesCalls = async ({
|
|
|
5600
5665
|
chainId,
|
|
5601
5666
|
rewardsGetter
|
|
5602
5667
|
}) => {
|
|
5603
|
-
const
|
|
5604
|
-
address: claimFor
|
|
5605
|
-
|
|
5668
|
+
const erc20ZsAndSecondaryActivated = await rewardsGetter.getErc20ZzForCreator(
|
|
5669
|
+
{ address: claimFor }
|
|
5670
|
+
);
|
|
5671
|
+
const erc20z = erc20ZsAndSecondaryActivated.filter(({ secondaryActivated }) => secondaryActivated).map(({ erc20z: erc20z2 }) => erc20z2);
|
|
5606
5672
|
const royaltiesAddress = erc20ZRoyaltiesAddress[chainId];
|
|
5607
5673
|
if (erc20z.length === 0) {
|
|
5608
5674
|
return [];
|
|
@@ -5709,6 +5775,7 @@ function buildCreatorERC20zs({
|
|
|
5709
5775
|
}
|
|
5710
5776
|
salesStrategies {
|
|
5711
5777
|
zoraTimedMinter {
|
|
5778
|
+
secondaryActivated
|
|
5712
5779
|
erc20Z {
|
|
5713
5780
|
id
|
|
5714
5781
|
}
|
|
@@ -5729,15 +5796,23 @@ var SubgraphRewardsGetter = class extends SubgraphGetter {
|
|
|
5729
5796
|
constructor(chainId, subgraphQuerier) {
|
|
5730
5797
|
super(chainId, subgraphQuerier);
|
|
5731
5798
|
}
|
|
5732
|
-
async getErc20ZzForCreator({
|
|
5733
|
-
address
|
|
5734
|
-
}) {
|
|
5799
|
+
async getErc20ZzForCreator({ address }) {
|
|
5735
5800
|
const queryResults = await this.querySubgraphWithRetries(
|
|
5736
5801
|
buildCreatorERC20zs({ address })
|
|
5737
5802
|
);
|
|
5738
|
-
|
|
5739
|
-
|
|
5740
|
-
|
|
5803
|
+
const results = (queryResults?.map((result) => {
|
|
5804
|
+
const timedMinter = result.salesStrategies[0].zoraTimedMinter;
|
|
5805
|
+
if (!timedMinter) {
|
|
5806
|
+
return null;
|
|
5807
|
+
}
|
|
5808
|
+
return {
|
|
5809
|
+
secondaryActivated: timedMinter.secondaryActivated,
|
|
5810
|
+
erc20z: timedMinter.erc20Z.id
|
|
5811
|
+
};
|
|
5812
|
+
}) || []).filter(
|
|
5813
|
+
(idAndActivated) => !!idAndActivated
|
|
5814
|
+
);
|
|
5815
|
+
return results;
|
|
5741
5816
|
}
|
|
5742
5817
|
};
|
|
5743
5818
|
|
|
@@ -5747,7 +5822,9 @@ import {
|
|
|
5747
5822
|
secondarySwapAddress,
|
|
5748
5823
|
zoraCreator1155ImplABI as zoraCreator1155ImplABI7,
|
|
5749
5824
|
safeTransferSwapAbiParameters,
|
|
5750
|
-
secondarySwapABI
|
|
5825
|
+
secondarySwapABI,
|
|
5826
|
+
callerAndCommenterABI as callerAndCommenterABI2,
|
|
5827
|
+
callerAndCommenterAddress as callerAndCommenterAddress2
|
|
5751
5828
|
} from "@zoralabs/protocol-deployments";
|
|
5752
5829
|
|
|
5753
5830
|
// src/secondary/uniswap/uniswapQuote.ts
|
|
@@ -6035,10 +6112,13 @@ var ERROR_INSUFFICIENT_WALLET_FUNDS = "Insufficient wallet funds";
|
|
|
6035
6112
|
var ERROR_INSUFFICIENT_POOL_SUPPLY = "Insufficient pool supply";
|
|
6036
6113
|
var ERROR_SECONDARY_NOT_CONFIGURED = "Secondary not configured for given contract and token";
|
|
6037
6114
|
var ERROR_SECONDARY_NOT_STARTED = "Secondary market has not started";
|
|
6115
|
+
var ERROR_RECIPIENT_MISMATCH = "Recipient must be the same as the caller if there is a comment";
|
|
6038
6116
|
function makeError(errorMessage) {
|
|
6039
6117
|
return { error: errorMessage };
|
|
6040
6118
|
}
|
|
6041
6119
|
async function makeBuy({
|
|
6120
|
+
contract,
|
|
6121
|
+
tokenId,
|
|
6042
6122
|
erc20z,
|
|
6043
6123
|
poolBalance,
|
|
6044
6124
|
amount,
|
|
@@ -6047,20 +6127,106 @@ async function makeBuy({
|
|
|
6047
6127
|
recipient,
|
|
6048
6128
|
chainId,
|
|
6049
6129
|
slippage,
|
|
6050
|
-
publicClient
|
|
6130
|
+
publicClient,
|
|
6131
|
+
comment
|
|
6051
6132
|
}) {
|
|
6052
6133
|
const costWithSlippage = calculateSlippageUp(amount, slippage);
|
|
6053
|
-
const availableToBuy = poolBalance.erc20z / BigInt(1e18) - 1n;
|
|
6054
6134
|
const accountAddress = addressOrAccountAddress(account);
|
|
6135
|
+
const validationResult = await validateBuyConditions({
|
|
6136
|
+
poolBalance,
|
|
6137
|
+
quantity,
|
|
6138
|
+
costWithSlippage,
|
|
6139
|
+
accountAddress,
|
|
6140
|
+
publicClient
|
|
6141
|
+
});
|
|
6142
|
+
if (validationResult.error) {
|
|
6143
|
+
return makeError(validationResult.error);
|
|
6144
|
+
}
|
|
6145
|
+
if (comment && comment !== "") {
|
|
6146
|
+
return handleBuyWithComment({
|
|
6147
|
+
accountAddress,
|
|
6148
|
+
recipient,
|
|
6149
|
+
chainId,
|
|
6150
|
+
quantity,
|
|
6151
|
+
contract,
|
|
6152
|
+
tokenId,
|
|
6153
|
+
costWithSlippage,
|
|
6154
|
+
comment,
|
|
6155
|
+
account
|
|
6156
|
+
});
|
|
6157
|
+
}
|
|
6158
|
+
return handleBuyWithoutComment({
|
|
6159
|
+
erc20z,
|
|
6160
|
+
quantity,
|
|
6161
|
+
recipient,
|
|
6162
|
+
accountAddress,
|
|
6163
|
+
costWithSlippage,
|
|
6164
|
+
chainId,
|
|
6165
|
+
account
|
|
6166
|
+
});
|
|
6167
|
+
}
|
|
6168
|
+
async function validateBuyConditions({
|
|
6169
|
+
poolBalance,
|
|
6170
|
+
quantity,
|
|
6171
|
+
costWithSlippage,
|
|
6172
|
+
accountAddress,
|
|
6173
|
+
publicClient
|
|
6174
|
+
}) {
|
|
6175
|
+
const availableToBuy = poolBalance.erc20z / BigInt(1e18) - 1n;
|
|
6055
6176
|
const availableToSpend = await publicClient.getBalance({
|
|
6056
6177
|
address: accountAddress
|
|
6057
6178
|
});
|
|
6058
6179
|
if (costWithSlippage > availableToSpend) {
|
|
6059
|
-
return
|
|
6180
|
+
return { error: ERROR_INSUFFICIENT_WALLET_FUNDS };
|
|
6060
6181
|
}
|
|
6061
6182
|
if (availableToBuy < BigInt(quantity)) {
|
|
6062
|
-
return
|
|
6183
|
+
return { error: ERROR_INSUFFICIENT_POOL_SUPPLY };
|
|
6184
|
+
}
|
|
6185
|
+
return {};
|
|
6186
|
+
}
|
|
6187
|
+
function handleBuyWithComment({
|
|
6188
|
+
accountAddress,
|
|
6189
|
+
recipient,
|
|
6190
|
+
chainId,
|
|
6191
|
+
quantity,
|
|
6192
|
+
contract,
|
|
6193
|
+
tokenId,
|
|
6194
|
+
costWithSlippage,
|
|
6195
|
+
comment,
|
|
6196
|
+
account
|
|
6197
|
+
}) {
|
|
6198
|
+
if (recipient && recipient !== accountAddress) {
|
|
6199
|
+
return makeError(ERROR_RECIPIENT_MISMATCH);
|
|
6063
6200
|
}
|
|
6201
|
+
return {
|
|
6202
|
+
parameters: makeContractParameters({
|
|
6203
|
+
abi: callerAndCommenterABI2,
|
|
6204
|
+
address: callerAndCommenterAddress2[chainId],
|
|
6205
|
+
functionName: "buyOnSecondaryAndComment",
|
|
6206
|
+
args: [
|
|
6207
|
+
accountAddress,
|
|
6208
|
+
quantity,
|
|
6209
|
+
contract,
|
|
6210
|
+
tokenId,
|
|
6211
|
+
accountAddress,
|
|
6212
|
+
costWithSlippage,
|
|
6213
|
+
0n,
|
|
6214
|
+
comment
|
|
6215
|
+
],
|
|
6216
|
+
account,
|
|
6217
|
+
value: costWithSlippage
|
|
6218
|
+
})
|
|
6219
|
+
};
|
|
6220
|
+
}
|
|
6221
|
+
function handleBuyWithoutComment({
|
|
6222
|
+
erc20z,
|
|
6223
|
+
quantity,
|
|
6224
|
+
recipient,
|
|
6225
|
+
accountAddress,
|
|
6226
|
+
costWithSlippage,
|
|
6227
|
+
chainId,
|
|
6228
|
+
account
|
|
6229
|
+
}) {
|
|
6064
6230
|
return {
|
|
6065
6231
|
parameters: makeContractParameters({
|
|
6066
6232
|
abi: secondarySwapABI,
|
|
@@ -6087,7 +6253,8 @@ async function buyWithSlippage({
|
|
|
6087
6253
|
chainId,
|
|
6088
6254
|
account,
|
|
6089
6255
|
slippage = UNISWAP_SLIPPAGE,
|
|
6090
|
-
recipient
|
|
6256
|
+
recipient,
|
|
6257
|
+
comment
|
|
6091
6258
|
}) {
|
|
6092
6259
|
const secondaryInfo = await getSecondaryInfo({
|
|
6093
6260
|
contract,
|
|
@@ -6114,6 +6281,8 @@ async function buyWithSlippage({
|
|
|
6114
6281
|
);
|
|
6115
6282
|
const call = await makeBuy({
|
|
6116
6283
|
erc20z,
|
|
6284
|
+
contract,
|
|
6285
|
+
tokenId,
|
|
6117
6286
|
poolBalance,
|
|
6118
6287
|
amount,
|
|
6119
6288
|
quantity,
|
|
@@ -6121,6 +6290,7 @@ async function buyWithSlippage({
|
|
|
6121
6290
|
recipient,
|
|
6122
6291
|
chainId,
|
|
6123
6292
|
slippage,
|
|
6293
|
+
comment,
|
|
6124
6294
|
publicClient
|
|
6125
6295
|
});
|
|
6126
6296
|
return {
|
|
@@ -6310,7 +6480,8 @@ function createCollectorClient(params) {
|
|
|
6310
6480
|
const mintClient = new MintClient({
|
|
6311
6481
|
publicClient: params.publicClient,
|
|
6312
6482
|
premintGetter: premintGetterToUse,
|
|
6313
|
-
mintGetter: mintGetterToUse
|
|
6483
|
+
mintGetter: mintGetterToUse,
|
|
6484
|
+
chainId: params.chainId
|
|
6314
6485
|
});
|
|
6315
6486
|
const secondaryClient = new SecondaryClient({
|
|
6316
6487
|
publicClient: params.publicClient,
|