@catalabs/catalyst-sdk
Version:
Catalyst AMM SDK
149 lines • 6.03 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EvmSDKV5 = void 0;
const ethers_v5_1 = require("ethers-v5");
const catalyst_sdk_1 = require("./catalyst-sdk");
const catalyst_network_enum_1 = require("./enums/catalyst-network.enum");
const evm_describers_module_v5_1 = require("./evm/evm-describers.module-v5");
const evm_registry_module_v5_1 = require("./evm/evm-registry.module-v5");
const evm_tokens_module_v5_1 = require("./evm/evm-tokens.module-v5");
const evm_vaults_module_v5_1 = require("./evm/evm-vaults.module-v5");
class EvmSDKV5 extends catalyst_sdk_1.CatalystSDK {
provider;
signer;
registryModule;
describerModule;
tokensModule;
vaultsModule;
constructor(options) {
super(options.catalystNetwork ?? catalyst_network_enum_1.CatalystNetwork.Mainnet);
this.provider = this.#getSdkProvider(options);
this.registryModule = new evm_registry_module_v5_1.EvmRegistryModuleV5(this);
this.describerModule = new evm_describers_module_v5_1.EvmDescriberModuleV5(this);
this.tokensModule = new evm_tokens_module_v5_1.EvmTokensModuleV5(this);
this.vaultsModule = new evm_vaults_module_v5_1.EvmVaultsModuleV5(this);
}
async getFeeData() {
const result = await this.provider.getFeeData();
return {
gasPrice: BigInt(result.gasPrice?.toString() ?? '0'),
maxFeePerGas: BigInt(result.maxFeePerGas?.toString() ?? '0'),
maxPriorityFeePerGas: BigInt(result.maxPriorityFeePerGas?.toString() ?? '0'),
};
}
async signMessage(message) {
if (!this.signer) {
throw new Error('signMessages requires a signer');
}
return this.signer.signMessage(message);
}
async signTypedData(domain, types, value) {
if (!this.signer) {
throw new Error('signTypedData requires a signer');
}
return this.signer._signTypedData(domain, types, value);
}
async deployVault(options) {
return this.vaultsModule.deployVault(options);
}
async setConnection(vault, toVault, channelId, isActive) {
return this.vaultsModule.setConnection(vault, toVault, channelId, isActive);
}
async finishSetup(vault) {
return this.vaultsModule.finishSetup(vault);
}
async sendAsset(options) {
return this.vaultsModule.sendAsset(options);
}
sendAssetWithRouter(instructions, gasAmount, options) {
return this.vaultsModule.sendAssetWithRouter(instructions, gasAmount, options);
}
estimateGasForExecuteInstructions(instructions, gasAmount, options) {
return this.vaultsModule.estimateGasForExecuteInstructions(instructions, gasAmount, options);
}
sendAssetWithRouterFromQuote(quote) {
return this.vaultsModule.sendAssetWithRouterFromQuote(quote);
}
async sendAssetFromQuote(quote, toAccount, fallbackUser, callData) {
return this.vaultsModule.sendAssetFromQuote(quote, toAccount, fallbackUser, callData);
}
async calcSendAsset(vault, from, amount) {
return this.vaultsModule.calcSendAsset(vault, from, amount);
}
async calcReceiveAsset(vault, to, units) {
return this.vaultsModule.calcReceiveAsset(vault, to, units);
}
async depositMixed(vault, tokenAmounts, minOut) {
return this.vaultsModule.depositMixed(vault, tokenAmounts, minOut);
}
async withdrawAll(vault, poolTokens, minOut) {
return this.vaultsModule.withdrawAll(vault, poolTokens, minOut);
}
async withdrawMixed(vault, poolTokens, withdrawRatio, minOut) {
return this.vaultsModule.withdrawMixed(vault, poolTokens, withdrawRatio, minOut);
}
async getUnitCapacity(vault) {
return this.vaultsModule.getUnitCapacity(vault);
}
async getBalance(address) {
return BigInt((await this.provider.getBalance(address)).toString());
}
async checkBalance(token, owner) {
return this.tokensModule.checkBalance(token, owner);
}
async checkBalances(tokens, owner) {
return this.tokensModule.checkBalances(tokens, owner);
}
async checkAllowance(token, owner, spender) {
return this.tokensModule.checkAllowance(token, owner, spender);
}
async increaseAllowance(token, spender, amount, options) {
return this.tokensModule.increaseAllowance(token, spender, amount, options);
}
checkPermitAmount(token, owner, spender) {
return this.tokensModule.checkPermitAmount(token, owner, spender);
}
async ensurePermit2Allowance(token, options) {
return this.tokensModule.ensurePermit2Allowance(token, options);
}
generatePermitData(token, spender, amount) {
return this.tokensModule.generatePermitData(token, spender, amount);
}
generatePermitBatchData(assets, spender) {
return this.tokensModule.generatePermitBatchData(assets, spender);
}
async revoke(token, spender) {
return this.tokensModule.revoke(token, spender);
}
updateProvider(options) {
this.provider = this.#getSdkProvider(options);
}
async connectSigner(signer) {
try {
this.signer = signer;
this.address = await signer.getAddress();
}
catch (err) {
console.error(err);
}
}
#getSdkProvider(options) {
const { provider, network, timeout } = options;
let sdkProvider;
if (typeof provider === 'string') {
sdkProvider = new ethers_v5_1.ethers.providers.StaticJsonRpcProvider({
url: provider,
timeout: timeout ?? 5_000,
}, network);
}
else {
sdkProvider = provider;
}
return sdkProvider;
}
async ensureAllowance(token, owner, spender, amount, options) {
return this.tokensModule.ensureAllowance(token, owner, spender, amount, options);
}
}
exports.EvmSDKV5 = EvmSDKV5;
//# sourceMappingURL=evm-sdk-v5.js.map