@zoralabs/protocol-sdk 0.11.4 → 0.11.6-COMMENTS.0
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 +32 -0
- package/dist/create/mint-from-create.d.ts +2 -1
- package/dist/create/mint-from-create.d.ts.map +1 -1
- package/dist/create/minter-defaults.d.ts.map +1 -1
- package/dist/create/types.d.ts +1 -0
- package/dist/create/types.d.ts.map +1 -1
- package/dist/index.cjs +235 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +239 -58
- 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/sdk.d.ts.map +1 -1
- package/dist/secondary/secondary-client.d.ts +4 -3
- package/dist/secondary/secondary-client.d.ts.map +1 -1
- package/dist/secondary/types.d.ts +7 -0
- package/dist/secondary/types.d.ts.map +1 -1
- package/dist/secondary/utils.d.ts.map +1 -1
- package/dist/test-utils.d.ts +3 -1
- package/dist/test-utils.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/comments/comments.test.ts +342 -0
- package/src/create/1155-create-helper.test.ts +77 -14
- package/src/create/1155-create-helper.ts +2 -0
- package/src/create/mint-from-create.ts +3 -0
- package/src/create/minter-defaults.ts +22 -8
- package/src/create/types.ts +5 -3
- 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/sdk.ts +1 -0
- package/src/secondary/secondary-client.test.ts +149 -25
- package/src/secondary/secondary-client.ts +138 -7
- package/src/secondary/types.ts +19 -4
- package/src/secondary/utils.ts +30 -10
- package/src/sparks/sparks-sponsored-sparks-spender.test.ts +1 -1
- package/src/test-utils.ts +12 -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");
|
|
@@ -4414,19 +4472,27 @@ var parseNameIntoSymbol = (name) => {
|
|
|
4414
4472
|
}
|
|
4415
4473
|
return result;
|
|
4416
4474
|
};
|
|
4475
|
+
var getMinimumMarketEth = (params) => {
|
|
4476
|
+
if (params.minimumMintsForCountdown) {
|
|
4477
|
+
return params.minimumMintsForCountdown * parseEther3("0.0000111");
|
|
4478
|
+
}
|
|
4479
|
+
return params.minimumMarketEth || DEFAULT_MINIMUM_MARKET_ETH;
|
|
4480
|
+
};
|
|
4417
4481
|
var timedSaleSettingsWithDefaults = (params, contractName) => {
|
|
4418
4482
|
const erc20Name = params.erc20Name || contractName;
|
|
4419
|
-
const
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4483
|
+
const minimumMarketEth = getMinimumMarketEth({
|
|
4484
|
+
minimumMarketEth: params.minimumMarketEth,
|
|
4485
|
+
minimumMintsForCountdown: params.minimumMintsForCountdown
|
|
4486
|
+
});
|
|
4487
|
+
const minimumMintsForCountdown = minimumMarketEth / parseEther3("0.0000111");
|
|
4423
4488
|
return {
|
|
4424
4489
|
type: "timed",
|
|
4425
4490
|
erc20Name,
|
|
4426
|
-
erc20Symbol:
|
|
4427
|
-
saleStart:
|
|
4428
|
-
marketCountdown:
|
|
4429
|
-
minimumMarketEth
|
|
4491
|
+
erc20Symbol: params.erc20Symbol || parseNameIntoSymbol(erc20Name),
|
|
4492
|
+
saleStart: params.saleStart || 0n,
|
|
4493
|
+
marketCountdown: params.marketCountdown || DEFAULT_MARKET_COUNTDOWN,
|
|
4494
|
+
minimumMarketEth,
|
|
4495
|
+
minimumMintsForCountdown
|
|
4430
4496
|
};
|
|
4431
4497
|
};
|
|
4432
4498
|
var isAllowList = (salesConfig) => salesConfig.type === "allowlistMint";
|
|
@@ -4852,7 +4918,8 @@ function makeOnchainPrepareMintFromCreate({
|
|
|
4852
4918
|
result,
|
|
4853
4919
|
minter,
|
|
4854
4920
|
getContractMintFee,
|
|
4855
|
-
contractVersion
|
|
4921
|
+
contractVersion,
|
|
4922
|
+
chainId
|
|
4856
4923
|
}) {
|
|
4857
4924
|
return async (params) => {
|
|
4858
4925
|
const subgraphSalesConfig = await toSalesStrategyFromSubgraph({
|
|
@@ -4868,7 +4935,8 @@ function makeOnchainPrepareMintFromCreate({
|
|
|
4868
4935
|
},
|
|
4869
4936
|
...params,
|
|
4870
4937
|
tokenContract: contractAddress,
|
|
4871
|
-
tokenId
|
|
4938
|
+
tokenId,
|
|
4939
|
+
chainId
|
|
4872
4940
|
}),
|
|
4873
4941
|
costs: parseMintCosts({
|
|
4874
4942
|
allowListEntry: params.allowListEntry,
|
|
@@ -5041,7 +5109,8 @@ async function createNew1155ContractAndToken({
|
|
|
5041
5109
|
getContractMintFee: async () => getNewContractMintFee({
|
|
5042
5110
|
publicClient,
|
|
5043
5111
|
chainId
|
|
5044
|
-
})
|
|
5112
|
+
}),
|
|
5113
|
+
chainId
|
|
5045
5114
|
});
|
|
5046
5115
|
return {
|
|
5047
5116
|
parameters: request,
|
|
@@ -5087,7 +5156,8 @@ async function createNew1155Token({
|
|
|
5087
5156
|
minter,
|
|
5088
5157
|
result: newToken.salesConfig,
|
|
5089
5158
|
tokenId: nextTokenId,
|
|
5090
|
-
getContractMintFee: async () => mintFee
|
|
5159
|
+
getContractMintFee: async () => mintFee,
|
|
5160
|
+
chainId
|
|
5091
5161
|
});
|
|
5092
5162
|
return {
|
|
5093
5163
|
parameters: request,
|
|
@@ -5739,7 +5809,9 @@ import {
|
|
|
5739
5809
|
secondarySwapAddress,
|
|
5740
5810
|
zoraCreator1155ImplABI as zoraCreator1155ImplABI7,
|
|
5741
5811
|
safeTransferSwapAbiParameters,
|
|
5742
|
-
secondarySwapABI
|
|
5812
|
+
secondarySwapABI,
|
|
5813
|
+
callerAndCommenterABI as callerAndCommenterABI2,
|
|
5814
|
+
callerAndCommenterAddress as callerAndCommenterAddress2
|
|
5743
5815
|
} from "@zoralabs/protocol-deployments";
|
|
5744
5816
|
|
|
5745
5817
|
// src/secondary/uniswap/uniswapQuote.ts
|
|
@@ -5979,6 +6051,7 @@ function calculateSlippageDown(amount, slippage) {
|
|
|
5979
6051
|
}
|
|
5980
6052
|
|
|
5981
6053
|
// src/secondary/utils.ts
|
|
6054
|
+
import { parseEther as parseEther5 } from "viem";
|
|
5982
6055
|
import {
|
|
5983
6056
|
zoraTimedSaleStrategyABI as zoraTimedSaleStrategyABI3,
|
|
5984
6057
|
zoraTimedSaleStrategyAddress as zoraTimedSaleStrategyAddress2
|
|
@@ -5989,12 +6062,18 @@ async function getSecondaryInfo({
|
|
|
5989
6062
|
publicClient,
|
|
5990
6063
|
chainId
|
|
5991
6064
|
}) {
|
|
5992
|
-
|
|
5993
|
-
|
|
5994
|
-
|
|
5995
|
-
|
|
5996
|
-
|
|
5997
|
-
|
|
6065
|
+
let result;
|
|
6066
|
+
try {
|
|
6067
|
+
result = await publicClient.readContract({
|
|
6068
|
+
abi: zoraTimedSaleStrategyABI3,
|
|
6069
|
+
address: zoraTimedSaleStrategyAddress2[chainId],
|
|
6070
|
+
functionName: "saleV2",
|
|
6071
|
+
args: [contract, tokenId]
|
|
6072
|
+
});
|
|
6073
|
+
} catch (e) {
|
|
6074
|
+
console.error(e);
|
|
6075
|
+
return void 0;
|
|
6076
|
+
}
|
|
5998
6077
|
if (!result.erc20zAddress) {
|
|
5999
6078
|
return void 0;
|
|
6000
6079
|
}
|
|
@@ -6002,7 +6081,15 @@ async function getSecondaryInfo({
|
|
|
6002
6081
|
erc20z: result.erc20zAddress,
|
|
6003
6082
|
pool: result.poolAddress,
|
|
6004
6083
|
secondaryActivated: result.secondaryActivated,
|
|
6005
|
-
saleEnd: result.saleEnd === 0n ? void 0 : result.saleEnd
|
|
6084
|
+
saleEnd: result.saleEnd === 0n ? void 0 : result.saleEnd,
|
|
6085
|
+
saleStart: result.saleStart,
|
|
6086
|
+
name: result.name,
|
|
6087
|
+
symbol: result.symbol,
|
|
6088
|
+
marketCountdown: result.marketCountdown === 0n ? void 0 : result.marketCountdown,
|
|
6089
|
+
minimumMintsForCountdown: result.minimumMarketEth === 0n ? void 0 : result.minimumMarketEth / parseEther5("0.0000111"),
|
|
6090
|
+
mintCount: await publicClient.getBalance({
|
|
6091
|
+
address: result.erc20zAddress
|
|
6092
|
+
}) / parseEther5("0.0000111")
|
|
6006
6093
|
};
|
|
6007
6094
|
}
|
|
6008
6095
|
|
|
@@ -6012,10 +6099,13 @@ var ERROR_INSUFFICIENT_WALLET_FUNDS = "Insufficient wallet funds";
|
|
|
6012
6099
|
var ERROR_INSUFFICIENT_POOL_SUPPLY = "Insufficient pool supply";
|
|
6013
6100
|
var ERROR_SECONDARY_NOT_CONFIGURED = "Secondary not configured for given contract and token";
|
|
6014
6101
|
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";
|
|
6015
6103
|
function makeError(errorMessage) {
|
|
6016
6104
|
return { error: errorMessage };
|
|
6017
6105
|
}
|
|
6018
6106
|
async function makeBuy({
|
|
6107
|
+
contract,
|
|
6108
|
+
tokenId,
|
|
6019
6109
|
erc20z,
|
|
6020
6110
|
poolBalance,
|
|
6021
6111
|
amount,
|
|
@@ -6024,20 +6114,106 @@ async function makeBuy({
|
|
|
6024
6114
|
recipient,
|
|
6025
6115
|
chainId,
|
|
6026
6116
|
slippage,
|
|
6027
|
-
publicClient
|
|
6117
|
+
publicClient,
|
|
6118
|
+
comment
|
|
6028
6119
|
}) {
|
|
6029
6120
|
const costWithSlippage = calculateSlippageUp(amount, slippage);
|
|
6030
|
-
const availableToBuy = poolBalance.erc20z / BigInt(1e18) - 1n;
|
|
6031
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
|
+
publicClient
|
|
6161
|
+
}) {
|
|
6162
|
+
const availableToBuy = poolBalance.erc20z / BigInt(1e18) - 1n;
|
|
6032
6163
|
const availableToSpend = await publicClient.getBalance({
|
|
6033
6164
|
address: accountAddress
|
|
6034
6165
|
});
|
|
6035
6166
|
if (costWithSlippage > availableToSpend) {
|
|
6036
|
-
return
|
|
6167
|
+
return { error: ERROR_INSUFFICIENT_WALLET_FUNDS };
|
|
6037
6168
|
}
|
|
6038
6169
|
if (availableToBuy < BigInt(quantity)) {
|
|
6039
|
-
return
|
|
6170
|
+
return { error: ERROR_INSUFFICIENT_POOL_SUPPLY };
|
|
6040
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);
|
|
6187
|
+
}
|
|
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
|
+
}) {
|
|
6041
6217
|
return {
|
|
6042
6218
|
parameters: makeContractParameters({
|
|
6043
6219
|
abi: secondarySwapABI,
|
|
@@ -6064,7 +6240,8 @@ async function buyWithSlippage({
|
|
|
6064
6240
|
chainId,
|
|
6065
6241
|
account,
|
|
6066
6242
|
slippage = UNISWAP_SLIPPAGE,
|
|
6067
|
-
recipient
|
|
6243
|
+
recipient,
|
|
6244
|
+
comment
|
|
6068
6245
|
}) {
|
|
6069
6246
|
const secondaryInfo = await getSecondaryInfo({
|
|
6070
6247
|
contract,
|
|
@@ -6091,6 +6268,8 @@ async function buyWithSlippage({
|
|
|
6091
6268
|
);
|
|
6092
6269
|
const call = await makeBuy({
|
|
6093
6270
|
erc20z,
|
|
6271
|
+
contract,
|
|
6272
|
+
tokenId,
|
|
6094
6273
|
poolBalance,
|
|
6095
6274
|
amount,
|
|
6096
6275
|
quantity,
|
|
@@ -6098,6 +6277,7 @@ async function buyWithSlippage({
|
|
|
6098
6277
|
recipient,
|
|
6099
6278
|
chainId,
|
|
6100
6279
|
slippage,
|
|
6280
|
+
comment,
|
|
6101
6281
|
publicClient
|
|
6102
6282
|
});
|
|
6103
6283
|
return {
|
|
@@ -6287,7 +6467,8 @@ function createCollectorClient(params) {
|
|
|
6287
6467
|
const mintClient = new MintClient({
|
|
6288
6468
|
publicClient: params.publicClient,
|
|
6289
6469
|
premintGetter: premintGetterToUse,
|
|
6290
|
-
mintGetter: mintGetterToUse
|
|
6470
|
+
mintGetter: mintGetterToUse,
|
|
6471
|
+
chainId: params.chainId
|
|
6291
6472
|
});
|
|
6292
6473
|
const secondaryClient = new SecondaryClient({
|
|
6293
6474
|
publicClient: params.publicClient,
|