Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement multicall #314

Merged
merged 16 commits into from
Nov 13, 2024
Merged
135 changes: 135 additions & 0 deletions packages/core-sdk/src/abi/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12349,6 +12349,15 @@ export type DerivativeWorkflowsMintAndRegisterIpAndMakeDerivativeWithLicenseToke
recipient: Address;
};

/**
* DerivativeWorkflowsMulticallRequest
*
* @param data bytes[]
*/
export type DerivativeWorkflowsMulticallRequest = {
data: readonly Hex[];
};

/**
* DerivativeWorkflowsRegisterIpAndMakeDerivativeRequest
*
Expand Down Expand Up @@ -12522,6 +12531,42 @@ export class DerivativeWorkflowsClient {
};
}

/**
* method multicall for contract DerivativeWorkflows
*
* @param request DerivativeWorkflowsMulticallRequest
* @return Promise<WriteContractReturnType>
*/
public async multicall(
request: DerivativeWorkflowsMulticallRequest,
): Promise<WriteContractReturnType> {
const { request: call } = await this.rpcClient.simulateContract({
abi: derivativeWorkflowsAbi,
address: this.address,
functionName: "multicall",
account: this.wallet.account,
args: [request.data],
});
return await this.wallet.writeContract(call as WriteContractParameters);
}

/**
* method multicall for contract DerivativeWorkflows with only encode
*
* @param request DerivativeWorkflowsMulticallRequest
* @return EncodedTxData
*/
public multicallEncode(request: DerivativeWorkflowsMulticallRequest): EncodedTxData {
return {
to: this.address,
data: encodeFunctionData({
abi: derivativeWorkflowsAbi,
functionName: "multicall",
args: [request.data],
}),
};
}

/**
* method registerIpAndMakeDerivative for contract DerivativeWorkflows
*
Expand Down Expand Up @@ -16427,6 +16472,15 @@ export type LicenseAttachmentWorkflowsMintAndRegisterIpAndAttachPilTermsRequest
};
};

/**
* LicenseAttachmentWorkflowsMulticallRequest
*
* @param data bytes[]
*/
export type LicenseAttachmentWorkflowsMulticallRequest = {
data: readonly Hex[];
};

/**
* LicenseAttachmentWorkflowsRegisterIpAndAttachPilTermsRequest
*
Expand Down Expand Up @@ -16564,6 +16618,42 @@ export class LicenseAttachmentWorkflowsClient {
};
}

/**
* method multicall for contract LicenseAttachmentWorkflows
*
* @param request LicenseAttachmentWorkflowsMulticallRequest
* @return Promise<WriteContractReturnType>
*/
public async multicall(
request: LicenseAttachmentWorkflowsMulticallRequest,
): Promise<WriteContractReturnType> {
const { request: call } = await this.rpcClient.simulateContract({
abi: licenseAttachmentWorkflowsAbi,
address: this.address,
functionName: "multicall",
account: this.wallet.account,
args: [request.data],
});
return await this.wallet.writeContract(call as WriteContractParameters);
}

/**
* method multicall for contract LicenseAttachmentWorkflows with only encode
*
* @param request LicenseAttachmentWorkflowsMulticallRequest
* @return EncodedTxData
*/
public multicallEncode(request: LicenseAttachmentWorkflowsMulticallRequest): EncodedTxData {
return {
to: this.address,
data: encodeFunctionData({
abi: licenseAttachmentWorkflowsAbi,
functionName: "multicall",
args: [request.data],
}),
};
}

/**
* method registerIpAndAttachPILTerms for contract LicenseAttachmentWorkflows
*
Expand Down Expand Up @@ -20780,6 +20870,15 @@ export type RegistrationWorkflowsMintAndRegisterIpRequest = {
};
};

/**
* RegistrationWorkflowsMulticallRequest
*
* @param data bytes[]
*/
export type RegistrationWorkflowsMulticallRequest = {
data: readonly Hex[];
};

