@0xsplits/splits-sdk
Version:
SDK for the 0xSplits protocol
931 lines (930 loc) • 78 kB
JavaScript
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
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());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
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);
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
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;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SplitV2Client = void 0;
var viem_1 = require("viem");
var constants_1 = require("../constants");
var splitV2_1 = require("../constants/abi/splitV2");
var splitV2Factory_1 = require("../constants/abi/splitV2Factory");
var errors_1 = require("../errors");
var types_1 = require("../types");
var utils_1 = require("../utils");
var base_1 = require("./base");
var mixin_1 = require("./mixin");
var abi_1 = require("../constants/abi");
var VALID_ERC1271_SIG = '0x1626ba7e';
// TODO:add validation to execute contract function
var SplitV2Transactions = /** @class */ (function (_super) {
__extends(SplitV2Transactions, _super);
function SplitV2Transactions(transactionClientArgs) {
return _super.call(this, __assign({ supportedChainIds: constants_1.SPLITS_V2_SUPPORTED_CHAIN_IDS }, transactionClientArgs)) || this;
}
SplitV2Transactions.prototype._createSplit = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var _c, recipientAddresses, recipientAllocations, distributionIncentive, totalAllocation, functionChainId, functionName, functionArgs;
var recipients = _b.recipients, distributorFeePercent = _b.distributorFeePercent, totalAllocationPercent = _b.totalAllocationPercent, _d = _b.splitType, splitType = _d === void 0 ? types_1.SplitV2Type.Pull : _d, _e = _b.ownerAddress, controllerAddress = _e === void 0 ? viem_1.zeroAddress : _e, _f = _b.creatorAddress, creatorAddress = _f === void 0 ? viem_1.zeroAddress : _f, salt = _b.salt, chainId = _b.chainId, _g = _b.transactionOverrides, transactionOverrides = _g === void 0 ? {} : _g, _h = _b.v2Type, v2Type = _h === void 0 ? 'splitV2o1' : _h;
return __generator(this, function (_j) {
_c = (0, utils_1.getValidatedSplitV2Config)(recipients, distributorFeePercent, totalAllocationPercent), recipientAddresses = _c.recipientAddresses, recipientAllocations = _c.recipientAllocations, distributionIncentive = _c.distributionIncentive, totalAllocation = _c.totalAllocation;
recipientAddresses.map(function (recipient) { return (0, utils_1.validateAddress)(recipient); });
(0, utils_1.validateAddress)(controllerAddress);
(0, utils_1.validateAddress)(creatorAddress);
if (this._shouldRequireWalletClient)
this._requireWalletClient();
functionChainId = this._getFunctionChainId(chainId);
functionName = salt ? 'createSplitDeterministic' : 'createSplit';
functionArgs = [
{
recipients: recipientAddresses,
allocations: recipientAllocations,
totalAllocation: totalAllocation,
distributionIncentive: distributionIncentive,
},
controllerAddress,
creatorAddress,
];
if (salt)
functionArgs.push(salt);
return [2 /*return*/, this._executeContractFunction({
contractAddress: v2Type === 'splitV2o1'
? (0, constants_1.getSplitV2o1FactoryAddress)(functionChainId, splitType)
: (0, constants_1.getSplitV2FactoryAddress)(functionChainId, splitType),
contractAbi: abi_1.splitV2o1FactoryAbi,
functionName: functionName,
functionArgs: functionArgs,
transactionOverrides: transactionOverrides,
})];
});
});
};
SplitV2Transactions.prototype._transferOwnership = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var splitAddress = _b.splitAddress, newController = _b.newOwner, _c = _b.transactionOverrides, transactionOverrides = _c === void 0 ? {} : _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
(0, utils_1.validateAddress)(splitAddress);
(0, utils_1.validateAddress)(newController);
if (this._shouldRequireWalletClient)
this._requireWalletClient();
return [4 /*yield*/, this._requireOwner(splitAddress)];
case 1:
_d.sent();
return [2 /*return*/, this._executeContractFunction({
contractAddress: splitAddress,
contractAbi: splitV2_1.splitV2ABI,
functionName: 'transferOwnership',
functionArgs: [newController],
transactionOverrides: transactionOverrides,
})];
}
});
});
};
SplitV2Transactions.prototype._setPaused = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var splitAddress = _b.splitAddress, paused = _b.paused, _c = _b.transactionOverrides, transactionOverrides = _c === void 0 ? {} : _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
(0, utils_1.validateAddress)(splitAddress);
if (this._shouldRequireWalletClient)
this._requireWalletClient();
return [4 /*yield*/, this._requireOwner(splitAddress)];
case 1:
_d.sent();
return [2 /*return*/, this._executeContractFunction({
contractAddress: splitAddress,
contractAbi: splitV2_1.splitV2ABI,
functionName: 'setPaused',
functionArgs: [paused],
transactionOverrides: transactionOverrides,
})];
}
});
});
};
SplitV2Transactions.prototype._execCalls = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var splitAddress = _b.splitAddress, calls = _b.calls, _c = _b.transactionOverrides, transactionOverrides = _c === void 0 ? {} : _c;
return __generator(this, function (_d) {
(0, utils_1.validateAddress)(splitAddress);
calls.map(function (call) { return (0, utils_1.validateAddress)(call.to); });
if (this._shouldRequireWalletClient)
this._requireWalletClient();
this._requireOwner(splitAddress);
return [2 /*return*/, this._executeContractFunction({
contractAddress: splitAddress,
contractAbi: splitV2_1.splitV2ABI,
functionName: 'execCalls',
functionArgs: [calls],
transactionOverrides: transactionOverrides,
})];
});
});
};
SplitV2Transactions.prototype._updateSplit = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var _c, recipientAddresses, recipientAllocations, distributionIncentive, totalAllocation;
var splitAddress = _b.splitAddress, recipients = _b.recipients, distributorFeePercent = _b.distributorFeePercent, totalAllocationPercent = _b.totalAllocationPercent, _d = _b.transactionOverrides, transactionOverrides = _d === void 0 ? {} : _d;
return __generator(this, function (_e) {
_c = (0, utils_1.getValidatedSplitV2Config)(recipients, distributorFeePercent, totalAllocationPercent), recipientAddresses = _c.recipientAddresses, recipientAllocations = _c.recipientAllocations, distributionIncentive = _c.distributionIncentive, totalAllocation = _c.totalAllocation;
(0, utils_1.validateAddress)(splitAddress);
recipientAddresses.map(function (recipient) { return (0, utils_1.validateAddress)(recipient); });
if (this._shouldRequireWalletClient)
this._requireWalletClient();
this._requireOwner(splitAddress);
return [2 /*return*/, this._executeContractFunction({
contractAddress: splitAddress,
contractAbi: splitV2_1.splitV2ABI,
functionName: 'updateSplit',
functionArgs: [
{
recipients: recipientAddresses,
allocations: recipientAllocations,
totalAllocation: totalAllocation,
distributionIncentive: distributionIncentive,
},
],
transactionOverrides: transactionOverrides,
})];
});
});
};
SplitV2Transactions.prototype._distribute = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var functionChainId, split, recipientAddresses, recipientAllocations;
var _c, _d;
var splitAddress = _b.splitAddress, token = _b.tokenAddress, _e = _b.distributorAddress, distributorAddress = _e === void 0 ? (_d = (_c = this._walletClient) === null || _c === void 0 ? void 0 : _c.account) === null || _d === void 0 ? void 0 : _d.address : _e, chainId = _b.chainId, splitFields = _b.splitFields, _f = _b.transactionOverrides, transactionOverrides = _f === void 0 ? {} : _f;
return __generator(this, function (_g) {
switch (_g.label) {
case 0:
(0, utils_1.validateAddress)(splitAddress);
(0, utils_1.validateAddress)(token);
(0, utils_1.validateAddress)(distributorAddress);
if (this._shouldRequireWalletClient)
this._requireWalletClient();
functionChainId = this._getFunctionChainId(chainId);
if (!splitFields) return [3 /*break*/, 1];
split = splitFields;
return [3 /*break*/, 5];
case 1:
if (!(this._dataClient &&
constants_1.SPLITS_SUBGRAPH_CHAIN_IDS.includes(functionChainId))) return [3 /*break*/, 3];
return [4 /*yield*/, this._dataClient.getSplitMetadata({
chainId: functionChainId,
splitAddress: splitAddress,
})];
case 2:
split = _g.sent();
return [3 /*break*/, 5];
case 3: return [4 /*yield*/, this._getSplitMetadataViaProvider({
splitAddress: splitAddress,
chainId: functionChainId,
})];
case 4:
split = (_g.sent()).split;
_g.label = 5;
case 5:
recipientAddresses = split.recipients.map(function (recipient) { return recipient.recipient.address; });
recipientAllocations = split.recipients.map(function (recipient) { return recipient.ownership; });
return [2 /*return*/, this._executeContractFunction({
contractAddress: splitAddress,
contractAbi: splitV2_1.splitV2ABI,
functionName: 'distribute',
functionArgs: [
{
recipients: recipientAddresses,
allocations: recipientAllocations,
totalAllocation: recipientAllocations.reduce(function (acc, curr) { return acc + curr; }, BigInt(0)),
distributionIncentive: (0, utils_1.getNumberFromPercent)(split.distributorFeePercent),
},
token === viem_1.zeroAddress ? constants_1.NATIVE_TOKEN_ADDRESS : token,
distributorAddress,
],
transactionOverrides: transactionOverrides,
value: constants_1.ZERO,
})];
}
});
});
};
SplitV2Transactions.prototype._paused = function (splitAddress, chainId) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this._getSplitV2Contract(splitAddress, chainId).read.paused()];
});
});
};
SplitV2Transactions.prototype._owner = function (splitAddress, chainId) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this._getSplitV2Contract(splitAddress, chainId).read.owner()];
});
});
};
SplitV2Transactions.prototype._checkForSplitExistence = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var _c;
var splitAddress = _b.splitAddress, chainId = _b.chainId;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
_d.trys.push([0, 2, , 3]);
return [4 /*yield*/, this._getSplitV2Contract(splitAddress, chainId).read.splitHash()];
case 1:
_d.sent();
return [3 /*break*/, 3];
case 2:
_c = _d.sent();
// Split does not exist
throw new errors_1.AccountNotFoundError('Split', splitAddress, chainId);
case 3: return [2 /*return*/];
}
});
});
};
SplitV2Transactions.prototype._getSplitVersion = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var _c, name_1, version, _d;
var splitAddress = _b.splitAddress, chainId = _b.chainId;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
_e.trys.push([0, 2, , 3]);
return [4 /*yield*/, this._getSplitV2Contract(splitAddress, chainId).read.eip712Domain()];
case 1:
_c = __read.apply(void 0, [_e.sent(), 3]), name_1 = _c[1], version = _c[2];
if (name_1 !== 'splitWallet')
throw new Error();
return [2 /*return*/, version === '2' ? 'splitV2' : 'splitV2o1'];
case 2:
_d = _e.sent();
// Split does not exist
throw new errors_1.AccountNotFoundError('Split', splitAddress, chainId);
case 3: return [2 /*return*/];
}
});
});
};
SplitV2Transactions.prototype._getSplitMetadataViaProvider = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var formattedSplitAddress, publicClient, version, _c, blockRange, createLog, updateLog, split;
var splitAddress = _b.splitAddress, chainId = _b.chainId, cachedData = _b.cachedData;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
formattedSplitAddress = (0, viem_1.getAddress)(splitAddress);
publicClient = this._getPublicClient(chainId);
return [4 /*yield*/, this._getSplitVersion({ splitAddress: splitAddress, chainId: chainId })];
case 1:
version = _d.sent();
return [4 /*yield*/, (0, utils_1.getSplitCreateAndUpdateLogs)({
splitAddress: splitAddress,
publicClient: publicClient,
splitCreatedEvent: constants_1.splitV2CreatedEvent,
splitUpdatedEvent: constants_1.splitV2UpdatedEvent,
addresses: [
formattedSplitAddress,
(0, constants_1.getSplitV2FactoryAddress)(chainId, types_1.SplitV2Type.Pull),
(0, constants_1.getSplitV2FactoryAddress)(chainId, types_1.SplitV2Type.Push),
],
startBlockNumber: (0, constants_1.getSplitV2FactoriesStartBlock)(chainId),
cachedBlocks: cachedData === null || cachedData === void 0 ? void 0 : cachedData.blocks,
defaultBlockRange: cachedData === null || cachedData === void 0 ? void 0 : cachedData.blockRange,
splitV2Version: version,
})];
case 2:
_c = _d.sent(), blockRange = _c.blockRange, createLog = _c.createLog, updateLog = _c.updateLog;
return [4 /*yield*/, this._buildSplitFromLogs({
splitAddress: formattedSplitAddress,
chainId: chainId,
createLog: createLog,
updateLog: updateLog,
})];
case 3:
split = _d.sent();
return [2 /*return*/, { split: split, blockRange: blockRange }];
}
});
});
};
SplitV2Transactions.prototype._buildSplitFromLogs = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var _c, owner, paused, recipients, distributorFeePercent, type, publicClient, code, totalOwnership, split;
var splitAddress = _b.splitAddress, chainId = _b.chainId, createLog = _b.createLog, updateLog = _b.updateLog;
return __generator(this, function (_d) {
switch (_d.label) {
case 0: return [4 /*yield*/, Promise.all([
this._owner(splitAddress, chainId),
this._paused(splitAddress, chainId),
])];
case 1:
_c = __read.apply(void 0, [_d.sent(), 2]), owner = _c[0], paused = _c[1];
if (!createLog && !updateLog)
throw new Error('Split create and update logs missing');
if (updateLog) {
recipients = updateLog.args._split.recipients.map(function (recipient, i) {
return {
recipient: {
address: recipient,
},
ownership: updateLog.args._split.allocations[i],
percentAllocation: (0, utils_1.fromBigIntToPercent)(updateLog.args._split.allocations[i], updateLog.args._split.totalAllocation),
};
});
distributorFeePercent = (0, utils_1.fromBigIntToPercent)(updateLog.args._split.distributionIncentive);
}
else if (createLog) {
recipients = createLog.args.splitParams.recipients.map(function (recipient, i) {
return {
recipient: {
address: recipient,
},
ownership: createLog.args.splitParams.allocations[i],
percentAllocation: (0, utils_1.fromBigIntToPercent)(createLog.args.splitParams.allocations[i], createLog.args.splitParams.totalAllocation),
};
});
distributorFeePercent = (0, utils_1.fromBigIntToPercent)(createLog.args.splitParams.distributionIncentive);
}
if (!createLog) return [3 /*break*/, 2];
type = (0, utils_1.getSplitType)(chainId, createLog.address);
return [3 /*break*/, 4];
case 2:
publicClient = this._getPublicClient(chainId);
return [4 /*yield*/, publicClient.getBytecode({
address: splitAddress,
})];
case 3:
code = _d.sent();
if (code === null || code === void 0 ? void 0 : code.includes(constants_1.PULL_SPLIT_V2o1_ADDRESS.toLowerCase().slice(2))) {
type = 'pull';
}
else if (code === null || code === void 0 ? void 0 : code.includes(constants_1.PUSH_SPLIT_V2o1_ADDRESS.toLowerCase().slice(2))) {
type = 'push';
}
else {
throw new Error("failed to identify type of split ".concat(splitAddress));
}
_d.label = 4;
case 4:
totalOwnership = recipients.reduce(function (acc, recipient) {
return acc + recipient.ownership;
}, BigInt(0));
split = {
address: splitAddress,
totalOwnership: totalOwnership,
recipients: recipients,
distributorFeePercent: distributorFeePercent,
distributeDirection: type,
type: 'SplitV2',
controller: {
address: owner,
},
distributionsPaused: paused,
newPotentialController: {
address: viem_1.zeroAddress,
},
createdBlock: createLog ? Number(createLog === null || createLog === void 0 ? void 0 : createLog.blockNumber) : undefined,
updateBlock: updateLog
? Number(updateLog.blockNumber)
: Number(createLog.blockNumber),
};
return [2 /*return*/, split];
}
});
});
};
SplitV2Transactions.prototype._getSplitV2Contract = function (splitAddress, chainId) {
(0, utils_1.validateAddress)(splitAddress);
var publicClient = this._getPublicClient(chainId);
return (0, viem_1.getContract)({
address: splitAddress,
abi: splitV2_1.splitV2ABI,
client: publicClient,
});
};
SplitV2Transactions.prototype._getSplitV2FactoryContract = function (splitType, chainId) {
var publicClient = this._getPublicClient(chainId);
return (0, viem_1.getContract)({
address: (0, constants_1.getSplitV2FactoryAddress)(chainId, splitType),
abi: splitV2Factory_1.splitV2FactoryABI,
client: publicClient,
});
};
SplitV2Transactions.prototype._getSplitV2o1FactoryContract = function (splitType, chainId) {
var publicClient = this._getPublicClient(chainId);
return (0, viem_1.getContract)({
address: (0, constants_1.getSplitV2o1FactoryAddress)(chainId, splitType),
abi: abi_1.splitV2o1FactoryAbi,
client: publicClient,
});
};
SplitV2Transactions.prototype._eip712Domain = function (splitAddress, chainId) {
return __awaiter(this, void 0, void 0, function () {
var eip712Domain;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._getSplitV2Contract(splitAddress, chainId).read.eip712Domain()];
case 1:
eip712Domain = _a.sent();
return [2 /*return*/, {
domain: {
chainId: Number(eip712Domain[3].toString()),
name: eip712Domain[1],
version: eip712Domain[2],
verifyingContract: eip712Domain[4],
salt: eip712Domain[5],
},
}];
}
});
});
};
SplitV2Transactions.prototype._requireOwner = function (splitAddress) {
return __awaiter(this, void 0, void 0, function () {
var ownerAddress, walletAddress;
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, this._owner(splitAddress, this._walletClient.chain.id)];
case 1:
ownerAddress = _b.sent();
walletAddress = (_a = this._walletClient.account) === null || _a === void 0 ? void 0 : _a.address;
if (ownerAddress.toLowerCase() !== (walletAddress === null || walletAddress === void 0 ? void 0 : walletAddress.toLowerCase()))
throw new errors_1.InvalidAuthError("Action only available to the split controller. Split id: ".concat(splitAddress, ", split controller: ").concat(ownerAddress, ", wallet address: ").concat(walletAddress));
return [2 /*return*/];
}
});
});
};
return SplitV2Transactions;
}(base_1.BaseTransactions));
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
var SplitV2Client = /** @class */ (function (_super) {
__extends(SplitV2Client, _super);
function SplitV2Client(clientArgs) {
var _this = _super.call(this, __assign({ transactionType: constants_1.TransactionType.Transaction }, clientArgs)) || this;
var splitV2o1CreatedEvents = abi_1.splitV2o1FactoryAbi.filter(function (abi) {
return abi.type === 'event' && abi.name === 'SplitCreated';
});
_this.eventTopics = {
splitCreated: [
(0, viem_1.encodeEventTopics)({
abi: splitV2Factory_1.splitV2FactoryABI,
eventName: 'SplitCreated',
})[0],
(0, viem_1.encodeEventTopics)({
abi: [splitV2o1CreatedEvents[0]],
})[0],
(0, viem_1.encodeEventTopics)({
abi: [splitV2o1CreatedEvents[1]],
})[0],
],
splitUpdated: [
(0, viem_1.encodeEventTopics)({
abi: splitV2_1.splitV2ABI,
eventName: 'SplitUpdated',
})[0],
],
splitDistributed: [
(0, viem_1.encodeEventTopics)({
abi: splitV2_1.splitV2ABI,
eventName: 'SplitDistributed',
})[0],
],
ownershipTransferred: [
(0, viem_1.encodeEventTopics)({
abi: splitV2_1.splitV2ABI,
eventName: 'OwnershipTransferred',
})[0],
],
setPaused: [
(0, viem_1.encodeEventTopics)({
abi: splitV2_1.splitV2ABI,
eventName: 'SetPaused',
})[0],
],
execCalls: [
(0, viem_1.encodeEventTopics)({
abi: splitV2_1.splitV2ABI,
eventName: 'ExecCalls',
})[0],
],
};
_this.callData = new SplitV2CallData(clientArgs);
_this.estimateGas = new SplitV2GasEstimates(clientArgs);
_this.sign = new SplitV2Signature(clientArgs);
return _this;
}
SplitV2Client.prototype._submitCreateSplitTransaction = function (createSplitArgs) {
return __awaiter(this, void 0, void 0, function () {
var txHash;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._createSplit(__assign(__assign({}, createSplitArgs), { v2Type: 'splitV2o1' }))];
case 1:
txHash = _a.sent();
if (!this._isContractTransaction(txHash))
throw new Error('Invalid response');
return [2 /*return*/, { txHash: txHash }];
}
});
});
};
SplitV2Client.prototype.createSplit = function (createSplitArgs) {
return __awaiter(this, void 0, void 0, function () {
var txHash, events, event, log;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._submitCreateSplitTransaction(createSplitArgs)];
case 1:
txHash = (_a.sent()).txHash;
return [4 /*yield*/, this.getTransactionEvents({
txHash: txHash,
eventTopics: this.eventTopics.splitCreated,
})];
case 2:
events = _a.sent();
event = events.length > 0 ? events[0] : undefined;
if (event) {
log = (0, viem_1.decodeEventLog)({
abi: abi_1.splitV2o1FactoryAbi,
data: event.data,
topics: event.topics,
});
return [2 /*return*/, {
splitAddress: log.args.split,
event: event,
}];
}
throw new errors_1.TransactionFailedError();
}
});
});
};
SplitV2Client.prototype._submitCreateSplitTransactionOldV2 = function (createSplitArgs) {
return __awaiter(this, void 0, void 0, function () {
var txHash;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._createSplit(__assign(__assign({}, createSplitArgs), { v2Type: 'splitV2' }))];
case 1:
txHash = _a.sent();
if (!this._isContractTransaction(txHash))
throw new Error('Invalid response');
return [2 /*return*/, { txHash: txHash }];
}
});
});
};
SplitV2Client.prototype._createSplitOldV2 = function (createSplitArgs) {
return __awaiter(this, void 0, void 0, function () {
var txHash, events, event, log;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._submitCreateSplitTransactionOldV2(createSplitArgs)];
case 1:
txHash = (_a.sent()).txHash;
return [4 /*yield*/, this.getTransactionEvents({
txHash: txHash,
eventTopics: this.eventTopics.splitCreated,
})];
case 2:
events = _a.sent();
event = events.length > 0 ? events[0] : undefined;
if (event) {
log = (0, viem_1.decodeEventLog)({
abi: abi_1.splitV2o1FactoryAbi,
data: event.data,
topics: event.topics,
});
return [2 /*return*/, {
splitAddress: log.args.split,
event: event,
}];
}
throw new errors_1.TransactionFailedError();
}
});
});
};
SplitV2Client.prototype._submitTransferOwnershipTransaction = function (transferOwnershipArgs) {
return __awaiter(this, void 0, void 0, function () {
var txHash;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._transferOwnership(transferOwnershipArgs)];
case 1:
txHash = _a.sent();
if (!this._isContractTransaction(txHash))
throw new Error('Invalid response');
return [2 /*return*/, { txHash: txHash }];
}
});
});
};
SplitV2Client.prototype.transferOwnership = function (transferOwnershipArgs) {
return __awaiter(this, void 0, void 0, function () {
var txHash, events, event;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._submitTransferOwnershipTransaction(transferOwnershipArgs)];
case 1:
txHash = (_a.sent()).txHash;
return [4 /*yield*/, this.getTransactionEvents({
txHash: txHash,
eventTopics: this.eventTopics.ownershipTransferred,
})];
case 2:
events = _a.sent();
event = events.length > 0 ? events[0] : undefined;
if (event) {
return [2 /*return*/, {
event: event,
}];
}
throw new errors_1.TransactionFailedError();
}
});
});
};
SplitV2Client.prototype._submitSetPauseTransaction = function (setPausedArgs) {
return __awaiter(this, void 0, void 0, function () {
var txHash;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._setPaused(setPausedArgs)];
case 1:
txHash = _a.sent();
if (!this._isContractTransaction(txHash))
throw new Error('Invalid response');
return [2 /*return*/, { txHash: txHash }];
}
});
});
};
SplitV2Client.prototype.setPause = function (setPausedArgs) {
return __awaiter(this, void 0, void 0, function () {
var txHash, events, event;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._submitSetPauseTransaction(setPausedArgs)];
case 1:
txHash = (_a.sent()).txHash;
return [4 /*yield*/, this.getTransactionEvents({
txHash: txHash,
eventTopics: this.eventTopics.setPaused,
})];
case 2:
events = _a.sent();
event = events.length > 0 ? events[0] : undefined;
if (event) {
return [2 /*return*/, {
event: event,
}];
}
throw new errors_1.TransactionFailedError();
}
});
});
};
SplitV2Client.prototype._submitExecCallsTransaction = function (execCallsArgs) {
return __awaiter(this, void 0, void 0, function () {
var txHash;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._execCalls(execCallsArgs)];
case 1:
txHash = _a.sent();
if (!this._isContractTransaction(txHash))
throw new Error('Invalid response');
return [2 /*return*/, { txHash: txHash }];
}
});
});
};
SplitV2Client.prototype.execCalls = function (execCallsArgs) {
return __awaiter(this, void 0, void 0, function () {
var txHash, events, event;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._submitExecCallsTransaction(execCallsArgs)];
case 1:
txHash = (_a.sent()).txHash;
return [4 /*yield*/, this.getTransactionEvents({
txHash: txHash,
eventTopics: this.eventTopics.execCalls,
})];
case 2:
events = _a.sent();
event = events.length > 0 ? events[0] : undefined;
if (event) {
return [2 /*return*/, {
event: event,
}];
}
throw new errors_1.TransactionFailedError();
}
});
});
};
SplitV2Client.prototype._submitDistributeTransaction = function (distributeArgs) {
return __awaiter(this, void 0, void 0, function () {
var txHash;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._distribute(distributeArgs)];
case 1:
txHash = _a.sent();
if (!this._isContractTransaction(txHash))
throw new Error('Invalid response');
return [2 /*return*/, { txHash: txHash }];
}
});
});
};
SplitV2Client.prototype.distribute = function (distributeArgs) {
return __awaiter(this, void 0, void 0, function () {
var txHash, events, event;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._submitDistributeTransaction(distributeArgs)];
case 1:
txHash = (_a.sent()).txHash;
return [4 /*yield*/, this.getTransactionEvents({
txHash: txHash,
eventTopics: this.eventTopics.splitDistributed,
})];
case 2:
events = _a.sent();
event = events.length > 0 ? events[0] : undefined;
if (event) {
return [2 /*return*/, {
event: event,
}];
}
throw new errors_1.TransactionFailedError();
}
});
});
};
SplitV2Client.prototype._submitUpdateSplitTransaction = function (updateSplitArgs) {
return __awaiter(this, void 0, void 0, function () {
var txHash;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._updateSplit(updateSplitArgs)];
case 1:
txHash = _a.sent();
if (!this._isContractTransaction(txHash))
throw new Error('Invalid response');
return [2 /*return*/, { txHash: txHash }];
}
});
});
};
SplitV2Client.prototype.updateSplit = function (updateSplitArgs) {
return __awaiter(this, void 0, void 0, function () {
var txHash, events, event;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._submitUpdateSplitTransaction(updateSplitArgs)];
case 1:
txHash = (_a.sent()).txHash;
return [4 /*yield*/, this.getTransactionEvents({
txHash: txHash,
eventTopics: this.eventTopics.splitUpdated,
})];
case 2:
events = _a.sent();
event = events.length > 0 ? events[0] : undefined;
if (event) {
return [2 /*return*/, {
event: event,
}];
}
throw new errors_1.TransactionFailedError();
}
});
});
};
SplitV2Client.prototype._predictDeterministicAddress = function (createSplitArgs, v2Type) {
return __awaiter(this, void 0, void 0, function () {
var _a, recipientAddresses, recipientAllocations, distributionIncentive, totalAllocation, functionChainId, factory, splitAddress;
var _b, _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
if (!createSplitArgs.ownerAddress)
createSplitArgs.ownerAddress = viem_1.zeroAddress;
if (!createSplitArgs.creatorAddress)
createSplitArgs.creatorAddress = viem_1.zeroAddress;
_a = (0, utils_1.getValidatedSplitV2Config)(createSplitArgs.recipients, createSplitArgs.distributorFeePercent, createSplitArgs.totalAllocationPercent), recipientAddresses = _a.recipientAddresses, recipientAllocations = _a.recipientAllocations, distributionIncentive = _a.distributionIncentive, totalAllocation = _a.totalAllocation;
(0, utils_1.validateAddress)(createSplitArgs.ownerAddress);
(0, utils_1.validateAddress)(createSplitArgs.creatorAddress);
recipientAddresses.map(function (recipient) { return (0, utils_1.validateAddress)(recipient); });
functionChainId = this._getReadOnlyFunctionChainId(createSplitArgs.chainId);
factory = v2Type === 'splitV2o1'
? this._getSplitV2o1FactoryContract((_b = createSplitArgs.splitType) !== null && _b !== void 0 ? _b : types_1.SplitV2Type.Pull, functionChainId)
: this._getSplitV2FactoryContract((_c = createSplitArgs.splitType) !== null && _c !== void 0 ? _c : types_1.SplitV2Type.Pull, functionChainId);
if (!createSplitArgs.salt) return [3 /*break*/, 2];
return [4 /*yield*/, factory.read.predictDeterministicAddress([
{
recipients: recipientAddresses,
allocations: recipientAllocations,
totalAllocation: totalAllocation,
distributionIncentive: distributionIncentive,
},
createSplitArgs.ownerAddress,
createSplitArgs.salt,
])];
case 1:
splitAddress = _d.sent();
return [3 /*break*/, 4];
case 2: return [4 /*yield*/, factory.read.predictDeterministicAddress([