UNPKG

aftermath-ts-sdk

Version:
151 lines (150 loc) 7.93 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.FaucetApi = void 0; const transactions_1 = require("@mysten/sui/transactions"); const faucetApiCasting_1 = require("./faucetApiCasting"); const coin_1 = require("../../coin"); const transactionsApiHelpers_1 = require("../../../general/apiHelpers/transactionsApiHelpers"); const eventsApiHelpers_1 = require("../../../general/apiHelpers/eventsApiHelpers"); const sui_1 = require("../../sui"); class FaucetApi { // ========================================================================= // Constructor // ========================================================================= constructor(Provider) { this.Provider = Provider; // ========================================================================= // Transaction Builders // ========================================================================= this.fetchRequestCustomCoinAmountTx = (inputs) => __awaiter(this, void 0, void 0, function* () { const { walletAddress, coinType, amount } = inputs; const tx = new transactions_1.Transaction(); tx.setSender(walletAddress); this.requestCoinAmountTx({ tx, coinType, amount, }); return tx; }); this.fetchBuildMintSuiFrenTx = (inputs) => __awaiter(this, void 0, void 0, function* () { const { walletAddress, mintFee, suiFrenType } = inputs; const tx = new transactions_1.Transaction(); tx.setSender(walletAddress); const suiPaymentCoinId = yield this.Provider.Coin().fetchCoinWithAmountTx({ tx, walletAddress, coinType: coin_1.Coin.constants.suiCoinType, coinAmount: mintFee, }); this.mintSuiFrenTx({ tx, suiPaymentCoinId, suiFrenType }); return tx; }); // ========================================================================= // Transcation Commands // ========================================================================= this.addCoinTx = (inputs) => { const { tx, treasuryCapId, treasuryCapType } = inputs; return tx.moveCall({ target: transactionsApiHelpers_1.TransactionsApiHelpers.createTxTarget(this.addresses.packages.faucet, FaucetApi.constants.moduleNames.faucet, "add_coin"), typeArguments: [treasuryCapType], arguments: [ tx.object(this.addresses.objects.faucet), tx.object(treasuryCapId), ], }); }; this.requestCoinAmountTx = (inputs) => { const { tx, coinType, amount } = inputs; return tx.moveCall({ target: transactionsApiHelpers_1.TransactionsApiHelpers.createTxTarget(this.addresses.packages.faucet, FaucetApi.constants.moduleNames.faucet, "request_coin_amount"), typeArguments: [coinType], arguments: [ tx.object(this.addresses.objects.faucet), tx.pure.u64(amount), ], }); }; this.requestCoinTx = (inputs) => { const { tx, coinType } = inputs; return tx.moveCall({ target: transactionsApiHelpers_1.TransactionsApiHelpers.createTxTarget(this.addresses.packages.faucet, FaucetApi.constants.moduleNames.faucet, "request_coin"), typeArguments: [coinType], arguments: [tx.object(this.addresses.objects.faucet)], }); }; this.mintSuiFrenTx = (inputs) => { const { tx, suiPaymentCoinId, suiFrenType } = inputs; return tx.moveCall({ target: transactionsApiHelpers_1.TransactionsApiHelpers.createTxTarget(this.addresses.packages.suiFrensGenesisWrapper, FaucetApi.constants.moduleNames.suiFrensGenesisWrapper, "mint_and_keep"), typeArguments: [suiFrenType], arguments: [ tx.object(this.addresses.objects.suiFrensMint), // Mint tx.object(sui_1.Sui.constants.addresses.suiClockId), // Clock typeof suiPaymentCoinId === "string" ? tx.object(suiPaymentCoinId) : suiPaymentCoinId, // Coin ], }); }; // ========================================================================= // Events // ========================================================================= // TODO: add to indexer this.fetchMintCoinEvents = (inputs) => __awaiter(this, void 0, void 0, function* () { return yield this.Provider.Events().fetchCastEventsWithCursor(Object.assign(Object.assign({}, inputs), { query: { MoveEventType: this.eventTypes.mintCoin, }, eventFromEventOnChain: faucetApiCasting_1.FaucetApiCasting.faucetMintCoinEventFromOnChain })); }); // TODO: add to indexer this.fetchAddCoinEvents = (inputs) => __awaiter(this, void 0, void 0, function* () { return yield this.Provider.Events().fetchCastEventsWithCursor(Object.assign(Object.assign({}, inputs), { query: { MoveEventType: this.eventTypes.addCoin, }, eventFromEventOnChain: faucetApiCasting_1.FaucetApiCasting.faucetAddCoinEventFromOnChain })); }); // ========================================================================= // Private Methods // ========================================================================= // ========================================================================= // Event Types // ========================================================================= this.mintCoinEventType = () => { return eventsApiHelpers_1.EventsApiHelpers.createEventType(this.addresses.packages.faucet, FaucetApi.constants.moduleNames.faucet, FaucetApi.constants.eventNames.mintCoin); }; this.addCoinEventType = () => { return eventsApiHelpers_1.EventsApiHelpers.createEventType(this.addresses.packages.faucet, FaucetApi.constants.moduleNames.faucet, FaucetApi.constants.eventNames.addCoin); }; const addresses = this.Provider.addresses.faucet; if (!addresses) throw new Error("not all required addresses have been set in provider"); this.addresses = addresses; this.eventTypes = { mintCoin: this.mintCoinEventType(), addCoin: this.addCoinEventType(), }; } } exports.FaucetApi = FaucetApi; // ========================================================================= // Constants // ========================================================================= FaucetApi.constants = { moduleNames: { faucet: "faucet", faucetRegistry: "faucet_registry", suiFrensGenesisWrapper: "genesis_wrapper", }, eventNames: { mintCoin: "MintedCoin", addCoin: "AddedCoinEvent", }, };