Skip to content

Commit c5768b7

Browse files
committed
fix(sdk): Fixing SDK build
1 parent 8378a08 commit c5768b7

File tree

9 files changed

+78
-55
lines changed

9 files changed

+78
-55
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,6 @@ package-lock.json
163163
scm/srv/
164164
scm/pwfile
165165

166+
# ides
167+
.idea
168+

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"trailingComma": "es5",
3+
"tabWidth": 4,
4+
"semi": false
5+
}

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"private": true,
3+
"engines": {
4+
"node": "16"
5+
},
36
"scripts": {
47
"generate_classes": "typechain --target=web3-v1 --out-dir types/contracts 'build/contracts/*.json'"
58
},

sdk/.eslintrc.js

-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
21
module.exports = {
32
env: {
43
browser: false,
54
es6: true,
65
node: true,
76
},
87
parser: "@typescript-eslint/parser",
9-
parserOptions: {
10-
project: `${__dirname}/tsconfig.json`,
11-
sourceType: "module",
12-
},
138
rules: {
149
"prettier/prettier": "error",
1510
},

sdk/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Setup
2+
3+
4+
Add this var envs:
5+
6+
export RPC_URL="your_rpc_url_here"
7+
export PRIVATE_KEY="your_testnet_private_wallet_key"
8+
9+
10+
# how test this?
11+
12+
1. `yarn` / `yarn install`
13+
1. `yarn example`
14+
15+
*or*
16+
17+
1. `yarn build`
18+
2. `node lib/example`

sdk/package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
"name": "@moonstream/engine",
33
"version": "0.0.1",
44
"description": "SDK for moonstream engine",
5-
"main": "index.ts",
5+
"main": "lib/index.js",
6+
"types": "lib/index.d.ts",
67
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
8+
"build": "tsc",
9+
"example": "ts-node ./src/example.ts"
810
},
911
"author": "moonstream",
1012
"license": "ISC",
1113
"devDependencies": {
1214
"@typechain/ethers-v5": "^10.1.0",
15+
"ts-node": "^10.9.1",
1316
"typechain": "^8.1.0",
1417
"typescript": "^4.7.4"
1518
},

sdk/src/CraftingContract.ts

+23-32
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ import {
1111
CraftingRecipe,
1212
CraftingInputActions,
1313
CraftingOutputActions,
14-
ERC20Item,
1514
ERC1155Item,
16-
CraftingItem,
1715
CraftingInput,
1816
CraftingOutput,
1917
} from "./types/CraftingTypes"
@@ -101,43 +99,36 @@ export class CraftingContract {
10199
}
102100

