diff --git a/sdk-usage/.env b/scripts/.env similarity index 100% rename from sdk-usage/.env rename to scripts/.env diff --git a/sdk-usage/.env.example b/scripts/.env.example similarity index 100% rename from sdk-usage/.env.example rename to scripts/.env.example diff --git a/scripts/addresses.json b/scripts/addresses.json deleted file mode 100644 index 953c481d..00000000 --- a/scripts/addresses.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "INVARIANT_CODE_HASH": "0xf8df019beec758c3ce53f9b697ecf29c7b9749fe5f3cb7c21ace0f86609c44a4", - "INVARIANT_ADDRESS": "5DNQ2JCwGip6iUuHgam2Y7FZHbJfJsr8M9AQCdVzkBV9LMSM" -} diff --git a/scripts/call.sh b/scripts/call.sh deleted file mode 100755 index bea7c17b..00000000 --- a/scripts/call.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -SEED="//Alice" -URL="wss://ws.test.azero.dev" -CONTRACT="5DNQ2JCwGip6iUuHgam2Y7FZHbJfJsr8M9AQCdVzkBV9LMSM" - -cargo contract call --suri "$SEED" --url "$URL" \ - --contract $CONTRACT \ - --message Invariant::get_protocol_fee \ - --execute \ - --skip-confirm - - -# cargo contract call ABI_PATH --suri "$SEED" --url "$URL" \ -# --contract 5DNQ2JCwGip6iUuHgam2Y7FZHbJfJsr8M9AQCdVzkBV9LMSM \ -# --message get_protocol_fee \ - \ No newline at end of file diff --git a/scripts/deploy.sh b/scripts/deploy.sh deleted file mode 100755 index 850ce322..00000000 --- a/scripts/deploy.sh +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/env bash - -# This script does the following: -# * deploys Invariant contract -# * instantiates them -# * stores addreses in the `addresses.json` file in the current directory -# -# What it does not do: -# * it doesn't build the contracts - assumes they're already built - -set -euo pipefail - -# Quiet versions of pushd and popd -pushd () { - command pushd "$@" > /dev/null -} - -popd () { - command popd "$@" > /dev/null -} - -CONTRACTS_PATH=$(pwd) -echo "Path ${CONTRACTS_PATH}" - -# Check if NODE_URL is localhost, and set a different URL accordingly -if [ "$n" == "localhost" ]; then - NODE_URL="ws://localhost:9944" - else - NODE_URL="wss://ws.test.azero.dev" -fi - -AUTHORITY_SEED=${AUTHORITY_SEED:="//Alice"} - -echo "node=${NODE_URL}" -echo "authority_seed=${AUTHORITY_SEED}" - -function upload_contract { - - local __resultvar=$1 - local contract_name=$2 - - echo "contract_name ${contract_name}" - - - pushd "$CONTRACTS_PATH"/$contract_name - - echo "Uploading ${contract_name}" - - # --- UPLOAD CONTRACT CODE - - code_hash=$(cargo contract upload --quiet --url "$NODE_URL" --suri "$AUTHORITY_SEED" --execute --skip-confirm) - code_hash=$(echo "${code_hash}" | grep hash | tail -1 | cut -c 14-) - - eval $__resultvar=${code_hash} - - popd -} - -function extract_contract_addresses { - jq '.events[] | select((.pallet == "Contracts") and (.name = "Instantiated")) | .fields[] | select(.name == "contract") | .value.Literal' -} - -function extract_from_quotes { - echo $1 | tr -d '"' -} - -upload_contract INVARIANT_CODE_HASH ./ -echo "Invariant code hash: ${INVARIANT_CODE_HASH}" - -# --- instantiate contract - -pushd ${CONTRACTS_PATH} - -# Using temporary file as piping JSON from env variable crates problems with escaping. -temp_file=$(mktemp) -# Remove temporary file when finished. -trap "rm -f $temp_file" 0 2 3 15 - -SALT=${INVARIANT_VERSION:-0} -INVARIANT_CONTRACT_FILE="target/ink/contract.contract" - -echo "Instantiating Invariant contract (version: ${SALT})" -cargo contract instantiate --url "$NODE_URL" --salt ${SALT} --suri "$AUTHORITY_SEED" $INVARIANT_CONTRACT_FILE --constructor new --args "0" --execute --skip-confirm --output-json > temp_file - -# No salt instantiation -# cargo contract instantiate --url "$NODE_URL" --suri "$AUTHORITY_SEED" $INVARIANT_CONTRACT_FILE --constructor new --args "1" --execute --skip-confirm --output-json > temp_file - -INVARIANT_ADDRESS=$(cat temp_file | jq '.events[] | select((.pallet == "Contracts") and (.name = "Instantiated")) | .fields[] | select(.name == "contract") | .value.Literal' | tail -1 | tr -d '"') -if [[ -z INVARIANT_ADDRESS && -v INVARIANT_ADDRESS ]]; then - echo "Empty INVARIANT_ADDRESS" - exit 1 -fi - -echo "Invariant instance address: ${INVARIANT_ADDRESS}" - -popd - -jq -n --arg INVARIANT_CODE_HASH "$INVARIANT_CODE_HASH" \ - --arg INVARIANT_ADDRESS "$INVARIANT_ADDRESS" \ - '{ - INVARIANT_CODE_HASH: $INVARIANT_CODE_HASH, - INVARIANT_ADDRESS: $INVARIANT_ADDRESS - }' > ${PWD}/scripts/addresses.json - -echo "Contract addresses stored in addresses.json" -exit 0 \ No newline at end of file diff --git a/sdk-usage/package-lock.json b/scripts/package-lock.json similarity index 93% rename from sdk-usage/package-lock.json rename to scripts/package-lock.json index 0c349e96..71fe3c52 100644 --- a/sdk-usage/package-lock.json +++ b/scripts/package-lock.json @@ -1,11 +1,11 @@ { - "name": "sdk-test", + "name": "scripts", "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "sdk-test", + "name": "scripts", "version": "1.0.0", "license": "ISC", "dependencies": { @@ -18,10 +18,10 @@ }, "../sdk": { "name": "@invariant-labs/a0-sdk", - "version": "0.2.10", + "version": "0.2.12", "license": "ISC", "dependencies": { - "@invariant-labs/a0-sdk-wasm": "^0.1.20", + "@invariant-labs/a0-sdk-wasm": "^0.1.21", "@polkadot/api": "^10.12.4", "@polkadot/api-contract": "^10.12.4", "@scio-labs/use-inkathon": "^0.6.3", diff --git a/sdk-usage/package.json b/scripts/package.json similarity index 98% rename from sdk-usage/package.json rename to scripts/package.json index b9630fe8..7c8477c8 100644 --- a/sdk-usage/package.json +++ b/scripts/package.json @@ -1,5 +1,5 @@ { - "name": "sdk-test", + "name": "scripts", "version": "1.0.0", "description": "", "main": "target/index.js", diff --git a/sdk-usage/src/create-pool.ts b/scripts/src/create-pool.ts similarity index 100% rename from sdk-usage/src/create-pool.ts rename to scripts/src/create-pool.ts diff --git a/sdk-usage/src/create-position.ts b/scripts/src/create-position.ts similarity index 100% rename from sdk-usage/src/create-position.ts rename to scripts/src/create-position.ts diff --git a/sdk-usage/src/deploy-invariant.ts b/scripts/src/deploy-invariant.ts similarity index 100% rename from sdk-usage/src/deploy-invariant.ts rename to scripts/src/deploy-invariant.ts diff --git a/sdk-usage/src/deploy-tokens.ts b/scripts/src/deploy-tokens.ts similarity index 100% rename from sdk-usage/src/deploy-tokens.ts rename to scripts/src/deploy-tokens.ts diff --git a/sdk-usage/src/index.ts b/scripts/src/index.ts similarity index 100% rename from sdk-usage/src/index.ts rename to scripts/src/index.ts diff --git a/sdk-usage/src/query-tickmap.ts b/scripts/src/query-tickmap.ts similarity index 100% rename from sdk-usage/src/query-tickmap.ts rename to scripts/src/query-tickmap.ts diff --git a/sdk-usage/src/setup.ts b/scripts/src/setup.ts similarity index 72% rename from sdk-usage/src/setup.ts rename to scripts/src/setup.ts index 636a4cb2..db2c74f8 100644 --- a/sdk-usage/src/setup.ts +++ b/scripts/src/setup.ts @@ -41,35 +41,52 @@ const main = async () => { const BTCAddress = await PSP22.deploy(api, account, 0n, 'Bitcoin', 'BTC', 8n) const ETHAddress = await PSP22.deploy(api, account, 0n, 'Ether', 'ETH', 12n) const USDCAddress = await PSP22.deploy(api, account, 0n, 'USDC', 'USDC', 6n) + const USDTAddress = await PSP22.deploy(api, account, 0n, 'Tether USD', 'USDT', 6n) + const SOLAddress = await PSP22.deploy(api, account, 0n, 'Solana', 'SOL', 9n) const decimals = { [BTCAddress]: 8n, [ETHAddress]: 12n, [USDCAddress]: 6n, + [USDTAddress]: 6n, + [SOLAddress]: 9n, [TESTNET_WAZERO_ADDRESS]: 12n } - console.log(`BTC: ${BTCAddress}, ETH: ${ETHAddress}, USDC: ${USDCAddress}`) + console.log( + `BTC: ${BTCAddress}, ETH: ${ETHAddress}, USDC: ${USDCAddress}, USDT: ${USDTAddress}, SOL: ${SOLAddress}` + ) const response = await fetch( - 'https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=bitcoin,ethereum,aleph-zero' + 'https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=bitcoin,ethereum,aleph-zero,solana' ) const data = await response.json() const prices = { [BTCAddress]: data.find((coin: any) => coin.id === 'bitcoin').current_price, [ETHAddress]: data.find((coin: any) => coin.id === 'ethereum').current_price, [USDCAddress]: 1, + [USDTAddress]: 1, + [SOLAddress]: data.find((coin: any) => coin.id === 'solana').current_price, [TESTNET_WAZERO_ADDRESS]: data.find((coin: any) => coin.id === 'aleph-zero').current_price } console.log( - `BTC: ${prices[BTCAddress]}, ETH: ${prices[ETHAddress]}, USDC: ${prices[USDCAddress]}, AZERO: ${prices[TESTNET_WAZERO_ADDRESS]}` + `BTC: ${prices[BTCAddress]}, ETH: ${prices[ETHAddress]}, USDC: ${prices[USDCAddress]}, USDT: ${prices[USDTAddress]}, SOL: ${prices[SOLAddress]}, AZERO: ${prices[TESTNET_WAZERO_ADDRESS]}` ) const poolKeys: [PoolKey, bigint][] = [ [newPoolKey(TESTNET_WAZERO_ADDRESS, BTCAddress, FEE_TIERS[1]), 10804609546189987720n], [newPoolKey(TESTNET_WAZERO_ADDRESS, ETHAddress, FEE_TIERS[1]), 4711830510277394610468n], [newPoolKey(TESTNET_WAZERO_ADDRESS, USDCAddress, FEE_TIERS[1]), 272063075569508447756n], + [newPoolKey(TESTNET_WAZERO_ADDRESS, USDTAddress, FEE_TIERS[1]), 272063075569508447756n], + [newPoolKey(TESTNET_WAZERO_ADDRESS, SOLAddress, FEE_TIERS[1]), 37143700245489847211n], [newPoolKey(BTCAddress, ETHAddress, FEE_TIERS[1]), 130559235944405760n], [newPoolKey(BTCAddress, USDCAddress, FEE_TIERS[1]), 7865049221247086n], - [newPoolKey(ETHAddress, USDCAddress, FEE_TIERS[1]), 3454809855596621497n] + [newPoolKey(BTCAddress, USDTAddress, FEE_TIERS[1]), 7865049221247086n], + [newPoolKey(BTCAddress, SOLAddress, FEE_TIERS[1]), 977937074251981n], + [newPoolKey(ETHAddress, USDCAddress, FEE_TIERS[1]), 3454809855596621497n], + [newPoolKey(ETHAddress, USDTAddress, FEE_TIERS[1]), 3454809855596621497n], + [newPoolKey(ETHAddress, SOLAddress, FEE_TIERS[1]), 423131631710393596n], + [newPoolKey(USDCAddress, USDTAddress, FEE_TIERS[1]), 9999818389598293n], + [newPoolKey(USDCAddress, SOLAddress, FEE_TIERS[1]), 24911294718392400n], + [newPoolKey(USDTAddress, SOLAddress, FEE_TIERS[1]), 24911294718392400n] ] for (const [poolKey] of poolKeys) { const price = @@ -93,9 +110,13 @@ const main = async () => { await psp22.mint(account, 2n ** 96n - 1n, BTCAddress) await psp22.mint(account, 2n ** 96n - 1n, ETHAddress) await psp22.mint(account, 2n ** 96n - 1n, USDCAddress) + await psp22.mint(account, 2n ** 96n - 1n, USDTAddress) + await psp22.mint(account, 2n ** 96n - 1n, SOLAddress) await psp22.approve(account, invariant.contract.address.toString(), 2n ** 96n - 1n, BTCAddress) await psp22.approve(account, invariant.contract.address.toString(), 2n ** 96n - 1n, ETHAddress) await psp22.approve(account, invariant.contract.address.toString(), 2n ** 96n - 1n, USDCAddress) + await psp22.approve(account, invariant.contract.address.toString(), 2n ** 96n - 1n, USDTAddress) + await psp22.approve(account, invariant.contract.address.toString(), 2n ** 96n - 1n, SOLAddress) const wazero = await WrappedAZERO.load(api, network, TESTNET_WAZERO_ADDRESS, { storageDepositLimit: 100000000000, refTime: 100000000000, @@ -103,7 +124,7 @@ const main = async () => { }) const wazeroBalance = await wazero.balanceOf(account.address) await wazero.withdraw(account, wazeroBalance) - await wazero.deposit(account, 30000n * 10n ** 12n) + await wazero.deposit(account, 50000n * 10n ** 12n) await psp22.approve( account, invariant.contract.address.toString(), @@ -113,6 +134,8 @@ const main = async () => { const BTCBefore = await psp22.balanceOf(account.address, BTCAddress) const ETHBefore = await psp22.balanceOf(account.address, ETHAddress) const USDCBefore = await psp22.balanceOf(account.address, USDCAddress) + const USDTBefore = await psp22.balanceOf(account.address, USDTAddress) + const SOLBefore = await psp22.balanceOf(account.address, SOLAddress) const WAZEROBefore = await psp22.balanceOf(account.address, TESTNET_WAZERO_ADDRESS) for (const [poolKey, amount] of poolKeys) { const price = @@ -141,11 +164,15 @@ const main = async () => { const BTCAfter = await psp22.balanceOf(account.address, BTCAddress) const ETHAfter = await psp22.balanceOf(account.address, ETHAddress) const USDCAfter = await psp22.balanceOf(account.address, USDCAddress) + const USDTAfter = await psp22.balanceOf(account.address, USDTAddress) + const SOLAfter = await psp22.balanceOf(account.address, SOLAddress) const WAZEROAfter = await psp22.balanceOf(account.address, TESTNET_WAZERO_ADDRESS) console.log( `BTC: ${BTCBefore - BTCAfter}, ETH: ${ETHBefore - ETHAfter}, USDC: ${ USDCBefore - USDCAfter - }, AZERO: ${WAZEROBefore - WAZEROAfter}` + }, USDT: ${USDTBefore - USDTAfter}, SOL: ${SOLBefore - SOLAfter}, AZERO: ${ + WAZEROBefore - WAZEROAfter + }` ) console.log('Successfully created positions') diff --git a/sdk-usage/src/swap.ts b/scripts/src/swap.ts similarity index 100% rename from sdk-usage/src/swap.ts rename to scripts/src/swap.ts diff --git a/sdk-usage/tests.sh b/scripts/tests.sh similarity index 92% rename from sdk-usage/tests.sh rename to scripts/tests.sh index 54ea583f..db2fabe8 100755 --- a/sdk-usage/tests.sh +++ b/scripts/tests.sh @@ -8,7 +8,7 @@ cd sdk npm run node:start & sleep 5 cd .. -cd sdk-usage +cd scripts npm i npm run start & test_pid=$! diff --git a/sdk-usage/tsconfig.json b/scripts/tsconfig.json similarity index 100% rename from sdk-usage/tsconfig.json rename to scripts/tsconfig.json diff --git a/scripts/update_contract_addresses.sh b/scripts/update_contract_addresses.sh deleted file mode 100755 index 8f7036d2..00000000 --- a/scripts/update_contract_addresses.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -# This script copies `addresses.json` files from ./scriptes directory into frontend metadata. -# This is required so that the frontend can interact with deployed contracts. -set -euo pipefail - -cp $(pwd)/scripts/addresses.json $(pwd)/frontend/src/metadata/ -exit 0 \ No newline at end of file diff --git a/scripts/update_contract_metadata.sh b/scripts/update_contract_metadata.sh deleted file mode 100644 index ee35da19..00000000 --- a/scripts/update_contract_metadata.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash - -# This script copies `metadata.json` files from contracts' target directories into frontend metadata. -# This is required so that the frontend can interact with deployed contracts. -set -euo pipefail - -CONTRACTS_PATH=$(pwd)/contracts - -METADATA_FILE=/target/ink/metadata.json -BULLETIN_BOARD_METADATA=$(pwd)/frontend/src/metadata/metadata_bulletin_board.json -HIGHLIHTED_POSTS_METADATA=$(pwd)/frontend/src/metadata/metadata_highlighted_posts.json - -cp ${CONTRACTS_PATH}/bulletin_board/target/ink/bulletin_board.json ${BULLETIN_BOARD_METADATA} -cp ${CONTRACTS_PATH}/highlighted_posts/target/ink/highlighted_posts.json ${HIGHLIHTED_POSTS_METADATA} - -echo "Contract metadata updated" -exit 0 \ No newline at end of file diff --git a/sdk/package-lock.json b/sdk/package-lock.json index 4aedd251..1490d5ea 100644 --- a/sdk/package-lock.json +++ b/sdk/package-lock.json @@ -1,12 +1,12 @@ { "name": "@invariant-labs/a0-sdk", - "version": "0.2.12", + "version": "0.2.13", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@invariant-labs/a0-sdk", - "version": "0.2.12", + "version": "0.2.13", "license": "ISC", "dependencies": { "@invariant-labs/a0-sdk-wasm": "^0.1.21", diff --git a/sdk/package.json b/sdk/package.json index 20d5e085..a2b497f0 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@invariant-labs/a0-sdk", - "version": "0.2.12", + "version": "0.2.13", "collaborators": [ "Invariant Labs" ], diff --git a/sdk/src/consts.ts b/sdk/src/consts.ts index 9cd093e7..694c44a3 100644 --- a/sdk/src/consts.ts +++ b/sdk/src/consts.ts @@ -37,10 +37,12 @@ export const DEFAULT_LOCAL = 'ws://127.0.0.1:9944' export const TESTNET_WAZERO_ADDRESS = '5EFDb7mKbougLtr5dnwd5KDfZ3wK55JPGPLiryKq4uRMPR46' -export const TESTNET_INVARIANT_ADDRESS = '5FxTEpmxrqr8Nwx7u1Y7heTFJiSe8xU1zZMfWmuC5f1UJMbf' -export const TESTNET_BTC_ADDRESS = '5DPvVudq6bCZ84jwFSsRwD7hDh4aaGh7XzpJUKXWDDHMHXaL' -export const TESTNET_ETH_ADDRESS = '5GmqniLhEcZCsn7vrer6yHzn7giapNG6N4fHx9exXHn29MvC' -export const TESTNET_USDC_ADDRESS = '5Cr6gjWk5cUavkbo9d6GTZBGjf4XavQf6WpiLkgT9UCmGQYP' +export const TESTNET_INVARIANT_ADDRESS = '5FU7vwthg7LDANp2Ljmw4gYdBY8rAF2UeS3rtM4sFZfnFNXv' +export const TESTNET_BTC_ADDRESS = '5FsnMq7UCvkaniSKiLdas2ujqRfKNiUehE21pQ4eCtZ4Hdgm' +export const TESTNET_ETH_ADDRESS = '5E3MV1sZQSav3BCf9aucDnZ79vRLWWE2eZbuy5dbNbj62qwN' +export const TESTNET_USDC_ADDRESS = '5Duwky8RAzWFKb8GNYcejjmxAAU2EkxPgeWCxMtvcsPdKtHm' +export const TESTNET_USDT_ADDRESS = '5FR9i4PwD9T3fokcLocyzWLCfUs7CstGRnwUSVovMDhnDxrz' +export const TESTNET_SOL_ADDRESS = '5CRMY8uap4JAQPcoJiaM4bHnuHjZLxRWRzYWh118BNiMsPW5' export const FEE_GROWTH_DENOMINATOR = getFeeGrowthDenominator() export const FIXED_POINT_DENOMINATOR = getFixedPointDenominator()