-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from storyprotocol/dev
beta rc.5
- Loading branch information
Showing
22 changed files
with
249 additions
and
337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { PublicClient, WalletClient, getAddress } from "viem"; | ||
|
||
import { | ||
IPAccountExecuteRequest, | ||
IPAccountExecuteResponse, | ||
IPAccountExecuteWithSigRequest, | ||
IPAccountExecuteWithSigResponse, | ||
} from "../types/resources/ipAccount"; | ||
import { handleError } from "../utils/errors"; | ||
import { IPAccountABI } from "../abi/config"; | ||
import { parseToBigInt, waitTx } from "../utils/utils"; | ||
|
||
export class IPAccountClient { | ||
private readonly wallet: WalletClient; | ||
private readonly rpcClient: PublicClient; | ||
public ipAccountABI = IPAccountABI; | ||
|
||
constructor(rpcClient: PublicClient, wallet: WalletClient) { | ||
this.wallet = wallet; | ||
this.rpcClient = rpcClient; | ||
} | ||
|
||
/** Executes a transaction from the IP Account. | ||
* @param request The request object containing necessary data to execute IP Account a transaction. | ||
* @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. | ||
* @returns Tx hash for the transaction. | ||
*/ | ||
public async execute(request: IPAccountExecuteRequest): Promise<IPAccountExecuteResponse> { | ||
try { | ||
const IPAccountConfig = { | ||
abi: this.ipAccountABI, | ||
address: getAddress(request.accountAddress), | ||
}; | ||
|
||
const { request: call } = await this.rpcClient.simulateContract({ | ||
...IPAccountConfig, | ||
functionName: "execute", | ||
args: [request.to, parseToBigInt(0), request.data], | ||
account: this.wallet.account, | ||
}); | ||
const txHash = await this.wallet.writeContract(call); | ||
|
||
if (request.txOptions?.waitForTransaction) { | ||
await waitTx(this.rpcClient, txHash); | ||
} | ||
return { txHash: txHash }; | ||
} catch (error) { | ||
handleError(error, "Failed to execute the IP Account transaction"); | ||
} | ||
} | ||
|
||
/** Executes a transaction from the IP Account. | ||
* @param request The request object containing necessary data to execute IP Account a transaction. | ||
* @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. | ||
* @returns Tx hash for the transaction. | ||
*/ | ||
public async executeWithSig( | ||
request: IPAccountExecuteWithSigRequest, | ||
): Promise<IPAccountExecuteWithSigResponse> { | ||
try { | ||
const IPAccountConfig = { | ||
abi: this.ipAccountABI, | ||
address: getAddress(request.accountAddress), | ||
}; | ||
|
||
const { request: call } = await this.rpcClient.simulateContract({ | ||
...IPAccountConfig, | ||
functionName: "executeWithSig", | ||
args: [ | ||
request.to, | ||
parseToBigInt(0), | ||
request.data, | ||
request.signer, | ||
parseToBigInt(request.deadline), | ||
request.signature, | ||
], | ||
account: this.wallet.account, | ||
}); | ||
const txHash = await this.wallet.writeContract(call); | ||
|
||
if (request.txOptions?.waitForTransaction) { | ||
await waitTx(this.rpcClient, txHash); | ||
} | ||
return { txHash: txHash }; | ||
} catch (error) { | ||
handleError(error, "Failed to execute with signature for the IP Account transaction"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.