@skalenetwork/skale-contracts-ethers-v5 0.0.1-main.133

Sign up to get free protection for your applications and to get access to all the features.
package/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # SKALE Contracts
2
+
3
+ ## Description
4
+
5
+ The library simplifies development of dApps that interact with smart contracts in SKALE infrastructure.
6
+
7
+ ## Features
8
+
9
+ - resolving of addresses of SKALE contracts on different networks
10
+ - providing up to date ABI for SKALE contracts (they may change over time due to upgradeable nature of some contracts)
11
+ - automatic creation of `Contract` objects. Currently supported libraries:
12
+ - ethers v5
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ yarn add @skalenetwork/skale-contracts
18
+ ```
19
+
20
+ ## Glossary
21
+
22
+ Main abstractions used by the library is provided below:
23
+
24
+ ### Network
25
+
26
+ Represents blockchain where smart contracts are deployed.
27
+
28
+ It could be Ethereum mainnet, goerli, SKALE chain or similar ethereum compatible chains
29
+
30
+ ### Project
31
+
32
+ SKALE smart contracts grouped into projects to serve particular purpose.
33
+
34
+ Examples of projects are [IMA](https://github.com/skalenetwork/IMA/), [skale-manager](https://github.com/skalenetwork/skale-manager) or [etherbase](https://github.com/skalenetwork/etherbase/).
35
+
36
+ ### Instance
37
+
38
+ An instance is a particular project deployed to a particular network.
39
+
40
+ For example `IMA` on Ethereum mainnet or `etherbase` on some of SKALE chains.
41
+
42
+ ### Alias
43
+
44
+ An alias is a textual name of an instance.
45
+
46
+ ## Usage
47
+
48
+ The library provides master object `skaleContracts`.
49
+
50
+ This object is used to provide desired [network](#network), [project](#project) and [instance](#instance) using it's [alias](#alias) or direct address.
51
+
52
+ When target instance is received it can be queried for information (address, ABI or Contract object) about a particular contract by it's name.
53
+
54
+ ### Example
55
+
56
+ ```typescript
57
+ import { skaleContracts } from "@skalenetwork/skale-contracts";
58
+ import { ethers } from "ethers";
59
+
60
+ const provider = new ethers.providers.JsonRpcProvider(endpoint)
61
+ const network = await skaleContracts.getNetworkByProvider(provider);
62
+ const project = await network.getProject("skale-manager");
63
+ const instance = await project.getInstance("production");
64
+ const distributor = await instance.getContract("Distributor");
65
+ const fee = await distributor.getEarnedFeeAmount()
66
+ ```
@@ -0,0 +1,10 @@
1
+ import { Abi, Adapter, ContractData, FunctionCall } from "@skalenetwork/skale-contracts";
2
+ import { BaseContract, ethers } from "ethers";
3
+ import { Provider } from "@ethersproject/providers";
4
+ export declare class Ethers5Adapter extends Adapter<BaseContract> {
5
+ provider: Provider;
6
+ constructor(provider: Provider);
7
+ createContract(address: string, abi: Abi): ethers.Contract;
8
+ makeCall(contract: ContractData, targetFunction: FunctionCall): Promise<unknown>;
9
+ getChainId(): Promise<bigint>;
10
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Ethers5Adapter = void 0;
4
+ const skale_contracts_1 = require("@skalenetwork/skale-contracts");
5
+ const ethers_1 = require("ethers");
6
+ class Ethers5Adapter extends skale_contracts_1.Adapter {
7
+ constructor(provider) {
8
+ super();
9
+ this.provider = provider;
10
+ }
11
+ createContract(address, abi) {
12
+ return new ethers_1.ethers.Contract(address, new ethers_1.ethers.utils.Interface(abi), this.provider);
13
+ }
14
+ async makeCall(contract, targetFunction) {
15
+ const contractInterface = new ethers_1.ethers.utils.Interface(contract.abi), [result] = contractInterface.decodeFunctionResult(targetFunction.functionName, await this.provider.call({
16
+ "data": contractInterface.encodeFunctionData(targetFunction.functionName, targetFunction.args),
17
+ "to": contract.address
18
+ }));
19
+ return result;
20
+ }
21
+ async getChainId() {
22
+ const { chainId } = await this.provider.getNetwork();
23
+ return BigInt(chainId);
24
+ }
25
+ }
26
+ exports.Ethers5Adapter = Ethers5Adapter;
27
+ //# sourceMappingURL=ethers5Adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ethers5Adapter.js","sourceRoot":"","sources":["../src/ethers5Adapter.ts"],"names":[],"mappings":";;;AAAA,mEAKuC;AACvC,mCAA8C;AAI9C,MAAa,cAAe,SAAQ,yBAAqB;IAGrD,YAAa,QAAkB;QAC3B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IAED,cAAc,CAAE,OAAe,EAAE,GAAQ;QACrC,OAAO,IAAI,eAAM,CAAC,QAAQ,CACtB,OAAO,EACP,IAAI,eAAM,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,EAC/B,IAAI,CAAC,QAAQ,CACA,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,QAAQ,CACV,QAAsB,EACtB,cAA4B;QAE5B,MACI,iBAAiB,GAAG,IAAI,eAAM,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,EAC5D,CAAC,MAAM,CAAC,GAAG,iBAAiB,CAAC,oBAAoB,CAC7C,cAAc,CAAC,YAAY,EAC3B,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YACrB,MAAM,EAAE,iBAAiB,CAAC,kBAAkB,CACxC,cAAc,CAAC,YAAY,EAC3B,cAAc,CAAC,IAAI,CACtB;YACD,IAAI,EAAE,QAAQ,CAAC,OAAO;SACzB,CAAC,CACL,CAAC;QACN,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,KAAK,CAAC,UAAU;QACZ,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;QACrD,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;CACJ;AAvCD,wCAuCC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { SkaleContracts } from "./skaleContracts";
2
+ export declare const skaleContracts: SkaleContracts;
package/lib/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.skaleContracts = void 0;
4
+ const skaleContracts_1 = require("./skaleContracts");
5
+ exports.skaleContracts = new skaleContracts_1.SkaleContracts();
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAAkD;AAErC,QAAA,cAAc,GAAG,IAAI,+BAAc,EAAE,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { BaseContract } from "ethers";
2
+ import { SkaleContracts as BaseSkaleContracts } from "@skalenetwork/skale-contracts";
3
+ import { Provider } from "@ethersproject/providers";
4
+ export declare class SkaleContracts extends BaseSkaleContracts<BaseContract> {
5
+ getNetworkByChainId(chainId: number): Promise<import("@skalenetwork/skale-contracts/lib/network").Network<BaseContract>>;
6
+ getNetworkByProvider(provider: Provider): Promise<import("@skalenetwork/skale-contracts/lib/network").Network<BaseContract>>;
7
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SkaleContracts = void 0;
4
+ const ethers_1 = require("ethers");
5
+ const skale_contracts_1 = require("@skalenetwork/skale-contracts");
6
+ const ethers5Adapter_1 = require("./ethers5Adapter");
7
+ class SkaleContracts extends skale_contracts_1.SkaleContracts {
8
+ getNetworkByChainId(chainId) {
9
+ return this.getNetworkByProvider(ethers_1.ethers.getDefaultProvider(chainId));
10
+ }
11
+ getNetworkByProvider(provider) {
12
+ return this.getNetworkByAdapter(new ethers5Adapter_1.Ethers5Adapter(provider));
13
+ }
14
+ }
15
+ exports.SkaleContracts = SkaleContracts;
16
+ //# sourceMappingURL=skaleContracts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skaleContracts.js","sourceRoot":"","sources":["../src/skaleContracts.ts"],"names":[],"mappings":";;;AAAA,mCAA8C;AAC9C,mEAEuC;AACvC,qDAAkD;AAIlD,MAAa,cAAe,SAAQ,gCAAgC;IAChE,mBAAmB,CAAE,OAAe;QAChC,OAAO,IAAI,CAAC,oBAAoB,CAAC,eAAM,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;IACzE,CAAC;IAED,oBAAoB,CAAE,QAAkB;QACpC,OAAO,IAAI,CAAC,mBAAmB,CAAC,IAAI,+BAAc,CAAC,QAAQ,CAAC,CAAC,CAAC;IAClE,CAAC;CACJ;AARD,wCAQC"}
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "engines": {
3
+ "node": ">=16.0.0"
4
+ },
5
+ "devDependencies": {
6
+ "@skalenetwork/skale-contracts": "portal:../base/",
7
+ "@types/node": "^20.5.0",
8
+ "@typescript-eslint/eslint-plugin": "^6.0.0",
9
+ "@typescript-eslint/parser": "^6.0.0",
10
+ "eslint": "^8.45.0",
11
+ "typescript": "^5.1.6"
12
+ },
13
+ "files": [
14
+ "lib/**/*"
15
+ ],
16
+ "main": "lib/index.js",
17
+ "name": "@skalenetwork/skale-contracts-ethers-v5",
18
+ "packageManager": "yarn@3.5.1",
19
+ "scripts": {
20
+ "compile": "npx tsc",
21
+ "fullCheck": "yarn compile && yarn eslint",
22
+ "prepare": "yarn compile",
23
+ "eslint": "npx eslint ."
24
+ },
25
+ "types": "lib/index.d.ts",
26
+ "dependencies": {
27
+ "@skalenetwork/skale-contracts-ethers-v5": "0.0.1-main.133",
28
+ "ethers": "^5.7.2"
29
+ },
30
+ "version": "0.0.1-main.133"
31
+ }