Skip to content

Commit

Permalink
Refactor multicall about protocol core
Browse files Browse the repository at this point in the history
  • Loading branch information
bonnie57 committed Nov 12, 2024
1 parent 827438d commit 50a9bb4
Show file tree
Hide file tree
Showing 8 changed files with 452 additions and 213 deletions.
2 changes: 1 addition & 1 deletion packages/core-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
"scripts": {
"build": "pnpm run fix && preconstruct build",
"test": "pnpm run test:unit",
"test": "pnpm run test:unit && pnpm run test:integration",
"test:unit": "TS_NODE_PROJECT='./tsconfig.test.json' c8 --all --src ./src mocha -r ts-node/register './test/unit/**/*.test.ts'",
"test:integration": "TS_NODE_PROJECT='./tsconfig.test.json' mocha -r ts-node/register './test/integration/**/*.test.ts' --timeout 240000",
"fix": "pnpm run format:fix && pnpm run lint:fix",
Expand Down
323 changes: 323 additions & 0 deletions packages/core-sdk/src/abi/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7514,6 +7514,265 @@ export const moduleRegistryConfig = {
abi: moduleRegistryAbi,
} as const;

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Multicall3
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/**
*
*/
export const multicall3Abi = [
{
type: "function",
inputs: [
{
name: "calls",
internalType: "struct Multicall3.Call[]",
type: "tuple[]",
components: [
{ name: "target", internalType: "address", type: "address" },
{ name: "callData", internalType: "bytes", type: "bytes" },
],
},
],
name: "aggregate",
outputs: [
{ name: "blockNumber", internalType: "uint256", type: "uint256" },
{ name: "returnData", internalType: "bytes[]", type: "bytes[]" },
],
stateMutability: "payable",
},
{
type: "function",
inputs: [
{
name: "calls",
internalType: "struct Multicall3.Call3[]",
type: "tuple[]",
components: [
{ name: "target", internalType: "address", type: "address" },
{ name: "allowFailure", internalType: "bool", type: "bool" },
{ name: "callData", internalType: "bytes", type: "bytes" },
],
},
],
name: "aggregate3",
outputs: [
{
name: "returnData",
internalType: "struct Multicall3.Result[]",
type: "tuple[]",
components: [
{ name: "success", internalType: "bool", type: "bool" },
{ name: "returnData", internalType: "bytes", type: "bytes" },
],
},
],
stateMutability: "payable",
},
{
type: "function",
inputs: [
{
name: "calls",
internalType: "struct Multicall3.Call3Value[]",
type: "tuple[]",
components: [
{ name: "target", internalType: "address", type: "address" },
{ name: "allowFailure", internalType: "bool", type: "bool" },
{ name: "value", internalType: "uint256", type: "uint256" },
{ name: "callData", internalType: "bytes", type: "bytes" },
],
},
],
name: "aggregate3Value",
outputs: [
{
name: "returnData",
internalType: "struct Multicall3.Result[]",
type: "tuple[]",
components: [
{ name: "success", internalType: "bool", type: "bool" },
{ name: "returnData", internalType: "bytes", type: "bytes" },
],
},
],
stateMutability: "payable",
},
{
type: "function",
inputs: [
{
name: "calls",
internalType: "struct Multicall3.Call[]",
type: "tuple[]",
components: [
{ name: "target", internalType: "address", type: "address" },
{ name: "callData", internalType: "bytes", type: "bytes" },
],
},
],
name: "blockAndAggregate",
outputs: [
{ name: "blockNumber", internalType: "uint256", type: "uint256" },
{ name: "blockHash", internalType: "bytes32", type: "bytes32" },
{
name: "returnData",
internalType: "struct Multicall3.Result[]",
type: "tuple[]",
components: [
{ name: "success", internalType: "bool", type: "bool" },
{ name: "returnData", internalType: "bytes", type: "bytes" },
],
},
],
stateMutability: "payable",
},
{
type: "function",
inputs: [],
name: "getBasefee",
outputs: [{ name: "basefee", internalType: "uint256", type: "uint256" }],
stateMutability: "view",
},
{
type: "function",
inputs: [{ name: "blockNumber", internalType: "uint256", type: "uint256" }],
name: "getBlockHash",
outputs: [{ name: "blockHash", internalType: "bytes32", type: "bytes32" }],
stateMutability: "view",
},
{
type: "function",
inputs: [],
name: "getBlockNumber",
outputs: [{ name: "blockNumber", internalType: "uint256", type: "uint256" }],
stateMutability: "view",
},
{
type: "function",
inputs: [],
name: "getChainId",
outputs: [{ name: "chainid", internalType: "uint256", type: "uint256" }],
stateMutability: "view",
},
{
type: "function",
inputs: [],
name: "getCurrentBlockCoinbase",
outputs: [{ name: "coinbase", internalType: "address", type: "address" }],
stateMutability: "view",
},
{
type: "function",
inputs: [],
name: "getCurrentBlockDifficulty",
outputs: [{ name: "difficulty", internalType: "uint256", type: "uint256" }],
stateMutability: "view",
},
{
type: "function",
inputs: [],
name: "getCurrentBlockGasLimit",
outputs: [{ name: "gaslimit", internalType: "uint256", type: "uint256" }],
stateMutability: "view",
},
{
type: "function",
inputs: [],
name: "getCurrentBlockTimestamp",
outputs: [{ name: "timestamp", internalType: "uint256", type: "uint256" }],
stateMutability: "view",
},
{
type: "function",
inputs: [{ name: "addr", internalType: "address", type: "address" }],
name: "getEthBalance",
outputs: [{ name: "balance", internalType: "uint256", type: "uint256" }],
stateMutability: "view",
},
{
type: "function",
inputs: [],
name: "getLastBlockHash",
outputs: [{ name: "blockHash", internalType: "bytes32", type: "bytes32" }],
stateMutability: "view",
},
{
type: "function",
inputs: [
{ name: "requireSuccess", internalType: "bool", type: "bool" },
{
name: "calls",
internalType: "struct Multicall3.Call[]",
type: "tuple[]",
components: [
{ name: "target", internalType: "address", type: "address" },
{ name: "callData", internalType: "bytes", type: "bytes" },
],
},
],
name: "tryAggregate",
outputs: [
{
name: "returnData",
internalType: "struct Multicall3.Result[]",
type: "tuple[]",
components: [
{ name: "success", internalType: "bool", type: "bool" },
{ name: "returnData", internalType: "bytes", type: "bytes" },
],
},
],
stateMutability: "payable",
},
{
type: "function",
inputs: [
{ name: "requireSuccess", internalType: "bool", type: "bool" },
{
name: "calls",
internalType: "struct Multicall3.Call[]",
type: "tuple[]",
components: [
{ name: "target", internalType: "address", type: "address" },
{ name: "callData", internalType: "bytes", type: "bytes" },
],
},
],
name: "tryBlockAndAggregate",
outputs: [
{ name: "blockNumber", internalType: "uint256", type: "uint256" },
{ name: "blockHash", internalType: "bytes32", type: "bytes32" },
{
name: "returnData",
internalType: "struct Multicall3.Result[]",
type: "tuple[]",
components: [
{ name: "success", internalType: "bool", type: "bool" },
{ name: "returnData", internalType: "bytes", type: "bytes" },
],
},
],
stateMutability: "payable",
},
] as const;

/**
*
*/
export const multicall3Address = {
1516: "0xcA11bde05977b3631167028862bE2a173976CA11",
} as const;

/**
*
*/
export const multicall3Config = {
address: multicall3Address,
abi: multicall3Abi,
} as const;

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// PILicenseTemplate
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -19492,6 +19751,70 @@ export class ModuleRegistryReadOnlyClient {
}
}

