Skip to content

Commit

Permalink
fix(core): encode execute function for custom call
Browse files Browse the repository at this point in the history
  • Loading branch information
extg3 committed Jul 5, 2024
1 parent 1ed947f commit dabcbaf
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 57 deletions.
3 changes: 2 additions & 1 deletion examples/sandbox/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<base href="/" />

<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
<link rel="icon" type="image/png" href="/favicon.png">
<link rel="stylesheet" href="/src/styles.css" />
<script>
window.Browser = { T: () => undefined };
Expand Down
Binary file removed examples/sandbox/public/favicon.ico
Binary file not shown.
Binary file added examples/sandbox/public/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions examples/sandbox/public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type CallItem = {
method: string;
abi: any;
args: any[];
value?: string | number | bigint; // native amount to send with the call
};

type ActionConfig = {
Expand All @@ -20,69 +21,39 @@ type ActionConfig = {
};

export class CustomContractCall implements CallDataBuilder {
private vaultInterface: any;

constructor(
protected readonly config: ActionConfig,
protected readonly commonCallDataBuilderConfig: CommonBuilderOptions
) {}
) {
this.vaultInterface = this.commonCallDataBuilderConfig.provider
.getContractFactory()
.getContractInterface(JSON.stringify(VaultABI));
}

public async build(): Promise<CallDataBuilderReturnData> {
const callData = new Set<CallData>();

for (const item of this.config.items) {
if (!item.contract || !item.method || !item.abi) continue;

const contractInterface = this.commonCallDataBuilderConfig.provider
.getContractFactory()
.getContractInterface(JSON.stringify(item.abi));
const contractInterface = this.commonCallDataBuilderConfig.provider
.getContractFactory()
.getContractInterface(JSON.stringify(item.abi));

const functionCallData = contractInterface.encodeFunctionData(item.method, item.args);

callData.add({
to: item.contract,
callData: contractInterface.encodeFunctionData(item.method, item.args),
callData: this.vaultInterface.encodeFunctionData("execute", [
item.contract,
item.value ? String(item.value) : "0",
functionCallData,
]),
});
}

return { callData, value: this.config.value || BigInt(0) };
}
}




// public encodeExecuteFunctionCallRaw(
// pointer: string,
// to: string,
// callData: string,
// nativeAmount?: string | number
// ): CallData {
// return {
// pointer: pointer,
// callData: this.vaultInterface.encodeFunctionData("execute", [
// to,
// nativeAmount ?? "0",
// callData
// ]),
// value: nativeAmount?.toString()
// }
// }

// public encodeExecuteFunctionCall(
// pointer: string,
// callParams: {
// functionName: string,
// data: any[],
// to: string,
// nativeAmount?: string | number,
// viewData?: string
// }
// ): CallData {
// const functionCall = this.encodeFunctionData(pointer, callParams.functionName, callParams.data, callParams.viewData)

// return {
// pointer,
// callData: this.vaultInterface.encodeFunctionData("execute", [
// callParams.to,
// callParams.nativeAmount ?? "0",
// functionCall.callData
// ])
// }
// }

0 comments on commit dabcbaf

Please sign in to comment.