@credenza3/contracts-lib-sui 0.0.4 → 0.0.6

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.
@@ -1720,7 +1720,7 @@ var CredenzaSuiClient = (function () {
1720
1720
  this.prepareModules();
1721
1721
  }
1722
1722
  CredenzaSuiClient.createSigner = function (pk) {
1723
- return ed25519_1.Ed25519Keypair.fromSecretKey((0, utils_1.fromBase64)(pk).slice(1));
1723
+ return ed25519_1.Ed25519Keypair.fromSecretKey((0, utils_1.fromB64)(pk).slice(1));
1724
1724
  };
1725
1725
  CredenzaSuiClient.prototype.prepareModules = function () {
1726
1726
  for (var module in modules) {
@@ -1831,9 +1831,46 @@ var __extends = (this && this.__extends) || (function () {
1831
1831
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1832
1832
  };
1833
1833
  })();
1834
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1835
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1836
+ return new (P || (P = Promise))(function (resolve, reject) {
1837
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
1838
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
1839
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
1840
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
1841
+ });
1842
+ };
1843
+ var __generator = (this && this.__generator) || function (thisArg, body) {
1844
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
1845
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
1846
+ function verb(n) { return function (v) { return step([n, v]); }; }
1847
+ function step(op) {
1848
+ if (f) throw new TypeError("Generator is already executing.");
1849
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
1850
+ 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;
1851
+ if (y = 0, t) op = [op[0] & 2, t.value];
1852
+ switch (op[0]) {
1853
+ case 0: case 1: t = op; break;
1854
+ case 4: _.label++; return { value: op[1], done: false };
1855
+ case 5: _.label++; y = op[1]; op = [0]; continue;
1856
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
1857
+ default:
1858
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
1859
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
1860
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
1861
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
1862
+ if (t[2]) _.ops.pop();
1863
+ _.trys.pop(); continue;
1864
+ }
1865
+ op = body.call(thisArg, _);
1866
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
1867
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
1868
+ }
1869
+ };
1834
1870
  Object.defineProperty(exports, "__esModule", ({ value: true }));
1835
1871
  exports.CRED = void 0;
1836
1872
  var CredenzaSuiModule_1 = __webpack_require__(1090);
1873
+ var transactions_1 = __webpack_require__(1218);
1837
1874
  var CRED = (function (_super) {
1838
1875
  __extends(CRED, _super);
1839
1876
  function CRED() {
@@ -1842,11 +1879,312 @@ var CRED = (function (_super) {
1842
1879
  CRED.prototype.getCredType = function () {
1843
1880
  return "".concat(this.client.getPackageId(), "::cred::CRED");
1844
1881
  };
1882
+ CRED.prototype.mint = function (target, amount) {
1883
+ return __awaiter(this, void 0, Promise, function () {
1884
+ var treasury, tx;
1885
+ return __generator(this, function (_a) {
1886
+ switch (_a.label) {
1887
+ case 0: return [4, this.getTreasuryCap()];
1888
+ case 1:
1889
+ treasury = _a.sent();
1890
+ tx = new transactions_1.Transaction();
1891
+ tx.moveCall({
1892
+ target: "0x02::coin::mint_and_transfer",
1893
+ arguments: [tx.object(treasury), tx.pure.u64(amount), tx.pure.address(target)],
1894
+ typeArguments: [this.getCredType()],
1895
+ });
1896
+ return [4, this.client.signAndExecuteTransaction(tx)];
1897
+ case 2: return [2, _a.sent()];
1898
+ }
1899
+ });
1900
+ });
1901
+ };
1902
+ CRED.prototype.getTreasuryCap = function () {
1903
+ return __awaiter(this, void 0, Promise, function () {
1904
+ var res;
1905
+ var _a, _b, _c;
1906
+ return __generator(this, function (_d) {
1907
+ switch (_d.label) {
1908
+ case 0: return [4, this.client.suiClient.getOwnedObjects({
1909
+ owner: this.client.getSignerAddress(),
1910
+ filter: {
1911
+ StructType: "0x2::coin::TreasuryCap<".concat(this.getCredType(), ">"),
1912
+ },
1913
+ })];
1914
+ case 1:
1915
+ res = _d.sent();
1916
+ return [2, (_c = (_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a['0']) === null || _b === void 0 ? void 0 : _b.data.objectId) !== null && _c !== void 0 ? _c : null];
1917
+ }
1918
+ });
1919
+ });
1920
+ };
1845
1921
  return CRED;
1846
1922
  }(CredenzaSuiModule_1.CredenzaSuiModule));
1847
1923
  exports.CRED = CRED;
1848
1924
 
1849
1925
 
1926
+ /***/ }),
1927
+
1928
+ /***/ 816:
1929
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
1930
+
1931
+ "use strict";
1932
+
1933
+ var __extends = (this && this.__extends) || (function () {
1934
+ var extendStatics = function (d, b) {
1935
+ extendStatics = Object.setPrototypeOf ||
1936
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
1937
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
1938
+ return extendStatics(d, b);
1939
+ };
1940
+ return function (d, b) {
1941
+ if (typeof b !== "function" && b !== null)
1942
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
1943
+ extendStatics(d, b);
1944
+ function __() { this.constructor = d; }
1945
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1946
+ };
1947
+ })();
1948
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1949
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1950
+ return new (P || (P = Promise))(function (resolve, reject) {
1951
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
1952
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
1953
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
1954
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
1955
+ });
1956
+ };
1957
+ var __generator = (this && this.__generator) || function (thisArg, body) {
1958
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
1959
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
1960
+ function verb(n) { return function (v) { return step([n, v]); }; }
1961
+ function step(op) {
1962
+ if (f) throw new TypeError("Generator is already executing.");
1963
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
1964
+ 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;
1965
+ if (y = 0, t) op = [op[0] & 2, t.value];
1966
+ switch (op[0]) {
1967
+ case 0: case 1: t = op; break;
1968
+ case 4: _.label++; return { value: op[1], done: false };
1969
+ case 5: _.label++; y = op[1]; op = [0]; continue;
1970
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
1971
+ default:
1972
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
1973
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
1974
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
1975
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
1976
+ if (t[2]) _.ops.pop();
1977
+ _.trys.pop(); continue;
1978
+ }
1979
+ op = body.call(thisArg, _);
1980
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
1981
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
1982
+ }
1983
+ };
1984
+ var __importDefault = (this && this.__importDefault) || function (mod) {
1985
+ return (mod && mod.__esModule) ? mod : { "default": mod };
1986
+ };
1987
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
1988
+ exports.CredenzaAirdrop = void 0;
1989
+ var CredenzaSuiModule_1 = __webpack_require__(1090);
1990
+ var transactions_1 = __webpack_require__(1218);
1991
+ var get_1 = __importDefault(__webpack_require__(644));
1992
+ var CredenzaAirdrop = (function (_super) {
1993
+ __extends(CredenzaAirdrop, _super);
1994
+ function CredenzaAirdrop() {
1995
+ return _super !== null && _super.apply(this, arguments) || this;
1996
+ }
1997
+ CredenzaAirdrop.prototype.getCreatedConfigs = function () {
1998
+ return __awaiter(this, void 0, Promise, function () {
1999
+ var events, res, _i, _a, event;
2000
+ return __generator(this, function (_b) {
2001
+ switch (_b.label) {
2002
+ case 0: return [4, this.client.suiClient.queryEvents({
2003
+ query: {
2004
+ MoveEventType: "".concat(this.client.getPackageId(), "::credenza_airdrop::CredenzaAirdropConfigCreatedEvent"),
2005
+ },
2006
+ })];
2007
+ case 1:
2008
+ events = _b.sent();
2009
+ res = [];
2010
+ for (_i = 0, _a = events.data; _i < _a.length; _i++) {
2011
+ event = _a[_i];
2012
+ res.push((0, get_1.default)(event, 'parsedJson.id'));
2013
+ }
2014
+ return [2, res];
2015
+ }
2016
+ });
2017
+ });
2018
+ };
2019
+ CredenzaAirdrop.prototype.createConfig = function () {
2020
+ return __awaiter(this, void 0, Promise, function () {
2021
+ var tx;
2022
+ return __generator(this, function (_a) {
2023
+ tx = new transactions_1.Transaction();
2024
+ tx.moveCall({
2025
+ target: "".concat(this.client.getPackageId(), "::credenza_airdrop::create_config"),
2026
+ arguments: [],
2027
+ });
2028
+ return [2, this.client.signAndExecuteTransaction(tx)];
2029
+ });
2030
+ });
2031
+ };
2032
+ CredenzaAirdrop.prototype.setDropPerAddressLimit = function (configId, limit) {
2033
+ return __awaiter(this, void 0, Promise, function () {
2034
+ var tx;
2035
+ return __generator(this, function (_a) {
2036
+ tx = new transactions_1.Transaction();
2037
+ tx.moveCall({
2038
+ target: "".concat(this.client.getPackageId(), "::credenza_airdrop::set_drop_per_address_limit"),
2039
+ arguments: [tx.object(configId), tx.pure.u64(limit)],
2040
+ });
2041
+ return [2, this.client.signAndExecuteTransaction(tx)];
2042
+ });
2043
+ });
2044
+ };
2045
+ CredenzaAirdrop.prototype.setCoin = function (configId, coinId) {
2046
+ return __awaiter(this, void 0, Promise, function () {
2047
+ var coin, coinType, oldCoinType, tx;
2048
+ var _a;
2049
+ return __generator(this, function (_b) {
2050
+ switch (_b.label) {
2051
+ case 0: return [4, this.client.suiClient.getObject({ id: coinId, options: { showContent: true } })];
2052
+ case 1:
2053
+ coin = _b.sent();
2054
+ coinType = (_a = (0, get_1.default)(coin, 'data.content.type')) === null || _a === void 0 ? void 0 : _a.split('<')[1].split('>')[0];
2055
+ return [4, this.getAirdropCoinType(configId)];
2056
+ case 2:
2057
+ oldCoinType = _b.sent();
2058
+ if (!oldCoinType) {
2059
+ oldCoinType = coinType;
2060
+ }
2061
+ tx = new transactions_1.Transaction();
2062
+ tx.moveCall({
2063
+ target: "".concat(this.client.getPackageId(), "::credenza_airdrop::set_coin"),
2064
+ arguments: [tx.object(configId), tx.object(coinId)],
2065
+ typeArguments: [oldCoinType, coinType],
2066
+ });
2067
+ return [2, this.client.signAndExecuteTransaction(tx)];
2068
+ }
2069
+ });
2070
+ });
2071
+ };
2072
+ CredenzaAirdrop.prototype.setCollectionAsset = function (configId, assetId) {
2073
+ return __awaiter(this, void 0, Promise, function () {
2074
+ var tx;
2075
+ return __generator(this, function (_a) {
2076
+ tx = new transactions_1.Transaction();
2077
+ tx.moveCall({
2078
+ target: "".concat(this.client.getPackageId(), "::credenza_airdrop::set_asset"),
2079
+ arguments: [tx.object(configId), tx.object(assetId)],
2080
+ typeArguments: [],
2081
+ });
2082
+ return [2, this.client.signAndExecuteTransaction(tx)];
2083
+ });
2084
+ });
2085
+ };
2086
+ CredenzaAirdrop.prototype.getAirdropCoinType = function (configId) {
2087
+ return __awaiter(this, void 0, Promise, function () {
2088
+ var config, fieldData, _i, _a, item;
2089
+ var _b, _c;
2090
+ return __generator(this, function (_d) {
2091
+ switch (_d.label) {
2092
+ case 0: return [4, this.client.suiClient.getObject({ id: configId, options: { showContent: true } })];
2093
+ case 1:
2094
+ config = _d.sent();
2095
+ if (!parseInt((0, get_1.default)(config, 'data.content.fields.items.fields.size'))) return [3, 3];
2096
+ return [4, this.client.suiClient.getDynamicFields({
2097
+ parentId: (0, get_1.default)(config, 'data.content.fields.items.fields.id.id'),
2098
+ })];
2099
+ case 2:
2100
+ fieldData = _d.sent();
2101
+ for (_i = 0, _a = fieldData.data; _i < _a.length; _i++) {
2102
+ item = _a[_i];
2103
+ if (((_b = item === null || item === void 0 ? void 0 : item.name) === null || _b === void 0 ? void 0 : _b.type) === '0x2::object::ID') {
2104
+ return [2, (_c = item.objectType.split('<')[1].split('>')[0]) !== null && _c !== void 0 ? _c : null];
2105
+ }
2106
+ }
2107
+ _d.label = 3;
2108
+ case 3: return [2, null];
2109
+ }
2110
+ });
2111
+ });
2112
+ };
2113
+ CredenzaAirdrop.prototype.getAirdropAssetType = function (configId) {
2114
+ return __awaiter(this, void 0, Promise, function () {
2115
+ var config, fieldData, _i, _a, item;
2116
+ var _b, _c;
2117
+ return __generator(this, function (_d) {
2118
+ switch (_d.label) {
2119
+ case 0: return [4, this.client.suiClient.getObject({ id: configId, options: { showContent: true } })];
2120
+ case 1:
2121
+ config = _d.sent();
2122
+ if (!parseInt((0, get_1.default)(config, 'data.content.fields.items.fields.size'))) return [3, 3];
2123
+ return [4, this.client.suiClient.getDynamicFields({
2124
+ parentId: (0, get_1.default)(config, 'data.content.fields.items.fields.id.id'),
2125
+ })];
2126
+ case 2:
2127
+ fieldData = _d.sent();
2128
+ for (_i = 0, _a = fieldData.data; _i < _a.length; _i++) {
2129
+ item = _a[_i];
2130
+ if (((_b = item === null || item === void 0 ? void 0 : item.name) === null || _b === void 0 ? void 0 : _b.type) !== '0x2::object::ID') {
2131
+ return [2, (_c = item.objectType) !== null && _c !== void 0 ? _c : null];
2132
+ }
2133
+ }
2134
+ _d.label = 3;
2135
+ case 3: return [2, null];
2136
+ }
2137
+ });
2138
+ });
2139
+ };
2140
+ CredenzaAirdrop.prototype.requestCoin = function (configId, amount) {
2141
+ return __awaiter(this, void 0, Promise, function () {
2142
+ var coinType, tx;
2143
+ return __generator(this, function (_a) {
2144
+ switch (_a.label) {
2145
+ case 0: return [4, this.getAirdropCoinType(configId)];
2146
+ case 1:
2147
+ coinType = _a.sent();
2148
+ if (!coinType) {
2149
+ throw new Error("This config does not have coin to drop setup");
2150
+ }
2151
+ tx = new transactions_1.Transaction();
2152
+ tx.moveCall({
2153
+ target: "".concat(this.client.getPackageId(), "::credenza_airdrop::request_coin"),
2154
+ arguments: [tx.object(configId), tx.pure.u64(amount)],
2155
+ typeArguments: [coinType],
2156
+ });
2157
+ return [2, this.client.signAndExecuteTransaction(tx)];
2158
+ }
2159
+ });
2160
+ });
2161
+ };
2162
+ CredenzaAirdrop.prototype.requestAsset = function (configId, assetId, amount) {
2163
+ return __awaiter(this, void 0, Promise, function () {
2164
+ var assetType, tx;
2165
+ return __generator(this, function (_a) {
2166
+ switch (_a.label) {
2167
+ case 0: return [4, this.getAirdropAssetType(configId)];
2168
+ case 1:
2169
+ assetType = _a.sent();
2170
+ if (!assetType) {
2171
+ throw new Error("This config does not have coin to drop setup");
2172
+ }
2173
+ tx = new transactions_1.Transaction();
2174
+ tx.moveCall({
2175
+ target: "".concat(this.client.getPackageId(), "::credenza_airdrop::request_asset"),
2176
+ arguments: [tx.object(configId), tx.pure.u64(assetId), tx.pure.u64(amount)],
2177
+ });
2178
+ return [2, this.client.signAndExecuteTransaction(tx)];
2179
+ }
2180
+ });
2181
+ });
2182
+ };
2183
+ return CredenzaAirdrop;
2184
+ }(CredenzaSuiModule_1.CredenzaSuiModule));
2185
+ exports.CredenzaAirdrop = CredenzaAirdrop;
2186
+
2187
+
1850
2188
  /***/ }),
