Skip to content

Commit

Permalink
refactor: use zx for creating vaults
Browse files Browse the repository at this point in the history
  • Loading branch information
rabi-siddique committed Dec 18, 2024
1 parent 5ce73f8 commit 870a7dc
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 103 deletions.
19 changes: 2 additions & 17 deletions .github/actions/createVault/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,5 @@ inputs:
required: true

runs:
using: 'composite'
steps:
- name: Create Vault
shell: bash
run: |
createVaultCommand="/usr/src/agoric-sdk/packages/agoric-cli/bin/agops vaults open --wantMinted \"${{ inputs.wantMinted }}\" --giveCollateral \"${{ inputs.giveCollateral }}\" > /tmp/want-ist.json"
echo "Executing create vault command in the container..."
docker exec ${{ inputs.containerName }} /bin/bash -c "env AGORIC_NET=${{ inputs.agoricNet }} timeout ${{ inputs.commandTimeout }} $createVaultCommand"
- name: Broadcast Offer
shell: bash
run: |
broadcastCommand="/usr/src/agoric-sdk/packages/agoric-cli/bin/agops perf satisfaction --executeOffer /tmp/want-ist.json --from \"${{ inputs.userKey }}\" --keyring-backend=test"
echo "Executing broadcast command in the container..."
docker exec ${{ inputs.containerName }} /bin/bash -c "env AGORIC_NET=${{ inputs.agoricNet }} timeout ${{ inputs.commandTimeout }} $broadcastCommand"
using: 'node20'
main: 'createVault.mjs'
62 changes: 62 additions & 0 deletions .github/actions/createVault/createVault.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env zx

import { $ } from 'zx';

/**
* Creates a vault by executing a command in a Docker container.
*
* @param {string} containerName - The name of the Docker container where the command will be executed.
* @param {string} agoricNet - The network configuration for the Agoric CLI.
* @param {string} commandTimeout - The maximum time in seconds for the command to complete.
* @param {string} wantMinted - The amount of ISTs to be minted by the vault.
* @param {string} giveCollateral - The amount of ATOMs to secure the minted currency.
*/
const createVault = async (containerName, agoricNet, commandTimeout, userKey, wantMinted, giveCollateral) => {
console.log('Starting the vault creation process...');
const agops = '/usr/src/agoric-sdk/packages/agoric-cli/bin/agops';

let res = await $`docker ps`;
console.log('test.........', res);

res = await $`ls /usr/`;
console.log('usr.........', res);

res = await $`ls /usr/src`;
console.log('src.........', res);

res = await $`find / -type d -name "agoric-sdk" 2>/dev/null`
console.log('sdk dir.........', res);

const createVaultCommand = `${agops} vaults open --wantMinted \"${wantMinted}\" --giveCollateral \"${giveCollateral}\" > /tmp/want-ist.json`;
const executeCreateVaultCommand = `docker exec ${containerName} /bin/bash -c "env AGORIC_NET=${agoricNet} timeout ${commandTimeout} ${createVaultCommand}"`;
try {
if (!containerName || !agoricNet || !commandTimeout || !userKey || !wantMinted || !giveCollateral) {
console.error('Missing required parameters.');
process.exit(1);
}

// Improved logging for debugging
console.log(`Command to execute: ${executeCreateVaultCommand}`);

await $`${executeCreateVaultCommand}`;
console.log('Executing broadcast command...');
const broadcastCommand = `timeout ${commandTimeout} ${agops} perf satisfaction --executeOffer /tmp/want-ist.json --from ${userKey} --keyring-backend=test`;
const executeBroadcastCommand = `docker exec ${containerName} AGORIC_NET=${agoricNet} ${broadcastCommand}`;

await $`${executeBroadcastCommand}`;
console.log('Offer broadcast successfully.');
} catch (error) {
console.error('Error during vault creation:', error);
process.exit(1);
}
};

const containerName = process.env.INPUT_CONTAINERNAME;
const agoricNet = process.env.INPUT_AGORICNET;
const commandTimeout = process.env.INPUT_COMMANDTIMEOUT;
const userKey = process.env.INPUT_USERKEY;
const wantMinted = process.env.INPUT_WANTMINTED;
const giveCollateral = process.env.INPUT_GIVECOLLATERAL;

console.log('ARGS:', { containerName, agoricNet, commandTimeout, userKey, wantMinted, giveCollateral });
createVault(containerName, agoricNet, commandTimeout, userKey, wantMinted, giveCollateral);
170 changes: 85 additions & 85 deletions .github/workflows/liquidation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,29 @@ jobs:
- name: Install dependencies
run: yarn install

