forked from getgems-io/nft-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NftAuctionV2.data.ts
156 lines (132 loc) · 5.16 KB
/
NftAuctionV2.data.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import {Address, Builder, Cell, contractAddress, StateInit} from "ton";
import {NftAuctionV2CodeCell} from "./NftAuctionV2.source";
import {NftAuctionData} from "../nft-auction/NftAuction.data";
import BN from "bn.js";
export type NftAuctionV2Data = NftAuctionData
export type NftAuctionV3R2Data = Omit<NftAuctionData, 'minStep'> & {
minPercentStep: number
}
export function buildNftAuctionV3R2DataCell(data: NftAuctionV3R2Data) {
if (data.minPercentStep < 1) {
throw new Error('minPercentStep less 1')
}
if (data.minPercentStep > 100) {
throw new Error('minPercentStep great 1000')
}
return buildNftAuctionV2DataCell({
...data,
minStep: new BN(data.minPercentStep),
})
}
export function buildNftAuctionV2DataCell(data: NftAuctionV2Data) {
const constantCell = new Builder()
const subGasPriceFromBid = 8449000
constantCell.storeUint(subGasPriceFromBid, 32);
constantCell.storeAddress(data.marketplaceAddress);
constantCell.storeCoins(data.minBid)
constantCell.storeCoins(data.maxBid)
constantCell.storeCoins(data.minStep)
constantCell.storeUint(data.stepTimeSeconds, 32) // step_time
constantCell.storeAddress(data.nftAddress);
constantCell.storeUint(data.createdAtTimestamp, 32)
const feesCell = new Builder()
feesCell.storeAddress(data.marketplaceFeeAddress) // mp_fee_addr
feesCell.storeUint(data.marketplaceFeeFactor, 32) // mp_fee_factor
feesCell.storeUint(data.marketplaceFeeBase, 32) // mp_fee_base
feesCell.storeAddress(data.royaltyAddress) // royalty_fee_addr
feesCell.storeUint(data.royaltyFactor, 32) // royalty_fee_factor
feesCell.storeUint(data.royaltyBase, 32) // royalty_fee_base
const storage = new Builder()
storage.storeBit(data.end) // end?
storage.storeBit(data.activated) // activated
storage.storeBit(false) // is_canceled
storage.storeBitArray([0, 0]) // last_member
storage.storeCoins(0) // last_bid
storage.storeUint(0, 32) // last_bid_at
storage.storeUint(data.endTimestamp, 32) // end_time
if (data.nftOwnerAddress) {
storage.storeAddress(data.nftOwnerAddress)
} else {
storage.storeBitArray([0, 0])
}
storage.storeRef(feesCell.endCell())
storage.storeRef(constantCell.endCell())
return storage.endCell()
}
export function buildNftAuctionV2StateInit(data: NftAuctionV2Data) {
let dataCell = buildNftAuctionV2DataCell({
...data,
})
let stateInit = new StateInit({
code: NftAuctionV2CodeCell,
data: dataCell
})
let address = contractAddress({workchain: 0, initialCode: NftAuctionV2CodeCell, initialData: dataCell})
return {
address,
stateInit
}
}
export const Queries = {
stopMessage: () => {
return new Builder().storeUint(0, 32).storeBuffer(Buffer.from('stop')).endCell();
},
cancelMessage: () => {
return new Builder().storeUint(0, 32).storeBuffer(Buffer.from('cancel')).endCell();
},
getStateInitContract: (address: Address, dataCellBase64: string) => {
const dataCellBuffer = Buffer.from(dataCellBase64, 'base64');
const dataCell = Cell.fromBoc(dataCellBuffer)[0];
return {
address: address,
source: {
initialCode: NftAuctionV2CodeCell,
initialData: dataCell,
workchain: 0,
type: 'nft_auction v2',
backup: () => "",
describe: () => "nft_auction v2",
},
}
}
}
export const AuctionV2Queries = Queries
export function buildNftAuctionV3R3DataCell(data: Omit<NftAuctionV3R2Data, 'activated'>) {
if (data.minPercentStep < 1) {
throw new Error('minPercentStep less 1')
}
if (data.minPercentStep > 100) {
throw new Error('minPercentStep great 100')
}
const constantCell = new Builder()
constantCell.storeAddress(data.marketplaceAddress)
constantCell.storeCoins(data.minBid)
constantCell.storeCoins(data.maxBid)
constantCell.storeUint(data.minPercentStep, 7)
constantCell.storeUint(data.stepTimeSeconds, 17) // step_time
constantCell.storeAddress(data.nftAddress)
constantCell.storeUint(data.createdAtTimestamp, 32)
const feesCell = new Builder()
feesCell.storeAddress(data.marketplaceFeeAddress) // mp_fee_addr
feesCell.storeAddress(data.royaltyAddress) // royalty_fee_addr
const storage = new Builder()
storage.storeBit(data.end) // end?
storage.storeBit(false) // is_canceled
storage.storeBitArray([0, 0]) // last_member
storage.storeCoins(0) // last_bid
storage.storeUint(0, 32) // last_bid_at
storage.storeUint(data.endTimestamp, 32) // end_time
if (data.nftOwnerAddress) {
storage.storeAddress(data.nftOwnerAddress)
} else {
storage.storeBitArray([0, 0])
}
storage.storeUint(0, 64) // query_id
storage.storeUint(data.marketplaceFeeFactor, 32) // mp_fee_factor
storage.storeUint(data.marketplaceFeeBase, 32) // mp_fee_base
storage.storeUint(data.royaltyFactor, 32) // royalty_fee_factor
storage.storeUint(data.royaltyBase, 32) // royalty_fee_base
storage.storeRef(feesCell.endCell())
storage.storeRef(constantCell.endCell())
return storage.endCell()
}