1851
2189
 
1852
2190
  /***/ 5909:
@@ -2408,6 +2746,27 @@ var CredenzaAssetCollection = (function (_super) {
2408
2746
  });
2409
2747
  });
2410
2748
  };
2749
+ CredenzaAssetCollection.prototype.getOwners = function () {
2750
+ return __awaiter(this, void 0, Promise, function () {
2751
+ var collectionCapId, res, collectionCap, _i, _a, field;
2752
+ return __generator(this, function (_b) {
2753
+ switch (_b.label) {
2754
+ case 0: return [4, this.getCollectionCap()];
2755
+ case 1:
2756
+ collectionCapId = _b.sent();
2757
+ res = [];
2758
+ return [4, this.client.suiClient.getObject({ id: collectionCapId, options: { showContent: true } })];
2759
+ case 2:
2760
+ collectionCap = _b.sent();
2761
+ for (_i = 0, _a = (0, get_1.default)(collectionCap, 'data.content.fields.ownership.fields.owners.fields.contents'); _i < _a.length; _i++) {
2762
+ field = _a[_i];
2763
+ res.push(field);
2764
+ }
2765
+ return [2, res];
2766
+ }
2767
+ });
2768
+ });
2769
+ };
2411
2770
  return CredenzaAssetCollection;
