Skip to content

Commit

Permalink
chore: use prettier to format more things.
Browse files Browse the repository at this point in the history
  • Loading branch information
kovipu committed Aug 19, 2024
1 parent fa756f3 commit f6b6569
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 103 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ jobs:
node-version: 22.6.0
cache: 'npm'
- run: npm ci
- run: npm run prettier:check
- run: npm run biome:check
- run: npm run lint:check
- run: npm run format:check
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
build/
dist/
contracts/
package-lock.json
4 changes: 2 additions & 2 deletions .prettierrc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const config = {
singleQuote: true,
jsxSingleQuote: false,
bracketSpacing: true,
semi: true
}
semi: true,
};

export default config;
12 changes: 6 additions & 6 deletions astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { defineConfig } from 'astro/config';
import basicSsl from '@vitejs/plugin-basic-ssl';
import react from "@astrojs/react";
import react from '@astrojs/react';

import tailwind from "@astrojs/tailwind";
import tailwind from '@astrojs/tailwind';

// https://astro.build/config
export default defineConfig({
vite: {
plugins: [basicSsl()],
server: {
https: true
}
https: true,
},
},
integrations: [react(), tailwind()]
});
integrations: [react(), tailwind()],
});
170 changes: 90 additions & 80 deletions initialize.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import 'dotenv/config'
import { mkdirSync, readdirSync, statSync, writeFileSync } from 'fs'
import { execSync } from 'child_process'
import path from 'path'
import { fileURLToPath } from 'url'
import crypto from 'crypto'
import 'dotenv/config';
import { mkdirSync, readdirSync, statSync, writeFileSync } from 'fs';
import { execSync } from 'child_process';
import path from 'path';
import { fileURLToPath } from 'url';
import crypto from 'crypto';

// Load environment variables starting with PUBLIC_ into the environment,
// so we don't need to specify duplicate variables in .env
for (const key in process.env) {
if (key.startsWith('PUBLIC_')) {
process.env[key.substring(7)] = process.env[key]
process.env[key.substring(7)] = process.env[key];
}
}

Expand All @@ -20,53 +20,55 @@ const GENESIS_ACCOUNTS = {
public: 'GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7',
testnet: 'GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H',
futurenet: 'GADNDFP7HM3KFVHOQBBJDBGRONMKQVUYKXI6OYNDMS2ZIK7L6HA3F2RF',
standalone: 'GBZXN7PIRZGNMHGA7MUUUF4GWPY5AYPV6LY4UV2GL6VJGIQRXFDNMADI'
}
standalone: 'GBZXN7PIRZGNMHGA7MUUUF4GWPY5AYPV6LY4UV2GL6VJGIQRXFDNMADI',
};

console.log('###################### Initializing ########################')
console.log('###################### Initializing ########################');

// Get dirname (equivalent to the Bash version)
const __filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(__filename)
const __filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(__filename);

// variable for later setting pinned version of soroban in "$(dirname/target/bin/soroban)"
const soroban = 'soroban'
const soroban = 'soroban';

