sacredrealm-sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2021 SEALEM-LAB
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ ## Install Dependencies
2
+
3
+ ```
4
+ npm i
5
+ ```
6
+
7
+ ## Build SDK
8
+
9
+ ```
10
+ npm run build
11
+ ```
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "sacredrealm-sdk",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "src/index.ts",
6
+ "scripts": {
7
+ "build": "tsdx build",
8
+ "start": "tsdx watch",
9
+ "test": "tsdx test"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/Sacred-Realm/sacredrealm-sdk.git"
14
+ },
15
+ "author": "SEALEM-LAB",
16
+ "license": "MIT",
17
+ "bugs": {
18
+ "url": "https://github.com/Sacred-Realm/sacredrealm-sdk/issues"
19
+ },
20
+ "homepage": "https://github.com/Sacred-Realm/sacredrealm-sdk#readme",
21
+ "dependencies": {
22
+ "@apollo/client": "^3.5.10",
23
+ "@walletconnect/web3-provider": "^1.7.5",
24
+ "ethers": "^5.6.1",
25
+ "graphql": "^16.3.0",
26
+ "sacredrealm-core": "^1.0.0"
27
+ },
28
+ "devDependencies": {
29
+ "tsdx": "^0.14.1"
30
+ }
31
+ }
@@ -0,0 +1,50 @@
1
+ export function token(env?: string) {
2
+ const environment = env || process.env.NODE_ENV;
3
+ if (environment === 'production') {
4
+ return {
5
+ SB: '0x',
6
+ SN: '0x',
7
+ ST: '0x',
8
+ SR: '0x',
9
+ BUSD: '0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56',
10
+ }
11
+ } else {
12
+ return {
13
+ SB: '0x',
14
+ SN: '0x',
15
+ ST: '0x',
16
+ SR: '0x',
17
+ BUSD: '0x6Cbb3Ef5A8c9743a1e2148d6DCA69f3ba26BC8C5',
18
+ };
19
+ }
20
+ };
21
+
22
+ export function contract(env?: string) {
23
+ const environment = env || process.env.NODE_ENV;
24
+ if (environment === 'production') {
25
+ return {
26
+ PancakeRouter: '0x10ED43C718714eb63d5aA57B78B54704E256024E',
27
+ };
28
+ } else {
29
+ return {
30
+ PancakeRouter: '0x9Ac64Cc6e4415144C455BD8E4837Fea55603e5c3',
31
+ };
32
+ }
33
+ };
34
+
35
+ export function network(env?: string) {
36
+ const environment = env || process.env.NODE_ENV;
37
+ if (environment === 'production') {
38
+ return {
39
+ chainId: '0x38',
40
+ chainName: 'BSC-Mainnet',
41
+ rpcUrls: ['https://bsc-dataseed.binance.org/']
42
+ };
43
+ } else {
44
+ return {
45
+ chainId: '0x61',
46
+ chainName: 'BSC-Testnet',
47
+ rpcUrls: ['https://data-seed-prebsc-1-s1.binance.org:8545/']
48
+ };
49
+ }
50
+ };
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './token';
2
+ export * from './constant';
@@ -0,0 +1,7 @@
1
+ import { SB__factory } from 'sacredrealm-core/typechain-types'
2
+ import { rpcProvider } from '../utils';
3
+ import { token } from '../constant';
4
+
5
+ export function sb() {
6
+ return SB__factory.connect(token().SB, rpcProvider);
7
+ }
@@ -0,0 +1,7 @@
1
+ import { SN__factory } from 'sacredrealm-core/typechain-types'
2
+ import { rpcProvider } from '../utils';
3
+ import { token } from '../constant';
4
+
5
+ export function sn() {
6
+ return SN__factory.connect(token().SN, rpcProvider);
7
+ }
@@ -0,0 +1,7 @@
1
+ import { SR__factory } from 'sacredrealm-core/typechain-types'
2
+ import { rpcProvider } from '../utils';
3
+ import { token } from '../constant';
4
+
5
+ export function sr() {
6
+ return SR__factory.connect(token().SR, rpcProvider);
7
+ }
@@ -0,0 +1,7 @@
1
+ import { ST__factory } from 'sacredrealm-core/typechain-types'
2
+ import { rpcProvider } from '../utils';
3
+ import { token } from '../constant';
4
+
5
+ export function st() {
6
+ return ST__factory.connect(token().ST, rpcProvider);
7
+ }
@@ -0,0 +1,4 @@
1
+ export * from './SB';
2
+ export * from './SN';
3
+ export * from './ST';
4
+ export * from './SR';
package/src/utils.ts ADDED
@@ -0,0 +1,103 @@
1
+ import { ethers, utils, constants, BigNumber } from 'ethers';
2
+ import WalletConnectProvider from '@walletconnect/web3-provider';
3
+ import { token, network } from './constant';
4
+
5
+ export const util = utils;
6
+ export const constant = constants;
7
+
8
+ export const rpcProvider = new ethers.providers.JsonRpcProvider(network().rpcUrls[0]);
9
+ let web3Provider = newWeb3Provider(localStorage.getItem('walletType'));
10
+
11
+ function newWeb3Provider(walletType: string | null) {
12
+ let provider;
13
+
14
+ if (walletType == 'walletconnect') {
15
+ provider = new WalletConnectProvider({
16
+ rpc: {
17
+ [Number(network().chainId)]: network().rpcUrls[0],
18
+ },
19
+ chainId: Number(network().chainId)
20
+ });
21
+ } else {
22
+ provider = (window as any).ethereum;
23
+ }
24
+
25
+ return provider;
26
+ }
27
+
28
+ export const wallet = {
29
+ getAccount: async (walletType: string | null) => {
30
+ web3Provider = newWeb3Provider(walletType);
31
+ localStorage.setItem('walletType', walletType ? walletType : 'metamask')
32
+ return walletType == 'walletconnect' ? await web3Provider.enable() : await web3Provider.request({ method: 'eth_requestAccounts' });
33
+ },
34
+
35
+ getChainId: async () => {
36
+ return await web3Provider.request({ method: 'eth_chainId' });
37
+ },
38
+
39
+ addChain: async () => {
40
+ return await web3Provider.request({
41
+ method: 'wallet_addEthereumChain',
42
+ params: [network()]
43
+ });
44
+ },
45
+
46
+ addST: async (img: string) => {
47
+ return await web3Provider.request({
48
+ method: 'wallet_watchAsset',
49
+ params: {
50
+ type: 'ERC20',
51
+ options: {
52
+ address: token().ST,
53
+ symbol: 'ST',
54
+ decimals: 18,
55
+ image: img,
56
+ },
57
+ },
58
+ });
59
+ },
60
+
61
+ addSR: async (img: string) => {
62
+ return await web3Provider.request({
63
+ method: 'wallet_watchAsset',
64
+ params: {
65
+ type: 'ERC20',
66
+ options: {
67
+ address: token().SR,
68
+ symbol: 'SR',
69
+ decimals: 18,
70
+ image: img,
71
+ },
72
+ },
73
+ });
74
+ },
75
+
76
+ disconnect: async () => {
77
+ return await web3Provider.disconnect();
78
+ },
79
+
80
+ onAccountChanged: (handleAccountsChanged: any) => {
81
+ web3Provider.on('accountsChanged', handleAccountsChanged);
82
+ },
83
+
84
+ onChainChanged: (handleChainChanged: any) => {
85
+ web3Provider.on('chainChanged', handleChainChanged);
86
+ },
87
+
88
+ onDisconnect: (handleDisconnect: any) => {
89
+ web3Provider.on('disconnect', handleDisconnect);
90
+ },
91
+ }
92
+
93
+ export function getProvider() {
94
+ return new ethers.providers.Web3Provider(web3Provider);
95
+ }
96
+
97
+ export function getSigner() {
98
+ return new ethers.providers.Web3Provider(web3Provider).getSigner();
99
+ }
100
+
101
+ export function getRandomNumber(snId: number, slot: string, base: number, range: number) {
102
+ return BigNumber.from(utils.solidityKeccak256(['uint256', 'string'], [snId, slot])).mod(range).add(base).toNumber();
103
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es5",
4
+ "module": "ESNext",
5
+ "strict": true,
6
+ "esModuleInterop": true,
7
+ "rootDir": "./src",
8
+ "outDir": "dist",
9
+ "moduleResolution": "node",
10
+ "resolveJsonModule": true,
11
+ },
12
+ "include": ["./src"]
13
+ }