/**
* RegistrationWorkflowsRegisterIpRequest
*
Expand Down Expand Up @@ -20945,6 +21044,42 @@ export class RegistrationWorkflowsClient extends RegistrationWorkflowsEventClien
};
}

/**
* method multicall for contract RegistrationWorkflows
*
* @param request RegistrationWorkflowsMulticallRequest
* @return Promise<WriteContractReturnType>
*/
public async multicall(
request: RegistrationWorkflowsMulticallRequest,
): Promise<WriteContractReturnType> {
const { request: call } = await this.rpcClient.simulateContract({
abi: registrationWorkflowsAbi,
address: this.address,
functionName: "multicall",
account: this.wallet.account,
args: [request.data],
});
return await this.wallet.writeContract(call as WriteContractParameters);
}

/**
* method multicall for contract RegistrationWorkflows with only encode
*
* @param request RegistrationWorkflowsMulticallRequest
* @return EncodedTxData
*/
public multicallEncode(request: RegistrationWorkflowsMulticallRequest): EncodedTxData {
return {
to: this.address,
data: encodeFunctionData({
abi: registrationWorkflowsAbi,
functionName: "multicall",
args: [request.data],
}),
};
}

/**
* method registerIp for contract RegistrationWorkflows
*
Expand Down
14 changes: 13 additions & 1 deletion packages/core-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ export type {
RegisterPilTermsAndAttachResponse,
MintAndRegisterIpAndMakeDerivativeWithLicenseTokensRequest,
RegisterIpAndMakeDerivativeWithLicenseTokensRequest,
BatchMintAndRegisterIpAssetWithPilTermsRequest,
BatchMintAndRegisterIpAssetWithPilTermsResponse,
BatchMintAndRegisterIpAndMakeDerivativeRequest,
BatchMintAndRegisterIpAndMakeDerivativeResponse,
BatchRegisterRequest,
BatchRegisterResponse,
BatchRegisterDerivativeRequest,
BatchRegisterDerivativeResponse,
BatchRegisterWithIpMetadataRequest,
BatchRegisterWithIpMetadataResponse,
} from "./types/resources/ipAsset";

export type {
Expand Down Expand Up @@ -86,6 +96,8 @@ export type {
CreateBatchPermissionSignatureRequest,
PermissionSignatureRequest,
PermissionSignatureResponse,
SignatureRequest,
SignatureResponse,
} from "./types/resources/permission";
export { AccessPermission } from "./types/resources/permission";
export type {
Expand Down Expand Up @@ -130,5 +142,5 @@ export type {
LicensingModulePredictMintingLicenseFeeResponse,
} from "./abi/generated";

export { getPermissionSignature } from "./utils/sign";
export { getPermissionSignature, getSignature } from "./utils/sign";
export { convertCIDtoHashIPFS, convertHashIPFStoCID } from "./utils/ipfs";
7 changes: 3 additions & 4 deletions packages/core-sdk/src/resources/ipAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ export class IPAccountClient {
* @param request - The request object containing necessary data to execute IP Account a transaction.
* @param request.ipId The Ip Id to get ip account.
* @param request.to The recipient of the transaction.
* @param request.value The amount of Ether to send.
* @param request.data The data to send along with the transaction.
* @param request.signer The signer of the transaction.
* @param request.deadline The deadline of the transaction signature.
* @param request.signature The signature of the transaction, EIP-712 encoded.
* @param request.txOptions - [Optional] transaction. This extends `WaitForTransactionReceiptParameters` from the Viem library, excluding the `hash` property.
* @param request.value [Optional] The amount of Ether to send.
* @param request.txOptions [Optional] This extends `WaitForTransactionReceiptParameters` from the Viem library, excluding the `hash` property.
* @returns Tx hash for the transaction.
*/
public async executeWithSig(
Expand All @@ -87,13 +87,12 @@ export class IPAccountClient {

const req = {
to: getAddress(request.to, "request.to"),
value: BigInt(0),
value: BigInt(request.value || 0),
data: request.data,
signer: getAddress(request.signer, "request.signer"),
deadline: BigInt(request.deadline),
signature: request.signature,
};

if (request.txOptions?.encodedTxDataOnly) {
return { encodedTxData: ipAccountClient.executeWithSigEncode(req) };
} else {
Expand Down
Loading