// Contract Multicall3 =============================================================

/**
* Multicall3Aggregate3Request
*
* @param calls tuple[]
*/
export type Multicall3Aggregate3Request = {
calls: {
target: Address;
allowFailure: boolean;
callData: Hex;
}[];
};

/**
* contract Multicall3 write method
*/
export class Multicall3Client {
protected readonly wallet: SimpleWalletClient;
protected readonly rpcClient: PublicClient;
public readonly address: Address;

constructor(rpcClient: PublicClient, wallet: SimpleWalletClient, address?: Address) {
this.address = address || getAddress(multicall3Address, rpcClient.chain?.id);
this.rpcClient = rpcClient;
this.wallet = wallet;
}

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

/**
* method aggregate3 for contract Multicall3 with only encode
*
* @param request Multicall3Aggregate3Request
* @return EncodedTxData
*/
public aggregate3Encode(request: Multicall3Aggregate3Request): EncodedTxData {
return {
to: this.address,
data: encodeFunctionData({
abi: multicall3Abi,
functionName: "aggregate3",
args: [request.calls],
}),
};
}
}

// Contract PILicenseTemplate =============================================================

/**
Expand Down
3 changes: 1 addition & 2 deletions packages/core-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type {
RegisterIpAndAttachPilTermsRequest,
RegisterIpAndAttachPilTermsResponse,
MintAndRegisterIpAndMakeDerivativeRequest,
MintAndRegisterIpAndMakeDerivativeResponse,
GenerateCreatorMetadataParam,
IpCreator,
GenerateIpMetadataParam,
Expand All @@ -49,8 +50,6 @@ export type {
BatchRegisterResponse,
BatchRegisterDerivativeRequest,
BatchRegisterDerivativeResponse,
BatchRegisterWithIpMetadataRequest,
BatchRegisterWithIpMetadataResponse,
} from "./types/resources/ipAsset";

export type {
Expand Down
Loading

0 comments on commit 50a9bb4

Please sign in to comment.