2412
2771
  }(CredenzaSuiModule_1.CredenzaSuiModule));
2413
2772
  exports.CredenzaAssetCollection = CredenzaAssetCollection;
@@ -3692,7 +4051,7 @@ exports.Sellable = Sellable;
3692
4051
  "use strict";
3693
4052
 
3694
4053
  Object.defineProperty(exports, "__esModule", ({ value: true }));
3695
- exports.CredenzaAssetCollection = exports.Sellable = exports.CredenzaDecom = exports.CredenzaMembership = exports.CredenzaLedger = exports.CRED = void 0;
4054
+ exports.CredenzaAirdrop = exports.CredenzaAssetCollection = exports.Sellable = exports.CredenzaDecom = exports.CredenzaMembership = exports.CredenzaLedger = exports.CRED = void 0;
3696
4055
  var CRED_1 = __webpack_require__(1235);
3697
4056
  Object.defineProperty(exports, "CRED", ({ enumerable: true, get: function () { return CRED_1.CRED; } }));
3698
4057
  var CredenzaLedger_1 = __webpack_require__(6160);
@@ -3705,6 +4064,8 @@ var Sellable_1 = __webpack_require__(5111);
3705
4064
  Object.defineProperty(exports, "Sellable", ({ enumerable: true, get: function () { return Sellable_1.Sellable; } }));
3706
4065
  var CredenzaAssetCollection_1 = __webpack_require__(5909);
3707
4066
  Object.defineProperty(exports, "CredenzaAssetCollection", ({ enumerable: true, get: function () { return CredenzaAssetCollection_1.CredenzaAssetCollection; } }));
4067
+ var CredenzaAirdrop_1 = __webpack_require__(816);
4068
+ Object.defineProperty(exports, "CredenzaAirdrop", ({ enumerable: true, get: function () { return CredenzaAirdrop_1.CredenzaAirdrop; } }));
3708
4069
 
3709
4070
 
3710
4071
  /***/ }),