@niftykit/redeemable 0.0.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/README.md +21 -0
- package/dist/cjs/src/Redeemable.js +138 -0
- package/dist/cjs/src/index.js +7 -0
- package/dist/cjs/types/redeemable.js +2 -0
- package/dist/esm/src/Redeemable.js +136 -0
- package/dist/esm/src/index.js +2 -0
- package/dist/esm/types/redeemable.js +1 -0
- package/dist/types/src/Redeemable.d.ts +13 -0
- package/dist/types/src/index.d.ts +2 -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 +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Redeemable SDK
|
|
2
|
+
|
|
3
|
+
NiiftyKit Redeemable SDK Library.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
1. Install via npm or yarn
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# with npm
|
|
11
|
+
npm install @niftykit/redeemable
|
|
12
|
+
|
|
13
|
+
# with yarn
|
|
14
|
+
yarn add @niftykit/redeemable
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
2. Import via CDN
|
|
18
|
+
|
|
19
|
+
```html
|
|
20
|
+
<script async src='https://unpkg.com/@niftykit/redeemable/dist/umd/index.js'></script>
|
|
21
|
+
```
|
|
@@ -0,0 +1,138 @@
|
|
|
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 (_) 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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
var typechain_1 = require("@niftykit/contracts/typechain");
|
|
40
|
+
var Redeemable = /** @class */ (function () {
|
|
41
|
+
function Redeemable() {
|
|
42
|
+
this.contract = {};
|
|
43
|
+
}
|
|
44
|
+
Redeemable.prototype.init = function (signerOrProvider, contractAddress) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
46
|
+
return __generator(this, function (_a) {
|
|
47
|
+
this.contract = typechain_1.TokenCollection__factory.connect(contractAddress, signerOrProvider);
|
|
48
|
+
if (!this.contract) {
|
|
49
|
+
throw new Error('Initialization failed.');
|
|
50
|
+
}
|
|
51
|
+
return [2 /*return*/];
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
Redeemable.create = function (signerOrProvider, contractAddress) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
57
|
+
var instance;
|
|
58
|
+
return __generator(this, function (_a) {
|
|
59
|
+
switch (_a.label) {
|
|
60
|
+
case 0:
|
|
61
|
+
instance = new Redeemable();
|
|
62
|
+
return [4 /*yield*/, instance.init(signerOrProvider, contractAddress)];
|
|
63
|
+
case 1:
|
|
64
|
+
_a.sent();
|
|
65
|
+
return [2 /*return*/, instance];
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
Redeemable.prototype.getNFT = function (tokenId) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
72
|
+
var payload;
|
|
73
|
+
return __generator(this, function (_a) {
|
|
74
|
+
switch (_a.label) {
|
|
75
|
+
case 0: return [4 /*yield*/, this.contract.redeemableByIndex(tokenId)];
|
|
76
|
+
case 1:
|
|
77
|
+
payload = _a.sent();
|
|
78
|
+
return [2 /*return*/, {
|
|
79
|
+
index: tokenId,
|
|
80
|
+
tokenURI: payload.uri,
|
|
81
|
+
price: payload.price,
|
|
82
|
+
maxAmount: payload.maxAmount.toNumber(),
|
|
83
|
+
maxPerWallet: payload.maxPerWallet.toNumber(),
|
|
84
|
+
maxPerMint: payload.maxPerMint.toNumber(),
|
|
85
|
+
redeemedCount: payload.redeemedCount.toNumber(),
|
|
86
|
+
merkleRoot: payload.merkleRoot,
|
|
87
|
+
active: payload.active,
|
|
88
|
+
nonce: payload.nonce,
|
|
89
|
+
}];
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
Redeemable.prototype.redeem = function (tokenId, quantity, signature) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
96
|
+
var nft;
|
|
97
|
+
return __generator(this, function (_a) {
|
|
98
|
+
switch (_a.label) {
|
|
99
|
+
case 0: return [4 /*yield*/, this.getNFT(tokenId)];
|
|
100
|
+
case 1:
|
|
101
|
+
nft = _a.sent();
|
|
102
|
+
return [4 /*yield*/, this.contract['redeem(uint256,uint256,bytes)'](nft.index, quantity, signature, {
|
|
103
|
+
value: nft.price.mul(quantity),
|
|
104
|
+
})];
|
|
105
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
Redeemable.prototype.presaleRedeem = function (tokenId, quantity, signature, proof) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
112
|
+
var nft;
|
|
113
|
+
return __generator(this, function (_a) {
|
|
114
|
+
switch (_a.label) {
|
|
115
|
+
case 0: return [4 /*yield*/, this.getNFT(tokenId)];
|
|
116
|
+
case 1:
|
|
117
|
+
nft = _a.sent();
|
|
118
|
+
return [4 /*yield*/, this.contract['redeem(uint256,uint256,bytes,bytes32[])'](nft.index, quantity, signature, proof, {
|
|
119
|
+
value: nft.price.mul(quantity),
|
|
120
|
+
})];
|
|
121
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
Redeemable.prototype.burn = function (tokenId) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
128
|
+
return __generator(this, function (_a) {
|
|
129
|
+
switch (_a.label) {
|
|
130
|
+
case 0: return [4 /*yield*/, this.contract.burn(tokenId)];
|
|
131
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
return Redeemable;
|
|
137
|
+
}());
|
|
138
|
+
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,136 @@
|
|
|
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 (_) 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__factory, } from '@niftykit/contracts/typechain';
|
|
38
|
+
var Redeemable = /** @class */ (function () {
|
|
39
|
+
function Redeemable() {
|
|
40
|
+
this.contract = {};
|
|
41
|
+
}
|
|
42
|
+
Redeemable.prototype.init = function (signerOrProvider, contractAddress) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
44
|
+
return __generator(this, function (_a) {
|
|
45
|
+
this.contract = TokenCollection__factory.connect(contractAddress, signerOrProvider);
|
|
46
|
+
if (!this.contract) {
|
|
47
|
+
throw new Error('Initialization failed.');
|
|
48
|
+
}
|
|
49
|
+
return [2 /*return*/];
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
Redeemable.create = function (signerOrProvider, contractAddress) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
55
|
+
var instance;
|
|
56
|
+
return __generator(this, function (_a) {
|
|
57
|
+
switch (_a.label) {
|
|
58
|
+
case 0:
|
|
59
|
+
instance = new Redeemable();
|
|
60
|
+
return [4 /*yield*/, instance.init(signerOrProvider, contractAddress)];
|
|
61
|
+
case 1:
|
|
62
|
+
_a.sent();
|
|
63
|
+
return [2 /*return*/, instance];
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
Redeemable.prototype.getNFT = function (tokenId) {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
70
|
+
var payload;
|
|
71
|
+
return __generator(this, function (_a) {
|
|
72
|
+
switch (_a.label) {
|
|
73
|
+
case 0: return [4 /*yield*/, this.contract.redeemableByIndex(tokenId)];
|
|
74
|
+
case 1:
|
|
75
|
+
payload = _a.sent();
|
|
76
|
+
return [2 /*return*/, {
|
|
77
|
+
index: tokenId,
|
|
78
|
+
tokenURI: payload.uri,
|
|
79
|
+
price: payload.price,
|
|
80
|
+
maxAmount: payload.maxAmount.toNumber(),
|
|
81
|
+
maxPerWallet: payload.maxPerWallet.toNumber(),
|
|
82
|
+
maxPerMint: payload.maxPerMint.toNumber(),
|
|
83
|
+
redeemedCount: payload.redeemedCount.toNumber(),
|
|
84
|
+
merkleRoot: payload.merkleRoot,
|
|
85
|
+
active: payload.active,
|
|
86
|
+
nonce: payload.nonce,
|
|
87
|
+
}];
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
Redeemable.prototype.redeem = function (tokenId, quantity, signature) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
94
|
+
var nft;
|
|
95
|
+
return __generator(this, function (_a) {
|
|
96
|
+
switch (_a.label) {
|
|
97
|
+
case 0: return [4 /*yield*/, this.getNFT(tokenId)];
|
|
98
|
+
case 1:
|
|
99
|
+
nft = _a.sent();
|
|
100
|
+
return [4 /*yield*/, this.contract['redeem(uint256,uint256,bytes)'](nft.index, quantity, signature, {
|
|
101
|
+
value: nft.price.mul(quantity),
|
|
102
|
+
})];
|
|
103
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
Redeemable.prototype.presaleRedeem = function (tokenId, quantity, signature, proof) {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
110
|
+
var nft;
|
|
111
|
+
return __generator(this, function (_a) {
|
|
112
|
+
switch (_a.label) {
|
|
113
|
+
case 0: return [4 /*yield*/, this.getNFT(tokenId)];
|
|
114
|
+
case 1:
|
|
115
|
+
nft = _a.sent();
|
|
116
|
+
return [4 /*yield*/, this.contract['redeem(uint256,uint256,bytes,bytes32[])'](nft.index, quantity, signature, proof, {
|
|
117
|
+
value: nft.price.mul(quantity),
|
|
118
|
+
})];
|
|
119
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
Redeemable.prototype.burn = function (tokenId) {
|
|
125
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
126
|
+
return __generator(this, function (_a) {
|
|
127
|
+
switch (_a.label) {
|
|
128
|
+
case 0: return [4 /*yield*/, this.contract.burn(tokenId)];
|
|
129
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
return Redeemable;
|
|
135
|
+
}());
|
|
136
|
+
export default Redeemable;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Provider } from '@ethersproject/providers';
|
|
2
|
+
import { TokenCollection } from '@niftykit/contracts/typechain';
|
|
3
|
+
import { ContractTransaction, Signer } from 'ethers';
|
|
4
|
+
import { RedeemableData } from '../types/redeemable';
|
|
5
|
+
export default class Redeemable {
|
|
6
|
+
contract: TokenCollection;
|
|
7
|
+
private init;
|
|
8
|
+
static create(signerOrProvider: Signer | Provider, contractAddress: string): Promise<Redeemable | null>;
|
|
9
|
+
getNFT(tokenId: number): Promise<RedeemableData>;
|
|
10
|
+
redeem(tokenId: number, quantity: number, signature: string): Promise<ContractTransaction>;
|
|
11
|
+
presaleRedeem(tokenId: number, quantity: number, signature: string, proof: string[]): Promise<ContractTransaction>;
|
|
12
|
+
burn(tokenId: number): Promise<ContractTransaction>;
|
|
13
|
+
}
|
|
@@ -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
|
+
}
|