From a82759180be86de0690ef4f017a3fa95e06a1b71 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 10 Dec 2024 11:31:28 -0800 Subject: [PATCH 01/25] chore: gitignore for aider --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index cac0e181..d03387a7 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,5 @@ Thumbs.db !.yarn/releases !.yarn/sdks !.yarn/versions +.aider* +.env From b3bd7cd0bd4d6d26461917f315323a3a5adf881a Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 11 Dec 2024 14:13:59 -0800 Subject: [PATCH 02/25] chore(deps): bump subql deps to get https://github.com/subquery/subql/pull/2624/ --- package.json | 4 ++-- yarn.lock | 59 ++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 490362a6..75a20438 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "license": "Apache-2.0", "devDependencies": { "@cosmjs/stargate": "^0.28.9", - "@subql/cli": "^5.3.3", + "@subql/cli": "^5.4.0", "@subql/node-cosmos": "^4.2.1", "@subql/testing": "latest", "prettier": "^3.4.2", @@ -33,7 +33,7 @@ }, "dependencies": { "@subql/types-cosmos": "^4.0.0", - "@subql/utils": "^2.16.0", + "@subql/utils": "^2.17.0", "@types/node": "^17.0.21", "bech32": "^2.0.0", "js-sha256": "^0.11.0", diff --git a/yarn.lock b/yarn.lock index a723e7eb..8a9231c6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3177,15 +3177,16 @@ __metadata: languageName: node linkType: hard -"@subql/cli@npm:^5.3.3": - version: 5.3.3 - resolution: "@subql/cli@npm:5.3.3" +"@subql/cli@npm:^5.4.0": + version: 5.4.0 + resolution: "@subql/cli@npm:5.4.0" dependencies: "@inquirer/prompts": "npm:^5.3.6" "@oclif/core": "npm:^2.16.0" - "@subql/common": "npm:5.2.1" - "@subql/utils": "npm:2.16.0" + "@subql/common": "npm:5.2.2" + "@subql/utils": "npm:2.17.0" boxen: "npm:5.1.2" + chalk: "npm:^4" ejs: "npm:^3.1.10" fs-extra: "npm:^11.2.0" fuzzy: "npm:^0.1.3" @@ -3209,7 +3210,7 @@ __metadata: yaml-loader: "npm:^0.8.1" bin: subql: ./bin/run - checksum: 10c0/5d2f0764b6105fb9af9511f7acf63004c3e7b2b6a85178fb4dd75aee1c020d5d4afb5b693baa190b63a8b50d9e38a9ddd928df517707c30128e6fa895764bd31 + checksum: 10c0/4f85a748a7f79873b6f7c10974f7a5367a04782595da90ec204a7790b48dd1ff6c81025c67f67f4779586dcbdba8e579c7ed286e5a00d9c241aa2914bb85ac23 languageName: node linkType: hard @@ -3255,6 +3256,23 @@ __metadata: languageName: node linkType: hard +"@subql/common@npm:5.2.2": + version: 5.2.2 + resolution: "@subql/common@npm:5.2.2" + dependencies: + "@subql/types-core": "npm:2.0.0" + axios: "npm:^0.28.0" + class-transformer: "npm:^0.5.1" + class-validator: "npm:^0.14.1" + form-data: "npm:^4.0.1" + js-yaml: "npm:^4.1.0" + reflect-metadata: "npm:^0.1.14" + semver: "npm:^7.6.3" + update-notifier: "npm:^5.1.0" + checksum: 10c0/3f32110e5e16674f40e87553edeeef46bfc4553e14c21e40de9e25b1ad5df5417294606c1e64a114f3d0c0e50ec4368bfb94e9b6c7ed607018910dd15902cb99 + languageName: node + linkType: hard + "@subql/node-core@npm:^15.0.2": version: 15.0.3 resolution: "@subql/node-core@npm:15.0.3" @@ -3357,7 +3375,7 @@ __metadata: languageName: node linkType: hard -"@subql/utils@npm:2.16.0, @subql/utils@npm:^2.16.0": +"@subql/utils@npm:2.16.0": version: 2.16.0 resolution: "@subql/utils@npm:2.16.0" dependencies: @@ -3376,6 +3394,25 @@ __metadata: languageName: node linkType: hard +"@subql/utils@npm:2.17.0, @subql/utils@npm:^2.17.0": + version: 2.17.0 + resolution: "@subql/utils@npm:2.17.0" + dependencies: + "@polkadot/util": "npm:^13.2.3" + "@polkadot/util-crypto": "npm:^13.2.3" + "@subql/x-sequelize": "npm:6.32.0-0.0.4" + chalk: "npm:^4.1.2" + detect-port: "npm:^1.6.1" + flatted: "npm:^3.3.1" + graphql: "npm:^15.8.0" + graphql-tag: "npm:^2.12.6" + lodash: "npm:^4.17.21" + pino: "npm:^6.13.3" + rotating-file-stream: "npm:^3.2.3" + checksum: 10c0/18f67336235f4068d96c9aa0b906a95564311834a91f9af28e0442867db3e31ec099dd469dacf4c1c791824d07f62c6fe7c92b83d5b6ac0f231ceff26c164f6e + languageName: node + linkType: hard + "@subql/x-cosmology-ast@npm:^1.4.10": version: 1.4.10 resolution: "@subql/x-cosmology-ast@npm:1.4.10" @@ -4088,11 +4125,11 @@ __metadata: resolution: "agoric-indexer@workspace:." dependencies: "@cosmjs/stargate": "npm:^0.28.9" - "@subql/cli": "npm:^5.3.3" + "@subql/cli": "npm:^5.4.0" "@subql/node-cosmos": "npm:^4.2.1" "@subql/testing": "npm:latest" "@subql/types-cosmos": "npm:^4.0.0" - "@subql/utils": "npm:^2.16.0" + "@subql/utils": "npm:^2.17.0" "@types/node": "npm:^17.0.21" bech32: "npm:^2.0.0" js-sha256: "npm:^0.11.0" @@ -4874,7 +4911,7 @@ __metadata: languageName: node linkType: hard -"chalk@npm:^4.0.0, chalk@npm:^4.0.2, chalk@npm:^4.1.0, chalk@npm:^4.1.2": +"chalk@npm:^4, chalk@npm:^4.0.0, chalk@npm:^4.0.2, chalk@npm:^4.1.0, chalk@npm:^4.1.2": version: 4.1.2 resolution: "chalk@npm:4.1.2" dependencies: @@ -6149,7 +6186,7 @@ __metadata: languageName: node linkType: hard -"form-data@npm:^4.0.0": +"form-data@npm:^4.0.0, form-data@npm:^4.0.1": version: 4.0.1 resolution: "form-data@npm:4.0.1" dependencies: From ef0fc4a0f43a06c28b33ef399d83a06247606b1c Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 11 Dec 2024 14:16:35 -0800 Subject: [PATCH 03/25] chore(deps): rm unused --- package.json | 4 +-- yarn.lock | 84 ++-------------------------------------------------- 2 files changed, 3 insertions(+), 85 deletions(-) diff --git a/package.json b/package.json index 75a20438..12d6cf59 100644 --- a/package.json +++ b/package.json @@ -37,9 +37,7 @@ "@types/node": "^17.0.21", "bech32": "^2.0.0", "js-sha256": "^0.11.0", - "pino": "^7.8.0", - "ts-proto": "^1.112.1", - "tslib": "^2.3.1" + "pino": "^7.8.0" }, "packageManager": "yarn@4.5.3" } diff --git a/yarn.lock b/yarn.lock index 8a9231c6..ab8eb7d7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4136,8 +4136,6 @@ __metadata: pino: "npm:^7.8.0" prettier: "npm:^3.4.2" starknet: "npm:6.11.0" - ts-proto: "npm:^1.112.1" - tslib: "npm:^2.3.1" typescript: "npm:^5.7.2" languageName: unknown linkType: soft @@ -4873,13 +4871,6 @@ __metadata: languageName: node linkType: hard -"case-anything@npm:^2.1.13": - version: 2.1.13 - resolution: "case-anything@npm:2.1.13" - checksum: 10c0/b02ffa51d7d58b9a32df7b40973836e16afad131eae7d343e64cb3ca7be57a936bf3d6c9d57a7aa242cf2f545d9a33990b755e93bcac2517761d77773a4a6a30 - languageName: node - linkType: hard - "case@npm:1.6.3": version: 1.6.3 resolution: "case@npm:1.6.3" @@ -5527,15 +5518,6 @@ __metadata: languageName: node linkType: hard -"detect-libc@npm:^1.0.3": - version: 1.0.3 - resolution: "detect-libc@npm:1.0.3" - bin: - detect-libc: ./bin/detect-libc.js - checksum: 10c0/4da0deae9f69e13bc37a0902d78bf7169480004b1fed3c19722d56cff578d16f0e11633b7fbf5fb6249181236c72e90024cbd68f0b9558ae06e281f47326d50d - languageName: node - linkType: hard - "detect-port@npm:^1.6.1": version: 1.6.1 resolution: "detect-port@npm:1.6.1" @@ -5588,15 +5570,6 @@ __metadata: languageName: node linkType: hard -"dprint-node@npm:^1.0.8": - version: 1.0.8 - resolution: "dprint-node@npm:1.0.8" - dependencies: - detect-libc: "npm:^1.0.3" - checksum: 10c0/39c1f8511833226cde773129afc5862dfd05babe062375e6b1f5824e221a5743a4d9c48626f32f7c2080113566270fe80521a50acb9029a20a2e80a3cd5e4106 - languageName: node - linkType: hard - "dunder-proto@npm:^1.0.0": version: 1.0.0 resolution: "dunder-proto@npm:1.0.0" @@ -7413,7 +7386,7 @@ __metadata: languageName: node linkType: hard -"long@npm:^5.0.0, long@npm:^5.2.0, long@npm:^5.2.1, long@npm:^5.2.3": +"long@npm:^5.2.0, long@npm:^5.2.1": version: 5.2.3 resolution: "long@npm:5.2.3" checksum: 10c0/6a0da658f5ef683b90330b1af76f06790c623e148222da9d75b60e266bbf88f803232dd21464575681638894a84091616e7f89557aa087fd14116c0f4e0e43d9 @@ -8603,26 +8576,6 @@ __metadata: languageName: node linkType: hard -"protobufjs@npm:^7.2.4": - version: 7.4.0 - resolution: "protobufjs@npm:7.4.0" - dependencies: - "@protobufjs/aspromise": "npm:^1.1.2" - "@protobufjs/base64": "npm:^1.1.2" - "@protobufjs/codegen": "npm:^2.0.4" - "@protobufjs/eventemitter": "npm:^1.1.0" - "@protobufjs/fetch": "npm:^1.1.0" - "@protobufjs/float": "npm:^1.0.2" - "@protobufjs/inquire": "npm:^1.1.0" - "@protobufjs/path": "npm:^1.1.2" - "@protobufjs/pool": "npm:^1.1.0" - "@protobufjs/utf8": "npm:^1.1.0" - "@types/node": "npm:>=13.7.0" - long: "npm:^5.0.0" - checksum: 10c0/a5460a63fe596523b9a067cbce39a6b310d1a71750fda261f076535662aada97c24450e18c5bc98a27784f70500615904ff1227e1742183509f0db4fdede669b - languageName: node - linkType: hard - "proxy-addr@npm:~2.0.7": version: 2.0.7 resolution: "proxy-addr@npm:2.0.7" @@ -9967,39 +9920,6 @@ __metadata: languageName: node linkType: hard -"ts-poet@npm:^6.7.0": - version: 6.9.0 - resolution: "ts-poet@npm:6.9.0" - dependencies: - dprint-node: "npm:^1.0.8" - checksum: 10c0/c1e3ee6048f075407c2076c8b884b405a3402ae6c013c0af9d0f6b8a6d939c71751a954882d2bd33a606c013d4a57519f5305e0bb1fd6aa0d23edda93e6007bf - languageName: node - linkType: hard - -"ts-proto-descriptors@npm:1.16.0": - version: 1.16.0 - resolution: "ts-proto-descriptors@npm:1.16.0" - dependencies: - long: "npm:^5.2.3" - protobufjs: "npm:^7.2.4" - checksum: 10c0/6e943b05ecd1f240ff443719479fe112e198d5bbf2d9ec7c3412511d555f85da485021286b424cedba52392dc23de49d3ea773f865f556c9c173446a948d5484 - languageName: node - linkType: hard - -"ts-proto@npm:^1.112.1": - version: 1.181.2 - resolution: "ts-proto@npm:1.181.2" - dependencies: - case-anything: "npm:^2.1.13" - protobufjs: "npm:^7.2.4" - ts-poet: "npm:^6.7.0" - ts-proto-descriptors: "npm:1.16.0" - bin: - protoc-gen-ts_proto: protoc-gen-ts_proto - checksum: 10c0/1c72e9d4b350379f2ee0717f20d2fafc4164a51763fbc6bb58421b79ee7b252fa4098566e2a0804c30ff399fef93c4620d237ed51bac9d79b1caa9f4edf1bbfb - languageName: node - linkType: hard - "tslib@npm:2.5.3": version: 2.5.3 resolution: "tslib@npm:2.5.3" @@ -10014,7 +9934,7 @@ __metadata: languageName: node linkType: hard -"tslib@npm:^2.1.0, tslib@npm:^2.3.0, tslib@npm:^2.3.1, tslib@npm:^2.4.0, tslib@npm:^2.5.0, tslib@npm:^2.6.3, tslib@npm:^2.7.0, tslib@npm:^2.8.0": +"tslib@npm:^2.1.0, tslib@npm:^2.3.0, tslib@npm:^2.4.0, tslib@npm:^2.5.0, tslib@npm:^2.6.3, tslib@npm:^2.7.0, tslib@npm:^2.8.0": version: 2.8.1 resolution: "tslib@npm:2.8.1" checksum: 10c0/9c4759110a19c53f992d9aae23aac5ced636e99887b51b9e61def52611732872ff7668757d4e4c61f19691e36f4da981cd9485e869b4a7408d689f6bf1f14e62 From 704a737da62575261e02accc54892d9f70eef430 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 10 Dec 2024 11:42:32 -0800 Subject: [PATCH 04/25] feat: AGORIC_NET env option --- project.ts | 89 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 37 deletions(-) diff --git a/project.ts b/project.ts index 25d1c2d9..7df273c0 100644 --- a/project.ts +++ b/project.ts @@ -1,5 +1,56 @@ import { CosmosDatasourceKind, CosmosHandlerKind, CosmosProject } from '@subql/types-cosmos'; +const chainTypesU18 = new Map([ + [ + 'cosmos.slashing.v1beta1', + { + file: './proto/cosmos/slashing/v1beta1/tx.proto', + messages: ['MsgUnjail'], + }, + ], + [ + 'cosmos.gov.v1beta1', + { + file: './proto/cosmos/gov/v1beta1/tx.proto', + messages: ['MsgVoteWeighted'], + }, + ], + [ + 'cosmos.gov.v1beta1.gov', + { + file: './proto/cosmos/gov/v1beta1/gov.proto', + messages: ['WeightedVoteOption'], + }, + ], + [ + '/agoric.swingset.MsgInstallBundle', + { + file: './proto/agoric/swingset/msgs.proto', + messages: ['MsgInstallBundle'], + }, + ], +]); + +const networkConfig = { + local: { + chainId: 'agoriclocal', + endpoint: ['http://localhost:26657'], + chaintypes: chainTypesU18, + }, + docker: { + chainId: 'agoriclocal', + endpoint: ['http://host.docker.internal:26657'], + chaintypes: chainTypesU18, + }, + main: { + chainId: 'agoric-3', + endpoint: ['https://main-a.rpc.agoric.net:443'], + chaintypes: chainTypesU18, + }, +}; + +const networkKey = process.env.AGORIC_NET || 'main'; + // Can expand the Datasource processor types via the genreic param const project: CosmosProject = { specVersion: '1.0.0', @@ -19,43 +70,7 @@ const project: CosmosProject = { schema: { file: './schema.graphql', }, - network: { - // chainId: "agoriclocal", - // endpoint: ["http://host.docker.internal:26657/"], - chainId: 'agoric-3', - endpoint: ['https://main-a.rpc.agoric.net:443'], - - chaintypes: new Map([ - [ - 'cosmos.slashing.v1beta1', - { - file: './proto/cosmos/slashing/v1beta1/tx.proto', - messages: ['MsgUnjail'], - }, - ], - [ - 'cosmos.gov.v1beta1', - { - file: './proto/cosmos/gov/v1beta1/tx.proto', - messages: ['MsgVoteWeighted'], - }, - ], - [ - 'cosmos.gov.v1beta1.gov', - { - file: './proto/cosmos/gov/v1beta1/gov.proto', - messages: ['WeightedVoteOption'], - }, - ], - [ - '/agoric.swingset.MsgInstallBundle', - { - file: './proto/agoric/swingset/msgs.proto', - messages: ['MsgInstallBundle'], - }, - ], - ]), - }, + network: networkConfig[networkKey], dataSources: [ { kind: CosmosDatasourceKind.Runtime, From 6599ee69ca030eb54d5db0ef447de2ac5a063781 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 10 Dec 2024 11:32:22 -0800 Subject: [PATCH 05/25] ci: Rename PR workflow job from 'pr' to 'test' --- .github/workflows/pr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 5f31979e..1b8e7c05 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -3,7 +3,7 @@ on: pull_request: jobs: - pr: + test: runs-on: ubuntu-latest services: postgres: From 2a3a53959ae8e7da0b0d56f7f081f6e93e468ff7 Mon Sep 17 00:00:00 2001 From: "Turadg Aleahmad (aider)" Date: Tue, 10 Dec 2024 11:32:24 -0800 Subject: [PATCH 06/25] ci: Add a3p container service to GitHub Actions workflow --- .github/workflows/pr.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 1b8e7c05..b7a3577c 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -6,6 +6,10 @@ jobs: test: runs-on: ubuntu-latest services: + a3p: + image: ghcr.io/agoric/agoric-3-proposals:latest + ports: + - 26657:26657 postgres: image: postgres:16-alpine ports: From 658514cadabefe7b247d3719936550f0fe8b2746 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Mon, 9 Dec 2024 18:26:06 -0800 Subject: [PATCH 07/25] ci: subql-node-cosmos test --- .github/workflows/pr.yaml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index b7a3577c..b3cb790e 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -45,10 +45,13 @@ jobs: - run: yarn tsc - name: Build run: yarn build - # TODO: https://github.com/Agoric/agoric-subql/issues/8 + env: + AGORIC_NET: local + + # Runtime tests using the db - name: Enable btree btree_gist run: psql "postgresql://$DB_USER:$DB_PASS@$DB_HOST:$DB_PORT/$DB_DATABASE" -c "CREATE EXTENSION IF NOT EXISTS btree_gist;" - # - name: Install subql-node-cosmos - # run: yarn global add @subql/node-cosmos - # - name: Run tests with Subquery Node - # run: subql-node-cosmos test -f ${{ github.workspace }} + - name: Run tests with Subquery Node + env: + TZ: UTC # prevents: Environment Timezone is not set to UTC. This may cause issues with indexing or proof of index + run: yarn subql-node-cosmos test -f ${{ github.workspace }} From ebe26e63cd43236894b017d0ede7f2fdc9cead5f Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 10 Dec 2024 12:28:09 -0800 Subject: [PATCH 08/25] feat: parameterize startBlock --- project.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/project.ts b/project.ts index 7df273c0..e6b1fc86 100644 --- a/project.ts +++ b/project.ts @@ -36,21 +36,33 @@ const networkConfig = { chainId: 'agoriclocal', endpoint: ['http://localhost:26657'], chaintypes: chainTypesU18, + startBlock: 0, }, docker: { chainId: 'agoriclocal', endpoint: ['http://host.docker.internal:26657'], chaintypes: chainTypesU18, + startBlock: 0, }, main: { chainId: 'agoric-3', endpoint: ['https://main-a.rpc.agoric.net:443'], chaintypes: chainTypesU18, + startBlock: 2115669, }, }; const networkKey = process.env.AGORIC_NET || 'main'; +const startBlock = { + local: 0, + docker: 0, + main: 2115669, + /** Launch of Inter Protocol */ + upgrade8: 7179262, +}; +const startBlockKey = process.env.SUBQL_START_BLOCK || networkKey; + // Can expand the Datasource processor types via the genreic param const project: CosmosProject = { specVersion: '1.0.0', @@ -74,14 +86,13 @@ const project: CosmosProject = { dataSources: [ { kind: CosmosDatasourceKind.Runtime, - // First block of mainnet is 2115669 + // TODO document these // startBlock: 2115669, // startBlock: 14347000, // startBlock: 12306806, // startBlock: 13017175, // startBlock: 2115669, - // Upgrade 8 (launch of Inter Protocol) - startBlock: 7179262, + startBlock: startBlock[startBlockKey], mapping: { file: './dist/index.js', From 5c1033d994e030867168ec96847cb75f67a46de6 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 10 Dec 2024 12:57:44 -0800 Subject: [PATCH 09/25] test: a3p --- README.md | 16 ++++++++++++++++ src/test/mappingHandlers.test.ts | 8 +++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2ba23f0d..74337600 100644 --- a/README.md +++ b/README.md @@ -106,3 +106,19 @@ The fastest way to get support is by [searching our documentation](https://acade - storage - submit_proposal - transfer + +## Developing + +### Locally + +1. Start up an A3P instance: + +```sh +docker run -p 26657:26657 -p 1317:1317 -p 9090:9090 ghcr.io/agoric/agoric-3-proposals:latest +``` + +2. Browse it with [vstorage viewer](https://vstorage.agoric.net/?endpoint=http%3A%2F%2Flocalhost%3A26657) + +3. Update tests to verify some observations you've made in the vstorage viewer + +4. Run `yarn test` diff --git a/src/test/mappingHandlers.test.ts b/src/test/mappingHandlers.test.ts index aa641104..e27c7394 100644 --- a/src/test/mappingHandlers.test.ts +++ b/src/test/mappingHandlers.test.ts @@ -1,3 +1,4 @@ +/** @file test against agoric-3-proposals:latest */ import { subqlTest } from '@subql/testing'; import { StateChangeEvent, @@ -99,14 +100,15 @@ subqlTest( 'handleStateChangeEvent', ); +const VaultManagerGovernance_Height = 1153; subqlTest( - 'VaultManagerGovernance in state_change at block 982', - 982, // block height to process + 'VaultManagerGovernance in state_change', + VaultManagerGovernance_Height, // block height to process [], [ new VaultManagerGovernance( 'published.vaultFactory.managers.manager1.governance', - BigInt(982), + BigInt(VaultManagerGovernance_Height), new Date('2024-01-17T20:29:32.963Z'), BigInt(1000000000), BigInt(100), From 93e39b99b5c20b3fd86570d1b4d7bcbeca0771c3 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 11 Dec 2024 14:47:05 -0800 Subject: [PATCH 10/25] fixup! chore(deps): bump subql deps --- package.json | 3 +++ yarn.lock | 49 +++++++++++++++---------------------------------- 2 files changed, 18 insertions(+), 34 deletions(-) diff --git a/package.json b/package.json index 12d6cf59..fb463d05 100644 --- a/package.json +++ b/package.json @@ -39,5 +39,8 @@ "js-sha256": "^0.11.0", "pino": "^7.8.0" }, + "resolutions": { + "@subql/node-core": "^16.1.0" + }, "packageManager": "yarn@4.5.3" } diff --git a/yarn.lock b/yarn.lock index ab8eb7d7..af4f2afb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3240,51 +3240,51 @@ __metadata: languageName: node linkType: hard -"@subql/common@npm:5.2.1, @subql/common@npm:^5.2.1": - version: 5.2.1 - resolution: "@subql/common@npm:5.2.1" +"@subql/common@npm:5.2.2": + version: 5.2.2 + resolution: "@subql/common@npm:5.2.2" dependencies: "@subql/types-core": "npm:2.0.0" axios: "npm:^0.28.0" class-transformer: "npm:^0.5.1" class-validator: "npm:^0.14.1" + form-data: "npm:^4.0.1" js-yaml: "npm:^4.1.0" reflect-metadata: "npm:^0.1.14" semver: "npm:^7.6.3" update-notifier: "npm:^5.1.0" - checksum: 10c0/02ac5e46489e9eeb73f01c007e868d491f415462d654149bb296f1c4f0d74ff67b4881458a154f237a1e88df7f4a99fdf0ff44739b85ae44b871234642753fc6 + checksum: 10c0/3f32110e5e16674f40e87553edeeef46bfc4553e14c21e40de9e25b1ad5df5417294606c1e64a114f3d0c0e50ec4368bfb94e9b6c7ed607018910dd15902cb99 languageName: node linkType: hard -"@subql/common@npm:5.2.2": - version: 5.2.2 - resolution: "@subql/common@npm:5.2.2" +"@subql/common@npm:^5.2.1": + version: 5.2.1 + resolution: "@subql/common@npm:5.2.1" dependencies: "@subql/types-core": "npm:2.0.0" axios: "npm:^0.28.0" class-transformer: "npm:^0.5.1" class-validator: "npm:^0.14.1" - form-data: "npm:^4.0.1" js-yaml: "npm:^4.1.0" reflect-metadata: "npm:^0.1.14" semver: "npm:^7.6.3" update-notifier: "npm:^5.1.0" - checksum: 10c0/3f32110e5e16674f40e87553edeeef46bfc4553e14c21e40de9e25b1ad5df5417294606c1e64a114f3d0c0e50ec4368bfb94e9b6c7ed607018910dd15902cb99 + checksum: 10c0/02ac5e46489e9eeb73f01c007e868d491f415462d654149bb296f1c4f0d74ff67b4881458a154f237a1e88df7f4a99fdf0ff44739b85ae44b871234642753fc6 languageName: node linkType: hard -"@subql/node-core@npm:^15.0.2": - version: 15.0.3 - resolution: "@subql/node-core@npm:15.0.3" +"@subql/node-core@npm:^16.1.0": + version: 16.1.0 + resolution: "@subql/node-core@npm:16.1.0" dependencies: "@apollo/client": "npm:^3.11.2" "@nestjs/common": "npm:^9.4.0" "@nestjs/event-emitter": "npm:^2.0.0" "@nestjs/schedule": "npm:^3.0.1" - "@subql/common": "npm:5.2.1" + "@subql/common": "npm:5.2.2" "@subql/testing": "npm:2.2.2" "@subql/types": "npm:3.11.4" - "@subql/utils": "npm:2.16.0" + "@subql/utils": "npm:2.17.0" "@willsoto/nestjs-prometheus": "npm:^5.4.0" async-mutex: "npm:^0.5.0" cron-converter: "npm:^2.0.1" @@ -3301,7 +3301,7 @@ __metadata: toposort-class: "npm:^1.0.1" vm2: "npm:^3.9.19" yargs: "npm:^16.2.0" - checksum: 10c0/fe5f8f5ca4f8f6dc90d9cb9b450345952eacb9106c610fb9812f6ae9138714820347e1e4667d3b9bc73b19ec6652f045a7c6fca46b1911fee226a16700460f04 + checksum: 10c0/0760a511d78e00dd6961daece046affc287329bc5693a49e65262d910aaacf670f71d089a461b1931297e88241c5718091618880a942df2b142a5a6e59ea573f languageName: node linkType: hard @@ -3375,25 +3375,6 @@ __metadata: languageName: node linkType: hard -"@subql/utils@npm:2.16.0": - version: 2.16.0 - resolution: "@subql/utils@npm:2.16.0" - dependencies: - "@polkadot/util": "npm:^13.2.3" - "@polkadot/util-crypto": "npm:^13.2.3" - "@subql/x-sequelize": "npm:6.32.0-0.0.4" - chalk: "npm:^4.1.2" - detect-port: "npm:^1.6.1" - flatted: "npm:^3.3.1" - graphql: "npm:^15.8.0" - graphql-tag: "npm:^2.12.6" - lodash: "npm:^4.17.21" - pino: "npm:^6.13.3" - rotating-file-stream: "npm:^3.2.3" - checksum: 10c0/a72f222b2b956c06b636e4a10f2d6f6e5e4e96451660eb80754897f8066fe8364ec55ff41ceb45eb668226ac95c4df7965fcb9e1c25d1f1ceae80598293792b3 - languageName: node - linkType: hard - "@subql/utils@npm:2.17.0, @subql/utils@npm:^2.17.0": version: 2.17.0 resolution: "@subql/utils@npm:2.17.0" From 475cf4cca8fd7ecbc2e1333aaca6a5dab0643fe0 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 11 Dec 2024 17:54:59 -0800 Subject: [PATCH 11/25] WIP --- docker-compose.yml | 2 - project.ts | 8 +- src/test/mappingHandlers.test.ts | 147 +++---------------------------- 3 files changed, 18 insertions(+), 139 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index c8d6cc63..abe34630 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3' - services: postgres: build: diff --git a/project.ts b/project.ts index e6b1fc86..a26e2303 100644 --- a/project.ts +++ b/project.ts @@ -36,13 +36,13 @@ const networkConfig = { chainId: 'agoriclocal', endpoint: ['http://localhost:26657'], chaintypes: chainTypesU18, - startBlock: 0, + startBlock: 1, }, docker: { chainId: 'agoriclocal', endpoint: ['http://host.docker.internal:26657'], chaintypes: chainTypesU18, - startBlock: 0, + startBlock: 1, }, main: { chainId: 'agoric-3', @@ -55,8 +55,8 @@ const networkConfig = { const networkKey = process.env.AGORIC_NET || 'main'; const startBlock = { - local: 0, - docker: 0, + local: 1, + docker: 1, main: 2115669, /** Launch of Inter Protocol */ upgrade8: 7179262, diff --git a/src/test/mappingHandlers.test.ts b/src/test/mappingHandlers.test.ts index e27c7394..ceb45065 100644 --- a/src/test/mappingHandlers.test.ts +++ b/src/test/mappingHandlers.test.ts @@ -1,148 +1,29 @@ /** @file test against agoric-3-proposals:latest */ import { subqlTest } from '@subql/testing'; -import { - StateChangeEvent, - Wallet, - Vault, - VaultManagerMetrics, - ReserveMetrics, - ReserveAllocationMetrics, - VaultManagerGovernance, - OraclePrice, -} from '../types'; +import { StateChangeEvent, Wallet } from '../types'; +// FIXME observed in A3P:latest but not passing tests subqlTest( - 'Wallet and StateChangeEvent in state_change at block 654', - 654, // block height to process + 'Wallet and StateChangeEvent in state_change at block 627', + 627, // block height to process [], // dependent entities [ new Wallet( - 'published.wallet.agoric180apa567ssxdc7a7vjqklnyfaq94uk3qe9g00j.current', - BigInt(654), - new Date('2024-01-17T20:15:30.674Z'), - 'agoric180apa567ssxdc7a7vjqklnyfaq94uk3qe9g00j', + 'published.wallet.agoric1ee9hr0jyrxhy999y755mp862ljgycmwyp4pl7q', + BigInt(627), + new Date('"2024-12-09T23:09:55.9Z"'), + 'agoric1ee9hr0jyrxhy999y755mp862ljgycmwyp4pl7q', ), new StateChangeEvent( - '654:25:0', - BigInt(654), - new Date('2024-01-17T20:15:30.674Z'), + '627:37:1', + BigInt(627), + new Date('2024-12-09T23:09:55.9Z'), 'published.wallet', - 'published.wallet.agoric180apa567ssxdc7a7vjqklnyfaq94uk3qe9g00j.current', + 'published.wallet.agoric1ee9hr0jyrxhy999y755mp862ljgycmwyp4pl7q', 0, - '["board05557","board0257","board0074",null,"board02021","board02963",null,"board01422","board04661",null,"board00613","board04149",null,"board05815","board00360",null]', - '{"liveOffers":[["bid-1705522531200",{"id":"bid-1705522531200","invitationSpec":{"callPipe":[["makeBidInvitation",["$0.Alleged: ATOM brand"]]],"instancePath":["auctioneer"],"source":"agoricContract"},"offerArgs":{"maxBuy":{"brand":"$0","value":"+1000000000000","__brand":"ATOM","__value":"1000000000000"},"offerPrice":{"denominator":{"brand":"$0","value":"+1","__brand":"ATOM","__value":"1"},"numerator":{"brand":"$1.Alleged: IST brand","value":"+1","__brand":"IST","__value":"1"}}},"proposal":{"give":{"Bid":{"brand":"$1","value":"+1000000","__brand":"IST","__value":"1000000"}}}}]],"offerToPublicSubscriberPaths":[["openVault-1705522437474",{"vault":"published.vaultFactory.managers.manager0.vaults.vault0"}],["openVault-1705522440909",{"vault":"published.vaultFactory.managers.manager0.vaults.vault1"}]],"offerToUsedInvitation":[["1705522155009",{"brand":"$2.Alleged: Zoe Invitation brand","value":[{"description":"oracle invitation","handle":"$3.Alleged: InvitationHandle","installation":"$4.Alleged: BundleIDInstallation","instance":"$5.Alleged: InstanceHandle","__handle":"InvitationHandle","__installation":"BundleIDInstallation","__instance":"InstanceHandle"}],"__brand":"Zoe Invitation"}],["ecCharter-1705522175986",{"brand":"$2","value":[{"description":"charter member invitation","handle":"$6.Alleged: InvitationHandle","installation":"$7.Alleged: BundleIDInstallation","instance":"$8.Alleged: InstanceHandle","__handle":"InvitationHandle","__installation":"BundleIDInstallation","__instance":"InstanceHandle"}],"__brand":"Zoe Invitation"}],["ecCommittee-1705522165239",{"brand":"$2","value":[{"description":"Voter0","handle":"$9.Alleged: InvitationHandle","installation":"$10.Alleged: BundleIDInstallation","instance":"$11.Alleged: InstanceHandle","__handle":"InvitationHandle","__installation":"BundleIDInstallation","__instance":"InstanceHandle"}],"__brand":"Zoe Invitation"}],["openVault-1705522437474",{"brand":"$2","value":[{"description":"manager0: MakeVault","handle":"$12.Alleged: InvitationHandle","installation":"$13.Alleged: BundleIDInstallation","instance":"$14.Alleged: InstanceHandle","__handle":"InvitationHandle","__installation":"BundleIDInstallation","__instance":"InstanceHandle"}],"__brand":"Zoe Invitation"}],["openVault-1705522440909",{"brand":"$2","value":[{"description":"manager0: MakeVault","handle":"$15.Alleged: InvitationHandle","installation":"$13","instance":"$14","__handle":"InvitationHandle","__installation":"BundleIDInstallation","__instance":"InstanceHandle"}],"__brand":"Zoe Invitation"}]],"purses":[{"balance":{"brand":"$2","value":[],"__brand":"Zoe Invitation"},"brand":"$2","__brand":"Zoe Invitation"}]}', + '["board0257"]', + '{"status":{"id":"closeVault-1733785795438","invitationSpec":{"invitationMakerName":"CloseVault","previousOffer":"openVault-1733785785382","source":"continuing"},"numWantsSatisfied":1,"proposal":{"give":{"Minted":{"brand":"$0.Alleged: IST brand","value":"+5750000","__brand":"IST","__value":"5750000"}},"want":{}},"result":"your vault is closed, thank you for your business"},"updated":"offerStatus"}', ), ], 'handleStateChangeEvent', ); - -subqlTest( - 'Vault and VaultManagerMetrics in state_change at block 630', - 630, // block height to process - [], - [ - new VaultManagerMetrics( - 'published.vaultFactory.managers.manager0.metrics', - BigInt(630), - new Date('2024-01-17T20:14:14.943Z'), - 'ATOM', - BigInt(0), - 'IST', - BigInt(0), - BigInt(0), - BigInt(0), - BigInt(2), - BigInt(0), - BigInt(0), - BigInt(0), - BigInt(0), - BigInt(19000000), - BigInt(0), - BigInt(13065000), - BigInt(0), - BigInt(0), - BigInt(0), - ), - new Vault( - 'published.vaultFactory.managers.manager0.vaults.vault2', - BigInt(630), - new Date('2024-01-17T20:14:14.943Z'), - '', - ), - ], - 'handleStateChangeEvent', -); - -subqlTest( - 'ReserveMetrics and ReserveAllocationMetrics in state_change at block 1246', - 1246, // block height to process - [], - [ - new ReserveMetrics( - 'published.reserve.metrics', - BigInt(1246), - new Date('2024-03-28T20:33:14.226Z'), - BigInt(0), - BigInt(0), - BigInt(0), - ), - new ReserveAllocationMetrics( - 'published.reserve.metrics:Fee', - BigInt(1246), - new Date('2024-03-28T20:33:14.226Z'), - 'IST', - 'Fee', - BigInt(166443434), - 'published.reserve.metrics', - ), - ], - - 'handleStateChangeEvent', -); - -const VaultManagerGovernance_Height = 1153; -subqlTest( - 'VaultManagerGovernance in state_change', - VaultManagerGovernance_Height, // block height to process - [], - [ - new VaultManagerGovernance( - 'published.vaultFactory.managers.manager1.governance', - BigInt(VaultManagerGovernance_Height), - new Date('2024-01-17T20:29:32.963Z'), - BigInt(1000000000), - BigInt(100), - BigInt(1), - BigInt(100), - BigInt(150), - BigInt(100), - BigInt(25), - BigInt(100), - BigInt(1), - BigInt(10000), - BigInt(50), - ), - ], - - 'handleStateChangeEvent', -); - -subqlTest( - 'OraclePrice in state_change at block 612', - 612, // block height to process - [], - [ - new OraclePrice( - 'published.priceFeed.ATOM-USD_price_feed', - BigInt(612), - new Date('2024-01-17T20:13:51.004Z'), - 'ATOM-USD_price_feed', - BigInt(1000000), - BigInt(12010000), - 'ATOM', - 'USD', - ), - ], - - 'handleStateChangeEvent', -); From b29ea2a15c2006112a4a80a8ea36da562e7a075e Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Fri, 13 Dec 2024 10:20:24 +0500 Subject: [PATCH 12/25] test: update tests --- src/mappings/constants.ts | 14 +++++++------- src/mappings/events/vaults.ts | 1 + src/mappings/mappingHandlers.ts | 3 +++ src/test/mappingHandlers.test.ts | 24 +++++++++++++----------- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/mappings/constants.ts b/src/mappings/constants.ts index fcf843a6..97b9d91b 100644 --- a/src/mappings/constants.ts +++ b/src/mappings/constants.ts @@ -31,13 +31,13 @@ export const VAULT_STATES = { LIQUIDATED_CLOSED: 'liquidatedClosed', }; -export const VALUE_KEY = b64encode('value'); -export const STORE_KEY = b64encode('store'); -export const VSTORAGE_VALUE = b64encode('vstorage'); -export const KEY_KEY = b64encode('key'); -export const STORE_NAME_KEY = b64encode('store_name'); -export const SUBKEY_KEY = b64encode('store_subkey'); -export const UNPROVED_VALUE_KEY = b64encode('unproved_value'); +export const VALUE_KEY = 'value'; +export const STORE_KEY = 'store'; +export const VSTORAGE_VALUE = 'vstorage'; +export const KEY_KEY = 'key'; +export const STORE_NAME_KEY = 'store_name'; +export const SUBKEY_KEY = 'store_subkey'; +export const UNPROVED_VALUE_KEY = 'unproved_value'; export const PACKET_DATA_KEY = 'packet_data'; export const PACKET_SRC_CHANNEL_KEY = 'packet_src_channel'; export const PACKET_DST_CHANNEL_KEY = 'packet_dst_channel'; diff --git a/src/mappings/events/vaults.ts b/src/mappings/events/vaults.ts index 0528aa8d..70c241d8 100644 --- a/src/mappings/events/vaults.ts +++ b/src/mappings/events/vaults.ts @@ -34,6 +34,7 @@ export const vaultsEventKit = (block: any, data: any, module: string, path: stri } async function saveWallets(payload: any): Promise[]> { + logger.info(`PAYLOAD: ${JSON.stringify(payload)}`); const promises: Promise[] = []; const address = path.split('.')[2]; const wallet = new Wallet(path, BigInt(data.blockHeight), block.block.header.time as any, address); diff --git a/src/mappings/mappingHandlers.ts b/src/mappings/mappingHandlers.ts index 34978131..460e5e96 100644 --- a/src/mappings/mappingHandlers.ts +++ b/src/mappings/mappingHandlers.ts @@ -156,6 +156,9 @@ export async function handleBundleInstallMessage(message: CosmosMessage): Promis export async function handleStateChangeEvent(cosmosEvent: CosmosEvent): Promise { const { event, block } = cosmosEvent as CosmosEvent & { event: tendermint37.Event }; + logger.info(`EVENT ${JSON.stringify(event)}`); + logger.info(`EVENT TYPE:${event.type}`); + if (event.type != EVENT_TYPES.STATE_CHANGE) { logger.warn('Not valid state_change event.'); return; diff --git a/src/test/mappingHandlers.test.ts b/src/test/mappingHandlers.test.ts index ceb45065..c0697a51 100644 --- a/src/test/mappingHandlers.test.ts +++ b/src/test/mappingHandlers.test.ts @@ -4,26 +4,28 @@ import { StateChangeEvent, Wallet } from '../types'; // FIXME observed in A3P:latest but not passing tests subqlTest( - 'Wallet and StateChangeEvent in state_change at block 627', + 'StateChangeEvent in state_change at block 627', 627, // block height to process - [], // dependent entities + // dependent entities + [], [ new Wallet( - 'published.wallet.agoric1ee9hr0jyrxhy999y755mp862ljgycmwyp4pl7q', + 'published.wallet.agoric1rwwley550k9mmk6uq6mm6z4udrg8kyuyvfszjk.current', BigInt(627), - new Date('"2024-12-09T23:09:55.9Z"'), - 'agoric1ee9hr0jyrxhy999y755mp862ljgycmwyp4pl7q', + new Date('2024-12-09T23:07:18.273Z'), + 'agoric1rwwley550k9mmk6uq6mm6z4udrg8kyuyvfszjk', ), new StateChangeEvent( - '627:37:1', + '627:39:3', BigInt(627), - new Date('2024-12-09T23:09:55.9Z'), + new Date('2024-12-09T23:07:18.273Z'), 'published.wallet', - 'published.wallet.agoric1ee9hr0jyrxhy999y755mp862ljgycmwyp4pl7q', - 0, - '["board0257"]', - '{"status":{"id":"closeVault-1733785795438","invitationSpec":{"invitationMakerName":"CloseVault","previousOffer":"openVault-1733785785382","source":"continuing"},"numWantsSatisfied":1,"proposal":{"give":{"Minted":{"brand":"$0.Alleged: IST brand","value":"+5750000","__brand":"IST","__value":"5750000"}},"want":{}},"result":"your vault is closed, thank you for your business"},"updated":"offerStatus"}', + 'published.wallet.agoric1rwwley550k9mmk6uq6mm6z4udrg8kyuyvfszjk.current', + 3, + '["board05557","board0257","board0074",null,"board05815","board00360"]', + '{"liveOffers":[["openVault-1733785637736",{"id":"openVault-1733785637736","invitationSpec":{"callPipe":[["getCollateralManager",["$0.Alleged: ATOM brand"]],["makeVaultInvitation"]],"instancePath":["VaultFactory"],"source":"agoricContract"},"proposal":{"give":{"Collateral":{"brand":"$0","value":"+583000000","__brand":"ATOM","__value":"583000000"}},"want":{"Minted":{"brand":"$1.Alleged: IST brand","value":"+3489000000","__brand":"IST","__value":"3489000000"}}}}]],"offerToPublicSubscriberPaths":[["openVault-1733785637736",{"vault":"published.vaultFactory.managers.manager0.vaults.vault4"}]],"offerToUsedInvitation":[["openVault-1733785637736",{"brand":"$2.Alleged: Zoe Invitation brand","value":[{"description":"manager0: MakeVault","handle":"$3.Alleged: InvitationHandle","installation":"$4.Alleged: BundleIDInstallation","instance":"$5.Alleged: InstanceHandle","__handle":"InvitationHandle","__installation":"BundleIDInstallation","__instance":"InstanceHandle"}],"__brand":"Zoe Invitation"}]],"purses":[{"balance":{"brand":"$2","value":[],"__brand":"Zoe Invitation"},"brand":"$2","__brand":"Zoe Invitation"}]}', ), ], + 'handleStateChangeEvent', ); From 0970e1f2beb3e8d698cb2016dc45bd6f8c8398fe Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Fri, 13 Dec 2024 15:54:07 +0500 Subject: [PATCH 13/25] chore: remove encoding/decoding --- .github/workflows/pr.yaml | 2 +- docker-compose.yml | 2 +- package.json | 2 +- src/mappings/constants.ts | 16 +++++++--------- src/mappings/events/vaults.ts | 1 - src/mappings/mappingHandlers.ts | 11 ++--------- yarn.lock | 4 ++-- 7 files changed, 14 insertions(+), 24 deletions(-) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index b3cb790e..7e5e2084 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest services: a3p: - image: ghcr.io/agoric/agoric-3-proposals:latest + image: ghcr.io/agoric/agoric-3-proposals@sha256:644e09bf041e5588570ff9a49e6129cc468e9c8458417541027e8532cb91083b ports: - 26657:26657 postgres: diff --git a/docker-compose.yml b/docker-compose.yml index abe34630..ddd67f4f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,7 +16,7 @@ services: retries: 5 subquery-node: - image: subquerynetwork/subql-node-cosmos:v3.12.0 + image: subquerynetwork/subql-node-cosmos:v4.2.1 depends_on: 'postgres': condition: service_healthy diff --git a/package.json b/package.json index fb463d05..2811b755 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "devDependencies": { "@cosmjs/stargate": "^0.28.9", "@subql/cli": "^5.4.0", - "@subql/node-cosmos": "^4.2.1", + "@subql/node-cosmos": "4.2.1", "@subql/testing": "latest", "prettier": "^3.4.2", "starknet": "6.11.0", diff --git a/src/mappings/constants.ts b/src/mappings/constants.ts index 97b9d91b..61e630d7 100644 --- a/src/mappings/constants.ts +++ b/src/mappings/constants.ts @@ -1,5 +1,3 @@ -import { b64encode } from './utils'; - export const EVENT_TYPES = { ACTIVE_PROPOSAL: 'active_proposal', BURN: 'burn', @@ -43,11 +41,11 @@ export const PACKET_SRC_CHANNEL_KEY = 'packet_src_channel'; export const PACKET_DST_CHANNEL_KEY = 'packet_dst_channel'; export const PACKET_SRC_PORT_KEY = 'packet_src_port'; export const PACKET_DST_PORT_KEY = 'packet_dst_port'; -export const ACTION_KEY = b64encode('action'); -export const IBC_MESSAGE_TRANSFER_VALUE = b64encode('/ibc.applications.transfer.v1.MsgTransfer'); -export const IBC_MESSAGE_RECEIVE_PACKET_VALUE = b64encode('/ibc.core.channel.v1.MsgRecvPacket'); -export const RECEPIENT_KEY = b64encode('recipient'); -export const SENDER_KEY = b64encode('sender'); -export const RECEIVER_KEY = b64encode('receiver'); -export const AMOUNT_KEY = b64encode('amount'); +export const ACTION_KEY = 'action'; +export const IBC_MESSAGE_TRANSFER_VALUE = '/ibc.applications.transfer.v1.MsgTransfer'; +export const IBC_MESSAGE_RECEIVE_PACKET_VALUE = '/ibc.core.channel.v1.MsgRecvPacket'; +export const RECEPIENT_KEY = 'recipient'; +export const SENDER_KEY = 'sender'; +export const RECEIVER_KEY = 'receiver'; +export const AMOUNT_KEY = 'amount'; export const TRANSFER_PORT_VALUE = 'transfer'; diff --git a/src/mappings/events/vaults.ts b/src/mappings/events/vaults.ts index 70c241d8..0528aa8d 100644 --- a/src/mappings/events/vaults.ts +++ b/src/mappings/events/vaults.ts @@ -34,7 +34,6 @@ export const vaultsEventKit = (block: any, data: any, module: string, path: stri } async function saveWallets(payload: any): Promise[]> { - logger.info(`PAYLOAD: ${JSON.stringify(payload)}`); const promises: Promise[] = []; const address = path.split('.')[2]; const wallet = new Wallet(path, BigInt(data.blockHeight), block.block.header.time as any, address); diff --git a/src/mappings/mappingHandlers.ts b/src/mappings/mappingHandlers.ts index 460e5e96..17ff2ee7 100644 --- a/src/mappings/mappingHandlers.ts +++ b/src/mappings/mappingHandlers.ts @@ -156,9 +156,6 @@ export async function handleBundleInstallMessage(message: CosmosMessage): Promis export async function handleStateChangeEvent(cosmosEvent: CosmosEvent): Promise { const { event, block } = cosmosEvent as CosmosEvent & { event: tendermint37.Event }; - logger.info(`EVENT ${JSON.stringify(event)}`); - logger.info(`EVENT TYPE:${event.type}`); - if (event.type != EVENT_TYPES.STATE_CHANGE) { logger.warn('Not valid state_change event.'); return; @@ -183,8 +180,7 @@ export async function handleStateChangeEvent(cosmosEvent: CosmosEvent): Promise< let data = Object(); try { - const decodedValue = - valueAttr.key === UNPROVED_VALUE_KEY ? b64decode(b64decode(valueAttr.value)) : b64decode(valueAttr.value); + const decodedValue = valueAttr.key === UNPROVED_VALUE_KEY ? b64decode(valueAttr.value) : valueAttr.value; data = JSON.parse(decodedValue); } catch (e) { return; @@ -195,10 +191,7 @@ export async function handleStateChangeEvent(cosmosEvent: CosmosEvent): Promise< return; } - const decodedKey = - keyAttr.key === SUBKEY_KEY - ? b64decode(b64decode(keyAttr.value)).replaceAll('\u0000', '\x00') - : b64decode(keyAttr.value); + const decodedKey = keyAttr.key === SUBKEY_KEY ? b64decode(keyAttr.value).replaceAll('\u0000', '\x00') : keyAttr.value; const path = extractStoragePath(decodedKey); const module = getStateChangeModule(path); diff --git a/yarn.lock b/yarn.lock index af4f2afb..4c0e2d2d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3305,7 +3305,7 @@ __metadata: languageName: node linkType: hard -"@subql/node-cosmos@npm:^4.2.1": +"@subql/node-cosmos@npm:4.2.1": version: 4.2.1 resolution: "@subql/node-cosmos@npm:4.2.1" dependencies: @@ -4107,7 +4107,7 @@ __metadata: dependencies: "@cosmjs/stargate": "npm:^0.28.9" "@subql/cli": "npm:^5.4.0" - "@subql/node-cosmos": "npm:^4.2.1" + "@subql/node-cosmos": "npm:4.2.1" "@subql/testing": "npm:latest" "@subql/types-cosmos": "npm:^4.0.0" "@subql/utils": "npm:^2.17.0" From f9d7d2d200d39b9fd62a88e9ccb5c66d49d8c861 Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Mon, 16 Dec 2024 17:53:20 +0500 Subject: [PATCH 14/25] test: add tests for vault and reserve entities --- src/test/mappingHandlers.test.ts | 158 ++++++++++++++++++++++++++++++- 1 file changed, 155 insertions(+), 3 deletions(-) diff --git a/src/test/mappingHandlers.test.ts b/src/test/mappingHandlers.test.ts index c0697a51..971be57f 100644 --- a/src/test/mappingHandlers.test.ts +++ b/src/test/mappingHandlers.test.ts @@ -1,12 +1,22 @@ /** @file test against agoric-3-proposals:latest */ import { subqlTest } from '@subql/testing'; -import { StateChangeEvent, Wallet } from '../types'; +import { + ReserveAllocationMetrics, + ReserveAllocationMetricsDaily, + ReserveMetrics, + StateChangeEvent, + Vault, + VaultManagerGovernance, + VaultManagerMetrics, + VaultManagerMetricsDaily, + VaultStatesDaily, + Wallet, +} from '../types'; // FIXME observed in A3P:latest but not passing tests subqlTest( 'StateChangeEvent in state_change at block 627', - 627, // block height to process - // dependent entities + 627, [], [ new Wallet( @@ -29,3 +39,145 @@ subqlTest( 'handleStateChangeEvent', ); + +const vault = new Vault( + 'published.vaultFactory.managers.manager0.vaults.vault6', + BigInt(742), + new Date('2024-12-09 23:13:19.186'), + 'published.wallet.agoric1ee9hr0jyrxhy999y755mp862ljgycmwyp4pl7q.current', +); + +vault.balance = BigInt(788000000); +vault.lockedValue = BigInt(788000000); +vault.coin = 'ATOM'; +vault.denom = 'ATOM'; +vault.debt = BigInt(4745610000); +vault.state = 'active'; + +subqlTest( + 'Vault and VaultStateDailies at height 742', + 742, + [], + [ + vault, + new VaultStatesDaily( + '20241209', + BigInt(742), + new Date('2024-12-09 23:13:19.186'), + BigInt(1), + BigInt(0), + BigInt(0), + BigInt(0), + BigInt(0), + ), + ], + + 'handleStateChangeEvent', +); + +const reserveAllocationMetricsDaily = new ReserveAllocationMetricsDaily( + 'IST:20241216', + 'IST', + 20241216, + BigInt(1212), + new Date('2024-12-16T11:42:27.000Z'), +); + +reserveAllocationMetricsDaily.denom = 'IST'; +reserveAllocationMetricsDaily.key = 'Fee'; +reserveAllocationMetricsDaily.valueLast = BigInt(184980868); +reserveAllocationMetricsDaily.metricsCount = BigInt(1); + +const vaultManagerMetricsDaily = new VaultManagerMetricsDaily( + 'published.vaultFactory.managers.manager1.metrics:20241216', + 'published.vaultFactory.managers.manager1.metrics', + 20241216, + BigInt(1212), + new Date('2024-12-16 11:42:27.202'), +); + +vaultManagerMetricsDaily.liquidatingCollateralBrand = 'stATOM'; +vaultManagerMetricsDaily.liquidatingDebtBrand = 'IST'; +vaultManagerMetricsDaily.liquidatingCollateralValueLast = BigInt(0); +vaultManagerMetricsDaily.liquidatingDebtValueLast = BigInt(0); +vaultManagerMetricsDaily.lockedQuoteDenominatorLast = BigInt(0); +vaultManagerMetricsDaily.lockedQuoteNumeratorLast = BigInt(0); +vaultManagerMetricsDaily.numActiveVaultsLast = BigInt(0); +vaultManagerMetricsDaily.numLiquidatingVaultsLast = BigInt(0); +vaultManagerMetricsDaily.numLiquidationsAbortedLast = BigInt(0); +vaultManagerMetricsDaily.numLiquidationsCompletedLast = BigInt(0); +vaultManagerMetricsDaily.retainedCollateralLast = BigInt(0); +vaultManagerMetricsDaily.totalCollateralLast = BigInt(0); +vaultManagerMetricsDaily.totalCollateralSoldLast = BigInt(0); +vaultManagerMetricsDaily.totalDebtLast = BigInt(0); +vaultManagerMetricsDaily.totalOverageReceivedLast = BigInt(0); +vaultManagerMetricsDaily.totalProceedsReceivedLast = BigInt(0); +vaultManagerMetricsDaily.totalShortfallReceivedLast = BigInt(0); +vaultManagerMetricsDaily.metricsCount = BigInt(1); + +subqlTest( + 'VaultManagerGovernance, VaultManagerMetrics, VaultManagerMetricsDaily, ReserveMetrics, \ + ReserveAllocationMetrics, and ReserveAllocationMetricsDaily at block height 1212', + 1212, + [], + [ + new VaultManagerGovernance( + 'published.vaultFactory.managers.manager1.governance', + BigInt(1212), + new Date('2024-12-16 11:42:27.202'), + BigInt(1000000000), + BigInt(100), + BigInt(1), + BigInt(100), + BigInt(150), + BigInt(100), + BigInt(25), + BigInt(100), + BigInt(1), + BigInt(10000), + BigInt(50), + ), + new VaultManagerMetrics( + 'published.vaultFactory.managers.manager1.metrics', + BigInt(1212), + new Date('2024-12-16 11:42:27.202'), + 'stATOM', + BigInt(0), + 'IST', + BigInt(0), + BigInt(0), + BigInt(0), + BigInt(0), + BigInt(0), + BigInt(0), + BigInt(0), + BigInt(0), + BigInt(0), + BigInt(0), + BigInt(0), + BigInt(0), + BigInt(0), + BigInt(0), + ), + vaultManagerMetricsDaily, + new ReserveMetrics( + 'published.reserve.metrics', + BigInt(1212), + new Date('2024-12-16T11:42:27.202Z'), + BigInt(0), + BigInt(0), + BigInt(0), + ), + new ReserveAllocationMetrics( + 'IST', + BigInt(1212), + new Date('2024-12-16T11:42:27.202Z'), + 'IST', + 'Fee', + BigInt(184980868), + 'published.reserve.metrics', + ), + reserveAllocationMetricsDaily, + ], + 'handleStateChangeEvent', +); From 349741a16c1437ea0138cd076453e479afb1febb Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Mon, 16 Dec 2024 19:06:44 +0500 Subject: [PATCH 15/25] test: add tests for boardaux, oraclePriceDaily and PsmMetricsDaily --- src/test/mappingHandlers.test.ts | 80 ++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/src/test/mappingHandlers.test.ts b/src/test/mappingHandlers.test.ts index 971be57f..990e1f7b 100644 --- a/src/test/mappingHandlers.test.ts +++ b/src/test/mappingHandlers.test.ts @@ -1,6 +1,9 @@ /** @file test against agoric-3-proposals:latest */ import { subqlTest } from '@subql/testing'; import { + BoardAux, + OraclePriceDaily, + PsmMetricsDaily, ReserveAllocationMetrics, ReserveAllocationMetricsDaily, ReserveMetrics, @@ -181,3 +184,80 @@ subqlTest( ], 'handleStateChangeEvent', ); + +subqlTest( + 'BoardAux at block 643', + 643, + [], + [ + new BoardAux( + 'published.boardAux.board0074', + BigInt(643), + new Date('2024-12-09T23:07:37.423Z'), + 'Zoe Invitation', + 'set', + 0, + ), + new BoardAux( + 'published.boardAux.board01744', + BigInt(643), + new Date('2024-12-09T23:07:37.423Z'), + 'USDT_axl', + 'nat', + 6, + ), + new BoardAux('published.boardAux.board0257', BigInt(643), new Date('2024-12-09T23:07:37.423Z'), 'IST', 'nat', 6), + new BoardAux( + 'published.boardAux.board03040', + BigInt(643), + new Date('2024-12-09T23:07:37.423Z'), + 'USDC_axl', + 'nat', + 6, + ), + ], + + 'handleStateChangeEvent', +); + +const oraclePriceDaily = new OraclePriceDaily( + 'ATOM-USD:20241209', + 20241209, + BigInt(506), + new Date('2024-12-09T23:03:17.000Z'), +); + +oraclePriceDaily.typeInAmountLast = BigInt(1000000); +oraclePriceDaily.typeInAmountSum = BigInt(1000000); +oraclePriceDaily.typeOutAmountLast = BigInt(12010000); +oraclePriceDaily.typeOutAmountSum = BigInt(12010000); +oraclePriceDaily.typeInName = 'ATOM'; +oraclePriceDaily.typeOutName = 'USD'; +oraclePriceDaily.metricsCount = BigInt(1); + +subqlTest( + 'oraclePriceDaily at block 506', + 506, + [], + [oraclePriceDaily], + + 'handleStateChangeEvent', +); + +const psmMetricsDaily = new PsmMetricsDaily( + 'published.psm.IST.USDC_axl.metrics:20241207', + 'published.psm.IST.USDC_axl.metrics', + 20241207, + BigInt(35), + new Date('2024-12-07T02:03:32.000Z'), +); + +psmMetricsDaily.denom = 'USDC_axl'; +psmMetricsDaily.anchorPoolBalanceLast = BigInt(0); +psmMetricsDaily.feePoolBalanceLast = BigInt(0); +psmMetricsDaily.mintedPoolBalanceLast = BigInt(0); +psmMetricsDaily.totalAnchorProvidedLast = BigInt(0); +psmMetricsDaily.totalMintedProvidedLast = BigInt(0); +psmMetricsDaily.metricsCount = BigInt(1); + +subqlTest('psmMetricsDaily at block 35', 35, [], [psmMetricsDaily], 'handleStateChangeEvent'); From 962afe2ccd809f60a9013fcb3aabc73490aff0fa Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Tue, 17 Dec 2024 13:59:24 +0500 Subject: [PATCH 16/25] ci: initial setup for liquidation testing --- .github/workflows/liquidation.yml | 29 +++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 30 insertions(+) create mode 100644 .github/workflows/liquidation.yml diff --git a/.github/workflows/liquidation.yml b/.github/workflows/liquidation.yml new file mode 100644 index 00000000..60b82b6e --- /dev/null +++ b/.github/workflows/liquidation.yml @@ -0,0 +1,29 @@ +name: Liquidation Testing +on: + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Start A3P container + run: docker run -d -p 26657:26657 -p 1317:1317 -p 9090:9090 --name a3p ghcr.io/agoric/agoric-3-proposals:latest + + - run: corepack enable + shell: bash + + - name: Setup Node.js environment + uses: actions/setup-node@v4 + with: + node-version: 18 + cache: yarn + + - name: Install dependencies + run: yarn install + + - name: Start subql indexer + run: yarn dev:ci + env: + AGORIC_NET: docker diff --git a/package.json b/package.json index 2811b755..49b376ea 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "codegen": "subql codegen", "start:docker": "docker-compose pull && docker-compose up --remove-orphans", "dev": "subql codegen && subql build && docker-compose pull && docker-compose up --remove-orphans", + "dev:ci": "subql codegen && subql build && docker compose pull && docker compose up --remove-orphans --detach", "prepack": "rm -rf dist && npm run build", "test": "subql build && subql-node-cosmos test", "prettier:check": "prettier --list-different . --print-width 120", From b74de953ef9a64c4fb267f45c7438cdd014f4fb2 Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Tue, 17 Dec 2024 14:30:41 +0500 Subject: [PATCH 17/25] ci: set ATOM price and create vaults --- .github/actions/createVault/action.yml | 48 ++++++++++++++++++++++++++ .github/workflows/liquidation.yml | 36 +++++++++++++++++-- package.json | 2 +- 3 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 .github/actions/createVault/action.yml diff --git a/.github/actions/createVault/action.yml b/.github/actions/createVault/action.yml new file mode 100644 index 00000000..d0f4eea0 --- /dev/null +++ b/.github/actions/createVault/action.yml @@ -0,0 +1,48 @@ +name: 'Create Vault' +description: 'Creates a vault and broadcasts an offer within an A3P container' +inputs: + wantMinted: + description: 'Amount of currency to be minted by the vault' + required: true + giveCollateral: + description: 'Collateral amount to secure the minted currency' + required: true + userKey: + description: 'User key to authenticate the transaction' + required: true + agoricNet: + description: 'Agoric network configuration' + required: true + commandTimeout: + description: 'Maximum time in seconds for the command to complete' + required: true + containerName: + description: 'Name of the Docker container where the commands will be executed' + 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..." + output=$(docker exec ${{ inputs.containerName }} /bin/bash -c "env AGORIC_NET=${{ inputs.agoricNet }} timeout ${{ inputs.commandTimeout }} $createVaultCommand") + + if echo "$output" | grep -q 'Error'; then + echo "Error found during vault creation: $output" + exit 1 + fi + - 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..." + output=$(docker exec ${{ inputs.containerName }} /bin/bash -c "env AGORIC_NET=${{ inputs.agoricNet }} timeout ${{ inputs.commandTimeout }} $broadcastCommand") + + if echo "$output" | grep -q 'Error'; then + echo "Error found during broadcast: $output" + exit 1 + else + echo "Broadcast successful: $output" diff --git a/.github/workflows/liquidation.yml b/.github/workflows/liquidation.yml index 60b82b6e..b4b3b56a 100644 --- a/.github/workflows/liquidation.yml +++ b/.github/workflows/liquidation.yml @@ -25,5 +25,37 @@ jobs: - name: Start subql indexer run: yarn dev:ci - env: - AGORIC_NET: docker + + - name: Set ATOM Price to 12.34 + run: | + docker exec a3p /usr/src/agoric-sdk/packages/agoric-cli/bin/agops oracle setPrice --keys gov1,gov2 --pair ATOM.USD --price 12.34 --keyring-backend=test + + - name: Create Vault with 100 Minted and 15 Collateral + uses: ./.github/actions/createVault + with: + wantMinted: '100' + giveCollateral: '15' + userKey: 'user1' + agoricNet: 'local' + commandTimeout: '120' + containerName: 'a3p' + + - name: Create Vault with 103 Minted and 15 Collateral + uses: ./.github/actions/createVault + with: + wantMinted: '103' + giveCollateral: '15' + userKey: 'user1' + agoricNet: 'local' + commandTimeout: '120' + containerName: 'a3p' + + - name: Create Vault with 105 Minted and 15 Collateral + uses: ./.github/actions/createVault + with: + wantMinted: '105' + giveCollateral: '15' + userKey: 'user1' + agoricNet: 'local' + commandTimeout: '120' + containerName: 'a3p' diff --git a/package.json b/package.json index 49b376ea..e9c7ec51 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "codegen": "subql codegen", "start:docker": "docker-compose pull && docker-compose up --remove-orphans", "dev": "subql codegen && subql build && docker-compose pull && docker-compose up --remove-orphans", - "dev:ci": "subql codegen && subql build && docker compose pull && docker compose up --remove-orphans --detach", + "dev:ci": "AGORIC_NET=docker subql codegen && subql build && docker compose pull && docker compose up --remove-orphans --detach", "prepack": "rm -rf dist && npm run build", "test": "subql build && subql-node-cosmos test", "prettier:check": "prettier --list-different . --print-width 120", From 4040adfda5712a43bbe0cb9e7ce3ecf166490f13 Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Tue, 17 Dec 2024 15:07:49 +0500 Subject: [PATCH 18/25] ci: place bids and set ATOM price to 9.99 --- .github/actions/createVault/action.yml | 14 ++------ .github/actions/placeBid/action.yml | 40 +++++++++++++++++++++++ .github/workflows/liquidation.yml | 45 +++++++++++++++++++++++--- 3 files changed, 84 insertions(+), 15 deletions(-) create mode 100644 .github/actions/placeBid/action.yml diff --git a/.github/actions/createVault/action.yml b/.github/actions/createVault/action.yml index d0f4eea0..3460914a 100644 --- a/.github/actions/createVault/action.yml +++ b/.github/actions/createVault/action.yml @@ -28,21 +28,13 @@ runs: 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..." - output=$(docker exec ${{ inputs.containerName }} /bin/bash -c "env AGORIC_NET=${{ inputs.agoricNet }} timeout ${{ inputs.commandTimeout }} $createVaultCommand") - if echo "$output" | grep -q 'Error'; then - echo "Error found during vault creation: $output" - exit 1 - fi + 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..." - output=$(docker exec ${{ inputs.containerName }} /bin/bash -c "env AGORIC_NET=${{ inputs.agoricNet }} timeout ${{ inputs.commandTimeout }} $broadcastCommand") - if echo "$output" | grep -q 'Error'; then - echo "Error found during broadcast: $output" - exit 1 - else - echo "Broadcast successful: $output" + docker exec ${{ inputs.containerName }} /bin/bash -c "env AGORIC_NET=${{ inputs.agoricNet }} timeout ${{ inputs.commandTimeout }} $broadcastCommand" diff --git a/.github/actions/placeBid/action.yml b/.github/actions/placeBid/action.yml new file mode 100644 index 00000000..b8375a35 --- /dev/null +++ b/.github/actions/placeBid/action.yml @@ -0,0 +1,40 @@ +name: 'Place Bids' +description: 'Place bids by price or discount' +inputs: + fromAddress: + description: 'Address from which the bid is made' + required: true + giveAmount: + description: 'Amount to offer in the bid' + required: true + priceOrDiscount: + description: 'Price or discount to apply to the bid' + required: true + commandType: + description: 'Type of command to execute (by-price or by-discount)' + required: true + agoricNet: + description: 'Agoric network configuration' + required: true + commandTimeout: + description: 'Maximum time in seconds for the command to complete' + required: true + containerName: + description: 'Name of the Docker container where the commands will be executed' + required: true + +runs: + using: 'composite' + steps: + - name: Place Bid + shell: bash + run: | + if [ "${{ inputs.commandType }}" == "by-price" ]; then + commandType="bid by-price --price" + elif [ "${{ inputs.commandType }}" == "by-discount" ]; then + commandType="bid by-discount --discount" + fi + + command="/usr/src/agoric-sdk/packages/agoric-cli/bin/agops inter ${commandType} \"${{ inputs.priceOrDiscount }}\" --from \"${{ inputs.fromAddress }}\" --give \"${{ inputs.giveAmount }}\" --keyring-backend=test" + echo "Executing command in the container..." + docker exec ${{ inputs.containerName }} /bin/bash -c "env AGORIC_NET=${{ inputs.agoricNet }} timeout ${{ inputs.commandTimeout }} $command" diff --git a/.github/workflows/liquidation.yml b/.github/workflows/liquidation.yml index b4b3b56a..8247f147 100644 --- a/.github/workflows/liquidation.yml +++ b/.github/workflows/liquidation.yml @@ -1,4 +1,4 @@ -name: Liquidation Testing +name: Liquidation Indexing on: pull_request: @@ -35,7 +35,7 @@ jobs: with: wantMinted: '100' giveCollateral: '15' - userKey: 'user1' + userKey: 'gov3' agoricNet: 'local' commandTimeout: '120' containerName: 'a3p' @@ -45,7 +45,7 @@ jobs: with: wantMinted: '103' giveCollateral: '15' - userKey: 'user1' + userKey: 'gov3' agoricNet: 'local' commandTimeout: '120' containerName: 'a3p' @@ -55,7 +55,44 @@ jobs: with: wantMinted: '105' giveCollateral: '15' - userKey: 'user1' + userKey: 'gov3' agoricNet: 'local' commandTimeout: '120' containerName: 'a3p' + + - name: Place bid for 90IST + uses: ./.github/actions/placeBid + with: + fromAddress: 'gov1' + giveAmount: '90IST' + priceOrDiscount: '9' + commandType: 'by-price' + agoricNet: 'local' + commandTimeout: '120' + containerName: 'a3p' + + - name: Place bid for 80IST + uses: ./.github/actions/placeBid + with: + fromAddress: 'gov1' + giveAmount: '80IST' + priceOrDiscount: '10' + commandType: 'by-discount' + agoricNet: 'local' + commandTimeout: '120' + containerName: 'a3p' + + - name: Place bid for 150IST + uses: ./.github/actions/placeBid + with: + fromAddress: 'gov1' + giveAmount: '150IST' + priceOrDiscount: '15' + commandType: 'by-discount' + agoricNet: 'local' + commandTimeout: '120' + containerName: 'a3p' + + - name: Set ATOM Price to 9.99 + run: | + docker exec a3p /usr/src/agoric-sdk/packages/agoric-cli/bin/agops oracle setPrice --keys gov1,gov2 --pair ATOM.USD --price 9.99 --keyring-backend=test From 05619b3a05e1dfc94d27a0e4e2067737c68d4d6e Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Tue, 17 Dec 2024 16:34:51 +0500 Subject: [PATCH 19/25] ci: get active vaults --- .github/actions/createVault/action.yml | 40 -------- .github/actions/placeBid/action.yml | 40 -------- .github/scripts/changePrice.mjs | 36 +++++++ .github/scripts/createVault.mjs | 37 +++++++ .github/scripts/getActiveVaults.mjs | 55 ++++++++++ .github/scripts/placeBid.mjs | 47 +++++++++ .github/workflows/liquidation.yml | 80 ++++++++++----- docker-compose.yml | 34 +++++-- package.json | 4 +- project.ts | 6 ++ yarn.lock | 136 +++++++++++++++++++++++++ 11 files changed, 400 insertions(+), 115 deletions(-) delete mode 100644 .github/actions/createVault/action.yml delete mode 100644 .github/actions/placeBid/action.yml create mode 100644 .github/scripts/changePrice.mjs create mode 100644 .github/scripts/createVault.mjs create mode 100644 .github/scripts/getActiveVaults.mjs create mode 100644 .github/scripts/placeBid.mjs diff --git a/.github/actions/createVault/action.yml b/.github/actions/createVault/action.yml deleted file mode 100644 index 3460914a..00000000 --- a/.github/actions/createVault/action.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: 'Create Vault' -description: 'Creates a vault and broadcasts an offer within an A3P container' -inputs: - wantMinted: - description: 'Amount of currency to be minted by the vault' - required: true - giveCollateral: - description: 'Collateral amount to secure the minted currency' - required: true - userKey: - description: 'User key to authenticate the transaction' - required: true - agoricNet: - description: 'Agoric network configuration' - required: true - commandTimeout: - description: 'Maximum time in seconds for the command to complete' - required: true - containerName: - description: 'Name of the Docker container where the commands will be executed' - 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" diff --git a/.github/actions/placeBid/action.yml b/.github/actions/placeBid/action.yml deleted file mode 100644 index b8375a35..00000000 --- a/.github/actions/placeBid/action.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: 'Place Bids' -description: 'Place bids by price or discount' -inputs: - fromAddress: - description: 'Address from which the bid is made' - required: true - giveAmount: - description: 'Amount to offer in the bid' - required: true - priceOrDiscount: - description: 'Price or discount to apply to the bid' - required: true - commandType: - description: 'Type of command to execute (by-price or by-discount)' - required: true - agoricNet: - description: 'Agoric network configuration' - required: true - commandTimeout: - description: 'Maximum time in seconds for the command to complete' - required: true - containerName: - description: 'Name of the Docker container where the commands will be executed' - required: true - -runs: - using: 'composite' - steps: - - name: Place Bid - shell: bash - run: | - if [ "${{ inputs.commandType }}" == "by-price" ]; then - commandType="bid by-price --price" - elif [ "${{ inputs.commandType }}" == "by-discount" ]; then - commandType="bid by-discount --discount" - fi - - command="/usr/src/agoric-sdk/packages/agoric-cli/bin/agops inter ${commandType} \"${{ inputs.priceOrDiscount }}\" --from \"${{ inputs.fromAddress }}\" --give \"${{ inputs.giveAmount }}\" --keyring-backend=test" - echo "Executing command in the container..." - docker exec ${{ inputs.containerName }} /bin/bash -c "env AGORIC_NET=${{ inputs.agoricNet }} timeout ${{ inputs.commandTimeout }} $command" diff --git a/.github/scripts/changePrice.mjs b/.github/scripts/changePrice.mjs new file mode 100644 index 00000000..707293b2 --- /dev/null +++ b/.github/scripts/changePrice.mjs @@ -0,0 +1,36 @@ +import { execa } from 'execa'; +import assert from 'assert'; + +const agops = '/usr/src/agoric-sdk/packages/agoric-cli/bin/agops'; + +const amount = process.env.amount; +const containerName = process.env.containerName; +const agoricNet = process.env.agoricNet; + +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 command = `${agops} oracle setPrice --keys gov1,gov2 --pair ATOM.USD --price ${amount} --keyring-backend=test`; + const { stdout, stderr } = await execa('docker', ['exec', containerName, command], { env, shell: true }); + + assert.strictEqual(stderr, '', `Expected stderr to be empty, but received: '${stderr}'`); + console.log('Standard output:', stdout); + } catch (error) { + console.error('Error:', error); + } +}; + +setAtomPrice(amount, containerName, agoricNet); diff --git a/.github/scripts/createVault.mjs b/.github/scripts/createVault.mjs new file mode 100644 index 00000000..ad0bbff8 --- /dev/null +++ b/.github/scripts/createVault.mjs @@ -0,0 +1,37 @@ +import { execa } from 'execa'; +import assert from 'assert'; + +const agops = '/usr/src/agoric-sdk/packages/agoric-cli/bin/agops'; + +const createVault = async (containerName, agoricNet, userKey, wantMinted, giveCollateral) => { + console.log('Starting the vault creation process...'); + + try { + const env = { + AGORIC_NET: agoricNet, + }; + + const command = `${agops} vaults open --wantMinted ${wantMinted} --giveCollateral ${giveCollateral} > /tmp/want-ist.json`; + await execa('docker', ['exec', containerName, `bash -c "${command}"`], { env, shell: true }); + + const broadCastCommand = `${agops} perf satisfaction --executeOffer /tmp/want-ist.json --from ${userKey} --keyring-backend=test`; + const { stdout } = await execa('docker', ['exec', containerName, broadCastCommand], { + env, + shell: true, + }); + + assert.ok(!stdout.includes('Error'), `Expected 'stdout' not to contain 'Error'`); + console.log('Standard output:', stdout); + } catch (error) { + console.error('Error during vault creation:', error); + process.exit(1); + } +}; + +const containerName = process.env.containerName; +const agoricNet = process.env.agoricNet; +const userKey = process.env.userKey; +const wantMinted = process.env.wantMinted; +const giveCollateral = process.env.giveCollateral; + +createVault(containerName, agoricNet, userKey, wantMinted, giveCollateral); diff --git a/.github/scripts/getActiveVaults.mjs b/.github/scripts/getActiveVaults.mjs new file mode 100644 index 00000000..a62f48f9 --- /dev/null +++ b/.github/scripts/getActiveVaults.mjs @@ -0,0 +1,55 @@ +import fetch from 'node-fetch'; + +const delay = (ms) => { + return new Promise((resolve) => setTimeout(resolve, ms)); +}; +const getActiveVaults = async (apiUrl, expectedVaults) => { + console.log('Fetching the number of active vaults...'); + const maxRetries = 5; + let retries = 0; + + while (retries < maxRetries) { + try { + const graphqlQuery = { + query: `query { vaults(filter: {state: {equalTo: "active"}}) { totalCount } }`, + }; + + const response = await fetch(apiUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json', + }, + body: JSON.stringify(graphqlQuery), + }); + + const jsonResponse = await response.json(); + const activeVaults = jsonResponse.data.vaults.totalCount; + + console.log(`Attempt ${retries + 1}: Active vaults: ${activeVaults}`); + + if (activeVaults === expectedVaults) { + console.log(`Assertion passed: ${activeVaults} active vaults match the expected count.`); + return; + } + + console.log( + `Assertion failed on attempt ${retries + 1}: Expected ${expectedVaults} active vaults, but found ${activeVaults}. Retrying...`, + ); + retries++; + await delay(5000); + } catch (error) { + console.error(`Error on attempt ${retries + 1} fetching active vaults:`, error); + retries++; + await delay(5000); + } + } + + console.error('Maximum retry attempts reached. Exiting...'); + process.exit(1); +}; + +const apiUrl = process.env.apiUrl; +const expectedVaults = parseInt(process.env.expectedVaults, 10); + +getActiveVaults(apiUrl, expectedVaults); diff --git a/.github/scripts/placeBid.mjs b/.github/scripts/placeBid.mjs new file mode 100644 index 00000000..100081c5 --- /dev/null +++ b/.github/scripts/placeBid.mjs @@ -0,0 +1,47 @@ +import { execa } from 'execa'; +import assert from 'assert'; + +const agops = '/usr/src/agoric-sdk/packages/agoric-cli/bin/agops'; + +const placeBid = async ({ fromAddress, giveAmount, priceOrDiscount, commandType, agoricNet, containerName }) => { + console.log('Starting the bidding process...'); + + try { + const env = { + AGORIC_NET: agoricNet, + }; + + let commandTypeOption; + if (commandType === 'by-price') { + commandTypeOption = 'by-price --price'; + } else if (commandType === 'by-discount') { + commandTypeOption = 'by-discount --discount'; + } + + const command = `${agops} inter bid ${commandTypeOption} ${priceOrDiscount} --from ${fromAddress} --give ${giveAmount} --keyring-backend=test`; + + console.log('Executing command in the container...'); + const { stdout } = await execa('docker', ['exec', containerName, `bash -c "${command}"`], { + env, + shell: true, + }); + + assert.ok(stdout.includes('Your bid has been accepted')); + console.log('Standard output:', stdout); + } catch (error) { + console.error('Error during bid placement:', error); + process.exit(1); + } +}; + +const bidInfo = { + fromAddress: process.env.fromAddress, + giveAmount: process.env.giveAmount, + priceOrDiscount: process.env.priceOrDiscount, + commandType: process.env.commandType, + agoricNet: process.env.agoricNet, + commandTimeout: process.env.commandTimeout, + containerName: process.env.containerName, +}; + +placeBid(bidInfo); diff --git a/.github/workflows/liquidation.yml b/.github/workflows/liquidation.yml index 8247f147..cb0f38d8 100644 --- a/.github/workflows/liquidation.yml +++ b/.github/workflows/liquidation.yml @@ -9,7 +9,7 @@ jobs: - uses: actions/checkout@v4 - name: Start A3P container - run: docker run -d -p 26657:26657 -p 1317:1317 -p 9090:9090 --name a3p ghcr.io/agoric/agoric-3-proposals:latest + run: docker compose --profile ci up -d a3p - run: corepack enable shell: bash @@ -24,75 +24,101 @@ jobs: run: yarn install - name: Start subql indexer - run: yarn dev:ci + env: + AGORIC_NET: ci + run: yarn dev - - name: Set ATOM Price to 12.34 + - name: Print initial logs of all containers run: | - docker exec a3p /usr/src/agoric-sdk/packages/agoric-cli/bin/agops oracle setPrice --keys gov1,gov2 --pair ATOM.USD --price 12.34 --keyring-backend=test + 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: node .github/scripts/changePrice.mjs + env: + amount: 12.34 + containerName: agd + agoricNet: local + + - name: Get active vaults + run: node .github/scripts/getActiveVaults.mjs + env: + apiUrl: 'http://localhost:3000/' + expectedVaults: '7' - name: Create Vault with 100 Minted and 15 Collateral - uses: ./.github/actions/createVault - with: + run: node .github/scripts/createVault.mjs + env: wantMinted: '100' giveCollateral: '15' userKey: 'gov3' agoricNet: 'local' commandTimeout: '120' - containerName: 'a3p' + containerName: 'agd' - name: Create Vault with 103 Minted and 15 Collateral - uses: ./.github/actions/createVault - with: + run: node .github/scripts/createVault.mjs + env: wantMinted: '103' giveCollateral: '15' userKey: 'gov3' agoricNet: 'local' commandTimeout: '120' - containerName: 'a3p' + containerName: 'agd' - name: Create Vault with 105 Minted and 15 Collateral - uses: ./.github/actions/createVault - with: + run: node .github/scripts/createVault.mjs + env: wantMinted: '105' giveCollateral: '15' userKey: 'gov3' agoricNet: 'local' commandTimeout: '120' - containerName: 'a3p' + containerName: 'agd' + + - name: Get active vaults + run: node .github/scripts/getActiveVaults.mjs + env: + apiUrl: 'http://localhost:3000/' + expectedVaults: 10 - name: Place bid for 90IST - uses: ./.github/actions/placeBid - with: + run: node .github/scripts/placeBid.mjs + env: fromAddress: 'gov1' giveAmount: '90IST' priceOrDiscount: '9' commandType: 'by-price' agoricNet: 'local' - commandTimeout: '120' - containerName: 'a3p' + containerName: 'agd' - name: Place bid for 80IST - uses: ./.github/actions/placeBid - with: + run: node .github/scripts/placeBid.mjs + env: fromAddress: 'gov1' giveAmount: '80IST' priceOrDiscount: '10' commandType: 'by-discount' agoricNet: 'local' - commandTimeout: '120' - containerName: 'a3p' + containerName: 'agd' - name: Place bid for 150IST - uses: ./.github/actions/placeBid - with: + run: node .github/scripts/placeBid.mjs + env: fromAddress: 'gov1' giveAmount: '150IST' priceOrDiscount: '15' commandType: 'by-discount' agoricNet: 'local' - commandTimeout: '120' - containerName: 'a3p' + containerName: 'agd' - name: Set ATOM Price to 9.99 - run: | - docker exec a3p /usr/src/agoric-sdk/packages/agoric-cli/bin/agops oracle setPrice --keys gov1,gov2 --pair ATOM.USD --price 9.99 --keyring-backend=test + run: node .github/scripts/changePrice.mjs + env: + amount: 9.99 + containerName: agd + agoricNet: local diff --git a/docker-compose.yml b/docker-compose.yml index ddd67f4f..e2ecc711 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,11 +14,14 @@ services: interval: 5s timeout: 5s retries: 5 + profiles: + - default + - ci subquery-node: image: subquerynetwork/subql-node-cosmos:v4.2.1 depends_on: - 'postgres': + postgres: condition: service_healthy restart: always environment: @@ -30,27 +33,28 @@ services: volumes: - ./:/app command: - - ${SUB_COMMAND:-} # set SUB_COMMAND env variable to "test" to run tests + - ${SUB_COMMAND:-} - -f=/app - --db-schema=app - --workers=4 - --batch-size=30 - # - --log-level=debug - # - --unfinalized-blocks=true healthcheck: test: ['CMD', 'curl', '-f', 'http://subquery-node:3000/ready'] interval: 3s timeout: 5s retries: 10 + profiles: + - default + - ci graphql-engine: image: onfinality/subql-query:v2.13.0 ports: - 3000:3000 depends_on: - 'postgres': + postgres: condition: service_healthy - 'subquery-node': + subquery-node: condition: service_healthy restart: always environment: @@ -63,3 +67,21 @@ services: - --name=app - --playground - --indexer=http://subquery-node:3000 + profiles: + - default + - ci + + a3p: + image: ghcr.io/agoric/agoric-3-proposals:latest + container_name: agd + ports: + - 26657:26657 + - 1317:1317 + - 9090:9090 + restart: always + profiles: + - ci + +networks: + default: + driver: bridge diff --git a/package.json b/package.json index e9c7ec51..4f8f205b 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,7 @@ "build": "subql build", "codegen": "subql codegen", "start:docker": "docker-compose pull && docker-compose up --remove-orphans", - "dev": "subql codegen && subql build && docker-compose pull && docker-compose up --remove-orphans", - "dev:ci": "AGORIC_NET=docker subql codegen && subql build && docker compose pull && docker compose up --remove-orphans --detach", + "dev": "subql codegen && subql build && docker compose pull && docker compose --profile default up --remove-orphans --detach", "prepack": "rm -rf dist && npm run build", "test": "subql build && subql-node-cosmos test", "prettier:check": "prettier --list-different . --print-width 120", @@ -28,6 +27,7 @@ "@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" diff --git a/project.ts b/project.ts index a26e2303..5ed79c5d 100644 --- a/project.ts +++ b/project.ts @@ -44,6 +44,12 @@ const networkConfig = { chaintypes: chainTypesU18, startBlock: 1, }, + ci: { + chainId: 'agoriclocal', + endpoint: ['http://a3p:26657'], + chaintypes: chainTypesU18, + startBlock: 1, + }, main: { chainId: 'agoric-3', endpoint: ['https://main-a.rpc.agoric.net:443'], diff --git a/yarn.lock b/yarn.lock index 4c0e2d2d..c75cf26d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3156,6 +3156,13 @@ __metadata: languageName: node linkType: hard +"@sec-ant/readable-stream@npm:^0.4.1": + version: 0.4.1 + resolution: "@sec-ant/readable-stream@npm:0.4.1" + checksum: 10c0/64e9e9cf161e848067a5bf60cdc04d18495dc28bb63a8d9f8993e4dd99b91ad34e4b563c85de17d91ffb177ec17a0664991d2e115f6543e73236a906068987af + languageName: node + linkType: hard + "@sinclair/typebox@npm:^0.24.1": version: 0.24.51 resolution: "@sinclair/typebox@npm:0.24.51" @@ -3170,6 +3177,13 @@ __metadata: languageName: node linkType: hard +"@sindresorhus/merge-streams@npm:^4.0.0": + version: 4.0.0 + resolution: "@sindresorhus/merge-streams@npm:4.0.0" + checksum: 10c0/482ee543629aa1933b332f811a1ae805a213681ecdd98c042b1c1b89387df63e7812248bb4df3910b02b3cc5589d3d73e4393f30e197c9dde18046ccd471fc6b + languageName: node + linkType: hard + "@starknet-io/types-js@npm:^0.7.7, starknet-types-07@npm:@starknet-io/types-js@^0.7.7": version: 0.7.10 resolution: "@starknet-io/types-js@npm:0.7.10" @@ -4113,6 +4127,7 @@ __metadata: "@subql/utils": "npm:^2.17.0" "@types/node": "npm:^17.0.21" bech32: "npm:^2.0.0" + execa: "npm:^9.5.2" js-sha256: "npm:^0.11.0" pino: "npm:^7.8.0" prettier: "npm:^3.4.2" @@ -5892,6 +5907,26 @@ __metadata: languageName: node linkType: hard +"execa@npm:^9.5.2": + version: 9.5.2 + resolution: "execa@npm:9.5.2" + dependencies: + "@sindresorhus/merge-streams": "npm:^4.0.0" + cross-spawn: "npm:^7.0.3" + figures: "npm:^6.1.0" + get-stream: "npm:^9.0.0" + human-signals: "npm:^8.0.0" + is-plain-obj: "npm:^4.1.0" + is-stream: "npm:^4.0.1" + npm-run-path: "npm:^6.0.0" + pretty-ms: "npm:^9.0.0" + signal-exit: "npm:^4.1.0" + strip-final-newline: "npm:^4.0.0" + yoctocolors: "npm:^2.0.0" + checksum: 10c0/94782a6282e03253224406c29068d18f9095cc251a45d1f19ac3d8f2a9db2cbe32fb8ceb039db1451d8fce3531135a6c0c559f76d634f85416268fc4a6995365 + languageName: node + linkType: hard + "exponential-backoff@npm:^3.1.1": version: 3.1.1 resolution: "exponential-backoff@npm:3.1.1" @@ -6047,6 +6082,15 @@ __metadata: languageName: node linkType: hard +"figures@npm:^6.1.0": + version: 6.1.0 + resolution: "figures@npm:6.1.0" + dependencies: + is-unicode-supported: "npm:^2.0.0" + checksum: 10c0/9159df4264d62ef447a3931537de92f5012210cf5135c35c010df50a2169377581378149abfe1eb238bd6acbba1c0d547b1f18e0af6eee49e30363cedaffcfe4 + languageName: node + linkType: hard + "file-uri-to-path@npm:1.0.0": version: 1.0.0 resolution: "file-uri-to-path@npm:1.0.0" @@ -6307,6 +6351,16 @@ __metadata: languageName: node linkType: hard +"get-stream@npm:^9.0.0": + version: 9.0.1 + resolution: "get-stream@npm:9.0.1" + dependencies: + "@sec-ant/readable-stream": "npm:^0.4.1" + is-stream: "npm:^4.0.1" + checksum: 10c0/d70e73857f2eea1826ac570c3a912757dcfbe8a718a033fa0c23e12ac8e7d633195b01710e0559af574cbb5af101009b42df7b6f6b29ceec8dbdf7291931b948 + languageName: node + linkType: hard + "glob-parent@npm:^5.1.2": version: 5.1.2 resolution: "glob-parent@npm:5.1.2" @@ -6604,6 +6658,13 @@ __metadata: languageName: node linkType: hard +"human-signals@npm:^8.0.0": + version: 8.0.0 + resolution: "human-signals@npm:8.0.0" + checksum: 10c0/e4dac4f7d3eb791ed04129fc6a85bd454a9102d3e3b76c911d0db7057ebd60b2956b435b5b5712aec18960488ede3c21ef7c56e42cdd70760c0d84d3c05cd92e + languageName: node + linkType: hard + "humanize-number@npm:0.0.2": version: 0.0.2 resolution: "humanize-number@npm:0.0.2" @@ -6913,6 +6974,13 @@ __metadata: languageName: node linkType: hard +"is-plain-obj@npm:^4.1.0": + version: 4.1.0 + resolution: "is-plain-obj@npm:4.1.0" + checksum: 10c0/32130d651d71d9564dc88ba7e6fda0e91a1010a3694648e9f4f47bb6080438140696d3e3e15c741411d712e47ac9edc1a8a9de1fe76f3487b0d90be06ac9975e + languageName: node + linkType: hard + "is-plain-object@npm:^2.0.4": version: 2.0.4 resolution: "is-plain-object@npm:2.0.4" @@ -6929,6 +6997,13 @@ __metadata: languageName: node linkType: hard +"is-stream@npm:^4.0.1": + version: 4.0.1 + resolution: "is-stream@npm:4.0.1" + checksum: 10c0/2706c7f19b851327ba374687bc4a3940805e14ca496dc672b9629e744d143b1ad9c6f1b162dece81c7bfbc0f83b32b61ccc19ad2e05aad2dd7af347408f60c7f + languageName: node + linkType: hard + "is-typedarray@npm:^1.0.0": version: 1.0.0 resolution: "is-typedarray@npm:1.0.0" @@ -6943,6 +7018,13 @@ __metadata: languageName: node linkType: hard +"is-unicode-supported@npm:^2.0.0": + version: 2.1.0 + resolution: "is-unicode-supported@npm:2.1.0" + checksum: 10c0/a0f53e9a7c1fdbcf2d2ef6e40d4736fdffff1c9f8944c75e15425118ff3610172c87bf7bc6c34d3903b04be59790bb2212ddbe21ee65b5a97030fc50370545a5 + languageName: node + linkType: hard + "is-wsl@npm:^2.2.0": version: 2.2.0 resolution: "is-wsl@npm:2.2.0" @@ -8007,6 +8089,16 @@ __metadata: languageName: node linkType: hard +"npm-run-path@npm:^6.0.0": + version: 6.0.0 + resolution: "npm-run-path@npm:6.0.0" + dependencies: + path-key: "npm:^4.0.0" + unicorn-magic: "npm:^0.3.0" + checksum: 10c0/b223c8a0dcd608abf95363ea5c3c0ccc3cd877daf0102eaf1b0f2390d6858d8337fbb7c443af2403b067a7d2c116d10691ecd22ab3c5273c44da1ff8d07753bd + languageName: node + linkType: hard + "object-assign@npm:^4, object-assign@npm:^4.0.1, object-assign@npm:^4.1.1": version: 4.1.1 resolution: "object-assign@npm:4.1.1" @@ -8179,6 +8271,13 @@ __metadata: languageName: node linkType: hard +"parse-ms@npm:^4.0.0": + version: 4.0.0 + resolution: "parse-ms@npm:4.0.0" + checksum: 10c0/a7900f4f1ebac24cbf5e9708c16fb2fd482517fad353aecd7aefb8c2ba2f85ce017913ccb8925d231770404780df46244ea6fec598b3bde6490882358b4d2d16 + languageName: node + linkType: hard + "parse-package-name@npm:1.0.0": version: 1.0.0 resolution: "parse-package-name@npm:1.0.0" @@ -8224,6 +8323,13 @@ __metadata: languageName: node linkType: hard +"path-key@npm:^4.0.0": + version: 4.0.0 + resolution: "path-key@npm:4.0.0" + checksum: 10c0/794efeef32863a65ac312f3c0b0a99f921f3e827ff63afa5cb09a377e202c262b671f7b3832a4e64731003fa94af0263713962d317b9887bd1e0c48a342efba3 + languageName: node + linkType: hard + "path-parse@npm:^1.0.7": version: 1.0.7 resolution: "path-parse@npm:1.0.7" @@ -8481,6 +8587,15 @@ __metadata: languageName: node linkType: hard +"pretty-ms@npm:^9.0.0": + version: 9.2.0 + resolution: "pretty-ms@npm:9.2.0" + dependencies: + parse-ms: "npm:^4.0.0" + checksum: 10c0/ab6d066f90e9f77020426986e1b018369f41575674544c539aabec2e63a20fec01166d8cf6571d0e165ad11cfe5a8134a2a48a36d42ab291c59c6deca5264cbb + languageName: node + linkType: hard + "proc-log@npm:^5.0.0": version: 5.0.0 resolution: "proc-log@npm:5.0.0" @@ -9552,6 +9667,13 @@ __metadata: languageName: node linkType: hard +"strip-final-newline@npm:^4.0.0": + version: 4.0.0 + resolution: "strip-final-newline@npm:4.0.0" + checksum: 10c0/b0cf2b62d597a1b0e3ebc42b88767f0a0d45601f89fd379a928a1812c8779440c81abba708082c946445af1d6b62d5f16e2a7cf4f30d9d6587b89425fae801ff + languageName: node + linkType: hard + "strip-json-comments@npm:~2.0.1": version: 2.0.1 resolution: "strip-json-comments@npm:2.0.1" @@ -10043,6 +10165,13 @@ __metadata: languageName: node linkType: hard +"unicorn-magic@npm:^0.3.0": + version: 0.3.0 + resolution: "unicorn-magic@npm:0.3.0" + checksum: 10c0/0a32a997d6c15f1c2a077a15b1c4ca6f268d574cf5b8975e778bb98e6f8db4ef4e86dfcae4e158cd4c7e38fb4dd383b93b13eefddc7f178dea13d3ac8a603271 + languageName: node + linkType: hard + "unique-filename@npm:^4.0.0": version: 4.0.0 resolution: "unique-filename@npm:4.0.0" @@ -10664,6 +10793,13 @@ __metadata: languageName: node linkType: hard +"yoctocolors@npm:^2.0.0": + version: 2.1.1 + resolution: "yoctocolors@npm:2.1.1" + checksum: 10c0/85903f7fa96f1c70badee94789fade709f9d83dab2ec92753d612d84fcea6d34c772337a9f8914c6bed2f5fc03a428ac5d893e76fab636da5f1236ab725486d0 + languageName: node + linkType: hard + "zen-observable-ts@npm:^1.2.5": version: 1.2.5 resolution: "zen-observable-ts@npm:1.2.5" From fccc9a02415e529798783743c7ab83ad6fee5f14 Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Wed, 18 Dec 2024 16:24:12 +0500 Subject: [PATCH 20/25] ci: validate liquidating vaults --- .github/scripts/changePrice.mjs | 3 +- .github/scripts/checkLiquidation.mjs | 157 +++++++++++++++++++++++++++ .github/workflows/liquidation.yml | 13 ++- .github/workflows/pr.yaml | 2 +- package.json | 2 +- yarn.lock | 44 +++----- 6 files changed, 186 insertions(+), 35 deletions(-) create mode 100644 .github/scripts/checkLiquidation.mjs diff --git a/.github/scripts/changePrice.mjs b/.github/scripts/changePrice.mjs index 707293b2..913988c7 100644 --- a/.github/scripts/changePrice.mjs +++ b/.github/scripts/changePrice.mjs @@ -24,9 +24,8 @@ const setAtomPrice = async (amount, containerName, agoricNet) => { }; const command = `${agops} oracle setPrice --keys gov1,gov2 --pair ATOM.USD --price ${amount} --keyring-backend=test`; - const { stdout, stderr } = await execa('docker', ['exec', containerName, command], { env, shell: true }); + const { stdout } = await execa('docker', ['exec', containerName, command], { env, shell: true }); - assert.strictEqual(stderr, '', `Expected stderr to be empty, but received: '${stderr}'`); console.log('Standard output:', stdout); } catch (error) { console.error('Error:', error); diff --git a/.github/scripts/checkLiquidation.mjs b/.github/scripts/checkLiquidation.mjs new file mode 100644 index 00000000..7ac30d31 --- /dev/null +++ b/.github/scripts/checkLiquidation.mjs @@ -0,0 +1,157 @@ +// @ts-check +import fetch from 'node-fetch'; +import assert from 'assert'; +const delay = (ms) => { + return new Promise((resolve) => setTimeout(resolve, ms)); +}; + +const states = { + liquidated: 'liquidated', + liquidating: 'liquidating', +}; + +const expectedLiquidating = { + ids: [ + 'published.vaultFactory.managers.manager0.vaults.vault10-liquidating', + 'published.vaultFactory.managers.manager0.vaults.vault11-liquidating', + 'published.vaultFactory.managers.manager0.vaults.vault12-liquidating', + ], + debts: ['100500000', '103515000', '105525000'], + balance: ['15000000', '15000000', '15000000'], + denom: 'ATOM', +}; + +const expectedLiquidated = { + ids: [ + 'published.vaultFactory.managers.manager0.vaults.vault10-liquidated', + 'published.vaultFactory.managers.manager0.vaults.vault11-liquidated', + 'published.vaultFactory.managers.manager0.vaults.vault12-liquidated', + ], + debts: ['0', '0', '0'], + balance: ['3425146', '3077900', '2846403'], + denom: 'ATOM', +}; + +const validate = async ({ + apiUrl, + maxRetries, + retryDuration, + expectedIds, + expectedDebts, + expectedBalance, + expectedDenom, + filterState, +}) => { + console.log(`Checking ${filterState} vaults...`); + let retries = 0; + + while (retries < maxRetries) { + try { + const graphqlQuery = { + query: `query { + vaultLiquidations (filter: {state: {equalTo: "${filterState}"}}) { + nodes { + id + denom + debt + state + balance + } + } + }`, + }; + + const response = await fetch(apiUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json', + }, + body: JSON.stringify(graphqlQuery), + }); + + const jsonResponse = await response.json(); + console.log('Response:', JSON.stringify(jsonResponse)); + + const nodes = jsonResponse?.data?.vaultLiquidations?.nodes || []; + if (nodes.length !== 3) { + console.error(`Attempt ${retries + 1}: No data available`); + retries++; + await delay(retryDuration); + continue; + } + + nodes.sort((a, b) => a.id.localeCompare(b.id)); + console.log('Sorted Nodes:', JSON.stringify(nodes)); + + // Validate Ids + assert.strictEqual(nodes[0].id, expectedIds[0]); + assert.strictEqual(nodes[1].id, expectedIds[1]); + assert.strictEqual(nodes[2].id, expectedIds[2]); + + // Validate Debts + assert.strictEqual(nodes[0].debt, expectedDebts[0]); + assert.strictEqual(nodes[1].debt, expectedDebts[1]); + assert.strictEqual(nodes[2].debt, expectedDebts[2]); + + // Validate Denom + assert.strictEqual(nodes[0].denom, expectedDenom); + assert.strictEqual(nodes[1].denom, expectedDenom); + assert.strictEqual(nodes[2].denom, expectedDenom); + + // Validate Balance + assert.strictEqual(nodes[0].balance, expectedBalance[0]); + assert.strictEqual(nodes[1].balance, expectedBalance[1]); + assert.strictEqual(nodes[2].balance, expectedBalance[2]); + + console.log('All validations passed successfully.'); + return; + } catch (error) { + console.error(`Error on attempt ${retries + 1} fetching active vaults:`, error); + retries++; + await delay(retryDuration); + } + } + + console.error('Maximum retry attempts reached. Exiting...'); + process.exit(1); +}; + +const main = async () => { + console.log('Starting main process...'); + + const apiUrl = process.env.API_URL || 'http://localhost:3000/'; + console.log(`API URL set to: ${apiUrl}`); + + try { + console.log('Validating liquidating vaults...'); + await validate({ + apiUrl, + expectedIds: expectedLiquidating.ids, + expectedBalance: expectedLiquidating.balance, + expectedDenom: expectedLiquidating.denom, + expectedDebts: expectedLiquidating.debts, + maxRetries: 6, + retryDuration: 3 * 60 * 1000, + filterState: states.liquidating, + }); + console.log('Validation successful for liquidating vaults.'); + + console.log('Validating liquidated vaults...'); + await validate({ + apiUrl, + expectedIds: expectedLiquidated.ids, + expectedBalance: expectedLiquidated.balance, + expectedDenom: expectedLiquidated.denom, + expectedDebts: expectedLiquidated.debts, + maxRetries: 3, + retryDuration: 2 * 60 * 1000, + filterState: states.liquidated, + }); + console.log('Validation successful for liquidated vaults.'); + } catch (error) { + console.error('Validation failed:', error); + } +}; + +main(); diff --git a/.github/workflows/liquidation.yml b/.github/workflows/liquidation.yml index cb0f38d8..60e4aa38 100644 --- a/.github/workflows/liquidation.yml +++ b/.github/workflows/liquidation.yml @@ -48,7 +48,7 @@ jobs: run: node .github/scripts/getActiveVaults.mjs env: apiUrl: 'http://localhost:3000/' - expectedVaults: '7' + expectedVaults: 7 - name: Create Vault with 100 Minted and 15 Collateral run: node .github/scripts/createVault.mjs @@ -122,3 +122,14 @@ jobs: amount: 9.99 containerName: agd agoricNet: local + + - name: Check liquidation indexing + run: node .github/scripts/checkLiquidation.mjs + env: + apiUrl: 'http://localhost:3000/' + + - name: Get active vaults + run: node .github/scripts/getActiveVaults.mjs + env: + apiUrl: 'http://localhost:3000/' + expectedVaults: 7 diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 7e5e2084..c19f2b3a 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest services: a3p: - image: ghcr.io/agoric/agoric-3-proposals@sha256:644e09bf041e5588570ff9a49e6129cc468e9c8458417541027e8532cb91083b + image: ghcr.io/agoric/agoric-3-proposals:use-upgrade-17 ports: - 26657:26657 postgres: diff --git a/package.json b/package.json index 4f8f205b..e08a1b1f 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "devDependencies": { "@cosmjs/stargate": "^0.28.9", "@subql/cli": "^5.4.0", - "@subql/node-cosmos": "4.2.1", + "@subql/node-cosmos": "^4.2.1", "@subql/testing": "latest", "execa": "^9.5.2", "prettier": "^3.4.2", diff --git a/yarn.lock b/yarn.lock index c75cf26d..3e88d8c1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3228,9 +3228,9 @@ __metadata: languageName: node linkType: hard -"@subql/common-cosmos@npm:5.0.6": - version: 5.0.6 - resolution: "@subql/common-cosmos@npm:5.0.6" +"@subql/common-cosmos@npm:5.1.0": + version: 5.1.0 + resolution: "@subql/common-cosmos@npm:5.1.0" dependencies: "@cosmwasm/ts-codegen": "npm:^1.11.1" "@protobufs/cosmos": "npm:^0.1.0" @@ -3240,7 +3240,7 @@ __metadata: "@protobufs/google": "npm:^0.0.10" "@protobufs/ibc": "npm:^0.1.0" "@protobufs/tendermint": "npm:^0.0.10" - "@subql/common": "npm:^5.2.1" + "@subql/common": "npm:^5.2.2" "@subql/types-cosmos": "npm:4.0.0" "@subql/x-cosmology-telescope": "npm:^1.4.14" fs-extra: "npm:^11.1.1" @@ -3250,11 +3250,11 @@ __metadata: class-transformer: "*" class-validator: "*" ejs: "*" - checksum: 10c0/7c1b2beb1d0497d1aa4bbf987c2bd91ccbe4f13456259dcdd9dc6fae10e791e7efdf6e01061ce35e1e219dd41429fb639595053574b75f301d911061af268ca1 + checksum: 10c0/83f6eabcdf6dcf2d9d8e499201f7751eb2009ec0c501be2c58b0e269ee40d77d34db90090562afbf91ff10bf9adaec9e04aff025766829200c95f035eff58c4b languageName: node linkType: hard -"@subql/common@npm:5.2.2": +"@subql/common@npm:5.2.2, @subql/common@npm:^5.2.2": version: 5.2.2 resolution: "@subql/common@npm:5.2.2" dependencies: @@ -3271,22 +3271,6 @@ __metadata: languageName: node linkType: hard -"@subql/common@npm:^5.2.1": - version: 5.2.1 - resolution: "@subql/common@npm:5.2.1" - dependencies: - "@subql/types-core": "npm:2.0.0" - axios: "npm:^0.28.0" - class-transformer: "npm:^0.5.1" - class-validator: "npm:^0.14.1" - js-yaml: "npm:^4.1.0" - reflect-metadata: "npm:^0.1.14" - semver: "npm:^7.6.3" - update-notifier: "npm:^5.1.0" - checksum: 10c0/02ac5e46489e9eeb73f01c007e868d491f415462d654149bb296f1c4f0d74ff67b4881458a154f237a1e88df7f4a99fdf0ff44739b85ae44b871234642753fc6 - languageName: node - linkType: hard - "@subql/node-core@npm:^16.1.0": version: 16.1.0 resolution: "@subql/node-core@npm:16.1.0" @@ -3319,9 +3303,9 @@ __metadata: languageName: node linkType: hard -"@subql/node-cosmos@npm:4.2.1": - version: 4.2.1 - resolution: "@subql/node-cosmos@npm:4.2.1" +"@subql/node-cosmos@npm:^4.2.1": + version: 4.3.0 + resolution: "@subql/node-cosmos@npm:4.3.0" dependencies: "@cosmjs/cosmwasm-stargate": "npm:^0.32.4" "@cosmjs/proto-signing": "npm:^0.32.4" @@ -3333,9 +3317,9 @@ __metadata: "@nestjs/event-emitter": "npm:^2.0.0" "@nestjs/platform-express": "npm:^9.4.0" "@nestjs/schedule": "npm:^3.0.1" - "@subql/common": "npm:^5.2.1" - "@subql/common-cosmos": "npm:5.0.6" - "@subql/node-core": "npm:^15.0.2" + "@subql/common": "npm:^5.2.2" + "@subql/common-cosmos": "npm:5.1.0" + "@subql/node-core": "npm:^16.1.0" "@subql/types-cosmos": "npm:4.0.0" lodash: "npm:^4.17.21" protobufjs: "npm:^6.11.4" @@ -3346,7 +3330,7 @@ __metadata: "@subql/utils": "*" bin: subql-node-cosmos: ./bin/run - checksum: 10c0/950dc4aae8bbca6b47c8e618c44d2d7c63ea39206d748f3a4d57a105e88509447fa72c0f6d6fd92b0394aec030f1f9cf932715d864e031cf0ebe49adbf4dcd74 + checksum: 10c0/78cc7dbde1cb39465ec3d1f231105a69e33cd7eb98bcb06d8aa45264ee9eb3b64777147ead5d6d6b9ab92bcfed73dff6344fbb8b23233dc7fda0d5f2885d124a languageName: node linkType: hard @@ -4121,7 +4105,7 @@ __metadata: dependencies: "@cosmjs/stargate": "npm:^0.28.9" "@subql/cli": "npm:^5.4.0" - "@subql/node-cosmos": "npm:4.2.1" + "@subql/node-cosmos": "npm:^4.2.1" "@subql/testing": "npm:latest" "@subql/types-cosmos": "npm:^4.0.0" "@subql/utils": "npm:^2.17.0" From deee3de467c13da9f3c639ba69b3833b2f855621 Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Wed, 18 Dec 2024 22:05:39 +0500 Subject: [PATCH 21/25] fixup! ci: validate liquidating vaults --- .github/scripts/changePrice.mjs | 35 --- .github/scripts/checkLiquidation.mjs | 157 ----------- .github/scripts/createVault.mjs | 37 --- .github/scripts/placeBid.mjs | 47 ---- .github/workflows/liquidation.yml | 40 +-- package.json | 1 + scripts/changePrice.mjs | 22 ++ scripts/checkLiquidation.mjs | 121 ++++++++ {.github/scripts => scripts}/ci.package.json | 0 {.github/scripts => scripts}/ci.tsconfig.json | 0 .../scripts => scripts}/copy-ts-config.sh | 0 scripts/createVault.mjs | 31 +++ .../scripts => scripts}/getActiveVaults.mjs | 3 +- scripts/placeBid.mjs | 37 +++ yarn.lock | 258 ++++++++++++++++++ 15 files changed, 492 insertions(+), 297 deletions(-) delete mode 100644 .github/scripts/changePrice.mjs delete mode 100644 .github/scripts/checkLiquidation.mjs delete mode 100644 .github/scripts/createVault.mjs delete mode 100644 .github/scripts/placeBid.mjs create mode 100644 scripts/changePrice.mjs create mode 100644 scripts/checkLiquidation.mjs rename {.github/scripts => scripts}/ci.package.json (100%) rename {.github/scripts => scripts}/ci.tsconfig.json (100%) rename {.github/scripts => scripts}/copy-ts-config.sh (100%) create mode 100644 scripts/createVault.mjs rename {.github/scripts => scripts}/getActiveVaults.mjs (97%) create mode 100644 scripts/placeBid.mjs diff --git a/.github/scripts/changePrice.mjs b/.github/scripts/changePrice.mjs deleted file mode 100644 index 913988c7..00000000 --- a/.github/scripts/changePrice.mjs +++ /dev/null @@ -1,35 +0,0 @@ -import { execa } from 'execa'; -import assert from 'assert'; - -const agops = '/usr/src/agoric-sdk/packages/agoric-cli/bin/agops'; - -const amount = process.env.amount; -const containerName = process.env.containerName; -const agoricNet = process.env.agoricNet; - -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 command = `${agops} oracle setPrice --keys gov1,gov2 --pair ATOM.USD --price ${amount} --keyring-backend=test`; - const { stdout } = await execa('docker', ['exec', containerName, command], { env, shell: true }); - - console.log('Standard output:', stdout); - } catch (error) { - console.error('Error:', error); - } -}; - -setAtomPrice(amount, containerName, agoricNet); diff --git a/.github/scripts/checkLiquidation.mjs b/.github/scripts/checkLiquidation.mjs deleted file mode 100644 index 7ac30d31..00000000 --- a/.github/scripts/checkLiquidation.mjs +++ /dev/null @@ -1,157 +0,0 @@ -// @ts-check -import fetch from 'node-fetch'; -import assert from 'assert'; -const delay = (ms) => { - return new Promise((resolve) => setTimeout(resolve, ms)); -}; - -const states = { - liquidated: 'liquidated', - liquidating: 'liquidating', -}; - -const expectedLiquidating = { - ids: [ - 'published.vaultFactory.managers.manager0.vaults.vault10-liquidating', - 'published.vaultFactory.managers.manager0.vaults.vault11-liquidating', - 'published.vaultFactory.managers.manager0.vaults.vault12-liquidating', - ], - debts: ['100500000', '103515000', '105525000'], - balance: ['15000000', '15000000', '15000000'], - denom: 'ATOM', -}; - -const expectedLiquidated = { - ids: [ - 'published.vaultFactory.managers.manager0.vaults.vault10-liquidated', - 'published.vaultFactory.managers.manager0.vaults.vault11-liquidated', - 'published.vaultFactory.managers.manager0.vaults.vault12-liquidated', - ], - debts: ['0', '0', '0'], - balance: ['3425146', '3077900', '2846403'], - denom: 'ATOM', -}; - -const validate = async ({ - apiUrl, - maxRetries, - retryDuration, - expectedIds, - expectedDebts, - expectedBalance, - expectedDenom, - filterState, -}) => { - console.log(`Checking ${filterState} vaults...`); - let retries = 0; - - while (retries < maxRetries) { - try { - const graphqlQuery = { - query: `query { - vaultLiquidations (filter: {state: {equalTo: "${filterState}"}}) { - nodes { - id - denom - debt - state - balance - } - } - }`, - }; - - const response = await fetch(apiUrl, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - Accept: 'application/json', - }, - body: JSON.stringify(graphqlQuery), - }); - - const jsonResponse = await response.json(); - console.log('Response:', JSON.stringify(jsonResponse)); - - const nodes = jsonResponse?.data?.vaultLiquidations?.nodes || []; - if (nodes.length !== 3) { - console.error(`Attempt ${retries + 1}: No data available`); - retries++; - await delay(retryDuration); - continue; - } - - nodes.sort((a, b) => a.id.localeCompare(b.id)); - console.log('Sorted Nodes:', JSON.stringify(nodes)); - - // Validate Ids - assert.strictEqual(nodes[0].id, expectedIds[0]); - assert.strictEqual(nodes[1].id, expectedIds[1]); - assert.strictEqual(nodes[2].id, expectedIds[2]); - - // Validate Debts - assert.strictEqual(nodes[0].debt, expectedDebts[0]); - assert.strictEqual(nodes[1].debt, expectedDebts[1]); - assert.strictEqual(nodes[2].debt, expectedDebts[2]); - - // Validate Denom - assert.strictEqual(nodes[0].denom, expectedDenom); - assert.strictEqual(nodes[1].denom, expectedDenom); - assert.strictEqual(nodes[2].denom, expectedDenom); - - // Validate Balance - assert.strictEqual(nodes[0].balance, expectedBalance[0]); - assert.strictEqual(nodes[1].balance, expectedBalance[1]); - assert.strictEqual(nodes[2].balance, expectedBalance[2]); - - console.log('All validations passed successfully.'); - return; - } catch (error) { - console.error(`Error on attempt ${retries + 1} fetching active vaults:`, error); - retries++; - await delay(retryDuration); - } - } - - console.error('Maximum retry attempts reached. Exiting...'); - process.exit(1); -}; - -const main = async () => { - console.log('Starting main process...'); - - const apiUrl = process.env.API_URL || 'http://localhost:3000/'; - console.log(`API URL set to: ${apiUrl}`); - - try { - console.log('Validating liquidating vaults...'); - await validate({ - apiUrl, - expectedIds: expectedLiquidating.ids, - expectedBalance: expectedLiquidating.balance, - expectedDenom: expectedLiquidating.denom, - expectedDebts: expectedLiquidating.debts, - maxRetries: 6, - retryDuration: 3 * 60 * 1000, - filterState: states.liquidating, - }); - console.log('Validation successful for liquidating vaults.'); - - console.log('Validating liquidated vaults...'); - await validate({ - apiUrl, - expectedIds: expectedLiquidated.ids, - expectedBalance: expectedLiquidated.balance, - expectedDenom: expectedLiquidated.denom, - expectedDebts: expectedLiquidated.debts, - maxRetries: 3, - retryDuration: 2 * 60 * 1000, - filterState: states.liquidated, - }); - console.log('Validation successful for liquidated vaults.'); - } catch (error) { - console.error('Validation failed:', error); - } -}; - -main(); diff --git a/.github/scripts/createVault.mjs b/.github/scripts/createVault.mjs deleted file mode 100644 index ad0bbff8..00000000 --- a/.github/scripts/createVault.mjs +++ /dev/null @@ -1,37 +0,0 @@ -import { execa } from 'execa'; -import assert from 'assert'; - -const agops = '/usr/src/agoric-sdk/packages/agoric-cli/bin/agops'; - -const createVault = async (containerName, agoricNet, userKey, wantMinted, giveCollateral) => { - console.log('Starting the vault creation process...'); - - try { - const env = { - AGORIC_NET: agoricNet, - }; - - const command = `${agops} vaults open --wantMinted ${wantMinted} --giveCollateral ${giveCollateral} > /tmp/want-ist.json`; - await execa('docker', ['exec', containerName, `bash -c "${command}"`], { env, shell: true }); - - const broadCastCommand = `${agops} perf satisfaction --executeOffer /tmp/want-ist.json --from ${userKey} --keyring-backend=test`; - const { stdout } = await execa('docker', ['exec', containerName, broadCastCommand], { - env, - shell: true, - }); - - assert.ok(!stdout.includes('Error'), `Expected 'stdout' not to contain 'Error'`); - console.log('Standard output:', stdout); - } catch (error) { - console.error('Error during vault creation:', error); - process.exit(1); - } -}; - -const containerName = process.env.containerName; -const agoricNet = process.env.agoricNet; -const userKey = process.env.userKey; -const wantMinted = process.env.wantMinted; -const giveCollateral = process.env.giveCollateral; - -createVault(containerName, agoricNet, userKey, wantMinted, giveCollateral); diff --git a/.github/scripts/placeBid.mjs b/.github/scripts/placeBid.mjs deleted file mode 100644 index 100081c5..00000000 --- a/.github/scripts/placeBid.mjs +++ /dev/null @@ -1,47 +0,0 @@ -import { execa } from 'execa'; -import assert from 'assert'; - -const agops = '/usr/src/agoric-sdk/packages/agoric-cli/bin/agops'; - -const placeBid = async ({ fromAddress, giveAmount, priceOrDiscount, commandType, agoricNet, containerName }) => { - console.log('Starting the bidding process...'); - - try { - const env = { - AGORIC_NET: agoricNet, - }; - - let commandTypeOption; - if (commandType === 'by-price') { - commandTypeOption = 'by-price --price'; - } else if (commandType === 'by-discount') { - commandTypeOption = 'by-discount --discount'; - } - - const command = `${agops} inter bid ${commandTypeOption} ${priceOrDiscount} --from ${fromAddress} --give ${giveAmount} --keyring-backend=test`; - - console.log('Executing command in the container...'); - const { stdout } = await execa('docker', ['exec', containerName, `bash -c "${command}"`], { - env, - shell: true, - }); - - assert.ok(stdout.includes('Your bid has been accepted')); - console.log('Standard output:', stdout); - } catch (error) { - console.error('Error during bid placement:', error); - process.exit(1); - } -}; - -const bidInfo = { - fromAddress: process.env.fromAddress, - giveAmount: process.env.giveAmount, - priceOrDiscount: process.env.priceOrDiscount, - commandType: process.env.commandType, - agoricNet: process.env.agoricNet, - commandTimeout: process.env.commandTimeout, - containerName: process.env.containerName, -}; - -placeBid(bidInfo); diff --git a/.github/workflows/liquidation.yml b/.github/workflows/liquidation.yml index 60e4aa38..e164a366 100644 --- a/.github/workflows/liquidation.yml +++ b/.github/workflows/liquidation.yml @@ -38,98 +38,98 @@ jobs: done - name: Set ATOM Price to 12.34 - run: node .github/scripts/changePrice.mjs + run: ./scripts/changePrice.mjs env: amount: 12.34 containerName: agd - agoricNet: local + AGORIC_NET: local - name: Get active vaults - run: node .github/scripts/getActiveVaults.mjs + run: ./scripts/getActiveVaults.mjs env: apiUrl: 'http://localhost:3000/' expectedVaults: 7 - name: Create Vault with 100 Minted and 15 Collateral - run: node .github/scripts/createVault.mjs + run: ./scripts/createVault.mjs env: wantMinted: '100' giveCollateral: '15' userKey: 'gov3' - agoricNet: 'local' + AGORIC_NET: 'local' commandTimeout: '120' containerName: 'agd' - name: Create Vault with 103 Minted and 15 Collateral - run: node .github/scripts/createVault.mjs + run: ./scripts/createVault.mjs env: wantMinted: '103' giveCollateral: '15' userKey: 'gov3' - agoricNet: 'local' + AGORIC_NET: 'local' commandTimeout: '120' containerName: 'agd' - name: Create Vault with 105 Minted and 15 Collateral - run: node .github/scripts/createVault.mjs + run: ./scripts/createVault.mjs env: wantMinted: '105' giveCollateral: '15' userKey: 'gov3' - agoricNet: 'local' + AGORIC_NET: 'local' commandTimeout: '120' containerName: 'agd' - name: Get active vaults - run: node .github/scripts/getActiveVaults.mjs + run: ./scripts/getActiveVaults.mjs env: apiUrl: 'http://localhost:3000/' expectedVaults: 10 - name: Place bid for 90IST - run: node .github/scripts/placeBid.mjs + run: ./scripts/placeBid.mjs env: fromAddress: 'gov1' giveAmount: '90IST' priceOrDiscount: '9' commandType: 'by-price' - agoricNet: 'local' + AGORIC_NET: 'local' containerName: 'agd' - name: Place bid for 80IST - run: node .github/scripts/placeBid.mjs + run: ./scripts/placeBid.mjs env: fromAddress: 'gov1' giveAmount: '80IST' priceOrDiscount: '10' commandType: 'by-discount' - agoricNet: 'local' + AGORIC_NET: 'local' containerName: 'agd' - name: Place bid for 150IST - run: node .github/scripts/placeBid.mjs + run: ./scripts/placeBid.mjs env: fromAddress: 'gov1' giveAmount: '150IST' priceOrDiscount: '15' commandType: 'by-discount' - agoricNet: 'local' + AGORIC_NET: 'local' containerName: 'agd' - name: Set ATOM Price to 9.99 - run: node .github/scripts/changePrice.mjs + run: ./scripts/changePrice.mjs env: amount: 9.99 containerName: agd - agoricNet: local + AGORIC_NET: local - name: Check liquidation indexing - run: node .github/scripts/checkLiquidation.mjs + run: ./scripts/checkLiquidation.mjs env: apiUrl: 'http://localhost:3000/' - name: Get active vaults - run: node .github/scripts/getActiveVaults.mjs + run: ./scripts/getActiveVaults.mjs env: apiUrl: 'http://localhost:3000/' expectedVaults: 7 diff --git a/package.json b/package.json index e08a1b1f..8c88226e 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "author": "Agoric OpCo", "license": "Apache-2.0", "devDependencies": { + "@agoric/internal": "0.4.0-u18.0", "@cosmjs/stargate": "^0.28.9", "@subql/cli": "^5.4.0", "@subql/node-cosmos": "^4.2.1", diff --git a/scripts/changePrice.mjs b/scripts/changePrice.mjs new file mode 100644 index 00000000..e72900b9 --- /dev/null +++ b/scripts/changePrice.mjs @@ -0,0 +1,22 @@ +#! /usr/bin/env node +import { execa } from 'execa'; +import { assertAllDefined } from '@agoric/internal'; + +const agops = '/usr/src/agoric-sdk/packages/agoric-cli/bin/agops'; +const { AGORIC_NET, amount, containerName } = process.env; + +assertAllDefined({ AGORIC_NET, amount, containerName }); + +try { + const env = { + AGORIC_NET, + }; + + console.log(`Initiating price change to ${amount} for ATOM...`); + const command = `${agops} oracle setPrice --keys gov1,gov2 --pair ATOM.USD --price ${amount} --keyring-backend=test`; + const { stdout } = await execa('docker', ['exec', containerName, command], { env, shell: true }); + + console.log('Standard output:', stdout); +} catch (error) { + console.error('Error:', error); +} diff --git a/scripts/checkLiquidation.mjs b/scripts/checkLiquidation.mjs new file mode 100644 index 00000000..9b8208ed --- /dev/null +++ b/scripts/checkLiquidation.mjs @@ -0,0 +1,121 @@ +#! /usr/bin/env node +/* eslint-env node */ +import { equal } from 'node:assert/strict'; +const delay = (ms) => { + return new Promise((resolve) => setTimeout(resolve, ms)); +}; + +const states = { + liquidated: 'liquidated', + liquidating: 'liquidating', +}; + +const expectedLiquidating = { + id: [ + 'published.vaultFactory.managers.manager0.vaults.vault10-liquidating', + 'published.vaultFactory.managers.manager0.vaults.vault11-liquidating', + 'published.vaultFactory.managers.manager0.vaults.vault12-liquidating', + ], + debt: ['100500000', '103515000', '105525000'], + balance: ['15000000', '15000000', '15000000'], + denom: ['ATOM', 'ATOM', 'ATOM'], +}; + +const expectedLiquidated = { + id: [ + 'published.vaultFactory.managers.manager0.vaults.vault10-liquidated', + 'published.vaultFactory.managers.manager0.vaults.vault11-liquidated', + 'published.vaultFactory.managers.manager0.vaults.vault12-liquidated', + ], + debt: ['0', '0', '0'], + balance: ['3425146', '3077900', '2846403'], + denom: ['ATOM', 'ATOM', 'ATOM'], +}; + +const validate = async ({ apiUrl, maxRetries, retryDuration, expectations, filterState }) => { + let retries = 0; + + while (retries < maxRetries) { + try { + const graphqlQuery = { + query: `query { + vaultLiquidations (filter: {state: {equalTo: "${filterState}"}}) { + nodes { + id + denom + debt + state + balance + } + } + }`, + }; + + const response = await fetch(apiUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json', + }, + body: JSON.stringify(graphqlQuery), + }); + + const jsonResponse = await response.json(); + console.log('Response:', JSON.stringify(jsonResponse)); + + const nodes = jsonResponse?.data?.vaultLiquidations?.nodes || []; + if (nodes.length !== 3) { + console.error(`Attempt ${retries + 1}: No data available`); + retries++; + await delay(retryDuration); + continue; + } + + nodes.sort((a, b) => a.id.localeCompare(b.id)); + console.log('Sorted Nodes:', JSON.stringify(nodes)); + + for (const key of Object.keys(expectations)) { + for (let i = 0; i < nodes.length; i++) { + equal(nodes[i][key], expectations[i].key); + } + } + + console.log('All validations passed successfully.'); + return; + } catch (error) { + console.error(`Error on attempt ${retries + 1} fetching active vaults:`, error); + retries++; + await delay(retryDuration); + } + } + + console.error('Maximum retry attempts reached. Exiting...'); + process.exit(1); +}; + +const apiUrl = process.env.API_URL || 'http://localhost:3000/'; +console.log(`API URL set to: ${apiUrl}`); + +try { + console.log('Validating liquidating vaults...'); + await validate({ + apiUrl, + expectations: expectedLiquidating, + maxRetries: 6, + retryDuration: 3 * 60 * 1000, + filterState: states.liquidating, + }); + console.log('Validation successful for liquidating vaults.'); + + console.log('Validating liquidated vaults...'); + await validate({ + apiUrl, + expectations: expectedLiquidated, + maxRetries: 3, + retryDuration: 2 * 60 * 1000, + filterState: states.liquidated, + }); + console.log('Validation successful for liquidated vaults.'); +} catch (error) { + console.error('Validation failed:', error); +} diff --git a/.github/scripts/ci.package.json b/scripts/ci.package.json similarity index 100% rename from .github/scripts/ci.package.json rename to scripts/ci.package.json diff --git a/.github/scripts/ci.tsconfig.json b/scripts/ci.tsconfig.json similarity index 100% rename from .github/scripts/ci.tsconfig.json rename to scripts/ci.tsconfig.json diff --git a/.github/scripts/copy-ts-config.sh b/scripts/copy-ts-config.sh similarity index 100% rename from .github/scripts/copy-ts-config.sh rename to scripts/copy-ts-config.sh diff --git a/scripts/createVault.mjs b/scripts/createVault.mjs new file mode 100644 index 00000000..241df2f2 --- /dev/null +++ b/scripts/createVault.mjs @@ -0,0 +1,31 @@ +#! /usr/bin/env node +import { execa } from 'execa'; +import assert from 'node:assert/strict'; +import { assertAllDefined } from '@agoric/internal'; + +const agops = '/usr/src/agoric-sdk/packages/agoric-cli/bin/agops'; + +const { AGORIC_NET, userKey, containerName, wantMinted, giveCollateral } = process.env; +assertAllDefined({ AGORIC_NET, userKey, containerName, wantMinted, giveCollateral }); + +try { + const env = { + AGORIC_NET, + }; + + console.log('Starting the vault creation process...'); + const command = `${agops} vaults open --wantMinted ${wantMinted} --giveCollateral ${giveCollateral} > /tmp/want-ist.json`; + await execa('docker', ['exec', containerName, `bash -c "${command}"`], { env, shell: true }); + + const broadCastCommand = `${agops} perf satisfaction --executeOffer /tmp/want-ist.json --from ${userKey} --keyring-backend=test`; + const { stdout } = await execa('docker', ['exec', containerName, broadCastCommand], { + env, + shell: true, + }); + + assert.ok(!stdout.includes('Error'), `Expected 'stdout' not to contain 'Error'`); + console.log('Standard output:', stdout); +} catch (error) { + console.error('Error during vault creation:', error); + process.exit(1); +} diff --git a/.github/scripts/getActiveVaults.mjs b/scripts/getActiveVaults.mjs similarity index 97% rename from .github/scripts/getActiveVaults.mjs rename to scripts/getActiveVaults.mjs index a62f48f9..4d4cb21c 100644 --- a/.github/scripts/getActiveVaults.mjs +++ b/scripts/getActiveVaults.mjs @@ -1,4 +1,5 @@ -import fetch from 'node-fetch'; +#! /usr/bin/env node +/* eslint-env node */ const delay = (ms) => { return new Promise((resolve) => setTimeout(resolve, ms)); diff --git a/scripts/placeBid.mjs b/scripts/placeBid.mjs new file mode 100644 index 00000000..8ee96e7a --- /dev/null +++ b/scripts/placeBid.mjs @@ -0,0 +1,37 @@ +#! /usr/bin/env node +import { execa } from 'execa'; +import assert from 'node:assert/strict'; +import { assertAllDefined } from '@agoric/internal'; + +const agops = '/usr/src/agoric-sdk/packages/agoric-cli/bin/agops'; + +const { AGORIC_NET, fromAddress, giveAmount, priceOrDiscount, commandType, containerName } = process.env; +assertAllDefined({ AGORIC_NET, fromAddress, giveAmount, priceOrDiscount, commandType, containerName }); + +try { + const env = { + AGORIC_NET, + }; + + let commandTypeOption; + if (commandType === 'by-price') { + commandTypeOption = 'by-price --price'; + } else if (commandType === 'by-discount') { + commandTypeOption = 'by-discount --discount'; + } + + console.log('Starting the bidding process...'); + const command = `${agops} inter bid ${commandTypeOption} ${priceOrDiscount} --from ${fromAddress} --give ${giveAmount} --keyring-backend=test`; + + console.log('Executing command in the container...'); + const { stdout } = await execa('docker', ['exec', containerName, `bash -c "${command}"`], { + env, + shell: true, + }); + + assert.ok(stdout.includes('Your bid has been accepted')); + console.log('Standard output:', stdout); +} catch (error) { + console.error('Error during bid placement:', error); + process.exit(1); +} diff --git a/yarn.lock b/yarn.lock index 3e88d8c1..9b3c15a8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5,6 +5,54 @@ __metadata: version: 8 cacheKey: 10c0 +"@agoric/base-zone@npm:^0.1.1-u18.0": + version: 0.1.1-upgrade-18-dev-ef001c0.0 + resolution: "@agoric/base-zone@npm:0.1.1-upgrade-18-dev-ef001c0.0" + dependencies: + "@agoric/store": "npm:0.9.3-upgrade-18-dev-ef001c0.0+ef001c0" + "@endo/common": "npm:^1.2.7" + "@endo/errors": "npm:^1.2.7" + "@endo/exo": "npm:^1.5.6" + "@endo/far": "npm:^1.1.8" + "@endo/pass-style": "npm:^1.4.6" + "@endo/patterns": "npm:^1.4.6" + checksum: 10c0/0df4eba4133cf41c8a3e4edbfe5ba74a0976fde58687c50a1fb32b932160538ec1af077495c375b3ee223df271086500e571b02086275c8ea5be2d5c6c658702 + languageName: node + linkType: hard + +"@agoric/internal@npm:0.4.0-u18.0": + version: 0.4.0-u18.0 + resolution: "@agoric/internal@npm:0.4.0-u18.0" + dependencies: + "@agoric/base-zone": "npm:^0.1.1-u18.0" + "@endo/common": "npm:^1.2.7" + "@endo/errors": "npm:^1.2.7" + "@endo/far": "npm:^1.1.8" + "@endo/init": "npm:^1.1.6" + "@endo/marshal": "npm:^1.6.1" + "@endo/pass-style": "npm:^1.4.6" + "@endo/patterns": "npm:^1.4.6" + "@endo/promise-kit": "npm:^1.1.7" + "@endo/stream": "npm:^1.2.7" + anylogger: "npm:^0.21.0" + jessie.js: "npm:^0.3.4" + checksum: 10c0/5a7d36cb8faf69eabf9d53f6ea79bcd10187d83782e6fa06d8debd5d5565ecdbf33ef85efbe8697e91eed09c21599ab03b8b746065611513cc54b467a87ce427 + languageName: node + linkType: hard + +"@agoric/store@npm:0.9.3-upgrade-18-dev-ef001c0.0+ef001c0": + version: 0.9.3-upgrade-18-dev-ef001c0.0 + resolution: "@agoric/store@npm:0.9.3-upgrade-18-dev-ef001c0.0" + dependencies: + "@endo/errors": "npm:^1.2.7" + "@endo/exo": "npm:^1.5.6" + "@endo/marshal": "npm:^1.6.1" + "@endo/pass-style": "npm:^1.4.6" + "@endo/patterns": "npm:^1.4.6" + checksum: 10c0/8ca7d3a1b4fe909b98146d6c91c0a79a812f1df27ce298d791a0a1b1224f344eacb756be7a6c5c5abc16a875855b99eeddb0d058bcdcea01a55ccf0e2b8bc8ff + languageName: node + linkType: hard + "@ampproject/remapping@npm:^2.1.0, @ampproject/remapping@npm:^2.2.0": version: 2.3.0 resolution: "@ampproject/remapping@npm:2.3.0" @@ -1954,6 +2002,163 @@ __metadata: languageName: node linkType: hard +"@endo/base64@npm:^1.0.9": + version: 1.0.9 + resolution: "@endo/base64@npm:1.0.9" + checksum: 10c0/63e487cf59b50a080fab389a8ab24d66264910ecf375dc19677c2ee7421d92a4be9c85e435b216b4adc9983384073a7eb753223f85ba77aec8d9fd3e0c1fe090 + languageName: node + linkType: hard + +"@endo/common@npm:^1.2.7, @endo/common@npm:^1.2.8": + version: 1.2.8 + resolution: "@endo/common@npm:1.2.8" + dependencies: + "@endo/errors": "npm:^1.2.8" + "@endo/eventual-send": "npm:^1.2.8" + "@endo/promise-kit": "npm:^1.1.8" + checksum: 10c0/c9465721095d9f06278b6550909a02c330c7a69223f11aff29759067586d41b86054127639fa2c2c0345d0d0aa43518e5b72d5c547b67bfe8e802cd21756d87b + languageName: node + linkType: hard + +"@endo/env-options@npm:^1.1.8": + version: 1.1.8 + resolution: "@endo/env-options@npm:1.1.8" + checksum: 10c0/2f519f48a5b966dbd9e66134d4abc89ff02b9791d21146b49031ceb694584f3f41c6119125b6bb4eb0d347f5bcd846473b5f3c4ae6bae3dac19402fcaf522520 + languageName: node + linkType: hard + +"@endo/errors@npm:^1.2.7, @endo/errors@npm:^1.2.8": + version: 1.2.8 + resolution: "@endo/errors@npm:1.2.8" + dependencies: + ses: "npm:^1.10.0" + checksum: 10c0/3f33fc7119ab840ad0f5bdfb70e73cc99630f09593c31928e30de4d9c8e898c85397c5170964d54c819a757a74d3b005f6275480ff8d0f1aa2aa8ef872852e97 + languageName: node + linkType: hard + +"@endo/eventual-send@npm:^1.2.8": + version: 1.2.8 + resolution: "@endo/eventual-send@npm:1.2.8" + dependencies: + "@endo/env-options": "npm:^1.1.8" + checksum: 10c0/d7c16c935441b67d029fcb6785f425a1194fb7f936e4b20dde21eb393266cb7366edf7a95d3fdfa96cd4a3246a3659a06d0dbb3c1217045e1718e1cf34c7a3bd + languageName: node + linkType: hard + +"@endo/exo@npm:^1.5.6": + version: 1.5.7 + resolution: "@endo/exo@npm:1.5.7" + dependencies: + "@endo/common": "npm:^1.2.8" + "@endo/env-options": "npm:^1.1.8" + "@endo/errors": "npm:^1.2.8" + "@endo/eventual-send": "npm:^1.2.8" + "@endo/far": "npm:^1.1.9" + "@endo/pass-style": "npm:^1.4.7" + "@endo/patterns": "npm:^1.4.7" + checksum: 10c0/0193de0606a7f07f207f3dd8bb71ec6be0acfb0ff5ef570f03cbbcaed888db68e451082c34764de8ee301f8d2d175e6c5a5405e76367c27151d644536bdf57a4 + languageName: node + linkType: hard + +"@endo/far@npm:^1.0.0, @endo/far@npm:^1.1.8, @endo/far@npm:^1.1.9": + version: 1.1.9 + resolution: "@endo/far@npm:1.1.9" + dependencies: + "@endo/errors": "npm:^1.2.8" + "@endo/eventual-send": "npm:^1.2.8" + "@endo/pass-style": "npm:^1.4.7" + checksum: 10c0/e0d95743c25183b961aa1f11dd81c067739fd2fb3deeab58520e949961eacba9ed109bb01b9ed820d596e8a043b6721d650d9624abf0263296cca647e7286a2e + languageName: node + linkType: hard + +"@endo/init@npm:^1.1.6": + version: 1.1.7 + resolution: "@endo/init@npm:1.1.7" + dependencies: + "@endo/base64": "npm:^1.0.9" + "@endo/eventual-send": "npm:^1.2.8" + "@endo/lockdown": "npm:^1.0.13" + "@endo/promise-kit": "npm:^1.1.8" + checksum: 10c0/6cfcc244f02da9883f65a8f34da9483a628d5350192983c53d5116b12403dc5693145c6349b6c3ca381b6b8d9590cee16f90440dc0e2da5f525e13079d6c9a2f + languageName: node + linkType: hard + +"@endo/lockdown@npm:^1.0.13": + version: 1.0.13 + resolution: "@endo/lockdown@npm:1.0.13" + dependencies: + ses: "npm:^1.10.0" + checksum: 10c0/9df04cc477595b368088a1d445f2241d8a152cb4dcf6a79d39d4804594dd8ff472380ab2bdf262adeb5b4b7cfc73effb6cc716c5a3aeca282801d57fe8a018a0 + languageName: node + linkType: hard + +"@endo/marshal@npm:^1.6.1, @endo/marshal@npm:^1.6.2": + version: 1.6.2 + resolution: "@endo/marshal@npm:1.6.2" + dependencies: + "@endo/common": "npm:^1.2.8" + "@endo/errors": "npm:^1.2.8" + "@endo/eventual-send": "npm:^1.2.8" + "@endo/nat": "npm:^5.0.13" + "@endo/pass-style": "npm:^1.4.7" + "@endo/promise-kit": "npm:^1.1.8" + checksum: 10c0/bdb634a77c2147c1359792531822aabe642a5e4d39f496dd57bb97367617a2f2d72edaaa50c51ed6a2ec1f2c08deab6a571c3dd8ffa260d441d25f53606902b1 + languageName: node + linkType: hard + +"@endo/nat@npm:^5.0.13": + version: 5.0.13 + resolution: "@endo/nat@npm:5.0.13" + checksum: 10c0/78578de4567c9bc4c6f50638c688886c07c38177a8d44192230d344221da06ccffc6d9ef8d423e27198d864ed7c57ef5ced9b1d05922eaa4e40bf82856b1aa11 + languageName: node + linkType: hard + +"@endo/pass-style@npm:^1.4.6, @endo/pass-style@npm:^1.4.7": + version: 1.4.7 + resolution: "@endo/pass-style@npm:1.4.7" + dependencies: + "@endo/env-options": "npm:^1.1.8" + "@endo/errors": "npm:^1.2.8" + "@endo/eventual-send": "npm:^1.2.8" + "@endo/promise-kit": "npm:^1.1.8" + "@fast-check/ava": "npm:^1.1.5" + checksum: 10c0/ee30e011fb08c292718a315f2ebd5ee2da6d918bf2cdaf2b269e123207c642fa1525493c41180db8c941e1a1959369730114b116656c99e8bb107ca5917f3f4e + languageName: node + linkType: hard + +"@endo/patterns@npm:^1.4.6, @endo/patterns@npm:^1.4.7": + version: 1.4.7 + resolution: "@endo/patterns@npm:1.4.7" + dependencies: + "@endo/common": "npm:^1.2.8" + "@endo/errors": "npm:^1.2.8" + "@endo/eventual-send": "npm:^1.2.8" + "@endo/marshal": "npm:^1.6.2" + "@endo/promise-kit": "npm:^1.1.8" + checksum: 10c0/358720438a019847406dfad9f23fc9b565c955ffd86d75693cea994c492dd46efaf189502f04b04f8870e6d50ffcb44ffa1e1dd3a0d6b2dfbbe57edeb994b83b + languageName: node + linkType: hard + +"@endo/promise-kit@npm:^1.1.7, @endo/promise-kit@npm:^1.1.8": + version: 1.1.8 + resolution: "@endo/promise-kit@npm:1.1.8" + dependencies: + ses: "npm:^1.10.0" + checksum: 10c0/3a51755822bd4112474bec584005b81f9ffe6a6b590faa16cff7a4994010d001d6d190f58a1e890d85b0feb0eb052d79ed2c5ed88977afb0e47ca53b6b199196 + languageName: node + linkType: hard + +"@endo/stream@npm:^1.2.7": + version: 1.2.8 + resolution: "@endo/stream@npm:1.2.8" + dependencies: + "@endo/eventual-send": "npm:^1.2.8" + "@endo/promise-kit": "npm:^1.1.8" + ses: "npm:^1.10.0" + checksum: 10c0/f435f7650020b32c10bb4cb139910b363b4d4f22bcf9e7a659d3d2eae694a3ea43c3af49c80370760a573370429e5fbe1619dec631251578d4c5eba9ff161613 + languageName: node + linkType: hard + "@ethersproject/address@npm:^5.6.0": version: 5.7.0 resolution: "@ethersproject/address@npm:5.7.0" @@ -2014,6 +2219,17 @@ __metadata: languageName: node linkType: hard +"@fast-check/ava@npm:^1.1.5": + version: 1.2.1 + resolution: "@fast-check/ava@npm:1.2.1" + dependencies: + fast-check: "npm:^3.0.0" + peerDependencies: + ava: ^4 || ^5 || ^6 + checksum: 10c0/3800098fd7e8098102544a2f7a595351d063a7ebaeca18ed4901df5ec2679da2330ba8c0db2c820721d4cbb3e23d817ba22fec6d058957930e229f44fa71a684 + languageName: node + linkType: hard + "@graphql-typed-document-node/core@npm:^3.1.1": version: 3.2.0 resolution: "@graphql-typed-document-node/core@npm:3.2.0" @@ -4103,6 +4319,7 @@ __metadata: version: 0.0.0-use.local resolution: "agoric-indexer@workspace:." dependencies: + "@agoric/internal": "npm:0.4.0-u18.0" "@cosmjs/stargate": "npm:^0.28.9" "@subql/cli": "npm:^5.4.0" "@subql/node-cosmos": "npm:^4.2.1" @@ -4254,6 +4471,13 @@ __metadata: languageName: node linkType: hard +"anylogger@npm:^0.21.0": + version: 0.21.0 + resolution: "anylogger@npm:0.21.0" + checksum: 10c0/1ca7fcf5bc2b78d1e1d9b8c8cc7ce50b5c6cc67a8da5a28c9c975b7b46fff255a04abab02de38a5139190c9d8b34b3d6c59af6724521b077f7d7dfbad9b47a9c + languageName: node + linkType: hard + "anymatch@npm:^3.0.3": version: 3.1.3 resolution: "anymatch@npm:3.1.3" @@ -5988,6 +6212,15 @@ __metadata: languageName: node linkType: hard +"fast-check@npm:^3.0.0": + version: 3.23.2 + resolution: "fast-check@npm:3.23.2" + dependencies: + pure-rand: "npm:^6.1.0" + checksum: 10c0/16fcff3c80321ee765e23c3aebd0f6427f175c9c6c1753104ec658970162365dc2d56bda046d815e8f2e90634c07ba7d6f0bcfd327fbd576d98c56a18a9765ed + languageName: node + linkType: hard + "fast-deep-equal@npm:^3.1.1": version: 3.1.3 resolution: "fast-deep-equal@npm:3.1.3" @@ -7133,6 +7366,15 @@ __metadata: languageName: node linkType: hard +"jessie.js@npm:^0.3.4": + version: 0.3.4 + resolution: "jessie.js@npm:0.3.4" + dependencies: + "@endo/far": "npm:^1.0.0" + checksum: 10c0/853ab3f8a0e30df11742882f5e11479d1303033a5a203a247d8ffbf4c6f3f3d4bcbefa53084ae4632e6ab106e348f23dc988280486cbeaaf5d16487fa3d40e96 + languageName: node + linkType: hard + "jest-haste-map@npm:^28.1.3": version: 28.1.3 resolution: "jest-haste-map@npm:28.1.3" @@ -8708,6 +8950,13 @@ __metadata: languageName: node linkType: hard +"pure-rand@npm:^6.1.0": + version: 6.1.0 + resolution: "pure-rand@npm:6.1.0" + checksum: 10c0/1abe217897bf74dcb3a0c9aba3555fe975023147b48db540aa2faf507aee91c03bf54f6aef0eb2bf59cc259a16d06b28eca37f0dc426d94f4692aeff02fb0e65 + languageName: node + linkType: hard + "qs@npm:6.11.0": version: 6.11.0 resolution: "qs@npm:6.11.0" @@ -9280,6 +9529,15 @@ __metadata: languageName: node linkType: hard +"ses@npm:^1.10.0": + version: 1.10.0 + resolution: "ses@npm:1.10.0" + dependencies: + "@endo/env-options": "npm:^1.1.8" + checksum: 10c0/83b92bc49e27af04eeb7ee01a2196a0c4b0906e4de51e70403aa9ffc82be1d27a0c3506f2d54da8d6d260be0855f2123a13a7e2c6896e81ec85899df1a428609 + languageName: node + linkType: hard + "set-cookie-parser@npm:^2.4.8": version: 2.7.1 resolution: "set-cookie-parser@npm:2.7.1" From da6b46dcbe64cc4d6ca92d3f18f625d268941593 Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Wed, 18 Dec 2024 22:10:51 +0500 Subject: [PATCH 22/25] ci: set execute permission for all .mjs files in scripts --- .github/workflows/liquidation.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/liquidation.yml b/.github/workflows/liquidation.yml index e164a366..54cb9d4c 100644 --- a/.github/workflows/liquidation.yml +++ b/.github/workflows/liquidation.yml @@ -37,6 +37,9 @@ jobs: docker logs $container done + - name: Set Execute Permission for All Scripts + run: chmod +x ./scripts/*.mjs + - name: Set ATOM Price to 12.34 run: ./scripts/changePrice.mjs env: From 9fb678c1e844bb8594c21a94c807a4210ff0d988 Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Wed, 18 Dec 2024 22:16:56 +0500 Subject: [PATCH 23/25] chore(deps): install ses --- package.json | 1 + scripts/changePrice.mjs | 1 + scripts/createVault.mjs | 1 + scripts/placeBid.mjs | 1 + yarn.lock | 1 + 5 files changed, 5 insertions(+) diff --git a/package.json b/package.json index 8c88226e..387ddbe3 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "@subql/testing": "latest", "execa": "^9.5.2", "prettier": "^3.4.2", + "ses": "^1.10.0", "starknet": "6.11.0", "typescript": "^5.7.2" }, diff --git a/scripts/changePrice.mjs b/scripts/changePrice.mjs index e72900b9..e0939128 100644 --- a/scripts/changePrice.mjs +++ b/scripts/changePrice.mjs @@ -1,4 +1,5 @@ #! /usr/bin/env node +import 'ses'; import { execa } from 'execa'; import { assertAllDefined } from '@agoric/internal'; diff --git a/scripts/createVault.mjs b/scripts/createVault.mjs index 241df2f2..dce4e7fc 100644 --- a/scripts/createVault.mjs +++ b/scripts/createVault.mjs @@ -1,4 +1,5 @@ #! /usr/bin/env node +import 'ses'; import { execa } from 'execa'; import assert from 'node:assert/strict'; import { assertAllDefined } from '@agoric/internal'; diff --git a/scripts/placeBid.mjs b/scripts/placeBid.mjs index 8ee96e7a..223cb2b4 100644 --- a/scripts/placeBid.mjs +++ b/scripts/placeBid.mjs @@ -1,4 +1,5 @@ #! /usr/bin/env node +import 'ses'; import { execa } from 'execa'; import assert from 'node:assert/strict'; import { assertAllDefined } from '@agoric/internal'; diff --git a/yarn.lock b/yarn.lock index 9b3c15a8..93d0745a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4332,6 +4332,7 @@ __metadata: js-sha256: "npm:^0.11.0" pino: "npm:^7.8.0" prettier: "npm:^3.4.2" + ses: "npm:^1.10.0" starknet: "npm:6.11.0" typescript: "npm:^5.7.2" languageName: unknown From 9201fe941c539a384ecf377d92e060b0332c6bc1 Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Wed, 18 Dec 2024 22:28:37 +0500 Subject: [PATCH 24/25] fixup! chore(deps): install ses --- package.json | 1 + scripts/changePrice.mjs | 2 +- scripts/createVault.mjs | 2 +- scripts/lockdown.mjs | 10 ++++++++++ scripts/placeBid.mjs | 2 +- yarn.lock | 1 + 6 files changed, 15 insertions(+), 3 deletions(-) mode change 100644 => 100755 scripts/changePrice.mjs create mode 100644 scripts/lockdown.mjs diff --git a/package.json b/package.json index 387ddbe3..8c7635f5 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "devDependencies": { "@agoric/internal": "0.4.0-u18.0", "@cosmjs/stargate": "^0.28.9", + "@endo/eventual-send": "^1.2.8", "@subql/cli": "^5.4.0", "@subql/node-cosmos": "^4.2.1", "@subql/testing": "latest", diff --git a/scripts/changePrice.mjs b/scripts/changePrice.mjs old mode 100644 new mode 100755 index e0939128..45fbaa7f --- a/scripts/changePrice.mjs +++ b/scripts/changePrice.mjs @@ -1,5 +1,5 @@ #! /usr/bin/env node -import 'ses'; +import './lockdown.mjs'; import { execa } from 'execa'; import { assertAllDefined } from '@agoric/internal'; diff --git a/scripts/createVault.mjs b/scripts/createVault.mjs index dce4e7fc..563e1f67 100644 --- a/scripts/createVault.mjs +++ b/scripts/createVault.mjs @@ -1,5 +1,5 @@ #! /usr/bin/env node -import 'ses'; +import './lockdown.mjs'; import { execa } from 'execa'; import assert from 'node:assert/strict'; import { assertAllDefined } from '@agoric/internal'; diff --git a/scripts/lockdown.mjs b/scripts/lockdown.mjs new file mode 100644 index 00000000..76a83b63 --- /dev/null +++ b/scripts/lockdown.mjs @@ -0,0 +1,10 @@ +import 'ses'; +import '@endo/eventual-send/shim.js'; + +const options = { + overrideTaming: 'severe', + stackFiltering: 'verbose', + errorTaming: 'unsafe', +}; + +lockdown(options); diff --git a/scripts/placeBid.mjs b/scripts/placeBid.mjs index 223cb2b4..a3e8f847 100644 --- a/scripts/placeBid.mjs +++ b/scripts/placeBid.mjs @@ -1,5 +1,5 @@ #! /usr/bin/env node -import 'ses'; +import './lockdown.mjs'; import { execa } from 'execa'; import assert from 'node:assert/strict'; import { assertAllDefined } from '@agoric/internal'; diff --git a/yarn.lock b/yarn.lock index 93d0745a..3d72bb34 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4321,6 +4321,7 @@ __metadata: dependencies: "@agoric/internal": "npm:0.4.0-u18.0" "@cosmjs/stargate": "npm:^0.28.9" + "@endo/eventual-send": "npm:^1.2.8" "@subql/cli": "npm:^5.4.0" "@subql/node-cosmos": "npm:^4.2.1" "@subql/testing": "npm:latest" From 7dc8b52d5d2f4c7f51cc36d2cb88db068bcacaed Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Thu, 19 Dec 2024 09:30:19 +0500 Subject: [PATCH 25/25] fixup! fixup! chore(deps): install ses --- scripts/checkLiquidation.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/checkLiquidation.mjs b/scripts/checkLiquidation.mjs index 9b8208ed..008f9ca6 100644 --- a/scripts/checkLiquidation.mjs +++ b/scripts/checkLiquidation.mjs @@ -76,7 +76,7 @@ const validate = async ({ apiUrl, maxRetries, retryDuration, expectations, filte for (const key of Object.keys(expectations)) { for (let i = 0; i < nodes.length; i++) { - equal(nodes[i][key], expectations[i].key); + equal(nodes[i][key], expectations[key][i]); } }