From 8ba0cdaa575abea0251ed5b6d1e5c4e405c2ace6 Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Wed, 18 Dec 2024 12:24:44 +0500 Subject: [PATCH] change atom price --- .github/actions/changePrice/action.yml | 17 ++++ .github/actions/createVault/createVault.mjs | 104 +++++++------------- .github/scripts/changePrice.js | 50 ++++++++++ .github/workflows/liquidation.yml | 25 +++-- 4 files changed, 117 insertions(+), 79 deletions(-) create mode 100644 .github/actions/changePrice/action.yml create mode 100644 .github/scripts/changePrice.js diff --git a/.github/actions/changePrice/action.yml b/.github/actions/changePrice/action.yml new file mode 100644 index 000000000..1654ebc67 --- /dev/null +++ b/.github/actions/changePrice/action.yml @@ -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' diff --git a/.github/actions/createVault/createVault.mjs b/.github/actions/createVault/createVault.mjs index 4168da00d..1eb65ce28 100644 --- a/.github/actions/createVault/createVault.mjs +++ b/.github/actions/createVault/createVault.mjs @@ -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); diff --git a/.github/scripts/changePrice.js b/.github/scripts/changePrice.js new file mode 100644 index 000000000..981fb8c4a --- /dev/null +++ b/.github/scripts/changePrice.js @@ -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); diff --git a/.github/workflows/liquidation.yml b/.github/workflows/liquidation.yml index 1b297d7a2..421cba606 100644 --- a/.github/workflows/liquidation.yml +++ b/.github/workflows/liquidation.yml @@ -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