- name: Start subql indexer
env:
AGORIC_NET: ci
run: yarn dev

- name: Print initial logs of all containers
run: |
echo "Fetching initial logs for all containers..."
containers=$(docker ps --format '{{.ID}}')
for container in $containers; do
echo "Fetching initial logs for container $container..."
docker logs $container
done
- name: Set ATOM Price to 12.34
run: |
docker exec agd /usr/src/agoric-sdk/packages/agoric-cli/bin/agops oracle setPrice --keys gov1,gov2 --pair ATOM.USD --price 12.34 --keyring-backend=test
- name: Get active vaults
uses: ./.github/actions/getActiveVaults
with:
apiUrl: 'http://localhost:3000/'
expectedVaults: 7
# - name: Start subql indexer
# env:
# AGORIC_NET: ci
# run: yarn dev

# - name: Print initial logs of all containers
# run: |
# echo "Fetching initial logs for all containers..."
# containers=$(docker ps --format '{{.ID}}')
# for container in $containers; do
# echo "Fetching initial logs for container $container..."
# docker logs $container
# done

# - name: Set ATOM Price to 12.34
# run: |
# docker exec agd /usr/src/agoric-sdk/packages/agoric-cli/bin/agops oracle setPrice --keys gov1,gov2 --pair ATOM.USD --price 12.34 --keyring-backend=test

# - name: Get active vaults
# uses: ./.github/actions/getActiveVaults
# with:
# apiUrl: 'http://localhost:3000/'
# expectedVaults: 7

- name: Create Vault with 100 Minted and 15 Collateral
uses: ./.github/actions/createVault
Expand All @@ -57,65 +57,65 @@ jobs:
commandTimeout: '120'
containerName: 'agd'

- name: Create Vault with 103 Minted and 15 Collateral
uses: ./.github/actions/createVault
with:
wantMinted: '103'
giveCollateral: '15'
userKey: 'gov3'
agoricNet: 'local'
commandTimeout: '120'
containerName: 'agd'

- name: Create Vault with 105 Minted and 15 Collateral
uses: ./.github/actions/createVault
with:
wantMinted: '105'
giveCollateral: '15'
userKey: 'gov3'
agoricNet: 'local'
commandTimeout: '120'
containerName: 'agd'

- name: Get active vaults
uses: ./.github/actions/getActiveVaults
with:
apiUrl: 'http://localhost:3000/'
expectedVaults: 10

- name: Place bid for 90IST
uses: ./.github/actions/placeBid
with:
fromAddress: 'gov1'
giveAmount: '90IST'
priceOrDiscount: '9'
commandType: 'by-price'
agoricNet: 'local'
commandTimeout: '120'
containerName: 'agd'

- name: Place bid for 80IST
uses: ./.github/actions/placeBid
with:
fromAddress: 'gov1'
giveAmount: '80IST'
priceOrDiscount: '10'
commandType: 'by-discount'
agoricNet: 'local'
commandTimeout: '120'
containerName: 'agd'

- name: Place bid for 150IST
uses: ./.github/actions/placeBid
with:
fromAddress: 'gov1'
giveAmount: '150IST'
priceOrDiscount: '15'
commandType: 'by-discount'
agoricNet: 'local'
commandTimeout: '120'
containerName: 'agd'

- name: Set ATOM Price to 9.99
run: |
docker exec agd /usr/src/agoric-sdk/packages/agoric-cli/bin/agops oracle setPrice --keys gov1,gov2 --pair ATOM.USD --price 9.99 --keyring-backend=test
# - name: Create Vault with 103 Minted and 15 Collateral
# uses: ./.github/actions/createVault
# with:
# wantMinted: '103'
# giveCollateral: '15'
# userKey: 'gov3'
# agoricNet: 'local'
# commandTimeout: '120'
# containerName: 'agd'

# - name: Create Vault with 105 Minted and 15 Collateral
# uses: ./.github/actions/createVault
# with:
# wantMinted: '105'
# giveCollateral: '15'
# userKey: 'gov3'
# agoricNet: 'local'
# commandTimeout: '120'
# containerName: 'agd'

# - name: Get active vaults
# uses: ./.github/actions/getActiveVaults
# with:
# apiUrl: 'http://localhost:3000/'
# expectedVaults: 10

# - name: Place bid for 90IST
# uses: ./.github/actions/placeBid
# with:
# fromAddress: 'gov1'
# giveAmount: '90IST'
# priceOrDiscount: '9'
# commandType: 'by-price'
# agoricNet: 'local'
# commandTimeout: '120'
# containerName: 'agd'

