@gotake/gotake-sdk
Version:
SDK for interacting with GoTake blockchain contracts
87 lines (86 loc) • 3.35 kB
JavaScript
import { ethers } from 'ethers';
import { BaseTransactionWrapper } from './base-transaction-wrapper.js';
import { ERC6551Account__factory } from 'gotake-contracts/dist/typechain/factories/contracts/ERC6551Account__factory.js';
/**
* Wrapper for Token Bound Account contract operations
*/
export class TBAWrapper extends BaseTransactionWrapper {
/**
* Create TBA wrapper instance
* @param provider Provider instance
* @param signer Signer instance
*/
constructor(provider, signer) {
super(provider, signer);
}
/**
* Get TBA account contract instance
* @param address Account address
* @returns ERC6551Account contract instance
*/
getAccountContract(address) {
return ERC6551Account__factory.connect(address, this._signer);
}
/**
* Get token information of a TBA
* @param accountAddress TBA address
* @returns Token information
*/
async tokenOf(accountAddress) {
const account = this.getAccountContract(accountAddress);
return account.token();
}
/**
* Get state of a TBA
* @param accountAddress TBA address
* @returns State as BigNumber
*/
async getState(accountAddress) {
const account = this.getAccountContract(accountAddress);
return account.state();
}
/**
* Initialize a TBA
* @param params Initialization parameters
* @param options Transaction options
* @returns Transaction
*/
async initialize(params, options) {
const account = this.getAccountContract(params.accountAddress);
const tokenIdBN = ethers.BigNumber.from(params.tokenId);
// Create transaction overrides from gas configuration
const overrides = this.createOverrides(options === null || options === void 0 ? void 0 : options.gasConfig);
// Direct contract call with overrides
return account.initialize(params.chainId, params.tokenContract, tokenIdBN, overrides);
}
/**
* Execute a transaction from a TBA
* @param params Execution parameters
* @param options Transaction options
* @returns Transaction and result
*/
async execute(params, options) {
const account = this.getAccountContract(params.accountAddress);
const valueBN = ethers.BigNumber.from(params.value);
// Create transaction overrides from gas configuration
const overrides = this.createOverrides(options === null || options === void 0 ? void 0 : options.gasConfig);
// Direct contract call with overrides
const tx = await account.execute(params.to, valueBN, params.data, 0, // 0 is operation type, representing CALL
overrides);
// Simplified placeholder for result
const result = "0x";
return { tx, result };
}
/**
* Check if address is a valid signer for a TBA
* @param accountAddress TBA address
* @param signerAddress Signer address to check
* @returns Whether the address is a valid signer
*/
async isValidSigner(accountAddress, signerAddress) {
const account = this.getAccountContract(accountAddress);
// Get execution result (0x00 means invalid, anything else is valid)
const result = await account.isValidSigner(signerAddress, "0x");
return result !== "0x";
}
}