103101
public async addRecipe(
104-
recipe: CraftingRecipe,
105-
overrides?: ethers.Overrides
102+
recipe: CraftingRecipe
103+
// overrides?: ethers.Overrides
106104
): Promise<ethers.BigNumber> {
107-
let craftingInputs = recipe.craftingInputs.map(
108-
(el): CraftingInputItemStruct => {
109-
return {
110-
tokenType: "tokenId" in el.item ? 1155 : 20,
111-
tokenAddress: el.item.tokenAddrress,
112-
tokenId:
113-
"tokenId" in el.item
114-
? (el.item as ERC1155Item).tokenId
115-
: 0,
116-
amount: el.item.amount,
117-
tokenAction: el.action,
118-
}
119-
}
105+
const craftingInputs = recipe.craftingInputs.map(
106+
(el): CraftingInputItemStruct => ({
107+
tokenType: "tokenId" in el.item ? 1155 : 20,
108+
tokenAddress: el.item.tokenAddrress,
109+
tokenId:
110+
"tokenId" in el.item ? (el.item as ERC1155Item).tokenId : 0,
111+
amount: el.item.amount,
112+
tokenAction: el.action,
113+
})
120114
)
121-
let craftingOutputs = recipe.craftingOutputs.map(
122-
(el): CraftingOutputItemStruct => {
123-
return {
124-
tokenType: "tokenId" in el.item ? 1155 : 20,
125-
tokenAddress: el.item.tokenAddrress,
126-
tokenId:
127-
"tokenId" in el.item
128-
? (el.item as ERC1155Item).tokenId
129-
: 0,
130-
amount: el.item.amount,
131-
tokenAction: el.action,
132-
}
133-
}
115+
const craftingOutputs = recipe.craftingOutputs.map(
116+
(el): CraftingOutputItemStruct => ({
117+
tokenType: "tokenId" in el.item ? 1155 : 20,
118+
tokenAddress: el.item.tokenAddrress,
119+
tokenId:
120+
"tokenId" in el.item ? (el.item as ERC1155Item).tokenId : 0,
121+
amount: el.item.amount,
122+
tokenAction: el.action,
123+
})
134124
)
135-
let recipeStruct: RecipeStruct = {
125+
const recipeStruct: RecipeStruct = {
136126
inputs: craftingInputs,
137127
outputs: craftingOutputs,
138128
isActive: recipe.isActive,
139129
}
140-
await (await this.contract.addRecipe(recipeStruct, overrides)).wait(1)
130+
const tx = await this.contract.addRecipe(recipeStruct)
131+
await tx.wait(1)
141132
return this.numRecipes()
142133
}
143134
public connect(_signer: ethers.Signer) {

sdk/src/contract-types/CraftingFacet.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ export interface CraftingFacet extends BaseContract {
274274
};
275275

276276
addRecipe(
277-
recipe: RecipeStruct,
278-
overrides?: Overrides & { from?: PromiseOrValue<string> }
277+
recipe: RecipeStruct
278+
// overrides?: Overrides & { from?: PromiseOrValue<string> }
279279
): Promise<ContractTransaction>;
280280

281281
craft(

sdk/src/example.ts

+19-14
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,53 @@ import {
99
} from "./index"
1010

1111
async function main() {
12-
let rpcUrl = process.env.RPC_URL
12+
const rpcUrl = process.env.RPC_URL
13+
const privateKey = process.env.PRIVATE_KEY
14+
1315
if (!rpcUrl) {
1416
throw new Error("RPC_URL env var is not set")
1517
}
18+
19+
if (!privateKey) {
20+
throw new Error("PRIVATE_KEY env var is not set")
21+
}
22+
1623
const provider = new ethers.providers.JsonRpcProvider(rpcUrl)
1724

18-
let craftingContract = new CraftingContract(
25+
const craftingContract = new CraftingContract(
1926
"0x8EA6A5EE9B9f7BCa384D804a12180473Ae4BE297",
2027
provider
2128
)
2229

23-
let recipesCount = await craftingContract.numRecipes()
30+
const recipesCount = await craftingContract.numRecipes()
2431
console.log(`There are ${recipesCount} recipes on this contract`)
2532
for (let i = 1; i <= recipesCount.toNumber(); ++i) {
2633
console.log(JSON.stringify(await craftingContract.getRecipe(i)))
2734
console.log()
2835
}
2936

30-
let privateKey = process.env.PRIVATE_KEY
31-
if (!privateKey) {
32-
throw new Error("PRIVATE_KEY env var is not set")
33-
}
3437
const signer = new ethers.Wallet(privateKey, provider)
3538

3639
craftingContract.connect(signer)
3740

38-
let emptyBottle: CraftingItem = {
41+
const emptyBottle: CraftingItem = {
3942
tokenAddrress: "0x0000000000000000000000000000000000000000",
4043
amount: "1",
4144
tokenId: "1",
4245
}
4346

44-
let milk: CraftingItem = {
47+
const milk: CraftingItem = {
4548
tokenAddrress: "0x0000000000000000000000000000000000000000",
4649
amount: "100000000000000000000", // 100 * 10^18, 100 unim
4750
}
4851

49-
let fullBottle: CraftingItem = {
52+
const fullBottle: CraftingItem = {
5053
tokenAddrress: "0x0000000000000000000000000000000000000000",
5154
amount: "1",
5255
tokenId: "2",
5356
}
5457

55-
let bottlingRecipe: CraftingRecipe = {
58+
const bottlingRecipe: CraftingRecipe = {
5659
isActive: true,
5760
craftingInputs: [
5861
{
@@ -72,10 +75,10 @@ async function main() {
7275
],
7376
}
7477
console.log("Adding bottling contract")
75-
let recipeId = await craftingContract.addRecipe(bottlingRecipe)
78+
const recipeId = await craftingContract.addRecipe(bottlingRecipe)
7679
console.log(`Bottling recipe is created with id: ${recipeId}`)
7780

78-
let unbottlingRecipe: CraftingRecipe = {
81+
const unbottlingRecipe: CraftingRecipe = {
7982
isActive: true,
8083
craftingInputs: [
8184
{
@@ -96,7 +99,9 @@ async function main() {
9699
}
97100

98101
console.log("Adding unbottling contract")
99-
let unbottlingRecipeId = await craftingContract.addRecipe(unbottlingRecipe)
102+
const unbottlingRecipeId = await craftingContract.addRecipe(
103+
unbottlingRecipe
104+
)
100105
console.log(`Unbottling recipe is created with id: ${unbottlingRecipeId}`)
101106
}
102107

0 commit comments

Comments
 (0)