From 1ceca20d05f978e3f75cca6f83c3757f3213f136 Mon Sep 17 00:00:00 2001 From: eliasmpw Date: Tue, 6 Feb 2024 10:14:30 +0100 Subject: [PATCH] feat!: upgrade to Archway v6 (#114) ### Added #### **arch3-core** - added `withdrawToWallet` property to the `ContractMetadata` interface ### Changed #### **arch3-proto** - updated to the version `6.0.0` of the protocol --- CHANGELOG.md | 19 +++++ README.md | 3 +- docker-compose.yaml | 2 +- package.json | 2 +- packages/arch3-core/package.json | 2 +- packages/arch3-core/src/archwayclient.spec.ts | 4 +- .../src/signingarchwayclient.spec.ts | 77 +++++++++++++------ .../arch3-core/src/signingarchwayclient.ts | 3 + packages/arch3-core/src/types.ts | 5 ++ .../generated/archway/rewards/v1/rewards.ts | 20 ++++- .../generated/archway/rewards/v1/tx.amino.ts | 7 +- packages/arch3-proto/package.json | 2 +- .../proto/archway/rewards/v1/rewards.proto | 4 + scripts/start-local-node.sh | 6 +- yarn.lock | 32 +++++++- 15 files changed, 147 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab08035..b6eae2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,25 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## v0.6.0 (2023-02-06) + +### BREAKING CHANGES + +- the new version of `arch3.js` will, by default, be compatible only with the + Archway protocol version `6.0.0` and above. + +### Added + +#### **arch3-core** + +- added `withdrawToWallet` property to the `ContractMetadata` interface (#114) + +### Changed + +#### **arch3-proto** + +- updated to the version `6.0.0` of the protocol (#114) + ## v0.5.0 (2023-11-21) ### BREAKING CHANGES diff --git a/README.md b/README.md index 549305a..d85cab5 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,8 @@ List of Archway [protocol versions](https://github.com/archway-network/archway/r | archwayd | arch3.js | | :----------------: | :----------------: | -| `>=5.0.0` | `>=0.5.0` | +| `>=6.0.0` | `>=0.6.0` | +| `5.0.0` | `0.5.0` | | `0.5.0` to `4.0.2` | `0.2.0` to `0.4.0` | | `<0.5.0` | `0.1.0` | diff --git a/docker-compose.yaml b/docker-compose.yaml index bd1da3c..27be11c 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,6 +1,6 @@ services: node: - image: archwaynetwork/archwayd:v5.0.1 + image: archwaynetwork/archwayd:v6.0.0 command: start --x-crisis-skip-assert-invariants entrypoint: /docker-entrypoint.sh ports: diff --git a/package.json b/package.json index c854bc7..40efe8c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@archwayhq/arch3.js", - "version": "0.5.0", + "version": "0.6.0", "description": "The all-in-one library for your awesome Archway dApp", "homepage": "https://docs.archway.io", "repository": "github:archway-network/arch3.js", diff --git a/packages/arch3-core/package.json b/packages/arch3-core/package.json index 2ae170c..868ce29 100644 --- a/packages/arch3-core/package.json +++ b/packages/arch3-core/package.json @@ -1,6 +1,6 @@ { "name": "@archwayhq/arch3-core", - "version": "0.5.0", + "version": "0.6.0", "description": "Core library to interact with Archway Network", "homepage": "https://docs.archway.io", "repository": "github:archway-network/arch3.js", diff --git a/packages/arch3-core/src/archwayclient.spec.ts b/packages/arch3-core/src/archwayclient.spec.ts index 879de7f..cfba350 100644 --- a/packages/arch3-core/src/archwayclient.spec.ts +++ b/packages/arch3-core/src/archwayclient.spec.ts @@ -141,9 +141,9 @@ describe('ArchwayClient', () => { it('check does not fail when contract premium is not set', async () => { const client = await ArchwayClient.connect(archwayd.endpoint); - const response = await client.getContractPremium(contracts.voter.addresses[2]); + const response = await client.getContractPremium(contracts.voter.addresses[3]); - expect(response.contractAddress).toBe(contracts.voter.addresses[2]); + expect(response.contractAddress).toBe(contracts.voter.addresses[3]); expect(response.flatFee).toBeUndefined(); client.disconnect(); diff --git a/packages/arch3-core/src/signingarchwayclient.spec.ts b/packages/arch3-core/src/signingarchwayclient.spec.ts index 34a0775..20a4bfb 100644 --- a/packages/arch3-core/src/signingarchwayclient.spec.ts +++ b/packages/arch3-core/src/signingarchwayclient.spec.ts @@ -24,7 +24,7 @@ const mnemonics = { async function getWalletWithAccounts(): Promise<[DirectSecp256k1HdWallet, readonly AccountData[]]> { const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonics.alice, { - hdPaths: [0, 1, 2, 3, 4].map(makeCosmoshubPath), + hdPaths: [0, 1, 2, 3, 4, 5].map(makeCosmoshubPath), prefix: archwayd.prefix }); const accounts = await wallet.getAccounts(); @@ -153,8 +153,8 @@ describe('SigningArchwayClient', () => { const [wallet, accounts] = await getWalletWithAccounts(); const client = await SigningArchwayClient.connectWithSigner(archwayd.endpoint, wallet, clientOptions); - const contractAddress = contracts.voter.addresses[2]; - const ownerAddress = accounts[2].address; + const contractAddress = contracts.voter.addresses[3]; + const ownerAddress = accounts[3].address; /* eslint-disable camelcase, @typescript-eslint/naming-convention */ const msg = { @@ -324,8 +324,8 @@ describe('SigningArchwayClient', () => { const [wallet, accounts] = await getWalletWithAccounts(); const client = await SigningArchwayClient.connectWithSigner(archwayd.endpoint, wallet, clientOptions); - const contractAddress = contracts.voter.addresses[2]; - const ownerAddress = accounts[2].address; + const contractAddress = contracts.voter.addresses[3]; + const ownerAddress = accounts[3].address; const result = await client.setContractPremium( ownerAddress, @@ -356,8 +356,8 @@ describe('SigningArchwayClient', () => { const [wallet, accounts] = await getWalletWithAccounts(); const client = await SigningArchwayClient.connectWithSigner(archwayd.endpoint, wallet, clientOptions); - const contractAddress = contracts.voter.addresses[3]; - const rewardsAddress = accounts[3].address; + const contractAddress = contracts.voter.addresses[4]; + const rewardsAddress = accounts[4].address; /* eslint-disable camelcase, @typescript-eslint/naming-convention */ const msg = { @@ -388,28 +388,59 @@ describe('SigningArchwayClient', () => { client.disconnect(); }); - }); - it('gracefully handles withdrawing when no rewards found', async () => { - const [wallet, accounts] = await getWalletWithAccounts(); - const client = await SigningArchwayClient.connectWithSigner(archwayd.endpoint, wallet, clientOptions); + it('gracefully handles withdrawing when no rewards found', async () => { + const [wallet, accounts] = await getWalletWithAccounts(); + const client = await SigningArchwayClient.connectWithSigner(archwayd.endpoint, wallet, clientOptions); - const rewardsAddress = accounts[1].address; + const rewardsAddress = accounts[1].address; - const result = await client.withdrawContractRewards(rewardsAddress, 0, 'auto'); + const result = await client.withdrawContractRewards(rewardsAddress, 0, 'auto'); - expect(result).toMatchObject({ - height: expect.any(Number), - transactionHash: expect.any(String), - gasWanted: expect.any(Number), - gasUsed: expect.any(Number), - rewardsAddress: rewardsAddress, - rewards: expect.arrayContaining([]), + expect(result).toMatchObject({ + height: expect.any(Number), + transactionHash: expect.any(String), + gasWanted: expect.any(Number), + gasUsed: expect.any(Number), + rewardsAddress: rewardsAddress, + rewards: expect.arrayContaining([]), + }); + expect(result.logs).not.toHaveLength(0); + expect(result.events).not.toHaveLength(0); + + client.disconnect(); }); - expect(result.logs).not.toHaveLength(0); - expect(result.events).not.toHaveLength(0); + }); - client.disconnect(); + describe('withdrawToWallet', () => { + it('enables the flag withdrawToWallet in the metadata', async () => { + const [wallet, accounts] = await getWalletWithAccounts(); + const client = await SigningArchwayClient.connectWithSigner(archwayd.endpoint, wallet, clientOptions); + + const contractAddress = contracts.voter.addresses[2]; + const ownerAddress = accounts[2].address; + const rewardsAddress = accounts[5].address; + + const metadata: ContractMetadata = { + contractAddress, + ownerAddress, + rewardsAddress, + withdrawToWallet: true + }; + const result = await client.setContractMetadata(ownerAddress, metadata, 'auto'); + + expect(result).toMatchObject({ + height: expect.any(Number), + transactionHash: expect.any(String), + gasWanted: expect.any(Number), + gasUsed: expect.any(Number), + metadata, + }); + expect(result.logs).not.toHaveLength(0); + expect(result.events).not.toHaveLength(0); + + client.disconnect(); + }); }); }); }); diff --git a/packages/arch3-core/src/signingarchwayclient.ts b/packages/arch3-core/src/signingarchwayclient.ts index c9b0dfd..a095228 100644 --- a/packages/arch3-core/src/signingarchwayclient.ts +++ b/packages/arch3-core/src/signingarchwayclient.ts @@ -258,6 +258,7 @@ export class SigningArchwayClient extends SigningCosmWasmClient implements IArch contractAddress: metadata.contractAddress, ownerAddress: metadata.ownerAddress ?? '', rewardsAddress: metadata.rewardsAddress ?? '', + withdrawToWallet: metadata.withdrawToWallet ?? false, } }); const response = await this.assertSignAndBroadcast(senderAddress, [message], fee, memo); @@ -267,6 +268,7 @@ export class SigningArchwayClient extends SigningCosmWasmClient implements IArch contract_address: string, owner_address?: string, rewards_address?: string, + withdraw_to_wallet?: boolean, }; /* eslint-enable */ return { @@ -275,6 +277,7 @@ export class SigningArchwayClient extends SigningCosmWasmClient implements IArch contractAddress: contractMetadata.contract_address, ownerAddress: contractMetadata.owner_address, rewardsAddress: contractMetadata.rewards_address, + withdrawToWallet: contractMetadata.withdraw_to_wallet, }, }; } diff --git a/packages/arch3-core/src/types.ts b/packages/arch3-core/src/types.ts index ae50f1f..03fe9b5 100644 --- a/packages/arch3-core/src/types.ts +++ b/packages/arch3-core/src/types.ts @@ -24,6 +24,11 @@ export interface ContractMetadata { * the rewards using the [WASM bindings](https://github.com/archway-network/archway-bindings). */ readonly rewardsAddress?: string; + /** + * Flag that defines if rewards should be immediately withdrawn to the wallet + * instead of creating a rewards record to be lazily withdrawn after. + */ + readonly withdrawToWallet?: boolean; } /** diff --git a/packages/arch3-proto/generated/archway/rewards/v1/rewards.ts b/packages/arch3-proto/generated/archway/rewards/v1/rewards.ts index 944f78b..5679d6c 100644 --- a/packages/arch3-proto/generated/archway/rewards/v1/rewards.ts +++ b/packages/arch3-proto/generated/archway/rewards/v1/rewards.ts @@ -49,6 +49,12 @@ export interface ContractMetadata { * If not set (empty), rewards are not distributed for this contract. */ rewardsAddress: string; + /** + * withdraw_to_wallet is a flag that defines if rewards should be immediately + * withdrawn to the wallet instead of creating a rewards record to be lazily + * withdrawn after. + */ + withdrawToWallet: boolean; } /** BlockRewards defines block related rewards distribution data. */ export interface BlockRewards { @@ -180,7 +186,8 @@ function createBaseContractMetadata(): ContractMetadata { return { contractAddress: "", ownerAddress: "", - rewardsAddress: "" + rewardsAddress: "", + withdrawToWallet: false }; } export const ContractMetadata = { @@ -194,6 +201,9 @@ export const ContractMetadata = { if (message.rewardsAddress !== "") { writer.uint32(26).string(message.rewardsAddress); } + if (message.withdrawToWallet === true) { + writer.uint32(32).bool(message.withdrawToWallet); + } return writer; }, decode(input: _m0.Reader | Uint8Array, length?: number): ContractMetadata { @@ -212,6 +222,9 @@ export const ContractMetadata = { case 3: message.rewardsAddress = reader.string(); break; + case 4: + message.withdrawToWallet = reader.bool(); + break; default: reader.skipType(tag & 7); break; @@ -223,7 +236,8 @@ export const ContractMetadata = { return { contractAddress: isSet(object.contractAddress) ? String(object.contractAddress) : "", ownerAddress: isSet(object.ownerAddress) ? String(object.ownerAddress) : "", - rewardsAddress: isSet(object.rewardsAddress) ? String(object.rewardsAddress) : "" + rewardsAddress: isSet(object.rewardsAddress) ? String(object.rewardsAddress) : "", + withdrawToWallet: isSet(object.withdrawToWallet) ? Boolean(object.withdrawToWallet) : false }; }, toJSON(message: ContractMetadata): unknown { @@ -231,6 +245,7 @@ export const ContractMetadata = { message.contractAddress !== undefined && (obj.contractAddress = message.contractAddress); message.ownerAddress !== undefined && (obj.ownerAddress = message.ownerAddress); message.rewardsAddress !== undefined && (obj.rewardsAddress = message.rewardsAddress); + message.withdrawToWallet !== undefined && (obj.withdrawToWallet = message.withdrawToWallet); return obj; }, fromPartial(object: Partial): ContractMetadata { @@ -238,6 +253,7 @@ export const ContractMetadata = { message.contractAddress = object.contractAddress ?? ""; message.ownerAddress = object.ownerAddress ?? ""; message.rewardsAddress = object.rewardsAddress ?? ""; + message.withdrawToWallet = object.withdrawToWallet ?? false; return message; } }; diff --git a/packages/arch3-proto/generated/archway/rewards/v1/tx.amino.ts b/packages/arch3-proto/generated/archway/rewards/v1/tx.amino.ts index 2c750e9..7d1551e 100644 --- a/packages/arch3-proto/generated/archway/rewards/v1/tx.amino.ts +++ b/packages/arch3-proto/generated/archway/rewards/v1/tx.amino.ts @@ -10,6 +10,7 @@ export interface MsgSetContractMetadataAminoType extends AminoMsg { contract_address: string; owner_address: string; rewards_address: string; + withdraw_to_wallet: boolean; }; }; } @@ -63,7 +64,8 @@ export const AminoConverter = { metadata: { contract_address: metadata.contractAddress, owner_address: metadata.ownerAddress, - rewards_address: metadata.rewardsAddress + rewards_address: metadata.rewardsAddress, + withdraw_to_wallet: metadata.withdrawToWallet } }; }, @@ -76,7 +78,8 @@ export const AminoConverter = { metadata: { contractAddress: metadata.contract_address, ownerAddress: metadata.owner_address, - rewardsAddress: metadata.rewards_address + rewardsAddress: metadata.rewards_address, + withdrawToWallet: metadata.withdraw_to_wallet } }; } diff --git a/packages/arch3-proto/package.json b/packages/arch3-proto/package.json index d3a2cbb..031a302 100644 --- a/packages/arch3-proto/package.json +++ b/packages/arch3-proto/package.json @@ -1,6 +1,6 @@ { "name": "@archwayhq/arch3-proto", - "version": "0.5.0", + "version": "0.6.0", "description": "Protobuf definitions and RPC clients for the Archway Network", "homepage": "https://docs.archway.io", "repository": "github:archway-network/arch3.js", diff --git a/packages/arch3-proto/proto/archway/rewards/v1/rewards.proto b/packages/arch3-proto/proto/archway/rewards/v1/rewards.proto index 7a54584..d369930 100644 --- a/packages/arch3-proto/proto/archway/rewards/v1/rewards.proto +++ b/packages/arch3-proto/proto/archway/rewards/v1/rewards.proto @@ -52,6 +52,10 @@ message ContractMetadata { // rewards_address is an address to distribute rewards to (bech32 encoded). // If not set (empty), rewards are not distributed for this contract. string rewards_address = 3; + // withdraw_to_wallet is a flag that defines if rewards should be immediately + // withdrawn to the wallet instead of creating a rewards record to be lazily + // withdrawn after. + bool withdraw_to_wallet = 4; } // BlockRewards defines block related rewards distribution data. diff --git a/scripts/start-local-node.sh b/scripts/start-local-node.sh index fc1d0d6..aef7114 100755 --- a/scripts/start-local-node.sh +++ b/scripts/start-local-node.sh @@ -184,7 +184,7 @@ ALICE_MNEMONIC="culture ten bar chase cross obey margin owner recycle trim valid dotenv-add ALICE_MNEMONIC "${ALICE_MNEMONIC}" declare -a alice_addresses=() -for i in {0..4}; do +for i in {0..5}; do key_name="alice-$i" action "$key_name" @@ -253,7 +253,7 @@ dotenv-add "VOTER_CONTRACT_ADDRESSES" "${contract_addresses[*]}" ok "contracts instantiated" action "setting metadata" -for i in {0..3}; do +for i in {0..4}; do step "voter-$i" if archwayd q rewards contract-metadata "${contract_addresses[i]}" 2>/dev/null | @@ -280,7 +280,7 @@ ok "contract metadata set" action "setting contract premium" flat_fee_amount="1000" -for i in {0..1}; do +for i in {0..2}; do step "voter-$i" if archwayd q rewards flat-fee "${contract_addresses[i]}" 2>/dev/null | \ diff --git a/yarn.lock b/yarn.lock index 6152793..caf497f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5796,12 +5796,12 @@ __metadata: linkType: hard "follow-redirects@npm:^1.14.0": - version: 1.15.1 - resolution: "follow-redirects@npm:1.15.1" + version: 1.15.5 + resolution: "follow-redirects@npm:1.15.5" peerDependenciesMeta: debug: optional: true - checksum: a57f93ce566d4602fe7b2f6cef8f8d3d053891b3d8f2feae7e97eec18aa0003d23aeec8e857801d93887eee27e1617276a16f6a3d5c9d78e45882346612462d5 + checksum: d467f13c1c6aa734599b8b369cd7a625b20081af358f6204ff515f6f4116eb440de9c4e0c49f10798eeb0df26c95dd05d5e0d9ddc5786ab1a8a8abefe92929b4 languageName: node linkType: hard @@ -8994,7 +8994,7 @@ __metadata: languageName: node linkType: hard -"protobufjs@npm:^6.8.8, protobufjs@npm:~6.11.2, protobufjs@npm:~6.11.3": +"protobufjs@npm:^6.8.8": version: 6.11.3 resolution: "protobufjs@npm:6.11.3" dependencies: @@ -9038,6 +9038,30 @@ __metadata: languageName: node linkType: hard +"protobufjs@npm:~6.11.2, protobufjs@npm:~6.11.3": + version: 6.11.4 + resolution: "protobufjs@npm:6.11.4" + 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/long": "npm:^4.0.1" + "@types/node": "npm:>=13.7.0" + long: "npm:^4.0.0" + bin: + pbjs: bin/pbjs + pbts: bin/pbts + checksum: 6b7fd7540d74350d65c38f69f398c9995ae019da070e79d9cd464a458c6d19b40b07c9a026be4e10704c824a344b603307745863310c50026ebd661ce4da0663 + languageName: node + linkType: hard + "pump@npm:^3.0.0": version: 3.0.0 resolution: "pump@npm:3.0.0"