# - name: Place bid for 80IST
# uses: ./.github/actions/placeBid
# with:
# fromAddress: 'gov1'
# giveAmount: '80IST'
# priceOrDiscount: '10'
# commandType: 'by-discount'
# agoricNet: 'local'
# commandTimeout: '120'
# containerName: 'agd'

# - name: Place bid for 150IST
# uses: ./.github/actions/placeBid
# with:
# fromAddress: 'gov1'
# giveAmount: '150IST'
# priceOrDiscount: '15'
# commandType: 'by-discount'
# agoricNet: 'local'
# commandTimeout: '120'
# containerName: 'agd'

# - name: Set ATOM Price to 9.99
# run: |
# docker exec agd /usr/src/agoric-sdk/packages/agoric-cli/bin/agops oracle setPrice --keys gov1,gov2 --pair ATOM.USD --price 9.99 --keyring-backend=test
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"@subql/testing": "latest",
"prettier": "^3.4.2",
"starknet": "6.11.0",
"typescript": "^5.7.2"
"typescript": "^5.7.2",
"zx": "^8.2.4"
},
"dependencies": {
"@subql/types-cosmos": "^4.0.0",
Expand Down
46 changes: 46 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3617,6 +3617,16 @@ __metadata:
languageName: node
linkType: hard

"@types/fs-extra@npm:>=11":
version: 11.0.4
resolution: "@types/fs-extra@npm:11.0.4"
dependencies:
"@types/jsonfile": "npm:*"
"@types/node": "npm:*"
checksum: 10c0/9e34f9b24ea464f3c0b18c3f8a82aefc36dc524cc720fc2b886e5465abc66486ff4e439ea3fb2c0acebf91f6d3f74e514f9983b1f02d4243706bdbb7511796ad
languageName: node
linkType: hard

"@types/glob@npm:*":
version: 8.1.0
resolution: "@types/glob@npm:8.1.0"
Expand Down Expand Up @@ -3678,6 +3688,15 @@ __metadata:
languageName: node
linkType: hard

"@types/jsonfile@npm:*":
version: 6.1.4
resolution: "@types/jsonfile@npm:6.1.4"
dependencies:
"@types/node": "npm:*"
checksum: 10c0/b12d068b021e4078f6ac4441353965769be87acf15326173e2aea9f3bf8ead41bd0ad29421df5bbeb0123ec3fc02eb0a734481d52903704a1454a1845896b9eb
languageName: node
linkType: hard

"@types/keyv@npm:^3.1.1":
version: 3.1.4
resolution: "@types/keyv@npm:3.1.4"
Expand Down Expand Up @@ -3747,6 +3766,15 @@ __metadata:
languageName: node
linkType: hard

"@types/node@npm:>=20":
version: 22.10.2
resolution: "@types/node@npm:22.10.2"
dependencies:
undici-types: "npm:~6.20.0"
checksum: 10c0/2c7b71a040f1ef5320938eca8ebc946e6905caa9bbf3d5665d9b3774a8d15ea9fab1582b849a6d28c7fc80756a62c5666bc66b69f42f4d5dafd1ccb193cdb4ac
languageName: node
linkType: hard

"@types/node@npm:^17.0.21":
version: 17.0.45
resolution: "@types/node@npm:17.0.45"
Expand Down Expand Up @@ -4118,6 +4146,7 @@ __metadata:
prettier: "npm:^3.4.2"
starknet: "npm:6.11.0"
typescript: "npm:^5.7.2"
zx: "npm:^8.2.4"
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -10679,3 +10708,20 @@ __metadata:
checksum: 10c0/71cc2f2bbb537300c3f569e25693d37b3bc91f225cefce251a71c30bc6bb3e7f8e9420ca0eb57f2ac9e492b085b8dfa075fd1e8195c40b83c951dd59c6e4fbf8
languageName: node
linkType: hard

"zx@npm:^8.2.4":
version: 8.2.4
resolution: "zx@npm:8.2.4"
dependencies:
"@types/fs-extra": "npm:>=11"
"@types/node": "npm:>=20"
dependenciesMeta:
"@types/fs-extra":
optional: true
"@types/node":
optional: true
bin:
zx: build/cli.js
checksum: 10c0/ae60ceef4eaf62695de0a24edab302efc770da10f2f4e79b7b8d50c2e7bee8c4b100e8722c6963a6f4badafe3f00d8d0fd50080c90745bf7bca90203c4aee59b
languageName: node
linkType: hard

0 comments on commit 870a7dc

Please sign in to comment.