This repository has been archived by the owner on Aug 23, 2021. It is now read-only.
forked from rahuldamodar94/marketplace-contract
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fillerc721.js
executable file
·187 lines (166 loc) · 5.16 KB
/
fillerc721.js
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
let {
ContractWrappers,
ERC20TokenContract,
ERC721TokenContract,
OrderStatus,
} = require("@0x/contract-wrappers");
let { providerEngine } = require("./provider_engine");
let {
assetDataUtils,
generatePseudoRandomSalt,
signatureUtils,
} = require("@0x/order-utils");
let { BigNumber } = require("@0x/utils");
let { NETWORK_CONFIGS } = require("./configs");
let { exchangeDataEncoder } = require("@0x/contracts-exchange");
let {
DECIMALS,
UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
NULL_ADDRESS,
NULL_BYTES,
ZERO,
} = require("./constants");
let { Web3Wrapper } = require("@0x/web3-wrapper");
let utils = require("./utils");
// let dummyERC721TokenContracts = require('./contracts');
(async () => {
const contractWrappers = new ContractWrappers(providerEngine(), {
chainId: NETWORK_CONFIGS.chainId,
});
const web3Wrapper = new Web3Wrapper(providerEngine());
const [
maker,
taker2,
taker,
taker4,
taker5,
] = await web3Wrapper.getAvailableAddressesAsync();
const TestBTokenAddress = "0x8CF293247CBFB38cB6474d5f9cE64Dda7db974bc".toLowerCase();
const TestCTokenAddress = "0x927d909Cda7cD9Fee03f9481210907A3cB51781a".toLowerCase();
const takerAssetAmount = new BigNumber(1);
const makerAssetAmount = Web3Wrapper.toBaseUnitAmount(
new BigNumber(40),
DECIMALS
);
const takerAssetData = await contractWrappers.devUtils
.encodeERC721AssetData(
TestBTokenAddress,
new BigNumber(
"105045125714244168733981138770329276532473093455428486030848904550754377656049"
)
)
.callAsync();
const makerAssetData = await contractWrappers.devUtils
.encodeERC20AssetData(TestCTokenAddress)
.callAsync();
// let txHash;
// // ERC721
// const erc721Token = new ERC721TokenContract(
// TestCTokenAddress,
// providerEngine()
// );
// const isApprovedForAll = await erc721Token
// .isApprovedForAll(maker, contractWrappers.contractAddresses.erc721Proxy)
// .callAsync();
// console.log(isApprovedForAll);
// const makerERC721ApprovalTxHash = await erc721Token
// .setApprovalForAll(contractWrappers.contractAddresses.erc721Proxy, true)
// .sendTransactionAsync({ from: maker, gas: 8000000, gasPrice: 1000000000 });
// console.log(makerERC721ApprovalTxHash);
// // ERC20
// const erc20Token = new ERC20TokenContract(
// TestBTokenAddress,
// providerEngine()
// );
// let balance = await erc20Token.balanceOf(taker).callAsync();
// console.log(balance);
// let allowance = await erc20Token
// .allowance(taker, contractWrappers.contractAddresses.erc20Proxy)
// .callAsync();
// console.log(allowance);
// const takerTestBApprovalTxHash = await erc20Token
// .approve(
// contractWrappers.contractAddresses.erc20Proxy,
// UNLIMITED_ALLOWANCE_IN_BASE_UNITS
// )
// .sendTransactionAsync({ from: taker, gas: 8000000 });
// console.log(takerTestBApprovalTxHash);
// Set up the Order and fill it
const randomExpiration = utils.getRandomFutureDateInSeconds();
const exchangeAddress = contractWrappers.contractAddresses.exchange;
// Create the order
const order = {
chainId: NETWORK_CONFIGS.chainId,
exchangeAddress,
makerAddress: taker,
takerAddress: NULL_ADDRESS,
senderAddress: taker4,
feeRecipientAddress: NULL_ADDRESS,
expirationTimeSeconds: parseInt(randomExpiration) + 1000000000,
salt: generatePseudoRandomSalt(),
makerAssetAmount,
takerAssetAmount,
makerAssetData,
takerAssetData,
makerFeeAssetData: NULL_BYTES,
takerFeeAssetData: NULL_BYTES,
makerFee: ZERO,
takerFee: ZERO,
};
const signedOrder = await signatureUtils.ecSignOrderAsync(
providerEngine(),
order,
taker
);
let zrx = {
salt: generatePseudoRandomSalt(),
expirationTimeSeconds: parseInt(randomExpiration) + 1000000000,
gasPrice: 10000000000,
signerAddress: taker,
data: exchangeDataEncoder.encodeOrdersToExchangeData("cancelOrder", [
signedOrder,
]),
domain: {
name: "0x Protocol",
version: "3.0.0",
chainId: 80001,
verifyingContract: contractWrappers.contractAddresses.exchange,
},
};
const takerSign = await signatureUtils.ecSignTransactionAsync(
providerEngine(),
zrx,
taker
);
const [
{ orderStatus },
remainingFillableAmount,
isValidSignature,
] = await contractWrappers.devUtils
.getOrderRelevantState(signedOrder, signedOrder.signature)
.callAsync();
if (
orderStatus === OrderStatus.Fillable &&
remainingFillableAmount.isGreaterThan(0) &&
isValidSignature
) {
console.log("Fillable");
} else {
console.log("Not fillable");
}
console.log(JSON.stringify(signedOrder));
console.log("##################################");
console.log(JSON.stringify(takerSign));
// txHash = await contractWrappers.exchange
// .executeTransaction(takerSign, takerSign.signature)
// .awaitTransactionSuccessAsync({
// from: taker4,
// gas: 8000000,
// gasPrice: 10000000000,
// value: utils.calculateProtocolFee([signedOrder]),
// });
// console.log(txHash);
// providerEngine().stop();
})().catch((err) => {
console.log("!!!!!!!!!!!!!!!!!!!", err);
});