Skip to content

Commit

Permalink
change atom price
Browse files Browse the repository at this point in the history
  • Loading branch information
rabi-siddique committed Dec 18, 2024
1 parent fc8aeba commit 8ba0cda
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 79 deletions.
17 changes: 17 additions & 0 deletions .github/actions/changePrice/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: 'Change ATOM Price'
description: 'This action updates the ATOM price on the specified Agoric network.'

inputs:
amount:
description: 'The new price to set for ATOM.'
required: true
agoricNet:
description: 'The Agoric network configuration where the price change will apply.'
required: true
containerName:
description: 'The name of the Docker container in which the commands are executed.'
required: true

runs:
using: 'node20'
main: 'changePrice.mjs'
104 changes: 34 additions & 70 deletions .github/actions/createVault/createVault.mjs
Original file line number Diff line number Diff line change
@@ -1,77 +1,41 @@
import { execa, $ } from 'execa';
import { execa } from 'execa';

async function setAtomPrice() {
const agops = '/usr/src/agoric-sdk/packages/agoric-cli/bin/agops';
const setAtomPrice = async (amount, containerName, agoricNet) => {
try {
console.log('Changing Price...');
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);
console.log(`Initiating price change to ${amount} for ATOM...`);

const env = {
AGORIC_NET: agoricNet,
};

const { stdout } = await execa(
'docker',
[
'exec',
containerName,
agops,
'oracle',
'setPrice',
'--keys',
'gov1,gov2',
'--pair',
'ATOM.USD',
'--price',
amount,
'--keyring-backend',
'test',
],
{ env },
);
console.log('Standard output:', stdout);
} catch (error) {
console.error('Error:', error);
}
}
};

setAtomPrice();
const amount = process.env.PRICE;
const containerName = process.env.INPUT_CONTAINERNAME;
const agoricNet = process.env.INPUT_AGORICNET;

// 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);
setAtomPrice(amount, containerName, agoricNet);
50 changes: 50 additions & 0 deletions .github/scripts/changePrice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { execa } from 'execa';

const agops = '/usr/src/agoric-sdk/packages/agoric-cli/bin/agops';

const amount = process.env.AMOUNT;
const containerName = process.env.CONTAINER_NAME;
const agoricNet = process.env.AGORIC_NET;

if (!amount || !containerName || !agoricNet) {
console.error('Error: Missing one or more required parameters:');
if (!amount) console.error('Missing amount');
if (!containerName) console.error('Missing containerName');
if (!agoricNet) console.error('Missing agoricNet');
process.exit(1);
}

const setAtomPrice = async (amount, containerName, agoricNet) => {
try {
console.log(`Initiating price change to ${amount} for ATOM...`);

const env = {
AGORIC_NET: agoricNet,
};

const { stdout } = await execa(
'docker',
[
'exec',
containerName,
agops,
'oracle',
'setPrice',
'--keys',
'gov1,gov2',
'--pair',
'ATOM.USD',
'--price',
amount,
'--keyring-backend',
'test',
],
{ env },
);
console.log('Standard output:', stdout);
} catch (error) {
console.error('Error:', error);
}
};

setAtomPrice(amount, containerName, agoricNet);
25 changes: 16 additions & 9 deletions .github/workflows/liquidation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,22 @@ jobs:
# apiUrl: 'http://localhost:3000/'
# expectedVaults: 7

- name: Create Vault with 100 Minted and 15 Collateral
uses: ./.github/actions/createVault
with:
wantMinted: '100'
giveCollateral: '15'
userKey: 'gov3'
agoricNet: 'local'
commandTimeout: '120'
containerName: 'agd'
- name: Set ATOM Price to 12.34
run: node .github/scripts/changePrice.js
env:
AMOUNT: 12.34
CONTAINER_NAME: a3p
AGORIC_NET: local

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

# - name: Create Vault with 103 Minted and 15 Collateral
# uses: ./.github/actions/createVault
Expand Down

0 comments on commit 8ba0cda

Please sign in to comment.