// Function to execute and log shell commands
function exe (command) {
console.log(command)
execSync(command, { stdio: 'inherit' })
function exe(command) {
console.log(command);
execSync(command, { stdio: 'inherit' });
}

function fundAll () {
exe(`${soroban} keys generate ${process.env.SOROBAN_ACCOUNT}`)
exe(`${soroban} keys fund ${process.env.SOROBAN_ACCOUNT}`)
function fundAll() {
exe(`${soroban} keys generate ${process.env.SOROBAN_ACCOUNT}`);
exe(`${soroban} keys fund ${process.env.SOROBAN_ACCOUNT}`);
}

function buildAll () {
exe(`rm -f ${dirname}/target/wasm32-unknown-unknown/release/*.wasm`)
exe(`rm -f ${dirname}/target/wasm32-unknown-unknown/release/*.d`)
function buildAll() {
exe(`rm -f ${dirname}/target/wasm32-unknown-unknown/release/*.wasm`);
exe(`rm -f ${dirname}/target/wasm32-unknown-unknown/release/*.d`);
// Tokens has to be built before others.
exe(`${soroban} contract build --package token`)
exe(`${soroban} contract build --package token`);
// Then loan_pool as loan_pool uses it
exe(`${soroban} contract build --package loan_pool`)
exe(`${soroban} contract build`)
exe(`${soroban} contract build --package loan_pool`);
exe(`${soroban} contract build`);
}

function filenameNoExtension (filename) {
return path.basename(filename, path.extname(filename))
function filenameNoExtension(filename) {
return path.basename(filename, path.extname(filename));
}

function deploy (wasm) {
exe(`(${soroban} contract deploy --wasm ${wasm} --ignore-checks) > ${dirname}/.soroban/contract-ids/${filenameNoExtension(wasm)}.txt`)
function deploy(wasm) {
exe(
`(${soroban} contract deploy --wasm ${wasm} --ignore-checks) > ${dirname}/.soroban/contract-ids/${filenameNoExtension(wasm)}.txt`,
);
}

function deployFactory () {
const contractsDir = `${dirname}/.soroban/contract-ids`
mkdirSync(contractsDir, { recursive: true })
function deployFactory() {
const contractsDir = `${dirname}/.soroban/contract-ids`;
mkdirSync(contractsDir, { recursive: true });

// try to deploy only factory contract that will be used to generate others. Maybe later it has to be some sort of admin contract?
deploy(`${dirname}/target/wasm32-unknown-unknown/release/factory.wasm`)
deploy(`${dirname}/target/wasm32-unknown-unknown/release/factory.wasm`);
// Deploy loans contract as there will only be one for all
// deploy(`${dirname}/target/wasm32-unknown-unknown/release/loans.wasm`)

Expand All @@ -77,64 +79,72 @@ function deployFactory () {
// });
}

function install (wasm) {
function install(wasm) {
// Contract installer
exe(`(${soroban} contract install --wasm ${wasm} --ignore-checks) > ${dirname}/.soroban/contract-wasm-hash/${filenameNoExtension(wasm)}.txt`)
exe(
`(${soroban} contract install --wasm ${wasm} --ignore-checks) > ${dirname}/.soroban/contract-wasm-hash/${filenameNoExtension(wasm)}.txt`,
);
}

function installAll () {
function installAll() {
// Install all contracts except factory and save the wasm hash to .soroban
const contractsDir = `${dirname}/.soroban/contract-wasm-hash`
mkdirSync(contractsDir, { recursive: true })
const contractsDir = `${dirname}/.soroban/contract-wasm-hash`;
mkdirSync(contractsDir, { recursive: true });

const wasmFiles = readdirSync(`${dirname}/target/wasm32-unknown-unknown/release`)
.filter(file => file.endsWith('.wasm'))
.filter(file => file !== 'factory.wasm')
.filter((file) => file.endsWith('.wasm'))
.filter((file) => file !== 'factory.wasm');

wasmFiles.forEach(wasmFile => {
install(`${dirname}/target/wasm32-unknown-unknown/release/${wasmFile}`)
})
wasmFiles.forEach((wasmFile) => {
install(`${dirname}/target/wasm32-unknown-unknown/release/${wasmFile}`);
});
}

function deployLpWithFactory () {
function deployLpWithFactory() {
// Deploy liquidity pool with factory contract

// Read values of parameters
const contractId = execSync(`cat ${dirname}/.soroban/contract-ids/factory.txt`).toString().trim();
const wasmHash = execSync(`cat ${dirname}/.soroban/contract-wasm-hash/loan_pool.txt`).toString().trim();
const shareTokenBytes = execSync(`cat ${dirname}/.soroban/contract-wasm-hash/token.txt`).toString().trim();
const xlmTokenAddress = "CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC"
const usdcTokenAddress = "CBIELTK6YBZJU5UP2WWQEUCYKLPU6AUNZ2BQ4WWFEIE3USCIHMXQDAMA"
const xlmTokenAddress = 'CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC';
const usdcTokenAddress = 'CBIELTK6YBZJU5UP2WWQEUCYKLPU6AUNZ2BQ4WWFEIE3USCIHMXQDAMA';
// Generate salt
const salt1 = crypto.randomBytes(32).toString('hex');
const salt2 = crypto.randomBytes(32).toString('hex');

exe(`${soroban} contract invoke --id ${contractId} --source-account alice --network testnet -- deploy --wasm_hash ${wasmHash} --salt ${salt1} --init_fn initialize --token_wasm_hash ${shareTokenBytes} --token_contract ${xlmTokenAddress} | tr -d '"' > ${dirname}/.soroban/contract-ids/loan_pool.txt`);
exe(`${soroban} contract invoke --id ${contractId} --source-account alice --network testnet -- deploy --wasm_hash ${wasmHash} --salt ${salt2} --init_fn initialize --token_wasm_hash ${shareTokenBytes} --token_contract ${usdcTokenAddress} | tr -d '"' > ${dirname}/.soroban/contract-ids/usdc_pool.txt`);
exe(
`${soroban} contract invoke --id ${contractId} --source-account alice --network testnet -- deploy --wasm_hash ${wasmHash} --salt ${salt1} --init_fn initialize --token_wasm_hash ${shareTokenBytes} --token_contract ${xlmTokenAddress} | tr -d '"' > ${dirname}/.soroban/contract-ids/loan_pool.txt`,
);
exe(
`${soroban} contract invoke --id ${contractId} --source-account alice --network testnet -- deploy --wasm_hash ${wasmHash} --salt ${salt2} --init_fn initialize --token_wasm_hash ${shareTokenBytes} --token_contract ${usdcTokenAddress} | tr -d '"' > ${dirname}/.soroban/contract-ids/usdc_pool.txt`,
);
}

function bind (contract) {
const filenameNoExt = filenameNoExtension(contract)
exe(`${soroban} contract bindings typescript --contract-id $(cat ${contract}) --output-dir ${dirname}/packages/${filenameNoExt} --overwrite`)
function bind(contract) {
const filenameNoExt = filenameNoExtension(contract);
exe(
`${soroban} contract bindings typescript --contract-id $(cat ${contract}) --output-dir ${dirname}/packages/${filenameNoExt} --overwrite`,
);
}

function bindAll () {
const contractIdsDir = `${dirname}/.soroban/contract-ids`
const contractFiles = readdirSync(contractIdsDir)
function bindAll() {
const contractIdsDir = `${dirname}/.soroban/contract-ids`;
const contractFiles = readdirSync(contractIdsDir);

contractFiles.forEach(contractFile => {
const contractPath = path.join(contractIdsDir, contractFile)
contractFiles.forEach((contractFile) => {
const contractPath = path.join(contractIdsDir, contractFile);
if (statSync(contractPath).size > 0) {
// Check if file is not empty
bind(contractPath)
bind(contractPath);
}
})
});
}

function importContract (contract) {
const filenameNoExt = filenameNoExtension(contract)
const outputDir = `${dirname}/src/contracts/`
mkdirSync(outputDir, { recursive: true })
function importContract(contract) {
const filenameNoExt = filenameNoExtension(contract);
const outputDir = `${dirname}/src/contracts/`;
mkdirSync(outputDir, { recursive: true });

/* eslint-disable quotes */
/* eslint-disable no-constant-condition */
Expand All @@ -146,33 +156,33 @@ function importContract (contract) {
` rpcUrl,\n` +
`${process.env.SOROBAN_NETWORK === 'local' || 'standalone' ? ` allowHttp: true,\n` : null}` +
` publicKey: '${GENESIS_ACCOUNTS[process.env.SOROBAN_NETWORK]}',\n` +
`});\n`
`});\n`;
/* eslint-disable no-constant-condition */
/* eslint-enable quotes */

const outputPath = `${outputDir}/${filenameNoExt}.ts`
writeFileSync(outputPath, importContent)
console.log(`Created import for ${filenameNoExt}`)
const outputPath = `${outputDir}/${filenameNoExt}.ts`;
writeFileSync(outputPath, importContent);
console.log(`Created import for ${filenameNoExt}`);
}

function importAll () {
const contractIdsDir = `${dirname}/.soroban/contract-ids`
const contractFiles = readdirSync(contractIdsDir)
function importAll() {
const contractIdsDir = `${dirname}/.soroban/contract-ids`;
const contractFiles = readdirSync(contractIdsDir);

contractFiles.forEach(contractFile => {
const contractPath = path.join(contractIdsDir, contractFile)
contractFiles.forEach((contractFile) => {
const contractPath = path.join(contractIdsDir, contractFile);
if (statSync(contractPath).size > 0) {
// Check if file is not empty
importContract(contractPath)
importContract(contractPath);
}
})
});
}

// Calling the functions (equivalent to the last part of your bash script)
fundAll()
buildAll()
deployFactory()
installAll()
deployLpWithFactory()
bindAll()
importAll()
fundAll();
buildAll();
deployFactory();
installAll();
deployLpWithFactory();
bindAll();
importAll();
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
"start": "npm run init && astro dev",
"continue": "astro dev",
"lint": "biome check --write ./src",
"format": "prettier --write ./src",
"prettier:check": "prettier --check ./src",
"biome:check": "biome check ./src"
"lint:check": "biome check ./src",
"format": "prettier --write \"**/*.{js,mjs,jsx,ts,tsx,json,graphql,css,astro,md}\"",
"format:check": "prettier --check \"**/*.{js,mjs,jsx,ts,tsx,json,graphql,css,astro,md}\""
},
"type": "module",
"version": "0.0.1",
Expand Down
12 changes: 6 additions & 6 deletions tailwind.config.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/** @type {import('tailwindcss').Config} */
export default {
content: ['./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}'],
theme: {
extend: {},
},
plugins: [],
}
content: ['./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}'],
theme: {
extend: {},
},
plugins: [],
};
6 changes: 2 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"extends": "astro/tsconfigs/strictest",
"exclude": [
"packages"
],
"exclude": ["packages"],
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "react"
}
}
}

0 comments on commit f6b6569

Please sign in to comment.