@niftykit/redeemable 0.0.11 → 0.1.1
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/LICENSE +21 -0
- package/dist/cjs/Redeemable.js +185 -0
- package/dist/cjs/config/endpoint.js +5 -0
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/types/api-responses.js +2 -0
- package/dist/cjs/types/redeemable.js +2 -0
- package/dist/esm/Redeemable.js +180 -0
- package/dist/esm/config/endpoint.js +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/types/api-responses.js +1 -0
- package/dist/esm/types/redeemable.js +1 -0
- package/dist/types/Redeemable.d.ts +17 -0
- package/dist/types/config/endpoint.d.ts +2 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/types/api-responses.d.ts +6 -0
- package/dist/types/types/redeemable.d.ts +13 -0
- package/dist/umd/index.js +2 -0
- package/dist/umd/index.js.LICENSE.txt +8 -0
- package/package.json +5 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 NiftyKit Inc. (niftykit.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
var contracts_1 = require("@niftykit/contracts");
|
|
43
|
+
var axios_1 = __importDefault(require("axios"));
|
|
44
|
+
var ethers_1 = require("ethers");
|
|
45
|
+
var endpoint_1 = require("./config/endpoint");
|
|
46
|
+
var Redeemable = /** @class */ (function () {
|
|
47
|
+
function Redeemable(isDev) {
|
|
48
|
+
this.contract = {};
|
|
49
|
+
this.version = 1;
|
|
50
|
+
this.isDev = isDev;
|
|
51
|
+
}
|
|
52
|
+
Object.defineProperty(Redeemable.prototype, "apiBaseUrl", {
|
|
53
|
+
get: function () {
|
|
54
|
+
return this.isDev ? endpoint_1.API_ENDPOINT_DEV : endpoint_1.API_ENDPOINT;
|
|
55
|
+
},
|
|
56
|
+
enumerable: false,
|
|
57
|
+
configurable: true
|
|
58
|
+
});
|
|
59
|
+
Redeemable.prototype.init = function (signerOrProvider, contractAddress) {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
61
|
+
var url, resp;
|
|
62
|
+
return __generator(this, function (_a) {
|
|
63
|
+
switch (_a.label) {
|
|
64
|
+
case 0:
|
|
65
|
+
if (!ethers_1.ethers.utils.isAddress(contractAddress)) {
|
|
66
|
+
throw new Error('Invalid contract address.');
|
|
67
|
+
}
|
|
68
|
+
url = "".concat(this.apiBaseUrl, "/v2/redeemables/").concat(contractAddress);
|
|
69
|
+
return [4 /*yield*/, axios_1.default.get(url, {
|
|
70
|
+
validateStatus: function (status) { return status < 500; },
|
|
71
|
+
})];
|
|
72
|
+
case 1:
|
|
73
|
+
resp = _a.sent();
|
|
74
|
+
if (resp.status !== 200) {
|
|
75
|
+
throw new Error('Something went wrong.');
|
|
76
|
+
}
|
|
77
|
+
this.version = resp.data.version;
|
|
78
|
+
this.contract =
|
|
79
|
+
this.version > 1
|
|
80
|
+
? contracts_1.TokenCollection__factoryV2.connect(contractAddress, signerOrProvider)
|
|
81
|
+
: contracts_1.TokenCollection__factory.connect(contractAddress, signerOrProvider);
|
|
82
|
+
if (!this.contract) {
|
|
83
|
+
throw new Error('Initialization failed.');
|
|
84
|
+
}
|
|
85
|
+
return [2 /*return*/];
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
Redeemable.create = function (signerOrProvider, contractAddress, isDev) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
92
|
+
var instance;
|
|
93
|
+
return __generator(this, function (_a) {
|
|
94
|
+
switch (_a.label) {
|
|
95
|
+
case 0:
|
|
96
|
+
instance = new Redeemable(isDev);
|
|
97
|
+
return [4 /*yield*/, instance.init(signerOrProvider, contractAddress)];
|
|
98
|
+
case 1:
|
|
99
|
+
_a.sent();
|
|
100
|
+
return [2 /*return*/, instance];
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
Redeemable.prototype.getRedeemable = function (tokenId) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
107
|
+
var payload, _a;
|
|
108
|
+
return __generator(this, function (_b) {
|
|
109
|
+
switch (_b.label) {
|
|
110
|
+
case 0:
|
|
111
|
+
if (!(this.version > 1)) return [3 /*break*/, 2];
|
|
112
|
+
return [4 /*yield*/, this.contract.redeemableAt(tokenId)];
|
|
113
|
+
case 1:
|
|
114
|
+
_a = _b.sent();
|
|
115
|
+
return [3 /*break*/, 4];
|
|
116
|
+
case 2: return [4 /*yield*/, this.contract.redeemableByIndex(tokenId)];
|
|
117
|
+
case 3:
|
|
118
|
+
_a = _b.sent();
|
|
119
|
+
_b.label = 4;
|
|
120
|
+
case 4:
|
|
121
|
+
payload = _a;
|
|
122
|
+
return [2 /*return*/, {
|
|
123
|
+
index: tokenId,
|
|
124
|
+
tokenURI: payload[0],
|
|
125
|
+
price: payload.price,
|
|
126
|
+
maxAmount: payload[3].toNumber(),
|
|
127
|
+
maxPerWallet: payload.maxPerWallet.toNumber(),
|
|
128
|
+
maxPerMint: payload.maxPerMint.toNumber(),
|
|
129
|
+
redeemedCount: payload.redeemedCount.toNumber(),
|
|
130
|
+
merkleRoot: payload.merkleRoot,
|
|
131
|
+
active: payload.active,
|
|
132
|
+
nonce: payload.nonce,
|
|
133
|
+
}];
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
Redeemable.prototype.redeem = function (tokenId, quantity, signature) {
|
|
139
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
140
|
+
var nft;
|
|
141
|
+
return __generator(this, function (_a) {
|
|
142
|
+
switch (_a.label) {
|
|
143
|
+
case 0: return [4 /*yield*/, this.getRedeemable(tokenId)];
|
|
144
|
+
case 1:
|
|
145
|
+
nft = _a.sent();
|
|
146
|
+
if (!(this.version > 1)) return [3 /*break*/, 3];
|
|
147
|
+
return [4 /*yield*/, this.contract.redeem(nft.index, quantity, signature, [], {
|
|
148
|
+
value: nft.price.mul(quantity),
|
|
149
|
+
})];
|
|
150
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
151
|
+
case 3: return [4 /*yield*/, this.contract['redeem(uint256,uint256,bytes)'](nft.index, quantity, signature, {
|
|
152
|
+
value: nft.price.mul(quantity),
|
|
153
|
+
})];
|
|
154
|
+
case 4: return [2 /*return*/, _a.sent()];
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
Redeemable.prototype.presaleRedeem = function (tokenId, quantity, signature, proof) {
|
|
160
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
161
|
+
var nft;
|
|
162
|
+
return __generator(this, function (_a) {
|
|
163
|
+
switch (_a.label) {
|
|
164
|
+
case 0: return [4 /*yield*/, this.getRedeemable(tokenId)];
|
|
165
|
+
case 1:
|
|
166
|
+
nft = _a.sent();
|
|
167
|
+
if (!(this.version > 1)) return [3 /*break*/, 3];
|
|
168
|
+
return [4 /*yield*/, this.contract.redeem(nft.index, quantity, signature, proof, {
|
|
169
|
+
value: nft.price.mul(quantity),
|
|
170
|
+
})];
|
|
171
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
172
|
+
case 3: return [4 /*yield*/, this.contract['redeem(uint256,uint256,bytes,bytes32[])'](nft.index, quantity, signature, proof, {
|
|
173
|
+
value: nft.price.mul(quantity),
|
|
174
|
+
})];
|
|
175
|
+
case 4: return [2 /*return*/, _a.sent()];
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
Redeemable.prototype.burn = function (tokenId) {
|
|
181
|
+
return this.contract.burn(tokenId);
|
|
182
|
+
};
|
|
183
|
+
return Redeemable;
|
|
184
|
+
}());
|
|
185
|
+
exports.default = Redeemable;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var Redeemable_1 = __importDefault(require("./Redeemable"));
|
|
7
|
+
exports.default = Redeemable_1.default;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import { TokenCollection__factoryV2, TokenCollection__factory, } from '@niftykit/contracts';
|
|
38
|
+
import axios from 'axios';
|
|
39
|
+
import { ethers } from 'ethers';
|
|
40
|
+
import { API_ENDPOINT, API_ENDPOINT_DEV } from './config/endpoint';
|
|
41
|
+
var Redeemable = /** @class */ (function () {
|
|
42
|
+
function Redeemable(isDev) {
|
|
43
|
+
this.contract = {};
|
|
44
|
+
this.version = 1;
|
|
45
|
+
this.isDev = isDev;
|
|
46
|
+
}
|
|
47
|
+
Object.defineProperty(Redeemable.prototype, "apiBaseUrl", {
|
|
48
|
+
get: function () {
|
|
49
|
+
return this.isDev ? API_ENDPOINT_DEV : API_ENDPOINT;
|
|
50
|
+
},
|
|
51
|
+
enumerable: false,
|
|
52
|
+
configurable: true
|
|
53
|
+
});
|
|
54
|
+
Redeemable.prototype.init = function (signerOrProvider, contractAddress) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
+
var url, resp;
|
|
57
|
+
return __generator(this, function (_a) {
|
|
58
|
+
switch (_a.label) {
|
|
59
|
+
case 0:
|
|
60
|
+
if (!ethers.utils.isAddress(contractAddress)) {
|
|
61
|
+
throw new Error('Invalid contract address.');
|
|
62
|
+
}
|
|
63
|
+
url = "".concat(this.apiBaseUrl, "/v2/redeemables/").concat(contractAddress);
|
|
64
|
+
return [4 /*yield*/, axios.get(url, {
|
|
65
|
+
validateStatus: function (status) { return status < 500; },
|
|
66
|
+
})];
|
|
67
|
+
case 1:
|
|
68
|
+
resp = _a.sent();
|
|
69
|
+
if (resp.status !== 200) {
|
|
70
|
+
throw new Error('Something went wrong.');
|
|
71
|
+
}
|
|
72
|
+
this.version = resp.data.version;
|
|
73
|
+
this.contract =
|
|
74
|
+
this.version > 1
|
|
75
|
+
? TokenCollection__factoryV2.connect(contractAddress, signerOrProvider)
|
|
76
|
+
: TokenCollection__factory.connect(contractAddress, signerOrProvider);
|
|
77
|
+
if (!this.contract) {
|
|
78
|
+
throw new Error('Initialization failed.');
|
|
79
|
+
}
|
|
80
|
+
return [2 /*return*/];
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
Redeemable.create = function (signerOrProvider, contractAddress, isDev) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
87
|
+
var instance;
|
|
88
|
+
return __generator(this, function (_a) {
|
|
89
|
+
switch (_a.label) {
|
|
90
|
+
case 0:
|
|
91
|
+
instance = new Redeemable(isDev);
|
|
92
|
+
return [4 /*yield*/, instance.init(signerOrProvider, contractAddress)];
|
|
93
|
+
case 1:
|
|
94
|
+
_a.sent();
|
|
95
|
+
return [2 /*return*/, instance];
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
Redeemable.prototype.getRedeemable = function (tokenId) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
102
|
+
var payload, _a;
|
|
103
|
+
return __generator(this, function (_b) {
|
|
104
|
+
switch (_b.label) {
|
|
105
|
+
case 0:
|
|
106
|
+
if (!(this.version > 1)) return [3 /*break*/, 2];
|
|
107
|
+
return [4 /*yield*/, this.contract.redeemableAt(tokenId)];
|
|
108
|
+
case 1:
|
|
109
|
+
_a = _b.sent();
|
|
110
|
+
return [3 /*break*/, 4];
|
|
111
|
+
case 2: return [4 /*yield*/, this.contract.redeemableByIndex(tokenId)];
|
|
112
|
+
case 3:
|
|
113
|
+
_a = _b.sent();
|
|
114
|
+
_b.label = 4;
|
|
115
|
+
case 4:
|
|
116
|
+
payload = _a;
|
|
117
|
+
return [2 /*return*/, {
|
|
118
|
+
index: tokenId,
|
|
119
|
+
tokenURI: payload[0],
|
|
120
|
+
price: payload.price,
|
|
121
|
+
maxAmount: payload[3].toNumber(),
|
|
122
|
+
maxPerWallet: payload.maxPerWallet.toNumber(),
|
|
123
|
+
maxPerMint: payload.maxPerMint.toNumber(),
|
|
124
|
+
redeemedCount: payload.redeemedCount.toNumber(),
|
|
125
|
+
merkleRoot: payload.merkleRoot,
|
|
126
|
+
active: payload.active,
|
|
127
|
+
nonce: payload.nonce,
|
|
128
|
+
}];
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
Redeemable.prototype.redeem = function (tokenId, quantity, signature) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
135
|
+
var nft;
|
|
136
|
+
return __generator(this, function (_a) {
|
|
137
|
+
switch (_a.label) {
|
|
138
|
+
case 0: return [4 /*yield*/, this.getRedeemable(tokenId)];
|
|
139
|
+
case 1:
|
|
140
|
+
nft = _a.sent();
|
|
141
|
+
if (!(this.version > 1)) return [3 /*break*/, 3];
|
|
142
|
+
return [4 /*yield*/, this.contract.redeem(nft.index, quantity, signature, [], {
|
|
143
|
+
value: nft.price.mul(quantity),
|
|
144
|
+
})];
|
|
145
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
146
|
+
case 3: return [4 /*yield*/, this.contract['redeem(uint256,uint256,bytes)'](nft.index, quantity, signature, {
|
|
147
|
+
value: nft.price.mul(quantity),
|
|
148
|
+
})];
|
|
149
|
+
case 4: return [2 /*return*/, _a.sent()];
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
Redeemable.prototype.presaleRedeem = function (tokenId, quantity, signature, proof) {
|
|
155
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
156
|
+
var nft;
|
|
157
|
+
return __generator(this, function (_a) {
|
|
158
|
+
switch (_a.label) {
|
|
159
|
+
case 0: return [4 /*yield*/, this.getRedeemable(tokenId)];
|
|
160
|
+
case 1:
|
|
161
|
+
nft = _a.sent();
|
|
162
|
+
if (!(this.version > 1)) return [3 /*break*/, 3];
|
|
163
|
+
return [4 /*yield*/, this.contract.redeem(nft.index, quantity, signature, proof, {
|
|
164
|
+
value: nft.price.mul(quantity),
|
|
165
|
+
})];
|
|
166
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
167
|
+
case 3: return [4 /*yield*/, this.contract['redeem(uint256,uint256,bytes,bytes32[])'](nft.index, quantity, signature, proof, {
|
|
168
|
+
value: nft.price.mul(quantity),
|
|
169
|
+
})];
|
|
170
|
+
case 4: return [2 /*return*/, _a.sent()];
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
Redeemable.prototype.burn = function (tokenId) {
|
|
176
|
+
return this.contract.burn(tokenId);
|
|
177
|
+
};
|
|
178
|
+
return Redeemable;
|
|
179
|
+
}());
|
|
180
|
+
export default Redeemable;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Provider } from '@ethersproject/providers';
|
|
2
|
+
import { TokenCollection, TokenCollectionV2 } from '@niftykit/contracts';
|
|
3
|
+
import { ContractTransaction, Signer } from 'ethers';
|
|
4
|
+
import { RedeemableData } from './types/redeemable';
|
|
5
|
+
export default class Redeemable {
|
|
6
|
+
contract: TokenCollection | TokenCollectionV2;
|
|
7
|
+
isDev?: boolean;
|
|
8
|
+
version: number;
|
|
9
|
+
private get apiBaseUrl();
|
|
10
|
+
constructor(isDev?: boolean);
|
|
11
|
+
private init;
|
|
12
|
+
static create(signerOrProvider: Signer | Provider, contractAddress: string, isDev?: boolean): Promise<Redeemable | null>;
|
|
13
|
+
getRedeemable(tokenId: number): Promise<RedeemableData>;
|
|
14
|
+
redeem(tokenId: number, quantity: number, signature: string): Promise<ContractTransaction>;
|
|
15
|
+
presaleRedeem(tokenId: number, quantity: number, signature: string, proof: string[]): Promise<ContractTransaction>;
|
|
16
|
+
burn(tokenId: number): Promise<ContractTransaction>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
export interface RedeemableData {
|
|
3
|
+
index: number;
|
|
4
|
+
tokenURI: string;
|
|
5
|
+
price: ethers.BigNumber;
|
|
6
|
+
maxAmount: number;
|
|
7
|
+
maxPerWallet: number;
|
|
8
|
+
maxPerMint: number;
|
|
9
|
+
redeemedCount: number;
|
|
10
|
+
merkleRoot: string;
|
|
11
|
+
active: boolean;
|
|
12
|
+
nonce: ethers.BigNumber;
|
|
13
|
+
}
|