@0xsplits/splits-sdk
Version:
SDK for the 0xSplits protocol
990 lines • 80.7 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 };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WarehouseClient = void 0;
var viem_1 = require("viem");
var warehouse_1 = require("../constants/abi/warehouse");
var base_1 = require("./base");
var constants_1 = require("../constants");
var errors_1 = require("../errors");
var mixin_1 = require("./mixin");
var utils_1 = require("../utils");
var nativeTokenAddress = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';
var WarehouseTransactions = /** @class */ (function (_super) {
__extends(WarehouseTransactions, _super);
function WarehouseTransactions(transactionClientArgs) {
var _this = _super.call(this, __assign({ supportedChainIds: constants_1.SPLITS_V2_SUPPORTED_CHAIN_IDS }, transactionClientArgs)) || this;
_this._warehouseAbi = warehouse_1.warehouseAbi;
return _this;
}
WarehouseTransactions.prototype._getWarehouseContract = function (chainId) {
var publicClient = this._getPublicClient(chainId);
return (0, viem_1.getContract)({
address: (0, constants_1.getWarehouseAddress)(),
abi: warehouse_1.warehouseAbi,
client: publicClient,
});
};
WarehouseTransactions.prototype._transfer = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var result;
var receiver = _b.receiverAddress, token = _b.tokenAddress, amount = _b.amount, _c = _b.transactionOverrides, transactionOverrides = _c === void 0 ? {} : _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
(0, utils_1.validateAddress)(receiver);
(0, utils_1.validateAddress)(token);
if (this._shouldRequireWalletClient)
this._requireWalletClient();
return [4 /*yield*/, this._executeContractFunction({
contractAddress: (0, constants_1.getWarehouseAddress)(),
contractAbi: warehouse_1.warehouseAbi,
functionName: 'transfer',
functionArgs: [receiver, (0, viem_1.fromHex)(token, 'bigint'), amount],
transactionOverrides: transactionOverrides,
})];
case 1:
result = _d.sent();
return [2 /*return*/, result];
}
});
});
};
WarehouseTransactions.prototype._transferFrom = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var result;
var sender = _b.senderAddress, receiver = _b.receiverAddress, token = _b.tokenAddress, amount = _b.amount, _c = _b.transactionOverrides, transactionOverrides = _c === void 0 ? {} : _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
(0, utils_1.validateAddress)(sender);
(0, utils_1.validateAddress)(receiver);
(0, utils_1.validateAddress)(token);
if (this._shouldRequireWalletClient)
this._requireWalletClient();
return [4 /*yield*/, this._executeContractFunction({
contractAddress: (0, constants_1.getWarehouseAddress)(),
contractAbi: warehouse_1.warehouseAbi,
functionName: 'transferFrom',
functionArgs: [sender, receiver, (0, viem_1.fromHex)(token, 'bigint'), amount],
transactionOverrides: transactionOverrides,
})];
case 1:
result = _d.sent();
return [2 /*return*/, result];
}
});
});
};
WarehouseTransactions.prototype._approve = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var result;
var spender = _b.spenderAddress, token = _b.tokenAddress, amount = _b.amount, _c = _b.transactionOverrides, transactionOverrides = _c === void 0 ? {} : _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
(0, utils_1.validateAddress)(spender);
(0, utils_1.validateAddress)(token);
if (this._shouldRequireWalletClient)
this._requireWalletClient();
return [4 /*yield*/, this._executeContractFunction({
contractAddress: (0, constants_1.getWarehouseAddress)(),
contractAbi: warehouse_1.warehouseAbi,
functionName: 'approve',
functionArgs: [spender, (0, viem_1.fromHex)(token, 'bigint'), amount],
transactionOverrides: transactionOverrides,
})];
case 1:
result = _d.sent();
return [2 /*return*/, result];
}
});
});
};
WarehouseTransactions.prototype._setOperator = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var result;
var operator = _b.operatorAddress, approved = _b.approved, _c = _b.transactionOverrides, transactionOverrides = _c === void 0 ? {} : _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
(0, utils_1.validateAddress)(operator);
if (this._shouldRequireWalletClient)
this._requireWalletClient();
return [4 /*yield*/, this._executeContractFunction({
contractAddress: (0, constants_1.getWarehouseAddress)(),
contractAbi: warehouse_1.warehouseAbi,
functionName: 'setOperator',
functionArgs: [operator, approved],
transactionOverrides: transactionOverrides,
})];
case 1:
result = _d.sent();
return [2 /*return*/, result];
}
});
});
};
WarehouseTransactions.prototype._invalidateNonce = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var result;
var nonce = _b.nonce, _c = _b.transactionOverrides, transactionOverrides = _c === void 0 ? {} : _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
if (this._shouldRequireWalletClient)
this._requireWalletClient();
return [4 /*yield*/, this._executeContractFunction({
contractAddress: (0, constants_1.getWarehouseAddress)(),
contractAbi: warehouse_1.warehouseAbi,
functionName: 'invalidateNonce',
functionArgs: [nonce],
transactionOverrides: transactionOverrides,
})];
case 1:
result = _d.sent();
return [2 /*return*/, result];
}
});
});
};
WarehouseTransactions.prototype._temporaryApproveAndCall = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var result;
var spender = _b.spenderAddress, operator = _b.operator, token = _b.tokenAddress, amount = _b.amount, target = _b.targetAddress, data = _b.data, _c = _b.transactionOverrides, transactionOverrides = _c === void 0 ? {} : _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
(0, utils_1.validateAddress)(spender);
(0, utils_1.validateAddress)(token);
(0, utils_1.validateAddress)(target);
if (this._shouldRequireWalletClient)
this._requireWalletClient();
return [4 /*yield*/, this._executeContractFunction({
contractAddress: (0, constants_1.getWarehouseAddress)(),
contractAbi: warehouse_1.warehouseAbi,
functionName: 'temporaryApproveAndCall',
functionArgs: [
spender,
operator,
(0, viem_1.fromHex)(token, 'bigint'),
amount,
target,
data,
],
transactionOverrides: transactionOverrides,
})];
case 1:
result = _d.sent();
return [2 /*return*/, result];
}
});
});
};
WarehouseTransactions.prototype._temporaryApproveAndCallBySig = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var result;
var owner = _b.ownerAddress, spender = _b.spenderAddress, operator = _b.operator, token = _b.tokenAddress, amount = _b.amount, target = _b.targetAddress, data = _b.data, nonce = _b.nonce, deadline = _b.deadline, signature = _b.signature, _c = _b.transactionOverrides, transactionOverrides = _c === void 0 ? {} : _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
(0, utils_1.validateAddress)(owner);
(0, utils_1.validateAddress)(spender);
(0, utils_1.validateAddress)(token);
(0, utils_1.validateAddress)(target);
if (this._shouldRequireWalletClient)
this._requireWalletClient();
return [4 /*yield*/, this._executeContractFunction({
contractAddress: (0, constants_1.getWarehouseAddress)(),
contractAbi: warehouse_1.warehouseAbi,
functionName: 'temporaryApproveAndCallBySig',
functionArgs: [
owner,
spender,
operator,
(0, viem_1.fromHex)(token, 'bigint'),
amount,
target,
data,
nonce,
deadline,
signature,
],
transactionOverrides: transactionOverrides,
})];
case 1:
result = _d.sent();
return [2 /*return*/, result];
}
});
});
};
WarehouseTransactions.prototype._approveBySig = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var result;
var owner = _b.ownerAddress, spender = _b.spenderAddress, operator = _b.operator, token = _b.tokenAddress, amount = _b.amount, nonce = _b.nonce, deadline = _b.deadline, signature = _b.signature, _c = _b.transactionOverrides, transactionOverrides = _c === void 0 ? {} : _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
(0, utils_1.validateAddress)(owner);
(0, utils_1.validateAddress)(spender);
(0, utils_1.validateAddress)(token);
if (this._shouldRequireWalletClient)
this._requireWalletClient();
return [4 /*yield*/, this._executeContractFunction({
contractAddress: (0, constants_1.getWarehouseAddress)(),
contractAbi: warehouse_1.warehouseAbi,
functionName: 'approveBySig',
functionArgs: [
owner,
spender,
operator,
(0, viem_1.fromHex)(token, 'bigint'),
amount,
nonce,
deadline,
signature,
],
transactionOverrides: transactionOverrides,
})];
case 1:
result = _d.sent();
return [2 /*return*/, result];
}
});
});
};
WarehouseTransactions.prototype._deposit = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var result;
var receiver = _b.receiverAddress, token = _b.tokenAddress, amount = _b.amount, _c = _b.transactionOverrides, transactionOverrides = _c === void 0 ? {} : _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
(0, utils_1.validateAddress)(receiver);
(0, utils_1.validateAddress)(token);
if (this._shouldRequireWalletClient)
this._requireWalletClient();
return [4 /*yield*/, this._executeContractFunction({
contractAddress: (0, constants_1.getWarehouseAddress)(),
contractAbi: warehouse_1.warehouseAbi,
functionName: 'deposit',
functionArgs: [receiver, token, amount],
value: token === nativeTokenAddress ? amount : BigInt(0),
transactionOverrides: transactionOverrides,
})];
case 1:
result = _d.sent();
return [2 /*return*/, result];
}
});
});
};
WarehouseTransactions.prototype._batchDeposit = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var result;
var receivers = _b.receiversAddresses, token = _b.tokenAddress, amounts = _b.amounts, _c = _b.transactionOverrides, transactionOverrides = _c === void 0 ? {} : _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
receivers.map(function (receiver) { return (0, utils_1.validateAddress)(receiver); });
(0, utils_1.validateAddress)(token);
if (this._shouldRequireWalletClient)
this._requireWalletClient();
return [4 /*yield*/, this._executeContractFunction({
contractAddress: (0, constants_1.getWarehouseAddress)(),
contractAbi: warehouse_1.warehouseAbi,
functionName: 'batchDeposit',
functionArgs: [receivers, token, amounts],
value: amounts.reduce(function (a, b) { return a + b; }),
transactionOverrides: transactionOverrides,
})];
case 1:
result = _d.sent();
return [2 /*return*/, result];
}
});
});
};
WarehouseTransactions.prototype._withdraw = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var result;
var owner = _b.ownerAddress, token = _b.tokenAddress, _c = _b.transactionOverrides, transactionOverrides = _c === void 0 ? {} : _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
(0, utils_1.validateAddress)(owner);
(0, utils_1.validateAddress)(token);
if (this._shouldRequireWalletClient)
this._requireWalletClient();
return [4 /*yield*/, this._executeContractFunction({
contractAddress: (0, constants_1.getWarehouseAddress)(),
contractAbi: warehouse_1.warehouseAbi,
functionName: 'withdraw',
functionArgs: [
owner,
token === viem_1.zeroAddress ? constants_1.NATIVE_TOKEN_ADDRESS : token,
],
transactionOverrides: transactionOverrides,
})];
case 1:
result = _d.sent();
return [2 /*return*/, result];
}
});
});
};
WarehouseTransactions.prototype._batchWithdraw = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var result;
var owner = _b.ownerAddress, tokens = _b.tokensAddresses, amounts = _b.amounts, withdrawer = _b.withdrawerAddress, _c = _b.transactionOverrides, transactionOverrides = _c === void 0 ? {} : _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
(0, utils_1.validateAddress)(owner);
tokens.map(function (token) { return (0, utils_1.validateAddress)(token); });
(0, utils_1.validateAddress)(withdrawer);
if (this._shouldRequireWalletClient)
this._requireWalletClient();
return [4 /*yield*/, this._executeContractFunction({
contractAddress: (0, constants_1.getWarehouseAddress)(),
contractAbi: warehouse_1.warehouseAbi,
functionName: 'withdraw',
functionArgs: [owner, tokens, amounts, withdrawer],
transactionOverrides: transactionOverrides,
})];
case 1:
result = _d.sent();
return [2 /*return*/, result];
}
});
});
};
WarehouseTransactions.prototype._batchTransfer = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var result;
var receivers = _b.receiversAddresses, token = _b.tokenAddress, amounts = _b.amounts, _c = _b.transactionOverrides, transactionOverrides = _c === void 0 ? {} : _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
receivers.map(function (receiver) { return (0, utils_1.validateAddress)(receiver); });
(0, utils_1.validateAddress)(token);
if (this._shouldRequireWalletClient)
this._requireWalletClient();
return [4 /*yield*/, this._executeContractFunction({
contractAddress: (0, constants_1.getWarehouseAddress)(),
contractAbi: warehouse_1.warehouseAbi,
functionName: 'batchTransfer',
functionArgs: [receivers, token, amounts],
transactionOverrides: transactionOverrides,
})];
case 1:
result = _d.sent();
return [2 /*return*/, result];
}
});
});
};
WarehouseTransactions.prototype._setWithdrawConfig = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var result;
var incentive = _b.incentivePercent, paused = _b.paused, _c = _b.transactionOverrides, transactionOverrides = _c === void 0 ? {} : _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
if (this._shouldRequireWalletClient)
this._requireWalletClient();
return [4 /*yield*/, this._executeContractFunction({
contractAddress: (0, constants_1.getWarehouseAddress)(),
contractAbi: warehouse_1.warehouseAbi,
functionName: 'setWithdrawConfig',
functionArgs: [{ incentive: (0, utils_1.getNumberFromPercent)(incentive), paused: paused }],
transactionOverrides: transactionOverrides,
})];
case 1:
result = _d.sent();
return [2 /*return*/, result];
}
});
});
};
WarehouseTransactions.prototype._eip712Domain = function (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._getWarehouseContract(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],
},
}];
}
});
});
};
return WarehouseTransactions;
}(base_1.BaseTransactions));
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
var WarehouseClient = /** @class */ (function (_super) {
__extends(WarehouseClient, _super);
function WarehouseClient(clientArgs) {
var _this = _super.call(this, __assign({ transactionType: constants_1.TransactionType.Transaction }, clientArgs)) || this;
_this.eventTopics = {
transfer: [
(0, viem_1.encodeEventTopics)({
abi: warehouse_1.warehouseAbi,
eventName: 'Transfer',
})[0],
],
withdraw: [
(0, viem_1.encodeEventTopics)({
abi: warehouse_1.warehouseAbi,
eventName: 'Withdraw',
})[0],
],
operatorSet: [
(0, viem_1.encodeEventTopics)({
abi: warehouse_1.warehouseAbi,
eventName: 'OperatorSet',
})[0],
],
approval: [
(0, viem_1.encodeEventTopics)({
abi: warehouse_1.warehouseAbi,
eventName: 'Approval',
})[0],
],
nonceInvalidation: [
(0, viem_1.encodeEventTopics)({
abi: warehouse_1.warehouseAbi,
eventName: 'NonceInvalidation',
})[0],
],
withdrawConfigUpdated: [
(0, viem_1.encodeEventTopics)({
abi: warehouse_1.warehouseAbi,
eventName: 'WithdrawConfigUpdated',
})[0],
],
};
_this.callData = new WarehouseCallData(clientArgs);
_this.estimateGas = new WarehouseGasEstimates(clientArgs);
_this.sign = new WarehouseSignature(clientArgs);
return _this;
}
// ERC6909 Metadata
WarehouseClient.prototype.getName = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var functionChainId, name;
var tokenAddress = _b.tokenAddress, chainId = _b.chainId;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
(0, utils_1.validateAddress)(tokenAddress);
functionChainId = this._getReadOnlyFunctionChainId(chainId);
return [4 /*yield*/, this._getWarehouseContract(functionChainId).read.name([
(0, viem_1.fromHex)(tokenAddress, 'bigint'),
])];
case 1:
name = _c.sent();
return [2 /*return*/, {
name: name,
}];
}
});
});
};
WarehouseClient.prototype.getSymbol = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var functionChainId, symbol;
var tokenAddress = _b.tokenAddress, chainId = _b.chainId;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
(0, utils_1.validateAddress)(tokenAddress);
functionChainId = this._getReadOnlyFunctionChainId(chainId);
return [4 /*yield*/, this._getWarehouseContract(functionChainId).read.symbol([(0, viem_1.fromHex)(tokenAddress, 'bigint')])];
case 1:
symbol = _c.sent();
return [2 /*return*/, {
symbol: symbol,
}];
}
});
});
};
WarehouseClient.prototype.getDecimals = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var functionChainId, decimals;
var tokenAddress = _b.tokenAddress, chainId = _b.chainId;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
(0, utils_1.validateAddress)(tokenAddress);
functionChainId = this._getReadOnlyFunctionChainId(chainId);
return [4 /*yield*/, this._getWarehouseContract(functionChainId).read.decimals([(0, viem_1.fromHex)(tokenAddress, 'bigint')])];
case 1:
decimals = _c.sent();
return [2 /*return*/, {
decimals: decimals,
}];
}
});
});
};
// Warehouse withdraw config
WarehouseClient.prototype.getWithdrawConfig = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var functionChainId, config;
var userAddress = _b.userAddress, chainId = _b.chainId;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
(0, utils_1.validateAddress)(userAddress);
functionChainId = this._getReadOnlyFunctionChainId(chainId);
return [4 /*yield*/, this._getWarehouseContract(functionChainId).read.withdrawConfig([userAddress])];
case 1:
config = _c.sent();
return [2 /*return*/, {
withdrawConfig: {
incentive: config[0],
paused: config[1],
},
}];
}
});
});
};
// ERC6909X nonce
WarehouseClient.prototype.isValidNonce = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var functionChainId, isValidNonce;
var userAddress = _b.userAddress, userNonce = _b.userNonce, chainId = _b.chainId;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
(0, utils_1.validateAddress)(userAddress);
functionChainId = this._getReadOnlyFunctionChainId(chainId);
return [4 /*yield*/, this._getWarehouseContract(functionChainId).read.isValidNonce([userAddress, userNonce])];
case 1:
isValidNonce = _c.sent();
return [2 /*return*/, {
isValidNonce: isValidNonce,
}];
}
});
});
};
WarehouseClient.prototype.eip712Domain = function (args) {
return __awaiter(this, void 0, void 0, function () {
var chainId, functionChainId;
return __generator(this, function (_a) {
chainId = args === null || args === void 0 ? void 0 : args.chainId;
functionChainId = this._getReadOnlyFunctionChainId(chainId);
return [2 /*return*/, this._eip712Domain(functionChainId)];
});
});
};
// ERC6909 read
WarehouseClient.prototype.isOperator = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var functionChainId, isOperator;
var ownerAddress = _b.ownerAddress, operatorAddress = _b.operatorAddress, chainId = _b.chainId;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
(0, utils_1.validateAddress)(ownerAddress);
(0, utils_1.validateAddress)(operatorAddress);
functionChainId = this._getReadOnlyFunctionChainId(chainId);
return [4 /*yield*/, this._getWarehouseContract(functionChainId).read.isOperator([ownerAddress, operatorAddress])];
case 1:
isOperator = _c.sent();
return [2 /*return*/, {
isOperator: isOperator,
}];
}
});
});
};
WarehouseClient.prototype.balanceOf = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var functionChainId, balance;
var ownerAddress = _b.ownerAddress, tokenAddress = _b.tokenAddress, chainId = _b.chainId;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
(0, utils_1.validateAddress)(ownerAddress);
(0, utils_1.validateAddress)(tokenAddress);
functionChainId = this._getReadOnlyFunctionChainId(chainId);
return [4 /*yield*/, this._getWarehouseContract(functionChainId).read.balanceOf([ownerAddress, (0, viem_1.fromHex)(tokenAddress, 'bigint')])];
case 1:
balance = _c.sent();
return [2 /*return*/, {
balance: balance,
}];
}
});
});
};
WarehouseClient.prototype.allowance = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var functionChainId, allowance;
var ownerAddress = _b.ownerAddress, spenderAddress = _b.spenderAddress, tokenAddress = _b.tokenAddress, chainId = _b.chainId;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
(0, utils_1.validateAddress)(ownerAddress);
(0, utils_1.validateAddress)(spenderAddress);
(0, utils_1.validateAddress)(tokenAddress);
functionChainId = this._getReadOnlyFunctionChainId(chainId);
return [4 /*yield*/, this._getWarehouseContract(functionChainId).read.allowance([
ownerAddress,
spenderAddress,
(0, viem_1.fromHex)(tokenAddress, 'bigint'),
])];
case 1:
allowance = _c.sent();
return [2 /*return*/, {
allowance: allowance,
}];
}
});
});
};
// erc6909 write
WarehouseClient.prototype.transfer = function (transferArgs) {
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._transfer(transferArgs)];
case 1:
txHash = _a.sent();
if (!this._isContractTransaction(txHash))
throw new Error('Invalid response');
return [4 /*yield*/, this.getTransactionEvents({
txHash: txHash,
eventTopics: this.eventTopics.transfer,
})];
case 2:
events = _a.sent();
event = events.length > 0 ? events[0] : undefined;
if (event) {
return [2 /*return*/, {
event: event,
}];
}
throw new errors_1.TransactionFailedError();
}
});
});
};
WarehouseClient.prototype.transferFrom = function (transferFromArgs) {
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._transferFrom(transferFromArgs)];
case 1:
txHash = _a.sent();
if (!this._isContractTransaction(txHash))
throw new Error('Invalid response');
return [4 /*yield*/, this.getTransactionEvents({
txHash: txHash,
eventTopics: this.eventTopics.transfer,
})];
case 2:
events = _a.sent();
event = events.length > 0 ? events[0] : undefined;
if (event) {
return [2 /*return*/, {
event: event,
}];
}
throw new errors_1.TransactionFailedError();
}
});
});
};
WarehouseClient.prototype.approve = function (approveArgs) {
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._approve(approveArgs)];
case 1:
txHash = _a.sent();
if (!this._isContractTransaction(txHash))
throw new Error('Invalid response');
return [4 /*yield*/, this.getTransactionEvents({
txHash: txHash,
eventTopics: this.eventTopics.approval,
})];
case 2:
events = _a.sent();
event = events.length > 0 ? events[0] : undefined;
if (event) {
return [2 /*return*/, {
event: event,
}];
}
throw new errors_1.TransactionFailedError();
}
});
});
};
WarehouseClient.prototype.setOperator = function (setOperatorArgs) {
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._setOperator(setOperatorArgs)];
case 1:
txHash = _a.sent();
if (!this._isContractTransaction(txHash))
throw new Error('Invalid response');
return [4 /*yield*/, this.getTransactionEvents({
txHash: txHash,
eventTopics: this.eventTopics.operatorSet,
})];
case 2:
events = _a.sent();
event = events.length > 0 ? events[0] : undefined;
if (event) {
return [2 /*return*/, {
event: event,
}];
}
throw new errors_1.TransactionFailedError();
}
});
});
};
WarehouseClient.prototype.invalidateNonce = function (invalidateNonceArgs) {
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._invalidateNonce(invalidateNonceArgs)];
case 1:
txHash = _a.sent();
if (!this._isContractTransaction(txHash))
throw new Error('Invalid response');
return [4 /*yield*/, this.getTransactionEvents({
txHash: txHash,
eventTopics: this.eventTopics.nonceInvalidation,
})];
case 2:
events = _a.sent();
event = events.length > 0 ? events[0] : undefined;
if (event) {
return [2 /*return*/, {
event: event,
}];
}
throw new errors_1.TransactionFailedError();
}
});
});
};
WarehouseClient.prototype.temporaryApproveAndCall = function (temporaryApproveAndCallArgs) {
return __awaiter(this, void 0, void 0, function () {
var txHash;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._temporaryApproveAndCall(temporaryApproveAndCallArgs)];
case 1:
txHash = _a.sent();
if (!this._isContractTransaction(txHash))
throw new Error('Invalid response');
return [2 /*return*/, { txHash: txHash }];
}
});
});
};
WarehouseClient.prototype.temporaryApproveAndCallBySig = function (temporaryApproveAndCallBySigArgs) {
return __awaiter(this, void 0, void 0, function () {
var txHash;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._temporaryApproveAndCallBySig(temporaryApproveAndCallBySigArgs)];
case 1:
txHash = _a.sent();
if (!this._isContractTransaction(txHash))
throw new Error('Invalid response');
return [2 /*return*/, { txHash: txHash }];
}
});
});
};
WarehouseClient.prototype.approveBySig = function (approveBySigArgs) {
return __awaiter(this, void 0, void 0, function () {
var txHash, eventTopics, events, event;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._approveBySig(approveBySigArgs)];
case 1:
txHash = _a.sent();
if (!this._isContractTransaction(txHash))
throw new Error('Invalid response');
eventTopics = [];
if (approveBySigArgs.operator) {
eventTopics = this.eventTopics.operatorSet;
}
else {
eventTopics = this.eventTopics.approval;
}
return [4 /*yield*/, this.getTransactionEvents({
txHash: txHash,
eventTopics: eventTopics,
})];
case 2:
events = _a.sent();
event = events.length > 0 ? events[0] : undefined;
if (event) {
return [2 /*return*/, {
event: event,
}];
}
throw new errors_1.TransactionFailedError();
}
});
});
};
WarehouseClient.prototype.deposit = function (depositArgs) {
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._deposit(depositArgs)];
case 1:
txHash = _a.sent();
if (!this._isContractTransaction(txHash))
throw new Error('Invalid response');
return [4 /*yield*/, this.getTransactionEvents({
txHash: txHash,
eventTopics: this.eventTopics.transfer,
})];
case 2:
events = _a.sent();
event = events.length > 0 ? events[0] : undefined;
if (event) {
return [2 /*return*/, {
event: event,
}];
}
throw new errors_1.TransactionFailedError();
}
});
});
};
WarehouseClient.prototype.batchDeposit = function (batchDepositArgs) {
return __awaiter(this, void 0, void 0, function () {
var txHash, events;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._batchDeposit(batchDepositArgs)];
case 1:
txHash = _a.sent();
if (!this._isContractTransaction(txHash))
throw new Error('Invalid response');
return [4 /*yield*/, this.getTransactionEvents({
txHash: txHash,
eventTopics: this.eventTopics.transfer,
})];
case 2:
events = _a.sent();
if (events.length > 0) {
return [2 /*return*/, {
events: events,
}];
}
throw new errors_1.TransactionFailedError();
}
});
});
};
WarehouseClient.prototype._submitWithdrawTransaction = function (withdrawArgs) {
return __awaiter(this, void 0, void 0, function () {
var txHash;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._withdraw(withdrawArgs)];
case 1:
txHash = _a.sent();
if (!this._isContractTransaction(txHash))
throw new Error('Invalid response');
return [2 /*return*/, { txHash: txHash }];
}
});
});
};
WarehouseClient.prototype.withdraw = function (withdrawArgs) {