Skip to content

Commit

Permalink
feat: update initialization (#5)
Browse files Browse the repository at this point in the history
* update install method

* feat: update initialization

* chore: admin -> owner

---------

Co-authored-by: Henry <[email protected]>
  • Loading branch information
Atlasoin and HenryQW authored Jan 14, 2025
1 parent 586f9bc commit e56053f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion content/guide/openchain/ovm/specification.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Example: ovm-cal-pi

Version of the specification schema.

Example: v1.0.0
Currently: 1.0.0

### Description

Expand Down
36 changes: 24 additions & 12 deletions content/guide/openchain/ovm/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ You should use foundry to [create a new project](https://book.getfoundry.sh/proj
forge install https://github.com/webisopen/ovm-contracts
```


2. Otherwise you can use NPM to install the dependencies, there are two packages required:


```bash
npm i @webisopen/ovm-contracts @openzeppelin/contracts
```
Expand All @@ -51,21 +49,24 @@ You may refer to the [OVM Cal PI](https://github.com/webisopen/ovm-cal-pi) repos

#### Initialization

The constructor initializes the smart contract with the specification of the task to be executed.
This contract inherits from `OVMClient` and `OwnableUpgradeable`.
In the ``initialize`` method, it initializes the smart contract with the specification of the task to be executed.
For more details, refer to the [OVM Contract Specification](./specification).

Additionally, `admin` address is also defined in the constructor for collecting royalty fees.
Additionally, `owner` address is defined to collect royalty fees escrowed in the contract.

```solidity
constructor(
address OVMTaskAddress,
address admin
) OVMClient(OVMTaskAddress, admin) {
contract Pi is OVMClient, OwnableUpgradeable {
// ...
function initialize(address owner) external initializer {
__Ownable_init(owner);
// set specification
Specification memory spec;
spec.name = "ovm-cal-pi";
spec.version = "1.0.0";
spec.description = "Calculate PI";
spec.repository = "https://github.com/webisopen/ovm-cal-pi";
spec.repository = "https://github.com/webisopen/ovm-pi";
spec.repoTag = "9231c80a6cba45c8ff9a1d3ba19e8596407e8850";
spec.license = "WTFPL";
spec.requirement = Requirement({
Expand All @@ -76,14 +77,16 @@ Additionally, `admin` address is also defined in the constructor for collecting
gpu: 0,
gpuModel: GPUModel.T4
});
spec
.apiABIs = '[{"request": {"type":"function","name":"sendRequest","inputs":[{"name":"numDigits","type":"uint256","internalType":"uint256"}],"outputs":[{"name":"requestId","type":"bytes32","internalType":"bytes32"}],"stateMutability":"payable"},"getResponse":{"type":"function","name":"getResponse","inputs":[{"name":"requestId","type":"bytes32","internalType":"bytes32"}],"outputs":[{"name":"","type":"string","internalType":"string"}],"stateMutability":"view"}}]';
spec.apiABIs =
'[{"request": {"type":"function","name":"sendRequest","inputs":[{"name":"numDigits","type":"uint256","internalType":"uint256"}],"outputs":[{"name":"requestId","type":"bytes32","internalType":"bytes32"}],"stateMutability":"payable"},"getResponse":{"type":"function","name":"getResponse","inputs":[{"name":"requestId","type":"bytes32","internalType":"bytes32"}],"outputs":[{"name":"","type":"string","internalType":"string"}],"stateMutability":"view"}}]';
spec.royalty = 5;
spec.execMode = ExecMode.JIT;
spec.arch = Arch.ARM64;
spec.arch = Arch.AMD64;
_updateSpecification(spec);
}
// ...
}
```

#### Send Request
Expand Down Expand Up @@ -141,6 +144,15 @@ The interface `function setResponse(bytes32 requestId, bytes calldata data)` mus

Similarly, you need to decode the response here.

#### Collect Royalty

Royalty fees are escrowed in the contract, this function enables the owner to withdraw the fees.
```solidity
function withdraw() external onlyOwner {
payable(owner()).transfer(address(this).balance);
}
```

## Conclusion

In this guide, we demonstrated how to publish an OVM task by building a smart contract that specifies the computation to be executed, the environment in which it should run, and the requirements for the execution.
Expand Down
2 changes: 1 addition & 1 deletion content/guide/openchain/ovm/tutorial/pi.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Common features are implemented in the `OVMClient` contract, which can be import
contract Pi is OVMClient {
mapping(bytes32 requestId => string result) internal _results;
constructor(address ovmTaskAddress, address admin) OVMClient(ovmTaskAddress, admin) {
constructor(address ovmTaskAddress, address owner) OVMClient(ovmTaskAddress, owner) {
Requirement memory requirement =
Requirement({ram: "128mb", disk: "100mb", timeout: 1000, cpu: 1, gpu: 0, gpuModel: GPUModel.T4});
Expand Down

0 comments on commit e56053f

Please sign in to comment.