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 058085e
Show file tree
Hide file tree
Showing 5 changed files with 349 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'
77 changes: 77 additions & 0 deletions .github/actions/createVault/createVault.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { $ } from 'execa';


const execa = require('execa');

async function setAtomPrice() {
try {
const { stdout } = await execa('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'
]);
console.log('Output:', stdout);
} catch (error) {
console.error('Error:', error);
}
}

setAtomPrice();



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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
"@subql/cli": "^5.4.0",
"@subql/node-cosmos": "4.2.1",
"@subql/testing": "latest",
"execa": "^9.5.2",
"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
Loading

0 comments on commit 058085e

Please sign in to comment.